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