sfc: Enable VF's via a write to the sysfs file sriov_numvfs
[linux-2.6-microblaze.git] / drivers / net / ethernet / sfc / siena_sriov.c
1 /****************************************************************************
2  * Driver for Solarflare network controllers and boards
3  * Copyright 2010-2012 Solarflare Communications Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published
7  * by the Free Software Foundation, incorporated herein by reference.
8  */
9 #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"
18 #include "farch_regs.h"
19 #include "siena_sriov.h"
20 #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
25 /* Maximum number of RX queues supported */
26 #define VF_MAX_RX_QUEUES 63
27
28 /**
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  */
35 enum efx_vf_tx_filter_mode {
36         VF_TX_FILTER_OFF,
37         VF_TX_FILTER_AUTO,
38         VF_TX_FILTER_ON,
39 };
40
41 /**
42  * struct siena_vf - Back-end resource and protocol state for a PCI VF
43  * @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
70  *      efx_siena_sriov_update_vf_addr()
71  * @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  */
87 struct siena_vf {
88         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
125 struct 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  */
145 struct 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  */
157 struct 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 */
177 static unsigned int vf_max_tx_channels = 2;
178 module_param(vf_max_tx_channels, uint, 0444);
179 MODULE_PARM_DESC(vf_max_tx_channels,
180                  "Limit the number of TX channels VFs can use");
181
182 static int max_vfs = -1;
183 module_param(max_vfs, int, 0444);
184 MODULE_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  */
191 static struct workqueue_struct *vfdi_workqueue;
192
193 static unsigned abs_index(struct siena_vf *vf, unsigned index)
194 {
195         return EFX_VI_BASE + vf->index * efx_vf_size(vf->efx) + index;
196 }
197
198 static int efx_siena_sriov_cmd(struct efx_nic *efx, bool enable,
199                                unsigned *vi_scale_out, unsigned *vf_total_out)
200 {
201         MCDI_DECLARE_BUF(inbuf, MC_CMD_SRIOV_IN_LEN);
202         MCDI_DECLARE_BUF(outbuf, MC_CMD_SRIOV_OUT_LEN);
203         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
231 static void efx_siena_sriov_usrev(struct efx_nic *efx, bool enabled)
232 {
233         struct siena_nic_data *nic_data = efx->nic_data;
234         efx_oword_t reg;
235
236         EFX_POPULATE_OWORD_2(reg,
237                              FRF_CZ_USREV_DIS, enabled ? 0 : 1,
238                              FRF_CZ_DFLT_EVQ, nic_data->vfdi_channel->channel);
239         efx_writeo(efx, &reg, FR_CZ_USR_EV_CFG);
240 }
241
242 static int efx_siena_sriov_memcpy(struct efx_nic *efx,
243                                   struct efx_memcpy_req *req,
244                                   unsigned int count)
245 {
246         MCDI_DECLARE_BUF(inbuf, MCDI_CTL_SDU_LEN_MAX_V1);
247         MCDI_DECLARE_STRUCT_PTR(record);
248         unsigned int index, used;
249         u64 from_addr;
250         u32 from_rid;
251         int rc;
252
253         mb();   /* Finish writing source/reading dest before DMA starts */
254
255         if (WARN_ON(count > MC_CMD_MEMCPY_IN_RECORD_MAXNUM))
256                 return -ENOBUFS;
257         used = MC_CMD_MEMCPY_IN_LEN(count);
258
259         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);
263                 MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_TO_RID,
264                                req->to_rid);
265                 MCDI_SET_QWORD(record, MEMCPY_RECORD_TYPEDEF_TO_ADDR,
266                                req->to_addr);
267                 if (req->from_buf == NULL) {
268                         from_rid = req->from_rid;
269                         from_addr = req->from_addr;
270                 } else {
271                         if (WARN_ON(used + req->length >
272                                     MCDI_CTL_SDU_LEN_MAX_V1)) {
273                                 rc = -ENOBUFS;
274                                 goto out;
275                         }
276
277                         from_rid = MC_CMD_MEMCPY_RECORD_TYPEDEF_RID_INLINE;
278                         from_addr = used;
279                         memcpy(_MCDI_PTR(inbuf, used), req->from_buf,
280                                req->length);
281                         used += req->length;
282                 }
283
284                 MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_FROM_RID, from_rid);
285                 MCDI_SET_QWORD(record, MEMCPY_RECORD_TYPEDEF_FROM_ADDR,
286                                from_addr);
287                 MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_LENGTH,
288                                req->length);
289
290                 ++req;
291         }
292
293         rc = efx_mcdi_rpc(efx, MC_CMD_MEMCPY, inbuf, used, NULL, 0, NULL);
294 out:
295         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  */
303 static void efx_siena_sriov_reset_tx_filter(struct siena_vf *vf)
304 {
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 */
347 static void efx_siena_sriov_reset_rx_filter(struct siena_vf *vf)
348 {
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
386 static void __efx_siena_sriov_update_vf_addr(struct siena_vf *vf)
387 {
388         struct efx_nic *efx = vf->efx;
389         struct siena_nic_data *nic_data = efx->nic_data;
390
391         efx_siena_sriov_reset_tx_filter(vf);
392         efx_siena_sriov_reset_rx_filter(vf);
393         queue_work(vfdi_workqueue, &nic_data->peer_work);
394 }
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
399  * efx_siena_sriov_peer_work()
400  */
401 static void __efx_siena_sriov_push_vf_status(struct siena_vf *vf)
402 {
403         struct efx_nic *efx = vf->efx;
404         struct siena_nic_data *nic_data = efx->nic_data;
405         struct vfdi_status *status = nic_data->vfdi_status.addr;
406         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;
431         copy[1].from_addr = nic_data->vfdi_status.dma_addr + data_offset;
432         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;
439         list_for_each_entry(epp, &nic_data->local_page_list, link) {
440                 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)) {
454                         efx_siena_sriov_memcpy(efx, copy, ARRAY_SIZE(copy));
455                         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);
466         efx_siena_sriov_memcpy(efx, copy, pos + 1);
467
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;
474         efx_farch_generate_event(efx,
475                                  EFX_VI_BASE + vf->index * efx_vf_size(efx),
476                                  &event);
477 }
478
479 static void efx_siena_sriov_bufs(struct efx_nic *efx, unsigned offset,
480                                  u64 *addr, unsigned count)
481 {
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
496 static bool bad_vf_index(struct efx_nic *efx, unsigned index)
497 {
498         return index >= efx_vf_size(efx);
499 }
500
501 static 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  */
512 static bool map_vi_index(struct efx_nic *efx, unsigned abs_index,
513                          struct siena_vf **vf_out, unsigned *rel_index_out)
514 {
515         struct siena_nic_data *nic_data = efx->nic_data;
516         unsigned vf_i;
517
518         if (abs_index < EFX_VI_BASE)
519                 return true;
520         vf_i = (abs_index - EFX_VI_BASE) / efx_vf_size(efx);
521         if (vf_i >= efx->vf_init_count)
522                 return true;
523
524         if (vf_out)
525                 *vf_out = nic_data->vf + vf_i;
526         if (rel_index_out)
527                 *rel_index_out = abs_index % efx_vf_size(efx);
528         return false;
529 }
530
531 static int efx_vfdi_init_evq(struct siena_vf *vf)
532 {
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
550         efx_siena_sriov_bufs(efx, buftbl, req->u.init_evq.addr, buf_count);
551
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
572 static int efx_vfdi_init_rxq(struct siena_vf *vf)
573 {
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) ||
584             vf_rxq >= VF_MAX_RX_QUEUES ||
585             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;
595         efx_siena_sriov_bufs(efx, buftbl, req->u.init_rxq.addr, buf_count);
596
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
613 static int efx_vfdi_init_txq(struct siena_vf *vf)
614 {
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);
639         efx_siena_sriov_bufs(efx, buftbl, req->u.init_txq.addr, buf_count);
640
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 */
660 static bool efx_vfdi_flush_wake(struct siena_vf *vf)
661 {
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
669 static void efx_vfdi_flush_clear(struct siena_vf *vf)
670 {
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
679 static int efx_vfdi_fini_all_queues(struct siena_vf *vf)
680 {
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;
687         MCDI_DECLARE_BUF(inbuf, MC_CMD_FLUSH_RX_QUEUES_IN_LENMAX);
688         int rc;
689
690         BUILD_BUG_ON(VF_MAX_RX_QUEUES >
691                      MC_CMD_FLUSH_RX_QUEUES_IN_QID_OFST_MAXNUM);
692
693         rtnl_lock();
694         siena_prepare_flush(efx);
695         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                 }
707                 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                 }
713         }
714
715         atomic_set(&vf->rxq_retry_count, 0);
716         while (timeout && (vf->rxq_count || vf->txq_count)) {
717                 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);
720                 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);
729                                 MCDI_SET_ARRAY_DWORD(
730                                         inbuf, FLUSH_RX_QUEUES_IN_QID_OFST,
731                                         rxqs_count, vf_offset + index);
732                                 rxqs_count++;
733                         }
734                 }
735         }
736
737         rtnl_lock();
738         siena_finish_flush(efx);
739         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         }
753         efx_siena_sriov_bufs(efx, vf->buftbl_base, NULL,
754                              EFX_VF_BUFTBL_PER_VI * efx_vf_size(efx));
755         efx_vfdi_flush_clear(vf);
756
757         vf->evq0_count = 0;
758
759         return timeout ? 0 : VFDI_RC_ETIMEDOUT;
760 }
761
762 static int efx_vfdi_insert_filter(struct siena_vf *vf)
763 {
764         struct efx_nic *efx = vf->efx;
765         struct siena_nic_data *nic_data = efx->nic_data;
766         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
788         efx_siena_sriov_reset_rx_filter(vf);
789         queue_work(vfdi_workqueue, &nic_data->peer_work);
790
791         return VFDI_RC_SUCCESS;
792 }
793
794 static int efx_vfdi_remove_all_filters(struct siena_vf *vf)
795 {
796         struct efx_nic *efx = vf->efx;
797         struct siena_nic_data *nic_data = efx->nic_data;
798
799         vf->rx_filtering = false;
800         efx_siena_sriov_reset_rx_filter(vf);
801         queue_work(vfdi_workqueue, &nic_data->peer_work);
802
803         return VFDI_RC_SUCCESS;
804 }
805
806 static int efx_vfdi_set_status_page(struct siena_vf *vf)
807 {
808         struct efx_nic *efx = vf->efx;
809         struct siena_nic_data *nic_data = efx->nic_data;
810         struct vfdi_req *req = vf->buf.addr;
811         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]);
816
817         if (!req->u.set_status_page.dma_addr || page_count > max_page_count) {
818                 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
825         mutex_lock(&nic_data->local_lock);
826         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
844         __efx_siena_sriov_push_vf_status(vf);
845         mutex_unlock(&vf->status_lock);
846         mutex_unlock(&nic_data->local_lock);
847
848         return VFDI_RC_SUCCESS;
849 }
850
851 static int efx_vfdi_clear_status_page(struct siena_vf *vf)
852 {
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
860 typedef int (*efx_vfdi_op_t)(struct siena_vf *vf);
861
862 static 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
873 static void efx_siena_sriov_vfdi(struct work_struct *work)
874 {
875         struct siena_vf *vf = container_of(work, struct siena_vf, req);
876         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;
888         rc = efx_siena_sriov_memcpy(efx, copy, 1);
889         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
932         (void)efx_siena_sriov_memcpy(efx, copy, ARRAY_SIZE(copy));
933 }
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  */
941
942 static void efx_siena_sriov_reset_vf(struct siena_vf *vf,
943                                      struct efx_buffer *buffer)
944 {
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                 }
979                 rc = efx_siena_sriov_memcpy(efx, copy_req, count);
980                 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);
992         efx_siena_sriov_bufs(efx, buftbl, vf->evq0_addrs, vf->evq0_count);
993
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);
1005         efx_writed(efx, &ptr, FR_BZ_EVQ_RPTR + FR_BZ_EVQ_RPTR_STEP * abs_evq);
1006
1007         mutex_unlock(&vf->status_lock);
1008 }
1009
1010 static void efx_siena_sriov_reset_vf_work(struct work_struct *work)
1011 {
1012         struct siena_vf *vf = container_of(work, struct siena_vf, req);
1013         struct efx_nic *efx = vf->efx;
1014         struct efx_buffer buf;
1015
1016         if (!efx_nic_alloc_buffer(efx, &buf, EFX_PAGE_SIZE, GFP_NOIO)) {
1017                 efx_siena_sriov_reset_vf(vf, &buf);
1018                 efx_nic_free_buffer(efx, &buf);
1019         }
1020 }
1021
1022 static void efx_siena_sriov_handle_no_channel(struct efx_nic *efx)
1023 {
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
1030 static int efx_siena_sriov_probe_channel(struct efx_channel *channel)
1031 {
1032         struct siena_nic_data *nic_data = channel->efx->nic_data;
1033         nic_data->vfdi_channel = channel;
1034
1035         return 0;
1036 }
1037
1038 static void
1039 efx_siena_sriov_get_channel_name(struct efx_channel *channel,
1040                                  char *buf, size_t len)
1041 {
1042         snprintf(buf, len, "%s-iov", channel->efx->name);
1043 }
1044
1045 static 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,
1048         .post_remove            = efx_channel_dummy_op_void,
1049         .get_name               = efx_siena_sriov_get_channel_name,
1050         /* no copy operation; channel must not be reallocated */
1051         .keep_eventq            = true,
1052 };
1053
1054 void efx_siena_sriov_probe(struct efx_nic *efx)
1055 {
1056         unsigned count;
1057
1058         if (!max_vfs)
1059                 return;
1060
1061         if (efx_siena_sriov_cmd(efx, false, &efx->vi_scale, &count))
1062                 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
1069         efx->extra_channel_type[EFX_EXTRA_CHANNEL_IOV] = &efx_siena_sriov_channel_type;
1070 }
1071
1072 /* Copy the list of individual addresses into the vfdi_status.peers
1073  * array and auxiliary pages, protected by %local_lock. Drop that lock
1074  * and then broadcast the address list to every VF.
1075  */
1076 static void efx_siena_sriov_peer_work(struct work_struct *data)
1077 {
1078         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;
1083         struct siena_vf *vf;
1084         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
1092         mutex_lock(&nic_data->local_lock);
1093
1094         /* Move the existing peer pages off %local_page_list */
1095         INIT_LIST_HEAD(&pages);
1096         list_splice_tail_init(&nic_data->local_page_list, &pages);
1097
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) {
1105                 vf = nic_data->vf + pos;
1106
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 */
1118         list_for_each_entry(local_addr, &nic_data->local_addr_list, link) {
1119                 ether_addr_copy(peer->mac_addr, local_addr->addr);
1120                 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
1141                         list_add_tail(&epp->link, &nic_data->local_page_list);
1142                         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;
1147         mutex_unlock(&nic_data->local_lock);
1148
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) {
1161                 vf = nic_data->vf + pos;
1162
1163                 mutex_lock(&vf->status_lock);
1164                 if (vf->status_addr)
1165                         __efx_siena_sriov_push_vf_status(vf);
1166                 mutex_unlock(&vf->status_lock);
1167         }
1168 }
1169
1170 static void efx_siena_sriov_free_local(struct efx_nic *efx)
1171 {
1172         struct siena_nic_data *nic_data = efx->nic_data;
1173         struct efx_local_addr *local_addr;
1174         struct efx_endpoint_page *epp;
1175
1176         while (!list_empty(&nic_data->local_addr_list)) {
1177                 local_addr = list_first_entry(&nic_data->local_addr_list,
1178                                               struct efx_local_addr, link);
1179                 list_del(&local_addr->link);
1180                 kfree(local_addr);
1181         }
1182
1183         while (!list_empty(&nic_data->local_page_list)) {
1184                 epp = list_first_entry(&nic_data->local_page_list,
1185                                        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
1193 static int efx_siena_sriov_vf_alloc(struct efx_nic *efx)
1194 {
1195         unsigned index;
1196         struct siena_vf *vf;
1197         struct siena_nic_data *nic_data = efx->nic_data;
1198
1199         nic_data->vf = kcalloc(efx->vf_count, sizeof(*nic_data->vf),
1200                                GFP_KERNEL);
1201         if (!nic_data->vf)
1202                 return -ENOMEM;
1203
1204         for (index = 0; index < efx->vf_count; ++index) {
1205                 vf = nic_data->vf + index;
1206
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;
1212                 INIT_WORK(&vf->req, efx_siena_sriov_vfdi);
1213                 INIT_WORK(&vf->reset_work, efx_siena_sriov_reset_vf_work);
1214                 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
1222 static void efx_siena_sriov_vfs_fini(struct efx_nic *efx)
1223 {
1224         struct siena_nic_data *nic_data = efx->nic_data;
1225         struct siena_vf *vf;
1226         unsigned int pos;
1227
1228         for (pos = 0; pos < efx->vf_count; ++pos) {
1229                 vf = nic_data->vf + pos;
1230
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
1240 static int efx_siena_sriov_vfs_init(struct efx_nic *efx)
1241 {
1242         struct pci_dev *pci_dev = efx->pci_dev;
1243         struct siena_nic_data *nic_data = efx->nic_data;
1244         unsigned index, devfn, sriov, buftbl_base;
1245         u16 offset, stride;
1246         struct siena_vf *vf;
1247         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
1256         buftbl_base = nic_data->vf_buftbl_base;
1257         devfn = pci_dev->devfn + offset;
1258         for (index = 0; index < efx->vf_count; ++index) {
1259                 vf = nic_data->vf + index;
1260
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
1271                 rc = efx_nic_alloc_buffer(efx, &vf->buf, EFX_PAGE_SIZE,
1272                                           GFP_KERNEL);
1273                 if (rc)
1274                         goto fail;
1275
1276                 devfn += stride;
1277         }
1278
1279         return 0;
1280
1281 fail:
1282         efx_siena_sriov_vfs_fini(efx);
1283         return rc;
1284 }
1285
1286 int efx_siena_sriov_init(struct efx_nic *efx)
1287 {
1288         struct net_device *net_dev = efx->net_dev;
1289         struct siena_nic_data *nic_data = efx->nic_data;
1290         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
1301         rc = efx_siena_sriov_cmd(efx, true, NULL, NULL);
1302         if (rc)
1303                 goto fail_cmd;
1304
1305         rc = efx_nic_alloc_buffer(efx, &nic_data->vfdi_status,
1306                                   sizeof(*vfdi_status), GFP_KERNEL);
1307         if (rc)
1308                 goto fail_status;
1309         vfdi_status = nic_data->vfdi_status.addr;
1310         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
1319         rc = efx_siena_sriov_vf_alloc(efx);
1320         if (rc)
1321                 goto fail_alloc;
1322
1323         mutex_init(&nic_data->local_lock);
1324         INIT_WORK(&nic_data->peer_work, efx_siena_sriov_peer_work);
1325         INIT_LIST_HEAD(&nic_data->local_addr_list);
1326         INIT_LIST_HEAD(&nic_data->local_page_list);
1327
1328         rc = efx_siena_sriov_vfs_init(efx);
1329         if (rc)
1330                 goto fail_vfs;
1331
1332         rtnl_lock();
1333         ether_addr_copy(vfdi_status->peers[0].mac_addr, net_dev->dev_addr);
1334         efx->vf_init_count = efx->vf_count;
1335         rtnl_unlock();
1336
1337         efx_siena_sriov_usrev(efx, true);
1338
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
1350 fail_pci:
1351         efx_siena_sriov_usrev(efx, false);
1352         rtnl_lock();
1353         efx->vf_init_count = 0;
1354         rtnl_unlock();
1355         efx_siena_sriov_vfs_fini(efx);
1356 fail_vfs:
1357         cancel_work_sync(&nic_data->peer_work);
1358         efx_siena_sriov_free_local(efx);
1359         kfree(nic_data->vf);
1360 fail_alloc:
1361         efx_nic_free_buffer(efx, &nic_data->vfdi_status);
1362 fail_status:
1363         efx_siena_sriov_cmd(efx, false, NULL, NULL);
1364 fail_cmd:
1365         return rc;
1366 }
1367
1368 void efx_siena_sriov_fini(struct efx_nic *efx)
1369 {
1370         struct siena_vf *vf;
1371         unsigned int pos;
1372         struct siena_nic_data *nic_data = efx->nic_data;
1373
1374         if (efx->vf_init_count == 0)
1375                 return;
1376
1377         /* Disable all interfaces to reconfiguration */
1378         BUG_ON(nic_data->vfdi_channel->enabled);
1379         efx_siena_sriov_usrev(efx, false);
1380         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) {
1386                 vf = nic_data->vf + pos;
1387                 cancel_work_sync(&vf->req);
1388                 cancel_work_sync(&vf->reset_work);
1389         }
1390         cancel_work_sync(&nic_data->peer_work);
1391
1392         pci_disable_sriov(efx->pci_dev);
1393
1394         /* Tear down back-end state */
1395         efx_siena_sriov_vfs_fini(efx);
1396         efx_siena_sriov_free_local(efx);
1397         kfree(nic_data->vf);
1398         efx_nic_free_buffer(efx, &nic_data->vfdi_status);
1399         efx_siena_sriov_cmd(efx, false, NULL, NULL);
1400 }
1401
1402 void efx_siena_sriov_event(struct efx_channel *channel, efx_qword_t *event)
1403 {
1404         struct efx_nic *efx = channel->efx;
1405         struct siena_vf *vf;
1406         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
1449 error:
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
1459 void efx_siena_sriov_flr(struct efx_nic *efx, unsigned vf_i)
1460 {
1461         struct siena_nic_data *nic_data = efx->nic_data;
1462         struct siena_vf *vf;
1463
1464         if (vf_i > efx->vf_init_count)
1465                 return;
1466         vf = nic_data->vf + vf_i;
1467         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
1477 void efx_siena_sriov_mac_address_changed(struct efx_nic *efx)
1478 {
1479         struct siena_nic_data *nic_data = efx->nic_data;
1480         struct vfdi_status *vfdi_status = nic_data->vfdi_status.addr;
1481
1482         if (!efx->vf_init_count)
1483                 return;
1484         ether_addr_copy(vfdi_status->peers[0].mac_addr,
1485                         efx->net_dev->dev_addr);
1486         queue_work(vfdi_workqueue, &nic_data->peer_work);
1487 }
1488
1489 void efx_siena_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event)
1490 {
1491         struct siena_vf *vf;
1492         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
1508 void efx_siena_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event)
1509 {
1510         struct siena_vf *vf;
1511         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 */
1533 void efx_siena_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq)
1534 {
1535         struct siena_vf *vf;
1536         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 */
1549 void efx_siena_sriov_reset(struct efx_nic *efx)
1550 {
1551         struct siena_nic_data *nic_data = efx->nic_data;
1552         unsigned int vf_i;
1553         struct efx_buffer buf;
1554         struct siena_vf *vf;
1555
1556         ASSERT_RTNL();
1557
1558         if (efx->vf_init_count == 0)
1559                 return;
1560
1561         efx_siena_sriov_usrev(efx, true);
1562         (void)efx_siena_sriov_cmd(efx, true, NULL, NULL);
1563
1564         if (efx_nic_alloc_buffer(efx, &buf, EFX_PAGE_SIZE, GFP_NOIO))
1565                 return;
1566
1567         for (vf_i = 0; vf_i < efx->vf_init_count; ++vf_i) {
1568                 vf = nic_data->vf + vf_i;
1569                 efx_siena_sriov_reset_vf(vf, &buf);
1570         }
1571
1572         efx_nic_free_buffer(efx, &buf);
1573 }
1574
1575 int efx_init_sriov(void)
1576 {
1577         /* A single threaded workqueue is sufficient. efx_siena_sriov_vfdi() and
1578          * efx_siena_sriov_peer_work() spend almost all their time sleeping for
1579          * MCDI to complete anyway
1580          */
1581         vfdi_workqueue = create_singlethread_workqueue("sfc_vfdi");
1582         if (!vfdi_workqueue)
1583                 return -ENOMEM;
1584         return 0;
1585 }
1586
1587 void efx_fini_sriov(void)
1588 {
1589         destroy_workqueue(vfdi_workqueue);
1590 }
1591
1592 int efx_siena_sriov_set_vf_mac(struct efx_nic *efx, int vf_i, u8 *mac)
1593 {
1594         struct siena_nic_data *nic_data = efx->nic_data;
1595         struct siena_vf *vf;
1596
1597         if (vf_i >= efx->vf_init_count)
1598                 return -EINVAL;
1599         vf = nic_data->vf + vf_i;
1600
1601         mutex_lock(&vf->status_lock);
1602         ether_addr_copy(vf->addr.mac_addr, mac);
1603         __efx_siena_sriov_update_vf_addr(vf);
1604         mutex_unlock(&vf->status_lock);
1605
1606         return 0;
1607 }
1608
1609 int efx_siena_sriov_set_vf_vlan(struct efx_nic *efx, int vf_i,
1610                                 u16 vlan, u8 qos)
1611 {
1612         struct siena_nic_data *nic_data = efx->nic_data;
1613         struct siena_vf *vf;
1614         u16 tci;
1615
1616         if (vf_i >= efx->vf_init_count)
1617                 return -EINVAL;
1618         vf = nic_data->vf + vf_i;
1619
1620         mutex_lock(&vf->status_lock);
1621         tci = (vlan & VLAN_VID_MASK) | ((qos & 0x7) << VLAN_PRIO_SHIFT);
1622         vf->addr.tci = htons(tci);
1623         __efx_siena_sriov_update_vf_addr(vf);
1624         mutex_unlock(&vf->status_lock);
1625
1626         return 0;
1627 }
1628
1629 int efx_siena_sriov_set_vf_spoofchk(struct efx_nic *efx, int vf_i,
1630                                     bool spoofchk)
1631 {
1632         struct siena_nic_data *nic_data = efx->nic_data;
1633         struct siena_vf *vf;
1634         int rc;
1635
1636         if (vf_i >= efx->vf_init_count)
1637                 return -EINVAL;
1638         vf = nic_data->vf + vf_i;
1639
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
1653 int efx_siena_sriov_get_vf_config(struct efx_nic *efx, int vf_i,
1654                                   struct ifla_vf_info *ivi)
1655 {
1656         struct siena_nic_data *nic_data = efx->nic_data;
1657         struct siena_vf *vf;
1658         u16 tci;
1659
1660         if (vf_i >= efx->vf_init_count)
1661                 return -EINVAL;
1662         vf = nic_data->vf + vf_i;
1663
1664         ivi->vf = vf_i;
1665         ether_addr_copy(ivi->mac, vf->addr.mac_addr);
1666         ivi->max_tx_rate = 0;
1667         ivi->min_tx_rate = 0;
1668         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
1676 bool efx_siena_sriov_wanted(struct efx_nic *efx)
1677 {
1678         return efx->vf_count != 0;
1679 }
1680
1681 int efx_siena_sriov_configure(struct efx_nic *efx, int num_vfs)
1682 {
1683         return 0;
1684 }