diff options
| author | Karthikeyan Ramasubramanian <kramasub@codeaurora.org> | 2016-02-01 16:53:22 -0700 |
|---|---|---|
| committer | David Keitel <dkeitel@codeaurora.org> | 2016-03-22 11:07:59 -0700 |
| commit | 016c030cc67882b2143fc8098afa471c8bf33bdf (patch) | |
| tree | 9c36744577971acb0c98729f79385af44796f0b1 /include | |
| parent | 9b066e098123f8620a8f5a3decf23b6a0267eee4 (diff) | |
net: ipc_router: Add snapshot of IPC Router
This snapshot is taken as of msm-3.18 commit e70ad0cd (Promotion of
kernel.lnx.3.18-151201.)
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/linux/ipc_router.h | 344 | ||||
| -rw-r--r-- | include/linux/ipc_router_xprt.h | 171 | ||||
| -rw-r--r-- | include/uapi/linux/msm_ipc.h | 91 |
3 files changed, 606 insertions, 0 deletions
diff --git a/include/linux/ipc_router.h b/include/linux/ipc_router.h new file mode 100644 index 000000000000..c89b972a91bd --- /dev/null +++ b/include/linux/ipc_router.h @@ -0,0 +1,344 @@ +/* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _IPC_ROUTER_H +#define _IPC_ROUTER_H + +#include <linux/types.h> +#include <linux/socket.h> +#include <linux/errno.h> +#include <linux/mm.h> +#include <linux/list.h> +#include <linux/pm.h> +#include <linux/msm_ipc.h> +#include <linux/device.h> +#include <linux/kref.h> + +/* Maximum Wakeup Source Name Size */ +#define MAX_WS_NAME_SZ 32 + +#define IPC_RTR_ERR(buf, ...) \ + pr_err("IPC_RTR: " buf, __VA_ARGS__) + +/** + * enum msm_ipc_router_event - Events that will be generated by IPC Router + */ +enum msm_ipc_router_event { + IPC_ROUTER_CTRL_CMD_DATA = 1, + IPC_ROUTER_CTRL_CMD_HELLO, + IPC_ROUTER_CTRL_CMD_BYE, + IPC_ROUTER_CTRL_CMD_NEW_SERVER, + IPC_ROUTER_CTRL_CMD_REMOVE_SERVER, + IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT, + IPC_ROUTER_CTRL_CMD_RESUME_TX, +}; + +/** + * rr_control_msg - Control message structure + * @cmd: Command identifier for HELLO message in Version 1. + * @hello: Message structure for HELLO message in Version 2. + * @srv: Message structure for NEW_SERVER/REMOVE_SERVER events. + * @cli: Message structure for REMOVE_CLIENT event. + */ +union rr_control_msg { + uint32_t cmd; + struct { + uint32_t cmd; + uint32_t magic; + uint32_t capability; + } hello; + struct { + uint32_t cmd; + uint32_t service; + uint32_t instance; + uint32_t node_id; + uint32_t port_id; + } srv; + struct { + uint32_t cmd; + uint32_t node_id; + uint32_t port_id; + } cli; +}; + +struct comm_mode_info { + int mode; + void *xprt_info; +}; + +enum ipc_rtr_af_event_type { + IPCRTR_AF_INIT = 1, + IPCRTR_AF_DEINIT, +}; + +/** + * msm_ipc_port - Definition of IPC Router port + * @list: List(local/control ports) in which this port is present. + * @ref: Reference count for this port. + * @this_port: Contains port's node_id and port_id information. + * @port_name: Contains service & instance info if the port hosts a service. + * @type: Type of the port - Client, Service, Control or Security Config. + * @flags: Flags to identify the port state. + * @port_lock_lhc3: Lock to protect access to the port information. + * @mode_info: Communication mode of the port owner. + * @port_rx_q: Receive queue where incoming messages are queued. + * @port_rx_q_lock_lhc3: Lock to protect access to the port's rx_q. + * @rx_ws_name: Name of the receive wakeup source. + * @port_rx_ws: Wakeup source to prevent suspend until the rx_q is empty. + * @port_rx_wait_q: Wait queue to wait for the incoming messages. + * @restart_state: Flag to hold the restart state information. + * @restart_lock: Lock to protect access to the restart_state. + * @restart_wait: Wait Queue to wait for any restart events. + * @endpoint: Contains the information related to user-space interface. + * @notify: Function to notify the incoming events on the port. + * @check_send_permissions: Function to check access control from this port. + * @num_tx: Number of packets transmitted. + * @num_rx: Number of packets received. + * @num_tx_bytes: Number of bytes transmitted. + * @num_rx_bytes: Number of bytes received. + * @priv: Private information registered by the port owner. + */ +struct msm_ipc_port { + struct list_head list; + struct kref ref; + + struct msm_ipc_port_addr this_port; + struct msm_ipc_port_name port_name; + uint32_t type; + unsigned flags; + struct mutex port_lock_lhc3; + struct comm_mode_info mode_info; + + struct msm_ipc_port_addr dest_addr; + int conn_status; + + struct list_head port_rx_q; + struct mutex port_rx_q_lock_lhc3; + char rx_ws_name[MAX_WS_NAME_SZ]; + struct wakeup_source *port_rx_ws; + wait_queue_head_t port_rx_wait_q; + wait_queue_head_t port_tx_wait_q; + + int restart_state; + spinlock_t restart_lock; + wait_queue_head_t restart_wait; + + void *rport_info; + void *endpoint; + void (*notify)(unsigned event, void *oob_data, + size_t oob_data_len, void *priv); + int (*check_send_permissions)(void *data); + + uint32_t num_tx; + uint32_t num_rx; + unsigned long num_tx_bytes; + unsigned long num_rx_bytes; + void *priv; +}; + +#ifdef CONFIG_IPC_ROUTER +/** + * msm_ipc_router_create_port() - Create a IPC Router port/endpoint + * @notify: Callback function to notify any event on the port. + * @event: Event ID to be handled. + * @oob_data: Any out-of-band data associated with the event. + * @oob_data_len: Size of the out-of-band data, if valid. + * @priv: Private data registered during the port creation. + * @priv: Private info to be passed while the notification is generated. + * + * @return: Pointer to the port on success, NULL on error. + */ +struct msm_ipc_port *msm_ipc_router_create_port( + void (*notify)(unsigned event, void *oob_data, + size_t oob_data_len, void *priv), + void *priv); + +/** + * msm_ipc_router_bind_control_port() - Bind a port as a control port + * @port_ptr: Port which needs to be marked as a control port. + * + * @return: 0 on success, standard Linux error codes on error. + */ +int msm_ipc_router_bind_control_port(struct msm_ipc_port *port_ptr); + +/** + * msm_ipc_router_lookup_server_name() - Resolve server address + * @srv_name: Name<service:instance> of the server to be resolved. + * @srv_info: Buffer to hold the resolved address. + * @num_entries_in_array: Number of server info the buffer can hold. + * @lookup_mask: Mask to specify the range of instances to be resolved. + * + * @return: Number of server addresses resolved on success, < 0 on error. + */ +int msm_ipc_router_lookup_server_name(struct msm_ipc_port_name *srv_name, + struct msm_ipc_server_info *srv_info, + int num_entries_in_array, + uint32_t lookup_mask); + +/** + * msm_ipc_router_send_msg() - Send a message/packet + * @src: Sender's address/port. + * @dest: Destination address. + * @data: Pointer to the data to be sent. + * @data_len: Length of the data to be sent. + * + * @return: 0 on success, < 0 on error. + */ +int msm_ipc_router_send_msg(struct msm_ipc_port *src, + struct msm_ipc_addr *dest, + void *data, unsigned int data_len); + +/** + * msm_ipc_router_get_curr_pkt_size() - Get the packet size of the first + * packet in the rx queue + * @port_ptr: Port which owns the rx queue. + * + * @return: Returns the size of the first packet, if available. + * 0 if no packets available, < 0 on error. + */ +int msm_ipc_router_get_curr_pkt_size(struct msm_ipc_port *port_ptr); + +/** + * msm_ipc_router_read_msg() - Read a message/packet + * @port_ptr: Receiver's port/address. + * @data: Pointer containing the address of the received data. + * @src: Address of the sender/source. + * @len: Length of the data being read. + * + * @return: 0 on success, < 0 on error. + */ +int msm_ipc_router_read_msg(struct msm_ipc_port *port_ptr, + struct msm_ipc_addr *src, + unsigned char **data, + unsigned int *len); + +/** + * msm_ipc_router_close_port() - Close the port + * @port_ptr: Pointer to the port to be closed. + * + * @return: 0 on success, < 0 on error. + */ +int msm_ipc_router_close_port(struct msm_ipc_port *port_ptr); + +/** + * msm_ipc_router_register_server() - Register a service on a port + * @server_port: IPC Router port with which a service is registered. + * @name: Service name <service_id:instance_id> that gets registered. + * + * @return: 0 on success, standard Linux error codes on error. + */ +int msm_ipc_router_register_server(struct msm_ipc_port *server_port, + struct msm_ipc_addr *name); + +/** + * msm_ipc_router_unregister_server() - Unregister a service from a port + * @server_port: Port with with a service is already registered. + * + * @return: 0 on success, standard Linux error codes on error. + */ +int msm_ipc_router_unregister_server(struct msm_ipc_port *server_port); + +/** + * register_ipcrtr_af_init_notifier() - Register for ipc router socket + * address family initialization callback + * @nb: Notifier block which will be notified once address family is + * initialized. + * + * Return: 0 on success, standard error code otherwise. + */ +int register_ipcrtr_af_init_notifier(struct notifier_block *nb); + +/** + * unregister_ipcrtr_af_init_notifier() - Unregister for ipc router socket + * address family initialization callback + * @nb: Notifier block which will be notified once address family is + * initialized. + * + * Return: 0 on success, standard error code otherwise. + */ +int unregister_ipcrtr_af_init_notifier(struct notifier_block *nb); + +#else + +struct msm_ipc_port *msm_ipc_router_create_port( + void (*notify)(unsigned event, void *oob_data, + size_t oob_data_len, void *priv), + void *priv) +{ + return NULL; +} + +static inline int msm_ipc_router_bind_control_port( + struct msm_ipc_port *port_ptr) +{ + return -ENODEV; +} + +int msm_ipc_router_lookup_server_name(struct msm_ipc_port_name *srv_name, + struct msm_ipc_server_info *srv_info, + int num_entries_in_array, + uint32_t lookup_mask) +{ + return -ENODEV; +} + +int msm_ipc_router_send_msg(struct msm_ipc_port *src, + struct msm_ipc_addr *dest, + void *data, unsigned int data_len) +{ + return -ENODEV; +} + +int msm_ipc_router_get_curr_pkt_size(struct msm_ipc_port *port_ptr) +{ + return -ENODEV; +} + +int msm_ipc_router_read_msg(struct msm_ipc_port *port_ptr, + struct msm_ipc_addr *src, + unsigned char **data, + unsigned int *len) +{ + return -ENODEV; +} + +int msm_ipc_router_close_port(struct msm_ipc_port *port_ptr) +{ + return -ENODEV; +} + +static inline int msm_ipc_router_register_server( + struct msm_ipc_port *server_port, + struct msm_ipc_addr *name) +{ + return -ENODEV; +} + +static inline int msm_ipc_router_unregister_server( + struct msm_ipc_port *server_port) +{ + return -ENODEV; +} + +int register_ipcrtr_af_notifier(struct notifier_block *nb) +{ + return -ENODEV; +} + +int register_ipcrtr_af_notifier(struct notifier_block *nb) +{ + return -ENODEV; +} + +#endif + +#endif diff --git a/include/linux/ipc_router_xprt.h b/include/linux/ipc_router_xprt.h new file mode 100644 index 000000000000..8e3a2b3f1c99 --- /dev/null +++ b/include/linux/ipc_router_xprt.h @@ -0,0 +1,171 @@ +/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _IPC_ROUTER_XPRT_H +#define _IPC_ROUTER_XPRT_H + +#include <linux/types.h> +#include <linux/errno.h> +#include <linux/mm.h> +#include <linux/list.h> +#include <linux/platform_device.h> +#include <linux/msm_ipc.h> +#include <linux/ipc_router.h> +#include <linux/kref.h> + +#define IPC_ROUTER_XPRT_EVENT_DATA 1 +#define IPC_ROUTER_XPRT_EVENT_OPEN 2 +#define IPC_ROUTER_XPRT_EVENT_CLOSE 3 + +#define FRAG_PKT_WRITE_ENABLE 0x1 + +/** + * rr_header_v1 - IPC Router header version 1 + * @version: Version information. + * @type: IPC Router Message Type. + * @src_node_id: Source Node ID of the message. + * @src_port_id: Source Port ID of the message. + * @control_flag: Flag to indicate flow control. + * @size: Size of the IPC Router payload. + * @dst_node_id: Destination Node ID of the message. + * @dst_port_id: Destination Port ID of the message. + */ +struct rr_header_v1 { + uint32_t version; + uint32_t type; + uint32_t src_node_id; + uint32_t src_port_id; + uint32_t control_flag; + uint32_t size; + uint32_t dst_node_id; + uint32_t dst_port_id; +}; + +/** + * rr_header_v2 - IPC Router header version 2 + * @version: Version information. + * @type: IPC Router Message Type. + * @control_flag: Flags to indicate flow control, optional header etc. + * @opt_len: Combined size of the all optional headers in units of words. + * @size: Size of the IPC Router payload. + * @src_node_id: Source Node ID of the message. + * @src_port_id: Source Port ID of the message. + * @dst_node_id: Destination Node ID of the message. + * @dst_port_id: Destination Port ID of the message. + */ +struct rr_header_v2 { + uint8_t version; + uint8_t type; + uint8_t control_flag; + uint8_t opt_len; + uint32_t size; + uint16_t src_node_id; + uint16_t src_port_id; + uint16_t dst_node_id; + uint16_t dst_port_id; +} __attribute__((__packed__)); + +union rr_header { + struct rr_header_v1 hdr_v1; + struct rr_header_v2 hdr_v2; +}; + +/** + * rr_opt_hdr - Optional header for IPC Router header version 2 + * @len: Total length of the optional header. + * @data: Pointer to the actual optional header. + */ +struct rr_opt_hdr { + size_t len; + unsigned char *data; +}; + +#define IPC_ROUTER_HDR_SIZE sizeof(union rr_header) +#define IPCR_WORD_SIZE 4 + +/** + * rr_packet - Router to Router packet structure + * @list: Pointer to prev & next packets in a port's rx list. + * @hdr: Header information extracted from or prepended to a packet. + * @opt_hdr: Optinal header information. + * @pkt_fragment_q: Queue of SKBs containing payload. + * @length: Length of data in the chain of SKBs + * @ref: Reference count for the packet. + */ +struct rr_packet { + struct list_head list; + struct rr_header_v1 hdr; + struct rr_opt_hdr opt_hdr; + struct sk_buff_head *pkt_fragment_q; + uint32_t length; + struct kref ref; +}; + +/** + * msm_ipc_router_xprt - Structure to hold XPRT specific information + * @name: Name of the XPRT. + * @link_id: Network cluster ID to which the XPRT belongs to. + * @priv: XPRT's private data. + * @get_version: Method to get header version supported by the XPRT. + * @get_option: Method to get XPRT specific options. + * @read_avail: Method to get data size available to be read from the XPRT. + * @read: Method to read data from the XPRT. + * @write_avail: Method to get write space available in the XPRT. + * @write: Method to write data to the XPRT. + * @close: Method to close the XPRT. + * @sft_close_done: Method to indicate to the XPRT that handling of reset + * event is complete. + */ +struct msm_ipc_router_xprt { + char *name; + uint32_t link_id; + void *priv; + + int (*get_version)(struct msm_ipc_router_xprt *xprt); + int (*get_option)(struct msm_ipc_router_xprt *xprt); + int (*read_avail)(struct msm_ipc_router_xprt *xprt); + int (*read)(void *data, uint32_t len, + struct msm_ipc_router_xprt *xprt); + int (*write_avail)(struct msm_ipc_router_xprt *xprt); + int (*write)(void *data, uint32_t len, + struct msm_ipc_router_xprt *xprt); + int (*close)(struct msm_ipc_router_xprt *xprt); + void (*sft_close_done)(struct msm_ipc_router_xprt *xprt); +}; + +void msm_ipc_router_xprt_notify(struct msm_ipc_router_xprt *xprt, + unsigned event, + void *data); + +/** + * create_pkt() - Create a Router packet + * @data: SKB queue to be contained inside the packet. + * + * @return: pointer to packet on success, NULL on failure. + */ +struct rr_packet *create_pkt(struct sk_buff_head *data); +struct rr_packet *clone_pkt(struct rr_packet *pkt); +void release_pkt(struct rr_packet *pkt); + +/** + * ipc_router_peek_pkt_size() - Peek into the packet header to get potential packet size + * @data: Starting address of the packet which points to router header. + * + * @returns: potential packet size on success, < 0 on error. + * + * This function is used by the underlying transport abstraction layer to + * peek into the potential packet size of an incoming packet. This information + * is used to perform link layer fragmentation and re-assembly + */ +int ipc_router_peek_pkt_size(char *data); + +#endif diff --git a/include/uapi/linux/msm_ipc.h b/include/uapi/linux/msm_ipc.h new file mode 100644 index 000000000000..ea2f0ff60330 --- /dev/null +++ b/include/uapi/linux/msm_ipc.h @@ -0,0 +1,91 @@ +#ifndef _UAPI_MSM_IPC_H_ +#define _UAPI_MSM_IPC_H_ + +#include <linux/types.h> +#include <linux/ioctl.h> + +struct msm_ipc_port_addr { + uint32_t node_id; + uint32_t port_id; +}; + +struct msm_ipc_port_name { + uint32_t service; + uint32_t instance; +}; + +struct msm_ipc_addr { + unsigned char addrtype; + union { + struct msm_ipc_port_addr port_addr; + struct msm_ipc_port_name port_name; + } addr; +}; + +#define MSM_IPC_WAIT_FOREVER (~0) /* timeout for permanent subscription */ + +/* + * Socket API + */ + +#ifndef AF_MSM_IPC +#define AF_MSM_IPC 27 +#endif + +#ifndef PF_MSM_IPC +#define PF_MSM_IPC AF_MSM_IPC +#endif + +#define MSM_IPC_ADDR_NAME 1 +#define MSM_IPC_ADDR_ID 2 + +struct sockaddr_msm_ipc { + unsigned short family; + struct msm_ipc_addr address; + unsigned char reserved; +}; + +struct config_sec_rules_args { + int num_group_info; + uint32_t service_id; + uint32_t instance_id; + unsigned reserved; + gid_t group_id[0]; +}; + +#define IPC_ROUTER_IOCTL_MAGIC (0xC3) + +#define IPC_ROUTER_IOCTL_GET_VERSION \ + _IOR(IPC_ROUTER_IOCTL_MAGIC, 0, unsigned int) + +#define IPC_ROUTER_IOCTL_GET_MTU \ + _IOR(IPC_ROUTER_IOCTL_MAGIC, 1, unsigned int) + +#define IPC_ROUTER_IOCTL_LOOKUP_SERVER \ + _IOWR(IPC_ROUTER_IOCTL_MAGIC, 2, struct sockaddr_msm_ipc) + +#define IPC_ROUTER_IOCTL_GET_CURR_PKT_SIZE \ + _IOR(IPC_ROUTER_IOCTL_MAGIC, 3, unsigned int) + +#define IPC_ROUTER_IOCTL_BIND_CONTROL_PORT \ + _IOR(IPC_ROUTER_IOCTL_MAGIC, 4, unsigned int) + +#define IPC_ROUTER_IOCTL_CONFIG_SEC_RULES \ + _IOR(IPC_ROUTER_IOCTL_MAGIC, 5, struct config_sec_rules_args) + +struct msm_ipc_server_info { + uint32_t node_id; + uint32_t port_id; + uint32_t service; + uint32_t instance; +}; + +struct server_lookup_args { + struct msm_ipc_port_name port_name; + int num_entries_in_array; + int num_entries_found; + uint32_t lookup_mask; + struct msm_ipc_server_info srv_info[0]; +}; + +#endif |
