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