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); |
| 757 | if (err <= 0) |
| 758 | return err; |
| 759 | |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 760 | if (first_boot != 0x55555555) { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 761 | NXWR32(adapter, CRB_CMDPEG_STATE, 0); |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 762 | netxen_pinit_from_rom(adapter, 0); |
| 763 | msleep(1); |
| 764 | } |
Dhananjay Phadke | 567c6c4 | 2009-03-02 16:02:17 +0000 | [diff] [blame] | 765 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 766 | NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555); |
Dhananjay Phadke | 567c6c4 | 2009-03-02 16:02:17 +0000 | [diff] [blame] | 767 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 768 | netxen_set_port_mode(adapter); |
| 769 | |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 770 | netxen_load_firmware(adapter); |
| 771 | |
| 772 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
| 773 | |
| 774 | /* Initialize multicast addr pool owners */ |
| 775 | val = 0x7654; |
Dhananjay Phadke | 1e2d005 | 2009-03-09 08:50:56 +0000 | [diff] [blame] | 776 | if (adapter->ahw.port_type == NETXEN_NIC_XGBE) |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 777 | val |= 0x0f000000; |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 778 | NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val); |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 779 | |
| 780 | } |
| 781 | |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 782 | err = netxen_init_dummy_dma(adapter); |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 783 | if (err) |
| 784 | return err; |
| 785 | |
| 786 | /* |
| 787 | * Tell the hardware our version number. |
| 788 | */ |
| 789 | val = (_NETXEN_NIC_LINUX_MAJOR << 16) |
| 790 | | ((_NETXEN_NIC_LINUX_MINOR << 8)) |
| 791 | | (_NETXEN_NIC_LINUX_SUBVERSION); |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 792 | NXWR32(adapter, CRB_DRIVER_VERSION, val); |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 793 | |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 794 | wait_init: |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 795 | /* Handshake with the card before we register the devices. */ |
| 796 | err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
| 797 | if (err) { |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 798 | netxen_free_dummy_dma(adapter); |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 799 | return err; |
| 800 | } |
| 801 | |
Dhananjay Phadke | 68b3cae | 2009-07-26 20:07:36 +0000 | [diff] [blame] | 802 | nx_update_dma_mask(adapter); |
| 803 | |
| 804 | netxen_nic_get_firmware_info(adapter); |
| 805 | |
Dhananjay Phadke | ba599d4 | 2009-02-24 16:38:22 -0800 | [diff] [blame] | 806 | return 0; |
| 807 | } |
| 808 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 809 | static int |
| 810 | netxen_nic_request_irq(struct netxen_adapter *adapter) |
| 811 | { |
| 812 | irq_handler_t handler; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 813 | struct nx_host_sds_ring *sds_ring; |
| 814 | int err, ring; |
| 815 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 816 | unsigned long flags = IRQF_SAMPLE_RANDOM; |
| 817 | struct net_device *netdev = adapter->netdev; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 818 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 819 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 820 | if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) |
| 821 | handler = netxen_msix_intr; |
| 822 | else if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 823 | handler = netxen_msi_intr; |
| 824 | else { |
| 825 | flags |= IRQF_SHARED; |
| 826 | handler = netxen_intr; |
| 827 | } |
| 828 | adapter->irq = netdev->irq; |
| 829 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 830 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 831 | sds_ring = &recv_ctx->sds_rings[ring]; |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 832 | sprintf(sds_ring->name, "%s[%d]", netdev->name, ring); |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 833 | err = request_irq(sds_ring->irq, handler, |
| 834 | flags, sds_ring->name, sds_ring); |
| 835 | if (err) |
| 836 | return err; |
| 837 | } |
| 838 | |
| 839 | return 0; |
| 840 | } |
| 841 | |
| 842 | static void |
| 843 | netxen_nic_free_irq(struct netxen_adapter *adapter) |
| 844 | { |
| 845 | int ring; |
| 846 | struct nx_host_sds_ring *sds_ring; |
| 847 | |
| 848 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; |
| 849 | |
| 850 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 851 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 852 | free_irq(sds_ring->irq, sds_ring); |
| 853 | } |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Dhananjay Phadke | ca2ef33 | 2009-07-26 20:07:38 +0000 | [diff] [blame] | 856 | static void |
| 857 | netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter) |
| 858 | { |
| 859 | adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT; |
| 860 | adapter->coal.normal.data.rx_time_us = |
| 861 | NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US; |
| 862 | adapter->coal.normal.data.rx_packets = |
| 863 | NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS; |
| 864 | adapter->coal.normal.data.tx_time_us = |
| 865 | NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US; |
| 866 | adapter->coal.normal.data.tx_packets = |
| 867 | NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS; |
| 868 | } |
| 869 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 870 | static int |
| 871 | netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev) |
| 872 | { |
| 873 | int err; |
| 874 | |
| 875 | err = adapter->init_port(adapter, adapter->physical_port); |
| 876 | if (err) { |
| 877 | printk(KERN_ERR "%s: Failed to initialize port %d\n", |
| 878 | netxen_nic_driver_name, adapter->portnum); |
| 879 | return err; |
| 880 | } |
Dhananjay Phadke | 3d0a3cc | 2009-05-05 19:05:08 +0000 | [diff] [blame] | 881 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 882 | adapter->macaddr_set(adapter, netdev->dev_addr); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 883 | |
Dhananjay Phadke | 3d0a3cc | 2009-05-05 19:05:08 +0000 | [diff] [blame] | 884 | adapter->set_multi(netdev); |
| 885 | adapter->set_mtu(adapter, netdev->mtu); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 886 | |
| 887 | adapter->ahw.linkup = 0; |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 888 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 889 | if (adapter->max_sds_rings > 1) |
| 890 | netxen_config_rss(adapter, 1); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 891 | |
Dhananjay Phadke | ca2ef33 | 2009-07-26 20:07:38 +0000 | [diff] [blame] | 892 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 893 | netxen_config_intr_coalesce(adapter); |
| 894 | |
Narender Kumar | 1bb482f | 2009-08-23 08:35:09 +0000 | [diff] [blame^] | 895 | if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO) |
| 896 | netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED); |
| 897 | |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 898 | netxen_napi_enable(adapter); |
| 899 | |
Dhananjay Phadke | 5103c9f | 2009-04-28 15:29:09 +0000 | [diff] [blame] | 900 | if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION) |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 901 | netxen_linkevent_request(adapter, 1); |
Dhananjay Phadke | 3d0a3cc | 2009-05-05 19:05:08 +0000 | [diff] [blame] | 902 | else |
| 903 | netxen_nic_set_link_parameters(adapter); |
| 904 | |
| 905 | mod_timer(&adapter->watchdog_timer, jiffies); |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 906 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 907 | return 0; |
| 908 | } |
| 909 | |
| 910 | static void |
| 911 | netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev) |
| 912 | { |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 913 | spin_lock(&adapter->tx_clean_lock); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 914 | netif_carrier_off(netdev); |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 915 | netif_tx_disable(netdev); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 916 | |
| 917 | if (adapter->stop_port) |
| 918 | adapter->stop_port(adapter); |
| 919 | |
Dhananjay Phadke | 5cf4d32 | 2009-05-05 19:05:07 +0000 | [diff] [blame] | 920 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 921 | netxen_p3_free_mac_list(adapter); |
| 922 | |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 923 | netxen_napi_disable(adapter); |
| 924 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 925 | netxen_release_tx_buffers(adapter); |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 926 | spin_unlock(&adapter->tx_clean_lock); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 927 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 928 | del_timer_sync(&adapter->watchdog_timer); |
| 929 | } |
| 930 | |
| 931 | |
| 932 | static int |
| 933 | netxen_nic_attach(struct netxen_adapter *adapter) |
| 934 | { |
| 935 | struct net_device *netdev = adapter->netdev; |
| 936 | struct pci_dev *pdev = adapter->pdev; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 937 | int err, ring; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 938 | struct nx_host_rds_ring *rds_ring; |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 939 | struct nx_host_tx_ring *tx_ring; |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 940 | |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 941 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) |
| 942 | return 0; |
| 943 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 944 | err = netxen_init_firmware(adapter); |
Dhananjay Phadke | 232e7d6 | 2009-08-13 07:03:01 +0000 | [diff] [blame] | 945 | if (err) |
| 946 | return err; |
| 947 | |
| 948 | err = netxen_napi_add(adapter, netdev); |
| 949 | if (err) |
| 950 | return err; |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 951 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 952 | err = netxen_alloc_sw_resources(adapter); |
| 953 | if (err) { |
| 954 | printk(KERN_ERR "%s: Error in setting sw resources\n", |
| 955 | netdev->name); |
| 956 | return err; |
| 957 | } |
| 958 | |
| 959 | netxen_nic_clear_stats(adapter); |
| 960 | |
| 961 | err = netxen_alloc_hw_resources(adapter); |
| 962 | if (err) { |
| 963 | printk(KERN_ERR "%s: Error in setting hw resources\n", |
| 964 | netdev->name); |
| 965 | goto err_out_free_sw; |
| 966 | } |
| 967 | |
Dhananjay Phadke | 4f96b98 | 2009-07-26 20:07:42 +0000 | [diff] [blame] | 968 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 969 | tx_ring = adapter->tx_ring; |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 970 | tx_ring->crb_cmd_producer = crb_cmd_producer[adapter->portnum]; |
| 971 | tx_ring->crb_cmd_consumer = crb_cmd_consumer[adapter->portnum]; |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 972 | |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 973 | tx_ring->producer = 0; |
| 974 | tx_ring->sw_consumer = 0; |
| 975 | |
| 976 | netxen_nic_update_cmd_producer(adapter, tx_ring); |
| 977 | netxen_nic_update_cmd_consumer(adapter, tx_ring); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 978 | } |
| 979 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 980 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 981 | rds_ring = &adapter->recv_ctx.rds_rings[ring]; |
| 982 | netxen_post_rx_buffers(adapter, ring, rds_ring); |
| 983 | } |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 984 | |
| 985 | err = netxen_nic_request_irq(adapter); |
| 986 | if (err) { |
| 987 | dev_err(&pdev->dev, "%s: failed to setup interrupt\n", |
| 988 | netdev->name); |
| 989 | goto err_out_free_rxbuf; |
| 990 | } |
| 991 | |
Dhananjay Phadke | ca2ef33 | 2009-07-26 20:07:38 +0000 | [diff] [blame] | 992 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 993 | netxen_nic_init_coalesce_defaults(adapter); |
| 994 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 995 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; |
| 996 | return 0; |
| 997 | |
| 998 | err_out_free_rxbuf: |
| 999 | netxen_release_rx_buffers(adapter); |
| 1000 | netxen_free_hw_resources(adapter); |
| 1001 | err_out_free_sw: |
| 1002 | netxen_free_sw_resources(adapter); |
| 1003 | return err; |
| 1004 | } |
| 1005 | |
| 1006 | static void |
| 1007 | netxen_nic_detach(struct netxen_adapter *adapter) |
| 1008 | { |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1009 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) |
| 1010 | return; |
| 1011 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1012 | netxen_free_hw_resources(adapter); |
Dhananjay Phadke | cf981ff | 2009-07-17 15:27:06 +0000 | [diff] [blame] | 1013 | netxen_release_rx_buffers(adapter); |
Dhananjay Phadke | be339ae | 2009-05-08 22:02:28 +0000 | [diff] [blame] | 1014 | netxen_nic_free_irq(adapter); |
Dhananjay Phadke | 232e7d6 | 2009-08-13 07:03:01 +0000 | [diff] [blame] | 1015 | netxen_napi_del(adapter); |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1016 | netxen_free_sw_resources(adapter); |
| 1017 | |
| 1018 | adapter->is_up = 0; |
| 1019 | } |
| 1020 | |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1021 | int |
| 1022 | netxen_nic_reset_context(struct netxen_adapter *adapter) |
| 1023 | { |
| 1024 | int err = 0; |
| 1025 | struct net_device *netdev = adapter->netdev; |
| 1026 | |
| 1027 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
| 1028 | |
| 1029 | if (netif_running(netdev)) |
| 1030 | netxen_nic_down(adapter, netdev); |
| 1031 | |
| 1032 | netxen_nic_detach(adapter); |
| 1033 | |
| 1034 | err = netxen_nic_attach(adapter); |
| 1035 | if (err) |
| 1036 | goto done; |
| 1037 | |
| 1038 | if (netif_running(netdev)) |
| 1039 | err = netxen_nic_up(adapter, netdev); |
| 1040 | } |
| 1041 | done: |
| 1042 | return err; |
| 1043 | } |
| 1044 | |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1045 | static int |
| 1046 | netxen_setup_netdev(struct netxen_adapter *adapter, |
| 1047 | struct net_device *netdev) |
| 1048 | { |
| 1049 | int err = 0; |
| 1050 | struct pci_dev *pdev = adapter->pdev; |
| 1051 | |
| 1052 | adapter->rx_csum = 1; |
| 1053 | adapter->mc_enabled = 0; |
| 1054 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 1055 | adapter->max_mc_count = 38; |
| 1056 | else |
| 1057 | adapter->max_mc_count = 16; |
| 1058 | |
| 1059 | netdev->netdev_ops = &netxen_netdev_ops; |
| 1060 | netdev->watchdog_timeo = 2*HZ; |
| 1061 | |
| 1062 | netxen_nic_change_mtu(netdev, netdev->mtu); |
| 1063 | |
| 1064 | SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops); |
| 1065 | |
| 1066 | netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO); |
| 1067 | netdev->features |= (NETIF_F_GRO); |
| 1068 | netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO); |
| 1069 | |
| 1070 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
| 1071 | netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 1072 | netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 1073 | } |
| 1074 | |
| 1075 | if (adapter->pci_using_dac) { |
| 1076 | netdev->features |= NETIF_F_HIGHDMA; |
| 1077 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 1078 | } |
| 1079 | |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1080 | if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX) |
| 1081 | netdev->features |= (NETIF_F_HW_VLAN_TX); |
| 1082 | |
Narender Kumar | 1bb482f | 2009-08-23 08:35:09 +0000 | [diff] [blame^] | 1083 | if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO) |
| 1084 | netdev->features |= NETIF_F_LRO; |
| 1085 | |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1086 | netdev->irq = adapter->msix_entries[0].vector; |
| 1087 | |
| 1088 | err = netxen_napi_add(adapter, netdev); |
| 1089 | if (err) |
| 1090 | return err; |
| 1091 | |
| 1092 | init_timer(&adapter->watchdog_timer); |
| 1093 | adapter->watchdog_timer.function = &netxen_watchdog; |
| 1094 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 1095 | INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task); |
| 1096 | INIT_WORK(&adapter->tx_timeout_task, netxen_reset_task); |
| 1097 | |
| 1098 | if (netxen_read_mac_addr(adapter)) |
| 1099 | dev_warn(&pdev->dev, "failed to read mac addr\n"); |
| 1100 | |
| 1101 | netif_carrier_off(netdev); |
| 1102 | netif_stop_queue(netdev); |
| 1103 | |
| 1104 | err = register_netdev(netdev); |
| 1105 | if (err) { |
| 1106 | dev_err(&pdev->dev, "failed to register net device\n"); |
| 1107 | return err; |
| 1108 | } |
| 1109 | |
| 1110 | return 0; |
| 1111 | } |
| 1112 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1113 | static int __devinit |
| 1114 | netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 1115 | { |
| 1116 | struct net_device *netdev = NULL; |
| 1117 | struct netxen_adapter *adapter = NULL; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1118 | int i = 0, err; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1119 | int pci_func_id = PCI_FUNC(pdev->devfn); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1120 | uint8_t revision_id; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1121 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1122 | if (pdev->class != 0x020000) { |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 1123 | printk(KERN_DEBUG "NetXen function %d, class %x will not " |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1124 | "be enabled.\n",pci_func_id, pdev->class); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1125 | return -ENODEV; |
| 1126 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1127 | |
Dhananjay Phadke | 11d89d6 | 2008-08-08 00:08:45 -0700 | [diff] [blame] | 1128 | if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) { |
| 1129 | printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x" |
| 1130 | "will not be enabled.\n", |
| 1131 | NX_P3_A0, NX_P3_B1); |
| 1132 | return -ENODEV; |
| 1133 | } |
| 1134 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1135 | if ((err = pci_enable_device(pdev))) |
| 1136 | return err; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1137 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1138 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 1139 | err = -ENODEV; |
| 1140 | goto err_out_disable_pdev; |
| 1141 | } |
| 1142 | |
| 1143 | if ((err = pci_request_regions(pdev, netxen_nic_driver_name))) |
| 1144 | goto err_out_disable_pdev; |
| 1145 | |
| 1146 | pci_set_master(pdev); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1147 | |
| 1148 | netdev = alloc_etherdev(sizeof(struct netxen_adapter)); |
| 1149 | if(!netdev) { |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1150 | dev_err(&pdev->dev, "failed to allocate net_device\n"); |
| 1151 | err = -ENOMEM; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1152 | goto err_out_free_res; |
| 1153 | } |
| 1154 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1155 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 1156 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1157 | adapter = netdev_priv(netdev); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1158 | adapter->netdev = netdev; |
| 1159 | adapter->pdev = pdev; |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 1160 | adapter->ahw.pci_func = pci_func_id; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1161 | |
| 1162 | revision_id = pdev->revision; |
| 1163 | adapter->ahw.revision_id = revision_id; |
| 1164 | |
Dhananjay Phadke | 50c643e | 2009-08-01 21:36:16 +0000 | [diff] [blame] | 1165 | err = nx_set_dma_mask(adapter); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1166 | if (err) |
| 1167 | goto err_out_free_netdev; |
| 1168 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1169 | rwlock_init(&adapter->adapter_lock); |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1170 | spin_lock_init(&adapter->tx_clean_lock); |
Dhananjay Phadke | 5cf4d32 | 2009-05-05 19:05:07 +0000 | [diff] [blame] | 1171 | INIT_LIST_HEAD(&adapter->mac_list); |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 1172 | |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 1173 | err = netxen_setup_pci_map(adapter); |
| 1174 | if (err) |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1175 | goto err_out_free_netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1176 | |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 1177 | /* This will be reset for mezz cards */ |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1178 | adapter->portnum = pci_func_id; |
| 1179 | |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1180 | err = netxen_nic_get_board_info(adapter); |
| 1181 | if (err) { |
| 1182 | dev_err(&pdev->dev, "Error getting board config info.\n"); |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 1183 | goto err_out_iounmap; |
| 1184 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1185 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1186 | netxen_initialize_adapter_ops(adapter); |
| 1187 | |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 1188 | /* Mezz cards have PCI function 0,2,3 enabled */ |
Dhananjay Phadke | 1e2d005 | 2009-03-09 08:50:56 +0000 | [diff] [blame] | 1189 | switch (adapter->ahw.board_type) { |
Dhananjay Phadke | dc515f2 | 2008-06-15 22:59:43 -0700 | [diff] [blame] | 1190 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: |
| 1191 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: |
| 1192 | if (pci_func_id >= 2) |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 1193 | adapter->portnum = pci_func_id - 2; |
Dhananjay Phadke | dc515f2 | 2008-06-15 22:59:43 -0700 | [diff] [blame] | 1194 | break; |
| 1195 | default: |
| 1196 | break; |
| 1197 | } |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 1198 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1199 | err = netxen_start_firmware(adapter, 1); |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1200 | if (err) |
| 1201 | goto err_out_iounmap; |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1202 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1203 | /* |
| 1204 | * See if the firmware gave us a virtual-physical port mapping. |
| 1205 | */ |
| 1206 | adapter->physical_port = adapter->portnum; |
Dhananjay Phadke | 4f96b98 | 2009-07-26 20:07:42 +0000 | [diff] [blame] | 1207 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1208 | i = NXRD32(adapter, CRB_V2P(adapter->portnum)); |
Dhananjay Phadke | 044fad0 | 2009-02-24 03:42:59 -0800 | [diff] [blame] | 1209 | if (i != 0x55555555) |
| 1210 | adapter->physical_port = i; |
| 1211 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1212 | |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1213 | netxen_check_options(adapter); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1214 | |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 1215 | netxen_setup_intr(adapter); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1216 | |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1217 | err = netxen_setup_netdev(adapter, netdev); |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 1218 | if (err) |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1219 | goto err_out_disable_msi; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1220 | |
| 1221 | pci_set_drvdata(pdev, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1222 | |
Dhananjay Phadke | 1e2d005 | 2009-03-09 08:50:56 +0000 | [diff] [blame] | 1223 | switch (adapter->ahw.port_type) { |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1224 | case NETXEN_NIC_GBE: |
| 1225 | dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", |
| 1226 | adapter->netdev->name); |
| 1227 | break; |
| 1228 | case NETXEN_NIC_XGBE: |
| 1229 | dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", |
| 1230 | adapter->netdev->name); |
| 1231 | break; |
| 1232 | } |
| 1233 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1234 | return 0; |
| 1235 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1236 | err_out_disable_msi: |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 1237 | netxen_teardown_intr(adapter); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1238 | |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 1239 | netxen_free_dummy_dma(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1240 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1241 | err_out_iounmap: |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 1242 | netxen_cleanup_pci_map(adapter); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1243 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1244 | err_out_free_netdev: |
| 1245 | free_netdev(netdev); |
| 1246 | |
| 1247 | err_out_free_res: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1248 | pci_release_regions(pdev); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1249 | |
| 1250 | err_out_disable_pdev: |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1251 | pci_set_drvdata(pdev, NULL); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1252 | pci_disable_device(pdev); |
| 1253 | return err; |
| 1254 | } |
| 1255 | |
| 1256 | static void __devexit netxen_nic_remove(struct pci_dev *pdev) |
| 1257 | { |
| 1258 | struct netxen_adapter *adapter; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1259 | struct net_device *netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1260 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1261 | adapter = pci_get_drvdata(pdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1262 | if (adapter == NULL) |
| 1263 | return; |
| 1264 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1265 | netdev = adapter->netdev; |
| 1266 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1267 | unregister_netdev(netdev); |
| 1268 | |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1269 | cancel_work_sync(&adapter->watchdog_task); |
| 1270 | cancel_work_sync(&adapter->tx_timeout_task); |
| 1271 | |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1272 | netxen_nic_detach(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1273 | |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 1274 | if (adapter->portnum == 0) |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 1275 | netxen_free_dummy_dma(adapter); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1276 | |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 1277 | netxen_teardown_intr(adapter); |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 1278 | |
Dhananjay Phadke | 97daee8 | 2009-02-24 16:39:21 -0800 | [diff] [blame] | 1279 | netxen_cleanup_pci_map(adapter); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1280 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1281 | netxen_release_firmware(adapter); |
| 1282 | |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1283 | pci_release_regions(pdev); |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 1284 | pci_disable_device(pdev); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1285 | pci_set_drvdata(pdev, NULL); |
| 1286 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1287 | free_netdev(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1288 | } |
| 1289 | |
Dhananjay Phadke | 01542cd | 2009-06-22 20:26:20 +0000 | [diff] [blame] | 1290 | #ifdef CONFIG_PM |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1291 | static int |
| 1292 | netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state) |
| 1293 | { |
| 1294 | |
| 1295 | struct netxen_adapter *adapter = pci_get_drvdata(pdev); |
| 1296 | struct net_device *netdev = adapter->netdev; |
| 1297 | |
| 1298 | netif_device_detach(netdev); |
| 1299 | |
| 1300 | if (netif_running(netdev)) |
| 1301 | netxen_nic_down(adapter, netdev); |
| 1302 | |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1303 | cancel_work_sync(&adapter->watchdog_task); |
| 1304 | cancel_work_sync(&adapter->tx_timeout_task); |
| 1305 | |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1306 | netxen_nic_detach(adapter); |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1307 | |
| 1308 | pci_save_state(pdev); |
| 1309 | |
| 1310 | if (netxen_nic_wol_supported(adapter)) { |
| 1311 | pci_enable_wake(pdev, PCI_D3cold, 1); |
| 1312 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 1313 | } |
| 1314 | |
| 1315 | pci_disable_device(pdev); |
| 1316 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 1317 | |
| 1318 | return 0; |
| 1319 | } |
| 1320 | |
| 1321 | static int |
| 1322 | netxen_nic_resume(struct pci_dev *pdev) |
| 1323 | { |
| 1324 | struct netxen_adapter *adapter = pci_get_drvdata(pdev); |
| 1325 | struct net_device *netdev = adapter->netdev; |
| 1326 | int err; |
| 1327 | |
| 1328 | pci_set_power_state(pdev, PCI_D0); |
| 1329 | pci_restore_state(pdev); |
| 1330 | |
| 1331 | err = pci_enable_device(pdev); |
| 1332 | if (err) |
| 1333 | return err; |
| 1334 | |
| 1335 | adapter->curr_window = 255; |
| 1336 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1337 | err = netxen_start_firmware(adapter, 0); |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1338 | if (err) { |
| 1339 | dev_err(&pdev->dev, "failed to start firmware\n"); |
| 1340 | return err; |
| 1341 | } |
| 1342 | |
| 1343 | if (netif_running(netdev)) { |
| 1344 | err = netxen_nic_attach(adapter); |
| 1345 | if (err) |
| 1346 | return err; |
| 1347 | |
| 1348 | err = netxen_nic_up(adapter, netdev); |
| 1349 | if (err) |
| 1350 | return err; |
| 1351 | |
| 1352 | netif_device_attach(netdev); |
| 1353 | } |
| 1354 | |
| 1355 | return 0; |
| 1356 | } |
Dhananjay Phadke | 01542cd | 2009-06-22 20:26:20 +0000 | [diff] [blame] | 1357 | #endif |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 1358 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1359 | static int netxen_nic_open(struct net_device *netdev) |
| 1360 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1361 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1362 | int err = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1363 | |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 1364 | if (adapter->driver_mismatch) |
| 1365 | return -EIO; |
| 1366 | |
Amit Kumar Salecha | 7042cd8 | 2009-07-27 11:15:54 -0700 | [diff] [blame] | 1367 | err = netxen_nic_attach(adapter); |
| 1368 | if (err) |
| 1369 | return err; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1370 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1371 | err = netxen_nic_up(adapter, netdev); |
| 1372 | if (err) |
| 1373 | goto err_out; |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1374 | |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 1375 | netif_start_queue(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1376 | |
| 1377 | return 0; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1378 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1379 | err_out: |
| 1380 | netxen_nic_detach(adapter); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1381 | return err; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | /* |
| 1385 | * netxen_nic_close - Disables a network interface entry point |
| 1386 | */ |
| 1387 | static int netxen_nic_close(struct net_device *netdev) |
| 1388 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1389 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1390 | |
Dhananjay Phadke | 9f5bc7f | 2009-03-09 08:50:54 +0000 | [diff] [blame] | 1391 | netxen_nic_down(adapter, netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1392 | return 0; |
| 1393 | } |
| 1394 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1395 | static void |
| 1396 | netxen_tso_check(struct net_device *netdev, |
| 1397 | struct nx_host_tx_ring *tx_ring, |
| 1398 | struct cmd_desc_type0 *first_desc, |
| 1399 | struct sk_buff *skb) |
Dhananjay Phadke | cd1f816 | 2008-07-21 19:44:09 -0700 | [diff] [blame] | 1400 | { |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1401 | u8 opcode = TX_ETHER_PKT; |
Dhananjay Phadke | cdff103 | 2009-01-26 12:34:57 -0800 | [diff] [blame] | 1402 | __be16 protocol = skb->protocol; |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1403 | u16 flags = 0, vid = 0; |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1404 | u32 producer; |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1405 | 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] | 1406 | struct cmd_desc_type0 *hwdesc; |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1407 | struct vlan_ethhdr *vh; |
Dhananjay Phadke | cdff103 | 2009-01-26 12:34:57 -0800 | [diff] [blame] | 1408 | |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 1409 | if (protocol == cpu_to_be16(ETH_P_8021Q)) { |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1410 | |
| 1411 | vh = (struct vlan_ethhdr *)skb->data; |
Dhananjay Phadke | cdff103 | 2009-01-26 12:34:57 -0800 | [diff] [blame] | 1412 | protocol = vh->h_vlan_encapsulated_proto; |
| 1413 | flags = FLAGS_VLAN_TAGGED; |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1414 | |
| 1415 | } else if (vlan_tx_tag_present(skb)) { |
| 1416 | |
| 1417 | flags = FLAGS_VLAN_OOB; |
| 1418 | vid = vlan_tx_tag_get(skb); |
| 1419 | netxen_set_tx_vlan_tci(first_desc, vid); |
| 1420 | vlan_oob = 1; |
Dhananjay Phadke | cdff103 | 2009-01-26 12:34:57 -0800 | [diff] [blame] | 1421 | } |
Dhananjay Phadke | cd1f816 | 2008-07-21 19:44:09 -0700 | [diff] [blame] | 1422 | |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1423 | if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) && |
| 1424 | skb_shinfo(skb)->gso_size > 0) { |
| 1425 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1426 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 1427 | |
| 1428 | first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
| 1429 | first_desc->total_hdr_length = hdr_len; |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1430 | if (vlan_oob) { |
| 1431 | first_desc->total_hdr_length += VLAN_HLEN; |
| 1432 | first_desc->tcp_hdr_offset = VLAN_HLEN; |
| 1433 | first_desc->ip_hdr_offset = VLAN_HLEN; |
| 1434 | /* Only in case of TSO on vlan device */ |
| 1435 | flags |= FLAGS_VLAN_TAGGED; |
| 1436 | } |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1437 | |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 1438 | opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ? |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1439 | TX_TCP_LSO6 : TX_TCP_LSO; |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1440 | tso = 1; |
Dhananjay Phadke | cd1f816 | 2008-07-21 19:44:09 -0700 | [diff] [blame] | 1441 | |
| 1442 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1443 | u8 l4proto; |
| 1444 | |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 1445 | if (protocol == cpu_to_be16(ETH_P_IP)) { |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1446 | l4proto = ip_hdr(skb)->protocol; |
| 1447 | |
| 1448 | if (l4proto == IPPROTO_TCP) |
| 1449 | opcode = TX_TCP_PKT; |
| 1450 | else if(l4proto == IPPROTO_UDP) |
| 1451 | opcode = TX_UDP_PKT; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 1452 | } else if (protocol == cpu_to_be16(ETH_P_IPV6)) { |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1453 | l4proto = ipv6_hdr(skb)->nexthdr; |
| 1454 | |
| 1455 | if (l4proto == IPPROTO_TCP) |
| 1456 | opcode = TX_TCPV6_PKT; |
| 1457 | else if(l4proto == IPPROTO_UDP) |
| 1458 | opcode = TX_UDPV6_PKT; |
| 1459 | } |
Dhananjay Phadke | cd1f816 | 2008-07-21 19:44:09 -0700 | [diff] [blame] | 1460 | } |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1461 | |
| 1462 | first_desc->tcp_hdr_offset += skb_transport_offset(skb); |
| 1463 | first_desc->ip_hdr_offset += skb_network_offset(skb); |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1464 | netxen_set_tx_flags_opcode(first_desc, flags, opcode); |
| 1465 | |
| 1466 | if (!tso) |
| 1467 | return; |
| 1468 | |
| 1469 | /* For LSO, we need to copy the MAC/IP/TCP headers into |
| 1470 | * the descriptor ring |
| 1471 | */ |
| 1472 | producer = tx_ring->producer; |
| 1473 | copied = 0; |
| 1474 | offset = 2; |
| 1475 | |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1476 | if (vlan_oob) { |
| 1477 | /* Create a TSO vlan header template for firmware */ |
| 1478 | |
| 1479 | hwdesc = &tx_ring->desc_head[producer]; |
| 1480 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
| 1481 | |
| 1482 | copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, |
| 1483 | hdr_len + VLAN_HLEN); |
| 1484 | |
| 1485 | vh = (struct vlan_ethhdr *)((char *)hwdesc + 2); |
| 1486 | skb_copy_from_linear_data(skb, vh, 12); |
| 1487 | vh->h_vlan_proto = htons(ETH_P_8021Q); |
| 1488 | vh->h_vlan_TCI = htons(vid); |
| 1489 | skb_copy_from_linear_data_offset(skb, 12, |
| 1490 | (char *)vh + 16, copy_len - 16); |
| 1491 | |
Dhananjay Phadke | 545eb37 | 2009-08-05 07:34:07 +0000 | [diff] [blame] | 1492 | copied = copy_len - VLAN_HLEN; |
Dhananjay Phadke | 028afe7 | 2009-07-26 20:07:45 +0000 | [diff] [blame] | 1493 | offset = 0; |
| 1494 | |
| 1495 | producer = get_next_index(producer, tx_ring->num_desc); |
| 1496 | } |
| 1497 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1498 | while (copied < hdr_len) { |
| 1499 | |
| 1500 | copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, |
| 1501 | (hdr_len - copied)); |
| 1502 | |
| 1503 | hwdesc = &tx_ring->desc_head[producer]; |
| 1504 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
| 1505 | |
| 1506 | skb_copy_from_linear_data_offset(skb, copied, |
| 1507 | (char *)hwdesc + offset, copy_len); |
| 1508 | |
| 1509 | copied += copy_len; |
| 1510 | offset = 0; |
| 1511 | |
| 1512 | producer = get_next_index(producer, tx_ring->num_desc); |
| 1513 | } |
| 1514 | |
| 1515 | tx_ring->producer = producer; |
| 1516 | barrier(); |
Dhananjay Phadke | cd1f816 | 2008-07-21 19:44:09 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1519 | static void |
| 1520 | netxen_clean_tx_dma_mapping(struct pci_dev *pdev, |
| 1521 | struct netxen_cmd_buffer *pbuf, int last) |
| 1522 | { |
| 1523 | int k; |
| 1524 | struct netxen_skb_frag *buffrag; |
| 1525 | |
| 1526 | buffrag = &pbuf->frag_array[0]; |
| 1527 | pci_unmap_single(pdev, buffrag->dma, |
| 1528 | buffrag->length, PCI_DMA_TODEVICE); |
| 1529 | |
| 1530 | for (k = 1; k < last; k++) { |
| 1531 | buffrag = &pbuf->frag_array[k]; |
| 1532 | pci_unmap_page(pdev, buffrag->dma, |
| 1533 | buffrag->length, PCI_DMA_TODEVICE); |
| 1534 | } |
| 1535 | } |
| 1536 | |
Dhananjay Phadke | d32cc3d | 2009-03-09 08:50:53 +0000 | [diff] [blame] | 1537 | static inline void |
| 1538 | netxen_clear_cmddesc(u64 *desc) |
| 1539 | { |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1540 | desc[0] = 0ULL; |
| 1541 | desc[2] = 0ULL; |
Dhananjay Phadke | d32cc3d | 2009-03-09 08:50:53 +0000 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | static int |
| 1545 | 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] | 1546 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1547 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 1548 | struct nx_host_tx_ring *tx_ring = adapter->tx_ring; |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1549 | struct skb_frag_struct *frag; |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1550 | struct netxen_cmd_buffer *pbuf; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1551 | struct netxen_skb_frag *buffrag; |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1552 | struct cmd_desc_type0 *hwdesc, *first_desc; |
| 1553 | struct pci_dev *pdev; |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1554 | dma_addr_t temp_dma; |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1555 | int i, k; |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1556 | unsigned long offset; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1557 | |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1558 | u32 producer; |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1559 | int len, frag_count, no_of_desc; |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1560 | u32 num_txd = tx_ring->num_desc; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1561 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1562 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
| 1563 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1564 | /* 4 fragments per cmd des */ |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1565 | no_of_desc = (frag_count + 3) >> 2; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1566 | |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1567 | if (unlikely(no_of_desc + 2) > netxen_tx_avail(tx_ring)) { |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1568 | netif_stop_queue(netdev); |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1569 | return NETDEV_TX_BUSY; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1570 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1571 | |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1572 | producer = tx_ring->producer; |
| 1573 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1574 | pdev = adapter->pdev; |
| 1575 | len = skb->len - skb->data_len; |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1576 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1577 | temp_dma = pci_map_single(pdev, skb->data, len, PCI_DMA_TODEVICE); |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1578 | if (pci_dma_mapping_error(pdev, temp_dma)) |
| 1579 | goto drop_packet; |
| 1580 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1581 | pbuf = &tx_ring->cmd_buf_arr[producer]; |
| 1582 | pbuf->skb = skb; |
| 1583 | pbuf->frag_count = frag_count; |
| 1584 | |
| 1585 | buffrag = &pbuf->frag_array[0]; |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1586 | buffrag->dma = temp_dma; |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1587 | buffrag->length = len; |
| 1588 | |
| 1589 | first_desc = hwdesc = &tx_ring->desc_head[producer]; |
| 1590 | netxen_clear_cmddesc((u64 *)hwdesc); |
Dhananjay Phadke | 391587c | 2009-01-14 20:48:11 -0800 | [diff] [blame] | 1591 | netxen_set_tx_frags_len(hwdesc, frag_count, skb->len); |
| 1592 | netxen_set_tx_port(hwdesc, adapter->portnum); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1593 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1594 | hwdesc->buffer_length[0] = cpu_to_le16(len); |
| 1595 | hwdesc->addr_buffer1 = cpu_to_le64(temp_dma); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1596 | |
| 1597 | for (i = 1, k = 1; i < frag_count; i++, k++) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1598 | |
| 1599 | /* move to next desc. if there is a need */ |
| 1600 | if ((i & 0x3) == 0) { |
| 1601 | k = 0; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1602 | producer = get_next_index(producer, num_txd); |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1603 | hwdesc = &tx_ring->desc_head[producer]; |
Dhananjay Phadke | d32cc3d | 2009-03-09 08:50:53 +0000 | [diff] [blame] | 1604 | netxen_clear_cmddesc((u64 *)hwdesc); |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1605 | pbuf = &tx_ring->cmd_buf_arr[producer]; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1606 | pbuf->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1607 | } |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1608 | buffrag = &pbuf->frag_array[i]; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1609 | frag = &skb_shinfo(skb)->frags[i - 1]; |
| 1610 | len = frag->size; |
| 1611 | offset = frag->page_offset; |
| 1612 | |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1613 | temp_dma = pci_map_page(pdev, frag->page, offset, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1614 | len, PCI_DMA_TODEVICE); |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1615 | if (pci_dma_mapping_error(pdev, temp_dma)) { |
| 1616 | netxen_clean_tx_dma_mapping(pdev, pbuf, i); |
| 1617 | goto drop_packet; |
| 1618 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1619 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1620 | buffrag->dma = temp_dma; |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1621 | buffrag->length = len; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1622 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1623 | hwdesc->buffer_length[k] = cpu_to_le16(len); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1624 | switch (k) { |
| 1625 | case 0: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1626 | hwdesc->addr_buffer1 = cpu_to_le64(temp_dma); |
| 1627 | break; |
| 1628 | case 1: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1629 | hwdesc->addr_buffer2 = cpu_to_le64(temp_dma); |
| 1630 | break; |
| 1631 | case 2: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1632 | hwdesc->addr_buffer3 = cpu_to_le64(temp_dma); |
| 1633 | break; |
| 1634 | case 3: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1635 | hwdesc->addr_buffer4 = cpu_to_le64(temp_dma); |
| 1636 | break; |
| 1637 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1638 | } |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1639 | tx_ring->producer = get_next_index(producer, num_txd); |
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 | netxen_tso_check(netdev, tx_ring, first_desc, skb); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1642 | |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1643 | netxen_nic_update_cmd_producer(adapter, tx_ring); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1644 | |
Dhananjay Phadke | 1bcfd79 | 2009-07-26 20:07:40 +0000 | [diff] [blame] | 1645 | adapter->stats.txbytes += skb->len; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1646 | adapter->stats.xmitcalled++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1647 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1648 | return NETDEV_TX_OK; |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1649 | |
| 1650 | drop_packet: |
| 1651 | adapter->stats.txdropped++; |
| 1652 | dev_kfree_skb_any(skb); |
| 1653 | return NETDEV_TX_OK; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1654 | } |
| 1655 | |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1656 | static int netxen_nic_check_temp(struct netxen_adapter *adapter) |
| 1657 | { |
| 1658 | struct net_device *netdev = adapter->netdev; |
| 1659 | uint32_t temp, temp_state, temp_val; |
| 1660 | int rv = 0; |
| 1661 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1662 | temp = NXRD32(adapter, CRB_TEMP_STATE); |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1663 | |
| 1664 | temp_state = nx_get_temp_state(temp); |
| 1665 | temp_val = nx_get_temp_val(temp); |
| 1666 | |
| 1667 | if (temp_state == NX_TEMP_PANIC) { |
| 1668 | printk(KERN_ALERT |
| 1669 | "%s: Device temperature %d degrees C exceeds" |
| 1670 | " maximum allowed. Hardware has been shut down.\n", |
Dhananjay Phadke | e4135c2 | 2009-07-17 15:27:08 +0000 | [diff] [blame] | 1671 | netdev->name, temp_val); |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1672 | rv = 1; |
| 1673 | } else if (temp_state == NX_TEMP_WARN) { |
| 1674 | if (adapter->temp == NX_TEMP_NORMAL) { |
| 1675 | printk(KERN_ALERT |
| 1676 | "%s: Device temperature %d degrees C " |
| 1677 | "exceeds operating range." |
| 1678 | " Immediate action needed.\n", |
Dhananjay Phadke | e4135c2 | 2009-07-17 15:27:08 +0000 | [diff] [blame] | 1679 | netdev->name, temp_val); |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1680 | } |
| 1681 | } else { |
| 1682 | if (adapter->temp == NX_TEMP_WARN) { |
| 1683 | printk(KERN_INFO |
| 1684 | "%s: Device temperature is now %d degrees C" |
Dhananjay Phadke | e4135c2 | 2009-07-17 15:27:08 +0000 | [diff] [blame] | 1685 | " in normal range.\n", netdev->name, |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1686 | temp_val); |
| 1687 | } |
| 1688 | } |
| 1689 | adapter->temp = temp_state; |
| 1690 | return rv; |
| 1691 | } |
| 1692 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1693 | void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup) |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1694 | { |
| 1695 | struct net_device *netdev = adapter->netdev; |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1696 | |
| 1697 | if (adapter->ahw.linkup && !linkup) { |
| 1698 | printk(KERN_INFO "%s: %s NIC Link is down\n", |
| 1699 | netxen_nic_driver_name, netdev->name); |
| 1700 | adapter->ahw.linkup = 0; |
| 1701 | if (netif_running(netdev)) { |
| 1702 | netif_carrier_off(netdev); |
| 1703 | netif_stop_queue(netdev); |
| 1704 | } |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1705 | adapter->link_changed = !adapter->has_link_events; |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1706 | } else if (!adapter->ahw.linkup && linkup) { |
| 1707 | printk(KERN_INFO "%s: %s NIC Link is up\n", |
| 1708 | netxen_nic_driver_name, netdev->name); |
| 1709 | adapter->ahw.linkup = 1; |
| 1710 | if (netif_running(netdev)) { |
| 1711 | netif_carrier_on(netdev); |
| 1712 | netif_wake_queue(netdev); |
| 1713 | } |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1714 | adapter->link_changed = !adapter->has_link_events; |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1715 | } |
| 1716 | } |
| 1717 | |
| 1718 | static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter) |
| 1719 | { |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1720 | u32 val, port, linkup; |
| 1721 | |
| 1722 | port = adapter->physical_port; |
| 1723 | |
Dhananjay Phadke | 24a7a45 | 2008-08-01 03:14:55 -0700 | [diff] [blame] | 1724 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1725 | val = NXRD32(adapter, CRB_XG_STATE_P3); |
Dhananjay Phadke | 24a7a45 | 2008-08-01 03:14:55 -0700 | [diff] [blame] | 1726 | val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val); |
| 1727 | linkup = (val == XG_LINK_UP_P3); |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 1728 | } else { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1729 | val = NXRD32(adapter, CRB_XG_STATE); |
Dhananjay Phadke | 1e2d005 | 2009-03-09 08:50:56 +0000 | [diff] [blame] | 1730 | if (adapter->ahw.port_type == NETXEN_NIC_GBE) |
Dhananjay Phadke | 24a7a45 | 2008-08-01 03:14:55 -0700 | [diff] [blame] | 1731 | linkup = (val >> port) & 1; |
| 1732 | else { |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 1733 | val = (val >> port*8) & 0xff; |
| 1734 | linkup = (val == XG_LINK_UP); |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 1735 | } |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1736 | } |
| 1737 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1738 | netxen_advert_link_change(adapter, linkup); |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1741 | static void netxen_nic_thermal_shutdown(struct netxen_adapter *adapter) |
| 1742 | { |
| 1743 | struct net_device *netdev = adapter->netdev; |
| 1744 | |
| 1745 | netif_device_detach(netdev); |
| 1746 | netxen_nic_down(adapter, netdev); |
| 1747 | netxen_nic_detach(adapter); |
| 1748 | } |
| 1749 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1750 | static void netxen_watchdog(unsigned long v) |
| 1751 | { |
| 1752 | struct netxen_adapter *adapter = (struct netxen_adapter *)v; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1753 | |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1754 | if (netxen_nic_check_temp(adapter)) |
| 1755 | goto do_sched; |
| 1756 | |
| 1757 | if (!adapter->has_link_events) { |
| 1758 | netxen_nic_handle_phy_intr(adapter); |
| 1759 | |
| 1760 | if (adapter->link_changed) |
| 1761 | goto do_sched; |
| 1762 | } |
| 1763 | |
| 1764 | if (netif_running(adapter->netdev)) |
| 1765 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); |
| 1766 | |
| 1767 | return; |
| 1768 | |
| 1769 | do_sched: |
| 1770 | schedule_work(&adapter->watchdog_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1771 | } |
| 1772 | |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1773 | void netxen_watchdog_task(struct work_struct *work) |
| 1774 | { |
| 1775 | struct netxen_adapter *adapter = |
| 1776 | container_of(work, struct netxen_adapter, watchdog_task); |
| 1777 | |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1778 | if (adapter->temp == NX_TEMP_PANIC) { |
| 1779 | netxen_nic_thermal_shutdown(adapter); |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1780 | return; |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1781 | } |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1782 | |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1783 | if (adapter->link_changed) |
| 1784 | netxen_nic_set_link_parameters(adapter); |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1785 | |
Dhananjay Phadke | 922c4f2 | 2008-08-08 00:08:41 -0700 | [diff] [blame] | 1786 | if (netif_running(adapter->netdev)) |
| 1787 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1790 | static void netxen_tx_timeout(struct net_device *netdev) |
| 1791 | { |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1792 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1793 | |
| 1794 | dev_err(&netdev->dev, "transmit timeout, resetting.\n"); |
Amit Kumar Salecha | e424fa9 | 2009-08-13 07:03:00 +0000 | [diff] [blame] | 1795 | schedule_work(&adapter->tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1796 | } |
| 1797 | |
Dhananjay Phadke | f17443f | 2009-07-26 20:07:43 +0000 | [diff] [blame] | 1798 | static void netxen_reset_task(struct work_struct *work) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1799 | { |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 1800 | struct netxen_adapter *adapter = |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1801 | container_of(work, struct netxen_adapter, tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1802 | |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 1803 | if (!netif_running(adapter->netdev)) |
| 1804 | return; |
| 1805 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1806 | netxen_napi_disable(adapter); |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1807 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1808 | adapter->netdev->trans_start = jiffies; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1809 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1810 | netxen_napi_enable(adapter); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1811 | netif_wake_queue(adapter->netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1812 | } |
| 1813 | |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1814 | struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev) |
| 1815 | { |
| 1816 | struct netxen_adapter *adapter = netdev_priv(netdev); |
| 1817 | struct net_device_stats *stats = &adapter->net_stats; |
| 1818 | |
| 1819 | memset(stats, 0, sizeof(*stats)); |
| 1820 | |
Narender Kumar | 1bb482f | 2009-08-23 08:35:09 +0000 | [diff] [blame^] | 1821 | stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; |
Dhananjay Phadke | e98e335 | 2009-04-07 22:50:38 +0000 | [diff] [blame] | 1822 | stats->tx_packets = adapter->stats.xmitfinished; |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1823 | stats->rx_bytes = adapter->stats.rxbytes; |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1824 | stats->tx_bytes = adapter->stats.txbytes; |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1825 | stats->rx_dropped = adapter->stats.rxdropped; |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1826 | stats->tx_dropped = adapter->stats.txdropped; |
| 1827 | |
| 1828 | return stats; |
| 1829 | } |
| 1830 | |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1831 | static irqreturn_t netxen_intr(int irq, void *data) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1832 | { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1833 | struct nx_host_sds_ring *sds_ring = data; |
| 1834 | struct netxen_adapter *adapter = sds_ring->adapter; |
Dhananjay Phadke | d71e1be | 2008-08-01 03:14:57 -0700 | [diff] [blame] | 1835 | u32 status = 0; |
| 1836 | |
| 1837 | status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR); |
| 1838 | |
| 1839 | if (!(status & adapter->legacy_intr.int_vec_bit)) |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1840 | return IRQ_NONE; |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1841 | |
Dhananjay Phadke | d71e1be | 2008-08-01 03:14:57 -0700 | [diff] [blame] | 1842 | if (adapter->ahw.revision_id >= NX_P3_B1) { |
| 1843 | /* check interrupt state machine, to be sure */ |
| 1844 | status = adapter->pci_read_immediate(adapter, |
| 1845 | ISR_INT_STATE_REG); |
| 1846 | if (!ISR_LEGACY_INT_TRIGGERED(status)) |
| 1847 | return IRQ_NONE; |
| 1848 | |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 1849 | } else { |
| 1850 | unsigned long our_int = 0; |
Dhananjay Phadke | d71e1be | 2008-08-01 03:14:57 -0700 | [diff] [blame] | 1851 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1852 | our_int = NXRD32(adapter, CRB_INT_VECTOR); |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 1853 | |
Dhananjay Phadke | d71e1be | 2008-08-01 03:14:57 -0700 | [diff] [blame] | 1854 | /* not our interrupt */ |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 1855 | if (!test_and_clear_bit((7 + adapter->portnum), &our_int)) |
Dhananjay Phadke | d71e1be | 2008-08-01 03:14:57 -0700 | [diff] [blame] | 1856 | return IRQ_NONE; |
| 1857 | |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 1858 | /* claim interrupt */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1859 | NXWR32(adapter, CRB_INT_VECTOR, (our_int & 0xffffffff)); |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1860 | } |
| 1861 | |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 1862 | /* clear interrupt */ |
Dhananjay Phadke | 4f96b98 | 2009-07-26 20:07:42 +0000 | [diff] [blame] | 1863 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1864 | netxen_nic_disable_int(sds_ring); |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 1865 | |
| 1866 | adapter->pci_write_immediate(adapter, |
| 1867 | adapter->legacy_intr.tgt_status_reg, |
| 1868 | 0xffffffff); |
| 1869 | /* read twice to ensure write is flushed */ |
| 1870 | adapter->pci_read_immediate(adapter, ISR_INT_VECTOR); |
| 1871 | adapter->pci_read_immediate(adapter, ISR_INT_VECTOR); |
| 1872 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1873 | napi_schedule(&sds_ring->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1874 | |
| 1875 | return IRQ_HANDLED; |
| 1876 | } |
| 1877 | |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1878 | static irqreturn_t netxen_msi_intr(int irq, void *data) |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1879 | { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1880 | struct nx_host_sds_ring *sds_ring = data; |
| 1881 | struct netxen_adapter *adapter = sds_ring->adapter; |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1882 | |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 1883 | /* clear interrupt */ |
| 1884 | adapter->pci_write_immediate(adapter, |
Dhananjay Phadke | 7a2469c | 2009-05-08 22:02:27 +0000 | [diff] [blame] | 1885 | adapter->msi_tgt_status, 0xffffffff); |
Dhananjay Phadke | 092bc57 | 2008-08-08 00:08:43 -0700 | [diff] [blame] | 1886 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1887 | napi_schedule(&sds_ring->napi); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1888 | return IRQ_HANDLED; |
| 1889 | } |
| 1890 | |
Dhananjay Phadke | b3df68f | 2009-02-08 19:20:19 -0800 | [diff] [blame] | 1891 | static irqreturn_t netxen_msix_intr(int irq, void *data) |
| 1892 | { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1893 | struct nx_host_sds_ring *sds_ring = data; |
Dhananjay Phadke | b3df68f | 2009-02-08 19:20:19 -0800 | [diff] [blame] | 1894 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1895 | napi_schedule(&sds_ring->napi); |
Dhananjay Phadke | b3df68f | 2009-02-08 19:20:19 -0800 | [diff] [blame] | 1896 | return IRQ_HANDLED; |
| 1897 | } |
| 1898 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1899 | static int netxen_nic_poll(struct napi_struct *napi, int budget) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1900 | { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1901 | struct nx_host_sds_ring *sds_ring = |
| 1902 | container_of(napi, struct nx_host_sds_ring, napi); |
| 1903 | |
| 1904 | struct netxen_adapter *adapter = sds_ring->adapter; |
| 1905 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1906 | int tx_complete; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1907 | int work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1908 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1909 | tx_complete = netxen_process_cmd_ring(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1910 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1911 | work_done = netxen_process_rcv_ring(sds_ring, budget); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1912 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1913 | if ((work_done < budget) && tx_complete) { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1914 | napi_complete(&sds_ring->napi); |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 1915 | if (netif_running(adapter->netdev)) |
| 1916 | netxen_nic_enable_int(sds_ring); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1917 | } |
| 1918 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1919 | return work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1923 | static void netxen_nic_poll_controller(struct net_device *netdev) |
| 1924 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1925 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1926 | disable_irq(adapter->irq); |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1927 | netxen_intr(adapter->irq, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1928 | enable_irq(adapter->irq); |
| 1929 | } |
| 1930 | #endif |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1931 | |
Dhananjay Phadke | 044824d | 2009-07-28 09:10:03 +0000 | [diff] [blame] | 1932 | #ifdef CONFIG_INET |
| 1933 | |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 1934 | #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops) |
| 1935 | |
| 1936 | static int |
| 1937 | netxen_destip_supported(struct netxen_adapter *adapter) |
| 1938 | { |
| 1939 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 1940 | return 0; |
| 1941 | |
| 1942 | if (adapter->ahw.cut_through) |
| 1943 | return 0; |
| 1944 | |
| 1945 | return 1; |
| 1946 | } |
| 1947 | |
| 1948 | static int netxen_netdev_event(struct notifier_block *this, |
| 1949 | unsigned long event, void *ptr) |
| 1950 | { |
| 1951 | struct netxen_adapter *adapter; |
| 1952 | struct net_device *dev = (struct net_device *)ptr; |
| 1953 | struct in_device *indev; |
| 1954 | |
| 1955 | recheck: |
| 1956 | if (dev == NULL) |
| 1957 | goto done; |
| 1958 | |
| 1959 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 1960 | dev = vlan_dev_real_dev(dev); |
| 1961 | goto recheck; |
| 1962 | } |
| 1963 | |
| 1964 | if (!is_netxen_netdev(dev)) |
| 1965 | goto done; |
| 1966 | |
| 1967 | adapter = netdev_priv(dev); |
| 1968 | |
| 1969 | if (!adapter || !netxen_destip_supported(adapter)) |
| 1970 | goto done; |
| 1971 | |
| 1972 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) |
| 1973 | goto done; |
| 1974 | |
| 1975 | indev = in_dev_get(dev); |
| 1976 | if (!indev) |
| 1977 | goto done; |
| 1978 | |
| 1979 | for_ifa(indev) { |
| 1980 | switch (event) { |
| 1981 | case NETDEV_UP: |
| 1982 | netxen_config_ipaddr(adapter, |
| 1983 | ifa->ifa_address, NX_IP_UP); |
| 1984 | break; |
| 1985 | case NETDEV_DOWN: |
| 1986 | netxen_config_ipaddr(adapter, |
| 1987 | ifa->ifa_address, NX_IP_DOWN); |
| 1988 | break; |
| 1989 | default: |
| 1990 | break; |
| 1991 | } |
| 1992 | } endfor_ifa(indev); |
| 1993 | |
| 1994 | in_dev_put(indev); |
| 1995 | done: |
| 1996 | return NOTIFY_DONE; |
| 1997 | } |
| 1998 | |
| 1999 | static int |
| 2000 | netxen_inetaddr_event(struct notifier_block *this, |
| 2001 | unsigned long event, void *ptr) |
| 2002 | { |
| 2003 | struct netxen_adapter *adapter; |
| 2004 | struct net_device *dev; |
| 2005 | |
| 2006 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; |
| 2007 | |
| 2008 | dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; |
| 2009 | |
| 2010 | recheck: |
| 2011 | if (dev == NULL || !netif_running(dev)) |
| 2012 | goto done; |
| 2013 | |
| 2014 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 2015 | dev = vlan_dev_real_dev(dev); |
| 2016 | goto recheck; |
| 2017 | } |
| 2018 | |
| 2019 | if (!is_netxen_netdev(dev)) |
| 2020 | goto done; |
| 2021 | |
| 2022 | adapter = netdev_priv(dev); |
| 2023 | |
| 2024 | if (!adapter || !netxen_destip_supported(adapter)) |
| 2025 | goto done; |
| 2026 | |
| 2027 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) |
| 2028 | goto done; |
| 2029 | |
| 2030 | switch (event) { |
| 2031 | case NETDEV_UP: |
| 2032 | netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP); |
| 2033 | break; |
| 2034 | case NETDEV_DOWN: |
| 2035 | netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN); |
| 2036 | break; |
| 2037 | default: |
| 2038 | break; |
| 2039 | } |
| 2040 | |
| 2041 | done: |
| 2042 | return NOTIFY_DONE; |
| 2043 | } |
| 2044 | |
| 2045 | static struct notifier_block netxen_netdev_cb = { |
| 2046 | .notifier_call = netxen_netdev_event, |
| 2047 | }; |
| 2048 | |
| 2049 | static struct notifier_block netxen_inetaddr_cb = { |
| 2050 | .notifier_call = netxen_inetaddr_event, |
| 2051 | }; |
Dhananjay Phadke | 044824d | 2009-07-28 09:10:03 +0000 | [diff] [blame] | 2052 | #endif |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2053 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2054 | static struct pci_driver netxen_driver = { |
| 2055 | .name = netxen_nic_driver_name, |
| 2056 | .id_table = netxen_pci_tbl, |
| 2057 | .probe = netxen_nic_probe, |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 2058 | .remove = __devexit_p(netxen_nic_remove), |
Dhananjay Phadke | 01542cd | 2009-06-22 20:26:20 +0000 | [diff] [blame] | 2059 | #ifdef CONFIG_PM |
Dhananjay Phadke | 0b72e65 | 2009-03-13 14:52:02 +0000 | [diff] [blame] | 2060 | .suspend = netxen_nic_suspend, |
| 2061 | .resume = netxen_nic_resume |
Dhananjay Phadke | 01542cd | 2009-06-22 20:26:20 +0000 | [diff] [blame] | 2062 | #endif |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2063 | }; |
| 2064 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2065 | static int __init netxen_init_module(void) |
| 2066 | { |
Dhananjay Phadke | ff4fbd4 | 2009-03-13 14:52:06 +0000 | [diff] [blame] | 2067 | printk(KERN_INFO "%s\n", netxen_nic_driver_string); |
| 2068 | |
Dhananjay Phadke | 044824d | 2009-07-28 09:10:03 +0000 | [diff] [blame] | 2069 | #ifdef CONFIG_INET |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2070 | register_netdevice_notifier(&netxen_netdev_cb); |
| 2071 | register_inetaddr_notifier(&netxen_inetaddr_cb); |
Dhananjay Phadke | 044824d | 2009-07-28 09:10:03 +0000 | [diff] [blame] | 2072 | #endif |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2073 | |
Amit S. Kale | 184231b | 2007-01-22 06:52:53 -0800 | [diff] [blame] | 2074 | return pci_register_driver(&netxen_driver); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | module_init(netxen_init_module); |
| 2078 | |
| 2079 | static void __exit netxen_exit_module(void) |
| 2080 | { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2081 | pci_unregister_driver(&netxen_driver); |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2082 | |
Dhananjay Phadke | 044824d | 2009-07-28 09:10:03 +0000 | [diff] [blame] | 2083 | #ifdef CONFIG_INET |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 2084 | unregister_inetaddr_notifier(&netxen_inetaddr_cb); |
| 2085 | unregister_netdevice_notifier(&netxen_netdev_cb); |
Dhananjay Phadke | 044824d | 2009-07-28 09:10:03 +0000 | [diff] [blame] | 2086 | #endif |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | module_exit(netxen_exit_module); |