blob: 2044e929f48d37c5e84e4f7957978f43f4db1ee6 [file] [log] [blame]
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001/****************************************************************************
Ben Hutchingsf7a6d2c2013-08-29 23:32:48 +01002 * Driver for Solarflare network controllers and boards
3 * Copyright 2010-2012 Solarflare Communications Inc.
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00004 *
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 Hutchings8b8a95a2012-09-18 01:57:07 +010018#include "farch_regs.h"
Shradha Shah7fa8d542015-05-06 00:55:13 +010019#include "siena_sriov.h"
Ben Hutchingscd2d5b52012-02-14 00:48:07 +000020#include "vfdi.h"
21
22/* Number of longs required to track all the VIs in a VF */
23#define VI_MASK_LENGTH BITS_TO_LONGS(1 << EFX_VI_SCALE_MAX)
24
Ben Hutchings45078372012-09-19 02:53:34 +010025/* Maximum number of RX queues supported */
26#define VF_MAX_RX_QUEUES 63
27
Ben Hutchingscd2d5b52012-02-14 00:48:07 +000028/**
29 * enum efx_vf_tx_filter_mode - TX MAC filtering behaviour
30 * @VF_TX_FILTER_OFF: Disabled
31 * @VF_TX_FILTER_AUTO: Enabled if MAC address assigned to VF and only
32 * 2 TX queues allowed per VF.
33 * @VF_TX_FILTER_ON: Enabled
34 */
35enum efx_vf_tx_filter_mode {
36 VF_TX_FILTER_OFF,
37 VF_TX_FILTER_AUTO,
38 VF_TX_FILTER_ON,
39};
40
41/**
Daniel Pieczkobf3d0152015-05-06 00:55:36 +010042 * struct siena_vf - Back-end resource and protocol state for a PCI VF
Ben Hutchingscd2d5b52012-02-14 00:48:07 +000043 * @efx: The Efx NIC owning this VF
44 * @pci_rid: The PCI requester ID for this VF
45 * @pci_name: The PCI name (formatted address) of this VF
46 * @index: Index of VF within its port and PF.
47 * @req: VFDI incoming request work item. Incoming USR_EV events are received
48 * by the NAPI handler, but must be handled by executing MCDI requests
49 * inside a work item.
50 * @req_addr: VFDI incoming request DMA address (in VF's PCI address space).
51 * @req_type: Expected next incoming (from VF) %VFDI_EV_TYPE member.
52 * @req_seqno: Expected next incoming (from VF) %VFDI_EV_SEQ member.
53 * @msg_seqno: Next %VFDI_EV_SEQ member to reply to VF. Protected by
54 * @status_lock
55 * @busy: VFDI request queued to be processed or being processed. Receiving
56 * a VFDI request when @busy is set is an error condition.
57 * @buf: Incoming VFDI requests are DMA from the VF into this buffer.
58 * @buftbl_base: Buffer table entries for this VF start at this index.
59 * @rx_filtering: Receive filtering has been requested by the VF driver.
60 * @rx_filter_flags: The flags sent in the %VFDI_OP_INSERT_FILTER request.
61 * @rx_filter_qid: VF relative qid for RX filter requested by VF.
62 * @rx_filter_id: Receive MAC filter ID. Only one filter per VF is supported.
63 * @tx_filter_mode: Transmit MAC filtering mode.
64 * @tx_filter_id: Transmit MAC filter ID.
65 * @addr: The MAC address and outer vlan tag of the VF.
66 * @status_addr: VF DMA address of page for &struct vfdi_status updates.
67 * @status_lock: Mutex protecting @msg_seqno, @status_addr, @addr,
68 * @peer_page_addrs and @peer_page_count from simultaneous
69 * updates by the VM and consumption by
Shradha Shah327c6852014-11-05 12:16:32 +000070 * efx_siena_sriov_update_vf_addr()
Ben Hutchingscd2d5b52012-02-14 00:48:07 +000071 * @peer_page_addrs: Pointer to an array of guest pages for local addresses.
72 * @peer_page_count: Number of entries in @peer_page_count.
73 * @evq0_addrs: Array of guest pages backing evq0.
74 * @evq0_count: Number of entries in @evq0_addrs.
75 * @flush_waitq: wait queue used by %VFDI_OP_FINI_ALL_QUEUES handler
76 * to wait for flush completions.
77 * @txq_lock: Mutex for TX queue allocation.
78 * @txq_mask: Mask of initialized transmit queues.
79 * @txq_count: Number of initialized transmit queues.
80 * @rxq_mask: Mask of initialized receive queues.
81 * @rxq_count: Number of initialized receive queues.
82 * @rxq_retry_mask: Mask or receive queues that need to be flushed again
83 * due to flush failure.
84 * @rxq_retry_count: Number of receive queues in @rxq_retry_mask.
85 * @reset_work: Work item to schedule a VF reset.
86 */
Daniel Pieczkobf3d0152015-05-06 00:55:36 +010087struct siena_vf {
Ben Hutchingscd2d5b52012-02-14 00:48:07 +000088 struct efx_nic *efx;
89 unsigned int pci_rid;
90 char pci_name[13]; /* dddd:bb:dd.f */
91 unsigned int index;
92 struct work_struct req;
93 u64 req_addr;
94 int req_type;
95 unsigned req_seqno;
96 unsigned msg_seqno;
97 bool busy;
98 struct efx_buffer buf;
99 unsigned buftbl_base;
100 bool rx_filtering;
101 enum efx_filter_flags rx_filter_flags;
102 unsigned rx_filter_qid;
103 int rx_filter_id;
104 enum efx_vf_tx_filter_mode tx_filter_mode;
105 int tx_filter_id;
106 struct vfdi_endpoint addr;
107 u64 status_addr;
108 struct mutex status_lock;
109 u64 *peer_page_addrs;
110 unsigned peer_page_count;
111 u64 evq0_addrs[EFX_MAX_VF_EVQ_SIZE * sizeof(efx_qword_t) /
112 EFX_BUF_SIZE];
113 unsigned evq0_count;
114 wait_queue_head_t flush_waitq;
115 struct mutex txq_lock;
116 unsigned long txq_mask[VI_MASK_LENGTH];
117 unsigned txq_count;
118 unsigned long rxq_mask[VI_MASK_LENGTH];
119 unsigned rxq_count;
120 unsigned long rxq_retry_mask[VI_MASK_LENGTH];
121 atomic_t rxq_retry_count;
122 struct work_struct reset_work;
123};
124
125struct efx_memcpy_req {
126 unsigned int from_rid;
127 void *from_buf;
128 u64 from_addr;
129 unsigned int to_rid;
130 u64 to_addr;
131 unsigned length;
132};
133
134/**
135 * struct efx_local_addr - A MAC address on the vswitch without a VF.
136 *
137 * Siena does not have a switch, so VFs can't transmit data to each
138 * other. Instead the VFs must be made aware of the local addresses
139 * on the vswitch, so that they can arrange for an alternative
140 * software datapath to be used.
141 *
142 * @link: List head for insertion into efx->local_addr_list.
143 * @addr: Ethernet address
144 */
145struct efx_local_addr {
146 struct list_head link;
147 u8 addr[ETH_ALEN];
148};
149
150/**
151 * struct efx_endpoint_page - Page of vfdi_endpoint structures
152 *
153 * @link: List head for insertion into efx->local_page_list.
154 * @ptr: Pointer to page.
155 * @addr: DMA address of page.
156 */
157struct efx_endpoint_page {
158 struct list_head link;
159 void *ptr;
160 dma_addr_t addr;
161};
162
163/* Buffer table entries are reserved txq0,rxq0,evq0,txq1,rxq1,evq1 */
164#define EFX_BUFTBL_TXQ_BASE(_vf, _qid) \
165 ((_vf)->buftbl_base + EFX_VF_BUFTBL_PER_VI * (_qid))
166#define EFX_BUFTBL_RXQ_BASE(_vf, _qid) \
167 (EFX_BUFTBL_TXQ_BASE(_vf, _qid) + \
168 (EFX_MAX_DMAQ_SIZE * sizeof(efx_qword_t) / EFX_BUF_SIZE))
169#define EFX_BUFTBL_EVQ_BASE(_vf, _qid) \
170 (EFX_BUFTBL_TXQ_BASE(_vf, _qid) + \
171 (2 * EFX_MAX_DMAQ_SIZE * sizeof(efx_qword_t) / EFX_BUF_SIZE))
172
173#define EFX_FIELD_MASK(_field) \
174 ((1 << _field ## _WIDTH) - 1)
175
176/* VFs can only use this many transmit channels */
177static unsigned int vf_max_tx_channels = 2;
178module_param(vf_max_tx_channels, uint, 0444);
179MODULE_PARM_DESC(vf_max_tx_channels,
180 "Limit the number of TX channels VFs can use");
181
182static int max_vfs = -1;
183module_param(max_vfs, int, 0444);
184MODULE_PARM_DESC(max_vfs,
185 "Reduce the number of VFs initialized by the driver");
186
187/* Workqueue used by VFDI communication. We can't use the global
188 * workqueue because it may be running the VF driver's probe()
189 * routine, which will be blocked there waiting for a VFDI response.
190 */
191static struct workqueue_struct *vfdi_workqueue;
192
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100193static unsigned abs_index(struct siena_vf *vf, unsigned index)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000194{
195 return EFX_VI_BASE + vf->index * efx_vf_size(vf->efx) + index;
196}
197
Shradha Shah327c6852014-11-05 12:16:32 +0000198static int efx_siena_sriov_cmd(struct efx_nic *efx, bool enable,
199 unsigned *vi_scale_out, unsigned *vf_total_out)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000200{
Ben Hutchings59cfc472012-09-14 17:30:10 +0100201 MCDI_DECLARE_BUF(inbuf, MC_CMD_SRIOV_IN_LEN);
202 MCDI_DECLARE_BUF(outbuf, MC_CMD_SRIOV_OUT_LEN);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000203 unsigned vi_scale, vf_total;
204 size_t outlen;
205 int rc;
206
207 MCDI_SET_DWORD(inbuf, SRIOV_IN_ENABLE, enable ? 1 : 0);
208 MCDI_SET_DWORD(inbuf, SRIOV_IN_VI_BASE, EFX_VI_BASE);
209 MCDI_SET_DWORD(inbuf, SRIOV_IN_VF_COUNT, efx->vf_count);
210
211 rc = efx_mcdi_rpc(efx, MC_CMD_SRIOV, inbuf, MC_CMD_SRIOV_IN_LEN,
212 outbuf, MC_CMD_SRIOV_OUT_LEN, &outlen);
213 if (rc)
214 return rc;
215 if (outlen < MC_CMD_SRIOV_OUT_LEN)
216 return -EIO;
217
218 vf_total = MCDI_DWORD(outbuf, SRIOV_OUT_VF_TOTAL);
219 vi_scale = MCDI_DWORD(outbuf, SRIOV_OUT_VI_SCALE);
220 if (vi_scale > EFX_VI_SCALE_MAX)
221 return -EOPNOTSUPP;
222
223 if (vi_scale_out)
224 *vi_scale_out = vi_scale;
225 if (vf_total_out)
226 *vf_total_out = vf_total;
227
228 return 0;
229}
230
Shradha Shah327c6852014-11-05 12:16:32 +0000231static void efx_siena_sriov_usrev(struct efx_nic *efx, bool enabled)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000232{
Shradha Shah2dc313e2014-11-05 12:16:18 +0000233 struct siena_nic_data *nic_data = efx->nic_data;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000234 efx_oword_t reg;
235
236 EFX_POPULATE_OWORD_2(reg,
237 FRF_CZ_USREV_DIS, enabled ? 0 : 1,
Shradha Shah2dc313e2014-11-05 12:16:18 +0000238 FRF_CZ_DFLT_EVQ, nic_data->vfdi_channel->channel);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000239 efx_writeo(efx, &reg, FR_CZ_USR_EV_CFG);
240}
241
Shradha Shah327c6852014-11-05 12:16:32 +0000242static int efx_siena_sriov_memcpy(struct efx_nic *efx,
243 struct efx_memcpy_req *req,
244 unsigned int count)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000245{
Ben Hutchingsc5bb0e92012-09-14 17:31:33 +0100246 MCDI_DECLARE_BUF(inbuf, MCDI_CTL_SDU_LEN_MAX_V1);
247 MCDI_DECLARE_STRUCT_PTR(record);
248 unsigned int index, used;
Ben Hutchings338f74d2012-10-10 23:20:17 +0100249 u64 from_addr;
250 u32 from_rid;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000251 int rc;
252
253 mb(); /* Finish writing source/reading dest before DMA starts */
254
Ben Hutchingsc5bb0e92012-09-14 17:31:33 +0100255 if (WARN_ON(count > MC_CMD_MEMCPY_IN_RECORD_MAXNUM))
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000256 return -ENOBUFS;
Ben Hutchingsc5bb0e92012-09-14 17:31:33 +0100257 used = MC_CMD_MEMCPY_IN_LEN(count);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000258
Ben Hutchingsc5bb0e92012-09-14 17:31:33 +0100259 for (index = 0; index < count; index++) {
260 record = MCDI_ARRAY_STRUCT_PTR(inbuf, MEMCPY_IN_RECORD, index);
261 MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_NUM_RECORDS,
262 count);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000263 MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_TO_RID,
264 req->to_rid);
Ben Hutchings338f74d2012-10-10 23:20:17 +0100265 MCDI_SET_QWORD(record, MEMCPY_RECORD_TYPEDEF_TO_ADDR,
266 req->to_addr);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000267 if (req->from_buf == NULL) {
268 from_rid = req->from_rid;
Ben Hutchings338f74d2012-10-10 23:20:17 +0100269 from_addr = req->from_addr;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000270 } else {
Ben Hutchingsd0c2ee92013-08-20 15:47:12 +0100271 if (WARN_ON(used + req->length >
272 MCDI_CTL_SDU_LEN_MAX_V1)) {
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000273 rc = -ENOBUFS;
274 goto out;
275 }
276
277 from_rid = MC_CMD_MEMCPY_RECORD_TYPEDEF_RID_INLINE;
Ben Hutchings338f74d2012-10-10 23:20:17 +0100278 from_addr = used;
Ben Hutchingsc5bb0e92012-09-14 17:31:33 +0100279 memcpy(_MCDI_PTR(inbuf, used), req->from_buf,
280 req->length);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000281 used += req->length;
282 }
283
284 MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_FROM_RID, from_rid);
Ben Hutchings338f74d2012-10-10 23:20:17 +0100285 MCDI_SET_QWORD(record, MEMCPY_RECORD_TYPEDEF_FROM_ADDR,
286 from_addr);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000287 MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_LENGTH,
288 req->length);
289
290 ++req;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000291 }
292
293 rc = efx_mcdi_rpc(efx, MC_CMD_MEMCPY, inbuf, used, NULL, 0, NULL);
294out:
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000295 mb(); /* Don't write source/read dest before DMA is complete */
296
297 return rc;
298}
299
300/* The TX filter is entirely controlled by this driver, and is modified
301 * underneath the feet of the VF
302 */
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100303static void efx_siena_sriov_reset_tx_filter(struct siena_vf *vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000304{
305 struct efx_nic *efx = vf->efx;
306 struct efx_filter_spec filter;
307 u16 vlan;
308 int rc;
309
310 if (vf->tx_filter_id != -1) {
311 efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED,
312 vf->tx_filter_id);
313 netif_dbg(efx, hw, efx->net_dev, "Removed vf %s tx filter %d\n",
314 vf->pci_name, vf->tx_filter_id);
315 vf->tx_filter_id = -1;
316 }
317
318 if (is_zero_ether_addr(vf->addr.mac_addr))
319 return;
320
321 /* Turn on TX filtering automatically if not explicitly
322 * enabled or disabled.
323 */
324 if (vf->tx_filter_mode == VF_TX_FILTER_AUTO && vf_max_tx_channels <= 2)
325 vf->tx_filter_mode = VF_TX_FILTER_ON;
326
327 vlan = ntohs(vf->addr.tci) & VLAN_VID_MASK;
328 efx_filter_init_tx(&filter, abs_index(vf, 0));
329 rc = efx_filter_set_eth_local(&filter,
330 vlan ? vlan : EFX_FILTER_VID_UNSPEC,
331 vf->addr.mac_addr);
332 BUG_ON(rc);
333
334 rc = efx_filter_insert_filter(efx, &filter, true);
335 if (rc < 0) {
336 netif_warn(efx, hw, efx->net_dev,
337 "Unable to migrate tx filter for vf %s\n",
338 vf->pci_name);
339 } else {
340 netif_dbg(efx, hw, efx->net_dev, "Inserted vf %s tx filter %d\n",
341 vf->pci_name, rc);
342 vf->tx_filter_id = rc;
343 }
344}
345
346/* The RX filter is managed here on behalf of the VF driver */
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100347static void efx_siena_sriov_reset_rx_filter(struct siena_vf *vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000348{
349 struct efx_nic *efx = vf->efx;
350 struct efx_filter_spec filter;
351 u16 vlan;
352 int rc;
353
354 if (vf->rx_filter_id != -1) {
355 efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED,
356 vf->rx_filter_id);
357 netif_dbg(efx, hw, efx->net_dev, "Removed vf %s rx filter %d\n",
358 vf->pci_name, vf->rx_filter_id);
359 vf->rx_filter_id = -1;
360 }
361
362 if (!vf->rx_filtering || is_zero_ether_addr(vf->addr.mac_addr))
363 return;
364
365 vlan = ntohs(vf->addr.tci) & VLAN_VID_MASK;
366 efx_filter_init_rx(&filter, EFX_FILTER_PRI_REQUIRED,
367 vf->rx_filter_flags,
368 abs_index(vf, vf->rx_filter_qid));
369 rc = efx_filter_set_eth_local(&filter,
370 vlan ? vlan : EFX_FILTER_VID_UNSPEC,
371 vf->addr.mac_addr);
372 BUG_ON(rc);
373
374 rc = efx_filter_insert_filter(efx, &filter, true);
375 if (rc < 0) {
376 netif_warn(efx, hw, efx->net_dev,
377 "Unable to insert rx filter for vf %s\n",
378 vf->pci_name);
379 } else {
380 netif_dbg(efx, hw, efx->net_dev, "Inserted vf %s rx filter %d\n",
381 vf->pci_name, rc);
382 vf->rx_filter_id = rc;
383 }
384}
385
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100386static void __efx_siena_sriov_update_vf_addr(struct siena_vf *vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000387{
Shradha Shah2dc313e2014-11-05 12:16:18 +0000388 struct efx_nic *efx = vf->efx;
389 struct siena_nic_data *nic_data = efx->nic_data;
390
Shradha Shah327c6852014-11-05 12:16:32 +0000391 efx_siena_sriov_reset_tx_filter(vf);
392 efx_siena_sriov_reset_rx_filter(vf);
Shradha Shah2dc313e2014-11-05 12:16:18 +0000393 queue_work(vfdi_workqueue, &nic_data->peer_work);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000394}
395
396/* Push the peer list to this VF. The caller must hold status_lock to interlock
397 * with VFDI requests, and they must be serialised against manipulation of
398 * local_page_list, either by acquiring local_lock or by running from
Shradha Shah327c6852014-11-05 12:16:32 +0000399 * efx_siena_sriov_peer_work()
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000400 */
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100401static void __efx_siena_sriov_push_vf_status(struct siena_vf *vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000402{
403 struct efx_nic *efx = vf->efx;
Shradha Shah2dc313e2014-11-05 12:16:18 +0000404 struct siena_nic_data *nic_data = efx->nic_data;
405 struct vfdi_status *status = nic_data->vfdi_status.addr;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000406 struct efx_memcpy_req copy[4];
407 struct efx_endpoint_page *epp;
408 unsigned int pos, count;
409 unsigned data_offset;
410 efx_qword_t event;
411
412 WARN_ON(!mutex_is_locked(&vf->status_lock));
413 WARN_ON(!vf->status_addr);
414
415 status->local = vf->addr;
416 status->generation_end = ++status->generation_start;
417
418 memset(copy, '\0', sizeof(copy));
419 /* Write generation_start */
420 copy[0].from_buf = &status->generation_start;
421 copy[0].to_rid = vf->pci_rid;
422 copy[0].to_addr = vf->status_addr + offsetof(struct vfdi_status,
423 generation_start);
424 copy[0].length = sizeof(status->generation_start);
425 /* DMA the rest of the structure (excluding the generations). This
426 * assumes that the non-generation portion of vfdi_status is in
427 * one chunk starting at the version member.
428 */
429 data_offset = offsetof(struct vfdi_status, version);
430 copy[1].from_rid = efx->pci_dev->devfn;
Shradha Shah2dc313e2014-11-05 12:16:18 +0000431 copy[1].from_addr = nic_data->vfdi_status.dma_addr + data_offset;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000432 copy[1].to_rid = vf->pci_rid;
433 copy[1].to_addr = vf->status_addr + data_offset;
434 copy[1].length = status->length - data_offset;
435
436 /* Copy the peer pages */
437 pos = 2;
438 count = 0;
Shradha Shah2dc313e2014-11-05 12:16:18 +0000439 list_for_each_entry(epp, &nic_data->local_page_list, link) {
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000440 if (count == vf->peer_page_count) {
441 /* The VF driver will know they need to provide more
442 * pages because peer_addr_count is too large.
443 */
444 break;
445 }
446 copy[pos].from_buf = NULL;
447 copy[pos].from_rid = efx->pci_dev->devfn;
448 copy[pos].from_addr = epp->addr;
449 copy[pos].to_rid = vf->pci_rid;
450 copy[pos].to_addr = vf->peer_page_addrs[count];
451 copy[pos].length = EFX_PAGE_SIZE;
452
453 if (++pos == ARRAY_SIZE(copy)) {
Shradha Shah327c6852014-11-05 12:16:32 +0000454 efx_siena_sriov_memcpy(efx, copy, ARRAY_SIZE(copy));
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000455 pos = 0;
456 }
457 ++count;
458 }
459
460 /* Write generation_end */
461 copy[pos].from_buf = &status->generation_end;
462 copy[pos].to_rid = vf->pci_rid;
463 copy[pos].to_addr = vf->status_addr + offsetof(struct vfdi_status,
464 generation_end);
465 copy[pos].length = sizeof(status->generation_end);
Shradha Shah327c6852014-11-05 12:16:32 +0000466 efx_siena_sriov_memcpy(efx, copy, pos + 1);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000467
468 /* Notify the guest */
469 EFX_POPULATE_QWORD_3(event,
470 FSF_AZ_EV_CODE, FSE_CZ_EV_CODE_USER_EV,
471 VFDI_EV_SEQ, (vf->msg_seqno & 0xff),
472 VFDI_EV_TYPE, VFDI_EV_TYPE_STATUS);
473 ++vf->msg_seqno;
Ben Hutchings86094f72013-08-21 19:51:04 +0100474 efx_farch_generate_event(efx,
475 EFX_VI_BASE + vf->index * efx_vf_size(efx),
476 &event);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000477}
478
Shradha Shah327c6852014-11-05 12:16:32 +0000479static void efx_siena_sriov_bufs(struct efx_nic *efx, unsigned offset,
480 u64 *addr, unsigned count)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000481{
482 efx_qword_t buf;
483 unsigned pos;
484
485 for (pos = 0; pos < count; ++pos) {
486 EFX_POPULATE_QWORD_3(buf,
487 FRF_AZ_BUF_ADR_REGION, 0,
488 FRF_AZ_BUF_ADR_FBUF,
489 addr ? addr[pos] >> 12 : 0,
490 FRF_AZ_BUF_OWNER_ID_FBUF, 0);
491 efx_sram_writeq(efx, efx->membase + FR_BZ_BUF_FULL_TBL,
492 &buf, offset + pos);
493 }
494}
495
496static bool bad_vf_index(struct efx_nic *efx, unsigned index)
497{
498 return index >= efx_vf_size(efx);
499}
500
501static bool bad_buf_count(unsigned buf_count, unsigned max_entry_count)
502{
503 unsigned max_buf_count = max_entry_count *
504 sizeof(efx_qword_t) / EFX_BUF_SIZE;
505
506 return ((buf_count & (buf_count - 1)) || buf_count > max_buf_count);
507}
508
509/* Check that VI specified by per-port index belongs to a VF.
510 * Optionally set VF index and VI index within the VF.
511 */
512static bool map_vi_index(struct efx_nic *efx, unsigned abs_index,
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100513 struct siena_vf **vf_out, unsigned *rel_index_out)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000514{
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100515 struct siena_nic_data *nic_data = efx->nic_data;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000516 unsigned vf_i;
517
518 if (abs_index < EFX_VI_BASE)
519 return true;
Robert Stonehouse2c61c8a2012-03-02 17:20:00 +0000520 vf_i = (abs_index - EFX_VI_BASE) / efx_vf_size(efx);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000521 if (vf_i >= efx->vf_init_count)
522 return true;
523
524 if (vf_out)
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100525 *vf_out = nic_data->vf + vf_i;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000526 if (rel_index_out)
527 *rel_index_out = abs_index % efx_vf_size(efx);
528 return false;
529}
530
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100531static int efx_vfdi_init_evq(struct siena_vf *vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000532{
533 struct efx_nic *efx = vf->efx;
534 struct vfdi_req *req = vf->buf.addr;
535 unsigned vf_evq = req->u.init_evq.index;
536 unsigned buf_count = req->u.init_evq.buf_count;
537 unsigned abs_evq = abs_index(vf, vf_evq);
538 unsigned buftbl = EFX_BUFTBL_EVQ_BASE(vf, vf_evq);
539 efx_oword_t reg;
540
541 if (bad_vf_index(efx, vf_evq) ||
542 bad_buf_count(buf_count, EFX_MAX_VF_EVQ_SIZE)) {
543 if (net_ratelimit())
544 netif_err(efx, hw, efx->net_dev,
545 "ERROR: Invalid INIT_EVQ from %s: evq %d bufs %d\n",
546 vf->pci_name, vf_evq, buf_count);
547 return VFDI_RC_EINVAL;
548 }
549
Shradha Shah327c6852014-11-05 12:16:32 +0000550 efx_siena_sriov_bufs(efx, buftbl, req->u.init_evq.addr, buf_count);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000551
552 EFX_POPULATE_OWORD_3(reg,
553 FRF_CZ_TIMER_Q_EN, 1,
554 FRF_CZ_HOST_NOTIFY_MODE, 0,
555 FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS);
556 efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL, abs_evq);
557 EFX_POPULATE_OWORD_3(reg,
558 FRF_AZ_EVQ_EN, 1,
559 FRF_AZ_EVQ_SIZE, __ffs(buf_count),
560 FRF_AZ_EVQ_BUF_BASE_ID, buftbl);
561 efx_writeo_table(efx, &reg, FR_BZ_EVQ_PTR_TBL, abs_evq);
562
563 if (vf_evq == 0) {
564 memcpy(vf->evq0_addrs, req->u.init_evq.addr,
565 buf_count * sizeof(u64));
566 vf->evq0_count = buf_count;
567 }
568
569 return VFDI_RC_SUCCESS;
570}
571
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100572static int efx_vfdi_init_rxq(struct siena_vf *vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000573{
574 struct efx_nic *efx = vf->efx;
575 struct vfdi_req *req = vf->buf.addr;
576 unsigned vf_rxq = req->u.init_rxq.index;
577 unsigned vf_evq = req->u.init_rxq.evq;
578 unsigned buf_count = req->u.init_rxq.buf_count;
579 unsigned buftbl = EFX_BUFTBL_RXQ_BASE(vf, vf_rxq);
580 unsigned label;
581 efx_oword_t reg;
582
583 if (bad_vf_index(efx, vf_evq) || bad_vf_index(efx, vf_rxq) ||
Ben Hutchings45078372012-09-19 02:53:34 +0100584 vf_rxq >= VF_MAX_RX_QUEUES ||
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000585 bad_buf_count(buf_count, EFX_MAX_DMAQ_SIZE)) {
586 if (net_ratelimit())
587 netif_err(efx, hw, efx->net_dev,
588 "ERROR: Invalid INIT_RXQ from %s: rxq %d evq %d "
589 "buf_count %d\n", vf->pci_name, vf_rxq,
590 vf_evq, buf_count);
591 return VFDI_RC_EINVAL;
592 }
593 if (__test_and_set_bit(req->u.init_rxq.index, vf->rxq_mask))
594 ++vf->rxq_count;
Shradha Shah327c6852014-11-05 12:16:32 +0000595 efx_siena_sriov_bufs(efx, buftbl, req->u.init_rxq.addr, buf_count);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000596
597 label = req->u.init_rxq.label & EFX_FIELD_MASK(FRF_AZ_RX_DESCQ_LABEL);
598 EFX_POPULATE_OWORD_6(reg,
599 FRF_AZ_RX_DESCQ_BUF_BASE_ID, buftbl,
600 FRF_AZ_RX_DESCQ_EVQ_ID, abs_index(vf, vf_evq),
601 FRF_AZ_RX_DESCQ_LABEL, label,
602 FRF_AZ_RX_DESCQ_SIZE, __ffs(buf_count),
603 FRF_AZ_RX_DESCQ_JUMBO,
604 !!(req->u.init_rxq.flags &
605 VFDI_RXQ_FLAG_SCATTER_EN),
606 FRF_AZ_RX_DESCQ_EN, 1);
607 efx_writeo_table(efx, &reg, FR_BZ_RX_DESC_PTR_TBL,
608 abs_index(vf, vf_rxq));
609
610 return VFDI_RC_SUCCESS;
611}
612
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100613static int efx_vfdi_init_txq(struct siena_vf *vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000614{
615 struct efx_nic *efx = vf->efx;
616 struct vfdi_req *req = vf->buf.addr;
617 unsigned vf_txq = req->u.init_txq.index;
618 unsigned vf_evq = req->u.init_txq.evq;
619 unsigned buf_count = req->u.init_txq.buf_count;
620 unsigned buftbl = EFX_BUFTBL_TXQ_BASE(vf, vf_txq);
621 unsigned label, eth_filt_en;
622 efx_oword_t reg;
623
624 if (bad_vf_index(efx, vf_evq) || bad_vf_index(efx, vf_txq) ||
625 vf_txq >= vf_max_tx_channels ||
626 bad_buf_count(buf_count, EFX_MAX_DMAQ_SIZE)) {
627 if (net_ratelimit())
628 netif_err(efx, hw, efx->net_dev,
629 "ERROR: Invalid INIT_TXQ from %s: txq %d evq %d "
630 "buf_count %d\n", vf->pci_name, vf_txq,
631 vf_evq, buf_count);
632 return VFDI_RC_EINVAL;
633 }
634
635 mutex_lock(&vf->txq_lock);
636 if (__test_and_set_bit(req->u.init_txq.index, vf->txq_mask))
637 ++vf->txq_count;
638 mutex_unlock(&vf->txq_lock);
Shradha Shah327c6852014-11-05 12:16:32 +0000639 efx_siena_sriov_bufs(efx, buftbl, req->u.init_txq.addr, buf_count);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000640
641 eth_filt_en = vf->tx_filter_mode == VF_TX_FILTER_ON;
642
643 label = req->u.init_txq.label & EFX_FIELD_MASK(FRF_AZ_TX_DESCQ_LABEL);
644 EFX_POPULATE_OWORD_8(reg,
645 FRF_CZ_TX_DPT_Q_MASK_WIDTH, min(efx->vi_scale, 1U),
646 FRF_CZ_TX_DPT_ETH_FILT_EN, eth_filt_en,
647 FRF_AZ_TX_DESCQ_EN, 1,
648 FRF_AZ_TX_DESCQ_BUF_BASE_ID, buftbl,
649 FRF_AZ_TX_DESCQ_EVQ_ID, abs_index(vf, vf_evq),
650 FRF_AZ_TX_DESCQ_LABEL, label,
651 FRF_AZ_TX_DESCQ_SIZE, __ffs(buf_count),
652 FRF_BZ_TX_NON_IP_DROP_DIS, 1);
653 efx_writeo_table(efx, &reg, FR_BZ_TX_DESC_PTR_TBL,
654 abs_index(vf, vf_txq));
655
656 return VFDI_RC_SUCCESS;
657}
658
659/* Returns true when efx_vfdi_fini_all_queues should wake */
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100660static bool efx_vfdi_flush_wake(struct siena_vf *vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000661{
662 /* Ensure that all updates are visible to efx_vfdi_fini_all_queues() */
663 smp_mb();
664
665 return (!vf->txq_count && !vf->rxq_count) ||
666 atomic_read(&vf->rxq_retry_count);
667}
668
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100669static void efx_vfdi_flush_clear(struct siena_vf *vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000670{
671 memset(vf->txq_mask, 0, sizeof(vf->txq_mask));
672 vf->txq_count = 0;
673 memset(vf->rxq_mask, 0, sizeof(vf->rxq_mask));
674 vf->rxq_count = 0;
675 memset(vf->rxq_retry_mask, 0, sizeof(vf->rxq_retry_mask));
676 atomic_set(&vf->rxq_retry_count, 0);
677}
678
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100679static int efx_vfdi_fini_all_queues(struct siena_vf *vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000680{
681 struct efx_nic *efx = vf->efx;
682 efx_oword_t reg;
683 unsigned count = efx_vf_size(efx);
684 unsigned vf_offset = EFX_VI_BASE + vf->index * efx_vf_size(efx);
685 unsigned timeout = HZ;
686 unsigned index, rxqs_count;
Ben Hutchingsc5bb0e92012-09-14 17:31:33 +0100687 MCDI_DECLARE_BUF(inbuf, MC_CMD_FLUSH_RX_QUEUES_IN_LENMAX);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000688 int rc;
689
Ben Hutchings45078372012-09-19 02:53:34 +0100690 BUILD_BUG_ON(VF_MAX_RX_QUEUES >
691 MC_CMD_FLUSH_RX_QUEUES_IN_QID_OFST_MAXNUM);
692
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000693 rtnl_lock();
Ben Hutchingsd5e8cc62012-09-06 16:52:31 +0100694 siena_prepare_flush(efx);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000695 rtnl_unlock();
696
697 /* Flush all the initialized queues */
698 rxqs_count = 0;
699 for (index = 0; index < count; ++index) {
700 if (test_bit(index, vf->txq_mask)) {
701 EFX_POPULATE_OWORD_2(reg,
702 FRF_AZ_TX_FLUSH_DESCQ_CMD, 1,
703 FRF_AZ_TX_FLUSH_DESCQ,
704 vf_offset + index);
705 efx_writeo(efx, &reg, FR_AZ_TX_FLUSH_DESCQ);
706 }
Ben Hutchingsc5bb0e92012-09-14 17:31:33 +0100707 if (test_bit(index, vf->rxq_mask)) {
708 MCDI_SET_ARRAY_DWORD(
709 inbuf, FLUSH_RX_QUEUES_IN_QID_OFST,
710 rxqs_count, vf_offset + index);
711 rxqs_count++;
712 }
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000713 }
714
715 atomic_set(&vf->rxq_retry_count, 0);
716 while (timeout && (vf->rxq_count || vf->txq_count)) {
Ben Hutchingsc5bb0e92012-09-14 17:31:33 +0100717 rc = efx_mcdi_rpc(efx, MC_CMD_FLUSH_RX_QUEUES, inbuf,
718 MC_CMD_FLUSH_RX_QUEUES_IN_LEN(rxqs_count),
719 NULL, 0, NULL);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000720 WARN_ON(rc < 0);
721
722 timeout = wait_event_timeout(vf->flush_waitq,
723 efx_vfdi_flush_wake(vf),
724 timeout);
725 rxqs_count = 0;
726 for (index = 0; index < count; ++index) {
727 if (test_and_clear_bit(index, vf->rxq_retry_mask)) {
728 atomic_dec(&vf->rxq_retry_count);
Ben Hutchingsc5bb0e92012-09-14 17:31:33 +0100729 MCDI_SET_ARRAY_DWORD(
730 inbuf, FLUSH_RX_QUEUES_IN_QID_OFST,
731 rxqs_count, vf_offset + index);
732 rxqs_count++;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000733 }
734 }
735 }
736
737 rtnl_lock();
Ben Hutchingsd5e8cc62012-09-06 16:52:31 +0100738 siena_finish_flush(efx);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000739 rtnl_unlock();
740
741 /* Irrespective of success/failure, fini the queues */
742 EFX_ZERO_OWORD(reg);
743 for (index = 0; index < count; ++index) {
744 efx_writeo_table(efx, &reg, FR_BZ_RX_DESC_PTR_TBL,
745 vf_offset + index);
746 efx_writeo_table(efx, &reg, FR_BZ_TX_DESC_PTR_TBL,
747 vf_offset + index);
748 efx_writeo_table(efx, &reg, FR_BZ_EVQ_PTR_TBL,
749 vf_offset + index);
750 efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL,
751 vf_offset + index);
752 }
Shradha Shah327c6852014-11-05 12:16:32 +0000753 efx_siena_sriov_bufs(efx, vf->buftbl_base, NULL,
754 EFX_VF_BUFTBL_PER_VI * efx_vf_size(efx));
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000755 efx_vfdi_flush_clear(vf);
756
757 vf->evq0_count = 0;
758
759 return timeout ? 0 : VFDI_RC_ETIMEDOUT;
760}
761
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100762static int efx_vfdi_insert_filter(struct siena_vf *vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000763{
764 struct efx_nic *efx = vf->efx;
Shradha Shah2dc313e2014-11-05 12:16:18 +0000765 struct siena_nic_data *nic_data = efx->nic_data;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000766 struct vfdi_req *req = vf->buf.addr;
767 unsigned vf_rxq = req->u.mac_filter.rxq;
768 unsigned flags;
769
770 if (bad_vf_index(efx, vf_rxq) || vf->rx_filtering) {
771 if (net_ratelimit())
772 netif_err(efx, hw, efx->net_dev,
773 "ERROR: Invalid INSERT_FILTER from %s: rxq %d "
774 "flags 0x%x\n", vf->pci_name, vf_rxq,
775 req->u.mac_filter.flags);
776 return VFDI_RC_EINVAL;
777 }
778
779 flags = 0;
780 if (req->u.mac_filter.flags & VFDI_MAC_FILTER_FLAG_RSS)
781 flags |= EFX_FILTER_FLAG_RX_RSS;
782 if (req->u.mac_filter.flags & VFDI_MAC_FILTER_FLAG_SCATTER)
783 flags |= EFX_FILTER_FLAG_RX_SCATTER;
784 vf->rx_filter_flags = flags;
785 vf->rx_filter_qid = vf_rxq;
786 vf->rx_filtering = true;
787
Shradha Shah327c6852014-11-05 12:16:32 +0000788 efx_siena_sriov_reset_rx_filter(vf);
Shradha Shah2dc313e2014-11-05 12:16:18 +0000789 queue_work(vfdi_workqueue, &nic_data->peer_work);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000790
791 return VFDI_RC_SUCCESS;
792}
793
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100794static int efx_vfdi_remove_all_filters(struct siena_vf *vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000795{
Shradha Shah2dc313e2014-11-05 12:16:18 +0000796 struct efx_nic *efx = vf->efx;
797 struct siena_nic_data *nic_data = efx->nic_data;
798
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000799 vf->rx_filtering = false;
Shradha Shah327c6852014-11-05 12:16:32 +0000800 efx_siena_sriov_reset_rx_filter(vf);
Shradha Shah2dc313e2014-11-05 12:16:18 +0000801 queue_work(vfdi_workqueue, &nic_data->peer_work);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000802
803 return VFDI_RC_SUCCESS;
804}
805
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100806static int efx_vfdi_set_status_page(struct siena_vf *vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000807{
808 struct efx_nic *efx = vf->efx;
Shradha Shah2dc313e2014-11-05 12:16:18 +0000809 struct siena_nic_data *nic_data = efx->nic_data;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000810 struct vfdi_req *req = vf->buf.addr;
Ben Hutchings01cb5432012-02-21 02:57:33 +0000811 u64 page_count = req->u.set_status_page.peer_page_count;
812 u64 max_page_count =
813 (EFX_PAGE_SIZE -
814 offsetof(struct vfdi_req, u.set_status_page.peer_page_addr[0]))
815 / sizeof(req->u.set_status_page.peer_page_addr[0]);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000816
Ben Hutchings01cb5432012-02-21 02:57:33 +0000817 if (!req->u.set_status_page.dma_addr || page_count > max_page_count) {
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000818 if (net_ratelimit())
819 netif_err(efx, hw, efx->net_dev,
820 "ERROR: Invalid SET_STATUS_PAGE from %s\n",
821 vf->pci_name);
822 return VFDI_RC_EINVAL;
823 }
824
Shradha Shah2dc313e2014-11-05 12:16:18 +0000825 mutex_lock(&nic_data->local_lock);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000826 mutex_lock(&vf->status_lock);
827 vf->status_addr = req->u.set_status_page.dma_addr;
828
829 kfree(vf->peer_page_addrs);
830 vf->peer_page_addrs = NULL;
831 vf->peer_page_count = 0;
832
833 if (page_count) {
834 vf->peer_page_addrs = kcalloc(page_count, sizeof(u64),
835 GFP_KERNEL);
836 if (vf->peer_page_addrs) {
837 memcpy(vf->peer_page_addrs,
838 req->u.set_status_page.peer_page_addr,
839 page_count * sizeof(u64));
840 vf->peer_page_count = page_count;
841 }
842 }
843
Shradha Shah327c6852014-11-05 12:16:32 +0000844 __efx_siena_sriov_push_vf_status(vf);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000845 mutex_unlock(&vf->status_lock);
Shradha Shah2dc313e2014-11-05 12:16:18 +0000846 mutex_unlock(&nic_data->local_lock);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000847
848 return VFDI_RC_SUCCESS;
849}
850
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100851static int efx_vfdi_clear_status_page(struct siena_vf *vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000852{
853 mutex_lock(&vf->status_lock);
854 vf->status_addr = 0;
855 mutex_unlock(&vf->status_lock);
856
857 return VFDI_RC_SUCCESS;
858}
859
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100860typedef int (*efx_vfdi_op_t)(struct siena_vf *vf);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000861
862static const efx_vfdi_op_t vfdi_ops[VFDI_OP_LIMIT] = {
863 [VFDI_OP_INIT_EVQ] = efx_vfdi_init_evq,
864 [VFDI_OP_INIT_TXQ] = efx_vfdi_init_txq,
865 [VFDI_OP_INIT_RXQ] = efx_vfdi_init_rxq,
866 [VFDI_OP_FINI_ALL_QUEUES] = efx_vfdi_fini_all_queues,
867 [VFDI_OP_INSERT_FILTER] = efx_vfdi_insert_filter,
868 [VFDI_OP_REMOVE_ALL_FILTERS] = efx_vfdi_remove_all_filters,
869 [VFDI_OP_SET_STATUS_PAGE] = efx_vfdi_set_status_page,
870 [VFDI_OP_CLEAR_STATUS_PAGE] = efx_vfdi_clear_status_page,
871};
872
Shradha Shah327c6852014-11-05 12:16:32 +0000873static void efx_siena_sriov_vfdi(struct work_struct *work)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000874{
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100875 struct siena_vf *vf = container_of(work, struct siena_vf, req);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000876 struct efx_nic *efx = vf->efx;
877 struct vfdi_req *req = vf->buf.addr;
878 struct efx_memcpy_req copy[2];
879 int rc;
880
881 /* Copy this page into the local address space */
882 memset(copy, '\0', sizeof(copy));
883 copy[0].from_rid = vf->pci_rid;
884 copy[0].from_addr = vf->req_addr;
885 copy[0].to_rid = efx->pci_dev->devfn;
886 copy[0].to_addr = vf->buf.dma_addr;
887 copy[0].length = EFX_PAGE_SIZE;
Shradha Shah327c6852014-11-05 12:16:32 +0000888 rc = efx_siena_sriov_memcpy(efx, copy, 1);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000889 if (rc) {
890 /* If we can't get the request, we can't reply to the caller */
891 if (net_ratelimit())
892 netif_err(efx, hw, efx->net_dev,
893 "ERROR: Unable to fetch VFDI request from %s rc %d\n",
894 vf->pci_name, -rc);
895 vf->busy = false;
896 return;
897 }
898
899 if (req->op < VFDI_OP_LIMIT && vfdi_ops[req->op] != NULL) {
900 rc = vfdi_ops[req->op](vf);
901 if (rc == 0) {
902 netif_dbg(efx, hw, efx->net_dev,
903 "vfdi request %d from %s ok\n",
904 req->op, vf->pci_name);
905 }
906 } else {
907 netif_dbg(efx, hw, efx->net_dev,
908 "ERROR: Unrecognised request %d from VF %s addr "
909 "%llx\n", req->op, vf->pci_name,
910 (unsigned long long)vf->req_addr);
911 rc = VFDI_RC_EOPNOTSUPP;
912 }
913
914 /* Allow subsequent VF requests */
915 vf->busy = false;
916 smp_wmb();
917
918 /* Respond to the request */
919 req->rc = rc;
920 req->op = VFDI_OP_RESPONSE;
921
922 memset(copy, '\0', sizeof(copy));
923 copy[0].from_buf = &req->rc;
924 copy[0].to_rid = vf->pci_rid;
925 copy[0].to_addr = vf->req_addr + offsetof(struct vfdi_req, rc);
926 copy[0].length = sizeof(req->rc);
927 copy[1].from_buf = &req->op;
928 copy[1].to_rid = vf->pci_rid;
929 copy[1].to_addr = vf->req_addr + offsetof(struct vfdi_req, op);
930 copy[1].length = sizeof(req->op);
931
Shradha Shah327c6852014-11-05 12:16:32 +0000932 (void)efx_siena_sriov_memcpy(efx, copy, ARRAY_SIZE(copy));
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000933}
934
935
936
937/* After a reset the event queues inside the guests no longer exist. Fill the
938 * event ring in guest memory with VFDI reset events, then (re-initialise) the
939 * event queue to raise an interrupt. The guest driver will then recover.
940 */
Daniel Pieczkobf3d0152015-05-06 00:55:36 +0100941
942static void efx_siena_sriov_reset_vf(struct siena_vf *vf,
Shradha Shah327c6852014-11-05 12:16:32 +0000943 struct efx_buffer *buffer)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000944{
945 struct efx_nic *efx = vf->efx;
946 struct efx_memcpy_req copy_req[4];
947 efx_qword_t event;
948 unsigned int pos, count, k, buftbl, abs_evq;
949 efx_oword_t reg;
950 efx_dword_t ptr;
951 int rc;
952
953 BUG_ON(buffer->len != EFX_PAGE_SIZE);
954
955 if (!vf->evq0_count)
956 return;
957 BUG_ON(vf->evq0_count & (vf->evq0_count - 1));
958
959 mutex_lock(&vf->status_lock);
960 EFX_POPULATE_QWORD_3(event,
961 FSF_AZ_EV_CODE, FSE_CZ_EV_CODE_USER_EV,
962 VFDI_EV_SEQ, vf->msg_seqno,
963 VFDI_EV_TYPE, VFDI_EV_TYPE_RESET);
964 vf->msg_seqno++;
965 for (pos = 0; pos < EFX_PAGE_SIZE; pos += sizeof(event))
966 memcpy(buffer->addr + pos, &event, sizeof(event));
967
968 for (pos = 0; pos < vf->evq0_count; pos += count) {
969 count = min_t(unsigned, vf->evq0_count - pos,
970 ARRAY_SIZE(copy_req));
971 for (k = 0; k < count; k++) {
972 copy_req[k].from_buf = NULL;
973 copy_req[k].from_rid = efx->pci_dev->devfn;
974 copy_req[k].from_addr = buffer->dma_addr;
975 copy_req[k].to_rid = vf->pci_rid;
976 copy_req[k].to_addr = vf->evq0_addrs[pos + k];
977 copy_req[k].length = EFX_PAGE_SIZE;
978 }
Shradha Shah327c6852014-11-05 12:16:32 +0000979 rc = efx_siena_sriov_memcpy(efx, copy_req, count);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000980 if (rc) {
981 if (net_ratelimit())
982 netif_err(efx, hw, efx->net_dev,
983 "ERROR: Unable to notify %s of reset"
984 ": %d\n", vf->pci_name, -rc);
985 break;
986 }
987 }
988
989 /* Reinitialise, arm and trigger evq0 */
990 abs_evq = abs_index(vf, 0);
991 buftbl = EFX_BUFTBL_EVQ_BASE(vf, 0);
Shradha Shah327c6852014-11-05 12:16:32 +0000992 efx_siena_sriov_bufs(efx, buftbl, vf->evq0_addrs, vf->evq0_count);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000993
994 EFX_POPULATE_OWORD_3(reg,
995 FRF_CZ_TIMER_Q_EN, 1,
996 FRF_CZ_HOST_NOTIFY_MODE, 0,
997 FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS);
998 efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL, abs_evq);
999 EFX_POPULATE_OWORD_3(reg,
1000 FRF_AZ_EVQ_EN, 1,
1001 FRF_AZ_EVQ_SIZE, __ffs(vf->evq0_count),
1002 FRF_AZ_EVQ_BUF_BASE_ID, buftbl);
1003 efx_writeo_table(efx, &reg, FR_BZ_EVQ_PTR_TBL, abs_evq);
1004 EFX_POPULATE_DWORD_1(ptr, FRF_AZ_EVQ_RPTR, 0);
Ben Hutchings778cdaf2012-09-18 01:56:50 +01001005 efx_writed(efx, &ptr, FR_BZ_EVQ_RPTR + FR_BZ_EVQ_RPTR_STEP * abs_evq);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001006
1007 mutex_unlock(&vf->status_lock);
1008}
1009
Shradha Shah327c6852014-11-05 12:16:32 +00001010static void efx_siena_sriov_reset_vf_work(struct work_struct *work)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001011{
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001012 struct siena_vf *vf = container_of(work, struct siena_vf, req);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001013 struct efx_nic *efx = vf->efx;
1014 struct efx_buffer buf;
1015
Ben Hutchings0d19a542012-09-18 21:59:52 +01001016 if (!efx_nic_alloc_buffer(efx, &buf, EFX_PAGE_SIZE, GFP_NOIO)) {
Shradha Shah327c6852014-11-05 12:16:32 +00001017 efx_siena_sriov_reset_vf(vf, &buf);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001018 efx_nic_free_buffer(efx, &buf);
1019 }
1020}
1021
Shradha Shah327c6852014-11-05 12:16:32 +00001022static void efx_siena_sriov_handle_no_channel(struct efx_nic *efx)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001023{
1024 netif_err(efx, drv, efx->net_dev,
1025 "ERROR: IOV requires MSI-X and 1 additional interrupt"
1026 "vector. IOV disabled\n");
1027 efx->vf_count = 0;
1028}
1029
Shradha Shah327c6852014-11-05 12:16:32 +00001030static int efx_siena_sriov_probe_channel(struct efx_channel *channel)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001031{
Shradha Shah2dc313e2014-11-05 12:16:18 +00001032 struct siena_nic_data *nic_data = channel->efx->nic_data;
1033 nic_data->vfdi_channel = channel;
1034
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001035 return 0;
1036}
1037
1038static void
Shradha Shah327c6852014-11-05 12:16:32 +00001039efx_siena_sriov_get_channel_name(struct efx_channel *channel,
1040 char *buf, size_t len)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001041{
1042 snprintf(buf, len, "%s-iov", channel->efx->name);
1043}
1044
Shradha Shah327c6852014-11-05 12:16:32 +00001045static const struct efx_channel_type efx_siena_sriov_channel_type = {
1046 .handle_no_channel = efx_siena_sriov_handle_no_channel,
1047 .pre_probe = efx_siena_sriov_probe_channel,
Ben Hutchings726ba0e2012-10-02 01:43:45 +01001048 .post_remove = efx_channel_dummy_op_void,
Shradha Shah327c6852014-11-05 12:16:32 +00001049 .get_name = efx_siena_sriov_get_channel_name,
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001050 /* no copy operation; channel must not be reallocated */
1051 .keep_eventq = true,
1052};
1053
Shradha Shah327c6852014-11-05 12:16:32 +00001054void efx_siena_sriov_probe(struct efx_nic *efx)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001055{
1056 unsigned count;
1057
1058 if (!max_vfs)
1059 return;
1060
Shradha Shah327c6852014-11-05 12:16:32 +00001061 if (efx_siena_sriov_cmd(efx, false, &efx->vi_scale, &count))
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001062 return;
1063 if (count > 0 && count > max_vfs)
1064 count = max_vfs;
1065
1066 /* efx_nic_dimension_resources() will reduce vf_count as appopriate */
1067 efx->vf_count = count;
1068
Shradha Shah327c6852014-11-05 12:16:32 +00001069 efx->extra_channel_type[EFX_EXTRA_CHANNEL_IOV] = &efx_siena_sriov_channel_type;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001070}
1071
1072/* Copy the list of individual addresses into the vfdi_status.peers
Joe Perchesdbedd442015-03-06 20:49:12 -08001073 * array and auxiliary pages, protected by %local_lock. Drop that lock
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001074 * and then broadcast the address list to every VF.
1075 */
Shradha Shah327c6852014-11-05 12:16:32 +00001076static void efx_siena_sriov_peer_work(struct work_struct *data)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001077{
Shradha Shah2dc313e2014-11-05 12:16:18 +00001078 struct siena_nic_data *nic_data = container_of(data,
1079 struct siena_nic_data,
1080 peer_work);
1081 struct efx_nic *efx = nic_data->efx;
1082 struct vfdi_status *vfdi_status = nic_data->vfdi_status.addr;
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001083 struct siena_vf *vf;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001084 struct efx_local_addr *local_addr;
1085 struct vfdi_endpoint *peer;
1086 struct efx_endpoint_page *epp;
1087 struct list_head pages;
1088 unsigned int peer_space;
1089 unsigned int peer_count;
1090 unsigned int pos;
1091
Shradha Shah2dc313e2014-11-05 12:16:18 +00001092 mutex_lock(&nic_data->local_lock);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001093
1094 /* Move the existing peer pages off %local_page_list */
1095 INIT_LIST_HEAD(&pages);
Shradha Shah2dc313e2014-11-05 12:16:18 +00001096 list_splice_tail_init(&nic_data->local_page_list, &pages);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001097
1098 /* Populate the VF addresses starting from entry 1 (entry 0 is
1099 * the PF address)
1100 */
1101 peer = vfdi_status->peers + 1;
1102 peer_space = ARRAY_SIZE(vfdi_status->peers) - 1;
1103 peer_count = 1;
1104 for (pos = 0; pos < efx->vf_count; ++pos) {
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001105 vf = nic_data->vf + pos;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001106
1107 mutex_lock(&vf->status_lock);
1108 if (vf->rx_filtering && !is_zero_ether_addr(vf->addr.mac_addr)) {
1109 *peer++ = vf->addr;
1110 ++peer_count;
1111 --peer_space;
1112 BUG_ON(peer_space == 0);
1113 }
1114 mutex_unlock(&vf->status_lock);
1115 }
1116
1117 /* Fill the remaining addresses */
Shradha Shah2dc313e2014-11-05 12:16:18 +00001118 list_for_each_entry(local_addr, &nic_data->local_addr_list, link) {
Edward Creecd84ff42014-03-07 18:27:41 +00001119 ether_addr_copy(peer->mac_addr, local_addr->addr);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001120 peer->tci = 0;
1121 ++peer;
1122 ++peer_count;
1123 if (--peer_space == 0) {
1124 if (list_empty(&pages)) {
1125 epp = kmalloc(sizeof(*epp), GFP_KERNEL);
1126 if (!epp)
1127 break;
1128 epp->ptr = dma_alloc_coherent(
1129 &efx->pci_dev->dev, EFX_PAGE_SIZE,
1130 &epp->addr, GFP_KERNEL);
1131 if (!epp->ptr) {
1132 kfree(epp);
1133 break;
1134 }
1135 } else {
1136 epp = list_first_entry(
1137 &pages, struct efx_endpoint_page, link);
1138 list_del(&epp->link);
1139 }
1140
Shradha Shah2dc313e2014-11-05 12:16:18 +00001141 list_add_tail(&epp->link, &nic_data->local_page_list);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001142 peer = (struct vfdi_endpoint *)epp->ptr;
1143 peer_space = EFX_PAGE_SIZE / sizeof(struct vfdi_endpoint);
1144 }
1145 }
1146 vfdi_status->peer_count = peer_count;
Shradha Shah2dc313e2014-11-05 12:16:18 +00001147 mutex_unlock(&nic_data->local_lock);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001148
1149 /* Free any now unused endpoint pages */
1150 while (!list_empty(&pages)) {
1151 epp = list_first_entry(
1152 &pages, struct efx_endpoint_page, link);
1153 list_del(&epp->link);
1154 dma_free_coherent(&efx->pci_dev->dev, EFX_PAGE_SIZE,
1155 epp->ptr, epp->addr);
1156 kfree(epp);
1157 }
1158
1159 /* Finally, push the pages */
1160 for (pos = 0; pos < efx->vf_count; ++pos) {
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001161 vf = nic_data->vf + pos;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001162
1163 mutex_lock(&vf->status_lock);
1164 if (vf->status_addr)
Shradha Shah327c6852014-11-05 12:16:32 +00001165 __efx_siena_sriov_push_vf_status(vf);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001166 mutex_unlock(&vf->status_lock);
1167 }
1168}
1169
Shradha Shah327c6852014-11-05 12:16:32 +00001170static void efx_siena_sriov_free_local(struct efx_nic *efx)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001171{
Shradha Shah2dc313e2014-11-05 12:16:18 +00001172 struct siena_nic_data *nic_data = efx->nic_data;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001173 struct efx_local_addr *local_addr;
1174 struct efx_endpoint_page *epp;
1175
Shradha Shah2dc313e2014-11-05 12:16:18 +00001176 while (!list_empty(&nic_data->local_addr_list)) {
1177 local_addr = list_first_entry(&nic_data->local_addr_list,
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001178 struct efx_local_addr, link);
1179 list_del(&local_addr->link);
1180 kfree(local_addr);
1181 }
1182
Shradha Shah2dc313e2014-11-05 12:16:18 +00001183 while (!list_empty(&nic_data->local_page_list)) {
1184 epp = list_first_entry(&nic_data->local_page_list,
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001185 struct efx_endpoint_page, link);
1186 list_del(&epp->link);
1187 dma_free_coherent(&efx->pci_dev->dev, EFX_PAGE_SIZE,
1188 epp->ptr, epp->addr);
1189 kfree(epp);
1190 }
1191}
1192
Shradha Shah327c6852014-11-05 12:16:32 +00001193static int efx_siena_sriov_vf_alloc(struct efx_nic *efx)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001194{
1195 unsigned index;
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001196 struct siena_vf *vf;
1197 struct siena_nic_data *nic_data = efx->nic_data;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001198
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001199 nic_data->vf = kcalloc(efx->vf_count, sizeof(*nic_data->vf),
1200 GFP_KERNEL);
1201 if (!nic_data->vf)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001202 return -ENOMEM;
1203
1204 for (index = 0; index < efx->vf_count; ++index) {
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001205 vf = nic_data->vf + index;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001206
1207 vf->efx = efx;
1208 vf->index = index;
1209 vf->rx_filter_id = -1;
1210 vf->tx_filter_mode = VF_TX_FILTER_AUTO;
1211 vf->tx_filter_id = -1;
Shradha Shah327c6852014-11-05 12:16:32 +00001212 INIT_WORK(&vf->req, efx_siena_sriov_vfdi);
1213 INIT_WORK(&vf->reset_work, efx_siena_sriov_reset_vf_work);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001214 init_waitqueue_head(&vf->flush_waitq);
1215 mutex_init(&vf->status_lock);
1216 mutex_init(&vf->txq_lock);
1217 }
1218
1219 return 0;
1220}
1221
Shradha Shah327c6852014-11-05 12:16:32 +00001222static void efx_siena_sriov_vfs_fini(struct efx_nic *efx)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001223{
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001224 struct siena_nic_data *nic_data = efx->nic_data;
1225 struct siena_vf *vf;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001226 unsigned int pos;
1227
1228 for (pos = 0; pos < efx->vf_count; ++pos) {
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001229 vf = nic_data->vf + pos;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001230
1231 efx_nic_free_buffer(efx, &vf->buf);
1232 kfree(vf->peer_page_addrs);
1233 vf->peer_page_addrs = NULL;
1234 vf->peer_page_count = 0;
1235
1236 vf->evq0_count = 0;
1237 }
1238}
1239
Shradha Shah327c6852014-11-05 12:16:32 +00001240static int efx_siena_sriov_vfs_init(struct efx_nic *efx)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001241{
1242 struct pci_dev *pci_dev = efx->pci_dev;
Shradha Shah2dc313e2014-11-05 12:16:18 +00001243 struct siena_nic_data *nic_data = efx->nic_data;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001244 unsigned index, devfn, sriov, buftbl_base;
1245 u16 offset, stride;
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001246 struct siena_vf *vf;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001247 int rc;
1248
1249 sriov = pci_find_ext_capability(pci_dev, PCI_EXT_CAP_ID_SRIOV);
1250 if (!sriov)
1251 return -ENOENT;
1252
1253 pci_read_config_word(pci_dev, sriov + PCI_SRIOV_VF_OFFSET, &offset);
1254 pci_read_config_word(pci_dev, sriov + PCI_SRIOV_VF_STRIDE, &stride);
1255
Shradha Shah2dc313e2014-11-05 12:16:18 +00001256 buftbl_base = nic_data->vf_buftbl_base;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001257 devfn = pci_dev->devfn + offset;
1258 for (index = 0; index < efx->vf_count; ++index) {
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001259 vf = nic_data->vf + index;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001260
1261 /* Reserve buffer entries */
1262 vf->buftbl_base = buftbl_base;
1263 buftbl_base += EFX_VF_BUFTBL_PER_VI * efx_vf_size(efx);
1264
1265 vf->pci_rid = devfn;
1266 snprintf(vf->pci_name, sizeof(vf->pci_name),
1267 "%04x:%02x:%02x.%d",
1268 pci_domain_nr(pci_dev->bus), pci_dev->bus->number,
1269 PCI_SLOT(devfn), PCI_FUNC(devfn));
1270
Ben Hutchings0d19a542012-09-18 21:59:52 +01001271 rc = efx_nic_alloc_buffer(efx, &vf->buf, EFX_PAGE_SIZE,
1272 GFP_KERNEL);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001273 if (rc)
1274 goto fail;
1275
1276 devfn += stride;
1277 }
1278
1279 return 0;
1280
1281fail:
Shradha Shah327c6852014-11-05 12:16:32 +00001282 efx_siena_sriov_vfs_fini(efx);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001283 return rc;
1284}
1285
Shradha Shah327c6852014-11-05 12:16:32 +00001286int efx_siena_sriov_init(struct efx_nic *efx)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001287{
1288 struct net_device *net_dev = efx->net_dev;
Shradha Shah2dc313e2014-11-05 12:16:18 +00001289 struct siena_nic_data *nic_data = efx->nic_data;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001290 struct vfdi_status *vfdi_status;
1291 int rc;
1292
1293 /* Ensure there's room for vf_channel */
1294 BUILD_BUG_ON(EFX_MAX_CHANNELS + 1 >= EFX_VI_BASE);
1295 /* Ensure that VI_BASE is aligned on VI_SCALE */
1296 BUILD_BUG_ON(EFX_VI_BASE & ((1 << EFX_VI_SCALE_MAX) - 1));
1297
1298 if (efx->vf_count == 0)
1299 return 0;
1300
Shradha Shah327c6852014-11-05 12:16:32 +00001301 rc = efx_siena_sriov_cmd(efx, true, NULL, NULL);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001302 if (rc)
1303 goto fail_cmd;
1304
Shradha Shah2dc313e2014-11-05 12:16:18 +00001305 rc = efx_nic_alloc_buffer(efx, &nic_data->vfdi_status,
1306 sizeof(*vfdi_status), GFP_KERNEL);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001307 if (rc)
1308 goto fail_status;
Shradha Shah2dc313e2014-11-05 12:16:18 +00001309 vfdi_status = nic_data->vfdi_status.addr;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001310 memset(vfdi_status, 0, sizeof(*vfdi_status));
1311 vfdi_status->version = 1;
1312 vfdi_status->length = sizeof(*vfdi_status);
1313 vfdi_status->max_tx_channels = vf_max_tx_channels;
1314 vfdi_status->vi_scale = efx->vi_scale;
1315 vfdi_status->rss_rxq_count = efx->rss_spread;
1316 vfdi_status->peer_count = 1 + efx->vf_count;
1317 vfdi_status->timer_quantum_ns = efx->timer_quantum_ns;
1318
Shradha Shah327c6852014-11-05 12:16:32 +00001319 rc = efx_siena_sriov_vf_alloc(efx);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001320 if (rc)
1321 goto fail_alloc;
1322
Shradha Shah2dc313e2014-11-05 12:16:18 +00001323 mutex_init(&nic_data->local_lock);
Shradha Shah327c6852014-11-05 12:16:32 +00001324 INIT_WORK(&nic_data->peer_work, efx_siena_sriov_peer_work);
Shradha Shah2dc313e2014-11-05 12:16:18 +00001325 INIT_LIST_HEAD(&nic_data->local_addr_list);
1326 INIT_LIST_HEAD(&nic_data->local_page_list);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001327
Shradha Shah327c6852014-11-05 12:16:32 +00001328 rc = efx_siena_sriov_vfs_init(efx);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001329 if (rc)
1330 goto fail_vfs;
1331
1332 rtnl_lock();
Edward Creecd84ff42014-03-07 18:27:41 +00001333 ether_addr_copy(vfdi_status->peers[0].mac_addr, net_dev->dev_addr);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001334 efx->vf_init_count = efx->vf_count;
1335 rtnl_unlock();
1336
Shradha Shah327c6852014-11-05 12:16:32 +00001337 efx_siena_sriov_usrev(efx, true);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001338
1339 /* At this point we must be ready to accept VFDI requests */
1340
1341 rc = pci_enable_sriov(efx->pci_dev, efx->vf_count);
1342 if (rc)
1343 goto fail_pci;
1344
1345 netif_info(efx, probe, net_dev,
1346 "enabled SR-IOV for %d VFs, %d VI per VF\n",
1347 efx->vf_count, efx_vf_size(efx));
1348 return 0;
1349
1350fail_pci:
Shradha Shah327c6852014-11-05 12:16:32 +00001351 efx_siena_sriov_usrev(efx, false);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001352 rtnl_lock();
1353 efx->vf_init_count = 0;
1354 rtnl_unlock();
Shradha Shah327c6852014-11-05 12:16:32 +00001355 efx_siena_sriov_vfs_fini(efx);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001356fail_vfs:
Shradha Shah2dc313e2014-11-05 12:16:18 +00001357 cancel_work_sync(&nic_data->peer_work);
Shradha Shah327c6852014-11-05 12:16:32 +00001358 efx_siena_sriov_free_local(efx);
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001359 kfree(nic_data->vf);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001360fail_alloc:
Shradha Shah2dc313e2014-11-05 12:16:18 +00001361 efx_nic_free_buffer(efx, &nic_data->vfdi_status);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001362fail_status:
Shradha Shah327c6852014-11-05 12:16:32 +00001363 efx_siena_sriov_cmd(efx, false, NULL, NULL);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001364fail_cmd:
1365 return rc;
1366}
1367
Shradha Shah327c6852014-11-05 12:16:32 +00001368void efx_siena_sriov_fini(struct efx_nic *efx)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001369{
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001370 struct siena_vf *vf;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001371 unsigned int pos;
Shradha Shah2dc313e2014-11-05 12:16:18 +00001372 struct siena_nic_data *nic_data = efx->nic_data;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001373
1374 if (efx->vf_init_count == 0)
1375 return;
1376
1377 /* Disable all interfaces to reconfiguration */
Shradha Shah2dc313e2014-11-05 12:16:18 +00001378 BUG_ON(nic_data->vfdi_channel->enabled);
Shradha Shah327c6852014-11-05 12:16:32 +00001379 efx_siena_sriov_usrev(efx, false);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001380 rtnl_lock();
1381 efx->vf_init_count = 0;
1382 rtnl_unlock();
1383
1384 /* Flush all reconfiguration work */
1385 for (pos = 0; pos < efx->vf_count; ++pos) {
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001386 vf = nic_data->vf + pos;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001387 cancel_work_sync(&vf->req);
1388 cancel_work_sync(&vf->reset_work);
1389 }
Shradha Shah2dc313e2014-11-05 12:16:18 +00001390 cancel_work_sync(&nic_data->peer_work);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001391
1392 pci_disable_sriov(efx->pci_dev);
1393
1394 /* Tear down back-end state */
Shradha Shah327c6852014-11-05 12:16:32 +00001395 efx_siena_sriov_vfs_fini(efx);
1396 efx_siena_sriov_free_local(efx);
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001397 kfree(nic_data->vf);
Shradha Shah2dc313e2014-11-05 12:16:18 +00001398 efx_nic_free_buffer(efx, &nic_data->vfdi_status);
Shradha Shah327c6852014-11-05 12:16:32 +00001399 efx_siena_sriov_cmd(efx, false, NULL, NULL);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001400}
1401
Shradha Shah327c6852014-11-05 12:16:32 +00001402void efx_siena_sriov_event(struct efx_channel *channel, efx_qword_t *event)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001403{
1404 struct efx_nic *efx = channel->efx;
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001405 struct siena_vf *vf;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001406 unsigned qid, seq, type, data;
1407
1408 qid = EFX_QWORD_FIELD(*event, FSF_CZ_USER_QID);
1409
1410 /* USR_EV_REG_VALUE is dword0, so access the VFDI_EV fields directly */
1411 BUILD_BUG_ON(FSF_CZ_USER_EV_REG_VALUE_LBN != 0);
1412 seq = EFX_QWORD_FIELD(*event, VFDI_EV_SEQ);
1413 type = EFX_QWORD_FIELD(*event, VFDI_EV_TYPE);
1414 data = EFX_QWORD_FIELD(*event, VFDI_EV_DATA);
1415
1416 netif_vdbg(efx, hw, efx->net_dev,
1417 "USR_EV event from qid %d seq 0x%x type %d data 0x%x\n",
1418 qid, seq, type, data);
1419
1420 if (map_vi_index(efx, qid, &vf, NULL))
1421 return;
1422 if (vf->busy)
1423 goto error;
1424
1425 if (type == VFDI_EV_TYPE_REQ_WORD0) {
1426 /* Resynchronise */
1427 vf->req_type = VFDI_EV_TYPE_REQ_WORD0;
1428 vf->req_seqno = seq + 1;
1429 vf->req_addr = 0;
1430 } else if (seq != (vf->req_seqno++ & 0xff) || type != vf->req_type)
1431 goto error;
1432
1433 switch (vf->req_type) {
1434 case VFDI_EV_TYPE_REQ_WORD0:
1435 case VFDI_EV_TYPE_REQ_WORD1:
1436 case VFDI_EV_TYPE_REQ_WORD2:
1437 vf->req_addr |= (u64)data << (vf->req_type << 4);
1438 ++vf->req_type;
1439 return;
1440
1441 case VFDI_EV_TYPE_REQ_WORD3:
1442 vf->req_addr |= (u64)data << 48;
1443 vf->req_type = VFDI_EV_TYPE_REQ_WORD0;
1444 vf->busy = true;
1445 queue_work(vfdi_workqueue, &vf->req);
1446 return;
1447 }
1448
1449error:
1450 if (net_ratelimit())
1451 netif_err(efx, hw, efx->net_dev,
1452 "ERROR: Screaming VFDI request from %s\n",
1453 vf->pci_name);
1454 /* Reset the request and sequence number */
1455 vf->req_type = VFDI_EV_TYPE_REQ_WORD0;
1456 vf->req_seqno = seq + 1;
1457}
1458
Shradha Shah327c6852014-11-05 12:16:32 +00001459void efx_siena_sriov_flr(struct efx_nic *efx, unsigned vf_i)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001460{
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001461 struct siena_nic_data *nic_data = efx->nic_data;
1462 struct siena_vf *vf;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001463
1464 if (vf_i > efx->vf_init_count)
1465 return;
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001466 vf = nic_data->vf + vf_i;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001467 netif_info(efx, hw, efx->net_dev,
1468 "FLR on VF %s\n", vf->pci_name);
1469
1470 vf->status_addr = 0;
1471 efx_vfdi_remove_all_filters(vf);
1472 efx_vfdi_flush_clear(vf);
1473
1474 vf->evq0_count = 0;
1475}
1476
Shradha Shah327c6852014-11-05 12:16:32 +00001477void efx_siena_sriov_mac_address_changed(struct efx_nic *efx)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001478{
Shradha Shah2dc313e2014-11-05 12:16:18 +00001479 struct siena_nic_data *nic_data = efx->nic_data;
1480 struct vfdi_status *vfdi_status = nic_data->vfdi_status.addr;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001481
1482 if (!efx->vf_init_count)
1483 return;
Edward Creecd84ff42014-03-07 18:27:41 +00001484 ether_addr_copy(vfdi_status->peers[0].mac_addr,
1485 efx->net_dev->dev_addr);
Shradha Shah2dc313e2014-11-05 12:16:18 +00001486 queue_work(vfdi_workqueue, &nic_data->peer_work);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001487}
1488
Shradha Shah327c6852014-11-05 12:16:32 +00001489void efx_siena_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001490{
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001491 struct siena_vf *vf;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001492 unsigned queue, qid;
1493
1494 queue = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);
1495 if (map_vi_index(efx, queue, &vf, &qid))
1496 return;
1497 /* Ignore flush completions triggered by an FLR */
1498 if (!test_bit(qid, vf->txq_mask))
1499 return;
1500
1501 __clear_bit(qid, vf->txq_mask);
1502 --vf->txq_count;
1503
1504 if (efx_vfdi_flush_wake(vf))
1505 wake_up(&vf->flush_waitq);
1506}
1507
Shradha Shah327c6852014-11-05 12:16:32 +00001508void efx_siena_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001509{
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001510 struct siena_vf *vf;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001511 unsigned ev_failed, queue, qid;
1512
1513 queue = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
1514 ev_failed = EFX_QWORD_FIELD(*event,
1515 FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
1516 if (map_vi_index(efx, queue, &vf, &qid))
1517 return;
1518 if (!test_bit(qid, vf->rxq_mask))
1519 return;
1520
1521 if (ev_failed) {
1522 set_bit(qid, vf->rxq_retry_mask);
1523 atomic_inc(&vf->rxq_retry_count);
1524 } else {
1525 __clear_bit(qid, vf->rxq_mask);
1526 --vf->rxq_count;
1527 }
1528 if (efx_vfdi_flush_wake(vf))
1529 wake_up(&vf->flush_waitq);
1530}
1531
1532/* Called from napi. Schedule the reset work item */
Shradha Shah327c6852014-11-05 12:16:32 +00001533void efx_siena_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001534{
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001535 struct siena_vf *vf;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001536 unsigned int rel;
1537
1538 if (map_vi_index(efx, dmaq, &vf, &rel))
1539 return;
1540
1541 if (net_ratelimit())
1542 netif_err(efx, hw, efx->net_dev,
1543 "VF %d DMA Q %d reports descriptor fetch error.\n",
1544 vf->index, rel);
1545 queue_work(vfdi_workqueue, &vf->reset_work);
1546}
1547
1548/* Reset all VFs */
Shradha Shah327c6852014-11-05 12:16:32 +00001549void efx_siena_sriov_reset(struct efx_nic *efx)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001550{
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001551 struct siena_nic_data *nic_data = efx->nic_data;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001552 unsigned int vf_i;
1553 struct efx_buffer buf;
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001554 struct siena_vf *vf;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001555
1556 ASSERT_RTNL();
1557
1558 if (efx->vf_init_count == 0)
1559 return;
1560
Shradha Shah327c6852014-11-05 12:16:32 +00001561 efx_siena_sriov_usrev(efx, true);
1562 (void)efx_siena_sriov_cmd(efx, true, NULL, NULL);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001563
Ben Hutchings0d19a542012-09-18 21:59:52 +01001564 if (efx_nic_alloc_buffer(efx, &buf, EFX_PAGE_SIZE, GFP_NOIO))
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001565 return;
1566
1567 for (vf_i = 0; vf_i < efx->vf_init_count; ++vf_i) {
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001568 vf = nic_data->vf + vf_i;
Shradha Shah327c6852014-11-05 12:16:32 +00001569 efx_siena_sriov_reset_vf(vf, &buf);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001570 }
1571
1572 efx_nic_free_buffer(efx, &buf);
1573}
1574
1575int efx_init_sriov(void)
1576{
Shradha Shah327c6852014-11-05 12:16:32 +00001577 /* A single threaded workqueue is sufficient. efx_siena_sriov_vfdi() and
1578 * efx_siena_sriov_peer_work() spend almost all their time sleeping for
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001579 * MCDI to complete anyway
1580 */
1581 vfdi_workqueue = create_singlethread_workqueue("sfc_vfdi");
1582 if (!vfdi_workqueue)
1583 return -ENOMEM;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001584 return 0;
1585}
1586
1587void efx_fini_sriov(void)
1588{
1589 destroy_workqueue(vfdi_workqueue);
1590}
1591
Shradha Shah7fa8d542015-05-06 00:55:13 +01001592int efx_siena_sriov_set_vf_mac(struct efx_nic *efx, int vf_i, u8 *mac)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001593{
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001594 struct siena_nic_data *nic_data = efx->nic_data;
1595 struct siena_vf *vf;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001596
1597 if (vf_i >= efx->vf_init_count)
1598 return -EINVAL;
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001599 vf = nic_data->vf + vf_i;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001600
1601 mutex_lock(&vf->status_lock);
Edward Creecd84ff42014-03-07 18:27:41 +00001602 ether_addr_copy(vf->addr.mac_addr, mac);
Shradha Shah327c6852014-11-05 12:16:32 +00001603 __efx_siena_sriov_update_vf_addr(vf);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001604 mutex_unlock(&vf->status_lock);
1605
1606 return 0;
1607}
1608
Shradha Shah7fa8d542015-05-06 00:55:13 +01001609int efx_siena_sriov_set_vf_vlan(struct efx_nic *efx, int vf_i,
Shradha Shah327c6852014-11-05 12:16:32 +00001610 u16 vlan, u8 qos)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001611{
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001612 struct siena_nic_data *nic_data = efx->nic_data;
1613 struct siena_vf *vf;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001614 u16 tci;
1615
1616 if (vf_i >= efx->vf_init_count)
1617 return -EINVAL;
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001618 vf = nic_data->vf + vf_i;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001619
1620 mutex_lock(&vf->status_lock);
1621 tci = (vlan & VLAN_VID_MASK) | ((qos & 0x7) << VLAN_PRIO_SHIFT);
1622 vf->addr.tci = htons(tci);
Shradha Shah327c6852014-11-05 12:16:32 +00001623 __efx_siena_sriov_update_vf_addr(vf);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001624 mutex_unlock(&vf->status_lock);
1625
1626 return 0;
1627}
1628
Shradha Shah7fa8d542015-05-06 00:55:13 +01001629int efx_siena_sriov_set_vf_spoofchk(struct efx_nic *efx, int vf_i,
Shradha Shah327c6852014-11-05 12:16:32 +00001630 bool spoofchk)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001631{
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001632 struct siena_nic_data *nic_data = efx->nic_data;
1633 struct siena_vf *vf;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001634 int rc;
1635
1636 if (vf_i >= efx->vf_init_count)
1637 return -EINVAL;
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001638 vf = nic_data->vf + vf_i;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001639
1640 mutex_lock(&vf->txq_lock);
1641 if (vf->txq_count == 0) {
1642 vf->tx_filter_mode =
1643 spoofchk ? VF_TX_FILTER_ON : VF_TX_FILTER_OFF;
1644 rc = 0;
1645 } else {
1646 /* This cannot be changed while TX queues are running */
1647 rc = -EBUSY;
1648 }
1649 mutex_unlock(&vf->txq_lock);
1650 return rc;
1651}
1652
Shradha Shah7fa8d542015-05-06 00:55:13 +01001653int efx_siena_sriov_get_vf_config(struct efx_nic *efx, int vf_i,
Shradha Shah327c6852014-11-05 12:16:32 +00001654 struct ifla_vf_info *ivi)
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001655{
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001656 struct siena_nic_data *nic_data = efx->nic_data;
1657 struct siena_vf *vf;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001658 u16 tci;
1659
1660 if (vf_i >= efx->vf_init_count)
1661 return -EINVAL;
Daniel Pieczkobf3d0152015-05-06 00:55:36 +01001662 vf = nic_data->vf + vf_i;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001663
1664 ivi->vf = vf_i;
Edward Creecd84ff42014-03-07 18:27:41 +00001665 ether_addr_copy(ivi->mac, vf->addr.mac_addr);
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04001666 ivi->max_tx_rate = 0;
1667 ivi->min_tx_rate = 0;
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001668 tci = ntohs(vf->addr.tci);
1669 ivi->vlan = tci & VLAN_VID_MASK;
1670 ivi->qos = (tci >> VLAN_PRIO_SHIFT) & 0x7;
1671 ivi->spoofchk = vf->tx_filter_mode == VF_TX_FILTER_ON;
1672
1673 return 0;
1674}
1675
Shradha Shah7fa8d542015-05-06 00:55:13 +01001676bool efx_siena_sriov_wanted(struct efx_nic *efx)
1677{
1678 return efx->vf_count != 0;
1679}