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