blob: d403ce29a1418e408d3071410735d07be0ac641b [file] [log] [blame]
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001/*
2 * Copyright 2008 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
4 *
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16 * SOFTWARE.
17 *
18 */
19
20#include <linux/module.h>
21#include <linux/kernel.h>
22#include <linux/string.h>
23#include <linux/errno.h>
24#include <linux/types.h>
25#include <linux/init.h>
26#include <linux/workqueue.h>
27#include <linux/pci.h>
28#include <linux/netdevice.h>
29#include <linux/etherdevice.h>
30#include <linux/if_ether.h>
31#include <linux/if_vlan.h>
32#include <linux/ethtool.h>
33#include <linux/in.h>
34#include <linux/ip.h>
35#include <linux/ipv6.h>
36#include <linux/tcp.h>
37
38#include "cq_enet_desc.h"
39#include "vnic_dev.h"
40#include "vnic_intr.h"
41#include "vnic_stats.h"
42#include "enic_res.h"
43#include "enic.h"
44
45#define ENIC_NOTIFY_TIMER_PERIOD (2 * HZ)
Scott Feldman01f2e4e2008-09-15 09:17:11 -070046
47/* Supported devices */
48static struct pci_device_id enic_id_table[] = {
49 { PCI_VDEVICE(CISCO, 0x0043) },
50 { 0, } /* end of table */
51};
52
53MODULE_DESCRIPTION(DRV_DESCRIPTION);
54MODULE_AUTHOR("Scott Feldman <scofeldm@cisco.com>");
55MODULE_LICENSE("GPL");
56MODULE_VERSION(DRV_VERSION);
57MODULE_DEVICE_TABLE(pci, enic_id_table);
58
59struct enic_stat {
60 char name[ETH_GSTRING_LEN];
61 unsigned int offset;
62};
63
64#define ENIC_TX_STAT(stat) \
65 { .name = #stat, .offset = offsetof(struct vnic_tx_stats, stat) / 8 }
66#define ENIC_RX_STAT(stat) \
67 { .name = #stat, .offset = offsetof(struct vnic_rx_stats, stat) / 8 }
68
69static const struct enic_stat enic_tx_stats[] = {
70 ENIC_TX_STAT(tx_frames_ok),
71 ENIC_TX_STAT(tx_unicast_frames_ok),
72 ENIC_TX_STAT(tx_multicast_frames_ok),
73 ENIC_TX_STAT(tx_broadcast_frames_ok),
74 ENIC_TX_STAT(tx_bytes_ok),
75 ENIC_TX_STAT(tx_unicast_bytes_ok),
76 ENIC_TX_STAT(tx_multicast_bytes_ok),
77 ENIC_TX_STAT(tx_broadcast_bytes_ok),
78 ENIC_TX_STAT(tx_drops),
79 ENIC_TX_STAT(tx_errors),
80 ENIC_TX_STAT(tx_tso),
81};
82
83static const struct enic_stat enic_rx_stats[] = {
84 ENIC_RX_STAT(rx_frames_ok),
85 ENIC_RX_STAT(rx_frames_total),
86 ENIC_RX_STAT(rx_unicast_frames_ok),
87 ENIC_RX_STAT(rx_multicast_frames_ok),
88 ENIC_RX_STAT(rx_broadcast_frames_ok),
89 ENIC_RX_STAT(rx_bytes_ok),
90 ENIC_RX_STAT(rx_unicast_bytes_ok),
91 ENIC_RX_STAT(rx_multicast_bytes_ok),
92 ENIC_RX_STAT(rx_broadcast_bytes_ok),
93 ENIC_RX_STAT(rx_drop),
94 ENIC_RX_STAT(rx_no_bufs),
95 ENIC_RX_STAT(rx_errors),
96 ENIC_RX_STAT(rx_rss),
97 ENIC_RX_STAT(rx_crc_errors),
98 ENIC_RX_STAT(rx_frames_64),
99 ENIC_RX_STAT(rx_frames_127),
100 ENIC_RX_STAT(rx_frames_255),
101 ENIC_RX_STAT(rx_frames_511),
102 ENIC_RX_STAT(rx_frames_1023),
103 ENIC_RX_STAT(rx_frames_1518),
104 ENIC_RX_STAT(rx_frames_to_max),
105};
106
107static const unsigned int enic_n_tx_stats = ARRAY_SIZE(enic_tx_stats);
108static const unsigned int enic_n_rx_stats = ARRAY_SIZE(enic_rx_stats);
109
110static int enic_get_settings(struct net_device *netdev,
111 struct ethtool_cmd *ecmd)
112{
113 struct enic *enic = netdev_priv(netdev);
114
115 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
116 ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
117 ecmd->port = PORT_FIBRE;
118 ecmd->transceiver = XCVR_EXTERNAL;
119
120 if (netif_carrier_ok(netdev)) {
121 ecmd->speed = vnic_dev_port_speed(enic->vdev);
122 ecmd->duplex = DUPLEX_FULL;
123 } else {
124 ecmd->speed = -1;
125 ecmd->duplex = -1;
126 }
127
128 ecmd->autoneg = AUTONEG_DISABLE;
129
130 return 0;
131}
132
133static void enic_get_drvinfo(struct net_device *netdev,
134 struct ethtool_drvinfo *drvinfo)
135{
136 struct enic *enic = netdev_priv(netdev);
137 struct vnic_devcmd_fw_info *fw_info;
138
139 spin_lock(&enic->devcmd_lock);
140 vnic_dev_fw_info(enic->vdev, &fw_info);
141 spin_unlock(&enic->devcmd_lock);
142
143 strncpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
144 strncpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
145 strncpy(drvinfo->fw_version, fw_info->fw_version,
146 sizeof(drvinfo->fw_version));
147 strncpy(drvinfo->bus_info, pci_name(enic->pdev),
148 sizeof(drvinfo->bus_info));
149}
150
151static void enic_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
152{
153 unsigned int i;
154
155 switch (stringset) {
156 case ETH_SS_STATS:
157 for (i = 0; i < enic_n_tx_stats; i++) {
158 memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
159 data += ETH_GSTRING_LEN;
160 }
161 for (i = 0; i < enic_n_rx_stats; i++) {
162 memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
163 data += ETH_GSTRING_LEN;
164 }
165 break;
166 }
167}
168
Scott Feldman25f0a062008-09-24 11:23:32 -0700169static int enic_get_sset_count(struct net_device *netdev, int sset)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700170{
Scott Feldman25f0a062008-09-24 11:23:32 -0700171 switch (sset) {
172 case ETH_SS_STATS:
173 return enic_n_tx_stats + enic_n_rx_stats;
174 default:
175 return -EOPNOTSUPP;
176 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700177}
178
179static void enic_get_ethtool_stats(struct net_device *netdev,
180 struct ethtool_stats *stats, u64 *data)
181{
182 struct enic *enic = netdev_priv(netdev);
183 struct vnic_stats *vstats;
184 unsigned int i;
185
186 spin_lock(&enic->devcmd_lock);
187 vnic_dev_stats_dump(enic->vdev, &vstats);
188 spin_unlock(&enic->devcmd_lock);
189
190 for (i = 0; i < enic_n_tx_stats; i++)
191 *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].offset];
192 for (i = 0; i < enic_n_rx_stats; i++)
193 *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].offset];
194}
195
196static u32 enic_get_rx_csum(struct net_device *netdev)
197{
198 struct enic *enic = netdev_priv(netdev);
199 return enic->csum_rx_enabled;
200}
201
202static int enic_set_rx_csum(struct net_device *netdev, u32 data)
203{
204 struct enic *enic = netdev_priv(netdev);
205
Scott Feldman25f0a062008-09-24 11:23:32 -0700206 if (data && !ENIC_SETTING(enic, RXCSUM))
207 return -EINVAL;
208
209 enic->csum_rx_enabled = !!data;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700210
211 return 0;
212}
213
214static int enic_set_tx_csum(struct net_device *netdev, u32 data)
215{
216 struct enic *enic = netdev_priv(netdev);
217
Scott Feldman25f0a062008-09-24 11:23:32 -0700218 if (data && !ENIC_SETTING(enic, TXCSUM))
219 return -EINVAL;
220
221 if (data)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700222 netdev->features |= NETIF_F_HW_CSUM;
223 else
224 netdev->features &= ~NETIF_F_HW_CSUM;
225
226 return 0;
227}
228
229static int enic_set_tso(struct net_device *netdev, u32 data)
230{
231 struct enic *enic = netdev_priv(netdev);
232
Scott Feldman25f0a062008-09-24 11:23:32 -0700233 if (data && !ENIC_SETTING(enic, TSO))
234 return -EINVAL;
235
236 if (data)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700237 netdev->features |=
238 NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN;
239 else
240 netdev->features &=
241 ~(NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN);
242
243 return 0;
244}
245
246static u32 enic_get_msglevel(struct net_device *netdev)
247{
248 struct enic *enic = netdev_priv(netdev);
249 return enic->msg_enable;
250}
251
252static void enic_set_msglevel(struct net_device *netdev, u32 value)
253{
254 struct enic *enic = netdev_priv(netdev);
255 enic->msg_enable = value;
256}
257
258static struct ethtool_ops enic_ethtool_ops = {
259 .get_settings = enic_get_settings,
260 .get_drvinfo = enic_get_drvinfo,
261 .get_msglevel = enic_get_msglevel,
262 .set_msglevel = enic_set_msglevel,
263 .get_link = ethtool_op_get_link,
264 .get_strings = enic_get_strings,
Scott Feldman25f0a062008-09-24 11:23:32 -0700265 .get_sset_count = enic_get_sset_count,
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700266 .get_ethtool_stats = enic_get_ethtool_stats,
267 .get_rx_csum = enic_get_rx_csum,
268 .set_rx_csum = enic_set_rx_csum,
269 .get_tx_csum = ethtool_op_get_tx_csum,
270 .set_tx_csum = enic_set_tx_csum,
271 .get_sg = ethtool_op_get_sg,
272 .set_sg = ethtool_op_set_sg,
273 .get_tso = ethtool_op_get_tso,
274 .set_tso = enic_set_tso,
275};
276
277static void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
278{
279 struct enic *enic = vnic_dev_priv(wq->vdev);
280
281 if (buf->sop)
282 pci_unmap_single(enic->pdev, buf->dma_addr,
283 buf->len, PCI_DMA_TODEVICE);
284 else
285 pci_unmap_page(enic->pdev, buf->dma_addr,
286 buf->len, PCI_DMA_TODEVICE);
287
288 if (buf->os_buf)
289 dev_kfree_skb_any(buf->os_buf);
290}
291
292static void enic_wq_free_buf(struct vnic_wq *wq,
293 struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque)
294{
295 enic_free_wq_buf(wq, buf);
296}
297
298static int enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
299 u8 type, u16 q_number, u16 completed_index, void *opaque)
300{
301 struct enic *enic = vnic_dev_priv(vdev);
302
303 spin_lock(&enic->wq_lock[q_number]);
304
305 vnic_wq_service(&enic->wq[q_number], cq_desc,
306 completed_index, enic_wq_free_buf,
307 opaque);
308
309 if (netif_queue_stopped(enic->netdev) &&
310 vnic_wq_desc_avail(&enic->wq[q_number]) >= MAX_SKB_FRAGS + 1)
311 netif_wake_queue(enic->netdev);
312
313 spin_unlock(&enic->wq_lock[q_number]);
314
315 return 0;
316}
317
318static void enic_log_q_error(struct enic *enic)
319{
320 unsigned int i;
321 u32 error_status;
322
323 for (i = 0; i < enic->wq_count; i++) {
324 error_status = vnic_wq_error_status(&enic->wq[i]);
325 if (error_status)
326 printk(KERN_ERR PFX "%s: WQ[%d] error_status %d\n",
327 enic->netdev->name, i, error_status);
328 }
329
330 for (i = 0; i < enic->rq_count; i++) {
331 error_status = vnic_rq_error_status(&enic->rq[i]);
332 if (error_status)
333 printk(KERN_ERR PFX "%s: RQ[%d] error_status %d\n",
334 enic->netdev->name, i, error_status);
335 }
336}
337
338static void enic_link_check(struct enic *enic)
339{
340 int link_status = vnic_dev_link_status(enic->vdev);
341 int carrier_ok = netif_carrier_ok(enic->netdev);
342
343 if (link_status && !carrier_ok) {
344 printk(KERN_INFO PFX "%s: Link UP\n", enic->netdev->name);
345 netif_carrier_on(enic->netdev);
346 } else if (!link_status && carrier_ok) {
347 printk(KERN_INFO PFX "%s: Link DOWN\n", enic->netdev->name);
348 netif_carrier_off(enic->netdev);
349 }
350}
351
352static void enic_mtu_check(struct enic *enic)
353{
354 u32 mtu = vnic_dev_mtu(enic->vdev);
355
356 if (mtu != enic->port_mtu) {
357 if (mtu < enic->netdev->mtu)
358 printk(KERN_WARNING PFX
359 "%s: interface MTU (%d) set higher "
360 "than switch port MTU (%d)\n",
361 enic->netdev->name, enic->netdev->mtu, mtu);
362 enic->port_mtu = mtu;
363 }
364}
365
366static void enic_msglvl_check(struct enic *enic)
367{
368 u32 msg_enable = vnic_dev_msg_lvl(enic->vdev);
369
370 if (msg_enable != enic->msg_enable) {
371 printk(KERN_INFO PFX "%s: msg lvl changed from 0x%x to 0x%x\n",
372 enic->netdev->name, enic->msg_enable, msg_enable);
373 enic->msg_enable = msg_enable;
374 }
375}
376
377static void enic_notify_check(struct enic *enic)
378{
379 enic_msglvl_check(enic);
380 enic_mtu_check(enic);
381 enic_link_check(enic);
382}
383
384#define ENIC_TEST_INTR(pba, i) (pba & (1 << i))
385
386static irqreturn_t enic_isr_legacy(int irq, void *data)
387{
388 struct net_device *netdev = data;
389 struct enic *enic = netdev_priv(netdev);
390 u32 pba;
391
392 vnic_intr_mask(&enic->intr[ENIC_INTX_WQ_RQ]);
393
394 pba = vnic_intr_legacy_pba(enic->legacy_pba);
395 if (!pba) {
396 vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
397 return IRQ_NONE; /* not our interrupt */
398 }
399
400 if (ENIC_TEST_INTR(pba, ENIC_INTX_NOTIFY))
401 enic_notify_check(enic);
402
403 if (ENIC_TEST_INTR(pba, ENIC_INTX_ERR)) {
404 enic_log_q_error(enic);
405 /* schedule recovery from WQ/RQ error */
406 schedule_work(&enic->reset);
407 return IRQ_HANDLED;
408 }
409
410 if (ENIC_TEST_INTR(pba, ENIC_INTX_WQ_RQ)) {
411 if (netif_rx_schedule_prep(netdev, &enic->napi))
412 __netif_rx_schedule(netdev, &enic->napi);
413 } else {
414 vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
415 }
416
417 return IRQ_HANDLED;
418}
419
420static irqreturn_t enic_isr_msi(int irq, void *data)
421{
422 struct enic *enic = data;
423
424 /* With MSI, there is no sharing of interrupts, so this is
425 * our interrupt and there is no need to ack it. The device
426 * is not providing per-vector masking, so the OS will not
427 * write to PCI config space to mask/unmask the interrupt.
428 * We're using mask_on_assertion for MSI, so the device
429 * automatically masks the interrupt when the interrupt is
430 * generated. Later, when exiting polling, the interrupt
431 * will be unmasked (see enic_poll).
432 *
433 * Also, the device uses the same PCIe Traffic Class (TC)
434 * for Memory Write data and MSI, so there are no ordering
435 * issues; the MSI will always arrive at the Root Complex
436 * _after_ corresponding Memory Writes (i.e. descriptor
437 * writes).
438 */
439
440 netif_rx_schedule(enic->netdev, &enic->napi);
441
442 return IRQ_HANDLED;
443}
444
445static irqreturn_t enic_isr_msix_rq(int irq, void *data)
446{
447 struct enic *enic = data;
448
449 /* schedule NAPI polling for RQ cleanup */
450 netif_rx_schedule(enic->netdev, &enic->napi);
451
452 return IRQ_HANDLED;
453}
454
455static irqreturn_t enic_isr_msix_wq(int irq, void *data)
456{
457 struct enic *enic = data;
458 unsigned int wq_work_to_do = -1; /* no limit */
459 unsigned int wq_work_done;
460
461 wq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_WQ],
462 wq_work_to_do, enic_wq_service, NULL);
463
464 vnic_intr_return_credits(&enic->intr[ENIC_MSIX_WQ],
465 wq_work_done,
466 1 /* unmask intr */,
467 1 /* reset intr timer */);
468
469 return IRQ_HANDLED;
470}
471
472static irqreturn_t enic_isr_msix_err(int irq, void *data)
473{
474 struct enic *enic = data;
475
476 enic_log_q_error(enic);
477
478 /* schedule recovery from WQ/RQ error */
479 schedule_work(&enic->reset);
480
481 return IRQ_HANDLED;
482}
483
484static irqreturn_t enic_isr_msix_notify(int irq, void *data)
485{
486 struct enic *enic = data;
487
488 enic_notify_check(enic);
489 vnic_intr_unmask(&enic->intr[ENIC_MSIX_NOTIFY]);
490
491 return IRQ_HANDLED;
492}
493
494static inline void enic_queue_wq_skb_cont(struct enic *enic,
495 struct vnic_wq *wq, struct sk_buff *skb,
496 unsigned int len_left)
497{
498 skb_frag_t *frag;
499
500 /* Queue additional data fragments */
501 for (frag = skb_shinfo(skb)->frags; len_left; frag++) {
502 len_left -= frag->size;
503 enic_queue_wq_desc_cont(wq, skb,
504 pci_map_page(enic->pdev, frag->page,
505 frag->page_offset, frag->size,
506 PCI_DMA_TODEVICE),
507 frag->size,
508 (len_left == 0)); /* EOP? */
509 }
510}
511
512static inline void enic_queue_wq_skb_vlan(struct enic *enic,
513 struct vnic_wq *wq, struct sk_buff *skb,
514 int vlan_tag_insert, unsigned int vlan_tag)
515{
516 unsigned int head_len = skb_headlen(skb);
517 unsigned int len_left = skb->len - head_len;
518 int eop = (len_left == 0);
519
520 /* Queue the main skb fragment */
521 enic_queue_wq_desc(wq, skb,
522 pci_map_single(enic->pdev, skb->data,
523 head_len, PCI_DMA_TODEVICE),
524 head_len,
525 vlan_tag_insert, vlan_tag,
526 eop);
527
528 if (!eop)
529 enic_queue_wq_skb_cont(enic, wq, skb, len_left);
530}
531
532static inline void enic_queue_wq_skb_csum_l4(struct enic *enic,
533 struct vnic_wq *wq, struct sk_buff *skb,
534 int vlan_tag_insert, unsigned int vlan_tag)
535{
536 unsigned int head_len = skb_headlen(skb);
537 unsigned int len_left = skb->len - head_len;
538 unsigned int hdr_len = skb_transport_offset(skb);
539 unsigned int csum_offset = hdr_len + skb->csum_offset;
540 int eop = (len_left == 0);
541
542 /* Queue the main skb fragment */
543 enic_queue_wq_desc_csum_l4(wq, skb,
544 pci_map_single(enic->pdev, skb->data,
545 head_len, PCI_DMA_TODEVICE),
546 head_len,
547 csum_offset,
548 hdr_len,
549 vlan_tag_insert, vlan_tag,
550 eop);
551
552 if (!eop)
553 enic_queue_wq_skb_cont(enic, wq, skb, len_left);
554}
555
556static inline void enic_queue_wq_skb_tso(struct enic *enic,
557 struct vnic_wq *wq, struct sk_buff *skb, unsigned int mss,
558 int vlan_tag_insert, unsigned int vlan_tag)
559{
560 unsigned int head_len = skb_headlen(skb);
561 unsigned int len_left = skb->len - head_len;
562 unsigned int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
563 int eop = (len_left == 0);
564
565 /* Preload TCP csum field with IP pseudo hdr calculated
566 * with IP length set to zero. HW will later add in length
567 * to each TCP segment resulting from the TSO.
568 */
569
570 if (skb->protocol == __constant_htons(ETH_P_IP)) {
571 ip_hdr(skb)->check = 0;
572 tcp_hdr(skb)->check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
573 ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
574 } else if (skb->protocol == __constant_htons(ETH_P_IPV6)) {
575 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
576 &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
577 }
578
579 /* Queue the main skb fragment */
580 enic_queue_wq_desc_tso(wq, skb,
581 pci_map_single(enic->pdev, skb->data,
582 head_len, PCI_DMA_TODEVICE),
583 head_len,
584 mss, hdr_len,
585 vlan_tag_insert, vlan_tag,
586 eop);
587
588 if (!eop)
589 enic_queue_wq_skb_cont(enic, wq, skb, len_left);
590}
591
592static inline void enic_queue_wq_skb(struct enic *enic,
593 struct vnic_wq *wq, struct sk_buff *skb)
594{
595 unsigned int mss = skb_shinfo(skb)->gso_size;
596 unsigned int vlan_tag = 0;
597 int vlan_tag_insert = 0;
598
599 if (enic->vlan_group && vlan_tx_tag_present(skb)) {
600 /* VLAN tag from trunking driver */
601 vlan_tag_insert = 1;
602 vlan_tag = vlan_tx_tag_get(skb);
603 }
604
605 if (mss)
606 enic_queue_wq_skb_tso(enic, wq, skb, mss,
607 vlan_tag_insert, vlan_tag);
608 else if (skb->ip_summed == CHECKSUM_PARTIAL)
609 enic_queue_wq_skb_csum_l4(enic, wq, skb,
610 vlan_tag_insert, vlan_tag);
611 else
612 enic_queue_wq_skb_vlan(enic, wq, skb,
613 vlan_tag_insert, vlan_tag);
614}
615
616/* netif_tx_lock held, process context with BHs disabled */
617static int enic_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev)
618{
619 struct enic *enic = netdev_priv(netdev);
620 struct vnic_wq *wq = &enic->wq[0];
621 unsigned long flags;
622
623 if (skb->len <= 0) {
624 dev_kfree_skb(skb);
625 return NETDEV_TX_OK;
626 }
627
628 /* Non-TSO sends must fit within ENIC_NON_TSO_MAX_DESC descs,
629 * which is very likely. In the off chance it's going to take
630 * more than * ENIC_NON_TSO_MAX_DESC, linearize the skb.
631 */
632
633 if (skb_shinfo(skb)->gso_size == 0 &&
634 skb_shinfo(skb)->nr_frags + 1 > ENIC_NON_TSO_MAX_DESC &&
635 skb_linearize(skb)) {
636 dev_kfree_skb(skb);
637 return NETDEV_TX_OK;
638 }
639
640 spin_lock_irqsave(&enic->wq_lock[0], flags);
641
642 if (vnic_wq_desc_avail(wq) < skb_shinfo(skb)->nr_frags + 1) {
643 netif_stop_queue(netdev);
644 /* This is a hard error, log it */
645 printk(KERN_ERR PFX "%s: BUG! Tx ring full when "
646 "queue awake!\n", netdev->name);
647 spin_unlock_irqrestore(&enic->wq_lock[0], flags);
648 return NETDEV_TX_BUSY;
649 }
650
651 enic_queue_wq_skb(enic, wq, skb);
652
653 if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + 1)
654 netif_stop_queue(netdev);
655
656 netdev->trans_start = jiffies;
657
658 spin_unlock_irqrestore(&enic->wq_lock[0], flags);
659
660 return NETDEV_TX_OK;
661}
662
663/* dev_base_lock rwlock held, nominally process context */
664static struct net_device_stats *enic_get_stats(struct net_device *netdev)
665{
666 struct enic *enic = netdev_priv(netdev);
Scott Feldman25f0a062008-09-24 11:23:32 -0700667 struct net_device_stats *net_stats = &netdev->stats;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700668 struct vnic_stats *stats;
669
670 spin_lock(&enic->devcmd_lock);
671 vnic_dev_stats_dump(enic->vdev, &stats);
672 spin_unlock(&enic->devcmd_lock);
673
Scott Feldman25f0a062008-09-24 11:23:32 -0700674 net_stats->tx_packets = stats->tx.tx_frames_ok;
675 net_stats->tx_bytes = stats->tx.tx_bytes_ok;
676 net_stats->tx_errors = stats->tx.tx_errors;
677 net_stats->tx_dropped = stats->tx.tx_drops;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700678
Scott Feldman25f0a062008-09-24 11:23:32 -0700679 net_stats->rx_packets = stats->rx.rx_frames_ok;
680 net_stats->rx_bytes = stats->rx.rx_bytes_ok;
681 net_stats->rx_errors = stats->rx.rx_errors;
682 net_stats->multicast = stats->rx.rx_multicast_frames_ok;
683 net_stats->rx_crc_errors = stats->rx.rx_crc_errors;
684 net_stats->rx_dropped = stats->rx.rx_no_bufs;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700685
Scott Feldman25f0a062008-09-24 11:23:32 -0700686 return net_stats;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700687}
688
689static void enic_reset_mcaddrs(struct enic *enic)
690{
691 enic->mc_count = 0;
692}
693
694static int enic_set_mac_addr(struct net_device *netdev, char *addr)
695{
696 if (!is_valid_ether_addr(addr))
697 return -EADDRNOTAVAIL;
698
699 memcpy(netdev->dev_addr, addr, netdev->addr_len);
700
701 return 0;
702}
703
704/* netif_tx_lock held, BHs disabled */
705static void enic_set_multicast_list(struct net_device *netdev)
706{
707 struct enic *enic = netdev_priv(netdev);
708 struct dev_mc_list *list = netdev->mc_list;
709 int directed = 1;
710 int multicast = (netdev->flags & IFF_MULTICAST) ? 1 : 0;
711 int broadcast = (netdev->flags & IFF_BROADCAST) ? 1 : 0;
712 int promisc = (netdev->flags & IFF_PROMISC) ? 1 : 0;
713 int allmulti = (netdev->flags & IFF_ALLMULTI) ||
714 (netdev->mc_count > ENIC_MULTICAST_PERFECT_FILTERS);
715 u8 mc_addr[ENIC_MULTICAST_PERFECT_FILTERS][ETH_ALEN];
716 unsigned int mc_count = netdev->mc_count;
717 unsigned int i, j;
718
719 if (mc_count > ENIC_MULTICAST_PERFECT_FILTERS)
720 mc_count = ENIC_MULTICAST_PERFECT_FILTERS;
721
722 spin_lock(&enic->devcmd_lock);
723
724 vnic_dev_packet_filter(enic->vdev, directed,
725 multicast, broadcast, promisc, allmulti);
726
727 /* Is there an easier way? Trying to minimize to
728 * calls to add/del multicast addrs. We keep the
729 * addrs from the last call in enic->mc_addr and
730 * look for changes to add/del.
731 */
732
733 for (i = 0; list && i < mc_count; i++) {
734 memcpy(mc_addr[i], list->dmi_addr, ETH_ALEN);
735 list = list->next;
736 }
737
738 for (i = 0; i < enic->mc_count; i++) {
739 for (j = 0; j < mc_count; j++)
740 if (compare_ether_addr(enic->mc_addr[i],
741 mc_addr[j]) == 0)
742 break;
743 if (j == mc_count)
744 enic_del_multicast_addr(enic, enic->mc_addr[i]);
745 }
746
747 for (i = 0; i < mc_count; i++) {
748 for (j = 0; j < enic->mc_count; j++)
749 if (compare_ether_addr(mc_addr[i],
750 enic->mc_addr[j]) == 0)
751 break;
752 if (j == enic->mc_count)
753 enic_add_multicast_addr(enic, mc_addr[i]);
754 }
755
756 /* Save the list to compare against next time
757 */
758
759 for (i = 0; i < mc_count; i++)
760 memcpy(enic->mc_addr[i], mc_addr[i], ETH_ALEN);
761
762 enic->mc_count = mc_count;
763
764 spin_unlock(&enic->devcmd_lock);
765}
766
767/* rtnl lock is held */
768static void enic_vlan_rx_register(struct net_device *netdev,
769 struct vlan_group *vlan_group)
770{
771 struct enic *enic = netdev_priv(netdev);
772 enic->vlan_group = vlan_group;
773}
774
775/* rtnl lock is held */
776static void enic_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
777{
778 struct enic *enic = netdev_priv(netdev);
779
780 spin_lock(&enic->devcmd_lock);
781 enic_add_vlan(enic, vid);
782 spin_unlock(&enic->devcmd_lock);
783}
784
785/* rtnl lock is held */
786static void enic_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
787{
788 struct enic *enic = netdev_priv(netdev);
789
790 spin_lock(&enic->devcmd_lock);
791 enic_del_vlan(enic, vid);
792 spin_unlock(&enic->devcmd_lock);
793}
794
795/* netif_tx_lock held, BHs disabled */
796static void enic_tx_timeout(struct net_device *netdev)
797{
798 struct enic *enic = netdev_priv(netdev);
799 schedule_work(&enic->reset);
800}
801
802static void enic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf)
803{
804 struct enic *enic = vnic_dev_priv(rq->vdev);
805
806 if (!buf->os_buf)
807 return;
808
809 pci_unmap_single(enic->pdev, buf->dma_addr,
810 buf->len, PCI_DMA_FROMDEVICE);
811 dev_kfree_skb_any(buf->os_buf);
812}
813
814static inline struct sk_buff *enic_rq_alloc_skb(unsigned int size)
815{
816 struct sk_buff *skb;
817
818 skb = dev_alloc_skb(size + NET_IP_ALIGN);
819
820 if (skb)
821 skb_reserve(skb, NET_IP_ALIGN);
822
823 return skb;
824}
825
826static int enic_rq_alloc_buf(struct vnic_rq *rq)
827{
828 struct enic *enic = vnic_dev_priv(rq->vdev);
829 struct sk_buff *skb;
830 unsigned int len = enic->netdev->mtu + ETH_HLEN;
831 unsigned int os_buf_index = 0;
832 dma_addr_t dma_addr;
833
834 skb = enic_rq_alloc_skb(len);
835 if (!skb)
836 return -ENOMEM;
837
838 dma_addr = pci_map_single(enic->pdev, skb->data,
839 len, PCI_DMA_FROMDEVICE);
840
841 enic_queue_rq_desc(rq, skb, os_buf_index,
842 dma_addr, len);
843
844 return 0;
845}
846
847static int enic_get_skb_header(struct sk_buff *skb, void **iphdr,
848 void **tcph, u64 *hdr_flags, void *priv)
849{
850 struct cq_enet_rq_desc *cq_desc = priv;
851 unsigned int ip_len;
852 struct iphdr *iph;
853
854 u8 type, color, eop, sop, ingress_port, vlan_stripped;
855 u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof;
856 u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
857 u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc;
858 u8 packet_error;
859 u16 q_number, completed_index, bytes_written, vlan, checksum;
860 u32 rss_hash;
861
862 cq_enet_rq_desc_dec(cq_desc,
863 &type, &color, &q_number, &completed_index,
864 &ingress_port, &fcoe, &eop, &sop, &rss_type,
865 &csum_not_calc, &rss_hash, &bytes_written,
866 &packet_error, &vlan_stripped, &vlan, &checksum,
867 &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error,
868 &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp,
869 &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment,
870 &fcs_ok);
871
872 if (!(ipv4 && tcp && !ipv4_fragment))
873 return -1;
874
875 skb_reset_network_header(skb);
876 iph = ip_hdr(skb);
877
878 ip_len = ip_hdrlen(skb);
879 skb_set_transport_header(skb, ip_len);
880
881 /* check if ip header and tcp header are complete */
882 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
883 return -1;
884
885 *hdr_flags = LRO_IPV4 | LRO_TCP;
886 *tcph = tcp_hdr(skb);
887 *iphdr = iph;
888
889 return 0;
890}
891
892static void enic_rq_indicate_buf(struct vnic_rq *rq,
893 struct cq_desc *cq_desc, struct vnic_rq_buf *buf,
894 int skipped, void *opaque)
895{
896 struct enic *enic = vnic_dev_priv(rq->vdev);
897 struct sk_buff *skb;
898
899 u8 type, color, eop, sop, ingress_port, vlan_stripped;
900 u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof;
901 u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
902 u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc;
903 u8 packet_error;
904 u16 q_number, completed_index, bytes_written, vlan, checksum;
905 u32 rss_hash;
906
907 if (skipped)
908 return;
909
910 skb = buf->os_buf;
911 prefetch(skb->data - NET_IP_ALIGN);
912 pci_unmap_single(enic->pdev, buf->dma_addr,
913 buf->len, PCI_DMA_FROMDEVICE);
914
915 cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc,
916 &type, &color, &q_number, &completed_index,
917 &ingress_port, &fcoe, &eop, &sop, &rss_type,
918 &csum_not_calc, &rss_hash, &bytes_written,
919 &packet_error, &vlan_stripped, &vlan, &checksum,
920 &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error,
921 &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp,
922 &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment,
923 &fcs_ok);
924
925 if (packet_error) {
926
927 if (bytes_written > 0 && !fcs_ok) {
928 if (net_ratelimit())
929 printk(KERN_ERR PFX
930 "%s: packet error: bad FCS\n",
931 enic->netdev->name);
932 }
933
934 dev_kfree_skb_any(skb);
935
936 return;
937 }
938
939 if (eop && bytes_written > 0) {
940
941 /* Good receive
942 */
943
944 skb_put(skb, bytes_written);
945 skb->protocol = eth_type_trans(skb, enic->netdev);
946
947 if (enic->csum_rx_enabled && !csum_not_calc) {
948 skb->csum = htons(checksum);
949 skb->ip_summed = CHECKSUM_COMPLETE;
950 }
951
952 skb->dev = enic->netdev;
953 enic->netdev->last_rx = jiffies;
954
955 if (enic->vlan_group && vlan_stripped) {
956
Scott Feldmand9c3c572008-09-24 11:23:22 -0700957 if (ENIC_SETTING(enic, LRO) && ipv4)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700958 lro_vlan_hwaccel_receive_skb(&enic->lro_mgr,
959 skb, enic->vlan_group,
960 vlan, cq_desc);
961 else
962 vlan_hwaccel_receive_skb(skb,
963 enic->vlan_group, vlan);
964
965 } else {
966
Scott Feldmand9c3c572008-09-24 11:23:22 -0700967 if (ENIC_SETTING(enic, LRO) && ipv4)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700968 lro_receive_skb(&enic->lro_mgr, skb, cq_desc);
969 else
970 netif_receive_skb(skb);
971
972 }
973
974 } else {
975
976 /* Buffer overflow
977 */
978
979 dev_kfree_skb_any(skb);
980 }
981}
982
983static int enic_rq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
984 u8 type, u16 q_number, u16 completed_index, void *opaque)
985{
986 struct enic *enic = vnic_dev_priv(vdev);
987
988 vnic_rq_service(&enic->rq[q_number], cq_desc,
989 completed_index, VNIC_RQ_RETURN_DESC,
990 enic_rq_indicate_buf, opaque);
991
992 return 0;
993}
994
995static void enic_rq_drop_buf(struct vnic_rq *rq,
996 struct cq_desc *cq_desc, struct vnic_rq_buf *buf,
997 int skipped, void *opaque)
998{
999 struct enic *enic = vnic_dev_priv(rq->vdev);
1000 struct sk_buff *skb = buf->os_buf;
1001
1002 if (skipped)
1003 return;
1004
1005 pci_unmap_single(enic->pdev, buf->dma_addr,
1006 buf->len, PCI_DMA_FROMDEVICE);
1007
1008 dev_kfree_skb_any(skb);
1009}
1010
1011static int enic_rq_service_drop(struct vnic_dev *vdev, struct cq_desc *cq_desc,
1012 u8 type, u16 q_number, u16 completed_index, void *opaque)
1013{
1014 struct enic *enic = vnic_dev_priv(vdev);
1015
1016 vnic_rq_service(&enic->rq[q_number], cq_desc,
1017 completed_index, VNIC_RQ_RETURN_DESC,
1018 enic_rq_drop_buf, opaque);
1019
1020 return 0;
1021}
1022
1023static int enic_poll(struct napi_struct *napi, int budget)
1024{
1025 struct enic *enic = container_of(napi, struct enic, napi);
1026 struct net_device *netdev = enic->netdev;
1027 unsigned int rq_work_to_do = budget;
1028 unsigned int wq_work_to_do = -1; /* no limit */
1029 unsigned int work_done, rq_work_done, wq_work_done;
1030
1031 /* Service RQ (first) and WQ
1032 */
1033
1034 rq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_RQ],
1035 rq_work_to_do, enic_rq_service, NULL);
1036
1037 wq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_WQ],
1038 wq_work_to_do, enic_wq_service, NULL);
1039
1040 /* Accumulate intr event credits for this polling
1041 * cycle. An intr event is the completion of a
1042 * a WQ or RQ packet.
1043 */
1044
1045 work_done = rq_work_done + wq_work_done;
1046
1047 if (work_done > 0)
1048 vnic_intr_return_credits(&enic->intr[ENIC_INTX_WQ_RQ],
1049 work_done,
1050 0 /* don't unmask intr */,
1051 0 /* don't reset intr timer */);
1052
1053 if (rq_work_done > 0) {
1054
1055 /* Replenish RQ
1056 */
1057
1058 vnic_rq_fill(&enic->rq[0], enic_rq_alloc_buf);
1059
1060 } else {
1061
1062 /* If no work done, flush all LROs and exit polling
1063 */
1064
1065 if (ENIC_SETTING(enic, LRO))
1066 lro_flush_all(&enic->lro_mgr);
1067
1068 netif_rx_complete(netdev, napi);
1069 vnic_intr_unmask(&enic->intr[ENIC_MSIX_RQ]);
1070 }
1071
1072 return rq_work_done;
1073}
1074
1075static int enic_poll_msix(struct napi_struct *napi, int budget)
1076{
1077 struct enic *enic = container_of(napi, struct enic, napi);
1078 struct net_device *netdev = enic->netdev;
1079 unsigned int work_to_do = budget;
1080 unsigned int work_done;
1081
1082 /* Service RQ
1083 */
1084
1085 work_done = vnic_cq_service(&enic->cq[ENIC_CQ_RQ],
1086 work_to_do, enic_rq_service, NULL);
1087
1088 if (work_done > 0) {
1089
1090 /* Replenish RQ
1091 */
1092
1093 vnic_rq_fill(&enic->rq[0], enic_rq_alloc_buf);
1094
1095 /* Accumulate intr event credits for this polling
1096 * cycle. An intr event is the completion of a
1097 * a WQ or RQ packet.
1098 */
1099
1100 vnic_intr_return_credits(&enic->intr[ENIC_MSIX_RQ],
1101 work_done,
1102 0 /* don't unmask intr */,
1103 0 /* don't reset intr timer */);
1104 } else {
1105
1106 /* If no work done, flush all LROs and exit polling
1107 */
1108
1109 if (ENIC_SETTING(enic, LRO))
1110 lro_flush_all(&enic->lro_mgr);
1111
1112 netif_rx_complete(netdev, napi);
1113 vnic_intr_unmask(&enic->intr[ENIC_MSIX_RQ]);
1114 }
1115
1116 return work_done;
1117}
1118
1119static void enic_notify_timer(unsigned long data)
1120{
1121 struct enic *enic = (struct enic *)data;
1122
1123 enic_notify_check(enic);
1124
Scott Feldman25f0a062008-09-24 11:23:32 -07001125 mod_timer(&enic->notify_timer,
1126 round_jiffies(jiffies + ENIC_NOTIFY_TIMER_PERIOD));
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001127}
1128
1129static void enic_free_intr(struct enic *enic)
1130{
1131 struct net_device *netdev = enic->netdev;
1132 unsigned int i;
1133
1134 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1135 case VNIC_DEV_INTR_MODE_INTX:
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001136 free_irq(enic->pdev->irq, netdev);
1137 break;
Scott Feldman8f4d2482008-09-24 11:23:42 -07001138 case VNIC_DEV_INTR_MODE_MSI:
1139 free_irq(enic->pdev->irq, enic);
1140 break;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001141 case VNIC_DEV_INTR_MODE_MSIX:
1142 for (i = 0; i < ARRAY_SIZE(enic->msix); i++)
1143 if (enic->msix[i].requested)
1144 free_irq(enic->msix_entry[i].vector,
1145 enic->msix[i].devid);
1146 break;
1147 default:
1148 break;
1149 }
1150}
1151
1152static int enic_request_intr(struct enic *enic)
1153{
1154 struct net_device *netdev = enic->netdev;
1155 unsigned int i;
1156 int err = 0;
1157
1158 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1159
1160 case VNIC_DEV_INTR_MODE_INTX:
1161
1162 err = request_irq(enic->pdev->irq, enic_isr_legacy,
1163 IRQF_SHARED, netdev->name, netdev);
1164 break;
1165
1166 case VNIC_DEV_INTR_MODE_MSI:
1167
1168 err = request_irq(enic->pdev->irq, enic_isr_msi,
1169 0, netdev->name, enic);
1170 break;
1171
1172 case VNIC_DEV_INTR_MODE_MSIX:
1173
1174 sprintf(enic->msix[ENIC_MSIX_RQ].devname,
Scott Feldman8f4d2482008-09-24 11:23:42 -07001175 "%.11s-rx-0", netdev->name);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001176 enic->msix[ENIC_MSIX_RQ].isr = enic_isr_msix_rq;
1177 enic->msix[ENIC_MSIX_RQ].devid = enic;
1178
1179 sprintf(enic->msix[ENIC_MSIX_WQ].devname,
Scott Feldman8f4d2482008-09-24 11:23:42 -07001180 "%.11s-tx-0", netdev->name);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001181 enic->msix[ENIC_MSIX_WQ].isr = enic_isr_msix_wq;
1182 enic->msix[ENIC_MSIX_WQ].devid = enic;
1183
1184 sprintf(enic->msix[ENIC_MSIX_ERR].devname,
1185 "%.11s-err", netdev->name);
1186 enic->msix[ENIC_MSIX_ERR].isr = enic_isr_msix_err;
1187 enic->msix[ENIC_MSIX_ERR].devid = enic;
1188
1189 sprintf(enic->msix[ENIC_MSIX_NOTIFY].devname,
1190 "%.11s-notify", netdev->name);
1191 enic->msix[ENIC_MSIX_NOTIFY].isr = enic_isr_msix_notify;
1192 enic->msix[ENIC_MSIX_NOTIFY].devid = enic;
1193
1194 for (i = 0; i < ARRAY_SIZE(enic->msix); i++) {
1195 err = request_irq(enic->msix_entry[i].vector,
1196 enic->msix[i].isr, 0,
1197 enic->msix[i].devname,
1198 enic->msix[i].devid);
1199 if (err) {
1200 enic_free_intr(enic);
1201 break;
1202 }
1203 enic->msix[i].requested = 1;
1204 }
1205
1206 break;
1207
1208 default:
1209 break;
1210 }
1211
1212 return err;
1213}
1214
1215static int enic_notify_set(struct enic *enic)
1216{
1217 int err;
1218
1219 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1220 case VNIC_DEV_INTR_MODE_INTX:
1221 err = vnic_dev_notify_set(enic->vdev, ENIC_INTX_NOTIFY);
1222 break;
1223 case VNIC_DEV_INTR_MODE_MSIX:
1224 err = vnic_dev_notify_set(enic->vdev, ENIC_MSIX_NOTIFY);
1225 break;
1226 default:
1227 err = vnic_dev_notify_set(enic->vdev, -1 /* no intr */);
1228 break;
1229 }
1230
1231 return err;
1232}
1233
1234static void enic_notify_timer_start(struct enic *enic)
1235{
1236 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1237 case VNIC_DEV_INTR_MODE_MSI:
1238 mod_timer(&enic->notify_timer, jiffies);
1239 break;
1240 default:
1241 /* Using intr for notification for INTx/MSI-X */
1242 break;
1243 };
1244}
1245
1246/* rtnl lock is held, process context */
1247static int enic_open(struct net_device *netdev)
1248{
1249 struct enic *enic = netdev_priv(netdev);
1250 unsigned int i;
1251 int err;
1252
1253 for (i = 0; i < enic->rq_count; i++) {
1254 err = vnic_rq_fill(&enic->rq[i], enic_rq_alloc_buf);
1255 if (err) {
1256 printk(KERN_ERR PFX
1257 "%s: Unable to alloc receive buffers.\n",
1258 netdev->name);
1259 return err;
1260 }
1261 }
1262
1263 for (i = 0; i < enic->wq_count; i++)
1264 vnic_wq_enable(&enic->wq[i]);
1265 for (i = 0; i < enic->rq_count; i++)
1266 vnic_rq_enable(&enic->rq[i]);
1267
1268 enic_add_station_addr(enic);
1269 enic_set_multicast_list(netdev);
1270
1271 netif_wake_queue(netdev);
1272 napi_enable(&enic->napi);
1273 vnic_dev_enable(enic->vdev);
1274
1275 for (i = 0; i < enic->intr_count; i++)
1276 vnic_intr_unmask(&enic->intr[i]);
1277
1278 enic_notify_timer_start(enic);
1279
1280 return 0;
1281}
1282
1283/* rtnl lock is held, process context */
1284static int enic_stop(struct net_device *netdev)
1285{
1286 struct enic *enic = netdev_priv(netdev);
1287 unsigned int i;
1288 int err;
1289
1290 del_timer_sync(&enic->notify_timer);
1291
1292 vnic_dev_disable(enic->vdev);
1293 napi_disable(&enic->napi);
1294 netif_stop_queue(netdev);
1295
1296 for (i = 0; i < enic->intr_count; i++)
1297 vnic_intr_mask(&enic->intr[i]);
1298
1299 for (i = 0; i < enic->wq_count; i++) {
1300 err = vnic_wq_disable(&enic->wq[i]);
1301 if (err)
1302 return err;
1303 }
1304 for (i = 0; i < enic->rq_count; i++) {
1305 err = vnic_rq_disable(&enic->rq[i]);
1306 if (err)
1307 return err;
1308 }
1309
1310 (void)vnic_cq_service(&enic->cq[ENIC_CQ_RQ],
1311 -1, enic_rq_service_drop, NULL);
1312 (void)vnic_cq_service(&enic->cq[ENIC_CQ_WQ],
1313 -1, enic_wq_service, NULL);
1314
1315 for (i = 0; i < enic->wq_count; i++)
1316 vnic_wq_clean(&enic->wq[i], enic_free_wq_buf);
1317 for (i = 0; i < enic->rq_count; i++)
1318 vnic_rq_clean(&enic->rq[i], enic_free_rq_buf);
1319 for (i = 0; i < enic->cq_count; i++)
1320 vnic_cq_clean(&enic->cq[i]);
1321 for (i = 0; i < enic->intr_count; i++)
1322 vnic_intr_clean(&enic->intr[i]);
1323
1324 return 0;
1325}
1326
1327static int enic_change_mtu(struct net_device *netdev, int new_mtu)
1328{
1329 struct enic *enic = netdev_priv(netdev);
1330 int running = netif_running(netdev);
1331
Scott Feldman25f0a062008-09-24 11:23:32 -07001332 if (new_mtu < ENIC_MIN_MTU || new_mtu > ENIC_MAX_MTU)
1333 return -EINVAL;
1334
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001335 if (running)
1336 enic_stop(netdev);
1337
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001338 netdev->mtu = new_mtu;
1339
1340 if (netdev->mtu > enic->port_mtu)
1341 printk(KERN_WARNING PFX
1342 "%s: interface MTU (%d) set higher "
1343 "than port MTU (%d)\n",
1344 netdev->name, netdev->mtu, enic->port_mtu);
1345
1346 if (running)
1347 enic_open(netdev);
1348
1349 return 0;
1350}
1351
1352#ifdef CONFIG_NET_POLL_CONTROLLER
1353static void enic_poll_controller(struct net_device *netdev)
1354{
1355 struct enic *enic = netdev_priv(netdev);
1356 struct vnic_dev *vdev = enic->vdev;
1357
1358 switch (vnic_dev_get_intr_mode(vdev)) {
1359 case VNIC_DEV_INTR_MODE_MSIX:
1360 enic_isr_msix_rq(enic->pdev->irq, enic);
1361 enic_isr_msix_wq(enic->pdev->irq, enic);
1362 break;
1363 case VNIC_DEV_INTR_MODE_MSI:
1364 enic_isr_msi(enic->pdev->irq, enic);
1365 break;
1366 case VNIC_DEV_INTR_MODE_INTX:
1367 enic_isr_legacy(enic->pdev->irq, netdev);
1368 break;
1369 default:
1370 break;
1371 }
1372}
1373#endif
1374
1375static int enic_dev_wait(struct vnic_dev *vdev,
1376 int (*start)(struct vnic_dev *, int),
1377 int (*finished)(struct vnic_dev *, int *),
1378 int arg)
1379{
1380 unsigned long time;
1381 int done;
1382 int err;
1383
1384 BUG_ON(in_interrupt());
1385
1386 err = start(vdev, arg);
1387 if (err)
1388 return err;
1389
1390 /* Wait for func to complete...2 seconds max
1391 */
1392
1393 time = jiffies + (HZ * 2);
1394 do {
1395
1396 err = finished(vdev, &done);
1397 if (err)
1398 return err;
1399
1400 if (done)
1401 return 0;
1402
1403 schedule_timeout_uninterruptible(HZ / 10);
1404
1405 } while (time_after(time, jiffies));
1406
1407 return -ETIMEDOUT;
1408}
1409
1410static int enic_dev_open(struct enic *enic)
1411{
1412 int err;
1413
1414 err = enic_dev_wait(enic->vdev, vnic_dev_open,
1415 vnic_dev_open_done, 0);
1416 if (err)
1417 printk(KERN_ERR PFX
1418 "vNIC device open failed, err %d.\n", err);
1419
1420 return err;
1421}
1422
1423static int enic_dev_soft_reset(struct enic *enic)
1424{
1425 int err;
1426
1427 err = enic_dev_wait(enic->vdev, vnic_dev_soft_reset,
1428 vnic_dev_soft_reset_done, 0);
1429 if (err)
1430 printk(KERN_ERR PFX
1431 "vNIC soft reset failed, err %d.\n", err);
1432
1433 return err;
1434}
1435
1436static void enic_reset(struct work_struct *work)
1437{
1438 struct enic *enic = container_of(work, struct enic, reset);
1439
1440 if (!netif_running(enic->netdev))
1441 return;
1442
1443 rtnl_lock();
1444
1445 spin_lock(&enic->devcmd_lock);
1446 vnic_dev_hang_notify(enic->vdev);
1447 spin_unlock(&enic->devcmd_lock);
1448
1449 enic_stop(enic->netdev);
1450 enic_dev_soft_reset(enic);
1451 enic_reset_mcaddrs(enic);
1452 enic_init_vnic_resources(enic);
1453 enic_open(enic->netdev);
1454
1455 rtnl_unlock();
1456}
1457
1458static int enic_set_intr_mode(struct enic *enic)
1459{
1460 unsigned int n = ARRAY_SIZE(enic->rq);
1461 unsigned int m = ARRAY_SIZE(enic->wq);
1462 unsigned int i;
1463
1464 /* Set interrupt mode (INTx, MSI, MSI-X) depending
1465 * system capabilities.
1466 *
1467 * Try MSI-X first
1468 *
1469 * We need n RQs, m WQs, n+m CQs, and n+m+2 INTRs
1470 * (the second to last INTR is used for WQ/RQ errors)
1471 * (the last INTR is used for notifications)
1472 */
1473
1474 BUG_ON(ARRAY_SIZE(enic->msix_entry) < n + m + 2);
1475 for (i = 0; i < n + m + 2; i++)
1476 enic->msix_entry[i].entry = i;
1477
1478 if (enic->config.intr_mode < 1 &&
1479 enic->rq_count >= n &&
1480 enic->wq_count >= m &&
1481 enic->cq_count >= n + m &&
1482 enic->intr_count >= n + m + 2 &&
1483 !pci_enable_msix(enic->pdev, enic->msix_entry, n + m + 2)) {
1484
1485 enic->rq_count = n;
1486 enic->wq_count = m;
1487 enic->cq_count = n + m;
1488 enic->intr_count = n + m + 2;
1489
1490 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSIX);
1491
1492 return 0;
1493 }
1494
1495 /* Next try MSI
1496 *
1497 * We need 1 RQ, 1 WQ, 2 CQs, and 1 INTR
1498 */
1499
1500 if (enic->config.intr_mode < 2 &&
1501 enic->rq_count >= 1 &&
1502 enic->wq_count >= 1 &&
1503 enic->cq_count >= 2 &&
1504 enic->intr_count >= 1 &&
1505 !pci_enable_msi(enic->pdev)) {
1506
1507 enic->rq_count = 1;
1508 enic->wq_count = 1;
1509 enic->cq_count = 2;
1510 enic->intr_count = 1;
1511
1512 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSI);
1513
1514 return 0;
1515 }
1516
1517 /* Next try INTx
1518 *
1519 * We need 1 RQ, 1 WQ, 2 CQs, and 3 INTRs
1520 * (the first INTR is used for WQ/RQ)
1521 * (the second INTR is used for WQ/RQ errors)
1522 * (the last INTR is used for notifications)
1523 */
1524
1525 if (enic->config.intr_mode < 3 &&
1526 enic->rq_count >= 1 &&
1527 enic->wq_count >= 1 &&
1528 enic->cq_count >= 2 &&
1529 enic->intr_count >= 3) {
1530
1531 enic->rq_count = 1;
1532 enic->wq_count = 1;
1533 enic->cq_count = 2;
1534 enic->intr_count = 3;
1535
1536 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_INTX);
1537
1538 return 0;
1539 }
1540
1541 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
1542
1543 return -EINVAL;
1544}
1545
1546static void enic_clear_intr_mode(struct enic *enic)
1547{
1548 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1549 case VNIC_DEV_INTR_MODE_MSIX:
1550 pci_disable_msix(enic->pdev);
1551 break;
1552 case VNIC_DEV_INTR_MODE_MSI:
1553 pci_disable_msi(enic->pdev);
1554 break;
1555 default:
1556 break;
1557 }
1558
1559 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
1560}
1561
1562static void enic_iounmap(struct enic *enic)
1563{
1564 if (enic->bar0.vaddr)
1565 iounmap(enic->bar0.vaddr);
1566}
1567
1568static int __devinit enic_probe(struct pci_dev *pdev,
1569 const struct pci_device_id *ent)
1570{
1571 struct net_device *netdev;
1572 struct enic *enic;
1573 int using_dac = 0;
1574 unsigned int i;
1575 int err;
1576
1577 const u8 rss_default_cpu = 0;
1578 const u8 rss_hash_type = 0;
1579 const u8 rss_hash_bits = 0;
1580 const u8 rss_base_cpu = 0;
1581 const u8 rss_enable = 0;
1582 const u8 tso_ipid_split_en = 0;
1583 const u8 ig_vlan_strip_en = 1;
1584
1585 /* Allocate net device structure and initialize. Private
1586 * instance data is initialized to zero.
1587 */
1588
1589 netdev = alloc_etherdev(sizeof(struct enic));
1590 if (!netdev) {
1591 printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
1592 return -ENOMEM;
1593 }
1594
1595 /* Set the netdev name early so intr vectors are properly
1596 * named and any error msgs can include netdev->name
1597 */
1598
1599 rtnl_lock();
1600 err = dev_alloc_name(netdev, netdev->name);
1601 rtnl_unlock();
1602 if (err < 0) {
1603 printk(KERN_ERR PFX "Unable to allocate netdev name.\n");
1604 goto err_out_free_netdev;
1605 }
1606
1607 pci_set_drvdata(pdev, netdev);
1608
1609 SET_NETDEV_DEV(netdev, &pdev->dev);
1610
1611 enic = netdev_priv(netdev);
1612 enic->netdev = netdev;
1613 enic->pdev = pdev;
1614
1615 /* Setup PCI resources
1616 */
1617
1618 err = pci_enable_device(pdev);
1619 if (err) {
1620 printk(KERN_ERR PFX
1621 "%s: Cannot enable PCI device, aborting.\n",
1622 netdev->name);
1623 goto err_out_free_netdev;
1624 }
1625
1626 err = pci_request_regions(pdev, DRV_NAME);
1627 if (err) {
1628 printk(KERN_ERR PFX
1629 "%s: Cannot request PCI regions, aborting.\n",
1630 netdev->name);
1631 goto err_out_disable_device;
1632 }
1633
1634 pci_set_master(pdev);
1635
1636 /* Query PCI controller on system for DMA addressing
1637 * limitation for the device. Try 40-bit first, and
1638 * fail to 32-bit.
1639 */
1640
1641 err = pci_set_dma_mask(pdev, DMA_40BIT_MASK);
1642 if (err) {
1643 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
1644 if (err) {
1645 printk(KERN_ERR PFX
1646 "%s: No usable DMA configuration, aborting.\n",
1647 netdev->name);
1648 goto err_out_release_regions;
1649 }
1650 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
1651 if (err) {
1652 printk(KERN_ERR PFX
1653 "%s: Unable to obtain 32-bit DMA "
1654 "for consistent allocations, aborting.\n",
1655 netdev->name);
1656 goto err_out_release_regions;
1657 }
1658 } else {
1659 err = pci_set_consistent_dma_mask(pdev, DMA_40BIT_MASK);
1660 if (err) {
1661 printk(KERN_ERR PFX
1662 "%s: Unable to obtain 40-bit DMA "
1663 "for consistent allocations, aborting.\n",
1664 netdev->name);
1665 goto err_out_release_regions;
1666 }
1667 using_dac = 1;
1668 }
1669
1670 /* Map vNIC resources from BAR0
1671 */
1672
1673 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1674 printk(KERN_ERR PFX
1675 "%s: BAR0 not memory-map'able, aborting.\n",
1676 netdev->name);
1677 err = -ENODEV;
1678 goto err_out_release_regions;
1679 }
1680
1681 enic->bar0.vaddr = pci_iomap(pdev, 0, enic->bar0.len);
1682 enic->bar0.bus_addr = pci_resource_start(pdev, 0);
1683 enic->bar0.len = pci_resource_len(pdev, 0);
1684
1685 if (!enic->bar0.vaddr) {
1686 printk(KERN_ERR PFX
1687 "%s: Cannot memory-map BAR0 res hdr, aborting.\n",
1688 netdev->name);
1689 err = -ENODEV;
1690 goto err_out_release_regions;
1691 }
1692
1693 /* Register vNIC device
1694 */
1695
1696 enic->vdev = vnic_dev_register(NULL, enic, pdev, &enic->bar0);
1697 if (!enic->vdev) {
1698 printk(KERN_ERR PFX
1699 "%s: vNIC registration failed, aborting.\n",
1700 netdev->name);
1701 err = -ENODEV;
1702 goto err_out_iounmap;
1703 }
1704
1705 /* Issue device open to get device in known state
1706 */
1707
1708 err = enic_dev_open(enic);
1709 if (err) {
1710 printk(KERN_ERR PFX
1711 "%s: vNIC dev open failed, aborting.\n",
1712 netdev->name);
1713 goto err_out_vnic_unregister;
1714 }
1715
1716 /* Issue device init to initialize the vnic-to-switch link.
1717 * We'll start with carrier off and wait for link UP
1718 * notification later to turn on carrier. We don't need
1719 * to wait here for the vnic-to-switch link initialization
1720 * to complete; link UP notification is the indication that
1721 * the process is complete.
1722 */
1723
1724 netif_carrier_off(netdev);
1725
1726 err = vnic_dev_init(enic->vdev, 0);
1727 if (err) {
1728 printk(KERN_ERR PFX
1729 "%s: vNIC dev init failed, aborting.\n",
1730 netdev->name);
1731 goto err_out_dev_close;
1732 }
1733
1734 /* Get vNIC configuration
1735 */
1736
1737 err = enic_get_vnic_config(enic);
1738 if (err) {
1739 printk(KERN_ERR PFX
1740 "%s: Get vNIC configuration failed, aborting.\n",
1741 netdev->name);
1742 goto err_out_dev_close;
1743 }
1744
1745 /* Get available resource counts
1746 */
1747
1748 enic_get_res_counts(enic);
1749
1750 /* Set interrupt mode based on resource counts and system
1751 * capabilities
1752 */
1753
1754 err = enic_set_intr_mode(enic);
1755 if (err) {
1756 printk(KERN_ERR PFX
1757 "%s: Failed to set intr mode, aborting.\n",
1758 netdev->name);
1759 goto err_out_dev_close;
1760 }
1761
1762 /* Request interrupt vector(s)
1763 */
1764
1765 err = enic_request_intr(enic);
1766 if (err) {
1767 printk(KERN_ERR PFX "%s: Unable to request irq.\n",
1768 netdev->name);
1769 goto err_out_dev_close;
1770 }
1771
1772 /* Allocate and configure vNIC resources
1773 */
1774
1775 err = enic_alloc_vnic_resources(enic);
1776 if (err) {
1777 printk(KERN_ERR PFX
1778 "%s: Failed to alloc vNIC resources, aborting.\n",
1779 netdev->name);
1780 goto err_out_free_vnic_resources;
1781 }
1782
1783 enic_init_vnic_resources(enic);
1784
1785 /* Enable VLAN tag stripping. RSS not enabled (yet).
1786 */
1787
1788 err = enic_set_nic_cfg(enic,
1789 rss_default_cpu, rss_hash_type,
1790 rss_hash_bits, rss_base_cpu,
1791 rss_enable, tso_ipid_split_en,
1792 ig_vlan_strip_en);
1793 if (err) {
1794 printk(KERN_ERR PFX
1795 "%s: Failed to config nic, aborting.\n",
1796 netdev->name);
1797 goto err_out_free_vnic_resources;
1798 }
1799
1800 /* Setup notification buffer area
1801 */
1802
1803 err = enic_notify_set(enic);
1804 if (err) {
1805 printk(KERN_ERR PFX
1806 "%s: Failed to alloc notify buffer, aborting.\n",
1807 netdev->name);
1808 goto err_out_free_vnic_resources;
1809 }
1810
1811 /* Setup notification timer, HW reset task, and locks
1812 */
1813
1814 init_timer(&enic->notify_timer);
1815 enic->notify_timer.function = enic_notify_timer;
1816 enic->notify_timer.data = (unsigned long)enic;
1817
1818 INIT_WORK(&enic->reset, enic_reset);
1819
1820 for (i = 0; i < enic->wq_count; i++)
1821 spin_lock_init(&enic->wq_lock[i]);
1822
1823 spin_lock_init(&enic->devcmd_lock);
1824
1825 /* Register net device
1826 */
1827
1828 enic->port_mtu = enic->config.mtu;
1829 (void)enic_change_mtu(netdev, enic->port_mtu);
1830
1831 err = enic_set_mac_addr(netdev, enic->mac_addr);
1832 if (err) {
1833 printk(KERN_ERR PFX
1834 "%s: Invalid MAC address, aborting.\n",
1835 netdev->name);
1836 goto err_out_notify_unset;
1837 }
1838
1839 netdev->open = enic_open;
1840 netdev->stop = enic_stop;
1841 netdev->hard_start_xmit = enic_hard_start_xmit;
1842 netdev->get_stats = enic_get_stats;
1843 netdev->set_multicast_list = enic_set_multicast_list;
1844 netdev->change_mtu = enic_change_mtu;
1845 netdev->vlan_rx_register = enic_vlan_rx_register;
1846 netdev->vlan_rx_add_vid = enic_vlan_rx_add_vid;
1847 netdev->vlan_rx_kill_vid = enic_vlan_rx_kill_vid;
1848 netdev->tx_timeout = enic_tx_timeout;
1849 netdev->watchdog_timeo = 2 * HZ;
1850 netdev->ethtool_ops = &enic_ethtool_ops;
1851#ifdef CONFIG_NET_POLL_CONTROLLER
1852 netdev->poll_controller = enic_poll_controller;
1853#endif
1854
1855 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1856 default:
1857 netif_napi_add(netdev, &enic->napi, enic_poll, 64);
1858 break;
1859 case VNIC_DEV_INTR_MODE_MSIX:
1860 netif_napi_add(netdev, &enic->napi, enic_poll_msix, 64);
1861 break;
1862 }
1863
1864 netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
1865 if (ENIC_SETTING(enic, TXCSUM))
1866 netdev->features |= NETIF_F_SG | NETIF_F_HW_CSUM;
1867 if (ENIC_SETTING(enic, TSO))
1868 netdev->features |= NETIF_F_TSO |
1869 NETIF_F_TSO6 | NETIF_F_TSO_ECN;
1870 if (using_dac)
1871 netdev->features |= NETIF_F_HIGHDMA;
1872
1873
1874 enic->csum_rx_enabled = ENIC_SETTING(enic, RXCSUM);
1875
1876 if (ENIC_SETTING(enic, LRO)) {
1877 enic->lro_mgr.max_aggr = ENIC_LRO_MAX_AGGR;
1878 enic->lro_mgr.max_desc = ENIC_LRO_MAX_DESC;
1879 enic->lro_mgr.lro_arr = enic->lro_desc;
1880 enic->lro_mgr.get_skb_header = enic_get_skb_header;
1881 enic->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1882 enic->lro_mgr.dev = netdev;
1883 enic->lro_mgr.ip_summed = CHECKSUM_COMPLETE;
1884 enic->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1885 }
1886
1887 err = register_netdev(netdev);
1888 if (err) {
1889 printk(KERN_ERR PFX
1890 "%s: Cannot register net device, aborting.\n",
1891 netdev->name);
1892 goto err_out_notify_unset;
1893 }
1894
1895 return 0;
1896
1897err_out_notify_unset:
1898 vnic_dev_notify_unset(enic->vdev);
1899err_out_free_vnic_resources:
1900 enic_free_vnic_resources(enic);
1901 enic_free_intr(enic);
1902err_out_dev_close:
1903 vnic_dev_close(enic->vdev);
1904err_out_vnic_unregister:
1905 enic_clear_intr_mode(enic);
1906 vnic_dev_unregister(enic->vdev);
1907err_out_iounmap:
1908 enic_iounmap(enic);
1909err_out_release_regions:
1910 pci_release_regions(pdev);
1911err_out_disable_device:
1912 pci_disable_device(pdev);
1913err_out_free_netdev:
1914 pci_set_drvdata(pdev, NULL);
1915 free_netdev(netdev);
1916
1917 return err;
1918}
1919
1920static void __devexit enic_remove(struct pci_dev *pdev)
1921{
1922 struct net_device *netdev = pci_get_drvdata(pdev);
1923
1924 if (netdev) {
1925 struct enic *enic = netdev_priv(netdev);
1926
1927 flush_scheduled_work();
1928 unregister_netdev(netdev);
1929 vnic_dev_notify_unset(enic->vdev);
1930 enic_free_vnic_resources(enic);
1931 enic_free_intr(enic);
1932 vnic_dev_close(enic->vdev);
1933 enic_clear_intr_mode(enic);
1934 vnic_dev_unregister(enic->vdev);
1935 enic_iounmap(enic);
1936 pci_release_regions(pdev);
1937 pci_disable_device(pdev);
1938 pci_set_drvdata(pdev, NULL);
1939 free_netdev(netdev);
1940 }
1941}
1942
1943static struct pci_driver enic_driver = {
1944 .name = DRV_NAME,
1945 .id_table = enic_id_table,
1946 .probe = enic_probe,
1947 .remove = __devexit_p(enic_remove),
1948};
1949
1950static int __init enic_init_module(void)
1951{
1952 printk(KERN_INFO PFX "%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION);
1953
1954 return pci_register_driver(&enic_driver);
1955}
1956
1957static void __exit enic_cleanup_module(void)
1958{
1959 pci_unregister_driver(&enic_driver);
1960}
1961
1962module_init(enic_init_module);
1963module_exit(enic_cleanup_module);