1 /******************************************************************************
2 * This software may be used and distributed according to the terms of
3 * the GNU General Public License (GPL), incorporated herein by reference.
4 * Drivers based on or derived from this code fall under the GPL and must
5 * retain the authorship, copyright and license notice. This file is not
6 * a complete program and may only be used when the entire operating
7 * system is licensed under the GPL.
8 * See the file COPYING in this distribution for more information.
10 * vxge-main.c: Driver for Neterion Inc's X3100 Series 10GbE PCIe I/O
11 * Virtualized Server Adapter.
12 * Copyright(c) 2002-2009 Neterion Inc.
14 * The module loadable parameters that are supported by the driver and a brief
15 * explanation of all the variables:
17 * Strip VLAN Tag enable/disable. Instructs the device to remove
18 * the VLAN tag from all received tagged frames that are not
19 * replicated at the internal L2 switch.
20 * 0 - Do not strip the VLAN tag.
21 * 1 - Strip the VLAN tag.
24 * Enable learning the mac address of the guest OS interface in
25 * a virtualization environment.
30 * Maximum number of port to be supported.
34 * This configures the maximum no of VPATH configures for each
36 * MIN - 1 and MAX - 17
39 * This configures maximum no of Device function to be enabled.
40 * MIN - 1 and MAX - 17
42 ******************************************************************************/
44 #include <linux/if_vlan.h>
45 #include <linux/pci.h>
46 #include <linux/tcp.h>
48 #include <linux/netdevice.h>
49 #include <linux/etherdevice.h>
50 #include "vxge-main.h"
53 MODULE_LICENSE("Dual BSD/GPL");
54 MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
55 "Virtualized Server Adapter");
57 static struct pci_device_id vxge_id_table[] __devinitdata = {
58 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
60 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
65 MODULE_DEVICE_TABLE(pci, vxge_id_table);
67 VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
68 VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
69 VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
70 VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
71 VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
72 VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
74 static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
75 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
76 static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
77 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
78 module_param_array(bw_percentage, uint, NULL, 0);
80 static struct vxge_drv_config *driver_config;
82 static inline int is_vxge_card_up(struct vxgedev *vdev)
84 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
87 static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
89 unsigned long flags = 0;
90 struct sk_buff **skb_ptr = NULL;
91 struct sk_buff **temp;
92 #define NR_SKB_COMPLETED 128
93 struct sk_buff *completed[NR_SKB_COMPLETED];
100 if (spin_trylock_irqsave(&fifo->tx_lock, flags)) {
101 vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
102 NR_SKB_COMPLETED, &more);
103 spin_unlock_irqrestore(&fifo->tx_lock, flags);
106 for (temp = completed; temp != skb_ptr; temp++)
107 dev_kfree_skb_irq(*temp);
111 static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
115 /* Complete all transmits */
116 for (i = 0; i < vdev->no_of_vpath; i++)
117 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
120 static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
123 struct vxge_ring *ring;
125 /* Complete all receives*/
126 for (i = 0; i < vdev->no_of_vpath; i++) {
127 ring = &vdev->vpaths[i].ring;
128 vxge_hw_vpath_poll_rx(ring->handle);
133 * MultiQ manipulation helper functions
135 void vxge_stop_all_tx_queue(struct vxgedev *vdev)
138 struct net_device *dev = vdev->ndev;
140 if (vdev->config.tx_steering_type != TX_MULTIQ_STEERING) {
141 for (i = 0; i < vdev->no_of_vpath; i++)
142 vdev->vpaths[i].fifo.queue_state = VPATH_QUEUE_STOP;
144 netif_tx_stop_all_queues(dev);
147 void vxge_stop_tx_queue(struct vxge_fifo *fifo)
149 struct net_device *dev = fifo->ndev;
151 struct netdev_queue *txq = NULL;
152 if (fifo->tx_steering_type == TX_MULTIQ_STEERING)
153 txq = netdev_get_tx_queue(dev, fifo->driver_id);
155 txq = netdev_get_tx_queue(dev, 0);
156 fifo->queue_state = VPATH_QUEUE_STOP;
159 netif_tx_stop_queue(txq);
162 void vxge_start_all_tx_queue(struct vxgedev *vdev)
165 struct net_device *dev = vdev->ndev;
167 if (vdev->config.tx_steering_type != TX_MULTIQ_STEERING) {
168 for (i = 0; i < vdev->no_of_vpath; i++)
169 vdev->vpaths[i].fifo.queue_state = VPATH_QUEUE_START;
171 netif_tx_start_all_queues(dev);
174 static void vxge_wake_all_tx_queue(struct vxgedev *vdev)
177 struct net_device *dev = vdev->ndev;
179 if (vdev->config.tx_steering_type != TX_MULTIQ_STEERING) {
180 for (i = 0; i < vdev->no_of_vpath; i++)
181 vdev->vpaths[i].fifo.queue_state = VPATH_QUEUE_START;
183 netif_tx_wake_all_queues(dev);
186 void vxge_wake_tx_queue(struct vxge_fifo *fifo, struct sk_buff *skb)
188 struct net_device *dev = fifo->ndev;
190 int vpath_no = fifo->driver_id;
191 struct netdev_queue *txq = NULL;
192 if (fifo->tx_steering_type == TX_MULTIQ_STEERING) {
193 txq = netdev_get_tx_queue(dev, vpath_no);
194 if (netif_tx_queue_stopped(txq))
195 netif_tx_wake_queue(txq);
197 txq = netdev_get_tx_queue(dev, 0);
198 if (fifo->queue_state == VPATH_QUEUE_STOP)
199 if (netif_tx_queue_stopped(txq)) {
200 fifo->queue_state = VPATH_QUEUE_START;
201 netif_tx_wake_queue(txq);
207 * vxge_callback_link_up
209 * This function is called during interrupt context to notify link up state
213 vxge_callback_link_up(struct __vxge_hw_device *hldev)
215 struct net_device *dev = hldev->ndev;
216 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
218 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
219 vdev->ndev->name, __func__, __LINE__);
220 printk(KERN_NOTICE "%s: Link Up\n", vdev->ndev->name);
221 vdev->stats.link_up++;
223 netif_carrier_on(vdev->ndev);
224 vxge_wake_all_tx_queue(vdev);
226 vxge_debug_entryexit(VXGE_TRACE,
227 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
231 * vxge_callback_link_down
233 * This function is called during interrupt context to notify link down state
237 vxge_callback_link_down(struct __vxge_hw_device *hldev)
239 struct net_device *dev = hldev->ndev;
240 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
242 vxge_debug_entryexit(VXGE_TRACE,
243 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
244 printk(KERN_NOTICE "%s: Link Down\n", vdev->ndev->name);
246 vdev->stats.link_down++;
247 netif_carrier_off(vdev->ndev);
248 vxge_stop_all_tx_queue(vdev);
250 vxge_debug_entryexit(VXGE_TRACE,
251 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
259 static struct sk_buff*
260 vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
262 struct net_device *dev;
264 struct vxge_rx_priv *rx_priv;
267 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
268 ring->ndev->name, __func__, __LINE__);
270 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
272 /* try to allocate skb first. this one may fail */
273 skb = netdev_alloc_skb(dev, skb_size +
274 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
276 vxge_debug_mem(VXGE_ERR,
277 "%s: out of memory to allocate SKB", dev->name);
278 ring->stats.skb_alloc_fail++;
282 vxge_debug_mem(VXGE_TRACE,
283 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
284 __func__, __LINE__, skb);
286 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
289 rx_priv->data_size = skb_size;
290 vxge_debug_entryexit(VXGE_TRACE,
291 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
299 static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
301 struct vxge_rx_priv *rx_priv;
304 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
305 ring->ndev->name, __func__, __LINE__);
306 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
308 dma_addr = pci_map_single(ring->pdev, rx_priv->skb->data,
309 rx_priv->data_size, PCI_DMA_FROMDEVICE);
312 ring->stats.pci_map_fail++;
315 vxge_debug_mem(VXGE_TRACE,
316 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
317 ring->ndev->name, __func__, __LINE__,
318 (unsigned long long)dma_addr);
319 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
321 rx_priv->data_dma = dma_addr;
322 vxge_debug_entryexit(VXGE_TRACE,
323 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
329 * vxge_rx_initial_replenish
330 * Allocation of RxD as an initial replenish procedure.
332 static enum vxge_hw_status
333 vxge_rx_initial_replenish(void *dtrh, void *userdata)
335 struct vxge_ring *ring = (struct vxge_ring *)userdata;
336 struct vxge_rx_priv *rx_priv;
338 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
339 ring->ndev->name, __func__, __LINE__);
340 if (vxge_rx_alloc(dtrh, ring,
341 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
344 if (vxge_rx_map(dtrh, ring)) {
345 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
346 dev_kfree_skb(rx_priv->skb);
350 vxge_debug_entryexit(VXGE_TRACE,
351 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
357 vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
358 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
361 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
362 ring->ndev->name, __func__, __LINE__);
363 skb_record_rx_queue(skb, ring->driver_id);
364 skb->protocol = eth_type_trans(skb, ring->ndev);
366 ring->stats.rx_frms++;
367 ring->stats.rx_bytes += pkt_length;
369 if (skb->pkt_type == PACKET_MULTICAST)
370 ring->stats.rx_mcast++;
372 vxge_debug_rx(VXGE_TRACE,
373 "%s: %s:%d skb protocol = %d",
374 ring->ndev->name, __func__, __LINE__, skb->protocol);
376 if (ring->gro_enable) {
377 if (ring->vlgrp && ext_info->vlan &&
378 (ring->vlan_tag_strip ==
379 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
380 vlan_gro_receive(ring->napi_p, ring->vlgrp,
381 ext_info->vlan, skb);
383 napi_gro_receive(ring->napi_p, skb);
385 if (ring->vlgrp && vlan &&
386 (ring->vlan_tag_strip ==
387 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
388 vlan_hwaccel_receive_skb(skb, ring->vlgrp, vlan);
390 netif_receive_skb(skb);
392 vxge_debug_entryexit(VXGE_TRACE,
393 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
396 static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
397 struct vxge_rx_priv *rx_priv)
399 pci_dma_sync_single_for_device(ring->pdev,
400 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
402 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
403 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
406 static inline void vxge_post(int *dtr_cnt, void **first_dtr,
407 void *post_dtr, struct __vxge_hw_ring *ringh)
409 int dtr_count = *dtr_cnt;
410 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
412 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
413 *first_dtr = post_dtr;
415 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
417 *dtr_cnt = dtr_count;
423 * If the interrupt is because of a received frame or if the receive ring
424 * contains fresh as yet un-processed frames, this function is called.
427 vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
428 u8 t_code, void *userdata)
430 struct vxge_ring *ring = (struct vxge_ring *)userdata;
431 struct net_device *dev = ring->ndev;
432 unsigned int dma_sizes;
433 void *first_dtr = NULL;
439 struct vxge_rx_priv *rx_priv;
440 struct vxge_hw_ring_rxd_info ext_info;
441 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
442 ring->ndev->name, __func__, __LINE__);
443 ring->pkts_processed = 0;
445 vxge_hw_ring_replenish(ringh, 0);
448 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
450 data_size = rx_priv->data_size;
451 data_dma = rx_priv->data_dma;
453 vxge_debug_rx(VXGE_TRACE,
454 "%s: %s:%d skb = 0x%p",
455 ring->ndev->name, __func__, __LINE__, skb);
457 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
458 pkt_length = dma_sizes;
460 pkt_length -= ETH_FCS_LEN;
462 vxge_debug_rx(VXGE_TRACE,
463 "%s: %s:%d Packet Length = %d",
464 ring->ndev->name, __func__, __LINE__, pkt_length);
466 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
468 /* check skb validity */
471 prefetch((char *)skb + L1_CACHE_BYTES);
472 if (unlikely(t_code)) {
474 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
477 ring->stats.rx_errors++;
478 vxge_debug_rx(VXGE_TRACE,
479 "%s: %s :%d Rx T_code is %d",
480 ring->ndev->name, __func__,
483 /* If the t_code is not supported and if the
484 * t_code is other than 0x5 (unparseable packet
485 * such as unknown UPV6 header), Drop it !!!
487 vxge_re_pre_post(dtr, ring, rx_priv);
489 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
490 ring->stats.rx_dropped++;
495 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
497 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
499 if (!vxge_rx_map(dtr, ring)) {
500 skb_put(skb, pkt_length);
502 pci_unmap_single(ring->pdev, data_dma,
503 data_size, PCI_DMA_FROMDEVICE);
505 vxge_hw_ring_rxd_pre_post(ringh, dtr);
506 vxge_post(&dtr_cnt, &first_dtr, dtr,
509 dev_kfree_skb(rx_priv->skb);
511 rx_priv->data_size = data_size;
512 vxge_re_pre_post(dtr, ring, rx_priv);
514 vxge_post(&dtr_cnt, &first_dtr, dtr,
516 ring->stats.rx_dropped++;
520 vxge_re_pre_post(dtr, ring, rx_priv);
522 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
523 ring->stats.rx_dropped++;
527 struct sk_buff *skb_up;
529 skb_up = netdev_alloc_skb(dev, pkt_length +
530 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
531 if (skb_up != NULL) {
533 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
535 pci_dma_sync_single_for_cpu(ring->pdev,
539 vxge_debug_mem(VXGE_TRACE,
540 "%s: %s:%d skb_up = %p",
541 ring->ndev->name, __func__,
543 memcpy(skb_up->data, skb->data, pkt_length);
545 vxge_re_pre_post(dtr, ring, rx_priv);
547 vxge_post(&dtr_cnt, &first_dtr, dtr,
549 /* will netif_rx small SKB instead */
551 skb_put(skb, pkt_length);
553 vxge_re_pre_post(dtr, ring, rx_priv);
555 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
556 vxge_debug_rx(VXGE_ERR,
557 "%s: vxge_rx_1b_compl: out of "
558 "memory", dev->name);
559 ring->stats.skb_alloc_fail++;
564 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
565 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
566 ring->rx_csum && /* Offload Rx side CSUM */
567 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
568 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
569 skb->ip_summed = CHECKSUM_UNNECESSARY;
571 skb->ip_summed = CHECKSUM_NONE;
573 vxge_rx_complete(ring, skb, ext_info.vlan,
574 pkt_length, &ext_info);
577 ring->pkts_processed++;
581 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
582 &t_code) == VXGE_HW_OK);
585 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
587 dev->last_rx = jiffies;
589 vxge_debug_entryexit(VXGE_TRACE,
598 * If an interrupt was raised to indicate DMA complete of the Tx packet,
599 * this function is called. It identifies the last TxD whose buffer was
600 * freed and frees all skbs whose data have already DMA'ed into the NICs
604 vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
605 enum vxge_hw_fifo_tcode t_code, void *userdata,
606 struct sk_buff ***skb_ptr, int nr_skb, int *more)
608 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
609 struct sk_buff *skb, **done_skb = *skb_ptr;
612 vxge_debug_entryexit(VXGE_TRACE,
613 "%s:%d Entered....", __func__, __LINE__);
619 struct vxge_tx_priv *txd_priv =
620 vxge_hw_fifo_txdl_private_get(dtr);
623 frg_cnt = skb_shinfo(skb)->nr_frags;
624 frag = &skb_shinfo(skb)->frags[0];
626 vxge_debug_tx(VXGE_TRACE,
627 "%s: %s:%d fifo_hw = %p dtr = %p "
628 "tcode = 0x%x", fifo->ndev->name, __func__,
629 __LINE__, fifo_hw, dtr, t_code);
630 /* check skb validity */
632 vxge_debug_tx(VXGE_TRACE,
633 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
634 fifo->ndev->name, __func__, __LINE__,
635 skb, txd_priv, frg_cnt);
636 if (unlikely(t_code)) {
637 fifo->stats.tx_errors++;
638 vxge_debug_tx(VXGE_ERR,
639 "%s: tx: dtr %p completed due to "
640 "error t_code %01x", fifo->ndev->name,
642 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
645 /* for unfragmented skb */
646 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
647 skb_headlen(skb), PCI_DMA_TODEVICE);
649 for (j = 0; j < frg_cnt; j++) {
650 pci_unmap_page(fifo->pdev,
651 txd_priv->dma_buffers[i++],
652 frag->size, PCI_DMA_TODEVICE);
656 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
658 /* Updating the statistics block */
659 fifo->stats.tx_frms++;
660 fifo->stats.tx_bytes += skb->len;
670 if (pkt_cnt > fifo->indicate_max_pkts)
673 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
674 &dtr, &t_code) == VXGE_HW_OK);
677 vxge_wake_tx_queue(fifo, skb);
679 vxge_debug_entryexit(VXGE_TRACE,
680 "%s: %s:%d Exiting...",
681 fifo->ndev->name, __func__, __LINE__);
685 /* select a vpath to transmit the packet */
686 static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb,
689 u16 queue_len, counter = 0;
690 if (skb->protocol == htons(ETH_P_IP)) {
696 if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) {
697 th = (struct tcphdr *)(((unsigned char *)ip) +
700 queue_len = vdev->no_of_vpath;
701 counter = (ntohs(th->source) +
703 vdev->vpath_selector[queue_len - 1];
704 if (counter >= queue_len)
705 counter = queue_len - 1;
707 if (ip->protocol == IPPROTO_UDP) {
717 static enum vxge_hw_status vxge_search_mac_addr_in_list(
718 struct vxge_vpath *vpath, u64 del_mac)
720 struct list_head *entry, *next;
721 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
722 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
728 static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
730 struct macInfo mac_info;
731 u8 *mac_address = NULL;
732 u64 mac_addr = 0, vpath_vector = 0;
734 enum vxge_hw_status status = VXGE_HW_OK;
735 struct vxge_vpath *vpath = NULL;
736 struct __vxge_hw_device *hldev;
738 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
740 mac_address = (u8 *)&mac_addr;
741 memcpy(mac_address, mac_header, ETH_ALEN);
743 /* Is this mac address already in the list? */
744 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
745 vpath = &vdev->vpaths[vpath_idx];
746 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
750 memset(&mac_info, 0, sizeof(struct macInfo));
751 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
753 /* Any vpath has room to add mac address to its da table? */
754 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
755 vpath = &vdev->vpaths[vpath_idx];
756 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
757 /* Add this mac address to this vpath */
758 mac_info.vpath_no = vpath_idx;
759 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
760 status = vxge_add_mac_addr(vdev, &mac_info);
761 if (status != VXGE_HW_OK)
767 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
769 mac_info.vpath_no = vpath_idx;
770 /* Is the first vpath already selected as catch-basin ? */
771 vpath = &vdev->vpaths[vpath_idx];
772 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
773 /* Add this mac address to this vpath */
774 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
779 /* Select first vpath as catch-basin */
780 vpath_vector = vxge_mBIT(vpath->device_id);
781 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
782 vxge_hw_mgmt_reg_type_mrpcim,
785 struct vxge_hw_mrpcim_reg,
788 if (status != VXGE_HW_OK) {
789 vxge_debug_tx(VXGE_ERR,
790 "%s: Unable to set the vpath-%d in catch-basin mode",
791 VXGE_DRIVER_NAME, vpath->device_id);
795 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
803 * @skb : the socket buffer containing the Tx data.
804 * @dev : device pointer.
806 * This function is the Tx entry point of the driver. Neterion NIC supports
807 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
808 * NOTE: when device cant queue the pkt, just the trans_start variable will
812 vxge_xmit(struct sk_buff *skb, struct net_device *dev)
814 struct vxge_fifo *fifo = NULL;
817 struct vxgedev *vdev = NULL;
818 enum vxge_hw_status status;
819 int frg_cnt, first_frg_len;
821 int i = 0, j = 0, avail;
823 struct vxge_tx_priv *txdl_priv = NULL;
824 struct __vxge_hw_fifo *fifo_hw;
826 unsigned long flags = 0;
828 int do_spin_tx_lock = 1;
830 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
831 dev->name, __func__, __LINE__);
833 /* A buffer with no data will be dropped */
834 if (unlikely(skb->len <= 0)) {
835 vxge_debug_tx(VXGE_ERR,
836 "%s: Buffer has no data..", dev->name);
841 vdev = (struct vxgedev *)netdev_priv(dev);
843 if (unlikely(!is_vxge_card_up(vdev))) {
844 vxge_debug_tx(VXGE_ERR,
845 "%s: vdev not initialized", dev->name);
850 if (vdev->config.addr_learn_en) {
851 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
852 if (vpath_no == -EPERM) {
853 vxge_debug_tx(VXGE_ERR,
854 "%s: Failed to store the mac address",
861 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
862 vpath_no = skb_get_queue_mapping(skb);
863 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
864 vpath_no = vxge_get_vpath_no(vdev, skb, &do_spin_tx_lock);
866 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
868 if (vpath_no >= vdev->no_of_vpath)
871 fifo = &vdev->vpaths[vpath_no].fifo;
872 fifo_hw = fifo->handle;
875 spin_lock_irqsave(&fifo->tx_lock, flags);
877 if (unlikely(!spin_trylock_irqsave(&fifo->tx_lock, flags)))
878 return NETDEV_TX_LOCKED;
881 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING) {
882 if (netif_subqueue_stopped(dev, skb)) {
883 spin_unlock_irqrestore(&fifo->tx_lock, flags);
884 return NETDEV_TX_BUSY;
886 } else if (unlikely(fifo->queue_state == VPATH_QUEUE_STOP)) {
887 if (netif_queue_stopped(dev)) {
888 spin_unlock_irqrestore(&fifo->tx_lock, flags);
889 return NETDEV_TX_BUSY;
892 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
894 vxge_debug_tx(VXGE_ERR,
895 "%s: No free TXDs available", dev->name);
896 fifo->stats.txd_not_free++;
897 vxge_stop_tx_queue(fifo);
901 /* Last TXD? Stop tx queue to avoid dropping packets. TX
902 * completion will resume the queue.
905 vxge_stop_tx_queue(fifo);
907 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
908 if (unlikely(status != VXGE_HW_OK)) {
909 vxge_debug_tx(VXGE_ERR,
910 "%s: Out of descriptors .", dev->name);
911 fifo->stats.txd_out_of_desc++;
912 vxge_stop_tx_queue(fifo);
916 vxge_debug_tx(VXGE_TRACE,
917 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
918 dev->name, __func__, __LINE__,
919 fifo_hw, dtr, dtr_priv);
921 if (vdev->vlgrp && vlan_tx_tag_present(skb)) {
922 u16 vlan_tag = vlan_tx_tag_get(skb);
923 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
926 first_frg_len = skb_headlen(skb);
928 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
931 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
932 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
933 vxge_stop_tx_queue(fifo);
934 fifo->stats.pci_map_fail++;
938 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
939 txdl_priv->skb = skb;
940 txdl_priv->dma_buffers[j] = dma_pointer;
942 frg_cnt = skb_shinfo(skb)->nr_frags;
943 vxge_debug_tx(VXGE_TRACE,
944 "%s: %s:%d skb = %p txdl_priv = %p "
945 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
946 __func__, __LINE__, skb, txdl_priv,
947 frg_cnt, (unsigned long long)dma_pointer);
949 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
952 frag = &skb_shinfo(skb)->frags[0];
953 for (i = 0; i < frg_cnt; i++) {
954 /* ignore 0 length fragment */
959 (u64)pci_map_page(fifo->pdev, frag->page,
960 frag->page_offset, frag->size,
963 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
965 vxge_debug_tx(VXGE_TRACE,
966 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
967 dev->name, __func__, __LINE__, i,
968 (unsigned long long)dma_pointer);
970 txdl_priv->dma_buffers[j] = dma_pointer;
971 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
976 offload_type = vxge_offload_type(skb);
978 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
980 int mss = vxge_tcp_mss(skb);
982 vxge_debug_tx(VXGE_TRACE,
983 "%s: %s:%d mss = %d",
984 dev->name, __func__, __LINE__, mss);
985 vxge_hw_fifo_txdl_mss_set(dtr, mss);
987 vxge_assert(skb->len <=
988 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
994 if (skb->ip_summed == CHECKSUM_PARTIAL)
995 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
996 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
997 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
998 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
1000 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
1002 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
1004 spin_unlock_irqrestore(&fifo->tx_lock, flags);
1006 VXGE_COMPLETE_VPATH_TX(fifo);
1007 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
1008 dev->name, __func__, __LINE__);
1009 return NETDEV_TX_OK;
1012 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
1016 frag = &skb_shinfo(skb)->frags[0];
1018 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
1019 skb_headlen(skb), PCI_DMA_TODEVICE);
1021 for (; j < i; j++) {
1022 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
1023 frag->size, PCI_DMA_TODEVICE);
1027 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
1030 spin_unlock_irqrestore(&fifo->tx_lock, flags);
1031 VXGE_COMPLETE_VPATH_TX(fifo);
1033 return NETDEV_TX_OK;
1039 * Function will be called by hw function to abort all outstanding receive
1043 vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1045 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1046 struct vxge_rx_priv *rx_priv =
1047 vxge_hw_ring_rxd_private_get(dtrh);
1049 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1050 ring->ndev->name, __func__, __LINE__);
1051 if (state != VXGE_HW_RXD_STATE_POSTED)
1054 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1055 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1057 dev_kfree_skb(rx_priv->skb);
1059 vxge_debug_entryexit(VXGE_TRACE,
1060 "%s: %s:%d Exiting...",
1061 ring->ndev->name, __func__, __LINE__);
1067 * Function will be called to abort all outstanding tx descriptors
1070 vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1072 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1074 int i = 0, j, frg_cnt;
1075 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1076 struct sk_buff *skb = txd_priv->skb;
1078 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1080 if (state != VXGE_HW_TXDL_STATE_POSTED)
1083 /* check skb validity */
1085 frg_cnt = skb_shinfo(skb)->nr_frags;
1086 frag = &skb_shinfo(skb)->frags[0];
1088 /* for unfragmented skb */
1089 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1090 skb_headlen(skb), PCI_DMA_TODEVICE);
1092 for (j = 0; j < frg_cnt; j++) {
1093 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
1094 frag->size, PCI_DMA_TODEVICE);
1100 vxge_debug_entryexit(VXGE_TRACE,
1101 "%s:%d Exiting...", __func__, __LINE__);
1105 * vxge_set_multicast
1106 * @dev: pointer to the device structure
1108 * Entry point for multicast address enable/disable
1109 * This function is a driver entry point which gets called by the kernel
1110 * whenever multicast addresses must be enabled/disabled. This also gets
1111 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1112 * determine, if multicast address must be enabled or if promiscuous mode
1113 * is to be disabled etc.
1115 static void vxge_set_multicast(struct net_device *dev)
1117 struct dev_mc_list *mclist;
1118 struct vxgedev *vdev;
1119 int i, mcast_cnt = 0;
1120 struct __vxge_hw_device *hldev;
1121 enum vxge_hw_status status = VXGE_HW_OK;
1122 struct macInfo mac_info;
1124 struct vxge_mac_addrs *mac_entry;
1125 struct list_head *list_head;
1126 struct list_head *entry, *next;
1127 u8 *mac_address = NULL;
1129 vxge_debug_entryexit(VXGE_TRACE,
1130 "%s:%d", __func__, __LINE__);
1132 vdev = (struct vxgedev *)netdev_priv(dev);
1133 hldev = (struct __vxge_hw_device *)vdev->devh;
1135 if (unlikely(!is_vxge_card_up(vdev)))
1138 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1139 for (i = 0; i < vdev->no_of_vpath; i++) {
1140 vxge_assert(vdev->vpaths[i].is_open);
1141 status = vxge_hw_vpath_mcast_enable(
1142 vdev->vpaths[i].handle);
1143 vdev->all_multi_flg = 1;
1145 } else if ((dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
1146 for (i = 0; i < vdev->no_of_vpath; i++) {
1147 vxge_assert(vdev->vpaths[i].is_open);
1148 status = vxge_hw_vpath_mcast_disable(
1149 vdev->vpaths[i].handle);
1150 vdev->all_multi_flg = 1;
1154 if (status != VXGE_HW_OK)
1155 vxge_debug_init(VXGE_ERR,
1156 "failed to %s multicast, status %d",
1157 dev->flags & IFF_ALLMULTI ?
1158 "enable" : "disable", status);
1160 if (!vdev->config.addr_learn_en) {
1161 if (dev->flags & IFF_PROMISC) {
1162 for (i = 0; i < vdev->no_of_vpath; i++) {
1163 vxge_assert(vdev->vpaths[i].is_open);
1164 status = vxge_hw_vpath_promisc_enable(
1165 vdev->vpaths[i].handle);
1168 for (i = 0; i < vdev->no_of_vpath; i++) {
1169 vxge_assert(vdev->vpaths[i].is_open);
1170 status = vxge_hw_vpath_promisc_disable(
1171 vdev->vpaths[i].handle);
1176 memset(&mac_info, 0, sizeof(struct macInfo));
1177 /* Update individual M_CAST address list */
1178 if ((!vdev->all_multi_flg) && dev->mc_count) {
1180 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1181 list_head = &vdev->vpaths[0].mac_addr_list;
1182 if ((dev->mc_count +
1183 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1184 vdev->vpaths[0].max_mac_addr_cnt)
1185 goto _set_all_mcast;
1187 /* Delete previous MC's */
1188 for (i = 0; i < mcast_cnt; i++) {
1189 if (!list_empty(list_head))
1190 mac_entry = (struct vxge_mac_addrs *)
1191 list_first_entry(list_head,
1192 struct vxge_mac_addrs,
1195 list_for_each_safe(entry, next, list_head) {
1197 mac_entry = (struct vxge_mac_addrs *) entry;
1198 /* Copy the mac address to delete */
1199 mac_address = (u8 *)&mac_entry->macaddr;
1200 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1202 /* Is this a multicast address */
1203 if (0x01 & mac_info.macaddr[0]) {
1204 for (vpath_idx = 0; vpath_idx <
1207 mac_info.vpath_no = vpath_idx;
1208 status = vxge_del_mac_addr(
1217 for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
1218 i++, mclist = mclist->next) {
1220 memcpy(mac_info.macaddr, mclist->dmi_addr, ETH_ALEN);
1221 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1223 mac_info.vpath_no = vpath_idx;
1224 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1225 status = vxge_add_mac_addr(vdev, &mac_info);
1226 if (status != VXGE_HW_OK) {
1227 vxge_debug_init(VXGE_ERR,
1228 "%s:%d Setting individual"
1229 "multicast address failed",
1230 __func__, __LINE__);
1231 goto _set_all_mcast;
1238 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1239 /* Delete previous MC's */
1240 for (i = 0; i < mcast_cnt; i++) {
1242 list_for_each_safe(entry, next, list_head) {
1244 mac_entry = (struct vxge_mac_addrs *) entry;
1245 /* Copy the mac address to delete */
1246 mac_address = (u8 *)&mac_entry->macaddr;
1247 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1249 /* Is this a multicast address */
1250 if (0x01 & mac_info.macaddr[0])
1254 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1256 mac_info.vpath_no = vpath_idx;
1257 status = vxge_del_mac_addr(vdev, &mac_info);
1261 /* Enable all multicast */
1262 for (i = 0; i < vdev->no_of_vpath; i++) {
1263 vxge_assert(vdev->vpaths[i].is_open);
1264 status = vxge_hw_vpath_mcast_enable(
1265 vdev->vpaths[i].handle);
1266 if (status != VXGE_HW_OK) {
1267 vxge_debug_init(VXGE_ERR,
1268 "%s:%d Enabling all multicasts failed",
1269 __func__, __LINE__);
1271 vdev->all_multi_flg = 1;
1273 dev->flags |= IFF_ALLMULTI;
1276 vxge_debug_entryexit(VXGE_TRACE,
1277 "%s:%d Exiting...", __func__, __LINE__);
1282 * @dev: pointer to the device structure
1284 * Update entry "0" (default MAC addr)
1286 static int vxge_set_mac_addr(struct net_device *dev, void *p)
1288 struct sockaddr *addr = p;
1289 struct vxgedev *vdev;
1290 struct __vxge_hw_device *hldev;
1291 enum vxge_hw_status status = VXGE_HW_OK;
1292 struct macInfo mac_info_new, mac_info_old;
1295 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1297 vdev = (struct vxgedev *)netdev_priv(dev);
1300 if (!is_valid_ether_addr(addr->sa_data))
1303 memset(&mac_info_new, 0, sizeof(struct macInfo));
1304 memset(&mac_info_old, 0, sizeof(struct macInfo));
1306 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1307 __func__, __LINE__);
1309 /* Get the old address */
1310 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1312 /* Copy the new address */
1313 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1315 /* First delete the old mac address from all the vpaths
1316 as we can't specify the index while adding new mac address */
1317 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1318 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1319 if (!vpath->is_open) {
1320 /* This can happen when this interface is added/removed
1321 to the bonding interface. Delete this station address
1322 from the linked list */
1323 vxge_mac_list_del(vpath, &mac_info_old);
1325 /* Add this new address to the linked list
1326 for later restoring */
1327 vxge_mac_list_add(vpath, &mac_info_new);
1331 /* Delete the station address */
1332 mac_info_old.vpath_no = vpath_idx;
1333 status = vxge_del_mac_addr(vdev, &mac_info_old);
1336 if (unlikely(!is_vxge_card_up(vdev))) {
1337 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1341 /* Set this mac address to all the vpaths */
1342 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1343 mac_info_new.vpath_no = vpath_idx;
1344 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1345 status = vxge_add_mac_addr(vdev, &mac_info_new);
1346 if (status != VXGE_HW_OK)
1350 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1356 * vxge_vpath_intr_enable
1357 * @vdev: pointer to vdev
1358 * @vp_id: vpath for which to enable the interrupts
1360 * Enables the interrupts for the vpath
1362 void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
1364 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1365 int msix_id, alarm_msix_id;
1366 int tim_msix_id[4] = {[0 ...3] = 0};
1368 vxge_hw_vpath_intr_enable(vpath->handle);
1370 if (vdev->config.intr_type == INTA)
1371 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1373 msix_id = vp_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1375 VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
1377 tim_msix_id[0] = msix_id;
1378 tim_msix_id[1] = msix_id + 1;
1379 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1382 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1383 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1385 /* enable the alarm vector */
1386 vxge_hw_vpath_msix_unmask(vpath->handle, alarm_msix_id);
1391 * vxge_vpath_intr_disable
1392 * @vdev: pointer to vdev
1393 * @vp_id: vpath for which to disable the interrupts
1395 * Disables the interrupts for the vpath
1397 void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
1399 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1402 vxge_hw_vpath_intr_disable(vpath->handle);
1404 if (vdev->config.intr_type == INTA)
1405 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1407 msix_id = vp_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1408 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1409 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1411 /* disable the alarm vector */
1412 msix_id = VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
1413 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1419 * @vdev: pointer to vdev
1420 * @vp_id: vpath to reset
1424 static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1426 enum vxge_hw_status status = VXGE_HW_OK;
1429 /* check if device is down already */
1430 if (unlikely(!is_vxge_card_up(vdev)))
1433 /* is device reset already scheduled */
1434 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1437 if (vdev->vpaths[vp_id].handle) {
1438 if (vxge_hw_vpath_reset(vdev->vpaths[vp_id].handle)
1440 if (is_vxge_card_up(vdev) &&
1441 vxge_hw_vpath_recover_from_reset(
1442 vdev->vpaths[vp_id].handle)
1444 vxge_debug_init(VXGE_ERR,
1445 "vxge_hw_vpath_recover_from_reset"
1446 "failed for vpath:%d", vp_id);
1450 vxge_debug_init(VXGE_ERR,
1451 "vxge_hw_vpath_reset failed for"
1456 return VXGE_HW_FAIL;
1458 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1459 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1461 /* Enable all broadcast */
1462 vxge_hw_vpath_bcast_enable(vdev->vpaths[vp_id].handle);
1464 /* Enable the interrupts */
1465 vxge_vpath_intr_enable(vdev, vp_id);
1469 /* Enable the flow of traffic through the vpath */
1470 vxge_hw_vpath_enable(vdev->vpaths[vp_id].handle);
1473 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[vp_id].handle);
1474 vdev->vpaths[vp_id].ring.last_status = VXGE_HW_OK;
1476 /* Vpath reset done */
1477 clear_bit(vp_id, &vdev->vp_reset);
1479 /* Start the vpath queue */
1480 vxge_wake_tx_queue(&vdev->vpaths[vp_id].fifo, NULL);
1485 static int do_vxge_reset(struct vxgedev *vdev, int event)
1487 enum vxge_hw_status status;
1488 int ret = 0, vp_id, i;
1490 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1492 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1493 /* check if device is down already */
1494 if (unlikely(!is_vxge_card_up(vdev)))
1497 /* is reset already scheduled */
1498 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1502 if (event == VXGE_LL_FULL_RESET) {
1503 /* wait for all the vpath reset to complete */
1504 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1505 while (test_bit(vp_id, &vdev->vp_reset))
1509 /* if execution mode is set to debug, don't reset the adapter */
1510 if (unlikely(vdev->exec_mode)) {
1511 vxge_debug_init(VXGE_ERR,
1512 "%s: execution mode is debug, returning..",
1514 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1515 vxge_stop_all_tx_queue(vdev);
1520 if (event == VXGE_LL_FULL_RESET) {
1521 vxge_hw_device_intr_disable(vdev->devh);
1523 switch (vdev->cric_err_event) {
1524 case VXGE_HW_EVENT_UNKNOWN:
1525 vxge_stop_all_tx_queue(vdev);
1526 vxge_debug_init(VXGE_ERR,
1527 "fatal: %s: Disabling device due to"
1532 case VXGE_HW_EVENT_RESET_START:
1534 case VXGE_HW_EVENT_RESET_COMPLETE:
1535 case VXGE_HW_EVENT_LINK_DOWN:
1536 case VXGE_HW_EVENT_LINK_UP:
1537 case VXGE_HW_EVENT_ALARM_CLEARED:
1538 case VXGE_HW_EVENT_ECCERR:
1539 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1542 case VXGE_HW_EVENT_FIFO_ERR:
1543 case VXGE_HW_EVENT_VPATH_ERR:
1545 case VXGE_HW_EVENT_CRITICAL_ERR:
1546 vxge_stop_all_tx_queue(vdev);
1547 vxge_debug_init(VXGE_ERR,
1548 "fatal: %s: Disabling device due to"
1551 /* SOP or device reset required */
1552 /* This event is not currently used */
1555 case VXGE_HW_EVENT_SERR:
1556 vxge_stop_all_tx_queue(vdev);
1557 vxge_debug_init(VXGE_ERR,
1558 "fatal: %s: Disabling device due to"
1563 case VXGE_HW_EVENT_SRPCIM_SERR:
1564 case VXGE_HW_EVENT_MRPCIM_SERR:
1567 case VXGE_HW_EVENT_SLOT_FREEZE:
1568 vxge_stop_all_tx_queue(vdev);
1569 vxge_debug_init(VXGE_ERR,
1570 "fatal: %s: Disabling device due to"
1581 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
1582 vxge_stop_all_tx_queue(vdev);
1584 if (event == VXGE_LL_FULL_RESET) {
1585 status = vxge_reset_all_vpaths(vdev);
1586 if (status != VXGE_HW_OK) {
1587 vxge_debug_init(VXGE_ERR,
1588 "fatal: %s: can not reset vpaths",
1595 if (event == VXGE_LL_COMPL_RESET) {
1596 for (i = 0; i < vdev->no_of_vpath; i++)
1597 if (vdev->vpaths[i].handle) {
1598 if (vxge_hw_vpath_recover_from_reset(
1599 vdev->vpaths[i].handle)
1601 vxge_debug_init(VXGE_ERR,
1602 "vxge_hw_vpath_recover_"
1603 "from_reset failed for vpath: "
1609 vxge_debug_init(VXGE_ERR,
1610 "vxge_hw_vpath_reset failed for "
1617 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1618 /* Reprogram the DA table with populated mac addresses */
1619 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1620 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1621 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1624 /* enable vpath interrupts */
1625 for (i = 0; i < vdev->no_of_vpath; i++)
1626 vxge_vpath_intr_enable(vdev, i);
1628 vxge_hw_device_intr_enable(vdev->devh);
1632 /* Indicate card up */
1633 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1635 /* Get the traffic to flow through the vpaths */
1636 for (i = 0; i < vdev->no_of_vpath; i++) {
1637 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1639 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1642 vxge_wake_all_tx_queue(vdev);
1646 vxge_debug_entryexit(VXGE_TRACE,
1647 "%s:%d Exiting...", __func__, __LINE__);
1649 /* Indicate reset done */
1650 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1651 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1657 * @vdev: pointer to ll device
1659 * driver may reset the chip on events of serr, eccerr, etc
1661 int vxge_reset(struct vxgedev *vdev)
1663 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
1668 * vxge_poll - Receive handler when Receive Polling is used.
1669 * @dev: pointer to the device structure.
1670 * @budget: Number of packets budgeted to be processed in this iteration.
1672 * This function comes into picture only if Receive side is being handled
1673 * through polling (called NAPI in linux). It mostly does what the normal
1674 * Rx interrupt handler does in terms of descriptor and packet processing
1675 * but not in an interrupt context. Also it will process a specified number
1676 * of packets at most in one iteration. This value is passed down by the
1677 * kernel as the function argument 'budget'.
1679 static int vxge_poll_msix(struct napi_struct *napi, int budget)
1681 struct vxge_ring *ring =
1682 container_of(napi, struct vxge_ring, napi);
1683 int budget_org = budget;
1684 ring->budget = budget;
1686 vxge_hw_vpath_poll_rx(ring->handle);
1688 if (ring->pkts_processed < budget_org) {
1689 napi_complete(napi);
1690 /* Re enable the Rx interrupts for the vpath */
1691 vxge_hw_channel_msix_unmask(
1692 (struct __vxge_hw_channel *)ring->handle,
1693 ring->rx_vector_no);
1696 return ring->pkts_processed;
1699 static int vxge_poll_inta(struct napi_struct *napi, int budget)
1701 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1702 int pkts_processed = 0;
1704 int budget_org = budget;
1705 struct vxge_ring *ring;
1707 struct __vxge_hw_device *hldev = (struct __vxge_hw_device *)
1708 pci_get_drvdata(vdev->pdev);
1710 for (i = 0; i < vdev->no_of_vpath; i++) {
1711 ring = &vdev->vpaths[i].ring;
1712 ring->budget = budget;
1713 vxge_hw_vpath_poll_rx(ring->handle);
1714 pkts_processed += ring->pkts_processed;
1715 budget -= ring->pkts_processed;
1720 VXGE_COMPLETE_ALL_TX(vdev);
1722 if (pkts_processed < budget_org) {
1723 napi_complete(napi);
1724 /* Re enable the Rx interrupts for the ring */
1725 vxge_hw_device_unmask_all(hldev);
1726 vxge_hw_device_flush_io(hldev);
1729 return pkts_processed;
1732 #ifdef CONFIG_NET_POLL_CONTROLLER
1734 * vxge_netpoll - netpoll event handler entry point
1735 * @dev : pointer to the device structure.
1737 * This function will be called by upper layer to check for events on the
1738 * interface in situations where interrupts are disabled. It is used for
1739 * specific in-kernel networking tasks, such as remote consoles and kernel
1740 * debugging over the network (example netdump in RedHat).
1742 static void vxge_netpoll(struct net_device *dev)
1744 struct __vxge_hw_device *hldev;
1745 struct vxgedev *vdev;
1747 vdev = (struct vxgedev *)netdev_priv(dev);
1748 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
1750 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1752 if (pci_channel_offline(vdev->pdev))
1755 disable_irq(dev->irq);
1756 vxge_hw_device_clear_tx_rx(hldev);
1758 vxge_hw_device_clear_tx_rx(hldev);
1759 VXGE_COMPLETE_ALL_RX(vdev);
1760 VXGE_COMPLETE_ALL_TX(vdev);
1762 enable_irq(dev->irq);
1764 vxge_debug_entryexit(VXGE_TRACE,
1765 "%s:%d Exiting...", __func__, __LINE__);
1770 /* RTH configuration */
1771 static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1773 enum vxge_hw_status status = VXGE_HW_OK;
1774 struct vxge_hw_rth_hash_types hash_types;
1775 u8 itable[256] = {0}; /* indirection table */
1776 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1781 * - itable with bucket numbers
1782 * - mtable with bucket-to-vpath mapping
1784 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1785 itable[index] = index;
1786 mtable[index] = index % vdev->no_of_vpath;
1789 /* Fill RTH hash types */
1790 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1791 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1792 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1793 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1794 hash_types.hash_type_tcpipv6ex_en =
1795 vdev->config.rth_hash_type_tcpipv6ex;
1796 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1798 /* set indirection table, bucket-to-vpath mapping */
1799 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1802 vdev->config.rth_bkt_sz);
1803 if (status != VXGE_HW_OK) {
1804 vxge_debug_init(VXGE_ERR,
1805 "RTH indirection table configuration failed "
1806 "for vpath:%d", vdev->vpaths[0].device_id);
1811 * Because the itable_set() method uses the active_table field
1812 * for the target virtual path the RTH config should be updated
1813 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1814 * when steering frames.
1816 for (index = 0; index < vdev->no_of_vpath; index++) {
1817 status = vxge_hw_vpath_rts_rth_set(
1818 vdev->vpaths[index].handle,
1819 vdev->config.rth_algorithm,
1821 vdev->config.rth_bkt_sz);
1823 if (status != VXGE_HW_OK) {
1824 vxge_debug_init(VXGE_ERR,
1825 "RTH configuration failed for vpath:%d",
1826 vdev->vpaths[index].device_id);
1834 int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
1836 struct vxge_mac_addrs *new_mac_entry;
1837 u8 *mac_address = NULL;
1839 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
1842 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
1843 if (!new_mac_entry) {
1844 vxge_debug_mem(VXGE_ERR,
1845 "%s: memory allocation failed",
1850 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
1852 /* Copy the new mac address to the list */
1853 mac_address = (u8 *)&new_mac_entry->macaddr;
1854 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1856 new_mac_entry->state = mac->state;
1857 vpath->mac_addr_cnt++;
1859 /* Is this a multicast address */
1860 if (0x01 & mac->macaddr[0])
1861 vpath->mcast_addr_cnt++;
1866 /* Add a mac address to DA table */
1867 enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1869 enum vxge_hw_status status = VXGE_HW_OK;
1870 struct vxge_vpath *vpath;
1871 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
1873 if (0x01 & mac->macaddr[0]) /* multicast address */
1874 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
1876 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
1878 vpath = &vdev->vpaths[mac->vpath_no];
1879 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
1880 mac->macmask, duplicate_mode);
1881 if (status != VXGE_HW_OK) {
1882 vxge_debug_init(VXGE_ERR,
1883 "DA config add entry failed for vpath:%d",
1886 if (FALSE == vxge_mac_list_add(vpath, mac))
1892 int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1894 struct list_head *entry, *next;
1896 u8 *mac_address = (u8 *) (&del_mac);
1898 /* Copy the mac address to delete from the list */
1899 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1901 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1902 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1904 kfree((struct vxge_mac_addrs *)entry);
1905 vpath->mac_addr_cnt--;
1907 /* Is this a multicast address */
1908 if (0x01 & mac->macaddr[0])
1909 vpath->mcast_addr_cnt--;
1916 /* delete a mac address from DA table */
1917 enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1919 enum vxge_hw_status status = VXGE_HW_OK;
1920 struct vxge_vpath *vpath;
1922 vpath = &vdev->vpaths[mac->vpath_no];
1923 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1925 if (status != VXGE_HW_OK) {
1926 vxge_debug_init(VXGE_ERR,
1927 "DA config delete entry failed for vpath:%d",
1930 vxge_mac_list_del(vpath, mac);
1934 /* list all mac addresses from DA table */
1936 static vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath,
1937 struct macInfo *mac)
1939 enum vxge_hw_status status = VXGE_HW_OK;
1940 unsigned char macmask[ETH_ALEN];
1941 unsigned char macaddr[ETH_ALEN];
1943 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1945 if (status != VXGE_HW_OK) {
1946 vxge_debug_init(VXGE_ERR,
1947 "DA config list entry failed for vpath:%d",
1952 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1954 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1956 if (status != VXGE_HW_OK)
1963 /* Store all vlan ids from the list to the vid table */
1964 enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1966 enum vxge_hw_status status = VXGE_HW_OK;
1967 struct vxgedev *vdev = vpath->vdev;
1970 if (vdev->vlgrp && vpath->is_open) {
1972 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1973 if (!vlan_group_get_device(vdev->vlgrp, vid))
1975 /* Add these vlan to the vid table */
1976 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
1983 /* Store all mac addresses from the list to the DA table */
1984 enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1986 enum vxge_hw_status status = VXGE_HW_OK;
1987 struct macInfo mac_info;
1988 u8 *mac_address = NULL;
1989 struct list_head *entry, *next;
1991 memset(&mac_info, 0, sizeof(struct macInfo));
1993 if (vpath->is_open) {
1995 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1998 ((struct vxge_mac_addrs *)entry)->macaddr;
1999 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
2000 ((struct vxge_mac_addrs *)entry)->state =
2001 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
2002 /* does this mac address already exist in da table? */
2003 status = vxge_search_mac_addr_in_da_table(vpath,
2005 if (status != VXGE_HW_OK) {
2006 /* Add this mac address to the DA table */
2007 status = vxge_hw_vpath_mac_addr_add(
2008 vpath->handle, mac_info.macaddr,
2010 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
2011 if (status != VXGE_HW_OK) {
2012 vxge_debug_init(VXGE_ERR,
2013 "DA add entry failed for vpath:%d",
2015 ((struct vxge_mac_addrs *)entry)->state
2016 = VXGE_LL_MAC_ADDR_IN_LIST;
2026 enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
2029 enum vxge_hw_status status = VXGE_HW_OK;
2031 for (i = 0; i < vdev->no_of_vpath; i++)
2032 if (vdev->vpaths[i].handle) {
2033 if (vxge_hw_vpath_reset(vdev->vpaths[i].handle)
2035 if (is_vxge_card_up(vdev) &&
2036 vxge_hw_vpath_recover_from_reset(
2037 vdev->vpaths[i].handle)
2039 vxge_debug_init(VXGE_ERR,
2040 "vxge_hw_vpath_recover_"
2041 "from_reset failed for vpath: "
2046 vxge_debug_init(VXGE_ERR,
2047 "vxge_hw_vpath_reset failed for "
2056 void vxge_close_vpaths(struct vxgedev *vdev, int index)
2059 for (i = index; i < vdev->no_of_vpath; i++) {
2060 if (vdev->vpaths[i].handle && vdev->vpaths[i].is_open) {
2061 vxge_hw_vpath_close(vdev->vpaths[i].handle);
2062 vdev->stats.vpaths_open--;
2064 vdev->vpaths[i].is_open = 0;
2065 vdev->vpaths[i].handle = NULL;
2070 int vxge_open_vpaths(struct vxgedev *vdev)
2072 enum vxge_hw_status status;
2075 struct vxge_hw_vpath_attr attr;
2077 for (i = 0; i < vdev->no_of_vpath; i++) {
2078 vxge_assert(vdev->vpaths[i].is_configured);
2079 attr.vp_id = vdev->vpaths[i].device_id;
2080 attr.fifo_attr.callback = vxge_xmit_compl;
2081 attr.fifo_attr.txdl_term = vxge_tx_term;
2082 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
2083 attr.fifo_attr.userdata = (void *)&vdev->vpaths[i].fifo;
2085 attr.ring_attr.callback = vxge_rx_1b_compl;
2086 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2087 attr.ring_attr.rxd_term = vxge_rx_term;
2088 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
2089 attr.ring_attr.userdata = (void *)&vdev->vpaths[i].ring;
2091 vdev->vpaths[i].ring.ndev = vdev->ndev;
2092 vdev->vpaths[i].ring.pdev = vdev->pdev;
2093 status = vxge_hw_vpath_open(vdev->devh, &attr,
2094 &(vdev->vpaths[i].handle));
2095 if (status == VXGE_HW_OK) {
2096 vdev->vpaths[i].fifo.handle =
2097 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
2098 vdev->vpaths[i].ring.handle =
2099 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
2100 vdev->vpaths[i].fifo.tx_steering_type =
2101 vdev->config.tx_steering_type;
2102 vdev->vpaths[i].fifo.ndev = vdev->ndev;
2103 vdev->vpaths[i].fifo.pdev = vdev->pdev;
2104 vdev->vpaths[i].fifo.indicate_max_pkts =
2105 vdev->config.fifo_indicate_max_pkts;
2106 vdev->vpaths[i].ring.rx_vector_no = 0;
2107 vdev->vpaths[i].ring.rx_csum = vdev->rx_csum;
2108 vdev->vpaths[i].is_open = 1;
2109 vdev->vp_handles[i] = vdev->vpaths[i].handle;
2110 vdev->vpaths[i].ring.gro_enable =
2111 vdev->config.gro_enable;
2112 vdev->vpaths[i].ring.vlan_tag_strip =
2113 vdev->vlan_tag_strip;
2114 vdev->stats.vpaths_open++;
2116 vdev->stats.vpath_open_fail++;
2117 vxge_debug_init(VXGE_ERR,
2118 "%s: vpath: %d failed to open "
2120 vdev->ndev->name, vdev->vpaths[i].device_id,
2122 vxge_close_vpaths(vdev, 0);
2127 ((struct __vxge_hw_vpath_handle *)vdev->vpaths[i].handle)->
2129 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2136 * @irq: the irq of the device.
2137 * @dev_id: a void pointer to the hldev structure of the Titan device
2138 * @ptregs: pointer to the registers pushed on the stack.
2140 * This function is the ISR handler of the device when napi is enabled. It
2141 * identifies the reason for the interrupt and calls the relevant service
2144 static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2146 struct net_device *dev;
2147 struct __vxge_hw_device *hldev;
2149 enum vxge_hw_status status;
2150 struct vxgedev *vdev = (struct vxgedev *) dev_id;;
2152 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2155 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
2157 if (pci_channel_offline(vdev->pdev))
2160 if (unlikely(!is_vxge_card_up(vdev)))
2163 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode,
2165 if (status == VXGE_HW_OK) {
2166 vxge_hw_device_mask_all(hldev);
2169 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2170 vdev->vpaths_deployed >>
2171 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2173 vxge_hw_device_clear_tx_rx(hldev);
2174 napi_schedule(&vdev->napi);
2175 vxge_debug_intr(VXGE_TRACE,
2176 "%s:%d Exiting...", __func__, __LINE__);
2179 vxge_hw_device_unmask_all(hldev);
2180 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2181 (status == VXGE_HW_ERR_CRITICAL) ||
2182 (status == VXGE_HW_ERR_FIFO))) {
2183 vxge_hw_device_mask_all(hldev);
2184 vxge_hw_device_flush_io(hldev);
2186 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2189 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2193 #ifdef CONFIG_PCI_MSI
2196 vxge_tx_msix_handle(int irq, void *dev_id)
2198 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2200 VXGE_COMPLETE_VPATH_TX(fifo);
2206 vxge_rx_msix_napi_handle(int irq, void *dev_id)
2208 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2210 /* MSIX_IDX for Rx is 1 */
2211 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
2212 ring->rx_vector_no);
2214 napi_schedule(&ring->napi);
2219 vxge_alarm_msix_handle(int irq, void *dev_id)
2222 enum vxge_hw_status status;
2223 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2224 struct vxgedev *vdev = vpath->vdev;
2226 VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
2228 for (i = 0; i < vdev->no_of_vpath; i++) {
2229 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle,
2232 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2234 if (status == VXGE_HW_OK) {
2236 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
2240 vxge_debug_intr(VXGE_ERR,
2241 "%s: vxge_hw_vpath_alarm_process failed %x ",
2242 VXGE_DRIVER_NAME, status);
2247 static int vxge_alloc_msix(struct vxgedev *vdev)
2251 int alarm_msix_id = 0, msix_intr_vect = 0;
2254 /* Tx/Rx MSIX Vectors count */
2255 vdev->intr_cnt = vdev->no_of_vpath * 2;
2257 /* Alarm MSIX Vectors count */
2260 intr_cnt = (vdev->max_vpath_supported * 2) + 1;
2261 vdev->entries = kzalloc(intr_cnt * sizeof(struct msix_entry),
2263 if (!vdev->entries) {
2264 vxge_debug_init(VXGE_ERR,
2265 "%s: memory allocation failed",
2270 vdev->vxge_entries = kzalloc(intr_cnt * sizeof(struct vxge_msix_entry),
2272 if (!vdev->vxge_entries) {
2273 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2275 kfree(vdev->entries);
2279 /* Last vector in the list is used for alarm */
2280 alarm_msix_id = VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
2281 for (i = 0, j = 0; i < vdev->max_vpath_supported; i++) {
2283 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2285 /* Initialize the fifo vector */
2286 vdev->entries[j].entry = msix_intr_vect;
2287 vdev->vxge_entries[j].entry = msix_intr_vect;
2288 vdev->vxge_entries[j].in_use = 0;
2291 /* Initialize the ring vector */
2292 vdev->entries[j].entry = msix_intr_vect + 1;
2293 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2294 vdev->vxge_entries[j].in_use = 0;
2298 /* Initialize the alarm vector */
2299 vdev->entries[j].entry = alarm_msix_id;
2300 vdev->vxge_entries[j].entry = alarm_msix_id;
2301 vdev->vxge_entries[j].in_use = 0;
2303 ret = pci_enable_msix(vdev->pdev, vdev->entries, intr_cnt);
2304 /* if driver request exceeeds available irq's, request with a small
2308 vxge_debug_init(VXGE_ERR,
2309 "%s: MSI-X enable failed for %d vectors, available: %d",
2310 VXGE_DRIVER_NAME, intr_cnt, ret);
2311 vdev->max_vpath_supported = vdev->no_of_vpath;
2312 intr_cnt = (vdev->max_vpath_supported * 2) + 1;
2314 /* Reset the alarm vector setting */
2315 vdev->entries[j].entry = 0;
2316 vdev->vxge_entries[j].entry = 0;
2318 /* Initialize the alarm vector with new setting */
2319 vdev->entries[intr_cnt - 1].entry = alarm_msix_id;
2320 vdev->vxge_entries[intr_cnt - 1].entry = alarm_msix_id;
2321 vdev->vxge_entries[intr_cnt - 1].in_use = 0;
2323 ret = pci_enable_msix(vdev->pdev, vdev->entries, intr_cnt);
2325 vxge_debug_init(VXGE_ERR,
2326 "%s: MSI-X enabled for %d vectors",
2327 VXGE_DRIVER_NAME, intr_cnt);
2331 vxge_debug_init(VXGE_ERR,
2332 "%s: MSI-X enable failed for %d vectors, ret: %d",
2333 VXGE_DRIVER_NAME, intr_cnt, ret);
2334 kfree(vdev->entries);
2335 kfree(vdev->vxge_entries);
2336 vdev->entries = NULL;
2337 vdev->vxge_entries = NULL;
2343 static int vxge_enable_msix(struct vxgedev *vdev)
2347 enum vxge_hw_status status;
2348 /* 0 - Tx, 1 - Rx */
2350 int alarm_msix_id = 0, msix_intr_vect = 0;;
2353 /* allocate msix vectors */
2354 ret = vxge_alloc_msix(vdev);
2356 /* Last vector in the list is used for alarm */
2358 VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
2359 for (i = 0; i < vdev->no_of_vpath; i++) {
2361 /* If fifo or ring are not enabled
2362 the MSIX vector for that should be set to 0
2363 Hence initializeing this array to all 0s.
2365 memset(tim_msix_id, 0, sizeof(tim_msix_id));
2366 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2367 tim_msix_id[0] = msix_intr_vect;
2369 tim_msix_id[1] = msix_intr_vect + 1;
2370 vdev->vpaths[i].ring.rx_vector_no = tim_msix_id[1];
2372 status = vxge_hw_vpath_msix_set(
2373 vdev->vpaths[i].handle,
2374 tim_msix_id, alarm_msix_id);
2375 if (status != VXGE_HW_OK) {
2376 vxge_debug_init(VXGE_ERR,
2377 "vxge_hw_vpath_msix_set "
2378 "failed with status : %x", status);
2379 kfree(vdev->entries);
2380 kfree(vdev->vxge_entries);
2381 pci_disable_msix(vdev->pdev);
2390 static void vxge_rem_msix_isr(struct vxgedev *vdev)
2394 for (intr_cnt = 0; intr_cnt < (vdev->max_vpath_supported * 2 + 1);
2396 if (vdev->vxge_entries[intr_cnt].in_use) {
2397 synchronize_irq(vdev->entries[intr_cnt].vector);
2398 free_irq(vdev->entries[intr_cnt].vector,
2399 vdev->vxge_entries[intr_cnt].arg);
2400 vdev->vxge_entries[intr_cnt].in_use = 0;
2404 kfree(vdev->entries);
2405 kfree(vdev->vxge_entries);
2406 vdev->entries = NULL;
2407 vdev->vxge_entries = NULL;
2409 if (vdev->config.intr_type == MSI_X)
2410 pci_disable_msix(vdev->pdev);
2414 static void vxge_rem_isr(struct vxgedev *vdev)
2416 struct __vxge_hw_device *hldev;
2417 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2419 #ifdef CONFIG_PCI_MSI
2420 if (vdev->config.intr_type == MSI_X) {
2421 vxge_rem_msix_isr(vdev);
2424 if (vdev->config.intr_type == INTA) {
2425 synchronize_irq(vdev->pdev->irq);
2426 free_irq(vdev->pdev->irq, vdev);
2430 static int vxge_add_isr(struct vxgedev *vdev)
2433 #ifdef CONFIG_PCI_MSI
2434 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
2435 u64 function_mode = vdev->config.device_hw_info.function_mode;
2436 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2438 if (vdev->config.intr_type == MSI_X)
2439 ret = vxge_enable_msix(vdev);
2442 vxge_debug_init(VXGE_ERR,
2443 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
2444 if ((function_mode == VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2445 test_and_set_bit(__VXGE_STATE_CARD_UP,
2446 &driver_config->inta_dev_open))
2447 return VXGE_HW_FAIL;
2449 vxge_debug_init(VXGE_ERR,
2450 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2451 vdev->config.intr_type = INTA;
2452 vxge_hw_device_set_intr_type(vdev->devh,
2453 VXGE_HW_INTR_MODE_IRQLINE);
2454 vxge_close_vpaths(vdev, 1);
2455 vdev->no_of_vpath = 1;
2456 vdev->stats.vpaths_open = 1;
2460 if (vdev->config.intr_type == MSI_X) {
2462 intr_idx < (vdev->no_of_vpath *
2463 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2465 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2470 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2471 "%s:vxge fn: %d vpath: %d Tx MSI-X: %d",
2472 vdev->ndev->name, pci_fun, vp_idx,
2473 vdev->entries[intr_cnt].entry);
2475 vdev->entries[intr_cnt].vector,
2476 vxge_tx_msix_handle, 0,
2477 vdev->desc[intr_cnt],
2478 &vdev->vpaths[vp_idx].fifo);
2479 vdev->vxge_entries[intr_cnt].arg =
2480 &vdev->vpaths[vp_idx].fifo;
2484 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2485 "%s:vxge fn: %d vpath: %d Rx MSI-X: %d",
2486 vdev->ndev->name, pci_fun, vp_idx,
2487 vdev->entries[intr_cnt].entry);
2489 vdev->entries[intr_cnt].vector,
2490 vxge_rx_msix_napi_handle,
2492 vdev->desc[intr_cnt],
2493 &vdev->vpaths[vp_idx].ring);
2494 vdev->vxge_entries[intr_cnt].arg =
2495 &vdev->vpaths[vp_idx].ring;
2501 vxge_debug_init(VXGE_ERR,
2502 "%s: MSIX - %d Registration failed",
2503 vdev->ndev->name, intr_cnt);
2504 vxge_rem_msix_isr(vdev);
2505 if ((function_mode ==
2506 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2507 test_and_set_bit(__VXGE_STATE_CARD_UP,
2508 &driver_config->inta_dev_open))
2509 return VXGE_HW_FAIL;
2511 vxge_hw_device_set_intr_type(
2513 VXGE_HW_INTR_MODE_IRQLINE);
2514 vdev->config.intr_type = INTA;
2515 vxge_debug_init(VXGE_ERR,
2516 "%s: Defaulting to INTA"
2517 , vdev->ndev->name);
2518 vxge_close_vpaths(vdev, 1);
2519 vdev->no_of_vpath = 1;
2520 vdev->stats.vpaths_open = 1;
2526 /* We requested for this msix interrupt */
2527 vdev->vxge_entries[intr_cnt].in_use = 1;
2528 vxge_hw_vpath_msix_unmask(
2529 vdev->vpaths[vp_idx].handle,
2534 /* Point to next vpath handler */
2535 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0)
2536 && (vp_idx < (vdev->no_of_vpath - 1)))
2540 intr_cnt = vdev->max_vpath_supported * 2;
2541 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2542 "%s:vxge Alarm fn: %d MSI-X: %d",
2543 vdev->ndev->name, pci_fun,
2544 vdev->entries[intr_cnt].entry);
2545 /* For Alarm interrupts */
2546 ret = request_irq(vdev->entries[intr_cnt].vector,
2547 vxge_alarm_msix_handle, 0,
2548 vdev->desc[intr_cnt],
2549 &vdev->vpaths[vp_idx]);
2551 vxge_debug_init(VXGE_ERR,
2552 "%s: MSIX - %d Registration failed",
2553 vdev->ndev->name, intr_cnt);
2554 vxge_rem_msix_isr(vdev);
2555 if ((function_mode ==
2556 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2557 test_and_set_bit(__VXGE_STATE_CARD_UP,
2558 &driver_config->inta_dev_open))
2559 return VXGE_HW_FAIL;
2561 vxge_hw_device_set_intr_type(vdev->devh,
2562 VXGE_HW_INTR_MODE_IRQLINE);
2563 vdev->config.intr_type = INTA;
2564 vxge_debug_init(VXGE_ERR,
2565 "%s: Defaulting to INTA",
2567 vxge_close_vpaths(vdev, 1);
2568 vdev->no_of_vpath = 1;
2569 vdev->stats.vpaths_open = 1;
2574 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
2576 vdev->vxge_entries[intr_cnt].in_use = 1;
2577 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[vp_idx];
2581 snprintf(vdev->desc[0], VXGE_INTR_STRLEN, "%s:vxge", vdev->ndev->name);
2583 if (vdev->config.intr_type == INTA) {
2584 ret = request_irq((int) vdev->pdev->irq,
2586 IRQF_SHARED, vdev->desc[0], vdev);
2588 vxge_debug_init(VXGE_ERR,
2589 "%s %s-%d: ISR registration failed",
2590 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2593 vxge_debug_init(VXGE_TRACE,
2594 "new %s-%d line allocated",
2595 "IRQ", vdev->pdev->irq);
2601 static void vxge_poll_vp_reset(unsigned long data)
2603 struct vxgedev *vdev = (struct vxgedev *)data;
2606 for (i = 0; i < vdev->no_of_vpath; i++) {
2607 if (test_bit(i, &vdev->vp_reset)) {
2608 vxge_reset_vpath(vdev, i);
2612 if (j && (vdev->config.intr_type != MSI_X)) {
2613 vxge_hw_device_unmask_all(vdev->devh);
2614 vxge_hw_device_flush_io(vdev->devh);
2617 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2620 static void vxge_poll_vp_lockup(unsigned long data)
2622 struct vxgedev *vdev = (struct vxgedev *)data;
2624 struct vxge_ring *ring;
2625 enum vxge_hw_status status = VXGE_HW_OK;
2627 for (i = 0; i < vdev->no_of_vpath; i++) {
2628 ring = &vdev->vpaths[i].ring;
2629 /* Did this vpath received any packets */
2630 if (ring->stats.prev_rx_frms == ring->stats.rx_frms) {
2631 status = vxge_hw_vpath_check_leak(ring->handle);
2633 /* Did it received any packets last time */
2634 if ((VXGE_HW_FAIL == status) &&
2635 (VXGE_HW_FAIL == ring->last_status)) {
2637 /* schedule vpath reset */
2638 if (!test_and_set_bit(i, &vdev->vp_reset)) {
2640 /* disable interrupts for this vpath */
2641 vxge_vpath_intr_disable(vdev, i);
2643 /* stop the queue for this vpath */
2644 vxge_stop_tx_queue(&vdev->vpaths[i].
2650 ring->stats.prev_rx_frms = ring->stats.rx_frms;
2651 ring->last_status = status;
2654 /* Check every 1 milli second */
2655 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2660 * @dev: pointer to the device structure.
2662 * This function is the open entry point of the driver. It mainly calls a
2663 * function to allocate Rx buffers and inserts them into the buffer
2664 * descriptors and then enables the Rx part of the NIC.
2665 * Return value: '0' on success and an appropriate (-)ve integer as
2666 * defined in errno.h file on failure.
2669 vxge_open(struct net_device *dev)
2671 enum vxge_hw_status status;
2672 struct vxgedev *vdev;
2673 struct __vxge_hw_device *hldev;
2676 u64 val64, function_mode;
2677 vxge_debug_entryexit(VXGE_TRACE,
2678 "%s: %s:%d", dev->name, __func__, __LINE__);
2680 vdev = (struct vxgedev *)netdev_priv(dev);
2681 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2682 function_mode = vdev->config.device_hw_info.function_mode;
2684 /* make sure you have link off by default every time Nic is
2686 netif_carrier_off(dev);
2688 /* Check for another device already opn with INTA */
2689 if ((function_mode == VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2690 test_bit(__VXGE_STATE_CARD_UP, &driver_config->inta_dev_open)) {
2696 status = vxge_open_vpaths(vdev);
2697 if (status != VXGE_HW_OK) {
2698 vxge_debug_init(VXGE_ERR,
2699 "%s: fatal: Vpath open failed", vdev->ndev->name);
2704 vdev->mtu = dev->mtu;
2706 status = vxge_add_isr(vdev);
2707 if (status != VXGE_HW_OK) {
2708 vxge_debug_init(VXGE_ERR,
2709 "%s: fatal: ISR add failed", dev->name);
2715 if (vdev->config.intr_type != MSI_X) {
2716 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2717 vdev->config.napi_weight);
2718 napi_enable(&vdev->napi);
2719 for (i = 0; i < vdev->no_of_vpath; i++)
2720 vdev->vpaths[i].ring.napi_p = &vdev->napi;
2722 for (i = 0; i < vdev->no_of_vpath; i++) {
2723 netif_napi_add(dev, &vdev->vpaths[i].ring.napi,
2724 vxge_poll_msix, vdev->config.napi_weight);
2725 napi_enable(&vdev->vpaths[i].ring.napi);
2726 vdev->vpaths[i].ring.napi_p =
2727 &vdev->vpaths[i].ring.napi;
2732 if (vdev->config.rth_steering) {
2733 status = vxge_rth_configure(vdev);
2734 if (status != VXGE_HW_OK) {
2735 vxge_debug_init(VXGE_ERR,
2736 "%s: fatal: RTH configuration failed",
2743 for (i = 0; i < vdev->no_of_vpath; i++) {
2744 /* set initial mtu before enabling the device */
2745 status = vxge_hw_vpath_mtu_set(vdev->vpaths[i].handle,
2747 if (status != VXGE_HW_OK) {
2748 vxge_debug_init(VXGE_ERR,
2749 "%s: fatal: can not set new MTU", dev->name);
2755 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2756 vxge_debug_init(vdev->level_trace,
2757 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2758 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2760 /* Reprogram the DA table with populated mac addresses */
2761 for (i = 0; i < vdev->no_of_vpath; i++) {
2762 vxge_restore_vpath_mac_addr(&vdev->vpaths[i]);
2763 vxge_restore_vpath_vid_table(&vdev->vpaths[i]);
2766 /* Enable vpath to sniff all unicast/multicast traffic that not
2767 * addressed to them. We allow promiscous mode for PF only
2771 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2772 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2774 vxge_hw_mgmt_reg_write(vdev->devh,
2775 vxge_hw_mgmt_reg_type_mrpcim,
2777 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2778 rxmac_authorize_all_addr),
2781 vxge_hw_mgmt_reg_write(vdev->devh,
2782 vxge_hw_mgmt_reg_type_mrpcim,
2784 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2785 rxmac_authorize_all_vid),
2788 vxge_set_multicast(dev);
2790 /* Enabling Bcast and mcast for all vpath */
2791 for (i = 0; i < vdev->no_of_vpath; i++) {
2792 status = vxge_hw_vpath_bcast_enable(vdev->vpaths[i].handle);
2793 if (status != VXGE_HW_OK)
2794 vxge_debug_init(VXGE_ERR,
2795 "%s : Can not enable bcast for vpath "
2796 "id %d", dev->name, i);
2797 if (vdev->config.addr_learn_en) {
2799 vxge_hw_vpath_mcast_enable(vdev->vpaths[i].handle);
2800 if (status != VXGE_HW_OK)
2801 vxge_debug_init(VXGE_ERR,
2802 "%s : Can not enable mcast for vpath "
2803 "id %d", dev->name, i);
2807 vxge_hw_device_setpause_data(vdev->devh, 0,
2808 vdev->config.tx_pause_enable,
2809 vdev->config.rx_pause_enable);
2811 if (vdev->vp_reset_timer.function == NULL)
2812 vxge_os_timer(vdev->vp_reset_timer,
2813 vxge_poll_vp_reset, vdev, (HZ/2));
2815 if (vdev->vp_lockup_timer.function == NULL)
2816 vxge_os_timer(vdev->vp_lockup_timer,
2817 vxge_poll_vp_lockup, vdev, (HZ/2));
2819 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2823 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2824 netif_carrier_on(vdev->ndev);
2825 printk(KERN_NOTICE "%s: Link Up\n", vdev->ndev->name);
2826 vdev->stats.link_up++;
2829 vxge_hw_device_intr_enable(vdev->devh);
2833 for (i = 0; i < vdev->no_of_vpath; i++) {
2834 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
2836 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
2839 vxge_start_all_tx_queue(vdev);
2846 if (vdev->config.intr_type != MSI_X)
2847 napi_disable(&vdev->napi);
2849 for (i = 0; i < vdev->no_of_vpath; i++)
2850 napi_disable(&vdev->vpaths[i].ring.napi);
2854 vxge_close_vpaths(vdev, 0);
2856 vxge_debug_entryexit(VXGE_TRACE,
2857 "%s: %s:%d Exiting...",
2858 dev->name, __func__, __LINE__);
2862 /* Loop throught the mac address list and delete all the entries */
2863 void vxge_free_mac_add_list(struct vxge_vpath *vpath)
2866 struct list_head *entry, *next;
2867 if (list_empty(&vpath->mac_addr_list))
2870 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2872 kfree((struct vxge_mac_addrs *)entry);
2876 static void vxge_napi_del_all(struct vxgedev *vdev)
2879 if (vdev->config.intr_type != MSI_X)
2880 netif_napi_del(&vdev->napi);
2882 for (i = 0; i < vdev->no_of_vpath; i++)
2883 netif_napi_del(&vdev->vpaths[i].ring.napi);
2888 int do_vxge_close(struct net_device *dev, int do_io)
2890 enum vxge_hw_status status;
2891 struct vxgedev *vdev;
2892 struct __vxge_hw_device *hldev;
2894 u64 val64, vpath_vector;
2895 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2896 dev->name, __func__, __LINE__);
2898 vdev = (struct vxgedev *)netdev_priv(dev);
2899 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2901 if (unlikely(!is_vxge_card_up(vdev)))
2904 /* If vxge_handle_crit_err task is executing,
2905 * wait till it completes. */
2906 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2909 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2911 /* Put the vpath back in normal mode */
2912 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2913 status = vxge_hw_mgmt_reg_read(vdev->devh,
2914 vxge_hw_mgmt_reg_type_mrpcim,
2917 struct vxge_hw_mrpcim_reg,
2918 rts_mgr_cbasin_cfg),
2921 if (status == VXGE_HW_OK) {
2922 val64 &= ~vpath_vector;
2923 status = vxge_hw_mgmt_reg_write(vdev->devh,
2924 vxge_hw_mgmt_reg_type_mrpcim,
2927 struct vxge_hw_mrpcim_reg,
2928 rts_mgr_cbasin_cfg),
2932 /* Remove the function 0 from promiscous mode */
2933 vxge_hw_mgmt_reg_write(vdev->devh,
2934 vxge_hw_mgmt_reg_type_mrpcim,
2936 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2937 rxmac_authorize_all_addr),
2940 vxge_hw_mgmt_reg_write(vdev->devh,
2941 vxge_hw_mgmt_reg_type_mrpcim,
2943 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2944 rxmac_authorize_all_vid),
2949 del_timer_sync(&vdev->vp_lockup_timer);
2951 del_timer_sync(&vdev->vp_reset_timer);
2954 if (vdev->config.intr_type != MSI_X)
2955 napi_disable(&vdev->napi);
2957 for (i = 0; i < vdev->no_of_vpath; i++)
2958 napi_disable(&vdev->vpaths[i].ring.napi);
2961 netif_carrier_off(vdev->ndev);
2962 printk(KERN_NOTICE "%s: Link Down\n", vdev->ndev->name);
2963 vxge_stop_all_tx_queue(vdev);
2965 /* Note that at this point xmit() is stopped by upper layer */
2967 vxge_hw_device_intr_disable(vdev->devh);
2973 vxge_napi_del_all(vdev);
2976 vxge_reset_all_vpaths(vdev);
2978 vxge_close_vpaths(vdev, 0);
2980 vxge_debug_entryexit(VXGE_TRACE,
2981 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
2983 clear_bit(__VXGE_STATE_CARD_UP, &driver_config->inta_dev_open);
2984 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
2991 * @dev: device pointer.
2993 * This is the stop entry point of the driver. It needs to undo exactly
2994 * whatever was done by the open entry point, thus it's usually referred to
2995 * as the close function.Among other things this function mainly stops the
2996 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
2997 * Return value: '0' on success and an appropriate (-)ve integer as
2998 * defined in errno.h file on failure.
3001 vxge_close(struct net_device *dev)
3003 do_vxge_close(dev, 1);
3009 * @dev: net device pointer.
3010 * @new_mtu :the new MTU size for the device.
3012 * A driver entry point to change MTU size for the device. Before changing
3013 * the MTU the device must be stopped.
3015 static int vxge_change_mtu(struct net_device *dev, int new_mtu)
3017 struct vxgedev *vdev = netdev_priv(dev);
3019 vxge_debug_entryexit(vdev->level_trace,
3020 "%s:%d", __func__, __LINE__);
3021 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
3022 vxge_debug_init(vdev->level_err,
3023 "%s: mtu size is invalid", dev->name);
3027 /* check if device is down already */
3028 if (unlikely(!is_vxge_card_up(vdev))) {
3029 /* just store new value, will use later on open() */
3031 vxge_debug_init(vdev->level_err,
3032 "%s", "device is down on MTU change");
3036 vxge_debug_init(vdev->level_trace,
3037 "trying to apply new MTU %d", new_mtu);
3039 if (vxge_close(dev))
3043 vdev->mtu = new_mtu;
3048 vxge_debug_init(vdev->level_trace,
3049 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
3051 vxge_debug_entryexit(vdev->level_trace,
3052 "%s:%d Exiting...", __func__, __LINE__);
3059 * @dev: pointer to the device structure
3061 * Updates the device statistics structure. This function updates the device
3062 * statistics structure in the net_device structure and returns a pointer
3065 static struct net_device_stats *
3066 vxge_get_stats(struct net_device *dev)
3068 struct vxgedev *vdev;
3069 struct net_device_stats *net_stats;
3072 vdev = netdev_priv(dev);
3074 net_stats = &vdev->stats.net_stats;
3076 memset(net_stats, 0, sizeof(struct net_device_stats));
3078 for (k = 0; k < vdev->no_of_vpath; k++) {
3079 net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms;
3080 net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes;
3081 net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors;
3082 net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast;
3083 net_stats->rx_dropped +=
3084 vdev->vpaths[k].ring.stats.rx_dropped;
3086 net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms;
3087 net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes;
3088 net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors;
3096 * @dev: Device pointer.
3097 * @ifr: An IOCTL specific structure, that can contain a pointer to
3098 * a proprietary structure used to pass information to the driver.
3099 * @cmd: This is used to distinguish between the different commands that
3100 * can be passed to the IOCTL functions.
3102 * Entry point for the Ioctl.
3104 static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3111 * @dev: pointer to net device structure
3113 * Watchdog for transmit side.
3114 * This function is triggered if the Tx Queue is stopped
3115 * for a pre-defined amount of time when the Interface is still up.
3118 vxge_tx_watchdog(struct net_device *dev)
3120 struct vxgedev *vdev;
3122 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3124 vdev = (struct vxgedev *)netdev_priv(dev);
3126 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3129 vxge_debug_entryexit(VXGE_TRACE,
3130 "%s:%d Exiting...", __func__, __LINE__);
3134 * vxge_vlan_rx_register
3135 * @dev: net device pointer.
3138 * Vlan group registration
3141 vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
3143 struct vxgedev *vdev;
3144 struct vxge_vpath *vpath;
3147 enum vxge_hw_status status;
3150 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3152 vdev = (struct vxgedev *)netdev_priv(dev);
3154 vpath = &vdev->vpaths[0];
3155 if ((NULL == grp) && (vpath->is_open)) {
3156 /* Get the first vlan */
3157 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3159 while (status == VXGE_HW_OK) {
3161 /* Delete this vlan from the vid table */
3162 for (vp = 0; vp < vdev->no_of_vpath; vp++) {
3163 vpath = &vdev->vpaths[vp];
3164 if (!vpath->is_open)
3167 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3170 /* Get the next vlan to be deleted */
3171 vpath = &vdev->vpaths[0];
3172 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3178 for (i = 0; i < vdev->no_of_vpath; i++) {
3179 if (vdev->vpaths[i].is_configured)
3180 vdev->vpaths[i].ring.vlgrp = grp;
3183 vxge_debug_entryexit(VXGE_TRACE,
3184 "%s:%d Exiting...", __func__, __LINE__);
3188 * vxge_vlan_rx_add_vid
3189 * @dev: net device pointer.
3192 * Add the vlan id to the devices vlan id table
3195 vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3197 struct vxgedev *vdev;
3198 struct vxge_vpath *vpath;
3201 vdev = (struct vxgedev *)netdev_priv(dev);
3203 /* Add these vlan to the vid table */
3204 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3205 vpath = &vdev->vpaths[vp_id];
3206 if (!vpath->is_open)
3208 vxge_hw_vpath_vid_add(vpath->handle, vid);
3213 * vxge_vlan_rx_add_vid
3214 * @dev: net device pointer.
3217 * Remove the vlan id from the device's vlan id table
3220 vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3222 struct vxgedev *vdev;
3223 struct vxge_vpath *vpath;
3226 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3228 vdev = (struct vxgedev *)netdev_priv(dev);
3230 vlan_group_set_device(vdev->vlgrp, vid, NULL);
3232 /* Delete this vlan from the vid table */
3233 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3234 vpath = &vdev->vpaths[vp_id];
3235 if (!vpath->is_open)
3237 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3239 vxge_debug_entryexit(VXGE_TRACE,
3240 "%s:%d Exiting...", __func__, __LINE__);
3243 static const struct net_device_ops vxge_netdev_ops = {
3244 .ndo_open = vxge_open,
3245 .ndo_stop = vxge_close,
3246 .ndo_get_stats = vxge_get_stats,
3247 .ndo_start_xmit = vxge_xmit,
3248 .ndo_validate_addr = eth_validate_addr,
3249 .ndo_set_multicast_list = vxge_set_multicast,
3251 .ndo_do_ioctl = vxge_ioctl,
3253 .ndo_set_mac_address = vxge_set_mac_addr,
3254 .ndo_change_mtu = vxge_change_mtu,
3255 .ndo_vlan_rx_register = vxge_vlan_rx_register,
3256 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3257 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
3259 .ndo_tx_timeout = vxge_tx_watchdog,
3260 #ifdef CONFIG_NET_POLL_CONTROLLER
3261 .ndo_poll_controller = vxge_netpoll,
3265 int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3266 struct vxge_config *config,
3267 int high_dma, int no_of_vpath,
3268 struct vxgedev **vdev_out)
3270 struct net_device *ndev;
3271 enum vxge_hw_status status = VXGE_HW_OK;
3272 struct vxgedev *vdev;
3273 int i, ret = 0, no_of_queue = 1;
3277 if (config->tx_steering_type == TX_MULTIQ_STEERING)
3278 no_of_queue = no_of_vpath;
3280 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3284 vxge_hw_device_trace_level_get(hldev),
3285 "%s : device allocation failed", __func__);
3290 vxge_debug_entryexit(
3291 vxge_hw_device_trace_level_get(hldev),
3292 "%s: %s:%d Entering...",
3293 ndev->name, __func__, __LINE__);
3295 vdev = netdev_priv(ndev);
3296 memset(vdev, 0, sizeof(struct vxgedev));
3300 vdev->pdev = hldev->pdev;
3301 memcpy(&vdev->config, config, sizeof(struct vxge_config));
3302 vdev->rx_csum = 1; /* Enable Rx CSUM by default. */
3304 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3306 ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
3307 NETIF_F_HW_VLAN_FILTER;
3308 /* Driver entry points */
3309 ndev->irq = vdev->pdev->irq;
3310 ndev->base_addr = (unsigned long) hldev->bar0;
3312 ndev->netdev_ops = &vxge_netdev_ops;
3314 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
3316 initialize_ethtool_ops(ndev);
3318 /* Allocate memory for vpath */
3319 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3320 no_of_vpath, GFP_KERNEL);
3321 if (!vdev->vpaths) {
3322 vxge_debug_init(VXGE_ERR,
3323 "%s: vpath memory allocation failed",
3329 ndev->features |= NETIF_F_SG;
3331 ndev->features |= NETIF_F_HW_CSUM;
3332 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3333 "%s : checksuming enabled", __func__);
3336 ndev->features |= NETIF_F_HIGHDMA;
3337 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3338 "%s : using High DMA", __func__);
3341 ndev->features |= NETIF_F_TSO | NETIF_F_TSO6;
3343 if (vdev->config.gro_enable)
3344 ndev->features |= NETIF_F_GRO;
3346 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
3347 ndev->real_num_tx_queues = no_of_vpath;
3350 ndev->features |= NETIF_F_LLTX;
3353 for (i = 0; i < no_of_vpath; i++)
3354 spin_lock_init(&vdev->vpaths[i].fifo.tx_lock);
3356 if (register_netdev(ndev)) {
3357 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3358 "%s: %s : device registration failed!",
3359 ndev->name, __func__);
3364 /* Set the factory defined MAC address initially */
3365 ndev->addr_len = ETH_ALEN;
3367 /* Make Link state as off at this point, when the Link change
3368 * interrupt comes the state will be automatically changed to
3371 netif_carrier_off(ndev);
3373 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3374 "%s: Ethernet device registered",
3379 /* Resetting the Device stats */
3380 status = vxge_hw_mrpcim_stats_access(
3382 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3387 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3389 vxge_hw_device_trace_level_get(hldev),
3390 "%s: device stats clear returns"
3391 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3393 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3394 "%s: %s:%d Exiting...",
3395 ndev->name, __func__, __LINE__);
3399 kfree(vdev->vpaths);
3407 * vxge_device_unregister
3409 * This function will unregister and free network device
3412 vxge_device_unregister(struct __vxge_hw_device *hldev)
3414 struct vxgedev *vdev;
3415 struct net_device *dev;
3417 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3418 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3423 vdev = netdev_priv(dev);
3424 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3425 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3426 level_trace = vdev->level_trace;
3428 vxge_debug_entryexit(level_trace,
3429 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3431 memcpy(buf, vdev->ndev->name, IFNAMSIZ);
3433 /* in 2.6 will call stop() if device is up */
3434 unregister_netdev(dev);
3436 flush_scheduled_work();
3438 vxge_debug_init(level_trace, "%s: ethernet device unregistered", buf);
3439 vxge_debug_entryexit(level_trace,
3440 "%s: %s:%d Exiting...", buf, __func__, __LINE__);
3444 * vxge_callback_crit_err
3446 * This function is called by the alarm handler in interrupt context.
3447 * Driver must analyze it based on the event type.
3450 vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3451 enum vxge_hw_event type, u64 vp_id)
3453 struct net_device *dev = hldev->ndev;
3454 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
3457 vxge_debug_entryexit(vdev->level_trace,
3458 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3460 /* Note: This event type should be used for device wide
3461 * indications only - Serious errors, Slot freeze and critical errors
3463 vdev->cric_err_event = type;
3465 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++)
3466 if (vdev->vpaths[vpath_idx].device_id == vp_id)
3469 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3470 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3471 vxge_debug_init(VXGE_ERR,
3472 "%s: Slot is frozen", vdev->ndev->name);
3473 } else if (type == VXGE_HW_EVENT_SERR) {
3474 vxge_debug_init(VXGE_ERR,
3475 "%s: Encountered Serious Error",
3477 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3478 vxge_debug_init(VXGE_ERR,
3479 "%s: Encountered Critical Error",
3483 if ((type == VXGE_HW_EVENT_SERR) ||
3484 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3485 if (unlikely(vdev->exec_mode))
3486 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3487 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3488 vxge_hw_device_mask_all(hldev);
3489 if (unlikely(vdev->exec_mode))
3490 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3491 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3492 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3494 if (unlikely(vdev->exec_mode))
3495 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3497 /* check if this vpath is already set for reset */
3498 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3500 /* disable interrupts for this vpath */
3501 vxge_vpath_intr_disable(vdev, vpath_idx);
3503 /* stop the queue for this vpath */
3504 vxge_stop_tx_queue(&vdev->vpaths[vpath_idx].
3510 vxge_debug_entryexit(vdev->level_trace,
3511 "%s: %s:%d Exiting...",
3512 vdev->ndev->name, __func__, __LINE__);
3515 static void verify_bandwidth(void)
3517 int i, band_width, total = 0, equal_priority = 0;
3519 /* 1. If user enters 0 for some fifo, give equal priority to all */
3520 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3521 if (bw_percentage[i] == 0) {
3527 if (!equal_priority) {
3528 /* 2. If sum exceeds 100, give equal priority to all */
3529 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3530 if (bw_percentage[i] == 0xFF)
3533 total += bw_percentage[i];
3534 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3541 if (!equal_priority) {
3542 /* Is all the bandwidth consumed? */
3543 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3544 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3545 /* Split rest of bw equally among next VPs*/
3547 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3548 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3549 if (band_width < 2) /* min of 2% */
3552 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3558 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3562 if (equal_priority) {
3563 vxge_debug_init(VXGE_ERR,
3564 "%s: Assigning equal bandwidth to all the vpaths",
3566 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3567 VXGE_HW_MAX_VIRTUAL_PATHS;
3568 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3569 bw_percentage[i] = bw_percentage[0];
3576 * Vpath configuration
3578 static int __devinit vxge_config_vpaths(
3579 struct vxge_hw_device_config *device_config,
3580 u64 vpath_mask, struct vxge_config *config_param)
3582 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3583 u32 txdl_size, txdl_per_memblock;
3585 temp = driver_config->vpath_per_dev;
3586 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3587 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3588 /* No more CPU. Return vpath number as zero.*/
3589 if (driver_config->g_no_cpus == -1)
3592 if (!driver_config->g_no_cpus)
3593 driver_config->g_no_cpus = num_online_cpus();
3595 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3596 if (!driver_config->vpath_per_dev)
3597 driver_config->vpath_per_dev = 1;
3599 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3600 if (!vxge_bVALn(vpath_mask, i, 1))
3604 if (default_no_vpath < driver_config->vpath_per_dev)
3605 driver_config->vpath_per_dev = default_no_vpath;
3607 driver_config->g_no_cpus = driver_config->g_no_cpus -
3608 (driver_config->vpath_per_dev * 2);
3609 if (driver_config->g_no_cpus <= 0)
3610 driver_config->g_no_cpus = -1;
3613 if (driver_config->vpath_per_dev == 1) {
3614 vxge_debug_ll_config(VXGE_TRACE,
3615 "%s: Disable tx and rx steering, "
3616 "as single vpath is configured", VXGE_DRIVER_NAME);
3617 config_param->rth_steering = NO_STEERING;
3618 config_param->tx_steering_type = NO_STEERING;
3619 device_config->rth_en = 0;
3622 /* configure bandwidth */
3623 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3624 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3626 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3627 device_config->vp_config[i].vp_id = i;
3628 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3629 if (no_of_vpaths < driver_config->vpath_per_dev) {
3630 if (!vxge_bVALn(vpath_mask, i, 1)) {
3631 vxge_debug_ll_config(VXGE_TRACE,
3632 "%s: vpath: %d is not available",
3633 VXGE_DRIVER_NAME, i);
3636 vxge_debug_ll_config(VXGE_TRACE,
3637 "%s: vpath: %d available",
3638 VXGE_DRIVER_NAME, i);
3642 vxge_debug_ll_config(VXGE_TRACE,
3643 "%s: vpath: %d is not configured, "
3644 "max_config_vpath exceeded",
3645 VXGE_DRIVER_NAME, i);
3649 /* Configure Tx fifo's */
3650 device_config->vp_config[i].fifo.enable =
3651 VXGE_HW_FIFO_ENABLE;
3652 device_config->vp_config[i].fifo.max_frags =
3654 device_config->vp_config[i].fifo.memblock_size =
3655 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3657 txdl_size = MAX_SKB_FRAGS * sizeof(struct vxge_hw_fifo_txd);
3658 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3660 device_config->vp_config[i].fifo.fifo_blocks =
3661 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3663 device_config->vp_config[i].fifo.intr =
3664 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3666 /* Configure tti properties */
3667 device_config->vp_config[i].tti.intr_enable =
3668 VXGE_HW_TIM_INTR_ENABLE;
3670 device_config->vp_config[i].tti.btimer_val =
3671 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3673 device_config->vp_config[i].tti.timer_ac_en =
3674 VXGE_HW_TIM_TIMER_AC_ENABLE;
3676 /* For msi-x with napi (each vector
3677 has a handler of its own) -
3678 Set CI to OFF for all vpaths */
3679 device_config->vp_config[i].tti.timer_ci_en =
3680 VXGE_HW_TIM_TIMER_CI_DISABLE;
3682 device_config->vp_config[i].tti.timer_ri_en =
3683 VXGE_HW_TIM_TIMER_RI_DISABLE;
3685 device_config->vp_config[i].tti.util_sel =
3686 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3688 device_config->vp_config[i].tti.ltimer_val =
3689 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3691 device_config->vp_config[i].tti.rtimer_val =
3692 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3694 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3695 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3696 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3697 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3698 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3699 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3700 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3702 /* Configure Rx rings */
3703 device_config->vp_config[i].ring.enable =
3704 VXGE_HW_RING_ENABLE;
3706 device_config->vp_config[i].ring.ring_blocks =
3707 VXGE_HW_DEF_RING_BLOCKS;
3708 device_config->vp_config[i].ring.buffer_mode =
3709 VXGE_HW_RING_RXD_BUFFER_MODE_1;
3710 device_config->vp_config[i].ring.rxds_limit =
3711 VXGE_HW_DEF_RING_RXDS_LIMIT;
3712 device_config->vp_config[i].ring.scatter_mode =
3713 VXGE_HW_RING_SCATTER_MODE_A;
3715 /* Configure rti properties */
3716 device_config->vp_config[i].rti.intr_enable =
3717 VXGE_HW_TIM_INTR_ENABLE;
3719 device_config->vp_config[i].rti.btimer_val =
3720 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3722 device_config->vp_config[i].rti.timer_ac_en =
3723 VXGE_HW_TIM_TIMER_AC_ENABLE;
3725 device_config->vp_config[i].rti.timer_ci_en =
3726 VXGE_HW_TIM_TIMER_CI_DISABLE;
3728 device_config->vp_config[i].rti.timer_ri_en =
3729 VXGE_HW_TIM_TIMER_RI_DISABLE;
3731 device_config->vp_config[i].rti.util_sel =
3732 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3734 device_config->vp_config[i].rti.urange_a =
3736 device_config->vp_config[i].rti.urange_b =
3738 device_config->vp_config[i].rti.urange_c =
3740 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3741 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3742 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3743 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3745 device_config->vp_config[i].rti.rtimer_val =
3746 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3748 device_config->vp_config[i].rti.ltimer_val =
3749 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3751 device_config->vp_config[i].rpa_strip_vlan_tag =
3755 driver_config->vpath_per_dev = temp;
3756 return no_of_vpaths;
3759 /* initialize device configuratrions */
3760 static void __devinit vxge_device_config_init(
3761 struct vxge_hw_device_config *device_config,
3764 /* Used for CQRQ/SRQ. */
3765 device_config->dma_blockpool_initial =
3766 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3768 device_config->dma_blockpool_max =
3769 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3771 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3772 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3774 #ifndef CONFIG_PCI_MSI
3775 vxge_debug_init(VXGE_ERR,
3776 "%s: This Kernel does not support "
3777 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3781 /* Configure whether MSI-X or IRQL. */
3782 switch (*intr_type) {
3784 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3788 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX;
3791 /* Timer period between device poll */
3792 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3794 /* Configure mac based steering. */
3795 device_config->rts_mac_en = addr_learn_en;
3797 /* Configure Vpaths */
3798 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3800 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3802 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_initial : %d",
3803 device_config->dma_blockpool_initial);
3804 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_max : %d",
3805 device_config->dma_blockpool_max);
3806 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3807 device_config->intr_mode);
3808 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3809 device_config->device_poll_millis);
3810 vxge_debug_ll_config(VXGE_TRACE, "rts_mac_en : %d",
3811 device_config->rts_mac_en);
3812 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3813 device_config->rth_en);
3814 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3815 device_config->rth_it_type);
3818 static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3822 vxge_debug_init(VXGE_TRACE,
3823 "%s: %d Vpath(s) opened",
3824 vdev->ndev->name, vdev->no_of_vpath);
3826 switch (vdev->config.intr_type) {
3828 vxge_debug_init(VXGE_TRACE,
3829 "%s: Interrupt type INTA", vdev->ndev->name);
3833 vxge_debug_init(VXGE_TRACE,
3834 "%s: Interrupt type MSI-X", vdev->ndev->name);
3838 if (vdev->config.rth_steering) {
3839 vxge_debug_init(VXGE_TRACE,
3840 "%s: RTH steering enabled for TCP_IPV4",
3843 vxge_debug_init(VXGE_TRACE,
3844 "%s: RTH steering disabled", vdev->ndev->name);
3847 switch (vdev->config.tx_steering_type) {
3849 vxge_debug_init(VXGE_TRACE,
3850 "%s: Tx steering disabled", vdev->ndev->name);
3852 case TX_PRIORITY_STEERING:
3853 vxge_debug_init(VXGE_TRACE,
3854 "%s: Unsupported tx steering option",
3856 vxge_debug_init(VXGE_TRACE,
3857 "%s: Tx steering disabled", vdev->ndev->name);
3858 vdev->config.tx_steering_type = 0;
3860 case TX_VLAN_STEERING:
3861 vxge_debug_init(VXGE_TRACE,
3862 "%s: Unsupported tx steering option",
3864 vxge_debug_init(VXGE_TRACE,
3865 "%s: Tx steering disabled", vdev->ndev->name);
3866 vdev->config.tx_steering_type = 0;
3868 case TX_MULTIQ_STEERING:
3869 vxge_debug_init(VXGE_TRACE,
3870 "%s: Tx multiqueue steering enabled",
3873 case TX_PORT_STEERING:
3874 vxge_debug_init(VXGE_TRACE,
3875 "%s: Tx port steering enabled",
3879 vxge_debug_init(VXGE_ERR,
3880 "%s: Unsupported tx steering type",
3882 vxge_debug_init(VXGE_TRACE,
3883 "%s: Tx steering disabled", vdev->ndev->name);
3884 vdev->config.tx_steering_type = 0;
3887 if (vdev->config.gro_enable) {
3888 vxge_debug_init(VXGE_ERR,
3889 "%s: Generic receive offload enabled",
3892 vxge_debug_init(VXGE_TRACE,
3893 "%s: Generic receive offload disabled",
3896 if (vdev->config.addr_learn_en)
3897 vxge_debug_init(VXGE_TRACE,
3898 "%s: MAC Address learning enabled", vdev->ndev->name);
3900 vxge_debug_init(VXGE_TRACE,
3901 "%s: Rx doorbell mode enabled", vdev->ndev->name);
3903 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3904 if (!vxge_bVALn(vpath_mask, i, 1))
3906 vxge_debug_ll_config(VXGE_TRACE,
3907 "%s: MTU size - %d", vdev->ndev->name,
3908 ((struct __vxge_hw_device *)(vdev->devh))->
3909 config.vp_config[i].mtu);
3910 vxge_debug_init(VXGE_TRACE,
3911 "%s: VLAN tag stripping %s", vdev->ndev->name,
3912 ((struct __vxge_hw_device *)(vdev->devh))->
3913 config.vp_config[i].rpa_strip_vlan_tag
3914 ? "Enabled" : "Disabled");
3915 vxge_debug_init(VXGE_TRACE,
3916 "%s: Ring blocks : %d", vdev->ndev->name,
3917 ((struct __vxge_hw_device *)(vdev->devh))->
3918 config.vp_config[i].ring.ring_blocks);
3919 vxge_debug_init(VXGE_TRACE,
3920 "%s: Fifo blocks : %d", vdev->ndev->name,
3921 ((struct __vxge_hw_device *)(vdev->devh))->
3922 config.vp_config[i].fifo.fifo_blocks);
3923 vxge_debug_ll_config(VXGE_TRACE,
3924 "%s: Max frags : %d", vdev->ndev->name,
3925 ((struct __vxge_hw_device *)(vdev->devh))->
3926 config.vp_config[i].fifo.max_frags);
3933 * vxge_pm_suspend - vxge power management suspend entry point
3936 static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
3941 * vxge_pm_resume - vxge power management resume entry point
3944 static int vxge_pm_resume(struct pci_dev *pdev)
3952 * vxge_io_error_detected - called when PCI error is detected
3953 * @pdev: Pointer to PCI device
3954 * @state: The current pci connection state
3956 * This function is called after a PCI bus error affecting
3957 * this device has been detected.
3959 static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
3960 pci_channel_state_t state)
3962 struct __vxge_hw_device *hldev =
3963 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3964 struct net_device *netdev = hldev->ndev;
3966 netif_device_detach(netdev);
3968 if (state == pci_channel_io_perm_failure)
3969 return PCI_ERS_RESULT_DISCONNECT;
3971 if (netif_running(netdev)) {
3972 /* Bring down the card, while avoiding PCI I/O */
3973 do_vxge_close(netdev, 0);
3976 pci_disable_device(pdev);
3978 return PCI_ERS_RESULT_NEED_RESET;
3982 * vxge_io_slot_reset - called after the pci bus has been reset.
3983 * @pdev: Pointer to PCI device
3985 * Restart the card from scratch, as if from a cold-boot.
3986 * At this point, the card has exprienced a hard reset,
3987 * followed by fixups by BIOS, and has its config space
3988 * set up identically to what it was at cold boot.
3990 static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
3992 struct __vxge_hw_device *hldev =
3993 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3994 struct net_device *netdev = hldev->ndev;
3996 struct vxgedev *vdev = netdev_priv(netdev);
3998 if (pci_enable_device(pdev)) {
3999 printk(KERN_ERR "%s: "
4000 "Cannot re-enable device after reset\n",
4002 return PCI_ERS_RESULT_DISCONNECT;
4005 pci_set_master(pdev);
4008 return PCI_ERS_RESULT_RECOVERED;
4012 * vxge_io_resume - called when traffic can start flowing again.
4013 * @pdev: Pointer to PCI device
4015 * This callback is called when the error recovery driver tells
4016 * us that its OK to resume normal operation.
4018 static void vxge_io_resume(struct pci_dev *pdev)
4020 struct __vxge_hw_device *hldev =
4021 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
4022 struct net_device *netdev = hldev->ndev;
4024 if (netif_running(netdev)) {
4025 if (vxge_open(netdev)) {
4026 printk(KERN_ERR "%s: "
4027 "Can't bring device back up after reset\n",
4033 netif_device_attach(netdev);
4038 * @pdev : structure containing the PCI related information of the device.
4039 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4041 * This function is called when a new PCI device gets detected and initializes
4044 * returns 0 on success and negative on failure.
4047 static int __devinit
4048 vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4050 struct __vxge_hw_device *hldev;
4051 enum vxge_hw_status status;
4055 struct vxgedev *vdev;
4056 struct vxge_config ll_config;
4057 struct vxge_hw_device_config *device_config = NULL;
4058 struct vxge_hw_device_attr attr;
4059 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4061 struct vxge_mac_addrs *entry;
4062 static int bus = -1, device = -1;
4065 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4068 if (bus != pdev->bus->number)
4070 if (device != PCI_SLOT(pdev->devfn))
4073 bus = pdev->bus->number;
4074 device = PCI_SLOT(pdev->devfn);
4077 if (driver_config->config_dev_cnt &&
4078 (driver_config->config_dev_cnt !=
4079 driver_config->total_dev_cnt))
4080 vxge_debug_init(VXGE_ERR,
4081 "%s: Configured %d of %d devices",
4083 driver_config->config_dev_cnt,
4084 driver_config->total_dev_cnt);
4085 driver_config->config_dev_cnt = 0;
4086 driver_config->total_dev_cnt = 0;
4087 driver_config->g_no_cpus = 0;
4088 driver_config->vpath_per_dev = max_config_vpath;
4091 driver_config->total_dev_cnt++;
4092 if (++driver_config->config_dev_cnt > max_config_dev) {
4097 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4099 if (!device_config) {
4101 vxge_debug_init(VXGE_ERR,
4102 "device_config : malloc failed %s %d",
4103 __FILE__, __LINE__);
4107 memset(&ll_config, 0, sizeof(struct vxge_config));
4108 ll_config.tx_steering_type = TX_MULTIQ_STEERING;
4109 ll_config.intr_type = MSI_X;
4110 ll_config.napi_weight = NEW_NAPI_WEIGHT;
4111 ll_config.rth_steering = RTH_STEERING;
4113 /* get the default configuration parameters */
4114 vxge_hw_device_config_default_get(device_config);
4116 /* initialize configuration parameters */
4117 vxge_device_config_init(device_config, &ll_config.intr_type);
4119 ret = pci_enable_device(pdev);
4121 vxge_debug_init(VXGE_ERR,
4122 "%s : can not enable PCI device", __func__);
4126 if (!pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) {
4127 vxge_debug_ll_config(VXGE_TRACE,
4128 "%s : using 64bit DMA", __func__);
4132 if (pci_set_consistent_dma_mask(pdev,
4133 0xffffffffffffffffULL)) {
4134 vxge_debug_init(VXGE_ERR,
4135 "%s : unable to obtain 64bit DMA for "
4136 "consistent allocations", __func__);
4140 } else if (!pci_set_dma_mask(pdev, 0xffffffffUL)) {
4141 vxge_debug_ll_config(VXGE_TRACE,
4142 "%s : using 32bit DMA", __func__);
4148 if (pci_request_regions(pdev, VXGE_DRIVER_NAME)) {
4149 vxge_debug_init(VXGE_ERR,
4150 "%s : request regions failed", __func__);
4155 pci_set_master(pdev);
4157 attr.bar0 = pci_ioremap_bar(pdev, 0);
4159 vxge_debug_init(VXGE_ERR,
4160 "%s : cannot remap io memory bar0", __func__);
4164 vxge_debug_ll_config(VXGE_TRACE,
4165 "pci ioremap bar0: %p:0x%llx",
4167 (unsigned long long)pci_resource_start(pdev, 0));
4169 status = vxge_hw_device_hw_info_get(attr.bar0,
4170 &ll_config.device_hw_info);
4171 if (status != VXGE_HW_OK) {
4172 vxge_debug_init(VXGE_ERR,
4173 "%s: Reading of hardware info failed."
4174 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4179 if (ll_config.device_hw_info.fw_version.major !=
4180 VXGE_DRIVER_FW_VERSION_MAJOR) {
4181 vxge_debug_init(VXGE_ERR,
4182 "%s: Incorrect firmware version."
4183 "Please upgrade the firmware to version 1.x.x",
4189 vpath_mask = ll_config.device_hw_info.vpath_mask;
4190 if (vpath_mask == 0) {
4191 vxge_debug_ll_config(VXGE_TRACE,
4192 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4197 vxge_debug_ll_config(VXGE_TRACE,
4198 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4199 (unsigned long long)vpath_mask);
4201 /* Check how many vpaths are available */
4202 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4203 if (!((vpath_mask) & vxge_mBIT(i)))
4205 max_vpath_supported++;
4208 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4209 if ((VXGE_HW_FUNCTION_MODE_SRIOV ==
4210 ll_config.device_hw_info.function_mode) &&
4211 (max_config_dev > 1) && (pdev->is_physfn)) {
4212 ret = pci_enable_sriov(pdev, max_config_dev - 1);
4214 vxge_debug_ll_config(VXGE_ERR,
4215 "Failed to enable SRIOV: %d \n", ret);
4219 * Configure vpaths and get driver configured number of vpaths
4220 * which is less than or equal to the maximum vpaths per function.
4222 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, &ll_config);
4224 vxge_debug_ll_config(VXGE_ERR,
4225 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4230 /* Setting driver callbacks */
4231 attr.uld_callbacks.link_up = vxge_callback_link_up;
4232 attr.uld_callbacks.link_down = vxge_callback_link_down;
4233 attr.uld_callbacks.crit_err = vxge_callback_crit_err;
4235 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4236 if (status != VXGE_HW_OK) {
4237 vxge_debug_init(VXGE_ERR,
4238 "Failed to initialize device (%d)", status);
4243 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4245 /* set private device info */
4246 pci_set_drvdata(pdev, hldev);
4248 ll_config.gro_enable = VXGE_GRO_ALWAYS_AGGREGATE;
4249 ll_config.fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4250 ll_config.addr_learn_en = addr_learn_en;
4251 ll_config.rth_algorithm = RTH_ALG_JENKINS;
4252 ll_config.rth_hash_type_tcpipv4 = VXGE_HW_RING_HASH_TYPE_TCP_IPV4;
4253 ll_config.rth_hash_type_ipv4 = VXGE_HW_RING_HASH_TYPE_NONE;
4254 ll_config.rth_hash_type_tcpipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
4255 ll_config.rth_hash_type_ipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
4256 ll_config.rth_hash_type_tcpipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
4257 ll_config.rth_hash_type_ipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
4258 ll_config.rth_bkt_sz = RTH_BUCKET_SIZE;
4259 ll_config.tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4260 ll_config.rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4262 if (vxge_device_register(hldev, &ll_config, high_dma, no_of_vpath,
4268 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4269 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4270 vxge_hw_device_trace_level_get(hldev));
4272 /* set private HW device info */
4273 hldev->ndev = vdev->ndev;
4274 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4275 vdev->bar0 = attr.bar0;
4276 vdev->max_vpath_supported = max_vpath_supported;
4277 vdev->no_of_vpath = no_of_vpath;
4279 /* Virtual Path count */
4280 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4281 if (!vxge_bVALn(vpath_mask, i, 1))
4283 if (j >= vdev->no_of_vpath)
4286 vdev->vpaths[j].is_configured = 1;
4287 vdev->vpaths[j].device_id = i;
4288 vdev->vpaths[j].fifo.driver_id = j;
4289 vdev->vpaths[j].ring.driver_id = j;
4290 vdev->vpaths[j].vdev = vdev;
4291 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4292 memcpy((u8 *)vdev->vpaths[j].macaddr,
4293 (u8 *)ll_config.device_hw_info.mac_addrs[i],
4296 /* Initialize the mac address list header */
4297 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4299 vdev->vpaths[j].mac_addr_cnt = 0;
4300 vdev->vpaths[j].mcast_addr_cnt = 0;
4303 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4304 vdev->max_config_port = max_config_port;
4306 vdev->vlan_tag_strip = vlan_tag_strip;
4308 /* map the hashing selector table to the configured vpaths */
4309 for (i = 0; i < vdev->no_of_vpath; i++)
4310 vdev->vpath_selector[i] = vpath_selector[i];
4312 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4314 ll_config.device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4315 ll_config.device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4316 ll_config.device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
4318 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
4319 vdev->ndev->name, ll_config.device_hw_info.serial_number);
4321 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
4322 vdev->ndev->name, ll_config.device_hw_info.part_number);
4324 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
4325 vdev->ndev->name, ll_config.device_hw_info.product_desc);
4327 vxge_debug_init(VXGE_TRACE,
4328 "%s: MAC ADDR: %02X:%02X:%02X:%02X:%02X:%02X",
4329 vdev->ndev->name, macaddr[0], macaddr[1], macaddr[2],
4330 macaddr[3], macaddr[4], macaddr[5]);
4332 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4333 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4335 vxge_debug_init(VXGE_TRACE,
4336 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
4337 ll_config.device_hw_info.fw_version.version,
4338 ll_config.device_hw_info.fw_date.date);
4341 switch (ll_config.device_hw_info.function_mode) {
4342 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4343 vxge_debug_init(VXGE_TRACE,
4344 "%s: Single Function Mode Enabled", vdev->ndev->name);
4346 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4347 vxge_debug_init(VXGE_TRACE,
4348 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4350 case VXGE_HW_FUNCTION_MODE_SRIOV:
4351 vxge_debug_init(VXGE_TRACE,
4352 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4354 case VXGE_HW_FUNCTION_MODE_MRIOV:
4355 vxge_debug_init(VXGE_TRACE,
4356 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4361 vxge_print_parm(vdev, vpath_mask);
4363 /* Store the fw version for ethttool option */
4364 strcpy(vdev->fw_version, ll_config.device_hw_info.fw_version.version);
4365 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4366 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4368 /* Copy the station mac address to the list */
4369 for (i = 0; i < vdev->no_of_vpath; i++) {
4370 entry = (struct vxge_mac_addrs *)
4371 kzalloc(sizeof(struct vxge_mac_addrs),
4373 if (NULL == entry) {
4374 vxge_debug_init(VXGE_ERR,
4375 "%s: mac_addr_list : memory allocation failed",
4380 macaddr = (u8 *)&entry->macaddr;
4381 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4382 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4383 vdev->vpaths[i].mac_addr_cnt = 1;
4386 kfree(device_config);
4387 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4388 vdev->ndev->name, __func__, __LINE__);
4390 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4391 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4392 vxge_hw_device_trace_level_get(hldev));
4397 for (i = 0; i < vdev->no_of_vpath; i++)
4398 vxge_free_mac_add_list(&vdev->vpaths[i]);
4400 vxge_device_unregister(hldev);
4402 pci_disable_sriov(pdev);
4403 vxge_hw_device_terminate(hldev);
4407 pci_release_regions(pdev);
4409 pci_disable_device(pdev);
4411 kfree(device_config);
4412 driver_config->config_dev_cnt--;
4413 pci_set_drvdata(pdev, NULL);
4418 * vxge_rem_nic - Free the PCI device
4419 * @pdev: structure containing the PCI related information of the device.
4420 * Description: This function is called by the Pci subsystem to release a
4421 * PCI device and free up all resource held up by the device.
4423 static void __devexit
4424 vxge_remove(struct pci_dev *pdev)
4426 struct __vxge_hw_device *hldev;
4427 struct vxgedev *vdev = NULL;
4428 struct net_device *dev;
4430 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4431 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4435 hldev = (struct __vxge_hw_device *) pci_get_drvdata(pdev);
4440 vdev = netdev_priv(dev);
4442 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4443 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4444 level_trace = vdev->level_trace;
4446 vxge_debug_entryexit(level_trace,
4447 "%s:%d", __func__, __LINE__);
4449 vxge_debug_init(level_trace,
4450 "%s : removing PCI device...", __func__);
4451 vxge_device_unregister(hldev);
4453 for (i = 0; i < vdev->no_of_vpath; i++) {
4454 vxge_free_mac_add_list(&vdev->vpaths[i]);
4455 vdev->vpaths[i].mcast_addr_cnt = 0;
4456 vdev->vpaths[i].mac_addr_cnt = 0;
4459 kfree(vdev->vpaths);
4461 iounmap(vdev->bar0);
4463 pci_disable_sriov(pdev);
4465 /* we are safe to free it now */
4468 vxge_debug_init(level_trace,
4469 "%s:%d Device unregistered", __func__, __LINE__);
4471 vxge_hw_device_terminate(hldev);
4473 pci_disable_device(pdev);
4474 pci_release_regions(pdev);
4475 pci_set_drvdata(pdev, NULL);
4476 vxge_debug_entryexit(level_trace,
4477 "%s:%d Exiting...", __func__, __LINE__);
4480 static struct pci_error_handlers vxge_err_handler = {
4481 .error_detected = vxge_io_error_detected,
4482 .slot_reset = vxge_io_slot_reset,
4483 .resume = vxge_io_resume,
4486 static struct pci_driver vxge_driver = {
4487 .name = VXGE_DRIVER_NAME,
4488 .id_table = vxge_id_table,
4489 .probe = vxge_probe,
4490 .remove = __devexit_p(vxge_remove),
4492 .suspend = vxge_pm_suspend,
4493 .resume = vxge_pm_resume,
4495 .err_handler = &vxge_err_handler,
4503 snprintf(version, 32, "%s", DRV_VERSION);
4505 printk(KERN_CRIT "%s: Copyright(c) 2002-2009 Neterion Inc\n",
4507 printk(KERN_CRIT "%s: Driver version: %s\n",
4508 VXGE_DRIVER_NAME, version);
4512 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4516 ret = pci_register_driver(&vxge_driver);
4518 if (driver_config->config_dev_cnt &&
4519 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4520 vxge_debug_init(VXGE_ERR,
4521 "%s: Configured %d of %d devices",
4522 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4523 driver_config->total_dev_cnt);
4526 kfree(driver_config);
4534 pci_unregister_driver(&vxge_driver);
4535 kfree(driver_config);
4537 module_init(vxge_starter);
4538 module_exit(vxge_closer);