Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1 | /**************************************************************************** |
Ben Hutchings | f7a6d2c | 2013-08-29 23:32:48 +0100 | [diff] [blame] | 2 | * Driver for Solarflare network controllers and boards |
| 3 | * Copyright 2010-2012 Solarflare Communications Inc. |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 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 | #include <linux/pci.h> |
| 10 | #include <linux/module.h> |
| 11 | #include "net_driver.h" |
| 12 | #include "efx.h" |
| 13 | #include "nic.h" |
| 14 | #include "io.h" |
| 15 | #include "mcdi.h" |
| 16 | #include "filter.h" |
| 17 | #include "mcdi_pcol.h" |
Ben Hutchings | 8b8a95a | 2012-09-18 01:57:07 +0100 | [diff] [blame] | 18 | #include "farch_regs.h" |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 19 | #include "vfdi.h" |
| 20 | |
| 21 | /* Number of longs required to track all the VIs in a VF */ |
| 22 | #define VI_MASK_LENGTH BITS_TO_LONGS(1 << EFX_VI_SCALE_MAX) |
| 23 | |
Ben Hutchings | 4507837 | 2012-09-19 02:53:34 +0100 | [diff] [blame] | 24 | /* Maximum number of RX queues supported */ |
| 25 | #define VF_MAX_RX_QUEUES 63 |
| 26 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 27 | /** |
| 28 | * enum efx_vf_tx_filter_mode - TX MAC filtering behaviour |
| 29 | * @VF_TX_FILTER_OFF: Disabled |
| 30 | * @VF_TX_FILTER_AUTO: Enabled if MAC address assigned to VF and only |
| 31 | * 2 TX queues allowed per VF. |
| 32 | * @VF_TX_FILTER_ON: Enabled |
| 33 | */ |
| 34 | enum efx_vf_tx_filter_mode { |
| 35 | VF_TX_FILTER_OFF, |
| 36 | VF_TX_FILTER_AUTO, |
| 37 | VF_TX_FILTER_ON, |
| 38 | }; |
| 39 | |
| 40 | /** |
| 41 | * struct efx_vf - Back-end resource and protocol state for a PCI VF |
| 42 | * @efx: The Efx NIC owning this VF |
| 43 | * @pci_rid: The PCI requester ID for this VF |
| 44 | * @pci_name: The PCI name (formatted address) of this VF |
| 45 | * @index: Index of VF within its port and PF. |
| 46 | * @req: VFDI incoming request work item. Incoming USR_EV events are received |
| 47 | * by the NAPI handler, but must be handled by executing MCDI requests |
| 48 | * inside a work item. |
| 49 | * @req_addr: VFDI incoming request DMA address (in VF's PCI address space). |
| 50 | * @req_type: Expected next incoming (from VF) %VFDI_EV_TYPE member. |
| 51 | * @req_seqno: Expected next incoming (from VF) %VFDI_EV_SEQ member. |
| 52 | * @msg_seqno: Next %VFDI_EV_SEQ member to reply to VF. Protected by |
| 53 | * @status_lock |
| 54 | * @busy: VFDI request queued to be processed or being processed. Receiving |
| 55 | * a VFDI request when @busy is set is an error condition. |
| 56 | * @buf: Incoming VFDI requests are DMA from the VF into this buffer. |
| 57 | * @buftbl_base: Buffer table entries for this VF start at this index. |
| 58 | * @rx_filtering: Receive filtering has been requested by the VF driver. |
| 59 | * @rx_filter_flags: The flags sent in the %VFDI_OP_INSERT_FILTER request. |
| 60 | * @rx_filter_qid: VF relative qid for RX filter requested by VF. |
| 61 | * @rx_filter_id: Receive MAC filter ID. Only one filter per VF is supported. |
| 62 | * @tx_filter_mode: Transmit MAC filtering mode. |
| 63 | * @tx_filter_id: Transmit MAC filter ID. |
| 64 | * @addr: The MAC address and outer vlan tag of the VF. |
| 65 | * @status_addr: VF DMA address of page for &struct vfdi_status updates. |
| 66 | * @status_lock: Mutex protecting @msg_seqno, @status_addr, @addr, |
| 67 | * @peer_page_addrs and @peer_page_count from simultaneous |
| 68 | * updates by the VM and consumption by |
| 69 | * efx_sriov_update_vf_addr() |
| 70 | * @peer_page_addrs: Pointer to an array of guest pages for local addresses. |
| 71 | * @peer_page_count: Number of entries in @peer_page_count. |
| 72 | * @evq0_addrs: Array of guest pages backing evq0. |
| 73 | * @evq0_count: Number of entries in @evq0_addrs. |
| 74 | * @flush_waitq: wait queue used by %VFDI_OP_FINI_ALL_QUEUES handler |
| 75 | * to wait for flush completions. |
| 76 | * @txq_lock: Mutex for TX queue allocation. |
| 77 | * @txq_mask: Mask of initialized transmit queues. |
| 78 | * @txq_count: Number of initialized transmit queues. |
| 79 | * @rxq_mask: Mask of initialized receive queues. |
| 80 | * @rxq_count: Number of initialized receive queues. |
| 81 | * @rxq_retry_mask: Mask or receive queues that need to be flushed again |
| 82 | * due to flush failure. |
| 83 | * @rxq_retry_count: Number of receive queues in @rxq_retry_mask. |
| 84 | * @reset_work: Work item to schedule a VF reset. |
| 85 | */ |
| 86 | struct efx_vf { |
| 87 | struct efx_nic *efx; |
| 88 | unsigned int pci_rid; |
| 89 | char pci_name[13]; /* dddd:bb:dd.f */ |
| 90 | unsigned int index; |
| 91 | struct work_struct req; |
| 92 | u64 req_addr; |
| 93 | int req_type; |
| 94 | unsigned req_seqno; |
| 95 | unsigned msg_seqno; |
| 96 | bool busy; |
| 97 | struct efx_buffer buf; |
| 98 | unsigned buftbl_base; |
| 99 | bool rx_filtering; |
| 100 | enum efx_filter_flags rx_filter_flags; |
| 101 | unsigned rx_filter_qid; |
| 102 | int rx_filter_id; |
| 103 | enum efx_vf_tx_filter_mode tx_filter_mode; |
| 104 | int tx_filter_id; |
| 105 | struct vfdi_endpoint addr; |
| 106 | u64 status_addr; |
| 107 | struct mutex status_lock; |
| 108 | u64 *peer_page_addrs; |
| 109 | unsigned peer_page_count; |
| 110 | u64 evq0_addrs[EFX_MAX_VF_EVQ_SIZE * sizeof(efx_qword_t) / |
| 111 | EFX_BUF_SIZE]; |
| 112 | unsigned evq0_count; |
| 113 | wait_queue_head_t flush_waitq; |
| 114 | struct mutex txq_lock; |
| 115 | unsigned long txq_mask[VI_MASK_LENGTH]; |
| 116 | unsigned txq_count; |
| 117 | unsigned long rxq_mask[VI_MASK_LENGTH]; |
| 118 | unsigned rxq_count; |
| 119 | unsigned long rxq_retry_mask[VI_MASK_LENGTH]; |
| 120 | atomic_t rxq_retry_count; |
| 121 | struct work_struct reset_work; |
| 122 | }; |
| 123 | |
| 124 | struct efx_memcpy_req { |
| 125 | unsigned int from_rid; |
| 126 | void *from_buf; |
| 127 | u64 from_addr; |
| 128 | unsigned int to_rid; |
| 129 | u64 to_addr; |
| 130 | unsigned length; |
| 131 | }; |
| 132 | |
| 133 | /** |
| 134 | * struct efx_local_addr - A MAC address on the vswitch without a VF. |
| 135 | * |
| 136 | * Siena does not have a switch, so VFs can't transmit data to each |
| 137 | * other. Instead the VFs must be made aware of the local addresses |
| 138 | * on the vswitch, so that they can arrange for an alternative |
| 139 | * software datapath to be used. |
| 140 | * |
| 141 | * @link: List head for insertion into efx->local_addr_list. |
| 142 | * @addr: Ethernet address |
| 143 | */ |
| 144 | struct efx_local_addr { |
| 145 | struct list_head link; |
| 146 | u8 addr[ETH_ALEN]; |
| 147 | }; |
| 148 | |
| 149 | /** |
| 150 | * struct efx_endpoint_page - Page of vfdi_endpoint structures |
| 151 | * |
| 152 | * @link: List head for insertion into efx->local_page_list. |
| 153 | * @ptr: Pointer to page. |
| 154 | * @addr: DMA address of page. |
| 155 | */ |
| 156 | struct efx_endpoint_page { |
| 157 | struct list_head link; |
| 158 | void *ptr; |
| 159 | dma_addr_t addr; |
| 160 | }; |
| 161 | |
| 162 | /* Buffer table entries are reserved txq0,rxq0,evq0,txq1,rxq1,evq1 */ |
| 163 | #define EFX_BUFTBL_TXQ_BASE(_vf, _qid) \ |
| 164 | ((_vf)->buftbl_base + EFX_VF_BUFTBL_PER_VI * (_qid)) |
| 165 | #define EFX_BUFTBL_RXQ_BASE(_vf, _qid) \ |
| 166 | (EFX_BUFTBL_TXQ_BASE(_vf, _qid) + \ |
| 167 | (EFX_MAX_DMAQ_SIZE * sizeof(efx_qword_t) / EFX_BUF_SIZE)) |
| 168 | #define EFX_BUFTBL_EVQ_BASE(_vf, _qid) \ |
| 169 | (EFX_BUFTBL_TXQ_BASE(_vf, _qid) + \ |
| 170 | (2 * EFX_MAX_DMAQ_SIZE * sizeof(efx_qword_t) / EFX_BUF_SIZE)) |
| 171 | |
| 172 | #define EFX_FIELD_MASK(_field) \ |
| 173 | ((1 << _field ## _WIDTH) - 1) |
| 174 | |
| 175 | /* VFs can only use this many transmit channels */ |
| 176 | static unsigned int vf_max_tx_channels = 2; |
| 177 | module_param(vf_max_tx_channels, uint, 0444); |
| 178 | MODULE_PARM_DESC(vf_max_tx_channels, |
| 179 | "Limit the number of TX channels VFs can use"); |
| 180 | |
| 181 | static int max_vfs = -1; |
| 182 | module_param(max_vfs, int, 0444); |
| 183 | MODULE_PARM_DESC(max_vfs, |
| 184 | "Reduce the number of VFs initialized by the driver"); |
| 185 | |
| 186 | /* Workqueue used by VFDI communication. We can't use the global |
| 187 | * workqueue because it may be running the VF driver's probe() |
| 188 | * routine, which will be blocked there waiting for a VFDI response. |
| 189 | */ |
| 190 | static struct workqueue_struct *vfdi_workqueue; |
| 191 | |
| 192 | static unsigned abs_index(struct efx_vf *vf, unsigned index) |
| 193 | { |
| 194 | return EFX_VI_BASE + vf->index * efx_vf_size(vf->efx) + index; |
| 195 | } |
| 196 | |
| 197 | static int efx_sriov_cmd(struct efx_nic *efx, bool enable, |
| 198 | unsigned *vi_scale_out, unsigned *vf_total_out) |
| 199 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 200 | MCDI_DECLARE_BUF(inbuf, MC_CMD_SRIOV_IN_LEN); |
| 201 | MCDI_DECLARE_BUF(outbuf, MC_CMD_SRIOV_OUT_LEN); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 202 | unsigned vi_scale, vf_total; |
| 203 | size_t outlen; |
| 204 | int rc; |
| 205 | |
| 206 | MCDI_SET_DWORD(inbuf, SRIOV_IN_ENABLE, enable ? 1 : 0); |
| 207 | MCDI_SET_DWORD(inbuf, SRIOV_IN_VI_BASE, EFX_VI_BASE); |
| 208 | MCDI_SET_DWORD(inbuf, SRIOV_IN_VF_COUNT, efx->vf_count); |
| 209 | |
| 210 | rc = efx_mcdi_rpc(efx, MC_CMD_SRIOV, inbuf, MC_CMD_SRIOV_IN_LEN, |
| 211 | outbuf, MC_CMD_SRIOV_OUT_LEN, &outlen); |
| 212 | if (rc) |
| 213 | return rc; |
| 214 | if (outlen < MC_CMD_SRIOV_OUT_LEN) |
| 215 | return -EIO; |
| 216 | |
| 217 | vf_total = MCDI_DWORD(outbuf, SRIOV_OUT_VF_TOTAL); |
| 218 | vi_scale = MCDI_DWORD(outbuf, SRIOV_OUT_VI_SCALE); |
| 219 | if (vi_scale > EFX_VI_SCALE_MAX) |
| 220 | return -EOPNOTSUPP; |
| 221 | |
| 222 | if (vi_scale_out) |
| 223 | *vi_scale_out = vi_scale; |
| 224 | if (vf_total_out) |
| 225 | *vf_total_out = vf_total; |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | static void efx_sriov_usrev(struct efx_nic *efx, bool enabled) |
| 231 | { |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 232 | struct siena_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 233 | efx_oword_t reg; |
| 234 | |
| 235 | EFX_POPULATE_OWORD_2(reg, |
| 236 | FRF_CZ_USREV_DIS, enabled ? 0 : 1, |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 237 | FRF_CZ_DFLT_EVQ, nic_data->vfdi_channel->channel); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 238 | efx_writeo(efx, ®, FR_CZ_USR_EV_CFG); |
| 239 | } |
| 240 | |
| 241 | static int efx_sriov_memcpy(struct efx_nic *efx, struct efx_memcpy_req *req, |
| 242 | unsigned int count) |
| 243 | { |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 244 | MCDI_DECLARE_BUF(inbuf, MCDI_CTL_SDU_LEN_MAX_V1); |
| 245 | MCDI_DECLARE_STRUCT_PTR(record); |
| 246 | unsigned int index, used; |
Ben Hutchings | 338f74d | 2012-10-10 23:20:17 +0100 | [diff] [blame] | 247 | u64 from_addr; |
| 248 | u32 from_rid; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 249 | int rc; |
| 250 | |
| 251 | mb(); /* Finish writing source/reading dest before DMA starts */ |
| 252 | |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 253 | if (WARN_ON(count > MC_CMD_MEMCPY_IN_RECORD_MAXNUM)) |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 254 | return -ENOBUFS; |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 255 | used = MC_CMD_MEMCPY_IN_LEN(count); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 256 | |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 257 | for (index = 0; index < count; index++) { |
| 258 | record = MCDI_ARRAY_STRUCT_PTR(inbuf, MEMCPY_IN_RECORD, index); |
| 259 | MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_NUM_RECORDS, |
| 260 | count); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 261 | MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_TO_RID, |
| 262 | req->to_rid); |
Ben Hutchings | 338f74d | 2012-10-10 23:20:17 +0100 | [diff] [blame] | 263 | MCDI_SET_QWORD(record, MEMCPY_RECORD_TYPEDEF_TO_ADDR, |
| 264 | req->to_addr); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 265 | if (req->from_buf == NULL) { |
| 266 | from_rid = req->from_rid; |
Ben Hutchings | 338f74d | 2012-10-10 23:20:17 +0100 | [diff] [blame] | 267 | from_addr = req->from_addr; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 268 | } else { |
Ben Hutchings | d0c2ee9 | 2013-08-20 15:47:12 +0100 | [diff] [blame] | 269 | if (WARN_ON(used + req->length > |
| 270 | MCDI_CTL_SDU_LEN_MAX_V1)) { |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 271 | rc = -ENOBUFS; |
| 272 | goto out; |
| 273 | } |
| 274 | |
| 275 | from_rid = MC_CMD_MEMCPY_RECORD_TYPEDEF_RID_INLINE; |
Ben Hutchings | 338f74d | 2012-10-10 23:20:17 +0100 | [diff] [blame] | 276 | from_addr = used; |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 277 | memcpy(_MCDI_PTR(inbuf, used), req->from_buf, |
| 278 | req->length); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 279 | used += req->length; |
| 280 | } |
| 281 | |
| 282 | MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_FROM_RID, from_rid); |
Ben Hutchings | 338f74d | 2012-10-10 23:20:17 +0100 | [diff] [blame] | 283 | MCDI_SET_QWORD(record, MEMCPY_RECORD_TYPEDEF_FROM_ADDR, |
| 284 | from_addr); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 285 | MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_LENGTH, |
| 286 | req->length); |
| 287 | |
| 288 | ++req; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | rc = efx_mcdi_rpc(efx, MC_CMD_MEMCPY, inbuf, used, NULL, 0, NULL); |
| 292 | out: |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 293 | mb(); /* Don't write source/read dest before DMA is complete */ |
| 294 | |
| 295 | return rc; |
| 296 | } |
| 297 | |
| 298 | /* The TX filter is entirely controlled by this driver, and is modified |
| 299 | * underneath the feet of the VF |
| 300 | */ |
| 301 | static void efx_sriov_reset_tx_filter(struct efx_vf *vf) |
| 302 | { |
| 303 | struct efx_nic *efx = vf->efx; |
| 304 | struct efx_filter_spec filter; |
| 305 | u16 vlan; |
| 306 | int rc; |
| 307 | |
| 308 | if (vf->tx_filter_id != -1) { |
| 309 | efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED, |
| 310 | vf->tx_filter_id); |
| 311 | netif_dbg(efx, hw, efx->net_dev, "Removed vf %s tx filter %d\n", |
| 312 | vf->pci_name, vf->tx_filter_id); |
| 313 | vf->tx_filter_id = -1; |
| 314 | } |
| 315 | |
| 316 | if (is_zero_ether_addr(vf->addr.mac_addr)) |
| 317 | return; |
| 318 | |
| 319 | /* Turn on TX filtering automatically if not explicitly |
| 320 | * enabled or disabled. |
| 321 | */ |
| 322 | if (vf->tx_filter_mode == VF_TX_FILTER_AUTO && vf_max_tx_channels <= 2) |
| 323 | vf->tx_filter_mode = VF_TX_FILTER_ON; |
| 324 | |
| 325 | vlan = ntohs(vf->addr.tci) & VLAN_VID_MASK; |
| 326 | efx_filter_init_tx(&filter, abs_index(vf, 0)); |
| 327 | rc = efx_filter_set_eth_local(&filter, |
| 328 | vlan ? vlan : EFX_FILTER_VID_UNSPEC, |
| 329 | vf->addr.mac_addr); |
| 330 | BUG_ON(rc); |
| 331 | |
| 332 | rc = efx_filter_insert_filter(efx, &filter, true); |
| 333 | if (rc < 0) { |
| 334 | netif_warn(efx, hw, efx->net_dev, |
| 335 | "Unable to migrate tx filter for vf %s\n", |
| 336 | vf->pci_name); |
| 337 | } else { |
| 338 | netif_dbg(efx, hw, efx->net_dev, "Inserted vf %s tx filter %d\n", |
| 339 | vf->pci_name, rc); |
| 340 | vf->tx_filter_id = rc; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /* The RX filter is managed here on behalf of the VF driver */ |
| 345 | static void efx_sriov_reset_rx_filter(struct efx_vf *vf) |
| 346 | { |
| 347 | struct efx_nic *efx = vf->efx; |
| 348 | struct efx_filter_spec filter; |
| 349 | u16 vlan; |
| 350 | int rc; |
| 351 | |
| 352 | if (vf->rx_filter_id != -1) { |
| 353 | efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED, |
| 354 | vf->rx_filter_id); |
| 355 | netif_dbg(efx, hw, efx->net_dev, "Removed vf %s rx filter %d\n", |
| 356 | vf->pci_name, vf->rx_filter_id); |
| 357 | vf->rx_filter_id = -1; |
| 358 | } |
| 359 | |
| 360 | if (!vf->rx_filtering || is_zero_ether_addr(vf->addr.mac_addr)) |
| 361 | return; |
| 362 | |
| 363 | vlan = ntohs(vf->addr.tci) & VLAN_VID_MASK; |
| 364 | efx_filter_init_rx(&filter, EFX_FILTER_PRI_REQUIRED, |
| 365 | vf->rx_filter_flags, |
| 366 | abs_index(vf, vf->rx_filter_qid)); |
| 367 | rc = efx_filter_set_eth_local(&filter, |
| 368 | vlan ? vlan : EFX_FILTER_VID_UNSPEC, |
| 369 | vf->addr.mac_addr); |
| 370 | BUG_ON(rc); |
| 371 | |
| 372 | rc = efx_filter_insert_filter(efx, &filter, true); |
| 373 | if (rc < 0) { |
| 374 | netif_warn(efx, hw, efx->net_dev, |
| 375 | "Unable to insert rx filter for vf %s\n", |
| 376 | vf->pci_name); |
| 377 | } else { |
| 378 | netif_dbg(efx, hw, efx->net_dev, "Inserted vf %s rx filter %d\n", |
| 379 | vf->pci_name, rc); |
| 380 | vf->rx_filter_id = rc; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | static void __efx_sriov_update_vf_addr(struct efx_vf *vf) |
| 385 | { |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 386 | struct efx_nic *efx = vf->efx; |
| 387 | struct siena_nic_data *nic_data = efx->nic_data; |
| 388 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 389 | efx_sriov_reset_tx_filter(vf); |
| 390 | efx_sriov_reset_rx_filter(vf); |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 391 | queue_work(vfdi_workqueue, &nic_data->peer_work); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /* Push the peer list to this VF. The caller must hold status_lock to interlock |
| 395 | * with VFDI requests, and they must be serialised against manipulation of |
| 396 | * local_page_list, either by acquiring local_lock or by running from |
| 397 | * efx_sriov_peer_work() |
| 398 | */ |
| 399 | static void __efx_sriov_push_vf_status(struct efx_vf *vf) |
| 400 | { |
| 401 | struct efx_nic *efx = vf->efx; |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 402 | struct siena_nic_data *nic_data = efx->nic_data; |
| 403 | struct vfdi_status *status = nic_data->vfdi_status.addr; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 404 | struct efx_memcpy_req copy[4]; |
| 405 | struct efx_endpoint_page *epp; |
| 406 | unsigned int pos, count; |
| 407 | unsigned data_offset; |
| 408 | efx_qword_t event; |
| 409 | |
| 410 | WARN_ON(!mutex_is_locked(&vf->status_lock)); |
| 411 | WARN_ON(!vf->status_addr); |
| 412 | |
| 413 | status->local = vf->addr; |
| 414 | status->generation_end = ++status->generation_start; |
| 415 | |
| 416 | memset(copy, '\0', sizeof(copy)); |
| 417 | /* Write generation_start */ |
| 418 | copy[0].from_buf = &status->generation_start; |
| 419 | copy[0].to_rid = vf->pci_rid; |
| 420 | copy[0].to_addr = vf->status_addr + offsetof(struct vfdi_status, |
| 421 | generation_start); |
| 422 | copy[0].length = sizeof(status->generation_start); |
| 423 | /* DMA the rest of the structure (excluding the generations). This |
| 424 | * assumes that the non-generation portion of vfdi_status is in |
| 425 | * one chunk starting at the version member. |
| 426 | */ |
| 427 | data_offset = offsetof(struct vfdi_status, version); |
| 428 | copy[1].from_rid = efx->pci_dev->devfn; |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 429 | copy[1].from_addr = nic_data->vfdi_status.dma_addr + data_offset; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 430 | copy[1].to_rid = vf->pci_rid; |
| 431 | copy[1].to_addr = vf->status_addr + data_offset; |
| 432 | copy[1].length = status->length - data_offset; |
| 433 | |
| 434 | /* Copy the peer pages */ |
| 435 | pos = 2; |
| 436 | count = 0; |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 437 | list_for_each_entry(epp, &nic_data->local_page_list, link) { |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 438 | if (count == vf->peer_page_count) { |
| 439 | /* The VF driver will know they need to provide more |
| 440 | * pages because peer_addr_count is too large. |
| 441 | */ |
| 442 | break; |
| 443 | } |
| 444 | copy[pos].from_buf = NULL; |
| 445 | copy[pos].from_rid = efx->pci_dev->devfn; |
| 446 | copy[pos].from_addr = epp->addr; |
| 447 | copy[pos].to_rid = vf->pci_rid; |
| 448 | copy[pos].to_addr = vf->peer_page_addrs[count]; |
| 449 | copy[pos].length = EFX_PAGE_SIZE; |
| 450 | |
| 451 | if (++pos == ARRAY_SIZE(copy)) { |
| 452 | efx_sriov_memcpy(efx, copy, ARRAY_SIZE(copy)); |
| 453 | pos = 0; |
| 454 | } |
| 455 | ++count; |
| 456 | } |
| 457 | |
| 458 | /* Write generation_end */ |
| 459 | copy[pos].from_buf = &status->generation_end; |
| 460 | copy[pos].to_rid = vf->pci_rid; |
| 461 | copy[pos].to_addr = vf->status_addr + offsetof(struct vfdi_status, |
| 462 | generation_end); |
| 463 | copy[pos].length = sizeof(status->generation_end); |
| 464 | efx_sriov_memcpy(efx, copy, pos + 1); |
| 465 | |
| 466 | /* Notify the guest */ |
| 467 | EFX_POPULATE_QWORD_3(event, |
| 468 | FSF_AZ_EV_CODE, FSE_CZ_EV_CODE_USER_EV, |
| 469 | VFDI_EV_SEQ, (vf->msg_seqno & 0xff), |
| 470 | VFDI_EV_TYPE, VFDI_EV_TYPE_STATUS); |
| 471 | ++vf->msg_seqno; |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 472 | efx_farch_generate_event(efx, |
| 473 | EFX_VI_BASE + vf->index * efx_vf_size(efx), |
| 474 | &event); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | static void efx_sriov_bufs(struct efx_nic *efx, unsigned offset, |
| 478 | u64 *addr, unsigned count) |
| 479 | { |
| 480 | efx_qword_t buf; |
| 481 | unsigned pos; |
| 482 | |
| 483 | for (pos = 0; pos < count; ++pos) { |
| 484 | EFX_POPULATE_QWORD_3(buf, |
| 485 | FRF_AZ_BUF_ADR_REGION, 0, |
| 486 | FRF_AZ_BUF_ADR_FBUF, |
| 487 | addr ? addr[pos] >> 12 : 0, |
| 488 | FRF_AZ_BUF_OWNER_ID_FBUF, 0); |
| 489 | efx_sram_writeq(efx, efx->membase + FR_BZ_BUF_FULL_TBL, |
| 490 | &buf, offset + pos); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | static bool bad_vf_index(struct efx_nic *efx, unsigned index) |
| 495 | { |
| 496 | return index >= efx_vf_size(efx); |
| 497 | } |
| 498 | |
| 499 | static bool bad_buf_count(unsigned buf_count, unsigned max_entry_count) |
| 500 | { |
| 501 | unsigned max_buf_count = max_entry_count * |
| 502 | sizeof(efx_qword_t) / EFX_BUF_SIZE; |
| 503 | |
| 504 | return ((buf_count & (buf_count - 1)) || buf_count > max_buf_count); |
| 505 | } |
| 506 | |
| 507 | /* Check that VI specified by per-port index belongs to a VF. |
| 508 | * Optionally set VF index and VI index within the VF. |
| 509 | */ |
| 510 | static bool map_vi_index(struct efx_nic *efx, unsigned abs_index, |
| 511 | struct efx_vf **vf_out, unsigned *rel_index_out) |
| 512 | { |
| 513 | unsigned vf_i; |
| 514 | |
| 515 | if (abs_index < EFX_VI_BASE) |
| 516 | return true; |
Robert Stonehouse | 2c61c8a | 2012-03-02 17:20:00 +0000 | [diff] [blame] | 517 | vf_i = (abs_index - EFX_VI_BASE) / efx_vf_size(efx); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 518 | if (vf_i >= efx->vf_init_count) |
| 519 | return true; |
| 520 | |
| 521 | if (vf_out) |
| 522 | *vf_out = efx->vf + vf_i; |
| 523 | if (rel_index_out) |
| 524 | *rel_index_out = abs_index % efx_vf_size(efx); |
| 525 | return false; |
| 526 | } |
| 527 | |
| 528 | static int efx_vfdi_init_evq(struct efx_vf *vf) |
| 529 | { |
| 530 | struct efx_nic *efx = vf->efx; |
| 531 | struct vfdi_req *req = vf->buf.addr; |
| 532 | unsigned vf_evq = req->u.init_evq.index; |
| 533 | unsigned buf_count = req->u.init_evq.buf_count; |
| 534 | unsigned abs_evq = abs_index(vf, vf_evq); |
| 535 | unsigned buftbl = EFX_BUFTBL_EVQ_BASE(vf, vf_evq); |
| 536 | efx_oword_t reg; |
| 537 | |
| 538 | if (bad_vf_index(efx, vf_evq) || |
| 539 | bad_buf_count(buf_count, EFX_MAX_VF_EVQ_SIZE)) { |
| 540 | if (net_ratelimit()) |
| 541 | netif_err(efx, hw, efx->net_dev, |
| 542 | "ERROR: Invalid INIT_EVQ from %s: evq %d bufs %d\n", |
| 543 | vf->pci_name, vf_evq, buf_count); |
| 544 | return VFDI_RC_EINVAL; |
| 545 | } |
| 546 | |
| 547 | efx_sriov_bufs(efx, buftbl, req->u.init_evq.addr, buf_count); |
| 548 | |
| 549 | EFX_POPULATE_OWORD_3(reg, |
| 550 | FRF_CZ_TIMER_Q_EN, 1, |
| 551 | FRF_CZ_HOST_NOTIFY_MODE, 0, |
| 552 | FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS); |
| 553 | efx_writeo_table(efx, ®, FR_BZ_TIMER_TBL, abs_evq); |
| 554 | EFX_POPULATE_OWORD_3(reg, |
| 555 | FRF_AZ_EVQ_EN, 1, |
| 556 | FRF_AZ_EVQ_SIZE, __ffs(buf_count), |
| 557 | FRF_AZ_EVQ_BUF_BASE_ID, buftbl); |
| 558 | efx_writeo_table(efx, ®, FR_BZ_EVQ_PTR_TBL, abs_evq); |
| 559 | |
| 560 | if (vf_evq == 0) { |
| 561 | memcpy(vf->evq0_addrs, req->u.init_evq.addr, |
| 562 | buf_count * sizeof(u64)); |
| 563 | vf->evq0_count = buf_count; |
| 564 | } |
| 565 | |
| 566 | return VFDI_RC_SUCCESS; |
| 567 | } |
| 568 | |
| 569 | static int efx_vfdi_init_rxq(struct efx_vf *vf) |
| 570 | { |
| 571 | struct efx_nic *efx = vf->efx; |
| 572 | struct vfdi_req *req = vf->buf.addr; |
| 573 | unsigned vf_rxq = req->u.init_rxq.index; |
| 574 | unsigned vf_evq = req->u.init_rxq.evq; |
| 575 | unsigned buf_count = req->u.init_rxq.buf_count; |
| 576 | unsigned buftbl = EFX_BUFTBL_RXQ_BASE(vf, vf_rxq); |
| 577 | unsigned label; |
| 578 | efx_oword_t reg; |
| 579 | |
| 580 | if (bad_vf_index(efx, vf_evq) || bad_vf_index(efx, vf_rxq) || |
Ben Hutchings | 4507837 | 2012-09-19 02:53:34 +0100 | [diff] [blame] | 581 | vf_rxq >= VF_MAX_RX_QUEUES || |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 582 | bad_buf_count(buf_count, EFX_MAX_DMAQ_SIZE)) { |
| 583 | if (net_ratelimit()) |
| 584 | netif_err(efx, hw, efx->net_dev, |
| 585 | "ERROR: Invalid INIT_RXQ from %s: rxq %d evq %d " |
| 586 | "buf_count %d\n", vf->pci_name, vf_rxq, |
| 587 | vf_evq, buf_count); |
| 588 | return VFDI_RC_EINVAL; |
| 589 | } |
| 590 | if (__test_and_set_bit(req->u.init_rxq.index, vf->rxq_mask)) |
| 591 | ++vf->rxq_count; |
| 592 | efx_sriov_bufs(efx, buftbl, req->u.init_rxq.addr, buf_count); |
| 593 | |
| 594 | label = req->u.init_rxq.label & EFX_FIELD_MASK(FRF_AZ_RX_DESCQ_LABEL); |
| 595 | EFX_POPULATE_OWORD_6(reg, |
| 596 | FRF_AZ_RX_DESCQ_BUF_BASE_ID, buftbl, |
| 597 | FRF_AZ_RX_DESCQ_EVQ_ID, abs_index(vf, vf_evq), |
| 598 | FRF_AZ_RX_DESCQ_LABEL, label, |
| 599 | FRF_AZ_RX_DESCQ_SIZE, __ffs(buf_count), |
| 600 | FRF_AZ_RX_DESCQ_JUMBO, |
| 601 | !!(req->u.init_rxq.flags & |
| 602 | VFDI_RXQ_FLAG_SCATTER_EN), |
| 603 | FRF_AZ_RX_DESCQ_EN, 1); |
| 604 | efx_writeo_table(efx, ®, FR_BZ_RX_DESC_PTR_TBL, |
| 605 | abs_index(vf, vf_rxq)); |
| 606 | |
| 607 | return VFDI_RC_SUCCESS; |
| 608 | } |
| 609 | |
| 610 | static int efx_vfdi_init_txq(struct efx_vf *vf) |
| 611 | { |
| 612 | struct efx_nic *efx = vf->efx; |
| 613 | struct vfdi_req *req = vf->buf.addr; |
| 614 | unsigned vf_txq = req->u.init_txq.index; |
| 615 | unsigned vf_evq = req->u.init_txq.evq; |
| 616 | unsigned buf_count = req->u.init_txq.buf_count; |
| 617 | unsigned buftbl = EFX_BUFTBL_TXQ_BASE(vf, vf_txq); |
| 618 | unsigned label, eth_filt_en; |
| 619 | efx_oword_t reg; |
| 620 | |
| 621 | if (bad_vf_index(efx, vf_evq) || bad_vf_index(efx, vf_txq) || |
| 622 | vf_txq >= vf_max_tx_channels || |
| 623 | bad_buf_count(buf_count, EFX_MAX_DMAQ_SIZE)) { |
| 624 | if (net_ratelimit()) |
| 625 | netif_err(efx, hw, efx->net_dev, |
| 626 | "ERROR: Invalid INIT_TXQ from %s: txq %d evq %d " |
| 627 | "buf_count %d\n", vf->pci_name, vf_txq, |
| 628 | vf_evq, buf_count); |
| 629 | return VFDI_RC_EINVAL; |
| 630 | } |
| 631 | |
| 632 | mutex_lock(&vf->txq_lock); |
| 633 | if (__test_and_set_bit(req->u.init_txq.index, vf->txq_mask)) |
| 634 | ++vf->txq_count; |
| 635 | mutex_unlock(&vf->txq_lock); |
| 636 | efx_sriov_bufs(efx, buftbl, req->u.init_txq.addr, buf_count); |
| 637 | |
| 638 | eth_filt_en = vf->tx_filter_mode == VF_TX_FILTER_ON; |
| 639 | |
| 640 | label = req->u.init_txq.label & EFX_FIELD_MASK(FRF_AZ_TX_DESCQ_LABEL); |
| 641 | EFX_POPULATE_OWORD_8(reg, |
| 642 | FRF_CZ_TX_DPT_Q_MASK_WIDTH, min(efx->vi_scale, 1U), |
| 643 | FRF_CZ_TX_DPT_ETH_FILT_EN, eth_filt_en, |
| 644 | FRF_AZ_TX_DESCQ_EN, 1, |
| 645 | FRF_AZ_TX_DESCQ_BUF_BASE_ID, buftbl, |
| 646 | FRF_AZ_TX_DESCQ_EVQ_ID, abs_index(vf, vf_evq), |
| 647 | FRF_AZ_TX_DESCQ_LABEL, label, |
| 648 | FRF_AZ_TX_DESCQ_SIZE, __ffs(buf_count), |
| 649 | FRF_BZ_TX_NON_IP_DROP_DIS, 1); |
| 650 | efx_writeo_table(efx, ®, FR_BZ_TX_DESC_PTR_TBL, |
| 651 | abs_index(vf, vf_txq)); |
| 652 | |
| 653 | return VFDI_RC_SUCCESS; |
| 654 | } |
| 655 | |
| 656 | /* Returns true when efx_vfdi_fini_all_queues should wake */ |
| 657 | static bool efx_vfdi_flush_wake(struct efx_vf *vf) |
| 658 | { |
| 659 | /* Ensure that all updates are visible to efx_vfdi_fini_all_queues() */ |
| 660 | smp_mb(); |
| 661 | |
| 662 | return (!vf->txq_count && !vf->rxq_count) || |
| 663 | atomic_read(&vf->rxq_retry_count); |
| 664 | } |
| 665 | |
| 666 | static void efx_vfdi_flush_clear(struct efx_vf *vf) |
| 667 | { |
| 668 | memset(vf->txq_mask, 0, sizeof(vf->txq_mask)); |
| 669 | vf->txq_count = 0; |
| 670 | memset(vf->rxq_mask, 0, sizeof(vf->rxq_mask)); |
| 671 | vf->rxq_count = 0; |
| 672 | memset(vf->rxq_retry_mask, 0, sizeof(vf->rxq_retry_mask)); |
| 673 | atomic_set(&vf->rxq_retry_count, 0); |
| 674 | } |
| 675 | |
| 676 | static int efx_vfdi_fini_all_queues(struct efx_vf *vf) |
| 677 | { |
| 678 | struct efx_nic *efx = vf->efx; |
| 679 | efx_oword_t reg; |
| 680 | unsigned count = efx_vf_size(efx); |
| 681 | unsigned vf_offset = EFX_VI_BASE + vf->index * efx_vf_size(efx); |
| 682 | unsigned timeout = HZ; |
| 683 | unsigned index, rxqs_count; |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 684 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FLUSH_RX_QUEUES_IN_LENMAX); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 685 | int rc; |
| 686 | |
Ben Hutchings | 4507837 | 2012-09-19 02:53:34 +0100 | [diff] [blame] | 687 | BUILD_BUG_ON(VF_MAX_RX_QUEUES > |
| 688 | MC_CMD_FLUSH_RX_QUEUES_IN_QID_OFST_MAXNUM); |
| 689 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 690 | rtnl_lock(); |
Ben Hutchings | d5e8cc6 | 2012-09-06 16:52:31 +0100 | [diff] [blame] | 691 | siena_prepare_flush(efx); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 692 | rtnl_unlock(); |
| 693 | |
| 694 | /* Flush all the initialized queues */ |
| 695 | rxqs_count = 0; |
| 696 | for (index = 0; index < count; ++index) { |
| 697 | if (test_bit(index, vf->txq_mask)) { |
| 698 | EFX_POPULATE_OWORD_2(reg, |
| 699 | FRF_AZ_TX_FLUSH_DESCQ_CMD, 1, |
| 700 | FRF_AZ_TX_FLUSH_DESCQ, |
| 701 | vf_offset + index); |
| 702 | efx_writeo(efx, ®, FR_AZ_TX_FLUSH_DESCQ); |
| 703 | } |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 704 | if (test_bit(index, vf->rxq_mask)) { |
| 705 | MCDI_SET_ARRAY_DWORD( |
| 706 | inbuf, FLUSH_RX_QUEUES_IN_QID_OFST, |
| 707 | rxqs_count, vf_offset + index); |
| 708 | rxqs_count++; |
| 709 | } |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | atomic_set(&vf->rxq_retry_count, 0); |
| 713 | while (timeout && (vf->rxq_count || vf->txq_count)) { |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 714 | rc = efx_mcdi_rpc(efx, MC_CMD_FLUSH_RX_QUEUES, inbuf, |
| 715 | MC_CMD_FLUSH_RX_QUEUES_IN_LEN(rxqs_count), |
| 716 | NULL, 0, NULL); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 717 | WARN_ON(rc < 0); |
| 718 | |
| 719 | timeout = wait_event_timeout(vf->flush_waitq, |
| 720 | efx_vfdi_flush_wake(vf), |
| 721 | timeout); |
| 722 | rxqs_count = 0; |
| 723 | for (index = 0; index < count; ++index) { |
| 724 | if (test_and_clear_bit(index, vf->rxq_retry_mask)) { |
| 725 | atomic_dec(&vf->rxq_retry_count); |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 726 | MCDI_SET_ARRAY_DWORD( |
| 727 | inbuf, FLUSH_RX_QUEUES_IN_QID_OFST, |
| 728 | rxqs_count, vf_offset + index); |
| 729 | rxqs_count++; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 730 | } |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | rtnl_lock(); |
Ben Hutchings | d5e8cc6 | 2012-09-06 16:52:31 +0100 | [diff] [blame] | 735 | siena_finish_flush(efx); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 736 | rtnl_unlock(); |
| 737 | |
| 738 | /* Irrespective of success/failure, fini the queues */ |
| 739 | EFX_ZERO_OWORD(reg); |
| 740 | for (index = 0; index < count; ++index) { |
| 741 | efx_writeo_table(efx, ®, FR_BZ_RX_DESC_PTR_TBL, |
| 742 | vf_offset + index); |
| 743 | efx_writeo_table(efx, ®, FR_BZ_TX_DESC_PTR_TBL, |
| 744 | vf_offset + index); |
| 745 | efx_writeo_table(efx, ®, FR_BZ_EVQ_PTR_TBL, |
| 746 | vf_offset + index); |
| 747 | efx_writeo_table(efx, ®, FR_BZ_TIMER_TBL, |
| 748 | vf_offset + index); |
| 749 | } |
| 750 | efx_sriov_bufs(efx, vf->buftbl_base, NULL, |
| 751 | EFX_VF_BUFTBL_PER_VI * efx_vf_size(efx)); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 752 | efx_vfdi_flush_clear(vf); |
| 753 | |
| 754 | vf->evq0_count = 0; |
| 755 | |
| 756 | return timeout ? 0 : VFDI_RC_ETIMEDOUT; |
| 757 | } |
| 758 | |
| 759 | static int efx_vfdi_insert_filter(struct efx_vf *vf) |
| 760 | { |
| 761 | struct efx_nic *efx = vf->efx; |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 762 | struct siena_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 763 | struct vfdi_req *req = vf->buf.addr; |
| 764 | unsigned vf_rxq = req->u.mac_filter.rxq; |
| 765 | unsigned flags; |
| 766 | |
| 767 | if (bad_vf_index(efx, vf_rxq) || vf->rx_filtering) { |
| 768 | if (net_ratelimit()) |
| 769 | netif_err(efx, hw, efx->net_dev, |
| 770 | "ERROR: Invalid INSERT_FILTER from %s: rxq %d " |
| 771 | "flags 0x%x\n", vf->pci_name, vf_rxq, |
| 772 | req->u.mac_filter.flags); |
| 773 | return VFDI_RC_EINVAL; |
| 774 | } |
| 775 | |
| 776 | flags = 0; |
| 777 | if (req->u.mac_filter.flags & VFDI_MAC_FILTER_FLAG_RSS) |
| 778 | flags |= EFX_FILTER_FLAG_RX_RSS; |
| 779 | if (req->u.mac_filter.flags & VFDI_MAC_FILTER_FLAG_SCATTER) |
| 780 | flags |= EFX_FILTER_FLAG_RX_SCATTER; |
| 781 | vf->rx_filter_flags = flags; |
| 782 | vf->rx_filter_qid = vf_rxq; |
| 783 | vf->rx_filtering = true; |
| 784 | |
| 785 | efx_sriov_reset_rx_filter(vf); |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 786 | queue_work(vfdi_workqueue, &nic_data->peer_work); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 787 | |
| 788 | return VFDI_RC_SUCCESS; |
| 789 | } |
| 790 | |
| 791 | static int efx_vfdi_remove_all_filters(struct efx_vf *vf) |
| 792 | { |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 793 | struct efx_nic *efx = vf->efx; |
| 794 | struct siena_nic_data *nic_data = efx->nic_data; |
| 795 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 796 | vf->rx_filtering = false; |
| 797 | efx_sriov_reset_rx_filter(vf); |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 798 | queue_work(vfdi_workqueue, &nic_data->peer_work); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 799 | |
| 800 | return VFDI_RC_SUCCESS; |
| 801 | } |
| 802 | |
| 803 | static int efx_vfdi_set_status_page(struct efx_vf *vf) |
| 804 | { |
| 805 | struct efx_nic *efx = vf->efx; |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 806 | struct siena_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 807 | struct vfdi_req *req = vf->buf.addr; |
Ben Hutchings | 01cb543 | 2012-02-21 02:57:33 +0000 | [diff] [blame] | 808 | u64 page_count = req->u.set_status_page.peer_page_count; |
| 809 | u64 max_page_count = |
| 810 | (EFX_PAGE_SIZE - |
| 811 | offsetof(struct vfdi_req, u.set_status_page.peer_page_addr[0])) |
| 812 | / sizeof(req->u.set_status_page.peer_page_addr[0]); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 813 | |
Ben Hutchings | 01cb543 | 2012-02-21 02:57:33 +0000 | [diff] [blame] | 814 | if (!req->u.set_status_page.dma_addr || page_count > max_page_count) { |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 815 | if (net_ratelimit()) |
| 816 | netif_err(efx, hw, efx->net_dev, |
| 817 | "ERROR: Invalid SET_STATUS_PAGE from %s\n", |
| 818 | vf->pci_name); |
| 819 | return VFDI_RC_EINVAL; |
| 820 | } |
| 821 | |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 822 | mutex_lock(&nic_data->local_lock); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 823 | mutex_lock(&vf->status_lock); |
| 824 | vf->status_addr = req->u.set_status_page.dma_addr; |
| 825 | |
| 826 | kfree(vf->peer_page_addrs); |
| 827 | vf->peer_page_addrs = NULL; |
| 828 | vf->peer_page_count = 0; |
| 829 | |
| 830 | if (page_count) { |
| 831 | vf->peer_page_addrs = kcalloc(page_count, sizeof(u64), |
| 832 | GFP_KERNEL); |
| 833 | if (vf->peer_page_addrs) { |
| 834 | memcpy(vf->peer_page_addrs, |
| 835 | req->u.set_status_page.peer_page_addr, |
| 836 | page_count * sizeof(u64)); |
| 837 | vf->peer_page_count = page_count; |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | __efx_sriov_push_vf_status(vf); |
| 842 | mutex_unlock(&vf->status_lock); |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 843 | mutex_unlock(&nic_data->local_lock); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 844 | |
| 845 | return VFDI_RC_SUCCESS; |
| 846 | } |
| 847 | |
| 848 | static int efx_vfdi_clear_status_page(struct efx_vf *vf) |
| 849 | { |
| 850 | mutex_lock(&vf->status_lock); |
| 851 | vf->status_addr = 0; |
| 852 | mutex_unlock(&vf->status_lock); |
| 853 | |
| 854 | return VFDI_RC_SUCCESS; |
| 855 | } |
| 856 | |
| 857 | typedef int (*efx_vfdi_op_t)(struct efx_vf *vf); |
| 858 | |
| 859 | static const efx_vfdi_op_t vfdi_ops[VFDI_OP_LIMIT] = { |
| 860 | [VFDI_OP_INIT_EVQ] = efx_vfdi_init_evq, |
| 861 | [VFDI_OP_INIT_TXQ] = efx_vfdi_init_txq, |
| 862 | [VFDI_OP_INIT_RXQ] = efx_vfdi_init_rxq, |
| 863 | [VFDI_OP_FINI_ALL_QUEUES] = efx_vfdi_fini_all_queues, |
| 864 | [VFDI_OP_INSERT_FILTER] = efx_vfdi_insert_filter, |
| 865 | [VFDI_OP_REMOVE_ALL_FILTERS] = efx_vfdi_remove_all_filters, |
| 866 | [VFDI_OP_SET_STATUS_PAGE] = efx_vfdi_set_status_page, |
| 867 | [VFDI_OP_CLEAR_STATUS_PAGE] = efx_vfdi_clear_status_page, |
| 868 | }; |
| 869 | |
| 870 | static void efx_sriov_vfdi(struct work_struct *work) |
| 871 | { |
| 872 | struct efx_vf *vf = container_of(work, struct efx_vf, req); |
| 873 | struct efx_nic *efx = vf->efx; |
| 874 | struct vfdi_req *req = vf->buf.addr; |
| 875 | struct efx_memcpy_req copy[2]; |
| 876 | int rc; |
| 877 | |
| 878 | /* Copy this page into the local address space */ |
| 879 | memset(copy, '\0', sizeof(copy)); |
| 880 | copy[0].from_rid = vf->pci_rid; |
| 881 | copy[0].from_addr = vf->req_addr; |
| 882 | copy[0].to_rid = efx->pci_dev->devfn; |
| 883 | copy[0].to_addr = vf->buf.dma_addr; |
| 884 | copy[0].length = EFX_PAGE_SIZE; |
| 885 | rc = efx_sriov_memcpy(efx, copy, 1); |
| 886 | if (rc) { |
| 887 | /* If we can't get the request, we can't reply to the caller */ |
| 888 | if (net_ratelimit()) |
| 889 | netif_err(efx, hw, efx->net_dev, |
| 890 | "ERROR: Unable to fetch VFDI request from %s rc %d\n", |
| 891 | vf->pci_name, -rc); |
| 892 | vf->busy = false; |
| 893 | return; |
| 894 | } |
| 895 | |
| 896 | if (req->op < VFDI_OP_LIMIT && vfdi_ops[req->op] != NULL) { |
| 897 | rc = vfdi_ops[req->op](vf); |
| 898 | if (rc == 0) { |
| 899 | netif_dbg(efx, hw, efx->net_dev, |
| 900 | "vfdi request %d from %s ok\n", |
| 901 | req->op, vf->pci_name); |
| 902 | } |
| 903 | } else { |
| 904 | netif_dbg(efx, hw, efx->net_dev, |
| 905 | "ERROR: Unrecognised request %d from VF %s addr " |
| 906 | "%llx\n", req->op, vf->pci_name, |
| 907 | (unsigned long long)vf->req_addr); |
| 908 | rc = VFDI_RC_EOPNOTSUPP; |
| 909 | } |
| 910 | |
| 911 | /* Allow subsequent VF requests */ |
| 912 | vf->busy = false; |
| 913 | smp_wmb(); |
| 914 | |
| 915 | /* Respond to the request */ |
| 916 | req->rc = rc; |
| 917 | req->op = VFDI_OP_RESPONSE; |
| 918 | |
| 919 | memset(copy, '\0', sizeof(copy)); |
| 920 | copy[0].from_buf = &req->rc; |
| 921 | copy[0].to_rid = vf->pci_rid; |
| 922 | copy[0].to_addr = vf->req_addr + offsetof(struct vfdi_req, rc); |
| 923 | copy[0].length = sizeof(req->rc); |
| 924 | copy[1].from_buf = &req->op; |
| 925 | copy[1].to_rid = vf->pci_rid; |
| 926 | copy[1].to_addr = vf->req_addr + offsetof(struct vfdi_req, op); |
| 927 | copy[1].length = sizeof(req->op); |
| 928 | |
| 929 | (void) efx_sriov_memcpy(efx, copy, ARRAY_SIZE(copy)); |
| 930 | } |
| 931 | |
| 932 | |
| 933 | |
| 934 | /* After a reset the event queues inside the guests no longer exist. Fill the |
| 935 | * event ring in guest memory with VFDI reset events, then (re-initialise) the |
| 936 | * event queue to raise an interrupt. The guest driver will then recover. |
| 937 | */ |
| 938 | static void efx_sriov_reset_vf(struct efx_vf *vf, struct efx_buffer *buffer) |
| 939 | { |
| 940 | struct efx_nic *efx = vf->efx; |
| 941 | struct efx_memcpy_req copy_req[4]; |
| 942 | efx_qword_t event; |
| 943 | unsigned int pos, count, k, buftbl, abs_evq; |
| 944 | efx_oword_t reg; |
| 945 | efx_dword_t ptr; |
| 946 | int rc; |
| 947 | |
| 948 | BUG_ON(buffer->len != EFX_PAGE_SIZE); |
| 949 | |
| 950 | if (!vf->evq0_count) |
| 951 | return; |
| 952 | BUG_ON(vf->evq0_count & (vf->evq0_count - 1)); |
| 953 | |
| 954 | mutex_lock(&vf->status_lock); |
| 955 | EFX_POPULATE_QWORD_3(event, |
| 956 | FSF_AZ_EV_CODE, FSE_CZ_EV_CODE_USER_EV, |
| 957 | VFDI_EV_SEQ, vf->msg_seqno, |
| 958 | VFDI_EV_TYPE, VFDI_EV_TYPE_RESET); |
| 959 | vf->msg_seqno++; |
| 960 | for (pos = 0; pos < EFX_PAGE_SIZE; pos += sizeof(event)) |
| 961 | memcpy(buffer->addr + pos, &event, sizeof(event)); |
| 962 | |
| 963 | for (pos = 0; pos < vf->evq0_count; pos += count) { |
| 964 | count = min_t(unsigned, vf->evq0_count - pos, |
| 965 | ARRAY_SIZE(copy_req)); |
| 966 | for (k = 0; k < count; k++) { |
| 967 | copy_req[k].from_buf = NULL; |
| 968 | copy_req[k].from_rid = efx->pci_dev->devfn; |
| 969 | copy_req[k].from_addr = buffer->dma_addr; |
| 970 | copy_req[k].to_rid = vf->pci_rid; |
| 971 | copy_req[k].to_addr = vf->evq0_addrs[pos + k]; |
| 972 | copy_req[k].length = EFX_PAGE_SIZE; |
| 973 | } |
| 974 | rc = efx_sriov_memcpy(efx, copy_req, count); |
| 975 | if (rc) { |
| 976 | if (net_ratelimit()) |
| 977 | netif_err(efx, hw, efx->net_dev, |
| 978 | "ERROR: Unable to notify %s of reset" |
| 979 | ": %d\n", vf->pci_name, -rc); |
| 980 | break; |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | /* Reinitialise, arm and trigger evq0 */ |
| 985 | abs_evq = abs_index(vf, 0); |
| 986 | buftbl = EFX_BUFTBL_EVQ_BASE(vf, 0); |
| 987 | efx_sriov_bufs(efx, buftbl, vf->evq0_addrs, vf->evq0_count); |
| 988 | |
| 989 | EFX_POPULATE_OWORD_3(reg, |
| 990 | FRF_CZ_TIMER_Q_EN, 1, |
| 991 | FRF_CZ_HOST_NOTIFY_MODE, 0, |
| 992 | FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS); |
| 993 | efx_writeo_table(efx, ®, FR_BZ_TIMER_TBL, abs_evq); |
| 994 | EFX_POPULATE_OWORD_3(reg, |
| 995 | FRF_AZ_EVQ_EN, 1, |
| 996 | FRF_AZ_EVQ_SIZE, __ffs(vf->evq0_count), |
| 997 | FRF_AZ_EVQ_BUF_BASE_ID, buftbl); |
| 998 | efx_writeo_table(efx, ®, FR_BZ_EVQ_PTR_TBL, abs_evq); |
| 999 | EFX_POPULATE_DWORD_1(ptr, FRF_AZ_EVQ_RPTR, 0); |
Ben Hutchings | 778cdaf | 2012-09-18 01:56:50 +0100 | [diff] [blame] | 1000 | efx_writed(efx, &ptr, FR_BZ_EVQ_RPTR + FR_BZ_EVQ_RPTR_STEP * abs_evq); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1001 | |
| 1002 | mutex_unlock(&vf->status_lock); |
| 1003 | } |
| 1004 | |
| 1005 | static void efx_sriov_reset_vf_work(struct work_struct *work) |
| 1006 | { |
| 1007 | struct efx_vf *vf = container_of(work, struct efx_vf, req); |
| 1008 | struct efx_nic *efx = vf->efx; |
| 1009 | struct efx_buffer buf; |
| 1010 | |
Ben Hutchings | 0d19a54 | 2012-09-18 21:59:52 +0100 | [diff] [blame] | 1011 | if (!efx_nic_alloc_buffer(efx, &buf, EFX_PAGE_SIZE, GFP_NOIO)) { |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1012 | efx_sriov_reset_vf(vf, &buf); |
| 1013 | efx_nic_free_buffer(efx, &buf); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | static void efx_sriov_handle_no_channel(struct efx_nic *efx) |
| 1018 | { |
| 1019 | netif_err(efx, drv, efx->net_dev, |
| 1020 | "ERROR: IOV requires MSI-X and 1 additional interrupt" |
| 1021 | "vector. IOV disabled\n"); |
| 1022 | efx->vf_count = 0; |
| 1023 | } |
| 1024 | |
| 1025 | static int efx_sriov_probe_channel(struct efx_channel *channel) |
| 1026 | { |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1027 | struct siena_nic_data *nic_data = channel->efx->nic_data; |
| 1028 | nic_data->vfdi_channel = channel; |
| 1029 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1030 | return 0; |
| 1031 | } |
| 1032 | |
| 1033 | static void |
| 1034 | efx_sriov_get_channel_name(struct efx_channel *channel, char *buf, size_t len) |
| 1035 | { |
| 1036 | snprintf(buf, len, "%s-iov", channel->efx->name); |
| 1037 | } |
| 1038 | |
| 1039 | static const struct efx_channel_type efx_sriov_channel_type = { |
| 1040 | .handle_no_channel = efx_sriov_handle_no_channel, |
| 1041 | .pre_probe = efx_sriov_probe_channel, |
Ben Hutchings | 726ba0e | 2012-10-02 01:43:45 +0100 | [diff] [blame] | 1042 | .post_remove = efx_channel_dummy_op_void, |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1043 | .get_name = efx_sriov_get_channel_name, |
| 1044 | /* no copy operation; channel must not be reallocated */ |
| 1045 | .keep_eventq = true, |
| 1046 | }; |
| 1047 | |
| 1048 | void efx_sriov_probe(struct efx_nic *efx) |
| 1049 | { |
| 1050 | unsigned count; |
| 1051 | |
| 1052 | if (!max_vfs) |
| 1053 | return; |
| 1054 | |
| 1055 | if (efx_sriov_cmd(efx, false, &efx->vi_scale, &count)) |
| 1056 | return; |
| 1057 | if (count > 0 && count > max_vfs) |
| 1058 | count = max_vfs; |
| 1059 | |
| 1060 | /* efx_nic_dimension_resources() will reduce vf_count as appopriate */ |
| 1061 | efx->vf_count = count; |
| 1062 | |
| 1063 | efx->extra_channel_type[EFX_EXTRA_CHANNEL_IOV] = &efx_sriov_channel_type; |
| 1064 | } |
| 1065 | |
| 1066 | /* Copy the list of individual addresses into the vfdi_status.peers |
| 1067 | * array and auxillary pages, protected by %local_lock. Drop that lock |
| 1068 | * and then broadcast the address list to every VF. |
| 1069 | */ |
| 1070 | static void efx_sriov_peer_work(struct work_struct *data) |
| 1071 | { |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1072 | struct siena_nic_data *nic_data = container_of(data, |
| 1073 | struct siena_nic_data, |
| 1074 | peer_work); |
| 1075 | struct efx_nic *efx = nic_data->efx; |
| 1076 | struct vfdi_status *vfdi_status = nic_data->vfdi_status.addr; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1077 | struct efx_vf *vf; |
| 1078 | struct efx_local_addr *local_addr; |
| 1079 | struct vfdi_endpoint *peer; |
| 1080 | struct efx_endpoint_page *epp; |
| 1081 | struct list_head pages; |
| 1082 | unsigned int peer_space; |
| 1083 | unsigned int peer_count; |
| 1084 | unsigned int pos; |
| 1085 | |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1086 | mutex_lock(&nic_data->local_lock); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1087 | |
| 1088 | /* Move the existing peer pages off %local_page_list */ |
| 1089 | INIT_LIST_HEAD(&pages); |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1090 | list_splice_tail_init(&nic_data->local_page_list, &pages); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1091 | |
| 1092 | /* Populate the VF addresses starting from entry 1 (entry 0 is |
| 1093 | * the PF address) |
| 1094 | */ |
| 1095 | peer = vfdi_status->peers + 1; |
| 1096 | peer_space = ARRAY_SIZE(vfdi_status->peers) - 1; |
| 1097 | peer_count = 1; |
| 1098 | for (pos = 0; pos < efx->vf_count; ++pos) { |
| 1099 | vf = efx->vf + pos; |
| 1100 | |
| 1101 | mutex_lock(&vf->status_lock); |
| 1102 | if (vf->rx_filtering && !is_zero_ether_addr(vf->addr.mac_addr)) { |
| 1103 | *peer++ = vf->addr; |
| 1104 | ++peer_count; |
| 1105 | --peer_space; |
| 1106 | BUG_ON(peer_space == 0); |
| 1107 | } |
| 1108 | mutex_unlock(&vf->status_lock); |
| 1109 | } |
| 1110 | |
| 1111 | /* Fill the remaining addresses */ |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1112 | list_for_each_entry(local_addr, &nic_data->local_addr_list, link) { |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 1113 | ether_addr_copy(peer->mac_addr, local_addr->addr); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1114 | peer->tci = 0; |
| 1115 | ++peer; |
| 1116 | ++peer_count; |
| 1117 | if (--peer_space == 0) { |
| 1118 | if (list_empty(&pages)) { |
| 1119 | epp = kmalloc(sizeof(*epp), GFP_KERNEL); |
| 1120 | if (!epp) |
| 1121 | break; |
| 1122 | epp->ptr = dma_alloc_coherent( |
| 1123 | &efx->pci_dev->dev, EFX_PAGE_SIZE, |
| 1124 | &epp->addr, GFP_KERNEL); |
| 1125 | if (!epp->ptr) { |
| 1126 | kfree(epp); |
| 1127 | break; |
| 1128 | } |
| 1129 | } else { |
| 1130 | epp = list_first_entry( |
| 1131 | &pages, struct efx_endpoint_page, link); |
| 1132 | list_del(&epp->link); |
| 1133 | } |
| 1134 | |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1135 | list_add_tail(&epp->link, &nic_data->local_page_list); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1136 | peer = (struct vfdi_endpoint *)epp->ptr; |
| 1137 | peer_space = EFX_PAGE_SIZE / sizeof(struct vfdi_endpoint); |
| 1138 | } |
| 1139 | } |
| 1140 | vfdi_status->peer_count = peer_count; |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1141 | mutex_unlock(&nic_data->local_lock); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1142 | |
| 1143 | /* Free any now unused endpoint pages */ |
| 1144 | while (!list_empty(&pages)) { |
| 1145 | epp = list_first_entry( |
| 1146 | &pages, struct efx_endpoint_page, link); |
| 1147 | list_del(&epp->link); |
| 1148 | dma_free_coherent(&efx->pci_dev->dev, EFX_PAGE_SIZE, |
| 1149 | epp->ptr, epp->addr); |
| 1150 | kfree(epp); |
| 1151 | } |
| 1152 | |
| 1153 | /* Finally, push the pages */ |
| 1154 | for (pos = 0; pos < efx->vf_count; ++pos) { |
| 1155 | vf = efx->vf + pos; |
| 1156 | |
| 1157 | mutex_lock(&vf->status_lock); |
| 1158 | if (vf->status_addr) |
| 1159 | __efx_sriov_push_vf_status(vf); |
| 1160 | mutex_unlock(&vf->status_lock); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | static void efx_sriov_free_local(struct efx_nic *efx) |
| 1165 | { |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1166 | struct siena_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1167 | struct efx_local_addr *local_addr; |
| 1168 | struct efx_endpoint_page *epp; |
| 1169 | |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1170 | while (!list_empty(&nic_data->local_addr_list)) { |
| 1171 | local_addr = list_first_entry(&nic_data->local_addr_list, |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1172 | struct efx_local_addr, link); |
| 1173 | list_del(&local_addr->link); |
| 1174 | kfree(local_addr); |
| 1175 | } |
| 1176 | |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1177 | while (!list_empty(&nic_data->local_page_list)) { |
| 1178 | epp = list_first_entry(&nic_data->local_page_list, |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1179 | struct efx_endpoint_page, link); |
| 1180 | list_del(&epp->link); |
| 1181 | dma_free_coherent(&efx->pci_dev->dev, EFX_PAGE_SIZE, |
| 1182 | epp->ptr, epp->addr); |
| 1183 | kfree(epp); |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | static int efx_sriov_vf_alloc(struct efx_nic *efx) |
| 1188 | { |
| 1189 | unsigned index; |
| 1190 | struct efx_vf *vf; |
| 1191 | |
| 1192 | efx->vf = kzalloc(sizeof(struct efx_vf) * efx->vf_count, GFP_KERNEL); |
| 1193 | if (!efx->vf) |
| 1194 | return -ENOMEM; |
| 1195 | |
| 1196 | for (index = 0; index < efx->vf_count; ++index) { |
| 1197 | vf = efx->vf + index; |
| 1198 | |
| 1199 | vf->efx = efx; |
| 1200 | vf->index = index; |
| 1201 | vf->rx_filter_id = -1; |
| 1202 | vf->tx_filter_mode = VF_TX_FILTER_AUTO; |
| 1203 | vf->tx_filter_id = -1; |
| 1204 | INIT_WORK(&vf->req, efx_sriov_vfdi); |
| 1205 | INIT_WORK(&vf->reset_work, efx_sriov_reset_vf_work); |
| 1206 | init_waitqueue_head(&vf->flush_waitq); |
| 1207 | mutex_init(&vf->status_lock); |
| 1208 | mutex_init(&vf->txq_lock); |
| 1209 | } |
| 1210 | |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
| 1214 | static void efx_sriov_vfs_fini(struct efx_nic *efx) |
| 1215 | { |
| 1216 | struct efx_vf *vf; |
| 1217 | unsigned int pos; |
| 1218 | |
| 1219 | for (pos = 0; pos < efx->vf_count; ++pos) { |
| 1220 | vf = efx->vf + pos; |
| 1221 | |
| 1222 | efx_nic_free_buffer(efx, &vf->buf); |
| 1223 | kfree(vf->peer_page_addrs); |
| 1224 | vf->peer_page_addrs = NULL; |
| 1225 | vf->peer_page_count = 0; |
| 1226 | |
| 1227 | vf->evq0_count = 0; |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | static int efx_sriov_vfs_init(struct efx_nic *efx) |
| 1232 | { |
| 1233 | struct pci_dev *pci_dev = efx->pci_dev; |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1234 | struct siena_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1235 | unsigned index, devfn, sriov, buftbl_base; |
| 1236 | u16 offset, stride; |
| 1237 | struct efx_vf *vf; |
| 1238 | int rc; |
| 1239 | |
| 1240 | sriov = pci_find_ext_capability(pci_dev, PCI_EXT_CAP_ID_SRIOV); |
| 1241 | if (!sriov) |
| 1242 | return -ENOENT; |
| 1243 | |
| 1244 | pci_read_config_word(pci_dev, sriov + PCI_SRIOV_VF_OFFSET, &offset); |
| 1245 | pci_read_config_word(pci_dev, sriov + PCI_SRIOV_VF_STRIDE, &stride); |
| 1246 | |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1247 | buftbl_base = nic_data->vf_buftbl_base; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1248 | devfn = pci_dev->devfn + offset; |
| 1249 | for (index = 0; index < efx->vf_count; ++index) { |
| 1250 | vf = efx->vf + index; |
| 1251 | |
| 1252 | /* Reserve buffer entries */ |
| 1253 | vf->buftbl_base = buftbl_base; |
| 1254 | buftbl_base += EFX_VF_BUFTBL_PER_VI * efx_vf_size(efx); |
| 1255 | |
| 1256 | vf->pci_rid = devfn; |
| 1257 | snprintf(vf->pci_name, sizeof(vf->pci_name), |
| 1258 | "%04x:%02x:%02x.%d", |
| 1259 | pci_domain_nr(pci_dev->bus), pci_dev->bus->number, |
| 1260 | PCI_SLOT(devfn), PCI_FUNC(devfn)); |
| 1261 | |
Ben Hutchings | 0d19a54 | 2012-09-18 21:59:52 +0100 | [diff] [blame] | 1262 | rc = efx_nic_alloc_buffer(efx, &vf->buf, EFX_PAGE_SIZE, |
| 1263 | GFP_KERNEL); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1264 | if (rc) |
| 1265 | goto fail; |
| 1266 | |
| 1267 | devfn += stride; |
| 1268 | } |
| 1269 | |
| 1270 | return 0; |
| 1271 | |
| 1272 | fail: |
| 1273 | efx_sriov_vfs_fini(efx); |
| 1274 | return rc; |
| 1275 | } |
| 1276 | |
| 1277 | int efx_sriov_init(struct efx_nic *efx) |
| 1278 | { |
| 1279 | struct net_device *net_dev = efx->net_dev; |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1280 | struct siena_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1281 | struct vfdi_status *vfdi_status; |
| 1282 | int rc; |
| 1283 | |
| 1284 | /* Ensure there's room for vf_channel */ |
| 1285 | BUILD_BUG_ON(EFX_MAX_CHANNELS + 1 >= EFX_VI_BASE); |
| 1286 | /* Ensure that VI_BASE is aligned on VI_SCALE */ |
| 1287 | BUILD_BUG_ON(EFX_VI_BASE & ((1 << EFX_VI_SCALE_MAX) - 1)); |
| 1288 | |
| 1289 | if (efx->vf_count == 0) |
| 1290 | return 0; |
| 1291 | |
| 1292 | rc = efx_sriov_cmd(efx, true, NULL, NULL); |
| 1293 | if (rc) |
| 1294 | goto fail_cmd; |
| 1295 | |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1296 | rc = efx_nic_alloc_buffer(efx, &nic_data->vfdi_status, |
| 1297 | sizeof(*vfdi_status), GFP_KERNEL); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1298 | if (rc) |
| 1299 | goto fail_status; |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1300 | vfdi_status = nic_data->vfdi_status.addr; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1301 | memset(vfdi_status, 0, sizeof(*vfdi_status)); |
| 1302 | vfdi_status->version = 1; |
| 1303 | vfdi_status->length = sizeof(*vfdi_status); |
| 1304 | vfdi_status->max_tx_channels = vf_max_tx_channels; |
| 1305 | vfdi_status->vi_scale = efx->vi_scale; |
| 1306 | vfdi_status->rss_rxq_count = efx->rss_spread; |
| 1307 | vfdi_status->peer_count = 1 + efx->vf_count; |
| 1308 | vfdi_status->timer_quantum_ns = efx->timer_quantum_ns; |
| 1309 | |
| 1310 | rc = efx_sriov_vf_alloc(efx); |
| 1311 | if (rc) |
| 1312 | goto fail_alloc; |
| 1313 | |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1314 | mutex_init(&nic_data->local_lock); |
| 1315 | INIT_WORK(&nic_data->peer_work, efx_sriov_peer_work); |
| 1316 | INIT_LIST_HEAD(&nic_data->local_addr_list); |
| 1317 | INIT_LIST_HEAD(&nic_data->local_page_list); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1318 | |
| 1319 | rc = efx_sriov_vfs_init(efx); |
| 1320 | if (rc) |
| 1321 | goto fail_vfs; |
| 1322 | |
| 1323 | rtnl_lock(); |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 1324 | ether_addr_copy(vfdi_status->peers[0].mac_addr, net_dev->dev_addr); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1325 | efx->vf_init_count = efx->vf_count; |
| 1326 | rtnl_unlock(); |
| 1327 | |
| 1328 | efx_sriov_usrev(efx, true); |
| 1329 | |
| 1330 | /* At this point we must be ready to accept VFDI requests */ |
| 1331 | |
| 1332 | rc = pci_enable_sriov(efx->pci_dev, efx->vf_count); |
| 1333 | if (rc) |
| 1334 | goto fail_pci; |
| 1335 | |
| 1336 | netif_info(efx, probe, net_dev, |
| 1337 | "enabled SR-IOV for %d VFs, %d VI per VF\n", |
| 1338 | efx->vf_count, efx_vf_size(efx)); |
| 1339 | return 0; |
| 1340 | |
| 1341 | fail_pci: |
| 1342 | efx_sriov_usrev(efx, false); |
| 1343 | rtnl_lock(); |
| 1344 | efx->vf_init_count = 0; |
| 1345 | rtnl_unlock(); |
| 1346 | efx_sriov_vfs_fini(efx); |
| 1347 | fail_vfs: |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1348 | cancel_work_sync(&nic_data->peer_work); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1349 | efx_sriov_free_local(efx); |
| 1350 | kfree(efx->vf); |
| 1351 | fail_alloc: |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1352 | efx_nic_free_buffer(efx, &nic_data->vfdi_status); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1353 | fail_status: |
| 1354 | efx_sriov_cmd(efx, false, NULL, NULL); |
| 1355 | fail_cmd: |
| 1356 | return rc; |
| 1357 | } |
| 1358 | |
| 1359 | void efx_sriov_fini(struct efx_nic *efx) |
| 1360 | { |
| 1361 | struct efx_vf *vf; |
| 1362 | unsigned int pos; |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1363 | struct siena_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1364 | |
| 1365 | if (efx->vf_init_count == 0) |
| 1366 | return; |
| 1367 | |
| 1368 | /* Disable all interfaces to reconfiguration */ |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1369 | BUG_ON(nic_data->vfdi_channel->enabled); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1370 | efx_sriov_usrev(efx, false); |
| 1371 | rtnl_lock(); |
| 1372 | efx->vf_init_count = 0; |
| 1373 | rtnl_unlock(); |
| 1374 | |
| 1375 | /* Flush all reconfiguration work */ |
| 1376 | for (pos = 0; pos < efx->vf_count; ++pos) { |
| 1377 | vf = efx->vf + pos; |
| 1378 | cancel_work_sync(&vf->req); |
| 1379 | cancel_work_sync(&vf->reset_work); |
| 1380 | } |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1381 | cancel_work_sync(&nic_data->peer_work); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1382 | |
| 1383 | pci_disable_sriov(efx->pci_dev); |
| 1384 | |
| 1385 | /* Tear down back-end state */ |
| 1386 | efx_sriov_vfs_fini(efx); |
| 1387 | efx_sriov_free_local(efx); |
| 1388 | kfree(efx->vf); |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1389 | efx_nic_free_buffer(efx, &nic_data->vfdi_status); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1390 | efx_sriov_cmd(efx, false, NULL, NULL); |
| 1391 | } |
| 1392 | |
| 1393 | void efx_sriov_event(struct efx_channel *channel, efx_qword_t *event) |
| 1394 | { |
| 1395 | struct efx_nic *efx = channel->efx; |
| 1396 | struct efx_vf *vf; |
| 1397 | unsigned qid, seq, type, data; |
| 1398 | |
| 1399 | qid = EFX_QWORD_FIELD(*event, FSF_CZ_USER_QID); |
| 1400 | |
| 1401 | /* USR_EV_REG_VALUE is dword0, so access the VFDI_EV fields directly */ |
| 1402 | BUILD_BUG_ON(FSF_CZ_USER_EV_REG_VALUE_LBN != 0); |
| 1403 | seq = EFX_QWORD_FIELD(*event, VFDI_EV_SEQ); |
| 1404 | type = EFX_QWORD_FIELD(*event, VFDI_EV_TYPE); |
| 1405 | data = EFX_QWORD_FIELD(*event, VFDI_EV_DATA); |
| 1406 | |
| 1407 | netif_vdbg(efx, hw, efx->net_dev, |
| 1408 | "USR_EV event from qid %d seq 0x%x type %d data 0x%x\n", |
| 1409 | qid, seq, type, data); |
| 1410 | |
| 1411 | if (map_vi_index(efx, qid, &vf, NULL)) |
| 1412 | return; |
| 1413 | if (vf->busy) |
| 1414 | goto error; |
| 1415 | |
| 1416 | if (type == VFDI_EV_TYPE_REQ_WORD0) { |
| 1417 | /* Resynchronise */ |
| 1418 | vf->req_type = VFDI_EV_TYPE_REQ_WORD0; |
| 1419 | vf->req_seqno = seq + 1; |
| 1420 | vf->req_addr = 0; |
| 1421 | } else if (seq != (vf->req_seqno++ & 0xff) || type != vf->req_type) |
| 1422 | goto error; |
| 1423 | |
| 1424 | switch (vf->req_type) { |
| 1425 | case VFDI_EV_TYPE_REQ_WORD0: |
| 1426 | case VFDI_EV_TYPE_REQ_WORD1: |
| 1427 | case VFDI_EV_TYPE_REQ_WORD2: |
| 1428 | vf->req_addr |= (u64)data << (vf->req_type << 4); |
| 1429 | ++vf->req_type; |
| 1430 | return; |
| 1431 | |
| 1432 | case VFDI_EV_TYPE_REQ_WORD3: |
| 1433 | vf->req_addr |= (u64)data << 48; |
| 1434 | vf->req_type = VFDI_EV_TYPE_REQ_WORD0; |
| 1435 | vf->busy = true; |
| 1436 | queue_work(vfdi_workqueue, &vf->req); |
| 1437 | return; |
| 1438 | } |
| 1439 | |
| 1440 | error: |
| 1441 | if (net_ratelimit()) |
| 1442 | netif_err(efx, hw, efx->net_dev, |
| 1443 | "ERROR: Screaming VFDI request from %s\n", |
| 1444 | vf->pci_name); |
| 1445 | /* Reset the request and sequence number */ |
| 1446 | vf->req_type = VFDI_EV_TYPE_REQ_WORD0; |
| 1447 | vf->req_seqno = seq + 1; |
| 1448 | } |
| 1449 | |
| 1450 | void efx_sriov_flr(struct efx_nic *efx, unsigned vf_i) |
| 1451 | { |
| 1452 | struct efx_vf *vf; |
| 1453 | |
| 1454 | if (vf_i > efx->vf_init_count) |
| 1455 | return; |
| 1456 | vf = efx->vf + vf_i; |
| 1457 | netif_info(efx, hw, efx->net_dev, |
| 1458 | "FLR on VF %s\n", vf->pci_name); |
| 1459 | |
| 1460 | vf->status_addr = 0; |
| 1461 | efx_vfdi_remove_all_filters(vf); |
| 1462 | efx_vfdi_flush_clear(vf); |
| 1463 | |
| 1464 | vf->evq0_count = 0; |
| 1465 | } |
| 1466 | |
| 1467 | void efx_sriov_mac_address_changed(struct efx_nic *efx) |
| 1468 | { |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1469 | struct siena_nic_data *nic_data = efx->nic_data; |
| 1470 | struct vfdi_status *vfdi_status = nic_data->vfdi_status.addr; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1471 | |
| 1472 | if (!efx->vf_init_count) |
| 1473 | return; |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 1474 | ether_addr_copy(vfdi_status->peers[0].mac_addr, |
| 1475 | efx->net_dev->dev_addr); |
Shradha Shah | 2dc313e | 2014-11-05 12:16:18 +0000 | [diff] [blame^] | 1476 | queue_work(vfdi_workqueue, &nic_data->peer_work); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | void efx_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event) |
| 1480 | { |
| 1481 | struct efx_vf *vf; |
| 1482 | unsigned queue, qid; |
| 1483 | |
| 1484 | queue = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA); |
| 1485 | if (map_vi_index(efx, queue, &vf, &qid)) |
| 1486 | return; |
| 1487 | /* Ignore flush completions triggered by an FLR */ |
| 1488 | if (!test_bit(qid, vf->txq_mask)) |
| 1489 | return; |
| 1490 | |
| 1491 | __clear_bit(qid, vf->txq_mask); |
| 1492 | --vf->txq_count; |
| 1493 | |
| 1494 | if (efx_vfdi_flush_wake(vf)) |
| 1495 | wake_up(&vf->flush_waitq); |
| 1496 | } |
| 1497 | |
| 1498 | void efx_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event) |
| 1499 | { |
| 1500 | struct efx_vf *vf; |
| 1501 | unsigned ev_failed, queue, qid; |
| 1502 | |
| 1503 | queue = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID); |
| 1504 | ev_failed = EFX_QWORD_FIELD(*event, |
| 1505 | FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL); |
| 1506 | if (map_vi_index(efx, queue, &vf, &qid)) |
| 1507 | return; |
| 1508 | if (!test_bit(qid, vf->rxq_mask)) |
| 1509 | return; |
| 1510 | |
| 1511 | if (ev_failed) { |
| 1512 | set_bit(qid, vf->rxq_retry_mask); |
| 1513 | atomic_inc(&vf->rxq_retry_count); |
| 1514 | } else { |
| 1515 | __clear_bit(qid, vf->rxq_mask); |
| 1516 | --vf->rxq_count; |
| 1517 | } |
| 1518 | if (efx_vfdi_flush_wake(vf)) |
| 1519 | wake_up(&vf->flush_waitq); |
| 1520 | } |
| 1521 | |
| 1522 | /* Called from napi. Schedule the reset work item */ |
| 1523 | void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq) |
| 1524 | { |
| 1525 | struct efx_vf *vf; |
| 1526 | unsigned int rel; |
| 1527 | |
| 1528 | if (map_vi_index(efx, dmaq, &vf, &rel)) |
| 1529 | return; |
| 1530 | |
| 1531 | if (net_ratelimit()) |
| 1532 | netif_err(efx, hw, efx->net_dev, |
| 1533 | "VF %d DMA Q %d reports descriptor fetch error.\n", |
| 1534 | vf->index, rel); |
| 1535 | queue_work(vfdi_workqueue, &vf->reset_work); |
| 1536 | } |
| 1537 | |
| 1538 | /* Reset all VFs */ |
| 1539 | void efx_sriov_reset(struct efx_nic *efx) |
| 1540 | { |
| 1541 | unsigned int vf_i; |
| 1542 | struct efx_buffer buf; |
| 1543 | struct efx_vf *vf; |
| 1544 | |
| 1545 | ASSERT_RTNL(); |
| 1546 | |
| 1547 | if (efx->vf_init_count == 0) |
| 1548 | return; |
| 1549 | |
| 1550 | efx_sriov_usrev(efx, true); |
| 1551 | (void)efx_sriov_cmd(efx, true, NULL, NULL); |
| 1552 | |
Ben Hutchings | 0d19a54 | 2012-09-18 21:59:52 +0100 | [diff] [blame] | 1553 | if (efx_nic_alloc_buffer(efx, &buf, EFX_PAGE_SIZE, GFP_NOIO)) |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1554 | return; |
| 1555 | |
| 1556 | for (vf_i = 0; vf_i < efx->vf_init_count; ++vf_i) { |
| 1557 | vf = efx->vf + vf_i; |
| 1558 | efx_sriov_reset_vf(vf, &buf); |
| 1559 | } |
| 1560 | |
| 1561 | efx_nic_free_buffer(efx, &buf); |
| 1562 | } |
| 1563 | |
| 1564 | int efx_init_sriov(void) |
| 1565 | { |
| 1566 | /* A single threaded workqueue is sufficient. efx_sriov_vfdi() and |
| 1567 | * efx_sriov_peer_work() spend almost all their time sleeping for |
| 1568 | * MCDI to complete anyway |
| 1569 | */ |
| 1570 | vfdi_workqueue = create_singlethread_workqueue("sfc_vfdi"); |
| 1571 | if (!vfdi_workqueue) |
| 1572 | return -ENOMEM; |
| 1573 | |
| 1574 | return 0; |
| 1575 | } |
| 1576 | |
| 1577 | void efx_fini_sriov(void) |
| 1578 | { |
| 1579 | destroy_workqueue(vfdi_workqueue); |
| 1580 | } |
| 1581 | |
| 1582 | int efx_sriov_set_vf_mac(struct net_device *net_dev, int vf_i, u8 *mac) |
| 1583 | { |
| 1584 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1585 | struct efx_vf *vf; |
| 1586 | |
| 1587 | if (vf_i >= efx->vf_init_count) |
| 1588 | return -EINVAL; |
| 1589 | vf = efx->vf + vf_i; |
| 1590 | |
| 1591 | mutex_lock(&vf->status_lock); |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 1592 | ether_addr_copy(vf->addr.mac_addr, mac); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1593 | __efx_sriov_update_vf_addr(vf); |
| 1594 | mutex_unlock(&vf->status_lock); |
| 1595 | |
| 1596 | return 0; |
| 1597 | } |
| 1598 | |
| 1599 | int efx_sriov_set_vf_vlan(struct net_device *net_dev, int vf_i, |
| 1600 | u16 vlan, u8 qos) |
| 1601 | { |
| 1602 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1603 | struct efx_vf *vf; |
| 1604 | u16 tci; |
| 1605 | |
| 1606 | if (vf_i >= efx->vf_init_count) |
| 1607 | return -EINVAL; |
| 1608 | vf = efx->vf + vf_i; |
| 1609 | |
| 1610 | mutex_lock(&vf->status_lock); |
| 1611 | tci = (vlan & VLAN_VID_MASK) | ((qos & 0x7) << VLAN_PRIO_SHIFT); |
| 1612 | vf->addr.tci = htons(tci); |
| 1613 | __efx_sriov_update_vf_addr(vf); |
| 1614 | mutex_unlock(&vf->status_lock); |
| 1615 | |
| 1616 | return 0; |
| 1617 | } |
| 1618 | |
| 1619 | int efx_sriov_set_vf_spoofchk(struct net_device *net_dev, int vf_i, |
| 1620 | bool spoofchk) |
| 1621 | { |
| 1622 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1623 | struct efx_vf *vf; |
| 1624 | int rc; |
| 1625 | |
| 1626 | if (vf_i >= efx->vf_init_count) |
| 1627 | return -EINVAL; |
| 1628 | vf = efx->vf + vf_i; |
| 1629 | |
| 1630 | mutex_lock(&vf->txq_lock); |
| 1631 | if (vf->txq_count == 0) { |
| 1632 | vf->tx_filter_mode = |
| 1633 | spoofchk ? VF_TX_FILTER_ON : VF_TX_FILTER_OFF; |
| 1634 | rc = 0; |
| 1635 | } else { |
| 1636 | /* This cannot be changed while TX queues are running */ |
| 1637 | rc = -EBUSY; |
| 1638 | } |
| 1639 | mutex_unlock(&vf->txq_lock); |
| 1640 | return rc; |
| 1641 | } |
| 1642 | |
| 1643 | int efx_sriov_get_vf_config(struct net_device *net_dev, int vf_i, |
| 1644 | struct ifla_vf_info *ivi) |
| 1645 | { |
| 1646 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1647 | struct efx_vf *vf; |
| 1648 | u16 tci; |
| 1649 | |
| 1650 | if (vf_i >= efx->vf_init_count) |
| 1651 | return -EINVAL; |
| 1652 | vf = efx->vf + vf_i; |
| 1653 | |
| 1654 | ivi->vf = vf_i; |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 1655 | ether_addr_copy(ivi->mac, vf->addr.mac_addr); |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 1656 | ivi->max_tx_rate = 0; |
| 1657 | ivi->min_tx_rate = 0; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1658 | tci = ntohs(vf->addr.tci); |
| 1659 | ivi->vlan = tci & VLAN_VID_MASK; |
| 1660 | ivi->qos = (tci >> VLAN_PRIO_SHIFT) & 0x7; |
| 1661 | ivi->spoofchk = vf->tx_filter_mode == VF_TX_FILTER_ON; |
| 1662 | |
| 1663 | return 0; |
| 1664 | } |
| 1665 | |