]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/greybus/svc.c
greybus: svc: skip setting flags for boot over unipro
[karo-tx-linux.git] / drivers / staging / greybus / svc.c
1 /*
2  * SVC Greybus driver.
3  *
4  * Copyright 2015 Google Inc.
5  * Copyright 2015 Linaro Ltd.
6  *
7  * Released under the GPLv2 only.
8  */
9
10 #include <linux/workqueue.h>
11
12 #include "greybus.h"
13
14 #define CPORT_FLAGS_E2EFC       (1)
15 #define CPORT_FLAGS_CSD_N       (2)
16 #define CPORT_FLAGS_CSV_N       (4)
17
18 enum gb_svc_state {
19         GB_SVC_STATE_RESET,
20         GB_SVC_STATE_PROTOCOL_VERSION,
21         GB_SVC_STATE_SVC_HELLO,
22 };
23
24 struct gb_svc {
25         struct gb_connection    *connection;
26         enum gb_svc_state       state;
27         struct ida              device_id_map;
28 };
29
30 struct svc_hotplug {
31         struct work_struct work;
32         struct gb_connection *connection;
33         struct gb_svc_intf_hotplug_request data;
34 };
35
36
37 /*
38  * AP's SVC cport is required early to get messages from the SVC. This happens
39  * even before the Endo is created and hence any modules or interfaces.
40  *
41  * This is a temporary connection, used only at initial bootup.
42  */
43 struct gb_connection *
44 gb_ap_svc_connection_create(struct greybus_host_device *hd)
45 {
46         struct gb_connection *connection;
47
48         connection = gb_connection_create_range(hd, NULL, hd->parent,
49                                                 GB_SVC_CPORT_ID,
50                                                 GREYBUS_PROTOCOL_SVC,
51                                                 GB_SVC_CPORT_ID,
52                                                 GB_SVC_CPORT_ID + 1);
53
54         return connection;
55 }
56
57 /*
58  * We know endo-type and AP's interface id now, lets create a proper svc
59  * connection (and its interface/bundle) now and get rid of the initial
60  * 'partially' initialized one svc connection.
61  */
62 static struct gb_interface *
63 gb_ap_interface_create(struct greybus_host_device *hd,
64                        struct gb_connection *connection, u8 interface_id)
65 {
66         struct gb_interface *intf;
67         struct device *dev = &hd->endo->dev;
68
69         intf = gb_interface_create(hd, interface_id);
70         if (!intf) {
71                 dev_err(dev, "%s: Failed to create interface with id %hhu\n",
72                         __func__, interface_id);
73                 return NULL;
74         }
75
76         intf->device_id = GB_DEVICE_ID_AP;
77         svc_update_connection(intf, connection);
78
79         /* Its no longer a partially initialized connection */
80         hd->initial_svc_connection = NULL;
81
82         return intf;
83 }
84
85 static int gb_svc_intf_device_id(struct gb_svc *svc, u8 intf_id, u8 device_id)
86 {
87         struct gb_svc_intf_device_id_request request;
88
89         request.intf_id = intf_id;
90         request.device_id = device_id;
91
92         return gb_operation_sync(svc->connection, GB_SVC_TYPE_INTF_DEVICE_ID,
93                                  &request, sizeof(request), NULL, 0);
94 }
95
96 int gb_svc_intf_reset(struct gb_svc *svc, u8 intf_id)
97 {
98         struct gb_svc_intf_reset_request request;
99
100         request.intf_id = intf_id;
101
102         return gb_operation_sync(svc->connection, GB_SVC_TYPE_INTF_RESET,
103                                  &request, sizeof(request), NULL, 0);
104 }
105 EXPORT_SYMBOL_GPL(gb_svc_intf_reset);
106
107 int gb_svc_dme_peer_get(struct gb_svc *svc, u8 intf_id, u16 attr, u16 selector,
108                         u32 *value)
109 {
110         struct gb_svc_dme_peer_get_request request;
111         struct gb_svc_dme_peer_get_response response;
112         u16 result;
113         int ret;
114
115         request.intf_id = intf_id;
116         request.attr = cpu_to_le16(attr);
117         request.selector = cpu_to_le16(selector);
118
119         ret = gb_operation_sync(svc->connection, GB_SVC_TYPE_DME_PEER_GET,
120                                 &request, sizeof(request),
121                                 &response, sizeof(response));
122         if (ret) {
123                 dev_err(&svc->connection->dev,
124                         "failed to get DME attribute (%hhu %hx %hu) %d\n",
125                         intf_id, attr, selector, ret);
126                 return ret;
127         }
128
129         result = le16_to_cpu(response.result_code);
130         if (result) {
131                 dev_err(&svc->connection->dev,
132                         "Unipro error %hu while getting DME attribute (%hhu %hx %hu)\n",
133                         result, intf_id, attr, selector);
134                 return -EINVAL;
135         }
136
137         if (value)
138                 *value = le32_to_cpu(response.attr_value);
139
140         return 0;
141 }
142 EXPORT_SYMBOL_GPL(gb_svc_dme_peer_get);
143
144 int gb_svc_dme_peer_set(struct gb_svc *svc, u8 intf_id, u16 attr, u16 selector,
145                         u32 value)
146 {
147         struct gb_svc_dme_peer_set_request request;
148         struct gb_svc_dme_peer_set_response response;
149         u16 result;
150         int ret;
151
152         request.intf_id = intf_id;
153         request.attr = cpu_to_le16(attr);
154         request.selector = cpu_to_le16(selector);
155         request.value = cpu_to_le32(value);
156
157         ret = gb_operation_sync(svc->connection, GB_SVC_TYPE_DME_PEER_SET,
158                                 &request, sizeof(request),
159                                 &response, sizeof(response));
160         if (ret) {
161                 dev_err(&svc->connection->dev,
162                         "failed to set DME attribute (%hhu %hx %hu %u) %d\n",
163                         intf_id, attr, selector, value, ret);
164                 return ret;
165         }
166
167         result = le16_to_cpu(response.result_code);
168         if (result) {
169                 dev_err(&svc->connection->dev,
170                         "Unipro error %hu while setting DME attribute (%hhu %hx %hu %u)\n",
171                         result, intf_id, attr, selector, value);
172                 return -EINVAL;
173         }
174
175         return 0;
176 }
177 EXPORT_SYMBOL_GPL(gb_svc_dme_peer_set);
178
179 /*
180  * T_TstSrcIncrement is written by the module on ES2 as a stand-in for boot
181  * status attribute. AP needs to read and clear it, after reading a non-zero
182  * value from it.
183  *
184  * FIXME: This is module-hardware dependent and needs to be extended for every
185  * type of module we want to support.
186  */
187 static int gb_svc_read_and_clear_module_boot_status(struct gb_interface *intf)
188 {
189         struct greybus_host_device *hd = intf->hd;
190         int ret;
191         u32 value;
192
193         /* Read and clear boot status in T_TstSrcIncrement */
194         ret = gb_svc_dme_peer_get(hd->svc, intf->interface_id,
195                                   DME_ATTR_T_TST_SRC_INCREMENT,
196                                   DME_ATTR_SELECTOR_INDEX, &value);
197
198         if (ret)
199                 return ret;
200
201         /*
202          * A nonzero boot status indicates the module has finished
203          * booting. Clear it.
204          */
205         if (!value) {
206                 dev_err(&intf->dev, "Module not ready yet\n");
207                 return -ENODEV;
208         }
209
210         /*
211          * Check if the module needs to boot from unipro.
212          * For ES2: We need to check lowest 8 bits of 'value'.
213          * For ES3: We need to check highest 8 bits out of 32 of 'value'.
214          *
215          * FIXME: Add code to find if we are on ES2 or ES3 to have separate
216          * checks.
217          */
218         if (value == DME_TSI_UNIPRO_BOOT_STARTED ||
219             value == DME_TSI_FALLBACK_UNIPRO_BOOT_STARTED)
220                 intf->boot_over_unipro = true;
221
222         return gb_svc_dme_peer_set(hd->svc, intf->interface_id,
223                                    DME_ATTR_T_TST_SRC_INCREMENT,
224                                    DME_ATTR_SELECTOR_INDEX, 0);
225 }
226
227 int gb_svc_connection_create(struct gb_svc *svc,
228                                 u8 intf1_id, u16 cport1_id,
229                                 u8 intf2_id, u16 cport2_id,
230                                 bool boot_over_unipro)
231 {
232         struct gb_svc_conn_create_request request;
233
234         request.intf1_id = intf1_id;
235         request.cport1_id = cpu_to_le16(cport1_id);
236         request.intf2_id = intf2_id;
237         request.cport2_id = cpu_to_le16(cport2_id);
238         /*
239          * XXX: fix connections paramaters to TC0 and all CPort flags
240          * for now.
241          */
242         request.tc = 0;
243
244         /*
245          * We need to skip setting E2EFC and other flags to the connection
246          * create request, for all cports, on an interface that need to boot
247          * over unipro, i.e. interfaces required to download firmware.
248          */
249         if (boot_over_unipro)
250                 request.flags = CPORT_FLAGS_CSV_N | CPORT_FLAGS_CSD_N;
251         else
252                 request.flags = CPORT_FLAGS_CSV_N | CPORT_FLAGS_E2EFC;
253
254         return gb_operation_sync(svc->connection, GB_SVC_TYPE_CONN_CREATE,
255                                  &request, sizeof(request), NULL, 0);
256 }
257 EXPORT_SYMBOL_GPL(gb_svc_connection_create);
258
259 void gb_svc_connection_destroy(struct gb_svc *svc, u8 intf1_id, u16 cport1_id,
260                                u8 intf2_id, u16 cport2_id)
261 {
262         struct gb_svc_conn_destroy_request request;
263         struct gb_connection *connection = svc->connection;
264         int ret;
265
266         request.intf1_id = intf1_id;
267         request.cport1_id = cpu_to_le16(cport1_id);
268         request.intf2_id = intf2_id;
269         request.cport2_id = cpu_to_le16(cport2_id);
270
271         ret = gb_operation_sync(connection, GB_SVC_TYPE_CONN_DESTROY,
272                                 &request, sizeof(request), NULL, 0);
273         if (ret) {
274                 dev_err(&connection->dev,
275                         "failed to destroy connection (%hhx:%hx %hhx:%hx) %d\n",
276                         intf1_id, cport1_id, intf2_id, cport2_id, ret);
277         }
278 }
279 EXPORT_SYMBOL_GPL(gb_svc_connection_destroy);
280
281 /* Creates bi-directional routes between the devices */
282 static int gb_svc_route_create(struct gb_svc *svc, u8 intf1_id, u8 dev1_id,
283                                u8 intf2_id, u8 dev2_id)
284 {
285         struct gb_svc_route_create_request request;
286
287         request.intf1_id = intf1_id;
288         request.dev1_id = dev1_id;
289         request.intf2_id = intf2_id;
290         request.dev2_id = dev2_id;
291
292         return gb_operation_sync(svc->connection, GB_SVC_TYPE_ROUTE_CREATE,
293                                  &request, sizeof(request), NULL, 0);
294 }
295
296 /* Destroys bi-directional routes between the devices */
297 static void gb_svc_route_destroy(struct gb_svc *svc, u8 intf1_id, u8 intf2_id)
298 {
299         struct gb_svc_route_destroy_request request;
300         int ret;
301
302         request.intf1_id = intf1_id;
303         request.intf2_id = intf2_id;
304
305         ret = gb_operation_sync(svc->connection, GB_SVC_TYPE_ROUTE_DESTROY,
306                                 &request, sizeof(request), NULL, 0);
307         if (ret) {
308                 dev_err(&svc->connection->dev,
309                         "failed to destroy route (%hhx %hhx) %d\n",
310                         intf1_id, intf2_id, ret);
311         }
312 }
313
314 static int gb_svc_version_request(struct gb_operation *op)
315 {
316         struct gb_connection *connection = op->connection;
317         struct gb_protocol_version_request *request;
318         struct gb_protocol_version_response *response;
319         struct device *dev = &connection->dev;
320
321         request = op->request->payload;
322
323         if (request->major > GB_SVC_VERSION_MAJOR) {
324                 dev_err(&connection->dev,
325                         "unsupported major version (%hhu > %hhu)\n",
326                         request->major, GB_SVC_VERSION_MAJOR);
327                 return -ENOTSUPP;
328         }
329
330         connection->module_major = request->major;
331         connection->module_minor = request->minor;
332
333         if (!gb_operation_response_alloc(op, sizeof(*response), GFP_KERNEL)) {
334                 dev_err(dev, "%s: error allocating response\n",
335                                 __func__);
336                 return -ENOMEM;
337         }
338
339         response = op->response->payload;
340         response->major = connection->module_major;
341         response->minor = connection->module_minor;
342
343         return 0;
344 }
345
346 static int gb_svc_hello(struct gb_operation *op)
347 {
348         struct gb_connection *connection = op->connection;
349         struct greybus_host_device *hd = connection->hd;
350         struct gb_svc_hello_request *hello_request;
351         struct device *dev = &connection->dev;
352         struct gb_interface *intf;
353         u16 endo_id;
354         u8 interface_id;
355         int ret;
356
357         /*
358          * SVC sends information about the endo and interface-id on the hello
359          * request, use that to create an endo.
360          */
361         if (op->request->payload_size < sizeof(*hello_request)) {
362                 dev_err(dev, "%s: Illegal size of hello request (%zu < %zu)\n",
363                         __func__, op->request->payload_size,
364                         sizeof(*hello_request));
365                 return -EINVAL;
366         }
367
368         hello_request = op->request->payload;
369         endo_id = le16_to_cpu(hello_request->endo_id);
370         interface_id = hello_request->interface_id;
371
372         /* Setup Endo */
373         ret = greybus_endo_setup(hd, endo_id, interface_id);
374         if (ret)
375                 return ret;
376
377         /*
378          * Endo and its modules are ready now, fix AP's partially initialized
379          * svc protocol and its connection.
380          */
381         intf = gb_ap_interface_create(hd, connection, interface_id);
382         if (!intf) {
383                 gb_endo_remove(hd->endo);
384                 return ret;
385         }
386
387         return 0;
388 }
389
390 static void svc_intf_remove(struct gb_connection *connection,
391                             struct gb_interface *intf)
392 {
393         struct greybus_host_device *hd = connection->hd;
394         struct gb_svc *svc = connection->private;
395         u8 intf_id = intf->interface_id;
396         u8 device_id;
397
398         device_id = intf->device_id;
399         gb_interface_remove(intf);
400
401         /*
402          * Destroy the two-way route between the AP and the interface.
403          */
404         gb_svc_route_destroy(svc, hd->endo->ap_intf_id, intf_id);
405
406         ida_simple_remove(&svc->device_id_map, device_id);
407 }
408
409 /*
410  * 'struct svc_hotplug' should be freed by svc_process_hotplug() before it
411  * returns, irrespective of success or Failure in bringing up the module.
412  */
413 static void svc_process_hotplug(struct work_struct *work)
414 {
415         struct svc_hotplug *svc_hotplug = container_of(work, struct svc_hotplug,
416                                                        work);
417         struct gb_svc_intf_hotplug_request *hotplug = &svc_hotplug->data;
418         struct gb_connection *connection = svc_hotplug->connection;
419         struct gb_svc *svc = connection->private;
420         struct greybus_host_device *hd = connection->hd;
421         struct device *dev = &connection->dev;
422         struct gb_interface *intf;
423         u8 intf_id, device_id;
424         int ret;
425
426         /*
427          * Grab the information we need.
428          */
429         intf_id = hotplug->intf_id;
430
431         intf = gb_interface_find(hd, intf_id);
432         if (intf) {
433                 /*
434                  * We have received a hotplug request for an interface that
435                  * already exists.
436                  *
437                  * This can happen in cases like:
438                  * - bootrom loading the firmware image and booting into that,
439                  *   which only generates a hotplug event. i.e. no hot-unplug
440                  *   event.
441                  * - Or the firmware on the module crashed and sent hotplug
442                  *   request again to the SVC, which got propagated to AP.
443                  *
444                  * Remove the interface and add it again, and let user know
445                  * about this with a print message.
446                  */
447                 dev_info(dev, "Removed interface (%hhu) to add it again\n",
448                          intf_id);
449                 svc_intf_remove(connection, intf);
450         }
451
452         intf = gb_interface_create(hd, intf_id);
453         if (!intf) {
454                 dev_err(dev, "%s: Failed to create interface with id %hhu\n",
455                         __func__, intf_id);
456                 goto free_svc_hotplug;
457         }
458
459         ret = gb_svc_read_and_clear_module_boot_status(intf);
460         if (ret)
461                 goto destroy_interface;
462
463         intf->unipro_mfg_id = le32_to_cpu(hotplug->data.unipro_mfg_id);
464         intf->unipro_prod_id = le32_to_cpu(hotplug->data.unipro_prod_id);
465         intf->ara_vend_id = le32_to_cpu(hotplug->data.ara_vend_id);
466         intf->ara_prod_id = le32_to_cpu(hotplug->data.ara_prod_id);
467
468         /*
469          * Create a device id for the interface:
470          * - device id 0 (GB_DEVICE_ID_SVC) belongs to the SVC
471          * - device id 1 (GB_DEVICE_ID_AP) belongs to the AP
472          *
473          * XXX Do we need to allocate device ID for SVC or the AP here? And what
474          * XXX about an AP with multiple interface blocks?
475          */
476         device_id = ida_simple_get(&svc->device_id_map,
477                                    GB_DEVICE_ID_MODULES_START, 0, GFP_KERNEL);
478         if (device_id < 0) {
479                 ret = device_id;
480                 dev_err(dev, "%s: Failed to allocate device id for interface with id %hhu (%d)\n",
481                         __func__, intf_id, ret);
482                 goto destroy_interface;
483         }
484
485         ret = gb_svc_intf_device_id(svc, intf_id, device_id);
486         if (ret) {
487                 dev_err(dev, "%s: Device id operation failed, interface %hhu device_id %hhu (%d)\n",
488                         __func__, intf_id, device_id, ret);
489                 goto ida_put;
490         }
491
492         /*
493          * Create a two-way route between the AP and the new interface
494          */
495         ret = gb_svc_route_create(svc, hd->endo->ap_intf_id, GB_DEVICE_ID_AP,
496                                   intf_id, device_id);
497         if (ret) {
498                 dev_err(dev, "%s: Route create operation failed, interface %hhu device_id %hhu (%d)\n",
499                         __func__, intf_id, device_id, ret);
500                 goto svc_id_free;
501         }
502
503         ret = gb_interface_init(intf, device_id);
504         if (ret) {
505                 dev_err(dev, "%s: Failed to initialize interface, interface %hhu device_id %hhu (%d)\n",
506                         __func__, intf_id, device_id, ret);
507                 goto destroy_route;
508         }
509
510         goto free_svc_hotplug;
511
512 destroy_route:
513         gb_svc_route_destroy(svc, hd->endo->ap_intf_id, intf_id);
514 svc_id_free:
515         /*
516          * XXX Should we tell SVC that this id doesn't belong to interface
517          * XXX anymore.
518          */
519 ida_put:
520         ida_simple_remove(&svc->device_id_map, device_id);
521 destroy_interface:
522         gb_interface_remove(intf);
523 free_svc_hotplug:
524         kfree(svc_hotplug);
525 }
526
527 /*
528  * Bringing up a module can be time consuming, as that may require lots of
529  * initialization on the module side. Over that, we may also need to download
530  * the firmware first and flash that on the module.
531  *
532  * In order to make other hotplug events to not wait for all this to finish,
533  * handle most of module hotplug stuff outside of the hotplug callback, with
534  * help of a workqueue.
535  */
536 static int gb_svc_intf_hotplug_recv(struct gb_operation *op)
537 {
538         struct gb_message *request = op->request;
539         struct svc_hotplug *svc_hotplug;
540
541         if (request->payload_size < sizeof(svc_hotplug->data)) {
542                 dev_err(&op->connection->dev,
543                         "%s: short hotplug request received (%zu < %zu)\n",
544                         __func__, request->payload_size,
545                         sizeof(svc_hotplug->data));
546                 return -EINVAL;
547         }
548
549         svc_hotplug = kmalloc(sizeof(*svc_hotplug), GFP_KERNEL);
550         if (!svc_hotplug)
551                 return -ENOMEM;
552
553         svc_hotplug->connection = op->connection;
554         memcpy(&svc_hotplug->data, op->request->payload, sizeof(svc_hotplug->data));
555
556         INIT_WORK(&svc_hotplug->work, svc_process_hotplug);
557         queue_work(system_unbound_wq, &svc_hotplug->work);
558
559         return 0;
560 }
561
562 static int gb_svc_intf_hot_unplug_recv(struct gb_operation *op)
563 {
564         struct gb_message *request = op->request;
565         struct gb_svc_intf_hot_unplug_request *hot_unplug = request->payload;
566         struct greybus_host_device *hd = op->connection->hd;
567         struct device *dev = &op->connection->dev;
568         struct gb_interface *intf;
569         u8 intf_id;
570
571         if (request->payload_size < sizeof(*hot_unplug)) {
572                 dev_err(dev, "short hot unplug request received (%zu < %zu)\n",
573                         request->payload_size, sizeof(*hot_unplug));
574                 return -EINVAL;
575         }
576
577         intf_id = hot_unplug->intf_id;
578
579         intf = gb_interface_find(hd, intf_id);
580         if (!intf) {
581                 dev_err(dev, "%s: Couldn't find interface for id %hhu\n",
582                         __func__, intf_id);
583                 return -EINVAL;
584         }
585
586         svc_intf_remove(op->connection, intf);
587
588         return 0;
589 }
590
591 static int gb_svc_intf_reset_recv(struct gb_operation *op)
592 {
593         struct gb_message *request = op->request;
594         struct gb_svc_intf_reset_request *reset;
595         u8 intf_id;
596
597         if (request->payload_size < sizeof(*reset)) {
598                 dev_err(&op->connection->dev,
599                         "short reset request received (%zu < %zu)\n",
600                         request->payload_size, sizeof(*reset));
601                 return -EINVAL;
602         }
603         reset = request->payload;
604
605         intf_id = reset->intf_id;
606
607         /* FIXME Reset the interface here */
608
609         return 0;
610 }
611
612 static int gb_svc_request_recv(u8 type, struct gb_operation *op)
613 {
614         struct gb_connection *connection = op->connection;
615         struct gb_svc *svc = connection->private;
616         int ret = 0;
617
618         /*
619          * SVC requests need to follow a specific order (at least initially) and
620          * below code takes care of enforcing that. The expected order is:
621          * - PROTOCOL_VERSION
622          * - SVC_HELLO
623          * - Any other request, but the earlier two.
624          *
625          * Incoming requests are guaranteed to be serialized and so we don't
626          * need to protect 'state' for any races.
627          */
628         switch (type) {
629         case GB_REQUEST_TYPE_PROTOCOL_VERSION:
630                 if (svc->state != GB_SVC_STATE_RESET)
631                         ret = -EINVAL;
632                 break;
633         case GB_SVC_TYPE_SVC_HELLO:
634                 if (svc->state != GB_SVC_STATE_PROTOCOL_VERSION)
635                         ret = -EINVAL;
636                 break;
637         default:
638                 if (svc->state != GB_SVC_STATE_SVC_HELLO)
639                         ret = -EINVAL;
640                 break;
641         }
642
643         if (ret) {
644                 dev_warn(&connection->dev,
645                          "unexpected SVC request 0x%02x received (state %u)\n",
646                          type, svc->state);
647                 return ret;
648         }
649
650         switch (type) {
651         case GB_REQUEST_TYPE_PROTOCOL_VERSION:
652                 ret = gb_svc_version_request(op);
653                 if (!ret)
654                         svc->state = GB_SVC_STATE_PROTOCOL_VERSION;
655                 return ret;
656         case GB_SVC_TYPE_SVC_HELLO:
657                 ret = gb_svc_hello(op);
658                 if (!ret)
659                         svc->state = GB_SVC_STATE_SVC_HELLO;
660                 return ret;
661         case GB_SVC_TYPE_INTF_HOTPLUG:
662                 return gb_svc_intf_hotplug_recv(op);
663         case GB_SVC_TYPE_INTF_HOT_UNPLUG:
664                 return gb_svc_intf_hot_unplug_recv(op);
665         case GB_SVC_TYPE_INTF_RESET:
666                 return gb_svc_intf_reset_recv(op);
667         default:
668                 dev_err(&op->connection->dev,
669                         "unsupported request: %hhu\n", type);
670                 return -EINVAL;
671         }
672 }
673
674 static int gb_svc_connection_init(struct gb_connection *connection)
675 {
676         struct gb_svc *svc;
677
678         svc = kzalloc(sizeof(*svc), GFP_KERNEL);
679         if (!svc)
680                 return -ENOMEM;
681
682         connection->hd->svc = svc;
683         svc->state = GB_SVC_STATE_RESET;
684         svc->connection = connection;
685         connection->private = svc;
686
687         WARN_ON(connection->hd->initial_svc_connection);
688         connection->hd->initial_svc_connection = connection;
689
690         ida_init(&svc->device_id_map);
691
692         return 0;
693 }
694
695 static void gb_svc_connection_exit(struct gb_connection *connection)
696 {
697         struct gb_svc *svc = connection->private;
698
699         ida_destroy(&svc->device_id_map);
700         connection->hd->svc = NULL;
701         connection->private = NULL;
702         kfree(svc);
703 }
704
705 static struct gb_protocol svc_protocol = {
706         .name                   = "svc",
707         .id                     = GREYBUS_PROTOCOL_SVC,
708         .major                  = GB_SVC_VERSION_MAJOR,
709         .minor                  = GB_SVC_VERSION_MINOR,
710         .connection_init        = gb_svc_connection_init,
711         .connection_exit        = gb_svc_connection_exit,
712         .request_recv           = gb_svc_request_recv,
713         .flags                  = GB_PROTOCOL_SKIP_CONTROL_CONNECTED |
714                                   GB_PROTOCOL_SKIP_CONTROL_DISCONNECTED |
715                                   GB_PROTOCOL_NO_BUNDLE |
716                                   GB_PROTOCOL_SKIP_VERSION |
717                                   GB_PROTOCOL_SKIP_SVC_CONNECTION,
718 };
719 gb_builtin_protocol_driver(svc_protocol);