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 *); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame^] | 71 | static int netxen_nic_poll(struct napi_struct *napi, int budget); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 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 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame^] | 405 | netif_napi_add(netdev, &adapter->napi, |
| 406 | netxen_nic_poll, NETXEN_NETDEV_WEIGHT); |
| 407 | |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 408 | /* this will be read from FW later */ |
| 409 | adapter->intr_scheme = -1; |
| 410 | |
| 411 | /* This will be reset for mezz cards */ |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 412 | adapter->portnum = pci_func_id; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 413 | adapter->status &= ~NETXEN_NETDEV_STATUS; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 414 | |
| 415 | netdev->open = netxen_nic_open; |
| 416 | netdev->stop = netxen_nic_close; |
| 417 | netdev->hard_start_xmit = netxen_nic_xmit_frame; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 418 | netdev->get_stats = netxen_nic_get_stats; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 419 | netdev->set_multicast_list = netxen_nic_set_multi; |
| 420 | netdev->set_mac_address = netxen_nic_set_mac; |
| 421 | netdev->change_mtu = netxen_nic_change_mtu; |
| 422 | netdev->tx_timeout = netxen_tx_timeout; |
| 423 | netdev->watchdog_timeo = HZ; |
| 424 | |
| 425 | netxen_nic_change_mtu(netdev, netdev->mtu); |
| 426 | |
| 427 | SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 428 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 429 | netdev->poll_controller = netxen_nic_poll_controller; |
| 430 | #endif |
| 431 | /* ScatterGather support */ |
| 432 | netdev->features = NETIF_F_SG; |
| 433 | netdev->features |= NETIF_F_IP_CSUM; |
| 434 | netdev->features |= NETIF_F_TSO; |
| 435 | |
| 436 | if (pci_using_dac) |
| 437 | netdev->features |= NETIF_F_HIGHDMA; |
| 438 | |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 439 | if (pci_enable_msi(pdev)) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 440 | adapter->flags &= ~NETXEN_NIC_MSI_ENABLED; |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 441 | else |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 442 | adapter->flags |= NETXEN_NIC_MSI_ENABLED; |
| 443 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 444 | netdev->irq = pdev->irq; |
| 445 | INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task); |
| 446 | |
| 447 | /* |
| 448 | * Set the CRB window to invalid. If any register in window 0 is |
| 449 | * accessed it should set the window to 0 and then reset it to 1. |
| 450 | */ |
| 451 | adapter->curr_window = 255; |
| 452 | |
| 453 | /* initialize the adapter */ |
| 454 | netxen_initialize_adapter_hw(adapter); |
| 455 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 456 | /* |
| 457 | * Adapter in our case is quad port so initialize it before |
| 458 | * initializing the ports |
| 459 | */ |
| 460 | |
| 461 | netxen_initialize_adapter_ops(adapter); |
| 462 | |
| 463 | adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS_HOST; |
| 464 | if ((adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB35_4G) || |
| 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->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
| 751 | init_firmware_done++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 752 | netxen_free_hw_resources(adapter); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 753 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 754 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 755 | for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) { |
| 756 | recv_ctx = &adapter->recv_ctx[ctxid]; |
| 757 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 758 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 759 | for (i = 0; i < rcv_desc->max_rx_desc_count; ++i) { |
| 760 | buffer = &(rcv_desc->rx_buf_arr[i]); |
| 761 | if (buffer->state == NETXEN_BUFFER_FREE) |
| 762 | continue; |
| 763 | pci_unmap_single(pdev, buffer->dma, |
| 764 | rcv_desc->dma_size, |
| 765 | PCI_DMA_FROMDEVICE); |
| 766 | if (buffer->skb != NULL) |
| 767 | dev_kfree_skb_any(buffer->skb); |
| 768 | } |
| 769 | vfree(rcv_desc->rx_buf_arr); |
| 770 | } |
| 771 | } |
| 772 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 773 | vfree(adapter->cmd_buf_arr); |
| 774 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 775 | if (adapter->portnum == 0) { |
| 776 | if (init_firmware_done) { |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 777 | i = 100; |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 778 | do { |
| 779 | if (dma_watchdog_shutdown_request(adapter) == 1) |
| 780 | break; |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 781 | msleep(100); |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 782 | if (dma_watchdog_shutdown_poll_result(adapter) == 1) |
| 783 | break; |
| 784 | } while (--i); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 785 | |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 786 | if (i == 0) |
| 787 | printk(KERN_ERR "%s: dma_watchdog_shutdown failed\n", |
| 788 | netdev->name); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 789 | |
| 790 | /* clear the register for future unloads/loads */ |
| 791 | writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc))); |
| 792 | printk(KERN_INFO "State: 0x%0x\n", |
| 793 | readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE))); |
| 794 | |
| 795 | /* leave the hw in the same state as reboot */ |
| 796 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 797 | netxen_pinit_from_rom(adapter, 0); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 798 | msleep(1); |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 799 | netxen_load_firmware(adapter); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 800 | netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
| 801 | } |
| 802 | |
| 803 | /* clear the register for future unloads/loads */ |
| 804 | writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc))); |
| 805 | printk(KERN_INFO "State: 0x%0x\n", |
| 806 | readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE))); |
| 807 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 808 | i = 100; |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 809 | do { |
| 810 | if (dma_watchdog_shutdown_request(adapter) == 1) |
| 811 | break; |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 812 | msleep(100); |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 813 | if (dma_watchdog_shutdown_poll_result(adapter) == 1) |
| 814 | break; |
| 815 | } while (--i); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 816 | |
| 817 | if (i) { |
| 818 | netxen_free_adapter_offload(adapter); |
| 819 | } else { |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 820 | printk(KERN_ERR "%s: dma_watchdog_shutdown failed\n", |
| 821 | netdev->name); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 822 | } |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 823 | } |
| 824 | |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 825 | if (adapter->irq) |
| 826 | free_irq(adapter->irq, adapter); |
| 827 | |
| 828 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 829 | pci_disable_msi(pdev); |
| 830 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 831 | iounmap(adapter->ahw.db_base); |
| 832 | iounmap(adapter->ahw.pci_base0); |
| 833 | iounmap(adapter->ahw.pci_base1); |
| 834 | iounmap(adapter->ahw.pci_base2); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 835 | |
| 836 | pci_release_regions(pdev); |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 837 | pci_disable_device(pdev); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 838 | pci_set_drvdata(pdev, NULL); |
| 839 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 840 | free_netdev(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | /* |
| 844 | * Called when a network interface is made active |
| 845 | * @returns 0 on success, negative value on failure |
| 846 | */ |
| 847 | static int netxen_nic_open(struct net_device *netdev) |
| 848 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 849 | struct netxen_adapter *adapter = (struct netxen_adapter *)netdev->priv; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 850 | int err = 0; |
| 851 | int ctx, ring; |
| 852 | |
| 853 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) { |
| 854 | err = netxen_init_firmware(adapter); |
| 855 | if (err != 0) { |
| 856 | printk(KERN_ERR "Failed to init firmware\n"); |
| 857 | return -EIO; |
| 858 | } |
| 859 | netxen_nic_flash_print(adapter); |
| 860 | |
| 861 | /* setup all the resources for the Phantom... */ |
| 862 | /* this include the descriptors for rcv, tx, and status */ |
| 863 | netxen_nic_clear_stats(adapter); |
| 864 | err = netxen_nic_hw_resources(adapter); |
| 865 | if (err) { |
| 866 | printk(KERN_ERR "Error in setting hw resources:%d\n", |
| 867 | err); |
| 868 | return err; |
| 869 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 870 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 871 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 872 | netxen_post_rx_buffers(adapter, ctx, ring); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 873 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 874 | adapter->irq = adapter->ahw.pdev->irq; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 875 | err = request_irq(adapter->ahw.pdev->irq, netxen_intr, |
Andrew Morton | 1c8e039 | 2007-05-10 22:53:00 -0700 | [diff] [blame] | 876 | IRQF_SHARED|IRQF_SAMPLE_RANDOM, netdev->name, |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 877 | adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 878 | if (err) { |
| 879 | printk(KERN_ERR "request_irq failed with: %d\n", err); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 880 | netxen_free_hw_resources(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 881 | return err; |
| 882 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 883 | |
| 884 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; |
| 885 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 886 | if (!adapter->driver_mismatch) |
| 887 | mod_timer(&adapter->watchdog_timer, jiffies); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 888 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame^] | 889 | napi_enable(&adapter->napi); |
| 890 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 891 | netxen_nic_enable_int(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 892 | |
| 893 | /* Done here again so that even if phantom sw overwrote it, |
| 894 | * we set it */ |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 895 | if (adapter->init_port |
| 896 | && adapter->init_port(adapter, adapter->portnum) != 0) { |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 897 | del_timer_sync(&adapter->watchdog_timer); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 898 | printk(KERN_ERR "%s: Failed to initialize port %d\n", |
| 899 | netxen_nic_driver_name, adapter->portnum); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame^] | 900 | napi_disable(&adapter->napi); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 901 | return -EIO; |
| 902 | } |
dhananjay@netxen.com | 7eec517 | 2007-07-25 20:13:11 +0530 | [diff] [blame] | 903 | if (adapter->macaddr_set) |
| 904 | adapter->macaddr_set(adapter, netdev->dev_addr); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 905 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 906 | netxen_nic_set_link_parameters(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 907 | |
| 908 | netxen_nic_set_multi(netdev); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 909 | if (adapter->set_mtu) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 910 | adapter->set_mtu(adapter, netdev->mtu); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 911 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 912 | if (!adapter->driver_mismatch) |
| 913 | netif_start_queue(netdev); |
| 914 | |
| 915 | return 0; |
| 916 | } |
| 917 | |
| 918 | /* |
| 919 | * netxen_nic_close - Disables a network interface entry point |
| 920 | */ |
| 921 | static int netxen_nic_close(struct net_device *netdev) |
| 922 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 923 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 924 | int i, j; |
| 925 | struct netxen_cmd_buffer *cmd_buff; |
| 926 | struct netxen_skb_frag *buffrag; |
| 927 | |
| 928 | netif_carrier_off(netdev); |
| 929 | netif_stop_queue(netdev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame^] | 930 | napi_disable(&adapter->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 931 | |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 932 | netxen_nic_disable_int(adapter); |
| 933 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 934 | cmd_buff = adapter->cmd_buf_arr; |
| 935 | for (i = 0; i < adapter->max_tx_desc_count; i++) { |
| 936 | buffrag = cmd_buff->frag_array; |
| 937 | if (buffrag->dma) { |
| 938 | pci_unmap_single(adapter->pdev, buffrag->dma, |
| 939 | buffrag->length, PCI_DMA_TODEVICE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 940 | buffrag->dma = 0ULL; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 941 | } |
| 942 | for (j = 0; j < cmd_buff->frag_count; j++) { |
| 943 | buffrag++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 944 | if (buffrag->dma) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 945 | pci_unmap_page(adapter->pdev, buffrag->dma, |
| 946 | buffrag->length, |
| 947 | PCI_DMA_TODEVICE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 948 | buffrag->dma = 0ULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 949 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 950 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 951 | /* Free the skb we received in netxen_nic_xmit_frame */ |
| 952 | if (cmd_buff->skb) { |
| 953 | dev_kfree_skb_any(cmd_buff->skb); |
| 954 | cmd_buff->skb = NULL; |
| 955 | } |
| 956 | cmd_buff++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 957 | } |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 958 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
| 959 | FLUSH_SCHEDULED_WORK(); |
| 960 | del_timer_sync(&adapter->watchdog_timer); |
| 961 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 962 | |
| 963 | return 0; |
| 964 | } |
| 965 | |
| 966 | static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 967 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 968 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 969 | struct netxen_hardware_context *hw = &adapter->ahw; |
| 970 | unsigned int first_seg_len = skb->len - skb->data_len; |
| 971 | struct netxen_skb_frag *buffrag; |
| 972 | unsigned int i; |
| 973 | |
| 974 | u32 producer = 0; |
| 975 | u32 saved_producer = 0; |
| 976 | struct cmd_desc_type0 *hwdesc; |
| 977 | int k; |
| 978 | struct netxen_cmd_buffer *pbuf = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 979 | static int dropped_packet = 0; |
| 980 | int frag_count; |
| 981 | u32 local_producer = 0; |
| 982 | u32 max_tx_desc_count = 0; |
| 983 | u32 last_cmd_consumer = 0; |
| 984 | int no_of_desc; |
| 985 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 986 | adapter->stats.xmitcalled++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 987 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
| 988 | |
| 989 | if (unlikely(skb->len <= 0)) { |
| 990 | dev_kfree_skb_any(skb); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 991 | adapter->stats.badskblen++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 992 | return NETDEV_TX_OK; |
| 993 | } |
| 994 | |
| 995 | if (frag_count > MAX_BUFFERS_PER_CMD) { |
| 996 | printk("%s: %s netxen_nic_xmit_frame: frag_count (%d)" |
| 997 | "too large, can handle only %d frags\n", |
| 998 | netxen_nic_driver_name, netdev->name, |
| 999 | frag_count, MAX_BUFFERS_PER_CMD); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1000 | adapter->stats.txdropped++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1001 | if ((++dropped_packet & 0xff) == 0xff) |
| 1002 | printk("%s: %s droppped packets = %d\n", |
| 1003 | netxen_nic_driver_name, netdev->name, |
| 1004 | dropped_packet); |
| 1005 | |
| 1006 | return NETDEV_TX_OK; |
| 1007 | } |
| 1008 | |
| 1009 | /* |
| 1010 | * Everything is set up. Now, we just need to transmit it out. |
| 1011 | * Note that we have to copy the contents of buffer over to |
| 1012 | * right place. Later on, this can be optimized out by de-coupling the |
| 1013 | * producer index from the buffer index. |
| 1014 | */ |
| 1015 | retry_getting_window: |
| 1016 | spin_lock_bh(&adapter->tx_lock); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1017 | if (adapter->total_threads >= MAX_XMIT_PRODUCERS) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1018 | spin_unlock_bh(&adapter->tx_lock); |
| 1019 | /* |
| 1020 | * Yield CPU |
| 1021 | */ |
| 1022 | if (!in_atomic()) |
| 1023 | schedule(); |
| 1024 | else { |
| 1025 | for (i = 0; i < 20; i++) |
| 1026 | cpu_relax(); /*This a nop instr on i386 */ |
| 1027 | } |
| 1028 | goto retry_getting_window; |
| 1029 | } |
| 1030 | local_producer = adapter->cmd_producer; |
| 1031 | /* There 4 fragments per descriptor */ |
| 1032 | no_of_desc = (frag_count + 3) >> 2; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1033 | if (netdev->features & NETIF_F_TSO) { |
| 1034 | if (skb_shinfo(skb)->gso_size > 0) { |
| 1035 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1036 | no_of_desc++; |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 1037 | if ((ip_hdrlen(skb) + tcp_hdrlen(skb) + |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 1038 | sizeof(struct ethhdr)) > |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1039 | (sizeof(struct cmd_desc_type0) - 2)) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1040 | no_of_desc++; |
| 1041 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1042 | } |
| 1043 | } |
| 1044 | k = adapter->cmd_producer; |
| 1045 | max_tx_desc_count = adapter->max_tx_desc_count; |
| 1046 | last_cmd_consumer = adapter->last_cmd_consumer; |
| 1047 | if ((k + no_of_desc) >= |
| 1048 | ((last_cmd_consumer <= k) ? last_cmd_consumer + max_tx_desc_count : |
| 1049 | last_cmd_consumer)) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1050 | netif_stop_queue(netdev); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1051 | adapter->flags |= NETXEN_NETDEV_STATUS; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1052 | spin_unlock_bh(&adapter->tx_lock); |
| 1053 | return NETDEV_TX_BUSY; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1054 | } |
| 1055 | k = get_index_range(k, max_tx_desc_count, no_of_desc); |
| 1056 | adapter->cmd_producer = k; |
| 1057 | adapter->total_threads++; |
| 1058 | adapter->num_threads++; |
| 1059 | |
| 1060 | spin_unlock_bh(&adapter->tx_lock); |
| 1061 | /* Copy the descriptors into the hardware */ |
| 1062 | producer = local_producer; |
| 1063 | saved_producer = producer; |
| 1064 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1065 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
| 1066 | /* Take skb->data itself */ |
| 1067 | pbuf = &adapter->cmd_buf_arr[producer]; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1068 | if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) { |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1069 | pbuf->mss = skb_shinfo(skb)->gso_size; |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1070 | hwdesc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1071 | } else { |
| 1072 | pbuf->mss = 0; |
| 1073 | hwdesc->mss = 0; |
| 1074 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1075 | pbuf->total_length = skb->len; |
| 1076 | pbuf->skb = skb; |
| 1077 | pbuf->cmd = TX_ETHER_PKT; |
| 1078 | pbuf->frag_count = frag_count; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1079 | pbuf->port = adapter->portnum; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1080 | buffrag = &pbuf->frag_array[0]; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1081 | 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] | 1082 | PCI_DMA_TODEVICE); |
| 1083 | buffrag->length = first_seg_len; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1084 | netxen_set_cmd_desc_totallength(hwdesc, skb->len); |
| 1085 | netxen_set_cmd_desc_num_of_buff(hwdesc, frag_count); |
| 1086 | netxen_set_cmd_desc_opcode(hwdesc, TX_ETHER_PKT); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1087 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1088 | netxen_set_cmd_desc_port(hwdesc, adapter->portnum); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1089 | netxen_set_cmd_desc_ctxid(hwdesc, adapter->portnum); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1090 | hwdesc->buffer1_length = cpu_to_le16(first_seg_len); |
| 1091 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); |
| 1092 | |
| 1093 | for (i = 1, k = 1; i < frag_count; i++, k++) { |
| 1094 | struct skb_frag_struct *frag; |
| 1095 | int len, temp_len; |
| 1096 | unsigned long offset; |
| 1097 | dma_addr_t temp_dma; |
| 1098 | |
| 1099 | /* move to next desc. if there is a need */ |
| 1100 | if ((i & 0x3) == 0) { |
| 1101 | k = 0; |
| 1102 | producer = get_next_index(producer, |
| 1103 | adapter->max_tx_desc_count); |
| 1104 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1105 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
| 1106 | } |
| 1107 | frag = &skb_shinfo(skb)->frags[i - 1]; |
| 1108 | len = frag->size; |
| 1109 | offset = frag->page_offset; |
| 1110 | |
| 1111 | temp_len = len; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1112 | temp_dma = pci_map_page(adapter->pdev, frag->page, offset, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1113 | len, PCI_DMA_TODEVICE); |
| 1114 | |
| 1115 | buffrag++; |
| 1116 | buffrag->dma = temp_dma; |
| 1117 | buffrag->length = temp_len; |
| 1118 | |
| 1119 | DPRINTK(INFO, "for loop. i=%d k=%d\n", i, k); |
| 1120 | switch (k) { |
| 1121 | case 0: |
| 1122 | hwdesc->buffer1_length = cpu_to_le16(temp_len); |
| 1123 | hwdesc->addr_buffer1 = cpu_to_le64(temp_dma); |
| 1124 | break; |
| 1125 | case 1: |
| 1126 | hwdesc->buffer2_length = cpu_to_le16(temp_len); |
| 1127 | hwdesc->addr_buffer2 = cpu_to_le64(temp_dma); |
| 1128 | break; |
| 1129 | case 2: |
| 1130 | hwdesc->buffer3_length = cpu_to_le16(temp_len); |
| 1131 | hwdesc->addr_buffer3 = cpu_to_le64(temp_dma); |
| 1132 | break; |
| 1133 | case 3: |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1134 | hwdesc->buffer4_length = cpu_to_le16(temp_len); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1135 | hwdesc->addr_buffer4 = cpu_to_le64(temp_dma); |
| 1136 | break; |
| 1137 | } |
| 1138 | frag++; |
| 1139 | } |
| 1140 | producer = get_next_index(producer, adapter->max_tx_desc_count); |
| 1141 | |
| 1142 | /* might change opcode to TX_TCP_LSO */ |
| 1143 | netxen_tso_check(adapter, &hw->cmd_desc_head[saved_producer], skb); |
| 1144 | |
| 1145 | /* For LSO, we need to copy the MAC/IP/TCP headers into |
| 1146 | * the descriptor ring |
| 1147 | */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1148 | if (netxen_get_cmd_desc_opcode(&hw->cmd_desc_head[saved_producer]) |
| 1149 | == TX_TCP_LSO) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1150 | int hdr_len, first_hdr_len, more_hdr; |
| 1151 | hdr_len = hw->cmd_desc_head[saved_producer].total_hdr_length; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1152 | if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) { |
| 1153 | first_hdr_len = sizeof(struct cmd_desc_type0) - 2; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1154 | more_hdr = 1; |
| 1155 | } else { |
| 1156 | first_hdr_len = hdr_len; |
| 1157 | more_hdr = 0; |
| 1158 | } |
| 1159 | /* copy the MAC/IP/TCP headers to the cmd descriptor list */ |
| 1160 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1161 | |
| 1162 | /* copy the first 64 bytes */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1163 | memcpy(((void *)hwdesc) + 2, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1164 | (void *)(skb->data), first_hdr_len); |
| 1165 | producer = get_next_index(producer, max_tx_desc_count); |
| 1166 | |
| 1167 | if (more_hdr) { |
| 1168 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1169 | /* copy the next 64 bytes - should be enough except |
| 1170 | * for pathological case |
| 1171 | */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1172 | skb_copy_from_linear_data_offset(skb, first_hdr_len, |
| 1173 | hwdesc, |
| 1174 | (hdr_len - |
| 1175 | first_hdr_len)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1176 | producer = get_next_index(producer, max_tx_desc_count); |
| 1177 | } |
| 1178 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1179 | |
| 1180 | i = netxen_get_cmd_desc_totallength(&hw->cmd_desc_head[saved_producer]); |
| 1181 | |
| 1182 | hw->cmd_desc_head[saved_producer].flags_opcode = |
| 1183 | cpu_to_le16(hw->cmd_desc_head[saved_producer].flags_opcode); |
| 1184 | hw->cmd_desc_head[saved_producer].num_of_buffers_total_length = |
| 1185 | cpu_to_le32(hw->cmd_desc_head[saved_producer]. |
| 1186 | num_of_buffers_total_length); |
| 1187 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1188 | spin_lock_bh(&adapter->tx_lock); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1189 | adapter->stats.txbytes += i; |
| 1190 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1191 | /* Code to update the adapter considering how many producer threads |
| 1192 | are currently working */ |
| 1193 | if ((--adapter->num_threads) == 0) { |
| 1194 | /* This is the last thread */ |
| 1195 | u32 crb_producer = adapter->cmd_producer; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1196 | netxen_nic_update_cmd_producer(adapter, crb_producer); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1197 | wmb(); |
| 1198 | adapter->total_threads = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1199 | } |
| 1200 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1201 | adapter->stats.xmitfinished++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1202 | spin_unlock_bh(&adapter->tx_lock); |
| 1203 | |
| 1204 | netdev->trans_start = jiffies; |
| 1205 | |
| 1206 | DPRINTK(INFO, "wrote CMD producer %x to phantom\n", producer); |
| 1207 | |
| 1208 | DPRINTK(INFO, "Done. Send\n"); |
| 1209 | return NETDEV_TX_OK; |
| 1210 | } |
| 1211 | |
| 1212 | static void netxen_watchdog(unsigned long v) |
| 1213 | { |
| 1214 | struct netxen_adapter *adapter = (struct netxen_adapter *)v; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1215 | |
| 1216 | SCHEDULE_WORK(&adapter->watchdog_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | static void netxen_tx_timeout(struct net_device *netdev) |
| 1220 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1221 | struct netxen_adapter *adapter = (struct netxen_adapter *) |
| 1222 | netdev_priv(netdev); |
| 1223 | SCHEDULE_WORK(&adapter->tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1224 | } |
| 1225 | |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 1226 | static void netxen_tx_timeout_task(struct work_struct *work) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1227 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1228 | struct netxen_adapter *adapter = |
| 1229 | container_of(work, struct netxen_adapter, tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 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 | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1234 | netxen_nic_close(adapter->netdev); |
| 1235 | netxen_nic_open(adapter->netdev); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1236 | adapter->netdev->trans_start = jiffies; |
| 1237 | netif_wake_queue(adapter->netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | static int |
| 1241 | netxen_handle_int(struct netxen_adapter *adapter, struct net_device *netdev) |
| 1242 | { |
| 1243 | u32 ret = 0; |
| 1244 | |
| 1245 | DPRINTK(INFO, "Entered handle ISR\n"); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1246 | adapter->stats.ints++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1247 | |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 1248 | netxen_nic_disable_int(adapter); |
| 1249 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1250 | if (netxen_nic_rx_has_work(adapter) || netxen_nic_tx_has_work(adapter)) { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame^] | 1251 | if (netif_rx_schedule_prep(netdev, &adapter->napi)) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1252 | /* |
| 1253 | * Interrupts are already disabled. |
| 1254 | */ |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame^] | 1255 | __netif_rx_schedule(netdev, &adapter->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1256 | } else { |
| 1257 | static unsigned int intcount = 0; |
| 1258 | if ((++intcount & 0xfff) == 0xfff) |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 1259 | DPRINTK(KERN_ERR |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1260 | "%s: %s interrupt %d while in poll\n", |
| 1261 | netxen_nic_driver_name, netdev->name, |
| 1262 | intcount); |
| 1263 | } |
| 1264 | ret = 1; |
| 1265 | } |
| 1266 | |
| 1267 | if (ret == 0) { |
| 1268 | netxen_nic_enable_int(adapter); |
| 1269 | } |
| 1270 | |
| 1271 | return ret; |
| 1272 | } |
| 1273 | |
| 1274 | /* |
| 1275 | * netxen_intr - Interrupt Handler |
| 1276 | * @irq: interrupt number |
| 1277 | * data points to adapter stucture (which may be handling more than 1 port |
| 1278 | */ |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1279 | irqreturn_t netxen_intr(int irq, void *data) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1280 | { |
| 1281 | struct netxen_adapter *adapter; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1282 | struct net_device *netdev; |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1283 | u32 our_int = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1284 | |
| 1285 | if (unlikely(!irq)) { |
| 1286 | return IRQ_NONE; /* Not our interrupt */ |
| 1287 | } |
| 1288 | |
| 1289 | adapter = (struct netxen_adapter *)data; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1290 | netdev = adapter->netdev; |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1291 | |
| 1292 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { |
| 1293 | our_int = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR)); |
| 1294 | /* not our interrupt */ |
| 1295 | if ((our_int & (0x80 << adapter->portnum)) == 0) |
| 1296 | return IRQ_NONE; |
| 1297 | } |
| 1298 | |
| 1299 | if (adapter->intr_scheme == INTR_SCHEME_PERPORT) { |
| 1300 | /* claim interrupt */ |
| 1301 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { |
| 1302 | writel(our_int & ~((u32)(0x80 << adapter->portnum)), |
| 1303 | NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR)); |
| 1304 | } |
| 1305 | } |
| 1306 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1307 | if (netif_running(netdev)) |
| 1308 | netxen_handle_int(adapter, netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1309 | |
| 1310 | return IRQ_HANDLED; |
| 1311 | } |
| 1312 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame^] | 1313 | static int netxen_nic_poll(struct napi_struct *napi, int budget) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1314 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame^] | 1315 | struct netxen_adapter *adapter = container_of(napi, struct netxen_adapter, napi); |
| 1316 | struct net_device *netdev = adapter->netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1317 | int done = 1; |
| 1318 | int ctx; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame^] | 1319 | int work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1320 | |
| 1321 | DPRINTK(INFO, "polling for %d descriptors\n", *budget); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1322 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1323 | work_done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1324 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
| 1325 | /* |
| 1326 | * Fairness issue. This will give undue weight to the |
| 1327 | * receive context 0. |
| 1328 | */ |
| 1329 | |
| 1330 | /* |
| 1331 | * To avoid starvation, we give each of our receivers, |
| 1332 | * a fraction of the quota. Sometimes, it might happen that we |
| 1333 | * have enough quota to process every packet, but since all the |
| 1334 | * packets are on one context, it gets only half of the quota, |
| 1335 | * and ends up not processing it. |
| 1336 | */ |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame^] | 1337 | work_done += netxen_process_rcv_ring(adapter, ctx, |
| 1338 | budget / MAX_RCV_CTX); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1339 | } |
| 1340 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame^] | 1341 | if (work_done >= budget && netxen_nic_rx_has_work(adapter) != 0) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1342 | done = 0; |
| 1343 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1344 | if (netxen_process_cmd_ring((unsigned long)adapter) == 0) |
| 1345 | done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1346 | |
| 1347 | DPRINTK(INFO, "new work_done: %d work_to_do: %d\n", |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1348 | work_done, work_to_do); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1349 | if (done) { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame^] | 1350 | netif_rx_complete(netdev, napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1351 | netxen_nic_enable_int(adapter); |
| 1352 | } |
| 1353 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame^] | 1354 | return work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1358 | static void netxen_nic_poll_controller(struct net_device *netdev) |
| 1359 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1360 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1361 | disable_irq(adapter->irq); |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1362 | netxen_intr(adapter->irq, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1363 | enable_irq(adapter->irq); |
| 1364 | } |
| 1365 | #endif |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1366 | |
| 1367 | static struct pci_driver netxen_driver = { |
| 1368 | .name = netxen_nic_driver_name, |
| 1369 | .id_table = netxen_pci_tbl, |
| 1370 | .probe = netxen_nic_probe, |
| 1371 | .remove = __devexit_p(netxen_nic_remove) |
| 1372 | }; |
| 1373 | |
| 1374 | /* Driver Registration on NetXen card */ |
| 1375 | |
| 1376 | static int __init netxen_init_module(void) |
| 1377 | { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1378 | if ((netxen_workq = create_singlethread_workqueue("netxen")) == 0) |
| 1379 | return -ENOMEM; |
| 1380 | |
Amit S. Kale | 184231b | 2007-01-22 06:52:53 -0800 | [diff] [blame] | 1381 | return pci_register_driver(&netxen_driver); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | module_init(netxen_init_module); |
| 1385 | |
| 1386 | static void __exit netxen_exit_module(void) |
| 1387 | { |
| 1388 | /* |
| 1389 | * Wait for some time to allow the dma to drain, if any. |
| 1390 | */ |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1391 | msleep(100); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1392 | pci_unregister_driver(&netxen_driver); |
Amit S. Kale | 9de0661 | 2007-02-21 06:37:06 -0800 | [diff] [blame] | 1393 | destroy_workqueue(netxen_workq); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | module_exit(netxen_exit_module); |