2 * vxge-main.c: iPXE driver for Neterion Inc's X3100 Series 10GbE
3 * PCIe I/O Virtualized Server Adapter.
5 * Copyright(c) 2002-2010 Neterion Inc.
7 * This software may be used and distributed according to the terms of
8 * the GNU General Public License (GPL), incorporated herein by
9 * reference. Drivers based on or derived from this code fall under
10 * the GPL and must retain the authorship, copyright and license
15 FILE_LICENCE(GPL2_ONLY);
24 #include <ipxe/malloc.h>
25 #include <ipxe/if_ether.h>
26 #include <ipxe/ethernet.h>
27 #include <ipxe/iobuf.h>
28 #include <ipxe/netdevice.h>
29 #include <ipxe/timer.h>
32 #include "vxge_main.h"
35 /* function modes strings */
36 static char *vxge_func_mode_names[] = {
37 "Single Function - 1 func, 17 vpath",
38 "Multi Function 8 - 8 func, 2 vpath per func",
39 "SRIOV 17 - 17 VF, 1 vpath per VF",
40 "WLPEX/SharedIO 17 - 17 VH, 1 vpath/func/hierarchy",
41 "WLPEX/SharedIO 8 - 8 VH, 2 vpath/func/hierarchy",
42 "Multi Function 17 - 17 func, 1 vpath per func",
43 "SRIOV 8 - 1 PF, 7 VF, 2 vpath per VF",
44 "SRIOV 4 - 1 PF, 3 VF, 4 vpath per VF",
45 "Multi Function 2 - 2 func, 8 vpath per func",
46 "Multi Function 4 - 4 func, 4 vpath per func",
47 "WLPEX/SharedIO 4 - 17 func, 1 vpath per func (PCIe ARI)",
48 "Multi Function 8 - For ESX DirectIO - 8 func, 2 vpath per func",
51 static inline int is_vxge_card_up(struct vxgedev *vdev)
53 return test_bit(__VXGE_STATE_CARD_UP, vdev->state);
59 * If an interrupt was raised to indicate DMA complete of the Tx packet,
60 * this function is called. It identifies the last TxD whose buffer was
61 * freed and frees all skbs whose data have already DMA'ed into the NICs
65 vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw,
66 struct vxge_hw_fifo_txd *txdp, enum vxge_hw_fifo_tcode tcode)
68 struct net_device *netdev;
69 struct io_buffer *tx_iob = NULL;
73 netdev = fifo_hw->vpathh->hldev->ndev;
75 tx_iob = (struct io_buffer *)(intptr_t)txdp->host_control;
77 if (tcode == VXGE_HW_FIFO_T_CODE_OK) {
78 netdev_tx_complete(netdev, tx_iob);
80 netdev_tx_complete_err(netdev, tx_iob, -EINVAL);
81 vxge_debug(VXGE_ERR, "%s: transmit failed, tcode %d\n",
85 memset(txdp, 0, sizeof(struct vxge_hw_fifo_txd));
91 enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
93 enum vxge_hw_status status = VXGE_HW_OK;
94 struct __vxge_hw_virtualpath *vpath;
98 vpath = vdev->vpath.vpathh;
101 if ((status = vxge_hw_vpath_reset(vpath)) == VXGE_HW_OK) {
102 if (is_vxge_card_up(vdev) &&
103 (status = vxge_hw_vpath_recover_from_reset(
104 vpath)) != VXGE_HW_OK) {
105 vxge_debug(VXGE_ERR, "vxge_hw_vpath_recover_"
106 "from_reset failed\n");
109 status = __vxge_hw_vpath_reset_check(vpath);
110 if (status != VXGE_HW_OK) {
112 "__vxge_hw_vpath_reset_check error\n");
117 vxge_debug(VXGE_ERR, "vxge_hw_vpath_reset failed\n");
125 void vxge_close_vpaths(struct vxgedev *vdev)
128 if (vdev->vpath.vpathh && vdev->vpath.is_open)
129 vxge_hw_vpath_close(vdev->vpath.vpathh);
131 vdev->vpath.is_open = 0;
132 vdev->vpath.vpathh = NULL;
136 int vxge_open_vpaths(struct vxgedev *vdev)
138 enum vxge_hw_status status;
139 struct __vxge_hw_device *hldev;
141 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
143 vdev->vpath.vpathh = &hldev->virtual_path;
144 vdev->vpath.fifo.ndev = vdev->ndev;
145 vdev->vpath.fifo.pdev = vdev->pdev;
146 vdev->vpath.fifo.fifoh = &hldev->virtual_path.fifoh;
147 vdev->vpath.ring.ndev = vdev->ndev;
148 vdev->vpath.ring.pdev = vdev->pdev;
149 vdev->vpath.ring.ringh = &hldev->virtual_path.ringh;
151 status = vxge_hw_vpath_open(vdev->devh, &vdev->vpath);
152 if (status == VXGE_HW_OK) {
153 vdev->vpath.is_open = 1;
156 "%s: vpath: %d failed to open "
158 vdev->ndev->name, vdev->vpath.device_id,
160 vxge_close_vpaths(vdev);
164 hldev->vpaths_deployed |= vxge_mBIT(vdev->vpath.vpathh->vp_id);
169 /** Functions that implement the iPXE driver API **/
173 * @skb : the socket buffer containing the Tx data.
174 * @dev : device pointer.
176 * This function is the Tx entry point of the driver. Neterion NIC supports
177 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
180 vxge_xmit(struct net_device *dev, struct io_buffer *iobuf)
182 struct vxge_fifo *fifo = NULL;
183 struct vxgedev *vdev = NULL;
184 struct __vxge_hw_fifo *fifoh;
185 struct vxge_hw_fifo_txd *txdp;
189 vdev = (struct vxgedev *)netdev_priv(dev);
191 if (!is_vxge_card_up(vdev)) {
193 "%s: vdev not initialized\n", dev->name);
197 if (!netdev_link_ok(dev)) {
199 "%s: Link down, transmit failed\n", dev->name);
203 fifo = &vdev->vpath.fifo;
206 txdp = vxge_hw_fifo_free_txdl_get(fifoh);
209 "%s: Out of tx descriptors\n", dev->name);
213 vxge_debug(VXGE_XMIT, "%s: %s:%d fifoh offset= %d\n",
214 dev->name, __func__, __LINE__, fifoh->sw_offset);
216 vxge_hw_fifo_txdl_buffer_set(fifoh, txdp, iobuf);
218 vxge_hw_fifo_txdl_post(fifoh, txdp);
225 * @ndev: net device pointer
227 * This function acks the interrupt. It polls for rx packets
228 * and send to upper layer. It also checks for tx completion
231 static void vxge_poll(struct net_device *ndev)
233 struct __vxge_hw_device *hldev;
234 struct vxgedev *vdev;
236 vxge_debug(VXGE_POLL, "%s:%d \n", __func__, __LINE__);
238 vdev = (struct vxgedev *)netdev_priv(ndev);
239 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
241 if (!is_vxge_card_up(vdev))
244 /* process alarm and acknowledge the interrupts */
245 vxge_hw_device_begin_irq(hldev);
247 vxge_hw_vpath_poll_tx(&hldev->virtual_path.fifoh);
249 vxge_hw_vpath_poll_rx(&hldev->virtual_path.ringh);
253 * vxge_irq - enable or Disable interrupts
255 * @netdev netdevice structure reference
256 * @action requested interrupt action
258 static void vxge_irq(struct net_device *netdev __unused, int action)
260 struct __vxge_hw_device *hldev;
261 struct vxgedev *vdev;
263 vxge_debug(VXGE_INFO,
264 "%s:%d action(%d)\n", __func__, __LINE__, action);
266 vdev = (struct vxgedev *)netdev_priv(netdev);
267 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
271 vxge_hw_device_mask_all(hldev);
274 vxge_hw_device_unmask_all(hldev);
281 * @dev: pointer to the device structure.
283 * This function is the open entry point of the driver. It mainly calls a
284 * function to allocate Rx buffers and inserts them into the buffer
285 * descriptors and then enables the Rx part of the NIC.
286 * Return value: '0' on success and an appropriate (-)ve integer as
287 * defined in errno.h file on failure.
290 vxge_open(struct net_device *dev)
292 enum vxge_hw_status status;
293 struct vxgedev *vdev;
294 struct __vxge_hw_device *hldev;
297 vxge_debug(VXGE_INFO, "%s: %s:%d\n",
298 VXGE_DRIVER_NAME, __func__, __LINE__);
300 vdev = (struct vxgedev *)netdev_priv(dev);
301 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
303 /* make sure you have link off by default every time Nic is
305 netdev_link_down(dev);
308 status = vxge_open_vpaths(vdev);
309 if (status != VXGE_HW_OK) {
310 vxge_debug(VXGE_ERR, "%s: fatal: Vpath open failed\n",
316 vdev->mtu = VXGE_HW_DEFAULT_MTU;
317 /* set initial mtu before enabling the device */
318 status = vxge_hw_vpath_mtu_set(vdev->vpath.vpathh, vdev->mtu);
319 if (status != VXGE_HW_OK) {
321 "%s: fatal: can not set new MTU\n", dev->name);
325 vxge_debug(VXGE_INFO,
326 "%s: MTU is %d\n", vdev->ndev->name, vdev->mtu);
328 set_bit(__VXGE_STATE_CARD_UP, vdev->state);
332 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
333 netdev_link_up(vdev->ndev);
334 vxge_debug(VXGE_INFO, "%s: Link Up\n", vdev->ndev->name);
337 vxge_hw_device_intr_enable(hldev);
339 vxge_hw_vpath_enable(vdev->vpath.vpathh);
341 vxge_hw_vpath_rx_doorbell_init(vdev->vpath.vpathh);
346 vxge_close_vpaths(vdev);
348 vxge_debug(VXGE_INFO, "%s: %s:%d Exiting...\n",
349 dev->name, __func__, __LINE__);
355 * @dev: device pointer.
357 * This is the stop entry point of the driver. It needs to undo exactly
358 * whatever was done by the open entry point, thus it's usually referred to
359 * as the close function.Among other things this function mainly stops the
360 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
361 * Return value: '0' on success and an appropriate (-)ve integer as
362 * defined in errno.h file on failure.
364 static void vxge_close(struct net_device *dev)
366 struct vxgedev *vdev;
367 struct __vxge_hw_device *hldev;
369 vxge_debug(VXGE_INFO, "%s: %s:%d\n",
370 dev->name, __func__, __LINE__);
372 vdev = (struct vxgedev *)netdev_priv(dev);
373 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
375 if (!is_vxge_card_up(vdev))
378 clear_bit(__VXGE_STATE_CARD_UP, vdev->state);
380 vxge_hw_vpath_set_zero_rx_frm_len(hldev);
382 netdev_link_down(vdev->ndev);
383 vxge_debug(VXGE_INFO, "%s: Link Down\n", vdev->ndev->name);
385 /* Note that at this point xmit() is stopped by upper layer */
386 vxge_hw_device_intr_disable(hldev);
388 /* Multi function shares INTA, hence we should
389 * leave it in enabled state
391 if (is_mf(hldev->hw_info.function_mode))
392 vxge_hw_device_unmask_all(hldev);
394 vxge_reset_all_vpaths(vdev);
396 vxge_close_vpaths(vdev);
398 vxge_debug(VXGE_INFO,
399 "%s: %s:%d Exiting...\n", dev->name, __func__, __LINE__);
402 static struct net_device_operations vxge_operations;
404 int vxge_device_register(struct __vxge_hw_device *hldev,
405 struct vxgedev **vdev_out)
407 struct net_device *ndev;
408 struct vxgedev *vdev;
413 ndev = alloc_etherdev(sizeof(struct vxgedev));
415 vxge_debug(VXGE_ERR, "%s : device allocation failed\n",
421 vxge_debug(VXGE_INFO, "%s:%d netdev registering\n",
423 vdev = netdev_priv(ndev);
424 memset(vdev, 0, sizeof(struct vxgedev));
428 vdev->pdev = hldev->pdev;
430 ndev->dev = &vdev->pdev->dev;
431 /* Associate vxge-specific network operations operations with
432 * generic network device layer */
433 netdev_init(ndev, &vxge_operations);
435 memcpy(ndev->hw_addr,
436 (u8 *)hldev->hw_info.mac_addrs[hldev->first_vp_id], ETH_ALEN);
438 if (register_netdev(ndev)) {
439 vxge_debug(VXGE_ERR, "%s : device registration failed!\n",
445 /* Leave link state as off at this point, when the link change
446 * interrupt comes the state will be automatically changed to
450 vxge_debug(VXGE_INFO, "%s: Ethernet device registered\n",
463 * vxge_device_unregister
465 * This function will unregister and free network device
468 vxge_device_unregister(struct __vxge_hw_device *hldev)
470 struct net_device *ndev;
474 unregister_netdev(ndev);
475 netdev_nullify(ndev);
478 vxge_debug(VXGE_INFO, "%s: ethernet device unregistered\n",
484 * @pdev : structure containing the PCI related information of the device.
485 * @id: List of PCI devices supported by the driver listed in vxge_id_table.
487 * This function is called when a new PCI device gets detected and initializes
490 * returns 0 on success and negative on failure.
494 vxge_probe(struct pci_device *pdev)
496 struct __vxge_hw_device *hldev;
497 enum vxge_hw_status status;
500 struct vxgedev *vdev;
504 unsigned long mmio_start, mmio_len;
506 struct vxge_hw_device_hw_info hw_info;
507 struct vxge_hw_device_version *fw_version;
509 vxge_debug(VXGE_INFO, "vxge_probe for device " PCI_FMT "\n",
512 pci_read_config_byte(pdev, PCI_REVISION_ID, &revision);
513 titan1 = is_titan1(pdev->device, revision);
515 mmio_start = pci_bar_start(pdev, PCI_BASE_ADDRESS_0);
516 mmio_len = pci_bar_size(pdev, PCI_BASE_ADDRESS_0);
517 vxge_debug(VXGE_INFO, "mmio_start: %#08lx, mmio_len: %#08lx\n",
518 mmio_start, mmio_len);
520 /* sets the bus master */
521 adjust_pci_device(pdev);
523 bar0 = ioremap(mmio_start, mmio_len);
526 "%s : cannot remap io memory bar0\n", __func__);
531 status = vxge_hw_device_hw_info_get(pdev, bar0, &hw_info);
532 if (status != VXGE_HW_OK) {
534 "%s: Reading of hardware info failed.\n",
540 if (hw_info.func_id != 0) {
541 /* Non zero function, So do not load the driver */
543 pci_set_drvdata(pdev, NULL);
548 vpath_mask = hw_info.vpath_mask;
549 if (vpath_mask == 0) {
551 "%s: No vpaths available in device\n",
556 vxge_debug(VXGE_INFO,
557 "%s:%d Vpath mask = %llx\n", __func__, __LINE__,
558 (unsigned long long)vpath_mask);
560 fw_version = &hw_info.fw_version;
561 /* fail the driver loading if firmware is incompatible */
562 if ((fw_version->major != VXGE_CERT_FW_VER_MAJOR) ||
563 (fw_version->minor < VXGE_CERT_FW_VER_MINOR)) {
564 printf("%s: Adapter's current firmware version: %d.%d.%d\n",
565 VXGE_DRIVER_NAME, fw_version->major,
566 fw_version->minor, fw_version->build);
568 printf("%s: Upgrade firmware to version %d.%d.%d\n",
569 VXGE_DRIVER_NAME, VXGE_CERT_FW_VER_MAJOR,
570 VXGE_CERT_FW_VER_MINOR, VXGE_CERT_FW_VER_BUILD);
576 status = vxge_hw_device_initialize(&hldev, bar0, pdev, titan1);
577 if (status != VXGE_HW_OK) {
579 "Failed to initialize device (%d)\n", status);
583 memcpy(&hldev->hw_info, &hw_info,
584 sizeof(struct vxge_hw_device_hw_info));
586 /* find the vpath id of the first available one */
587 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
588 if (vpath_mask & vxge_mBIT(i)) {
589 hldev->first_vp_id = i;
592 /* if FCS stripping is not disabled in MAC fail driver load */
593 if (vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask) != VXGE_HW_OK) {
595 "%s: FCS stripping is not disabled in MAC"
596 " failing driver load\n", VXGE_DRIVER_NAME);
601 /* Read function mode */
602 status = vxge_hw_get_func_mode(hldev, &function_mode);
603 if (status != VXGE_HW_OK)
606 hldev->hw_info.function_mode = function_mode;
608 /* set private device info */
609 pci_set_drvdata(pdev, hldev);
611 if (vxge_device_register(hldev, &vdev)) {
616 /* set private HW device info */
617 hldev->ndev = vdev->ndev;
620 vdev->mtu = VXGE_HW_DEFAULT_MTU;
622 vdev->titan1 = titan1;
623 /* Virtual Path count */
624 vdev->vpath.device_id = hldev->first_vp_id;
625 vdev->vpath.vdev = vdev;
626 memcpy((u8 *)vdev->vpath.macaddr,
627 (u8 *)hldev->hw_info.mac_addrs[hldev->first_vp_id],
630 hldev->hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
631 hldev->hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
632 hldev->hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
634 vxge_debug(VXGE_INFO, "%s: Neterion %s Server Adapter\n",
635 VXGE_DRIVER_NAME, hldev->hw_info.product_desc);
636 vxge_debug(VXGE_INFO, "%s: SERIAL NUMBER: %s\n",
637 VXGE_DRIVER_NAME, hldev->hw_info.serial_number);
638 vxge_debug(VXGE_INFO, "%s: PART NUMBER: %s\n",
639 VXGE_DRIVER_NAME, hldev->hw_info.part_number);
640 vxge_debug(VXGE_INFO, "%s: MAC ADDR: %s\n",
641 VXGE_DRIVER_NAME, eth_ntoa(vdev->vpath.macaddr));
642 vxge_debug(VXGE_INFO,
643 "%s: Firmware version : %s Date : %s\n", VXGE_DRIVER_NAME,
644 hldev->hw_info.fw_version.version,
645 hldev->hw_info.fw_date.date);
646 vxge_debug(VXGE_INFO, "%s: %s Enabled\n",
647 VXGE_DRIVER_NAME, vxge_func_mode_names[function_mode]);
649 vxge_debug(VXGE_INFO, "%s: %s:%d Probe Exiting...\n",
650 VXGE_DRIVER_NAME, __func__, __LINE__);
655 vxge_hw_device_terminate(hldev);
659 pci_set_drvdata(pdev, NULL);
660 printf("%s: WARNING!! Driver loading failed!!\n",
667 * vxge_remove - Free the PCI device
668 * @pdev: structure containing the PCI related information of the device.
669 * Description: This function is called by the Pci subsystem to release a
670 * PCI device and free up all resource held up by the device.
673 vxge_remove(struct pci_device *pdev)
675 struct __vxge_hw_device *hldev;
676 struct vxgedev *vdev = NULL;
677 struct net_device *ndev;
679 vxge_debug(VXGE_INFO,
680 "%s:%d\n", __func__, __LINE__);
681 hldev = (struct __vxge_hw_device *) pci_get_drvdata(pdev);
686 vdev = netdev_priv(ndev);
690 vxge_device_unregister(hldev);
692 vxge_debug(VXGE_INFO,
693 "%s:%d Device unregistered\n", __func__, __LINE__);
695 vxge_hw_device_terminate(hldev);
696 pci_set_drvdata(pdev, NULL);
699 /* vxge net device operations */
700 static struct net_device_operations vxge_operations = {
703 .transmit = vxge_xmit,
708 static struct pci_device_id vxge_main_nics[] = {
709 /* If you change this, also adjust vxge_nics[] in vxge.c */
710 PCI_ID(0x17d5, 0x5833, "vxge-x3100", "Neterion X3100 Series", 0),
713 struct pci_driver vxge_driver __pci_driver = {
714 .ids = vxge_main_nics,
715 .id_count = (sizeof(vxge_main_nics) / sizeof(vxge_main_nics[0])),
717 .remove = vxge_remove,