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" |
| 39 | #define DEFINE_GLOBAL_RECV_CRB |
| 40 | #include "netxen_nic_phan_reg.h" |
| 41 | #include "netxen_nic_ioctl.h" |
| 42 | |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 43 | #include <linux/dma-mapping.h> |
| 44 | #include <linux/vmalloc.h> |
| 45 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 46 | #define PHAN_VENDOR_ID 0x4040 |
| 47 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 48 | MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver"); |
| 49 | MODULE_LICENSE("GPL"); |
| 50 | MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID); |
| 51 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 52 | char netxen_nic_driver_name[] = "netxen-nic"; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 53 | static char netxen_nic_driver_string[] = "NetXen Network Driver version " |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 54 | NETXEN_NIC_LINUX_VERSIONID; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 55 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 56 | struct netxen_adapter *g_adapter = NULL; |
| 57 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 58 | #define NETXEN_NETDEV_WEIGHT 120 |
| 59 | #define NETXEN_ADAPTER_UP_MAGIC 777 |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 60 | #define NETXEN_NIC_PEG_TUNE 0 |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 61 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 62 | u8 nx_p2_id = NX_P2_C0; |
| 63 | |
| 64 | #define DMA_32BIT_MASK 0x00000000ffffffffULL |
| 65 | #define DMA_35BIT_MASK 0x00000007ffffffffULL |
| 66 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 67 | /* Local functions to NetXen NIC driver */ |
| 68 | static int __devinit netxen_nic_probe(struct pci_dev *pdev, |
| 69 | const struct pci_device_id *ent); |
| 70 | static void __devexit netxen_nic_remove(struct pci_dev *pdev); |
| 71 | static int netxen_nic_open(struct net_device *netdev); |
| 72 | static int netxen_nic_close(struct net_device *netdev); |
| 73 | static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *); |
| 74 | static void netxen_tx_timeout(struct net_device *netdev); |
| 75 | static void netxen_tx_timeout_task(struct net_device *netdev); |
| 76 | static void netxen_watchdog(unsigned long); |
| 77 | static int netxen_handle_int(struct netxen_adapter *, struct net_device *); |
| 78 | static int netxen_nic_ioctl(struct net_device *netdev, |
| 79 | struct ifreq *ifr, int cmd); |
| 80 | static int netxen_nic_poll(struct net_device *dev, int *budget); |
| 81 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 82 | static void netxen_nic_poll_controller(struct net_device *netdev); |
| 83 | #endif |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 84 | static irqreturn_t netxen_intr(int irq, void *data); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 85 | |
| 86 | /* PCI Device ID Table */ |
| 87 | static struct pci_device_id netxen_pci_tbl[] __devinitdata = { |
| 88 | {PCI_DEVICE(0x4040, 0x0001)}, |
| 89 | {PCI_DEVICE(0x4040, 0x0002)}, |
| 90 | {PCI_DEVICE(0x4040, 0x0003)}, |
| 91 | {PCI_DEVICE(0x4040, 0x0004)}, |
| 92 | {PCI_DEVICE(0x4040, 0x0005)}, |
| 93 | {0,} |
| 94 | }; |
| 95 | |
| 96 | MODULE_DEVICE_TABLE(pci, netxen_pci_tbl); |
| 97 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 98 | struct workqueue_struct *netxen_workq; |
| 99 | static void netxen_watchdog(unsigned long); |
| 100 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 101 | /* |
| 102 | * netxen_nic_probe() |
| 103 | * |
| 104 | * The Linux system will invoke this after identifying the vendor ID and |
| 105 | * device Id in the pci_tbl supported by this module. |
| 106 | * |
| 107 | * A quad port card has one operational PCI config space, (function 0), |
| 108 | * which is used to access all four ports. |
| 109 | * |
| 110 | * This routine will initialize the adapter, and setup the global parameters |
| 111 | * along with the port's specific structure. |
| 112 | */ |
| 113 | static int __devinit |
| 114 | netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 115 | { |
| 116 | struct net_device *netdev = NULL; |
| 117 | struct netxen_adapter *adapter = NULL; |
| 118 | struct netxen_port *port = NULL; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 119 | void __iomem *mem_ptr0 = NULL; |
| 120 | void __iomem *mem_ptr1 = NULL; |
| 121 | void __iomem *mem_ptr2 = NULL; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 122 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 123 | u8 *db_ptr = NULL; |
| 124 | unsigned long mem_base, mem_len, db_base, db_len; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 125 | int pci_using_dac, i, err; |
| 126 | int ring; |
| 127 | struct netxen_recv_context *recv_ctx = NULL; |
| 128 | struct netxen_rcv_desc_ctx *rcv_desc = NULL; |
| 129 | struct netxen_cmd_buffer *cmd_buf_arr = NULL; |
| 130 | u64 mac_addr[FLASH_NUM_PORTS + 1]; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 131 | int valid_mac = 0; |
| 132 | static int netxen_cards_found = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 133 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 134 | printk(KERN_INFO "%s \n", netxen_nic_driver_string); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 135 | /* In current scheme, we use only PCI function 0 */ |
| 136 | if (PCI_FUNC(pdev->devfn) != 0) { |
| 137 | DPRINTK(ERR, "NetXen function %d will not be enabled.\n", |
| 138 | PCI_FUNC(pdev->devfn)); |
| 139 | return -ENODEV; |
| 140 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 141 | if ((err = pci_enable_device(pdev))) |
| 142 | return err; |
| 143 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 144 | err = -ENODEV; |
| 145 | goto err_out_disable_pdev; |
| 146 | } |
| 147 | |
| 148 | if ((err = pci_request_regions(pdev, netxen_nic_driver_name))) |
| 149 | goto err_out_disable_pdev; |
| 150 | |
| 151 | pci_set_master(pdev); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 152 | pci_read_config_byte(pdev, PCI_REVISION_ID, &nx_p2_id); |
| 153 | if (nx_p2_id == NX_P2_C1 && |
| 154 | (pci_set_dma_mask(pdev, DMA_35BIT_MASK) == 0) && |
| 155 | (pci_set_consistent_dma_mask(pdev, DMA_35BIT_MASK) == 0)) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 156 | pci_using_dac = 1; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 157 | } else { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 158 | if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) || |
| 159 | (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) |
| 160 | goto err_out_free_res; |
| 161 | |
| 162 | pci_using_dac = 0; |
| 163 | } |
| 164 | |
| 165 | /* remap phys address */ |
| 166 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 167 | mem_len = pci_resource_len(pdev, 0); |
| 168 | |
| 169 | /* 128 Meg of memory */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 170 | mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE); |
| 171 | mem_ptr1 = |
| 172 | ioremap(mem_base + SECOND_PAGE_GROUP_START, SECOND_PAGE_GROUP_SIZE); |
| 173 | mem_ptr2 = |
| 174 | ioremap(mem_base + THIRD_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE); |
| 175 | |
| 176 | if ((mem_ptr0 == 0UL) || (mem_ptr1 == 0UL) || (mem_ptr2 == 0UL)) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 177 | DPRINTK(ERR, |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 178 | "Cannot remap adapter memory aborting.:" |
| 179 | "0 -> %p, 1 -> %p, 2 -> %p\n", |
| 180 | mem_ptr0, mem_ptr1, mem_ptr2); |
| 181 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 182 | err = -EIO; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 183 | goto err_out_iounmap; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 184 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 185 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ |
| 186 | db_len = pci_resource_len(pdev, 4); |
| 187 | |
| 188 | if (db_len == 0) { |
| 189 | printk(KERN_ERR "%s: doorbell is disabled\n", |
| 190 | netxen_nic_driver_name); |
| 191 | err = -EIO; |
| 192 | goto err_out_iounmap; |
| 193 | } |
| 194 | DPRINTK(INFO, "doorbell ioremap from %lx a size of %lx\n", db_base, |
| 195 | db_len); |
| 196 | |
| 197 | db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES); |
| 198 | if (db_ptr == 0UL) { |
| 199 | printk(KERN_ERR "%s: Failed to allocate doorbell map.", |
| 200 | netxen_nic_driver_name); |
| 201 | err = -EIO; |
| 202 | goto err_out_iounmap; |
| 203 | } |
| 204 | DPRINTK(INFO, "doorbell ioremaped at %p\n", db_ptr); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 205 | |
| 206 | /* |
| 207 | * Allocate a adapter structure which will manage all the initialization |
| 208 | * as well as the common resources for all ports... |
| 209 | * all the ports will have pointer to this adapter as well as Adapter |
| 210 | * will have pointers of all the ports structures. |
| 211 | */ |
| 212 | |
| 213 | /* One adapter structure for all 4 ports.... */ |
| 214 | adapter = kzalloc(sizeof(struct netxen_adapter), GFP_KERNEL); |
| 215 | if (adapter == NULL) { |
| 216 | printk(KERN_ERR "%s: Could not allocate adapter memory:%d\n", |
| 217 | netxen_nic_driver_name, |
| 218 | (int)sizeof(struct netxen_adapter)); |
| 219 | err = -ENOMEM; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 220 | goto err_out_dbunmap; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 221 | } |
| 222 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 223 | if (netxen_cards_found == 0) { |
| 224 | g_adapter = adapter; |
| 225 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 226 | adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS; |
| 227 | adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS; |
| 228 | adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 229 | adapter->max_lro_rx_desc_count = MAX_LRO_RCV_DESCRIPTORS; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 230 | |
| 231 | pci_set_drvdata(pdev, adapter); |
| 232 | |
| 233 | cmd_buf_arr = (struct netxen_cmd_buffer *)vmalloc(TX_RINGSIZE); |
| 234 | if (cmd_buf_arr == NULL) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 235 | printk(KERN_ERR |
| 236 | "%s: Could not allocate cmd_buf_arr memory:%d\n", |
| 237 | netxen_nic_driver_name, (int)TX_RINGSIZE); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 238 | err = -ENOMEM; |
| 239 | goto err_out_free_adapter; |
| 240 | } |
| 241 | memset(cmd_buf_arr, 0, TX_RINGSIZE); |
| 242 | |
| 243 | for (i = 0; i < MAX_RCV_CTX; ++i) { |
| 244 | recv_ctx = &adapter->recv_ctx[i]; |
| 245 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 246 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 247 | switch (RCV_DESC_TYPE(ring)) { |
| 248 | case RCV_DESC_NORMAL: |
| 249 | rcv_desc->max_rx_desc_count = |
| 250 | adapter->max_rx_desc_count; |
| 251 | rcv_desc->flags = RCV_DESC_NORMAL; |
| 252 | rcv_desc->dma_size = RX_DMA_MAP_LEN; |
| 253 | rcv_desc->skb_size = MAX_RX_BUFFER_LENGTH; |
| 254 | break; |
| 255 | |
| 256 | case RCV_DESC_JUMBO: |
| 257 | rcv_desc->max_rx_desc_count = |
| 258 | adapter->max_jumbo_rx_desc_count; |
| 259 | rcv_desc->flags = RCV_DESC_JUMBO; |
| 260 | rcv_desc->dma_size = RX_JUMBO_DMA_MAP_LEN; |
| 261 | rcv_desc->skb_size = MAX_RX_JUMBO_BUFFER_LENGTH; |
| 262 | break; |
| 263 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 264 | case RCV_RING_LRO: |
| 265 | rcv_desc->max_rx_desc_count = |
| 266 | adapter->max_lro_rx_desc_count; |
| 267 | rcv_desc->flags = RCV_DESC_LRO; |
| 268 | rcv_desc->dma_size = RX_LRO_DMA_MAP_LEN; |
| 269 | rcv_desc->skb_size = MAX_RX_LRO_BUFFER_LENGTH; |
| 270 | break; |
| 271 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 272 | } |
| 273 | rcv_desc->rx_buf_arr = (struct netxen_rx_buffer *) |
| 274 | vmalloc(RCV_BUFFSIZE); |
| 275 | |
| 276 | if (rcv_desc->rx_buf_arr == NULL) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 277 | printk(KERN_ERR "%s: Could not allocate" |
| 278 | "rcv_desc->rx_buf_arr memory:%d\n", |
| 279 | netxen_nic_driver_name, |
| 280 | (int)RCV_BUFFSIZE); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 281 | err = -ENOMEM; |
| 282 | goto err_out_free_rx_buffer; |
| 283 | } |
| 284 | memset(rcv_desc->rx_buf_arr, 0, RCV_BUFFSIZE); |
| 285 | } |
| 286 | |
| 287 | } |
| 288 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 289 | adapter->cmd_buf_arr = cmd_buf_arr; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 290 | adapter->ahw.pci_base0 = mem_ptr0; |
| 291 | adapter->ahw.pci_base1 = mem_ptr1; |
| 292 | adapter->ahw.pci_base2 = mem_ptr2; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 293 | adapter->ahw.db_base = db_ptr; |
| 294 | adapter->ahw.db_len = db_len; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 295 | spin_lock_init(&adapter->tx_lock); |
| 296 | spin_lock_init(&adapter->lock); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 297 | netxen_initialize_adapter_sw(adapter); /* initialize the buffers in adapter */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 298 | #ifdef CONFIG_IA64 |
| 299 | netxen_pinit_from_rom(adapter, 0); |
| 300 | udelay(500); |
| 301 | netxen_load_firmware(adapter); |
| 302 | #endif |
| 303 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 304 | /* |
| 305 | * Set the CRB window to invalid. If any register in window 0 is |
| 306 | * accessed it should set the window to 0 and then reset it to 1. |
| 307 | */ |
| 308 | adapter->curr_window = 255; |
| 309 | /* |
| 310 | * Adapter in our case is quad port so initialize it before |
| 311 | * initializing the ports |
| 312 | */ |
| 313 | netxen_initialize_adapter_hw(adapter); /* initialize the adapter */ |
| 314 | |
| 315 | netxen_initialize_adapter_ops(adapter); |
| 316 | |
| 317 | init_timer(&adapter->watchdog_timer); |
| 318 | adapter->ahw.xg_linkup = 0; |
| 319 | adapter->watchdog_timer.function = &netxen_watchdog; |
| 320 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 321 | INIT_WORK(&adapter->watchdog_task, |
| 322 | (void (*)(void *))netxen_watchdog_task, adapter); |
| 323 | adapter->ahw.pdev = pdev; |
| 324 | adapter->proc_cmd_buf_counter = 0; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 325 | adapter->ahw.revision_id = nx_p2_id; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 326 | |
| 327 | if (pci_enable_msi(pdev)) { |
| 328 | adapter->flags &= ~NETXEN_NIC_MSI_ENABLED; |
| 329 | printk(KERN_WARNING "%s: unable to allocate MSI interrupt" |
| 330 | " error\n", netxen_nic_driver_name); |
| 331 | } else |
| 332 | adapter->flags |= NETXEN_NIC_MSI_ENABLED; |
| 333 | |
| 334 | if (netxen_is_flash_supported(adapter) == 0 && |
| 335 | netxen_get_flash_mac_addr(adapter, mac_addr) == 0) |
| 336 | valid_mac = 1; |
| 337 | else |
| 338 | valid_mac = 0; |
| 339 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 340 | /* |
| 341 | * Initialize all the CRB registers here. |
| 342 | */ |
| 343 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMD_PRODUCER_OFFSET)); |
| 344 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMD_CONSUMER_OFFSET)); |
| 345 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_CMD_ADDR_LO)); |
| 346 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 347 | /* do this before waking up pegs so that we have valid dummy dma addr */ |
| 348 | err = netxen_initialize_adapter_offload(adapter); |
| 349 | if (err) { |
| 350 | goto err_out_free_dev; |
| 351 | } |
| 352 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 353 | /* Unlock the HW, prompting the boot sequence */ |
| 354 | writel(1, |
| 355 | NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE)); |
| 356 | |
| 357 | /* Handshake with the card before we register the devices. */ |
| 358 | netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
| 359 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 360 | /* initialize the all the ports */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 361 | adapter->active_ports = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 362 | |
| 363 | for (i = 0; i < adapter->ahw.max_ports; i++) { |
| 364 | netdev = alloc_etherdev(sizeof(struct netxen_port)); |
| 365 | if (!netdev) { |
| 366 | printk(KERN_ERR "%s: could not allocate netdev for port" |
| 367 | " %d\n", netxen_nic_driver_name, i + 1); |
| 368 | goto err_out_free_dev; |
| 369 | } |
| 370 | |
| 371 | SET_MODULE_OWNER(netdev); |
Amit S. Kale | edf9016 | 2006-11-29 08:58:11 -0800 | [diff] [blame] | 372 | SET_NETDEV_DEV(netdev, &pdev->dev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 373 | |
| 374 | port = netdev_priv(netdev); |
| 375 | port->netdev = netdev; |
| 376 | port->pdev = pdev; |
| 377 | port->adapter = adapter; |
| 378 | port->portnum = i; /* Gigabit port number from 0-3 */ |
| 379 | |
| 380 | netdev->open = netxen_nic_open; |
| 381 | netdev->stop = netxen_nic_close; |
| 382 | netdev->hard_start_xmit = netxen_nic_xmit_frame; |
| 383 | netdev->get_stats = netxen_nic_get_stats; |
| 384 | netdev->set_multicast_list = netxen_nic_set_multi; |
| 385 | netdev->set_mac_address = netxen_nic_set_mac; |
| 386 | netdev->change_mtu = netxen_nic_change_mtu; |
| 387 | netdev->do_ioctl = netxen_nic_ioctl; |
| 388 | netdev->tx_timeout = netxen_tx_timeout; |
| 389 | netdev->watchdog_timeo = HZ; |
| 390 | |
| 391 | SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops); |
| 392 | netdev->poll = netxen_nic_poll; |
| 393 | netdev->weight = NETXEN_NETDEV_WEIGHT; |
| 394 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 395 | netdev->poll_controller = netxen_nic_poll_controller; |
| 396 | #endif |
| 397 | /* ScatterGather support */ |
| 398 | netdev->features = NETIF_F_SG; |
| 399 | netdev->features |= NETIF_F_IP_CSUM; |
| 400 | netdev->features |= NETIF_F_TSO; |
| 401 | |
| 402 | if (pci_using_dac) |
| 403 | netdev->features |= NETIF_F_HIGHDMA; |
| 404 | |
| 405 | if (valid_mac) { |
| 406 | unsigned char *p = (unsigned char *)&mac_addr[i]; |
| 407 | netdev->dev_addr[0] = *(p + 5); |
| 408 | netdev->dev_addr[1] = *(p + 4); |
| 409 | netdev->dev_addr[2] = *(p + 3); |
| 410 | netdev->dev_addr[3] = *(p + 2); |
| 411 | netdev->dev_addr[4] = *(p + 1); |
| 412 | netdev->dev_addr[5] = *(p + 0); |
| 413 | |
| 414 | memcpy(netdev->perm_addr, netdev->dev_addr, |
| 415 | netdev->addr_len); |
| 416 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
| 417 | printk(KERN_ERR "%s: Bad MAC address " |
| 418 | "%02x:%02x:%02x:%02x:%02x:%02x.\n", |
| 419 | netxen_nic_driver_name, |
| 420 | netdev->dev_addr[0], |
| 421 | netdev->dev_addr[1], |
| 422 | netdev->dev_addr[2], |
| 423 | netdev->dev_addr[3], |
| 424 | netdev->dev_addr[4], |
| 425 | netdev->dev_addr[5]); |
| 426 | } else { |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 427 | if (adapter->macaddr_set) |
| 428 | adapter->macaddr_set(port, |
| 429 | netdev->dev_addr); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 430 | } |
| 431 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 432 | INIT_WORK(adapter->tx_timeout_task + i, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 433 | (void (*)(void *))netxen_tx_timeout_task, netdev); |
| 434 | netif_carrier_off(netdev); |
| 435 | netif_stop_queue(netdev); |
| 436 | |
| 437 | if ((err = register_netdev(netdev))) { |
| 438 | printk(KERN_ERR "%s: register_netdev failed port #%d" |
| 439 | " aborting\n", netxen_nic_driver_name, i + 1); |
| 440 | err = -EIO; |
| 441 | free_netdev(netdev); |
| 442 | goto err_out_free_dev; |
| 443 | } |
| 444 | adapter->port_count++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 445 | adapter->port[i] = port; |
| 446 | } |
| 447 | |
| 448 | /* |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 449 | * delay a while to ensure that the Pegs are up & running. |
| 450 | * Otherwise, we might see some flaky behaviour. |
| 451 | */ |
| 452 | udelay(100); |
| 453 | |
| 454 | switch (adapter->ahw.board_type) { |
| 455 | case NETXEN_NIC_GBE: |
| 456 | printk("%s: QUAD GbE board initialized\n", |
| 457 | netxen_nic_driver_name); |
| 458 | break; |
| 459 | |
| 460 | case NETXEN_NIC_XGBE: |
| 461 | printk("%s: XGbE board initialized\n", netxen_nic_driver_name); |
| 462 | break; |
| 463 | } |
| 464 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 465 | adapter->number = netxen_cards_found; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 466 | adapter->driver_mismatch = 0; |
| 467 | |
| 468 | return 0; |
| 469 | |
| 470 | err_out_free_dev: |
| 471 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 472 | pci_disable_msi(pdev); |
| 473 | for (i = 0; i < adapter->port_count; i++) { |
| 474 | port = adapter->port[i]; |
| 475 | if ((port) && (port->netdev)) { |
| 476 | unregister_netdev(port->netdev); |
| 477 | free_netdev(port->netdev); |
| 478 | } |
| 479 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 480 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 481 | netxen_free_adapter_offload(adapter); |
| 482 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 483 | err_out_free_rx_buffer: |
| 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 | if (rcv_desc->rx_buf_arr != NULL) { |
| 489 | vfree(rcv_desc->rx_buf_arr); |
| 490 | rcv_desc->rx_buf_arr = NULL; |
| 491 | } |
| 492 | } |
| 493 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 494 | vfree(cmd_buf_arr); |
| 495 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 496 | err_out_free_adapter: |
| 497 | pci_set_drvdata(pdev, NULL); |
| 498 | kfree(adapter); |
| 499 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 500 | err_out_dbunmap: |
| 501 | if (db_ptr) |
| 502 | iounmap(db_ptr); |
| 503 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 504 | err_out_iounmap: |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 505 | if (mem_ptr0) |
| 506 | iounmap(mem_ptr0); |
| 507 | if (mem_ptr1) |
| 508 | iounmap(mem_ptr1); |
| 509 | if (mem_ptr2) |
| 510 | iounmap(mem_ptr2); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 511 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 512 | err_out_free_res: |
| 513 | pci_release_regions(pdev); |
| 514 | err_out_disable_pdev: |
| 515 | pci_disable_device(pdev); |
| 516 | return err; |
| 517 | } |
| 518 | |
| 519 | static void __devexit netxen_nic_remove(struct pci_dev *pdev) |
| 520 | { |
| 521 | struct netxen_adapter *adapter; |
| 522 | struct netxen_port *port; |
| 523 | struct netxen_rx_buffer *buffer; |
| 524 | struct netxen_recv_context *recv_ctx; |
| 525 | struct netxen_rcv_desc_ctx *rcv_desc; |
| 526 | int i; |
| 527 | int ctxid, ring; |
| 528 | |
| 529 | adapter = pci_get_drvdata(pdev); |
| 530 | if (adapter == NULL) |
| 531 | return; |
| 532 | |
| 533 | netxen_nic_stop_all_ports(adapter); |
| 534 | /* leave the hw in the same state as reboot */ |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 535 | netxen_load_firmware(adapter); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 536 | netxen_free_adapter_offload(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 537 | |
| 538 | udelay(500); /* Delay for a while to drain the DMA engines */ |
| 539 | for (i = 0; i < adapter->port_count; i++) { |
| 540 | port = adapter->port[i]; |
| 541 | if ((port) && (port->netdev)) { |
| 542 | unregister_netdev(port->netdev); |
| 543 | free_netdev(port->netdev); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | if ((adapter->flags & NETXEN_NIC_MSI_ENABLED)) |
| 548 | pci_disable_msi(pdev); |
| 549 | pci_set_drvdata(pdev, NULL); |
| 550 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) |
| 551 | netxen_free_hw_resources(adapter); |
| 552 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 553 | iounmap(adapter->ahw.db_base); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 554 | iounmap(adapter->ahw.pci_base0); |
| 555 | iounmap(adapter->ahw.pci_base1); |
| 556 | iounmap(adapter->ahw.pci_base2); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 557 | |
| 558 | pci_release_regions(pdev); |
| 559 | pci_disable_device(pdev); |
| 560 | |
| 561 | for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) { |
| 562 | recv_ctx = &adapter->recv_ctx[ctxid]; |
| 563 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 564 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 565 | for (i = 0; i < rcv_desc->max_rx_desc_count; ++i) { |
| 566 | buffer = &(rcv_desc->rx_buf_arr[i]); |
| 567 | if (buffer->state == NETXEN_BUFFER_FREE) |
| 568 | continue; |
| 569 | pci_unmap_single(pdev, buffer->dma, |
| 570 | rcv_desc->dma_size, |
| 571 | PCI_DMA_FROMDEVICE); |
| 572 | if (buffer->skb != NULL) |
| 573 | dev_kfree_skb_any(buffer->skb); |
| 574 | } |
| 575 | vfree(rcv_desc->rx_buf_arr); |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | vfree(adapter->cmd_buf_arr); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 580 | kfree(adapter); |
| 581 | } |
| 582 | |
| 583 | /* |
| 584 | * Called when a network interface is made active |
| 585 | * @returns 0 on success, negative value on failure |
| 586 | */ |
| 587 | static int netxen_nic_open(struct net_device *netdev) |
| 588 | { |
| 589 | struct netxen_port *port = netdev_priv(netdev); |
| 590 | struct netxen_adapter *adapter = port->adapter; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 591 | int err = 0; |
| 592 | int ctx, ring; |
| 593 | |
| 594 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) { |
| 595 | err = netxen_init_firmware(adapter); |
| 596 | if (err != 0) { |
| 597 | printk(KERN_ERR "Failed to init firmware\n"); |
| 598 | return -EIO; |
| 599 | } |
| 600 | netxen_nic_flash_print(adapter); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 601 | if (adapter->init_niu) |
| 602 | adapter->init_niu(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 603 | |
| 604 | /* setup all the resources for the Phantom... */ |
| 605 | /* this include the descriptors for rcv, tx, and status */ |
| 606 | netxen_nic_clear_stats(adapter); |
| 607 | err = netxen_nic_hw_resources(adapter); |
| 608 | if (err) { |
| 609 | printk(KERN_ERR "Error in setting hw resources:%d\n", |
| 610 | err); |
| 611 | return err; |
| 612 | } |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 613 | if (adapter->init_port |
| 614 | && adapter->init_port(adapter, port->portnum) != 0) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 615 | printk(KERN_ERR "%s: Failed to initialize port %d\n", |
| 616 | netxen_nic_driver_name, port->portnum); |
| 617 | netxen_free_hw_resources(adapter); |
| 618 | return -EIO; |
| 619 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 620 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 621 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 622 | netxen_post_rx_buffers(adapter, ctx, ring); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 623 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 624 | adapter->irq = adapter->ahw.pdev->irq; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 625 | err = request_irq(adapter->ahw.pdev->irq, &netxen_intr, |
| 626 | SA_SHIRQ | SA_SAMPLE_RANDOM, netdev->name, |
| 627 | adapter); |
| 628 | if (err) { |
| 629 | printk(KERN_ERR "request_irq failed with: %d\n", err); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 630 | netxen_free_hw_resources(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 631 | return err; |
| 632 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 633 | |
| 634 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; |
| 635 | } |
| 636 | adapter->active_ports++; |
| 637 | if (adapter->active_ports == 1) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 638 | if (!adapter->driver_mismatch) |
| 639 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 640 | |
| 641 | netxen_nic_enable_int(adapter); |
| 642 | } |
| 643 | |
| 644 | /* Done here again so that even if phantom sw overwrote it, |
| 645 | * we set it */ |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 646 | if (adapter->macaddr_set) |
| 647 | adapter->macaddr_set(port, netdev->dev_addr); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 648 | netxen_nic_set_link_parameters(port); |
| 649 | |
| 650 | netxen_nic_set_multi(netdev); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 651 | if (adapter->set_mtu) |
| 652 | adapter->set_mtu(port, netdev->mtu); |
| 653 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 654 | if (!adapter->driver_mismatch) |
| 655 | netif_start_queue(netdev); |
| 656 | |
| 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | /* |
| 661 | * netxen_nic_close - Disables a network interface entry point |
| 662 | */ |
| 663 | static int netxen_nic_close(struct net_device *netdev) |
| 664 | { |
| 665 | struct netxen_port *port = netdev_priv(netdev); |
| 666 | struct netxen_adapter *adapter = port->adapter; |
| 667 | int i, j; |
| 668 | struct netxen_cmd_buffer *cmd_buff; |
| 669 | struct netxen_skb_frag *buffrag; |
| 670 | |
| 671 | netif_carrier_off(netdev); |
| 672 | netif_stop_queue(netdev); |
| 673 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 674 | adapter->active_ports--; |
| 675 | |
| 676 | if (!adapter->active_ports) { |
| 677 | netxen_nic_disable_int(adapter); |
| 678 | if (adapter->irq) |
| 679 | free_irq(adapter->irq, adapter); |
| 680 | cmd_buff = adapter->cmd_buf_arr; |
| 681 | for (i = 0; i < adapter->max_tx_desc_count; i++) { |
| 682 | buffrag = cmd_buff->frag_array; |
| 683 | if (buffrag->dma) { |
| 684 | pci_unmap_single(port->pdev, buffrag->dma, |
| 685 | buffrag->length, |
| 686 | PCI_DMA_TODEVICE); |
| 687 | buffrag->dma = (u64) NULL; |
| 688 | } |
| 689 | for (j = 0; j < cmd_buff->frag_count; j++) { |
| 690 | buffrag++; |
| 691 | if (buffrag->dma) { |
| 692 | pci_unmap_page(port->pdev, |
| 693 | buffrag->dma, |
| 694 | buffrag->length, |
| 695 | PCI_DMA_TODEVICE); |
| 696 | buffrag->dma = (u64) NULL; |
| 697 | } |
| 698 | } |
| 699 | /* Free the skb we received in netxen_nic_xmit_frame */ |
| 700 | if (cmd_buff->skb) { |
| 701 | dev_kfree_skb_any(cmd_buff->skb); |
| 702 | cmd_buff->skb = NULL; |
| 703 | } |
| 704 | cmd_buff++; |
| 705 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 706 | FLUSH_SCHEDULED_WORK(); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 707 | del_timer_sync(&adapter->watchdog_timer); |
| 708 | } |
| 709 | |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 714 | { |
| 715 | struct netxen_port *port = netdev_priv(netdev); |
| 716 | struct netxen_adapter *adapter = port->adapter; |
| 717 | struct netxen_hardware_context *hw = &adapter->ahw; |
| 718 | unsigned int first_seg_len = skb->len - skb->data_len; |
| 719 | struct netxen_skb_frag *buffrag; |
| 720 | unsigned int i; |
| 721 | |
| 722 | u32 producer = 0; |
| 723 | u32 saved_producer = 0; |
| 724 | struct cmd_desc_type0 *hwdesc; |
| 725 | int k; |
| 726 | struct netxen_cmd_buffer *pbuf = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 727 | static int dropped_packet = 0; |
| 728 | int frag_count; |
| 729 | u32 local_producer = 0; |
| 730 | u32 max_tx_desc_count = 0; |
| 731 | u32 last_cmd_consumer = 0; |
| 732 | int no_of_desc; |
| 733 | |
| 734 | port->stats.xmitcalled++; |
| 735 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
| 736 | |
| 737 | if (unlikely(skb->len <= 0)) { |
| 738 | dev_kfree_skb_any(skb); |
| 739 | port->stats.badskblen++; |
| 740 | return NETDEV_TX_OK; |
| 741 | } |
| 742 | |
| 743 | if (frag_count > MAX_BUFFERS_PER_CMD) { |
| 744 | printk("%s: %s netxen_nic_xmit_frame: frag_count (%d)" |
| 745 | "too large, can handle only %d frags\n", |
| 746 | netxen_nic_driver_name, netdev->name, |
| 747 | frag_count, MAX_BUFFERS_PER_CMD); |
| 748 | port->stats.txdropped++; |
| 749 | if ((++dropped_packet & 0xff) == 0xff) |
| 750 | printk("%s: %s droppped packets = %d\n", |
| 751 | netxen_nic_driver_name, netdev->name, |
| 752 | dropped_packet); |
| 753 | |
| 754 | return NETDEV_TX_OK; |
| 755 | } |
| 756 | |
| 757 | /* |
| 758 | * Everything is set up. Now, we just need to transmit it out. |
| 759 | * Note that we have to copy the contents of buffer over to |
| 760 | * right place. Later on, this can be optimized out by de-coupling the |
| 761 | * producer index from the buffer index. |
| 762 | */ |
| 763 | retry_getting_window: |
| 764 | spin_lock_bh(&adapter->tx_lock); |
| 765 | if (adapter->total_threads == MAX_XMIT_PRODUCERS) { |
| 766 | spin_unlock_bh(&adapter->tx_lock); |
| 767 | /* |
| 768 | * Yield CPU |
| 769 | */ |
| 770 | if (!in_atomic()) |
| 771 | schedule(); |
| 772 | else { |
| 773 | for (i = 0; i < 20; i++) |
| 774 | cpu_relax(); /*This a nop instr on i386 */ |
| 775 | } |
| 776 | goto retry_getting_window; |
| 777 | } |
| 778 | local_producer = adapter->cmd_producer; |
| 779 | /* There 4 fragments per descriptor */ |
| 780 | no_of_desc = (frag_count + 3) >> 2; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 781 | if (netdev->features & NETIF_F_TSO) { |
| 782 | if (skb_shinfo(skb)->gso_size > 0) { |
| 783 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 784 | no_of_desc++; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 785 | if (((skb->nh.iph)->ihl * sizeof(u32)) + |
| 786 | ((skb->h.th)->doff * sizeof(u32)) + |
| 787 | sizeof(struct ethhdr) > |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 788 | (sizeof(struct cmd_desc_type0) - 2)) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 789 | no_of_desc++; |
| 790 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 791 | } |
| 792 | } |
| 793 | k = adapter->cmd_producer; |
| 794 | max_tx_desc_count = adapter->max_tx_desc_count; |
| 795 | last_cmd_consumer = adapter->last_cmd_consumer; |
| 796 | if ((k + no_of_desc) >= |
| 797 | ((last_cmd_consumer <= k) ? last_cmd_consumer + max_tx_desc_count : |
| 798 | last_cmd_consumer)) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 799 | port->stats.nocmddescriptor++; |
| 800 | DPRINTK(ERR, "No command descriptors available," |
| 801 | " producer = %d, consumer = %d count=%llu," |
| 802 | " dropping packet\n", producer, |
| 803 | adapter->last_cmd_consumer, |
| 804 | port->stats.nocmddescriptor); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 805 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 806 | netif_stop_queue(netdev); |
| 807 | port->flags |= NETXEN_NETDEV_STATUS; |
| 808 | spin_unlock_bh(&adapter->tx_lock); |
| 809 | return NETDEV_TX_BUSY; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 810 | } |
| 811 | k = get_index_range(k, max_tx_desc_count, no_of_desc); |
| 812 | adapter->cmd_producer = k; |
| 813 | adapter->total_threads++; |
| 814 | adapter->num_threads++; |
| 815 | |
| 816 | spin_unlock_bh(&adapter->tx_lock); |
| 817 | /* Copy the descriptors into the hardware */ |
| 818 | producer = local_producer; |
| 819 | saved_producer = producer; |
| 820 | hwdesc = &hw->cmd_desc_head[producer]; |
| 821 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
| 822 | /* Take skb->data itself */ |
| 823 | pbuf = &adapter->cmd_buf_arr[producer]; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 824 | if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 825 | pbuf->mss = skb_shinfo(skb)->gso_size; |
| 826 | hwdesc->mss = skb_shinfo(skb)->gso_size; |
| 827 | } else { |
| 828 | pbuf->mss = 0; |
| 829 | hwdesc->mss = 0; |
| 830 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 831 | pbuf->total_length = skb->len; |
| 832 | pbuf->skb = skb; |
| 833 | pbuf->cmd = TX_ETHER_PKT; |
| 834 | pbuf->frag_count = frag_count; |
| 835 | pbuf->port = port->portnum; |
| 836 | buffrag = &pbuf->frag_array[0]; |
| 837 | buffrag->dma = pci_map_single(port->pdev, skb->data, first_seg_len, |
| 838 | PCI_DMA_TODEVICE); |
| 839 | buffrag->length = first_seg_len; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 840 | netxen_set_cmd_desc_totallength(hwdesc, skb->len); |
| 841 | netxen_set_cmd_desc_num_of_buff(hwdesc, frag_count); |
| 842 | netxen_set_cmd_desc_opcode(hwdesc, TX_ETHER_PKT); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 843 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 844 | netxen_set_cmd_desc_port(hwdesc, port->portnum); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 845 | hwdesc->buffer1_length = cpu_to_le16(first_seg_len); |
| 846 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); |
| 847 | |
| 848 | for (i = 1, k = 1; i < frag_count; i++, k++) { |
| 849 | struct skb_frag_struct *frag; |
| 850 | int len, temp_len; |
| 851 | unsigned long offset; |
| 852 | dma_addr_t temp_dma; |
| 853 | |
| 854 | /* move to next desc. if there is a need */ |
| 855 | if ((i & 0x3) == 0) { |
| 856 | k = 0; |
| 857 | producer = get_next_index(producer, |
| 858 | adapter->max_tx_desc_count); |
| 859 | hwdesc = &hw->cmd_desc_head[producer]; |
| 860 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
| 861 | } |
| 862 | frag = &skb_shinfo(skb)->frags[i - 1]; |
| 863 | len = frag->size; |
| 864 | offset = frag->page_offset; |
| 865 | |
| 866 | temp_len = len; |
| 867 | temp_dma = pci_map_page(port->pdev, frag->page, offset, |
| 868 | len, PCI_DMA_TODEVICE); |
| 869 | |
| 870 | buffrag++; |
| 871 | buffrag->dma = temp_dma; |
| 872 | buffrag->length = temp_len; |
| 873 | |
| 874 | DPRINTK(INFO, "for loop. i=%d k=%d\n", i, k); |
| 875 | switch (k) { |
| 876 | case 0: |
| 877 | hwdesc->buffer1_length = cpu_to_le16(temp_len); |
| 878 | hwdesc->addr_buffer1 = cpu_to_le64(temp_dma); |
| 879 | break; |
| 880 | case 1: |
| 881 | hwdesc->buffer2_length = cpu_to_le16(temp_len); |
| 882 | hwdesc->addr_buffer2 = cpu_to_le64(temp_dma); |
| 883 | break; |
| 884 | case 2: |
| 885 | hwdesc->buffer3_length = cpu_to_le16(temp_len); |
| 886 | hwdesc->addr_buffer3 = cpu_to_le64(temp_dma); |
| 887 | break; |
| 888 | case 3: |
| 889 | hwdesc->buffer4_length = temp_len; |
| 890 | hwdesc->addr_buffer4 = cpu_to_le64(temp_dma); |
| 891 | break; |
| 892 | } |
| 893 | frag++; |
| 894 | } |
| 895 | producer = get_next_index(producer, adapter->max_tx_desc_count); |
| 896 | |
| 897 | /* might change opcode to TX_TCP_LSO */ |
| 898 | netxen_tso_check(adapter, &hw->cmd_desc_head[saved_producer], skb); |
| 899 | |
| 900 | /* For LSO, we need to copy the MAC/IP/TCP headers into |
| 901 | * the descriptor ring |
| 902 | */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 903 | if (netxen_get_cmd_desc_opcode(&hw->cmd_desc_head[saved_producer]) |
| 904 | == TX_TCP_LSO) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 905 | int hdr_len, first_hdr_len, more_hdr; |
| 906 | hdr_len = hw->cmd_desc_head[saved_producer].total_hdr_length; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 907 | if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) { |
| 908 | first_hdr_len = sizeof(struct cmd_desc_type0) - 2; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 909 | more_hdr = 1; |
| 910 | } else { |
| 911 | first_hdr_len = hdr_len; |
| 912 | more_hdr = 0; |
| 913 | } |
| 914 | /* copy the MAC/IP/TCP headers to the cmd descriptor list */ |
| 915 | hwdesc = &hw->cmd_desc_head[producer]; |
| 916 | |
| 917 | /* copy the first 64 bytes */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 918 | memcpy(((void *)hwdesc) + 2, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 919 | (void *)(skb->data), first_hdr_len); |
| 920 | producer = get_next_index(producer, max_tx_desc_count); |
| 921 | |
| 922 | if (more_hdr) { |
| 923 | hwdesc = &hw->cmd_desc_head[producer]; |
| 924 | /* copy the next 64 bytes - should be enough except |
| 925 | * for pathological case |
| 926 | */ |
| 927 | memcpy((void *)hwdesc, (void *)(skb->data) + |
| 928 | first_hdr_len, hdr_len - first_hdr_len); |
| 929 | producer = get_next_index(producer, max_tx_desc_count); |
| 930 | } |
| 931 | } |
| 932 | spin_lock_bh(&adapter->tx_lock); |
| 933 | port->stats.txbytes += |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 934 | netxen_get_cmd_desc_totallength(&hw->cmd_desc_head[saved_producer]); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 935 | /* Code to update the adapter considering how many producer threads |
| 936 | are currently working */ |
| 937 | if ((--adapter->num_threads) == 0) { |
| 938 | /* This is the last thread */ |
| 939 | u32 crb_producer = adapter->cmd_producer; |
| 940 | writel(crb_producer, |
| 941 | NETXEN_CRB_NORMALIZE(adapter, CRB_CMD_PRODUCER_OFFSET)); |
| 942 | wmb(); |
| 943 | adapter->total_threads = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | port->stats.xmitfinished++; |
| 947 | spin_unlock_bh(&adapter->tx_lock); |
| 948 | |
| 949 | netdev->trans_start = jiffies; |
| 950 | |
| 951 | DPRINTK(INFO, "wrote CMD producer %x to phantom\n", producer); |
| 952 | |
| 953 | DPRINTK(INFO, "Done. Send\n"); |
| 954 | return NETDEV_TX_OK; |
| 955 | } |
| 956 | |
| 957 | static void netxen_watchdog(unsigned long v) |
| 958 | { |
| 959 | struct netxen_adapter *adapter = (struct netxen_adapter *)v; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 960 | if (adapter != g_adapter) { |
| 961 | printk("%s: ***BUG*** adapter[%p] != g_adapter[%p]\n", |
| 962 | __FUNCTION__, adapter, g_adapter); |
| 963 | return; |
| 964 | } |
| 965 | |
| 966 | SCHEDULE_WORK(&adapter->watchdog_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | static void netxen_tx_timeout(struct net_device *netdev) |
| 970 | { |
| 971 | struct netxen_port *port = (struct netxen_port *)netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 972 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 973 | SCHEDULE_WORK(port->adapter->tx_timeout_task + port->portnum); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | static void netxen_tx_timeout_task(struct net_device *netdev) |
| 977 | { |
| 978 | struct netxen_port *port = (struct netxen_port *)netdev_priv(netdev); |
| 979 | unsigned long flags; |
| 980 | |
| 981 | printk(KERN_ERR "%s %s: transmit timeout, resetting.\n", |
| 982 | netxen_nic_driver_name, netdev->name); |
| 983 | |
| 984 | spin_lock_irqsave(&port->adapter->lock, flags); |
| 985 | netxen_nic_close(netdev); |
| 986 | netxen_nic_open(netdev); |
| 987 | spin_unlock_irqrestore(&port->adapter->lock, flags); |
| 988 | netdev->trans_start = jiffies; |
| 989 | netif_wake_queue(netdev); |
| 990 | } |
| 991 | |
| 992 | static int |
| 993 | netxen_handle_int(struct netxen_adapter *adapter, struct net_device *netdev) |
| 994 | { |
| 995 | u32 ret = 0; |
| 996 | |
| 997 | DPRINTK(INFO, "Entered handle ISR\n"); |
| 998 | |
| 999 | adapter->stats.ints++; |
| 1000 | |
| 1001 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { |
| 1002 | int count = 0; |
| 1003 | u32 mask; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 1004 | mask = readl(pci_base_offset(adapter, ISR_INT_VECTOR)); |
| 1005 | if ((mask & 0x80) == 0) { |
| 1006 | /* not our interrupt */ |
| 1007 | return ret; |
| 1008 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1009 | netxen_nic_disable_int(adapter); |
| 1010 | /* Window = 0 or 1 */ |
| 1011 | do { |
Amit S. Kale | 71bd787 | 2006-12-01 05:36:22 -0800 | [diff] [blame] | 1012 | writel(0xffffffff, PCI_OFFSET_SECOND_RANGE(adapter, |
| 1013 | ISR_INT_TARGET_STATUS)); |
| 1014 | mask = readl(pci_base_offset(adapter, ISR_INT_VECTOR)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1015 | } while (((mask & 0x80) != 0) && (++count < 32)); |
| 1016 | if ((mask & 0x80) != 0) |
| 1017 | printk("Could not disable interrupt completely\n"); |
| 1018 | |
| 1019 | } |
| 1020 | adapter->stats.hostints++; |
| 1021 | |
| 1022 | if (netxen_nic_rx_has_work(adapter) || netxen_nic_tx_has_work(adapter)) { |
| 1023 | if (netif_rx_schedule_prep(netdev)) { |
| 1024 | /* |
| 1025 | * Interrupts are already disabled. |
| 1026 | */ |
| 1027 | __netif_rx_schedule(netdev); |
| 1028 | } else { |
| 1029 | static unsigned int intcount = 0; |
| 1030 | if ((++intcount & 0xfff) == 0xfff) |
| 1031 | printk(KERN_ERR |
| 1032 | "%s: %s interrupt %d while in poll\n", |
| 1033 | netxen_nic_driver_name, netdev->name, |
| 1034 | intcount); |
| 1035 | } |
| 1036 | ret = 1; |
| 1037 | } |
| 1038 | |
| 1039 | if (ret == 0) { |
| 1040 | netxen_nic_enable_int(adapter); |
| 1041 | } |
| 1042 | |
| 1043 | return ret; |
| 1044 | } |
| 1045 | |
| 1046 | /* |
| 1047 | * netxen_intr - Interrupt Handler |
| 1048 | * @irq: interrupt number |
| 1049 | * data points to adapter stucture (which may be handling more than 1 port |
| 1050 | */ |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1051 | irqreturn_t netxen_intr(int irq, void *data) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1052 | { |
| 1053 | struct netxen_adapter *adapter; |
| 1054 | struct netxen_port *port; |
| 1055 | struct net_device *netdev; |
| 1056 | int i; |
| 1057 | |
| 1058 | if (unlikely(!irq)) { |
| 1059 | return IRQ_NONE; /* Not our interrupt */ |
| 1060 | } |
| 1061 | |
| 1062 | adapter = (struct netxen_adapter *)data; |
| 1063 | for (i = 0; i < adapter->ahw.max_ports; i++) { |
| 1064 | port = adapter->port[i]; |
| 1065 | netdev = port->netdev; |
| 1066 | |
| 1067 | /* process our status queue (for all 4 ports) */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 1068 | if (netif_running(netdev)) { |
| 1069 | netxen_handle_int(adapter, netdev); |
| 1070 | break; |
| 1071 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | return IRQ_HANDLED; |
| 1075 | } |
| 1076 | |
| 1077 | static int netxen_nic_poll(struct net_device *netdev, int *budget) |
| 1078 | { |
| 1079 | struct netxen_port *port = (struct netxen_port *)netdev_priv(netdev); |
| 1080 | struct netxen_adapter *adapter = port->adapter; |
| 1081 | int work_to_do = min(*budget, netdev->quota); |
| 1082 | int done = 1; |
| 1083 | int ctx; |
| 1084 | int this_work_done; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1085 | int work_done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1086 | |
| 1087 | DPRINTK(INFO, "polling for %d descriptors\n", *budget); |
| 1088 | port->stats.polled++; |
| 1089 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1090 | work_done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1091 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
| 1092 | /* |
| 1093 | * Fairness issue. This will give undue weight to the |
| 1094 | * receive context 0. |
| 1095 | */ |
| 1096 | |
| 1097 | /* |
| 1098 | * To avoid starvation, we give each of our receivers, |
| 1099 | * a fraction of the quota. Sometimes, it might happen that we |
| 1100 | * have enough quota to process every packet, but since all the |
| 1101 | * packets are on one context, it gets only half of the quota, |
| 1102 | * and ends up not processing it. |
| 1103 | */ |
| 1104 | this_work_done = netxen_process_rcv_ring(adapter, ctx, |
| 1105 | work_to_do / |
| 1106 | MAX_RCV_CTX); |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1107 | work_done += this_work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1108 | } |
| 1109 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1110 | netdev->quota -= work_done; |
| 1111 | *budget -= work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1112 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 1113 | 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] | 1114 | done = 0; |
| 1115 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 1116 | if (netxen_process_cmd_ring((unsigned long)adapter) == 0) |
| 1117 | done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1118 | |
| 1119 | DPRINTK(INFO, "new work_done: %d work_to_do: %d\n", |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1120 | work_done, work_to_do); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1121 | if (done) { |
| 1122 | netif_rx_complete(netdev); |
| 1123 | netxen_nic_enable_int(adapter); |
| 1124 | } |
| 1125 | |
Amit S. Kale | edf9016 | 2006-11-29 08:58:11 -0800 | [diff] [blame] | 1126 | return !done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1130 | static void netxen_nic_poll_controller(struct net_device *netdev) |
| 1131 | { |
| 1132 | struct netxen_port *port = netdev_priv(netdev); |
| 1133 | struct netxen_adapter *adapter = port->adapter; |
| 1134 | disable_irq(adapter->irq); |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1135 | netxen_intr(adapter->irq, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1136 | enable_irq(adapter->irq); |
| 1137 | } |
| 1138 | #endif |
| 1139 | /* |
| 1140 | * netxen_nic_ioctl () We provide the tcl/phanmon support through these |
| 1141 | * ioctls. |
| 1142 | */ |
| 1143 | static int |
| 1144 | netxen_nic_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 1145 | { |
| 1146 | int err = 0; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1147 | unsigned long nr_bytes = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1148 | struct netxen_port *port = netdev_priv(netdev); |
| 1149 | struct netxen_adapter *adapter = port->adapter; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1150 | char dev_name[NETXEN_NIC_NAME_LEN]; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1151 | |
| 1152 | DPRINTK(INFO, "doing ioctl for %s\n", netdev->name); |
| 1153 | switch (cmd) { |
| 1154 | case NETXEN_NIC_CMD: |
| 1155 | err = netxen_nic_do_ioctl(adapter, (void *)ifr->ifr_data, port); |
| 1156 | break; |
| 1157 | |
| 1158 | case NETXEN_NIC_NAME: |
| 1159 | DPRINTK(INFO, "ioctl cmd for NetXen\n"); |
| 1160 | if (ifr->ifr_data) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1161 | sprintf(dev_name, "%s-%d", NETXEN_NIC_NAME_RSP, |
| 1162 | port->portnum); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 1163 | nr_bytes = |
| 1164 | copy_to_user((char __user *)ifr->ifr_data, dev_name, |
| 1165 | NETXEN_NIC_NAME_LEN); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1166 | if (nr_bytes) |
| 1167 | err = -EIO; |
| 1168 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1169 | } |
| 1170 | break; |
| 1171 | |
| 1172 | default: |
| 1173 | DPRINTK(INFO, "ioctl cmd %x not supported\n", cmd); |
| 1174 | err = -EOPNOTSUPP; |
| 1175 | break; |
| 1176 | } |
| 1177 | |
| 1178 | return err; |
| 1179 | } |
| 1180 | |
| 1181 | static struct pci_driver netxen_driver = { |
| 1182 | .name = netxen_nic_driver_name, |
| 1183 | .id_table = netxen_pci_tbl, |
| 1184 | .probe = netxen_nic_probe, |
| 1185 | .remove = __devexit_p(netxen_nic_remove) |
| 1186 | }; |
| 1187 | |
| 1188 | /* Driver Registration on NetXen card */ |
| 1189 | |
| 1190 | static int __init netxen_init_module(void) |
| 1191 | { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 1192 | if ((netxen_workq = create_singlethread_workqueue("netxen")) == 0) |
| 1193 | return -ENOMEM; |
| 1194 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1195 | return pci_module_init(&netxen_driver); |
| 1196 | } |
| 1197 | |
| 1198 | module_init(netxen_init_module); |
| 1199 | |
| 1200 | static void __exit netxen_exit_module(void) |
| 1201 | { |
| 1202 | /* |
| 1203 | * Wait for some time to allow the dma to drain, if any. |
| 1204 | */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame^] | 1205 | destroy_workqueue(netxen_workq); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1206 | pci_unregister_driver(&netxen_driver); |
| 1207 | } |
| 1208 | |
| 1209 | module_exit(netxen_exit_module); |