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