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