blob: 1a53a24fe3d45a2ad832515d46311414f1a30c22 [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
Jiri Pirko53515732011-07-20 04:54:40 +000046#include <linux/bitops.h>
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000047#include <linux/if_vlan.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000048#include <linux/interrupt.h>
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000049#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090050#include <linux/slab.h>
Alexander Beregalov2b05e002009-04-04 16:36:18 -070051#include <linux/tcp.h>
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000052#include <net/ip.h>
53#include <linux/netdevice.h>
54#include <linux/etherdevice.h>
Jon Masone8ac1752010-11-11 04:25:57 +000055#include <linux/firmware.h>
Jon Masonb81b3732010-11-11 04:25:58 +000056#include <linux/net_tstamp.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040057#include <linux/prefetch.h>
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000058#include "vxge-main.h"
59#include "vxge-reg.h"
60
61MODULE_LICENSE("Dual BSD/GPL");
62MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
63 "Virtualized Server Adapter");
64
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000065static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000066 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
67 PCI_ANY_ID},
68 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
69 PCI_ANY_ID},
70 {0}
71};
72
73MODULE_DEVICE_TABLE(pci, vxge_id_table);
74
75VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
76VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
77VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
78VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
79VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
80VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
81
82static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
83 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
84static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
85 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
86module_param_array(bw_percentage, uint, NULL, 0);
87
88static struct vxge_drv_config *driver_config;
89
90static inline int is_vxge_card_up(struct vxgedev *vdev)
91{
92 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
93}
94
95static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
96{
Benjamin LaHaiseff67df52009-08-04 10:21:03 +000097 struct sk_buff **skb_ptr = NULL;
98 struct sk_buff **temp;
99#define NR_SKB_COMPLETED 128
100 struct sk_buff *completed[NR_SKB_COMPLETED];
101 int more;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000102
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000103 do {
104 more = 0;
105 skb_ptr = completed;
106
Jon Mason98f45da2010-07-15 08:47:25 +0000107 if (__netif_tx_trylock(fifo->txq)) {
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000108 vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
109 NR_SKB_COMPLETED, &more);
Jon Mason98f45da2010-07-15 08:47:25 +0000110 __netif_tx_unlock(fifo->txq);
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000111 }
Jon Mason98f45da2010-07-15 08:47:25 +0000112
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000113 /* free SKBs */
114 for (temp = completed; temp != skb_ptr; temp++)
115 dev_kfree_skb_irq(*temp);
Jon Mason98f45da2010-07-15 08:47:25 +0000116 } while (more);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000117}
118
119static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
120{
121 int i;
122
123 /* Complete all transmits */
124 for (i = 0; i < vdev->no_of_vpath; i++)
125 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
126}
127
128static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
129{
130 int i;
131 struct vxge_ring *ring;
132
133 /* Complete all receives*/
134 for (i = 0; i < vdev->no_of_vpath; i++) {
135 ring = &vdev->vpaths[i].ring;
136 vxge_hw_vpath_poll_rx(ring->handle);
137 }
138}
139
140/*
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000141 * vxge_callback_link_up
142 *
143 * This function is called during interrupt context to notify link up state
144 * change.
145 */
Jon Mason528f7272010-12-10 14:02:56 +0000146static void vxge_callback_link_up(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000147{
148 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +0000149 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000150
151 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
152 vdev->ndev->name, __func__, __LINE__);
Joe Perches75f5e1c2010-07-27 11:47:03 +0000153 netdev_notice(vdev->ndev, "Link Up\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000154 vdev->stats.link_up++;
155
156 netif_carrier_on(vdev->ndev);
Jon Masond03848e2010-07-15 08:47:23 +0000157 netif_tx_wake_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000158
159 vxge_debug_entryexit(VXGE_TRACE,
160 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
161}
162
163/*
164 * vxge_callback_link_down
165 *
166 * This function is called during interrupt context to notify link down state
167 * change.
168 */
Jon Mason528f7272010-12-10 14:02:56 +0000169static void vxge_callback_link_down(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000170{
171 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +0000172 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000173
174 vxge_debug_entryexit(VXGE_TRACE,
175 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
Joe Perches75f5e1c2010-07-27 11:47:03 +0000176 netdev_notice(vdev->ndev, "Link Down\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000177
178 vdev->stats.link_down++;
179 netif_carrier_off(vdev->ndev);
Jon Masond03848e2010-07-15 08:47:23 +0000180 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000181
182 vxge_debug_entryexit(VXGE_TRACE,
183 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
184}
185
186/*
187 * vxge_rx_alloc
188 *
189 * Allocate SKB.
190 */
Jon Mason528f7272010-12-10 14:02:56 +0000191static struct sk_buff *
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000192vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
193{
194 struct net_device *dev;
195 struct sk_buff *skb;
196 struct vxge_rx_priv *rx_priv;
197
198 dev = ring->ndev;
199 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
200 ring->ndev->name, __func__, __LINE__);
201
202 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
203
204 /* try to allocate skb first. this one may fail */
205 skb = netdev_alloc_skb(dev, skb_size +
206 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
207 if (skb == NULL) {
208 vxge_debug_mem(VXGE_ERR,
209 "%s: out of memory to allocate SKB", dev->name);
210 ring->stats.skb_alloc_fail++;
211 return NULL;
212 }
213
214 vxge_debug_mem(VXGE_TRACE,
215 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
216 __func__, __LINE__, skb);
217
218 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
219
220 rx_priv->skb = skb;
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000221 rx_priv->skb_data = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000222 rx_priv->data_size = skb_size;
223 vxge_debug_entryexit(VXGE_TRACE,
224 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
225
226 return skb;
227}
228
229/*
230 * vxge_rx_map
231 */
232static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
233{
234 struct vxge_rx_priv *rx_priv;
235 dma_addr_t dma_addr;
236
237 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
238 ring->ndev->name, __func__, __LINE__);
239 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
240
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000241 rx_priv->skb_data = rx_priv->skb->data;
242 dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000243 rx_priv->data_size, PCI_DMA_FROMDEVICE);
244
Denis Kirjanovfa15e992010-01-10 13:40:10 -0800245 if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000246 ring->stats.pci_map_fail++;
247 return -EIO;
248 }
249 vxge_debug_mem(VXGE_TRACE,
250 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
251 ring->ndev->name, __func__, __LINE__,
252 (unsigned long long)dma_addr);
253 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
254
255 rx_priv->data_dma = dma_addr;
256 vxge_debug_entryexit(VXGE_TRACE,
257 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
258
259 return 0;
260}
261
262/*
263 * vxge_rx_initial_replenish
264 * Allocation of RxD as an initial replenish procedure.
265 */
266static enum vxge_hw_status
267vxge_rx_initial_replenish(void *dtrh, void *userdata)
268{
269 struct vxge_ring *ring = (struct vxge_ring *)userdata;
270 struct vxge_rx_priv *rx_priv;
271
272 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
273 ring->ndev->name, __func__, __LINE__);
274 if (vxge_rx_alloc(dtrh, ring,
275 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
276 return VXGE_HW_FAIL;
277
278 if (vxge_rx_map(dtrh, ring)) {
279 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
280 dev_kfree_skb(rx_priv->skb);
281
282 return VXGE_HW_FAIL;
283 }
284 vxge_debug_entryexit(VXGE_TRACE,
285 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
286
287 return VXGE_HW_OK;
288}
289
290static inline void
291vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
292 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
293{
294
295 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
296 ring->ndev->name, __func__, __LINE__);
297 skb_record_rx_queue(skb, ring->driver_id);
298 skb->protocol = eth_type_trans(skb, ring->ndev);
299
stephen hemminger62ea0552011-06-20 10:35:07 +0000300 u64_stats_update_begin(&ring->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000301 ring->stats.rx_frms++;
302 ring->stats.rx_bytes += pkt_length;
303
304 if (skb->pkt_type == PACKET_MULTICAST)
305 ring->stats.rx_mcast++;
stephen hemminger62ea0552011-06-20 10:35:07 +0000306 u64_stats_update_end(&ring->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000307
308 vxge_debug_rx(VXGE_TRACE,
309 "%s: %s:%d skb protocol = %d",
310 ring->ndev->name, __func__, __LINE__, skb->protocol);
311
Jiri Pirko53515732011-07-20 04:54:40 +0000312 if (ext_info->vlan &&
313 ring->vlan_tag_strip == VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE)
314 __vlan_hwaccel_put_tag(skb, ext_info->vlan);
315 napi_gro_receive(ring->napi_p, skb);
Michał Mirosławfeb990d2011-04-18 13:31:21 +0000316
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000317 vxge_debug_entryexit(VXGE_TRACE,
318 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
319}
320
321static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
322 struct vxge_rx_priv *rx_priv)
323{
324 pci_dma_sync_single_for_device(ring->pdev,
325 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
326
327 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
328 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
329}
330
331static inline void vxge_post(int *dtr_cnt, void **first_dtr,
332 void *post_dtr, struct __vxge_hw_ring *ringh)
333{
334 int dtr_count = *dtr_cnt;
335 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
336 if (*first_dtr)
337 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
338 *first_dtr = post_dtr;
339 } else
340 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
341 dtr_count++;
342 *dtr_cnt = dtr_count;
343}
344
345/*
346 * vxge_rx_1b_compl
347 *
348 * If the interrupt is because of a received frame or if the receive ring
349 * contains fresh as yet un-processed frames, this function is called.
350 */
stephen hemminger42821a52010-10-21 07:50:53 +0000351static enum vxge_hw_status
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000352vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
353 u8 t_code, void *userdata)
354{
355 struct vxge_ring *ring = (struct vxge_ring *)userdata;
Jon Masonb81b3732010-11-11 04:25:58 +0000356 struct net_device *dev = ring->ndev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000357 unsigned int dma_sizes;
358 void *first_dtr = NULL;
359 int dtr_cnt = 0;
360 int data_size;
361 dma_addr_t data_dma;
362 int pkt_length;
363 struct sk_buff *skb;
364 struct vxge_rx_priv *rx_priv;
365 struct vxge_hw_ring_rxd_info ext_info;
366 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
367 ring->ndev->name, __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000368
369 do {
Benjamin LaHaise3f23e432009-08-04 10:21:39 +0000370 prefetch((char *)dtr + L1_CACHE_BYTES);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000371 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
372 skb = rx_priv->skb;
373 data_size = rx_priv->data_size;
374 data_dma = rx_priv->data_dma;
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000375 prefetch(rx_priv->skb_data);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000376
377 vxge_debug_rx(VXGE_TRACE,
378 "%s: %s:%d skb = 0x%p",
379 ring->ndev->name, __func__, __LINE__, skb);
380
381 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
382 pkt_length = dma_sizes;
383
Sreenivasa Honnur22fa1252009-07-01 21:17:24 +0000384 pkt_length -= ETH_FCS_LEN;
385
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000386 vxge_debug_rx(VXGE_TRACE,
387 "%s: %s:%d Packet Length = %d",
388 ring->ndev->name, __func__, __LINE__, pkt_length);
389
390 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
391
392 /* check skb validity */
393 vxge_assert(skb);
394
395 prefetch((char *)skb + L1_CACHE_BYTES);
396 if (unlikely(t_code)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000397 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
398 VXGE_HW_OK) {
399
400 ring->stats.rx_errors++;
401 vxge_debug_rx(VXGE_TRACE,
402 "%s: %s :%d Rx T_code is %d",
403 ring->ndev->name, __func__,
404 __LINE__, t_code);
405
406 /* If the t_code is not supported and if the
407 * t_code is other than 0x5 (unparseable packet
408 * such as unknown UPV6 header), Drop it !!!
409 */
410 vxge_re_pre_post(dtr, ring, rx_priv);
411
412 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
413 ring->stats.rx_dropped++;
414 continue;
415 }
416 }
417
418 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000419 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000420 if (!vxge_rx_map(dtr, ring)) {
421 skb_put(skb, pkt_length);
422
423 pci_unmap_single(ring->pdev, data_dma,
424 data_size, PCI_DMA_FROMDEVICE);
425
426 vxge_hw_ring_rxd_pre_post(ringh, dtr);
427 vxge_post(&dtr_cnt, &first_dtr, dtr,
428 ringh);
429 } else {
430 dev_kfree_skb(rx_priv->skb);
431 rx_priv->skb = skb;
432 rx_priv->data_size = data_size;
433 vxge_re_pre_post(dtr, ring, rx_priv);
434
435 vxge_post(&dtr_cnt, &first_dtr, dtr,
436 ringh);
437 ring->stats.rx_dropped++;
438 break;
439 }
440 } else {
441 vxge_re_pre_post(dtr, ring, rx_priv);
442
443 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
444 ring->stats.rx_dropped++;
445 break;
446 }
447 } else {
448 struct sk_buff *skb_up;
449
450 skb_up = netdev_alloc_skb(dev, pkt_length +
451 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
452 if (skb_up != NULL) {
453 skb_reserve(skb_up,
454 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
455
456 pci_dma_sync_single_for_cpu(ring->pdev,
457 data_dma, data_size,
458 PCI_DMA_FROMDEVICE);
459
460 vxge_debug_mem(VXGE_TRACE,
461 "%s: %s:%d skb_up = %p",
462 ring->ndev->name, __func__,
463 __LINE__, skb);
464 memcpy(skb_up->data, skb->data, pkt_length);
465
466 vxge_re_pre_post(dtr, ring, rx_priv);
467
468 vxge_post(&dtr_cnt, &first_dtr, dtr,
469 ringh);
470 /* will netif_rx small SKB instead */
471 skb = skb_up;
472 skb_put(skb, pkt_length);
473 } else {
474 vxge_re_pre_post(dtr, ring, rx_priv);
475
476 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
477 vxge_debug_rx(VXGE_ERR,
478 "%s: vxge_rx_1b_compl: out of "
479 "memory", dev->name);
480 ring->stats.skb_alloc_fail++;
481 break;
482 }
483 }
484
485 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
486 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
Michał Mirosławfeb990d2011-04-18 13:31:21 +0000487 (dev->features & NETIF_F_RXCSUM) && /* Offload Rx side CSUM */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000488 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
489 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
490 skb->ip_summed = CHECKSUM_UNNECESSARY;
491 else
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700492 skb_checksum_none_assert(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000493
Jon Masonb81b3732010-11-11 04:25:58 +0000494
495 if (ring->rx_hwts) {
496 struct skb_shared_hwtstamps *skb_hwts;
497 u32 ns = *(u32 *)(skb->head + pkt_length);
498
499 skb_hwts = skb_hwtstamps(skb);
500 skb_hwts->hwtstamp = ns_to_ktime(ns);
501 skb_hwts->syststamp.tv64 = 0;
502 }
503
Jon Mason47f01db2010-11-11 04:25:53 +0000504 /* rth_hash_type and rth_it_hit are non-zero regardless of
505 * whether rss is enabled. Only the rth_value is zero/non-zero
506 * if rss is disabled/enabled, so key off of that.
507 */
508 if (ext_info.rth_value)
509 skb->rxhash = ext_info.rth_value;
510
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000511 vxge_rx_complete(ring, skb, ext_info.vlan,
512 pkt_length, &ext_info);
513
514 ring->budget--;
515 ring->pkts_processed++;
516 if (!ring->budget)
517 break;
518
519 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
520 &t_code) == VXGE_HW_OK);
521
522 if (first_dtr)
523 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
524
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000525 vxge_debug_entryexit(VXGE_TRACE,
526 "%s:%d Exiting...",
527 __func__, __LINE__);
528 return VXGE_HW_OK;
529}
530
531/*
532 * vxge_xmit_compl
533 *
534 * If an interrupt was raised to indicate DMA complete of the Tx packet,
535 * this function is called. It identifies the last TxD whose buffer was
536 * freed and frees all skbs whose data have already DMA'ed into the NICs
537 * internal memory.
538 */
stephen hemminger42821a52010-10-21 07:50:53 +0000539static enum vxge_hw_status
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000540vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
541 enum vxge_hw_fifo_tcode t_code, void *userdata,
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000542 struct sk_buff ***skb_ptr, int nr_skb, int *more)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000543{
544 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000545 struct sk_buff *skb, **done_skb = *skb_ptr;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000546 int pkt_cnt = 0;
547
548 vxge_debug_entryexit(VXGE_TRACE,
549 "%s:%d Entered....", __func__, __LINE__);
550
551 do {
552 int frg_cnt;
553 skb_frag_t *frag;
554 int i = 0, j;
555 struct vxge_tx_priv *txd_priv =
556 vxge_hw_fifo_txdl_private_get(dtr);
557
558 skb = txd_priv->skb;
559 frg_cnt = skb_shinfo(skb)->nr_frags;
560 frag = &skb_shinfo(skb)->frags[0];
561
562 vxge_debug_tx(VXGE_TRACE,
563 "%s: %s:%d fifo_hw = %p dtr = %p "
564 "tcode = 0x%x", fifo->ndev->name, __func__,
565 __LINE__, fifo_hw, dtr, t_code);
566 /* check skb validity */
567 vxge_assert(skb);
568 vxge_debug_tx(VXGE_TRACE,
569 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
570 fifo->ndev->name, __func__, __LINE__,
571 skb, txd_priv, frg_cnt);
572 if (unlikely(t_code)) {
573 fifo->stats.tx_errors++;
574 vxge_debug_tx(VXGE_ERR,
575 "%s: tx: dtr %p completed due to "
576 "error t_code %01x", fifo->ndev->name,
577 dtr, t_code);
578 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
579 }
580
581 /* for unfragmented skb */
582 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
583 skb_headlen(skb), PCI_DMA_TODEVICE);
584
585 for (j = 0; j < frg_cnt; j++) {
586 pci_unmap_page(fifo->pdev,
587 txd_priv->dma_buffers[i++],
588 frag->size, PCI_DMA_TODEVICE);
589 frag += 1;
590 }
591
592 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
593
594 /* Updating the statistics block */
stephen hemminger62ea0552011-06-20 10:35:07 +0000595 u64_stats_update_begin(&fifo->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000596 fifo->stats.tx_frms++;
597 fifo->stats.tx_bytes += skb->len;
stephen hemminger62ea0552011-06-20 10:35:07 +0000598 u64_stats_update_end(&fifo->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000599
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000600 *done_skb++ = skb;
601
602 if (--nr_skb <= 0) {
603 *more = 1;
604 break;
605 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000606
607 pkt_cnt++;
608 if (pkt_cnt > fifo->indicate_max_pkts)
609 break;
610
611 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
612 &dtr, &t_code) == VXGE_HW_OK);
613
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000614 *skb_ptr = done_skb;
Jon Mason98f45da2010-07-15 08:47:25 +0000615 if (netif_tx_queue_stopped(fifo->txq))
616 netif_tx_wake_queue(fifo->txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000617
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000618 vxge_debug_entryexit(VXGE_TRACE,
619 "%s: %s:%d Exiting...",
620 fifo->ndev->name, __func__, __LINE__);
621 return VXGE_HW_OK;
622}
623
Eric Dumazet28679752009-05-27 19:26:37 +0000624/* select a vpath to transmit the packet */
Jon Mason98f45da2010-07-15 08:47:25 +0000625static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000626{
627 u16 queue_len, counter = 0;
628 if (skb->protocol == htons(ETH_P_IP)) {
629 struct iphdr *ip;
630 struct tcphdr *th;
631
632 ip = ip_hdr(skb);
633
Paul Gortmaker56f8a752011-06-21 20:33:34 -0700634 if (!ip_is_fragment(ip)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000635 th = (struct tcphdr *)(((unsigned char *)ip) +
636 ip->ihl*4);
637
638 queue_len = vdev->no_of_vpath;
639 counter = (ntohs(th->source) +
640 ntohs(th->dest)) &
641 vdev->vpath_selector[queue_len - 1];
642 if (counter >= queue_len)
643 counter = queue_len - 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000644 }
645 }
646 return counter;
647}
648
649static enum vxge_hw_status vxge_search_mac_addr_in_list(
650 struct vxge_vpath *vpath, u64 del_mac)
651{
652 struct list_head *entry, *next;
653 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
654 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
655 return TRUE;
656 }
657 return FALSE;
658}
659
Jon Mason528f7272010-12-10 14:02:56 +0000660static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
661{
662 struct vxge_mac_addrs *new_mac_entry;
663 u8 *mac_address = NULL;
664
665 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
666 return TRUE;
667
668 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
669 if (!new_mac_entry) {
670 vxge_debug_mem(VXGE_ERR,
671 "%s: memory allocation failed",
672 VXGE_DRIVER_NAME);
673 return FALSE;
674 }
675
676 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
677
678 /* Copy the new mac address to the list */
679 mac_address = (u8 *)&new_mac_entry->macaddr;
680 memcpy(mac_address, mac->macaddr, ETH_ALEN);
681
682 new_mac_entry->state = mac->state;
683 vpath->mac_addr_cnt++;
684
Tobias Klauserf8d4aa22011-07-03 23:58:04 +0000685 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +0000686 vpath->mcast_addr_cnt++;
687
688 return TRUE;
689}
690
691/* Add a mac address to DA table */
692static enum vxge_hw_status
693vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
694{
695 enum vxge_hw_status status = VXGE_HW_OK;
696 struct vxge_vpath *vpath;
697 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
698
Tobias Klauserf8d4aa22011-07-03 23:58:04 +0000699 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +0000700 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
701 else
702 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
703
704 vpath = &vdev->vpaths[mac->vpath_no];
705 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
706 mac->macmask, duplicate_mode);
707 if (status != VXGE_HW_OK) {
708 vxge_debug_init(VXGE_ERR,
709 "DA config add entry failed for vpath:%d",
710 vpath->device_id);
711 } else
712 if (FALSE == vxge_mac_list_add(vpath, mac))
713 status = -EPERM;
714
715 return status;
716}
717
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000718static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
719{
720 struct macInfo mac_info;
721 u8 *mac_address = NULL;
722 u64 mac_addr = 0, vpath_vector = 0;
723 int vpath_idx = 0;
724 enum vxge_hw_status status = VXGE_HW_OK;
725 struct vxge_vpath *vpath = NULL;
726 struct __vxge_hw_device *hldev;
727
Joe Perchesd8ee7072010-11-15 10:13:58 +0000728 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000729
730 mac_address = (u8 *)&mac_addr;
731 memcpy(mac_address, mac_header, ETH_ALEN);
732
733 /* Is this mac address already in the list? */
734 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
735 vpath = &vdev->vpaths[vpath_idx];
736 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
737 return vpath_idx;
738 }
739
740 memset(&mac_info, 0, sizeof(struct macInfo));
741 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
742
743 /* Any vpath has room to add mac address to its da table? */
744 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
745 vpath = &vdev->vpaths[vpath_idx];
746 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
747 /* Add this mac address to this vpath */
748 mac_info.vpath_no = vpath_idx;
749 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
750 status = vxge_add_mac_addr(vdev, &mac_info);
751 if (status != VXGE_HW_OK)
752 return -EPERM;
753 return vpath_idx;
754 }
755 }
756
757 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
758 vpath_idx = 0;
759 mac_info.vpath_no = vpath_idx;
760 /* Is the first vpath already selected as catch-basin ? */
761 vpath = &vdev->vpaths[vpath_idx];
762 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
763 /* Add this mac address to this vpath */
764 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
765 return -EPERM;
766 return vpath_idx;
767 }
768
769 /* Select first vpath as catch-basin */
770 vpath_vector = vxge_mBIT(vpath->device_id);
771 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
772 vxge_hw_mgmt_reg_type_mrpcim,
773 0,
774 (ulong)offsetof(
775 struct vxge_hw_mrpcim_reg,
776 rts_mgr_cbasin_cfg),
777 vpath_vector);
778 if (status != VXGE_HW_OK) {
779 vxge_debug_tx(VXGE_ERR,
780 "%s: Unable to set the vpath-%d in catch-basin mode",
781 VXGE_DRIVER_NAME, vpath->device_id);
782 return -EPERM;
783 }
784
785 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
786 return -EPERM;
787
788 return vpath_idx;
789}
790
791/**
792 * vxge_xmit
793 * @skb : the socket buffer containing the Tx data.
794 * @dev : device pointer.
795 *
796 * This function is the Tx entry point of the driver. Neterion NIC supports
797 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000798*/
Stephen Hemminger613573252009-08-31 19:50:58 +0000799static netdev_tx_t
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000800vxge_xmit(struct sk_buff *skb, struct net_device *dev)
801{
802 struct vxge_fifo *fifo = NULL;
803 void *dtr_priv;
804 void *dtr = NULL;
805 struct vxgedev *vdev = NULL;
806 enum vxge_hw_status status;
807 int frg_cnt, first_frg_len;
808 skb_frag_t *frag;
809 int i = 0, j = 0, avail;
810 u64 dma_pointer;
811 struct vxge_tx_priv *txdl_priv = NULL;
812 struct __vxge_hw_fifo *fifo_hw;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000813 int offload_type;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000814 int vpath_no = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000815
816 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
817 dev->name, __func__, __LINE__);
818
819 /* A buffer with no data will be dropped */
820 if (unlikely(skb->len <= 0)) {
821 vxge_debug_tx(VXGE_ERR,
822 "%s: Buffer has no data..", dev->name);
823 dev_kfree_skb(skb);
824 return NETDEV_TX_OK;
825 }
826
Joe Perches5f54ceb2010-11-15 11:12:30 +0000827 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000828
829 if (unlikely(!is_vxge_card_up(vdev))) {
830 vxge_debug_tx(VXGE_ERR,
831 "%s: vdev not initialized", dev->name);
832 dev_kfree_skb(skb);
833 return NETDEV_TX_OK;
834 }
835
836 if (vdev->config.addr_learn_en) {
837 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
838 if (vpath_no == -EPERM) {
839 vxge_debug_tx(VXGE_ERR,
840 "%s: Failed to store the mac address",
841 dev->name);
842 dev_kfree_skb(skb);
843 return NETDEV_TX_OK;
844 }
845 }
846
847 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
848 vpath_no = skb_get_queue_mapping(skb);
849 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
Jon Mason98f45da2010-07-15 08:47:25 +0000850 vpath_no = vxge_get_vpath_no(vdev, skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000851
852 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
853
854 if (vpath_no >= vdev->no_of_vpath)
855 vpath_no = 0;
856
857 fifo = &vdev->vpaths[vpath_no].fifo;
858 fifo_hw = fifo->handle;
859
Jon Mason98f45da2010-07-15 08:47:25 +0000860 if (netif_tx_queue_stopped(fifo->txq))
Jon Masond03848e2010-07-15 08:47:23 +0000861 return NETDEV_TX_BUSY;
Jon Masond03848e2010-07-15 08:47:23 +0000862
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000863 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
864 if (avail == 0) {
865 vxge_debug_tx(VXGE_ERR,
866 "%s: No free TXDs available", dev->name);
867 fifo->stats.txd_not_free++;
Jon Mason98f45da2010-07-15 08:47:25 +0000868 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000869 }
870
Benjamin LaHaise4403b372009-08-04 10:20:44 +0000871 /* Last TXD? Stop tx queue to avoid dropping packets. TX
872 * completion will resume the queue.
873 */
874 if (avail == 1)
Jon Mason98f45da2010-07-15 08:47:25 +0000875 netif_tx_stop_queue(fifo->txq);
Benjamin LaHaise4403b372009-08-04 10:20:44 +0000876
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000877 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
878 if (unlikely(status != VXGE_HW_OK)) {
879 vxge_debug_tx(VXGE_ERR,
880 "%s: Out of descriptors .", dev->name);
881 fifo->stats.txd_out_of_desc++;
Jon Mason98f45da2010-07-15 08:47:25 +0000882 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000883 }
884
885 vxge_debug_tx(VXGE_TRACE,
886 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
887 dev->name, __func__, __LINE__,
888 fifo_hw, dtr, dtr_priv);
889
Jesse Grosseab6d182010-10-20 13:56:03 +0000890 if (vlan_tx_tag_present(skb)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000891 u16 vlan_tag = vlan_tx_tag_get(skb);
892 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
893 }
894
895 first_frg_len = skb_headlen(skb);
896
897 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
898 PCI_DMA_TODEVICE);
899
900 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
901 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000902 fifo->stats.pci_map_fail++;
Jon Mason98f45da2010-07-15 08:47:25 +0000903 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000904 }
905
906 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
907 txdl_priv->skb = skb;
908 txdl_priv->dma_buffers[j] = dma_pointer;
909
910 frg_cnt = skb_shinfo(skb)->nr_frags;
911 vxge_debug_tx(VXGE_TRACE,
912 "%s: %s:%d skb = %p txdl_priv = %p "
913 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
914 __func__, __LINE__, skb, txdl_priv,
915 frg_cnt, (unsigned long long)dma_pointer);
916
917 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
918 first_frg_len);
919
920 frag = &skb_shinfo(skb)->frags[0];
921 for (i = 0; i < frg_cnt; i++) {
922 /* ignore 0 length fragment */
923 if (!frag->size)
924 continue;
925
Jon Mason98f45da2010-07-15 08:47:25 +0000926 dma_pointer = (u64) pci_map_page(fifo->pdev, frag->page,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000927 frag->page_offset, frag->size,
928 PCI_DMA_TODEVICE);
929
930 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
Jon Mason98f45da2010-07-15 08:47:25 +0000931 goto _exit2;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000932 vxge_debug_tx(VXGE_TRACE,
933 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
934 dev->name, __func__, __LINE__, i,
935 (unsigned long long)dma_pointer);
936
937 txdl_priv->dma_buffers[j] = dma_pointer;
938 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
939 frag->size);
940 frag += 1;
941 }
942
943 offload_type = vxge_offload_type(skb);
944
945 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000946 int mss = vxge_tcp_mss(skb);
947 if (mss) {
Jon Mason98f45da2010-07-15 08:47:25 +0000948 vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000949 dev->name, __func__, __LINE__, mss);
950 vxge_hw_fifo_txdl_mss_set(dtr, mss);
951 } else {
952 vxge_assert(skb->len <=
953 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
954 vxge_assert(0);
955 goto _exit1;
956 }
957 }
958
959 if (skb->ip_summed == CHECKSUM_PARTIAL)
960 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
961 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
962 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
963 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
964
965 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000966
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000967 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
968 dev->name, __func__, __LINE__);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000969 return NETDEV_TX_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000970
Jon Mason98f45da2010-07-15 08:47:25 +0000971_exit2:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000972 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000973_exit1:
974 j = 0;
975 frag = &skb_shinfo(skb)->frags[0];
976
977 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
978 skb_headlen(skb), PCI_DMA_TODEVICE);
979
980 for (; j < i; j++) {
981 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
982 frag->size, PCI_DMA_TODEVICE);
983 frag += 1;
984 }
985
986 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
Jon Mason98f45da2010-07-15 08:47:25 +0000987_exit0:
988 netif_tx_stop_queue(fifo->txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000989 dev_kfree_skb(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000990
Patrick McHardy6ed10652009-06-23 06:03:08 +0000991 return NETDEV_TX_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000992}
993
994/*
995 * vxge_rx_term
996 *
997 * Function will be called by hw function to abort all outstanding receive
998 * descriptors.
999 */
1000static void
1001vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1002{
1003 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1004 struct vxge_rx_priv *rx_priv =
1005 vxge_hw_ring_rxd_private_get(dtrh);
1006
1007 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1008 ring->ndev->name, __func__, __LINE__);
1009 if (state != VXGE_HW_RXD_STATE_POSTED)
1010 return;
1011
1012 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1013 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1014
1015 dev_kfree_skb(rx_priv->skb);
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +00001016 rx_priv->skb_data = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001017
1018 vxge_debug_entryexit(VXGE_TRACE,
1019 "%s: %s:%d Exiting...",
1020 ring->ndev->name, __func__, __LINE__);
1021}
1022
1023/*
1024 * vxge_tx_term
1025 *
1026 * Function will be called to abort all outstanding tx descriptors
1027 */
1028static void
1029vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1030{
1031 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1032 skb_frag_t *frag;
1033 int i = 0, j, frg_cnt;
1034 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1035 struct sk_buff *skb = txd_priv->skb;
1036
1037 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1038
1039 if (state != VXGE_HW_TXDL_STATE_POSTED)
1040 return;
1041
1042 /* check skb validity */
1043 vxge_assert(skb);
1044 frg_cnt = skb_shinfo(skb)->nr_frags;
1045 frag = &skb_shinfo(skb)->frags[0];
1046
1047 /* for unfragmented skb */
1048 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1049 skb_headlen(skb), PCI_DMA_TODEVICE);
1050
1051 for (j = 0; j < frg_cnt; j++) {
1052 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
1053 frag->size, PCI_DMA_TODEVICE);
1054 frag += 1;
1055 }
1056
1057 dev_kfree_skb(skb);
1058
1059 vxge_debug_entryexit(VXGE_TRACE,
1060 "%s:%d Exiting...", __func__, __LINE__);
1061}
1062
Jon Mason528f7272010-12-10 14:02:56 +00001063static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1064{
1065 struct list_head *entry, *next;
1066 u64 del_mac = 0;
1067 u8 *mac_address = (u8 *) (&del_mac);
1068
1069 /* Copy the mac address to delete from the list */
1070 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1071
1072 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1073 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1074 list_del(entry);
1075 kfree((struct vxge_mac_addrs *)entry);
1076 vpath->mac_addr_cnt--;
1077
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001078 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +00001079 vpath->mcast_addr_cnt--;
1080 return TRUE;
1081 }
1082 }
1083
1084 return FALSE;
1085}
1086
1087/* delete a mac address from DA table */
1088static enum vxge_hw_status
1089vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1090{
1091 enum vxge_hw_status status = VXGE_HW_OK;
1092 struct vxge_vpath *vpath;
1093
1094 vpath = &vdev->vpaths[mac->vpath_no];
1095 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1096 mac->macmask);
1097 if (status != VXGE_HW_OK) {
1098 vxge_debug_init(VXGE_ERR,
1099 "DA config delete entry failed for vpath:%d",
1100 vpath->device_id);
1101 } else
1102 vxge_mac_list_del(vpath, mac);
1103 return status;
1104}
1105
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001106/**
1107 * vxge_set_multicast
1108 * @dev: pointer to the device structure
1109 *
1110 * Entry point for multicast address enable/disable
1111 * This function is a driver entry point which gets called by the kernel
1112 * whenever multicast addresses must be enabled/disabled. This also gets
1113 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1114 * determine, if multicast address must be enabled or if promiscuous mode
1115 * is to be disabled etc.
1116 */
1117static void vxge_set_multicast(struct net_device *dev)
1118{
Jiri Pirko22bedad2010-04-01 21:22:57 +00001119 struct netdev_hw_addr *ha;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001120 struct vxgedev *vdev;
1121 int i, mcast_cnt = 0;
Jon Mason7adf7d12010-07-15 08:47:24 +00001122 struct __vxge_hw_device *hldev;
1123 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001124 enum vxge_hw_status status = VXGE_HW_OK;
1125 struct macInfo mac_info;
1126 int vpath_idx = 0;
1127 struct vxge_mac_addrs *mac_entry;
1128 struct list_head *list_head;
1129 struct list_head *entry, *next;
1130 u8 *mac_address = NULL;
1131
1132 vxge_debug_entryexit(VXGE_TRACE,
1133 "%s:%d", __func__, __LINE__);
1134
Joe Perches5f54ceb2010-11-15 11:12:30 +00001135 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001136 hldev = (struct __vxge_hw_device *)vdev->devh;
1137
1138 if (unlikely(!is_vxge_card_up(vdev)))
1139 return;
1140
1141 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1142 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001143 vpath = &vdev->vpaths[i];
1144 vxge_assert(vpath->is_open);
1145 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1146 if (status != VXGE_HW_OK)
1147 vxge_debug_init(VXGE_ERR, "failed to enable "
1148 "multicast, status %d", status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001149 vdev->all_multi_flg = 1;
1150 }
Jon Mason7adf7d12010-07-15 08:47:24 +00001151 } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001152 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001153 vpath = &vdev->vpaths[i];
1154 vxge_assert(vpath->is_open);
1155 status = vxge_hw_vpath_mcast_disable(vpath->handle);
1156 if (status != VXGE_HW_OK)
1157 vxge_debug_init(VXGE_ERR, "failed to disable "
1158 "multicast, status %d", status);
1159 vdev->all_multi_flg = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001160 }
1161 }
1162
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001163
1164 if (!vdev->config.addr_learn_en) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001165 for (i = 0; i < vdev->no_of_vpath; i++) {
1166 vpath = &vdev->vpaths[i];
1167 vxge_assert(vpath->is_open);
1168
1169 if (dev->flags & IFF_PROMISC)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001170 status = vxge_hw_vpath_promisc_enable(
Jon Mason7adf7d12010-07-15 08:47:24 +00001171 vpath->handle);
1172 else
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001173 status = vxge_hw_vpath_promisc_disable(
Jon Mason7adf7d12010-07-15 08:47:24 +00001174 vpath->handle);
1175 if (status != VXGE_HW_OK)
1176 vxge_debug_init(VXGE_ERR, "failed to %s promisc"
1177 ", status %d", dev->flags&IFF_PROMISC ?
1178 "enable" : "disable", status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001179 }
1180 }
1181
1182 memset(&mac_info, 0, sizeof(struct macInfo));
1183 /* Update individual M_CAST address list */
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001184 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001185 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1186 list_head = &vdev->vpaths[0].mac_addr_list;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001187 if ((netdev_mc_count(dev) +
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001188 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1189 vdev->vpaths[0].max_mac_addr_cnt)
1190 goto _set_all_mcast;
1191
1192 /* Delete previous MC's */
1193 for (i = 0; i < mcast_cnt; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001194 list_for_each_safe(entry, next, list_head) {
Jon Mason2c913082010-11-11 04:26:03 +00001195 mac_entry = (struct vxge_mac_addrs *)entry;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001196 /* Copy the mac address to delete */
1197 mac_address = (u8 *)&mac_entry->macaddr;
1198 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1199
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001200 if (is_multicast_ether_addr(mac_info.macaddr)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001201 for (vpath_idx = 0; vpath_idx <
1202 vdev->no_of_vpath;
1203 vpath_idx++) {
1204 mac_info.vpath_no = vpath_idx;
1205 status = vxge_del_mac_addr(
1206 vdev,
1207 &mac_info);
1208 }
1209 }
1210 }
1211 }
1212
1213 /* Add new ones */
Jiri Pirko22bedad2010-04-01 21:22:57 +00001214 netdev_for_each_mc_addr(ha, dev) {
1215 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001216 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1217 vpath_idx++) {
1218 mac_info.vpath_no = vpath_idx;
1219 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1220 status = vxge_add_mac_addr(vdev, &mac_info);
1221 if (status != VXGE_HW_OK) {
1222 vxge_debug_init(VXGE_ERR,
1223 "%s:%d Setting individual"
1224 "multicast address failed",
1225 __func__, __LINE__);
1226 goto _set_all_mcast;
1227 }
1228 }
1229 }
1230
1231 return;
1232_set_all_mcast:
1233 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1234 /* Delete previous MC's */
1235 for (i = 0; i < mcast_cnt; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001236 list_for_each_safe(entry, next, list_head) {
Jon Mason2c913082010-11-11 04:26:03 +00001237 mac_entry = (struct vxge_mac_addrs *)entry;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001238 /* Copy the mac address to delete */
1239 mac_address = (u8 *)&mac_entry->macaddr;
1240 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1241
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001242 if (is_multicast_ether_addr(mac_info.macaddr))
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001243 break;
1244 }
1245
1246 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1247 vpath_idx++) {
1248 mac_info.vpath_no = vpath_idx;
1249 status = vxge_del_mac_addr(vdev, &mac_info);
1250 }
1251 }
1252
1253 /* Enable all multicast */
1254 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001255 vpath = &vdev->vpaths[i];
1256 vxge_assert(vpath->is_open);
1257
1258 status = vxge_hw_vpath_mcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001259 if (status != VXGE_HW_OK) {
1260 vxge_debug_init(VXGE_ERR,
1261 "%s:%d Enabling all multicasts failed",
1262 __func__, __LINE__);
1263 }
1264 vdev->all_multi_flg = 1;
1265 }
1266 dev->flags |= IFF_ALLMULTI;
1267 }
1268
1269 vxge_debug_entryexit(VXGE_TRACE,
1270 "%s:%d Exiting...", __func__, __LINE__);
1271}
1272
1273/**
1274 * vxge_set_mac_addr
1275 * @dev: pointer to the device structure
1276 *
1277 * Update entry "0" (default MAC addr)
1278 */
1279static int vxge_set_mac_addr(struct net_device *dev, void *p)
1280{
1281 struct sockaddr *addr = p;
1282 struct vxgedev *vdev;
Jon Mason2c913082010-11-11 04:26:03 +00001283 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001284 enum vxge_hw_status status = VXGE_HW_OK;
1285 struct macInfo mac_info_new, mac_info_old;
1286 int vpath_idx = 0;
1287
1288 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1289
Joe Perches5f54ceb2010-11-15 11:12:30 +00001290 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001291 hldev = vdev->devh;
1292
1293 if (!is_valid_ether_addr(addr->sa_data))
1294 return -EINVAL;
1295
1296 memset(&mac_info_new, 0, sizeof(struct macInfo));
1297 memset(&mac_info_old, 0, sizeof(struct macInfo));
1298
1299 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1300 __func__, __LINE__);
1301
1302 /* Get the old address */
1303 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1304
1305 /* Copy the new address */
1306 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1307
1308 /* First delete the old mac address from all the vpaths
1309 as we can't specify the index while adding new mac address */
1310 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1311 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1312 if (!vpath->is_open) {
1313 /* This can happen when this interface is added/removed
1314 to the bonding interface. Delete this station address
1315 from the linked list */
1316 vxge_mac_list_del(vpath, &mac_info_old);
1317
1318 /* Add this new address to the linked list
1319 for later restoring */
1320 vxge_mac_list_add(vpath, &mac_info_new);
1321
1322 continue;
1323 }
1324 /* Delete the station address */
1325 mac_info_old.vpath_no = vpath_idx;
1326 status = vxge_del_mac_addr(vdev, &mac_info_old);
1327 }
1328
1329 if (unlikely(!is_vxge_card_up(vdev))) {
1330 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1331 return VXGE_HW_OK;
1332 }
1333
1334 /* Set this mac address to all the vpaths */
1335 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1336 mac_info_new.vpath_no = vpath_idx;
1337 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1338 status = vxge_add_mac_addr(vdev, &mac_info_new);
1339 if (status != VXGE_HW_OK)
1340 return -EINVAL;
1341 }
1342
1343 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1344
1345 return status;
1346}
1347
1348/*
1349 * vxge_vpath_intr_enable
1350 * @vdev: pointer to vdev
1351 * @vp_id: vpath for which to enable the interrupts
1352 *
1353 * Enables the interrupts for the vpath
1354*/
stephen hemminger42821a52010-10-21 07:50:53 +00001355static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001356{
1357 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00001358 int msix_id = 0;
1359 int tim_msix_id[4] = {0, 1, 0, 0};
1360 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001361
1362 vxge_hw_vpath_intr_enable(vpath->handle);
1363
1364 if (vdev->config.intr_type == INTA)
1365 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1366 else {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001367 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1368 alarm_msix_id);
1369
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00001370 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001371 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1372 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1373
1374 /* enable the alarm vector */
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00001375 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1376 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1377 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001378 }
1379}
1380
1381/*
1382 * vxge_vpath_intr_disable
1383 * @vdev: pointer to vdev
1384 * @vp_id: vpath for which to disable the interrupts
1385 *
1386 * Disables the interrupts for the vpath
1387*/
stephen hemminger42821a52010-10-21 07:50:53 +00001388static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001389{
1390 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Jon Mason4d2a5b42010-11-11 04:25:54 +00001391 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001392 int msix_id;
1393
Joe Perchesd8ee7072010-11-15 10:13:58 +00001394 hldev = pci_get_drvdata(vdev->pdev);
Jon Mason4d2a5b42010-11-11 04:25:54 +00001395
1396 vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
1397
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001398 vxge_hw_vpath_intr_disable(vpath->handle);
1399
1400 if (vdev->config.intr_type == INTA)
1401 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1402 else {
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00001403 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001404 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1405 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1406
1407 /* disable the alarm vector */
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00001408 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1409 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001410 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1411 }
1412}
1413
Jon Mason528f7272010-12-10 14:02:56 +00001414/* list all mac addresses from DA table */
1415static enum vxge_hw_status
1416vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, struct macInfo *mac)
1417{
1418 enum vxge_hw_status status = VXGE_HW_OK;
1419 unsigned char macmask[ETH_ALEN];
1420 unsigned char macaddr[ETH_ALEN];
1421
1422 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1423 macaddr, macmask);
1424 if (status != VXGE_HW_OK) {
1425 vxge_debug_init(VXGE_ERR,
1426 "DA config list entry failed for vpath:%d",
1427 vpath->device_id);
1428 return status;
1429 }
1430
1431 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1432 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1433 macaddr, macmask);
1434 if (status != VXGE_HW_OK)
1435 break;
1436 }
1437
1438 return status;
1439}
1440
1441/* Store all mac addresses from the list to the DA table */
1442static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1443{
1444 enum vxge_hw_status status = VXGE_HW_OK;
1445 struct macInfo mac_info;
1446 u8 *mac_address = NULL;
1447 struct list_head *entry, *next;
1448
1449 memset(&mac_info, 0, sizeof(struct macInfo));
1450
1451 if (vpath->is_open) {
1452 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1453 mac_address =
1454 (u8 *)&
1455 ((struct vxge_mac_addrs *)entry)->macaddr;
1456 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1457 ((struct vxge_mac_addrs *)entry)->state =
1458 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1459 /* does this mac address already exist in da table? */
1460 status = vxge_search_mac_addr_in_da_table(vpath,
1461 &mac_info);
1462 if (status != VXGE_HW_OK) {
1463 /* Add this mac address to the DA table */
1464 status = vxge_hw_vpath_mac_addr_add(
1465 vpath->handle, mac_info.macaddr,
1466 mac_info.macmask,
1467 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
1468 if (status != VXGE_HW_OK) {
1469 vxge_debug_init(VXGE_ERR,
1470 "DA add entry failed for vpath:%d",
1471 vpath->device_id);
1472 ((struct vxge_mac_addrs *)entry)->state
1473 = VXGE_LL_MAC_ADDR_IN_LIST;
1474 }
1475 }
1476 }
1477 }
1478
1479 return status;
1480}
1481
1482/* Store all vlan ids from the list to the vid table */
1483static enum vxge_hw_status
1484vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1485{
1486 enum vxge_hw_status status = VXGE_HW_OK;
1487 struct vxgedev *vdev = vpath->vdev;
1488 u16 vid;
1489
Jiri Pirko53515732011-07-20 04:54:40 +00001490 if (!vpath->is_open)
1491 return status;
Jon Mason528f7272010-12-10 14:02:56 +00001492
Jiri Pirko53515732011-07-20 04:54:40 +00001493 for_each_set_bit(vid, vdev->active_vlans, VLAN_N_VID)
1494 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
Jon Mason528f7272010-12-10 14:02:56 +00001495
1496 return status;
1497}
1498
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001499/*
1500 * vxge_reset_vpath
1501 * @vdev: pointer to vdev
1502 * @vp_id: vpath to reset
1503 *
1504 * Resets the vpath
1505*/
1506static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1507{
1508 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00001509 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001510 int ret = 0;
1511
1512 /* check if device is down already */
1513 if (unlikely(!is_vxge_card_up(vdev)))
1514 return 0;
1515
1516 /* is device reset already scheduled */
1517 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1518 return 0;
1519
Jon Mason7adf7d12010-07-15 08:47:24 +00001520 if (vpath->handle) {
1521 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001522 if (is_vxge_card_up(vdev) &&
Jon Mason7adf7d12010-07-15 08:47:24 +00001523 vxge_hw_vpath_recover_from_reset(vpath->handle)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001524 != VXGE_HW_OK) {
1525 vxge_debug_init(VXGE_ERR,
1526 "vxge_hw_vpath_recover_from_reset"
1527 "failed for vpath:%d", vp_id);
1528 return status;
1529 }
1530 } else {
1531 vxge_debug_init(VXGE_ERR,
1532 "vxge_hw_vpath_reset failed for"
1533 "vpath:%d", vp_id);
1534 return status;
1535 }
1536 } else
1537 return VXGE_HW_FAIL;
1538
Jon Mason7adf7d12010-07-15 08:47:24 +00001539 vxge_restore_vpath_mac_addr(vpath);
1540 vxge_restore_vpath_vid_table(vpath);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001541
1542 /* Enable all broadcast */
Jon Mason7adf7d12010-07-15 08:47:24 +00001543 vxge_hw_vpath_bcast_enable(vpath->handle);
1544
1545 /* Enable all multicast */
1546 if (vdev->all_multi_flg) {
1547 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1548 if (status != VXGE_HW_OK)
1549 vxge_debug_init(VXGE_ERR,
1550 "%s:%d Enabling multicast failed",
1551 __func__, __LINE__);
1552 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001553
1554 /* Enable the interrupts */
1555 vxge_vpath_intr_enable(vdev, vp_id);
1556
1557 smp_wmb();
1558
1559 /* Enable the flow of traffic through the vpath */
Jon Mason7adf7d12010-07-15 08:47:24 +00001560 vxge_hw_vpath_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001561
1562 smp_wmb();
Jon Mason7adf7d12010-07-15 08:47:24 +00001563 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
1564 vpath->ring.last_status = VXGE_HW_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001565
1566 /* Vpath reset done */
1567 clear_bit(vp_id, &vdev->vp_reset);
1568
1569 /* Start the vpath queue */
Jon Mason98f45da2010-07-15 08:47:25 +00001570 if (netif_tx_queue_stopped(vpath->fifo.txq))
1571 netif_tx_wake_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001572
1573 return ret;
1574}
1575
Jon Mason16fded72011-01-18 15:02:21 +00001576/* Configure CI */
1577static void vxge_config_ci_for_tti_rti(struct vxgedev *vdev)
1578{
1579 int i = 0;
1580
1581 /* Enable CI for RTI */
1582 if (vdev->config.intr_type == MSI_X) {
1583 for (i = 0; i < vdev->no_of_vpath; i++) {
1584 struct __vxge_hw_ring *hw_ring;
1585
1586 hw_ring = vdev->vpaths[i].ring.handle;
1587 vxge_hw_vpath_dynamic_rti_ci_set(hw_ring);
1588 }
1589 }
1590
1591 /* Enable CI for TTI */
1592 for (i = 0; i < vdev->no_of_vpath; i++) {
1593 struct __vxge_hw_fifo *hw_fifo = vdev->vpaths[i].fifo.handle;
1594 vxge_hw_vpath_tti_ci_set(hw_fifo);
1595 /*
1596 * For Inta (with or without napi), Set CI ON for only one
1597 * vpath. (Have only one free running timer).
1598 */
1599 if ((vdev->config.intr_type == INTA) && (i == 0))
1600 break;
1601 }
1602
1603 return;
1604}
1605
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001606static int do_vxge_reset(struct vxgedev *vdev, int event)
1607{
1608 enum vxge_hw_status status;
1609 int ret = 0, vp_id, i;
1610
1611 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1612
1613 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1614 /* check if device is down already */
1615 if (unlikely(!is_vxge_card_up(vdev)))
1616 return 0;
1617
1618 /* is reset already scheduled */
1619 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1620 return 0;
1621 }
1622
1623 if (event == VXGE_LL_FULL_RESET) {
Jon Mason2e41f642010-12-10 14:02:59 +00001624 netif_carrier_off(vdev->ndev);
1625
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001626 /* wait for all the vpath reset to complete */
1627 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1628 while (test_bit(vp_id, &vdev->vp_reset))
1629 msleep(50);
1630 }
1631
Jon Mason2e41f642010-12-10 14:02:59 +00001632 netif_carrier_on(vdev->ndev);
1633
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001634 /* if execution mode is set to debug, don't reset the adapter */
1635 if (unlikely(vdev->exec_mode)) {
1636 vxge_debug_init(VXGE_ERR,
1637 "%s: execution mode is debug, returning..",
1638 vdev->ndev->name);
Jon Mason7adf7d12010-07-15 08:47:24 +00001639 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1640 netif_tx_stop_all_queues(vdev->ndev);
1641 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001642 }
1643 }
1644
1645 if (event == VXGE_LL_FULL_RESET) {
Jon Mason4d2a5b42010-11-11 04:25:54 +00001646 vxge_hw_device_wait_receive_idle(vdev->devh);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001647 vxge_hw_device_intr_disable(vdev->devh);
1648
1649 switch (vdev->cric_err_event) {
1650 case VXGE_HW_EVENT_UNKNOWN:
Jon Masond03848e2010-07-15 08:47:23 +00001651 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001652 vxge_debug_init(VXGE_ERR,
1653 "fatal: %s: Disabling device due to"
1654 "unknown error",
1655 vdev->ndev->name);
1656 ret = -EPERM;
1657 goto out;
1658 case VXGE_HW_EVENT_RESET_START:
1659 break;
1660 case VXGE_HW_EVENT_RESET_COMPLETE:
1661 case VXGE_HW_EVENT_LINK_DOWN:
1662 case VXGE_HW_EVENT_LINK_UP:
1663 case VXGE_HW_EVENT_ALARM_CLEARED:
1664 case VXGE_HW_EVENT_ECCERR:
1665 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1666 ret = -EPERM;
1667 goto out;
1668 case VXGE_HW_EVENT_FIFO_ERR:
1669 case VXGE_HW_EVENT_VPATH_ERR:
1670 break;
1671 case VXGE_HW_EVENT_CRITICAL_ERR:
Jon Masond03848e2010-07-15 08:47:23 +00001672 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001673 vxge_debug_init(VXGE_ERR,
1674 "fatal: %s: Disabling device due to"
1675 "serious error",
1676 vdev->ndev->name);
1677 /* SOP or device reset required */
1678 /* This event is not currently used */
1679 ret = -EPERM;
1680 goto out;
1681 case VXGE_HW_EVENT_SERR:
Jon Masond03848e2010-07-15 08:47:23 +00001682 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001683 vxge_debug_init(VXGE_ERR,
1684 "fatal: %s: Disabling device due to"
1685 "serious error",
1686 vdev->ndev->name);
1687 ret = -EPERM;
1688 goto out;
1689 case VXGE_HW_EVENT_SRPCIM_SERR:
1690 case VXGE_HW_EVENT_MRPCIM_SERR:
1691 ret = -EPERM;
1692 goto out;
1693 case VXGE_HW_EVENT_SLOT_FREEZE:
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 "slot freeze",
1698 vdev->ndev->name);
1699 ret = -EPERM;
1700 goto out;
1701 default:
1702 break;
1703
1704 }
1705 }
1706
1707 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
Jon Masond03848e2010-07-15 08:47:23 +00001708 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001709
1710 if (event == VXGE_LL_FULL_RESET) {
1711 status = vxge_reset_all_vpaths(vdev);
1712 if (status != VXGE_HW_OK) {
1713 vxge_debug_init(VXGE_ERR,
1714 "fatal: %s: can not reset vpaths",
1715 vdev->ndev->name);
1716 ret = -EPERM;
1717 goto out;
1718 }
1719 }
1720
1721 if (event == VXGE_LL_COMPL_RESET) {
1722 for (i = 0; i < vdev->no_of_vpath; i++)
1723 if (vdev->vpaths[i].handle) {
1724 if (vxge_hw_vpath_recover_from_reset(
1725 vdev->vpaths[i].handle)
1726 != VXGE_HW_OK) {
1727 vxge_debug_init(VXGE_ERR,
1728 "vxge_hw_vpath_recover_"
1729 "from_reset failed for vpath: "
1730 "%d", i);
1731 ret = -EPERM;
1732 goto out;
1733 }
1734 } else {
1735 vxge_debug_init(VXGE_ERR,
1736 "vxge_hw_vpath_reset failed for "
1737 "vpath:%d", i);
1738 ret = -EPERM;
1739 goto out;
1740 }
1741 }
1742
1743 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1744 /* Reprogram the DA table with populated mac addresses */
1745 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1746 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1747 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1748 }
1749
1750 /* enable vpath interrupts */
1751 for (i = 0; i < vdev->no_of_vpath; i++)
1752 vxge_vpath_intr_enable(vdev, i);
1753
1754 vxge_hw_device_intr_enable(vdev->devh);
1755
1756 smp_wmb();
1757
1758 /* Indicate card up */
1759 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1760
1761 /* Get the traffic to flow through the vpaths */
1762 for (i = 0; i < vdev->no_of_vpath; i++) {
1763 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1764 smp_wmb();
1765 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1766 }
1767
Jon Masond03848e2010-07-15 08:47:23 +00001768 netif_tx_wake_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001769 }
1770
Jon Mason16fded72011-01-18 15:02:21 +00001771 /* configure CI */
1772 vxge_config_ci_for_tti_rti(vdev);
1773
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001774out:
1775 vxge_debug_entryexit(VXGE_TRACE,
1776 "%s:%d Exiting...", __func__, __LINE__);
1777
1778 /* Indicate reset done */
1779 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1780 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1781 return ret;
1782}
1783
1784/*
1785 * vxge_reset
1786 * @vdev: pointer to ll device
1787 *
1788 * driver may reset the chip on events of serr, eccerr, etc
1789 */
Jon Mason2e41f642010-12-10 14:02:59 +00001790static void vxge_reset(struct work_struct *work)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001791{
Jon Mason2e41f642010-12-10 14:02:59 +00001792 struct vxgedev *vdev = container_of(work, struct vxgedev, reset_task);
1793
1794 if (!netif_running(vdev->ndev))
1795 return;
1796
1797 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001798}
1799
1800/**
1801 * vxge_poll - Receive handler when Receive Polling is used.
1802 * @dev: pointer to the device structure.
1803 * @budget: Number of packets budgeted to be processed in this iteration.
1804 *
1805 * This function comes into picture only if Receive side is being handled
1806 * through polling (called NAPI in linux). It mostly does what the normal
1807 * Rx interrupt handler does in terms of descriptor and packet processing
1808 * but not in an interrupt context. Also it will process a specified number
1809 * of packets at most in one iteration. This value is passed down by the
1810 * kernel as the function argument 'budget'.
1811 */
1812static int vxge_poll_msix(struct napi_struct *napi, int budget)
1813{
Jon Mason16fded72011-01-18 15:02:21 +00001814 struct vxge_ring *ring = container_of(napi, struct vxge_ring, napi);
1815 int pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001816 int budget_org = budget;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001817
Jon Mason16fded72011-01-18 15:02:21 +00001818 ring->budget = budget;
1819 ring->pkts_processed = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001820 vxge_hw_vpath_poll_rx(ring->handle);
Jon Mason16fded72011-01-18 15:02:21 +00001821 pkts_processed = ring->pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001822
1823 if (ring->pkts_processed < budget_org) {
1824 napi_complete(napi);
Jon Mason16fded72011-01-18 15:02:21 +00001825
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001826 /* Re enable the Rx interrupts for the vpath */
1827 vxge_hw_channel_msix_unmask(
1828 (struct __vxge_hw_channel *)ring->handle,
1829 ring->rx_vector_no);
Jon Mason16fded72011-01-18 15:02:21 +00001830 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001831 }
1832
Jon Mason16fded72011-01-18 15:02:21 +00001833 /* We are copying and returning the local variable, in case if after
1834 * clearing the msix interrupt above, if the interrupt fires right
1835 * away which can preempt this NAPI thread */
1836 return pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001837}
1838
1839static int vxge_poll_inta(struct napi_struct *napi, int budget)
1840{
1841 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1842 int pkts_processed = 0;
1843 int i;
1844 int budget_org = budget;
1845 struct vxge_ring *ring;
1846
Joe Perchesd8ee7072010-11-15 10:13:58 +00001847 struct __vxge_hw_device *hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001848
1849 for (i = 0; i < vdev->no_of_vpath; i++) {
1850 ring = &vdev->vpaths[i].ring;
1851 ring->budget = budget;
Jon Mason16fded72011-01-18 15:02:21 +00001852 ring->pkts_processed = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001853 vxge_hw_vpath_poll_rx(ring->handle);
1854 pkts_processed += ring->pkts_processed;
1855 budget -= ring->pkts_processed;
1856 if (budget <= 0)
1857 break;
1858 }
1859
1860 VXGE_COMPLETE_ALL_TX(vdev);
1861
1862 if (pkts_processed < budget_org) {
1863 napi_complete(napi);
1864 /* Re enable the Rx interrupts for the ring */
1865 vxge_hw_device_unmask_all(hldev);
1866 vxge_hw_device_flush_io(hldev);
1867 }
1868
1869 return pkts_processed;
1870}
1871
1872#ifdef CONFIG_NET_POLL_CONTROLLER
1873/**
1874 * vxge_netpoll - netpoll event handler entry point
1875 * @dev : pointer to the device structure.
1876 * Description:
1877 * This function will be called by upper layer to check for events on the
1878 * interface in situations where interrupts are disabled. It is used for
1879 * specific in-kernel networking tasks, such as remote consoles and kernel
1880 * debugging over the network (example netdump in RedHat).
1881 */
1882static void vxge_netpoll(struct net_device *dev)
1883{
Jon Mason2c913082010-11-11 04:26:03 +00001884 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001885 struct vxgedev *vdev;
1886
Joe Perches5f54ceb2010-11-15 11:12:30 +00001887 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00001888 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001889
1890 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1891
1892 if (pci_channel_offline(vdev->pdev))
1893 return;
1894
1895 disable_irq(dev->irq);
1896 vxge_hw_device_clear_tx_rx(hldev);
1897
1898 vxge_hw_device_clear_tx_rx(hldev);
1899 VXGE_COMPLETE_ALL_RX(vdev);
1900 VXGE_COMPLETE_ALL_TX(vdev);
1901
1902 enable_irq(dev->irq);
1903
1904 vxge_debug_entryexit(VXGE_TRACE,
1905 "%s:%d Exiting...", __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001906}
1907#endif
1908
1909/* RTH configuration */
1910static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1911{
1912 enum vxge_hw_status status = VXGE_HW_OK;
1913 struct vxge_hw_rth_hash_types hash_types;
1914 u8 itable[256] = {0}; /* indirection table */
1915 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1916 int index;
1917
1918 /*
1919 * Filling
1920 * - itable with bucket numbers
1921 * - mtable with bucket-to-vpath mapping
1922 */
1923 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1924 itable[index] = index;
1925 mtable[index] = index % vdev->no_of_vpath;
1926 }
1927
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001928 /* set indirection table, bucket-to-vpath mapping */
1929 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1930 vdev->no_of_vpath,
1931 mtable, itable,
1932 vdev->config.rth_bkt_sz);
1933 if (status != VXGE_HW_OK) {
1934 vxge_debug_init(VXGE_ERR,
1935 "RTH indirection table configuration failed "
1936 "for vpath:%d", vdev->vpaths[0].device_id);
1937 return status;
1938 }
1939
Jon Mason47f01db2010-11-11 04:25:53 +00001940 /* Fill RTH hash types */
1941 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1942 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1943 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1944 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1945 hash_types.hash_type_tcpipv6ex_en =
1946 vdev->config.rth_hash_type_tcpipv6ex;
1947 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1948
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001949 /*
Jon Mason47f01db2010-11-11 04:25:53 +00001950 * Because the itable_set() method uses the active_table field
1951 * for the target virtual path the RTH config should be updated
1952 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1953 * when steering frames.
1954 */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001955 for (index = 0; index < vdev->no_of_vpath; index++) {
1956 status = vxge_hw_vpath_rts_rth_set(
1957 vdev->vpaths[index].handle,
1958 vdev->config.rth_algorithm,
1959 &hash_types,
1960 vdev->config.rth_bkt_sz);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001961 if (status != VXGE_HW_OK) {
1962 vxge_debug_init(VXGE_ERR,
1963 "RTH configuration failed for vpath:%d",
1964 vdev->vpaths[index].device_id);
1965 return status;
1966 }
1967 }
1968
1969 return status;
1970}
1971
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001972/* reset vpaths */
Jon Mason4d2a5b42010-11-11 04:25:54 +00001973enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001974{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001975 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00001976 struct vxge_vpath *vpath;
1977 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001978
Jon Mason7adf7d12010-07-15 08:47:24 +00001979 for (i = 0; i < vdev->no_of_vpath; i++) {
1980 vpath = &vdev->vpaths[i];
1981 if (vpath->handle) {
1982 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001983 if (is_vxge_card_up(vdev) &&
1984 vxge_hw_vpath_recover_from_reset(
Jon Mason7adf7d12010-07-15 08:47:24 +00001985 vpath->handle) != VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001986 vxge_debug_init(VXGE_ERR,
1987 "vxge_hw_vpath_recover_"
1988 "from_reset failed for vpath: "
1989 "%d", i);
1990 return status;
1991 }
1992 } else {
1993 vxge_debug_init(VXGE_ERR,
1994 "vxge_hw_vpath_reset failed for "
1995 "vpath:%d", i);
1996 return status;
1997 }
1998 }
Jon Mason7adf7d12010-07-15 08:47:24 +00001999 }
2000
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002001 return status;
2002}
2003
2004/* close vpaths */
stephen hemminger42821a52010-10-21 07:50:53 +00002005static void vxge_close_vpaths(struct vxgedev *vdev, int index)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002006{
Jon Mason7adf7d12010-07-15 08:47:24 +00002007 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002008 int i;
Jon Mason7adf7d12010-07-15 08:47:24 +00002009
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002010 for (i = index; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002011 vpath = &vdev->vpaths[i];
2012
2013 if (vpath->handle && vpath->is_open) {
2014 vxge_hw_vpath_close(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002015 vdev->stats.vpaths_open--;
2016 }
Jon Mason7adf7d12010-07-15 08:47:24 +00002017 vpath->is_open = 0;
2018 vpath->handle = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002019 }
2020}
2021
2022/* open vpaths */
stephen hemminger42821a52010-10-21 07:50:53 +00002023static int vxge_open_vpaths(struct vxgedev *vdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002024{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002025 struct vxge_hw_vpath_attr attr;
Jon Mason7adf7d12010-07-15 08:47:24 +00002026 enum vxge_hw_status status;
2027 struct vxge_vpath *vpath;
2028 u32 vp_id = 0;
2029 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002030
2031 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002032 vpath = &vdev->vpaths[i];
Jon Mason7adf7d12010-07-15 08:47:24 +00002033 vxge_assert(vpath->is_configured);
Jon Masone7935c92010-11-11 04:26:00 +00002034
2035 if (!vdev->titan1) {
2036 struct vxge_hw_vp_config *vcfg;
2037 vcfg = &vdev->devh->config.vp_config[vpath->device_id];
2038
2039 vcfg->rti.urange_a = RTI_T1A_RX_URANGE_A;
2040 vcfg->rti.urange_b = RTI_T1A_RX_URANGE_B;
2041 vcfg->rti.urange_c = RTI_T1A_RX_URANGE_C;
2042 vcfg->tti.uec_a = TTI_T1A_TX_UFC_A;
2043 vcfg->tti.uec_b = TTI_T1A_TX_UFC_B;
2044 vcfg->tti.uec_c = TTI_T1A_TX_UFC_C(vdev->mtu);
2045 vcfg->tti.uec_d = TTI_T1A_TX_UFC_D(vdev->mtu);
2046 vcfg->tti.ltimer_val = VXGE_T1A_TTI_LTIMER_VAL;
2047 vcfg->tti.rtimer_val = VXGE_T1A_TTI_RTIMER_VAL;
2048 }
2049
Jon Mason7adf7d12010-07-15 08:47:24 +00002050 attr.vp_id = vpath->device_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002051 attr.fifo_attr.callback = vxge_xmit_compl;
2052 attr.fifo_attr.txdl_term = vxge_tx_term;
2053 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
Jon Mason7adf7d12010-07-15 08:47:24 +00002054 attr.fifo_attr.userdata = &vpath->fifo;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002055
2056 attr.ring_attr.callback = vxge_rx_1b_compl;
2057 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2058 attr.ring_attr.rxd_term = vxge_rx_term;
2059 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
Jon Mason7adf7d12010-07-15 08:47:24 +00002060 attr.ring_attr.userdata = &vpath->ring;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002061
Jon Mason7adf7d12010-07-15 08:47:24 +00002062 vpath->ring.ndev = vdev->ndev;
2063 vpath->ring.pdev = vdev->pdev;
Jon Mason528f7272010-12-10 14:02:56 +00002064
Jon Mason7adf7d12010-07-15 08:47:24 +00002065 status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002066 if (status == VXGE_HW_OK) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002067 vpath->fifo.handle =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002068 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
Jon Mason7adf7d12010-07-15 08:47:24 +00002069 vpath->ring.handle =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002070 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
Jon Mason7adf7d12010-07-15 08:47:24 +00002071 vpath->fifo.tx_steering_type =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002072 vdev->config.tx_steering_type;
Jon Mason7adf7d12010-07-15 08:47:24 +00002073 vpath->fifo.ndev = vdev->ndev;
2074 vpath->fifo.pdev = vdev->pdev;
Jon Mason98f45da2010-07-15 08:47:25 +00002075 if (vdev->config.tx_steering_type)
2076 vpath->fifo.txq =
2077 netdev_get_tx_queue(vdev->ndev, i);
2078 else
2079 vpath->fifo.txq =
2080 netdev_get_tx_queue(vdev->ndev, 0);
Jon Mason7adf7d12010-07-15 08:47:24 +00002081 vpath->fifo.indicate_max_pkts =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002082 vdev->config.fifo_indicate_max_pkts;
Jon Mason16fded72011-01-18 15:02:21 +00002083 vpath->fifo.tx_vector_no = 0;
Jon Mason7adf7d12010-07-15 08:47:24 +00002084 vpath->ring.rx_vector_no = 0;
Jon Masonb81b3732010-11-11 04:25:58 +00002085 vpath->ring.rx_hwts = vdev->rx_hwts;
Jon Mason7adf7d12010-07-15 08:47:24 +00002086 vpath->is_open = 1;
2087 vdev->vp_handles[i] = vpath->handle;
Jon Mason7adf7d12010-07-15 08:47:24 +00002088 vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002089 vdev->stats.vpaths_open++;
2090 } else {
2091 vdev->stats.vpath_open_fail++;
Jon Mason528f7272010-12-10 14:02:56 +00002092 vxge_debug_init(VXGE_ERR, "%s: vpath: %d failed to "
2093 "open with status: %d",
2094 vdev->ndev->name, vpath->device_id,
2095 status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002096 vxge_close_vpaths(vdev, 0);
2097 return -EPERM;
2098 }
2099
Jon Mason7adf7d12010-07-15 08:47:24 +00002100 vp_id = vpath->handle->vpath->vp_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002101 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2102 }
Jon Mason528f7272010-12-10 14:02:56 +00002103
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002104 return VXGE_HW_OK;
2105}
2106
Jon Mason16fded72011-01-18 15:02:21 +00002107/**
2108 * adaptive_coalesce_tx_interrupts - Changes the interrupt coalescing
2109 * if the interrupts are not within a range
2110 * @fifo: pointer to transmit fifo structure
2111 * Description: The function changes boundary timer and restriction timer
2112 * value depends on the traffic
2113 * Return Value: None
2114 */
2115static void adaptive_coalesce_tx_interrupts(struct vxge_fifo *fifo)
2116{
2117 fifo->interrupt_count++;
2118 if (jiffies > fifo->jiffies + HZ / 100) {
2119 struct __vxge_hw_fifo *hw_fifo = fifo->handle;
2120
2121 fifo->jiffies = jiffies;
2122 if (fifo->interrupt_count > VXGE_T1A_MAX_TX_INTERRUPT_COUNT &&
2123 hw_fifo->rtimer != VXGE_TTI_RTIMER_ADAPT_VAL) {
2124 hw_fifo->rtimer = VXGE_TTI_RTIMER_ADAPT_VAL;
2125 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2126 } else if (hw_fifo->rtimer != 0) {
2127 hw_fifo->rtimer = 0;
2128 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2129 }
2130 fifo->interrupt_count = 0;
2131 }
2132}
2133
2134/**
2135 * adaptive_coalesce_rx_interrupts - Changes the interrupt coalescing
2136 * if the interrupts are not within a range
2137 * @ring: pointer to receive ring structure
2138 * Description: The function increases of decreases the packet counts within
2139 * the ranges of traffic utilization, if the interrupts due to this ring are
2140 * not within a fixed range.
2141 * Return Value: Nothing
2142 */
2143static void adaptive_coalesce_rx_interrupts(struct vxge_ring *ring)
2144{
2145 ring->interrupt_count++;
2146 if (jiffies > ring->jiffies + HZ / 100) {
2147 struct __vxge_hw_ring *hw_ring = ring->handle;
2148
2149 ring->jiffies = jiffies;
2150 if (ring->interrupt_count > VXGE_T1A_MAX_INTERRUPT_COUNT &&
2151 hw_ring->rtimer != VXGE_RTI_RTIMER_ADAPT_VAL) {
2152 hw_ring->rtimer = VXGE_RTI_RTIMER_ADAPT_VAL;
2153 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2154 } else if (hw_ring->rtimer != 0) {
2155 hw_ring->rtimer = 0;
2156 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2157 }
2158 ring->interrupt_count = 0;
2159 }
2160}
2161
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002162/*
2163 * vxge_isr_napi
2164 * @irq: the irq of the device.
2165 * @dev_id: a void pointer to the hldev structure of the Titan device
2166 * @ptregs: pointer to the registers pushed on the stack.
2167 *
2168 * This function is the ISR handler of the device when napi is enabled. It
2169 * identifies the reason for the interrupt and calls the relevant service
2170 * routines.
2171 */
2172static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2173{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002174 struct net_device *dev;
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002175 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002176 u64 reason;
2177 enum vxge_hw_status status;
Jon Mason2c913082010-11-11 04:26:03 +00002178 struct vxgedev *vdev = (struct vxgedev *)dev_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002179
2180 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2181
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002182 dev = vdev->ndev;
Joe Perchesd8ee7072010-11-15 10:13:58 +00002183 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002184
2185 if (pci_channel_offline(vdev->pdev))
2186 return IRQ_NONE;
2187
2188 if (unlikely(!is_vxge_card_up(vdev)))
Jon Mason4d2a5b42010-11-11 04:25:54 +00002189 return IRQ_HANDLED;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002190
Jon Mason528f7272010-12-10 14:02:56 +00002191 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, &reason);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002192 if (status == VXGE_HW_OK) {
2193 vxge_hw_device_mask_all(hldev);
2194
2195 if (reason &
2196 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2197 vdev->vpaths_deployed >>
2198 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2199
2200 vxge_hw_device_clear_tx_rx(hldev);
2201 napi_schedule(&vdev->napi);
2202 vxge_debug_intr(VXGE_TRACE,
2203 "%s:%d Exiting...", __func__, __LINE__);
2204 return IRQ_HANDLED;
2205 } else
2206 vxge_hw_device_unmask_all(hldev);
2207 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2208 (status == VXGE_HW_ERR_CRITICAL) ||
2209 (status == VXGE_HW_ERR_FIFO))) {
2210 vxge_hw_device_mask_all(hldev);
2211 vxge_hw_device_flush_io(hldev);
2212 return IRQ_HANDLED;
2213 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2214 return IRQ_HANDLED;
2215
2216 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2217 return IRQ_NONE;
2218}
2219
2220#ifdef CONFIG_PCI_MSI
2221
Jon Mason16fded72011-01-18 15:02:21 +00002222static irqreturn_t vxge_tx_msix_handle(int irq, void *dev_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002223{
2224 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2225
Jon Mason16fded72011-01-18 15:02:21 +00002226 adaptive_coalesce_tx_interrupts(fifo);
2227
2228 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)fifo->handle,
2229 fifo->tx_vector_no);
2230
2231 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)fifo->handle,
2232 fifo->tx_vector_no);
2233
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002234 VXGE_COMPLETE_VPATH_TX(fifo);
2235
Jon Mason16fded72011-01-18 15:02:21 +00002236 vxge_hw_channel_msix_unmask((struct __vxge_hw_channel *)fifo->handle,
2237 fifo->tx_vector_no);
2238
2239 mmiowb();
2240
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002241 return IRQ_HANDLED;
2242}
2243
Jon Mason16fded72011-01-18 15:02:21 +00002244static irqreturn_t vxge_rx_msix_napi_handle(int irq, void *dev_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002245{
2246 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2247
Jon Mason16fded72011-01-18 15:02:21 +00002248 adaptive_coalesce_rx_interrupts(ring);
2249
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002250 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
Jon Mason16fded72011-01-18 15:02:21 +00002251 ring->rx_vector_no);
2252
2253 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)ring->handle,
2254 ring->rx_vector_no);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002255
2256 napi_schedule(&ring->napi);
2257 return IRQ_HANDLED;
2258}
2259
2260static irqreturn_t
2261vxge_alarm_msix_handle(int irq, void *dev_id)
2262{
2263 int i;
2264 enum vxge_hw_status status;
2265 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2266 struct vxgedev *vdev = vpath->vdev;
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002267 int msix_id = (vpath->handle->vpath->vp_id *
2268 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002269
2270 for (i = 0; i < vdev->no_of_vpath; i++) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002271 /* Reduce the chance of losing alarm interrupts by masking
Jon Mason16fded72011-01-18 15:02:21 +00002272 * the vector. A pending bit will be set if an alarm is
2273 * generated and on unmask the interrupt will be fired.
2274 */
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002275 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
Jon Mason16fded72011-01-18 15:02:21 +00002276 vxge_hw_vpath_msix_clear(vdev->vpaths[i].handle, msix_id);
2277 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002278
2279 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2280 vdev->exec_mode);
2281 if (status == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002282 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
Jon Mason16fded72011-01-18 15:02:21 +00002283 msix_id);
2284 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002285 continue;
2286 }
2287 vxge_debug_intr(VXGE_ERR,
2288 "%s: vxge_hw_vpath_alarm_process failed %x ",
2289 VXGE_DRIVER_NAME, status);
2290 }
2291 return IRQ_HANDLED;
2292}
2293
2294static int vxge_alloc_msix(struct vxgedev *vdev)
2295{
2296 int j, i, ret = 0;
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002297 int msix_intr_vect = 0, temp;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002298 vdev->intr_cnt = 0;
2299
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002300start:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002301 /* Tx/Rx MSIX Vectors count */
2302 vdev->intr_cnt = vdev->no_of_vpath * 2;
2303
2304 /* Alarm MSIX Vectors count */
2305 vdev->intr_cnt++;
2306
Joe Perchesbaeb2ff2010-08-11 07:02:48 +00002307 vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
2308 GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002309 if (!vdev->entries) {
2310 vxge_debug_init(VXGE_ERR,
2311 "%s: memory allocation failed",
2312 VXGE_DRIVER_NAME);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002313 ret = -ENOMEM;
2314 goto alloc_entries_failed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002315 }
2316
Joe Perchesbaeb2ff2010-08-11 07:02:48 +00002317 vdev->vxge_entries = kcalloc(vdev->intr_cnt,
2318 sizeof(struct vxge_msix_entry),
2319 GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002320 if (!vdev->vxge_entries) {
2321 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2322 VXGE_DRIVER_NAME);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002323 ret = -ENOMEM;
2324 goto alloc_vxge_entries_failed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002325 }
2326
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002327 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002328
2329 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2330
2331 /* Initialize the fifo vector */
2332 vdev->entries[j].entry = msix_intr_vect;
2333 vdev->vxge_entries[j].entry = msix_intr_vect;
2334 vdev->vxge_entries[j].in_use = 0;
2335 j++;
2336
2337 /* Initialize the ring vector */
2338 vdev->entries[j].entry = msix_intr_vect + 1;
2339 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2340 vdev->vxge_entries[j].in_use = 0;
2341 j++;
2342 }
2343
2344 /* Initialize the alarm vector */
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002345 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2346 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002347 vdev->vxge_entries[j].in_use = 0;
2348
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002349 ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002350 if (ret > 0) {
2351 vxge_debug_init(VXGE_ERR,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002352 "%s: MSI-X enable failed for %d vectors, ret: %d",
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002353 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002354 if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) {
2355 ret = -ENODEV;
2356 goto enable_msix_failed;
2357 }
2358
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002359 kfree(vdev->entries);
2360 kfree(vdev->vxge_entries);
2361 vdev->entries = NULL;
2362 vdev->vxge_entries = NULL;
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002363 /* Try with less no of vector by reducing no of vpaths count */
2364 temp = (ret - 1)/2;
2365 vxge_close_vpaths(vdev, temp);
2366 vdev->no_of_vpath = temp;
2367 goto start;
Michal Schmidtcc413d92010-06-24 04:13:44 +00002368 } else if (ret < 0) {
2369 ret = -ENODEV;
2370 goto enable_msix_failed;
2371 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002372 return 0;
Michal Schmidtcc413d92010-06-24 04:13:44 +00002373
2374enable_msix_failed:
2375 kfree(vdev->vxge_entries);
2376alloc_vxge_entries_failed:
2377 kfree(vdev->entries);
2378alloc_entries_failed:
2379 return ret;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002380}
2381
2382static int vxge_enable_msix(struct vxgedev *vdev)
2383{
2384
2385 int i, ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002386 /* 0 - Tx, 1 - Rx */
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002387 int tim_msix_id[4] = {0, 1, 0, 0};
2388
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002389 vdev->intr_cnt = 0;
2390
2391 /* allocate msix vectors */
2392 ret = vxge_alloc_msix(vdev);
2393 if (!ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002394 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002395 struct vxge_vpath *vpath = &vdev->vpaths[i];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002396
Jon Mason7adf7d12010-07-15 08:47:24 +00002397 /* If fifo or ring are not enabled, the MSIX vector for
2398 * it should be set to 0.
2399 */
2400 vpath->ring.rx_vector_no = (vpath->device_id *
2401 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002402
Jon Mason16fded72011-01-18 15:02:21 +00002403 vpath->fifo.tx_vector_no = (vpath->device_id *
2404 VXGE_HW_VPATH_MSIX_ACTIVE);
2405
Jon Mason7adf7d12010-07-15 08:47:24 +00002406 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
2407 VXGE_ALARM_MSIX_ID);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002408 }
2409 }
2410
2411 return ret;
2412}
2413
2414static void vxge_rem_msix_isr(struct vxgedev *vdev)
2415{
2416 int intr_cnt;
2417
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002418 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002419 intr_cnt++) {
2420 if (vdev->vxge_entries[intr_cnt].in_use) {
2421 synchronize_irq(vdev->entries[intr_cnt].vector);
2422 free_irq(vdev->entries[intr_cnt].vector,
2423 vdev->vxge_entries[intr_cnt].arg);
2424 vdev->vxge_entries[intr_cnt].in_use = 0;
2425 }
2426 }
2427
2428 kfree(vdev->entries);
2429 kfree(vdev->vxge_entries);
2430 vdev->entries = NULL;
2431 vdev->vxge_entries = NULL;
2432
2433 if (vdev->config.intr_type == MSI_X)
2434 pci_disable_msix(vdev->pdev);
2435}
2436#endif
2437
2438static void vxge_rem_isr(struct vxgedev *vdev)
2439{
Jon Mason2c913082010-11-11 04:26:03 +00002440 struct __vxge_hw_device *hldev;
Joe Perchesd8ee7072010-11-15 10:13:58 +00002441 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002442
2443#ifdef CONFIG_PCI_MSI
2444 if (vdev->config.intr_type == MSI_X) {
2445 vxge_rem_msix_isr(vdev);
2446 } else
2447#endif
2448 if (vdev->config.intr_type == INTA) {
2449 synchronize_irq(vdev->pdev->irq);
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002450 free_irq(vdev->pdev->irq, vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002451 }
2452}
2453
2454static int vxge_add_isr(struct vxgedev *vdev)
2455{
2456 int ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002457#ifdef CONFIG_PCI_MSI
2458 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002459 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2460
2461 if (vdev->config.intr_type == MSI_X)
2462 ret = vxge_enable_msix(vdev);
2463
2464 if (ret) {
2465 vxge_debug_init(VXGE_ERR,
2466 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002467 vxge_debug_init(VXGE_ERR,
2468 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2469 vdev->config.intr_type = INTA;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002470 }
2471
2472 if (vdev->config.intr_type == MSI_X) {
2473 for (intr_idx = 0;
2474 intr_idx < (vdev->no_of_vpath *
2475 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2476
2477 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2478 irq_req = 0;
2479
2480 switch (msix_idx) {
2481 case 0:
2482 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002483 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2484 vdev->ndev->name,
2485 vdev->entries[intr_cnt].entry,
2486 pci_fun, vp_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002487 ret = request_irq(
2488 vdev->entries[intr_cnt].vector,
2489 vxge_tx_msix_handle, 0,
2490 vdev->desc[intr_cnt],
2491 &vdev->vpaths[vp_idx].fifo);
2492 vdev->vxge_entries[intr_cnt].arg =
2493 &vdev->vpaths[vp_idx].fifo;
2494 irq_req = 1;
2495 break;
2496 case 1:
2497 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002498 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2499 vdev->ndev->name,
2500 vdev->entries[intr_cnt].entry,
2501 pci_fun, vp_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002502 ret = request_irq(
2503 vdev->entries[intr_cnt].vector,
2504 vxge_rx_msix_napi_handle,
2505 0,
2506 vdev->desc[intr_cnt],
2507 &vdev->vpaths[vp_idx].ring);
2508 vdev->vxge_entries[intr_cnt].arg =
2509 &vdev->vpaths[vp_idx].ring;
2510 irq_req = 1;
2511 break;
2512 }
2513
2514 if (ret) {
2515 vxge_debug_init(VXGE_ERR,
2516 "%s: MSIX - %d Registration failed",
2517 vdev->ndev->name, intr_cnt);
2518 vxge_rem_msix_isr(vdev);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002519 vdev->config.intr_type = INTA;
2520 vxge_debug_init(VXGE_ERR,
2521 "%s: Defaulting to INTA"
2522 , vdev->ndev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002523 goto INTA_MODE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002524 }
2525
2526 if (irq_req) {
2527 /* We requested for this msix interrupt */
2528 vdev->vxge_entries[intr_cnt].in_use = 1;
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002529 msix_idx += vdev->vpaths[vp_idx].device_id *
2530 VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002531 vxge_hw_vpath_msix_unmask(
2532 vdev->vpaths[vp_idx].handle,
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002533 msix_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002534 intr_cnt++;
2535 }
2536
2537 /* Point to next vpath handler */
Joe Perches8e95a202009-12-03 07:58:21 +00002538 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2539 (vp_idx < (vdev->no_of_vpath - 1)))
2540 vp_idx++;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002541 }
2542
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002543 intr_cnt = vdev->no_of_vpath * 2;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002544 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002545 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2546 vdev->ndev->name,
2547 vdev->entries[intr_cnt].entry,
2548 pci_fun);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002549 /* For Alarm interrupts */
2550 ret = request_irq(vdev->entries[intr_cnt].vector,
2551 vxge_alarm_msix_handle, 0,
2552 vdev->desc[intr_cnt],
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002553 &vdev->vpaths[0]);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002554 if (ret) {
2555 vxge_debug_init(VXGE_ERR,
2556 "%s: MSIX - %d Registration failed",
2557 vdev->ndev->name, intr_cnt);
2558 vxge_rem_msix_isr(vdev);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002559 vdev->config.intr_type = INTA;
2560 vxge_debug_init(VXGE_ERR,
2561 "%s: Defaulting to INTA",
2562 vdev->ndev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002563 goto INTA_MODE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002564 }
2565
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002566 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2567 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002568 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002569 msix_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002570 vdev->vxge_entries[intr_cnt].in_use = 1;
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002571 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002572 }
2573INTA_MODE:
2574#endif
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002575
2576 if (vdev->config.intr_type == INTA) {
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002577 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2578 "%s:vxge:INTA", vdev->ndev->name);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002579 vxge_hw_device_set_intr_type(vdev->devh,
2580 VXGE_HW_INTR_MODE_IRQLINE);
Jon Mason16fded72011-01-18 15:02:21 +00002581
2582 vxge_hw_vpath_tti_ci_set(vdev->vpaths[0].fifo.handle);
2583
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002584 ret = request_irq((int) vdev->pdev->irq,
2585 vxge_isr_napi,
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002586 IRQF_SHARED, vdev->desc[0], vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002587 if (ret) {
2588 vxge_debug_init(VXGE_ERR,
2589 "%s %s-%d: ISR registration failed",
2590 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2591 return -ENODEV;
2592 }
2593 vxge_debug_init(VXGE_TRACE,
2594 "new %s-%d line allocated",
2595 "IRQ", vdev->pdev->irq);
2596 }
2597
2598 return VXGE_HW_OK;
2599}
2600
2601static void vxge_poll_vp_reset(unsigned long data)
2602{
2603 struct vxgedev *vdev = (struct vxgedev *)data;
2604 int i, j = 0;
2605
2606 for (i = 0; i < vdev->no_of_vpath; i++) {
2607 if (test_bit(i, &vdev->vp_reset)) {
2608 vxge_reset_vpath(vdev, i);
2609 j++;
2610 }
2611 }
2612 if (j && (vdev->config.intr_type != MSI_X)) {
2613 vxge_hw_device_unmask_all(vdev->devh);
2614 vxge_hw_device_flush_io(vdev->devh);
2615 }
2616
2617 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2618}
2619
2620static void vxge_poll_vp_lockup(unsigned long data)
2621{
2622 struct vxgedev *vdev = (struct vxgedev *)data;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002623 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00002624 struct vxge_vpath *vpath;
2625 struct vxge_ring *ring;
2626 int i;
stephen hemminger62ea0552011-06-20 10:35:07 +00002627 unsigned long rx_frms;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002628
2629 for (i = 0; i < vdev->no_of_vpath; i++) {
2630 ring = &vdev->vpaths[i].ring;
stephen hemminger62ea0552011-06-20 10:35:07 +00002631
2632 /* Truncated to machine word size number of frames */
2633 rx_frms = ACCESS_ONCE(ring->stats.rx_frms);
2634
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002635 /* Did this vpath received any packets */
stephen hemminger62ea0552011-06-20 10:35:07 +00002636 if (ring->stats.prev_rx_frms == rx_frms) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002637 status = vxge_hw_vpath_check_leak(ring->handle);
2638
2639 /* Did it received any packets last time */
2640 if ((VXGE_HW_FAIL == status) &&
2641 (VXGE_HW_FAIL == ring->last_status)) {
2642
2643 /* schedule vpath reset */
2644 if (!test_and_set_bit(i, &vdev->vp_reset)) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002645 vpath = &vdev->vpaths[i];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002646
2647 /* disable interrupts for this vpath */
2648 vxge_vpath_intr_disable(vdev, i);
2649
2650 /* stop the queue for this vpath */
Jon Mason98f45da2010-07-15 08:47:25 +00002651 netif_tx_stop_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002652 continue;
2653 }
2654 }
2655 }
stephen hemminger62ea0552011-06-20 10:35:07 +00002656 ring->stats.prev_rx_frms = rx_frms;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002657 ring->last_status = status;
2658 }
2659
2660 /* Check every 1 milli second */
2661 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2662}
2663
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002664static u32 vxge_fix_features(struct net_device *dev, u32 features)
2665{
2666 u32 changed = dev->features ^ features;
2667
2668 /* Enabling RTH requires some of the logic in vxge_device_register and a
2669 * vpath reset. Due to these restrictions, only allow modification
2670 * while the interface is down.
2671 */
2672 if ((changed & NETIF_F_RXHASH) && netif_running(dev))
2673 features ^= NETIF_F_RXHASH;
2674
2675 return features;
2676}
2677
2678static int vxge_set_features(struct net_device *dev, u32 features)
2679{
2680 struct vxgedev *vdev = netdev_priv(dev);
2681 u32 changed = dev->features ^ features;
2682
2683 if (!(changed & NETIF_F_RXHASH))
2684 return 0;
2685
2686 /* !netif_running() ensured by vxge_fix_features() */
2687
2688 vdev->devh->config.rth_en = !!(features & NETIF_F_RXHASH);
2689 if (vxge_reset_all_vpaths(vdev) != VXGE_HW_OK) {
2690 dev->features = features ^ NETIF_F_RXHASH;
2691 vdev->devh->config.rth_en = !!(dev->features & NETIF_F_RXHASH);
2692 return -EIO;
2693 }
2694
2695 return 0;
2696}
2697
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002698/**
2699 * vxge_open
2700 * @dev: pointer to the device structure.
2701 *
2702 * This function is the open entry point of the driver. It mainly calls a
2703 * function to allocate Rx buffers and inserts them into the buffer
2704 * descriptors and then enables the Rx part of the NIC.
2705 * Return value: '0' on success and an appropriate (-)ve integer as
2706 * defined in errno.h file on failure.
2707 */
Jon Mason528f7272010-12-10 14:02:56 +00002708static int vxge_open(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002709{
2710 enum vxge_hw_status status;
2711 struct vxgedev *vdev;
2712 struct __vxge_hw_device *hldev;
Jon Mason7adf7d12010-07-15 08:47:24 +00002713 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002714 int ret = 0;
2715 int i;
2716 u64 val64, function_mode;
Jon Mason528f7272010-12-10 14:02:56 +00002717
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002718 vxge_debug_entryexit(VXGE_TRACE,
2719 "%s: %s:%d", dev->name, __func__, __LINE__);
2720
Joe Perches5f54ceb2010-11-15 11:12:30 +00002721 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00002722 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002723 function_mode = vdev->config.device_hw_info.function_mode;
2724
2725 /* make sure you have link off by default every time Nic is
2726 * initialized */
2727 netif_carrier_off(dev);
2728
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002729 /* Open VPATHs */
2730 status = vxge_open_vpaths(vdev);
2731 if (status != VXGE_HW_OK) {
2732 vxge_debug_init(VXGE_ERR,
2733 "%s: fatal: Vpath open failed", vdev->ndev->name);
2734 ret = -EPERM;
2735 goto out0;
2736 }
2737
2738 vdev->mtu = dev->mtu;
2739
2740 status = vxge_add_isr(vdev);
2741 if (status != VXGE_HW_OK) {
2742 vxge_debug_init(VXGE_ERR,
2743 "%s: fatal: ISR add failed", dev->name);
2744 ret = -EPERM;
2745 goto out1;
2746 }
2747
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002748 if (vdev->config.intr_type != MSI_X) {
2749 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2750 vdev->config.napi_weight);
2751 napi_enable(&vdev->napi);
Jon Mason7adf7d12010-07-15 08:47:24 +00002752 for (i = 0; i < vdev->no_of_vpath; i++) {
2753 vpath = &vdev->vpaths[i];
2754 vpath->ring.napi_p = &vdev->napi;
2755 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002756 } else {
2757 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002758 vpath = &vdev->vpaths[i];
2759 netif_napi_add(dev, &vpath->ring.napi,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002760 vxge_poll_msix, vdev->config.napi_weight);
Jon Mason7adf7d12010-07-15 08:47:24 +00002761 napi_enable(&vpath->ring.napi);
2762 vpath->ring.napi_p = &vpath->ring.napi;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002763 }
2764 }
2765
2766 /* configure RTH */
2767 if (vdev->config.rth_steering) {
2768 status = vxge_rth_configure(vdev);
2769 if (status != VXGE_HW_OK) {
2770 vxge_debug_init(VXGE_ERR,
2771 "%s: fatal: RTH configuration failed",
2772 dev->name);
2773 ret = -EPERM;
2774 goto out2;
2775 }
2776 }
Jon Mason47f01db2010-11-11 04:25:53 +00002777 printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name,
2778 hldev->config.rth_en ? "enabled" : "disabled");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002779
2780 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002781 vpath = &vdev->vpaths[i];
2782
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002783 /* set initial mtu before enabling the device */
Jon Mason7adf7d12010-07-15 08:47:24 +00002784 status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002785 if (status != VXGE_HW_OK) {
2786 vxge_debug_init(VXGE_ERR,
2787 "%s: fatal: can not set new MTU", dev->name);
2788 ret = -EPERM;
2789 goto out2;
2790 }
2791 }
2792
2793 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2794 vxge_debug_init(vdev->level_trace,
2795 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2796 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2797
Jon Mason7adf7d12010-07-15 08:47:24 +00002798 /* Restore the DA, VID table and also multicast and promiscuous mode
2799 * states
2800 */
2801 if (vdev->all_multi_flg) {
2802 for (i = 0; i < vdev->no_of_vpath; i++) {
2803 vpath = &vdev->vpaths[i];
2804 vxge_restore_vpath_mac_addr(vpath);
2805 vxge_restore_vpath_vid_table(vpath);
2806
2807 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2808 if (status != VXGE_HW_OK)
2809 vxge_debug_init(VXGE_ERR,
2810 "%s:%d Enabling multicast failed",
2811 __func__, __LINE__);
2812 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002813 }
2814
2815 /* Enable vpath to sniff all unicast/multicast traffic that not
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002816 * addressed to them. We allow promiscuous mode for PF only
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002817 */
2818
2819 val64 = 0;
2820 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2821 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2822
2823 vxge_hw_mgmt_reg_write(vdev->devh,
2824 vxge_hw_mgmt_reg_type_mrpcim,
2825 0,
2826 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2827 rxmac_authorize_all_addr),
2828 val64);
2829
2830 vxge_hw_mgmt_reg_write(vdev->devh,
2831 vxge_hw_mgmt_reg_type_mrpcim,
2832 0,
2833 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2834 rxmac_authorize_all_vid),
2835 val64);
2836
2837 vxge_set_multicast(dev);
2838
2839 /* Enabling Bcast and mcast for all vpath */
2840 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002841 vpath = &vdev->vpaths[i];
2842 status = vxge_hw_vpath_bcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002843 if (status != VXGE_HW_OK)
2844 vxge_debug_init(VXGE_ERR,
2845 "%s : Can not enable bcast for vpath "
2846 "id %d", dev->name, i);
2847 if (vdev->config.addr_learn_en) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002848 status = vxge_hw_vpath_mcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002849 if (status != VXGE_HW_OK)
2850 vxge_debug_init(VXGE_ERR,
2851 "%s : Can not enable mcast for vpath "
2852 "id %d", dev->name, i);
2853 }
2854 }
2855
2856 vxge_hw_device_setpause_data(vdev->devh, 0,
2857 vdev->config.tx_pause_enable,
2858 vdev->config.rx_pause_enable);
2859
2860 if (vdev->vp_reset_timer.function == NULL)
2861 vxge_os_timer(vdev->vp_reset_timer,
2862 vxge_poll_vp_reset, vdev, (HZ/2));
2863
Jon Masone7935c92010-11-11 04:26:00 +00002864 /* There is no need to check for RxD leak and RxD lookup on Titan1A */
2865 if (vdev->titan1 && vdev->vp_lockup_timer.function == NULL)
2866 vxge_os_timer(vdev->vp_lockup_timer, vxge_poll_vp_lockup, vdev,
2867 HZ / 2);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002868
2869 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2870
2871 smp_wmb();
2872
2873 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2874 netif_carrier_on(vdev->ndev);
Joe Perches75f5e1c2010-07-27 11:47:03 +00002875 netdev_notice(vdev->ndev, "Link Up\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002876 vdev->stats.link_up++;
2877 }
2878
2879 vxge_hw_device_intr_enable(vdev->devh);
2880
2881 smp_wmb();
2882
2883 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002884 vpath = &vdev->vpaths[i];
2885
2886 vxge_hw_vpath_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002887 smp_wmb();
Jon Mason7adf7d12010-07-15 08:47:24 +00002888 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002889 }
2890
Jon Masond03848e2010-07-15 08:47:23 +00002891 netif_tx_start_all_queues(vdev->ndev);
Jon Mason16fded72011-01-18 15:02:21 +00002892
2893 /* configure CI */
2894 vxge_config_ci_for_tti_rti(vdev);
2895
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002896 goto out0;
2897
2898out2:
2899 vxge_rem_isr(vdev);
2900
2901 /* Disable napi */
2902 if (vdev->config.intr_type != MSI_X)
2903 napi_disable(&vdev->napi);
2904 else {
2905 for (i = 0; i < vdev->no_of_vpath; i++)
2906 napi_disable(&vdev->vpaths[i].ring.napi);
2907 }
2908
2909out1:
2910 vxge_close_vpaths(vdev, 0);
2911out0:
2912 vxge_debug_entryexit(VXGE_TRACE,
2913 "%s: %s:%d Exiting...",
2914 dev->name, __func__, __LINE__);
2915 return ret;
2916}
2917
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002918/* Loop through the mac address list and delete all the entries */
stephen hemminger42821a52010-10-21 07:50:53 +00002919static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002920{
2921
2922 struct list_head *entry, *next;
2923 if (list_empty(&vpath->mac_addr_list))
2924 return;
2925
2926 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2927 list_del(entry);
2928 kfree((struct vxge_mac_addrs *)entry);
2929 }
2930}
2931
2932static void vxge_napi_del_all(struct vxgedev *vdev)
2933{
2934 int i;
2935 if (vdev->config.intr_type != MSI_X)
2936 netif_napi_del(&vdev->napi);
2937 else {
2938 for (i = 0; i < vdev->no_of_vpath; i++)
2939 netif_napi_del(&vdev->vpaths[i].ring.napi);
2940 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002941}
2942
stephen hemminger42821a52010-10-21 07:50:53 +00002943static int do_vxge_close(struct net_device *dev, int do_io)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002944{
2945 enum vxge_hw_status status;
2946 struct vxgedev *vdev;
2947 struct __vxge_hw_device *hldev;
2948 int i;
2949 u64 val64, vpath_vector;
2950 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2951 dev->name, __func__, __LINE__);
2952
Joe Perches5f54ceb2010-11-15 11:12:30 +00002953 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00002954 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002955
Sreenivasa Honnurbd9ee682009-07-01 21:14:03 +00002956 if (unlikely(!is_vxge_card_up(vdev)))
2957 return 0;
2958
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002959 /* If vxge_handle_crit_err task is executing,
2960 * wait till it completes. */
2961 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2962 msleep(50);
2963
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002964 if (do_io) {
2965 /* Put the vpath back in normal mode */
2966 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2967 status = vxge_hw_mgmt_reg_read(vdev->devh,
2968 vxge_hw_mgmt_reg_type_mrpcim,
2969 0,
2970 (ulong)offsetof(
2971 struct vxge_hw_mrpcim_reg,
2972 rts_mgr_cbasin_cfg),
2973 &val64);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002974 if (status == VXGE_HW_OK) {
2975 val64 &= ~vpath_vector;
2976 status = vxge_hw_mgmt_reg_write(vdev->devh,
2977 vxge_hw_mgmt_reg_type_mrpcim,
2978 0,
2979 (ulong)offsetof(
2980 struct vxge_hw_mrpcim_reg,
2981 rts_mgr_cbasin_cfg),
2982 val64);
2983 }
2984
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002985 /* Remove the function 0 from promiscuous mode */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002986 vxge_hw_mgmt_reg_write(vdev->devh,
2987 vxge_hw_mgmt_reg_type_mrpcim,
2988 0,
2989 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2990 rxmac_authorize_all_addr),
2991 0);
2992
2993 vxge_hw_mgmt_reg_write(vdev->devh,
2994 vxge_hw_mgmt_reg_type_mrpcim,
2995 0,
2996 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2997 rxmac_authorize_all_vid),
2998 0);
2999
3000 smp_wmb();
3001 }
Jon Masone7935c92010-11-11 04:26:00 +00003002
3003 if (vdev->titan1)
3004 del_timer_sync(&vdev->vp_lockup_timer);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003005
3006 del_timer_sync(&vdev->vp_reset_timer);
3007
Jon Mason4d2a5b42010-11-11 04:25:54 +00003008 if (do_io)
3009 vxge_hw_device_wait_receive_idle(hldev);
3010
3011 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3012
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003013 /* Disable napi */
3014 if (vdev->config.intr_type != MSI_X)
3015 napi_disable(&vdev->napi);
3016 else {
3017 for (i = 0; i < vdev->no_of_vpath; i++)
3018 napi_disable(&vdev->vpaths[i].ring.napi);
3019 }
3020
3021 netif_carrier_off(vdev->ndev);
Joe Perches75f5e1c2010-07-27 11:47:03 +00003022 netdev_notice(vdev->ndev, "Link Down\n");
Jon Masond03848e2010-07-15 08:47:23 +00003023 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003024
3025 /* Note that at this point xmit() is stopped by upper layer */
3026 if (do_io)
3027 vxge_hw_device_intr_disable(vdev->devh);
3028
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003029 vxge_rem_isr(vdev);
3030
3031 vxge_napi_del_all(vdev);
3032
3033 if (do_io)
3034 vxge_reset_all_vpaths(vdev);
3035
3036 vxge_close_vpaths(vdev, 0);
3037
3038 vxge_debug_entryexit(VXGE_TRACE,
3039 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
3040
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003041 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
3042
3043 return 0;
3044}
3045
3046/**
3047 * vxge_close
3048 * @dev: device pointer.
3049 *
3050 * This is the stop entry point of the driver. It needs to undo exactly
3051 * whatever was done by the open entry point, thus it's usually referred to
3052 * as the close function.Among other things this function mainly stops the
3053 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
3054 * Return value: '0' on success and an appropriate (-)ve integer as
3055 * defined in errno.h file on failure.
3056 */
Jon Mason528f7272010-12-10 14:02:56 +00003057static int vxge_close(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003058{
3059 do_vxge_close(dev, 1);
3060 return 0;
3061}
3062
3063/**
3064 * vxge_change_mtu
3065 * @dev: net device pointer.
3066 * @new_mtu :the new MTU size for the device.
3067 *
3068 * A driver entry point to change MTU size for the device. Before changing
3069 * the MTU the device must be stopped.
3070 */
3071static int vxge_change_mtu(struct net_device *dev, int new_mtu)
3072{
3073 struct vxgedev *vdev = netdev_priv(dev);
3074
3075 vxge_debug_entryexit(vdev->level_trace,
3076 "%s:%d", __func__, __LINE__);
3077 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
3078 vxge_debug_init(vdev->level_err,
3079 "%s: mtu size is invalid", dev->name);
3080 return -EPERM;
3081 }
3082
3083 /* check if device is down already */
3084 if (unlikely(!is_vxge_card_up(vdev))) {
3085 /* just store new value, will use later on open() */
3086 dev->mtu = new_mtu;
3087 vxge_debug_init(vdev->level_err,
3088 "%s", "device is down on MTU change");
3089 return 0;
3090 }
3091
3092 vxge_debug_init(vdev->level_trace,
3093 "trying to apply new MTU %d", new_mtu);
3094
3095 if (vxge_close(dev))
3096 return -EIO;
3097
3098 dev->mtu = new_mtu;
3099 vdev->mtu = new_mtu;
3100
3101 if (vxge_open(dev))
3102 return -EIO;
3103
3104 vxge_debug_init(vdev->level_trace,
3105 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
3106
3107 vxge_debug_entryexit(vdev->level_trace,
3108 "%s:%d Exiting...", __func__, __LINE__);
3109
3110 return 0;
3111}
3112
3113/**
Eric Dumazetdd57f972010-08-18 03:42:54 +00003114 * vxge_get_stats64
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003115 * @dev: pointer to the device structure
Eric Dumazetdd57f972010-08-18 03:42:54 +00003116 * @stats: pointer to struct rtnl_link_stats64
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003117 *
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003118 */
Eric Dumazetdd57f972010-08-18 03:42:54 +00003119static struct rtnl_link_stats64 *
3120vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003121{
Eric Dumazetdd57f972010-08-18 03:42:54 +00003122 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003123 int k;
3124
Eric Dumazetdd57f972010-08-18 03:42:54 +00003125 /* net_stats already zeroed by caller */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003126 for (k = 0; k < vdev->no_of_vpath; k++) {
stephen hemminger62ea0552011-06-20 10:35:07 +00003127 struct vxge_ring_stats *rxstats = &vdev->vpaths[k].ring.stats;
3128 struct vxge_fifo_stats *txstats = &vdev->vpaths[k].fifo.stats;
3129 unsigned int start;
3130 u64 packets, bytes, multicast;
3131
3132 do {
3133 start = u64_stats_fetch_begin(&rxstats->syncp);
3134
3135 packets = rxstats->rx_frms;
3136 multicast = rxstats->rx_mcast;
3137 bytes = rxstats->rx_bytes;
3138 } while (u64_stats_fetch_retry(&rxstats->syncp, start));
3139
3140 net_stats->rx_packets += packets;
3141 net_stats->rx_bytes += bytes;
3142 net_stats->multicast += multicast;
3143
3144 net_stats->rx_errors += rxstats->rx_errors;
3145 net_stats->rx_dropped += rxstats->rx_dropped;
3146
3147 do {
3148 start = u64_stats_fetch_begin(&txstats->syncp);
3149
3150 packets = txstats->tx_frms;
3151 bytes = txstats->tx_bytes;
3152 } while (u64_stats_fetch_retry(&txstats->syncp, start));
3153
3154 net_stats->tx_packets += packets;
3155 net_stats->tx_bytes += bytes;
3156 net_stats->tx_errors += txstats->tx_errors;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003157 }
3158
3159 return net_stats;
3160}
3161
Jon Masoncd883a72011-04-08 11:11:21 +00003162static enum vxge_hw_status vxge_timestamp_config(struct __vxge_hw_device *devh)
Jon Masonb81b3732010-11-11 04:25:58 +00003163{
3164 enum vxge_hw_status status;
3165 u64 val64;
3166
3167 /* Timestamp is passed to the driver via the FCS, therefore we
3168 * must disable the FCS stripping by the adapter. Since this is
3169 * required for the driver to load (due to a hardware bug),
3170 * there is no need to do anything special here.
3171 */
Jon Masoncd883a72011-04-08 11:11:21 +00003172 val64 = VXGE_HW_XMAC_TIMESTAMP_EN |
3173 VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
3174 VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
Jon Masonb81b3732010-11-11 04:25:58 +00003175
Jon Masoncd883a72011-04-08 11:11:21 +00003176 status = vxge_hw_mgmt_reg_write(devh,
Jon Masonb81b3732010-11-11 04:25:58 +00003177 vxge_hw_mgmt_reg_type_mrpcim,
3178 0,
3179 offsetof(struct vxge_hw_mrpcim_reg,
3180 xmac_timestamp),
3181 val64);
Jon Masoncd883a72011-04-08 11:11:21 +00003182 vxge_hw_device_flush_io(devh);
3183 devh->config.hwts_en = VXGE_HW_HWTS_ENABLE;
Jon Masonb81b3732010-11-11 04:25:58 +00003184 return status;
3185}
3186
3187static int vxge_hwtstamp_ioctl(struct vxgedev *vdev, void __user *data)
3188{
3189 struct hwtstamp_config config;
Jon Masonb81b3732010-11-11 04:25:58 +00003190 int i;
3191
3192 if (copy_from_user(&config, data, sizeof(config)))
3193 return -EFAULT;
3194
3195 /* reserved for future extensions */
3196 if (config.flags)
3197 return -EINVAL;
3198
3199 /* Transmit HW Timestamp not supported */
3200 switch (config.tx_type) {
3201 case HWTSTAMP_TX_OFF:
3202 break;
3203 case HWTSTAMP_TX_ON:
3204 default:
3205 return -ERANGE;
3206 }
3207
3208 switch (config.rx_filter) {
3209 case HWTSTAMP_FILTER_NONE:
Jon Masonb81b3732010-11-11 04:25:58 +00003210 vdev->rx_hwts = 0;
3211 config.rx_filter = HWTSTAMP_FILTER_NONE;
3212 break;
3213
3214 case HWTSTAMP_FILTER_ALL:
3215 case HWTSTAMP_FILTER_SOME:
3216 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3217 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3218 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3219 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3220 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3221 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3222 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3223 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3224 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3225 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3226 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3227 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
Jon Masoncd883a72011-04-08 11:11:21 +00003228 if (vdev->devh->config.hwts_en != VXGE_HW_HWTS_ENABLE)
Jon Masonb81b3732010-11-11 04:25:58 +00003229 return -EFAULT;
3230
3231 vdev->rx_hwts = 1;
3232 config.rx_filter = HWTSTAMP_FILTER_ALL;
3233 break;
3234
3235 default:
3236 return -ERANGE;
3237 }
3238
3239 for (i = 0; i < vdev->no_of_vpath; i++)
3240 vdev->vpaths[i].ring.rx_hwts = vdev->rx_hwts;
3241
3242 if (copy_to_user(data, &config, sizeof(config)))
3243 return -EFAULT;
3244
3245 return 0;
3246}
3247
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003248/**
3249 * vxge_ioctl
3250 * @dev: Device pointer.
3251 * @ifr: An IOCTL specific structure, that can contain a pointer to
3252 * a proprietary structure used to pass information to the driver.
3253 * @cmd: This is used to distinguish between the different commands that
3254 * can be passed to the IOCTL functions.
3255 *
3256 * Entry point for the Ioctl.
3257 */
3258static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3259{
Jon Masonb81b3732010-11-11 04:25:58 +00003260 struct vxgedev *vdev = netdev_priv(dev);
3261 int ret;
3262
3263 switch (cmd) {
3264 case SIOCSHWTSTAMP:
3265 ret = vxge_hwtstamp_ioctl(vdev, rq->ifr_data);
3266 if (ret)
3267 return ret;
3268 break;
3269 default:
3270 return -EOPNOTSUPP;
3271 }
3272
3273 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003274}
3275
3276/**
3277 * vxge_tx_watchdog
3278 * @dev: pointer to net device structure
3279 *
3280 * Watchdog for transmit side.
3281 * This function is triggered if the Tx Queue is stopped
3282 * for a pre-defined amount of time when the Interface is still up.
3283 */
Jon Mason2e41f642010-12-10 14:02:59 +00003284static void vxge_tx_watchdog(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003285{
3286 struct vxgedev *vdev;
3287
3288 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3289
Joe Perches5f54ceb2010-11-15 11:12:30 +00003290 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003291
3292 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3293
Jon Mason2e41f642010-12-10 14:02:59 +00003294 schedule_work(&vdev->reset_task);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003295 vxge_debug_entryexit(VXGE_TRACE,
3296 "%s:%d Exiting...", __func__, __LINE__);
3297}
3298
3299/**
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003300 * vxge_vlan_rx_add_vid
3301 * @dev: net device pointer.
3302 * @vid: vid
3303 *
3304 * Add the vlan id to the devices vlan id table
3305 */
3306static void
3307vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3308{
Jiri Pirko53515732011-07-20 04:54:40 +00003309 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003310 struct vxge_vpath *vpath;
3311 int vp_id;
3312
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003313 /* Add these vlan to the vid table */
3314 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3315 vpath = &vdev->vpaths[vp_id];
3316 if (!vpath->is_open)
3317 continue;
3318 vxge_hw_vpath_vid_add(vpath->handle, vid);
3319 }
Jiri Pirko53515732011-07-20 04:54:40 +00003320 set_bit(vid, vdev->active_vlans);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003321}
3322
3323/**
3324 * vxge_vlan_rx_add_vid
3325 * @dev: net device pointer.
3326 * @vid: vid
3327 *
3328 * Remove the vlan id from the device's vlan id table
3329 */
3330static void
3331vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3332{
Jiri Pirko53515732011-07-20 04:54:40 +00003333 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003334 struct vxge_vpath *vpath;
3335 int vp_id;
3336
3337 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3338
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003339 /* Delete this vlan from the vid table */
3340 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3341 vpath = &vdev->vpaths[vp_id];
3342 if (!vpath->is_open)
3343 continue;
3344 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3345 }
3346 vxge_debug_entryexit(VXGE_TRACE,
3347 "%s:%d Exiting...", __func__, __LINE__);
Jiri Pirko53515732011-07-20 04:54:40 +00003348 clear_bit(vid, vdev->active_vlans);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003349}
3350
3351static const struct net_device_ops vxge_netdev_ops = {
3352 .ndo_open = vxge_open,
3353 .ndo_stop = vxge_close,
Eric Dumazetdd57f972010-08-18 03:42:54 +00003354 .ndo_get_stats64 = vxge_get_stats64,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003355 .ndo_start_xmit = vxge_xmit,
3356 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003357 .ndo_set_rx_mode = vxge_set_multicast,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003358 .ndo_do_ioctl = vxge_ioctl,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003359 .ndo_set_mac_address = vxge_set_mac_addr,
3360 .ndo_change_mtu = vxge_change_mtu,
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003361 .ndo_fix_features = vxge_fix_features,
3362 .ndo_set_features = vxge_set_features,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003363 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3364 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003365 .ndo_tx_timeout = vxge_tx_watchdog,
3366#ifdef CONFIG_NET_POLL_CONTROLLER
3367 .ndo_poll_controller = vxge_netpoll,
3368#endif
3369};
3370
stephen hemminger42821a52010-10-21 07:50:53 +00003371static int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3372 struct vxge_config *config,
3373 int high_dma, int no_of_vpath,
3374 struct vxgedev **vdev_out)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003375{
3376 struct net_device *ndev;
3377 enum vxge_hw_status status = VXGE_HW_OK;
3378 struct vxgedev *vdev;
Jon Mason98f45da2010-07-15 08:47:25 +00003379 int ret = 0, no_of_queue = 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003380 u64 stat;
3381
3382 *vdev_out = NULL;
Jon Masond03848e2010-07-15 08:47:23 +00003383 if (config->tx_steering_type)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003384 no_of_queue = no_of_vpath;
3385
3386 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3387 no_of_queue);
3388 if (ndev == NULL) {
3389 vxge_debug_init(
3390 vxge_hw_device_trace_level_get(hldev),
3391 "%s : device allocation failed", __func__);
3392 ret = -ENODEV;
3393 goto _out0;
3394 }
3395
3396 vxge_debug_entryexit(
3397 vxge_hw_device_trace_level_get(hldev),
3398 "%s: %s:%d Entering...",
3399 ndev->name, __func__, __LINE__);
3400
3401 vdev = netdev_priv(ndev);
3402 memset(vdev, 0, sizeof(struct vxgedev));
3403
3404 vdev->ndev = ndev;
3405 vdev->devh = hldev;
3406 vdev->pdev = hldev->pdev;
3407 memcpy(&vdev->config, config, sizeof(struct vxge_config));
Jon Masonb81b3732010-11-11 04:25:58 +00003408 vdev->rx_hwts = 0;
Sergei Shtylyovff938e42011-02-28 11:57:33 -08003409 vdev->titan1 = (vdev->pdev->revision == VXGE_HW_TITAN1_PCI_REVISION);
Jon Masone7935c92010-11-11 04:26:00 +00003410
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003411 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3412
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003413 ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_SG |
3414 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3415 NETIF_F_TSO | NETIF_F_TSO6 |
3416 NETIF_F_HW_VLAN_TX;
3417 if (vdev->config.rth_steering != NO_STEERING)
3418 ndev->hw_features |= NETIF_F_RXHASH;
3419
3420 ndev->features |= ndev->hw_features |
3421 NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;
3422
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003423 /* Driver entry points */
3424 ndev->irq = vdev->pdev->irq;
3425 ndev->base_addr = (unsigned long) hldev->bar0;
3426
3427 ndev->netdev_ops = &vxge_netdev_ops;
3428
3429 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
Jon Mason2e41f642010-12-10 14:02:59 +00003430 INIT_WORK(&vdev->reset_task, vxge_reset);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003431
stephen hemminger42821a52010-10-21 07:50:53 +00003432 vxge_initialize_ethtool_ops(ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003433
3434 /* Allocate memory for vpath */
3435 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3436 no_of_vpath, GFP_KERNEL);
3437 if (!vdev->vpaths) {
3438 vxge_debug_init(VXGE_ERR,
3439 "%s: vpath memory allocation failed",
3440 vdev->ndev->name);
Jon Mason6cca2002011-01-18 15:02:19 +00003441 ret = -ENOMEM;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003442 goto _out1;
3443 }
3444
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003445 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3446 "%s : checksuming enabled", __func__);
3447
3448 if (high_dma) {
3449 ndev->features |= NETIF_F_HIGHDMA;
3450 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3451 "%s : using High DMA", __func__);
3452 }
3453
Jon Mason6cca2002011-01-18 15:02:19 +00003454 ret = register_netdev(ndev);
3455 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003456 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3457 "%s: %s : device registration failed!",
3458 ndev->name, __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003459 goto _out2;
3460 }
3461
3462 /* Set the factory defined MAC address initially */
3463 ndev->addr_len = ETH_ALEN;
3464
3465 /* Make Link state as off at this point, when the Link change
3466 * interrupt comes the state will be automatically changed to
3467 * the right state.
3468 */
3469 netif_carrier_off(ndev);
3470
3471 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3472 "%s: Ethernet device registered",
3473 ndev->name);
3474
Jon Masone8ac1752010-11-11 04:25:57 +00003475 hldev->ndev = ndev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003476 *vdev_out = vdev;
3477
3478 /* Resetting the Device stats */
3479 status = vxge_hw_mrpcim_stats_access(
3480 hldev,
3481 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3482 0,
3483 0,
3484 &stat);
3485
3486 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3487 vxge_debug_init(
3488 vxge_hw_device_trace_level_get(hldev),
3489 "%s: device stats clear returns"
3490 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3491
3492 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3493 "%s: %s:%d Exiting...",
3494 ndev->name, __func__, __LINE__);
3495
3496 return ret;
3497_out2:
3498 kfree(vdev->vpaths);
3499_out1:
3500 free_netdev(ndev);
3501_out0:
3502 return ret;
3503}
3504
3505/*
3506 * vxge_device_unregister
3507 *
3508 * This function will unregister and free network device
3509 */
Jon Mason2c913082010-11-11 04:26:03 +00003510static void vxge_device_unregister(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003511{
3512 struct vxgedev *vdev;
3513 struct net_device *dev;
3514 char buf[IFNAMSIZ];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003515
3516 dev = hldev->ndev;
3517 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003518
Jon Mason2c913082010-11-11 04:26:03 +00003519 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d", vdev->ndev->name,
3520 __func__, __LINE__);
3521
Jon Masonead5d232010-11-29 18:02:46 +00003522 strncpy(buf, dev->name, IFNAMSIZ);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003523
Tejun Heoba27d852010-12-15 04:03:29 +00003524 flush_work_sync(&vdev->reset_task);
3525
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003526 /* in 2.6 will call stop() if device is up */
3527 unregister_netdev(dev);
3528
Jon Mason6cca2002011-01-18 15:02:19 +00003529 kfree(vdev->vpaths);
3530
3531 /* we are safe to free it now */
3532 free_netdev(dev);
3533
Jon Mason2c913082010-11-11 04:26:03 +00003534 vxge_debug_init(vdev->level_trace, "%s: ethernet device unregistered",
3535 buf);
3536 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d Exiting...", buf,
3537 __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003538}
3539
3540/*
3541 * vxge_callback_crit_err
3542 *
3543 * This function is called by the alarm handler in interrupt context.
3544 * Driver must analyze it based on the event type.
3545 */
3546static void
3547vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3548 enum vxge_hw_event type, u64 vp_id)
3549{
3550 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +00003551 struct vxgedev *vdev = netdev_priv(dev);
Jon Mason98f45da2010-07-15 08:47:25 +00003552 struct vxge_vpath *vpath = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003553 int vpath_idx;
3554
3555 vxge_debug_entryexit(vdev->level_trace,
3556 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3557
3558 /* Note: This event type should be used for device wide
3559 * indications only - Serious errors, Slot freeze and critical errors
3560 */
3561 vdev->cric_err_event = type;
3562
Jon Mason98f45da2010-07-15 08:47:25 +00003563 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
3564 vpath = &vdev->vpaths[vpath_idx];
3565 if (vpath->device_id == vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003566 break;
Jon Mason98f45da2010-07-15 08:47:25 +00003567 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003568
3569 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3570 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3571 vxge_debug_init(VXGE_ERR,
3572 "%s: Slot is frozen", vdev->ndev->name);
3573 } else if (type == VXGE_HW_EVENT_SERR) {
3574 vxge_debug_init(VXGE_ERR,
3575 "%s: Encountered Serious Error",
3576 vdev->ndev->name);
3577 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3578 vxge_debug_init(VXGE_ERR,
3579 "%s: Encountered Critical Error",
3580 vdev->ndev->name);
3581 }
3582
3583 if ((type == VXGE_HW_EVENT_SERR) ||
3584 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3585 if (unlikely(vdev->exec_mode))
3586 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3587 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3588 vxge_hw_device_mask_all(hldev);
3589 if (unlikely(vdev->exec_mode))
3590 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3591 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3592 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3593
3594 if (unlikely(vdev->exec_mode))
3595 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3596 else {
3597 /* check if this vpath is already set for reset */
3598 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3599
3600 /* disable interrupts for this vpath */
3601 vxge_vpath_intr_disable(vdev, vpath_idx);
3602
3603 /* stop the queue for this vpath */
Jon Mason98f45da2010-07-15 08:47:25 +00003604 netif_tx_stop_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003605 }
3606 }
3607 }
3608
3609 vxge_debug_entryexit(vdev->level_trace,
3610 "%s: %s:%d Exiting...",
3611 vdev->ndev->name, __func__, __LINE__);
3612}
3613
3614static void verify_bandwidth(void)
3615{
3616 int i, band_width, total = 0, equal_priority = 0;
3617
3618 /* 1. If user enters 0 for some fifo, give equal priority to all */
3619 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3620 if (bw_percentage[i] == 0) {
3621 equal_priority = 1;
3622 break;
3623 }
3624 }
3625
3626 if (!equal_priority) {
3627 /* 2. If sum exceeds 100, give equal priority to all */
3628 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3629 if (bw_percentage[i] == 0xFF)
3630 break;
3631
3632 total += bw_percentage[i];
3633 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3634 equal_priority = 1;
3635 break;
3636 }
3637 }
3638 }
3639
3640 if (!equal_priority) {
3641 /* Is all the bandwidth consumed? */
3642 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3643 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3644 /* Split rest of bw equally among next VPs*/
3645 band_width =
3646 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3647 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3648 if (band_width < 2) /* min of 2% */
3649 equal_priority = 1;
3650 else {
3651 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3652 i++)
3653 bw_percentage[i] =
3654 band_width;
3655 }
3656 }
3657 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3658 equal_priority = 1;
3659 }
3660
3661 if (equal_priority) {
3662 vxge_debug_init(VXGE_ERR,
3663 "%s: Assigning equal bandwidth to all the vpaths",
3664 VXGE_DRIVER_NAME);
3665 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3666 VXGE_HW_MAX_VIRTUAL_PATHS;
3667 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3668 bw_percentage[i] = bw_percentage[0];
3669 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003670}
3671
3672/*
3673 * Vpath configuration
3674 */
3675static int __devinit vxge_config_vpaths(
3676 struct vxge_hw_device_config *device_config,
3677 u64 vpath_mask, struct vxge_config *config_param)
3678{
3679 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3680 u32 txdl_size, txdl_per_memblock;
3681
3682 temp = driver_config->vpath_per_dev;
3683 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3684 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3685 /* No more CPU. Return vpath number as zero.*/
3686 if (driver_config->g_no_cpus == -1)
3687 return 0;
3688
3689 if (!driver_config->g_no_cpus)
3690 driver_config->g_no_cpus = num_online_cpus();
3691
3692 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3693 if (!driver_config->vpath_per_dev)
3694 driver_config->vpath_per_dev = 1;
3695
3696 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3697 if (!vxge_bVALn(vpath_mask, i, 1))
3698 continue;
3699 else
3700 default_no_vpath++;
3701 if (default_no_vpath < driver_config->vpath_per_dev)
3702 driver_config->vpath_per_dev = default_no_vpath;
3703
3704 driver_config->g_no_cpus = driver_config->g_no_cpus -
3705 (driver_config->vpath_per_dev * 2);
3706 if (driver_config->g_no_cpus <= 0)
3707 driver_config->g_no_cpus = -1;
3708 }
3709
3710 if (driver_config->vpath_per_dev == 1) {
3711 vxge_debug_ll_config(VXGE_TRACE,
3712 "%s: Disable tx and rx steering, "
3713 "as single vpath is configured", VXGE_DRIVER_NAME);
3714 config_param->rth_steering = NO_STEERING;
3715 config_param->tx_steering_type = NO_STEERING;
3716 device_config->rth_en = 0;
3717 }
3718
3719 /* configure bandwidth */
3720 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3721 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3722
3723 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3724 device_config->vp_config[i].vp_id = i;
3725 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3726 if (no_of_vpaths < driver_config->vpath_per_dev) {
3727 if (!vxge_bVALn(vpath_mask, i, 1)) {
3728 vxge_debug_ll_config(VXGE_TRACE,
3729 "%s: vpath: %d is not available",
3730 VXGE_DRIVER_NAME, i);
3731 continue;
3732 } else {
3733 vxge_debug_ll_config(VXGE_TRACE,
3734 "%s: vpath: %d available",
3735 VXGE_DRIVER_NAME, i);
3736 no_of_vpaths++;
3737 }
3738 } else {
3739 vxge_debug_ll_config(VXGE_TRACE,
3740 "%s: vpath: %d is not configured, "
3741 "max_config_vpath exceeded",
3742 VXGE_DRIVER_NAME, i);
3743 break;
3744 }
3745
3746 /* Configure Tx fifo's */
3747 device_config->vp_config[i].fifo.enable =
3748 VXGE_HW_FIFO_ENABLE;
3749 device_config->vp_config[i].fifo.max_frags =
Sreenivasa Honnur5beefb42009-10-28 02:46:54 -07003750 MAX_SKB_FRAGS + 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003751 device_config->vp_config[i].fifo.memblock_size =
3752 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3753
Sreenivasa Honnur5beefb42009-10-28 02:46:54 -07003754 txdl_size = device_config->vp_config[i].fifo.max_frags *
3755 sizeof(struct vxge_hw_fifo_txd);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003756 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3757
3758 device_config->vp_config[i].fifo.fifo_blocks =
3759 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3760
3761 device_config->vp_config[i].fifo.intr =
3762 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3763
3764 /* Configure tti properties */
3765 device_config->vp_config[i].tti.intr_enable =
3766 VXGE_HW_TIM_INTR_ENABLE;
3767
3768 device_config->vp_config[i].tti.btimer_val =
3769 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3770
3771 device_config->vp_config[i].tti.timer_ac_en =
3772 VXGE_HW_TIM_TIMER_AC_ENABLE;
3773
Jon Mason528f7272010-12-10 14:02:56 +00003774 /* For msi-x with napi (each vector has a handler of its own) -
3775 * Set CI to OFF for all vpaths
3776 */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003777 device_config->vp_config[i].tti.timer_ci_en =
3778 VXGE_HW_TIM_TIMER_CI_DISABLE;
3779
3780 device_config->vp_config[i].tti.timer_ri_en =
3781 VXGE_HW_TIM_TIMER_RI_DISABLE;
3782
3783 device_config->vp_config[i].tti.util_sel =
3784 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3785
3786 device_config->vp_config[i].tti.ltimer_val =
3787 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3788
3789 device_config->vp_config[i].tti.rtimer_val =
3790 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3791
3792 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3793 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3794 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3795 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3796 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3797 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3798 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3799
3800 /* Configure Rx rings */
3801 device_config->vp_config[i].ring.enable =
3802 VXGE_HW_RING_ENABLE;
3803
3804 device_config->vp_config[i].ring.ring_blocks =
3805 VXGE_HW_DEF_RING_BLOCKS;
Jon Mason528f7272010-12-10 14:02:56 +00003806
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003807 device_config->vp_config[i].ring.buffer_mode =
3808 VXGE_HW_RING_RXD_BUFFER_MODE_1;
Jon Mason528f7272010-12-10 14:02:56 +00003809
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003810 device_config->vp_config[i].ring.rxds_limit =
3811 VXGE_HW_DEF_RING_RXDS_LIMIT;
Jon Mason528f7272010-12-10 14:02:56 +00003812
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003813 device_config->vp_config[i].ring.scatter_mode =
3814 VXGE_HW_RING_SCATTER_MODE_A;
3815
3816 /* Configure rti properties */
3817 device_config->vp_config[i].rti.intr_enable =
3818 VXGE_HW_TIM_INTR_ENABLE;
3819
3820 device_config->vp_config[i].rti.btimer_val =
3821 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3822
3823 device_config->vp_config[i].rti.timer_ac_en =
3824 VXGE_HW_TIM_TIMER_AC_ENABLE;
3825
3826 device_config->vp_config[i].rti.timer_ci_en =
3827 VXGE_HW_TIM_TIMER_CI_DISABLE;
3828
3829 device_config->vp_config[i].rti.timer_ri_en =
3830 VXGE_HW_TIM_TIMER_RI_DISABLE;
3831
3832 device_config->vp_config[i].rti.util_sel =
3833 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3834
3835 device_config->vp_config[i].rti.urange_a =
3836 RTI_RX_URANGE_A;
3837 device_config->vp_config[i].rti.urange_b =
3838 RTI_RX_URANGE_B;
3839 device_config->vp_config[i].rti.urange_c =
3840 RTI_RX_URANGE_C;
3841 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3842 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3843 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3844 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3845
3846 device_config->vp_config[i].rti.rtimer_val =
3847 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3848
3849 device_config->vp_config[i].rti.ltimer_val =
3850 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3851
3852 device_config->vp_config[i].rpa_strip_vlan_tag =
3853 vlan_tag_strip;
3854 }
3855
3856 driver_config->vpath_per_dev = temp;
3857 return no_of_vpaths;
3858}
3859
3860/* initialize device configuratrions */
3861static void __devinit vxge_device_config_init(
3862 struct vxge_hw_device_config *device_config,
3863 int *intr_type)
3864{
3865 /* Used for CQRQ/SRQ. */
3866 device_config->dma_blockpool_initial =
3867 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3868
3869 device_config->dma_blockpool_max =
3870 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3871
3872 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3873 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3874
3875#ifndef CONFIG_PCI_MSI
3876 vxge_debug_init(VXGE_ERR,
3877 "%s: This Kernel does not support "
3878 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3879 *intr_type = INTA;
3880#endif
3881
3882 /* Configure whether MSI-X or IRQL. */
3883 switch (*intr_type) {
3884 case INTA:
3885 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3886 break;
3887
3888 case MSI_X:
Jon Mason16fded72011-01-18 15:02:21 +00003889 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX_ONE_SHOT;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003890 break;
3891 }
Jon Mason528f7272010-12-10 14:02:56 +00003892
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003893 /* Timer period between device poll */
3894 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3895
3896 /* Configure mac based steering. */
3897 device_config->rts_mac_en = addr_learn_en;
3898
3899 /* Configure Vpaths */
3900 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3901
3902 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3903 __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003904 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3905 device_config->intr_mode);
3906 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3907 device_config->device_poll_millis);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003908 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3909 device_config->rth_en);
3910 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3911 device_config->rth_it_type);
3912}
3913
3914static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3915{
3916 int i;
3917
3918 vxge_debug_init(VXGE_TRACE,
3919 "%s: %d Vpath(s) opened",
3920 vdev->ndev->name, vdev->no_of_vpath);
3921
3922 switch (vdev->config.intr_type) {
3923 case INTA:
3924 vxge_debug_init(VXGE_TRACE,
3925 "%s: Interrupt type INTA", vdev->ndev->name);
3926 break;
3927
3928 case MSI_X:
3929 vxge_debug_init(VXGE_TRACE,
3930 "%s: Interrupt type MSI-X", vdev->ndev->name);
3931 break;
3932 }
3933
3934 if (vdev->config.rth_steering) {
3935 vxge_debug_init(VXGE_TRACE,
3936 "%s: RTH steering enabled for TCP_IPV4",
3937 vdev->ndev->name);
3938 } else {
3939 vxge_debug_init(VXGE_TRACE,
3940 "%s: RTH steering disabled", vdev->ndev->name);
3941 }
3942
3943 switch (vdev->config.tx_steering_type) {
3944 case NO_STEERING:
3945 vxge_debug_init(VXGE_TRACE,
3946 "%s: Tx steering disabled", vdev->ndev->name);
3947 break;
3948 case TX_PRIORITY_STEERING:
3949 vxge_debug_init(VXGE_TRACE,
3950 "%s: Unsupported tx steering option",
3951 vdev->ndev->name);
3952 vxge_debug_init(VXGE_TRACE,
3953 "%s: Tx steering disabled", vdev->ndev->name);
3954 vdev->config.tx_steering_type = 0;
3955 break;
3956 case TX_VLAN_STEERING:
3957 vxge_debug_init(VXGE_TRACE,
3958 "%s: Unsupported tx steering option",
3959 vdev->ndev->name);
3960 vxge_debug_init(VXGE_TRACE,
3961 "%s: Tx steering disabled", vdev->ndev->name);
3962 vdev->config.tx_steering_type = 0;
3963 break;
3964 case TX_MULTIQ_STEERING:
3965 vxge_debug_init(VXGE_TRACE,
3966 "%s: Tx multiqueue steering enabled",
3967 vdev->ndev->name);
3968 break;
3969 case TX_PORT_STEERING:
3970 vxge_debug_init(VXGE_TRACE,
3971 "%s: Tx port steering enabled",
3972 vdev->ndev->name);
3973 break;
3974 default:
3975 vxge_debug_init(VXGE_ERR,
3976 "%s: Unsupported tx steering type",
3977 vdev->ndev->name);
3978 vxge_debug_init(VXGE_TRACE,
3979 "%s: Tx steering disabled", vdev->ndev->name);
3980 vdev->config.tx_steering_type = 0;
3981 }
3982
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003983 if (vdev->config.addr_learn_en)
3984 vxge_debug_init(VXGE_TRACE,
3985 "%s: MAC Address learning enabled", vdev->ndev->name);
3986
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003987 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3988 if (!vxge_bVALn(vpath_mask, i, 1))
3989 continue;
3990 vxge_debug_ll_config(VXGE_TRACE,
3991 "%s: MTU size - %d", vdev->ndev->name,
3992 ((struct __vxge_hw_device *)(vdev->devh))->
3993 config.vp_config[i].mtu);
3994 vxge_debug_init(VXGE_TRACE,
3995 "%s: VLAN tag stripping %s", vdev->ndev->name,
3996 ((struct __vxge_hw_device *)(vdev->devh))->
3997 config.vp_config[i].rpa_strip_vlan_tag
3998 ? "Enabled" : "Disabled");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003999 vxge_debug_ll_config(VXGE_TRACE,
4000 "%s: Max frags : %d", vdev->ndev->name,
4001 ((struct __vxge_hw_device *)(vdev->devh))->
4002 config.vp_config[i].fifo.max_frags);
4003 break;
4004 }
4005}
4006
4007#ifdef CONFIG_PM
4008/**
4009 * vxge_pm_suspend - vxge power management suspend entry point
4010 *
4011 */
4012static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
4013{
4014 return -ENOSYS;
4015}
4016/**
4017 * vxge_pm_resume - vxge power management resume entry point
4018 *
4019 */
4020static int vxge_pm_resume(struct pci_dev *pdev)
4021{
4022 return -ENOSYS;
4023}
4024
4025#endif
4026
4027/**
4028 * vxge_io_error_detected - called when PCI error is detected
4029 * @pdev: Pointer to PCI device
4030 * @state: The current pci connection state
4031 *
4032 * This function is called after a PCI bus error affecting
4033 * this device has been detected.
4034 */
4035static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
4036 pci_channel_state_t state)
4037{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004038 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004039 struct net_device *netdev = hldev->ndev;
4040
4041 netif_device_detach(netdev);
4042
Dean Nelsone33b9922009-07-31 09:14:03 +00004043 if (state == pci_channel_io_perm_failure)
4044 return PCI_ERS_RESULT_DISCONNECT;
4045
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004046 if (netif_running(netdev)) {
4047 /* Bring down the card, while avoiding PCI I/O */
4048 do_vxge_close(netdev, 0);
4049 }
4050
4051 pci_disable_device(pdev);
4052
4053 return PCI_ERS_RESULT_NEED_RESET;
4054}
4055
4056/**
4057 * vxge_io_slot_reset - called after the pci bus has been reset.
4058 * @pdev: Pointer to PCI device
4059 *
4060 * Restart the card from scratch, as if from a cold-boot.
4061 * At this point, the card has exprienced a hard reset,
4062 * followed by fixups by BIOS, and has its config space
4063 * set up identically to what it was at cold boot.
4064 */
4065static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
4066{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004067 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004068 struct net_device *netdev = hldev->ndev;
4069
4070 struct vxgedev *vdev = netdev_priv(netdev);
4071
4072 if (pci_enable_device(pdev)) {
Joe Perches75f5e1c2010-07-27 11:47:03 +00004073 netdev_err(netdev, "Cannot re-enable device after reset\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004074 return PCI_ERS_RESULT_DISCONNECT;
4075 }
4076
4077 pci_set_master(pdev);
Jon Mason528f7272010-12-10 14:02:56 +00004078 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004079
4080 return PCI_ERS_RESULT_RECOVERED;
4081}
4082
4083/**
4084 * vxge_io_resume - called when traffic can start flowing again.
4085 * @pdev: Pointer to PCI device
4086 *
4087 * This callback is called when the error recovery driver tells
4088 * us that its OK to resume normal operation.
4089 */
4090static void vxge_io_resume(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 if (netif_running(netdev)) {
4096 if (vxge_open(netdev)) {
Joe Perches75f5e1c2010-07-27 11:47:03 +00004097 netdev_err(netdev,
4098 "Can't bring device back up after reset\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004099 return;
4100 }
4101 }
4102
4103 netif_device_attach(netdev);
4104}
4105
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004106static inline u32 vxge_get_num_vfs(u64 function_mode)
4107{
4108 u32 num_functions = 0;
4109
4110 switch (function_mode) {
4111 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4112 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
4113 num_functions = 8;
4114 break;
4115 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4116 num_functions = 1;
4117 break;
4118 case VXGE_HW_FUNCTION_MODE_SRIOV:
4119 case VXGE_HW_FUNCTION_MODE_MRIOV:
4120 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
4121 num_functions = 17;
4122 break;
4123 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
4124 num_functions = 4;
4125 break;
4126 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
4127 num_functions = 2;
4128 break;
4129 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
4130 num_functions = 8; /* TODO */
4131 break;
4132 }
4133 return num_functions;
4134}
4135
Jon Masone8ac1752010-11-11 04:25:57 +00004136int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override)
4137{
4138 struct __vxge_hw_device *hldev = vdev->devh;
4139 u32 maj, min, bld, cmaj, cmin, cbld;
4140 enum vxge_hw_status status;
4141 const struct firmware *fw;
4142 int ret;
4143
4144 ret = request_firmware(&fw, fw_name, &vdev->pdev->dev);
4145 if (ret) {
4146 vxge_debug_init(VXGE_ERR, "%s: Firmware file '%s' not found",
4147 VXGE_DRIVER_NAME, fw_name);
4148 goto out;
4149 }
4150
4151 /* Load the new firmware onto the adapter */
4152 status = vxge_update_fw_image(hldev, fw->data, fw->size);
4153 if (status != VXGE_HW_OK) {
4154 vxge_debug_init(VXGE_ERR,
4155 "%s: FW image download to adapter failed '%s'.",
4156 VXGE_DRIVER_NAME, fw_name);
4157 ret = -EIO;
4158 goto out;
4159 }
4160
4161 /* Read the version of the new firmware */
4162 status = vxge_hw_upgrade_read_version(hldev, &maj, &min, &bld);
4163 if (status != VXGE_HW_OK) {
4164 vxge_debug_init(VXGE_ERR,
4165 "%s: Upgrade read version failed '%s'.",
4166 VXGE_DRIVER_NAME, fw_name);
4167 ret = -EIO;
4168 goto out;
4169 }
4170
4171 cmaj = vdev->config.device_hw_info.fw_version.major;
4172 cmin = vdev->config.device_hw_info.fw_version.minor;
4173 cbld = vdev->config.device_hw_info.fw_version.build;
4174 /* It's possible the version in /lib/firmware is not the latest version.
4175 * If so, we could get into a loop of trying to upgrade to the latest
4176 * and flashing the older version.
4177 */
4178 if (VXGE_FW_VER(maj, min, bld) == VXGE_FW_VER(cmaj, cmin, cbld) &&
4179 !override) {
4180 ret = -EINVAL;
4181 goto out;
4182 }
4183
4184 printk(KERN_NOTICE "Upgrade to firmware version %d.%d.%d commencing\n",
4185 maj, min, bld);
4186
4187 /* Flash the adapter with the new firmware */
4188 status = vxge_hw_flash_fw(hldev);
4189 if (status != VXGE_HW_OK) {
4190 vxge_debug_init(VXGE_ERR, "%s: Upgrade commit failed '%s'.",
4191 VXGE_DRIVER_NAME, fw_name);
4192 ret = -EIO;
4193 goto out;
4194 }
4195
4196 printk(KERN_NOTICE "Upgrade of firmware successful! Adapter must be "
4197 "hard reset before using, thus requiring a system reboot or a "
4198 "hotplug event.\n");
4199
4200out:
Jesper Juhle84f8852011-01-13 10:25:20 +00004201 release_firmware(fw);
Jon Masone8ac1752010-11-11 04:25:57 +00004202 return ret;
4203}
4204
4205static int vxge_probe_fw_update(struct vxgedev *vdev)
4206{
4207 u32 maj, min, bld;
4208 int ret, gpxe = 0;
4209 char *fw_name;
4210
4211 maj = vdev->config.device_hw_info.fw_version.major;
4212 min = vdev->config.device_hw_info.fw_version.minor;
4213 bld = vdev->config.device_hw_info.fw_version.build;
4214
4215 if (VXGE_FW_VER(maj, min, bld) == VXGE_CERT_FW_VER)
4216 return 0;
4217
4218 /* Ignore the build number when determining if the current firmware is
4219 * "too new" to load the driver
4220 */
4221 if (VXGE_FW_VER(maj, min, 0) > VXGE_CERT_FW_VER) {
4222 vxge_debug_init(VXGE_ERR, "%s: Firmware newer than last known "
4223 "version, unable to load driver\n",
4224 VXGE_DRIVER_NAME);
4225 return -EINVAL;
4226 }
4227
4228 /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
4229 * work with this driver.
4230 */
4231 if (VXGE_FW_VER(maj, min, bld) <= VXGE_FW_DEAD_VER) {
4232 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d cannot be "
4233 "upgraded\n", VXGE_DRIVER_NAME, maj, min, bld);
4234 return -EINVAL;
4235 }
4236
4237 /* If file not specified, determine gPXE or not */
4238 if (VXGE_FW_VER(maj, min, bld) >= VXGE_EPROM_FW_VER) {
4239 int i;
4240 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++)
4241 if (vdev->devh->eprom_versions[i]) {
4242 gpxe = 1;
4243 break;
4244 }
4245 }
4246 if (gpxe)
4247 fw_name = "vxge/X3fw-pxe.ncf";
4248 else
4249 fw_name = "vxge/X3fw.ncf";
4250
4251 ret = vxge_fw_upgrade(vdev, fw_name, 0);
4252 /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
4253 * probe, so ignore them
4254 */
4255 if (ret != -EINVAL && ret != -ENOENT)
4256 return -EIO;
4257 else
4258 ret = 0;
4259
4260 if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR, VXGE_CERT_FW_VER_MINOR, 0) >
4261 VXGE_FW_VER(maj, min, 0)) {
4262 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d is too old to"
4263 " be used with this driver.\n"
4264 "Please get the latest version from "
4265 "ftp://ftp.s2io.com/pub/X3100-Drivers/FIRMWARE",
4266 VXGE_DRIVER_NAME, maj, min, bld);
4267 return -EINVAL;
4268 }
4269
4270 return ret;
4271}
4272
Jon Masonc92bf702010-12-10 14:02:57 +00004273static int __devinit is_sriov_initialized(struct pci_dev *pdev)
4274{
4275 int pos;
4276 u16 ctrl;
4277
4278 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4279 if (pos) {
4280 pci_read_config_word(pdev, pos + PCI_SRIOV_CTRL, &ctrl);
4281 if (ctrl & PCI_SRIOV_CTRL_VFE)
4282 return 1;
4283 }
4284 return 0;
4285}
4286
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004287/**
4288 * vxge_probe
4289 * @pdev : structure containing the PCI related information of the device.
4290 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4291 * Description:
4292 * This function is called when a new PCI device gets detected and initializes
4293 * it.
4294 * Return value:
4295 * returns 0 on success and negative on failure.
4296 *
4297 */
4298static int __devinit
4299vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4300{
Jon Mason2c913082010-11-11 04:26:03 +00004301 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004302 enum vxge_hw_status status;
4303 int ret;
4304 int high_dma = 0;
4305 u64 vpath_mask = 0;
4306 struct vxgedev *vdev;
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004307 struct vxge_config *ll_config = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004308 struct vxge_hw_device_config *device_config = NULL;
4309 struct vxge_hw_device_attr attr;
4310 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4311 u8 *macaddr;
4312 struct vxge_mac_addrs *entry;
4313 static int bus = -1, device = -1;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004314 u32 host_type;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004315 u8 new_device = 0;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004316 enum vxge_hw_status is_privileged;
4317 u32 function_mode;
4318 u32 num_vfs = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004319
4320 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4321 attr.pdev = pdev;
4322
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004323 /* In SRIOV-17 mode, functions of the same adapter
Jon Mason528f7272010-12-10 14:02:56 +00004324 * can be deployed on different buses
4325 */
4326 if (((bus != pdev->bus->number) || (device != PCI_SLOT(pdev->devfn))) &&
4327 !pdev->is_virtfn)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004328 new_device = 1;
4329
4330 bus = pdev->bus->number;
4331 device = PCI_SLOT(pdev->devfn);
4332
4333 if (new_device) {
4334 if (driver_config->config_dev_cnt &&
4335 (driver_config->config_dev_cnt !=
4336 driver_config->total_dev_cnt))
4337 vxge_debug_init(VXGE_ERR,
4338 "%s: Configured %d of %d devices",
4339 VXGE_DRIVER_NAME,
4340 driver_config->config_dev_cnt,
4341 driver_config->total_dev_cnt);
4342 driver_config->config_dev_cnt = 0;
4343 driver_config->total_dev_cnt = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004344 }
Jon Mason528f7272010-12-10 14:02:56 +00004345
Sreenivasa Honnur90023972010-04-08 01:48:30 -07004346 /* Now making the CPU based no of vpath calculation
4347 * applicable for individual functions as well.
4348 */
4349 driver_config->g_no_cpus = 0;
Sreenivasa Honnur657205b2009-10-05 01:52:54 +00004350 driver_config->vpath_per_dev = max_config_vpath;
4351
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004352 driver_config->total_dev_cnt++;
4353 if (++driver_config->config_dev_cnt > max_config_dev) {
4354 ret = 0;
4355 goto _exit0;
4356 }
4357
4358 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4359 GFP_KERNEL);
4360 if (!device_config) {
4361 ret = -ENOMEM;
4362 vxge_debug_init(VXGE_ERR,
4363 "device_config : malloc failed %s %d",
4364 __FILE__, __LINE__);
4365 goto _exit0;
4366 }
4367
Jon Mason528f7272010-12-10 14:02:56 +00004368 ll_config = kzalloc(sizeof(struct vxge_config), GFP_KERNEL);
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004369 if (!ll_config) {
4370 ret = -ENOMEM;
4371 vxge_debug_init(VXGE_ERR,
Jon Mason528f7272010-12-10 14:02:56 +00004372 "device_config : malloc failed %s %d",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004373 __FILE__, __LINE__);
4374 goto _exit0;
4375 }
4376 ll_config->tx_steering_type = TX_MULTIQ_STEERING;
4377 ll_config->intr_type = MSI_X;
4378 ll_config->napi_weight = NEW_NAPI_WEIGHT;
4379 ll_config->rth_steering = RTH_STEERING;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004380
4381 /* get the default configuration parameters */
4382 vxge_hw_device_config_default_get(device_config);
4383
4384 /* initialize configuration parameters */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004385 vxge_device_config_init(device_config, &ll_config->intr_type);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004386
4387 ret = pci_enable_device(pdev);
4388 if (ret) {
4389 vxge_debug_init(VXGE_ERR,
4390 "%s : can not enable PCI device", __func__);
4391 goto _exit0;
4392 }
4393
Denis Kirjanovb3837cec2009-12-25 18:48:33 -08004394 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004395 vxge_debug_ll_config(VXGE_TRACE,
4396 "%s : using 64bit DMA", __func__);
4397
4398 high_dma = 1;
4399
4400 if (pci_set_consistent_dma_mask(pdev,
Denis Kirjanovb3837cec2009-12-25 18:48:33 -08004401 DMA_BIT_MASK(64))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004402 vxge_debug_init(VXGE_ERR,
4403 "%s : unable to obtain 64bit DMA for "
4404 "consistent allocations", __func__);
4405 ret = -ENOMEM;
4406 goto _exit1;
4407 }
Denis Kirjanovb3837cec2009-12-25 18:48:33 -08004408 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004409 vxge_debug_ll_config(VXGE_TRACE,
4410 "%s : using 32bit DMA", __func__);
4411 } else {
4412 ret = -ENOMEM;
4413 goto _exit1;
4414 }
4415
Jon Mason6cca2002011-01-18 15:02:19 +00004416 ret = pci_request_region(pdev, 0, VXGE_DRIVER_NAME);
4417 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004418 vxge_debug_init(VXGE_ERR,
4419 "%s : request regions failed", __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004420 goto _exit1;
4421 }
4422
4423 pci_set_master(pdev);
4424
4425 attr.bar0 = pci_ioremap_bar(pdev, 0);
4426 if (!attr.bar0) {
4427 vxge_debug_init(VXGE_ERR,
4428 "%s : cannot remap io memory bar0", __func__);
4429 ret = -ENODEV;
4430 goto _exit2;
4431 }
4432 vxge_debug_ll_config(VXGE_TRACE,
4433 "pci ioremap bar0: %p:0x%llx",
4434 attr.bar0,
4435 (unsigned long long)pci_resource_start(pdev, 0));
4436
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004437 status = vxge_hw_device_hw_info_get(attr.bar0,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004438 &ll_config->device_hw_info);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004439 if (status != VXGE_HW_OK) {
4440 vxge_debug_init(VXGE_ERR,
4441 "%s: Reading of hardware info failed."
4442 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4443 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004444 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004445 }
4446
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004447 vpath_mask = ll_config->device_hw_info.vpath_mask;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004448 if (vpath_mask == 0) {
4449 vxge_debug_ll_config(VXGE_TRACE,
4450 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4451 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004452 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004453 }
4454
4455 vxge_debug_ll_config(VXGE_TRACE,
4456 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4457 (unsigned long long)vpath_mask);
4458
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004459 function_mode = ll_config->device_hw_info.function_mode;
4460 host_type = ll_config->device_hw_info.host_type;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004461 is_privileged = __vxge_hw_device_is_privilaged(host_type,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004462 ll_config->device_hw_info.func_id);
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004463
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004464 /* Check how many vpaths are available */
4465 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4466 if (!((vpath_mask) & vxge_mBIT(i)))
4467 continue;
4468 max_vpath_supported++;
4469 }
4470
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004471 if (new_device)
4472 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4473
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004474 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
Jon Masonc92bf702010-12-10 14:02:57 +00004475 if (is_sriov(function_mode) && !is_sriov_initialized(pdev) &&
4476 (ll_config->intr_type != INTA)) {
4477 ret = pci_enable_sriov(pdev, num_vfs);
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004478 if (ret)
4479 vxge_debug_ll_config(VXGE_ERR,
4480 "Failed in enabling SRIOV mode: %d\n", ret);
Jon Masonc92bf702010-12-10 14:02:57 +00004481 /* No need to fail out, as an error here is non-fatal */
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004482 }
4483
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004484 /*
4485 * Configure vpaths and get driver configured number of vpaths
4486 * which is less than or equal to the maximum vpaths per function.
4487 */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004488 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004489 if (!no_of_vpath) {
4490 vxge_debug_ll_config(VXGE_ERR,
4491 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4492 ret = 0;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004493 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004494 }
4495
4496 /* Setting driver callbacks */
4497 attr.uld_callbacks.link_up = vxge_callback_link_up;
4498 attr.uld_callbacks.link_down = vxge_callback_link_down;
4499 attr.uld_callbacks.crit_err = vxge_callback_crit_err;
4500
4501 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4502 if (status != VXGE_HW_OK) {
4503 vxge_debug_init(VXGE_ERR,
4504 "Failed to initialize device (%d)", status);
4505 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004506 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004507 }
4508
Jon Masone8ac1752010-11-11 04:25:57 +00004509 if (VXGE_FW_VER(ll_config->device_hw_info.fw_version.major,
4510 ll_config->device_hw_info.fw_version.minor,
4511 ll_config->device_hw_info.fw_version.build) >=
4512 VXGE_EPROM_FW_VER) {
4513 struct eprom_image img[VXGE_HW_MAX_ROM_IMAGES];
4514
4515 status = vxge_hw_vpath_eprom_img_ver_get(hldev, img);
4516 if (status != VXGE_HW_OK) {
4517 vxge_debug_init(VXGE_ERR, "%s: Reading of EPROM failed",
4518 VXGE_DRIVER_NAME);
4519 /* This is a non-fatal error, continue */
4520 }
4521
4522 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
4523 hldev->eprom_versions[i] = img[i].version;
4524 if (!img[i].is_valid)
4525 break;
4526 vxge_debug_init(VXGE_TRACE, "%s: EPROM %d, version "
Jon Mason1d15f812011-01-18 15:02:20 +00004527 "%d.%d.%d.%d", VXGE_DRIVER_NAME, i,
Jon Masone8ac1752010-11-11 04:25:57 +00004528 VXGE_EPROM_IMG_MAJOR(img[i].version),
4529 VXGE_EPROM_IMG_MINOR(img[i].version),
4530 VXGE_EPROM_IMG_FIX(img[i].version),
4531 VXGE_EPROM_IMG_BUILD(img[i].version));
4532 }
4533 }
4534
Sreenivasa Honnurfa41fd12009-10-05 01:56:35 +00004535 /* if FCS stripping is not disabled in MAC fail driver load */
Jon Masonb81b3732010-11-11 04:25:58 +00004536 status = vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask);
4537 if (status != VXGE_HW_OK) {
4538 vxge_debug_init(VXGE_ERR, "%s: FCS stripping is enabled in MAC"
4539 " failing driver load", VXGE_DRIVER_NAME);
Sreenivasa Honnurfa41fd12009-10-05 01:56:35 +00004540 ret = -EINVAL;
4541 goto _exit4;
4542 }
4543
Jon Masoncd883a72011-04-08 11:11:21 +00004544 /* Always enable HWTS. This will always cause the FCS to be invalid,
4545 * due to the fact that HWTS is using the FCS as the location of the
4546 * timestamp. The HW FCS checking will still correctly determine if
4547 * there is a valid checksum, and the FCS is being removed by the driver
4548 * anyway. So no fucntionality is being lost. Since it is always
4549 * enabled, we now simply use the ioctl call to set whether or not the
4550 * driver should be paying attention to the HWTS.
4551 */
4552 if (is_privileged == VXGE_HW_OK) {
4553 status = vxge_timestamp_config(hldev);
4554 if (status != VXGE_HW_OK) {
4555 vxge_debug_init(VXGE_ERR, "%s: HWTS enable failed",
4556 VXGE_DRIVER_NAME);
4557 ret = -EFAULT;
4558 goto _exit4;
4559 }
4560 }
4561
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004562 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4563
4564 /* set private device info */
4565 pci_set_drvdata(pdev, hldev);
4566
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004567 ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4568 ll_config->addr_learn_en = addr_learn_en;
4569 ll_config->rth_algorithm = RTH_ALG_JENKINS;
Jon Mason47f01db2010-11-11 04:25:53 +00004570 ll_config->rth_hash_type_tcpipv4 = 1;
4571 ll_config->rth_hash_type_ipv4 = 0;
4572 ll_config->rth_hash_type_tcpipv6 = 0;
4573 ll_config->rth_hash_type_ipv6 = 0;
4574 ll_config->rth_hash_type_tcpipv6ex = 0;
4575 ll_config->rth_hash_type_ipv6ex = 0;
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004576 ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
4577 ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4578 ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004579
Jon Masone8ac1752010-11-11 04:25:57 +00004580 ret = vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
4581 &vdev);
4582 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004583 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004584 goto _exit4;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004585 }
4586
Jon Masone8ac1752010-11-11 04:25:57 +00004587 ret = vxge_probe_fw_update(vdev);
4588 if (ret)
4589 goto _exit5;
4590
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004591 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4592 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4593 vxge_hw_device_trace_level_get(hldev));
4594
4595 /* set private HW device info */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004596 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4597 vdev->bar0 = attr.bar0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004598 vdev->max_vpath_supported = max_vpath_supported;
4599 vdev->no_of_vpath = no_of_vpath;
4600
4601 /* Virtual Path count */
4602 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4603 if (!vxge_bVALn(vpath_mask, i, 1))
4604 continue;
4605 if (j >= vdev->no_of_vpath)
4606 break;
4607
4608 vdev->vpaths[j].is_configured = 1;
4609 vdev->vpaths[j].device_id = i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004610 vdev->vpaths[j].ring.driver_id = j;
4611 vdev->vpaths[j].vdev = vdev;
4612 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4613 memcpy((u8 *)vdev->vpaths[j].macaddr,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004614 ll_config->device_hw_info.mac_addrs[i],
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004615 ETH_ALEN);
4616
4617 /* Initialize the mac address list header */
4618 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4619
4620 vdev->vpaths[j].mac_addr_cnt = 0;
4621 vdev->vpaths[j].mcast_addr_cnt = 0;
4622 j++;
4623 }
4624 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4625 vdev->max_config_port = max_config_port;
4626
4627 vdev->vlan_tag_strip = vlan_tag_strip;
4628
4629 /* map the hashing selector table to the configured vpaths */
4630 for (i = 0; i < vdev->no_of_vpath; i++)
4631 vdev->vpath_selector[i] = vpath_selector[i];
4632
4633 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4634
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004635 ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4636 ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4637 ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004638
4639 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004640 vdev->ndev->name, ll_config->device_hw_info.serial_number);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004641
4642 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004643 vdev->ndev->name, ll_config->device_hw_info.part_number);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004644
4645 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004646 vdev->ndev->name, ll_config->device_hw_info.product_desc);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004647
hartleysbf54e732010-01-05 06:59:23 +00004648 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4649 vdev->ndev->name, macaddr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004650
4651 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4652 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4653
4654 vxge_debug_init(VXGE_TRACE,
4655 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004656 ll_config->device_hw_info.fw_version.version,
4657 ll_config->device_hw_info.fw_date.date);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004658
Sreenivasa Honnur0a25bdc2009-07-01 21:18:06 +00004659 if (new_device) {
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004660 switch (ll_config->device_hw_info.function_mode) {
Sreenivasa Honnur0a25bdc2009-07-01 21:18:06 +00004661 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4662 vxge_debug_init(VXGE_TRACE,
4663 "%s: Single Function Mode Enabled", vdev->ndev->name);
4664 break;
4665 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4666 vxge_debug_init(VXGE_TRACE,
4667 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4668 break;
4669 case VXGE_HW_FUNCTION_MODE_SRIOV:
4670 vxge_debug_init(VXGE_TRACE,
4671 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4672 break;
4673 case VXGE_HW_FUNCTION_MODE_MRIOV:
4674 vxge_debug_init(VXGE_TRACE,
4675 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4676 break;
4677 }
4678 }
4679
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004680 vxge_print_parm(vdev, vpath_mask);
4681
4682 /* Store the fw version for ethttool option */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004683 strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004684 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4685 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4686
4687 /* Copy the station mac address to the list */
4688 for (i = 0; i < vdev->no_of_vpath; i++) {
Joe Perchese80be0b2010-11-27 23:05:45 +00004689 entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004690 if (NULL == entry) {
4691 vxge_debug_init(VXGE_ERR,
4692 "%s: mac_addr_list : memory allocation failed",
4693 vdev->ndev->name);
4694 ret = -EPERM;
Jon Masone8ac1752010-11-11 04:25:57 +00004695 goto _exit6;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004696 }
4697 macaddr = (u8 *)&entry->macaddr;
4698 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4699 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4700 vdev->vpaths[i].mac_addr_cnt = 1;
4701 }
4702
Sreenivasa Honnur914d0d72009-07-01 21:13:12 +00004703 kfree(device_config);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00004704
4705 /*
4706 * INTA is shared in multi-function mode. This is unlike the INTA
4707 * implementation in MR mode, where each VH has its own INTA message.
4708 * - INTA is masked (disabled) as long as at least one function sets
4709 * its TITAN_MASK_ALL_INT.ALARM bit.
4710 * - INTA is unmasked (enabled) when all enabled functions have cleared
4711 * their own TITAN_MASK_ALL_INT.ALARM bit.
4712 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4713 * Though this driver leaves the top level interrupts unmasked while
4714 * leaving the required module interrupt bits masked on exit, there
4715 * could be a rougue driver around that does not follow this procedure
4716 * resulting in a failure to generate interrupts. The following code is
4717 * present to prevent such a failure.
4718 */
4719
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004720 if (ll_config->device_hw_info.function_mode ==
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00004721 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4722 if (vdev->config.intr_type == INTA)
4723 vxge_hw_device_unmask_all(hldev);
4724
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004725 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4726 vdev->ndev->name, __func__, __LINE__);
4727
4728 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4729 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4730 vxge_hw_device_trace_level_get(hldev));
4731
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004732 kfree(ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004733 return 0;
4734
Jon Masone8ac1752010-11-11 04:25:57 +00004735_exit6:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004736 for (i = 0; i < vdev->no_of_vpath; i++)
4737 vxge_free_mac_add_list(&vdev->vpaths[i]);
Jon Masone8ac1752010-11-11 04:25:57 +00004738_exit5:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004739 vxge_device_unregister(hldev);
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004740_exit4:
Jon Mason6cca2002011-01-18 15:02:19 +00004741 pci_set_drvdata(pdev, NULL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004742 vxge_hw_device_terminate(hldev);
Jon Mason6cca2002011-01-18 15:02:19 +00004743 pci_disable_sriov(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004744_exit3:
4745 iounmap(attr.bar0);
4746_exit2:
Jon Masondc66daa2010-12-10 14:02:58 +00004747 pci_release_region(pdev, 0);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004748_exit1:
4749 pci_disable_device(pdev);
4750_exit0:
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004751 kfree(ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004752 kfree(device_config);
4753 driver_config->config_dev_cnt--;
Jon Mason6cca2002011-01-18 15:02:19 +00004754 driver_config->total_dev_cnt--;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004755 return ret;
4756}
4757
4758/**
4759 * vxge_rem_nic - Free the PCI device
4760 * @pdev: structure containing the PCI related information of the device.
4761 * Description: This function is called by the Pci subsystem to release a
4762 * PCI device and free up all resource held up by the device.
4763 */
Jon Mason2c913082010-11-11 04:26:03 +00004764static void __devexit vxge_remove(struct pci_dev *pdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004765{
Jon Mason2c913082010-11-11 04:26:03 +00004766 struct __vxge_hw_device *hldev;
Jon Mason6cca2002011-01-18 15:02:19 +00004767 struct vxgedev *vdev;
4768 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004769
Joe Perchesd8ee7072010-11-15 10:13:58 +00004770 hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004771 if (hldev == NULL)
4772 return;
Jon Mason2c913082010-11-11 04:26:03 +00004773
Jon Mason6cca2002011-01-18 15:02:19 +00004774 vdev = netdev_priv(hldev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004775
Jon Mason2c913082010-11-11 04:26:03 +00004776 vxge_debug_entryexit(vdev->level_trace, "%s:%d", __func__, __LINE__);
Jon Mason2c913082010-11-11 04:26:03 +00004777 vxge_debug_init(vdev->level_trace, "%s : removing PCI device...",
4778 __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004779
Jon Mason6cca2002011-01-18 15:02:19 +00004780 for (i = 0; i < vdev->no_of_vpath; i++)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004781 vxge_free_mac_add_list(&vdev->vpaths[i]);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004782
Jon Mason6cca2002011-01-18 15:02:19 +00004783 vxge_device_unregister(hldev);
4784 pci_set_drvdata(pdev, NULL);
4785 /* Do not call pci_disable_sriov here, as it will break child devices */
4786 vxge_hw_device_terminate(hldev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004787 iounmap(vdev->bar0);
Jon Mason6cca2002011-01-18 15:02:19 +00004788 pci_release_region(pdev, 0);
4789 pci_disable_device(pdev);
4790 driver_config->config_dev_cnt--;
4791 driver_config->total_dev_cnt--;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004792
Jon Mason2c913082010-11-11 04:26:03 +00004793 vxge_debug_init(vdev->level_trace, "%s:%d Device unregistered",
4794 __func__, __LINE__);
Jon Mason2c913082010-11-11 04:26:03 +00004795 vxge_debug_entryexit(vdev->level_trace, "%s:%d Exiting...", __func__,
4796 __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004797}
4798
4799static struct pci_error_handlers vxge_err_handler = {
4800 .error_detected = vxge_io_error_detected,
4801 .slot_reset = vxge_io_slot_reset,
4802 .resume = vxge_io_resume,
4803};
4804
4805static struct pci_driver vxge_driver = {
4806 .name = VXGE_DRIVER_NAME,
4807 .id_table = vxge_id_table,
4808 .probe = vxge_probe,
4809 .remove = __devexit_p(vxge_remove),
4810#ifdef CONFIG_PM
4811 .suspend = vxge_pm_suspend,
4812 .resume = vxge_pm_resume,
4813#endif
4814 .err_handler = &vxge_err_handler,
4815};
4816
4817static int __init
4818vxge_starter(void)
4819{
4820 int ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004821
Joe Perches75f5e1c2010-07-27 11:47:03 +00004822 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4823 pr_info("Driver version: %s\n", DRV_VERSION);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004824
4825 verify_bandwidth();
4826
4827 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4828 if (!driver_config)
4829 return -ENOMEM;
4830
4831 ret = pci_register_driver(&vxge_driver);
Jon Mason528f7272010-12-10 14:02:56 +00004832 if (ret) {
4833 kfree(driver_config);
4834 goto err;
4835 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004836
4837 if (driver_config->config_dev_cnt &&
4838 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4839 vxge_debug_init(VXGE_ERR,
4840 "%s: Configured %d of %d devices",
4841 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4842 driver_config->total_dev_cnt);
Jon Mason528f7272010-12-10 14:02:56 +00004843err:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004844 return ret;
4845}
4846
4847static void __exit
4848vxge_closer(void)
4849{
4850 pci_unregister_driver(&vxge_driver);
4851 kfree(driver_config);
4852}
4853module_init(vxge_starter);
4854module_exit(vxge_closer);