]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/net/vxge/vxge-main.c
vxge: Fix multicast issues
[net-next-2.6.git] / drivers / net / vxge / vxge-main.c
CommitLineData
703da5a1
RV
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.
9*
10* vxge-main.c: Driver for Neterion Inc's X3100 Series 10GbE PCIe I/O
11* Virtualized Server Adapter.
12* Copyright(c) 2002-2009 Neterion Inc.
13*
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.
22*
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
28*
29* max_config_port:
30* Maximum number of port to be supported.
31* MIN -1 and MAX - 2
32*
33* max_config_vpath:
34* This configures the maximum no of VPATH configures for each
35* device function.
36* MIN - 1 and MAX - 17
37*
38* max_config_dev:
39* This configures maximum no of Device function to be enabled.
40* MIN - 1 and MAX - 17
41*
42******************************************************************************/
43
44#include <linux/if_vlan.h>
45#include <linux/pci.h>
5a0e3ad6 46#include <linux/slab.h>
2b05e002 47#include <linux/tcp.h>
703da5a1
RV
48#include <net/ip.h>
49#include <linux/netdevice.h>
50#include <linux/etherdevice.h>
51#include "vxge-main.h"
52#include "vxge-reg.h"
53
54MODULE_LICENSE("Dual BSD/GPL");
55MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
56 "Virtualized Server Adapter");
57
a3aa1884 58static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = {
703da5a1
RV
59 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
60 PCI_ANY_ID},
61 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
62 PCI_ANY_ID},
63 {0}
64};
65
66MODULE_DEVICE_TABLE(pci, vxge_id_table);
67
68VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
69VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
70VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
71VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
72VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
73VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
74
75static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
76 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
77static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
78 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
79module_param_array(bw_percentage, uint, NULL, 0);
80
81static struct vxge_drv_config *driver_config;
82
83static inline int is_vxge_card_up(struct vxgedev *vdev)
84{
85 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
86}
87
88static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
89{
90 unsigned long flags = 0;
ff67df55
BL
91 struct sk_buff **skb_ptr = NULL;
92 struct sk_buff **temp;
93#define NR_SKB_COMPLETED 128
94 struct sk_buff *completed[NR_SKB_COMPLETED];
95 int more;
703da5a1 96
ff67df55
BL
97 do {
98 more = 0;
99 skb_ptr = completed;
100
101 if (spin_trylock_irqsave(&fifo->tx_lock, flags)) {
102 vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
103 NR_SKB_COMPLETED, &more);
104 spin_unlock_irqrestore(&fifo->tx_lock, flags);
105 }
106 /* free SKBs */
107 for (temp = completed; temp != skb_ptr; temp++)
108 dev_kfree_skb_irq(*temp);
109 } while (more) ;
703da5a1
RV
110}
111
112static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
113{
114 int i;
115
116 /* Complete all transmits */
117 for (i = 0; i < vdev->no_of_vpath; i++)
118 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
119}
120
121static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
122{
123 int i;
124 struct vxge_ring *ring;
125
126 /* Complete all receives*/
127 for (i = 0; i < vdev->no_of_vpath; i++) {
128 ring = &vdev->vpaths[i].ring;
129 vxge_hw_vpath_poll_rx(ring->handle);
130 }
131}
132
133/*
134 * MultiQ manipulation helper functions
135 */
d03848e0 136static inline int vxge_netif_queue_stopped(struct vxge_fifo *fifo)
703da5a1 137{
d03848e0
JM
138 struct net_device *dev = fifo->ndev;
139 struct netdev_queue *txq = NULL;
140 int vpath_no = fifo->driver_id;
141 int ret = 0;
703da5a1 142
d03848e0
JM
143 if (fifo->tx_steering_type)
144 txq = netdev_get_tx_queue(dev, vpath_no);
145 else
146 txq = netdev_get_tx_queue(dev, 0);
147
148 ret = netif_tx_queue_stopped(txq);
149 return ret;
703da5a1
RV
150}
151
152void vxge_stop_tx_queue(struct vxge_fifo *fifo)
153{
154 struct net_device *dev = fifo->ndev;
703da5a1 155 struct netdev_queue *txq = NULL;
d03848e0
JM
156
157 if (fifo->tx_steering_type)
703da5a1 158 txq = netdev_get_tx_queue(dev, fifo->driver_id);
d03848e0 159 else
703da5a1 160 txq = netdev_get_tx_queue(dev, 0);
703da5a1
RV
161
162 netif_tx_stop_queue(txq);
163}
164
d03848e0 165void vxge_wake_tx_queue(struct vxge_fifo *fifo)
703da5a1
RV
166{
167 struct net_device *dev = fifo->ndev;
703da5a1 168 struct netdev_queue *txq = NULL;
d03848e0
JM
169 int vpath_no = fifo->driver_id;
170
171 if (fifo->tx_steering_type)
703da5a1 172 txq = netdev_get_tx_queue(dev, vpath_no);
d03848e0 173 else
703da5a1 174 txq = netdev_get_tx_queue(dev, 0);
d03848e0
JM
175
176 if (netif_tx_queue_stopped(txq))
177 netif_tx_wake_queue(txq);
703da5a1
RV
178}
179
180/*
181 * vxge_callback_link_up
182 *
183 * This function is called during interrupt context to notify link up state
184 * change.
185 */
186void
187vxge_callback_link_up(struct __vxge_hw_device *hldev)
188{
189 struct net_device *dev = hldev->ndev;
190 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
191
192 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
193 vdev->ndev->name, __func__, __LINE__);
194 printk(KERN_NOTICE "%s: Link Up\n", vdev->ndev->name);
195 vdev->stats.link_up++;
196
197 netif_carrier_on(vdev->ndev);
d03848e0 198 netif_tx_wake_all_queues(vdev->ndev);
703da5a1
RV
199
200 vxge_debug_entryexit(VXGE_TRACE,
201 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
202}
203
204/*
205 * vxge_callback_link_down
206 *
207 * This function is called during interrupt context to notify link down state
208 * change.
209 */
210void
211vxge_callback_link_down(struct __vxge_hw_device *hldev)
212{
213 struct net_device *dev = hldev->ndev;
214 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
215
216 vxge_debug_entryexit(VXGE_TRACE,
217 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
218 printk(KERN_NOTICE "%s: Link Down\n", vdev->ndev->name);
219
220 vdev->stats.link_down++;
221 netif_carrier_off(vdev->ndev);
d03848e0 222 netif_tx_stop_all_queues(vdev->ndev);
703da5a1
RV
223
224 vxge_debug_entryexit(VXGE_TRACE,
225 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
226}
227
228/*
229 * vxge_rx_alloc
230 *
231 * Allocate SKB.
232 */
233static struct sk_buff*
234vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
235{
236 struct net_device *dev;
237 struct sk_buff *skb;
238 struct vxge_rx_priv *rx_priv;
239
240 dev = ring->ndev;
241 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
242 ring->ndev->name, __func__, __LINE__);
243
244 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
245
246 /* try to allocate skb first. this one may fail */
247 skb = netdev_alloc_skb(dev, skb_size +
248 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
249 if (skb == NULL) {
250 vxge_debug_mem(VXGE_ERR,
251 "%s: out of memory to allocate SKB", dev->name);
252 ring->stats.skb_alloc_fail++;
253 return NULL;
254 }
255
256 vxge_debug_mem(VXGE_TRACE,
257 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
258 __func__, __LINE__, skb);
259
260 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
261
262 rx_priv->skb = skb;
ea11bbe0 263 rx_priv->skb_data = NULL;
703da5a1
RV
264 rx_priv->data_size = skb_size;
265 vxge_debug_entryexit(VXGE_TRACE,
266 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
267
268 return skb;
269}
270
271/*
272 * vxge_rx_map
273 */
274static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
275{
276 struct vxge_rx_priv *rx_priv;
277 dma_addr_t dma_addr;
278
279 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
280 ring->ndev->name, __func__, __LINE__);
281 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
282
ea11bbe0
BL
283 rx_priv->skb_data = rx_priv->skb->data;
284 dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
703da5a1
RV
285 rx_priv->data_size, PCI_DMA_FROMDEVICE);
286
fa15e99b 287 if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
703da5a1
RV
288 ring->stats.pci_map_fail++;
289 return -EIO;
290 }
291 vxge_debug_mem(VXGE_TRACE,
292 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
293 ring->ndev->name, __func__, __LINE__,
294 (unsigned long long)dma_addr);
295 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
296
297 rx_priv->data_dma = dma_addr;
298 vxge_debug_entryexit(VXGE_TRACE,
299 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
300
301 return 0;
302}
303
304/*
305 * vxge_rx_initial_replenish
306 * Allocation of RxD as an initial replenish procedure.
307 */
308static enum vxge_hw_status
309vxge_rx_initial_replenish(void *dtrh, void *userdata)
310{
311 struct vxge_ring *ring = (struct vxge_ring *)userdata;
312 struct vxge_rx_priv *rx_priv;
313
314 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
315 ring->ndev->name, __func__, __LINE__);
316 if (vxge_rx_alloc(dtrh, ring,
317 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
318 return VXGE_HW_FAIL;
319
320 if (vxge_rx_map(dtrh, ring)) {
321 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
322 dev_kfree_skb(rx_priv->skb);
323
324 return VXGE_HW_FAIL;
325 }
326 vxge_debug_entryexit(VXGE_TRACE,
327 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
328
329 return VXGE_HW_OK;
330}
331
332static inline void
333vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
334 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
335{
336
337 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
338 ring->ndev->name, __func__, __LINE__);
339 skb_record_rx_queue(skb, ring->driver_id);
340 skb->protocol = eth_type_trans(skb, ring->ndev);
341
342 ring->stats.rx_frms++;
343 ring->stats.rx_bytes += pkt_length;
344
345 if (skb->pkt_type == PACKET_MULTICAST)
346 ring->stats.rx_mcast++;
347
348 vxge_debug_rx(VXGE_TRACE,
349 "%s: %s:%d skb protocol = %d",
350 ring->ndev->name, __func__, __LINE__, skb->protocol);
351
352 if (ring->gro_enable) {
353 if (ring->vlgrp && ext_info->vlan &&
354 (ring->vlan_tag_strip ==
355 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
a5d165b5 356 vlan_gro_receive(ring->napi_p, ring->vlgrp,
703da5a1
RV
357 ext_info->vlan, skb);
358 else
a5d165b5 359 napi_gro_receive(ring->napi_p, skb);
703da5a1
RV
360 } else {
361 if (ring->vlgrp && vlan &&
362 (ring->vlan_tag_strip ==
363 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
364 vlan_hwaccel_receive_skb(skb, ring->vlgrp, vlan);
365 else
366 netif_receive_skb(skb);
367 }
368 vxge_debug_entryexit(VXGE_TRACE,
369 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
370}
371
372static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
373 struct vxge_rx_priv *rx_priv)
374{
375 pci_dma_sync_single_for_device(ring->pdev,
376 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
377
378 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
379 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
380}
381
382static inline void vxge_post(int *dtr_cnt, void **first_dtr,
383 void *post_dtr, struct __vxge_hw_ring *ringh)
384{
385 int dtr_count = *dtr_cnt;
386 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
387 if (*first_dtr)
388 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
389 *first_dtr = post_dtr;
390 } else
391 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
392 dtr_count++;
393 *dtr_cnt = dtr_count;
394}
395
396/*
397 * vxge_rx_1b_compl
398 *
399 * If the interrupt is because of a received frame or if the receive ring
400 * contains fresh as yet un-processed frames, this function is called.
401 */
402enum vxge_hw_status
403vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
404 u8 t_code, void *userdata)
405{
406 struct vxge_ring *ring = (struct vxge_ring *)userdata;
407 struct net_device *dev = ring->ndev;
408 unsigned int dma_sizes;
409 void *first_dtr = NULL;
410 int dtr_cnt = 0;
411 int data_size;
412 dma_addr_t data_dma;
413 int pkt_length;
414 struct sk_buff *skb;
415 struct vxge_rx_priv *rx_priv;
416 struct vxge_hw_ring_rxd_info ext_info;
417 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
418 ring->ndev->name, __func__, __LINE__);
419 ring->pkts_processed = 0;
420
3363276f 421 vxge_hw_ring_replenish(ringh);
703da5a1
RV
422
423 do {
3f23e436 424 prefetch((char *)dtr + L1_CACHE_BYTES);
703da5a1
RV
425 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
426 skb = rx_priv->skb;
427 data_size = rx_priv->data_size;
428 data_dma = rx_priv->data_dma;
ea11bbe0 429 prefetch(rx_priv->skb_data);
703da5a1
RV
430
431 vxge_debug_rx(VXGE_TRACE,
432 "%s: %s:%d skb = 0x%p",
433 ring->ndev->name, __func__, __LINE__, skb);
434
435 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
436 pkt_length = dma_sizes;
437
22fa125e
SH
438 pkt_length -= ETH_FCS_LEN;
439
703da5a1
RV
440 vxge_debug_rx(VXGE_TRACE,
441 "%s: %s:%d Packet Length = %d",
442 ring->ndev->name, __func__, __LINE__, pkt_length);
443
444 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
445
446 /* check skb validity */
447 vxge_assert(skb);
448
449 prefetch((char *)skb + L1_CACHE_BYTES);
450 if (unlikely(t_code)) {
451
452 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
453 VXGE_HW_OK) {
454
455 ring->stats.rx_errors++;
456 vxge_debug_rx(VXGE_TRACE,
457 "%s: %s :%d Rx T_code is %d",
458 ring->ndev->name, __func__,
459 __LINE__, t_code);
460
461 /* If the t_code is not supported and if the
462 * t_code is other than 0x5 (unparseable packet
463 * such as unknown UPV6 header), Drop it !!!
464 */
465 vxge_re_pre_post(dtr, ring, rx_priv);
466
467 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
468 ring->stats.rx_dropped++;
469 continue;
470 }
471 }
472
473 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
474
475 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
476
477 if (!vxge_rx_map(dtr, ring)) {
478 skb_put(skb, pkt_length);
479
480 pci_unmap_single(ring->pdev, data_dma,
481 data_size, PCI_DMA_FROMDEVICE);
482
483 vxge_hw_ring_rxd_pre_post(ringh, dtr);
484 vxge_post(&dtr_cnt, &first_dtr, dtr,
485 ringh);
486 } else {
487 dev_kfree_skb(rx_priv->skb);
488 rx_priv->skb = skb;
489 rx_priv->data_size = data_size;
490 vxge_re_pre_post(dtr, ring, rx_priv);
491
492 vxge_post(&dtr_cnt, &first_dtr, dtr,
493 ringh);
494 ring->stats.rx_dropped++;
495 break;
496 }
497 } else {
498 vxge_re_pre_post(dtr, ring, rx_priv);
499
500 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
501 ring->stats.rx_dropped++;
502 break;
503 }
504 } else {
505 struct sk_buff *skb_up;
506
507 skb_up = netdev_alloc_skb(dev, pkt_length +
508 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
509 if (skb_up != NULL) {
510 skb_reserve(skb_up,
511 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
512
513 pci_dma_sync_single_for_cpu(ring->pdev,
514 data_dma, data_size,
515 PCI_DMA_FROMDEVICE);
516
517 vxge_debug_mem(VXGE_TRACE,
518 "%s: %s:%d skb_up = %p",
519 ring->ndev->name, __func__,
520 __LINE__, skb);
521 memcpy(skb_up->data, skb->data, pkt_length);
522
523 vxge_re_pre_post(dtr, ring, rx_priv);
524
525 vxge_post(&dtr_cnt, &first_dtr, dtr,
526 ringh);
527 /* will netif_rx small SKB instead */
528 skb = skb_up;
529 skb_put(skb, pkt_length);
530 } else {
531 vxge_re_pre_post(dtr, ring, rx_priv);
532
533 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
534 vxge_debug_rx(VXGE_ERR,
535 "%s: vxge_rx_1b_compl: out of "
536 "memory", dev->name);
537 ring->stats.skb_alloc_fail++;
538 break;
539 }
540 }
541
542 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
543 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
544 ring->rx_csum && /* Offload Rx side CSUM */
545 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
546 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
547 skb->ip_summed = CHECKSUM_UNNECESSARY;
548 else
549 skb->ip_summed = CHECKSUM_NONE;
550
551 vxge_rx_complete(ring, skb, ext_info.vlan,
552 pkt_length, &ext_info);
553
554 ring->budget--;
555 ring->pkts_processed++;
556 if (!ring->budget)
557 break;
558
559 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
560 &t_code) == VXGE_HW_OK);
561
562 if (first_dtr)
563 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
564
703da5a1
RV
565 vxge_debug_entryexit(VXGE_TRACE,
566 "%s:%d Exiting...",
567 __func__, __LINE__);
568 return VXGE_HW_OK;
569}
570
571/*
572 * vxge_xmit_compl
573 *
574 * If an interrupt was raised to indicate DMA complete of the Tx packet,
575 * this function is called. It identifies the last TxD whose buffer was
576 * freed and frees all skbs whose data have already DMA'ed into the NICs
577 * internal memory.
578 */
579enum vxge_hw_status
580vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
581 enum vxge_hw_fifo_tcode t_code, void *userdata,
ff67df55 582 struct sk_buff ***skb_ptr, int nr_skb, int *more)
703da5a1
RV
583{
584 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
ff67df55 585 struct sk_buff *skb, **done_skb = *skb_ptr;
703da5a1
RV
586 int pkt_cnt = 0;
587
588 vxge_debug_entryexit(VXGE_TRACE,
589 "%s:%d Entered....", __func__, __LINE__);
590
591 do {
592 int frg_cnt;
593 skb_frag_t *frag;
594 int i = 0, j;
595 struct vxge_tx_priv *txd_priv =
596 vxge_hw_fifo_txdl_private_get(dtr);
597
598 skb = txd_priv->skb;
599 frg_cnt = skb_shinfo(skb)->nr_frags;
600 frag = &skb_shinfo(skb)->frags[0];
601
602 vxge_debug_tx(VXGE_TRACE,
603 "%s: %s:%d fifo_hw = %p dtr = %p "
604 "tcode = 0x%x", fifo->ndev->name, __func__,
605 __LINE__, fifo_hw, dtr, t_code);
606 /* check skb validity */
607 vxge_assert(skb);
608 vxge_debug_tx(VXGE_TRACE,
609 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
610 fifo->ndev->name, __func__, __LINE__,
611 skb, txd_priv, frg_cnt);
612 if (unlikely(t_code)) {
613 fifo->stats.tx_errors++;
614 vxge_debug_tx(VXGE_ERR,
615 "%s: tx: dtr %p completed due to "
616 "error t_code %01x", fifo->ndev->name,
617 dtr, t_code);
618 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
619 }
620
621 /* for unfragmented skb */
622 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
623 skb_headlen(skb), PCI_DMA_TODEVICE);
624
625 for (j = 0; j < frg_cnt; j++) {
626 pci_unmap_page(fifo->pdev,
627 txd_priv->dma_buffers[i++],
628 frag->size, PCI_DMA_TODEVICE);
629 frag += 1;
630 }
631
632 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
633
634 /* Updating the statistics block */
635 fifo->stats.tx_frms++;
636 fifo->stats.tx_bytes += skb->len;
637
ff67df55
BL
638 *done_skb++ = skb;
639
640 if (--nr_skb <= 0) {
641 *more = 1;
642 break;
643 }
703da5a1
RV
644
645 pkt_cnt++;
646 if (pkt_cnt > fifo->indicate_max_pkts)
647 break;
648
649 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
650 &dtr, &t_code) == VXGE_HW_OK);
651
ff67df55 652 *skb_ptr = done_skb;
d03848e0 653 vxge_wake_tx_queue(fifo);
703da5a1 654
703da5a1
RV
655 vxge_debug_entryexit(VXGE_TRACE,
656 "%s: %s:%d Exiting...",
657 fifo->ndev->name, __func__, __LINE__);
658 return VXGE_HW_OK;
659}
660
28679751 661/* select a vpath to transmit the packet */
703da5a1
RV
662static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb,
663 int *do_lock)
664{
665 u16 queue_len, counter = 0;
666 if (skb->protocol == htons(ETH_P_IP)) {
667 struct iphdr *ip;
668 struct tcphdr *th;
669
670 ip = ip_hdr(skb);
671
672 if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) {
673 th = (struct tcphdr *)(((unsigned char *)ip) +
674 ip->ihl*4);
675
676 queue_len = vdev->no_of_vpath;
677 counter = (ntohs(th->source) +
678 ntohs(th->dest)) &
679 vdev->vpath_selector[queue_len - 1];
680 if (counter >= queue_len)
681 counter = queue_len - 1;
682
683 if (ip->protocol == IPPROTO_UDP) {
684#ifdef NETIF_F_LLTX
685 *do_lock = 0;
686#endif
687 }
688 }
689 }
690 return counter;
691}
692
693static enum vxge_hw_status vxge_search_mac_addr_in_list(
694 struct vxge_vpath *vpath, u64 del_mac)
695{
696 struct list_head *entry, *next;
697 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
698 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
699 return TRUE;
700 }
701 return FALSE;
702}
703
704static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
705{
706 struct macInfo mac_info;
707 u8 *mac_address = NULL;
708 u64 mac_addr = 0, vpath_vector = 0;
709 int vpath_idx = 0;
710 enum vxge_hw_status status = VXGE_HW_OK;
711 struct vxge_vpath *vpath = NULL;
712 struct __vxge_hw_device *hldev;
713
714 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
715
716 mac_address = (u8 *)&mac_addr;
717 memcpy(mac_address, mac_header, ETH_ALEN);
718
719 /* Is this mac address already in the list? */
720 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
721 vpath = &vdev->vpaths[vpath_idx];
722 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
723 return vpath_idx;
724 }
725
726 memset(&mac_info, 0, sizeof(struct macInfo));
727 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
728
729 /* Any vpath has room to add mac address to its da table? */
730 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
731 vpath = &vdev->vpaths[vpath_idx];
732 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
733 /* Add this mac address to this vpath */
734 mac_info.vpath_no = vpath_idx;
735 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
736 status = vxge_add_mac_addr(vdev, &mac_info);
737 if (status != VXGE_HW_OK)
738 return -EPERM;
739 return vpath_idx;
740 }
741 }
742
743 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
744 vpath_idx = 0;
745 mac_info.vpath_no = vpath_idx;
746 /* Is the first vpath already selected as catch-basin ? */
747 vpath = &vdev->vpaths[vpath_idx];
748 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
749 /* Add this mac address to this vpath */
750 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
751 return -EPERM;
752 return vpath_idx;
753 }
754
755 /* Select first vpath as catch-basin */
756 vpath_vector = vxge_mBIT(vpath->device_id);
757 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
758 vxge_hw_mgmt_reg_type_mrpcim,
759 0,
760 (ulong)offsetof(
761 struct vxge_hw_mrpcim_reg,
762 rts_mgr_cbasin_cfg),
763 vpath_vector);
764 if (status != VXGE_HW_OK) {
765 vxge_debug_tx(VXGE_ERR,
766 "%s: Unable to set the vpath-%d in catch-basin mode",
767 VXGE_DRIVER_NAME, vpath->device_id);
768 return -EPERM;
769 }
770
771 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
772 return -EPERM;
773
774 return vpath_idx;
775}
776
777/**
778 * vxge_xmit
779 * @skb : the socket buffer containing the Tx data.
780 * @dev : device pointer.
781 *
782 * This function is the Tx entry point of the driver. Neterion NIC supports
783 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
784 * NOTE: when device cant queue the pkt, just the trans_start variable will
785 * not be upadted.
786*/
61357325 787static netdev_tx_t
703da5a1
RV
788vxge_xmit(struct sk_buff *skb, struct net_device *dev)
789{
790 struct vxge_fifo *fifo = NULL;
791 void *dtr_priv;
792 void *dtr = NULL;
793 struct vxgedev *vdev = NULL;
794 enum vxge_hw_status status;
795 int frg_cnt, first_frg_len;
796 skb_frag_t *frag;
797 int i = 0, j = 0, avail;
798 u64 dma_pointer;
799 struct vxge_tx_priv *txdl_priv = NULL;
800 struct __vxge_hw_fifo *fifo_hw;
703da5a1
RV
801 int offload_type;
802 unsigned long flags = 0;
803 int vpath_no = 0;
804 int do_spin_tx_lock = 1;
805
806 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
807 dev->name, __func__, __LINE__);
808
809 /* A buffer with no data will be dropped */
810 if (unlikely(skb->len <= 0)) {
811 vxge_debug_tx(VXGE_ERR,
812 "%s: Buffer has no data..", dev->name);
813 dev_kfree_skb(skb);
814 return NETDEV_TX_OK;
815 }
816
817 vdev = (struct vxgedev *)netdev_priv(dev);
818
819 if (unlikely(!is_vxge_card_up(vdev))) {
820 vxge_debug_tx(VXGE_ERR,
821 "%s: vdev not initialized", dev->name);
822 dev_kfree_skb(skb);
823 return NETDEV_TX_OK;
824 }
825
826 if (vdev->config.addr_learn_en) {
827 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
828 if (vpath_no == -EPERM) {
829 vxge_debug_tx(VXGE_ERR,
830 "%s: Failed to store the mac address",
831 dev->name);
832 dev_kfree_skb(skb);
833 return NETDEV_TX_OK;
834 }
835 }
836
837 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
838 vpath_no = skb_get_queue_mapping(skb);
839 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
840 vpath_no = vxge_get_vpath_no(vdev, skb, &do_spin_tx_lock);
841
842 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
843
844 if (vpath_no >= vdev->no_of_vpath)
845 vpath_no = 0;
846
847 fifo = &vdev->vpaths[vpath_no].fifo;
848 fifo_hw = fifo->handle;
849
850 if (do_spin_tx_lock)
851 spin_lock_irqsave(&fifo->tx_lock, flags);
852 else {
853 if (unlikely(!spin_trylock_irqsave(&fifo->tx_lock, flags)))
854 return NETDEV_TX_LOCKED;
855 }
856
d03848e0
JM
857 if (vxge_netif_queue_stopped(fifo)) {
858 spin_unlock_irqrestore(&fifo->tx_lock, flags);
859 return NETDEV_TX_BUSY;
703da5a1 860 }
d03848e0 861
703da5a1
RV
862 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
863 if (avail == 0) {
864 vxge_debug_tx(VXGE_ERR,
865 "%s: No free TXDs available", dev->name);
866 fifo->stats.txd_not_free++;
867 vxge_stop_tx_queue(fifo);
868 goto _exit2;
869 }
870
4403b371
BL
871 /* Last TXD? Stop tx queue to avoid dropping packets. TX
872 * completion will resume the queue.
873 */
874 if (avail == 1)
875 vxge_stop_tx_queue(fifo);
876
703da5a1
RV
877 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
878 if (unlikely(status != VXGE_HW_OK)) {
879 vxge_debug_tx(VXGE_ERR,
880 "%s: Out of descriptors .", dev->name);
881 fifo->stats.txd_out_of_desc++;
882 vxge_stop_tx_queue(fifo);
883 goto _exit2;
884 }
885
886 vxge_debug_tx(VXGE_TRACE,
887 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
888 dev->name, __func__, __LINE__,
889 fifo_hw, dtr, dtr_priv);
890
891 if (vdev->vlgrp && vlan_tx_tag_present(skb)) {
892 u16 vlan_tag = vlan_tx_tag_get(skb);
893 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
894 }
895
896 first_frg_len = skb_headlen(skb);
897
898 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
899 PCI_DMA_TODEVICE);
900
901 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
902 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
903 vxge_stop_tx_queue(fifo);
904 fifo->stats.pci_map_fail++;
905 goto _exit2;
906 }
907
908 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
909 txdl_priv->skb = skb;
910 txdl_priv->dma_buffers[j] = dma_pointer;
911
912 frg_cnt = skb_shinfo(skb)->nr_frags;
913 vxge_debug_tx(VXGE_TRACE,
914 "%s: %s:%d skb = %p txdl_priv = %p "
915 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
916 __func__, __LINE__, skb, txdl_priv,
917 frg_cnt, (unsigned long long)dma_pointer);
918
919 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
920 first_frg_len);
921
922 frag = &skb_shinfo(skb)->frags[0];
923 for (i = 0; i < frg_cnt; i++) {
924 /* ignore 0 length fragment */
925 if (!frag->size)
926 continue;
927
928 dma_pointer =
929 (u64)pci_map_page(fifo->pdev, frag->page,
930 frag->page_offset, frag->size,
931 PCI_DMA_TODEVICE);
932
933 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
934 goto _exit0;
935 vxge_debug_tx(VXGE_TRACE,
936 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
937 dev->name, __func__, __LINE__, i,
938 (unsigned long long)dma_pointer);
939
940 txdl_priv->dma_buffers[j] = dma_pointer;
941 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
942 frag->size);
943 frag += 1;
944 }
945
946 offload_type = vxge_offload_type(skb);
947
948 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
949
950 int mss = vxge_tcp_mss(skb);
951 if (mss) {
703da5a1
RV
952 vxge_debug_tx(VXGE_TRACE,
953 "%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;
961 }
962 }
963
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);
969
970 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
28679751
ED
971#ifdef NETIF_F_LLTX
972 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
973#endif
703da5a1
RV
974 spin_unlock_irqrestore(&fifo->tx_lock, flags);
975
976 VXGE_COMPLETE_VPATH_TX(fifo);
977 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
978 dev->name, __func__, __LINE__);
6ed10654 979 return NETDEV_TX_OK;
703da5a1
RV
980
981_exit0:
982 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
983
984_exit1:
985 j = 0;
986 frag = &skb_shinfo(skb)->frags[0];
987
988 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
989 skb_headlen(skb), PCI_DMA_TODEVICE);
990
991 for (; j < i; j++) {
992 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
993 frag->size, PCI_DMA_TODEVICE);
994 frag += 1;
995 }
996
997 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
998_exit2:
999 dev_kfree_skb(skb);
1000 spin_unlock_irqrestore(&fifo->tx_lock, flags);
1001 VXGE_COMPLETE_VPATH_TX(fifo);
1002
6ed10654 1003 return NETDEV_TX_OK;
703da5a1
RV
1004}
1005
1006/*
1007 * vxge_rx_term
1008 *
1009 * Function will be called by hw function to abort all outstanding receive
1010 * descriptors.
1011 */
1012static void
1013vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1014{
1015 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1016 struct vxge_rx_priv *rx_priv =
1017 vxge_hw_ring_rxd_private_get(dtrh);
1018
1019 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1020 ring->ndev->name, __func__, __LINE__);
1021 if (state != VXGE_HW_RXD_STATE_POSTED)
1022 return;
1023
1024 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1025 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1026
1027 dev_kfree_skb(rx_priv->skb);
ea11bbe0 1028 rx_priv->skb_data = NULL;
703da5a1
RV
1029
1030 vxge_debug_entryexit(VXGE_TRACE,
1031 "%s: %s:%d Exiting...",
1032 ring->ndev->name, __func__, __LINE__);
1033}
1034
1035/*
1036 * vxge_tx_term
1037 *
1038 * Function will be called to abort all outstanding tx descriptors
1039 */
1040static void
1041vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1042{
1043 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1044 skb_frag_t *frag;
1045 int i = 0, j, frg_cnt;
1046 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1047 struct sk_buff *skb = txd_priv->skb;
1048
1049 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1050
1051 if (state != VXGE_HW_TXDL_STATE_POSTED)
1052 return;
1053
1054 /* check skb validity */
1055 vxge_assert(skb);
1056 frg_cnt = skb_shinfo(skb)->nr_frags;
1057 frag = &skb_shinfo(skb)->frags[0];
1058
1059 /* for unfragmented skb */
1060 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1061 skb_headlen(skb), PCI_DMA_TODEVICE);
1062
1063 for (j = 0; j < frg_cnt; j++) {
1064 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
1065 frag->size, PCI_DMA_TODEVICE);
1066 frag += 1;
1067 }
1068
1069 dev_kfree_skb(skb);
1070
1071 vxge_debug_entryexit(VXGE_TRACE,
1072 "%s:%d Exiting...", __func__, __LINE__);
1073}
1074
1075/**
1076 * vxge_set_multicast
1077 * @dev: pointer to the device structure
1078 *
1079 * Entry point for multicast address enable/disable
1080 * This function is a driver entry point which gets called by the kernel
1081 * whenever multicast addresses must be enabled/disabled. This also gets
1082 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1083 * determine, if multicast address must be enabled or if promiscuous mode
1084 * is to be disabled etc.
1085 */
1086static void vxge_set_multicast(struct net_device *dev)
1087{
22bedad3 1088 struct netdev_hw_addr *ha;
703da5a1
RV
1089 struct vxgedev *vdev;
1090 int i, mcast_cnt = 0;
7adf7d1b
JM
1091 struct __vxge_hw_device *hldev;
1092 struct vxge_vpath *vpath;
703da5a1
RV
1093 enum vxge_hw_status status = VXGE_HW_OK;
1094 struct macInfo mac_info;
1095 int vpath_idx = 0;
1096 struct vxge_mac_addrs *mac_entry;
1097 struct list_head *list_head;
1098 struct list_head *entry, *next;
1099 u8 *mac_address = NULL;
1100
1101 vxge_debug_entryexit(VXGE_TRACE,
1102 "%s:%d", __func__, __LINE__);
1103
1104 vdev = (struct vxgedev *)netdev_priv(dev);
1105 hldev = (struct __vxge_hw_device *)vdev->devh;
1106
1107 if (unlikely(!is_vxge_card_up(vdev)))
1108 return;
1109
1110 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1111 for (i = 0; i < vdev->no_of_vpath; i++) {
7adf7d1b
JM
1112 vpath = &vdev->vpaths[i];
1113 vxge_assert(vpath->is_open);
1114 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1115 if (status != VXGE_HW_OK)
1116 vxge_debug_init(VXGE_ERR, "failed to enable "
1117 "multicast, status %d", status);
703da5a1
RV
1118 vdev->all_multi_flg = 1;
1119 }
7adf7d1b 1120 } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
703da5a1 1121 for (i = 0; i < vdev->no_of_vpath; i++) {
7adf7d1b
JM
1122 vpath = &vdev->vpaths[i];
1123 vxge_assert(vpath->is_open);
1124 status = vxge_hw_vpath_mcast_disable(vpath->handle);
1125 if (status != VXGE_HW_OK)
1126 vxge_debug_init(VXGE_ERR, "failed to disable "
1127 "multicast, status %d", status);
1128 vdev->all_multi_flg = 0;
703da5a1
RV
1129 }
1130 }
1131
703da5a1
RV
1132
1133 if (!vdev->config.addr_learn_en) {
7adf7d1b
JM
1134 for (i = 0; i < vdev->no_of_vpath; i++) {
1135 vpath = &vdev->vpaths[i];
1136 vxge_assert(vpath->is_open);
1137
1138 if (dev->flags & IFF_PROMISC)
703da5a1 1139 status = vxge_hw_vpath_promisc_enable(
7adf7d1b
JM
1140 vpath->handle);
1141 else
703da5a1 1142 status = vxge_hw_vpath_promisc_disable(
7adf7d1b
JM
1143 vpath->handle);
1144 if (status != VXGE_HW_OK)
1145 vxge_debug_init(VXGE_ERR, "failed to %s promisc"
1146 ", status %d", dev->flags&IFF_PROMISC ?
1147 "enable" : "disable", status);
703da5a1
RV
1148 }
1149 }
1150
1151 memset(&mac_info, 0, sizeof(struct macInfo));
1152 /* Update individual M_CAST address list */
4cd24eaf 1153 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
703da5a1
RV
1154 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1155 list_head = &vdev->vpaths[0].mac_addr_list;
4cd24eaf 1156 if ((netdev_mc_count(dev) +
703da5a1
RV
1157 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1158 vdev->vpaths[0].max_mac_addr_cnt)
1159 goto _set_all_mcast;
1160
1161 /* Delete previous MC's */
1162 for (i = 0; i < mcast_cnt; i++) {
703da5a1 1163 list_for_each_safe(entry, next, list_head) {
703da5a1
RV
1164 mac_entry = (struct vxge_mac_addrs *) entry;
1165 /* Copy the mac address to delete */
1166 mac_address = (u8 *)&mac_entry->macaddr;
1167 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1168
1169 /* Is this a multicast address */
1170 if (0x01 & mac_info.macaddr[0]) {
1171 for (vpath_idx = 0; vpath_idx <
1172 vdev->no_of_vpath;
1173 vpath_idx++) {
1174 mac_info.vpath_no = vpath_idx;
1175 status = vxge_del_mac_addr(
1176 vdev,
1177 &mac_info);
1178 }
1179 }
1180 }
1181 }
1182
1183 /* Add new ones */
22bedad3
JP
1184 netdev_for_each_mc_addr(ha, dev) {
1185 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
703da5a1
RV
1186 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1187 vpath_idx++) {
1188 mac_info.vpath_no = vpath_idx;
1189 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1190 status = vxge_add_mac_addr(vdev, &mac_info);
1191 if (status != VXGE_HW_OK) {
1192 vxge_debug_init(VXGE_ERR,
1193 "%s:%d Setting individual"
1194 "multicast address failed",
1195 __func__, __LINE__);
1196 goto _set_all_mcast;
1197 }
1198 }
1199 }
1200
1201 return;
1202_set_all_mcast:
1203 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1204 /* Delete previous MC's */
1205 for (i = 0; i < mcast_cnt; i++) {
703da5a1 1206 list_for_each_safe(entry, next, list_head) {
703da5a1
RV
1207 mac_entry = (struct vxge_mac_addrs *) entry;
1208 /* Copy the mac address to delete */
1209 mac_address = (u8 *)&mac_entry->macaddr;
1210 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1211
1212 /* Is this a multicast address */
1213 if (0x01 & mac_info.macaddr[0])
1214 break;
1215 }
1216
1217 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1218 vpath_idx++) {
1219 mac_info.vpath_no = vpath_idx;
1220 status = vxge_del_mac_addr(vdev, &mac_info);
1221 }
1222 }
1223
1224 /* Enable all multicast */
1225 for (i = 0; i < vdev->no_of_vpath; i++) {
7adf7d1b
JM
1226 vpath = &vdev->vpaths[i];
1227 vxge_assert(vpath->is_open);
1228
1229 status = vxge_hw_vpath_mcast_enable(vpath->handle);
703da5a1
RV
1230 if (status != VXGE_HW_OK) {
1231 vxge_debug_init(VXGE_ERR,
1232 "%s:%d Enabling all multicasts failed",
1233 __func__, __LINE__);
1234 }
1235 vdev->all_multi_flg = 1;
1236 }
1237 dev->flags |= IFF_ALLMULTI;
1238 }
1239
1240 vxge_debug_entryexit(VXGE_TRACE,
1241 "%s:%d Exiting...", __func__, __LINE__);
1242}
1243
1244/**
1245 * vxge_set_mac_addr
1246 * @dev: pointer to the device structure
1247 *
1248 * Update entry "0" (default MAC addr)
1249 */
1250static int vxge_set_mac_addr(struct net_device *dev, void *p)
1251{
1252 struct sockaddr *addr = p;
1253 struct vxgedev *vdev;
1254 struct __vxge_hw_device *hldev;
1255 enum vxge_hw_status status = VXGE_HW_OK;
1256 struct macInfo mac_info_new, mac_info_old;
1257 int vpath_idx = 0;
1258
1259 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1260
1261 vdev = (struct vxgedev *)netdev_priv(dev);
1262 hldev = vdev->devh;
1263
1264 if (!is_valid_ether_addr(addr->sa_data))
1265 return -EINVAL;
1266
1267 memset(&mac_info_new, 0, sizeof(struct macInfo));
1268 memset(&mac_info_old, 0, sizeof(struct macInfo));
1269
1270 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1271 __func__, __LINE__);
1272
1273 /* Get the old address */
1274 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1275
1276 /* Copy the new address */
1277 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1278
1279 /* First delete the old mac address from all the vpaths
1280 as we can't specify the index while adding new mac address */
1281 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1282 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1283 if (!vpath->is_open) {
1284 /* This can happen when this interface is added/removed
1285 to the bonding interface. Delete this station address
1286 from the linked list */
1287 vxge_mac_list_del(vpath, &mac_info_old);
1288
1289 /* Add this new address to the linked list
1290 for later restoring */
1291 vxge_mac_list_add(vpath, &mac_info_new);
1292
1293 continue;
1294 }
1295 /* Delete the station address */
1296 mac_info_old.vpath_no = vpath_idx;
1297 status = vxge_del_mac_addr(vdev, &mac_info_old);
1298 }
1299
1300 if (unlikely(!is_vxge_card_up(vdev))) {
1301 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1302 return VXGE_HW_OK;
1303 }
1304
1305 /* Set this mac address to all the vpaths */
1306 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1307 mac_info_new.vpath_no = vpath_idx;
1308 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1309 status = vxge_add_mac_addr(vdev, &mac_info_new);
1310 if (status != VXGE_HW_OK)
1311 return -EINVAL;
1312 }
1313
1314 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1315
1316 return status;
1317}
1318
1319/*
1320 * vxge_vpath_intr_enable
1321 * @vdev: pointer to vdev
1322 * @vp_id: vpath for which to enable the interrupts
1323 *
1324 * Enables the interrupts for the vpath
1325*/
1326void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
1327{
1328 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
b59c9457
SH
1329 int msix_id = 0;
1330 int tim_msix_id[4] = {0, 1, 0, 0};
1331 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
703da5a1
RV
1332
1333 vxge_hw_vpath_intr_enable(vpath->handle);
1334
1335 if (vdev->config.intr_type == INTA)
1336 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1337 else {
703da5a1
RV
1338 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1339 alarm_msix_id);
1340
b59c9457 1341 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
703da5a1
RV
1342 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1343 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1344
1345 /* enable the alarm vector */
b59c9457
SH
1346 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1347 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1348 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
703da5a1
RV
1349 }
1350}
1351
1352/*
1353 * vxge_vpath_intr_disable
1354 * @vdev: pointer to vdev
1355 * @vp_id: vpath for which to disable the interrupts
1356 *
1357 * Disables the interrupts for the vpath
1358*/
1359void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
1360{
1361 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1362 int msix_id;
1363
1364 vxge_hw_vpath_intr_disable(vpath->handle);
1365
1366 if (vdev->config.intr_type == INTA)
1367 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1368 else {
b59c9457 1369 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
703da5a1
RV
1370 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1371 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1372
1373 /* disable the alarm vector */
b59c9457
SH
1374 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1375 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
703da5a1
RV
1376 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1377 }
1378}
1379
1380/*
1381 * vxge_reset_vpath
1382 * @vdev: pointer to vdev
1383 * @vp_id: vpath to reset
1384 *
1385 * Resets the vpath
1386*/
1387static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1388{
1389 enum vxge_hw_status status = VXGE_HW_OK;
7adf7d1b 1390 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
703da5a1
RV
1391 int ret = 0;
1392
1393 /* check if device is down already */
1394 if (unlikely(!is_vxge_card_up(vdev)))
1395 return 0;
1396
1397 /* is device reset already scheduled */
1398 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1399 return 0;
1400
7adf7d1b
JM
1401 if (vpath->handle) {
1402 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
703da5a1 1403 if (is_vxge_card_up(vdev) &&
7adf7d1b 1404 vxge_hw_vpath_recover_from_reset(vpath->handle)
703da5a1
RV
1405 != VXGE_HW_OK) {
1406 vxge_debug_init(VXGE_ERR,
1407 "vxge_hw_vpath_recover_from_reset"
1408 "failed for vpath:%d", vp_id);
1409 return status;
1410 }
1411 } else {
1412 vxge_debug_init(VXGE_ERR,
1413 "vxge_hw_vpath_reset failed for"
1414 "vpath:%d", vp_id);
1415 return status;
1416 }
1417 } else
1418 return VXGE_HW_FAIL;
1419
7adf7d1b
JM
1420 vxge_restore_vpath_mac_addr(vpath);
1421 vxge_restore_vpath_vid_table(vpath);
703da5a1
RV
1422
1423 /* Enable all broadcast */
7adf7d1b
JM
1424 vxge_hw_vpath_bcast_enable(vpath->handle);
1425
1426 /* Enable all multicast */
1427 if (vdev->all_multi_flg) {
1428 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1429 if (status != VXGE_HW_OK)
1430 vxge_debug_init(VXGE_ERR,
1431 "%s:%d Enabling multicast failed",
1432 __func__, __LINE__);
1433 }
703da5a1
RV
1434
1435 /* Enable the interrupts */
1436 vxge_vpath_intr_enable(vdev, vp_id);
1437
1438 smp_wmb();
1439
1440 /* Enable the flow of traffic through the vpath */
7adf7d1b 1441 vxge_hw_vpath_enable(vpath->handle);
703da5a1
RV
1442
1443 smp_wmb();
7adf7d1b
JM
1444 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
1445 vpath->ring.last_status = VXGE_HW_OK;
703da5a1
RV
1446
1447 /* Vpath reset done */
1448 clear_bit(vp_id, &vdev->vp_reset);
1449
1450 /* Start the vpath queue */
7adf7d1b 1451 vxge_wake_tx_queue(&vpath->fifo);
703da5a1
RV
1452
1453 return ret;
1454}
1455
1456static int do_vxge_reset(struct vxgedev *vdev, int event)
1457{
1458 enum vxge_hw_status status;
1459 int ret = 0, vp_id, i;
1460
1461 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1462
1463 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1464 /* check if device is down already */
1465 if (unlikely(!is_vxge_card_up(vdev)))
1466 return 0;
1467
1468 /* is reset already scheduled */
1469 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1470 return 0;
1471 }
1472
1473 if (event == VXGE_LL_FULL_RESET) {
1474 /* wait for all the vpath reset to complete */
1475 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1476 while (test_bit(vp_id, &vdev->vp_reset))
1477 msleep(50);
1478 }
1479
1480 /* if execution mode is set to debug, don't reset the adapter */
1481 if (unlikely(vdev->exec_mode)) {
1482 vxge_debug_init(VXGE_ERR,
1483 "%s: execution mode is debug, returning..",
1484 vdev->ndev->name);
7adf7d1b
JM
1485 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1486 netif_tx_stop_all_queues(vdev->ndev);
1487 return 0;
703da5a1
RV
1488 }
1489 }
1490
1491 if (event == VXGE_LL_FULL_RESET) {
1492 vxge_hw_device_intr_disable(vdev->devh);
1493
1494 switch (vdev->cric_err_event) {
1495 case VXGE_HW_EVENT_UNKNOWN:
d03848e0 1496 netif_tx_stop_all_queues(vdev->ndev);
703da5a1
RV
1497 vxge_debug_init(VXGE_ERR,
1498 "fatal: %s: Disabling device due to"
1499 "unknown error",
1500 vdev->ndev->name);
1501 ret = -EPERM;
1502 goto out;
1503 case VXGE_HW_EVENT_RESET_START:
1504 break;
1505 case VXGE_HW_EVENT_RESET_COMPLETE:
1506 case VXGE_HW_EVENT_LINK_DOWN:
1507 case VXGE_HW_EVENT_LINK_UP:
1508 case VXGE_HW_EVENT_ALARM_CLEARED:
1509 case VXGE_HW_EVENT_ECCERR:
1510 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1511 ret = -EPERM;
1512 goto out;
1513 case VXGE_HW_EVENT_FIFO_ERR:
1514 case VXGE_HW_EVENT_VPATH_ERR:
1515 break;
1516 case VXGE_HW_EVENT_CRITICAL_ERR:
d03848e0 1517 netif_tx_stop_all_queues(vdev->ndev);
703da5a1
RV
1518 vxge_debug_init(VXGE_ERR,
1519 "fatal: %s: Disabling device due to"
1520 "serious error",
1521 vdev->ndev->name);
1522 /* SOP or device reset required */
1523 /* This event is not currently used */
1524 ret = -EPERM;
1525 goto out;
1526 case VXGE_HW_EVENT_SERR:
d03848e0 1527 netif_tx_stop_all_queues(vdev->ndev);
703da5a1
RV
1528 vxge_debug_init(VXGE_ERR,
1529 "fatal: %s: Disabling device due to"
1530 "serious error",
1531 vdev->ndev->name);
1532 ret = -EPERM;
1533 goto out;
1534 case VXGE_HW_EVENT_SRPCIM_SERR:
1535 case VXGE_HW_EVENT_MRPCIM_SERR:
1536 ret = -EPERM;
1537 goto out;
1538 case VXGE_HW_EVENT_SLOT_FREEZE:
d03848e0 1539 netif_tx_stop_all_queues(vdev->ndev);
703da5a1
RV
1540 vxge_debug_init(VXGE_ERR,
1541 "fatal: %s: Disabling device due to"
1542 "slot freeze",
1543 vdev->ndev->name);
1544 ret = -EPERM;
1545 goto out;
1546 default:
1547 break;
1548
1549 }
1550 }
1551
1552 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
d03848e0 1553 netif_tx_stop_all_queues(vdev->ndev);
703da5a1
RV
1554
1555 if (event == VXGE_LL_FULL_RESET) {
1556 status = vxge_reset_all_vpaths(vdev);
1557 if (status != VXGE_HW_OK) {
1558 vxge_debug_init(VXGE_ERR,
1559 "fatal: %s: can not reset vpaths",
1560 vdev->ndev->name);
1561 ret = -EPERM;
1562 goto out;
1563 }
1564 }
1565
1566 if (event == VXGE_LL_COMPL_RESET) {
1567 for (i = 0; i < vdev->no_of_vpath; i++)
1568 if (vdev->vpaths[i].handle) {
1569 if (vxge_hw_vpath_recover_from_reset(
1570 vdev->vpaths[i].handle)
1571 != VXGE_HW_OK) {
1572 vxge_debug_init(VXGE_ERR,
1573 "vxge_hw_vpath_recover_"
1574 "from_reset failed for vpath: "
1575 "%d", i);
1576 ret = -EPERM;
1577 goto out;
1578 }
1579 } else {
1580 vxge_debug_init(VXGE_ERR,
1581 "vxge_hw_vpath_reset failed for "
1582 "vpath:%d", i);
1583 ret = -EPERM;
1584 goto out;
1585 }
1586 }
1587
1588 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1589 /* Reprogram the DA table with populated mac addresses */
1590 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1591 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1592 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1593 }
1594
1595 /* enable vpath interrupts */
1596 for (i = 0; i < vdev->no_of_vpath; i++)
1597 vxge_vpath_intr_enable(vdev, i);
1598
1599 vxge_hw_device_intr_enable(vdev->devh);
1600
1601 smp_wmb();
1602
1603 /* Indicate card up */
1604 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1605
1606 /* Get the traffic to flow through the vpaths */
1607 for (i = 0; i < vdev->no_of_vpath; i++) {
1608 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1609 smp_wmb();
1610 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1611 }
1612
d03848e0 1613 netif_tx_wake_all_queues(vdev->ndev);
703da5a1
RV
1614 }
1615
1616out:
1617 vxge_debug_entryexit(VXGE_TRACE,
1618 "%s:%d Exiting...", __func__, __LINE__);
1619
1620 /* Indicate reset done */
1621 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1622 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1623 return ret;
1624}
1625
1626/*
1627 * vxge_reset
1628 * @vdev: pointer to ll device
1629 *
1630 * driver may reset the chip on events of serr, eccerr, etc
1631 */
1632int vxge_reset(struct vxgedev *vdev)
1633{
7adf7d1b 1634 return do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
703da5a1
RV
1635}
1636
1637/**
1638 * vxge_poll - Receive handler when Receive Polling is used.
1639 * @dev: pointer to the device structure.
1640 * @budget: Number of packets budgeted to be processed in this iteration.
1641 *
1642 * This function comes into picture only if Receive side is being handled
1643 * through polling (called NAPI in linux). It mostly does what the normal
1644 * Rx interrupt handler does in terms of descriptor and packet processing
1645 * but not in an interrupt context. Also it will process a specified number
1646 * of packets at most in one iteration. This value is passed down by the
1647 * kernel as the function argument 'budget'.
1648 */
1649static int vxge_poll_msix(struct napi_struct *napi, int budget)
1650{
1651 struct vxge_ring *ring =
1652 container_of(napi, struct vxge_ring, napi);
1653 int budget_org = budget;
1654 ring->budget = budget;
1655
1656 vxge_hw_vpath_poll_rx(ring->handle);
1657
1658 if (ring->pkts_processed < budget_org) {
1659 napi_complete(napi);
1660 /* Re enable the Rx interrupts for the vpath */
1661 vxge_hw_channel_msix_unmask(
1662 (struct __vxge_hw_channel *)ring->handle,
1663 ring->rx_vector_no);
1664 }
1665
1666 return ring->pkts_processed;
1667}
1668
1669static int vxge_poll_inta(struct napi_struct *napi, int budget)
1670{
1671 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1672 int pkts_processed = 0;
1673 int i;
1674 int budget_org = budget;
1675 struct vxge_ring *ring;
1676
1677 struct __vxge_hw_device *hldev = (struct __vxge_hw_device *)
1678 pci_get_drvdata(vdev->pdev);
1679
1680 for (i = 0; i < vdev->no_of_vpath; i++) {
1681 ring = &vdev->vpaths[i].ring;
1682 ring->budget = budget;
1683 vxge_hw_vpath_poll_rx(ring->handle);
1684 pkts_processed += ring->pkts_processed;
1685 budget -= ring->pkts_processed;
1686 if (budget <= 0)
1687 break;
1688 }
1689
1690 VXGE_COMPLETE_ALL_TX(vdev);
1691
1692 if (pkts_processed < budget_org) {
1693 napi_complete(napi);
1694 /* Re enable the Rx interrupts for the ring */
1695 vxge_hw_device_unmask_all(hldev);
1696 vxge_hw_device_flush_io(hldev);
1697 }
1698
1699 return pkts_processed;
1700}
1701
1702#ifdef CONFIG_NET_POLL_CONTROLLER
1703/**
1704 * vxge_netpoll - netpoll event handler entry point
1705 * @dev : pointer to the device structure.
1706 * Description:
1707 * This function will be called by upper layer to check for events on the
1708 * interface in situations where interrupts are disabled. It is used for
1709 * specific in-kernel networking tasks, such as remote consoles and kernel
1710 * debugging over the network (example netdump in RedHat).
1711 */
1712static void vxge_netpoll(struct net_device *dev)
1713{
1714 struct __vxge_hw_device *hldev;
1715 struct vxgedev *vdev;
1716
1717 vdev = (struct vxgedev *)netdev_priv(dev);
1718 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
1719
1720 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1721
1722 if (pci_channel_offline(vdev->pdev))
1723 return;
1724
1725 disable_irq(dev->irq);
1726 vxge_hw_device_clear_tx_rx(hldev);
1727
1728 vxge_hw_device_clear_tx_rx(hldev);
1729 VXGE_COMPLETE_ALL_RX(vdev);
1730 VXGE_COMPLETE_ALL_TX(vdev);
1731
1732 enable_irq(dev->irq);
1733
1734 vxge_debug_entryexit(VXGE_TRACE,
1735 "%s:%d Exiting...", __func__, __LINE__);
703da5a1
RV
1736}
1737#endif
1738
1739/* RTH configuration */
1740static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1741{
1742 enum vxge_hw_status status = VXGE_HW_OK;
1743 struct vxge_hw_rth_hash_types hash_types;
1744 u8 itable[256] = {0}; /* indirection table */
1745 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1746 int index;
1747
1748 /*
1749 * Filling
1750 * - itable with bucket numbers
1751 * - mtable with bucket-to-vpath mapping
1752 */
1753 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1754 itable[index] = index;
1755 mtable[index] = index % vdev->no_of_vpath;
1756 }
1757
1758 /* Fill RTH hash types */
1759 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1760 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1761 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1762 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1763 hash_types.hash_type_tcpipv6ex_en =
1764 vdev->config.rth_hash_type_tcpipv6ex;
1765 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1766
1767 /* set indirection table, bucket-to-vpath mapping */
1768 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1769 vdev->no_of_vpath,
1770 mtable, itable,
1771 vdev->config.rth_bkt_sz);
1772 if (status != VXGE_HW_OK) {
1773 vxge_debug_init(VXGE_ERR,
1774 "RTH indirection table configuration failed "
1775 "for vpath:%d", vdev->vpaths[0].device_id);
1776 return status;
1777 }
1778
1779 /*
1780 * Because the itable_set() method uses the active_table field
1781 * for the target virtual path the RTH config should be updated
1782 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1783 * when steering frames.
1784 */
1785 for (index = 0; index < vdev->no_of_vpath; index++) {
1786 status = vxge_hw_vpath_rts_rth_set(
1787 vdev->vpaths[index].handle,
1788 vdev->config.rth_algorithm,
1789 &hash_types,
1790 vdev->config.rth_bkt_sz);
1791
1792 if (status != VXGE_HW_OK) {
1793 vxge_debug_init(VXGE_ERR,
1794 "RTH configuration failed for vpath:%d",
1795 vdev->vpaths[index].device_id);
1796 return status;
1797 }
1798 }
1799
1800 return status;
1801}
1802
1803int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
1804{
1805 struct vxge_mac_addrs *new_mac_entry;
1806 u8 *mac_address = NULL;
1807
1808 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
1809 return TRUE;
1810
1811 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
1812 if (!new_mac_entry) {
1813 vxge_debug_mem(VXGE_ERR,
1814 "%s: memory allocation failed",
1815 VXGE_DRIVER_NAME);
1816 return FALSE;
1817 }
1818
1819 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
1820
1821 /* Copy the new mac address to the list */
1822 mac_address = (u8 *)&new_mac_entry->macaddr;
1823 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1824
1825 new_mac_entry->state = mac->state;
1826 vpath->mac_addr_cnt++;
1827
1828 /* Is this a multicast address */
1829 if (0x01 & mac->macaddr[0])
1830 vpath->mcast_addr_cnt++;
1831
1832 return TRUE;
1833}
1834
1835/* Add a mac address to DA table */
1836enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1837{
1838 enum vxge_hw_status status = VXGE_HW_OK;
1839 struct vxge_vpath *vpath;
1840 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
1841
1842 if (0x01 & mac->macaddr[0]) /* multicast address */
1843 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
1844 else
1845 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
1846
1847 vpath = &vdev->vpaths[mac->vpath_no];
1848 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
1849 mac->macmask, duplicate_mode);
1850 if (status != VXGE_HW_OK) {
1851 vxge_debug_init(VXGE_ERR,
1852 "DA config add entry failed for vpath:%d",
1853 vpath->device_id);
1854 } else
1855 if (FALSE == vxge_mac_list_add(vpath, mac))
1856 status = -EPERM;
1857
1858 return status;
1859}
1860
1861int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1862{
1863 struct list_head *entry, *next;
1864 u64 del_mac = 0;
1865 u8 *mac_address = (u8 *) (&del_mac);
1866
1867 /* Copy the mac address to delete from the list */
1868 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1869
1870 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1871 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1872 list_del(entry);
1873 kfree((struct vxge_mac_addrs *)entry);
1874 vpath->mac_addr_cnt--;
1875
1876 /* Is this a multicast address */
1877 if (0x01 & mac->macaddr[0])
1878 vpath->mcast_addr_cnt--;
1879 return TRUE;
1880 }
1881 }
1882
1883 return FALSE;
1884}
1885/* delete a mac address from DA table */
1886enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1887{
1888 enum vxge_hw_status status = VXGE_HW_OK;
1889 struct vxge_vpath *vpath;
1890
1891 vpath = &vdev->vpaths[mac->vpath_no];
1892 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1893 mac->macmask);
1894 if (status != VXGE_HW_OK) {
1895 vxge_debug_init(VXGE_ERR,
1896 "DA config delete entry failed for vpath:%d",
1897 vpath->device_id);
1898 } else
1899 vxge_mac_list_del(vpath, mac);
1900 return status;
1901}
1902
1903/* list all mac addresses from DA table */
1904enum vxge_hw_status
1905static vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath,
1906 struct macInfo *mac)
1907{
1908 enum vxge_hw_status status = VXGE_HW_OK;
1909 unsigned char macmask[ETH_ALEN];
1910 unsigned char macaddr[ETH_ALEN];
1911
1912 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1913 macaddr, macmask);
1914 if (status != VXGE_HW_OK) {
1915 vxge_debug_init(VXGE_ERR,
1916 "DA config list entry failed for vpath:%d",
1917 vpath->device_id);
1918 return status;
1919 }
1920
1921 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1922
1923 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1924 macaddr, macmask);
1925 if (status != VXGE_HW_OK)
1926 break;
1927 }
1928
1929 return status;
1930}
1931
1932/* Store all vlan ids from the list to the vid table */
1933enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1934{
1935 enum vxge_hw_status status = VXGE_HW_OK;
1936 struct vxgedev *vdev = vpath->vdev;
1937 u16 vid;
1938
1939 if (vdev->vlgrp && vpath->is_open) {
1940
1941 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1942 if (!vlan_group_get_device(vdev->vlgrp, vid))
1943 continue;
1944 /* Add these vlan to the vid table */
1945 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
1946 }
1947 }
1948
1949 return status;
1950}
1951
1952/* Store all mac addresses from the list to the DA table */
1953enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1954{
1955 enum vxge_hw_status status = VXGE_HW_OK;
1956 struct macInfo mac_info;
1957 u8 *mac_address = NULL;
1958 struct list_head *entry, *next;
1959
1960 memset(&mac_info, 0, sizeof(struct macInfo));
1961
1962 if (vpath->is_open) {
1963
1964 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1965 mac_address =
1966 (u8 *)&
1967 ((struct vxge_mac_addrs *)entry)->macaddr;
1968 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1969 ((struct vxge_mac_addrs *)entry)->state =
1970 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1971 /* does this mac address already exist in da table? */
1972 status = vxge_search_mac_addr_in_da_table(vpath,
1973 &mac_info);
1974 if (status != VXGE_HW_OK) {
1975 /* Add this mac address to the DA table */
1976 status = vxge_hw_vpath_mac_addr_add(
1977 vpath->handle, mac_info.macaddr,
1978 mac_info.macmask,
1979 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
1980 if (status != VXGE_HW_OK) {
1981 vxge_debug_init(VXGE_ERR,
1982 "DA add entry failed for vpath:%d",
1983 vpath->device_id);
1984 ((struct vxge_mac_addrs *)entry)->state
1985 = VXGE_LL_MAC_ADDR_IN_LIST;
1986 }
1987 }
1988 }
1989 }
1990
1991 return status;
1992}
1993
1994/* reset vpaths */
1995enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
1996{
703da5a1 1997 enum vxge_hw_status status = VXGE_HW_OK;
7adf7d1b
JM
1998 struct vxge_vpath *vpath;
1999 int i;
703da5a1 2000
7adf7d1b
JM
2001 for (i = 0; i < vdev->no_of_vpath; i++) {
2002 vpath = &vdev->vpaths[i];
2003 if (vpath->handle) {
2004 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
703da5a1
RV
2005 if (is_vxge_card_up(vdev) &&
2006 vxge_hw_vpath_recover_from_reset(
7adf7d1b 2007 vpath->handle) != VXGE_HW_OK) {
703da5a1
RV
2008 vxge_debug_init(VXGE_ERR,
2009 "vxge_hw_vpath_recover_"
2010 "from_reset failed for vpath: "
2011 "%d", i);
2012 return status;
2013 }
2014 } else {
2015 vxge_debug_init(VXGE_ERR,
2016 "vxge_hw_vpath_reset failed for "
2017 "vpath:%d", i);
2018 return status;
2019 }
2020 }
7adf7d1b
JM
2021 }
2022
703da5a1
RV
2023 return status;
2024}
2025
2026/* close vpaths */
2027void vxge_close_vpaths(struct vxgedev *vdev, int index)
2028{
7adf7d1b 2029 struct vxge_vpath *vpath;
703da5a1 2030 int i;
7adf7d1b 2031
703da5a1 2032 for (i = index; i < vdev->no_of_vpath; i++) {
7adf7d1b
JM
2033 vpath = &vdev->vpaths[i];
2034
2035 if (vpath->handle && vpath->is_open) {
2036 vxge_hw_vpath_close(vpath->handle);
703da5a1
RV
2037 vdev->stats.vpaths_open--;
2038 }
7adf7d1b
JM
2039 vpath->is_open = 0;
2040 vpath->handle = NULL;
703da5a1
RV
2041 }
2042}
2043
2044/* open vpaths */
2045int vxge_open_vpaths(struct vxgedev *vdev)
2046{
7adf7d1b 2047 struct vxge_hw_vpath_attr attr;
703da5a1 2048 enum vxge_hw_status status;
7adf7d1b 2049 struct vxge_vpath *vpath;
703da5a1 2050 u32 vp_id = 0;
7adf7d1b 2051 int i;
703da5a1
RV
2052
2053 for (i = 0; i < vdev->no_of_vpath; i++) {
7adf7d1b
JM
2054 vpath = &vdev->vpaths[i];
2055
2056 vxge_assert(vpath->is_configured);
2057 attr.vp_id = vpath->device_id;
703da5a1
RV
2058 attr.fifo_attr.callback = vxge_xmit_compl;
2059 attr.fifo_attr.txdl_term = vxge_tx_term;
2060 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
7adf7d1b 2061 attr.fifo_attr.userdata = &vpath->fifo;
703da5a1
RV
2062
2063 attr.ring_attr.callback = vxge_rx_1b_compl;
2064 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2065 attr.ring_attr.rxd_term = vxge_rx_term;
2066 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
7adf7d1b 2067 attr.ring_attr.userdata = &vpath->ring;
703da5a1 2068
7adf7d1b
JM
2069 vpath->ring.ndev = vdev->ndev;
2070 vpath->ring.pdev = vdev->pdev;
2071 status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
703da5a1 2072 if (status == VXGE_HW_OK) {
7adf7d1b 2073 vpath->fifo.handle =
703da5a1 2074 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
7adf7d1b 2075 vpath->ring.handle =
703da5a1 2076 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
7adf7d1b 2077 vpath->fifo.tx_steering_type =
703da5a1 2078 vdev->config.tx_steering_type;
7adf7d1b
JM
2079 vpath->fifo.ndev = vdev->ndev;
2080 vpath->fifo.pdev = vdev->pdev;
2081 vpath->fifo.indicate_max_pkts =
703da5a1 2082 vdev->config.fifo_indicate_max_pkts;
7adf7d1b
JM
2083 vpath->ring.rx_vector_no = 0;
2084 vpath->ring.rx_csum = vdev->rx_csum;
2085 vpath->is_open = 1;
2086 vdev->vp_handles[i] = vpath->handle;
2087 vpath->ring.gro_enable = vdev->config.gro_enable;
2088 vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
703da5a1
RV
2089 vdev->stats.vpaths_open++;
2090 } else {
2091 vdev->stats.vpath_open_fail++;
2092 vxge_debug_init(VXGE_ERR,
2093 "%s: vpath: %d failed to open "
2094 "with status: %d",
7adf7d1b 2095 vdev->ndev->name, vpath->device_id,
703da5a1
RV
2096 status);
2097 vxge_close_vpaths(vdev, 0);
2098 return -EPERM;
2099 }
2100
7adf7d1b 2101 vp_id = vpath->handle->vpath->vp_id;
703da5a1
RV
2102 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2103 }
2104 return VXGE_HW_OK;
2105}
2106
2107/*
2108 * vxge_isr_napi
2109 * @irq: the irq of the device.
2110 * @dev_id: a void pointer to the hldev structure of the Titan device
2111 * @ptregs: pointer to the registers pushed on the stack.
2112 *
2113 * This function is the ISR handler of the device when napi is enabled. It
2114 * identifies the reason for the interrupt and calls the relevant service
2115 * routines.
2116 */
2117static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2118{
703da5a1 2119 struct net_device *dev;
a5d165b5 2120 struct __vxge_hw_device *hldev;
703da5a1
RV
2121 u64 reason;
2122 enum vxge_hw_status status;
a5d165b5 2123 struct vxgedev *vdev = (struct vxgedev *) dev_id;;
703da5a1
RV
2124
2125 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2126
a5d165b5
SH
2127 dev = vdev->ndev;
2128 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
703da5a1
RV
2129
2130 if (pci_channel_offline(vdev->pdev))
2131 return IRQ_NONE;
2132
2133 if (unlikely(!is_vxge_card_up(vdev)))
2134 return IRQ_NONE;
2135
2136 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode,
2137 &reason);
2138 if (status == VXGE_HW_OK) {
2139 vxge_hw_device_mask_all(hldev);
2140
2141 if (reason &
2142 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2143 vdev->vpaths_deployed >>
2144 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2145
2146 vxge_hw_device_clear_tx_rx(hldev);
2147 napi_schedule(&vdev->napi);
2148 vxge_debug_intr(VXGE_TRACE,
2149 "%s:%d Exiting...", __func__, __LINE__);
2150 return IRQ_HANDLED;
2151 } else
2152 vxge_hw_device_unmask_all(hldev);
2153 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2154 (status == VXGE_HW_ERR_CRITICAL) ||
2155 (status == VXGE_HW_ERR_FIFO))) {
2156 vxge_hw_device_mask_all(hldev);
2157 vxge_hw_device_flush_io(hldev);
2158 return IRQ_HANDLED;
2159 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2160 return IRQ_HANDLED;
2161
2162 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2163 return IRQ_NONE;
2164}
2165
2166#ifdef CONFIG_PCI_MSI
2167
2168static irqreturn_t
2169vxge_tx_msix_handle(int irq, void *dev_id)
2170{
2171 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2172
2173 VXGE_COMPLETE_VPATH_TX(fifo);
2174
2175 return IRQ_HANDLED;
2176}
2177
2178static irqreturn_t
2179vxge_rx_msix_napi_handle(int irq, void *dev_id)
2180{
2181 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2182
2183 /* MSIX_IDX for Rx is 1 */
2184 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
2185 ring->rx_vector_no);
2186
2187 napi_schedule(&ring->napi);
2188 return IRQ_HANDLED;
2189}
2190
2191static irqreturn_t
2192vxge_alarm_msix_handle(int irq, void *dev_id)
2193{
2194 int i;
2195 enum vxge_hw_status status;
2196 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2197 struct vxgedev *vdev = vpath->vdev;
b59c9457
SH
2198 int msix_id = (vpath->handle->vpath->vp_id *
2199 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
703da5a1
RV
2200
2201 for (i = 0; i < vdev->no_of_vpath; i++) {
b59c9457 2202 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
703da5a1
RV
2203
2204 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2205 vdev->exec_mode);
2206 if (status == VXGE_HW_OK) {
2207
2208 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
b59c9457 2209 msix_id);
703da5a1
RV
2210 continue;
2211 }
2212 vxge_debug_intr(VXGE_ERR,
2213 "%s: vxge_hw_vpath_alarm_process failed %x ",
2214 VXGE_DRIVER_NAME, status);
2215 }
2216 return IRQ_HANDLED;
2217}
2218
2219static int vxge_alloc_msix(struct vxgedev *vdev)
2220{
2221 int j, i, ret = 0;
b59c9457 2222 int msix_intr_vect = 0, temp;
703da5a1
RV
2223 vdev->intr_cnt = 0;
2224
b59c9457 2225start:
703da5a1
RV
2226 /* Tx/Rx MSIX Vectors count */
2227 vdev->intr_cnt = vdev->no_of_vpath * 2;
2228
2229 /* Alarm MSIX Vectors count */
2230 vdev->intr_cnt++;
2231
b59c9457 2232 vdev->entries = kzalloc(vdev->intr_cnt * sizeof(struct msix_entry),
703da5a1
RV
2233 GFP_KERNEL);
2234 if (!vdev->entries) {
2235 vxge_debug_init(VXGE_ERR,
2236 "%s: memory allocation failed",
2237 VXGE_DRIVER_NAME);
cc413d90
MS
2238 ret = -ENOMEM;
2239 goto alloc_entries_failed;
703da5a1
RV
2240 }
2241
b59c9457
SH
2242 vdev->vxge_entries =
2243 kzalloc(vdev->intr_cnt * sizeof(struct vxge_msix_entry),
2244 GFP_KERNEL);
703da5a1
RV
2245 if (!vdev->vxge_entries) {
2246 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2247 VXGE_DRIVER_NAME);
cc413d90
MS
2248 ret = -ENOMEM;
2249 goto alloc_vxge_entries_failed;
703da5a1
RV
2250 }
2251
b59c9457 2252 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
703da5a1
RV
2253
2254 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2255
2256 /* Initialize the fifo vector */
2257 vdev->entries[j].entry = msix_intr_vect;
2258 vdev->vxge_entries[j].entry = msix_intr_vect;
2259 vdev->vxge_entries[j].in_use = 0;
2260 j++;
2261
2262 /* Initialize the ring vector */
2263 vdev->entries[j].entry = msix_intr_vect + 1;
2264 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2265 vdev->vxge_entries[j].in_use = 0;
2266 j++;
2267 }
2268
2269 /* Initialize the alarm vector */
b59c9457
SH
2270 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2271 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
703da5a1
RV
2272 vdev->vxge_entries[j].in_use = 0;
2273
b59c9457 2274 ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt);
b59c9457 2275 if (ret > 0) {
703da5a1
RV
2276 vxge_debug_init(VXGE_ERR,
2277 "%s: MSI-X enable failed for %d vectors, ret: %d",
b59c9457 2278 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
cc413d90
MS
2279 if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) {
2280 ret = -ENODEV;
2281 goto enable_msix_failed;
2282 }
2283
703da5a1
RV
2284 kfree(vdev->entries);
2285 kfree(vdev->vxge_entries);
2286 vdev->entries = NULL;
2287 vdev->vxge_entries = NULL;
b59c9457
SH
2288 /* Try with less no of vector by reducing no of vpaths count */
2289 temp = (ret - 1)/2;
2290 vxge_close_vpaths(vdev, temp);
2291 vdev->no_of_vpath = temp;
2292 goto start;
cc413d90
MS
2293 } else if (ret < 0) {
2294 ret = -ENODEV;
2295 goto enable_msix_failed;
2296 }
703da5a1 2297 return 0;
cc413d90
MS
2298
2299enable_msix_failed:
2300 kfree(vdev->vxge_entries);
2301alloc_vxge_entries_failed:
2302 kfree(vdev->entries);
2303alloc_entries_failed:
2304 return ret;
703da5a1
RV
2305}
2306
2307static int vxge_enable_msix(struct vxgedev *vdev)
2308{
2309
2310 int i, ret = 0;
703da5a1 2311 /* 0 - Tx, 1 - Rx */
b59c9457
SH
2312 int tim_msix_id[4] = {0, 1, 0, 0};
2313
703da5a1
RV
2314 vdev->intr_cnt = 0;
2315
2316 /* allocate msix vectors */
2317 ret = vxge_alloc_msix(vdev);
2318 if (!ret) {
703da5a1 2319 for (i = 0; i < vdev->no_of_vpath; i++) {
7adf7d1b 2320 struct vxge_vpath *vpath = &vdev->vpaths[i];
703da5a1 2321
7adf7d1b
JM
2322 /* If fifo or ring are not enabled, the MSIX vector for
2323 * it should be set to 0.
2324 */
2325 vpath->ring.rx_vector_no = (vpath->device_id *
2326 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
703da5a1 2327
7adf7d1b
JM
2328 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
2329 VXGE_ALARM_MSIX_ID);
703da5a1
RV
2330 }
2331 }
2332
2333 return ret;
2334}
2335
2336static void vxge_rem_msix_isr(struct vxgedev *vdev)
2337{
2338 int intr_cnt;
2339
b59c9457 2340 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
703da5a1
RV
2341 intr_cnt++) {
2342 if (vdev->vxge_entries[intr_cnt].in_use) {
2343 synchronize_irq(vdev->entries[intr_cnt].vector);
2344 free_irq(vdev->entries[intr_cnt].vector,
2345 vdev->vxge_entries[intr_cnt].arg);
2346 vdev->vxge_entries[intr_cnt].in_use = 0;
2347 }
2348 }
2349
2350 kfree(vdev->entries);
2351 kfree(vdev->vxge_entries);
2352 vdev->entries = NULL;
2353 vdev->vxge_entries = NULL;
2354
2355 if (vdev->config.intr_type == MSI_X)
2356 pci_disable_msix(vdev->pdev);
2357}
2358#endif
2359
2360static void vxge_rem_isr(struct vxgedev *vdev)
2361{
2362 struct __vxge_hw_device *hldev;
2363 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2364
2365#ifdef CONFIG_PCI_MSI
2366 if (vdev->config.intr_type == MSI_X) {
2367 vxge_rem_msix_isr(vdev);
2368 } else
2369#endif
2370 if (vdev->config.intr_type == INTA) {
2371 synchronize_irq(vdev->pdev->irq);
a5d165b5 2372 free_irq(vdev->pdev->irq, vdev);
703da5a1
RV
2373 }
2374}
2375
2376static int vxge_add_isr(struct vxgedev *vdev)
2377{
2378 int ret = 0;
703da5a1
RV
2379#ifdef CONFIG_PCI_MSI
2380 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
703da5a1
RV
2381 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2382
2383 if (vdev->config.intr_type == MSI_X)
2384 ret = vxge_enable_msix(vdev);
2385
2386 if (ret) {
2387 vxge_debug_init(VXGE_ERR,
2388 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
eb5f10c2
SH
2389 vxge_debug_init(VXGE_ERR,
2390 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2391 vdev->config.intr_type = INTA;
703da5a1
RV
2392 }
2393
2394 if (vdev->config.intr_type == MSI_X) {
2395 for (intr_idx = 0;
2396 intr_idx < (vdev->no_of_vpath *
2397 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2398
2399 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2400 irq_req = 0;
2401
2402 switch (msix_idx) {
2403 case 0:
2404 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
b59c9457
SH
2405 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2406 vdev->ndev->name,
2407 vdev->entries[intr_cnt].entry,
2408 pci_fun, vp_idx);
703da5a1
RV
2409 ret = request_irq(
2410 vdev->entries[intr_cnt].vector,
2411 vxge_tx_msix_handle, 0,
2412 vdev->desc[intr_cnt],
2413 &vdev->vpaths[vp_idx].fifo);
2414 vdev->vxge_entries[intr_cnt].arg =
2415 &vdev->vpaths[vp_idx].fifo;
2416 irq_req = 1;
2417 break;
2418 case 1:
2419 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
b59c9457
SH
2420 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2421 vdev->ndev->name,
2422 vdev->entries[intr_cnt].entry,
2423 pci_fun, vp_idx);
703da5a1
RV
2424 ret = request_irq(
2425 vdev->entries[intr_cnt].vector,
2426 vxge_rx_msix_napi_handle,
2427 0,
2428 vdev->desc[intr_cnt],
2429 &vdev->vpaths[vp_idx].ring);
2430 vdev->vxge_entries[intr_cnt].arg =
2431 &vdev->vpaths[vp_idx].ring;
2432 irq_req = 1;
2433 break;
2434 }
2435
2436 if (ret) {
2437 vxge_debug_init(VXGE_ERR,
2438 "%s: MSIX - %d Registration failed",
2439 vdev->ndev->name, intr_cnt);
2440 vxge_rem_msix_isr(vdev);
eb5f10c2
SH
2441 vdev->config.intr_type = INTA;
2442 vxge_debug_init(VXGE_ERR,
2443 "%s: Defaulting to INTA"
2444 , vdev->ndev->name);
703da5a1 2445 goto INTA_MODE;
703da5a1
RV
2446 }
2447
2448 if (irq_req) {
2449 /* We requested for this msix interrupt */
2450 vdev->vxge_entries[intr_cnt].in_use = 1;
b59c9457
SH
2451 msix_idx += vdev->vpaths[vp_idx].device_id *
2452 VXGE_HW_VPATH_MSIX_ACTIVE;
703da5a1
RV
2453 vxge_hw_vpath_msix_unmask(
2454 vdev->vpaths[vp_idx].handle,
b59c9457 2455 msix_idx);
703da5a1
RV
2456 intr_cnt++;
2457 }
2458
2459 /* Point to next vpath handler */
8e95a202
JP
2460 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2461 (vp_idx < (vdev->no_of_vpath - 1)))
2462 vp_idx++;
703da5a1
RV
2463 }
2464
b59c9457 2465 intr_cnt = vdev->no_of_vpath * 2;
703da5a1 2466 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
b59c9457
SH
2467 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2468 vdev->ndev->name,
2469 vdev->entries[intr_cnt].entry,
2470 pci_fun);
703da5a1
RV
2471 /* For Alarm interrupts */
2472 ret = request_irq(vdev->entries[intr_cnt].vector,
2473 vxge_alarm_msix_handle, 0,
2474 vdev->desc[intr_cnt],
b59c9457 2475 &vdev->vpaths[0]);
703da5a1
RV
2476 if (ret) {
2477 vxge_debug_init(VXGE_ERR,
2478 "%s: MSIX - %d Registration failed",
2479 vdev->ndev->name, intr_cnt);
2480 vxge_rem_msix_isr(vdev);
eb5f10c2
SH
2481 vdev->config.intr_type = INTA;
2482 vxge_debug_init(VXGE_ERR,
2483 "%s: Defaulting to INTA",
2484 vdev->ndev->name);
703da5a1 2485 goto INTA_MODE;
703da5a1
RV
2486 }
2487
b59c9457
SH
2488 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2489 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
703da5a1 2490 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
b59c9457 2491 msix_idx);
703da5a1 2492 vdev->vxge_entries[intr_cnt].in_use = 1;
b59c9457 2493 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
703da5a1
RV
2494 }
2495INTA_MODE:
2496#endif
703da5a1
RV
2497
2498 if (vdev->config.intr_type == INTA) {
b59c9457
SH
2499 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2500 "%s:vxge:INTA", vdev->ndev->name);
eb5f10c2
SH
2501 vxge_hw_device_set_intr_type(vdev->devh,
2502 VXGE_HW_INTR_MODE_IRQLINE);
2503 vxge_hw_vpath_tti_ci_set(vdev->devh,
2504 vdev->vpaths[0].device_id);
703da5a1
RV
2505 ret = request_irq((int) vdev->pdev->irq,
2506 vxge_isr_napi,
a5d165b5 2507 IRQF_SHARED, vdev->desc[0], vdev);
703da5a1
RV
2508 if (ret) {
2509 vxge_debug_init(VXGE_ERR,
2510 "%s %s-%d: ISR registration failed",
2511 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2512 return -ENODEV;
2513 }
2514 vxge_debug_init(VXGE_TRACE,
2515 "new %s-%d line allocated",
2516 "IRQ", vdev->pdev->irq);
2517 }
2518
2519 return VXGE_HW_OK;
2520}
2521
2522static void vxge_poll_vp_reset(unsigned long data)
2523{
2524 struct vxgedev *vdev = (struct vxgedev *)data;
2525 int i, j = 0;
2526
2527 for (i = 0; i < vdev->no_of_vpath; i++) {
2528 if (test_bit(i, &vdev->vp_reset)) {
2529 vxge_reset_vpath(vdev, i);
2530 j++;
2531 }
2532 }
2533 if (j && (vdev->config.intr_type != MSI_X)) {
2534 vxge_hw_device_unmask_all(vdev->devh);
2535 vxge_hw_device_flush_io(vdev->devh);
2536 }
2537
2538 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2539}
2540
2541static void vxge_poll_vp_lockup(unsigned long data)
2542{
2543 struct vxgedev *vdev = (struct vxgedev *)data;
703da5a1 2544 enum vxge_hw_status status = VXGE_HW_OK;
7adf7d1b
JM
2545 struct vxge_vpath *vpath;
2546 struct vxge_ring *ring;
2547 int i;
703da5a1
RV
2548
2549 for (i = 0; i < vdev->no_of_vpath; i++) {
2550 ring = &vdev->vpaths[i].ring;
2551 /* Did this vpath received any packets */
2552 if (ring->stats.prev_rx_frms == ring->stats.rx_frms) {
2553 status = vxge_hw_vpath_check_leak(ring->handle);
2554
2555 /* Did it received any packets last time */
2556 if ((VXGE_HW_FAIL == status) &&
2557 (VXGE_HW_FAIL == ring->last_status)) {
2558
2559 /* schedule vpath reset */
2560 if (!test_and_set_bit(i, &vdev->vp_reset)) {
7adf7d1b 2561 vpath = &vdev->vpaths[i];
703da5a1
RV
2562
2563 /* disable interrupts for this vpath */
2564 vxge_vpath_intr_disable(vdev, i);
2565
2566 /* stop the queue for this vpath */
7adf7d1b 2567 vxge_stop_tx_queue(&vpath->fifo);
703da5a1
RV
2568 continue;
2569 }
2570 }
2571 }
2572 ring->stats.prev_rx_frms = ring->stats.rx_frms;
2573 ring->last_status = status;
2574 }
2575
2576 /* Check every 1 milli second */
2577 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2578}
2579
2580/**
2581 * vxge_open
2582 * @dev: pointer to the device structure.
2583 *
2584 * This function is the open entry point of the driver. It mainly calls a
2585 * function to allocate Rx buffers and inserts them into the buffer
2586 * descriptors and then enables the Rx part of the NIC.
2587 * Return value: '0' on success and an appropriate (-)ve integer as
2588 * defined in errno.h file on failure.
2589 */
2590int
2591vxge_open(struct net_device *dev)
2592{
2593 enum vxge_hw_status status;
2594 struct vxgedev *vdev;
2595 struct __vxge_hw_device *hldev;
7adf7d1b 2596 struct vxge_vpath *vpath;
703da5a1
RV
2597 int ret = 0;
2598 int i;
2599 u64 val64, function_mode;
2600 vxge_debug_entryexit(VXGE_TRACE,
2601 "%s: %s:%d", dev->name, __func__, __LINE__);
2602
2603 vdev = (struct vxgedev *)netdev_priv(dev);
2604 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2605 function_mode = vdev->config.device_hw_info.function_mode;
2606
2607 /* make sure you have link off by default every time Nic is
2608 * initialized */
2609 netif_carrier_off(dev);
2610
703da5a1
RV
2611 /* Open VPATHs */
2612 status = vxge_open_vpaths(vdev);
2613 if (status != VXGE_HW_OK) {
2614 vxge_debug_init(VXGE_ERR,
2615 "%s: fatal: Vpath open failed", vdev->ndev->name);
2616 ret = -EPERM;
2617 goto out0;
2618 }
2619
2620 vdev->mtu = dev->mtu;
2621
2622 status = vxge_add_isr(vdev);
2623 if (status != VXGE_HW_OK) {
2624 vxge_debug_init(VXGE_ERR,
2625 "%s: fatal: ISR add failed", dev->name);
2626 ret = -EPERM;
2627 goto out1;
2628 }
2629
2630
2631 if (vdev->config.intr_type != MSI_X) {
2632 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2633 vdev->config.napi_weight);
2634 napi_enable(&vdev->napi);
7adf7d1b
JM
2635 for (i = 0; i < vdev->no_of_vpath; i++) {
2636 vpath = &vdev->vpaths[i];
2637 vpath->ring.napi_p = &vdev->napi;
2638 }
703da5a1
RV
2639 } else {
2640 for (i = 0; i < vdev->no_of_vpath; i++) {
7adf7d1b
JM
2641 vpath = &vdev->vpaths[i];
2642 netif_napi_add(dev, &vpath->ring.napi,
703da5a1 2643 vxge_poll_msix, vdev->config.napi_weight);
7adf7d1b
JM
2644 napi_enable(&vpath->ring.napi);
2645 vpath->ring.napi_p = &vpath->ring.napi;
703da5a1
RV
2646 }
2647 }
2648
2649 /* configure RTH */
2650 if (vdev->config.rth_steering) {
2651 status = vxge_rth_configure(vdev);
2652 if (status != VXGE_HW_OK) {
2653 vxge_debug_init(VXGE_ERR,
2654 "%s: fatal: RTH configuration failed",
2655 dev->name);
2656 ret = -EPERM;
2657 goto out2;
2658 }
2659 }
2660
2661 for (i = 0; i < vdev->no_of_vpath; i++) {
7adf7d1b
JM
2662 vpath = &vdev->vpaths[i];
2663
703da5a1 2664 /* set initial mtu before enabling the device */
7adf7d1b 2665 status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
703da5a1
RV
2666 if (status != VXGE_HW_OK) {
2667 vxge_debug_init(VXGE_ERR,
2668 "%s: fatal: can not set new MTU", dev->name);
2669 ret = -EPERM;
2670 goto out2;
2671 }
2672 }
2673
2674 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2675 vxge_debug_init(vdev->level_trace,
2676 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2677 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2678
7adf7d1b
JM
2679 /* Restore the DA, VID table and also multicast and promiscuous mode
2680 * states
2681 */
2682 if (vdev->all_multi_flg) {
2683 for (i = 0; i < vdev->no_of_vpath; i++) {
2684 vpath = &vdev->vpaths[i];
2685 vxge_restore_vpath_mac_addr(vpath);
2686 vxge_restore_vpath_vid_table(vpath);
2687
2688 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2689 if (status != VXGE_HW_OK)
2690 vxge_debug_init(VXGE_ERR,
2691 "%s:%d Enabling multicast failed",
2692 __func__, __LINE__);
2693 }
703da5a1
RV
2694 }
2695
2696 /* Enable vpath to sniff all unicast/multicast traffic that not
2697 * addressed to them. We allow promiscous mode for PF only
2698 */
2699
2700 val64 = 0;
2701 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2702 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2703
2704 vxge_hw_mgmt_reg_write(vdev->devh,
2705 vxge_hw_mgmt_reg_type_mrpcim,
2706 0,
2707 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2708 rxmac_authorize_all_addr),
2709 val64);
2710
2711 vxge_hw_mgmt_reg_write(vdev->devh,
2712 vxge_hw_mgmt_reg_type_mrpcim,
2713 0,
2714 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2715 rxmac_authorize_all_vid),
2716 val64);
2717
2718 vxge_set_multicast(dev);
2719
2720 /* Enabling Bcast and mcast for all vpath */
2721 for (i = 0; i < vdev->no_of_vpath; i++) {
7adf7d1b
JM
2722 vpath = &vdev->vpaths[i];
2723 status = vxge_hw_vpath_bcast_enable(vpath->handle);
703da5a1
RV
2724 if (status != VXGE_HW_OK)
2725 vxge_debug_init(VXGE_ERR,
2726 "%s : Can not enable bcast for vpath "
2727 "id %d", dev->name, i);
2728 if (vdev->config.addr_learn_en) {
7adf7d1b 2729 status = vxge_hw_vpath_mcast_enable(vpath->handle);
703da5a1
RV
2730 if (status != VXGE_HW_OK)
2731 vxge_debug_init(VXGE_ERR,
2732 "%s : Can not enable mcast for vpath "
2733 "id %d", dev->name, i);
2734 }
2735 }
2736
2737 vxge_hw_device_setpause_data(vdev->devh, 0,
2738 vdev->config.tx_pause_enable,
2739 vdev->config.rx_pause_enable);
2740
2741 if (vdev->vp_reset_timer.function == NULL)
2742 vxge_os_timer(vdev->vp_reset_timer,
2743 vxge_poll_vp_reset, vdev, (HZ/2));
2744
2745 if (vdev->vp_lockup_timer.function == NULL)
2746 vxge_os_timer(vdev->vp_lockup_timer,
2747 vxge_poll_vp_lockup, vdev, (HZ/2));
2748
2749 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2750
2751 smp_wmb();
2752
2753 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2754 netif_carrier_on(vdev->ndev);
2755 printk(KERN_NOTICE "%s: Link Up\n", vdev->ndev->name);
2756 vdev->stats.link_up++;
2757 }
2758
2759 vxge_hw_device_intr_enable(vdev->devh);
2760
2761 smp_wmb();
2762
2763 for (i = 0; i < vdev->no_of_vpath; i++) {
7adf7d1b
JM
2764 vpath = &vdev->vpaths[i];
2765
2766 vxge_hw_vpath_enable(vpath->handle);
703da5a1 2767 smp_wmb();
7adf7d1b 2768 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
703da5a1
RV
2769 }
2770
d03848e0 2771 netif_tx_start_all_queues(vdev->ndev);
703da5a1
RV
2772 goto out0;
2773
2774out2:
2775 vxge_rem_isr(vdev);
2776
2777 /* Disable napi */
2778 if (vdev->config.intr_type != MSI_X)
2779 napi_disable(&vdev->napi);
2780 else {
2781 for (i = 0; i < vdev->no_of_vpath; i++)
2782 napi_disable(&vdev->vpaths[i].ring.napi);
2783 }
2784
2785out1:
2786 vxge_close_vpaths(vdev, 0);
2787out0:
2788 vxge_debug_entryexit(VXGE_TRACE,
2789 "%s: %s:%d Exiting...",
2790 dev->name, __func__, __LINE__);
2791 return ret;
2792}
2793
2794/* Loop throught the mac address list and delete all the entries */
2795void vxge_free_mac_add_list(struct vxge_vpath *vpath)
2796{
2797
2798 struct list_head *entry, *next;
2799 if (list_empty(&vpath->mac_addr_list))
2800 return;
2801
2802 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2803 list_del(entry);
2804 kfree((struct vxge_mac_addrs *)entry);
2805 }
2806}
2807
2808static void vxge_napi_del_all(struct vxgedev *vdev)
2809{
2810 int i;
2811 if (vdev->config.intr_type != MSI_X)
2812 netif_napi_del(&vdev->napi);
2813 else {
2814 for (i = 0; i < vdev->no_of_vpath; i++)
2815 netif_napi_del(&vdev->vpaths[i].ring.napi);
2816 }
703da5a1
RV
2817}
2818
2819int do_vxge_close(struct net_device *dev, int do_io)
2820{
2821 enum vxge_hw_status status;
2822 struct vxgedev *vdev;
2823 struct __vxge_hw_device *hldev;
2824 int i;
2825 u64 val64, vpath_vector;
2826 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2827 dev->name, __func__, __LINE__);
2828
2829 vdev = (struct vxgedev *)netdev_priv(dev);
2830 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2831
bd9ee680
SH
2832 if (unlikely(!is_vxge_card_up(vdev)))
2833 return 0;
2834
703da5a1
RV
2835 /* If vxge_handle_crit_err task is executing,
2836 * wait till it completes. */
2837 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2838 msleep(50);
2839
2840 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2841 if (do_io) {
2842 /* Put the vpath back in normal mode */
2843 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2844 status = vxge_hw_mgmt_reg_read(vdev->devh,
2845 vxge_hw_mgmt_reg_type_mrpcim,
2846 0,
2847 (ulong)offsetof(
2848 struct vxge_hw_mrpcim_reg,
2849 rts_mgr_cbasin_cfg),
2850 &val64);
2851
2852 if (status == VXGE_HW_OK) {
2853 val64 &= ~vpath_vector;
2854 status = vxge_hw_mgmt_reg_write(vdev->devh,
2855 vxge_hw_mgmt_reg_type_mrpcim,
2856 0,
2857 (ulong)offsetof(
2858 struct vxge_hw_mrpcim_reg,
2859 rts_mgr_cbasin_cfg),
2860 val64);
2861 }
2862
2863 /* Remove the function 0 from promiscous mode */
2864 vxge_hw_mgmt_reg_write(vdev->devh,
2865 vxge_hw_mgmt_reg_type_mrpcim,
2866 0,
2867 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2868 rxmac_authorize_all_addr),
2869 0);
2870
2871 vxge_hw_mgmt_reg_write(vdev->devh,
2872 vxge_hw_mgmt_reg_type_mrpcim,
2873 0,
2874 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2875 rxmac_authorize_all_vid),
2876 0);
2877
2878 smp_wmb();
2879 }
2880 del_timer_sync(&vdev->vp_lockup_timer);
2881
2882 del_timer_sync(&vdev->vp_reset_timer);
2883
2884 /* Disable napi */
2885 if (vdev->config.intr_type != MSI_X)
2886 napi_disable(&vdev->napi);
2887 else {
2888 for (i = 0; i < vdev->no_of_vpath; i++)
2889 napi_disable(&vdev->vpaths[i].ring.napi);
2890 }
2891
2892 netif_carrier_off(vdev->ndev);
2893 printk(KERN_NOTICE "%s: Link Down\n", vdev->ndev->name);
d03848e0 2894 netif_tx_stop_all_queues(vdev->ndev);
703da5a1
RV
2895
2896 /* Note that at this point xmit() is stopped by upper layer */
2897 if (do_io)
2898 vxge_hw_device_intr_disable(vdev->devh);
2899
2900 mdelay(1000);
2901
2902 vxge_rem_isr(vdev);
2903
2904 vxge_napi_del_all(vdev);
2905
2906 if (do_io)
2907 vxge_reset_all_vpaths(vdev);
2908
2909 vxge_close_vpaths(vdev, 0);
2910
2911 vxge_debug_entryexit(VXGE_TRACE,
2912 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
2913
703da5a1
RV
2914 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
2915
2916 return 0;
2917}
2918
2919/**
2920 * vxge_close
2921 * @dev: device pointer.
2922 *
2923 * This is the stop entry point of the driver. It needs to undo exactly
2924 * whatever was done by the open entry point, thus it's usually referred to
2925 * as the close function.Among other things this function mainly stops the
2926 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
2927 * Return value: '0' on success and an appropriate (-)ve integer as
2928 * defined in errno.h file on failure.
2929 */
2930int
2931vxge_close(struct net_device *dev)
2932{
2933 do_vxge_close(dev, 1);
2934 return 0;
2935}
2936
2937/**
2938 * vxge_change_mtu
2939 * @dev: net device pointer.
2940 * @new_mtu :the new MTU size for the device.
2941 *
2942 * A driver entry point to change MTU size for the device. Before changing
2943 * the MTU the device must be stopped.
2944 */
2945static int vxge_change_mtu(struct net_device *dev, int new_mtu)
2946{
2947 struct vxgedev *vdev = netdev_priv(dev);
2948
2949 vxge_debug_entryexit(vdev->level_trace,
2950 "%s:%d", __func__, __LINE__);
2951 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
2952 vxge_debug_init(vdev->level_err,
2953 "%s: mtu size is invalid", dev->name);
2954 return -EPERM;
2955 }
2956
2957 /* check if device is down already */
2958 if (unlikely(!is_vxge_card_up(vdev))) {
2959 /* just store new value, will use later on open() */
2960 dev->mtu = new_mtu;
2961 vxge_debug_init(vdev->level_err,
2962 "%s", "device is down on MTU change");
2963 return 0;
2964 }
2965
2966 vxge_debug_init(vdev->level_trace,
2967 "trying to apply new MTU %d", new_mtu);
2968
2969 if (vxge_close(dev))
2970 return -EIO;
2971
2972 dev->mtu = new_mtu;
2973 vdev->mtu = new_mtu;
2974
2975 if (vxge_open(dev))
2976 return -EIO;
2977
2978 vxge_debug_init(vdev->level_trace,
2979 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
2980
2981 vxge_debug_entryexit(vdev->level_trace,
2982 "%s:%d Exiting...", __func__, __LINE__);
2983
2984 return 0;
2985}
2986
2987/**
2988 * vxge_get_stats
2989 * @dev: pointer to the device structure
2990 *
2991 * Updates the device statistics structure. This function updates the device
2992 * statistics structure in the net_device structure and returns a pointer
2993 * to the same.
2994 */
2995static struct net_device_stats *
2996vxge_get_stats(struct net_device *dev)
2997{
2998 struct vxgedev *vdev;
2999 struct net_device_stats *net_stats;
3000 int k;
3001
3002 vdev = netdev_priv(dev);
3003
3004 net_stats = &vdev->stats.net_stats;
3005
3006 memset(net_stats, 0, sizeof(struct net_device_stats));
3007
3008 for (k = 0; k < vdev->no_of_vpath; k++) {
3009 net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms;
3010 net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes;
3011 net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors;
3012 net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast;
3013 net_stats->rx_dropped +=
3014 vdev->vpaths[k].ring.stats.rx_dropped;
3015
3016 net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms;
3017 net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes;
3018 net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors;
3019 }
3020
3021 return net_stats;
3022}
3023
3024/**
3025 * vxge_ioctl
3026 * @dev: Device pointer.
3027 * @ifr: An IOCTL specific structure, that can contain a pointer to
3028 * a proprietary structure used to pass information to the driver.
3029 * @cmd: This is used to distinguish between the different commands that
3030 * can be passed to the IOCTL functions.
3031 *
3032 * Entry point for the Ioctl.
3033 */
3034static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3035{
3036 return -EOPNOTSUPP;
3037}
3038
3039/**
3040 * vxge_tx_watchdog
3041 * @dev: pointer to net device structure
3042 *
3043 * Watchdog for transmit side.
3044 * This function is triggered if the Tx Queue is stopped
3045 * for a pre-defined amount of time when the Interface is still up.
3046 */
3047static void
3048vxge_tx_watchdog(struct net_device *dev)
3049{
3050 struct vxgedev *vdev;
3051
3052 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3053
3054 vdev = (struct vxgedev *)netdev_priv(dev);
3055
3056 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3057
3058 vxge_reset(vdev);
3059 vxge_debug_entryexit(VXGE_TRACE,
3060 "%s:%d Exiting...", __func__, __LINE__);
3061}
3062
3063/**
3064 * vxge_vlan_rx_register
3065 * @dev: net device pointer.
3066 * @grp: vlan group
3067 *
3068 * Vlan group registration
3069 */
3070static void
3071vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
3072{
3073 struct vxgedev *vdev;
3074 struct vxge_vpath *vpath;
3075 int vp;
3076 u64 vid;
3077 enum vxge_hw_status status;
3078 int i;
3079
3080 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3081
3082 vdev = (struct vxgedev *)netdev_priv(dev);
3083
3084 vpath = &vdev->vpaths[0];
3085 if ((NULL == grp) && (vpath->is_open)) {
3086 /* Get the first vlan */
3087 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3088
3089 while (status == VXGE_HW_OK) {
3090
3091 /* Delete this vlan from the vid table */
3092 for (vp = 0; vp < vdev->no_of_vpath; vp++) {
3093 vpath = &vdev->vpaths[vp];
3094 if (!vpath->is_open)
3095 continue;
3096
3097 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3098 }
3099
3100 /* Get the next vlan to be deleted */
3101 vpath = &vdev->vpaths[0];
3102 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3103 }
3104 }
3105
3106 vdev->vlgrp = grp;
3107
3108 for (i = 0; i < vdev->no_of_vpath; i++) {
3109 if (vdev->vpaths[i].is_configured)
3110 vdev->vpaths[i].ring.vlgrp = grp;
3111 }
3112
3113 vxge_debug_entryexit(VXGE_TRACE,
3114 "%s:%d Exiting...", __func__, __LINE__);
3115}
3116
3117/**
3118 * vxge_vlan_rx_add_vid
3119 * @dev: net device pointer.
3120 * @vid: vid
3121 *
3122 * Add the vlan id to the devices vlan id table
3123 */
3124static void
3125vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3126{
3127 struct vxgedev *vdev;
3128 struct vxge_vpath *vpath;
3129 int vp_id;
3130
3131 vdev = (struct vxgedev *)netdev_priv(dev);
3132
3133 /* Add these vlan to the vid table */
3134 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3135 vpath = &vdev->vpaths[vp_id];
3136 if (!vpath->is_open)
3137 continue;
3138 vxge_hw_vpath_vid_add(vpath->handle, vid);
3139 }
3140}
3141
3142/**
3143 * vxge_vlan_rx_add_vid
3144 * @dev: net device pointer.
3145 * @vid: vid
3146 *
3147 * Remove the vlan id from the device's vlan id table
3148 */
3149static void
3150vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3151{
3152 struct vxgedev *vdev;
3153 struct vxge_vpath *vpath;
3154 int vp_id;
3155
3156 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3157
3158 vdev = (struct vxgedev *)netdev_priv(dev);
3159
3160 vlan_group_set_device(vdev->vlgrp, vid, NULL);
3161
3162 /* Delete this vlan from the vid table */
3163 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3164 vpath = &vdev->vpaths[vp_id];
3165 if (!vpath->is_open)
3166 continue;
3167 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3168 }
3169 vxge_debug_entryexit(VXGE_TRACE,
3170 "%s:%d Exiting...", __func__, __LINE__);
3171}
3172
3173static const struct net_device_ops vxge_netdev_ops = {
3174 .ndo_open = vxge_open,
3175 .ndo_stop = vxge_close,
3176 .ndo_get_stats = vxge_get_stats,
3177 .ndo_start_xmit = vxge_xmit,
3178 .ndo_validate_addr = eth_validate_addr,
3179 .ndo_set_multicast_list = vxge_set_multicast,
3180
3181 .ndo_do_ioctl = vxge_ioctl,
3182
3183 .ndo_set_mac_address = vxge_set_mac_addr,
3184 .ndo_change_mtu = vxge_change_mtu,
3185 .ndo_vlan_rx_register = vxge_vlan_rx_register,
3186 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3187 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
3188
3189 .ndo_tx_timeout = vxge_tx_watchdog,
3190#ifdef CONFIG_NET_POLL_CONTROLLER
3191 .ndo_poll_controller = vxge_netpoll,
3192#endif
3193};
3194
3195int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3196 struct vxge_config *config,
3197 int high_dma, int no_of_vpath,
3198 struct vxgedev **vdev_out)
3199{
3200 struct net_device *ndev;
3201 enum vxge_hw_status status = VXGE_HW_OK;
3202 struct vxgedev *vdev;
3203 int i, ret = 0, no_of_queue = 1;
3204 u64 stat;
3205
3206 *vdev_out = NULL;
d03848e0 3207 if (config->tx_steering_type)
703da5a1
RV
3208 no_of_queue = no_of_vpath;
3209
3210 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3211 no_of_queue);
3212 if (ndev == NULL) {
3213 vxge_debug_init(
3214 vxge_hw_device_trace_level_get(hldev),
3215 "%s : device allocation failed", __func__);
3216 ret = -ENODEV;
3217 goto _out0;
3218 }
3219
3220 vxge_debug_entryexit(
3221 vxge_hw_device_trace_level_get(hldev),
3222 "%s: %s:%d Entering...",
3223 ndev->name, __func__, __LINE__);
3224
3225 vdev = netdev_priv(ndev);
3226 memset(vdev, 0, sizeof(struct vxgedev));
3227
3228 vdev->ndev = ndev;
3229 vdev->devh = hldev;
3230 vdev->pdev = hldev->pdev;
3231 memcpy(&vdev->config, config, sizeof(struct vxge_config));
3232 vdev->rx_csum = 1; /* Enable Rx CSUM by default. */
3233
3234 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3235
3236 ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
3237 NETIF_F_HW_VLAN_FILTER;
3238 /* Driver entry points */
3239 ndev->irq = vdev->pdev->irq;
3240 ndev->base_addr = (unsigned long) hldev->bar0;
3241
3242 ndev->netdev_ops = &vxge_netdev_ops;
3243
3244 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
3245
3246 initialize_ethtool_ops(ndev);
3247
3248 /* Allocate memory for vpath */
3249 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3250 no_of_vpath, GFP_KERNEL);
3251 if (!vdev->vpaths) {
3252 vxge_debug_init(VXGE_ERR,
3253 "%s: vpath memory allocation failed",
3254 vdev->ndev->name);
3255 ret = -ENODEV;
3256 goto _out1;
3257 }
3258
3259 ndev->features |= NETIF_F_SG;
3260
3261 ndev->features |= NETIF_F_HW_CSUM;
3262 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3263 "%s : checksuming enabled", __func__);
3264
3265 if (high_dma) {
3266 ndev->features |= NETIF_F_HIGHDMA;
3267 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3268 "%s : using High DMA", __func__);
3269 }
3270
3271 ndev->features |= NETIF_F_TSO | NETIF_F_TSO6;
3272
3273 if (vdev->config.gro_enable)
3274 ndev->features |= NETIF_F_GRO;
3275
703da5a1
RV
3276#ifdef NETIF_F_LLTX
3277 ndev->features |= NETIF_F_LLTX;
3278#endif
3279
3280 for (i = 0; i < no_of_vpath; i++)
3281 spin_lock_init(&vdev->vpaths[i].fifo.tx_lock);
3282
3283 if (register_netdev(ndev)) {
3284 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3285 "%s: %s : device registration failed!",
3286 ndev->name, __func__);
3287 ret = -ENODEV;
3288 goto _out2;
3289 }
3290
3291 /* Set the factory defined MAC address initially */
3292 ndev->addr_len = ETH_ALEN;
3293
3294 /* Make Link state as off at this point, when the Link change
3295 * interrupt comes the state will be automatically changed to
3296 * the right state.
3297 */
3298 netif_carrier_off(ndev);
3299
3300 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3301 "%s: Ethernet device registered",
3302 ndev->name);
3303
3304 *vdev_out = vdev;
3305
3306 /* Resetting the Device stats */
3307 status = vxge_hw_mrpcim_stats_access(
3308 hldev,
3309 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3310 0,
3311 0,
3312 &stat);
3313
3314 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3315 vxge_debug_init(
3316 vxge_hw_device_trace_level_get(hldev),
3317 "%s: device stats clear returns"
3318 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3319
3320 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3321 "%s: %s:%d Exiting...",
3322 ndev->name, __func__, __LINE__);
3323
3324 return ret;
3325_out2:
3326 kfree(vdev->vpaths);
3327_out1:
3328 free_netdev(ndev);
3329_out0:
3330 return ret;
3331}
3332
3333/*
3334 * vxge_device_unregister
3335 *
3336 * This function will unregister and free network device
3337 */
3338void
3339vxge_device_unregister(struct __vxge_hw_device *hldev)
3340{
3341 struct vxgedev *vdev;
3342 struct net_device *dev;
3343 char buf[IFNAMSIZ];
3344#if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3345 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3346 u32 level_trace;
3347#endif
3348
3349 dev = hldev->ndev;
3350 vdev = netdev_priv(dev);
3351#if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3352 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3353 level_trace = vdev->level_trace;
3354#endif
3355 vxge_debug_entryexit(level_trace,
3356 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3357
3358 memcpy(buf, vdev->ndev->name, IFNAMSIZ);
3359
3360 /* in 2.6 will call stop() if device is up */
3361 unregister_netdev(dev);
3362
3363 flush_scheduled_work();
3364
3365 vxge_debug_init(level_trace, "%s: ethernet device unregistered", buf);
3366 vxge_debug_entryexit(level_trace,
3367 "%s: %s:%d Exiting...", buf, __func__, __LINE__);
3368}
3369
3370/*
3371 * vxge_callback_crit_err
3372 *
3373 * This function is called by the alarm handler in interrupt context.
3374 * Driver must analyze it based on the event type.
3375 */
3376static void
3377vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3378 enum vxge_hw_event type, u64 vp_id)
3379{
3380 struct net_device *dev = hldev->ndev;
3381 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
3382 int vpath_idx;
3383
3384 vxge_debug_entryexit(vdev->level_trace,
3385 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3386
3387 /* Note: This event type should be used for device wide
3388 * indications only - Serious errors, Slot freeze and critical errors
3389 */
3390 vdev->cric_err_event = type;
3391
3392 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++)
3393 if (vdev->vpaths[vpath_idx].device_id == vp_id)
3394 break;
3395
3396 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3397 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3398 vxge_debug_init(VXGE_ERR,
3399 "%s: Slot is frozen", vdev->ndev->name);
3400 } else if (type == VXGE_HW_EVENT_SERR) {
3401 vxge_debug_init(VXGE_ERR,
3402 "%s: Encountered Serious Error",
3403 vdev->ndev->name);
3404 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3405 vxge_debug_init(VXGE_ERR,
3406 "%s: Encountered Critical Error",
3407 vdev->ndev->name);
3408 }
3409
3410 if ((type == VXGE_HW_EVENT_SERR) ||
3411 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3412 if (unlikely(vdev->exec_mode))
3413 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3414 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3415 vxge_hw_device_mask_all(hldev);
3416 if (unlikely(vdev->exec_mode))
3417 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3418 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3419 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3420
3421 if (unlikely(vdev->exec_mode))
3422 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3423 else {
3424 /* check if this vpath is already set for reset */
3425 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3426
3427 /* disable interrupts for this vpath */
3428 vxge_vpath_intr_disable(vdev, vpath_idx);
3429
3430 /* stop the queue for this vpath */
3431 vxge_stop_tx_queue(&vdev->vpaths[vpath_idx].
3432 fifo);
3433 }
3434 }
3435 }
3436
3437 vxge_debug_entryexit(vdev->level_trace,
3438 "%s: %s:%d Exiting...",
3439 vdev->ndev->name, __func__, __LINE__);
3440}
3441
3442static void verify_bandwidth(void)
3443{
3444 int i, band_width, total = 0, equal_priority = 0;
3445
3446 /* 1. If user enters 0 for some fifo, give equal priority to all */
3447 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3448 if (bw_percentage[i] == 0) {
3449 equal_priority = 1;
3450 break;
3451 }
3452 }
3453
3454 if (!equal_priority) {
3455 /* 2. If sum exceeds 100, give equal priority to all */
3456 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3457 if (bw_percentage[i] == 0xFF)
3458 break;
3459
3460 total += bw_percentage[i];
3461 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3462 equal_priority = 1;
3463 break;
3464 }
3465 }
3466 }
3467
3468 if (!equal_priority) {
3469 /* Is all the bandwidth consumed? */
3470 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3471 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3472 /* Split rest of bw equally among next VPs*/
3473 band_width =
3474 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3475 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3476 if (band_width < 2) /* min of 2% */
3477 equal_priority = 1;
3478 else {
3479 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3480 i++)
3481 bw_percentage[i] =
3482 band_width;
3483 }
3484 }
3485 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3486 equal_priority = 1;
3487 }
3488
3489 if (equal_priority) {
3490 vxge_debug_init(VXGE_ERR,
3491 "%s: Assigning equal bandwidth to all the vpaths",
3492 VXGE_DRIVER_NAME);
3493 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3494 VXGE_HW_MAX_VIRTUAL_PATHS;
3495 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3496 bw_percentage[i] = bw_percentage[0];
3497 }
703da5a1
RV
3498}
3499
3500/*
3501 * Vpath configuration
3502 */
3503static int __devinit vxge_config_vpaths(
3504 struct vxge_hw_device_config *device_config,
3505 u64 vpath_mask, struct vxge_config *config_param)
3506{
3507 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3508 u32 txdl_size, txdl_per_memblock;
3509
3510 temp = driver_config->vpath_per_dev;
3511 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3512 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3513 /* No more CPU. Return vpath number as zero.*/
3514 if (driver_config->g_no_cpus == -1)
3515 return 0;
3516
3517 if (!driver_config->g_no_cpus)
3518 driver_config->g_no_cpus = num_online_cpus();
3519
3520 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3521 if (!driver_config->vpath_per_dev)
3522 driver_config->vpath_per_dev = 1;
3523
3524 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3525 if (!vxge_bVALn(vpath_mask, i, 1))
3526 continue;
3527 else
3528 default_no_vpath++;
3529 if (default_no_vpath < driver_config->vpath_per_dev)
3530 driver_config->vpath_per_dev = default_no_vpath;
3531
3532 driver_config->g_no_cpus = driver_config->g_no_cpus -
3533 (driver_config->vpath_per_dev * 2);
3534 if (driver_config->g_no_cpus <= 0)
3535 driver_config->g_no_cpus = -1;
3536 }
3537
3538 if (driver_config->vpath_per_dev == 1) {
3539 vxge_debug_ll_config(VXGE_TRACE,
3540 "%s: Disable tx and rx steering, "
3541 "as single vpath is configured", VXGE_DRIVER_NAME);
3542 config_param->rth_steering = NO_STEERING;
3543 config_param->tx_steering_type = NO_STEERING;
3544 device_config->rth_en = 0;
3545 }
3546
3547 /* configure bandwidth */
3548 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3549 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3550
3551 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3552 device_config->vp_config[i].vp_id = i;
3553 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3554 if (no_of_vpaths < driver_config->vpath_per_dev) {
3555 if (!vxge_bVALn(vpath_mask, i, 1)) {
3556 vxge_debug_ll_config(VXGE_TRACE,
3557 "%s: vpath: %d is not available",
3558 VXGE_DRIVER_NAME, i);
3559 continue;
3560 } else {
3561 vxge_debug_ll_config(VXGE_TRACE,
3562 "%s: vpath: %d available",
3563 VXGE_DRIVER_NAME, i);
3564 no_of_vpaths++;
3565 }
3566 } else {
3567 vxge_debug_ll_config(VXGE_TRACE,
3568 "%s: vpath: %d is not configured, "
3569 "max_config_vpath exceeded",
3570 VXGE_DRIVER_NAME, i);
3571 break;
3572 }
3573
3574 /* Configure Tx fifo's */
3575 device_config->vp_config[i].fifo.enable =
3576 VXGE_HW_FIFO_ENABLE;
3577 device_config->vp_config[i].fifo.max_frags =
5beefb4f 3578 MAX_SKB_FRAGS + 1;
703da5a1
RV
3579 device_config->vp_config[i].fifo.memblock_size =
3580 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3581
5beefb4f
SH
3582 txdl_size = device_config->vp_config[i].fifo.max_frags *
3583 sizeof(struct vxge_hw_fifo_txd);
703da5a1
RV
3584 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3585
3586 device_config->vp_config[i].fifo.fifo_blocks =
3587 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3588
3589 device_config->vp_config[i].fifo.intr =
3590 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3591
3592 /* Configure tti properties */
3593 device_config->vp_config[i].tti.intr_enable =
3594 VXGE_HW_TIM_INTR_ENABLE;
3595
3596 device_config->vp_config[i].tti.btimer_val =
3597 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3598
3599 device_config->vp_config[i].tti.timer_ac_en =
3600 VXGE_HW_TIM_TIMER_AC_ENABLE;
3601
3602 /* For msi-x with napi (each vector
3603 has a handler of its own) -
3604 Set CI to OFF for all vpaths */
3605 device_config->vp_config[i].tti.timer_ci_en =
3606 VXGE_HW_TIM_TIMER_CI_DISABLE;
3607
3608 device_config->vp_config[i].tti.timer_ri_en =
3609 VXGE_HW_TIM_TIMER_RI_DISABLE;
3610
3611 device_config->vp_config[i].tti.util_sel =
3612 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3613
3614 device_config->vp_config[i].tti.ltimer_val =
3615 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3616
3617 device_config->vp_config[i].tti.rtimer_val =
3618 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3619
3620 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3621 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3622 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3623 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3624 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3625 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3626 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3627
3628 /* Configure Rx rings */
3629 device_config->vp_config[i].ring.enable =
3630 VXGE_HW_RING_ENABLE;
3631
3632 device_config->vp_config[i].ring.ring_blocks =
3633 VXGE_HW_DEF_RING_BLOCKS;
3634 device_config->vp_config[i].ring.buffer_mode =
3635 VXGE_HW_RING_RXD_BUFFER_MODE_1;
3636 device_config->vp_config[i].ring.rxds_limit =
3637 VXGE_HW_DEF_RING_RXDS_LIMIT;
3638 device_config->vp_config[i].ring.scatter_mode =
3639 VXGE_HW_RING_SCATTER_MODE_A;
3640
3641 /* Configure rti properties */
3642 device_config->vp_config[i].rti.intr_enable =
3643 VXGE_HW_TIM_INTR_ENABLE;
3644
3645 device_config->vp_config[i].rti.btimer_val =
3646 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3647
3648 device_config->vp_config[i].rti.timer_ac_en =
3649 VXGE_HW_TIM_TIMER_AC_ENABLE;
3650
3651 device_config->vp_config[i].rti.timer_ci_en =
3652 VXGE_HW_TIM_TIMER_CI_DISABLE;
3653
3654 device_config->vp_config[i].rti.timer_ri_en =
3655 VXGE_HW_TIM_TIMER_RI_DISABLE;
3656
3657 device_config->vp_config[i].rti.util_sel =
3658 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3659
3660 device_config->vp_config[i].rti.urange_a =
3661 RTI_RX_URANGE_A;
3662 device_config->vp_config[i].rti.urange_b =
3663 RTI_RX_URANGE_B;
3664 device_config->vp_config[i].rti.urange_c =
3665 RTI_RX_URANGE_C;
3666 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3667 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3668 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3669 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3670
3671 device_config->vp_config[i].rti.rtimer_val =
3672 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3673
3674 device_config->vp_config[i].rti.ltimer_val =
3675 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3676
3677 device_config->vp_config[i].rpa_strip_vlan_tag =
3678 vlan_tag_strip;
3679 }
3680
3681 driver_config->vpath_per_dev = temp;
3682 return no_of_vpaths;
3683}
3684
3685/* initialize device configuratrions */
3686static void __devinit vxge_device_config_init(
3687 struct vxge_hw_device_config *device_config,
3688 int *intr_type)
3689{
3690 /* Used for CQRQ/SRQ. */
3691 device_config->dma_blockpool_initial =
3692 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3693
3694 device_config->dma_blockpool_max =
3695 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3696
3697 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3698 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3699
3700#ifndef CONFIG_PCI_MSI
3701 vxge_debug_init(VXGE_ERR,
3702 "%s: This Kernel does not support "
3703 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3704 *intr_type = INTA;
3705#endif
3706
3707 /* Configure whether MSI-X or IRQL. */
3708 switch (*intr_type) {
3709 case INTA:
3710 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3711 break;
3712
3713 case MSI_X:
3714 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX;
3715 break;
3716 }
3717 /* Timer period between device poll */
3718 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3719
3720 /* Configure mac based steering. */
3721 device_config->rts_mac_en = addr_learn_en;
3722
3723 /* Configure Vpaths */
3724 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3725
3726 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3727 __func__);
3728 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_initial : %d",
3729 device_config->dma_blockpool_initial);
3730 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_max : %d",
3731 device_config->dma_blockpool_max);
3732 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3733 device_config->intr_mode);
3734 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3735 device_config->device_poll_millis);
3736 vxge_debug_ll_config(VXGE_TRACE, "rts_mac_en : %d",
3737 device_config->rts_mac_en);
3738 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3739 device_config->rth_en);
3740 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3741 device_config->rth_it_type);
3742}
3743
3744static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3745{
3746 int i;
3747
3748 vxge_debug_init(VXGE_TRACE,
3749 "%s: %d Vpath(s) opened",
3750 vdev->ndev->name, vdev->no_of_vpath);
3751
3752 switch (vdev->config.intr_type) {
3753 case INTA:
3754 vxge_debug_init(VXGE_TRACE,
3755 "%s: Interrupt type INTA", vdev->ndev->name);
3756 break;
3757
3758 case MSI_X:
3759 vxge_debug_init(VXGE_TRACE,
3760 "%s: Interrupt type MSI-X", vdev->ndev->name);
3761 break;
3762 }
3763
3764 if (vdev->config.rth_steering) {
3765 vxge_debug_init(VXGE_TRACE,
3766 "%s: RTH steering enabled for TCP_IPV4",
3767 vdev->ndev->name);
3768 } else {
3769 vxge_debug_init(VXGE_TRACE,
3770 "%s: RTH steering disabled", vdev->ndev->name);
3771 }
3772
3773 switch (vdev->config.tx_steering_type) {
3774 case NO_STEERING:
3775 vxge_debug_init(VXGE_TRACE,
3776 "%s: Tx steering disabled", vdev->ndev->name);
3777 break;
3778 case TX_PRIORITY_STEERING:
3779 vxge_debug_init(VXGE_TRACE,
3780 "%s: Unsupported tx steering option",
3781 vdev->ndev->name);
3782 vxge_debug_init(VXGE_TRACE,
3783 "%s: Tx steering disabled", vdev->ndev->name);
3784 vdev->config.tx_steering_type = 0;
3785 break;
3786 case TX_VLAN_STEERING:
3787 vxge_debug_init(VXGE_TRACE,
3788 "%s: Unsupported tx steering option",
3789 vdev->ndev->name);
3790 vxge_debug_init(VXGE_TRACE,
3791 "%s: Tx steering disabled", vdev->ndev->name);
3792 vdev->config.tx_steering_type = 0;
3793 break;
3794 case TX_MULTIQ_STEERING:
3795 vxge_debug_init(VXGE_TRACE,
3796 "%s: Tx multiqueue steering enabled",
3797 vdev->ndev->name);
3798 break;
3799 case TX_PORT_STEERING:
3800 vxge_debug_init(VXGE_TRACE,
3801 "%s: Tx port steering enabled",
3802 vdev->ndev->name);
3803 break;
3804 default:
3805 vxge_debug_init(VXGE_ERR,
3806 "%s: Unsupported tx steering type",
3807 vdev->ndev->name);
3808 vxge_debug_init(VXGE_TRACE,
3809 "%s: Tx steering disabled", vdev->ndev->name);
3810 vdev->config.tx_steering_type = 0;
3811 }
3812
3813 if (vdev->config.gro_enable) {
3814 vxge_debug_init(VXGE_ERR,
3815 "%s: Generic receive offload enabled",
3816 vdev->ndev->name);
3817 } else
3818 vxge_debug_init(VXGE_TRACE,
3819 "%s: Generic receive offload disabled",
3820 vdev->ndev->name);
3821
3822 if (vdev->config.addr_learn_en)
3823 vxge_debug_init(VXGE_TRACE,
3824 "%s: MAC Address learning enabled", vdev->ndev->name);
3825
3826 vxge_debug_init(VXGE_TRACE,
3827 "%s: Rx doorbell mode enabled", vdev->ndev->name);
3828
3829 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3830 if (!vxge_bVALn(vpath_mask, i, 1))
3831 continue;
3832 vxge_debug_ll_config(VXGE_TRACE,
3833 "%s: MTU size - %d", vdev->ndev->name,
3834 ((struct __vxge_hw_device *)(vdev->devh))->
3835 config.vp_config[i].mtu);
3836 vxge_debug_init(VXGE_TRACE,
3837 "%s: VLAN tag stripping %s", vdev->ndev->name,
3838 ((struct __vxge_hw_device *)(vdev->devh))->
3839 config.vp_config[i].rpa_strip_vlan_tag
3840 ? "Enabled" : "Disabled");
3841 vxge_debug_init(VXGE_TRACE,
3842 "%s: Ring blocks : %d", vdev->ndev->name,
3843 ((struct __vxge_hw_device *)(vdev->devh))->
3844 config.vp_config[i].ring.ring_blocks);
3845 vxge_debug_init(VXGE_TRACE,
3846 "%s: Fifo blocks : %d", vdev->ndev->name,
3847 ((struct __vxge_hw_device *)(vdev->devh))->
3848 config.vp_config[i].fifo.fifo_blocks);
3849 vxge_debug_ll_config(VXGE_TRACE,
3850 "%s: Max frags : %d", vdev->ndev->name,
3851 ((struct __vxge_hw_device *)(vdev->devh))->
3852 config.vp_config[i].fifo.max_frags);
3853 break;
3854 }
3855}
3856
3857#ifdef CONFIG_PM
3858/**
3859 * vxge_pm_suspend - vxge power management suspend entry point
3860 *
3861 */
3862static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
3863{
3864 return -ENOSYS;
3865}
3866/**
3867 * vxge_pm_resume - vxge power management resume entry point
3868 *
3869 */
3870static int vxge_pm_resume(struct pci_dev *pdev)
3871{
3872 return -ENOSYS;
3873}
3874
3875#endif
3876
3877/**
3878 * vxge_io_error_detected - called when PCI error is detected
3879 * @pdev: Pointer to PCI device
3880 * @state: The current pci connection state
3881 *
3882 * This function is called after a PCI bus error affecting
3883 * this device has been detected.
3884 */
3885static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
3886 pci_channel_state_t state)
3887{
3888 struct __vxge_hw_device *hldev =
3889 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3890 struct net_device *netdev = hldev->ndev;
3891
3892 netif_device_detach(netdev);
3893
e33b992d
DN
3894 if (state == pci_channel_io_perm_failure)
3895 return PCI_ERS_RESULT_DISCONNECT;
3896
703da5a1
RV
3897 if (netif_running(netdev)) {
3898 /* Bring down the card, while avoiding PCI I/O */
3899 do_vxge_close(netdev, 0);
3900 }
3901
3902 pci_disable_device(pdev);
3903
3904 return PCI_ERS_RESULT_NEED_RESET;
3905}
3906
3907/**
3908 * vxge_io_slot_reset - called after the pci bus has been reset.
3909 * @pdev: Pointer to PCI device
3910 *
3911 * Restart the card from scratch, as if from a cold-boot.
3912 * At this point, the card has exprienced a hard reset,
3913 * followed by fixups by BIOS, and has its config space
3914 * set up identically to what it was at cold boot.
3915 */
3916static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
3917{
3918 struct __vxge_hw_device *hldev =
3919 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3920 struct net_device *netdev = hldev->ndev;
3921
3922 struct vxgedev *vdev = netdev_priv(netdev);
3923
3924 if (pci_enable_device(pdev)) {
3925 printk(KERN_ERR "%s: "
3926 "Cannot re-enable device after reset\n",
3927 VXGE_DRIVER_NAME);
3928 return PCI_ERS_RESULT_DISCONNECT;
3929 }
3930
3931 pci_set_master(pdev);
3932 vxge_reset(vdev);
3933
3934 return PCI_ERS_RESULT_RECOVERED;
3935}
3936
3937/**
3938 * vxge_io_resume - called when traffic can start flowing again.
3939 * @pdev: Pointer to PCI device
3940 *
3941 * This callback is called when the error recovery driver tells
3942 * us that its OK to resume normal operation.
3943 */
3944static void vxge_io_resume(struct pci_dev *pdev)
3945{
3946 struct __vxge_hw_device *hldev =
3947 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3948 struct net_device *netdev = hldev->ndev;
3949
3950 if (netif_running(netdev)) {
3951 if (vxge_open(netdev)) {
3952 printk(KERN_ERR "%s: "
3953 "Can't bring device back up after reset\n",
3954 VXGE_DRIVER_NAME);
3955 return;
3956 }
3957 }
3958
3959 netif_device_attach(netdev);
3960}
3961
cb27ec60
SH
3962static inline u32 vxge_get_num_vfs(u64 function_mode)
3963{
3964 u32 num_functions = 0;
3965
3966 switch (function_mode) {
3967 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
3968 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
3969 num_functions = 8;
3970 break;
3971 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
3972 num_functions = 1;
3973 break;
3974 case VXGE_HW_FUNCTION_MODE_SRIOV:
3975 case VXGE_HW_FUNCTION_MODE_MRIOV:
3976 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
3977 num_functions = 17;
3978 break;
3979 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
3980 num_functions = 4;
3981 break;
3982 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
3983 num_functions = 2;
3984 break;
3985 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
3986 num_functions = 8; /* TODO */
3987 break;
3988 }
3989 return num_functions;
3990}
3991
703da5a1
RV
3992/**
3993 * vxge_probe
3994 * @pdev : structure containing the PCI related information of the device.
3995 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
3996 * Description:
3997 * This function is called when a new PCI device gets detected and initializes
3998 * it.
3999 * Return value:
4000 * returns 0 on success and negative on failure.
4001 *
4002 */
4003static int __devinit
4004vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4005{
4006 struct __vxge_hw_device *hldev;
4007 enum vxge_hw_status status;
4008 int ret;
4009 int high_dma = 0;
4010 u64 vpath_mask = 0;
4011 struct vxgedev *vdev;
7dad171c 4012 struct vxge_config *ll_config = NULL;
703da5a1
RV
4013 struct vxge_hw_device_config *device_config = NULL;
4014 struct vxge_hw_device_attr attr;
4015 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4016 u8 *macaddr;
4017 struct vxge_mac_addrs *entry;
4018 static int bus = -1, device = -1;
cb27ec60 4019 u32 host_type;
703da5a1 4020 u8 new_device = 0;
cb27ec60
SH
4021 enum vxge_hw_status is_privileged;
4022 u32 function_mode;
4023 u32 num_vfs = 0;
703da5a1
RV
4024
4025 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4026 attr.pdev = pdev;
4027
cb27ec60
SH
4028 /* In SRIOV-17 mode, functions of the same adapter
4029 * can be deployed on different buses */
4030 if ((!pdev->is_virtfn) && ((bus != pdev->bus->number) ||
4031 (device != PCI_SLOT(pdev->devfn))))
703da5a1
RV
4032 new_device = 1;
4033
4034 bus = pdev->bus->number;
4035 device = PCI_SLOT(pdev->devfn);
4036
4037 if (new_device) {
4038 if (driver_config->config_dev_cnt &&
4039 (driver_config->config_dev_cnt !=
4040 driver_config->total_dev_cnt))
4041 vxge_debug_init(VXGE_ERR,
4042 "%s: Configured %d of %d devices",
4043 VXGE_DRIVER_NAME,
4044 driver_config->config_dev_cnt,
4045 driver_config->total_dev_cnt);
4046 driver_config->config_dev_cnt = 0;
4047 driver_config->total_dev_cnt = 0;
703da5a1 4048 }
9002397e
SH
4049 /* Now making the CPU based no of vpath calculation
4050 * applicable for individual functions as well.
4051 */
4052 driver_config->g_no_cpus = 0;
657205bd
SH
4053 driver_config->vpath_per_dev = max_config_vpath;
4054
703da5a1
RV
4055 driver_config->total_dev_cnt++;
4056 if (++driver_config->config_dev_cnt > max_config_dev) {
4057 ret = 0;
4058 goto _exit0;
4059 }
4060
4061 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4062 GFP_KERNEL);
4063 if (!device_config) {
4064 ret = -ENOMEM;
4065 vxge_debug_init(VXGE_ERR,
4066 "device_config : malloc failed %s %d",
4067 __FILE__, __LINE__);
4068 goto _exit0;
4069 }
4070
7dad171c
PB
4071 ll_config = kzalloc(sizeof(*ll_config), GFP_KERNEL);
4072 if (!ll_config) {
4073 ret = -ENOMEM;
4074 vxge_debug_init(VXGE_ERR,
4075 "ll_config : malloc failed %s %d",
4076 __FILE__, __LINE__);
4077 goto _exit0;
4078 }
4079 ll_config->tx_steering_type = TX_MULTIQ_STEERING;
4080 ll_config->intr_type = MSI_X;
4081 ll_config->napi_weight = NEW_NAPI_WEIGHT;
4082 ll_config->rth_steering = RTH_STEERING;
703da5a1
RV
4083
4084 /* get the default configuration parameters */
4085 vxge_hw_device_config_default_get(device_config);
4086
4087 /* initialize configuration parameters */
7dad171c 4088 vxge_device_config_init(device_config, &ll_config->intr_type);
703da5a1
RV
4089
4090 ret = pci_enable_device(pdev);
4091 if (ret) {
4092 vxge_debug_init(VXGE_ERR,
4093 "%s : can not enable PCI device", __func__);
4094 goto _exit0;
4095 }
4096
b3837cec 4097 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
703da5a1
RV
4098 vxge_debug_ll_config(VXGE_TRACE,
4099 "%s : using 64bit DMA", __func__);
4100
4101 high_dma = 1;
4102
4103 if (pci_set_consistent_dma_mask(pdev,
b3837cec 4104 DMA_BIT_MASK(64))) {
703da5a1
RV
4105 vxge_debug_init(VXGE_ERR,
4106 "%s : unable to obtain 64bit DMA for "
4107 "consistent allocations", __func__);
4108 ret = -ENOMEM;
4109 goto _exit1;
4110 }
b3837cec 4111 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
703da5a1
RV
4112 vxge_debug_ll_config(VXGE_TRACE,
4113 "%s : using 32bit DMA", __func__);
4114 } else {
4115 ret = -ENOMEM;
4116 goto _exit1;
4117 }
4118
4119 if (pci_request_regions(pdev, VXGE_DRIVER_NAME)) {
4120 vxge_debug_init(VXGE_ERR,
4121 "%s : request regions failed", __func__);
4122 ret = -ENODEV;
4123 goto _exit1;
4124 }
4125
4126 pci_set_master(pdev);
4127
4128 attr.bar0 = pci_ioremap_bar(pdev, 0);
4129 if (!attr.bar0) {
4130 vxge_debug_init(VXGE_ERR,
4131 "%s : cannot remap io memory bar0", __func__);
4132 ret = -ENODEV;
4133 goto _exit2;
4134 }
4135 vxge_debug_ll_config(VXGE_TRACE,
4136 "pci ioremap bar0: %p:0x%llx",
4137 attr.bar0,
4138 (unsigned long long)pci_resource_start(pdev, 0));
4139
703da5a1 4140 status = vxge_hw_device_hw_info_get(attr.bar0,
7dad171c 4141 &ll_config->device_hw_info);
703da5a1
RV
4142 if (status != VXGE_HW_OK) {
4143 vxge_debug_init(VXGE_ERR,
4144 "%s: Reading of hardware info failed."
4145 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4146 ret = -EINVAL;
7975d1ee 4147 goto _exit3;
703da5a1
RV
4148 }
4149
7dad171c 4150 if (ll_config->device_hw_info.fw_version.major !=
22fa125e 4151 VXGE_DRIVER_FW_VERSION_MAJOR) {
703da5a1 4152 vxge_debug_init(VXGE_ERR,
22fa125e
SH
4153 "%s: Incorrect firmware version."
4154 "Please upgrade the firmware to version 1.x.x",
4155 VXGE_DRIVER_NAME);
703da5a1 4156 ret = -EINVAL;
7975d1ee 4157 goto _exit3;
703da5a1
RV
4158 }
4159
7dad171c 4160 vpath_mask = ll_config->device_hw_info.vpath_mask;
703da5a1
RV
4161 if (vpath_mask == 0) {
4162 vxge_debug_ll_config(VXGE_TRACE,
4163 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4164 ret = -EINVAL;
7975d1ee 4165 goto _exit3;
703da5a1
RV
4166 }
4167
4168 vxge_debug_ll_config(VXGE_TRACE,
4169 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4170 (unsigned long long)vpath_mask);
4171
7dad171c
PB
4172 function_mode = ll_config->device_hw_info.function_mode;
4173 host_type = ll_config->device_hw_info.host_type;
cb27ec60 4174 is_privileged = __vxge_hw_device_is_privilaged(host_type,
7dad171c 4175 ll_config->device_hw_info.func_id);
cb27ec60 4176
703da5a1
RV
4177 /* Check how many vpaths are available */
4178 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4179 if (!((vpath_mask) & vxge_mBIT(i)))
4180 continue;
4181 max_vpath_supported++;
4182 }
4183
cb27ec60
SH
4184 if (new_device)
4185 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4186
5dbc9011 4187 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
cb27ec60 4188 if (is_sriov(function_mode) && (max_config_dev > 1) &&
7dad171c 4189 (ll_config->intr_type != INTA) &&
cb27ec60
SH
4190 (is_privileged == VXGE_HW_OK)) {
4191 ret = pci_enable_sriov(pdev, ((max_config_dev - 1) < num_vfs)
4192 ? (max_config_dev - 1) : num_vfs);
4193 if (ret)
4194 vxge_debug_ll_config(VXGE_ERR,
4195 "Failed in enabling SRIOV mode: %d\n", ret);
5dbc9011
SS
4196 }
4197
703da5a1
RV
4198 /*
4199 * Configure vpaths and get driver configured number of vpaths
4200 * which is less than or equal to the maximum vpaths per function.
4201 */
7dad171c 4202 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
703da5a1
RV
4203 if (!no_of_vpath) {
4204 vxge_debug_ll_config(VXGE_ERR,
4205 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4206 ret = 0;
7975d1ee 4207 goto _exit3;
703da5a1
RV
4208 }
4209
4210 /* Setting driver callbacks */
4211 attr.uld_callbacks.link_up = vxge_callback_link_up;
4212 attr.uld_callbacks.link_down = vxge_callback_link_down;
4213 attr.uld_callbacks.crit_err = vxge_callback_crit_err;
4214
4215 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4216 if (status != VXGE_HW_OK) {
4217 vxge_debug_init(VXGE_ERR,
4218 "Failed to initialize device (%d)", status);
4219 ret = -EINVAL;
7975d1ee 4220 goto _exit3;
703da5a1
RV
4221 }
4222
fa41fd10
SH
4223 /* if FCS stripping is not disabled in MAC fail driver load */
4224 if (vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask) != VXGE_HW_OK) {
4225 vxge_debug_init(VXGE_ERR,
4226 "%s: FCS stripping is not disabled in MAC"
4227 " failing driver load", VXGE_DRIVER_NAME);
4228 ret = -EINVAL;
4229 goto _exit4;
4230 }
4231
703da5a1
RV
4232 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4233
4234 /* set private device info */
4235 pci_set_drvdata(pdev, hldev);
4236
7dad171c
PB
4237 ll_config->gro_enable = VXGE_GRO_ALWAYS_AGGREGATE;
4238 ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4239 ll_config->addr_learn_en = addr_learn_en;
4240 ll_config->rth_algorithm = RTH_ALG_JENKINS;
4241 ll_config->rth_hash_type_tcpipv4 = VXGE_HW_RING_HASH_TYPE_TCP_IPV4;
4242 ll_config->rth_hash_type_ipv4 = VXGE_HW_RING_HASH_TYPE_NONE;
4243 ll_config->rth_hash_type_tcpipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
4244 ll_config->rth_hash_type_ipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
4245 ll_config->rth_hash_type_tcpipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
4246 ll_config->rth_hash_type_ipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
4247 ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
4248 ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4249 ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4250
4251 if (vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
703da5a1
RV
4252 &vdev)) {
4253 ret = -EINVAL;
7975d1ee 4254 goto _exit4;
703da5a1
RV
4255 }
4256
4257 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4258 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4259 vxge_hw_device_trace_level_get(hldev));
4260
4261 /* set private HW device info */
4262 hldev->ndev = vdev->ndev;
4263 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4264 vdev->bar0 = attr.bar0;
703da5a1
RV
4265 vdev->max_vpath_supported = max_vpath_supported;
4266 vdev->no_of_vpath = no_of_vpath;
4267
4268 /* Virtual Path count */
4269 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4270 if (!vxge_bVALn(vpath_mask, i, 1))
4271 continue;
4272 if (j >= vdev->no_of_vpath)
4273 break;
4274
4275 vdev->vpaths[j].is_configured = 1;
4276 vdev->vpaths[j].device_id = i;
4277 vdev->vpaths[j].fifo.driver_id = j;
4278 vdev->vpaths[j].ring.driver_id = j;
4279 vdev->vpaths[j].vdev = vdev;
4280 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4281 memcpy((u8 *)vdev->vpaths[j].macaddr,
7dad171c 4282 ll_config->device_hw_info.mac_addrs[i],
703da5a1
RV
4283 ETH_ALEN);
4284
4285 /* Initialize the mac address list header */
4286 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4287
4288 vdev->vpaths[j].mac_addr_cnt = 0;
4289 vdev->vpaths[j].mcast_addr_cnt = 0;
4290 j++;
4291 }
4292 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4293 vdev->max_config_port = max_config_port;
4294
4295 vdev->vlan_tag_strip = vlan_tag_strip;
4296
4297 /* map the hashing selector table to the configured vpaths */
4298 for (i = 0; i < vdev->no_of_vpath; i++)
4299 vdev->vpath_selector[i] = vpath_selector[i];
4300
4301 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4302
7dad171c
PB
4303 ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4304 ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4305 ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
703da5a1
RV
4306
4307 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
7dad171c 4308 vdev->ndev->name, ll_config->device_hw_info.serial_number);
703da5a1
RV
4309
4310 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
7dad171c 4311 vdev->ndev->name, ll_config->device_hw_info.part_number);
703da5a1
RV
4312
4313 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
7dad171c 4314 vdev->ndev->name, ll_config->device_hw_info.product_desc);
703da5a1 4315
bf54e736 4316 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4317 vdev->ndev->name, macaddr);
703da5a1
RV
4318
4319 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4320 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4321
4322 vxge_debug_init(VXGE_TRACE,
4323 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
7dad171c
PB
4324 ll_config->device_hw_info.fw_version.version,
4325 ll_config->device_hw_info.fw_date.date);
703da5a1 4326
0a25bdc6 4327 if (new_device) {
7dad171c 4328 switch (ll_config->device_hw_info.function_mode) {
0a25bdc6
SH
4329 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4330 vxge_debug_init(VXGE_TRACE,
4331 "%s: Single Function Mode Enabled", vdev->ndev->name);
4332 break;
4333 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4334 vxge_debug_init(VXGE_TRACE,
4335 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4336 break;
4337 case VXGE_HW_FUNCTION_MODE_SRIOV:
4338 vxge_debug_init(VXGE_TRACE,
4339 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4340 break;
4341 case VXGE_HW_FUNCTION_MODE_MRIOV:
4342 vxge_debug_init(VXGE_TRACE,
4343 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4344 break;
4345 }
4346 }
4347
703da5a1
RV
4348 vxge_print_parm(vdev, vpath_mask);
4349
4350 /* Store the fw version for ethttool option */
7dad171c 4351 strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
703da5a1
RV
4352 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4353 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4354
4355 /* Copy the station mac address to the list */
4356 for (i = 0; i < vdev->no_of_vpath; i++) {
4357 entry = (struct vxge_mac_addrs *)
4358 kzalloc(sizeof(struct vxge_mac_addrs),
4359 GFP_KERNEL);
4360 if (NULL == entry) {
4361 vxge_debug_init(VXGE_ERR,
4362 "%s: mac_addr_list : memory allocation failed",
4363 vdev->ndev->name);
4364 ret = -EPERM;
7975d1ee 4365 goto _exit5;
703da5a1
RV
4366 }
4367 macaddr = (u8 *)&entry->macaddr;
4368 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4369 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4370 vdev->vpaths[i].mac_addr_cnt = 1;
4371 }
4372
914d0d71 4373 kfree(device_config);
eb5f10c2
SH
4374
4375 /*
4376 * INTA is shared in multi-function mode. This is unlike the INTA
4377 * implementation in MR mode, where each VH has its own INTA message.
4378 * - INTA is masked (disabled) as long as at least one function sets
4379 * its TITAN_MASK_ALL_INT.ALARM bit.
4380 * - INTA is unmasked (enabled) when all enabled functions have cleared
4381 * their own TITAN_MASK_ALL_INT.ALARM bit.
4382 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4383 * Though this driver leaves the top level interrupts unmasked while
4384 * leaving the required module interrupt bits masked on exit, there
4385 * could be a rougue driver around that does not follow this procedure
4386 * resulting in a failure to generate interrupts. The following code is
4387 * present to prevent such a failure.
4388 */
4389
7dad171c 4390 if (ll_config->device_hw_info.function_mode ==
eb5f10c2
SH
4391 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4392 if (vdev->config.intr_type == INTA)
4393 vxge_hw_device_unmask_all(hldev);
4394
703da5a1
RV
4395 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4396 vdev->ndev->name, __func__, __LINE__);
4397
4398 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4399 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4400 vxge_hw_device_trace_level_get(hldev));
4401
7dad171c 4402 kfree(ll_config);
703da5a1
RV
4403 return 0;
4404
7975d1ee 4405_exit5:
703da5a1
RV
4406 for (i = 0; i < vdev->no_of_vpath; i++)
4407 vxge_free_mac_add_list(&vdev->vpaths[i]);
4408
4409 vxge_device_unregister(hldev);
7975d1ee 4410_exit4:
5dbc9011 4411 pci_disable_sriov(pdev);
703da5a1 4412 vxge_hw_device_terminate(hldev);
703da5a1
RV
4413_exit3:
4414 iounmap(attr.bar0);
4415_exit2:
4416 pci_release_regions(pdev);
4417_exit1:
4418 pci_disable_device(pdev);
4419_exit0:
7dad171c 4420 kfree(ll_config);
703da5a1
RV
4421 kfree(device_config);
4422 driver_config->config_dev_cnt--;
4423 pci_set_drvdata(pdev, NULL);
4424 return ret;
4425}
4426
4427/**
4428 * vxge_rem_nic - Free the PCI device
4429 * @pdev: structure containing the PCI related information of the device.
4430 * Description: This function is called by the Pci subsystem to release a
4431 * PCI device and free up all resource held up by the device.
4432 */
4433static void __devexit
4434vxge_remove(struct pci_dev *pdev)
4435{
4436 struct __vxge_hw_device *hldev;
4437 struct vxgedev *vdev = NULL;
4438 struct net_device *dev;
4439 int i = 0;
4440#if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4441 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4442 u32 level_trace;
4443#endif
4444
4445 hldev = (struct __vxge_hw_device *) pci_get_drvdata(pdev);
4446
4447 if (hldev == NULL)
4448 return;
4449 dev = hldev->ndev;
4450 vdev = netdev_priv(dev);
4451
4452#if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4453 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4454 level_trace = vdev->level_trace;
4455#endif
4456 vxge_debug_entryexit(level_trace,
4457 "%s:%d", __func__, __LINE__);
4458
4459 vxge_debug_init(level_trace,
4460 "%s : removing PCI device...", __func__);
4461 vxge_device_unregister(hldev);
4462
4463 for (i = 0; i < vdev->no_of_vpath; i++) {
4464 vxge_free_mac_add_list(&vdev->vpaths[i]);
4465 vdev->vpaths[i].mcast_addr_cnt = 0;
4466 vdev->vpaths[i].mac_addr_cnt = 0;
4467 }
4468
4469 kfree(vdev->vpaths);
4470
4471 iounmap(vdev->bar0);
703da5a1 4472
5dbc9011
SS
4473 pci_disable_sriov(pdev);
4474
703da5a1
RV
4475 /* we are safe to free it now */
4476 free_netdev(dev);
4477
4478 vxge_debug_init(level_trace,
4479 "%s:%d Device unregistered", __func__, __LINE__);
4480
4481 vxge_hw_device_terminate(hldev);
4482
4483 pci_disable_device(pdev);
4484 pci_release_regions(pdev);
4485 pci_set_drvdata(pdev, NULL);
4486 vxge_debug_entryexit(level_trace,
4487 "%s:%d Exiting...", __func__, __LINE__);
4488}
4489
4490static struct pci_error_handlers vxge_err_handler = {
4491 .error_detected = vxge_io_error_detected,
4492 .slot_reset = vxge_io_slot_reset,
4493 .resume = vxge_io_resume,
4494};
4495
4496static struct pci_driver vxge_driver = {
4497 .name = VXGE_DRIVER_NAME,
4498 .id_table = vxge_id_table,
4499 .probe = vxge_probe,
4500 .remove = __devexit_p(vxge_remove),
4501#ifdef CONFIG_PM
4502 .suspend = vxge_pm_suspend,
4503 .resume = vxge_pm_resume,
4504#endif
4505 .err_handler = &vxge_err_handler,
4506};
4507
4508static int __init
4509vxge_starter(void)
4510{
4511 int ret = 0;
4512 char version[32];
4513 snprintf(version, 32, "%s", DRV_VERSION);
4514
7074b16c 4515 printk(KERN_INFO "%s: Copyright(c) 2002-2009 Neterion Inc\n",
703da5a1 4516 VXGE_DRIVER_NAME);
7074b16c 4517 printk(KERN_INFO "%s: Driver version: %s\n",
703da5a1
RV
4518 VXGE_DRIVER_NAME, version);
4519
4520 verify_bandwidth();
4521
4522 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4523 if (!driver_config)
4524 return -ENOMEM;
4525
4526 ret = pci_register_driver(&vxge_driver);
4527
4528 if (driver_config->config_dev_cnt &&
4529 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4530 vxge_debug_init(VXGE_ERR,
4531 "%s: Configured %d of %d devices",
4532 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4533 driver_config->total_dev_cnt);
4534
4535 if (ret)
4536 kfree(driver_config);
4537
4538 return ret;
4539}
4540
4541static void __exit
4542vxge_closer(void)
4543{
4544 pci_unregister_driver(&vxge_driver);
4545 kfree(driver_config);
4546}
4547module_init(vxge_starter);
4548module_exit(vxge_closer);