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