blob: d192dad8ff219d26f40e07eb804b4881599e2a7e [file] [log] [blame]
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001/******************************************************************************
2* This software may be used and distributed according to the terms of
3* the GNU General Public License (GPL), incorporated herein by reference.
4* Drivers based on or derived from this code fall under the GPL and must
5* retain the authorship, copyright and license notice. This file is not
6* a complete program and may only be used when the entire operating
7* system is licensed under the GPL.
8* See the file COPYING in this distribution for more information.
9*
Jon Mason926bd902010-07-15 08:47:26 +000010* vxge-main.c: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000011* Virtualized Server Adapter.
Jon Mason926bd902010-07-15 08:47:26 +000012* Copyright(c) 2002-2010 Exar Corp.
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000013*
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
Joe Perches75f5e1c2010-07-27 11:47:03 +000044#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
45
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000046#include <linux/if_vlan.h>
47#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090048#include <linux/slab.h>
Alexander Beregalov2b05e002009-04-04 16:36:18 -070049#include <linux/tcp.h>
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000050#include <net/ip.h>
51#include <linux/netdevice.h>
52#include <linux/etherdevice.h>
Jon Masone8ac1752010-11-11 04:25:57 +000053#include <linux/firmware.h>
Jon Masonb81b3732010-11-11 04:25:58 +000054#include <linux/net_tstamp.h>
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000055#include "vxge-main.h"
56#include "vxge-reg.h"
57
58MODULE_LICENSE("Dual BSD/GPL");
59MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
60 "Virtualized Server Adapter");
61
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000062static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000063 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
64 PCI_ANY_ID},
65 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
66 PCI_ANY_ID},
67 {0}
68};
69
70MODULE_DEVICE_TABLE(pci, vxge_id_table);
71
72VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
73VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
74VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
75VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
76VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
77VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
78
79static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
80 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
81static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
82 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
83module_param_array(bw_percentage, uint, NULL, 0);
84
85static struct vxge_drv_config *driver_config;
86
87static inline int is_vxge_card_up(struct vxgedev *vdev)
88{
89 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
90}
91
92static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
93{
Benjamin LaHaiseff67df52009-08-04 10:21:03 +000094 struct sk_buff **skb_ptr = NULL;
95 struct sk_buff **temp;
96#define NR_SKB_COMPLETED 128
97 struct sk_buff *completed[NR_SKB_COMPLETED];
98 int more;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000099
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000100 do {
101 more = 0;
102 skb_ptr = completed;
103
Jon Mason98f45da2010-07-15 08:47:25 +0000104 if (__netif_tx_trylock(fifo->txq)) {
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000105 vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
106 NR_SKB_COMPLETED, &more);
Jon Mason98f45da2010-07-15 08:47:25 +0000107 __netif_tx_unlock(fifo->txq);
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000108 }
Jon Mason98f45da2010-07-15 08:47:25 +0000109
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000110 /* free SKBs */
111 for (temp = completed; temp != skb_ptr; temp++)
112 dev_kfree_skb_irq(*temp);
Jon Mason98f45da2010-07-15 08:47:25 +0000113 } while (more);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000114}
115
116static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
117{
118 int i;
119
120 /* Complete all transmits */
121 for (i = 0; i < vdev->no_of_vpath; i++)
122 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
123}
124
125static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
126{
127 int i;
128 struct vxge_ring *ring;
129
130 /* Complete all receives*/
131 for (i = 0; i < vdev->no_of_vpath; i++) {
132 ring = &vdev->vpaths[i].ring;
133 vxge_hw_vpath_poll_rx(ring->handle);
134 }
135}
136
137/*
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000138 * vxge_callback_link_up
139 *
140 * This function is called during interrupt context to notify link up state
141 * change.
142 */
Jon Mason528f7272010-12-10 14:02:56 +0000143static void vxge_callback_link_up(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000144{
145 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +0000146 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000147
148 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
149 vdev->ndev->name, __func__, __LINE__);
Joe Perches75f5e1c2010-07-27 11:47:03 +0000150 netdev_notice(vdev->ndev, "Link Up\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000151 vdev->stats.link_up++;
152
153 netif_carrier_on(vdev->ndev);
Jon Masond03848e2010-07-15 08:47:23 +0000154 netif_tx_wake_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000155
156 vxge_debug_entryexit(VXGE_TRACE,
157 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
158}
159
160/*
161 * vxge_callback_link_down
162 *
163 * This function is called during interrupt context to notify link down state
164 * change.
165 */
Jon Mason528f7272010-12-10 14:02:56 +0000166static void vxge_callback_link_down(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000167{
168 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +0000169 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000170
171 vxge_debug_entryexit(VXGE_TRACE,
172 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
Joe Perches75f5e1c2010-07-27 11:47:03 +0000173 netdev_notice(vdev->ndev, "Link Down\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000174
175 vdev->stats.link_down++;
176 netif_carrier_off(vdev->ndev);
Jon Masond03848e2010-07-15 08:47:23 +0000177 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000178
179 vxge_debug_entryexit(VXGE_TRACE,
180 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
181}
182
183/*
184 * vxge_rx_alloc
185 *
186 * Allocate SKB.
187 */
Jon Mason528f7272010-12-10 14:02:56 +0000188static struct sk_buff *
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000189vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
190{
191 struct net_device *dev;
192 struct sk_buff *skb;
193 struct vxge_rx_priv *rx_priv;
194
195 dev = ring->ndev;
196 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
197 ring->ndev->name, __func__, __LINE__);
198
199 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
200
201 /* try to allocate skb first. this one may fail */
202 skb = netdev_alloc_skb(dev, skb_size +
203 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
204 if (skb == NULL) {
205 vxge_debug_mem(VXGE_ERR,
206 "%s: out of memory to allocate SKB", dev->name);
207 ring->stats.skb_alloc_fail++;
208 return NULL;
209 }
210
211 vxge_debug_mem(VXGE_TRACE,
212 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
213 __func__, __LINE__, skb);
214
215 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
216
217 rx_priv->skb = skb;
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000218 rx_priv->skb_data = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000219 rx_priv->data_size = skb_size;
220 vxge_debug_entryexit(VXGE_TRACE,
221 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
222
223 return skb;
224}
225
226/*
227 * vxge_rx_map
228 */
229static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
230{
231 struct vxge_rx_priv *rx_priv;
232 dma_addr_t dma_addr;
233
234 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
235 ring->ndev->name, __func__, __LINE__);
236 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
237
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000238 rx_priv->skb_data = rx_priv->skb->data;
239 dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000240 rx_priv->data_size, PCI_DMA_FROMDEVICE);
241
Denis Kirjanovfa15e992010-01-10 13:40:10 -0800242 if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000243 ring->stats.pci_map_fail++;
244 return -EIO;
245 }
246 vxge_debug_mem(VXGE_TRACE,
247 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
248 ring->ndev->name, __func__, __LINE__,
249 (unsigned long long)dma_addr);
250 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
251
252 rx_priv->data_dma = dma_addr;
253 vxge_debug_entryexit(VXGE_TRACE,
254 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
255
256 return 0;
257}
258
259/*
260 * vxge_rx_initial_replenish
261 * Allocation of RxD as an initial replenish procedure.
262 */
263static enum vxge_hw_status
264vxge_rx_initial_replenish(void *dtrh, void *userdata)
265{
266 struct vxge_ring *ring = (struct vxge_ring *)userdata;
267 struct vxge_rx_priv *rx_priv;
268
269 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
270 ring->ndev->name, __func__, __LINE__);
271 if (vxge_rx_alloc(dtrh, ring,
272 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
273 return VXGE_HW_FAIL;
274
275 if (vxge_rx_map(dtrh, ring)) {
276 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
277 dev_kfree_skb(rx_priv->skb);
278
279 return VXGE_HW_FAIL;
280 }
281 vxge_debug_entryexit(VXGE_TRACE,
282 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
283
284 return VXGE_HW_OK;
285}
286
287static inline void
288vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
289 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
290{
291
292 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
293 ring->ndev->name, __func__, __LINE__);
294 skb_record_rx_queue(skb, ring->driver_id);
295 skb->protocol = eth_type_trans(skb, ring->ndev);
296
297 ring->stats.rx_frms++;
298 ring->stats.rx_bytes += pkt_length;
299
300 if (skb->pkt_type == PACKET_MULTICAST)
301 ring->stats.rx_mcast++;
302
303 vxge_debug_rx(VXGE_TRACE,
304 "%s: %s:%d skb protocol = %d",
305 ring->ndev->name, __func__, __LINE__, skb->protocol);
306
307 if (ring->gro_enable) {
308 if (ring->vlgrp && ext_info->vlan &&
309 (ring->vlan_tag_strip ==
310 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +0000311 vlan_gro_receive(ring->napi_p, ring->vlgrp,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000312 ext_info->vlan, skb);
313 else
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +0000314 napi_gro_receive(ring->napi_p, skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000315 } else {
316 if (ring->vlgrp && vlan &&
317 (ring->vlan_tag_strip ==
318 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
319 vlan_hwaccel_receive_skb(skb, ring->vlgrp, vlan);
320 else
321 netif_receive_skb(skb);
322 }
323 vxge_debug_entryexit(VXGE_TRACE,
324 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
325}
326
327static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
328 struct vxge_rx_priv *rx_priv)
329{
330 pci_dma_sync_single_for_device(ring->pdev,
331 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
332
333 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
334 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
335}
336
337static inline void vxge_post(int *dtr_cnt, void **first_dtr,
338 void *post_dtr, struct __vxge_hw_ring *ringh)
339{
340 int dtr_count = *dtr_cnt;
341 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
342 if (*first_dtr)
343 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
344 *first_dtr = post_dtr;
345 } else
346 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
347 dtr_count++;
348 *dtr_cnt = dtr_count;
349}
350
351/*
352 * vxge_rx_1b_compl
353 *
354 * If the interrupt is because of a received frame or if the receive ring
355 * contains fresh as yet un-processed frames, this function is called.
356 */
stephen hemminger42821a52010-10-21 07:50:53 +0000357static enum vxge_hw_status
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000358vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
359 u8 t_code, void *userdata)
360{
361 struct vxge_ring *ring = (struct vxge_ring *)userdata;
Jon Masonb81b3732010-11-11 04:25:58 +0000362 struct net_device *dev = ring->ndev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000363 unsigned int dma_sizes;
364 void *first_dtr = NULL;
365 int dtr_cnt = 0;
366 int data_size;
367 dma_addr_t data_dma;
368 int pkt_length;
369 struct sk_buff *skb;
370 struct vxge_rx_priv *rx_priv;
371 struct vxge_hw_ring_rxd_info ext_info;
372 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
373 ring->ndev->name, __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000374
375 do {
Benjamin LaHaise3f23e432009-08-04 10:21:39 +0000376 prefetch((char *)dtr + L1_CACHE_BYTES);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000377 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
378 skb = rx_priv->skb;
379 data_size = rx_priv->data_size;
380 data_dma = rx_priv->data_dma;
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000381 prefetch(rx_priv->skb_data);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000382
383 vxge_debug_rx(VXGE_TRACE,
384 "%s: %s:%d skb = 0x%p",
385 ring->ndev->name, __func__, __LINE__, skb);
386
387 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
388 pkt_length = dma_sizes;
389
Sreenivasa Honnur22fa1252009-07-01 21:17:24 +0000390 pkt_length -= ETH_FCS_LEN;
391
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000392 vxge_debug_rx(VXGE_TRACE,
393 "%s: %s:%d Packet Length = %d",
394 ring->ndev->name, __func__, __LINE__, pkt_length);
395
396 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
397
398 /* check skb validity */
399 vxge_assert(skb);
400
401 prefetch((char *)skb + L1_CACHE_BYTES);
402 if (unlikely(t_code)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000403 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
404 VXGE_HW_OK) {
405
406 ring->stats.rx_errors++;
407 vxge_debug_rx(VXGE_TRACE,
408 "%s: %s :%d Rx T_code is %d",
409 ring->ndev->name, __func__,
410 __LINE__, t_code);
411
412 /* If the t_code is not supported and if the
413 * t_code is other than 0x5 (unparseable packet
414 * such as unknown UPV6 header), Drop it !!!
415 */
416 vxge_re_pre_post(dtr, ring, rx_priv);
417
418 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
419 ring->stats.rx_dropped++;
420 continue;
421 }
422 }
423
424 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000425 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000426 if (!vxge_rx_map(dtr, ring)) {
427 skb_put(skb, pkt_length);
428
429 pci_unmap_single(ring->pdev, data_dma,
430 data_size, PCI_DMA_FROMDEVICE);
431
432 vxge_hw_ring_rxd_pre_post(ringh, dtr);
433 vxge_post(&dtr_cnt, &first_dtr, dtr,
434 ringh);
435 } else {
436 dev_kfree_skb(rx_priv->skb);
437 rx_priv->skb = skb;
438 rx_priv->data_size = data_size;
439 vxge_re_pre_post(dtr, ring, rx_priv);
440
441 vxge_post(&dtr_cnt, &first_dtr, dtr,
442 ringh);
443 ring->stats.rx_dropped++;
444 break;
445 }
446 } else {
447 vxge_re_pre_post(dtr, ring, rx_priv);
448
449 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
450 ring->stats.rx_dropped++;
451 break;
452 }
453 } else {
454 struct sk_buff *skb_up;
455
456 skb_up = netdev_alloc_skb(dev, pkt_length +
457 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
458 if (skb_up != NULL) {
459 skb_reserve(skb_up,
460 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
461
462 pci_dma_sync_single_for_cpu(ring->pdev,
463 data_dma, data_size,
464 PCI_DMA_FROMDEVICE);
465
466 vxge_debug_mem(VXGE_TRACE,
467 "%s: %s:%d skb_up = %p",
468 ring->ndev->name, __func__,
469 __LINE__, skb);
470 memcpy(skb_up->data, skb->data, pkt_length);
471
472 vxge_re_pre_post(dtr, ring, rx_priv);
473
474 vxge_post(&dtr_cnt, &first_dtr, dtr,
475 ringh);
476 /* will netif_rx small SKB instead */
477 skb = skb_up;
478 skb_put(skb, pkt_length);
479 } else {
480 vxge_re_pre_post(dtr, ring, rx_priv);
481
482 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
483 vxge_debug_rx(VXGE_ERR,
484 "%s: vxge_rx_1b_compl: out of "
485 "memory", dev->name);
486 ring->stats.skb_alloc_fail++;
487 break;
488 }
489 }
490
491 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
492 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
493 ring->rx_csum && /* Offload Rx side CSUM */
494 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
495 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
496 skb->ip_summed = CHECKSUM_UNNECESSARY;
497 else
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700498 skb_checksum_none_assert(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000499
Jon Masonb81b3732010-11-11 04:25:58 +0000500
501 if (ring->rx_hwts) {
502 struct skb_shared_hwtstamps *skb_hwts;
503 u32 ns = *(u32 *)(skb->head + pkt_length);
504
505 skb_hwts = skb_hwtstamps(skb);
506 skb_hwts->hwtstamp = ns_to_ktime(ns);
507 skb_hwts->syststamp.tv64 = 0;
508 }
509
Jon Mason47f01db2010-11-11 04:25:53 +0000510 /* rth_hash_type and rth_it_hit are non-zero regardless of
511 * whether rss is enabled. Only the rth_value is zero/non-zero
512 * if rss is disabled/enabled, so key off of that.
513 */
514 if (ext_info.rth_value)
515 skb->rxhash = ext_info.rth_value;
516
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000517 vxge_rx_complete(ring, skb, ext_info.vlan,
518 pkt_length, &ext_info);
519
520 ring->budget--;
521 ring->pkts_processed++;
522 if (!ring->budget)
523 break;
524
525 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
526 &t_code) == VXGE_HW_OK);
527
528 if (first_dtr)
529 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
530
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000531 vxge_debug_entryexit(VXGE_TRACE,
532 "%s:%d Exiting...",
533 __func__, __LINE__);
534 return VXGE_HW_OK;
535}
536
537/*
538 * vxge_xmit_compl
539 *
540 * If an interrupt was raised to indicate DMA complete of the Tx packet,
541 * this function is called. It identifies the last TxD whose buffer was
542 * freed and frees all skbs whose data have already DMA'ed into the NICs
543 * internal memory.
544 */
stephen hemminger42821a52010-10-21 07:50:53 +0000545static enum vxge_hw_status
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000546vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
547 enum vxge_hw_fifo_tcode t_code, void *userdata,
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000548 struct sk_buff ***skb_ptr, int nr_skb, int *more)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000549{
550 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000551 struct sk_buff *skb, **done_skb = *skb_ptr;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000552 int pkt_cnt = 0;
553
554 vxge_debug_entryexit(VXGE_TRACE,
555 "%s:%d Entered....", __func__, __LINE__);
556
557 do {
558 int frg_cnt;
559 skb_frag_t *frag;
560 int i = 0, j;
561 struct vxge_tx_priv *txd_priv =
562 vxge_hw_fifo_txdl_private_get(dtr);
563
564 skb = txd_priv->skb;
565 frg_cnt = skb_shinfo(skb)->nr_frags;
566 frag = &skb_shinfo(skb)->frags[0];
567
568 vxge_debug_tx(VXGE_TRACE,
569 "%s: %s:%d fifo_hw = %p dtr = %p "
570 "tcode = 0x%x", fifo->ndev->name, __func__,
571 __LINE__, fifo_hw, dtr, t_code);
572 /* check skb validity */
573 vxge_assert(skb);
574 vxge_debug_tx(VXGE_TRACE,
575 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
576 fifo->ndev->name, __func__, __LINE__,
577 skb, txd_priv, frg_cnt);
578 if (unlikely(t_code)) {
579 fifo->stats.tx_errors++;
580 vxge_debug_tx(VXGE_ERR,
581 "%s: tx: dtr %p completed due to "
582 "error t_code %01x", fifo->ndev->name,
583 dtr, t_code);
584 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
585 }
586
587 /* for unfragmented skb */
588 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
589 skb_headlen(skb), PCI_DMA_TODEVICE);
590
591 for (j = 0; j < frg_cnt; j++) {
592 pci_unmap_page(fifo->pdev,
593 txd_priv->dma_buffers[i++],
594 frag->size, PCI_DMA_TODEVICE);
595 frag += 1;
596 }
597
598 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
599
600 /* Updating the statistics block */
601 fifo->stats.tx_frms++;
602 fifo->stats.tx_bytes += skb->len;
603
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000604 *done_skb++ = skb;
605
606 if (--nr_skb <= 0) {
607 *more = 1;
608 break;
609 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000610
611 pkt_cnt++;
612 if (pkt_cnt > fifo->indicate_max_pkts)
613 break;
614
615 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
616 &dtr, &t_code) == VXGE_HW_OK);
617
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000618 *skb_ptr = done_skb;
Jon Mason98f45da2010-07-15 08:47:25 +0000619 if (netif_tx_queue_stopped(fifo->txq))
620 netif_tx_wake_queue(fifo->txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000621
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000622 vxge_debug_entryexit(VXGE_TRACE,
623 "%s: %s:%d Exiting...",
624 fifo->ndev->name, __func__, __LINE__);
625 return VXGE_HW_OK;
626}
627
Eric Dumazet28679752009-05-27 19:26:37 +0000628/* select a vpath to transmit the packet */
Jon Mason98f45da2010-07-15 08:47:25 +0000629static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000630{
631 u16 queue_len, counter = 0;
632 if (skb->protocol == htons(ETH_P_IP)) {
633 struct iphdr *ip;
634 struct tcphdr *th;
635
636 ip = ip_hdr(skb);
637
638 if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) {
639 th = (struct tcphdr *)(((unsigned char *)ip) +
640 ip->ihl*4);
641
642 queue_len = vdev->no_of_vpath;
643 counter = (ntohs(th->source) +
644 ntohs(th->dest)) &
645 vdev->vpath_selector[queue_len - 1];
646 if (counter >= queue_len)
647 counter = queue_len - 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000648 }
649 }
650 return counter;
651}
652
653static enum vxge_hw_status vxge_search_mac_addr_in_list(
654 struct vxge_vpath *vpath, u64 del_mac)
655{
656 struct list_head *entry, *next;
657 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
658 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
659 return TRUE;
660 }
661 return FALSE;
662}
663
Jon Mason528f7272010-12-10 14:02:56 +0000664static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
665{
666 struct vxge_mac_addrs *new_mac_entry;
667 u8 *mac_address = NULL;
668
669 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
670 return TRUE;
671
672 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
673 if (!new_mac_entry) {
674 vxge_debug_mem(VXGE_ERR,
675 "%s: memory allocation failed",
676 VXGE_DRIVER_NAME);
677 return FALSE;
678 }
679
680 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
681
682 /* Copy the new mac address to the list */
683 mac_address = (u8 *)&new_mac_entry->macaddr;
684 memcpy(mac_address, mac->macaddr, ETH_ALEN);
685
686 new_mac_entry->state = mac->state;
687 vpath->mac_addr_cnt++;
688
689 /* Is this a multicast address */
690 if (0x01 & mac->macaddr[0])
691 vpath->mcast_addr_cnt++;
692
693 return TRUE;
694}
695
696/* Add a mac address to DA table */
697static enum vxge_hw_status
698vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
699{
700 enum vxge_hw_status status = VXGE_HW_OK;
701 struct vxge_vpath *vpath;
702 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
703
704 if (0x01 & mac->macaddr[0]) /* multicast address */
705 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
706 else
707 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
708
709 vpath = &vdev->vpaths[mac->vpath_no];
710 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
711 mac->macmask, duplicate_mode);
712 if (status != VXGE_HW_OK) {
713 vxge_debug_init(VXGE_ERR,
714 "DA config add entry failed for vpath:%d",
715 vpath->device_id);
716 } else
717 if (FALSE == vxge_mac_list_add(vpath, mac))
718 status = -EPERM;
719
720 return status;
721}
722
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000723static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
724{
725 struct macInfo mac_info;
726 u8 *mac_address = NULL;
727 u64 mac_addr = 0, vpath_vector = 0;
728 int vpath_idx = 0;
729 enum vxge_hw_status status = VXGE_HW_OK;
730 struct vxge_vpath *vpath = NULL;
731 struct __vxge_hw_device *hldev;
732
Joe Perchesd8ee7072010-11-15 10:13:58 +0000733 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000734
735 mac_address = (u8 *)&mac_addr;
736 memcpy(mac_address, mac_header, ETH_ALEN);
737
738 /* Is this mac address already in the list? */
739 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
740 vpath = &vdev->vpaths[vpath_idx];
741 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
742 return vpath_idx;
743 }
744
745 memset(&mac_info, 0, sizeof(struct macInfo));
746 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
747
748 /* Any vpath has room to add mac address to its da table? */
749 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
750 vpath = &vdev->vpaths[vpath_idx];
751 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
752 /* Add this mac address to this vpath */
753 mac_info.vpath_no = vpath_idx;
754 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
755 status = vxge_add_mac_addr(vdev, &mac_info);
756 if (status != VXGE_HW_OK)
757 return -EPERM;
758 return vpath_idx;
759 }
760 }
761
762 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
763 vpath_idx = 0;
764 mac_info.vpath_no = vpath_idx;
765 /* Is the first vpath already selected as catch-basin ? */
766 vpath = &vdev->vpaths[vpath_idx];
767 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
768 /* Add this mac address to this vpath */
769 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
770 return -EPERM;
771 return vpath_idx;
772 }
773
774 /* Select first vpath as catch-basin */
775 vpath_vector = vxge_mBIT(vpath->device_id);
776 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
777 vxge_hw_mgmt_reg_type_mrpcim,
778 0,
779 (ulong)offsetof(
780 struct vxge_hw_mrpcim_reg,
781 rts_mgr_cbasin_cfg),
782 vpath_vector);
783 if (status != VXGE_HW_OK) {
784 vxge_debug_tx(VXGE_ERR,
785 "%s: Unable to set the vpath-%d in catch-basin mode",
786 VXGE_DRIVER_NAME, vpath->device_id);
787 return -EPERM;
788 }
789
790 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
791 return -EPERM;
792
793 return vpath_idx;
794}
795
796/**
797 * vxge_xmit
798 * @skb : the socket buffer containing the Tx data.
799 * @dev : device pointer.
800 *
801 * This function is the Tx entry point of the driver. Neterion NIC supports
802 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000803*/
Stephen Hemminger613573252009-08-31 19:50:58 +0000804static netdev_tx_t
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000805vxge_xmit(struct sk_buff *skb, struct net_device *dev)
806{
807 struct vxge_fifo *fifo = NULL;
808 void *dtr_priv;
809 void *dtr = NULL;
810 struct vxgedev *vdev = NULL;
811 enum vxge_hw_status status;
812 int frg_cnt, first_frg_len;
813 skb_frag_t *frag;
814 int i = 0, j = 0, avail;
815 u64 dma_pointer;
816 struct vxge_tx_priv *txdl_priv = NULL;
817 struct __vxge_hw_fifo *fifo_hw;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000818 int offload_type;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000819 int vpath_no = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000820
821 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
822 dev->name, __func__, __LINE__);
823
824 /* A buffer with no data will be dropped */
825 if (unlikely(skb->len <= 0)) {
826 vxge_debug_tx(VXGE_ERR,
827 "%s: Buffer has no data..", dev->name);
828 dev_kfree_skb(skb);
829 return NETDEV_TX_OK;
830 }
831
Joe Perches5f54ceb2010-11-15 11:12:30 +0000832 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000833
834 if (unlikely(!is_vxge_card_up(vdev))) {
835 vxge_debug_tx(VXGE_ERR,
836 "%s: vdev not initialized", dev->name);
837 dev_kfree_skb(skb);
838 return NETDEV_TX_OK;
839 }
840
841 if (vdev->config.addr_learn_en) {
842 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
843 if (vpath_no == -EPERM) {
844 vxge_debug_tx(VXGE_ERR,
845 "%s: Failed to store the mac address",
846 dev->name);
847 dev_kfree_skb(skb);
848 return NETDEV_TX_OK;
849 }
850 }
851
852 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
853 vpath_no = skb_get_queue_mapping(skb);
854 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
Jon Mason98f45da2010-07-15 08:47:25 +0000855 vpath_no = vxge_get_vpath_no(vdev, skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000856
857 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
858
859 if (vpath_no >= vdev->no_of_vpath)
860 vpath_no = 0;
861
862 fifo = &vdev->vpaths[vpath_no].fifo;
863 fifo_hw = fifo->handle;
864
Jon Mason98f45da2010-07-15 08:47:25 +0000865 if (netif_tx_queue_stopped(fifo->txq))
Jon Masond03848e2010-07-15 08:47:23 +0000866 return NETDEV_TX_BUSY;
Jon Masond03848e2010-07-15 08:47:23 +0000867
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000868 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
869 if (avail == 0) {
870 vxge_debug_tx(VXGE_ERR,
871 "%s: No free TXDs available", dev->name);
872 fifo->stats.txd_not_free++;
Jon Mason98f45da2010-07-15 08:47:25 +0000873 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000874 }
875
Benjamin LaHaise4403b372009-08-04 10:20:44 +0000876 /* Last TXD? Stop tx queue to avoid dropping packets. TX
877 * completion will resume the queue.
878 */
879 if (avail == 1)
Jon Mason98f45da2010-07-15 08:47:25 +0000880 netif_tx_stop_queue(fifo->txq);
Benjamin LaHaise4403b372009-08-04 10:20:44 +0000881
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000882 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
883 if (unlikely(status != VXGE_HW_OK)) {
884 vxge_debug_tx(VXGE_ERR,
885 "%s: Out of descriptors .", dev->name);
886 fifo->stats.txd_out_of_desc++;
Jon Mason98f45da2010-07-15 08:47:25 +0000887 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000888 }
889
890 vxge_debug_tx(VXGE_TRACE,
891 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
892 dev->name, __func__, __LINE__,
893 fifo_hw, dtr, dtr_priv);
894
Jesse Grosseab6d182010-10-20 13:56:03 +0000895 if (vlan_tx_tag_present(skb)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000896 u16 vlan_tag = vlan_tx_tag_get(skb);
897 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
898 }
899
900 first_frg_len = skb_headlen(skb);
901
902 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
903 PCI_DMA_TODEVICE);
904
905 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
906 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000907 fifo->stats.pci_map_fail++;
Jon Mason98f45da2010-07-15 08:47:25 +0000908 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000909 }
910
911 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
912 txdl_priv->skb = skb;
913 txdl_priv->dma_buffers[j] = dma_pointer;
914
915 frg_cnt = skb_shinfo(skb)->nr_frags;
916 vxge_debug_tx(VXGE_TRACE,
917 "%s: %s:%d skb = %p txdl_priv = %p "
918 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
919 __func__, __LINE__, skb, txdl_priv,
920 frg_cnt, (unsigned long long)dma_pointer);
921
922 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
923 first_frg_len);
924
925 frag = &skb_shinfo(skb)->frags[0];
926 for (i = 0; i < frg_cnt; i++) {
927 /* ignore 0 length fragment */
928 if (!frag->size)
929 continue;
930
Jon Mason98f45da2010-07-15 08:47:25 +0000931 dma_pointer = (u64) pci_map_page(fifo->pdev, frag->page,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000932 frag->page_offset, frag->size,
933 PCI_DMA_TODEVICE);
934
935 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
Jon Mason98f45da2010-07-15 08:47:25 +0000936 goto _exit2;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000937 vxge_debug_tx(VXGE_TRACE,
938 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
939 dev->name, __func__, __LINE__, i,
940 (unsigned long long)dma_pointer);
941
942 txdl_priv->dma_buffers[j] = dma_pointer;
943 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
944 frag->size);
945 frag += 1;
946 }
947
948 offload_type = vxge_offload_type(skb);
949
950 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000951 int mss = vxge_tcp_mss(skb);
952 if (mss) {
Jon Mason98f45da2010-07-15 08:47:25 +0000953 vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000954 dev->name, __func__, __LINE__, mss);
955 vxge_hw_fifo_txdl_mss_set(dtr, mss);
956 } else {
957 vxge_assert(skb->len <=
958 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
959 vxge_assert(0);
960 goto _exit1;
961 }
962 }
963
964 if (skb->ip_summed == CHECKSUM_PARTIAL)
965 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
966 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
967 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
968 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
969
970 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000971
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000972 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
973 dev->name, __func__, __LINE__);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000974 return NETDEV_TX_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000975
Jon Mason98f45da2010-07-15 08:47:25 +0000976_exit2:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000977 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000978_exit1:
979 j = 0;
980 frag = &skb_shinfo(skb)->frags[0];
981
982 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
983 skb_headlen(skb), PCI_DMA_TODEVICE);
984
985 for (; j < i; j++) {
986 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
987 frag->size, PCI_DMA_TODEVICE);
988 frag += 1;
989 }
990
991 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
Jon Mason98f45da2010-07-15 08:47:25 +0000992_exit0:
993 netif_tx_stop_queue(fifo->txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000994 dev_kfree_skb(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000995
Patrick McHardy6ed10652009-06-23 06:03:08 +0000996 return NETDEV_TX_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000997}
998
999/*
1000 * vxge_rx_term
1001 *
1002 * Function will be called by hw function to abort all outstanding receive
1003 * descriptors.
1004 */
1005static void
1006vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1007{
1008 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1009 struct vxge_rx_priv *rx_priv =
1010 vxge_hw_ring_rxd_private_get(dtrh);
1011
1012 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1013 ring->ndev->name, __func__, __LINE__);
1014 if (state != VXGE_HW_RXD_STATE_POSTED)
1015 return;
1016
1017 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1018 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1019
1020 dev_kfree_skb(rx_priv->skb);
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +00001021 rx_priv->skb_data = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001022
1023 vxge_debug_entryexit(VXGE_TRACE,
1024 "%s: %s:%d Exiting...",
1025 ring->ndev->name, __func__, __LINE__);
1026}
1027
1028/*
1029 * vxge_tx_term
1030 *
1031 * Function will be called to abort all outstanding tx descriptors
1032 */
1033static void
1034vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1035{
1036 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1037 skb_frag_t *frag;
1038 int i = 0, j, frg_cnt;
1039 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1040 struct sk_buff *skb = txd_priv->skb;
1041
1042 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1043
1044 if (state != VXGE_HW_TXDL_STATE_POSTED)
1045 return;
1046
1047 /* check skb validity */
1048 vxge_assert(skb);
1049 frg_cnt = skb_shinfo(skb)->nr_frags;
1050 frag = &skb_shinfo(skb)->frags[0];
1051
1052 /* for unfragmented skb */
1053 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1054 skb_headlen(skb), PCI_DMA_TODEVICE);
1055
1056 for (j = 0; j < frg_cnt; j++) {
1057 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
1058 frag->size, PCI_DMA_TODEVICE);
1059 frag += 1;
1060 }
1061
1062 dev_kfree_skb(skb);
1063
1064 vxge_debug_entryexit(VXGE_TRACE,
1065 "%s:%d Exiting...", __func__, __LINE__);
1066}
1067
Jon Mason528f7272010-12-10 14:02:56 +00001068static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1069{
1070 struct list_head *entry, *next;
1071 u64 del_mac = 0;
1072 u8 *mac_address = (u8 *) (&del_mac);
1073
1074 /* Copy the mac address to delete from the list */
1075 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1076
1077 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1078 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1079 list_del(entry);
1080 kfree((struct vxge_mac_addrs *)entry);
1081 vpath->mac_addr_cnt--;
1082
1083 /* Is this a multicast address */
1084 if (0x01 & mac->macaddr[0])
1085 vpath->mcast_addr_cnt--;
1086 return TRUE;
1087 }
1088 }
1089
1090 return FALSE;
1091}
1092
1093/* delete a mac address from DA table */
1094static enum vxge_hw_status
1095vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1096{
1097 enum vxge_hw_status status = VXGE_HW_OK;
1098 struct vxge_vpath *vpath;
1099
1100 vpath = &vdev->vpaths[mac->vpath_no];
1101 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1102 mac->macmask);
1103 if (status != VXGE_HW_OK) {
1104 vxge_debug_init(VXGE_ERR,
1105 "DA config delete entry failed for vpath:%d",
1106 vpath->device_id);
1107 } else
1108 vxge_mac_list_del(vpath, mac);
1109 return status;
1110}
1111
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001112/**
1113 * vxge_set_multicast
1114 * @dev: pointer to the device structure
1115 *
1116 * Entry point for multicast address enable/disable
1117 * This function is a driver entry point which gets called by the kernel
1118 * whenever multicast addresses must be enabled/disabled. This also gets
1119 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1120 * determine, if multicast address must be enabled or if promiscuous mode
1121 * is to be disabled etc.
1122 */
1123static void vxge_set_multicast(struct net_device *dev)
1124{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001125 struct netdev_hw_addr *ha;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001126 struct vxgedev *vdev;
1127 int i, mcast_cnt = 0;
Jon Mason7adf7d12010-07-15 08:47:24 +00001128 struct __vxge_hw_device *hldev;
1129 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001130 enum vxge_hw_status status = VXGE_HW_OK;
1131 struct macInfo mac_info;
1132 int vpath_idx = 0;
1133 struct vxge_mac_addrs *mac_entry;
1134 struct list_head *list_head;
1135 struct list_head *entry, *next;
1136 u8 *mac_address = NULL;
1137
1138 vxge_debug_entryexit(VXGE_TRACE,
1139 "%s:%d", __func__, __LINE__);
1140
Joe Perches5f54ceb2010-11-15 11:12:30 +00001141 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001142 hldev = (struct __vxge_hw_device *)vdev->devh;
1143
1144 if (unlikely(!is_vxge_card_up(vdev)))
1145 return;
1146
1147 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1148 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001149 vpath = &vdev->vpaths[i];
1150 vxge_assert(vpath->is_open);
1151 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1152 if (status != VXGE_HW_OK)
1153 vxge_debug_init(VXGE_ERR, "failed to enable "
1154 "multicast, status %d", status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001155 vdev->all_multi_flg = 1;
1156 }
Jon Mason7adf7d12010-07-15 08:47:24 +00001157 } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001158 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001159 vpath = &vdev->vpaths[i];
1160 vxge_assert(vpath->is_open);
1161 status = vxge_hw_vpath_mcast_disable(vpath->handle);
1162 if (status != VXGE_HW_OK)
1163 vxge_debug_init(VXGE_ERR, "failed to disable "
1164 "multicast, status %d", status);
1165 vdev->all_multi_flg = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001166 }
1167 }
1168
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001169
1170 if (!vdev->config.addr_learn_en) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001171 for (i = 0; i < vdev->no_of_vpath; i++) {
1172 vpath = &vdev->vpaths[i];
1173 vxge_assert(vpath->is_open);
1174
1175 if (dev->flags & IFF_PROMISC)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001176 status = vxge_hw_vpath_promisc_enable(
Jon Mason7adf7d12010-07-15 08:47:24 +00001177 vpath->handle);
1178 else
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001179 status = vxge_hw_vpath_promisc_disable(
Jon Mason7adf7d12010-07-15 08:47:24 +00001180 vpath->handle);
1181 if (status != VXGE_HW_OK)
1182 vxge_debug_init(VXGE_ERR, "failed to %s promisc"
1183 ", status %d", dev->flags&IFF_PROMISC ?
1184 "enable" : "disable", status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001185 }
1186 }
1187
1188 memset(&mac_info, 0, sizeof(struct macInfo));
1189 /* Update individual M_CAST address list */
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001190 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001191 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1192 list_head = &vdev->vpaths[0].mac_addr_list;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001193 if ((netdev_mc_count(dev) +
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001194 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1195 vdev->vpaths[0].max_mac_addr_cnt)
1196 goto _set_all_mcast;
1197
1198 /* Delete previous MC's */
1199 for (i = 0; i < mcast_cnt; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001200 list_for_each_safe(entry, next, list_head) {
Jon Mason2c913082010-11-11 04:26:03 +00001201 mac_entry = (struct vxge_mac_addrs *)entry;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001202 /* Copy the mac address to delete */
1203 mac_address = (u8 *)&mac_entry->macaddr;
1204 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1205
1206 /* Is this a multicast address */
1207 if (0x01 & mac_info.macaddr[0]) {
1208 for (vpath_idx = 0; vpath_idx <
1209 vdev->no_of_vpath;
1210 vpath_idx++) {
1211 mac_info.vpath_no = vpath_idx;
1212 status = vxge_del_mac_addr(
1213 vdev,
1214 &mac_info);
1215 }
1216 }
1217 }
1218 }
1219
1220 /* Add new ones */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001221 netdev_for_each_mc_addr(ha, dev) {
1222 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001223 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1224 vpath_idx++) {
1225 mac_info.vpath_no = vpath_idx;
1226 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1227 status = vxge_add_mac_addr(vdev, &mac_info);
1228 if (status != VXGE_HW_OK) {
1229 vxge_debug_init(VXGE_ERR,
1230 "%s:%d Setting individual"
1231 "multicast address failed",
1232 __func__, __LINE__);
1233 goto _set_all_mcast;
1234 }
1235 }
1236 }
1237
1238 return;
1239_set_all_mcast:
1240 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1241 /* Delete previous MC's */
1242 for (i = 0; i < mcast_cnt; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001243 list_for_each_safe(entry, next, list_head) {
Jon Mason2c913082010-11-11 04:26:03 +00001244 mac_entry = (struct vxge_mac_addrs *)entry;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001245 /* Copy the mac address to delete */
1246 mac_address = (u8 *)&mac_entry->macaddr;
1247 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1248
1249 /* Is this a multicast address */
1250 if (0x01 & mac_info.macaddr[0])
1251 break;
1252 }
1253
1254 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1255 vpath_idx++) {
1256 mac_info.vpath_no = vpath_idx;
1257 status = vxge_del_mac_addr(vdev, &mac_info);
1258 }
1259 }
1260
1261 /* Enable all multicast */
1262 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001263 vpath = &vdev->vpaths[i];
1264 vxge_assert(vpath->is_open);
1265
1266 status = vxge_hw_vpath_mcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001267 if (status != VXGE_HW_OK) {
1268 vxge_debug_init(VXGE_ERR,
1269 "%s:%d Enabling all multicasts failed",
1270 __func__, __LINE__);
1271 }
1272 vdev->all_multi_flg = 1;
1273 }
1274 dev->flags |= IFF_ALLMULTI;
1275 }
1276
1277 vxge_debug_entryexit(VXGE_TRACE,
1278 "%s:%d Exiting...", __func__, __LINE__);
1279}
1280
1281/**
1282 * vxge_set_mac_addr
1283 * @dev: pointer to the device structure
1284 *
1285 * Update entry "0" (default MAC addr)
1286 */
1287static int vxge_set_mac_addr(struct net_device *dev, void *p)
1288{
1289 struct sockaddr *addr = p;
1290 struct vxgedev *vdev;
Jon Mason2c913082010-11-11 04:26:03 +00001291 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001292 enum vxge_hw_status status = VXGE_HW_OK;
1293 struct macInfo mac_info_new, mac_info_old;
1294 int vpath_idx = 0;
1295
1296 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1297
Joe Perches5f54ceb2010-11-15 11:12:30 +00001298 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001299 hldev = vdev->devh;
1300
1301 if (!is_valid_ether_addr(addr->sa_data))
1302 return -EINVAL;
1303
1304 memset(&mac_info_new, 0, sizeof(struct macInfo));
1305 memset(&mac_info_old, 0, sizeof(struct macInfo));
1306
1307 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1308 __func__, __LINE__);
1309
1310 /* Get the old address */
1311 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1312
1313 /* Copy the new address */
1314 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1315
1316 /* First delete the old mac address from all the vpaths
1317 as we can't specify the index while adding new mac address */
1318 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1319 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1320 if (!vpath->is_open) {
1321 /* This can happen when this interface is added/removed
1322 to the bonding interface. Delete this station address
1323 from the linked list */
1324 vxge_mac_list_del(vpath, &mac_info_old);
1325
1326 /* Add this new address to the linked list
1327 for later restoring */
1328 vxge_mac_list_add(vpath, &mac_info_new);
1329
1330 continue;
1331 }
1332 /* Delete the station address */
1333 mac_info_old.vpath_no = vpath_idx;
1334 status = vxge_del_mac_addr(vdev, &mac_info_old);
1335 }
1336
1337 if (unlikely(!is_vxge_card_up(vdev))) {
1338 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1339 return VXGE_HW_OK;
1340 }
1341
1342 /* Set this mac address to all the vpaths */
1343 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1344 mac_info_new.vpath_no = vpath_idx;
1345 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1346 status = vxge_add_mac_addr(vdev, &mac_info_new);
1347 if (status != VXGE_HW_OK)
1348 return -EINVAL;
1349 }
1350
1351 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1352
1353 return status;
1354}
1355
1356/*
1357 * vxge_vpath_intr_enable
1358 * @vdev: pointer to vdev
1359 * @vp_id: vpath for which to enable the interrupts
1360 *
1361 * Enables the interrupts for the vpath
1362*/
stephen hemminger42821a52010-10-21 07:50:53 +00001363static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001364{
1365 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001366 int msix_id = 0;
1367 int tim_msix_id[4] = {0, 1, 0, 0};
1368 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001369
1370 vxge_hw_vpath_intr_enable(vpath->handle);
1371
1372 if (vdev->config.intr_type == INTA)
1373 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1374 else {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001375 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1376 alarm_msix_id);
1377
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001378 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001379 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1380 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1381
1382 /* enable the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001383 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1384 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1385 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001386 }
1387}
1388
1389/*
1390 * vxge_vpath_intr_disable
1391 * @vdev: pointer to vdev
1392 * @vp_id: vpath for which to disable the interrupts
1393 *
1394 * Disables the interrupts for the vpath
1395*/
stephen hemminger42821a52010-10-21 07:50:53 +00001396static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001397{
1398 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Jon Mason4d2a5b42010-11-11 04:25:54 +00001399 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001400 int msix_id;
1401
Joe Perchesd8ee7072010-11-15 10:13:58 +00001402 hldev = pci_get_drvdata(vdev->pdev);
Jon Mason4d2a5b42010-11-11 04:25:54 +00001403
1404 vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
1405
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001406 vxge_hw_vpath_intr_disable(vpath->handle);
1407
1408 if (vdev->config.intr_type == INTA)
1409 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1410 else {
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001411 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001412 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1413 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1414
1415 /* disable the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001416 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1417 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001418 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1419 }
1420}
1421
Jon Mason528f7272010-12-10 14:02:56 +00001422/* list all mac addresses from DA table */
1423static enum vxge_hw_status
1424vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, struct macInfo *mac)
1425{
1426 enum vxge_hw_status status = VXGE_HW_OK;
1427 unsigned char macmask[ETH_ALEN];
1428 unsigned char macaddr[ETH_ALEN];
1429
1430 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1431 macaddr, macmask);
1432 if (status != VXGE_HW_OK) {
1433 vxge_debug_init(VXGE_ERR,
1434 "DA config list entry failed for vpath:%d",
1435 vpath->device_id);
1436 return status;
1437 }
1438
1439 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1440 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1441 macaddr, macmask);
1442 if (status != VXGE_HW_OK)
1443 break;
1444 }
1445
1446 return status;
1447}
1448
1449/* Store all mac addresses from the list to the DA table */
1450static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1451{
1452 enum vxge_hw_status status = VXGE_HW_OK;
1453 struct macInfo mac_info;
1454 u8 *mac_address = NULL;
1455 struct list_head *entry, *next;
1456
1457 memset(&mac_info, 0, sizeof(struct macInfo));
1458
1459 if (vpath->is_open) {
1460 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1461 mac_address =
1462 (u8 *)&
1463 ((struct vxge_mac_addrs *)entry)->macaddr;
1464 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1465 ((struct vxge_mac_addrs *)entry)->state =
1466 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1467 /* does this mac address already exist in da table? */
1468 status = vxge_search_mac_addr_in_da_table(vpath,
1469 &mac_info);
1470 if (status != VXGE_HW_OK) {
1471 /* Add this mac address to the DA table */
1472 status = vxge_hw_vpath_mac_addr_add(
1473 vpath->handle, mac_info.macaddr,
1474 mac_info.macmask,
1475 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
1476 if (status != VXGE_HW_OK) {
1477 vxge_debug_init(VXGE_ERR,
1478 "DA add entry failed for vpath:%d",
1479 vpath->device_id);
1480 ((struct vxge_mac_addrs *)entry)->state
1481 = VXGE_LL_MAC_ADDR_IN_LIST;
1482 }
1483 }
1484 }
1485 }
1486
1487 return status;
1488}
1489
1490/* Store all vlan ids from the list to the vid table */
1491static enum vxge_hw_status
1492vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1493{
1494 enum vxge_hw_status status = VXGE_HW_OK;
1495 struct vxgedev *vdev = vpath->vdev;
1496 u16 vid;
1497
1498 if (vdev->vlgrp && vpath->is_open) {
1499
1500 for (vid = 0; vid < VLAN_N_VID; vid++) {
1501 if (!vlan_group_get_device(vdev->vlgrp, vid))
1502 continue;
1503 /* Add these vlan to the vid table */
1504 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
1505 }
1506 }
1507
1508 return status;
1509}
1510
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001511/*
1512 * vxge_reset_vpath
1513 * @vdev: pointer to vdev
1514 * @vp_id: vpath to reset
1515 *
1516 * Resets the vpath
1517*/
1518static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1519{
1520 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00001521 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001522 int ret = 0;
1523
1524 /* check if device is down already */
1525 if (unlikely(!is_vxge_card_up(vdev)))
1526 return 0;
1527
1528 /* is device reset already scheduled */
1529 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1530 return 0;
1531
Jon Mason7adf7d12010-07-15 08:47:24 +00001532 if (vpath->handle) {
1533 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001534 if (is_vxge_card_up(vdev) &&
Jon Mason7adf7d12010-07-15 08:47:24 +00001535 vxge_hw_vpath_recover_from_reset(vpath->handle)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001536 != VXGE_HW_OK) {
1537 vxge_debug_init(VXGE_ERR,
1538 "vxge_hw_vpath_recover_from_reset"
1539 "failed for vpath:%d", vp_id);
1540 return status;
1541 }
1542 } else {
1543 vxge_debug_init(VXGE_ERR,
1544 "vxge_hw_vpath_reset failed for"
1545 "vpath:%d", vp_id);
1546 return status;
1547 }
1548 } else
1549 return VXGE_HW_FAIL;
1550
Jon Mason7adf7d12010-07-15 08:47:24 +00001551 vxge_restore_vpath_mac_addr(vpath);
1552 vxge_restore_vpath_vid_table(vpath);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001553
1554 /* Enable all broadcast */
Jon Mason7adf7d12010-07-15 08:47:24 +00001555 vxge_hw_vpath_bcast_enable(vpath->handle);
1556
1557 /* Enable all multicast */
1558 if (vdev->all_multi_flg) {
1559 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1560 if (status != VXGE_HW_OK)
1561 vxge_debug_init(VXGE_ERR,
1562 "%s:%d Enabling multicast failed",
1563 __func__, __LINE__);
1564 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001565
1566 /* Enable the interrupts */
1567 vxge_vpath_intr_enable(vdev, vp_id);
1568
1569 smp_wmb();
1570
1571 /* Enable the flow of traffic through the vpath */
Jon Mason7adf7d12010-07-15 08:47:24 +00001572 vxge_hw_vpath_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001573
1574 smp_wmb();
Jon Mason7adf7d12010-07-15 08:47:24 +00001575 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
1576 vpath->ring.last_status = VXGE_HW_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001577
1578 /* Vpath reset done */
1579 clear_bit(vp_id, &vdev->vp_reset);
1580
1581 /* Start the vpath queue */
Jon Mason98f45da2010-07-15 08:47:25 +00001582 if (netif_tx_queue_stopped(vpath->fifo.txq))
1583 netif_tx_wake_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001584
1585 return ret;
1586}
1587
Jon Mason16fded72011-01-18 15:02:21 +00001588/* Configure CI */
1589static void vxge_config_ci_for_tti_rti(struct vxgedev *vdev)
1590{
1591 int i = 0;
1592
1593 /* Enable CI for RTI */
1594 if (vdev->config.intr_type == MSI_X) {
1595 for (i = 0; i < vdev->no_of_vpath; i++) {
1596 struct __vxge_hw_ring *hw_ring;
1597
1598 hw_ring = vdev->vpaths[i].ring.handle;
1599 vxge_hw_vpath_dynamic_rti_ci_set(hw_ring);
1600 }
1601 }
1602
1603 /* Enable CI for TTI */
1604 for (i = 0; i < vdev->no_of_vpath; i++) {
1605 struct __vxge_hw_fifo *hw_fifo = vdev->vpaths[i].fifo.handle;
1606 vxge_hw_vpath_tti_ci_set(hw_fifo);
1607 /*
1608 * For Inta (with or without napi), Set CI ON for only one
1609 * vpath. (Have only one free running timer).
1610 */
1611 if ((vdev->config.intr_type == INTA) && (i == 0))
1612 break;
1613 }
1614
1615 return;
1616}
1617
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001618static int do_vxge_reset(struct vxgedev *vdev, int event)
1619{
1620 enum vxge_hw_status status;
1621 int ret = 0, vp_id, i;
1622
1623 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1624
1625 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1626 /* check if device is down already */
1627 if (unlikely(!is_vxge_card_up(vdev)))
1628 return 0;
1629
1630 /* is reset already scheduled */
1631 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1632 return 0;
1633 }
1634
1635 if (event == VXGE_LL_FULL_RESET) {
Jon Mason2e41f642010-12-10 14:02:59 +00001636 netif_carrier_off(vdev->ndev);
1637
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001638 /* wait for all the vpath reset to complete */
1639 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1640 while (test_bit(vp_id, &vdev->vp_reset))
1641 msleep(50);
1642 }
1643
Jon Mason2e41f642010-12-10 14:02:59 +00001644 netif_carrier_on(vdev->ndev);
1645
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001646 /* if execution mode is set to debug, don't reset the adapter */
1647 if (unlikely(vdev->exec_mode)) {
1648 vxge_debug_init(VXGE_ERR,
1649 "%s: execution mode is debug, returning..",
1650 vdev->ndev->name);
Jon Mason7adf7d12010-07-15 08:47:24 +00001651 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1652 netif_tx_stop_all_queues(vdev->ndev);
1653 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001654 }
1655 }
1656
1657 if (event == VXGE_LL_FULL_RESET) {
Jon Mason4d2a5b42010-11-11 04:25:54 +00001658 vxge_hw_device_wait_receive_idle(vdev->devh);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001659 vxge_hw_device_intr_disable(vdev->devh);
1660
1661 switch (vdev->cric_err_event) {
1662 case VXGE_HW_EVENT_UNKNOWN:
Jon Masond03848e2010-07-15 08:47:23 +00001663 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001664 vxge_debug_init(VXGE_ERR,
1665 "fatal: %s: Disabling device due to"
1666 "unknown error",
1667 vdev->ndev->name);
1668 ret = -EPERM;
1669 goto out;
1670 case VXGE_HW_EVENT_RESET_START:
1671 break;
1672 case VXGE_HW_EVENT_RESET_COMPLETE:
1673 case VXGE_HW_EVENT_LINK_DOWN:
1674 case VXGE_HW_EVENT_LINK_UP:
1675 case VXGE_HW_EVENT_ALARM_CLEARED:
1676 case VXGE_HW_EVENT_ECCERR:
1677 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1678 ret = -EPERM;
1679 goto out;
1680 case VXGE_HW_EVENT_FIFO_ERR:
1681 case VXGE_HW_EVENT_VPATH_ERR:
1682 break;
1683 case VXGE_HW_EVENT_CRITICAL_ERR:
Jon Masond03848e2010-07-15 08:47:23 +00001684 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001685 vxge_debug_init(VXGE_ERR,
1686 "fatal: %s: Disabling device due to"
1687 "serious error",
1688 vdev->ndev->name);
1689 /* SOP or device reset required */
1690 /* This event is not currently used */
1691 ret = -EPERM;
1692 goto out;
1693 case VXGE_HW_EVENT_SERR:
Jon Masond03848e2010-07-15 08:47:23 +00001694 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001695 vxge_debug_init(VXGE_ERR,
1696 "fatal: %s: Disabling device due to"
1697 "serious error",
1698 vdev->ndev->name);
1699 ret = -EPERM;
1700 goto out;
1701 case VXGE_HW_EVENT_SRPCIM_SERR:
1702 case VXGE_HW_EVENT_MRPCIM_SERR:
1703 ret = -EPERM;
1704 goto out;
1705 case VXGE_HW_EVENT_SLOT_FREEZE:
Jon Masond03848e2010-07-15 08:47:23 +00001706 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001707 vxge_debug_init(VXGE_ERR,
1708 "fatal: %s: Disabling device due to"
1709 "slot freeze",
1710 vdev->ndev->name);
1711 ret = -EPERM;
1712 goto out;
1713 default:
1714 break;
1715
1716 }
1717 }
1718
1719 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
Jon Masond03848e2010-07-15 08:47:23 +00001720 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001721
1722 if (event == VXGE_LL_FULL_RESET) {
1723 status = vxge_reset_all_vpaths(vdev);
1724 if (status != VXGE_HW_OK) {
1725 vxge_debug_init(VXGE_ERR,
1726 "fatal: %s: can not reset vpaths",
1727 vdev->ndev->name);
1728 ret = -EPERM;
1729 goto out;
1730 }
1731 }
1732
1733 if (event == VXGE_LL_COMPL_RESET) {
1734 for (i = 0; i < vdev->no_of_vpath; i++)
1735 if (vdev->vpaths[i].handle) {
1736 if (vxge_hw_vpath_recover_from_reset(
1737 vdev->vpaths[i].handle)
1738 != VXGE_HW_OK) {
1739 vxge_debug_init(VXGE_ERR,
1740 "vxge_hw_vpath_recover_"
1741 "from_reset failed for vpath: "
1742 "%d", i);
1743 ret = -EPERM;
1744 goto out;
1745 }
1746 } else {
1747 vxge_debug_init(VXGE_ERR,
1748 "vxge_hw_vpath_reset failed for "
1749 "vpath:%d", i);
1750 ret = -EPERM;
1751 goto out;
1752 }
1753 }
1754
1755 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1756 /* Reprogram the DA table with populated mac addresses */
1757 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1758 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1759 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1760 }
1761
1762 /* enable vpath interrupts */
1763 for (i = 0; i < vdev->no_of_vpath; i++)
1764 vxge_vpath_intr_enable(vdev, i);
1765
1766 vxge_hw_device_intr_enable(vdev->devh);
1767
1768 smp_wmb();
1769
1770 /* Indicate card up */
1771 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1772
1773 /* Get the traffic to flow through the vpaths */
1774 for (i = 0; i < vdev->no_of_vpath; i++) {
1775 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1776 smp_wmb();
1777 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1778 }
1779
Jon Masond03848e2010-07-15 08:47:23 +00001780 netif_tx_wake_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001781 }
1782
Jon Mason16fded72011-01-18 15:02:21 +00001783 /* configure CI */
1784 vxge_config_ci_for_tti_rti(vdev);
1785
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001786out:
1787 vxge_debug_entryexit(VXGE_TRACE,
1788 "%s:%d Exiting...", __func__, __LINE__);
1789
1790 /* Indicate reset done */
1791 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1792 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1793 return ret;
1794}
1795
1796/*
1797 * vxge_reset
1798 * @vdev: pointer to ll device
1799 *
1800 * driver may reset the chip on events of serr, eccerr, etc
1801 */
Jon Mason2e41f642010-12-10 14:02:59 +00001802static void vxge_reset(struct work_struct *work)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001803{
Jon Mason2e41f642010-12-10 14:02:59 +00001804 struct vxgedev *vdev = container_of(work, struct vxgedev, reset_task);
1805
1806 if (!netif_running(vdev->ndev))
1807 return;
1808
1809 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001810}
1811
1812/**
1813 * vxge_poll - Receive handler when Receive Polling is used.
1814 * @dev: pointer to the device structure.
1815 * @budget: Number of packets budgeted to be processed in this iteration.
1816 *
1817 * This function comes into picture only if Receive side is being handled
1818 * through polling (called NAPI in linux). It mostly does what the normal
1819 * Rx interrupt handler does in terms of descriptor and packet processing
1820 * but not in an interrupt context. Also it will process a specified number
1821 * of packets at most in one iteration. This value is passed down by the
1822 * kernel as the function argument 'budget'.
1823 */
1824static int vxge_poll_msix(struct napi_struct *napi, int budget)
1825{
Jon Mason16fded72011-01-18 15:02:21 +00001826 struct vxge_ring *ring = container_of(napi, struct vxge_ring, napi);
1827 int pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001828 int budget_org = budget;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001829
Jon Mason16fded72011-01-18 15:02:21 +00001830 ring->budget = budget;
1831 ring->pkts_processed = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001832 vxge_hw_vpath_poll_rx(ring->handle);
Jon Mason16fded72011-01-18 15:02:21 +00001833 pkts_processed = ring->pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001834
1835 if (ring->pkts_processed < budget_org) {
1836 napi_complete(napi);
Jon Mason16fded72011-01-18 15:02:21 +00001837
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001838 /* Re enable the Rx interrupts for the vpath */
1839 vxge_hw_channel_msix_unmask(
1840 (struct __vxge_hw_channel *)ring->handle,
1841 ring->rx_vector_no);
Jon Mason16fded72011-01-18 15:02:21 +00001842 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001843 }
1844
Jon Mason16fded72011-01-18 15:02:21 +00001845 /* We are copying and returning the local variable, in case if after
1846 * clearing the msix interrupt above, if the interrupt fires right
1847 * away which can preempt this NAPI thread */
1848 return pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001849}
1850
1851static int vxge_poll_inta(struct napi_struct *napi, int budget)
1852{
1853 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1854 int pkts_processed = 0;
1855 int i;
1856 int budget_org = budget;
1857 struct vxge_ring *ring;
1858
Joe Perchesd8ee7072010-11-15 10:13:58 +00001859 struct __vxge_hw_device *hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001860
1861 for (i = 0; i < vdev->no_of_vpath; i++) {
1862 ring = &vdev->vpaths[i].ring;
1863 ring->budget = budget;
Jon Mason16fded72011-01-18 15:02:21 +00001864 ring->pkts_processed = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001865 vxge_hw_vpath_poll_rx(ring->handle);
1866 pkts_processed += ring->pkts_processed;
1867 budget -= ring->pkts_processed;
1868 if (budget <= 0)
1869 break;
1870 }
1871
1872 VXGE_COMPLETE_ALL_TX(vdev);
1873
1874 if (pkts_processed < budget_org) {
1875 napi_complete(napi);
1876 /* Re enable the Rx interrupts for the ring */
1877 vxge_hw_device_unmask_all(hldev);
1878 vxge_hw_device_flush_io(hldev);
1879 }
1880
1881 return pkts_processed;
1882}
1883
1884#ifdef CONFIG_NET_POLL_CONTROLLER
1885/**
1886 * vxge_netpoll - netpoll event handler entry point
1887 * @dev : pointer to the device structure.
1888 * Description:
1889 * This function will be called by upper layer to check for events on the
1890 * interface in situations where interrupts are disabled. It is used for
1891 * specific in-kernel networking tasks, such as remote consoles and kernel
1892 * debugging over the network (example netdump in RedHat).
1893 */
1894static void vxge_netpoll(struct net_device *dev)
1895{
Jon Mason2c913082010-11-11 04:26:03 +00001896 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001897 struct vxgedev *vdev;
1898
Joe Perches5f54ceb2010-11-15 11:12:30 +00001899 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00001900 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001901
1902 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1903
1904 if (pci_channel_offline(vdev->pdev))
1905 return;
1906
1907 disable_irq(dev->irq);
1908 vxge_hw_device_clear_tx_rx(hldev);
1909
1910 vxge_hw_device_clear_tx_rx(hldev);
1911 VXGE_COMPLETE_ALL_RX(vdev);
1912 VXGE_COMPLETE_ALL_TX(vdev);
1913
1914 enable_irq(dev->irq);
1915
1916 vxge_debug_entryexit(VXGE_TRACE,
1917 "%s:%d Exiting...", __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001918}
1919#endif
1920
1921/* RTH configuration */
1922static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1923{
1924 enum vxge_hw_status status = VXGE_HW_OK;
1925 struct vxge_hw_rth_hash_types hash_types;
1926 u8 itable[256] = {0}; /* indirection table */
1927 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1928 int index;
1929
1930 /*
1931 * Filling
1932 * - itable with bucket numbers
1933 * - mtable with bucket-to-vpath mapping
1934 */
1935 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1936 itable[index] = index;
1937 mtable[index] = index % vdev->no_of_vpath;
1938 }
1939
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001940 /* set indirection table, bucket-to-vpath mapping */
1941 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1942 vdev->no_of_vpath,
1943 mtable, itable,
1944 vdev->config.rth_bkt_sz);
1945 if (status != VXGE_HW_OK) {
1946 vxge_debug_init(VXGE_ERR,
1947 "RTH indirection table configuration failed "
1948 "for vpath:%d", vdev->vpaths[0].device_id);
1949 return status;
1950 }
1951
Jon Mason47f01db2010-11-11 04:25:53 +00001952 /* Fill RTH hash types */
1953 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1954 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1955 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1956 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1957 hash_types.hash_type_tcpipv6ex_en =
1958 vdev->config.rth_hash_type_tcpipv6ex;
1959 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1960
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001961 /*
Jon Mason47f01db2010-11-11 04:25:53 +00001962 * Because the itable_set() method uses the active_table field
1963 * for the target virtual path the RTH config should be updated
1964 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1965 * when steering frames.
1966 */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001967 for (index = 0; index < vdev->no_of_vpath; index++) {
1968 status = vxge_hw_vpath_rts_rth_set(
1969 vdev->vpaths[index].handle,
1970 vdev->config.rth_algorithm,
1971 &hash_types,
1972 vdev->config.rth_bkt_sz);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001973 if (status != VXGE_HW_OK) {
1974 vxge_debug_init(VXGE_ERR,
1975 "RTH configuration failed for vpath:%d",
1976 vdev->vpaths[index].device_id);
1977 return status;
1978 }
1979 }
1980
1981 return status;
1982}
1983
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001984/* reset vpaths */
Jon Mason4d2a5b42010-11-11 04:25:54 +00001985enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001986{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001987 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00001988 struct vxge_vpath *vpath;
1989 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001990
Jon Mason7adf7d12010-07-15 08:47:24 +00001991 for (i = 0; i < vdev->no_of_vpath; i++) {
1992 vpath = &vdev->vpaths[i];
1993 if (vpath->handle) {
1994 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001995 if (is_vxge_card_up(vdev) &&
1996 vxge_hw_vpath_recover_from_reset(
Jon Mason7adf7d12010-07-15 08:47:24 +00001997 vpath->handle) != VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001998 vxge_debug_init(VXGE_ERR,
1999 "vxge_hw_vpath_recover_"
2000 "from_reset failed for vpath: "
2001 "%d", i);
2002 return status;
2003 }
2004 } else {
2005 vxge_debug_init(VXGE_ERR,
2006 "vxge_hw_vpath_reset failed for "
2007 "vpath:%d", i);
2008 return status;
2009 }
2010 }
Jon Mason7adf7d12010-07-15 08:47:24 +00002011 }
2012
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002013 return status;
2014}
2015
2016/* close vpaths */
stephen hemminger42821a52010-10-21 07:50:53 +00002017static void vxge_close_vpaths(struct vxgedev *vdev, int index)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002018{
Jon Mason7adf7d12010-07-15 08:47:24 +00002019 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002020 int i;
Jon Mason7adf7d12010-07-15 08:47:24 +00002021
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002022 for (i = index; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002023 vpath = &vdev->vpaths[i];
2024
2025 if (vpath->handle && vpath->is_open) {
2026 vxge_hw_vpath_close(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002027 vdev->stats.vpaths_open--;
2028 }
Jon Mason7adf7d12010-07-15 08:47:24 +00002029 vpath->is_open = 0;
2030 vpath->handle = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002031 }
2032}
2033
2034/* open vpaths */
stephen hemminger42821a52010-10-21 07:50:53 +00002035static int vxge_open_vpaths(struct vxgedev *vdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002036{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002037 struct vxge_hw_vpath_attr attr;
Jon Mason7adf7d12010-07-15 08:47:24 +00002038 enum vxge_hw_status status;
2039 struct vxge_vpath *vpath;
2040 u32 vp_id = 0;
2041 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002042
2043 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002044 vpath = &vdev->vpaths[i];
Jon Mason7adf7d12010-07-15 08:47:24 +00002045 vxge_assert(vpath->is_configured);
Jon Masone7935c92010-11-11 04:26:00 +00002046
2047 if (!vdev->titan1) {
2048 struct vxge_hw_vp_config *vcfg;
2049 vcfg = &vdev->devh->config.vp_config[vpath->device_id];
2050
2051 vcfg->rti.urange_a = RTI_T1A_RX_URANGE_A;
2052 vcfg->rti.urange_b = RTI_T1A_RX_URANGE_B;
2053 vcfg->rti.urange_c = RTI_T1A_RX_URANGE_C;
2054 vcfg->tti.uec_a = TTI_T1A_TX_UFC_A;
2055 vcfg->tti.uec_b = TTI_T1A_TX_UFC_B;
2056 vcfg->tti.uec_c = TTI_T1A_TX_UFC_C(vdev->mtu);
2057 vcfg->tti.uec_d = TTI_T1A_TX_UFC_D(vdev->mtu);
2058 vcfg->tti.ltimer_val = VXGE_T1A_TTI_LTIMER_VAL;
2059 vcfg->tti.rtimer_val = VXGE_T1A_TTI_RTIMER_VAL;
2060 }
2061
Jon Mason7adf7d12010-07-15 08:47:24 +00002062 attr.vp_id = vpath->device_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002063 attr.fifo_attr.callback = vxge_xmit_compl;
2064 attr.fifo_attr.txdl_term = vxge_tx_term;
2065 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
Jon Mason7adf7d12010-07-15 08:47:24 +00002066 attr.fifo_attr.userdata = &vpath->fifo;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002067
2068 attr.ring_attr.callback = vxge_rx_1b_compl;
2069 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2070 attr.ring_attr.rxd_term = vxge_rx_term;
2071 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
Jon Mason7adf7d12010-07-15 08:47:24 +00002072 attr.ring_attr.userdata = &vpath->ring;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002073
Jon Mason7adf7d12010-07-15 08:47:24 +00002074 vpath->ring.ndev = vdev->ndev;
2075 vpath->ring.pdev = vdev->pdev;
Jon Mason528f7272010-12-10 14:02:56 +00002076
Jon Mason7adf7d12010-07-15 08:47:24 +00002077 status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002078 if (status == VXGE_HW_OK) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002079 vpath->fifo.handle =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002080 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
Jon Mason7adf7d12010-07-15 08:47:24 +00002081 vpath->ring.handle =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002082 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
Jon Mason7adf7d12010-07-15 08:47:24 +00002083 vpath->fifo.tx_steering_type =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002084 vdev->config.tx_steering_type;
Jon Mason7adf7d12010-07-15 08:47:24 +00002085 vpath->fifo.ndev = vdev->ndev;
2086 vpath->fifo.pdev = vdev->pdev;
Jon Mason98f45da2010-07-15 08:47:25 +00002087 if (vdev->config.tx_steering_type)
2088 vpath->fifo.txq =
2089 netdev_get_tx_queue(vdev->ndev, i);
2090 else
2091 vpath->fifo.txq =
2092 netdev_get_tx_queue(vdev->ndev, 0);
Jon Mason7adf7d12010-07-15 08:47:24 +00002093 vpath->fifo.indicate_max_pkts =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002094 vdev->config.fifo_indicate_max_pkts;
Jon Mason16fded72011-01-18 15:02:21 +00002095 vpath->fifo.tx_vector_no = 0;
Jon Mason7adf7d12010-07-15 08:47:24 +00002096 vpath->ring.rx_vector_no = 0;
2097 vpath->ring.rx_csum = vdev->rx_csum;
Jon Masonb81b3732010-11-11 04:25:58 +00002098 vpath->ring.rx_hwts = vdev->rx_hwts;
Jon Mason7adf7d12010-07-15 08:47:24 +00002099 vpath->is_open = 1;
2100 vdev->vp_handles[i] = vpath->handle;
2101 vpath->ring.gro_enable = vdev->config.gro_enable;
2102 vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002103 vdev->stats.vpaths_open++;
2104 } else {
2105 vdev->stats.vpath_open_fail++;
Jon Mason528f7272010-12-10 14:02:56 +00002106 vxge_debug_init(VXGE_ERR, "%s: vpath: %d failed to "
2107 "open with status: %d",
2108 vdev->ndev->name, vpath->device_id,
2109 status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002110 vxge_close_vpaths(vdev, 0);
2111 return -EPERM;
2112 }
2113
Jon Mason7adf7d12010-07-15 08:47:24 +00002114 vp_id = vpath->handle->vpath->vp_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002115 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2116 }
Jon Mason528f7272010-12-10 14:02:56 +00002117
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002118 return VXGE_HW_OK;
2119}
2120
Jon Mason16fded72011-01-18 15:02:21 +00002121/**
2122 * adaptive_coalesce_tx_interrupts - Changes the interrupt coalescing
2123 * if the interrupts are not within a range
2124 * @fifo: pointer to transmit fifo structure
2125 * Description: The function changes boundary timer and restriction timer
2126 * value depends on the traffic
2127 * Return Value: None
2128 */
2129static void adaptive_coalesce_tx_interrupts(struct vxge_fifo *fifo)
2130{
2131 fifo->interrupt_count++;
2132 if (jiffies > fifo->jiffies + HZ / 100) {
2133 struct __vxge_hw_fifo *hw_fifo = fifo->handle;
2134
2135 fifo->jiffies = jiffies;
2136 if (fifo->interrupt_count > VXGE_T1A_MAX_TX_INTERRUPT_COUNT &&
2137 hw_fifo->rtimer != VXGE_TTI_RTIMER_ADAPT_VAL) {
2138 hw_fifo->rtimer = VXGE_TTI_RTIMER_ADAPT_VAL;
2139 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2140 } else if (hw_fifo->rtimer != 0) {
2141 hw_fifo->rtimer = 0;
2142 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2143 }
2144 fifo->interrupt_count = 0;
2145 }
2146}
2147
2148/**
2149 * adaptive_coalesce_rx_interrupts - Changes the interrupt coalescing
2150 * if the interrupts are not within a range
2151 * @ring: pointer to receive ring structure
2152 * Description: The function increases of decreases the packet counts within
2153 * the ranges of traffic utilization, if the interrupts due to this ring are
2154 * not within a fixed range.
2155 * Return Value: Nothing
2156 */
2157static void adaptive_coalesce_rx_interrupts(struct vxge_ring *ring)
2158{
2159 ring->interrupt_count++;
2160 if (jiffies > ring->jiffies + HZ / 100) {
2161 struct __vxge_hw_ring *hw_ring = ring->handle;
2162
2163 ring->jiffies = jiffies;
2164 if (ring->interrupt_count > VXGE_T1A_MAX_INTERRUPT_COUNT &&
2165 hw_ring->rtimer != VXGE_RTI_RTIMER_ADAPT_VAL) {
2166 hw_ring->rtimer = VXGE_RTI_RTIMER_ADAPT_VAL;
2167 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2168 } else if (hw_ring->rtimer != 0) {
2169 hw_ring->rtimer = 0;
2170 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2171 }
2172 ring->interrupt_count = 0;
2173 }
2174}
2175
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002176/*
2177 * vxge_isr_napi
2178 * @irq: the irq of the device.
2179 * @dev_id: a void pointer to the hldev structure of the Titan device
2180 * @ptregs: pointer to the registers pushed on the stack.
2181 *
2182 * This function is the ISR handler of the device when napi is enabled. It
2183 * identifies the reason for the interrupt and calls the relevant service
2184 * routines.
2185 */
2186static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2187{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002188 struct net_device *dev;
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002189 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002190 u64 reason;
2191 enum vxge_hw_status status;
Jon Mason2c913082010-11-11 04:26:03 +00002192 struct vxgedev *vdev = (struct vxgedev *)dev_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002193
2194 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2195
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002196 dev = vdev->ndev;
Joe Perchesd8ee7072010-11-15 10:13:58 +00002197 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002198
2199 if (pci_channel_offline(vdev->pdev))
2200 return IRQ_NONE;
2201
2202 if (unlikely(!is_vxge_card_up(vdev)))
Jon Mason4d2a5b42010-11-11 04:25:54 +00002203 return IRQ_HANDLED;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002204
Jon Mason528f7272010-12-10 14:02:56 +00002205 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, &reason);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002206 if (status == VXGE_HW_OK) {
2207 vxge_hw_device_mask_all(hldev);
2208
2209 if (reason &
2210 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2211 vdev->vpaths_deployed >>
2212 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2213
2214 vxge_hw_device_clear_tx_rx(hldev);
2215 napi_schedule(&vdev->napi);
2216 vxge_debug_intr(VXGE_TRACE,
2217 "%s:%d Exiting...", __func__, __LINE__);
2218 return IRQ_HANDLED;
2219 } else
2220 vxge_hw_device_unmask_all(hldev);
2221 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2222 (status == VXGE_HW_ERR_CRITICAL) ||
2223 (status == VXGE_HW_ERR_FIFO))) {
2224 vxge_hw_device_mask_all(hldev);
2225 vxge_hw_device_flush_io(hldev);
2226 return IRQ_HANDLED;
2227 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2228 return IRQ_HANDLED;
2229
2230 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2231 return IRQ_NONE;
2232}
2233
2234#ifdef CONFIG_PCI_MSI
2235
Jon Mason16fded72011-01-18 15:02:21 +00002236static irqreturn_t vxge_tx_msix_handle(int irq, void *dev_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002237{
2238 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2239
Jon Mason16fded72011-01-18 15:02:21 +00002240 adaptive_coalesce_tx_interrupts(fifo);
2241
2242 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)fifo->handle,
2243 fifo->tx_vector_no);
2244
2245 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)fifo->handle,
2246 fifo->tx_vector_no);
2247
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002248 VXGE_COMPLETE_VPATH_TX(fifo);
2249
Jon Mason16fded72011-01-18 15:02:21 +00002250 vxge_hw_channel_msix_unmask((struct __vxge_hw_channel *)fifo->handle,
2251 fifo->tx_vector_no);
2252
2253 mmiowb();
2254
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002255 return IRQ_HANDLED;
2256}
2257
Jon Mason16fded72011-01-18 15:02:21 +00002258static irqreturn_t vxge_rx_msix_napi_handle(int irq, void *dev_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002259{
2260 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2261
Jon Mason16fded72011-01-18 15:02:21 +00002262 adaptive_coalesce_rx_interrupts(ring);
2263
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002264 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
Jon Mason16fded72011-01-18 15:02:21 +00002265 ring->rx_vector_no);
2266
2267 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)ring->handle,
2268 ring->rx_vector_no);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002269
2270 napi_schedule(&ring->napi);
2271 return IRQ_HANDLED;
2272}
2273
2274static irqreturn_t
2275vxge_alarm_msix_handle(int irq, void *dev_id)
2276{
2277 int i;
2278 enum vxge_hw_status status;
2279 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2280 struct vxgedev *vdev = vpath->vdev;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002281 int msix_id = (vpath->handle->vpath->vp_id *
2282 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002283
2284 for (i = 0; i < vdev->no_of_vpath; i++) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002285 /* Reduce the chance of losing alarm interrupts by masking
Jon Mason16fded72011-01-18 15:02:21 +00002286 * the vector. A pending bit will be set if an alarm is
2287 * generated and on unmask the interrupt will be fired.
2288 */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002289 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
Jon Mason16fded72011-01-18 15:02:21 +00002290 vxge_hw_vpath_msix_clear(vdev->vpaths[i].handle, msix_id);
2291 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002292
2293 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2294 vdev->exec_mode);
2295 if (status == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002296 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
Jon Mason16fded72011-01-18 15:02:21 +00002297 msix_id);
2298 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002299 continue;
2300 }
2301 vxge_debug_intr(VXGE_ERR,
2302 "%s: vxge_hw_vpath_alarm_process failed %x ",
2303 VXGE_DRIVER_NAME, status);
2304 }
2305 return IRQ_HANDLED;
2306}
2307
2308static int vxge_alloc_msix(struct vxgedev *vdev)
2309{
2310 int j, i, ret = 0;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002311 int msix_intr_vect = 0, temp;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002312 vdev->intr_cnt = 0;
2313
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002314start:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002315 /* Tx/Rx MSIX Vectors count */
2316 vdev->intr_cnt = vdev->no_of_vpath * 2;
2317
2318 /* Alarm MSIX Vectors count */
2319 vdev->intr_cnt++;
2320
Joe Perchesbaeb2ff2010-08-11 07:02:48 +00002321 vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
2322 GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002323 if (!vdev->entries) {
2324 vxge_debug_init(VXGE_ERR,
2325 "%s: memory allocation failed",
2326 VXGE_DRIVER_NAME);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002327 ret = -ENOMEM;
2328 goto alloc_entries_failed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002329 }
2330
Joe Perchesbaeb2ff2010-08-11 07:02:48 +00002331 vdev->vxge_entries = kcalloc(vdev->intr_cnt,
2332 sizeof(struct vxge_msix_entry),
2333 GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002334 if (!vdev->vxge_entries) {
2335 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2336 VXGE_DRIVER_NAME);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002337 ret = -ENOMEM;
2338 goto alloc_vxge_entries_failed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002339 }
2340
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002341 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002342
2343 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2344
2345 /* Initialize the fifo vector */
2346 vdev->entries[j].entry = msix_intr_vect;
2347 vdev->vxge_entries[j].entry = msix_intr_vect;
2348 vdev->vxge_entries[j].in_use = 0;
2349 j++;
2350
2351 /* Initialize the ring vector */
2352 vdev->entries[j].entry = msix_intr_vect + 1;
2353 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2354 vdev->vxge_entries[j].in_use = 0;
2355 j++;
2356 }
2357
2358 /* Initialize the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002359 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2360 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002361 vdev->vxge_entries[j].in_use = 0;
2362
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002363 ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002364 if (ret > 0) {
2365 vxge_debug_init(VXGE_ERR,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002366 "%s: MSI-X enable failed for %d vectors, ret: %d",
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002367 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002368 if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) {
2369 ret = -ENODEV;
2370 goto enable_msix_failed;
2371 }
2372
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002373 kfree(vdev->entries);
2374 kfree(vdev->vxge_entries);
2375 vdev->entries = NULL;
2376 vdev->vxge_entries = NULL;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002377 /* Try with less no of vector by reducing no of vpaths count */
2378 temp = (ret - 1)/2;
2379 vxge_close_vpaths(vdev, temp);
2380 vdev->no_of_vpath = temp;
2381 goto start;
Michal Schmidtcc413d92010-06-24 04:13:44 +00002382 } else if (ret < 0) {
2383 ret = -ENODEV;
2384 goto enable_msix_failed;
2385 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002386 return 0;
Michal Schmidtcc413d92010-06-24 04:13:44 +00002387
2388enable_msix_failed:
2389 kfree(vdev->vxge_entries);
2390alloc_vxge_entries_failed:
2391 kfree(vdev->entries);
2392alloc_entries_failed:
2393 return ret;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002394}
2395
2396static int vxge_enable_msix(struct vxgedev *vdev)
2397{
2398
2399 int i, ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002400 /* 0 - Tx, 1 - Rx */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002401 int tim_msix_id[4] = {0, 1, 0, 0};
2402
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002403 vdev->intr_cnt = 0;
2404
2405 /* allocate msix vectors */
2406 ret = vxge_alloc_msix(vdev);
2407 if (!ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002408 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002409 struct vxge_vpath *vpath = &vdev->vpaths[i];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002410
Jon Mason7adf7d12010-07-15 08:47:24 +00002411 /* If fifo or ring are not enabled, the MSIX vector for
2412 * it should be set to 0.
2413 */
2414 vpath->ring.rx_vector_no = (vpath->device_id *
2415 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002416
Jon Mason16fded72011-01-18 15:02:21 +00002417 vpath->fifo.tx_vector_no = (vpath->device_id *
2418 VXGE_HW_VPATH_MSIX_ACTIVE);
2419
Jon Mason7adf7d12010-07-15 08:47:24 +00002420 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
2421 VXGE_ALARM_MSIX_ID);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002422 }
2423 }
2424
2425 return ret;
2426}
2427
2428static void vxge_rem_msix_isr(struct vxgedev *vdev)
2429{
2430 int intr_cnt;
2431
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002432 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002433 intr_cnt++) {
2434 if (vdev->vxge_entries[intr_cnt].in_use) {
2435 synchronize_irq(vdev->entries[intr_cnt].vector);
2436 free_irq(vdev->entries[intr_cnt].vector,
2437 vdev->vxge_entries[intr_cnt].arg);
2438 vdev->vxge_entries[intr_cnt].in_use = 0;
2439 }
2440 }
2441
2442 kfree(vdev->entries);
2443 kfree(vdev->vxge_entries);
2444 vdev->entries = NULL;
2445 vdev->vxge_entries = NULL;
2446
2447 if (vdev->config.intr_type == MSI_X)
2448 pci_disable_msix(vdev->pdev);
2449}
2450#endif
2451
2452static void vxge_rem_isr(struct vxgedev *vdev)
2453{
Jon Mason2c913082010-11-11 04:26:03 +00002454 struct __vxge_hw_device *hldev;
Joe Perchesd8ee7072010-11-15 10:13:58 +00002455 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002456
2457#ifdef CONFIG_PCI_MSI
2458 if (vdev->config.intr_type == MSI_X) {
2459 vxge_rem_msix_isr(vdev);
2460 } else
2461#endif
2462 if (vdev->config.intr_type == INTA) {
2463 synchronize_irq(vdev->pdev->irq);
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002464 free_irq(vdev->pdev->irq, vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002465 }
2466}
2467
2468static int vxge_add_isr(struct vxgedev *vdev)
2469{
2470 int ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002471#ifdef CONFIG_PCI_MSI
2472 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002473 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2474
2475 if (vdev->config.intr_type == MSI_X)
2476 ret = vxge_enable_msix(vdev);
2477
2478 if (ret) {
2479 vxge_debug_init(VXGE_ERR,
2480 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002481 vxge_debug_init(VXGE_ERR,
2482 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2483 vdev->config.intr_type = INTA;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002484 }
2485
2486 if (vdev->config.intr_type == MSI_X) {
2487 for (intr_idx = 0;
2488 intr_idx < (vdev->no_of_vpath *
2489 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2490
2491 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2492 irq_req = 0;
2493
2494 switch (msix_idx) {
2495 case 0:
2496 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002497 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2498 vdev->ndev->name,
2499 vdev->entries[intr_cnt].entry,
2500 pci_fun, vp_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002501 ret = request_irq(
2502 vdev->entries[intr_cnt].vector,
2503 vxge_tx_msix_handle, 0,
2504 vdev->desc[intr_cnt],
2505 &vdev->vpaths[vp_idx].fifo);
2506 vdev->vxge_entries[intr_cnt].arg =
2507 &vdev->vpaths[vp_idx].fifo;
2508 irq_req = 1;
2509 break;
2510 case 1:
2511 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002512 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2513 vdev->ndev->name,
2514 vdev->entries[intr_cnt].entry,
2515 pci_fun, vp_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002516 ret = request_irq(
2517 vdev->entries[intr_cnt].vector,
2518 vxge_rx_msix_napi_handle,
2519 0,
2520 vdev->desc[intr_cnt],
2521 &vdev->vpaths[vp_idx].ring);
2522 vdev->vxge_entries[intr_cnt].arg =
2523 &vdev->vpaths[vp_idx].ring;
2524 irq_req = 1;
2525 break;
2526 }
2527
2528 if (ret) {
2529 vxge_debug_init(VXGE_ERR,
2530 "%s: MSIX - %d Registration failed",
2531 vdev->ndev->name, intr_cnt);
2532 vxge_rem_msix_isr(vdev);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002533 vdev->config.intr_type = INTA;
2534 vxge_debug_init(VXGE_ERR,
2535 "%s: Defaulting to INTA"
2536 , vdev->ndev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002537 goto INTA_MODE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002538 }
2539
2540 if (irq_req) {
2541 /* We requested for this msix interrupt */
2542 vdev->vxge_entries[intr_cnt].in_use = 1;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002543 msix_idx += vdev->vpaths[vp_idx].device_id *
2544 VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002545 vxge_hw_vpath_msix_unmask(
2546 vdev->vpaths[vp_idx].handle,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002547 msix_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002548 intr_cnt++;
2549 }
2550
2551 /* Point to next vpath handler */
Joe Perches8e95a202009-12-03 07:58:21 +00002552 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2553 (vp_idx < (vdev->no_of_vpath - 1)))
2554 vp_idx++;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002555 }
2556
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002557 intr_cnt = vdev->no_of_vpath * 2;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002558 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002559 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2560 vdev->ndev->name,
2561 vdev->entries[intr_cnt].entry,
2562 pci_fun);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002563 /* For Alarm interrupts */
2564 ret = request_irq(vdev->entries[intr_cnt].vector,
2565 vxge_alarm_msix_handle, 0,
2566 vdev->desc[intr_cnt],
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002567 &vdev->vpaths[0]);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002568 if (ret) {
2569 vxge_debug_init(VXGE_ERR,
2570 "%s: MSIX - %d Registration failed",
2571 vdev->ndev->name, intr_cnt);
2572 vxge_rem_msix_isr(vdev);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002573 vdev->config.intr_type = INTA;
2574 vxge_debug_init(VXGE_ERR,
2575 "%s: Defaulting to INTA",
2576 vdev->ndev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002577 goto INTA_MODE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002578 }
2579
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002580 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2581 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002582 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002583 msix_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002584 vdev->vxge_entries[intr_cnt].in_use = 1;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002585 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002586 }
2587INTA_MODE:
2588#endif
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002589
2590 if (vdev->config.intr_type == INTA) {
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002591 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2592 "%s:vxge:INTA", vdev->ndev->name);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002593 vxge_hw_device_set_intr_type(vdev->devh,
2594 VXGE_HW_INTR_MODE_IRQLINE);
Jon Mason16fded72011-01-18 15:02:21 +00002595
2596 vxge_hw_vpath_tti_ci_set(vdev->vpaths[0].fifo.handle);
2597
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002598 ret = request_irq((int) vdev->pdev->irq,
2599 vxge_isr_napi,
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002600 IRQF_SHARED, vdev->desc[0], vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002601 if (ret) {
2602 vxge_debug_init(VXGE_ERR,
2603 "%s %s-%d: ISR registration failed",
2604 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2605 return -ENODEV;
2606 }
2607 vxge_debug_init(VXGE_TRACE,
2608 "new %s-%d line allocated",
2609 "IRQ", vdev->pdev->irq);
2610 }
2611
2612 return VXGE_HW_OK;
2613}
2614
2615static void vxge_poll_vp_reset(unsigned long data)
2616{
2617 struct vxgedev *vdev = (struct vxgedev *)data;
2618 int i, j = 0;
2619
2620 for (i = 0; i < vdev->no_of_vpath; i++) {
2621 if (test_bit(i, &vdev->vp_reset)) {
2622 vxge_reset_vpath(vdev, i);
2623 j++;
2624 }
2625 }
2626 if (j && (vdev->config.intr_type != MSI_X)) {
2627 vxge_hw_device_unmask_all(vdev->devh);
2628 vxge_hw_device_flush_io(vdev->devh);
2629 }
2630
2631 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2632}
2633
2634static void vxge_poll_vp_lockup(unsigned long data)
2635{
2636 struct vxgedev *vdev = (struct vxgedev *)data;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002637 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00002638 struct vxge_vpath *vpath;
2639 struct vxge_ring *ring;
2640 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002641
2642 for (i = 0; i < vdev->no_of_vpath; i++) {
2643 ring = &vdev->vpaths[i].ring;
2644 /* Did this vpath received any packets */
2645 if (ring->stats.prev_rx_frms == ring->stats.rx_frms) {
2646 status = vxge_hw_vpath_check_leak(ring->handle);
2647
2648 /* Did it received any packets last time */
2649 if ((VXGE_HW_FAIL == status) &&
2650 (VXGE_HW_FAIL == ring->last_status)) {
2651
2652 /* schedule vpath reset */
2653 if (!test_and_set_bit(i, &vdev->vp_reset)) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002654 vpath = &vdev->vpaths[i];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002655
2656 /* disable interrupts for this vpath */
2657 vxge_vpath_intr_disable(vdev, i);
2658
2659 /* stop the queue for this vpath */
Jon Mason98f45da2010-07-15 08:47:25 +00002660 netif_tx_stop_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002661 continue;
2662 }
2663 }
2664 }
2665 ring->stats.prev_rx_frms = ring->stats.rx_frms;
2666 ring->last_status = status;
2667 }
2668
2669 /* Check every 1 milli second */
2670 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2671}
2672
2673/**
2674 * vxge_open
2675 * @dev: pointer to the device structure.
2676 *
2677 * This function is the open entry point of the driver. It mainly calls a
2678 * function to allocate Rx buffers and inserts them into the buffer
2679 * descriptors and then enables the Rx part of the NIC.
2680 * Return value: '0' on success and an appropriate (-)ve integer as
2681 * defined in errno.h file on failure.
2682 */
Jon Mason528f7272010-12-10 14:02:56 +00002683static int vxge_open(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002684{
2685 enum vxge_hw_status status;
2686 struct vxgedev *vdev;
2687 struct __vxge_hw_device *hldev;
Jon Mason7adf7d12010-07-15 08:47:24 +00002688 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002689 int ret = 0;
2690 int i;
2691 u64 val64, function_mode;
Jon Mason528f7272010-12-10 14:02:56 +00002692
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002693 vxge_debug_entryexit(VXGE_TRACE,
2694 "%s: %s:%d", dev->name, __func__, __LINE__);
2695
Joe Perches5f54ceb2010-11-15 11:12:30 +00002696 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00002697 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002698 function_mode = vdev->config.device_hw_info.function_mode;
2699
2700 /* make sure you have link off by default every time Nic is
2701 * initialized */
2702 netif_carrier_off(dev);
2703
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002704 /* Open VPATHs */
2705 status = vxge_open_vpaths(vdev);
2706 if (status != VXGE_HW_OK) {
2707 vxge_debug_init(VXGE_ERR,
2708 "%s: fatal: Vpath open failed", vdev->ndev->name);
2709 ret = -EPERM;
2710 goto out0;
2711 }
2712
2713 vdev->mtu = dev->mtu;
2714
2715 status = vxge_add_isr(vdev);
2716 if (status != VXGE_HW_OK) {
2717 vxge_debug_init(VXGE_ERR,
2718 "%s: fatal: ISR add failed", dev->name);
2719 ret = -EPERM;
2720 goto out1;
2721 }
2722
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002723 if (vdev->config.intr_type != MSI_X) {
2724 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2725 vdev->config.napi_weight);
2726 napi_enable(&vdev->napi);
Jon Mason7adf7d12010-07-15 08:47:24 +00002727 for (i = 0; i < vdev->no_of_vpath; i++) {
2728 vpath = &vdev->vpaths[i];
2729 vpath->ring.napi_p = &vdev->napi;
2730 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002731 } else {
2732 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002733 vpath = &vdev->vpaths[i];
2734 netif_napi_add(dev, &vpath->ring.napi,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002735 vxge_poll_msix, vdev->config.napi_weight);
Jon Mason7adf7d12010-07-15 08:47:24 +00002736 napi_enable(&vpath->ring.napi);
2737 vpath->ring.napi_p = &vpath->ring.napi;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002738 }
2739 }
2740
2741 /* configure RTH */
2742 if (vdev->config.rth_steering) {
2743 status = vxge_rth_configure(vdev);
2744 if (status != VXGE_HW_OK) {
2745 vxge_debug_init(VXGE_ERR,
2746 "%s: fatal: RTH configuration failed",
2747 dev->name);
2748 ret = -EPERM;
2749 goto out2;
2750 }
2751 }
Jon Mason47f01db2010-11-11 04:25:53 +00002752 printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name,
2753 hldev->config.rth_en ? "enabled" : "disabled");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002754
2755 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002756 vpath = &vdev->vpaths[i];
2757
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002758 /* set initial mtu before enabling the device */
Jon Mason7adf7d12010-07-15 08:47:24 +00002759 status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002760 if (status != VXGE_HW_OK) {
2761 vxge_debug_init(VXGE_ERR,
2762 "%s: fatal: can not set new MTU", dev->name);
2763 ret = -EPERM;
2764 goto out2;
2765 }
2766 }
2767
2768 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2769 vxge_debug_init(vdev->level_trace,
2770 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2771 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2772
Jon Mason7adf7d12010-07-15 08:47:24 +00002773 /* Restore the DA, VID table and also multicast and promiscuous mode
2774 * states
2775 */
2776 if (vdev->all_multi_flg) {
2777 for (i = 0; i < vdev->no_of_vpath; i++) {
2778 vpath = &vdev->vpaths[i];
2779 vxge_restore_vpath_mac_addr(vpath);
2780 vxge_restore_vpath_vid_table(vpath);
2781
2782 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2783 if (status != VXGE_HW_OK)
2784 vxge_debug_init(VXGE_ERR,
2785 "%s:%d Enabling multicast failed",
2786 __func__, __LINE__);
2787 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002788 }
2789
2790 /* Enable vpath to sniff all unicast/multicast traffic that not
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002791 * addressed to them. We allow promiscuous mode for PF only
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002792 */
2793
2794 val64 = 0;
2795 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2796 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2797
2798 vxge_hw_mgmt_reg_write(vdev->devh,
2799 vxge_hw_mgmt_reg_type_mrpcim,
2800 0,
2801 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2802 rxmac_authorize_all_addr),
2803 val64);
2804
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_vid),
2810 val64);
2811
2812 vxge_set_multicast(dev);
2813
2814 /* Enabling Bcast and mcast for all vpath */
2815 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002816 vpath = &vdev->vpaths[i];
2817 status = vxge_hw_vpath_bcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002818 if (status != VXGE_HW_OK)
2819 vxge_debug_init(VXGE_ERR,
2820 "%s : Can not enable bcast for vpath "
2821 "id %d", dev->name, i);
2822 if (vdev->config.addr_learn_en) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002823 status = vxge_hw_vpath_mcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002824 if (status != VXGE_HW_OK)
2825 vxge_debug_init(VXGE_ERR,
2826 "%s : Can not enable mcast for vpath "
2827 "id %d", dev->name, i);
2828 }
2829 }
2830
2831 vxge_hw_device_setpause_data(vdev->devh, 0,
2832 vdev->config.tx_pause_enable,
2833 vdev->config.rx_pause_enable);
2834
2835 if (vdev->vp_reset_timer.function == NULL)
2836 vxge_os_timer(vdev->vp_reset_timer,
2837 vxge_poll_vp_reset, vdev, (HZ/2));
2838
Jon Masone7935c92010-11-11 04:26:00 +00002839 /* There is no need to check for RxD leak and RxD lookup on Titan1A */
2840 if (vdev->titan1 && vdev->vp_lockup_timer.function == NULL)
2841 vxge_os_timer(vdev->vp_lockup_timer, vxge_poll_vp_lockup, vdev,
2842 HZ / 2);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002843
2844 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2845
2846 smp_wmb();
2847
2848 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2849 netif_carrier_on(vdev->ndev);
Joe Perches75f5e1c2010-07-27 11:47:03 +00002850 netdev_notice(vdev->ndev, "Link Up\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002851 vdev->stats.link_up++;
2852 }
2853
2854 vxge_hw_device_intr_enable(vdev->devh);
2855
2856 smp_wmb();
2857
2858 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002859 vpath = &vdev->vpaths[i];
2860
2861 vxge_hw_vpath_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002862 smp_wmb();
Jon Mason7adf7d12010-07-15 08:47:24 +00002863 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002864 }
2865
Jon Masond03848e2010-07-15 08:47:23 +00002866 netif_tx_start_all_queues(vdev->ndev);
Jon Mason16fded72011-01-18 15:02:21 +00002867
2868 /* configure CI */
2869 vxge_config_ci_for_tti_rti(vdev);
2870
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002871 goto out0;
2872
2873out2:
2874 vxge_rem_isr(vdev);
2875
2876 /* Disable napi */
2877 if (vdev->config.intr_type != MSI_X)
2878 napi_disable(&vdev->napi);
2879 else {
2880 for (i = 0; i < vdev->no_of_vpath; i++)
2881 napi_disable(&vdev->vpaths[i].ring.napi);
2882 }
2883
2884out1:
2885 vxge_close_vpaths(vdev, 0);
2886out0:
2887 vxge_debug_entryexit(VXGE_TRACE,
2888 "%s: %s:%d Exiting...",
2889 dev->name, __func__, __LINE__);
2890 return ret;
2891}
2892
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002893/* Loop through the mac address list and delete all the entries */
stephen hemminger42821a52010-10-21 07:50:53 +00002894static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002895{
2896
2897 struct list_head *entry, *next;
2898 if (list_empty(&vpath->mac_addr_list))
2899 return;
2900
2901 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2902 list_del(entry);
2903 kfree((struct vxge_mac_addrs *)entry);
2904 }
2905}
2906
2907static void vxge_napi_del_all(struct vxgedev *vdev)
2908{
2909 int i;
2910 if (vdev->config.intr_type != MSI_X)
2911 netif_napi_del(&vdev->napi);
2912 else {
2913 for (i = 0; i < vdev->no_of_vpath; i++)
2914 netif_napi_del(&vdev->vpaths[i].ring.napi);
2915 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002916}
2917
stephen hemminger42821a52010-10-21 07:50:53 +00002918static int do_vxge_close(struct net_device *dev, int do_io)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002919{
2920 enum vxge_hw_status status;
2921 struct vxgedev *vdev;
2922 struct __vxge_hw_device *hldev;
2923 int i;
2924 u64 val64, vpath_vector;
2925 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2926 dev->name, __func__, __LINE__);
2927
Joe Perches5f54ceb2010-11-15 11:12:30 +00002928 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00002929 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002930
Sreenivasa Honnurbd9ee682009-07-01 21:14:03 +00002931 if (unlikely(!is_vxge_card_up(vdev)))
2932 return 0;
2933
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002934 /* If vxge_handle_crit_err task is executing,
2935 * wait till it completes. */
2936 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2937 msleep(50);
2938
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002939 if (do_io) {
2940 /* Put the vpath back in normal mode */
2941 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2942 status = vxge_hw_mgmt_reg_read(vdev->devh,
2943 vxge_hw_mgmt_reg_type_mrpcim,
2944 0,
2945 (ulong)offsetof(
2946 struct vxge_hw_mrpcim_reg,
2947 rts_mgr_cbasin_cfg),
2948 &val64);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002949 if (status == VXGE_HW_OK) {
2950 val64 &= ~vpath_vector;
2951 status = vxge_hw_mgmt_reg_write(vdev->devh,
2952 vxge_hw_mgmt_reg_type_mrpcim,
2953 0,
2954 (ulong)offsetof(
2955 struct vxge_hw_mrpcim_reg,
2956 rts_mgr_cbasin_cfg),
2957 val64);
2958 }
2959
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002960 /* Remove the function 0 from promiscuous mode */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002961 vxge_hw_mgmt_reg_write(vdev->devh,
2962 vxge_hw_mgmt_reg_type_mrpcim,
2963 0,
2964 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2965 rxmac_authorize_all_addr),
2966 0);
2967
2968 vxge_hw_mgmt_reg_write(vdev->devh,
2969 vxge_hw_mgmt_reg_type_mrpcim,
2970 0,
2971 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2972 rxmac_authorize_all_vid),
2973 0);
2974
2975 smp_wmb();
2976 }
Jon Masone7935c92010-11-11 04:26:00 +00002977
2978 if (vdev->titan1)
2979 del_timer_sync(&vdev->vp_lockup_timer);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002980
2981 del_timer_sync(&vdev->vp_reset_timer);
2982
Jon Mason4d2a5b42010-11-11 04:25:54 +00002983 if (do_io)
2984 vxge_hw_device_wait_receive_idle(hldev);
2985
2986 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2987
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002988 /* Disable napi */
2989 if (vdev->config.intr_type != MSI_X)
2990 napi_disable(&vdev->napi);
2991 else {
2992 for (i = 0; i < vdev->no_of_vpath; i++)
2993 napi_disable(&vdev->vpaths[i].ring.napi);
2994 }
2995
2996 netif_carrier_off(vdev->ndev);
Joe Perches75f5e1c2010-07-27 11:47:03 +00002997 netdev_notice(vdev->ndev, "Link Down\n");
Jon Masond03848e2010-07-15 08:47:23 +00002998 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002999
3000 /* Note that at this point xmit() is stopped by upper layer */
3001 if (do_io)
3002 vxge_hw_device_intr_disable(vdev->devh);
3003
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003004 vxge_rem_isr(vdev);
3005
3006 vxge_napi_del_all(vdev);
3007
3008 if (do_io)
3009 vxge_reset_all_vpaths(vdev);
3010
3011 vxge_close_vpaths(vdev, 0);
3012
3013 vxge_debug_entryexit(VXGE_TRACE,
3014 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
3015
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003016 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
3017
3018 return 0;
3019}
3020
3021/**
3022 * vxge_close
3023 * @dev: device pointer.
3024 *
3025 * This is the stop entry point of the driver. It needs to undo exactly
3026 * whatever was done by the open entry point, thus it's usually referred to
3027 * as the close function.Among other things this function mainly stops the
3028 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
3029 * Return value: '0' on success and an appropriate (-)ve integer as
3030 * defined in errno.h file on failure.
3031 */
Jon Mason528f7272010-12-10 14:02:56 +00003032static int vxge_close(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003033{
3034 do_vxge_close(dev, 1);
3035 return 0;
3036}
3037
3038/**
3039 * vxge_change_mtu
3040 * @dev: net device pointer.
3041 * @new_mtu :the new MTU size for the device.
3042 *
3043 * A driver entry point to change MTU size for the device. Before changing
3044 * the MTU the device must be stopped.
3045 */
3046static int vxge_change_mtu(struct net_device *dev, int new_mtu)
3047{
3048 struct vxgedev *vdev = netdev_priv(dev);
3049
3050 vxge_debug_entryexit(vdev->level_trace,
3051 "%s:%d", __func__, __LINE__);
3052 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
3053 vxge_debug_init(vdev->level_err,
3054 "%s: mtu size is invalid", dev->name);
3055 return -EPERM;
3056 }
3057
3058 /* check if device is down already */
3059 if (unlikely(!is_vxge_card_up(vdev))) {
3060 /* just store new value, will use later on open() */
3061 dev->mtu = new_mtu;
3062 vxge_debug_init(vdev->level_err,
3063 "%s", "device is down on MTU change");
3064 return 0;
3065 }
3066
3067 vxge_debug_init(vdev->level_trace,
3068 "trying to apply new MTU %d", new_mtu);
3069
3070 if (vxge_close(dev))
3071 return -EIO;
3072
3073 dev->mtu = new_mtu;
3074 vdev->mtu = new_mtu;
3075
3076 if (vxge_open(dev))
3077 return -EIO;
3078
3079 vxge_debug_init(vdev->level_trace,
3080 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
3081
3082 vxge_debug_entryexit(vdev->level_trace,
3083 "%s:%d Exiting...", __func__, __LINE__);
3084
3085 return 0;
3086}
3087
3088/**
Eric Dumazetdd57f972010-08-18 03:42:54 +00003089 * vxge_get_stats64
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003090 * @dev: pointer to the device structure
Eric Dumazetdd57f972010-08-18 03:42:54 +00003091 * @stats: pointer to struct rtnl_link_stats64
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003092 *
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003093 */
Eric Dumazetdd57f972010-08-18 03:42:54 +00003094static struct rtnl_link_stats64 *
3095vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003096{
Eric Dumazetdd57f972010-08-18 03:42:54 +00003097 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003098 int k;
3099
Eric Dumazetdd57f972010-08-18 03:42:54 +00003100 /* net_stats already zeroed by caller */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003101 for (k = 0; k < vdev->no_of_vpath; k++) {
3102 net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms;
3103 net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes;
3104 net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors;
3105 net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast;
Jon Mason528f7272010-12-10 14:02:56 +00003106 net_stats->rx_dropped += vdev->vpaths[k].ring.stats.rx_dropped;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003107 net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms;
3108 net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes;
3109 net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors;
3110 }
3111
3112 return net_stats;
3113}
3114
Jon Masoncd883a72011-04-08 11:11:21 +00003115static enum vxge_hw_status vxge_timestamp_config(struct __vxge_hw_device *devh)
Jon Masonb81b3732010-11-11 04:25:58 +00003116{
3117 enum vxge_hw_status status;
3118 u64 val64;
3119
3120 /* Timestamp is passed to the driver via the FCS, therefore we
3121 * must disable the FCS stripping by the adapter. Since this is
3122 * required for the driver to load (due to a hardware bug),
3123 * there is no need to do anything special here.
3124 */
Jon Masoncd883a72011-04-08 11:11:21 +00003125 val64 = VXGE_HW_XMAC_TIMESTAMP_EN |
3126 VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
3127 VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
Jon Masonb81b3732010-11-11 04:25:58 +00003128
Jon Masoncd883a72011-04-08 11:11:21 +00003129 status = vxge_hw_mgmt_reg_write(devh,
Jon Masonb81b3732010-11-11 04:25:58 +00003130 vxge_hw_mgmt_reg_type_mrpcim,
3131 0,
3132 offsetof(struct vxge_hw_mrpcim_reg,
3133 xmac_timestamp),
3134 val64);
Jon Masoncd883a72011-04-08 11:11:21 +00003135 vxge_hw_device_flush_io(devh);
3136 devh->config.hwts_en = VXGE_HW_HWTS_ENABLE;
Jon Masonb81b3732010-11-11 04:25:58 +00003137 return status;
3138}
3139
3140static int vxge_hwtstamp_ioctl(struct vxgedev *vdev, void __user *data)
3141{
3142 struct hwtstamp_config config;
Jon Masonb81b3732010-11-11 04:25:58 +00003143 int i;
3144
3145 if (copy_from_user(&config, data, sizeof(config)))
3146 return -EFAULT;
3147
3148 /* reserved for future extensions */
3149 if (config.flags)
3150 return -EINVAL;
3151
3152 /* Transmit HW Timestamp not supported */
3153 switch (config.tx_type) {
3154 case HWTSTAMP_TX_OFF:
3155 break;
3156 case HWTSTAMP_TX_ON:
3157 default:
3158 return -ERANGE;
3159 }
3160
3161 switch (config.rx_filter) {
3162 case HWTSTAMP_FILTER_NONE:
Jon Masonb81b3732010-11-11 04:25:58 +00003163 vdev->rx_hwts = 0;
3164 config.rx_filter = HWTSTAMP_FILTER_NONE;
3165 break;
3166
3167 case HWTSTAMP_FILTER_ALL:
3168 case HWTSTAMP_FILTER_SOME:
3169 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3170 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3171 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3172 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3173 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3174 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3175 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3176 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3177 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3178 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3179 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3180 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
Jon Masoncd883a72011-04-08 11:11:21 +00003181 if (vdev->devh->config.hwts_en != VXGE_HW_HWTS_ENABLE)
Jon Masonb81b3732010-11-11 04:25:58 +00003182 return -EFAULT;
3183
3184 vdev->rx_hwts = 1;
3185 config.rx_filter = HWTSTAMP_FILTER_ALL;
3186 break;
3187
3188 default:
3189 return -ERANGE;
3190 }
3191
3192 for (i = 0; i < vdev->no_of_vpath; i++)
3193 vdev->vpaths[i].ring.rx_hwts = vdev->rx_hwts;
3194
3195 if (copy_to_user(data, &config, sizeof(config)))
3196 return -EFAULT;
3197
3198 return 0;
3199}
3200
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003201/**
3202 * vxge_ioctl
3203 * @dev: Device pointer.
3204 * @ifr: An IOCTL specific structure, that can contain a pointer to
3205 * a proprietary structure used to pass information to the driver.
3206 * @cmd: This is used to distinguish between the different commands that
3207 * can be passed to the IOCTL functions.
3208 *
3209 * Entry point for the Ioctl.
3210 */
3211static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3212{
Jon Masonb81b3732010-11-11 04:25:58 +00003213 struct vxgedev *vdev = netdev_priv(dev);
3214 int ret;
3215
3216 switch (cmd) {
3217 case SIOCSHWTSTAMP:
3218 ret = vxge_hwtstamp_ioctl(vdev, rq->ifr_data);
3219 if (ret)
3220 return ret;
3221 break;
3222 default:
3223 return -EOPNOTSUPP;
3224 }
3225
3226 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003227}
3228
3229/**
3230 * vxge_tx_watchdog
3231 * @dev: pointer to net device structure
3232 *
3233 * Watchdog for transmit side.
3234 * This function is triggered if the Tx Queue is stopped
3235 * for a pre-defined amount of time when the Interface is still up.
3236 */
Jon Mason2e41f642010-12-10 14:02:59 +00003237static void vxge_tx_watchdog(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003238{
3239 struct vxgedev *vdev;
3240
3241 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3242
Joe Perches5f54ceb2010-11-15 11:12:30 +00003243 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003244
3245 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3246
Jon Mason2e41f642010-12-10 14:02:59 +00003247 schedule_work(&vdev->reset_task);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003248 vxge_debug_entryexit(VXGE_TRACE,
3249 "%s:%d Exiting...", __func__, __LINE__);
3250}
3251
3252/**
3253 * vxge_vlan_rx_register
3254 * @dev: net device pointer.
3255 * @grp: vlan group
3256 *
3257 * Vlan group registration
3258 */
3259static void
3260vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
3261{
3262 struct vxgedev *vdev;
3263 struct vxge_vpath *vpath;
3264 int vp;
3265 u64 vid;
3266 enum vxge_hw_status status;
3267 int i;
3268
3269 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3270
Joe Perches5f54ceb2010-11-15 11:12:30 +00003271 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003272
3273 vpath = &vdev->vpaths[0];
3274 if ((NULL == grp) && (vpath->is_open)) {
3275 /* Get the first vlan */
3276 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3277
3278 while (status == VXGE_HW_OK) {
3279
3280 /* Delete this vlan from the vid table */
3281 for (vp = 0; vp < vdev->no_of_vpath; vp++) {
3282 vpath = &vdev->vpaths[vp];
3283 if (!vpath->is_open)
3284 continue;
3285
3286 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3287 }
3288
3289 /* Get the next vlan to be deleted */
3290 vpath = &vdev->vpaths[0];
3291 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3292 }
3293 }
3294
3295 vdev->vlgrp = grp;
3296
3297 for (i = 0; i < vdev->no_of_vpath; i++) {
3298 if (vdev->vpaths[i].is_configured)
3299 vdev->vpaths[i].ring.vlgrp = grp;
3300 }
3301
3302 vxge_debug_entryexit(VXGE_TRACE,
3303 "%s:%d Exiting...", __func__, __LINE__);
3304}
3305
3306/**
3307 * vxge_vlan_rx_add_vid
3308 * @dev: net device pointer.
3309 * @vid: vid
3310 *
3311 * Add the vlan id to the devices vlan id table
3312 */
3313static void
3314vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3315{
3316 struct vxgedev *vdev;
3317 struct vxge_vpath *vpath;
3318 int vp_id;
3319
Joe Perches5f54ceb2010-11-15 11:12:30 +00003320 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003321
3322 /* Add these vlan to the vid table */
3323 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3324 vpath = &vdev->vpaths[vp_id];
3325 if (!vpath->is_open)
3326 continue;
3327 vxge_hw_vpath_vid_add(vpath->handle, vid);
3328 }
3329}
3330
3331/**
3332 * vxge_vlan_rx_add_vid
3333 * @dev: net device pointer.
3334 * @vid: vid
3335 *
3336 * Remove the vlan id from the device's vlan id table
3337 */
3338static void
3339vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3340{
3341 struct vxgedev *vdev;
3342 struct vxge_vpath *vpath;
3343 int vp_id;
3344
3345 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3346
Joe Perches5f54ceb2010-11-15 11:12:30 +00003347 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003348
3349 vlan_group_set_device(vdev->vlgrp, vid, NULL);
3350
3351 /* Delete this vlan from the vid table */
3352 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3353 vpath = &vdev->vpaths[vp_id];
3354 if (!vpath->is_open)
3355 continue;
3356 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3357 }
3358 vxge_debug_entryexit(VXGE_TRACE,
3359 "%s:%d Exiting...", __func__, __LINE__);
3360}
3361
3362static const struct net_device_ops vxge_netdev_ops = {
3363 .ndo_open = vxge_open,
3364 .ndo_stop = vxge_close,
Eric Dumazetdd57f972010-08-18 03:42:54 +00003365 .ndo_get_stats64 = vxge_get_stats64,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003366 .ndo_start_xmit = vxge_xmit,
3367 .ndo_validate_addr = eth_validate_addr,
3368 .ndo_set_multicast_list = vxge_set_multicast,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003369 .ndo_do_ioctl = vxge_ioctl,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003370 .ndo_set_mac_address = vxge_set_mac_addr,
3371 .ndo_change_mtu = vxge_change_mtu,
3372 .ndo_vlan_rx_register = vxge_vlan_rx_register,
3373 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3374 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003375 .ndo_tx_timeout = vxge_tx_watchdog,
3376#ifdef CONFIG_NET_POLL_CONTROLLER
3377 .ndo_poll_controller = vxge_netpoll,
3378#endif
3379};
3380
stephen hemminger42821a52010-10-21 07:50:53 +00003381static int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3382 struct vxge_config *config,
3383 int high_dma, int no_of_vpath,
3384 struct vxgedev **vdev_out)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003385{
3386 struct net_device *ndev;
3387 enum vxge_hw_status status = VXGE_HW_OK;
3388 struct vxgedev *vdev;
Jon Mason98f45da2010-07-15 08:47:25 +00003389 int ret = 0, no_of_queue = 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003390 u64 stat;
3391
3392 *vdev_out = NULL;
Jon Masond03848e2010-07-15 08:47:23 +00003393 if (config->tx_steering_type)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003394 no_of_queue = no_of_vpath;
3395
3396 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3397 no_of_queue);
3398 if (ndev == NULL) {
3399 vxge_debug_init(
3400 vxge_hw_device_trace_level_get(hldev),
3401 "%s : device allocation failed", __func__);
3402 ret = -ENODEV;
3403 goto _out0;
3404 }
3405
3406 vxge_debug_entryexit(
3407 vxge_hw_device_trace_level_get(hldev),
3408 "%s: %s:%d Entering...",
3409 ndev->name, __func__, __LINE__);
3410
3411 vdev = netdev_priv(ndev);
3412 memset(vdev, 0, sizeof(struct vxgedev));
3413
3414 vdev->ndev = ndev;
3415 vdev->devh = hldev;
3416 vdev->pdev = hldev->pdev;
3417 memcpy(&vdev->config, config, sizeof(struct vxge_config));
3418 vdev->rx_csum = 1; /* Enable Rx CSUM by default. */
Jon Masonb81b3732010-11-11 04:25:58 +00003419 vdev->rx_hwts = 0;
Sergei Shtylyovff938e42011-02-28 11:57:33 -08003420 vdev->titan1 = (vdev->pdev->revision == VXGE_HW_TITAN1_PCI_REVISION);
Jon Masone7935c92010-11-11 04:26:00 +00003421
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003422 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3423
3424 ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
3425 NETIF_F_HW_VLAN_FILTER;
3426 /* Driver entry points */
3427 ndev->irq = vdev->pdev->irq;
3428 ndev->base_addr = (unsigned long) hldev->bar0;
3429
3430 ndev->netdev_ops = &vxge_netdev_ops;
3431
3432 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
Jon Mason2e41f642010-12-10 14:02:59 +00003433 INIT_WORK(&vdev->reset_task, vxge_reset);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003434
stephen hemminger42821a52010-10-21 07:50:53 +00003435 vxge_initialize_ethtool_ops(ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003436
Jon Mason47f01db2010-11-11 04:25:53 +00003437 if (vdev->config.rth_steering != NO_STEERING) {
3438 ndev->features |= NETIF_F_RXHASH;
3439 hldev->config.rth_en = VXGE_HW_RTH_ENABLE;
3440 }
3441
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003442 /* Allocate memory for vpath */
3443 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3444 no_of_vpath, GFP_KERNEL);
3445 if (!vdev->vpaths) {
3446 vxge_debug_init(VXGE_ERR,
3447 "%s: vpath memory allocation failed",
3448 vdev->ndev->name);
Jon Mason6cca2002011-01-18 15:02:19 +00003449 ret = -ENOMEM;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003450 goto _out1;
3451 }
3452
3453 ndev->features |= NETIF_F_SG;
3454
Michał Mirosław79032642010-11-30 06:38:00 +00003455 ndev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003456 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3457 "%s : checksuming enabled", __func__);
3458
3459 if (high_dma) {
3460 ndev->features |= NETIF_F_HIGHDMA;
3461 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3462 "%s : using High DMA", __func__);
3463 }
3464
3465 ndev->features |= NETIF_F_TSO | NETIF_F_TSO6;
3466
3467 if (vdev->config.gro_enable)
3468 ndev->features |= NETIF_F_GRO;
3469
Jon Mason6cca2002011-01-18 15:02:19 +00003470 ret = register_netdev(ndev);
3471 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003472 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3473 "%s: %s : device registration failed!",
3474 ndev->name, __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003475 goto _out2;
3476 }
3477
3478 /* Set the factory defined MAC address initially */
3479 ndev->addr_len = ETH_ALEN;
3480
3481 /* Make Link state as off at this point, when the Link change
3482 * interrupt comes the state will be automatically changed to
3483 * the right state.
3484 */
3485 netif_carrier_off(ndev);
3486
3487 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3488 "%s: Ethernet device registered",
3489 ndev->name);
3490
Jon Masone8ac1752010-11-11 04:25:57 +00003491 hldev->ndev = ndev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003492 *vdev_out = vdev;
3493
3494 /* Resetting the Device stats */
3495 status = vxge_hw_mrpcim_stats_access(
3496 hldev,
3497 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3498 0,
3499 0,
3500 &stat);
3501
3502 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3503 vxge_debug_init(
3504 vxge_hw_device_trace_level_get(hldev),
3505 "%s: device stats clear returns"
3506 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3507
3508 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3509 "%s: %s:%d Exiting...",
3510 ndev->name, __func__, __LINE__);
3511
3512 return ret;
3513_out2:
3514 kfree(vdev->vpaths);
3515_out1:
3516 free_netdev(ndev);
3517_out0:
3518 return ret;
3519}
3520
3521/*
3522 * vxge_device_unregister
3523 *
3524 * This function will unregister and free network device
3525 */
Jon Mason2c913082010-11-11 04:26:03 +00003526static void vxge_device_unregister(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003527{
3528 struct vxgedev *vdev;
3529 struct net_device *dev;
3530 char buf[IFNAMSIZ];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003531
3532 dev = hldev->ndev;
3533 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003534
Jon Mason2c913082010-11-11 04:26:03 +00003535 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d", vdev->ndev->name,
3536 __func__, __LINE__);
3537
Jon Masonead5d232010-11-29 18:02:46 +00003538 strncpy(buf, dev->name, IFNAMSIZ);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003539
Tejun Heoba27d852010-12-15 04:03:29 +00003540 flush_work_sync(&vdev->reset_task);
3541
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003542 /* in 2.6 will call stop() if device is up */
3543 unregister_netdev(dev);
3544
Jon Mason6cca2002011-01-18 15:02:19 +00003545 kfree(vdev->vpaths);
3546
3547 /* we are safe to free it now */
3548 free_netdev(dev);
3549
Jon Mason2c913082010-11-11 04:26:03 +00003550 vxge_debug_init(vdev->level_trace, "%s: ethernet device unregistered",
3551 buf);
3552 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d Exiting...", buf,
3553 __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003554}
3555
3556/*
3557 * vxge_callback_crit_err
3558 *
3559 * This function is called by the alarm handler in interrupt context.
3560 * Driver must analyze it based on the event type.
3561 */
3562static void
3563vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3564 enum vxge_hw_event type, u64 vp_id)
3565{
3566 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +00003567 struct vxgedev *vdev = netdev_priv(dev);
Jon Mason98f45da2010-07-15 08:47:25 +00003568 struct vxge_vpath *vpath = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003569 int vpath_idx;
3570
3571 vxge_debug_entryexit(vdev->level_trace,
3572 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3573
3574 /* Note: This event type should be used for device wide
3575 * indications only - Serious errors, Slot freeze and critical errors
3576 */
3577 vdev->cric_err_event = type;
3578
Jon Mason98f45da2010-07-15 08:47:25 +00003579 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
3580 vpath = &vdev->vpaths[vpath_idx];
3581 if (vpath->device_id == vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003582 break;
Jon Mason98f45da2010-07-15 08:47:25 +00003583 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003584
3585 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3586 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3587 vxge_debug_init(VXGE_ERR,
3588 "%s: Slot is frozen", vdev->ndev->name);
3589 } else if (type == VXGE_HW_EVENT_SERR) {
3590 vxge_debug_init(VXGE_ERR,
3591 "%s: Encountered Serious Error",
3592 vdev->ndev->name);
3593 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3594 vxge_debug_init(VXGE_ERR,
3595 "%s: Encountered Critical Error",
3596 vdev->ndev->name);
3597 }
3598
3599 if ((type == VXGE_HW_EVENT_SERR) ||
3600 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3601 if (unlikely(vdev->exec_mode))
3602 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3603 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3604 vxge_hw_device_mask_all(hldev);
3605 if (unlikely(vdev->exec_mode))
3606 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3607 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3608 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3609
3610 if (unlikely(vdev->exec_mode))
3611 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3612 else {
3613 /* check if this vpath is already set for reset */
3614 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3615
3616 /* disable interrupts for this vpath */
3617 vxge_vpath_intr_disable(vdev, vpath_idx);
3618
3619 /* stop the queue for this vpath */
Jon Mason98f45da2010-07-15 08:47:25 +00003620 netif_tx_stop_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003621 }
3622 }
3623 }
3624
3625 vxge_debug_entryexit(vdev->level_trace,
3626 "%s: %s:%d Exiting...",
3627 vdev->ndev->name, __func__, __LINE__);
3628}
3629
3630static void verify_bandwidth(void)
3631{
3632 int i, band_width, total = 0, equal_priority = 0;
3633
3634 /* 1. If user enters 0 for some fifo, give equal priority to all */
3635 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3636 if (bw_percentage[i] == 0) {
3637 equal_priority = 1;
3638 break;
3639 }
3640 }
3641
3642 if (!equal_priority) {
3643 /* 2. If sum exceeds 100, give equal priority to all */
3644 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3645 if (bw_percentage[i] == 0xFF)
3646 break;
3647
3648 total += bw_percentage[i];
3649 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3650 equal_priority = 1;
3651 break;
3652 }
3653 }
3654 }
3655
3656 if (!equal_priority) {
3657 /* Is all the bandwidth consumed? */
3658 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3659 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3660 /* Split rest of bw equally among next VPs*/
3661 band_width =
3662 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3663 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3664 if (band_width < 2) /* min of 2% */
3665 equal_priority = 1;
3666 else {
3667 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3668 i++)
3669 bw_percentage[i] =
3670 band_width;
3671 }
3672 }
3673 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3674 equal_priority = 1;
3675 }
3676
3677 if (equal_priority) {
3678 vxge_debug_init(VXGE_ERR,
3679 "%s: Assigning equal bandwidth to all the vpaths",
3680 VXGE_DRIVER_NAME);
3681 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3682 VXGE_HW_MAX_VIRTUAL_PATHS;
3683 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3684 bw_percentage[i] = bw_percentage[0];
3685 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003686}
3687
3688/*
3689 * Vpath configuration
3690 */
3691static int __devinit vxge_config_vpaths(
3692 struct vxge_hw_device_config *device_config,
3693 u64 vpath_mask, struct vxge_config *config_param)
3694{
3695 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3696 u32 txdl_size, txdl_per_memblock;
3697
3698 temp = driver_config->vpath_per_dev;
3699 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3700 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3701 /* No more CPU. Return vpath number as zero.*/
3702 if (driver_config->g_no_cpus == -1)
3703 return 0;
3704
3705 if (!driver_config->g_no_cpus)
3706 driver_config->g_no_cpus = num_online_cpus();
3707
3708 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3709 if (!driver_config->vpath_per_dev)
3710 driver_config->vpath_per_dev = 1;
3711
3712 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3713 if (!vxge_bVALn(vpath_mask, i, 1))
3714 continue;
3715 else
3716 default_no_vpath++;
3717 if (default_no_vpath < driver_config->vpath_per_dev)
3718 driver_config->vpath_per_dev = default_no_vpath;
3719
3720 driver_config->g_no_cpus = driver_config->g_no_cpus -
3721 (driver_config->vpath_per_dev * 2);
3722 if (driver_config->g_no_cpus <= 0)
3723 driver_config->g_no_cpus = -1;
3724 }
3725
3726 if (driver_config->vpath_per_dev == 1) {
3727 vxge_debug_ll_config(VXGE_TRACE,
3728 "%s: Disable tx and rx steering, "
3729 "as single vpath is configured", VXGE_DRIVER_NAME);
3730 config_param->rth_steering = NO_STEERING;
3731 config_param->tx_steering_type = NO_STEERING;
3732 device_config->rth_en = 0;
3733 }
3734
3735 /* configure bandwidth */
3736 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3737 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3738
3739 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3740 device_config->vp_config[i].vp_id = i;
3741 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3742 if (no_of_vpaths < driver_config->vpath_per_dev) {
3743 if (!vxge_bVALn(vpath_mask, i, 1)) {
3744 vxge_debug_ll_config(VXGE_TRACE,
3745 "%s: vpath: %d is not available",
3746 VXGE_DRIVER_NAME, i);
3747 continue;
3748 } else {
3749 vxge_debug_ll_config(VXGE_TRACE,
3750 "%s: vpath: %d available",
3751 VXGE_DRIVER_NAME, i);
3752 no_of_vpaths++;
3753 }
3754 } else {
3755 vxge_debug_ll_config(VXGE_TRACE,
3756 "%s: vpath: %d is not configured, "
3757 "max_config_vpath exceeded",
3758 VXGE_DRIVER_NAME, i);
3759 break;
3760 }
3761
3762 /* Configure Tx fifo's */
3763 device_config->vp_config[i].fifo.enable =
3764 VXGE_HW_FIFO_ENABLE;
3765 device_config->vp_config[i].fifo.max_frags =
Sreenivasa Honnur5beefb42009-10-28 02:46:54 -07003766 MAX_SKB_FRAGS + 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003767 device_config->vp_config[i].fifo.memblock_size =
3768 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3769
Sreenivasa Honnur5beefb42009-10-28 02:46:54 -07003770 txdl_size = device_config->vp_config[i].fifo.max_frags *
3771 sizeof(struct vxge_hw_fifo_txd);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003772 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3773
3774 device_config->vp_config[i].fifo.fifo_blocks =
3775 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3776
3777 device_config->vp_config[i].fifo.intr =
3778 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3779
3780 /* Configure tti properties */
3781 device_config->vp_config[i].tti.intr_enable =
3782 VXGE_HW_TIM_INTR_ENABLE;
3783
3784 device_config->vp_config[i].tti.btimer_val =
3785 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3786
3787 device_config->vp_config[i].tti.timer_ac_en =
3788 VXGE_HW_TIM_TIMER_AC_ENABLE;
3789
Jon Mason528f7272010-12-10 14:02:56 +00003790 /* For msi-x with napi (each vector has a handler of its own) -
3791 * Set CI to OFF for all vpaths
3792 */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003793 device_config->vp_config[i].tti.timer_ci_en =
3794 VXGE_HW_TIM_TIMER_CI_DISABLE;
3795
3796 device_config->vp_config[i].tti.timer_ri_en =
3797 VXGE_HW_TIM_TIMER_RI_DISABLE;
3798
3799 device_config->vp_config[i].tti.util_sel =
3800 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3801
3802 device_config->vp_config[i].tti.ltimer_val =
3803 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3804
3805 device_config->vp_config[i].tti.rtimer_val =
3806 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3807
3808 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3809 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3810 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3811 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3812 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3813 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3814 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3815
3816 /* Configure Rx rings */
3817 device_config->vp_config[i].ring.enable =
3818 VXGE_HW_RING_ENABLE;
3819
3820 device_config->vp_config[i].ring.ring_blocks =
3821 VXGE_HW_DEF_RING_BLOCKS;
Jon Mason528f7272010-12-10 14:02:56 +00003822
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003823 device_config->vp_config[i].ring.buffer_mode =
3824 VXGE_HW_RING_RXD_BUFFER_MODE_1;
Jon Mason528f7272010-12-10 14:02:56 +00003825
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003826 device_config->vp_config[i].ring.rxds_limit =
3827 VXGE_HW_DEF_RING_RXDS_LIMIT;
Jon Mason528f7272010-12-10 14:02:56 +00003828
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003829 device_config->vp_config[i].ring.scatter_mode =
3830 VXGE_HW_RING_SCATTER_MODE_A;
3831
3832 /* Configure rti properties */
3833 device_config->vp_config[i].rti.intr_enable =
3834 VXGE_HW_TIM_INTR_ENABLE;
3835
3836 device_config->vp_config[i].rti.btimer_val =
3837 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3838
3839 device_config->vp_config[i].rti.timer_ac_en =
3840 VXGE_HW_TIM_TIMER_AC_ENABLE;
3841
3842 device_config->vp_config[i].rti.timer_ci_en =
3843 VXGE_HW_TIM_TIMER_CI_DISABLE;
3844
3845 device_config->vp_config[i].rti.timer_ri_en =
3846 VXGE_HW_TIM_TIMER_RI_DISABLE;
3847
3848 device_config->vp_config[i].rti.util_sel =
3849 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3850
3851 device_config->vp_config[i].rti.urange_a =
3852 RTI_RX_URANGE_A;
3853 device_config->vp_config[i].rti.urange_b =
3854 RTI_RX_URANGE_B;
3855 device_config->vp_config[i].rti.urange_c =
3856 RTI_RX_URANGE_C;
3857 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3858 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3859 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3860 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3861
3862 device_config->vp_config[i].rti.rtimer_val =
3863 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3864
3865 device_config->vp_config[i].rti.ltimer_val =
3866 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3867
3868 device_config->vp_config[i].rpa_strip_vlan_tag =
3869 vlan_tag_strip;
3870 }
3871
3872 driver_config->vpath_per_dev = temp;
3873 return no_of_vpaths;
3874}
3875
3876/* initialize device configuratrions */
3877static void __devinit vxge_device_config_init(
3878 struct vxge_hw_device_config *device_config,
3879 int *intr_type)
3880{
3881 /* Used for CQRQ/SRQ. */
3882 device_config->dma_blockpool_initial =
3883 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3884
3885 device_config->dma_blockpool_max =
3886 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3887
3888 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3889 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3890
3891#ifndef CONFIG_PCI_MSI
3892 vxge_debug_init(VXGE_ERR,
3893 "%s: This Kernel does not support "
3894 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3895 *intr_type = INTA;
3896#endif
3897
3898 /* Configure whether MSI-X or IRQL. */
3899 switch (*intr_type) {
3900 case INTA:
3901 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3902 break;
3903
3904 case MSI_X:
Jon Mason16fded72011-01-18 15:02:21 +00003905 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX_ONE_SHOT;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003906 break;
3907 }
Jon Mason528f7272010-12-10 14:02:56 +00003908
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003909 /* Timer period between device poll */
3910 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3911
3912 /* Configure mac based steering. */
3913 device_config->rts_mac_en = addr_learn_en;
3914
3915 /* Configure Vpaths */
3916 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3917
3918 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3919 __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003920 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3921 device_config->intr_mode);
3922 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3923 device_config->device_poll_millis);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003924 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3925 device_config->rth_en);
3926 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3927 device_config->rth_it_type);
3928}
3929
3930static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3931{
3932 int i;
3933
3934 vxge_debug_init(VXGE_TRACE,
3935 "%s: %d Vpath(s) opened",
3936 vdev->ndev->name, vdev->no_of_vpath);
3937
3938 switch (vdev->config.intr_type) {
3939 case INTA:
3940 vxge_debug_init(VXGE_TRACE,
3941 "%s: Interrupt type INTA", vdev->ndev->name);
3942 break;
3943
3944 case MSI_X:
3945 vxge_debug_init(VXGE_TRACE,
3946 "%s: Interrupt type MSI-X", vdev->ndev->name);
3947 break;
3948 }
3949
3950 if (vdev->config.rth_steering) {
3951 vxge_debug_init(VXGE_TRACE,
3952 "%s: RTH steering enabled for TCP_IPV4",
3953 vdev->ndev->name);
3954 } else {
3955 vxge_debug_init(VXGE_TRACE,
3956 "%s: RTH steering disabled", vdev->ndev->name);
3957 }
3958
3959 switch (vdev->config.tx_steering_type) {
3960 case NO_STEERING:
3961 vxge_debug_init(VXGE_TRACE,
3962 "%s: Tx steering disabled", vdev->ndev->name);
3963 break;
3964 case TX_PRIORITY_STEERING:
3965 vxge_debug_init(VXGE_TRACE,
3966 "%s: Unsupported tx steering option",
3967 vdev->ndev->name);
3968 vxge_debug_init(VXGE_TRACE,
3969 "%s: Tx steering disabled", vdev->ndev->name);
3970 vdev->config.tx_steering_type = 0;
3971 break;
3972 case TX_VLAN_STEERING:
3973 vxge_debug_init(VXGE_TRACE,
3974 "%s: Unsupported tx steering option",
3975 vdev->ndev->name);
3976 vxge_debug_init(VXGE_TRACE,
3977 "%s: Tx steering disabled", vdev->ndev->name);
3978 vdev->config.tx_steering_type = 0;
3979 break;
3980 case TX_MULTIQ_STEERING:
3981 vxge_debug_init(VXGE_TRACE,
3982 "%s: Tx multiqueue steering enabled",
3983 vdev->ndev->name);
3984 break;
3985 case TX_PORT_STEERING:
3986 vxge_debug_init(VXGE_TRACE,
3987 "%s: Tx port steering enabled",
3988 vdev->ndev->name);
3989 break;
3990 default:
3991 vxge_debug_init(VXGE_ERR,
3992 "%s: Unsupported tx steering type",
3993 vdev->ndev->name);
3994 vxge_debug_init(VXGE_TRACE,
3995 "%s: Tx steering disabled", vdev->ndev->name);
3996 vdev->config.tx_steering_type = 0;
3997 }
3998
3999 if (vdev->config.gro_enable) {
4000 vxge_debug_init(VXGE_ERR,
4001 "%s: Generic receive offload enabled",
4002 vdev->ndev->name);
4003 } else
4004 vxge_debug_init(VXGE_TRACE,
4005 "%s: Generic receive offload disabled",
4006 vdev->ndev->name);
4007
4008 if (vdev->config.addr_learn_en)
4009 vxge_debug_init(VXGE_TRACE,
4010 "%s: MAC Address learning enabled", vdev->ndev->name);
4011
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004012 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4013 if (!vxge_bVALn(vpath_mask, i, 1))
4014 continue;
4015 vxge_debug_ll_config(VXGE_TRACE,
4016 "%s: MTU size - %d", vdev->ndev->name,
4017 ((struct __vxge_hw_device *)(vdev->devh))->
4018 config.vp_config[i].mtu);
4019 vxge_debug_init(VXGE_TRACE,
4020 "%s: VLAN tag stripping %s", vdev->ndev->name,
4021 ((struct __vxge_hw_device *)(vdev->devh))->
4022 config.vp_config[i].rpa_strip_vlan_tag
4023 ? "Enabled" : "Disabled");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004024 vxge_debug_ll_config(VXGE_TRACE,
4025 "%s: Max frags : %d", vdev->ndev->name,
4026 ((struct __vxge_hw_device *)(vdev->devh))->
4027 config.vp_config[i].fifo.max_frags);
4028 break;
4029 }
4030}
4031
4032#ifdef CONFIG_PM
4033/**
4034 * vxge_pm_suspend - vxge power management suspend entry point
4035 *
4036 */
4037static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
4038{
4039 return -ENOSYS;
4040}
4041/**
4042 * vxge_pm_resume - vxge power management resume entry point
4043 *
4044 */
4045static int vxge_pm_resume(struct pci_dev *pdev)
4046{
4047 return -ENOSYS;
4048}
4049
4050#endif
4051
4052/**
4053 * vxge_io_error_detected - called when PCI error is detected
4054 * @pdev: Pointer to PCI device
4055 * @state: The current pci connection state
4056 *
4057 * This function is called after a PCI bus error affecting
4058 * this device has been detected.
4059 */
4060static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
4061 pci_channel_state_t state)
4062{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004063 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004064 struct net_device *netdev = hldev->ndev;
4065
4066 netif_device_detach(netdev);
4067
Dean Nelsone33b9922009-07-31 09:14:03 +00004068 if (state == pci_channel_io_perm_failure)
4069 return PCI_ERS_RESULT_DISCONNECT;
4070
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004071 if (netif_running(netdev)) {
4072 /* Bring down the card, while avoiding PCI I/O */
4073 do_vxge_close(netdev, 0);
4074 }
4075
4076 pci_disable_device(pdev);
4077
4078 return PCI_ERS_RESULT_NEED_RESET;
4079}
4080
4081/**
4082 * vxge_io_slot_reset - called after the pci bus has been reset.
4083 * @pdev: Pointer to PCI device
4084 *
4085 * Restart the card from scratch, as if from a cold-boot.
4086 * At this point, the card has exprienced a hard reset,
4087 * followed by fixups by BIOS, and has its config space
4088 * set up identically to what it was at cold boot.
4089 */
4090static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
4091{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004092 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004093 struct net_device *netdev = hldev->ndev;
4094
4095 struct vxgedev *vdev = netdev_priv(netdev);
4096
4097 if (pci_enable_device(pdev)) {
Joe Perches75f5e1c2010-07-27 11:47:03 +00004098 netdev_err(netdev, "Cannot re-enable device after reset\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004099 return PCI_ERS_RESULT_DISCONNECT;
4100 }
4101
4102 pci_set_master(pdev);
Jon Mason528f7272010-12-10 14:02:56 +00004103 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004104
4105 return PCI_ERS_RESULT_RECOVERED;
4106}
4107
4108/**
4109 * vxge_io_resume - called when traffic can start flowing again.
4110 * @pdev: Pointer to PCI device
4111 *
4112 * This callback is called when the error recovery driver tells
4113 * us that its OK to resume normal operation.
4114 */
4115static void vxge_io_resume(struct pci_dev *pdev)
4116{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004117 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004118 struct net_device *netdev = hldev->ndev;
4119
4120 if (netif_running(netdev)) {
4121 if (vxge_open(netdev)) {
Joe Perches75f5e1c2010-07-27 11:47:03 +00004122 netdev_err(netdev,
4123 "Can't bring device back up after reset\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004124 return;
4125 }
4126 }
4127
4128 netif_device_attach(netdev);
4129}
4130
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004131static inline u32 vxge_get_num_vfs(u64 function_mode)
4132{
4133 u32 num_functions = 0;
4134
4135 switch (function_mode) {
4136 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4137 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
4138 num_functions = 8;
4139 break;
4140 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4141 num_functions = 1;
4142 break;
4143 case VXGE_HW_FUNCTION_MODE_SRIOV:
4144 case VXGE_HW_FUNCTION_MODE_MRIOV:
4145 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
4146 num_functions = 17;
4147 break;
4148 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
4149 num_functions = 4;
4150 break;
4151 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
4152 num_functions = 2;
4153 break;
4154 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
4155 num_functions = 8; /* TODO */
4156 break;
4157 }
4158 return num_functions;
4159}
4160
Jon Masone8ac1752010-11-11 04:25:57 +00004161int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override)
4162{
4163 struct __vxge_hw_device *hldev = vdev->devh;
4164 u32 maj, min, bld, cmaj, cmin, cbld;
4165 enum vxge_hw_status status;
4166 const struct firmware *fw;
4167 int ret;
4168
4169 ret = request_firmware(&fw, fw_name, &vdev->pdev->dev);
4170 if (ret) {
4171 vxge_debug_init(VXGE_ERR, "%s: Firmware file '%s' not found",
4172 VXGE_DRIVER_NAME, fw_name);
4173 goto out;
4174 }
4175
4176 /* Load the new firmware onto the adapter */
4177 status = vxge_update_fw_image(hldev, fw->data, fw->size);
4178 if (status != VXGE_HW_OK) {
4179 vxge_debug_init(VXGE_ERR,
4180 "%s: FW image download to adapter failed '%s'.",
4181 VXGE_DRIVER_NAME, fw_name);
4182 ret = -EIO;
4183 goto out;
4184 }
4185
4186 /* Read the version of the new firmware */
4187 status = vxge_hw_upgrade_read_version(hldev, &maj, &min, &bld);
4188 if (status != VXGE_HW_OK) {
4189 vxge_debug_init(VXGE_ERR,
4190 "%s: Upgrade read version failed '%s'.",
4191 VXGE_DRIVER_NAME, fw_name);
4192 ret = -EIO;
4193 goto out;
4194 }
4195
4196 cmaj = vdev->config.device_hw_info.fw_version.major;
4197 cmin = vdev->config.device_hw_info.fw_version.minor;
4198 cbld = vdev->config.device_hw_info.fw_version.build;
4199 /* It's possible the version in /lib/firmware is not the latest version.
4200 * If so, we could get into a loop of trying to upgrade to the latest
4201 * and flashing the older version.
4202 */
4203 if (VXGE_FW_VER(maj, min, bld) == VXGE_FW_VER(cmaj, cmin, cbld) &&
4204 !override) {
4205 ret = -EINVAL;
4206 goto out;
4207 }
4208
4209 printk(KERN_NOTICE "Upgrade to firmware version %d.%d.%d commencing\n",
4210 maj, min, bld);
4211
4212 /* Flash the adapter with the new firmware */
4213 status = vxge_hw_flash_fw(hldev);
4214 if (status != VXGE_HW_OK) {
4215 vxge_debug_init(VXGE_ERR, "%s: Upgrade commit failed '%s'.",
4216 VXGE_DRIVER_NAME, fw_name);
4217 ret = -EIO;
4218 goto out;
4219 }
4220
4221 printk(KERN_NOTICE "Upgrade of firmware successful! Adapter must be "
4222 "hard reset before using, thus requiring a system reboot or a "
4223 "hotplug event.\n");
4224
4225out:
Jesper Juhle84f8852011-01-13 10:25:20 +00004226 release_firmware(fw);
Jon Masone8ac1752010-11-11 04:25:57 +00004227 return ret;
4228}
4229
4230static int vxge_probe_fw_update(struct vxgedev *vdev)
4231{
4232 u32 maj, min, bld;
4233 int ret, gpxe = 0;
4234 char *fw_name;
4235
4236 maj = vdev->config.device_hw_info.fw_version.major;
4237 min = vdev->config.device_hw_info.fw_version.minor;
4238 bld = vdev->config.device_hw_info.fw_version.build;
4239
4240 if (VXGE_FW_VER(maj, min, bld) == VXGE_CERT_FW_VER)
4241 return 0;
4242
4243 /* Ignore the build number when determining if the current firmware is
4244 * "too new" to load the driver
4245 */
4246 if (VXGE_FW_VER(maj, min, 0) > VXGE_CERT_FW_VER) {
4247 vxge_debug_init(VXGE_ERR, "%s: Firmware newer than last known "
4248 "version, unable to load driver\n",
4249 VXGE_DRIVER_NAME);
4250 return -EINVAL;
4251 }
4252
4253 /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
4254 * work with this driver.
4255 */
4256 if (VXGE_FW_VER(maj, min, bld) <= VXGE_FW_DEAD_VER) {
4257 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d cannot be "
4258 "upgraded\n", VXGE_DRIVER_NAME, maj, min, bld);
4259 return -EINVAL;
4260 }
4261
4262 /* If file not specified, determine gPXE or not */
4263 if (VXGE_FW_VER(maj, min, bld) >= VXGE_EPROM_FW_VER) {
4264 int i;
4265 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++)
4266 if (vdev->devh->eprom_versions[i]) {
4267 gpxe = 1;
4268 break;
4269 }
4270 }
4271 if (gpxe)
4272 fw_name = "vxge/X3fw-pxe.ncf";
4273 else
4274 fw_name = "vxge/X3fw.ncf";
4275
4276 ret = vxge_fw_upgrade(vdev, fw_name, 0);
4277 /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
4278 * probe, so ignore them
4279 */
4280 if (ret != -EINVAL && ret != -ENOENT)
4281 return -EIO;
4282 else
4283 ret = 0;
4284
4285 if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR, VXGE_CERT_FW_VER_MINOR, 0) >
4286 VXGE_FW_VER(maj, min, 0)) {
4287 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d is too old to"
4288 " be used with this driver.\n"
4289 "Please get the latest version from "
4290 "ftp://ftp.s2io.com/pub/X3100-Drivers/FIRMWARE",
4291 VXGE_DRIVER_NAME, maj, min, bld);
4292 return -EINVAL;
4293 }
4294
4295 return ret;
4296}
4297
Jon Masonc92bf702010-12-10 14:02:57 +00004298static int __devinit is_sriov_initialized(struct pci_dev *pdev)
4299{
4300 int pos;
4301 u16 ctrl;
4302
4303 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4304 if (pos) {
4305 pci_read_config_word(pdev, pos + PCI_SRIOV_CTRL, &ctrl);
4306 if (ctrl & PCI_SRIOV_CTRL_VFE)
4307 return 1;
4308 }
4309 return 0;
4310}
4311
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004312/**
4313 * vxge_probe
4314 * @pdev : structure containing the PCI related information of the device.
4315 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4316 * Description:
4317 * This function is called when a new PCI device gets detected and initializes
4318 * it.
4319 * Return value:
4320 * returns 0 on success and negative on failure.
4321 *
4322 */
4323static int __devinit
4324vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4325{
Jon Mason2c913082010-11-11 04:26:03 +00004326 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004327 enum vxge_hw_status status;
4328 int ret;
4329 int high_dma = 0;
4330 u64 vpath_mask = 0;
4331 struct vxgedev *vdev;
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004332 struct vxge_config *ll_config = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004333 struct vxge_hw_device_config *device_config = NULL;
4334 struct vxge_hw_device_attr attr;
4335 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4336 u8 *macaddr;
4337 struct vxge_mac_addrs *entry;
4338 static int bus = -1, device = -1;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004339 u32 host_type;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004340 u8 new_device = 0;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004341 enum vxge_hw_status is_privileged;
4342 u32 function_mode;
4343 u32 num_vfs = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004344
4345 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4346 attr.pdev = pdev;
4347
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004348 /* In SRIOV-17 mode, functions of the same adapter
Jon Mason528f7272010-12-10 14:02:56 +00004349 * can be deployed on different buses
4350 */
4351 if (((bus != pdev->bus->number) || (device != PCI_SLOT(pdev->devfn))) &&
4352 !pdev->is_virtfn)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004353 new_device = 1;
4354
4355 bus = pdev->bus->number;
4356 device = PCI_SLOT(pdev->devfn);
4357
4358 if (new_device) {
4359 if (driver_config->config_dev_cnt &&
4360 (driver_config->config_dev_cnt !=
4361 driver_config->total_dev_cnt))
4362 vxge_debug_init(VXGE_ERR,
4363 "%s: Configured %d of %d devices",
4364 VXGE_DRIVER_NAME,
4365 driver_config->config_dev_cnt,
4366 driver_config->total_dev_cnt);
4367 driver_config->config_dev_cnt = 0;
4368 driver_config->total_dev_cnt = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004369 }
Jon Mason528f7272010-12-10 14:02:56 +00004370
Sreenivasa Honnur90023972010-04-08 01:48:30 -07004371 /* Now making the CPU based no of vpath calculation
4372 * applicable for individual functions as well.
4373 */
4374 driver_config->g_no_cpus = 0;
Sreenivasa Honnur657205b2009-10-05 01:52:54 +00004375 driver_config->vpath_per_dev = max_config_vpath;
4376
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004377 driver_config->total_dev_cnt++;
4378 if (++driver_config->config_dev_cnt > max_config_dev) {
4379 ret = 0;
4380 goto _exit0;
4381 }
4382
4383 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4384 GFP_KERNEL);
4385 if (!device_config) {
4386 ret = -ENOMEM;
4387 vxge_debug_init(VXGE_ERR,
4388 "device_config : malloc failed %s %d",
4389 __FILE__, __LINE__);
4390 goto _exit0;
4391 }
4392
Jon Mason528f7272010-12-10 14:02:56 +00004393 ll_config = kzalloc(sizeof(struct vxge_config), GFP_KERNEL);
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004394 if (!ll_config) {
4395 ret = -ENOMEM;
4396 vxge_debug_init(VXGE_ERR,
Jon Mason528f7272010-12-10 14:02:56 +00004397 "device_config : malloc failed %s %d",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004398 __FILE__, __LINE__);
4399 goto _exit0;
4400 }
4401 ll_config->tx_steering_type = TX_MULTIQ_STEERING;
4402 ll_config->intr_type = MSI_X;
4403 ll_config->napi_weight = NEW_NAPI_WEIGHT;
4404 ll_config->rth_steering = RTH_STEERING;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004405
4406 /* get the default configuration parameters */
4407 vxge_hw_device_config_default_get(device_config);
4408
4409 /* initialize configuration parameters */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004410 vxge_device_config_init(device_config, &ll_config->intr_type);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004411
4412 ret = pci_enable_device(pdev);
4413 if (ret) {
4414 vxge_debug_init(VXGE_ERR,
4415 "%s : can not enable PCI device", __func__);
4416 goto _exit0;
4417 }
4418
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004419 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004420 vxge_debug_ll_config(VXGE_TRACE,
4421 "%s : using 64bit DMA", __func__);
4422
4423 high_dma = 1;
4424
4425 if (pci_set_consistent_dma_mask(pdev,
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004426 DMA_BIT_MASK(64))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004427 vxge_debug_init(VXGE_ERR,
4428 "%s : unable to obtain 64bit DMA for "
4429 "consistent allocations", __func__);
4430 ret = -ENOMEM;
4431 goto _exit1;
4432 }
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004433 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004434 vxge_debug_ll_config(VXGE_TRACE,
4435 "%s : using 32bit DMA", __func__);
4436 } else {
4437 ret = -ENOMEM;
4438 goto _exit1;
4439 }
4440
Jon Mason6cca2002011-01-18 15:02:19 +00004441 ret = pci_request_region(pdev, 0, VXGE_DRIVER_NAME);
4442 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004443 vxge_debug_init(VXGE_ERR,
4444 "%s : request regions failed", __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004445 goto _exit1;
4446 }
4447
4448 pci_set_master(pdev);
4449
4450 attr.bar0 = pci_ioremap_bar(pdev, 0);
4451 if (!attr.bar0) {
4452 vxge_debug_init(VXGE_ERR,
4453 "%s : cannot remap io memory bar0", __func__);
4454 ret = -ENODEV;
4455 goto _exit2;
4456 }
4457 vxge_debug_ll_config(VXGE_TRACE,
4458 "pci ioremap bar0: %p:0x%llx",
4459 attr.bar0,
4460 (unsigned long long)pci_resource_start(pdev, 0));
4461
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004462 status = vxge_hw_device_hw_info_get(attr.bar0,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004463 &ll_config->device_hw_info);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004464 if (status != VXGE_HW_OK) {
4465 vxge_debug_init(VXGE_ERR,
4466 "%s: Reading of hardware info failed."
4467 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4468 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004469 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004470 }
4471
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004472 vpath_mask = ll_config->device_hw_info.vpath_mask;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004473 if (vpath_mask == 0) {
4474 vxge_debug_ll_config(VXGE_TRACE,
4475 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4476 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004477 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004478 }
4479
4480 vxge_debug_ll_config(VXGE_TRACE,
4481 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4482 (unsigned long long)vpath_mask);
4483
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004484 function_mode = ll_config->device_hw_info.function_mode;
4485 host_type = ll_config->device_hw_info.host_type;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004486 is_privileged = __vxge_hw_device_is_privilaged(host_type,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004487 ll_config->device_hw_info.func_id);
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004488
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004489 /* Check how many vpaths are available */
4490 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4491 if (!((vpath_mask) & vxge_mBIT(i)))
4492 continue;
4493 max_vpath_supported++;
4494 }
4495
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004496 if (new_device)
4497 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4498
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004499 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
Jon Masonc92bf702010-12-10 14:02:57 +00004500 if (is_sriov(function_mode) && !is_sriov_initialized(pdev) &&
4501 (ll_config->intr_type != INTA)) {
4502 ret = pci_enable_sriov(pdev, num_vfs);
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004503 if (ret)
4504 vxge_debug_ll_config(VXGE_ERR,
4505 "Failed in enabling SRIOV mode: %d\n", ret);
Jon Masonc92bf702010-12-10 14:02:57 +00004506 /* No need to fail out, as an error here is non-fatal */
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004507 }
4508
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004509 /*
4510 * Configure vpaths and get driver configured number of vpaths
4511 * which is less than or equal to the maximum vpaths per function.
4512 */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004513 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004514 if (!no_of_vpath) {
4515 vxge_debug_ll_config(VXGE_ERR,
4516 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4517 ret = 0;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004518 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004519 }
4520
4521 /* Setting driver callbacks */
4522 attr.uld_callbacks.link_up = vxge_callback_link_up;
4523 attr.uld_callbacks.link_down = vxge_callback_link_down;
4524 attr.uld_callbacks.crit_err = vxge_callback_crit_err;
4525
4526 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4527 if (status != VXGE_HW_OK) {
4528 vxge_debug_init(VXGE_ERR,
4529 "Failed to initialize device (%d)", status);
4530 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004531 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004532 }
4533
Jon Masone8ac1752010-11-11 04:25:57 +00004534 if (VXGE_FW_VER(ll_config->device_hw_info.fw_version.major,
4535 ll_config->device_hw_info.fw_version.minor,
4536 ll_config->device_hw_info.fw_version.build) >=
4537 VXGE_EPROM_FW_VER) {
4538 struct eprom_image img[VXGE_HW_MAX_ROM_IMAGES];
4539
4540 status = vxge_hw_vpath_eprom_img_ver_get(hldev, img);
4541 if (status != VXGE_HW_OK) {
4542 vxge_debug_init(VXGE_ERR, "%s: Reading of EPROM failed",
4543 VXGE_DRIVER_NAME);
4544 /* This is a non-fatal error, continue */
4545 }
4546
4547 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
4548 hldev->eprom_versions[i] = img[i].version;
4549 if (!img[i].is_valid)
4550 break;
4551 vxge_debug_init(VXGE_TRACE, "%s: EPROM %d, version "
Jon Mason1d15f812011-01-18 15:02:20 +00004552 "%d.%d.%d.%d", VXGE_DRIVER_NAME, i,
Jon Masone8ac1752010-11-11 04:25:57 +00004553 VXGE_EPROM_IMG_MAJOR(img[i].version),
4554 VXGE_EPROM_IMG_MINOR(img[i].version),
4555 VXGE_EPROM_IMG_FIX(img[i].version),
4556 VXGE_EPROM_IMG_BUILD(img[i].version));
4557 }
4558 }
4559
Sreenivasa Honnurfa41fd12009-10-05 01:56:35 +00004560 /* if FCS stripping is not disabled in MAC fail driver load */
Jon Masonb81b3732010-11-11 04:25:58 +00004561 status = vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask);
4562 if (status != VXGE_HW_OK) {
4563 vxge_debug_init(VXGE_ERR, "%s: FCS stripping is enabled in MAC"
4564 " failing driver load", VXGE_DRIVER_NAME);
Sreenivasa Honnurfa41fd12009-10-05 01:56:35 +00004565 ret = -EINVAL;
4566 goto _exit4;
4567 }
4568
Jon Masoncd883a72011-04-08 11:11:21 +00004569 /* Always enable HWTS. This will always cause the FCS to be invalid,
4570 * due to the fact that HWTS is using the FCS as the location of the
4571 * timestamp. The HW FCS checking will still correctly determine if
4572 * there is a valid checksum, and the FCS is being removed by the driver
4573 * anyway. So no fucntionality is being lost. Since it is always
4574 * enabled, we now simply use the ioctl call to set whether or not the
4575 * driver should be paying attention to the HWTS.
4576 */
4577 if (is_privileged == VXGE_HW_OK) {
4578 status = vxge_timestamp_config(hldev);
4579 if (status != VXGE_HW_OK) {
4580 vxge_debug_init(VXGE_ERR, "%s: HWTS enable failed",
4581 VXGE_DRIVER_NAME);
4582 ret = -EFAULT;
4583 goto _exit4;
4584 }
4585 }
4586
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004587 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4588
4589 /* set private device info */
4590 pci_set_drvdata(pdev, hldev);
4591
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004592 ll_config->gro_enable = VXGE_GRO_ALWAYS_AGGREGATE;
4593 ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4594 ll_config->addr_learn_en = addr_learn_en;
4595 ll_config->rth_algorithm = RTH_ALG_JENKINS;
Jon Mason47f01db2010-11-11 04:25:53 +00004596 ll_config->rth_hash_type_tcpipv4 = 1;
4597 ll_config->rth_hash_type_ipv4 = 0;
4598 ll_config->rth_hash_type_tcpipv6 = 0;
4599 ll_config->rth_hash_type_ipv6 = 0;
4600 ll_config->rth_hash_type_tcpipv6ex = 0;
4601 ll_config->rth_hash_type_ipv6ex = 0;
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004602 ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
4603 ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4604 ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004605
Jon Masone8ac1752010-11-11 04:25:57 +00004606 ret = vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
4607 &vdev);
4608 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004609 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004610 goto _exit4;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004611 }
4612
Jon Masone8ac1752010-11-11 04:25:57 +00004613 ret = vxge_probe_fw_update(vdev);
4614 if (ret)
4615 goto _exit5;
4616
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004617 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4618 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4619 vxge_hw_device_trace_level_get(hldev));
4620
4621 /* set private HW device info */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004622 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4623 vdev->bar0 = attr.bar0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004624 vdev->max_vpath_supported = max_vpath_supported;
4625 vdev->no_of_vpath = no_of_vpath;
4626
4627 /* Virtual Path count */
4628 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4629 if (!vxge_bVALn(vpath_mask, i, 1))
4630 continue;
4631 if (j >= vdev->no_of_vpath)
4632 break;
4633
4634 vdev->vpaths[j].is_configured = 1;
4635 vdev->vpaths[j].device_id = i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004636 vdev->vpaths[j].ring.driver_id = j;
4637 vdev->vpaths[j].vdev = vdev;
4638 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4639 memcpy((u8 *)vdev->vpaths[j].macaddr,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004640 ll_config->device_hw_info.mac_addrs[i],
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004641 ETH_ALEN);
4642
4643 /* Initialize the mac address list header */
4644 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4645
4646 vdev->vpaths[j].mac_addr_cnt = 0;
4647 vdev->vpaths[j].mcast_addr_cnt = 0;
4648 j++;
4649 }
4650 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4651 vdev->max_config_port = max_config_port;
4652
4653 vdev->vlan_tag_strip = vlan_tag_strip;
4654
4655 /* map the hashing selector table to the configured vpaths */
4656 for (i = 0; i < vdev->no_of_vpath; i++)
4657 vdev->vpath_selector[i] = vpath_selector[i];
4658
4659 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4660
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004661 ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4662 ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4663 ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004664
4665 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004666 vdev->ndev->name, ll_config->device_hw_info.serial_number);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004667
4668 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004669 vdev->ndev->name, ll_config->device_hw_info.part_number);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004670
4671 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004672 vdev->ndev->name, ll_config->device_hw_info.product_desc);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004673
hartleysbf54e732010-01-05 06:59:23 +00004674 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4675 vdev->ndev->name, macaddr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004676
4677 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4678 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4679
4680 vxge_debug_init(VXGE_TRACE,
4681 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004682 ll_config->device_hw_info.fw_version.version,
4683 ll_config->device_hw_info.fw_date.date);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004684
Sreenivasa Honnur0a25bdc2009-07-01 21:18:06 +00004685 if (new_device) {
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004686 switch (ll_config->device_hw_info.function_mode) {
Sreenivasa Honnur0a25bdc2009-07-01 21:18:06 +00004687 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4688 vxge_debug_init(VXGE_TRACE,
4689 "%s: Single Function Mode Enabled", vdev->ndev->name);
4690 break;
4691 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4692 vxge_debug_init(VXGE_TRACE,
4693 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4694 break;
4695 case VXGE_HW_FUNCTION_MODE_SRIOV:
4696 vxge_debug_init(VXGE_TRACE,
4697 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4698 break;
4699 case VXGE_HW_FUNCTION_MODE_MRIOV:
4700 vxge_debug_init(VXGE_TRACE,
4701 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4702 break;
4703 }
4704 }
4705
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004706 vxge_print_parm(vdev, vpath_mask);
4707
4708 /* Store the fw version for ethttool option */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004709 strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004710 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4711 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4712
4713 /* Copy the station mac address to the list */
4714 for (i = 0; i < vdev->no_of_vpath; i++) {
Joe Perchese80be0b2010-11-27 23:05:45 +00004715 entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004716 if (NULL == entry) {
4717 vxge_debug_init(VXGE_ERR,
4718 "%s: mac_addr_list : memory allocation failed",
4719 vdev->ndev->name);
4720 ret = -EPERM;
Jon Masone8ac1752010-11-11 04:25:57 +00004721 goto _exit6;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004722 }
4723 macaddr = (u8 *)&entry->macaddr;
4724 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4725 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4726 vdev->vpaths[i].mac_addr_cnt = 1;
4727 }
4728
Sreenivasa Honnur914d0d72009-07-01 21:13:12 +00004729 kfree(device_config);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00004730
4731 /*
4732 * INTA is shared in multi-function mode. This is unlike the INTA
4733 * implementation in MR mode, where each VH has its own INTA message.
4734 * - INTA is masked (disabled) as long as at least one function sets
4735 * its TITAN_MASK_ALL_INT.ALARM bit.
4736 * - INTA is unmasked (enabled) when all enabled functions have cleared
4737 * their own TITAN_MASK_ALL_INT.ALARM bit.
4738 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4739 * Though this driver leaves the top level interrupts unmasked while
4740 * leaving the required module interrupt bits masked on exit, there
4741 * could be a rougue driver around that does not follow this procedure
4742 * resulting in a failure to generate interrupts. The following code is
4743 * present to prevent such a failure.
4744 */
4745
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004746 if (ll_config->device_hw_info.function_mode ==
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00004747 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4748 if (vdev->config.intr_type == INTA)
4749 vxge_hw_device_unmask_all(hldev);
4750
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004751 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4752 vdev->ndev->name, __func__, __LINE__);
4753
4754 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4755 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4756 vxge_hw_device_trace_level_get(hldev));
4757
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004758 kfree(ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004759 return 0;
4760
Jon Masone8ac1752010-11-11 04:25:57 +00004761_exit6:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004762 for (i = 0; i < vdev->no_of_vpath; i++)
4763 vxge_free_mac_add_list(&vdev->vpaths[i]);
Jon Masone8ac1752010-11-11 04:25:57 +00004764_exit5:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004765 vxge_device_unregister(hldev);
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004766_exit4:
Jon Mason6cca2002011-01-18 15:02:19 +00004767 pci_set_drvdata(pdev, NULL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004768 vxge_hw_device_terminate(hldev);
Jon Mason6cca2002011-01-18 15:02:19 +00004769 pci_disable_sriov(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004770_exit3:
4771 iounmap(attr.bar0);
4772_exit2:
Jon Masondc66daa2010-12-10 14:02:58 +00004773 pci_release_region(pdev, 0);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004774_exit1:
4775 pci_disable_device(pdev);
4776_exit0:
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004777 kfree(ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004778 kfree(device_config);
4779 driver_config->config_dev_cnt--;
Jon Mason6cca2002011-01-18 15:02:19 +00004780 driver_config->total_dev_cnt--;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004781 return ret;
4782}
4783
4784/**
4785 * vxge_rem_nic - Free the PCI device
4786 * @pdev: structure containing the PCI related information of the device.
4787 * Description: This function is called by the Pci subsystem to release a
4788 * PCI device and free up all resource held up by the device.
4789 */
Jon Mason2c913082010-11-11 04:26:03 +00004790static void __devexit vxge_remove(struct pci_dev *pdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004791{
Jon Mason2c913082010-11-11 04:26:03 +00004792 struct __vxge_hw_device *hldev;
Jon Mason6cca2002011-01-18 15:02:19 +00004793 struct vxgedev *vdev;
4794 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004795
Joe Perchesd8ee7072010-11-15 10:13:58 +00004796 hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004797 if (hldev == NULL)
4798 return;
Jon Mason2c913082010-11-11 04:26:03 +00004799
Jon Mason6cca2002011-01-18 15:02:19 +00004800 vdev = netdev_priv(hldev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004801
Jon Mason2c913082010-11-11 04:26:03 +00004802 vxge_debug_entryexit(vdev->level_trace, "%s:%d", __func__, __LINE__);
Jon Mason2c913082010-11-11 04:26:03 +00004803 vxge_debug_init(vdev->level_trace, "%s : removing PCI device...",
4804 __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004805
Jon Mason6cca2002011-01-18 15:02:19 +00004806 for (i = 0; i < vdev->no_of_vpath; i++)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004807 vxge_free_mac_add_list(&vdev->vpaths[i]);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004808
Jon Mason6cca2002011-01-18 15:02:19 +00004809 vxge_device_unregister(hldev);
4810 pci_set_drvdata(pdev, NULL);
4811 /* Do not call pci_disable_sriov here, as it will break child devices */
4812 vxge_hw_device_terminate(hldev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004813 iounmap(vdev->bar0);
Jon Mason6cca2002011-01-18 15:02:19 +00004814 pci_release_region(pdev, 0);
4815 pci_disable_device(pdev);
4816 driver_config->config_dev_cnt--;
4817 driver_config->total_dev_cnt--;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004818
Jon Mason2c913082010-11-11 04:26:03 +00004819 vxge_debug_init(vdev->level_trace, "%s:%d Device unregistered",
4820 __func__, __LINE__);
Jon Mason2c913082010-11-11 04:26:03 +00004821 vxge_debug_entryexit(vdev->level_trace, "%s:%d Exiting...", __func__,
4822 __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004823}
4824
4825static struct pci_error_handlers vxge_err_handler = {
4826 .error_detected = vxge_io_error_detected,
4827 .slot_reset = vxge_io_slot_reset,
4828 .resume = vxge_io_resume,
4829};
4830
4831static struct pci_driver vxge_driver = {
4832 .name = VXGE_DRIVER_NAME,
4833 .id_table = vxge_id_table,
4834 .probe = vxge_probe,
4835 .remove = __devexit_p(vxge_remove),
4836#ifdef CONFIG_PM
4837 .suspend = vxge_pm_suspend,
4838 .resume = vxge_pm_resume,
4839#endif
4840 .err_handler = &vxge_err_handler,
4841};
4842
4843static int __init
4844vxge_starter(void)
4845{
4846 int ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004847
Joe Perches75f5e1c2010-07-27 11:47:03 +00004848 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4849 pr_info("Driver version: %s\n", DRV_VERSION);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004850
4851 verify_bandwidth();
4852
4853 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4854 if (!driver_config)
4855 return -ENOMEM;
4856
4857 ret = pci_register_driver(&vxge_driver);
Jon Mason528f7272010-12-10 14:02:56 +00004858 if (ret) {
4859 kfree(driver_config);
4860 goto err;
4861 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004862
4863 if (driver_config->config_dev_cnt &&
4864 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4865 vxge_debug_init(VXGE_ERR,
4866 "%s: Configured %d of %d devices",
4867 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4868 driver_config->total_dev_cnt);
Jon Mason528f7272010-12-10 14:02:56 +00004869err:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004870 return ret;
4871}
4872
4873static void __exit
4874vxge_closer(void)
4875{
4876 pci_unregister_driver(&vxge_driver);
4877 kfree(driver_config);
4878}
4879module_init(vxge_starter);
4880module_exit(vxge_closer);