Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1 | /* |
Dhananjay Phadke | 5d242f1 | 2009-02-25 15:57:56 +0000 | [diff] [blame] | 2 | * Copyright (C) 2003 - 2009 NetXen, Inc. |
Dhananjay Phadke | 13af7a6 | 2009-09-11 11:28:15 +0000 | [diff] [blame] | 3 | * Copyright (C) 2009 - QLogic Corporation. |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 4 | * All rights reserved. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 5 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 10 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 15 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 19 | * MA 02111-1307, USA. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 20 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 21 | * The full GNU General Public License is included in this distribution |
| 22 | * in the file called LICENSE. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 23 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 24 | */ |
| 25 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 26 | #include <linux/vmalloc.h> |
Dhananjay Phadke | e98e335 | 2009-04-07 22:50:38 +0000 | [diff] [blame] | 27 | #include <linux/interrupt.h> |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 28 | #include "netxen_nic_hw.h" |
| 29 | |
| 30 | #include "netxen_nic.h" |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 31 | |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 32 | #include <linux/dma-mapping.h> |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 33 | #include <linux/if_vlan.h> |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 34 | #include <net/ip.h> |
Dhananjay Phadke | 0097778 | 2009-01-16 11:03:25 -0800 | [diff] [blame] | 35 | #include <linux/ipv6.h> |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 36 | #include <linux/inetdevice.h> |
Randy Dunlap | 0531d7b8 | 2009-10-26 12:09:45 +0000 | [diff] [blame] | 37 | #include <linux/sysfs.h> |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 38 | |
Dhananjay Phadke | c25c0b9 | 2009-10-28 04:11:04 -0700 | [diff] [blame] | 39 | MODULE_DESCRIPTION("QLogic/NetXen (1/10) GbE Converged Ethernet Driver"); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 40 | MODULE_LICENSE("GPL"); |
| 41 | MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID); |
Dhananjay Phadke | 7e8e5d9 | 2009-10-24 16:04:02 +0000 | [diff] [blame] | 42 | MODULE_FIRMWARE(NX_P2_MN_ROMIMAGE_NAME); |
| 43 | MODULE_FIRMWARE(NX_P3_CT_ROMIMAGE_NAME); |
| 44 | MODULE_FIRMWARE(NX_P3_MN_ROMIMAGE_NAME); |
| 45 | MODULE_FIRMWARE(NX_UNIFIED_ROMIMAGE_NAME); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 46 | |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 47 | char netxen_nic_driver_name[] = "netxen_nic"; |
Dhananjay Phadke | c25c0b9 | 2009-10-28 04:11:04 -0700 | [diff] [blame] | 48 | static char netxen_nic_driver_string[] = "QLogic/NetXen Network Driver v" |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 49 | NETXEN_NIC_LINUX_VERSIONID; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 50 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 51 | static int port_mode = NETXEN_PORT_MODE_AUTO_NEG; |
| 52 | |
| 53 | /* Default to restricted 1G auto-neg mode */ |
| 54 | static int wol_port_mode = 5; |
| 55 | |
| 56 | static int use_msi = 1; |
| 57 | |
| 58 | static int use_msi_x = 1; |
| 59 | |
Narender Kumar | caa2dd5 | 2009-10-16 15:50:11 +0000 | [diff] [blame] | 60 | static unsigned long auto_fw_reset = AUTO_FW_RESET_ENABLED; |
| 61 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 62 | static int __devinit netxen_nic_probe(struct pci_dev *pdev, |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 63 | const struct pci_device_id *ent); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 64 | static void __devexit netxen_nic_remove(struct pci_dev *pdev); |
| 65 | static int netxen_nic_open(struct net_device *netdev); |
| 66 | static int netxen_nic_close(struct net_device *netdev); |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 67 | static netdev_tx_t netxen_nic_xmit_frame(struct sk_buff *, |
| 68 | struct net_device *); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 69 | static void netxen_tx_timeout(struct net_device *netdev); |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 70 | static void netxen_tx_timeout_task(struct work_struct *work); |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 71 | static void netxen_fw_poll_work(struct work_struct *work); |
| 72 | static void netxen_schedule_work(struct netxen_adapter *adapter, |
| 73 | work_func_t func, int delay); |
| 74 | static void netxen_cancel_fw_work(struct netxen_adapter *adapter); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 75 | static int netxen_nic_poll(struct napi_struct *napi, int budget); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 76 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 77 | static void netxen_nic_poll_controller(struct net_device *netdev); |
| 78 | #endif |
Narender Kumar | fa3ce35 | 2009-08-24 19:23:28 +0000 | [diff] [blame] | 79 | |
| 80 | static void netxen_create_sysfs_entries(struct netxen_adapter *adapter); |
| 81 | static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter); |
Dhananjay Phadke | 70f9cf8 | 2009-10-13 05:31:45 +0000 | [diff] [blame] | 82 | static void netxen_create_diag_entries(struct netxen_adapter *adapter); |
| 83 | static void netxen_remove_diag_entries(struct netxen_adapter *adapter); |
Narender Kumar | fa3ce35 | 2009-08-24 19:23:28 +0000 | [diff] [blame] | 84 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 85 | static int nx_decr_dev_ref_cnt(struct netxen_adapter *adapter); |
| 86 | static int netxen_can_start_firmware(struct netxen_adapter *adapter); |
| 87 | |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 88 | static irqreturn_t netxen_intr(int irq, void *data); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 89 | static irqreturn_t netxen_msi_intr(int irq, void *data); |
Dhananjay Phadke | b3df68f | 2009-02-08 19:20:19 -0800 | [diff] [blame] | 90 | static irqreturn_t netxen_msix_intr(int irq, void *data); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 91 | |
Amit Kumar Salecha | d0725e4 | 2009-09-05 17:43:09 +0000 | [diff] [blame] | 92 | static void netxen_config_indev_addr(struct net_device *dev, unsigned long); |
| 93 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 94 | /* PCI Device ID Table */ |
Al Viro | 70081ac | 2008-06-23 02:04:50 +0100 | [diff] [blame] | 95 | #define ENTRY(device) \ |
Dhananjay Phadke | 040dec3 | 2008-09-12 06:55:14 -0700 | [diff] [blame] | 96 | {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \ |
Al Viro | 70081ac | 2008-06-23 02:04:50 +0100 | [diff] [blame] | 97 | .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} |
| 98 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 99 | static struct pci_device_id netxen_pci_tbl[] __devinitdata = { |
Dhananjay Phadke | 040dec3 | 2008-09-12 06:55:14 -0700 | [diff] [blame] | 100 | ENTRY(PCI_DEVICE_ID_NX2031_10GXSR), |
| 101 | ENTRY(PCI_DEVICE_ID_NX2031_10GCX4), |
| 102 | ENTRY(PCI_DEVICE_ID_NX2031_4GCU), |
| 103 | ENTRY(PCI_DEVICE_ID_NX2031_IMEZ), |
| 104 | ENTRY(PCI_DEVICE_ID_NX2031_HMEZ), |
| 105 | ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT), |
| 106 | ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2), |
| 107 | ENTRY(PCI_DEVICE_ID_NX3031), |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 108 | {0,} |
| 109 | }; |
| 110 | |
| 111 | MODULE_DEVICE_TABLE(pci, netxen_pci_tbl); |
| 112 | |
Dhananjay Phadke | 7830b22 | 2008-07-21 19:44:00 -0700 | [diff] [blame] | 113 | static uint32_t crb_cmd_producer[4] = { |
| 114 | CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1, |
| 115 | CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3 |
| 116 | }; |
| 117 | |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 118 | void |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 119 | netxen_nic_update_cmd_producer(struct netxen_adapter *adapter, |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 120 | struct nx_host_tx_ring *tx_ring) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 121 | { |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 122 | NXWRIO(adapter, tx_ring->crb_cmd_producer, tx_ring->producer); |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 123 | |
| 124 | if (netxen_tx_avail(tx_ring) <= TX_STOP_THRESH) { |
| 125 | netif_stop_queue(adapter->netdev); |
| 126 | smp_mb(); |
| 127 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Dhananjay Phadke | 7830b22 | 2008-07-21 19:44:00 -0700 | [diff] [blame] | 130 | static uint32_t crb_cmd_consumer[4] = { |
| 131 | CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1, |
| 132 | CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3 |
| 133 | }; |
| 134 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 135 | static inline void |
| 136 | netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter, |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 137 | struct nx_host_tx_ring *tx_ring) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 138 | { |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 139 | NXWRIO(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 142 | static uint32_t msi_tgt_status[8] = { |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 143 | ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 144 | ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, |
| 145 | ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, |
| 146 | ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7 |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 147 | }; |
| 148 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 149 | static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG; |
| 150 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 151 | static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring) |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 152 | { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 153 | struct netxen_adapter *adapter = sds_ring->adapter; |
| 154 | |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 155 | NXWRIO(adapter, sds_ring->crb_intr_mask, 0); |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 158 | static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring) |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 159 | { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 160 | struct netxen_adapter *adapter = sds_ring->adapter; |
| 161 | |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 162 | NXWRIO(adapter, sds_ring->crb_intr_mask, 0x1); |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 163 | |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 164 | if (!NETXEN_IS_MSI_FAMILY(adapter)) |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 165 | NXWRIO(adapter, adapter->tgt_mask_reg, 0xfbff); |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Dhananjay Phadke | 71dcddb | 2009-04-07 22:50:43 +0000 | [diff] [blame] | 168 | static int |
| 169 | netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count) |
| 170 | { |
| 171 | int size = sizeof(struct nx_host_sds_ring) * count; |
| 172 | |
| 173 | recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL); |
| 174 | |
| 175 | return (recv_ctx->sds_rings == NULL); |
| 176 | } |
| 177 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 178 | static void |
Dhananjay Phadke | 71dcddb | 2009-04-07 22:50:43 +0000 | [diff] [blame] | 179 | netxen_free_sds_rings(struct netxen_recv_context *recv_ctx) |
| 180 | { |
| 181 | if (recv_ctx->sds_rings != NULL) |
| 182 | kfree(recv_ctx->sds_rings); |
Dhananjay Phadke | 232e7d6 | 2009-08-13 07:03:01 +0000 | [diff] [blame] | 183 | |
| 184 | recv_ctx->sds_rings = NULL; |
Dhananjay Phadke | 71dcddb | 2009-04-07 22:50:43 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | static int |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 188 | netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev) |
| 189 | { |
| 190 | int ring; |
| 191 | struct nx_host_sds_ring *sds_ring; |
| 192 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; |
| 193 | |
Dhananjay Phadke | 71dcddb | 2009-04-07 22:50:43 +0000 | [diff] [blame] | 194 | if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings)) |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 195 | return -ENOMEM; |
Dhananjay Phadke | 71dcddb | 2009-04-07 22:50:43 +0000 | [diff] [blame] | 196 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 197 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 198 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 199 | netif_napi_add(netdev, &sds_ring->napi, |
| 200 | netxen_nic_poll, NETXEN_NETDEV_WEIGHT); |
| 201 | } |
Dhananjay Phadke | 71dcddb | 2009-04-07 22:50:43 +0000 | [diff] [blame] | 202 | |
| 203 | return 0; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static void |
Dhananjay Phadke | 232e7d6 | 2009-08-13 07:03:01 +0000 | [diff] [blame] | 207 | netxen_napi_del(struct netxen_adapter *adapter) |
| 208 | { |
| 209 | int ring; |
| 210 | struct nx_host_sds_ring *sds_ring; |
| 211 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; |
| 212 | |
| 213 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 214 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 215 | netif_napi_del(&sds_ring->napi); |
| 216 | } |
| 217 | |
| 218 | netxen_free_sds_rings(&adapter->recv_ctx); |
| 219 | } |
| 220 | |
| 221 | static void |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 222 | netxen_napi_enable(struct netxen_adapter *adapter) |
| 223 | { |
| 224 | int ring; |
| 225 | struct nx_host_sds_ring *sds_ring; |
| 226 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; |
| 227 | |
| 228 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 229 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 230 | napi_enable(&sds_ring->napi); |
| 231 | netxen_nic_enable_int(sds_ring); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | static void |
| 236 | netxen_napi_disable(struct netxen_adapter *adapter) |
| 237 | { |
| 238 | int ring; |
| 239 | struct nx_host_sds_ring *sds_ring; |
| 240 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; |
| 241 | |
| 242 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 243 | sds_ring = &recv_ctx->sds_rings[ring]; |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 244 | netxen_nic_disable_int(sds_ring); |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 245 | napi_synchronize(&sds_ring->napi); |
| 246 | napi_disable(&sds_ring->napi); |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
Dhananjay Phadke | 50c643e | 2009-08-01 21:36:16 +0000 | [diff] [blame] | 250 | static int nx_set_dma_mask(struct netxen_adapter *adapter) |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 251 | { |
| 252 | struct pci_dev *pdev = adapter->pdev; |
Dhananjay Phadke | 1f434f6 | 2009-03-02 16:02:16 +0000 | [diff] [blame] | 253 | uint64_t mask, cmask; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 254 | |
Dhananjay Phadke | 1f434f6 | 2009-03-02 16:02:16 +0000 | [diff] [blame] | 255 | adapter->pci_using_dac = 0; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 256 | |
Yang Hongyang | 6afd142 | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 257 | mask = DMA_BIT_MASK(32); |
Yang Hongyang | 6afd142 | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 258 | cmask = DMA_BIT_MASK(32); |
Dhananjay Phadke | 1f434f6 | 2009-03-02 16:02:16 +0000 | [diff] [blame] | 259 | |
Dhananjay Phadke | 50c643e | 2009-08-01 21:36:16 +0000 | [diff] [blame] | 260 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
Dhananjay Phadke | 1f434f6 | 2009-03-02 16:02:16 +0000 | [diff] [blame] | 261 | #ifndef CONFIG_IA64 |
Yang Hongyang | 6afd142 | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 262 | mask = DMA_BIT_MASK(35); |
Dhananjay Phadke | 1f434f6 | 2009-03-02 16:02:16 +0000 | [diff] [blame] | 263 | #endif |
Dhananjay Phadke | 50c643e | 2009-08-01 21:36:16 +0000 | [diff] [blame] | 264 | } else { |
| 265 | mask = DMA_BIT_MASK(39); |
| 266 | cmask = mask; |
| 267 | } |
| 268 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 269 | if (pci_set_dma_mask(pdev, mask) == 0 && |
Dhananjay Phadke | 1f434f6 | 2009-03-02 16:02:16 +0000 | [diff] [blame] | 270 | pci_set_consistent_dma_mask(pdev, cmask) == 0) { |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 271 | adapter->pci_using_dac = 1; |
| 272 | return 0; |
| 273 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 274 | |
Dhananjay Phadke | 1f434f6 | 2009-03-02 16:02:16 +0000 | [diff] [blame] | 275 | return -EIO; |
| 276 | } |
| 277 | |
| 278 | /* Update addressable range if firmware supports it */ |
| 279 | static int |
| 280 | nx_update_dma_mask(struct netxen_adapter *adapter) |
| 281 | { |
| 282 | int change, shift, err; |
Dhananjay Phadke | 50c643e | 2009-08-01 21:36:16 +0000 | [diff] [blame] | 283 | uint64_t mask, old_mask, old_cmask; |
Dhananjay Phadke | 1f434f6 | 2009-03-02 16:02:16 +0000 | [diff] [blame] | 284 | struct pci_dev *pdev = adapter->pdev; |
| 285 | |
| 286 | change = 0; |
| 287 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 288 | shift = NXRD32(adapter, CRB_DMA_SHIFT); |
Dhananjay Phadke | f60f785 | 2009-08-04 10:39:03 +0000 | [diff] [blame] | 289 | if (shift > 32) |
Dhananjay Phadke | 1f434f6 | 2009-03-02 16:02:16 +0000 | [diff] [blame] | 290 | return 0; |
| 291 | |
| 292 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9)) |
| 293 | change = 1; |
| 294 | else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4)) |
| 295 | change = 1; |
| 296 | |
| 297 | if (change) { |
| 298 | old_mask = pdev->dma_mask; |
Dhananjay Phadke | 50c643e | 2009-08-01 21:36:16 +0000 | [diff] [blame] | 299 | old_cmask = pdev->dev.coherent_dma_mask; |
| 300 | |
Dhananjay Phadke | f60f785 | 2009-08-04 10:39:03 +0000 | [diff] [blame] | 301 | mask = DMA_BIT_MASK(32+shift); |
Dhananjay Phadke | 1f434f6 | 2009-03-02 16:02:16 +0000 | [diff] [blame] | 302 | |
| 303 | err = pci_set_dma_mask(pdev, mask); |
| 304 | if (err) |
Dhananjay Phadke | 50c643e | 2009-08-01 21:36:16 +0000 | [diff] [blame] | 305 | goto err_out; |
| 306 | |
| 307 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
| 308 | |
| 309 | err = pci_set_consistent_dma_mask(pdev, mask); |
| 310 | if (err) |
| 311 | goto err_out; |
| 312 | } |
| 313 | dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 316 | return 0; |
Dhananjay Phadke | 50c643e | 2009-08-01 21:36:16 +0000 | [diff] [blame] | 317 | |
| 318 | err_out: |
| 319 | pci_set_dma_mask(pdev, old_mask); |
| 320 | pci_set_consistent_dma_mask(pdev, old_cmask); |
| 321 | return err; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 324 | static int |
| 325 | netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot) |
| 326 | { |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 327 | u32 val, timeout; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 328 | |
| 329 | if (first_boot == 0x55555555) { |
| 330 | /* This is the first boot after power up */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 331 | NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC); |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 332 | |
| 333 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 334 | return 0; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 335 | |
| 336 | /* PCI bus master workaround */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 337 | first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4)); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 338 | if (!(first_boot & 0x4)) { |
| 339 | first_boot |= 0x4; |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 340 | NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot); |
| 341 | first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4)); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /* This is the first boot after power up */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 345 | first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 346 | if (first_boot != 0x80000f) { |
| 347 | /* clear the register for future unloads/loads */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 348 | NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0); |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 349 | return -EIO; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 352 | /* Start P2 boot loader */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 353 | val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE); |
| 354 | NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1); |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 355 | timeout = 0; |
| 356 | do { |
| 357 | msleep(1); |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 358 | val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc)); |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 359 | |
| 360 | if (++timeout > 5000) |
| 361 | return -EIO; |
| 362 | |
| 363 | } while (val == NETXEN_BDINFO_MAGIC); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 364 | } |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 365 | return 0; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | static void netxen_set_port_mode(struct netxen_adapter *adapter) |
| 369 | { |
| 370 | u32 val, data; |
| 371 | |
Dhananjay Phadke | 1e2d005 | 2009-03-09 08:50:56 +0000 | [diff] [blame] | 372 | val = adapter->ahw.board_type; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 373 | if ((val == NETXEN_BRDTYPE_P3_HMEZ) || |
| 374 | (val == NETXEN_BRDTYPE_P3_XG_LOM)) { |
| 375 | if (port_mode == NETXEN_PORT_MODE_802_3_AP) { |
| 376 | data = NETXEN_PORT_MODE_802_3_AP; |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 377 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 378 | } else if (port_mode == NETXEN_PORT_MODE_XG) { |
| 379 | data = NETXEN_PORT_MODE_XG; |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 380 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 381 | } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) { |
| 382 | data = NETXEN_PORT_MODE_AUTO_NEG_1G; |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 383 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 384 | } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) { |
| 385 | data = NETXEN_PORT_MODE_AUTO_NEG_XG; |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 386 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 387 | } else { |
| 388 | data = NETXEN_PORT_MODE_AUTO_NEG; |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 389 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) && |
| 393 | (wol_port_mode != NETXEN_PORT_MODE_XG) && |
| 394 | (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) && |
| 395 | (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) { |
| 396 | wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG; |
| 397 | } |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 398 | NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 402 | static void netxen_set_msix_bit(struct pci_dev *pdev, int enable) |
| 403 | { |
| 404 | u32 control; |
| 405 | int pos; |
| 406 | |
| 407 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 408 | if (pos) { |
| 409 | pci_read_config_dword(pdev, pos, &control); |
| 410 | if (enable) |
| 411 | control |= PCI_MSIX_FLAGS_ENABLE; |
| 412 | else |
| 413 | control = 0; |
| 414 | pci_write_config_dword(pdev, pos, control); |
| 415 | } |
| 416 | } |
| 417 | |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 418 | static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count) |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 419 | { |
| 420 | int i; |
| 421 | |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 422 | for (i = 0; i < count; i++) |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 423 | adapter->msix_entries[i].entry = i; |
| 424 | } |
| 425 | |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 426 | static int |
| 427 | netxen_read_mac_addr(struct netxen_adapter *adapter) |
| 428 | { |
| 429 | int i; |
| 430 | unsigned char *p; |
| 431 | __le64 mac_addr; |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 432 | struct net_device *netdev = adapter->netdev; |
| 433 | struct pci_dev *pdev = adapter->pdev; |
| 434 | |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 435 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
| 436 | if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0) |
| 437 | return -EIO; |
| 438 | } else { |
| 439 | if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0) |
| 440 | return -EIO; |
| 441 | } |
| 442 | |
| 443 | p = (unsigned char *)&mac_addr; |
| 444 | for (i = 0; i < 6; i++) |
| 445 | netdev->dev_addr[i] = *(p + 5 - i); |
| 446 | |
| 447 | memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len); |
Narender Kumar | 5d09e53 | 2009-11-20 22:08:57 +0000 | [diff] [blame] | 448 | memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len); |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 449 | |
| 450 | /* set station address */ |
| 451 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 452 | if (!is_valid_ether_addr(netdev->perm_addr)) |
| 453 | dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr); |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
Dhananjay Phadke | 3d0a3cc | 2009-05-05 19:05:08 +0000 | [diff] [blame] | 458 | int netxen_nic_set_mac(struct net_device *netdev, void *p) |
| 459 | { |
| 460 | struct netxen_adapter *adapter = netdev_priv(netdev); |
| 461 | struct sockaddr *addr = p; |
| 462 | |
| 463 | if (!is_valid_ether_addr(addr->sa_data)) |
| 464 | return -EINVAL; |
| 465 | |
| 466 | if (netif_running(netdev)) { |
| 467 | netif_device_detach(netdev); |
| 468 | netxen_napi_disable(adapter); |
| 469 | } |
| 470 | |
Narender Kumar | 5d09e53 | 2009-11-20 22:08:57 +0000 | [diff] [blame] | 471 | memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len); |
Dhananjay Phadke | 3d0a3cc | 2009-05-05 19:05:08 +0000 | [diff] [blame] | 472 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 473 | adapter->macaddr_set(adapter, addr->sa_data); |
| 474 | |
| 475 | if (netif_running(netdev)) { |
| 476 | netif_device_attach(netdev); |
| 477 | netxen_napi_enable(adapter); |
| 478 | } |
| 479 | return 0; |
| 480 | } |
| 481 | |
Stephen Hemminger | 1abd266 | 2008-11-21 17:32:15 -0800 | [diff] [blame] | 482 | static void netxen_set_multicast_list(struct net_device *dev) |
| 483 | { |
| 484 | struct netxen_adapter *adapter = netdev_priv(dev); |
| 485 | |
Dhananjay Phadke | 3d0a3cc | 2009-05-05 19:05:08 +0000 | [diff] [blame] | 486 | adapter->set_multi(dev); |
Stephen Hemminger | 1abd266 | 2008-11-21 17:32:15 -0800 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | static const struct net_device_ops netxen_netdev_ops = { |
| 490 | .ndo_open = netxen_nic_open, |
| 491 | .ndo_stop = netxen_nic_close, |
| 492 | .ndo_start_xmit = netxen_nic_xmit_frame, |
| 493 | .ndo_get_stats = netxen_nic_get_stats, |
| 494 | .ndo_validate_addr = eth_validate_addr, |
| 495 | .ndo_set_multicast_list = netxen_set_multicast_list, |
| 496 | .ndo_set_mac_address = netxen_nic_set_mac, |
| 497 | .ndo_change_mtu = netxen_nic_change_mtu, |
| 498 | .ndo_tx_timeout = netxen_tx_timeout, |
| 499 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 500 | .ndo_poll_controller = netxen_nic_poll_controller, |
| 501 | #endif |
| 502 | }; |
| 503 | |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 504 | static void |
| 505 | netxen_setup_intr(struct netxen_adapter *adapter) |
| 506 | { |
| 507 | struct netxen_legacy_intr_set *legacy_intrp; |
| 508 | struct pci_dev *pdev = adapter->pdev; |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 509 | int err, num_msix; |
| 510 | |
| 511 | if (adapter->rss_supported) { |
| 512 | num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ? |
| 513 | MSIX_ENTRIES_PER_ADAPTER : 2; |
| 514 | } else |
| 515 | num_msix = 1; |
| 516 | |
| 517 | adapter->max_sds_rings = 1; |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 518 | |
| 519 | adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED); |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 520 | |
| 521 | if (adapter->ahw.revision_id >= NX_P3_B0) |
| 522 | legacy_intrp = &legacy_intr[adapter->ahw.pci_func]; |
| 523 | else |
| 524 | legacy_intrp = &legacy_intr[0]; |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 525 | |
| 526 | adapter->int_vec_bit = legacy_intrp->int_vec_bit; |
| 527 | adapter->tgt_status_reg = netxen_get_ioaddr(adapter, |
| 528 | legacy_intrp->tgt_status_reg); |
| 529 | adapter->tgt_mask_reg = netxen_get_ioaddr(adapter, |
| 530 | legacy_intrp->tgt_mask_reg); |
| 531 | adapter->pci_int_reg = netxen_get_ioaddr(adapter, |
| 532 | legacy_intrp->pci_int_reg); |
| 533 | adapter->isr_int_vec = netxen_get_ioaddr(adapter, ISR_INT_VECTOR); |
| 534 | |
| 535 | if (adapter->ahw.revision_id >= NX_P3_B1) |
| 536 | adapter->crb_int_state_reg = netxen_get_ioaddr(adapter, |
| 537 | ISR_INT_STATE_REG); |
| 538 | else |
| 539 | adapter->crb_int_state_reg = netxen_get_ioaddr(adapter, |
| 540 | CRB_INT_VECTOR); |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 541 | |
| 542 | netxen_set_msix_bit(pdev, 0); |
| 543 | |
| 544 | if (adapter->msix_supported) { |
| 545 | |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 546 | netxen_init_msix_entries(adapter, num_msix); |
| 547 | err = pci_enable_msix(pdev, adapter->msix_entries, num_msix); |
| 548 | if (err == 0) { |
| 549 | adapter->flags |= NETXEN_NIC_MSIX_ENABLED; |
| 550 | netxen_set_msix_bit(pdev, 1); |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 551 | |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 552 | if (adapter->rss_supported) |
| 553 | adapter->max_sds_rings = num_msix; |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 554 | |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 555 | dev_info(&pdev->dev, "using msi-x interrupts\n"); |
| 556 | return; |
| 557 | } |
| 558 | |
| 559 | if (err > 0) |
| 560 | pci_disable_msix(pdev); |
| 561 | |
| 562 | /* fall through for msi */ |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 563 | } |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 564 | |
| 565 | if (use_msi && !pci_enable_msi(pdev)) { |
| 566 | adapter->flags |= NETXEN_NIC_MSI_ENABLED; |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 567 | adapter->tgt_status_reg = netxen_get_ioaddr(adapter, |
| 568 | msi_tgt_status[adapter->ahw.pci_func]); |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 569 | dev_info(&pdev->dev, "using msi interrupts\n"); |
Dhananjay Phadke | f67f340 | 2009-05-18 21:46:40 -0700 | [diff] [blame] | 570 | adapter->msix_entries[0].vector = pdev->irq; |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 571 | return; |
| 572 | } |
| 573 | |
| 574 | dev_info(&pdev->dev, "using legacy interrupts\n"); |
| 575 | adapter->msix_entries[0].vector = pdev->irq; |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | static void |
| 579 | netxen_teardown_intr(struct netxen_adapter *adapter) |
| 580 | { |
| 581 | if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) |
| 582 | pci_disable_msix(adapter->pdev); |
| 583 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 584 | pci_disable_msi(adapter->pdev); |
| 585 | } |
| 586 | |
| 587 | static void |
| 588 | netxen_cleanup_pci_map(struct netxen_adapter *adapter) |
| 589 | { |
| 590 | if (adapter->ahw.db_base != NULL) |
| 591 | iounmap(adapter->ahw.db_base); |
| 592 | if (adapter->ahw.pci_base0 != NULL) |
| 593 | iounmap(adapter->ahw.pci_base0); |
| 594 | if (adapter->ahw.pci_base1 != NULL) |
| 595 | iounmap(adapter->ahw.pci_base1); |
| 596 | if (adapter->ahw.pci_base2 != NULL) |
| 597 | iounmap(adapter->ahw.pci_base2); |
| 598 | } |
| 599 | |
| 600 | static int |
| 601 | netxen_setup_pci_map(struct netxen_adapter *adapter) |
| 602 | { |
| 603 | void __iomem *mem_ptr0 = NULL; |
| 604 | void __iomem *mem_ptr1 = NULL; |
| 605 | void __iomem *mem_ptr2 = NULL; |
| 606 | void __iomem *db_ptr = NULL; |
| 607 | |
Dhananjay Phadke | 71fb62f | 2009-10-13 00:26:04 -0700 | [diff] [blame] | 608 | resource_size_t mem_base, db_base; |
| 609 | unsigned long mem_len, db_len = 0, pci_len0 = 0; |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 610 | |
| 611 | struct pci_dev *pdev = adapter->pdev; |
| 612 | int pci_func = adapter->ahw.pci_func; |
| 613 | |
| 614 | int err = 0; |
| 615 | |
| 616 | /* |
| 617 | * Set the CRB window to invalid. If any register in window 0 is |
| 618 | * accessed it should set the window to 0 and then reset it to 1. |
| 619 | */ |
Dhananjay Phadke | 907fa12 | 2009-10-13 05:31:43 +0000 | [diff] [blame] | 620 | adapter->ahw.crb_win = -1; |
Dhananjay Phadke | 47abe35 | 2009-10-13 05:31:42 +0000 | [diff] [blame] | 621 | adapter->ahw.ocm_win = -1; |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 622 | |
| 623 | /* remap phys address */ |
| 624 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 625 | mem_len = pci_resource_len(pdev, 0); |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 626 | |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 627 | /* 128 Meg of memory */ |
| 628 | if (mem_len == NETXEN_PCI_128MB_SIZE) { |
| 629 | mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE); |
| 630 | mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START, |
| 631 | SECOND_PAGE_GROUP_SIZE); |
| 632 | mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START, |
| 633 | THIRD_PAGE_GROUP_SIZE); |
Dhananjay Phadke | 47abe35 | 2009-10-13 05:31:42 +0000 | [diff] [blame] | 634 | pci_len0 = FIRST_PAGE_GROUP_SIZE; |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 635 | } else if (mem_len == NETXEN_PCI_32MB_SIZE) { |
| 636 | mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE); |
| 637 | mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START - |
| 638 | SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE); |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 639 | } else if (mem_len == NETXEN_PCI_2MB_SIZE) { |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 640 | |
| 641 | mem_ptr0 = pci_ioremap_bar(pdev, 0); |
| 642 | if (mem_ptr0 == NULL) { |
| 643 | dev_err(&pdev->dev, "failed to map PCI bar 0\n"); |
| 644 | return -EIO; |
| 645 | } |
| 646 | pci_len0 = mem_len; |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 647 | } else { |
| 648 | return -EIO; |
| 649 | } |
| 650 | |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 651 | netxen_setup_hwops(adapter); |
| 652 | |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 653 | dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20)); |
| 654 | |
| 655 | adapter->ahw.pci_base0 = mem_ptr0; |
| 656 | adapter->ahw.pci_len0 = pci_len0; |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 657 | adapter->ahw.pci_base1 = mem_ptr1; |
| 658 | adapter->ahw.pci_base2 = mem_ptr2; |
| 659 | |
Amit Kumar Salecha | 6abb4b8 | 2009-10-16 15:50:09 +0000 | [diff] [blame] | 660 | if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) { |
| 661 | adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter, |
| 662 | NETXEN_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(pci_func))); |
| 663 | |
| 664 | } else if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
Dhananjay Phadke | 47abe35 | 2009-10-13 05:31:42 +0000 | [diff] [blame] | 665 | adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter, |
| 666 | NETXEN_PCIX_PS_REG(PCIE_MN_WINDOW_REG(pci_func))); |
| 667 | } |
| 668 | |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 669 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 670 | goto skip_doorbell; |
| 671 | |
| 672 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ |
| 673 | db_len = pci_resource_len(pdev, 4); |
| 674 | |
| 675 | if (db_len == 0) { |
| 676 | printk(KERN_ERR "%s: doorbell is disabled\n", |
| 677 | netxen_nic_driver_name); |
| 678 | err = -EIO; |
| 679 | goto err_out; |
| 680 | } |
| 681 | |
| 682 | db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES); |
| 683 | if (!db_ptr) { |
| 684 | printk(KERN_ERR "%s: Failed to allocate doorbell map.", |
| 685 | netxen_nic_driver_name); |
| 686 | err = -EIO; |
| 687 | goto err_out; |
| 688 | } |
| 689 | |
| 690 | skip_doorbell: |
| 691 | adapter->ahw.db_base = db_ptr; |
| 692 | adapter->ahw.db_len = db_len; |
| 693 | return 0; |
| 694 | |
| 695 | err_out: |
| 696 | netxen_cleanup_pci_map(adapter); |
| 697 | return err; |
| 698 | } |
| 699 | |
Dhananjay Phadke | 2b9e62e | 2009-09-05 17:43:11 +0000 | [diff] [blame] | 700 | static void |
| 701 | netxen_check_options(struct netxen_adapter *adapter) |
| 702 | { |
| 703 | u32 fw_major, fw_minor, fw_build; |
| 704 | char brd_name[NETXEN_MAX_SHORT_NAME]; |
| 705 | char serial_num[32]; |
| 706 | int i, offset, val; |
| 707 | int *ptr32; |
| 708 | struct pci_dev *pdev = adapter->pdev; |
| 709 | |
| 710 | adapter->driver_mismatch = 0; |
| 711 | |
| 712 | ptr32 = (int *)&serial_num; |
| 713 | offset = NX_FW_SERIAL_NUM_OFFSET; |
| 714 | for (i = 0; i < 8; i++) { |
| 715 | if (netxen_rom_fast_read(adapter, offset, &val) == -1) { |
| 716 | dev_err(&pdev->dev, "error reading board info\n"); |
| 717 | adapter->driver_mismatch = 1; |
| 718 | return; |
| 719 | } |
| 720 | ptr32[i] = cpu_to_le32(val); |
| 721 | offset += sizeof(u32); |
| 722 | } |
| 723 | |
| 724 | fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR); |
| 725 | fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR); |
| 726 | fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB); |
| 727 | |
| 728 | adapter->fw_version = NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build); |
| 729 | |
| 730 | if (adapter->portnum == 0) { |
| 731 | get_brd_name_by_type(adapter->ahw.board_type, brd_name); |
| 732 | |
Dhananjay Phadke | c25c0b9 | 2009-10-28 04:11:04 -0700 | [diff] [blame] | 733 | pr_info("%s: %s Board S/N %s Chip rev 0x%x\n", |
| 734 | module_name(THIS_MODULE), |
Dhananjay Phadke | 2b9e62e | 2009-09-05 17:43:11 +0000 | [diff] [blame] | 735 | brd_name, serial_num, adapter->ahw.revision_id); |
| 736 | } |
| 737 | |
| 738 | if (adapter->fw_version < NETXEN_VERSION_CODE(3, 4, 216)) { |
| 739 | adapter->driver_mismatch = 1; |
| 740 | dev_warn(&pdev->dev, "firmware version %d.%d.%d unsupported\n", |
| 741 | fw_major, fw_minor, fw_build); |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
| 746 | i = NXRD32(adapter, NETXEN_SRE_MISC); |
| 747 | adapter->ahw.cut_through = (i & 0x8000) ? 1 : 0; |
| 748 | } |
| 749 | |
| 750 | dev_info(&pdev->dev, "firmware v%d.%d.%d [%s]\n", |
| 751 | fw_major, fw_minor, fw_build, |
| 752 | adapter->ahw.cut_through ? "cut-through" : "legacy"); |
| 753 | |
| 754 | if (adapter->fw_version >= NETXEN_VERSION_CODE(4, 0, 222)) |
| 755 | adapter->capabilities = NXRD32(adapter, CRB_FW_CAPABILITIES_1); |
| 756 | |
| 757 | adapter->flags &= ~NETXEN_NIC_LRO_ENABLED; |
| 758 | |
| 759 | if (adapter->ahw.port_type == NETXEN_NIC_XGBE) { |
| 760 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G; |
| 761 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; |
| 762 | } else if (adapter->ahw.port_type == NETXEN_NIC_GBE) { |
| 763 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; |
| 764 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; |
| 765 | } |
| 766 | |
| 767 | adapter->msix_supported = 0; |
| 768 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
| 769 | adapter->msix_supported = !!use_msi_x; |
| 770 | adapter->rss_supported = !!use_msi_x; |
| 771 | } else if (adapter->fw_version >= NETXEN_VERSION_CODE(3, 4, 336)) { |
| 772 | switch (adapter->ahw.board_type) { |
| 773 | case NETXEN_BRDTYPE_P2_SB31_10G: |
| 774 | case NETXEN_BRDTYPE_P2_SB31_10G_CX4: |
| 775 | adapter->msix_supported = !!use_msi_x; |
| 776 | adapter->rss_supported = !!use_msi_x; |
| 777 | break; |
| 778 | default: |
| 779 | break; |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | adapter->num_txd = MAX_CMD_DESCRIPTORS; |
| 784 | |
| 785 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
| 786 | adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS; |
| 787 | adapter->max_rds_rings = 3; |
| 788 | } else { |
| 789 | adapter->num_lro_rxd = 0; |
| 790 | adapter->max_rds_rings = 2; |
| 791 | } |
| 792 | } |
| 793 | |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 794 | static int |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 795 | netxen_start_firmware(struct netxen_adapter *adapter) |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 796 | { |
| 797 | int val, err, first_boot; |
| 798 | struct pci_dev *pdev = adapter->pdev; |
| 799 | |
Dhananjay Phadke | 2b9e62e | 2009-09-05 17:43:11 +0000 | [diff] [blame] | 800 | /* required for NX2031 dummy dma */ |
| 801 | err = nx_set_dma_mask(adapter); |
| 802 | if (err) |
| 803 | return err; |
| 804 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 805 | if (!netxen_can_start_firmware(adapter)) |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 806 | goto wait_init; |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 807 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 808 | first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc)); |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 809 | |
| 810 | err = netxen_check_hw_init(adapter, first_boot); |
| 811 | if (err) { |
| 812 | dev_err(&pdev->dev, "error in init HW init sequence\n"); |
| 813 | return err; |
| 814 | } |
| 815 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 816 | netxen_request_firmware(adapter); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 817 | |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 818 | err = netxen_need_fw_reset(adapter); |
Dhananjay Phadke | 1dbc84a | 2009-08-23 08:35:10 +0000 | [diff] [blame] | 819 | if (err < 0) |
Dhananjay Phadke | db4cfd8 | 2009-09-05 17:43:07 +0000 | [diff] [blame] | 820 | goto err_out; |
Dhananjay Phadke | 1dbc84a | 2009-08-23 08:35:10 +0000 | [diff] [blame] | 821 | if (err == 0) |
Amit Kumar Salecha | 8f9b3f6 | 2009-12-02 15:46:19 +0000 | [diff] [blame] | 822 | goto wait_init; |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 823 | |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 824 | if (first_boot != 0x55555555) { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 825 | NXWR32(adapter, CRB_CMDPEG_STATE, 0); |
Amit Kumar Salecha | 0be367b | 2009-10-16 15:50:08 +0000 | [diff] [blame] | 826 | netxen_pinit_from_rom(adapter); |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 827 | msleep(1); |
| 828 | } |
Dhananjay Phadke | 567c6c4 | 2009-03-02 16:02:17 +0000 | [diff] [blame] | 829 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 830 | NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555); |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 831 | NXWR32(adapter, NETXEN_PEG_HALT_STATUS1, 0); |
| 832 | NXWR32(adapter, NETXEN_PEG_HALT_STATUS2, 0); |
| 833 | |
Dhananjay Phadke | 567c6c4 | 2009-03-02 16:02:17 +0000 | [diff] [blame] | 834 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 835 | netxen_set_port_mode(adapter); |
| 836 | |
Dhananjay Phadke | db4cfd8 | 2009-09-05 17:43:07 +0000 | [diff] [blame] | 837 | err = netxen_load_firmware(adapter); |
| 838 | if (err) |
| 839 | goto err_out; |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 840 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 841 | netxen_release_firmware(adapter); |
| 842 | |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 843 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
| 844 | |
| 845 | /* Initialize multicast addr pool owners */ |
| 846 | val = 0x7654; |
Dhananjay Phadke | 1e2d005 | 2009-03-09 08:50:56 +0000 | [diff] [blame] | 847 | if (adapter->ahw.port_type == NETXEN_NIC_XGBE) |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 848 | val |= 0x0f000000; |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 849 | NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val); |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 850 | |
| 851 | } |
| 852 | |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 853 | err = netxen_init_dummy_dma(adapter); |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 854 | if (err) |
Dhananjay Phadke | db4cfd8 | 2009-09-05 17:43:07 +0000 | [diff] [blame] | 855 | goto err_out; |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 856 | |
| 857 | /* |
| 858 | * Tell the hardware our version number. |
| 859 | */ |
| 860 | val = (_NETXEN_NIC_LINUX_MAJOR << 16) |
| 861 | | ((_NETXEN_NIC_LINUX_MINOR << 8)) |
| 862 | | (_NETXEN_NIC_LINUX_SUBVERSION); |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 863 | NXWR32(adapter, CRB_DRIVER_VERSION, val); |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 864 | |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 865 | wait_init: |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 866 | /* Handshake with the card before we register the devices. */ |
| 867 | err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
| 868 | if (err) { |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 869 | netxen_free_dummy_dma(adapter); |
Dhananjay Phadke | db4cfd8 | 2009-09-05 17:43:07 +0000 | [diff] [blame] | 870 | goto err_out; |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 871 | } |
| 872 | |
Amit Kumar Salecha | 8f9b3f6 | 2009-12-02 15:46:19 +0000 | [diff] [blame] | 873 | NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_READY); |
| 874 | |
Dhananjay Phadke | 68b3cae | 2009-07-26 20:07:36 +0000 | [diff] [blame] | 875 | nx_update_dma_mask(adapter); |
| 876 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 877 | netxen_check_options(adapter); |
Dhananjay Phadke | 68b3cae | 2009-07-26 20:07:36 +0000 | [diff] [blame] | 878 | |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 879 | adapter->need_fw_reset = 0; |
| 880 | |
Dhananjay Phadke | ec5c50c | 2009-09-11 11:28:13 +0000 | [diff] [blame] | 881 | /* fall through and release firmware */ |
Dhananjay Phadke | db4cfd8 | 2009-09-05 17:43:07 +0000 | [diff] [blame] | 882 | |
| 883 | err_out: |
| 884 | netxen_release_firmware(adapter); |
| 885 | return err; |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 886 | } |
| 887 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 888 | static int |
| 889 | netxen_nic_request_irq(struct netxen_adapter *adapter) |
| 890 | { |
| 891 | irq_handler_t handler; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 892 | struct nx_host_sds_ring *sds_ring; |
| 893 | int err, ring; |
| 894 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 895 | unsigned long flags = IRQF_SAMPLE_RANDOM; |
| 896 | struct net_device *netdev = adapter->netdev; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 897 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 898 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 899 | if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) |
| 900 | handler = netxen_msix_intr; |
| 901 | else if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 902 | handler = netxen_msi_intr; |
| 903 | else { |
| 904 | flags |= IRQF_SHARED; |
| 905 | handler = netxen_intr; |
| 906 | } |
| 907 | adapter->irq = netdev->irq; |
| 908 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 909 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 910 | sds_ring = &recv_ctx->sds_rings[ring]; |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 911 | sprintf(sds_ring->name, "%s[%d]", netdev->name, ring); |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 912 | err = request_irq(sds_ring->irq, handler, |
| 913 | flags, sds_ring->name, sds_ring); |
| 914 | if (err) |
| 915 | return err; |
| 916 | } |
| 917 | |
| 918 | return 0; |
| 919 | } |
| 920 | |
| 921 | static void |
| 922 | netxen_nic_free_irq(struct netxen_adapter *adapter) |
| 923 | { |
| 924 | int ring; |
| 925 | struct nx_host_sds_ring *sds_ring; |
| 926 | |
| 927 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; |
| 928 | |
| 929 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 930 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 931 | free_irq(sds_ring->irq, sds_ring); |
| 932 | } |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Dhananjay Phadke | ca2ef33 | 2009-07-26 20:07:38 +0000 | [diff] [blame] | 935 | static void |
| 936 | netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter) |
| 937 | { |
| 938 | adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT; |
| 939 | adapter->coal.normal.data.rx_time_us = |
| 940 | NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US; |
| 941 | adapter->coal.normal.data.rx_packets = |
| 942 | NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS; |
| 943 | adapter->coal.normal.data.tx_time_us = |
| 944 | NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US; |
| 945 | adapter->coal.normal.data.tx_packets = |
| 946 | NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS; |
| 947 | } |
| 948 | |
Amit Kumar Salecha | 6f77141 | 2009-12-05 12:23:54 +0000 | [diff] [blame^] | 949 | /* with rtnl_lock */ |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 950 | static int |
Amit Kumar Salecha | 6f77141 | 2009-12-05 12:23:54 +0000 | [diff] [blame^] | 951 | __netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev) |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 952 | { |
| 953 | int err; |
| 954 | |
Dhananjay Phadke | db4cfd8 | 2009-09-05 17:43:07 +0000 | [diff] [blame] | 955 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) |
| 956 | return -EIO; |
| 957 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 958 | err = adapter->init_port(adapter, adapter->physical_port); |
| 959 | if (err) { |
| 960 | printk(KERN_ERR "%s: Failed to initialize port %d\n", |
| 961 | netxen_nic_driver_name, adapter->portnum); |
| 962 | return err; |
| 963 | } |
Dhananjay Phadke | 3d0a3cc | 2009-05-05 19:05:08 +0000 | [diff] [blame] | 964 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
Narender Kumar | 5d09e53 | 2009-11-20 22:08:57 +0000 | [diff] [blame] | 965 | adapter->macaddr_set(adapter, adapter->mac_addr); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 966 | |
Dhananjay Phadke | 3d0a3cc | 2009-05-05 19:05:08 +0000 | [diff] [blame] | 967 | adapter->set_multi(netdev); |
| 968 | adapter->set_mtu(adapter, netdev->mtu); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 969 | |
| 970 | adapter->ahw.linkup = 0; |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 971 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 972 | if (adapter->max_sds_rings > 1) |
| 973 | netxen_config_rss(adapter, 1); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 974 | |
Dhananjay Phadke | ca2ef33 | 2009-07-26 20:07:38 +0000 | [diff] [blame] | 975 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 976 | netxen_config_intr_coalesce(adapter); |
| 977 | |
Narender Kumar | 1bb482f | 2009-08-23 08:35:09 +0000 | [diff] [blame] | 978 | if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO) |
| 979 | netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED); |
| 980 | |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 981 | netxen_napi_enable(adapter); |
| 982 | |
Dhananjay Phadke | 5103c9f | 2009-04-28 15:29:09 +0000 | [diff] [blame] | 983 | if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION) |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 984 | netxen_linkevent_request(adapter, 1); |
Dhananjay Phadke | 3d0a3cc | 2009-05-05 19:05:08 +0000 | [diff] [blame] | 985 | else |
| 986 | netxen_nic_set_link_parameters(adapter); |
| 987 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 988 | set_bit(__NX_DEV_UP, &adapter->state); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 989 | return 0; |
| 990 | } |
| 991 | |
Amit Kumar Salecha | 6f77141 | 2009-12-05 12:23:54 +0000 | [diff] [blame^] | 992 | /* Usage: During resume and firmware recovery module.*/ |
| 993 | |
| 994 | static inline int |
| 995 | netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev) |
| 996 | { |
| 997 | int err = 0; |
| 998 | |
| 999 | rtnl_lock(); |
| 1000 | if (netif_running(netdev)) |
| 1001 | err = __netxen_nic_up(adapter, netdev); |
| 1002 | rtnl_unlock(); |
| 1003 | |
| 1004 | return err; |
| 1005 | } |
| 1006 | |
| 1007 | /* with rtnl_lock */ |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1008 | static void |
Amit Kumar Salecha | 6f77141 | 2009-12-05 12:23:54 +0000 | [diff] [blame^] | 1009 | __netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev) |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1010 | { |
Dhananjay Phadke | db4cfd8 | 2009-09-05 17:43:07 +0000 | [diff] [blame] | 1011 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) |
| 1012 | return; |
| 1013 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1014 | clear_bit(__NX_DEV_UP, &adapter->state); |
| 1015 | |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 1016 | spin_lock(&adapter->tx_clean_lock); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1017 | netif_carrier_off(netdev); |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 1018 | netif_tx_disable(netdev); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1019 | |
| 1020 | if (adapter->stop_port) |
| 1021 | adapter->stop_port(adapter); |
| 1022 | |
Dhananjay Phadke | 5cf4d32 | 2009-05-05 19:05:07 +0000 | [diff] [blame] | 1023 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 1024 | netxen_p3_free_mac_list(adapter); |
| 1025 | |
Amit Kumar Salecha | 22b5794 | 2009-08-23 08:35:12 +0000 | [diff] [blame] | 1026 | adapter->set_promisc(adapter, NETXEN_NIU_NON_PROMISC_MODE); |
| 1027 | |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 1028 | netxen_napi_disable(adapter); |
| 1029 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1030 | netxen_release_tx_buffers(adapter); |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 1031 | spin_unlock(&adapter->tx_clean_lock); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
Amit Kumar Salecha | 6f77141 | 2009-12-05 12:23:54 +0000 | [diff] [blame^] | 1034 | /* Usage: During suspend and firmware recovery module */ |
| 1035 | |
| 1036 | static inline void |
| 1037 | netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev) |
| 1038 | { |
| 1039 | rtnl_lock(); |
| 1040 | if (netif_running(netdev)) |
| 1041 | __netxen_nic_down(adapter, netdev); |
| 1042 | rtnl_unlock(); |
| 1043 | |
| 1044 | } |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1045 | |
| 1046 | static int |
| 1047 | netxen_nic_attach(struct netxen_adapter *adapter) |
| 1048 | { |
| 1049 | struct net_device *netdev = adapter->netdev; |
| 1050 | struct pci_dev *pdev = adapter->pdev; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 1051 | int err, ring; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1052 | struct nx_host_rds_ring *rds_ring; |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1053 | struct nx_host_tx_ring *tx_ring; |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1054 | |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1055 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) |
| 1056 | return 0; |
| 1057 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1058 | err = netxen_init_firmware(adapter); |
Dhananjay Phadke | 232e7d6 | 2009-08-13 07:03:01 +0000 | [diff] [blame] | 1059 | if (err) |
| 1060 | return err; |
| 1061 | |
| 1062 | err = netxen_napi_add(adapter, netdev); |
| 1063 | if (err) |
| 1064 | return err; |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1065 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1066 | err = netxen_alloc_sw_resources(adapter); |
| 1067 | if (err) { |
| 1068 | printk(KERN_ERR "%s: Error in setting sw resources\n", |
| 1069 | netdev->name); |
| 1070 | return err; |
| 1071 | } |
| 1072 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1073 | err = netxen_alloc_hw_resources(adapter); |
| 1074 | if (err) { |
| 1075 | printk(KERN_ERR "%s: Error in setting hw resources\n", |
| 1076 | netdev->name); |
| 1077 | goto err_out_free_sw; |
| 1078 | } |
| 1079 | |
Dhananjay Phadke | 4f96b98 | 2009-07-26 20:07:42 +0000 | [diff] [blame] | 1080 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 1081 | tx_ring = adapter->tx_ring; |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 1082 | tx_ring->crb_cmd_producer = netxen_get_ioaddr(adapter, |
| 1083 | crb_cmd_producer[adapter->portnum]); |
| 1084 | tx_ring->crb_cmd_consumer = netxen_get_ioaddr(adapter, |
| 1085 | crb_cmd_consumer[adapter->portnum]); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1086 | |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1087 | tx_ring->producer = 0; |
| 1088 | tx_ring->sw_consumer = 0; |
| 1089 | |
| 1090 | netxen_nic_update_cmd_producer(adapter, tx_ring); |
| 1091 | netxen_nic_update_cmd_consumer(adapter, tx_ring); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1094 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 1095 | rds_ring = &adapter->recv_ctx.rds_rings[ring]; |
| 1096 | netxen_post_rx_buffers(adapter, ring, rds_ring); |
| 1097 | } |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1098 | |
| 1099 | err = netxen_nic_request_irq(adapter); |
| 1100 | if (err) { |
| 1101 | dev_err(&pdev->dev, "%s: failed to setup interrupt\n", |
| 1102 | netdev->name); |
| 1103 | goto err_out_free_rxbuf; |
| 1104 | } |
| 1105 | |
Dhananjay Phadke | ca2ef33 | 2009-07-26 20:07:38 +0000 | [diff] [blame] | 1106 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 1107 | netxen_nic_init_coalesce_defaults(adapter); |
| 1108 | |
Narender Kumar | fa3ce35 | 2009-08-24 19:23:28 +0000 | [diff] [blame] | 1109 | netxen_create_sysfs_entries(adapter); |
| 1110 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1111 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; |
| 1112 | return 0; |
| 1113 | |
| 1114 | err_out_free_rxbuf: |
| 1115 | netxen_release_rx_buffers(adapter); |
| 1116 | netxen_free_hw_resources(adapter); |
| 1117 | err_out_free_sw: |
| 1118 | netxen_free_sw_resources(adapter); |
| 1119 | return err; |
| 1120 | } |
| 1121 | |
| 1122 | static void |
| 1123 | netxen_nic_detach(struct netxen_adapter *adapter) |
| 1124 | { |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1125 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) |
| 1126 | return; |
| 1127 | |
Narender Kumar | fa3ce35 | 2009-08-24 19:23:28 +0000 | [diff] [blame] | 1128 | netxen_remove_sysfs_entries(adapter); |
| 1129 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1130 | netxen_free_hw_resources(adapter); |
Dhananjay Phadke | cf981ff | 2009-07-17 15:27:06 +0000 | [diff] [blame] | 1131 | netxen_release_rx_buffers(adapter); |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 1132 | netxen_nic_free_irq(adapter); |
Dhananjay Phadke | 232e7d6 | 2009-08-13 07:03:01 +0000 | [diff] [blame] | 1133 | netxen_napi_del(adapter); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1134 | netxen_free_sw_resources(adapter); |
| 1135 | |
| 1136 | adapter->is_up = 0; |
| 1137 | } |
| 1138 | |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1139 | int |
| 1140 | netxen_nic_reset_context(struct netxen_adapter *adapter) |
| 1141 | { |
| 1142 | int err = 0; |
| 1143 | struct net_device *netdev = adapter->netdev; |
| 1144 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1145 | if (test_and_set_bit(__NX_RESETTING, &adapter->state)) |
| 1146 | return -EBUSY; |
| 1147 | |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1148 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
| 1149 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1150 | netif_device_detach(netdev); |
| 1151 | |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1152 | if (netif_running(netdev)) |
Amit Kumar Salecha | 6f77141 | 2009-12-05 12:23:54 +0000 | [diff] [blame^] | 1153 | __netxen_nic_down(adapter, netdev); |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1154 | |
| 1155 | netxen_nic_detach(adapter); |
| 1156 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1157 | if (netif_running(netdev)) { |
| 1158 | err = netxen_nic_attach(adapter); |
| 1159 | if (!err) |
Amit Kumar Salecha | 6f77141 | 2009-12-05 12:23:54 +0000 | [diff] [blame^] | 1160 | err = __netxen_nic_up(adapter, netdev); |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1161 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1162 | if (err) |
| 1163 | goto done; |
| 1164 | } |
| 1165 | |
| 1166 | netif_device_attach(netdev); |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1167 | } |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1168 | |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1169 | done: |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1170 | clear_bit(__NX_RESETTING, &adapter->state); |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1171 | return err; |
| 1172 | } |
| 1173 | |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1174 | static int |
| 1175 | netxen_setup_netdev(struct netxen_adapter *adapter, |
| 1176 | struct net_device *netdev) |
| 1177 | { |
| 1178 | int err = 0; |
| 1179 | struct pci_dev *pdev = adapter->pdev; |
| 1180 | |
| 1181 | adapter->rx_csum = 1; |
| 1182 | adapter->mc_enabled = 0; |
| 1183 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 1184 | adapter->max_mc_count = 38; |
| 1185 | else |
| 1186 | adapter->max_mc_count = 16; |
| 1187 | |
| 1188 | netdev->netdev_ops = &netxen_netdev_ops; |
| 1189 | netdev->watchdog_timeo = 2*HZ; |
| 1190 | |
| 1191 | netxen_nic_change_mtu(netdev, netdev->mtu); |
| 1192 | |
| 1193 | SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops); |
| 1194 | |
| 1195 | netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO); |
| 1196 | netdev->features |= (NETIF_F_GRO); |
| 1197 | netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO); |
| 1198 | |
| 1199 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
| 1200 | netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 1201 | netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 1202 | } |
| 1203 | |
| 1204 | if (adapter->pci_using_dac) { |
| 1205 | netdev->features |= NETIF_F_HIGHDMA; |
| 1206 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 1207 | } |
| 1208 | |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1209 | if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX) |
| 1210 | netdev->features |= (NETIF_F_HW_VLAN_TX); |
| 1211 | |
Narender Kumar | 1bb482f | 2009-08-23 08:35:09 +0000 | [diff] [blame] | 1212 | if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO) |
| 1213 | netdev->features |= NETIF_F_LRO; |
| 1214 | |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1215 | netdev->irq = adapter->msix_entries[0].vector; |
| 1216 | |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 1217 | INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task); |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1218 | |
| 1219 | if (netxen_read_mac_addr(adapter)) |
| 1220 | dev_warn(&pdev->dev, "failed to read mac addr\n"); |
| 1221 | |
| 1222 | netif_carrier_off(netdev); |
| 1223 | netif_stop_queue(netdev); |
| 1224 | |
| 1225 | err = register_netdev(netdev); |
| 1226 | if (err) { |
| 1227 | dev_err(&pdev->dev, "failed to register net device\n"); |
| 1228 | return err; |
| 1229 | } |
| 1230 | |
| 1231 | return 0; |
| 1232 | } |
| 1233 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1234 | static int __devinit |
| 1235 | netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 1236 | { |
| 1237 | struct net_device *netdev = NULL; |
| 1238 | struct netxen_adapter *adapter = NULL; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1239 | int i = 0, err; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1240 | int pci_func_id = PCI_FUNC(pdev->devfn); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1241 | uint8_t revision_id; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1242 | |
Dhananjay Phadke | 11d89d6 | 2008-08-08 00:08:45 -0700 | [diff] [blame] | 1243 | if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) { |
Dhananjay Phadke | c25c0b9 | 2009-10-28 04:11:04 -0700 | [diff] [blame] | 1244 | pr_warning("%s: chip revisions between 0x%x-0x%x" |
Dhananjay Phadke | 11d89d6 | 2008-08-08 00:08:45 -0700 | [diff] [blame] | 1245 | "will not be enabled.\n", |
Dhananjay Phadke | c25c0b9 | 2009-10-28 04:11:04 -0700 | [diff] [blame] | 1246 | module_name(THIS_MODULE), NX_P3_A0, NX_P3_B1); |
Dhananjay Phadke | 11d89d6 | 2008-08-08 00:08:45 -0700 | [diff] [blame] | 1247 | return -ENODEV; |
| 1248 | } |
| 1249 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1250 | if ((err = pci_enable_device(pdev))) |
| 1251 | return err; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1252 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1253 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 1254 | err = -ENODEV; |
| 1255 | goto err_out_disable_pdev; |
| 1256 | } |
| 1257 | |
| 1258 | if ((err = pci_request_regions(pdev, netxen_nic_driver_name))) |
| 1259 | goto err_out_disable_pdev; |
| 1260 | |
| 1261 | pci_set_master(pdev); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1262 | |
| 1263 | netdev = alloc_etherdev(sizeof(struct netxen_adapter)); |
| 1264 | if(!netdev) { |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1265 | dev_err(&pdev->dev, "failed to allocate net_device\n"); |
| 1266 | err = -ENOMEM; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1267 | goto err_out_free_res; |
| 1268 | } |
| 1269 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1270 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 1271 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1272 | adapter = netdev_priv(netdev); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1273 | adapter->netdev = netdev; |
| 1274 | adapter->pdev = pdev; |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 1275 | adapter->ahw.pci_func = pci_func_id; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1276 | |
| 1277 | revision_id = pdev->revision; |
| 1278 | adapter->ahw.revision_id = revision_id; |
| 1279 | |
Dhananjay Phadke | f03b0eb | 2009-10-13 05:31:44 +0000 | [diff] [blame] | 1280 | rwlock_init(&adapter->ahw.crb_lock); |
| 1281 | spin_lock_init(&adapter->ahw.mem_lock); |
| 1282 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1283 | spin_lock_init(&adapter->tx_clean_lock); |
Dhananjay Phadke | 5cf4d32 | 2009-05-05 19:05:07 +0000 | [diff] [blame] | 1284 | INIT_LIST_HEAD(&adapter->mac_list); |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 1285 | |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 1286 | err = netxen_setup_pci_map(adapter); |
| 1287 | if (err) |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1288 | goto err_out_free_netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1289 | |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 1290 | /* This will be reset for mezz cards */ |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1291 | adapter->portnum = pci_func_id; |
| 1292 | |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1293 | err = netxen_nic_get_board_info(adapter); |
| 1294 | if (err) { |
| 1295 | dev_err(&pdev->dev, "Error getting board config info.\n"); |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 1296 | goto err_out_iounmap; |
| 1297 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1298 | |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 1299 | /* Mezz cards have PCI function 0,2,3 enabled */ |
Dhananjay Phadke | 1e2d005 | 2009-03-09 08:50:56 +0000 | [diff] [blame] | 1300 | switch (adapter->ahw.board_type) { |
Dhananjay Phadke | dc515f2 | 2008-06-15 22:59:43 -0700 | [diff] [blame] | 1301 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: |
| 1302 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: |
| 1303 | if (pci_func_id >= 2) |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 1304 | adapter->portnum = pci_func_id - 2; |
Dhananjay Phadke | dc515f2 | 2008-06-15 22:59:43 -0700 | [diff] [blame] | 1305 | break; |
| 1306 | default: |
| 1307 | break; |
| 1308 | } |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 1309 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1310 | err = netxen_start_firmware(adapter); |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1311 | if (err) |
Amit Kumar Salecha | 8f9b3f6 | 2009-12-02 15:46:19 +0000 | [diff] [blame] | 1312 | goto err_out_decr_ref; |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1313 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1314 | /* |
| 1315 | * See if the firmware gave us a virtual-physical port mapping. |
| 1316 | */ |
| 1317 | adapter->physical_port = adapter->portnum; |
Dhananjay Phadke | 4f96b98 | 2009-07-26 20:07:42 +0000 | [diff] [blame] | 1318 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1319 | i = NXRD32(adapter, CRB_V2P(adapter->portnum)); |
Dhananjay Phadke | 044fad0 | 2009-02-24 03:42:59 -0800 | [diff] [blame] | 1320 | if (i != 0x55555555) |
| 1321 | adapter->physical_port = i; |
| 1322 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1323 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1324 | netxen_nic_clear_stats(adapter); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1325 | |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 1326 | netxen_setup_intr(adapter); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1327 | |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1328 | err = netxen_setup_netdev(adapter, netdev); |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 1329 | if (err) |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1330 | goto err_out_disable_msi; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1331 | |
| 1332 | pci_set_drvdata(pdev, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1333 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1334 | netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); |
| 1335 | |
Dhananjay Phadke | 1e2d005 | 2009-03-09 08:50:56 +0000 | [diff] [blame] | 1336 | switch (adapter->ahw.port_type) { |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1337 | case NETXEN_NIC_GBE: |
| 1338 | dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", |
| 1339 | adapter->netdev->name); |
| 1340 | break; |
| 1341 | case NETXEN_NIC_XGBE: |
| 1342 | dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", |
| 1343 | adapter->netdev->name); |
| 1344 | break; |
| 1345 | } |
| 1346 | |
Dhananjay Phadke | 70f9cf8 | 2009-10-13 05:31:45 +0000 | [diff] [blame] | 1347 | netxen_create_diag_entries(adapter); |
| 1348 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1349 | return 0; |
| 1350 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1351 | err_out_disable_msi: |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 1352 | netxen_teardown_intr(adapter); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1353 | |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 1354 | netxen_free_dummy_dma(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1355 | |
Amit Kumar Salecha | 8f9b3f6 | 2009-12-02 15:46:19 +0000 | [diff] [blame] | 1356 | err_out_decr_ref: |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1357 | nx_decr_dev_ref_cnt(adapter); |
| 1358 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1359 | err_out_iounmap: |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 1360 | netxen_cleanup_pci_map(adapter); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1361 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1362 | err_out_free_netdev: |
| 1363 | free_netdev(netdev); |
| 1364 | |
| 1365 | err_out_free_res: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1366 | pci_release_regions(pdev); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1367 | |
| 1368 | err_out_disable_pdev: |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1369 | pci_set_drvdata(pdev, NULL); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1370 | pci_disable_device(pdev); |
| 1371 | return err; |
| 1372 | } |
| 1373 | |
| 1374 | static void __devexit netxen_nic_remove(struct pci_dev *pdev) |
| 1375 | { |
| 1376 | struct netxen_adapter *adapter; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1377 | struct net_device *netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1378 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1379 | adapter = pci_get_drvdata(pdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1380 | if (adapter == NULL) |
| 1381 | return; |
| 1382 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1383 | netdev = adapter->netdev; |
| 1384 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1385 | netxen_cancel_fw_work(adapter); |
| 1386 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1387 | unregister_netdev(netdev); |
| 1388 | |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1389 | cancel_work_sync(&adapter->tx_timeout_task); |
| 1390 | |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1391 | netxen_nic_detach(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1392 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1393 | nx_decr_dev_ref_cnt(adapter); |
| 1394 | |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 1395 | if (adapter->portnum == 0) |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 1396 | netxen_free_dummy_dma(adapter); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1397 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1398 | clear_bit(__NX_RESETTING, &adapter->state); |
| 1399 | |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 1400 | netxen_teardown_intr(adapter); |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 1401 | |
Dhananjay Phadke | 70f9cf8 | 2009-10-13 05:31:45 +0000 | [diff] [blame] | 1402 | netxen_remove_diag_entries(adapter); |
| 1403 | |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 1404 | netxen_cleanup_pci_map(adapter); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1405 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1406 | netxen_release_firmware(adapter); |
| 1407 | |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1408 | pci_release_regions(pdev); |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 1409 | pci_disable_device(pdev); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1410 | pci_set_drvdata(pdev, NULL); |
| 1411 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1412 | free_netdev(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1413 | } |
Amit Kumar Salecha | 22b5794 | 2009-08-23 08:35:12 +0000 | [diff] [blame] | 1414 | static int __netxen_nic_shutdown(struct pci_dev *pdev) |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1415 | { |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1416 | struct netxen_adapter *adapter = pci_get_drvdata(pdev); |
| 1417 | struct net_device *netdev = adapter->netdev; |
Amit Kumar Salecha | 22b5794 | 2009-08-23 08:35:12 +0000 | [diff] [blame] | 1418 | int retval; |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1419 | |
| 1420 | netif_device_detach(netdev); |
| 1421 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1422 | netxen_cancel_fw_work(adapter); |
| 1423 | |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1424 | if (netif_running(netdev)) |
| 1425 | netxen_nic_down(adapter, netdev); |
| 1426 | |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1427 | cancel_work_sync(&adapter->tx_timeout_task); |
| 1428 | |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1429 | netxen_nic_detach(adapter); |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1430 | |
Amit Kumar Salecha | 22b5794 | 2009-08-23 08:35:12 +0000 | [diff] [blame] | 1431 | if (adapter->portnum == 0) |
| 1432 | netxen_free_dummy_dma(adapter); |
| 1433 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1434 | nx_decr_dev_ref_cnt(adapter); |
| 1435 | |
| 1436 | clear_bit(__NX_RESETTING, &adapter->state); |
| 1437 | |
Amit Kumar Salecha | 22b5794 | 2009-08-23 08:35:12 +0000 | [diff] [blame] | 1438 | retval = pci_save_state(pdev); |
| 1439 | if (retval) |
| 1440 | return retval; |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1441 | |
| 1442 | if (netxen_nic_wol_supported(adapter)) { |
| 1443 | pci_enable_wake(pdev, PCI_D3cold, 1); |
| 1444 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 1445 | } |
| 1446 | |
| 1447 | pci_disable_device(pdev); |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1448 | |
| 1449 | return 0; |
| 1450 | } |
Amit Kumar Salecha | 22b5794 | 2009-08-23 08:35:12 +0000 | [diff] [blame] | 1451 | static void netxen_nic_shutdown(struct pci_dev *pdev) |
| 1452 | { |
| 1453 | if (__netxen_nic_shutdown(pdev)) |
| 1454 | return; |
| 1455 | } |
| 1456 | #ifdef CONFIG_PM |
| 1457 | static int |
| 1458 | netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state) |
| 1459 | { |
| 1460 | int retval; |
| 1461 | |
| 1462 | retval = __netxen_nic_shutdown(pdev); |
| 1463 | if (retval) |
| 1464 | return retval; |
| 1465 | |
| 1466 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 1467 | return 0; |
| 1468 | } |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1469 | |
| 1470 | static int |
| 1471 | netxen_nic_resume(struct pci_dev *pdev) |
| 1472 | { |
| 1473 | struct netxen_adapter *adapter = pci_get_drvdata(pdev); |
| 1474 | struct net_device *netdev = adapter->netdev; |
| 1475 | int err; |
| 1476 | |
| 1477 | pci_set_power_state(pdev, PCI_D0); |
| 1478 | pci_restore_state(pdev); |
| 1479 | |
| 1480 | err = pci_enable_device(pdev); |
| 1481 | if (err) |
| 1482 | return err; |
| 1483 | |
Dhananjay Phadke | 907fa12 | 2009-10-13 05:31:43 +0000 | [diff] [blame] | 1484 | adapter->ahw.crb_win = -1; |
Dhananjay Phadke | 47abe35 | 2009-10-13 05:31:42 +0000 | [diff] [blame] | 1485 | adapter->ahw.ocm_win = -1; |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1486 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1487 | err = netxen_start_firmware(adapter); |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1488 | if (err) { |
| 1489 | dev_err(&pdev->dev, "failed to start firmware\n"); |
| 1490 | return err; |
| 1491 | } |
| 1492 | |
| 1493 | if (netif_running(netdev)) { |
| 1494 | err = netxen_nic_attach(adapter); |
| 1495 | if (err) |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1496 | goto err_out; |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1497 | |
| 1498 | err = netxen_nic_up(adapter, netdev); |
| 1499 | if (err) |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1500 | goto err_out_detach; |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1501 | |
| 1502 | netif_device_attach(netdev); |
Amit Kumar Salecha | d0725e4 | 2009-09-05 17:43:09 +0000 | [diff] [blame] | 1503 | |
| 1504 | netxen_config_indev_addr(netdev, NETDEV_UP); |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1505 | } |
| 1506 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1507 | netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); |
Dhananjay Phadke | 07653aa | 2009-09-20 19:20:39 +0000 | [diff] [blame] | 1508 | return 0; |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1509 | |
| 1510 | err_out_detach: |
| 1511 | netxen_nic_detach(adapter); |
| 1512 | err_out: |
| 1513 | nx_decr_dev_ref_cnt(adapter); |
| 1514 | return err; |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1515 | } |
Dhananjay Phadke | 01542cd | 2009-06-22 20:26:20 +0000 | [diff] [blame] | 1516 | #endif |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1517 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1518 | static int netxen_nic_open(struct net_device *netdev) |
| 1519 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1520 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1521 | int err = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1522 | |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 1523 | if (adapter->driver_mismatch) |
| 1524 | return -EIO; |
| 1525 | |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1526 | err = netxen_nic_attach(adapter); |
| 1527 | if (err) |
| 1528 | return err; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1529 | |
Amit Kumar Salecha | 6f77141 | 2009-12-05 12:23:54 +0000 | [diff] [blame^] | 1530 | err = __netxen_nic_up(adapter, netdev); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1531 | if (err) |
| 1532 | goto err_out; |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1533 | |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 1534 | netif_start_queue(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1535 | |
| 1536 | return 0; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1537 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1538 | err_out: |
| 1539 | netxen_nic_detach(adapter); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1540 | return err; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | /* |
| 1544 | * netxen_nic_close - Disables a network interface entry point |
| 1545 | */ |
| 1546 | static int netxen_nic_close(struct net_device *netdev) |
| 1547 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1548 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1549 | |
Amit Kumar Salecha | 6f77141 | 2009-12-05 12:23:54 +0000 | [diff] [blame^] | 1550 | __netxen_nic_down(adapter, netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1551 | return 0; |
| 1552 | } |
| 1553 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1554 | static void |
| 1555 | netxen_tso_check(struct net_device *netdev, |
| 1556 | struct nx_host_tx_ring *tx_ring, |
| 1557 | struct cmd_desc_type0 *first_desc, |
| 1558 | struct sk_buff *skb) |
Dhananjay Phadke | cd1f816 | 2008-07-21 19:44:09 -0700 | [diff] [blame] | 1559 | { |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1560 | u8 opcode = TX_ETHER_PKT; |
Dhananjay Phadke | cdff103 | 2009-01-26 12:34:57 -0800 | [diff] [blame] | 1561 | __be16 protocol = skb->protocol; |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1562 | u16 flags = 0, vid = 0; |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1563 | u32 producer; |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1564 | int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0; |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1565 | struct cmd_desc_type0 *hwdesc; |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1566 | struct vlan_ethhdr *vh; |
Dhananjay Phadke | cdff103 | 2009-01-26 12:34:57 -0800 | [diff] [blame] | 1567 | |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 1568 | if (protocol == cpu_to_be16(ETH_P_8021Q)) { |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1569 | |
| 1570 | vh = (struct vlan_ethhdr *)skb->data; |
Dhananjay Phadke | cdff103 | 2009-01-26 12:34:57 -0800 | [diff] [blame] | 1571 | protocol = vh->h_vlan_encapsulated_proto; |
| 1572 | flags = FLAGS_VLAN_TAGGED; |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1573 | |
| 1574 | } else if (vlan_tx_tag_present(skb)) { |
| 1575 | |
| 1576 | flags = FLAGS_VLAN_OOB; |
| 1577 | vid = vlan_tx_tag_get(skb); |
| 1578 | netxen_set_tx_vlan_tci(first_desc, vid); |
| 1579 | vlan_oob = 1; |
Dhananjay Phadke | cdff103 | 2009-01-26 12:34:57 -0800 | [diff] [blame] | 1580 | } |
Dhananjay Phadke | cd1f816 | 2008-07-21 19:44:09 -0700 | [diff] [blame] | 1581 | |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1582 | if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) && |
| 1583 | skb_shinfo(skb)->gso_size > 0) { |
| 1584 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1585 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 1586 | |
| 1587 | first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
| 1588 | first_desc->total_hdr_length = hdr_len; |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1589 | if (vlan_oob) { |
| 1590 | first_desc->total_hdr_length += VLAN_HLEN; |
| 1591 | first_desc->tcp_hdr_offset = VLAN_HLEN; |
| 1592 | first_desc->ip_hdr_offset = VLAN_HLEN; |
| 1593 | /* Only in case of TSO on vlan device */ |
| 1594 | flags |= FLAGS_VLAN_TAGGED; |
| 1595 | } |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1596 | |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 1597 | opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ? |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1598 | TX_TCP_LSO6 : TX_TCP_LSO; |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1599 | tso = 1; |
Dhananjay Phadke | cd1f816 | 2008-07-21 19:44:09 -0700 | [diff] [blame] | 1600 | |
| 1601 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1602 | u8 l4proto; |
| 1603 | |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 1604 | if (protocol == cpu_to_be16(ETH_P_IP)) { |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1605 | l4proto = ip_hdr(skb)->protocol; |
| 1606 | |
| 1607 | if (l4proto == IPPROTO_TCP) |
| 1608 | opcode = TX_TCP_PKT; |
| 1609 | else if(l4proto == IPPROTO_UDP) |
| 1610 | opcode = TX_UDP_PKT; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 1611 | } else if (protocol == cpu_to_be16(ETH_P_IPV6)) { |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1612 | l4proto = ipv6_hdr(skb)->nexthdr; |
| 1613 | |
| 1614 | if (l4proto == IPPROTO_TCP) |
| 1615 | opcode = TX_TCPV6_PKT; |
| 1616 | else if(l4proto == IPPROTO_UDP) |
| 1617 | opcode = TX_UDPV6_PKT; |
| 1618 | } |
Dhananjay Phadke | cd1f816 | 2008-07-21 19:44:09 -0700 | [diff] [blame] | 1619 | } |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1620 | |
| 1621 | first_desc->tcp_hdr_offset += skb_transport_offset(skb); |
| 1622 | first_desc->ip_hdr_offset += skb_network_offset(skb); |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1623 | netxen_set_tx_flags_opcode(first_desc, flags, opcode); |
| 1624 | |
| 1625 | if (!tso) |
| 1626 | return; |
| 1627 | |
| 1628 | /* For LSO, we need to copy the MAC/IP/TCP headers into |
| 1629 | * the descriptor ring |
| 1630 | */ |
| 1631 | producer = tx_ring->producer; |
| 1632 | copied = 0; |
| 1633 | offset = 2; |
| 1634 | |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1635 | if (vlan_oob) { |
| 1636 | /* Create a TSO vlan header template for firmware */ |
| 1637 | |
| 1638 | hwdesc = &tx_ring->desc_head[producer]; |
| 1639 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
| 1640 | |
| 1641 | copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, |
| 1642 | hdr_len + VLAN_HLEN); |
| 1643 | |
| 1644 | vh = (struct vlan_ethhdr *)((char *)hwdesc + 2); |
| 1645 | skb_copy_from_linear_data(skb, vh, 12); |
| 1646 | vh->h_vlan_proto = htons(ETH_P_8021Q); |
| 1647 | vh->h_vlan_TCI = htons(vid); |
| 1648 | skb_copy_from_linear_data_offset(skb, 12, |
| 1649 | (char *)vh + 16, copy_len - 16); |
| 1650 | |
Dhananjay Phadke | 545eb37 | 2009-08-05 07:34:07 +0000 | [diff] [blame] | 1651 | copied = copy_len - VLAN_HLEN; |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1652 | offset = 0; |
| 1653 | |
| 1654 | producer = get_next_index(producer, tx_ring->num_desc); |
| 1655 | } |
| 1656 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1657 | while (copied < hdr_len) { |
| 1658 | |
| 1659 | copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, |
| 1660 | (hdr_len - copied)); |
| 1661 | |
| 1662 | hwdesc = &tx_ring->desc_head[producer]; |
| 1663 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
| 1664 | |
| 1665 | skb_copy_from_linear_data_offset(skb, copied, |
| 1666 | (char *)hwdesc + offset, copy_len); |
| 1667 | |
| 1668 | copied += copy_len; |
| 1669 | offset = 0; |
| 1670 | |
| 1671 | producer = get_next_index(producer, tx_ring->num_desc); |
| 1672 | } |
| 1673 | |
| 1674 | tx_ring->producer = producer; |
| 1675 | barrier(); |
Dhananjay Phadke | cd1f816 | 2008-07-21 19:44:09 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1678 | static int |
| 1679 | netxen_map_tx_skb(struct pci_dev *pdev, |
| 1680 | struct sk_buff *skb, struct netxen_cmd_buffer *pbuf) |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1681 | { |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1682 | struct netxen_skb_frag *nf; |
| 1683 | struct skb_frag_struct *frag; |
| 1684 | int i, nr_frags; |
| 1685 | dma_addr_t map; |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1686 | |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1687 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 1688 | nf = &pbuf->frag_array[0]; |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1689 | |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1690 | map = pci_map_single(pdev, skb->data, |
| 1691 | skb_headlen(skb), PCI_DMA_TODEVICE); |
| 1692 | if (pci_dma_mapping_error(pdev, map)) |
| 1693 | goto out_err; |
| 1694 | |
| 1695 | nf->dma = map; |
| 1696 | nf->length = skb_headlen(skb); |
| 1697 | |
| 1698 | for (i = 0; i < nr_frags; i++) { |
| 1699 | frag = &skb_shinfo(skb)->frags[i]; |
| 1700 | nf = &pbuf->frag_array[i+1]; |
| 1701 | |
| 1702 | map = pci_map_page(pdev, frag->page, frag->page_offset, |
| 1703 | frag->size, PCI_DMA_TODEVICE); |
| 1704 | if (pci_dma_mapping_error(pdev, map)) |
| 1705 | goto unwind; |
| 1706 | |
| 1707 | nf->dma = map; |
| 1708 | nf->length = frag->size; |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1709 | } |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1710 | |
| 1711 | return 0; |
| 1712 | |
| 1713 | unwind: |
Dhananjay Phadke | cf503e8 | 2009-09-03 13:10:55 +0000 | [diff] [blame] | 1714 | while (--i >= 0) { |
| 1715 | nf = &pbuf->frag_array[i+1]; |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1716 | pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); |
| 1717 | } |
| 1718 | |
| 1719 | nf = &pbuf->frag_array[0]; |
| 1720 | pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); |
| 1721 | |
| 1722 | out_err: |
| 1723 | return -ENOMEM; |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1724 | } |
| 1725 | |
Dhananjay Phadke | d32cc3d | 2009-03-09 08:50:53 +0000 | [diff] [blame] | 1726 | static inline void |
| 1727 | netxen_clear_cmddesc(u64 *desc) |
| 1728 | { |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1729 | desc[0] = 0ULL; |
| 1730 | desc[2] = 0ULL; |
Dhananjay Phadke | d32cc3d | 2009-03-09 08:50:53 +0000 | [diff] [blame] | 1731 | } |
| 1732 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 1733 | static netdev_tx_t |
Dhananjay Phadke | d32cc3d | 2009-03-09 08:50:53 +0000 | [diff] [blame] | 1734 | netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1735 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1736 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 1737 | struct nx_host_tx_ring *tx_ring = adapter->tx_ring; |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1738 | struct netxen_cmd_buffer *pbuf; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1739 | struct netxen_skb_frag *buffrag; |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1740 | struct cmd_desc_type0 *hwdesc, *first_desc; |
| 1741 | struct pci_dev *pdev; |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1742 | int i, k; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1743 | |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1744 | u32 producer; |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1745 | int frag_count, no_of_desc; |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1746 | u32 num_txd = tx_ring->num_desc; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1747 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1748 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
| 1749 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1750 | /* 4 fragments per cmd des */ |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1751 | no_of_desc = (frag_count + 3) >> 2; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1752 | |
Roel Kluin | fa9859e | 2009-10-06 19:34:39 +0000 | [diff] [blame] | 1753 | if (unlikely(no_of_desc + 2 > netxen_tx_avail(tx_ring))) { |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1754 | netif_stop_queue(netdev); |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1755 | return NETDEV_TX_BUSY; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1756 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1757 | |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1758 | producer = tx_ring->producer; |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1759 | pbuf = &tx_ring->cmd_buf_arr[producer]; |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1760 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1761 | pdev = adapter->pdev; |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1762 | |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1763 | if (netxen_map_tx_skb(pdev, skb, pbuf)) |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1764 | goto drop_packet; |
| 1765 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1766 | pbuf->skb = skb; |
| 1767 | pbuf->frag_count = frag_count; |
| 1768 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1769 | first_desc = hwdesc = &tx_ring->desc_head[producer]; |
| 1770 | netxen_clear_cmddesc((u64 *)hwdesc); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1771 | |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1772 | netxen_set_tx_frags_len(first_desc, frag_count, skb->len); |
| 1773 | netxen_set_tx_port(first_desc, adapter->portnum); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1774 | |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1775 | for (i = 0; i < frag_count; i++) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1776 | |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1777 | k = i % 4; |
| 1778 | |
| 1779 | if ((k == 0) && (i > 0)) { |
| 1780 | /* move to next desc.*/ |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1781 | producer = get_next_index(producer, num_txd); |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1782 | hwdesc = &tx_ring->desc_head[producer]; |
Dhananjay Phadke | d32cc3d | 2009-03-09 08:50:53 +0000 | [diff] [blame] | 1783 | netxen_clear_cmddesc((u64 *)hwdesc); |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1784 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1785 | } |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1786 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1787 | buffrag = &pbuf->frag_array[i]; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1788 | |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1789 | hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1790 | switch (k) { |
| 1791 | case 0: |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1792 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1793 | break; |
| 1794 | case 1: |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1795 | hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1796 | break; |
| 1797 | case 2: |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1798 | hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1799 | break; |
| 1800 | case 3: |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1801 | hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1802 | break; |
| 1803 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1804 | } |
Dhananjay Phadke | ce644ed | 2009-08-23 08:35:11 +0000 | [diff] [blame] | 1805 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1806 | tx_ring->producer = get_next_index(producer, num_txd); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1807 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1808 | netxen_tso_check(netdev, tx_ring, first_desc, skb); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1809 | |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1810 | netxen_nic_update_cmd_producer(adapter, tx_ring); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1811 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1812 | adapter->stats.txbytes += skb->len; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1813 | adapter->stats.xmitcalled++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1814 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1815 | return NETDEV_TX_OK; |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1816 | |
| 1817 | drop_packet: |
| 1818 | adapter->stats.txdropped++; |
| 1819 | dev_kfree_skb_any(skb); |
| 1820 | return NETDEV_TX_OK; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1821 | } |
| 1822 | |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1823 | static int netxen_nic_check_temp(struct netxen_adapter *adapter) |
| 1824 | { |
| 1825 | struct net_device *netdev = adapter->netdev; |
| 1826 | uint32_t temp, temp_state, temp_val; |
| 1827 | int rv = 0; |
| 1828 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1829 | temp = NXRD32(adapter, CRB_TEMP_STATE); |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1830 | |
| 1831 | temp_state = nx_get_temp_state(temp); |
| 1832 | temp_val = nx_get_temp_val(temp); |
| 1833 | |
| 1834 | if (temp_state == NX_TEMP_PANIC) { |
| 1835 | printk(KERN_ALERT |
| 1836 | "%s: Device temperature %d degrees C exceeds" |
| 1837 | " maximum allowed. Hardware has been shut down.\n", |
Dhananjay Phadke | e4135c2 | 2009-07-17 15:27:08 +0000 | [diff] [blame] | 1838 | netdev->name, temp_val); |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1839 | rv = 1; |
| 1840 | } else if (temp_state == NX_TEMP_WARN) { |
| 1841 | if (adapter->temp == NX_TEMP_NORMAL) { |
| 1842 | printk(KERN_ALERT |
| 1843 | "%s: Device temperature %d degrees C " |
| 1844 | "exceeds operating range." |
| 1845 | " Immediate action needed.\n", |
Dhananjay Phadke | e4135c2 | 2009-07-17 15:27:08 +0000 | [diff] [blame] | 1846 | netdev->name, temp_val); |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1847 | } |
| 1848 | } else { |
| 1849 | if (adapter->temp == NX_TEMP_WARN) { |
| 1850 | printk(KERN_INFO |
| 1851 | "%s: Device temperature is now %d degrees C" |
Dhananjay Phadke | e4135c2 | 2009-07-17 15:27:08 +0000 | [diff] [blame] | 1852 | " in normal range.\n", netdev->name, |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1853 | temp_val); |
| 1854 | } |
| 1855 | } |
| 1856 | adapter->temp = temp_state; |
| 1857 | return rv; |
| 1858 | } |
| 1859 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1860 | void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup) |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1861 | { |
| 1862 | struct net_device *netdev = adapter->netdev; |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1863 | |
| 1864 | if (adapter->ahw.linkup && !linkup) { |
| 1865 | printk(KERN_INFO "%s: %s NIC Link is down\n", |
| 1866 | netxen_nic_driver_name, netdev->name); |
| 1867 | adapter->ahw.linkup = 0; |
| 1868 | if (netif_running(netdev)) { |
| 1869 | netif_carrier_off(netdev); |
| 1870 | netif_stop_queue(netdev); |
| 1871 | } |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1872 | adapter->link_changed = !adapter->has_link_events; |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1873 | } else if (!adapter->ahw.linkup && linkup) { |
| 1874 | printk(KERN_INFO "%s: %s NIC Link is up\n", |
| 1875 | netxen_nic_driver_name, netdev->name); |
| 1876 | adapter->ahw.linkup = 1; |
| 1877 | if (netif_running(netdev)) { |
| 1878 | netif_carrier_on(netdev); |
| 1879 | netif_wake_queue(netdev); |
| 1880 | } |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1881 | adapter->link_changed = !adapter->has_link_events; |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter) |
| 1886 | { |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1887 | u32 val, port, linkup; |
| 1888 | |
| 1889 | port = adapter->physical_port; |
| 1890 | |
Dhananjay Phadke | 24a7a45 | 2008-08-01 03:14:55 -0700 | [diff] [blame] | 1891 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1892 | val = NXRD32(adapter, CRB_XG_STATE_P3); |
Dhananjay Phadke | 24a7a45 | 2008-08-01 03:14:55 -0700 | [diff] [blame] | 1893 | val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val); |
| 1894 | linkup = (val == XG_LINK_UP_P3); |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 1895 | } else { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1896 | val = NXRD32(adapter, CRB_XG_STATE); |
Dhananjay Phadke | 1e2d005 | 2009-03-09 08:50:56 +0000 | [diff] [blame] | 1897 | if (adapter->ahw.port_type == NETXEN_NIC_GBE) |
Dhananjay Phadke | 24a7a45 | 2008-08-01 03:14:55 -0700 | [diff] [blame] | 1898 | linkup = (val >> port) & 1; |
| 1899 | else { |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 1900 | val = (val >> port*8) & 0xff; |
| 1901 | linkup = (val == XG_LINK_UP); |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 1902 | } |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1905 | netxen_advert_link_change(adapter, linkup); |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1908 | static void netxen_tx_timeout(struct net_device *netdev) |
| 1909 | { |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1910 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1911 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1912 | if (test_bit(__NX_RESETTING, &adapter->state)) |
| 1913 | return; |
| 1914 | |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1915 | dev_err(&netdev->dev, "transmit timeout, resetting.\n"); |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1916 | schedule_work(&adapter->tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1917 | } |
| 1918 | |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 1919 | static void netxen_tx_timeout_task(struct work_struct *work) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1920 | { |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 1921 | struct netxen_adapter *adapter = |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1922 | container_of(work, struct netxen_adapter, tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1923 | |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 1924 | if (!netif_running(adapter->netdev)) |
| 1925 | return; |
| 1926 | |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 1927 | if (test_and_set_bit(__NX_RESETTING, &adapter->state)) |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 1928 | return; |
| 1929 | |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 1930 | if (++adapter->tx_timeo_cnt >= NX_MAX_TX_TIMEOUTS) |
| 1931 | goto request_reset; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1932 | |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 1933 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
| 1934 | /* try to scrub interrupt */ |
| 1935 | netxen_napi_disable(adapter); |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1936 | |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 1937 | adapter->netdev->trans_start = jiffies; |
| 1938 | |
| 1939 | netxen_napi_enable(adapter); |
| 1940 | |
| 1941 | netif_wake_queue(adapter->netdev); |
| 1942 | |
Dhananjay Phadke | a598ae1 | 2009-09-20 19:20:38 +0000 | [diff] [blame] | 1943 | clear_bit(__NX_RESETTING, &adapter->state); |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 1944 | |
| 1945 | } else { |
Dhananjay Phadke | a598ae1 | 2009-09-20 19:20:38 +0000 | [diff] [blame] | 1946 | clear_bit(__NX_RESETTING, &adapter->state); |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 1947 | if (!netxen_nic_reset_context(adapter)) { |
| 1948 | adapter->netdev->trans_start = jiffies; |
Dhananjay Phadke | a598ae1 | 2009-09-20 19:20:38 +0000 | [diff] [blame] | 1949 | return; |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | /* context reset failed, fall through for fw reset */ |
| 1953 | } |
| 1954 | |
| 1955 | request_reset: |
| 1956 | adapter->need_fw_reset = 1; |
Amit Kumar Salecha | ff8a306 | 2009-10-21 19:39:02 +0000 | [diff] [blame] | 1957 | clear_bit(__NX_RESETTING, &adapter->state); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1958 | } |
| 1959 | |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1960 | struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev) |
| 1961 | { |
| 1962 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | 5a4d631 | 2009-10-07 02:45:34 +0000 | [diff] [blame] | 1963 | struct net_device_stats *stats = &netdev->stats; |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1964 | |
| 1965 | memset(stats, 0, sizeof(*stats)); |
| 1966 | |
Narender Kumar | 1bb482f | 2009-08-23 08:35:09 +0000 | [diff] [blame] | 1967 | stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; |
Dhananjay Phadke | e98e335 | 2009-04-07 22:50:38 +0000 | [diff] [blame] | 1968 | stats->tx_packets = adapter->stats.xmitfinished; |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1969 | stats->rx_bytes = adapter->stats.rxbytes; |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1970 | stats->tx_bytes = adapter->stats.txbytes; |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1971 | stats->rx_dropped = adapter->stats.rxdropped; |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1972 | stats->tx_dropped = adapter->stats.txdropped; |
| 1973 | |
| 1974 | return stats; |
| 1975 | } |
| 1976 | |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1977 | static irqreturn_t netxen_intr(int irq, void *data) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1978 | { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1979 | struct nx_host_sds_ring *sds_ring = data; |
| 1980 | struct netxen_adapter *adapter = sds_ring->adapter; |
Dhananjay Phadke | d71e1be | 2008-08-01 03:14:57 -0700 | [diff] [blame] | 1981 | u32 status = 0; |
| 1982 | |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 1983 | status = readl(adapter->isr_int_vec); |
Dhananjay Phadke | d71e1be | 2008-08-01 03:14:57 -0700 | [diff] [blame] | 1984 | |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 1985 | if (!(status & adapter->int_vec_bit)) |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1986 | return IRQ_NONE; |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1987 | |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 1988 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
Dhananjay Phadke | d71e1be | 2008-08-01 03:14:57 -0700 | [diff] [blame] | 1989 | /* check interrupt state machine, to be sure */ |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 1990 | status = readl(adapter->crb_int_state_reg); |
Dhananjay Phadke | d71e1be | 2008-08-01 03:14:57 -0700 | [diff] [blame] | 1991 | if (!ISR_LEGACY_INT_TRIGGERED(status)) |
| 1992 | return IRQ_NONE; |
| 1993 | |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 1994 | } else { |
| 1995 | unsigned long our_int = 0; |
Dhananjay Phadke | d71e1be | 2008-08-01 03:14:57 -0700 | [diff] [blame] | 1996 | |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 1997 | our_int = readl(adapter->crb_int_state_reg); |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 1998 | |
Dhananjay Phadke | d71e1be | 2008-08-01 03:14:57 -0700 | [diff] [blame] | 1999 | /* not our interrupt */ |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 2000 | if (!test_and_clear_bit((7 + adapter->portnum), &our_int)) |
Dhananjay Phadke | d71e1be | 2008-08-01 03:14:57 -0700 | [diff] [blame] | 2001 | return IRQ_NONE; |
| 2002 | |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 2003 | /* claim interrupt */ |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 2004 | writel((our_int & 0xffffffff), adapter->crb_int_state_reg); |
| 2005 | |
| 2006 | /* clear interrupt */ |
| 2007 | netxen_nic_disable_int(sds_ring); |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 2008 | } |
| 2009 | |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 2010 | writel(0xffffffff, adapter->tgt_status_reg); |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 2011 | /* read twice to ensure write is flushed */ |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 2012 | readl(adapter->isr_int_vec); |
| 2013 | readl(adapter->isr_int_vec); |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 2014 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 2015 | napi_schedule(&sds_ring->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2016 | |
| 2017 | return IRQ_HANDLED; |
| 2018 | } |
| 2019 | |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 2020 | static irqreturn_t netxen_msi_intr(int irq, void *data) |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 2021 | { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 2022 | struct nx_host_sds_ring *sds_ring = data; |
| 2023 | struct netxen_adapter *adapter = sds_ring->adapter; |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 2024 | |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 2025 | /* clear interrupt */ |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 2026 | writel(0xffffffff, adapter->tgt_status_reg); |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 2027 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 2028 | napi_schedule(&sds_ring->napi); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 2029 | return IRQ_HANDLED; |
| 2030 | } |
| 2031 | |
Dhananjay Phadke | b3df68f | 2009-02-08 19:20:19 -0800 | [diff] [blame] | 2032 | static irqreturn_t netxen_msix_intr(int irq, void *data) |
| 2033 | { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 2034 | struct nx_host_sds_ring *sds_ring = data; |
Dhananjay Phadke | b3df68f | 2009-02-08 19:20:19 -0800 | [diff] [blame] | 2035 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 2036 | napi_schedule(&sds_ring->napi); |
Dhananjay Phadke | b3df68f | 2009-02-08 19:20:19 -0800 | [diff] [blame] | 2037 | return IRQ_HANDLED; |
| 2038 | } |
| 2039 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2040 | static int netxen_nic_poll(struct napi_struct *napi, int budget) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2041 | { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 2042 | struct nx_host_sds_ring *sds_ring = |
| 2043 | container_of(napi, struct nx_host_sds_ring, napi); |
| 2044 | |
| 2045 | struct netxen_adapter *adapter = sds_ring->adapter; |
| 2046 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 2047 | int tx_complete; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2048 | int work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2049 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 2050 | tx_complete = netxen_process_cmd_ring(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2051 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 2052 | work_done = netxen_process_rcv_ring(sds_ring, budget); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2053 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 2054 | if ((work_done < budget) && tx_complete) { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 2055 | napi_complete(&sds_ring->napi); |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 2056 | if (netif_running(adapter->netdev)) |
| 2057 | netxen_nic_enable_int(sds_ring); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2058 | } |
| 2059 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2060 | return work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2064 | static void netxen_nic_poll_controller(struct net_device *netdev) |
| 2065 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 2066 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2067 | disable_irq(adapter->irq); |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 2068 | netxen_intr(adapter->irq, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2069 | enable_irq(adapter->irq); |
| 2070 | } |
| 2071 | #endif |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2072 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 2073 | static int |
| 2074 | nx_incr_dev_ref_cnt(struct netxen_adapter *adapter) |
| 2075 | { |
| 2076 | int count; |
| 2077 | if (netxen_api_lock(adapter)) |
| 2078 | return -EIO; |
| 2079 | |
| 2080 | count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); |
| 2081 | |
| 2082 | NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count); |
| 2083 | |
| 2084 | netxen_api_unlock(adapter); |
| 2085 | return count; |
| 2086 | } |
| 2087 | |
| 2088 | static int |
| 2089 | nx_decr_dev_ref_cnt(struct netxen_adapter *adapter) |
| 2090 | { |
| 2091 | int count; |
| 2092 | if (netxen_api_lock(adapter)) |
| 2093 | return -EIO; |
| 2094 | |
| 2095 | count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); |
| 2096 | WARN_ON(count == 0); |
| 2097 | |
| 2098 | NXWR32(adapter, NX_CRB_DEV_REF_COUNT, --count); |
| 2099 | |
| 2100 | if (count == 0) |
| 2101 | NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_COLD); |
| 2102 | |
| 2103 | netxen_api_unlock(adapter); |
| 2104 | return count; |
| 2105 | } |
| 2106 | |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 2107 | static void |
| 2108 | nx_dev_request_reset(struct netxen_adapter *adapter) |
| 2109 | { |
| 2110 | u32 state; |
| 2111 | |
| 2112 | if (netxen_api_lock(adapter)) |
| 2113 | return; |
| 2114 | |
| 2115 | state = NXRD32(adapter, NX_CRB_DEV_STATE); |
| 2116 | |
| 2117 | if (state != NX_DEV_INITALIZING) |
| 2118 | NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_RESET); |
| 2119 | |
| 2120 | netxen_api_unlock(adapter); |
| 2121 | } |
| 2122 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 2123 | static int |
| 2124 | netxen_can_start_firmware(struct netxen_adapter *adapter) |
| 2125 | { |
| 2126 | int count; |
| 2127 | int can_start = 0; |
| 2128 | |
| 2129 | if (netxen_api_lock(adapter)) |
| 2130 | return 0; |
| 2131 | |
| 2132 | count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT); |
| 2133 | |
| 2134 | if ((count < 0) || (count >= NX_MAX_PCI_FUNC)) |
| 2135 | count = 0; |
| 2136 | |
| 2137 | if (count == 0) { |
| 2138 | can_start = 1; |
| 2139 | NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_INITALIZING); |
| 2140 | } |
| 2141 | |
| 2142 | NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count); |
| 2143 | |
| 2144 | netxen_api_unlock(adapter); |
| 2145 | |
| 2146 | return can_start; |
| 2147 | } |
| 2148 | |
| 2149 | static void |
| 2150 | netxen_schedule_work(struct netxen_adapter *adapter, |
| 2151 | work_func_t func, int delay) |
| 2152 | { |
| 2153 | INIT_DELAYED_WORK(&adapter->fw_work, func); |
| 2154 | schedule_delayed_work(&adapter->fw_work, delay); |
| 2155 | } |
| 2156 | |
| 2157 | static void |
| 2158 | netxen_cancel_fw_work(struct netxen_adapter *adapter) |
| 2159 | { |
| 2160 | while (test_and_set_bit(__NX_RESETTING, &adapter->state)) |
| 2161 | msleep(10); |
| 2162 | |
| 2163 | cancel_delayed_work_sync(&adapter->fw_work); |
| 2164 | } |
| 2165 | |
| 2166 | static void |
| 2167 | netxen_attach_work(struct work_struct *work) |
| 2168 | { |
| 2169 | struct netxen_adapter *adapter = container_of(work, |
| 2170 | struct netxen_adapter, fw_work.work); |
| 2171 | struct net_device *netdev = adapter->netdev; |
| 2172 | int err = 0; |
| 2173 | |
| 2174 | if (netif_running(netdev)) { |
| 2175 | err = netxen_nic_attach(adapter); |
| 2176 | if (err) |
| 2177 | goto done; |
| 2178 | |
| 2179 | err = netxen_nic_up(adapter, netdev); |
| 2180 | if (err) { |
| 2181 | netxen_nic_detach(adapter); |
| 2182 | goto done; |
| 2183 | } |
| 2184 | |
Amit Kumar Salecha | d0725e4 | 2009-09-05 17:43:09 +0000 | [diff] [blame] | 2185 | netxen_config_indev_addr(netdev, NETDEV_UP); |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | netif_device_attach(netdev); |
| 2189 | |
| 2190 | done: |
| 2191 | adapter->fw_fail_cnt = 0; |
| 2192 | clear_bit(__NX_RESETTING, &adapter->state); |
| 2193 | netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); |
| 2194 | } |
| 2195 | |
| 2196 | static void |
| 2197 | netxen_fwinit_work(struct work_struct *work) |
| 2198 | { |
| 2199 | struct netxen_adapter *adapter = container_of(work, |
| 2200 | struct netxen_adapter, fw_work.work); |
| 2201 | int dev_state; |
| 2202 | |
| 2203 | dev_state = NXRD32(adapter, NX_CRB_DEV_STATE); |
| 2204 | |
| 2205 | switch (dev_state) { |
| 2206 | case NX_DEV_COLD: |
| 2207 | case NX_DEV_READY: |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 2208 | if (!netxen_start_firmware(adapter)) { |
| 2209 | netxen_schedule_work(adapter, netxen_attach_work, 0); |
| 2210 | return; |
| 2211 | } |
| 2212 | break; |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 2213 | |
| 2214 | case NX_DEV_INITALIZING: |
| 2215 | if (++adapter->fw_wait_cnt < FW_POLL_THRESH) { |
| 2216 | netxen_schedule_work(adapter, |
| 2217 | netxen_fwinit_work, 2 * FW_POLL_DELAY); |
| 2218 | return; |
| 2219 | } |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 2220 | |
| 2221 | case NX_DEV_FAILED: |
| 2222 | default: |
Amit Kumar Salecha | 8f9b3f6 | 2009-12-02 15:46:19 +0000 | [diff] [blame] | 2223 | nx_incr_dev_ref_cnt(adapter); |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 2224 | break; |
| 2225 | } |
| 2226 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 2227 | clear_bit(__NX_RESETTING, &adapter->state); |
| 2228 | } |
| 2229 | |
| 2230 | static void |
| 2231 | netxen_detach_work(struct work_struct *work) |
| 2232 | { |
| 2233 | struct netxen_adapter *adapter = container_of(work, |
| 2234 | struct netxen_adapter, fw_work.work); |
| 2235 | struct net_device *netdev = adapter->netdev; |
| 2236 | int ref_cnt, delay; |
| 2237 | u32 status; |
| 2238 | |
| 2239 | netif_device_detach(netdev); |
| 2240 | |
Amit Kumar Salecha | 6f77141 | 2009-12-05 12:23:54 +0000 | [diff] [blame^] | 2241 | netxen_nic_down(adapter, netdev); |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 2242 | |
| 2243 | netxen_nic_detach(adapter); |
| 2244 | |
| 2245 | status = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1); |
| 2246 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 2247 | if (status & NX_RCODE_FATAL_ERROR) |
Amit Kumar Salecha | 8f9b3f6 | 2009-12-02 15:46:19 +0000 | [diff] [blame] | 2248 | goto err_ret; |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 2249 | |
| 2250 | if (adapter->temp == NX_TEMP_PANIC) |
Amit Kumar Salecha | 8f9b3f6 | 2009-12-02 15:46:19 +0000 | [diff] [blame] | 2251 | goto err_ret; |
| 2252 | |
| 2253 | ref_cnt = nx_decr_dev_ref_cnt(adapter); |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 2254 | |
| 2255 | delay = (ref_cnt == 0) ? 0 : (2 * FW_POLL_DELAY); |
| 2256 | |
| 2257 | adapter->fw_wait_cnt = 0; |
| 2258 | netxen_schedule_work(adapter, netxen_fwinit_work, delay); |
Amit Kumar Salecha | 8f9b3f6 | 2009-12-02 15:46:19 +0000 | [diff] [blame] | 2259 | |
| 2260 | return; |
| 2261 | |
| 2262 | err_ret: |
| 2263 | clear_bit(__NX_RESETTING, &adapter->state); |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | static int |
| 2267 | netxen_check_health(struct netxen_adapter *adapter) |
| 2268 | { |
| 2269 | u32 state, heartbit; |
| 2270 | struct net_device *netdev = adapter->netdev; |
| 2271 | |
| 2272 | if (netxen_nic_check_temp(adapter)) |
| 2273 | goto detach; |
| 2274 | |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 2275 | if (adapter->need_fw_reset) { |
| 2276 | nx_dev_request_reset(adapter); |
| 2277 | goto detach; |
| 2278 | } |
| 2279 | |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 2280 | state = NXRD32(adapter, NX_CRB_DEV_STATE); |
| 2281 | if (state == NX_DEV_NEED_RESET) |
| 2282 | goto detach; |
| 2283 | |
| 2284 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 2285 | return 0; |
| 2286 | |
| 2287 | heartbit = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); |
| 2288 | if (heartbit != adapter->heartbit) { |
| 2289 | adapter->heartbit = heartbit; |
| 2290 | adapter->fw_fail_cnt = 0; |
| 2291 | return 0; |
| 2292 | } |
| 2293 | |
| 2294 | if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) |
| 2295 | return 0; |
| 2296 | |
| 2297 | clear_bit(__NX_FW_ATTACHED, &adapter->state); |
| 2298 | |
| 2299 | dev_info(&netdev->dev, "firmware hang detected\n"); |
| 2300 | |
| 2301 | detach: |
Narender Kumar | caa2dd5 | 2009-10-16 15:50:11 +0000 | [diff] [blame] | 2302 | if ((auto_fw_reset == AUTO_FW_RESET_ENABLED) && |
| 2303 | !test_and_set_bit(__NX_RESETTING, &adapter->state)) |
Dhananjay Phadke | 6a581e9 | 2009-09-05 17:43:08 +0000 | [diff] [blame] | 2304 | netxen_schedule_work(adapter, netxen_detach_work, 0); |
| 2305 | return 1; |
| 2306 | } |
| 2307 | |
| 2308 | static void |
| 2309 | netxen_fw_poll_work(struct work_struct *work) |
| 2310 | { |
| 2311 | struct netxen_adapter *adapter = container_of(work, |
| 2312 | struct netxen_adapter, fw_work.work); |
| 2313 | |
| 2314 | if (test_bit(__NX_RESETTING, &adapter->state)) |
| 2315 | goto reschedule; |
| 2316 | |
| 2317 | if (test_bit(__NX_DEV_UP, &adapter->state)) { |
| 2318 | if (!adapter->has_link_events) { |
| 2319 | |
| 2320 | netxen_nic_handle_phy_intr(adapter); |
| 2321 | |
| 2322 | if (adapter->link_changed) |
| 2323 | netxen_nic_set_link_parameters(adapter); |
| 2324 | } |
| 2325 | } |
| 2326 | |
| 2327 | if (netxen_check_health(adapter)) |
| 2328 | return; |
| 2329 | |
| 2330 | reschedule: |
| 2331 | netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY); |
| 2332 | } |
| 2333 | |
Narender Kumar | fa3ce35 | 2009-08-24 19:23:28 +0000 | [diff] [blame] | 2334 | static ssize_t |
| 2335 | netxen_store_bridged_mode(struct device *dev, |
| 2336 | struct device_attribute *attr, const char *buf, size_t len) |
| 2337 | { |
| 2338 | struct net_device *net = to_net_dev(dev); |
| 2339 | struct netxen_adapter *adapter = netdev_priv(net); |
| 2340 | unsigned long new; |
| 2341 | int ret = -EINVAL; |
| 2342 | |
| 2343 | if (!(adapter->capabilities & NX_FW_CAPABILITY_BDG)) |
| 2344 | goto err_out; |
| 2345 | |
| 2346 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) |
| 2347 | goto err_out; |
| 2348 | |
| 2349 | if (strict_strtoul(buf, 2, &new)) |
| 2350 | goto err_out; |
| 2351 | |
| 2352 | if (!netxen_config_bridged_mode(adapter, !!new)) |
| 2353 | ret = len; |
| 2354 | |
| 2355 | err_out: |
| 2356 | return ret; |
| 2357 | } |
| 2358 | |
| 2359 | static ssize_t |
| 2360 | netxen_show_bridged_mode(struct device *dev, |
| 2361 | struct device_attribute *attr, char *buf) |
| 2362 | { |
| 2363 | struct net_device *net = to_net_dev(dev); |
| 2364 | struct netxen_adapter *adapter; |
| 2365 | int bridged_mode = 0; |
| 2366 | |
| 2367 | adapter = netdev_priv(net); |
| 2368 | |
| 2369 | if (adapter->capabilities & NX_FW_CAPABILITY_BDG) |
| 2370 | bridged_mode = !!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED); |
| 2371 | |
| 2372 | return sprintf(buf, "%d\n", bridged_mode); |
| 2373 | } |
| 2374 | |
| 2375 | static struct device_attribute dev_attr_bridged_mode = { |
| 2376 | .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)}, |
| 2377 | .show = netxen_show_bridged_mode, |
| 2378 | .store = netxen_store_bridged_mode, |
| 2379 | }; |
| 2380 | |
Dhananjay Phadke | 70f9cf8 | 2009-10-13 05:31:45 +0000 | [diff] [blame] | 2381 | static ssize_t |
| 2382 | netxen_store_diag_mode(struct device *dev, |
| 2383 | struct device_attribute *attr, const char *buf, size_t len) |
| 2384 | { |
| 2385 | struct netxen_adapter *adapter = dev_get_drvdata(dev); |
| 2386 | unsigned long new; |
| 2387 | |
| 2388 | if (strict_strtoul(buf, 2, &new)) |
| 2389 | return -EINVAL; |
| 2390 | |
| 2391 | if (!!new != !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)) |
| 2392 | adapter->flags ^= NETXEN_NIC_DIAG_ENABLED; |
| 2393 | |
| 2394 | return len; |
| 2395 | } |
| 2396 | |
| 2397 | static ssize_t |
| 2398 | netxen_show_diag_mode(struct device *dev, |
| 2399 | struct device_attribute *attr, char *buf) |
| 2400 | { |
| 2401 | struct netxen_adapter *adapter = dev_get_drvdata(dev); |
| 2402 | |
| 2403 | return sprintf(buf, "%d\n", |
| 2404 | !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)); |
| 2405 | } |
| 2406 | |
| 2407 | static struct device_attribute dev_attr_diag_mode = { |
| 2408 | .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)}, |
| 2409 | .show = netxen_show_diag_mode, |
| 2410 | .store = netxen_store_diag_mode, |
| 2411 | }; |
| 2412 | |
| 2413 | static int |
| 2414 | netxen_sysfs_validate_crb(struct netxen_adapter *adapter, |
| 2415 | loff_t offset, size_t size) |
| 2416 | { |
| 2417 | if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)) |
| 2418 | return -EIO; |
| 2419 | |
| 2420 | if ((size != 4) || (offset & 0x3)) |
| 2421 | return -EINVAL; |
| 2422 | |
| 2423 | if (offset < NETXEN_PCI_CRBSPACE) |
| 2424 | return -EINVAL; |
| 2425 | |
| 2426 | return 0; |
| 2427 | } |
| 2428 | |
| 2429 | static ssize_t |
| 2430 | netxen_sysfs_read_crb(struct kobject *kobj, struct bin_attribute *attr, |
| 2431 | char *buf, loff_t offset, size_t size) |
| 2432 | { |
| 2433 | struct device *dev = container_of(kobj, struct device, kobj); |
| 2434 | struct netxen_adapter *adapter = dev_get_drvdata(dev); |
| 2435 | u32 data; |
| 2436 | int ret; |
| 2437 | |
| 2438 | ret = netxen_sysfs_validate_crb(adapter, offset, size); |
| 2439 | if (ret != 0) |
| 2440 | return ret; |
| 2441 | |
| 2442 | data = NXRD32(adapter, offset); |
| 2443 | memcpy(buf, &data, size); |
| 2444 | return size; |
| 2445 | } |
| 2446 | |
| 2447 | static ssize_t |
| 2448 | netxen_sysfs_write_crb(struct kobject *kobj, struct bin_attribute *attr, |
| 2449 | char *buf, loff_t offset, size_t size) |
| 2450 | { |
| 2451 | struct device *dev = container_of(kobj, struct device, kobj); |
| 2452 | struct netxen_adapter *adapter = dev_get_drvdata(dev); |
| 2453 | u32 data; |
| 2454 | int ret; |
| 2455 | |
| 2456 | ret = netxen_sysfs_validate_crb(adapter, offset, size); |
| 2457 | if (ret != 0) |
| 2458 | return ret; |
| 2459 | |
| 2460 | memcpy(&data, buf, size); |
| 2461 | NXWR32(adapter, offset, data); |
| 2462 | return size; |
| 2463 | } |
| 2464 | |
| 2465 | static int |
| 2466 | netxen_sysfs_validate_mem(struct netxen_adapter *adapter, |
| 2467 | loff_t offset, size_t size) |
| 2468 | { |
| 2469 | if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)) |
| 2470 | return -EIO; |
| 2471 | |
| 2472 | if ((size != 8) || (offset & 0x7)) |
| 2473 | return -EIO; |
| 2474 | |
| 2475 | return 0; |
| 2476 | } |
| 2477 | |
| 2478 | static ssize_t |
| 2479 | netxen_sysfs_read_mem(struct kobject *kobj, struct bin_attribute *attr, |
| 2480 | char *buf, loff_t offset, size_t size) |
| 2481 | { |
| 2482 | struct device *dev = container_of(kobj, struct device, kobj); |
| 2483 | struct netxen_adapter *adapter = dev_get_drvdata(dev); |
| 2484 | u64 data; |
| 2485 | int ret; |
| 2486 | |
| 2487 | ret = netxen_sysfs_validate_mem(adapter, offset, size); |
| 2488 | if (ret != 0) |
| 2489 | return ret; |
| 2490 | |
| 2491 | if (adapter->pci_mem_read(adapter, offset, &data)) |
| 2492 | return -EIO; |
| 2493 | |
| 2494 | memcpy(buf, &data, size); |
| 2495 | |
| 2496 | return size; |
| 2497 | } |
| 2498 | |
| 2499 | ssize_t netxen_sysfs_write_mem(struct kobject *kobj, |
| 2500 | struct bin_attribute *attr, char *buf, |
| 2501 | loff_t offset, size_t size) |
| 2502 | { |
| 2503 | struct device *dev = container_of(kobj, struct device, kobj); |
| 2504 | struct netxen_adapter *adapter = dev_get_drvdata(dev); |
| 2505 | u64 data; |
| 2506 | int ret; |
| 2507 | |
| 2508 | ret = netxen_sysfs_validate_mem(adapter, offset, size); |
| 2509 | if (ret != 0) |
| 2510 | return ret; |
| 2511 | |
| 2512 | memcpy(&data, buf, size); |
| 2513 | |
| 2514 | if (adapter->pci_mem_write(adapter, offset, data)) |
| 2515 | return -EIO; |
| 2516 | |
| 2517 | return size; |
| 2518 | } |
| 2519 | |
| 2520 | |
| 2521 | static struct bin_attribute bin_attr_crb = { |
| 2522 | .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)}, |
| 2523 | .size = 0, |
| 2524 | .read = netxen_sysfs_read_crb, |
| 2525 | .write = netxen_sysfs_write_crb, |
| 2526 | }; |
| 2527 | |
| 2528 | static struct bin_attribute bin_attr_mem = { |
| 2529 | .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)}, |
| 2530 | .size = 0, |
| 2531 | .read = netxen_sysfs_read_mem, |
| 2532 | .write = netxen_sysfs_write_mem, |
| 2533 | }; |
| 2534 | |
Randy Dunlap | 0531d7b8 | 2009-10-26 12:09:45 +0000 | [diff] [blame] | 2535 | #ifdef CONFIG_MODULES |
Narender Kumar | caa2dd5 | 2009-10-16 15:50:11 +0000 | [diff] [blame] | 2536 | static ssize_t |
| 2537 | netxen_store_auto_fw_reset(struct module_attribute *mattr, |
| 2538 | struct module *mod, const char *buf, size_t count) |
| 2539 | |
| 2540 | { |
| 2541 | unsigned long new; |
| 2542 | |
| 2543 | if (strict_strtoul(buf, 16, &new)) |
| 2544 | return -EINVAL; |
| 2545 | |
| 2546 | if ((new == AUTO_FW_RESET_ENABLED) || (new == AUTO_FW_RESET_DISABLED)) { |
| 2547 | auto_fw_reset = new; |
| 2548 | return count; |
| 2549 | } |
| 2550 | |
| 2551 | return -EINVAL; |
| 2552 | } |
| 2553 | |
| 2554 | static ssize_t |
| 2555 | netxen_show_auto_fw_reset(struct module_attribute *mattr, |
| 2556 | struct module *mod, char *buf) |
| 2557 | |
| 2558 | { |
| 2559 | if (auto_fw_reset == AUTO_FW_RESET_ENABLED) |
| 2560 | return sprintf(buf, "enabled\n"); |
| 2561 | else |
| 2562 | return sprintf(buf, "disabled\n"); |
| 2563 | } |
| 2564 | |
| 2565 | static struct module_attribute mod_attr_fw_reset = { |
| 2566 | .attr = {.name = "auto_fw_reset", .mode = (S_IRUGO | S_IWUSR)}, |
| 2567 | .show = netxen_show_auto_fw_reset, |
| 2568 | .store = netxen_store_auto_fw_reset, |
| 2569 | }; |
Randy Dunlap | 0531d7b8 | 2009-10-26 12:09:45 +0000 | [diff] [blame] | 2570 | #endif |
Narender Kumar | caa2dd5 | 2009-10-16 15:50:11 +0000 | [diff] [blame] | 2571 | |
Narender Kumar | fa3ce35 | 2009-08-24 19:23:28 +0000 | [diff] [blame] | 2572 | static void |
| 2573 | netxen_create_sysfs_entries(struct netxen_adapter *adapter) |
| 2574 | { |
| 2575 | struct net_device *netdev = adapter->netdev; |
| 2576 | struct device *dev = &netdev->dev; |
| 2577 | |
| 2578 | if (adapter->capabilities & NX_FW_CAPABILITY_BDG) { |
| 2579 | /* bridged_mode control */ |
| 2580 | if (device_create_file(dev, &dev_attr_bridged_mode)) { |
| 2581 | dev_warn(&netdev->dev, |
| 2582 | "failed to create bridged_mode sysfs entry\n"); |
| 2583 | } |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | static void |
| 2588 | netxen_remove_sysfs_entries(struct netxen_adapter *adapter) |
| 2589 | { |
| 2590 | struct net_device *netdev = adapter->netdev; |
| 2591 | struct device *dev = &netdev->dev; |
| 2592 | |
| 2593 | if (adapter->capabilities & NX_FW_CAPABILITY_BDG) |
| 2594 | device_remove_file(dev, &dev_attr_bridged_mode); |
| 2595 | } |
| 2596 | |
Dhananjay Phadke | 70f9cf8 | 2009-10-13 05:31:45 +0000 | [diff] [blame] | 2597 | static void |
| 2598 | netxen_create_diag_entries(struct netxen_adapter *adapter) |
| 2599 | { |
| 2600 | struct pci_dev *pdev = adapter->pdev; |
| 2601 | struct device *dev; |
| 2602 | |
| 2603 | dev = &pdev->dev; |
| 2604 | if (device_create_file(dev, &dev_attr_diag_mode)) |
| 2605 | dev_info(dev, "failed to create diag_mode sysfs entry\n"); |
| 2606 | if (device_create_bin_file(dev, &bin_attr_crb)) |
| 2607 | dev_info(dev, "failed to create crb sysfs entry\n"); |
| 2608 | if (device_create_bin_file(dev, &bin_attr_mem)) |
| 2609 | dev_info(dev, "failed to create mem sysfs entry\n"); |
| 2610 | } |
| 2611 | |
| 2612 | |
| 2613 | static void |
| 2614 | netxen_remove_diag_entries(struct netxen_adapter *adapter) |
| 2615 | { |
| 2616 | struct pci_dev *pdev = adapter->pdev; |
| 2617 | struct device *dev = &pdev->dev; |
| 2618 | |
| 2619 | device_remove_file(dev, &dev_attr_diag_mode); |
| 2620 | device_remove_bin_file(dev, &bin_attr_crb); |
| 2621 | device_remove_bin_file(dev, &bin_attr_mem); |
| 2622 | } |
| 2623 | |
Dhananjay Phadke | 044824d | 2009-07-28 09:10:03 +0000 | [diff] [blame] | 2624 | #ifdef CONFIG_INET |
| 2625 | |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2626 | #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops) |
| 2627 | |
| 2628 | static int |
| 2629 | netxen_destip_supported(struct netxen_adapter *adapter) |
| 2630 | { |
| 2631 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 2632 | return 0; |
| 2633 | |
| 2634 | if (adapter->ahw.cut_through) |
| 2635 | return 0; |
| 2636 | |
| 2637 | return 1; |
| 2638 | } |
| 2639 | |
Amit Kumar Salecha | d0725e4 | 2009-09-05 17:43:09 +0000 | [diff] [blame] | 2640 | static void |
| 2641 | netxen_config_indev_addr(struct net_device *dev, unsigned long event) |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2642 | { |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2643 | struct in_device *indev; |
Amit Kumar Salecha | d0725e4 | 2009-09-05 17:43:09 +0000 | [diff] [blame] | 2644 | struct netxen_adapter *adapter = netdev_priv(dev); |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2645 | |
Amit Kumar Salecha | 3db7675 | 2009-09-09 18:12:37 -0700 | [diff] [blame] | 2646 | if (!netxen_destip_supported(adapter)) |
Amit Kumar Salecha | d0725e4 | 2009-09-05 17:43:09 +0000 | [diff] [blame] | 2647 | return; |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2648 | |
| 2649 | indev = in_dev_get(dev); |
| 2650 | if (!indev) |
Amit Kumar Salecha | d0725e4 | 2009-09-05 17:43:09 +0000 | [diff] [blame] | 2651 | return; |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2652 | |
| 2653 | for_ifa(indev) { |
| 2654 | switch (event) { |
| 2655 | case NETDEV_UP: |
| 2656 | netxen_config_ipaddr(adapter, |
| 2657 | ifa->ifa_address, NX_IP_UP); |
| 2658 | break; |
| 2659 | case NETDEV_DOWN: |
| 2660 | netxen_config_ipaddr(adapter, |
| 2661 | ifa->ifa_address, NX_IP_DOWN); |
| 2662 | break; |
| 2663 | default: |
| 2664 | break; |
| 2665 | } |
| 2666 | } endfor_ifa(indev); |
| 2667 | |
| 2668 | in_dev_put(indev); |
Amit Kumar Salecha | d0725e4 | 2009-09-05 17:43:09 +0000 | [diff] [blame] | 2669 | return; |
| 2670 | } |
| 2671 | |
| 2672 | static int netxen_netdev_event(struct notifier_block *this, |
| 2673 | unsigned long event, void *ptr) |
| 2674 | { |
| 2675 | struct netxen_adapter *adapter; |
| 2676 | struct net_device *dev = (struct net_device *)ptr; |
| 2677 | |
| 2678 | recheck: |
| 2679 | if (dev == NULL) |
| 2680 | goto done; |
| 2681 | |
| 2682 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 2683 | dev = vlan_dev_real_dev(dev); |
| 2684 | goto recheck; |
| 2685 | } |
| 2686 | |
| 2687 | if (!is_netxen_netdev(dev)) |
| 2688 | goto done; |
| 2689 | |
| 2690 | adapter = netdev_priv(dev); |
| 2691 | |
| 2692 | if (!adapter) |
| 2693 | goto done; |
| 2694 | |
| 2695 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) |
| 2696 | goto done; |
| 2697 | |
| 2698 | netxen_config_indev_addr(dev, event); |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2699 | done: |
| 2700 | return NOTIFY_DONE; |
| 2701 | } |
| 2702 | |
| 2703 | static int |
| 2704 | netxen_inetaddr_event(struct notifier_block *this, |
| 2705 | unsigned long event, void *ptr) |
| 2706 | { |
| 2707 | struct netxen_adapter *adapter; |
| 2708 | struct net_device *dev; |
| 2709 | |
| 2710 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; |
| 2711 | |
| 2712 | dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; |
| 2713 | |
| 2714 | recheck: |
| 2715 | if (dev == NULL || !netif_running(dev)) |
| 2716 | goto done; |
| 2717 | |
| 2718 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 2719 | dev = vlan_dev_real_dev(dev); |
| 2720 | goto recheck; |
| 2721 | } |
| 2722 | |
| 2723 | if (!is_netxen_netdev(dev)) |
| 2724 | goto done; |
| 2725 | |
| 2726 | adapter = netdev_priv(dev); |
| 2727 | |
| 2728 | if (!adapter || !netxen_destip_supported(adapter)) |
| 2729 | goto done; |
| 2730 | |
| 2731 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) |
| 2732 | goto done; |
| 2733 | |
| 2734 | switch (event) { |
| 2735 | case NETDEV_UP: |
| 2736 | netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP); |
| 2737 | break; |
| 2738 | case NETDEV_DOWN: |
| 2739 | netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN); |
| 2740 | break; |
| 2741 | default: |
| 2742 | break; |
| 2743 | } |
| 2744 | |
| 2745 | done: |
| 2746 | return NOTIFY_DONE; |
| 2747 | } |
| 2748 | |
| 2749 | static struct notifier_block netxen_netdev_cb = { |
| 2750 | .notifier_call = netxen_netdev_event, |
| 2751 | }; |
| 2752 | |
| 2753 | static struct notifier_block netxen_inetaddr_cb = { |
| 2754 | .notifier_call = netxen_inetaddr_event, |
| 2755 | }; |
Randy Dunlap | 9feae56 | 2009-09-11 12:41:04 +0000 | [diff] [blame] | 2756 | #else |
| 2757 | static void |
| 2758 | netxen_config_indev_addr(struct net_device *dev, unsigned long event) |
| 2759 | { } |
Dhananjay Phadke | 044824d | 2009-07-28 09:10:03 +0000 | [diff] [blame] | 2760 | #endif |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2761 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2762 | static struct pci_driver netxen_driver = { |
| 2763 | .name = netxen_nic_driver_name, |
| 2764 | .id_table = netxen_pci_tbl, |
| 2765 | .probe = netxen_nic_probe, |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 2766 | .remove = __devexit_p(netxen_nic_remove), |
Dhananjay Phadke | 01542cd | 2009-06-22 20:26:20 +0000 | [diff] [blame] | 2767 | #ifdef CONFIG_PM |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 2768 | .suspend = netxen_nic_suspend, |
Amit Kumar Salecha | 22b5794 | 2009-08-23 08:35:12 +0000 | [diff] [blame] | 2769 | .resume = netxen_nic_resume, |
Dhananjay Phadke | 01542cd | 2009-06-22 20:26:20 +0000 | [diff] [blame] | 2770 | #endif |
Amit Kumar Salecha | 22b5794 | 2009-08-23 08:35:12 +0000 | [diff] [blame] | 2771 | .shutdown = netxen_nic_shutdown |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2772 | }; |
| 2773 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2774 | static int __init netxen_init_module(void) |
| 2775 | { |
Randy Dunlap | 0531d7b8 | 2009-10-26 12:09:45 +0000 | [diff] [blame] | 2776 | #ifdef CONFIG_MODULES |
Narender Kumar | caa2dd5 | 2009-10-16 15:50:11 +0000 | [diff] [blame] | 2777 | struct module *mod = THIS_MODULE; |
Randy Dunlap | 0531d7b8 | 2009-10-26 12:09:45 +0000 | [diff] [blame] | 2778 | #endif |
Narender Kumar | caa2dd5 | 2009-10-16 15:50:11 +0000 | [diff] [blame] | 2779 | |
Dhananjay Phadke | ff4fbd4 | 2009-03-13 14:52:06 +0000 | [diff] [blame] | 2780 | printk(KERN_INFO "%s\n", netxen_nic_driver_string); |
| 2781 | |
Dhananjay Phadke | 044824d | 2009-07-28 09:10:03 +0000 | [diff] [blame] | 2782 | #ifdef CONFIG_INET |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2783 | register_netdevice_notifier(&netxen_netdev_cb); |
| 2784 | register_inetaddr_notifier(&netxen_inetaddr_cb); |
Dhananjay Phadke | 044824d | 2009-07-28 09:10:03 +0000 | [diff] [blame] | 2785 | #endif |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2786 | |
Randy Dunlap | 0531d7b8 | 2009-10-26 12:09:45 +0000 | [diff] [blame] | 2787 | #ifdef CONFIG_MODULES |
Narender Kumar | caa2dd5 | 2009-10-16 15:50:11 +0000 | [diff] [blame] | 2788 | if (sysfs_create_file(&mod->mkobj.kobj, &mod_attr_fw_reset.attr)) |
| 2789 | printk(KERN_ERR "%s: Failed to create auto_fw_reset " |
| 2790 | "sysfs entry.", netxen_nic_driver_name); |
Randy Dunlap | 0531d7b8 | 2009-10-26 12:09:45 +0000 | [diff] [blame] | 2791 | #endif |
Narender Kumar | caa2dd5 | 2009-10-16 15:50:11 +0000 | [diff] [blame] | 2792 | |
Amit S. Kale | 184231b | 2007-01-22 06:52:53 -0800 | [diff] [blame] | 2793 | return pci_register_driver(&netxen_driver); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | module_init(netxen_init_module); |
| 2797 | |
| 2798 | static void __exit netxen_exit_module(void) |
| 2799 | { |
Randy Dunlap | 0531d7b8 | 2009-10-26 12:09:45 +0000 | [diff] [blame] | 2800 | #ifdef CONFIG_MODULES |
Narender Kumar | caa2dd5 | 2009-10-16 15:50:11 +0000 | [diff] [blame] | 2801 | struct module *mod = THIS_MODULE; |
| 2802 | |
| 2803 | sysfs_remove_file(&mod->mkobj.kobj, &mod_attr_fw_reset.attr); |
Randy Dunlap | 0531d7b8 | 2009-10-26 12:09:45 +0000 | [diff] [blame] | 2804 | #endif |
Narender Kumar | caa2dd5 | 2009-10-16 15:50:11 +0000 | [diff] [blame] | 2805 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2806 | pci_unregister_driver(&netxen_driver); |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2807 | |
Dhananjay Phadke | 044824d | 2009-07-28 09:10:03 +0000 | [diff] [blame] | 2808 | #ifdef CONFIG_INET |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2809 | unregister_inetaddr_notifier(&netxen_inetaddr_cb); |
| 2810 | unregister_netdevice_notifier(&netxen_netdev_cb); |
Dhananjay Phadke | 044824d | 2009-07-28 09:10:03 +0000 | [diff] [blame] | 2811 | #endif |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | module_exit(netxen_exit_module); |