Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 - QLogic Corporation. |
| 3 | * All rights reserved. |
| 4 | * |
| 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. |
| 9 | * |
| 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. |
| 14 | * |
| 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. |
| 19 | * |
| 20 | * The full GNU General Public License is included in this distribution |
| 21 | * in the file called "COPYING". |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <linux/netdevice.h> |
| 26 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Amit Kumar Salecha | 8cf61f8 | 2010-08-25 04:03:03 +0000 | [diff] [blame] | 28 | #include <linux/if_vlan.h> |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 29 | #include "qlcnic.h" |
| 30 | |
| 31 | struct crb_addr_pair { |
| 32 | u32 addr; |
| 33 | u32 data; |
| 34 | }; |
| 35 | |
| 36 | #define QLCNIC_MAX_CRB_XFORM 60 |
| 37 | static unsigned int crb_addr_xform[QLCNIC_MAX_CRB_XFORM]; |
| 38 | |
| 39 | #define crb_addr_transform(name) \ |
| 40 | (crb_addr_xform[QLCNIC_HW_PX_MAP_CRB_##name] = \ |
| 41 | QLCNIC_HW_CRB_HUB_AGT_ADR_##name << 20) |
| 42 | |
| 43 | #define QLCNIC_ADDR_ERROR (0xffffffff) |
| 44 | |
| 45 | static void |
| 46 | qlcnic_post_rx_buffers_nodb(struct qlcnic_adapter *adapter, |
| 47 | struct qlcnic_host_rds_ring *rds_ring); |
| 48 | |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame^] | 49 | static int |
| 50 | qlcnic_check_fw_hearbeat(struct qlcnic_adapter *adapter); |
| 51 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 52 | static void crb_addr_transform_setup(void) |
| 53 | { |
| 54 | crb_addr_transform(XDMA); |
| 55 | crb_addr_transform(TIMR); |
| 56 | crb_addr_transform(SRE); |
| 57 | crb_addr_transform(SQN3); |
| 58 | crb_addr_transform(SQN2); |
| 59 | crb_addr_transform(SQN1); |
| 60 | crb_addr_transform(SQN0); |
| 61 | crb_addr_transform(SQS3); |
| 62 | crb_addr_transform(SQS2); |
| 63 | crb_addr_transform(SQS1); |
| 64 | crb_addr_transform(SQS0); |
| 65 | crb_addr_transform(RPMX7); |
| 66 | crb_addr_transform(RPMX6); |
| 67 | crb_addr_transform(RPMX5); |
| 68 | crb_addr_transform(RPMX4); |
| 69 | crb_addr_transform(RPMX3); |
| 70 | crb_addr_transform(RPMX2); |
| 71 | crb_addr_transform(RPMX1); |
| 72 | crb_addr_transform(RPMX0); |
| 73 | crb_addr_transform(ROMUSB); |
| 74 | crb_addr_transform(SN); |
| 75 | crb_addr_transform(QMN); |
| 76 | crb_addr_transform(QMS); |
| 77 | crb_addr_transform(PGNI); |
| 78 | crb_addr_transform(PGND); |
| 79 | crb_addr_transform(PGN3); |
| 80 | crb_addr_transform(PGN2); |
| 81 | crb_addr_transform(PGN1); |
| 82 | crb_addr_transform(PGN0); |
| 83 | crb_addr_transform(PGSI); |
| 84 | crb_addr_transform(PGSD); |
| 85 | crb_addr_transform(PGS3); |
| 86 | crb_addr_transform(PGS2); |
| 87 | crb_addr_transform(PGS1); |
| 88 | crb_addr_transform(PGS0); |
| 89 | crb_addr_transform(PS); |
| 90 | crb_addr_transform(PH); |
| 91 | crb_addr_transform(NIU); |
| 92 | crb_addr_transform(I2Q); |
| 93 | crb_addr_transform(EG); |
| 94 | crb_addr_transform(MN); |
| 95 | crb_addr_transform(MS); |
| 96 | crb_addr_transform(CAS2); |
| 97 | crb_addr_transform(CAS1); |
| 98 | crb_addr_transform(CAS0); |
| 99 | crb_addr_transform(CAM); |
| 100 | crb_addr_transform(C2C1); |
| 101 | crb_addr_transform(C2C0); |
| 102 | crb_addr_transform(SMB); |
| 103 | crb_addr_transform(OCM0); |
| 104 | crb_addr_transform(I2C0); |
| 105 | } |
| 106 | |
| 107 | void qlcnic_release_rx_buffers(struct qlcnic_adapter *adapter) |
| 108 | { |
| 109 | struct qlcnic_recv_context *recv_ctx; |
| 110 | struct qlcnic_host_rds_ring *rds_ring; |
| 111 | struct qlcnic_rx_buffer *rx_buf; |
| 112 | int i, ring; |
| 113 | |
| 114 | recv_ctx = &adapter->recv_ctx; |
| 115 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 116 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 117 | for (i = 0; i < rds_ring->num_desc; ++i) { |
| 118 | rx_buf = &(rds_ring->rx_buf_arr[i]); |
Amit Kumar Salecha | 9665982 | 2010-06-22 03:18:58 +0000 | [diff] [blame] | 119 | if (rx_buf->skb == NULL) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 120 | continue; |
Amit Kumar Salecha | 9665982 | 2010-06-22 03:18:58 +0000 | [diff] [blame] | 121 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 122 | pci_unmap_single(adapter->pdev, |
| 123 | rx_buf->dma, |
| 124 | rds_ring->dma_size, |
| 125 | PCI_DMA_FROMDEVICE); |
Amit Kumar Salecha | 9665982 | 2010-06-22 03:18:58 +0000 | [diff] [blame] | 126 | |
| 127 | dev_kfree_skb_any(rx_buf->skb); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 132 | void qlcnic_reset_rx_buffers_list(struct qlcnic_adapter *adapter) |
| 133 | { |
| 134 | struct qlcnic_recv_context *recv_ctx; |
| 135 | struct qlcnic_host_rds_ring *rds_ring; |
| 136 | struct qlcnic_rx_buffer *rx_buf; |
| 137 | int i, ring; |
| 138 | |
| 139 | recv_ctx = &adapter->recv_ctx; |
| 140 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 141 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 142 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 143 | INIT_LIST_HEAD(&rds_ring->free_list); |
| 144 | |
| 145 | rx_buf = rds_ring->rx_buf_arr; |
| 146 | for (i = 0; i < rds_ring->num_desc; i++) { |
| 147 | list_add_tail(&rx_buf->list, |
| 148 | &rds_ring->free_list); |
| 149 | rx_buf++; |
| 150 | } |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 154 | void qlcnic_release_tx_buffers(struct qlcnic_adapter *adapter) |
| 155 | { |
| 156 | struct qlcnic_cmd_buffer *cmd_buf; |
| 157 | struct qlcnic_skb_frag *buffrag; |
| 158 | int i, j; |
| 159 | struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; |
| 160 | |
| 161 | cmd_buf = tx_ring->cmd_buf_arr; |
| 162 | for (i = 0; i < tx_ring->num_desc; i++) { |
| 163 | buffrag = cmd_buf->frag_array; |
| 164 | if (buffrag->dma) { |
| 165 | pci_unmap_single(adapter->pdev, buffrag->dma, |
| 166 | buffrag->length, PCI_DMA_TODEVICE); |
| 167 | buffrag->dma = 0ULL; |
| 168 | } |
| 169 | for (j = 0; j < cmd_buf->frag_count; j++) { |
| 170 | buffrag++; |
| 171 | if (buffrag->dma) { |
| 172 | pci_unmap_page(adapter->pdev, buffrag->dma, |
| 173 | buffrag->length, |
| 174 | PCI_DMA_TODEVICE); |
| 175 | buffrag->dma = 0ULL; |
| 176 | } |
| 177 | } |
| 178 | if (cmd_buf->skb) { |
| 179 | dev_kfree_skb_any(cmd_buf->skb); |
| 180 | cmd_buf->skb = NULL; |
| 181 | } |
| 182 | cmd_buf++; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | void qlcnic_free_sw_resources(struct qlcnic_adapter *adapter) |
| 187 | { |
| 188 | struct qlcnic_recv_context *recv_ctx; |
| 189 | struct qlcnic_host_rds_ring *rds_ring; |
| 190 | struct qlcnic_host_tx_ring *tx_ring; |
| 191 | int ring; |
| 192 | |
| 193 | recv_ctx = &adapter->recv_ctx; |
| 194 | |
| 195 | if (recv_ctx->rds_rings == NULL) |
| 196 | goto skip_rds; |
| 197 | |
| 198 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 199 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 200 | vfree(rds_ring->rx_buf_arr); |
| 201 | rds_ring->rx_buf_arr = NULL; |
| 202 | } |
| 203 | kfree(recv_ctx->rds_rings); |
| 204 | |
| 205 | skip_rds: |
| 206 | if (adapter->tx_ring == NULL) |
| 207 | return; |
| 208 | |
| 209 | tx_ring = adapter->tx_ring; |
| 210 | vfree(tx_ring->cmd_buf_arr); |
Rajesh K Borundia | ef71ff8 | 2010-06-17 02:56:41 +0000 | [diff] [blame] | 211 | tx_ring->cmd_buf_arr = NULL; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 212 | kfree(adapter->tx_ring); |
Rajesh K Borundia | ef71ff8 | 2010-06-17 02:56:41 +0000 | [diff] [blame] | 213 | adapter->tx_ring = NULL; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | int qlcnic_alloc_sw_resources(struct qlcnic_adapter *adapter) |
| 217 | { |
| 218 | struct qlcnic_recv_context *recv_ctx; |
| 219 | struct qlcnic_host_rds_ring *rds_ring; |
| 220 | struct qlcnic_host_sds_ring *sds_ring; |
| 221 | struct qlcnic_host_tx_ring *tx_ring; |
| 222 | struct qlcnic_rx_buffer *rx_buf; |
| 223 | int ring, i, size; |
| 224 | |
| 225 | struct qlcnic_cmd_buffer *cmd_buf_arr; |
| 226 | struct net_device *netdev = adapter->netdev; |
| 227 | |
| 228 | size = sizeof(struct qlcnic_host_tx_ring); |
| 229 | tx_ring = kzalloc(size, GFP_KERNEL); |
| 230 | if (tx_ring == NULL) { |
| 231 | dev_err(&netdev->dev, "failed to allocate tx ring struct\n"); |
| 232 | return -ENOMEM; |
| 233 | } |
| 234 | adapter->tx_ring = tx_ring; |
| 235 | |
| 236 | tx_ring->num_desc = adapter->num_txd; |
| 237 | tx_ring->txq = netdev_get_tx_queue(netdev, 0); |
| 238 | |
| 239 | cmd_buf_arr = vmalloc(TX_BUFF_RINGSIZE(tx_ring)); |
| 240 | if (cmd_buf_arr == NULL) { |
| 241 | dev_err(&netdev->dev, "failed to allocate cmd buffer ring\n"); |
Anirban Chakraborty | aadd818 | 2010-05-17 01:22:08 +0000 | [diff] [blame] | 242 | goto err_out; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 243 | } |
| 244 | memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring)); |
| 245 | tx_ring->cmd_buf_arr = cmd_buf_arr; |
| 246 | |
| 247 | recv_ctx = &adapter->recv_ctx; |
| 248 | |
| 249 | size = adapter->max_rds_rings * sizeof(struct qlcnic_host_rds_ring); |
| 250 | rds_ring = kzalloc(size, GFP_KERNEL); |
| 251 | if (rds_ring == NULL) { |
| 252 | dev_err(&netdev->dev, "failed to allocate rds ring struct\n"); |
Anirban Chakraborty | aadd818 | 2010-05-17 01:22:08 +0000 | [diff] [blame] | 253 | goto err_out; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 254 | } |
| 255 | recv_ctx->rds_rings = rds_ring; |
| 256 | |
| 257 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 258 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 259 | switch (ring) { |
| 260 | case RCV_RING_NORMAL: |
| 261 | rds_ring->num_desc = adapter->num_rxd; |
Amit Kumar Salecha | 251a84c | 2010-05-13 03:07:46 +0000 | [diff] [blame] | 262 | rds_ring->dma_size = QLCNIC_P3_RX_BUF_MAX_LEN; |
| 263 | rds_ring->skb_size = rds_ring->dma_size + NET_IP_ALIGN; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 264 | break; |
| 265 | |
| 266 | case RCV_RING_JUMBO: |
| 267 | rds_ring->num_desc = adapter->num_jumbo_rxd; |
| 268 | rds_ring->dma_size = |
| 269 | QLCNIC_P3_RX_JUMBO_BUF_MAX_LEN; |
| 270 | |
| 271 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) |
| 272 | rds_ring->dma_size += QLCNIC_LRO_BUFFER_EXTRA; |
| 273 | |
| 274 | rds_ring->skb_size = |
| 275 | rds_ring->dma_size + NET_IP_ALIGN; |
| 276 | break; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 277 | } |
| 278 | rds_ring->rx_buf_arr = (struct qlcnic_rx_buffer *) |
| 279 | vmalloc(RCV_BUFF_RINGSIZE(rds_ring)); |
| 280 | if (rds_ring->rx_buf_arr == NULL) { |
| 281 | dev_err(&netdev->dev, "Failed to allocate " |
| 282 | "rx buffer ring %d\n", ring); |
| 283 | goto err_out; |
| 284 | } |
| 285 | memset(rds_ring->rx_buf_arr, 0, RCV_BUFF_RINGSIZE(rds_ring)); |
| 286 | INIT_LIST_HEAD(&rds_ring->free_list); |
| 287 | /* |
| 288 | * Now go through all of them, set reference handles |
| 289 | * and put them in the queues. |
| 290 | */ |
| 291 | rx_buf = rds_ring->rx_buf_arr; |
| 292 | for (i = 0; i < rds_ring->num_desc; i++) { |
| 293 | list_add_tail(&rx_buf->list, |
| 294 | &rds_ring->free_list); |
| 295 | rx_buf->ref_handle = i; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 296 | rx_buf++; |
| 297 | } |
| 298 | spin_lock_init(&rds_ring->lock); |
| 299 | } |
| 300 | |
| 301 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 302 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 303 | sds_ring->irq = adapter->msix_entries[ring].vector; |
| 304 | sds_ring->adapter = adapter; |
| 305 | sds_ring->num_desc = adapter->num_rxd; |
| 306 | |
| 307 | for (i = 0; i < NUM_RCV_DESC_RINGS; i++) |
| 308 | INIT_LIST_HEAD(&sds_ring->free_list[i]); |
| 309 | } |
| 310 | |
| 311 | return 0; |
| 312 | |
| 313 | err_out: |
| 314 | qlcnic_free_sw_resources(adapter); |
| 315 | return -ENOMEM; |
| 316 | } |
| 317 | |
| 318 | /* |
| 319 | * Utility to translate from internal Phantom CRB address |
| 320 | * to external PCI CRB address. |
| 321 | */ |
| 322 | static u32 qlcnic_decode_crb_addr(u32 addr) |
| 323 | { |
| 324 | int i; |
| 325 | u32 base_addr, offset, pci_base; |
| 326 | |
| 327 | crb_addr_transform_setup(); |
| 328 | |
| 329 | pci_base = QLCNIC_ADDR_ERROR; |
| 330 | base_addr = addr & 0xfff00000; |
| 331 | offset = addr & 0x000fffff; |
| 332 | |
| 333 | for (i = 0; i < QLCNIC_MAX_CRB_XFORM; i++) { |
| 334 | if (crb_addr_xform[i] == base_addr) { |
| 335 | pci_base = i << 20; |
| 336 | break; |
| 337 | } |
| 338 | } |
| 339 | if (pci_base == QLCNIC_ADDR_ERROR) |
| 340 | return pci_base; |
| 341 | else |
| 342 | return pci_base + offset; |
| 343 | } |
| 344 | |
| 345 | #define QLCNIC_MAX_ROM_WAIT_USEC 100 |
| 346 | |
| 347 | static int qlcnic_wait_rom_done(struct qlcnic_adapter *adapter) |
| 348 | { |
| 349 | long timeout = 0; |
| 350 | long done = 0; |
| 351 | |
| 352 | cond_resched(); |
| 353 | |
| 354 | while (done == 0) { |
| 355 | done = QLCRD32(adapter, QLCNIC_ROMUSB_GLB_STATUS); |
| 356 | done &= 2; |
| 357 | if (++timeout >= QLCNIC_MAX_ROM_WAIT_USEC) { |
| 358 | dev_err(&adapter->pdev->dev, |
| 359 | "Timeout reached waiting for rom done"); |
| 360 | return -EIO; |
| 361 | } |
| 362 | udelay(1); |
| 363 | } |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | static int do_rom_fast_read(struct qlcnic_adapter *adapter, |
| 368 | int addr, int *valp) |
| 369 | { |
| 370 | QLCWR32(adapter, QLCNIC_ROMUSB_ROM_ADDRESS, addr); |
| 371 | QLCWR32(adapter, QLCNIC_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); |
| 372 | QLCWR32(adapter, QLCNIC_ROMUSB_ROM_ABYTE_CNT, 3); |
| 373 | QLCWR32(adapter, QLCNIC_ROMUSB_ROM_INSTR_OPCODE, 0xb); |
| 374 | if (qlcnic_wait_rom_done(adapter)) { |
| 375 | dev_err(&adapter->pdev->dev, "Error waiting for rom done\n"); |
| 376 | return -EIO; |
| 377 | } |
| 378 | /* reset abyte_cnt and dummy_byte_cnt */ |
| 379 | QLCWR32(adapter, QLCNIC_ROMUSB_ROM_ABYTE_CNT, 0); |
| 380 | udelay(10); |
| 381 | QLCWR32(adapter, QLCNIC_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); |
| 382 | |
| 383 | *valp = QLCRD32(adapter, QLCNIC_ROMUSB_ROM_RDATA); |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static int do_rom_fast_read_words(struct qlcnic_adapter *adapter, int addr, |
| 388 | u8 *bytes, size_t size) |
| 389 | { |
| 390 | int addridx; |
| 391 | int ret = 0; |
| 392 | |
| 393 | for (addridx = addr; addridx < (addr + size); addridx += 4) { |
| 394 | int v; |
| 395 | ret = do_rom_fast_read(adapter, addridx, &v); |
| 396 | if (ret != 0) |
| 397 | break; |
| 398 | *(__le32 *)bytes = cpu_to_le32(v); |
| 399 | bytes += 4; |
| 400 | } |
| 401 | |
| 402 | return ret; |
| 403 | } |
| 404 | |
| 405 | int |
| 406 | qlcnic_rom_fast_read_words(struct qlcnic_adapter *adapter, int addr, |
| 407 | u8 *bytes, size_t size) |
| 408 | { |
| 409 | int ret; |
| 410 | |
| 411 | ret = qlcnic_rom_lock(adapter); |
| 412 | if (ret < 0) |
| 413 | return ret; |
| 414 | |
| 415 | ret = do_rom_fast_read_words(adapter, addr, bytes, size); |
| 416 | |
| 417 | qlcnic_rom_unlock(adapter); |
| 418 | return ret; |
| 419 | } |
| 420 | |
| 421 | int qlcnic_rom_fast_read(struct qlcnic_adapter *adapter, int addr, int *valp) |
| 422 | { |
| 423 | int ret; |
| 424 | |
| 425 | if (qlcnic_rom_lock(adapter) != 0) |
| 426 | return -EIO; |
| 427 | |
| 428 | ret = do_rom_fast_read(adapter, addr, valp); |
| 429 | qlcnic_rom_unlock(adapter); |
| 430 | return ret; |
| 431 | } |
| 432 | |
| 433 | int qlcnic_pinit_from_rom(struct qlcnic_adapter *adapter) |
| 434 | { |
| 435 | int addr, val; |
| 436 | int i, n, init_delay; |
| 437 | struct crb_addr_pair *buf; |
| 438 | unsigned offset; |
| 439 | u32 off; |
| 440 | struct pci_dev *pdev = adapter->pdev; |
| 441 | |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 442 | QLCWR32(adapter, CRB_CMDPEG_STATE, 0); |
| 443 | QLCWR32(adapter, CRB_RCVPEG_STATE, 0); |
| 444 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 445 | qlcnic_rom_lock(adapter); |
Sucheta Chakraborty | 469c221 | 2010-06-17 02:56:38 +0000 | [diff] [blame] | 446 | QLCWR32(adapter, QLCNIC_ROMUSB_GLB_SW_RESET, 0xfeffffff); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 447 | qlcnic_rom_unlock(adapter); |
| 448 | |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 449 | /* Init HW CRB block */ |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 450 | if (qlcnic_rom_fast_read(adapter, 0, &n) != 0 || (n != 0xcafecafe) || |
| 451 | qlcnic_rom_fast_read(adapter, 4, &n) != 0) { |
| 452 | dev_err(&pdev->dev, "ERROR Reading crb_init area: val:%x\n", n); |
| 453 | return -EIO; |
| 454 | } |
| 455 | offset = n & 0xffffU; |
| 456 | n = (n >> 16) & 0xffffU; |
| 457 | |
| 458 | if (n >= 1024) { |
| 459 | dev_err(&pdev->dev, "QLOGIC card flash not initialized.\n"); |
| 460 | return -EIO; |
| 461 | } |
| 462 | |
| 463 | buf = kcalloc(n, sizeof(struct crb_addr_pair), GFP_KERNEL); |
| 464 | if (buf == NULL) { |
| 465 | dev_err(&pdev->dev, "Unable to calloc memory for rom read.\n"); |
| 466 | return -ENOMEM; |
| 467 | } |
| 468 | |
| 469 | for (i = 0; i < n; i++) { |
| 470 | if (qlcnic_rom_fast_read(adapter, 8*i + 4*offset, &val) != 0 || |
| 471 | qlcnic_rom_fast_read(adapter, 8*i + 4*offset + 4, &addr) != 0) { |
| 472 | kfree(buf); |
| 473 | return -EIO; |
| 474 | } |
| 475 | |
| 476 | buf[i].addr = addr; |
| 477 | buf[i].data = val; |
| 478 | } |
| 479 | |
| 480 | for (i = 0; i < n; i++) { |
| 481 | |
| 482 | off = qlcnic_decode_crb_addr(buf[i].addr); |
| 483 | if (off == QLCNIC_ADDR_ERROR) { |
| 484 | dev_err(&pdev->dev, "CRB init value out of range %x\n", |
| 485 | buf[i].addr); |
| 486 | continue; |
| 487 | } |
| 488 | off += QLCNIC_PCI_CRBSPACE; |
| 489 | |
| 490 | if (off & 1) |
| 491 | continue; |
| 492 | |
| 493 | /* skipping cold reboot MAGIC */ |
| 494 | if (off == QLCNIC_CAM_RAM(0x1fc)) |
| 495 | continue; |
| 496 | if (off == (QLCNIC_CRB_I2C0 + 0x1c)) |
| 497 | continue; |
| 498 | if (off == (ROMUSB_GLB + 0xbc)) /* do not reset PCI */ |
| 499 | continue; |
| 500 | if (off == (ROMUSB_GLB + 0xa8)) |
| 501 | continue; |
| 502 | if (off == (ROMUSB_GLB + 0xc8)) /* core clock */ |
| 503 | continue; |
| 504 | if (off == (ROMUSB_GLB + 0x24)) /* MN clock */ |
| 505 | continue; |
| 506 | if (off == (ROMUSB_GLB + 0x1c)) /* MS clock */ |
| 507 | continue; |
| 508 | if ((off & 0x0ff00000) == QLCNIC_CRB_DDR_NET) |
| 509 | continue; |
| 510 | /* skip the function enable register */ |
| 511 | if (off == QLCNIC_PCIE_REG(PCIE_SETUP_FUNCTION)) |
| 512 | continue; |
| 513 | if (off == QLCNIC_PCIE_REG(PCIE_SETUP_FUNCTION2)) |
| 514 | continue; |
| 515 | if ((off & 0x0ff00000) == QLCNIC_CRB_SMB) |
| 516 | continue; |
| 517 | |
| 518 | init_delay = 1; |
| 519 | /* After writing this register, HW needs time for CRB */ |
| 520 | /* to quiet down (else crb_window returns 0xffffffff) */ |
| 521 | if (off == QLCNIC_ROMUSB_GLB_SW_RESET) |
| 522 | init_delay = 1000; |
| 523 | |
| 524 | QLCWR32(adapter, off, buf[i].data); |
| 525 | |
| 526 | msleep(init_delay); |
| 527 | } |
| 528 | kfree(buf); |
| 529 | |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 530 | /* Initialize protocol process engine */ |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 531 | QLCWR32(adapter, QLCNIC_CRB_PEG_NET_D + 0xec, 0x1e); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 532 | QLCWR32(adapter, QLCNIC_CRB_PEG_NET_D + 0x4c, 8); |
| 533 | QLCWR32(adapter, QLCNIC_CRB_PEG_NET_I + 0x4c, 8); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 534 | QLCWR32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x8, 0); |
| 535 | QLCWR32(adapter, QLCNIC_CRB_PEG_NET_0 + 0xc, 0); |
| 536 | QLCWR32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x8, 0); |
| 537 | QLCWR32(adapter, QLCNIC_CRB_PEG_NET_1 + 0xc, 0); |
| 538 | QLCWR32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x8, 0); |
| 539 | QLCWR32(adapter, QLCNIC_CRB_PEG_NET_2 + 0xc, 0); |
| 540 | QLCWR32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x8, 0); |
| 541 | QLCWR32(adapter, QLCNIC_CRB_PEG_NET_3 + 0xc, 0); |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 542 | QLCWR32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x8, 0); |
| 543 | QLCWR32(adapter, QLCNIC_CRB_PEG_NET_4 + 0xc, 0); |
| 544 | msleep(1); |
| 545 | QLCWR32(adapter, QLCNIC_PEG_HALT_STATUS1, 0); |
| 546 | QLCWR32(adapter, QLCNIC_PEG_HALT_STATUS2, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 547 | return 0; |
| 548 | } |
| 549 | |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame^] | 550 | static int qlcnic_cmd_peg_ready(struct qlcnic_adapter *adapter) |
| 551 | { |
| 552 | u32 val; |
| 553 | int retries = QLCNIC_CMDPEG_CHECK_RETRY_COUNT; |
| 554 | |
| 555 | do { |
| 556 | val = QLCRD32(adapter, CRB_CMDPEG_STATE); |
| 557 | |
| 558 | switch (val) { |
| 559 | case PHAN_INITIALIZE_COMPLETE: |
| 560 | case PHAN_INITIALIZE_ACK: |
| 561 | return 0; |
| 562 | case PHAN_INITIALIZE_FAILED: |
| 563 | goto out_err; |
| 564 | default: |
| 565 | break; |
| 566 | } |
| 567 | |
| 568 | msleep(QLCNIC_CMDPEG_CHECK_DELAY); |
| 569 | |
| 570 | } while (--retries); |
| 571 | |
| 572 | QLCWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_FAILED); |
| 573 | |
| 574 | out_err: |
| 575 | dev_err(&adapter->pdev->dev, "Command Peg initialization not " |
| 576 | "complete, state: 0x%x.\n", val); |
| 577 | return -EIO; |
| 578 | } |
| 579 | |
| 580 | static int |
| 581 | qlcnic_receive_peg_ready(struct qlcnic_adapter *adapter) |
| 582 | { |
| 583 | u32 val; |
| 584 | int retries = QLCNIC_RCVPEG_CHECK_RETRY_COUNT; |
| 585 | |
| 586 | do { |
| 587 | val = QLCRD32(adapter, CRB_RCVPEG_STATE); |
| 588 | |
| 589 | if (val == PHAN_PEG_RCV_INITIALIZED) |
| 590 | return 0; |
| 591 | |
| 592 | msleep(QLCNIC_RCVPEG_CHECK_DELAY); |
| 593 | |
| 594 | } while (--retries); |
| 595 | |
| 596 | if (!retries) { |
| 597 | dev_err(&adapter->pdev->dev, "Receive Peg initialization not " |
| 598 | "complete, state: 0x%x.\n", val); |
| 599 | return -EIO; |
| 600 | } |
| 601 | |
| 602 | return 0; |
| 603 | } |
| 604 | |
Sucheta Chakraborty | b3a2464 | 2010-05-13 03:07:48 +0000 | [diff] [blame] | 605 | int |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 606 | qlcnic_check_fw_status(struct qlcnic_adapter *adapter) |
| 607 | { |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame^] | 608 | int err; |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 609 | |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame^] | 610 | err = qlcnic_cmd_peg_ready(adapter); |
| 611 | if (err) |
| 612 | return err; |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 613 | |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame^] | 614 | err = qlcnic_receive_peg_ready(adapter); |
| 615 | if (err) |
| 616 | return err; |
| 617 | |
| 618 | QLCWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_ACK); |
| 619 | |
| 620 | return err; |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | int |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 624 | qlcnic_setup_idc_param(struct qlcnic_adapter *adapter) { |
| 625 | |
| 626 | int timeo; |
Sucheta Chakraborty | b3a2464 | 2010-05-13 03:07:48 +0000 | [diff] [blame] | 627 | u32 val; |
| 628 | |
Anirban Chakraborty | 45918e2 | 2010-06-29 07:52:12 +0000 | [diff] [blame] | 629 | val = QLCRD32(adapter, QLCNIC_CRB_DEV_PARTITION_INFO); |
| 630 | val = QLC_DEV_GET_DRV(val, adapter->portnum); |
| 631 | if ((val & 0x3) != QLCNIC_TYPE_NIC) { |
| 632 | dev_err(&adapter->pdev->dev, |
| 633 | "Not an Ethernet NIC func=%u\n", val); |
| 634 | return -EIO; |
Sucheta Chakraborty | b3a2464 | 2010-05-13 03:07:48 +0000 | [diff] [blame] | 635 | } |
Anirban Chakraborty | 45918e2 | 2010-06-29 07:52:12 +0000 | [diff] [blame] | 636 | adapter->physical_port = (val >> 2); |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 637 | if (qlcnic_rom_fast_read(adapter, QLCNIC_ROM_DEV_INIT_TIMEOUT, &timeo)) |
Sony Chacko | 251b036 | 2010-08-19 05:08:24 +0000 | [diff] [blame] | 638 | timeo = QLCNIC_INIT_TIMEOUT_SECS; |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 639 | |
| 640 | adapter->dev_init_timeo = timeo; |
| 641 | |
| 642 | if (qlcnic_rom_fast_read(adapter, QLCNIC_ROM_DRV_RESET_TIMEOUT, &timeo)) |
Sony Chacko | 251b036 | 2010-08-19 05:08:24 +0000 | [diff] [blame] | 643 | timeo = QLCNIC_RESET_TIMEOUT_SECS; |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 644 | |
| 645 | adapter->reset_ack_timeo = timeo; |
Sucheta Chakraborty | b3a2464 | 2010-05-13 03:07:48 +0000 | [diff] [blame] | 646 | |
| 647 | return 0; |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 648 | } |
| 649 | |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 650 | int |
| 651 | qlcnic_check_flash_fw_ver(struct qlcnic_adapter *adapter) |
| 652 | { |
| 653 | u32 ver = -1, min_ver; |
| 654 | |
| 655 | qlcnic_rom_fast_read(adapter, QLCNIC_FW_VERSION_OFFSET, (int *)&ver); |
| 656 | |
| 657 | ver = QLCNIC_DECODE_VERSION(ver); |
| 658 | min_ver = QLCNIC_MIN_FW_VERSION; |
| 659 | |
| 660 | if (ver < min_ver) { |
| 661 | dev_err(&adapter->pdev->dev, |
| 662 | "firmware version %d.%d.%d unsupported." |
| 663 | "Min supported version %d.%d.%d\n", |
| 664 | _major(ver), _minor(ver), _build(ver), |
| 665 | _major(min_ver), _minor(min_ver), _build(min_ver)); |
| 666 | return -EINVAL; |
| 667 | } |
| 668 | |
| 669 | return 0; |
| 670 | } |
| 671 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 672 | static int |
| 673 | qlcnic_has_mn(struct qlcnic_adapter *adapter) |
| 674 | { |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 675 | u32 capability; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 676 | capability = 0; |
| 677 | |
Amit Kumar Salecha | 251a84c | 2010-05-13 03:07:46 +0000 | [diff] [blame] | 678 | capability = QLCRD32(adapter, QLCNIC_PEG_TUNE_CAPABILITY); |
| 679 | if (capability & QLCNIC_PEG_TUNE_MN_PRESENT) |
| 680 | return 1; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 681 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 682 | return 0; |
| 683 | } |
| 684 | |
| 685 | static |
| 686 | struct uni_table_desc *qlcnic_get_table_desc(const u8 *unirom, int section) |
| 687 | { |
| 688 | u32 i; |
| 689 | struct uni_table_desc *directory = (struct uni_table_desc *) &unirom[0]; |
| 690 | __le32 entries = cpu_to_le32(directory->num_entries); |
| 691 | |
| 692 | for (i = 0; i < entries; i++) { |
| 693 | |
| 694 | __le32 offs = cpu_to_le32(directory->findex) + |
| 695 | (i * cpu_to_le32(directory->entry_size)); |
| 696 | __le32 tab_type = cpu_to_le32(*((u32 *)&unirom[offs] + 8)); |
| 697 | |
| 698 | if (tab_type == section) |
| 699 | return (struct uni_table_desc *) &unirom[offs]; |
| 700 | } |
| 701 | |
| 702 | return NULL; |
| 703 | } |
| 704 | |
Sucheta Chakraborty | b7eff10 | 2010-03-08 00:14:48 +0000 | [diff] [blame] | 705 | #define FILEHEADER_SIZE (14 * 4) |
| 706 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 707 | static int |
Sucheta Chakraborty | b7eff10 | 2010-03-08 00:14:48 +0000 | [diff] [blame] | 708 | qlcnic_validate_header(struct qlcnic_adapter *adapter) |
| 709 | { |
| 710 | const u8 *unirom = adapter->fw->data; |
| 711 | struct uni_table_desc *directory = (struct uni_table_desc *) &unirom[0]; |
| 712 | __le32 fw_file_size = adapter->fw->size; |
| 713 | __le32 entries; |
| 714 | __le32 entry_size; |
| 715 | __le32 tab_size; |
| 716 | |
| 717 | if (fw_file_size < FILEHEADER_SIZE) |
| 718 | return -EINVAL; |
| 719 | |
| 720 | entries = cpu_to_le32(directory->num_entries); |
| 721 | entry_size = cpu_to_le32(directory->entry_size); |
| 722 | tab_size = cpu_to_le32(directory->findex) + (entries * entry_size); |
| 723 | |
| 724 | if (fw_file_size < tab_size) |
| 725 | return -EINVAL; |
| 726 | |
| 727 | return 0; |
| 728 | } |
| 729 | |
| 730 | static int |
| 731 | qlcnic_validate_bootld(struct qlcnic_adapter *adapter) |
| 732 | { |
| 733 | struct uni_table_desc *tab_desc; |
| 734 | struct uni_data_desc *descr; |
| 735 | const u8 *unirom = adapter->fw->data; |
| 736 | int idx = cpu_to_le32(*((int *)&unirom[adapter->file_prd_off] + |
| 737 | QLCNIC_UNI_BOOTLD_IDX_OFF)); |
| 738 | __le32 offs; |
| 739 | __le32 tab_size; |
| 740 | __le32 data_size; |
| 741 | |
| 742 | tab_desc = qlcnic_get_table_desc(unirom, QLCNIC_UNI_DIR_SECT_BOOTLD); |
| 743 | |
| 744 | if (!tab_desc) |
| 745 | return -EINVAL; |
| 746 | |
| 747 | tab_size = cpu_to_le32(tab_desc->findex) + |
Amit Kumar Salecha | 22dfaa8 | 2010-04-01 19:01:35 +0000 | [diff] [blame] | 748 | (cpu_to_le32(tab_desc->entry_size) * (idx + 1)); |
Sucheta Chakraborty | b7eff10 | 2010-03-08 00:14:48 +0000 | [diff] [blame] | 749 | |
| 750 | if (adapter->fw->size < tab_size) |
| 751 | return -EINVAL; |
| 752 | |
| 753 | offs = cpu_to_le32(tab_desc->findex) + |
| 754 | (cpu_to_le32(tab_desc->entry_size) * (idx)); |
| 755 | descr = (struct uni_data_desc *)&unirom[offs]; |
| 756 | |
Amit Kumar Salecha | 22dfaa8 | 2010-04-01 19:01:35 +0000 | [diff] [blame] | 757 | data_size = cpu_to_le32(descr->findex) + cpu_to_le32(descr->size); |
Sucheta Chakraborty | b7eff10 | 2010-03-08 00:14:48 +0000 | [diff] [blame] | 758 | |
| 759 | if (adapter->fw->size < data_size) |
| 760 | return -EINVAL; |
| 761 | |
| 762 | return 0; |
| 763 | } |
| 764 | |
| 765 | static int |
| 766 | qlcnic_validate_fw(struct qlcnic_adapter *adapter) |
| 767 | { |
| 768 | struct uni_table_desc *tab_desc; |
| 769 | struct uni_data_desc *descr; |
| 770 | const u8 *unirom = adapter->fw->data; |
| 771 | int idx = cpu_to_le32(*((int *)&unirom[adapter->file_prd_off] + |
| 772 | QLCNIC_UNI_FIRMWARE_IDX_OFF)); |
| 773 | __le32 offs; |
| 774 | __le32 tab_size; |
| 775 | __le32 data_size; |
| 776 | |
| 777 | tab_desc = qlcnic_get_table_desc(unirom, QLCNIC_UNI_DIR_SECT_FW); |
| 778 | |
| 779 | if (!tab_desc) |
| 780 | return -EINVAL; |
| 781 | |
| 782 | tab_size = cpu_to_le32(tab_desc->findex) + |
Amit Kumar Salecha | 22dfaa8 | 2010-04-01 19:01:35 +0000 | [diff] [blame] | 783 | (cpu_to_le32(tab_desc->entry_size) * (idx + 1)); |
Sucheta Chakraborty | b7eff10 | 2010-03-08 00:14:48 +0000 | [diff] [blame] | 784 | |
| 785 | if (adapter->fw->size < tab_size) |
| 786 | return -EINVAL; |
| 787 | |
| 788 | offs = cpu_to_le32(tab_desc->findex) + |
| 789 | (cpu_to_le32(tab_desc->entry_size) * (idx)); |
| 790 | descr = (struct uni_data_desc *)&unirom[offs]; |
Amit Kumar Salecha | 22dfaa8 | 2010-04-01 19:01:35 +0000 | [diff] [blame] | 791 | data_size = cpu_to_le32(descr->findex) + cpu_to_le32(descr->size); |
Sucheta Chakraborty | b7eff10 | 2010-03-08 00:14:48 +0000 | [diff] [blame] | 792 | |
| 793 | if (adapter->fw->size < data_size) |
| 794 | return -EINVAL; |
| 795 | |
| 796 | return 0; |
| 797 | } |
| 798 | |
| 799 | static int |
| 800 | qlcnic_validate_product_offs(struct qlcnic_adapter *adapter) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 801 | { |
| 802 | struct uni_table_desc *ptab_descr; |
| 803 | const u8 *unirom = adapter->fw->data; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 804 | int mn_present = qlcnic_has_mn(adapter); |
Sucheta Chakraborty | b7eff10 | 2010-03-08 00:14:48 +0000 | [diff] [blame] | 805 | __le32 entries; |
| 806 | __le32 entry_size; |
| 807 | __le32 tab_size; |
| 808 | u32 i; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 809 | |
| 810 | ptab_descr = qlcnic_get_table_desc(unirom, |
| 811 | QLCNIC_UNI_DIR_SECT_PRODUCT_TBL); |
Sucheta Chakraborty | b7eff10 | 2010-03-08 00:14:48 +0000 | [diff] [blame] | 812 | if (!ptab_descr) |
| 813 | return -EINVAL; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 814 | |
| 815 | entries = cpu_to_le32(ptab_descr->num_entries); |
Sucheta Chakraborty | b7eff10 | 2010-03-08 00:14:48 +0000 | [diff] [blame] | 816 | entry_size = cpu_to_le32(ptab_descr->entry_size); |
| 817 | tab_size = cpu_to_le32(ptab_descr->findex) + (entries * entry_size); |
| 818 | |
| 819 | if (adapter->fw->size < tab_size) |
| 820 | return -EINVAL; |
| 821 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 822 | nomn: |
| 823 | for (i = 0; i < entries; i++) { |
| 824 | |
| 825 | __le32 flags, file_chiprev, offs; |
| 826 | u8 chiprev = adapter->ahw.revision_id; |
| 827 | u32 flagbit; |
| 828 | |
| 829 | offs = cpu_to_le32(ptab_descr->findex) + |
| 830 | (i * cpu_to_le32(ptab_descr->entry_size)); |
| 831 | flags = cpu_to_le32(*((int *)&unirom[offs] + |
| 832 | QLCNIC_UNI_FLAGS_OFF)); |
| 833 | file_chiprev = cpu_to_le32(*((int *)&unirom[offs] + |
| 834 | QLCNIC_UNI_CHIP_REV_OFF)); |
| 835 | |
| 836 | flagbit = mn_present ? 1 : 2; |
| 837 | |
| 838 | if ((chiprev == file_chiprev) && |
| 839 | ((1ULL << flagbit) & flags)) { |
| 840 | adapter->file_prd_off = offs; |
| 841 | return 0; |
| 842 | } |
| 843 | } |
| 844 | if (mn_present) { |
| 845 | mn_present = 0; |
| 846 | goto nomn; |
| 847 | } |
Sucheta Chakraborty | b7eff10 | 2010-03-08 00:14:48 +0000 | [diff] [blame] | 848 | return -EINVAL; |
| 849 | } |
| 850 | |
| 851 | static int |
| 852 | qlcnic_validate_unified_romimage(struct qlcnic_adapter *adapter) |
| 853 | { |
| 854 | if (qlcnic_validate_header(adapter)) { |
| 855 | dev_err(&adapter->pdev->dev, |
| 856 | "unified image: header validation failed\n"); |
| 857 | return -EINVAL; |
| 858 | } |
| 859 | |
| 860 | if (qlcnic_validate_product_offs(adapter)) { |
| 861 | dev_err(&adapter->pdev->dev, |
| 862 | "unified image: product validation failed\n"); |
| 863 | return -EINVAL; |
| 864 | } |
| 865 | |
| 866 | if (qlcnic_validate_bootld(adapter)) { |
| 867 | dev_err(&adapter->pdev->dev, |
| 868 | "unified image: bootld validation failed\n"); |
| 869 | return -EINVAL; |
| 870 | } |
| 871 | |
| 872 | if (qlcnic_validate_fw(adapter)) { |
| 873 | dev_err(&adapter->pdev->dev, |
| 874 | "unified image: firmware validation failed\n"); |
| 875 | return -EINVAL; |
| 876 | } |
| 877 | |
| 878 | return 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | static |
| 882 | struct uni_data_desc *qlcnic_get_data_desc(struct qlcnic_adapter *adapter, |
| 883 | u32 section, u32 idx_offset) |
| 884 | { |
| 885 | const u8 *unirom = adapter->fw->data; |
| 886 | int idx = cpu_to_le32(*((int *)&unirom[adapter->file_prd_off] + |
| 887 | idx_offset)); |
| 888 | struct uni_table_desc *tab_desc; |
| 889 | __le32 offs; |
| 890 | |
| 891 | tab_desc = qlcnic_get_table_desc(unirom, section); |
| 892 | |
| 893 | if (tab_desc == NULL) |
| 894 | return NULL; |
| 895 | |
| 896 | offs = cpu_to_le32(tab_desc->findex) + |
| 897 | (cpu_to_le32(tab_desc->entry_size) * idx); |
| 898 | |
| 899 | return (struct uni_data_desc *)&unirom[offs]; |
| 900 | } |
| 901 | |
| 902 | static u8 * |
| 903 | qlcnic_get_bootld_offs(struct qlcnic_adapter *adapter) |
| 904 | { |
| 905 | u32 offs = QLCNIC_BOOTLD_START; |
| 906 | |
| 907 | if (adapter->fw_type == QLCNIC_UNIFIED_ROMIMAGE) |
| 908 | offs = cpu_to_le32((qlcnic_get_data_desc(adapter, |
| 909 | QLCNIC_UNI_DIR_SECT_BOOTLD, |
| 910 | QLCNIC_UNI_BOOTLD_IDX_OFF))->findex); |
| 911 | |
| 912 | return (u8 *)&adapter->fw->data[offs]; |
| 913 | } |
| 914 | |
| 915 | static u8 * |
| 916 | qlcnic_get_fw_offs(struct qlcnic_adapter *adapter) |
| 917 | { |
| 918 | u32 offs = QLCNIC_IMAGE_START; |
| 919 | |
| 920 | if (adapter->fw_type == QLCNIC_UNIFIED_ROMIMAGE) |
| 921 | offs = cpu_to_le32((qlcnic_get_data_desc(adapter, |
| 922 | QLCNIC_UNI_DIR_SECT_FW, |
| 923 | QLCNIC_UNI_FIRMWARE_IDX_OFF))->findex); |
| 924 | |
| 925 | return (u8 *)&adapter->fw->data[offs]; |
| 926 | } |
| 927 | |
| 928 | static __le32 |
| 929 | qlcnic_get_fw_size(struct qlcnic_adapter *adapter) |
| 930 | { |
| 931 | if (adapter->fw_type == QLCNIC_UNIFIED_ROMIMAGE) |
| 932 | return cpu_to_le32((qlcnic_get_data_desc(adapter, |
| 933 | QLCNIC_UNI_DIR_SECT_FW, |
| 934 | QLCNIC_UNI_FIRMWARE_IDX_OFF))->size); |
| 935 | else |
| 936 | return cpu_to_le32( |
| 937 | *(u32 *)&adapter->fw->data[QLCNIC_FW_SIZE_OFFSET]); |
| 938 | } |
| 939 | |
| 940 | static __le32 |
| 941 | qlcnic_get_fw_version(struct qlcnic_adapter *adapter) |
| 942 | { |
| 943 | struct uni_data_desc *fw_data_desc; |
| 944 | const struct firmware *fw = adapter->fw; |
| 945 | __le32 major, minor, sub; |
| 946 | const u8 *ver_str; |
| 947 | int i, ret; |
| 948 | |
| 949 | if (adapter->fw_type != QLCNIC_UNIFIED_ROMIMAGE) |
| 950 | return cpu_to_le32(*(u32 *)&fw->data[QLCNIC_FW_VERSION_OFFSET]); |
| 951 | |
| 952 | fw_data_desc = qlcnic_get_data_desc(adapter, QLCNIC_UNI_DIR_SECT_FW, |
| 953 | QLCNIC_UNI_FIRMWARE_IDX_OFF); |
| 954 | ver_str = fw->data + cpu_to_le32(fw_data_desc->findex) + |
| 955 | cpu_to_le32(fw_data_desc->size) - 17; |
| 956 | |
| 957 | for (i = 0; i < 12; i++) { |
| 958 | if (!strncmp(&ver_str[i], "REV=", 4)) { |
| 959 | ret = sscanf(&ver_str[i+4], "%u.%u.%u ", |
| 960 | &major, &minor, &sub); |
| 961 | if (ret != 3) |
| 962 | return 0; |
| 963 | else |
| 964 | return major + (minor << 8) + (sub << 16); |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | return 0; |
| 969 | } |
| 970 | |
| 971 | static __le32 |
| 972 | qlcnic_get_bios_version(struct qlcnic_adapter *adapter) |
| 973 | { |
| 974 | const struct firmware *fw = adapter->fw; |
| 975 | __le32 bios_ver, prd_off = adapter->file_prd_off; |
| 976 | |
| 977 | if (adapter->fw_type != QLCNIC_UNIFIED_ROMIMAGE) |
| 978 | return cpu_to_le32( |
| 979 | *(u32 *)&fw->data[QLCNIC_BIOS_VERSION_OFFSET]); |
| 980 | |
| 981 | bios_ver = cpu_to_le32(*((u32 *) (&fw->data[prd_off]) |
| 982 | + QLCNIC_UNI_BIOS_VERSION_OFF)); |
| 983 | |
Amit Kumar Salecha | addd5ab | 2010-03-08 00:14:49 +0000 | [diff] [blame] | 984 | return (bios_ver << 16) + ((bios_ver >> 8) & 0xff00) + (bios_ver >> 24); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 985 | } |
| 986 | |
Sucheta Chakraborty | 091754a | 2010-08-19 05:08:32 +0000 | [diff] [blame] | 987 | static void qlcnic_rom_lock_recovery(struct qlcnic_adapter *adapter) |
| 988 | { |
| 989 | if (qlcnic_pcie_sem_lock(adapter, 2, QLCNIC_ROM_LOCK_ID)) |
| 990 | dev_info(&adapter->pdev->dev, "Resetting rom_lock\n"); |
| 991 | |
| 992 | qlcnic_pcie_sem_unlock(adapter, 2); |
| 993 | } |
| 994 | |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame^] | 995 | static int |
| 996 | qlcnic_check_fw_hearbeat(struct qlcnic_adapter *adapter) |
| 997 | { |
| 998 | u32 heartbeat, ret = -EIO; |
| 999 | int retries = QLCNIC_HEARTBEAT_CHECK_RETRY_COUNT; |
| 1000 | |
| 1001 | adapter->heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); |
| 1002 | |
| 1003 | do { |
| 1004 | msleep(QLCNIC_HEARTBEAT_PERIOD_MSECS); |
| 1005 | heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); |
| 1006 | if (heartbeat != adapter->heartbeat) { |
| 1007 | ret = QLCNIC_RCODE_SUCCESS; |
| 1008 | break; |
| 1009 | } |
| 1010 | } while (--retries); |
| 1011 | |
| 1012 | return ret; |
| 1013 | } |
| 1014 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1015 | int |
| 1016 | qlcnic_need_fw_reset(struct qlcnic_adapter *adapter) |
| 1017 | { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1018 | u32 val, version, major, minor, build; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1019 | |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame^] | 1020 | if (qlcnic_check_fw_hearbeat(adapter)) { |
Sucheta Chakraborty | 091754a | 2010-08-19 05:08:32 +0000 | [diff] [blame] | 1021 | qlcnic_rom_lock_recovery(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1022 | return 1; |
Sucheta Chakraborty | 091754a | 2010-08-19 05:08:32 +0000 | [diff] [blame] | 1023 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1024 | |
Sucheta Chakraborty | 091754a | 2010-08-19 05:08:32 +0000 | [diff] [blame] | 1025 | if (adapter->need_fw_reset) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1026 | return 1; |
| 1027 | |
| 1028 | /* check if we have got newer or different file firmware */ |
| 1029 | if (adapter->fw) { |
| 1030 | |
| 1031 | val = qlcnic_get_fw_version(adapter); |
| 1032 | |
| 1033 | version = QLCNIC_DECODE_VERSION(val); |
| 1034 | |
| 1035 | major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR); |
| 1036 | minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR); |
| 1037 | build = QLCRD32(adapter, QLCNIC_FW_VERSION_SUB); |
| 1038 | |
| 1039 | if (version > QLCNIC_VERSION_CODE(major, minor, build)) |
| 1040 | return 1; |
| 1041 | } |
| 1042 | |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
| 1046 | static const char *fw_name[] = { |
| 1047 | QLCNIC_UNIFIED_ROMIMAGE_NAME, |
| 1048 | QLCNIC_FLASH_ROMIMAGE_NAME, |
| 1049 | }; |
| 1050 | |
| 1051 | int |
| 1052 | qlcnic_load_firmware(struct qlcnic_adapter *adapter) |
| 1053 | { |
| 1054 | u64 *ptr64; |
| 1055 | u32 i, flashaddr, size; |
| 1056 | const struct firmware *fw = adapter->fw; |
| 1057 | struct pci_dev *pdev = adapter->pdev; |
| 1058 | |
| 1059 | dev_info(&pdev->dev, "loading firmware from %s\n", |
| 1060 | fw_name[adapter->fw_type]); |
| 1061 | |
| 1062 | if (fw) { |
| 1063 | __le64 data; |
| 1064 | |
| 1065 | size = (QLCNIC_IMAGE_START - QLCNIC_BOOTLD_START) / 8; |
| 1066 | |
| 1067 | ptr64 = (u64 *)qlcnic_get_bootld_offs(adapter); |
| 1068 | flashaddr = QLCNIC_BOOTLD_START; |
| 1069 | |
| 1070 | for (i = 0; i < size; i++) { |
| 1071 | data = cpu_to_le64(ptr64[i]); |
| 1072 | |
| 1073 | if (qlcnic_pci_mem_write_2M(adapter, flashaddr, data)) |
| 1074 | return -EIO; |
| 1075 | |
| 1076 | flashaddr += 8; |
| 1077 | } |
| 1078 | |
| 1079 | size = (__force u32)qlcnic_get_fw_size(adapter) / 8; |
| 1080 | |
| 1081 | ptr64 = (u64 *)qlcnic_get_fw_offs(adapter); |
| 1082 | flashaddr = QLCNIC_IMAGE_START; |
| 1083 | |
| 1084 | for (i = 0; i < size; i++) { |
| 1085 | data = cpu_to_le64(ptr64[i]); |
| 1086 | |
| 1087 | if (qlcnic_pci_mem_write_2M(adapter, |
| 1088 | flashaddr, data)) |
| 1089 | return -EIO; |
| 1090 | |
| 1091 | flashaddr += 8; |
| 1092 | } |
Amit Kumar Salecha | 0bc92b5 | 2010-04-01 19:01:28 +0000 | [diff] [blame] | 1093 | |
| 1094 | size = (__force u32)qlcnic_get_fw_size(adapter) % 8; |
| 1095 | if (size) { |
| 1096 | data = cpu_to_le64(ptr64[i]); |
| 1097 | |
| 1098 | if (qlcnic_pci_mem_write_2M(adapter, |
| 1099 | flashaddr, data)) |
| 1100 | return -EIO; |
| 1101 | } |
| 1102 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1103 | } else { |
| 1104 | u64 data; |
| 1105 | u32 hi, lo; |
| 1106 | |
| 1107 | size = (QLCNIC_IMAGE_START - QLCNIC_BOOTLD_START) / 8; |
| 1108 | flashaddr = QLCNIC_BOOTLD_START; |
| 1109 | |
| 1110 | for (i = 0; i < size; i++) { |
| 1111 | if (qlcnic_rom_fast_read(adapter, |
| 1112 | flashaddr, (int *)&lo) != 0) |
| 1113 | return -EIO; |
| 1114 | if (qlcnic_rom_fast_read(adapter, |
| 1115 | flashaddr + 4, (int *)&hi) != 0) |
| 1116 | return -EIO; |
| 1117 | |
| 1118 | data = (((u64)hi << 32) | lo); |
| 1119 | |
| 1120 | if (qlcnic_pci_mem_write_2M(adapter, |
| 1121 | flashaddr, data)) |
| 1122 | return -EIO; |
| 1123 | |
| 1124 | flashaddr += 8; |
| 1125 | } |
| 1126 | } |
| 1127 | msleep(1); |
| 1128 | |
| 1129 | QLCWR32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x18, 0x1020); |
| 1130 | QLCWR32(adapter, QLCNIC_ROMUSB_GLB_SW_RESET, 0x80001e); |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
| 1134 | static int |
| 1135 | qlcnic_validate_firmware(struct qlcnic_adapter *adapter) |
| 1136 | { |
| 1137 | __le32 val; |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 1138 | u32 ver, bios, min_size; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1139 | struct pci_dev *pdev = adapter->pdev; |
| 1140 | const struct firmware *fw = adapter->fw; |
| 1141 | u8 fw_type = adapter->fw_type; |
| 1142 | |
| 1143 | if (fw_type == QLCNIC_UNIFIED_ROMIMAGE) { |
Sucheta Chakraborty | b7eff10 | 2010-03-08 00:14:48 +0000 | [diff] [blame] | 1144 | if (qlcnic_validate_unified_romimage(adapter)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1145 | return -EINVAL; |
| 1146 | |
| 1147 | min_size = QLCNIC_UNI_FW_MIN_SIZE; |
| 1148 | } else { |
| 1149 | val = cpu_to_le32(*(u32 *)&fw->data[QLCNIC_FW_MAGIC_OFFSET]); |
| 1150 | if ((__force u32)val != QLCNIC_BDINFO_MAGIC) |
| 1151 | return -EINVAL; |
| 1152 | |
| 1153 | min_size = QLCNIC_FW_MIN_SIZE; |
| 1154 | } |
| 1155 | |
| 1156 | if (fw->size < min_size) |
| 1157 | return -EINVAL; |
| 1158 | |
| 1159 | val = qlcnic_get_fw_version(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1160 | ver = QLCNIC_DECODE_VERSION(val); |
| 1161 | |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 1162 | if (ver < QLCNIC_MIN_FW_VERSION) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1163 | dev_err(&pdev->dev, |
| 1164 | "%s: firmware version %d.%d.%d unsupported\n", |
| 1165 | fw_name[fw_type], _major(ver), _minor(ver), _build(ver)); |
| 1166 | return -EINVAL; |
| 1167 | } |
| 1168 | |
| 1169 | val = qlcnic_get_bios_version(adapter); |
| 1170 | qlcnic_rom_fast_read(adapter, QLCNIC_BIOS_VERSION_OFFSET, (int *)&bios); |
| 1171 | if ((__force u32)val != bios) { |
| 1172 | dev_err(&pdev->dev, "%s: firmware bios is incompatible\n", |
| 1173 | fw_name[fw_type]); |
| 1174 | return -EINVAL; |
| 1175 | } |
| 1176 | |
| 1177 | /* check if flashed firmware is newer */ |
| 1178 | if (qlcnic_rom_fast_read(adapter, |
| 1179 | QLCNIC_FW_VERSION_OFFSET, (int *)&val)) |
| 1180 | return -EIO; |
| 1181 | |
| 1182 | val = QLCNIC_DECODE_VERSION(val); |
| 1183 | if (val > ver) { |
| 1184 | dev_info(&pdev->dev, "%s: firmware is older than flash\n", |
| 1185 | fw_name[fw_type]); |
| 1186 | return -EINVAL; |
| 1187 | } |
| 1188 | |
| 1189 | QLCWR32(adapter, QLCNIC_CAM_RAM(0x1fc), QLCNIC_BDINFO_MAGIC); |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
| 1193 | static void |
| 1194 | qlcnic_get_next_fwtype(struct qlcnic_adapter *adapter) |
| 1195 | { |
| 1196 | u8 fw_type; |
| 1197 | |
| 1198 | switch (adapter->fw_type) { |
| 1199 | case QLCNIC_UNKNOWN_ROMIMAGE: |
| 1200 | fw_type = QLCNIC_UNIFIED_ROMIMAGE; |
| 1201 | break; |
| 1202 | |
| 1203 | case QLCNIC_UNIFIED_ROMIMAGE: |
| 1204 | default: |
| 1205 | fw_type = QLCNIC_FLASH_ROMIMAGE; |
| 1206 | break; |
| 1207 | } |
| 1208 | |
| 1209 | adapter->fw_type = fw_type; |
| 1210 | } |
| 1211 | |
| 1212 | |
| 1213 | |
| 1214 | void qlcnic_request_firmware(struct qlcnic_adapter *adapter) |
| 1215 | { |
| 1216 | struct pci_dev *pdev = adapter->pdev; |
| 1217 | int rc; |
| 1218 | |
| 1219 | adapter->fw_type = QLCNIC_UNKNOWN_ROMIMAGE; |
| 1220 | |
| 1221 | next: |
| 1222 | qlcnic_get_next_fwtype(adapter); |
| 1223 | |
| 1224 | if (adapter->fw_type == QLCNIC_FLASH_ROMIMAGE) { |
| 1225 | adapter->fw = NULL; |
| 1226 | } else { |
| 1227 | rc = request_firmware(&adapter->fw, |
| 1228 | fw_name[adapter->fw_type], &pdev->dev); |
| 1229 | if (rc != 0) |
| 1230 | goto next; |
| 1231 | |
| 1232 | rc = qlcnic_validate_firmware(adapter); |
| 1233 | if (rc != 0) { |
| 1234 | release_firmware(adapter->fw); |
| 1235 | msleep(1); |
| 1236 | goto next; |
| 1237 | } |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | |
| 1242 | void |
| 1243 | qlcnic_release_firmware(struct qlcnic_adapter *adapter) |
| 1244 | { |
| 1245 | if (adapter->fw) |
| 1246 | release_firmware(adapter->fw); |
| 1247 | adapter->fw = NULL; |
| 1248 | } |
| 1249 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1250 | static void |
| 1251 | qlcnic_handle_linkevent(struct qlcnic_adapter *adapter, |
| 1252 | struct qlcnic_fw_msg *msg) |
| 1253 | { |
| 1254 | u32 cable_OUI; |
| 1255 | u16 cable_len; |
| 1256 | u16 link_speed; |
| 1257 | u8 link_status, module, duplex, autoneg; |
| 1258 | struct net_device *netdev = adapter->netdev; |
| 1259 | |
| 1260 | adapter->has_link_events = 1; |
| 1261 | |
| 1262 | cable_OUI = msg->body[1] & 0xffffffff; |
| 1263 | cable_len = (msg->body[1] >> 32) & 0xffff; |
| 1264 | link_speed = (msg->body[1] >> 48) & 0xffff; |
| 1265 | |
| 1266 | link_status = msg->body[2] & 0xff; |
| 1267 | duplex = (msg->body[2] >> 16) & 0xff; |
| 1268 | autoneg = (msg->body[2] >> 24) & 0xff; |
| 1269 | |
| 1270 | module = (msg->body[2] >> 8) & 0xff; |
| 1271 | if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE) |
| 1272 | dev_info(&netdev->dev, "unsupported cable: OUI 0x%x, " |
| 1273 | "length %d\n", cable_OUI, cable_len); |
| 1274 | else if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN) |
| 1275 | dev_info(&netdev->dev, "unsupported cable length %d\n", |
| 1276 | cable_len); |
| 1277 | |
| 1278 | qlcnic_advert_link_change(adapter, link_status); |
| 1279 | |
| 1280 | if (duplex == LINKEVENT_FULL_DUPLEX) |
| 1281 | adapter->link_duplex = DUPLEX_FULL; |
| 1282 | else |
| 1283 | adapter->link_duplex = DUPLEX_HALF; |
| 1284 | |
| 1285 | adapter->module_type = module; |
| 1286 | adapter->link_autoneg = autoneg; |
| 1287 | adapter->link_speed = link_speed; |
| 1288 | } |
| 1289 | |
| 1290 | static void |
| 1291 | qlcnic_handle_fw_message(int desc_cnt, int index, |
| 1292 | struct qlcnic_host_sds_ring *sds_ring) |
| 1293 | { |
| 1294 | struct qlcnic_fw_msg msg; |
| 1295 | struct status_desc *desc; |
| 1296 | int i = 0, opcode; |
| 1297 | |
| 1298 | while (desc_cnt > 0 && i < 8) { |
| 1299 | desc = &sds_ring->desc_head[index]; |
| 1300 | msg.words[i++] = le64_to_cpu(desc->status_desc_data[0]); |
| 1301 | msg.words[i++] = le64_to_cpu(desc->status_desc_data[1]); |
| 1302 | |
| 1303 | index = get_next_index(index, sds_ring->num_desc); |
| 1304 | desc_cnt--; |
| 1305 | } |
| 1306 | |
| 1307 | opcode = qlcnic_get_nic_msg_opcode(msg.body[0]); |
| 1308 | switch (opcode) { |
| 1309 | case QLCNIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE: |
| 1310 | qlcnic_handle_linkevent(sds_ring->adapter, &msg); |
| 1311 | break; |
| 1312 | default: |
| 1313 | break; |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | static int |
| 1318 | qlcnic_alloc_rx_skb(struct qlcnic_adapter *adapter, |
| 1319 | struct qlcnic_host_rds_ring *rds_ring, |
| 1320 | struct qlcnic_rx_buffer *buffer) |
| 1321 | { |
| 1322 | struct sk_buff *skb; |
| 1323 | dma_addr_t dma; |
| 1324 | struct pci_dev *pdev = adapter->pdev; |
| 1325 | |
Amit Kumar Salecha | 9665982 | 2010-06-22 03:18:58 +0000 | [diff] [blame] | 1326 | skb = dev_alloc_skb(rds_ring->skb_size); |
| 1327 | if (!skb) { |
Sucheta Chakraborty | 8bfe8b9 | 2010-03-08 00:14:46 +0000 | [diff] [blame] | 1328 | adapter->stats.skb_alloc_failure++; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1329 | return -ENOMEM; |
Sucheta Chakraborty | 8bfe8b9 | 2010-03-08 00:14:46 +0000 | [diff] [blame] | 1330 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1331 | |
Amit Kumar Salecha | 251a84c | 2010-05-13 03:07:46 +0000 | [diff] [blame] | 1332 | skb_reserve(skb, 2); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1333 | |
| 1334 | dma = pci_map_single(pdev, skb->data, |
| 1335 | rds_ring->dma_size, PCI_DMA_FROMDEVICE); |
| 1336 | |
| 1337 | if (pci_dma_mapping_error(pdev, dma)) { |
Amit Kumar Salecha | 8ae6df9 | 2010-04-22 02:51:35 +0000 | [diff] [blame] | 1338 | adapter->stats.rx_dma_map_error++; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1339 | dev_kfree_skb_any(skb); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1340 | return -ENOMEM; |
| 1341 | } |
| 1342 | |
| 1343 | buffer->skb = skb; |
| 1344 | buffer->dma = dma; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1345 | |
| 1346 | return 0; |
| 1347 | } |
| 1348 | |
| 1349 | static struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *adapter, |
| 1350 | struct qlcnic_host_rds_ring *rds_ring, u16 index, u16 cksum) |
| 1351 | { |
| 1352 | struct qlcnic_rx_buffer *buffer; |
| 1353 | struct sk_buff *skb; |
| 1354 | |
| 1355 | buffer = &rds_ring->rx_buf_arr[index]; |
| 1356 | |
Amit Kumar Salecha | 9665982 | 2010-06-22 03:18:58 +0000 | [diff] [blame] | 1357 | if (unlikely(buffer->skb == NULL)) { |
| 1358 | WARN_ON(1); |
| 1359 | return NULL; |
| 1360 | } |
| 1361 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1362 | pci_unmap_single(adapter->pdev, buffer->dma, rds_ring->dma_size, |
| 1363 | PCI_DMA_FROMDEVICE); |
| 1364 | |
| 1365 | skb = buffer->skb; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1366 | |
| 1367 | if (likely(adapter->rx_csum && cksum == STATUS_CKSUM_OK)) { |
| 1368 | adapter->stats.csummed++; |
| 1369 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1370 | } else { |
| 1371 | skb->ip_summed = CHECKSUM_NONE; |
| 1372 | } |
| 1373 | |
| 1374 | skb->dev = adapter->netdev; |
| 1375 | |
| 1376 | buffer->skb = NULL; |
Amit Kumar Salecha | 9665982 | 2010-06-22 03:18:58 +0000 | [diff] [blame] | 1377 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1378 | return skb; |
| 1379 | } |
| 1380 | |
Amit Kumar Salecha | 8cf61f8 | 2010-08-25 04:03:03 +0000 | [diff] [blame] | 1381 | static int |
| 1382 | qlcnic_check_rx_tagging(struct qlcnic_adapter *adapter, struct sk_buff *skb) |
| 1383 | { |
| 1384 | u16 vlan_tag; |
| 1385 | struct ethhdr *eth_hdr; |
| 1386 | |
| 1387 | if (!__vlan_get_tag(skb, &vlan_tag)) { |
| 1388 | if (vlan_tag == adapter->pvid) { |
| 1389 | /* strip the tag from the packet and send it up */ |
| 1390 | eth_hdr = (struct ethhdr *) skb->data; |
| 1391 | memmove(skb->data + VLAN_HLEN, eth_hdr, ETH_ALEN * 2); |
| 1392 | skb_pull(skb, VLAN_HLEN); |
| 1393 | return 0; |
| 1394 | } |
| 1395 | } |
| 1396 | if (adapter->flags & QLCNIC_TAGGING_ENABLED) |
| 1397 | return 0; |
| 1398 | |
| 1399 | return -EIO; |
| 1400 | } |
| 1401 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1402 | static struct qlcnic_rx_buffer * |
| 1403 | qlcnic_process_rcv(struct qlcnic_adapter *adapter, |
| 1404 | struct qlcnic_host_sds_ring *sds_ring, |
| 1405 | int ring, u64 sts_data0) |
| 1406 | { |
| 1407 | struct net_device *netdev = adapter->netdev; |
| 1408 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 1409 | struct qlcnic_rx_buffer *buffer; |
| 1410 | struct sk_buff *skb; |
| 1411 | struct qlcnic_host_rds_ring *rds_ring; |
| 1412 | int index, length, cksum, pkt_offset; |
| 1413 | |
| 1414 | if (unlikely(ring >= adapter->max_rds_rings)) |
| 1415 | return NULL; |
| 1416 | |
| 1417 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 1418 | |
| 1419 | index = qlcnic_get_sts_refhandle(sts_data0); |
| 1420 | if (unlikely(index >= rds_ring->num_desc)) |
| 1421 | return NULL; |
| 1422 | |
| 1423 | buffer = &rds_ring->rx_buf_arr[index]; |
| 1424 | |
| 1425 | length = qlcnic_get_sts_totallength(sts_data0); |
| 1426 | cksum = qlcnic_get_sts_status(sts_data0); |
| 1427 | pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0); |
| 1428 | |
| 1429 | skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum); |
| 1430 | if (!skb) |
| 1431 | return buffer; |
| 1432 | |
| 1433 | if (length > rds_ring->skb_size) |
| 1434 | skb_put(skb, rds_ring->skb_size); |
| 1435 | else |
| 1436 | skb_put(skb, length); |
| 1437 | |
| 1438 | if (pkt_offset) |
| 1439 | skb_pull(skb, pkt_offset); |
| 1440 | |
| 1441 | skb->truesize = skb->len + sizeof(struct sk_buff); |
Amit Kumar Salecha | 8cf61f8 | 2010-08-25 04:03:03 +0000 | [diff] [blame] | 1442 | |
| 1443 | if (unlikely(adapter->pvid)) { |
| 1444 | if (qlcnic_check_rx_tagging(adapter, skb)) { |
| 1445 | adapter->stats.rxdropped++; |
| 1446 | dev_kfree_skb_any(skb); |
| 1447 | return buffer; |
| 1448 | } |
| 1449 | } |
| 1450 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1451 | skb->protocol = eth_type_trans(skb, netdev); |
| 1452 | |
| 1453 | napi_gro_receive(&sds_ring->napi, skb); |
| 1454 | |
| 1455 | adapter->stats.rx_pkts++; |
| 1456 | adapter->stats.rxbytes += length; |
| 1457 | |
| 1458 | return buffer; |
| 1459 | } |
| 1460 | |
| 1461 | #define QLC_TCP_HDR_SIZE 20 |
| 1462 | #define QLC_TCP_TS_OPTION_SIZE 12 |
| 1463 | #define QLC_TCP_TS_HDR_SIZE (QLC_TCP_HDR_SIZE + QLC_TCP_TS_OPTION_SIZE) |
| 1464 | |
| 1465 | static struct qlcnic_rx_buffer * |
| 1466 | qlcnic_process_lro(struct qlcnic_adapter *adapter, |
| 1467 | struct qlcnic_host_sds_ring *sds_ring, |
| 1468 | int ring, u64 sts_data0, u64 sts_data1) |
| 1469 | { |
| 1470 | struct net_device *netdev = adapter->netdev; |
| 1471 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 1472 | struct qlcnic_rx_buffer *buffer; |
| 1473 | struct sk_buff *skb; |
| 1474 | struct qlcnic_host_rds_ring *rds_ring; |
| 1475 | struct iphdr *iph; |
| 1476 | struct tcphdr *th; |
| 1477 | bool push, timestamp; |
| 1478 | int l2_hdr_offset, l4_hdr_offset; |
| 1479 | int index; |
| 1480 | u16 lro_length, length, data_offset; |
| 1481 | u32 seq_number; |
| 1482 | |
| 1483 | if (unlikely(ring > adapter->max_rds_rings)) |
| 1484 | return NULL; |
| 1485 | |
| 1486 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 1487 | |
| 1488 | index = qlcnic_get_lro_sts_refhandle(sts_data0); |
| 1489 | if (unlikely(index > rds_ring->num_desc)) |
| 1490 | return NULL; |
| 1491 | |
| 1492 | buffer = &rds_ring->rx_buf_arr[index]; |
| 1493 | |
| 1494 | timestamp = qlcnic_get_lro_sts_timestamp(sts_data0); |
| 1495 | lro_length = qlcnic_get_lro_sts_length(sts_data0); |
| 1496 | l2_hdr_offset = qlcnic_get_lro_sts_l2_hdr_offset(sts_data0); |
| 1497 | l4_hdr_offset = qlcnic_get_lro_sts_l4_hdr_offset(sts_data0); |
| 1498 | push = qlcnic_get_lro_sts_push_flag(sts_data0); |
| 1499 | seq_number = qlcnic_get_lro_sts_seq_number(sts_data1); |
| 1500 | |
| 1501 | skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK); |
| 1502 | if (!skb) |
| 1503 | return buffer; |
| 1504 | |
| 1505 | if (timestamp) |
| 1506 | data_offset = l4_hdr_offset + QLC_TCP_TS_HDR_SIZE; |
| 1507 | else |
| 1508 | data_offset = l4_hdr_offset + QLC_TCP_HDR_SIZE; |
| 1509 | |
| 1510 | skb_put(skb, lro_length + data_offset); |
| 1511 | |
| 1512 | skb->truesize = skb->len + sizeof(struct sk_buff) + skb_headroom(skb); |
| 1513 | |
| 1514 | skb_pull(skb, l2_hdr_offset); |
Amit Kumar Salecha | 8cf61f8 | 2010-08-25 04:03:03 +0000 | [diff] [blame] | 1515 | |
| 1516 | if (unlikely(adapter->pvid)) { |
| 1517 | if (qlcnic_check_rx_tagging(adapter, skb)) { |
| 1518 | adapter->stats.rxdropped++; |
| 1519 | dev_kfree_skb_any(skb); |
| 1520 | return buffer; |
| 1521 | } |
| 1522 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1523 | skb->protocol = eth_type_trans(skb, netdev); |
| 1524 | |
| 1525 | iph = (struct iphdr *)skb->data; |
| 1526 | th = (struct tcphdr *)(skb->data + (iph->ihl << 2)); |
| 1527 | |
| 1528 | length = (iph->ihl << 2) + (th->doff << 2) + lro_length; |
| 1529 | iph->tot_len = htons(length); |
| 1530 | iph->check = 0; |
| 1531 | iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); |
| 1532 | th->psh = push; |
| 1533 | th->seq = htonl(seq_number); |
| 1534 | |
| 1535 | length = skb->len; |
| 1536 | |
| 1537 | netif_receive_skb(skb); |
| 1538 | |
| 1539 | adapter->stats.lro_pkts++; |
Sucheta Chakraborty | 8bfe8b9 | 2010-03-08 00:14:46 +0000 | [diff] [blame] | 1540 | adapter->stats.lrobytes += length; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1541 | |
| 1542 | return buffer; |
| 1543 | } |
| 1544 | |
| 1545 | int |
| 1546 | qlcnic_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring, int max) |
| 1547 | { |
| 1548 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1549 | struct list_head *cur; |
| 1550 | struct status_desc *desc; |
| 1551 | struct qlcnic_rx_buffer *rxbuf; |
| 1552 | u64 sts_data0, sts_data1; |
| 1553 | |
| 1554 | int count = 0; |
| 1555 | int opcode, ring, desc_cnt; |
| 1556 | u32 consumer = sds_ring->consumer; |
| 1557 | |
| 1558 | while (count < max) { |
| 1559 | desc = &sds_ring->desc_head[consumer]; |
| 1560 | sts_data0 = le64_to_cpu(desc->status_desc_data[0]); |
| 1561 | |
| 1562 | if (!(sts_data0 & STATUS_OWNER_HOST)) |
| 1563 | break; |
| 1564 | |
| 1565 | desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0); |
| 1566 | opcode = qlcnic_get_sts_opcode(sts_data0); |
| 1567 | |
| 1568 | switch (opcode) { |
| 1569 | case QLCNIC_RXPKT_DESC: |
| 1570 | case QLCNIC_OLD_RXPKT_DESC: |
| 1571 | case QLCNIC_SYN_OFFLOAD: |
| 1572 | ring = qlcnic_get_sts_type(sts_data0); |
| 1573 | rxbuf = qlcnic_process_rcv(adapter, sds_ring, |
| 1574 | ring, sts_data0); |
| 1575 | break; |
| 1576 | case QLCNIC_LRO_DESC: |
| 1577 | ring = qlcnic_get_lro_sts_type(sts_data0); |
| 1578 | sts_data1 = le64_to_cpu(desc->status_desc_data[1]); |
| 1579 | rxbuf = qlcnic_process_lro(adapter, sds_ring, |
| 1580 | ring, sts_data0, sts_data1); |
| 1581 | break; |
| 1582 | case QLCNIC_RESPONSE_DESC: |
| 1583 | qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring); |
| 1584 | default: |
| 1585 | goto skip; |
| 1586 | } |
| 1587 | |
| 1588 | WARN_ON(desc_cnt > 1); |
| 1589 | |
Amit Kumar Salecha | 9665982 | 2010-06-22 03:18:58 +0000 | [diff] [blame] | 1590 | if (likely(rxbuf)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1591 | list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]); |
Amit Kumar Salecha | 8ae6df9 | 2010-04-22 02:51:35 +0000 | [diff] [blame] | 1592 | else |
| 1593 | adapter->stats.null_rxbuf++; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1594 | |
| 1595 | skip: |
| 1596 | for (; desc_cnt > 0; desc_cnt--) { |
| 1597 | desc = &sds_ring->desc_head[consumer]; |
| 1598 | desc->status_desc_data[0] = |
| 1599 | cpu_to_le64(STATUS_OWNER_PHANTOM); |
| 1600 | consumer = get_next_index(consumer, sds_ring->num_desc); |
| 1601 | } |
| 1602 | count++; |
| 1603 | } |
| 1604 | |
| 1605 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 1606 | struct qlcnic_host_rds_ring *rds_ring = |
| 1607 | &adapter->recv_ctx.rds_rings[ring]; |
| 1608 | |
| 1609 | if (!list_empty(&sds_ring->free_list[ring])) { |
| 1610 | list_for_each(cur, &sds_ring->free_list[ring]) { |
| 1611 | rxbuf = list_entry(cur, |
| 1612 | struct qlcnic_rx_buffer, list); |
| 1613 | qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf); |
| 1614 | } |
| 1615 | spin_lock(&rds_ring->lock); |
| 1616 | list_splice_tail_init(&sds_ring->free_list[ring], |
| 1617 | &rds_ring->free_list); |
| 1618 | spin_unlock(&rds_ring->lock); |
| 1619 | } |
| 1620 | |
| 1621 | qlcnic_post_rx_buffers_nodb(adapter, rds_ring); |
| 1622 | } |
| 1623 | |
| 1624 | if (count) { |
| 1625 | sds_ring->consumer = consumer; |
| 1626 | writel(consumer, sds_ring->crb_sts_consumer); |
| 1627 | } |
| 1628 | |
| 1629 | return count; |
| 1630 | } |
| 1631 | |
| 1632 | void |
| 1633 | qlcnic_post_rx_buffers(struct qlcnic_adapter *adapter, u32 ringid, |
| 1634 | struct qlcnic_host_rds_ring *rds_ring) |
| 1635 | { |
| 1636 | struct rcv_desc *pdesc; |
| 1637 | struct qlcnic_rx_buffer *buffer; |
| 1638 | int producer, count = 0; |
| 1639 | struct list_head *head; |
| 1640 | |
| 1641 | producer = rds_ring->producer; |
| 1642 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1643 | head = &rds_ring->free_list; |
| 1644 | while (!list_empty(head)) { |
| 1645 | |
| 1646 | buffer = list_entry(head->next, struct qlcnic_rx_buffer, list); |
| 1647 | |
| 1648 | if (!buffer->skb) { |
| 1649 | if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer)) |
| 1650 | break; |
| 1651 | } |
| 1652 | |
| 1653 | count++; |
| 1654 | list_del(&buffer->list); |
| 1655 | |
| 1656 | /* make a rcv descriptor */ |
| 1657 | pdesc = &rds_ring->desc_head[producer]; |
| 1658 | pdesc->addr_buffer = cpu_to_le64(buffer->dma); |
| 1659 | pdesc->reference_handle = cpu_to_le16(buffer->ref_handle); |
| 1660 | pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size); |
| 1661 | |
| 1662 | producer = get_next_index(producer, rds_ring->num_desc); |
| 1663 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1664 | |
| 1665 | if (count) { |
| 1666 | rds_ring->producer = producer; |
| 1667 | writel((producer-1) & (rds_ring->num_desc-1), |
| 1668 | rds_ring->crb_rcv_producer); |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | static void |
| 1673 | qlcnic_post_rx_buffers_nodb(struct qlcnic_adapter *adapter, |
| 1674 | struct qlcnic_host_rds_ring *rds_ring) |
| 1675 | { |
| 1676 | struct rcv_desc *pdesc; |
| 1677 | struct qlcnic_rx_buffer *buffer; |
| 1678 | int producer, count = 0; |
| 1679 | struct list_head *head; |
| 1680 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1681 | if (!spin_trylock(&rds_ring->lock)) |
| 1682 | return; |
| 1683 | |
Amit Kumar Salecha | ed6f135 | 2010-04-22 02:51:40 +0000 | [diff] [blame] | 1684 | producer = rds_ring->producer; |
| 1685 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1686 | head = &rds_ring->free_list; |
| 1687 | while (!list_empty(head)) { |
| 1688 | |
| 1689 | buffer = list_entry(head->next, struct qlcnic_rx_buffer, list); |
| 1690 | |
| 1691 | if (!buffer->skb) { |
| 1692 | if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer)) |
| 1693 | break; |
| 1694 | } |
| 1695 | |
| 1696 | count++; |
| 1697 | list_del(&buffer->list); |
| 1698 | |
| 1699 | /* make a rcv descriptor */ |
| 1700 | pdesc = &rds_ring->desc_head[producer]; |
| 1701 | pdesc->reference_handle = cpu_to_le16(buffer->ref_handle); |
| 1702 | pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size); |
| 1703 | pdesc->addr_buffer = cpu_to_le64(buffer->dma); |
| 1704 | |
| 1705 | producer = get_next_index(producer, rds_ring->num_desc); |
| 1706 | } |
| 1707 | |
| 1708 | if (count) { |
| 1709 | rds_ring->producer = producer; |
| 1710 | writel((producer - 1) & (rds_ring->num_desc - 1), |
| 1711 | rds_ring->crb_rcv_producer); |
| 1712 | } |
| 1713 | spin_unlock(&rds_ring->lock); |
| 1714 | } |
| 1715 | |
Amit Kumar Salecha | cdaff18 | 2010-02-01 05:25:00 +0000 | [diff] [blame] | 1716 | static struct qlcnic_rx_buffer * |
| 1717 | qlcnic_process_rcv_diag(struct qlcnic_adapter *adapter, |
| 1718 | struct qlcnic_host_sds_ring *sds_ring, |
| 1719 | int ring, u64 sts_data0) |
| 1720 | { |
| 1721 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 1722 | struct qlcnic_rx_buffer *buffer; |
| 1723 | struct sk_buff *skb; |
| 1724 | struct qlcnic_host_rds_ring *rds_ring; |
| 1725 | int index, length, cksum, pkt_offset; |
| 1726 | |
| 1727 | if (unlikely(ring >= adapter->max_rds_rings)) |
| 1728 | return NULL; |
| 1729 | |
| 1730 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 1731 | |
| 1732 | index = qlcnic_get_sts_refhandle(sts_data0); |
| 1733 | if (unlikely(index >= rds_ring->num_desc)) |
| 1734 | return NULL; |
| 1735 | |
| 1736 | buffer = &rds_ring->rx_buf_arr[index]; |
| 1737 | |
| 1738 | length = qlcnic_get_sts_totallength(sts_data0); |
| 1739 | cksum = qlcnic_get_sts_status(sts_data0); |
| 1740 | pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0); |
| 1741 | |
| 1742 | skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum); |
| 1743 | if (!skb) |
| 1744 | return buffer; |
| 1745 | |
| 1746 | skb_put(skb, rds_ring->skb_size); |
| 1747 | |
| 1748 | if (pkt_offset) |
| 1749 | skb_pull(skb, pkt_offset); |
| 1750 | |
| 1751 | skb->truesize = skb->len + sizeof(struct sk_buff); |
| 1752 | |
| 1753 | if (!qlcnic_check_loopback_buff(skb->data)) |
| 1754 | adapter->diag_cnt++; |
| 1755 | |
| 1756 | dev_kfree_skb_any(skb); |
Sucheta Chakraborty | 8bfe8b9 | 2010-03-08 00:14:46 +0000 | [diff] [blame] | 1757 | adapter->stats.rx_pkts++; |
| 1758 | adapter->stats.rxbytes += length; |
Amit Kumar Salecha | cdaff18 | 2010-02-01 05:25:00 +0000 | [diff] [blame] | 1759 | |
| 1760 | return buffer; |
| 1761 | } |
| 1762 | |
| 1763 | void |
| 1764 | qlcnic_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring) |
| 1765 | { |
| 1766 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1767 | struct status_desc *desc; |
| 1768 | struct qlcnic_rx_buffer *rxbuf; |
| 1769 | u64 sts_data0; |
| 1770 | |
| 1771 | int opcode, ring, desc_cnt; |
| 1772 | u32 consumer = sds_ring->consumer; |
| 1773 | |
| 1774 | desc = &sds_ring->desc_head[consumer]; |
| 1775 | sts_data0 = le64_to_cpu(desc->status_desc_data[0]); |
| 1776 | |
| 1777 | if (!(sts_data0 & STATUS_OWNER_HOST)) |
| 1778 | return; |
| 1779 | |
| 1780 | desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0); |
| 1781 | opcode = qlcnic_get_sts_opcode(sts_data0); |
| 1782 | |
| 1783 | ring = qlcnic_get_sts_type(sts_data0); |
| 1784 | rxbuf = qlcnic_process_rcv_diag(adapter, sds_ring, |
| 1785 | ring, sts_data0); |
| 1786 | |
| 1787 | desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM); |
| 1788 | consumer = get_next_index(consumer, sds_ring->num_desc); |
| 1789 | |
| 1790 | sds_ring->consumer = consumer; |
| 1791 | writel(consumer, sds_ring->crb_sts_consumer); |
| 1792 | } |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1793 | |
| 1794 | void |
| 1795 | qlcnic_fetch_mac(struct qlcnic_adapter *adapter, u32 off1, u32 off2, |
| 1796 | u8 alt_mac, u8 *mac) |
| 1797 | { |
| 1798 | u32 mac_low, mac_high; |
| 1799 | int i; |
| 1800 | |
| 1801 | mac_low = QLCRD32(adapter, off1); |
| 1802 | mac_high = QLCRD32(adapter, off2); |
| 1803 | |
| 1804 | if (alt_mac) { |
| 1805 | mac_low |= (mac_low >> 16) | (mac_high << 16); |
| 1806 | mac_high >>= 16; |
| 1807 | } |
| 1808 | |
| 1809 | for (i = 0; i < 2; i++) |
| 1810 | mac[i] = (u8)(mac_high >> ((1 - i) * 8)); |
| 1811 | for (i = 2; i < 6; i++) |
| 1812 | mac[i] = (u8)(mac_low >> ((5 - i) * 8)); |
| 1813 | } |