mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 13:55:32 +00:00
![Manivannan Sadhasivam](/assets/img/avatar_default.png)
This commit adds support for registering MHI endpoint client drivers with the MHI endpoint stack. MHI endpoint client drivers bind to one or more MHI endpoint devices inorder to send and receive the upper-layer protocol packets like IP packets, modem control messages, and diagnostics messages over MHI bus. Reviewed-by: Hemant Kumar <hemantk@codeaurora.org> Reviewed-by: Alex Elder <elder@linaro.org> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Link: https://lore.kernel.org/r/20220405135754.6622-3-manivannan.sadhasivam@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
189 lines
6.4 KiB
C
189 lines
6.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* Copyright (c) 2022, Linaro Ltd.
|
|
*
|
|
*/
|
|
#ifndef _MHI_EP_H_
|
|
#define _MHI_EP_H_
|
|
|
|
#include <linux/dma-direction.h>
|
|
#include <linux/mhi.h>
|
|
|
|
#define MHI_EP_DEFAULT_MTU 0x8000
|
|
|
|
/**
|
|
* struct mhi_ep_channel_config - Channel configuration structure for controller
|
|
* @name: The name of this channel
|
|
* @num: The number assigned to this channel
|
|
* @num_elements: The number of elements that can be queued to this channel
|
|
* @dir: Direction that data may flow on this channel
|
|
*/
|
|
struct mhi_ep_channel_config {
|
|
char *name;
|
|
u32 num;
|
|
u32 num_elements;
|
|
enum dma_data_direction dir;
|
|
};
|
|
|
|
/**
|
|
* struct mhi_ep_cntrl_config - MHI Endpoint controller configuration
|
|
* @mhi_version: MHI spec version supported by the controller
|
|
* @max_channels: Maximum number of channels supported
|
|
* @num_channels: Number of channels defined in @ch_cfg
|
|
* @ch_cfg: Array of defined channels
|
|
*/
|
|
struct mhi_ep_cntrl_config {
|
|
u32 mhi_version;
|
|
u32 max_channels;
|
|
u32 num_channels;
|
|
const struct mhi_ep_channel_config *ch_cfg;
|
|
};
|
|
|
|
/**
|
|
* struct mhi_ep_db_info - MHI Endpoint doorbell info
|
|
* @mask: Mask of the doorbell interrupt
|
|
* @status: Status of the doorbell interrupt
|
|
*/
|
|
struct mhi_ep_db_info {
|
|
u32 mask;
|
|
u32 status;
|
|
};
|
|
|
|
/**
|
|
* struct mhi_ep_cntrl - MHI Endpoint controller structure
|
|
* @cntrl_dev: Pointer to the struct device of physical bus acting as the MHI
|
|
* Endpoint controller
|
|
* @mhi_dev: MHI Endpoint device instance for the controller
|
|
* @mmio: MMIO region containing the MHI registers
|
|
* @mhi_chan: Points to the channel configuration table
|
|
* @mhi_event: Points to the event ring configurations table
|
|
* @mhi_cmd: Points to the command ring configurations table
|
|
* @sm: MHI Endpoint state machine
|
|
* @raise_irq: CB function for raising IRQ to the host
|
|
* @alloc_map: CB function for allocating memory in endpoint for storing host context and mapping it
|
|
* @unmap_free: CB function to unmap and free the allocated memory in endpoint for storing host context
|
|
* @read_from_host: CB function for reading from host memory from endpoint
|
|
* @write_to_host: CB function for writing to host memory from endpoint
|
|
* @mhi_state: MHI Endpoint state
|
|
* @max_chan: Maximum channels supported by the endpoint controller
|
|
* @mru: MRU (Maximum Receive Unit) value of the endpoint controller
|
|
* @index: MHI Endpoint controller index
|
|
*/
|
|
struct mhi_ep_cntrl {
|
|
struct device *cntrl_dev;
|
|
struct mhi_ep_device *mhi_dev;
|
|
void __iomem *mmio;
|
|
|
|
struct mhi_ep_chan *mhi_chan;
|
|
struct mhi_ep_event *mhi_event;
|
|
struct mhi_ep_cmd *mhi_cmd;
|
|
struct mhi_ep_sm *sm;
|
|
|
|
void (*raise_irq)(struct mhi_ep_cntrl *mhi_cntrl, u32 vector);
|
|
int (*alloc_map)(struct mhi_ep_cntrl *mhi_cntrl, u64 pci_addr, phys_addr_t *phys_ptr,
|
|
void __iomem **virt, size_t size);
|
|
void (*unmap_free)(struct mhi_ep_cntrl *mhi_cntrl, u64 pci_addr, phys_addr_t phys,
|
|
void __iomem *virt, size_t size);
|
|
int (*read_from_host)(struct mhi_ep_cntrl *mhi_cntrl, u64 from, void *to, size_t size);
|
|
int (*write_to_host)(struct mhi_ep_cntrl *mhi_cntrl, void *from, u64 to, size_t size);
|
|
|
|
enum mhi_state mhi_state;
|
|
|
|
u32 max_chan;
|
|
u32 mru;
|
|
u32 index;
|
|
};
|
|
|
|
/**
|
|
* struct mhi_ep_device - Structure representing an MHI Endpoint device that binds
|
|
* to channels or is associated with controllers
|
|
* @dev: Driver model device node for the MHI Endpoint device
|
|
* @mhi_cntrl: Controller the device belongs to
|
|
* @id: Pointer to MHI Endpoint device ID struct
|
|
* @name: Name of the associated MHI Endpoint device
|
|
* @ul_chan: UL (from host to endpoint) channel for the device
|
|
* @dl_chan: DL (from endpoint to host) channel for the device
|
|
* @dev_type: MHI device type
|
|
*/
|
|
struct mhi_ep_device {
|
|
struct device dev;
|
|
struct mhi_ep_cntrl *mhi_cntrl;
|
|
const struct mhi_device_id *id;
|
|
const char *name;
|
|
struct mhi_ep_chan *ul_chan;
|
|
struct mhi_ep_chan *dl_chan;
|
|
enum mhi_device_type dev_type;
|
|
};
|
|
|
|
/**
|
|
* struct mhi_ep_driver - Structure representing a MHI Endpoint client driver
|
|
* @id_table: Pointer to MHI Endpoint device ID table
|
|
* @driver: Device driver model driver
|
|
* @probe: CB function for client driver probe function
|
|
* @remove: CB function for client driver remove function
|
|
* @ul_xfer_cb: CB function for UL (from host to endpoint) data transfer
|
|
* @dl_xfer_cb: CB function for DL (from endpoint to host) data transfer
|
|
*/
|
|
struct mhi_ep_driver {
|
|
const struct mhi_device_id *id_table;
|
|
struct device_driver driver;
|
|
int (*probe)(struct mhi_ep_device *mhi_ep,
|
|
const struct mhi_device_id *id);
|
|
void (*remove)(struct mhi_ep_device *mhi_ep);
|
|
void (*ul_xfer_cb)(struct mhi_ep_device *mhi_dev,
|
|
struct mhi_result *result);
|
|
void (*dl_xfer_cb)(struct mhi_ep_device *mhi_dev,
|
|
struct mhi_result *result);
|
|
};
|
|
|
|
#define to_mhi_ep_device(dev) container_of(dev, struct mhi_ep_device, dev)
|
|
#define to_mhi_ep_driver(drv) container_of(drv, struct mhi_ep_driver, driver)
|
|
|
|
/*
|
|
* module_mhi_ep_driver() - Helper macro for drivers that don't do
|
|
* anything special other than using default mhi_ep_driver_register() and
|
|
* mhi_ep_driver_unregister(). This eliminates a lot of boilerplate.
|
|
* Each module may only use this macro once.
|
|
*/
|
|
#define module_mhi_ep_driver(mhi_drv) \
|
|
module_driver(mhi_drv, mhi_ep_driver_register, \
|
|
mhi_ep_driver_unregister)
|
|
|
|
/*
|
|
* Macro to avoid include chaining to get THIS_MODULE
|
|
*/
|
|
#define mhi_ep_driver_register(mhi_drv) \
|
|
__mhi_ep_driver_register(mhi_drv, THIS_MODULE)
|
|
|
|
/**
|
|
* __mhi_ep_driver_register - Register a driver with MHI Endpoint bus
|
|
* @mhi_drv: Driver to be associated with the device
|
|
* @owner: The module owner
|
|
*
|
|
* Return: 0 if driver registrations succeeds, a negative error code otherwise.
|
|
*/
|
|
int __mhi_ep_driver_register(struct mhi_ep_driver *mhi_drv, struct module *owner);
|
|
|
|
/**
|
|
* mhi_ep_driver_unregister - Unregister a driver from MHI Endpoint bus
|
|
* @mhi_drv: Driver associated with the device
|
|
*/
|
|
void mhi_ep_driver_unregister(struct mhi_ep_driver *mhi_drv);
|
|
|
|
/**
|
|
* mhi_ep_register_controller - Register MHI Endpoint controller
|
|
* @mhi_cntrl: MHI Endpoint controller to register
|
|
* @config: Configuration to use for the controller
|
|
*
|
|
* Return: 0 if controller registrations succeeds, a negative error code otherwise.
|
|
*/
|
|
int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl,
|
|
const struct mhi_ep_cntrl_config *config);
|
|
|
|
/**
|
|
* mhi_ep_unregister_controller - Unregister MHI Endpoint controller
|
|
* @mhi_cntrl: MHI Endpoint controller to unregister
|
|
*/
|
|
void mhi_ep_unregister_controller(struct mhi_ep_cntrl *mhi_cntrl);
|
|
|
|
#endif
|