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