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