2 * vxge-main.c: gPXE 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 <gpxe/malloc.h>
25 #include <gpxe/if_ether.h>
26 #include <gpxe/ethernet.h>
27 #include <gpxe/iobuf.h>
28 #include <gpxe/netdevice.h>
29 #include <gpxe/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)",
50 static inline int is_vxge_card_up(struct vxgedev
*vdev
)
52 return test_bit(__VXGE_STATE_CARD_UP
, vdev
->state
);
58 * If an interrupt was raised to indicate DMA complete of the Tx packet,
59 * this function is called. It identifies the last TxD whose buffer was
60 * freed and frees all skbs whose data have already DMA'ed into the NICs
64 vxge_xmit_compl(struct __vxge_hw_fifo
*fifo_hw
,
65 struct vxge_hw_fifo_txd
*txdp
, enum vxge_hw_fifo_tcode tcode
)
67 struct net_device
*netdev
;
68 struct io_buffer
*tx_iob
= NULL
;
72 netdev
= fifo_hw
->vpathh
->hldev
->ndev
;
74 tx_iob
= (struct io_buffer
*)(intptr_t)txdp
->host_control
;
76 if (tcode
== VXGE_HW_FIFO_T_CODE_OK
) {
77 netdev_tx_complete(netdev
, tx_iob
);
79 netdev_tx_complete_err(netdev
, tx_iob
, -EINVAL
);
80 vxge_debug(VXGE_ERR
, "%s: transmit failed, tcode %d\n",
84 memset(txdp
, 0, sizeof(struct vxge_hw_fifo_txd
));
90 enum vxge_hw_status
vxge_reset_all_vpaths(struct vxgedev
*vdev
)
92 enum vxge_hw_status status
= VXGE_HW_OK
;
93 struct __vxge_hw_virtualpath
*vpath
;
97 vpath
= vdev
->vpath
.vpathh
;
100 if ((status
= vxge_hw_vpath_reset(vpath
)) == VXGE_HW_OK
) {
101 if (is_vxge_card_up(vdev
) &&
102 (status
= vxge_hw_vpath_recover_from_reset(
103 vpath
)) != VXGE_HW_OK
) {
104 vxge_debug(VXGE_ERR
, "vxge_hw_vpath_recover_"
105 "from_reset failed\n");
108 status
= __vxge_hw_vpath_reset_check(vpath
);
109 if (status
!= VXGE_HW_OK
) {
111 "__vxge_hw_vpath_reset_check error\n");
116 vxge_debug(VXGE_ERR
, "vxge_hw_vpath_reset failed\n");
124 void vxge_close_vpaths(struct vxgedev
*vdev
)
127 if (vdev
->vpath
.vpathh
&& vdev
->vpath
.is_open
)
128 vxge_hw_vpath_close(vdev
->vpath
.vpathh
);
130 vdev
->vpath
.is_open
= 0;
131 vdev
->vpath
.vpathh
= NULL
;
135 int vxge_open_vpaths(struct vxgedev
*vdev
)
137 enum vxge_hw_status status
;
138 struct __vxge_hw_device
*hldev
;
140 hldev
= (struct __vxge_hw_device
*)pci_get_drvdata(vdev
->pdev
);
142 vdev
->vpath
.vpathh
= &hldev
->virtual_path
;
143 vdev
->vpath
.fifo
.ndev
= vdev
->ndev
;
144 vdev
->vpath
.fifo
.pdev
= vdev
->pdev
;
145 vdev
->vpath
.fifo
.fifoh
= &hldev
->virtual_path
.fifoh
;
146 vdev
->vpath
.ring
.ndev
= vdev
->ndev
;
147 vdev
->vpath
.ring
.pdev
= vdev
->pdev
;
148 vdev
->vpath
.ring
.ringh
= &hldev
->virtual_path
.ringh
;
150 status
= vxge_hw_vpath_open(vdev
->devh
, &vdev
->vpath
);
151 if (status
== VXGE_HW_OK
) {
152 vdev
->vpath
.is_open
= 1;
155 "%s: vpath: %d failed to open "
157 vdev
->ndev
->name
, vdev
->vpath
.device_id
,
159 vxge_close_vpaths(vdev
);
163 hldev
->vpaths_deployed
|= vxge_mBIT(vdev
->vpath
.vpathh
->vp_id
);
168 /** Functions that implement the gPXE driver API **/
172 * @skb : the socket buffer containing the Tx data.
173 * @dev : device pointer.
175 * This function is the Tx entry point of the driver. Neterion NIC supports
176 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
179 vxge_xmit(struct net_device
*dev
, struct io_buffer
*iobuf
)
181 struct vxge_fifo
*fifo
= NULL
;
182 struct vxgedev
*vdev
= NULL
;
183 struct __vxge_hw_fifo
*fifoh
;
184 struct __vxge_hw_device
*hldev
;
185 struct vxge_hw_fifo_txd
*txdp
;
189 vdev
= (struct vxgedev
*)netdev_priv(dev
);
190 hldev
= (struct __vxge_hw_device
*)pci_get_drvdata(vdev
->pdev
);
192 if (!is_vxge_card_up(vdev
)) {
194 "%s: vdev not initialized\n", dev
->name
);
198 if (!netdev_link_ok(dev
)) {
200 "%s: Link down, transmit failed\n", dev
->name
);
204 fifo
= &vdev
->vpath
.fifo
;
207 txdp
= vxge_hw_fifo_free_txdl_get(fifoh
);
210 "%s: Out of tx descriptors\n", dev
->name
);
214 vxge_debug(VXGE_XMIT
, "%s: %s:%d fifoh offset= %d\n",
215 dev
->name
, __func__
, __LINE__
, fifoh
->sw_offset
);
217 vxge_hw_fifo_txdl_buffer_set(fifoh
, txdp
, iobuf
);
219 vxge_hw_fifo_txdl_post(fifoh
, txdp
);
226 * @ndev: net device pointer
228 * This function acks the interrupt. It polls for rx packets
229 * and send to upper layer. It also checks for tx completion
232 static void vxge_poll(struct net_device
*ndev
)
234 struct __vxge_hw_device
*hldev
;
235 struct vxgedev
*vdev
;
237 vxge_debug(VXGE_POLL
, "%s:%d \n", __func__
, __LINE__
);
239 vdev
= (struct vxgedev
*)netdev_priv(ndev
);
240 hldev
= (struct __vxge_hw_device
*)pci_get_drvdata(vdev
->pdev
);
242 if (!is_vxge_card_up(vdev
))
245 /* process alarm and acknowledge the interrupts */
246 vxge_hw_device_begin_irq(hldev
);
248 vxge_hw_vpath_poll_tx(&hldev
->virtual_path
.fifoh
);
250 vxge_hw_vpath_poll_rx(&hldev
->virtual_path
.ringh
);
254 * vxge_irq - enable or Disable interrupts
256 * @netdev netdevice sturcture reference
257 * @action requested interrupt action
259 static void vxge_irq(struct net_device
*netdev __unused
, int action
)
261 struct __vxge_hw_device
*hldev
;
262 struct vxgedev
*vdev
;
264 vxge_debug(VXGE_INFO
,
265 "%s:%d action(%d)\n", __func__
, __LINE__
, action
);
267 vdev
= (struct vxgedev
*)netdev_priv(netdev
);
268 hldev
= (struct __vxge_hw_device
*)pci_get_drvdata(vdev
->pdev
);
272 vxge_hw_device_mask_all(hldev
);
275 vxge_hw_device_unmask_all(hldev
);
282 * @dev: pointer to the device structure.
284 * This function is the open entry point of the driver. It mainly calls a
285 * function to allocate Rx buffers and inserts them into the buffer
286 * descriptors and then enables the Rx part of the NIC.
287 * Return value: '0' on success and an appropriate (-)ve integer as
288 * defined in errno.h file on failure.
291 vxge_open(struct net_device
*dev
)
293 enum vxge_hw_status status
;
294 struct vxgedev
*vdev
;
295 struct __vxge_hw_device
*hldev
;
298 vxge_debug(VXGE_INFO
, "%s: %s:%d\n",
299 VXGE_DRIVER_NAME
, __func__
, __LINE__
);
301 vdev
= (struct vxgedev
*)netdev_priv(dev
);
302 hldev
= (struct __vxge_hw_device
*)pci_get_drvdata(vdev
->pdev
);
304 /* make sure you have link off by default every time Nic is
306 netdev_link_down(dev
);
309 status
= vxge_open_vpaths(vdev
);
310 if (status
!= VXGE_HW_OK
) {
311 vxge_debug(VXGE_ERR
, "%s: fatal: Vpath open failed\n",
317 vdev
->mtu
= VXGE_HW_DEFAULT_MTU
;
318 /* set initial mtu before enabling the device */
319 status
= vxge_hw_vpath_mtu_set(vdev
->vpath
.vpathh
, vdev
->mtu
);
320 if (status
!= VXGE_HW_OK
) {
322 "%s: fatal: can not set new MTU\n", dev
->name
);
326 vxge_debug(VXGE_INFO
,
327 "%s: MTU is %d\n", vdev
->ndev
->name
, vdev
->mtu
);
329 set_bit(__VXGE_STATE_CARD_UP
, vdev
->state
);
333 if (vxge_hw_device_link_state_get(vdev
->devh
) == VXGE_HW_LINK_UP
) {
334 netdev_link_up(vdev
->ndev
);
335 vxge_debug(VXGE_INFO
, "%s: Link Up\n", vdev
->ndev
->name
);
338 vxge_hw_device_intr_enable(hldev
);
340 vxge_hw_vpath_enable(vdev
->vpath
.vpathh
);
342 vxge_hw_vpath_rx_doorbell_init(vdev
->vpath
.vpathh
);
347 vxge_close_vpaths(vdev
);
349 vxge_debug(VXGE_INFO
, "%s: %s:%d Exiting...\n",
350 dev
->name
, __func__
, __LINE__
);
356 * @dev: device pointer.
358 * This is the stop entry point of the driver. It needs to undo exactly
359 * whatever was done by the open entry point, thus it's usually referred to
360 * as the close function.Among other things this function mainly stops the
361 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
362 * Return value: '0' on success and an appropriate (-)ve integer as
363 * defined in errno.h file on failure.
365 static void vxge_close(struct net_device
*dev
)
367 struct vxgedev
*vdev
;
368 struct __vxge_hw_device
*hldev
;
370 vxge_debug(VXGE_INFO
, "%s: %s:%d\n",
371 dev
->name
, __func__
, __LINE__
);
373 vdev
= (struct vxgedev
*)netdev_priv(dev
);
374 hldev
= (struct __vxge_hw_device
*)pci_get_drvdata(vdev
->pdev
);
376 if (!is_vxge_card_up(vdev
))
379 clear_bit(__VXGE_STATE_CARD_UP
, vdev
->state
);
381 vxge_hw_vpath_set_zero_rx_frm_len(hldev
);
383 netdev_link_down(vdev
->ndev
);
384 vxge_debug(VXGE_INFO
, "%s: Link Down\n", vdev
->ndev
->name
);
386 /* Note that at this point xmit() is stopped by upper layer */
387 vxge_hw_device_intr_disable(hldev
);
389 /* Multi function shares INTA, hence we should
390 * leave it in enabled state
392 if (is_mf(hldev
->hw_info
.function_mode
))
393 vxge_hw_device_unmask_all(hldev
);
395 vxge_reset_all_vpaths(vdev
);
397 vxge_close_vpaths(vdev
);
399 vxge_debug(VXGE_INFO
,
400 "%s: %s:%d Exiting...\n", dev
->name
, __func__
, __LINE__
);
403 static struct net_device_operations vxge_operations
;
405 int vxge_device_register(struct __vxge_hw_device
*hldev
,
406 struct vxgedev
**vdev_out
)
408 struct net_device
*ndev
;
409 struct vxgedev
*vdev
;
414 ndev
= alloc_etherdev(sizeof(struct vxgedev
));
416 vxge_debug(VXGE_ERR
, "%s : device allocation failed\n",
422 vxge_debug(VXGE_INFO
, "%s:%d netdev registering\n",
424 vdev
= netdev_priv(ndev
);
425 memset(vdev
, 0, sizeof(struct vxgedev
));
429 vdev
->pdev
= hldev
->pdev
;
431 ndev
->dev
= &vdev
->pdev
->dev
;
432 /* Associate vxge-specific network operations operations with
433 * generic network device layer */
434 netdev_init(ndev
, &vxge_operations
);
436 memcpy(ndev
->hw_addr
,
437 (u8
*)hldev
->hw_info
.mac_addrs
[hldev
->first_vp_id
], ETH_ALEN
);
439 if (register_netdev(ndev
)) {
440 vxge_debug(VXGE_ERR
, "%s : device registration failed!\n",
446 /* Make Link state as off at this point, when the Link change
447 * interrupt comes the state will be automatically changed to
450 netdev_link_down(ndev
);
452 vxge_debug(VXGE_INFO
, "%s: Ethernet device registered\n",
465 * vxge_device_unregister
467 * This function will unregister and free network device
470 vxge_device_unregister(struct __vxge_hw_device
*hldev
)
472 struct vxgedev
*vdev
;
473 struct net_device
*ndev
;
476 vdev
= netdev_priv(ndev
);
478 unregister_netdev(ndev
);
479 netdev_nullify(ndev
);
482 vxge_debug(VXGE_INFO
, "%s: ethernet device unregistered\n",
488 * @pdev : structure containing the PCI related information of the device.
489 * @id: List of PCI devices supported by the driver listed in vxge_id_table.
491 * This function is called when a new PCI device gets detected and initializes
494 * returns 0 on success and negative on failure.
498 vxge_probe(struct pci_device
*pdev
, const struct pci_device_id
*id __unused
)
500 struct __vxge_hw_device
*hldev
;
501 enum vxge_hw_status status
;
504 struct vxgedev
*vdev
;
509 unsigned long mmio_start
, mmio_len
;
511 struct vxge_hw_device_hw_info hw_info
;
512 struct vxge_hw_device_version
*fw_version
;
514 vxge_debug(VXGE_INFO
, "vxge_probe for device %02X:%02X.%X\n",
515 pdev
->bus
, PCI_SLOT(pdev
->devfn
),
516 PCI_FUNC(pdev
->devfn
));
518 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &revision
);
519 titan1
= is_titan1(pdev
->device
, revision
);
521 mmio_start
= pci_bar_start(pdev
, PCI_BASE_ADDRESS_0
);
522 mmio_len
= pci_bar_size(pdev
, PCI_BASE_ADDRESS_0
);
523 vxge_debug(VXGE_INFO
, "mmio_start: %#08lx, mmio_len: %#08lx\n",
524 mmio_start
, mmio_len
);
526 /* sets the bus master */
527 adjust_pci_device(pdev
);
529 bar0
= ioremap(mmio_start
, mmio_len
);
532 "%s : cannot remap io memory bar0\n", __func__
);
537 status
= vxge_hw_device_hw_info_get(bar0
, &hw_info
);
538 if (status
!= VXGE_HW_OK
) {
540 "%s: Reading of hardware info failed.\n",
546 if (hw_info
.func_id
!= 0) {
547 /* Non zero function, So do not load the driver */
549 pci_set_drvdata(pdev
, NULL
);
554 vpath_mask
= hw_info
.vpath_mask
;
555 if (vpath_mask
== 0) {
557 "%s: No vpaths available in device\n",
562 vxge_debug(VXGE_INFO
,
563 "%s:%d Vpath mask = %llx\n", __func__
, __LINE__
,
564 (unsigned long long)vpath_mask
);
566 host_type
= hw_info
.host_type
;
567 fw_version
= &hw_info
.fw_version
;
568 /* fail the driver loading if firmware is incompatible */
569 if ((fw_version
->major
!= VXGE_CERT_FW_VER_MAJOR
) ||
570 (fw_version
->minor
< VXGE_CERT_FW_VER_MINOR
)) {
571 printf("%s: Adapter's current firmware version: %d.%d.%d\n",
572 VXGE_DRIVER_NAME
, fw_version
->major
,
573 fw_version
->minor
, fw_version
->build
);
575 printf("%s: Upgrade firmware to version %d.%d.%d\n",
576 VXGE_DRIVER_NAME
, VXGE_CERT_FW_VER_MAJOR
,
577 VXGE_CERT_FW_VER_MINOR
, VXGE_CERT_FW_VER_BUILD
);
583 status
= vxge_hw_device_initialize(&hldev
, bar0
, pdev
, titan1
);
584 if (status
!= VXGE_HW_OK
) {
586 "Failed to initialize device (%d)\n", status
);
590 memcpy(&hldev
->hw_info
, &hw_info
,
591 sizeof(struct vxge_hw_device_hw_info
));
593 /* find the vpath id of the first available one */
594 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
595 if (vpath_mask
& vxge_mBIT(i
)) {
596 hldev
->first_vp_id
= i
;
599 /* if FCS stripping is not disabled in MAC fail driver load */
600 if (vxge_hw_vpath_strip_fcs_check(hldev
, vpath_mask
) != VXGE_HW_OK
) {
602 "%s: FCS stripping is not disabled in MAC"
603 " failing driver load\n", VXGE_DRIVER_NAME
);
608 /* Read function mode */
609 status
= vxge_hw_get_func_mode(hldev
, &function_mode
);
610 if (status
!= VXGE_HW_OK
)
613 hldev
->hw_info
.function_mode
= function_mode
;
615 /* set private device info */
616 pci_set_drvdata(pdev
, hldev
);
618 if (vxge_device_register(hldev
, &vdev
)) {
623 /* set private HW device info */
624 hldev
->ndev
= vdev
->ndev
;
627 vdev
->mtu
= VXGE_HW_DEFAULT_MTU
;
629 vdev
->titan1
= titan1
;
630 /* Virtual Path count */
631 vdev
->vpath
.device_id
= hldev
->first_vp_id
;
632 vdev
->vpath
.vdev
= vdev
;
633 memcpy((u8
*)vdev
->vpath
.macaddr
,
634 (u8
*)hldev
->hw_info
.mac_addrs
[hldev
->first_vp_id
],
637 hldev
->hw_info
.serial_number
[VXGE_HW_INFO_LEN
- 1] = '\0';
638 hldev
->hw_info
.product_desc
[VXGE_HW_INFO_LEN
- 1] = '\0';
639 hldev
->hw_info
.part_number
[VXGE_HW_INFO_LEN
- 1] = '\0';
641 vxge_debug(VXGE_INFO
, "%s: Neterion %s Server Adapter\n",
642 VXGE_DRIVER_NAME
, hldev
->hw_info
.product_desc
);
643 vxge_debug(VXGE_INFO
, "%s: SERIAL NUMBER: %s\n",
644 VXGE_DRIVER_NAME
, hldev
->hw_info
.serial_number
);
645 vxge_debug(VXGE_INFO
, "%s: PART NUMBER: %s\n",
646 VXGE_DRIVER_NAME
, hldev
->hw_info
.part_number
);
647 vxge_debug(VXGE_INFO
, "%s: MAC ADDR: %s\n",
648 VXGE_DRIVER_NAME
, eth_ntoa(vdev
->vpath
.macaddr
));
649 vxge_debug(VXGE_INFO
,
650 "%s: Firmware version : %s Date : %s\n", VXGE_DRIVER_NAME
,
651 hldev
->hw_info
.fw_version
.version
,
652 hldev
->hw_info
.fw_date
.date
);
653 vxge_debug(VXGE_INFO
, "%s: %s Enabled\n",
654 VXGE_DRIVER_NAME
, vxge_func_mode_names
[function_mode
]);
656 vxge_debug(VXGE_INFO
, "%s: %s:%d Probe Exiting...\n",
657 VXGE_DRIVER_NAME
, __func__
, __LINE__
);
662 vxge_hw_device_terminate(hldev
);
666 pci_set_drvdata(pdev
, NULL
);
667 printf("%s: WARNING!! Driver loading failed!!\n",
674 * vxge_remove - Free the PCI device
675 * @pdev: structure containing the PCI related information of the device.
676 * Description: This function is called by the Pci subsystem to release a
677 * PCI device and free up all resource held up by the device.
680 vxge_remove(struct pci_device
*pdev
)
682 struct __vxge_hw_device
*hldev
;
683 struct vxgedev
*vdev
= NULL
;
684 struct net_device
*ndev
;
686 vxge_debug(VXGE_INFO
,
687 "%s:%d\n", __func__
, __LINE__
);
688 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
693 vdev
= netdev_priv(ndev
);
697 vxge_device_unregister(hldev
);
699 vxge_debug(VXGE_INFO
,
700 "%s:%d Device unregistered\n", __func__
, __LINE__
);
702 vxge_hw_device_terminate(hldev
);
703 pci_set_drvdata(pdev
, NULL
);
706 /* vxge net device operations */
707 static struct net_device_operations vxge_operations
= {
710 .transmit
= vxge_xmit
,
715 static struct pci_device_id vxge_main_nics
[] = {
716 /* If you change this, also adjust vxge_nics[] in vxge.c */
717 PCI_ID(0x17d5, 0x5833, "vxge-x3100", "Neterion X3100 Series", 0),
720 struct pci_driver vxge_driver __pci_driver
= {
721 .ids
= vxge_main_nics
,
722 .id_count
= (sizeof(vxge_main_nics
) / sizeof(vxge_main_nics
[0])),
724 .remove
= vxge_remove
,