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