d7ac6c17547c9ad8f1cacc1db6de7f1e32264bb4
[deliverable/linux.git] / drivers / net / ethernet / cisco / enic / enic_main.c
1 /*
2 * Copyright 2008-2010 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/interrupt.h>
27 #include <linux/workqueue.h>
28 #include <linux/pci.h>
29 #include <linux/netdevice.h>
30 #include <linux/etherdevice.h>
31 #include <linux/if.h>
32 #include <linux/if_ether.h>
33 #include <linux/if_vlan.h>
34 #include <linux/ethtool.h>
35 #include <linux/in.h>
36 #include <linux/ip.h>
37 #include <linux/ipv6.h>
38 #include <linux/tcp.h>
39 #include <linux/rtnetlink.h>
40 #include <linux/prefetch.h>
41 #include <net/ip6_checksum.h>
42
43 #include "cq_enet_desc.h"
44 #include "vnic_dev.h"
45 #include "vnic_intr.h"
46 #include "vnic_stats.h"
47 #include "vnic_vic.h"
48 #include "enic_res.h"
49 #include "enic.h"
50 #include "enic_dev.h"
51 #include "enic_pp.h"
52
53 #define ENIC_NOTIFY_TIMER_PERIOD (2 * HZ)
54 #define WQ_ENET_MAX_DESC_LEN (1 << WQ_ENET_LEN_BITS)
55 #define MAX_TSO (1 << 16)
56 #define ENIC_DESC_MAX_SPLITS (MAX_TSO / WQ_ENET_MAX_DESC_LEN + 1)
57
58 #define PCI_DEVICE_ID_CISCO_VIC_ENET 0x0043 /* ethernet vnic */
59 #define PCI_DEVICE_ID_CISCO_VIC_ENET_DYN 0x0044 /* enet dynamic vnic */
60 #define PCI_DEVICE_ID_CISCO_VIC_ENET_VF 0x0071 /* enet SRIOV VF */
61
62 /* Supported devices */
63 static DEFINE_PCI_DEVICE_TABLE(enic_id_table) = {
64 { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET) },
65 { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET_DYN) },
66 { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET_VF) },
67 { 0, } /* end of table */
68 };
69
70 MODULE_DESCRIPTION(DRV_DESCRIPTION);
71 MODULE_AUTHOR("Scott Feldman <scofeldm@cisco.com>");
72 MODULE_LICENSE("GPL");
73 MODULE_VERSION(DRV_VERSION);
74 MODULE_DEVICE_TABLE(pci, enic_id_table);
75
76 struct enic_stat {
77 char name[ETH_GSTRING_LEN];
78 unsigned int offset;
79 };
80
81 #define ENIC_TX_STAT(stat) \
82 { .name = #stat, .offset = offsetof(struct vnic_tx_stats, stat) / 8 }
83 #define ENIC_RX_STAT(stat) \
84 { .name = #stat, .offset = offsetof(struct vnic_rx_stats, stat) / 8 }
85
86 static const struct enic_stat enic_tx_stats[] = {
87 ENIC_TX_STAT(tx_frames_ok),
88 ENIC_TX_STAT(tx_unicast_frames_ok),
89 ENIC_TX_STAT(tx_multicast_frames_ok),
90 ENIC_TX_STAT(tx_broadcast_frames_ok),
91 ENIC_TX_STAT(tx_bytes_ok),
92 ENIC_TX_STAT(tx_unicast_bytes_ok),
93 ENIC_TX_STAT(tx_multicast_bytes_ok),
94 ENIC_TX_STAT(tx_broadcast_bytes_ok),
95 ENIC_TX_STAT(tx_drops),
96 ENIC_TX_STAT(tx_errors),
97 ENIC_TX_STAT(tx_tso),
98 };
99
100 static const struct enic_stat enic_rx_stats[] = {
101 ENIC_RX_STAT(rx_frames_ok),
102 ENIC_RX_STAT(rx_frames_total),
103 ENIC_RX_STAT(rx_unicast_frames_ok),
104 ENIC_RX_STAT(rx_multicast_frames_ok),
105 ENIC_RX_STAT(rx_broadcast_frames_ok),
106 ENIC_RX_STAT(rx_bytes_ok),
107 ENIC_RX_STAT(rx_unicast_bytes_ok),
108 ENIC_RX_STAT(rx_multicast_bytes_ok),
109 ENIC_RX_STAT(rx_broadcast_bytes_ok),
110 ENIC_RX_STAT(rx_drop),
111 ENIC_RX_STAT(rx_no_bufs),
112 ENIC_RX_STAT(rx_errors),
113 ENIC_RX_STAT(rx_rss),
114 ENIC_RX_STAT(rx_crc_errors),
115 ENIC_RX_STAT(rx_frames_64),
116 ENIC_RX_STAT(rx_frames_127),
117 ENIC_RX_STAT(rx_frames_255),
118 ENIC_RX_STAT(rx_frames_511),
119 ENIC_RX_STAT(rx_frames_1023),
120 ENIC_RX_STAT(rx_frames_1518),
121 ENIC_RX_STAT(rx_frames_to_max),
122 };
123
124 static const unsigned int enic_n_tx_stats = ARRAY_SIZE(enic_tx_stats);
125 static const unsigned int enic_n_rx_stats = ARRAY_SIZE(enic_rx_stats);
126
127 int enic_is_dynamic(struct enic *enic)
128 {
129 return enic->pdev->device == PCI_DEVICE_ID_CISCO_VIC_ENET_DYN;
130 }
131
132 int enic_sriov_enabled(struct enic *enic)
133 {
134 return (enic->priv_flags & ENIC_SRIOV_ENABLED) ? 1 : 0;
135 }
136
137 static int enic_is_sriov_vf(struct enic *enic)
138 {
139 return enic->pdev->device == PCI_DEVICE_ID_CISCO_VIC_ENET_VF;
140 }
141
142 int enic_is_valid_vf(struct enic *enic, int vf)
143 {
144 #ifdef CONFIG_PCI_IOV
145 return vf >= 0 && vf < enic->num_vfs;
146 #else
147 return 0;
148 #endif
149 }
150
151 static inline unsigned int enic_cq_rq(struct enic *enic, unsigned int rq)
152 {
153 return rq;
154 }
155
156 static inline unsigned int enic_cq_wq(struct enic *enic, unsigned int wq)
157 {
158 return enic->rq_count + wq;
159 }
160
161 static inline unsigned int enic_legacy_io_intr(void)
162 {
163 return 0;
164 }
165
166 static inline unsigned int enic_legacy_err_intr(void)
167 {
168 return 1;
169 }
170
171 static inline unsigned int enic_legacy_notify_intr(void)
172 {
173 return 2;
174 }
175
176 static inline unsigned int enic_msix_rq_intr(struct enic *enic, unsigned int rq)
177 {
178 return enic->cq[enic_cq_rq(enic, rq)].interrupt_offset;
179 }
180
181 static inline unsigned int enic_msix_wq_intr(struct enic *enic, unsigned int wq)
182 {
183 return enic->cq[enic_cq_wq(enic, wq)].interrupt_offset;
184 }
185
186 static inline unsigned int enic_msix_err_intr(struct enic *enic)
187 {
188 return enic->rq_count + enic->wq_count;
189 }
190
191 static inline unsigned int enic_msix_notify_intr(struct enic *enic)
192 {
193 return enic->rq_count + enic->wq_count + 1;
194 }
195
196 static int enic_get_settings(struct net_device *netdev,
197 struct ethtool_cmd *ecmd)
198 {
199 struct enic *enic = netdev_priv(netdev);
200
201 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
202 ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
203 ecmd->port = PORT_FIBRE;
204 ecmd->transceiver = XCVR_EXTERNAL;
205
206 if (netif_carrier_ok(netdev)) {
207 ethtool_cmd_speed_set(ecmd, vnic_dev_port_speed(enic->vdev));
208 ecmd->duplex = DUPLEX_FULL;
209 } else {
210 ethtool_cmd_speed_set(ecmd, -1);
211 ecmd->duplex = -1;
212 }
213
214 ecmd->autoneg = AUTONEG_DISABLE;
215
216 return 0;
217 }
218
219 static void enic_get_drvinfo(struct net_device *netdev,
220 struct ethtool_drvinfo *drvinfo)
221 {
222 struct enic *enic = netdev_priv(netdev);
223 struct vnic_devcmd_fw_info *fw_info;
224
225 enic_dev_fw_info(enic, &fw_info);
226
227 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
228 strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
229 strlcpy(drvinfo->fw_version, fw_info->fw_version,
230 sizeof(drvinfo->fw_version));
231 strlcpy(drvinfo->bus_info, pci_name(enic->pdev),
232 sizeof(drvinfo->bus_info));
233 }
234
235 static void enic_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
236 {
237 unsigned int i;
238
239 switch (stringset) {
240 case ETH_SS_STATS:
241 for (i = 0; i < enic_n_tx_stats; i++) {
242 memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
243 data += ETH_GSTRING_LEN;
244 }
245 for (i = 0; i < enic_n_rx_stats; i++) {
246 memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
247 data += ETH_GSTRING_LEN;
248 }
249 break;
250 }
251 }
252
253 static int enic_get_sset_count(struct net_device *netdev, int sset)
254 {
255 switch (sset) {
256 case ETH_SS_STATS:
257 return enic_n_tx_stats + enic_n_rx_stats;
258 default:
259 return -EOPNOTSUPP;
260 }
261 }
262
263 static void enic_get_ethtool_stats(struct net_device *netdev,
264 struct ethtool_stats *stats, u64 *data)
265 {
266 struct enic *enic = netdev_priv(netdev);
267 struct vnic_stats *vstats;
268 unsigned int i;
269
270 enic_dev_stats_dump(enic, &vstats);
271
272 for (i = 0; i < enic_n_tx_stats; i++)
273 *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].offset];
274 for (i = 0; i < enic_n_rx_stats; i++)
275 *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].offset];
276 }
277
278 static u32 enic_get_msglevel(struct net_device *netdev)
279 {
280 struct enic *enic = netdev_priv(netdev);
281 return enic->msg_enable;
282 }
283
284 static void enic_set_msglevel(struct net_device *netdev, u32 value)
285 {
286 struct enic *enic = netdev_priv(netdev);
287 enic->msg_enable = value;
288 }
289
290 static int enic_get_coalesce(struct net_device *netdev,
291 struct ethtool_coalesce *ecmd)
292 {
293 struct enic *enic = netdev_priv(netdev);
294
295 ecmd->tx_coalesce_usecs = enic->tx_coalesce_usecs;
296 ecmd->rx_coalesce_usecs = enic->rx_coalesce_usecs;
297
298 return 0;
299 }
300
301 static int enic_set_coalesce(struct net_device *netdev,
302 struct ethtool_coalesce *ecmd)
303 {
304 struct enic *enic = netdev_priv(netdev);
305 u32 tx_coalesce_usecs;
306 u32 rx_coalesce_usecs;
307 unsigned int i, intr;
308
309 tx_coalesce_usecs = min_t(u32, ecmd->tx_coalesce_usecs,
310 vnic_dev_get_intr_coal_timer_max(enic->vdev));
311 rx_coalesce_usecs = min_t(u32, ecmd->rx_coalesce_usecs,
312 vnic_dev_get_intr_coal_timer_max(enic->vdev));
313
314 switch (vnic_dev_get_intr_mode(enic->vdev)) {
315 case VNIC_DEV_INTR_MODE_INTX:
316 if (tx_coalesce_usecs != rx_coalesce_usecs)
317 return -EINVAL;
318
319 intr = enic_legacy_io_intr();
320 vnic_intr_coalescing_timer_set(&enic->intr[intr],
321 tx_coalesce_usecs);
322 break;
323 case VNIC_DEV_INTR_MODE_MSI:
324 if (tx_coalesce_usecs != rx_coalesce_usecs)
325 return -EINVAL;
326
327 vnic_intr_coalescing_timer_set(&enic->intr[0],
328 tx_coalesce_usecs);
329 break;
330 case VNIC_DEV_INTR_MODE_MSIX:
331 for (i = 0; i < enic->wq_count; i++) {
332 intr = enic_msix_wq_intr(enic, i);
333 vnic_intr_coalescing_timer_set(&enic->intr[intr],
334 tx_coalesce_usecs);
335 }
336
337 for (i = 0; i < enic->rq_count; i++) {
338 intr = enic_msix_rq_intr(enic, i);
339 vnic_intr_coalescing_timer_set(&enic->intr[intr],
340 rx_coalesce_usecs);
341 }
342
343 break;
344 default:
345 break;
346 }
347
348 enic->tx_coalesce_usecs = tx_coalesce_usecs;
349 enic->rx_coalesce_usecs = rx_coalesce_usecs;
350
351 return 0;
352 }
353
354 static const struct ethtool_ops enic_ethtool_ops = {
355 .get_settings = enic_get_settings,
356 .get_drvinfo = enic_get_drvinfo,
357 .get_msglevel = enic_get_msglevel,
358 .set_msglevel = enic_set_msglevel,
359 .get_link = ethtool_op_get_link,
360 .get_strings = enic_get_strings,
361 .get_sset_count = enic_get_sset_count,
362 .get_ethtool_stats = enic_get_ethtool_stats,
363 .get_coalesce = enic_get_coalesce,
364 .set_coalesce = enic_set_coalesce,
365 };
366
367 static void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
368 {
369 struct enic *enic = vnic_dev_priv(wq->vdev);
370
371 if (buf->sop)
372 pci_unmap_single(enic->pdev, buf->dma_addr,
373 buf->len, PCI_DMA_TODEVICE);
374 else
375 pci_unmap_page(enic->pdev, buf->dma_addr,
376 buf->len, PCI_DMA_TODEVICE);
377
378 if (buf->os_buf)
379 dev_kfree_skb_any(buf->os_buf);
380 }
381
382 static void enic_wq_free_buf(struct vnic_wq *wq,
383 struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque)
384 {
385 enic_free_wq_buf(wq, buf);
386 }
387
388 static int enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
389 u8 type, u16 q_number, u16 completed_index, void *opaque)
390 {
391 struct enic *enic = vnic_dev_priv(vdev);
392
393 spin_lock(&enic->wq_lock[q_number]);
394
395 vnic_wq_service(&enic->wq[q_number], cq_desc,
396 completed_index, enic_wq_free_buf,
397 opaque);
398
399 if (netif_queue_stopped(enic->netdev) &&
400 vnic_wq_desc_avail(&enic->wq[q_number]) >=
401 (MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS))
402 netif_wake_queue(enic->netdev);
403
404 spin_unlock(&enic->wq_lock[q_number]);
405
406 return 0;
407 }
408
409 static void enic_log_q_error(struct enic *enic)
410 {
411 unsigned int i;
412 u32 error_status;
413
414 for (i = 0; i < enic->wq_count; i++) {
415 error_status = vnic_wq_error_status(&enic->wq[i]);
416 if (error_status)
417 netdev_err(enic->netdev, "WQ[%d] error_status %d\n",
418 i, error_status);
419 }
420
421 for (i = 0; i < enic->rq_count; i++) {
422 error_status = vnic_rq_error_status(&enic->rq[i]);
423 if (error_status)
424 netdev_err(enic->netdev, "RQ[%d] error_status %d\n",
425 i, error_status);
426 }
427 }
428
429 static void enic_msglvl_check(struct enic *enic)
430 {
431 u32 msg_enable = vnic_dev_msg_lvl(enic->vdev);
432
433 if (msg_enable != enic->msg_enable) {
434 netdev_info(enic->netdev, "msg lvl changed from 0x%x to 0x%x\n",
435 enic->msg_enable, msg_enable);
436 enic->msg_enable = msg_enable;
437 }
438 }
439
440 static void enic_mtu_check(struct enic *enic)
441 {
442 u32 mtu = vnic_dev_mtu(enic->vdev);
443 struct net_device *netdev = enic->netdev;
444
445 if (mtu && mtu != enic->port_mtu) {
446 enic->port_mtu = mtu;
447 if (enic_is_dynamic(enic) || enic_is_sriov_vf(enic)) {
448 mtu = max_t(int, ENIC_MIN_MTU,
449 min_t(int, ENIC_MAX_MTU, mtu));
450 if (mtu != netdev->mtu)
451 schedule_work(&enic->change_mtu_work);
452 } else {
453 if (mtu < netdev->mtu)
454 netdev_warn(netdev,
455 "interface MTU (%d) set higher "
456 "than switch port MTU (%d)\n",
457 netdev->mtu, mtu);
458 }
459 }
460 }
461
462 static void enic_link_check(struct enic *enic)
463 {
464 int link_status = vnic_dev_link_status(enic->vdev);
465 int carrier_ok = netif_carrier_ok(enic->netdev);
466
467 if (link_status && !carrier_ok) {
468 netdev_info(enic->netdev, "Link UP\n");
469 netif_carrier_on(enic->netdev);
470 } else if (!link_status && carrier_ok) {
471 netdev_info(enic->netdev, "Link DOWN\n");
472 netif_carrier_off(enic->netdev);
473 }
474 }
475
476 static void enic_notify_check(struct enic *enic)
477 {
478 enic_msglvl_check(enic);
479 enic_mtu_check(enic);
480 enic_link_check(enic);
481 }
482
483 #define ENIC_TEST_INTR(pba, i) (pba & (1 << i))
484
485 static irqreturn_t enic_isr_legacy(int irq, void *data)
486 {
487 struct net_device *netdev = data;
488 struct enic *enic = netdev_priv(netdev);
489 unsigned int io_intr = enic_legacy_io_intr();
490 unsigned int err_intr = enic_legacy_err_intr();
491 unsigned int notify_intr = enic_legacy_notify_intr();
492 u32 pba;
493
494 vnic_intr_mask(&enic->intr[io_intr]);
495
496 pba = vnic_intr_legacy_pba(enic->legacy_pba);
497 if (!pba) {
498 vnic_intr_unmask(&enic->intr[io_intr]);
499 return IRQ_NONE; /* not our interrupt */
500 }
501
502 if (ENIC_TEST_INTR(pba, notify_intr)) {
503 vnic_intr_return_all_credits(&enic->intr[notify_intr]);
504 enic_notify_check(enic);
505 }
506
507 if (ENIC_TEST_INTR(pba, err_intr)) {
508 vnic_intr_return_all_credits(&enic->intr[err_intr]);
509 enic_log_q_error(enic);
510 /* schedule recovery from WQ/RQ error */
511 schedule_work(&enic->reset);
512 return IRQ_HANDLED;
513 }
514
515 if (ENIC_TEST_INTR(pba, io_intr)) {
516 if (napi_schedule_prep(&enic->napi[0]))
517 __napi_schedule(&enic->napi[0]);
518 } else {
519 vnic_intr_unmask(&enic->intr[io_intr]);
520 }
521
522 return IRQ_HANDLED;
523 }
524
525 static irqreturn_t enic_isr_msi(int irq, void *data)
526 {
527 struct enic *enic = data;
528
529 /* With MSI, there is no sharing of interrupts, so this is
530 * our interrupt and there is no need to ack it. The device
531 * is not providing per-vector masking, so the OS will not
532 * write to PCI config space to mask/unmask the interrupt.
533 * We're using mask_on_assertion for MSI, so the device
534 * automatically masks the interrupt when the interrupt is
535 * generated. Later, when exiting polling, the interrupt
536 * will be unmasked (see enic_poll).
537 *
538 * Also, the device uses the same PCIe Traffic Class (TC)
539 * for Memory Write data and MSI, so there are no ordering
540 * issues; the MSI will always arrive at the Root Complex
541 * _after_ corresponding Memory Writes (i.e. descriptor
542 * writes).
543 */
544
545 napi_schedule(&enic->napi[0]);
546
547 return IRQ_HANDLED;
548 }
549
550 static irqreturn_t enic_isr_msix_rq(int irq, void *data)
551 {
552 struct napi_struct *napi = data;
553
554 /* schedule NAPI polling for RQ cleanup */
555 napi_schedule(napi);
556
557 return IRQ_HANDLED;
558 }
559
560 static irqreturn_t enic_isr_msix_wq(int irq, void *data)
561 {
562 struct enic *enic = data;
563 unsigned int cq = enic_cq_wq(enic, 0);
564 unsigned int intr = enic_msix_wq_intr(enic, 0);
565 unsigned int wq_work_to_do = -1; /* no limit */
566 unsigned int wq_work_done;
567
568 wq_work_done = vnic_cq_service(&enic->cq[cq],
569 wq_work_to_do, enic_wq_service, NULL);
570
571 vnic_intr_return_credits(&enic->intr[intr],
572 wq_work_done,
573 1 /* unmask intr */,
574 1 /* reset intr timer */);
575
576 return IRQ_HANDLED;
577 }
578
579 static irqreturn_t enic_isr_msix_err(int irq, void *data)
580 {
581 struct enic *enic = data;
582 unsigned int intr = enic_msix_err_intr(enic);
583
584 vnic_intr_return_all_credits(&enic->intr[intr]);
585
586 enic_log_q_error(enic);
587
588 /* schedule recovery from WQ/RQ error */
589 schedule_work(&enic->reset);
590
591 return IRQ_HANDLED;
592 }
593
594 static irqreturn_t enic_isr_msix_notify(int irq, void *data)
595 {
596 struct enic *enic = data;
597 unsigned int intr = enic_msix_notify_intr(enic);
598
599 vnic_intr_return_all_credits(&enic->intr[intr]);
600 enic_notify_check(enic);
601
602 return IRQ_HANDLED;
603 }
604
605 static inline void enic_queue_wq_skb_cont(struct enic *enic,
606 struct vnic_wq *wq, struct sk_buff *skb,
607 unsigned int len_left, int loopback)
608 {
609 const skb_frag_t *frag;
610
611 /* Queue additional data fragments */
612 for (frag = skb_shinfo(skb)->frags; len_left; frag++) {
613 len_left -= skb_frag_size(frag);
614 enic_queue_wq_desc_cont(wq, skb,
615 skb_frag_dma_map(&enic->pdev->dev,
616 frag, 0, skb_frag_size(frag),
617 DMA_TO_DEVICE),
618 skb_frag_size(frag),
619 (len_left == 0), /* EOP? */
620 loopback);
621 }
622 }
623
624 static inline void enic_queue_wq_skb_vlan(struct enic *enic,
625 struct vnic_wq *wq, struct sk_buff *skb,
626 int vlan_tag_insert, unsigned int vlan_tag, int loopback)
627 {
628 unsigned int head_len = skb_headlen(skb);
629 unsigned int len_left = skb->len - head_len;
630 int eop = (len_left == 0);
631
632 /* Queue the main skb fragment. The fragments are no larger
633 * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less
634 * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor
635 * per fragment is queued.
636 */
637 enic_queue_wq_desc(wq, skb,
638 pci_map_single(enic->pdev, skb->data,
639 head_len, PCI_DMA_TODEVICE),
640 head_len,
641 vlan_tag_insert, vlan_tag,
642 eop, loopback);
643
644 if (!eop)
645 enic_queue_wq_skb_cont(enic, wq, skb, len_left, loopback);
646 }
647
648 static inline void enic_queue_wq_skb_csum_l4(struct enic *enic,
649 struct vnic_wq *wq, struct sk_buff *skb,
650 int vlan_tag_insert, unsigned int vlan_tag, int loopback)
651 {
652 unsigned int head_len = skb_headlen(skb);
653 unsigned int len_left = skb->len - head_len;
654 unsigned int hdr_len = skb_checksum_start_offset(skb);
655 unsigned int csum_offset = hdr_len + skb->csum_offset;
656 int eop = (len_left == 0);
657
658 /* Queue the main skb fragment. The fragments are no larger
659 * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less
660 * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor
661 * per fragment is queued.
662 */
663 enic_queue_wq_desc_csum_l4(wq, skb,
664 pci_map_single(enic->pdev, skb->data,
665 head_len, PCI_DMA_TODEVICE),
666 head_len,
667 csum_offset,
668 hdr_len,
669 vlan_tag_insert, vlan_tag,
670 eop, loopback);
671
672 if (!eop)
673 enic_queue_wq_skb_cont(enic, wq, skb, len_left, loopback);
674 }
675
676 static inline void enic_queue_wq_skb_tso(struct enic *enic,
677 struct vnic_wq *wq, struct sk_buff *skb, unsigned int mss,
678 int vlan_tag_insert, unsigned int vlan_tag, int loopback)
679 {
680 unsigned int frag_len_left = skb_headlen(skb);
681 unsigned int len_left = skb->len - frag_len_left;
682 unsigned int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
683 int eop = (len_left == 0);
684 unsigned int len;
685 dma_addr_t dma_addr;
686 unsigned int offset = 0;
687 skb_frag_t *frag;
688
689 /* Preload TCP csum field with IP pseudo hdr calculated
690 * with IP length set to zero. HW will later add in length
691 * to each TCP segment resulting from the TSO.
692 */
693
694 if (skb->protocol == cpu_to_be16(ETH_P_IP)) {
695 ip_hdr(skb)->check = 0;
696 tcp_hdr(skb)->check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
697 ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
698 } else if (skb->protocol == cpu_to_be16(ETH_P_IPV6)) {
699 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
700 &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
701 }
702
703 /* Queue WQ_ENET_MAX_DESC_LEN length descriptors
704 * for the main skb fragment
705 */
706 while (frag_len_left) {
707 len = min(frag_len_left, (unsigned int)WQ_ENET_MAX_DESC_LEN);
708 dma_addr = pci_map_single(enic->pdev, skb->data + offset,
709 len, PCI_DMA_TODEVICE);
710 enic_queue_wq_desc_tso(wq, skb,
711 dma_addr,
712 len,
713 mss, hdr_len,
714 vlan_tag_insert, vlan_tag,
715 eop && (len == frag_len_left), loopback);
716 frag_len_left -= len;
717 offset += len;
718 }
719
720 if (eop)
721 return;
722
723 /* Queue WQ_ENET_MAX_DESC_LEN length descriptors
724 * for additional data fragments
725 */
726 for (frag = skb_shinfo(skb)->frags; len_left; frag++) {
727 len_left -= skb_frag_size(frag);
728 frag_len_left = skb_frag_size(frag);
729 offset = 0;
730
731 while (frag_len_left) {
732 len = min(frag_len_left,
733 (unsigned int)WQ_ENET_MAX_DESC_LEN);
734 dma_addr = skb_frag_dma_map(&enic->pdev->dev, frag,
735 offset, len,
736 DMA_TO_DEVICE);
737 enic_queue_wq_desc_cont(wq, skb,
738 dma_addr,
739 len,
740 (len_left == 0) &&
741 (len == frag_len_left), /* EOP? */
742 loopback);
743 frag_len_left -= len;
744 offset += len;
745 }
746 }
747 }
748
749 static inline void enic_queue_wq_skb(struct enic *enic,
750 struct vnic_wq *wq, struct sk_buff *skb)
751 {
752 unsigned int mss = skb_shinfo(skb)->gso_size;
753 unsigned int vlan_tag = 0;
754 int vlan_tag_insert = 0;
755 int loopback = 0;
756
757 if (vlan_tx_tag_present(skb)) {
758 /* VLAN tag from trunking driver */
759 vlan_tag_insert = 1;
760 vlan_tag = vlan_tx_tag_get(skb);
761 } else if (enic->loop_enable) {
762 vlan_tag = enic->loop_tag;
763 loopback = 1;
764 }
765
766 if (mss)
767 enic_queue_wq_skb_tso(enic, wq, skb, mss,
768 vlan_tag_insert, vlan_tag, loopback);
769 else if (skb->ip_summed == CHECKSUM_PARTIAL)
770 enic_queue_wq_skb_csum_l4(enic, wq, skb,
771 vlan_tag_insert, vlan_tag, loopback);
772 else
773 enic_queue_wq_skb_vlan(enic, wq, skb,
774 vlan_tag_insert, vlan_tag, loopback);
775 }
776
777 /* netif_tx_lock held, process context with BHs disabled, or BH */
778 static netdev_tx_t enic_hard_start_xmit(struct sk_buff *skb,
779 struct net_device *netdev)
780 {
781 struct enic *enic = netdev_priv(netdev);
782 struct vnic_wq *wq = &enic->wq[0];
783 unsigned long flags;
784
785 if (skb->len <= 0) {
786 dev_kfree_skb(skb);
787 return NETDEV_TX_OK;
788 }
789
790 /* Non-TSO sends must fit within ENIC_NON_TSO_MAX_DESC descs,
791 * which is very likely. In the off chance it's going to take
792 * more than * ENIC_NON_TSO_MAX_DESC, linearize the skb.
793 */
794
795 if (skb_shinfo(skb)->gso_size == 0 &&
796 skb_shinfo(skb)->nr_frags + 1 > ENIC_NON_TSO_MAX_DESC &&
797 skb_linearize(skb)) {
798 dev_kfree_skb(skb);
799 return NETDEV_TX_OK;
800 }
801
802 spin_lock_irqsave(&enic->wq_lock[0], flags);
803
804 if (vnic_wq_desc_avail(wq) <
805 skb_shinfo(skb)->nr_frags + ENIC_DESC_MAX_SPLITS) {
806 netif_stop_queue(netdev);
807 /* This is a hard error, log it */
808 netdev_err(netdev, "BUG! Tx ring full when queue awake!\n");
809 spin_unlock_irqrestore(&enic->wq_lock[0], flags);
810 return NETDEV_TX_BUSY;
811 }
812
813 enic_queue_wq_skb(enic, wq, skb);
814
815 if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS)
816 netif_stop_queue(netdev);
817
818 spin_unlock_irqrestore(&enic->wq_lock[0], flags);
819
820 return NETDEV_TX_OK;
821 }
822
823 /* dev_base_lock rwlock held, nominally process context */
824 static struct rtnl_link_stats64 *enic_get_stats(struct net_device *netdev,
825 struct rtnl_link_stats64 *net_stats)
826 {
827 struct enic *enic = netdev_priv(netdev);
828 struct vnic_stats *stats;
829
830 enic_dev_stats_dump(enic, &stats);
831
832 net_stats->tx_packets = stats->tx.tx_frames_ok;
833 net_stats->tx_bytes = stats->tx.tx_bytes_ok;
834 net_stats->tx_errors = stats->tx.tx_errors;
835 net_stats->tx_dropped = stats->tx.tx_drops;
836
837 net_stats->rx_packets = stats->rx.rx_frames_ok;
838 net_stats->rx_bytes = stats->rx.rx_bytes_ok;
839 net_stats->rx_errors = stats->rx.rx_errors;
840 net_stats->multicast = stats->rx.rx_multicast_frames_ok;
841 net_stats->rx_over_errors = enic->rq_truncated_pkts;
842 net_stats->rx_crc_errors = enic->rq_bad_fcs;
843 net_stats->rx_dropped = stats->rx.rx_no_bufs + stats->rx.rx_drop;
844
845 return net_stats;
846 }
847
848 void enic_reset_addr_lists(struct enic *enic)
849 {
850 enic->mc_count = 0;
851 enic->uc_count = 0;
852 enic->flags = 0;
853 }
854
855 static int enic_set_mac_addr(struct net_device *netdev, char *addr)
856 {
857 struct enic *enic = netdev_priv(netdev);
858
859 if (enic_is_dynamic(enic) || enic_is_sriov_vf(enic)) {
860 if (!is_valid_ether_addr(addr) && !is_zero_ether_addr(addr))
861 return -EADDRNOTAVAIL;
862 } else {
863 if (!is_valid_ether_addr(addr))
864 return -EADDRNOTAVAIL;
865 }
866
867 memcpy(netdev->dev_addr, addr, netdev->addr_len);
868 netdev->addr_assign_type &= ~NET_ADDR_RANDOM;
869
870 return 0;
871 }
872
873 static int enic_set_mac_address_dynamic(struct net_device *netdev, void *p)
874 {
875 struct enic *enic = netdev_priv(netdev);
876 struct sockaddr *saddr = p;
877 char *addr = saddr->sa_data;
878 int err;
879
880 if (netif_running(enic->netdev)) {
881 err = enic_dev_del_station_addr(enic);
882 if (err)
883 return err;
884 }
885
886 err = enic_set_mac_addr(netdev, addr);
887 if (err)
888 return err;
889
890 if (netif_running(enic->netdev)) {
891 err = enic_dev_add_station_addr(enic);
892 if (err)
893 return err;
894 }
895
896 return err;
897 }
898
899 static int enic_set_mac_address(struct net_device *netdev, void *p)
900 {
901 struct sockaddr *saddr = p;
902 char *addr = saddr->sa_data;
903 struct enic *enic = netdev_priv(netdev);
904 int err;
905
906 err = enic_dev_del_station_addr(enic);
907 if (err)
908 return err;
909
910 err = enic_set_mac_addr(netdev, addr);
911 if (err)
912 return err;
913
914 return enic_dev_add_station_addr(enic);
915 }
916
917 static void enic_update_multicast_addr_list(struct enic *enic)
918 {
919 struct net_device *netdev = enic->netdev;
920 struct netdev_hw_addr *ha;
921 unsigned int mc_count = netdev_mc_count(netdev);
922 u8 mc_addr[ENIC_MULTICAST_PERFECT_FILTERS][ETH_ALEN];
923 unsigned int i, j;
924
925 if (mc_count > ENIC_MULTICAST_PERFECT_FILTERS) {
926 netdev_warn(netdev, "Registering only %d out of %d "
927 "multicast addresses\n",
928 ENIC_MULTICAST_PERFECT_FILTERS, mc_count);
929 mc_count = ENIC_MULTICAST_PERFECT_FILTERS;
930 }
931
932 /* Is there an easier way? Trying to minimize to
933 * calls to add/del multicast addrs. We keep the
934 * addrs from the last call in enic->mc_addr and
935 * look for changes to add/del.
936 */
937
938 i = 0;
939 netdev_for_each_mc_addr(ha, netdev) {
940 if (i == mc_count)
941 break;
942 memcpy(mc_addr[i++], ha->addr, ETH_ALEN);
943 }
944
945 for (i = 0; i < enic->mc_count; i++) {
946 for (j = 0; j < mc_count; j++)
947 if (compare_ether_addr(enic->mc_addr[i],
948 mc_addr[j]) == 0)
949 break;
950 if (j == mc_count)
951 enic_dev_del_addr(enic, enic->mc_addr[i]);
952 }
953
954 for (i = 0; i < mc_count; i++) {
955 for (j = 0; j < enic->mc_count; j++)
956 if (compare_ether_addr(mc_addr[i],
957 enic->mc_addr[j]) == 0)
958 break;
959 if (j == enic->mc_count)
960 enic_dev_add_addr(enic, mc_addr[i]);
961 }
962
963 /* Save the list to compare against next time
964 */
965
966 for (i = 0; i < mc_count; i++)
967 memcpy(enic->mc_addr[i], mc_addr[i], ETH_ALEN);
968
969 enic->mc_count = mc_count;
970 }
971
972 static void enic_update_unicast_addr_list(struct enic *enic)
973 {
974 struct net_device *netdev = enic->netdev;
975 struct netdev_hw_addr *ha;
976 unsigned int uc_count = netdev_uc_count(netdev);
977 u8 uc_addr[ENIC_UNICAST_PERFECT_FILTERS][ETH_ALEN];
978 unsigned int i, j;
979
980 if (uc_count > ENIC_UNICAST_PERFECT_FILTERS) {
981 netdev_warn(netdev, "Registering only %d out of %d "
982 "unicast addresses\n",
983 ENIC_UNICAST_PERFECT_FILTERS, uc_count);
984 uc_count = ENIC_UNICAST_PERFECT_FILTERS;
985 }
986
987 /* Is there an easier way? Trying to minimize to
988 * calls to add/del unicast addrs. We keep the
989 * addrs from the last call in enic->uc_addr and
990 * look for changes to add/del.
991 */
992
993 i = 0;
994 netdev_for_each_uc_addr(ha, netdev) {
995 if (i == uc_count)
996 break;
997 memcpy(uc_addr[i++], ha->addr, ETH_ALEN);
998 }
999
1000 for (i = 0; i < enic->uc_count; i++) {
1001 for (j = 0; j < uc_count; j++)
1002 if (compare_ether_addr(enic->uc_addr[i],
1003 uc_addr[j]) == 0)
1004 break;
1005 if (j == uc_count)
1006 enic_dev_del_addr(enic, enic->uc_addr[i]);
1007 }
1008
1009 for (i = 0; i < uc_count; i++) {
1010 for (j = 0; j < enic->uc_count; j++)
1011 if (compare_ether_addr(uc_addr[i],
1012 enic->uc_addr[j]) == 0)
1013 break;
1014 if (j == enic->uc_count)
1015 enic_dev_add_addr(enic, uc_addr[i]);
1016 }
1017
1018 /* Save the list to compare against next time
1019 */
1020
1021 for (i = 0; i < uc_count; i++)
1022 memcpy(enic->uc_addr[i], uc_addr[i], ETH_ALEN);
1023
1024 enic->uc_count = uc_count;
1025 }
1026
1027 /* netif_tx_lock held, BHs disabled */
1028 static void enic_set_rx_mode(struct net_device *netdev)
1029 {
1030 struct enic *enic = netdev_priv(netdev);
1031 int directed = 1;
1032 int multicast = (netdev->flags & IFF_MULTICAST) ? 1 : 0;
1033 int broadcast = (netdev->flags & IFF_BROADCAST) ? 1 : 0;
1034 int promisc = (netdev->flags & IFF_PROMISC) ||
1035 netdev_uc_count(netdev) > ENIC_UNICAST_PERFECT_FILTERS;
1036 int allmulti = (netdev->flags & IFF_ALLMULTI) ||
1037 netdev_mc_count(netdev) > ENIC_MULTICAST_PERFECT_FILTERS;
1038 unsigned int flags = netdev->flags |
1039 (allmulti ? IFF_ALLMULTI : 0) |
1040 (promisc ? IFF_PROMISC : 0);
1041
1042 if (enic->flags != flags) {
1043 enic->flags = flags;
1044 enic_dev_packet_filter(enic, directed,
1045 multicast, broadcast, promisc, allmulti);
1046 }
1047
1048 if (!promisc) {
1049 enic_update_unicast_addr_list(enic);
1050 if (!allmulti)
1051 enic_update_multicast_addr_list(enic);
1052 }
1053 }
1054
1055 /* netif_tx_lock held, BHs disabled */
1056 static void enic_tx_timeout(struct net_device *netdev)
1057 {
1058 struct enic *enic = netdev_priv(netdev);
1059 schedule_work(&enic->reset);
1060 }
1061
1062 static int enic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
1063 {
1064 struct enic *enic = netdev_priv(netdev);
1065 struct enic_port_profile *pp;
1066 int err;
1067
1068 ENIC_PP_BY_INDEX(enic, vf, pp, &err);
1069 if (err)
1070 return err;
1071
1072 if (is_valid_ether_addr(mac) || is_zero_ether_addr(mac)) {
1073 if (vf == PORT_SELF_VF) {
1074 memcpy(pp->vf_mac, mac, ETH_ALEN);
1075 return 0;
1076 } else {
1077 /*
1078 * For sriov vf's set the mac in hw
1079 */
1080 ENIC_DEVCMD_PROXY_BY_INDEX(vf, err, enic,
1081 vnic_dev_set_mac_addr, mac);
1082 return enic_dev_status_to_errno(err);
1083 }
1084 } else
1085 return -EINVAL;
1086 }
1087
1088 static int enic_set_vf_port(struct net_device *netdev, int vf,
1089 struct nlattr *port[])
1090 {
1091 struct enic *enic = netdev_priv(netdev);
1092 struct enic_port_profile prev_pp;
1093 struct enic_port_profile *pp;
1094 int err = 0, restore_pp = 1;
1095
1096 ENIC_PP_BY_INDEX(enic, vf, pp, &err);
1097 if (err)
1098 return err;
1099
1100 if (!port[IFLA_PORT_REQUEST])
1101 return -EOPNOTSUPP;
1102
1103 memcpy(&prev_pp, pp, sizeof(*enic->pp));
1104 memset(pp, 0, sizeof(*enic->pp));
1105
1106 pp->set |= ENIC_SET_REQUEST;
1107 pp->request = nla_get_u8(port[IFLA_PORT_REQUEST]);
1108
1109 if (port[IFLA_PORT_PROFILE]) {
1110 pp->set |= ENIC_SET_NAME;
1111 memcpy(pp->name, nla_data(port[IFLA_PORT_PROFILE]),
1112 PORT_PROFILE_MAX);
1113 }
1114
1115 if (port[IFLA_PORT_INSTANCE_UUID]) {
1116 pp->set |= ENIC_SET_INSTANCE;
1117 memcpy(pp->instance_uuid,
1118 nla_data(port[IFLA_PORT_INSTANCE_UUID]), PORT_UUID_MAX);
1119 }
1120
1121 if (port[IFLA_PORT_HOST_UUID]) {
1122 pp->set |= ENIC_SET_HOST;
1123 memcpy(pp->host_uuid,
1124 nla_data(port[IFLA_PORT_HOST_UUID]), PORT_UUID_MAX);
1125 }
1126
1127 if (vf == PORT_SELF_VF) {
1128 /* Special case handling: mac came from IFLA_VF_MAC */
1129 if (!is_zero_ether_addr(prev_pp.vf_mac))
1130 memcpy(pp->mac_addr, prev_pp.vf_mac, ETH_ALEN);
1131
1132 if (is_zero_ether_addr(netdev->dev_addr))
1133 eth_hw_addr_random(netdev);
1134 } else {
1135 /* SR-IOV VF: get mac from adapter */
1136 ENIC_DEVCMD_PROXY_BY_INDEX(vf, err, enic,
1137 vnic_dev_get_mac_addr, pp->mac_addr);
1138 if (err) {
1139 netdev_err(netdev, "Error getting mac for vf %d\n", vf);
1140 memcpy(pp, &prev_pp, sizeof(*pp));
1141 return enic_dev_status_to_errno(err);
1142 }
1143 }
1144
1145 err = enic_process_set_pp_request(enic, vf, &prev_pp, &restore_pp);
1146 if (err) {
1147 if (restore_pp) {
1148 /* Things are still the way they were: Implicit
1149 * DISASSOCIATE failed
1150 */
1151 memcpy(pp, &prev_pp, sizeof(*pp));
1152 } else {
1153 memset(pp, 0, sizeof(*pp));
1154 if (vf == PORT_SELF_VF)
1155 memset(netdev->dev_addr, 0, ETH_ALEN);
1156 }
1157 } else {
1158 /* Set flag to indicate that the port assoc/disassoc
1159 * request has been sent out to fw
1160 */
1161 pp->set |= ENIC_PORT_REQUEST_APPLIED;
1162
1163 /* If DISASSOCIATE, clean up all assigned/saved macaddresses */
1164 if (pp->request == PORT_REQUEST_DISASSOCIATE) {
1165 memset(pp->mac_addr, 0, ETH_ALEN);
1166 if (vf == PORT_SELF_VF)
1167 memset(netdev->dev_addr, 0, ETH_ALEN);
1168 }
1169 }
1170
1171 if (vf == PORT_SELF_VF)
1172 memset(pp->vf_mac, 0, ETH_ALEN);
1173
1174 return err;
1175 }
1176
1177 static int enic_get_vf_port(struct net_device *netdev, int vf,
1178 struct sk_buff *skb)
1179 {
1180 struct enic *enic = netdev_priv(netdev);
1181 u16 response = PORT_PROFILE_RESPONSE_SUCCESS;
1182 struct enic_port_profile *pp;
1183 int err;
1184
1185 ENIC_PP_BY_INDEX(enic, vf, pp, &err);
1186 if (err)
1187 return err;
1188
1189 if (!(pp->set & ENIC_PORT_REQUEST_APPLIED))
1190 return -ENODATA;
1191
1192 err = enic_process_get_pp_request(enic, vf, pp->request, &response);
1193 if (err)
1194 return err;
1195
1196 if (nla_put_u16(skb, IFLA_PORT_REQUEST, pp->request) ||
1197 nla_put_u16(skb, IFLA_PORT_RESPONSE, response) ||
1198 ((pp->set & ENIC_SET_NAME) &&
1199 nla_put(skb, IFLA_PORT_PROFILE, PORT_PROFILE_MAX, pp->name)) ||
1200 ((pp->set & ENIC_SET_INSTANCE) &&
1201 nla_put(skb, IFLA_PORT_INSTANCE_UUID, PORT_UUID_MAX,
1202 pp->instance_uuid)) ||
1203 ((pp->set & ENIC_SET_HOST) &&
1204 nla_put(skb, IFLA_PORT_HOST_UUID, PORT_UUID_MAX, pp->host_uuid)))
1205 goto nla_put_failure;
1206 return 0;
1207
1208 nla_put_failure:
1209 return -EMSGSIZE;
1210 }
1211
1212 static void enic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf)
1213 {
1214 struct enic *enic = vnic_dev_priv(rq->vdev);
1215
1216 if (!buf->os_buf)
1217 return;
1218
1219 pci_unmap_single(enic->pdev, buf->dma_addr,
1220 buf->len, PCI_DMA_FROMDEVICE);
1221 dev_kfree_skb_any(buf->os_buf);
1222 }
1223
1224 static int enic_rq_alloc_buf(struct vnic_rq *rq)
1225 {
1226 struct enic *enic = vnic_dev_priv(rq->vdev);
1227 struct net_device *netdev = enic->netdev;
1228 struct sk_buff *skb;
1229 unsigned int len = netdev->mtu + VLAN_ETH_HLEN;
1230 unsigned int os_buf_index = 0;
1231 dma_addr_t dma_addr;
1232
1233 skb = netdev_alloc_skb_ip_align(netdev, len);
1234 if (!skb)
1235 return -ENOMEM;
1236
1237 dma_addr = pci_map_single(enic->pdev, skb->data,
1238 len, PCI_DMA_FROMDEVICE);
1239
1240 enic_queue_rq_desc(rq, skb, os_buf_index,
1241 dma_addr, len);
1242
1243 return 0;
1244 }
1245
1246 static void enic_rq_indicate_buf(struct vnic_rq *rq,
1247 struct cq_desc *cq_desc, struct vnic_rq_buf *buf,
1248 int skipped, void *opaque)
1249 {
1250 struct enic *enic = vnic_dev_priv(rq->vdev);
1251 struct net_device *netdev = enic->netdev;
1252 struct sk_buff *skb;
1253
1254 u8 type, color, eop, sop, ingress_port, vlan_stripped;
1255 u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof;
1256 u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
1257 u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc;
1258 u8 packet_error;
1259 u16 q_number, completed_index, bytes_written, vlan_tci, checksum;
1260 u32 rss_hash;
1261
1262 if (skipped)
1263 return;
1264
1265 skb = buf->os_buf;
1266 prefetch(skb->data - NET_IP_ALIGN);
1267 pci_unmap_single(enic->pdev, buf->dma_addr,
1268 buf->len, PCI_DMA_FROMDEVICE);
1269
1270 cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc,
1271 &type, &color, &q_number, &completed_index,
1272 &ingress_port, &fcoe, &eop, &sop, &rss_type,
1273 &csum_not_calc, &rss_hash, &bytes_written,
1274 &packet_error, &vlan_stripped, &vlan_tci, &checksum,
1275 &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error,
1276 &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp,
1277 &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment,
1278 &fcs_ok);
1279
1280 if (packet_error) {
1281
1282 if (!fcs_ok) {
1283 if (bytes_written > 0)
1284 enic->rq_bad_fcs++;
1285 else if (bytes_written == 0)
1286 enic->rq_truncated_pkts++;
1287 }
1288
1289 dev_kfree_skb_any(skb);
1290
1291 return;
1292 }
1293
1294 if (eop && bytes_written > 0) {
1295
1296 /* Good receive
1297 */
1298
1299 skb_put(skb, bytes_written);
1300 skb->protocol = eth_type_trans(skb, netdev);
1301
1302 if ((netdev->features & NETIF_F_RXCSUM) && !csum_not_calc) {
1303 skb->csum = htons(checksum);
1304 skb->ip_summed = CHECKSUM_COMPLETE;
1305 }
1306
1307 skb->dev = netdev;
1308
1309 if (vlan_stripped)
1310 __vlan_hwaccel_put_tag(skb, vlan_tci);
1311
1312 if (netdev->features & NETIF_F_GRO)
1313 napi_gro_receive(&enic->napi[q_number], skb);
1314 else
1315 netif_receive_skb(skb);
1316 } else {
1317
1318 /* Buffer overflow
1319 */
1320
1321 dev_kfree_skb_any(skb);
1322 }
1323 }
1324
1325 static int enic_rq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
1326 u8 type, u16 q_number, u16 completed_index, void *opaque)
1327 {
1328 struct enic *enic = vnic_dev_priv(vdev);
1329
1330 vnic_rq_service(&enic->rq[q_number], cq_desc,
1331 completed_index, VNIC_RQ_RETURN_DESC,
1332 enic_rq_indicate_buf, opaque);
1333
1334 return 0;
1335 }
1336
1337 static int enic_poll(struct napi_struct *napi, int budget)
1338 {
1339 struct net_device *netdev = napi->dev;
1340 struct enic *enic = netdev_priv(netdev);
1341 unsigned int cq_rq = enic_cq_rq(enic, 0);
1342 unsigned int cq_wq = enic_cq_wq(enic, 0);
1343 unsigned int intr = enic_legacy_io_intr();
1344 unsigned int rq_work_to_do = budget;
1345 unsigned int wq_work_to_do = -1; /* no limit */
1346 unsigned int work_done, rq_work_done, wq_work_done;
1347 int err;
1348
1349 /* Service RQ (first) and WQ
1350 */
1351
1352 rq_work_done = vnic_cq_service(&enic->cq[cq_rq],
1353 rq_work_to_do, enic_rq_service, NULL);
1354
1355 wq_work_done = vnic_cq_service(&enic->cq[cq_wq],
1356 wq_work_to_do, enic_wq_service, NULL);
1357
1358 /* Accumulate intr event credits for this polling
1359 * cycle. An intr event is the completion of a
1360 * a WQ or RQ packet.
1361 */
1362
1363 work_done = rq_work_done + wq_work_done;
1364
1365 if (work_done > 0)
1366 vnic_intr_return_credits(&enic->intr[intr],
1367 work_done,
1368 0 /* don't unmask intr */,
1369 0 /* don't reset intr timer */);
1370
1371 err = vnic_rq_fill(&enic->rq[0], enic_rq_alloc_buf);
1372
1373 /* Buffer allocation failed. Stay in polling
1374 * mode so we can try to fill the ring again.
1375 */
1376
1377 if (err)
1378 rq_work_done = rq_work_to_do;
1379
1380 if (rq_work_done < rq_work_to_do) {
1381
1382 /* Some work done, but not enough to stay in polling,
1383 * exit polling
1384 */
1385
1386 napi_complete(napi);
1387 vnic_intr_unmask(&enic->intr[intr]);
1388 }
1389
1390 return rq_work_done;
1391 }
1392
1393 static int enic_poll_msix(struct napi_struct *napi, int budget)
1394 {
1395 struct net_device *netdev = napi->dev;
1396 struct enic *enic = netdev_priv(netdev);
1397 unsigned int rq = (napi - &enic->napi[0]);
1398 unsigned int cq = enic_cq_rq(enic, rq);
1399 unsigned int intr = enic_msix_rq_intr(enic, rq);
1400 unsigned int work_to_do = budget;
1401 unsigned int work_done;
1402 int err;
1403
1404 /* Service RQ
1405 */
1406
1407 work_done = vnic_cq_service(&enic->cq[cq],
1408 work_to_do, enic_rq_service, NULL);
1409
1410 /* Return intr event credits for this polling
1411 * cycle. An intr event is the completion of a
1412 * RQ packet.
1413 */
1414
1415 if (work_done > 0)
1416 vnic_intr_return_credits(&enic->intr[intr],
1417 work_done,
1418 0 /* don't unmask intr */,
1419 0 /* don't reset intr timer */);
1420
1421 err = vnic_rq_fill(&enic->rq[rq], enic_rq_alloc_buf);
1422
1423 /* Buffer allocation failed. Stay in polling mode
1424 * so we can try to fill the ring again.
1425 */
1426
1427 if (err)
1428 work_done = work_to_do;
1429
1430 if (work_done < work_to_do) {
1431
1432 /* Some work done, but not enough to stay in polling,
1433 * exit polling
1434 */
1435
1436 napi_complete(napi);
1437 vnic_intr_unmask(&enic->intr[intr]);
1438 }
1439
1440 return work_done;
1441 }
1442
1443 static void enic_notify_timer(unsigned long data)
1444 {
1445 struct enic *enic = (struct enic *)data;
1446
1447 enic_notify_check(enic);
1448
1449 mod_timer(&enic->notify_timer,
1450 round_jiffies(jiffies + ENIC_NOTIFY_TIMER_PERIOD));
1451 }
1452
1453 static void enic_free_intr(struct enic *enic)
1454 {
1455 struct net_device *netdev = enic->netdev;
1456 unsigned int i;
1457
1458 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1459 case VNIC_DEV_INTR_MODE_INTX:
1460 free_irq(enic->pdev->irq, netdev);
1461 break;
1462 case VNIC_DEV_INTR_MODE_MSI:
1463 free_irq(enic->pdev->irq, enic);
1464 break;
1465 case VNIC_DEV_INTR_MODE_MSIX:
1466 for (i = 0; i < ARRAY_SIZE(enic->msix); i++)
1467 if (enic->msix[i].requested)
1468 free_irq(enic->msix_entry[i].vector,
1469 enic->msix[i].devid);
1470 break;
1471 default:
1472 break;
1473 }
1474 }
1475
1476 static int enic_request_intr(struct enic *enic)
1477 {
1478 struct net_device *netdev = enic->netdev;
1479 unsigned int i, intr;
1480 int err = 0;
1481
1482 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1483
1484 case VNIC_DEV_INTR_MODE_INTX:
1485
1486 err = request_irq(enic->pdev->irq, enic_isr_legacy,
1487 IRQF_SHARED, netdev->name, netdev);
1488 break;
1489
1490 case VNIC_DEV_INTR_MODE_MSI:
1491
1492 err = request_irq(enic->pdev->irq, enic_isr_msi,
1493 0, netdev->name, enic);
1494 break;
1495
1496 case VNIC_DEV_INTR_MODE_MSIX:
1497
1498 for (i = 0; i < enic->rq_count; i++) {
1499 intr = enic_msix_rq_intr(enic, i);
1500 sprintf(enic->msix[intr].devname,
1501 "%.11s-rx-%d", netdev->name, i);
1502 enic->msix[intr].isr = enic_isr_msix_rq;
1503 enic->msix[intr].devid = &enic->napi[i];
1504 }
1505
1506 for (i = 0; i < enic->wq_count; i++) {
1507 intr = enic_msix_wq_intr(enic, i);
1508 sprintf(enic->msix[intr].devname,
1509 "%.11s-tx-%d", netdev->name, i);
1510 enic->msix[intr].isr = enic_isr_msix_wq;
1511 enic->msix[intr].devid = enic;
1512 }
1513
1514 intr = enic_msix_err_intr(enic);
1515 sprintf(enic->msix[intr].devname,
1516 "%.11s-err", netdev->name);
1517 enic->msix[intr].isr = enic_isr_msix_err;
1518 enic->msix[intr].devid = enic;
1519
1520 intr = enic_msix_notify_intr(enic);
1521 sprintf(enic->msix[intr].devname,
1522 "%.11s-notify", netdev->name);
1523 enic->msix[intr].isr = enic_isr_msix_notify;
1524 enic->msix[intr].devid = enic;
1525
1526 for (i = 0; i < ARRAY_SIZE(enic->msix); i++)
1527 enic->msix[i].requested = 0;
1528
1529 for (i = 0; i < enic->intr_count; i++) {
1530 err = request_irq(enic->msix_entry[i].vector,
1531 enic->msix[i].isr, 0,
1532 enic->msix[i].devname,
1533 enic->msix[i].devid);
1534 if (err) {
1535 enic_free_intr(enic);
1536 break;
1537 }
1538 enic->msix[i].requested = 1;
1539 }
1540
1541 break;
1542
1543 default:
1544 break;
1545 }
1546
1547 return err;
1548 }
1549
1550 static void enic_synchronize_irqs(struct enic *enic)
1551 {
1552 unsigned int i;
1553
1554 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1555 case VNIC_DEV_INTR_MODE_INTX:
1556 case VNIC_DEV_INTR_MODE_MSI:
1557 synchronize_irq(enic->pdev->irq);
1558 break;
1559 case VNIC_DEV_INTR_MODE_MSIX:
1560 for (i = 0; i < enic->intr_count; i++)
1561 synchronize_irq(enic->msix_entry[i].vector);
1562 break;
1563 default:
1564 break;
1565 }
1566 }
1567
1568 static int enic_dev_notify_set(struct enic *enic)
1569 {
1570 int err;
1571
1572 spin_lock(&enic->devcmd_lock);
1573 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1574 case VNIC_DEV_INTR_MODE_INTX:
1575 err = vnic_dev_notify_set(enic->vdev,
1576 enic_legacy_notify_intr());
1577 break;
1578 case VNIC_DEV_INTR_MODE_MSIX:
1579 err = vnic_dev_notify_set(enic->vdev,
1580 enic_msix_notify_intr(enic));
1581 break;
1582 default:
1583 err = vnic_dev_notify_set(enic->vdev, -1 /* no intr */);
1584 break;
1585 }
1586 spin_unlock(&enic->devcmd_lock);
1587
1588 return err;
1589 }
1590
1591 static void enic_notify_timer_start(struct enic *enic)
1592 {
1593 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1594 case VNIC_DEV_INTR_MODE_MSI:
1595 mod_timer(&enic->notify_timer, jiffies);
1596 break;
1597 default:
1598 /* Using intr for notification for INTx/MSI-X */
1599 break;
1600 }
1601 }
1602
1603 /* rtnl lock is held, process context */
1604 static int enic_open(struct net_device *netdev)
1605 {
1606 struct enic *enic = netdev_priv(netdev);
1607 unsigned int i;
1608 int err;
1609
1610 err = enic_request_intr(enic);
1611 if (err) {
1612 netdev_err(netdev, "Unable to request irq.\n");
1613 return err;
1614 }
1615
1616 err = enic_dev_notify_set(enic);
1617 if (err) {
1618 netdev_err(netdev,
1619 "Failed to alloc notify buffer, aborting.\n");
1620 goto err_out_free_intr;
1621 }
1622
1623 for (i = 0; i < enic->rq_count; i++) {
1624 vnic_rq_fill(&enic->rq[i], enic_rq_alloc_buf);
1625 /* Need at least one buffer on ring to get going */
1626 if (vnic_rq_desc_used(&enic->rq[i]) == 0) {
1627 netdev_err(netdev, "Unable to alloc receive buffers\n");
1628 err = -ENOMEM;
1629 goto err_out_notify_unset;
1630 }
1631 }
1632
1633 for (i = 0; i < enic->wq_count; i++)
1634 vnic_wq_enable(&enic->wq[i]);
1635 for (i = 0; i < enic->rq_count; i++)
1636 vnic_rq_enable(&enic->rq[i]);
1637
1638 if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic))
1639 enic_dev_add_station_addr(enic);
1640
1641 enic_set_rx_mode(netdev);
1642
1643 netif_wake_queue(netdev);
1644
1645 for (i = 0; i < enic->rq_count; i++)
1646 napi_enable(&enic->napi[i]);
1647
1648 enic_dev_enable(enic);
1649
1650 for (i = 0; i < enic->intr_count; i++)
1651 vnic_intr_unmask(&enic->intr[i]);
1652
1653 enic_notify_timer_start(enic);
1654
1655 return 0;
1656
1657 err_out_notify_unset:
1658 enic_dev_notify_unset(enic);
1659 err_out_free_intr:
1660 enic_free_intr(enic);
1661
1662 return err;
1663 }
1664
1665 /* rtnl lock is held, process context */
1666 static int enic_stop(struct net_device *netdev)
1667 {
1668 struct enic *enic = netdev_priv(netdev);
1669 unsigned int i;
1670 int err;
1671
1672 for (i = 0; i < enic->intr_count; i++) {
1673 vnic_intr_mask(&enic->intr[i]);
1674 (void)vnic_intr_masked(&enic->intr[i]); /* flush write */
1675 }
1676
1677 enic_synchronize_irqs(enic);
1678
1679 del_timer_sync(&enic->notify_timer);
1680
1681 enic_dev_disable(enic);
1682
1683 for (i = 0; i < enic->rq_count; i++)
1684 napi_disable(&enic->napi[i]);
1685
1686 netif_carrier_off(netdev);
1687 netif_tx_disable(netdev);
1688
1689 if (!enic_is_dynamic(enic) && !enic_is_sriov_vf(enic))
1690 enic_dev_del_station_addr(enic);
1691
1692 for (i = 0; i < enic->wq_count; i++) {
1693 err = vnic_wq_disable(&enic->wq[i]);
1694 if (err)
1695 return err;
1696 }
1697 for (i = 0; i < enic->rq_count; i++) {
1698 err = vnic_rq_disable(&enic->rq[i]);
1699 if (err)
1700 return err;
1701 }
1702
1703 enic_dev_notify_unset(enic);
1704 enic_free_intr(enic);
1705
1706 for (i = 0; i < enic->wq_count; i++)
1707 vnic_wq_clean(&enic->wq[i], enic_free_wq_buf);
1708 for (i = 0; i < enic->rq_count; i++)
1709 vnic_rq_clean(&enic->rq[i], enic_free_rq_buf);
1710 for (i = 0; i < enic->cq_count; i++)
1711 vnic_cq_clean(&enic->cq[i]);
1712 for (i = 0; i < enic->intr_count; i++)
1713 vnic_intr_clean(&enic->intr[i]);
1714
1715 return 0;
1716 }
1717
1718 static int enic_change_mtu(struct net_device *netdev, int new_mtu)
1719 {
1720 struct enic *enic = netdev_priv(netdev);
1721 int running = netif_running(netdev);
1722
1723 if (new_mtu < ENIC_MIN_MTU || new_mtu > ENIC_MAX_MTU)
1724 return -EINVAL;
1725
1726 if (enic_is_dynamic(enic) || enic_is_sriov_vf(enic))
1727 return -EOPNOTSUPP;
1728
1729 if (running)
1730 enic_stop(netdev);
1731
1732 netdev->mtu = new_mtu;
1733
1734 if (netdev->mtu > enic->port_mtu)
1735 netdev_warn(netdev,
1736 "interface MTU (%d) set higher than port MTU (%d)\n",
1737 netdev->mtu, enic->port_mtu);
1738
1739 if (running)
1740 enic_open(netdev);
1741
1742 return 0;
1743 }
1744
1745 static void enic_change_mtu_work(struct work_struct *work)
1746 {
1747 struct enic *enic = container_of(work, struct enic, change_mtu_work);
1748 struct net_device *netdev = enic->netdev;
1749 int new_mtu = vnic_dev_mtu(enic->vdev);
1750 int err;
1751 unsigned int i;
1752
1753 new_mtu = max_t(int, ENIC_MIN_MTU, min_t(int, ENIC_MAX_MTU, new_mtu));
1754
1755 rtnl_lock();
1756
1757 /* Stop RQ */
1758 del_timer_sync(&enic->notify_timer);
1759
1760 for (i = 0; i < enic->rq_count; i++)
1761 napi_disable(&enic->napi[i]);
1762
1763 vnic_intr_mask(&enic->intr[0]);
1764 enic_synchronize_irqs(enic);
1765 err = vnic_rq_disable(&enic->rq[0]);
1766 if (err) {
1767 netdev_err(netdev, "Unable to disable RQ.\n");
1768 return;
1769 }
1770 vnic_rq_clean(&enic->rq[0], enic_free_rq_buf);
1771 vnic_cq_clean(&enic->cq[0]);
1772 vnic_intr_clean(&enic->intr[0]);
1773
1774 /* Fill RQ with new_mtu-sized buffers */
1775 netdev->mtu = new_mtu;
1776 vnic_rq_fill(&enic->rq[0], enic_rq_alloc_buf);
1777 /* Need at least one buffer on ring to get going */
1778 if (vnic_rq_desc_used(&enic->rq[0]) == 0) {
1779 netdev_err(netdev, "Unable to alloc receive buffers.\n");
1780 return;
1781 }
1782
1783 /* Start RQ */
1784 vnic_rq_enable(&enic->rq[0]);
1785 napi_enable(&enic->napi[0]);
1786 vnic_intr_unmask(&enic->intr[0]);
1787 enic_notify_timer_start(enic);
1788
1789 rtnl_unlock();
1790
1791 netdev_info(netdev, "interface MTU set as %d\n", netdev->mtu);
1792 }
1793
1794 #ifdef CONFIG_NET_POLL_CONTROLLER
1795 static void enic_poll_controller(struct net_device *netdev)
1796 {
1797 struct enic *enic = netdev_priv(netdev);
1798 struct vnic_dev *vdev = enic->vdev;
1799 unsigned int i, intr;
1800
1801 switch (vnic_dev_get_intr_mode(vdev)) {
1802 case VNIC_DEV_INTR_MODE_MSIX:
1803 for (i = 0; i < enic->rq_count; i++) {
1804 intr = enic_msix_rq_intr(enic, i);
1805 enic_isr_msix_rq(enic->msix_entry[intr].vector,
1806 &enic->napi[i]);
1807 }
1808
1809 for (i = 0; i < enic->wq_count; i++) {
1810 intr = enic_msix_wq_intr(enic, i);
1811 enic_isr_msix_wq(enic->msix_entry[intr].vector, enic);
1812 }
1813
1814 break;
1815 case VNIC_DEV_INTR_MODE_MSI:
1816 enic_isr_msi(enic->pdev->irq, enic);
1817 break;
1818 case VNIC_DEV_INTR_MODE_INTX:
1819 enic_isr_legacy(enic->pdev->irq, netdev);
1820 break;
1821 default:
1822 break;
1823 }
1824 }
1825 #endif
1826
1827 static int enic_dev_wait(struct vnic_dev *vdev,
1828 int (*start)(struct vnic_dev *, int),
1829 int (*finished)(struct vnic_dev *, int *),
1830 int arg)
1831 {
1832 unsigned long time;
1833 int done;
1834 int err;
1835
1836 BUG_ON(in_interrupt());
1837
1838 err = start(vdev, arg);
1839 if (err)
1840 return err;
1841
1842 /* Wait for func to complete...2 seconds max
1843 */
1844
1845 time = jiffies + (HZ * 2);
1846 do {
1847
1848 err = finished(vdev, &done);
1849 if (err)
1850 return err;
1851
1852 if (done)
1853 return 0;
1854
1855 schedule_timeout_uninterruptible(HZ / 10);
1856
1857 } while (time_after(time, jiffies));
1858
1859 return -ETIMEDOUT;
1860 }
1861
1862 static int enic_dev_open(struct enic *enic)
1863 {
1864 int err;
1865
1866 err = enic_dev_wait(enic->vdev, vnic_dev_open,
1867 vnic_dev_open_done, 0);
1868 if (err)
1869 dev_err(enic_get_dev(enic), "vNIC device open failed, err %d\n",
1870 err);
1871
1872 return err;
1873 }
1874
1875 static int enic_dev_hang_reset(struct enic *enic)
1876 {
1877 int err;
1878
1879 err = enic_dev_wait(enic->vdev, vnic_dev_hang_reset,
1880 vnic_dev_hang_reset_done, 0);
1881 if (err)
1882 netdev_err(enic->netdev, "vNIC hang reset failed, err %d\n",
1883 err);
1884
1885 return err;
1886 }
1887
1888 static int enic_set_rsskey(struct enic *enic)
1889 {
1890 dma_addr_t rss_key_buf_pa;
1891 union vnic_rss_key *rss_key_buf_va = NULL;
1892 union vnic_rss_key rss_key = {
1893 .key[0].b = {85, 67, 83, 97, 119, 101, 115, 111, 109, 101},
1894 .key[1].b = {80, 65, 76, 79, 117, 110, 105, 113, 117, 101},
1895 .key[2].b = {76, 73, 78, 85, 88, 114, 111, 99, 107, 115},
1896 .key[3].b = {69, 78, 73, 67, 105, 115, 99, 111, 111, 108},
1897 };
1898 int err;
1899
1900 rss_key_buf_va = pci_alloc_consistent(enic->pdev,
1901 sizeof(union vnic_rss_key), &rss_key_buf_pa);
1902 if (!rss_key_buf_va)
1903 return -ENOMEM;
1904
1905 memcpy(rss_key_buf_va, &rss_key, sizeof(union vnic_rss_key));
1906
1907 spin_lock(&enic->devcmd_lock);
1908 err = enic_set_rss_key(enic,
1909 rss_key_buf_pa,
1910 sizeof(union vnic_rss_key));
1911 spin_unlock(&enic->devcmd_lock);
1912
1913 pci_free_consistent(enic->pdev, sizeof(union vnic_rss_key),
1914 rss_key_buf_va, rss_key_buf_pa);
1915
1916 return err;
1917 }
1918
1919 static int enic_set_rsscpu(struct enic *enic, u8 rss_hash_bits)
1920 {
1921 dma_addr_t rss_cpu_buf_pa;
1922 union vnic_rss_cpu *rss_cpu_buf_va = NULL;
1923 unsigned int i;
1924 int err;
1925
1926 rss_cpu_buf_va = pci_alloc_consistent(enic->pdev,
1927 sizeof(union vnic_rss_cpu), &rss_cpu_buf_pa);
1928 if (!rss_cpu_buf_va)
1929 return -ENOMEM;
1930
1931 for (i = 0; i < (1 << rss_hash_bits); i++)
1932 (*rss_cpu_buf_va).cpu[i/4].b[i%4] = i % enic->rq_count;
1933
1934 spin_lock(&enic->devcmd_lock);
1935 err = enic_set_rss_cpu(enic,
1936 rss_cpu_buf_pa,
1937 sizeof(union vnic_rss_cpu));
1938 spin_unlock(&enic->devcmd_lock);
1939
1940 pci_free_consistent(enic->pdev, sizeof(union vnic_rss_cpu),
1941 rss_cpu_buf_va, rss_cpu_buf_pa);
1942
1943 return err;
1944 }
1945
1946 static int enic_set_niccfg(struct enic *enic, u8 rss_default_cpu,
1947 u8 rss_hash_type, u8 rss_hash_bits, u8 rss_base_cpu, u8 rss_enable)
1948 {
1949 const u8 tso_ipid_split_en = 0;
1950 const u8 ig_vlan_strip_en = 1;
1951 int err;
1952
1953 /* Enable VLAN tag stripping.
1954 */
1955
1956 spin_lock(&enic->devcmd_lock);
1957 err = enic_set_nic_cfg(enic,
1958 rss_default_cpu, rss_hash_type,
1959 rss_hash_bits, rss_base_cpu,
1960 rss_enable, tso_ipid_split_en,
1961 ig_vlan_strip_en);
1962 spin_unlock(&enic->devcmd_lock);
1963
1964 return err;
1965 }
1966
1967 static int enic_set_rss_nic_cfg(struct enic *enic)
1968 {
1969 struct device *dev = enic_get_dev(enic);
1970 const u8 rss_default_cpu = 0;
1971 const u8 rss_hash_type = NIC_CFG_RSS_HASH_TYPE_IPV4 |
1972 NIC_CFG_RSS_HASH_TYPE_TCP_IPV4 |
1973 NIC_CFG_RSS_HASH_TYPE_IPV6 |
1974 NIC_CFG_RSS_HASH_TYPE_TCP_IPV6;
1975 const u8 rss_hash_bits = 7;
1976 const u8 rss_base_cpu = 0;
1977 u8 rss_enable = ENIC_SETTING(enic, RSS) && (enic->rq_count > 1);
1978
1979 if (rss_enable) {
1980 if (!enic_set_rsskey(enic)) {
1981 if (enic_set_rsscpu(enic, rss_hash_bits)) {
1982 rss_enable = 0;
1983 dev_warn(dev, "RSS disabled, "
1984 "Failed to set RSS cpu indirection table.");
1985 }
1986 } else {
1987 rss_enable = 0;
1988 dev_warn(dev, "RSS disabled, Failed to set RSS key.\n");
1989 }
1990 }
1991
1992 return enic_set_niccfg(enic, rss_default_cpu, rss_hash_type,
1993 rss_hash_bits, rss_base_cpu, rss_enable);
1994 }
1995
1996 static void enic_reset(struct work_struct *work)
1997 {
1998 struct enic *enic = container_of(work, struct enic, reset);
1999
2000 if (!netif_running(enic->netdev))
2001 return;
2002
2003 rtnl_lock();
2004
2005 enic_dev_hang_notify(enic);
2006 enic_stop(enic->netdev);
2007 enic_dev_hang_reset(enic);
2008 enic_reset_addr_lists(enic);
2009 enic_init_vnic_resources(enic);
2010 enic_set_rss_nic_cfg(enic);
2011 enic_dev_set_ig_vlan_rewrite_mode(enic);
2012 enic_open(enic->netdev);
2013
2014 rtnl_unlock();
2015 }
2016
2017 static int enic_set_intr_mode(struct enic *enic)
2018 {
2019 unsigned int n = min_t(unsigned int, enic->rq_count, ENIC_RQ_MAX);
2020 unsigned int m = min_t(unsigned int, enic->wq_count, ENIC_WQ_MAX);
2021 unsigned int i;
2022
2023 /* Set interrupt mode (INTx, MSI, MSI-X) depending
2024 * on system capabilities.
2025 *
2026 * Try MSI-X first
2027 *
2028 * We need n RQs, m WQs, n+m CQs, and n+m+2 INTRs
2029 * (the second to last INTR is used for WQ/RQ errors)
2030 * (the last INTR is used for notifications)
2031 */
2032
2033 BUG_ON(ARRAY_SIZE(enic->msix_entry) < n + m + 2);
2034 for (i = 0; i < n + m + 2; i++)
2035 enic->msix_entry[i].entry = i;
2036
2037 /* Use multiple RQs if RSS is enabled
2038 */
2039
2040 if (ENIC_SETTING(enic, RSS) &&
2041 enic->config.intr_mode < 1 &&
2042 enic->rq_count >= n &&
2043 enic->wq_count >= m &&
2044 enic->cq_count >= n + m &&
2045 enic->intr_count >= n + m + 2) {
2046
2047 if (!pci_enable_msix(enic->pdev, enic->msix_entry, n + m + 2)) {
2048
2049 enic->rq_count = n;
2050 enic->wq_count = m;
2051 enic->cq_count = n + m;
2052 enic->intr_count = n + m + 2;
2053
2054 vnic_dev_set_intr_mode(enic->vdev,
2055 VNIC_DEV_INTR_MODE_MSIX);
2056
2057 return 0;
2058 }
2059 }
2060
2061 if (enic->config.intr_mode < 1 &&
2062 enic->rq_count >= 1 &&
2063 enic->wq_count >= m &&
2064 enic->cq_count >= 1 + m &&
2065 enic->intr_count >= 1 + m + 2) {
2066 if (!pci_enable_msix(enic->pdev, enic->msix_entry, 1 + m + 2)) {
2067
2068 enic->rq_count = 1;
2069 enic->wq_count = m;
2070 enic->cq_count = 1 + m;
2071 enic->intr_count = 1 + m + 2;
2072
2073 vnic_dev_set_intr_mode(enic->vdev,
2074 VNIC_DEV_INTR_MODE_MSIX);
2075
2076 return 0;
2077 }
2078 }
2079
2080 /* Next try MSI
2081 *
2082 * We need 1 RQ, 1 WQ, 2 CQs, and 1 INTR
2083 */
2084
2085 if (enic->config.intr_mode < 2 &&
2086 enic->rq_count >= 1 &&
2087 enic->wq_count >= 1 &&
2088 enic->cq_count >= 2 &&
2089 enic->intr_count >= 1 &&
2090 !pci_enable_msi(enic->pdev)) {
2091
2092 enic->rq_count = 1;
2093 enic->wq_count = 1;
2094 enic->cq_count = 2;
2095 enic->intr_count = 1;
2096
2097 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSI);
2098
2099 return 0;
2100 }
2101
2102 /* Next try INTx
2103 *
2104 * We need 1 RQ, 1 WQ, 2 CQs, and 3 INTRs
2105 * (the first INTR is used for WQ/RQ)
2106 * (the second INTR is used for WQ/RQ errors)
2107 * (the last INTR is used for notifications)
2108 */
2109
2110 if (enic->config.intr_mode < 3 &&
2111 enic->rq_count >= 1 &&
2112 enic->wq_count >= 1 &&
2113 enic->cq_count >= 2 &&
2114 enic->intr_count >= 3) {
2115
2116 enic->rq_count = 1;
2117 enic->wq_count = 1;
2118 enic->cq_count = 2;
2119 enic->intr_count = 3;
2120
2121 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_INTX);
2122
2123 return 0;
2124 }
2125
2126 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
2127
2128 return -EINVAL;
2129 }
2130
2131 static void enic_clear_intr_mode(struct enic *enic)
2132 {
2133 switch (vnic_dev_get_intr_mode(enic->vdev)) {
2134 case VNIC_DEV_INTR_MODE_MSIX:
2135 pci_disable_msix(enic->pdev);
2136 break;
2137 case VNIC_DEV_INTR_MODE_MSI:
2138 pci_disable_msi(enic->pdev);
2139 break;
2140 default:
2141 break;
2142 }
2143
2144 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
2145 }
2146
2147 static const struct net_device_ops enic_netdev_dynamic_ops = {
2148 .ndo_open = enic_open,
2149 .ndo_stop = enic_stop,
2150 .ndo_start_xmit = enic_hard_start_xmit,
2151 .ndo_get_stats64 = enic_get_stats,
2152 .ndo_validate_addr = eth_validate_addr,
2153 .ndo_set_rx_mode = enic_set_rx_mode,
2154 .ndo_set_mac_address = enic_set_mac_address_dynamic,
2155 .ndo_change_mtu = enic_change_mtu,
2156 .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid,
2157 .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid,
2158 .ndo_tx_timeout = enic_tx_timeout,
2159 .ndo_set_vf_port = enic_set_vf_port,
2160 .ndo_get_vf_port = enic_get_vf_port,
2161 .ndo_set_vf_mac = enic_set_vf_mac,
2162 #ifdef CONFIG_NET_POLL_CONTROLLER
2163 .ndo_poll_controller = enic_poll_controller,
2164 #endif
2165 };
2166
2167 static const struct net_device_ops enic_netdev_ops = {
2168 .ndo_open = enic_open,
2169 .ndo_stop = enic_stop,
2170 .ndo_start_xmit = enic_hard_start_xmit,
2171 .ndo_get_stats64 = enic_get_stats,
2172 .ndo_validate_addr = eth_validate_addr,
2173 .ndo_set_mac_address = enic_set_mac_address,
2174 .ndo_set_rx_mode = enic_set_rx_mode,
2175 .ndo_change_mtu = enic_change_mtu,
2176 .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid,
2177 .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid,
2178 .ndo_tx_timeout = enic_tx_timeout,
2179 .ndo_set_vf_port = enic_set_vf_port,
2180 .ndo_get_vf_port = enic_get_vf_port,
2181 .ndo_set_vf_mac = enic_set_vf_mac,
2182 #ifdef CONFIG_NET_POLL_CONTROLLER
2183 .ndo_poll_controller = enic_poll_controller,
2184 #endif
2185 };
2186
2187 static void enic_dev_deinit(struct enic *enic)
2188 {
2189 unsigned int i;
2190
2191 for (i = 0; i < enic->rq_count; i++)
2192 netif_napi_del(&enic->napi[i]);
2193
2194 enic_free_vnic_resources(enic);
2195 enic_clear_intr_mode(enic);
2196 }
2197
2198 static int enic_dev_init(struct enic *enic)
2199 {
2200 struct device *dev = enic_get_dev(enic);
2201 struct net_device *netdev = enic->netdev;
2202 unsigned int i;
2203 int err;
2204
2205 /* Get interrupt coalesce timer info */
2206 err = enic_dev_intr_coal_timer_info(enic);
2207 if (err) {
2208 dev_warn(dev, "Using default conversion factor for "
2209 "interrupt coalesce timer\n");
2210 vnic_dev_intr_coal_timer_info_default(enic->vdev);
2211 }
2212
2213 /* Get vNIC configuration
2214 */
2215
2216 err = enic_get_vnic_config(enic);
2217 if (err) {
2218 dev_err(dev, "Get vNIC configuration failed, aborting\n");
2219 return err;
2220 }
2221
2222 /* Get available resource counts
2223 */
2224
2225 enic_get_res_counts(enic);
2226
2227 /* Set interrupt mode based on resource counts and system
2228 * capabilities
2229 */
2230
2231 err = enic_set_intr_mode(enic);
2232 if (err) {
2233 dev_err(dev, "Failed to set intr mode based on resource "
2234 "counts and system capabilities, aborting\n");
2235 return err;
2236 }
2237
2238 /* Allocate and configure vNIC resources
2239 */
2240
2241 err = enic_alloc_vnic_resources(enic);
2242 if (err) {
2243 dev_err(dev, "Failed to alloc vNIC resources, aborting\n");
2244 goto err_out_free_vnic_resources;
2245 }
2246
2247 enic_init_vnic_resources(enic);
2248
2249 err = enic_set_rss_nic_cfg(enic);
2250 if (err) {
2251 dev_err(dev, "Failed to config nic, aborting\n");
2252 goto err_out_free_vnic_resources;
2253 }
2254
2255 switch (vnic_dev_get_intr_mode(enic->vdev)) {
2256 default:
2257 netif_napi_add(netdev, &enic->napi[0], enic_poll, 64);
2258 break;
2259 case VNIC_DEV_INTR_MODE_MSIX:
2260 for (i = 0; i < enic->rq_count; i++)
2261 netif_napi_add(netdev, &enic->napi[i],
2262 enic_poll_msix, 64);
2263 break;
2264 }
2265
2266 return 0;
2267
2268 err_out_free_vnic_resources:
2269 enic_clear_intr_mode(enic);
2270 enic_free_vnic_resources(enic);
2271
2272 return err;
2273 }
2274
2275 static void enic_iounmap(struct enic *enic)
2276 {
2277 unsigned int i;
2278
2279 for (i = 0; i < ARRAY_SIZE(enic->bar); i++)
2280 if (enic->bar[i].vaddr)
2281 iounmap(enic->bar[i].vaddr);
2282 }
2283
2284 static int __devinit enic_probe(struct pci_dev *pdev,
2285 const struct pci_device_id *ent)
2286 {
2287 struct device *dev = &pdev->dev;
2288 struct net_device *netdev;
2289 struct enic *enic;
2290 int using_dac = 0;
2291 unsigned int i;
2292 int err;
2293 #ifdef CONFIG_PCI_IOV
2294 int pos = 0;
2295 #endif
2296 int num_pps = 1;
2297
2298 /* Allocate net device structure and initialize. Private
2299 * instance data is initialized to zero.
2300 */
2301
2302 netdev = alloc_etherdev(sizeof(struct enic));
2303 if (!netdev)
2304 return -ENOMEM;
2305
2306 pci_set_drvdata(pdev, netdev);
2307
2308 SET_NETDEV_DEV(netdev, &pdev->dev);
2309
2310 enic = netdev_priv(netdev);
2311 enic->netdev = netdev;
2312 enic->pdev = pdev;
2313
2314 /* Setup PCI resources
2315 */
2316
2317 err = pci_enable_device_mem(pdev);
2318 if (err) {
2319 dev_err(dev, "Cannot enable PCI device, aborting\n");
2320 goto err_out_free_netdev;
2321 }
2322
2323 err = pci_request_regions(pdev, DRV_NAME);
2324 if (err) {
2325 dev_err(dev, "Cannot request PCI regions, aborting\n");
2326 goto err_out_disable_device;
2327 }
2328
2329 pci_set_master(pdev);
2330
2331 /* Query PCI controller on system for DMA addressing
2332 * limitation for the device. Try 40-bit first, and
2333 * fail to 32-bit.
2334 */
2335
2336 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(40));
2337 if (err) {
2338 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2339 if (err) {
2340 dev_err(dev, "No usable DMA configuration, aborting\n");
2341 goto err_out_release_regions;
2342 }
2343 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
2344 if (err) {
2345 dev_err(dev, "Unable to obtain %u-bit DMA "
2346 "for consistent allocations, aborting\n", 32);
2347 goto err_out_release_regions;
2348 }
2349 } else {
2350 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(40));
2351 if (err) {
2352 dev_err(dev, "Unable to obtain %u-bit DMA "
2353 "for consistent allocations, aborting\n", 40);
2354 goto err_out_release_regions;
2355 }
2356 using_dac = 1;
2357 }
2358
2359 /* Map vNIC resources from BAR0-5
2360 */
2361
2362 for (i = 0; i < ARRAY_SIZE(enic->bar); i++) {
2363 if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM))
2364 continue;
2365 enic->bar[i].len = pci_resource_len(pdev, i);
2366 enic->bar[i].vaddr = pci_iomap(pdev, i, enic->bar[i].len);
2367 if (!enic->bar[i].vaddr) {
2368 dev_err(dev, "Cannot memory-map BAR %d, aborting\n", i);
2369 err = -ENODEV;
2370 goto err_out_iounmap;
2371 }
2372 enic->bar[i].bus_addr = pci_resource_start(pdev, i);
2373 }
2374
2375 /* Register vNIC device
2376 */
2377
2378 enic->vdev = vnic_dev_register(NULL, enic, pdev, enic->bar,
2379 ARRAY_SIZE(enic->bar));
2380 if (!enic->vdev) {
2381 dev_err(dev, "vNIC registration failed, aborting\n");
2382 err = -ENODEV;
2383 goto err_out_iounmap;
2384 }
2385
2386 #ifdef CONFIG_PCI_IOV
2387 /* Get number of subvnics */
2388 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
2389 if (pos) {
2390 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF,
2391 &enic->num_vfs);
2392 if (enic->num_vfs) {
2393 err = pci_enable_sriov(pdev, enic->num_vfs);
2394 if (err) {
2395 dev_err(dev, "SRIOV enable failed, aborting."
2396 " pci_enable_sriov() returned %d\n",
2397 err);
2398 goto err_out_vnic_unregister;
2399 }
2400 enic->priv_flags |= ENIC_SRIOV_ENABLED;
2401 num_pps = enic->num_vfs;
2402 }
2403 }
2404 #endif
2405
2406 /* Allocate structure for port profiles */
2407 enic->pp = kcalloc(num_pps, sizeof(*enic->pp), GFP_KERNEL);
2408 if (!enic->pp) {
2409 err = -ENOMEM;
2410 goto err_out_disable_sriov_pp;
2411 }
2412
2413 /* Issue device open to get device in known state
2414 */
2415
2416 err = enic_dev_open(enic);
2417 if (err) {
2418 dev_err(dev, "vNIC dev open failed, aborting\n");
2419 goto err_out_disable_sriov;
2420 }
2421
2422 /* Setup devcmd lock
2423 */
2424
2425 spin_lock_init(&enic->devcmd_lock);
2426
2427 /*
2428 * Set ingress vlan rewrite mode before vnic initialization
2429 */
2430
2431 err = enic_dev_set_ig_vlan_rewrite_mode(enic);
2432 if (err) {
2433 dev_err(dev,
2434 "Failed to set ingress vlan rewrite mode, aborting.\n");
2435 goto err_out_dev_close;
2436 }
2437
2438 /* Issue device init to initialize the vnic-to-switch link.
2439 * We'll start with carrier off and wait for link UP
2440 * notification later to turn on carrier. We don't need
2441 * to wait here for the vnic-to-switch link initialization
2442 * to complete; link UP notification is the indication that
2443 * the process is complete.
2444 */
2445
2446 netif_carrier_off(netdev);
2447
2448 /* Do not call dev_init for a dynamic vnic.
2449 * For a dynamic vnic, init_prov_info will be
2450 * called later by an upper layer.
2451 */
2452
2453 if (!enic_is_dynamic(enic)) {
2454 err = vnic_dev_init(enic->vdev, 0);
2455 if (err) {
2456 dev_err(dev, "vNIC dev init failed, aborting\n");
2457 goto err_out_dev_close;
2458 }
2459 }
2460
2461 err = enic_dev_init(enic);
2462 if (err) {
2463 dev_err(dev, "Device initialization failed, aborting\n");
2464 goto err_out_dev_close;
2465 }
2466
2467 /* Setup notification timer, HW reset task, and wq locks
2468 */
2469
2470 init_timer(&enic->notify_timer);
2471 enic->notify_timer.function = enic_notify_timer;
2472 enic->notify_timer.data = (unsigned long)enic;
2473
2474 INIT_WORK(&enic->reset, enic_reset);
2475 INIT_WORK(&enic->change_mtu_work, enic_change_mtu_work);
2476
2477 for (i = 0; i < enic->wq_count; i++)
2478 spin_lock_init(&enic->wq_lock[i]);
2479
2480 /* Register net device
2481 */
2482
2483 enic->port_mtu = enic->config.mtu;
2484 (void)enic_change_mtu(netdev, enic->port_mtu);
2485
2486 err = enic_set_mac_addr(netdev, enic->mac_addr);
2487 if (err) {
2488 dev_err(dev, "Invalid MAC address, aborting\n");
2489 goto err_out_dev_deinit;
2490 }
2491
2492 enic->tx_coalesce_usecs = enic->config.intr_timer_usec;
2493 enic->rx_coalesce_usecs = enic->tx_coalesce_usecs;
2494
2495 if (enic_is_dynamic(enic) || enic_is_sriov_vf(enic))
2496 netdev->netdev_ops = &enic_netdev_dynamic_ops;
2497 else
2498 netdev->netdev_ops = &enic_netdev_ops;
2499
2500 netdev->watchdog_timeo = 2 * HZ;
2501 netdev->ethtool_ops = &enic_ethtool_ops;
2502
2503 netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
2504 if (ENIC_SETTING(enic, LOOP)) {
2505 netdev->features &= ~NETIF_F_HW_VLAN_TX;
2506 enic->loop_enable = 1;
2507 enic->loop_tag = enic->config.loop_tag;
2508 dev_info(dev, "loopback tag=0x%04x\n", enic->loop_tag);
2509 }
2510 if (ENIC_SETTING(enic, TXCSUM))
2511 netdev->hw_features |= NETIF_F_SG | NETIF_F_HW_CSUM;
2512 if (ENIC_SETTING(enic, TSO))
2513 netdev->hw_features |= NETIF_F_TSO |
2514 NETIF_F_TSO6 | NETIF_F_TSO_ECN;
2515 if (ENIC_SETTING(enic, RXCSUM))
2516 netdev->hw_features |= NETIF_F_RXCSUM;
2517
2518 netdev->features |= netdev->hw_features;
2519
2520 if (using_dac)
2521 netdev->features |= NETIF_F_HIGHDMA;
2522
2523 netdev->priv_flags |= IFF_UNICAST_FLT;
2524
2525 err = register_netdev(netdev);
2526 if (err) {
2527 dev_err(dev, "Cannot register net device, aborting\n");
2528 goto err_out_dev_deinit;
2529 }
2530
2531 return 0;
2532
2533 err_out_dev_deinit:
2534 enic_dev_deinit(enic);
2535 err_out_dev_close:
2536 vnic_dev_close(enic->vdev);
2537 err_out_disable_sriov:
2538 kfree(enic->pp);
2539 err_out_disable_sriov_pp:
2540 #ifdef CONFIG_PCI_IOV
2541 if (enic_sriov_enabled(enic)) {
2542 pci_disable_sriov(pdev);
2543 enic->priv_flags &= ~ENIC_SRIOV_ENABLED;
2544 }
2545 err_out_vnic_unregister:
2546 #endif
2547 vnic_dev_unregister(enic->vdev);
2548 err_out_iounmap:
2549 enic_iounmap(enic);
2550 err_out_release_regions:
2551 pci_release_regions(pdev);
2552 err_out_disable_device:
2553 pci_disable_device(pdev);
2554 err_out_free_netdev:
2555 pci_set_drvdata(pdev, NULL);
2556 free_netdev(netdev);
2557
2558 return err;
2559 }
2560
2561 static void __devexit enic_remove(struct pci_dev *pdev)
2562 {
2563 struct net_device *netdev = pci_get_drvdata(pdev);
2564
2565 if (netdev) {
2566 struct enic *enic = netdev_priv(netdev);
2567
2568 cancel_work_sync(&enic->reset);
2569 cancel_work_sync(&enic->change_mtu_work);
2570 unregister_netdev(netdev);
2571 enic_dev_deinit(enic);
2572 vnic_dev_close(enic->vdev);
2573 #ifdef CONFIG_PCI_IOV
2574 if (enic_sriov_enabled(enic)) {
2575 pci_disable_sriov(pdev);
2576 enic->priv_flags &= ~ENIC_SRIOV_ENABLED;
2577 }
2578 #endif
2579 kfree(enic->pp);
2580 vnic_dev_unregister(enic->vdev);
2581 enic_iounmap(enic);
2582 pci_release_regions(pdev);
2583 pci_disable_device(pdev);
2584 pci_set_drvdata(pdev, NULL);
2585 free_netdev(netdev);
2586 }
2587 }
2588
2589 static struct pci_driver enic_driver = {
2590 .name = DRV_NAME,
2591 .id_table = enic_id_table,
2592 .probe = enic_probe,
2593 .remove = __devexit_p(enic_remove),
2594 };
2595
2596 static int __init enic_init_module(void)
2597 {
2598 pr_info("%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION);
2599
2600 return pci_register_driver(&enic_driver);
2601 }
2602
2603 static void __exit enic_cleanup_module(void)
2604 {
2605 pci_unregister_driver(&enic_driver);
2606 }
2607
2608 module_init(enic_init_module);
2609 module_exit(enic_cleanup_module);
This page took 0.138833 seconds and 5 git commands to generate.