diff options
Diffstat (limited to 'drivers/net/netxen/netxen_nic_main.c')
-rw-r--r-- | drivers/net/netxen/netxen_nic_main.c | 220 |
1 files changed, 96 insertions, 124 deletions
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c index 7615c715e66e..008fd6618a5f 100644 --- a/drivers/net/netxen/netxen_nic_main.c +++ b/drivers/net/netxen/netxen_nic_main.c | |||
@@ -149,76 +149,18 @@ static uint32_t msi_tgt_status[8] = { | |||
149 | 149 | ||
150 | static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG; | 150 | static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG; |
151 | 151 | ||
152 | static void netxen_nic_disable_int(struct netxen_adapter *adapter) | 152 | static inline void netxen_nic_disable_int(struct netxen_adapter *adapter) |
153 | { | 153 | { |
154 | u32 mask = 0x7ff; | 154 | adapter->pci_write_normalize(adapter, adapter->crb_intr_mask, 0); |
155 | int retries = 32; | ||
156 | int pci_fn = adapter->ahw.pci_func; | ||
157 | |||
158 | if (adapter->msi_mode != MSI_MODE_MULTIFUNC) | ||
159 | adapter->pci_write_normalize(adapter, | ||
160 | adapter->crb_intr_mask, 0); | ||
161 | |||
162 | if (adapter->intr_scheme != -1 && | ||
163 | adapter->intr_scheme != INTR_SCHEME_PERPORT) | ||
164 | adapter->pci_write_immediate(adapter, ISR_INT_MASK, mask); | ||
165 | |||
166 | if (!NETXEN_IS_MSI_FAMILY(adapter)) { | ||
167 | do { | ||
168 | adapter->pci_write_immediate(adapter, | ||
169 | adapter->legacy_intr.tgt_status_reg, | ||
170 | 0xffffffff); | ||
171 | mask = adapter->pci_read_immediate(adapter, | ||
172 | ISR_INT_VECTOR); | ||
173 | if (!(mask & 0x80)) | ||
174 | break; | ||
175 | udelay(10); | ||
176 | } while (--retries); | ||
177 | |||
178 | if (!retries) { | ||
179 | printk(KERN_NOTICE "%s: Failed to disable interrupt\n", | ||
180 | netxen_nic_driver_name); | ||
181 | } | ||
182 | } else { | ||
183 | if (adapter->msi_mode == MSI_MODE_MULTIFUNC) { | ||
184 | adapter->pci_write_immediate(adapter, | ||
185 | msi_tgt_status[pci_fn], 0xffffffff); | ||
186 | } | ||
187 | } | ||
188 | } | 155 | } |
189 | 156 | ||
190 | static void netxen_nic_enable_int(struct netxen_adapter *adapter) | 157 | static inline void netxen_nic_enable_int(struct netxen_adapter *adapter) |
191 | { | 158 | { |
192 | u32 mask; | ||
193 | |||
194 | if (adapter->intr_scheme != -1 && | ||
195 | adapter->intr_scheme != INTR_SCHEME_PERPORT) { | ||
196 | switch (adapter->ahw.board_type) { | ||
197 | case NETXEN_NIC_GBE: | ||
198 | mask = 0x77b; | ||
199 | break; | ||
200 | case NETXEN_NIC_XGBE: | ||
201 | mask = 0x77f; | ||
202 | break; | ||
203 | default: | ||
204 | mask = 0x7ff; | ||
205 | break; | ||
206 | } | ||
207 | |||
208 | adapter->pci_write_immediate(adapter, ISR_INT_MASK, mask); | ||
209 | } | ||
210 | |||
211 | adapter->pci_write_normalize(adapter, adapter->crb_intr_mask, 0x1); | 159 | adapter->pci_write_normalize(adapter, adapter->crb_intr_mask, 0x1); |
212 | 160 | ||
213 | if (!NETXEN_IS_MSI_FAMILY(adapter)) { | 161 | if (!NETXEN_IS_MSI_FAMILY(adapter)) |
214 | mask = 0xbff; | 162 | adapter->pci_write_immediate(adapter, |
215 | if (adapter->intr_scheme == INTR_SCHEME_PERPORT) | 163 | adapter->legacy_intr.tgt_mask_reg, 0xfbff); |
216 | adapter->pci_write_immediate(adapter, | ||
217 | adapter->legacy_intr.tgt_mask_reg, mask); | ||
218 | else | ||
219 | adapter->pci_write_normalize(adapter, | ||
220 | CRB_INT_VECTOR, 0); | ||
221 | } | ||
222 | } | 164 | } |
223 | 165 | ||
224 | static int nx_set_dma_mask(struct netxen_adapter *adapter, uint8_t revision_id) | 166 | static int nx_set_dma_mask(struct netxen_adapter *adapter, uint8_t revision_id) |
@@ -417,16 +359,6 @@ static void netxen_pcie_strap_init(struct netxen_adapter *adapter) | |||
417 | int i, pos; | 359 | int i, pos; |
418 | struct pci_dev *pdev; | 360 | struct pci_dev *pdev; |
419 | 361 | ||
420 | pdev = pci_get_device(0x1166, 0x0140, NULL); | ||
421 | if (pdev) { | ||
422 | pci_dev_put(pdev); | ||
423 | adapter->hw_read_wx(adapter, | ||
424 | NETXEN_PCIE_REG(PCIE_TGT_SPLIT_CHICKEN), &chicken, 4); | ||
425 | chicken |= 0x4000; | ||
426 | adapter->hw_write_wx(adapter, | ||
427 | NETXEN_PCIE_REG(PCIE_TGT_SPLIT_CHICKEN), &chicken, 4); | ||
428 | } | ||
429 | |||
430 | pdev = adapter->pdev; | 362 | pdev = adapter->pdev; |
431 | 363 | ||
432 | adapter->hw_read_wx(adapter, | 364 | adapter->hw_read_wx(adapter, |
@@ -501,6 +433,44 @@ static void netxen_init_msix_entries(struct netxen_adapter *adapter) | |||
501 | adapter->msix_entries[i].entry = i; | 433 | adapter->msix_entries[i].entry = i; |
502 | } | 434 | } |
503 | 435 | ||
436 | static int | ||
437 | netxen_read_mac_addr(struct netxen_adapter *adapter) | ||
438 | { | ||
439 | int i; | ||
440 | unsigned char *p; | ||
441 | __le64 mac_addr; | ||
442 | DECLARE_MAC_BUF(mac); | ||
443 | struct net_device *netdev = adapter->netdev; | ||
444 | struct pci_dev *pdev = adapter->pdev; | ||
445 | |||
446 | if (netxen_is_flash_supported(adapter) != 0) | ||
447 | return -EIO; | ||
448 | |||
449 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | ||
450 | if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0) | ||
451 | return -EIO; | ||
452 | } else { | ||
453 | if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0) | ||
454 | return -EIO; | ||
455 | } | ||
456 | |||
457 | p = (unsigned char *)&mac_addr; | ||
458 | for (i = 0; i < 6; i++) | ||
459 | netdev->dev_addr[i] = *(p + 5 - i); | ||
460 | |||
461 | memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len); | ||
462 | |||
463 | /* set station address */ | ||
464 | |||
465 | if (!is_valid_ether_addr(netdev->perm_addr)) { | ||
466 | dev_warn(&pdev->dev, "Bad MAC address %s.\n", | ||
467 | print_mac(mac, netdev->dev_addr)); | ||
468 | } else | ||
469 | adapter->macaddr_set(adapter, netdev->dev_addr); | ||
470 | |||
471 | return 0; | ||
472 | } | ||
473 | |||
504 | /* | 474 | /* |
505 | * netxen_nic_probe() | 475 | * netxen_nic_probe() |
506 | * | 476 | * |
@@ -529,10 +499,8 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
529 | unsigned long mem_base, mem_len, db_base, db_len, pci_len0 = 0; | 499 | unsigned long mem_base, mem_len, db_base, db_len, pci_len0 = 0; |
530 | int i = 0, err; | 500 | int i = 0, err; |
531 | int first_driver, first_boot; | 501 | int first_driver, first_boot; |
532 | __le64 mac_addr[FLASH_NUM_PORTS + 1]; | ||
533 | u32 val; | 502 | u32 val; |
534 | int pci_func_id = PCI_FUNC(pdev->devfn); | 503 | int pci_func_id = PCI_FUNC(pdev->devfn); |
535 | DECLARE_MAC_BUF(mac); | ||
536 | struct netxen_legacy_intr_set *legacy_intrp; | 504 | struct netxen_legacy_intr_set *legacy_intrp; |
537 | uint8_t revision_id; | 505 | uint8_t revision_id; |
538 | 506 | ||
@@ -545,6 +513,13 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
545 | return -ENODEV; | 513 | return -ENODEV; |
546 | } | 514 | } |
547 | 515 | ||
516 | if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) { | ||
517 | printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x" | ||
518 | "will not be enabled.\n", | ||
519 | NX_P3_A0, NX_P3_B1); | ||
520 | return -ENODEV; | ||
521 | } | ||
522 | |||
548 | if ((err = pci_enable_device(pdev))) | 523 | if ((err = pci_enable_device(pdev))) |
549 | return err; | 524 | return err; |
550 | 525 | ||
@@ -898,34 +873,14 @@ request_msi: | |||
898 | goto err_out_disable_msi; | 873 | goto err_out_disable_msi; |
899 | 874 | ||
900 | init_timer(&adapter->watchdog_timer); | 875 | init_timer(&adapter->watchdog_timer); |
901 | adapter->ahw.linkup = 0; | ||
902 | adapter->watchdog_timer.function = &netxen_watchdog; | 876 | adapter->watchdog_timer.function = &netxen_watchdog; |
903 | adapter->watchdog_timer.data = (unsigned long)adapter; | 877 | adapter->watchdog_timer.data = (unsigned long)adapter; |
904 | INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task); | 878 | INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task); |
905 | INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task); | 879 | INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task); |
906 | 880 | ||
907 | if (netxen_is_flash_supported(adapter) == 0 && | 881 | err = netxen_read_mac_addr(adapter); |
908 | netxen_get_flash_mac_addr(adapter, mac_addr) == 0) { | 882 | if (err) |
909 | unsigned char *p; | 883 | dev_warn(&pdev->dev, "failed to read mac addr\n"); |
910 | |||
911 | p = (unsigned char *)&mac_addr[adapter->portnum]; | ||
912 | netdev->dev_addr[0] = *(p + 5); | ||
913 | netdev->dev_addr[1] = *(p + 4); | ||
914 | netdev->dev_addr[2] = *(p + 3); | ||
915 | netdev->dev_addr[3] = *(p + 2); | ||
916 | netdev->dev_addr[4] = *(p + 1); | ||
917 | netdev->dev_addr[5] = *(p + 0); | ||
918 | |||
919 | memcpy(netdev->perm_addr, netdev->dev_addr, | ||
920 | netdev->addr_len); | ||
921 | if (!is_valid_ether_addr(netdev->perm_addr)) { | ||
922 | printk(KERN_ERR "%s: Bad MAC address %s.\n", | ||
923 | netxen_nic_driver_name, | ||
924 | print_mac(mac, netdev->dev_addr)); | ||
925 | } else { | ||
926 | adapter->macaddr_set(adapter, netdev->dev_addr); | ||
927 | } | ||
928 | } | ||
929 | 884 | ||
930 | netif_carrier_off(netdev); | 885 | netif_carrier_off(netdev); |
931 | netif_stop_queue(netdev); | 886 | netif_stop_queue(netdev); |
@@ -1000,6 +955,7 @@ static void __devexit netxen_nic_remove(struct pci_dev *pdev) | |||
1000 | 955 | ||
1001 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { | 956 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
1002 | netxen_free_hw_resources(adapter); | 957 | netxen_free_hw_resources(adapter); |
958 | netxen_release_rx_buffers(adapter); | ||
1003 | netxen_free_sw_resources(adapter); | 959 | netxen_free_sw_resources(adapter); |
1004 | } | 960 | } |
1005 | 961 | ||
@@ -1069,6 +1025,15 @@ static int netxen_nic_open(struct net_device *netdev) | |||
1069 | goto err_out_free_sw; | 1025 | goto err_out_free_sw; |
1070 | } | 1026 | } |
1071 | 1027 | ||
1028 | if ((adapter->msi_mode != MSI_MODE_MULTIFUNC) || | ||
1029 | (adapter->intr_scheme != INTR_SCHEME_PERPORT)) { | ||
1030 | printk(KERN_ERR "%s: Firmware interrupt scheme is " | ||
1031 | "incompatible with driver\n", | ||
1032 | netdev->name); | ||
1033 | adapter->driver_mismatch = 1; | ||
1034 | goto err_out_free_hw; | ||
1035 | } | ||
1036 | |||
1072 | if (adapter->fw_major < 4) { | 1037 | if (adapter->fw_major < 4) { |
1073 | adapter->crb_addr_cmd_producer = | 1038 | adapter->crb_addr_cmd_producer = |
1074 | crb_cmd_producer[adapter->portnum]; | 1039 | crb_cmd_producer[adapter->portnum]; |
@@ -1094,7 +1059,7 @@ static int netxen_nic_open(struct net_device *netdev) | |||
1094 | flags, netdev->name, adapter); | 1059 | flags, netdev->name, adapter); |
1095 | if (err) { | 1060 | if (err) { |
1096 | printk(KERN_ERR "request_irq failed with: %d\n", err); | 1061 | printk(KERN_ERR "request_irq failed with: %d\n", err); |
1097 | goto err_out_free_hw; | 1062 | goto err_out_free_rxbuf; |
1098 | } | 1063 | } |
1099 | 1064 | ||
1100 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; | 1065 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; |
@@ -1116,6 +1081,7 @@ static int netxen_nic_open(struct net_device *netdev) | |||
1116 | if (adapter->set_mtu) | 1081 | if (adapter->set_mtu) |
1117 | adapter->set_mtu(adapter, netdev->mtu); | 1082 | adapter->set_mtu(adapter, netdev->mtu); |
1118 | 1083 | ||
1084 | adapter->ahw.linkup = 0; | ||
1119 | mod_timer(&adapter->watchdog_timer, jiffies); | 1085 | mod_timer(&adapter->watchdog_timer, jiffies); |
1120 | 1086 | ||
1121 | napi_enable(&adapter->napi); | 1087 | napi_enable(&adapter->napi); |
@@ -1127,6 +1093,8 @@ static int netxen_nic_open(struct net_device *netdev) | |||
1127 | 1093 | ||
1128 | err_out_free_irq: | 1094 | err_out_free_irq: |
1129 | free_irq(adapter->irq, adapter); | 1095 | free_irq(adapter->irq, adapter); |
1096 | err_out_free_rxbuf: | ||
1097 | netxen_release_rx_buffers(adapter); | ||
1130 | err_out_free_hw: | 1098 | err_out_free_hw: |
1131 | netxen_free_hw_resources(adapter); | 1099 | netxen_free_hw_resources(adapter); |
1132 | err_out_free_sw: | 1100 | err_out_free_sw: |
@@ -1152,10 +1120,8 @@ static int netxen_nic_close(struct net_device *netdev) | |||
1152 | 1120 | ||
1153 | netxen_release_tx_buffers(adapter); | 1121 | netxen_release_tx_buffers(adapter); |
1154 | 1122 | ||
1155 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { | 1123 | FLUSH_SCHEDULED_WORK(); |
1156 | FLUSH_SCHEDULED_WORK(); | 1124 | del_timer_sync(&adapter->watchdog_timer); |
1157 | del_timer_sync(&adapter->watchdog_timer); | ||
1158 | } | ||
1159 | 1125 | ||
1160 | return 0; | 1126 | return 0; |
1161 | } | 1127 | } |
@@ -1458,7 +1424,8 @@ void netxen_watchdog_task(struct work_struct *work) | |||
1458 | 1424 | ||
1459 | netxen_nic_handle_phy_intr(adapter); | 1425 | netxen_nic_handle_phy_intr(adapter); |
1460 | 1426 | ||
1461 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); | 1427 | if (netif_running(adapter->netdev)) |
1428 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); | ||
1462 | } | 1429 | } |
1463 | 1430 | ||
1464 | static void netxen_tx_timeout(struct net_device *netdev) | 1431 | static void netxen_tx_timeout(struct net_device *netdev) |
@@ -1518,18 +1485,9 @@ struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev) | |||
1518 | return stats; | 1485 | return stats; |
1519 | } | 1486 | } |
1520 | 1487 | ||
1521 | static inline void | ||
1522 | netxen_handle_int(struct netxen_adapter *adapter) | ||
1523 | { | ||
1524 | netxen_nic_disable_int(adapter); | ||
1525 | napi_schedule(&adapter->napi); | ||
1526 | } | ||
1527 | |||
1528 | static irqreturn_t netxen_intr(int irq, void *data) | 1488 | static irqreturn_t netxen_intr(int irq, void *data) |
1529 | { | 1489 | { |
1530 | struct netxen_adapter *adapter = data; | 1490 | struct netxen_adapter *adapter = data; |
1531 | u32 our_int = 0; | ||
1532 | |||
1533 | u32 status = 0; | 1491 | u32 status = 0; |
1534 | 1492 | ||
1535 | status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR); | 1493 | status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR); |
@@ -1544,22 +1502,32 @@ static irqreturn_t netxen_intr(int irq, void *data) | |||
1544 | if (!ISR_LEGACY_INT_TRIGGERED(status)) | 1502 | if (!ISR_LEGACY_INT_TRIGGERED(status)) |
1545 | return IRQ_NONE; | 1503 | return IRQ_NONE; |
1546 | 1504 | ||
1547 | } else if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | 1505 | } else { |
1506 | unsigned long our_int = 0; | ||
1548 | 1507 | ||
1549 | our_int = adapter->pci_read_normalize(adapter, CRB_INT_VECTOR); | 1508 | our_int = adapter->pci_read_normalize(adapter, CRB_INT_VECTOR); |
1509 | |||
1550 | /* not our interrupt */ | 1510 | /* not our interrupt */ |
1551 | if ((our_int & (0x80 << adapter->portnum)) == 0) | 1511 | if (!test_and_clear_bit((7 + adapter->portnum), &our_int)) |
1552 | return IRQ_NONE; | 1512 | return IRQ_NONE; |
1553 | 1513 | ||
1554 | if (adapter->intr_scheme == INTR_SCHEME_PERPORT) { | 1514 | /* claim interrupt */ |
1555 | /* claim interrupt */ | 1515 | adapter->pci_write_normalize(adapter, |
1556 | adapter->pci_write_normalize(adapter, | 1516 | CRB_INT_VECTOR, (our_int & 0xffffffff)); |
1557 | CRB_INT_VECTOR, | ||
1558 | our_int & ~((u32)(0x80 << adapter->portnum))); | ||
1559 | } | ||
1560 | } | 1517 | } |
1561 | 1518 | ||
1562 | netxen_handle_int(adapter); | 1519 | /* clear interrupt */ |
1520 | if (adapter->fw_major < 4) | ||
1521 | netxen_nic_disable_int(adapter); | ||
1522 | |||
1523 | adapter->pci_write_immediate(adapter, | ||
1524 | adapter->legacy_intr.tgt_status_reg, | ||
1525 | 0xffffffff); | ||
1526 | /* read twice to ensure write is flushed */ | ||
1527 | adapter->pci_read_immediate(adapter, ISR_INT_VECTOR); | ||
1528 | adapter->pci_read_immediate(adapter, ISR_INT_VECTOR); | ||
1529 | |||
1530 | napi_schedule(&adapter->napi); | ||
1563 | 1531 | ||
1564 | return IRQ_HANDLED; | 1532 | return IRQ_HANDLED; |
1565 | } | 1533 | } |
@@ -1568,7 +1536,11 @@ static irqreturn_t netxen_msi_intr(int irq, void *data) | |||
1568 | { | 1536 | { |
1569 | struct netxen_adapter *adapter = data; | 1537 | struct netxen_adapter *adapter = data; |
1570 | 1538 | ||
1571 | netxen_handle_int(adapter); | 1539 | /* clear interrupt */ |
1540 | adapter->pci_write_immediate(adapter, | ||
1541 | msi_tgt_status[adapter->ahw.pci_func], 0xffffffff); | ||
1542 | |||
1543 | napi_schedule(&adapter->napi); | ||
1572 | return IRQ_HANDLED; | 1544 | return IRQ_HANDLED; |
1573 | } | 1545 | } |
1574 | 1546 | ||