Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / misc / mei / bus.c
blob718ec5d81d940f6e8633a8e866e28a3a331182e4
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2012-2023, Intel Corporation. All rights reserved.
4 * Intel Management Engine Interface (Intel MEI) Linux driver
5 */
7 #include <linux/module.h>
8 #include <linux/device.h>
9 #include <linux/kernel.h>
10 #include <linux/sched/signal.h>
11 #include <linux/init.h>
12 #include <linux/errno.h>
13 #include <linux/slab.h>
14 #include <linux/mutex.h>
15 #include <linux/interrupt.h>
16 #include <linux/scatterlist.h>
17 #include <linux/mei_cl_bus.h>
19 #include "mei_dev.h"
20 #include "client.h"
22 #define to_mei_cl_driver(d) container_of_const(d, struct mei_cl_driver, driver)
24 /**
25 * __mei_cl_send - internal client send (write)
27 * @cl: host client
28 * @buf: buffer to send
29 * @length: buffer length
30 * @vtag: virtual tag
31 * @mode: sending mode
33 * Return: written size bytes or < 0 on error
35 ssize_t __mei_cl_send(struct mei_cl *cl, const u8 *buf, size_t length, u8 vtag,
36 unsigned int mode)
38 return __mei_cl_send_timeout(cl, buf, length, vtag, mode, MAX_SCHEDULE_TIMEOUT);
41 /**
42 * __mei_cl_send_timeout - internal client send (write)
44 * @cl: host client
45 * @buf: buffer to send
46 * @length: buffer length
47 * @vtag: virtual tag
48 * @mode: sending mode
49 * @timeout: send timeout in milliseconds.
50 * effective only for blocking writes: the MEI_CL_IO_TX_BLOCKING mode bit is set.
51 * set timeout to the MAX_SCHEDULE_TIMEOUT to maixum allowed wait.
53 * Return: written size bytes or < 0 on error
55 ssize_t __mei_cl_send_timeout(struct mei_cl *cl, const u8 *buf, size_t length, u8 vtag,
56 unsigned int mode, unsigned long timeout)
58 struct mei_device *bus;
59 struct mei_cl_cb *cb;
60 ssize_t rets;
62 if (WARN_ON(!cl || !cl->dev))
63 return -ENODEV;
65 bus = cl->dev;
67 mutex_lock(&bus->device_lock);
68 if (bus->dev_state != MEI_DEV_ENABLED &&
69 bus->dev_state != MEI_DEV_POWERING_DOWN) {
70 rets = -ENODEV;
71 goto out;
74 if (!mei_cl_is_connected(cl)) {
75 rets = -ENODEV;
76 goto out;
79 /* Check if we have an ME client device */
80 if (!mei_me_cl_is_active(cl->me_cl)) {
81 rets = -ENOTTY;
82 goto out;
85 if (vtag) {
86 /* Check if vtag is supported by client */
87 rets = mei_cl_vt_support_check(cl);
88 if (rets)
89 goto out;
92 if (length > mei_cl_mtu(cl)) {
93 rets = -EFBIG;
94 goto out;
97 while (cl->tx_cb_queued >= bus->tx_queue_limit) {
98 mutex_unlock(&bus->device_lock);
99 rets = wait_event_interruptible(cl->tx_wait,
100 cl->writing_state == MEI_WRITE_COMPLETE ||
101 (!mei_cl_is_connected(cl)));
102 mutex_lock(&bus->device_lock);
103 if (rets) {
104 if (signal_pending(current))
105 rets = -EINTR;
106 goto out;
108 if (!mei_cl_is_connected(cl)) {
109 rets = -ENODEV;
110 goto out;
114 cb = mei_cl_alloc_cb(cl, length, MEI_FOP_WRITE, NULL);
115 if (!cb) {
116 rets = -ENOMEM;
117 goto out;
119 cb->vtag = vtag;
121 cb->internal = !!(mode & MEI_CL_IO_TX_INTERNAL);
122 cb->blocking = !!(mode & MEI_CL_IO_TX_BLOCKING);
123 memcpy(cb->buf.data, buf, length);
124 /* hack we point data to header */
125 if (mode & MEI_CL_IO_SGL) {
126 cb->ext_hdr = (struct mei_ext_hdr *)cb->buf.data;
127 cb->buf.data = NULL;
128 cb->buf.size = 0;
131 rets = mei_cl_write(cl, cb, timeout);
133 if (mode & MEI_CL_IO_SGL && rets == 0)
134 rets = length;
136 out:
137 mutex_unlock(&bus->device_lock);
139 return rets;
143 * __mei_cl_recv - internal client receive (read)
145 * @cl: host client
146 * @buf: buffer to receive
147 * @length: buffer length
148 * @vtag: virtual tag
149 * @mode: io mode
150 * @timeout: recv timeout, 0 for infinite timeout
152 * Return: read size in bytes of < 0 on error
154 ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length, u8 *vtag,
155 unsigned int mode, unsigned long timeout)
157 struct mei_device *bus;
158 struct mei_cl_cb *cb;
159 size_t r_length;
160 ssize_t rets;
161 bool nonblock = !!(mode & MEI_CL_IO_RX_NONBLOCK);
163 if (WARN_ON(!cl || !cl->dev))
164 return -ENODEV;
166 bus = cl->dev;
168 mutex_lock(&bus->device_lock);
169 if (bus->dev_state != MEI_DEV_ENABLED &&
170 bus->dev_state != MEI_DEV_POWERING_DOWN) {
171 rets = -ENODEV;
172 goto out;
175 cb = mei_cl_read_cb(cl, NULL);
176 if (cb)
177 goto copy;
179 rets = mei_cl_read_start(cl, length, NULL);
180 if (rets && rets != -EBUSY)
181 goto out;
183 if (nonblock) {
184 rets = -EAGAIN;
185 goto out;
188 /* wait on event only if there is no other waiter */
189 /* synchronized under device mutex */
190 if (!waitqueue_active(&cl->rx_wait)) {
192 mutex_unlock(&bus->device_lock);
194 if (timeout) {
195 rets = wait_event_interruptible_timeout
196 (cl->rx_wait,
197 mei_cl_read_cb(cl, NULL) ||
198 (!mei_cl_is_connected(cl)),
199 msecs_to_jiffies(timeout));
200 if (rets == 0)
201 return -ETIME;
202 if (rets < 0) {
203 if (signal_pending(current))
204 return -EINTR;
205 return -ERESTARTSYS;
207 } else {
208 if (wait_event_interruptible
209 (cl->rx_wait,
210 mei_cl_read_cb(cl, NULL) ||
211 (!mei_cl_is_connected(cl)))) {
212 if (signal_pending(current))
213 return -EINTR;
214 return -ERESTARTSYS;
218 mutex_lock(&bus->device_lock);
220 if (!mei_cl_is_connected(cl)) {
221 rets = -ENODEV;
222 goto out;
226 cb = mei_cl_read_cb(cl, NULL);
227 if (!cb) {
228 rets = 0;
229 goto out;
232 copy:
233 if (cb->status) {
234 rets = cb->status;
235 goto free;
238 /* for the GSC type - copy the extended header to the buffer */
239 if (cb->ext_hdr && cb->ext_hdr->type == MEI_EXT_HDR_GSC) {
240 r_length = min_t(size_t, length, cb->ext_hdr->length * sizeof(u32));
241 memcpy(buf, cb->ext_hdr, r_length);
242 } else {
243 r_length = min_t(size_t, length, cb->buf_idx);
244 memcpy(buf, cb->buf.data, r_length);
246 rets = r_length;
248 if (vtag)
249 *vtag = cb->vtag;
251 free:
252 mei_cl_del_rd_completed(cl, cb);
253 out:
254 mutex_unlock(&bus->device_lock);
256 return rets;
260 * mei_cldev_send_vtag - me device send with vtag (write)
262 * @cldev: me client device
263 * @buf: buffer to send
264 * @length: buffer length
265 * @vtag: virtual tag
267 * Return:
268 * * written size in bytes
269 * * < 0 on error
272 ssize_t mei_cldev_send_vtag(struct mei_cl_device *cldev, const u8 *buf,
273 size_t length, u8 vtag)
275 struct mei_cl *cl = cldev->cl;
277 return __mei_cl_send(cl, buf, length, vtag, MEI_CL_IO_TX_BLOCKING);
279 EXPORT_SYMBOL_GPL(mei_cldev_send_vtag);
282 * mei_cldev_send_vtag_timeout - me device send with vtag and timeout (write)
284 * @cldev: me client device
285 * @buf: buffer to send
286 * @length: buffer length
287 * @vtag: virtual tag
288 * @timeout: send timeout in milliseconds, 0 for infinite timeout
290 * Return:
291 * * written size in bytes
292 * * < 0 on error
295 ssize_t mei_cldev_send_vtag_timeout(struct mei_cl_device *cldev, const u8 *buf,
296 size_t length, u8 vtag, unsigned long timeout)
298 struct mei_cl *cl = cldev->cl;
300 return __mei_cl_send_timeout(cl, buf, length, vtag, MEI_CL_IO_TX_BLOCKING, timeout);
302 EXPORT_SYMBOL_GPL(mei_cldev_send_vtag_timeout);
305 * mei_cldev_recv_vtag - client receive with vtag (read)
307 * @cldev: me client device
308 * @buf: buffer to receive
309 * @length: buffer length
310 * @vtag: virtual tag
312 * Return:
313 * * read size in bytes
314 * * < 0 on error
317 ssize_t mei_cldev_recv_vtag(struct mei_cl_device *cldev, u8 *buf, size_t length,
318 u8 *vtag)
320 struct mei_cl *cl = cldev->cl;
322 return __mei_cl_recv(cl, buf, length, vtag, 0, 0);
324 EXPORT_SYMBOL_GPL(mei_cldev_recv_vtag);
327 * mei_cldev_recv_nonblock_vtag - non block client receive with vtag (read)
329 * @cldev: me client device
330 * @buf: buffer to receive
331 * @length: buffer length
332 * @vtag: virtual tag
334 * Return:
335 * * read size in bytes
336 * * -EAGAIN if function will block.
337 * * < 0 on other error
339 ssize_t mei_cldev_recv_nonblock_vtag(struct mei_cl_device *cldev, u8 *buf,
340 size_t length, u8 *vtag)
342 struct mei_cl *cl = cldev->cl;
344 return __mei_cl_recv(cl, buf, length, vtag, MEI_CL_IO_RX_NONBLOCK, 0);
346 EXPORT_SYMBOL_GPL(mei_cldev_recv_nonblock_vtag);
349 * mei_cldev_recv_timeout - client receive with timeout (read)
351 * @cldev: me client device
352 * @buf: buffer to receive
353 * @length: buffer length
354 * @timeout: send timeout in milliseconds, 0 for infinite timeout
356 * Return:
357 * * read size in bytes
358 * * < 0 on error
360 ssize_t mei_cldev_recv_timeout(struct mei_cl_device *cldev, u8 *buf, size_t length,
361 unsigned long timeout)
363 return mei_cldev_recv_vtag_timeout(cldev, buf, length, NULL, timeout);
365 EXPORT_SYMBOL_GPL(mei_cldev_recv_timeout);
368 * mei_cldev_recv_vtag_timeout - client receive with vtag (read)
370 * @cldev: me client device
371 * @buf: buffer to receive
372 * @length: buffer length
373 * @vtag: virtual tag
374 * @timeout: recv timeout in milliseconds, 0 for infinite timeout
376 * Return:
377 * * read size in bytes
378 * * < 0 on error
381 ssize_t mei_cldev_recv_vtag_timeout(struct mei_cl_device *cldev, u8 *buf, size_t length,
382 u8 *vtag, unsigned long timeout)
384 struct mei_cl *cl = cldev->cl;
386 return __mei_cl_recv(cl, buf, length, vtag, 0, timeout);
388 EXPORT_SYMBOL_GPL(mei_cldev_recv_vtag_timeout);
391 * mei_cldev_send - me device send (write)
393 * @cldev: me client device
394 * @buf: buffer to send
395 * @length: buffer length
397 * Return:
398 * * written size in bytes
399 * * < 0 on error
401 ssize_t mei_cldev_send(struct mei_cl_device *cldev, const u8 *buf, size_t length)
403 return mei_cldev_send_vtag(cldev, buf, length, 0);
405 EXPORT_SYMBOL_GPL(mei_cldev_send);
408 * mei_cldev_send_timeout - me device send with timeout (write)
410 * @cldev: me client device
411 * @buf: buffer to send
412 * @length: buffer length
413 * @timeout: send timeout in milliseconds, 0 for infinite timeout
415 * Return:
416 * * written size in bytes
417 * * < 0 on error
419 ssize_t mei_cldev_send_timeout(struct mei_cl_device *cldev, const u8 *buf, size_t length,
420 unsigned long timeout)
422 return mei_cldev_send_vtag_timeout(cldev, buf, length, 0, timeout);
424 EXPORT_SYMBOL_GPL(mei_cldev_send_timeout);
427 * mei_cldev_recv - client receive (read)
429 * @cldev: me client device
430 * @buf: buffer to receive
431 * @length: buffer length
433 * Return: read size in bytes of < 0 on error
435 ssize_t mei_cldev_recv(struct mei_cl_device *cldev, u8 *buf, size_t length)
437 return mei_cldev_recv_vtag(cldev, buf, length, NULL);
439 EXPORT_SYMBOL_GPL(mei_cldev_recv);
442 * mei_cldev_recv_nonblock - non block client receive (read)
444 * @cldev: me client device
445 * @buf: buffer to receive
446 * @length: buffer length
448 * Return: read size in bytes of < 0 on error
449 * -EAGAIN if function will block.
451 ssize_t mei_cldev_recv_nonblock(struct mei_cl_device *cldev, u8 *buf,
452 size_t length)
454 return mei_cldev_recv_nonblock_vtag(cldev, buf, length, NULL);
456 EXPORT_SYMBOL_GPL(mei_cldev_recv_nonblock);
459 * mei_cl_bus_rx_work - dispatch rx event for a bus device
461 * @work: work
463 static void mei_cl_bus_rx_work(struct work_struct *work)
465 struct mei_cl_device *cldev;
466 struct mei_device *bus;
468 cldev = container_of(work, struct mei_cl_device, rx_work);
470 bus = cldev->bus;
472 if (cldev->rx_cb)
473 cldev->rx_cb(cldev);
475 mutex_lock(&bus->device_lock);
476 if (mei_cl_is_connected(cldev->cl))
477 mei_cl_read_start(cldev->cl, mei_cl_mtu(cldev->cl), NULL);
478 mutex_unlock(&bus->device_lock);
482 * mei_cl_bus_notif_work - dispatch FW notif event for a bus device
484 * @work: work
486 static void mei_cl_bus_notif_work(struct work_struct *work)
488 struct mei_cl_device *cldev;
490 cldev = container_of(work, struct mei_cl_device, notif_work);
492 if (cldev->notif_cb)
493 cldev->notif_cb(cldev);
497 * mei_cl_bus_notify_event - schedule notify cb on bus client
499 * @cl: host client
501 * Return: true if event was scheduled
502 * false if the client is not waiting for event
504 bool mei_cl_bus_notify_event(struct mei_cl *cl)
506 struct mei_cl_device *cldev = cl->cldev;
508 if (!cldev || !cldev->notif_cb)
509 return false;
511 if (!cl->notify_ev)
512 return false;
514 schedule_work(&cldev->notif_work);
516 cl->notify_ev = false;
518 return true;
522 * mei_cl_bus_rx_event - schedule rx event
524 * @cl: host client
526 * Return: true if event was scheduled
527 * false if the client is not waiting for event
529 bool mei_cl_bus_rx_event(struct mei_cl *cl)
531 struct mei_cl_device *cldev = cl->cldev;
533 if (!cldev || !cldev->rx_cb)
534 return false;
536 schedule_work(&cldev->rx_work);
538 return true;
542 * mei_cldev_register_rx_cb - register Rx event callback
544 * @cldev: me client devices
545 * @rx_cb: callback function
547 * Return: 0 on success
548 * -EALREADY if an callback is already registered
549 * <0 on other errors
551 int mei_cldev_register_rx_cb(struct mei_cl_device *cldev, mei_cldev_cb_t rx_cb)
553 struct mei_device *bus = cldev->bus;
554 int ret;
556 if (!rx_cb)
557 return -EINVAL;
558 if (cldev->rx_cb)
559 return -EALREADY;
561 cldev->rx_cb = rx_cb;
562 INIT_WORK(&cldev->rx_work, mei_cl_bus_rx_work);
564 mutex_lock(&bus->device_lock);
565 if (mei_cl_is_connected(cldev->cl))
566 ret = mei_cl_read_start(cldev->cl, mei_cl_mtu(cldev->cl), NULL);
567 else
568 ret = -ENODEV;
569 mutex_unlock(&bus->device_lock);
570 if (ret && ret != -EBUSY) {
571 cancel_work_sync(&cldev->rx_work);
572 cldev->rx_cb = NULL;
573 return ret;
576 return 0;
578 EXPORT_SYMBOL_GPL(mei_cldev_register_rx_cb);
581 * mei_cldev_register_notif_cb - register FW notification event callback
583 * @cldev: me client devices
584 * @notif_cb: callback function
586 * Return: 0 on success
587 * -EALREADY if an callback is already registered
588 * <0 on other errors
590 int mei_cldev_register_notif_cb(struct mei_cl_device *cldev,
591 mei_cldev_cb_t notif_cb)
593 struct mei_device *bus = cldev->bus;
594 int ret;
596 if (!notif_cb)
597 return -EINVAL;
599 if (cldev->notif_cb)
600 return -EALREADY;
602 cldev->notif_cb = notif_cb;
603 INIT_WORK(&cldev->notif_work, mei_cl_bus_notif_work);
605 mutex_lock(&bus->device_lock);
606 ret = mei_cl_notify_request(cldev->cl, NULL, 1);
607 mutex_unlock(&bus->device_lock);
608 if (ret) {
609 cancel_work_sync(&cldev->notif_work);
610 cldev->notif_cb = NULL;
611 return ret;
614 return 0;
616 EXPORT_SYMBOL_GPL(mei_cldev_register_notif_cb);
619 * mei_cldev_get_drvdata - driver data getter
621 * @cldev: mei client device
623 * Return: driver private data
625 void *mei_cldev_get_drvdata(const struct mei_cl_device *cldev)
627 return dev_get_drvdata(&cldev->dev);
629 EXPORT_SYMBOL_GPL(mei_cldev_get_drvdata);
632 * mei_cldev_set_drvdata - driver data setter
634 * @cldev: mei client device
635 * @data: data to store
637 void mei_cldev_set_drvdata(struct mei_cl_device *cldev, void *data)
639 dev_set_drvdata(&cldev->dev, data);
641 EXPORT_SYMBOL_GPL(mei_cldev_set_drvdata);
644 * mei_cldev_uuid - return uuid of the underlying me client
646 * @cldev: mei client device
648 * Return: me client uuid
650 const uuid_le *mei_cldev_uuid(const struct mei_cl_device *cldev)
652 return mei_me_cl_uuid(cldev->me_cl);
654 EXPORT_SYMBOL_GPL(mei_cldev_uuid);
657 * mei_cldev_ver - return protocol version of the underlying me client
659 * @cldev: mei client device
661 * Return: me client protocol version
663 u8 mei_cldev_ver(const struct mei_cl_device *cldev)
665 return mei_me_cl_ver(cldev->me_cl);
667 EXPORT_SYMBOL_GPL(mei_cldev_ver);
670 * mei_cldev_enabled - check whether the device is enabled
672 * @cldev: mei client device
674 * Return: true if me client is initialized and connected
676 bool mei_cldev_enabled(const struct mei_cl_device *cldev)
678 return mei_cl_is_connected(cldev->cl);
680 EXPORT_SYMBOL_GPL(mei_cldev_enabled);
683 * mei_cl_bus_module_get - acquire module of the underlying
684 * hw driver.
686 * @cldev: mei client device
688 * Return: true on success; false if the module was removed.
690 static bool mei_cl_bus_module_get(struct mei_cl_device *cldev)
692 return try_module_get(cldev->bus->dev->driver->owner);
696 * mei_cl_bus_module_put - release the underlying hw module.
698 * @cldev: mei client device
700 static void mei_cl_bus_module_put(struct mei_cl_device *cldev)
702 module_put(cldev->bus->dev->driver->owner);
706 * mei_cl_bus_vtag - get bus vtag entry wrapper
707 * The tag for bus client is always first.
709 * @cl: host client
711 * Return: bus vtag or NULL
713 static inline struct mei_cl_vtag *mei_cl_bus_vtag(struct mei_cl *cl)
715 return list_first_entry_or_null(&cl->vtag_map,
716 struct mei_cl_vtag, list);
720 * mei_cl_bus_vtag_alloc - add bus client entry to vtag map
722 * @cldev: me client device
724 * Return:
725 * * 0 on success
726 * * -ENOMEM if memory allocation failed
728 static int mei_cl_bus_vtag_alloc(struct mei_cl_device *cldev)
730 struct mei_cl *cl = cldev->cl;
731 struct mei_cl_vtag *cl_vtag;
734 * Bail out if the client does not supports vtags
735 * or has already allocated one
737 if (mei_cl_vt_support_check(cl) || mei_cl_bus_vtag(cl))
738 return 0;
740 cl_vtag = mei_cl_vtag_alloc(NULL, 0);
741 if (IS_ERR(cl_vtag))
742 return -ENOMEM;
744 list_add_tail(&cl_vtag->list, &cl->vtag_map);
746 return 0;
750 * mei_cl_bus_vtag_free - remove the bus entry from vtag map
752 * @cldev: me client device
754 static void mei_cl_bus_vtag_free(struct mei_cl_device *cldev)
756 struct mei_cl *cl = cldev->cl;
757 struct mei_cl_vtag *cl_vtag;
759 cl_vtag = mei_cl_bus_vtag(cl);
760 if (!cl_vtag)
761 return;
763 list_del(&cl_vtag->list);
764 kfree(cl_vtag);
767 void *mei_cldev_dma_map(struct mei_cl_device *cldev, u8 buffer_id, size_t size)
769 struct mei_device *bus;
770 struct mei_cl *cl;
771 int ret;
773 if (!cldev || !buffer_id || !size)
774 return ERR_PTR(-EINVAL);
776 if (!IS_ALIGNED(size, MEI_FW_PAGE_SIZE)) {
777 dev_err(&cldev->dev, "Map size should be aligned to %lu\n",
778 MEI_FW_PAGE_SIZE);
779 return ERR_PTR(-EINVAL);
782 cl = cldev->cl;
783 bus = cldev->bus;
785 mutex_lock(&bus->device_lock);
786 if (cl->state == MEI_FILE_UNINITIALIZED) {
787 ret = mei_cl_link(cl);
788 if (ret)
789 goto notlinked;
790 /* update pointers */
791 cl->cldev = cldev;
794 ret = mei_cl_dma_alloc_and_map(cl, NULL, buffer_id, size);
795 if (ret)
796 mei_cl_unlink(cl);
797 notlinked:
798 mutex_unlock(&bus->device_lock);
799 if (ret)
800 return ERR_PTR(ret);
801 return cl->dma.vaddr;
803 EXPORT_SYMBOL_GPL(mei_cldev_dma_map);
805 int mei_cldev_dma_unmap(struct mei_cl_device *cldev)
807 struct mei_device *bus;
808 struct mei_cl *cl;
809 int ret;
811 if (!cldev)
812 return -EINVAL;
814 cl = cldev->cl;
815 bus = cldev->bus;
817 mutex_lock(&bus->device_lock);
818 ret = mei_cl_dma_unmap(cl, NULL);
820 mei_cl_flush_queues(cl, NULL);
821 mei_cl_unlink(cl);
822 mutex_unlock(&bus->device_lock);
823 return ret;
825 EXPORT_SYMBOL_GPL(mei_cldev_dma_unmap);
828 * mei_cldev_enable - enable me client device
829 * create connection with me client
831 * @cldev: me client device
833 * Return: 0 on success and < 0 on error
835 int mei_cldev_enable(struct mei_cl_device *cldev)
837 struct mei_device *bus = cldev->bus;
838 struct mei_cl *cl;
839 int ret;
841 cl = cldev->cl;
843 mutex_lock(&bus->device_lock);
844 if (cl->state == MEI_FILE_UNINITIALIZED) {
845 ret = mei_cl_link(cl);
846 if (ret)
847 goto notlinked;
848 /* update pointers */
849 cl->cldev = cldev;
852 if (mei_cl_is_connected(cl)) {
853 ret = 0;
854 goto out;
857 if (!mei_me_cl_is_active(cldev->me_cl)) {
858 dev_err(&cldev->dev, "me client is not active\n");
859 ret = -ENOTTY;
860 goto out;
863 ret = mei_cl_bus_vtag_alloc(cldev);
864 if (ret)
865 goto out;
867 ret = mei_cl_connect(cl, cldev->me_cl, NULL);
868 if (ret < 0) {
869 dev_err(&cldev->dev, "cannot connect\n");
870 mei_cl_bus_vtag_free(cldev);
873 out:
874 if (ret)
875 mei_cl_unlink(cl);
876 notlinked:
877 mutex_unlock(&bus->device_lock);
879 return ret;
881 EXPORT_SYMBOL_GPL(mei_cldev_enable);
884 * mei_cldev_unregister_callbacks - internal wrapper for unregistering
885 * callbacks.
887 * @cldev: client device
889 static void mei_cldev_unregister_callbacks(struct mei_cl_device *cldev)
891 if (cldev->rx_cb) {
892 cancel_work_sync(&cldev->rx_work);
893 cldev->rx_cb = NULL;
896 if (cldev->notif_cb) {
897 cancel_work_sync(&cldev->notif_work);
898 cldev->notif_cb = NULL;
903 * mei_cldev_disable - disable me client device
904 * disconnect form the me client
906 * @cldev: me client device
908 * Return: 0 on success and < 0 on error
910 int mei_cldev_disable(struct mei_cl_device *cldev)
912 struct mei_device *bus;
913 struct mei_cl *cl;
914 int err;
916 if (!cldev)
917 return -ENODEV;
919 cl = cldev->cl;
921 bus = cldev->bus;
923 mei_cldev_unregister_callbacks(cldev);
925 mutex_lock(&bus->device_lock);
927 mei_cl_bus_vtag_free(cldev);
929 if (!mei_cl_is_connected(cl)) {
930 dev_dbg(bus->dev, "Already disconnected\n");
931 err = 0;
932 goto out;
935 err = mei_cl_disconnect(cl);
936 if (err < 0)
937 dev_err(bus->dev, "Could not disconnect from the ME client\n");
939 out:
940 /* Flush queues and remove any pending read unless we have mapped DMA */
941 if (!cl->dma_mapped) {
942 mei_cl_flush_queues(cl, NULL);
943 mei_cl_unlink(cl);
946 mutex_unlock(&bus->device_lock);
947 return err;
949 EXPORT_SYMBOL_GPL(mei_cldev_disable);
952 * mei_cldev_send_gsc_command - sends a gsc command, by sending
953 * a gsl mei message to gsc and receiving reply from gsc
955 * @cldev: me client device
956 * @client_id: client id to send the command to
957 * @fence_id: fence id to send the command to
958 * @sg_in: scatter gather list containing addresses for rx message buffer
959 * @total_in_len: total length of data in 'in' sg, can be less than the sum of buffers sizes
960 * @sg_out: scatter gather list containing addresses for tx message buffer
962 * Return:
963 * * written size in bytes
964 * * < 0 on error
966 ssize_t mei_cldev_send_gsc_command(struct mei_cl_device *cldev,
967 u8 client_id, u32 fence_id,
968 struct scatterlist *sg_in,
969 size_t total_in_len,
970 struct scatterlist *sg_out)
972 struct mei_cl *cl;
973 struct mei_device *bus;
974 ssize_t ret = 0;
976 struct mei_ext_hdr_gsc_h2f *ext_hdr;
977 size_t buf_sz = sizeof(struct mei_ext_hdr_gsc_h2f);
978 int sg_out_nents, sg_in_nents;
979 int i;
980 struct scatterlist *sg;
981 struct mei_ext_hdr_gsc_f2h rx_msg;
982 unsigned int sg_len;
984 if (!cldev || !sg_in || !sg_out)
985 return -EINVAL;
987 cl = cldev->cl;
988 bus = cldev->bus;
990 dev_dbg(bus->dev, "client_id %u, fence_id %u\n", client_id, fence_id);
992 if (!bus->hbm_f_gsc_supported)
993 return -EOPNOTSUPP;
995 sg_out_nents = sg_nents(sg_out);
996 sg_in_nents = sg_nents(sg_in);
997 /* at least one entry in tx and rx sgls must be present */
998 if (sg_out_nents <= 0 || sg_in_nents <= 0)
999 return -EINVAL;
1001 buf_sz += (sg_out_nents + sg_in_nents) * sizeof(struct mei_gsc_sgl);
1002 ext_hdr = kzalloc(buf_sz, GFP_KERNEL);
1003 if (!ext_hdr)
1004 return -ENOMEM;
1006 /* construct the GSC message */
1007 ext_hdr->hdr.type = MEI_EXT_HDR_GSC;
1008 ext_hdr->hdr.length = buf_sz / sizeof(u32); /* length is in dw */
1010 ext_hdr->client_id = client_id;
1011 ext_hdr->addr_type = GSC_ADDRESS_TYPE_PHYSICAL_SGL;
1012 ext_hdr->fence_id = fence_id;
1013 ext_hdr->input_address_count = sg_in_nents;
1014 ext_hdr->output_address_count = sg_out_nents;
1015 ext_hdr->reserved[0] = 0;
1016 ext_hdr->reserved[1] = 0;
1018 /* copy in-sgl to the message */
1019 for (i = 0, sg = sg_in; i < sg_in_nents; i++, sg++) {
1020 ext_hdr->sgl[i].low = lower_32_bits(sg_dma_address(sg));
1021 ext_hdr->sgl[i].high = upper_32_bits(sg_dma_address(sg));
1022 sg_len = min_t(unsigned int, sg_dma_len(sg), PAGE_SIZE);
1023 ext_hdr->sgl[i].length = (sg_len <= total_in_len) ? sg_len : total_in_len;
1024 total_in_len -= ext_hdr->sgl[i].length;
1027 /* copy out-sgl to the message */
1028 for (i = sg_in_nents, sg = sg_out; i < sg_in_nents + sg_out_nents; i++, sg++) {
1029 ext_hdr->sgl[i].low = lower_32_bits(sg_dma_address(sg));
1030 ext_hdr->sgl[i].high = upper_32_bits(sg_dma_address(sg));
1031 sg_len = min_t(unsigned int, sg_dma_len(sg), PAGE_SIZE);
1032 ext_hdr->sgl[i].length = sg_len;
1035 /* send the message to GSC */
1036 ret = __mei_cl_send(cl, (u8 *)ext_hdr, buf_sz, 0, MEI_CL_IO_SGL);
1037 if (ret < 0) {
1038 dev_err(bus->dev, "__mei_cl_send failed, returned %zd\n", ret);
1039 goto end;
1041 if (ret != buf_sz) {
1042 dev_err(bus->dev, "__mei_cl_send returned %zd instead of expected %zd\n",
1043 ret, buf_sz);
1044 ret = -EIO;
1045 goto end;
1048 /* receive the reply from GSC, note that at this point sg_in should contain the reply */
1049 ret = __mei_cl_recv(cl, (u8 *)&rx_msg, sizeof(rx_msg), NULL, MEI_CL_IO_SGL, 0);
1051 if (ret != sizeof(rx_msg)) {
1052 dev_err(bus->dev, "__mei_cl_recv returned %zd instead of expected %zd\n",
1053 ret, sizeof(rx_msg));
1054 if (ret >= 0)
1055 ret = -EIO;
1056 goto end;
1059 /* check rx_msg.client_id and rx_msg.fence_id match the ones we send */
1060 if (rx_msg.client_id != client_id || rx_msg.fence_id != fence_id) {
1061 dev_err(bus->dev, "received client_id/fence_id %u/%u instead of %u/%u sent\n",
1062 rx_msg.client_id, rx_msg.fence_id, client_id, fence_id);
1063 ret = -EFAULT;
1064 goto end;
1067 dev_dbg(bus->dev, "gsc command: successfully written %u bytes\n", rx_msg.written);
1068 ret = rx_msg.written;
1070 end:
1071 kfree(ext_hdr);
1072 return ret;
1074 EXPORT_SYMBOL_GPL(mei_cldev_send_gsc_command);
1077 * mei_cl_device_find - find matching entry in the driver id table
1079 * @cldev: me client device
1080 * @cldrv: me client driver
1082 * Return: id on success; NULL if no id is matching
1084 static const
1085 struct mei_cl_device_id *mei_cl_device_find(const struct mei_cl_device *cldev,
1086 const struct mei_cl_driver *cldrv)
1088 const struct mei_cl_device_id *id;
1089 const uuid_le *uuid;
1090 u8 version;
1091 bool match;
1093 uuid = mei_me_cl_uuid(cldev->me_cl);
1094 version = mei_me_cl_ver(cldev->me_cl);
1096 id = cldrv->id_table;
1097 while (uuid_le_cmp(NULL_UUID_LE, id->uuid)) {
1098 if (!uuid_le_cmp(*uuid, id->uuid)) {
1099 match = true;
1101 if (cldev->name[0])
1102 if (strncmp(cldev->name, id->name,
1103 sizeof(id->name)))
1104 match = false;
1106 if (id->version != MEI_CL_VERSION_ANY)
1107 if (id->version != version)
1108 match = false;
1109 if (match)
1110 return id;
1113 id++;
1116 return NULL;
1120 * mei_cl_device_match - device match function
1122 * @dev: device
1123 * @drv: driver
1125 * Return: 1 if matching device was found 0 otherwise
1127 static int mei_cl_device_match(struct device *dev, const struct device_driver *drv)
1129 const struct mei_cl_device *cldev = to_mei_cl_device(dev);
1130 const struct mei_cl_driver *cldrv = to_mei_cl_driver(drv);
1131 const struct mei_cl_device_id *found_id;
1133 if (!cldev->do_match)
1134 return 0;
1136 if (!cldrv || !cldrv->id_table)
1137 return 0;
1139 found_id = mei_cl_device_find(cldev, cldrv);
1140 if (found_id)
1141 return 1;
1143 return 0;
1147 * mei_cl_device_probe - bus probe function
1149 * @dev: device
1151 * Return: 0 on success; < 0 otherwise
1153 static int mei_cl_device_probe(struct device *dev)
1155 struct mei_cl_device *cldev;
1156 struct mei_cl_driver *cldrv;
1157 const struct mei_cl_device_id *id;
1158 int ret;
1160 cldev = to_mei_cl_device(dev);
1161 cldrv = to_mei_cl_driver(dev->driver);
1163 if (!cldrv || !cldrv->probe)
1164 return -ENODEV;
1166 id = mei_cl_device_find(cldev, cldrv);
1167 if (!id)
1168 return -ENODEV;
1170 if (!mei_cl_bus_module_get(cldev)) {
1171 dev_err(&cldev->dev, "get hw module failed");
1172 return -ENODEV;
1175 ret = cldrv->probe(cldev, id);
1176 if (ret) {
1177 mei_cl_bus_module_put(cldev);
1178 return ret;
1181 __module_get(THIS_MODULE);
1182 return 0;
1186 * mei_cl_device_remove - remove device from the bus
1188 * @dev: device
1190 * Return: 0 on success; < 0 otherwise
1192 static void mei_cl_device_remove(struct device *dev)
1194 struct mei_cl_device *cldev = to_mei_cl_device(dev);
1195 struct mei_cl_driver *cldrv = to_mei_cl_driver(dev->driver);
1197 if (cldrv->remove)
1198 cldrv->remove(cldev);
1200 mei_cldev_unregister_callbacks(cldev);
1202 mei_cl_bus_module_put(cldev);
1203 module_put(THIS_MODULE);
1206 static ssize_t name_show(struct device *dev, struct device_attribute *a,
1207 char *buf)
1209 struct mei_cl_device *cldev = to_mei_cl_device(dev);
1211 return scnprintf(buf, PAGE_SIZE, "%s", cldev->name);
1213 static DEVICE_ATTR_RO(name);
1215 static ssize_t uuid_show(struct device *dev, struct device_attribute *a,
1216 char *buf)
1218 struct mei_cl_device *cldev = to_mei_cl_device(dev);
1219 const uuid_le *uuid = mei_me_cl_uuid(cldev->me_cl);
1221 return sprintf(buf, "%pUl", uuid);
1223 static DEVICE_ATTR_RO(uuid);
1225 static ssize_t version_show(struct device *dev, struct device_attribute *a,
1226 char *buf)
1228 struct mei_cl_device *cldev = to_mei_cl_device(dev);
1229 u8 version = mei_me_cl_ver(cldev->me_cl);
1231 return sprintf(buf, "%02X", version);
1233 static DEVICE_ATTR_RO(version);
1235 static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
1236 char *buf)
1238 struct mei_cl_device *cldev = to_mei_cl_device(dev);
1239 const uuid_le *uuid = mei_me_cl_uuid(cldev->me_cl);
1240 u8 version = mei_me_cl_ver(cldev->me_cl);
1242 return scnprintf(buf, PAGE_SIZE, "mei:%s:%pUl:%02X:",
1243 cldev->name, uuid, version);
1245 static DEVICE_ATTR_RO(modalias);
1247 static ssize_t max_conn_show(struct device *dev, struct device_attribute *a,
1248 char *buf)
1250 struct mei_cl_device *cldev = to_mei_cl_device(dev);
1251 u8 maxconn = mei_me_cl_max_conn(cldev->me_cl);
1253 return sprintf(buf, "%d", maxconn);
1255 static DEVICE_ATTR_RO(max_conn);
1257 static ssize_t fixed_show(struct device *dev, struct device_attribute *a,
1258 char *buf)
1260 struct mei_cl_device *cldev = to_mei_cl_device(dev);
1261 u8 fixed = mei_me_cl_fixed(cldev->me_cl);
1263 return sprintf(buf, "%d", fixed);
1265 static DEVICE_ATTR_RO(fixed);
1267 static ssize_t vtag_show(struct device *dev, struct device_attribute *a,
1268 char *buf)
1270 struct mei_cl_device *cldev = to_mei_cl_device(dev);
1271 bool vt = mei_me_cl_vt(cldev->me_cl);
1273 return sprintf(buf, "%d", vt);
1275 static DEVICE_ATTR_RO(vtag);
1277 static ssize_t max_len_show(struct device *dev, struct device_attribute *a,
1278 char *buf)
1280 struct mei_cl_device *cldev = to_mei_cl_device(dev);
1281 u32 maxlen = mei_me_cl_max_len(cldev->me_cl);
1283 return sprintf(buf, "%u", maxlen);
1285 static DEVICE_ATTR_RO(max_len);
1287 static struct attribute *mei_cldev_attrs[] = {
1288 &dev_attr_name.attr,
1289 &dev_attr_uuid.attr,
1290 &dev_attr_version.attr,
1291 &dev_attr_modalias.attr,
1292 &dev_attr_max_conn.attr,
1293 &dev_attr_fixed.attr,
1294 &dev_attr_vtag.attr,
1295 &dev_attr_max_len.attr,
1296 NULL,
1298 ATTRIBUTE_GROUPS(mei_cldev);
1301 * mei_cl_device_uevent - me client bus uevent handler
1303 * @dev: device
1304 * @env: uevent kobject
1306 * Return: 0 on success -ENOMEM on when add_uevent_var fails
1308 static int mei_cl_device_uevent(const struct device *dev, struct kobj_uevent_env *env)
1310 const struct mei_cl_device *cldev = to_mei_cl_device(dev);
1311 const uuid_le *uuid = mei_me_cl_uuid(cldev->me_cl);
1312 u8 version = mei_me_cl_ver(cldev->me_cl);
1314 if (add_uevent_var(env, "MEI_CL_VERSION=%d", version))
1315 return -ENOMEM;
1317 if (add_uevent_var(env, "MEI_CL_UUID=%pUl", uuid))
1318 return -ENOMEM;
1320 if (add_uevent_var(env, "MEI_CL_NAME=%s", cldev->name))
1321 return -ENOMEM;
1323 if (add_uevent_var(env, "MODALIAS=mei:%s:%pUl:%02X:",
1324 cldev->name, uuid, version))
1325 return -ENOMEM;
1327 return 0;
1330 static const struct bus_type mei_cl_bus_type = {
1331 .name = "mei",
1332 .dev_groups = mei_cldev_groups,
1333 .match = mei_cl_device_match,
1334 .probe = mei_cl_device_probe,
1335 .remove = mei_cl_device_remove,
1336 .uevent = mei_cl_device_uevent,
1339 static struct mei_device *mei_dev_bus_get(struct mei_device *bus)
1341 if (bus)
1342 get_device(bus->dev);
1344 return bus;
1347 static void mei_dev_bus_put(struct mei_device *bus)
1349 if (bus)
1350 put_device(bus->dev);
1353 static void mei_cl_bus_dev_release(struct device *dev)
1355 struct mei_cl_device *cldev = to_mei_cl_device(dev);
1357 mei_cl_flush_queues(cldev->cl, NULL);
1358 mei_me_cl_put(cldev->me_cl);
1359 mei_dev_bus_put(cldev->bus);
1360 kfree(cldev->cl);
1361 kfree(cldev);
1364 static const struct device_type mei_cl_device_type = {
1365 .release = mei_cl_bus_dev_release,
1369 * mei_cl_bus_set_name - set device name for me client device
1370 * <controller>-<client device>
1371 * Example: 0000:00:16.0-55213584-9a29-4916-badf-0fb7ed682aeb
1373 * @cldev: me client device
1375 static inline void mei_cl_bus_set_name(struct mei_cl_device *cldev)
1377 dev_set_name(&cldev->dev, "%s-%pUl",
1378 dev_name(cldev->bus->dev),
1379 mei_me_cl_uuid(cldev->me_cl));
1383 * mei_cl_bus_dev_alloc - initialize and allocate mei client device
1385 * @bus: mei device
1386 * @me_cl: me client
1388 * Return: allocated device structure or NULL on allocation failure
1390 static struct mei_cl_device *mei_cl_bus_dev_alloc(struct mei_device *bus,
1391 struct mei_me_client *me_cl)
1393 struct mei_cl_device *cldev;
1394 struct mei_cl *cl;
1396 cldev = kzalloc(sizeof(*cldev), GFP_KERNEL);
1397 if (!cldev)
1398 return NULL;
1400 cl = mei_cl_allocate(bus);
1401 if (!cl) {
1402 kfree(cldev);
1403 return NULL;
1406 device_initialize(&cldev->dev);
1407 cldev->dev.parent = bus->dev;
1408 cldev->dev.bus = &mei_cl_bus_type;
1409 cldev->dev.type = &mei_cl_device_type;
1410 cldev->bus = mei_dev_bus_get(bus);
1411 cldev->me_cl = mei_me_cl_get(me_cl);
1412 cldev->cl = cl;
1413 mei_cl_bus_set_name(cldev);
1414 cldev->is_added = 0;
1415 INIT_LIST_HEAD(&cldev->bus_list);
1416 device_enable_async_suspend(&cldev->dev);
1418 return cldev;
1422 * mei_cl_bus_dev_setup - setup me client device
1423 * run fix up routines and set the device name
1425 * @bus: mei device
1426 * @cldev: me client device
1428 * Return: true if the device is eligible for enumeration
1430 static bool mei_cl_bus_dev_setup(struct mei_device *bus,
1431 struct mei_cl_device *cldev)
1433 cldev->do_match = 1;
1434 mei_cl_bus_dev_fixup(cldev);
1436 /* the device name can change during fix up */
1437 if (cldev->do_match)
1438 mei_cl_bus_set_name(cldev);
1440 return cldev->do_match == 1;
1444 * mei_cl_bus_dev_add - add me client devices
1446 * @cldev: me client device
1448 * Return: 0 on success; < 0 on failure
1450 static int mei_cl_bus_dev_add(struct mei_cl_device *cldev)
1452 int ret;
1454 dev_dbg(cldev->bus->dev, "adding %pUL:%02X\n",
1455 mei_me_cl_uuid(cldev->me_cl),
1456 mei_me_cl_ver(cldev->me_cl));
1457 ret = device_add(&cldev->dev);
1458 if (!ret)
1459 cldev->is_added = 1;
1461 return ret;
1465 * mei_cl_bus_dev_stop - stop the driver
1467 * @cldev: me client device
1469 static void mei_cl_bus_dev_stop(struct mei_cl_device *cldev)
1471 cldev->do_match = 0;
1472 if (cldev->is_added)
1473 device_release_driver(&cldev->dev);
1477 * mei_cl_bus_dev_destroy - destroy me client devices object
1479 * @cldev: me client device
1481 * Locking: called under "dev->cl_bus_lock" lock
1483 static void mei_cl_bus_dev_destroy(struct mei_cl_device *cldev)
1486 WARN_ON(!mutex_is_locked(&cldev->bus->cl_bus_lock));
1488 if (!cldev->is_added)
1489 return;
1491 device_del(&cldev->dev);
1493 list_del_init(&cldev->bus_list);
1495 cldev->is_added = 0;
1496 put_device(&cldev->dev);
1500 * mei_cl_bus_remove_device - remove a devices form the bus
1502 * @cldev: me client device
1504 static void mei_cl_bus_remove_device(struct mei_cl_device *cldev)
1506 mei_cl_bus_dev_stop(cldev);
1507 mei_cl_bus_dev_destroy(cldev);
1511 * mei_cl_bus_remove_devices - remove all devices form the bus
1513 * @bus: mei device
1515 void mei_cl_bus_remove_devices(struct mei_device *bus)
1517 struct mei_cl_device *cldev, *next;
1519 mutex_lock(&bus->cl_bus_lock);
1520 list_for_each_entry_safe(cldev, next, &bus->device_list, bus_list)
1521 mei_cl_bus_remove_device(cldev);
1522 mutex_unlock(&bus->cl_bus_lock);
1527 * mei_cl_bus_dev_init - allocate and initializes an mei client devices
1528 * based on me client
1530 * @bus: mei device
1531 * @me_cl: me client
1533 * Locking: called under "dev->cl_bus_lock" lock
1535 static void mei_cl_bus_dev_init(struct mei_device *bus,
1536 struct mei_me_client *me_cl)
1538 struct mei_cl_device *cldev;
1540 WARN_ON(!mutex_is_locked(&bus->cl_bus_lock));
1542 dev_dbg(bus->dev, "initializing %pUl", mei_me_cl_uuid(me_cl));
1544 if (me_cl->bus_added)
1545 return;
1547 cldev = mei_cl_bus_dev_alloc(bus, me_cl);
1548 if (!cldev)
1549 return;
1551 me_cl->bus_added = true;
1552 list_add_tail(&cldev->bus_list, &bus->device_list);
1557 * mei_cl_bus_rescan - scan me clients list and add create
1558 * devices for eligible clients
1560 * @bus: mei device
1562 static void mei_cl_bus_rescan(struct mei_device *bus)
1564 struct mei_cl_device *cldev, *n;
1565 struct mei_me_client *me_cl;
1567 mutex_lock(&bus->cl_bus_lock);
1569 down_read(&bus->me_clients_rwsem);
1570 list_for_each_entry(me_cl, &bus->me_clients, list)
1571 mei_cl_bus_dev_init(bus, me_cl);
1572 up_read(&bus->me_clients_rwsem);
1574 list_for_each_entry_safe(cldev, n, &bus->device_list, bus_list) {
1576 if (!mei_me_cl_is_active(cldev->me_cl)) {
1577 mei_cl_bus_remove_device(cldev);
1578 continue;
1581 if (cldev->is_added)
1582 continue;
1584 if (mei_cl_bus_dev_setup(bus, cldev))
1585 mei_cl_bus_dev_add(cldev);
1586 else {
1587 list_del_init(&cldev->bus_list);
1588 put_device(&cldev->dev);
1591 mutex_unlock(&bus->cl_bus_lock);
1593 dev_dbg(bus->dev, "rescan end");
1596 void mei_cl_bus_rescan_work(struct work_struct *work)
1598 struct mei_device *bus =
1599 container_of(work, struct mei_device, bus_rescan_work);
1601 mei_cl_bus_rescan(bus);
1604 int __mei_cldev_driver_register(struct mei_cl_driver *cldrv,
1605 struct module *owner)
1607 int err;
1609 cldrv->driver.name = cldrv->name;
1610 cldrv->driver.owner = owner;
1611 cldrv->driver.bus = &mei_cl_bus_type;
1613 err = driver_register(&cldrv->driver);
1614 if (err)
1615 return err;
1617 pr_debug("mei: driver [%s] registered\n", cldrv->driver.name);
1619 return 0;
1621 EXPORT_SYMBOL_GPL(__mei_cldev_driver_register);
1623 void mei_cldev_driver_unregister(struct mei_cl_driver *cldrv)
1625 driver_unregister(&cldrv->driver);
1627 pr_debug("mei: driver [%s] unregistered\n", cldrv->driver.name);
1629 EXPORT_SYMBOL_GPL(mei_cldev_driver_unregister);
1632 int __init mei_cl_bus_init(void)
1634 return bus_register(&mei_cl_bus_type);
1637 void __exit mei_cl_bus_exit(void)
1639 bus_unregister(&mei_cl_bus_type);