2 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2013 QLogic Corporation
5 * See LICENSE.qlcnic for copyright and licensing details.
10 static const struct qlcnic_mailbox_metadata qlcnic_mbx_tbl
[] = {
11 {QLCNIC_CMD_CREATE_RX_CTX
, 4, 1},
12 {QLCNIC_CMD_DESTROY_RX_CTX
, 2, 1},
13 {QLCNIC_CMD_CREATE_TX_CTX
, 4, 1},
14 {QLCNIC_CMD_DESTROY_TX_CTX
, 3, 1},
15 {QLCNIC_CMD_INTRPT_TEST
, 4, 1},
16 {QLCNIC_CMD_SET_MTU
, 4, 1},
17 {QLCNIC_CMD_READ_PHY
, 4, 2},
18 {QLCNIC_CMD_WRITE_PHY
, 5, 1},
19 {QLCNIC_CMD_READ_HW_REG
, 4, 1},
20 {QLCNIC_CMD_GET_FLOW_CTL
, 4, 2},
21 {QLCNIC_CMD_SET_FLOW_CTL
, 4, 1},
22 {QLCNIC_CMD_READ_MAX_MTU
, 4, 2},
23 {QLCNIC_CMD_READ_MAX_LRO
, 4, 2},
24 {QLCNIC_CMD_MAC_ADDRESS
, 4, 3},
25 {QLCNIC_CMD_GET_PCI_INFO
, 4, 1},
26 {QLCNIC_CMD_GET_NIC_INFO
, 4, 1},
27 {QLCNIC_CMD_SET_NIC_INFO
, 4, 1},
28 {QLCNIC_CMD_GET_ESWITCH_CAPABILITY
, 4, 3},
29 {QLCNIC_CMD_TOGGLE_ESWITCH
, 4, 1},
30 {QLCNIC_CMD_GET_ESWITCH_STATUS
, 4, 3},
31 {QLCNIC_CMD_SET_PORTMIRRORING
, 4, 1},
32 {QLCNIC_CMD_CONFIGURE_ESWITCH
, 4, 1},
33 {QLCNIC_CMD_GET_MAC_STATS
, 4, 1},
34 {QLCNIC_CMD_GET_ESWITCH_PORT_CONFIG
, 4, 3},
35 {QLCNIC_CMD_GET_ESWITCH_STATS
, 4, 1},
36 {QLCNIC_CMD_CONFIG_PORT
, 4, 1},
37 {QLCNIC_CMD_TEMP_SIZE
, 4, 4},
38 {QLCNIC_CMD_GET_TEMP_HDR
, 4, 1},
39 {QLCNIC_CMD_82XX_SET_DRV_VER
, 4, 1},
40 {QLCNIC_CMD_GET_LED_STATUS
, 4, 2},
41 {QLCNIC_CMD_MQ_TX_CONFIG_INTR
, 2, 3},
42 {QLCNIC_CMD_DCB_QUERY_CAP
, 1, 2},
43 {QLCNIC_CMD_DCB_QUERY_PARAM
, 4, 1},
46 static inline u32
qlcnic_get_cmd_signature(struct qlcnic_hardware_context
*ahw
)
48 return (ahw
->pci_func
& 0xff) | ((ahw
->fw_hal_version
& 0xff) << 8) |
52 /* Allocate mailbox registers */
53 int qlcnic_82xx_alloc_mbx_args(struct qlcnic_cmd_args
*mbx
,
54 struct qlcnic_adapter
*adapter
, u32 type
)
57 const struct qlcnic_mailbox_metadata
*mbx_tbl
;
59 mbx_tbl
= qlcnic_mbx_tbl
;
60 size
= ARRAY_SIZE(qlcnic_mbx_tbl
);
61 for (i
= 0; i
< size
; i
++) {
62 if (type
== mbx_tbl
[i
].cmd
) {
63 mbx
->req
.num
= mbx_tbl
[i
].in_args
;
64 mbx
->rsp
.num
= mbx_tbl
[i
].out_args
;
65 mbx
->req
.arg
= kcalloc(mbx
->req
.num
,
66 sizeof(u32
), GFP_ATOMIC
);
69 mbx
->rsp
.arg
= kcalloc(mbx
->rsp
.num
,
70 sizeof(u32
), GFP_ATOMIC
);
76 mbx
->req
.arg
[0] = type
;
83 /* Free up mailbox registers */
84 void qlcnic_free_mbx_args(struct qlcnic_cmd_args
*cmd
)
93 qlcnic_poll_rsp(struct qlcnic_adapter
*adapter
)
96 int timeout
= 0, err
= 0;
99 /* give atleast 1ms for firmware to respond */
102 if (++timeout
> QLCNIC_OS_CRB_RETRY_COUNT
)
103 return QLCNIC_CDRP_RSP_TIMEOUT
;
105 rsp
= QLCRD32(adapter
, QLCNIC_CDRP_CRB_OFFSET
, &err
);
106 } while (!QLCNIC_CDRP_IS_RSP(rsp
));
111 int qlcnic_82xx_issue_cmd(struct qlcnic_adapter
*adapter
,
112 struct qlcnic_cmd_args
*cmd
)
117 struct pci_dev
*pdev
= adapter
->pdev
;
118 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
121 signature
= qlcnic_get_cmd_signature(ahw
);
123 /* Acquire semaphore before accessing CRB */
124 if (qlcnic_api_lock(adapter
)) {
125 cmd
->rsp
.arg
[0] = QLCNIC_RCODE_TIMEOUT
;
126 return cmd
->rsp
.arg
[0];
129 QLCWR32(adapter
, QLCNIC_SIGN_CRB_OFFSET
, signature
);
130 for (i
= 1; i
< cmd
->req
.num
; i
++)
131 QLCWR32(adapter
, QLCNIC_CDRP_ARG(i
), cmd
->req
.arg
[i
]);
132 QLCWR32(adapter
, QLCNIC_CDRP_CRB_OFFSET
,
133 QLCNIC_CDRP_FORM_CMD(cmd
->req
.arg
[0]));
134 rsp
= qlcnic_poll_rsp(adapter
);
136 if (rsp
== QLCNIC_CDRP_RSP_TIMEOUT
) {
137 dev_err(&pdev
->dev
, "command timeout, response = 0x%x\n", rsp
);
138 cmd
->rsp
.arg
[0] = QLCNIC_RCODE_TIMEOUT
;
139 } else if (rsp
== QLCNIC_CDRP_RSP_FAIL
) {
140 cmd
->rsp
.arg
[0] = QLCRD32(adapter
, QLCNIC_CDRP_ARG(1), &err
);
141 switch (cmd
->rsp
.arg
[0]) {
142 case QLCNIC_RCODE_INVALID_ARGS
:
143 fmt
= "CDRP invalid args: [%d]\n";
145 case QLCNIC_RCODE_NOT_SUPPORTED
:
146 case QLCNIC_RCODE_NOT_IMPL
:
147 fmt
= "CDRP command not supported: [%d]\n";
149 case QLCNIC_RCODE_NOT_PERMITTED
:
150 fmt
= "CDRP requested action not permitted: [%d]\n";
152 case QLCNIC_RCODE_INVALID
:
153 fmt
= "CDRP invalid or unknown cmd received: [%d]\n";
155 case QLCNIC_RCODE_TIMEOUT
:
156 fmt
= "CDRP command timeout: [%d]\n";
159 fmt
= "CDRP command failed: [%d]\n";
162 dev_err(&pdev
->dev
, fmt
, cmd
->rsp
.arg
[0]);
163 qlcnic_dump_mbx(adapter
, cmd
);
164 } else if (rsp
== QLCNIC_CDRP_RSP_OK
)
165 cmd
->rsp
.arg
[0] = QLCNIC_RCODE_SUCCESS
;
167 for (i
= 1; i
< cmd
->rsp
.num
; i
++)
168 cmd
->rsp
.arg
[i
] = QLCRD32(adapter
, QLCNIC_CDRP_ARG(i
), &err
);
170 /* Release semaphore */
171 qlcnic_api_unlock(adapter
);
172 return cmd
->rsp
.arg
[0];
175 int qlcnic_fw_cmd_set_drv_version(struct qlcnic_adapter
*adapter
, u32 fw_cmd
)
177 struct qlcnic_cmd_args cmd
;
178 u32 arg1
, arg2
, arg3
;
182 memset(drv_string
, 0, sizeof(drv_string
));
183 snprintf(drv_string
, sizeof(drv_string
), "%d"".""%d"".""%d",
184 _QLCNIC_LINUX_MAJOR
, _QLCNIC_LINUX_MINOR
,
185 _QLCNIC_LINUX_SUBVERSION
);
187 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, fw_cmd
);
191 memcpy(&arg1
, drv_string
, sizeof(u32
));
192 memcpy(&arg2
, drv_string
+ 4, sizeof(u32
));
193 memcpy(&arg3
, drv_string
+ 8, sizeof(u32
));
195 cmd
.req
.arg
[1] = arg1
;
196 cmd
.req
.arg
[2] = arg2
;
197 cmd
.req
.arg
[3] = arg3
;
199 err
= qlcnic_issue_cmd(adapter
, &cmd
);
201 dev_info(&adapter
->pdev
->dev
,
202 "Failed to set driver version in firmware\n");
205 qlcnic_free_mbx_args(&cmd
);
210 qlcnic_fw_cmd_set_mtu(struct qlcnic_adapter
*adapter
, int mtu
)
213 struct qlcnic_cmd_args cmd
;
214 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
216 if (recv_ctx
->state
!= QLCNIC_HOST_CTX_STATE_ACTIVE
)
218 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_SET_MTU
);
222 cmd
.req
.arg
[1] = recv_ctx
->context_id
;
223 cmd
.req
.arg
[2] = mtu
;
225 err
= qlcnic_issue_cmd(adapter
, &cmd
);
227 dev_err(&adapter
->pdev
->dev
, "Failed to set mtu\n");
230 qlcnic_free_mbx_args(&cmd
);
234 int qlcnic_82xx_fw_cmd_create_rx_ctx(struct qlcnic_adapter
*adapter
)
236 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
237 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
238 dma_addr_t hostrq_phys_addr
, cardrsp_phys_addr
;
239 struct net_device
*netdev
= adapter
->netdev
;
240 u32 temp_intr_crb_mode
, temp_rds_crb_mode
;
241 struct qlcnic_cardrsp_rds_ring
*prsp_rds
;
242 struct qlcnic_cardrsp_sds_ring
*prsp_sds
;
243 struct qlcnic_hostrq_rds_ring
*prq_rds
;
244 struct qlcnic_hostrq_sds_ring
*prq_sds
;
245 struct qlcnic_host_rds_ring
*rds_ring
;
246 struct qlcnic_host_sds_ring
*sds_ring
;
247 struct qlcnic_cardrsp_rx_ctx
*prsp
;
248 struct qlcnic_hostrq_rx_ctx
*prq
;
249 u8 i
, nrds_rings
, nsds_rings
;
250 struct qlcnic_cmd_args cmd
;
251 size_t rq_size
, rsp_size
;
252 u32 cap
, reg
, val
, reg2
;
258 nrds_rings
= adapter
->max_rds_rings
;
259 nsds_rings
= adapter
->drv_sds_rings
;
261 rq_size
= SIZEOF_HOSTRQ_RX(struct qlcnic_hostrq_rx_ctx
, nrds_rings
,
263 rsp_size
= SIZEOF_CARDRSP_RX(struct qlcnic_cardrsp_rx_ctx
, nrds_rings
,
266 addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, rq_size
,
267 &hostrq_phys_addr
, GFP_KERNEL
);
272 addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, rsp_size
,
273 &cardrsp_phys_addr
, GFP_KERNEL
);
280 prq
->host_rsp_dma_addr
= cpu_to_le64(cardrsp_phys_addr
);
282 cap
= (QLCNIC_CAP0_LEGACY_CONTEXT
| QLCNIC_CAP0_LEGACY_MN
283 | QLCNIC_CAP0_VALIDOFF
);
284 cap
|= (QLCNIC_CAP0_JUMBO_CONTIGUOUS
| QLCNIC_CAP0_LRO_CONTIGUOUS
);
286 if (qlcnic_check_multi_tx(adapter
) &&
287 !adapter
->ahw
->diag_test
) {
288 cap
|= QLCNIC_CAP0_TX_MULTI
;
290 temp_u16
= offsetof(struct qlcnic_hostrq_rx_ctx
, msix_handler
);
291 prq
->valid_field_offset
= cpu_to_le16(temp_u16
);
292 prq
->txrx_sds_binding
= nsds_rings
- 1;
293 temp_intr_crb_mode
= QLCNIC_HOST_INT_CRB_MODE_SHARED
;
294 prq
->host_int_crb_mode
= cpu_to_le32(temp_intr_crb_mode
);
295 temp_rds_crb_mode
= QLCNIC_HOST_RDS_CRB_MODE_UNIQUE
;
296 prq
->host_rds_crb_mode
= cpu_to_le32(temp_rds_crb_mode
);
299 prq
->capabilities
[0] = cpu_to_le32(cap
);
301 prq
->num_rds_rings
= cpu_to_le16(nrds_rings
);
302 prq
->num_sds_rings
= cpu_to_le16(nsds_rings
);
303 prq
->rds_ring_offset
= 0;
305 val
= le32_to_cpu(prq
->rds_ring_offset
) +
306 (sizeof(struct qlcnic_hostrq_rds_ring
) * nrds_rings
);
307 prq
->sds_ring_offset
= cpu_to_le32(val
);
309 prq_rds
= (struct qlcnic_hostrq_rds_ring
*)(prq
->data
+
310 le32_to_cpu(prq
->rds_ring_offset
));
312 for (i
= 0; i
< nrds_rings
; i
++) {
313 rds_ring
= &recv_ctx
->rds_rings
[i
];
314 rds_ring
->producer
= 0;
315 prq_rds
[i
].host_phys_addr
= cpu_to_le64(rds_ring
->phys_addr
);
316 prq_rds
[i
].ring_size
= cpu_to_le32(rds_ring
->num_desc
);
317 prq_rds
[i
].ring_kind
= cpu_to_le32(i
);
318 prq_rds
[i
].buff_size
= cpu_to_le64(rds_ring
->dma_size
);
321 prq_sds
= (struct qlcnic_hostrq_sds_ring
*)(prq
->data
+
322 le32_to_cpu(prq
->sds_ring_offset
));
324 for (i
= 0; i
< nsds_rings
; i
++) {
325 sds_ring
= &recv_ctx
->sds_rings
[i
];
326 sds_ring
->consumer
= 0;
327 memset(sds_ring
->desc_head
, 0, STATUS_DESC_RINGSIZE(sds_ring
));
328 prq_sds
[i
].host_phys_addr
= cpu_to_le64(sds_ring
->phys_addr
);
329 prq_sds
[i
].ring_size
= cpu_to_le32(sds_ring
->num_desc
);
330 if (qlcnic_check_multi_tx(adapter
) &&
331 !adapter
->ahw
->diag_test
)
332 prq_sds
[i
].msi_index
= cpu_to_le16(ahw
->intr_tbl
[i
].id
);
334 prq_sds
[i
].msi_index
= cpu_to_le16(i
);
337 phys_addr
= hostrq_phys_addr
;
338 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_CREATE_RX_CTX
);
342 cmd
.req
.arg
[1] = MSD(phys_addr
);
343 cmd
.req
.arg
[2] = LSD(phys_addr
);
344 cmd
.req
.arg
[3] = rq_size
;
345 err
= qlcnic_issue_cmd(adapter
, &cmd
);
347 dev_err(&adapter
->pdev
->dev
,
348 "Failed to create rx ctx in firmware%d\n", err
);
352 prsp_rds
= ((struct qlcnic_cardrsp_rds_ring
*)
353 &prsp
->data
[le32_to_cpu(prsp
->rds_ring_offset
)]);
355 for (i
= 0; i
< le16_to_cpu(prsp
->num_rds_rings
); i
++) {
356 rds_ring
= &recv_ctx
->rds_rings
[i
];
357 reg
= le32_to_cpu(prsp_rds
[i
].host_producer_crb
);
358 rds_ring
->crb_rcv_producer
= ahw
->pci_base0
+ reg
;
361 prsp_sds
= ((struct qlcnic_cardrsp_sds_ring
*)
362 &prsp
->data
[le32_to_cpu(prsp
->sds_ring_offset
)]);
364 for (i
= 0; i
< le16_to_cpu(prsp
->num_sds_rings
); i
++) {
365 sds_ring
= &recv_ctx
->sds_rings
[i
];
366 reg
= le32_to_cpu(prsp_sds
[i
].host_consumer_crb
);
367 if (qlcnic_check_multi_tx(adapter
) && !adapter
->ahw
->diag_test
)
368 reg2
= ahw
->intr_tbl
[i
].src
;
370 reg2
= le32_to_cpu(prsp_sds
[i
].interrupt_crb
);
372 sds_ring
->crb_intr_mask
= ahw
->pci_base0
+ reg2
;
373 sds_ring
->crb_sts_consumer
= ahw
->pci_base0
+ reg
;
376 recv_ctx
->state
= le32_to_cpu(prsp
->host_ctx_state
);
377 recv_ctx
->context_id
= le16_to_cpu(prsp
->context_id
);
378 recv_ctx
->virt_port
= prsp
->virt_port
;
380 netdev_info(netdev
, "Rx Context[%d] Created, state 0x%x\n",
381 recv_ctx
->context_id
, recv_ctx
->state
);
382 qlcnic_free_mbx_args(&cmd
);
385 dma_free_coherent(&adapter
->pdev
->dev
, rsp_size
, prsp
,
388 dma_free_coherent(&adapter
->pdev
->dev
, rq_size
, prq
, hostrq_phys_addr
);
393 void qlcnic_82xx_fw_cmd_del_rx_ctx(struct qlcnic_adapter
*adapter
)
396 struct qlcnic_cmd_args cmd
;
397 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
399 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_DESTROY_RX_CTX
);
403 cmd
.req
.arg
[1] = recv_ctx
->context_id
;
404 err
= qlcnic_issue_cmd(adapter
, &cmd
);
406 dev_err(&adapter
->pdev
->dev
,
407 "Failed to destroy rx ctx in firmware\n");
409 recv_ctx
->state
= QLCNIC_HOST_CTX_STATE_FREED
;
410 qlcnic_free_mbx_args(&cmd
);
413 int qlcnic_82xx_fw_cmd_create_tx_ctx(struct qlcnic_adapter
*adapter
,
414 struct qlcnic_host_tx_ring
*tx_ring
,
417 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
418 struct net_device
*netdev
= adapter
->netdev
;
419 struct qlcnic_hostrq_tx_ctx
*prq
;
420 struct qlcnic_hostrq_cds_ring
*prq_cds
;
421 struct qlcnic_cardrsp_tx_ctx
*prsp
;
422 struct qlcnic_cmd_args cmd
;
423 u32 temp
, intr_mask
, temp_int_crb_mode
;
424 dma_addr_t rq_phys_addr
, rsp_phys_addr
;
425 int temp_nsds_rings
, index
, err
;
426 void *rq_addr
, *rsp_addr
;
427 size_t rq_size
, rsp_size
;
431 /* reset host resources */
432 tx_ring
->producer
= 0;
433 tx_ring
->sw_consumer
= 0;
434 *(tx_ring
->hw_consumer
) = 0;
436 rq_size
= SIZEOF_HOSTRQ_TX(struct qlcnic_hostrq_tx_ctx
);
437 rq_addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, rq_size
,
438 &rq_phys_addr
, GFP_KERNEL
);
442 rsp_size
= SIZEOF_CARDRSP_TX(struct qlcnic_cardrsp_tx_ctx
);
443 rsp_addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, rsp_size
,
444 &rsp_phys_addr
, GFP_KERNEL
);
453 prq
->host_rsp_dma_addr
= cpu_to_le64(rsp_phys_addr
);
455 temp
= (QLCNIC_CAP0_LEGACY_CONTEXT
| QLCNIC_CAP0_LEGACY_MN
|
457 if (qlcnic_check_multi_tx(adapter
) && !adapter
->ahw
->diag_test
)
458 temp
|= QLCNIC_CAP0_TX_MULTI
;
460 prq
->capabilities
[0] = cpu_to_le32(temp
);
462 if (qlcnic_check_multi_tx(adapter
) &&
463 !adapter
->ahw
->diag_test
) {
464 temp_nsds_rings
= adapter
->drv_sds_rings
;
465 index
= temp_nsds_rings
+ ring
;
466 msix_id
= ahw
->intr_tbl
[index
].id
;
467 prq
->msi_index
= cpu_to_le16(msix_id
);
469 temp_int_crb_mode
= QLCNIC_HOST_INT_CRB_MODE_SHARED
;
470 prq
->host_int_crb_mode
= cpu_to_le32(temp_int_crb_mode
);
474 prq
->interrupt_ctl
= 0;
475 prq
->cmd_cons_dma_addr
= cpu_to_le64(tx_ring
->hw_cons_phys_addr
);
477 prq_cds
= &prq
->cds_ring
;
479 prq_cds
->host_phys_addr
= cpu_to_le64(tx_ring
->phys_addr
);
480 prq_cds
->ring_size
= cpu_to_le32(tx_ring
->num_desc
);
482 phys_addr
= rq_phys_addr
;
484 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_CREATE_TX_CTX
);
488 cmd
.req
.arg
[1] = MSD(phys_addr
);
489 cmd
.req
.arg
[2] = LSD(phys_addr
);
490 cmd
.req
.arg
[3] = rq_size
;
491 err
= qlcnic_issue_cmd(adapter
, &cmd
);
493 if (err
== QLCNIC_RCODE_SUCCESS
) {
494 tx_ring
->state
= le32_to_cpu(prsp
->host_ctx_state
);
495 temp
= le32_to_cpu(prsp
->cds_ring
.host_producer_crb
);
496 tx_ring
->crb_cmd_producer
= adapter
->ahw
->pci_base0
+ temp
;
497 tx_ring
->ctx_id
= le16_to_cpu(prsp
->context_id
);
498 if (qlcnic_check_multi_tx(adapter
) &&
499 !adapter
->ahw
->diag_test
&&
500 (adapter
->flags
& QLCNIC_MSIX_ENABLED
)) {
501 index
= adapter
->drv_sds_rings
+ ring
;
502 intr_mask
= ahw
->intr_tbl
[index
].src
;
503 tx_ring
->crb_intr_mask
= ahw
->pci_base0
+ intr_mask
;
506 netdev_info(netdev
, "Tx Context[0x%x] Created, state 0x%x\n",
507 tx_ring
->ctx_id
, tx_ring
->state
);
509 netdev_err(netdev
, "Failed to create tx ctx in firmware%d\n",
513 qlcnic_free_mbx_args(&cmd
);
516 dma_free_coherent(&adapter
->pdev
->dev
, rsp_size
, rsp_addr
,
519 dma_free_coherent(&adapter
->pdev
->dev
, rq_size
, rq_addr
, rq_phys_addr
);
524 void qlcnic_82xx_fw_cmd_del_tx_ctx(struct qlcnic_adapter
*adapter
,
525 struct qlcnic_host_tx_ring
*tx_ring
)
527 struct qlcnic_cmd_args cmd
;
530 ret
= qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_DESTROY_TX_CTX
);
534 cmd
.req
.arg
[1] = tx_ring
->ctx_id
;
535 if (qlcnic_issue_cmd(adapter
, &cmd
))
536 dev_err(&adapter
->pdev
->dev
,
537 "Failed to destroy tx ctx in firmware\n");
538 qlcnic_free_mbx_args(&cmd
);
542 qlcnic_fw_cmd_set_port(struct qlcnic_adapter
*adapter
, u32 config
)
545 struct qlcnic_cmd_args cmd
;
547 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_CONFIG_PORT
);
551 cmd
.req
.arg
[1] = config
;
552 err
= qlcnic_issue_cmd(adapter
, &cmd
);
553 qlcnic_free_mbx_args(&cmd
);
557 int qlcnic_alloc_hw_resources(struct qlcnic_adapter
*adapter
)
561 struct qlcnic_recv_context
*recv_ctx
;
562 struct qlcnic_host_rds_ring
*rds_ring
;
563 struct qlcnic_host_sds_ring
*sds_ring
;
564 struct qlcnic_host_tx_ring
*tx_ring
;
567 struct pci_dev
*pdev
= adapter
->pdev
;
569 recv_ctx
= adapter
->recv_ctx
;
571 for (ring
= 0; ring
< adapter
->drv_tx_rings
; ring
++) {
572 tx_ring
= &adapter
->tx_ring
[ring
];
573 ptr
= (__le32
*)dma_alloc_coherent(&pdev
->dev
, sizeof(u32
),
574 &tx_ring
->hw_cons_phys_addr
,
581 tx_ring
->hw_consumer
= ptr
;
583 addr
= dma_alloc_coherent(&pdev
->dev
, TX_DESC_RINGSIZE(tx_ring
),
591 tx_ring
->desc_head
= addr
;
594 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
595 rds_ring
= &recv_ctx
->rds_rings
[ring
];
596 addr
= dma_alloc_coherent(&adapter
->pdev
->dev
,
597 RCV_DESC_RINGSIZE(rds_ring
),
598 &rds_ring
->phys_addr
, GFP_KERNEL
);
603 rds_ring
->desc_head
= addr
;
607 for (ring
= 0; ring
< adapter
->drv_sds_rings
; ring
++) {
608 sds_ring
= &recv_ctx
->sds_rings
[ring
];
610 addr
= dma_alloc_coherent(&adapter
->pdev
->dev
,
611 STATUS_DESC_RINGSIZE(sds_ring
),
612 &sds_ring
->phys_addr
, GFP_KERNEL
);
617 sds_ring
->desc_head
= addr
;
623 qlcnic_free_hw_resources(adapter
);
627 int qlcnic_fw_create_ctx(struct qlcnic_adapter
*dev
)
631 if (dev
->flags
& QLCNIC_NEED_FLR
) {
632 pci_reset_function(dev
->pdev
);
633 dev
->flags
&= ~QLCNIC_NEED_FLR
;
636 if (qlcnic_83xx_check(dev
) && (dev
->flags
& QLCNIC_MSIX_ENABLED
)) {
637 if (dev
->ahw
->diag_test
!= QLCNIC_LOOPBACK_TEST
) {
638 err
= qlcnic_83xx_config_intrpt(dev
, 1);
644 if (qlcnic_82xx_check(dev
) && (dev
->flags
& QLCNIC_MSIX_ENABLED
) &&
645 qlcnic_check_multi_tx(dev
) && !dev
->ahw
->diag_test
) {
646 err
= qlcnic_82xx_mq_intrpt(dev
, 1);
651 err
= qlcnic_fw_cmd_create_rx_ctx(dev
);
655 for (ring
= 0; ring
< dev
->drv_tx_rings
; ring
++) {
656 err
= qlcnic_fw_cmd_create_tx_ctx(dev
,
660 qlcnic_fw_cmd_del_rx_ctx(dev
);
664 for (i
= 0; i
< ring
; i
++)
665 qlcnic_fw_cmd_del_tx_ctx(dev
, &dev
->tx_ring
[i
]);
671 set_bit(__QLCNIC_FW_ATTACHED
, &dev
->state
);
676 if (qlcnic_82xx_check(dev
) && (dev
->flags
& QLCNIC_MSIX_ENABLED
) &&
677 qlcnic_check_multi_tx(dev
) && !dev
->ahw
->diag_test
)
678 qlcnic_82xx_config_intrpt(dev
, 0);
680 if (qlcnic_83xx_check(dev
) && (dev
->flags
& QLCNIC_MSIX_ENABLED
)) {
681 if (dev
->ahw
->diag_test
!= QLCNIC_LOOPBACK_TEST
)
682 qlcnic_83xx_config_intrpt(dev
, 0);
688 void qlcnic_fw_destroy_ctx(struct qlcnic_adapter
*adapter
)
692 if (test_and_clear_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
)) {
693 qlcnic_fw_cmd_del_rx_ctx(adapter
);
694 for (ring
= 0; ring
< adapter
->drv_tx_rings
; ring
++)
695 qlcnic_fw_cmd_del_tx_ctx(adapter
,
696 &adapter
->tx_ring
[ring
]);
698 if (qlcnic_82xx_check(adapter
) &&
699 (adapter
->flags
& QLCNIC_MSIX_ENABLED
) &&
700 qlcnic_check_multi_tx(adapter
) &&
701 !adapter
->ahw
->diag_test
)
702 qlcnic_82xx_config_intrpt(adapter
, 0);
704 if (qlcnic_83xx_check(adapter
) &&
705 (adapter
->flags
& QLCNIC_MSIX_ENABLED
)) {
706 if (adapter
->ahw
->diag_test
!= QLCNIC_LOOPBACK_TEST
)
707 qlcnic_83xx_config_intrpt(adapter
, 0);
709 /* Allow dma queues to drain after context reset */
714 void qlcnic_free_hw_resources(struct qlcnic_adapter
*adapter
)
716 struct qlcnic_recv_context
*recv_ctx
;
717 struct qlcnic_host_rds_ring
*rds_ring
;
718 struct qlcnic_host_sds_ring
*sds_ring
;
719 struct qlcnic_host_tx_ring
*tx_ring
;
722 recv_ctx
= adapter
->recv_ctx
;
724 for (ring
= 0; ring
< adapter
->drv_tx_rings
; ring
++) {
725 tx_ring
= &adapter
->tx_ring
[ring
];
726 if (tx_ring
->hw_consumer
!= NULL
) {
727 dma_free_coherent(&adapter
->pdev
->dev
, sizeof(u32
),
728 tx_ring
->hw_consumer
,
729 tx_ring
->hw_cons_phys_addr
);
731 tx_ring
->hw_consumer
= NULL
;
734 if (tx_ring
->desc_head
!= NULL
) {
735 dma_free_coherent(&adapter
->pdev
->dev
,
736 TX_DESC_RINGSIZE(tx_ring
),
739 tx_ring
->desc_head
= NULL
;
743 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
744 rds_ring
= &recv_ctx
->rds_rings
[ring
];
746 if (rds_ring
->desc_head
!= NULL
) {
747 dma_free_coherent(&adapter
->pdev
->dev
,
748 RCV_DESC_RINGSIZE(rds_ring
),
750 rds_ring
->phys_addr
);
751 rds_ring
->desc_head
= NULL
;
755 for (ring
= 0; ring
< adapter
->drv_sds_rings
; ring
++) {
756 sds_ring
= &recv_ctx
->sds_rings
[ring
];
758 if (sds_ring
->desc_head
!= NULL
) {
759 dma_free_coherent(&adapter
->pdev
->dev
,
760 STATUS_DESC_RINGSIZE(sds_ring
),
762 sds_ring
->phys_addr
);
763 sds_ring
->desc_head
= NULL
;
768 int qlcnic_82xx_config_intrpt(struct qlcnic_adapter
*adapter
, u8 op_type
)
770 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
771 struct net_device
*netdev
= adapter
->netdev
;
772 struct qlcnic_cmd_args cmd
;
776 for (i
= 0; i
< ahw
->num_msix
; i
++) {
777 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
,
778 QLCNIC_CMD_MQ_TX_CONFIG_INTR
);
781 type
= op_type
? QLCNIC_INTRPT_ADD
: QLCNIC_INTRPT_DEL
;
782 val
= type
| (ahw
->intr_tbl
[i
].type
<< 4);
783 if (ahw
->intr_tbl
[i
].type
== QLCNIC_INTRPT_MSIX
)
784 val
|= (ahw
->intr_tbl
[i
].id
<< 16);
785 cmd
.req
.arg
[1] = val
;
786 err
= qlcnic_issue_cmd(adapter
, &cmd
);
788 netdev_err(netdev
, "Failed to %s interrupts %d\n",
789 op_type
== QLCNIC_INTRPT_ADD
? "Add" :
791 qlcnic_free_mbx_args(&cmd
);
794 val
= cmd
.rsp
.arg
[1];
797 "failed to configure interrupt for %d\n",
798 ahw
->intr_tbl
[i
].id
);
802 ahw
->intr_tbl
[i
].id
= MSW(val
);
803 ahw
->intr_tbl
[i
].enabled
= 1;
804 ahw
->intr_tbl
[i
].src
= cmd
.rsp
.arg
[2];
806 ahw
->intr_tbl
[i
].id
= i
;
807 ahw
->intr_tbl
[i
].enabled
= 0;
808 ahw
->intr_tbl
[i
].src
= 0;
810 qlcnic_free_mbx_args(&cmd
);
816 int qlcnic_82xx_get_mac_address(struct qlcnic_adapter
*adapter
, u8
*mac
,
820 struct qlcnic_cmd_args cmd
;
821 u32 mac_low
, mac_high
;
823 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_MAC_ADDRESS
);
827 cmd
.req
.arg
[1] = function
| BIT_8
;
828 err
= qlcnic_issue_cmd(adapter
, &cmd
);
830 if (err
== QLCNIC_RCODE_SUCCESS
) {
831 mac_low
= cmd
.rsp
.arg
[1];
832 mac_high
= cmd
.rsp
.arg
[2];
834 for (i
= 0; i
< 2; i
++)
835 mac
[i
] = (u8
) (mac_high
>> ((1 - i
) * 8));
836 for (i
= 2; i
< 6; i
++)
837 mac
[i
] = (u8
) (mac_low
>> ((5 - i
) * 8));
839 dev_err(&adapter
->pdev
->dev
,
840 "Failed to get mac address%d\n", err
);
843 qlcnic_free_mbx_args(&cmd
);
847 /* Get info of a NIC partition */
848 int qlcnic_82xx_get_nic_info(struct qlcnic_adapter
*adapter
,
849 struct qlcnic_info
*npar_info
, u8 func_id
)
852 dma_addr_t nic_dma_t
;
853 const struct qlcnic_info_le
*nic_info
;
855 struct qlcnic_cmd_args cmd
;
856 size_t nic_size
= sizeof(struct qlcnic_info_le
);
858 nic_info_addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, nic_size
,
859 &nic_dma_t
, GFP_KERNEL
);
863 nic_info
= nic_info_addr
;
865 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_GET_NIC_INFO
);
869 cmd
.req
.arg
[1] = MSD(nic_dma_t
);
870 cmd
.req
.arg
[2] = LSD(nic_dma_t
);
871 cmd
.req
.arg
[3] = (func_id
<< 16 | nic_size
);
872 err
= qlcnic_issue_cmd(adapter
, &cmd
);
873 if (err
!= QLCNIC_RCODE_SUCCESS
) {
874 dev_err(&adapter
->pdev
->dev
,
875 "Failed to get nic info%d\n", err
);
878 npar_info
->pci_func
= le16_to_cpu(nic_info
->pci_func
);
879 npar_info
->op_mode
= le16_to_cpu(nic_info
->op_mode
);
880 npar_info
->min_tx_bw
= le16_to_cpu(nic_info
->min_tx_bw
);
881 npar_info
->max_tx_bw
= le16_to_cpu(nic_info
->max_tx_bw
);
882 npar_info
->phys_port
= le16_to_cpu(nic_info
->phys_port
);
883 npar_info
->switch_mode
= le16_to_cpu(nic_info
->switch_mode
);
884 npar_info
->max_tx_ques
= le16_to_cpu(nic_info
->max_tx_ques
);
885 npar_info
->max_rx_ques
= le16_to_cpu(nic_info
->max_rx_ques
);
886 npar_info
->capabilities
= le32_to_cpu(nic_info
->capabilities
);
887 npar_info
->max_mtu
= le16_to_cpu(nic_info
->max_mtu
);
890 qlcnic_free_mbx_args(&cmd
);
892 dma_free_coherent(&adapter
->pdev
->dev
, nic_size
, nic_info_addr
,
898 /* Configure a NIC partition */
899 int qlcnic_82xx_set_nic_info(struct qlcnic_adapter
*adapter
,
900 struct qlcnic_info
*nic
)
903 dma_addr_t nic_dma_t
;
905 struct qlcnic_cmd_args cmd
;
906 struct qlcnic_info_le
*nic_info
;
907 size_t nic_size
= sizeof(struct qlcnic_info_le
);
909 if (adapter
->ahw
->op_mode
!= QLCNIC_MGMT_FUNC
)
912 nic_info_addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, nic_size
,
913 &nic_dma_t
, GFP_KERNEL
);
917 nic_info
= nic_info_addr
;
919 nic_info
->pci_func
= cpu_to_le16(nic
->pci_func
);
920 nic_info
->op_mode
= cpu_to_le16(nic
->op_mode
);
921 nic_info
->phys_port
= cpu_to_le16(nic
->phys_port
);
922 nic_info
->switch_mode
= cpu_to_le16(nic
->switch_mode
);
923 nic_info
->capabilities
= cpu_to_le32(nic
->capabilities
);
924 nic_info
->max_mac_filters
= nic
->max_mac_filters
;
925 nic_info
->max_tx_ques
= cpu_to_le16(nic
->max_tx_ques
);
926 nic_info
->max_rx_ques
= cpu_to_le16(nic
->max_rx_ques
);
927 nic_info
->min_tx_bw
= cpu_to_le16(nic
->min_tx_bw
);
928 nic_info
->max_tx_bw
= cpu_to_le16(nic
->max_tx_bw
);
930 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_SET_NIC_INFO
);
934 cmd
.req
.arg
[1] = MSD(nic_dma_t
);
935 cmd
.req
.arg
[2] = LSD(nic_dma_t
);
936 cmd
.req
.arg
[3] = ((nic
->pci_func
<< 16) | nic_size
);
937 err
= qlcnic_issue_cmd(adapter
, &cmd
);
939 if (err
!= QLCNIC_RCODE_SUCCESS
) {
940 dev_err(&adapter
->pdev
->dev
,
941 "Failed to set nic info%d\n", err
);
945 qlcnic_free_mbx_args(&cmd
);
947 dma_free_coherent(&adapter
->pdev
->dev
, nic_size
, nic_info_addr
,
953 /* Get PCI Info of a partition */
954 int qlcnic_82xx_get_pci_info(struct qlcnic_adapter
*adapter
,
955 struct qlcnic_pci_info
*pci_info
)
957 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
958 size_t npar_size
= sizeof(struct qlcnic_pci_info_le
);
959 size_t pci_size
= npar_size
* ahw
->max_vnic_func
;
960 u16 nic
= 0, fcoe
= 0, iscsi
= 0;
961 struct qlcnic_pci_info_le
*npar
;
962 struct qlcnic_cmd_args cmd
;
963 dma_addr_t pci_info_dma_t
;
967 pci_info_addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, pci_size
,
968 &pci_info_dma_t
, GFP_KERNEL
);
972 npar
= pci_info_addr
;
973 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_GET_PCI_INFO
);
977 cmd
.req
.arg
[1] = MSD(pci_info_dma_t
);
978 cmd
.req
.arg
[2] = LSD(pci_info_dma_t
);
979 cmd
.req
.arg
[3] = pci_size
;
980 err
= qlcnic_issue_cmd(adapter
, &cmd
);
982 ahw
->total_nic_func
= 0;
983 if (err
== QLCNIC_RCODE_SUCCESS
) {
984 for (i
= 0; i
< ahw
->max_vnic_func
; i
++, npar
++, pci_info
++) {
985 pci_info
->id
= le16_to_cpu(npar
->id
);
986 pci_info
->active
= le16_to_cpu(npar
->active
);
987 if (!pci_info
->active
)
989 pci_info
->type
= le16_to_cpu(npar
->type
);
990 err
= qlcnic_get_pci_func_type(adapter
, pci_info
->type
,
991 &nic
, &fcoe
, &iscsi
);
992 pci_info
->default_port
=
993 le16_to_cpu(npar
->default_port
);
994 pci_info
->tx_min_bw
=
995 le16_to_cpu(npar
->tx_min_bw
);
996 pci_info
->tx_max_bw
=
997 le16_to_cpu(npar
->tx_max_bw
);
998 memcpy(pci_info
->mac
, npar
->mac
, ETH_ALEN
);
1001 dev_err(&adapter
->pdev
->dev
,
1002 "Failed to get PCI Info%d\n", err
);
1006 ahw
->total_nic_func
= nic
;
1007 ahw
->total_pci_func
= nic
+ fcoe
+ iscsi
;
1008 if (ahw
->total_nic_func
== 0 || ahw
->total_pci_func
== 0) {
1009 dev_err(&adapter
->pdev
->dev
,
1010 "%s: Invalid function count: total nic func[%x], total pci func[%x]\n",
1011 __func__
, ahw
->total_nic_func
, ahw
->total_pci_func
);
1014 qlcnic_free_mbx_args(&cmd
);
1016 dma_free_coherent(&adapter
->pdev
->dev
, pci_size
, pci_info_addr
,
1022 /* Configure eSwitch for port mirroring */
1023 int qlcnic_config_port_mirroring(struct qlcnic_adapter
*adapter
, u8 id
,
1024 u8 enable_mirroring
, u8 pci_func
)
1026 struct device
*dev
= &adapter
->pdev
->dev
;
1027 struct qlcnic_cmd_args cmd
;
1031 if (adapter
->ahw
->op_mode
!= QLCNIC_MGMT_FUNC
||
1032 !(adapter
->eswitch
[id
].flags
& QLCNIC_SWITCH_ENABLE
)) {
1033 dev_err(&adapter
->pdev
->dev
, "%s: Not a management function\n",
1038 arg1
= id
| (enable_mirroring
? BIT_4
: 0);
1039 arg1
|= pci_func
<< 8;
1041 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
,
1042 QLCNIC_CMD_SET_PORTMIRRORING
);
1046 cmd
.req
.arg
[1] = arg1
;
1047 err
= qlcnic_issue_cmd(adapter
, &cmd
);
1049 if (err
!= QLCNIC_RCODE_SUCCESS
)
1050 dev_err(dev
, "Failed to configure port mirroring for vNIC function %d on eSwitch %d\n",
1053 dev_info(dev
, "Configured port mirroring for vNIC function %d on eSwitch %d\n",
1055 qlcnic_free_mbx_args(&cmd
);
1060 int qlcnic_get_port_stats(struct qlcnic_adapter
*adapter
, const u8 func
,
1061 const u8 rx_tx
, struct __qlcnic_esw_statistics
*esw_stats
) {
1063 size_t stats_size
= sizeof(struct qlcnic_esw_stats_le
);
1064 struct qlcnic_esw_stats_le
*stats
;
1065 dma_addr_t stats_dma_t
;
1068 struct qlcnic_cmd_args cmd
;
1071 if (esw_stats
== NULL
)
1074 if ((adapter
->ahw
->op_mode
!= QLCNIC_MGMT_FUNC
) &&
1075 (func
!= adapter
->ahw
->pci_func
)) {
1076 dev_err(&adapter
->pdev
->dev
,
1077 "Not privilege to query stats for func=%d", func
);
1081 stats_addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, stats_size
,
1082 &stats_dma_t
, GFP_KERNEL
);
1086 arg1
= func
| QLCNIC_STATS_VERSION
<< 8 | QLCNIC_STATS_PORT
<< 12;
1087 arg1
|= rx_tx
<< 15 | stats_size
<< 16;
1089 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
,
1090 QLCNIC_CMD_GET_ESWITCH_STATS
);
1094 cmd
.req
.arg
[1] = arg1
;
1095 cmd
.req
.arg
[2] = MSD(stats_dma_t
);
1096 cmd
.req
.arg
[3] = LSD(stats_dma_t
);
1097 err
= qlcnic_issue_cmd(adapter
, &cmd
);
1101 esw_stats
->context_id
= le16_to_cpu(stats
->context_id
);
1102 esw_stats
->version
= le16_to_cpu(stats
->version
);
1103 esw_stats
->size
= le16_to_cpu(stats
->size
);
1104 esw_stats
->multicast_frames
=
1105 le64_to_cpu(stats
->multicast_frames
);
1106 esw_stats
->broadcast_frames
=
1107 le64_to_cpu(stats
->broadcast_frames
);
1108 esw_stats
->unicast_frames
= le64_to_cpu(stats
->unicast_frames
);
1109 esw_stats
->dropped_frames
= le64_to_cpu(stats
->dropped_frames
);
1110 esw_stats
->local_frames
= le64_to_cpu(stats
->local_frames
);
1111 esw_stats
->errors
= le64_to_cpu(stats
->errors
);
1112 esw_stats
->numbytes
= le64_to_cpu(stats
->numbytes
);
1115 qlcnic_free_mbx_args(&cmd
);
1117 dma_free_coherent(&adapter
->pdev
->dev
, stats_size
, stats_addr
,
1123 /* This routine will retrieve the MAC statistics from firmware */
1124 int qlcnic_get_mac_stats(struct qlcnic_adapter
*adapter
,
1125 struct qlcnic_mac_statistics
*mac_stats
)
1127 struct qlcnic_mac_statistics_le
*stats
;
1128 struct qlcnic_cmd_args cmd
;
1129 size_t stats_size
= sizeof(struct qlcnic_mac_statistics_le
);
1130 dma_addr_t stats_dma_t
;
1134 if (mac_stats
== NULL
)
1137 stats_addr
= dma_alloc_coherent(&adapter
->pdev
->dev
, stats_size
,
1138 &stats_dma_t
, GFP_KERNEL
);
1142 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_GET_MAC_STATS
);
1146 cmd
.req
.arg
[1] = stats_size
<< 16;
1147 cmd
.req
.arg
[2] = MSD(stats_dma_t
);
1148 cmd
.req
.arg
[3] = LSD(stats_dma_t
);
1149 err
= qlcnic_issue_cmd(adapter
, &cmd
);
1152 mac_stats
->mac_tx_frames
= le64_to_cpu(stats
->mac_tx_frames
);
1153 mac_stats
->mac_tx_bytes
= le64_to_cpu(stats
->mac_tx_bytes
);
1154 mac_stats
->mac_tx_mcast_pkts
=
1155 le64_to_cpu(stats
->mac_tx_mcast_pkts
);
1156 mac_stats
->mac_tx_bcast_pkts
=
1157 le64_to_cpu(stats
->mac_tx_bcast_pkts
);
1158 mac_stats
->mac_rx_frames
= le64_to_cpu(stats
->mac_rx_frames
);
1159 mac_stats
->mac_rx_bytes
= le64_to_cpu(stats
->mac_rx_bytes
);
1160 mac_stats
->mac_rx_mcast_pkts
=
1161 le64_to_cpu(stats
->mac_rx_mcast_pkts
);
1162 mac_stats
->mac_rx_length_error
=
1163 le64_to_cpu(stats
->mac_rx_length_error
);
1164 mac_stats
->mac_rx_length_small
=
1165 le64_to_cpu(stats
->mac_rx_length_small
);
1166 mac_stats
->mac_rx_length_large
=
1167 le64_to_cpu(stats
->mac_rx_length_large
);
1168 mac_stats
->mac_rx_jabber
= le64_to_cpu(stats
->mac_rx_jabber
);
1169 mac_stats
->mac_rx_dropped
= le64_to_cpu(stats
->mac_rx_dropped
);
1170 mac_stats
->mac_rx_crc_error
= le64_to_cpu(stats
->mac_rx_crc_error
);
1172 dev_err(&adapter
->pdev
->dev
,
1173 "%s: Get mac stats failed, err=%d.\n", __func__
, err
);
1176 qlcnic_free_mbx_args(&cmd
);
1179 dma_free_coherent(&adapter
->pdev
->dev
, stats_size
, stats_addr
,
1185 int qlcnic_get_eswitch_stats(struct qlcnic_adapter
*adapter
, const u8 eswitch
,
1186 const u8 rx_tx
, struct __qlcnic_esw_statistics
*esw_stats
) {
1188 struct __qlcnic_esw_statistics port_stats
;
1192 if (esw_stats
== NULL
)
1194 if (adapter
->ahw
->op_mode
!= QLCNIC_MGMT_FUNC
)
1196 if (adapter
->npars
== NULL
)
1199 memset(esw_stats
, 0, sizeof(u64
));
1200 esw_stats
->unicast_frames
= QLCNIC_STATS_NOT_AVAIL
;
1201 esw_stats
->multicast_frames
= QLCNIC_STATS_NOT_AVAIL
;
1202 esw_stats
->broadcast_frames
= QLCNIC_STATS_NOT_AVAIL
;
1203 esw_stats
->dropped_frames
= QLCNIC_STATS_NOT_AVAIL
;
1204 esw_stats
->errors
= QLCNIC_STATS_NOT_AVAIL
;
1205 esw_stats
->local_frames
= QLCNIC_STATS_NOT_AVAIL
;
1206 esw_stats
->numbytes
= QLCNIC_STATS_NOT_AVAIL
;
1207 esw_stats
->context_id
= eswitch
;
1209 for (i
= 0; i
< adapter
->ahw
->total_nic_func
; i
++) {
1210 if (adapter
->npars
[i
].phy_port
!= eswitch
)
1213 memset(&port_stats
, 0, sizeof(struct __qlcnic_esw_statistics
));
1214 if (qlcnic_get_port_stats(adapter
, adapter
->npars
[i
].pci_func
,
1215 rx_tx
, &port_stats
))
1218 esw_stats
->size
= port_stats
.size
;
1219 esw_stats
->version
= port_stats
.version
;
1220 QLCNIC_ADD_ESW_STATS(esw_stats
->unicast_frames
,
1221 port_stats
.unicast_frames
);
1222 QLCNIC_ADD_ESW_STATS(esw_stats
->multicast_frames
,
1223 port_stats
.multicast_frames
);
1224 QLCNIC_ADD_ESW_STATS(esw_stats
->broadcast_frames
,
1225 port_stats
.broadcast_frames
);
1226 QLCNIC_ADD_ESW_STATS(esw_stats
->dropped_frames
,
1227 port_stats
.dropped_frames
);
1228 QLCNIC_ADD_ESW_STATS(esw_stats
->errors
,
1230 QLCNIC_ADD_ESW_STATS(esw_stats
->local_frames
,
1231 port_stats
.local_frames
);
1232 QLCNIC_ADD_ESW_STATS(esw_stats
->numbytes
,
1233 port_stats
.numbytes
);
1239 int qlcnic_clear_esw_stats(struct qlcnic_adapter
*adapter
, const u8 func_esw
,
1240 const u8 port
, const u8 rx_tx
)
1242 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1243 struct qlcnic_cmd_args cmd
;
1247 if (ahw
->op_mode
!= QLCNIC_MGMT_FUNC
)
1250 if (func_esw
== QLCNIC_STATS_PORT
) {
1251 if (port
>= ahw
->max_vnic_func
)
1253 } else if (func_esw
== QLCNIC_STATS_ESWITCH
) {
1254 if (port
>= QLCNIC_NIU_MAX_XG_PORTS
)
1260 if (rx_tx
> QLCNIC_QUERY_TX_COUNTER
)
1263 arg1
= port
| QLCNIC_STATS_VERSION
<< 8 | func_esw
<< 12;
1264 arg1
|= BIT_14
| rx_tx
<< 15;
1266 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
,
1267 QLCNIC_CMD_GET_ESWITCH_STATS
);
1271 cmd
.req
.arg
[1] = arg1
;
1272 err
= qlcnic_issue_cmd(adapter
, &cmd
);
1273 qlcnic_free_mbx_args(&cmd
);
1277 dev_err(&adapter
->pdev
->dev
,
1278 "Invalid args func_esw %d port %d rx_ctx %d\n",
1279 func_esw
, port
, rx_tx
);
1283 static int __qlcnic_get_eswitch_port_config(struct qlcnic_adapter
*adapter
,
1284 u32
*arg1
, u32
*arg2
)
1286 struct device
*dev
= &adapter
->pdev
->dev
;
1287 struct qlcnic_cmd_args cmd
;
1288 u8 pci_func
= *arg1
>> 8;
1291 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
,
1292 QLCNIC_CMD_GET_ESWITCH_PORT_CONFIG
);
1296 cmd
.req
.arg
[1] = *arg1
;
1297 err
= qlcnic_issue_cmd(adapter
, &cmd
);
1298 *arg1
= cmd
.rsp
.arg
[1];
1299 *arg2
= cmd
.rsp
.arg
[2];
1300 qlcnic_free_mbx_args(&cmd
);
1302 if (err
== QLCNIC_RCODE_SUCCESS
)
1303 dev_info(dev
, "Get eSwitch port config for vNIC function %d\n",
1306 dev_err(dev
, "Failed to get eswitch port config for vNIC function %d\n",
1310 /* Configure eSwitch port
1311 op_mode = 0 for setting default port behavior
1312 op_mode = 1 for setting vlan id
1313 op_mode = 2 for deleting vlan id
1314 op_type = 0 for vlan_id
1315 op_type = 1 for port vlan_id
1317 int qlcnic_config_switch_port(struct qlcnic_adapter
*adapter
,
1318 struct qlcnic_esw_func_cfg
*esw_cfg
)
1320 struct device
*dev
= &adapter
->pdev
->dev
;
1321 struct qlcnic_cmd_args cmd
;
1322 int err
= -EIO
, index
;
1326 if (adapter
->ahw
->op_mode
!= QLCNIC_MGMT_FUNC
) {
1327 dev_err(&adapter
->pdev
->dev
, "%s: Not a management function\n",
1332 pci_func
= esw_cfg
->pci_func
;
1333 index
= qlcnic_is_valid_nic_func(adapter
, pci_func
);
1336 arg1
= (adapter
->npars
[index
].phy_port
& BIT_0
);
1337 arg1
|= (pci_func
<< 8);
1339 if (__qlcnic_get_eswitch_port_config(adapter
, &arg1
, &arg2
))
1341 arg1
&= ~(0x0ff << 8);
1342 arg1
|= (pci_func
<< 8);
1343 arg1
&= ~(BIT_2
| BIT_3
);
1344 switch (esw_cfg
->op_mode
) {
1345 case QLCNIC_PORT_DEFAULTS
:
1346 arg1
|= (BIT_4
| BIT_6
| BIT_7
);
1347 arg2
|= (BIT_0
| BIT_1
);
1348 if (adapter
->ahw
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
)
1349 arg2
|= (BIT_2
| BIT_3
);
1350 if (!(esw_cfg
->discard_tagged
))
1352 if (!(esw_cfg
->promisc_mode
))
1354 if (!(esw_cfg
->mac_override
))
1356 if (!(esw_cfg
->mac_anti_spoof
))
1358 if (!(esw_cfg
->offload_flags
& BIT_0
))
1359 arg2
&= ~(BIT_1
| BIT_2
| BIT_3
);
1360 if (!(esw_cfg
->offload_flags
& BIT_1
))
1362 if (!(esw_cfg
->offload_flags
& BIT_2
))
1365 case QLCNIC_ADD_VLAN
:
1366 arg1
&= ~(0x0ffff << 16);
1367 arg1
|= (BIT_2
| BIT_5
);
1368 arg1
|= (esw_cfg
->vlan_id
<< 16);
1370 case QLCNIC_DEL_VLAN
:
1371 arg1
|= (BIT_3
| BIT_5
);
1372 arg1
&= ~(0x0ffff << 16);
1375 dev_err(&adapter
->pdev
->dev
, "%s: Invalid opmode 0x%x\n",
1376 __func__
, esw_cfg
->op_mode
);
1380 err
= qlcnic_alloc_mbx_args(&cmd
, adapter
,
1381 QLCNIC_CMD_CONFIGURE_ESWITCH
);
1385 cmd
.req
.arg
[1] = arg1
;
1386 cmd
.req
.arg
[2] = arg2
;
1387 err
= qlcnic_issue_cmd(adapter
, &cmd
);
1388 qlcnic_free_mbx_args(&cmd
);
1390 if (err
!= QLCNIC_RCODE_SUCCESS
)
1391 dev_err(dev
, "Failed to configure eswitch for vNIC function %d\n",
1394 dev_info(dev
, "Configured eSwitch for vNIC function %d\n",
1401 qlcnic_get_eswitch_port_config(struct qlcnic_adapter
*adapter
,
1402 struct qlcnic_esw_func_cfg
*esw_cfg
)
1408 if (adapter
->ahw
->op_mode
== QLCNIC_MGMT_FUNC
) {
1409 index
= qlcnic_is_valid_nic_func(adapter
, esw_cfg
->pci_func
);
1412 phy_port
= adapter
->npars
[index
].phy_port
;
1414 phy_port
= adapter
->ahw
->physical_port
;
1417 arg1
|= (esw_cfg
->pci_func
<< 8);
1418 if (__qlcnic_get_eswitch_port_config(adapter
, &arg1
, &arg2
))
1421 esw_cfg
->discard_tagged
= !!(arg1
& BIT_4
);
1422 esw_cfg
->host_vlan_tag
= !!(arg1
& BIT_5
);
1423 esw_cfg
->promisc_mode
= !!(arg1
& BIT_6
);
1424 esw_cfg
->mac_override
= !!(arg1
& BIT_7
);
1425 esw_cfg
->vlan_id
= LSW(arg1
>> 16);
1426 esw_cfg
->mac_anti_spoof
= (arg2
& 0x1);
1427 esw_cfg
->offload_flags
= ((arg2
>> 1) & 0x7);