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 | * Source file for NIC routines to initialize the Phantom Hardware |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #include <linux/netdevice.h> |
| 35 | #include <linux/delay.h> |
| 36 | #include "netxen_nic.h" |
| 37 | #include "netxen_nic_hw.h" |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 38 | #include "netxen_nic_phan_reg.h" |
| 39 | |
| 40 | struct crb_addr_pair { |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 41 | u32 addr; |
| 42 | u32 data; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 43 | }; |
| 44 | |
Linsys Contractor Mithlesh Thukral | b58ecad | 2007-03-13 04:15:06 -0800 | [diff] [blame] | 45 | unsigned long last_schedule_time; |
| 46 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 47 | #define NETXEN_MAX_CRB_XFORM 60 |
| 48 | static unsigned int crb_addr_xform[NETXEN_MAX_CRB_XFORM]; |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 49 | #define NETXEN_ADDR_ERROR (0xffffffff) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 50 | |
| 51 | #define crb_addr_transform(name) \ |
| 52 | crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \ |
| 53 | NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20 |
| 54 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 55 | #define NETXEN_NIC_XDMA_RESET 0x8000ff |
| 56 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 57 | static inline void |
| 58 | netxen_nic_locked_write_reg(struct netxen_adapter *adapter, |
| 59 | unsigned long off, int *data) |
| 60 | { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 61 | void __iomem *addr = pci_base_offset(adapter, off); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 62 | writel(*data, addr); |
| 63 | } |
| 64 | |
| 65 | static void crb_addr_transform_setup(void) |
| 66 | { |
| 67 | crb_addr_transform(XDMA); |
| 68 | crb_addr_transform(TIMR); |
| 69 | crb_addr_transform(SRE); |
| 70 | crb_addr_transform(SQN3); |
| 71 | crb_addr_transform(SQN2); |
| 72 | crb_addr_transform(SQN1); |
| 73 | crb_addr_transform(SQN0); |
| 74 | crb_addr_transform(SQS3); |
| 75 | crb_addr_transform(SQS2); |
| 76 | crb_addr_transform(SQS1); |
| 77 | crb_addr_transform(SQS0); |
| 78 | crb_addr_transform(RPMX7); |
| 79 | crb_addr_transform(RPMX6); |
| 80 | crb_addr_transform(RPMX5); |
| 81 | crb_addr_transform(RPMX4); |
| 82 | crb_addr_transform(RPMX3); |
| 83 | crb_addr_transform(RPMX2); |
| 84 | crb_addr_transform(RPMX1); |
| 85 | crb_addr_transform(RPMX0); |
| 86 | crb_addr_transform(ROMUSB); |
| 87 | crb_addr_transform(SN); |
| 88 | crb_addr_transform(QMN); |
| 89 | crb_addr_transform(QMS); |
| 90 | crb_addr_transform(PGNI); |
| 91 | crb_addr_transform(PGND); |
| 92 | crb_addr_transform(PGN3); |
| 93 | crb_addr_transform(PGN2); |
| 94 | crb_addr_transform(PGN1); |
| 95 | crb_addr_transform(PGN0); |
| 96 | crb_addr_transform(PGSI); |
| 97 | crb_addr_transform(PGSD); |
| 98 | crb_addr_transform(PGS3); |
| 99 | crb_addr_transform(PGS2); |
| 100 | crb_addr_transform(PGS1); |
| 101 | crb_addr_transform(PGS0); |
| 102 | crb_addr_transform(PS); |
| 103 | crb_addr_transform(PH); |
| 104 | crb_addr_transform(NIU); |
| 105 | crb_addr_transform(I2Q); |
| 106 | crb_addr_transform(EG); |
| 107 | crb_addr_transform(MN); |
| 108 | crb_addr_transform(MS); |
| 109 | crb_addr_transform(CAS2); |
| 110 | crb_addr_transform(CAS1); |
| 111 | crb_addr_transform(CAS0); |
| 112 | crb_addr_transform(CAM); |
| 113 | crb_addr_transform(C2C1); |
| 114 | crb_addr_transform(C2C0); |
Amit S. Kale | 1fcca1a | 2007-02-05 07:35:26 -0800 | [diff] [blame] | 115 | crb_addr_transform(SMB); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | int netxen_init_firmware(struct netxen_adapter *adapter) |
| 119 | { |
| 120 | u32 state = 0, loops = 0, err = 0; |
| 121 | |
| 122 | /* Window 1 call */ |
| 123 | state = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); |
| 124 | |
| 125 | if (state == PHAN_INITIALIZE_ACK) |
| 126 | return 0; |
| 127 | |
| 128 | while (state != PHAN_INITIALIZE_COMPLETE && loops < 2000) { |
| 129 | udelay(100); |
| 130 | /* Window 1 call */ |
| 131 | state = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); |
| 132 | |
| 133 | loops++; |
| 134 | } |
| 135 | if (loops >= 2000) { |
| 136 | printk(KERN_ERR "Cmd Peg initialization not complete:%x.\n", |
| 137 | state); |
| 138 | err = -EIO; |
| 139 | return err; |
| 140 | } |
| 141 | /* Window 1 call */ |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 142 | writel(MPORT_MULTI_FUNCTION_MODE, |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 143 | NETXEN_CRB_NORMALIZE(adapter, CRB_MPORT_MODE)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 144 | writel(PHAN_INITIALIZE_ACK, |
| 145 | NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); |
| 146 | |
| 147 | return err; |
| 148 | } |
| 149 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 150 | #define NETXEN_ADDR_LIMIT 0xffffffffULL |
| 151 | |
| 152 | void *netxen_alloc(struct pci_dev *pdev, size_t sz, dma_addr_t * ptr, |
| 153 | struct pci_dev **used_dev) |
| 154 | { |
| 155 | void *addr; |
| 156 | |
| 157 | addr = pci_alloc_consistent(pdev, sz, ptr); |
| 158 | if ((unsigned long long)(*ptr) < NETXEN_ADDR_LIMIT) { |
| 159 | *used_dev = pdev; |
| 160 | return addr; |
| 161 | } |
| 162 | pci_free_consistent(pdev, sz, addr, *ptr); |
| 163 | addr = pci_alloc_consistent(NULL, sz, ptr); |
| 164 | *used_dev = NULL; |
| 165 | return addr; |
| 166 | } |
| 167 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 168 | void netxen_initialize_adapter_sw(struct netxen_adapter *adapter) |
| 169 | { |
| 170 | int ctxid, ring; |
| 171 | u32 i; |
| 172 | u32 num_rx_bufs = 0; |
| 173 | struct netxen_rcv_desc_ctx *rcv_desc; |
| 174 | |
| 175 | DPRINTK(INFO, "initializing some queues: %p\n", adapter); |
| 176 | for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) { |
| 177 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 178 | struct netxen_rx_buffer *rx_buf; |
| 179 | rcv_desc = &adapter->recv_ctx[ctxid].rcv_desc[ring]; |
| 180 | rcv_desc->rcv_free = rcv_desc->max_rx_desc_count; |
| 181 | rcv_desc->begin_alloc = 0; |
| 182 | rx_buf = rcv_desc->rx_buf_arr; |
| 183 | num_rx_bufs = rcv_desc->max_rx_desc_count; |
| 184 | /* |
| 185 | * Now go through all of them, set reference handles |
| 186 | * and put them in the queues. |
| 187 | */ |
| 188 | for (i = 0; i < num_rx_bufs; i++) { |
| 189 | rx_buf->ref_handle = i; |
| 190 | rx_buf->state = NETXEN_BUFFER_FREE; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 191 | DPRINTK(INFO, "Rx buf:ctx%d i(%d) rx_buf:" |
| 192 | "%p\n", ctxid, i, rx_buf); |
| 193 | rx_buf++; |
| 194 | } |
| 195 | } |
| 196 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | void netxen_initialize_adapter_hw(struct netxen_adapter *adapter) |
| 200 | { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 201 | int ports = 0; |
| 202 | struct netxen_board_info *board_info = &(adapter->ahw.boardcfg); |
| 203 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 204 | if (netxen_nic_get_board_info(adapter) != 0) |
| 205 | printk("%s: Error getting board config info.\n", |
| 206 | netxen_nic_driver_name); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 207 | get_brd_port_by_type(board_info->board_type, &ports); |
| 208 | if (ports == 0) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 209 | printk(KERN_ERR "%s: Unknown board type\n", |
| 210 | netxen_nic_driver_name); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 211 | adapter->ahw.max_ports = ports; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | void netxen_initialize_adapter_ops(struct netxen_adapter *adapter) |
| 215 | { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 216 | switch (adapter->ahw.board_type) { |
| 217 | case NETXEN_NIC_GBE: |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 218 | adapter->enable_phy_interrupts = |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 219 | netxen_niu_gbe_enable_phy_interrupts; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 220 | adapter->disable_phy_interrupts = |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 221 | netxen_niu_gbe_disable_phy_interrupts; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 222 | adapter->handle_phy_intr = netxen_nic_gbe_handle_phy_intr; |
| 223 | adapter->macaddr_set = netxen_niu_macaddr_set; |
| 224 | adapter->set_mtu = netxen_nic_set_mtu_gb; |
| 225 | adapter->set_promisc = netxen_niu_set_promiscuous_mode; |
| 226 | adapter->unset_promisc = netxen_niu_set_promiscuous_mode; |
| 227 | adapter->phy_read = netxen_niu_gbe_phy_read; |
| 228 | adapter->phy_write = netxen_niu_gbe_phy_write; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 229 | adapter->init_niu = netxen_nic_init_niu_gb; |
| 230 | adapter->stop_port = netxen_niu_disable_gbe_port; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 231 | break; |
| 232 | |
| 233 | case NETXEN_NIC_XGBE: |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 234 | adapter->enable_phy_interrupts = |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 235 | netxen_niu_xgbe_enable_phy_interrupts; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 236 | adapter->disable_phy_interrupts = |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 237 | netxen_niu_xgbe_disable_phy_interrupts; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 238 | adapter->handle_phy_intr = netxen_nic_xgbe_handle_phy_intr; |
| 239 | adapter->macaddr_set = netxen_niu_xg_macaddr_set; |
| 240 | adapter->set_mtu = netxen_nic_set_mtu_xgb; |
| 241 | adapter->init_port = netxen_niu_xg_init_port; |
| 242 | adapter->set_promisc = netxen_niu_xg_set_promiscuous_mode; |
| 243 | adapter->unset_promisc = netxen_niu_xg_set_promiscuous_mode; |
| 244 | adapter->stop_port = netxen_niu_disable_xg_port; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 245 | break; |
| 246 | |
| 247 | default: |
| 248 | break; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | /* |
| 253 | * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB |
| 254 | * address to external PCI CRB address. |
| 255 | */ |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 256 | u32 netxen_decode_crb_addr(u32 addr) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 257 | { |
| 258 | int i; |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 259 | u32 base_addr, offset, pci_base; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 260 | |
| 261 | crb_addr_transform_setup(); |
| 262 | |
| 263 | pci_base = NETXEN_ADDR_ERROR; |
| 264 | base_addr = addr & 0xfff00000; |
| 265 | offset = addr & 0x000fffff; |
| 266 | |
| 267 | for (i = 0; i < NETXEN_MAX_CRB_XFORM; i++) { |
| 268 | if (crb_addr_xform[i] == base_addr) { |
| 269 | pci_base = i << 20; |
| 270 | break; |
| 271 | } |
| 272 | } |
| 273 | if (pci_base == NETXEN_ADDR_ERROR) |
| 274 | return pci_base; |
| 275 | else |
| 276 | return (pci_base + offset); |
| 277 | } |
| 278 | |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 279 | static long rom_max_timeout = 100; |
| 280 | static long rom_lock_timeout = 10000; |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 281 | static long rom_write_timeout = 700; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 282 | |
| 283 | static inline int rom_lock(struct netxen_adapter *adapter) |
| 284 | { |
| 285 | int iter; |
| 286 | u32 done = 0; |
| 287 | int timeout = 0; |
| 288 | |
| 289 | while (!done) { |
| 290 | /* acquire semaphore2 from PCI HW block */ |
| 291 | netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(PCIE_SEM2_LOCK), |
| 292 | &done); |
| 293 | if (done == 1) |
| 294 | break; |
| 295 | if (timeout >= rom_lock_timeout) |
| 296 | return -EIO; |
| 297 | |
| 298 | timeout++; |
| 299 | /* |
| 300 | * Yield CPU |
| 301 | */ |
| 302 | if (!in_atomic()) |
| 303 | schedule(); |
| 304 | else { |
| 305 | for (iter = 0; iter < 20; iter++) |
| 306 | cpu_relax(); /*This a nop instr on i386 */ |
| 307 | } |
| 308 | } |
| 309 | netxen_nic_reg_write(adapter, NETXEN_ROM_LOCK_ID, ROM_LOCK_DRIVER); |
| 310 | return 0; |
| 311 | } |
| 312 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 313 | int netxen_wait_rom_done(struct netxen_adapter *adapter) |
| 314 | { |
| 315 | long timeout = 0; |
| 316 | long done = 0; |
| 317 | |
| 318 | while (done == 0) { |
| 319 | done = netxen_nic_reg_read(adapter, NETXEN_ROMUSB_GLB_STATUS); |
| 320 | done &= 2; |
| 321 | timeout++; |
| 322 | if (timeout >= rom_max_timeout) { |
| 323 | printk("Timeout reached waiting for rom done"); |
| 324 | return -EIO; |
| 325 | } |
| 326 | } |
| 327 | return 0; |
| 328 | } |
| 329 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 330 | static inline int netxen_rom_wren(struct netxen_adapter *adapter) |
| 331 | { |
| 332 | /* Set write enable latch in ROM status register */ |
| 333 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); |
| 334 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, |
| 335 | M25P_INSTR_WREN); |
| 336 | if (netxen_wait_rom_done(adapter)) { |
| 337 | return -1; |
| 338 | } |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | static inline unsigned int netxen_rdcrbreg(struct netxen_adapter *adapter, |
| 343 | unsigned int addr) |
| 344 | { |
| 345 | unsigned int data = 0xdeaddead; |
| 346 | data = netxen_nic_reg_read(adapter, addr); |
| 347 | return data; |
| 348 | } |
| 349 | |
| 350 | static inline int netxen_do_rom_rdsr(struct netxen_adapter *adapter) |
| 351 | { |
| 352 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, |
| 353 | M25P_INSTR_RDSR); |
| 354 | if (netxen_wait_rom_done(adapter)) { |
| 355 | return -1; |
| 356 | } |
| 357 | return netxen_rdcrbreg(adapter, NETXEN_ROMUSB_ROM_RDATA); |
| 358 | } |
| 359 | |
| 360 | static inline void netxen_rom_unlock(struct netxen_adapter *adapter) |
| 361 | { |
| 362 | u32 val; |
| 363 | |
| 364 | /* release semaphore2 */ |
| 365 | netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(PCIE_SEM2_UNLOCK), &val); |
| 366 | |
| 367 | } |
| 368 | |
| 369 | int netxen_rom_wip_poll(struct netxen_adapter *adapter) |
| 370 | { |
| 371 | long timeout = 0; |
| 372 | long wip = 1; |
| 373 | int val; |
| 374 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); |
| 375 | while (wip != 0) { |
| 376 | val = netxen_do_rom_rdsr(adapter); |
| 377 | wip = val & 1; |
| 378 | timeout++; |
| 379 | if (timeout > rom_max_timeout) { |
| 380 | return -1; |
| 381 | } |
| 382 | } |
| 383 | return 0; |
| 384 | } |
| 385 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 386 | static inline int do_rom_fast_write(struct netxen_adapter *adapter, int addr, |
| 387 | int data) |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 388 | { |
| 389 | if (netxen_rom_wren(adapter)) { |
| 390 | return -1; |
| 391 | } |
| 392 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_WDATA, data); |
| 393 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr); |
| 394 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3); |
| 395 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, |
| 396 | M25P_INSTR_PP); |
| 397 | if (netxen_wait_rom_done(adapter)) { |
| 398 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); |
| 399 | return -1; |
| 400 | } |
| 401 | |
| 402 | return netxen_rom_wip_poll(adapter); |
| 403 | } |
| 404 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 405 | static inline int |
| 406 | do_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp) |
| 407 | { |
Linsys Contractor Mithlesh Thukral | b58ecad | 2007-03-13 04:15:06 -0800 | [diff] [blame] | 408 | if (jiffies > (last_schedule_time + (8 * HZ))) { |
| 409 | last_schedule_time = jiffies; |
| 410 | schedule(); |
| 411 | } |
| 412 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 413 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr); |
| 414 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3); |
Linsys Contractor Mithlesh Thukral | b58ecad | 2007-03-13 04:15:06 -0800 | [diff] [blame] | 415 | udelay(100); /* prevent bursting on CRB */ |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 416 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); |
| 417 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, 0xb); |
| 418 | if (netxen_wait_rom_done(adapter)) { |
| 419 | printk("Error waiting for rom done\n"); |
| 420 | return -EIO; |
| 421 | } |
| 422 | /* reset abyte_cnt and dummy_byte_cnt */ |
| 423 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); |
Linsys Contractor Mithlesh Thukral | b58ecad | 2007-03-13 04:15:06 -0800 | [diff] [blame] | 424 | udelay(100); /* prevent bursting on CRB */ |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 425 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); |
| 426 | |
| 427 | *valp = netxen_nic_reg_read(adapter, NETXEN_ROMUSB_ROM_RDATA); |
| 428 | return 0; |
| 429 | } |
| 430 | |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 431 | static inline int |
| 432 | do_rom_fast_read_words(struct netxen_adapter *adapter, int addr, |
| 433 | u8 *bytes, size_t size) |
| 434 | { |
| 435 | int addridx; |
| 436 | int ret = 0; |
| 437 | |
| 438 | for (addridx = addr; addridx < (addr + size); addridx += 4) { |
| 439 | ret = do_rom_fast_read(adapter, addridx, (int *)bytes); |
| 440 | if (ret != 0) |
| 441 | break; |
Mithlesh Thukral | 6d1495f | 2007-04-20 07:56:42 -0700 | [diff] [blame] | 442 | *(int *)bytes = cpu_to_le32(*(int *)bytes); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 443 | bytes += 4; |
| 444 | } |
| 445 | |
| 446 | return ret; |
| 447 | } |
| 448 | |
| 449 | int |
| 450 | netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr, |
| 451 | u8 *bytes, size_t size) |
| 452 | { |
| 453 | int ret; |
| 454 | |
| 455 | ret = rom_lock(adapter); |
| 456 | if (ret < 0) |
| 457 | return ret; |
| 458 | |
| 459 | ret = do_rom_fast_read_words(adapter, addr, bytes, size); |
| 460 | |
| 461 | netxen_rom_unlock(adapter); |
| 462 | return ret; |
| 463 | } |
| 464 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 465 | int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp) |
| 466 | { |
| 467 | int ret; |
| 468 | |
| 469 | if (rom_lock(adapter) != 0) |
| 470 | return -EIO; |
| 471 | |
| 472 | ret = do_rom_fast_read(adapter, addr, valp); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 473 | netxen_rom_unlock(adapter); |
| 474 | return ret; |
| 475 | } |
| 476 | |
| 477 | int netxen_rom_fast_write(struct netxen_adapter *adapter, int addr, int data) |
| 478 | { |
| 479 | int ret = 0; |
| 480 | |
| 481 | if (rom_lock(adapter) != 0) { |
| 482 | return -1; |
| 483 | } |
| 484 | ret = do_rom_fast_write(adapter, addr, data); |
| 485 | netxen_rom_unlock(adapter); |
| 486 | return ret; |
| 487 | } |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 488 | |
| 489 | static inline int do_rom_fast_write_words(struct netxen_adapter *adapter, |
| 490 | int addr, u8 *bytes, size_t size) |
| 491 | { |
| 492 | int addridx = addr; |
| 493 | int ret = 0; |
| 494 | |
| 495 | while (addridx < (addr + size)) { |
| 496 | int last_attempt = 0; |
| 497 | int timeout = 0; |
| 498 | int data; |
| 499 | |
Mithlesh Thukral | 6d1495f | 2007-04-20 07:56:42 -0700 | [diff] [blame] | 500 | data = le32_to_cpu((*(u32*)bytes)); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 501 | ret = do_rom_fast_write(adapter, addridx, data); |
| 502 | if (ret < 0) |
| 503 | return ret; |
| 504 | |
| 505 | while(1) { |
| 506 | int data1; |
| 507 | |
Stephen Hemminger | f8dfdd5 | 2007-02-26 14:51:56 -0800 | [diff] [blame] | 508 | ret = do_rom_fast_read(adapter, addridx, &data1); |
| 509 | if (ret < 0) |
| 510 | return ret; |
| 511 | |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 512 | if (data1 == data) |
| 513 | break; |
| 514 | |
| 515 | if (timeout++ >= rom_write_timeout) { |
| 516 | if (last_attempt++ < 4) { |
| 517 | ret = do_rom_fast_write(adapter, |
| 518 | addridx, data); |
| 519 | if (ret < 0) |
| 520 | return ret; |
| 521 | } |
| 522 | else { |
| 523 | printk(KERN_INFO "Data write did not " |
| 524 | "succeed at address 0x%x\n", addridx); |
| 525 | break; |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | bytes += 4; |
| 531 | addridx += 4; |
| 532 | } |
| 533 | |
| 534 | return ret; |
| 535 | } |
| 536 | |
| 537 | int netxen_rom_fast_write_words(struct netxen_adapter *adapter, int addr, |
| 538 | u8 *bytes, size_t size) |
| 539 | { |
| 540 | int ret = 0; |
| 541 | |
| 542 | ret = rom_lock(adapter); |
| 543 | if (ret < 0) |
| 544 | return ret; |
| 545 | |
| 546 | ret = do_rom_fast_write_words(adapter, addr, bytes, size); |
| 547 | netxen_rom_unlock(adapter); |
| 548 | |
| 549 | return ret; |
| 550 | } |
| 551 | |
| 552 | int netxen_rom_wrsr(struct netxen_adapter *adapter, int data) |
| 553 | { |
| 554 | int ret; |
| 555 | |
| 556 | ret = netxen_rom_wren(adapter); |
| 557 | if (ret < 0) |
| 558 | return ret; |
| 559 | |
| 560 | netxen_crb_writelit_adapter(adapter, NETXEN_ROMUSB_ROM_WDATA, data); |
| 561 | netxen_crb_writelit_adapter(adapter, |
| 562 | NETXEN_ROMUSB_ROM_INSTR_OPCODE, 0x1); |
| 563 | |
| 564 | ret = netxen_wait_rom_done(adapter); |
| 565 | if (ret < 0) |
| 566 | return ret; |
| 567 | |
| 568 | return netxen_rom_wip_poll(adapter); |
| 569 | } |
| 570 | |
| 571 | int netxen_rom_rdsr(struct netxen_adapter *adapter) |
| 572 | { |
| 573 | int ret; |
| 574 | |
| 575 | ret = rom_lock(adapter); |
| 576 | if (ret < 0) |
| 577 | return ret; |
| 578 | |
| 579 | ret = netxen_do_rom_rdsr(adapter); |
| 580 | netxen_rom_unlock(adapter); |
| 581 | return ret; |
| 582 | } |
| 583 | |
| 584 | int netxen_backup_crbinit(struct netxen_adapter *adapter) |
| 585 | { |
| 586 | int ret = FLASH_SUCCESS; |
| 587 | int val; |
Mithlesh Thukral | 0d04761 | 2007-06-07 04:36:36 -0700 | [diff] [blame] | 588 | char *buffer = kmalloc(NETXEN_FLASH_SECTOR_SIZE, GFP_KERNEL); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 589 | |
| 590 | if (!buffer) |
| 591 | return -ENOMEM; |
| 592 | /* unlock sector 63 */ |
| 593 | val = netxen_rom_rdsr(adapter); |
| 594 | val = val & 0xe3; |
| 595 | ret = netxen_rom_wrsr(adapter, val); |
| 596 | if (ret != FLASH_SUCCESS) |
| 597 | goto out_kfree; |
| 598 | |
| 599 | ret = netxen_rom_wip_poll(adapter); |
| 600 | if (ret != FLASH_SUCCESS) |
| 601 | goto out_kfree; |
| 602 | |
| 603 | /* copy sector 0 to sector 63 */ |
Mithlesh Thukral | 0d04761 | 2007-06-07 04:36:36 -0700 | [diff] [blame] | 604 | ret = netxen_rom_fast_read_words(adapter, NETXEN_CRBINIT_START, |
| 605 | buffer, NETXEN_FLASH_SECTOR_SIZE); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 606 | if (ret != FLASH_SUCCESS) |
| 607 | goto out_kfree; |
| 608 | |
Mithlesh Thukral | 0d04761 | 2007-06-07 04:36:36 -0700 | [diff] [blame] | 609 | ret = netxen_rom_fast_write_words(adapter, NETXEN_FIXED_START, |
| 610 | buffer, NETXEN_FLASH_SECTOR_SIZE); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 611 | if (ret != FLASH_SUCCESS) |
| 612 | goto out_kfree; |
| 613 | |
| 614 | /* lock sector 63 */ |
| 615 | val = netxen_rom_rdsr(adapter); |
| 616 | if (!(val & 0x8)) { |
| 617 | val |= (0x1 << 2); |
| 618 | /* lock sector 63 */ |
| 619 | if (netxen_rom_wrsr(adapter, val) == 0) { |
| 620 | ret = netxen_rom_wip_poll(adapter); |
| 621 | if (ret != FLASH_SUCCESS) |
| 622 | goto out_kfree; |
| 623 | |
| 624 | /* lock SR writes */ |
| 625 | ret = netxen_rom_wip_poll(adapter); |
| 626 | if (ret != FLASH_SUCCESS) |
| 627 | goto out_kfree; |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | out_kfree: |
| 632 | kfree(buffer); |
| 633 | return ret; |
| 634 | } |
| 635 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 636 | int netxen_do_rom_se(struct netxen_adapter *adapter, int addr) |
| 637 | { |
| 638 | netxen_rom_wren(adapter); |
| 639 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr); |
| 640 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3); |
| 641 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, |
| 642 | M25P_INSTR_SE); |
| 643 | if (netxen_wait_rom_done(adapter)) { |
| 644 | netxen_nic_reg_write(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); |
| 645 | return -1; |
| 646 | } |
| 647 | return netxen_rom_wip_poll(adapter); |
| 648 | } |
| 649 | |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 650 | void check_erased_flash(struct netxen_adapter *adapter, int addr) |
| 651 | { |
| 652 | int i; |
| 653 | int val; |
| 654 | int count = 0, erased_errors = 0; |
| 655 | int range; |
| 656 | |
Mithlesh Thukral | 0d04761 | 2007-06-07 04:36:36 -0700 | [diff] [blame] | 657 | range = (addr == NETXEN_USER_START) ? |
| 658 | NETXEN_FIXED_START : addr + NETXEN_FLASH_SECTOR_SIZE; |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 659 | |
| 660 | for (i = addr; i < range; i += 4) { |
| 661 | netxen_rom_fast_read(adapter, i, &val); |
| 662 | if (val != 0xffffffff) |
| 663 | erased_errors++; |
| 664 | count++; |
| 665 | } |
| 666 | |
| 667 | if (erased_errors) |
| 668 | printk(KERN_INFO "0x%x out of 0x%x words fail to be erased " |
| 669 | "for sector address: %x\n", erased_errors, count, addr); |
| 670 | } |
| 671 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 672 | int netxen_rom_se(struct netxen_adapter *adapter, int addr) |
| 673 | { |
| 674 | int ret = 0; |
| 675 | if (rom_lock(adapter) != 0) { |
| 676 | return -1; |
| 677 | } |
| 678 | ret = netxen_do_rom_se(adapter, addr); |
| 679 | netxen_rom_unlock(adapter); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 680 | msleep(30); |
| 681 | check_erased_flash(adapter, addr); |
| 682 | |
| 683 | return ret; |
| 684 | } |
| 685 | |
| 686 | int |
| 687 | netxen_flash_erase_sections(struct netxen_adapter *adapter, int start, int end) |
| 688 | { |
| 689 | int ret = FLASH_SUCCESS; |
| 690 | int i; |
| 691 | |
| 692 | for (i = start; i < end; i++) { |
Mithlesh Thukral | 0d04761 | 2007-06-07 04:36:36 -0700 | [diff] [blame] | 693 | ret = netxen_rom_se(adapter, i * NETXEN_FLASH_SECTOR_SIZE); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 694 | if (ret) |
| 695 | break; |
| 696 | ret = netxen_rom_wip_poll(adapter); |
| 697 | if (ret < 0) |
| 698 | return ret; |
| 699 | } |
| 700 | |
| 701 | return ret; |
| 702 | } |
| 703 | |
| 704 | int |
| 705 | netxen_flash_erase_secondary(struct netxen_adapter *adapter) |
| 706 | { |
| 707 | int ret = FLASH_SUCCESS; |
| 708 | int start, end; |
| 709 | |
Mithlesh Thukral | 0d04761 | 2007-06-07 04:36:36 -0700 | [diff] [blame] | 710 | start = NETXEN_SECONDARY_START / NETXEN_FLASH_SECTOR_SIZE; |
| 711 | end = NETXEN_USER_START / NETXEN_FLASH_SECTOR_SIZE; |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 712 | ret = netxen_flash_erase_sections(adapter, start, end); |
| 713 | |
| 714 | return ret; |
| 715 | } |
| 716 | |
| 717 | int |
| 718 | netxen_flash_erase_primary(struct netxen_adapter *adapter) |
| 719 | { |
| 720 | int ret = FLASH_SUCCESS; |
| 721 | int start, end; |
| 722 | |
Mithlesh Thukral | 0d04761 | 2007-06-07 04:36:36 -0700 | [diff] [blame] | 723 | start = NETXEN_PRIMARY_START / NETXEN_FLASH_SECTOR_SIZE; |
| 724 | end = NETXEN_SECONDARY_START / NETXEN_FLASH_SECTOR_SIZE; |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 725 | ret = netxen_flash_erase_sections(adapter, start, end); |
| 726 | |
| 727 | return ret; |
| 728 | } |
| 729 | |
Amit S. Kale | e45d9ab | 2007-02-09 05:49:08 -0800 | [diff] [blame] | 730 | void netxen_halt_pegs(struct netxen_adapter *adapter) |
| 731 | { |
| 732 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_0 + 0x3c, 1); |
| 733 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_1 + 0x3c, 1); |
| 734 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_2 + 0x3c, 1); |
| 735 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_3 + 0x3c, 1); |
| 736 | } |
| 737 | |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 738 | int netxen_flash_unlock(struct netxen_adapter *adapter) |
| 739 | { |
| 740 | int ret = 0; |
| 741 | |
| 742 | ret = netxen_rom_wrsr(adapter, 0); |
| 743 | if (ret < 0) |
| 744 | return ret; |
| 745 | |
| 746 | ret = netxen_rom_wren(adapter); |
| 747 | if (ret < 0) |
| 748 | return ret; |
| 749 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 750 | return ret; |
| 751 | } |
| 752 | |
| 753 | #define NETXEN_BOARDTYPE 0x4008 |
| 754 | #define NETXEN_BOARDNUM 0x400c |
| 755 | #define NETXEN_CHIPNUM 0x4010 |
| 756 | #define NETXEN_ROMBUS_RESET 0xFFFFFFFF |
| 757 | #define NETXEN_ROM_FIRST_BARRIER 0x800000000ULL |
| 758 | #define NETXEN_ROM_FOUND_INIT 0x400 |
| 759 | |
| 760 | int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose) |
| 761 | { |
| 762 | int addr, val, status; |
| 763 | int n, i; |
| 764 | int init_delay = 0; |
| 765 | struct crb_addr_pair *buf; |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 766 | u32 off; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 767 | |
| 768 | /* resetall */ |
| 769 | status = netxen_nic_get_board_info(adapter); |
| 770 | if (status) |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 771 | printk("%s: netxen_pinit_from_rom: Error getting board info\n", |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 772 | netxen_nic_driver_name); |
| 773 | |
| 774 | netxen_crb_writelit_adapter(adapter, NETXEN_ROMUSB_GLB_SW_RESET, |
| 775 | NETXEN_ROMBUS_RESET); |
| 776 | |
| 777 | if (verbose) { |
| 778 | int val; |
| 779 | if (netxen_rom_fast_read(adapter, NETXEN_BOARDTYPE, &val) == 0) |
| 780 | printk("P2 ROM board type: 0x%08x\n", val); |
| 781 | else |
| 782 | printk("Could not read board type\n"); |
| 783 | if (netxen_rom_fast_read(adapter, NETXEN_BOARDNUM, &val) == 0) |
| 784 | printk("P2 ROM board num: 0x%08x\n", val); |
| 785 | else |
| 786 | printk("Could not read board number\n"); |
| 787 | if (netxen_rom_fast_read(adapter, NETXEN_CHIPNUM, &val) == 0) |
| 788 | printk("P2 ROM chip num: 0x%08x\n", val); |
| 789 | else |
| 790 | printk("Could not read chip number\n"); |
| 791 | } |
| 792 | |
| 793 | if (netxen_rom_fast_read(adapter, 0, &n) == 0 |
| 794 | && (n & NETXEN_ROM_FIRST_BARRIER)) { |
| 795 | n &= ~NETXEN_ROM_ROUNDUP; |
| 796 | if (n < NETXEN_ROM_FOUND_INIT) { |
| 797 | if (verbose) |
| 798 | printk("%s: %d CRB init values found" |
| 799 | " in ROM.\n", netxen_nic_driver_name, n); |
| 800 | } else { |
| 801 | printk("%s:n=0x%x Error! NetXen card flash not" |
| 802 | " initialized.\n", __FUNCTION__, n); |
| 803 | return -EIO; |
| 804 | } |
| 805 | buf = kcalloc(n, sizeof(struct crb_addr_pair), GFP_KERNEL); |
| 806 | if (buf == NULL) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 807 | printk("%s: netxen_pinit_from_rom: Unable to calloc " |
| 808 | "memory.\n", netxen_nic_driver_name); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 809 | return -ENOMEM; |
| 810 | } |
| 811 | for (i = 0; i < n; i++) { |
| 812 | if (netxen_rom_fast_read(adapter, 8 * i + 4, &val) != 0 |
| 813 | || netxen_rom_fast_read(adapter, 8 * i + 8, |
| 814 | &addr) != 0) |
| 815 | return -EIO; |
| 816 | |
| 817 | buf[i].addr = addr; |
| 818 | buf[i].data = val; |
| 819 | |
| 820 | if (verbose) |
| 821 | printk("%s: PCI: 0x%08x == 0x%08x\n", |
| 822 | netxen_nic_driver_name, (unsigned int) |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 823 | netxen_decode_crb_addr(addr), val); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 824 | } |
| 825 | for (i = 0; i < n; i++) { |
| 826 | |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 827 | off = netxen_decode_crb_addr(buf[i].addr); |
Amit S. Kale | 1fcca1a | 2007-02-05 07:35:26 -0800 | [diff] [blame] | 828 | if (off == NETXEN_ADDR_ERROR) { |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 829 | printk(KERN_ERR"CRB init value out of range %x\n", |
Amit S. Kale | 1fcca1a | 2007-02-05 07:35:26 -0800 | [diff] [blame] | 830 | buf[i].addr); |
| 831 | continue; |
| 832 | } |
| 833 | off += NETXEN_PCI_CRBSPACE; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 834 | /* skipping cold reboot MAGIC */ |
| 835 | if (off == NETXEN_CAM_RAM(0x1fc)) |
| 836 | continue; |
| 837 | |
| 838 | /* After writing this register, HW needs time for CRB */ |
| 839 | /* to quiet down (else crb_window returns 0xffffffff) */ |
| 840 | if (off == NETXEN_ROMUSB_GLB_SW_RESET) { |
| 841 | init_delay = 1; |
| 842 | /* hold xdma in reset also */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 843 | buf[i].data = NETXEN_NIC_XDMA_RESET; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | if (ADDR_IN_WINDOW1(off)) { |
| 847 | writel(buf[i].data, |
| 848 | NETXEN_CRB_NORMALIZE(adapter, off)); |
| 849 | } else { |
| 850 | netxen_nic_pci_change_crbwindow(adapter, 0); |
| 851 | writel(buf[i].data, |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 852 | pci_base_offset(adapter, off)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 853 | |
| 854 | netxen_nic_pci_change_crbwindow(adapter, 1); |
| 855 | } |
| 856 | if (init_delay == 1) { |
| 857 | ssleep(1); |
| 858 | init_delay = 0; |
| 859 | } |
| 860 | msleep(1); |
| 861 | } |
| 862 | kfree(buf); |
| 863 | |
| 864 | /* disable_peg_cache_all */ |
| 865 | |
| 866 | /* unreset_net_cache */ |
| 867 | netxen_nic_hw_read_wx(adapter, NETXEN_ROMUSB_GLB_SW_RESET, &val, |
| 868 | 4); |
| 869 | netxen_crb_writelit_adapter(adapter, NETXEN_ROMUSB_GLB_SW_RESET, |
| 870 | (val & 0xffffff0f)); |
| 871 | /* p2dn replyCount */ |
| 872 | netxen_crb_writelit_adapter(adapter, |
| 873 | NETXEN_CRB_PEG_NET_D + 0xec, 0x1e); |
| 874 | /* disable_peg_cache 0 */ |
| 875 | netxen_crb_writelit_adapter(adapter, |
| 876 | NETXEN_CRB_PEG_NET_D + 0x4c, 8); |
| 877 | /* disable_peg_cache 1 */ |
| 878 | netxen_crb_writelit_adapter(adapter, |
| 879 | NETXEN_CRB_PEG_NET_I + 0x4c, 8); |
| 880 | |
| 881 | /* peg_clr_all */ |
| 882 | |
| 883 | /* peg_clr 0 */ |
| 884 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_0 + 0x8, |
| 885 | 0); |
| 886 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_0 + 0xc, |
| 887 | 0); |
| 888 | /* peg_clr 1 */ |
| 889 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_1 + 0x8, |
| 890 | 0); |
| 891 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_1 + 0xc, |
| 892 | 0); |
| 893 | /* peg_clr 2 */ |
| 894 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_2 + 0x8, |
| 895 | 0); |
| 896 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_2 + 0xc, |
| 897 | 0); |
| 898 | /* peg_clr 3 */ |
| 899 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_3 + 0x8, |
| 900 | 0); |
| 901 | netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_3 + 0xc, |
| 902 | 0); |
| 903 | } |
| 904 | return 0; |
| 905 | } |
| 906 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 907 | int netxen_initialize_adapter_offload(struct netxen_adapter *adapter) |
| 908 | { |
| 909 | uint64_t addr; |
| 910 | uint32_t hi; |
| 911 | uint32_t lo; |
| 912 | |
| 913 | adapter->dummy_dma.addr = |
| 914 | pci_alloc_consistent(adapter->ahw.pdev, |
| 915 | NETXEN_HOST_DUMMY_DMA_SIZE, |
| 916 | &adapter->dummy_dma.phys_addr); |
| 917 | if (adapter->dummy_dma.addr == NULL) { |
| 918 | printk("%s: ERROR: Could not allocate dummy DMA memory\n", |
| 919 | __FUNCTION__); |
| 920 | return -ENOMEM; |
| 921 | } |
| 922 | |
| 923 | addr = (uint64_t) adapter->dummy_dma.phys_addr; |
| 924 | hi = (addr >> 32) & 0xffffffff; |
| 925 | lo = addr & 0xffffffff; |
| 926 | |
| 927 | writel(hi, NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_DUMMY_BUF_ADDR_HI)); |
| 928 | writel(lo, NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_DUMMY_BUF_ADDR_LO)); |
| 929 | |
| 930 | return 0; |
| 931 | } |
| 932 | |
| 933 | void netxen_free_adapter_offload(struct netxen_adapter *adapter) |
| 934 | { |
| 935 | if (adapter->dummy_dma.addr) { |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 936 | writel(0, NETXEN_CRB_NORMALIZE(adapter, |
| 937 | CRB_HOST_DUMMY_BUF_ADDR_HI)); |
| 938 | writel(0, NETXEN_CRB_NORMALIZE(adapter, |
| 939 | CRB_HOST_DUMMY_BUF_ADDR_LO)); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 940 | pci_free_consistent(adapter->ahw.pdev, |
| 941 | NETXEN_HOST_DUMMY_DMA_SIZE, |
| 942 | adapter->dummy_dma.addr, |
| 943 | adapter->dummy_dma.phys_addr); |
| 944 | adapter->dummy_dma.addr = NULL; |
| 945 | } |
| 946 | } |
| 947 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 948 | void netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 949 | { |
| 950 | u32 val = 0; |
| 951 | int loops = 0; |
| 952 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 953 | if (!pegtune_val) { |
Amit S. Kale | 1fcca1a | 2007-02-05 07:35:26 -0800 | [diff] [blame] | 954 | val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 955 | while (val != PHAN_INITIALIZE_COMPLETE && |
| 956 | val != PHAN_INITIALIZE_ACK && loops < 200000) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 957 | udelay(100); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 958 | schedule(); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 959 | val = |
| 960 | readl(NETXEN_CRB_NORMALIZE |
| 961 | (adapter, CRB_CMDPEG_STATE)); |
| 962 | loops++; |
| 963 | } |
| 964 | if (val != PHAN_INITIALIZE_COMPLETE) |
| 965 | printk("WARNING: Initial boot wait loop failed...\n"); |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | int netxen_nic_rx_has_work(struct netxen_adapter *adapter) |
| 970 | { |
| 971 | int ctx; |
| 972 | |
| 973 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
| 974 | struct netxen_recv_context *recv_ctx = |
| 975 | &(adapter->recv_ctx[ctx]); |
| 976 | u32 consumer; |
| 977 | struct status_desc *desc_head; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 978 | struct status_desc *desc; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 979 | |
| 980 | consumer = recv_ctx->status_rx_consumer; |
| 981 | desc_head = recv_ctx->rcv_status_desc_head; |
| 982 | desc = &desc_head[consumer]; |
| 983 | |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 984 | if (netxen_get_sts_owner(desc) & STATUS_OWNER_HOST) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 985 | return 1; |
| 986 | } |
| 987 | |
| 988 | return 0; |
| 989 | } |
| 990 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 991 | static inline int netxen_nic_check_temp(struct netxen_adapter *adapter) |
| 992 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 993 | struct net_device *netdev = adapter->netdev; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 994 | uint32_t temp, temp_state, temp_val; |
| 995 | int rv = 0; |
| 996 | |
| 997 | temp = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_TEMP_STATE)); |
| 998 | |
| 999 | temp_state = nx_get_temp_state(temp); |
| 1000 | temp_val = nx_get_temp_val(temp); |
| 1001 | |
| 1002 | if (temp_state == NX_TEMP_PANIC) { |
| 1003 | printk(KERN_ALERT |
| 1004 | "%s: Device temperature %d degrees C exceeds" |
| 1005 | " maximum allowed. Hardware has been shut down.\n", |
| 1006 | netxen_nic_driver_name, temp_val); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1007 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1008 | netif_carrier_off(netdev); |
| 1009 | netif_stop_queue(netdev); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1010 | rv = 1; |
| 1011 | } else if (temp_state == NX_TEMP_WARN) { |
| 1012 | if (adapter->temp == NX_TEMP_NORMAL) { |
| 1013 | printk(KERN_ALERT |
| 1014 | "%s: Device temperature %d degrees C " |
| 1015 | "exceeds operating range." |
| 1016 | " Immediate action needed.\n", |
| 1017 | netxen_nic_driver_name, temp_val); |
| 1018 | } |
| 1019 | } else { |
| 1020 | if (adapter->temp == NX_TEMP_WARN) { |
| 1021 | printk(KERN_INFO |
| 1022 | "%s: Device temperature is now %d degrees C" |
| 1023 | " in normal range.\n", netxen_nic_driver_name, |
| 1024 | temp_val); |
| 1025 | } |
| 1026 | } |
| 1027 | adapter->temp = temp_state; |
| 1028 | return rv; |
| 1029 | } |
| 1030 | |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 1031 | void netxen_watchdog_task(struct work_struct *work) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1032 | { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1033 | struct net_device *netdev; |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 1034 | struct netxen_adapter *adapter = |
| 1035 | container_of(work, struct netxen_adapter, watchdog_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1036 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1037 | if ((adapter->portnum == 0) && netxen_nic_check_temp(adapter)) |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1038 | return; |
| 1039 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1040 | if (adapter->handle_phy_intr) |
| 1041 | adapter->handle_phy_intr(adapter); |
Mithlesh Thukral | c27e672 | 2007-06-11 03:30:58 -0700 | [diff] [blame] | 1042 | |
| 1043 | netdev = adapter->netdev; |
| 1044 | if ((netif_running(netdev)) && !netif_carrier_ok(netdev) && |
| 1045 | netxen_nic_link_ok(adapter) ) { |
| 1046 | printk(KERN_INFO "%s %s (port %d), Link is up\n", |
| 1047 | netxen_nic_driver_name, netdev->name, adapter->portnum); |
| 1048 | netif_carrier_on(netdev); |
| 1049 | netif_wake_queue(netdev); |
| 1050 | } else if(!(netif_running(netdev)) && netif_carrier_ok(netdev)) { |
| 1051 | printk(KERN_ERR "%s %s Link is Down\n", |
| 1052 | netxen_nic_driver_name, netdev->name); |
| 1053 | netif_carrier_off(netdev); |
| 1054 | netif_stop_queue(netdev); |
| 1055 | } |
| 1056 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1057 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); |
| 1058 | } |
| 1059 | |
| 1060 | /* |
| 1061 | * netxen_process_rcv() send the received packet to the protocol stack. |
| 1062 | * and if the number of receives exceeds RX_BUFFERS_REFILL, then we |
| 1063 | * invoke the routine to send more rx buffers to the Phantom... |
| 1064 | */ |
| 1065 | void |
| 1066 | netxen_process_rcv(struct netxen_adapter *adapter, int ctxid, |
| 1067 | struct status_desc *desc) |
| 1068 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1069 | struct pci_dev *pdev = adapter->pdev; |
| 1070 | struct net_device *netdev = adapter->netdev; |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1071 | int index = netxen_get_sts_refhandle(desc); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1072 | struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctxid]); |
| 1073 | struct netxen_rx_buffer *buffer; |
| 1074 | struct sk_buff *skb; |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1075 | u32 length = netxen_get_sts_totallength(desc); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1076 | u32 desc_ctx; |
| 1077 | struct netxen_rcv_desc_ctx *rcv_desc; |
| 1078 | int ret; |
| 1079 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1080 | desc_ctx = netxen_get_sts_type(desc); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1081 | if (unlikely(desc_ctx >= NUM_RCV_DESC_RINGS)) { |
| 1082 | printk("%s: %s Bad Rcv descriptor ring\n", |
| 1083 | netxen_nic_driver_name, netdev->name); |
| 1084 | return; |
| 1085 | } |
| 1086 | |
| 1087 | rcv_desc = &recv_ctx->rcv_desc[desc_ctx]; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1088 | if (unlikely(index > rcv_desc->max_rx_desc_count)) { |
| 1089 | DPRINTK(ERR, "Got a buffer index:%x Max is %x\n", |
| 1090 | index, rcv_desc->max_rx_desc_count); |
| 1091 | return; |
| 1092 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1093 | buffer = &rcv_desc->rx_buf_arr[index]; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1094 | if (desc_ctx == RCV_DESC_LRO_CTXID) { |
| 1095 | buffer->lro_current_frags++; |
| 1096 | if (netxen_get_sts_desc_lro_last_frag(desc)) { |
| 1097 | buffer->lro_expected_frags = |
| 1098 | netxen_get_sts_desc_lro_cnt(desc); |
| 1099 | buffer->lro_length = length; |
| 1100 | } |
| 1101 | if (buffer->lro_current_frags != buffer->lro_expected_frags) { |
| 1102 | if (buffer->lro_expected_frags != 0) { |
| 1103 | printk("LRO: (refhandle:%x) recv frag." |
| 1104 | "wait for last. flags: %x expected:%d" |
| 1105 | "have:%d\n", index, |
| 1106 | netxen_get_sts_desc_lro_last_frag(desc), |
| 1107 | buffer->lro_expected_frags, |
| 1108 | buffer->lro_current_frags); |
| 1109 | } |
| 1110 | return; |
| 1111 | } |
| 1112 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1113 | |
| 1114 | pci_unmap_single(pdev, buffer->dma, rcv_desc->dma_size, |
| 1115 | PCI_DMA_FROMDEVICE); |
| 1116 | |
| 1117 | skb = (struct sk_buff *)buffer->skb; |
| 1118 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1119 | if (likely(netxen_get_sts_status(desc) == STATUS_CKSUM_OK)) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1120 | adapter->stats.csummed++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1121 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1122 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1123 | if (desc_ctx == RCV_DESC_LRO_CTXID) { |
| 1124 | /* True length was only available on the last pkt */ |
| 1125 | skb_put(skb, buffer->lro_length); |
| 1126 | } else { |
| 1127 | skb_put(skb, length); |
| 1128 | } |
| 1129 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1130 | skb->protocol = eth_type_trans(skb, netdev); |
| 1131 | |
| 1132 | ret = netif_receive_skb(skb); |
| 1133 | |
| 1134 | /* |
| 1135 | * RH: Do we need these stats on a regular basis. Can we get it from |
| 1136 | * Linux stats. |
| 1137 | */ |
| 1138 | switch (ret) { |
| 1139 | case NET_RX_SUCCESS: |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1140 | adapter->stats.uphappy++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1141 | break; |
| 1142 | |
| 1143 | case NET_RX_CN_LOW: |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1144 | adapter->stats.uplcong++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1145 | break; |
| 1146 | |
| 1147 | case NET_RX_CN_MOD: |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1148 | adapter->stats.upmcong++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1149 | break; |
| 1150 | |
| 1151 | case NET_RX_CN_HIGH: |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1152 | adapter->stats.uphcong++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1153 | break; |
| 1154 | |
| 1155 | case NET_RX_DROP: |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1156 | adapter->stats.updropped++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1157 | break; |
| 1158 | |
| 1159 | default: |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1160 | adapter->stats.updunno++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1161 | break; |
| 1162 | } |
| 1163 | |
| 1164 | netdev->last_rx = jiffies; |
| 1165 | |
| 1166 | rcv_desc->rcv_free++; |
| 1167 | rcv_desc->rcv_pending--; |
| 1168 | |
| 1169 | /* |
| 1170 | * We just consumed one buffer so post a buffer. |
| 1171 | */ |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1172 | buffer->skb = NULL; |
| 1173 | buffer->state = NETXEN_BUFFER_FREE; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1174 | buffer->lro_current_frags = 0; |
| 1175 | buffer->lro_expected_frags = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1176 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1177 | adapter->stats.no_rcv++; |
| 1178 | adapter->stats.rxbytes += length; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | /* Process Receive status ring */ |
| 1182 | u32 netxen_process_rcv_ring(struct netxen_adapter *adapter, int ctxid, int max) |
| 1183 | { |
| 1184 | struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctxid]); |
| 1185 | struct status_desc *desc_head = recv_ctx->rcv_status_desc_head; |
| 1186 | struct status_desc *desc; /* used to read status desc here */ |
| 1187 | u32 consumer = recv_ctx->status_rx_consumer; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1188 | u32 producer = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1189 | int count = 0, ring; |
| 1190 | |
| 1191 | DPRINTK(INFO, "procesing receive\n"); |
| 1192 | /* |
| 1193 | * we assume in this case that there is only one port and that is |
| 1194 | * port #1...changes need to be done in firmware to indicate port |
| 1195 | * number as part of the descriptor. This way we will be able to get |
| 1196 | * the netdev which is associated with that device. |
| 1197 | */ |
| 1198 | while (count < max) { |
| 1199 | desc = &desc_head[consumer]; |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1200 | if (!(netxen_get_sts_owner(desc) & STATUS_OWNER_HOST)) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1201 | DPRINTK(ERR, "desc %p ownedby %x\n", desc, |
| 1202 | netxen_get_sts_owner(desc)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1203 | break; |
| 1204 | } |
| 1205 | netxen_process_rcv(adapter, ctxid, desc); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1206 | netxen_clear_sts_owner(desc); |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1207 | netxen_set_sts_owner(desc, STATUS_OWNER_PHANTOM); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1208 | consumer = (consumer + 1) & (adapter->max_rx_desc_count - 1); |
| 1209 | count++; |
| 1210 | } |
| 1211 | if (count) { |
| 1212 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1213 | netxen_post_rx_buffers_nodb(adapter, ctxid, ring); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | /* update the consumer index in phantom */ |
| 1218 | if (count) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1219 | recv_ctx->status_rx_consumer = consumer; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1220 | recv_ctx->status_rx_producer = producer; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1221 | |
| 1222 | /* Window = 1 */ |
| 1223 | writel(consumer, |
| 1224 | NETXEN_CRB_NORMALIZE(adapter, |
Mithlesh Thukral | 4a79a04 | 2007-05-17 06:52:25 -0700 | [diff] [blame] | 1225 | recv_crb_registers[adapter->portnum]. |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1226 | crb_rcv_status_consumer)); |
| 1227 | } |
| 1228 | |
| 1229 | return count; |
| 1230 | } |
| 1231 | |
| 1232 | /* Process Command status ring */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1233 | int netxen_process_cmd_ring(unsigned long data) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1234 | { |
| 1235 | u32 last_consumer; |
| 1236 | u32 consumer; |
| 1237 | struct netxen_adapter *adapter = (struct netxen_adapter *)data; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1238 | int count1 = 0; |
| 1239 | int count2 = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1240 | struct netxen_cmd_buffer *buffer; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1241 | struct pci_dev *pdev; |
| 1242 | struct netxen_skb_frag *frag; |
| 1243 | u32 i; |
| 1244 | struct sk_buff *skb = NULL; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1245 | int done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1246 | |
| 1247 | spin_lock(&adapter->tx_lock); |
| 1248 | last_consumer = adapter->last_cmd_consumer; |
| 1249 | DPRINTK(INFO, "procesing xmit complete\n"); |
| 1250 | /* we assume in this case that there is only one port and that is |
| 1251 | * port #1...changes need to be done in firmware to indicate port |
| 1252 | * number as part of the descriptor. This way we will be able to get |
| 1253 | * the netdev which is associated with that device. |
| 1254 | */ |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1255 | |
Amit S. Kale | 9b41011 | 2007-02-09 05:45:18 -0800 | [diff] [blame] | 1256 | consumer = le32_to_cpu(*(adapter->cmd_consumer)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1257 | if (last_consumer == consumer) { /* Ring is empty */ |
| 1258 | DPRINTK(INFO, "last_consumer %d == consumer %d\n", |
| 1259 | last_consumer, consumer); |
| 1260 | spin_unlock(&adapter->tx_lock); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1261 | return 1; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | adapter->proc_cmd_buf_counter++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1265 | /* |
| 1266 | * Not needed - does not seem to be used anywhere. |
| 1267 | * adapter->cmd_consumer = consumer; |
| 1268 | */ |
| 1269 | spin_unlock(&adapter->tx_lock); |
| 1270 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1271 | while ((last_consumer != consumer) && (count1 < MAX_STATUS_HANDLE)) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1272 | buffer = &adapter->cmd_buf_arr[last_consumer]; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1273 | pdev = adapter->pdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1274 | frag = &buffer->frag_array[0]; |
| 1275 | skb = buffer->skb; |
| 1276 | if (skb && (cmpxchg(&buffer->skb, skb, 0) == skb)) { |
| 1277 | pci_unmap_single(pdev, frag->dma, frag->length, |
| 1278 | PCI_DMA_TODEVICE); |
| 1279 | for (i = 1; i < buffer->frag_count; i++) { |
| 1280 | DPRINTK(INFO, "getting fragment no %d\n", i); |
| 1281 | frag++; /* Get the next frag */ |
| 1282 | pci_unmap_page(pdev, frag->dma, frag->length, |
| 1283 | PCI_DMA_TODEVICE); |
| 1284 | } |
| 1285 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1286 | adapter->stats.skbfreed++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1287 | dev_kfree_skb_any(skb); |
| 1288 | skb = NULL; |
| 1289 | } else if (adapter->proc_cmd_buf_counter == 1) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1290 | adapter->stats.txnullskb++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1291 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1292 | if (unlikely(netif_queue_stopped(adapter->netdev) |
| 1293 | && netif_carrier_ok(adapter->netdev)) |
| 1294 | && ((jiffies - adapter->netdev->trans_start) > |
| 1295 | adapter->netdev->watchdog_timeo)) { |
| 1296 | SCHEDULE_WORK(&adapter->tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | last_consumer = get_next_index(last_consumer, |
| 1300 | adapter->max_tx_desc_count); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1301 | count1++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1302 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1303 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1304 | count2 = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1305 | spin_lock(&adapter->tx_lock); |
| 1306 | if ((--adapter->proc_cmd_buf_counter) == 0) { |
| 1307 | adapter->last_cmd_consumer = last_consumer; |
| 1308 | while ((adapter->last_cmd_consumer != consumer) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1309 | && (count2 < MAX_STATUS_HANDLE)) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1310 | buffer = |
| 1311 | &adapter->cmd_buf_arr[adapter->last_cmd_consumer]; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1312 | count2++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1313 | if (buffer->skb) |
| 1314 | break; |
| 1315 | else |
| 1316 | adapter->last_cmd_consumer = |
| 1317 | get_next_index(adapter->last_cmd_consumer, |
| 1318 | adapter->max_tx_desc_count); |
| 1319 | } |
| 1320 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1321 | if (count1 || count2) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1322 | if (netif_queue_stopped(adapter->netdev) |
| 1323 | && (adapter->flags & NETXEN_NETDEV_STATUS)) { |
| 1324 | netif_wake_queue(adapter->netdev); |
| 1325 | adapter->flags &= ~NETXEN_NETDEV_STATUS; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1326 | } |
| 1327 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1328 | /* |
| 1329 | * If everything is freed up to consumer then check if the ring is full |
| 1330 | * If the ring is full then check if more needs to be freed and |
| 1331 | * schedule the call back again. |
| 1332 | * |
| 1333 | * This happens when there are 2 CPUs. One could be freeing and the |
| 1334 | * other filling it. If the ring is full when we get out of here and |
| 1335 | * the card has already interrupted the host then the host can miss the |
| 1336 | * interrupt. |
| 1337 | * |
| 1338 | * There is still a possible race condition and the host could miss an |
| 1339 | * interrupt. The card has to take care of this. |
| 1340 | */ |
| 1341 | if (adapter->last_cmd_consumer == consumer && |
| 1342 | (((adapter->cmd_producer + 1) % |
| 1343 | adapter->max_tx_desc_count) == adapter->last_cmd_consumer)) { |
Amit S. Kale | 9b41011 | 2007-02-09 05:45:18 -0800 | [diff] [blame] | 1344 | consumer = le32_to_cpu(*(adapter->cmd_consumer)); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1345 | } |
| 1346 | done = (adapter->last_cmd_consumer == consumer); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1347 | |
| 1348 | spin_unlock(&adapter->tx_lock); |
| 1349 | DPRINTK(INFO, "last consumer is %d in %s\n", last_consumer, |
| 1350 | __FUNCTION__); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1351 | return (done); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | /* |
| 1355 | * netxen_post_rx_buffers puts buffer in the Phantom memory |
| 1356 | */ |
| 1357 | void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ctx, u32 ringid) |
| 1358 | { |
| 1359 | struct pci_dev *pdev = adapter->ahw.pdev; |
| 1360 | struct sk_buff *skb; |
| 1361 | struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctx]); |
| 1362 | struct netxen_rcv_desc_ctx *rcv_desc = NULL; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1363 | uint producer; |
| 1364 | struct rcv_desc *pdesc; |
| 1365 | struct netxen_rx_buffer *buffer; |
| 1366 | int count = 0; |
| 1367 | int index = 0; |
| 1368 | netxen_ctx_msg msg = 0; |
| 1369 | dma_addr_t dma; |
| 1370 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1371 | rcv_desc = &recv_ctx->rcv_desc[ringid]; |
| 1372 | |
| 1373 | producer = rcv_desc->producer; |
| 1374 | index = rcv_desc->begin_alloc; |
| 1375 | buffer = &rcv_desc->rx_buf_arr[index]; |
| 1376 | /* We can start writing rx descriptors into the phantom memory. */ |
| 1377 | while (buffer->state == NETXEN_BUFFER_FREE) { |
| 1378 | skb = dev_alloc_skb(rcv_desc->skb_size); |
| 1379 | if (unlikely(!skb)) { |
| 1380 | /* |
| 1381 | * TODO |
| 1382 | * We need to schedule the posting of buffers to the pegs. |
| 1383 | */ |
| 1384 | rcv_desc->begin_alloc = index; |
| 1385 | DPRINTK(ERR, "netxen_post_rx_buffers: " |
| 1386 | " allocated only %d buffers\n", count); |
| 1387 | break; |
| 1388 | } |
| 1389 | |
| 1390 | count++; /* now there should be no failure */ |
| 1391 | pdesc = &rcv_desc->desc_head[producer]; |
| 1392 | |
| 1393 | #if defined(XGB_DEBUG) |
| 1394 | *(unsigned long *)(skb->head) = 0xc0debabe; |
| 1395 | if (skb_is_nonlinear(skb)) { |
| 1396 | printk("Allocated SKB @%p is nonlinear\n"); |
| 1397 | } |
| 1398 | #endif |
| 1399 | skb_reserve(skb, 2); |
| 1400 | /* This will be setup when we receive the |
| 1401 | * buffer after it has been filled FSL TBD TBD |
| 1402 | * skb->dev = netdev; |
| 1403 | */ |
| 1404 | dma = pci_map_single(pdev, skb->data, rcv_desc->dma_size, |
| 1405 | PCI_DMA_FROMDEVICE); |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1406 | pdesc->addr_buffer = cpu_to_le64(dma); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1407 | buffer->skb = skb; |
| 1408 | buffer->state = NETXEN_BUFFER_BUSY; |
| 1409 | buffer->dma = dma; |
| 1410 | /* make a rcv descriptor */ |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1411 | pdesc->reference_handle = cpu_to_le16(buffer->ref_handle); |
| 1412 | pdesc->buffer_length = cpu_to_le32(rcv_desc->dma_size); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1413 | DPRINTK(INFO, "done writing descripter\n"); |
| 1414 | producer = |
| 1415 | get_next_index(producer, rcv_desc->max_rx_desc_count); |
| 1416 | index = get_next_index(index, rcv_desc->max_rx_desc_count); |
| 1417 | buffer = &rcv_desc->rx_buf_arr[index]; |
| 1418 | } |
| 1419 | /* if we did allocate buffers, then write the count to Phantom */ |
| 1420 | if (count) { |
| 1421 | rcv_desc->begin_alloc = index; |
| 1422 | rcv_desc->rcv_pending += count; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1423 | rcv_desc->producer = producer; |
| 1424 | if (rcv_desc->rcv_free >= 32) { |
| 1425 | rcv_desc->rcv_free = 0; |
| 1426 | /* Window = 1 */ |
| 1427 | writel((producer - 1) & |
| 1428 | (rcv_desc->max_rx_desc_count - 1), |
| 1429 | NETXEN_CRB_NORMALIZE(adapter, |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1430 | recv_crb_registers[ |
| 1431 | adapter->portnum]. |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1432 | rcv_desc_crb[ringid]. |
| 1433 | crb_rcv_producer_offset)); |
| 1434 | /* |
| 1435 | * Write a doorbell msg to tell phanmon of change in |
| 1436 | * receive ring producer |
| 1437 | */ |
| 1438 | netxen_set_msg_peg_id(msg, NETXEN_RCV_PEG_DB_ID); |
| 1439 | netxen_set_msg_privid(msg); |
| 1440 | netxen_set_msg_count(msg, |
| 1441 | ((producer - |
| 1442 | 1) & (rcv_desc-> |
| 1443 | max_rx_desc_count - 1))); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1444 | netxen_set_msg_ctxid(msg, adapter->portnum); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1445 | netxen_set_msg_opcode(msg, NETXEN_RCV_PRODUCER(ringid)); |
| 1446 | writel(msg, |
| 1447 | DB_NORMALIZE(adapter, |
| 1448 | NETXEN_RCV_PRODUCER_OFFSET)); |
| 1449 | } |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | void netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter, uint32_t ctx, |
| 1454 | uint32_t ringid) |
| 1455 | { |
| 1456 | struct pci_dev *pdev = adapter->ahw.pdev; |
| 1457 | struct sk_buff *skb; |
| 1458 | struct netxen_recv_context *recv_ctx = &(adapter->recv_ctx[ctx]); |
| 1459 | struct netxen_rcv_desc_ctx *rcv_desc = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1460 | u32 producer; |
| 1461 | struct rcv_desc *pdesc; |
| 1462 | struct netxen_rx_buffer *buffer; |
| 1463 | int count = 0; |
| 1464 | int index = 0; |
| 1465 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1466 | rcv_desc = &recv_ctx->rcv_desc[ringid]; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1467 | |
| 1468 | producer = rcv_desc->producer; |
| 1469 | index = rcv_desc->begin_alloc; |
| 1470 | buffer = &rcv_desc->rx_buf_arr[index]; |
| 1471 | /* We can start writing rx descriptors into the phantom memory. */ |
| 1472 | while (buffer->state == NETXEN_BUFFER_FREE) { |
| 1473 | skb = dev_alloc_skb(rcv_desc->skb_size); |
| 1474 | if (unlikely(!skb)) { |
| 1475 | /* |
| 1476 | * We need to schedule the posting of buffers to the pegs. |
| 1477 | */ |
| 1478 | rcv_desc->begin_alloc = index; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1479 | DPRINTK(ERR, "netxen_post_rx_buffers_nodb: " |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1480 | " allocated only %d buffers\n", count); |
| 1481 | break; |
| 1482 | } |
| 1483 | count++; /* now there should be no failure */ |
| 1484 | pdesc = &rcv_desc->desc_head[producer]; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1485 | skb_reserve(skb, 2); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1486 | /* |
| 1487 | * This will be setup when we receive the |
| 1488 | * buffer after it has been filled |
| 1489 | * skb->dev = netdev; |
| 1490 | */ |
| 1491 | buffer->skb = skb; |
| 1492 | buffer->state = NETXEN_BUFFER_BUSY; |
| 1493 | buffer->dma = pci_map_single(pdev, skb->data, |
| 1494 | rcv_desc->dma_size, |
| 1495 | PCI_DMA_FROMDEVICE); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1496 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1497 | /* make a rcv descriptor */ |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1498 | pdesc->reference_handle = cpu_to_le16(buffer->ref_handle); |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1499 | pdesc->buffer_length = cpu_to_le32(rcv_desc->dma_size); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1500 | pdesc->addr_buffer = cpu_to_le64(buffer->dma); |
| 1501 | DPRINTK(INFO, "done writing descripter\n"); |
| 1502 | producer = |
| 1503 | get_next_index(producer, rcv_desc->max_rx_desc_count); |
| 1504 | index = get_next_index(index, rcv_desc->max_rx_desc_count); |
| 1505 | buffer = &rcv_desc->rx_buf_arr[index]; |
| 1506 | } |
| 1507 | |
| 1508 | /* if we did allocate buffers, then write the count to Phantom */ |
| 1509 | if (count) { |
| 1510 | rcv_desc->begin_alloc = index; |
| 1511 | rcv_desc->rcv_pending += count; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1512 | rcv_desc->producer = producer; |
| 1513 | if (rcv_desc->rcv_free >= 32) { |
| 1514 | rcv_desc->rcv_free = 0; |
| 1515 | /* Window = 1 */ |
| 1516 | writel((producer - 1) & |
| 1517 | (rcv_desc->max_rx_desc_count - 1), |
| 1518 | NETXEN_CRB_NORMALIZE(adapter, |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1519 | recv_crb_registers[ |
| 1520 | adapter->portnum]. |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1521 | rcv_desc_crb[ringid]. |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1522 | crb_rcv_producer_offset)); |
| 1523 | wmb(); |
| 1524 | } |
| 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | int netxen_nic_tx_has_work(struct netxen_adapter *adapter) |
| 1529 | { |
| 1530 | if (find_diff_among(adapter->last_cmd_consumer, |
| 1531 | adapter->cmd_producer, |
| 1532 | adapter->max_tx_desc_count) > 0) |
| 1533 | return 1; |
| 1534 | |
| 1535 | return 0; |
| 1536 | } |
| 1537 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1538 | |
| 1539 | void netxen_nic_clear_stats(struct netxen_adapter *adapter) |
| 1540 | { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1541 | memset(&adapter->stats, 0, sizeof(adapter->stats)); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1542 | return; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1543 | } |
| 1544 | |