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>
28 #include <linux/pci.h>
29 #include <linux/netdevice.h>
32 #include <linux/if_ether.h>
33 #include <linux/if_vlan.h>
34 #include <linux/ethtool.h>
37 #include <linux/ipv6.h>
38 #include <linux/tcp.h>
39 #include <linux/rtnetlink.h>
40 #include <linux/prefetch.h>
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)
58 #define PCI_DEVICE_ID_CISCO_VIC_ENET 0x0043
59 #define PCI_DEVICE_ID_CISCO_VIC_ENET_DYN 0x0044
60 #define PCI_DEVICE_ID_CISCO_VIC_ENET_VF 0x0071
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 }
86 static const struct enic_stat enic_tx_stats[] = {
100 static const struct enic_stat enic_rx_stats[] = {
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);
137 static int enic_is_sriov_vf(
struct enic *
enic)
144 #ifdef CONFIG_PCI_IOV
145 return vf >= 0 && vf < enic->num_vfs;
151 static inline unsigned int enic_cq_rq(
struct enic *
enic,
unsigned int rq)
156 static inline unsigned int enic_cq_wq(
struct enic *
enic,
unsigned int wq)
161 static inline unsigned int enic_legacy_io_intr(
void)
166 static inline unsigned int enic_legacy_err_intr(
void)
171 static inline unsigned int enic_legacy_notify_intr(
void)
176 static inline unsigned int enic_msix_rq_intr(
struct enic *
enic,
unsigned int rq)
178 return enic->
cq[enic_cq_rq(enic, rq)].interrupt_offset;
181 static inline unsigned int enic_msix_wq_intr(
struct enic *
enic,
unsigned int wq)
183 return enic->
cq[enic_cq_wq(enic, wq)].interrupt_offset;
186 static inline unsigned int enic_msix_err_intr(
struct enic *
enic)
191 static inline unsigned int enic_msix_notify_intr(
struct enic *
enic)
196 static int enic_get_settings(
struct net_device *netdev,
199 struct enic *
enic = netdev_priv(netdev);
206 if (netif_carrier_ok(netdev)) {
210 ethtool_cmd_speed_set(ecmd, -1);
219 static void enic_get_drvinfo(
struct net_device *netdev,
222 struct enic *enic = netdev_priv(netdev);
241 for (i = 0; i < enic_n_tx_stats; i++) {
245 for (i = 0; i < enic_n_rx_stats; i++) {
253 static int enic_get_sset_count(
struct net_device *netdev,
int sset)
257 return enic_n_tx_stats + enic_n_rx_stats;
263 static void enic_get_ethtool_stats(
struct net_device *netdev,
266 struct enic *enic = netdev_priv(netdev);
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];
280 struct enic *enic = netdev_priv(netdev);
286 struct enic *enic = netdev_priv(netdev);
290 static int enic_get_coalesce(
struct net_device *netdev,
293 struct enic *enic = netdev_priv(netdev);
301 static int enic_set_coalesce(
struct net_device *netdev,
304 struct enic *enic = netdev_priv(netdev);
307 unsigned int i,
intr;
316 if (tx_coalesce_usecs != rx_coalesce_usecs)
319 intr = enic_legacy_io_intr();
324 if (tx_coalesce_usecs != rx_coalesce_usecs)
331 for (i = 0; i < enic->
wq_count; i++) {
332 intr = enic_msix_wq_intr(enic, i);
337 for (i = 0; i < enic->
rq_count; i++) {
338 intr = enic_msix_rq_intr(enic, i);
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,
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,
382 static void enic_wq_free_buf(
struct vnic_wq *wq,
385 enic_free_wq_buf(wq, buf);
389 u8 type,
u16 q_number,
u16 completed_index,
void *opaque)
393 spin_lock(&enic->
wq_lock[q_number]);
396 completed_index, enic_wq_free_buf,
399 if (netif_queue_stopped(enic->
netdev) &&
402 netif_wake_queue(enic->
netdev);
404 spin_unlock(&enic->
wq_lock[q_number]);
409 static void enic_log_q_error(
struct enic *enic)
414 for (i = 0; i < enic->
wq_count; i++) {
417 netdev_err(enic->
netdev,
"WQ[%d] error_status %d\n",
421 for (i = 0; i < enic->
rq_count; i++) {
424 netdev_err(enic->
netdev,
"RQ[%d] error_status %d\n",
429 static void enic_msglvl_check(
struct enic *enic)
434 netdev_info(enic->
netdev,
"msg lvl changed from 0x%x to 0x%x\n",
440 static void enic_mtu_check(
struct enic *enic)
450 if (mtu != netdev->
mtu)
453 if (mtu < netdev->mtu)
455 "interface MTU (%d) set higher "
456 "than switch port MTU (%d)\n",
462 static void enic_link_check(
struct enic *enic)
465 int carrier_ok = netif_carrier_ok(enic->
netdev);
467 if (link_status && !carrier_ok) {
468 netdev_info(enic->
netdev,
"Link UP\n");
470 }
else if (!link_status && carrier_ok) {
471 netdev_info(enic->
netdev,
"Link DOWN\n");
476 static void enic_notify_check(
struct enic *enic)
478 enic_msglvl_check(enic);
479 enic_mtu_check(enic);
480 enic_link_check(enic);
483 #define ENIC_TEST_INTR(pba, i) (pba & (1 << i))
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();
504 enic_notify_check(enic);
509 enic_log_q_error(enic);
516 if (napi_schedule_prep(&enic->
napi[0]))
525 static irqreturn_t enic_isr_msi(
int irq,
void *data)
527 struct enic *enic =
data;
545 napi_schedule(&enic->
napi[0]);
550 static irqreturn_t enic_isr_msix_rq(
int irq,
void *data)
560 static irqreturn_t enic_isr_msix_wq(
int irq,
void *data)
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;
566 unsigned int wq_work_done;
569 wq_work_to_do, enic_wq_service,
NULL);
579 static irqreturn_t enic_isr_msix_err(
int irq,
void *data)
581 struct enic *enic =
data;
582 unsigned int intr = enic_msix_err_intr(enic);
586 enic_log_q_error(enic);
594 static irqreturn_t enic_isr_msix_notify(
int irq,
void *data)
596 struct enic *enic =
data;
597 unsigned int intr = enic_msix_notify_intr(enic);
600 enic_notify_check(enic);
605 static inline void enic_queue_wq_skb_cont(
struct enic *enic,
607 unsigned int len_left,
int loopback)
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),
624 static inline void enic_queue_wq_skb_vlan(
struct enic *enic,
626 int vlan_tag_insert,
unsigned int vlan_tag,
int loopback)
628 unsigned int head_len = skb_headlen(skb);
629 unsigned int len_left = skb->
len - head_len;
630 int eop = (len_left == 0);
637 enic_queue_wq_desc(wq, skb,
638 pci_map_single(enic->
pdev, skb->
data,
641 vlan_tag_insert, vlan_tag,
645 enic_queue_wq_skb_cont(enic, wq, skb, len_left, loopback);
648 static inline void enic_queue_wq_skb_csum_l4(
struct enic *enic,
650 int vlan_tag_insert,
unsigned int vlan_tag,
int loopback)
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);
663 enic_queue_wq_desc_csum_l4(wq, skb,
664 pci_map_single(enic->
pdev, skb->
data,
669 vlan_tag_insert, vlan_tag,
673 enic_queue_wq_skb_cont(enic, wq, skb, len_left, loopback);
676 static inline void enic_queue_wq_skb_tso(
struct enic *enic,
678 int vlan_tag_insert,
unsigned int vlan_tag,
int loopback)
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);
695 ip_hdr(skb)->check = 0;
706 while (frag_len_left) {
708 dma_addr = pci_map_single(enic->
pdev, skb->
data + offset,
710 enic_queue_wq_desc_tso(wq, skb,
714 vlan_tag_insert, vlan_tag,
715 eop && (len == frag_len_left), loopback);
716 frag_len_left -= len;
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);
731 while (frag_len_left) {
732 len =
min(frag_len_left,
734 dma_addr = skb_frag_dma_map(&enic->
pdev->dev, frag,
737 enic_queue_wq_desc_cont(wq, skb,
741 (len == frag_len_left),
743 frag_len_left -= len;
749 static inline void enic_queue_wq_skb(
struct enic *enic,
752 unsigned int mss = skb_shinfo(skb)->gso_size;
753 unsigned int vlan_tag = 0;
754 int vlan_tag_insert = 0;
767 enic_queue_wq_skb_tso(enic, wq, skb, mss,
768 vlan_tag_insert, vlan_tag, loopback);
770 enic_queue_wq_skb_csum_l4(enic, wq, skb,
771 vlan_tag_insert, vlan_tag, loopback);
773 enic_queue_wq_skb_vlan(enic, wq, skb,
774 vlan_tag_insert, vlan_tag, loopback);
781 struct enic *enic = netdev_priv(netdev);
795 if (skb_shinfo(skb)->gso_size == 0 &&
797 skb_linearize(skb)) {
806 netif_stop_queue(netdev);
808 netdev_err(netdev,
"BUG! Tx ring full when queue awake!\n");
809 spin_unlock_irqrestore(&enic->
wq_lock[0], flags);
813 enic_queue_wq_skb(enic, wq, skb);
816 netif_stop_queue(netdev);
818 spin_unlock_irqrestore(&enic->
wq_lock[0], flags);
827 struct enic *enic = netdev_priv(netdev);
840 net_stats->
multicast = stats->
rx.rx_multicast_frames_ok;
855 static int enic_set_mac_addr(
struct net_device *netdev,
char *
addr)
857 struct enic *enic = netdev_priv(netdev);
860 if (!is_valid_ether_addr(addr) && !is_zero_ether_addr(addr))
863 if (!is_valid_ether_addr(addr))
873 static int enic_set_mac_address_dynamic(
struct net_device *netdev,
void *
p)
875 struct enic *enic = netdev_priv(netdev);
880 if (netif_running(enic->
netdev)) {
886 err = enic_set_mac_addr(netdev, addr);
890 if (netif_running(enic->
netdev)) {
899 static int enic_set_mac_address(
struct net_device *netdev,
void *p)
903 struct enic *enic = netdev_priv(netdev);
910 err = enic_set_mac_addr(netdev, addr);
917 static void enic_update_multicast_addr_list(
struct enic *enic)
926 netdev_warn(netdev,
"Registering only %d out of %d "
927 "multicast addresses\n",
945 for (i = 0; i < enic->
mc_count; i++) {
946 for (j = 0; j < mc_count; j++)
947 if (ether_addr_equal(enic->
mc_addr[i], mc_addr[j]))
953 for (i = 0; i < mc_count; i++) {
954 for (j = 0; j < enic->
mc_count; j++)
955 if (ether_addr_equal(mc_addr[i], enic->
mc_addr[j]))
964 for (i = 0; i < mc_count; i++)
970 static void enic_update_unicast_addr_list(
struct enic *enic)
979 netdev_warn(netdev,
"Registering only %d out of %d "
980 "unicast addresses\n",
998 for (i = 0; i < enic->
uc_count; i++) {
999 for (j = 0; j < uc_count; j++)
1000 if (ether_addr_equal(enic->
uc_addr[i], uc_addr[j]))
1006 for (i = 0; i < uc_count; i++) {
1007 for (j = 0; j < enic->
uc_count; j++)
1008 if (ether_addr_equal(uc_addr[i], enic->
uc_addr[j]))
1017 for (i = 0; i < uc_count; i++)
1024 static void enic_set_rx_mode(
struct net_device *netdev)
1026 struct enic *enic = netdev_priv(netdev);
1034 unsigned int flags = netdev->
flags |
1038 if (enic->
flags != flags) {
1041 multicast, broadcast, promisc, allmulti);
1045 enic_update_unicast_addr_list(enic);
1047 enic_update_multicast_addr_list(enic);
1052 static void enic_tx_timeout(
struct net_device *netdev)
1054 struct enic *enic = netdev_priv(netdev);
1060 struct enic *enic = netdev_priv(netdev);
1068 if (is_valid_ether_addr(mac) || is_zero_ether_addr(mac)) {
1084 static int enic_set_vf_port(
struct net_device *netdev,
int vf,
1087 struct enic *enic = netdev_priv(netdev);
1090 int err = 0, restore_pp = 1;
1099 memcpy(&prev_pp, pp,
sizeof(*enic->
pp));
1103 pp->
request = nla_get_u8(port[IFLA_PORT_REQUEST]);
1107 memcpy(pp->
name, nla_data(port[IFLA_PORT_PROFILE]),
1125 if (!is_zero_ether_addr(prev_pp.vf_mac))
1128 if (is_zero_ether_addr(netdev->
dev_addr))
1129 eth_hw_addr_random(netdev);
1135 netdev_err(netdev,
"Error getting mac for vf %d\n", vf);
1136 memcpy(pp, &prev_pp,
sizeof(*pp));
1147 memcpy(pp, &prev_pp,
sizeof(*pp));
1149 memset(pp, 0,
sizeof(*pp));
1173 static int enic_get_vf_port(
struct net_device *netdev,
int vf,
1176 struct enic *enic = netdev_priv(netdev);
1192 if (nla_put_u16(skb, IFLA_PORT_REQUEST, pp->
request) ||
1201 goto nla_put_failure;
1220 static int enic_rq_alloc_buf(
struct vnic_rq *rq)
1226 unsigned int os_buf_index = 0;
1229 skb = netdev_alloc_skb_ip_align(netdev, len);
1233 dma_addr = pci_map_single(enic->
pdev, skb->
data,
1236 enic_queue_rq_desc(rq, skb, os_buf_index,
1242 static void enic_rq_indicate_buf(
struct vnic_rq *rq,
1244 int skipped,
void *opaque)
1250 u8 type,
color, eop, sop, ingress_port, vlan_stripped;
1251 u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error,
fcoe_eof;
1252 u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
1253 u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc;
1267 &type, &color, &q_number, &completed_index,
1268 &ingress_port, &fcoe, &eop, &sop, &rss_type,
1269 &csum_not_calc, &rss_hash, &bytes_written,
1270 &packet_error, &vlan_stripped, &vlan_tci, &checksum,
1271 &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error,
1272 &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp,
1273 &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment,
1279 if (bytes_written > 0)
1281 else if (bytes_written == 0)
1290 if (eop && bytes_written > 0) {
1304 __vlan_hwaccel_put_tag(skb, vlan_tci);
1319 static int enic_rq_service(
struct vnic_dev *vdev,
struct cq_desc *cq_desc,
1320 u8 type,
u16 q_number,
u16 completed_index,
void *opaque)
1326 enic_rq_indicate_buf, opaque);
1334 struct enic *enic = netdev_priv(netdev);
1335 unsigned int cq_rq = enic_cq_rq(enic, 0);
1336 unsigned int cq_wq = enic_cq_wq(enic, 0);
1337 unsigned int intr = enic_legacy_io_intr();
1338 unsigned int rq_work_to_do = budget;
1339 unsigned int wq_work_to_do = -1;
1340 unsigned int work_done, rq_work_done, wq_work_done;
1347 rq_work_to_do, enic_rq_service,
NULL);
1350 wq_work_to_do, enic_wq_service,
NULL);
1357 work_done = rq_work_done + wq_work_done;
1372 rq_work_done = rq_work_to_do;
1374 if (rq_work_done < rq_work_to_do) {
1384 return rq_work_done;
1387 static int enic_poll_msix(
struct napi_struct *napi,
int budget)
1390 struct enic *enic = netdev_priv(netdev);
1391 unsigned int rq = (napi - &enic->
napi[0]);
1392 unsigned int cq = enic_cq_rq(enic, rq);
1393 unsigned int intr = enic_msix_rq_intr(enic, rq);
1394 unsigned int work_to_do = budget;
1395 unsigned int work_done;
1402 work_to_do, enic_rq_service,
NULL);
1422 work_done = work_to_do;
1424 if (work_done < work_to_do) {
1437 static void enic_notify_timer(
unsigned long data)
1439 struct enic *enic = (
struct enic *)data;
1441 enic_notify_check(enic);
1447 static void enic_free_intr(
struct enic *enic)
1461 if (enic->
msix[i].requested)
1463 enic->
msix[i].devid);
1470 static int enic_request_intr(
struct enic *enic)
1473 unsigned int i,
intr;
1487 0, netdev->
name, enic);
1492 for (i = 0; i < enic->
rq_count; i++) {
1493 intr = enic_msix_rq_intr(enic, i);
1495 "%.11s-rx-%d", netdev->
name, i);
1496 enic->
msix[
intr].isr = enic_isr_msix_rq;
1500 for (i = 0; i < enic->
wq_count; i++) {
1501 intr = enic_msix_wq_intr(enic, i);
1503 "%.11s-tx-%d", netdev->
name, i);
1504 enic->
msix[
intr].isr = enic_isr_msix_wq;
1508 intr = enic_msix_err_intr(enic);
1510 "%.11s-err", netdev->
name);
1511 enic->
msix[
intr].isr = enic_isr_msix_err;
1514 intr = enic_msix_notify_intr(enic);
1516 "%.11s-notify", netdev->
name);
1517 enic->
msix[
intr].isr = enic_isr_msix_notify;
1521 enic->
msix[i].requested = 0;
1525 enic->
msix[i].isr, 0,
1526 enic->
msix[i].devname,
1527 enic->
msix[i].devid);
1529 enic_free_intr(enic);
1532 enic->
msix[
i].requested = 1;
1544 static void enic_synchronize_irqs(
struct enic *enic)
1562 static int enic_dev_notify_set(
struct enic *enic)
1570 enic_legacy_notify_intr());
1574 enic_msix_notify_intr(enic));
1585 static void enic_notify_timer_start(
struct enic *enic)
1598 static int enic_open(
struct net_device *netdev)
1600 struct enic *enic = netdev_priv(netdev);
1604 err = enic_request_intr(enic);
1606 netdev_err(netdev,
"Unable to request irq.\n");
1610 err = enic_dev_notify_set(enic);
1613 "Failed to alloc notify buffer, aborting.\n");
1614 goto err_out_free_intr;
1617 for (i = 0; i < enic->
rq_count; i++) {
1621 netdev_err(netdev,
"Unable to alloc receive buffers\n");
1623 goto err_out_notify_unset;
1627 for (i = 0; i < enic->
wq_count; i++)
1629 for (i = 0; i < enic->
rq_count; i++)
1635 enic_set_rx_mode(netdev);
1637 netif_wake_queue(netdev);
1639 for (i = 0; i < enic->
rq_count; i++)
1640 napi_enable(&enic->
napi[i]);
1647 enic_notify_timer_start(enic);
1651 err_out_notify_unset:
1654 enic_free_intr(enic);
1660 static int enic_stop(
struct net_device *netdev)
1662 struct enic *enic = netdev_priv(netdev);
1668 (
void)vnic_intr_masked(&enic->
intr[i]);
1671 enic_synchronize_irqs(enic);
1677 for (i = 0; i < enic->
rq_count; i++)
1678 napi_disable(&enic->
napi[i]);
1681 netif_tx_disable(netdev);
1686 for (i = 0; i < enic->
wq_count; i++) {
1691 for (i = 0; i < enic->
rq_count; i++) {
1698 enic_free_intr(enic);
1700 for (i = 0; i < enic->
wq_count; i++)
1702 for (i = 0; i < enic->
rq_count; i++)
1704 for (i = 0; i < enic->
cq_count; i++)
1712 static int enic_change_mtu(
struct net_device *netdev,
int new_mtu)
1714 struct enic *enic = netdev_priv(netdev);
1715 int running = netif_running(netdev);
1726 netdev->
mtu = new_mtu;
1730 "interface MTU (%d) set higher than port MTU (%d)\n",
1754 for (i = 0; i < enic->
rq_count; i++)
1755 napi_disable(&enic->
napi[i]);
1758 enic_synchronize_irqs(enic);
1761 netdev_err(netdev,
"Unable to disable RQ.\n");
1769 netdev->
mtu = new_mtu;
1773 netdev_err(netdev,
"Unable to alloc receive buffers.\n");
1779 napi_enable(&enic->
napi[0]);
1781 enic_notify_timer_start(enic);
1785 netdev_info(netdev,
"interface MTU set as %d\n", netdev->
mtu);
1788 #ifdef CONFIG_NET_POLL_CONTROLLER
1789 static void enic_poll_controller(
struct net_device *netdev)
1791 struct enic *enic = netdev_priv(netdev);
1793 unsigned int i,
intr;
1797 for (i = 0; i < enic->
rq_count; i++) {
1798 intr = enic_msix_rq_intr(enic, i);
1799 enic_isr_msix_rq(enic->
msix_entry[intr].vector,
1803 for (i = 0; i < enic->
wq_count; i++) {
1804 intr = enic_msix_wq_intr(enic, i);
1805 enic_isr_msix_wq(enic->
msix_entry[intr].vector, enic);
1810 enic_isr_msi(enic->
pdev->irq, enic);
1813 enic_isr_legacy(enic->
pdev->irq, netdev);
1821 static int enic_dev_wait(
struct vnic_dev *vdev,
1832 err =
start(vdev, arg);
1856 static int enic_dev_open(
struct enic *enic)
1863 dev_err(enic_get_dev(enic),
"vNIC device open failed, err %d\n",
1869 static int enic_dev_hang_reset(
struct enic *enic)
1876 netdev_err(enic->
netdev,
"vNIC hang reset failed, err %d\n",
1882 static int enic_set_rsskey(
struct enic *enic)
1887 .
key[0].b = {85, 67, 83, 97, 119, 101, 115, 111, 109, 101},
1888 .key[1].b = {80, 65, 76, 79, 117, 110, 105, 113, 117, 101},
1889 .key[2].b = {76, 73, 78, 85, 88, 114, 111, 99, 107, 115},
1890 .key[3].b = {69, 78, 73, 67, 105, 115, 99, 111, 111, 108},
1896 if (!rss_key_buf_va)
1908 rss_key_buf_va, rss_key_buf_pa);
1913 static int enic_set_rsscpu(
struct enic *enic,
u8 rss_hash_bits)
1922 if (!rss_cpu_buf_va)
1925 for (i = 0; i < (1 << rss_hash_bits); i++)
1926 (*rss_cpu_buf_va).cpu[i/4].b[i%4] = i % enic->
rq_count;
1935 rss_cpu_buf_va, rss_cpu_buf_pa);
1940 static int enic_set_niccfg(
struct enic *enic,
u8 rss_default_cpu,
1941 u8 rss_hash_type,
u8 rss_hash_bits,
u8 rss_base_cpu,
u8 rss_enable)
1943 const u8 tso_ipid_split_en = 0;
1944 const u8 ig_vlan_strip_en = 1;
1952 rss_default_cpu, rss_hash_type,
1953 rss_hash_bits, rss_base_cpu,
1954 rss_enable, tso_ipid_split_en,
1961 static int enic_set_rss_nic_cfg(
struct enic *enic)
1963 struct device *
dev = enic_get_dev(enic);
1964 const u8 rss_default_cpu = 0;
1969 const u8 rss_hash_bits = 7;
1970 const u8 rss_base_cpu = 0;
1974 if (!enic_set_rsskey(enic)) {
1975 if (enic_set_rsscpu(enic, rss_hash_bits)) {
1978 "Failed to set RSS cpu indirection table.");
1982 dev_warn(dev,
"RSS disabled, Failed to set RSS key.\n");
1986 return enic_set_niccfg(enic, rss_default_cpu, rss_hash_type,
1987 rss_hash_bits, rss_base_cpu, rss_enable);
1994 if (!netif_running(enic->
netdev))
2001 enic_dev_hang_reset(enic);
2004 enic_set_rss_nic_cfg(enic);
2011 static int enic_set_intr_mode(
struct enic *enic)
2028 for (i = 0; i < n + m + 2; i++)
2035 enic->
config.intr_mode < 1 &&
2055 if (enic->
config.intr_mode < 1 &&
2079 if (enic->
config.intr_mode < 2 &&
2084 !pci_enable_msi(enic->
pdev)) {
2104 if (enic->
config.intr_mode < 3 &&
2125 static void enic_clear_intr_mode(
struct enic *enic)
2142 .ndo_open = enic_open,
2143 .ndo_stop = enic_stop,
2144 .ndo_start_xmit = enic_hard_start_xmit,
2145 .ndo_get_stats64 = enic_get_stats,
2147 .ndo_set_rx_mode = enic_set_rx_mode,
2148 .ndo_set_mac_address = enic_set_mac_address_dynamic,
2149 .ndo_change_mtu = enic_change_mtu,
2152 .ndo_tx_timeout = enic_tx_timeout,
2153 .ndo_set_vf_port = enic_set_vf_port,
2154 .ndo_get_vf_port = enic_get_vf_port,
2155 .ndo_set_vf_mac = enic_set_vf_mac,
2156 #ifdef CONFIG_NET_POLL_CONTROLLER
2157 .ndo_poll_controller = enic_poll_controller,
2162 .ndo_open = enic_open,
2163 .ndo_stop = enic_stop,
2164 .ndo_start_xmit = enic_hard_start_xmit,
2165 .ndo_get_stats64 = enic_get_stats,
2167 .ndo_set_mac_address = enic_set_mac_address,
2168 .ndo_set_rx_mode = enic_set_rx_mode,
2169 .ndo_change_mtu = enic_change_mtu,
2172 .ndo_tx_timeout = enic_tx_timeout,
2173 .ndo_set_vf_port = enic_set_vf_port,
2174 .ndo_get_vf_port = enic_get_vf_port,
2175 .ndo_set_vf_mac = enic_set_vf_mac,
2176 #ifdef CONFIG_NET_POLL_CONTROLLER
2177 .ndo_poll_controller = enic_poll_controller,
2181 static void enic_dev_deinit(
struct enic *enic)
2185 for (i = 0; i < enic->
rq_count; i++)
2189 enic_clear_intr_mode(enic);
2192 static int enic_dev_init(
struct enic *enic)
2194 struct device *dev = enic_get_dev(enic);
2202 dev_warn(dev,
"Using default conversion factor for "
2203 "interrupt coalesce timer\n");
2212 dev_err(dev,
"Get vNIC configuration failed, aborting\n");
2225 err = enic_set_intr_mode(enic);
2227 dev_err(dev,
"Failed to set intr mode based on resource "
2228 "counts and system capabilities, aborting\n");
2237 dev_err(dev,
"Failed to alloc vNIC resources, aborting\n");
2238 goto err_out_free_vnic_resources;
2243 err = enic_set_rss_nic_cfg(enic);
2245 dev_err(dev,
"Failed to config nic, aborting\n");
2246 goto err_out_free_vnic_resources;
2254 for (i = 0; i < enic->
rq_count; i++)
2256 enic_poll_msix, 64);
2262 err_out_free_vnic_resources:
2263 enic_clear_intr_mode(enic);
2269 static void enic_iounmap(
struct enic *enic)
2274 if (enic->
bar[i].vaddr)
2287 #ifdef CONFIG_PCI_IOV
2296 netdev = alloc_etherdev(
sizeof(
struct enic));
2300 pci_set_drvdata(pdev, netdev);
2304 enic = netdev_priv(netdev);
2313 dev_err(dev,
"Cannot enable PCI device, aborting\n");
2314 goto err_out_free_netdev;
2319 dev_err(dev,
"Cannot request PCI regions, aborting\n");
2320 goto err_out_disable_device;
2334 dev_err(dev,
"No usable DMA configuration, aborting\n");
2335 goto err_out_release_regions;
2337 err = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32));
2339 dev_err(dev,
"Unable to obtain %u-bit DMA "
2340 "for consistent allocations, aborting\n", 32);
2341 goto err_out_release_regions;
2344 err = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(40));
2346 dev_err(dev,
"Unable to obtain %u-bit DMA "
2347 "for consistent allocations, aborting\n", 40);
2348 goto err_out_release_regions;
2360 enic->
bar[
i].vaddr = pci_iomap(pdev, i, enic->
bar[i].len);
2361 if (!enic->
bar[i].vaddr) {
2362 dev_err(dev,
"Cannot memory-map BAR %d, aborting\n", i);
2364 goto err_out_iounmap;
2375 dev_err(dev,
"vNIC registration failed, aborting\n");
2377 goto err_out_iounmap;
2380 #ifdef CONFIG_PCI_IOV
2386 if (enic->num_vfs) {
2389 dev_err(dev,
"SRIOV enable failed, aborting."
2390 " pci_enable_sriov() returned %d\n",
2392 goto err_out_vnic_unregister;
2395 num_pps = enic->num_vfs;
2404 goto err_out_disable_sriov_pp;
2410 err = enic_dev_open(enic);
2412 dev_err(dev,
"vNIC dev open failed, aborting\n");
2413 goto err_out_disable_sriov;
2428 "Failed to set ingress vlan rewrite mode, aborting.\n");
2429 goto err_out_dev_close;
2450 dev_err(dev,
"vNIC dev init failed, aborting\n");
2451 goto err_out_dev_close;
2455 err = enic_dev_init(enic);
2457 dev_err(dev,
"Device initialization failed, aborting\n");
2458 goto err_out_dev_close;
2471 for (i = 0; i < enic->
wq_count; i++)
2480 err = enic_set_mac_addr(netdev, enic->
mac_addr);
2482 dev_err(dev,
"Invalid MAC address, aborting\n");
2483 goto err_out_dev_deinit;
2490 netdev->
netdev_ops = &enic_netdev_dynamic_ops;
2521 dev_err(dev,
"Cannot register net device, aborting\n");
2522 goto err_out_dev_deinit;
2528 enic_dev_deinit(enic);
2531 err_out_disable_sriov:
2533 err_out_disable_sriov_pp:
2534 #ifdef CONFIG_PCI_IOV
2539 err_out_vnic_unregister:
2544 err_out_release_regions:
2546 err_out_disable_device:
2548 err_out_free_netdev:
2549 pci_set_drvdata(pdev,
NULL);
2557 struct net_device *netdev = pci_get_drvdata(pdev);
2560 struct enic *enic = netdev_priv(netdev);
2565 enic_dev_deinit(enic);
2567 #ifdef CONFIG_PCI_IOV
2578 pci_set_drvdata(pdev,
NULL);
2585 .id_table = enic_id_table,
2586 .probe = enic_probe,
2590 static int __init enic_init_module(
void)
2594 return pci_register_driver(&enic_driver);
2597 static void __exit enic_cleanup_module(
void)