2 * Copyright (C) 2009 - QLogic Corporation.
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.
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.
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,
20 * The full GNU General Public License is included in this distribution
21 * in the file called "COPYING".
25 #include <linux/netdevice.h>
26 #include <linux/delay.h>
27 #include <linux/slab.h>
30 struct crb_addr_pair
{
35 #define QLCNIC_MAX_CRB_XFORM 60
36 static unsigned int crb_addr_xform
[QLCNIC_MAX_CRB_XFORM
];
38 #define crb_addr_transform(name) \
39 (crb_addr_xform[QLCNIC_HW_PX_MAP_CRB_##name] = \
40 QLCNIC_HW_CRB_HUB_AGT_ADR_##name << 20)
42 #define QLCNIC_ADDR_ERROR (0xffffffff)
45 qlcnic_post_rx_buffers_nodb(struct qlcnic_adapter
*adapter
,
46 struct qlcnic_host_rds_ring
*rds_ring
);
48 static void crb_addr_transform_setup(void)
50 crb_addr_transform(XDMA
);
51 crb_addr_transform(TIMR
);
52 crb_addr_transform(SRE
);
53 crb_addr_transform(SQN3
);
54 crb_addr_transform(SQN2
);
55 crb_addr_transform(SQN1
);
56 crb_addr_transform(SQN0
);
57 crb_addr_transform(SQS3
);
58 crb_addr_transform(SQS2
);
59 crb_addr_transform(SQS1
);
60 crb_addr_transform(SQS0
);
61 crb_addr_transform(RPMX7
);
62 crb_addr_transform(RPMX6
);
63 crb_addr_transform(RPMX5
);
64 crb_addr_transform(RPMX4
);
65 crb_addr_transform(RPMX3
);
66 crb_addr_transform(RPMX2
);
67 crb_addr_transform(RPMX1
);
68 crb_addr_transform(RPMX0
);
69 crb_addr_transform(ROMUSB
);
70 crb_addr_transform(SN
);
71 crb_addr_transform(QMN
);
72 crb_addr_transform(QMS
);
73 crb_addr_transform(PGNI
);
74 crb_addr_transform(PGND
);
75 crb_addr_transform(PGN3
);
76 crb_addr_transform(PGN2
);
77 crb_addr_transform(PGN1
);
78 crb_addr_transform(PGN0
);
79 crb_addr_transform(PGSI
);
80 crb_addr_transform(PGSD
);
81 crb_addr_transform(PGS3
);
82 crb_addr_transform(PGS2
);
83 crb_addr_transform(PGS1
);
84 crb_addr_transform(PGS0
);
85 crb_addr_transform(PS
);
86 crb_addr_transform(PH
);
87 crb_addr_transform(NIU
);
88 crb_addr_transform(I2Q
);
89 crb_addr_transform(EG
);
90 crb_addr_transform(MN
);
91 crb_addr_transform(MS
);
92 crb_addr_transform(CAS2
);
93 crb_addr_transform(CAS1
);
94 crb_addr_transform(CAS0
);
95 crb_addr_transform(CAM
);
96 crb_addr_transform(C2C1
);
97 crb_addr_transform(C2C0
);
98 crb_addr_transform(SMB
);
99 crb_addr_transform(OCM0
);
100 crb_addr_transform(I2C0
);
103 void qlcnic_release_rx_buffers(struct qlcnic_adapter
*adapter
)
105 struct qlcnic_recv_context
*recv_ctx
;
106 struct qlcnic_host_rds_ring
*rds_ring
;
107 struct qlcnic_rx_buffer
*rx_buf
;
110 recv_ctx
= &adapter
->recv_ctx
;
111 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
112 rds_ring
= &recv_ctx
->rds_rings
[ring
];
113 for (i
= 0; i
< rds_ring
->num_desc
; ++i
) {
114 rx_buf
= &(rds_ring
->rx_buf_arr
[i
]);
115 if (rx_buf
->state
== QLCNIC_BUFFER_FREE
)
117 pci_unmap_single(adapter
->pdev
,
121 if (rx_buf
->skb
!= NULL
)
122 dev_kfree_skb_any(rx_buf
->skb
);
127 void qlcnic_release_tx_buffers(struct qlcnic_adapter
*adapter
)
129 struct qlcnic_cmd_buffer
*cmd_buf
;
130 struct qlcnic_skb_frag
*buffrag
;
132 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
134 cmd_buf
= tx_ring
->cmd_buf_arr
;
135 for (i
= 0; i
< tx_ring
->num_desc
; i
++) {
136 buffrag
= cmd_buf
->frag_array
;
138 pci_unmap_single(adapter
->pdev
, buffrag
->dma
,
139 buffrag
->length
, PCI_DMA_TODEVICE
);
142 for (j
= 0; j
< cmd_buf
->frag_count
; j
++) {
145 pci_unmap_page(adapter
->pdev
, buffrag
->dma
,
152 dev_kfree_skb_any(cmd_buf
->skb
);
159 void qlcnic_free_sw_resources(struct qlcnic_adapter
*adapter
)
161 struct qlcnic_recv_context
*recv_ctx
;
162 struct qlcnic_host_rds_ring
*rds_ring
;
163 struct qlcnic_host_tx_ring
*tx_ring
;
166 recv_ctx
= &adapter
->recv_ctx
;
168 if (recv_ctx
->rds_rings
== NULL
)
171 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
172 rds_ring
= &recv_ctx
->rds_rings
[ring
];
173 vfree(rds_ring
->rx_buf_arr
);
174 rds_ring
->rx_buf_arr
= NULL
;
176 kfree(recv_ctx
->rds_rings
);
179 if (adapter
->tx_ring
== NULL
)
182 tx_ring
= adapter
->tx_ring
;
183 vfree(tx_ring
->cmd_buf_arr
);
184 kfree(adapter
->tx_ring
);
187 int qlcnic_alloc_sw_resources(struct qlcnic_adapter
*adapter
)
189 struct qlcnic_recv_context
*recv_ctx
;
190 struct qlcnic_host_rds_ring
*rds_ring
;
191 struct qlcnic_host_sds_ring
*sds_ring
;
192 struct qlcnic_host_tx_ring
*tx_ring
;
193 struct qlcnic_rx_buffer
*rx_buf
;
196 struct qlcnic_cmd_buffer
*cmd_buf_arr
;
197 struct net_device
*netdev
= adapter
->netdev
;
199 size
= sizeof(struct qlcnic_host_tx_ring
);
200 tx_ring
= kzalloc(size
, GFP_KERNEL
);
201 if (tx_ring
== NULL
) {
202 dev_err(&netdev
->dev
, "failed to allocate tx ring struct\n");
205 adapter
->tx_ring
= tx_ring
;
207 tx_ring
->num_desc
= adapter
->num_txd
;
208 tx_ring
->txq
= netdev_get_tx_queue(netdev
, 0);
210 cmd_buf_arr
= vmalloc(TX_BUFF_RINGSIZE(tx_ring
));
211 if (cmd_buf_arr
== NULL
) {
212 dev_err(&netdev
->dev
, "failed to allocate cmd buffer ring\n");
215 memset(cmd_buf_arr
, 0, TX_BUFF_RINGSIZE(tx_ring
));
216 tx_ring
->cmd_buf_arr
= cmd_buf_arr
;
218 recv_ctx
= &adapter
->recv_ctx
;
220 size
= adapter
->max_rds_rings
* sizeof(struct qlcnic_host_rds_ring
);
221 rds_ring
= kzalloc(size
, GFP_KERNEL
);
222 if (rds_ring
== NULL
) {
223 dev_err(&netdev
->dev
, "failed to allocate rds ring struct\n");
226 recv_ctx
->rds_rings
= rds_ring
;
228 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
229 rds_ring
= &recv_ctx
->rds_rings
[ring
];
231 case RCV_RING_NORMAL
:
232 rds_ring
->num_desc
= adapter
->num_rxd
;
233 if (adapter
->ahw
.cut_through
) {
235 QLCNIC_CT_DEFAULT_RX_BUF_LEN
;
237 QLCNIC_CT_DEFAULT_RX_BUF_LEN
;
240 QLCNIC_P3_RX_BUF_MAX_LEN
;
242 rds_ring
->dma_size
+ NET_IP_ALIGN
;
247 rds_ring
->num_desc
= adapter
->num_jumbo_rxd
;
249 QLCNIC_P3_RX_JUMBO_BUF_MAX_LEN
;
251 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
)
252 rds_ring
->dma_size
+= QLCNIC_LRO_BUFFER_EXTRA
;
255 rds_ring
->dma_size
+ NET_IP_ALIGN
;
259 rds_ring
->num_desc
= adapter
->num_lro_rxd
;
260 rds_ring
->dma_size
= QLCNIC_RX_LRO_BUFFER_LENGTH
;
261 rds_ring
->skb_size
= rds_ring
->dma_size
+ NET_IP_ALIGN
;
265 rds_ring
->rx_buf_arr
= (struct qlcnic_rx_buffer
*)
266 vmalloc(RCV_BUFF_RINGSIZE(rds_ring
));
267 if (rds_ring
->rx_buf_arr
== NULL
) {
268 dev_err(&netdev
->dev
, "Failed to allocate "
269 "rx buffer ring %d\n", ring
);
272 memset(rds_ring
->rx_buf_arr
, 0, RCV_BUFF_RINGSIZE(rds_ring
));
273 INIT_LIST_HEAD(&rds_ring
->free_list
);
275 * Now go through all of them, set reference handles
276 * and put them in the queues.
278 rx_buf
= rds_ring
->rx_buf_arr
;
279 for (i
= 0; i
< rds_ring
->num_desc
; i
++) {
280 list_add_tail(&rx_buf
->list
,
281 &rds_ring
->free_list
);
282 rx_buf
->ref_handle
= i
;
283 rx_buf
->state
= QLCNIC_BUFFER_FREE
;
286 spin_lock_init(&rds_ring
->lock
);
289 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
290 sds_ring
= &recv_ctx
->sds_rings
[ring
];
291 sds_ring
->irq
= adapter
->msix_entries
[ring
].vector
;
292 sds_ring
->adapter
= adapter
;
293 sds_ring
->num_desc
= adapter
->num_rxd
;
295 for (i
= 0; i
< NUM_RCV_DESC_RINGS
; i
++)
296 INIT_LIST_HEAD(&sds_ring
->free_list
[i
]);
302 qlcnic_free_sw_resources(adapter
);
307 * Utility to translate from internal Phantom CRB address
308 * to external PCI CRB address.
310 static u32
qlcnic_decode_crb_addr(u32 addr
)
313 u32 base_addr
, offset
, pci_base
;
315 crb_addr_transform_setup();
317 pci_base
= QLCNIC_ADDR_ERROR
;
318 base_addr
= addr
& 0xfff00000;
319 offset
= addr
& 0x000fffff;
321 for (i
= 0; i
< QLCNIC_MAX_CRB_XFORM
; i
++) {
322 if (crb_addr_xform
[i
] == base_addr
) {
327 if (pci_base
== QLCNIC_ADDR_ERROR
)
330 return pci_base
+ offset
;
333 #define QLCNIC_MAX_ROM_WAIT_USEC 100
335 static int qlcnic_wait_rom_done(struct qlcnic_adapter
*adapter
)
343 done
= QLCRD32(adapter
, QLCNIC_ROMUSB_GLB_STATUS
);
345 if (++timeout
>= QLCNIC_MAX_ROM_WAIT_USEC
) {
346 dev_err(&adapter
->pdev
->dev
,
347 "Timeout reached waiting for rom done");
355 static int do_rom_fast_read(struct qlcnic_adapter
*adapter
,
358 QLCWR32(adapter
, QLCNIC_ROMUSB_ROM_ADDRESS
, addr
);
359 QLCWR32(adapter
, QLCNIC_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
360 QLCWR32(adapter
, QLCNIC_ROMUSB_ROM_ABYTE_CNT
, 3);
361 QLCWR32(adapter
, QLCNIC_ROMUSB_ROM_INSTR_OPCODE
, 0xb);
362 if (qlcnic_wait_rom_done(adapter
)) {
363 dev_err(&adapter
->pdev
->dev
, "Error waiting for rom done\n");
366 /* reset abyte_cnt and dummy_byte_cnt */
367 QLCWR32(adapter
, QLCNIC_ROMUSB_ROM_ABYTE_CNT
, 0);
369 QLCWR32(adapter
, QLCNIC_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
371 *valp
= QLCRD32(adapter
, QLCNIC_ROMUSB_ROM_RDATA
);
375 static int do_rom_fast_read_words(struct qlcnic_adapter
*adapter
, int addr
,
376 u8
*bytes
, size_t size
)
381 for (addridx
= addr
; addridx
< (addr
+ size
); addridx
+= 4) {
383 ret
= do_rom_fast_read(adapter
, addridx
, &v
);
386 *(__le32
*)bytes
= cpu_to_le32(v
);
394 qlcnic_rom_fast_read_words(struct qlcnic_adapter
*adapter
, int addr
,
395 u8
*bytes
, size_t size
)
399 ret
= qlcnic_rom_lock(adapter
);
403 ret
= do_rom_fast_read_words(adapter
, addr
, bytes
, size
);
405 qlcnic_rom_unlock(adapter
);
409 int qlcnic_rom_fast_read(struct qlcnic_adapter
*adapter
, int addr
, int *valp
)
413 if (qlcnic_rom_lock(adapter
) != 0)
416 ret
= do_rom_fast_read(adapter
, addr
, valp
);
417 qlcnic_rom_unlock(adapter
);
421 int qlcnic_pinit_from_rom(struct qlcnic_adapter
*adapter
)
424 int i
, n
, init_delay
;
425 struct crb_addr_pair
*buf
;
428 struct pci_dev
*pdev
= adapter
->pdev
;
431 qlcnic_rom_lock(adapter
);
432 QLCWR32(adapter
, QLCNIC_ROMUSB_GLB_SW_RESET
, 0xffffffff);
433 qlcnic_rom_unlock(adapter
);
435 if (qlcnic_rom_fast_read(adapter
, 0, &n
) != 0 || (n
!= 0xcafecafe) ||
436 qlcnic_rom_fast_read(adapter
, 4, &n
) != 0) {
437 dev_err(&pdev
->dev
, "ERROR Reading crb_init area: val:%x\n", n
);
440 offset
= n
& 0xffffU
;
441 n
= (n
>> 16) & 0xffffU
;
444 dev_err(&pdev
->dev
, "QLOGIC card flash not initialized.\n");
448 buf
= kcalloc(n
, sizeof(struct crb_addr_pair
), GFP_KERNEL
);
450 dev_err(&pdev
->dev
, "Unable to calloc memory for rom read.\n");
454 for (i
= 0; i
< n
; i
++) {
455 if (qlcnic_rom_fast_read(adapter
, 8*i
+ 4*offset
, &val
) != 0 ||
456 qlcnic_rom_fast_read(adapter
, 8*i
+ 4*offset
+ 4, &addr
) != 0) {
465 for (i
= 0; i
< n
; i
++) {
467 off
= qlcnic_decode_crb_addr(buf
[i
].addr
);
468 if (off
== QLCNIC_ADDR_ERROR
) {
469 dev_err(&pdev
->dev
, "CRB init value out of range %x\n",
473 off
+= QLCNIC_PCI_CRBSPACE
;
478 /* skipping cold reboot MAGIC */
479 if (off
== QLCNIC_CAM_RAM(0x1fc))
481 if (off
== (QLCNIC_CRB_I2C0
+ 0x1c))
483 if (off
== (ROMUSB_GLB
+ 0xbc)) /* do not reset PCI */
485 if (off
== (ROMUSB_GLB
+ 0xa8))
487 if (off
== (ROMUSB_GLB
+ 0xc8)) /* core clock */
489 if (off
== (ROMUSB_GLB
+ 0x24)) /* MN clock */
491 if (off
== (ROMUSB_GLB
+ 0x1c)) /* MS clock */
493 if ((off
& 0x0ff00000) == QLCNIC_CRB_DDR_NET
)
495 /* skip the function enable register */
496 if (off
== QLCNIC_PCIE_REG(PCIE_SETUP_FUNCTION
))
498 if (off
== QLCNIC_PCIE_REG(PCIE_SETUP_FUNCTION2
))
500 if ((off
& 0x0ff00000) == QLCNIC_CRB_SMB
)
504 /* After writing this register, HW needs time for CRB */
505 /* to quiet down (else crb_window returns 0xffffffff) */
506 if (off
== QLCNIC_ROMUSB_GLB_SW_RESET
)
509 QLCWR32(adapter
, off
, buf
[i
].data
);
515 /* p2dn replyCount */
516 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_D
+ 0xec, 0x1e);
517 /* disable_peg_cache 0 & 1*/
518 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_D
+ 0x4c, 8);
519 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_I
+ 0x4c, 8);
522 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_0
+ 0x8, 0);
523 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_0
+ 0xc, 0);
524 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_1
+ 0x8, 0);
525 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_1
+ 0xc, 0);
526 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_2
+ 0x8, 0);
527 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_2
+ 0xc, 0);
528 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_3
+ 0x8, 0);
529 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_3
+ 0xc, 0);
534 qlcnic_setup_idc_param(struct qlcnic_adapter
*adapter
) {
538 if (qlcnic_rom_fast_read(adapter
, QLCNIC_ROM_DEV_INIT_TIMEOUT
, &timeo
))
541 adapter
->dev_init_timeo
= timeo
;
543 if (qlcnic_rom_fast_read(adapter
, QLCNIC_ROM_DRV_RESET_TIMEOUT
, &timeo
))
546 adapter
->reset_ack_timeo
= timeo
;
550 qlcnic_has_mn(struct qlcnic_adapter
*adapter
)
552 u32 capability
, flashed_ver
;
555 qlcnic_rom_fast_read(adapter
,
556 QLCNIC_FW_VERSION_OFFSET
, (int *)&flashed_ver
);
557 flashed_ver
= QLCNIC_DECODE_VERSION(flashed_ver
);
559 if (flashed_ver
>= QLCNIC_VERSION_CODE(4, 0, 220)) {
561 capability
= QLCRD32(adapter
, QLCNIC_PEG_TUNE_CAPABILITY
);
562 if (capability
& QLCNIC_PEG_TUNE_MN_PRESENT
)
569 struct uni_table_desc
*qlcnic_get_table_desc(const u8
*unirom
, int section
)
572 struct uni_table_desc
*directory
= (struct uni_table_desc
*) &unirom
[0];
573 __le32 entries
= cpu_to_le32(directory
->num_entries
);
575 for (i
= 0; i
< entries
; i
++) {
577 __le32 offs
= cpu_to_le32(directory
->findex
) +
578 (i
* cpu_to_le32(directory
->entry_size
));
579 __le32 tab_type
= cpu_to_le32(*((u32
*)&unirom
[offs
] + 8));
581 if (tab_type
== section
)
582 return (struct uni_table_desc
*) &unirom
[offs
];
588 #define FILEHEADER_SIZE (14 * 4)
591 qlcnic_validate_header(struct qlcnic_adapter
*adapter
)
593 const u8
*unirom
= adapter
->fw
->data
;
594 struct uni_table_desc
*directory
= (struct uni_table_desc
*) &unirom
[0];
595 __le32 fw_file_size
= adapter
->fw
->size
;
600 if (fw_file_size
< FILEHEADER_SIZE
)
603 entries
= cpu_to_le32(directory
->num_entries
);
604 entry_size
= cpu_to_le32(directory
->entry_size
);
605 tab_size
= cpu_to_le32(directory
->findex
) + (entries
* entry_size
);
607 if (fw_file_size
< tab_size
)
614 qlcnic_validate_bootld(struct qlcnic_adapter
*adapter
)
616 struct uni_table_desc
*tab_desc
;
617 struct uni_data_desc
*descr
;
618 const u8
*unirom
= adapter
->fw
->data
;
619 int idx
= cpu_to_le32(*((int *)&unirom
[adapter
->file_prd_off
] +
620 QLCNIC_UNI_BOOTLD_IDX_OFF
));
625 tab_desc
= qlcnic_get_table_desc(unirom
, QLCNIC_UNI_DIR_SECT_BOOTLD
);
630 tab_size
= cpu_to_le32(tab_desc
->findex
) +
631 (cpu_to_le32(tab_desc
->entry_size
) * (idx
+ 1));
633 if (adapter
->fw
->size
< tab_size
)
636 offs
= cpu_to_le32(tab_desc
->findex
) +
637 (cpu_to_le32(tab_desc
->entry_size
) * (idx
));
638 descr
= (struct uni_data_desc
*)&unirom
[offs
];
640 data_size
= cpu_to_le32(descr
->findex
) + cpu_to_le32(descr
->size
);
642 if (adapter
->fw
->size
< data_size
)
649 qlcnic_validate_fw(struct qlcnic_adapter
*adapter
)
651 struct uni_table_desc
*tab_desc
;
652 struct uni_data_desc
*descr
;
653 const u8
*unirom
= adapter
->fw
->data
;
654 int idx
= cpu_to_le32(*((int *)&unirom
[adapter
->file_prd_off
] +
655 QLCNIC_UNI_FIRMWARE_IDX_OFF
));
660 tab_desc
= qlcnic_get_table_desc(unirom
, QLCNIC_UNI_DIR_SECT_FW
);
665 tab_size
= cpu_to_le32(tab_desc
->findex
) +
666 (cpu_to_le32(tab_desc
->entry_size
) * (idx
+ 1));
668 if (adapter
->fw
->size
< tab_size
)
671 offs
= cpu_to_le32(tab_desc
->findex
) +
672 (cpu_to_le32(tab_desc
->entry_size
) * (idx
));
673 descr
= (struct uni_data_desc
*)&unirom
[offs
];
674 data_size
= cpu_to_le32(descr
->findex
) + cpu_to_le32(descr
->size
);
676 if (adapter
->fw
->size
< data_size
)
683 qlcnic_validate_product_offs(struct qlcnic_adapter
*adapter
)
685 struct uni_table_desc
*ptab_descr
;
686 const u8
*unirom
= adapter
->fw
->data
;
687 int mn_present
= qlcnic_has_mn(adapter
);
693 ptab_descr
= qlcnic_get_table_desc(unirom
,
694 QLCNIC_UNI_DIR_SECT_PRODUCT_TBL
);
698 entries
= cpu_to_le32(ptab_descr
->num_entries
);
699 entry_size
= cpu_to_le32(ptab_descr
->entry_size
);
700 tab_size
= cpu_to_le32(ptab_descr
->findex
) + (entries
* entry_size
);
702 if (adapter
->fw
->size
< tab_size
)
706 for (i
= 0; i
< entries
; i
++) {
708 __le32 flags
, file_chiprev
, offs
;
709 u8 chiprev
= adapter
->ahw
.revision_id
;
712 offs
= cpu_to_le32(ptab_descr
->findex
) +
713 (i
* cpu_to_le32(ptab_descr
->entry_size
));
714 flags
= cpu_to_le32(*((int *)&unirom
[offs
] +
715 QLCNIC_UNI_FLAGS_OFF
));
716 file_chiprev
= cpu_to_le32(*((int *)&unirom
[offs
] +
717 QLCNIC_UNI_CHIP_REV_OFF
));
719 flagbit
= mn_present
? 1 : 2;
721 if ((chiprev
== file_chiprev
) &&
722 ((1ULL << flagbit
) & flags
)) {
723 adapter
->file_prd_off
= offs
;
735 qlcnic_validate_unified_romimage(struct qlcnic_adapter
*adapter
)
737 if (qlcnic_validate_header(adapter
)) {
738 dev_err(&adapter
->pdev
->dev
,
739 "unified image: header validation failed\n");
743 if (qlcnic_validate_product_offs(adapter
)) {
744 dev_err(&adapter
->pdev
->dev
,
745 "unified image: product validation failed\n");
749 if (qlcnic_validate_bootld(adapter
)) {
750 dev_err(&adapter
->pdev
->dev
,
751 "unified image: bootld validation failed\n");
755 if (qlcnic_validate_fw(adapter
)) {
756 dev_err(&adapter
->pdev
->dev
,
757 "unified image: firmware validation failed\n");
765 struct uni_data_desc
*qlcnic_get_data_desc(struct qlcnic_adapter
*adapter
,
766 u32 section
, u32 idx_offset
)
768 const u8
*unirom
= adapter
->fw
->data
;
769 int idx
= cpu_to_le32(*((int *)&unirom
[adapter
->file_prd_off
] +
771 struct uni_table_desc
*tab_desc
;
774 tab_desc
= qlcnic_get_table_desc(unirom
, section
);
776 if (tab_desc
== NULL
)
779 offs
= cpu_to_le32(tab_desc
->findex
) +
780 (cpu_to_le32(tab_desc
->entry_size
) * idx
);
782 return (struct uni_data_desc
*)&unirom
[offs
];
786 qlcnic_get_bootld_offs(struct qlcnic_adapter
*adapter
)
788 u32 offs
= QLCNIC_BOOTLD_START
;
790 if (adapter
->fw_type
== QLCNIC_UNIFIED_ROMIMAGE
)
791 offs
= cpu_to_le32((qlcnic_get_data_desc(adapter
,
792 QLCNIC_UNI_DIR_SECT_BOOTLD
,
793 QLCNIC_UNI_BOOTLD_IDX_OFF
))->findex
);
795 return (u8
*)&adapter
->fw
->data
[offs
];
799 qlcnic_get_fw_offs(struct qlcnic_adapter
*adapter
)
801 u32 offs
= QLCNIC_IMAGE_START
;
803 if (adapter
->fw_type
== QLCNIC_UNIFIED_ROMIMAGE
)
804 offs
= cpu_to_le32((qlcnic_get_data_desc(adapter
,
805 QLCNIC_UNI_DIR_SECT_FW
,
806 QLCNIC_UNI_FIRMWARE_IDX_OFF
))->findex
);
808 return (u8
*)&adapter
->fw
->data
[offs
];
812 qlcnic_get_fw_size(struct qlcnic_adapter
*adapter
)
814 if (adapter
->fw_type
== QLCNIC_UNIFIED_ROMIMAGE
)
815 return cpu_to_le32((qlcnic_get_data_desc(adapter
,
816 QLCNIC_UNI_DIR_SECT_FW
,
817 QLCNIC_UNI_FIRMWARE_IDX_OFF
))->size
);
820 *(u32
*)&adapter
->fw
->data
[QLCNIC_FW_SIZE_OFFSET
]);
824 qlcnic_get_fw_version(struct qlcnic_adapter
*adapter
)
826 struct uni_data_desc
*fw_data_desc
;
827 const struct firmware
*fw
= adapter
->fw
;
828 __le32 major
, minor
, sub
;
832 if (adapter
->fw_type
!= QLCNIC_UNIFIED_ROMIMAGE
)
833 return cpu_to_le32(*(u32
*)&fw
->data
[QLCNIC_FW_VERSION_OFFSET
]);
835 fw_data_desc
= qlcnic_get_data_desc(adapter
, QLCNIC_UNI_DIR_SECT_FW
,
836 QLCNIC_UNI_FIRMWARE_IDX_OFF
);
837 ver_str
= fw
->data
+ cpu_to_le32(fw_data_desc
->findex
) +
838 cpu_to_le32(fw_data_desc
->size
) - 17;
840 for (i
= 0; i
< 12; i
++) {
841 if (!strncmp(&ver_str
[i
], "REV=", 4)) {
842 ret
= sscanf(&ver_str
[i
+4], "%u.%u.%u ",
843 &major
, &minor
, &sub
);
847 return major
+ (minor
<< 8) + (sub
<< 16);
855 qlcnic_get_bios_version(struct qlcnic_adapter
*adapter
)
857 const struct firmware
*fw
= adapter
->fw
;
858 __le32 bios_ver
, prd_off
= adapter
->file_prd_off
;
860 if (adapter
->fw_type
!= QLCNIC_UNIFIED_ROMIMAGE
)
862 *(u32
*)&fw
->data
[QLCNIC_BIOS_VERSION_OFFSET
]);
864 bios_ver
= cpu_to_le32(*((u32
*) (&fw
->data
[prd_off
])
865 + QLCNIC_UNI_BIOS_VERSION_OFF
));
867 return (bios_ver
<< 16) + ((bios_ver
>> 8) & 0xff00) + (bios_ver
>> 24);
871 qlcnic_need_fw_reset(struct qlcnic_adapter
*adapter
)
873 u32 count
, old_count
;
874 u32 val
, version
, major
, minor
, build
;
877 if (adapter
->need_fw_reset
)
880 /* last attempt had failed */
881 if (QLCRD32(adapter
, CRB_CMDPEG_STATE
) == PHAN_INITIALIZE_FAILED
)
884 old_count
= QLCRD32(adapter
, QLCNIC_PEG_ALIVE_COUNTER
);
886 for (i
= 0; i
< 10; i
++) {
888 timeout
= msleep_interruptible(200);
890 QLCWR32(adapter
, CRB_CMDPEG_STATE
,
891 PHAN_INITIALIZE_FAILED
);
895 count
= QLCRD32(adapter
, QLCNIC_PEG_ALIVE_COUNTER
);
896 if (count
!= old_count
)
900 /* firmware is dead */
901 if (count
== old_count
)
904 /* check if we have got newer or different file firmware */
907 val
= qlcnic_get_fw_version(adapter
);
909 version
= QLCNIC_DECODE_VERSION(val
);
911 major
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MAJOR
);
912 minor
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MINOR
);
913 build
= QLCRD32(adapter
, QLCNIC_FW_VERSION_SUB
);
915 if (version
> QLCNIC_VERSION_CODE(major
, minor
, build
))
922 static const char *fw_name
[] = {
923 QLCNIC_UNIFIED_ROMIMAGE_NAME
,
924 QLCNIC_FLASH_ROMIMAGE_NAME
,
928 qlcnic_load_firmware(struct qlcnic_adapter
*adapter
)
931 u32 i
, flashaddr
, size
;
932 const struct firmware
*fw
= adapter
->fw
;
933 struct pci_dev
*pdev
= adapter
->pdev
;
935 dev_info(&pdev
->dev
, "loading firmware from %s\n",
936 fw_name
[adapter
->fw_type
]);
941 size
= (QLCNIC_IMAGE_START
- QLCNIC_BOOTLD_START
) / 8;
943 ptr64
= (u64
*)qlcnic_get_bootld_offs(adapter
);
944 flashaddr
= QLCNIC_BOOTLD_START
;
946 for (i
= 0; i
< size
; i
++) {
947 data
= cpu_to_le64(ptr64
[i
]);
949 if (qlcnic_pci_mem_write_2M(adapter
, flashaddr
, data
))
955 size
= (__force u32
)qlcnic_get_fw_size(adapter
) / 8;
957 ptr64
= (u64
*)qlcnic_get_fw_offs(adapter
);
958 flashaddr
= QLCNIC_IMAGE_START
;
960 for (i
= 0; i
< size
; i
++) {
961 data
= cpu_to_le64(ptr64
[i
]);
963 if (qlcnic_pci_mem_write_2M(adapter
,
970 size
= (__force u32
)qlcnic_get_fw_size(adapter
) % 8;
972 data
= cpu_to_le64(ptr64
[i
]);
974 if (qlcnic_pci_mem_write_2M(adapter
,
983 size
= (QLCNIC_IMAGE_START
- QLCNIC_BOOTLD_START
) / 8;
984 flashaddr
= QLCNIC_BOOTLD_START
;
986 for (i
= 0; i
< size
; i
++) {
987 if (qlcnic_rom_fast_read(adapter
,
988 flashaddr
, (int *)&lo
) != 0)
990 if (qlcnic_rom_fast_read(adapter
,
991 flashaddr
+ 4, (int *)&hi
) != 0)
994 data
= (((u64
)hi
<< 32) | lo
);
996 if (qlcnic_pci_mem_write_2M(adapter
,
1005 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_0
+ 0x18, 0x1020);
1006 QLCWR32(adapter
, QLCNIC_ROMUSB_GLB_SW_RESET
, 0x80001e);
1011 qlcnic_validate_firmware(struct qlcnic_adapter
*adapter
)
1014 u32 ver
, min_ver
, bios
, min_size
;
1015 struct pci_dev
*pdev
= adapter
->pdev
;
1016 const struct firmware
*fw
= adapter
->fw
;
1017 u8 fw_type
= adapter
->fw_type
;
1019 if (fw_type
== QLCNIC_UNIFIED_ROMIMAGE
) {
1020 if (qlcnic_validate_unified_romimage(adapter
))
1023 min_size
= QLCNIC_UNI_FW_MIN_SIZE
;
1025 val
= cpu_to_le32(*(u32
*)&fw
->data
[QLCNIC_FW_MAGIC_OFFSET
]);
1026 if ((__force u32
)val
!= QLCNIC_BDINFO_MAGIC
)
1029 min_size
= QLCNIC_FW_MIN_SIZE
;
1032 if (fw
->size
< min_size
)
1035 val
= qlcnic_get_fw_version(adapter
);
1037 min_ver
= QLCNIC_VERSION_CODE(4, 0, 216);
1039 ver
= QLCNIC_DECODE_VERSION(val
);
1041 if ((_major(ver
) > _QLCNIC_LINUX_MAJOR
) || (ver
< min_ver
)) {
1043 "%s: firmware version %d.%d.%d unsupported\n",
1044 fw_name
[fw_type
], _major(ver
), _minor(ver
), _build(ver
));
1048 val
= qlcnic_get_bios_version(adapter
);
1049 qlcnic_rom_fast_read(adapter
, QLCNIC_BIOS_VERSION_OFFSET
, (int *)&bios
);
1050 if ((__force u32
)val
!= bios
) {
1051 dev_err(&pdev
->dev
, "%s: firmware bios is incompatible\n",
1056 /* check if flashed firmware is newer */
1057 if (qlcnic_rom_fast_read(adapter
,
1058 QLCNIC_FW_VERSION_OFFSET
, (int *)&val
))
1061 val
= QLCNIC_DECODE_VERSION(val
);
1063 dev_info(&pdev
->dev
, "%s: firmware is older than flash\n",
1068 QLCWR32(adapter
, QLCNIC_CAM_RAM(0x1fc), QLCNIC_BDINFO_MAGIC
);
1073 qlcnic_get_next_fwtype(struct qlcnic_adapter
*adapter
)
1077 switch (adapter
->fw_type
) {
1078 case QLCNIC_UNKNOWN_ROMIMAGE
:
1079 fw_type
= QLCNIC_UNIFIED_ROMIMAGE
;
1082 case QLCNIC_UNIFIED_ROMIMAGE
:
1084 fw_type
= QLCNIC_FLASH_ROMIMAGE
;
1088 adapter
->fw_type
= fw_type
;
1093 void qlcnic_request_firmware(struct qlcnic_adapter
*adapter
)
1095 struct pci_dev
*pdev
= adapter
->pdev
;
1098 adapter
->fw_type
= QLCNIC_UNKNOWN_ROMIMAGE
;
1101 qlcnic_get_next_fwtype(adapter
);
1103 if (adapter
->fw_type
== QLCNIC_FLASH_ROMIMAGE
) {
1106 rc
= request_firmware(&adapter
->fw
,
1107 fw_name
[adapter
->fw_type
], &pdev
->dev
);
1111 rc
= qlcnic_validate_firmware(adapter
);
1113 release_firmware(adapter
->fw
);
1122 qlcnic_release_firmware(struct qlcnic_adapter
*adapter
)
1125 release_firmware(adapter
->fw
);
1129 int qlcnic_phantom_init(struct qlcnic_adapter
*adapter
)
1135 val
= QLCRD32(adapter
, CRB_CMDPEG_STATE
);
1138 case PHAN_INITIALIZE_COMPLETE
:
1139 case PHAN_INITIALIZE_ACK
:
1141 case PHAN_INITIALIZE_FAILED
:
1149 } while (--retries
);
1151 QLCWR32(adapter
, CRB_CMDPEG_STATE
, PHAN_INITIALIZE_FAILED
);
1154 dev_err(&adapter
->pdev
->dev
, "firmware init failed\n");
1159 qlcnic_receive_peg_ready(struct qlcnic_adapter
*adapter
)
1165 val
= QLCRD32(adapter
, CRB_RCVPEG_STATE
);
1167 if (val
== PHAN_PEG_RCV_INITIALIZED
)
1172 } while (--retries
);
1175 dev_err(&adapter
->pdev
->dev
, "Receive Peg initialization not "
1176 "complete, state: 0x%x.\n", val
);
1183 int qlcnic_init_firmware(struct qlcnic_adapter
*adapter
)
1187 err
= qlcnic_receive_peg_ready(adapter
);
1191 QLCWR32(adapter
, CRB_NIC_CAPABILITIES_HOST
, INTR_SCHEME_PERPORT
);
1192 QLCWR32(adapter
, CRB_NIC_MSI_MODE_HOST
, MSI_MODE_MULTIFUNC
);
1193 QLCWR32(adapter
, CRB_MPORT_MODE
, MPORT_MULTI_FUNCTION_MODE
);
1194 QLCWR32(adapter
, CRB_CMDPEG_STATE
, PHAN_INITIALIZE_ACK
);
1200 qlcnic_handle_linkevent(struct qlcnic_adapter
*adapter
,
1201 struct qlcnic_fw_msg
*msg
)
1206 u8 link_status
, module
, duplex
, autoneg
;
1207 struct net_device
*netdev
= adapter
->netdev
;
1209 adapter
->has_link_events
= 1;
1211 cable_OUI
= msg
->body
[1] & 0xffffffff;
1212 cable_len
= (msg
->body
[1] >> 32) & 0xffff;
1213 link_speed
= (msg
->body
[1] >> 48) & 0xffff;
1215 link_status
= msg
->body
[2] & 0xff;
1216 duplex
= (msg
->body
[2] >> 16) & 0xff;
1217 autoneg
= (msg
->body
[2] >> 24) & 0xff;
1219 module
= (msg
->body
[2] >> 8) & 0xff;
1220 if (module
== LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE
)
1221 dev_info(&netdev
->dev
, "unsupported cable: OUI 0x%x, "
1222 "length %d\n", cable_OUI
, cable_len
);
1223 else if (module
== LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN
)
1224 dev_info(&netdev
->dev
, "unsupported cable length %d\n",
1227 qlcnic_advert_link_change(adapter
, link_status
);
1229 if (duplex
== LINKEVENT_FULL_DUPLEX
)
1230 adapter
->link_duplex
= DUPLEX_FULL
;
1232 adapter
->link_duplex
= DUPLEX_HALF
;
1234 adapter
->module_type
= module
;
1235 adapter
->link_autoneg
= autoneg
;
1236 adapter
->link_speed
= link_speed
;
1240 qlcnic_handle_fw_message(int desc_cnt
, int index
,
1241 struct qlcnic_host_sds_ring
*sds_ring
)
1243 struct qlcnic_fw_msg msg
;
1244 struct status_desc
*desc
;
1247 while (desc_cnt
> 0 && i
< 8) {
1248 desc
= &sds_ring
->desc_head
[index
];
1249 msg
.words
[i
++] = le64_to_cpu(desc
->status_desc_data
[0]);
1250 msg
.words
[i
++] = le64_to_cpu(desc
->status_desc_data
[1]);
1252 index
= get_next_index(index
, sds_ring
->num_desc
);
1256 opcode
= qlcnic_get_nic_msg_opcode(msg
.body
[0]);
1258 case QLCNIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE
:
1259 qlcnic_handle_linkevent(sds_ring
->adapter
, &msg
);
1267 qlcnic_alloc_rx_skb(struct qlcnic_adapter
*adapter
,
1268 struct qlcnic_host_rds_ring
*rds_ring
,
1269 struct qlcnic_rx_buffer
*buffer
)
1271 struct sk_buff
*skb
;
1273 struct pci_dev
*pdev
= adapter
->pdev
;
1275 buffer
->skb
= dev_alloc_skb(rds_ring
->skb_size
);
1277 adapter
->stats
.skb_alloc_failure
++;
1283 if (!adapter
->ahw
.cut_through
)
1284 skb_reserve(skb
, 2);
1286 dma
= pci_map_single(pdev
, skb
->data
,
1287 rds_ring
->dma_size
, PCI_DMA_FROMDEVICE
);
1289 if (pci_dma_mapping_error(pdev
, dma
)) {
1290 adapter
->stats
.rx_dma_map_error
++;
1291 dev_kfree_skb_any(skb
);
1298 buffer
->state
= QLCNIC_BUFFER_BUSY
;
1303 static struct sk_buff
*qlcnic_process_rxbuf(struct qlcnic_adapter
*adapter
,
1304 struct qlcnic_host_rds_ring
*rds_ring
, u16 index
, u16 cksum
)
1306 struct qlcnic_rx_buffer
*buffer
;
1307 struct sk_buff
*skb
;
1309 buffer
= &rds_ring
->rx_buf_arr
[index
];
1311 pci_unmap_single(adapter
->pdev
, buffer
->dma
, rds_ring
->dma_size
,
1312 PCI_DMA_FROMDEVICE
);
1316 adapter
->stats
.null_skb
++;
1320 if (likely(adapter
->rx_csum
&& cksum
== STATUS_CKSUM_OK
)) {
1321 adapter
->stats
.csummed
++;
1322 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1324 skb
->ip_summed
= CHECKSUM_NONE
;
1327 skb
->dev
= adapter
->netdev
;
1331 buffer
->state
= QLCNIC_BUFFER_FREE
;
1335 static struct qlcnic_rx_buffer
*
1336 qlcnic_process_rcv(struct qlcnic_adapter
*adapter
,
1337 struct qlcnic_host_sds_ring
*sds_ring
,
1338 int ring
, u64 sts_data0
)
1340 struct net_device
*netdev
= adapter
->netdev
;
1341 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1342 struct qlcnic_rx_buffer
*buffer
;
1343 struct sk_buff
*skb
;
1344 struct qlcnic_host_rds_ring
*rds_ring
;
1345 int index
, length
, cksum
, pkt_offset
;
1347 if (unlikely(ring
>= adapter
->max_rds_rings
))
1350 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1352 index
= qlcnic_get_sts_refhandle(sts_data0
);
1353 if (unlikely(index
>= rds_ring
->num_desc
))
1356 buffer
= &rds_ring
->rx_buf_arr
[index
];
1358 length
= qlcnic_get_sts_totallength(sts_data0
);
1359 cksum
= qlcnic_get_sts_status(sts_data0
);
1360 pkt_offset
= qlcnic_get_sts_pkt_offset(sts_data0
);
1362 skb
= qlcnic_process_rxbuf(adapter
, rds_ring
, index
, cksum
);
1366 if (length
> rds_ring
->skb_size
)
1367 skb_put(skb
, rds_ring
->skb_size
);
1369 skb_put(skb
, length
);
1372 skb_pull(skb
, pkt_offset
);
1374 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
);
1375 skb
->protocol
= eth_type_trans(skb
, netdev
);
1377 napi_gro_receive(&sds_ring
->napi
, skb
);
1379 adapter
->stats
.rx_pkts
++;
1380 adapter
->stats
.rxbytes
+= length
;
1385 #define QLC_TCP_HDR_SIZE 20
1386 #define QLC_TCP_TS_OPTION_SIZE 12
1387 #define QLC_TCP_TS_HDR_SIZE (QLC_TCP_HDR_SIZE + QLC_TCP_TS_OPTION_SIZE)
1389 static struct qlcnic_rx_buffer
*
1390 qlcnic_process_lro(struct qlcnic_adapter
*adapter
,
1391 struct qlcnic_host_sds_ring
*sds_ring
,
1392 int ring
, u64 sts_data0
, u64 sts_data1
)
1394 struct net_device
*netdev
= adapter
->netdev
;
1395 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1396 struct qlcnic_rx_buffer
*buffer
;
1397 struct sk_buff
*skb
;
1398 struct qlcnic_host_rds_ring
*rds_ring
;
1401 bool push
, timestamp
;
1402 int l2_hdr_offset
, l4_hdr_offset
;
1404 u16 lro_length
, length
, data_offset
;
1407 if (unlikely(ring
> adapter
->max_rds_rings
))
1410 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1412 index
= qlcnic_get_lro_sts_refhandle(sts_data0
);
1413 if (unlikely(index
> rds_ring
->num_desc
))
1416 buffer
= &rds_ring
->rx_buf_arr
[index
];
1418 timestamp
= qlcnic_get_lro_sts_timestamp(sts_data0
);
1419 lro_length
= qlcnic_get_lro_sts_length(sts_data0
);
1420 l2_hdr_offset
= qlcnic_get_lro_sts_l2_hdr_offset(sts_data0
);
1421 l4_hdr_offset
= qlcnic_get_lro_sts_l4_hdr_offset(sts_data0
);
1422 push
= qlcnic_get_lro_sts_push_flag(sts_data0
);
1423 seq_number
= qlcnic_get_lro_sts_seq_number(sts_data1
);
1425 skb
= qlcnic_process_rxbuf(adapter
, rds_ring
, index
, STATUS_CKSUM_OK
);
1430 data_offset
= l4_hdr_offset
+ QLC_TCP_TS_HDR_SIZE
;
1432 data_offset
= l4_hdr_offset
+ QLC_TCP_HDR_SIZE
;
1434 skb_put(skb
, lro_length
+ data_offset
);
1436 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
) + skb_headroom(skb
);
1438 skb_pull(skb
, l2_hdr_offset
);
1439 skb
->protocol
= eth_type_trans(skb
, netdev
);
1441 iph
= (struct iphdr
*)skb
->data
;
1442 th
= (struct tcphdr
*)(skb
->data
+ (iph
->ihl
<< 2));
1444 length
= (iph
->ihl
<< 2) + (th
->doff
<< 2) + lro_length
;
1445 iph
->tot_len
= htons(length
);
1447 iph
->check
= ip_fast_csum((unsigned char *)iph
, iph
->ihl
);
1449 th
->seq
= htonl(seq_number
);
1453 netif_receive_skb(skb
);
1455 adapter
->stats
.lro_pkts
++;
1456 adapter
->stats
.lrobytes
+= length
;
1462 qlcnic_process_rcv_ring(struct qlcnic_host_sds_ring
*sds_ring
, int max
)
1464 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
1465 struct list_head
*cur
;
1466 struct status_desc
*desc
;
1467 struct qlcnic_rx_buffer
*rxbuf
;
1468 u64 sts_data0
, sts_data1
;
1471 int opcode
, ring
, desc_cnt
;
1472 u32 consumer
= sds_ring
->consumer
;
1474 while (count
< max
) {
1475 desc
= &sds_ring
->desc_head
[consumer
];
1476 sts_data0
= le64_to_cpu(desc
->status_desc_data
[0]);
1478 if (!(sts_data0
& STATUS_OWNER_HOST
))
1481 desc_cnt
= qlcnic_get_sts_desc_cnt(sts_data0
);
1482 opcode
= qlcnic_get_sts_opcode(sts_data0
);
1485 case QLCNIC_RXPKT_DESC
:
1486 case QLCNIC_OLD_RXPKT_DESC
:
1487 case QLCNIC_SYN_OFFLOAD
:
1488 ring
= qlcnic_get_sts_type(sts_data0
);
1489 rxbuf
= qlcnic_process_rcv(adapter
, sds_ring
,
1492 case QLCNIC_LRO_DESC
:
1493 ring
= qlcnic_get_lro_sts_type(sts_data0
);
1494 sts_data1
= le64_to_cpu(desc
->status_desc_data
[1]);
1495 rxbuf
= qlcnic_process_lro(adapter
, sds_ring
,
1496 ring
, sts_data0
, sts_data1
);
1498 case QLCNIC_RESPONSE_DESC
:
1499 qlcnic_handle_fw_message(desc_cnt
, consumer
, sds_ring
);
1504 WARN_ON(desc_cnt
> 1);
1507 list_add_tail(&rxbuf
->list
, &sds_ring
->free_list
[ring
]);
1509 adapter
->stats
.null_rxbuf
++;
1512 for (; desc_cnt
> 0; desc_cnt
--) {
1513 desc
= &sds_ring
->desc_head
[consumer
];
1514 desc
->status_desc_data
[0] =
1515 cpu_to_le64(STATUS_OWNER_PHANTOM
);
1516 consumer
= get_next_index(consumer
, sds_ring
->num_desc
);
1521 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1522 struct qlcnic_host_rds_ring
*rds_ring
=
1523 &adapter
->recv_ctx
.rds_rings
[ring
];
1525 if (!list_empty(&sds_ring
->free_list
[ring
])) {
1526 list_for_each(cur
, &sds_ring
->free_list
[ring
]) {
1527 rxbuf
= list_entry(cur
,
1528 struct qlcnic_rx_buffer
, list
);
1529 qlcnic_alloc_rx_skb(adapter
, rds_ring
, rxbuf
);
1531 spin_lock(&rds_ring
->lock
);
1532 list_splice_tail_init(&sds_ring
->free_list
[ring
],
1533 &rds_ring
->free_list
);
1534 spin_unlock(&rds_ring
->lock
);
1537 qlcnic_post_rx_buffers_nodb(adapter
, rds_ring
);
1541 sds_ring
->consumer
= consumer
;
1542 writel(consumer
, sds_ring
->crb_sts_consumer
);
1549 qlcnic_post_rx_buffers(struct qlcnic_adapter
*adapter
, u32 ringid
,
1550 struct qlcnic_host_rds_ring
*rds_ring
)
1552 struct rcv_desc
*pdesc
;
1553 struct qlcnic_rx_buffer
*buffer
;
1554 int producer
, count
= 0;
1555 struct list_head
*head
;
1557 producer
= rds_ring
->producer
;
1559 spin_lock(&rds_ring
->lock
);
1560 head
= &rds_ring
->free_list
;
1561 while (!list_empty(head
)) {
1563 buffer
= list_entry(head
->next
, struct qlcnic_rx_buffer
, list
);
1566 if (qlcnic_alloc_rx_skb(adapter
, rds_ring
, buffer
))
1571 list_del(&buffer
->list
);
1573 /* make a rcv descriptor */
1574 pdesc
= &rds_ring
->desc_head
[producer
];
1575 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1576 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1577 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1579 producer
= get_next_index(producer
, rds_ring
->num_desc
);
1581 spin_unlock(&rds_ring
->lock
);
1584 rds_ring
->producer
= producer
;
1585 writel((producer
-1) & (rds_ring
->num_desc
-1),
1586 rds_ring
->crb_rcv_producer
);
1591 qlcnic_post_rx_buffers_nodb(struct qlcnic_adapter
*adapter
,
1592 struct qlcnic_host_rds_ring
*rds_ring
)
1594 struct rcv_desc
*pdesc
;
1595 struct qlcnic_rx_buffer
*buffer
;
1596 int producer
, count
= 0;
1597 struct list_head
*head
;
1599 producer
= rds_ring
->producer
;
1600 if (!spin_trylock(&rds_ring
->lock
))
1603 head
= &rds_ring
->free_list
;
1604 while (!list_empty(head
)) {
1606 buffer
= list_entry(head
->next
, struct qlcnic_rx_buffer
, list
);
1609 if (qlcnic_alloc_rx_skb(adapter
, rds_ring
, buffer
))
1614 list_del(&buffer
->list
);
1616 /* make a rcv descriptor */
1617 pdesc
= &rds_ring
->desc_head
[producer
];
1618 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1619 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1620 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1622 producer
= get_next_index(producer
, rds_ring
->num_desc
);
1626 rds_ring
->producer
= producer
;
1627 writel((producer
- 1) & (rds_ring
->num_desc
- 1),
1628 rds_ring
->crb_rcv_producer
);
1630 spin_unlock(&rds_ring
->lock
);
1633 static struct qlcnic_rx_buffer
*
1634 qlcnic_process_rcv_diag(struct qlcnic_adapter
*adapter
,
1635 struct qlcnic_host_sds_ring
*sds_ring
,
1636 int ring
, u64 sts_data0
)
1638 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1639 struct qlcnic_rx_buffer
*buffer
;
1640 struct sk_buff
*skb
;
1641 struct qlcnic_host_rds_ring
*rds_ring
;
1642 int index
, length
, cksum
, pkt_offset
;
1644 if (unlikely(ring
>= adapter
->max_rds_rings
))
1647 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1649 index
= qlcnic_get_sts_refhandle(sts_data0
);
1650 if (unlikely(index
>= rds_ring
->num_desc
))
1653 buffer
= &rds_ring
->rx_buf_arr
[index
];
1655 length
= qlcnic_get_sts_totallength(sts_data0
);
1656 cksum
= qlcnic_get_sts_status(sts_data0
);
1657 pkt_offset
= qlcnic_get_sts_pkt_offset(sts_data0
);
1659 skb
= qlcnic_process_rxbuf(adapter
, rds_ring
, index
, cksum
);
1663 skb_put(skb
, rds_ring
->skb_size
);
1666 skb_pull(skb
, pkt_offset
);
1668 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
);
1670 if (!qlcnic_check_loopback_buff(skb
->data
))
1671 adapter
->diag_cnt
++;
1673 dev_kfree_skb_any(skb
);
1674 adapter
->stats
.rx_pkts
++;
1675 adapter
->stats
.rxbytes
+= length
;
1681 qlcnic_process_rcv_ring_diag(struct qlcnic_host_sds_ring
*sds_ring
)
1683 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
1684 struct status_desc
*desc
;
1685 struct qlcnic_rx_buffer
*rxbuf
;
1688 int opcode
, ring
, desc_cnt
;
1689 u32 consumer
= sds_ring
->consumer
;
1691 desc
= &sds_ring
->desc_head
[consumer
];
1692 sts_data0
= le64_to_cpu(desc
->status_desc_data
[0]);
1694 if (!(sts_data0
& STATUS_OWNER_HOST
))
1697 desc_cnt
= qlcnic_get_sts_desc_cnt(sts_data0
);
1698 opcode
= qlcnic_get_sts_opcode(sts_data0
);
1700 ring
= qlcnic_get_sts_type(sts_data0
);
1701 rxbuf
= qlcnic_process_rcv_diag(adapter
, sds_ring
,
1704 desc
->status_desc_data
[0] = cpu_to_le64(STATUS_OWNER_PHANTOM
);
1705 consumer
= get_next_index(consumer
, sds_ring
->num_desc
);
1707 sds_ring
->consumer
= consumer
;
1708 writel(consumer
, sds_ring
->crb_sts_consumer
);