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