Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mei: docs: update mei client bus documentation.

The mei client bus API has changed significantly from
time it was documented, and had required update.

Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Tomas Winkler and committed by
Greg Kroah-Hartman
6080e0cf 815d0f26

+85 -77
+85 -77
Documentation/driver-api/mei/mei-client-bus.rst
··· 8 8 Rationale 9 9 ========= 10 10 11 - MEI misc character device is useful for dedicated applications to send and receive 11 + The MEI character device is useful for dedicated applications to send and receive 12 12 data to the many FW appliance found in Intel's ME from the user space. 13 - However for some of the ME functionalities it make sense to leverage existing software 13 + However, for some of the ME functionalities it makes sense to leverage existing software 14 14 stack and expose them through existing kernel subsystems. 15 15 16 16 In order to plug seamlessly into the kernel device driver model we add kernel virtual 17 - bus abstraction on top of the MEI driver. This allows implementing linux kernel drivers 17 + bus abstraction on top of the MEI driver. This allows implementing Linux kernel drivers 18 18 for the various MEI features as a stand alone entities found in their respective subsystem. 19 19 Existing device drivers can even potentially be re-used by adding an MEI CL bus layer to 20 20 the existing code. ··· 23 23 MEI CL bus API 24 24 ============== 25 25 26 - A driver implementation for an MEI Client is very similar to existing bus 26 + A driver implementation for an MEI Client is very similar to any other existing bus 27 27 based device drivers. The driver registers itself as an MEI CL bus driver through 28 - the ``struct mei_cl_driver`` structure: 28 + the ``struct mei_cl_driver`` structure defined in :file:`include/linux/mei_cl_bus.c` 29 29 30 30 .. code-block:: C 31 31 ··· 39 39 int (*remove)(struct mei_cl_device *dev); 40 40 }; 41 41 42 - struct mei_cl_id { 43 - char name[MEI_NAME_SIZE]; 42 + 43 + 44 + The mei_cl_device_id structure defined in :file:`include/linux/mod_devicetable.h` allows a 45 + driver to bind itself against a device name. 46 + 47 + .. code-block:: C 48 + 49 + struct mei_cl_device_id { 50 + char name[MEI_CL_NAME_SIZE]; 51 + uuid_le uuid; 52 + __u8 version; 44 53 kernel_ulong_t driver_info; 45 54 }; 46 55 47 - The mei_cl_id structure allows the driver to bind itself against a device name. 56 + To actually register a driver on the ME Client bus one must call the :c:func:`mei_cl_add_driver` 57 + API. This is typically called at module initialization time. 48 58 49 - To actually register a driver on the ME Client bus one must call the mei_cl_add_driver() 50 - API. This is typically called at module init time. 59 + Once the driver is registered and bound to the device, a driver will typically 60 + try to do some I/O on this bus and this should be done through the :c:func:`mei_cl_send` 61 + and :c:func:`mei_cl_recv` functions. More detailed information is in :ref:`api` section. 51 62 52 - Once registered on the ME Client bus, a driver will typically try to do some I/O on 53 - this bus and this should be done through the mei_cl_send() and mei_cl_recv() 54 - routines. The latter is synchronous (blocks and sleeps until data shows up). 55 - In order for drivers to be notified of pending events waiting for them (e.g. 56 - an Rx event) they can register an event handler through the 57 - mei_cl_register_event_cb() routine. Currently only the MEI_EVENT_RX event 58 - will trigger an event handler call and the driver implementation is supposed 59 - to call mei_recv() from the event handler in order to fetch the pending 60 - received buffers. 63 + In order for a driver to be notified about pending traffic or event, the driver 64 + should register a callback via :c:func:`mei_cl_devev_register_rx_cb` and 65 + :c:func:`mei_cldev_register_notify_cb` function respectively. 66 + 67 + .. _api: 68 + 69 + API: 70 + ---- 71 + .. kernel-doc:: drivers/misc/mei/bus.c 72 + :export: drivers/misc/mei/bus.c 73 + 61 74 62 75 63 76 Example ··· 81 68 82 69 .. code-block:: C 83 70 84 - #define CONTACT_DRIVER_NAME "contact" 71 + #define CONTACT_DRIVER_NAME "contact" 85 72 86 - static struct mei_cl_device_id contact_mei_cl_tbl[] = { 87 - { CONTACT_DRIVER_NAME, }, 73 + static struct mei_cl_device_id contact_mei_cl_tbl[] = { 74 + { CONTACT_DRIVER_NAME, }, 88 75 89 - /* required last entry */ 90 - { } 91 - }; 92 - MODULE_DEVICE_TABLE(mei_cl, contact_mei_cl_tbl); 76 + /* required last entry */ 77 + { } 78 + }; 79 + MODULE_DEVICE_TABLE(mei_cl, contact_mei_cl_tbl); 93 80 94 - static struct mei_cl_driver contact_driver = { 95 - .id_table = contact_mei_tbl, 96 - .name = CONTACT_DRIVER_NAME, 81 + static struct mei_cl_driver contact_driver = { 82 + .id_table = contact_mei_tbl, 83 + .name = CONTACT_DRIVER_NAME, 97 84 98 - .probe = contact_probe, 99 - .remove = contact_remove, 100 - }; 85 + .probe = contact_probe, 86 + .remove = contact_remove, 87 + }; 101 88 102 - static int contact_init(void) 103 - { 104 - int r; 89 + static int contact_init(void) 90 + { 91 + int r; 105 92 106 - r = mei_cl_driver_register(&contact_driver); 107 - if (r) { 108 - pr_err(CONTACT_DRIVER_NAME ": driver registration failed\n"); 109 - return r; 110 - } 93 + r = mei_cl_driver_register(&contact_driver); 94 + if (r) { 95 + pr_err(CONTACT_DRIVER_NAME ": driver registration failed\n"); 96 + return r; 97 + } 111 98 112 - return 0; 113 - } 99 + return 0; 100 + } 114 101 115 - static void __exit contact_exit(void) 116 - { 117 - mei_cl_driver_unregister(&contact_driver); 118 - } 102 + static void __exit contact_exit(void) 103 + { 104 + mei_cl_driver_unregister(&contact_driver); 105 + } 119 106 120 - module_init(contact_init); 121 - module_exit(contact_exit); 107 + module_init(contact_init); 108 + module_exit(contact_exit); 122 109 123 110 And the driver's simplified probe routine would look like that: 124 111 125 112 .. code-block:: C 126 113 127 - int contact_probe(struct mei_cl_device *dev, struct mei_cl_device_id *id) 128 - { 129 - struct contact_driver *contact; 114 + int contact_probe(struct mei_cl_device *dev, struct mei_cl_device_id *id) 115 + { 116 + [...] 117 + mei_cldev_enable(dev); 130 118 131 - [...] 132 - mei_cl_enable_device(dev); 119 + mei_cldev_register_rx_cb(dev, contact_rx_cb); 133 120 134 - mei_cl_register_event_cb(dev, contact_event_cb, contact); 135 - 136 - return 0; 137 - } 121 + return 0; 122 + } 138 123 139 124 In the probe routine the driver first enable the MEI device and then registers 140 - an ME bus event handler which is as close as it can get to registering a 141 - threaded IRQ handler. 142 - The handler implementation will typically call some I/O routine depending on 143 - the pending events: 144 - 145 - #define MAX_NFC_PAYLOAD 128 125 + an rx handler which is as close as it can get to registering a threaded IRQ handler. 126 + The handler implementation will typically call :c:func:`mei_cldev_recv` and then 127 + process received data. 146 128 147 129 .. code-block:: C 148 130 149 - static void contact_event_cb(struct mei_cl_device *dev, u32 events, 150 - void *context) 151 - { 152 - struct contact_driver *contact = context; 131 + #define MAX_PAYLOAD 128 132 + #define HDR_SIZE 4 133 + static void conntact_rx_cb(struct mei_cl_device *cldev) 134 + { 135 + struct contact *c = mei_cldev_get_drvdata(cldev); 136 + unsigned char payload[MAX_PAYLOAD]; 137 + ssize_t payload_sz; 153 138 154 - if (events & BIT(MEI_EVENT_RX)) { 155 - u8 payload[MAX_NFC_PAYLOAD]; 156 - int payload_size; 139 + payload_sz = mei_cldev_recv(cldev, payload, MAX_PAYLOAD) 140 + if (reply_size < HDR_SIZE) { 141 + return; 142 + } 157 143 158 - payload_size = mei_recv(dev, payload, MAX_NFC_PAYLOAD); 159 - if (payload_size <= 0) 160 - return; 144 + c->process_rx(payload); 161 145 162 - /* Hook to the NFC subsystem */ 163 - nfc_hci_recv_frame(contact->hdev, payload, payload_size); 164 - } 165 - } 146 + } 147 +