Chris Lew | a9a78ae | 2017-05-11 16:47:37 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2014-2017, The Linux Foundation. All rights reserved. |
Chris Lew | fa6135e | 2016-08-01 13:29:46 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | #ifndef _SOC_QCOM_GLINK_XPRT_IF_H_ |
| 13 | #define _SOC_QCOM_GLINK_XPRT_IF_H_ |
| 14 | |
| 15 | #include <linux/bitops.h> |
| 16 | #include <linux/list.h> |
| 17 | #include <linux/types.h> |
| 18 | |
| 19 | struct glink_core_xprt_ctx; |
| 20 | struct glink_core_if; |
| 21 | struct channel_ctx; |
| 22 | struct glink_core_rx_intent; |
| 23 | |
| 24 | enum buf_type { |
| 25 | LINEAR = 0, |
| 26 | VECTOR, |
| 27 | }; |
| 28 | |
| 29 | enum xprt_ids { |
| 30 | SMEM_XPRT_ID = 100, |
| 31 | SPIV2_XPRT_ID = SMEM_XPRT_ID, |
| 32 | SMD_TRANS_XPRT_ID = 200, |
| 33 | LLOOP_XPRT_ID = 300, |
| 34 | MOCK_XPRT_HIGH_ID = 390, |
| 35 | MOCK_XPRT_ID = 400, |
| 36 | MOCK_XPRT_LOW_ID = 410, |
| 37 | }; |
| 38 | |
| 39 | #define GCAP_SIGNALS BIT(0) |
| 40 | #define GCAP_INTENTLESS BIT(1) |
| 41 | #define GCAP_TRACER_PKT BIT(2) |
| 42 | #define GCAP_AUTO_QUEUE_RX_INT BIT(3) |
| 43 | |
| 44 | /** |
| 45 | * struct glink_core_tx_pkt - Transmit Packet information |
| 46 | * @list_done: Index to the channel's transmit queue. |
| 47 | * @list_done: Index to the channel's acknowledgment queue. |
| 48 | * @pkt_priv: Private information specific to the packet. |
| 49 | * @data: Pointer to the buffer containing the data. |
| 50 | * @riid: Remote receive intent used to transmit the packet. |
| 51 | * @rcid: Remote channel receiving the packet. |
| 52 | * @size: Total size of the data in the packet. |
| 53 | * @tx_len: Data length to transmit in the current transmit slot. |
| 54 | * @size_remaining: Remaining size of the data in the packet. |
| 55 | * @intent_size: Receive intent size queued by the remote side. |
| 56 | * @tracer_pkt: Flag to indicate if the packet is a tracer packet. |
| 57 | * @iovec: Pointer to the vector buffer packet. |
| 58 | * @vprovider: Packet-specific virtual buffer provider function. |
| 59 | * @pprovider: Packet-specific physical buffer provider function. |
| 60 | * @cookie: Transport-specific cookie |
| 61 | * @pkt_ref: Active references to the packet. |
| 62 | */ |
| 63 | struct glink_core_tx_pkt { |
| 64 | struct list_head list_node; |
| 65 | struct list_head list_done; |
| 66 | const void *pkt_priv; |
| 67 | const void *data; |
| 68 | uint32_t riid; |
| 69 | uint32_t rcid; |
| 70 | uint32_t size; |
| 71 | uint32_t tx_len; |
| 72 | uint32_t size_remaining; |
| 73 | size_t intent_size; |
| 74 | bool tracer_pkt; |
| 75 | void *iovec; |
| 76 | void * (*vprovider)(void *iovec, size_t offset, size_t *size); |
| 77 | void * (*pprovider)(void *iovec, size_t offset, size_t *size); |
| 78 | void *cookie; |
| 79 | struct rwref_lock pkt_ref; |
| 80 | }; |
| 81 | |
| 82 | /** |
| 83 | * Note - each call to register the interface must pass a unique |
| 84 | * instance of this data. |
| 85 | */ |
| 86 | struct glink_transport_if { |
| 87 | /* Negotiation */ |
| 88 | void (*tx_cmd_version)(struct glink_transport_if *if_ptr, |
| 89 | uint32_t version, |
| 90 | uint32_t features); |
| 91 | void (*tx_cmd_version_ack)(struct glink_transport_if *if_ptr, |
| 92 | uint32_t version, |
| 93 | uint32_t features); |
| 94 | uint32_t (*set_version)(struct glink_transport_if *if_ptr, |
| 95 | uint32_t version, |
| 96 | uint32_t features); |
| 97 | |
| 98 | /* channel state */ |
| 99 | int (*tx_cmd_ch_open)(struct glink_transport_if *if_ptr, uint32_t lcid, |
| 100 | const char *name, uint16_t req_xprt); |
| 101 | int (*tx_cmd_ch_close)(struct glink_transport_if *if_ptr, |
| 102 | uint32_t lcid); |
| 103 | void (*tx_cmd_ch_remote_open_ack)(struct glink_transport_if *if_ptr, |
| 104 | uint32_t rcid, uint16_t xprt_resp); |
| 105 | void (*tx_cmd_ch_remote_close_ack)(struct glink_transport_if *if_ptr, |
| 106 | uint32_t rcid); |
| 107 | int (*ssr)(struct glink_transport_if *if_ptr); |
| 108 | |
| 109 | /* channel data */ |
| 110 | int (*allocate_rx_intent)(struct glink_transport_if *if_ptr, |
| 111 | size_t size, |
| 112 | struct glink_core_rx_intent *intent); |
| 113 | int (*deallocate_rx_intent)(struct glink_transport_if *if_ptr, |
| 114 | struct glink_core_rx_intent *intent); |
| 115 | /* Optional */ |
| 116 | int (*reuse_rx_intent)(struct glink_transport_if *if_ptr, |
| 117 | struct glink_core_rx_intent *intent); |
| 118 | |
| 119 | int (*tx_cmd_local_rx_intent)(struct glink_transport_if *if_ptr, |
| 120 | uint32_t lcid, size_t size, uint32_t liid); |
| 121 | void (*tx_cmd_local_rx_done)(struct glink_transport_if *if_ptr, |
| 122 | uint32_t lcid, uint32_t liid, bool reuse); |
| 123 | int (*tx)(struct glink_transport_if *if_ptr, uint32_t lcid, |
| 124 | struct glink_core_tx_pkt *pctx); |
| 125 | int (*tx_cmd_rx_intent_req)(struct glink_transport_if *if_ptr, |
| 126 | uint32_t lcid, size_t size); |
| 127 | int (*tx_cmd_remote_rx_intent_req_ack)( |
| 128 | struct glink_transport_if *if_ptr, |
| 129 | uint32_t lcid, bool granted); |
| 130 | int (*tx_cmd_set_sigs)(struct glink_transport_if *if_ptr, |
| 131 | uint32_t lcid, uint32_t sigs); |
| 132 | |
| 133 | /* Optional. If NULL at xprt registration, dummies will be used */ |
| 134 | int (*poll)(struct glink_transport_if *if_ptr, uint32_t lcid); |
| 135 | int (*mask_rx_irq)(struct glink_transport_if *if_ptr, uint32_t lcid, |
| 136 | bool mask, void *pstruct); |
| 137 | int (*wait_link_down)(struct glink_transport_if *if_ptr); |
| 138 | int (*tx_cmd_tracer_pkt)(struct glink_transport_if *if_ptr, |
| 139 | uint32_t lcid, struct glink_core_tx_pkt *pctx); |
| 140 | unsigned long (*get_power_vote_ramp_time)( |
| 141 | struct glink_transport_if *if_ptr, uint32_t state); |
| 142 | int (*power_vote)(struct glink_transport_if *if_ptr, uint32_t state); |
| 143 | int (*power_unvote)(struct glink_transport_if *if_ptr); |
Chris Lew | a9a78ae | 2017-05-11 16:47:37 -0700 | [diff] [blame] | 144 | int (*rx_rt_vote)(struct glink_transport_if *if_ptr); |
| 145 | int (*rx_rt_unvote)(struct glink_transport_if *if_ptr); |
Chris Lew | fa6135e | 2016-08-01 13:29:46 -0700 | [diff] [blame] | 146 | /* |
| 147 | * Keep data pointers at the end of the structure after all function |
| 148 | * pointer to allow for in-place initialization. |
| 149 | */ |
| 150 | |
| 151 | /* private pointer for core */ |
| 152 | struct glink_core_xprt_ctx *glink_core_priv; |
| 153 | |
| 154 | /* core pointer (set during transport registration) */ |
| 155 | struct glink_core_if *glink_core_if_ptr; |
| 156 | }; |
| 157 | |
| 158 | #ifdef CONFIG_MSM_GLINK |
| 159 | |
| 160 | /** |
| 161 | * get_tx_vaddr() - Get the virtual address from which the tx has to be done |
| 162 | * @pctx: transmit packet context. |
| 163 | * @offset: offset into the packet. |
| 164 | * @tx_size: pointer to hold the length of the contiguous buffer |
| 165 | * space. |
| 166 | * |
| 167 | * Return: Address from which the tx has to be done. |
| 168 | */ |
| 169 | static inline void *get_tx_vaddr(struct glink_core_tx_pkt *pctx, size_t offset, |
| 170 | size_t *tx_size) |
| 171 | { |
| 172 | void *pdata; |
| 173 | |
| 174 | if (pctx->vprovider) { |
| 175 | return pctx->vprovider((void *)pctx->iovec, offset, tx_size); |
| 176 | } else if (pctx->pprovider) { |
| 177 | pdata = pctx->pprovider((void *)pctx->iovec, offset, tx_size); |
| 178 | return phys_to_virt((unsigned long)pdata); |
| 179 | } |
| 180 | return NULL; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * glink_xprt_name_to_id() - convert transport name to id |
| 185 | * @name: Name of the transport. |
| 186 | * @id: Assigned id. |
| 187 | * |
| 188 | * Return: 0 on success or standard Linux error code. |
| 189 | */ |
| 190 | int glink_xprt_name_to_id(const char *name, uint16_t *id); |
| 191 | |
| 192 | |
| 193 | #else /* CONFIG_MSM_GLINK */ |
| 194 | static inline void *get_tx_vaddr(struct glink_core_tx_pkt *pctx, size_t offset, |
| 195 | size_t *tx_size) |
| 196 | { |
| 197 | return NULL; |
| 198 | } |
| 199 | |
| 200 | static inline int glink_xprt_name_to_id(const char *name, uint16_t *id) |
| 201 | { |
| 202 | return -ENODEV; |
| 203 | } |
| 204 | |
| 205 | #endif /* CONFIG_MSM_GLINK */ |
| 206 | #endif /* _SOC_QCOM_GLINK_XPRT_IF_H_ */ |