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