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