Intel(R) Management Engine (ME) Client bus API
Rationale #
The MEI character device is useful for dedicated applications to send and receive data to the many FW appliance found in Intel's ME from the user space. However, for some of the ME functionalities it makes sense to leverage existing software stack and expose them through existing kernel subsystems.
In order to plug seamlessly into the kernel device driver model we add kernel virtual bus abstraction on top of the MEI driver. This allows implementing Linux kernel drivers for the various MEI features as a stand alone entities found in their respective subsystem. Existing device drivers can even potentially be re-used by adding an MEI CL bus layer to the existing code.
MEI CL bus API #
A driver implementation for an MEI Client is very similar to any other existing bus based device drivers. The driver registers itself as an MEI CL bus driver through the struct mei_cl_driver structure defined in include/linux/mei_cl_bus.c
;
The mei_cl_device_id structure defined in include/linux/mod_devicetable.h allows a driver to bind itself against a device name.
;
To actually register a driver on the ME Client bus one must call the mei_cl_add_driver() API. This is typically called at module initialization time.
Once the driver is registered and bound to the device, a driver will typically try to do some I/O on this bus and this should be done through the mei_cl_send() and mei_cl_recv() functions. More detailed information is in API: section.
In order for a driver to be notified about pending traffic or event, the driver should register a callback via mei_cl_devev_register_rx_cb() and mei_cldev_register_notify_cb() function respectively.
API: #
mei_cldev_send_vtag() #
ssize_t me device send with vtag (write)
Parameters
struct mei_cl_device *cldev: me client deviceconst u8 *buf: buffer to sendsize_t length: buffer lengthu8 vtag: virtual tag
Return
- written size in bytes
- < 0 on error
mei_cldev_send_vtag_timeout() #
ssize_t me device send with vtag and timeout (write)
Parameters
struct mei_cl_device *cldev: me client deviceconst u8 *buf: buffer to sendsize_t length: buffer lengthu8 vtag: virtual tagunsigned long timeout: send timeout in milliseconds, 0 for infinite timeout
Return
- written size in bytes
- < 0 on error
mei_cldev_recv_vtag() #
ssize_t client receive with vtag (read)
Parameters
struct mei_cl_device *cldev: me client deviceu8 *buf: buffer to receivesize_t length: buffer lengthu8 *vtag: virtual tag
Return
- read size in bytes
- < 0 on error
mei_cldev_recv_timeout() #
ssize_t client receive with timeout (read)
Parameters
struct mei_cl_device *cldev: me client deviceu8 *buf: buffer to receivesize_t length: buffer lengthunsigned long timeout: send timeout in milliseconds, 0 for infinite timeout
Return
- read size in bytes
- < 0 on error
mei_cldev_recv_vtag_timeout() #
ssize_t client receive with vtag (read)
Parameters
struct mei_cl_device *cldev: me client deviceu8 *buf: buffer to receivesize_t length: buffer lengthu8 *vtag: virtual tagunsigned long timeout: recv timeout in milliseconds, 0 for infinite timeout
Return
- read size in bytes
- < 0 on error
mei_cldev_send() #
ssize_t me device send (write)
Parameters
struct mei_cl_device *cldev: me client deviceconst u8 *buf: buffer to sendsize_t length: buffer length
Return
- written size in bytes
- < 0 on error
mei_cldev_send_timeout() #
ssize_t me device send with timeout (write)
Parameters
struct mei_cl_device *cldev: me client deviceconst u8 *buf: buffer to sendsize_t length: buffer lengthunsigned long timeout: send timeout in milliseconds, 0 for infinite timeout
Return
- written size in bytes
- < 0 on error
mei_cldev_recv() #
ssize_t client receive (read)
Parameters
struct mei_cl_device *cldev: me client deviceu8 *buf: buffer to receivesize_t length: buffer length
Return
read size in bytes of < 0 on error
mei_cldev_register_rx_cb() #
int register Rx event callback
Parameters
struct mei_cl_device *cldev: me client devicesmei_cldev_cb_t rx_cb: callback function
Return
0 on success -EALREADY if an callback is already registered <0 on other errors
mei_cldev_register_notif_cb() #
int register FW notification event callback
Parameters
struct mei_cl_device *cldev: me client devicesmei_cldev_cb_t notif_cb: callback function
Return
0 on success -EALREADY if an callback is already registered <0 on other errors
mei_cldev_get_drvdata() #
void * driver data getter
Parameters
const struct mei_cl_device *cldev: mei client device
Return
driver private data
mei_cldev_set_drvdata() #
void driver data setter
Parameters
struct mei_cl_device *cldev: mei client devicevoid *data: data to store
mei_cldev_ver() #
u8 return protocol version of the underlying me client
Parameters
const struct mei_cl_device *cldev: mei client device
Return
me client protocol version
mei_cldev_mtu() #
size_t max message that client can send and receive
Parameters
const struct mei_cl_device *cldev: mei client device
Return
mtu or 0 if client is not connected
mei_cldev_enabled() #
bool check whether the device is enabled
Parameters
const struct mei_cl_device *cldev: mei client device
Return
true if me client is initialized and connected
mei_cldev_enable() #
int enable me client device create connection with me client
Parameters
struct mei_cl_device *cldev: me client device
Return
0 on success and < 0 on error
mei_cldev_disable() #
int disable me client device disconnect form the me client
Parameters
struct mei_cl_device *cldev: me client device
Return
0 on success and < 0 on error
mei_cldev_send_gsc_command() #
ssize_t sends a gsc command, by sending a gsl mei message to gsc and receiving reply from gsc
Parameters
struct mei_cl_device *cldev: me client deviceu8 client_id: client id to send the command tou32 fence_id: fence id to send the command tostruct scatterlist *sg_in: scatter gather list containing addresses for rx message buffersize_t total_in_len: total length of data in 'in' sg, can be less than the sum of buffers sizesstruct scatterlist *sg_out: scatter gather list containing addresses for tx message buffer
Return
- written size in bytes
- < 0 on error
Example #
As a theoretical example let's pretend the ME comes with a "contact" NFC IP. The driver init and exit routines for this device would look like:
static struct mei_cl_device_id contact_mei_cl_tbl = ;
;
static struct mei_cl_driver contact_driver = ;
static int
static void __exit
;
;
And the driver's simplified probe routine would look like that:
int
In the probe routine the driver first enable the MEI device and then registers an rx handler which is as close as it can get to registering a threaded IRQ handler. The handler implementation will typically call mei_cldev_recv() and then process received data.
static void