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_bus ( evt ), evt,
302  sizeof ( *evt ) );
303  DBGC_HDA ( intelxl, virt_to_bus ( 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, 0, evt, sizeof ( *evt ) );
318  DBGC_HDA ( intelxl, 0, buf, le16_to_cpu ( evt->len ) );
319  break;
320  }
321 }
322 
323 /**
324  * Get resources
325  *
326  * @v netdev Network device
327  * @ret rc Return status code
328  */
330  struct intelxl_nic *intelxl = netdev->priv;
333  int rc;
334 
335  /* Populate descriptor */
338 
339  /* Issue command */
340  if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
341  return rc;
342 
343  /* Parse response */
344  res = &intelxl->vbuf.res;
345  intelxl->vsi = le16_to_cpu ( res->vsi );
346  memcpy ( netdev->hw_addr, res->mac, ETH_ALEN );
347  DBGC ( intelxl, "INTELXL %p VSI %#04x\n", intelxl, intelxl->vsi );
348 
349  return 0;
350 }
351 
352 /******************************************************************************
353  *
354  * Network device interface
355  *
356  ******************************************************************************
357  */
358 
359 /**
360  * Configure queues
361  *
362  * @v netdev Network device
363  * @ret rc Return status code
364  */
366  struct intelxl_nic *intelxl = netdev->priv;
368  union intelxl_admin_buffer *buf;
369  int rc;
370 
371  /* Populate descriptor */
375  cmd->len = cpu_to_le16 ( sizeof ( buf->cfg ) );
376  buf = intelxl_admin_command_buffer ( intelxl );
377  buf->cfg.vsi = cpu_to_le16 ( intelxl->vsi );
378  buf->cfg.count = cpu_to_le16 ( 1 );
379  buf->cfg.tx.vsi = cpu_to_le16 ( intelxl->vsi );
381  buf->cfg.tx.base = cpu_to_le64 ( virt_to_bus ( intelxl->tx.desc.raw ) );
382  buf->cfg.rx.vsi = cpu_to_le16 ( intelxl->vsi );
384  buf->cfg.rx.len = cpu_to_le32 ( intelxl->mfs );
385  buf->cfg.rx.mfs = cpu_to_le32 ( intelxl->mfs );
386  buf->cfg.rx.base = cpu_to_le64 ( virt_to_bus ( intelxl->rx.desc.raw ) );
387 
388  /* Issue command */
389  if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
390  return rc;
391 
392  return 0;
393 }
394 
395 /**
396  * Configure IRQ mapping
397  *
398  * @v netdev Network device
399  * @ret rc Return status code
400  */
401 static int intelxlvf_admin_irq_map ( struct net_device *netdev ) {
402  struct intelxl_nic *intelxl = netdev->priv;
404  union intelxl_admin_buffer *buf;
405  int rc;
406 
407  /* Populate descriptor */
411  cmd->len = cpu_to_le16 ( sizeof ( buf->irq ) );
412  buf = intelxl_admin_command_buffer ( intelxl );
413  buf->irq.count = cpu_to_le16 ( 1 );
414  buf->irq.vsi = cpu_to_le16 ( intelxl->vsi );
415  buf->irq.rxmap = cpu_to_le16 ( 0x0001 );
416  buf->irq.txmap = cpu_to_le16 ( 0x0001 );
417 
418  /* Issue command */
419  if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
420  return rc;
421 
422  return 0;
423 }
424 
425 /**
426  * Enable/disable queues
427  *
428  * @v netdev Network device
429  * @v enable Enable queues
430  * @ret rc Return status code
431  */
432 static int intelxlvf_admin_queues ( struct net_device *netdev, int enable ) {
433  struct intelxl_nic *intelxl = netdev->priv;
435  union intelxl_admin_buffer *buf;
436  int rc;
437 
438  /* Populate descriptor */
440  cmd->vopcode = ( enable ? cpu_to_le32 ( INTELXL_ADMIN_VF_ENABLE ) :
443  cmd->len = cpu_to_le16 ( sizeof ( buf->queues ) );
444  buf = intelxl_admin_command_buffer ( intelxl );
445  buf->queues.vsi = cpu_to_le16 ( intelxl->vsi );
446  buf->queues.rx = cpu_to_le32 ( 1 );
447  buf->queues.tx = cpu_to_le32 ( 1 );
448 
449  /* Issue command */
450  if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
451  return rc;
452 
453  return 0;
454 }
455 
456 /**
457  * Configure promiscuous mode
458  *
459  * @v netdev Network device
460  * @ret rc Return status code
461  */
462 static int intelxlvf_admin_promisc ( struct net_device *netdev ) {
463  struct intelxl_nic *intelxl = netdev->priv;
465  union intelxl_admin_buffer *buf;
466  int rc;
467 
468  /* Populate descriptor */
472  cmd->len = cpu_to_le16 ( sizeof ( buf->promisc ) );
473  buf = intelxl_admin_command_buffer ( intelxl );
474  buf->promisc.vsi = cpu_to_le16 ( intelxl->vsi );
477 
478  /* Issue command */
479  if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
480  return rc;
481 
482  return 0;
483 }
484 
485 /**
486  * Open network device
487  *
488  * @v netdev Network device
489  * @ret rc Return status code
490  */
491 static int intelxlvf_open ( struct net_device *netdev ) {
492  struct intelxl_nic *intelxl = netdev->priv;
493  int rc;
494 
495  /* Calculate maximum frame size */
496  intelxl->mfs = ( ( ETH_HLEN + netdev->mtu + 4 /* CRC */ +
497  INTELXL_ALIGN - 1 ) & ~( INTELXL_ALIGN - 1 ) );
498 
499  /* Allocate transmit descriptor ring */
500  if ( ( rc = intelxl_alloc_ring ( intelxl, &intelxl->tx ) ) != 0 )
501  goto err_alloc_tx;
502 
503  /* Allocate receive descriptor ring */
504  if ( ( rc = intelxl_alloc_ring ( intelxl, &intelxl->rx ) ) != 0 )
505  goto err_alloc_rx;
506 
507  /* Configure queues */
508  if ( ( rc = intelxlvf_admin_configure ( netdev ) ) != 0 )
509  goto err_configure;
510 
511  /* Configure IRQ map */
512  if ( ( rc = intelxlvf_admin_irq_map ( netdev ) ) != 0 )
513  goto err_irq_map;
514 
515  /* Enable queues */
516  if ( ( rc = intelxlvf_admin_queues ( netdev, 1 ) ) != 0 )
517  goto err_enable;
518 
519  /* Configure promiscuous mode */
520  if ( ( rc = intelxlvf_admin_promisc ( netdev ) ) != 0 )
521  goto err_promisc;
522 
523  return 0;
524 
525  err_promisc:
527  err_enable:
528  err_irq_map:
529  err_configure:
530  intelxl_free_ring ( intelxl, &intelxl->rx );
531  err_alloc_rx:
532  intelxl_free_ring ( intelxl, &intelxl->tx );
533  err_alloc_tx:
534  return rc;
535 }
536 
537 /**
538  * Close network device
539  *
540  * @v netdev Network device
541  */
542 static void intelxlvf_close ( struct net_device *netdev ) {
543  struct intelxl_nic *intelxl = netdev->priv;
544  int rc;
545 
546  /* Disable queues */
547  if ( ( rc = intelxlvf_admin_queues ( netdev, 0 ) ) != 0 ) {
548  /* Leak memory; there's nothing else we can do */
549  return;
550  }
551 
552  /* Free receive descriptor ring */
553  intelxl_free_ring ( intelxl, &intelxl->rx );
554 
555  /* Free transmit descriptor ring */
556  intelxl_free_ring ( intelxl, &intelxl->tx );
557 
558  /* Discard any unused receive buffers */
559  intelxl_empty_rx ( intelxl );
560 }
561 
562 /** Network device operations */
564  .open = intelxlvf_open,
565  .close = intelxlvf_close,
566  .transmit = intelxl_transmit,
567  .poll = intelxl_poll,
568 };
569 
570 /******************************************************************************
571  *
572  * PCI interface
573  *
574  ******************************************************************************
575  */
576 
577 /**
578  * Probe PCI device
579  *
580  * @v pci PCI device
581  * @ret rc Return status code
582  */
583 static int intelxlvf_probe ( struct pci_device *pci ) {
584  struct net_device *netdev;
585  struct intelxl_nic *intelxl;
586  int rc;
587 
588  /* Allocate and initialise net device */
589  netdev = alloc_etherdev ( sizeof ( *intelxl ) );
590  if ( ! netdev ) {
591  rc = -ENOMEM;
592  goto err_alloc;
593  }
595  intelxl = netdev->priv;
596  pci_set_drvdata ( pci, netdev );
597  netdev->dev = &pci->dev;
598  memset ( intelxl, 0, sizeof ( *intelxl ) );
599  intelxl->intr = INTELXLVF_VFINT_DYN_CTL0;
605  sizeof ( intelxl->tx.desc.tx[0] ),
608  sizeof ( intelxl->rx.desc.rx[0] ),
610 
611  /* Fix up PCI device */
612  adjust_pci_device ( pci );
613 
614  /* Map registers */
615  intelxl->regs = ioremap ( pci->membase, INTELXLVF_BAR_SIZE );
616  if ( ! intelxl->regs ) {
617  rc = -ENODEV;
618  goto err_ioremap;
619  }
620 
621  /* Locate PCI Express capability */
622  intelxl->exp = pci_find_capability ( pci, PCI_CAP_ID_EXP );
623  if ( ! intelxl->exp ) {
624  DBGC ( intelxl, "INTELXL %p missing PCIe capability\n",
625  intelxl );
626  rc = -ENXIO;
627  goto err_exp;
628  }
629 
630  /* Reset the function via PCIe FLR */
631  intelxlvf_reset_flr ( intelxl, pci );
632 
633  /* Enable MSI-X dummy interrupt */
634  if ( ( rc = intelxl_msix_enable ( intelxl, pci ) ) != 0 )
635  goto err_msix;
636 
637  /* Open admin queues */
638  if ( ( rc = intelxl_open_admin ( intelxl ) ) != 0 )
639  goto err_open_admin;
640 
641  /* Reset the function via admin queue */
642  if ( ( rc = intelxlvf_reset_admin ( intelxl ) ) != 0 )
643  goto err_reset_admin;
644 
645  /* Get MAC address */
646  if ( ( rc = intelxlvf_admin_get_resources ( netdev ) ) != 0 )
647  goto err_get_resources;
648 
649  /* Register network device */
650  if ( ( rc = register_netdev ( netdev ) ) != 0 )
651  goto err_register_netdev;
652 
653  return 0;
654 
656  err_register_netdev:
657  err_get_resources:
658  err_reset_admin:
659  intelxl_close_admin ( intelxl );
660  err_open_admin:
661  intelxl_msix_disable ( intelxl, pci );
662  err_msix:
663  intelxlvf_reset_flr ( intelxl, pci );
664  err_exp:
665  iounmap ( intelxl->regs );
666  err_ioremap:
668  netdev_put ( netdev );
669  err_alloc:
670  return rc;
671 }
672 
673 /**
674  * Remove PCI device
675  *
676  * @v pci PCI device
677  */
678 static void intelxlvf_remove ( struct pci_device *pci ) {
679  struct net_device *netdev = pci_get_drvdata ( pci );
680  struct intelxl_nic *intelxl = netdev->priv;
681 
682  /* Unregister network device */
684 
685  /* Reset the function via admin queue */
686  intelxlvf_reset_admin ( intelxl );
687 
688  /* Close admin queues */
689  intelxl_close_admin ( intelxl );
690 
691  /* Disable MSI-X dummy interrupt */
692  intelxl_msix_disable ( intelxl, pci );
693 
694  /* Reset the function via PCIe FLR */
695  intelxlvf_reset_flr ( intelxl, pci );
696 
697  /* Free network device */
698  iounmap ( intelxl->regs );
700  netdev_put ( netdev );
701 }
702 
703 /** PCI device IDs */
704 static struct pci_device_id intelxlvf_nics[] = {
705  PCI_ROM ( 0x8086, 0x154c, "xl710-vf", "XL710 VF", 0 ),
706  PCI_ROM ( 0x8086, 0x1571, "xl710-vf-hv", "XL710 VF (Hyper-V)", 0 ),
707  PCI_ROM ( 0x8086, 0x1889, "xl710-vf-ad", "XL710 VF (adaptive)", 0 ),
708  PCI_ROM ( 0x8086, 0x37cd, "x722-vf", "X722 VF", 0 ),
709  PCI_ROM ( 0x8086, 0x37d9, "x722-vf-hv", "X722 VF (Hyper-V)", 0 ),
710 };
711 
712 /** PCI driver */
713 struct pci_driver intelxlvf_driver __pci_driver = {
714  .ids = intelxlvf_nics,
715  .id_count = ( sizeof ( intelxlvf_nics ) /
716  sizeof ( intelxlvf_nics[0] ) ),
719 };
#define INTELXL_RESET_DELAY_MS
Time to delay for device reset, in milliseconds.
Definition: intelxl.h:993
struct intelxl_admin_vf_configure_buffer cfg
VF Configure Queues data buffer.
Definition: intelxl.h:510
struct intelxl_admin_descriptor * intelxl_admin_command_descriptor(struct intelxl_nic *intelxl)
Get next admin command queue descriptor.
Definition: intelxl.c:290
int intelxl_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: intelxl.c:1465
void * regs
Registers.
Definition: intelxl.h:1030
static void intelxlvf_close(struct net_device *netdev)
Close network device.
Definition: intelxlvf.c:542
uint32_t tx
Transmit queue bitmask.
Definition: intelxl.h:459
unsigned long membase
Memory base.
Definition: pci.h:194
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct pci_driver intelxlvf_driver __pci_driver
PCI driver.
Definition: intelxlvf.c:713
unsigned short uint16_t
Definition: stdint.h:11
#define INTELXLVF_ADMIN_EVT_LEN
Admin Event Queue Length Register (offset)
Definition: intelxlvf.h:51
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:224
static int intelxlvf_admin_configure(struct net_device *netdev)
Configure queues.
Definition: intelxlvf.c:365
static int intelxlvf_admin_irq_map(struct net_device *netdev)
Configure IRQ mapping.
Definition: intelxlvf.c:401
#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:49
int vret
Current VF return value.
Definition: intelxl.h:1063
static int intelxlvf_probe(struct pci_device *pci)
Probe PCI device.
Definition: intelxlvf.c:583
static int intelxlvf_admin_promisc(struct net_device *netdev)
Configure promiscuous mode.
Definition: intelxlvf.c:462
void intelxl_msix_disable(struct intelxl_nic *intelxl, struct pci_device *pci)
Disable MSI-X dummy interrupt.
Definition: intelxl.c:159
Admin queue register offsets.
Definition: intelxl.h:62
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:226
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:409
Admin queue.
Definition: intelxl.h:560
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:320
struct intelxl_admin command
Admin command queue.
Definition: intelxl.h:1056
uint16_t vsi
VSI switching element ID.
Definition: intelxl.h:324
#define INTELXLVF_BAR_SIZE
BAR size.
Definition: intelxlvf.h:15
struct intelxl_admin_vf_irq_map_buffer irq
Definition: intelxl.h:516
union intelxl_admin_buffer * intelxl_admin_command_buffer(struct intelxl_nic *intelxl)
Get next admin command queue data buffer.
Definition: intelxl.c:307
struct intelxl_admin_vf_get_resources_buffer res
VF Get Resources data buffer.
Definition: intelxl.h:506
#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:417
uint32_t rx
Receive queue bitmask.
Definition: intelxl.h:457
#define INTELXLVF_VFGEN_RSTAT_VFR_STATE(x)
Definition: intelxlvf.h:64
#define INTELXL_ALIGN
Alignment.
Definition: intelxl.h:25
uint16_t vsi
VSI switching element ID.
Definition: intelxl.h:453
unsigned int bal
Base Address Low Register offset.
Definition: intelxl.h:64
size_t mfs
Maximum frame size.
Definition: intelxl.h:1032
uint32_t event
Event type.
Definition: intelxl.h:350
int intelxl_open_admin(struct intelxl_nic *intelxl)
Open admin queues.
Definition: intelxl.c:833
#define INTELXLVF_ADMIN
VF Admin Queue register block.
Definition: intelxlvf.h:27
union intelxl_tx_descriptor * tx
Transmit descriptors.
Definition: intelxl.h:868
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:149
struct device dev
Generic device.
Definition: pci.h:189
#define INTELXL_ADMIN_VF_STATUS_LINK
Link status change event type.
Definition: intelxl.h:335
struct intelxl_admin_vf_status_buffer stat
VF Status Change Event data buffer.
Definition: intelxl.h:508
#define PCI_EXP_DEVCTL_FLR
Function level reset.
Definition: pci.h:111
unsigned int exp
PCI Express capability offset.
Definition: intelxl.h:1053
uint32_t mfs
Maximum frame size.
Definition: intelxl.h:399
#define INTELXL_ADMIN_SEND_TO_PF
Admin queue Send Message to PF command.
Definition: intelxl.h:308
#define INTELXLVF_VFGEN_RSTAT_VFR_STATE_ACTIVE
Definition: intelxlvf.h:65
#define INTELXL_ADMIN_NUM_DESC
Number of admin queue descriptors.
Definition: intelxl.h:590
int intelxl_msix_enable(struct intelxl_nic *intelxl, struct pci_device *pci)
Enable MSI-X dummy interrupt.
Definition: intelxl.c:133
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:498
#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:338
#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:528
struct intelxl_ring rx
Receive descriptor ring.
Definition: intelxl.h:1070
static void intelxl_init_admin(struct intelxl_admin *admin, unsigned int base, const struct intelxl_admin_offsets *regs)
Initialise admin queue.
Definition: intelxl.h:582
unsigned int index
Queue index.
Definition: intelxl.h:566
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
#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.
struct intelxl_admin_vf_configure_buffer::@60 tx
Transmit queue.
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
Ethernet protocol.
unsigned int vsi
Virtual Station Interface switching element ID.
Definition: intelxl.h:1043
#define INTELXL_TX_NUM_DESC
Number of transmit descriptors.
Definition: intelxl.h:915
void * priv
Driver private data.
Definition: netdevice.h:425
#define DBGC_HDA(...)
Definition: compiler.h:506
#define INTELXL_ADMIN_VF_CONFIGURE
Admin Queue VF Configure Queues opcode.
Definition: intelxl.h:361
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:768
void * raw
Raw data.
Definition: intelxl.h:872
uint16_t txmap
Transmit queue bitmap.
Definition: intelxl.h:430
static int intelxlvf_admin_get_resources(struct net_device *netdev)
Get resources.
Definition: intelxlvf.c:329
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:924
static int intelxlvf_admin_queues(struct net_device *netdev, int enable)
Enable/disable queues.
Definition: intelxlvf.c:432
#define INTELXL_ADMIN_VF_DISABLE
Admin Queue VF Disable Queues opcode.
Definition: intelxl.h:448
void intelxl_poll_admin(struct net_device *netdev)
Poll admin event queue.
Definition: intelxl.c:780
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
static int intelxlvf_open(struct net_device *netdev)
Open network device.
Definition: intelxlvf.c:491
#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:964
uint64_t base
Base address.
Definition: intelxl.h:382
#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:424
union intelxl_rx_descriptor * rx
Receive descriptors.
Definition: intelxl.h:870
union intelxl_admin_vf_status_buffer::@59 data
Event data.
union intelxl_admin_buffer vbuf
Current VF event data buffer.
Definition: intelxl.h:1065
PCI bus.
A PCI device.
Definition: pci.h:187
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:667
union intelxl_ring::@64 desc
Descriptors.
unsigned int intr
Interrupt control register.
Definition: intelxl.h:1047
uint32_t control
Control.
Definition: myson.h:14
struct intelxl_admin_descriptor * desc
Descriptors.
Definition: intelxl.h:562
A network device.
Definition: netdevice.h:348
struct intelxl_admin_vf_configure_buffer::@61 rx
Receive queue.
#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:511
#define INTELXL_ADMIN_FL_BUF
Admin descriptor uses data buffer.
Definition: intelxl.h:557
int32_t vret
VF return value.
Definition: intelxl.h:539
#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:422
An Intel 40Gigabit network card.
Definition: intelxl.h:1028
#define INTELXL_ADMIN_VF_RESET
Admin Queue VF Reset opcode.
Definition: intelxl.h:314
#define ETH_ALEN
Definition: if_ether.h:8
A PCI device ID list entry.
Definition: pci.h:151
#define le16_to_cpu(value)
Definition: byteswap.h:112
uint16_t vsi
VSI switching element ID.
Definition: intelxl.h:468
unsigned int uint32_t
Definition: stdint.h:12
uint16_t count
Number of queue pairs.
Definition: intelxl.h:368
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:366
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:1068
#define INTELXL_ADMIN_VF_PROMISC
Admin Queue VF Configure Promiscuous Mode opcode.
Definition: intelxl.h:463
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
#define PCI_CAP_ID_EXP
PCI Express.
Definition: pci.h:96
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:346
Network device operations.
Definition: netdevice.h:213
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
static struct net_device_operations intelxlvf_operations
Network device operations.
Definition: intelxlvf.c:563
static struct pci_device_id intelxlvf_nics[]
PCI device IDs.
Definition: intelxlvf.c:704
Network device management.
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:348
uint32_t len
Data buffer length.
Definition: intelxl.h:397
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:522
#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:678
uint16_t rxmap
Receive queue bitmap.
Definition: intelxl.h:428
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:237
struct intelxl_admin_vf_queues_buffer queues
VF Enable/Disable Queues data buffer.
Definition: intelxl.h:512
#define INTELXLVF_VFGEN_RSTAT
VF Reset Status Register.
Definition: intelxlvf.h:63
Admin Queue VF Status Change Event data buffer.
Definition: intelxl.h:348
#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
#define INTELXL_ADMIN_VF_ENABLE
Admin Queue VF Enable Queues opcode.
Definition: intelxl.h:445
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:317
void intelxl_reopen_admin(struct intelxl_nic *intelxl)
Reopen admin queues (after virtual function reset)
Definition: intelxl.c:873
#define INTELXL_ADMIN_PROMISC_FL_UNICAST
Promiscuous unicast mode.
Definition: intelxl.h:254
#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:895
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
#define INTELXL_ADMIN_FL_RD
Admin descriptor uses data buffer for command parameters.
Definition: intelxl.h:554
#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:375
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29
struct intelxl_admin event
Admin event queue.
Definition: intelxl.h:1058
#define INTELXL_ADMIN_PROMISC_FL_MULTICAST
Promiscuous multicast mode.
Definition: intelxl.h:257
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
String functions.
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:283
void intelxl_empty_rx(struct intelxl_nic *intelxl)
Discard unused receive I/O buffers.
Definition: intelxl.c:1337
uint8_t mac[ETH_ALEN]
MAC address.
Definition: intelxl.h:328
void intelxl_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: intelxl.c:1587
#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:923
Admin queue data buffer.
Definition: intelxl.h:498
unsigned int vopcode
Current VF opcode.
Definition: intelxl.h:1061
#define PCI_EXP_DEVCTL
PCI Express.
Definition: pci.h:110
uint32_t vopcode
VF opcode.
Definition: intelxl.h:536
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:332
void * memset(void *dest, int character, size_t len) __nonnull
struct intelxl_admin_vf_status_link link
Link change event data.
Definition: intelxl.h:354
#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:514