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