blob: 1ded50ca1600195d3ab46daf3d5689c152b3d5cc [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>
Paul Gortmaker9d9779e2011-07-03 15:21:01 -040058#include <linux/module.h>
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000059#include "vxge-main.h"
60#include "vxge-reg.h"
61
62MODULE_LICENSE("Dual BSD/GPL");
63MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
64 "Virtualized Server Adapter");
65
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000066static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000067 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
68 PCI_ANY_ID},
69 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
70 PCI_ANY_ID},
71 {0}
72};
73
74MODULE_DEVICE_TABLE(pci, vxge_id_table);
75
76VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
77VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
78VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
79VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
80VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
81VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
82
83static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
84 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
85static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
86 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
87module_param_array(bw_percentage, uint, NULL, 0);
88
89static struct vxge_drv_config *driver_config;
stephen hemmingere40c10f2014-01-15 08:28:54 -080090static enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000091
92static inline int is_vxge_card_up(struct vxgedev *vdev)
93{
94 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
95}
96
97static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
98{
Benjamin LaHaiseff67df52009-08-04 10:21:03 +000099 struct sk_buff **skb_ptr = NULL;
100 struct sk_buff **temp;
101#define NR_SKB_COMPLETED 128
102 struct sk_buff *completed[NR_SKB_COMPLETED];
103 int more;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000104
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000105 do {
106 more = 0;
107 skb_ptr = completed;
108
Jon Mason98f45da2010-07-15 08:47:25 +0000109 if (__netif_tx_trylock(fifo->txq)) {
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000110 vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
111 NR_SKB_COMPLETED, &more);
Jon Mason98f45da2010-07-15 08:47:25 +0000112 __netif_tx_unlock(fifo->txq);
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000113 }
Jon Mason98f45da2010-07-15 08:47:25 +0000114
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000115 /* free SKBs */
116 for (temp = completed; temp != skb_ptr; temp++)
117 dev_kfree_skb_irq(*temp);
Jon Mason98f45da2010-07-15 08:47:25 +0000118 } while (more);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000119}
120
121static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
122{
123 int i;
124
125 /* Complete all transmits */
126 for (i = 0; i < vdev->no_of_vpath; i++)
127 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
128}
129
130static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
131{
132 int i;
133 struct vxge_ring *ring;
134
135 /* Complete all receives*/
136 for (i = 0; i < vdev->no_of_vpath; i++) {
137 ring = &vdev->vpaths[i].ring;
138 vxge_hw_vpath_poll_rx(ring->handle);
139 }
140}
141
142/*
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000143 * vxge_callback_link_up
144 *
145 * This function is called during interrupt context to notify link up state
146 * change.
147 */
Jon Mason528f7272010-12-10 14:02:56 +0000148static void vxge_callback_link_up(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000149{
150 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +0000151 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000152
153 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
154 vdev->ndev->name, __func__, __LINE__);
Joe Perches75f5e1c2010-07-27 11:47:03 +0000155 netdev_notice(vdev->ndev, "Link Up\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000156 vdev->stats.link_up++;
157
158 netif_carrier_on(vdev->ndev);
Jon Masond03848e2010-07-15 08:47:23 +0000159 netif_tx_wake_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000160
161 vxge_debug_entryexit(VXGE_TRACE,
162 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
163}
164
165/*
166 * vxge_callback_link_down
167 *
168 * This function is called during interrupt context to notify link down state
169 * change.
170 */
Jon Mason528f7272010-12-10 14:02:56 +0000171static void vxge_callback_link_down(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000172{
173 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +0000174 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000175
176 vxge_debug_entryexit(VXGE_TRACE,
177 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
Joe Perches75f5e1c2010-07-27 11:47:03 +0000178 netdev_notice(vdev->ndev, "Link Down\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000179
180 vdev->stats.link_down++;
181 netif_carrier_off(vdev->ndev);
Jon Masond03848e2010-07-15 08:47:23 +0000182 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000183
184 vxge_debug_entryexit(VXGE_TRACE,
185 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
186}
187
188/*
189 * vxge_rx_alloc
190 *
191 * Allocate SKB.
192 */
Jon Mason528f7272010-12-10 14:02:56 +0000193static struct sk_buff *
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000194vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
195{
196 struct net_device *dev;
197 struct sk_buff *skb;
198 struct vxge_rx_priv *rx_priv;
199
200 dev = ring->ndev;
201 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
202 ring->ndev->name, __func__, __LINE__);
203
204 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
205
206 /* try to allocate skb first. this one may fail */
207 skb = netdev_alloc_skb(dev, skb_size +
208 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
209 if (skb == NULL) {
210 vxge_debug_mem(VXGE_ERR,
211 "%s: out of memory to allocate SKB", dev->name);
212 ring->stats.skb_alloc_fail++;
213 return NULL;
214 }
215
216 vxge_debug_mem(VXGE_TRACE,
217 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
218 __func__, __LINE__, skb);
219
220 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
221
222 rx_priv->skb = skb;
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000223 rx_priv->skb_data = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000224 rx_priv->data_size = skb_size;
225 vxge_debug_entryexit(VXGE_TRACE,
226 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
227
228 return skb;
229}
230
231/*
232 * vxge_rx_map
233 */
234static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
235{
236 struct vxge_rx_priv *rx_priv;
237 dma_addr_t dma_addr;
238
239 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
240 ring->ndev->name, __func__, __LINE__);
241 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
242
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000243 rx_priv->skb_data = rx_priv->skb->data;
244 dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000245 rx_priv->data_size, PCI_DMA_FROMDEVICE);
246
Denis Kirjanovfa15e992010-01-10 13:40:10 -0800247 if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000248 ring->stats.pci_map_fail++;
249 return -EIO;
250 }
251 vxge_debug_mem(VXGE_TRACE,
252 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
253 ring->ndev->name, __func__, __LINE__,
254 (unsigned long long)dma_addr);
255 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
256
257 rx_priv->data_dma = dma_addr;
258 vxge_debug_entryexit(VXGE_TRACE,
259 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
260
261 return 0;
262}
263
264/*
265 * vxge_rx_initial_replenish
266 * Allocation of RxD as an initial replenish procedure.
267 */
268static enum vxge_hw_status
269vxge_rx_initial_replenish(void *dtrh, void *userdata)
270{
271 struct vxge_ring *ring = (struct vxge_ring *)userdata;
272 struct vxge_rx_priv *rx_priv;
273
274 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
275 ring->ndev->name, __func__, __LINE__);
276 if (vxge_rx_alloc(dtrh, ring,
277 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
278 return VXGE_HW_FAIL;
279
280 if (vxge_rx_map(dtrh, ring)) {
281 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
282 dev_kfree_skb(rx_priv->skb);
283
284 return VXGE_HW_FAIL;
285 }
286 vxge_debug_entryexit(VXGE_TRACE,
287 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
288
289 return VXGE_HW_OK;
290}
291
292static inline void
293vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
294 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
295{
296
297 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
298 ring->ndev->name, __func__, __LINE__);
299 skb_record_rx_queue(skb, ring->driver_id);
300 skb->protocol = eth_type_trans(skb, ring->ndev);
301
stephen hemminger62ea0552011-06-20 10:35:07 +0000302 u64_stats_update_begin(&ring->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000303 ring->stats.rx_frms++;
304 ring->stats.rx_bytes += pkt_length;
305
306 if (skb->pkt_type == PACKET_MULTICAST)
307 ring->stats.rx_mcast++;
stephen hemminger62ea0552011-06-20 10:35:07 +0000308 u64_stats_update_end(&ring->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000309
310 vxge_debug_rx(VXGE_TRACE,
311 "%s: %s:%d skb protocol = %d",
312 ring->ndev->name, __func__, __LINE__, skb->protocol);
313
Jiri Pirko53515732011-07-20 04:54:40 +0000314 if (ext_info->vlan &&
315 ring->vlan_tag_strip == VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE)
Patrick McHardy86a9bad2013-04-19 02:04:30 +0000316 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ext_info->vlan);
Jiri Pirko53515732011-07-20 04:54:40 +0000317 napi_gro_receive(ring->napi_p, skb);
Michał Mirosławfeb990d2011-04-18 13:31:21 +0000318
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000319 vxge_debug_entryexit(VXGE_TRACE,
320 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
321}
322
323static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
324 struct vxge_rx_priv *rx_priv)
325{
326 pci_dma_sync_single_for_device(ring->pdev,
327 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
328
329 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
330 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
331}
332
333static inline void vxge_post(int *dtr_cnt, void **first_dtr,
334 void *post_dtr, struct __vxge_hw_ring *ringh)
335{
336 int dtr_count = *dtr_cnt;
337 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
338 if (*first_dtr)
339 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
340 *first_dtr = post_dtr;
341 } else
342 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
343 dtr_count++;
344 *dtr_cnt = dtr_count;
345}
346
347/*
348 * vxge_rx_1b_compl
349 *
350 * If the interrupt is because of a received frame or if the receive ring
351 * contains fresh as yet un-processed frames, this function is called.
352 */
stephen hemminger42821a52010-10-21 07:50:53 +0000353static enum vxge_hw_status
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000354vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
355 u8 t_code, void *userdata)
356{
357 struct vxge_ring *ring = (struct vxge_ring *)userdata;
Jon Masonb81b3732010-11-11 04:25:58 +0000358 struct net_device *dev = ring->ndev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000359 unsigned int dma_sizes;
360 void *first_dtr = NULL;
361 int dtr_cnt = 0;
362 int data_size;
363 dma_addr_t data_dma;
364 int pkt_length;
365 struct sk_buff *skb;
366 struct vxge_rx_priv *rx_priv;
367 struct vxge_hw_ring_rxd_info ext_info;
368 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
369 ring->ndev->name, __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000370
371 do {
Benjamin LaHaise3f23e432009-08-04 10:21:39 +0000372 prefetch((char *)dtr + L1_CACHE_BYTES);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000373 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
374 skb = rx_priv->skb;
375 data_size = rx_priv->data_size;
376 data_dma = rx_priv->data_dma;
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000377 prefetch(rx_priv->skb_data);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000378
379 vxge_debug_rx(VXGE_TRACE,
380 "%s: %s:%d skb = 0x%p",
381 ring->ndev->name, __func__, __LINE__, skb);
382
383 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
384 pkt_length = dma_sizes;
385
Sreenivasa Honnur22fa1252009-07-01 21:17:24 +0000386 pkt_length -= ETH_FCS_LEN;
387
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000388 vxge_debug_rx(VXGE_TRACE,
389 "%s: %s:%d Packet Length = %d",
390 ring->ndev->name, __func__, __LINE__, pkt_length);
391
392 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
393
394 /* check skb validity */
395 vxge_assert(skb);
396
397 prefetch((char *)skb + L1_CACHE_BYTES);
398 if (unlikely(t_code)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000399 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
400 VXGE_HW_OK) {
401
402 ring->stats.rx_errors++;
403 vxge_debug_rx(VXGE_TRACE,
404 "%s: %s :%d Rx T_code is %d",
405 ring->ndev->name, __func__,
406 __LINE__, t_code);
407
408 /* If the t_code is not supported and if the
409 * t_code is other than 0x5 (unparseable packet
410 * such as unknown UPV6 header), Drop it !!!
411 */
412 vxge_re_pre_post(dtr, ring, rx_priv);
413
414 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
415 ring->stats.rx_dropped++;
416 continue;
417 }
418 }
419
420 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000421 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000422 if (!vxge_rx_map(dtr, ring)) {
423 skb_put(skb, pkt_length);
424
425 pci_unmap_single(ring->pdev, data_dma,
426 data_size, PCI_DMA_FROMDEVICE);
427
428 vxge_hw_ring_rxd_pre_post(ringh, dtr);
429 vxge_post(&dtr_cnt, &first_dtr, dtr,
430 ringh);
431 } else {
432 dev_kfree_skb(rx_priv->skb);
433 rx_priv->skb = skb;
434 rx_priv->data_size = data_size;
435 vxge_re_pre_post(dtr, ring, rx_priv);
436
437 vxge_post(&dtr_cnt, &first_dtr, dtr,
438 ringh);
439 ring->stats.rx_dropped++;
440 break;
441 }
442 } else {
443 vxge_re_pre_post(dtr, ring, rx_priv);
444
445 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
446 ring->stats.rx_dropped++;
447 break;
448 }
449 } else {
450 struct sk_buff *skb_up;
451
452 skb_up = netdev_alloc_skb(dev, pkt_length +
453 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
454 if (skb_up != NULL) {
455 skb_reserve(skb_up,
456 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
457
458 pci_dma_sync_single_for_cpu(ring->pdev,
459 data_dma, data_size,
460 PCI_DMA_FROMDEVICE);
461
462 vxge_debug_mem(VXGE_TRACE,
463 "%s: %s:%d skb_up = %p",
464 ring->ndev->name, __func__,
465 __LINE__, skb);
466 memcpy(skb_up->data, skb->data, pkt_length);
467
468 vxge_re_pre_post(dtr, ring, rx_priv);
469
470 vxge_post(&dtr_cnt, &first_dtr, dtr,
471 ringh);
472 /* will netif_rx small SKB instead */
473 skb = skb_up;
474 skb_put(skb, pkt_length);
475 } else {
476 vxge_re_pre_post(dtr, ring, rx_priv);
477
478 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
479 vxge_debug_rx(VXGE_ERR,
480 "%s: vxge_rx_1b_compl: out of "
481 "memory", dev->name);
482 ring->stats.skb_alloc_fail++;
483 break;
484 }
485 }
486
487 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
488 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
Michał Mirosławfeb990d2011-04-18 13:31:21 +0000489 (dev->features & NETIF_F_RXCSUM) && /* Offload Rx side CSUM */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000490 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
491 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
492 skb->ip_summed = CHECKSUM_UNNECESSARY;
493 else
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700494 skb_checksum_none_assert(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000495
Jon Masonb81b3732010-11-11 04:25:58 +0000496
497 if (ring->rx_hwts) {
498 struct skb_shared_hwtstamps *skb_hwts;
499 u32 ns = *(u32 *)(skb->head + pkt_length);
500
501 skb_hwts = skb_hwtstamps(skb);
502 skb_hwts->hwtstamp = ns_to_ktime(ns);
503 skb_hwts->syststamp.tv64 = 0;
504 }
505
Jon Mason47f01db2010-11-11 04:25:53 +0000506 /* rth_hash_type and rth_it_hit are non-zero regardless of
507 * whether rss is enabled. Only the rth_value is zero/non-zero
508 * if rss is disabled/enabled, so key off of that.
509 */
510 if (ext_info.rth_value)
Tom Herbertc4be4162013-12-17 23:31:36 -0800511 skb_set_hash(skb, ext_info.rth_value,
512 PKT_HASH_TYPE_L3);
Jon Mason47f01db2010-11-11 04:25:53 +0000513
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000514 vxge_rx_complete(ring, skb, ext_info.vlan,
515 pkt_length, &ext_info);
516
517 ring->budget--;
518 ring->pkts_processed++;
519 if (!ring->budget)
520 break;
521
522 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
523 &t_code) == VXGE_HW_OK);
524
525 if (first_dtr)
526 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
527
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000528 vxge_debug_entryexit(VXGE_TRACE,
529 "%s:%d Exiting...",
530 __func__, __LINE__);
531 return VXGE_HW_OK;
532}
533
534/*
535 * vxge_xmit_compl
536 *
537 * If an interrupt was raised to indicate DMA complete of the Tx packet,
538 * this function is called. It identifies the last TxD whose buffer was
539 * freed and frees all skbs whose data have already DMA'ed into the NICs
540 * internal memory.
541 */
stephen hemminger42821a52010-10-21 07:50:53 +0000542static enum vxge_hw_status
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000543vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
544 enum vxge_hw_fifo_tcode t_code, void *userdata,
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000545 struct sk_buff ***skb_ptr, int nr_skb, int *more)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000546{
547 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000548 struct sk_buff *skb, **done_skb = *skb_ptr;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000549 int pkt_cnt = 0;
550
551 vxge_debug_entryexit(VXGE_TRACE,
552 "%s:%d Entered....", __func__, __LINE__);
553
554 do {
555 int frg_cnt;
556 skb_frag_t *frag;
557 int i = 0, j;
558 struct vxge_tx_priv *txd_priv =
559 vxge_hw_fifo_txdl_private_get(dtr);
560
561 skb = txd_priv->skb;
562 frg_cnt = skb_shinfo(skb)->nr_frags;
563 frag = &skb_shinfo(skb)->frags[0];
564
565 vxge_debug_tx(VXGE_TRACE,
566 "%s: %s:%d fifo_hw = %p dtr = %p "
567 "tcode = 0x%x", fifo->ndev->name, __func__,
568 __LINE__, fifo_hw, dtr, t_code);
569 /* check skb validity */
570 vxge_assert(skb);
571 vxge_debug_tx(VXGE_TRACE,
572 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
573 fifo->ndev->name, __func__, __LINE__,
574 skb, txd_priv, frg_cnt);
575 if (unlikely(t_code)) {
576 fifo->stats.tx_errors++;
577 vxge_debug_tx(VXGE_ERR,
578 "%s: tx: dtr %p completed due to "
579 "error t_code %01x", fifo->ndev->name,
580 dtr, t_code);
581 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
582 }
583
584 /* for unfragmented skb */
585 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
586 skb_headlen(skb), PCI_DMA_TODEVICE);
587
588 for (j = 0; j < frg_cnt; j++) {
589 pci_unmap_page(fifo->pdev,
590 txd_priv->dma_buffers[i++],
Eric Dumazet9e903e02011-10-18 21:00:24 +0000591 skb_frag_size(frag), PCI_DMA_TODEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000592 frag += 1;
593 }
594
595 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
596
597 /* Updating the statistics block */
stephen hemminger62ea0552011-06-20 10:35:07 +0000598 u64_stats_update_begin(&fifo->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000599 fifo->stats.tx_frms++;
600 fifo->stats.tx_bytes += skb->len;
stephen hemminger62ea0552011-06-20 10:35:07 +0000601 u64_stats_update_end(&fifo->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000602
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000603 *done_skb++ = skb;
604
605 if (--nr_skb <= 0) {
606 *more = 1;
607 break;
608 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000609
610 pkt_cnt++;
611 if (pkt_cnt > fifo->indicate_max_pkts)
612 break;
613
614 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
615 &dtr, &t_code) == VXGE_HW_OK);
616
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000617 *skb_ptr = done_skb;
Jon Mason98f45da2010-07-15 08:47:25 +0000618 if (netif_tx_queue_stopped(fifo->txq))
619 netif_tx_wake_queue(fifo->txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000620
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000621 vxge_debug_entryexit(VXGE_TRACE,
622 "%s: %s:%d Exiting...",
623 fifo->ndev->name, __func__, __LINE__);
624 return VXGE_HW_OK;
625}
626
Eric Dumazet28679752009-05-27 19:26:37 +0000627/* select a vpath to transmit the packet */
Jon Mason98f45da2010-07-15 08:47:25 +0000628static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000629{
630 u16 queue_len, counter = 0;
631 if (skb->protocol == htons(ETH_P_IP)) {
632 struct iphdr *ip;
633 struct tcphdr *th;
634
635 ip = ip_hdr(skb);
636
Paul Gortmaker56f8a752011-06-21 20:33:34 -0700637 if (!ip_is_fragment(ip)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000638 th = (struct tcphdr *)(((unsigned char *)ip) +
639 ip->ihl*4);
640
641 queue_len = vdev->no_of_vpath;
642 counter = (ntohs(th->source) +
643 ntohs(th->dest)) &
644 vdev->vpath_selector[queue_len - 1];
645 if (counter >= queue_len)
646 counter = queue_len - 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000647 }
648 }
649 return counter;
650}
651
652static enum vxge_hw_status vxge_search_mac_addr_in_list(
653 struct vxge_vpath *vpath, u64 del_mac)
654{
655 struct list_head *entry, *next;
656 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
657 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
658 return TRUE;
659 }
660 return FALSE;
661}
662
Jon Mason528f7272010-12-10 14:02:56 +0000663static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
664{
665 struct vxge_mac_addrs *new_mac_entry;
666 u8 *mac_address = NULL;
667
668 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
669 return TRUE;
670
671 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
672 if (!new_mac_entry) {
673 vxge_debug_mem(VXGE_ERR,
674 "%s: memory allocation failed",
675 VXGE_DRIVER_NAME);
676 return FALSE;
677 }
678
679 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
680
681 /* Copy the new mac address to the list */
682 mac_address = (u8 *)&new_mac_entry->macaddr;
683 memcpy(mac_address, mac->macaddr, ETH_ALEN);
684
685 new_mac_entry->state = mac->state;
686 vpath->mac_addr_cnt++;
687
Tobias Klauserf8d4aa22011-07-03 23:58:04 +0000688 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +0000689 vpath->mcast_addr_cnt++;
690
691 return TRUE;
692}
693
694/* Add a mac address to DA table */
695static enum vxge_hw_status
696vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
697{
698 enum vxge_hw_status status = VXGE_HW_OK;
699 struct vxge_vpath *vpath;
700 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
701
Tobias Klauserf8d4aa22011-07-03 23:58:04 +0000702 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +0000703 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
704 else
705 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
706
707 vpath = &vdev->vpaths[mac->vpath_no];
708 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
709 mac->macmask, duplicate_mode);
710 if (status != VXGE_HW_OK) {
711 vxge_debug_init(VXGE_ERR,
712 "DA config add entry failed for vpath:%d",
713 vpath->device_id);
714 } else
715 if (FALSE == vxge_mac_list_add(vpath, mac))
716 status = -EPERM;
717
718 return status;
719}
720
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000721static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
722{
723 struct macInfo mac_info;
724 u8 *mac_address = NULL;
725 u64 mac_addr = 0, vpath_vector = 0;
726 int vpath_idx = 0;
727 enum vxge_hw_status status = VXGE_HW_OK;
728 struct vxge_vpath *vpath = NULL;
729 struct __vxge_hw_device *hldev;
730
Joe Perchesd8ee7072010-11-15 10:13:58 +0000731 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000732
733 mac_address = (u8 *)&mac_addr;
734 memcpy(mac_address, mac_header, ETH_ALEN);
735
736 /* Is this mac address already in the list? */
737 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
738 vpath = &vdev->vpaths[vpath_idx];
739 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
740 return vpath_idx;
741 }
742
743 memset(&mac_info, 0, sizeof(struct macInfo));
744 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
745
746 /* Any vpath has room to add mac address to its da table? */
747 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
748 vpath = &vdev->vpaths[vpath_idx];
749 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
750 /* Add this mac address to this vpath */
751 mac_info.vpath_no = vpath_idx;
752 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
753 status = vxge_add_mac_addr(vdev, &mac_info);
754 if (status != VXGE_HW_OK)
755 return -EPERM;
756 return vpath_idx;
757 }
758 }
759
760 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
761 vpath_idx = 0;
762 mac_info.vpath_no = vpath_idx;
763 /* Is the first vpath already selected as catch-basin ? */
764 vpath = &vdev->vpaths[vpath_idx];
765 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
766 /* Add this mac address to this vpath */
767 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
768 return -EPERM;
769 return vpath_idx;
770 }
771
772 /* Select first vpath as catch-basin */
773 vpath_vector = vxge_mBIT(vpath->device_id);
774 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
775 vxge_hw_mgmt_reg_type_mrpcim,
776 0,
777 (ulong)offsetof(
778 struct vxge_hw_mrpcim_reg,
779 rts_mgr_cbasin_cfg),
780 vpath_vector);
781 if (status != VXGE_HW_OK) {
782 vxge_debug_tx(VXGE_ERR,
783 "%s: Unable to set the vpath-%d in catch-basin mode",
784 VXGE_DRIVER_NAME, vpath->device_id);
785 return -EPERM;
786 }
787
788 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
789 return -EPERM;
790
791 return vpath_idx;
792}
793
794/**
795 * vxge_xmit
796 * @skb : the socket buffer containing the Tx data.
797 * @dev : device pointer.
798 *
799 * This function is the Tx entry point of the driver. Neterion NIC supports
800 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000801*/
Stephen Hemminger613573252009-08-31 19:50:58 +0000802static netdev_tx_t
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000803vxge_xmit(struct sk_buff *skb, struct net_device *dev)
804{
805 struct vxge_fifo *fifo = NULL;
806 void *dtr_priv;
807 void *dtr = NULL;
808 struct vxgedev *vdev = NULL;
809 enum vxge_hw_status status;
810 int frg_cnt, first_frg_len;
811 skb_frag_t *frag;
812 int i = 0, j = 0, avail;
813 u64 dma_pointer;
814 struct vxge_tx_priv *txdl_priv = NULL;
815 struct __vxge_hw_fifo *fifo_hw;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000816 int offload_type;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000817 int vpath_no = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000818
819 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
820 dev->name, __func__, __LINE__);
821
822 /* A buffer with no data will be dropped */
823 if (unlikely(skb->len <= 0)) {
824 vxge_debug_tx(VXGE_ERR,
825 "%s: Buffer has no data..", dev->name);
826 dev_kfree_skb(skb);
827 return NETDEV_TX_OK;
828 }
829
Joe Perches5f54ceb2010-11-15 11:12:30 +0000830 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000831
832 if (unlikely(!is_vxge_card_up(vdev))) {
833 vxge_debug_tx(VXGE_ERR,
834 "%s: vdev not initialized", dev->name);
835 dev_kfree_skb(skb);
836 return NETDEV_TX_OK;
837 }
838
839 if (vdev->config.addr_learn_en) {
840 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
841 if (vpath_no == -EPERM) {
842 vxge_debug_tx(VXGE_ERR,
843 "%s: Failed to store the mac address",
844 dev->name);
845 dev_kfree_skb(skb);
846 return NETDEV_TX_OK;
847 }
848 }
849
850 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
851 vpath_no = skb_get_queue_mapping(skb);
852 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
Jon Mason98f45da2010-07-15 08:47:25 +0000853 vpath_no = vxge_get_vpath_no(vdev, skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000854
855 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
856
857 if (vpath_no >= vdev->no_of_vpath)
858 vpath_no = 0;
859
860 fifo = &vdev->vpaths[vpath_no].fifo;
861 fifo_hw = fifo->handle;
862
Jon Mason98f45da2010-07-15 08:47:25 +0000863 if (netif_tx_queue_stopped(fifo->txq))
Jon Masond03848e2010-07-15 08:47:23 +0000864 return NETDEV_TX_BUSY;
Jon Masond03848e2010-07-15 08:47:23 +0000865
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000866 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
867 if (avail == 0) {
868 vxge_debug_tx(VXGE_ERR,
869 "%s: No free TXDs available", dev->name);
870 fifo->stats.txd_not_free++;
Jon Mason98f45da2010-07-15 08:47:25 +0000871 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000872 }
873
Benjamin LaHaise4403b372009-08-04 10:20:44 +0000874 /* Last TXD? Stop tx queue to avoid dropping packets. TX
875 * completion will resume the queue.
876 */
877 if (avail == 1)
Jon Mason98f45da2010-07-15 08:47:25 +0000878 netif_tx_stop_queue(fifo->txq);
Benjamin LaHaise4403b372009-08-04 10:20:44 +0000879
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000880 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
881 if (unlikely(status != VXGE_HW_OK)) {
882 vxge_debug_tx(VXGE_ERR,
883 "%s: Out of descriptors .", dev->name);
884 fifo->stats.txd_out_of_desc++;
Jon Mason98f45da2010-07-15 08:47:25 +0000885 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000886 }
887
888 vxge_debug_tx(VXGE_TRACE,
889 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
890 dev->name, __func__, __LINE__,
891 fifo_hw, dtr, dtr_priv);
892
Jesse Grosseab6d182010-10-20 13:56:03 +0000893 if (vlan_tx_tag_present(skb)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000894 u16 vlan_tag = vlan_tx_tag_get(skb);
895 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
896 }
897
898 first_frg_len = skb_headlen(skb);
899
900 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
901 PCI_DMA_TODEVICE);
902
903 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
904 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000905 fifo->stats.pci_map_fail++;
Jon Mason98f45da2010-07-15 08:47:25 +0000906 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000907 }
908
909 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
910 txdl_priv->skb = skb;
911 txdl_priv->dma_buffers[j] = dma_pointer;
912
913 frg_cnt = skb_shinfo(skb)->nr_frags;
914 vxge_debug_tx(VXGE_TRACE,
915 "%s: %s:%d skb = %p txdl_priv = %p "
916 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
917 __func__, __LINE__, skb, txdl_priv,
918 frg_cnt, (unsigned long long)dma_pointer);
919
920 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
921 first_frg_len);
922
923 frag = &skb_shinfo(skb)->frags[0];
924 for (i = 0; i < frg_cnt; i++) {
925 /* ignore 0 length fragment */
Eric Dumazet9e903e02011-10-18 21:00:24 +0000926 if (!skb_frag_size(frag))
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000927 continue;
928
Ian Campbell94d60a72011-10-05 17:35:34 -0400929 dma_pointer = (u64)skb_frag_dma_map(&fifo->pdev->dev, frag,
Eric Dumazet9e903e02011-10-18 21:00:24 +0000930 0, skb_frag_size(frag),
Ian Campbell94d60a72011-10-05 17:35:34 -0400931 DMA_TO_DEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000932
Ian Campbell94d60a72011-10-05 17:35:34 -0400933 if (unlikely(dma_mapping_error(&fifo->pdev->dev, dma_pointer)))
Jon Mason98f45da2010-07-15 08:47:25 +0000934 goto _exit2;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000935 vxge_debug_tx(VXGE_TRACE,
936 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
937 dev->name, __func__, __LINE__, i,
938 (unsigned long long)dma_pointer);
939
940 txdl_priv->dma_buffers[j] = dma_pointer;
941 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
Eric Dumazet9e903e02011-10-18 21:00:24 +0000942 skb_frag_size(frag));
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000943 frag += 1;
944 }
945
946 offload_type = vxge_offload_type(skb);
947
948 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000949 int mss = vxge_tcp_mss(skb);
950 if (mss) {
Jon Mason98f45da2010-07-15 08:47:25 +0000951 vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000952 dev->name, __func__, __LINE__, mss);
953 vxge_hw_fifo_txdl_mss_set(dtr, mss);
954 } else {
955 vxge_assert(skb->len <=
956 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
957 vxge_assert(0);
958 goto _exit1;
959 }
960 }
961
962 if (skb->ip_summed == CHECKSUM_PARTIAL)
963 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
964 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
965 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
966 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
967
968 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000969
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000970 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
971 dev->name, __func__, __LINE__);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000972 return NETDEV_TX_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000973
Jon Mason98f45da2010-07-15 08:47:25 +0000974_exit2:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000975 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000976_exit1:
977 j = 0;
978 frag = &skb_shinfo(skb)->frags[0];
979
980 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
981 skb_headlen(skb), PCI_DMA_TODEVICE);
982
983 for (; j < i; j++) {
984 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
Eric Dumazet9e903e02011-10-18 21:00:24 +0000985 skb_frag_size(frag), PCI_DMA_TODEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000986 frag += 1;
987 }
988
989 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
Jon Mason98f45da2010-07-15 08:47:25 +0000990_exit0:
991 netif_tx_stop_queue(fifo->txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000992 dev_kfree_skb(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000993
Patrick McHardy6ed10652009-06-23 06:03:08 +0000994 return NETDEV_TX_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000995}
996
997/*
998 * vxge_rx_term
999 *
1000 * Function will be called by hw function to abort all outstanding receive
1001 * descriptors.
1002 */
1003static void
1004vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1005{
1006 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1007 struct vxge_rx_priv *rx_priv =
1008 vxge_hw_ring_rxd_private_get(dtrh);
1009
1010 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1011 ring->ndev->name, __func__, __LINE__);
1012 if (state != VXGE_HW_RXD_STATE_POSTED)
1013 return;
1014
1015 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1016 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1017
1018 dev_kfree_skb(rx_priv->skb);
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +00001019 rx_priv->skb_data = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001020
1021 vxge_debug_entryexit(VXGE_TRACE,
1022 "%s: %s:%d Exiting...",
1023 ring->ndev->name, __func__, __LINE__);
1024}
1025
1026/*
1027 * vxge_tx_term
1028 *
1029 * Function will be called to abort all outstanding tx descriptors
1030 */
1031static void
1032vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1033{
1034 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1035 skb_frag_t *frag;
1036 int i = 0, j, frg_cnt;
1037 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1038 struct sk_buff *skb = txd_priv->skb;
1039
1040 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1041
1042 if (state != VXGE_HW_TXDL_STATE_POSTED)
1043 return;
1044
1045 /* check skb validity */
1046 vxge_assert(skb);
1047 frg_cnt = skb_shinfo(skb)->nr_frags;
1048 frag = &skb_shinfo(skb)->frags[0];
1049
1050 /* for unfragmented skb */
1051 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1052 skb_headlen(skb), PCI_DMA_TODEVICE);
1053
1054 for (j = 0; j < frg_cnt; j++) {
1055 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
Eric Dumazet9e903e02011-10-18 21:00:24 +00001056 skb_frag_size(frag), PCI_DMA_TODEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001057 frag += 1;
1058 }
1059
1060 dev_kfree_skb(skb);
1061
1062 vxge_debug_entryexit(VXGE_TRACE,
1063 "%s:%d Exiting...", __func__, __LINE__);
1064}
1065
Jon Mason528f7272010-12-10 14:02:56 +00001066static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1067{
1068 struct list_head *entry, *next;
1069 u64 del_mac = 0;
1070 u8 *mac_address = (u8 *) (&del_mac);
1071
1072 /* Copy the mac address to delete from the list */
1073 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1074
1075 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1076 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1077 list_del(entry);
1078 kfree((struct vxge_mac_addrs *)entry);
1079 vpath->mac_addr_cnt--;
1080
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001081 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +00001082 vpath->mcast_addr_cnt--;
1083 return TRUE;
1084 }
1085 }
1086
1087 return FALSE;
1088}
1089
1090/* delete a mac address from DA table */
1091static enum vxge_hw_status
1092vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1093{
1094 enum vxge_hw_status status = VXGE_HW_OK;
1095 struct vxge_vpath *vpath;
1096
1097 vpath = &vdev->vpaths[mac->vpath_no];
1098 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1099 mac->macmask);
1100 if (status != VXGE_HW_OK) {
1101 vxge_debug_init(VXGE_ERR,
1102 "DA config delete entry failed for vpath:%d",
1103 vpath->device_id);
1104 } else
1105 vxge_mac_list_del(vpath, mac);
1106 return status;
1107}
1108
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001109/**
1110 * vxge_set_multicast
1111 * @dev: pointer to the device structure
1112 *
1113 * Entry point for multicast address enable/disable
1114 * This function is a driver entry point which gets called by the kernel
1115 * whenever multicast addresses must be enabled/disabled. This also gets
1116 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1117 * determine, if multicast address must be enabled or if promiscuous mode
1118 * is to be disabled etc.
1119 */
1120static void vxge_set_multicast(struct net_device *dev)
1121{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001122 struct netdev_hw_addr *ha;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001123 struct vxgedev *vdev;
1124 int i, mcast_cnt = 0;
Jon Mason7adf7d12010-07-15 08:47:24 +00001125 struct __vxge_hw_device *hldev;
1126 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001127 enum vxge_hw_status status = VXGE_HW_OK;
1128 struct macInfo mac_info;
1129 int vpath_idx = 0;
1130 struct vxge_mac_addrs *mac_entry;
1131 struct list_head *list_head;
1132 struct list_head *entry, *next;
1133 u8 *mac_address = NULL;
1134
1135 vxge_debug_entryexit(VXGE_TRACE,
1136 "%s:%d", __func__, __LINE__);
1137
Joe Perches5f54ceb2010-11-15 11:12:30 +00001138 vdev = netdev_priv(dev);
Joe Perches64699332012-06-04 12:44:16 +00001139 hldev = vdev->devh;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001140
1141 if (unlikely(!is_vxge_card_up(vdev)))
1142 return;
1143
1144 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1145 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001146 vpath = &vdev->vpaths[i];
1147 vxge_assert(vpath->is_open);
1148 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1149 if (status != VXGE_HW_OK)
1150 vxge_debug_init(VXGE_ERR, "failed to enable "
1151 "multicast, status %d", status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001152 vdev->all_multi_flg = 1;
1153 }
Jon Mason7adf7d12010-07-15 08:47:24 +00001154 } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001155 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001156 vpath = &vdev->vpaths[i];
1157 vxge_assert(vpath->is_open);
1158 status = vxge_hw_vpath_mcast_disable(vpath->handle);
1159 if (status != VXGE_HW_OK)
1160 vxge_debug_init(VXGE_ERR, "failed to disable "
1161 "multicast, status %d", status);
1162 vdev->all_multi_flg = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001163 }
1164 }
1165
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001166
1167 if (!vdev->config.addr_learn_en) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001168 for (i = 0; i < vdev->no_of_vpath; i++) {
1169 vpath = &vdev->vpaths[i];
1170 vxge_assert(vpath->is_open);
1171
1172 if (dev->flags & IFF_PROMISC)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001173 status = vxge_hw_vpath_promisc_enable(
Jon Mason7adf7d12010-07-15 08:47:24 +00001174 vpath->handle);
1175 else
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001176 status = vxge_hw_vpath_promisc_disable(
Jon Mason7adf7d12010-07-15 08:47:24 +00001177 vpath->handle);
1178 if (status != VXGE_HW_OK)
1179 vxge_debug_init(VXGE_ERR, "failed to %s promisc"
1180 ", status %d", dev->flags&IFF_PROMISC ?
1181 "enable" : "disable", status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001182 }
1183 }
1184
1185 memset(&mac_info, 0, sizeof(struct macInfo));
1186 /* Update individual M_CAST address list */
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001187 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001188 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1189 list_head = &vdev->vpaths[0].mac_addr_list;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001190 if ((netdev_mc_count(dev) +
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001191 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1192 vdev->vpaths[0].max_mac_addr_cnt)
1193 goto _set_all_mcast;
1194
1195 /* Delete previous MC's */
1196 for (i = 0; i < mcast_cnt; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001197 list_for_each_safe(entry, next, list_head) {
Jon Mason2c913082010-11-11 04:26:03 +00001198 mac_entry = (struct vxge_mac_addrs *)entry;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001199 /* Copy the mac address to delete */
1200 mac_address = (u8 *)&mac_entry->macaddr;
1201 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1202
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001203 if (is_multicast_ether_addr(mac_info.macaddr)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001204 for (vpath_idx = 0; vpath_idx <
1205 vdev->no_of_vpath;
1206 vpath_idx++) {
1207 mac_info.vpath_no = vpath_idx;
1208 status = vxge_del_mac_addr(
1209 vdev,
1210 &mac_info);
1211 }
1212 }
1213 }
1214 }
1215
1216 /* Add new ones */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001217 netdev_for_each_mc_addr(ha, dev) {
1218 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001219 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1220 vpath_idx++) {
1221 mac_info.vpath_no = vpath_idx;
1222 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1223 status = vxge_add_mac_addr(vdev, &mac_info);
1224 if (status != VXGE_HW_OK) {
1225 vxge_debug_init(VXGE_ERR,
1226 "%s:%d Setting individual"
1227 "multicast address failed",
1228 __func__, __LINE__);
1229 goto _set_all_mcast;
1230 }
1231 }
1232 }
1233
1234 return;
1235_set_all_mcast:
1236 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1237 /* Delete previous MC's */
1238 for (i = 0; i < mcast_cnt; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001239 list_for_each_safe(entry, next, list_head) {
Jon Mason2c913082010-11-11 04:26:03 +00001240 mac_entry = (struct vxge_mac_addrs *)entry;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001241 /* Copy the mac address to delete */
1242 mac_address = (u8 *)&mac_entry->macaddr;
1243 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1244
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001245 if (is_multicast_ether_addr(mac_info.macaddr))
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001246 break;
1247 }
1248
1249 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1250 vpath_idx++) {
1251 mac_info.vpath_no = vpath_idx;
1252 status = vxge_del_mac_addr(vdev, &mac_info);
1253 }
1254 }
1255
1256 /* Enable all multicast */
1257 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001258 vpath = &vdev->vpaths[i];
1259 vxge_assert(vpath->is_open);
1260
1261 status = vxge_hw_vpath_mcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001262 if (status != VXGE_HW_OK) {
1263 vxge_debug_init(VXGE_ERR,
1264 "%s:%d Enabling all multicasts failed",
1265 __func__, __LINE__);
1266 }
1267 vdev->all_multi_flg = 1;
1268 }
1269 dev->flags |= IFF_ALLMULTI;
1270 }
1271
1272 vxge_debug_entryexit(VXGE_TRACE,
1273 "%s:%d Exiting...", __func__, __LINE__);
1274}
1275
1276/**
1277 * vxge_set_mac_addr
1278 * @dev: pointer to the device structure
1279 *
1280 * Update entry "0" (default MAC addr)
1281 */
1282static int vxge_set_mac_addr(struct net_device *dev, void *p)
1283{
1284 struct sockaddr *addr = p;
1285 struct vxgedev *vdev;
Jon Mason2c913082010-11-11 04:26:03 +00001286 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001287 enum vxge_hw_status status = VXGE_HW_OK;
1288 struct macInfo mac_info_new, mac_info_old;
1289 int vpath_idx = 0;
1290
1291 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1292
Joe Perches5f54ceb2010-11-15 11:12:30 +00001293 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001294 hldev = vdev->devh;
1295
1296 if (!is_valid_ether_addr(addr->sa_data))
1297 return -EINVAL;
1298
1299 memset(&mac_info_new, 0, sizeof(struct macInfo));
1300 memset(&mac_info_old, 0, sizeof(struct macInfo));
1301
1302 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1303 __func__, __LINE__);
1304
1305 /* Get the old address */
1306 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1307
1308 /* Copy the new address */
1309 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1310
1311 /* First delete the old mac address from all the vpaths
1312 as we can't specify the index while adding new mac address */
1313 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1314 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1315 if (!vpath->is_open) {
1316 /* This can happen when this interface is added/removed
1317 to the bonding interface. Delete this station address
1318 from the linked list */
1319 vxge_mac_list_del(vpath, &mac_info_old);
1320
1321 /* Add this new address to the linked list
1322 for later restoring */
1323 vxge_mac_list_add(vpath, &mac_info_new);
1324
1325 continue;
1326 }
1327 /* Delete the station address */
1328 mac_info_old.vpath_no = vpath_idx;
1329 status = vxge_del_mac_addr(vdev, &mac_info_old);
1330 }
1331
1332 if (unlikely(!is_vxge_card_up(vdev))) {
1333 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1334 return VXGE_HW_OK;
1335 }
1336
1337 /* Set this mac address to all the vpaths */
1338 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1339 mac_info_new.vpath_no = vpath_idx;
1340 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1341 status = vxge_add_mac_addr(vdev, &mac_info_new);
1342 if (status != VXGE_HW_OK)
1343 return -EINVAL;
1344 }
1345
1346 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1347
1348 return status;
1349}
1350
1351/*
1352 * vxge_vpath_intr_enable
1353 * @vdev: pointer to vdev
1354 * @vp_id: vpath for which to enable the interrupts
1355 *
1356 * Enables the interrupts for the vpath
1357*/
stephen hemminger42821a52010-10-21 07:50:53 +00001358static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001359{
1360 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001361 int msix_id = 0;
1362 int tim_msix_id[4] = {0, 1, 0, 0};
1363 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001364
1365 vxge_hw_vpath_intr_enable(vpath->handle);
1366
1367 if (vdev->config.intr_type == INTA)
1368 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1369 else {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001370 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1371 alarm_msix_id);
1372
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001373 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001374 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1375 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1376
1377 /* enable the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001378 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1379 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1380 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001381 }
1382}
1383
1384/*
1385 * vxge_vpath_intr_disable
1386 * @vdev: pointer to vdev
1387 * @vp_id: vpath for which to disable the interrupts
1388 *
1389 * Disables the interrupts for the vpath
1390*/
stephen hemminger42821a52010-10-21 07:50:53 +00001391static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001392{
1393 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Jon Mason4d2a5b42010-11-11 04:25:54 +00001394 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001395 int msix_id;
1396
Joe Perchesd8ee7072010-11-15 10:13:58 +00001397 hldev = pci_get_drvdata(vdev->pdev);
Jon Mason4d2a5b42010-11-11 04:25:54 +00001398
1399 vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
1400
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001401 vxge_hw_vpath_intr_disable(vpath->handle);
1402
1403 if (vdev->config.intr_type == INTA)
1404 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1405 else {
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001406 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001407 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1408 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1409
1410 /* disable the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001411 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1412 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001413 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1414 }
1415}
1416
Jon Mason528f7272010-12-10 14:02:56 +00001417/* list all mac addresses from DA table */
1418static enum vxge_hw_status
1419vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, struct macInfo *mac)
1420{
1421 enum vxge_hw_status status = VXGE_HW_OK;
1422 unsigned char macmask[ETH_ALEN];
1423 unsigned char macaddr[ETH_ALEN];
1424
1425 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1426 macaddr, macmask);
1427 if (status != VXGE_HW_OK) {
1428 vxge_debug_init(VXGE_ERR,
1429 "DA config list entry failed for vpath:%d",
1430 vpath->device_id);
1431 return status;
1432 }
1433
dingtianhongf75d1912013-12-30 15:41:02 +08001434 while (!ether_addr_equal(mac->macaddr, macaddr)) {
Jon Mason528f7272010-12-10 14:02:56 +00001435 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1436 macaddr, macmask);
1437 if (status != VXGE_HW_OK)
1438 break;
1439 }
1440
1441 return status;
1442}
1443
1444/* Store all mac addresses from the list to the DA table */
1445static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1446{
1447 enum vxge_hw_status status = VXGE_HW_OK;
1448 struct macInfo mac_info;
1449 u8 *mac_address = NULL;
1450 struct list_head *entry, *next;
1451
1452 memset(&mac_info, 0, sizeof(struct macInfo));
1453
1454 if (vpath->is_open) {
1455 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1456 mac_address =
1457 (u8 *)&
1458 ((struct vxge_mac_addrs *)entry)->macaddr;
1459 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1460 ((struct vxge_mac_addrs *)entry)->state =
1461 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1462 /* does this mac address already exist in da table? */
1463 status = vxge_search_mac_addr_in_da_table(vpath,
1464 &mac_info);
1465 if (status != VXGE_HW_OK) {
1466 /* Add this mac address to the DA table */
1467 status = vxge_hw_vpath_mac_addr_add(
1468 vpath->handle, mac_info.macaddr,
1469 mac_info.macmask,
1470 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
1471 if (status != VXGE_HW_OK) {
1472 vxge_debug_init(VXGE_ERR,
1473 "DA add entry failed for vpath:%d",
1474 vpath->device_id);
1475 ((struct vxge_mac_addrs *)entry)->state
1476 = VXGE_LL_MAC_ADDR_IN_LIST;
1477 }
1478 }
1479 }
1480 }
1481
1482 return status;
1483}
1484
1485/* Store all vlan ids from the list to the vid table */
1486static enum vxge_hw_status
1487vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1488{
1489 enum vxge_hw_status status = VXGE_HW_OK;
1490 struct vxgedev *vdev = vpath->vdev;
1491 u16 vid;
1492
Jiri Pirko53515732011-07-20 04:54:40 +00001493 if (!vpath->is_open)
1494 return status;
Jon Mason528f7272010-12-10 14:02:56 +00001495
Jiri Pirko53515732011-07-20 04:54:40 +00001496 for_each_set_bit(vid, vdev->active_vlans, VLAN_N_VID)
1497 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
Jon Mason528f7272010-12-10 14:02:56 +00001498
1499 return status;
1500}
1501
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001502/*
1503 * vxge_reset_vpath
1504 * @vdev: pointer to vdev
1505 * @vp_id: vpath to reset
1506 *
1507 * Resets the vpath
1508*/
1509static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1510{
1511 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00001512 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001513 int ret = 0;
1514
1515 /* check if device is down already */
1516 if (unlikely(!is_vxge_card_up(vdev)))
1517 return 0;
1518
1519 /* is device reset already scheduled */
1520 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1521 return 0;
1522
Jon Mason7adf7d12010-07-15 08:47:24 +00001523 if (vpath->handle) {
1524 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001525 if (is_vxge_card_up(vdev) &&
Jon Mason7adf7d12010-07-15 08:47:24 +00001526 vxge_hw_vpath_recover_from_reset(vpath->handle)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001527 != VXGE_HW_OK) {
1528 vxge_debug_init(VXGE_ERR,
1529 "vxge_hw_vpath_recover_from_reset"
1530 "failed for vpath:%d", vp_id);
1531 return status;
1532 }
1533 } else {
1534 vxge_debug_init(VXGE_ERR,
1535 "vxge_hw_vpath_reset failed for"
1536 "vpath:%d", vp_id);
1537 return status;
1538 }
1539 } else
1540 return VXGE_HW_FAIL;
1541
Jon Mason7adf7d12010-07-15 08:47:24 +00001542 vxge_restore_vpath_mac_addr(vpath);
1543 vxge_restore_vpath_vid_table(vpath);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001544
1545 /* Enable all broadcast */
Jon Mason7adf7d12010-07-15 08:47:24 +00001546 vxge_hw_vpath_bcast_enable(vpath->handle);
1547
1548 /* Enable all multicast */
1549 if (vdev->all_multi_flg) {
1550 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1551 if (status != VXGE_HW_OK)
1552 vxge_debug_init(VXGE_ERR,
1553 "%s:%d Enabling multicast failed",
1554 __func__, __LINE__);
1555 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001556
1557 /* Enable the interrupts */
1558 vxge_vpath_intr_enable(vdev, vp_id);
1559
1560 smp_wmb();
1561
1562 /* Enable the flow of traffic through the vpath */
Jon Mason7adf7d12010-07-15 08:47:24 +00001563 vxge_hw_vpath_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001564
1565 smp_wmb();
Jon Mason7adf7d12010-07-15 08:47:24 +00001566 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
1567 vpath->ring.last_status = VXGE_HW_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001568
1569 /* Vpath reset done */
1570 clear_bit(vp_id, &vdev->vp_reset);
1571
1572 /* Start the vpath queue */
Jon Mason98f45da2010-07-15 08:47:25 +00001573 if (netif_tx_queue_stopped(vpath->fifo.txq))
1574 netif_tx_wake_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001575
1576 return ret;
1577}
1578
Jon Mason16fded72011-01-18 15:02:21 +00001579/* Configure CI */
1580static void vxge_config_ci_for_tti_rti(struct vxgedev *vdev)
1581{
1582 int i = 0;
1583
1584 /* Enable CI for RTI */
1585 if (vdev->config.intr_type == MSI_X) {
1586 for (i = 0; i < vdev->no_of_vpath; i++) {
1587 struct __vxge_hw_ring *hw_ring;
1588
1589 hw_ring = vdev->vpaths[i].ring.handle;
1590 vxge_hw_vpath_dynamic_rti_ci_set(hw_ring);
1591 }
1592 }
1593
1594 /* Enable CI for TTI */
1595 for (i = 0; i < vdev->no_of_vpath; i++) {
1596 struct __vxge_hw_fifo *hw_fifo = vdev->vpaths[i].fifo.handle;
1597 vxge_hw_vpath_tti_ci_set(hw_fifo);
1598 /*
1599 * For Inta (with or without napi), Set CI ON for only one
1600 * vpath. (Have only one free running timer).
1601 */
1602 if ((vdev->config.intr_type == INTA) && (i == 0))
1603 break;
1604 }
1605
1606 return;
1607}
1608
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001609static int do_vxge_reset(struct vxgedev *vdev, int event)
1610{
1611 enum vxge_hw_status status;
1612 int ret = 0, vp_id, i;
1613
1614 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1615
1616 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1617 /* check if device is down already */
1618 if (unlikely(!is_vxge_card_up(vdev)))
1619 return 0;
1620
1621 /* is reset already scheduled */
1622 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1623 return 0;
1624 }
1625
1626 if (event == VXGE_LL_FULL_RESET) {
Jon Mason2e41f642010-12-10 14:02:59 +00001627 netif_carrier_off(vdev->ndev);
1628
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001629 /* wait for all the vpath reset to complete */
1630 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1631 while (test_bit(vp_id, &vdev->vp_reset))
1632 msleep(50);
1633 }
1634
Jon Mason2e41f642010-12-10 14:02:59 +00001635 netif_carrier_on(vdev->ndev);
1636
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001637 /* if execution mode is set to debug, don't reset the adapter */
1638 if (unlikely(vdev->exec_mode)) {
1639 vxge_debug_init(VXGE_ERR,
1640 "%s: execution mode is debug, returning..",
1641 vdev->ndev->name);
Jon Mason7adf7d12010-07-15 08:47:24 +00001642 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1643 netif_tx_stop_all_queues(vdev->ndev);
1644 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001645 }
1646 }
1647
1648 if (event == VXGE_LL_FULL_RESET) {
Jon Mason4d2a5b42010-11-11 04:25:54 +00001649 vxge_hw_device_wait_receive_idle(vdev->devh);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001650 vxge_hw_device_intr_disable(vdev->devh);
1651
1652 switch (vdev->cric_err_event) {
1653 case VXGE_HW_EVENT_UNKNOWN:
Jon Masond03848e2010-07-15 08:47:23 +00001654 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001655 vxge_debug_init(VXGE_ERR,
1656 "fatal: %s: Disabling device due to"
1657 "unknown error",
1658 vdev->ndev->name);
1659 ret = -EPERM;
1660 goto out;
1661 case VXGE_HW_EVENT_RESET_START:
1662 break;
1663 case VXGE_HW_EVENT_RESET_COMPLETE:
1664 case VXGE_HW_EVENT_LINK_DOWN:
1665 case VXGE_HW_EVENT_LINK_UP:
1666 case VXGE_HW_EVENT_ALARM_CLEARED:
1667 case VXGE_HW_EVENT_ECCERR:
1668 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1669 ret = -EPERM;
1670 goto out;
1671 case VXGE_HW_EVENT_FIFO_ERR:
1672 case VXGE_HW_EVENT_VPATH_ERR:
1673 break;
1674 case VXGE_HW_EVENT_CRITICAL_ERR:
Jon Masond03848e2010-07-15 08:47:23 +00001675 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001676 vxge_debug_init(VXGE_ERR,
1677 "fatal: %s: Disabling device due to"
1678 "serious error",
1679 vdev->ndev->name);
1680 /* SOP or device reset required */
1681 /* This event is not currently used */
1682 ret = -EPERM;
1683 goto out;
1684 case VXGE_HW_EVENT_SERR:
Jon Masond03848e2010-07-15 08:47:23 +00001685 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001686 vxge_debug_init(VXGE_ERR,
1687 "fatal: %s: Disabling device due to"
1688 "serious error",
1689 vdev->ndev->name);
1690 ret = -EPERM;
1691 goto out;
1692 case VXGE_HW_EVENT_SRPCIM_SERR:
1693 case VXGE_HW_EVENT_MRPCIM_SERR:
1694 ret = -EPERM;
1695 goto out;
1696 case VXGE_HW_EVENT_SLOT_FREEZE:
Jon Masond03848e2010-07-15 08:47:23 +00001697 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001698 vxge_debug_init(VXGE_ERR,
1699 "fatal: %s: Disabling device due to"
1700 "slot freeze",
1701 vdev->ndev->name);
1702 ret = -EPERM;
1703 goto out;
1704 default:
1705 break;
1706
1707 }
1708 }
1709
1710 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
Jon Masond03848e2010-07-15 08:47:23 +00001711 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001712
1713 if (event == VXGE_LL_FULL_RESET) {
1714 status = vxge_reset_all_vpaths(vdev);
1715 if (status != VXGE_HW_OK) {
1716 vxge_debug_init(VXGE_ERR,
1717 "fatal: %s: can not reset vpaths",
1718 vdev->ndev->name);
1719 ret = -EPERM;
1720 goto out;
1721 }
1722 }
1723
1724 if (event == VXGE_LL_COMPL_RESET) {
1725 for (i = 0; i < vdev->no_of_vpath; i++)
1726 if (vdev->vpaths[i].handle) {
1727 if (vxge_hw_vpath_recover_from_reset(
1728 vdev->vpaths[i].handle)
1729 != VXGE_HW_OK) {
1730 vxge_debug_init(VXGE_ERR,
1731 "vxge_hw_vpath_recover_"
1732 "from_reset failed for vpath: "
1733 "%d", i);
1734 ret = -EPERM;
1735 goto out;
1736 }
1737 } else {
1738 vxge_debug_init(VXGE_ERR,
1739 "vxge_hw_vpath_reset failed for "
1740 "vpath:%d", i);
1741 ret = -EPERM;
1742 goto out;
1743 }
1744 }
1745
1746 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1747 /* Reprogram the DA table with populated mac addresses */
1748 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1749 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1750 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1751 }
1752
1753 /* enable vpath interrupts */
1754 for (i = 0; i < vdev->no_of_vpath; i++)
1755 vxge_vpath_intr_enable(vdev, i);
1756
1757 vxge_hw_device_intr_enable(vdev->devh);
1758
1759 smp_wmb();
1760
1761 /* Indicate card up */
1762 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1763
1764 /* Get the traffic to flow through the vpaths */
1765 for (i = 0; i < vdev->no_of_vpath; i++) {
1766 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1767 smp_wmb();
1768 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1769 }
1770
Jon Masond03848e2010-07-15 08:47:23 +00001771 netif_tx_wake_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001772 }
1773
Jon Mason16fded72011-01-18 15:02:21 +00001774 /* configure CI */
1775 vxge_config_ci_for_tti_rti(vdev);
1776
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001777out:
1778 vxge_debug_entryexit(VXGE_TRACE,
1779 "%s:%d Exiting...", __func__, __LINE__);
1780
1781 /* Indicate reset done */
1782 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1783 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1784 return ret;
1785}
1786
1787/*
1788 * vxge_reset
1789 * @vdev: pointer to ll device
1790 *
1791 * driver may reset the chip on events of serr, eccerr, etc
1792 */
Jon Mason2e41f642010-12-10 14:02:59 +00001793static void vxge_reset(struct work_struct *work)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001794{
Jon Mason2e41f642010-12-10 14:02:59 +00001795 struct vxgedev *vdev = container_of(work, struct vxgedev, reset_task);
1796
1797 if (!netif_running(vdev->ndev))
1798 return;
1799
1800 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001801}
1802
1803/**
1804 * vxge_poll - Receive handler when Receive Polling is used.
1805 * @dev: pointer to the device structure.
1806 * @budget: Number of packets budgeted to be processed in this iteration.
1807 *
1808 * This function comes into picture only if Receive side is being handled
1809 * through polling (called NAPI in linux). It mostly does what the normal
1810 * Rx interrupt handler does in terms of descriptor and packet processing
1811 * but not in an interrupt context. Also it will process a specified number
1812 * of packets at most in one iteration. This value is passed down by the
1813 * kernel as the function argument 'budget'.
1814 */
1815static int vxge_poll_msix(struct napi_struct *napi, int budget)
1816{
Jon Mason16fded72011-01-18 15:02:21 +00001817 struct vxge_ring *ring = container_of(napi, struct vxge_ring, napi);
1818 int pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001819 int budget_org = budget;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001820
Jon Mason16fded72011-01-18 15:02:21 +00001821 ring->budget = budget;
1822 ring->pkts_processed = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001823 vxge_hw_vpath_poll_rx(ring->handle);
Jon Mason16fded72011-01-18 15:02:21 +00001824 pkts_processed = ring->pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001825
1826 if (ring->pkts_processed < budget_org) {
1827 napi_complete(napi);
Jon Mason16fded72011-01-18 15:02:21 +00001828
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001829 /* Re enable the Rx interrupts for the vpath */
1830 vxge_hw_channel_msix_unmask(
1831 (struct __vxge_hw_channel *)ring->handle,
1832 ring->rx_vector_no);
Jon Mason16fded72011-01-18 15:02:21 +00001833 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001834 }
1835
Jon Mason16fded72011-01-18 15:02:21 +00001836 /* We are copying and returning the local variable, in case if after
1837 * clearing the msix interrupt above, if the interrupt fires right
1838 * away which can preempt this NAPI thread */
1839 return pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001840}
1841
1842static int vxge_poll_inta(struct napi_struct *napi, int budget)
1843{
1844 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1845 int pkts_processed = 0;
1846 int i;
1847 int budget_org = budget;
1848 struct vxge_ring *ring;
1849
Joe Perchesd8ee7072010-11-15 10:13:58 +00001850 struct __vxge_hw_device *hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001851
1852 for (i = 0; i < vdev->no_of_vpath; i++) {
1853 ring = &vdev->vpaths[i].ring;
1854 ring->budget = budget;
Jon Mason16fded72011-01-18 15:02:21 +00001855 ring->pkts_processed = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001856 vxge_hw_vpath_poll_rx(ring->handle);
1857 pkts_processed += ring->pkts_processed;
1858 budget -= ring->pkts_processed;
1859 if (budget <= 0)
1860 break;
1861 }
1862
1863 VXGE_COMPLETE_ALL_TX(vdev);
1864
1865 if (pkts_processed < budget_org) {
1866 napi_complete(napi);
1867 /* Re enable the Rx interrupts for the ring */
1868 vxge_hw_device_unmask_all(hldev);
1869 vxge_hw_device_flush_io(hldev);
1870 }
1871
1872 return pkts_processed;
1873}
1874
1875#ifdef CONFIG_NET_POLL_CONTROLLER
1876/**
1877 * vxge_netpoll - netpoll event handler entry point
1878 * @dev : pointer to the device structure.
1879 * Description:
1880 * This function will be called by upper layer to check for events on the
1881 * interface in situations where interrupts are disabled. It is used for
1882 * specific in-kernel networking tasks, such as remote consoles and kernel
1883 * debugging over the network (example netdump in RedHat).
1884 */
1885static void vxge_netpoll(struct net_device *dev)
1886{
Francois Romieu32e819e2012-03-09 19:37:55 +01001887 struct vxgedev *vdev = netdev_priv(dev);
1888 struct pci_dev *pdev = vdev->pdev;
1889 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
1890 const int irq = pdev->irq;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001891
1892 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1893
Francois Romieu32e819e2012-03-09 19:37:55 +01001894 if (pci_channel_offline(pdev))
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001895 return;
1896
Francois Romieu32e819e2012-03-09 19:37:55 +01001897 disable_irq(irq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001898 vxge_hw_device_clear_tx_rx(hldev);
1899
1900 vxge_hw_device_clear_tx_rx(hldev);
1901 VXGE_COMPLETE_ALL_RX(vdev);
1902 VXGE_COMPLETE_ALL_TX(vdev);
1903
Francois Romieu32e819e2012-03-09 19:37:55 +01001904 enable_irq(irq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001905
1906 vxge_debug_entryexit(VXGE_TRACE,
1907 "%s:%d Exiting...", __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001908}
1909#endif
1910
1911/* RTH configuration */
1912static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1913{
1914 enum vxge_hw_status status = VXGE_HW_OK;
1915 struct vxge_hw_rth_hash_types hash_types;
1916 u8 itable[256] = {0}; /* indirection table */
1917 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1918 int index;
1919
1920 /*
1921 * Filling
1922 * - itable with bucket numbers
1923 * - mtable with bucket-to-vpath mapping
1924 */
1925 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1926 itable[index] = index;
1927 mtable[index] = index % vdev->no_of_vpath;
1928 }
1929
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001930 /* set indirection table, bucket-to-vpath mapping */
1931 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1932 vdev->no_of_vpath,
1933 mtable, itable,
1934 vdev->config.rth_bkt_sz);
1935 if (status != VXGE_HW_OK) {
1936 vxge_debug_init(VXGE_ERR,
1937 "RTH indirection table configuration failed "
1938 "for vpath:%d", vdev->vpaths[0].device_id);
1939 return status;
1940 }
1941
Jon Mason47f01db2010-11-11 04:25:53 +00001942 /* Fill RTH hash types */
1943 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1944 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1945 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1946 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1947 hash_types.hash_type_tcpipv6ex_en =
1948 vdev->config.rth_hash_type_tcpipv6ex;
1949 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1950
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001951 /*
Jon Mason47f01db2010-11-11 04:25:53 +00001952 * Because the itable_set() method uses the active_table field
1953 * for the target virtual path the RTH config should be updated
1954 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1955 * when steering frames.
1956 */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001957 for (index = 0; index < vdev->no_of_vpath; index++) {
1958 status = vxge_hw_vpath_rts_rth_set(
1959 vdev->vpaths[index].handle,
1960 vdev->config.rth_algorithm,
1961 &hash_types,
1962 vdev->config.rth_bkt_sz);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001963 if (status != VXGE_HW_OK) {
1964 vxge_debug_init(VXGE_ERR,
1965 "RTH configuration failed for vpath:%d",
1966 vdev->vpaths[index].device_id);
1967 return status;
1968 }
1969 }
1970
1971 return status;
1972}
1973
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001974/* reset vpaths */
stephen hemmingere40c10f2014-01-15 08:28:54 -08001975static enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001976{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001977 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00001978 struct vxge_vpath *vpath;
1979 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001980
Jon Mason7adf7d12010-07-15 08:47:24 +00001981 for (i = 0; i < vdev->no_of_vpath; i++) {
1982 vpath = &vdev->vpaths[i];
1983 if (vpath->handle) {
1984 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001985 if (is_vxge_card_up(vdev) &&
1986 vxge_hw_vpath_recover_from_reset(
Jon Mason7adf7d12010-07-15 08:47:24 +00001987 vpath->handle) != VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001988 vxge_debug_init(VXGE_ERR,
1989 "vxge_hw_vpath_recover_"
1990 "from_reset failed for vpath: "
1991 "%d", i);
1992 return status;
1993 }
1994 } else {
1995 vxge_debug_init(VXGE_ERR,
1996 "vxge_hw_vpath_reset failed for "
1997 "vpath:%d", i);
1998 return status;
1999 }
2000 }
Jon Mason7adf7d12010-07-15 08:47:24 +00002001 }
2002
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002003 return status;
2004}
2005
2006/* close vpaths */
stephen hemminger42821a52010-10-21 07:50:53 +00002007static void vxge_close_vpaths(struct vxgedev *vdev, int index)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002008{
Jon Mason7adf7d12010-07-15 08:47:24 +00002009 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002010 int i;
Jon Mason7adf7d12010-07-15 08:47:24 +00002011
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002012 for (i = index; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002013 vpath = &vdev->vpaths[i];
2014
2015 if (vpath->handle && vpath->is_open) {
2016 vxge_hw_vpath_close(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002017 vdev->stats.vpaths_open--;
2018 }
Jon Mason7adf7d12010-07-15 08:47:24 +00002019 vpath->is_open = 0;
2020 vpath->handle = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002021 }
2022}
2023
2024/* open vpaths */
stephen hemminger42821a52010-10-21 07:50:53 +00002025static int vxge_open_vpaths(struct vxgedev *vdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002026{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002027 struct vxge_hw_vpath_attr attr;
Jon Mason7adf7d12010-07-15 08:47:24 +00002028 enum vxge_hw_status status;
2029 struct vxge_vpath *vpath;
2030 u32 vp_id = 0;
2031 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002032
2033 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002034 vpath = &vdev->vpaths[i];
Jon Mason7adf7d12010-07-15 08:47:24 +00002035 vxge_assert(vpath->is_configured);
Jon Masone7935c92010-11-11 04:26:00 +00002036
2037 if (!vdev->titan1) {
2038 struct vxge_hw_vp_config *vcfg;
2039 vcfg = &vdev->devh->config.vp_config[vpath->device_id];
2040
2041 vcfg->rti.urange_a = RTI_T1A_RX_URANGE_A;
2042 vcfg->rti.urange_b = RTI_T1A_RX_URANGE_B;
2043 vcfg->rti.urange_c = RTI_T1A_RX_URANGE_C;
2044 vcfg->tti.uec_a = TTI_T1A_TX_UFC_A;
2045 vcfg->tti.uec_b = TTI_T1A_TX_UFC_B;
2046 vcfg->tti.uec_c = TTI_T1A_TX_UFC_C(vdev->mtu);
2047 vcfg->tti.uec_d = TTI_T1A_TX_UFC_D(vdev->mtu);
2048 vcfg->tti.ltimer_val = VXGE_T1A_TTI_LTIMER_VAL;
2049 vcfg->tti.rtimer_val = VXGE_T1A_TTI_RTIMER_VAL;
2050 }
2051
Jon Mason7adf7d12010-07-15 08:47:24 +00002052 attr.vp_id = vpath->device_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002053 attr.fifo_attr.callback = vxge_xmit_compl;
2054 attr.fifo_attr.txdl_term = vxge_tx_term;
2055 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
Jon Mason7adf7d12010-07-15 08:47:24 +00002056 attr.fifo_attr.userdata = &vpath->fifo;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002057
2058 attr.ring_attr.callback = vxge_rx_1b_compl;
2059 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2060 attr.ring_attr.rxd_term = vxge_rx_term;
2061 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
Jon Mason7adf7d12010-07-15 08:47:24 +00002062 attr.ring_attr.userdata = &vpath->ring;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002063
Jon Mason7adf7d12010-07-15 08:47:24 +00002064 vpath->ring.ndev = vdev->ndev;
2065 vpath->ring.pdev = vdev->pdev;
Jon Mason528f7272010-12-10 14:02:56 +00002066
Jon Mason7adf7d12010-07-15 08:47:24 +00002067 status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002068 if (status == VXGE_HW_OK) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002069 vpath->fifo.handle =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002070 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
Jon Mason7adf7d12010-07-15 08:47:24 +00002071 vpath->ring.handle =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002072 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
Jon Mason7adf7d12010-07-15 08:47:24 +00002073 vpath->fifo.tx_steering_type =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002074 vdev->config.tx_steering_type;
Jon Mason7adf7d12010-07-15 08:47:24 +00002075 vpath->fifo.ndev = vdev->ndev;
2076 vpath->fifo.pdev = vdev->pdev;
John Stultz827da442013-10-07 15:51:58 -07002077
2078 u64_stats_init(&vpath->fifo.stats.syncp);
2079 u64_stats_init(&vpath->ring.stats.syncp);
2080
Jon Mason98f45da2010-07-15 08:47:25 +00002081 if (vdev->config.tx_steering_type)
2082 vpath->fifo.txq =
2083 netdev_get_tx_queue(vdev->ndev, i);
2084 else
2085 vpath->fifo.txq =
2086 netdev_get_tx_queue(vdev->ndev, 0);
Jon Mason7adf7d12010-07-15 08:47:24 +00002087 vpath->fifo.indicate_max_pkts =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002088 vdev->config.fifo_indicate_max_pkts;
Jon Mason16fded72011-01-18 15:02:21 +00002089 vpath->fifo.tx_vector_no = 0;
Jon Mason7adf7d12010-07-15 08:47:24 +00002090 vpath->ring.rx_vector_no = 0;
Jon Masonb81b3732010-11-11 04:25:58 +00002091 vpath->ring.rx_hwts = vdev->rx_hwts;
Jon Mason7adf7d12010-07-15 08:47:24 +00002092 vpath->is_open = 1;
2093 vdev->vp_handles[i] = vpath->handle;
Jon Mason7adf7d12010-07-15 08:47:24 +00002094 vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002095 vdev->stats.vpaths_open++;
2096 } else {
2097 vdev->stats.vpath_open_fail++;
Jon Mason528f7272010-12-10 14:02:56 +00002098 vxge_debug_init(VXGE_ERR, "%s: vpath: %d failed to "
2099 "open with status: %d",
2100 vdev->ndev->name, vpath->device_id,
2101 status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002102 vxge_close_vpaths(vdev, 0);
2103 return -EPERM;
2104 }
2105
Jon Mason7adf7d12010-07-15 08:47:24 +00002106 vp_id = vpath->handle->vpath->vp_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002107 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2108 }
Jon Mason528f7272010-12-10 14:02:56 +00002109
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002110 return VXGE_HW_OK;
2111}
2112
Jon Mason16fded72011-01-18 15:02:21 +00002113/**
2114 * adaptive_coalesce_tx_interrupts - Changes the interrupt coalescing
2115 * if the interrupts are not within a range
2116 * @fifo: pointer to transmit fifo structure
2117 * Description: The function changes boundary timer and restriction timer
2118 * value depends on the traffic
2119 * Return Value: None
2120 */
2121static void adaptive_coalesce_tx_interrupts(struct vxge_fifo *fifo)
2122{
2123 fifo->interrupt_count++;
2124 if (jiffies > fifo->jiffies + HZ / 100) {
2125 struct __vxge_hw_fifo *hw_fifo = fifo->handle;
2126
2127 fifo->jiffies = jiffies;
2128 if (fifo->interrupt_count > VXGE_T1A_MAX_TX_INTERRUPT_COUNT &&
2129 hw_fifo->rtimer != VXGE_TTI_RTIMER_ADAPT_VAL) {
2130 hw_fifo->rtimer = VXGE_TTI_RTIMER_ADAPT_VAL;
2131 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2132 } else if (hw_fifo->rtimer != 0) {
2133 hw_fifo->rtimer = 0;
2134 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2135 }
2136 fifo->interrupt_count = 0;
2137 }
2138}
2139
2140/**
2141 * adaptive_coalesce_rx_interrupts - Changes the interrupt coalescing
2142 * if the interrupts are not within a range
2143 * @ring: pointer to receive ring structure
2144 * Description: The function increases of decreases the packet counts within
2145 * the ranges of traffic utilization, if the interrupts due to this ring are
2146 * not within a fixed range.
2147 * Return Value: Nothing
2148 */
2149static void adaptive_coalesce_rx_interrupts(struct vxge_ring *ring)
2150{
2151 ring->interrupt_count++;
2152 if (jiffies > ring->jiffies + HZ / 100) {
2153 struct __vxge_hw_ring *hw_ring = ring->handle;
2154
2155 ring->jiffies = jiffies;
2156 if (ring->interrupt_count > VXGE_T1A_MAX_INTERRUPT_COUNT &&
2157 hw_ring->rtimer != VXGE_RTI_RTIMER_ADAPT_VAL) {
2158 hw_ring->rtimer = VXGE_RTI_RTIMER_ADAPT_VAL;
2159 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2160 } else if (hw_ring->rtimer != 0) {
2161 hw_ring->rtimer = 0;
2162 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2163 }
2164 ring->interrupt_count = 0;
2165 }
2166}
2167
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002168/*
2169 * vxge_isr_napi
2170 * @irq: the irq of the device.
2171 * @dev_id: a void pointer to the hldev structure of the Titan device
2172 * @ptregs: pointer to the registers pushed on the stack.
2173 *
2174 * This function is the ISR handler of the device when napi is enabled. It
2175 * identifies the reason for the interrupt and calls the relevant service
2176 * routines.
2177 */
2178static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2179{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002180 struct net_device *dev;
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002181 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002182 u64 reason;
2183 enum vxge_hw_status status;
Jon Mason2c913082010-11-11 04:26:03 +00002184 struct vxgedev *vdev = (struct vxgedev *)dev_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002185
2186 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2187
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002188 dev = vdev->ndev;
Joe Perchesd8ee7072010-11-15 10:13:58 +00002189 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002190
2191 if (pci_channel_offline(vdev->pdev))
2192 return IRQ_NONE;
2193
2194 if (unlikely(!is_vxge_card_up(vdev)))
Jon Mason4d2a5b42010-11-11 04:25:54 +00002195 return IRQ_HANDLED;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002196
Jon Mason528f7272010-12-10 14:02:56 +00002197 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, &reason);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002198 if (status == VXGE_HW_OK) {
2199 vxge_hw_device_mask_all(hldev);
2200
2201 if (reason &
2202 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2203 vdev->vpaths_deployed >>
2204 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2205
2206 vxge_hw_device_clear_tx_rx(hldev);
2207 napi_schedule(&vdev->napi);
2208 vxge_debug_intr(VXGE_TRACE,
2209 "%s:%d Exiting...", __func__, __LINE__);
2210 return IRQ_HANDLED;
2211 } else
2212 vxge_hw_device_unmask_all(hldev);
2213 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2214 (status == VXGE_HW_ERR_CRITICAL) ||
2215 (status == VXGE_HW_ERR_FIFO))) {
2216 vxge_hw_device_mask_all(hldev);
2217 vxge_hw_device_flush_io(hldev);
2218 return IRQ_HANDLED;
2219 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2220 return IRQ_HANDLED;
2221
2222 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2223 return IRQ_NONE;
2224}
2225
2226#ifdef CONFIG_PCI_MSI
2227
Jon Mason16fded72011-01-18 15:02:21 +00002228static irqreturn_t vxge_tx_msix_handle(int irq, void *dev_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002229{
2230 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2231
Jon Mason16fded72011-01-18 15:02:21 +00002232 adaptive_coalesce_tx_interrupts(fifo);
2233
2234 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)fifo->handle,
2235 fifo->tx_vector_no);
2236
2237 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)fifo->handle,
2238 fifo->tx_vector_no);
2239
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002240 VXGE_COMPLETE_VPATH_TX(fifo);
2241
Jon Mason16fded72011-01-18 15:02:21 +00002242 vxge_hw_channel_msix_unmask((struct __vxge_hw_channel *)fifo->handle,
2243 fifo->tx_vector_no);
2244
2245 mmiowb();
2246
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002247 return IRQ_HANDLED;
2248}
2249
Jon Mason16fded72011-01-18 15:02:21 +00002250static irqreturn_t vxge_rx_msix_napi_handle(int irq, void *dev_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002251{
2252 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2253
Jon Mason16fded72011-01-18 15:02:21 +00002254 adaptive_coalesce_rx_interrupts(ring);
2255
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002256 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
Jon Mason16fded72011-01-18 15:02:21 +00002257 ring->rx_vector_no);
2258
2259 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)ring->handle,
2260 ring->rx_vector_no);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002261
2262 napi_schedule(&ring->napi);
2263 return IRQ_HANDLED;
2264}
2265
2266static irqreturn_t
2267vxge_alarm_msix_handle(int irq, void *dev_id)
2268{
2269 int i;
2270 enum vxge_hw_status status;
2271 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2272 struct vxgedev *vdev = vpath->vdev;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002273 int msix_id = (vpath->handle->vpath->vp_id *
2274 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002275
2276 for (i = 0; i < vdev->no_of_vpath; i++) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002277 /* Reduce the chance of losing alarm interrupts by masking
Jon Mason16fded72011-01-18 15:02:21 +00002278 * the vector. A pending bit will be set if an alarm is
2279 * generated and on unmask the interrupt will be fired.
2280 */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002281 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
Jon Mason16fded72011-01-18 15:02:21 +00002282 vxge_hw_vpath_msix_clear(vdev->vpaths[i].handle, msix_id);
2283 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002284
2285 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2286 vdev->exec_mode);
2287 if (status == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002288 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
Jon Mason16fded72011-01-18 15:02:21 +00002289 msix_id);
2290 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002291 continue;
2292 }
2293 vxge_debug_intr(VXGE_ERR,
2294 "%s: vxge_hw_vpath_alarm_process failed %x ",
2295 VXGE_DRIVER_NAME, status);
2296 }
2297 return IRQ_HANDLED;
2298}
2299
2300static int vxge_alloc_msix(struct vxgedev *vdev)
2301{
2302 int j, i, ret = 0;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002303 int msix_intr_vect = 0, temp;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002304 vdev->intr_cnt = 0;
2305
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002306start:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002307 /* Tx/Rx MSIX Vectors count */
2308 vdev->intr_cnt = vdev->no_of_vpath * 2;
2309
2310 /* Alarm MSIX Vectors count */
2311 vdev->intr_cnt++;
2312
Joe Perchesbaeb2ff2010-08-11 07:02:48 +00002313 vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
2314 GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002315 if (!vdev->entries) {
2316 vxge_debug_init(VXGE_ERR,
2317 "%s: memory allocation failed",
2318 VXGE_DRIVER_NAME);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002319 ret = -ENOMEM;
2320 goto alloc_entries_failed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002321 }
2322
Joe Perchesbaeb2ff2010-08-11 07:02:48 +00002323 vdev->vxge_entries = kcalloc(vdev->intr_cnt,
2324 sizeof(struct vxge_msix_entry),
2325 GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002326 if (!vdev->vxge_entries) {
2327 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2328 VXGE_DRIVER_NAME);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002329 ret = -ENOMEM;
2330 goto alloc_vxge_entries_failed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002331 }
2332
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002333 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002334
2335 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2336
2337 /* Initialize the fifo vector */
2338 vdev->entries[j].entry = msix_intr_vect;
2339 vdev->vxge_entries[j].entry = msix_intr_vect;
2340 vdev->vxge_entries[j].in_use = 0;
2341 j++;
2342
2343 /* Initialize the ring vector */
2344 vdev->entries[j].entry = msix_intr_vect + 1;
2345 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2346 vdev->vxge_entries[j].in_use = 0;
2347 j++;
2348 }
2349
2350 /* Initialize the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002351 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2352 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002353 vdev->vxge_entries[j].in_use = 0;
2354
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002355 ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002356 if (ret > 0) {
2357 vxge_debug_init(VXGE_ERR,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002358 "%s: MSI-X enable failed for %d vectors, ret: %d",
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002359 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002360 if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) {
2361 ret = -ENODEV;
2362 goto enable_msix_failed;
2363 }
2364
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002365 kfree(vdev->entries);
2366 kfree(vdev->vxge_entries);
2367 vdev->entries = NULL;
2368 vdev->vxge_entries = NULL;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002369 /* Try with less no of vector by reducing no of vpaths count */
2370 temp = (ret - 1)/2;
2371 vxge_close_vpaths(vdev, temp);
2372 vdev->no_of_vpath = temp;
2373 goto start;
Michal Schmidtcc413d92010-06-24 04:13:44 +00002374 } else if (ret < 0) {
2375 ret = -ENODEV;
2376 goto enable_msix_failed;
2377 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002378 return 0;
Michal Schmidtcc413d92010-06-24 04:13:44 +00002379
2380enable_msix_failed:
2381 kfree(vdev->vxge_entries);
2382alloc_vxge_entries_failed:
2383 kfree(vdev->entries);
2384alloc_entries_failed:
2385 return ret;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002386}
2387
2388static int vxge_enable_msix(struct vxgedev *vdev)
2389{
2390
2391 int i, ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002392 /* 0 - Tx, 1 - Rx */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002393 int tim_msix_id[4] = {0, 1, 0, 0};
2394
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002395 vdev->intr_cnt = 0;
2396
2397 /* allocate msix vectors */
2398 ret = vxge_alloc_msix(vdev);
2399 if (!ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002400 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002401 struct vxge_vpath *vpath = &vdev->vpaths[i];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002402
Jon Mason7adf7d12010-07-15 08:47:24 +00002403 /* If fifo or ring are not enabled, the MSIX vector for
2404 * it should be set to 0.
2405 */
2406 vpath->ring.rx_vector_no = (vpath->device_id *
2407 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002408
Jon Mason16fded72011-01-18 15:02:21 +00002409 vpath->fifo.tx_vector_no = (vpath->device_id *
2410 VXGE_HW_VPATH_MSIX_ACTIVE);
2411
Jon Mason7adf7d12010-07-15 08:47:24 +00002412 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
2413 VXGE_ALARM_MSIX_ID);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002414 }
2415 }
2416
2417 return ret;
2418}
2419
2420static void vxge_rem_msix_isr(struct vxgedev *vdev)
2421{
2422 int intr_cnt;
2423
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002424 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002425 intr_cnt++) {
2426 if (vdev->vxge_entries[intr_cnt].in_use) {
2427 synchronize_irq(vdev->entries[intr_cnt].vector);
2428 free_irq(vdev->entries[intr_cnt].vector,
2429 vdev->vxge_entries[intr_cnt].arg);
2430 vdev->vxge_entries[intr_cnt].in_use = 0;
2431 }
2432 }
2433
2434 kfree(vdev->entries);
2435 kfree(vdev->vxge_entries);
2436 vdev->entries = NULL;
2437 vdev->vxge_entries = NULL;
2438
2439 if (vdev->config.intr_type == MSI_X)
2440 pci_disable_msix(vdev->pdev);
2441}
2442#endif
2443
2444static void vxge_rem_isr(struct vxgedev *vdev)
2445{
Jon Mason2c913082010-11-11 04:26:03 +00002446 struct __vxge_hw_device *hldev;
Joe Perchesd8ee7072010-11-15 10:13:58 +00002447 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002448
2449#ifdef CONFIG_PCI_MSI
2450 if (vdev->config.intr_type == MSI_X) {
2451 vxge_rem_msix_isr(vdev);
2452 } else
2453#endif
2454 if (vdev->config.intr_type == INTA) {
2455 synchronize_irq(vdev->pdev->irq);
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002456 free_irq(vdev->pdev->irq, vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002457 }
2458}
2459
2460static int vxge_add_isr(struct vxgedev *vdev)
2461{
2462 int ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002463#ifdef CONFIG_PCI_MSI
2464 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002465 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2466
2467 if (vdev->config.intr_type == MSI_X)
2468 ret = vxge_enable_msix(vdev);
2469
2470 if (ret) {
2471 vxge_debug_init(VXGE_ERR,
2472 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002473 vxge_debug_init(VXGE_ERR,
2474 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2475 vdev->config.intr_type = INTA;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002476 }
2477
2478 if (vdev->config.intr_type == MSI_X) {
2479 for (intr_idx = 0;
2480 intr_idx < (vdev->no_of_vpath *
2481 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2482
2483 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2484 irq_req = 0;
2485
2486 switch (msix_idx) {
2487 case 0:
2488 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002489 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2490 vdev->ndev->name,
2491 vdev->entries[intr_cnt].entry,
2492 pci_fun, vp_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002493 ret = request_irq(
2494 vdev->entries[intr_cnt].vector,
2495 vxge_tx_msix_handle, 0,
2496 vdev->desc[intr_cnt],
2497 &vdev->vpaths[vp_idx].fifo);
2498 vdev->vxge_entries[intr_cnt].arg =
2499 &vdev->vpaths[vp_idx].fifo;
2500 irq_req = 1;
2501 break;
2502 case 1:
2503 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002504 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2505 vdev->ndev->name,
2506 vdev->entries[intr_cnt].entry,
2507 pci_fun, vp_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002508 ret = request_irq(
2509 vdev->entries[intr_cnt].vector,
2510 vxge_rx_msix_napi_handle,
2511 0,
2512 vdev->desc[intr_cnt],
2513 &vdev->vpaths[vp_idx].ring);
2514 vdev->vxge_entries[intr_cnt].arg =
2515 &vdev->vpaths[vp_idx].ring;
2516 irq_req = 1;
2517 break;
2518 }
2519
2520 if (ret) {
2521 vxge_debug_init(VXGE_ERR,
2522 "%s: MSIX - %d Registration failed",
2523 vdev->ndev->name, intr_cnt);
2524 vxge_rem_msix_isr(vdev);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002525 vdev->config.intr_type = INTA;
2526 vxge_debug_init(VXGE_ERR,
2527 "%s: Defaulting to INTA"
2528 , vdev->ndev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002529 goto INTA_MODE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002530 }
2531
2532 if (irq_req) {
2533 /* We requested for this msix interrupt */
2534 vdev->vxge_entries[intr_cnt].in_use = 1;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002535 msix_idx += vdev->vpaths[vp_idx].device_id *
2536 VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002537 vxge_hw_vpath_msix_unmask(
2538 vdev->vpaths[vp_idx].handle,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002539 msix_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002540 intr_cnt++;
2541 }
2542
2543 /* Point to next vpath handler */
Joe Perches8e95a202009-12-03 07:58:21 +00002544 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2545 (vp_idx < (vdev->no_of_vpath - 1)))
2546 vp_idx++;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002547 }
2548
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002549 intr_cnt = vdev->no_of_vpath * 2;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002550 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002551 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2552 vdev->ndev->name,
2553 vdev->entries[intr_cnt].entry,
2554 pci_fun);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002555 /* For Alarm interrupts */
2556 ret = request_irq(vdev->entries[intr_cnt].vector,
2557 vxge_alarm_msix_handle, 0,
2558 vdev->desc[intr_cnt],
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002559 &vdev->vpaths[0]);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002560 if (ret) {
2561 vxge_debug_init(VXGE_ERR,
2562 "%s: MSIX - %d Registration failed",
2563 vdev->ndev->name, intr_cnt);
2564 vxge_rem_msix_isr(vdev);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002565 vdev->config.intr_type = INTA;
2566 vxge_debug_init(VXGE_ERR,
2567 "%s: Defaulting to INTA",
2568 vdev->ndev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002569 goto INTA_MODE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002570 }
2571
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002572 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2573 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002574 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002575 msix_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002576 vdev->vxge_entries[intr_cnt].in_use = 1;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002577 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002578 }
2579INTA_MODE:
2580#endif
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002581
2582 if (vdev->config.intr_type == INTA) {
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002583 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2584 "%s:vxge:INTA", vdev->ndev->name);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002585 vxge_hw_device_set_intr_type(vdev->devh,
2586 VXGE_HW_INTR_MODE_IRQLINE);
Jon Mason16fded72011-01-18 15:02:21 +00002587
2588 vxge_hw_vpath_tti_ci_set(vdev->vpaths[0].fifo.handle);
2589
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002590 ret = request_irq((int) vdev->pdev->irq,
2591 vxge_isr_napi,
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002592 IRQF_SHARED, vdev->desc[0], vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002593 if (ret) {
2594 vxge_debug_init(VXGE_ERR,
2595 "%s %s-%d: ISR registration failed",
2596 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2597 return -ENODEV;
2598 }
2599 vxge_debug_init(VXGE_TRACE,
2600 "new %s-%d line allocated",
2601 "IRQ", vdev->pdev->irq);
2602 }
2603
2604 return VXGE_HW_OK;
2605}
2606
2607static void vxge_poll_vp_reset(unsigned long data)
2608{
2609 struct vxgedev *vdev = (struct vxgedev *)data;
2610 int i, j = 0;
2611
2612 for (i = 0; i < vdev->no_of_vpath; i++) {
2613 if (test_bit(i, &vdev->vp_reset)) {
2614 vxge_reset_vpath(vdev, i);
2615 j++;
2616 }
2617 }
2618 if (j && (vdev->config.intr_type != MSI_X)) {
2619 vxge_hw_device_unmask_all(vdev->devh);
2620 vxge_hw_device_flush_io(vdev->devh);
2621 }
2622
2623 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2624}
2625
2626static void vxge_poll_vp_lockup(unsigned long data)
2627{
2628 struct vxgedev *vdev = (struct vxgedev *)data;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002629 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00002630 struct vxge_vpath *vpath;
2631 struct vxge_ring *ring;
2632 int i;
stephen hemminger62ea0552011-06-20 10:35:07 +00002633 unsigned long rx_frms;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002634
2635 for (i = 0; i < vdev->no_of_vpath; i++) {
2636 ring = &vdev->vpaths[i].ring;
stephen hemminger62ea0552011-06-20 10:35:07 +00002637
2638 /* Truncated to machine word size number of frames */
2639 rx_frms = ACCESS_ONCE(ring->stats.rx_frms);
2640
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002641 /* Did this vpath received any packets */
stephen hemminger62ea0552011-06-20 10:35:07 +00002642 if (ring->stats.prev_rx_frms == rx_frms) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002643 status = vxge_hw_vpath_check_leak(ring->handle);
2644
2645 /* Did it received any packets last time */
2646 if ((VXGE_HW_FAIL == status) &&
2647 (VXGE_HW_FAIL == ring->last_status)) {
2648
2649 /* schedule vpath reset */
2650 if (!test_and_set_bit(i, &vdev->vp_reset)) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002651 vpath = &vdev->vpaths[i];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002652
2653 /* disable interrupts for this vpath */
2654 vxge_vpath_intr_disable(vdev, i);
2655
2656 /* stop the queue for this vpath */
Jon Mason98f45da2010-07-15 08:47:25 +00002657 netif_tx_stop_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002658 continue;
2659 }
2660 }
2661 }
stephen hemminger62ea0552011-06-20 10:35:07 +00002662 ring->stats.prev_rx_frms = rx_frms;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002663 ring->last_status = status;
2664 }
2665
2666 /* Check every 1 milli second */
2667 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2668}
2669
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002670static netdev_features_t vxge_fix_features(struct net_device *dev,
2671 netdev_features_t features)
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002672{
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002673 netdev_features_t changed = dev->features ^ features;
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002674
2675 /* Enabling RTH requires some of the logic in vxge_device_register and a
2676 * vpath reset. Due to these restrictions, only allow modification
2677 * while the interface is down.
2678 */
2679 if ((changed & NETIF_F_RXHASH) && netif_running(dev))
2680 features ^= NETIF_F_RXHASH;
2681
2682 return features;
2683}
2684
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002685static int vxge_set_features(struct net_device *dev, netdev_features_t features)
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002686{
2687 struct vxgedev *vdev = netdev_priv(dev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002688 netdev_features_t changed = dev->features ^ features;
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002689
2690 if (!(changed & NETIF_F_RXHASH))
2691 return 0;
2692
2693 /* !netif_running() ensured by vxge_fix_features() */
2694
2695 vdev->devh->config.rth_en = !!(features & NETIF_F_RXHASH);
2696 if (vxge_reset_all_vpaths(vdev) != VXGE_HW_OK) {
2697 dev->features = features ^ NETIF_F_RXHASH;
2698 vdev->devh->config.rth_en = !!(dev->features & NETIF_F_RXHASH);
2699 return -EIO;
2700 }
2701
2702 return 0;
2703}
2704
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002705/**
2706 * vxge_open
2707 * @dev: pointer to the device structure.
2708 *
2709 * This function is the open entry point of the driver. It mainly calls a
2710 * function to allocate Rx buffers and inserts them into the buffer
2711 * descriptors and then enables the Rx part of the NIC.
2712 * Return value: '0' on success and an appropriate (-)ve integer as
2713 * defined in errno.h file on failure.
2714 */
Jon Mason528f7272010-12-10 14:02:56 +00002715static int vxge_open(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002716{
2717 enum vxge_hw_status status;
2718 struct vxgedev *vdev;
2719 struct __vxge_hw_device *hldev;
Jon Mason7adf7d12010-07-15 08:47:24 +00002720 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002721 int ret = 0;
2722 int i;
2723 u64 val64, function_mode;
Jon Mason528f7272010-12-10 14:02:56 +00002724
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002725 vxge_debug_entryexit(VXGE_TRACE,
2726 "%s: %s:%d", dev->name, __func__, __LINE__);
2727
Joe Perches5f54ceb2010-11-15 11:12:30 +00002728 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00002729 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002730 function_mode = vdev->config.device_hw_info.function_mode;
2731
2732 /* make sure you have link off by default every time Nic is
2733 * initialized */
2734 netif_carrier_off(dev);
2735
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002736 /* Open VPATHs */
2737 status = vxge_open_vpaths(vdev);
2738 if (status != VXGE_HW_OK) {
2739 vxge_debug_init(VXGE_ERR,
2740 "%s: fatal: Vpath open failed", vdev->ndev->name);
2741 ret = -EPERM;
2742 goto out0;
2743 }
2744
2745 vdev->mtu = dev->mtu;
2746
2747 status = vxge_add_isr(vdev);
2748 if (status != VXGE_HW_OK) {
2749 vxge_debug_init(VXGE_ERR,
2750 "%s: fatal: ISR add failed", dev->name);
2751 ret = -EPERM;
2752 goto out1;
2753 }
2754
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002755 if (vdev->config.intr_type != MSI_X) {
2756 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2757 vdev->config.napi_weight);
2758 napi_enable(&vdev->napi);
Jon Mason7adf7d12010-07-15 08:47:24 +00002759 for (i = 0; i < vdev->no_of_vpath; i++) {
2760 vpath = &vdev->vpaths[i];
2761 vpath->ring.napi_p = &vdev->napi;
2762 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002763 } else {
2764 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002765 vpath = &vdev->vpaths[i];
2766 netif_napi_add(dev, &vpath->ring.napi,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002767 vxge_poll_msix, vdev->config.napi_weight);
Jon Mason7adf7d12010-07-15 08:47:24 +00002768 napi_enable(&vpath->ring.napi);
2769 vpath->ring.napi_p = &vpath->ring.napi;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002770 }
2771 }
2772
2773 /* configure RTH */
2774 if (vdev->config.rth_steering) {
2775 status = vxge_rth_configure(vdev);
2776 if (status != VXGE_HW_OK) {
2777 vxge_debug_init(VXGE_ERR,
2778 "%s: fatal: RTH configuration failed",
2779 dev->name);
2780 ret = -EPERM;
2781 goto out2;
2782 }
2783 }
Jon Mason47f01db2010-11-11 04:25:53 +00002784 printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name,
2785 hldev->config.rth_en ? "enabled" : "disabled");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002786
2787 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002788 vpath = &vdev->vpaths[i];
2789
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002790 /* set initial mtu before enabling the device */
Jon Mason7adf7d12010-07-15 08:47:24 +00002791 status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002792 if (status != VXGE_HW_OK) {
2793 vxge_debug_init(VXGE_ERR,
2794 "%s: fatal: can not set new MTU", dev->name);
2795 ret = -EPERM;
2796 goto out2;
2797 }
2798 }
2799
2800 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2801 vxge_debug_init(vdev->level_trace,
2802 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2803 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2804
Jon Mason7adf7d12010-07-15 08:47:24 +00002805 /* Restore the DA, VID table and also multicast and promiscuous mode
2806 * states
2807 */
2808 if (vdev->all_multi_flg) {
2809 for (i = 0; i < vdev->no_of_vpath; i++) {
2810 vpath = &vdev->vpaths[i];
2811 vxge_restore_vpath_mac_addr(vpath);
2812 vxge_restore_vpath_vid_table(vpath);
2813
2814 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2815 if (status != VXGE_HW_OK)
2816 vxge_debug_init(VXGE_ERR,
2817 "%s:%d Enabling multicast failed",
2818 __func__, __LINE__);
2819 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002820 }
2821
2822 /* Enable vpath to sniff all unicast/multicast traffic that not
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002823 * addressed to them. We allow promiscuous mode for PF only
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002824 */
2825
2826 val64 = 0;
2827 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2828 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
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_addr),
2835 val64);
2836
2837 vxge_hw_mgmt_reg_write(vdev->devh,
2838 vxge_hw_mgmt_reg_type_mrpcim,
2839 0,
2840 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2841 rxmac_authorize_all_vid),
2842 val64);
2843
2844 vxge_set_multicast(dev);
2845
2846 /* Enabling Bcast and mcast for all vpath */
2847 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002848 vpath = &vdev->vpaths[i];
2849 status = vxge_hw_vpath_bcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002850 if (status != VXGE_HW_OK)
2851 vxge_debug_init(VXGE_ERR,
2852 "%s : Can not enable bcast for vpath "
2853 "id %d", dev->name, i);
2854 if (vdev->config.addr_learn_en) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002855 status = vxge_hw_vpath_mcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002856 if (status != VXGE_HW_OK)
2857 vxge_debug_init(VXGE_ERR,
2858 "%s : Can not enable mcast for vpath "
2859 "id %d", dev->name, i);
2860 }
2861 }
2862
2863 vxge_hw_device_setpause_data(vdev->devh, 0,
2864 vdev->config.tx_pause_enable,
2865 vdev->config.rx_pause_enable);
2866
2867 if (vdev->vp_reset_timer.function == NULL)
Joe Perches044a3812012-04-03 12:14:31 +00002868 vxge_os_timer(&vdev->vp_reset_timer, vxge_poll_vp_reset, vdev,
2869 HZ / 2);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002870
Jon Masone7935c92010-11-11 04:26:00 +00002871 /* There is no need to check for RxD leak and RxD lookup on Titan1A */
2872 if (vdev->titan1 && vdev->vp_lockup_timer.function == NULL)
Joe Perches044a3812012-04-03 12:14:31 +00002873 vxge_os_timer(&vdev->vp_lockup_timer, vxge_poll_vp_lockup, vdev,
Jon Masone7935c92010-11-11 04:26:00 +00002874 HZ / 2);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002875
2876 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2877
2878 smp_wmb();
2879
2880 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2881 netif_carrier_on(vdev->ndev);
Joe Perches75f5e1c2010-07-27 11:47:03 +00002882 netdev_notice(vdev->ndev, "Link Up\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002883 vdev->stats.link_up++;
2884 }
2885
2886 vxge_hw_device_intr_enable(vdev->devh);
2887
2888 smp_wmb();
2889
2890 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002891 vpath = &vdev->vpaths[i];
2892
2893 vxge_hw_vpath_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002894 smp_wmb();
Jon Mason7adf7d12010-07-15 08:47:24 +00002895 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002896 }
2897
Jon Masond03848e2010-07-15 08:47:23 +00002898 netif_tx_start_all_queues(vdev->ndev);
Jon Mason16fded72011-01-18 15:02:21 +00002899
2900 /* configure CI */
2901 vxge_config_ci_for_tti_rti(vdev);
2902
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002903 goto out0;
2904
2905out2:
2906 vxge_rem_isr(vdev);
2907
2908 /* Disable napi */
2909 if (vdev->config.intr_type != MSI_X)
2910 napi_disable(&vdev->napi);
2911 else {
2912 for (i = 0; i < vdev->no_of_vpath; i++)
2913 napi_disable(&vdev->vpaths[i].ring.napi);
2914 }
2915
2916out1:
2917 vxge_close_vpaths(vdev, 0);
2918out0:
2919 vxge_debug_entryexit(VXGE_TRACE,
2920 "%s: %s:%d Exiting...",
2921 dev->name, __func__, __LINE__);
2922 return ret;
2923}
2924
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002925/* Loop through the mac address list and delete all the entries */
stephen hemminger42821a52010-10-21 07:50:53 +00002926static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002927{
2928
2929 struct list_head *entry, *next;
2930 if (list_empty(&vpath->mac_addr_list))
2931 return;
2932
2933 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2934 list_del(entry);
2935 kfree((struct vxge_mac_addrs *)entry);
2936 }
2937}
2938
2939static void vxge_napi_del_all(struct vxgedev *vdev)
2940{
2941 int i;
2942 if (vdev->config.intr_type != MSI_X)
2943 netif_napi_del(&vdev->napi);
2944 else {
2945 for (i = 0; i < vdev->no_of_vpath; i++)
2946 netif_napi_del(&vdev->vpaths[i].ring.napi);
2947 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002948}
2949
stephen hemminger42821a52010-10-21 07:50:53 +00002950static int do_vxge_close(struct net_device *dev, int do_io)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002951{
2952 enum vxge_hw_status status;
2953 struct vxgedev *vdev;
2954 struct __vxge_hw_device *hldev;
2955 int i;
2956 u64 val64, vpath_vector;
2957 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2958 dev->name, __func__, __LINE__);
2959
Joe Perches5f54ceb2010-11-15 11:12:30 +00002960 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00002961 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002962
Sreenivasa Honnurbd9ee682009-07-01 21:14:03 +00002963 if (unlikely(!is_vxge_card_up(vdev)))
2964 return 0;
2965
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002966 /* If vxge_handle_crit_err task is executing,
2967 * wait till it completes. */
2968 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2969 msleep(50);
2970
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002971 if (do_io) {
2972 /* Put the vpath back in normal mode */
2973 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2974 status = vxge_hw_mgmt_reg_read(vdev->devh,
2975 vxge_hw_mgmt_reg_type_mrpcim,
2976 0,
2977 (ulong)offsetof(
2978 struct vxge_hw_mrpcim_reg,
2979 rts_mgr_cbasin_cfg),
2980 &val64);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002981 if (status == VXGE_HW_OK) {
2982 val64 &= ~vpath_vector;
2983 status = vxge_hw_mgmt_reg_write(vdev->devh,
2984 vxge_hw_mgmt_reg_type_mrpcim,
2985 0,
2986 (ulong)offsetof(
2987 struct vxge_hw_mrpcim_reg,
2988 rts_mgr_cbasin_cfg),
2989 val64);
2990 }
2991
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002992 /* Remove the function 0 from promiscuous mode */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002993 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_addr),
2998 0);
2999
3000 vxge_hw_mgmt_reg_write(vdev->devh,
3001 vxge_hw_mgmt_reg_type_mrpcim,
3002 0,
3003 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
3004 rxmac_authorize_all_vid),
3005 0);
3006
3007 smp_wmb();
3008 }
Jon Masone7935c92010-11-11 04:26:00 +00003009
3010 if (vdev->titan1)
3011 del_timer_sync(&vdev->vp_lockup_timer);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003012
3013 del_timer_sync(&vdev->vp_reset_timer);
3014
Jon Mason4d2a5b42010-11-11 04:25:54 +00003015 if (do_io)
3016 vxge_hw_device_wait_receive_idle(hldev);
3017
3018 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3019
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003020 /* Disable napi */
3021 if (vdev->config.intr_type != MSI_X)
3022 napi_disable(&vdev->napi);
3023 else {
3024 for (i = 0; i < vdev->no_of_vpath; i++)
3025 napi_disable(&vdev->vpaths[i].ring.napi);
3026 }
3027
3028 netif_carrier_off(vdev->ndev);
Joe Perches75f5e1c2010-07-27 11:47:03 +00003029 netdev_notice(vdev->ndev, "Link Down\n");
Jon Masond03848e2010-07-15 08:47:23 +00003030 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003031
3032 /* Note that at this point xmit() is stopped by upper layer */
3033 if (do_io)
3034 vxge_hw_device_intr_disable(vdev->devh);
3035
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003036 vxge_rem_isr(vdev);
3037
3038 vxge_napi_del_all(vdev);
3039
3040 if (do_io)
3041 vxge_reset_all_vpaths(vdev);
3042
3043 vxge_close_vpaths(vdev, 0);
3044
3045 vxge_debug_entryexit(VXGE_TRACE,
3046 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
3047
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003048 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
3049
3050 return 0;
3051}
3052
3053/**
3054 * vxge_close
3055 * @dev: device pointer.
3056 *
3057 * This is the stop entry point of the driver. It needs to undo exactly
3058 * whatever was done by the open entry point, thus it's usually referred to
3059 * as the close function.Among other things this function mainly stops the
3060 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
3061 * Return value: '0' on success and an appropriate (-)ve integer as
3062 * defined in errno.h file on failure.
3063 */
Jon Mason528f7272010-12-10 14:02:56 +00003064static int vxge_close(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003065{
3066 do_vxge_close(dev, 1);
3067 return 0;
3068}
3069
3070/**
3071 * vxge_change_mtu
3072 * @dev: net device pointer.
3073 * @new_mtu :the new MTU size for the device.
3074 *
3075 * A driver entry point to change MTU size for the device. Before changing
3076 * the MTU the device must be stopped.
3077 */
3078static int vxge_change_mtu(struct net_device *dev, int new_mtu)
3079{
3080 struct vxgedev *vdev = netdev_priv(dev);
3081
3082 vxge_debug_entryexit(vdev->level_trace,
3083 "%s:%d", __func__, __LINE__);
3084 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
3085 vxge_debug_init(vdev->level_err,
3086 "%s: mtu size is invalid", dev->name);
3087 return -EPERM;
3088 }
3089
3090 /* check if device is down already */
3091 if (unlikely(!is_vxge_card_up(vdev))) {
3092 /* just store new value, will use later on open() */
3093 dev->mtu = new_mtu;
3094 vxge_debug_init(vdev->level_err,
3095 "%s", "device is down on MTU change");
3096 return 0;
3097 }
3098
3099 vxge_debug_init(vdev->level_trace,
3100 "trying to apply new MTU %d", new_mtu);
3101
3102 if (vxge_close(dev))
3103 return -EIO;
3104
3105 dev->mtu = new_mtu;
3106 vdev->mtu = new_mtu;
3107
3108 if (vxge_open(dev))
3109 return -EIO;
3110
3111 vxge_debug_init(vdev->level_trace,
3112 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
3113
3114 vxge_debug_entryexit(vdev->level_trace,
3115 "%s:%d Exiting...", __func__, __LINE__);
3116
3117 return 0;
3118}
3119
3120/**
Eric Dumazetdd57f972010-08-18 03:42:54 +00003121 * vxge_get_stats64
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003122 * @dev: pointer to the device structure
Eric Dumazetdd57f972010-08-18 03:42:54 +00003123 * @stats: pointer to struct rtnl_link_stats64
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003124 *
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003125 */
Eric Dumazetdd57f972010-08-18 03:42:54 +00003126static struct rtnl_link_stats64 *
3127vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003128{
Eric Dumazetdd57f972010-08-18 03:42:54 +00003129 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003130 int k;
3131
Eric Dumazetdd57f972010-08-18 03:42:54 +00003132 /* net_stats already zeroed by caller */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003133 for (k = 0; k < vdev->no_of_vpath; k++) {
stephen hemminger62ea0552011-06-20 10:35:07 +00003134 struct vxge_ring_stats *rxstats = &vdev->vpaths[k].ring.stats;
3135 struct vxge_fifo_stats *txstats = &vdev->vpaths[k].fifo.stats;
3136 unsigned int start;
3137 u64 packets, bytes, multicast;
3138
3139 do {
Kevin Groenevelde3906482012-07-21 06:30:50 +00003140 start = u64_stats_fetch_begin_bh(&rxstats->syncp);
stephen hemminger62ea0552011-06-20 10:35:07 +00003141
3142 packets = rxstats->rx_frms;
3143 multicast = rxstats->rx_mcast;
3144 bytes = rxstats->rx_bytes;
Kevin Groenevelde3906482012-07-21 06:30:50 +00003145 } while (u64_stats_fetch_retry_bh(&rxstats->syncp, start));
stephen hemminger62ea0552011-06-20 10:35:07 +00003146
3147 net_stats->rx_packets += packets;
3148 net_stats->rx_bytes += bytes;
3149 net_stats->multicast += multicast;
3150
3151 net_stats->rx_errors += rxstats->rx_errors;
3152 net_stats->rx_dropped += rxstats->rx_dropped;
3153
3154 do {
Kevin Groenevelde3906482012-07-21 06:30:50 +00003155 start = u64_stats_fetch_begin_bh(&txstats->syncp);
stephen hemminger62ea0552011-06-20 10:35:07 +00003156
3157 packets = txstats->tx_frms;
3158 bytes = txstats->tx_bytes;
Kevin Groenevelde3906482012-07-21 06:30:50 +00003159 } while (u64_stats_fetch_retry_bh(&txstats->syncp, start));
stephen hemminger62ea0552011-06-20 10:35:07 +00003160
3161 net_stats->tx_packets += packets;
3162 net_stats->tx_bytes += bytes;
3163 net_stats->tx_errors += txstats->tx_errors;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003164 }
3165
3166 return net_stats;
3167}
3168
Jon Masoncd883a72011-04-08 11:11:21 +00003169static enum vxge_hw_status vxge_timestamp_config(struct __vxge_hw_device *devh)
Jon Masonb81b3732010-11-11 04:25:58 +00003170{
3171 enum vxge_hw_status status;
3172 u64 val64;
3173
3174 /* Timestamp is passed to the driver via the FCS, therefore we
3175 * must disable the FCS stripping by the adapter. Since this is
3176 * required for the driver to load (due to a hardware bug),
3177 * there is no need to do anything special here.
3178 */
Jon Masoncd883a72011-04-08 11:11:21 +00003179 val64 = VXGE_HW_XMAC_TIMESTAMP_EN |
3180 VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
3181 VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
Jon Masonb81b3732010-11-11 04:25:58 +00003182
Jon Masoncd883a72011-04-08 11:11:21 +00003183 status = vxge_hw_mgmt_reg_write(devh,
Jon Masonb81b3732010-11-11 04:25:58 +00003184 vxge_hw_mgmt_reg_type_mrpcim,
3185 0,
3186 offsetof(struct vxge_hw_mrpcim_reg,
3187 xmac_timestamp),
3188 val64);
Jon Masoncd883a72011-04-08 11:11:21 +00003189 vxge_hw_device_flush_io(devh);
3190 devh->config.hwts_en = VXGE_HW_HWTS_ENABLE;
Jon Masonb81b3732010-11-11 04:25:58 +00003191 return status;
3192}
3193
Ben Hutchings450e55e2013-11-18 23:16:23 +00003194static int vxge_hwtstamp_set(struct vxgedev *vdev, void __user *data)
Jon Masonb81b3732010-11-11 04:25:58 +00003195{
3196 struct hwtstamp_config config;
Jon Masonb81b3732010-11-11 04:25:58 +00003197 int i;
3198
3199 if (copy_from_user(&config, data, sizeof(config)))
3200 return -EFAULT;
3201
3202 /* reserved for future extensions */
3203 if (config.flags)
3204 return -EINVAL;
3205
3206 /* Transmit HW Timestamp not supported */
3207 switch (config.tx_type) {
3208 case HWTSTAMP_TX_OFF:
3209 break;
3210 case HWTSTAMP_TX_ON:
3211 default:
3212 return -ERANGE;
3213 }
3214
3215 switch (config.rx_filter) {
3216 case HWTSTAMP_FILTER_NONE:
Jon Masonb81b3732010-11-11 04:25:58 +00003217 vdev->rx_hwts = 0;
3218 config.rx_filter = HWTSTAMP_FILTER_NONE;
3219 break;
3220
3221 case HWTSTAMP_FILTER_ALL:
3222 case HWTSTAMP_FILTER_SOME:
3223 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3224 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3225 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3226 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3227 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3228 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3229 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3230 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3231 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3232 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3233 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3234 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
Jon Masoncd883a72011-04-08 11:11:21 +00003235 if (vdev->devh->config.hwts_en != VXGE_HW_HWTS_ENABLE)
Jon Masonb81b3732010-11-11 04:25:58 +00003236 return -EFAULT;
3237
3238 vdev->rx_hwts = 1;
3239 config.rx_filter = HWTSTAMP_FILTER_ALL;
3240 break;
3241
3242 default:
3243 return -ERANGE;
3244 }
3245
3246 for (i = 0; i < vdev->no_of_vpath; i++)
3247 vdev->vpaths[i].ring.rx_hwts = vdev->rx_hwts;
3248
3249 if (copy_to_user(data, &config, sizeof(config)))
3250 return -EFAULT;
3251
3252 return 0;
3253}
3254
Ben Hutchings450e55e2013-11-18 23:16:23 +00003255static int vxge_hwtstamp_get(struct vxgedev *vdev, void __user *data)
3256{
3257 struct hwtstamp_config config;
3258
3259 config.flags = 0;
3260 config.tx_type = HWTSTAMP_TX_OFF;
3261 config.rx_filter = (vdev->rx_hwts ?
3262 HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE);
3263
3264 if (copy_to_user(data, &config, sizeof(config)))
3265 return -EFAULT;
3266
3267 return 0;
3268}
3269
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003270/**
3271 * vxge_ioctl
3272 * @dev: Device pointer.
3273 * @ifr: An IOCTL specific structure, that can contain a pointer to
3274 * a proprietary structure used to pass information to the driver.
3275 * @cmd: This is used to distinguish between the different commands that
3276 * can be passed to the IOCTL functions.
3277 *
3278 * Entry point for the Ioctl.
3279 */
3280static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3281{
Jon Masonb81b3732010-11-11 04:25:58 +00003282 struct vxgedev *vdev = netdev_priv(dev);
Jon Masonb81b3732010-11-11 04:25:58 +00003283
3284 switch (cmd) {
3285 case SIOCSHWTSTAMP:
Ben Hutchings450e55e2013-11-18 23:16:23 +00003286 return vxge_hwtstamp_set(vdev, rq->ifr_data);
3287 case SIOCGHWTSTAMP:
3288 return vxge_hwtstamp_get(vdev, rq->ifr_data);
Jon Masonb81b3732010-11-11 04:25:58 +00003289 default:
3290 return -EOPNOTSUPP;
3291 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003292}
3293
3294/**
3295 * vxge_tx_watchdog
3296 * @dev: pointer to net device structure
3297 *
3298 * Watchdog for transmit side.
3299 * This function is triggered if the Tx Queue is stopped
3300 * for a pre-defined amount of time when the Interface is still up.
3301 */
Jon Mason2e41f642010-12-10 14:02:59 +00003302static void vxge_tx_watchdog(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003303{
3304 struct vxgedev *vdev;
3305
3306 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3307
Joe Perches5f54ceb2010-11-15 11:12:30 +00003308 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003309
3310 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3311
Jon Mason2e41f642010-12-10 14:02:59 +00003312 schedule_work(&vdev->reset_task);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003313 vxge_debug_entryexit(VXGE_TRACE,
3314 "%s:%d Exiting...", __func__, __LINE__);
3315}
3316
3317/**
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003318 * vxge_vlan_rx_add_vid
3319 * @dev: net device pointer.
Patrick McHardy80d5c362013-04-19 02:04:28 +00003320 * @proto: vlan protocol
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003321 * @vid: vid
3322 *
3323 * Add the vlan id to the devices vlan id table
3324 */
Jiri Pirko8e586132011-12-08 19:52:37 -05003325static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00003326vxge_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003327{
Jiri Pirko53515732011-07-20 04:54:40 +00003328 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003329 struct vxge_vpath *vpath;
3330 int vp_id;
3331
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003332 /* Add these vlan to the vid table */
3333 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3334 vpath = &vdev->vpaths[vp_id];
3335 if (!vpath->is_open)
3336 continue;
3337 vxge_hw_vpath_vid_add(vpath->handle, vid);
3338 }
Jiri Pirko53515732011-07-20 04:54:40 +00003339 set_bit(vid, vdev->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003340 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003341}
3342
3343/**
Patrick McHardy80d5c362013-04-19 02:04:28 +00003344 * vxge_vlan_rx_kill_vid
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003345 * @dev: net device pointer.
Patrick McHardy80d5c362013-04-19 02:04:28 +00003346 * @proto: vlan protocol
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003347 * @vid: vid
3348 *
3349 * Remove the vlan id from the device's vlan id table
3350 */
Jiri Pirko8e586132011-12-08 19:52:37 -05003351static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00003352vxge_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003353{
Jiri Pirko53515732011-07-20 04:54:40 +00003354 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003355 struct vxge_vpath *vpath;
3356 int vp_id;
3357
3358 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3359
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003360 /* Delete this vlan from the vid table */
3361 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3362 vpath = &vdev->vpaths[vp_id];
3363 if (!vpath->is_open)
3364 continue;
3365 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3366 }
3367 vxge_debug_entryexit(VXGE_TRACE,
3368 "%s:%d Exiting...", __func__, __LINE__);
Jiri Pirko53515732011-07-20 04:54:40 +00003369 clear_bit(vid, vdev->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003370 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003371}
3372
3373static const struct net_device_ops vxge_netdev_ops = {
3374 .ndo_open = vxge_open,
3375 .ndo_stop = vxge_close,
Eric Dumazetdd57f972010-08-18 03:42:54 +00003376 .ndo_get_stats64 = vxge_get_stats64,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003377 .ndo_start_xmit = vxge_xmit,
3378 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003379 .ndo_set_rx_mode = vxge_set_multicast,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003380 .ndo_do_ioctl = vxge_ioctl,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003381 .ndo_set_mac_address = vxge_set_mac_addr,
3382 .ndo_change_mtu = vxge_change_mtu,
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003383 .ndo_fix_features = vxge_fix_features,
3384 .ndo_set_features = vxge_set_features,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003385 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3386 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003387 .ndo_tx_timeout = vxge_tx_watchdog,
3388#ifdef CONFIG_NET_POLL_CONTROLLER
3389 .ndo_poll_controller = vxge_netpoll,
3390#endif
3391};
3392
Bill Pemberton3a036ce2012-12-03 09:23:18 -05003393static int vxge_device_register(struct __vxge_hw_device *hldev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003394 struct vxge_config *config, int high_dma,
3395 int no_of_vpath, struct vxgedev **vdev_out)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003396{
3397 struct net_device *ndev;
3398 enum vxge_hw_status status = VXGE_HW_OK;
3399 struct vxgedev *vdev;
Jon Mason98f45da2010-07-15 08:47:25 +00003400 int ret = 0, no_of_queue = 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003401 u64 stat;
3402
3403 *vdev_out = NULL;
Jon Masond03848e2010-07-15 08:47:23 +00003404 if (config->tx_steering_type)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003405 no_of_queue = no_of_vpath;
3406
3407 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3408 no_of_queue);
3409 if (ndev == NULL) {
3410 vxge_debug_init(
3411 vxge_hw_device_trace_level_get(hldev),
3412 "%s : device allocation failed", __func__);
3413 ret = -ENODEV;
3414 goto _out0;
3415 }
3416
3417 vxge_debug_entryexit(
3418 vxge_hw_device_trace_level_get(hldev),
3419 "%s: %s:%d Entering...",
3420 ndev->name, __func__, __LINE__);
3421
3422 vdev = netdev_priv(ndev);
3423 memset(vdev, 0, sizeof(struct vxgedev));
3424
3425 vdev->ndev = ndev;
3426 vdev->devh = hldev;
3427 vdev->pdev = hldev->pdev;
3428 memcpy(&vdev->config, config, sizeof(struct vxge_config));
Jon Masonb81b3732010-11-11 04:25:58 +00003429 vdev->rx_hwts = 0;
Sergei Shtylyovff938e42011-02-28 11:57:33 -08003430 vdev->titan1 = (vdev->pdev->revision == VXGE_HW_TITAN1_PCI_REVISION);
Jon Masone7935c92010-11-11 04:26:00 +00003431
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003432 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3433
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003434 ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_SG |
3435 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3436 NETIF_F_TSO | NETIF_F_TSO6 |
Patrick McHardyf6469682013-04-19 02:04:27 +00003437 NETIF_F_HW_VLAN_CTAG_TX;
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003438 if (vdev->config.rth_steering != NO_STEERING)
3439 ndev->hw_features |= NETIF_F_RXHASH;
3440
3441 ndev->features |= ndev->hw_features |
Patrick McHardyf6469682013-04-19 02:04:27 +00003442 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_FILTER;
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003443
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003444
3445 ndev->netdev_ops = &vxge_netdev_ops;
3446
3447 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
Jon Mason2e41f642010-12-10 14:02:59 +00003448 INIT_WORK(&vdev->reset_task, vxge_reset);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003449
stephen hemminger42821a52010-10-21 07:50:53 +00003450 vxge_initialize_ethtool_ops(ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003451
3452 /* Allocate memory for vpath */
3453 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3454 no_of_vpath, GFP_KERNEL);
3455 if (!vdev->vpaths) {
3456 vxge_debug_init(VXGE_ERR,
3457 "%s: vpath memory allocation failed",
3458 vdev->ndev->name);
Jon Mason6cca2002011-01-18 15:02:19 +00003459 ret = -ENOMEM;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003460 goto _out1;
3461 }
3462
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003463 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
Masanari Iida278cee02013-06-01 01:30:56 +09003464 "%s : checksumming enabled", __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003465
3466 if (high_dma) {
3467 ndev->features |= NETIF_F_HIGHDMA;
3468 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3469 "%s : using High DMA", __func__);
3470 }
3471
Jon Mason6cca2002011-01-18 15:02:19 +00003472 ret = register_netdev(ndev);
3473 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003474 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3475 "%s: %s : device registration failed!",
3476 ndev->name, __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003477 goto _out2;
3478 }
3479
3480 /* Set the factory defined MAC address initially */
3481 ndev->addr_len = ETH_ALEN;
3482
3483 /* Make Link state as off at this point, when the Link change
3484 * interrupt comes the state will be automatically changed to
3485 * the right state.
3486 */
3487 netif_carrier_off(ndev);
3488
3489 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3490 "%s: Ethernet device registered",
3491 ndev->name);
3492
Jon Masone8ac1752010-11-11 04:25:57 +00003493 hldev->ndev = ndev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003494 *vdev_out = vdev;
3495
3496 /* Resetting the Device stats */
3497 status = vxge_hw_mrpcim_stats_access(
3498 hldev,
3499 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3500 0,
3501 0,
3502 &stat);
3503
3504 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3505 vxge_debug_init(
3506 vxge_hw_device_trace_level_get(hldev),
3507 "%s: device stats clear returns"
3508 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3509
3510 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3511 "%s: %s:%d Exiting...",
3512 ndev->name, __func__, __LINE__);
3513
3514 return ret;
3515_out2:
3516 kfree(vdev->vpaths);
3517_out1:
3518 free_netdev(ndev);
3519_out0:
3520 return ret;
3521}
3522
3523/*
3524 * vxge_device_unregister
3525 *
3526 * This function will unregister and free network device
3527 */
Jon Mason2c913082010-11-11 04:26:03 +00003528static void vxge_device_unregister(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003529{
3530 struct vxgedev *vdev;
3531 struct net_device *dev;
3532 char buf[IFNAMSIZ];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003533
3534 dev = hldev->ndev;
3535 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003536
Jon Mason2c913082010-11-11 04:26:03 +00003537 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d", vdev->ndev->name,
3538 __func__, __LINE__);
3539
Jon Masonead5d232010-11-29 18:02:46 +00003540 strncpy(buf, dev->name, IFNAMSIZ);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003541
Tejun Heo43829732012-08-20 14:51:24 -07003542 flush_work(&vdev->reset_task);
Tejun Heoba27d852010-12-15 04:03:29 +00003543
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003544 /* in 2.6 will call stop() if device is up */
3545 unregister_netdev(dev);
3546
Jon Mason6cca2002011-01-18 15:02:19 +00003547 kfree(vdev->vpaths);
3548
3549 /* we are safe to free it now */
3550 free_netdev(dev);
3551
Jon Mason2c913082010-11-11 04:26:03 +00003552 vxge_debug_init(vdev->level_trace, "%s: ethernet device unregistered",
3553 buf);
3554 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d Exiting...", buf,
3555 __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003556}
3557
3558/*
3559 * vxge_callback_crit_err
3560 *
3561 * This function is called by the alarm handler in interrupt context.
3562 * Driver must analyze it based on the event type.
3563 */
3564static void
3565vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3566 enum vxge_hw_event type, u64 vp_id)
3567{
3568 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +00003569 struct vxgedev *vdev = netdev_priv(dev);
Jon Mason98f45da2010-07-15 08:47:25 +00003570 struct vxge_vpath *vpath = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003571 int vpath_idx;
3572
3573 vxge_debug_entryexit(vdev->level_trace,
3574 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3575
3576 /* Note: This event type should be used for device wide
3577 * indications only - Serious errors, Slot freeze and critical errors
3578 */
3579 vdev->cric_err_event = type;
3580
Jon Mason98f45da2010-07-15 08:47:25 +00003581 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
3582 vpath = &vdev->vpaths[vpath_idx];
3583 if (vpath->device_id == vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003584 break;
Jon Mason98f45da2010-07-15 08:47:25 +00003585 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003586
3587 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3588 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3589 vxge_debug_init(VXGE_ERR,
3590 "%s: Slot is frozen", vdev->ndev->name);
3591 } else if (type == VXGE_HW_EVENT_SERR) {
3592 vxge_debug_init(VXGE_ERR,
3593 "%s: Encountered Serious Error",
3594 vdev->ndev->name);
3595 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3596 vxge_debug_init(VXGE_ERR,
3597 "%s: Encountered Critical Error",
3598 vdev->ndev->name);
3599 }
3600
3601 if ((type == VXGE_HW_EVENT_SERR) ||
3602 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3603 if (unlikely(vdev->exec_mode))
3604 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3605 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3606 vxge_hw_device_mask_all(hldev);
3607 if (unlikely(vdev->exec_mode))
3608 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3609 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3610 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3611
3612 if (unlikely(vdev->exec_mode))
3613 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3614 else {
3615 /* check if this vpath is already set for reset */
3616 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3617
3618 /* disable interrupts for this vpath */
3619 vxge_vpath_intr_disable(vdev, vpath_idx);
3620
3621 /* stop the queue for this vpath */
Jon Mason98f45da2010-07-15 08:47:25 +00003622 netif_tx_stop_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003623 }
3624 }
3625 }
3626
3627 vxge_debug_entryexit(vdev->level_trace,
3628 "%s: %s:%d Exiting...",
3629 vdev->ndev->name, __func__, __LINE__);
3630}
3631
3632static void verify_bandwidth(void)
3633{
3634 int i, band_width, total = 0, equal_priority = 0;
3635
3636 /* 1. If user enters 0 for some fifo, give equal priority to all */
3637 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3638 if (bw_percentage[i] == 0) {
3639 equal_priority = 1;
3640 break;
3641 }
3642 }
3643
3644 if (!equal_priority) {
3645 /* 2. If sum exceeds 100, give equal priority to all */
3646 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3647 if (bw_percentage[i] == 0xFF)
3648 break;
3649
3650 total += bw_percentage[i];
3651 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3652 equal_priority = 1;
3653 break;
3654 }
3655 }
3656 }
3657
3658 if (!equal_priority) {
3659 /* Is all the bandwidth consumed? */
3660 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3661 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3662 /* Split rest of bw equally among next VPs*/
3663 band_width =
3664 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3665 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3666 if (band_width < 2) /* min of 2% */
3667 equal_priority = 1;
3668 else {
3669 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3670 i++)
3671 bw_percentage[i] =
3672 band_width;
3673 }
3674 }
3675 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3676 equal_priority = 1;
3677 }
3678
3679 if (equal_priority) {
3680 vxge_debug_init(VXGE_ERR,
3681 "%s: Assigning equal bandwidth to all the vpaths",
3682 VXGE_DRIVER_NAME);
3683 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3684 VXGE_HW_MAX_VIRTUAL_PATHS;
3685 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3686 bw_percentage[i] = bw_percentage[0];
3687 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003688}
3689
3690/*
3691 * Vpath configuration
3692 */
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003693static int vxge_config_vpaths(struct vxge_hw_device_config *device_config,
3694 u64 vpath_mask, struct vxge_config *config_param)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003695{
3696 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3697 u32 txdl_size, txdl_per_memblock;
3698
3699 temp = driver_config->vpath_per_dev;
3700 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3701 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3702 /* No more CPU. Return vpath number as zero.*/
3703 if (driver_config->g_no_cpus == -1)
3704 return 0;
3705
3706 if (!driver_config->g_no_cpus)
Yuval Mintz9cbb5762012-07-01 03:18:52 +00003707 driver_config->g_no_cpus =
3708 netif_get_num_default_rss_queues();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003709
3710 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3711 if (!driver_config->vpath_per_dev)
3712 driver_config->vpath_per_dev = 1;
3713
3714 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3715 if (!vxge_bVALn(vpath_mask, i, 1))
3716 continue;
3717 else
3718 default_no_vpath++;
3719 if (default_no_vpath < driver_config->vpath_per_dev)
3720 driver_config->vpath_per_dev = default_no_vpath;
3721
3722 driver_config->g_no_cpus = driver_config->g_no_cpus -
3723 (driver_config->vpath_per_dev * 2);
3724 if (driver_config->g_no_cpus <= 0)
3725 driver_config->g_no_cpus = -1;
3726 }
3727
3728 if (driver_config->vpath_per_dev == 1) {
3729 vxge_debug_ll_config(VXGE_TRACE,
3730 "%s: Disable tx and rx steering, "
3731 "as single vpath is configured", VXGE_DRIVER_NAME);
3732 config_param->rth_steering = NO_STEERING;
3733 config_param->tx_steering_type = NO_STEERING;
3734 device_config->rth_en = 0;
3735 }
3736
3737 /* configure bandwidth */
3738 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3739 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3740
3741 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3742 device_config->vp_config[i].vp_id = i;
3743 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3744 if (no_of_vpaths < driver_config->vpath_per_dev) {
3745 if (!vxge_bVALn(vpath_mask, i, 1)) {
3746 vxge_debug_ll_config(VXGE_TRACE,
3747 "%s: vpath: %d is not available",
3748 VXGE_DRIVER_NAME, i);
3749 continue;
3750 } else {
3751 vxge_debug_ll_config(VXGE_TRACE,
3752 "%s: vpath: %d available",
3753 VXGE_DRIVER_NAME, i);
3754 no_of_vpaths++;
3755 }
3756 } else {
3757 vxge_debug_ll_config(VXGE_TRACE,
3758 "%s: vpath: %d is not configured, "
3759 "max_config_vpath exceeded",
3760 VXGE_DRIVER_NAME, i);
3761 break;
3762 }
3763
3764 /* Configure Tx fifo's */
3765 device_config->vp_config[i].fifo.enable =
3766 VXGE_HW_FIFO_ENABLE;
3767 device_config->vp_config[i].fifo.max_frags =
Sreenivasa Honnur5beefb42009-10-28 02:46:54 -07003768 MAX_SKB_FRAGS + 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003769 device_config->vp_config[i].fifo.memblock_size =
3770 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3771
Sreenivasa Honnur5beefb42009-10-28 02:46:54 -07003772 txdl_size = device_config->vp_config[i].fifo.max_frags *
3773 sizeof(struct vxge_hw_fifo_txd);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003774 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3775
3776 device_config->vp_config[i].fifo.fifo_blocks =
3777 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3778
3779 device_config->vp_config[i].fifo.intr =
3780 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3781
3782 /* Configure tti properties */
3783 device_config->vp_config[i].tti.intr_enable =
3784 VXGE_HW_TIM_INTR_ENABLE;
3785
3786 device_config->vp_config[i].tti.btimer_val =
3787 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3788
3789 device_config->vp_config[i].tti.timer_ac_en =
3790 VXGE_HW_TIM_TIMER_AC_ENABLE;
3791
Jon Mason528f7272010-12-10 14:02:56 +00003792 /* For msi-x with napi (each vector has a handler of its own) -
3793 * Set CI to OFF for all vpaths
3794 */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003795 device_config->vp_config[i].tti.timer_ci_en =
3796 VXGE_HW_TIM_TIMER_CI_DISABLE;
3797
3798 device_config->vp_config[i].tti.timer_ri_en =
3799 VXGE_HW_TIM_TIMER_RI_DISABLE;
3800
3801 device_config->vp_config[i].tti.util_sel =
3802 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3803
3804 device_config->vp_config[i].tti.ltimer_val =
3805 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3806
3807 device_config->vp_config[i].tti.rtimer_val =
3808 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3809
3810 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3811 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3812 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3813 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3814 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3815 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3816 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3817
3818 /* Configure Rx rings */
3819 device_config->vp_config[i].ring.enable =
3820 VXGE_HW_RING_ENABLE;
3821
3822 device_config->vp_config[i].ring.ring_blocks =
3823 VXGE_HW_DEF_RING_BLOCKS;
Jon Mason528f7272010-12-10 14:02:56 +00003824
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003825 device_config->vp_config[i].ring.buffer_mode =
3826 VXGE_HW_RING_RXD_BUFFER_MODE_1;
Jon Mason528f7272010-12-10 14:02:56 +00003827
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003828 device_config->vp_config[i].ring.rxds_limit =
3829 VXGE_HW_DEF_RING_RXDS_LIMIT;
Jon Mason528f7272010-12-10 14:02:56 +00003830
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003831 device_config->vp_config[i].ring.scatter_mode =
3832 VXGE_HW_RING_SCATTER_MODE_A;
3833
3834 /* Configure rti properties */
3835 device_config->vp_config[i].rti.intr_enable =
3836 VXGE_HW_TIM_INTR_ENABLE;
3837
3838 device_config->vp_config[i].rti.btimer_val =
3839 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3840
3841 device_config->vp_config[i].rti.timer_ac_en =
3842 VXGE_HW_TIM_TIMER_AC_ENABLE;
3843
3844 device_config->vp_config[i].rti.timer_ci_en =
3845 VXGE_HW_TIM_TIMER_CI_DISABLE;
3846
3847 device_config->vp_config[i].rti.timer_ri_en =
3848 VXGE_HW_TIM_TIMER_RI_DISABLE;
3849
3850 device_config->vp_config[i].rti.util_sel =
3851 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3852
3853 device_config->vp_config[i].rti.urange_a =
3854 RTI_RX_URANGE_A;
3855 device_config->vp_config[i].rti.urange_b =
3856 RTI_RX_URANGE_B;
3857 device_config->vp_config[i].rti.urange_c =
3858 RTI_RX_URANGE_C;
3859 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3860 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3861 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3862 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3863
3864 device_config->vp_config[i].rti.rtimer_val =
3865 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3866
3867 device_config->vp_config[i].rti.ltimer_val =
3868 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3869
3870 device_config->vp_config[i].rpa_strip_vlan_tag =
3871 vlan_tag_strip;
3872 }
3873
3874 driver_config->vpath_per_dev = temp;
3875 return no_of_vpaths;
3876}
3877
3878/* initialize device configuratrions */
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003879static void vxge_device_config_init(struct vxge_hw_device_config *device_config,
3880 int *intr_type)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003881{
3882 /* Used for CQRQ/SRQ. */
3883 device_config->dma_blockpool_initial =
3884 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3885
3886 device_config->dma_blockpool_max =
3887 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3888
3889 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3890 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3891
3892#ifndef CONFIG_PCI_MSI
3893 vxge_debug_init(VXGE_ERR,
3894 "%s: This Kernel does not support "
3895 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3896 *intr_type = INTA;
3897#endif
3898
3899 /* Configure whether MSI-X or IRQL. */
3900 switch (*intr_type) {
3901 case INTA:
3902 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3903 break;
3904
3905 case MSI_X:
Jon Mason16fded72011-01-18 15:02:21 +00003906 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX_ONE_SHOT;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003907 break;
3908 }
Jon Mason528f7272010-12-10 14:02:56 +00003909
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003910 /* Timer period between device poll */
3911 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3912
3913 /* Configure mac based steering. */
3914 device_config->rts_mac_en = addr_learn_en;
3915
3916 /* Configure Vpaths */
3917 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3918
3919 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3920 __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003921 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3922 device_config->intr_mode);
3923 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3924 device_config->device_poll_millis);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003925 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3926 device_config->rth_en);
3927 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3928 device_config->rth_it_type);
3929}
3930
Bill Pemberton3a036ce2012-12-03 09:23:18 -05003931static void vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003932{
3933 int i;
3934
3935 vxge_debug_init(VXGE_TRACE,
3936 "%s: %d Vpath(s) opened",
3937 vdev->ndev->name, vdev->no_of_vpath);
3938
3939 switch (vdev->config.intr_type) {
3940 case INTA:
3941 vxge_debug_init(VXGE_TRACE,
3942 "%s: Interrupt type INTA", vdev->ndev->name);
3943 break;
3944
3945 case MSI_X:
3946 vxge_debug_init(VXGE_TRACE,
3947 "%s: Interrupt type MSI-X", vdev->ndev->name);
3948 break;
3949 }
3950
3951 if (vdev->config.rth_steering) {
3952 vxge_debug_init(VXGE_TRACE,
3953 "%s: RTH steering enabled for TCP_IPV4",
3954 vdev->ndev->name);
3955 } else {
3956 vxge_debug_init(VXGE_TRACE,
3957 "%s: RTH steering disabled", vdev->ndev->name);
3958 }
3959
3960 switch (vdev->config.tx_steering_type) {
3961 case NO_STEERING:
3962 vxge_debug_init(VXGE_TRACE,
3963 "%s: Tx steering disabled", vdev->ndev->name);
3964 break;
3965 case TX_PRIORITY_STEERING:
3966 vxge_debug_init(VXGE_TRACE,
3967 "%s: Unsupported tx steering option",
3968 vdev->ndev->name);
3969 vxge_debug_init(VXGE_TRACE,
3970 "%s: Tx steering disabled", vdev->ndev->name);
3971 vdev->config.tx_steering_type = 0;
3972 break;
3973 case TX_VLAN_STEERING:
3974 vxge_debug_init(VXGE_TRACE,
3975 "%s: Unsupported tx steering option",
3976 vdev->ndev->name);
3977 vxge_debug_init(VXGE_TRACE,
3978 "%s: Tx steering disabled", vdev->ndev->name);
3979 vdev->config.tx_steering_type = 0;
3980 break;
3981 case TX_MULTIQ_STEERING:
3982 vxge_debug_init(VXGE_TRACE,
3983 "%s: Tx multiqueue steering enabled",
3984 vdev->ndev->name);
3985 break;
3986 case TX_PORT_STEERING:
3987 vxge_debug_init(VXGE_TRACE,
3988 "%s: Tx port steering enabled",
3989 vdev->ndev->name);
3990 break;
3991 default:
3992 vxge_debug_init(VXGE_ERR,
3993 "%s: Unsupported tx steering type",
3994 vdev->ndev->name);
3995 vxge_debug_init(VXGE_TRACE,
3996 "%s: Tx steering disabled", vdev->ndev->name);
3997 vdev->config.tx_steering_type = 0;
3998 }
3999
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004000 if (vdev->config.addr_learn_en)
4001 vxge_debug_init(VXGE_TRACE,
4002 "%s: MAC Address learning enabled", vdev->ndev->name);
4003
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004004 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4005 if (!vxge_bVALn(vpath_mask, i, 1))
4006 continue;
4007 vxge_debug_ll_config(VXGE_TRACE,
4008 "%s: MTU size - %d", vdev->ndev->name,
Joe Perches64699332012-06-04 12:44:16 +00004009 ((vdev->devh))->
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004010 config.vp_config[i].mtu);
4011 vxge_debug_init(VXGE_TRACE,
4012 "%s: VLAN tag stripping %s", vdev->ndev->name,
Joe Perches64699332012-06-04 12:44:16 +00004013 ((vdev->devh))->
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004014 config.vp_config[i].rpa_strip_vlan_tag
4015 ? "Enabled" : "Disabled");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004016 vxge_debug_ll_config(VXGE_TRACE,
4017 "%s: Max frags : %d", vdev->ndev->name,
Joe Perches64699332012-06-04 12:44:16 +00004018 ((vdev->devh))->
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004019 config.vp_config[i].fifo.max_frags);
4020 break;
4021 }
4022}
4023
4024#ifdef CONFIG_PM
4025/**
4026 * vxge_pm_suspend - vxge power management suspend entry point
4027 *
4028 */
4029static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
4030{
4031 return -ENOSYS;
4032}
4033/**
4034 * vxge_pm_resume - vxge power management resume entry point
4035 *
4036 */
4037static int vxge_pm_resume(struct pci_dev *pdev)
4038{
4039 return -ENOSYS;
4040}
4041
4042#endif
4043
4044/**
4045 * vxge_io_error_detected - called when PCI error is detected
4046 * @pdev: Pointer to PCI device
4047 * @state: The current pci connection state
4048 *
4049 * This function is called after a PCI bus error affecting
4050 * this device has been detected.
4051 */
4052static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
4053 pci_channel_state_t state)
4054{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004055 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004056 struct net_device *netdev = hldev->ndev;
4057
4058 netif_device_detach(netdev);
4059
Dean Nelsone33b9922009-07-31 09:14:03 +00004060 if (state == pci_channel_io_perm_failure)
4061 return PCI_ERS_RESULT_DISCONNECT;
4062
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004063 if (netif_running(netdev)) {
4064 /* Bring down the card, while avoiding PCI I/O */
4065 do_vxge_close(netdev, 0);
4066 }
4067
4068 pci_disable_device(pdev);
4069
4070 return PCI_ERS_RESULT_NEED_RESET;
4071}
4072
4073/**
4074 * vxge_io_slot_reset - called after the pci bus has been reset.
4075 * @pdev: Pointer to PCI device
4076 *
4077 * Restart the card from scratch, as if from a cold-boot.
4078 * At this point, the card has exprienced a hard reset,
4079 * followed by fixups by BIOS, and has its config space
4080 * set up identically to what it was at cold boot.
4081 */
4082static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
4083{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004084 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004085 struct net_device *netdev = hldev->ndev;
4086
4087 struct vxgedev *vdev = netdev_priv(netdev);
4088
4089 if (pci_enable_device(pdev)) {
Joe Perches75f5e1c2010-07-27 11:47:03 +00004090 netdev_err(netdev, "Cannot re-enable device after reset\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004091 return PCI_ERS_RESULT_DISCONNECT;
4092 }
4093
4094 pci_set_master(pdev);
Jon Mason528f7272010-12-10 14:02:56 +00004095 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004096
4097 return PCI_ERS_RESULT_RECOVERED;
4098}
4099
4100/**
4101 * vxge_io_resume - called when traffic can start flowing again.
4102 * @pdev: Pointer to PCI device
4103 *
4104 * This callback is called when the error recovery driver tells
4105 * us that its OK to resume normal operation.
4106 */
4107static void vxge_io_resume(struct pci_dev *pdev)
4108{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004109 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004110 struct net_device *netdev = hldev->ndev;
4111
4112 if (netif_running(netdev)) {
4113 if (vxge_open(netdev)) {
Joe Perches75f5e1c2010-07-27 11:47:03 +00004114 netdev_err(netdev,
4115 "Can't bring device back up after reset\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004116 return;
4117 }
4118 }
4119
4120 netif_device_attach(netdev);
4121}
4122
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004123static inline u32 vxge_get_num_vfs(u64 function_mode)
4124{
4125 u32 num_functions = 0;
4126
4127 switch (function_mode) {
4128 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4129 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
4130 num_functions = 8;
4131 break;
4132 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4133 num_functions = 1;
4134 break;
4135 case VXGE_HW_FUNCTION_MODE_SRIOV:
4136 case VXGE_HW_FUNCTION_MODE_MRIOV:
4137 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
4138 num_functions = 17;
4139 break;
4140 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
4141 num_functions = 4;
4142 break;
4143 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
4144 num_functions = 2;
4145 break;
4146 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
4147 num_functions = 8; /* TODO */
4148 break;
4149 }
4150 return num_functions;
4151}
4152
Jon Masone8ac1752010-11-11 04:25:57 +00004153int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override)
4154{
4155 struct __vxge_hw_device *hldev = vdev->devh;
4156 u32 maj, min, bld, cmaj, cmin, cbld;
4157 enum vxge_hw_status status;
4158 const struct firmware *fw;
4159 int ret;
4160
4161 ret = request_firmware(&fw, fw_name, &vdev->pdev->dev);
4162 if (ret) {
4163 vxge_debug_init(VXGE_ERR, "%s: Firmware file '%s' not found",
4164 VXGE_DRIVER_NAME, fw_name);
4165 goto out;
4166 }
4167
4168 /* Load the new firmware onto the adapter */
4169 status = vxge_update_fw_image(hldev, fw->data, fw->size);
4170 if (status != VXGE_HW_OK) {
4171 vxge_debug_init(VXGE_ERR,
4172 "%s: FW image download to adapter failed '%s'.",
4173 VXGE_DRIVER_NAME, fw_name);
4174 ret = -EIO;
4175 goto out;
4176 }
4177
4178 /* Read the version of the new firmware */
4179 status = vxge_hw_upgrade_read_version(hldev, &maj, &min, &bld);
4180 if (status != VXGE_HW_OK) {
4181 vxge_debug_init(VXGE_ERR,
4182 "%s: Upgrade read version failed '%s'.",
4183 VXGE_DRIVER_NAME, fw_name);
4184 ret = -EIO;
4185 goto out;
4186 }
4187
4188 cmaj = vdev->config.device_hw_info.fw_version.major;
4189 cmin = vdev->config.device_hw_info.fw_version.minor;
4190 cbld = vdev->config.device_hw_info.fw_version.build;
4191 /* It's possible the version in /lib/firmware is not the latest version.
4192 * If so, we could get into a loop of trying to upgrade to the latest
4193 * and flashing the older version.
4194 */
4195 if (VXGE_FW_VER(maj, min, bld) == VXGE_FW_VER(cmaj, cmin, cbld) &&
4196 !override) {
4197 ret = -EINVAL;
4198 goto out;
4199 }
4200
4201 printk(KERN_NOTICE "Upgrade to firmware version %d.%d.%d commencing\n",
4202 maj, min, bld);
4203
4204 /* Flash the adapter with the new firmware */
4205 status = vxge_hw_flash_fw(hldev);
4206 if (status != VXGE_HW_OK) {
4207 vxge_debug_init(VXGE_ERR, "%s: Upgrade commit failed '%s'.",
4208 VXGE_DRIVER_NAME, fw_name);
4209 ret = -EIO;
4210 goto out;
4211 }
4212
4213 printk(KERN_NOTICE "Upgrade of firmware successful! Adapter must be "
4214 "hard reset before using, thus requiring a system reboot or a "
4215 "hotplug event.\n");
4216
4217out:
Jesper Juhle84f8852011-01-13 10:25:20 +00004218 release_firmware(fw);
Jon Masone8ac1752010-11-11 04:25:57 +00004219 return ret;
4220}
4221
4222static int vxge_probe_fw_update(struct vxgedev *vdev)
4223{
4224 u32 maj, min, bld;
4225 int ret, gpxe = 0;
4226 char *fw_name;
4227
4228 maj = vdev->config.device_hw_info.fw_version.major;
4229 min = vdev->config.device_hw_info.fw_version.minor;
4230 bld = vdev->config.device_hw_info.fw_version.build;
4231
4232 if (VXGE_FW_VER(maj, min, bld) == VXGE_CERT_FW_VER)
4233 return 0;
4234
4235 /* Ignore the build number when determining if the current firmware is
4236 * "too new" to load the driver
4237 */
4238 if (VXGE_FW_VER(maj, min, 0) > VXGE_CERT_FW_VER) {
4239 vxge_debug_init(VXGE_ERR, "%s: Firmware newer than last known "
4240 "version, unable to load driver\n",
4241 VXGE_DRIVER_NAME);
4242 return -EINVAL;
4243 }
4244
4245 /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
4246 * work with this driver.
4247 */
4248 if (VXGE_FW_VER(maj, min, bld) <= VXGE_FW_DEAD_VER) {
4249 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d cannot be "
4250 "upgraded\n", VXGE_DRIVER_NAME, maj, min, bld);
4251 return -EINVAL;
4252 }
4253
4254 /* If file not specified, determine gPXE or not */
4255 if (VXGE_FW_VER(maj, min, bld) >= VXGE_EPROM_FW_VER) {
4256 int i;
4257 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++)
4258 if (vdev->devh->eprom_versions[i]) {
4259 gpxe = 1;
4260 break;
4261 }
4262 }
4263 if (gpxe)
4264 fw_name = "vxge/X3fw-pxe.ncf";
4265 else
4266 fw_name = "vxge/X3fw.ncf";
4267
4268 ret = vxge_fw_upgrade(vdev, fw_name, 0);
4269 /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
4270 * probe, so ignore them
4271 */
4272 if (ret != -EINVAL && ret != -ENOENT)
4273 return -EIO;
4274 else
4275 ret = 0;
4276
4277 if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR, VXGE_CERT_FW_VER_MINOR, 0) >
4278 VXGE_FW_VER(maj, min, 0)) {
4279 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d is too old to"
Jon Masonc0589fa2012-07-09 14:07:57 +00004280 " be used with this driver.",
Jon Masone8ac1752010-11-11 04:25:57 +00004281 VXGE_DRIVER_NAME, maj, min, bld);
4282 return -EINVAL;
4283 }
4284
4285 return ret;
4286}
4287
Bill Pemberton3a036ce2012-12-03 09:23:18 -05004288static int is_sriov_initialized(struct pci_dev *pdev)
Jon Masonc92bf702010-12-10 14:02:57 +00004289{
4290 int pos;
4291 u16 ctrl;
4292
4293 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4294 if (pos) {
4295 pci_read_config_word(pdev, pos + PCI_SRIOV_CTRL, &ctrl);
4296 if (ctrl & PCI_SRIOV_CTRL_VFE)
4297 return 1;
4298 }
4299 return 0;
4300}
4301
stephen hemminger956a2062011-09-16 11:10:01 +00004302static const struct vxge_hw_uld_cbs vxge_callbacks = {
4303 .link_up = vxge_callback_link_up,
4304 .link_down = vxge_callback_link_down,
4305 .crit_err = vxge_callback_crit_err,
4306};
4307
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004308/**
4309 * vxge_probe
4310 * @pdev : structure containing the PCI related information of the device.
4311 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4312 * Description:
4313 * This function is called when a new PCI device gets detected and initializes
4314 * it.
4315 * Return value:
4316 * returns 0 on success and negative on failure.
4317 *
4318 */
Bill Pemberton3a036ce2012-12-03 09:23:18 -05004319static int
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004320vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4321{
Jon Mason2c913082010-11-11 04:26:03 +00004322 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004323 enum vxge_hw_status status;
4324 int ret;
4325 int high_dma = 0;
4326 u64 vpath_mask = 0;
4327 struct vxgedev *vdev;
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004328 struct vxge_config *ll_config = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004329 struct vxge_hw_device_config *device_config = NULL;
4330 struct vxge_hw_device_attr attr;
4331 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4332 u8 *macaddr;
4333 struct vxge_mac_addrs *entry;
4334 static int bus = -1, device = -1;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004335 u32 host_type;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004336 u8 new_device = 0;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004337 enum vxge_hw_status is_privileged;
4338 u32 function_mode;
4339 u32 num_vfs = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004340
4341 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4342 attr.pdev = pdev;
4343
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004344 /* In SRIOV-17 mode, functions of the same adapter
Jon Mason528f7272010-12-10 14:02:56 +00004345 * can be deployed on different buses
4346 */
4347 if (((bus != pdev->bus->number) || (device != PCI_SLOT(pdev->devfn))) &&
4348 !pdev->is_virtfn)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004349 new_device = 1;
4350
4351 bus = pdev->bus->number;
4352 device = PCI_SLOT(pdev->devfn);
4353
4354 if (new_device) {
4355 if (driver_config->config_dev_cnt &&
4356 (driver_config->config_dev_cnt !=
4357 driver_config->total_dev_cnt))
4358 vxge_debug_init(VXGE_ERR,
4359 "%s: Configured %d of %d devices",
4360 VXGE_DRIVER_NAME,
4361 driver_config->config_dev_cnt,
4362 driver_config->total_dev_cnt);
4363 driver_config->config_dev_cnt = 0;
4364 driver_config->total_dev_cnt = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004365 }
Jon Mason528f7272010-12-10 14:02:56 +00004366
Sreenivasa Honnur90023972010-04-08 01:48:30 -07004367 /* Now making the CPU based no of vpath calculation
4368 * applicable for individual functions as well.
4369 */
4370 driver_config->g_no_cpus = 0;
Sreenivasa Honnur657205b2009-10-05 01:52:54 +00004371 driver_config->vpath_per_dev = max_config_vpath;
4372
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004373 driver_config->total_dev_cnt++;
4374 if (++driver_config->config_dev_cnt > max_config_dev) {
4375 ret = 0;
4376 goto _exit0;
4377 }
4378
4379 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4380 GFP_KERNEL);
4381 if (!device_config) {
4382 ret = -ENOMEM;
4383 vxge_debug_init(VXGE_ERR,
4384 "device_config : malloc failed %s %d",
4385 __FILE__, __LINE__);
4386 goto _exit0;
4387 }
4388
Jon Mason528f7272010-12-10 14:02:56 +00004389 ll_config = kzalloc(sizeof(struct vxge_config), GFP_KERNEL);
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004390 if (!ll_config) {
4391 ret = -ENOMEM;
4392 vxge_debug_init(VXGE_ERR,
Jon Mason528f7272010-12-10 14:02:56 +00004393 "device_config : malloc failed %s %d",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004394 __FILE__, __LINE__);
4395 goto _exit0;
4396 }
4397 ll_config->tx_steering_type = TX_MULTIQ_STEERING;
4398 ll_config->intr_type = MSI_X;
4399 ll_config->napi_weight = NEW_NAPI_WEIGHT;
4400 ll_config->rth_steering = RTH_STEERING;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004401
4402 /* get the default configuration parameters */
4403 vxge_hw_device_config_default_get(device_config);
4404
4405 /* initialize configuration parameters */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004406 vxge_device_config_init(device_config, &ll_config->intr_type);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004407
4408 ret = pci_enable_device(pdev);
4409 if (ret) {
4410 vxge_debug_init(VXGE_ERR,
4411 "%s : can not enable PCI device", __func__);
4412 goto _exit0;
4413 }
4414
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004415 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004416 vxge_debug_ll_config(VXGE_TRACE,
4417 "%s : using 64bit DMA", __func__);
4418
4419 high_dma = 1;
4420
4421 if (pci_set_consistent_dma_mask(pdev,
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004422 DMA_BIT_MASK(64))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004423 vxge_debug_init(VXGE_ERR,
4424 "%s : unable to obtain 64bit DMA for "
4425 "consistent allocations", __func__);
4426 ret = -ENOMEM;
4427 goto _exit1;
4428 }
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004429 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004430 vxge_debug_ll_config(VXGE_TRACE,
4431 "%s : using 32bit DMA", __func__);
4432 } else {
4433 ret = -ENOMEM;
4434 goto _exit1;
4435 }
4436
Jon Mason6cca2002011-01-18 15:02:19 +00004437 ret = pci_request_region(pdev, 0, VXGE_DRIVER_NAME);
4438 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004439 vxge_debug_init(VXGE_ERR,
4440 "%s : request regions failed", __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004441 goto _exit1;
4442 }
4443
4444 pci_set_master(pdev);
4445
4446 attr.bar0 = pci_ioremap_bar(pdev, 0);
4447 if (!attr.bar0) {
4448 vxge_debug_init(VXGE_ERR,
4449 "%s : cannot remap io memory bar0", __func__);
4450 ret = -ENODEV;
4451 goto _exit2;
4452 }
4453 vxge_debug_ll_config(VXGE_TRACE,
4454 "pci ioremap bar0: %p:0x%llx",
4455 attr.bar0,
4456 (unsigned long long)pci_resource_start(pdev, 0));
4457
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004458 status = vxge_hw_device_hw_info_get(attr.bar0,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004459 &ll_config->device_hw_info);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004460 if (status != VXGE_HW_OK) {
4461 vxge_debug_init(VXGE_ERR,
4462 "%s: Reading of hardware info failed."
4463 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4464 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004465 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004466 }
4467
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004468 vpath_mask = ll_config->device_hw_info.vpath_mask;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004469 if (vpath_mask == 0) {
4470 vxge_debug_ll_config(VXGE_TRACE,
4471 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4472 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004473 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004474 }
4475
4476 vxge_debug_ll_config(VXGE_TRACE,
4477 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4478 (unsigned long long)vpath_mask);
4479
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004480 function_mode = ll_config->device_hw_info.function_mode;
4481 host_type = ll_config->device_hw_info.host_type;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004482 is_privileged = __vxge_hw_device_is_privilaged(host_type,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004483 ll_config->device_hw_info.func_id);
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004484
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004485 /* Check how many vpaths are available */
4486 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4487 if (!((vpath_mask) & vxge_mBIT(i)))
4488 continue;
4489 max_vpath_supported++;
4490 }
4491
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004492 if (new_device)
4493 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4494
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004495 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
Jon Masonc92bf702010-12-10 14:02:57 +00004496 if (is_sriov(function_mode) && !is_sriov_initialized(pdev) &&
4497 (ll_config->intr_type != INTA)) {
4498 ret = pci_enable_sriov(pdev, num_vfs);
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004499 if (ret)
4500 vxge_debug_ll_config(VXGE_ERR,
4501 "Failed in enabling SRIOV mode: %d\n", ret);
Jon Masonc92bf702010-12-10 14:02:57 +00004502 /* No need to fail out, as an error here is non-fatal */
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004503 }
4504
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004505 /*
4506 * Configure vpaths and get driver configured number of vpaths
4507 * which is less than or equal to the maximum vpaths per function.
4508 */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004509 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004510 if (!no_of_vpath) {
4511 vxge_debug_ll_config(VXGE_ERR,
4512 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4513 ret = 0;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004514 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004515 }
4516
4517 /* Setting driver callbacks */
stephen hemminger956a2062011-09-16 11:10:01 +00004518 attr.uld_callbacks = &vxge_callbacks;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004519
4520 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4521 if (status != VXGE_HW_OK) {
4522 vxge_debug_init(VXGE_ERR,
4523 "Failed to initialize device (%d)", status);
4524 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004525 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004526 }
4527
Jon Masone8ac1752010-11-11 04:25:57 +00004528 if (VXGE_FW_VER(ll_config->device_hw_info.fw_version.major,
4529 ll_config->device_hw_info.fw_version.minor,
4530 ll_config->device_hw_info.fw_version.build) >=
4531 VXGE_EPROM_FW_VER) {
4532 struct eprom_image img[VXGE_HW_MAX_ROM_IMAGES];
4533
4534 status = vxge_hw_vpath_eprom_img_ver_get(hldev, img);
4535 if (status != VXGE_HW_OK) {
4536 vxge_debug_init(VXGE_ERR, "%s: Reading of EPROM failed",
4537 VXGE_DRIVER_NAME);
4538 /* This is a non-fatal error, continue */
4539 }
4540
4541 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
4542 hldev->eprom_versions[i] = img[i].version;
4543 if (!img[i].is_valid)
4544 break;
4545 vxge_debug_init(VXGE_TRACE, "%s: EPROM %d, version "
Jon Mason1d15f812011-01-18 15:02:20 +00004546 "%d.%d.%d.%d", VXGE_DRIVER_NAME, i,
Jon Masone8ac1752010-11-11 04:25:57 +00004547 VXGE_EPROM_IMG_MAJOR(img[i].version),
4548 VXGE_EPROM_IMG_MINOR(img[i].version),
4549 VXGE_EPROM_IMG_FIX(img[i].version),
4550 VXGE_EPROM_IMG_BUILD(img[i].version));
4551 }
4552 }
4553
Sreenivasa Honnurfa41fd12009-10-05 01:56:35 +00004554 /* if FCS stripping is not disabled in MAC fail driver load */
Jon Masonb81b3732010-11-11 04:25:58 +00004555 status = vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask);
4556 if (status != VXGE_HW_OK) {
4557 vxge_debug_init(VXGE_ERR, "%s: FCS stripping is enabled in MAC"
4558 " failing driver load", VXGE_DRIVER_NAME);
Sreenivasa Honnurfa41fd12009-10-05 01:56:35 +00004559 ret = -EINVAL;
4560 goto _exit4;
4561 }
4562
Jon Masoncd883a72011-04-08 11:11:21 +00004563 /* Always enable HWTS. This will always cause the FCS to be invalid,
4564 * due to the fact that HWTS is using the FCS as the location of the
4565 * timestamp. The HW FCS checking will still correctly determine if
4566 * there is a valid checksum, and the FCS is being removed by the driver
4567 * anyway. So no fucntionality is being lost. Since it is always
4568 * enabled, we now simply use the ioctl call to set whether or not the
4569 * driver should be paying attention to the HWTS.
4570 */
4571 if (is_privileged == VXGE_HW_OK) {
4572 status = vxge_timestamp_config(hldev);
4573 if (status != VXGE_HW_OK) {
4574 vxge_debug_init(VXGE_ERR, "%s: HWTS enable failed",
4575 VXGE_DRIVER_NAME);
4576 ret = -EFAULT;
4577 goto _exit4;
4578 }
4579 }
4580
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004581 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4582
4583 /* set private device info */
4584 pci_set_drvdata(pdev, hldev);
4585
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004586 ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4587 ll_config->addr_learn_en = addr_learn_en;
4588 ll_config->rth_algorithm = RTH_ALG_JENKINS;
Jon Mason47f01db2010-11-11 04:25:53 +00004589 ll_config->rth_hash_type_tcpipv4 = 1;
4590 ll_config->rth_hash_type_ipv4 = 0;
4591 ll_config->rth_hash_type_tcpipv6 = 0;
4592 ll_config->rth_hash_type_ipv6 = 0;
4593 ll_config->rth_hash_type_tcpipv6ex = 0;
4594 ll_config->rth_hash_type_ipv6ex = 0;
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004595 ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
4596 ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4597 ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004598
Jon Masone8ac1752010-11-11 04:25:57 +00004599 ret = vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
4600 &vdev);
4601 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004602 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004603 goto _exit4;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004604 }
4605
Jon Masone8ac1752010-11-11 04:25:57 +00004606 ret = vxge_probe_fw_update(vdev);
4607 if (ret)
4608 goto _exit5;
4609
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004610 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4611 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4612 vxge_hw_device_trace_level_get(hldev));
4613
4614 /* set private HW device info */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004615 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4616 vdev->bar0 = attr.bar0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004617 vdev->max_vpath_supported = max_vpath_supported;
4618 vdev->no_of_vpath = no_of_vpath;
4619
4620 /* Virtual Path count */
4621 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4622 if (!vxge_bVALn(vpath_mask, i, 1))
4623 continue;
4624 if (j >= vdev->no_of_vpath)
4625 break;
4626
4627 vdev->vpaths[j].is_configured = 1;
4628 vdev->vpaths[j].device_id = i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004629 vdev->vpaths[j].ring.driver_id = j;
4630 vdev->vpaths[j].vdev = vdev;
4631 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4632 memcpy((u8 *)vdev->vpaths[j].macaddr,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004633 ll_config->device_hw_info.mac_addrs[i],
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004634 ETH_ALEN);
4635
4636 /* Initialize the mac address list header */
4637 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4638
4639 vdev->vpaths[j].mac_addr_cnt = 0;
4640 vdev->vpaths[j].mcast_addr_cnt = 0;
4641 j++;
4642 }
4643 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4644 vdev->max_config_port = max_config_port;
4645
4646 vdev->vlan_tag_strip = vlan_tag_strip;
4647
4648 /* map the hashing selector table to the configured vpaths */
4649 for (i = 0; i < vdev->no_of_vpath; i++)
4650 vdev->vpath_selector[i] = vpath_selector[i];
4651
4652 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4653
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004654 ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4655 ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4656 ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004657
4658 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004659 vdev->ndev->name, ll_config->device_hw_info.serial_number);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004660
4661 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004662 vdev->ndev->name, ll_config->device_hw_info.part_number);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004663
4664 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004665 vdev->ndev->name, ll_config->device_hw_info.product_desc);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004666
hartleysbf54e732010-01-05 06:59:23 +00004667 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4668 vdev->ndev->name, macaddr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004669
4670 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4671 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4672
4673 vxge_debug_init(VXGE_TRACE,
4674 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004675 ll_config->device_hw_info.fw_version.version,
4676 ll_config->device_hw_info.fw_date.date);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004677
Sreenivasa Honnur0a25bdc2009-07-01 21:18:06 +00004678 if (new_device) {
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004679 switch (ll_config->device_hw_info.function_mode) {
Sreenivasa Honnur0a25bdc2009-07-01 21:18:06 +00004680 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4681 vxge_debug_init(VXGE_TRACE,
4682 "%s: Single Function Mode Enabled", vdev->ndev->name);
4683 break;
4684 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4685 vxge_debug_init(VXGE_TRACE,
4686 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4687 break;
4688 case VXGE_HW_FUNCTION_MODE_SRIOV:
4689 vxge_debug_init(VXGE_TRACE,
4690 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4691 break;
4692 case VXGE_HW_FUNCTION_MODE_MRIOV:
4693 vxge_debug_init(VXGE_TRACE,
4694 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4695 break;
4696 }
4697 }
4698
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004699 vxge_print_parm(vdev, vpath_mask);
4700
4701 /* Store the fw version for ethttool option */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004702 strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004703 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004704
4705 /* Copy the station mac address to the list */
4706 for (i = 0; i < vdev->no_of_vpath; i++) {
Joe Perchese80be0b2010-11-27 23:05:45 +00004707 entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004708 if (NULL == entry) {
4709 vxge_debug_init(VXGE_ERR,
4710 "%s: mac_addr_list : memory allocation failed",
4711 vdev->ndev->name);
4712 ret = -EPERM;
Jon Masone8ac1752010-11-11 04:25:57 +00004713 goto _exit6;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004714 }
4715 macaddr = (u8 *)&entry->macaddr;
4716 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4717 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4718 vdev->vpaths[i].mac_addr_cnt = 1;
4719 }
4720
Sreenivasa Honnur914d0d72009-07-01 21:13:12 +00004721 kfree(device_config);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00004722
4723 /*
4724 * INTA is shared in multi-function mode. This is unlike the INTA
4725 * implementation in MR mode, where each VH has its own INTA message.
4726 * - INTA is masked (disabled) as long as at least one function sets
4727 * its TITAN_MASK_ALL_INT.ALARM bit.
4728 * - INTA is unmasked (enabled) when all enabled functions have cleared
4729 * their own TITAN_MASK_ALL_INT.ALARM bit.
4730 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4731 * Though this driver leaves the top level interrupts unmasked while
4732 * leaving the required module interrupt bits masked on exit, there
4733 * could be a rougue driver around that does not follow this procedure
4734 * resulting in a failure to generate interrupts. The following code is
4735 * present to prevent such a failure.
4736 */
4737
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004738 if (ll_config->device_hw_info.function_mode ==
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00004739 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4740 if (vdev->config.intr_type == INTA)
4741 vxge_hw_device_unmask_all(hldev);
4742
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004743 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4744 vdev->ndev->name, __func__, __LINE__);
4745
4746 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4747 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4748 vxge_hw_device_trace_level_get(hldev));
4749
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004750 kfree(ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004751 return 0;
4752
Jon Masone8ac1752010-11-11 04:25:57 +00004753_exit6:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004754 for (i = 0; i < vdev->no_of_vpath; i++)
4755 vxge_free_mac_add_list(&vdev->vpaths[i]);
Jon Masone8ac1752010-11-11 04:25:57 +00004756_exit5:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004757 vxge_device_unregister(hldev);
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004758_exit4:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004759 vxge_hw_device_terminate(hldev);
Jon Mason6cca2002011-01-18 15:02:19 +00004760 pci_disable_sriov(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004761_exit3:
4762 iounmap(attr.bar0);
4763_exit2:
Jon Masondc66daa2010-12-10 14:02:58 +00004764 pci_release_region(pdev, 0);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004765_exit1:
4766 pci_disable_device(pdev);
4767_exit0:
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004768 kfree(ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004769 kfree(device_config);
4770 driver_config->config_dev_cnt--;
Jon Mason6cca2002011-01-18 15:02:19 +00004771 driver_config->total_dev_cnt--;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004772 return ret;
4773}
4774
4775/**
4776 * vxge_rem_nic - Free the PCI device
4777 * @pdev: structure containing the PCI related information of the device.
4778 * Description: This function is called by the Pci subsystem to release a
4779 * PCI device and free up all resource held up by the device.
4780 */
Bill Pemberton3a036ce2012-12-03 09:23:18 -05004781static void vxge_remove(struct pci_dev *pdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004782{
Jon Mason2c913082010-11-11 04:26:03 +00004783 struct __vxge_hw_device *hldev;
Jon Mason6cca2002011-01-18 15:02:19 +00004784 struct vxgedev *vdev;
4785 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004786
Joe Perchesd8ee7072010-11-15 10:13:58 +00004787 hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004788 if (hldev == NULL)
4789 return;
Jon Mason2c913082010-11-11 04:26:03 +00004790
Jon Mason6cca2002011-01-18 15:02:19 +00004791 vdev = netdev_priv(hldev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004792
Jon Mason2c913082010-11-11 04:26:03 +00004793 vxge_debug_entryexit(vdev->level_trace, "%s:%d", __func__, __LINE__);
Jon Mason2c913082010-11-11 04:26:03 +00004794 vxge_debug_init(vdev->level_trace, "%s : removing PCI device...",
4795 __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004796
Jon Mason6cca2002011-01-18 15:02:19 +00004797 for (i = 0; i < vdev->no_of_vpath; i++)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004798 vxge_free_mac_add_list(&vdev->vpaths[i]);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004799
Jon Mason6cca2002011-01-18 15:02:19 +00004800 vxge_device_unregister(hldev);
Jon Mason6cca2002011-01-18 15:02:19 +00004801 /* Do not call pci_disable_sriov here, as it will break child devices */
4802 vxge_hw_device_terminate(hldev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004803 iounmap(vdev->bar0);
Jon Mason6cca2002011-01-18 15:02:19 +00004804 pci_release_region(pdev, 0);
4805 pci_disable_device(pdev);
4806 driver_config->config_dev_cnt--;
4807 driver_config->total_dev_cnt--;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004808
Jon Mason2c913082010-11-11 04:26:03 +00004809 vxge_debug_init(vdev->level_trace, "%s:%d Device unregistered",
4810 __func__, __LINE__);
Jon Mason2c913082010-11-11 04:26:03 +00004811 vxge_debug_entryexit(vdev->level_trace, "%s:%d Exiting...", __func__,
4812 __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004813}
4814
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07004815static const struct pci_error_handlers vxge_err_handler = {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004816 .error_detected = vxge_io_error_detected,
4817 .slot_reset = vxge_io_slot_reset,
4818 .resume = vxge_io_resume,
4819};
4820
4821static struct pci_driver vxge_driver = {
4822 .name = VXGE_DRIVER_NAME,
4823 .id_table = vxge_id_table,
4824 .probe = vxge_probe,
Bill Pemberton3a036ce2012-12-03 09:23:18 -05004825 .remove = vxge_remove,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004826#ifdef CONFIG_PM
4827 .suspend = vxge_pm_suspend,
4828 .resume = vxge_pm_resume,
4829#endif
4830 .err_handler = &vxge_err_handler,
4831};
4832
4833static int __init
4834vxge_starter(void)
4835{
4836 int ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004837
Joe Perches75f5e1c2010-07-27 11:47:03 +00004838 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4839 pr_info("Driver version: %s\n", DRV_VERSION);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004840
4841 verify_bandwidth();
4842
4843 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4844 if (!driver_config)
4845 return -ENOMEM;
4846
4847 ret = pci_register_driver(&vxge_driver);
Jon Mason528f7272010-12-10 14:02:56 +00004848 if (ret) {
4849 kfree(driver_config);
4850 goto err;
4851 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004852
4853 if (driver_config->config_dev_cnt &&
4854 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4855 vxge_debug_init(VXGE_ERR,
4856 "%s: Configured %d of %d devices",
4857 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4858 driver_config->total_dev_cnt);
Jon Mason528f7272010-12-10 14:02:56 +00004859err:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004860 return ret;
4861}
4862
4863static void __exit
4864vxge_closer(void)
4865{
4866 pci_unregister_driver(&vxge_driver);
4867 kfree(driver_config);
4868}
4869module_init(vxge_starter);
4870module_exit(vxge_closer);