iPXE
intelxlvf.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <string.h>
27 #include <unistd.h>
28 #include <errno.h>
29 #include <byteswap.h>
30 #include <ipxe/pci.h>
31 #include <ipxe/netdevice.h>
32 #include <ipxe/ethernet.h>
33 #include "intelxlvf.h"
34 
35 /** @file
36  *
37  * Intel 40 Gigabit Ethernet virtual function network card driver
38  *
39  */
40 
41 /******************************************************************************
42  *
43  * Device reset
44  *
45  ******************************************************************************
46  */
47 
48 /**
49  * Reset hardware via PCIe function-level reset
50  *
51  * @v intelxl Intel device
52  */
53 static void intelxlvf_reset_flr ( struct intelxl_nic *intelxl,
54  struct pci_device *pci ) {
56 
57  /* Perform a PCIe function-level reset */
58  pci_read_config_word ( pci, ( intelxl->exp + PCI_EXP_DEVCTL ),
59  &control );
60  pci_write_config_word ( pci, ( intelxl->exp + PCI_EXP_DEVCTL ),
63 }
64 
65 /**
66  * Wait for admin event queue to be torn down
67  *
68  * @v intelxl Intel device
69  * @ret rc Return status code
70  */
71 static int intelxlvf_reset_wait_teardown ( struct intelxl_nic *intelxl ) {
72  uint32_t admin_evt_len;
73  unsigned int i;
74 
75  /* Wait for admin event queue to be torn down */
76  for ( i = 0 ; i < INTELXLVF_RESET_MAX_WAIT_MS ; i++ ) {
77 
78  /* Check admin event queue length register */
79  admin_evt_len = readl ( intelxl->regs + INTELXLVF_ADMIN +
81  if ( ! ( admin_evt_len & INTELXL_ADMIN_LEN_ENABLE ) )
82  return 0;
83 
84  /* Delay */
85  mdelay ( 1 );
86  }
87 
88  DBGC ( intelxl, "INTELXL %p timed out waiting for teardown (%#08x)\n",
89  intelxl, admin_evt_len );
90  return -ETIMEDOUT;
91 }
92 
93 /**
94  * Wait for virtual function to be marked as active
95  *
96  * @v intelxl Intel device
97  * @ret rc Return status code
98  */
99 static int intelxlvf_reset_wait_active ( struct intelxl_nic *intelxl ) {
100  uint32_t vfgen_rstat;
101  unsigned int vfr_state;
102  unsigned int i;
103 
104  /* Wait for virtual function to be marked as active */
105  for ( i = 0 ; i < INTELXLVF_RESET_MAX_WAIT_MS ; i++ ) {
106 
107  /* Check status as written by physical function driver */
108  vfgen_rstat = readl ( intelxl->regs + INTELXLVF_VFGEN_RSTAT );
109  vfr_state = INTELXLVF_VFGEN_RSTAT_VFR_STATE ( vfgen_rstat );
110  if ( vfr_state == INTELXLVF_VFGEN_RSTAT_VFR_STATE_ACTIVE )
111  return 0;
112 
113  /* Delay */
114  mdelay ( 1 );
115  }
116 
117  DBGC ( intelxl, "INTELXL %p timed out waiting for activation "
118  "(%#08x)\n", intelxl, vfgen_rstat );
119  return -ETIMEDOUT;
120 }
121 
122 /**
123  * Reset hardware via admin queue
124  *
125  * @v intelxl Intel device
126  * @ret rc Return status code
127  */
128 static int intelxlvf_reset_admin ( struct intelxl_nic *intelxl ) {
130  int rc;
131 
132  /* Populate descriptor */
135  cmd->vopcode = cpu_to_le32 ( INTELXL_ADMIN_VF_RESET );
136 
137  /* Issue command */
138  if ( ( rc = intelxl_admin_command ( intelxl ) ) != 0 )
139  goto err_command;
140 
141  /* Wait for minimum reset time */
143 
144  /* Wait for reset to take effect */
145  if ( ( rc = intelxlvf_reset_wait_teardown ( intelxl ) ) != 0 )
146  goto err_teardown;
147 
148  /* Wait for virtual function to become active */
149  if ( ( rc = intelxlvf_reset_wait_active ( intelxl ) ) != 0 )
150  goto err_active;
151 
152  err_active:
153  err_teardown:
154  intelxl_reopen_admin ( intelxl );
155  err_command:
156  return rc;
157 }
158 
159 /******************************************************************************
160  *
161  * Admin queue
162  *
163  ******************************************************************************
164  */
165 
166 /** Admin command queue register offsets */
171  .head = INTELXLVF_ADMIN_CMD_HEAD,
172  .tail = INTELXLVF_ADMIN_CMD_TAIL,
173 };
174 
175 /** Admin event queue register offsets */
180  .head = INTELXLVF_ADMIN_EVT_HEAD,
181  .tail = INTELXLVF_ADMIN_EVT_TAIL,
182 };
183 
184 /**
185  * Issue admin queue virtual function command
186  *
187  * @v netdev Network device
188  * @ret rc Return status code
189  */
190 static int intelxlvf_admin_command ( struct net_device *netdev ) {
191  struct intelxl_nic *intelxl = netdev->priv;
192  struct intelxl_admin *admin = &intelxl->command;
194  unsigned int i;
195  int rc;
196 
197  /* Populate descriptor */
198  cmd = &admin->desc[ admin->index % INTELXL_ADMIN_NUM_DESC ];
200 
201  /* Record opcode */
202  intelxl->vopcode = le32_to_cpu ( cmd->vopcode );
203 
204  /* Issue command */
205  if ( ( rc = intelxl_admin_command ( intelxl ) ) != 0 )
206  goto err_command;
207 
208  /* Wait for response */
209  for ( i = 0 ; i < INTELXLVF_ADMIN_MAX_WAIT_MS ; i++ ) {
210 
211  /* Poll admin event queue */
213 
214  /* If response has not arrived, delay 1ms and retry */
215  if ( intelxl->vopcode ) {
216  mdelay ( 1 );
217  continue;
218  }
219 
220  /* Check for errors */
221  if ( intelxl->vret != 0 )
222  return -EIO;
223 
224  return 0;
225  }
226 
227  rc = -ETIMEDOUT;
228  DBGC ( intelxl, "INTELXL %p timed out waiting for admin VF command "
229  "%#x\n", intelxl, intelxl->vopcode );
230  err_command:
231  intelxl->vopcode = 0;
232  return rc;
233 }
234 
235 /**
236  * Handle link status event
237  *
238  * @v netdev Network device
239  * @v link Link status
240  */
241 static void intelxlvf_admin_link ( struct net_device *netdev,
243  struct intelxl_nic *intelxl = netdev->priv;
244 
245  DBGC ( intelxl, "INTELXL %p link %#02x speed %#02x\n", intelxl,
246  link->status, link->speed );
247 
248  /* Update network device */
249  if ( link->status ) {
251  } else {
253  }
254 }
255 
256 /**
257  * Handle status change event
258  *
259  * @v netdev Network device
260  * @v stat Status change event
261  */
262 static void
264  struct intelxl_admin_vf_status_buffer *stat ) {
265  struct intelxl_nic *intelxl = netdev->priv;
266 
267  /* Handle event */
268  switch ( stat->event ) {
270  intelxlvf_admin_link ( netdev, &stat->data.link );
271  break;
272  default:
273  DBGC ( intelxl, "INTELXL %p unrecognised status change "
274  "event %#x:\n", intelxl, le32_to_cpu ( stat->event ) );
275  DBGC_HDA ( intelxl, 0, stat, sizeof ( *stat ) );
276  break;
277  }
278 }
279 
280 /**
281  * Handle virtual function event
282  *
283  * @v netdev Network device
284  * @v evt Admin queue event descriptor
285  * @v buf Admin queue event data buffer
286  */
288  struct intelxl_admin_descriptor *evt,
289  union intelxl_admin_buffer *buf ) {
290  struct intelxl_nic *intelxl = netdev->priv;
291  unsigned int vopcode = le32_to_cpu ( evt->vopcode );
292 
293  /* Record command response if applicable */
294  if ( vopcode == intelxl->vopcode ) {
295  memcpy ( &intelxl->vbuf, buf, sizeof ( intelxl->vbuf ) );
296  intelxl->vopcode = 0;
297  intelxl->vret = le32_to_cpu ( evt->vret );
298  if ( intelxl->vret != 0 ) {
299  DBGC ( intelxl, "INTELXL %p admin VF command %#x "
300  "error %d\n", intelxl, vopcode, intelxl->vret );
301  DBGC_HDA ( intelxl, virt_to_phys ( evt ), evt,
302  sizeof ( *evt ) );
303  DBGC_HDA ( intelxl, virt_to_phys ( buf ), buf,
304  le16_to_cpu ( evt->len ) );
305  }
306  return;
307  }
308 
309  /* Handle unsolicited events */
310  switch ( vopcode ) {
313  break;
314  default:
315  DBGC ( intelxl, "INTELXL %p unrecognised VF event %#x:\n",
316  intelxl, vopcode );
317  DBGC_HDA ( intelxl, virt_to_phys ( evt ), evt,
318  sizeof ( *evt ) );
319  DBGC_HDA ( intelxl, virt_to_phys ( buf ), buf,
320  le16_to_cpu ( evt->len ) );
321  break;
322  }
323 }
324 
325 /**
326  * Get resources
327  *
328  * @v netdev Network device
329  * @ret rc Return status code
330  */
332  struct intelxl_nic *intelxl = netdev->priv;
335  int rc;
336 
337  /* Populate descriptor */
340 
341  /* Issue command */
342  if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
343  return rc;
344 
345  /* Parse response */
346  res = &intelxl->vbuf.res;
347  intelxl->vsi = le16_to_cpu ( res->vsi );
348  memcpy ( netdev->hw_addr, res->mac, ETH_ALEN );
349  DBGC ( intelxl, "INTELXL %p VSI %#04x\n", intelxl, intelxl->vsi );
350 
351  return 0;
352 }
353 
354 /******************************************************************************
355  *
356  * Network device interface
357  *
358  ******************************************************************************
359  */
360 
361 /**
362  * Configure queues
363  *
364  * @v netdev Network device
365  * @ret rc Return status code
366  */
368  struct intelxl_nic *intelxl = netdev->priv;
370  union intelxl_admin_buffer *buf;
371  int rc;
372 
373  /* Populate descriptor */
377  cmd->len = cpu_to_le16 ( sizeof ( buf->cfg ) );
378  buf = intelxl_admin_command_buffer ( intelxl );
379  buf->cfg.vsi = cpu_to_le16 ( intelxl->vsi );
380  buf->cfg.count = cpu_to_le16 ( 1 );
381  buf->cfg.tx.vsi = cpu_to_le16 ( intelxl->vsi );
383  buf->cfg.tx.base = cpu_to_le64 ( dma ( &intelxl->tx.map,
384  intelxl->tx.desc.raw ) );
385  buf->cfg.rx.vsi = cpu_to_le16 ( intelxl->vsi );
387  buf->cfg.rx.len = cpu_to_le32 ( intelxl->mfs );
388  buf->cfg.rx.mfs = cpu_to_le32 ( intelxl->mfs );
389  buf->cfg.rx.base = cpu_to_le64 ( dma ( &intelxl->rx.map,
390  intelxl->rx.desc.raw ) );
391 
392  /* Issue command */
393  if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
394  return rc;
395 
396  return 0;
397 }
398 
399 /**
400  * Configure IRQ mapping
401  *
402  * @v netdev Network device
403  * @ret rc Return status code
404  */
405 static int intelxlvf_admin_irq_map ( struct net_device *netdev ) {
406  struct intelxl_nic *intelxl = netdev->priv;
408  union intelxl_admin_buffer *buf;
409  int rc;
410 
411  /* Populate descriptor */
415  cmd->len = cpu_to_le16 ( sizeof ( buf->irq ) );
416  buf = intelxl_admin_command_buffer ( intelxl );
417  buf->irq.count = cpu_to_le16 ( 1 );
418  buf->irq.vsi = cpu_to_le16 ( intelxl->vsi );
419  buf->irq.rxmap = cpu_to_le16 ( 0x0001 );
420  buf->irq.txmap = cpu_to_le16 ( 0x0001 );
421 
422  /* Issue command */
423  if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
424  return rc;
425 
426  return 0;
427 }
428 
429 /**
430  * Enable/disable queues
431  *
432  * @v netdev Network device
433  * @v enable Enable queues
434  * @ret rc Return status code
435  */
436 static int intelxlvf_admin_queues ( struct net_device *netdev, int enable ) {
437  struct intelxl_nic *intelxl = netdev->priv;
439  union intelxl_admin_buffer *buf;
440  int rc;
441 
442  /* Populate descriptor */
444  cmd->vopcode = ( enable ? cpu_to_le32 ( INTELXL_ADMIN_VF_ENABLE ) :
447  cmd->len = cpu_to_le16 ( sizeof ( buf->queues ) );
448  buf = intelxl_admin_command_buffer ( intelxl );
449  buf->queues.vsi = cpu_to_le16 ( intelxl->vsi );
450  buf->queues.rx = cpu_to_le32 ( 1 );
451  buf->queues.tx = cpu_to_le32 ( 1 );
452 
453  /* Issue command */
454  if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
455  return rc;
456 
457  return 0;
458 }
459 
460 /**
461  * Configure promiscuous mode
462  *
463  * @v netdev Network device
464  * @ret rc Return status code
465  */
466 static int intelxlvf_admin_promisc ( struct net_device *netdev ) {
467  struct intelxl_nic *intelxl = netdev->priv;
469  union intelxl_admin_buffer *buf;
470  int rc;
471 
472  /* Populate descriptor */
476  cmd->len = cpu_to_le16 ( sizeof ( buf->promisc ) );
477  buf = intelxl_admin_command_buffer ( intelxl );
478  buf->promisc.vsi = cpu_to_le16 ( intelxl->vsi );
481 
482  /* Issue command */
483  if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
484  return rc;
485 
486  return 0;
487 }
488 
489 /**
490  * Open network device
491  *
492  * @v netdev Network device
493  * @ret rc Return status code
494  */
495 static int intelxlvf_open ( struct net_device *netdev ) {
496  struct intelxl_nic *intelxl = netdev->priv;
497  int rc;
498 
499  /* Calculate maximum frame size */
500  intelxl->mfs = ( ( ETH_HLEN + netdev->mtu + 4 /* CRC */ +
501  INTELXL_ALIGN - 1 ) & ~( INTELXL_ALIGN - 1 ) );
502 
503  /* Allocate transmit descriptor ring */
504  if ( ( rc = intelxl_alloc_ring ( intelxl, &intelxl->tx ) ) != 0 )
505  goto err_alloc_tx;
506 
507  /* Allocate receive descriptor ring */
508  if ( ( rc = intelxl_alloc_ring ( intelxl, &intelxl->rx ) ) != 0 )
509  goto err_alloc_rx;
510 
511  /* Configure queues */
512  if ( ( rc = intelxlvf_admin_configure ( netdev ) ) != 0 )
513  goto err_configure;
514 
515  /* Configure IRQ map */
516  if ( ( rc = intelxlvf_admin_irq_map ( netdev ) ) != 0 )
517  goto err_irq_map;
518 
519  /* Enable queues */
520  if ( ( rc = intelxlvf_admin_queues ( netdev, 1 ) ) != 0 )
521  goto err_enable;
522 
523  /* Configure promiscuous mode */
524  if ( ( rc = intelxlvf_admin_promisc ( netdev ) ) != 0 )
525  goto err_promisc;
526 
527  return 0;
528 
529  err_promisc:
531  err_enable:
532  err_irq_map:
533  err_configure:
534  intelxl_free_ring ( intelxl, &intelxl->rx );
535  err_alloc_rx:
536  intelxl_free_ring ( intelxl, &intelxl->tx );
537  err_alloc_tx:
538  return rc;
539 }
540 
541 /**
542  * Close network device
543  *
544  * @v netdev Network device
545  */
546 static void intelxlvf_close ( struct net_device *netdev ) {
547  struct intelxl_nic *intelxl = netdev->priv;
548  int rc;
549 
550  /* Disable queues */
551  if ( ( rc = intelxlvf_admin_queues ( netdev, 0 ) ) != 0 ) {
552  /* Leak memory; there's nothing else we can do */
553  return;
554  }
555 
556  /* Free receive descriptor ring */
557  intelxl_free_ring ( intelxl, &intelxl->rx );
558 
559  /* Free transmit descriptor ring */
560  intelxl_free_ring ( intelxl, &intelxl->tx );
561 
562  /* Discard any unused receive buffers */
563  intelxl_empty_rx ( intelxl );
564 }
565 
566 /** Network device operations */
568  .open = intelxlvf_open,
569  .close = intelxlvf_close,
570  .transmit = intelxl_transmit,
571  .poll = intelxl_poll,
572 };
573 
574 /******************************************************************************
575  *
576  * PCI interface
577  *
578  ******************************************************************************
579  */
580 
581 /**
582  * Probe PCI device
583  *
584  * @v pci PCI device
585  * @ret rc Return status code
586  */
587 static int intelxlvf_probe ( struct pci_device *pci ) {
588  struct net_device *netdev;
589  struct intelxl_nic *intelxl;
590  int rc;
591 
592  /* Allocate and initialise net device */
593  netdev = alloc_etherdev ( sizeof ( *intelxl ) );
594  if ( ! netdev ) {
595  rc = -ENOMEM;
596  goto err_alloc;
597  }
599  intelxl = netdev->priv;
600  pci_set_drvdata ( pci, netdev );
601  netdev->dev = &pci->dev;
602  memset ( intelxl, 0, sizeof ( *intelxl ) );
603  intelxl->intr = INTELXLVF_VFINT_DYN_CTL0;
609  sizeof ( intelxl->tx.desc.tx[0] ),
612  sizeof ( intelxl->rx.desc.rx[0] ),
614 
615  /* Fix up PCI device */
616  adjust_pci_device ( pci );
617 
618  /* Map registers */
619  intelxl->regs = pci_ioremap ( pci, pci->membase, INTELXLVF_BAR_SIZE );
620  if ( ! intelxl->regs ) {
621  rc = -ENODEV;
622  goto err_ioremap;
623  }
624 
625  /* Configure DMA */
626  intelxl->dma = &pci->dma;
627  dma_set_mask_64bit ( intelxl->dma );
628  netdev->dma = intelxl->dma;
629 
630  /* Locate PCI Express capability */
631  intelxl->exp = pci_find_capability ( pci, PCI_CAP_ID_EXP );
632  if ( ! intelxl->exp ) {
633  DBGC ( intelxl, "INTELXL %p missing PCIe capability\n",
634  intelxl );
635  rc = -ENXIO;
636  goto err_exp;
637  }
638 
639  /* Reset the function via PCIe FLR */
640  intelxlvf_reset_flr ( intelxl, pci );
641 
642  /* Enable MSI-X dummy interrupt */
643  if ( ( rc = intelxl_msix_enable ( intelxl, pci ) ) != 0 )
644  goto err_msix;
645 
646  /* Open admin queues */
647  if ( ( rc = intelxl_open_admin ( intelxl ) ) != 0 )
648  goto err_open_admin;
649 
650  /* Reset the function via admin queue */
651  if ( ( rc = intelxlvf_reset_admin ( intelxl ) ) != 0 )
652  goto err_reset_admin;
653 
654  /* Get MAC address */
655  if ( ( rc = intelxlvf_admin_get_resources ( netdev ) ) != 0 )
656  goto err_get_resources;
657 
658  /* Register network device */
659  if ( ( rc = register_netdev ( netdev ) ) != 0 )
660  goto err_register_netdev;
661 
662  return 0;
663 
665  err_register_netdev:
666  err_get_resources:
667  err_reset_admin:
668  intelxl_close_admin ( intelxl );
669  err_open_admin:
670  intelxl_msix_disable ( intelxl, pci );
671  err_msix:
672  intelxlvf_reset_flr ( intelxl, pci );
673  err_exp:
674  iounmap ( intelxl->regs );
675  err_ioremap:
677  netdev_put ( netdev );
678  err_alloc:
679  return rc;
680 }
681 
682 /**
683  * Remove PCI device
684  *
685  * @v pci PCI device
686  */
687 static void intelxlvf_remove ( struct pci_device *pci ) {
688  struct net_device *netdev = pci_get_drvdata ( pci );
689  struct intelxl_nic *intelxl = netdev->priv;
690 
691  /* Unregister network device */
693 
694  /* Reset the function via admin queue */
695  intelxlvf_reset_admin ( intelxl );
696 
697  /* Close admin queues */
698  intelxl_close_admin ( intelxl );
699 
700  /* Disable MSI-X dummy interrupt */
701  intelxl_msix_disable ( intelxl, pci );
702 
703  /* Reset the function via PCIe FLR */
704  intelxlvf_reset_flr ( intelxl, pci );
705 
706  /* Free network device */
707  iounmap ( intelxl->regs );
709  netdev_put ( netdev );
710 }
711 
712 /** PCI device IDs */
713 static struct pci_device_id intelxlvf_nics[] = {
714  PCI_ROM ( 0x8086, 0x154c, "xl710-vf", "XL710 VF", 0 ),
715  PCI_ROM ( 0x8086, 0x1571, "xl710-vf-hv", "XL710 VF (Hyper-V)", 0 ),
716  PCI_ROM ( 0x8086, 0x1889, "xl710-vf-ad", "XL710 VF (adaptive)", 0 ),
717  PCI_ROM ( 0x8086, 0x37cd, "x722-vf", "X722 VF", 0 ),
718  PCI_ROM ( 0x8086, 0x37d9, "x722-vf-hv", "X722 VF (Hyper-V)", 0 ),
719 };
720 
721 /** PCI driver */
722 struct pci_driver intelxlvf_driver __pci_driver = {
723  .ids = intelxlvf_nics,
724  .id_count = ( sizeof ( intelxlvf_nics ) /
725  sizeof ( intelxlvf_nics[0] ) ),
728 };
#define INTELXL_RESET_DELAY_MS
Time to delay for device reset, in milliseconds.
Definition: intelxl.h:998
struct intelxl_admin_vf_configure_buffer cfg
VF Configure Queues data buffer.
Definition: intelxl.h:511
struct intelxl_admin_descriptor * intelxl_admin_command_descriptor(struct intelxl_nic *intelxl)
Get next admin command queue descriptor.
Definition: intelxl.c:310
int intelxl_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: intelxl.c:1482
void * regs
Registers.
Definition: intelxl.h:1057
static void intelxlvf_close(struct net_device *netdev)
Close network device.
Definition: intelxlvf.c:546
uint32_t tx
Transmit queue bitmask.
Definition: intelxl.h:460
unsigned long membase
Memory base.
Definition: pci.h:200
struct dma_device * dma
DMA device.
Definition: intelxl.h:1059
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct pci_driver intelxlvf_driver __pci_driver
PCI driver.
Definition: intelxlvf.c:722
unsigned short uint16_t
Definition: stdint.h:11
#define INTELXLVF_ADMIN_EVT_LEN
Admin Event Queue Length Register (offset)
Definition: intelxlvf.h:51
struct dma_device dma
DMA device.
Definition: pci.h:195
static int intelxlvf_admin_command(struct net_device *netdev)
Issue admin queue virtual function command.
Definition: intelxlvf.c:190
A PCI driver.
Definition: pci.h:230
static int intelxlvf_admin_configure(struct net_device *netdev)
Configure queues.
Definition: intelxlvf.c:367
static int intelxlvf_admin_irq_map(struct net_device *netdev)
Configure IRQ mapping.
Definition: intelxlvf.c:405
#define le32_to_cpu(value)
Definition: byteswap.h:113
int(* open)(struct net_device *netdev)
Open network device.
Definition: netdevice.h:222
int pci_find_capability(struct pci_device *pci, int cap)
Look for a PCI capability.
Definition: pciextra.c:36
#define INTELXLVF_ADMIN_CMD_HEAD
Admin Command Queue Head Register (offset)
Definition: intelxlvf.h:39
Error codes.
static int intelxlvf_reset_wait_active(struct intelxl_nic *intelxl)
Wait for virtual function to be marked as active.
Definition: intelxlvf.c:99
#define INTELXL_ADMIN_LEN_ENABLE
Queue enable.
Definition: intelxl.h:50
int vret
Current VF return value.
Definition: intelxl.h:1090
static int intelxlvf_probe(struct pci_device *pci)
Probe PCI device.
Definition: intelxlvf.c:587
static int intelxlvf_admin_promisc(struct net_device *netdev)
Configure promiscuous mode.
Definition: intelxlvf.c:466
void intelxl_msix_disable(struct intelxl_nic *intelxl, struct pci_device *pci)
Disable MSI-X dummy interrupt.
Definition: intelxl.c:176
Admin queue register offsets.
Definition: intelxl.h:63
static void intelxlvf_admin_link(struct net_device *netdev, struct intelxl_admin_vf_status_link *link)
Handle link status event.
Definition: intelxlvf.c:241
struct pci_device_id * ids
PCI ID table.
Definition: pci.h:232
int pci_write_config_word(struct pci_device *pci, unsigned int where, uint16_t value)
Write 16-bit word to PCI configuration space.
size_t mtu
Maximum transmission unit length.
Definition: netdevice.h:415
Admin queue.
Definition: intelxl.h:561
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define INTELXLVF_ADMIN_EVT_HEAD
Admin Event Queue Head Register (offset)
Definition: intelxlvf.h:54
#define DBGC(...)
Definition: compiler.h:505
Admin Queue VF Get Resources data buffer.
Definition: intelxl.h:321
struct intelxl_admin command
Admin command queue.
Definition: intelxl.h:1083
uint16_t vsi
VSI switching element ID.
Definition: intelxl.h:325
#define INTELXLVF_BAR_SIZE
BAR size.
Definition: intelxlvf.h:15
struct intelxl_admin_vf_irq_map_buffer irq
Definition: intelxl.h:517
static __always_inline void dma_set_mask_64bit(struct dma_device *dma)
Set 64-bit addressable space mask.
Definition: dma.h:474
union intelxl_admin_buffer * intelxl_admin_command_buffer(struct intelxl_nic *intelxl)
Get next admin command queue data buffer.
Definition: intelxl.c:327
struct dma_device * dma
DMA device.
Definition: netdevice.h:366
struct intelxl_admin_vf_get_resources_buffer res
VF Get Resources data buffer.
Definition: intelxl.h:507
#define cpu_to_le64(value)
Definition: byteswap.h:108
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
#define INTELXLVF_VFINT_DYN_CTL0
VF Interrupt Zero Dynamic Control Register.
Definition: intelxlvf.h:24
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:186
#define INTELXL_ADMIN_VF_IRQ_MAP
Admin Queue VF IRQ Map opcode.
Definition: intelxl.h:418
uint32_t rx
Receive queue bitmask.
Definition: intelxl.h:458
#define INTELXLVF_VFGEN_RSTAT_VFR_STATE(x)
Definition: intelxlvf.h:64
#define INTELXL_ALIGN
Alignment.
Definition: intelxl.h:26
uint16_t vsi
VSI switching element ID.
Definition: intelxl.h:454
unsigned int bal
Base Address Low Register offset.
Definition: intelxl.h:65
size_t mfs
Maximum frame size.
Definition: intelxl.h:1061
uint32_t event
Event type.
Definition: intelxl.h:351
int intelxl_open_admin(struct intelxl_nic *intelxl)
Open admin queues.
Definition: intelxl.c:853
#define INTELXLVF_ADMIN
VF Admin Queue register block.
Definition: intelxlvf.h:27
union intelxl_tx_descriptor * tx
Transmit descriptors.
Definition: intelxl.h:871
static void intelxlvf_admin_status(struct net_device *netdev, struct intelxl_admin_vf_status_buffer *stat)
Handle status change event.
Definition: intelxlvf.c:263
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:154
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
struct device dev
Generic device.
Definition: pci.h:193
#define INTELXL_ADMIN_VF_STATUS_LINK
Link status change event type.
Definition: intelxl.h:336
struct intelxl_admin_vf_status_buffer stat
VF Status Change Event data buffer.
Definition: intelxl.h:509
#define PCI_EXP_DEVCTL_FLR
Function level reset.
Definition: pci.h:112
unsigned int exp
PCI Express capability offset.
Definition: intelxl.h:1078
uint32_t mfs
Maximum frame size.
Definition: intelxl.h:400
#define INTELXL_ADMIN_SEND_TO_PF
Admin queue Send Message to PF command.
Definition: intelxl.h:309
#define INTELXLVF_VFGEN_RSTAT_VFR_STATE_ACTIVE
Definition: intelxlvf.h:65
#define INTELXL_ADMIN_NUM_DESC
Number of admin queue descriptors.
Definition: intelxl.h:593
int intelxl_msix_enable(struct intelxl_nic *intelxl, struct pci_device *pci)
Enable MSI-X dummy interrupt.
Definition: intelxl.c:134
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:510
#define INTELXLVF_ADMIN_CMD_TAIL
Admin Command Queue Tail Register (offset)
Definition: intelxlvf.h:42
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:344
#define ENOMEM
Not enough space.
Definition: errno.h:534
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint16_t len
Data length.
Definition: intelxl.h:529
struct intelxl_ring rx
Receive descriptor ring.
Definition: intelxl.h:1097
static void intelxl_init_admin(struct intelxl_admin *admin, unsigned int base, const struct intelxl_admin_offsets *regs)
Initialise admin queue.
Definition: intelxl.h:585
unsigned int index
Queue index.
Definition: intelxl.h:569
#define ETH_HLEN
Definition: if_ether.h:9
#define INTELXLVF_ADMIN_CMD_LEN
Admin Command Queue Length Register (offset)
Definition: intelxlvf.h:36
Intel 40 Gigabit Ethernet virtual function network card driver.
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:567
Ethernet protocol.
unsigned int vsi
Virtual Station Interface switching element ID.
Definition: intelxl.h:1072
#define INTELXL_TX_NUM_DESC
Number of transmit descriptors.
Definition: intelxl.h:920
void * priv
Driver private data.
Definition: netdevice.h:431
#define DBGC_HDA(...)
Definition: compiler.h:506
#define INTELXL_ADMIN_VF_CONFIGURE
Admin Queue VF Configure Queues opcode.
Definition: intelxl.h:362
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:780
void * raw
Raw data.
Definition: intelxl.h:875
uint16_t txmap
Transmit queue bitmap.
Definition: intelxl.h:431
static int intelxlvf_admin_get_resources(struct net_device *netdev)
Get resources.
Definition: intelxlvf.c:331
static struct net_device * netdev
Definition: gdbudp.c:52
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
#define INTELXL_RX_NUM_DESC
Number of receive descriptors.
Definition: intelxl.h:929
static int intelxlvf_admin_queues(struct net_device *netdev, int enable)
Enable/disable queues.
Definition: intelxlvf.c:436
#define INTELXL_ADMIN_VF_DISABLE
Admin Queue VF Disable Queues opcode.
Definition: intelxl.h:449
void intelxl_poll_admin(struct net_device *netdev)
Poll admin event queue.
Definition: intelxl.c:800
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:899
union intelxl_ring::@65 desc
Descriptors.
static int intelxlvf_open(struct net_device *netdev)
Open network device.
Definition: intelxlvf.c:495
#define cpu_to_le32(value)
Definition: byteswap.h:107
void intelxl_free_ring(struct intelxl_nic *intelxl __unused, struct intelxl_ring *ring)
Free descriptor ring.
Definition: intelxl.c:983
uint64_t base
Base address.
Definition: intelxl.h:383
#define INTELXLVF_QTX_TAIL
Transmit Queue Tail Register.
Definition: intelxlvf.h:18
#define INTELXLVF_ADMIN_EVT_BAH
Admin Event Queue Base Address High Register (offset)
Definition: intelxlvf.h:48
uint16_t vsi
VSI switching element ID.
Definition: intelxl.h:425
union intelxl_rx_descriptor * rx
Receive descriptors.
Definition: intelxl.h:873
union intelxl_admin_buffer vbuf
Current VF event data buffer.
Definition: intelxl.h:1092
PCI bus.
A PCI device.
Definition: pci.h:191
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:722
unsigned int intr
Interrupt control register.
Definition: intelxl.h:1076
uint32_t control
Control.
Definition: myson.h:14
struct intelxl_admin_descriptor * desc
Descriptors.
Definition: intelxl.h:563
A network device.
Definition: netdevice.h:352
#define ENODEV
No such device.
Definition: errno.h:509
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:523
struct dma_mapping map
Descriptor ring DMA mapping.
Definition: intelxl.h:878
#define INTELXL_ADMIN_FL_BUF
Admin descriptor uses data buffer.
Definition: intelxl.h:558
int32_t vret
VF return value.
Definition: intelxl.h:540
#define INTELXLVF_RESET_MAX_WAIT_MS
Maximum time to wait for reset to complete.
Definition: intelxlvf.h:68
uint16_t count
Number of interrupt vectors.
Definition: intelxl.h:423
An Intel 40Gigabit network card.
Definition: intelxl.h:1055
#define INTELXL_ADMIN_VF_RESET
Admin Queue VF Reset opcode.
Definition: intelxl.h:315
#define ETH_ALEN
Definition: if_ether.h:8
A PCI device ID list entry.
Definition: pci.h:155
#define le16_to_cpu(value)
Definition: byteswap.h:112
uint16_t vsi
VSI switching element ID.
Definition: intelxl.h:469
unsigned int uint32_t
Definition: stdint.h:12
uint16_t count
Number of queue pairs.
Definition: intelxl.h:369
static const struct intelxl_admin_offsets intelxlvf_admin_event_offsets
Admin event queue register offsets.
Definition: intelxlvf.c:176
uint16_t vsi
VSI switching element ID.
Definition: intelxl.h:367
static void intelxlvf_reset_flr(struct intelxl_nic *intelxl, struct pci_device *pci)
Reset hardware via PCIe function-level reset.
Definition: intelxlvf.c:53
struct intelxl_ring tx
Transmit descriptor ring.
Definition: intelxl.h:1095
#define INTELXL_ADMIN_VF_PROMISC
Admin Queue VF Configure Promiscuous Mode opcode.
Definition: intelxl.h:464
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
#define PCI_CAP_ID_EXP
PCI Express.
Definition: pci.h:97
void intelxlvf_admin_event(struct net_device *netdev, struct intelxl_admin_descriptor *evt, union intelxl_admin_buffer *buf)
Handle virtual function event.
Definition: intelxlvf.c:287
int intelxl_admin_command(struct intelxl_nic *intelxl)
Issue admin queue command.
Definition: intelxl.c:366
Network device operations.
Definition: netdevice.h:213
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
struct intelxl_admin_vf_configure_buffer::@62 rx
Receive queue.
static struct net_device_operations intelxlvf_operations
Network device operations.
Definition: intelxlvf.c:567
static struct pci_device_id intelxlvf_nics[]
PCI device IDs.
Definition: intelxlvf.c:713
Network device management.
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:354
uint32_t len
Data buffer length.
Definition: intelxl.h:398
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define INTELXLVF_ADMIN_EVT_BAL
Admin Event Queue Base Address Low Register (offset)
Definition: intelxlvf.h:45
Admin queue descriptor.
Definition: intelxl.h:523
#define ENXIO
No such device or address.
Definition: errno.h:599
static void intelxlvf_remove(struct pci_device *pci)
Remove PCI device.
Definition: intelxlvf.c:687
uint16_t rxmap
Receive queue bitmap.
Definition: intelxl.h:429
static int intelxlvf_reset_wait_teardown(struct intelxl_nic *intelxl)
Wait for admin event queue to be torn down.
Definition: intelxlvf.c:71
int(* probe)(struct pci_device *pci)
Probe device.
Definition: pci.h:243
struct intelxl_admin_vf_queues_buffer queues
VF Enable/Disable Queues data buffer.
Definition: intelxl.h:513
#define INTELXLVF_VFGEN_RSTAT
VF Reset Status Register.
Definition: intelxlvf.h:63
Admin Queue VF Status Change Event data buffer.
Definition: intelxl.h:349
#define EIO
Input/output error.
Definition: errno.h:433
#define INTELXLVF_ADMIN_MAX_WAIT_MS
Maximum time to wait for a VF admin request to complete.
Definition: intelxlvf.h:60
union intelxl_admin_vf_status_buffer::@60 data
Event data.
#define INTELXL_ADMIN_VF_ENABLE
Admin Queue VF Enable Queues opcode.
Definition: intelxl.h:446
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
static const struct intelxl_admin_offsets intelxlvf_admin_command_offsets
Admin command queue register offsets.
Definition: intelxlvf.c:167
#define cpu_to_le16(value)
Definition: byteswap.h:106
static void intelxlvf_init_ring(struct intelxl_ring *ring, unsigned int count, size_t len, unsigned int tail)
Initialise descriptor ring.
Definition: intelxlvf.h:79
void iounmap(volatile const void *io_addr)
Unmap I/O address.
#define INTELXL_ADMIN_VF_GET_RESOURCES
Admin Queue VF Get Resources opcode.
Definition: intelxl.h:318
void intelxl_reopen_admin(struct intelxl_nic *intelxl)
Reopen admin queues (after virtual function reset)
Definition: intelxl.c:893
#define INTELXL_ADMIN_PROMISC_FL_UNICAST
Promiscuous unicast mode.
Definition: intelxl.h:255
#define INTELXLVF_ADMIN_CMD_BAL
Admin Command Queue Base Address Low Register (offset)
Definition: intelxlvf.h:30
void intelxl_close_admin(struct intelxl_nic *intelxl)
Close admin queues.
Definition: intelxl.c:915
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
#define INTELXL_ADMIN_FL_RD
Admin descriptor uses data buffer for command parameters.
Definition: intelxl.h:555
#define INTELXLVF_ADMIN_EVT_TAIL
Admin Event Queue Tail Register (offset)
Definition: intelxlvf.h:57
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29
struct intelxl_admin event
Admin event queue.
Definition: intelxl.h:1085
#define INTELXL_ADMIN_PROMISC_FL_MULTICAST
Promiscuous multicast mode.
Definition: intelxl.h:258
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
String functions.
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:289
struct intelxl_admin_vf_configure_buffer::@61 tx
Transmit queue.
void intelxl_empty_rx(struct intelxl_nic *intelxl)
Discard unused receive I/O buffers.
Definition: intelxl.c:1354
uint8_t mac[ETH_ALEN]
MAC address.
Definition: intelxl.h:329
void intelxl_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: intelxl.c:1602
#define INTELXLVF_ADMIN_CMD_BAH
Admin Command Queue Base Address High Register (offset)
Definition: intelxlvf.h:33
int intelxl_alloc_ring(struct intelxl_nic *intelxl, struct intelxl_ring *ring)
Allocate descriptor ring.
Definition: intelxl.c:943
Admin queue data buffer.
Definition: intelxl.h:499
unsigned int vopcode
Current VF opcode.
Definition: intelxl.h:1088
#define PCI_EXP_DEVCTL
PCI Express.
Definition: pci.h:111
uint32_t vopcode
VF opcode.
Definition: intelxl.h:537
static int intelxlvf_reset_admin(struct intelxl_nic *intelxl)
Reset hardware via admin queue.
Definition: intelxlvf.c:128
#define INTELXL_ADMIN_VF_STATUS
Admin Queue VF Status Change Event opcode.
Definition: intelxl.h:333
void * memset(void *dest, int character, size_t len) __nonnull
struct intelxl_admin_vf_status_link link
Link change event data.
Definition: intelxl.h:355
#define INTELXLVF_QRX_TAIL
Receive Queue Tail Register.
Definition: intelxlvf.h:21
struct intelxl_admin_vf_promisc_buffer promisc
VF Configure Promiscuous Mode data buffer.
Definition: intelxl.h:515