| 1 | /**************************************************************************** |
| 2 | * Driver for Solarflare Solarstorm network controllers and boards |
| 3 | * Copyright 2010-2012 Solarflare Communications Inc. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published |
| 7 | * by the Free Software Foundation, incorporated herein by reference. |
| 8 | */ |
| 9 | #ifndef _VFDI_H |
| 10 | #define _VFDI_H |
| 11 | |
| 12 | /** |
| 13 | * DOC: Virtual Function Driver Interface |
| 14 | * |
| 15 | * This file contains software structures used to form a two way |
| 16 | * communication channel between the VF driver and the PF driver, |
| 17 | * named Virtual Function Driver Interface (VFDI). |
| 18 | * |
| 19 | * For the purposes of VFDI, a page is a memory region with size and |
| 20 | * alignment of 4K. All addresses are DMA addresses to be used within |
| 21 | * the domain of the relevant VF. |
| 22 | * |
| 23 | * The only hardware-defined channels for a VF driver to communicate |
| 24 | * with the PF driver are the event mailboxes (%FR_CZ_USR_EV |
| 25 | * registers). Writing to these registers generates an event with |
| 26 | * EV_CODE = EV_CODE_USR_EV, USER_QID set to the index of the mailbox |
| 27 | * and USER_EV_REG_VALUE set to the value written. The PF driver may |
| 28 | * direct or disable delivery of these events by setting |
| 29 | * %FR_CZ_USR_EV_CFG. |
| 30 | * |
| 31 | * The PF driver can send arbitrary events to arbitrary event queues. |
| 32 | * However, for consistency, VFDI events from the PF are defined to |
| 33 | * follow the same form and be sent to the first event queue assigned |
| 34 | * to the VF while that queue is enabled by the VF driver. |
| 35 | * |
| 36 | * The general form of the variable bits of VFDI events is: |
| 37 | * |
| 38 | * 0 16 24 31 |
| 39 | * | DATA | TYPE | SEQ | |
| 40 | * |
| 41 | * SEQ is a sequence number which should be incremented by 1 (modulo |
| 42 | * 256) for each event. The sequence numbers used in each direction |
| 43 | * are independent. |
| 44 | * |
| 45 | * The VF submits requests of type &struct vfdi_req by sending the |
| 46 | * address of the request (ADDR) in a series of 4 events: |
| 47 | * |
| 48 | * 0 16 24 31 |
| 49 | * | ADDR[0:15] | VFDI_EV_TYPE_REQ_WORD0 | SEQ | |
| 50 | * | ADDR[16:31] | VFDI_EV_TYPE_REQ_WORD1 | SEQ+1 | |
| 51 | * | ADDR[32:47] | VFDI_EV_TYPE_REQ_WORD2 | SEQ+2 | |
| 52 | * | ADDR[48:63] | VFDI_EV_TYPE_REQ_WORD3 | SEQ+3 | |
| 53 | * |
| 54 | * The address must be page-aligned. After receiving such a valid |
| 55 | * series of events, the PF driver will attempt to read the request |
| 56 | * and write a response to the same address. In case of an invalid |
| 57 | * sequence of events or a DMA error, there will be no response. |
| 58 | * |
| 59 | * The VF driver may request that the PF driver writes status |
| 60 | * information into its domain asynchronously. After writing the |
| 61 | * status, the PF driver will send an event of the form: |
| 62 | * |
| 63 | * 0 16 24 31 |
| 64 | * | reserved | VFDI_EV_TYPE_STATUS | SEQ | |
| 65 | * |
| 66 | * In case the VF must be reset for any reason, the PF driver will |
| 67 | * send an event of the form: |
| 68 | * |
| 69 | * 0 16 24 31 |
| 70 | * | reserved | VFDI_EV_TYPE_RESET | SEQ | |
| 71 | * |
| 72 | * It is then the responsibility of the VF driver to request |
| 73 | * reinitialisation of its queues. |
| 74 | */ |
| 75 | #define VFDI_EV_SEQ_LBN 24 |
| 76 | #define VFDI_EV_SEQ_WIDTH 8 |
| 77 | #define VFDI_EV_TYPE_LBN 16 |
| 78 | #define VFDI_EV_TYPE_WIDTH 8 |
| 79 | #define VFDI_EV_TYPE_REQ_WORD0 0 |
| 80 | #define VFDI_EV_TYPE_REQ_WORD1 1 |
| 81 | #define VFDI_EV_TYPE_REQ_WORD2 2 |
| 82 | #define VFDI_EV_TYPE_REQ_WORD3 3 |
| 83 | #define VFDI_EV_TYPE_STATUS 4 |
| 84 | #define VFDI_EV_TYPE_RESET 5 |
| 85 | #define VFDI_EV_DATA_LBN 0 |
| 86 | #define VFDI_EV_DATA_WIDTH 16 |
| 87 | |
| 88 | struct vfdi_endpoint { |
| 89 | u8 mac_addr[ETH_ALEN]; |
| 90 | __be16 tci; |
| 91 | }; |
| 92 | |
| 93 | /** |
| 94 | * enum vfdi_op - VFDI operation enumeration |
| 95 | * @VFDI_OP_RESPONSE: Indicates a response to the request. |
| 96 | * @VFDI_OP_INIT_EVQ: Initialize SRAM entries and initialize an EVQ. |
| 97 | * @VFDI_OP_INIT_RXQ: Initialize SRAM entries and initialize an RXQ. |
| 98 | * @VFDI_OP_INIT_TXQ: Initialize SRAM entries and initialize a TXQ. |
| 99 | * @VFDI_OP_FINI_ALL_QUEUES: Flush all queues, finalize all queues, then |
| 100 | * finalize the SRAM entries. |
| 101 | * @VFDI_OP_INSERT_FILTER: Insert a MAC filter targetting the given RXQ. |
| 102 | * @VFDI_OP_REMOVE_ALL_FILTERS: Remove all filters. |
| 103 | * @VFDI_OP_SET_STATUS_PAGE: Set the DMA page(s) used for status updates |
| 104 | * from PF and write the initial status. |
| 105 | * @VFDI_OP_CLEAR_STATUS_PAGE: Clear the DMA page(s) used for status |
| 106 | * updates from PF. |
| 107 | */ |
| 108 | enum vfdi_op { |
| 109 | VFDI_OP_RESPONSE = 0, |
| 110 | VFDI_OP_INIT_EVQ = 1, |
| 111 | VFDI_OP_INIT_RXQ = 2, |
| 112 | VFDI_OP_INIT_TXQ = 3, |
| 113 | VFDI_OP_FINI_ALL_QUEUES = 4, |
| 114 | VFDI_OP_INSERT_FILTER = 5, |
| 115 | VFDI_OP_REMOVE_ALL_FILTERS = 6, |
| 116 | VFDI_OP_SET_STATUS_PAGE = 7, |
| 117 | VFDI_OP_CLEAR_STATUS_PAGE = 8, |
| 118 | VFDI_OP_LIMIT, |
| 119 | }; |
| 120 | |
| 121 | /* Response codes for VFDI operations. Other values may be used in future. */ |
| 122 | #define VFDI_RC_SUCCESS 0 |
| 123 | #define VFDI_RC_ENOMEM (-12) |
| 124 | #define VFDI_RC_EINVAL (-22) |
| 125 | #define VFDI_RC_EOPNOTSUPP (-95) |
| 126 | #define VFDI_RC_ETIMEDOUT (-110) |
| 127 | |
| 128 | /** |
| 129 | * struct vfdi_req - Request from VF driver to PF driver |
| 130 | * @op: Operation code or response indicator, taken from &enum vfdi_op. |
| 131 | * @rc: Response code. Set to 0 on success or a negative error code on failure. |
| 132 | * @u.init_evq.index: Index of event queue to create. |
| 133 | * @u.init_evq.buf_count: Number of 4k buffers backing event queue. |
| 134 | * @u.init_evq.addr: Array of length %u.init_evq.buf_count containing DMA |
| 135 | * address of each page backing the event queue. |
| 136 | * @u.init_rxq.index: Index of receive queue to create. |
| 137 | * @u.init_rxq.buf_count: Number of 4k buffers backing receive queue. |
| 138 | * @u.init_rxq.evq: Instance of event queue to target receive events at. |
| 139 | * @u.init_rxq.label: Label used in receive events. |
| 140 | * @u.init_rxq.flags: Unused. |
| 141 | * @u.init_rxq.addr: Array of length %u.init_rxq.buf_count containing DMA |
| 142 | * address of each page backing the receive queue. |
| 143 | * @u.init_txq.index: Index of transmit queue to create. |
| 144 | * @u.init_txq.buf_count: Number of 4k buffers backing transmit queue. |
| 145 | * @u.init_txq.evq: Instance of event queue to target transmit completion |
| 146 | * events at. |
| 147 | * @u.init_txq.label: Label used in transmit completion events. |
| 148 | * @u.init_txq.flags: Checksum offload flags. |
| 149 | * @u.init_txq.addr: Array of length %u.init_txq.buf_count containing DMA |
| 150 | * address of each page backing the transmit queue. |
| 151 | * @u.mac_filter.rxq: Insert MAC filter at VF local address/VLAN targetting |
| 152 | * all traffic at this receive queue. |
| 153 | * @u.mac_filter.flags: MAC filter flags. |
| 154 | * @u.set_status_page.dma_addr: Base address for the &struct vfdi_status. |
| 155 | * This address must be page-aligned and the PF may write up to a |
| 156 | * whole page (allowing for extension of the structure). |
| 157 | * @u.set_status_page.peer_page_count: Number of additional pages the VF |
| 158 | * has provided into which peer addresses may be DMAd. |
| 159 | * @u.set_status_page.peer_page_addr: Array of DMA addresses of pages. |
| 160 | * If the number of peers exceeds 256, then the VF must provide |
| 161 | * additional pages in this array. The PF will then DMA up to |
| 162 | * 512 vfdi_endpoint structures into each page. These addresses |
| 163 | * must be page-aligned. |
| 164 | */ |
| 165 | struct vfdi_req { |
| 166 | u32 op; |
| 167 | u32 reserved1; |
| 168 | s32 rc; |
| 169 | u32 reserved2; |
| 170 | union { |
| 171 | struct { |
| 172 | u32 index; |
| 173 | u32 buf_count; |
| 174 | u64 addr[]; |
| 175 | } init_evq; |
| 176 | struct { |
| 177 | u32 index; |
| 178 | u32 buf_count; |
| 179 | u32 evq; |
| 180 | u32 label; |
| 181 | u32 flags; |
| 182 | #define VFDI_RXQ_FLAG_SCATTER_EN 1 |
| 183 | u32 reserved; |
| 184 | u64 addr[]; |
| 185 | } init_rxq; |
| 186 | struct { |
| 187 | u32 index; |
| 188 | u32 buf_count; |
| 189 | u32 evq; |
| 190 | u32 label; |
| 191 | u32 flags; |
| 192 | #define VFDI_TXQ_FLAG_IP_CSUM_DIS 1 |
| 193 | #define VFDI_TXQ_FLAG_TCPUDP_CSUM_DIS 2 |
| 194 | u32 reserved; |
| 195 | u64 addr[]; |
| 196 | } init_txq; |
| 197 | struct { |
| 198 | u32 rxq; |
| 199 | u32 flags; |
| 200 | #define VFDI_MAC_FILTER_FLAG_RSS 1 |
| 201 | #define VFDI_MAC_FILTER_FLAG_SCATTER 2 |
| 202 | } mac_filter; |
| 203 | struct { |
| 204 | u64 dma_addr; |
| 205 | u64 peer_page_count; |
| 206 | u64 peer_page_addr[]; |
| 207 | } set_status_page; |
| 208 | } u; |
| 209 | }; |
| 210 | |
| 211 | /** |
| 212 | * struct vfdi_status - Status provided by PF driver to VF driver |
| 213 | * @generation_start: A generation count DMA'd to VF *before* the |
| 214 | * rest of the structure. |
| 215 | * @generation_end: A generation count DMA'd to VF *after* the |
| 216 | * rest of the structure. |
| 217 | * @version: Version of this structure; currently set to 1. Later |
| 218 | * versions must either be layout-compatible or only be sent to VFs |
| 219 | * that specifically request them. |
| 220 | * @length: Total length of this structure including embedded tables |
| 221 | * @vi_scale: log2 the number of VIs available on this VF. This quantity |
| 222 | * is used by the hardware for register decoding. |
| 223 | * @max_tx_channels: The maximum number of transmit queues the VF can use. |
| 224 | * @rss_rxq_count: The number of receive queues present in the shared RSS |
| 225 | * indirection table. |
| 226 | * @peer_count: Total number of peers in the complete peer list. If larger |
| 227 | * than ARRAY_SIZE(%peers), then the VF must provide sufficient |
| 228 | * additional pages each of which is filled with vfdi_endpoint structures. |
| 229 | * @local: The MAC address and outer VLAN tag of *this* VF |
| 230 | * @peers: Table of peer addresses. The @tci fields in these structures |
| 231 | * are currently unused and must be ignored. Additional peers are |
| 232 | * written into any additional pages provided by the VF. |
| 233 | * @timer_quantum_ns: Timer quantum (nominal period between timer ticks) |
| 234 | * for interrupt moderation timers, in nanoseconds. This member is only |
| 235 | * present if @length is sufficiently large. |
| 236 | */ |
| 237 | struct vfdi_status { |
| 238 | u32 generation_start; |
| 239 | u32 generation_end; |
| 240 | u32 version; |
| 241 | u32 length; |
| 242 | u8 vi_scale; |
| 243 | u8 max_tx_channels; |
| 244 | u8 rss_rxq_count; |
| 245 | u8 reserved1; |
| 246 | u16 peer_count; |
| 247 | u16 reserved2; |
| 248 | struct vfdi_endpoint local; |
| 249 | struct vfdi_endpoint peers[256]; |
| 250 | |
| 251 | /* Members below here extend version 1 of this structure */ |
| 252 | u32 timer_quantum_ns; |
| 253 | }; |
| 254 | |
| 255 | #endif |