2 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2010 QLogic Corporation
5 * See LICENSE.qlcnic for copyright and licensing details.
11 qlcnic_poll_rsp(struct qlcnic_adapter
*adapter
)
17 /* give atleast 1ms for firmware to respond */
20 if (++timeout
> QLCNIC_OS_CRB_RETRY_COUNT
)
21 return QLCNIC_CDRP_RSP_TIMEOUT
;
23 rsp
= QLCRD32(adapter
, QLCNIC_CDRP_CRB_OFFSET
);
24 } while (!QLCNIC_CDRP_IS_RSP(rsp
));
30 qlcnic_issue_cmd(struct qlcnic_adapter
*adapter
,
31 u32 pci_fn
, u32 version
, u32 arg1
, u32 arg2
, u32 arg3
, u32 cmd
,
36 u32 rcode
= QLCNIC_RCODE_SUCCESS
;
37 struct pci_dev
*pdev
= adapter
->pdev
;
39 signature
= QLCNIC_CDRP_SIGNATURE_MAKE(pci_fn
, version
);
41 /* Acquire semaphore before accessing CRB */
42 if (qlcnic_api_lock(adapter
))
43 return QLCNIC_RCODE_TIMEOUT
;
45 QLCWR32(adapter
, QLCNIC_SIGN_CRB_OFFSET
, signature
);
46 QLCWR32(adapter
, QLCNIC_ARG1_CRB_OFFSET
, arg1
);
47 QLCWR32(adapter
, QLCNIC_ARG2_CRB_OFFSET
, arg2
);
48 QLCWR32(adapter
, QLCNIC_ARG3_CRB_OFFSET
, arg3
);
49 QLCWR32(adapter
, QLCNIC_CDRP_CRB_OFFSET
, QLCNIC_CDRP_FORM_CMD(cmd
));
51 rsp
= qlcnic_poll_rsp(adapter
);
53 if (rsp
== QLCNIC_CDRP_RSP_TIMEOUT
) {
54 dev_err(&pdev
->dev
, "card response timeout.\n");
55 rcode
= QLCNIC_RCODE_TIMEOUT
;
56 } else if (rsp
== QLCNIC_CDRP_RSP_FAIL
) {
57 rcode
= QLCRD32(adapter
, QLCNIC_ARG1_CRB_OFFSET
);
58 dev_err(&pdev
->dev
, "failed card response code:0x%x\n",
60 } else if (rsp
== QLCNIC_CDRP_RSP_OK
) {
62 *rd_args
[1] = QLCRD32(adapter
, QLCNIC_ARG2_CRB_OFFSET
);
64 *rd_args
[2] = QLCRD32(adapter
, QLCNIC_ARG3_CRB_OFFSET
);
67 *rd_args
[0] = QLCRD32(adapter
, QLCNIC_ARG1_CRB_OFFSET
);
69 /* Release semaphore */
70 qlcnic_api_unlock(adapter
);
75 static uint32_t qlcnic_temp_checksum(uint32_t *temp_buffer
, u16 temp_size
)
78 int count
= temp_size
/ sizeof(uint32_t);
80 sum
+= *temp_buffer
++;
82 sum
= (sum
& 0xFFFFFFFF) + (sum
>> 32);
86 int qlcnic_fw_cmd_get_minidump_temp(struct qlcnic_adapter
*adapter
)
91 u32 version
, csum
, *template, *tmp_buf
, rsp
;
93 struct qlcnic_hardware_context
*ahw
;
94 struct qlcnic_dump_template_hdr
*tmpl_hdr
, *tmp_tmpl
;
95 dma_addr_t tmp_addr_t
= 0;
99 rd_args
[1] = (u32
*) &temp_size
;
100 rd_args
[2] = &version
;
101 err
= qlcnic_issue_cmd(adapter
,
102 adapter
->ahw
->pci_func
,
103 adapter
->fw_hal_version
,
107 QLCNIC_CDRP_CMD_TEMP_SIZE
,
109 if (err
!= QLCNIC_RCODE_SUCCESS
) {
110 dev_info(&adapter
->pdev
->dev
,
111 "Can't get template size %d\n", rsp
);
118 tmp_addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, temp_size
,
119 &tmp_addr_t
, GFP_KERNEL
);
121 dev_err(&adapter
->pdev
->dev
,
122 "Can't get memory for FW dump template\n");
125 memset(rd_args
, 0, sizeof(rd_args
));
126 err
= qlcnic_issue_cmd(adapter
,
127 adapter
->ahw
->pci_func
,
128 adapter
->fw_hal_version
,
132 QLCNIC_CDRP_CMD_GET_TEMP_HDR
,
135 if (err
!= QLCNIC_RCODE_SUCCESS
) {
136 dev_err(&adapter
->pdev
->dev
,
137 "Failed to get mini dump template header %d\n", err
);
142 csum
= qlcnic_temp_checksum((uint32_t *) tmp_addr
, temp_size
);
144 dev_err(&adapter
->pdev
->dev
,
145 "Template header checksum validation failed\n");
149 ahw
->fw_dump
.tmpl_hdr
= vzalloc(temp_size
);
150 if (!ahw
->fw_dump
.tmpl_hdr
) {
155 template = (u32
*) ahw
->fw_dump
.tmpl_hdr
;
156 for (i
= 0; i
< temp_size
/sizeof(u32
); i
++)
157 *template++ = __le32_to_cpu(*tmp_buf
++);
159 tmpl_hdr
= ahw
->fw_dump
.tmpl_hdr
;
160 tmpl_hdr
->drv_cap_mask
= QLCNIC_DUMP_MASK_DEF
;
161 ahw
->fw_dump
.enable
= 1;
163 dma_free_coherent(&adapter
->pdev
->dev
, temp_size
, tmp_addr
, tmp_addr_t
);
168 qlcnic_fw_cmd_set_mtu(struct qlcnic_adapter
*adapter
, int mtu
)
171 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
173 memset(rd_args
, 0, sizeof(rd_args
));
174 if (recv_ctx
->state
== QLCNIC_HOST_CTX_STATE_ACTIVE
) {
175 if (qlcnic_issue_cmd(adapter
,
176 adapter
->ahw
->pci_func
,
177 adapter
->fw_hal_version
,
178 recv_ctx
->context_id
,
181 QLCNIC_CDRP_CMD_SET_MTU
,
184 dev_err(&adapter
->pdev
->dev
, "Failed to set mtu\n");
193 qlcnic_fw_cmd_create_rx_ctx(struct qlcnic_adapter
*adapter
)
196 struct qlcnic_hostrq_rx_ctx
*prq
;
197 struct qlcnic_cardrsp_rx_ctx
*prsp
;
198 struct qlcnic_hostrq_rds_ring
*prq_rds
;
199 struct qlcnic_hostrq_sds_ring
*prq_sds
;
200 struct qlcnic_cardrsp_rds_ring
*prsp_rds
;
201 struct qlcnic_cardrsp_sds_ring
*prsp_sds
;
202 struct qlcnic_host_rds_ring
*rds_ring
;
203 struct qlcnic_host_sds_ring
*sds_ring
;
205 dma_addr_t hostrq_phys_addr
, cardrsp_phys_addr
;
208 u8 i
, nrds_rings
, nsds_rings
;
209 size_t rq_size
, rsp_size
;
210 u32 cap
, reg
, val
, reg2
;
214 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
216 nrds_rings
= adapter
->max_rds_rings
;
217 nsds_rings
= adapter
->max_sds_rings
;
220 SIZEOF_HOSTRQ_RX(struct qlcnic_hostrq_rx_ctx
, nrds_rings
,
223 SIZEOF_CARDRSP_RX(struct qlcnic_cardrsp_rx_ctx
, nrds_rings
,
226 addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, rq_size
,
227 &hostrq_phys_addr
, GFP_KERNEL
);
232 addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, rsp_size
,
233 &cardrsp_phys_addr
, GFP_KERNEL
);
240 prq
->host_rsp_dma_addr
= cpu_to_le64(cardrsp_phys_addr
);
242 cap
= (QLCNIC_CAP0_LEGACY_CONTEXT
| QLCNIC_CAP0_LEGACY_MN
243 | QLCNIC_CAP0_VALIDOFF
);
244 cap
|= (QLCNIC_CAP0_JUMBO_CONTIGUOUS
| QLCNIC_CAP0_LRO_CONTIGUOUS
);
246 prq
->valid_field_offset
= offsetof(struct qlcnic_hostrq_rx_ctx
,
248 prq
->txrx_sds_binding
= nsds_rings
- 1;
250 prq
->capabilities
[0] = cpu_to_le32(cap
);
251 prq
->host_int_crb_mode
=
252 cpu_to_le32(QLCNIC_HOST_INT_CRB_MODE_SHARED
);
253 prq
->host_rds_crb_mode
=
254 cpu_to_le32(QLCNIC_HOST_RDS_CRB_MODE_UNIQUE
);
256 prq
->num_rds_rings
= cpu_to_le16(nrds_rings
);
257 prq
->num_sds_rings
= cpu_to_le16(nsds_rings
);
258 prq
->rds_ring_offset
= 0;
260 val
= le32_to_cpu(prq
->rds_ring_offset
) +
261 (sizeof(struct qlcnic_hostrq_rds_ring
) * nrds_rings
);
262 prq
->sds_ring_offset
= cpu_to_le32(val
);
264 prq_rds
= (struct qlcnic_hostrq_rds_ring
*)(prq
->data
+
265 le32_to_cpu(prq
->rds_ring_offset
));
267 for (i
= 0; i
< nrds_rings
; i
++) {
269 rds_ring
= &recv_ctx
->rds_rings
[i
];
270 rds_ring
->producer
= 0;
272 prq_rds
[i
].host_phys_addr
= cpu_to_le64(rds_ring
->phys_addr
);
273 prq_rds
[i
].ring_size
= cpu_to_le32(rds_ring
->num_desc
);
274 prq_rds
[i
].ring_kind
= cpu_to_le32(i
);
275 prq_rds
[i
].buff_size
= cpu_to_le64(rds_ring
->dma_size
);
278 prq_sds
= (struct qlcnic_hostrq_sds_ring
*)(prq
->data
+
279 le32_to_cpu(prq
->sds_ring_offset
));
281 for (i
= 0; i
< nsds_rings
; i
++) {
283 sds_ring
= &recv_ctx
->sds_rings
[i
];
284 sds_ring
->consumer
= 0;
285 memset(sds_ring
->desc_head
, 0, STATUS_DESC_RINGSIZE(sds_ring
));
287 prq_sds
[i
].host_phys_addr
= cpu_to_le64(sds_ring
->phys_addr
);
288 prq_sds
[i
].ring_size
= cpu_to_le32(sds_ring
->num_desc
);
289 prq_sds
[i
].msi_index
= cpu_to_le16(i
);
292 phys_addr
= hostrq_phys_addr
;
293 memset(rd_args
, 0, sizeof(rd_args
));
294 err
= qlcnic_issue_cmd(adapter
,
295 adapter
->ahw
->pci_func
,
296 adapter
->fw_hal_version
,
297 (u32
)(phys_addr
>> 32),
298 (u32
)(phys_addr
& 0xffffffff),
300 QLCNIC_CDRP_CMD_CREATE_RX_CTX
,
303 dev_err(&adapter
->pdev
->dev
,
304 "Failed to create rx ctx in firmware%d\n", err
);
309 prsp_rds
= ((struct qlcnic_cardrsp_rds_ring
*)
310 &prsp
->data
[le32_to_cpu(prsp
->rds_ring_offset
)]);
312 for (i
= 0; i
< le16_to_cpu(prsp
->num_rds_rings
); i
++) {
313 rds_ring
= &recv_ctx
->rds_rings
[i
];
315 reg
= le32_to_cpu(prsp_rds
[i
].host_producer_crb
);
316 rds_ring
->crb_rcv_producer
= adapter
->ahw
->pci_base0
+ reg
;
319 prsp_sds
= ((struct qlcnic_cardrsp_sds_ring
*)
320 &prsp
->data
[le32_to_cpu(prsp
->sds_ring_offset
)]);
322 for (i
= 0; i
< le16_to_cpu(prsp
->num_sds_rings
); i
++) {
323 sds_ring
= &recv_ctx
->sds_rings
[i
];
325 reg
= le32_to_cpu(prsp_sds
[i
].host_consumer_crb
);
326 reg2
= le32_to_cpu(prsp_sds
[i
].interrupt_crb
);
328 sds_ring
->crb_sts_consumer
= adapter
->ahw
->pci_base0
+ reg
;
329 sds_ring
->crb_intr_mask
= adapter
->ahw
->pci_base0
+ reg2
;
332 recv_ctx
->state
= le32_to_cpu(prsp
->host_ctx_state
);
333 recv_ctx
->context_id
= le16_to_cpu(prsp
->context_id
);
334 recv_ctx
->virt_port
= prsp
->virt_port
;
337 dma_free_coherent(&adapter
->pdev
->dev
, rsp_size
, prsp
,
340 dma_free_coherent(&adapter
->pdev
->dev
, rq_size
, prq
, hostrq_phys_addr
);
345 qlcnic_fw_cmd_destroy_rx_ctx(struct qlcnic_adapter
*adapter
)
348 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
350 memset(rd_args
, 0, sizeof(rd_args
));
351 if (qlcnic_issue_cmd(adapter
,
352 adapter
->ahw
->pci_func
,
353 adapter
->fw_hal_version
,
354 recv_ctx
->context_id
,
355 QLCNIC_DESTROY_CTX_RESET
,
357 QLCNIC_CDRP_CMD_DESTROY_RX_CTX
,
360 dev_err(&adapter
->pdev
->dev
,
361 "Failed to destroy rx ctx in firmware\n");
364 recv_ctx
->state
= QLCNIC_HOST_CTX_STATE_FREED
;
368 qlcnic_fw_cmd_create_tx_ctx(struct qlcnic_adapter
*adapter
)
370 struct qlcnic_hostrq_tx_ctx
*prq
;
371 struct qlcnic_hostrq_cds_ring
*prq_cds
;
372 struct qlcnic_cardrsp_tx_ctx
*prsp
;
373 void *rq_addr
, *rsp_addr
;
374 size_t rq_size
, rsp_size
;
379 dma_addr_t rq_phys_addr
, rsp_phys_addr
;
380 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
382 /* reset host resources */
383 tx_ring
->producer
= 0;
384 tx_ring
->sw_consumer
= 0;
385 *(tx_ring
->hw_consumer
) = 0;
387 rq_size
= SIZEOF_HOSTRQ_TX(struct qlcnic_hostrq_tx_ctx
);
388 rq_addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, rq_size
,
389 &rq_phys_addr
, GFP_KERNEL
);
393 rsp_size
= SIZEOF_CARDRSP_TX(struct qlcnic_cardrsp_tx_ctx
);
394 rsp_addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, rsp_size
,
395 &rsp_phys_addr
, GFP_KERNEL
);
401 memset(rq_addr
, 0, rq_size
);
404 memset(rsp_addr
, 0, rsp_size
);
407 prq
->host_rsp_dma_addr
= cpu_to_le64(rsp_phys_addr
);
409 temp
= (QLCNIC_CAP0_LEGACY_CONTEXT
| QLCNIC_CAP0_LEGACY_MN
|
411 prq
->capabilities
[0] = cpu_to_le32(temp
);
413 prq
->host_int_crb_mode
=
414 cpu_to_le32(QLCNIC_HOST_INT_CRB_MODE_SHARED
);
416 prq
->interrupt_ctl
= 0;
418 prq
->cmd_cons_dma_addr
= cpu_to_le64(tx_ring
->hw_cons_phys_addr
);
420 prq_cds
= &prq
->cds_ring
;
422 prq_cds
->host_phys_addr
= cpu_to_le64(tx_ring
->phys_addr
);
423 prq_cds
->ring_size
= cpu_to_le32(tx_ring
->num_desc
);
425 phys_addr
= rq_phys_addr
;
426 memset(rd_args
, 0, sizeof(rd_args
));
427 err
= qlcnic_issue_cmd(adapter
,
428 adapter
->ahw
->pci_func
,
429 adapter
->fw_hal_version
,
430 (u32
)(phys_addr
>> 32),
431 ((u32
)phys_addr
& 0xffffffff),
433 QLCNIC_CDRP_CMD_CREATE_TX_CTX
,
436 if (err
== QLCNIC_RCODE_SUCCESS
) {
437 temp
= le32_to_cpu(prsp
->cds_ring
.host_producer_crb
);
438 tx_ring
->crb_cmd_producer
= adapter
->ahw
->pci_base0
+ temp
;
440 adapter
->tx_context_id
=
441 le16_to_cpu(prsp
->context_id
);
443 dev_err(&adapter
->pdev
->dev
,
444 "Failed to create tx ctx in firmware%d\n", err
);
448 dma_free_coherent(&adapter
->pdev
->dev
, rsp_size
, rsp_addr
,
452 dma_free_coherent(&adapter
->pdev
->dev
, rq_size
, rq_addr
, rq_phys_addr
);
458 qlcnic_fw_cmd_destroy_tx_ctx(struct qlcnic_adapter
*adapter
)
462 memset(rd_args
, 0, sizeof(rd_args
));
463 if (qlcnic_issue_cmd(adapter
,
464 adapter
->ahw
->pci_func
,
465 adapter
->fw_hal_version
,
466 adapter
->tx_context_id
,
467 QLCNIC_DESTROY_CTX_RESET
,
469 QLCNIC_CDRP_CMD_DESTROY_TX_CTX
,
472 dev_err(&adapter
->pdev
->dev
,
473 "Failed to destroy tx ctx in firmware\n");
478 qlcnic_fw_cmd_set_port(struct qlcnic_adapter
*adapter
, u32 config
)
482 memset(rd_args
, 0, sizeof(rd_args
));
483 return qlcnic_issue_cmd(adapter
,
484 adapter
->ahw
->pci_func
,
485 adapter
->fw_hal_version
,
489 QLCNIC_CDRP_CMD_CONFIG_PORT
,
493 int qlcnic_alloc_hw_resources(struct qlcnic_adapter
*adapter
)
498 struct qlcnic_recv_context
*recv_ctx
;
499 struct qlcnic_host_rds_ring
*rds_ring
;
500 struct qlcnic_host_sds_ring
*sds_ring
;
501 struct qlcnic_host_tx_ring
*tx_ring
;
503 struct pci_dev
*pdev
= adapter
->pdev
;
505 recv_ctx
= adapter
->recv_ctx
;
506 tx_ring
= adapter
->tx_ring
;
508 tx_ring
->hw_consumer
= (__le32
*) dma_alloc_coherent(&pdev
->dev
,
509 sizeof(u32
), &tx_ring
->hw_cons_phys_addr
, GFP_KERNEL
);
510 if (tx_ring
->hw_consumer
== NULL
) {
511 dev_err(&pdev
->dev
, "failed to allocate tx consumer\n");
516 addr
= dma_alloc_coherent(&pdev
->dev
, TX_DESC_RINGSIZE(tx_ring
),
517 &tx_ring
->phys_addr
, GFP_KERNEL
);
520 dev_err(&pdev
->dev
, "failed to allocate tx desc ring\n");
525 tx_ring
->desc_head
= addr
;
527 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
528 rds_ring
= &recv_ctx
->rds_rings
[ring
];
529 addr
= dma_alloc_coherent(&adapter
->pdev
->dev
,
530 RCV_DESC_RINGSIZE(rds_ring
),
531 &rds_ring
->phys_addr
, GFP_KERNEL
);
534 "failed to allocate rds ring [%d]\n", ring
);
538 rds_ring
->desc_head
= addr
;
542 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
543 sds_ring
= &recv_ctx
->sds_rings
[ring
];
545 addr
= dma_alloc_coherent(&adapter
->pdev
->dev
,
546 STATUS_DESC_RINGSIZE(sds_ring
),
547 &sds_ring
->phys_addr
, GFP_KERNEL
);
550 "failed to allocate sds ring [%d]\n", ring
);
554 sds_ring
->desc_head
= addr
;
560 qlcnic_free_hw_resources(adapter
);
565 int qlcnic_fw_create_ctx(struct qlcnic_adapter
*adapter
)
569 if (adapter
->flags
& QLCNIC_NEED_FLR
) {
570 pci_reset_function(adapter
->pdev
);
571 adapter
->flags
&= ~QLCNIC_NEED_FLR
;
574 err
= qlcnic_fw_cmd_create_rx_ctx(adapter
);
578 err
= qlcnic_fw_cmd_create_tx_ctx(adapter
);
580 qlcnic_fw_cmd_destroy_rx_ctx(adapter
);
584 set_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
);
588 void qlcnic_fw_destroy_ctx(struct qlcnic_adapter
*adapter
)
590 if (test_and_clear_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
)) {
591 qlcnic_fw_cmd_destroy_rx_ctx(adapter
);
592 qlcnic_fw_cmd_destroy_tx_ctx(adapter
);
594 /* Allow dma queues to drain after context reset */
599 void qlcnic_free_hw_resources(struct qlcnic_adapter
*adapter
)
601 struct qlcnic_recv_context
*recv_ctx
;
602 struct qlcnic_host_rds_ring
*rds_ring
;
603 struct qlcnic_host_sds_ring
*sds_ring
;
604 struct qlcnic_host_tx_ring
*tx_ring
;
607 recv_ctx
= adapter
->recv_ctx
;
609 tx_ring
= adapter
->tx_ring
;
610 if (tx_ring
->hw_consumer
!= NULL
) {
611 dma_free_coherent(&adapter
->pdev
->dev
,
613 tx_ring
->hw_consumer
,
614 tx_ring
->hw_cons_phys_addr
);
615 tx_ring
->hw_consumer
= NULL
;
618 if (tx_ring
->desc_head
!= NULL
) {
619 dma_free_coherent(&adapter
->pdev
->dev
,
620 TX_DESC_RINGSIZE(tx_ring
),
621 tx_ring
->desc_head
, tx_ring
->phys_addr
);
622 tx_ring
->desc_head
= NULL
;
625 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
626 rds_ring
= &recv_ctx
->rds_rings
[ring
];
628 if (rds_ring
->desc_head
!= NULL
) {
629 dma_free_coherent(&adapter
->pdev
->dev
,
630 RCV_DESC_RINGSIZE(rds_ring
),
632 rds_ring
->phys_addr
);
633 rds_ring
->desc_head
= NULL
;
637 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
638 sds_ring
= &recv_ctx
->sds_rings
[ring
];
640 if (sds_ring
->desc_head
!= NULL
) {
641 dma_free_coherent(&adapter
->pdev
->dev
,
642 STATUS_DESC_RINGSIZE(sds_ring
),
644 sds_ring
->phys_addr
);
645 sds_ring
->desc_head
= NULL
;
651 /* Get MAC address of a NIC partition */
652 int qlcnic_get_mac_address(struct qlcnic_adapter
*adapter
, u8
*mac
)
655 u32 arg1
, rd_arg1
, rd_arg2
;
658 arg1
= adapter
->ahw
->pci_func
| BIT_8
;
659 rd_args
[0] = &rd_arg1
;
660 rd_args
[1] = &rd_arg2
;
662 err
= qlcnic_issue_cmd(adapter
,
663 adapter
->ahw
->pci_func
,
664 adapter
->fw_hal_version
,
668 QLCNIC_CDRP_CMD_MAC_ADDRESS
,
671 if (err
== QLCNIC_RCODE_SUCCESS
)
672 qlcnic_fetch_mac(adapter
, rd_arg1
, rd_arg2
, 0, mac
);
674 dev_err(&adapter
->pdev
->dev
,
675 "Failed to get mac address%d\n", err
);
682 /* Get info of a NIC partition */
683 int qlcnic_get_nic_info(struct qlcnic_adapter
*adapter
,
684 struct qlcnic_info
*npar_info
, u8 func_id
)
687 dma_addr_t nic_dma_t
;
688 struct qlcnic_info
*nic_info
;
691 size_t nic_size
= sizeof(struct qlcnic_info
);
693 nic_info_addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, nic_size
,
694 &nic_dma_t
, GFP_KERNEL
);
697 memset(nic_info_addr
, 0, nic_size
);
699 nic_info
= nic_info_addr
;
700 memset(rd_args
, 0, sizeof(rd_args
));
701 err
= qlcnic_issue_cmd(adapter
,
702 adapter
->ahw
->pci_func
,
703 adapter
->fw_hal_version
,
706 (func_id
<< 16 | nic_size
),
707 QLCNIC_CDRP_CMD_GET_NIC_INFO
,
710 if (err
== QLCNIC_RCODE_SUCCESS
) {
711 npar_info
->pci_func
= le16_to_cpu(nic_info
->pci_func
);
712 npar_info
->op_mode
= le16_to_cpu(nic_info
->op_mode
);
713 npar_info
->phys_port
= le16_to_cpu(nic_info
->phys_port
);
714 npar_info
->switch_mode
= le16_to_cpu(nic_info
->switch_mode
);
715 npar_info
->max_tx_ques
= le16_to_cpu(nic_info
->max_tx_ques
);
716 npar_info
->max_rx_ques
= le16_to_cpu(nic_info
->max_rx_ques
);
717 npar_info
->min_tx_bw
= le16_to_cpu(nic_info
->min_tx_bw
);
718 npar_info
->max_tx_bw
= le16_to_cpu(nic_info
->max_tx_bw
);
719 npar_info
->capabilities
= le32_to_cpu(nic_info
->capabilities
);
720 npar_info
->max_mtu
= le16_to_cpu(nic_info
->max_mtu
);
722 dev_info(&adapter
->pdev
->dev
,
723 "phy port: %d switch_mode: %d,\n"
724 "\tmax_tx_q: %d max_rx_q: %d min_tx_bw: 0x%x,\n"
725 "\tmax_tx_bw: 0x%x max_mtu:0x%x, capabilities: 0x%x\n",
726 npar_info
->phys_port
, npar_info
->switch_mode
,
727 npar_info
->max_tx_ques
, npar_info
->max_rx_ques
,
728 npar_info
->min_tx_bw
, npar_info
->max_tx_bw
,
729 npar_info
->max_mtu
, npar_info
->capabilities
);
731 dev_err(&adapter
->pdev
->dev
,
732 "Failed to get nic info%d\n", err
);
736 dma_free_coherent(&adapter
->pdev
->dev
, nic_size
, nic_info_addr
,
741 /* Configure a NIC partition */
742 int qlcnic_set_nic_info(struct qlcnic_adapter
*adapter
, struct qlcnic_info
*nic
)
745 dma_addr_t nic_dma_t
;
748 struct qlcnic_info
*nic_info
;
749 size_t nic_size
= sizeof(struct qlcnic_info
);
751 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
754 nic_info_addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, nic_size
,
755 &nic_dma_t
, GFP_KERNEL
);
759 memset(nic_info_addr
, 0, nic_size
);
760 nic_info
= nic_info_addr
;
762 nic_info
->pci_func
= cpu_to_le16(nic
->pci_func
);
763 nic_info
->op_mode
= cpu_to_le16(nic
->op_mode
);
764 nic_info
->phys_port
= cpu_to_le16(nic
->phys_port
);
765 nic_info
->switch_mode
= cpu_to_le16(nic
->switch_mode
);
766 nic_info
->capabilities
= cpu_to_le32(nic
->capabilities
);
767 nic_info
->max_mac_filters
= nic
->max_mac_filters
;
768 nic_info
->max_tx_ques
= cpu_to_le16(nic
->max_tx_ques
);
769 nic_info
->max_rx_ques
= cpu_to_le16(nic
->max_rx_ques
);
770 nic_info
->min_tx_bw
= cpu_to_le16(nic
->min_tx_bw
);
771 nic_info
->max_tx_bw
= cpu_to_le16(nic
->max_tx_bw
);
773 memset(rd_args
, 0, sizeof(rd_args
));
774 err
= qlcnic_issue_cmd(adapter
,
775 adapter
->ahw
->pci_func
,
776 adapter
->fw_hal_version
,
779 ((nic
->pci_func
<< 16) | nic_size
),
780 QLCNIC_CDRP_CMD_SET_NIC_INFO
,
783 if (err
!= QLCNIC_RCODE_SUCCESS
) {
784 dev_err(&adapter
->pdev
->dev
,
785 "Failed to set nic info%d\n", err
);
789 dma_free_coherent(&adapter
->pdev
->dev
, nic_size
, nic_info_addr
,
794 /* Get PCI Info of a partition */
795 int qlcnic_get_pci_info(struct qlcnic_adapter
*adapter
,
796 struct qlcnic_pci_info
*pci_info
)
800 dma_addr_t pci_info_dma_t
;
801 struct qlcnic_pci_info
*npar
;
803 size_t npar_size
= sizeof(struct qlcnic_pci_info
);
804 size_t pci_size
= npar_size
* QLCNIC_MAX_PCI_FUNC
;
806 pci_info_addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, pci_size
,
807 &pci_info_dma_t
, GFP_KERNEL
);
810 memset(pci_info_addr
, 0, pci_size
);
812 npar
= pci_info_addr
;
813 memset(rd_args
, 0, sizeof(rd_args
));
814 err
= qlcnic_issue_cmd(adapter
,
815 adapter
->ahw
->pci_func
,
816 adapter
->fw_hal_version
,
820 QLCNIC_CDRP_CMD_GET_PCI_INFO
,
823 if (err
== QLCNIC_RCODE_SUCCESS
) {
824 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++, npar
++, pci_info
++) {
825 pci_info
->id
= le16_to_cpu(npar
->id
);
826 pci_info
->active
= le16_to_cpu(npar
->active
);
827 pci_info
->type
= le16_to_cpu(npar
->type
);
828 pci_info
->default_port
=
829 le16_to_cpu(npar
->default_port
);
830 pci_info
->tx_min_bw
=
831 le16_to_cpu(npar
->tx_min_bw
);
832 pci_info
->tx_max_bw
=
833 le16_to_cpu(npar
->tx_max_bw
);
834 memcpy(pci_info
->mac
, npar
->mac
, ETH_ALEN
);
837 dev_err(&adapter
->pdev
->dev
,
838 "Failed to get PCI Info%d\n", err
);
842 dma_free_coherent(&adapter
->pdev
->dev
, pci_size
, pci_info_addr
,
847 /* Configure eSwitch for port mirroring */
848 int qlcnic_config_port_mirroring(struct qlcnic_adapter
*adapter
, u8 id
,
849 u8 enable_mirroring
, u8 pci_func
)
855 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
||
856 !(adapter
->eswitch
[id
].flags
& QLCNIC_SWITCH_ENABLE
))
859 arg1
= id
| (enable_mirroring
? BIT_4
: 0);
860 arg1
|= pci_func
<< 8;
862 memset(rd_args
, 0, sizeof(rd_args
));
863 err
= qlcnic_issue_cmd(adapter
,
864 adapter
->ahw
->pci_func
,
865 adapter
->fw_hal_version
,
869 QLCNIC_CDRP_CMD_SET_PORTMIRRORING
,
872 if (err
!= QLCNIC_RCODE_SUCCESS
) {
873 dev_err(&adapter
->pdev
->dev
,
874 "Failed to configure port mirroring%d on eswitch:%d\n",
877 dev_info(&adapter
->pdev
->dev
,
878 "Configured eSwitch %d for port mirroring:%d\n",
885 int qlcnic_get_port_stats(struct qlcnic_adapter
*adapter
, const u8 func
,
886 const u8 rx_tx
, struct __qlcnic_esw_statistics
*esw_stats
) {
888 size_t stats_size
= sizeof(struct __qlcnic_esw_statistics
);
889 struct __qlcnic_esw_statistics
*stats
;
890 dma_addr_t stats_dma_t
;
896 if (esw_stats
== NULL
)
899 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
&&
900 func
!= adapter
->ahw
->pci_func
) {
901 dev_err(&adapter
->pdev
->dev
,
902 "Not privilege to query stats for func=%d", func
);
906 stats_addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, stats_size
,
907 &stats_dma_t
, GFP_KERNEL
);
909 dev_err(&adapter
->pdev
->dev
, "Unable to allocate memory\n");
912 memset(stats_addr
, 0, stats_size
);
914 arg1
= func
| QLCNIC_STATS_VERSION
<< 8 | QLCNIC_STATS_PORT
<< 12;
915 arg1
|= rx_tx
<< 15 | stats_size
<< 16;
917 memset(rd_args
, 0, sizeof(rd_args
));
918 err
= qlcnic_issue_cmd(adapter
,
919 adapter
->ahw
->pci_func
,
920 adapter
->fw_hal_version
,
924 QLCNIC_CDRP_CMD_GET_ESWITCH_STATS
,
929 esw_stats
->context_id
= le16_to_cpu(stats
->context_id
);
930 esw_stats
->version
= le16_to_cpu(stats
->version
);
931 esw_stats
->size
= le16_to_cpu(stats
->size
);
932 esw_stats
->multicast_frames
=
933 le64_to_cpu(stats
->multicast_frames
);
934 esw_stats
->broadcast_frames
=
935 le64_to_cpu(stats
->broadcast_frames
);
936 esw_stats
->unicast_frames
= le64_to_cpu(stats
->unicast_frames
);
937 esw_stats
->dropped_frames
= le64_to_cpu(stats
->dropped_frames
);
938 esw_stats
->local_frames
= le64_to_cpu(stats
->local_frames
);
939 esw_stats
->errors
= le64_to_cpu(stats
->errors
);
940 esw_stats
->numbytes
= le64_to_cpu(stats
->numbytes
);
943 dma_free_coherent(&adapter
->pdev
->dev
, stats_size
, stats_addr
,
948 int qlcnic_get_eswitch_stats(struct qlcnic_adapter
*adapter
, const u8 eswitch
,
949 const u8 rx_tx
, struct __qlcnic_esw_statistics
*esw_stats
) {
951 struct __qlcnic_esw_statistics port_stats
;
955 if (esw_stats
== NULL
)
957 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
959 if (adapter
->npars
== NULL
)
962 memset(esw_stats
, 0, sizeof(u64
));
963 esw_stats
->unicast_frames
= QLCNIC_ESW_STATS_NOT_AVAIL
;
964 esw_stats
->multicast_frames
= QLCNIC_ESW_STATS_NOT_AVAIL
;
965 esw_stats
->broadcast_frames
= QLCNIC_ESW_STATS_NOT_AVAIL
;
966 esw_stats
->dropped_frames
= QLCNIC_ESW_STATS_NOT_AVAIL
;
967 esw_stats
->errors
= QLCNIC_ESW_STATS_NOT_AVAIL
;
968 esw_stats
->local_frames
= QLCNIC_ESW_STATS_NOT_AVAIL
;
969 esw_stats
->numbytes
= QLCNIC_ESW_STATS_NOT_AVAIL
;
970 esw_stats
->context_id
= eswitch
;
972 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
973 if (adapter
->npars
[i
].phy_port
!= eswitch
)
976 memset(&port_stats
, 0, sizeof(struct __qlcnic_esw_statistics
));
977 if (qlcnic_get_port_stats(adapter
, i
, rx_tx
, &port_stats
))
980 esw_stats
->size
= port_stats
.size
;
981 esw_stats
->version
= port_stats
.version
;
982 QLCNIC_ADD_ESW_STATS(esw_stats
->unicast_frames
,
983 port_stats
.unicast_frames
);
984 QLCNIC_ADD_ESW_STATS(esw_stats
->multicast_frames
,
985 port_stats
.multicast_frames
);
986 QLCNIC_ADD_ESW_STATS(esw_stats
->broadcast_frames
,
987 port_stats
.broadcast_frames
);
988 QLCNIC_ADD_ESW_STATS(esw_stats
->dropped_frames
,
989 port_stats
.dropped_frames
);
990 QLCNIC_ADD_ESW_STATS(esw_stats
->errors
,
992 QLCNIC_ADD_ESW_STATS(esw_stats
->local_frames
,
993 port_stats
.local_frames
);
994 QLCNIC_ADD_ESW_STATS(esw_stats
->numbytes
,
995 port_stats
.numbytes
);
1001 int qlcnic_clear_esw_stats(struct qlcnic_adapter
*adapter
, const u8 func_esw
,
1002 const u8 port
, const u8 rx_tx
)
1008 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
1011 if (func_esw
== QLCNIC_STATS_PORT
) {
1012 if (port
>= QLCNIC_MAX_PCI_FUNC
)
1014 } else if (func_esw
== QLCNIC_STATS_ESWITCH
) {
1015 if (port
>= QLCNIC_NIU_MAX_XG_PORTS
)
1021 if (rx_tx
> QLCNIC_QUERY_TX_COUNTER
)
1024 arg1
= port
| QLCNIC_STATS_VERSION
<< 8 | func_esw
<< 12;
1025 arg1
|= BIT_14
| rx_tx
<< 15;
1027 memset(rd_args
, 0, sizeof(rd_args
));
1028 return qlcnic_issue_cmd(adapter
,
1029 adapter
->ahw
->pci_func
,
1030 adapter
->fw_hal_version
,
1034 QLCNIC_CDRP_CMD_GET_ESWITCH_STATS
,
1038 dev_err(&adapter
->pdev
->dev
, "Invalid argument func_esw=%d port=%d"
1039 "rx_ctx=%d\n", func_esw
, port
, rx_tx
);
1044 __qlcnic_get_eswitch_port_config(struct qlcnic_adapter
*adapter
,
1045 u32
*arg1
, u32
*arg2
)
1050 pci_func
= (*arg1
>> 8);
1054 err
= qlcnic_issue_cmd(adapter
,
1055 adapter
->ahw
->pci_func
,
1056 adapter
->fw_hal_version
,
1060 QLCNIC_CDRP_CMD_GET_ESWITCH_PORT_CONFIG
,
1063 if (err
== QLCNIC_RCODE_SUCCESS
) {
1064 dev_info(&adapter
->pdev
->dev
,
1065 "eSwitch port config for pci func %d\n", pci_func
);
1067 dev_err(&adapter
->pdev
->dev
,
1068 "Failed to get eswitch port config for pci func %d\n",
1073 /* Configure eSwitch port
1074 op_mode = 0 for setting default port behavior
1075 op_mode = 1 for setting vlan id
1076 op_mode = 2 for deleting vlan id
1077 op_type = 0 for vlan_id
1078 op_type = 1 for port vlan_id
1080 int qlcnic_config_switch_port(struct qlcnic_adapter
*adapter
,
1081 struct qlcnic_esw_func_cfg
*esw_cfg
)
1088 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
1090 pci_func
= esw_cfg
->pci_func
;
1091 arg1
= (adapter
->npars
[pci_func
].phy_port
& BIT_0
);
1092 arg1
|= (pci_func
<< 8);
1094 if (__qlcnic_get_eswitch_port_config(adapter
, &arg1
, &arg2
))
1096 arg1
&= ~(0x0ff << 8);
1097 arg1
|= (pci_func
<< 8);
1098 arg1
&= ~(BIT_2
| BIT_3
);
1099 switch (esw_cfg
->op_mode
) {
1100 case QLCNIC_PORT_DEFAULTS
:
1101 arg1
|= (BIT_4
| BIT_6
| BIT_7
);
1102 arg2
|= (BIT_0
| BIT_1
);
1103 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
)
1104 arg2
|= (BIT_2
| BIT_3
);
1105 if (!(esw_cfg
->discard_tagged
))
1107 if (!(esw_cfg
->promisc_mode
))
1109 if (!(esw_cfg
->mac_override
))
1111 if (!(esw_cfg
->mac_anti_spoof
))
1113 if (!(esw_cfg
->offload_flags
& BIT_0
))
1114 arg2
&= ~(BIT_1
| BIT_2
| BIT_3
);
1115 if (!(esw_cfg
->offload_flags
& BIT_1
))
1117 if (!(esw_cfg
->offload_flags
& BIT_2
))
1120 case QLCNIC_ADD_VLAN
:
1121 arg1
|= (BIT_2
| BIT_5
);
1122 arg1
|= (esw_cfg
->vlan_id
<< 16);
1124 case QLCNIC_DEL_VLAN
:
1125 arg1
|= (BIT_3
| BIT_5
);
1126 arg1
&= ~(0x0ffff << 16);
1132 memset(rd_args
, 0, sizeof(rd_args
));
1133 err
= qlcnic_issue_cmd(adapter
,
1134 adapter
->ahw
->pci_func
,
1135 adapter
->fw_hal_version
,
1139 QLCNIC_CDRP_CMD_CONFIGURE_ESWITCH
,
1142 if (err
!= QLCNIC_RCODE_SUCCESS
) {
1143 dev_err(&adapter
->pdev
->dev
,
1144 "Failed to configure eswitch pci func %d\n", pci_func
);
1146 dev_info(&adapter
->pdev
->dev
,
1147 "Configured eSwitch for pci func %d\n", pci_func
);
1154 qlcnic_get_eswitch_port_config(struct qlcnic_adapter
*adapter
,
1155 struct qlcnic_esw_func_cfg
*esw_cfg
)
1159 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
1160 phy_port
= adapter
->npars
[esw_cfg
->pci_func
].phy_port
;
1162 phy_port
= adapter
->physical_port
;
1164 arg1
|= (esw_cfg
->pci_func
<< 8);
1165 if (__qlcnic_get_eswitch_port_config(adapter
, &arg1
, &arg2
))
1168 esw_cfg
->discard_tagged
= !!(arg1
& BIT_4
);
1169 esw_cfg
->host_vlan_tag
= !!(arg1
& BIT_5
);
1170 esw_cfg
->promisc_mode
= !!(arg1
& BIT_6
);
1171 esw_cfg
->mac_override
= !!(arg1
& BIT_7
);
1172 esw_cfg
->vlan_id
= LSW(arg1
>> 16);
1173 esw_cfg
->mac_anti_spoof
= (arg2
& 0x1);
1174 esw_cfg
->offload_flags
= ((arg2
>> 1) & 0x7);