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