Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003 - 2006 NetXen, Inc. |
| 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 |
| 25 | * NetXen, |
| 26 | * 3965 Freedom Circle, Fourth floor, |
| 27 | * Santa Clara, CA 95054 |
| 28 | * |
| 29 | * |
| 30 | * Main source file for NetXen NIC Driver on Linux |
| 31 | * |
| 32 | */ |
| 33 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 34 | #include <linux/vmalloc.h> |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 35 | #include <linux/highmem.h> |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 36 | #include "netxen_nic_hw.h" |
| 37 | |
| 38 | #include "netxen_nic.h" |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 39 | #include "netxen_nic_phan_reg.h" |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 40 | |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 41 | #include <linux/dma-mapping.h> |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 42 | #include <net/ip.h> |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 43 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 44 | MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver"); |
| 45 | MODULE_LICENSE("GPL"); |
| 46 | MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID); |
| 47 | |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 48 | char netxen_nic_driver_name[] = "netxen_nic"; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 49 | static char netxen_nic_driver_string[] = "NetXen Network Driver version " |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 50 | NETXEN_NIC_LINUX_VERSIONID; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 51 | |
| 52 | #define NETXEN_NETDEV_WEIGHT 120 |
| 53 | #define NETXEN_ADAPTER_UP_MAGIC 777 |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 54 | #define NETXEN_NIC_PEG_TUNE 0 |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 55 | |
| 56 | /* Local functions to NetXen NIC driver */ |
| 57 | static int __devinit netxen_nic_probe(struct pci_dev *pdev, |
| 58 | const struct pci_device_id *ent); |
| 59 | static void __devexit netxen_nic_remove(struct pci_dev *pdev); |
| 60 | static int netxen_nic_open(struct net_device *netdev); |
| 61 | static int netxen_nic_close(struct net_device *netdev); |
| 62 | static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *); |
| 63 | static void netxen_tx_timeout(struct net_device *netdev); |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 64 | static void netxen_tx_timeout_task(struct work_struct *work); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 65 | static void netxen_watchdog(unsigned long); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 66 | static int netxen_nic_poll(struct napi_struct *napi, int budget); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 67 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 68 | static void netxen_nic_poll_controller(struct net_device *netdev); |
| 69 | #endif |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 70 | static irqreturn_t netxen_intr(int irq, void *data); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 71 | static irqreturn_t netxen_msi_intr(int irq, void *data); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 72 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 73 | int physical_port[] = {0, 1, 2, 3}; |
| 74 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 75 | /* PCI Device ID Table */ |
| 76 | static struct pci_device_id netxen_pci_tbl[] __devinitdata = { |
| 77 | {PCI_DEVICE(0x4040, 0x0001)}, |
| 78 | {PCI_DEVICE(0x4040, 0x0002)}, |
| 79 | {PCI_DEVICE(0x4040, 0x0003)}, |
| 80 | {PCI_DEVICE(0x4040, 0x0004)}, |
| 81 | {PCI_DEVICE(0x4040, 0x0005)}, |
Amit S. Kale | 0d39073 | 2006-12-18 05:50:59 -0800 | [diff] [blame] | 82 | {PCI_DEVICE(0x4040, 0x0024)}, |
| 83 | {PCI_DEVICE(0x4040, 0x0025)}, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 84 | {0,} |
| 85 | }; |
| 86 | |
| 87 | MODULE_DEVICE_TABLE(pci, netxen_pci_tbl); |
| 88 | |
Adrian Bunk | b1555130 | 2008-03-31 02:22:18 +0300 | [diff] [blame^] | 89 | /* |
| 90 | * In netxen_nic_down(), we must wait for any pending callback requests into |
| 91 | * netxen_watchdog_task() to complete; eg otherwise the watchdog_timer could be |
| 92 | * reenabled right after it is deleted in netxen_nic_down(). |
| 93 | * FLUSH_SCHEDULED_WORK() does this synchronization. |
| 94 | * |
| 95 | * Normally, schedule_work()/flush_scheduled_work() could have worked, but |
| 96 | * netxen_nic_close() is invoked with kernel rtnl lock held. netif_carrier_off() |
| 97 | * call in netxen_nic_close() triggers a schedule_work(&linkwatch_work), and a |
| 98 | * subsequent call to flush_scheduled_work() in netxen_nic_down() would cause |
| 99 | * linkwatch_event() to be executed which also attempts to acquire the rtnl |
| 100 | * lock thus causing a deadlock. |
| 101 | */ |
| 102 | |
| 103 | static struct workqueue_struct *netxen_workq; |
| 104 | #define SCHEDULE_WORK(tp) queue_work(netxen_workq, tp) |
| 105 | #define FLUSH_SCHEDULED_WORK() flush_workqueue(netxen_workq) |
| 106 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 107 | static void netxen_watchdog(unsigned long); |
| 108 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 109 | static void netxen_nic_update_cmd_producer(struct netxen_adapter *adapter, |
| 110 | uint32_t crb_producer) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 111 | { |
| 112 | switch (adapter->portnum) { |
| 113 | case 0: |
| 114 | writel(crb_producer, NETXEN_CRB_NORMALIZE |
| 115 | (adapter, CRB_CMD_PRODUCER_OFFSET)); |
| 116 | return; |
| 117 | case 1: |
| 118 | writel(crb_producer, NETXEN_CRB_NORMALIZE |
| 119 | (adapter, CRB_CMD_PRODUCER_OFFSET_1)); |
| 120 | return; |
| 121 | case 2: |
| 122 | writel(crb_producer, NETXEN_CRB_NORMALIZE |
| 123 | (adapter, CRB_CMD_PRODUCER_OFFSET_2)); |
| 124 | return; |
| 125 | case 3: |
| 126 | writel(crb_producer, NETXEN_CRB_NORMALIZE |
| 127 | (adapter, CRB_CMD_PRODUCER_OFFSET_3)); |
| 128 | return; |
| 129 | default: |
| 130 | printk(KERN_WARNING "We tried to update " |
| 131 | "CRB_CMD_PRODUCER_OFFSET for invalid " |
| 132 | "PCI function id %d\n", |
| 133 | adapter->portnum); |
| 134 | return; |
| 135 | } |
| 136 | } |
| 137 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 138 | static void netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter, |
| 139 | u32 crb_consumer) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 140 | { |
| 141 | switch (adapter->portnum) { |
| 142 | case 0: |
| 143 | writel(crb_consumer, NETXEN_CRB_NORMALIZE |
| 144 | (adapter, CRB_CMD_CONSUMER_OFFSET)); |
| 145 | return; |
| 146 | case 1: |
| 147 | writel(crb_consumer, NETXEN_CRB_NORMALIZE |
| 148 | (adapter, CRB_CMD_CONSUMER_OFFSET_1)); |
| 149 | return; |
| 150 | case 2: |
| 151 | writel(crb_consumer, NETXEN_CRB_NORMALIZE |
| 152 | (adapter, CRB_CMD_CONSUMER_OFFSET_2)); |
| 153 | return; |
| 154 | case 3: |
| 155 | writel(crb_consumer, NETXEN_CRB_NORMALIZE |
| 156 | (adapter, CRB_CMD_CONSUMER_OFFSET_3)); |
| 157 | return; |
| 158 | default: |
| 159 | printk(KERN_WARNING "We tried to update " |
| 160 | "CRB_CMD_PRODUCER_OFFSET for invalid " |
| 161 | "PCI function id %d\n", |
| 162 | adapter->portnum); |
| 163 | return; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | #define ADAPTER_LIST_SIZE 12 |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 168 | |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 169 | static uint32_t msi_tgt_status[4] = { |
| 170 | ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, |
| 171 | ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3 |
| 172 | }; |
| 173 | |
| 174 | static uint32_t sw_int_mask[4] = { |
| 175 | CRB_SW_INT_MASK_0, CRB_SW_INT_MASK_1, |
| 176 | CRB_SW_INT_MASK_2, CRB_SW_INT_MASK_3 |
| 177 | }; |
| 178 | |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 179 | static void netxen_nic_disable_int(struct netxen_adapter *adapter) |
| 180 | { |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 181 | u32 mask = 0x7ff; |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 182 | int retries = 32; |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 183 | int port = adapter->portnum; |
| 184 | int pci_fn = adapter->ahw.pci_func; |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 185 | |
Jeff Garzik | f0c88f9 | 2008-03-25 23:53:24 -0400 | [diff] [blame] | 186 | if (adapter->msi_mode != MSI_MODE_MULTIFUNC) |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 187 | writel(0x0, NETXEN_CRB_NORMALIZE(adapter, sw_int_mask[port])); |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 188 | |
| 189 | if (adapter->intr_scheme != -1 && |
| 190 | adapter->intr_scheme != INTR_SCHEME_PERPORT) |
| 191 | writel(mask,PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_MASK)); |
| 192 | |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 193 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { |
| 194 | do { |
| 195 | writel(0xffffffff, |
| 196 | PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_TARGET_STATUS)); |
| 197 | mask = readl(pci_base_offset(adapter, ISR_INT_VECTOR)); |
| 198 | if (!(mask & 0x80)) |
| 199 | break; |
| 200 | udelay(10); |
| 201 | } while (--retries); |
| 202 | |
| 203 | if (!retries) { |
| 204 | printk(KERN_NOTICE "%s: Failed to disable interrupt completely\n", |
| 205 | netxen_nic_driver_name); |
| 206 | } |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 207 | } else { |
| 208 | if (adapter->msi_mode == MSI_MODE_MULTIFUNC) { |
| 209 | writel(0xffffffff, PCI_OFFSET_SECOND_RANGE(adapter, |
| 210 | msi_tgt_status[pci_fn])); |
| 211 | } |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 212 | } |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static void netxen_nic_enable_int(struct netxen_adapter *adapter) |
| 216 | { |
| 217 | u32 mask; |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 218 | int port = adapter->portnum; |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 219 | |
| 220 | DPRINTK(1, INFO, "Entered ISR Enable \n"); |
| 221 | |
| 222 | if (adapter->intr_scheme != -1 && |
| 223 | adapter->intr_scheme != INTR_SCHEME_PERPORT) { |
| 224 | switch (adapter->ahw.board_type) { |
| 225 | case NETXEN_NIC_GBE: |
| 226 | mask = 0x77b; |
| 227 | break; |
| 228 | case NETXEN_NIC_XGBE: |
| 229 | mask = 0x77f; |
| 230 | break; |
| 231 | default: |
| 232 | mask = 0x7ff; |
| 233 | break; |
| 234 | } |
| 235 | |
| 236 | writel(mask, PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_MASK)); |
| 237 | } |
| 238 | |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 239 | writel(0x1, NETXEN_CRB_NORMALIZE(adapter, sw_int_mask[port])); |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 240 | |
| 241 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { |
| 242 | mask = 0xbff; |
| 243 | if (adapter->intr_scheme != -1 && |
| 244 | adapter->intr_scheme != INTR_SCHEME_PERPORT) { |
| 245 | writel(0X0, NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR)); |
| 246 | } |
| 247 | writel(mask, |
| 248 | PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_TARGET_MASK)); |
| 249 | } |
| 250 | |
| 251 | DPRINTK(1, INFO, "Done with enable Int\n"); |
| 252 | } |
| 253 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 254 | /* |
| 255 | * netxen_nic_probe() |
| 256 | * |
| 257 | * The Linux system will invoke this after identifying the vendor ID and |
| 258 | * device Id in the pci_tbl supported by this module. |
| 259 | * |
| 260 | * A quad port card has one operational PCI config space, (function 0), |
| 261 | * which is used to access all four ports. |
| 262 | * |
| 263 | * This routine will initialize the adapter, and setup the global parameters |
| 264 | * along with the port's specific structure. |
| 265 | */ |
| 266 | static int __devinit |
| 267 | netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 268 | { |
| 269 | struct net_device *netdev = NULL; |
| 270 | struct netxen_adapter *adapter = NULL; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 271 | void __iomem *mem_ptr0 = NULL; |
| 272 | void __iomem *mem_ptr1 = NULL; |
| 273 | void __iomem *mem_ptr2 = NULL; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 274 | unsigned long first_page_group_end; |
| 275 | unsigned long first_page_group_start; |
| 276 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 277 | |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 278 | u8 __iomem *db_ptr = NULL; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 279 | unsigned long mem_base, mem_len, db_base, db_len; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 280 | int pci_using_dac, i = 0, err; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 281 | int ring; |
| 282 | struct netxen_recv_context *recv_ctx = NULL; |
| 283 | struct netxen_rcv_desc_ctx *rcv_desc = NULL; |
| 284 | struct netxen_cmd_buffer *cmd_buf_arr = NULL; |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 285 | __le64 mac_addr[FLASH_NUM_PORTS + 1]; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 286 | int valid_mac = 0; |
| 287 | u32 val; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 288 | int pci_func_id = PCI_FUNC(pdev->devfn); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 289 | DECLARE_MAC_BUF(mac); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 290 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 291 | printk(KERN_INFO "%s \n", netxen_nic_driver_string); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 292 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 293 | if (pdev->class != 0x020000) { |
Joe Perches | 5bc5142 | 2007-11-19 17:48:24 -0800 | [diff] [blame] | 294 | printk(KERN_ERR"NetXen function %d, class %x will not " |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 295 | "be enabled.\n",pci_func_id, pdev->class); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 296 | return -ENODEV; |
| 297 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 298 | if ((err = pci_enable_device(pdev))) |
| 299 | return err; |
| 300 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 301 | err = -ENODEV; |
| 302 | goto err_out_disable_pdev; |
| 303 | } |
| 304 | |
| 305 | if ((err = pci_request_regions(pdev, netxen_nic_driver_name))) |
| 306 | goto err_out_disable_pdev; |
| 307 | |
| 308 | pci_set_master(pdev); |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 309 | if (pdev->revision == NX_P2_C1 && |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 310 | (pci_set_dma_mask(pdev, DMA_35BIT_MASK) == 0) && |
| 311 | (pci_set_consistent_dma_mask(pdev, DMA_35BIT_MASK) == 0)) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 312 | pci_using_dac = 1; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 313 | } else { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 314 | if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) || |
| 315 | (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) |
| 316 | goto err_out_free_res; |
| 317 | |
| 318 | pci_using_dac = 0; |
| 319 | } |
| 320 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 321 | |
| 322 | netdev = alloc_etherdev(sizeof(struct netxen_adapter)); |
| 323 | if(!netdev) { |
| 324 | printk(KERN_ERR"%s: Failed to allocate memory for the " |
| 325 | "device block.Check system memory resource" |
| 326 | " usage.\n", netxen_nic_driver_name); |
| 327 | goto err_out_free_res; |
| 328 | } |
| 329 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 330 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 331 | |
| 332 | adapter = netdev->priv; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 333 | |
| 334 | adapter->ahw.pdev = pdev; |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 335 | adapter->ahw.pci_func = pci_func_id; |
| 336 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 337 | /* remap phys address */ |
| 338 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 339 | mem_len = pci_resource_len(pdev, 0); |
| 340 | |
| 341 | /* 128 Meg of memory */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 342 | if (mem_len == NETXEN_PCI_128MB_SIZE) { |
| 343 | mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE); |
| 344 | mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START, |
| 345 | SECOND_PAGE_GROUP_SIZE); |
| 346 | mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START, |
| 347 | THIRD_PAGE_GROUP_SIZE); |
| 348 | first_page_group_start = FIRST_PAGE_GROUP_START; |
| 349 | first_page_group_end = FIRST_PAGE_GROUP_END; |
| 350 | } else if (mem_len == NETXEN_PCI_32MB_SIZE) { |
| 351 | mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE); |
| 352 | mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START - |
| 353 | SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE); |
| 354 | first_page_group_start = 0; |
| 355 | first_page_group_end = 0; |
| 356 | } else { |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 357 | err = -EIO; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 358 | goto err_out_free_netdev; |
| 359 | } |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 360 | |
Al Viro | 79ea13c | 2008-01-24 02:06:46 -0800 | [diff] [blame] | 361 | if ((!mem_ptr0 && mem_len == NETXEN_PCI_128MB_SIZE) || |
| 362 | !mem_ptr1 || !mem_ptr2) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 363 | DPRINTK(ERR, |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 364 | "Cannot remap adapter memory aborting.:" |
| 365 | "0 -> %p, 1 -> %p, 2 -> %p\n", |
| 366 | mem_ptr0, mem_ptr1, mem_ptr2); |
| 367 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 368 | err = -EIO; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 369 | goto err_out_iounmap; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 370 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 371 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ |
| 372 | db_len = pci_resource_len(pdev, 4); |
| 373 | |
| 374 | if (db_len == 0) { |
| 375 | printk(KERN_ERR "%s: doorbell is disabled\n", |
| 376 | netxen_nic_driver_name); |
| 377 | err = -EIO; |
| 378 | goto err_out_iounmap; |
| 379 | } |
| 380 | DPRINTK(INFO, "doorbell ioremap from %lx a size of %lx\n", db_base, |
| 381 | db_len); |
| 382 | |
| 383 | db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES); |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 384 | if (!db_ptr) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 385 | printk(KERN_ERR "%s: Failed to allocate doorbell map.", |
| 386 | netxen_nic_driver_name); |
| 387 | err = -EIO; |
| 388 | goto err_out_iounmap; |
| 389 | } |
| 390 | DPRINTK(INFO, "doorbell ioremaped at %p\n", db_ptr); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 391 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 392 | adapter->ahw.pci_base0 = mem_ptr0; |
| 393 | adapter->ahw.first_page_group_start = first_page_group_start; |
| 394 | adapter->ahw.first_page_group_end = first_page_group_end; |
| 395 | adapter->ahw.pci_base1 = mem_ptr1; |
| 396 | adapter->ahw.pci_base2 = mem_ptr2; |
| 397 | adapter->ahw.db_base = db_ptr; |
| 398 | adapter->ahw.db_len = db_len; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 399 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 400 | adapter->netdev = netdev; |
| 401 | adapter->pdev = pdev; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 402 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 403 | netif_napi_add(netdev, &adapter->napi, |
| 404 | netxen_nic_poll, NETXEN_NETDEV_WEIGHT); |
| 405 | |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 406 | /* this will be read from FW later */ |
| 407 | adapter->intr_scheme = -1; |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 408 | adapter->msi_mode = -1; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 409 | |
| 410 | /* This will be reset for mezz cards */ |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 411 | adapter->portnum = pci_func_id; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 412 | adapter->status &= ~NETXEN_NETDEV_STATUS; |
Dhananjay Phadke | 200eef2 | 2007-09-03 10:33:35 +0530 | [diff] [blame] | 413 | adapter->rx_csum = 1; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 414 | |
| 415 | netdev->open = netxen_nic_open; |
| 416 | netdev->stop = netxen_nic_close; |
| 417 | netdev->hard_start_xmit = netxen_nic_xmit_frame; |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 418 | netdev->get_stats = netxen_nic_get_stats; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 419 | netdev->set_multicast_list = netxen_nic_set_multi; |
| 420 | netdev->set_mac_address = netxen_nic_set_mac; |
| 421 | netdev->change_mtu = netxen_nic_change_mtu; |
| 422 | netdev->tx_timeout = netxen_tx_timeout; |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 423 | netdev->watchdog_timeo = 2*HZ; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 424 | |
| 425 | netxen_nic_change_mtu(netdev, netdev->mtu); |
| 426 | |
| 427 | SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 428 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 429 | netdev->poll_controller = netxen_nic_poll_controller; |
| 430 | #endif |
| 431 | /* ScatterGather support */ |
| 432 | netdev->features = NETIF_F_SG; |
| 433 | netdev->features |= NETIF_F_IP_CSUM; |
| 434 | netdev->features |= NETIF_F_TSO; |
| 435 | |
| 436 | if (pci_using_dac) |
| 437 | netdev->features |= NETIF_F_HIGHDMA; |
| 438 | |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 439 | if (pci_enable_msi(pdev)) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 440 | adapter->flags &= ~NETXEN_NIC_MSI_ENABLED; |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 441 | else |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 442 | adapter->flags |= NETXEN_NIC_MSI_ENABLED; |
| 443 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 444 | netdev->irq = pdev->irq; |
| 445 | INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task); |
| 446 | |
| 447 | /* |
| 448 | * Set the CRB window to invalid. If any register in window 0 is |
| 449 | * accessed it should set the window to 0 and then reset it to 1. |
| 450 | */ |
| 451 | adapter->curr_window = 255; |
| 452 | |
| 453 | /* initialize the adapter */ |
| 454 | netxen_initialize_adapter_hw(adapter); |
| 455 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 456 | /* |
| 457 | * Adapter in our case is quad port so initialize it before |
| 458 | * initializing the ports |
| 459 | */ |
| 460 | |
| 461 | netxen_initialize_adapter_ops(adapter); |
| 462 | |
| 463 | adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS_HOST; |
| 464 | if ((adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB35_4G) || |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 465 | (adapter->ahw.boardcfg.board_type == |
| 466 | NETXEN_BRDTYPE_P2_SB31_2G)) |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 467 | adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G; |
| 468 | else |
| 469 | adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS; |
| 470 | adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS; |
| 471 | adapter->max_lro_rx_desc_count = MAX_LRO_RCV_DESCRIPTORS; |
| 472 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 473 | cmd_buf_arr = (struct netxen_cmd_buffer *)vmalloc(TX_RINGSIZE); |
| 474 | if (cmd_buf_arr == NULL) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 475 | printk(KERN_ERR |
| 476 | "%s: Could not allocate cmd_buf_arr memory:%d\n", |
| 477 | netxen_nic_driver_name, (int)TX_RINGSIZE); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 478 | err = -ENOMEM; |
| 479 | goto err_out_free_adapter; |
| 480 | } |
| 481 | memset(cmd_buf_arr, 0, TX_RINGSIZE); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 482 | adapter->cmd_buf_arr = cmd_buf_arr; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 483 | |
| 484 | for (i = 0; i < MAX_RCV_CTX; ++i) { |
| 485 | recv_ctx = &adapter->recv_ctx[i]; |
| 486 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 487 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 488 | switch (RCV_DESC_TYPE(ring)) { |
| 489 | case RCV_DESC_NORMAL: |
| 490 | rcv_desc->max_rx_desc_count = |
| 491 | adapter->max_rx_desc_count; |
| 492 | rcv_desc->flags = RCV_DESC_NORMAL; |
| 493 | rcv_desc->dma_size = RX_DMA_MAP_LEN; |
| 494 | rcv_desc->skb_size = MAX_RX_BUFFER_LENGTH; |
| 495 | break; |
| 496 | |
| 497 | case RCV_DESC_JUMBO: |
| 498 | rcv_desc->max_rx_desc_count = |
| 499 | adapter->max_jumbo_rx_desc_count; |
| 500 | rcv_desc->flags = RCV_DESC_JUMBO; |
| 501 | rcv_desc->dma_size = RX_JUMBO_DMA_MAP_LEN; |
| 502 | rcv_desc->skb_size = MAX_RX_JUMBO_BUFFER_LENGTH; |
| 503 | break; |
| 504 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 505 | case RCV_RING_LRO: |
| 506 | rcv_desc->max_rx_desc_count = |
| 507 | adapter->max_lro_rx_desc_count; |
| 508 | rcv_desc->flags = RCV_DESC_LRO; |
| 509 | rcv_desc->dma_size = RX_LRO_DMA_MAP_LEN; |
| 510 | rcv_desc->skb_size = MAX_RX_LRO_BUFFER_LENGTH; |
| 511 | break; |
| 512 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 513 | } |
| 514 | rcv_desc->rx_buf_arr = (struct netxen_rx_buffer *) |
| 515 | vmalloc(RCV_BUFFSIZE); |
| 516 | |
| 517 | if (rcv_desc->rx_buf_arr == NULL) { |
Joe Perches | 5bc5142 | 2007-11-19 17:48:24 -0800 | [diff] [blame] | 518 | printk(KERN_ERR "%s: Could not allocate " |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 519 | "rcv_desc->rx_buf_arr memory:%d\n", |
| 520 | netxen_nic_driver_name, |
| 521 | (int)RCV_BUFFSIZE); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 522 | err = -ENOMEM; |
| 523 | goto err_out_free_rx_buffer; |
| 524 | } |
| 525 | memset(rcv_desc->rx_buf_arr, 0, RCV_BUFFSIZE); |
| 526 | } |
| 527 | |
| 528 | } |
| 529 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 530 | netxen_initialize_adapter_sw(adapter); /* initialize the buffers in adapter */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 531 | |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 532 | /* Mezz cards have PCI function 0,2,3 enabled */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 533 | if ((adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) |
| 534 | && (pci_func_id >= 2)) |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 535 | adapter->portnum = pci_func_id - 2; |
| 536 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 537 | #ifdef CONFIG_IA64 |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 538 | if(adapter->portnum == 0) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 539 | netxen_pinit_from_rom(adapter, 0); |
| 540 | udelay(500); |
| 541 | netxen_load_firmware(adapter); |
| 542 | } |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 543 | #endif |
| 544 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 545 | init_timer(&adapter->watchdog_timer); |
| 546 | adapter->ahw.xg_linkup = 0; |
| 547 | adapter->watchdog_timer.function = &netxen_watchdog; |
| 548 | adapter->watchdog_timer.data = (unsigned long)adapter; |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 549 | INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 550 | adapter->ahw.pdev = pdev; |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 551 | adapter->ahw.revision_id = pdev->revision; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 552 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 553 | /* make sure Window == 1 */ |
| 554 | netxen_nic_pci_change_crbwindow(adapter, 1); |
| 555 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 556 | netxen_nic_update_cmd_producer(adapter, 0); |
| 557 | netxen_nic_update_cmd_consumer(adapter, 0); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 558 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_CMD_ADDR_LO)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 559 | |
| 560 | if (netxen_is_flash_supported(adapter) == 0 && |
| 561 | netxen_get_flash_mac_addr(adapter, mac_addr) == 0) |
| 562 | valid_mac = 1; |
| 563 | else |
| 564 | valid_mac = 0; |
| 565 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 566 | if (valid_mac) { |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 567 | unsigned char *p = (unsigned char *)&mac_addr[adapter->portnum]; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 568 | netdev->dev_addr[0] = *(p + 5); |
| 569 | netdev->dev_addr[1] = *(p + 4); |
| 570 | netdev->dev_addr[2] = *(p + 3); |
| 571 | netdev->dev_addr[3] = *(p + 2); |
| 572 | netdev->dev_addr[4] = *(p + 1); |
| 573 | netdev->dev_addr[5] = *(p + 0); |
| 574 | |
| 575 | memcpy(netdev->perm_addr, netdev->dev_addr, |
| 576 | netdev->addr_len); |
| 577 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 578 | printk(KERN_ERR "%s: Bad MAC address %s.\n", |
| 579 | netxen_nic_driver_name, |
| 580 | print_mac(mac, netdev->dev_addr)); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 581 | } else { |
| 582 | if (adapter->macaddr_set) |
| 583 | adapter->macaddr_set(adapter, |
| 584 | netdev->dev_addr); |
| 585 | } |
| 586 | } |
| 587 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 588 | if (adapter->portnum == 0) { |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 589 | err = netxen_initialize_adapter_offload(adapter); |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 590 | if (err) |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 591 | goto err_out_free_rx_buffer; |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 592 | val = readl(NETXEN_CRB_NORMALIZE(adapter, |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 593 | NETXEN_CAM_RAM(0x1fc))); |
| 594 | if (val == 0x55555555) { |
| 595 | /* This is the first boot after power up */ |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 596 | netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(0x4), &val); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 597 | if (!(val & 0x4)) { |
| 598 | val |= 0x4; |
| 599 | netxen_nic_write_w0(adapter, NETXEN_PCIE_REG(0x4), val); |
| 600 | netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(0x4), &val); |
| 601 | if (!(val & 0x4)) |
| 602 | printk(KERN_ERR "%s: failed to set MSI bit in PCI-e reg\n", |
| 603 | netxen_nic_driver_name); |
| 604 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 605 | val = readl(NETXEN_CRB_NORMALIZE(adapter, |
| 606 | NETXEN_ROMUSB_GLB_SW_RESET)); |
| 607 | printk(KERN_INFO"NetXen: read 0x%08x for reset reg.\n",val); |
| 608 | if (val != 0x80000f) { |
| 609 | /* clear the register for future unloads/loads */ |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 610 | writel(0, NETXEN_CRB_NORMALIZE(adapter, |
| 611 | NETXEN_CAM_RAM(0x1fc))); |
| 612 | printk(KERN_ERR "ERROR in NetXen HW init sequence.\n"); |
| 613 | err = -ENODEV; |
| 614 | goto err_out_free_dev; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 615 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 616 | } |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 617 | |
| 618 | /* clear the register for future unloads/loads */ |
| 619 | writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc))); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 620 | printk(KERN_INFO "State: 0x%0x\n", |
| 621 | readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE))); |
| 622 | |
| 623 | /* |
| 624 | * Tell the hardware our version number. |
| 625 | */ |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 626 | i = (_NETXEN_NIC_LINUX_MAJOR << 16) |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 627 | | ((_NETXEN_NIC_LINUX_MINOR << 8)) |
| 628 | | (_NETXEN_NIC_LINUX_SUBVERSION); |
| 629 | writel(i, NETXEN_CRB_NORMALIZE(adapter, CRB_DRIVER_VERSION)); |
| 630 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 631 | /* Unlock the HW, prompting the boot sequence */ |
| 632 | writel(1, |
| 633 | NETXEN_CRB_NORMALIZE(adapter, |
| 634 | NETXEN_ROMUSB_GLB_PEGTUNE_DONE)); |
| 635 | /* Handshake with the card before we register the devices. */ |
| 636 | netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 637 | } |
| 638 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 639 | /* |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 640 | * See if the firmware gave us a virtual-physical port mapping. |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 641 | */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 642 | i = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_V2P(adapter->portnum))); |
| 643 | if (i != 0x55555555) |
| 644 | physical_port[adapter->portnum] = i; |
| 645 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 646 | netif_carrier_off(netdev); |
| 647 | netif_stop_queue(netdev); |
| 648 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 649 | if ((err = register_netdev(netdev))) { |
| 650 | printk(KERN_ERR "%s: register_netdev failed port #%d" |
| 651 | " aborting\n", netxen_nic_driver_name, |
| 652 | adapter->portnum); |
| 653 | err = -EIO; |
| 654 | goto err_out_free_dev; |
| 655 | } |
| 656 | |
| 657 | pci_set_drvdata(pdev, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 658 | |
| 659 | switch (adapter->ahw.board_type) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 660 | case NETXEN_NIC_GBE: |
| 661 | printk(KERN_INFO "%s: QUAD GbE board initialized\n", |
| 662 | netxen_nic_driver_name); |
| 663 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 664 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 665 | case NETXEN_NIC_XGBE: |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 666 | printk(KERN_INFO "%s: XGbE board initialized\n", |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 667 | netxen_nic_driver_name); |
| 668 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | adapter->driver_mismatch = 0; |
| 672 | |
| 673 | return 0; |
| 674 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 675 | err_out_free_dev: |
| 676 | if (adapter->portnum == 0) |
| 677 | netxen_free_adapter_offload(adapter); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 678 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 679 | err_out_free_rx_buffer: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 680 | for (i = 0; i < MAX_RCV_CTX; ++i) { |
| 681 | recv_ctx = &adapter->recv_ctx[i]; |
| 682 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 683 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 684 | if (rcv_desc->rx_buf_arr != NULL) { |
| 685 | vfree(rcv_desc->rx_buf_arr); |
| 686 | rcv_desc->rx_buf_arr = NULL; |
| 687 | } |
| 688 | } |
| 689 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 690 | vfree(cmd_buf_arr); |
| 691 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 692 | err_out_free_adapter: |
| 693 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 694 | pci_disable_msi(pdev); |
| 695 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 696 | pci_set_drvdata(pdev, NULL); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 697 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 698 | if (db_ptr) |
| 699 | iounmap(db_ptr); |
| 700 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 701 | err_out_iounmap: |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 702 | if (mem_ptr0) |
| 703 | iounmap(mem_ptr0); |
| 704 | if (mem_ptr1) |
| 705 | iounmap(mem_ptr1); |
| 706 | if (mem_ptr2) |
| 707 | iounmap(mem_ptr2); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 708 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 709 | err_out_free_netdev: |
| 710 | free_netdev(netdev); |
| 711 | |
| 712 | err_out_free_res: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 713 | pci_release_regions(pdev); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 714 | |
| 715 | err_out_disable_pdev: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 716 | pci_disable_device(pdev); |
| 717 | return err; |
| 718 | } |
| 719 | |
| 720 | static void __devexit netxen_nic_remove(struct pci_dev *pdev) |
| 721 | { |
| 722 | struct netxen_adapter *adapter; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 723 | struct net_device *netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 724 | struct netxen_rx_buffer *buffer; |
| 725 | struct netxen_recv_context *recv_ctx; |
| 726 | struct netxen_rcv_desc_ctx *rcv_desc; |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 727 | int i, ctxid, ring; |
| 728 | static int init_firmware_done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 729 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 730 | adapter = pci_get_drvdata(pdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 731 | if (adapter == NULL) |
| 732 | return; |
| 733 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 734 | netdev = adapter->netdev; |
| 735 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 736 | unregister_netdev(netdev); |
| 737 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 738 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
| 739 | init_firmware_done++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 740 | netxen_free_hw_resources(adapter); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 741 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 742 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 743 | for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) { |
| 744 | recv_ctx = &adapter->recv_ctx[ctxid]; |
| 745 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 746 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 747 | for (i = 0; i < rcv_desc->max_rx_desc_count; ++i) { |
| 748 | buffer = &(rcv_desc->rx_buf_arr[i]); |
| 749 | if (buffer->state == NETXEN_BUFFER_FREE) |
| 750 | continue; |
| 751 | pci_unmap_single(pdev, buffer->dma, |
| 752 | rcv_desc->dma_size, |
| 753 | PCI_DMA_FROMDEVICE); |
| 754 | if (buffer->skb != NULL) |
| 755 | dev_kfree_skb_any(buffer->skb); |
| 756 | } |
| 757 | vfree(rcv_desc->rx_buf_arr); |
| 758 | } |
| 759 | } |
| 760 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 761 | vfree(adapter->cmd_buf_arr); |
| 762 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 763 | if (adapter->portnum == 0) { |
| 764 | if (init_firmware_done) { |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 765 | i = 100; |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 766 | do { |
| 767 | if (dma_watchdog_shutdown_request(adapter) == 1) |
| 768 | break; |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 769 | msleep(100); |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 770 | if (dma_watchdog_shutdown_poll_result(adapter) == 1) |
| 771 | break; |
| 772 | } while (--i); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 773 | |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 774 | if (i == 0) |
| 775 | printk(KERN_ERR "%s: dma_watchdog_shutdown failed\n", |
| 776 | netdev->name); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 777 | |
| 778 | /* clear the register for future unloads/loads */ |
| 779 | writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc))); |
| 780 | printk(KERN_INFO "State: 0x%0x\n", |
| 781 | readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE))); |
| 782 | |
| 783 | /* leave the hw in the same state as reboot */ |
| 784 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 785 | netxen_pinit_from_rom(adapter, 0); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 786 | msleep(1); |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 787 | netxen_load_firmware(adapter); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 788 | netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
| 789 | } |
| 790 | |
| 791 | /* clear the register for future unloads/loads */ |
| 792 | writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc))); |
| 793 | printk(KERN_INFO "State: 0x%0x\n", |
| 794 | readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE))); |
| 795 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 796 | i = 100; |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 797 | do { |
| 798 | if (dma_watchdog_shutdown_request(adapter) == 1) |
| 799 | break; |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 800 | msleep(100); |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 801 | if (dma_watchdog_shutdown_poll_result(adapter) == 1) |
| 802 | break; |
| 803 | } while (--i); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 804 | |
| 805 | if (i) { |
| 806 | netxen_free_adapter_offload(adapter); |
| 807 | } else { |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 808 | printk(KERN_ERR "%s: dma_watchdog_shutdown failed\n", |
| 809 | netdev->name); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 810 | } |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 811 | } |
| 812 | |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 813 | if (adapter->irq) |
| 814 | free_irq(adapter->irq, adapter); |
| 815 | |
| 816 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 817 | pci_disable_msi(pdev); |
| 818 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 819 | iounmap(adapter->ahw.db_base); |
| 820 | iounmap(adapter->ahw.pci_base0); |
| 821 | iounmap(adapter->ahw.pci_base1); |
| 822 | iounmap(adapter->ahw.pci_base2); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 823 | |
| 824 | pci_release_regions(pdev); |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 825 | pci_disable_device(pdev); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 826 | pci_set_drvdata(pdev, NULL); |
| 827 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 828 | free_netdev(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | /* |
| 832 | * Called when a network interface is made active |
| 833 | * @returns 0 on success, negative value on failure |
| 834 | */ |
| 835 | static int netxen_nic_open(struct net_device *netdev) |
| 836 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 837 | struct netxen_adapter *adapter = (struct netxen_adapter *)netdev->priv; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 838 | int err = 0; |
| 839 | int ctx, ring; |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 840 | irq_handler_t handler; |
| 841 | unsigned long flags = IRQF_SAMPLE_RANDOM; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 842 | |
| 843 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) { |
| 844 | err = netxen_init_firmware(adapter); |
| 845 | if (err != 0) { |
| 846 | printk(KERN_ERR "Failed to init firmware\n"); |
| 847 | return -EIO; |
| 848 | } |
| 849 | netxen_nic_flash_print(adapter); |
| 850 | |
| 851 | /* setup all the resources for the Phantom... */ |
| 852 | /* this include the descriptors for rcv, tx, and status */ |
| 853 | netxen_nic_clear_stats(adapter); |
| 854 | err = netxen_nic_hw_resources(adapter); |
| 855 | if (err) { |
| 856 | printk(KERN_ERR "Error in setting hw resources:%d\n", |
| 857 | err); |
| 858 | return err; |
| 859 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 860 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 861 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 862 | netxen_post_rx_buffers(adapter, ctx, ring); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 863 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 864 | adapter->irq = adapter->ahw.pdev->irq; |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 865 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 866 | handler = netxen_msi_intr; |
| 867 | else { |
| 868 | flags |= IRQF_SHARED; |
| 869 | handler = netxen_intr; |
| 870 | } |
| 871 | err = request_irq(adapter->irq, handler, |
| 872 | flags, netdev->name, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 873 | if (err) { |
| 874 | printk(KERN_ERR "request_irq failed with: %d\n", err); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 875 | netxen_free_hw_resources(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 876 | return err; |
| 877 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 878 | |
| 879 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; |
| 880 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 881 | /* Done here again so that even if phantom sw overwrote it, |
| 882 | * we set it */ |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 883 | if (adapter->init_port |
| 884 | && adapter->init_port(adapter, adapter->portnum) != 0) { |
| 885 | printk(KERN_ERR "%s: Failed to initialize port %d\n", |
| 886 | netxen_nic_driver_name, adapter->portnum); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 887 | return -EIO; |
| 888 | } |
dhananjay@netxen.com | 7eec517 | 2007-07-25 20:13:11 +0530 | [diff] [blame] | 889 | if (adapter->macaddr_set) |
| 890 | adapter->macaddr_set(adapter, netdev->dev_addr); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 891 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 892 | netxen_nic_set_link_parameters(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 893 | |
| 894 | netxen_nic_set_multi(netdev); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 895 | if (adapter->set_mtu) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 896 | adapter->set_mtu(adapter, netdev->mtu); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 897 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 898 | if (!adapter->driver_mismatch) |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 899 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 900 | |
| 901 | napi_enable(&adapter->napi); |
| 902 | netxen_nic_enable_int(adapter); |
| 903 | |
| 904 | if (!adapter->driver_mismatch) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 905 | netif_start_queue(netdev); |
| 906 | |
| 907 | return 0; |
| 908 | } |
| 909 | |
| 910 | /* |
| 911 | * netxen_nic_close - Disables a network interface entry point |
| 912 | */ |
| 913 | static int netxen_nic_close(struct net_device *netdev) |
| 914 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 915 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 916 | int i, j; |
| 917 | struct netxen_cmd_buffer *cmd_buff; |
| 918 | struct netxen_skb_frag *buffrag; |
| 919 | |
| 920 | netif_carrier_off(netdev); |
| 921 | netif_stop_queue(netdev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 922 | napi_disable(&adapter->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 923 | |
dhananjay@netxen.com | 72b0a7a | 2007-12-26 10:23:56 -0800 | [diff] [blame] | 924 | if (adapter->stop_port) |
| 925 | adapter->stop_port(adapter); |
| 926 | |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 927 | netxen_nic_disable_int(adapter); |
| 928 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 929 | cmd_buff = adapter->cmd_buf_arr; |
| 930 | for (i = 0; i < adapter->max_tx_desc_count; i++) { |
| 931 | buffrag = cmd_buff->frag_array; |
| 932 | if (buffrag->dma) { |
| 933 | pci_unmap_single(adapter->pdev, buffrag->dma, |
| 934 | buffrag->length, PCI_DMA_TODEVICE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 935 | buffrag->dma = 0ULL; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 936 | } |
| 937 | for (j = 0; j < cmd_buff->frag_count; j++) { |
| 938 | buffrag++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 939 | if (buffrag->dma) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 940 | pci_unmap_page(adapter->pdev, buffrag->dma, |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 941 | buffrag->length, |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 942 | PCI_DMA_TODEVICE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 943 | buffrag->dma = 0ULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 944 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 945 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 946 | /* Free the skb we received in netxen_nic_xmit_frame */ |
| 947 | if (cmd_buff->skb) { |
| 948 | dev_kfree_skb_any(cmd_buff->skb); |
| 949 | cmd_buff->skb = NULL; |
| 950 | } |
| 951 | cmd_buff++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 952 | } |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 953 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
| 954 | FLUSH_SCHEDULED_WORK(); |
| 955 | del_timer_sync(&adapter->watchdog_timer); |
| 956 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 957 | |
| 958 | return 0; |
| 959 | } |
| 960 | |
| 961 | static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 962 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 963 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 964 | struct netxen_hardware_context *hw = &adapter->ahw; |
| 965 | unsigned int first_seg_len = skb->len - skb->data_len; |
| 966 | struct netxen_skb_frag *buffrag; |
| 967 | unsigned int i; |
| 968 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 969 | u32 producer, consumer; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 970 | u32 saved_producer = 0; |
| 971 | struct cmd_desc_type0 *hwdesc; |
| 972 | int k; |
| 973 | struct netxen_cmd_buffer *pbuf = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 974 | int frag_count; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 975 | int no_of_desc; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 976 | u32 num_txd = adapter->max_tx_desc_count; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 977 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 978 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
| 979 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 980 | /* There 4 fragments per descriptor */ |
| 981 | no_of_desc = (frag_count + 3) >> 2; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 982 | if (netdev->features & NETIF_F_TSO) { |
| 983 | if (skb_shinfo(skb)->gso_size > 0) { |
| 984 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 985 | no_of_desc++; |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 986 | if ((ip_hdrlen(skb) + tcp_hdrlen(skb) + |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 987 | sizeof(struct ethhdr)) > |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 988 | (sizeof(struct cmd_desc_type0) - 2)) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 989 | no_of_desc++; |
| 990 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 991 | } |
| 992 | } |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 993 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 994 | producer = adapter->cmd_producer; |
| 995 | smp_mb(); |
| 996 | consumer = adapter->last_cmd_consumer; |
| 997 | if ((no_of_desc+2) > find_diff_among(producer, consumer, num_txd)) { |
| 998 | netif_stop_queue(netdev); |
| 999 | smp_mb(); |
| 1000 | return NETDEV_TX_BUSY; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1001 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1002 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1003 | /* Copy the descriptors into the hardware */ |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1004 | saved_producer = producer; |
| 1005 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1006 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
| 1007 | /* Take skb->data itself */ |
| 1008 | pbuf = &adapter->cmd_buf_arr[producer]; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1009 | if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) { |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1010 | pbuf->mss = skb_shinfo(skb)->gso_size; |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1011 | hwdesc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1012 | } else { |
| 1013 | pbuf->mss = 0; |
| 1014 | hwdesc->mss = 0; |
| 1015 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1016 | pbuf->total_length = skb->len; |
| 1017 | pbuf->skb = skb; |
| 1018 | pbuf->cmd = TX_ETHER_PKT; |
| 1019 | pbuf->frag_count = frag_count; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1020 | pbuf->port = adapter->portnum; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1021 | buffrag = &pbuf->frag_array[0]; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1022 | buffrag->dma = pci_map_single(adapter->pdev, skb->data, first_seg_len, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1023 | PCI_DMA_TODEVICE); |
| 1024 | buffrag->length = first_seg_len; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1025 | netxen_set_cmd_desc_totallength(hwdesc, skb->len); |
| 1026 | netxen_set_cmd_desc_num_of_buff(hwdesc, frag_count); |
| 1027 | netxen_set_cmd_desc_opcode(hwdesc, TX_ETHER_PKT); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1028 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1029 | netxen_set_cmd_desc_port(hwdesc, adapter->portnum); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1030 | netxen_set_cmd_desc_ctxid(hwdesc, adapter->portnum); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1031 | hwdesc->buffer1_length = cpu_to_le16(first_seg_len); |
| 1032 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); |
| 1033 | |
| 1034 | for (i = 1, k = 1; i < frag_count; i++, k++) { |
| 1035 | struct skb_frag_struct *frag; |
| 1036 | int len, temp_len; |
| 1037 | unsigned long offset; |
| 1038 | dma_addr_t temp_dma; |
| 1039 | |
| 1040 | /* move to next desc. if there is a need */ |
| 1041 | if ((i & 0x3) == 0) { |
| 1042 | k = 0; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1043 | producer = get_next_index(producer, num_txd); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1044 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1045 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1046 | pbuf = &adapter->cmd_buf_arr[producer]; |
| 1047 | pbuf->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1048 | } |
| 1049 | frag = &skb_shinfo(skb)->frags[i - 1]; |
| 1050 | len = frag->size; |
| 1051 | offset = frag->page_offset; |
| 1052 | |
| 1053 | temp_len = len; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1054 | temp_dma = pci_map_page(adapter->pdev, frag->page, offset, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1055 | len, PCI_DMA_TODEVICE); |
| 1056 | |
| 1057 | buffrag++; |
| 1058 | buffrag->dma = temp_dma; |
| 1059 | buffrag->length = temp_len; |
| 1060 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1061 | switch (k) { |
| 1062 | case 0: |
| 1063 | hwdesc->buffer1_length = cpu_to_le16(temp_len); |
| 1064 | hwdesc->addr_buffer1 = cpu_to_le64(temp_dma); |
| 1065 | break; |
| 1066 | case 1: |
| 1067 | hwdesc->buffer2_length = cpu_to_le16(temp_len); |
| 1068 | hwdesc->addr_buffer2 = cpu_to_le64(temp_dma); |
| 1069 | break; |
| 1070 | case 2: |
| 1071 | hwdesc->buffer3_length = cpu_to_le16(temp_len); |
| 1072 | hwdesc->addr_buffer3 = cpu_to_le64(temp_dma); |
| 1073 | break; |
| 1074 | case 3: |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1075 | hwdesc->buffer4_length = cpu_to_le16(temp_len); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1076 | hwdesc->addr_buffer4 = cpu_to_le64(temp_dma); |
| 1077 | break; |
| 1078 | } |
| 1079 | frag++; |
| 1080 | } |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1081 | producer = get_next_index(producer, num_txd); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1082 | |
| 1083 | /* might change opcode to TX_TCP_LSO */ |
| 1084 | netxen_tso_check(adapter, &hw->cmd_desc_head[saved_producer], skb); |
| 1085 | |
| 1086 | /* For LSO, we need to copy the MAC/IP/TCP headers into |
| 1087 | * the descriptor ring |
| 1088 | */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1089 | if (netxen_get_cmd_desc_opcode(&hw->cmd_desc_head[saved_producer]) |
| 1090 | == TX_TCP_LSO) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1091 | int hdr_len, first_hdr_len, more_hdr; |
| 1092 | hdr_len = hw->cmd_desc_head[saved_producer].total_hdr_length; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1093 | if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) { |
| 1094 | first_hdr_len = sizeof(struct cmd_desc_type0) - 2; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1095 | more_hdr = 1; |
| 1096 | } else { |
| 1097 | first_hdr_len = hdr_len; |
| 1098 | more_hdr = 0; |
| 1099 | } |
| 1100 | /* copy the MAC/IP/TCP headers to the cmd descriptor list */ |
| 1101 | hwdesc = &hw->cmd_desc_head[producer]; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1102 | pbuf = &adapter->cmd_buf_arr[producer]; |
| 1103 | pbuf->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1104 | |
| 1105 | /* copy the first 64 bytes */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1106 | memcpy(((void *)hwdesc) + 2, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1107 | (void *)(skb->data), first_hdr_len); |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1108 | producer = get_next_index(producer, num_txd); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1109 | |
| 1110 | if (more_hdr) { |
| 1111 | hwdesc = &hw->cmd_desc_head[producer]; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1112 | pbuf = &adapter->cmd_buf_arr[producer]; |
| 1113 | pbuf->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1114 | /* copy the next 64 bytes - should be enough except |
| 1115 | * for pathological case |
| 1116 | */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1117 | skb_copy_from_linear_data_offset(skb, first_hdr_len, |
| 1118 | hwdesc, |
| 1119 | (hdr_len - |
| 1120 | first_hdr_len)); |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1121 | producer = get_next_index(producer, num_txd); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1122 | } |
| 1123 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1124 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1125 | adapter->cmd_producer = producer; |
Dhananjay Phadke | 5dc1626 | 2007-12-31 10:08:57 -0800 | [diff] [blame] | 1126 | adapter->stats.txbytes += skb->len; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1127 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1128 | netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1129 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1130 | adapter->stats.xmitcalled++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1131 | netdev->trans_start = jiffies; |
| 1132 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1133 | return NETDEV_TX_OK; |
| 1134 | } |
| 1135 | |
| 1136 | static void netxen_watchdog(unsigned long v) |
| 1137 | { |
| 1138 | struct netxen_adapter *adapter = (struct netxen_adapter *)v; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1139 | |
| 1140 | SCHEDULE_WORK(&adapter->watchdog_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | static void netxen_tx_timeout(struct net_device *netdev) |
| 1144 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1145 | struct netxen_adapter *adapter = (struct netxen_adapter *) |
| 1146 | netdev_priv(netdev); |
| 1147 | SCHEDULE_WORK(&adapter->tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1148 | } |
| 1149 | |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 1150 | static void netxen_tx_timeout_task(struct work_struct *work) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1151 | { |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 1152 | struct netxen_adapter *adapter = |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1153 | container_of(work, struct netxen_adapter, tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1154 | |
| 1155 | printk(KERN_ERR "%s %s: transmit timeout, resetting.\n", |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1156 | netxen_nic_driver_name, adapter->netdev->name); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1157 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1158 | netxen_nic_disable_int(adapter); |
| 1159 | napi_disable(&adapter->napi); |
| 1160 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1161 | adapter->netdev->trans_start = jiffies; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1162 | |
| 1163 | napi_enable(&adapter->napi); |
| 1164 | netxen_nic_enable_int(adapter); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1165 | netif_wake_queue(adapter->netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1166 | } |
| 1167 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1168 | static inline void |
| 1169 | netxen_handle_int(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1170 | { |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 1171 | netxen_nic_disable_int(adapter); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1172 | napi_schedule(&adapter->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1173 | } |
| 1174 | |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1175 | irqreturn_t netxen_intr(int irq, void *data) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1176 | { |
Jeff Garzik | 1daec86 | 2007-10-19 03:14:03 -0400 | [diff] [blame] | 1177 | struct netxen_adapter *adapter = data; |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1178 | u32 our_int = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1179 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1180 | our_int = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR)); |
| 1181 | /* not our interrupt */ |
| 1182 | if ((our_int & (0x80 << adapter->portnum)) == 0) |
| 1183 | return IRQ_NONE; |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1184 | |
| 1185 | if (adapter->intr_scheme == INTR_SCHEME_PERPORT) { |
| 1186 | /* claim interrupt */ |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1187 | writel(our_int & ~((u32)(0x80 << adapter->portnum)), |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1188 | NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR)); |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1189 | } |
| 1190 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1191 | netxen_handle_int(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1192 | |
| 1193 | return IRQ_HANDLED; |
| 1194 | } |
| 1195 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1196 | irqreturn_t netxen_msi_intr(int irq, void *data) |
| 1197 | { |
| 1198 | struct netxen_adapter *adapter = data; |
| 1199 | |
| 1200 | netxen_handle_int(adapter); |
| 1201 | return IRQ_HANDLED; |
| 1202 | } |
| 1203 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1204 | static int netxen_nic_poll(struct napi_struct *napi, int budget) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1205 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1206 | struct netxen_adapter *adapter = container_of(napi, struct netxen_adapter, napi); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1207 | int tx_complete; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1208 | int ctx; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1209 | int work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1210 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1211 | tx_complete = netxen_process_cmd_ring(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1212 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1213 | work_done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1214 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
| 1215 | /* |
| 1216 | * Fairness issue. This will give undue weight to the |
| 1217 | * receive context 0. |
| 1218 | */ |
| 1219 | |
| 1220 | /* |
| 1221 | * To avoid starvation, we give each of our receivers, |
| 1222 | * a fraction of the quota. Sometimes, it might happen that we |
| 1223 | * have enough quota to process every packet, but since all the |
| 1224 | * packets are on one context, it gets only half of the quota, |
| 1225 | * and ends up not processing it. |
| 1226 | */ |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1227 | work_done += netxen_process_rcv_ring(adapter, ctx, |
| 1228 | budget / MAX_RCV_CTX); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1229 | } |
| 1230 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1231 | if ((work_done < budget) && tx_complete) { |
| 1232 | netif_rx_complete(adapter->netdev, &adapter->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1233 | netxen_nic_enable_int(adapter); |
| 1234 | } |
| 1235 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1236 | return work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1240 | static void netxen_nic_poll_controller(struct net_device *netdev) |
| 1241 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1242 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1243 | disable_irq(adapter->irq); |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1244 | netxen_intr(adapter->irq, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1245 | enable_irq(adapter->irq); |
| 1246 | } |
| 1247 | #endif |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1248 | |
| 1249 | static struct pci_driver netxen_driver = { |
| 1250 | .name = netxen_nic_driver_name, |
| 1251 | .id_table = netxen_pci_tbl, |
| 1252 | .probe = netxen_nic_probe, |
| 1253 | .remove = __devexit_p(netxen_nic_remove) |
| 1254 | }; |
| 1255 | |
| 1256 | /* Driver Registration on NetXen card */ |
| 1257 | |
| 1258 | static int __init netxen_init_module(void) |
| 1259 | { |
Al Viro | 79ea13c | 2008-01-24 02:06:46 -0800 | [diff] [blame] | 1260 | if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1261 | return -ENOMEM; |
| 1262 | |
Amit S. Kale | 184231b | 2007-01-22 06:52:53 -0800 | [diff] [blame] | 1263 | return pci_register_driver(&netxen_driver); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | module_init(netxen_init_module); |
| 1267 | |
| 1268 | static void __exit netxen_exit_module(void) |
| 1269 | { |
| 1270 | /* |
| 1271 | * Wait for some time to allow the dma to drain, if any. |
| 1272 | */ |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1273 | msleep(100); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1274 | pci_unregister_driver(&netxen_driver); |
Amit S. Kale | 9de0661 | 2007-02-21 06:37:06 -0800 | [diff] [blame] | 1275 | destroy_workqueue(netxen_workq); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | module_exit(netxen_exit_module); |