diff options
author | Dhananjay Phadke <dhananjay@netxen.com> | 2009-09-05 13:43:08 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-09-07 04:53:06 -0400 |
commit | 6a581e93981e8838c85e407303186faf937830d3 (patch) | |
tree | 3e2f083971fc33d4a3e88e7cc37e346f775d7168 | |
parent | db4cfd8a6149e778befb2ff6e6f91cdc6394cbe6 (diff) |
netxen: firmware hang detection
Implement state machine to detect firmware hung state
and recover. Since firmware will be shared by all PCI
functions that have different class drivers (NIC or
FCOE or iSCSI), explicit hardware based serialization
is required for initializing firmware.
o Used global scratchpad register to maintain device
reference count. Every probed pci function adds to
ref count.
o Implement timer (delayed work) for each pci func
that checks firmware heartbit every 5 sec and detaches
itself if firmware is dead. Last detaching function
reloads firmware. Other functions wait for firmware
init, and re-attach themselves.
Heartbit is not supported by NX2031 firmware.
Signed-off-by: Amit Kumar Salecha <amit@netxen.com>
Signed-off-by: Dhananjay Phadke <dhananjay@netxen.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/netxen/netxen_nic.h | 17 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_ctx.c | 8 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_hdr.h | 23 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_main.c | 388 |
4 files changed, 348 insertions, 88 deletions
diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h index ede2fa7477ac..30a38163b23b 100644 --- a/drivers/net/netxen/netxen_nic.h +++ b/drivers/net/netxen/netxen_nic.h | |||
@@ -229,6 +229,8 @@ | |||
229 | #define MPORT_SINGLE_FUNCTION_MODE 0x1111 | 229 | #define MPORT_SINGLE_FUNCTION_MODE 0x1111 |
230 | #define MPORT_MULTI_FUNCTION_MODE 0x2222 | 230 | #define MPORT_MULTI_FUNCTION_MODE 0x2222 |
231 | 231 | ||
232 | #define NX_MAX_PCI_FUNC 8 | ||
233 | |||
232 | /* | 234 | /* |
233 | * NetXen host-peg signal message structure | 235 | * NetXen host-peg signal message structure |
234 | * | 236 | * |
@@ -1101,6 +1103,10 @@ typedef struct { | |||
1101 | #define NETXEN_ADAPTER_UP_MAGIC 777 | 1103 | #define NETXEN_ADAPTER_UP_MAGIC 777 |
1102 | #define NETXEN_NIC_PEG_TUNE 0 | 1104 | #define NETXEN_NIC_PEG_TUNE 0 |
1103 | 1105 | ||
1106 | #define __NX_FW_ATTACHED 0 | ||
1107 | #define __NX_DEV_UP 1 | ||
1108 | #define __NX_RESETTING 2 | ||
1109 | |||
1104 | struct netxen_dummy_dma { | 1110 | struct netxen_dummy_dma { |
1105 | void *addr; | 1111 | void *addr; |
1106 | dma_addr_t phys_addr; | 1112 | dma_addr_t phys_addr; |
@@ -1137,7 +1143,9 @@ struct netxen_adapter { | |||
1137 | u8 max_mc_count; | 1143 | u8 max_mc_count; |
1138 | u8 rss_supported; | 1144 | u8 rss_supported; |
1139 | u8 link_changed; | 1145 | u8 link_changed; |
1140 | u32 resv3; | 1146 | u8 fw_wait_cnt; |
1147 | u8 fw_fail_cnt; | ||
1148 | u16 resv4; | ||
1141 | 1149 | ||
1142 | u8 has_link_events; | 1150 | u8 has_link_events; |
1143 | u8 fw_type; | 1151 | u8 fw_type; |
@@ -1156,7 +1164,7 @@ struct netxen_adapter { | |||
1156 | u32 temp; | 1164 | u32 temp; |
1157 | 1165 | ||
1158 | u32 msi_tgt_status; | 1166 | u32 msi_tgt_status; |
1159 | u32 resv4; | 1167 | u32 heartbit; |
1160 | 1168 | ||
1161 | struct netxen_adapter_stats stats; | 1169 | struct netxen_adapter_stats stats; |
1162 | 1170 | ||
@@ -1187,14 +1195,15 @@ struct netxen_adapter { | |||
1187 | 1195 | ||
1188 | struct netxen_dummy_dma dummy_dma; | 1196 | struct netxen_dummy_dma dummy_dma; |
1189 | 1197 | ||
1190 | struct work_struct watchdog_task; | 1198 | struct delayed_work fw_work; |
1191 | struct timer_list watchdog_timer; | 1199 | |
1192 | struct work_struct tx_timeout_task; | 1200 | struct work_struct tx_timeout_task; |
1193 | 1201 | ||
1194 | struct net_device_stats net_stats; | 1202 | struct net_device_stats net_stats; |
1195 | 1203 | ||
1196 | nx_nic_intr_coalesce_t coal; | 1204 | nx_nic_intr_coalesce_t coal; |
1197 | 1205 | ||
1206 | unsigned long state; | ||
1198 | u32 resv5; | 1207 | u32 resv5; |
1199 | u32 fw_version; | 1208 | u32 fw_version; |
1200 | const struct firmware *fw; | 1209 | const struct firmware *fw; |
diff --git a/drivers/net/netxen/netxen_nic_ctx.c b/drivers/net/netxen/netxen_nic_ctx.c index 0f42ab998368..8ab5773e47d6 100644 --- a/drivers/net/netxen/netxen_nic_ctx.c +++ b/drivers/net/netxen/netxen_nic_ctx.c | |||
@@ -678,6 +678,9 @@ int netxen_alloc_hw_resources(struct netxen_adapter *adapter) | |||
678 | 678 | ||
679 | 679 | ||
680 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | 680 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
681 | if (test_and_set_bit(__NX_FW_ATTACHED, &adapter->state)) | ||
682 | goto done; | ||
683 | |||
681 | err = nx_fw_cmd_create_rx_ctx(adapter); | 684 | err = nx_fw_cmd_create_rx_ctx(adapter); |
682 | if (err) | 685 | if (err) |
683 | goto err_out_free; | 686 | goto err_out_free; |
@@ -690,6 +693,7 @@ int netxen_alloc_hw_resources(struct netxen_adapter *adapter) | |||
690 | goto err_out_free; | 693 | goto err_out_free; |
691 | } | 694 | } |
692 | 695 | ||
696 | done: | ||
693 | return 0; | 697 | return 0; |
694 | 698 | ||
695 | err_out_free: | 699 | err_out_free: |
@@ -708,6 +712,9 @@ void netxen_free_hw_resources(struct netxen_adapter *adapter) | |||
708 | int port = adapter->portnum; | 712 | int port = adapter->portnum; |
709 | 713 | ||
710 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | 714 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
715 | if (!test_and_clear_bit(__NX_FW_ATTACHED, &adapter->state)) | ||
716 | goto done; | ||
717 | |||
711 | nx_fw_cmd_destroy_rx_ctx(adapter); | 718 | nx_fw_cmd_destroy_rx_ctx(adapter); |
712 | nx_fw_cmd_destroy_tx_ctx(adapter); | 719 | nx_fw_cmd_destroy_tx_ctx(adapter); |
713 | } else { | 720 | } else { |
@@ -720,6 +727,7 @@ void netxen_free_hw_resources(struct netxen_adapter *adapter) | |||
720 | /* Allow dma queues to drain after context reset */ | 727 | /* Allow dma queues to drain after context reset */ |
721 | msleep(20); | 728 | msleep(20); |
722 | 729 | ||
730 | done: | ||
723 | recv_ctx = &adapter->recv_ctx; | 731 | recv_ctx = &adapter->recv_ctx; |
724 | 732 | ||
725 | if (recv_ctx->hwctx != NULL) { | 733 | if (recv_ctx->hwctx != NULL) { |
diff --git a/drivers/net/netxen/netxen_nic_hdr.h b/drivers/net/netxen/netxen_nic_hdr.h index 92f5970c9aa9..26188b43abe9 100644 --- a/drivers/net/netxen/netxen_nic_hdr.h +++ b/drivers/net/netxen/netxen_nic_hdr.h | |||
@@ -433,6 +433,7 @@ enum { | |||
433 | #define NETXEN_CRB_PEG_NET_1 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN1) | 433 | #define NETXEN_CRB_PEG_NET_1 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN1) |
434 | #define NETXEN_CRB_PEG_NET_2 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN2) | 434 | #define NETXEN_CRB_PEG_NET_2 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN2) |
435 | #define NETXEN_CRB_PEG_NET_3 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN3) | 435 | #define NETXEN_CRB_PEG_NET_3 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGN3) |
436 | #define NETXEN_CRB_PEG_NET_4 NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_SQS2) | ||
436 | #define NETXEN_CRB_PEG_NET_D NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGND) | 437 | #define NETXEN_CRB_PEG_NET_D NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGND) |
437 | #define NETXEN_CRB_PEG_NET_I NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGNI) | 438 | #define NETXEN_CRB_PEG_NET_I NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_PGNI) |
438 | #define NETXEN_CRB_DDR_NET NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_MN) | 439 | #define NETXEN_CRB_DDR_NET NETXEN_PCI_CRB_WINDOW(NETXEN_HW_PX_MAP_CRB_MN) |
@@ -945,6 +946,28 @@ enum { | |||
945 | 946 | ||
946 | #define NETXEN_DMA_WATCHDOG_CTRL (NETXEN_CAM_RAM(0x14)) | 947 | #define NETXEN_DMA_WATCHDOG_CTRL (NETXEN_CAM_RAM(0x14)) |
947 | #define NETXEN_PEG_ALIVE_COUNTER (NETXEN_CAM_RAM(0xb0)) | 948 | #define NETXEN_PEG_ALIVE_COUNTER (NETXEN_CAM_RAM(0xb0)) |
949 | #define NETXEN_PEG_HALT_STATUS1 (NETXEN_CAM_RAM(0xa8)) | ||
950 | #define NETXEN_PEG_HALT_STATUS2 (NETXEN_CAM_RAM(0xac)) | ||
951 | #define NX_CRB_DEV_REF_COUNT (NETXEN_CAM_RAM(0x138)) | ||
952 | #define NX_CRB_DEV_STATE (NETXEN_CAM_RAM(0x140)) | ||
953 | |||
954 | /* Device State */ | ||
955 | #define NX_DEV_COLD 1 | ||
956 | #define NX_DEV_INITALIZING 2 | ||
957 | #define NX_DEV_READY 3 | ||
958 | #define NX_DEV_NEED_RESET 4 | ||
959 | #define NX_DEV_NEED_QUISCENT 5 | ||
960 | #define NX_DEV_FAILED 6 | ||
961 | |||
962 | #define NX_RCODE_DRIVER_INFO 0x20000000 | ||
963 | #define NX_RCODE_DRIVER_CAN_RELOAD 0x40000000 | ||
964 | #define NX_RCODE_FATAL_ERROR 0x80000000 | ||
965 | #define NX_FWERROR_PEGNUM(code) ((code) & 0xff) | ||
966 | #define NX_FWERROR_CODE(code) ((code >> 8) & 0xfffff) | ||
967 | |||
968 | #define FW_POLL_DELAY (2 * HZ) | ||
969 | #define FW_FAIL_THRESH 3 | ||
970 | #define FW_POLL_THRESH 10 | ||
948 | 971 | ||
949 | #define ISR_MSI_INT_TRIGGER(FUNC) (NETXEN_PCIX_PS_REG(PCIX_MSI_F(FUNC))) | 972 | #define ISR_MSI_INT_TRIGGER(FUNC) (NETXEN_PCIX_PS_REG(PCIX_MSI_F(FUNC))) |
950 | #define ISR_LEGACY_INT_TRIGGERED(VAL) (((VAL) & 0x300) == 0x200) | 973 | #define ISR_LEGACY_INT_TRIGGERED(VAL) (((VAL) & 0x300) == 0x200) |
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c index 47aede622035..498943601379 100644 --- a/drivers/net/netxen/netxen_nic_main.c +++ b/drivers/net/netxen/netxen_nic_main.c | |||
@@ -67,7 +67,10 @@ static netdev_tx_t netxen_nic_xmit_frame(struct sk_buff *, | |||
67 | struct net_device *); | 67 | struct net_device *); |
68 | static void netxen_tx_timeout(struct net_device *netdev); | 68 | static void netxen_tx_timeout(struct net_device *netdev); |
69 | static void netxen_reset_task(struct work_struct *work); | 69 | static void netxen_reset_task(struct work_struct *work); |
70 | static void netxen_watchdog(unsigned long); | 70 | static void netxen_fw_poll_work(struct work_struct *work); |
71 | static void netxen_schedule_work(struct netxen_adapter *adapter, | ||
72 | work_func_t func, int delay); | ||
73 | static void netxen_cancel_fw_work(struct netxen_adapter *adapter); | ||
71 | static int netxen_nic_poll(struct napi_struct *napi, int budget); | 74 | static int netxen_nic_poll(struct napi_struct *napi, int budget); |
72 | #ifdef CONFIG_NET_POLL_CONTROLLER | 75 | #ifdef CONFIG_NET_POLL_CONTROLLER |
73 | static void netxen_nic_poll_controller(struct net_device *netdev); | 76 | static void netxen_nic_poll_controller(struct net_device *netdev); |
@@ -76,6 +79,9 @@ static void netxen_nic_poll_controller(struct net_device *netdev); | |||
76 | static void netxen_create_sysfs_entries(struct netxen_adapter *adapter); | 79 | static void netxen_create_sysfs_entries(struct netxen_adapter *adapter); |
77 | static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter); | 80 | static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter); |
78 | 81 | ||
82 | static int nx_decr_dev_ref_cnt(struct netxen_adapter *adapter); | ||
83 | static int netxen_can_start_firmware(struct netxen_adapter *adapter); | ||
84 | |||
79 | static irqreturn_t netxen_intr(int irq, void *data); | 85 | static irqreturn_t netxen_intr(int irq, void *data); |
80 | static irqreturn_t netxen_msi_intr(int irq, void *data); | 86 | static irqreturn_t netxen_msi_intr(int irq, void *data); |
81 | static irqreturn_t netxen_msix_intr(int irq, void *data); | 87 | static irqreturn_t netxen_msix_intr(int irq, void *data); |
@@ -729,19 +735,12 @@ err_out: | |||
729 | } | 735 | } |
730 | 736 | ||
731 | static int | 737 | static int |
732 | netxen_start_firmware(struct netxen_adapter *adapter, int request_fw) | 738 | netxen_start_firmware(struct netxen_adapter *adapter) |
733 | { | 739 | { |
734 | int val, err, first_boot; | 740 | int val, err, first_boot; |
735 | struct pci_dev *pdev = adapter->pdev; | 741 | struct pci_dev *pdev = adapter->pdev; |
736 | 742 | ||
737 | int first_driver = 0; | 743 | if (!netxen_can_start_firmware(adapter)) |
738 | |||
739 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
740 | first_driver = (adapter->portnum == 0); | ||
741 | else | ||
742 | first_driver = (adapter->ahw.pci_func == 0); | ||
743 | |||
744 | if (!first_driver) | ||
745 | goto wait_init; | 744 | goto wait_init; |
746 | 745 | ||
747 | first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc)); | 746 | first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc)); |
@@ -752,8 +751,7 @@ netxen_start_firmware(struct netxen_adapter *adapter, int request_fw) | |||
752 | return err; | 751 | return err; |
753 | } | 752 | } |
754 | 753 | ||
755 | if (request_fw) | 754 | netxen_request_firmware(adapter); |
756 | netxen_request_firmware(adapter); | ||
757 | 755 | ||
758 | err = netxen_need_fw_reset(adapter); | 756 | err = netxen_need_fw_reset(adapter); |
759 | if (err < 0) | 757 | if (err < 0) |
@@ -768,6 +766,9 @@ netxen_start_firmware(struct netxen_adapter *adapter, int request_fw) | |||
768 | } | 766 | } |
769 | 767 | ||
770 | NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555); | 768 | NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555); |
769 | NXWR32(adapter, NETXEN_PEG_HALT_STATUS1, 0); | ||
770 | NXWR32(adapter, NETXEN_PEG_HALT_STATUS2, 0); | ||
771 | |||
771 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | 772 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
772 | netxen_set_port_mode(adapter); | 773 | netxen_set_port_mode(adapter); |
773 | 774 | ||
@@ -775,6 +776,8 @@ netxen_start_firmware(struct netxen_adapter *adapter, int request_fw) | |||
775 | if (err) | 776 | if (err) |
776 | goto err_out; | 777 | goto err_out; |
777 | 778 | ||
779 | netxen_release_firmware(adapter); | ||
780 | |||
778 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | 781 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
779 | 782 | ||
780 | /* Initialize multicast addr pool owners */ | 783 | /* Initialize multicast addr pool owners */ |
@@ -797,6 +800,8 @@ netxen_start_firmware(struct netxen_adapter *adapter, int request_fw) | |||
797 | | (_NETXEN_NIC_LINUX_SUBVERSION); | 800 | | (_NETXEN_NIC_LINUX_SUBVERSION); |
798 | NXWR32(adapter, CRB_DRIVER_VERSION, val); | 801 | NXWR32(adapter, CRB_DRIVER_VERSION, val); |
799 | 802 | ||
803 | NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_READY); | ||
804 | |||
800 | wait_init: | 805 | wait_init: |
801 | /* Handshake with the card before we register the devices. */ | 806 | /* Handshake with the card before we register the devices. */ |
802 | err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); | 807 | err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
@@ -808,6 +813,7 @@ wait_init: | |||
808 | nx_update_dma_mask(adapter); | 813 | nx_update_dma_mask(adapter); |
809 | 814 | ||
810 | netxen_nic_get_firmware_info(adapter); | 815 | netxen_nic_get_firmware_info(adapter); |
816 | netxen_check_options(adapter); | ||
811 | 817 | ||
812 | return 0; | 818 | return 0; |
813 | 819 | ||
@@ -915,8 +921,7 @@ netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev) | |||
915 | else | 921 | else |
916 | netxen_nic_set_link_parameters(adapter); | 922 | netxen_nic_set_link_parameters(adapter); |
917 | 923 | ||
918 | mod_timer(&adapter->watchdog_timer, jiffies); | 924 | set_bit(__NX_DEV_UP, &adapter->state); |
919 | |||
920 | return 0; | 925 | return 0; |
921 | } | 926 | } |
922 | 927 | ||
@@ -926,6 +931,8 @@ netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev) | |||
926 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | 931 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) |
927 | return; | 932 | return; |
928 | 933 | ||
934 | clear_bit(__NX_DEV_UP, &adapter->state); | ||
935 | |||
929 | spin_lock(&adapter->tx_clean_lock); | 936 | spin_lock(&adapter->tx_clean_lock); |
930 | netif_carrier_off(netdev); | 937 | netif_carrier_off(netdev); |
931 | netif_tx_disable(netdev); | 938 | netif_tx_disable(netdev); |
@@ -942,8 +949,6 @@ netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev) | |||
942 | 949 | ||
943 | netxen_release_tx_buffers(adapter); | 950 | netxen_release_tx_buffers(adapter); |
944 | spin_unlock(&adapter->tx_clean_lock); | 951 | spin_unlock(&adapter->tx_clean_lock); |
945 | |||
946 | del_timer_sync(&adapter->watchdog_timer); | ||
947 | } | 952 | } |
948 | 953 | ||
949 | 954 | ||
@@ -974,8 +979,6 @@ netxen_nic_attach(struct netxen_adapter *adapter) | |||
974 | return err; | 979 | return err; |
975 | } | 980 | } |
976 | 981 | ||
977 | netxen_nic_clear_stats(adapter); | ||
978 | |||
979 | err = netxen_alloc_hw_resources(adapter); | 982 | err = netxen_alloc_hw_resources(adapter); |
980 | if (err) { | 983 | if (err) { |
981 | printk(KERN_ERR "%s: Error in setting hw resources\n", | 984 | printk(KERN_ERR "%s: Error in setting hw resources\n", |
@@ -1046,21 +1049,32 @@ netxen_nic_reset_context(struct netxen_adapter *adapter) | |||
1046 | int err = 0; | 1049 | int err = 0; |
1047 | struct net_device *netdev = adapter->netdev; | 1050 | struct net_device *netdev = adapter->netdev; |
1048 | 1051 | ||
1052 | if (test_and_set_bit(__NX_RESETTING, &adapter->state)) | ||
1053 | return -EBUSY; | ||
1054 | |||
1049 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { | 1055 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
1050 | 1056 | ||
1057 | netif_device_detach(netdev); | ||
1058 | |||
1051 | if (netif_running(netdev)) | 1059 | if (netif_running(netdev)) |
1052 | netxen_nic_down(adapter, netdev); | 1060 | netxen_nic_down(adapter, netdev); |
1053 | 1061 | ||
1054 | netxen_nic_detach(adapter); | 1062 | netxen_nic_detach(adapter); |
1055 | 1063 | ||
1056 | err = netxen_nic_attach(adapter); | 1064 | if (netif_running(netdev)) { |
1057 | if (err) | 1065 | err = netxen_nic_attach(adapter); |
1058 | goto done; | 1066 | if (!err) |
1067 | err = netxen_nic_up(adapter, netdev); | ||
1059 | 1068 | ||
1060 | if (netif_running(netdev)) | 1069 | if (err) |
1061 | err = netxen_nic_up(adapter, netdev); | 1070 | goto done; |
1071 | } | ||
1072 | |||
1073 | netif_device_attach(netdev); | ||
1062 | } | 1074 | } |
1075 | |||
1063 | done: | 1076 | done: |
1077 | clear_bit(__NX_RESETTING, &adapter->state); | ||
1064 | return err; | 1078 | return err; |
1065 | } | 1079 | } |
1066 | 1080 | ||
@@ -1107,10 +1121,6 @@ netxen_setup_netdev(struct netxen_adapter *adapter, | |||
1107 | 1121 | ||
1108 | netdev->irq = adapter->msix_entries[0].vector; | 1122 | netdev->irq = adapter->msix_entries[0].vector; |
1109 | 1123 | ||
1110 | init_timer(&adapter->watchdog_timer); | ||
1111 | adapter->watchdog_timer.function = &netxen_watchdog; | ||
1112 | adapter->watchdog_timer.data = (unsigned long)adapter; | ||
1113 | INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task); | ||
1114 | INIT_WORK(&adapter->tx_timeout_task, netxen_reset_task); | 1124 | INIT_WORK(&adapter->tx_timeout_task, netxen_reset_task); |
1115 | 1125 | ||
1116 | if (netxen_read_mac_addr(adapter)) | 1126 | if (netxen_read_mac_addr(adapter)) |
@@ -1214,7 +1224,7 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
1214 | break; | 1224 | break; |
1215 | } | 1225 | } |
1216 | 1226 | ||
1217 | err = netxen_start_firmware(adapter, 1); | 1227 | err = netxen_start_firmware(adapter); |
1218 | if (err) | 1228 | if (err) |
1219 | goto err_out_iounmap; | 1229 | goto err_out_iounmap; |
1220 | 1230 | ||
@@ -1228,7 +1238,7 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
1228 | adapter->physical_port = i; | 1238 | adapter->physical_port = i; |
1229 | } | 1239 | } |
1230 | 1240 | ||
1231 | netxen_check_options(adapter); | 1241 | netxen_nic_clear_stats(adapter); |
1232 | 1242 | ||
1233 | netxen_setup_intr(adapter); | 1243 | netxen_setup_intr(adapter); |
1234 | 1244 | ||
@@ -1238,6 +1248,8 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
1238 | 1248 | ||
1239 | pci_set_drvdata(pdev, adapter); | 1249 | pci_set_drvdata(pdev, adapter); |
1240 | 1250 | ||
1251 | netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); | ||
1252 | |||
1241 | switch (adapter->ahw.port_type) { | 1253 | switch (adapter->ahw.port_type) { |
1242 | case NETXEN_NIC_GBE: | 1254 | case NETXEN_NIC_GBE: |
1243 | dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", | 1255 | dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", |
@@ -1256,6 +1268,8 @@ err_out_disable_msi: | |||
1256 | 1268 | ||
1257 | netxen_free_dummy_dma(adapter); | 1269 | netxen_free_dummy_dma(adapter); |
1258 | 1270 | ||
1271 | nx_decr_dev_ref_cnt(adapter); | ||
1272 | |||
1259 | err_out_iounmap: | 1273 | err_out_iounmap: |
1260 | netxen_cleanup_pci_map(adapter); | 1274 | netxen_cleanup_pci_map(adapter); |
1261 | 1275 | ||
@@ -1282,16 +1296,21 @@ static void __devexit netxen_nic_remove(struct pci_dev *pdev) | |||
1282 | 1296 | ||
1283 | netdev = adapter->netdev; | 1297 | netdev = adapter->netdev; |
1284 | 1298 | ||
1299 | netxen_cancel_fw_work(adapter); | ||
1300 | |||
1285 | unregister_netdev(netdev); | 1301 | unregister_netdev(netdev); |
1286 | 1302 | ||
1287 | cancel_work_sync(&adapter->watchdog_task); | ||
1288 | cancel_work_sync(&adapter->tx_timeout_task); | 1303 | cancel_work_sync(&adapter->tx_timeout_task); |
1289 | 1304 | ||
1290 | netxen_nic_detach(adapter); | 1305 | netxen_nic_detach(adapter); |
1291 | 1306 | ||
1307 | nx_decr_dev_ref_cnt(adapter); | ||
1308 | |||
1292 | if (adapter->portnum == 0) | 1309 | if (adapter->portnum == 0) |
1293 | netxen_free_dummy_dma(adapter); | 1310 | netxen_free_dummy_dma(adapter); |
1294 | 1311 | ||
1312 | clear_bit(__NX_RESETTING, &adapter->state); | ||
1313 | |||
1295 | netxen_teardown_intr(adapter); | 1314 | netxen_teardown_intr(adapter); |
1296 | 1315 | ||
1297 | netxen_cleanup_pci_map(adapter); | 1316 | netxen_cleanup_pci_map(adapter); |
@@ -1312,10 +1331,11 @@ static int __netxen_nic_shutdown(struct pci_dev *pdev) | |||
1312 | 1331 | ||
1313 | netif_device_detach(netdev); | 1332 | netif_device_detach(netdev); |
1314 | 1333 | ||
1334 | netxen_cancel_fw_work(adapter); | ||
1335 | |||
1315 | if (netif_running(netdev)) | 1336 | if (netif_running(netdev)) |
1316 | netxen_nic_down(adapter, netdev); | 1337 | netxen_nic_down(adapter, netdev); |
1317 | 1338 | ||
1318 | cancel_work_sync(&adapter->watchdog_task); | ||
1319 | cancel_work_sync(&adapter->tx_timeout_task); | 1339 | cancel_work_sync(&adapter->tx_timeout_task); |
1320 | 1340 | ||
1321 | netxen_nic_detach(adapter); | 1341 | netxen_nic_detach(adapter); |
@@ -1323,6 +1343,10 @@ static int __netxen_nic_shutdown(struct pci_dev *pdev) | |||
1323 | if (adapter->portnum == 0) | 1343 | if (adapter->portnum == 0) |
1324 | netxen_free_dummy_dma(adapter); | 1344 | netxen_free_dummy_dma(adapter); |
1325 | 1345 | ||
1346 | nx_decr_dev_ref_cnt(adapter); | ||
1347 | |||
1348 | clear_bit(__NX_RESETTING, &adapter->state); | ||
1349 | |||
1326 | retval = pci_save_state(pdev); | 1350 | retval = pci_save_state(pdev); |
1327 | if (retval) | 1351 | if (retval) |
1328 | return retval; | 1352 | return retval; |
@@ -1371,7 +1395,7 @@ netxen_nic_resume(struct pci_dev *pdev) | |||
1371 | 1395 | ||
1372 | adapter->curr_window = 255; | 1396 | adapter->curr_window = 255; |
1373 | 1397 | ||
1374 | err = netxen_start_firmware(adapter, 0); | 1398 | err = netxen_start_firmware(adapter); |
1375 | if (err) { | 1399 | if (err) { |
1376 | dev_err(&pdev->dev, "failed to start firmware\n"); | 1400 | dev_err(&pdev->dev, "failed to start firmware\n"); |
1377 | return err; | 1401 | return err; |
@@ -1380,16 +1404,22 @@ netxen_nic_resume(struct pci_dev *pdev) | |||
1380 | if (netif_running(netdev)) { | 1404 | if (netif_running(netdev)) { |
1381 | err = netxen_nic_attach(adapter); | 1405 | err = netxen_nic_attach(adapter); |
1382 | if (err) | 1406 | if (err) |
1383 | return err; | 1407 | goto err_out; |
1384 | 1408 | ||
1385 | err = netxen_nic_up(adapter, netdev); | 1409 | err = netxen_nic_up(adapter, netdev); |
1386 | if (err) | 1410 | if (err) |
1387 | return err; | 1411 | goto err_out_detach; |
1388 | 1412 | ||
1389 | netif_device_attach(netdev); | 1413 | netif_device_attach(netdev); |
1390 | } | 1414 | } |
1391 | 1415 | ||
1392 | return 0; | 1416 | netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); |
1417 | |||
1418 | err_out_detach: | ||
1419 | netxen_nic_detach(adapter); | ||
1420 | err_out: | ||
1421 | nx_decr_dev_ref_cnt(adapter); | ||
1422 | return err; | ||
1393 | } | 1423 | } |
1394 | #endif | 1424 | #endif |
1395 | 1425 | ||
@@ -1783,59 +1813,13 @@ static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter) | |||
1783 | netxen_advert_link_change(adapter, linkup); | 1813 | netxen_advert_link_change(adapter, linkup); |
1784 | } | 1814 | } |
1785 | 1815 | ||
1786 | static void netxen_nic_thermal_shutdown(struct netxen_adapter *adapter) | ||
1787 | { | ||
1788 | struct net_device *netdev = adapter->netdev; | ||
1789 | |||
1790 | netif_device_detach(netdev); | ||
1791 | netxen_nic_down(adapter, netdev); | ||
1792 | netxen_nic_detach(adapter); | ||
1793 | } | ||
1794 | |||
1795 | static void netxen_watchdog(unsigned long v) | ||
1796 | { | ||
1797 | struct netxen_adapter *adapter = (struct netxen_adapter *)v; | ||
1798 | |||
1799 | if (netxen_nic_check_temp(adapter)) | ||
1800 | goto do_sched; | ||
1801 | |||
1802 | if (!adapter->has_link_events) { | ||
1803 | netxen_nic_handle_phy_intr(adapter); | ||
1804 | |||
1805 | if (adapter->link_changed) | ||
1806 | goto do_sched; | ||
1807 | } | ||
1808 | |||
1809 | if (netif_running(adapter->netdev)) | ||
1810 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); | ||
1811 | |||
1812 | return; | ||
1813 | |||
1814 | do_sched: | ||
1815 | schedule_work(&adapter->watchdog_task); | ||
1816 | } | ||
1817 | |||
1818 | void netxen_watchdog_task(struct work_struct *work) | ||
1819 | { | ||
1820 | struct netxen_adapter *adapter = | ||
1821 | container_of(work, struct netxen_adapter, watchdog_task); | ||
1822 | |||
1823 | if (adapter->temp == NX_TEMP_PANIC) { | ||
1824 | netxen_nic_thermal_shutdown(adapter); | ||
1825 | return; | ||
1826 | } | ||
1827 | |||
1828 | if (adapter->link_changed) | ||
1829 | netxen_nic_set_link_parameters(adapter); | ||
1830 | |||
1831 | if (netif_running(adapter->netdev)) | ||
1832 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); | ||
1833 | } | ||
1834 | |||
1835 | static void netxen_tx_timeout(struct net_device *netdev) | 1816 | static void netxen_tx_timeout(struct net_device *netdev) |
1836 | { | 1817 | { |
1837 | struct netxen_adapter *adapter = netdev_priv(netdev); | 1818 | struct netxen_adapter *adapter = netdev_priv(netdev); |
1838 | 1819 | ||
1820 | if (test_bit(__NX_RESETTING, &adapter->state)) | ||
1821 | return; | ||
1822 | |||
1839 | dev_err(&netdev->dev, "transmit timeout, resetting.\n"); | 1823 | dev_err(&netdev->dev, "transmit timeout, resetting.\n"); |
1840 | schedule_work(&adapter->tx_timeout_task); | 1824 | schedule_work(&adapter->tx_timeout_task); |
1841 | } | 1825 | } |
@@ -1848,6 +1832,9 @@ static void netxen_reset_task(struct work_struct *work) | |||
1848 | if (!netif_running(adapter->netdev)) | 1832 | if (!netif_running(adapter->netdev)) |
1849 | return; | 1833 | return; |
1850 | 1834 | ||
1835 | if (test_bit(__NX_RESETTING, &adapter->state)) | ||
1836 | return; | ||
1837 | |||
1851 | netxen_napi_disable(adapter); | 1838 | netxen_napi_disable(adapter); |
1852 | 1839 | ||
1853 | adapter->netdev->trans_start = jiffies; | 1840 | adapter->netdev->trans_start = jiffies; |
@@ -1974,6 +1961,239 @@ static void netxen_nic_poll_controller(struct net_device *netdev) | |||
1974 | } | 1961 | } |
1975 | #endif | 1962 | #endif |
1976 | 1963 | ||
1964 | static int | ||
1965 | nx_incr_dev_ref_cnt(struct netxen_adapter *adapter) | ||
1966 | { | ||
1967 | int count; | ||
1968 | if (netxen_api_lock(adapter)) | ||
1969 | return -EIO; | ||
1970 | |||
1971 | count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); | ||
1972 | |||
1973 | NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count); | ||
1974 | |||
1975 | netxen_api_unlock(adapter); | ||
1976 | return count; | ||
1977 | } | ||
1978 | |||
1979 | static int | ||
1980 | nx_decr_dev_ref_cnt(struct netxen_adapter *adapter) | ||
1981 | { | ||
1982 | int count; | ||
1983 | if (netxen_api_lock(adapter)) | ||
1984 | return -EIO; | ||
1985 | |||
1986 | count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); | ||
1987 | WARN_ON(count == 0); | ||
1988 | |||
1989 | NXWR32(adapter, NX_CRB_DEV_REF_COUNT, --count); | ||
1990 | |||
1991 | if (count == 0) | ||
1992 | NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_COLD); | ||
1993 | |||
1994 | netxen_api_unlock(adapter); | ||
1995 | return count; | ||
1996 | } | ||
1997 | |||
1998 | static int | ||
1999 | netxen_can_start_firmware(struct netxen_adapter *adapter) | ||
2000 | { | ||
2001 | int count; | ||
2002 | int can_start = 0; | ||
2003 | |||
2004 | if (netxen_api_lock(adapter)) | ||
2005 | return 0; | ||
2006 | |||
2007 | count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); | ||
2008 | |||
2009 | if ((count < 0) || (count >= NX_MAX_PCI_FUNC)) | ||
2010 | count = 0; | ||
2011 | |||
2012 | if (count == 0) { | ||
2013 | can_start = 1; | ||
2014 | NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_INITALIZING); | ||
2015 | } | ||
2016 | |||
2017 | NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count); | ||
2018 | |||
2019 | netxen_api_unlock(adapter); | ||
2020 | |||
2021 | return can_start; | ||
2022 | } | ||
2023 | |||
2024 | static void | ||
2025 | netxen_schedule_work(struct netxen_adapter *adapter, | ||
2026 | work_func_t func, int delay) | ||
2027 | { | ||
2028 | INIT_DELAYED_WORK(&adapter->fw_work, func); | ||
2029 | schedule_delayed_work(&adapter->fw_work, delay); | ||
2030 | } | ||
2031 | |||
2032 | static void | ||
2033 | netxen_cancel_fw_work(struct netxen_adapter *adapter) | ||
2034 | { | ||
2035 | while (test_and_set_bit(__NX_RESETTING, &adapter->state)) | ||
2036 | msleep(10); | ||
2037 | |||
2038 | cancel_delayed_work_sync(&adapter->fw_work); | ||
2039 | } | ||
2040 | |||
2041 | static void | ||
2042 | netxen_attach_work(struct work_struct *work) | ||
2043 | { | ||
2044 | struct netxen_adapter *adapter = container_of(work, | ||
2045 | struct netxen_adapter, fw_work.work); | ||
2046 | struct net_device *netdev = adapter->netdev; | ||
2047 | int err = 0; | ||
2048 | |||
2049 | if (netif_running(netdev)) { | ||
2050 | err = netxen_nic_attach(adapter); | ||
2051 | if (err) | ||
2052 | goto done; | ||
2053 | |||
2054 | err = netxen_nic_up(adapter, netdev); | ||
2055 | if (err) { | ||
2056 | netxen_nic_detach(adapter); | ||
2057 | goto done; | ||
2058 | } | ||
2059 | |||
2060 | } | ||
2061 | |||
2062 | netif_device_attach(netdev); | ||
2063 | |||
2064 | done: | ||
2065 | adapter->fw_fail_cnt = 0; | ||
2066 | clear_bit(__NX_RESETTING, &adapter->state); | ||
2067 | netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); | ||
2068 | } | ||
2069 | |||
2070 | static void | ||
2071 | netxen_fwinit_work(struct work_struct *work) | ||
2072 | { | ||
2073 | struct netxen_adapter *adapter = container_of(work, | ||
2074 | struct netxen_adapter, fw_work.work); | ||
2075 | int dev_state; | ||
2076 | |||
2077 | dev_state = NXRD32(adapter, NX_CRB_DEV_STATE); | ||
2078 | |||
2079 | switch (dev_state) { | ||
2080 | case NX_DEV_COLD: | ||
2081 | case NX_DEV_READY: | ||
2082 | netxen_start_firmware(adapter); | ||
2083 | netxen_schedule_work(adapter, netxen_attach_work, 0); | ||
2084 | return; | ||
2085 | |||
2086 | case NX_DEV_INITALIZING: | ||
2087 | if (++adapter->fw_wait_cnt < FW_POLL_THRESH) { | ||
2088 | netxen_schedule_work(adapter, | ||
2089 | netxen_fwinit_work, 2 * FW_POLL_DELAY); | ||
2090 | return; | ||
2091 | } | ||
2092 | break; | ||
2093 | |||
2094 | case NX_DEV_FAILED: | ||
2095 | default: | ||
2096 | break; | ||
2097 | } | ||
2098 | |||
2099 | nx_incr_dev_ref_cnt(adapter); | ||
2100 | clear_bit(__NX_RESETTING, &adapter->state); | ||
2101 | } | ||
2102 | |||
2103 | static void | ||
2104 | netxen_detach_work(struct work_struct *work) | ||
2105 | { | ||
2106 | struct netxen_adapter *adapter = container_of(work, | ||
2107 | struct netxen_adapter, fw_work.work); | ||
2108 | struct net_device *netdev = adapter->netdev; | ||
2109 | int ref_cnt, delay; | ||
2110 | u32 status; | ||
2111 | |||
2112 | netif_device_detach(netdev); | ||
2113 | |||
2114 | if (netif_running(netdev)) | ||
2115 | netxen_nic_down(adapter, netdev); | ||
2116 | |||
2117 | netxen_nic_detach(adapter); | ||
2118 | |||
2119 | status = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1); | ||
2120 | |||
2121 | ref_cnt = nx_decr_dev_ref_cnt(adapter); | ||
2122 | |||
2123 | if (status & NX_RCODE_FATAL_ERROR) | ||
2124 | return; | ||
2125 | |||
2126 | if (adapter->temp == NX_TEMP_PANIC) | ||
2127 | return; | ||
2128 | |||
2129 | delay = (ref_cnt == 0) ? 0 : (2 * FW_POLL_DELAY); | ||
2130 | |||
2131 | adapter->fw_wait_cnt = 0; | ||
2132 | netxen_schedule_work(adapter, netxen_fwinit_work, delay); | ||
2133 | } | ||
2134 | |||
2135 | static int | ||
2136 | netxen_check_health(struct netxen_adapter *adapter) | ||
2137 | { | ||
2138 | u32 state, heartbit; | ||
2139 | struct net_device *netdev = adapter->netdev; | ||
2140 | |||
2141 | if (netxen_nic_check_temp(adapter)) | ||
2142 | goto detach; | ||
2143 | |||
2144 | state = NXRD32(adapter, NX_CRB_DEV_STATE); | ||
2145 | if (state == NX_DEV_NEED_RESET) | ||
2146 | goto detach; | ||
2147 | |||
2148 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | ||
2149 | return 0; | ||
2150 | |||
2151 | heartbit = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); | ||
2152 | if (heartbit != adapter->heartbit) { | ||
2153 | adapter->heartbit = heartbit; | ||
2154 | adapter->fw_fail_cnt = 0; | ||
2155 | return 0; | ||
2156 | } | ||
2157 | |||
2158 | if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) | ||
2159 | return 0; | ||
2160 | |||
2161 | clear_bit(__NX_FW_ATTACHED, &adapter->state); | ||
2162 | |||
2163 | dev_info(&netdev->dev, "firmware hang detected\n"); | ||
2164 | |||
2165 | detach: | ||
2166 | if (!test_and_set_bit(__NX_RESETTING, &adapter->state)) | ||
2167 | netxen_schedule_work(adapter, netxen_detach_work, 0); | ||
2168 | return 1; | ||
2169 | } | ||
2170 | |||
2171 | static void | ||
2172 | netxen_fw_poll_work(struct work_struct *work) | ||
2173 | { | ||
2174 | struct netxen_adapter *adapter = container_of(work, | ||
2175 | struct netxen_adapter, fw_work.work); | ||
2176 | |||
2177 | if (test_bit(__NX_RESETTING, &adapter->state)) | ||
2178 | goto reschedule; | ||
2179 | |||
2180 | if (test_bit(__NX_DEV_UP, &adapter->state)) { | ||
2181 | if (!adapter->has_link_events) { | ||
2182 | |||
2183 | netxen_nic_handle_phy_intr(adapter); | ||
2184 | |||
2185 | if (adapter->link_changed) | ||
2186 | netxen_nic_set_link_parameters(adapter); | ||
2187 | } | ||
2188 | } | ||
2189 | |||
2190 | if (netxen_check_health(adapter)) | ||
2191 | return; | ||
2192 | |||
2193 | reschedule: | ||
2194 | netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); | ||
2195 | } | ||
2196 | |||
1977 | static ssize_t | 2197 | static ssize_t |
1978 | netxen_store_bridged_mode(struct device *dev, | 2198 | netxen_store_bridged_mode(struct device *dev, |
1979 | struct device_attribute *attr, const char *buf, size_t len) | 2199 | struct device_attribute *attr, const char *buf, size_t len) |