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 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [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); |
| 338 | spin_lock_init(&adapter->lock); |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 339 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 340 | /* remap phys address */ |
| 341 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 342 | mem_len = pci_resource_len(pdev, 0); |
| 343 | |
| 344 | /* 128 Meg of memory */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 345 | if (mem_len == NETXEN_PCI_128MB_SIZE) { |
| 346 | mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE); |
| 347 | mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START, |
| 348 | SECOND_PAGE_GROUP_SIZE); |
| 349 | mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START, |
| 350 | THIRD_PAGE_GROUP_SIZE); |
| 351 | first_page_group_start = FIRST_PAGE_GROUP_START; |
| 352 | first_page_group_end = FIRST_PAGE_GROUP_END; |
| 353 | } else if (mem_len == NETXEN_PCI_32MB_SIZE) { |
| 354 | mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE); |
| 355 | mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START - |
| 356 | SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE); |
| 357 | first_page_group_start = 0; |
| 358 | first_page_group_end = 0; |
| 359 | } else { |
| 360 | err = -EIO; |
| 361 | goto err_out_free_netdev; |
| 362 | } |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 363 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 364 | if (((mem_ptr0 == 0UL) && (mem_len == NETXEN_PCI_128MB_SIZE)) || |
| 365 | (mem_ptr1 == 0UL) || (mem_ptr2 == 0UL)) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 366 | DPRINTK(ERR, |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 367 | "Cannot remap adapter memory aborting.:" |
| 368 | "0 -> %p, 1 -> %p, 2 -> %p\n", |
| 369 | mem_ptr0, mem_ptr1, mem_ptr2); |
| 370 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 371 | err = -EIO; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 372 | goto err_out_iounmap; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 373 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 374 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ |
| 375 | db_len = pci_resource_len(pdev, 4); |
| 376 | |
| 377 | if (db_len == 0) { |
| 378 | printk(KERN_ERR "%s: doorbell is disabled\n", |
| 379 | netxen_nic_driver_name); |
| 380 | err = -EIO; |
| 381 | goto err_out_iounmap; |
| 382 | } |
| 383 | DPRINTK(INFO, "doorbell ioremap from %lx a size of %lx\n", db_base, |
| 384 | db_len); |
| 385 | |
| 386 | db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES); |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 387 | if (!db_ptr) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 388 | printk(KERN_ERR "%s: Failed to allocate doorbell map.", |
| 389 | netxen_nic_driver_name); |
| 390 | err = -EIO; |
| 391 | goto err_out_iounmap; |
| 392 | } |
| 393 | DPRINTK(INFO, "doorbell ioremaped at %p\n", db_ptr); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 394 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 395 | adapter->ahw.pci_base0 = mem_ptr0; |
| 396 | adapter->ahw.first_page_group_start = first_page_group_start; |
| 397 | adapter->ahw.first_page_group_end = first_page_group_end; |
| 398 | adapter->ahw.pci_base1 = mem_ptr1; |
| 399 | adapter->ahw.pci_base2 = mem_ptr2; |
| 400 | adapter->ahw.db_base = db_ptr; |
| 401 | adapter->ahw.db_len = db_len; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 402 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 403 | adapter->netdev = netdev; |
| 404 | adapter->pdev = pdev; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 405 | |
| 406 | /* this will be read from FW later */ |
| 407 | adapter->intr_scheme = -1; |
| 408 | |
| 409 | /* This will be reset for mezz cards */ |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 410 | adapter->portnum = pci_func_id; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 411 | adapter->status &= ~NETXEN_NETDEV_STATUS; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 412 | |
| 413 | netdev->open = netxen_nic_open; |
| 414 | netdev->stop = netxen_nic_close; |
| 415 | netdev->hard_start_xmit = netxen_nic_xmit_frame; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 416 | netdev->get_stats = netxen_nic_get_stats; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 417 | netdev->set_multicast_list = netxen_nic_set_multi; |
| 418 | netdev->set_mac_address = netxen_nic_set_mac; |
| 419 | netdev->change_mtu = netxen_nic_change_mtu; |
| 420 | netdev->tx_timeout = netxen_tx_timeout; |
| 421 | netdev->watchdog_timeo = HZ; |
| 422 | |
| 423 | netxen_nic_change_mtu(netdev, netdev->mtu); |
| 424 | |
| 425 | SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops); |
| 426 | netdev->poll = netxen_nic_poll; |
| 427 | netdev->weight = NETXEN_NETDEV_WEIGHT; |
| 428 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 429 | netdev->poll_controller = netxen_nic_poll_controller; |
| 430 | #endif |
| 431 | /* ScatterGather support */ |
| 432 | netdev->features = NETIF_F_SG; |
| 433 | netdev->features |= NETIF_F_IP_CSUM; |
| 434 | netdev->features |= NETIF_F_TSO; |
| 435 | |
| 436 | if (pci_using_dac) |
| 437 | netdev->features |= NETIF_F_HIGHDMA; |
| 438 | |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 439 | if (pci_enable_msi(pdev)) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 440 | adapter->flags &= ~NETXEN_NIC_MSI_ENABLED; |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 441 | else |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 442 | adapter->flags |= NETXEN_NIC_MSI_ENABLED; |
| 443 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 444 | netdev->irq = pdev->irq; |
| 445 | INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task); |
| 446 | |
| 447 | /* |
| 448 | * Set the CRB window to invalid. If any register in window 0 is |
| 449 | * accessed it should set the window to 0 and then reset it to 1. |
| 450 | */ |
| 451 | adapter->curr_window = 255; |
| 452 | |
| 453 | /* initialize the adapter */ |
| 454 | netxen_initialize_adapter_hw(adapter); |
| 455 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 456 | /* |
| 457 | * Adapter in our case is quad port so initialize it before |
| 458 | * initializing the ports |
| 459 | */ |
| 460 | |
| 461 | netxen_initialize_adapter_ops(adapter); |
| 462 | |
| 463 | adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS_HOST; |
| 464 | if ((adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB35_4G) || |
| 465 | (adapter->ahw.boardcfg.board_type == |
| 466 | NETXEN_BRDTYPE_P2_SB31_2G)) |
| 467 | adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G; |
| 468 | else |
| 469 | adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS; |
| 470 | adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS; |
| 471 | adapter->max_lro_rx_desc_count = MAX_LRO_RCV_DESCRIPTORS; |
| 472 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 473 | cmd_buf_arr = (struct netxen_cmd_buffer *)vmalloc(TX_RINGSIZE); |
| 474 | if (cmd_buf_arr == NULL) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 475 | printk(KERN_ERR |
| 476 | "%s: Could not allocate cmd_buf_arr memory:%d\n", |
| 477 | netxen_nic_driver_name, (int)TX_RINGSIZE); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 478 | err = -ENOMEM; |
| 479 | goto err_out_free_adapter; |
| 480 | } |
| 481 | memset(cmd_buf_arr, 0, TX_RINGSIZE); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 482 | adapter->cmd_buf_arr = cmd_buf_arr; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 483 | |
| 484 | for (i = 0; i < MAX_RCV_CTX; ++i) { |
| 485 | recv_ctx = &adapter->recv_ctx[i]; |
| 486 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 487 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 488 | switch (RCV_DESC_TYPE(ring)) { |
| 489 | case RCV_DESC_NORMAL: |
| 490 | rcv_desc->max_rx_desc_count = |
| 491 | adapter->max_rx_desc_count; |
| 492 | rcv_desc->flags = RCV_DESC_NORMAL; |
| 493 | rcv_desc->dma_size = RX_DMA_MAP_LEN; |
| 494 | rcv_desc->skb_size = MAX_RX_BUFFER_LENGTH; |
| 495 | break; |
| 496 | |
| 497 | case RCV_DESC_JUMBO: |
| 498 | rcv_desc->max_rx_desc_count = |
| 499 | adapter->max_jumbo_rx_desc_count; |
| 500 | rcv_desc->flags = RCV_DESC_JUMBO; |
| 501 | rcv_desc->dma_size = RX_JUMBO_DMA_MAP_LEN; |
| 502 | rcv_desc->skb_size = MAX_RX_JUMBO_BUFFER_LENGTH; |
| 503 | break; |
| 504 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 505 | case RCV_RING_LRO: |
| 506 | rcv_desc->max_rx_desc_count = |
| 507 | adapter->max_lro_rx_desc_count; |
| 508 | rcv_desc->flags = RCV_DESC_LRO; |
| 509 | rcv_desc->dma_size = RX_LRO_DMA_MAP_LEN; |
| 510 | rcv_desc->skb_size = MAX_RX_LRO_BUFFER_LENGTH; |
| 511 | break; |
| 512 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 513 | } |
| 514 | rcv_desc->rx_buf_arr = (struct netxen_rx_buffer *) |
| 515 | vmalloc(RCV_BUFFSIZE); |
| 516 | |
| 517 | if (rcv_desc->rx_buf_arr == NULL) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 518 | printk(KERN_ERR "%s: Could not allocate" |
| 519 | "rcv_desc->rx_buf_arr memory:%d\n", |
| 520 | netxen_nic_driver_name, |
| 521 | (int)RCV_BUFFSIZE); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 522 | err = -ENOMEM; |
| 523 | goto err_out_free_rx_buffer; |
| 524 | } |
| 525 | memset(rcv_desc->rx_buf_arr, 0, RCV_BUFFSIZE); |
| 526 | } |
| 527 | |
| 528 | } |
| 529 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 530 | netxen_initialize_adapter_sw(adapter); /* initialize the buffers in adapter */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 531 | |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 532 | /* Mezz cards have PCI function 0,2,3 enabled */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 533 | if ((adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) |
| 534 | && (pci_func_id >= 2)) |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 535 | adapter->portnum = pci_func_id - 2; |
| 536 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 537 | #ifdef CONFIG_IA64 |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 538 | if(adapter->portnum == 0) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 539 | netxen_pinit_from_rom(adapter, 0); |
| 540 | udelay(500); |
| 541 | netxen_load_firmware(adapter); |
| 542 | } |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 543 | #endif |
| 544 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 545 | init_timer(&adapter->watchdog_timer); |
| 546 | adapter->ahw.xg_linkup = 0; |
| 547 | adapter->watchdog_timer.function = &netxen_watchdog; |
| 548 | adapter->watchdog_timer.data = (unsigned long)adapter; |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 549 | INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 550 | adapter->ahw.pdev = pdev; |
| 551 | adapter->proc_cmd_buf_counter = 0; |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 552 | adapter->ahw.revision_id = pdev->revision; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 553 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 554 | /* make sure Window == 1 */ |
| 555 | netxen_nic_pci_change_crbwindow(adapter, 1); |
| 556 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 557 | netxen_nic_update_cmd_producer(adapter, 0); |
| 558 | netxen_nic_update_cmd_consumer(adapter, 0); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 559 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_CMD_ADDR_LO)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 560 | |
| 561 | if (netxen_is_flash_supported(adapter) == 0 && |
| 562 | netxen_get_flash_mac_addr(adapter, mac_addr) == 0) |
| 563 | valid_mac = 1; |
| 564 | else |
| 565 | valid_mac = 0; |
| 566 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 567 | if (valid_mac) { |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 568 | unsigned char *p = (unsigned char *)&mac_addr[adapter->portnum]; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 569 | netdev->dev_addr[0] = *(p + 5); |
| 570 | netdev->dev_addr[1] = *(p + 4); |
| 571 | netdev->dev_addr[2] = *(p + 3); |
| 572 | netdev->dev_addr[3] = *(p + 2); |
| 573 | netdev->dev_addr[4] = *(p + 1); |
| 574 | netdev->dev_addr[5] = *(p + 0); |
| 575 | |
| 576 | memcpy(netdev->perm_addr, netdev->dev_addr, |
| 577 | netdev->addr_len); |
| 578 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
| 579 | printk(KERN_ERR "%s: Bad MAC address " |
| 580 | "%02x:%02x:%02x:%02x:%02x:%02x.\n", |
| 581 | netxen_nic_driver_name, |
| 582 | netdev->dev_addr[0], |
| 583 | netdev->dev_addr[1], |
| 584 | netdev->dev_addr[2], |
| 585 | netdev->dev_addr[3], |
| 586 | netdev->dev_addr[4], |
| 587 | netdev->dev_addr[5]); |
| 588 | } else { |
| 589 | if (adapter->macaddr_set) |
| 590 | adapter->macaddr_set(adapter, |
| 591 | netdev->dev_addr); |
| 592 | } |
| 593 | } |
| 594 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 595 | if (adapter->portnum == 0) { |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 596 | err = netxen_initialize_adapter_offload(adapter); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 597 | if (err) |
| 598 | goto err_out_free_rx_buffer; |
| 599 | val = readl(NETXEN_CRB_NORMALIZE(adapter, |
| 600 | NETXEN_CAM_RAM(0x1fc))); |
| 601 | if (val == 0x55555555) { |
| 602 | /* This is the first boot after power up */ |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 603 | netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(0x4), &val); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 604 | if (!(val & 0x4)) { |
| 605 | val |= 0x4; |
| 606 | netxen_nic_write_w0(adapter, NETXEN_PCIE_REG(0x4), val); |
| 607 | netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(0x4), &val); |
| 608 | if (!(val & 0x4)) |
| 609 | printk(KERN_ERR "%s: failed to set MSI bit in PCI-e reg\n", |
| 610 | netxen_nic_driver_name); |
| 611 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 612 | val = readl(NETXEN_CRB_NORMALIZE(adapter, |
| 613 | NETXEN_ROMUSB_GLB_SW_RESET)); |
| 614 | printk(KERN_INFO"NetXen: read 0x%08x for reset reg.\n",val); |
| 615 | if (val != 0x80000f) { |
| 616 | /* clear the register for future unloads/loads */ |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 617 | writel(0, NETXEN_CRB_NORMALIZE(adapter, |
| 618 | NETXEN_CAM_RAM(0x1fc))); |
| 619 | printk(KERN_ERR "ERROR in NetXen HW init sequence.\n"); |
| 620 | err = -ENODEV; |
| 621 | goto err_out_free_dev; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 622 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 623 | } |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 624 | |
| 625 | /* clear the register for future unloads/loads */ |
| 626 | writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc))); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 627 | printk(KERN_INFO "State: 0x%0x\n", |
| 628 | readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE))); |
| 629 | |
| 630 | /* |
| 631 | * Tell the hardware our version number. |
| 632 | */ |
| 633 | i = (_NETXEN_NIC_LINUX_MAJOR << 16) |
| 634 | | ((_NETXEN_NIC_LINUX_MINOR << 8)) |
| 635 | | (_NETXEN_NIC_LINUX_SUBVERSION); |
| 636 | writel(i, NETXEN_CRB_NORMALIZE(adapter, CRB_DRIVER_VERSION)); |
| 637 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 638 | /* Unlock the HW, prompting the boot sequence */ |
| 639 | writel(1, |
| 640 | NETXEN_CRB_NORMALIZE(adapter, |
| 641 | NETXEN_ROMUSB_GLB_PEGTUNE_DONE)); |
| 642 | /* Handshake with the card before we register the devices. */ |
| 643 | netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 644 | } |
| 645 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 646 | /* |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 647 | * See if the firmware gave us a virtual-physical port mapping. |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 648 | */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 649 | i = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_V2P(adapter->portnum))); |
| 650 | if (i != 0x55555555) |
| 651 | physical_port[adapter->portnum] = i; |
| 652 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 653 | netif_carrier_off(netdev); |
| 654 | netif_stop_queue(netdev); |
| 655 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 656 | if ((err = register_netdev(netdev))) { |
| 657 | printk(KERN_ERR "%s: register_netdev failed port #%d" |
| 658 | " aborting\n", netxen_nic_driver_name, |
| 659 | adapter->portnum); |
| 660 | err = -EIO; |
| 661 | goto err_out_free_dev; |
| 662 | } |
| 663 | |
| 664 | pci_set_drvdata(pdev, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 665 | |
| 666 | switch (adapter->ahw.board_type) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 667 | case NETXEN_NIC_GBE: |
| 668 | printk(KERN_INFO "%s: QUAD GbE board initialized\n", |
| 669 | netxen_nic_driver_name); |
| 670 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 671 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 672 | case NETXEN_NIC_XGBE: |
| 673 | printk(KERN_INFO "%s: XGbE board initialized\n", |
| 674 | netxen_nic_driver_name); |
| 675 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | adapter->driver_mismatch = 0; |
| 679 | |
| 680 | return 0; |
| 681 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 682 | err_out_free_dev: |
| 683 | if (adapter->portnum == 0) |
| 684 | netxen_free_adapter_offload(adapter); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 685 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 686 | err_out_free_rx_buffer: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 687 | for (i = 0; i < MAX_RCV_CTX; ++i) { |
| 688 | recv_ctx = &adapter->recv_ctx[i]; |
| 689 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 690 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 691 | if (rcv_desc->rx_buf_arr != NULL) { |
| 692 | vfree(rcv_desc->rx_buf_arr); |
| 693 | rcv_desc->rx_buf_arr = NULL; |
| 694 | } |
| 695 | } |
| 696 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 697 | vfree(cmd_buf_arr); |
| 698 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 699 | err_out_free_adapter: |
| 700 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 701 | pci_disable_msi(pdev); |
| 702 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 703 | pci_set_drvdata(pdev, NULL); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 704 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 705 | if (db_ptr) |
| 706 | iounmap(db_ptr); |
| 707 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 708 | err_out_iounmap: |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 709 | if (mem_ptr0) |
| 710 | iounmap(mem_ptr0); |
| 711 | if (mem_ptr1) |
| 712 | iounmap(mem_ptr1); |
| 713 | if (mem_ptr2) |
| 714 | iounmap(mem_ptr2); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 715 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 716 | err_out_free_netdev: |
| 717 | free_netdev(netdev); |
| 718 | |
| 719 | err_out_free_res: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 720 | pci_release_regions(pdev); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 721 | |
| 722 | err_out_disable_pdev: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 723 | pci_disable_device(pdev); |
| 724 | return err; |
| 725 | } |
| 726 | |
| 727 | static void __devexit netxen_nic_remove(struct pci_dev *pdev) |
| 728 | { |
| 729 | struct netxen_adapter *adapter; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 730 | struct net_device *netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 731 | struct netxen_rx_buffer *buffer; |
| 732 | struct netxen_recv_context *recv_ctx; |
| 733 | struct netxen_rcv_desc_ctx *rcv_desc; |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 734 | int i, ctxid, ring; |
| 735 | static int init_firmware_done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 736 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 737 | adapter = pci_get_drvdata(pdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 738 | if (adapter == NULL) |
| 739 | return; |
| 740 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 741 | netdev = adapter->netdev; |
| 742 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 743 | unregister_netdev(netdev); |
| 744 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 745 | if (adapter->stop_port) |
| 746 | adapter->stop_port(adapter); |
| 747 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 748 | netxen_nic_disable_int(adapter); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 749 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 750 | if (adapter->irq) |
| 751 | free_irq(adapter->irq, adapter); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 752 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 753 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
| 754 | init_firmware_done++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 755 | netxen_free_hw_resources(adapter); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 756 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 757 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 758 | for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) { |
| 759 | recv_ctx = &adapter->recv_ctx[ctxid]; |
| 760 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 761 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 762 | for (i = 0; i < rcv_desc->max_rx_desc_count; ++i) { |
| 763 | buffer = &(rcv_desc->rx_buf_arr[i]); |
| 764 | if (buffer->state == NETXEN_BUFFER_FREE) |
| 765 | continue; |
| 766 | pci_unmap_single(pdev, buffer->dma, |
| 767 | rcv_desc->dma_size, |
| 768 | PCI_DMA_FROMDEVICE); |
| 769 | if (buffer->skb != NULL) |
| 770 | dev_kfree_skb_any(buffer->skb); |
| 771 | } |
| 772 | vfree(rcv_desc->rx_buf_arr); |
| 773 | } |
| 774 | } |
| 775 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 776 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 777 | pci_disable_msi(pdev); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 778 | |
| 779 | vfree(adapter->cmd_buf_arr); |
| 780 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 781 | pci_disable_device(pdev); |
| 782 | |
| 783 | if (adapter->portnum == 0) { |
| 784 | if (init_firmware_done) { |
| 785 | dma_watchdog_shutdown_request(adapter); |
| 786 | msleep(100); |
| 787 | i = 100; |
| 788 | while ((dma_watchdog_shutdown_poll_result(adapter) != 1) && i) { |
| 789 | printk(KERN_INFO "dma_watchdog_shutdown_poll still in progress\n"); |
| 790 | msleep(100); |
| 791 | i--; |
| 792 | } |
| 793 | |
| 794 | if (i == 0) { |
| 795 | printk(KERN_ERR "dma_watchdog_shutdown_request failed\n"); |
| 796 | return; |
| 797 | } |
| 798 | |
| 799 | /* clear the register for future unloads/loads */ |
| 800 | writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc))); |
| 801 | printk(KERN_INFO "State: 0x%0x\n", |
| 802 | readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE))); |
| 803 | |
| 804 | /* leave the hw in the same state as reboot */ |
| 805 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); |
| 806 | if (netxen_pinit_from_rom(adapter, 0)) |
| 807 | return; |
| 808 | msleep(1); |
| 809 | if (netxen_load_firmware(adapter)) |
| 810 | return; |
| 811 | netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
| 812 | } |
| 813 | |
| 814 | /* clear the register for future unloads/loads */ |
| 815 | writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc))); |
| 816 | printk(KERN_INFO "State: 0x%0x\n", |
| 817 | readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE))); |
| 818 | |
| 819 | dma_watchdog_shutdown_request(adapter); |
| 820 | msleep(100); |
| 821 | i = 100; |
| 822 | while ((dma_watchdog_shutdown_poll_result(adapter) != 1) && i) { |
| 823 | printk(KERN_INFO "dma_watchdog_shutdown_poll still in progress\n"); |
| 824 | msleep(100); |
| 825 | i--; |
| 826 | } |
| 827 | |
| 828 | if (i) { |
| 829 | netxen_free_adapter_offload(adapter); |
| 830 | } else { |
| 831 | printk(KERN_ERR "failed to dma shutdown\n"); |
| 832 | return; |
| 833 | } |
| 834 | |
| 835 | } |
| 836 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 837 | iounmap(adapter->ahw.db_base); |
| 838 | iounmap(adapter->ahw.pci_base0); |
| 839 | iounmap(adapter->ahw.pci_base1); |
| 840 | iounmap(adapter->ahw.pci_base2); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 841 | |
| 842 | pci_release_regions(pdev); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 843 | pci_set_drvdata(pdev, NULL); |
| 844 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 845 | free_netdev(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | /* |
| 849 | * Called when a network interface is made active |
| 850 | * @returns 0 on success, negative value on failure |
| 851 | */ |
| 852 | static int netxen_nic_open(struct net_device *netdev) |
| 853 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 854 | struct netxen_adapter *adapter = (struct netxen_adapter *)netdev->priv; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 855 | int err = 0; |
| 856 | int ctx, ring; |
| 857 | |
| 858 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) { |
| 859 | err = netxen_init_firmware(adapter); |
| 860 | if (err != 0) { |
| 861 | printk(KERN_ERR "Failed to init firmware\n"); |
| 862 | return -EIO; |
| 863 | } |
| 864 | netxen_nic_flash_print(adapter); |
| 865 | |
| 866 | /* setup all the resources for the Phantom... */ |
| 867 | /* this include the descriptors for rcv, tx, and status */ |
| 868 | netxen_nic_clear_stats(adapter); |
| 869 | err = netxen_nic_hw_resources(adapter); |
| 870 | if (err) { |
| 871 | printk(KERN_ERR "Error in setting hw resources:%d\n", |
| 872 | err); |
| 873 | return err; |
| 874 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 875 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 876 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 877 | netxen_post_rx_buffers(adapter, ctx, ring); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 878 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 879 | adapter->irq = adapter->ahw.pdev->irq; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 880 | err = request_irq(adapter->ahw.pdev->irq, netxen_intr, |
Andrew Morton | 1c8e039 | 2007-05-10 22:53:00 -0700 | [diff] [blame] | 881 | IRQF_SHARED|IRQF_SAMPLE_RANDOM, netdev->name, |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 882 | adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 883 | if (err) { |
| 884 | printk(KERN_ERR "request_irq failed with: %d\n", err); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 885 | netxen_free_hw_resources(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 886 | return err; |
| 887 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 888 | |
| 889 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; |
| 890 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 891 | if (!adapter->driver_mismatch) |
| 892 | mod_timer(&adapter->watchdog_timer, jiffies); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 893 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 894 | netxen_nic_enable_int(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 895 | |
| 896 | /* Done here again so that even if phantom sw overwrote it, |
| 897 | * we set it */ |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 898 | if (adapter->macaddr_set) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 899 | adapter->macaddr_set(adapter, netdev->dev_addr); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 900 | if (adapter->init_port |
| 901 | && adapter->init_port(adapter, adapter->portnum) != 0) { |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 902 | del_timer_sync(&adapter->watchdog_timer); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 903 | printk(KERN_ERR "%s: Failed to initialize port %d\n", |
| 904 | netxen_nic_driver_name, adapter->portnum); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 905 | return -EIO; |
| 906 | } |
| 907 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 908 | netxen_nic_set_link_parameters(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 909 | |
| 910 | netxen_nic_set_multi(netdev); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 911 | if (adapter->set_mtu) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 912 | adapter->set_mtu(adapter, netdev->mtu); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 913 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 914 | if (!adapter->driver_mismatch) |
| 915 | netif_start_queue(netdev); |
| 916 | |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | /* |
| 921 | * netxen_nic_close - Disables a network interface entry point |
| 922 | */ |
| 923 | static int netxen_nic_close(struct net_device *netdev) |
| 924 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 925 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 926 | int i, j; |
| 927 | struct netxen_cmd_buffer *cmd_buff; |
| 928 | struct netxen_skb_frag *buffrag; |
| 929 | |
| 930 | netif_carrier_off(netdev); |
| 931 | netif_stop_queue(netdev); |
| 932 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 933 | cmd_buff = adapter->cmd_buf_arr; |
| 934 | for (i = 0; i < adapter->max_tx_desc_count; i++) { |
| 935 | buffrag = cmd_buff->frag_array; |
| 936 | if (buffrag->dma) { |
| 937 | pci_unmap_single(adapter->pdev, buffrag->dma, |
| 938 | buffrag->length, PCI_DMA_TODEVICE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 939 | buffrag->dma = 0ULL; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 940 | } |
| 941 | for (j = 0; j < cmd_buff->frag_count; j++) { |
| 942 | buffrag++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 943 | if (buffrag->dma) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 944 | pci_unmap_page(adapter->pdev, buffrag->dma, |
| 945 | buffrag->length, |
| 946 | PCI_DMA_TODEVICE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 947 | buffrag->dma = 0ULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 948 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 949 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 950 | /* Free the skb we received in netxen_nic_xmit_frame */ |
| 951 | if (cmd_buff->skb) { |
| 952 | dev_kfree_skb_any(cmd_buff->skb); |
| 953 | cmd_buff->skb = NULL; |
| 954 | } |
| 955 | cmd_buff++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 956 | } |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 957 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
| 958 | FLUSH_SCHEDULED_WORK(); |
| 959 | del_timer_sync(&adapter->watchdog_timer); |
| 960 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 961 | |
| 962 | return 0; |
| 963 | } |
| 964 | |
| 965 | static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 966 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 967 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 968 | struct netxen_hardware_context *hw = &adapter->ahw; |
| 969 | unsigned int first_seg_len = skb->len - skb->data_len; |
| 970 | struct netxen_skb_frag *buffrag; |
| 971 | unsigned int i; |
| 972 | |
| 973 | u32 producer = 0; |
| 974 | u32 saved_producer = 0; |
| 975 | struct cmd_desc_type0 *hwdesc; |
| 976 | int k; |
| 977 | struct netxen_cmd_buffer *pbuf = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 978 | static int dropped_packet = 0; |
| 979 | int frag_count; |
| 980 | u32 local_producer = 0; |
| 981 | u32 max_tx_desc_count = 0; |
| 982 | u32 last_cmd_consumer = 0; |
| 983 | int no_of_desc; |
| 984 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 985 | adapter->stats.xmitcalled++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 986 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
| 987 | |
| 988 | if (unlikely(skb->len <= 0)) { |
| 989 | dev_kfree_skb_any(skb); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 990 | adapter->stats.badskblen++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 991 | return NETDEV_TX_OK; |
| 992 | } |
| 993 | |
| 994 | if (frag_count > MAX_BUFFERS_PER_CMD) { |
| 995 | printk("%s: %s netxen_nic_xmit_frame: frag_count (%d)" |
| 996 | "too large, can handle only %d frags\n", |
| 997 | netxen_nic_driver_name, netdev->name, |
| 998 | frag_count, MAX_BUFFERS_PER_CMD); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 999 | adapter->stats.txdropped++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1000 | if ((++dropped_packet & 0xff) == 0xff) |
| 1001 | printk("%s: %s droppped packets = %d\n", |
| 1002 | netxen_nic_driver_name, netdev->name, |
| 1003 | dropped_packet); |
| 1004 | |
| 1005 | return NETDEV_TX_OK; |
| 1006 | } |
| 1007 | |
| 1008 | /* |
| 1009 | * Everything is set up. Now, we just need to transmit it out. |
| 1010 | * Note that we have to copy the contents of buffer over to |
| 1011 | * right place. Later on, this can be optimized out by de-coupling the |
| 1012 | * producer index from the buffer index. |
| 1013 | */ |
| 1014 | retry_getting_window: |
| 1015 | spin_lock_bh(&adapter->tx_lock); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1016 | if (adapter->total_threads >= MAX_XMIT_PRODUCERS) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1017 | spin_unlock_bh(&adapter->tx_lock); |
| 1018 | /* |
| 1019 | * Yield CPU |
| 1020 | */ |
| 1021 | if (!in_atomic()) |
| 1022 | schedule(); |
| 1023 | else { |
| 1024 | for (i = 0; i < 20; i++) |
| 1025 | cpu_relax(); /*This a nop instr on i386 */ |
| 1026 | } |
| 1027 | goto retry_getting_window; |
| 1028 | } |
| 1029 | local_producer = adapter->cmd_producer; |
| 1030 | /* There 4 fragments per descriptor */ |
| 1031 | no_of_desc = (frag_count + 3) >> 2; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1032 | if (netdev->features & NETIF_F_TSO) { |
| 1033 | if (skb_shinfo(skb)->gso_size > 0) { |
| 1034 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1035 | no_of_desc++; |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 1036 | if ((ip_hdrlen(skb) + tcp_hdrlen(skb) + |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 1037 | sizeof(struct ethhdr)) > |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1038 | (sizeof(struct cmd_desc_type0) - 2)) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1039 | no_of_desc++; |
| 1040 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | k = adapter->cmd_producer; |
| 1044 | max_tx_desc_count = adapter->max_tx_desc_count; |
| 1045 | last_cmd_consumer = adapter->last_cmd_consumer; |
| 1046 | if ((k + no_of_desc) >= |
| 1047 | ((last_cmd_consumer <= k) ? last_cmd_consumer + max_tx_desc_count : |
| 1048 | last_cmd_consumer)) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1049 | netif_stop_queue(netdev); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1050 | adapter->flags |= NETXEN_NETDEV_STATUS; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1051 | spin_unlock_bh(&adapter->tx_lock); |
| 1052 | return NETDEV_TX_BUSY; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1053 | } |
| 1054 | k = get_index_range(k, max_tx_desc_count, no_of_desc); |
| 1055 | adapter->cmd_producer = k; |
| 1056 | adapter->total_threads++; |
| 1057 | adapter->num_threads++; |
| 1058 | |
| 1059 | spin_unlock_bh(&adapter->tx_lock); |
| 1060 | /* Copy the descriptors into the hardware */ |
| 1061 | producer = local_producer; |
| 1062 | saved_producer = producer; |
| 1063 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1064 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
| 1065 | /* Take skb->data itself */ |
| 1066 | pbuf = &adapter->cmd_buf_arr[producer]; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1067 | if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) { |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1068 | pbuf->mss = skb_shinfo(skb)->gso_size; |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1069 | hwdesc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1070 | } else { |
| 1071 | pbuf->mss = 0; |
| 1072 | hwdesc->mss = 0; |
| 1073 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1074 | pbuf->total_length = skb->len; |
| 1075 | pbuf->skb = skb; |
| 1076 | pbuf->cmd = TX_ETHER_PKT; |
| 1077 | pbuf->frag_count = frag_count; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1078 | pbuf->port = adapter->portnum; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1079 | buffrag = &pbuf->frag_array[0]; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1080 | 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] | 1081 | PCI_DMA_TODEVICE); |
| 1082 | buffrag->length = first_seg_len; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1083 | netxen_set_cmd_desc_totallength(hwdesc, skb->len); |
| 1084 | netxen_set_cmd_desc_num_of_buff(hwdesc, frag_count); |
| 1085 | netxen_set_cmd_desc_opcode(hwdesc, TX_ETHER_PKT); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1086 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1087 | netxen_set_cmd_desc_port(hwdesc, adapter->portnum); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1088 | netxen_set_cmd_desc_ctxid(hwdesc, adapter->portnum); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1089 | hwdesc->buffer1_length = cpu_to_le16(first_seg_len); |
| 1090 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); |
| 1091 | |
| 1092 | for (i = 1, k = 1; i < frag_count; i++, k++) { |
| 1093 | struct skb_frag_struct *frag; |
| 1094 | int len, temp_len; |
| 1095 | unsigned long offset; |
| 1096 | dma_addr_t temp_dma; |
| 1097 | |
| 1098 | /* move to next desc. if there is a need */ |
| 1099 | if ((i & 0x3) == 0) { |
| 1100 | k = 0; |
| 1101 | producer = get_next_index(producer, |
| 1102 | adapter->max_tx_desc_count); |
| 1103 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1104 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
| 1105 | } |
| 1106 | frag = &skb_shinfo(skb)->frags[i - 1]; |
| 1107 | len = frag->size; |
| 1108 | offset = frag->page_offset; |
| 1109 | |
| 1110 | temp_len = len; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1111 | temp_dma = pci_map_page(adapter->pdev, frag->page, offset, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1112 | len, PCI_DMA_TODEVICE); |
| 1113 | |
| 1114 | buffrag++; |
| 1115 | buffrag->dma = temp_dma; |
| 1116 | buffrag->length = temp_len; |
| 1117 | |
| 1118 | DPRINTK(INFO, "for loop. i=%d k=%d\n", i, k); |
| 1119 | switch (k) { |
| 1120 | case 0: |
| 1121 | hwdesc->buffer1_length = cpu_to_le16(temp_len); |
| 1122 | hwdesc->addr_buffer1 = cpu_to_le64(temp_dma); |
| 1123 | break; |
| 1124 | case 1: |
| 1125 | hwdesc->buffer2_length = cpu_to_le16(temp_len); |
| 1126 | hwdesc->addr_buffer2 = cpu_to_le64(temp_dma); |
| 1127 | break; |
| 1128 | case 2: |
| 1129 | hwdesc->buffer3_length = cpu_to_le16(temp_len); |
| 1130 | hwdesc->addr_buffer3 = cpu_to_le64(temp_dma); |
| 1131 | break; |
| 1132 | case 3: |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1133 | hwdesc->buffer4_length = cpu_to_le16(temp_len); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1134 | hwdesc->addr_buffer4 = cpu_to_le64(temp_dma); |
| 1135 | break; |
| 1136 | } |
| 1137 | frag++; |
| 1138 | } |
| 1139 | producer = get_next_index(producer, adapter->max_tx_desc_count); |
| 1140 | |
| 1141 | /* might change opcode to TX_TCP_LSO */ |
| 1142 | netxen_tso_check(adapter, &hw->cmd_desc_head[saved_producer], skb); |
| 1143 | |
| 1144 | /* For LSO, we need to copy the MAC/IP/TCP headers into |
| 1145 | * the descriptor ring |
| 1146 | */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1147 | if (netxen_get_cmd_desc_opcode(&hw->cmd_desc_head[saved_producer]) |
| 1148 | == TX_TCP_LSO) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1149 | int hdr_len, first_hdr_len, more_hdr; |
| 1150 | hdr_len = hw->cmd_desc_head[saved_producer].total_hdr_length; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1151 | if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) { |
| 1152 | first_hdr_len = sizeof(struct cmd_desc_type0) - 2; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1153 | more_hdr = 1; |
| 1154 | } else { |
| 1155 | first_hdr_len = hdr_len; |
| 1156 | more_hdr = 0; |
| 1157 | } |
| 1158 | /* copy the MAC/IP/TCP headers to the cmd descriptor list */ |
| 1159 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1160 | |
| 1161 | /* copy the first 64 bytes */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1162 | memcpy(((void *)hwdesc) + 2, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1163 | (void *)(skb->data), first_hdr_len); |
| 1164 | producer = get_next_index(producer, max_tx_desc_count); |
| 1165 | |
| 1166 | if (more_hdr) { |
| 1167 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1168 | /* copy the next 64 bytes - should be enough except |
| 1169 | * for pathological case |
| 1170 | */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1171 | skb_copy_from_linear_data_offset(skb, first_hdr_len, |
| 1172 | hwdesc, |
| 1173 | (hdr_len - |
| 1174 | first_hdr_len)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1175 | producer = get_next_index(producer, max_tx_desc_count); |
| 1176 | } |
| 1177 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1178 | |
| 1179 | i = netxen_get_cmd_desc_totallength(&hw->cmd_desc_head[saved_producer]); |
| 1180 | |
| 1181 | hw->cmd_desc_head[saved_producer].flags_opcode = |
| 1182 | cpu_to_le16(hw->cmd_desc_head[saved_producer].flags_opcode); |
| 1183 | hw->cmd_desc_head[saved_producer].num_of_buffers_total_length = |
| 1184 | cpu_to_le32(hw->cmd_desc_head[saved_producer]. |
| 1185 | num_of_buffers_total_length); |
| 1186 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1187 | spin_lock_bh(&adapter->tx_lock); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1188 | adapter->stats.txbytes += i; |
| 1189 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1190 | /* Code to update the adapter considering how many producer threads |
| 1191 | are currently working */ |
| 1192 | if ((--adapter->num_threads) == 0) { |
| 1193 | /* This is the last thread */ |
| 1194 | u32 crb_producer = adapter->cmd_producer; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1195 | netxen_nic_update_cmd_producer(adapter, crb_producer); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1196 | wmb(); |
| 1197 | adapter->total_threads = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1198 | } |
| 1199 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1200 | adapter->stats.xmitfinished++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1201 | spin_unlock_bh(&adapter->tx_lock); |
| 1202 | |
| 1203 | netdev->trans_start = jiffies; |
| 1204 | |
| 1205 | DPRINTK(INFO, "wrote CMD producer %x to phantom\n", producer); |
| 1206 | |
| 1207 | DPRINTK(INFO, "Done. Send\n"); |
| 1208 | return NETDEV_TX_OK; |
| 1209 | } |
| 1210 | |
| 1211 | static void netxen_watchdog(unsigned long v) |
| 1212 | { |
| 1213 | struct netxen_adapter *adapter = (struct netxen_adapter *)v; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1214 | |
| 1215 | SCHEDULE_WORK(&adapter->watchdog_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | static void netxen_tx_timeout(struct net_device *netdev) |
| 1219 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1220 | struct netxen_adapter *adapter = (struct netxen_adapter *) |
| 1221 | netdev_priv(netdev); |
| 1222 | SCHEDULE_WORK(&adapter->tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1223 | } |
| 1224 | |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 1225 | static void netxen_tx_timeout_task(struct work_struct *work) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1226 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1227 | struct netxen_adapter *adapter = |
| 1228 | container_of(work, struct netxen_adapter, tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1229 | unsigned long flags; |
| 1230 | |
| 1231 | printk(KERN_ERR "%s %s: transmit timeout, resetting.\n", |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1232 | netxen_nic_driver_name, adapter->netdev->name); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1233 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1234 | spin_lock_irqsave(&adapter->lock, flags); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1235 | netxen_nic_close(adapter->netdev); |
| 1236 | netxen_nic_open(adapter->netdev); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1237 | spin_unlock_irqrestore(&adapter->lock, flags); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1238 | adapter->netdev->trans_start = jiffies; |
| 1239 | netif_wake_queue(adapter->netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | static int |
| 1243 | netxen_handle_int(struct netxen_adapter *adapter, struct net_device *netdev) |
| 1244 | { |
| 1245 | u32 ret = 0; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 1246 | u32 our_int = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1247 | |
| 1248 | DPRINTK(INFO, "Entered handle ISR\n"); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1249 | adapter->stats.ints++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1250 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1251 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1252 | our_int = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR)); |
| 1253 | /* not our interrupt */ |
| 1254 | if ((our_int & (0x80 << adapter->portnum)) == 0) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1255 | return ret; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 1256 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1257 | |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 1258 | netxen_nic_disable_int(adapter); |
| 1259 | |
| 1260 | if (adapter->intr_scheme == INTR_SCHEME_PERPORT) { |
| 1261 | /* claim interrupt */ |
| 1262 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { |
| 1263 | writel(our_int & ~((u32)(0x80 << adapter->portnum)), |
| 1264 | NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR)); |
| 1265 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1266 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1267 | |
| 1268 | if (netxen_nic_rx_has_work(adapter) || netxen_nic_tx_has_work(adapter)) { |
| 1269 | if (netif_rx_schedule_prep(netdev)) { |
| 1270 | /* |
| 1271 | * Interrupts are already disabled. |
| 1272 | */ |
| 1273 | __netif_rx_schedule(netdev); |
| 1274 | } else { |
| 1275 | static unsigned int intcount = 0; |
| 1276 | if ((++intcount & 0xfff) == 0xfff) |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 1277 | DPRINTK(KERN_ERR |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1278 | "%s: %s interrupt %d while in poll\n", |
| 1279 | netxen_nic_driver_name, netdev->name, |
| 1280 | intcount); |
| 1281 | } |
| 1282 | ret = 1; |
| 1283 | } |
| 1284 | |
| 1285 | if (ret == 0) { |
| 1286 | netxen_nic_enable_int(adapter); |
| 1287 | } |
| 1288 | |
| 1289 | return ret; |
| 1290 | } |
| 1291 | |
| 1292 | /* |
| 1293 | * netxen_intr - Interrupt Handler |
| 1294 | * @irq: interrupt number |
| 1295 | * data points to adapter stucture (which may be handling more than 1 port |
| 1296 | */ |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1297 | irqreturn_t netxen_intr(int irq, void *data) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1298 | { |
| 1299 | struct netxen_adapter *adapter; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1300 | struct net_device *netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1301 | |
| 1302 | if (unlikely(!irq)) { |
| 1303 | return IRQ_NONE; /* Not our interrupt */ |
| 1304 | } |
| 1305 | |
| 1306 | adapter = (struct netxen_adapter *)data; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1307 | netdev = adapter->netdev; |
| 1308 | /* process our status queue (for all 4 ports) */ |
| 1309 | if (netif_running(netdev)) |
| 1310 | netxen_handle_int(adapter, netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1311 | |
| 1312 | return IRQ_HANDLED; |
| 1313 | } |
| 1314 | |
| 1315 | static int netxen_nic_poll(struct net_device *netdev, int *budget) |
| 1316 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1317 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1318 | int work_to_do = min(*budget, netdev->quota); |
| 1319 | int done = 1; |
| 1320 | int ctx; |
| 1321 | int this_work_done; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1322 | int work_done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1323 | |
| 1324 | DPRINTK(INFO, "polling for %d descriptors\n", *budget); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1325 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1326 | work_done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1327 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
| 1328 | /* |
| 1329 | * Fairness issue. This will give undue weight to the |
| 1330 | * receive context 0. |
| 1331 | */ |
| 1332 | |
| 1333 | /* |
| 1334 | * To avoid starvation, we give each of our receivers, |
| 1335 | * a fraction of the quota. Sometimes, it might happen that we |
| 1336 | * have enough quota to process every packet, but since all the |
| 1337 | * packets are on one context, it gets only half of the quota, |
| 1338 | * and ends up not processing it. |
| 1339 | */ |
| 1340 | this_work_done = netxen_process_rcv_ring(adapter, ctx, |
| 1341 | work_to_do / |
| 1342 | MAX_RCV_CTX); |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1343 | work_done += this_work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1344 | } |
| 1345 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1346 | netdev->quota -= work_done; |
| 1347 | *budget -= work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1348 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1349 | 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] | 1350 | done = 0; |
| 1351 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1352 | if (netxen_process_cmd_ring((unsigned long)adapter) == 0) |
| 1353 | done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1354 | |
| 1355 | DPRINTK(INFO, "new work_done: %d work_to_do: %d\n", |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1356 | work_done, work_to_do); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1357 | if (done) { |
| 1358 | netif_rx_complete(netdev); |
| 1359 | netxen_nic_enable_int(adapter); |
| 1360 | } |
| 1361 | |
Amit S. Kale | edf9016 | 2006-11-29 08:58:11 -0800 | [diff] [blame] | 1362 | return !done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1366 | static void netxen_nic_poll_controller(struct net_device *netdev) |
| 1367 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1368 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1369 | disable_irq(adapter->irq); |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1370 | netxen_intr(adapter->irq, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1371 | enable_irq(adapter->irq); |
| 1372 | } |
| 1373 | #endif |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1374 | |
| 1375 | static struct pci_driver netxen_driver = { |
| 1376 | .name = netxen_nic_driver_name, |
| 1377 | .id_table = netxen_pci_tbl, |
| 1378 | .probe = netxen_nic_probe, |
| 1379 | .remove = __devexit_p(netxen_nic_remove) |
| 1380 | }; |
| 1381 | |
| 1382 | /* Driver Registration on NetXen card */ |
| 1383 | |
| 1384 | static int __init netxen_init_module(void) |
| 1385 | { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1386 | if ((netxen_workq = create_singlethread_workqueue("netxen")) == 0) |
| 1387 | return -ENOMEM; |
| 1388 | |
Amit S. Kale | 184231b | 2007-01-22 06:52:53 -0800 | [diff] [blame] | 1389 | return pci_register_driver(&netxen_driver); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | module_init(netxen_init_module); |
| 1393 | |
| 1394 | static void __exit netxen_exit_module(void) |
| 1395 | { |
| 1396 | /* |
| 1397 | * Wait for some time to allow the dma to drain, if any. |
| 1398 | */ |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1399 | msleep(100); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1400 | pci_unregister_driver(&netxen_driver); |
Amit S. Kale | 9de0661 | 2007-02-21 06:37:06 -0800 | [diff] [blame] | 1401 | destroy_workqueue(netxen_workq); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | module_exit(netxen_exit_module); |