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