// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2012-2023, Intel Corporation. All rights reserved. * Intel Management Engine Interface (Intel MEI) Linux driver */ #include <linux/module.h> #include <linux/device.h> #include <linux/kernel.h> #include <linux/sched/signal.h> #include <linux/init.h> #include <linux/errno.h> #include <linux/slab.h> #include <linux/mutex.h> #include <linux/interrupt.h> #include <linux/scatterlist.h> #include <linux/mei_cl_bus.h> #include "mei_dev.h" #include "client.h" #define to_mei_cl_driver(d) … /** * __mei_cl_send - internal client send (write) * * @cl: host client * @buf: buffer to send * @length: buffer length * @vtag: virtual tag * @mode: sending mode * * Return: written size bytes or < 0 on error */ ssize_t __mei_cl_send(struct mei_cl *cl, const u8 *buf, size_t length, u8 vtag, unsigned int mode) { … } /** * __mei_cl_send_timeout - internal client send (write) * * @cl: host client * @buf: buffer to send * @length: buffer length * @vtag: virtual tag * @mode: sending mode * @timeout: send timeout in milliseconds. * effective only for blocking writes: the MEI_CL_IO_TX_BLOCKING mode bit is set. * set timeout to the MAX_SCHEDULE_TIMEOUT to maixum allowed wait. * * Return: written size bytes or < 0 on error */ ssize_t __mei_cl_send_timeout(struct mei_cl *cl, const u8 *buf, size_t length, u8 vtag, unsigned int mode, unsigned long timeout) { … } /** * __mei_cl_recv - internal client receive (read) * * @cl: host client * @buf: buffer to receive * @length: buffer length * @mode: io mode * @vtag: virtual tag * @timeout: recv timeout, 0 for infinite timeout * * Return: read size in bytes of < 0 on error */ ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length, u8 *vtag, unsigned int mode, unsigned long timeout) { … } /** * mei_cldev_send_vtag - me device send with vtag (write) * * @cldev: me client device * @buf: buffer to send * @length: buffer length * @vtag: virtual tag * * Return: * * written size in bytes * * < 0 on error */ ssize_t mei_cldev_send_vtag(struct mei_cl_device *cldev, const u8 *buf, size_t length, u8 vtag) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_send_vtag_timeout - me device send with vtag and timeout (write) * * @cldev: me client device * @buf: buffer to send * @length: buffer length * @vtag: virtual tag * @timeout: send timeout in milliseconds, 0 for infinite timeout * * Return: * * written size in bytes * * < 0 on error */ ssize_t mei_cldev_send_vtag_timeout(struct mei_cl_device *cldev, const u8 *buf, size_t length, u8 vtag, unsigned long timeout) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_recv_vtag - client receive with vtag (read) * * @cldev: me client device * @buf: buffer to receive * @length: buffer length * @vtag: virtual tag * * Return: * * read size in bytes * * < 0 on error */ ssize_t mei_cldev_recv_vtag(struct mei_cl_device *cldev, u8 *buf, size_t length, u8 *vtag) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_recv_nonblock_vtag - non block client receive with vtag (read) * * @cldev: me client device * @buf: buffer to receive * @length: buffer length * @vtag: virtual tag * * Return: * * read size in bytes * * -EAGAIN if function will block. * * < 0 on other error */ ssize_t mei_cldev_recv_nonblock_vtag(struct mei_cl_device *cldev, u8 *buf, size_t length, u8 *vtag) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_recv_timeout - client receive with timeout (read) * * @cldev: me client device * @buf: buffer to receive * @length: buffer length * @timeout: send timeout in milliseconds, 0 for infinite timeout * * Return: * * read size in bytes * * < 0 on error */ ssize_t mei_cldev_recv_timeout(struct mei_cl_device *cldev, u8 *buf, size_t length, unsigned long timeout) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_recv_vtag_timeout - client receive with vtag (read) * * @cldev: me client device * @buf: buffer to receive * @length: buffer length * @vtag: virtual tag * @timeout: recv timeout in milliseconds, 0 for infinite timeout * * Return: * * read size in bytes * * < 0 on error */ ssize_t mei_cldev_recv_vtag_timeout(struct mei_cl_device *cldev, u8 *buf, size_t length, u8 *vtag, unsigned long timeout) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_send - me device send (write) * * @cldev: me client device * @buf: buffer to send * @length: buffer length * * Return: * * written size in bytes * * < 0 on error */ ssize_t mei_cldev_send(struct mei_cl_device *cldev, const u8 *buf, size_t length) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_send_timeout - me device send with timeout (write) * * @cldev: me client device * @buf: buffer to send * @length: buffer length * @timeout: send timeout in milliseconds, 0 for infinite timeout * * Return: * * written size in bytes * * < 0 on error */ ssize_t mei_cldev_send_timeout(struct mei_cl_device *cldev, const u8 *buf, size_t length, unsigned long timeout) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_recv - client receive (read) * * @cldev: me client device * @buf: buffer to receive * @length: buffer length * * Return: read size in bytes of < 0 on error */ ssize_t mei_cldev_recv(struct mei_cl_device *cldev, u8 *buf, size_t length) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_recv_nonblock - non block client receive (read) * * @cldev: me client device * @buf: buffer to receive * @length: buffer length * * Return: read size in bytes of < 0 on error * -EAGAIN if function will block. */ ssize_t mei_cldev_recv_nonblock(struct mei_cl_device *cldev, u8 *buf, size_t length) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cl_bus_rx_work - dispatch rx event for a bus device * * @work: work */ static void mei_cl_bus_rx_work(struct work_struct *work) { … } /** * mei_cl_bus_notif_work - dispatch FW notif event for a bus device * * @work: work */ static void mei_cl_bus_notif_work(struct work_struct *work) { … } /** * mei_cl_bus_notify_event - schedule notify cb on bus client * * @cl: host client * * Return: true if event was scheduled * false if the client is not waiting for event */ bool mei_cl_bus_notify_event(struct mei_cl *cl) { … } /** * mei_cl_bus_rx_event - schedule rx event * * @cl: host client * * Return: true if event was scheduled * false if the client is not waiting for event */ bool mei_cl_bus_rx_event(struct mei_cl *cl) { … } /** * mei_cldev_register_rx_cb - register Rx event callback * * @cldev: me client devices * @rx_cb: callback function * * Return: 0 on success * -EALREADY if an callback is already registered * <0 on other errors */ int mei_cldev_register_rx_cb(struct mei_cl_device *cldev, mei_cldev_cb_t rx_cb) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_register_notif_cb - register FW notification event callback * * @cldev: me client devices * @notif_cb: callback function * * Return: 0 on success * -EALREADY if an callback is already registered * <0 on other errors */ int mei_cldev_register_notif_cb(struct mei_cl_device *cldev, mei_cldev_cb_t notif_cb) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_get_drvdata - driver data getter * * @cldev: mei client device * * Return: driver private data */ void *mei_cldev_get_drvdata(const struct mei_cl_device *cldev) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_set_drvdata - driver data setter * * @cldev: mei client device * @data: data to store */ void mei_cldev_set_drvdata(struct mei_cl_device *cldev, void *data) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_uuid - return uuid of the underlying me client * * @cldev: mei client device * * Return: me client uuid */ const uuid_le *mei_cldev_uuid(const struct mei_cl_device *cldev) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_ver - return protocol version of the underlying me client * * @cldev: mei client device * * Return: me client protocol version */ u8 mei_cldev_ver(const struct mei_cl_device *cldev) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_enabled - check whether the device is enabled * * @cldev: mei client device * * Return: true if me client is initialized and connected */ bool mei_cldev_enabled(const struct mei_cl_device *cldev) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cl_bus_module_get - acquire module of the underlying * hw driver. * * @cldev: mei client device * * Return: true on success; false if the module was removed. */ static bool mei_cl_bus_module_get(struct mei_cl_device *cldev) { … } /** * mei_cl_bus_module_put - release the underlying hw module. * * @cldev: mei client device */ static void mei_cl_bus_module_put(struct mei_cl_device *cldev) { … } /** * mei_cl_bus_vtag - get bus vtag entry wrapper * The tag for bus client is always first. * * @cl: host client * * Return: bus vtag or NULL */ static inline struct mei_cl_vtag *mei_cl_bus_vtag(struct mei_cl *cl) { … } /** * mei_cl_bus_vtag_alloc - add bus client entry to vtag map * * @cldev: me client device * * Return: * * 0 on success * * -ENOMEM if memory allocation failed */ static int mei_cl_bus_vtag_alloc(struct mei_cl_device *cldev) { … } /** * mei_cl_bus_vtag_free - remove the bus entry from vtag map * * @cldev: me client device */ static void mei_cl_bus_vtag_free(struct mei_cl_device *cldev) { … } void *mei_cldev_dma_map(struct mei_cl_device *cldev, u8 buffer_id, size_t size) { … } EXPORT_SYMBOL_GPL(…); int mei_cldev_dma_unmap(struct mei_cl_device *cldev) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_enable - enable me client device * create connection with me client * * @cldev: me client device * * Return: 0 on success and < 0 on error */ int mei_cldev_enable(struct mei_cl_device *cldev) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_unregister_callbacks - internal wrapper for unregistering * callbacks. * * @cldev: client device */ static void mei_cldev_unregister_callbacks(struct mei_cl_device *cldev) { … } /** * mei_cldev_disable - disable me client device * disconnect form the me client * * @cldev: me client device * * Return: 0 on success and < 0 on error */ int mei_cldev_disable(struct mei_cl_device *cldev) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cldev_send_gsc_command - sends a gsc command, by sending * a gsl mei message to gsc and receiving reply from gsc * * @cldev: me client device * @client_id: client id to send the command to * @fence_id: fence id to send the command to * @sg_in: scatter gather list containing addresses for rx message buffer * @total_in_len: total length of data in 'in' sg, can be less than the sum of buffers sizes * @sg_out: scatter gather list containing addresses for tx message buffer * * Return: * * written size in bytes * * < 0 on error */ ssize_t mei_cldev_send_gsc_command(struct mei_cl_device *cldev, u8 client_id, u32 fence_id, struct scatterlist *sg_in, size_t total_in_len, struct scatterlist *sg_out) { … } EXPORT_SYMBOL_GPL(…); /** * mei_cl_device_find - find matching entry in the driver id table * * @cldev: me client device * @cldrv: me client driver * * Return: id on success; NULL if no id is matching */ static const struct mei_cl_device_id *mei_cl_device_find(const struct mei_cl_device *cldev, const struct mei_cl_driver *cldrv) { … } /** * mei_cl_device_match - device match function * * @dev: device * @drv: driver * * Return: 1 if matching device was found 0 otherwise */ static int mei_cl_device_match(struct device *dev, const struct device_driver *drv) { … } /** * mei_cl_device_probe - bus probe function * * @dev: device * * Return: 0 on success; < 0 otherwise */ static int mei_cl_device_probe(struct device *dev) { … } /** * mei_cl_device_remove - remove device from the bus * * @dev: device * * Return: 0 on success; < 0 otherwise */ static void mei_cl_device_remove(struct device *dev) { … } static ssize_t name_show(struct device *dev, struct device_attribute *a, char *buf) { … } static DEVICE_ATTR_RO(name); static ssize_t uuid_show(struct device *dev, struct device_attribute *a, char *buf) { … } static DEVICE_ATTR_RO(uuid); static ssize_t version_show(struct device *dev, struct device_attribute *a, char *buf) { … } static DEVICE_ATTR_RO(version); static ssize_t modalias_show(struct device *dev, struct device_attribute *a, char *buf) { … } static DEVICE_ATTR_RO(modalias); static ssize_t max_conn_show(struct device *dev, struct device_attribute *a, char *buf) { … } static DEVICE_ATTR_RO(max_conn); static ssize_t fixed_show(struct device *dev, struct device_attribute *a, char *buf) { … } static DEVICE_ATTR_RO(fixed); static ssize_t vtag_show(struct device *dev, struct device_attribute *a, char *buf) { … } static DEVICE_ATTR_RO(vtag); static ssize_t max_len_show(struct device *dev, struct device_attribute *a, char *buf) { … } static DEVICE_ATTR_RO(max_len); static struct attribute *mei_cldev_attrs[] = …; ATTRIBUTE_GROUPS(…); /** * mei_cl_device_uevent - me client bus uevent handler * * @dev: device * @env: uevent kobject * * Return: 0 on success -ENOMEM on when add_uevent_var fails */ static int mei_cl_device_uevent(const struct device *dev, struct kobj_uevent_env *env) { … } static const struct bus_type mei_cl_bus_type = …; static struct mei_device *mei_dev_bus_get(struct mei_device *bus) { … } static void mei_dev_bus_put(struct mei_device *bus) { … } static void mei_cl_bus_dev_release(struct device *dev) { … } static const struct device_type mei_cl_device_type = …; /** * mei_cl_bus_set_name - set device name for me client device * <controller>-<client device> * Example: 0000:00:16.0-55213584-9a29-4916-badf-0fb7ed682aeb * * @cldev: me client device */ static inline void mei_cl_bus_set_name(struct mei_cl_device *cldev) { … } /** * mei_cl_bus_dev_alloc - initialize and allocate mei client device * * @bus: mei device * @me_cl: me client * * Return: allocated device structure or NULL on allocation failure */ static struct mei_cl_device *mei_cl_bus_dev_alloc(struct mei_device *bus, struct mei_me_client *me_cl) { … } /** * mei_cl_bus_dev_setup - setup me client device * run fix up routines and set the device name * * @bus: mei device * @cldev: me client device * * Return: true if the device is eligible for enumeration */ static bool mei_cl_bus_dev_setup(struct mei_device *bus, struct mei_cl_device *cldev) { … } /** * mei_cl_bus_dev_add - add me client devices * * @cldev: me client device * * Return: 0 on success; < 0 on failure */ static int mei_cl_bus_dev_add(struct mei_cl_device *cldev) { … } /** * mei_cl_bus_dev_stop - stop the driver * * @cldev: me client device */ static void mei_cl_bus_dev_stop(struct mei_cl_device *cldev) { … } /** * mei_cl_bus_dev_destroy - destroy me client devices object * * @cldev: me client device * * Locking: called under "dev->cl_bus_lock" lock */ static void mei_cl_bus_dev_destroy(struct mei_cl_device *cldev) { … } /** * mei_cl_bus_remove_device - remove a devices form the bus * * @cldev: me client device */ static void mei_cl_bus_remove_device(struct mei_cl_device *cldev) { … } /** * mei_cl_bus_remove_devices - remove all devices form the bus * * @bus: mei device */ void mei_cl_bus_remove_devices(struct mei_device *bus) { … } /** * mei_cl_bus_dev_init - allocate and initializes an mei client devices * based on me client * * @bus: mei device * @me_cl: me client * * Locking: called under "dev->cl_bus_lock" lock */ static void mei_cl_bus_dev_init(struct mei_device *bus, struct mei_me_client *me_cl) { … } /** * mei_cl_bus_rescan - scan me clients list and add create * devices for eligible clients * * @bus: mei device */ static void mei_cl_bus_rescan(struct mei_device *bus) { … } void mei_cl_bus_rescan_work(struct work_struct *work) { … } int __mei_cldev_driver_register(struct mei_cl_driver *cldrv, struct module *owner) { … } EXPORT_SYMBOL_GPL(…); void mei_cldev_driver_unregister(struct mei_cl_driver *cldrv) { … } EXPORT_SYMBOL_GPL(…); int __init mei_cl_bus_init(void) { … } void __exit mei_cl_bus_exit(void) { … }