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