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