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 rds_ring
->dma_size
= QLCNIC_P3_RX_BUF_MAX_LEN
;
234 rds_ring
->skb_size
= rds_ring
->dma_size
+ NET_IP_ALIGN
;
238 rds_ring
->num_desc
= adapter
->num_jumbo_rxd
;
240 QLCNIC_P3_RX_JUMBO_BUF_MAX_LEN
;
242 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
)
243 rds_ring
->dma_size
+= QLCNIC_LRO_BUFFER_EXTRA
;
246 rds_ring
->dma_size
+ NET_IP_ALIGN
;
249 rds_ring
->rx_buf_arr
= (struct qlcnic_rx_buffer
*)
250 vmalloc(RCV_BUFF_RINGSIZE(rds_ring
));
251 if (rds_ring
->rx_buf_arr
== NULL
) {
252 dev_err(&netdev
->dev
, "Failed to allocate "
253 "rx buffer ring %d\n", ring
);
256 memset(rds_ring
->rx_buf_arr
, 0, RCV_BUFF_RINGSIZE(rds_ring
));
257 INIT_LIST_HEAD(&rds_ring
->free_list
);
259 * Now go through all of them, set reference handles
260 * and put them in the queues.
262 rx_buf
= rds_ring
->rx_buf_arr
;
263 for (i
= 0; i
< rds_ring
->num_desc
; i
++) {
264 list_add_tail(&rx_buf
->list
,
265 &rds_ring
->free_list
);
266 rx_buf
->ref_handle
= i
;
267 rx_buf
->state
= QLCNIC_BUFFER_FREE
;
270 spin_lock_init(&rds_ring
->lock
);
273 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
274 sds_ring
= &recv_ctx
->sds_rings
[ring
];
275 sds_ring
->irq
= adapter
->msix_entries
[ring
].vector
;
276 sds_ring
->adapter
= adapter
;
277 sds_ring
->num_desc
= adapter
->num_rxd
;
279 for (i
= 0; i
< NUM_RCV_DESC_RINGS
; i
++)
280 INIT_LIST_HEAD(&sds_ring
->free_list
[i
]);
286 qlcnic_free_sw_resources(adapter
);
291 * Utility to translate from internal Phantom CRB address
292 * to external PCI CRB address.
294 static u32
qlcnic_decode_crb_addr(u32 addr
)
297 u32 base_addr
, offset
, pci_base
;
299 crb_addr_transform_setup();
301 pci_base
= QLCNIC_ADDR_ERROR
;
302 base_addr
= addr
& 0xfff00000;
303 offset
= addr
& 0x000fffff;
305 for (i
= 0; i
< QLCNIC_MAX_CRB_XFORM
; i
++) {
306 if (crb_addr_xform
[i
] == base_addr
) {
311 if (pci_base
== QLCNIC_ADDR_ERROR
)
314 return pci_base
+ offset
;
317 #define QLCNIC_MAX_ROM_WAIT_USEC 100
319 static int qlcnic_wait_rom_done(struct qlcnic_adapter
*adapter
)
327 done
= QLCRD32(adapter
, QLCNIC_ROMUSB_GLB_STATUS
);
329 if (++timeout
>= QLCNIC_MAX_ROM_WAIT_USEC
) {
330 dev_err(&adapter
->pdev
->dev
,
331 "Timeout reached waiting for rom done");
339 static int do_rom_fast_read(struct qlcnic_adapter
*adapter
,
342 QLCWR32(adapter
, QLCNIC_ROMUSB_ROM_ADDRESS
, addr
);
343 QLCWR32(adapter
, QLCNIC_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
344 QLCWR32(adapter
, QLCNIC_ROMUSB_ROM_ABYTE_CNT
, 3);
345 QLCWR32(adapter
, QLCNIC_ROMUSB_ROM_INSTR_OPCODE
, 0xb);
346 if (qlcnic_wait_rom_done(adapter
)) {
347 dev_err(&adapter
->pdev
->dev
, "Error waiting for rom done\n");
350 /* reset abyte_cnt and dummy_byte_cnt */
351 QLCWR32(adapter
, QLCNIC_ROMUSB_ROM_ABYTE_CNT
, 0);
353 QLCWR32(adapter
, QLCNIC_ROMUSB_ROM_DUMMY_BYTE_CNT
, 0);
355 *valp
= QLCRD32(adapter
, QLCNIC_ROMUSB_ROM_RDATA
);
359 static int do_rom_fast_read_words(struct qlcnic_adapter
*adapter
, int addr
,
360 u8
*bytes
, size_t size
)
365 for (addridx
= addr
; addridx
< (addr
+ size
); addridx
+= 4) {
367 ret
= do_rom_fast_read(adapter
, addridx
, &v
);
370 *(__le32
*)bytes
= cpu_to_le32(v
);
378 qlcnic_rom_fast_read_words(struct qlcnic_adapter
*adapter
, int addr
,
379 u8
*bytes
, size_t size
)
383 ret
= qlcnic_rom_lock(adapter
);
387 ret
= do_rom_fast_read_words(adapter
, addr
, bytes
, size
);
389 qlcnic_rom_unlock(adapter
);
393 int qlcnic_rom_fast_read(struct qlcnic_adapter
*adapter
, int addr
, int *valp
)
397 if (qlcnic_rom_lock(adapter
) != 0)
400 ret
= do_rom_fast_read(adapter
, addr
, valp
);
401 qlcnic_rom_unlock(adapter
);
405 int qlcnic_pinit_from_rom(struct qlcnic_adapter
*adapter
)
408 int i
, n
, init_delay
;
409 struct crb_addr_pair
*buf
;
412 struct pci_dev
*pdev
= adapter
->pdev
;
415 qlcnic_rom_lock(adapter
);
416 QLCWR32(adapter
, QLCNIC_ROMUSB_GLB_SW_RESET
, 0xffffffff);
417 qlcnic_rom_unlock(adapter
);
419 if (qlcnic_rom_fast_read(adapter
, 0, &n
) != 0 || (n
!= 0xcafecafe) ||
420 qlcnic_rom_fast_read(adapter
, 4, &n
) != 0) {
421 dev_err(&pdev
->dev
, "ERROR Reading crb_init area: val:%x\n", n
);
424 offset
= n
& 0xffffU
;
425 n
= (n
>> 16) & 0xffffU
;
428 dev_err(&pdev
->dev
, "QLOGIC card flash not initialized.\n");
432 buf
= kcalloc(n
, sizeof(struct crb_addr_pair
), GFP_KERNEL
);
434 dev_err(&pdev
->dev
, "Unable to calloc memory for rom read.\n");
438 for (i
= 0; i
< n
; i
++) {
439 if (qlcnic_rom_fast_read(adapter
, 8*i
+ 4*offset
, &val
) != 0 ||
440 qlcnic_rom_fast_read(adapter
, 8*i
+ 4*offset
+ 4, &addr
) != 0) {
449 for (i
= 0; i
< n
; i
++) {
451 off
= qlcnic_decode_crb_addr(buf
[i
].addr
);
452 if (off
== QLCNIC_ADDR_ERROR
) {
453 dev_err(&pdev
->dev
, "CRB init value out of range %x\n",
457 off
+= QLCNIC_PCI_CRBSPACE
;
462 /* skipping cold reboot MAGIC */
463 if (off
== QLCNIC_CAM_RAM(0x1fc))
465 if (off
== (QLCNIC_CRB_I2C0
+ 0x1c))
467 if (off
== (ROMUSB_GLB
+ 0xbc)) /* do not reset PCI */
469 if (off
== (ROMUSB_GLB
+ 0xa8))
471 if (off
== (ROMUSB_GLB
+ 0xc8)) /* core clock */
473 if (off
== (ROMUSB_GLB
+ 0x24)) /* MN clock */
475 if (off
== (ROMUSB_GLB
+ 0x1c)) /* MS clock */
477 if ((off
& 0x0ff00000) == QLCNIC_CRB_DDR_NET
)
479 /* skip the function enable register */
480 if (off
== QLCNIC_PCIE_REG(PCIE_SETUP_FUNCTION
))
482 if (off
== QLCNIC_PCIE_REG(PCIE_SETUP_FUNCTION2
))
484 if ((off
& 0x0ff00000) == QLCNIC_CRB_SMB
)
488 /* After writing this register, HW needs time for CRB */
489 /* to quiet down (else crb_window returns 0xffffffff) */
490 if (off
== QLCNIC_ROMUSB_GLB_SW_RESET
)
493 QLCWR32(adapter
, off
, buf
[i
].data
);
499 /* p2dn replyCount */
500 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_D
+ 0xec, 0x1e);
501 /* disable_peg_cache 0 & 1*/
502 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_D
+ 0x4c, 8);
503 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_I
+ 0x4c, 8);
506 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_0
+ 0x8, 0);
507 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_0
+ 0xc, 0);
508 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_1
+ 0x8, 0);
509 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_1
+ 0xc, 0);
510 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_2
+ 0x8, 0);
511 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_2
+ 0xc, 0);
512 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_3
+ 0x8, 0);
513 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_3
+ 0xc, 0);
518 qlcnic_setup_idc_param(struct qlcnic_adapter
*adapter
) {
523 val
= QLCRD32(adapter
, QLCNIC_CRB_DEV_PARTITION_INFO
);
524 val
= (val
>> (adapter
->portnum
* 4)) & 0xf;
526 if ((val
& 0x3) != 1) {
527 dev_err(&adapter
->pdev
->dev
, "Not an Ethernet NIC func=%u\n",
532 adapter
->physical_port
= (val
>> 2);
534 if (qlcnic_rom_fast_read(adapter
, QLCNIC_ROM_DEV_INIT_TIMEOUT
, &timeo
))
537 adapter
->dev_init_timeo
= timeo
;
539 if (qlcnic_rom_fast_read(adapter
, QLCNIC_ROM_DRV_RESET_TIMEOUT
, &timeo
))
542 adapter
->reset_ack_timeo
= timeo
;
548 qlcnic_has_mn(struct qlcnic_adapter
*adapter
)
550 u32 capability
, flashed_ver
;
553 qlcnic_rom_fast_read(adapter
,
554 QLCNIC_FW_VERSION_OFFSET
, (int *)&flashed_ver
);
555 flashed_ver
= QLCNIC_DECODE_VERSION(flashed_ver
);
557 capability
= QLCRD32(adapter
, QLCNIC_PEG_TUNE_CAPABILITY
);
558 if (capability
& QLCNIC_PEG_TUNE_MN_PRESENT
)
565 struct uni_table_desc
*qlcnic_get_table_desc(const u8
*unirom
, int section
)
568 struct uni_table_desc
*directory
= (struct uni_table_desc
*) &unirom
[0];
569 __le32 entries
= cpu_to_le32(directory
->num_entries
);
571 for (i
= 0; i
< entries
; i
++) {
573 __le32 offs
= cpu_to_le32(directory
->findex
) +
574 (i
* cpu_to_le32(directory
->entry_size
));
575 __le32 tab_type
= cpu_to_le32(*((u32
*)&unirom
[offs
] + 8));
577 if (tab_type
== section
)
578 return (struct uni_table_desc
*) &unirom
[offs
];
584 #define FILEHEADER_SIZE (14 * 4)
587 qlcnic_validate_header(struct qlcnic_adapter
*adapter
)
589 const u8
*unirom
= adapter
->fw
->data
;
590 struct uni_table_desc
*directory
= (struct uni_table_desc
*) &unirom
[0];
591 __le32 fw_file_size
= adapter
->fw
->size
;
596 if (fw_file_size
< FILEHEADER_SIZE
)
599 entries
= cpu_to_le32(directory
->num_entries
);
600 entry_size
= cpu_to_le32(directory
->entry_size
);
601 tab_size
= cpu_to_le32(directory
->findex
) + (entries
* entry_size
);
603 if (fw_file_size
< tab_size
)
610 qlcnic_validate_bootld(struct qlcnic_adapter
*adapter
)
612 struct uni_table_desc
*tab_desc
;
613 struct uni_data_desc
*descr
;
614 const u8
*unirom
= adapter
->fw
->data
;
615 int idx
= cpu_to_le32(*((int *)&unirom
[adapter
->file_prd_off
] +
616 QLCNIC_UNI_BOOTLD_IDX_OFF
));
621 tab_desc
= qlcnic_get_table_desc(unirom
, QLCNIC_UNI_DIR_SECT_BOOTLD
);
626 tab_size
= cpu_to_le32(tab_desc
->findex
) +
627 (cpu_to_le32(tab_desc
->entry_size
) * (idx
+ 1));
629 if (adapter
->fw
->size
< tab_size
)
632 offs
= cpu_to_le32(tab_desc
->findex
) +
633 (cpu_to_le32(tab_desc
->entry_size
) * (idx
));
634 descr
= (struct uni_data_desc
*)&unirom
[offs
];
636 data_size
= cpu_to_le32(descr
->findex
) + cpu_to_le32(descr
->size
);
638 if (adapter
->fw
->size
< data_size
)
645 qlcnic_validate_fw(struct qlcnic_adapter
*adapter
)
647 struct uni_table_desc
*tab_desc
;
648 struct uni_data_desc
*descr
;
649 const u8
*unirom
= adapter
->fw
->data
;
650 int idx
= cpu_to_le32(*((int *)&unirom
[adapter
->file_prd_off
] +
651 QLCNIC_UNI_FIRMWARE_IDX_OFF
));
656 tab_desc
= qlcnic_get_table_desc(unirom
, QLCNIC_UNI_DIR_SECT_FW
);
661 tab_size
= cpu_to_le32(tab_desc
->findex
) +
662 (cpu_to_le32(tab_desc
->entry_size
) * (idx
+ 1));
664 if (adapter
->fw
->size
< tab_size
)
667 offs
= cpu_to_le32(tab_desc
->findex
) +
668 (cpu_to_le32(tab_desc
->entry_size
) * (idx
));
669 descr
= (struct uni_data_desc
*)&unirom
[offs
];
670 data_size
= cpu_to_le32(descr
->findex
) + cpu_to_le32(descr
->size
);
672 if (adapter
->fw
->size
< data_size
)
679 qlcnic_validate_product_offs(struct qlcnic_adapter
*adapter
)
681 struct uni_table_desc
*ptab_descr
;
682 const u8
*unirom
= adapter
->fw
->data
;
683 int mn_present
= qlcnic_has_mn(adapter
);
689 ptab_descr
= qlcnic_get_table_desc(unirom
,
690 QLCNIC_UNI_DIR_SECT_PRODUCT_TBL
);
694 entries
= cpu_to_le32(ptab_descr
->num_entries
);
695 entry_size
= cpu_to_le32(ptab_descr
->entry_size
);
696 tab_size
= cpu_to_le32(ptab_descr
->findex
) + (entries
* entry_size
);
698 if (adapter
->fw
->size
< tab_size
)
702 for (i
= 0; i
< entries
; i
++) {
704 __le32 flags
, file_chiprev
, offs
;
705 u8 chiprev
= adapter
->ahw
.revision_id
;
708 offs
= cpu_to_le32(ptab_descr
->findex
) +
709 (i
* cpu_to_le32(ptab_descr
->entry_size
));
710 flags
= cpu_to_le32(*((int *)&unirom
[offs
] +
711 QLCNIC_UNI_FLAGS_OFF
));
712 file_chiprev
= cpu_to_le32(*((int *)&unirom
[offs
] +
713 QLCNIC_UNI_CHIP_REV_OFF
));
715 flagbit
= mn_present
? 1 : 2;
717 if ((chiprev
== file_chiprev
) &&
718 ((1ULL << flagbit
) & flags
)) {
719 adapter
->file_prd_off
= offs
;
731 qlcnic_validate_unified_romimage(struct qlcnic_adapter
*adapter
)
733 if (qlcnic_validate_header(adapter
)) {
734 dev_err(&adapter
->pdev
->dev
,
735 "unified image: header validation failed\n");
739 if (qlcnic_validate_product_offs(adapter
)) {
740 dev_err(&adapter
->pdev
->dev
,
741 "unified image: product validation failed\n");
745 if (qlcnic_validate_bootld(adapter
)) {
746 dev_err(&adapter
->pdev
->dev
,
747 "unified image: bootld validation failed\n");
751 if (qlcnic_validate_fw(adapter
)) {
752 dev_err(&adapter
->pdev
->dev
,
753 "unified image: firmware validation failed\n");
761 struct uni_data_desc
*qlcnic_get_data_desc(struct qlcnic_adapter
*adapter
,
762 u32 section
, u32 idx_offset
)
764 const u8
*unirom
= adapter
->fw
->data
;
765 int idx
= cpu_to_le32(*((int *)&unirom
[adapter
->file_prd_off
] +
767 struct uni_table_desc
*tab_desc
;
770 tab_desc
= qlcnic_get_table_desc(unirom
, section
);
772 if (tab_desc
== NULL
)
775 offs
= cpu_to_le32(tab_desc
->findex
) +
776 (cpu_to_le32(tab_desc
->entry_size
) * idx
);
778 return (struct uni_data_desc
*)&unirom
[offs
];
782 qlcnic_get_bootld_offs(struct qlcnic_adapter
*adapter
)
784 u32 offs
= QLCNIC_BOOTLD_START
;
786 if (adapter
->fw_type
== QLCNIC_UNIFIED_ROMIMAGE
)
787 offs
= cpu_to_le32((qlcnic_get_data_desc(adapter
,
788 QLCNIC_UNI_DIR_SECT_BOOTLD
,
789 QLCNIC_UNI_BOOTLD_IDX_OFF
))->findex
);
791 return (u8
*)&adapter
->fw
->data
[offs
];
795 qlcnic_get_fw_offs(struct qlcnic_adapter
*adapter
)
797 u32 offs
= QLCNIC_IMAGE_START
;
799 if (adapter
->fw_type
== QLCNIC_UNIFIED_ROMIMAGE
)
800 offs
= cpu_to_le32((qlcnic_get_data_desc(adapter
,
801 QLCNIC_UNI_DIR_SECT_FW
,
802 QLCNIC_UNI_FIRMWARE_IDX_OFF
))->findex
);
804 return (u8
*)&adapter
->fw
->data
[offs
];
808 qlcnic_get_fw_size(struct qlcnic_adapter
*adapter
)
810 if (adapter
->fw_type
== QLCNIC_UNIFIED_ROMIMAGE
)
811 return cpu_to_le32((qlcnic_get_data_desc(adapter
,
812 QLCNIC_UNI_DIR_SECT_FW
,
813 QLCNIC_UNI_FIRMWARE_IDX_OFF
))->size
);
816 *(u32
*)&adapter
->fw
->data
[QLCNIC_FW_SIZE_OFFSET
]);
820 qlcnic_get_fw_version(struct qlcnic_adapter
*adapter
)
822 struct uni_data_desc
*fw_data_desc
;
823 const struct firmware
*fw
= adapter
->fw
;
824 __le32 major
, minor
, sub
;
828 if (adapter
->fw_type
!= QLCNIC_UNIFIED_ROMIMAGE
)
829 return cpu_to_le32(*(u32
*)&fw
->data
[QLCNIC_FW_VERSION_OFFSET
]);
831 fw_data_desc
= qlcnic_get_data_desc(adapter
, QLCNIC_UNI_DIR_SECT_FW
,
832 QLCNIC_UNI_FIRMWARE_IDX_OFF
);
833 ver_str
= fw
->data
+ cpu_to_le32(fw_data_desc
->findex
) +
834 cpu_to_le32(fw_data_desc
->size
) - 17;
836 for (i
= 0; i
< 12; i
++) {
837 if (!strncmp(&ver_str
[i
], "REV=", 4)) {
838 ret
= sscanf(&ver_str
[i
+4], "%u.%u.%u ",
839 &major
, &minor
, &sub
);
843 return major
+ (minor
<< 8) + (sub
<< 16);
851 qlcnic_get_bios_version(struct qlcnic_adapter
*adapter
)
853 const struct firmware
*fw
= adapter
->fw
;
854 __le32 bios_ver
, prd_off
= adapter
->file_prd_off
;
856 if (adapter
->fw_type
!= QLCNIC_UNIFIED_ROMIMAGE
)
858 *(u32
*)&fw
->data
[QLCNIC_BIOS_VERSION_OFFSET
]);
860 bios_ver
= cpu_to_le32(*((u32
*) (&fw
->data
[prd_off
])
861 + QLCNIC_UNI_BIOS_VERSION_OFF
));
863 return (bios_ver
<< 16) + ((bios_ver
>> 8) & 0xff00) + (bios_ver
>> 24);
867 qlcnic_need_fw_reset(struct qlcnic_adapter
*adapter
)
869 u32 count
, old_count
;
870 u32 val
, version
, major
, minor
, build
;
873 if (adapter
->need_fw_reset
)
876 /* last attempt had failed */
877 if (QLCRD32(adapter
, CRB_CMDPEG_STATE
) == PHAN_INITIALIZE_FAILED
)
880 old_count
= QLCRD32(adapter
, QLCNIC_PEG_ALIVE_COUNTER
);
882 for (i
= 0; i
< 10; i
++) {
884 timeout
= msleep_interruptible(200);
886 QLCWR32(adapter
, CRB_CMDPEG_STATE
,
887 PHAN_INITIALIZE_FAILED
);
891 count
= QLCRD32(adapter
, QLCNIC_PEG_ALIVE_COUNTER
);
892 if (count
!= old_count
)
896 /* firmware is dead */
897 if (count
== old_count
)
900 /* check if we have got newer or different file firmware */
903 val
= qlcnic_get_fw_version(adapter
);
905 version
= QLCNIC_DECODE_VERSION(val
);
907 major
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MAJOR
);
908 minor
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MINOR
);
909 build
= QLCRD32(adapter
, QLCNIC_FW_VERSION_SUB
);
911 if (version
> QLCNIC_VERSION_CODE(major
, minor
, build
))
918 static const char *fw_name
[] = {
919 QLCNIC_UNIFIED_ROMIMAGE_NAME
,
920 QLCNIC_FLASH_ROMIMAGE_NAME
,
924 qlcnic_load_firmware(struct qlcnic_adapter
*adapter
)
927 u32 i
, flashaddr
, size
;
928 const struct firmware
*fw
= adapter
->fw
;
929 struct pci_dev
*pdev
= adapter
->pdev
;
931 dev_info(&pdev
->dev
, "loading firmware from %s\n",
932 fw_name
[adapter
->fw_type
]);
937 size
= (QLCNIC_IMAGE_START
- QLCNIC_BOOTLD_START
) / 8;
939 ptr64
= (u64
*)qlcnic_get_bootld_offs(adapter
);
940 flashaddr
= QLCNIC_BOOTLD_START
;
942 for (i
= 0; i
< size
; i
++) {
943 data
= cpu_to_le64(ptr64
[i
]);
945 if (qlcnic_pci_mem_write_2M(adapter
, flashaddr
, data
))
951 size
= (__force u32
)qlcnic_get_fw_size(adapter
) / 8;
953 ptr64
= (u64
*)qlcnic_get_fw_offs(adapter
);
954 flashaddr
= QLCNIC_IMAGE_START
;
956 for (i
= 0; i
< size
; i
++) {
957 data
= cpu_to_le64(ptr64
[i
]);
959 if (qlcnic_pci_mem_write_2M(adapter
,
966 size
= (__force u32
)qlcnic_get_fw_size(adapter
) % 8;
968 data
= cpu_to_le64(ptr64
[i
]);
970 if (qlcnic_pci_mem_write_2M(adapter
,
979 size
= (QLCNIC_IMAGE_START
- QLCNIC_BOOTLD_START
) / 8;
980 flashaddr
= QLCNIC_BOOTLD_START
;
982 for (i
= 0; i
< size
; i
++) {
983 if (qlcnic_rom_fast_read(adapter
,
984 flashaddr
, (int *)&lo
) != 0)
986 if (qlcnic_rom_fast_read(adapter
,
987 flashaddr
+ 4, (int *)&hi
) != 0)
990 data
= (((u64
)hi
<< 32) | lo
);
992 if (qlcnic_pci_mem_write_2M(adapter
,
1001 QLCWR32(adapter
, QLCNIC_CRB_PEG_NET_0
+ 0x18, 0x1020);
1002 QLCWR32(adapter
, QLCNIC_ROMUSB_GLB_SW_RESET
, 0x80001e);
1007 qlcnic_validate_firmware(struct qlcnic_adapter
*adapter
)
1010 u32 ver
, min_ver
, bios
, min_size
;
1011 struct pci_dev
*pdev
= adapter
->pdev
;
1012 const struct firmware
*fw
= adapter
->fw
;
1013 u8 fw_type
= adapter
->fw_type
;
1015 if (fw_type
== QLCNIC_UNIFIED_ROMIMAGE
) {
1016 if (qlcnic_validate_unified_romimage(adapter
))
1019 min_size
= QLCNIC_UNI_FW_MIN_SIZE
;
1021 val
= cpu_to_le32(*(u32
*)&fw
->data
[QLCNIC_FW_MAGIC_OFFSET
]);
1022 if ((__force u32
)val
!= QLCNIC_BDINFO_MAGIC
)
1025 min_size
= QLCNIC_FW_MIN_SIZE
;
1028 if (fw
->size
< min_size
)
1031 val
= qlcnic_get_fw_version(adapter
);
1033 min_ver
= QLCNIC_VERSION_CODE(4, 0, 216);
1035 ver
= QLCNIC_DECODE_VERSION(val
);
1037 if ((_major(ver
) > _QLCNIC_LINUX_MAJOR
) || (ver
< min_ver
)) {
1039 "%s: firmware version %d.%d.%d unsupported\n",
1040 fw_name
[fw_type
], _major(ver
), _minor(ver
), _build(ver
));
1044 val
= qlcnic_get_bios_version(adapter
);
1045 qlcnic_rom_fast_read(adapter
, QLCNIC_BIOS_VERSION_OFFSET
, (int *)&bios
);
1046 if ((__force u32
)val
!= bios
) {
1047 dev_err(&pdev
->dev
, "%s: firmware bios is incompatible\n",
1052 /* check if flashed firmware is newer */
1053 if (qlcnic_rom_fast_read(adapter
,
1054 QLCNIC_FW_VERSION_OFFSET
, (int *)&val
))
1057 val
= QLCNIC_DECODE_VERSION(val
);
1059 dev_info(&pdev
->dev
, "%s: firmware is older than flash\n",
1064 QLCWR32(adapter
, QLCNIC_CAM_RAM(0x1fc), QLCNIC_BDINFO_MAGIC
);
1069 qlcnic_get_next_fwtype(struct qlcnic_adapter
*adapter
)
1073 switch (adapter
->fw_type
) {
1074 case QLCNIC_UNKNOWN_ROMIMAGE
:
1075 fw_type
= QLCNIC_UNIFIED_ROMIMAGE
;
1078 case QLCNIC_UNIFIED_ROMIMAGE
:
1080 fw_type
= QLCNIC_FLASH_ROMIMAGE
;
1084 adapter
->fw_type
= fw_type
;
1089 void qlcnic_request_firmware(struct qlcnic_adapter
*adapter
)
1091 struct pci_dev
*pdev
= adapter
->pdev
;
1094 adapter
->fw_type
= QLCNIC_UNKNOWN_ROMIMAGE
;
1097 qlcnic_get_next_fwtype(adapter
);
1099 if (adapter
->fw_type
== QLCNIC_FLASH_ROMIMAGE
) {
1102 rc
= request_firmware(&adapter
->fw
,
1103 fw_name
[adapter
->fw_type
], &pdev
->dev
);
1107 rc
= qlcnic_validate_firmware(adapter
);
1109 release_firmware(adapter
->fw
);
1118 qlcnic_release_firmware(struct qlcnic_adapter
*adapter
)
1121 release_firmware(adapter
->fw
);
1125 int qlcnic_phantom_init(struct qlcnic_adapter
*adapter
)
1131 val
= QLCRD32(adapter
, CRB_CMDPEG_STATE
);
1134 case PHAN_INITIALIZE_COMPLETE
:
1135 case PHAN_INITIALIZE_ACK
:
1137 case PHAN_INITIALIZE_FAILED
:
1145 } while (--retries
);
1147 QLCWR32(adapter
, CRB_CMDPEG_STATE
, PHAN_INITIALIZE_FAILED
);
1150 dev_err(&adapter
->pdev
->dev
, "firmware init failed\n");
1155 qlcnic_receive_peg_ready(struct qlcnic_adapter
*adapter
)
1161 val
= QLCRD32(adapter
, CRB_RCVPEG_STATE
);
1163 if (val
== PHAN_PEG_RCV_INITIALIZED
)
1168 } while (--retries
);
1171 dev_err(&adapter
->pdev
->dev
, "Receive Peg initialization not "
1172 "complete, state: 0x%x.\n", val
);
1179 int qlcnic_init_firmware(struct qlcnic_adapter
*adapter
)
1183 err
= qlcnic_receive_peg_ready(adapter
);
1187 QLCWR32(adapter
, CRB_CMDPEG_STATE
, PHAN_INITIALIZE_ACK
);
1193 qlcnic_handle_linkevent(struct qlcnic_adapter
*adapter
,
1194 struct qlcnic_fw_msg
*msg
)
1199 u8 link_status
, module
, duplex
, autoneg
;
1200 struct net_device
*netdev
= adapter
->netdev
;
1202 adapter
->has_link_events
= 1;
1204 cable_OUI
= msg
->body
[1] & 0xffffffff;
1205 cable_len
= (msg
->body
[1] >> 32) & 0xffff;
1206 link_speed
= (msg
->body
[1] >> 48) & 0xffff;
1208 link_status
= msg
->body
[2] & 0xff;
1209 duplex
= (msg
->body
[2] >> 16) & 0xff;
1210 autoneg
= (msg
->body
[2] >> 24) & 0xff;
1212 module
= (msg
->body
[2] >> 8) & 0xff;
1213 if (module
== LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE
)
1214 dev_info(&netdev
->dev
, "unsupported cable: OUI 0x%x, "
1215 "length %d\n", cable_OUI
, cable_len
);
1216 else if (module
== LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN
)
1217 dev_info(&netdev
->dev
, "unsupported cable length %d\n",
1220 qlcnic_advert_link_change(adapter
, link_status
);
1222 if (duplex
== LINKEVENT_FULL_DUPLEX
)
1223 adapter
->link_duplex
= DUPLEX_FULL
;
1225 adapter
->link_duplex
= DUPLEX_HALF
;
1227 adapter
->module_type
= module
;
1228 adapter
->link_autoneg
= autoneg
;
1229 adapter
->link_speed
= link_speed
;
1233 qlcnic_handle_fw_message(int desc_cnt
, int index
,
1234 struct qlcnic_host_sds_ring
*sds_ring
)
1236 struct qlcnic_fw_msg msg
;
1237 struct status_desc
*desc
;
1240 while (desc_cnt
> 0 && i
< 8) {
1241 desc
= &sds_ring
->desc_head
[index
];
1242 msg
.words
[i
++] = le64_to_cpu(desc
->status_desc_data
[0]);
1243 msg
.words
[i
++] = le64_to_cpu(desc
->status_desc_data
[1]);
1245 index
= get_next_index(index
, sds_ring
->num_desc
);
1249 opcode
= qlcnic_get_nic_msg_opcode(msg
.body
[0]);
1251 case QLCNIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE
:
1252 qlcnic_handle_linkevent(sds_ring
->adapter
, &msg
);
1260 qlcnic_alloc_rx_skb(struct qlcnic_adapter
*adapter
,
1261 struct qlcnic_host_rds_ring
*rds_ring
,
1262 struct qlcnic_rx_buffer
*buffer
)
1264 struct sk_buff
*skb
;
1266 struct pci_dev
*pdev
= adapter
->pdev
;
1268 buffer
->skb
= dev_alloc_skb(rds_ring
->skb_size
);
1270 adapter
->stats
.skb_alloc_failure
++;
1276 skb_reserve(skb
, 2);
1278 dma
= pci_map_single(pdev
, skb
->data
,
1279 rds_ring
->dma_size
, PCI_DMA_FROMDEVICE
);
1281 if (pci_dma_mapping_error(pdev
, dma
)) {
1282 adapter
->stats
.rx_dma_map_error
++;
1283 dev_kfree_skb_any(skb
);
1290 buffer
->state
= QLCNIC_BUFFER_BUSY
;
1295 static struct sk_buff
*qlcnic_process_rxbuf(struct qlcnic_adapter
*adapter
,
1296 struct qlcnic_host_rds_ring
*rds_ring
, u16 index
, u16 cksum
)
1298 struct qlcnic_rx_buffer
*buffer
;
1299 struct sk_buff
*skb
;
1301 buffer
= &rds_ring
->rx_buf_arr
[index
];
1303 pci_unmap_single(adapter
->pdev
, buffer
->dma
, rds_ring
->dma_size
,
1304 PCI_DMA_FROMDEVICE
);
1308 adapter
->stats
.null_skb
++;
1312 if (likely(adapter
->rx_csum
&& cksum
== STATUS_CKSUM_OK
)) {
1313 adapter
->stats
.csummed
++;
1314 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1316 skb
->ip_summed
= CHECKSUM_NONE
;
1319 skb
->dev
= adapter
->netdev
;
1323 buffer
->state
= QLCNIC_BUFFER_FREE
;
1327 static struct qlcnic_rx_buffer
*
1328 qlcnic_process_rcv(struct qlcnic_adapter
*adapter
,
1329 struct qlcnic_host_sds_ring
*sds_ring
,
1330 int ring
, u64 sts_data0
)
1332 struct net_device
*netdev
= adapter
->netdev
;
1333 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1334 struct qlcnic_rx_buffer
*buffer
;
1335 struct sk_buff
*skb
;
1336 struct qlcnic_host_rds_ring
*rds_ring
;
1337 int index
, length
, cksum
, pkt_offset
;
1339 if (unlikely(ring
>= adapter
->max_rds_rings
))
1342 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1344 index
= qlcnic_get_sts_refhandle(sts_data0
);
1345 if (unlikely(index
>= rds_ring
->num_desc
))
1348 buffer
= &rds_ring
->rx_buf_arr
[index
];
1350 length
= qlcnic_get_sts_totallength(sts_data0
);
1351 cksum
= qlcnic_get_sts_status(sts_data0
);
1352 pkt_offset
= qlcnic_get_sts_pkt_offset(sts_data0
);
1354 skb
= qlcnic_process_rxbuf(adapter
, rds_ring
, index
, cksum
);
1358 if (length
> rds_ring
->skb_size
)
1359 skb_put(skb
, rds_ring
->skb_size
);
1361 skb_put(skb
, length
);
1364 skb_pull(skb
, pkt_offset
);
1366 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
);
1367 skb
->protocol
= eth_type_trans(skb
, netdev
);
1369 napi_gro_receive(&sds_ring
->napi
, skb
);
1371 adapter
->stats
.rx_pkts
++;
1372 adapter
->stats
.rxbytes
+= length
;
1377 #define QLC_TCP_HDR_SIZE 20
1378 #define QLC_TCP_TS_OPTION_SIZE 12
1379 #define QLC_TCP_TS_HDR_SIZE (QLC_TCP_HDR_SIZE + QLC_TCP_TS_OPTION_SIZE)
1381 static struct qlcnic_rx_buffer
*
1382 qlcnic_process_lro(struct qlcnic_adapter
*adapter
,
1383 struct qlcnic_host_sds_ring
*sds_ring
,
1384 int ring
, u64 sts_data0
, u64 sts_data1
)
1386 struct net_device
*netdev
= adapter
->netdev
;
1387 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1388 struct qlcnic_rx_buffer
*buffer
;
1389 struct sk_buff
*skb
;
1390 struct qlcnic_host_rds_ring
*rds_ring
;
1393 bool push
, timestamp
;
1394 int l2_hdr_offset
, l4_hdr_offset
;
1396 u16 lro_length
, length
, data_offset
;
1399 if (unlikely(ring
> adapter
->max_rds_rings
))
1402 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1404 index
= qlcnic_get_lro_sts_refhandle(sts_data0
);
1405 if (unlikely(index
> rds_ring
->num_desc
))
1408 buffer
= &rds_ring
->rx_buf_arr
[index
];
1410 timestamp
= qlcnic_get_lro_sts_timestamp(sts_data0
);
1411 lro_length
= qlcnic_get_lro_sts_length(sts_data0
);
1412 l2_hdr_offset
= qlcnic_get_lro_sts_l2_hdr_offset(sts_data0
);
1413 l4_hdr_offset
= qlcnic_get_lro_sts_l4_hdr_offset(sts_data0
);
1414 push
= qlcnic_get_lro_sts_push_flag(sts_data0
);
1415 seq_number
= qlcnic_get_lro_sts_seq_number(sts_data1
);
1417 skb
= qlcnic_process_rxbuf(adapter
, rds_ring
, index
, STATUS_CKSUM_OK
);
1422 data_offset
= l4_hdr_offset
+ QLC_TCP_TS_HDR_SIZE
;
1424 data_offset
= l4_hdr_offset
+ QLC_TCP_HDR_SIZE
;
1426 skb_put(skb
, lro_length
+ data_offset
);
1428 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
) + skb_headroom(skb
);
1430 skb_pull(skb
, l2_hdr_offset
);
1431 skb
->protocol
= eth_type_trans(skb
, netdev
);
1433 iph
= (struct iphdr
*)skb
->data
;
1434 th
= (struct tcphdr
*)(skb
->data
+ (iph
->ihl
<< 2));
1436 length
= (iph
->ihl
<< 2) + (th
->doff
<< 2) + lro_length
;
1437 iph
->tot_len
= htons(length
);
1439 iph
->check
= ip_fast_csum((unsigned char *)iph
, iph
->ihl
);
1441 th
->seq
= htonl(seq_number
);
1445 netif_receive_skb(skb
);
1447 adapter
->stats
.lro_pkts
++;
1448 adapter
->stats
.lrobytes
+= length
;
1454 qlcnic_process_rcv_ring(struct qlcnic_host_sds_ring
*sds_ring
, int max
)
1456 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
1457 struct list_head
*cur
;
1458 struct status_desc
*desc
;
1459 struct qlcnic_rx_buffer
*rxbuf
;
1460 u64 sts_data0
, sts_data1
;
1463 int opcode
, ring
, desc_cnt
;
1464 u32 consumer
= sds_ring
->consumer
;
1466 while (count
< max
) {
1467 desc
= &sds_ring
->desc_head
[consumer
];
1468 sts_data0
= le64_to_cpu(desc
->status_desc_data
[0]);
1470 if (!(sts_data0
& STATUS_OWNER_HOST
))
1473 desc_cnt
= qlcnic_get_sts_desc_cnt(sts_data0
);
1474 opcode
= qlcnic_get_sts_opcode(sts_data0
);
1477 case QLCNIC_RXPKT_DESC
:
1478 case QLCNIC_OLD_RXPKT_DESC
:
1479 case QLCNIC_SYN_OFFLOAD
:
1480 ring
= qlcnic_get_sts_type(sts_data0
);
1481 rxbuf
= qlcnic_process_rcv(adapter
, sds_ring
,
1484 case QLCNIC_LRO_DESC
:
1485 ring
= qlcnic_get_lro_sts_type(sts_data0
);
1486 sts_data1
= le64_to_cpu(desc
->status_desc_data
[1]);
1487 rxbuf
= qlcnic_process_lro(adapter
, sds_ring
,
1488 ring
, sts_data0
, sts_data1
);
1490 case QLCNIC_RESPONSE_DESC
:
1491 qlcnic_handle_fw_message(desc_cnt
, consumer
, sds_ring
);
1496 WARN_ON(desc_cnt
> 1);
1499 list_add_tail(&rxbuf
->list
, &sds_ring
->free_list
[ring
]);
1501 adapter
->stats
.null_rxbuf
++;
1504 for (; desc_cnt
> 0; desc_cnt
--) {
1505 desc
= &sds_ring
->desc_head
[consumer
];
1506 desc
->status_desc_data
[0] =
1507 cpu_to_le64(STATUS_OWNER_PHANTOM
);
1508 consumer
= get_next_index(consumer
, sds_ring
->num_desc
);
1513 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1514 struct qlcnic_host_rds_ring
*rds_ring
=
1515 &adapter
->recv_ctx
.rds_rings
[ring
];
1517 if (!list_empty(&sds_ring
->free_list
[ring
])) {
1518 list_for_each(cur
, &sds_ring
->free_list
[ring
]) {
1519 rxbuf
= list_entry(cur
,
1520 struct qlcnic_rx_buffer
, list
);
1521 qlcnic_alloc_rx_skb(adapter
, rds_ring
, rxbuf
);
1523 spin_lock(&rds_ring
->lock
);
1524 list_splice_tail_init(&sds_ring
->free_list
[ring
],
1525 &rds_ring
->free_list
);
1526 spin_unlock(&rds_ring
->lock
);
1529 qlcnic_post_rx_buffers_nodb(adapter
, rds_ring
);
1533 sds_ring
->consumer
= consumer
;
1534 writel(consumer
, sds_ring
->crb_sts_consumer
);
1541 qlcnic_post_rx_buffers(struct qlcnic_adapter
*adapter
, u32 ringid
,
1542 struct qlcnic_host_rds_ring
*rds_ring
)
1544 struct rcv_desc
*pdesc
;
1545 struct qlcnic_rx_buffer
*buffer
;
1546 int producer
, count
= 0;
1547 struct list_head
*head
;
1549 spin_lock(&rds_ring
->lock
);
1551 producer
= rds_ring
->producer
;
1553 head
= &rds_ring
->free_list
;
1554 while (!list_empty(head
)) {
1556 buffer
= list_entry(head
->next
, struct qlcnic_rx_buffer
, list
);
1559 if (qlcnic_alloc_rx_skb(adapter
, rds_ring
, buffer
))
1564 list_del(&buffer
->list
);
1566 /* make a rcv descriptor */
1567 pdesc
= &rds_ring
->desc_head
[producer
];
1568 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1569 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1570 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1572 producer
= get_next_index(producer
, rds_ring
->num_desc
);
1576 rds_ring
->producer
= producer
;
1577 writel((producer
-1) & (rds_ring
->num_desc
-1),
1578 rds_ring
->crb_rcv_producer
);
1580 spin_unlock(&rds_ring
->lock
);
1584 qlcnic_post_rx_buffers_nodb(struct qlcnic_adapter
*adapter
,
1585 struct qlcnic_host_rds_ring
*rds_ring
)
1587 struct rcv_desc
*pdesc
;
1588 struct qlcnic_rx_buffer
*buffer
;
1589 int producer
, count
= 0;
1590 struct list_head
*head
;
1592 if (!spin_trylock(&rds_ring
->lock
))
1595 producer
= rds_ring
->producer
;
1597 head
= &rds_ring
->free_list
;
1598 while (!list_empty(head
)) {
1600 buffer
= list_entry(head
->next
, struct qlcnic_rx_buffer
, list
);
1603 if (qlcnic_alloc_rx_skb(adapter
, rds_ring
, buffer
))
1608 list_del(&buffer
->list
);
1610 /* make a rcv descriptor */
1611 pdesc
= &rds_ring
->desc_head
[producer
];
1612 pdesc
->reference_handle
= cpu_to_le16(buffer
->ref_handle
);
1613 pdesc
->buffer_length
= cpu_to_le32(rds_ring
->dma_size
);
1614 pdesc
->addr_buffer
= cpu_to_le64(buffer
->dma
);
1616 producer
= get_next_index(producer
, rds_ring
->num_desc
);
1620 rds_ring
->producer
= producer
;
1621 writel((producer
- 1) & (rds_ring
->num_desc
- 1),
1622 rds_ring
->crb_rcv_producer
);
1624 spin_unlock(&rds_ring
->lock
);
1627 static struct qlcnic_rx_buffer
*
1628 qlcnic_process_rcv_diag(struct qlcnic_adapter
*adapter
,
1629 struct qlcnic_host_sds_ring
*sds_ring
,
1630 int ring
, u64 sts_data0
)
1632 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1633 struct qlcnic_rx_buffer
*buffer
;
1634 struct sk_buff
*skb
;
1635 struct qlcnic_host_rds_ring
*rds_ring
;
1636 int index
, length
, cksum
, pkt_offset
;
1638 if (unlikely(ring
>= adapter
->max_rds_rings
))
1641 rds_ring
= &recv_ctx
->rds_rings
[ring
];
1643 index
= qlcnic_get_sts_refhandle(sts_data0
);
1644 if (unlikely(index
>= rds_ring
->num_desc
))
1647 buffer
= &rds_ring
->rx_buf_arr
[index
];
1649 length
= qlcnic_get_sts_totallength(sts_data0
);
1650 cksum
= qlcnic_get_sts_status(sts_data0
);
1651 pkt_offset
= qlcnic_get_sts_pkt_offset(sts_data0
);
1653 skb
= qlcnic_process_rxbuf(adapter
, rds_ring
, index
, cksum
);
1657 skb_put(skb
, rds_ring
->skb_size
);
1660 skb_pull(skb
, pkt_offset
);
1662 skb
->truesize
= skb
->len
+ sizeof(struct sk_buff
);
1664 if (!qlcnic_check_loopback_buff(skb
->data
))
1665 adapter
->diag_cnt
++;
1667 dev_kfree_skb_any(skb
);
1668 adapter
->stats
.rx_pkts
++;
1669 adapter
->stats
.rxbytes
+= length
;
1675 qlcnic_process_rcv_ring_diag(struct qlcnic_host_sds_ring
*sds_ring
)
1677 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
1678 struct status_desc
*desc
;
1679 struct qlcnic_rx_buffer
*rxbuf
;
1682 int opcode
, ring
, desc_cnt
;
1683 u32 consumer
= sds_ring
->consumer
;
1685 desc
= &sds_ring
->desc_head
[consumer
];
1686 sts_data0
= le64_to_cpu(desc
->status_desc_data
[0]);
1688 if (!(sts_data0
& STATUS_OWNER_HOST
))
1691 desc_cnt
= qlcnic_get_sts_desc_cnt(sts_data0
);
1692 opcode
= qlcnic_get_sts_opcode(sts_data0
);
1694 ring
= qlcnic_get_sts_type(sts_data0
);
1695 rxbuf
= qlcnic_process_rcv_diag(adapter
, sds_ring
,
1698 desc
->status_desc_data
[0] = cpu_to_le64(STATUS_OWNER_PHANTOM
);
1699 consumer
= get_next_index(consumer
, sds_ring
->num_desc
);
1701 sds_ring
->consumer
= consumer
;
1702 writel(consumer
, sds_ring
->crb_sts_consumer
);