vxge: MSIX one shot mode
[linux-2.6/cjktty.git] / drivers / net / vxge / vxge-main.c
blobe40f619b62b1ef95d7e9090816976aaf9d58e31d
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 Exar Corp's X3100 Series 10GbE PCIe I/O
11 * Virtualized Server Adapter.
12 * Copyright(c) 2002-2010 Exar Corp.
14 * The module loadable parameters that are supported by the driver and a brief
15 * explanation of all the variables:
16 * vlan_tag_strip:
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.
23 * addr_learn_en:
24 * Enable learning the mac address of the guest OS interface in
25 * a virtualization environment.
26 * 0 - DISABLE
27 * 1 - ENABLE
29 * max_config_port:
30 * Maximum number of port to be supported.
31 * MIN -1 and MAX - 2
33 * max_config_vpath:
34 * This configures the maximum no of VPATH configures for each
35 * device function.
36 * MIN - 1 and MAX - 17
38 * max_config_dev:
39 * This configures maximum no of Device function to be enabled.
40 * MIN - 1 and MAX - 17
42 ******************************************************************************/
44 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
46 #include <linux/if_vlan.h>
47 #include <linux/pci.h>
48 #include <linux/slab.h>
49 #include <linux/tcp.h>
50 #include <net/ip.h>
51 #include <linux/netdevice.h>
52 #include <linux/etherdevice.h>
53 #include <linux/firmware.h>
54 #include <linux/net_tstamp.h>
55 #include "vxge-main.h"
56 #include "vxge-reg.h"
58 MODULE_LICENSE("Dual BSD/GPL");
59 MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
60 "Virtualized Server Adapter");
62 static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = {
63 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
64 PCI_ANY_ID},
65 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
66 PCI_ANY_ID},
67 {0}
70 MODULE_DEVICE_TABLE(pci, vxge_id_table);
72 VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
73 VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
74 VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
75 VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
76 VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
77 VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
79 static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
80 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
81 static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
82 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
83 module_param_array(bw_percentage, uint, NULL, 0);
85 static struct vxge_drv_config *driver_config;
87 static inline int is_vxge_card_up(struct vxgedev *vdev)
89 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
92 static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
94 struct sk_buff **skb_ptr = NULL;
95 struct sk_buff **temp;
96 #define NR_SKB_COMPLETED 128
97 struct sk_buff *completed[NR_SKB_COMPLETED];
98 int more;
100 do {
101 more = 0;
102 skb_ptr = completed;
104 if (__netif_tx_trylock(fifo->txq)) {
105 vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
106 NR_SKB_COMPLETED, &more);
107 __netif_tx_unlock(fifo->txq);
110 /* free SKBs */
111 for (temp = completed; temp != skb_ptr; temp++)
112 dev_kfree_skb_irq(*temp);
113 } while (more);
116 static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
118 int i;
120 /* Complete all transmits */
121 for (i = 0; i < vdev->no_of_vpath; i++)
122 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
125 static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
127 int i;
128 struct vxge_ring *ring;
130 /* Complete all receives*/
131 for (i = 0; i < vdev->no_of_vpath; i++) {
132 ring = &vdev->vpaths[i].ring;
133 vxge_hw_vpath_poll_rx(ring->handle);
138 * vxge_callback_link_up
140 * This function is called during interrupt context to notify link up state
141 * change.
143 static void vxge_callback_link_up(struct __vxge_hw_device *hldev)
145 struct net_device *dev = hldev->ndev;
146 struct vxgedev *vdev = netdev_priv(dev);
148 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
149 vdev->ndev->name, __func__, __LINE__);
150 netdev_notice(vdev->ndev, "Link Up\n");
151 vdev->stats.link_up++;
153 netif_carrier_on(vdev->ndev);
154 netif_tx_wake_all_queues(vdev->ndev);
156 vxge_debug_entryexit(VXGE_TRACE,
157 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
161 * vxge_callback_link_down
163 * This function is called during interrupt context to notify link down state
164 * change.
166 static void vxge_callback_link_down(struct __vxge_hw_device *hldev)
168 struct net_device *dev = hldev->ndev;
169 struct vxgedev *vdev = netdev_priv(dev);
171 vxge_debug_entryexit(VXGE_TRACE,
172 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
173 netdev_notice(vdev->ndev, "Link Down\n");
175 vdev->stats.link_down++;
176 netif_carrier_off(vdev->ndev);
177 netif_tx_stop_all_queues(vdev->ndev);
179 vxge_debug_entryexit(VXGE_TRACE,
180 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
184 * vxge_rx_alloc
186 * Allocate SKB.
188 static struct sk_buff *
189 vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
191 struct net_device *dev;
192 struct sk_buff *skb;
193 struct vxge_rx_priv *rx_priv;
195 dev = ring->ndev;
196 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
197 ring->ndev->name, __func__, __LINE__);
199 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
201 /* try to allocate skb first. this one may fail */
202 skb = netdev_alloc_skb(dev, skb_size +
203 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
204 if (skb == NULL) {
205 vxge_debug_mem(VXGE_ERR,
206 "%s: out of memory to allocate SKB", dev->name);
207 ring->stats.skb_alloc_fail++;
208 return NULL;
211 vxge_debug_mem(VXGE_TRACE,
212 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
213 __func__, __LINE__, skb);
215 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
217 rx_priv->skb = skb;
218 rx_priv->skb_data = NULL;
219 rx_priv->data_size = skb_size;
220 vxge_debug_entryexit(VXGE_TRACE,
221 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
223 return skb;
227 * vxge_rx_map
229 static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
231 struct vxge_rx_priv *rx_priv;
232 dma_addr_t dma_addr;
234 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
235 ring->ndev->name, __func__, __LINE__);
236 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
238 rx_priv->skb_data = rx_priv->skb->data;
239 dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
240 rx_priv->data_size, PCI_DMA_FROMDEVICE);
242 if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
243 ring->stats.pci_map_fail++;
244 return -EIO;
246 vxge_debug_mem(VXGE_TRACE,
247 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
248 ring->ndev->name, __func__, __LINE__,
249 (unsigned long long)dma_addr);
250 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
252 rx_priv->data_dma = dma_addr;
253 vxge_debug_entryexit(VXGE_TRACE,
254 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
256 return 0;
260 * vxge_rx_initial_replenish
261 * Allocation of RxD as an initial replenish procedure.
263 static enum vxge_hw_status
264 vxge_rx_initial_replenish(void *dtrh, void *userdata)
266 struct vxge_ring *ring = (struct vxge_ring *)userdata;
267 struct vxge_rx_priv *rx_priv;
269 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
270 ring->ndev->name, __func__, __LINE__);
271 if (vxge_rx_alloc(dtrh, ring,
272 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
273 return VXGE_HW_FAIL;
275 if (vxge_rx_map(dtrh, ring)) {
276 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
277 dev_kfree_skb(rx_priv->skb);
279 return VXGE_HW_FAIL;
281 vxge_debug_entryexit(VXGE_TRACE,
282 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
284 return VXGE_HW_OK;
287 static inline void
288 vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
289 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
292 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
293 ring->ndev->name, __func__, __LINE__);
294 skb_record_rx_queue(skb, ring->driver_id);
295 skb->protocol = eth_type_trans(skb, ring->ndev);
297 ring->stats.rx_frms++;
298 ring->stats.rx_bytes += pkt_length;
300 if (skb->pkt_type == PACKET_MULTICAST)
301 ring->stats.rx_mcast++;
303 vxge_debug_rx(VXGE_TRACE,
304 "%s: %s:%d skb protocol = %d",
305 ring->ndev->name, __func__, __LINE__, skb->protocol);
307 if (ring->gro_enable) {
308 if (ring->vlgrp && ext_info->vlan &&
309 (ring->vlan_tag_strip ==
310 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
311 vlan_gro_receive(ring->napi_p, ring->vlgrp,
312 ext_info->vlan, skb);
313 else
314 napi_gro_receive(ring->napi_p, skb);
315 } else {
316 if (ring->vlgrp && vlan &&
317 (ring->vlan_tag_strip ==
318 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
319 vlan_hwaccel_receive_skb(skb, ring->vlgrp, vlan);
320 else
321 netif_receive_skb(skb);
323 vxge_debug_entryexit(VXGE_TRACE,
324 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
327 static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
328 struct vxge_rx_priv *rx_priv)
330 pci_dma_sync_single_for_device(ring->pdev,
331 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
333 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
334 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
337 static inline void vxge_post(int *dtr_cnt, void **first_dtr,
338 void *post_dtr, struct __vxge_hw_ring *ringh)
340 int dtr_count = *dtr_cnt;
341 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
342 if (*first_dtr)
343 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
344 *first_dtr = post_dtr;
345 } else
346 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
347 dtr_count++;
348 *dtr_cnt = dtr_count;
352 * vxge_rx_1b_compl
354 * If the interrupt is because of a received frame or if the receive ring
355 * contains fresh as yet un-processed frames, this function is called.
357 static enum vxge_hw_status
358 vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
359 u8 t_code, void *userdata)
361 struct vxge_ring *ring = (struct vxge_ring *)userdata;
362 struct net_device *dev = ring->ndev;
363 unsigned int dma_sizes;
364 void *first_dtr = NULL;
365 int dtr_cnt = 0;
366 int data_size;
367 dma_addr_t data_dma;
368 int pkt_length;
369 struct sk_buff *skb;
370 struct vxge_rx_priv *rx_priv;
371 struct vxge_hw_ring_rxd_info ext_info;
372 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
373 ring->ndev->name, __func__, __LINE__);
375 do {
376 prefetch((char *)dtr + L1_CACHE_BYTES);
377 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
378 skb = rx_priv->skb;
379 data_size = rx_priv->data_size;
380 data_dma = rx_priv->data_dma;
381 prefetch(rx_priv->skb_data);
383 vxge_debug_rx(VXGE_TRACE,
384 "%s: %s:%d skb = 0x%p",
385 ring->ndev->name, __func__, __LINE__, skb);
387 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
388 pkt_length = dma_sizes;
390 pkt_length -= ETH_FCS_LEN;
392 vxge_debug_rx(VXGE_TRACE,
393 "%s: %s:%d Packet Length = %d",
394 ring->ndev->name, __func__, __LINE__, pkt_length);
396 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
398 /* check skb validity */
399 vxge_assert(skb);
401 prefetch((char *)skb + L1_CACHE_BYTES);
402 if (unlikely(t_code)) {
403 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
404 VXGE_HW_OK) {
406 ring->stats.rx_errors++;
407 vxge_debug_rx(VXGE_TRACE,
408 "%s: %s :%d Rx T_code is %d",
409 ring->ndev->name, __func__,
410 __LINE__, t_code);
412 /* If the t_code is not supported and if the
413 * t_code is other than 0x5 (unparseable packet
414 * such as unknown UPV6 header), Drop it !!!
416 vxge_re_pre_post(dtr, ring, rx_priv);
418 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
419 ring->stats.rx_dropped++;
420 continue;
424 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
425 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
426 if (!vxge_rx_map(dtr, ring)) {
427 skb_put(skb, pkt_length);
429 pci_unmap_single(ring->pdev, data_dma,
430 data_size, PCI_DMA_FROMDEVICE);
432 vxge_hw_ring_rxd_pre_post(ringh, dtr);
433 vxge_post(&dtr_cnt, &first_dtr, dtr,
434 ringh);
435 } else {
436 dev_kfree_skb(rx_priv->skb);
437 rx_priv->skb = skb;
438 rx_priv->data_size = data_size;
439 vxge_re_pre_post(dtr, ring, rx_priv);
441 vxge_post(&dtr_cnt, &first_dtr, dtr,
442 ringh);
443 ring->stats.rx_dropped++;
444 break;
446 } else {
447 vxge_re_pre_post(dtr, ring, rx_priv);
449 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
450 ring->stats.rx_dropped++;
451 break;
453 } else {
454 struct sk_buff *skb_up;
456 skb_up = netdev_alloc_skb(dev, pkt_length +
457 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
458 if (skb_up != NULL) {
459 skb_reserve(skb_up,
460 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
462 pci_dma_sync_single_for_cpu(ring->pdev,
463 data_dma, data_size,
464 PCI_DMA_FROMDEVICE);
466 vxge_debug_mem(VXGE_TRACE,
467 "%s: %s:%d skb_up = %p",
468 ring->ndev->name, __func__,
469 __LINE__, skb);
470 memcpy(skb_up->data, skb->data, pkt_length);
472 vxge_re_pre_post(dtr, ring, rx_priv);
474 vxge_post(&dtr_cnt, &first_dtr, dtr,
475 ringh);
476 /* will netif_rx small SKB instead */
477 skb = skb_up;
478 skb_put(skb, pkt_length);
479 } else {
480 vxge_re_pre_post(dtr, ring, rx_priv);
482 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
483 vxge_debug_rx(VXGE_ERR,
484 "%s: vxge_rx_1b_compl: out of "
485 "memory", dev->name);
486 ring->stats.skb_alloc_fail++;
487 break;
491 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
492 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
493 ring->rx_csum && /* Offload Rx side CSUM */
494 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
495 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
496 skb->ip_summed = CHECKSUM_UNNECESSARY;
497 else
498 skb_checksum_none_assert(skb);
501 if (ring->rx_hwts) {
502 struct skb_shared_hwtstamps *skb_hwts;
503 u32 ns = *(u32 *)(skb->head + pkt_length);
505 skb_hwts = skb_hwtstamps(skb);
506 skb_hwts->hwtstamp = ns_to_ktime(ns);
507 skb_hwts->syststamp.tv64 = 0;
510 /* rth_hash_type and rth_it_hit are non-zero regardless of
511 * whether rss is enabled. Only the rth_value is zero/non-zero
512 * if rss is disabled/enabled, so key off of that.
514 if (ext_info.rth_value)
515 skb->rxhash = ext_info.rth_value;
517 vxge_rx_complete(ring, skb, ext_info.vlan,
518 pkt_length, &ext_info);
520 ring->budget--;
521 ring->pkts_processed++;
522 if (!ring->budget)
523 break;
525 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
526 &t_code) == VXGE_HW_OK);
528 if (first_dtr)
529 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
531 vxge_debug_entryexit(VXGE_TRACE,
532 "%s:%d Exiting...",
533 __func__, __LINE__);
534 return VXGE_HW_OK;
538 * vxge_xmit_compl
540 * If an interrupt was raised to indicate DMA complete of the Tx packet,
541 * this function is called. It identifies the last TxD whose buffer was
542 * freed and frees all skbs whose data have already DMA'ed into the NICs
543 * internal memory.
545 static enum vxge_hw_status
546 vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
547 enum vxge_hw_fifo_tcode t_code, void *userdata,
548 struct sk_buff ***skb_ptr, int nr_skb, int *more)
550 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
551 struct sk_buff *skb, **done_skb = *skb_ptr;
552 int pkt_cnt = 0;
554 vxge_debug_entryexit(VXGE_TRACE,
555 "%s:%d Entered....", __func__, __LINE__);
557 do {
558 int frg_cnt;
559 skb_frag_t *frag;
560 int i = 0, j;
561 struct vxge_tx_priv *txd_priv =
562 vxge_hw_fifo_txdl_private_get(dtr);
564 skb = txd_priv->skb;
565 frg_cnt = skb_shinfo(skb)->nr_frags;
566 frag = &skb_shinfo(skb)->frags[0];
568 vxge_debug_tx(VXGE_TRACE,
569 "%s: %s:%d fifo_hw = %p dtr = %p "
570 "tcode = 0x%x", fifo->ndev->name, __func__,
571 __LINE__, fifo_hw, dtr, t_code);
572 /* check skb validity */
573 vxge_assert(skb);
574 vxge_debug_tx(VXGE_TRACE,
575 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
576 fifo->ndev->name, __func__, __LINE__,
577 skb, txd_priv, frg_cnt);
578 if (unlikely(t_code)) {
579 fifo->stats.tx_errors++;
580 vxge_debug_tx(VXGE_ERR,
581 "%s: tx: dtr %p completed due to "
582 "error t_code %01x", fifo->ndev->name,
583 dtr, t_code);
584 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
587 /* for unfragmented skb */
588 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
589 skb_headlen(skb), PCI_DMA_TODEVICE);
591 for (j = 0; j < frg_cnt; j++) {
592 pci_unmap_page(fifo->pdev,
593 txd_priv->dma_buffers[i++],
594 frag->size, PCI_DMA_TODEVICE);
595 frag += 1;
598 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
600 /* Updating the statistics block */
601 fifo->stats.tx_frms++;
602 fifo->stats.tx_bytes += skb->len;
604 *done_skb++ = skb;
606 if (--nr_skb <= 0) {
607 *more = 1;
608 break;
611 pkt_cnt++;
612 if (pkt_cnt > fifo->indicate_max_pkts)
613 break;
615 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
616 &dtr, &t_code) == VXGE_HW_OK);
618 *skb_ptr = done_skb;
619 if (netif_tx_queue_stopped(fifo->txq))
620 netif_tx_wake_queue(fifo->txq);
622 vxge_debug_entryexit(VXGE_TRACE,
623 "%s: %s:%d Exiting...",
624 fifo->ndev->name, __func__, __LINE__);
625 return VXGE_HW_OK;
628 /* select a vpath to transmit the packet */
629 static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
631 u16 queue_len, counter = 0;
632 if (skb->protocol == htons(ETH_P_IP)) {
633 struct iphdr *ip;
634 struct tcphdr *th;
636 ip = ip_hdr(skb);
638 if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) {
639 th = (struct tcphdr *)(((unsigned char *)ip) +
640 ip->ihl*4);
642 queue_len = vdev->no_of_vpath;
643 counter = (ntohs(th->source) +
644 ntohs(th->dest)) &
645 vdev->vpath_selector[queue_len - 1];
646 if (counter >= queue_len)
647 counter = queue_len - 1;
650 return counter;
653 static enum vxge_hw_status vxge_search_mac_addr_in_list(
654 struct vxge_vpath *vpath, u64 del_mac)
656 struct list_head *entry, *next;
657 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
658 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
659 return TRUE;
661 return FALSE;
664 static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
666 struct vxge_mac_addrs *new_mac_entry;
667 u8 *mac_address = NULL;
669 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
670 return TRUE;
672 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
673 if (!new_mac_entry) {
674 vxge_debug_mem(VXGE_ERR,
675 "%s: memory allocation failed",
676 VXGE_DRIVER_NAME);
677 return FALSE;
680 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
682 /* Copy the new mac address to the list */
683 mac_address = (u8 *)&new_mac_entry->macaddr;
684 memcpy(mac_address, mac->macaddr, ETH_ALEN);
686 new_mac_entry->state = mac->state;
687 vpath->mac_addr_cnt++;
689 /* Is this a multicast address */
690 if (0x01 & mac->macaddr[0])
691 vpath->mcast_addr_cnt++;
693 return TRUE;
696 /* Add a mac address to DA table */
697 static enum vxge_hw_status
698 vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
700 enum vxge_hw_status status = VXGE_HW_OK;
701 struct vxge_vpath *vpath;
702 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
704 if (0x01 & mac->macaddr[0]) /* multicast address */
705 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
706 else
707 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
709 vpath = &vdev->vpaths[mac->vpath_no];
710 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
711 mac->macmask, duplicate_mode);
712 if (status != VXGE_HW_OK) {
713 vxge_debug_init(VXGE_ERR,
714 "DA config add entry failed for vpath:%d",
715 vpath->device_id);
716 } else
717 if (FALSE == vxge_mac_list_add(vpath, mac))
718 status = -EPERM;
720 return status;
723 static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
725 struct macInfo mac_info;
726 u8 *mac_address = NULL;
727 u64 mac_addr = 0, vpath_vector = 0;
728 int vpath_idx = 0;
729 enum vxge_hw_status status = VXGE_HW_OK;
730 struct vxge_vpath *vpath = NULL;
731 struct __vxge_hw_device *hldev;
733 hldev = pci_get_drvdata(vdev->pdev);
735 mac_address = (u8 *)&mac_addr;
736 memcpy(mac_address, mac_header, ETH_ALEN);
738 /* Is this mac address already in the list? */
739 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
740 vpath = &vdev->vpaths[vpath_idx];
741 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
742 return vpath_idx;
745 memset(&mac_info, 0, sizeof(struct macInfo));
746 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
748 /* Any vpath has room to add mac address to its da table? */
749 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
750 vpath = &vdev->vpaths[vpath_idx];
751 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
752 /* Add this mac address to this vpath */
753 mac_info.vpath_no = vpath_idx;
754 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
755 status = vxge_add_mac_addr(vdev, &mac_info);
756 if (status != VXGE_HW_OK)
757 return -EPERM;
758 return vpath_idx;
762 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
763 vpath_idx = 0;
764 mac_info.vpath_no = vpath_idx;
765 /* Is the first vpath already selected as catch-basin ? */
766 vpath = &vdev->vpaths[vpath_idx];
767 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
768 /* Add this mac address to this vpath */
769 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
770 return -EPERM;
771 return vpath_idx;
774 /* Select first vpath as catch-basin */
775 vpath_vector = vxge_mBIT(vpath->device_id);
776 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
777 vxge_hw_mgmt_reg_type_mrpcim,
779 (ulong)offsetof(
780 struct vxge_hw_mrpcim_reg,
781 rts_mgr_cbasin_cfg),
782 vpath_vector);
783 if (status != VXGE_HW_OK) {
784 vxge_debug_tx(VXGE_ERR,
785 "%s: Unable to set the vpath-%d in catch-basin mode",
786 VXGE_DRIVER_NAME, vpath->device_id);
787 return -EPERM;
790 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
791 return -EPERM;
793 return vpath_idx;
797 * vxge_xmit
798 * @skb : the socket buffer containing the Tx data.
799 * @dev : device pointer.
801 * This function is the Tx entry point of the driver. Neterion NIC supports
802 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
804 static netdev_tx_t
805 vxge_xmit(struct sk_buff *skb, struct net_device *dev)
807 struct vxge_fifo *fifo = NULL;
808 void *dtr_priv;
809 void *dtr = NULL;
810 struct vxgedev *vdev = NULL;
811 enum vxge_hw_status status;
812 int frg_cnt, first_frg_len;
813 skb_frag_t *frag;
814 int i = 0, j = 0, avail;
815 u64 dma_pointer;
816 struct vxge_tx_priv *txdl_priv = NULL;
817 struct __vxge_hw_fifo *fifo_hw;
818 int offload_type;
819 int vpath_no = 0;
821 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
822 dev->name, __func__, __LINE__);
824 /* A buffer with no data will be dropped */
825 if (unlikely(skb->len <= 0)) {
826 vxge_debug_tx(VXGE_ERR,
827 "%s: Buffer has no data..", dev->name);
828 dev_kfree_skb(skb);
829 return NETDEV_TX_OK;
832 vdev = netdev_priv(dev);
834 if (unlikely(!is_vxge_card_up(vdev))) {
835 vxge_debug_tx(VXGE_ERR,
836 "%s: vdev not initialized", dev->name);
837 dev_kfree_skb(skb);
838 return NETDEV_TX_OK;
841 if (vdev->config.addr_learn_en) {
842 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
843 if (vpath_no == -EPERM) {
844 vxge_debug_tx(VXGE_ERR,
845 "%s: Failed to store the mac address",
846 dev->name);
847 dev_kfree_skb(skb);
848 return NETDEV_TX_OK;
852 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
853 vpath_no = skb_get_queue_mapping(skb);
854 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
855 vpath_no = vxge_get_vpath_no(vdev, skb);
857 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
859 if (vpath_no >= vdev->no_of_vpath)
860 vpath_no = 0;
862 fifo = &vdev->vpaths[vpath_no].fifo;
863 fifo_hw = fifo->handle;
865 if (netif_tx_queue_stopped(fifo->txq))
866 return NETDEV_TX_BUSY;
868 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
869 if (avail == 0) {
870 vxge_debug_tx(VXGE_ERR,
871 "%s: No free TXDs available", dev->name);
872 fifo->stats.txd_not_free++;
873 goto _exit0;
876 /* Last TXD? Stop tx queue to avoid dropping packets. TX
877 * completion will resume the queue.
879 if (avail == 1)
880 netif_tx_stop_queue(fifo->txq);
882 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
883 if (unlikely(status != VXGE_HW_OK)) {
884 vxge_debug_tx(VXGE_ERR,
885 "%s: Out of descriptors .", dev->name);
886 fifo->stats.txd_out_of_desc++;
887 goto _exit0;
890 vxge_debug_tx(VXGE_TRACE,
891 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
892 dev->name, __func__, __LINE__,
893 fifo_hw, dtr, dtr_priv);
895 if (vlan_tx_tag_present(skb)) {
896 u16 vlan_tag = vlan_tx_tag_get(skb);
897 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
900 first_frg_len = skb_headlen(skb);
902 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
903 PCI_DMA_TODEVICE);
905 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
906 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
907 fifo->stats.pci_map_fail++;
908 goto _exit0;
911 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
912 txdl_priv->skb = skb;
913 txdl_priv->dma_buffers[j] = dma_pointer;
915 frg_cnt = skb_shinfo(skb)->nr_frags;
916 vxge_debug_tx(VXGE_TRACE,
917 "%s: %s:%d skb = %p txdl_priv = %p "
918 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
919 __func__, __LINE__, skb, txdl_priv,
920 frg_cnt, (unsigned long long)dma_pointer);
922 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
923 first_frg_len);
925 frag = &skb_shinfo(skb)->frags[0];
926 for (i = 0; i < frg_cnt; i++) {
927 /* ignore 0 length fragment */
928 if (!frag->size)
929 continue;
931 dma_pointer = (u64) pci_map_page(fifo->pdev, frag->page,
932 frag->page_offset, frag->size,
933 PCI_DMA_TODEVICE);
935 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
936 goto _exit2;
937 vxge_debug_tx(VXGE_TRACE,
938 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
939 dev->name, __func__, __LINE__, i,
940 (unsigned long long)dma_pointer);
942 txdl_priv->dma_buffers[j] = dma_pointer;
943 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
944 frag->size);
945 frag += 1;
948 offload_type = vxge_offload_type(skb);
950 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
951 int mss = vxge_tcp_mss(skb);
952 if (mss) {
953 vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
954 dev->name, __func__, __LINE__, mss);
955 vxge_hw_fifo_txdl_mss_set(dtr, mss);
956 } else {
957 vxge_assert(skb->len <=
958 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
959 vxge_assert(0);
960 goto _exit1;
964 if (skb->ip_summed == CHECKSUM_PARTIAL)
965 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
966 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
967 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
968 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
970 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
972 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
973 dev->name, __func__, __LINE__);
974 return NETDEV_TX_OK;
976 _exit2:
977 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
978 _exit1:
979 j = 0;
980 frag = &skb_shinfo(skb)->frags[0];
982 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
983 skb_headlen(skb), PCI_DMA_TODEVICE);
985 for (; j < i; j++) {
986 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
987 frag->size, PCI_DMA_TODEVICE);
988 frag += 1;
991 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
992 _exit0:
993 netif_tx_stop_queue(fifo->txq);
994 dev_kfree_skb(skb);
996 return NETDEV_TX_OK;
1000 * vxge_rx_term
1002 * Function will be called by hw function to abort all outstanding receive
1003 * descriptors.
1005 static void
1006 vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1008 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1009 struct vxge_rx_priv *rx_priv =
1010 vxge_hw_ring_rxd_private_get(dtrh);
1012 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1013 ring->ndev->name, __func__, __LINE__);
1014 if (state != VXGE_HW_RXD_STATE_POSTED)
1015 return;
1017 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1018 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1020 dev_kfree_skb(rx_priv->skb);
1021 rx_priv->skb_data = NULL;
1023 vxge_debug_entryexit(VXGE_TRACE,
1024 "%s: %s:%d Exiting...",
1025 ring->ndev->name, __func__, __LINE__);
1029 * vxge_tx_term
1031 * Function will be called to abort all outstanding tx descriptors
1033 static void
1034 vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1036 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1037 skb_frag_t *frag;
1038 int i = 0, j, frg_cnt;
1039 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1040 struct sk_buff *skb = txd_priv->skb;
1042 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1044 if (state != VXGE_HW_TXDL_STATE_POSTED)
1045 return;
1047 /* check skb validity */
1048 vxge_assert(skb);
1049 frg_cnt = skb_shinfo(skb)->nr_frags;
1050 frag = &skb_shinfo(skb)->frags[0];
1052 /* for unfragmented skb */
1053 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1054 skb_headlen(skb), PCI_DMA_TODEVICE);
1056 for (j = 0; j < frg_cnt; j++) {
1057 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
1058 frag->size, PCI_DMA_TODEVICE);
1059 frag += 1;
1062 dev_kfree_skb(skb);
1064 vxge_debug_entryexit(VXGE_TRACE,
1065 "%s:%d Exiting...", __func__, __LINE__);
1068 static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1070 struct list_head *entry, *next;
1071 u64 del_mac = 0;
1072 u8 *mac_address = (u8 *) (&del_mac);
1074 /* Copy the mac address to delete from the list */
1075 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1077 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1078 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1079 list_del(entry);
1080 kfree((struct vxge_mac_addrs *)entry);
1081 vpath->mac_addr_cnt--;
1083 /* Is this a multicast address */
1084 if (0x01 & mac->macaddr[0])
1085 vpath->mcast_addr_cnt--;
1086 return TRUE;
1090 return FALSE;
1093 /* delete a mac address from DA table */
1094 static enum vxge_hw_status
1095 vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1097 enum vxge_hw_status status = VXGE_HW_OK;
1098 struct vxge_vpath *vpath;
1100 vpath = &vdev->vpaths[mac->vpath_no];
1101 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1102 mac->macmask);
1103 if (status != VXGE_HW_OK) {
1104 vxge_debug_init(VXGE_ERR,
1105 "DA config delete entry failed for vpath:%d",
1106 vpath->device_id);
1107 } else
1108 vxge_mac_list_del(vpath, mac);
1109 return status;
1113 * vxge_set_multicast
1114 * @dev: pointer to the device structure
1116 * Entry point for multicast address enable/disable
1117 * This function is a driver entry point which gets called by the kernel
1118 * whenever multicast addresses must be enabled/disabled. This also gets
1119 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1120 * determine, if multicast address must be enabled or if promiscuous mode
1121 * is to be disabled etc.
1123 static void vxge_set_multicast(struct net_device *dev)
1125 struct netdev_hw_addr *ha;
1126 struct vxgedev *vdev;
1127 int i, mcast_cnt = 0;
1128 struct __vxge_hw_device *hldev;
1129 struct vxge_vpath *vpath;
1130 enum vxge_hw_status status = VXGE_HW_OK;
1131 struct macInfo mac_info;
1132 int vpath_idx = 0;
1133 struct vxge_mac_addrs *mac_entry;
1134 struct list_head *list_head;
1135 struct list_head *entry, *next;
1136 u8 *mac_address = NULL;
1138 vxge_debug_entryexit(VXGE_TRACE,
1139 "%s:%d", __func__, __LINE__);
1141 vdev = netdev_priv(dev);
1142 hldev = (struct __vxge_hw_device *)vdev->devh;
1144 if (unlikely(!is_vxge_card_up(vdev)))
1145 return;
1147 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1148 for (i = 0; i < vdev->no_of_vpath; i++) {
1149 vpath = &vdev->vpaths[i];
1150 vxge_assert(vpath->is_open);
1151 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1152 if (status != VXGE_HW_OK)
1153 vxge_debug_init(VXGE_ERR, "failed to enable "
1154 "multicast, status %d", status);
1155 vdev->all_multi_flg = 1;
1157 } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
1158 for (i = 0; i < vdev->no_of_vpath; i++) {
1159 vpath = &vdev->vpaths[i];
1160 vxge_assert(vpath->is_open);
1161 status = vxge_hw_vpath_mcast_disable(vpath->handle);
1162 if (status != VXGE_HW_OK)
1163 vxge_debug_init(VXGE_ERR, "failed to disable "
1164 "multicast, status %d", status);
1165 vdev->all_multi_flg = 0;
1170 if (!vdev->config.addr_learn_en) {
1171 for (i = 0; i < vdev->no_of_vpath; i++) {
1172 vpath = &vdev->vpaths[i];
1173 vxge_assert(vpath->is_open);
1175 if (dev->flags & IFF_PROMISC)
1176 status = vxge_hw_vpath_promisc_enable(
1177 vpath->handle);
1178 else
1179 status = vxge_hw_vpath_promisc_disable(
1180 vpath->handle);
1181 if (status != VXGE_HW_OK)
1182 vxge_debug_init(VXGE_ERR, "failed to %s promisc"
1183 ", status %d", dev->flags&IFF_PROMISC ?
1184 "enable" : "disable", status);
1188 memset(&mac_info, 0, sizeof(struct macInfo));
1189 /* Update individual M_CAST address list */
1190 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
1191 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1192 list_head = &vdev->vpaths[0].mac_addr_list;
1193 if ((netdev_mc_count(dev) +
1194 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1195 vdev->vpaths[0].max_mac_addr_cnt)
1196 goto _set_all_mcast;
1198 /* Delete previous MC's */
1199 for (i = 0; i < mcast_cnt; i++) {
1200 list_for_each_safe(entry, next, list_head) {
1201 mac_entry = (struct vxge_mac_addrs *)entry;
1202 /* Copy the mac address to delete */
1203 mac_address = (u8 *)&mac_entry->macaddr;
1204 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1206 /* Is this a multicast address */
1207 if (0x01 & mac_info.macaddr[0]) {
1208 for (vpath_idx = 0; vpath_idx <
1209 vdev->no_of_vpath;
1210 vpath_idx++) {
1211 mac_info.vpath_no = vpath_idx;
1212 status = vxge_del_mac_addr(
1213 vdev,
1214 &mac_info);
1220 /* Add new ones */
1221 netdev_for_each_mc_addr(ha, dev) {
1222 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
1223 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1224 vpath_idx++) {
1225 mac_info.vpath_no = vpath_idx;
1226 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1227 status = vxge_add_mac_addr(vdev, &mac_info);
1228 if (status != VXGE_HW_OK) {
1229 vxge_debug_init(VXGE_ERR,
1230 "%s:%d Setting individual"
1231 "multicast address failed",
1232 __func__, __LINE__);
1233 goto _set_all_mcast;
1238 return;
1239 _set_all_mcast:
1240 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1241 /* Delete previous MC's */
1242 for (i = 0; i < mcast_cnt; i++) {
1243 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])
1251 break;
1254 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1255 vpath_idx++) {
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 vpath = &vdev->vpaths[i];
1264 vxge_assert(vpath->is_open);
1266 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1267 if (status != VXGE_HW_OK) {
1268 vxge_debug_init(VXGE_ERR,
1269 "%s:%d Enabling all multicasts failed",
1270 __func__, __LINE__);
1272 vdev->all_multi_flg = 1;
1274 dev->flags |= IFF_ALLMULTI;
1277 vxge_debug_entryexit(VXGE_TRACE,
1278 "%s:%d Exiting...", __func__, __LINE__);
1282 * vxge_set_mac_addr
1283 * @dev: pointer to the device structure
1285 * Update entry "0" (default MAC addr)
1287 static int vxge_set_mac_addr(struct net_device *dev, void *p)
1289 struct sockaddr *addr = p;
1290 struct vxgedev *vdev;
1291 struct __vxge_hw_device *hldev;
1292 enum vxge_hw_status status = VXGE_HW_OK;
1293 struct macInfo mac_info_new, mac_info_old;
1294 int vpath_idx = 0;
1296 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1298 vdev = netdev_priv(dev);
1299 hldev = vdev->devh;
1301 if (!is_valid_ether_addr(addr->sa_data))
1302 return -EINVAL;
1304 memset(&mac_info_new, 0, sizeof(struct macInfo));
1305 memset(&mac_info_old, 0, sizeof(struct macInfo));
1307 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1308 __func__, __LINE__);
1310 /* Get the old address */
1311 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1313 /* Copy the new address */
1314 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1316 /* First delete the old mac address from all the vpaths
1317 as we can't specify the index while adding new mac address */
1318 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1319 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1320 if (!vpath->is_open) {
1321 /* This can happen when this interface is added/removed
1322 to the bonding interface. Delete this station address
1323 from the linked list */
1324 vxge_mac_list_del(vpath, &mac_info_old);
1326 /* Add this new address to the linked list
1327 for later restoring */
1328 vxge_mac_list_add(vpath, &mac_info_new);
1330 continue;
1332 /* Delete the station address */
1333 mac_info_old.vpath_no = vpath_idx;
1334 status = vxge_del_mac_addr(vdev, &mac_info_old);
1337 if (unlikely(!is_vxge_card_up(vdev))) {
1338 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1339 return VXGE_HW_OK;
1342 /* Set this mac address to all the vpaths */
1343 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1344 mac_info_new.vpath_no = vpath_idx;
1345 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1346 status = vxge_add_mac_addr(vdev, &mac_info_new);
1347 if (status != VXGE_HW_OK)
1348 return -EINVAL;
1351 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1353 return status;
1357 * vxge_vpath_intr_enable
1358 * @vdev: pointer to vdev
1359 * @vp_id: vpath for which to enable the interrupts
1361 * Enables the interrupts for the vpath
1363 static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
1365 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1366 int msix_id = 0;
1367 int tim_msix_id[4] = {0, 1, 0, 0};
1368 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
1370 vxge_hw_vpath_intr_enable(vpath->handle);
1372 if (vdev->config.intr_type == INTA)
1373 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1374 else {
1375 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1376 alarm_msix_id);
1378 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1379 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1380 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1382 /* enable the alarm vector */
1383 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1384 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1385 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1390 * vxge_vpath_intr_disable
1391 * @vdev: pointer to vdev
1392 * @vp_id: vpath for which to disable the interrupts
1394 * Disables the interrupts for the vpath
1396 static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
1398 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1399 struct __vxge_hw_device *hldev;
1400 int msix_id;
1402 hldev = pci_get_drvdata(vdev->pdev);
1404 vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
1406 vxge_hw_vpath_intr_disable(vpath->handle);
1408 if (vdev->config.intr_type == INTA)
1409 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1410 else {
1411 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1412 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1413 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1415 /* disable the alarm vector */
1416 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1417 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
1418 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1422 /* list all mac addresses from DA table */
1423 static enum vxge_hw_status
1424 vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, struct macInfo *mac)
1426 enum vxge_hw_status status = VXGE_HW_OK;
1427 unsigned char macmask[ETH_ALEN];
1428 unsigned char macaddr[ETH_ALEN];
1430 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1431 macaddr, macmask);
1432 if (status != VXGE_HW_OK) {
1433 vxge_debug_init(VXGE_ERR,
1434 "DA config list entry failed for vpath:%d",
1435 vpath->device_id);
1436 return status;
1439 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1440 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1441 macaddr, macmask);
1442 if (status != VXGE_HW_OK)
1443 break;
1446 return status;
1449 /* Store all mac addresses from the list to the DA table */
1450 static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1452 enum vxge_hw_status status = VXGE_HW_OK;
1453 struct macInfo mac_info;
1454 u8 *mac_address = NULL;
1455 struct list_head *entry, *next;
1457 memset(&mac_info, 0, sizeof(struct macInfo));
1459 if (vpath->is_open) {
1460 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1461 mac_address =
1462 (u8 *)&
1463 ((struct vxge_mac_addrs *)entry)->macaddr;
1464 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1465 ((struct vxge_mac_addrs *)entry)->state =
1466 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1467 /* does this mac address already exist in da table? */
1468 status = vxge_search_mac_addr_in_da_table(vpath,
1469 &mac_info);
1470 if (status != VXGE_HW_OK) {
1471 /* Add this mac address to the DA table */
1472 status = vxge_hw_vpath_mac_addr_add(
1473 vpath->handle, mac_info.macaddr,
1474 mac_info.macmask,
1475 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
1476 if (status != VXGE_HW_OK) {
1477 vxge_debug_init(VXGE_ERR,
1478 "DA add entry failed for vpath:%d",
1479 vpath->device_id);
1480 ((struct vxge_mac_addrs *)entry)->state
1481 = VXGE_LL_MAC_ADDR_IN_LIST;
1487 return status;
1490 /* Store all vlan ids from the list to the vid table */
1491 static enum vxge_hw_status
1492 vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1494 enum vxge_hw_status status = VXGE_HW_OK;
1495 struct vxgedev *vdev = vpath->vdev;
1496 u16 vid;
1498 if (vdev->vlgrp && vpath->is_open) {
1500 for (vid = 0; vid < VLAN_N_VID; vid++) {
1501 if (!vlan_group_get_device(vdev->vlgrp, vid))
1502 continue;
1503 /* Add these vlan to the vid table */
1504 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
1508 return status;
1512 * vxge_reset_vpath
1513 * @vdev: pointer to vdev
1514 * @vp_id: vpath to reset
1516 * Resets the vpath
1518 static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1520 enum vxge_hw_status status = VXGE_HW_OK;
1521 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1522 int ret = 0;
1524 /* check if device is down already */
1525 if (unlikely(!is_vxge_card_up(vdev)))
1526 return 0;
1528 /* is device reset already scheduled */
1529 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1530 return 0;
1532 if (vpath->handle) {
1533 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
1534 if (is_vxge_card_up(vdev) &&
1535 vxge_hw_vpath_recover_from_reset(vpath->handle)
1536 != VXGE_HW_OK) {
1537 vxge_debug_init(VXGE_ERR,
1538 "vxge_hw_vpath_recover_from_reset"
1539 "failed for vpath:%d", vp_id);
1540 return status;
1542 } else {
1543 vxge_debug_init(VXGE_ERR,
1544 "vxge_hw_vpath_reset failed for"
1545 "vpath:%d", vp_id);
1546 return status;
1548 } else
1549 return VXGE_HW_FAIL;
1551 vxge_restore_vpath_mac_addr(vpath);
1552 vxge_restore_vpath_vid_table(vpath);
1554 /* Enable all broadcast */
1555 vxge_hw_vpath_bcast_enable(vpath->handle);
1557 /* Enable all multicast */
1558 if (vdev->all_multi_flg) {
1559 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1560 if (status != VXGE_HW_OK)
1561 vxge_debug_init(VXGE_ERR,
1562 "%s:%d Enabling multicast failed",
1563 __func__, __LINE__);
1566 /* Enable the interrupts */
1567 vxge_vpath_intr_enable(vdev, vp_id);
1569 smp_wmb();
1571 /* Enable the flow of traffic through the vpath */
1572 vxge_hw_vpath_enable(vpath->handle);
1574 smp_wmb();
1575 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
1576 vpath->ring.last_status = VXGE_HW_OK;
1578 /* Vpath reset done */
1579 clear_bit(vp_id, &vdev->vp_reset);
1581 /* Start the vpath queue */
1582 if (netif_tx_queue_stopped(vpath->fifo.txq))
1583 netif_tx_wake_queue(vpath->fifo.txq);
1585 return ret;
1588 /* Configure CI */
1589 static void vxge_config_ci_for_tti_rti(struct vxgedev *vdev)
1591 int i = 0;
1593 /* Enable CI for RTI */
1594 if (vdev->config.intr_type == MSI_X) {
1595 for (i = 0; i < vdev->no_of_vpath; i++) {
1596 struct __vxge_hw_ring *hw_ring;
1598 hw_ring = vdev->vpaths[i].ring.handle;
1599 vxge_hw_vpath_dynamic_rti_ci_set(hw_ring);
1603 /* Enable CI for TTI */
1604 for (i = 0; i < vdev->no_of_vpath; i++) {
1605 struct __vxge_hw_fifo *hw_fifo = vdev->vpaths[i].fifo.handle;
1606 vxge_hw_vpath_tti_ci_set(hw_fifo);
1608 * For Inta (with or without napi), Set CI ON for only one
1609 * vpath. (Have only one free running timer).
1611 if ((vdev->config.intr_type == INTA) && (i == 0))
1612 break;
1615 return;
1618 static int do_vxge_reset(struct vxgedev *vdev, int event)
1620 enum vxge_hw_status status;
1621 int ret = 0, vp_id, i;
1623 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1625 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1626 /* check if device is down already */
1627 if (unlikely(!is_vxge_card_up(vdev)))
1628 return 0;
1630 /* is reset already scheduled */
1631 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1632 return 0;
1635 if (event == VXGE_LL_FULL_RESET) {
1636 netif_carrier_off(vdev->ndev);
1638 /* wait for all the vpath reset to complete */
1639 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1640 while (test_bit(vp_id, &vdev->vp_reset))
1641 msleep(50);
1644 netif_carrier_on(vdev->ndev);
1646 /* if execution mode is set to debug, don't reset the adapter */
1647 if (unlikely(vdev->exec_mode)) {
1648 vxge_debug_init(VXGE_ERR,
1649 "%s: execution mode is debug, returning..",
1650 vdev->ndev->name);
1651 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1652 netif_tx_stop_all_queues(vdev->ndev);
1653 return 0;
1657 if (event == VXGE_LL_FULL_RESET) {
1658 vxge_hw_device_wait_receive_idle(vdev->devh);
1659 vxge_hw_device_intr_disable(vdev->devh);
1661 switch (vdev->cric_err_event) {
1662 case VXGE_HW_EVENT_UNKNOWN:
1663 netif_tx_stop_all_queues(vdev->ndev);
1664 vxge_debug_init(VXGE_ERR,
1665 "fatal: %s: Disabling device due to"
1666 "unknown error",
1667 vdev->ndev->name);
1668 ret = -EPERM;
1669 goto out;
1670 case VXGE_HW_EVENT_RESET_START:
1671 break;
1672 case VXGE_HW_EVENT_RESET_COMPLETE:
1673 case VXGE_HW_EVENT_LINK_DOWN:
1674 case VXGE_HW_EVENT_LINK_UP:
1675 case VXGE_HW_EVENT_ALARM_CLEARED:
1676 case VXGE_HW_EVENT_ECCERR:
1677 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1678 ret = -EPERM;
1679 goto out;
1680 case VXGE_HW_EVENT_FIFO_ERR:
1681 case VXGE_HW_EVENT_VPATH_ERR:
1682 break;
1683 case VXGE_HW_EVENT_CRITICAL_ERR:
1684 netif_tx_stop_all_queues(vdev->ndev);
1685 vxge_debug_init(VXGE_ERR,
1686 "fatal: %s: Disabling device due to"
1687 "serious error",
1688 vdev->ndev->name);
1689 /* SOP or device reset required */
1690 /* This event is not currently used */
1691 ret = -EPERM;
1692 goto out;
1693 case VXGE_HW_EVENT_SERR:
1694 netif_tx_stop_all_queues(vdev->ndev);
1695 vxge_debug_init(VXGE_ERR,
1696 "fatal: %s: Disabling device due to"
1697 "serious error",
1698 vdev->ndev->name);
1699 ret = -EPERM;
1700 goto out;
1701 case VXGE_HW_EVENT_SRPCIM_SERR:
1702 case VXGE_HW_EVENT_MRPCIM_SERR:
1703 ret = -EPERM;
1704 goto out;
1705 case VXGE_HW_EVENT_SLOT_FREEZE:
1706 netif_tx_stop_all_queues(vdev->ndev);
1707 vxge_debug_init(VXGE_ERR,
1708 "fatal: %s: Disabling device due to"
1709 "slot freeze",
1710 vdev->ndev->name);
1711 ret = -EPERM;
1712 goto out;
1713 default:
1714 break;
1719 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
1720 netif_tx_stop_all_queues(vdev->ndev);
1722 if (event == VXGE_LL_FULL_RESET) {
1723 status = vxge_reset_all_vpaths(vdev);
1724 if (status != VXGE_HW_OK) {
1725 vxge_debug_init(VXGE_ERR,
1726 "fatal: %s: can not reset vpaths",
1727 vdev->ndev->name);
1728 ret = -EPERM;
1729 goto out;
1733 if (event == VXGE_LL_COMPL_RESET) {
1734 for (i = 0; i < vdev->no_of_vpath; i++)
1735 if (vdev->vpaths[i].handle) {
1736 if (vxge_hw_vpath_recover_from_reset(
1737 vdev->vpaths[i].handle)
1738 != VXGE_HW_OK) {
1739 vxge_debug_init(VXGE_ERR,
1740 "vxge_hw_vpath_recover_"
1741 "from_reset failed for vpath: "
1742 "%d", i);
1743 ret = -EPERM;
1744 goto out;
1746 } else {
1747 vxge_debug_init(VXGE_ERR,
1748 "vxge_hw_vpath_reset failed for "
1749 "vpath:%d", i);
1750 ret = -EPERM;
1751 goto out;
1755 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1756 /* Reprogram the DA table with populated mac addresses */
1757 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1758 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1759 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1762 /* enable vpath interrupts */
1763 for (i = 0; i < vdev->no_of_vpath; i++)
1764 vxge_vpath_intr_enable(vdev, i);
1766 vxge_hw_device_intr_enable(vdev->devh);
1768 smp_wmb();
1770 /* Indicate card up */
1771 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1773 /* Get the traffic to flow through the vpaths */
1774 for (i = 0; i < vdev->no_of_vpath; i++) {
1775 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1776 smp_wmb();
1777 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1780 netif_tx_wake_all_queues(vdev->ndev);
1783 /* configure CI */
1784 vxge_config_ci_for_tti_rti(vdev);
1786 out:
1787 vxge_debug_entryexit(VXGE_TRACE,
1788 "%s:%d Exiting...", __func__, __LINE__);
1790 /* Indicate reset done */
1791 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1792 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1793 return ret;
1797 * vxge_reset
1798 * @vdev: pointer to ll device
1800 * driver may reset the chip on events of serr, eccerr, etc
1802 static void vxge_reset(struct work_struct *work)
1804 struct vxgedev *vdev = container_of(work, struct vxgedev, reset_task);
1806 if (!netif_running(vdev->ndev))
1807 return;
1809 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
1813 * vxge_poll - Receive handler when Receive Polling is used.
1814 * @dev: pointer to the device structure.
1815 * @budget: Number of packets budgeted to be processed in this iteration.
1817 * This function comes into picture only if Receive side is being handled
1818 * through polling (called NAPI in linux). It mostly does what the normal
1819 * Rx interrupt handler does in terms of descriptor and packet processing
1820 * but not in an interrupt context. Also it will process a specified number
1821 * of packets at most in one iteration. This value is passed down by the
1822 * kernel as the function argument 'budget'.
1824 static int vxge_poll_msix(struct napi_struct *napi, int budget)
1826 struct vxge_ring *ring = container_of(napi, struct vxge_ring, napi);
1827 int pkts_processed;
1828 int budget_org = budget;
1830 ring->budget = budget;
1831 ring->pkts_processed = 0;
1832 vxge_hw_vpath_poll_rx(ring->handle);
1833 pkts_processed = ring->pkts_processed;
1835 if (ring->pkts_processed < budget_org) {
1836 napi_complete(napi);
1838 /* Re enable the Rx interrupts for the vpath */
1839 vxge_hw_channel_msix_unmask(
1840 (struct __vxge_hw_channel *)ring->handle,
1841 ring->rx_vector_no);
1842 mmiowb();
1845 /* We are copying and returning the local variable, in case if after
1846 * clearing the msix interrupt above, if the interrupt fires right
1847 * away which can preempt this NAPI thread */
1848 return pkts_processed;
1851 static int vxge_poll_inta(struct napi_struct *napi, int budget)
1853 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1854 int pkts_processed = 0;
1855 int i;
1856 int budget_org = budget;
1857 struct vxge_ring *ring;
1859 struct __vxge_hw_device *hldev = pci_get_drvdata(vdev->pdev);
1861 for (i = 0; i < vdev->no_of_vpath; i++) {
1862 ring = &vdev->vpaths[i].ring;
1863 ring->budget = budget;
1864 ring->pkts_processed = 0;
1865 vxge_hw_vpath_poll_rx(ring->handle);
1866 pkts_processed += ring->pkts_processed;
1867 budget -= ring->pkts_processed;
1868 if (budget <= 0)
1869 break;
1872 VXGE_COMPLETE_ALL_TX(vdev);
1874 if (pkts_processed < budget_org) {
1875 napi_complete(napi);
1876 /* Re enable the Rx interrupts for the ring */
1877 vxge_hw_device_unmask_all(hldev);
1878 vxge_hw_device_flush_io(hldev);
1881 return pkts_processed;
1884 #ifdef CONFIG_NET_POLL_CONTROLLER
1886 * vxge_netpoll - netpoll event handler entry point
1887 * @dev : pointer to the device structure.
1888 * Description:
1889 * This function will be called by upper layer to check for events on the
1890 * interface in situations where interrupts are disabled. It is used for
1891 * specific in-kernel networking tasks, such as remote consoles and kernel
1892 * debugging over the network (example netdump in RedHat).
1894 static void vxge_netpoll(struct net_device *dev)
1896 struct __vxge_hw_device *hldev;
1897 struct vxgedev *vdev;
1899 vdev = netdev_priv(dev);
1900 hldev = pci_get_drvdata(vdev->pdev);
1902 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1904 if (pci_channel_offline(vdev->pdev))
1905 return;
1907 disable_irq(dev->irq);
1908 vxge_hw_device_clear_tx_rx(hldev);
1910 vxge_hw_device_clear_tx_rx(hldev);
1911 VXGE_COMPLETE_ALL_RX(vdev);
1912 VXGE_COMPLETE_ALL_TX(vdev);
1914 enable_irq(dev->irq);
1916 vxge_debug_entryexit(VXGE_TRACE,
1917 "%s:%d Exiting...", __func__, __LINE__);
1919 #endif
1921 /* RTH configuration */
1922 static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1924 enum vxge_hw_status status = VXGE_HW_OK;
1925 struct vxge_hw_rth_hash_types hash_types;
1926 u8 itable[256] = {0}; /* indirection table */
1927 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1928 int index;
1931 * Filling
1932 * - itable with bucket numbers
1933 * - mtable with bucket-to-vpath mapping
1935 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1936 itable[index] = index;
1937 mtable[index] = index % vdev->no_of_vpath;
1940 /* set indirection table, bucket-to-vpath mapping */
1941 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1942 vdev->no_of_vpath,
1943 mtable, itable,
1944 vdev->config.rth_bkt_sz);
1945 if (status != VXGE_HW_OK) {
1946 vxge_debug_init(VXGE_ERR,
1947 "RTH indirection table configuration failed "
1948 "for vpath:%d", vdev->vpaths[0].device_id);
1949 return status;
1952 /* Fill RTH hash types */
1953 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1954 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1955 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1956 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1957 hash_types.hash_type_tcpipv6ex_en =
1958 vdev->config.rth_hash_type_tcpipv6ex;
1959 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1962 * Because the itable_set() method uses the active_table field
1963 * for the target virtual path the RTH config should be updated
1964 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1965 * when steering frames.
1967 for (index = 0; index < vdev->no_of_vpath; index++) {
1968 status = vxge_hw_vpath_rts_rth_set(
1969 vdev->vpaths[index].handle,
1970 vdev->config.rth_algorithm,
1971 &hash_types,
1972 vdev->config.rth_bkt_sz);
1973 if (status != VXGE_HW_OK) {
1974 vxge_debug_init(VXGE_ERR,
1975 "RTH configuration failed for vpath:%d",
1976 vdev->vpaths[index].device_id);
1977 return status;
1981 return status;
1984 /* reset vpaths */
1985 enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
1987 enum vxge_hw_status status = VXGE_HW_OK;
1988 struct vxge_vpath *vpath;
1989 int i;
1991 for (i = 0; i < vdev->no_of_vpath; i++) {
1992 vpath = &vdev->vpaths[i];
1993 if (vpath->handle) {
1994 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
1995 if (is_vxge_card_up(vdev) &&
1996 vxge_hw_vpath_recover_from_reset(
1997 vpath->handle) != VXGE_HW_OK) {
1998 vxge_debug_init(VXGE_ERR,
1999 "vxge_hw_vpath_recover_"
2000 "from_reset failed for vpath: "
2001 "%d", i);
2002 return status;
2004 } else {
2005 vxge_debug_init(VXGE_ERR,
2006 "vxge_hw_vpath_reset failed for "
2007 "vpath:%d", i);
2008 return status;
2013 return status;
2016 /* close vpaths */
2017 static void vxge_close_vpaths(struct vxgedev *vdev, int index)
2019 struct vxge_vpath *vpath;
2020 int i;
2022 for (i = index; i < vdev->no_of_vpath; i++) {
2023 vpath = &vdev->vpaths[i];
2025 if (vpath->handle && vpath->is_open) {
2026 vxge_hw_vpath_close(vpath->handle);
2027 vdev->stats.vpaths_open--;
2029 vpath->is_open = 0;
2030 vpath->handle = NULL;
2034 /* open vpaths */
2035 static int vxge_open_vpaths(struct vxgedev *vdev)
2037 struct vxge_hw_vpath_attr attr;
2038 enum vxge_hw_status status;
2039 struct vxge_vpath *vpath;
2040 u32 vp_id = 0;
2041 int i;
2043 for (i = 0; i < vdev->no_of_vpath; i++) {
2044 vpath = &vdev->vpaths[i];
2045 vxge_assert(vpath->is_configured);
2047 if (!vdev->titan1) {
2048 struct vxge_hw_vp_config *vcfg;
2049 vcfg = &vdev->devh->config.vp_config[vpath->device_id];
2051 vcfg->rti.urange_a = RTI_T1A_RX_URANGE_A;
2052 vcfg->rti.urange_b = RTI_T1A_RX_URANGE_B;
2053 vcfg->rti.urange_c = RTI_T1A_RX_URANGE_C;
2054 vcfg->tti.uec_a = TTI_T1A_TX_UFC_A;
2055 vcfg->tti.uec_b = TTI_T1A_TX_UFC_B;
2056 vcfg->tti.uec_c = TTI_T1A_TX_UFC_C(vdev->mtu);
2057 vcfg->tti.uec_d = TTI_T1A_TX_UFC_D(vdev->mtu);
2058 vcfg->tti.ltimer_val = VXGE_T1A_TTI_LTIMER_VAL;
2059 vcfg->tti.rtimer_val = VXGE_T1A_TTI_RTIMER_VAL;
2062 attr.vp_id = vpath->device_id;
2063 attr.fifo_attr.callback = vxge_xmit_compl;
2064 attr.fifo_attr.txdl_term = vxge_tx_term;
2065 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
2066 attr.fifo_attr.userdata = &vpath->fifo;
2068 attr.ring_attr.callback = vxge_rx_1b_compl;
2069 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2070 attr.ring_attr.rxd_term = vxge_rx_term;
2071 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
2072 attr.ring_attr.userdata = &vpath->ring;
2074 vpath->ring.ndev = vdev->ndev;
2075 vpath->ring.pdev = vdev->pdev;
2077 status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
2078 if (status == VXGE_HW_OK) {
2079 vpath->fifo.handle =
2080 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
2081 vpath->ring.handle =
2082 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
2083 vpath->fifo.tx_steering_type =
2084 vdev->config.tx_steering_type;
2085 vpath->fifo.ndev = vdev->ndev;
2086 vpath->fifo.pdev = vdev->pdev;
2087 if (vdev->config.tx_steering_type)
2088 vpath->fifo.txq =
2089 netdev_get_tx_queue(vdev->ndev, i);
2090 else
2091 vpath->fifo.txq =
2092 netdev_get_tx_queue(vdev->ndev, 0);
2093 vpath->fifo.indicate_max_pkts =
2094 vdev->config.fifo_indicate_max_pkts;
2095 vpath->fifo.tx_vector_no = 0;
2096 vpath->ring.rx_vector_no = 0;
2097 vpath->ring.rx_csum = vdev->rx_csum;
2098 vpath->ring.rx_hwts = vdev->rx_hwts;
2099 vpath->is_open = 1;
2100 vdev->vp_handles[i] = vpath->handle;
2101 vpath->ring.gro_enable = vdev->config.gro_enable;
2102 vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
2103 vdev->stats.vpaths_open++;
2104 } else {
2105 vdev->stats.vpath_open_fail++;
2106 vxge_debug_init(VXGE_ERR, "%s: vpath: %d failed to "
2107 "open with status: %d",
2108 vdev->ndev->name, vpath->device_id,
2109 status);
2110 vxge_close_vpaths(vdev, 0);
2111 return -EPERM;
2114 vp_id = vpath->handle->vpath->vp_id;
2115 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2118 return VXGE_HW_OK;
2122 * adaptive_coalesce_tx_interrupts - Changes the interrupt coalescing
2123 * if the interrupts are not within a range
2124 * @fifo: pointer to transmit fifo structure
2125 * Description: The function changes boundary timer and restriction timer
2126 * value depends on the traffic
2127 * Return Value: None
2129 static void adaptive_coalesce_tx_interrupts(struct vxge_fifo *fifo)
2131 fifo->interrupt_count++;
2132 if (jiffies > fifo->jiffies + HZ / 100) {
2133 struct __vxge_hw_fifo *hw_fifo = fifo->handle;
2135 fifo->jiffies = jiffies;
2136 if (fifo->interrupt_count > VXGE_T1A_MAX_TX_INTERRUPT_COUNT &&
2137 hw_fifo->rtimer != VXGE_TTI_RTIMER_ADAPT_VAL) {
2138 hw_fifo->rtimer = VXGE_TTI_RTIMER_ADAPT_VAL;
2139 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2140 } else if (hw_fifo->rtimer != 0) {
2141 hw_fifo->rtimer = 0;
2142 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2144 fifo->interrupt_count = 0;
2149 * adaptive_coalesce_rx_interrupts - Changes the interrupt coalescing
2150 * if the interrupts are not within a range
2151 * @ring: pointer to receive ring structure
2152 * Description: The function increases of decreases the packet counts within
2153 * the ranges of traffic utilization, if the interrupts due to this ring are
2154 * not within a fixed range.
2155 * Return Value: Nothing
2157 static void adaptive_coalesce_rx_interrupts(struct vxge_ring *ring)
2159 ring->interrupt_count++;
2160 if (jiffies > ring->jiffies + HZ / 100) {
2161 struct __vxge_hw_ring *hw_ring = ring->handle;
2163 ring->jiffies = jiffies;
2164 if (ring->interrupt_count > VXGE_T1A_MAX_INTERRUPT_COUNT &&
2165 hw_ring->rtimer != VXGE_RTI_RTIMER_ADAPT_VAL) {
2166 hw_ring->rtimer = VXGE_RTI_RTIMER_ADAPT_VAL;
2167 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2168 } else if (hw_ring->rtimer != 0) {
2169 hw_ring->rtimer = 0;
2170 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2172 ring->interrupt_count = 0;
2177 * vxge_isr_napi
2178 * @irq: the irq of the device.
2179 * @dev_id: a void pointer to the hldev structure of the Titan device
2180 * @ptregs: pointer to the registers pushed on the stack.
2182 * This function is the ISR handler of the device when napi is enabled. It
2183 * identifies the reason for the interrupt and calls the relevant service
2184 * routines.
2186 static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2188 struct net_device *dev;
2189 struct __vxge_hw_device *hldev;
2190 u64 reason;
2191 enum vxge_hw_status status;
2192 struct vxgedev *vdev = (struct vxgedev *)dev_id;
2194 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2196 dev = vdev->ndev;
2197 hldev = pci_get_drvdata(vdev->pdev);
2199 if (pci_channel_offline(vdev->pdev))
2200 return IRQ_NONE;
2202 if (unlikely(!is_vxge_card_up(vdev)))
2203 return IRQ_HANDLED;
2205 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, &reason);
2206 if (status == VXGE_HW_OK) {
2207 vxge_hw_device_mask_all(hldev);
2209 if (reason &
2210 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2211 vdev->vpaths_deployed >>
2212 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2214 vxge_hw_device_clear_tx_rx(hldev);
2215 napi_schedule(&vdev->napi);
2216 vxge_debug_intr(VXGE_TRACE,
2217 "%s:%d Exiting...", __func__, __LINE__);
2218 return IRQ_HANDLED;
2219 } else
2220 vxge_hw_device_unmask_all(hldev);
2221 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2222 (status == VXGE_HW_ERR_CRITICAL) ||
2223 (status == VXGE_HW_ERR_FIFO))) {
2224 vxge_hw_device_mask_all(hldev);
2225 vxge_hw_device_flush_io(hldev);
2226 return IRQ_HANDLED;
2227 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2228 return IRQ_HANDLED;
2230 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2231 return IRQ_NONE;
2234 #ifdef CONFIG_PCI_MSI
2236 static irqreturn_t vxge_tx_msix_handle(int irq, void *dev_id)
2238 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2240 adaptive_coalesce_tx_interrupts(fifo);
2242 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)fifo->handle,
2243 fifo->tx_vector_no);
2245 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)fifo->handle,
2246 fifo->tx_vector_no);
2248 VXGE_COMPLETE_VPATH_TX(fifo);
2250 vxge_hw_channel_msix_unmask((struct __vxge_hw_channel *)fifo->handle,
2251 fifo->tx_vector_no);
2253 mmiowb();
2255 return IRQ_HANDLED;
2258 static irqreturn_t vxge_rx_msix_napi_handle(int irq, void *dev_id)
2260 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2262 adaptive_coalesce_rx_interrupts(ring);
2264 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
2265 ring->rx_vector_no);
2267 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)ring->handle,
2268 ring->rx_vector_no);
2270 napi_schedule(&ring->napi);
2271 return IRQ_HANDLED;
2274 static irqreturn_t
2275 vxge_alarm_msix_handle(int irq, void *dev_id)
2277 int i;
2278 enum vxge_hw_status status;
2279 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2280 struct vxgedev *vdev = vpath->vdev;
2281 int msix_id = (vpath->handle->vpath->vp_id *
2282 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
2284 for (i = 0; i < vdev->no_of_vpath; i++) {
2285 /* Reduce the chance of loosing alarm interrupts by masking
2286 * the vector. A pending bit will be set if an alarm is
2287 * generated and on unmask the interrupt will be fired.
2289 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
2290 vxge_hw_vpath_msix_clear(vdev->vpaths[i].handle, msix_id);
2291 mmiowb();
2293 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2294 vdev->exec_mode);
2295 if (status == VXGE_HW_OK) {
2296 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
2297 msix_id);
2298 mmiowb();
2299 continue;
2301 vxge_debug_intr(VXGE_ERR,
2302 "%s: vxge_hw_vpath_alarm_process failed %x ",
2303 VXGE_DRIVER_NAME, status);
2305 return IRQ_HANDLED;
2308 static int vxge_alloc_msix(struct vxgedev *vdev)
2310 int j, i, ret = 0;
2311 int msix_intr_vect = 0, temp;
2312 vdev->intr_cnt = 0;
2314 start:
2315 /* Tx/Rx MSIX Vectors count */
2316 vdev->intr_cnt = vdev->no_of_vpath * 2;
2318 /* Alarm MSIX Vectors count */
2319 vdev->intr_cnt++;
2321 vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
2322 GFP_KERNEL);
2323 if (!vdev->entries) {
2324 vxge_debug_init(VXGE_ERR,
2325 "%s: memory allocation failed",
2326 VXGE_DRIVER_NAME);
2327 ret = -ENOMEM;
2328 goto alloc_entries_failed;
2331 vdev->vxge_entries = kcalloc(vdev->intr_cnt,
2332 sizeof(struct vxge_msix_entry),
2333 GFP_KERNEL);
2334 if (!vdev->vxge_entries) {
2335 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2336 VXGE_DRIVER_NAME);
2337 ret = -ENOMEM;
2338 goto alloc_vxge_entries_failed;
2341 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
2343 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2345 /* Initialize the fifo vector */
2346 vdev->entries[j].entry = msix_intr_vect;
2347 vdev->vxge_entries[j].entry = msix_intr_vect;
2348 vdev->vxge_entries[j].in_use = 0;
2349 j++;
2351 /* Initialize the ring vector */
2352 vdev->entries[j].entry = msix_intr_vect + 1;
2353 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2354 vdev->vxge_entries[j].in_use = 0;
2355 j++;
2358 /* Initialize the alarm vector */
2359 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2360 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
2361 vdev->vxge_entries[j].in_use = 0;
2363 ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt);
2364 if (ret > 0) {
2365 vxge_debug_init(VXGE_ERR,
2366 "%s: MSI-X enable failed for %d vectors, ret: %d",
2367 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
2368 if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) {
2369 ret = -ENODEV;
2370 goto enable_msix_failed;
2373 kfree(vdev->entries);
2374 kfree(vdev->vxge_entries);
2375 vdev->entries = NULL;
2376 vdev->vxge_entries = NULL;
2377 /* Try with less no of vector by reducing no of vpaths count */
2378 temp = (ret - 1)/2;
2379 vxge_close_vpaths(vdev, temp);
2380 vdev->no_of_vpath = temp;
2381 goto start;
2382 } else if (ret < 0) {
2383 ret = -ENODEV;
2384 goto enable_msix_failed;
2386 return 0;
2388 enable_msix_failed:
2389 kfree(vdev->vxge_entries);
2390 alloc_vxge_entries_failed:
2391 kfree(vdev->entries);
2392 alloc_entries_failed:
2393 return ret;
2396 static int vxge_enable_msix(struct vxgedev *vdev)
2399 int i, ret = 0;
2400 /* 0 - Tx, 1 - Rx */
2401 int tim_msix_id[4] = {0, 1, 0, 0};
2403 vdev->intr_cnt = 0;
2405 /* allocate msix vectors */
2406 ret = vxge_alloc_msix(vdev);
2407 if (!ret) {
2408 for (i = 0; i < vdev->no_of_vpath; i++) {
2409 struct vxge_vpath *vpath = &vdev->vpaths[i];
2411 /* If fifo or ring are not enabled, the MSIX vector for
2412 * it should be set to 0.
2414 vpath->ring.rx_vector_no = (vpath->device_id *
2415 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
2417 vpath->fifo.tx_vector_no = (vpath->device_id *
2418 VXGE_HW_VPATH_MSIX_ACTIVE);
2420 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
2421 VXGE_ALARM_MSIX_ID);
2425 return ret;
2428 static void vxge_rem_msix_isr(struct vxgedev *vdev)
2430 int intr_cnt;
2432 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
2433 intr_cnt++) {
2434 if (vdev->vxge_entries[intr_cnt].in_use) {
2435 synchronize_irq(vdev->entries[intr_cnt].vector);
2436 free_irq(vdev->entries[intr_cnt].vector,
2437 vdev->vxge_entries[intr_cnt].arg);
2438 vdev->vxge_entries[intr_cnt].in_use = 0;
2442 kfree(vdev->entries);
2443 kfree(vdev->vxge_entries);
2444 vdev->entries = NULL;
2445 vdev->vxge_entries = NULL;
2447 if (vdev->config.intr_type == MSI_X)
2448 pci_disable_msix(vdev->pdev);
2450 #endif
2452 static void vxge_rem_isr(struct vxgedev *vdev)
2454 struct __vxge_hw_device *hldev;
2455 hldev = pci_get_drvdata(vdev->pdev);
2457 #ifdef CONFIG_PCI_MSI
2458 if (vdev->config.intr_type == MSI_X) {
2459 vxge_rem_msix_isr(vdev);
2460 } else
2461 #endif
2462 if (vdev->config.intr_type == INTA) {
2463 synchronize_irq(vdev->pdev->irq);
2464 free_irq(vdev->pdev->irq, vdev);
2468 static int vxge_add_isr(struct vxgedev *vdev)
2470 int ret = 0;
2471 #ifdef CONFIG_PCI_MSI
2472 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
2473 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2475 if (vdev->config.intr_type == MSI_X)
2476 ret = vxge_enable_msix(vdev);
2478 if (ret) {
2479 vxge_debug_init(VXGE_ERR,
2480 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
2481 vxge_debug_init(VXGE_ERR,
2482 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2483 vdev->config.intr_type = INTA;
2486 if (vdev->config.intr_type == MSI_X) {
2487 for (intr_idx = 0;
2488 intr_idx < (vdev->no_of_vpath *
2489 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2491 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2492 irq_req = 0;
2494 switch (msix_idx) {
2495 case 0:
2496 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2497 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2498 vdev->ndev->name,
2499 vdev->entries[intr_cnt].entry,
2500 pci_fun, vp_idx);
2501 ret = request_irq(
2502 vdev->entries[intr_cnt].vector,
2503 vxge_tx_msix_handle, 0,
2504 vdev->desc[intr_cnt],
2505 &vdev->vpaths[vp_idx].fifo);
2506 vdev->vxge_entries[intr_cnt].arg =
2507 &vdev->vpaths[vp_idx].fifo;
2508 irq_req = 1;
2509 break;
2510 case 1:
2511 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2512 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2513 vdev->ndev->name,
2514 vdev->entries[intr_cnt].entry,
2515 pci_fun, vp_idx);
2516 ret = request_irq(
2517 vdev->entries[intr_cnt].vector,
2518 vxge_rx_msix_napi_handle,
2520 vdev->desc[intr_cnt],
2521 &vdev->vpaths[vp_idx].ring);
2522 vdev->vxge_entries[intr_cnt].arg =
2523 &vdev->vpaths[vp_idx].ring;
2524 irq_req = 1;
2525 break;
2528 if (ret) {
2529 vxge_debug_init(VXGE_ERR,
2530 "%s: MSIX - %d Registration failed",
2531 vdev->ndev->name, intr_cnt);
2532 vxge_rem_msix_isr(vdev);
2533 vdev->config.intr_type = INTA;
2534 vxge_debug_init(VXGE_ERR,
2535 "%s: Defaulting to INTA"
2536 , vdev->ndev->name);
2537 goto INTA_MODE;
2540 if (irq_req) {
2541 /* We requested for this msix interrupt */
2542 vdev->vxge_entries[intr_cnt].in_use = 1;
2543 msix_idx += vdev->vpaths[vp_idx].device_id *
2544 VXGE_HW_VPATH_MSIX_ACTIVE;
2545 vxge_hw_vpath_msix_unmask(
2546 vdev->vpaths[vp_idx].handle,
2547 msix_idx);
2548 intr_cnt++;
2551 /* Point to next vpath handler */
2552 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2553 (vp_idx < (vdev->no_of_vpath - 1)))
2554 vp_idx++;
2557 intr_cnt = vdev->no_of_vpath * 2;
2558 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2559 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2560 vdev->ndev->name,
2561 vdev->entries[intr_cnt].entry,
2562 pci_fun);
2563 /* For Alarm interrupts */
2564 ret = request_irq(vdev->entries[intr_cnt].vector,
2565 vxge_alarm_msix_handle, 0,
2566 vdev->desc[intr_cnt],
2567 &vdev->vpaths[0]);
2568 if (ret) {
2569 vxge_debug_init(VXGE_ERR,
2570 "%s: MSIX - %d Registration failed",
2571 vdev->ndev->name, intr_cnt);
2572 vxge_rem_msix_isr(vdev);
2573 vdev->config.intr_type = INTA;
2574 vxge_debug_init(VXGE_ERR,
2575 "%s: Defaulting to INTA",
2576 vdev->ndev->name);
2577 goto INTA_MODE;
2580 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2581 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
2582 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
2583 msix_idx);
2584 vdev->vxge_entries[intr_cnt].in_use = 1;
2585 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
2587 INTA_MODE:
2588 #endif
2590 if (vdev->config.intr_type == INTA) {
2591 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2592 "%s:vxge:INTA", vdev->ndev->name);
2593 vxge_hw_device_set_intr_type(vdev->devh,
2594 VXGE_HW_INTR_MODE_IRQLINE);
2596 vxge_hw_vpath_tti_ci_set(vdev->vpaths[0].fifo.handle);
2598 ret = request_irq((int) vdev->pdev->irq,
2599 vxge_isr_napi,
2600 IRQF_SHARED, vdev->desc[0], vdev);
2601 if (ret) {
2602 vxge_debug_init(VXGE_ERR,
2603 "%s %s-%d: ISR registration failed",
2604 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2605 return -ENODEV;
2607 vxge_debug_init(VXGE_TRACE,
2608 "new %s-%d line allocated",
2609 "IRQ", vdev->pdev->irq);
2612 return VXGE_HW_OK;
2615 static void vxge_poll_vp_reset(unsigned long data)
2617 struct vxgedev *vdev = (struct vxgedev *)data;
2618 int i, j = 0;
2620 for (i = 0; i < vdev->no_of_vpath; i++) {
2621 if (test_bit(i, &vdev->vp_reset)) {
2622 vxge_reset_vpath(vdev, i);
2623 j++;
2626 if (j && (vdev->config.intr_type != MSI_X)) {
2627 vxge_hw_device_unmask_all(vdev->devh);
2628 vxge_hw_device_flush_io(vdev->devh);
2631 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2634 static void vxge_poll_vp_lockup(unsigned long data)
2636 struct vxgedev *vdev = (struct vxgedev *)data;
2637 enum vxge_hw_status status = VXGE_HW_OK;
2638 struct vxge_vpath *vpath;
2639 struct vxge_ring *ring;
2640 int i;
2642 for (i = 0; i < vdev->no_of_vpath; i++) {
2643 ring = &vdev->vpaths[i].ring;
2644 /* Did this vpath received any packets */
2645 if (ring->stats.prev_rx_frms == ring->stats.rx_frms) {
2646 status = vxge_hw_vpath_check_leak(ring->handle);
2648 /* Did it received any packets last time */
2649 if ((VXGE_HW_FAIL == status) &&
2650 (VXGE_HW_FAIL == ring->last_status)) {
2652 /* schedule vpath reset */
2653 if (!test_and_set_bit(i, &vdev->vp_reset)) {
2654 vpath = &vdev->vpaths[i];
2656 /* disable interrupts for this vpath */
2657 vxge_vpath_intr_disable(vdev, i);
2659 /* stop the queue for this vpath */
2660 netif_tx_stop_queue(vpath->fifo.txq);
2661 continue;
2665 ring->stats.prev_rx_frms = ring->stats.rx_frms;
2666 ring->last_status = status;
2669 /* Check every 1 milli second */
2670 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2674 * vxge_open
2675 * @dev: pointer to the device structure.
2677 * This function is the open entry point of the driver. It mainly calls a
2678 * function to allocate Rx buffers and inserts them into the buffer
2679 * descriptors and then enables the Rx part of the NIC.
2680 * Return value: '0' on success and an appropriate (-)ve integer as
2681 * defined in errno.h file on failure.
2683 static int vxge_open(struct net_device *dev)
2685 enum vxge_hw_status status;
2686 struct vxgedev *vdev;
2687 struct __vxge_hw_device *hldev;
2688 struct vxge_vpath *vpath;
2689 int ret = 0;
2690 int i;
2691 u64 val64, function_mode;
2693 vxge_debug_entryexit(VXGE_TRACE,
2694 "%s: %s:%d", dev->name, __func__, __LINE__);
2696 vdev = netdev_priv(dev);
2697 hldev = pci_get_drvdata(vdev->pdev);
2698 function_mode = vdev->config.device_hw_info.function_mode;
2700 /* make sure you have link off by default every time Nic is
2701 * initialized */
2702 netif_carrier_off(dev);
2704 /* Open VPATHs */
2705 status = vxge_open_vpaths(vdev);
2706 if (status != VXGE_HW_OK) {
2707 vxge_debug_init(VXGE_ERR,
2708 "%s: fatal: Vpath open failed", vdev->ndev->name);
2709 ret = -EPERM;
2710 goto out0;
2713 vdev->mtu = dev->mtu;
2715 status = vxge_add_isr(vdev);
2716 if (status != VXGE_HW_OK) {
2717 vxge_debug_init(VXGE_ERR,
2718 "%s: fatal: ISR add failed", dev->name);
2719 ret = -EPERM;
2720 goto out1;
2723 if (vdev->config.intr_type != MSI_X) {
2724 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2725 vdev->config.napi_weight);
2726 napi_enable(&vdev->napi);
2727 for (i = 0; i < vdev->no_of_vpath; i++) {
2728 vpath = &vdev->vpaths[i];
2729 vpath->ring.napi_p = &vdev->napi;
2731 } else {
2732 for (i = 0; i < vdev->no_of_vpath; i++) {
2733 vpath = &vdev->vpaths[i];
2734 netif_napi_add(dev, &vpath->ring.napi,
2735 vxge_poll_msix, vdev->config.napi_weight);
2736 napi_enable(&vpath->ring.napi);
2737 vpath->ring.napi_p = &vpath->ring.napi;
2741 /* configure RTH */
2742 if (vdev->config.rth_steering) {
2743 status = vxge_rth_configure(vdev);
2744 if (status != VXGE_HW_OK) {
2745 vxge_debug_init(VXGE_ERR,
2746 "%s: fatal: RTH configuration failed",
2747 dev->name);
2748 ret = -EPERM;
2749 goto out2;
2752 printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name,
2753 hldev->config.rth_en ? "enabled" : "disabled");
2755 for (i = 0; i < vdev->no_of_vpath; i++) {
2756 vpath = &vdev->vpaths[i];
2758 /* set initial mtu before enabling the device */
2759 status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
2760 if (status != VXGE_HW_OK) {
2761 vxge_debug_init(VXGE_ERR,
2762 "%s: fatal: can not set new MTU", dev->name);
2763 ret = -EPERM;
2764 goto out2;
2768 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2769 vxge_debug_init(vdev->level_trace,
2770 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2771 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2773 /* Restore the DA, VID table and also multicast and promiscuous mode
2774 * states
2776 if (vdev->all_multi_flg) {
2777 for (i = 0; i < vdev->no_of_vpath; i++) {
2778 vpath = &vdev->vpaths[i];
2779 vxge_restore_vpath_mac_addr(vpath);
2780 vxge_restore_vpath_vid_table(vpath);
2782 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2783 if (status != VXGE_HW_OK)
2784 vxge_debug_init(VXGE_ERR,
2785 "%s:%d Enabling multicast failed",
2786 __func__, __LINE__);
2790 /* Enable vpath to sniff all unicast/multicast traffic that not
2791 * addressed to them. We allow promiscous mode for PF only
2794 val64 = 0;
2795 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2796 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2798 vxge_hw_mgmt_reg_write(vdev->devh,
2799 vxge_hw_mgmt_reg_type_mrpcim,
2801 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2802 rxmac_authorize_all_addr),
2803 val64);
2805 vxge_hw_mgmt_reg_write(vdev->devh,
2806 vxge_hw_mgmt_reg_type_mrpcim,
2808 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2809 rxmac_authorize_all_vid),
2810 val64);
2812 vxge_set_multicast(dev);
2814 /* Enabling Bcast and mcast for all vpath */
2815 for (i = 0; i < vdev->no_of_vpath; i++) {
2816 vpath = &vdev->vpaths[i];
2817 status = vxge_hw_vpath_bcast_enable(vpath->handle);
2818 if (status != VXGE_HW_OK)
2819 vxge_debug_init(VXGE_ERR,
2820 "%s : Can not enable bcast for vpath "
2821 "id %d", dev->name, i);
2822 if (vdev->config.addr_learn_en) {
2823 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2824 if (status != VXGE_HW_OK)
2825 vxge_debug_init(VXGE_ERR,
2826 "%s : Can not enable mcast for vpath "
2827 "id %d", dev->name, i);
2831 vxge_hw_device_setpause_data(vdev->devh, 0,
2832 vdev->config.tx_pause_enable,
2833 vdev->config.rx_pause_enable);
2835 if (vdev->vp_reset_timer.function == NULL)
2836 vxge_os_timer(vdev->vp_reset_timer,
2837 vxge_poll_vp_reset, vdev, (HZ/2));
2839 /* There is no need to check for RxD leak and RxD lookup on Titan1A */
2840 if (vdev->titan1 && vdev->vp_lockup_timer.function == NULL)
2841 vxge_os_timer(vdev->vp_lockup_timer, vxge_poll_vp_lockup, vdev,
2842 HZ / 2);
2844 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2846 smp_wmb();
2848 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2849 netif_carrier_on(vdev->ndev);
2850 netdev_notice(vdev->ndev, "Link Up\n");
2851 vdev->stats.link_up++;
2854 vxge_hw_device_intr_enable(vdev->devh);
2856 smp_wmb();
2858 for (i = 0; i < vdev->no_of_vpath; i++) {
2859 vpath = &vdev->vpaths[i];
2861 vxge_hw_vpath_enable(vpath->handle);
2862 smp_wmb();
2863 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
2866 netif_tx_start_all_queues(vdev->ndev);
2868 /* configure CI */
2869 vxge_config_ci_for_tti_rti(vdev);
2871 goto out0;
2873 out2:
2874 vxge_rem_isr(vdev);
2876 /* Disable napi */
2877 if (vdev->config.intr_type != MSI_X)
2878 napi_disable(&vdev->napi);
2879 else {
2880 for (i = 0; i < vdev->no_of_vpath; i++)
2881 napi_disable(&vdev->vpaths[i].ring.napi);
2884 out1:
2885 vxge_close_vpaths(vdev, 0);
2886 out0:
2887 vxge_debug_entryexit(VXGE_TRACE,
2888 "%s: %s:%d Exiting...",
2889 dev->name, __func__, __LINE__);
2890 return ret;
2893 /* Loop throught the mac address list and delete all the entries */
2894 static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
2897 struct list_head *entry, *next;
2898 if (list_empty(&vpath->mac_addr_list))
2899 return;
2901 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2902 list_del(entry);
2903 kfree((struct vxge_mac_addrs *)entry);
2907 static void vxge_napi_del_all(struct vxgedev *vdev)
2909 int i;
2910 if (vdev->config.intr_type != MSI_X)
2911 netif_napi_del(&vdev->napi);
2912 else {
2913 for (i = 0; i < vdev->no_of_vpath; i++)
2914 netif_napi_del(&vdev->vpaths[i].ring.napi);
2918 static int do_vxge_close(struct net_device *dev, int do_io)
2920 enum vxge_hw_status status;
2921 struct vxgedev *vdev;
2922 struct __vxge_hw_device *hldev;
2923 int i;
2924 u64 val64, vpath_vector;
2925 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2926 dev->name, __func__, __LINE__);
2928 vdev = netdev_priv(dev);
2929 hldev = pci_get_drvdata(vdev->pdev);
2931 if (unlikely(!is_vxge_card_up(vdev)))
2932 return 0;
2934 /* If vxge_handle_crit_err task is executing,
2935 * wait till it completes. */
2936 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2937 msleep(50);
2939 if (do_io) {
2940 /* Put the vpath back in normal mode */
2941 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2942 status = vxge_hw_mgmt_reg_read(vdev->devh,
2943 vxge_hw_mgmt_reg_type_mrpcim,
2945 (ulong)offsetof(
2946 struct vxge_hw_mrpcim_reg,
2947 rts_mgr_cbasin_cfg),
2948 &val64);
2949 if (status == VXGE_HW_OK) {
2950 val64 &= ~vpath_vector;
2951 status = vxge_hw_mgmt_reg_write(vdev->devh,
2952 vxge_hw_mgmt_reg_type_mrpcim,
2954 (ulong)offsetof(
2955 struct vxge_hw_mrpcim_reg,
2956 rts_mgr_cbasin_cfg),
2957 val64);
2960 /* Remove the function 0 from promiscous mode */
2961 vxge_hw_mgmt_reg_write(vdev->devh,
2962 vxge_hw_mgmt_reg_type_mrpcim,
2964 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2965 rxmac_authorize_all_addr),
2968 vxge_hw_mgmt_reg_write(vdev->devh,
2969 vxge_hw_mgmt_reg_type_mrpcim,
2971 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2972 rxmac_authorize_all_vid),
2975 smp_wmb();
2978 if (vdev->titan1)
2979 del_timer_sync(&vdev->vp_lockup_timer);
2981 del_timer_sync(&vdev->vp_reset_timer);
2983 if (do_io)
2984 vxge_hw_device_wait_receive_idle(hldev);
2986 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2988 /* Disable napi */
2989 if (vdev->config.intr_type != MSI_X)
2990 napi_disable(&vdev->napi);
2991 else {
2992 for (i = 0; i < vdev->no_of_vpath; i++)
2993 napi_disable(&vdev->vpaths[i].ring.napi);
2996 netif_carrier_off(vdev->ndev);
2997 netdev_notice(vdev->ndev, "Link Down\n");
2998 netif_tx_stop_all_queues(vdev->ndev);
3000 /* Note that at this point xmit() is stopped by upper layer */
3001 if (do_io)
3002 vxge_hw_device_intr_disable(vdev->devh);
3004 vxge_rem_isr(vdev);
3006 vxge_napi_del_all(vdev);
3008 if (do_io)
3009 vxge_reset_all_vpaths(vdev);
3011 vxge_close_vpaths(vdev, 0);
3013 vxge_debug_entryexit(VXGE_TRACE,
3014 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
3016 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
3018 return 0;
3022 * vxge_close
3023 * @dev: device pointer.
3025 * This is the stop entry point of the driver. It needs to undo exactly
3026 * whatever was done by the open entry point, thus it's usually referred to
3027 * as the close function.Among other things this function mainly stops the
3028 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
3029 * Return value: '0' on success and an appropriate (-)ve integer as
3030 * defined in errno.h file on failure.
3032 static int vxge_close(struct net_device *dev)
3034 do_vxge_close(dev, 1);
3035 return 0;
3039 * vxge_change_mtu
3040 * @dev: net device pointer.
3041 * @new_mtu :the new MTU size for the device.
3043 * A driver entry point to change MTU size for the device. Before changing
3044 * the MTU the device must be stopped.
3046 static int vxge_change_mtu(struct net_device *dev, int new_mtu)
3048 struct vxgedev *vdev = netdev_priv(dev);
3050 vxge_debug_entryexit(vdev->level_trace,
3051 "%s:%d", __func__, __LINE__);
3052 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
3053 vxge_debug_init(vdev->level_err,
3054 "%s: mtu size is invalid", dev->name);
3055 return -EPERM;
3058 /* check if device is down already */
3059 if (unlikely(!is_vxge_card_up(vdev))) {
3060 /* just store new value, will use later on open() */
3061 dev->mtu = new_mtu;
3062 vxge_debug_init(vdev->level_err,
3063 "%s", "device is down on MTU change");
3064 return 0;
3067 vxge_debug_init(vdev->level_trace,
3068 "trying to apply new MTU %d", new_mtu);
3070 if (vxge_close(dev))
3071 return -EIO;
3073 dev->mtu = new_mtu;
3074 vdev->mtu = new_mtu;
3076 if (vxge_open(dev))
3077 return -EIO;
3079 vxge_debug_init(vdev->level_trace,
3080 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
3082 vxge_debug_entryexit(vdev->level_trace,
3083 "%s:%d Exiting...", __func__, __LINE__);
3085 return 0;
3089 * vxge_get_stats64
3090 * @dev: pointer to the device structure
3091 * @stats: pointer to struct rtnl_link_stats64
3094 static struct rtnl_link_stats64 *
3095 vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
3097 struct vxgedev *vdev = netdev_priv(dev);
3098 int k;
3100 /* net_stats already zeroed by caller */
3101 for (k = 0; k < vdev->no_of_vpath; k++) {
3102 net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms;
3103 net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes;
3104 net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors;
3105 net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast;
3106 net_stats->rx_dropped += vdev->vpaths[k].ring.stats.rx_dropped;
3107 net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms;
3108 net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes;
3109 net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors;
3112 return net_stats;
3115 static enum vxge_hw_status vxge_timestamp_config(struct vxgedev *vdev,
3116 int enable)
3118 enum vxge_hw_status status;
3119 u64 val64;
3121 /* Timestamp is passed to the driver via the FCS, therefore we
3122 * must disable the FCS stripping by the adapter. Since this is
3123 * required for the driver to load (due to a hardware bug),
3124 * there is no need to do anything special here.
3126 if (enable)
3127 val64 = VXGE_HW_XMAC_TIMESTAMP_EN |
3128 VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
3129 VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
3130 else
3131 val64 = 0;
3133 status = vxge_hw_mgmt_reg_write(vdev->devh,
3134 vxge_hw_mgmt_reg_type_mrpcim,
3136 offsetof(struct vxge_hw_mrpcim_reg,
3137 xmac_timestamp),
3138 val64);
3139 vxge_hw_device_flush_io(vdev->devh);
3140 return status;
3143 static int vxge_hwtstamp_ioctl(struct vxgedev *vdev, void __user *data)
3145 struct hwtstamp_config config;
3146 enum vxge_hw_status status;
3147 int i;
3149 if (copy_from_user(&config, data, sizeof(config)))
3150 return -EFAULT;
3152 /* reserved for future extensions */
3153 if (config.flags)
3154 return -EINVAL;
3156 /* Transmit HW Timestamp not supported */
3157 switch (config.tx_type) {
3158 case HWTSTAMP_TX_OFF:
3159 break;
3160 case HWTSTAMP_TX_ON:
3161 default:
3162 return -ERANGE;
3165 switch (config.rx_filter) {
3166 case HWTSTAMP_FILTER_NONE:
3167 status = vxge_timestamp_config(vdev, 0);
3168 if (status != VXGE_HW_OK)
3169 return -EFAULT;
3171 vdev->rx_hwts = 0;
3172 config.rx_filter = HWTSTAMP_FILTER_NONE;
3173 break;
3175 case HWTSTAMP_FILTER_ALL:
3176 case HWTSTAMP_FILTER_SOME:
3177 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3178 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3179 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3180 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3181 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3182 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3183 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3184 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3185 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3186 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3187 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3188 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3189 status = vxge_timestamp_config(vdev, 1);
3190 if (status != VXGE_HW_OK)
3191 return -EFAULT;
3193 vdev->rx_hwts = 1;
3194 config.rx_filter = HWTSTAMP_FILTER_ALL;
3195 break;
3197 default:
3198 return -ERANGE;
3201 for (i = 0; i < vdev->no_of_vpath; i++)
3202 vdev->vpaths[i].ring.rx_hwts = vdev->rx_hwts;
3204 if (copy_to_user(data, &config, sizeof(config)))
3205 return -EFAULT;
3207 return 0;
3211 * vxge_ioctl
3212 * @dev: Device pointer.
3213 * @ifr: An IOCTL specific structure, that can contain a pointer to
3214 * a proprietary structure used to pass information to the driver.
3215 * @cmd: This is used to distinguish between the different commands that
3216 * can be passed to the IOCTL functions.
3218 * Entry point for the Ioctl.
3220 static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3222 struct vxgedev *vdev = netdev_priv(dev);
3223 int ret;
3225 switch (cmd) {
3226 case SIOCSHWTSTAMP:
3227 ret = vxge_hwtstamp_ioctl(vdev, rq->ifr_data);
3228 if (ret)
3229 return ret;
3230 break;
3231 default:
3232 return -EOPNOTSUPP;
3235 return 0;
3239 * vxge_tx_watchdog
3240 * @dev: pointer to net device structure
3242 * Watchdog for transmit side.
3243 * This function is triggered if the Tx Queue is stopped
3244 * for a pre-defined amount of time when the Interface is still up.
3246 static void vxge_tx_watchdog(struct net_device *dev)
3248 struct vxgedev *vdev;
3250 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3252 vdev = netdev_priv(dev);
3254 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3256 schedule_work(&vdev->reset_task);
3257 vxge_debug_entryexit(VXGE_TRACE,
3258 "%s:%d Exiting...", __func__, __LINE__);
3262 * vxge_vlan_rx_register
3263 * @dev: net device pointer.
3264 * @grp: vlan group
3266 * Vlan group registration
3268 static void
3269 vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
3271 struct vxgedev *vdev;
3272 struct vxge_vpath *vpath;
3273 int vp;
3274 u64 vid;
3275 enum vxge_hw_status status;
3276 int i;
3278 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3280 vdev = netdev_priv(dev);
3282 vpath = &vdev->vpaths[0];
3283 if ((NULL == grp) && (vpath->is_open)) {
3284 /* Get the first vlan */
3285 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3287 while (status == VXGE_HW_OK) {
3289 /* Delete this vlan from the vid table */
3290 for (vp = 0; vp < vdev->no_of_vpath; vp++) {
3291 vpath = &vdev->vpaths[vp];
3292 if (!vpath->is_open)
3293 continue;
3295 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3298 /* Get the next vlan to be deleted */
3299 vpath = &vdev->vpaths[0];
3300 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3304 vdev->vlgrp = grp;
3306 for (i = 0; i < vdev->no_of_vpath; i++) {
3307 if (vdev->vpaths[i].is_configured)
3308 vdev->vpaths[i].ring.vlgrp = grp;
3311 vxge_debug_entryexit(VXGE_TRACE,
3312 "%s:%d Exiting...", __func__, __LINE__);
3316 * vxge_vlan_rx_add_vid
3317 * @dev: net device pointer.
3318 * @vid: vid
3320 * Add the vlan id to the devices vlan id table
3322 static void
3323 vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3325 struct vxgedev *vdev;
3326 struct vxge_vpath *vpath;
3327 int vp_id;
3329 vdev = netdev_priv(dev);
3331 /* Add these vlan to the vid table */
3332 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3333 vpath = &vdev->vpaths[vp_id];
3334 if (!vpath->is_open)
3335 continue;
3336 vxge_hw_vpath_vid_add(vpath->handle, vid);
3341 * vxge_vlan_rx_add_vid
3342 * @dev: net device pointer.
3343 * @vid: vid
3345 * Remove the vlan id from the device's vlan id table
3347 static void
3348 vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3350 struct vxgedev *vdev;
3351 struct vxge_vpath *vpath;
3352 int vp_id;
3354 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3356 vdev = netdev_priv(dev);
3358 vlan_group_set_device(vdev->vlgrp, vid, NULL);
3360 /* Delete this vlan from the vid table */
3361 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3362 vpath = &vdev->vpaths[vp_id];
3363 if (!vpath->is_open)
3364 continue;
3365 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3367 vxge_debug_entryexit(VXGE_TRACE,
3368 "%s:%d Exiting...", __func__, __LINE__);
3371 static const struct net_device_ops vxge_netdev_ops = {
3372 .ndo_open = vxge_open,
3373 .ndo_stop = vxge_close,
3374 .ndo_get_stats64 = vxge_get_stats64,
3375 .ndo_start_xmit = vxge_xmit,
3376 .ndo_validate_addr = eth_validate_addr,
3377 .ndo_set_multicast_list = vxge_set_multicast,
3378 .ndo_do_ioctl = vxge_ioctl,
3379 .ndo_set_mac_address = vxge_set_mac_addr,
3380 .ndo_change_mtu = vxge_change_mtu,
3381 .ndo_vlan_rx_register = vxge_vlan_rx_register,
3382 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3383 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
3384 .ndo_tx_timeout = vxge_tx_watchdog,
3385 #ifdef CONFIG_NET_POLL_CONTROLLER
3386 .ndo_poll_controller = vxge_netpoll,
3387 #endif
3390 static int __devinit vxge_device_revision(struct vxgedev *vdev)
3392 int ret;
3393 u8 revision;
3395 ret = pci_read_config_byte(vdev->pdev, PCI_REVISION_ID, &revision);
3396 if (ret)
3397 return -EIO;
3399 vdev->titan1 = (revision == VXGE_HW_TITAN1_PCI_REVISION);
3400 return 0;
3403 static int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3404 struct vxge_config *config,
3405 int high_dma, int no_of_vpath,
3406 struct vxgedev **vdev_out)
3408 struct net_device *ndev;
3409 enum vxge_hw_status status = VXGE_HW_OK;
3410 struct vxgedev *vdev;
3411 int ret = 0, no_of_queue = 1;
3412 u64 stat;
3414 *vdev_out = NULL;
3415 if (config->tx_steering_type)
3416 no_of_queue = no_of_vpath;
3418 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3419 no_of_queue);
3420 if (ndev == NULL) {
3421 vxge_debug_init(
3422 vxge_hw_device_trace_level_get(hldev),
3423 "%s : device allocation failed", __func__);
3424 ret = -ENODEV;
3425 goto _out0;
3428 vxge_debug_entryexit(
3429 vxge_hw_device_trace_level_get(hldev),
3430 "%s: %s:%d Entering...",
3431 ndev->name, __func__, __LINE__);
3433 vdev = netdev_priv(ndev);
3434 memset(vdev, 0, sizeof(struct vxgedev));
3436 vdev->ndev = ndev;
3437 vdev->devh = hldev;
3438 vdev->pdev = hldev->pdev;
3439 memcpy(&vdev->config, config, sizeof(struct vxge_config));
3440 vdev->rx_csum = 1; /* Enable Rx CSUM by default. */
3441 vdev->rx_hwts = 0;
3443 ret = vxge_device_revision(vdev);
3444 if (ret < 0)
3445 goto _out1;
3447 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3449 ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
3450 NETIF_F_HW_VLAN_FILTER;
3451 /* Driver entry points */
3452 ndev->irq = vdev->pdev->irq;
3453 ndev->base_addr = (unsigned long) hldev->bar0;
3455 ndev->netdev_ops = &vxge_netdev_ops;
3457 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
3458 INIT_WORK(&vdev->reset_task, vxge_reset);
3460 vxge_initialize_ethtool_ops(ndev);
3462 if (vdev->config.rth_steering != NO_STEERING) {
3463 ndev->features |= NETIF_F_RXHASH;
3464 hldev->config.rth_en = VXGE_HW_RTH_ENABLE;
3467 /* Allocate memory for vpath */
3468 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3469 no_of_vpath, GFP_KERNEL);
3470 if (!vdev->vpaths) {
3471 vxge_debug_init(VXGE_ERR,
3472 "%s: vpath memory allocation failed",
3473 vdev->ndev->name);
3474 ret = -ENOMEM;
3475 goto _out1;
3478 ndev->features |= NETIF_F_SG;
3480 ndev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3481 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3482 "%s : checksuming enabled", __func__);
3484 if (high_dma) {
3485 ndev->features |= NETIF_F_HIGHDMA;
3486 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3487 "%s : using High DMA", __func__);
3490 ndev->features |= NETIF_F_TSO | NETIF_F_TSO6;
3492 if (vdev->config.gro_enable)
3493 ndev->features |= NETIF_F_GRO;
3495 ret = register_netdev(ndev);
3496 if (ret) {
3497 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3498 "%s: %s : device registration failed!",
3499 ndev->name, __func__);
3500 goto _out2;
3503 /* Set the factory defined MAC address initially */
3504 ndev->addr_len = ETH_ALEN;
3506 /* Make Link state as off at this point, when the Link change
3507 * interrupt comes the state will be automatically changed to
3508 * the right state.
3510 netif_carrier_off(ndev);
3512 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3513 "%s: Ethernet device registered",
3514 ndev->name);
3516 hldev->ndev = ndev;
3517 *vdev_out = vdev;
3519 /* Resetting the Device stats */
3520 status = vxge_hw_mrpcim_stats_access(
3521 hldev,
3522 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3525 &stat);
3527 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3528 vxge_debug_init(
3529 vxge_hw_device_trace_level_get(hldev),
3530 "%s: device stats clear returns"
3531 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3533 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3534 "%s: %s:%d Exiting...",
3535 ndev->name, __func__, __LINE__);
3537 return ret;
3538 _out2:
3539 kfree(vdev->vpaths);
3540 _out1:
3541 free_netdev(ndev);
3542 _out0:
3543 return ret;
3547 * vxge_device_unregister
3549 * This function will unregister and free network device
3551 static void vxge_device_unregister(struct __vxge_hw_device *hldev)
3553 struct vxgedev *vdev;
3554 struct net_device *dev;
3555 char buf[IFNAMSIZ];
3557 dev = hldev->ndev;
3558 vdev = netdev_priv(dev);
3560 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d", vdev->ndev->name,
3561 __func__, __LINE__);
3563 strncpy(buf, dev->name, IFNAMSIZ);
3565 flush_work_sync(&vdev->reset_task);
3567 /* in 2.6 will call stop() if device is up */
3568 unregister_netdev(dev);
3570 kfree(vdev->vpaths);
3572 /* we are safe to free it now */
3573 free_netdev(dev);
3575 vxge_debug_init(vdev->level_trace, "%s: ethernet device unregistered",
3576 buf);
3577 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d Exiting...", buf,
3578 __func__, __LINE__);
3582 * vxge_callback_crit_err
3584 * This function is called by the alarm handler in interrupt context.
3585 * Driver must analyze it based on the event type.
3587 static void
3588 vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3589 enum vxge_hw_event type, u64 vp_id)
3591 struct net_device *dev = hldev->ndev;
3592 struct vxgedev *vdev = netdev_priv(dev);
3593 struct vxge_vpath *vpath = NULL;
3594 int vpath_idx;
3596 vxge_debug_entryexit(vdev->level_trace,
3597 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3599 /* Note: This event type should be used for device wide
3600 * indications only - Serious errors, Slot freeze and critical errors
3602 vdev->cric_err_event = type;
3604 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
3605 vpath = &vdev->vpaths[vpath_idx];
3606 if (vpath->device_id == vp_id)
3607 break;
3610 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3611 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3612 vxge_debug_init(VXGE_ERR,
3613 "%s: Slot is frozen", vdev->ndev->name);
3614 } else if (type == VXGE_HW_EVENT_SERR) {
3615 vxge_debug_init(VXGE_ERR,
3616 "%s: Encountered Serious Error",
3617 vdev->ndev->name);
3618 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3619 vxge_debug_init(VXGE_ERR,
3620 "%s: Encountered Critical Error",
3621 vdev->ndev->name);
3624 if ((type == VXGE_HW_EVENT_SERR) ||
3625 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3626 if (unlikely(vdev->exec_mode))
3627 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3628 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3629 vxge_hw_device_mask_all(hldev);
3630 if (unlikely(vdev->exec_mode))
3631 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3632 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3633 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3635 if (unlikely(vdev->exec_mode))
3636 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3637 else {
3638 /* check if this vpath is already set for reset */
3639 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3641 /* disable interrupts for this vpath */
3642 vxge_vpath_intr_disable(vdev, vpath_idx);
3644 /* stop the queue for this vpath */
3645 netif_tx_stop_queue(vpath->fifo.txq);
3650 vxge_debug_entryexit(vdev->level_trace,
3651 "%s: %s:%d Exiting...",
3652 vdev->ndev->name, __func__, __LINE__);
3655 static void verify_bandwidth(void)
3657 int i, band_width, total = 0, equal_priority = 0;
3659 /* 1. If user enters 0 for some fifo, give equal priority to all */
3660 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3661 if (bw_percentage[i] == 0) {
3662 equal_priority = 1;
3663 break;
3667 if (!equal_priority) {
3668 /* 2. If sum exceeds 100, give equal priority to all */
3669 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3670 if (bw_percentage[i] == 0xFF)
3671 break;
3673 total += bw_percentage[i];
3674 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3675 equal_priority = 1;
3676 break;
3681 if (!equal_priority) {
3682 /* Is all the bandwidth consumed? */
3683 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3684 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3685 /* Split rest of bw equally among next VPs*/
3686 band_width =
3687 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3688 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3689 if (band_width < 2) /* min of 2% */
3690 equal_priority = 1;
3691 else {
3692 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3693 i++)
3694 bw_percentage[i] =
3695 band_width;
3698 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3699 equal_priority = 1;
3702 if (equal_priority) {
3703 vxge_debug_init(VXGE_ERR,
3704 "%s: Assigning equal bandwidth to all the vpaths",
3705 VXGE_DRIVER_NAME);
3706 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3707 VXGE_HW_MAX_VIRTUAL_PATHS;
3708 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3709 bw_percentage[i] = bw_percentage[0];
3714 * Vpath configuration
3716 static int __devinit vxge_config_vpaths(
3717 struct vxge_hw_device_config *device_config,
3718 u64 vpath_mask, struct vxge_config *config_param)
3720 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3721 u32 txdl_size, txdl_per_memblock;
3723 temp = driver_config->vpath_per_dev;
3724 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3725 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3726 /* No more CPU. Return vpath number as zero.*/
3727 if (driver_config->g_no_cpus == -1)
3728 return 0;
3730 if (!driver_config->g_no_cpus)
3731 driver_config->g_no_cpus = num_online_cpus();
3733 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3734 if (!driver_config->vpath_per_dev)
3735 driver_config->vpath_per_dev = 1;
3737 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3738 if (!vxge_bVALn(vpath_mask, i, 1))
3739 continue;
3740 else
3741 default_no_vpath++;
3742 if (default_no_vpath < driver_config->vpath_per_dev)
3743 driver_config->vpath_per_dev = default_no_vpath;
3745 driver_config->g_no_cpus = driver_config->g_no_cpus -
3746 (driver_config->vpath_per_dev * 2);
3747 if (driver_config->g_no_cpus <= 0)
3748 driver_config->g_no_cpus = -1;
3751 if (driver_config->vpath_per_dev == 1) {
3752 vxge_debug_ll_config(VXGE_TRACE,
3753 "%s: Disable tx and rx steering, "
3754 "as single vpath is configured", VXGE_DRIVER_NAME);
3755 config_param->rth_steering = NO_STEERING;
3756 config_param->tx_steering_type = NO_STEERING;
3757 device_config->rth_en = 0;
3760 /* configure bandwidth */
3761 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3762 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3764 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3765 device_config->vp_config[i].vp_id = i;
3766 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3767 if (no_of_vpaths < driver_config->vpath_per_dev) {
3768 if (!vxge_bVALn(vpath_mask, i, 1)) {
3769 vxge_debug_ll_config(VXGE_TRACE,
3770 "%s: vpath: %d is not available",
3771 VXGE_DRIVER_NAME, i);
3772 continue;
3773 } else {
3774 vxge_debug_ll_config(VXGE_TRACE,
3775 "%s: vpath: %d available",
3776 VXGE_DRIVER_NAME, i);
3777 no_of_vpaths++;
3779 } else {
3780 vxge_debug_ll_config(VXGE_TRACE,
3781 "%s: vpath: %d is not configured, "
3782 "max_config_vpath exceeded",
3783 VXGE_DRIVER_NAME, i);
3784 break;
3787 /* Configure Tx fifo's */
3788 device_config->vp_config[i].fifo.enable =
3789 VXGE_HW_FIFO_ENABLE;
3790 device_config->vp_config[i].fifo.max_frags =
3791 MAX_SKB_FRAGS + 1;
3792 device_config->vp_config[i].fifo.memblock_size =
3793 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3795 txdl_size = device_config->vp_config[i].fifo.max_frags *
3796 sizeof(struct vxge_hw_fifo_txd);
3797 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3799 device_config->vp_config[i].fifo.fifo_blocks =
3800 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3802 device_config->vp_config[i].fifo.intr =
3803 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3805 /* Configure tti properties */
3806 device_config->vp_config[i].tti.intr_enable =
3807 VXGE_HW_TIM_INTR_ENABLE;
3809 device_config->vp_config[i].tti.btimer_val =
3810 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3812 device_config->vp_config[i].tti.timer_ac_en =
3813 VXGE_HW_TIM_TIMER_AC_ENABLE;
3815 /* For msi-x with napi (each vector has a handler of its own) -
3816 * Set CI to OFF for all vpaths
3818 device_config->vp_config[i].tti.timer_ci_en =
3819 VXGE_HW_TIM_TIMER_CI_DISABLE;
3821 device_config->vp_config[i].tti.timer_ri_en =
3822 VXGE_HW_TIM_TIMER_RI_DISABLE;
3824 device_config->vp_config[i].tti.util_sel =
3825 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3827 device_config->vp_config[i].tti.ltimer_val =
3828 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3830 device_config->vp_config[i].tti.rtimer_val =
3831 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3833 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3834 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3835 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3836 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3837 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3838 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3839 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3841 /* Configure Rx rings */
3842 device_config->vp_config[i].ring.enable =
3843 VXGE_HW_RING_ENABLE;
3845 device_config->vp_config[i].ring.ring_blocks =
3846 VXGE_HW_DEF_RING_BLOCKS;
3848 device_config->vp_config[i].ring.buffer_mode =
3849 VXGE_HW_RING_RXD_BUFFER_MODE_1;
3851 device_config->vp_config[i].ring.rxds_limit =
3852 VXGE_HW_DEF_RING_RXDS_LIMIT;
3854 device_config->vp_config[i].ring.scatter_mode =
3855 VXGE_HW_RING_SCATTER_MODE_A;
3857 /* Configure rti properties */
3858 device_config->vp_config[i].rti.intr_enable =
3859 VXGE_HW_TIM_INTR_ENABLE;
3861 device_config->vp_config[i].rti.btimer_val =
3862 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3864 device_config->vp_config[i].rti.timer_ac_en =
3865 VXGE_HW_TIM_TIMER_AC_ENABLE;
3867 device_config->vp_config[i].rti.timer_ci_en =
3868 VXGE_HW_TIM_TIMER_CI_DISABLE;
3870 device_config->vp_config[i].rti.timer_ri_en =
3871 VXGE_HW_TIM_TIMER_RI_DISABLE;
3873 device_config->vp_config[i].rti.util_sel =
3874 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3876 device_config->vp_config[i].rti.urange_a =
3877 RTI_RX_URANGE_A;
3878 device_config->vp_config[i].rti.urange_b =
3879 RTI_RX_URANGE_B;
3880 device_config->vp_config[i].rti.urange_c =
3881 RTI_RX_URANGE_C;
3882 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3883 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3884 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3885 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3887 device_config->vp_config[i].rti.rtimer_val =
3888 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3890 device_config->vp_config[i].rti.ltimer_val =
3891 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3893 device_config->vp_config[i].rpa_strip_vlan_tag =
3894 vlan_tag_strip;
3897 driver_config->vpath_per_dev = temp;
3898 return no_of_vpaths;
3901 /* initialize device configuratrions */
3902 static void __devinit vxge_device_config_init(
3903 struct vxge_hw_device_config *device_config,
3904 int *intr_type)
3906 /* Used for CQRQ/SRQ. */
3907 device_config->dma_blockpool_initial =
3908 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3910 device_config->dma_blockpool_max =
3911 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3913 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3914 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3916 #ifndef CONFIG_PCI_MSI
3917 vxge_debug_init(VXGE_ERR,
3918 "%s: This Kernel does not support "
3919 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3920 *intr_type = INTA;
3921 #endif
3923 /* Configure whether MSI-X or IRQL. */
3924 switch (*intr_type) {
3925 case INTA:
3926 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3927 break;
3929 case MSI_X:
3930 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX_ONE_SHOT;
3931 break;
3934 /* Timer period between device poll */
3935 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3937 /* Configure mac based steering. */
3938 device_config->rts_mac_en = addr_learn_en;
3940 /* Configure Vpaths */
3941 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3943 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3944 __func__);
3945 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3946 device_config->intr_mode);
3947 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3948 device_config->device_poll_millis);
3949 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3950 device_config->rth_en);
3951 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3952 device_config->rth_it_type);
3955 static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3957 int i;
3959 vxge_debug_init(VXGE_TRACE,
3960 "%s: %d Vpath(s) opened",
3961 vdev->ndev->name, vdev->no_of_vpath);
3963 switch (vdev->config.intr_type) {
3964 case INTA:
3965 vxge_debug_init(VXGE_TRACE,
3966 "%s: Interrupt type INTA", vdev->ndev->name);
3967 break;
3969 case MSI_X:
3970 vxge_debug_init(VXGE_TRACE,
3971 "%s: Interrupt type MSI-X", vdev->ndev->name);
3972 break;
3975 if (vdev->config.rth_steering) {
3976 vxge_debug_init(VXGE_TRACE,
3977 "%s: RTH steering enabled for TCP_IPV4",
3978 vdev->ndev->name);
3979 } else {
3980 vxge_debug_init(VXGE_TRACE,
3981 "%s: RTH steering disabled", vdev->ndev->name);
3984 switch (vdev->config.tx_steering_type) {
3985 case NO_STEERING:
3986 vxge_debug_init(VXGE_TRACE,
3987 "%s: Tx steering disabled", vdev->ndev->name);
3988 break;
3989 case TX_PRIORITY_STEERING:
3990 vxge_debug_init(VXGE_TRACE,
3991 "%s: Unsupported tx steering option",
3992 vdev->ndev->name);
3993 vxge_debug_init(VXGE_TRACE,
3994 "%s: Tx steering disabled", vdev->ndev->name);
3995 vdev->config.tx_steering_type = 0;
3996 break;
3997 case TX_VLAN_STEERING:
3998 vxge_debug_init(VXGE_TRACE,
3999 "%s: Unsupported tx steering option",
4000 vdev->ndev->name);
4001 vxge_debug_init(VXGE_TRACE,
4002 "%s: Tx steering disabled", vdev->ndev->name);
4003 vdev->config.tx_steering_type = 0;
4004 break;
4005 case TX_MULTIQ_STEERING:
4006 vxge_debug_init(VXGE_TRACE,
4007 "%s: Tx multiqueue steering enabled",
4008 vdev->ndev->name);
4009 break;
4010 case TX_PORT_STEERING:
4011 vxge_debug_init(VXGE_TRACE,
4012 "%s: Tx port steering enabled",
4013 vdev->ndev->name);
4014 break;
4015 default:
4016 vxge_debug_init(VXGE_ERR,
4017 "%s: Unsupported tx steering type",
4018 vdev->ndev->name);
4019 vxge_debug_init(VXGE_TRACE,
4020 "%s: Tx steering disabled", vdev->ndev->name);
4021 vdev->config.tx_steering_type = 0;
4024 if (vdev->config.gro_enable) {
4025 vxge_debug_init(VXGE_ERR,
4026 "%s: Generic receive offload enabled",
4027 vdev->ndev->name);
4028 } else
4029 vxge_debug_init(VXGE_TRACE,
4030 "%s: Generic receive offload disabled",
4031 vdev->ndev->name);
4033 if (vdev->config.addr_learn_en)
4034 vxge_debug_init(VXGE_TRACE,
4035 "%s: MAC Address learning enabled", vdev->ndev->name);
4037 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4038 if (!vxge_bVALn(vpath_mask, i, 1))
4039 continue;
4040 vxge_debug_ll_config(VXGE_TRACE,
4041 "%s: MTU size - %d", vdev->ndev->name,
4042 ((struct __vxge_hw_device *)(vdev->devh))->
4043 config.vp_config[i].mtu);
4044 vxge_debug_init(VXGE_TRACE,
4045 "%s: VLAN tag stripping %s", vdev->ndev->name,
4046 ((struct __vxge_hw_device *)(vdev->devh))->
4047 config.vp_config[i].rpa_strip_vlan_tag
4048 ? "Enabled" : "Disabled");
4049 vxge_debug_ll_config(VXGE_TRACE,
4050 "%s: Max frags : %d", vdev->ndev->name,
4051 ((struct __vxge_hw_device *)(vdev->devh))->
4052 config.vp_config[i].fifo.max_frags);
4053 break;
4057 #ifdef CONFIG_PM
4059 * vxge_pm_suspend - vxge power management suspend entry point
4062 static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
4064 return -ENOSYS;
4067 * vxge_pm_resume - vxge power management resume entry point
4070 static int vxge_pm_resume(struct pci_dev *pdev)
4072 return -ENOSYS;
4075 #endif
4078 * vxge_io_error_detected - called when PCI error is detected
4079 * @pdev: Pointer to PCI device
4080 * @state: The current pci connection state
4082 * This function is called after a PCI bus error affecting
4083 * this device has been detected.
4085 static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
4086 pci_channel_state_t state)
4088 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
4089 struct net_device *netdev = hldev->ndev;
4091 netif_device_detach(netdev);
4093 if (state == pci_channel_io_perm_failure)
4094 return PCI_ERS_RESULT_DISCONNECT;
4096 if (netif_running(netdev)) {
4097 /* Bring down the card, while avoiding PCI I/O */
4098 do_vxge_close(netdev, 0);
4101 pci_disable_device(pdev);
4103 return PCI_ERS_RESULT_NEED_RESET;
4107 * vxge_io_slot_reset - called after the pci bus has been reset.
4108 * @pdev: Pointer to PCI device
4110 * Restart the card from scratch, as if from a cold-boot.
4111 * At this point, the card has exprienced a hard reset,
4112 * followed by fixups by BIOS, and has its config space
4113 * set up identically to what it was at cold boot.
4115 static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
4117 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
4118 struct net_device *netdev = hldev->ndev;
4120 struct vxgedev *vdev = netdev_priv(netdev);
4122 if (pci_enable_device(pdev)) {
4123 netdev_err(netdev, "Cannot re-enable device after reset\n");
4124 return PCI_ERS_RESULT_DISCONNECT;
4127 pci_set_master(pdev);
4128 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
4130 return PCI_ERS_RESULT_RECOVERED;
4134 * vxge_io_resume - called when traffic can start flowing again.
4135 * @pdev: Pointer to PCI device
4137 * This callback is called when the error recovery driver tells
4138 * us that its OK to resume normal operation.
4140 static void vxge_io_resume(struct pci_dev *pdev)
4142 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
4143 struct net_device *netdev = hldev->ndev;
4145 if (netif_running(netdev)) {
4146 if (vxge_open(netdev)) {
4147 netdev_err(netdev,
4148 "Can't bring device back up after reset\n");
4149 return;
4153 netif_device_attach(netdev);
4156 static inline u32 vxge_get_num_vfs(u64 function_mode)
4158 u32 num_functions = 0;
4160 switch (function_mode) {
4161 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4162 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
4163 num_functions = 8;
4164 break;
4165 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4166 num_functions = 1;
4167 break;
4168 case VXGE_HW_FUNCTION_MODE_SRIOV:
4169 case VXGE_HW_FUNCTION_MODE_MRIOV:
4170 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
4171 num_functions = 17;
4172 break;
4173 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
4174 num_functions = 4;
4175 break;
4176 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
4177 num_functions = 2;
4178 break;
4179 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
4180 num_functions = 8; /* TODO */
4181 break;
4183 return num_functions;
4186 int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override)
4188 struct __vxge_hw_device *hldev = vdev->devh;
4189 u32 maj, min, bld, cmaj, cmin, cbld;
4190 enum vxge_hw_status status;
4191 const struct firmware *fw;
4192 int ret;
4194 ret = request_firmware(&fw, fw_name, &vdev->pdev->dev);
4195 if (ret) {
4196 vxge_debug_init(VXGE_ERR, "%s: Firmware file '%s' not found",
4197 VXGE_DRIVER_NAME, fw_name);
4198 goto out;
4201 /* Load the new firmware onto the adapter */
4202 status = vxge_update_fw_image(hldev, fw->data, fw->size);
4203 if (status != VXGE_HW_OK) {
4204 vxge_debug_init(VXGE_ERR,
4205 "%s: FW image download to adapter failed '%s'.",
4206 VXGE_DRIVER_NAME, fw_name);
4207 ret = -EIO;
4208 goto out;
4211 /* Read the version of the new firmware */
4212 status = vxge_hw_upgrade_read_version(hldev, &maj, &min, &bld);
4213 if (status != VXGE_HW_OK) {
4214 vxge_debug_init(VXGE_ERR,
4215 "%s: Upgrade read version failed '%s'.",
4216 VXGE_DRIVER_NAME, fw_name);
4217 ret = -EIO;
4218 goto out;
4221 cmaj = vdev->config.device_hw_info.fw_version.major;
4222 cmin = vdev->config.device_hw_info.fw_version.minor;
4223 cbld = vdev->config.device_hw_info.fw_version.build;
4224 /* It's possible the version in /lib/firmware is not the latest version.
4225 * If so, we could get into a loop of trying to upgrade to the latest
4226 * and flashing the older version.
4228 if (VXGE_FW_VER(maj, min, bld) == VXGE_FW_VER(cmaj, cmin, cbld) &&
4229 !override) {
4230 ret = -EINVAL;
4231 goto out;
4234 printk(KERN_NOTICE "Upgrade to firmware version %d.%d.%d commencing\n",
4235 maj, min, bld);
4237 /* Flash the adapter with the new firmware */
4238 status = vxge_hw_flash_fw(hldev);
4239 if (status != VXGE_HW_OK) {
4240 vxge_debug_init(VXGE_ERR, "%s: Upgrade commit failed '%s'.",
4241 VXGE_DRIVER_NAME, fw_name);
4242 ret = -EIO;
4243 goto out;
4246 printk(KERN_NOTICE "Upgrade of firmware successful! Adapter must be "
4247 "hard reset before using, thus requiring a system reboot or a "
4248 "hotplug event.\n");
4250 out:
4251 release_firmware(fw);
4252 return ret;
4255 static int vxge_probe_fw_update(struct vxgedev *vdev)
4257 u32 maj, min, bld;
4258 int ret, gpxe = 0;
4259 char *fw_name;
4261 maj = vdev->config.device_hw_info.fw_version.major;
4262 min = vdev->config.device_hw_info.fw_version.minor;
4263 bld = vdev->config.device_hw_info.fw_version.build;
4265 if (VXGE_FW_VER(maj, min, bld) == VXGE_CERT_FW_VER)
4266 return 0;
4268 /* Ignore the build number when determining if the current firmware is
4269 * "too new" to load the driver
4271 if (VXGE_FW_VER(maj, min, 0) > VXGE_CERT_FW_VER) {
4272 vxge_debug_init(VXGE_ERR, "%s: Firmware newer than last known "
4273 "version, unable to load driver\n",
4274 VXGE_DRIVER_NAME);
4275 return -EINVAL;
4278 /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
4279 * work with this driver.
4281 if (VXGE_FW_VER(maj, min, bld) <= VXGE_FW_DEAD_VER) {
4282 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d cannot be "
4283 "upgraded\n", VXGE_DRIVER_NAME, maj, min, bld);
4284 return -EINVAL;
4287 /* If file not specified, determine gPXE or not */
4288 if (VXGE_FW_VER(maj, min, bld) >= VXGE_EPROM_FW_VER) {
4289 int i;
4290 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++)
4291 if (vdev->devh->eprom_versions[i]) {
4292 gpxe = 1;
4293 break;
4296 if (gpxe)
4297 fw_name = "vxge/X3fw-pxe.ncf";
4298 else
4299 fw_name = "vxge/X3fw.ncf";
4301 ret = vxge_fw_upgrade(vdev, fw_name, 0);
4302 /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
4303 * probe, so ignore them
4305 if (ret != -EINVAL && ret != -ENOENT)
4306 return -EIO;
4307 else
4308 ret = 0;
4310 if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR, VXGE_CERT_FW_VER_MINOR, 0) >
4311 VXGE_FW_VER(maj, min, 0)) {
4312 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d is too old to"
4313 " be used with this driver.\n"
4314 "Please get the latest version from "
4315 "ftp://ftp.s2io.com/pub/X3100-Drivers/FIRMWARE",
4316 VXGE_DRIVER_NAME, maj, min, bld);
4317 return -EINVAL;
4320 return ret;
4323 static int __devinit is_sriov_initialized(struct pci_dev *pdev)
4325 int pos;
4326 u16 ctrl;
4328 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4329 if (pos) {
4330 pci_read_config_word(pdev, pos + PCI_SRIOV_CTRL, &ctrl);
4331 if (ctrl & PCI_SRIOV_CTRL_VFE)
4332 return 1;
4334 return 0;
4338 * vxge_probe
4339 * @pdev : structure containing the PCI related information of the device.
4340 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4341 * Description:
4342 * This function is called when a new PCI device gets detected and initializes
4343 * it.
4344 * Return value:
4345 * returns 0 on success and negative on failure.
4348 static int __devinit
4349 vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4351 struct __vxge_hw_device *hldev;
4352 enum vxge_hw_status status;
4353 int ret;
4354 int high_dma = 0;
4355 u64 vpath_mask = 0;
4356 struct vxgedev *vdev;
4357 struct vxge_config *ll_config = NULL;
4358 struct vxge_hw_device_config *device_config = NULL;
4359 struct vxge_hw_device_attr attr;
4360 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4361 u8 *macaddr;
4362 struct vxge_mac_addrs *entry;
4363 static int bus = -1, device = -1;
4364 u32 host_type;
4365 u8 new_device = 0;
4366 enum vxge_hw_status is_privileged;
4367 u32 function_mode;
4368 u32 num_vfs = 0;
4370 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4371 attr.pdev = pdev;
4373 /* In SRIOV-17 mode, functions of the same adapter
4374 * can be deployed on different buses
4376 if (((bus != pdev->bus->number) || (device != PCI_SLOT(pdev->devfn))) &&
4377 !pdev->is_virtfn)
4378 new_device = 1;
4380 bus = pdev->bus->number;
4381 device = PCI_SLOT(pdev->devfn);
4383 if (new_device) {
4384 if (driver_config->config_dev_cnt &&
4385 (driver_config->config_dev_cnt !=
4386 driver_config->total_dev_cnt))
4387 vxge_debug_init(VXGE_ERR,
4388 "%s: Configured %d of %d devices",
4389 VXGE_DRIVER_NAME,
4390 driver_config->config_dev_cnt,
4391 driver_config->total_dev_cnt);
4392 driver_config->config_dev_cnt = 0;
4393 driver_config->total_dev_cnt = 0;
4396 /* Now making the CPU based no of vpath calculation
4397 * applicable for individual functions as well.
4399 driver_config->g_no_cpus = 0;
4400 driver_config->vpath_per_dev = max_config_vpath;
4402 driver_config->total_dev_cnt++;
4403 if (++driver_config->config_dev_cnt > max_config_dev) {
4404 ret = 0;
4405 goto _exit0;
4408 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4409 GFP_KERNEL);
4410 if (!device_config) {
4411 ret = -ENOMEM;
4412 vxge_debug_init(VXGE_ERR,
4413 "device_config : malloc failed %s %d",
4414 __FILE__, __LINE__);
4415 goto _exit0;
4418 ll_config = kzalloc(sizeof(struct vxge_config), GFP_KERNEL);
4419 if (!ll_config) {
4420 ret = -ENOMEM;
4421 vxge_debug_init(VXGE_ERR,
4422 "device_config : malloc failed %s %d",
4423 __FILE__, __LINE__);
4424 goto _exit0;
4426 ll_config->tx_steering_type = TX_MULTIQ_STEERING;
4427 ll_config->intr_type = MSI_X;
4428 ll_config->napi_weight = NEW_NAPI_WEIGHT;
4429 ll_config->rth_steering = RTH_STEERING;
4431 /* get the default configuration parameters */
4432 vxge_hw_device_config_default_get(device_config);
4434 /* initialize configuration parameters */
4435 vxge_device_config_init(device_config, &ll_config->intr_type);
4437 ret = pci_enable_device(pdev);
4438 if (ret) {
4439 vxge_debug_init(VXGE_ERR,
4440 "%s : can not enable PCI device", __func__);
4441 goto _exit0;
4444 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
4445 vxge_debug_ll_config(VXGE_TRACE,
4446 "%s : using 64bit DMA", __func__);
4448 high_dma = 1;
4450 if (pci_set_consistent_dma_mask(pdev,
4451 DMA_BIT_MASK(64))) {
4452 vxge_debug_init(VXGE_ERR,
4453 "%s : unable to obtain 64bit DMA for "
4454 "consistent allocations", __func__);
4455 ret = -ENOMEM;
4456 goto _exit1;
4458 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
4459 vxge_debug_ll_config(VXGE_TRACE,
4460 "%s : using 32bit DMA", __func__);
4461 } else {
4462 ret = -ENOMEM;
4463 goto _exit1;
4466 ret = pci_request_region(pdev, 0, VXGE_DRIVER_NAME);
4467 if (ret) {
4468 vxge_debug_init(VXGE_ERR,
4469 "%s : request regions failed", __func__);
4470 goto _exit1;
4473 pci_set_master(pdev);
4475 attr.bar0 = pci_ioremap_bar(pdev, 0);
4476 if (!attr.bar0) {
4477 vxge_debug_init(VXGE_ERR,
4478 "%s : cannot remap io memory bar0", __func__);
4479 ret = -ENODEV;
4480 goto _exit2;
4482 vxge_debug_ll_config(VXGE_TRACE,
4483 "pci ioremap bar0: %p:0x%llx",
4484 attr.bar0,
4485 (unsigned long long)pci_resource_start(pdev, 0));
4487 status = vxge_hw_device_hw_info_get(attr.bar0,
4488 &ll_config->device_hw_info);
4489 if (status != VXGE_HW_OK) {
4490 vxge_debug_init(VXGE_ERR,
4491 "%s: Reading of hardware info failed."
4492 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4493 ret = -EINVAL;
4494 goto _exit3;
4497 vpath_mask = ll_config->device_hw_info.vpath_mask;
4498 if (vpath_mask == 0) {
4499 vxge_debug_ll_config(VXGE_TRACE,
4500 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4501 ret = -EINVAL;
4502 goto _exit3;
4505 vxge_debug_ll_config(VXGE_TRACE,
4506 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4507 (unsigned long long)vpath_mask);
4509 function_mode = ll_config->device_hw_info.function_mode;
4510 host_type = ll_config->device_hw_info.host_type;
4511 is_privileged = __vxge_hw_device_is_privilaged(host_type,
4512 ll_config->device_hw_info.func_id);
4514 /* Check how many vpaths are available */
4515 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4516 if (!((vpath_mask) & vxge_mBIT(i)))
4517 continue;
4518 max_vpath_supported++;
4521 if (new_device)
4522 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4524 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4525 if (is_sriov(function_mode) && !is_sriov_initialized(pdev) &&
4526 (ll_config->intr_type != INTA)) {
4527 ret = pci_enable_sriov(pdev, num_vfs);
4528 if (ret)
4529 vxge_debug_ll_config(VXGE_ERR,
4530 "Failed in enabling SRIOV mode: %d\n", ret);
4531 /* No need to fail out, as an error here is non-fatal */
4535 * Configure vpaths and get driver configured number of vpaths
4536 * which is less than or equal to the maximum vpaths per function.
4538 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
4539 if (!no_of_vpath) {
4540 vxge_debug_ll_config(VXGE_ERR,
4541 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4542 ret = 0;
4543 goto _exit3;
4546 /* Setting driver callbacks */
4547 attr.uld_callbacks.link_up = vxge_callback_link_up;
4548 attr.uld_callbacks.link_down = vxge_callback_link_down;
4549 attr.uld_callbacks.crit_err = vxge_callback_crit_err;
4551 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4552 if (status != VXGE_HW_OK) {
4553 vxge_debug_init(VXGE_ERR,
4554 "Failed to initialize device (%d)", status);
4555 ret = -EINVAL;
4556 goto _exit3;
4559 if (VXGE_FW_VER(ll_config->device_hw_info.fw_version.major,
4560 ll_config->device_hw_info.fw_version.minor,
4561 ll_config->device_hw_info.fw_version.build) >=
4562 VXGE_EPROM_FW_VER) {
4563 struct eprom_image img[VXGE_HW_MAX_ROM_IMAGES];
4565 status = vxge_hw_vpath_eprom_img_ver_get(hldev, img);
4566 if (status != VXGE_HW_OK) {
4567 vxge_debug_init(VXGE_ERR, "%s: Reading of EPROM failed",
4568 VXGE_DRIVER_NAME);
4569 /* This is a non-fatal error, continue */
4572 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
4573 hldev->eprom_versions[i] = img[i].version;
4574 if (!img[i].is_valid)
4575 break;
4576 vxge_debug_init(VXGE_TRACE, "%s: EPROM %d, version "
4577 "%d.%d.%d.%d", VXGE_DRIVER_NAME, i,
4578 VXGE_EPROM_IMG_MAJOR(img[i].version),
4579 VXGE_EPROM_IMG_MINOR(img[i].version),
4580 VXGE_EPROM_IMG_FIX(img[i].version),
4581 VXGE_EPROM_IMG_BUILD(img[i].version));
4585 /* if FCS stripping is not disabled in MAC fail driver load */
4586 status = vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask);
4587 if (status != VXGE_HW_OK) {
4588 vxge_debug_init(VXGE_ERR, "%s: FCS stripping is enabled in MAC"
4589 " failing driver load", VXGE_DRIVER_NAME);
4590 ret = -EINVAL;
4591 goto _exit4;
4594 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4596 /* set private device info */
4597 pci_set_drvdata(pdev, hldev);
4599 ll_config->gro_enable = VXGE_GRO_ALWAYS_AGGREGATE;
4600 ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4601 ll_config->addr_learn_en = addr_learn_en;
4602 ll_config->rth_algorithm = RTH_ALG_JENKINS;
4603 ll_config->rth_hash_type_tcpipv4 = 1;
4604 ll_config->rth_hash_type_ipv4 = 0;
4605 ll_config->rth_hash_type_tcpipv6 = 0;
4606 ll_config->rth_hash_type_ipv6 = 0;
4607 ll_config->rth_hash_type_tcpipv6ex = 0;
4608 ll_config->rth_hash_type_ipv6ex = 0;
4609 ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
4610 ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4611 ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4613 ret = vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
4614 &vdev);
4615 if (ret) {
4616 ret = -EINVAL;
4617 goto _exit4;
4620 ret = vxge_probe_fw_update(vdev);
4621 if (ret)
4622 goto _exit5;
4624 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4625 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4626 vxge_hw_device_trace_level_get(hldev));
4628 /* set private HW device info */
4629 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4630 vdev->bar0 = attr.bar0;
4631 vdev->max_vpath_supported = max_vpath_supported;
4632 vdev->no_of_vpath = no_of_vpath;
4634 /* Virtual Path count */
4635 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4636 if (!vxge_bVALn(vpath_mask, i, 1))
4637 continue;
4638 if (j >= vdev->no_of_vpath)
4639 break;
4641 vdev->vpaths[j].is_configured = 1;
4642 vdev->vpaths[j].device_id = i;
4643 vdev->vpaths[j].ring.driver_id = j;
4644 vdev->vpaths[j].vdev = vdev;
4645 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4646 memcpy((u8 *)vdev->vpaths[j].macaddr,
4647 ll_config->device_hw_info.mac_addrs[i],
4648 ETH_ALEN);
4650 /* Initialize the mac address list header */
4651 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4653 vdev->vpaths[j].mac_addr_cnt = 0;
4654 vdev->vpaths[j].mcast_addr_cnt = 0;
4655 j++;
4657 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4658 vdev->max_config_port = max_config_port;
4660 vdev->vlan_tag_strip = vlan_tag_strip;
4662 /* map the hashing selector table to the configured vpaths */
4663 for (i = 0; i < vdev->no_of_vpath; i++)
4664 vdev->vpath_selector[i] = vpath_selector[i];
4666 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4668 ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4669 ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4670 ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
4672 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
4673 vdev->ndev->name, ll_config->device_hw_info.serial_number);
4675 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
4676 vdev->ndev->name, ll_config->device_hw_info.part_number);
4678 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
4679 vdev->ndev->name, ll_config->device_hw_info.product_desc);
4681 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4682 vdev->ndev->name, macaddr);
4684 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4685 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4687 vxge_debug_init(VXGE_TRACE,
4688 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
4689 ll_config->device_hw_info.fw_version.version,
4690 ll_config->device_hw_info.fw_date.date);
4692 if (new_device) {
4693 switch (ll_config->device_hw_info.function_mode) {
4694 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4695 vxge_debug_init(VXGE_TRACE,
4696 "%s: Single Function Mode Enabled", vdev->ndev->name);
4697 break;
4698 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4699 vxge_debug_init(VXGE_TRACE,
4700 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4701 break;
4702 case VXGE_HW_FUNCTION_MODE_SRIOV:
4703 vxge_debug_init(VXGE_TRACE,
4704 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4705 break;
4706 case VXGE_HW_FUNCTION_MODE_MRIOV:
4707 vxge_debug_init(VXGE_TRACE,
4708 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4709 break;
4713 vxge_print_parm(vdev, vpath_mask);
4715 /* Store the fw version for ethttool option */
4716 strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
4717 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4718 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4720 /* Copy the station mac address to the list */
4721 for (i = 0; i < vdev->no_of_vpath; i++) {
4722 entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_KERNEL);
4723 if (NULL == entry) {
4724 vxge_debug_init(VXGE_ERR,
4725 "%s: mac_addr_list : memory allocation failed",
4726 vdev->ndev->name);
4727 ret = -EPERM;
4728 goto _exit6;
4730 macaddr = (u8 *)&entry->macaddr;
4731 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4732 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4733 vdev->vpaths[i].mac_addr_cnt = 1;
4736 kfree(device_config);
4739 * INTA is shared in multi-function mode. This is unlike the INTA
4740 * implementation in MR mode, where each VH has its own INTA message.
4741 * - INTA is masked (disabled) as long as at least one function sets
4742 * its TITAN_MASK_ALL_INT.ALARM bit.
4743 * - INTA is unmasked (enabled) when all enabled functions have cleared
4744 * their own TITAN_MASK_ALL_INT.ALARM bit.
4745 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4746 * Though this driver leaves the top level interrupts unmasked while
4747 * leaving the required module interrupt bits masked on exit, there
4748 * could be a rougue driver around that does not follow this procedure
4749 * resulting in a failure to generate interrupts. The following code is
4750 * present to prevent such a failure.
4753 if (ll_config->device_hw_info.function_mode ==
4754 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4755 if (vdev->config.intr_type == INTA)
4756 vxge_hw_device_unmask_all(hldev);
4758 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4759 vdev->ndev->name, __func__, __LINE__);
4761 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4762 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4763 vxge_hw_device_trace_level_get(hldev));
4765 kfree(ll_config);
4766 return 0;
4768 _exit6:
4769 for (i = 0; i < vdev->no_of_vpath; i++)
4770 vxge_free_mac_add_list(&vdev->vpaths[i]);
4771 _exit5:
4772 vxge_device_unregister(hldev);
4773 _exit4:
4774 pci_set_drvdata(pdev, NULL);
4775 vxge_hw_device_terminate(hldev);
4776 pci_disable_sriov(pdev);
4777 _exit3:
4778 iounmap(attr.bar0);
4779 _exit2:
4780 pci_release_region(pdev, 0);
4781 _exit1:
4782 pci_disable_device(pdev);
4783 _exit0:
4784 kfree(ll_config);
4785 kfree(device_config);
4786 driver_config->config_dev_cnt--;
4787 driver_config->total_dev_cnt--;
4788 return ret;
4792 * vxge_rem_nic - Free the PCI device
4793 * @pdev: structure containing the PCI related information of the device.
4794 * Description: This function is called by the Pci subsystem to release a
4795 * PCI device and free up all resource held up by the device.
4797 static void __devexit vxge_remove(struct pci_dev *pdev)
4799 struct __vxge_hw_device *hldev;
4800 struct vxgedev *vdev;
4801 int i;
4803 hldev = pci_get_drvdata(pdev);
4804 if (hldev == NULL)
4805 return;
4807 vdev = netdev_priv(hldev->ndev);
4809 vxge_debug_entryexit(vdev->level_trace, "%s:%d", __func__, __LINE__);
4810 vxge_debug_init(vdev->level_trace, "%s : removing PCI device...",
4811 __func__);
4813 for (i = 0; i < vdev->no_of_vpath; i++)
4814 vxge_free_mac_add_list(&vdev->vpaths[i]);
4816 vxge_device_unregister(hldev);
4817 pci_set_drvdata(pdev, NULL);
4818 /* Do not call pci_disable_sriov here, as it will break child devices */
4819 vxge_hw_device_terminate(hldev);
4820 iounmap(vdev->bar0);
4821 pci_release_region(pdev, 0);
4822 pci_disable_device(pdev);
4823 driver_config->config_dev_cnt--;
4824 driver_config->total_dev_cnt--;
4826 vxge_debug_init(vdev->level_trace, "%s:%d Device unregistered",
4827 __func__, __LINE__);
4828 vxge_debug_entryexit(vdev->level_trace, "%s:%d Exiting...", __func__,
4829 __LINE__);
4832 static struct pci_error_handlers vxge_err_handler = {
4833 .error_detected = vxge_io_error_detected,
4834 .slot_reset = vxge_io_slot_reset,
4835 .resume = vxge_io_resume,
4838 static struct pci_driver vxge_driver = {
4839 .name = VXGE_DRIVER_NAME,
4840 .id_table = vxge_id_table,
4841 .probe = vxge_probe,
4842 .remove = __devexit_p(vxge_remove),
4843 #ifdef CONFIG_PM
4844 .suspend = vxge_pm_suspend,
4845 .resume = vxge_pm_resume,
4846 #endif
4847 .err_handler = &vxge_err_handler,
4850 static int __init
4851 vxge_starter(void)
4853 int ret = 0;
4855 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4856 pr_info("Driver version: %s\n", DRV_VERSION);
4858 verify_bandwidth();
4860 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4861 if (!driver_config)
4862 return -ENOMEM;
4864 ret = pci_register_driver(&vxge_driver);
4865 if (ret) {
4866 kfree(driver_config);
4867 goto err;
4870 if (driver_config->config_dev_cnt &&
4871 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4872 vxge_debug_init(VXGE_ERR,
4873 "%s: Configured %d of %d devices",
4874 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4875 driver_config->total_dev_cnt);
4876 err:
4877 return ret;
4880 static void __exit
4881 vxge_closer(void)
4883 pci_unregister_driver(&vxge_driver);
4884 kfree(driver_config);
4886 module_init(vxge_starter);
4887 module_exit(vxge_closer);