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