blob: b504bd56136210776fa0d31e87a5e00b687cb03b [file] [log] [blame]
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001/******************************************************************************
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090046#include <linux/slab.h>
Alexander Beregalov2b05e002009-04-04 16:36:18 -070047#include <linux/tcp.h>
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000048#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
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000058static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000059 {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;
Benjamin LaHaiseff67df52009-08-04 10:21:03 +000091 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;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000096
Benjamin LaHaiseff67df52009-08-04 10:21:03 +000097 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) ;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000110}
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;
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000290 rx_priv->skb_data = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000291 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
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000310 rx_priv->skb_data = rx_priv->skb->data;
311 dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000312 rx_priv->data_size, PCI_DMA_FROMDEVICE);
313
Denis Kirjanovfa15e992010-01-10 13:40:10 -0800314 if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000315 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))
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +0000383 vlan_gro_receive(ring->napi_p, ring->vlgrp,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000384 ext_info->vlan, skb);
385 else
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +0000386 napi_gro_receive(ring->napi_p, skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000387 } 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
Sreenivasa Honnur33632762010-03-28 22:08:30 +0000448 vxge_hw_ring_replenish(ringh);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000449
450 do {
Benjamin LaHaise3f23e432009-08-04 10:21:39 +0000451 prefetch((char *)dtr + L1_CACHE_BYTES);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000452 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;
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000456 prefetch(rx_priv->skb_data);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000457
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
Sreenivasa Honnur22fa1252009-07-01 21:17:24 +0000465 pkt_length -= ETH_FCS_LEN;
466
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000467 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
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000592 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,
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000609 struct sk_buff ***skb_ptr, int nr_skb, int *more)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000610{
611 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000612 struct sk_buff *skb, **done_skb = *skb_ptr;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000613 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
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000665 *done_skb++ = skb;
666
667 if (--nr_skb <= 0) {
668 *more = 1;
669 break;
670 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000671
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
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000679 *skb_ptr = done_skb;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000680 vxge_wake_tx_queue(fifo, skb);
681
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000682 vxge_debug_entryexit(VXGE_TRACE,
683 "%s: %s:%d Exiting...",
684 fifo->ndev->name, __func__, __LINE__);
685 return VXGE_HW_OK;
686}
687
Eric Dumazet28679752009-05-27 19:26:37 +0000688/* select a vpath to transmit the packet */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000689static 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*/
Stephen Hemminger613573252009-08-31 19:50:58 +0000814static netdev_tx_t
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000815vxge_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;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000828 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
Benjamin LaHaise4403b372009-08-04 10:20:44 +0000904 /* 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
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000910 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) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000985 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);
Eric Dumazet28679752009-05-27 19:26:37 +00001004#ifdef NETIF_F_LLTX
1005 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
1006#endif
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001007 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__);
Patrick McHardy6ed10652009-06-23 06:03:08 +00001012 return NETDEV_TX_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001013
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
Patrick McHardy6ed10652009-06-23 06:03:08 +00001036 return NETDEV_TX_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001037}
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);
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +00001061 rx_priv->skb_data = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001062
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{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001121 struct netdev_hw_addr *ha;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001122 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 */
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001182 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001183
1184 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1185 list_head = &vdev->vpaths[0].mac_addr_list;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001186 if ((netdev_mc_count(dev) +
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001187 (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 */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001221 netdev_for_each_mc_addr(ha, dev) {
1222 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001223 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];
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001367 int msix_id = 0;
1368 int tim_msix_id[4] = {0, 1, 0, 0};
1369 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001370
1371 vxge_hw_vpath_intr_enable(vpath->handle);
1372
1373 if (vdev->config.intr_type == INTA)
1374 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1375 else {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001376 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1377 alarm_msix_id);
1378
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001379 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001380 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1381 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1382
1383 /* enable the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001384 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1385 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1386 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001387 }
1388}
1389
1390/*
1391 * vxge_vpath_intr_disable
1392 * @vdev: pointer to vdev
1393 * @vp_id: vpath for which to disable the interrupts
1394 *
1395 * Disables the interrupts for the vpath
1396*/
1397void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
1398{
1399 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1400 int msix_id;
1401
1402 vxge_hw_vpath_intr_disable(vpath->handle);
1403
1404 if (vdev->config.intr_type == INTA)
1405 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1406 else {
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001407 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001408 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1409 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1410
1411 /* disable the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001412 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1413 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001414 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1415 }
1416}
1417
1418/*
1419 * vxge_reset_vpath
1420 * @vdev: pointer to vdev
1421 * @vp_id: vpath to reset
1422 *
1423 * Resets the vpath
1424*/
1425static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1426{
1427 enum vxge_hw_status status = VXGE_HW_OK;
1428 int ret = 0;
1429
1430 /* check if device is down already */
1431 if (unlikely(!is_vxge_card_up(vdev)))
1432 return 0;
1433
1434 /* is device reset already scheduled */
1435 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1436 return 0;
1437
1438 if (vdev->vpaths[vp_id].handle) {
1439 if (vxge_hw_vpath_reset(vdev->vpaths[vp_id].handle)
1440 == VXGE_HW_OK) {
1441 if (is_vxge_card_up(vdev) &&
1442 vxge_hw_vpath_recover_from_reset(
1443 vdev->vpaths[vp_id].handle)
1444 != VXGE_HW_OK) {
1445 vxge_debug_init(VXGE_ERR,
1446 "vxge_hw_vpath_recover_from_reset"
1447 "failed for vpath:%d", vp_id);
1448 return status;
1449 }
1450 } else {
1451 vxge_debug_init(VXGE_ERR,
1452 "vxge_hw_vpath_reset failed for"
1453 "vpath:%d", vp_id);
1454 return status;
1455 }
1456 } else
1457 return VXGE_HW_FAIL;
1458
1459 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1460 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1461
1462 /* Enable all broadcast */
1463 vxge_hw_vpath_bcast_enable(vdev->vpaths[vp_id].handle);
1464
1465 /* Enable the interrupts */
1466 vxge_vpath_intr_enable(vdev, vp_id);
1467
1468 smp_wmb();
1469
1470 /* Enable the flow of traffic through the vpath */
1471 vxge_hw_vpath_enable(vdev->vpaths[vp_id].handle);
1472
1473 smp_wmb();
1474 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[vp_id].handle);
1475 vdev->vpaths[vp_id].ring.last_status = VXGE_HW_OK;
1476
1477 /* Vpath reset done */
1478 clear_bit(vp_id, &vdev->vp_reset);
1479
1480 /* Start the vpath queue */
1481 vxge_wake_tx_queue(&vdev->vpaths[vp_id].fifo, NULL);
1482
1483 return ret;
1484}
1485
1486static int do_vxge_reset(struct vxgedev *vdev, int event)
1487{
1488 enum vxge_hw_status status;
1489 int ret = 0, vp_id, i;
1490
1491 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1492
1493 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1494 /* check if device is down already */
1495 if (unlikely(!is_vxge_card_up(vdev)))
1496 return 0;
1497
1498 /* is reset already scheduled */
1499 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1500 return 0;
1501 }
1502
1503 if (event == VXGE_LL_FULL_RESET) {
1504 /* wait for all the vpath reset to complete */
1505 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1506 while (test_bit(vp_id, &vdev->vp_reset))
1507 msleep(50);
1508 }
1509
1510 /* if execution mode is set to debug, don't reset the adapter */
1511 if (unlikely(vdev->exec_mode)) {
1512 vxge_debug_init(VXGE_ERR,
1513 "%s: execution mode is debug, returning..",
1514 vdev->ndev->name);
1515 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1516 vxge_stop_all_tx_queue(vdev);
1517 return 0;
1518 }
1519 }
1520
1521 if (event == VXGE_LL_FULL_RESET) {
1522 vxge_hw_device_intr_disable(vdev->devh);
1523
1524 switch (vdev->cric_err_event) {
1525 case VXGE_HW_EVENT_UNKNOWN:
1526 vxge_stop_all_tx_queue(vdev);
1527 vxge_debug_init(VXGE_ERR,
1528 "fatal: %s: Disabling device due to"
1529 "unknown error",
1530 vdev->ndev->name);
1531 ret = -EPERM;
1532 goto out;
1533 case VXGE_HW_EVENT_RESET_START:
1534 break;
1535 case VXGE_HW_EVENT_RESET_COMPLETE:
1536 case VXGE_HW_EVENT_LINK_DOWN:
1537 case VXGE_HW_EVENT_LINK_UP:
1538 case VXGE_HW_EVENT_ALARM_CLEARED:
1539 case VXGE_HW_EVENT_ECCERR:
1540 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1541 ret = -EPERM;
1542 goto out;
1543 case VXGE_HW_EVENT_FIFO_ERR:
1544 case VXGE_HW_EVENT_VPATH_ERR:
1545 break;
1546 case VXGE_HW_EVENT_CRITICAL_ERR:
1547 vxge_stop_all_tx_queue(vdev);
1548 vxge_debug_init(VXGE_ERR,
1549 "fatal: %s: Disabling device due to"
1550 "serious error",
1551 vdev->ndev->name);
1552 /* SOP or device reset required */
1553 /* This event is not currently used */
1554 ret = -EPERM;
1555 goto out;
1556 case VXGE_HW_EVENT_SERR:
1557 vxge_stop_all_tx_queue(vdev);
1558 vxge_debug_init(VXGE_ERR,
1559 "fatal: %s: Disabling device due to"
1560 "serious error",
1561 vdev->ndev->name);
1562 ret = -EPERM;
1563 goto out;
1564 case VXGE_HW_EVENT_SRPCIM_SERR:
1565 case VXGE_HW_EVENT_MRPCIM_SERR:
1566 ret = -EPERM;
1567 goto out;
1568 case VXGE_HW_EVENT_SLOT_FREEZE:
1569 vxge_stop_all_tx_queue(vdev);
1570 vxge_debug_init(VXGE_ERR,
1571 "fatal: %s: Disabling device due to"
1572 "slot freeze",
1573 vdev->ndev->name);
1574 ret = -EPERM;
1575 goto out;
1576 default:
1577 break;
1578
1579 }
1580 }
1581
1582 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
1583 vxge_stop_all_tx_queue(vdev);
1584
1585 if (event == VXGE_LL_FULL_RESET) {
1586 status = vxge_reset_all_vpaths(vdev);
1587 if (status != VXGE_HW_OK) {
1588 vxge_debug_init(VXGE_ERR,
1589 "fatal: %s: can not reset vpaths",
1590 vdev->ndev->name);
1591 ret = -EPERM;
1592 goto out;
1593 }
1594 }
1595
1596 if (event == VXGE_LL_COMPL_RESET) {
1597 for (i = 0; i < vdev->no_of_vpath; i++)
1598 if (vdev->vpaths[i].handle) {
1599 if (vxge_hw_vpath_recover_from_reset(
1600 vdev->vpaths[i].handle)
1601 != VXGE_HW_OK) {
1602 vxge_debug_init(VXGE_ERR,
1603 "vxge_hw_vpath_recover_"
1604 "from_reset failed for vpath: "
1605 "%d", i);
1606 ret = -EPERM;
1607 goto out;
1608 }
1609 } else {
1610 vxge_debug_init(VXGE_ERR,
1611 "vxge_hw_vpath_reset failed for "
1612 "vpath:%d", i);
1613 ret = -EPERM;
1614 goto out;
1615 }
1616 }
1617
1618 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1619 /* Reprogram the DA table with populated mac addresses */
1620 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1621 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1622 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1623 }
1624
1625 /* enable vpath interrupts */
1626 for (i = 0; i < vdev->no_of_vpath; i++)
1627 vxge_vpath_intr_enable(vdev, i);
1628
1629 vxge_hw_device_intr_enable(vdev->devh);
1630
1631 smp_wmb();
1632
1633 /* Indicate card up */
1634 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1635
1636 /* Get the traffic to flow through the vpaths */
1637 for (i = 0; i < vdev->no_of_vpath; i++) {
1638 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1639 smp_wmb();
1640 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1641 }
1642
1643 vxge_wake_all_tx_queue(vdev);
1644 }
1645
1646out:
1647 vxge_debug_entryexit(VXGE_TRACE,
1648 "%s:%d Exiting...", __func__, __LINE__);
1649
1650 /* Indicate reset done */
1651 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1652 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1653 return ret;
1654}
1655
1656/*
1657 * vxge_reset
1658 * @vdev: pointer to ll device
1659 *
1660 * driver may reset the chip on events of serr, eccerr, etc
1661 */
1662int vxge_reset(struct vxgedev *vdev)
1663{
1664 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
1665 return 0;
1666}
1667
1668/**
1669 * vxge_poll - Receive handler when Receive Polling is used.
1670 * @dev: pointer to the device structure.
1671 * @budget: Number of packets budgeted to be processed in this iteration.
1672 *
1673 * This function comes into picture only if Receive side is being handled
1674 * through polling (called NAPI in linux). It mostly does what the normal
1675 * Rx interrupt handler does in terms of descriptor and packet processing
1676 * but not in an interrupt context. Also it will process a specified number
1677 * of packets at most in one iteration. This value is passed down by the
1678 * kernel as the function argument 'budget'.
1679 */
1680static int vxge_poll_msix(struct napi_struct *napi, int budget)
1681{
1682 struct vxge_ring *ring =
1683 container_of(napi, struct vxge_ring, napi);
1684 int budget_org = budget;
1685 ring->budget = budget;
1686
1687 vxge_hw_vpath_poll_rx(ring->handle);
1688
1689 if (ring->pkts_processed < budget_org) {
1690 napi_complete(napi);
1691 /* Re enable the Rx interrupts for the vpath */
1692 vxge_hw_channel_msix_unmask(
1693 (struct __vxge_hw_channel *)ring->handle,
1694 ring->rx_vector_no);
1695 }
1696
1697 return ring->pkts_processed;
1698}
1699
1700static int vxge_poll_inta(struct napi_struct *napi, int budget)
1701{
1702 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1703 int pkts_processed = 0;
1704 int i;
1705 int budget_org = budget;
1706 struct vxge_ring *ring;
1707
1708 struct __vxge_hw_device *hldev = (struct __vxge_hw_device *)
1709 pci_get_drvdata(vdev->pdev);
1710
1711 for (i = 0; i < vdev->no_of_vpath; i++) {
1712 ring = &vdev->vpaths[i].ring;
1713 ring->budget = budget;
1714 vxge_hw_vpath_poll_rx(ring->handle);
1715 pkts_processed += ring->pkts_processed;
1716 budget -= ring->pkts_processed;
1717 if (budget <= 0)
1718 break;
1719 }
1720
1721 VXGE_COMPLETE_ALL_TX(vdev);
1722
1723 if (pkts_processed < budget_org) {
1724 napi_complete(napi);
1725 /* Re enable the Rx interrupts for the ring */
1726 vxge_hw_device_unmask_all(hldev);
1727 vxge_hw_device_flush_io(hldev);
1728 }
1729
1730 return pkts_processed;
1731}
1732
1733#ifdef CONFIG_NET_POLL_CONTROLLER
1734/**
1735 * vxge_netpoll - netpoll event handler entry point
1736 * @dev : pointer to the device structure.
1737 * Description:
1738 * This function will be called by upper layer to check for events on the
1739 * interface in situations where interrupts are disabled. It is used for
1740 * specific in-kernel networking tasks, such as remote consoles and kernel
1741 * debugging over the network (example netdump in RedHat).
1742 */
1743static void vxge_netpoll(struct net_device *dev)
1744{
1745 struct __vxge_hw_device *hldev;
1746 struct vxgedev *vdev;
1747
1748 vdev = (struct vxgedev *)netdev_priv(dev);
1749 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
1750
1751 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1752
1753 if (pci_channel_offline(vdev->pdev))
1754 return;
1755
1756 disable_irq(dev->irq);
1757 vxge_hw_device_clear_tx_rx(hldev);
1758
1759 vxge_hw_device_clear_tx_rx(hldev);
1760 VXGE_COMPLETE_ALL_RX(vdev);
1761 VXGE_COMPLETE_ALL_TX(vdev);
1762
1763 enable_irq(dev->irq);
1764
1765 vxge_debug_entryexit(VXGE_TRACE,
1766 "%s:%d Exiting...", __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001767}
1768#endif
1769
1770/* RTH configuration */
1771static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1772{
1773 enum vxge_hw_status status = VXGE_HW_OK;
1774 struct vxge_hw_rth_hash_types hash_types;
1775 u8 itable[256] = {0}; /* indirection table */
1776 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1777 int index;
1778
1779 /*
1780 * Filling
1781 * - itable with bucket numbers
1782 * - mtable with bucket-to-vpath mapping
1783 */
1784 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1785 itable[index] = index;
1786 mtable[index] = index % vdev->no_of_vpath;
1787 }
1788
1789 /* Fill RTH hash types */
1790 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1791 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1792 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1793 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1794 hash_types.hash_type_tcpipv6ex_en =
1795 vdev->config.rth_hash_type_tcpipv6ex;
1796 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1797
1798 /* set indirection table, bucket-to-vpath mapping */
1799 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1800 vdev->no_of_vpath,
1801 mtable, itable,
1802 vdev->config.rth_bkt_sz);
1803 if (status != VXGE_HW_OK) {
1804 vxge_debug_init(VXGE_ERR,
1805 "RTH indirection table configuration failed "
1806 "for vpath:%d", vdev->vpaths[0].device_id);
1807 return status;
1808 }
1809
1810 /*
1811 * Because the itable_set() method uses the active_table field
1812 * for the target virtual path the RTH config should be updated
1813 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1814 * when steering frames.
1815 */
1816 for (index = 0; index < vdev->no_of_vpath; index++) {
1817 status = vxge_hw_vpath_rts_rth_set(
1818 vdev->vpaths[index].handle,
1819 vdev->config.rth_algorithm,
1820 &hash_types,
1821 vdev->config.rth_bkt_sz);
1822
1823 if (status != VXGE_HW_OK) {
1824 vxge_debug_init(VXGE_ERR,
1825 "RTH configuration failed for vpath:%d",
1826 vdev->vpaths[index].device_id);
1827 return status;
1828 }
1829 }
1830
1831 return status;
1832}
1833
1834int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
1835{
1836 struct vxge_mac_addrs *new_mac_entry;
1837 u8 *mac_address = NULL;
1838
1839 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
1840 return TRUE;
1841
1842 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
1843 if (!new_mac_entry) {
1844 vxge_debug_mem(VXGE_ERR,
1845 "%s: memory allocation failed",
1846 VXGE_DRIVER_NAME);
1847 return FALSE;
1848 }
1849
1850 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
1851
1852 /* Copy the new mac address to the list */
1853 mac_address = (u8 *)&new_mac_entry->macaddr;
1854 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1855
1856 new_mac_entry->state = mac->state;
1857 vpath->mac_addr_cnt++;
1858
1859 /* Is this a multicast address */
1860 if (0x01 & mac->macaddr[0])
1861 vpath->mcast_addr_cnt++;
1862
1863 return TRUE;
1864}
1865
1866/* Add a mac address to DA table */
1867enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1868{
1869 enum vxge_hw_status status = VXGE_HW_OK;
1870 struct vxge_vpath *vpath;
1871 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
1872
1873 if (0x01 & mac->macaddr[0]) /* multicast address */
1874 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
1875 else
1876 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
1877
1878 vpath = &vdev->vpaths[mac->vpath_no];
1879 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
1880 mac->macmask, duplicate_mode);
1881 if (status != VXGE_HW_OK) {
1882 vxge_debug_init(VXGE_ERR,
1883 "DA config add entry failed for vpath:%d",
1884 vpath->device_id);
1885 } else
1886 if (FALSE == vxge_mac_list_add(vpath, mac))
1887 status = -EPERM;
1888
1889 return status;
1890}
1891
1892int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1893{
1894 struct list_head *entry, *next;
1895 u64 del_mac = 0;
1896 u8 *mac_address = (u8 *) (&del_mac);
1897
1898 /* Copy the mac address to delete from the list */
1899 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1900
1901 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1902 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1903 list_del(entry);
1904 kfree((struct vxge_mac_addrs *)entry);
1905 vpath->mac_addr_cnt--;
1906
1907 /* Is this a multicast address */
1908 if (0x01 & mac->macaddr[0])
1909 vpath->mcast_addr_cnt--;
1910 return TRUE;
1911 }
1912 }
1913
1914 return FALSE;
1915}
1916/* delete a mac address from DA table */
1917enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1918{
1919 enum vxge_hw_status status = VXGE_HW_OK;
1920 struct vxge_vpath *vpath;
1921
1922 vpath = &vdev->vpaths[mac->vpath_no];
1923 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1924 mac->macmask);
1925 if (status != VXGE_HW_OK) {
1926 vxge_debug_init(VXGE_ERR,
1927 "DA config delete entry failed for vpath:%d",
1928 vpath->device_id);
1929 } else
1930 vxge_mac_list_del(vpath, mac);
1931 return status;
1932}
1933
1934/* list all mac addresses from DA table */
1935enum vxge_hw_status
1936static vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath,
1937 struct macInfo *mac)
1938{
1939 enum vxge_hw_status status = VXGE_HW_OK;
1940 unsigned char macmask[ETH_ALEN];
1941 unsigned char macaddr[ETH_ALEN];
1942
1943 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1944 macaddr, macmask);
1945 if (status != VXGE_HW_OK) {
1946 vxge_debug_init(VXGE_ERR,
1947 "DA config list entry failed for vpath:%d",
1948 vpath->device_id);
1949 return status;
1950 }
1951
1952 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1953
1954 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1955 macaddr, macmask);
1956 if (status != VXGE_HW_OK)
1957 break;
1958 }
1959
1960 return status;
1961}
1962
1963/* Store all vlan ids from the list to the vid table */
1964enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1965{
1966 enum vxge_hw_status status = VXGE_HW_OK;
1967 struct vxgedev *vdev = vpath->vdev;
1968 u16 vid;
1969
1970 if (vdev->vlgrp && vpath->is_open) {
1971
1972 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1973 if (!vlan_group_get_device(vdev->vlgrp, vid))
1974 continue;
1975 /* Add these vlan to the vid table */
1976 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
1977 }
1978 }
1979
1980 return status;
1981}
1982
1983/* Store all mac addresses from the list to the DA table */
1984enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1985{
1986 enum vxge_hw_status status = VXGE_HW_OK;
1987 struct macInfo mac_info;
1988 u8 *mac_address = NULL;
1989 struct list_head *entry, *next;
1990
1991 memset(&mac_info, 0, sizeof(struct macInfo));
1992
1993 if (vpath->is_open) {
1994
1995 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1996 mac_address =
1997 (u8 *)&
1998 ((struct vxge_mac_addrs *)entry)->macaddr;
1999 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
2000 ((struct vxge_mac_addrs *)entry)->state =
2001 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
2002 /* does this mac address already exist in da table? */
2003 status = vxge_search_mac_addr_in_da_table(vpath,
2004 &mac_info);
2005 if (status != VXGE_HW_OK) {
2006 /* Add this mac address to the DA table */
2007 status = vxge_hw_vpath_mac_addr_add(
2008 vpath->handle, mac_info.macaddr,
2009 mac_info.macmask,
2010 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
2011 if (status != VXGE_HW_OK) {
2012 vxge_debug_init(VXGE_ERR,
2013 "DA add entry failed for vpath:%d",
2014 vpath->device_id);
2015 ((struct vxge_mac_addrs *)entry)->state
2016 = VXGE_LL_MAC_ADDR_IN_LIST;
2017 }
2018 }
2019 }
2020 }
2021
2022 return status;
2023}
2024
2025/* reset vpaths */
2026enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
2027{
2028 int i;
2029 enum vxge_hw_status status = VXGE_HW_OK;
2030
2031 for (i = 0; i < vdev->no_of_vpath; i++)
2032 if (vdev->vpaths[i].handle) {
2033 if (vxge_hw_vpath_reset(vdev->vpaths[i].handle)
2034 == VXGE_HW_OK) {
2035 if (is_vxge_card_up(vdev) &&
2036 vxge_hw_vpath_recover_from_reset(
2037 vdev->vpaths[i].handle)
2038 != VXGE_HW_OK) {
2039 vxge_debug_init(VXGE_ERR,
2040 "vxge_hw_vpath_recover_"
2041 "from_reset failed for vpath: "
2042 "%d", i);
2043 return status;
2044 }
2045 } else {
2046 vxge_debug_init(VXGE_ERR,
2047 "vxge_hw_vpath_reset failed for "
2048 "vpath:%d", i);
2049 return status;
2050 }
2051 }
2052 return status;
2053}
2054
2055/* close vpaths */
2056void vxge_close_vpaths(struct vxgedev *vdev, int index)
2057{
2058 int i;
2059 for (i = index; i < vdev->no_of_vpath; i++) {
2060 if (vdev->vpaths[i].handle && vdev->vpaths[i].is_open) {
2061 vxge_hw_vpath_close(vdev->vpaths[i].handle);
2062 vdev->stats.vpaths_open--;
2063 }
2064 vdev->vpaths[i].is_open = 0;
2065 vdev->vpaths[i].handle = NULL;
2066 }
2067}
2068
2069/* open vpaths */
2070int vxge_open_vpaths(struct vxgedev *vdev)
2071{
2072 enum vxge_hw_status status;
2073 int i;
2074 u32 vp_id = 0;
2075 struct vxge_hw_vpath_attr attr;
2076
2077 for (i = 0; i < vdev->no_of_vpath; i++) {
2078 vxge_assert(vdev->vpaths[i].is_configured);
2079 attr.vp_id = vdev->vpaths[i].device_id;
2080 attr.fifo_attr.callback = vxge_xmit_compl;
2081 attr.fifo_attr.txdl_term = vxge_tx_term;
2082 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
2083 attr.fifo_attr.userdata = (void *)&vdev->vpaths[i].fifo;
2084
2085 attr.ring_attr.callback = vxge_rx_1b_compl;
2086 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2087 attr.ring_attr.rxd_term = vxge_rx_term;
2088 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
2089 attr.ring_attr.userdata = (void *)&vdev->vpaths[i].ring;
2090
2091 vdev->vpaths[i].ring.ndev = vdev->ndev;
2092 vdev->vpaths[i].ring.pdev = vdev->pdev;
2093 status = vxge_hw_vpath_open(vdev->devh, &attr,
2094 &(vdev->vpaths[i].handle));
2095 if (status == VXGE_HW_OK) {
2096 vdev->vpaths[i].fifo.handle =
2097 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
2098 vdev->vpaths[i].ring.handle =
2099 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
2100 vdev->vpaths[i].fifo.tx_steering_type =
2101 vdev->config.tx_steering_type;
2102 vdev->vpaths[i].fifo.ndev = vdev->ndev;
2103 vdev->vpaths[i].fifo.pdev = vdev->pdev;
2104 vdev->vpaths[i].fifo.indicate_max_pkts =
2105 vdev->config.fifo_indicate_max_pkts;
2106 vdev->vpaths[i].ring.rx_vector_no = 0;
2107 vdev->vpaths[i].ring.rx_csum = vdev->rx_csum;
2108 vdev->vpaths[i].is_open = 1;
2109 vdev->vp_handles[i] = vdev->vpaths[i].handle;
2110 vdev->vpaths[i].ring.gro_enable =
2111 vdev->config.gro_enable;
2112 vdev->vpaths[i].ring.vlan_tag_strip =
2113 vdev->vlan_tag_strip;
2114 vdev->stats.vpaths_open++;
2115 } else {
2116 vdev->stats.vpath_open_fail++;
2117 vxge_debug_init(VXGE_ERR,
2118 "%s: vpath: %d failed to open "
2119 "with status: %d",
2120 vdev->ndev->name, vdev->vpaths[i].device_id,
2121 status);
2122 vxge_close_vpaths(vdev, 0);
2123 return -EPERM;
2124 }
2125
2126 vp_id =
2127 ((struct __vxge_hw_vpath_handle *)vdev->vpaths[i].handle)->
2128 vpath->vp_id;
2129 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2130 }
2131 return VXGE_HW_OK;
2132}
2133
2134/*
2135 * vxge_isr_napi
2136 * @irq: the irq of the device.
2137 * @dev_id: a void pointer to the hldev structure of the Titan device
2138 * @ptregs: pointer to the registers pushed on the stack.
2139 *
2140 * This function is the ISR handler of the device when napi is enabled. It
2141 * identifies the reason for the interrupt and calls the relevant service
2142 * routines.
2143 */
2144static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2145{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002146 struct net_device *dev;
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002147 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002148 u64 reason;
2149 enum vxge_hw_status status;
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002150 struct vxgedev *vdev = (struct vxgedev *) dev_id;;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002151
2152 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2153
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002154 dev = vdev->ndev;
2155 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002156
2157 if (pci_channel_offline(vdev->pdev))
2158 return IRQ_NONE;
2159
2160 if (unlikely(!is_vxge_card_up(vdev)))
2161 return IRQ_NONE;
2162
2163 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode,
2164 &reason);
2165 if (status == VXGE_HW_OK) {
2166 vxge_hw_device_mask_all(hldev);
2167
2168 if (reason &
2169 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2170 vdev->vpaths_deployed >>
2171 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2172
2173 vxge_hw_device_clear_tx_rx(hldev);
2174 napi_schedule(&vdev->napi);
2175 vxge_debug_intr(VXGE_TRACE,
2176 "%s:%d Exiting...", __func__, __LINE__);
2177 return IRQ_HANDLED;
2178 } else
2179 vxge_hw_device_unmask_all(hldev);
2180 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2181 (status == VXGE_HW_ERR_CRITICAL) ||
2182 (status == VXGE_HW_ERR_FIFO))) {
2183 vxge_hw_device_mask_all(hldev);
2184 vxge_hw_device_flush_io(hldev);
2185 return IRQ_HANDLED;
2186 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2187 return IRQ_HANDLED;
2188
2189 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2190 return IRQ_NONE;
2191}
2192
2193#ifdef CONFIG_PCI_MSI
2194
2195static irqreturn_t
2196vxge_tx_msix_handle(int irq, void *dev_id)
2197{
2198 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2199
2200 VXGE_COMPLETE_VPATH_TX(fifo);
2201
2202 return IRQ_HANDLED;
2203}
2204
2205static irqreturn_t
2206vxge_rx_msix_napi_handle(int irq, void *dev_id)
2207{
2208 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2209
2210 /* MSIX_IDX for Rx is 1 */
2211 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
2212 ring->rx_vector_no);
2213
2214 napi_schedule(&ring->napi);
2215 return IRQ_HANDLED;
2216}
2217
2218static irqreturn_t
2219vxge_alarm_msix_handle(int irq, void *dev_id)
2220{
2221 int i;
2222 enum vxge_hw_status status;
2223 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2224 struct vxgedev *vdev = vpath->vdev;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002225 int msix_id = (vpath->handle->vpath->vp_id *
2226 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002227
2228 for (i = 0; i < vdev->no_of_vpath; i++) {
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002229 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002230
2231 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2232 vdev->exec_mode);
2233 if (status == VXGE_HW_OK) {
2234
2235 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002236 msix_id);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002237 continue;
2238 }
2239 vxge_debug_intr(VXGE_ERR,
2240 "%s: vxge_hw_vpath_alarm_process failed %x ",
2241 VXGE_DRIVER_NAME, status);
2242 }
2243 return IRQ_HANDLED;
2244}
2245
2246static int vxge_alloc_msix(struct vxgedev *vdev)
2247{
2248 int j, i, ret = 0;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002249 int msix_intr_vect = 0, temp;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002250 vdev->intr_cnt = 0;
2251
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002252start:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002253 /* Tx/Rx MSIX Vectors count */
2254 vdev->intr_cnt = vdev->no_of_vpath * 2;
2255
2256 /* Alarm MSIX Vectors count */
2257 vdev->intr_cnt++;
2258
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002259 vdev->entries = kzalloc(vdev->intr_cnt * sizeof(struct msix_entry),
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002260 GFP_KERNEL);
2261 if (!vdev->entries) {
2262 vxge_debug_init(VXGE_ERR,
2263 "%s: memory allocation failed",
2264 VXGE_DRIVER_NAME);
2265 return -ENOMEM;
2266 }
2267
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002268 vdev->vxge_entries =
2269 kzalloc(vdev->intr_cnt * sizeof(struct vxge_msix_entry),
2270 GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002271 if (!vdev->vxge_entries) {
2272 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2273 VXGE_DRIVER_NAME);
2274 kfree(vdev->entries);
2275 return -ENOMEM;
2276 }
2277
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002278 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002279
2280 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2281
2282 /* Initialize the fifo vector */
2283 vdev->entries[j].entry = msix_intr_vect;
2284 vdev->vxge_entries[j].entry = msix_intr_vect;
2285 vdev->vxge_entries[j].in_use = 0;
2286 j++;
2287
2288 /* Initialize the ring vector */
2289 vdev->entries[j].entry = msix_intr_vect + 1;
2290 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2291 vdev->vxge_entries[j].in_use = 0;
2292 j++;
2293 }
2294
2295 /* Initialize the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002296 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2297 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002298 vdev->vxge_entries[j].in_use = 0;
2299
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002300 ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt);
2301
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002302 if (ret > 0) {
2303 vxge_debug_init(VXGE_ERR,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002304 "%s: MSI-X enable failed for %d vectors, ret: %d",
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002305 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002306 kfree(vdev->entries);
2307 kfree(vdev->vxge_entries);
2308 vdev->entries = NULL;
2309 vdev->vxge_entries = NULL;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002310
2311 if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3))
2312 return -ENODEV;
2313 /* Try with less no of vector by reducing no of vpaths count */
2314 temp = (ret - 1)/2;
2315 vxge_close_vpaths(vdev, temp);
2316 vdev->no_of_vpath = temp;
2317 goto start;
2318 } else if (ret < 0)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002319 return -ENODEV;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002320
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002321 return 0;
2322}
2323
2324static int vxge_enable_msix(struct vxgedev *vdev)
2325{
2326
2327 int i, ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002328 /* 0 - Tx, 1 - Rx */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002329 int tim_msix_id[4] = {0, 1, 0, 0};
2330
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002331 vdev->intr_cnt = 0;
2332
2333 /* allocate msix vectors */
2334 ret = vxge_alloc_msix(vdev);
2335 if (!ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002336 for (i = 0; i < vdev->no_of_vpath; i++) {
2337
2338 /* If fifo or ring are not enabled
2339 the MSIX vector for that should be set to 0
2340 Hence initializeing this array to all 0s.
2341 */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002342 vdev->vpaths[i].ring.rx_vector_no =
2343 (vdev->vpaths[i].device_id *
2344 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002345
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002346 vxge_hw_vpath_msix_set(vdev->vpaths[i].handle,
2347 tim_msix_id, VXGE_ALARM_MSIX_ID);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002348 }
2349 }
2350
2351 return ret;
2352}
2353
2354static void vxge_rem_msix_isr(struct vxgedev *vdev)
2355{
2356 int intr_cnt;
2357
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002358 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002359 intr_cnt++) {
2360 if (vdev->vxge_entries[intr_cnt].in_use) {
2361 synchronize_irq(vdev->entries[intr_cnt].vector);
2362 free_irq(vdev->entries[intr_cnt].vector,
2363 vdev->vxge_entries[intr_cnt].arg);
2364 vdev->vxge_entries[intr_cnt].in_use = 0;
2365 }
2366 }
2367
2368 kfree(vdev->entries);
2369 kfree(vdev->vxge_entries);
2370 vdev->entries = NULL;
2371 vdev->vxge_entries = NULL;
2372
2373 if (vdev->config.intr_type == MSI_X)
2374 pci_disable_msix(vdev->pdev);
2375}
2376#endif
2377
2378static void vxge_rem_isr(struct vxgedev *vdev)
2379{
2380 struct __vxge_hw_device *hldev;
2381 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2382
2383#ifdef CONFIG_PCI_MSI
2384 if (vdev->config.intr_type == MSI_X) {
2385 vxge_rem_msix_isr(vdev);
2386 } else
2387#endif
2388 if (vdev->config.intr_type == INTA) {
2389 synchronize_irq(vdev->pdev->irq);
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002390 free_irq(vdev->pdev->irq, vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002391 }
2392}
2393
2394static int vxge_add_isr(struct vxgedev *vdev)
2395{
2396 int ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002397#ifdef CONFIG_PCI_MSI
2398 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002399 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2400
2401 if (vdev->config.intr_type == MSI_X)
2402 ret = vxge_enable_msix(vdev);
2403
2404 if (ret) {
2405 vxge_debug_init(VXGE_ERR,
2406 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002407 vxge_debug_init(VXGE_ERR,
2408 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2409 vdev->config.intr_type = INTA;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002410 }
2411
2412 if (vdev->config.intr_type == MSI_X) {
2413 for (intr_idx = 0;
2414 intr_idx < (vdev->no_of_vpath *
2415 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2416
2417 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2418 irq_req = 0;
2419
2420 switch (msix_idx) {
2421 case 0:
2422 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002423 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2424 vdev->ndev->name,
2425 vdev->entries[intr_cnt].entry,
2426 pci_fun, vp_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002427 ret = request_irq(
2428 vdev->entries[intr_cnt].vector,
2429 vxge_tx_msix_handle, 0,
2430 vdev->desc[intr_cnt],
2431 &vdev->vpaths[vp_idx].fifo);
2432 vdev->vxge_entries[intr_cnt].arg =
2433 &vdev->vpaths[vp_idx].fifo;
2434 irq_req = 1;
2435 break;
2436 case 1:
2437 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002438 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2439 vdev->ndev->name,
2440 vdev->entries[intr_cnt].entry,
2441 pci_fun, vp_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002442 ret = request_irq(
2443 vdev->entries[intr_cnt].vector,
2444 vxge_rx_msix_napi_handle,
2445 0,
2446 vdev->desc[intr_cnt],
2447 &vdev->vpaths[vp_idx].ring);
2448 vdev->vxge_entries[intr_cnt].arg =
2449 &vdev->vpaths[vp_idx].ring;
2450 irq_req = 1;
2451 break;
2452 }
2453
2454 if (ret) {
2455 vxge_debug_init(VXGE_ERR,
2456 "%s: MSIX - %d Registration failed",
2457 vdev->ndev->name, intr_cnt);
2458 vxge_rem_msix_isr(vdev);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002459 vdev->config.intr_type = INTA;
2460 vxge_debug_init(VXGE_ERR,
2461 "%s: Defaulting to INTA"
2462 , vdev->ndev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002463 goto INTA_MODE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002464 }
2465
2466 if (irq_req) {
2467 /* We requested for this msix interrupt */
2468 vdev->vxge_entries[intr_cnt].in_use = 1;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002469 msix_idx += vdev->vpaths[vp_idx].device_id *
2470 VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002471 vxge_hw_vpath_msix_unmask(
2472 vdev->vpaths[vp_idx].handle,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002473 msix_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002474 intr_cnt++;
2475 }
2476
2477 /* Point to next vpath handler */
Joe Perches8e95a202009-12-03 07:58:21 +00002478 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2479 (vp_idx < (vdev->no_of_vpath - 1)))
2480 vp_idx++;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002481 }
2482
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002483 intr_cnt = vdev->no_of_vpath * 2;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002484 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002485 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2486 vdev->ndev->name,
2487 vdev->entries[intr_cnt].entry,
2488 pci_fun);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002489 /* For Alarm interrupts */
2490 ret = request_irq(vdev->entries[intr_cnt].vector,
2491 vxge_alarm_msix_handle, 0,
2492 vdev->desc[intr_cnt],
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002493 &vdev->vpaths[0]);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002494 if (ret) {
2495 vxge_debug_init(VXGE_ERR,
2496 "%s: MSIX - %d Registration failed",
2497 vdev->ndev->name, intr_cnt);
2498 vxge_rem_msix_isr(vdev);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002499 vdev->config.intr_type = INTA;
2500 vxge_debug_init(VXGE_ERR,
2501 "%s: Defaulting to INTA",
2502 vdev->ndev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002503 goto INTA_MODE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002504 }
2505
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002506 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2507 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002508 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002509 msix_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002510 vdev->vxge_entries[intr_cnt].in_use = 1;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002511 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002512 }
2513INTA_MODE:
2514#endif
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002515
2516 if (vdev->config.intr_type == INTA) {
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002517 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2518 "%s:vxge:INTA", vdev->ndev->name);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002519 vxge_hw_device_set_intr_type(vdev->devh,
2520 VXGE_HW_INTR_MODE_IRQLINE);
2521 vxge_hw_vpath_tti_ci_set(vdev->devh,
2522 vdev->vpaths[0].device_id);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002523 ret = request_irq((int) vdev->pdev->irq,
2524 vxge_isr_napi,
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002525 IRQF_SHARED, vdev->desc[0], vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002526 if (ret) {
2527 vxge_debug_init(VXGE_ERR,
2528 "%s %s-%d: ISR registration failed",
2529 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2530 return -ENODEV;
2531 }
2532 vxge_debug_init(VXGE_TRACE,
2533 "new %s-%d line allocated",
2534 "IRQ", vdev->pdev->irq);
2535 }
2536
2537 return VXGE_HW_OK;
2538}
2539
2540static void vxge_poll_vp_reset(unsigned long data)
2541{
2542 struct vxgedev *vdev = (struct vxgedev *)data;
2543 int i, j = 0;
2544
2545 for (i = 0; i < vdev->no_of_vpath; i++) {
2546 if (test_bit(i, &vdev->vp_reset)) {
2547 vxge_reset_vpath(vdev, i);
2548 j++;
2549 }
2550 }
2551 if (j && (vdev->config.intr_type != MSI_X)) {
2552 vxge_hw_device_unmask_all(vdev->devh);
2553 vxge_hw_device_flush_io(vdev->devh);
2554 }
2555
2556 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2557}
2558
2559static void vxge_poll_vp_lockup(unsigned long data)
2560{
2561 struct vxgedev *vdev = (struct vxgedev *)data;
2562 int i;
2563 struct vxge_ring *ring;
2564 enum vxge_hw_status status = VXGE_HW_OK;
2565
2566 for (i = 0; i < vdev->no_of_vpath; i++) {
2567 ring = &vdev->vpaths[i].ring;
2568 /* Did this vpath received any packets */
2569 if (ring->stats.prev_rx_frms == ring->stats.rx_frms) {
2570 status = vxge_hw_vpath_check_leak(ring->handle);
2571
2572 /* Did it received any packets last time */
2573 if ((VXGE_HW_FAIL == status) &&
2574 (VXGE_HW_FAIL == ring->last_status)) {
2575
2576 /* schedule vpath reset */
2577 if (!test_and_set_bit(i, &vdev->vp_reset)) {
2578
2579 /* disable interrupts for this vpath */
2580 vxge_vpath_intr_disable(vdev, i);
2581
2582 /* stop the queue for this vpath */
2583 vxge_stop_tx_queue(&vdev->vpaths[i].
2584 fifo);
2585 continue;
2586 }
2587 }
2588 }
2589 ring->stats.prev_rx_frms = ring->stats.rx_frms;
2590 ring->last_status = status;
2591 }
2592
2593 /* Check every 1 milli second */
2594 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2595}
2596
2597/**
2598 * vxge_open
2599 * @dev: pointer to the device structure.
2600 *
2601 * This function is the open entry point of the driver. It mainly calls a
2602 * function to allocate Rx buffers and inserts them into the buffer
2603 * descriptors and then enables the Rx part of the NIC.
2604 * Return value: '0' on success and an appropriate (-)ve integer as
2605 * defined in errno.h file on failure.
2606 */
2607int
2608vxge_open(struct net_device *dev)
2609{
2610 enum vxge_hw_status status;
2611 struct vxgedev *vdev;
2612 struct __vxge_hw_device *hldev;
2613 int ret = 0;
2614 int i;
2615 u64 val64, function_mode;
2616 vxge_debug_entryexit(VXGE_TRACE,
2617 "%s: %s:%d", dev->name, __func__, __LINE__);
2618
2619 vdev = (struct vxgedev *)netdev_priv(dev);
2620 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2621 function_mode = vdev->config.device_hw_info.function_mode;
2622
2623 /* make sure you have link off by default every time Nic is
2624 * initialized */
2625 netif_carrier_off(dev);
2626
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002627 /* Open VPATHs */
2628 status = vxge_open_vpaths(vdev);
2629 if (status != VXGE_HW_OK) {
2630 vxge_debug_init(VXGE_ERR,
2631 "%s: fatal: Vpath open failed", vdev->ndev->name);
2632 ret = -EPERM;
2633 goto out0;
2634 }
2635
2636 vdev->mtu = dev->mtu;
2637
2638 status = vxge_add_isr(vdev);
2639 if (status != VXGE_HW_OK) {
2640 vxge_debug_init(VXGE_ERR,
2641 "%s: fatal: ISR add failed", dev->name);
2642 ret = -EPERM;
2643 goto out1;
2644 }
2645
2646
2647 if (vdev->config.intr_type != MSI_X) {
2648 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2649 vdev->config.napi_weight);
2650 napi_enable(&vdev->napi);
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002651 for (i = 0; i < vdev->no_of_vpath; i++)
2652 vdev->vpaths[i].ring.napi_p = &vdev->napi;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002653 } else {
2654 for (i = 0; i < vdev->no_of_vpath; i++) {
2655 netif_napi_add(dev, &vdev->vpaths[i].ring.napi,
2656 vxge_poll_msix, vdev->config.napi_weight);
2657 napi_enable(&vdev->vpaths[i].ring.napi);
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002658 vdev->vpaths[i].ring.napi_p =
2659 &vdev->vpaths[i].ring.napi;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002660 }
2661 }
2662
2663 /* configure RTH */
2664 if (vdev->config.rth_steering) {
2665 status = vxge_rth_configure(vdev);
2666 if (status != VXGE_HW_OK) {
2667 vxge_debug_init(VXGE_ERR,
2668 "%s: fatal: RTH configuration failed",
2669 dev->name);
2670 ret = -EPERM;
2671 goto out2;
2672 }
2673 }
2674
2675 for (i = 0; i < vdev->no_of_vpath; i++) {
2676 /* set initial mtu before enabling the device */
2677 status = vxge_hw_vpath_mtu_set(vdev->vpaths[i].handle,
2678 vdev->mtu);
2679 if (status != VXGE_HW_OK) {
2680 vxge_debug_init(VXGE_ERR,
2681 "%s: fatal: can not set new MTU", dev->name);
2682 ret = -EPERM;
2683 goto out2;
2684 }
2685 }
2686
2687 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2688 vxge_debug_init(vdev->level_trace,
2689 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2690 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2691
2692 /* Reprogram the DA table with populated mac addresses */
2693 for (i = 0; i < vdev->no_of_vpath; i++) {
2694 vxge_restore_vpath_mac_addr(&vdev->vpaths[i]);
2695 vxge_restore_vpath_vid_table(&vdev->vpaths[i]);
2696 }
2697
2698 /* Enable vpath to sniff all unicast/multicast traffic that not
2699 * addressed to them. We allow promiscous mode for PF only
2700 */
2701
2702 val64 = 0;
2703 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2704 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2705
2706 vxge_hw_mgmt_reg_write(vdev->devh,
2707 vxge_hw_mgmt_reg_type_mrpcim,
2708 0,
2709 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2710 rxmac_authorize_all_addr),
2711 val64);
2712
2713 vxge_hw_mgmt_reg_write(vdev->devh,
2714 vxge_hw_mgmt_reg_type_mrpcim,
2715 0,
2716 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2717 rxmac_authorize_all_vid),
2718 val64);
2719
2720 vxge_set_multicast(dev);
2721
2722 /* Enabling Bcast and mcast for all vpath */
2723 for (i = 0; i < vdev->no_of_vpath; i++) {
2724 status = vxge_hw_vpath_bcast_enable(vdev->vpaths[i].handle);
2725 if (status != VXGE_HW_OK)
2726 vxge_debug_init(VXGE_ERR,
2727 "%s : Can not enable bcast for vpath "
2728 "id %d", dev->name, i);
2729 if (vdev->config.addr_learn_en) {
2730 status =
2731 vxge_hw_vpath_mcast_enable(vdev->vpaths[i].handle);
2732 if (status != VXGE_HW_OK)
2733 vxge_debug_init(VXGE_ERR,
2734 "%s : Can not enable mcast for vpath "
2735 "id %d", dev->name, i);
2736 }
2737 }
2738
2739 vxge_hw_device_setpause_data(vdev->devh, 0,
2740 vdev->config.tx_pause_enable,
2741 vdev->config.rx_pause_enable);
2742
2743 if (vdev->vp_reset_timer.function == NULL)
2744 vxge_os_timer(vdev->vp_reset_timer,
2745 vxge_poll_vp_reset, vdev, (HZ/2));
2746
2747 if (vdev->vp_lockup_timer.function == NULL)
2748 vxge_os_timer(vdev->vp_lockup_timer,
2749 vxge_poll_vp_lockup, vdev, (HZ/2));
2750
2751 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2752
2753 smp_wmb();
2754
2755 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2756 netif_carrier_on(vdev->ndev);
2757 printk(KERN_NOTICE "%s: Link Up\n", vdev->ndev->name);
2758 vdev->stats.link_up++;
2759 }
2760
2761 vxge_hw_device_intr_enable(vdev->devh);
2762
2763 smp_wmb();
2764
2765 for (i = 0; i < vdev->no_of_vpath; i++) {
2766 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
2767 smp_wmb();
2768 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
2769 }
2770
2771 vxge_start_all_tx_queue(vdev);
2772 goto out0;
2773
2774out2:
2775 vxge_rem_isr(vdev);
2776
2777 /* Disable napi */
2778 if (vdev->config.intr_type != MSI_X)
2779 napi_disable(&vdev->napi);
2780 else {
2781 for (i = 0; i < vdev->no_of_vpath; i++)
2782 napi_disable(&vdev->vpaths[i].ring.napi);
2783 }
2784
2785out1:
2786 vxge_close_vpaths(vdev, 0);
2787out0:
2788 vxge_debug_entryexit(VXGE_TRACE,
2789 "%s: %s:%d Exiting...",
2790 dev->name, __func__, __LINE__);
2791 return ret;
2792}
2793
2794/* Loop throught the mac address list and delete all the entries */
2795void vxge_free_mac_add_list(struct vxge_vpath *vpath)
2796{
2797
2798 struct list_head *entry, *next;
2799 if (list_empty(&vpath->mac_addr_list))
2800 return;
2801
2802 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2803 list_del(entry);
2804 kfree((struct vxge_mac_addrs *)entry);
2805 }
2806}
2807
2808static void vxge_napi_del_all(struct vxgedev *vdev)
2809{
2810 int i;
2811 if (vdev->config.intr_type != MSI_X)
2812 netif_napi_del(&vdev->napi);
2813 else {
2814 for (i = 0; i < vdev->no_of_vpath; i++)
2815 netif_napi_del(&vdev->vpaths[i].ring.napi);
2816 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002817}
2818
2819int do_vxge_close(struct net_device *dev, int do_io)
2820{
2821 enum vxge_hw_status status;
2822 struct vxgedev *vdev;
2823 struct __vxge_hw_device *hldev;
2824 int i;
2825 u64 val64, vpath_vector;
2826 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2827 dev->name, __func__, __LINE__);
2828
2829 vdev = (struct vxgedev *)netdev_priv(dev);
2830 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2831
Sreenivasa Honnurbd9ee682009-07-01 21:14:03 +00002832 if (unlikely(!is_vxge_card_up(vdev)))
2833 return 0;
2834
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002835 /* If vxge_handle_crit_err task is executing,
2836 * wait till it completes. */
2837 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2838 msleep(50);
2839
2840 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2841 if (do_io) {
2842 /* Put the vpath back in normal mode */
2843 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2844 status = vxge_hw_mgmt_reg_read(vdev->devh,
2845 vxge_hw_mgmt_reg_type_mrpcim,
2846 0,
2847 (ulong)offsetof(
2848 struct vxge_hw_mrpcim_reg,
2849 rts_mgr_cbasin_cfg),
2850 &val64);
2851
2852 if (status == VXGE_HW_OK) {
2853 val64 &= ~vpath_vector;
2854 status = vxge_hw_mgmt_reg_write(vdev->devh,
2855 vxge_hw_mgmt_reg_type_mrpcim,
2856 0,
2857 (ulong)offsetof(
2858 struct vxge_hw_mrpcim_reg,
2859 rts_mgr_cbasin_cfg),
2860 val64);
2861 }
2862
2863 /* Remove the function 0 from promiscous mode */
2864 vxge_hw_mgmt_reg_write(vdev->devh,
2865 vxge_hw_mgmt_reg_type_mrpcim,
2866 0,
2867 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2868 rxmac_authorize_all_addr),
2869 0);
2870
2871 vxge_hw_mgmt_reg_write(vdev->devh,
2872 vxge_hw_mgmt_reg_type_mrpcim,
2873 0,
2874 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2875 rxmac_authorize_all_vid),
2876 0);
2877
2878 smp_wmb();
2879 }
2880 del_timer_sync(&vdev->vp_lockup_timer);
2881
2882 del_timer_sync(&vdev->vp_reset_timer);
2883
2884 /* Disable napi */
2885 if (vdev->config.intr_type != MSI_X)
2886 napi_disable(&vdev->napi);
2887 else {
2888 for (i = 0; i < vdev->no_of_vpath; i++)
2889 napi_disable(&vdev->vpaths[i].ring.napi);
2890 }
2891
2892 netif_carrier_off(vdev->ndev);
2893 printk(KERN_NOTICE "%s: Link Down\n", vdev->ndev->name);
2894 vxge_stop_all_tx_queue(vdev);
2895
2896 /* Note that at this point xmit() is stopped by upper layer */
2897 if (do_io)
2898 vxge_hw_device_intr_disable(vdev->devh);
2899
2900 mdelay(1000);
2901
2902 vxge_rem_isr(vdev);
2903
2904 vxge_napi_del_all(vdev);
2905
2906 if (do_io)
2907 vxge_reset_all_vpaths(vdev);
2908
2909 vxge_close_vpaths(vdev, 0);
2910
2911 vxge_debug_entryexit(VXGE_TRACE,
2912 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
2913
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002914 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
2915
2916 return 0;
2917}
2918
2919/**
2920 * vxge_close
2921 * @dev: device pointer.
2922 *
2923 * This is the stop entry point of the driver. It needs to undo exactly
2924 * whatever was done by the open entry point, thus it's usually referred to
2925 * as the close function.Among other things this function mainly stops the
2926 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
2927 * Return value: '0' on success and an appropriate (-)ve integer as
2928 * defined in errno.h file on failure.
2929 */
2930int
2931vxge_close(struct net_device *dev)
2932{
2933 do_vxge_close(dev, 1);
2934 return 0;
2935}
2936
2937/**
2938 * vxge_change_mtu
2939 * @dev: net device pointer.
2940 * @new_mtu :the new MTU size for the device.
2941 *
2942 * A driver entry point to change MTU size for the device. Before changing
2943 * the MTU the device must be stopped.
2944 */
2945static int vxge_change_mtu(struct net_device *dev, int new_mtu)
2946{
2947 struct vxgedev *vdev = netdev_priv(dev);
2948
2949 vxge_debug_entryexit(vdev->level_trace,
2950 "%s:%d", __func__, __LINE__);
2951 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
2952 vxge_debug_init(vdev->level_err,
2953 "%s: mtu size is invalid", dev->name);
2954 return -EPERM;
2955 }
2956
2957 /* check if device is down already */
2958 if (unlikely(!is_vxge_card_up(vdev))) {
2959 /* just store new value, will use later on open() */
2960 dev->mtu = new_mtu;
2961 vxge_debug_init(vdev->level_err,
2962 "%s", "device is down on MTU change");
2963 return 0;
2964 }
2965
2966 vxge_debug_init(vdev->level_trace,
2967 "trying to apply new MTU %d", new_mtu);
2968
2969 if (vxge_close(dev))
2970 return -EIO;
2971
2972 dev->mtu = new_mtu;
2973 vdev->mtu = new_mtu;
2974
2975 if (vxge_open(dev))
2976 return -EIO;
2977
2978 vxge_debug_init(vdev->level_trace,
2979 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
2980
2981 vxge_debug_entryexit(vdev->level_trace,
2982 "%s:%d Exiting...", __func__, __LINE__);
2983
2984 return 0;
2985}
2986
2987/**
2988 * vxge_get_stats
2989 * @dev: pointer to the device structure
2990 *
2991 * Updates the device statistics structure. This function updates the device
2992 * statistics structure in the net_device structure and returns a pointer
2993 * to the same.
2994 */
2995static struct net_device_stats *
2996vxge_get_stats(struct net_device *dev)
2997{
2998 struct vxgedev *vdev;
2999 struct net_device_stats *net_stats;
3000 int k;
3001
3002 vdev = netdev_priv(dev);
3003
3004 net_stats = &vdev->stats.net_stats;
3005
3006 memset(net_stats, 0, sizeof(struct net_device_stats));
3007
3008 for (k = 0; k < vdev->no_of_vpath; k++) {
3009 net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms;
3010 net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes;
3011 net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors;
3012 net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast;
3013 net_stats->rx_dropped +=
3014 vdev->vpaths[k].ring.stats.rx_dropped;
3015
3016 net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms;
3017 net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes;
3018 net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors;
3019 }
3020
3021 return net_stats;
3022}
3023
3024/**
3025 * vxge_ioctl
3026 * @dev: Device pointer.
3027 * @ifr: An IOCTL specific structure, that can contain a pointer to
3028 * a proprietary structure used to pass information to the driver.
3029 * @cmd: This is used to distinguish between the different commands that
3030 * can be passed to the IOCTL functions.
3031 *
3032 * Entry point for the Ioctl.
3033 */
3034static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3035{
3036 return -EOPNOTSUPP;
3037}
3038
3039/**
3040 * vxge_tx_watchdog
3041 * @dev: pointer to net device structure
3042 *
3043 * Watchdog for transmit side.
3044 * This function is triggered if the Tx Queue is stopped
3045 * for a pre-defined amount of time when the Interface is still up.
3046 */
3047static void
3048vxge_tx_watchdog(struct net_device *dev)
3049{
3050 struct vxgedev *vdev;
3051
3052 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3053
3054 vdev = (struct vxgedev *)netdev_priv(dev);
3055
3056 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3057
3058 vxge_reset(vdev);
3059 vxge_debug_entryexit(VXGE_TRACE,
3060 "%s:%d Exiting...", __func__, __LINE__);
3061}
3062
3063/**
3064 * vxge_vlan_rx_register
3065 * @dev: net device pointer.
3066 * @grp: vlan group
3067 *
3068 * Vlan group registration
3069 */
3070static void
3071vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
3072{
3073 struct vxgedev *vdev;
3074 struct vxge_vpath *vpath;
3075 int vp;
3076 u64 vid;
3077 enum vxge_hw_status status;
3078 int i;
3079
3080 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3081
3082 vdev = (struct vxgedev *)netdev_priv(dev);
3083
3084 vpath = &vdev->vpaths[0];
3085 if ((NULL == grp) && (vpath->is_open)) {
3086 /* Get the first vlan */
3087 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3088
3089 while (status == VXGE_HW_OK) {
3090
3091 /* Delete this vlan from the vid table */
3092 for (vp = 0; vp < vdev->no_of_vpath; vp++) {
3093 vpath = &vdev->vpaths[vp];
3094 if (!vpath->is_open)
3095 continue;
3096
3097 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3098 }
3099
3100 /* Get the next vlan to be deleted */
3101 vpath = &vdev->vpaths[0];
3102 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3103 }
3104 }
3105
3106 vdev->vlgrp = grp;
3107
3108 for (i = 0; i < vdev->no_of_vpath; i++) {
3109 if (vdev->vpaths[i].is_configured)
3110 vdev->vpaths[i].ring.vlgrp = grp;
3111 }
3112
3113 vxge_debug_entryexit(VXGE_TRACE,
3114 "%s:%d Exiting...", __func__, __LINE__);
3115}
3116
3117/**
3118 * vxge_vlan_rx_add_vid
3119 * @dev: net device pointer.
3120 * @vid: vid
3121 *
3122 * Add the vlan id to the devices vlan id table
3123 */
3124static void
3125vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3126{
3127 struct vxgedev *vdev;
3128 struct vxge_vpath *vpath;
3129 int vp_id;
3130
3131 vdev = (struct vxgedev *)netdev_priv(dev);
3132
3133 /* Add these vlan to the vid table */
3134 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3135 vpath = &vdev->vpaths[vp_id];
3136 if (!vpath->is_open)
3137 continue;
3138 vxge_hw_vpath_vid_add(vpath->handle, vid);
3139 }
3140}
3141
3142/**
3143 * vxge_vlan_rx_add_vid
3144 * @dev: net device pointer.
3145 * @vid: vid
3146 *
3147 * Remove the vlan id from the device's vlan id table
3148 */
3149static void
3150vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3151{
3152 struct vxgedev *vdev;
3153 struct vxge_vpath *vpath;
3154 int vp_id;
3155
3156 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3157
3158 vdev = (struct vxgedev *)netdev_priv(dev);
3159
3160 vlan_group_set_device(vdev->vlgrp, vid, NULL);
3161
3162 /* Delete this vlan from the vid table */
3163 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3164 vpath = &vdev->vpaths[vp_id];
3165 if (!vpath->is_open)
3166 continue;
3167 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3168 }
3169 vxge_debug_entryexit(VXGE_TRACE,
3170 "%s:%d Exiting...", __func__, __LINE__);
3171}
3172
3173static const struct net_device_ops vxge_netdev_ops = {
3174 .ndo_open = vxge_open,
3175 .ndo_stop = vxge_close,
3176 .ndo_get_stats = vxge_get_stats,
3177 .ndo_start_xmit = vxge_xmit,
3178 .ndo_validate_addr = eth_validate_addr,
3179 .ndo_set_multicast_list = vxge_set_multicast,
3180
3181 .ndo_do_ioctl = vxge_ioctl,
3182
3183 .ndo_set_mac_address = vxge_set_mac_addr,
3184 .ndo_change_mtu = vxge_change_mtu,
3185 .ndo_vlan_rx_register = vxge_vlan_rx_register,
3186 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3187 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
3188
3189 .ndo_tx_timeout = vxge_tx_watchdog,
3190#ifdef CONFIG_NET_POLL_CONTROLLER
3191 .ndo_poll_controller = vxge_netpoll,
3192#endif
3193};
3194
3195int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3196 struct vxge_config *config,
3197 int high_dma, int no_of_vpath,
3198 struct vxgedev **vdev_out)
3199{
3200 struct net_device *ndev;
3201 enum vxge_hw_status status = VXGE_HW_OK;
3202 struct vxgedev *vdev;
3203 int i, ret = 0, no_of_queue = 1;
3204 u64 stat;
3205
3206 *vdev_out = NULL;
3207 if (config->tx_steering_type == TX_MULTIQ_STEERING)
3208 no_of_queue = no_of_vpath;
3209
3210 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3211 no_of_queue);
3212 if (ndev == NULL) {
3213 vxge_debug_init(
3214 vxge_hw_device_trace_level_get(hldev),
3215 "%s : device allocation failed", __func__);
3216 ret = -ENODEV;
3217 goto _out0;
3218 }
3219
3220 vxge_debug_entryexit(
3221 vxge_hw_device_trace_level_get(hldev),
3222 "%s: %s:%d Entering...",
3223 ndev->name, __func__, __LINE__);
3224
3225 vdev = netdev_priv(ndev);
3226 memset(vdev, 0, sizeof(struct vxgedev));
3227
3228 vdev->ndev = ndev;
3229 vdev->devh = hldev;
3230 vdev->pdev = hldev->pdev;
3231 memcpy(&vdev->config, config, sizeof(struct vxge_config));
3232 vdev->rx_csum = 1; /* Enable Rx CSUM by default. */
3233
3234 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3235
3236 ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
3237 NETIF_F_HW_VLAN_FILTER;
3238 /* Driver entry points */
3239 ndev->irq = vdev->pdev->irq;
3240 ndev->base_addr = (unsigned long) hldev->bar0;
3241
3242 ndev->netdev_ops = &vxge_netdev_ops;
3243
3244 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
3245
3246 initialize_ethtool_ops(ndev);
3247
3248 /* Allocate memory for vpath */
3249 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3250 no_of_vpath, GFP_KERNEL);
3251 if (!vdev->vpaths) {
3252 vxge_debug_init(VXGE_ERR,
3253 "%s: vpath memory allocation failed",
3254 vdev->ndev->name);
3255 ret = -ENODEV;
3256 goto _out1;
3257 }
3258
3259 ndev->features |= NETIF_F_SG;
3260
3261 ndev->features |= NETIF_F_HW_CSUM;
3262 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3263 "%s : checksuming enabled", __func__);
3264
3265 if (high_dma) {
3266 ndev->features |= NETIF_F_HIGHDMA;
3267 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3268 "%s : using High DMA", __func__);
3269 }
3270
3271 ndev->features |= NETIF_F_TSO | NETIF_F_TSO6;
3272
3273 if (vdev->config.gro_enable)
3274 ndev->features |= NETIF_F_GRO;
3275
3276 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
3277 ndev->real_num_tx_queues = no_of_vpath;
3278
3279#ifdef NETIF_F_LLTX
3280 ndev->features |= NETIF_F_LLTX;
3281#endif
3282
3283 for (i = 0; i < no_of_vpath; i++)
3284 spin_lock_init(&vdev->vpaths[i].fifo.tx_lock);
3285
3286 if (register_netdev(ndev)) {
3287 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3288 "%s: %s : device registration failed!",
3289 ndev->name, __func__);
3290 ret = -ENODEV;
3291 goto _out2;
3292 }
3293
3294 /* Set the factory defined MAC address initially */
3295 ndev->addr_len = ETH_ALEN;
3296
3297 /* Make Link state as off at this point, when the Link change
3298 * interrupt comes the state will be automatically changed to
3299 * the right state.
3300 */
3301 netif_carrier_off(ndev);
3302
3303 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3304 "%s: Ethernet device registered",
3305 ndev->name);
3306
3307 *vdev_out = vdev;
3308
3309 /* Resetting the Device stats */
3310 status = vxge_hw_mrpcim_stats_access(
3311 hldev,
3312 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3313 0,
3314 0,
3315 &stat);
3316
3317 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3318 vxge_debug_init(
3319 vxge_hw_device_trace_level_get(hldev),
3320 "%s: device stats clear returns"
3321 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3322
3323 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3324 "%s: %s:%d Exiting...",
3325 ndev->name, __func__, __LINE__);
3326
3327 return ret;
3328_out2:
3329 kfree(vdev->vpaths);
3330_out1:
3331 free_netdev(ndev);
3332_out0:
3333 return ret;
3334}
3335
3336/*
3337 * vxge_device_unregister
3338 *
3339 * This function will unregister and free network device
3340 */
3341void
3342vxge_device_unregister(struct __vxge_hw_device *hldev)
3343{
3344 struct vxgedev *vdev;
3345 struct net_device *dev;
3346 char buf[IFNAMSIZ];
3347#if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3348 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3349 u32 level_trace;
3350#endif
3351
3352 dev = hldev->ndev;
3353 vdev = netdev_priv(dev);
3354#if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3355 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3356 level_trace = vdev->level_trace;
3357#endif
3358 vxge_debug_entryexit(level_trace,
3359 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3360
3361 memcpy(buf, vdev->ndev->name, IFNAMSIZ);
3362
3363 /* in 2.6 will call stop() if device is up */
3364 unregister_netdev(dev);
3365
3366 flush_scheduled_work();
3367
3368 vxge_debug_init(level_trace, "%s: ethernet device unregistered", buf);
3369 vxge_debug_entryexit(level_trace,
3370 "%s: %s:%d Exiting...", buf, __func__, __LINE__);
3371}
3372
3373/*
3374 * vxge_callback_crit_err
3375 *
3376 * This function is called by the alarm handler in interrupt context.
3377 * Driver must analyze it based on the event type.
3378 */
3379static void
3380vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3381 enum vxge_hw_event type, u64 vp_id)
3382{
3383 struct net_device *dev = hldev->ndev;
3384 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
3385 int vpath_idx;
3386
3387 vxge_debug_entryexit(vdev->level_trace,
3388 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3389
3390 /* Note: This event type should be used for device wide
3391 * indications only - Serious errors, Slot freeze and critical errors
3392 */
3393 vdev->cric_err_event = type;
3394
3395 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++)
3396 if (vdev->vpaths[vpath_idx].device_id == vp_id)
3397 break;
3398
3399 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3400 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3401 vxge_debug_init(VXGE_ERR,
3402 "%s: Slot is frozen", vdev->ndev->name);
3403 } else if (type == VXGE_HW_EVENT_SERR) {
3404 vxge_debug_init(VXGE_ERR,
3405 "%s: Encountered Serious Error",
3406 vdev->ndev->name);
3407 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3408 vxge_debug_init(VXGE_ERR,
3409 "%s: Encountered Critical Error",
3410 vdev->ndev->name);
3411 }
3412
3413 if ((type == VXGE_HW_EVENT_SERR) ||
3414 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3415 if (unlikely(vdev->exec_mode))
3416 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3417 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3418 vxge_hw_device_mask_all(hldev);
3419 if (unlikely(vdev->exec_mode))
3420 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3421 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3422 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3423
3424 if (unlikely(vdev->exec_mode))
3425 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3426 else {
3427 /* check if this vpath is already set for reset */
3428 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3429
3430 /* disable interrupts for this vpath */
3431 vxge_vpath_intr_disable(vdev, vpath_idx);
3432
3433 /* stop the queue for this vpath */
3434 vxge_stop_tx_queue(&vdev->vpaths[vpath_idx].
3435 fifo);
3436 }
3437 }
3438 }
3439
3440 vxge_debug_entryexit(vdev->level_trace,
3441 "%s: %s:%d Exiting...",
3442 vdev->ndev->name, __func__, __LINE__);
3443}
3444
3445static void verify_bandwidth(void)
3446{
3447 int i, band_width, total = 0, equal_priority = 0;
3448
3449 /* 1. If user enters 0 for some fifo, give equal priority to all */
3450 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3451 if (bw_percentage[i] == 0) {
3452 equal_priority = 1;
3453 break;
3454 }
3455 }
3456
3457 if (!equal_priority) {
3458 /* 2. If sum exceeds 100, give equal priority to all */
3459 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3460 if (bw_percentage[i] == 0xFF)
3461 break;
3462
3463 total += bw_percentage[i];
3464 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3465 equal_priority = 1;
3466 break;
3467 }
3468 }
3469 }
3470
3471 if (!equal_priority) {
3472 /* Is all the bandwidth consumed? */
3473 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3474 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3475 /* Split rest of bw equally among next VPs*/
3476 band_width =
3477 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3478 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3479 if (band_width < 2) /* min of 2% */
3480 equal_priority = 1;
3481 else {
3482 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3483 i++)
3484 bw_percentage[i] =
3485 band_width;
3486 }
3487 }
3488 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3489 equal_priority = 1;
3490 }
3491
3492 if (equal_priority) {
3493 vxge_debug_init(VXGE_ERR,
3494 "%s: Assigning equal bandwidth to all the vpaths",
3495 VXGE_DRIVER_NAME);
3496 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3497 VXGE_HW_MAX_VIRTUAL_PATHS;
3498 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3499 bw_percentage[i] = bw_percentage[0];
3500 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003501}
3502
3503/*
3504 * Vpath configuration
3505 */
3506static int __devinit vxge_config_vpaths(
3507 struct vxge_hw_device_config *device_config,
3508 u64 vpath_mask, struct vxge_config *config_param)
3509{
3510 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3511 u32 txdl_size, txdl_per_memblock;
3512
3513 temp = driver_config->vpath_per_dev;
3514 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3515 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3516 /* No more CPU. Return vpath number as zero.*/
3517 if (driver_config->g_no_cpus == -1)
3518 return 0;
3519
3520 if (!driver_config->g_no_cpus)
3521 driver_config->g_no_cpus = num_online_cpus();
3522
3523 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3524 if (!driver_config->vpath_per_dev)
3525 driver_config->vpath_per_dev = 1;
3526
3527 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3528 if (!vxge_bVALn(vpath_mask, i, 1))
3529 continue;
3530 else
3531 default_no_vpath++;
3532 if (default_no_vpath < driver_config->vpath_per_dev)
3533 driver_config->vpath_per_dev = default_no_vpath;
3534
3535 driver_config->g_no_cpus = driver_config->g_no_cpus -
3536 (driver_config->vpath_per_dev * 2);
3537 if (driver_config->g_no_cpus <= 0)
3538 driver_config->g_no_cpus = -1;
3539 }
3540
3541 if (driver_config->vpath_per_dev == 1) {
3542 vxge_debug_ll_config(VXGE_TRACE,
3543 "%s: Disable tx and rx steering, "
3544 "as single vpath is configured", VXGE_DRIVER_NAME);
3545 config_param->rth_steering = NO_STEERING;
3546 config_param->tx_steering_type = NO_STEERING;
3547 device_config->rth_en = 0;
3548 }
3549
3550 /* configure bandwidth */
3551 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3552 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3553
3554 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3555 device_config->vp_config[i].vp_id = i;
3556 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3557 if (no_of_vpaths < driver_config->vpath_per_dev) {
3558 if (!vxge_bVALn(vpath_mask, i, 1)) {
3559 vxge_debug_ll_config(VXGE_TRACE,
3560 "%s: vpath: %d is not available",
3561 VXGE_DRIVER_NAME, i);
3562 continue;
3563 } else {
3564 vxge_debug_ll_config(VXGE_TRACE,
3565 "%s: vpath: %d available",
3566 VXGE_DRIVER_NAME, i);
3567 no_of_vpaths++;
3568 }
3569 } else {
3570 vxge_debug_ll_config(VXGE_TRACE,
3571 "%s: vpath: %d is not configured, "
3572 "max_config_vpath exceeded",
3573 VXGE_DRIVER_NAME, i);
3574 break;
3575 }
3576
3577 /* Configure Tx fifo's */
3578 device_config->vp_config[i].fifo.enable =
3579 VXGE_HW_FIFO_ENABLE;
3580 device_config->vp_config[i].fifo.max_frags =
Sreenivasa Honnur5beefb42009-10-28 02:46:54 -07003581 MAX_SKB_FRAGS + 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003582 device_config->vp_config[i].fifo.memblock_size =
3583 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3584
Sreenivasa Honnur5beefb42009-10-28 02:46:54 -07003585 txdl_size = device_config->vp_config[i].fifo.max_frags *
3586 sizeof(struct vxge_hw_fifo_txd);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003587 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3588
3589 device_config->vp_config[i].fifo.fifo_blocks =
3590 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3591
3592 device_config->vp_config[i].fifo.intr =
3593 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3594
3595 /* Configure tti properties */
3596 device_config->vp_config[i].tti.intr_enable =
3597 VXGE_HW_TIM_INTR_ENABLE;
3598
3599 device_config->vp_config[i].tti.btimer_val =
3600 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3601
3602 device_config->vp_config[i].tti.timer_ac_en =
3603 VXGE_HW_TIM_TIMER_AC_ENABLE;
3604
3605 /* For msi-x with napi (each vector
3606 has a handler of its own) -
3607 Set CI to OFF for all vpaths */
3608 device_config->vp_config[i].tti.timer_ci_en =
3609 VXGE_HW_TIM_TIMER_CI_DISABLE;
3610
3611 device_config->vp_config[i].tti.timer_ri_en =
3612 VXGE_HW_TIM_TIMER_RI_DISABLE;
3613
3614 device_config->vp_config[i].tti.util_sel =
3615 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3616
3617 device_config->vp_config[i].tti.ltimer_val =
3618 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3619
3620 device_config->vp_config[i].tti.rtimer_val =
3621 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3622
3623 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3624 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3625 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3626 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3627 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3628 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3629 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3630
3631 /* Configure Rx rings */
3632 device_config->vp_config[i].ring.enable =
3633 VXGE_HW_RING_ENABLE;
3634
3635 device_config->vp_config[i].ring.ring_blocks =
3636 VXGE_HW_DEF_RING_BLOCKS;
3637 device_config->vp_config[i].ring.buffer_mode =
3638 VXGE_HW_RING_RXD_BUFFER_MODE_1;
3639 device_config->vp_config[i].ring.rxds_limit =
3640 VXGE_HW_DEF_RING_RXDS_LIMIT;
3641 device_config->vp_config[i].ring.scatter_mode =
3642 VXGE_HW_RING_SCATTER_MODE_A;
3643
3644 /* Configure rti properties */
3645 device_config->vp_config[i].rti.intr_enable =
3646 VXGE_HW_TIM_INTR_ENABLE;
3647
3648 device_config->vp_config[i].rti.btimer_val =
3649 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3650
3651 device_config->vp_config[i].rti.timer_ac_en =
3652 VXGE_HW_TIM_TIMER_AC_ENABLE;
3653
3654 device_config->vp_config[i].rti.timer_ci_en =
3655 VXGE_HW_TIM_TIMER_CI_DISABLE;
3656
3657 device_config->vp_config[i].rti.timer_ri_en =
3658 VXGE_HW_TIM_TIMER_RI_DISABLE;
3659
3660 device_config->vp_config[i].rti.util_sel =
3661 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3662
3663 device_config->vp_config[i].rti.urange_a =
3664 RTI_RX_URANGE_A;
3665 device_config->vp_config[i].rti.urange_b =
3666 RTI_RX_URANGE_B;
3667 device_config->vp_config[i].rti.urange_c =
3668 RTI_RX_URANGE_C;
3669 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3670 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3671 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3672 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3673
3674 device_config->vp_config[i].rti.rtimer_val =
3675 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3676
3677 device_config->vp_config[i].rti.ltimer_val =
3678 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3679
3680 device_config->vp_config[i].rpa_strip_vlan_tag =
3681 vlan_tag_strip;
3682 }
3683
3684 driver_config->vpath_per_dev = temp;
3685 return no_of_vpaths;
3686}
3687
3688/* initialize device configuratrions */
3689static void __devinit vxge_device_config_init(
3690 struct vxge_hw_device_config *device_config,
3691 int *intr_type)
3692{
3693 /* Used for CQRQ/SRQ. */
3694 device_config->dma_blockpool_initial =
3695 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3696
3697 device_config->dma_blockpool_max =
3698 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3699
3700 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3701 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3702
3703#ifndef CONFIG_PCI_MSI
3704 vxge_debug_init(VXGE_ERR,
3705 "%s: This Kernel does not support "
3706 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3707 *intr_type = INTA;
3708#endif
3709
3710 /* Configure whether MSI-X or IRQL. */
3711 switch (*intr_type) {
3712 case INTA:
3713 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3714 break;
3715
3716 case MSI_X:
3717 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX;
3718 break;
3719 }
3720 /* Timer period between device poll */
3721 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3722
3723 /* Configure mac based steering. */
3724 device_config->rts_mac_en = addr_learn_en;
3725
3726 /* Configure Vpaths */
3727 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3728
3729 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3730 __func__);
3731 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_initial : %d",
3732 device_config->dma_blockpool_initial);
3733 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_max : %d",
3734 device_config->dma_blockpool_max);
3735 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3736 device_config->intr_mode);
3737 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3738 device_config->device_poll_millis);
3739 vxge_debug_ll_config(VXGE_TRACE, "rts_mac_en : %d",
3740 device_config->rts_mac_en);
3741 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3742 device_config->rth_en);
3743 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3744 device_config->rth_it_type);
3745}
3746
3747static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3748{
3749 int i;
3750
3751 vxge_debug_init(VXGE_TRACE,
3752 "%s: %d Vpath(s) opened",
3753 vdev->ndev->name, vdev->no_of_vpath);
3754
3755 switch (vdev->config.intr_type) {
3756 case INTA:
3757 vxge_debug_init(VXGE_TRACE,
3758 "%s: Interrupt type INTA", vdev->ndev->name);
3759 break;
3760
3761 case MSI_X:
3762 vxge_debug_init(VXGE_TRACE,
3763 "%s: Interrupt type MSI-X", vdev->ndev->name);
3764 break;
3765 }
3766
3767 if (vdev->config.rth_steering) {
3768 vxge_debug_init(VXGE_TRACE,
3769 "%s: RTH steering enabled for TCP_IPV4",
3770 vdev->ndev->name);
3771 } else {
3772 vxge_debug_init(VXGE_TRACE,
3773 "%s: RTH steering disabled", vdev->ndev->name);
3774 }
3775
3776 switch (vdev->config.tx_steering_type) {
3777 case NO_STEERING:
3778 vxge_debug_init(VXGE_TRACE,
3779 "%s: Tx steering disabled", vdev->ndev->name);
3780 break;
3781 case TX_PRIORITY_STEERING:
3782 vxge_debug_init(VXGE_TRACE,
3783 "%s: Unsupported tx steering option",
3784 vdev->ndev->name);
3785 vxge_debug_init(VXGE_TRACE,
3786 "%s: Tx steering disabled", vdev->ndev->name);
3787 vdev->config.tx_steering_type = 0;
3788 break;
3789 case TX_VLAN_STEERING:
3790 vxge_debug_init(VXGE_TRACE,
3791 "%s: Unsupported tx steering option",
3792 vdev->ndev->name);
3793 vxge_debug_init(VXGE_TRACE,
3794 "%s: Tx steering disabled", vdev->ndev->name);
3795 vdev->config.tx_steering_type = 0;
3796 break;
3797 case TX_MULTIQ_STEERING:
3798 vxge_debug_init(VXGE_TRACE,
3799 "%s: Tx multiqueue steering enabled",
3800 vdev->ndev->name);
3801 break;
3802 case TX_PORT_STEERING:
3803 vxge_debug_init(VXGE_TRACE,
3804 "%s: Tx port steering enabled",
3805 vdev->ndev->name);
3806 break;
3807 default:
3808 vxge_debug_init(VXGE_ERR,
3809 "%s: Unsupported tx steering type",
3810 vdev->ndev->name);
3811 vxge_debug_init(VXGE_TRACE,
3812 "%s: Tx steering disabled", vdev->ndev->name);
3813 vdev->config.tx_steering_type = 0;
3814 }
3815
3816 if (vdev->config.gro_enable) {
3817 vxge_debug_init(VXGE_ERR,
3818 "%s: Generic receive offload enabled",
3819 vdev->ndev->name);
3820 } else
3821 vxge_debug_init(VXGE_TRACE,
3822 "%s: Generic receive offload disabled",
3823 vdev->ndev->name);
3824
3825 if (vdev->config.addr_learn_en)
3826 vxge_debug_init(VXGE_TRACE,
3827 "%s: MAC Address learning enabled", vdev->ndev->name);
3828
3829 vxge_debug_init(VXGE_TRACE,
3830 "%s: Rx doorbell mode enabled", vdev->ndev->name);
3831
3832 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3833 if (!vxge_bVALn(vpath_mask, i, 1))
3834 continue;
3835 vxge_debug_ll_config(VXGE_TRACE,
3836 "%s: MTU size - %d", vdev->ndev->name,
3837 ((struct __vxge_hw_device *)(vdev->devh))->
3838 config.vp_config[i].mtu);
3839 vxge_debug_init(VXGE_TRACE,
3840 "%s: VLAN tag stripping %s", vdev->ndev->name,
3841 ((struct __vxge_hw_device *)(vdev->devh))->
3842 config.vp_config[i].rpa_strip_vlan_tag
3843 ? "Enabled" : "Disabled");
3844 vxge_debug_init(VXGE_TRACE,
3845 "%s: Ring blocks : %d", vdev->ndev->name,
3846 ((struct __vxge_hw_device *)(vdev->devh))->
3847 config.vp_config[i].ring.ring_blocks);
3848 vxge_debug_init(VXGE_TRACE,
3849 "%s: Fifo blocks : %d", vdev->ndev->name,
3850 ((struct __vxge_hw_device *)(vdev->devh))->
3851 config.vp_config[i].fifo.fifo_blocks);
3852 vxge_debug_ll_config(VXGE_TRACE,
3853 "%s: Max frags : %d", vdev->ndev->name,
3854 ((struct __vxge_hw_device *)(vdev->devh))->
3855 config.vp_config[i].fifo.max_frags);
3856 break;
3857 }
3858}
3859
3860#ifdef CONFIG_PM
3861/**
3862 * vxge_pm_suspend - vxge power management suspend entry point
3863 *
3864 */
3865static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
3866{
3867 return -ENOSYS;
3868}
3869/**
3870 * vxge_pm_resume - vxge power management resume entry point
3871 *
3872 */
3873static int vxge_pm_resume(struct pci_dev *pdev)
3874{
3875 return -ENOSYS;
3876}
3877
3878#endif
3879
3880/**
3881 * vxge_io_error_detected - called when PCI error is detected
3882 * @pdev: Pointer to PCI device
3883 * @state: The current pci connection state
3884 *
3885 * This function is called after a PCI bus error affecting
3886 * this device has been detected.
3887 */
3888static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
3889 pci_channel_state_t state)
3890{
3891 struct __vxge_hw_device *hldev =
3892 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3893 struct net_device *netdev = hldev->ndev;
3894
3895 netif_device_detach(netdev);
3896
Dean Nelsone33b9922009-07-31 09:14:03 +00003897 if (state == pci_channel_io_perm_failure)
3898 return PCI_ERS_RESULT_DISCONNECT;
3899
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003900 if (netif_running(netdev)) {
3901 /* Bring down the card, while avoiding PCI I/O */
3902 do_vxge_close(netdev, 0);
3903 }
3904
3905 pci_disable_device(pdev);
3906
3907 return PCI_ERS_RESULT_NEED_RESET;
3908}
3909
3910/**
3911 * vxge_io_slot_reset - called after the pci bus has been reset.
3912 * @pdev: Pointer to PCI device
3913 *
3914 * Restart the card from scratch, as if from a cold-boot.
3915 * At this point, the card has exprienced a hard reset,
3916 * followed by fixups by BIOS, and has its config space
3917 * set up identically to what it was at cold boot.
3918 */
3919static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
3920{
3921 struct __vxge_hw_device *hldev =
3922 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3923 struct net_device *netdev = hldev->ndev;
3924
3925 struct vxgedev *vdev = netdev_priv(netdev);
3926
3927 if (pci_enable_device(pdev)) {
3928 printk(KERN_ERR "%s: "
3929 "Cannot re-enable device after reset\n",
3930 VXGE_DRIVER_NAME);
3931 return PCI_ERS_RESULT_DISCONNECT;
3932 }
3933
3934 pci_set_master(pdev);
3935 vxge_reset(vdev);
3936
3937 return PCI_ERS_RESULT_RECOVERED;
3938}
3939
3940/**
3941 * vxge_io_resume - called when traffic can start flowing again.
3942 * @pdev: Pointer to PCI device
3943 *
3944 * This callback is called when the error recovery driver tells
3945 * us that its OK to resume normal operation.
3946 */
3947static void vxge_io_resume(struct pci_dev *pdev)
3948{
3949 struct __vxge_hw_device *hldev =
3950 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3951 struct net_device *netdev = hldev->ndev;
3952
3953 if (netif_running(netdev)) {
3954 if (vxge_open(netdev)) {
3955 printk(KERN_ERR "%s: "
3956 "Can't bring device back up after reset\n",
3957 VXGE_DRIVER_NAME);
3958 return;
3959 }
3960 }
3961
3962 netif_device_attach(netdev);
3963}
3964
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07003965static inline u32 vxge_get_num_vfs(u64 function_mode)
3966{
3967 u32 num_functions = 0;
3968
3969 switch (function_mode) {
3970 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
3971 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
3972 num_functions = 8;
3973 break;
3974 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
3975 num_functions = 1;
3976 break;
3977 case VXGE_HW_FUNCTION_MODE_SRIOV:
3978 case VXGE_HW_FUNCTION_MODE_MRIOV:
3979 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
3980 num_functions = 17;
3981 break;
3982 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
3983 num_functions = 4;
3984 break;
3985 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
3986 num_functions = 2;
3987 break;
3988 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
3989 num_functions = 8; /* TODO */
3990 break;
3991 }
3992 return num_functions;
3993}
3994
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003995/**
3996 * vxge_probe
3997 * @pdev : structure containing the PCI related information of the device.
3998 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
3999 * Description:
4000 * This function is called when a new PCI device gets detected and initializes
4001 * it.
4002 * Return value:
4003 * returns 0 on success and negative on failure.
4004 *
4005 */
4006static int __devinit
4007vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4008{
4009 struct __vxge_hw_device *hldev;
4010 enum vxge_hw_status status;
4011 int ret;
4012 int high_dma = 0;
4013 u64 vpath_mask = 0;
4014 struct vxgedev *vdev;
4015 struct vxge_config ll_config;
4016 struct vxge_hw_device_config *device_config = NULL;
4017 struct vxge_hw_device_attr attr;
4018 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4019 u8 *macaddr;
4020 struct vxge_mac_addrs *entry;
4021 static int bus = -1, device = -1;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004022 u32 host_type;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004023 u8 new_device = 0;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004024 enum vxge_hw_status is_privileged;
4025 u32 function_mode;
4026 u32 num_vfs = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004027
4028 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4029 attr.pdev = pdev;
4030
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004031 /* In SRIOV-17 mode, functions of the same adapter
4032 * can be deployed on different buses */
4033 if ((!pdev->is_virtfn) && ((bus != pdev->bus->number) ||
4034 (device != PCI_SLOT(pdev->devfn))))
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004035 new_device = 1;
4036
4037 bus = pdev->bus->number;
4038 device = PCI_SLOT(pdev->devfn);
4039
4040 if (new_device) {
4041 if (driver_config->config_dev_cnt &&
4042 (driver_config->config_dev_cnt !=
4043 driver_config->total_dev_cnt))
4044 vxge_debug_init(VXGE_ERR,
4045 "%s: Configured %d of %d devices",
4046 VXGE_DRIVER_NAME,
4047 driver_config->config_dev_cnt,
4048 driver_config->total_dev_cnt);
4049 driver_config->config_dev_cnt = 0;
4050 driver_config->total_dev_cnt = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004051 }
Sreenivasa Honnur90023972010-04-08 01:48:30 -07004052 /* Now making the CPU based no of vpath calculation
4053 * applicable for individual functions as well.
4054 */
4055 driver_config->g_no_cpus = 0;
Sreenivasa Honnur657205b2009-10-05 01:52:54 +00004056 driver_config->vpath_per_dev = max_config_vpath;
4057
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004058 driver_config->total_dev_cnt++;
4059 if (++driver_config->config_dev_cnt > max_config_dev) {
4060 ret = 0;
4061 goto _exit0;
4062 }
4063
4064 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4065 GFP_KERNEL);
4066 if (!device_config) {
4067 ret = -ENOMEM;
4068 vxge_debug_init(VXGE_ERR,
4069 "device_config : malloc failed %s %d",
4070 __FILE__, __LINE__);
4071 goto _exit0;
4072 }
4073
4074 memset(&ll_config, 0, sizeof(struct vxge_config));
4075 ll_config.tx_steering_type = TX_MULTIQ_STEERING;
4076 ll_config.intr_type = MSI_X;
4077 ll_config.napi_weight = NEW_NAPI_WEIGHT;
4078 ll_config.rth_steering = RTH_STEERING;
4079
4080 /* get the default configuration parameters */
4081 vxge_hw_device_config_default_get(device_config);
4082
4083 /* initialize configuration parameters */
4084 vxge_device_config_init(device_config, &ll_config.intr_type);
4085
4086 ret = pci_enable_device(pdev);
4087 if (ret) {
4088 vxge_debug_init(VXGE_ERR,
4089 "%s : can not enable PCI device", __func__);
4090 goto _exit0;
4091 }
4092
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004093 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004094 vxge_debug_ll_config(VXGE_TRACE,
4095 "%s : using 64bit DMA", __func__);
4096
4097 high_dma = 1;
4098
4099 if (pci_set_consistent_dma_mask(pdev,
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004100 DMA_BIT_MASK(64))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004101 vxge_debug_init(VXGE_ERR,
4102 "%s : unable to obtain 64bit DMA for "
4103 "consistent allocations", __func__);
4104 ret = -ENOMEM;
4105 goto _exit1;
4106 }
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004107 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004108 vxge_debug_ll_config(VXGE_TRACE,
4109 "%s : using 32bit DMA", __func__);
4110 } else {
4111 ret = -ENOMEM;
4112 goto _exit1;
4113 }
4114
4115 if (pci_request_regions(pdev, VXGE_DRIVER_NAME)) {
4116 vxge_debug_init(VXGE_ERR,
4117 "%s : request regions failed", __func__);
4118 ret = -ENODEV;
4119 goto _exit1;
4120 }
4121
4122 pci_set_master(pdev);
4123
4124 attr.bar0 = pci_ioremap_bar(pdev, 0);
4125 if (!attr.bar0) {
4126 vxge_debug_init(VXGE_ERR,
4127 "%s : cannot remap io memory bar0", __func__);
4128 ret = -ENODEV;
4129 goto _exit2;
4130 }
4131 vxge_debug_ll_config(VXGE_TRACE,
4132 "pci ioremap bar0: %p:0x%llx",
4133 attr.bar0,
4134 (unsigned long long)pci_resource_start(pdev, 0));
4135
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004136 status = vxge_hw_device_hw_info_get(attr.bar0,
4137 &ll_config.device_hw_info);
4138 if (status != VXGE_HW_OK) {
4139 vxge_debug_init(VXGE_ERR,
4140 "%s: Reading of hardware info failed."
4141 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4142 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004143 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004144 }
4145
4146 if (ll_config.device_hw_info.fw_version.major !=
Sreenivasa Honnur22fa1252009-07-01 21:17:24 +00004147 VXGE_DRIVER_FW_VERSION_MAJOR) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004148 vxge_debug_init(VXGE_ERR,
Sreenivasa Honnur22fa1252009-07-01 21:17:24 +00004149 "%s: Incorrect firmware version."
4150 "Please upgrade the firmware to version 1.x.x",
4151 VXGE_DRIVER_NAME);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004152 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004153 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004154 }
4155
4156 vpath_mask = ll_config.device_hw_info.vpath_mask;
4157 if (vpath_mask == 0) {
4158 vxge_debug_ll_config(VXGE_TRACE,
4159 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4160 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004161 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004162 }
4163
4164 vxge_debug_ll_config(VXGE_TRACE,
4165 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4166 (unsigned long long)vpath_mask);
4167
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004168 function_mode = ll_config.device_hw_info.function_mode;
4169 host_type = ll_config.device_hw_info.host_type;
4170 is_privileged = __vxge_hw_device_is_privilaged(host_type,
4171 ll_config.device_hw_info.func_id);
4172
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004173 /* Check how many vpaths are available */
4174 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4175 if (!((vpath_mask) & vxge_mBIT(i)))
4176 continue;
4177 max_vpath_supported++;
4178 }
4179
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004180 if (new_device)
4181 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4182
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004183 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004184 if (is_sriov(function_mode) && (max_config_dev > 1) &&
4185 (ll_config.intr_type != INTA) &&
4186 (is_privileged == VXGE_HW_OK)) {
4187 ret = pci_enable_sriov(pdev, ((max_config_dev - 1) < num_vfs)
4188 ? (max_config_dev - 1) : num_vfs);
4189 if (ret)
4190 vxge_debug_ll_config(VXGE_ERR,
4191 "Failed in enabling SRIOV mode: %d\n", ret);
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004192 }
4193
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004194 /*
4195 * Configure vpaths and get driver configured number of vpaths
4196 * which is less than or equal to the maximum vpaths per function.
4197 */
4198 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, &ll_config);
4199 if (!no_of_vpath) {
4200 vxge_debug_ll_config(VXGE_ERR,
4201 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4202 ret = 0;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004203 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004204 }
4205
4206 /* Setting driver callbacks */
4207 attr.uld_callbacks.link_up = vxge_callback_link_up;
4208 attr.uld_callbacks.link_down = vxge_callback_link_down;
4209 attr.uld_callbacks.crit_err = vxge_callback_crit_err;
4210
4211 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4212 if (status != VXGE_HW_OK) {
4213 vxge_debug_init(VXGE_ERR,
4214 "Failed to initialize device (%d)", status);
4215 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004216 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004217 }
4218
Sreenivasa Honnurfa41fd12009-10-05 01:56:35 +00004219 /* if FCS stripping is not disabled in MAC fail driver load */
4220 if (vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask) != VXGE_HW_OK) {
4221 vxge_debug_init(VXGE_ERR,
4222 "%s: FCS stripping is not disabled in MAC"
4223 " failing driver load", VXGE_DRIVER_NAME);
4224 ret = -EINVAL;
4225 goto _exit4;
4226 }
4227
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004228 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4229
4230 /* set private device info */
4231 pci_set_drvdata(pdev, hldev);
4232
4233 ll_config.gro_enable = VXGE_GRO_ALWAYS_AGGREGATE;
4234 ll_config.fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4235 ll_config.addr_learn_en = addr_learn_en;
4236 ll_config.rth_algorithm = RTH_ALG_JENKINS;
4237 ll_config.rth_hash_type_tcpipv4 = VXGE_HW_RING_HASH_TYPE_TCP_IPV4;
4238 ll_config.rth_hash_type_ipv4 = VXGE_HW_RING_HASH_TYPE_NONE;
4239 ll_config.rth_hash_type_tcpipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
4240 ll_config.rth_hash_type_ipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
4241 ll_config.rth_hash_type_tcpipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
4242 ll_config.rth_hash_type_ipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
4243 ll_config.rth_bkt_sz = RTH_BUCKET_SIZE;
4244 ll_config.tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4245 ll_config.rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4246
4247 if (vxge_device_register(hldev, &ll_config, high_dma, no_of_vpath,
4248 &vdev)) {
4249 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004250 goto _exit4;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004251 }
4252
4253 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4254 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4255 vxge_hw_device_trace_level_get(hldev));
4256
4257 /* set private HW device info */
4258 hldev->ndev = vdev->ndev;
4259 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4260 vdev->bar0 = attr.bar0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004261 vdev->max_vpath_supported = max_vpath_supported;
4262 vdev->no_of_vpath = no_of_vpath;
4263
4264 /* Virtual Path count */
4265 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4266 if (!vxge_bVALn(vpath_mask, i, 1))
4267 continue;
4268 if (j >= vdev->no_of_vpath)
4269 break;
4270
4271 vdev->vpaths[j].is_configured = 1;
4272 vdev->vpaths[j].device_id = i;
4273 vdev->vpaths[j].fifo.driver_id = j;
4274 vdev->vpaths[j].ring.driver_id = j;
4275 vdev->vpaths[j].vdev = vdev;
4276 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4277 memcpy((u8 *)vdev->vpaths[j].macaddr,
4278 (u8 *)ll_config.device_hw_info.mac_addrs[i],
4279 ETH_ALEN);
4280
4281 /* Initialize the mac address list header */
4282 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4283
4284 vdev->vpaths[j].mac_addr_cnt = 0;
4285 vdev->vpaths[j].mcast_addr_cnt = 0;
4286 j++;
4287 }
4288 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4289 vdev->max_config_port = max_config_port;
4290
4291 vdev->vlan_tag_strip = vlan_tag_strip;
4292
4293 /* map the hashing selector table to the configured vpaths */
4294 for (i = 0; i < vdev->no_of_vpath; i++)
4295 vdev->vpath_selector[i] = vpath_selector[i];
4296
4297 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4298
4299 ll_config.device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4300 ll_config.device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4301 ll_config.device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
4302
4303 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
4304 vdev->ndev->name, ll_config.device_hw_info.serial_number);
4305
4306 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
4307 vdev->ndev->name, ll_config.device_hw_info.part_number);
4308
4309 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
4310 vdev->ndev->name, ll_config.device_hw_info.product_desc);
4311
hartleysbf54e732010-01-05 06:59:23 +00004312 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4313 vdev->ndev->name, macaddr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004314
4315 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4316 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4317
4318 vxge_debug_init(VXGE_TRACE,
4319 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
4320 ll_config.device_hw_info.fw_version.version,
4321 ll_config.device_hw_info.fw_date.date);
4322
Sreenivasa Honnur0a25bdc2009-07-01 21:18:06 +00004323 if (new_device) {
4324 switch (ll_config.device_hw_info.function_mode) {
4325 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4326 vxge_debug_init(VXGE_TRACE,
4327 "%s: Single Function Mode Enabled", vdev->ndev->name);
4328 break;
4329 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4330 vxge_debug_init(VXGE_TRACE,
4331 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4332 break;
4333 case VXGE_HW_FUNCTION_MODE_SRIOV:
4334 vxge_debug_init(VXGE_TRACE,
4335 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4336 break;
4337 case VXGE_HW_FUNCTION_MODE_MRIOV:
4338 vxge_debug_init(VXGE_TRACE,
4339 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4340 break;
4341 }
4342 }
4343
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004344 vxge_print_parm(vdev, vpath_mask);
4345
4346 /* Store the fw version for ethttool option */
4347 strcpy(vdev->fw_version, ll_config.device_hw_info.fw_version.version);
4348 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4349 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4350
4351 /* Copy the station mac address to the list */
4352 for (i = 0; i < vdev->no_of_vpath; i++) {
4353 entry = (struct vxge_mac_addrs *)
4354 kzalloc(sizeof(struct vxge_mac_addrs),
4355 GFP_KERNEL);
4356 if (NULL == entry) {
4357 vxge_debug_init(VXGE_ERR,
4358 "%s: mac_addr_list : memory allocation failed",
4359 vdev->ndev->name);
4360 ret = -EPERM;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004361 goto _exit5;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004362 }
4363 macaddr = (u8 *)&entry->macaddr;
4364 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4365 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4366 vdev->vpaths[i].mac_addr_cnt = 1;
4367 }
4368
Sreenivasa Honnur914d0d72009-07-01 21:13:12 +00004369 kfree(device_config);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00004370
4371 /*
4372 * INTA is shared in multi-function mode. This is unlike the INTA
4373 * implementation in MR mode, where each VH has its own INTA message.
4374 * - INTA is masked (disabled) as long as at least one function sets
4375 * its TITAN_MASK_ALL_INT.ALARM bit.
4376 * - INTA is unmasked (enabled) when all enabled functions have cleared
4377 * their own TITAN_MASK_ALL_INT.ALARM bit.
4378 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4379 * Though this driver leaves the top level interrupts unmasked while
4380 * leaving the required module interrupt bits masked on exit, there
4381 * could be a rougue driver around that does not follow this procedure
4382 * resulting in a failure to generate interrupts. The following code is
4383 * present to prevent such a failure.
4384 */
4385
4386 if (ll_config.device_hw_info.function_mode ==
4387 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4388 if (vdev->config.intr_type == INTA)
4389 vxge_hw_device_unmask_all(hldev);
4390
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004391 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4392 vdev->ndev->name, __func__, __LINE__);
4393
4394 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4395 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4396 vxge_hw_device_trace_level_get(hldev));
4397
4398 return 0;
4399
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004400_exit5:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004401 for (i = 0; i < vdev->no_of_vpath; i++)
4402 vxge_free_mac_add_list(&vdev->vpaths[i]);
4403
4404 vxge_device_unregister(hldev);
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004405_exit4:
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004406 pci_disable_sriov(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004407 vxge_hw_device_terminate(hldev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004408_exit3:
4409 iounmap(attr.bar0);
4410_exit2:
4411 pci_release_regions(pdev);
4412_exit1:
4413 pci_disable_device(pdev);
4414_exit0:
4415 kfree(device_config);
4416 driver_config->config_dev_cnt--;
4417 pci_set_drvdata(pdev, NULL);
4418 return ret;
4419}
4420
4421/**
4422 * vxge_rem_nic - Free the PCI device
4423 * @pdev: structure containing the PCI related information of the device.
4424 * Description: This function is called by the Pci subsystem to release a
4425 * PCI device and free up all resource held up by the device.
4426 */
4427static void __devexit
4428vxge_remove(struct pci_dev *pdev)
4429{
4430 struct __vxge_hw_device *hldev;
4431 struct vxgedev *vdev = NULL;
4432 struct net_device *dev;
4433 int i = 0;
4434#if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4435 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4436 u32 level_trace;
4437#endif
4438
4439 hldev = (struct __vxge_hw_device *) pci_get_drvdata(pdev);
4440
4441 if (hldev == NULL)
4442 return;
4443 dev = hldev->ndev;
4444 vdev = netdev_priv(dev);
4445
4446#if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4447 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4448 level_trace = vdev->level_trace;
4449#endif
4450 vxge_debug_entryexit(level_trace,
4451 "%s:%d", __func__, __LINE__);
4452
4453 vxge_debug_init(level_trace,
4454 "%s : removing PCI device...", __func__);
4455 vxge_device_unregister(hldev);
4456
4457 for (i = 0; i < vdev->no_of_vpath; i++) {
4458 vxge_free_mac_add_list(&vdev->vpaths[i]);
4459 vdev->vpaths[i].mcast_addr_cnt = 0;
4460 vdev->vpaths[i].mac_addr_cnt = 0;
4461 }
4462
4463 kfree(vdev->vpaths);
4464
4465 iounmap(vdev->bar0);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004466
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004467 pci_disable_sriov(pdev);
4468
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004469 /* we are safe to free it now */
4470 free_netdev(dev);
4471
4472 vxge_debug_init(level_trace,
4473 "%s:%d Device unregistered", __func__, __LINE__);
4474
4475 vxge_hw_device_terminate(hldev);
4476
4477 pci_disable_device(pdev);
4478 pci_release_regions(pdev);
4479 pci_set_drvdata(pdev, NULL);
4480 vxge_debug_entryexit(level_trace,
4481 "%s:%d Exiting...", __func__, __LINE__);
4482}
4483
4484static struct pci_error_handlers vxge_err_handler = {
4485 .error_detected = vxge_io_error_detected,
4486 .slot_reset = vxge_io_slot_reset,
4487 .resume = vxge_io_resume,
4488};
4489
4490static struct pci_driver vxge_driver = {
4491 .name = VXGE_DRIVER_NAME,
4492 .id_table = vxge_id_table,
4493 .probe = vxge_probe,
4494 .remove = __devexit_p(vxge_remove),
4495#ifdef CONFIG_PM
4496 .suspend = vxge_pm_suspend,
4497 .resume = vxge_pm_resume,
4498#endif
4499 .err_handler = &vxge_err_handler,
4500};
4501
4502static int __init
4503vxge_starter(void)
4504{
4505 int ret = 0;
4506 char version[32];
4507 snprintf(version, 32, "%s", DRV_VERSION);
4508
4509 printk(KERN_CRIT "%s: Copyright(c) 2002-2009 Neterion Inc\n",
4510 VXGE_DRIVER_NAME);
4511 printk(KERN_CRIT "%s: Driver version: %s\n",
4512 VXGE_DRIVER_NAME, version);
4513
4514 verify_bandwidth();
4515
4516 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4517 if (!driver_config)
4518 return -ENOMEM;
4519
4520 ret = pci_register_driver(&vxge_driver);
4521
4522 if (driver_config->config_dev_cnt &&
4523 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4524 vxge_debug_init(VXGE_ERR,
4525 "%s: Configured %d of %d devices",
4526 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4527 driver_config->total_dev_cnt);
4528
4529 if (ret)
4530 kfree(driver_config);
4531
4532 return ret;
4533}
4534
4535static void __exit
4536vxge_closer(void)
4537{
4538 pci_unregister_driver(&vxge_driver);
4539 kfree(driver_config);
4540}
4541module_init(vxge_starter);
4542module_exit(vxge_closer);