34 #include <linux/module.h>
36 #include <linux/netdevice.h>
39 #include <linux/tcp.h>
40 #include <linux/if_vlan.h>
42 #include <linux/slab.h>
50 static int wide_ppm_offset;
52 MODULE_PARM_DESC(wide_ppm_offset,
"Increase CX4 interface clock ppm offset, 0=100ppm (default), 1=300ppm");
54 static u32 crit_err_count;
63 static const u8 nes_max_critical_error_count = 100;
73 static void nes_process_iwarp_aeqe(
struct nes_device *nesdev,
75 static void process_critical_error(
struct nes_device *nesdev);
76 static void nes_process_mac_intr(
struct nes_device *nesdev,
u32 mac_number);
77 static unsigned int nes_reset_adapter_ne020(
struct nes_device *nesdev,
u8 *OneG_Mode);
78 static void nes_terminate_timeout(
unsigned long context);
79 static void nes_terminate_start_timer(
struct nes_qp *nesqp);
81 #ifdef CONFIG_INFINIBAND_NES_DEBUG
82 static unsigned char *nes_iwarp_state_str[] = {
93 static unsigned char *nes_tcp_state_str[] = {
113 static inline void print_ip(
struct nes_cm_node *cm_node)
115 unsigned char *rem_addr;
117 rem_addr = (
unsigned char *)&cm_node->
rem_addr;
153 static void nes_nic_init_timer(
struct nes_device *nesdev)
182 static void nes_nic_tune_timer(
struct nes_device *nesdev)
257 unsigned long num_pds;
279 " adapter PCI slot/bus = %u/%u, pci devices PCI slot/bus = %u/%u, .\n",
284 nesdev->
pcidev->bus->number );
309 if ((port_count = nes_reset_adapter_ne020(nesdev, &OneG_Mode)) == 0)
316 if (max_qp > ((
u32)1 << (u32temp & 0x001f))) {
319 max_qp = (
u32)1 << (u32temp & 0x001f);
322 hte_index_mask = ((
u32)1 << ((u32temp & 0x001f)+1))-1;
324 max_qp, hte_index_mask);
328 max_irrq = 1 << (u32temp & 0x001f);
330 if (max_qp > max_irrq) {
337 if (num_pds > max_qp)
341 max_mr = (
u32)8192 << (u32temp & 0x7);
344 max_256pbl = (
u32)1 << (u32temp & 0x0000001f);
345 max_4kpbl = (
u32)1 << ((u32temp >> 16) & 0x0000001f);
349 arp_table_size = 1 << u32temp;
352 (sizeof(unsigned long)-1)) & (~(
sizeof(
unsigned long)-1));
358 adapter_size +=
sizeof(
struct nes_qp **) * max_qp;
361 nesadapter = kzalloc(adapter_size,
GFP_KERNEL);
362 if (nesadapter ==
NULL) {
378 pci_bus_read_config_word(nesdev->
pcidev->bus, nesdev->
pcidev->devfn,
382 if (nes_init_serdes(nesdev, hw_rev, port_count, nesadapter,
387 nes_init_csr_ne020(nesdev, hw_rev, port_count);
401 nesadapter->
hw_rev = hw_rev;
413 nesadapter->
max_pd = num_pds;
425 printk(
PFX "%s: Using Adaptive Interrupt Moderation\n", __func__);
440 nesadapter->
allocated_qps = (
unsigned long *)&(((
unsigned char *)nesadapter)
441 [(
sizeof(
struct nes_adapter)+(sizeof(unsigned long)-1))&(~(
sizeof(
unsigned long)-1))]);
456 for (u32temp = 0; u32temp < 20; u32temp++)
460 max_rq_wrs = ((u32temp >> 8) & 3);
461 switch (max_rq_wrs) {
476 max_sq_wrs = (u32temp & 3);
477 switch (max_sq_wrs) {
542 u32 pcs_control_status0, pcs_control_status1;
550 pcs_control_status0 = nes_read_indexed(nesdev,
552 pcs_control_status1 = nes_read_indexed(nesdev,
556 pcs_control_status0 = nes_read_indexed(nesdev,
558 pcs_control_status1 = nes_read_indexed(nesdev,
560 if ((0x0F000100 == (pcs_control_status0 & 0x0F000100))
561 || (0x0F000100 == (pcs_control_status1 & 0x0F000100)))
570 reset_value |= 0x0000003d;
574 & 0x00000040) != 0x00000040) && (j++ < 5000));
575 spin_unlock_irqrestore(&nesadapter->
phy_lock, flags);
577 pcs_control_status0 = nes_read_indexed(nesdev,
579 pcs_control_status1 = nes_read_indexed(nesdev,
583 pcs_control_status0 = nes_read_indexed(nesdev,
585 pcs_control_status1 = nes_read_indexed(nesdev,
587 if ((0x0F000100 == (pcs_control_status0 & 0x0F000100))
588 || (0x0F000100 == (pcs_control_status1 & 0x0F000100))) {
589 if (++ext_cnt > int_cnt) {
595 reset_value |= 0x0000003d;
599 & 0x00000040) != 0x00000040) && (j++ < 5000));
600 spin_unlock_irqrestore(&nesadapter->
phy_lock, flags);
627 for (func_index = 0; func_index < 8; func_index++) {
628 pci_bus_read_config_word(nesdev->
pcidev->bus,
630 func_index), 0, &vendor_id);
631 if (vendor_id == 0xffff)
635 func_index, pci_name(nesdev->
pcidev));
645 static unsigned int nes_reset_adapter_ne020(
struct nes_device *nesdev,
u8 *OneG_Mode)
652 port_count = ((u32temp & 0x00000300) >> 8) + 1;
654 *OneG_Mode = (u32temp & 0x00003c00) ? 0 : 1;
656 u32temp, port_count);
659 u32temp &= 0xff00ffc0;
660 switch (port_count) {
662 u32temp |= 0x00ee0000;
665 u32temp |= 0x00cc0000;
668 u32temp |= 0x00000000;
699 switch (port_count) {
701 u32temp |= 0x00ee0010;
704 u32temp |= 0x00cc0030;
707 u32temp |= 0x00000030;
725 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
733 if (port_count > 1) {
736 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
751 static int nes_init_serdes(
struct nes_device *nesdev,
u8 hw_rev,
u8 port_count,
821 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
839 if (port_count > 1) {
844 & 0x0000000f)) != 0x0000000f) && (i++ < 5000))
847 printk(
"%s: Init: serdes 1 not ready, status=%x\n", __func__, u32temp);
868 static void nes_init_csr_ne020(
struct nes_device *nesdev,
u8 hw_rev,
u8 port_count)
874 nes_write_indexed(nesdev, 0x000001E4, 0x00000007);
876 nes_write_indexed(nesdev, 0x000001E8, 0x00020874);
877 nes_write_indexed(nesdev, 0x000001D8, 0x00048002);
879 nes_write_indexed(nesdev, 0x000001FC, 0x00050005);
880 nes_write_indexed(nesdev, 0x00000600, 0x55555555);
881 nes_write_indexed(nesdev, 0x00000604, 0x55555555);
884 nes_write_indexed(nesdev, 0x00002000, 0x00000001);
885 nes_write_indexed(nesdev, 0x00002004, 0x00000001);
886 nes_write_indexed(nesdev, 0x00002008, 0x0000FFFF);
887 nes_write_indexed(nesdev, 0x0000200C, 0x00000001);
888 nes_write_indexed(nesdev, 0x00002010, 0x000003c1);
889 nes_write_indexed(nesdev, 0x0000201C, 0x75345678);
890 if (port_count > 1) {
891 nes_write_indexed(nesdev, 0x00002200, 0x00000001);
892 nes_write_indexed(nesdev, 0x00002204, 0x00000001);
893 nes_write_indexed(nesdev, 0x00002208, 0x0000FFFF);
894 nes_write_indexed(nesdev, 0x0000220C, 0x00000001);
895 nes_write_indexed(nesdev, 0x00002210, 0x000003c1);
896 nes_write_indexed(nesdev, 0x0000221C, 0x75345678);
897 nes_write_indexed(nesdev, 0x00000908, 0x20000001);
899 if (port_count > 2) {
900 nes_write_indexed(nesdev, 0x00002400, 0x00000001);
901 nes_write_indexed(nesdev, 0x00002404, 0x00000001);
902 nes_write_indexed(nesdev, 0x00002408, 0x0000FFFF);
903 nes_write_indexed(nesdev, 0x0000240C, 0x00000001);
904 nes_write_indexed(nesdev, 0x00002410, 0x000003c1);
905 nes_write_indexed(nesdev, 0x0000241C, 0x75345678);
906 nes_write_indexed(nesdev, 0x00000910, 0x20000001);
908 nes_write_indexed(nesdev, 0x00002600, 0x00000001);
909 nes_write_indexed(nesdev, 0x00002604, 0x00000001);
910 nes_write_indexed(nesdev, 0x00002608, 0x0000FFFF);
911 nes_write_indexed(nesdev, 0x0000260C, 0x00000001);
912 nes_write_indexed(nesdev, 0x00002610, 0x000003c1);
913 nes_write_indexed(nesdev, 0x0000261C, 0x75345678);
914 nes_write_indexed(nesdev, 0x00000918, 0x20000001);
917 nes_write_indexed(nesdev, 0x00005000, 0x00018000);
921 nes_write_indexed(nesdev, 0x00005008, 0x1F1F1F1F);
922 nes_write_indexed(nesdev, 0x00005010, 0x1F1F1F1F);
923 nes_write_indexed(nesdev, 0x00005018, 0x1F1F1F1F);
924 nes_write_indexed(nesdev, 0x00005020, 0x1F1F1F1F);
925 nes_write_indexed(nesdev, 0x00006090, 0xFFFFFFFF);
928 nes_write_indexed(nesdev, 0x00000900, 0x20000001);
929 nes_write_indexed(nesdev, 0x000060C0, 0x0000028e);
930 nes_write_indexed(nesdev, 0x000060C8, 0x00000020);
932 nes_write_indexed(nesdev, 0x000001EC, 0x7b2625a0);
936 u32temp = nes_read_indexed(nesdev, 0x000008e8);
937 u32temp |= 0x80000000;
938 nes_write_indexed(nesdev, 0x000008e8, u32temp);
939 u32temp = nes_read_indexed(nesdev, 0x000021f8);
940 u32temp &= 0x7fffffff;
941 u32temp |= 0x7fff0010;
942 nes_write_indexed(nesdev, 0x000021f8, u32temp);
943 if (port_count > 1) {
944 u32temp = nes_read_indexed(nesdev, 0x000023f8);
945 u32temp &= 0x7fffffff;
946 u32temp |= 0x7fff0010;
947 nes_write_indexed(nesdev, 0x000023f8, u32temp);
1021 nesdev->
cqp.sq_pbase);
1032 vmem = (
void *)(((
unsigned long)nesdev->
cqp_vbase + (512 - 1)) &
1033 ~(
unsigned long)(512 - 1));
1035 ~(
unsigned long long)(512 - 1));
1037 nesdev->
cqp.sq_vbase = vmem;
1038 nesdev->
cqp.sq_pbase = pmem;
1040 nesdev->
cqp.sq_head = 0;
1041 nesdev->
cqp.sq_tail = 0;
1047 nesdev->
ccq.cq_vbase = vmem;
1048 nesdev->
ccq.cq_pbase = pmem;
1050 nesdev->
ccq.cq_head = 0;
1051 nesdev->
ccq.ce_handler = nes_cqp_ce_handler;
1087 cqp_qp_context = vmem;
1097 nes_write_indexed(nesdev,
1101 nes_write_indexed(nesdev,
1104 nes_write_indexed(nesdev,
1117 cqp_head = nesdev->
cqp.sq_head++;
1118 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
1119 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1124 (nesdev->
ccq.cq_number |
1126 u64temp = (
u64)nesdev->
ccq.cq_pbase;
1129 u64temp = (
unsigned long)&nesdev->
ccq;
1137 cqp_head = nesdev->
cqp.sq_head++;
1138 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
1139 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1147 cqp_head = nesdev->
cqp.sq_head++;
1148 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
1149 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1157 cqp_head = nesdev->
cqp.sq_head++;
1158 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
1159 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1169 if (count++ > 1000) {
1176 }
while (!(nes_read_indexed(nesdev,
1182 u32temp = 0x04800000;
1188 if (count++ > 1000) {
1195 }
while (((nes_read_indexed(nesdev,
1202 nesdev->
cqp.sq_tail++;
1216 unsigned long flags;
1222 }
while (!(nesdev->
cqp.sq_head == nesdev->
cqp.sq_tail));
1226 nesdev->
ccq.cq_number);
1234 cqp_head = nesdev->
cqp.sq_head++;
1235 nesdev->
cqp.sq_head &= nesdev->
cqp.sq_size-1;
1236 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
1242 cqp_head = nesdev->
cqp.sq_head++;
1243 nesdev->
cqp.sq_head &= nesdev->
cqp.sq_size-1;
1244 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
1249 cqp_head = nesdev->
cqp.sq_head++;
1250 nesdev->
cqp.sq_head &= nesdev->
cqp.sq_size-1;
1251 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
1256 cqp_head = nesdev->
cqp.sq_head++;
1257 nesdev->
cqp.sq_head &= nesdev->
cqp.sq_size-1;
1258 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
1264 cqp_head = nesdev->
cqp.sq_head++;
1265 nesdev->
cqp.sq_head &= nesdev->
cqp.sq_size-1;
1266 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
1275 spin_unlock_irqrestore(&nesdev->
cqp.lock, flags);
1280 if (count++ > 1000) {
1286 }
while (((nes_read_indexed(nesdev,
1292 nes_read_indexed(nesdev,
1299 nesdev->
cqp.sq_pbase);
1308 static int nes_init_1g_phy(
struct nes_device *nesdev,
u8 phy_type,
u8 phy_index)
1323 if (counter++ > 100) {
1327 }
while (phy_data & 0x8000);
1362 static int nes_init_2025_phy(
struct nes_device *nesdev,
u8 phy_type,
u8 phy_index)
1364 u32 temp_phy_data = 0;
1365 u32 temp_phy_data2 = 0;
1370 unsigned int first_attempt = 1;
1379 if (temp_phy_data != temp_phy_data2) {
1382 if ((temp_phy_data & 0xff) > 0x20)
1384 printk(
PFX "Reinitialize external PHY\n");
1454 if (counter++ > 150) {
1461 }
while ((temp_phy_data2 == temp_phy_data));
1468 if (counter++ > 300) {
1469 if (((temp_phy_data & 0xff) == 0x0) && first_attempt) {
1482 }
while ((temp_phy_data & 0xff) < 0x30);
1504 && (counter++ < 5000))
1519 unsigned long flags;
1520 u8 phy_type = nesadapter->
phy_type[mac_index];
1527 tx_config &= 0xFFFFFFE3;
1531 tx_config &= 0xFFFFFFE3;
1540 ret = nes_init_1g_phy(nesdev, phy_type, phy_index);
1545 ret = nes_init_2025_phy(nesdev, phy_type, phy_index);
1549 spin_unlock_irqrestore(&nesdev->
nesadapter->phy_lock, flags);
1558 static void nes_replenish_nic_rq(
struct nes_vnic *nesvnic)
1560 unsigned long flags;
1567 u32 rx_wqes_posted = 0;
1569 nesnic = &nesvnic->
nic;
1570 nesdev = nesvnic->
nesdev;
1576 spin_unlock_irqrestore(&nesnic->
rq_lock, flags);
1580 spin_unlock_irqrestore(&nesnic->
rq_lock, flags);
1584 spin_unlock_irqrestore(&nesnic->
rq_lock, flags);
1590 bus_address = pci_map_single(nesdev->
pcidev,
1596 nic_rqe = &nesnic->
rq_vbase[nesvnic->
nic.rq_head];
1609 if (++rx_wqes_posted == 255) {
1618 spin_unlock_irqrestore(&nesnic->
rq_lock, flags);
1622 spin_unlock_irqrestore(&nesnic->
rq_lock, flags);
1636 static void nes_rq_wqes_timeout(
unsigned long parm)
1639 printk(
"%s: Timer fired.\n", __func__);
1642 nes_replenish_nic_rq(nesvnic);
1646 static int nes_lro_get_skb_hdr(
struct sk_buff *skb,
void **
iphdr,
1647 void **tcph,
u64 *hdr_flags,
void *
priv)
1649 unsigned int ip_len;
1651 skb_reset_network_header(skb);
1655 ip_len = ip_hdrlen(skb);
1656 skb_set_transport_header(skb, ip_len);
1657 *tcph = tcp_hdr(skb);
1675 struct nes_vnic *nesvnic = netdev_priv(netdev);
1676 unsigned long flags;
1693 sizeof(struct nes_hw_nic_qp_context);
1705 vmem = (
void *)(((
unsigned long)nesvnic->
nic_vbase + (256 - 1)) &
1706 ~(
unsigned long)(256 - 1));
1708 ~(
unsigned long long)(256 - 1));
1711 nesvnic->
nic.first_frag_vbase = vmem;
1721 nesvnic->
nic.sq_vbase = (
void *)vmem;
1722 nesvnic->
nic.sq_pbase = pmem;
1723 nesvnic->
nic.sq_head = 0;
1724 nesvnic->
nic.sq_tail = 0;
1750 nesvnic->
nic.rq_vbase = vmem;
1751 nesvnic->
nic.rq_pbase = pmem;
1752 nesvnic->
nic.rq_head = 0;
1753 nesvnic->
nic.rq_tail = 0;
1765 nesvnic->
nic_cq.cq_vbase = vmem;
1766 nesvnic->
nic_cq.cq_pbase = pmem;
1767 nesvnic->
nic_cq.cq_head = 0;
1768 nesvnic->
nic_cq.cq_size = NES_NIC_WQ_SIZE * 2;
1770 nesvnic->
nic_cq.ce_handler = nes_nic_napi_ce_handler;
1774 cqp_head = nesdev->
cqp.sq_head;
1776 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
1777 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1784 u64temp = (
u64)nesvnic->
nic_cq.cq_pbase;
1792 if (++cqp_head >= nesdev->
cqp.sq_size)
1794 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
1795 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1798 nic_context = (
void *)(&nesvnic->
nic_cq.cq_vbase[nesvnic->
nic_cq.cq_size]);
1802 nes_debug(
NES_DBG_INIT,
"RX_WINDOW_BUFFER_PAGE_TABLE_SIZE = 0x%08X, RX_WINDOW_BUFFER_SIZE = 0x%08X\n",
1809 u64temp = (
u64)nesvnic->
nic.sq_pbase;
1812 u64temp = (
u64)nesvnic->
nic.rq_pbase;
1819 u64temp = (
u64)nesvnic->
nic_cq.cq_pbase +
1823 if (++cqp_head >= nesdev->
cqp.sq_size)
1825 nesdev->
cqp.sq_head = cqp_head;
1832 spin_unlock_irqrestore(&nesdev->
cqp.lock, flags);
1834 nesvnic->
nic.qp_id);
1839 nesvnic->
nic.qp_id, ret);
1848 for (counter = 0; counter < (NES_NIC_WQ_SIZE - 1); counter++) {
1859 pmem = pci_map_single(nesdev->
pcidev, skb->
data,
1865 nic_rqe = &nesvnic->
nic.rq_vbase[counter];
1873 wqe_count = NES_NIC_WQ_SIZE - 1;
1877 counter =
min(wqe_count, ((
u32)255));
1880 }
while (wqe_count);
1885 if (nesdev->
nesadapter->et_use_adaptive_rx_coalesce)
1887 nes_nic_init_timer(nesdev);
1888 if (netdev->
mtu > 1500)
1892 if ((nesdev->
nesadapter->allow_unaligned_fpdus) &&
1899 nesvnic->
lro_mgr.max_aggr = nes_lro_max_aggr;
1902 nesvnic->
lro_mgr.get_skb_header = nes_lro_get_skb_hdr;
1904 nesvnic->
lro_mgr.dev = netdev;
1921 __le16 *wqe_fragment_length;
1922 u16 wqe_fragment_index;
1925 unsigned long flags;
1930 if (nesdev->
nesadapter->allow_unaligned_fpdus)
1938 while (nesvnic->
nic.rq_head != nesvnic->
nic.rq_tail) {
1939 rx_skb = nesvnic->
nic.rx_skb[nesvnic->
nic.rq_tail];
1944 dev_kfree_skb(nesvnic->
nic.rx_skb[nesvnic->
nic.rq_tail++]);
1945 nesvnic->
nic.rq_tail &= (nesvnic->
nic.rq_size - 1);
1949 while (nesvnic->
nic.sq_head != nesvnic->
nic.sq_tail) {
1950 nic_sqe = &nesvnic->
nic.sq_vbase[nesvnic->
nic.sq_tail];
1951 wqe_fragment_index = 1;
1952 wqe_fragment_length = (
__le16 *)
1955 wqe_fragment_length++;
1956 if (
le16_to_cpu(wqe_fragment_length[wqe_fragment_index]) != 0) {
1959 wqe_fragment_index*2]);
1962 + wqe_fragment_index*2]))<<32;
1965 nesvnic->
nic.first_frag_overflow)) {
1966 pci_unmap_single(nesdev->
pcidev,
1969 wqe_fragment_index++]),
1972 for (; wqe_fragment_index < 5; wqe_fragment_index++) {
1973 if (wqe_fragment_length[wqe_fragment_index]) {
1977 wqe_fragment_index*2]);
1981 wqe_fragment_index*2]))<<32;
1983 pci_unmap_page(nesdev->
pcidev,
1986 wqe_fragment_length[
1987 wqe_fragment_index]),
1993 if (nesvnic->
nic.tx_skb[nesvnic->
nic.sq_tail])
1995 nesvnic->
nic.tx_skb[nesvnic->
nic.sq_tail]);
1997 nesvnic->
nic.sq_tail = (nesvnic->
nic.sq_tail + 1)
1998 & (nesvnic->
nic.sq_size - 1);
2004 cqp_head = nesdev->
cqp.sq_head;
2005 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
2006 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
2011 nesvnic->
nic.qp_id);
2013 if (++cqp_head >= nesdev->
cqp.sq_size)
2016 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
2019 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
2025 if (++cqp_head >= nesdev->
cqp.sq_size)
2028 nesdev->
cqp.sq_head = cqp_head;
2034 spin_unlock_irqrestore(&nesdev->
cqp.lock, flags);
2036 " cqp.sq_tail=%u, cqp.sq_size=%u\n",
2037 cqp_head, nesdev->
cqp.sq_head,
2038 nesdev->
cqp.sq_tail, nesdev->
cqp.sq_size);
2044 " cqp.sq_head=%u, cqp.sq_tail=%u\n",
2045 ret, cqp_head, nesdev->
cqp.sq_head, nesdev->
cqp.sq_tail);
2048 nesvnic->
nic.qp_id);
2077 if ((int_stat) && ((int_stat & 0x0000ff00) == int_stat)) {
2103 nes_nic_init_timer(nesdev);
2120 static void process_critical_error(
struct nes_device *nesdev)
2123 u32 nes_idx_debug_error_masks0 = 0;
2124 u16 error_module = 0;
2130 0x01010000 | (debug_error & 0x0000ffff));
2131 if (crit_err_count++ > 10)
2133 error_module = (
u16) (debug_error & 0x1F00) >> 8;
2134 if (++nesdev->
nesadapter->crit_error_count[error_module-1] >=
2135 nes_max_critical_error_count) {
2137 "0x%02X\n", (
u16)error_module);
2138 nes_idx_debug_error_masks0 = nes_read_indexed(nesdev,
2141 nes_idx_debug_error_masks0 | (1 << error_module));
2152 u32 loop_counter = 0;
2158 u32 processed_intf_int = 0;
2159 u16 processed_timer_int = 0;
2160 u16 completion_ints = 0;
2172 if (processed_intf_int != 0)
2176 if (processed_timer_int == 0) {
2177 processed_timer_int = 1;
2181 int_stat &= ~NES_INT_TIMER;
2197 temp_int_stat = int_stat;
2198 for (counter = 0, int_status_bit = 1; counter < 16; counter++) {
2199 if (int_stat & int_status_bit) {
2200 nes_process_ceq(nesdev, &nesadapter->
ceq[counter]);
2201 temp_int_stat &= ~int_status_bit;
2202 completion_ints = 1;
2204 if (!(temp_int_stat & 0x0000ffff))
2206 int_status_bit <<= 1;
2211 if (int_stat & int_status_bit) {
2216 int_status_bit = 1 << (24 + nesdev->
mac_index);
2217 if (int_stat & int_status_bit) {
2218 nes_process_mac_intr(nesdev, nesdev->
mac_index);
2231 processed_intf_int = 1;
2235 process_critical_error(nesdev);
2256 if (timer_ints == 1) {
2258 if (completion_ints == 0) {
2271 nes_nic_init_timer(nesdev);
2285 if ( (completion_ints == 1) &&
2334 if (++head >= ceq_size)
2374 nes_process_iwarp_aeqe(nesdev, (
struct nes_hw_aeqe *)aeqe);
2378 (
u16)(aeqe_misc >> 16));
2384 if (++head >= aeq_size)
2393 static void nes_reset_link(
struct nes_device *nesdev,
u32 mac_index)
2407 if ((mac_index == 0) || ((mac_index == 1) && (nesadapter->
OneG_Mode)))
2408 reset_value |= 0x0000001d;
2410 reset_value |= 0x0000002d;
2417 if (0x00000040 & u32temp)
2422 reset_value |= 0x0000003d;
2430 & 0x00000040) != 0x00000040) && (i++ < 5000));
2432 if (0x0000003d == (reset_value & 0x0000003d)) {
2433 u32 pcs_control_status0, pcs_control_status1;
2435 for (i = 0; i < 10; i++) {
2438 if (((0x0F000000 == (pcs_control_status0 & 0x0F000000))
2439 && (pcs_control_status0 & 0x00100000))
2440 || ((0x0F000000 == (pcs_control_status1 & 0x0F000000))
2441 && (pcs_control_status1 & 0x00100000)))
2448 if (0x00000040 & u32temp)
2456 & 0x00000040) != 0x00000040) && (i++ < 5000));
2464 static void nes_process_mac_intr(
struct nes_device *nesdev,
u32 mac_number)
2466 unsigned long flags;
2467 u32 pcs_control_status;
2475 u32 pcs_val = 0x0f0f0000;
2476 u32 pcs_mask = 0x0f1f0000;
2481 spin_unlock_irqrestore(&nesadapter->
phy_lock, flags);
2496 nes_reset_link(nesdev, mac_index);
2503 nesadapter->
phy_index[mac_index], &phy_data);
2505 nesadapter->
phy_index[mac_index], phy_data);
2506 }
while (phy_data&0x8000);
2511 nesadapter->
phy_index[mac_index], &phy_data);
2513 nesadapter->
phy_index[mac_index], phy_data);
2514 if (temp_phy_data == phy_data)
2516 temp_phy_data = phy_data;
2520 nesadapter->
phy_index[mac_index], &phy_data);
2522 nesadapter->
phy_index[mac_index], phy_data);
2525 nesadapter->
phy_index[mac_index], &phy_data);
2527 nesadapter->
phy_index[mac_index], phy_data);
2529 if (temp_phy_data & 0x1000) {
2541 switch (mac_index) {
2544 pcs_control_status = nes_read_indexed(nesdev,
2548 pcs_control_status = nes_read_indexed(nesdev,
2553 pcs_control_status = nes_read_indexed(nesdev,
2555 pcs_control_status = nes_read_indexed(nesdev,
2560 mac_index, pcs_control_status);
2563 u32temp = 0x01010000;
2565 u32temp |= 0x02020000;
2567 if ((pcs_control_status & u32temp)!= u32temp) {
2572 switch (nesadapter->
phy_type[mac_index]) {
2594 phy_data = (!temp_phy_data && (phy_data == 0x8000)) ? 0x4 : 0x0;
2597 __func__, phy_data, nesadapter->
mac_link_down[mac_index] ?
"DOWN" :
"UP");
2602 pcs_val = pcs_mask = 0x01010000;
2604 pcs_val = pcs_mask = 0x02020000;
2607 phy_data = (pcs_val == (pcs_control_status & pcs_mask)) ? 0x4 : 0x0;
2612 if (phy_data & 0x0004) {
2613 if (wide_ppm_offset &&
2616 cdr_ctrl = nes_read_indexed(nesdev,
2619 nes_write_indexed(nesdev,
2622 cdr_ctrl | 0x000F0000);
2628 if (nesvnic->
linkup == 0) {
2629 printk(PFX
"The Link is now up for port %s, netdev %p.\n",
2631 if (netif_queue_stopped(nesvnic->
netdev))
2632 netif_start_queue(nesvnic->
netdev);
2647 if (wide_ppm_offset &&
2650 cdr_ctrl = nes_read_indexed(nesdev,
2653 nes_write_indexed(nesdev,
2656 cdr_ctrl & 0xFFF0FFFF);
2662 if (nesvnic->
linkup == 1) {
2663 printk(PFX
"The Link is now down for port %s, netdev %p.\n",
2665 if (!(netif_queue_stopped(nesvnic->
netdev)))
2666 netif_stop_queue(nesvnic->
netdev);
2688 spin_unlock_irqrestore(&nesadapter->
phy_lock, flags);
2695 unsigned long flags;
2714 phy_data = (!temp_phy_data && (phy_data == 0x8000)) ? 0x4 : 0x0;
2720 if (phy_data & 0x0004) {
2723 if (nesvnic->
linkup == 0) {
2724 printk(PFX
"The Link is now up for port %s, netdev %p.\n",
2726 if (netif_queue_stopped(nesvnic->
netdev))
2727 netif_start_queue(nesvnic->
netdev);
2745 if (nesvnic->
linkup == 1) {
2746 printk(PFX
"The Link is now down for port %s, netdev %p.\n",
2748 if (!(netif_queue_stopped(nesvnic->
netdev)))
2749 netif_stop_queue(nesvnic->
netdev);
2769 spin_unlock_irqrestore(&nesadapter->
phy_lock, flags);
2777 napi_schedule(&nesvnic->
napi);
2784 #define MAX_RQES_TO_PROCESS 384
2801 __le16 *wqe_fragment_length;
2808 u16 wqe_fragment_index = 1;
2811 u16 rqes_processed = 0;
2823 nesnic = &nesvnic->
nic;
2827 wqe_fragment_index = 1;
2832 wqe_fragment_length++;
2833 if (
le16_to_cpu(wqe_fragment_length[wqe_fragment_index]) != 0) {
2835 wqe_fragment_index * 2]);
2837 wqe_fragment_index * 2])) << 32;
2840 pci_unmap_single(nesdev->
pcidev,
2842 le16_to_cpu(wqe_fragment_length[wqe_fragment_index++]),
2845 for (; wqe_fragment_index < 5; wqe_fragment_index++) {
2846 if (wqe_fragment_length[wqe_fragment_index]) {
2848 wqe_fragment_index * 2]);
2850 + wqe_fragment_index * 2])) <<32;
2852 pci_unmap_page(nesdev->
pcidev,
2854 le16_to_cpu(wqe_fragment_length[wqe_fragment_index]),
2864 if (sq_cqes > 128) {
2867 if (netif_queue_stopped(nesvnic->
netdev))
2868 netif_wake_queue(nesvnic->
netdev);
2876 rx_pkt_size = cqe_misc & 0x0000ffff;
2880 nic_rqe = &nesnic->
rq_vbase[nesvnic->
nic.rq_tail];
2883 pci_unmap_single(nesdev->
pcidev, bus_address,
2902 nes_replenish_nic_rq(nesvnic);
2917 " errv = 0x%X, pkt_type = 0x%X.\n",
2918 nesvnic->
netdev->name, cqe_errv, pkt_type);
2931 " errv = 0x%X, pkt_type = 0x%X.\n",
2932 nesvnic->
netdev->name, cqe_errv, pkt_type);
2942 goto skip_rx_indicate0;
2947 cq->
cq_vbase[head].cqe_words[NES_NIC_CQE_TAG_PKT_TYPE_IDX])
2950 nesvnic->
netdev->name, vlan_tag);
2952 __vlan_hwaccel_put_tag(rx_skb, vlan_tag);
2968 if (++head >= cq_size)
2970 if (cqe_count == 255) {
2993 if (netif_queue_stopped(nesvnic->
netdev))
2994 netif_wake_queue(nesvnic->
netdev);
3004 nes_nic_tune_timer(nesdev);
3007 nes_replenish_nic_rq(nesvnic);
3018 unsigned long flags;
3045 " Major/Minor codes = 0x%04X:%04X.\n",
3047 (
u16)(error_code >> 16),
3082 if (++head >= cq_size)
3092 ((((nesdev->
cqp.sq_tail+nesdev->
cqp.sq_size)-nesdev->
cqp.sq_head) &
3093 (nesdev->
cqp.sq_size - 1)) != 1)) {
3096 list_del_init(&cqp_request->
list);
3097 head = nesdev->
cqp.sq_head++;
3098 nesdev->
cqp.sq_head &= nesdev->
cqp.sq_size-1;
3099 cqp_wqe = &nesdev->
cqp.sq_vbase[
head];
3118 spin_unlock_irqrestore(&nesdev->
cqp.lock, flags);
3126 static u8 *locate_mpa(
u8 *pkt,
u32 aeq_info)
3133 pkt += 4 * (pkt[0] & 0x0f);
3134 pkt += 4 * ((pkt[12] >> 4) & 0x0f);
3140 static u32 iwarp_opcode(
struct nes_qp *nesqp,
u32 aeq_info)
3144 u32 opcode = 0xffffffff;
3148 mpa = (
u16 *)locate_mpa(pkt, aeq_info);
3156 static int nes_bld_terminate_hdr(
struct nes_qp *nesqp,
u16 async_event_id,
u32 aeq_info)
3168 if (aeq_info & NES_AEQE_Q2_DATA_WRITTEN) {
3171 pkt = locate_mpa(pkt, aeq_info);
3176 if (pkt[2] & 0x80) {
3198 switch (async_event_id) {
3200 switch (iwarp_opcode(nesqp, aeq_info)) {
3224 switch (iwarp_opcode(nesqp, aeq_info)) {
3261 switch (iwarp_opcode(nesqp, aeq_info)) {
3355 memcpy(termhdr + 1, pkt, copy_len);
3367 static void nes_terminate_connection(
struct nes_device *nesdev,
struct nes_qp *nesqp,
3371 unsigned long flags;
3387 async_event_id = (
u16)aeq_info;
3402 spin_unlock_irqrestore(&nesqp->
lock, flags);
3405 termlen = nes_bld_terminate_hdr(nesqp, async_event_id, aeq_info);
3414 nes_terminate_start_timer(nesqp);
3420 static void nes_terminate_send_fin(
struct nes_device *nesdev,
3427 unsigned long flags;
3432 async_event_id = (
u16)aeq_info;
3438 spin_unlock_irqrestore(&nesqp->
lock, flags);
3446 static void nes_terminate_done(
struct nes_qp *nesqp,
int timeout_occurred)
3449 unsigned long flags;
3450 struct nes_vnic *nesvnic = to_nesvnic(nesqp->
ibqp.device);
3462 spin_unlock_irqrestore(&nesqp->
lock, flags);
3466 if (timeout_occurred == 0)
3476 static void nes_terminate_received(
struct nes_device *nesdev,
3487 if (aeq_info & NES_AEQE_Q2_DATA_WRITTEN) {
3491 mpa = (
u32 *)locate_mpa(pkt, aeq_info);
3494 if ((ddp_ctl & 0xc0) != 0x40)
3496 else if ((ddp_ctl & 0x03) != 1)
3504 else if ((rdma_ctl & 0xc0) != 0x40)
3509 aeq_info = (aeq_info & 0xffff0000) | aeq_id;
3518 nes_terminate_start_timer(nesqp);
3519 nes_terminate_send_fin(nesdev, nesqp, aeqe);
3523 static void nes_terminate_timeout(
unsigned long context)
3527 nes_terminate_done(nesqp, 1);
3531 static void nes_terminate_start_timer(
struct nes_qp *nesqp)
3543 static void nes_process_iwarp_aeqe(
struct nes_device *nesdev,
3547 unsigned long flags;
3551 int resource_allocated;
3554 u32 next_iwarp_state = 0;
3574 async_event_id = (
u16)aeq_info;
3578 " Tcp state = %d, iWARP state = %d\n",
3581 tcp_state, iwarp_state);
3585 if (!nes_is_resource_allocated(nesadapter,
3591 switch (async_event_id) {
3605 spin_unlock_irqrestore(&nesqp->
lock, flags);
3613 " need ae to finish up, original_last_aeq = 0x%04X."
3614 " last_aeq = 0x%04X, scheduling timer. TCP state = %d\n",
3616 async_event_id, nesqp->
last_aeq, tcp_state);
3624 spin_unlock_irqrestore(&nesqp->
lock, flags);
3635 spin_unlock_irqrestore(&nesqp->
lock, flags);
3648 spin_unlock_irqrestore(&nesqp->
lock, flags);
3653 nes_terminate_send_fin(nesdev, nesqp, aeqe);
3657 nes_terminate_received(nesdev, nesqp, aeqe);
3670 printk(
KERN_ERR PFX
"QP[%u] async_event_id=0x%04X IB_EVENT_QP_ACCESS_ERR\n",
3671 nesqp->
hwqp.qp_id, async_event_id);
3680 aeq_info &= 0xffff0000;
3720 printk(
KERN_ERR PFX
"QP[%u] async_event_id=0x%04X IB_EVENT_QP_FATAL\n",
3721 nesqp->
hwqp.qp_id, async_event_id);
3731 resource_allocated = nes_is_resource_allocated(nesadapter, nesadapter->
allocated_cqs,
3733 if (resource_allocated) {
3734 printk(
KERN_ERR PFX
"%s: Processing an NES_AEQE_AEID_CQ_OPERATION_ERROR event on CQ%u\n",
3739 if (nescq->
ibcq.event_handler) {
3740 ibevent.device = nescq->
ibcq.device;
3742 ibevent.element.cq = &nescq->
ibcq;
3743 nescq->
ibcq.event_handler(&ibevent, nescq->
ibcq.cq_context);
3768 if (nescq->
ibcq.comp_handler)
3769 nescq->
ibcq.comp_handler(&nescq->
ibcq, nescq->
ibcq.cq_context);
3779 u32 nic_index,
u32 add_port)
3789 if (cqp_request ==
NULL) {
3794 cqp_wqe = &cqp_request->
cqp_wqe;
3798 accel_local_port, accel_local_port, nic_index);
3800 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
3822 else if (major_code)
3836 struct nes_vnic *nesvnic = netdev_priv(netdev);
3841 nesdev = nesvnic->
nesdev;
3842 arp_index =
nes_arp_table(nesdev, ip_addr, mac_addr, action);
3843 if (arp_index == -1) {
3849 if (cqp_request ==
NULL) {
3854 cqp_wqe = &cqp_request->
cqp_wqe;
3855 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
3866 (((
u32)mac_addr[2]) << 24) | (((
u32)mac_addr[3]) << 16) |
3867 (((
u32)mac_addr[4]) << 8) | (
u32)mac_addr[5]);
3869 (((
u32)mac_addr[0]) << 16) | (
u32)mac_addr[1]);
3876 nesdev->
cqp.sq_head, nesdev->
cqp.sq_tail);
3887 u32 which_wq,
u32 wait_completion)
3896 if (cqp_request ==
NULL) {
3900 if (wait_completion) {
3906 cqp_wqe = &cqp_request->
cqp_wqe;
3907 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
3933 if (wait_completion) {
3938 " CQP Major:Minor codes = 0x%04X:0x%04X\n",