2 * Copyright (C) 2005 - 2016 Broadcom
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
10 * Contact Information:
11 * linux-drivers@emulex.com
15 * Costa Mesa, CA 92626
18 #include <linux/module.h>
22 char *be_misconfig_evt_port_state
[] = {
23 "Physical Link is functional",
24 "Optics faulted/incorrectly installed/not installed - Reseat optics. If issue not resolved, replace.",
25 "Optics of two types installed – Remove one optic or install matching pair of optics.",
26 "Incompatible optics – Replace with compatible optics for card to function.",
27 "Unqualified optics – Replace with Avago optics for Warranty and Technical Support.",
28 "Uncertified optics – Replace with Avago-certified optics to enable link operation."
31 static char *be_port_misconfig_evt_severity
[] = {
38 static char *phy_state_oper_desc
[] = {
39 "Link is non-operational",
40 "Link is operational",
44 static struct be_cmd_priv_map cmd_priv_map
[] = {
46 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG
,
48 BE_PRIV_LNKMGMT
| BE_PRIV_VHADM
|
49 BE_PRIV_DEVCFG
| BE_PRIV_DEVSEC
52 OPCODE_COMMON_GET_FLOW_CONTROL
,
54 BE_PRIV_LNKQUERY
| BE_PRIV_VHADM
|
55 BE_PRIV_DEVCFG
| BE_PRIV_DEVSEC
58 OPCODE_COMMON_SET_FLOW_CONTROL
,
60 BE_PRIV_LNKMGMT
| BE_PRIV_VHADM
|
61 BE_PRIV_DEVCFG
| BE_PRIV_DEVSEC
64 OPCODE_ETH_GET_PPORT_STATS
,
66 BE_PRIV_LNKMGMT
| BE_PRIV_VHADM
|
67 BE_PRIV_DEVCFG
| BE_PRIV_DEVSEC
70 OPCODE_COMMON_GET_PHY_DETAILS
,
72 BE_PRIV_LNKMGMT
| BE_PRIV_VHADM
|
73 BE_PRIV_DEVCFG
| BE_PRIV_DEVSEC
76 OPCODE_LOWLEVEL_HOST_DDR_DMA
,
77 CMD_SUBSYSTEM_LOWLEVEL
,
78 BE_PRIV_DEVCFG
| BE_PRIV_DEVSEC
81 OPCODE_LOWLEVEL_LOOPBACK_TEST
,
82 CMD_SUBSYSTEM_LOWLEVEL
,
83 BE_PRIV_DEVCFG
| BE_PRIV_DEVSEC
86 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE
,
87 CMD_SUBSYSTEM_LOWLEVEL
,
88 BE_PRIV_DEVCFG
| BE_PRIV_DEVSEC
91 OPCODE_COMMON_SET_HSW_CONFIG
,
93 BE_PRIV_DEVCFG
| BE_PRIV_VHADM
|
97 OPCODE_COMMON_GET_EXT_FAT_CAPABILITIES
,
103 static bool be_cmd_allowed(struct be_adapter
*adapter
, u8 opcode
, u8 subsystem
)
106 int num_entries
= sizeof(cmd_priv_map
)/sizeof(struct be_cmd_priv_map
);
107 u32 cmd_privileges
= adapter
->cmd_privileges
;
109 for (i
= 0; i
< num_entries
; i
++)
110 if (opcode
== cmd_priv_map
[i
].opcode
&&
111 subsystem
== cmd_priv_map
[i
].subsystem
)
112 if (!(cmd_privileges
& cmd_priv_map
[i
].priv_mask
))
118 static inline void *embedded_payload(struct be_mcc_wrb
*wrb
)
120 return wrb
->payload
.embedded_payload
;
123 static int be_mcc_notify(struct be_adapter
*adapter
)
125 struct be_queue_info
*mccq
= &adapter
->mcc_obj
.q
;
128 if (be_check_error(adapter
, BE_ERROR_ANY
))
131 val
|= mccq
->id
& DB_MCCQ_RING_ID_MASK
;
132 val
|= 1 << DB_MCCQ_NUM_POSTED_SHIFT
;
135 iowrite32(val
, adapter
->db
+ DB_MCCQ_OFFSET
);
140 /* To check if valid bit is set, check the entire word as we don't know
141 * the endianness of the data (old entry is host endian while a new entry is
143 static inline bool be_mcc_compl_is_new(struct be_mcc_compl
*compl)
147 if (compl->flags
!= 0) {
148 flags
= le32_to_cpu(compl->flags
);
149 if (flags
& CQE_FLAGS_VALID_MASK
) {
150 compl->flags
= flags
;
157 /* Need to reset the entire word that houses the valid bit */
158 static inline void be_mcc_compl_use(struct be_mcc_compl
*compl)
163 static struct be_cmd_resp_hdr
*be_decode_resp_hdr(u32 tag0
, u32 tag1
)
168 addr
= ((addr
<< 16) << 16) | tag0
;
172 static bool be_skip_err_log(u8 opcode
, u16 base_status
, u16 addl_status
)
174 if (base_status
== MCC_STATUS_NOT_SUPPORTED
||
175 base_status
== MCC_STATUS_ILLEGAL_REQUEST
||
176 addl_status
== MCC_ADDL_STATUS_TOO_MANY_INTERFACES
||
177 addl_status
== MCC_ADDL_STATUS_INSUFFICIENT_VLANS
||
178 (opcode
== OPCODE_COMMON_WRITE_FLASHROM
&&
179 (base_status
== MCC_STATUS_ILLEGAL_FIELD
||
180 addl_status
== MCC_ADDL_STATUS_FLASH_IMAGE_CRC_MISMATCH
)))
186 /* Place holder for all the async MCC cmds wherein the caller is not in a busy
187 * loop (has not issued be_mcc_notify_wait())
189 static void be_async_cmd_process(struct be_adapter
*adapter
,
190 struct be_mcc_compl
*compl,
191 struct be_cmd_resp_hdr
*resp_hdr
)
193 enum mcc_base_status base_status
= base_status(compl->status
);
194 u8 opcode
= 0, subsystem
= 0;
197 opcode
= resp_hdr
->opcode
;
198 subsystem
= resp_hdr
->subsystem
;
201 if (opcode
== OPCODE_LOWLEVEL_LOOPBACK_TEST
&&
202 subsystem
== CMD_SUBSYSTEM_LOWLEVEL
) {
203 complete(&adapter
->et_cmd_compl
);
207 if (opcode
== OPCODE_LOWLEVEL_SET_LOOPBACK_MODE
&&
208 subsystem
== CMD_SUBSYSTEM_LOWLEVEL
) {
209 complete(&adapter
->et_cmd_compl
);
213 if ((opcode
== OPCODE_COMMON_WRITE_FLASHROM
||
214 opcode
== OPCODE_COMMON_WRITE_OBJECT
) &&
215 subsystem
== CMD_SUBSYSTEM_COMMON
) {
216 adapter
->flash_status
= compl->status
;
217 complete(&adapter
->et_cmd_compl
);
221 if ((opcode
== OPCODE_ETH_GET_STATISTICS
||
222 opcode
== OPCODE_ETH_GET_PPORT_STATS
) &&
223 subsystem
== CMD_SUBSYSTEM_ETH
&&
224 base_status
== MCC_STATUS_SUCCESS
) {
225 be_parse_stats(adapter
);
226 adapter
->stats_cmd_sent
= false;
230 if (opcode
== OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES
&&
231 subsystem
== CMD_SUBSYSTEM_COMMON
) {
232 if (base_status
== MCC_STATUS_SUCCESS
) {
233 struct be_cmd_resp_get_cntl_addnl_attribs
*resp
=
235 adapter
->hwmon_info
.be_on_die_temp
=
236 resp
->on_die_temperature
;
238 adapter
->be_get_temp_freq
= 0;
239 adapter
->hwmon_info
.be_on_die_temp
=
246 static int be_mcc_compl_process(struct be_adapter
*adapter
,
247 struct be_mcc_compl
*compl)
249 enum mcc_base_status base_status
;
250 enum mcc_addl_status addl_status
;
251 struct be_cmd_resp_hdr
*resp_hdr
;
252 u8 opcode
= 0, subsystem
= 0;
254 /* Just swap the status to host endian; mcc tag is opaquely copied
256 be_dws_le_to_cpu(compl, 4);
258 base_status
= base_status(compl->status
);
259 addl_status
= addl_status(compl->status
);
261 resp_hdr
= be_decode_resp_hdr(compl->tag0
, compl->tag1
);
263 opcode
= resp_hdr
->opcode
;
264 subsystem
= resp_hdr
->subsystem
;
267 be_async_cmd_process(adapter
, compl, resp_hdr
);
269 if (base_status
!= MCC_STATUS_SUCCESS
&&
270 !be_skip_err_log(opcode
, base_status
, addl_status
)) {
271 if (base_status
== MCC_STATUS_UNAUTHORIZED_REQUEST
||
272 addl_status
== MCC_ADDL_STATUS_INSUFFICIENT_PRIVILEGES
) {
273 dev_warn(&adapter
->pdev
->dev
,
274 "VF is not privileged to issue opcode %d-%d\n",
277 dev_err(&adapter
->pdev
->dev
,
278 "opcode %d-%d failed:status %d-%d\n",
279 opcode
, subsystem
, base_status
, addl_status
);
282 return compl->status
;
285 /* Link state evt is a string of bytes; no need for endian swapping */
286 static void be_async_link_state_process(struct be_adapter
*adapter
,
287 struct be_mcc_compl
*compl)
289 struct be_async_event_link_state
*evt
=
290 (struct be_async_event_link_state
*)compl;
292 /* When link status changes, link speed must be re-queried from FW */
293 adapter
->phy
.link_speed
= -1;
295 /* On BEx the FW does not send a separate link status
296 * notification for physical and logical link.
297 * On other chips just process the logical link
298 * status notification
300 if (!BEx_chip(adapter
) &&
301 !(evt
->port_link_status
& LOGICAL_LINK_STATUS_MASK
))
304 /* For the initial link status do not rely on the ASYNC event as
305 * it may not be received in some cases.
307 if (adapter
->flags
& BE_FLAGS_LINK_STATUS_INIT
)
308 be_link_status_update(adapter
,
309 evt
->port_link_status
& LINK_STATUS_MASK
);
312 static void be_async_port_misconfig_event_process(struct be_adapter
*adapter
,
313 struct be_mcc_compl
*compl)
315 struct be_async_event_misconfig_port
*evt
=
316 (struct be_async_event_misconfig_port
*)compl;
317 u32 sfp_misconfig_evt_word1
= le32_to_cpu(evt
->event_data_word1
);
318 u32 sfp_misconfig_evt_word2
= le32_to_cpu(evt
->event_data_word2
);
319 u8 phy_oper_state
= PHY_STATE_OPER_MSG_NONE
;
320 struct device
*dev
= &adapter
->pdev
->dev
;
321 u8 msg_severity
= DEFAULT_MSG_SEVERITY
;
326 (sfp_misconfig_evt_word1
>> (adapter
->hba_port_num
* 8)) & 0xff;
328 if (new_phy_state
== adapter
->phy_state
)
331 adapter
->phy_state
= new_phy_state
;
333 /* for older fw that doesn't populate link effect data */
334 if (!sfp_misconfig_evt_word2
)
338 (sfp_misconfig_evt_word2
>> (adapter
->hba_port_num
* 8)) & 0xff;
340 if (phy_state_info
& PHY_STATE_INFO_VALID
) {
341 msg_severity
= (phy_state_info
& PHY_STATE_MSG_SEVERITY
) >> 1;
343 if (be_phy_unqualified(new_phy_state
))
344 phy_oper_state
= (phy_state_info
& PHY_STATE_OPER
);
348 /* Log an error message that would allow a user to determine
349 * whether the SFPs have an issue
351 if (be_phy_state_unknown(new_phy_state
))
352 dev_printk(be_port_misconfig_evt_severity
[msg_severity
], dev
,
353 "Port %c: Unrecognized Optics state: 0x%x. %s",
356 phy_state_oper_desc
[phy_oper_state
]);
358 dev_printk(be_port_misconfig_evt_severity
[msg_severity
], dev
,
361 be_misconfig_evt_port_state
[new_phy_state
],
362 phy_state_oper_desc
[phy_oper_state
]);
364 /* Log Vendor name and part no. if a misconfigured SFP is detected */
365 if (be_phy_misconfigured(new_phy_state
))
366 adapter
->flags
|= BE_FLAGS_PHY_MISCONFIGURED
;
369 /* Grp5 CoS Priority evt */
370 static void be_async_grp5_cos_priority_process(struct be_adapter
*adapter
,
371 struct be_mcc_compl
*compl)
373 struct be_async_event_grp5_cos_priority
*evt
=
374 (struct be_async_event_grp5_cos_priority
*)compl;
377 adapter
->vlan_prio_bmap
= evt
->available_priority_bmap
;
378 adapter
->recommended_prio_bits
=
379 evt
->reco_default_priority
<< VLAN_PRIO_SHIFT
;
383 /* Grp5 QOS Speed evt: qos_link_speed is in units of 10 Mbps */
384 static void be_async_grp5_qos_speed_process(struct be_adapter
*adapter
,
385 struct be_mcc_compl
*compl)
387 struct be_async_event_grp5_qos_link_speed
*evt
=
388 (struct be_async_event_grp5_qos_link_speed
*)compl;
390 if (adapter
->phy
.link_speed
>= 0 &&
391 evt
->physical_port
== adapter
->port_num
)
392 adapter
->phy
.link_speed
= le16_to_cpu(evt
->qos_link_speed
) * 10;
396 static void be_async_grp5_pvid_state_process(struct be_adapter
*adapter
,
397 struct be_mcc_compl
*compl)
399 struct be_async_event_grp5_pvid_state
*evt
=
400 (struct be_async_event_grp5_pvid_state
*)compl;
403 adapter
->pvid
= le16_to_cpu(evt
->tag
) & VLAN_VID_MASK
;
404 dev_info(&adapter
->pdev
->dev
, "LPVID: %d\n", adapter
->pvid
);
410 #define MGMT_ENABLE_MASK 0x4
411 static void be_async_grp5_fw_control_process(struct be_adapter
*adapter
,
412 struct be_mcc_compl
*compl)
414 struct be_async_fw_control
*evt
= (struct be_async_fw_control
*)compl;
415 u32 evt_dw1
= le32_to_cpu(evt
->event_data_word1
);
417 if (evt_dw1
& MGMT_ENABLE_MASK
) {
418 adapter
->flags
|= BE_FLAGS_OS2BMC
;
419 adapter
->bmc_filt_mask
= le32_to_cpu(evt
->event_data_word2
);
421 adapter
->flags
&= ~BE_FLAGS_OS2BMC
;
425 static void be_async_grp5_evt_process(struct be_adapter
*adapter
,
426 struct be_mcc_compl
*compl)
428 u8 event_type
= (compl->flags
>> ASYNC_EVENT_TYPE_SHIFT
) &
429 ASYNC_EVENT_TYPE_MASK
;
431 switch (event_type
) {
432 case ASYNC_EVENT_COS_PRIORITY
:
433 be_async_grp5_cos_priority_process(adapter
, compl);
435 case ASYNC_EVENT_QOS_SPEED
:
436 be_async_grp5_qos_speed_process(adapter
, compl);
438 case ASYNC_EVENT_PVID_STATE
:
439 be_async_grp5_pvid_state_process(adapter
, compl);
441 /* Async event to disable/enable os2bmc and/or mac-learning */
442 case ASYNC_EVENT_FW_CONTROL
:
443 be_async_grp5_fw_control_process(adapter
, compl);
450 static void be_async_dbg_evt_process(struct be_adapter
*adapter
,
451 struct be_mcc_compl
*cmp
)
454 struct be_async_event_qnq
*evt
= (struct be_async_event_qnq
*)cmp
;
456 event_type
= (cmp
->flags
>> ASYNC_EVENT_TYPE_SHIFT
) &
457 ASYNC_EVENT_TYPE_MASK
;
459 switch (event_type
) {
460 case ASYNC_DEBUG_EVENT_TYPE_QNQ
:
462 adapter
->qnq_vid
= le16_to_cpu(evt
->vlan_tag
);
463 adapter
->flags
|= BE_FLAGS_QNQ_ASYNC_EVT_RCVD
;
466 dev_warn(&adapter
->pdev
->dev
, "Unknown debug event 0x%x!\n",
472 static void be_async_sliport_evt_process(struct be_adapter
*adapter
,
473 struct be_mcc_compl
*cmp
)
475 u8 event_type
= (cmp
->flags
>> ASYNC_EVENT_TYPE_SHIFT
) &
476 ASYNC_EVENT_TYPE_MASK
;
478 if (event_type
== ASYNC_EVENT_PORT_MISCONFIG
)
479 be_async_port_misconfig_event_process(adapter
, cmp
);
482 static inline bool is_link_state_evt(u32 flags
)
484 return ((flags
>> ASYNC_EVENT_CODE_SHIFT
) & ASYNC_EVENT_CODE_MASK
) ==
485 ASYNC_EVENT_CODE_LINK_STATE
;
488 static inline bool is_grp5_evt(u32 flags
)
490 return ((flags
>> ASYNC_EVENT_CODE_SHIFT
) & ASYNC_EVENT_CODE_MASK
) ==
491 ASYNC_EVENT_CODE_GRP_5
;
494 static inline bool is_dbg_evt(u32 flags
)
496 return ((flags
>> ASYNC_EVENT_CODE_SHIFT
) & ASYNC_EVENT_CODE_MASK
) ==
497 ASYNC_EVENT_CODE_QNQ
;
500 static inline bool is_sliport_evt(u32 flags
)
502 return ((flags
>> ASYNC_EVENT_CODE_SHIFT
) & ASYNC_EVENT_CODE_MASK
) ==
503 ASYNC_EVENT_CODE_SLIPORT
;
506 static void be_mcc_event_process(struct be_adapter
*adapter
,
507 struct be_mcc_compl
*compl)
509 if (is_link_state_evt(compl->flags
))
510 be_async_link_state_process(adapter
, compl);
511 else if (is_grp5_evt(compl->flags
))
512 be_async_grp5_evt_process(adapter
, compl);
513 else if (is_dbg_evt(compl->flags
))
514 be_async_dbg_evt_process(adapter
, compl);
515 else if (is_sliport_evt(compl->flags
))
516 be_async_sliport_evt_process(adapter
, compl);
519 static struct be_mcc_compl
*be_mcc_compl_get(struct be_adapter
*adapter
)
521 struct be_queue_info
*mcc_cq
= &adapter
->mcc_obj
.cq
;
522 struct be_mcc_compl
*compl = queue_tail_node(mcc_cq
);
524 if (be_mcc_compl_is_new(compl)) {
525 queue_tail_inc(mcc_cq
);
531 void be_async_mcc_enable(struct be_adapter
*adapter
)
533 spin_lock_bh(&adapter
->mcc_cq_lock
);
535 be_cq_notify(adapter
, adapter
->mcc_obj
.cq
.id
, true, 0);
536 adapter
->mcc_obj
.rearm_cq
= true;
538 spin_unlock_bh(&adapter
->mcc_cq_lock
);
541 void be_async_mcc_disable(struct be_adapter
*adapter
)
543 spin_lock_bh(&adapter
->mcc_cq_lock
);
545 adapter
->mcc_obj
.rearm_cq
= false;
546 be_cq_notify(adapter
, adapter
->mcc_obj
.cq
.id
, false, 0);
548 spin_unlock_bh(&adapter
->mcc_cq_lock
);
551 int be_process_mcc(struct be_adapter
*adapter
)
553 struct be_mcc_compl
*compl;
554 int num
= 0, status
= 0;
555 struct be_mcc_obj
*mcc_obj
= &adapter
->mcc_obj
;
557 spin_lock(&adapter
->mcc_cq_lock
);
559 while ((compl = be_mcc_compl_get(adapter
))) {
560 if (compl->flags
& CQE_FLAGS_ASYNC_MASK
) {
561 be_mcc_event_process(adapter
, compl);
562 } else if (compl->flags
& CQE_FLAGS_COMPLETED_MASK
) {
563 status
= be_mcc_compl_process(adapter
, compl);
564 atomic_dec(&mcc_obj
->q
.used
);
566 be_mcc_compl_use(compl);
571 be_cq_notify(adapter
, mcc_obj
->cq
.id
, mcc_obj
->rearm_cq
, num
);
573 spin_unlock(&adapter
->mcc_cq_lock
);
577 /* Wait till no more pending mcc requests are present */
578 static int be_mcc_wait_compl(struct be_adapter
*adapter
)
580 #define mcc_timeout 12000 /* 12s timeout */
582 struct be_mcc_obj
*mcc_obj
= &adapter
->mcc_obj
;
584 for (i
= 0; i
< mcc_timeout
; i
++) {
585 if (be_check_error(adapter
, BE_ERROR_ANY
))
589 status
= be_process_mcc(adapter
);
592 if (atomic_read(&mcc_obj
->q
.used
) == 0)
594 usleep_range(500, 1000);
596 if (i
== mcc_timeout
) {
597 dev_err(&adapter
->pdev
->dev
, "FW not responding\n");
598 be_set_error(adapter
, BE_ERROR_FW
);
604 /* Notify MCC requests and wait for completion */
605 static int be_mcc_notify_wait(struct be_adapter
*adapter
)
608 struct be_mcc_wrb
*wrb
;
609 struct be_mcc_obj
*mcc_obj
= &adapter
->mcc_obj
;
610 u32 index
= mcc_obj
->q
.head
;
611 struct be_cmd_resp_hdr
*resp
;
613 index_dec(&index
, mcc_obj
->q
.len
);
614 wrb
= queue_index_node(&mcc_obj
->q
, index
);
616 resp
= be_decode_resp_hdr(wrb
->tag0
, wrb
->tag1
);
618 status
= be_mcc_notify(adapter
);
622 status
= be_mcc_wait_compl(adapter
);
626 status
= (resp
->base_status
|
627 ((resp
->addl_status
& CQE_ADDL_STATUS_MASK
) <<
628 CQE_ADDL_STATUS_SHIFT
));
633 static int be_mbox_db_ready_wait(struct be_adapter
*adapter
, void __iomem
*db
)
639 if (be_check_error(adapter
, BE_ERROR_ANY
))
642 ready
= ioread32(db
);
643 if (ready
== 0xffffffff)
646 ready
&= MPU_MAILBOX_DB_RDY_MASK
;
651 dev_err(&adapter
->pdev
->dev
, "FW not responding\n");
652 be_set_error(adapter
, BE_ERROR_FW
);
653 be_detect_error(adapter
);
665 * Insert the mailbox address into the doorbell in two steps
666 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
668 static int be_mbox_notify_wait(struct be_adapter
*adapter
)
672 void __iomem
*db
= adapter
->db
+ MPU_MAILBOX_DB_OFFSET
;
673 struct be_dma_mem
*mbox_mem
= &adapter
->mbox_mem
;
674 struct be_mcc_mailbox
*mbox
= mbox_mem
->va
;
675 struct be_mcc_compl
*compl = &mbox
->compl;
677 /* wait for ready to be set */
678 status
= be_mbox_db_ready_wait(adapter
, db
);
682 val
|= MPU_MAILBOX_DB_HI_MASK
;
683 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
684 val
|= (upper_32_bits(mbox_mem
->dma
) >> 2) << 2;
687 /* wait for ready to be set */
688 status
= be_mbox_db_ready_wait(adapter
, db
);
693 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
694 val
|= (u32
)(mbox_mem
->dma
>> 4) << 2;
697 status
= be_mbox_db_ready_wait(adapter
, db
);
701 /* A cq entry has been made now */
702 if (be_mcc_compl_is_new(compl)) {
703 status
= be_mcc_compl_process(adapter
, &mbox
->compl);
704 be_mcc_compl_use(compl);
708 dev_err(&adapter
->pdev
->dev
, "invalid mailbox completion\n");
714 u16
be_POST_stage_get(struct be_adapter
*adapter
)
718 if (BEx_chip(adapter
))
719 sem
= ioread32(adapter
->csr
+ SLIPORT_SEMAPHORE_OFFSET_BEx
);
721 pci_read_config_dword(adapter
->pdev
,
722 SLIPORT_SEMAPHORE_OFFSET_SH
, &sem
);
724 return sem
& POST_STAGE_MASK
;
727 static int lancer_wait_ready(struct be_adapter
*adapter
)
729 #define SLIPORT_READY_TIMEOUT 30
733 for (i
= 0; i
< SLIPORT_READY_TIMEOUT
; i
++) {
734 sliport_status
= ioread32(adapter
->db
+ SLIPORT_STATUS_OFFSET
);
735 if (sliport_status
& SLIPORT_STATUS_RDY_MASK
)
738 if (sliport_status
& SLIPORT_STATUS_ERR_MASK
&&
739 !(sliport_status
& SLIPORT_STATUS_RN_MASK
))
745 return sliport_status
? : -1;
748 int be_fw_wait_ready(struct be_adapter
*adapter
)
751 int status
, timeout
= 0;
752 struct device
*dev
= &adapter
->pdev
->dev
;
754 if (lancer_chip(adapter
)) {
755 status
= lancer_wait_ready(adapter
);
764 /* There's no means to poll POST state on BE2/3 VFs */
765 if (BEx_chip(adapter
) && be_virtfn(adapter
))
768 stage
= be_POST_stage_get(adapter
);
769 if (stage
== POST_STAGE_ARMFW_RDY
)
772 dev_info(dev
, "Waiting for POST, %ds elapsed\n", timeout
);
773 if (msleep_interruptible(2000)) {
774 dev_err(dev
, "Waiting for POST aborted\n");
778 } while (timeout
< 60);
781 dev_err(dev
, "POST timeout; stage=%#x\n", stage
);
785 static inline struct be_sge
*nonembedded_sgl(struct be_mcc_wrb
*wrb
)
787 return &wrb
->payload
.sgl
[0];
790 static inline void fill_wrb_tags(struct be_mcc_wrb
*wrb
, unsigned long addr
)
792 wrb
->tag0
= addr
& 0xFFFFFFFF;
793 wrb
->tag1
= upper_32_bits(addr
);
796 /* Don't touch the hdr after it's prepared */
797 /* mem will be NULL for embedded commands */
798 static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr
*req_hdr
,
799 u8 subsystem
, u8 opcode
, int cmd_len
,
800 struct be_mcc_wrb
*wrb
,
801 struct be_dma_mem
*mem
)
805 req_hdr
->opcode
= opcode
;
806 req_hdr
->subsystem
= subsystem
;
807 req_hdr
->request_length
= cpu_to_le32(cmd_len
- sizeof(*req_hdr
));
808 req_hdr
->version
= 0;
809 fill_wrb_tags(wrb
, (ulong
) req_hdr
);
810 wrb
->payload_length
= cmd_len
;
812 wrb
->embedded
|= (1 & MCC_WRB_SGE_CNT_MASK
) <<
813 MCC_WRB_SGE_CNT_SHIFT
;
814 sge
= nonembedded_sgl(wrb
);
815 sge
->pa_hi
= cpu_to_le32(upper_32_bits(mem
->dma
));
816 sge
->pa_lo
= cpu_to_le32(mem
->dma
& 0xFFFFFFFF);
817 sge
->len
= cpu_to_le32(mem
->size
);
819 wrb
->embedded
|= MCC_WRB_EMBEDDED_MASK
;
820 be_dws_cpu_to_le(wrb
, 8);
823 static void be_cmd_page_addrs_prepare(struct phys_addr
*pages
, u32 max_pages
,
824 struct be_dma_mem
*mem
)
826 int i
, buf_pages
= min(PAGES_4K_SPANNED(mem
->va
, mem
->size
), max_pages
);
827 u64 dma
= (u64
)mem
->dma
;
829 for (i
= 0; i
< buf_pages
; i
++) {
830 pages
[i
].lo
= cpu_to_le32(dma
& 0xFFFFFFFF);
831 pages
[i
].hi
= cpu_to_le32(upper_32_bits(dma
));
836 static inline struct be_mcc_wrb
*wrb_from_mbox(struct be_adapter
*adapter
)
838 struct be_dma_mem
*mbox_mem
= &adapter
->mbox_mem
;
839 struct be_mcc_wrb
*wrb
840 = &((struct be_mcc_mailbox
*)(mbox_mem
->va
))->wrb
;
841 memset(wrb
, 0, sizeof(*wrb
));
845 static struct be_mcc_wrb
*wrb_from_mccq(struct be_adapter
*adapter
)
847 struct be_queue_info
*mccq
= &adapter
->mcc_obj
.q
;
848 struct be_mcc_wrb
*wrb
;
853 if (atomic_read(&mccq
->used
) >= mccq
->len
)
856 wrb
= queue_head_node(mccq
);
857 queue_head_inc(mccq
);
858 atomic_inc(&mccq
->used
);
859 memset(wrb
, 0, sizeof(*wrb
));
863 static bool use_mcc(struct be_adapter
*adapter
)
865 return adapter
->mcc_obj
.q
.created
;
868 /* Must be used only in process context */
869 static int be_cmd_lock(struct be_adapter
*adapter
)
871 if (use_mcc(adapter
)) {
872 mutex_lock(&adapter
->mcc_lock
);
875 return mutex_lock_interruptible(&adapter
->mbox_lock
);
879 /* Must be used only in process context */
880 static void be_cmd_unlock(struct be_adapter
*adapter
)
882 if (use_mcc(adapter
))
883 return mutex_unlock(&adapter
->mcc_lock
);
885 return mutex_unlock(&adapter
->mbox_lock
);
888 static struct be_mcc_wrb
*be_cmd_copy(struct be_adapter
*adapter
,
889 struct be_mcc_wrb
*wrb
)
891 struct be_mcc_wrb
*dest_wrb
;
893 if (use_mcc(adapter
)) {
894 dest_wrb
= wrb_from_mccq(adapter
);
898 dest_wrb
= wrb_from_mbox(adapter
);
901 memcpy(dest_wrb
, wrb
, sizeof(*wrb
));
902 if (wrb
->embedded
& cpu_to_le32(MCC_WRB_EMBEDDED_MASK
))
903 fill_wrb_tags(dest_wrb
, (ulong
) embedded_payload(wrb
));
908 /* Must be used only in process context */
909 static int be_cmd_notify_wait(struct be_adapter
*adapter
,
910 struct be_mcc_wrb
*wrb
)
912 struct be_mcc_wrb
*dest_wrb
;
915 status
= be_cmd_lock(adapter
);
919 dest_wrb
= be_cmd_copy(adapter
, wrb
);
925 if (use_mcc(adapter
))
926 status
= be_mcc_notify_wait(adapter
);
928 status
= be_mbox_notify_wait(adapter
);
931 memcpy(wrb
, dest_wrb
, sizeof(*wrb
));
934 be_cmd_unlock(adapter
);
938 /* Tell fw we're about to start firing cmds by writing a
939 * special pattern across the wrb hdr; uses mbox
941 int be_cmd_fw_init(struct be_adapter
*adapter
)
946 if (lancer_chip(adapter
))
949 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
952 wrb
= (u8
*)wrb_from_mbox(adapter
);
962 status
= be_mbox_notify_wait(adapter
);
964 mutex_unlock(&adapter
->mbox_lock
);
968 /* Tell fw we're done with firing cmds by writing a
969 * special pattern across the wrb hdr; uses mbox
971 int be_cmd_fw_clean(struct be_adapter
*adapter
)
976 if (lancer_chip(adapter
))
979 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
982 wrb
= (u8
*)wrb_from_mbox(adapter
);
992 status
= be_mbox_notify_wait(adapter
);
994 mutex_unlock(&adapter
->mbox_lock
);
998 int be_cmd_eq_create(struct be_adapter
*adapter
, struct be_eq_obj
*eqo
)
1000 struct be_mcc_wrb
*wrb
;
1001 struct be_cmd_req_eq_create
*req
;
1002 struct be_dma_mem
*q_mem
= &eqo
->q
.dma_mem
;
1003 int status
, ver
= 0;
1005 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1008 wrb
= wrb_from_mbox(adapter
);
1009 req
= embedded_payload(wrb
);
1011 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1012 OPCODE_COMMON_EQ_CREATE
, sizeof(*req
), wrb
,
1015 /* Support for EQ_CREATEv2 available only SH-R onwards */
1016 if (!(BEx_chip(adapter
) || lancer_chip(adapter
)))
1019 req
->hdr
.version
= ver
;
1020 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
1022 AMAP_SET_BITS(struct amap_eq_context
, valid
, req
->context
, 1);
1024 AMAP_SET_BITS(struct amap_eq_context
, size
, req
->context
, 0);
1025 AMAP_SET_BITS(struct amap_eq_context
, count
, req
->context
,
1026 __ilog2_u32(eqo
->q
.len
/ 256));
1027 be_dws_cpu_to_le(req
->context
, sizeof(req
->context
));
1029 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
1031 status
= be_mbox_notify_wait(adapter
);
1033 struct be_cmd_resp_eq_create
*resp
= embedded_payload(wrb
);
1035 eqo
->q
.id
= le16_to_cpu(resp
->eq_id
);
1037 (ver
== 2) ? le16_to_cpu(resp
->msix_idx
) : eqo
->idx
;
1038 eqo
->q
.created
= true;
1041 mutex_unlock(&adapter
->mbox_lock
);
1046 int be_cmd_mac_addr_query(struct be_adapter
*adapter
, u8
*mac_addr
,
1047 bool permanent
, u32 if_handle
, u32 pmac_id
)
1049 struct be_mcc_wrb
*wrb
;
1050 struct be_cmd_req_mac_query
*req
;
1053 mutex_lock(&adapter
->mcc_lock
);
1055 wrb
= wrb_from_mccq(adapter
);
1060 req
= embedded_payload(wrb
);
1062 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1063 OPCODE_COMMON_NTWK_MAC_QUERY
, sizeof(*req
), wrb
,
1065 req
->type
= MAC_ADDRESS_TYPE_NETWORK
;
1069 req
->if_id
= cpu_to_le16((u16
)if_handle
);
1070 req
->pmac_id
= cpu_to_le32(pmac_id
);
1074 status
= be_mcc_notify_wait(adapter
);
1076 struct be_cmd_resp_mac_query
*resp
= embedded_payload(wrb
);
1078 memcpy(mac_addr
, resp
->mac
.addr
, ETH_ALEN
);
1082 mutex_unlock(&adapter
->mcc_lock
);
1086 /* Uses synchronous MCCQ */
1087 int be_cmd_pmac_add(struct be_adapter
*adapter
, u8
*mac_addr
,
1088 u32 if_id
, u32
*pmac_id
, u32 domain
)
1090 struct be_mcc_wrb
*wrb
;
1091 struct be_cmd_req_pmac_add
*req
;
1094 mutex_lock(&adapter
->mcc_lock
);
1096 wrb
= wrb_from_mccq(adapter
);
1101 req
= embedded_payload(wrb
);
1103 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1104 OPCODE_COMMON_NTWK_PMAC_ADD
, sizeof(*req
), wrb
,
1107 req
->hdr
.domain
= domain
;
1108 req
->if_id
= cpu_to_le32(if_id
);
1109 memcpy(req
->mac_address
, mac_addr
, ETH_ALEN
);
1111 status
= be_mcc_notify_wait(adapter
);
1113 struct be_cmd_resp_pmac_add
*resp
= embedded_payload(wrb
);
1115 *pmac_id
= le32_to_cpu(resp
->pmac_id
);
1119 mutex_unlock(&adapter
->mcc_lock
);
1121 if (status
== MCC_STATUS_UNAUTHORIZED_REQUEST
)
1127 /* Uses synchronous MCCQ */
1128 int be_cmd_pmac_del(struct be_adapter
*adapter
, u32 if_id
, int pmac_id
, u32 dom
)
1130 struct be_mcc_wrb
*wrb
;
1131 struct be_cmd_req_pmac_del
*req
;
1137 mutex_lock(&adapter
->mcc_lock
);
1139 wrb
= wrb_from_mccq(adapter
);
1144 req
= embedded_payload(wrb
);
1146 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1147 OPCODE_COMMON_NTWK_PMAC_DEL
, sizeof(*req
),
1150 req
->hdr
.domain
= dom
;
1151 req
->if_id
= cpu_to_le32(if_id
);
1152 req
->pmac_id
= cpu_to_le32(pmac_id
);
1154 status
= be_mcc_notify_wait(adapter
);
1157 mutex_unlock(&adapter
->mcc_lock
);
1162 int be_cmd_cq_create(struct be_adapter
*adapter
, struct be_queue_info
*cq
,
1163 struct be_queue_info
*eq
, bool no_delay
, int coalesce_wm
)
1165 struct be_mcc_wrb
*wrb
;
1166 struct be_cmd_req_cq_create
*req
;
1167 struct be_dma_mem
*q_mem
= &cq
->dma_mem
;
1171 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1174 wrb
= wrb_from_mbox(adapter
);
1175 req
= embedded_payload(wrb
);
1176 ctxt
= &req
->context
;
1178 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1179 OPCODE_COMMON_CQ_CREATE
, sizeof(*req
), wrb
,
1182 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
1184 if (BEx_chip(adapter
)) {
1185 AMAP_SET_BITS(struct amap_cq_context_be
, coalescwm
, ctxt
,
1187 AMAP_SET_BITS(struct amap_cq_context_be
, nodelay
,
1189 AMAP_SET_BITS(struct amap_cq_context_be
, count
, ctxt
,
1190 __ilog2_u32(cq
->len
/ 256));
1191 AMAP_SET_BITS(struct amap_cq_context_be
, valid
, ctxt
, 1);
1192 AMAP_SET_BITS(struct amap_cq_context_be
, eventable
, ctxt
, 1);
1193 AMAP_SET_BITS(struct amap_cq_context_be
, eqid
, ctxt
, eq
->id
);
1195 req
->hdr
.version
= 2;
1196 req
->page_size
= 1; /* 1 for 4K */
1198 /* coalesce-wm field in this cmd is not relevant to Lancer.
1199 * Lancer uses COMMON_MODIFY_CQ to set this field
1201 if (!lancer_chip(adapter
))
1202 AMAP_SET_BITS(struct amap_cq_context_v2
, coalescwm
,
1204 AMAP_SET_BITS(struct amap_cq_context_v2
, nodelay
, ctxt
,
1206 AMAP_SET_BITS(struct amap_cq_context_v2
, count
, ctxt
,
1207 __ilog2_u32(cq
->len
/ 256));
1208 AMAP_SET_BITS(struct amap_cq_context_v2
, valid
, ctxt
, 1);
1209 AMAP_SET_BITS(struct amap_cq_context_v2
, eventable
, ctxt
, 1);
1210 AMAP_SET_BITS(struct amap_cq_context_v2
, eqid
, ctxt
, eq
->id
);
1213 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
1215 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
1217 status
= be_mbox_notify_wait(adapter
);
1219 struct be_cmd_resp_cq_create
*resp
= embedded_payload(wrb
);
1221 cq
->id
= le16_to_cpu(resp
->cq_id
);
1225 mutex_unlock(&adapter
->mbox_lock
);
1230 static u32
be_encoded_q_len(int q_len
)
1232 u32 len_encoded
= fls(q_len
); /* log2(len) + 1 */
1234 if (len_encoded
== 16)
1239 static int be_cmd_mccq_ext_create(struct be_adapter
*adapter
,
1240 struct be_queue_info
*mccq
,
1241 struct be_queue_info
*cq
)
1243 struct be_mcc_wrb
*wrb
;
1244 struct be_cmd_req_mcc_ext_create
*req
;
1245 struct be_dma_mem
*q_mem
= &mccq
->dma_mem
;
1249 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1252 wrb
= wrb_from_mbox(adapter
);
1253 req
= embedded_payload(wrb
);
1254 ctxt
= &req
->context
;
1256 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1257 OPCODE_COMMON_MCC_CREATE_EXT
, sizeof(*req
), wrb
,
1260 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
1261 if (BEx_chip(adapter
)) {
1262 AMAP_SET_BITS(struct amap_mcc_context_be
, valid
, ctxt
, 1);
1263 AMAP_SET_BITS(struct amap_mcc_context_be
, ring_size
, ctxt
,
1264 be_encoded_q_len(mccq
->len
));
1265 AMAP_SET_BITS(struct amap_mcc_context_be
, cq_id
, ctxt
, cq
->id
);
1267 req
->hdr
.version
= 1;
1268 req
->cq_id
= cpu_to_le16(cq
->id
);
1270 AMAP_SET_BITS(struct amap_mcc_context_v1
, ring_size
, ctxt
,
1271 be_encoded_q_len(mccq
->len
));
1272 AMAP_SET_BITS(struct amap_mcc_context_v1
, valid
, ctxt
, 1);
1273 AMAP_SET_BITS(struct amap_mcc_context_v1
, async_cq_id
,
1275 AMAP_SET_BITS(struct amap_mcc_context_v1
, async_cq_valid
,
1279 /* Subscribe to Link State, Sliport Event and Group 5 Events
1280 * (bits 1, 5 and 17 set)
1282 req
->async_event_bitmap
[0] =
1283 cpu_to_le32(BIT(ASYNC_EVENT_CODE_LINK_STATE
) |
1284 BIT(ASYNC_EVENT_CODE_GRP_5
) |
1285 BIT(ASYNC_EVENT_CODE_QNQ
) |
1286 BIT(ASYNC_EVENT_CODE_SLIPORT
));
1288 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
1290 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
1292 status
= be_mbox_notify_wait(adapter
);
1294 struct be_cmd_resp_mcc_create
*resp
= embedded_payload(wrb
);
1296 mccq
->id
= le16_to_cpu(resp
->id
);
1297 mccq
->created
= true;
1299 mutex_unlock(&adapter
->mbox_lock
);
1304 static int be_cmd_mccq_org_create(struct be_adapter
*adapter
,
1305 struct be_queue_info
*mccq
,
1306 struct be_queue_info
*cq
)
1308 struct be_mcc_wrb
*wrb
;
1309 struct be_cmd_req_mcc_create
*req
;
1310 struct be_dma_mem
*q_mem
= &mccq
->dma_mem
;
1314 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1317 wrb
= wrb_from_mbox(adapter
);
1318 req
= embedded_payload(wrb
);
1319 ctxt
= &req
->context
;
1321 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1322 OPCODE_COMMON_MCC_CREATE
, sizeof(*req
), wrb
,
1325 req
->num_pages
= cpu_to_le16(PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
));
1327 AMAP_SET_BITS(struct amap_mcc_context_be
, valid
, ctxt
, 1);
1328 AMAP_SET_BITS(struct amap_mcc_context_be
, ring_size
, ctxt
,
1329 be_encoded_q_len(mccq
->len
));
1330 AMAP_SET_BITS(struct amap_mcc_context_be
, cq_id
, ctxt
, cq
->id
);
1332 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
1334 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
1336 status
= be_mbox_notify_wait(adapter
);
1338 struct be_cmd_resp_mcc_create
*resp
= embedded_payload(wrb
);
1340 mccq
->id
= le16_to_cpu(resp
->id
);
1341 mccq
->created
= true;
1344 mutex_unlock(&adapter
->mbox_lock
);
1348 int be_cmd_mccq_create(struct be_adapter
*adapter
,
1349 struct be_queue_info
*mccq
, struct be_queue_info
*cq
)
1353 status
= be_cmd_mccq_ext_create(adapter
, mccq
, cq
);
1354 if (status
&& BEx_chip(adapter
)) {
1355 dev_warn(&adapter
->pdev
->dev
, "Upgrade to F/W ver 2.102.235.0 "
1356 "or newer to avoid conflicting priorities between NIC "
1357 "and FCoE traffic");
1358 status
= be_cmd_mccq_org_create(adapter
, mccq
, cq
);
1363 int be_cmd_txq_create(struct be_adapter
*adapter
, struct be_tx_obj
*txo
)
1365 struct be_mcc_wrb wrb
= {0};
1366 struct be_cmd_req_eth_tx_create
*req
;
1367 struct be_queue_info
*txq
= &txo
->q
;
1368 struct be_queue_info
*cq
= &txo
->cq
;
1369 struct be_dma_mem
*q_mem
= &txq
->dma_mem
;
1370 int status
, ver
= 0;
1372 req
= embedded_payload(&wrb
);
1373 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
1374 OPCODE_ETH_TX_CREATE
, sizeof(*req
), &wrb
, NULL
);
1376 if (lancer_chip(adapter
)) {
1377 req
->hdr
.version
= 1;
1378 } else if (BEx_chip(adapter
)) {
1379 if (adapter
->function_caps
& BE_FUNCTION_CAPS_SUPER_NIC
)
1380 req
->hdr
.version
= 2;
1381 } else { /* For SH */
1382 req
->hdr
.version
= 2;
1385 if (req
->hdr
.version
> 0)
1386 req
->if_id
= cpu_to_le16(adapter
->if_handle
);
1387 req
->num_pages
= PAGES_4K_SPANNED(q_mem
->va
, q_mem
->size
);
1388 req
->ulp_num
= BE_ULP1_NUM
;
1389 req
->type
= BE_ETH_TX_RING_TYPE_STANDARD
;
1390 req
->cq_id
= cpu_to_le16(cq
->id
);
1391 req
->queue_size
= be_encoded_q_len(txq
->len
);
1392 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
1393 ver
= req
->hdr
.version
;
1395 status
= be_cmd_notify_wait(adapter
, &wrb
);
1397 struct be_cmd_resp_eth_tx_create
*resp
= embedded_payload(&wrb
);
1399 txq
->id
= le16_to_cpu(resp
->cid
);
1401 txo
->db_offset
= le32_to_cpu(resp
->db_offset
);
1403 txo
->db_offset
= DB_TXULP1_OFFSET
;
1404 txq
->created
= true;
1411 int be_cmd_rxq_create(struct be_adapter
*adapter
,
1412 struct be_queue_info
*rxq
, u16 cq_id
, u16 frag_size
,
1413 u32 if_id
, u32 rss
, u8
*rss_id
)
1415 struct be_mcc_wrb
*wrb
;
1416 struct be_cmd_req_eth_rx_create
*req
;
1417 struct be_dma_mem
*q_mem
= &rxq
->dma_mem
;
1420 mutex_lock(&adapter
->mcc_lock
);
1422 wrb
= wrb_from_mccq(adapter
);
1427 req
= embedded_payload(wrb
);
1429 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
1430 OPCODE_ETH_RX_CREATE
, sizeof(*req
), wrb
, NULL
);
1432 req
->cq_id
= cpu_to_le16(cq_id
);
1433 req
->frag_size
= fls(frag_size
) - 1;
1435 be_cmd_page_addrs_prepare(req
->pages
, ARRAY_SIZE(req
->pages
), q_mem
);
1436 req
->interface_id
= cpu_to_le32(if_id
);
1437 req
->max_frame_size
= cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE
);
1438 req
->rss_queue
= cpu_to_le32(rss
);
1440 status
= be_mcc_notify_wait(adapter
);
1442 struct be_cmd_resp_eth_rx_create
*resp
= embedded_payload(wrb
);
1444 rxq
->id
= le16_to_cpu(resp
->id
);
1445 rxq
->created
= true;
1446 *rss_id
= resp
->rss_id
;
1450 mutex_unlock(&adapter
->mcc_lock
);
1454 /* Generic destroyer function for all types of queues
1457 int be_cmd_q_destroy(struct be_adapter
*adapter
, struct be_queue_info
*q
,
1460 struct be_mcc_wrb
*wrb
;
1461 struct be_cmd_req_q_destroy
*req
;
1462 u8 subsys
= 0, opcode
= 0;
1465 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
1468 wrb
= wrb_from_mbox(adapter
);
1469 req
= embedded_payload(wrb
);
1471 switch (queue_type
) {
1473 subsys
= CMD_SUBSYSTEM_COMMON
;
1474 opcode
= OPCODE_COMMON_EQ_DESTROY
;
1477 subsys
= CMD_SUBSYSTEM_COMMON
;
1478 opcode
= OPCODE_COMMON_CQ_DESTROY
;
1481 subsys
= CMD_SUBSYSTEM_ETH
;
1482 opcode
= OPCODE_ETH_TX_DESTROY
;
1485 subsys
= CMD_SUBSYSTEM_ETH
;
1486 opcode
= OPCODE_ETH_RX_DESTROY
;
1489 subsys
= CMD_SUBSYSTEM_COMMON
;
1490 opcode
= OPCODE_COMMON_MCC_DESTROY
;
1496 be_wrb_cmd_hdr_prepare(&req
->hdr
, subsys
, opcode
, sizeof(*req
), wrb
,
1498 req
->id
= cpu_to_le16(q
->id
);
1500 status
= be_mbox_notify_wait(adapter
);
1503 mutex_unlock(&adapter
->mbox_lock
);
1508 int be_cmd_rxq_destroy(struct be_adapter
*adapter
, struct be_queue_info
*q
)
1510 struct be_mcc_wrb
*wrb
;
1511 struct be_cmd_req_q_destroy
*req
;
1514 mutex_lock(&adapter
->mcc_lock
);
1516 wrb
= wrb_from_mccq(adapter
);
1521 req
= embedded_payload(wrb
);
1523 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
1524 OPCODE_ETH_RX_DESTROY
, sizeof(*req
), wrb
, NULL
);
1525 req
->id
= cpu_to_le16(q
->id
);
1527 status
= be_mcc_notify_wait(adapter
);
1531 mutex_unlock(&adapter
->mcc_lock
);
1535 /* Create an rx filtering policy configuration on an i/f
1536 * Will use MBOX only if MCCQ has not been created.
1538 int be_cmd_if_create(struct be_adapter
*adapter
, u32 cap_flags
, u32 en_flags
,
1539 u32
*if_handle
, u32 domain
)
1541 struct be_mcc_wrb wrb
= {0};
1542 struct be_cmd_req_if_create
*req
;
1545 req
= embedded_payload(&wrb
);
1546 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1547 OPCODE_COMMON_NTWK_INTERFACE_CREATE
,
1548 sizeof(*req
), &wrb
, NULL
);
1549 req
->hdr
.domain
= domain
;
1550 req
->capability_flags
= cpu_to_le32(cap_flags
);
1551 req
->enable_flags
= cpu_to_le32(en_flags
);
1552 req
->pmac_invalid
= true;
1554 status
= be_cmd_notify_wait(adapter
, &wrb
);
1556 struct be_cmd_resp_if_create
*resp
= embedded_payload(&wrb
);
1558 *if_handle
= le32_to_cpu(resp
->interface_id
);
1560 /* Hack to retrieve VF's pmac-id on BE3 */
1561 if (BE3_chip(adapter
) && be_virtfn(adapter
))
1562 adapter
->pmac_id
[0] = le32_to_cpu(resp
->pmac_id
);
1567 /* Uses MCCQ if available else MBOX */
1568 int be_cmd_if_destroy(struct be_adapter
*adapter
, int interface_id
, u32 domain
)
1570 struct be_mcc_wrb wrb
= {0};
1571 struct be_cmd_req_if_destroy
*req
;
1574 if (interface_id
== -1)
1577 req
= embedded_payload(&wrb
);
1579 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1580 OPCODE_COMMON_NTWK_INTERFACE_DESTROY
,
1581 sizeof(*req
), &wrb
, NULL
);
1582 req
->hdr
.domain
= domain
;
1583 req
->interface_id
= cpu_to_le32(interface_id
);
1585 status
= be_cmd_notify_wait(adapter
, &wrb
);
1589 /* Get stats is a non embedded command: the request is not embedded inside
1590 * WRB but is a separate dma memory block
1591 * Uses asynchronous MCC
1593 int be_cmd_get_stats(struct be_adapter
*adapter
, struct be_dma_mem
*nonemb_cmd
)
1595 struct be_mcc_wrb
*wrb
;
1596 struct be_cmd_req_hdr
*hdr
;
1599 mutex_lock(&adapter
->mcc_lock
);
1601 wrb
= wrb_from_mccq(adapter
);
1606 hdr
= nonemb_cmd
->va
;
1608 be_wrb_cmd_hdr_prepare(hdr
, CMD_SUBSYSTEM_ETH
,
1609 OPCODE_ETH_GET_STATISTICS
, nonemb_cmd
->size
, wrb
,
1612 /* version 1 of the cmd is not supported only by BE2 */
1613 if (BE2_chip(adapter
))
1615 if (BE3_chip(adapter
) || lancer_chip(adapter
))
1620 status
= be_mcc_notify(adapter
);
1624 adapter
->stats_cmd_sent
= true;
1627 mutex_unlock(&adapter
->mcc_lock
);
1632 int lancer_cmd_get_pport_stats(struct be_adapter
*adapter
,
1633 struct be_dma_mem
*nonemb_cmd
)
1635 struct be_mcc_wrb
*wrb
;
1636 struct lancer_cmd_req_pport_stats
*req
;
1639 if (!be_cmd_allowed(adapter
, OPCODE_ETH_GET_PPORT_STATS
,
1643 mutex_lock(&adapter
->mcc_lock
);
1645 wrb
= wrb_from_mccq(adapter
);
1650 req
= nonemb_cmd
->va
;
1652 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
1653 OPCODE_ETH_GET_PPORT_STATS
, nonemb_cmd
->size
,
1656 req
->cmd_params
.params
.pport_num
= cpu_to_le16(adapter
->hba_port_num
);
1657 req
->cmd_params
.params
.reset_stats
= 0;
1659 status
= be_mcc_notify(adapter
);
1663 adapter
->stats_cmd_sent
= true;
1666 mutex_unlock(&adapter
->mcc_lock
);
1670 static int be_mac_to_link_speed(int mac_speed
)
1672 switch (mac_speed
) {
1673 case PHY_LINK_SPEED_ZERO
:
1675 case PHY_LINK_SPEED_10MBPS
:
1677 case PHY_LINK_SPEED_100MBPS
:
1679 case PHY_LINK_SPEED_1GBPS
:
1681 case PHY_LINK_SPEED_10GBPS
:
1683 case PHY_LINK_SPEED_20GBPS
:
1685 case PHY_LINK_SPEED_25GBPS
:
1687 case PHY_LINK_SPEED_40GBPS
:
1693 /* Uses synchronous mcc
1694 * Returns link_speed in Mbps
1696 int be_cmd_link_status_query(struct be_adapter
*adapter
, u16
*link_speed
,
1697 u8
*link_status
, u32 dom
)
1699 struct be_mcc_wrb
*wrb
;
1700 struct be_cmd_req_link_status
*req
;
1703 mutex_lock(&adapter
->mcc_lock
);
1706 *link_status
= LINK_DOWN
;
1708 wrb
= wrb_from_mccq(adapter
);
1713 req
= embedded_payload(wrb
);
1715 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1716 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY
,
1717 sizeof(*req
), wrb
, NULL
);
1719 /* version 1 of the cmd is not supported only by BE2 */
1720 if (!BE2_chip(adapter
))
1721 req
->hdr
.version
= 1;
1723 req
->hdr
.domain
= dom
;
1725 status
= be_mcc_notify_wait(adapter
);
1727 struct be_cmd_resp_link_status
*resp
= embedded_payload(wrb
);
1730 *link_speed
= resp
->link_speed
?
1731 le16_to_cpu(resp
->link_speed
) * 10 :
1732 be_mac_to_link_speed(resp
->mac_speed
);
1734 if (!resp
->logical_link_status
)
1738 *link_status
= resp
->logical_link_status
;
1742 mutex_unlock(&adapter
->mcc_lock
);
1746 /* Uses synchronous mcc */
1747 int be_cmd_get_die_temperature(struct be_adapter
*adapter
)
1749 struct be_mcc_wrb
*wrb
;
1750 struct be_cmd_req_get_cntl_addnl_attribs
*req
;
1753 mutex_lock(&adapter
->mcc_lock
);
1755 wrb
= wrb_from_mccq(adapter
);
1760 req
= embedded_payload(wrb
);
1762 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1763 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES
,
1764 sizeof(*req
), wrb
, NULL
);
1766 status
= be_mcc_notify(adapter
);
1768 mutex_unlock(&adapter
->mcc_lock
);
1772 /* Uses synchronous mcc */
1773 int be_cmd_get_fat_dump_len(struct be_adapter
*adapter
, u32
*dump_size
)
1775 struct be_mcc_wrb wrb
= {0};
1776 struct be_cmd_req_get_fat
*req
;
1779 req
= embedded_payload(&wrb
);
1781 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1782 OPCODE_COMMON_MANAGE_FAT
, sizeof(*req
),
1784 req
->fat_operation
= cpu_to_le32(QUERY_FAT
);
1785 status
= be_cmd_notify_wait(adapter
, &wrb
);
1787 struct be_cmd_resp_get_fat
*resp
= embedded_payload(&wrb
);
1789 if (dump_size
&& resp
->log_size
)
1790 *dump_size
= le32_to_cpu(resp
->log_size
) -
1796 int be_cmd_get_fat_dump(struct be_adapter
*adapter
, u32 buf_len
, void *buf
)
1798 struct be_dma_mem get_fat_cmd
;
1799 struct be_mcc_wrb
*wrb
;
1800 struct be_cmd_req_get_fat
*req
;
1801 u32 offset
= 0, total_size
, buf_size
,
1802 log_offset
= sizeof(u32
), payload_len
;
1808 total_size
= buf_len
;
1810 get_fat_cmd
.size
= sizeof(struct be_cmd_req_get_fat
) + 60*1024;
1811 get_fat_cmd
.va
= dma_zalloc_coherent(&adapter
->pdev
->dev
,
1813 &get_fat_cmd
.dma
, GFP_ATOMIC
);
1814 if (!get_fat_cmd
.va
)
1817 mutex_lock(&adapter
->mcc_lock
);
1819 while (total_size
) {
1820 buf_size
= min(total_size
, (u32
)60*1024);
1821 total_size
-= buf_size
;
1823 wrb
= wrb_from_mccq(adapter
);
1828 req
= get_fat_cmd
.va
;
1830 payload_len
= sizeof(struct be_cmd_req_get_fat
) + buf_size
;
1831 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1832 OPCODE_COMMON_MANAGE_FAT
, payload_len
,
1835 req
->fat_operation
= cpu_to_le32(RETRIEVE_FAT
);
1836 req
->read_log_offset
= cpu_to_le32(log_offset
);
1837 req
->read_log_length
= cpu_to_le32(buf_size
);
1838 req
->data_buffer_size
= cpu_to_le32(buf_size
);
1840 status
= be_mcc_notify_wait(adapter
);
1842 struct be_cmd_resp_get_fat
*resp
= get_fat_cmd
.va
;
1844 memcpy(buf
+ offset
,
1846 le32_to_cpu(resp
->read_log_length
));
1848 dev_err(&adapter
->pdev
->dev
, "FAT Table Retrieve error\n");
1852 log_offset
+= buf_size
;
1855 dma_free_coherent(&adapter
->pdev
->dev
, get_fat_cmd
.size
,
1856 get_fat_cmd
.va
, get_fat_cmd
.dma
);
1857 mutex_unlock(&adapter
->mcc_lock
);
1861 /* Uses synchronous mcc */
1862 int be_cmd_get_fw_ver(struct be_adapter
*adapter
)
1864 struct be_mcc_wrb
*wrb
;
1865 struct be_cmd_req_get_fw_version
*req
;
1868 mutex_lock(&adapter
->mcc_lock
);
1870 wrb
= wrb_from_mccq(adapter
);
1876 req
= embedded_payload(wrb
);
1878 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1879 OPCODE_COMMON_GET_FW_VERSION
, sizeof(*req
), wrb
,
1881 status
= be_mcc_notify_wait(adapter
);
1883 struct be_cmd_resp_get_fw_version
*resp
= embedded_payload(wrb
);
1885 strlcpy(adapter
->fw_ver
, resp
->firmware_version_string
,
1886 sizeof(adapter
->fw_ver
));
1887 strlcpy(adapter
->fw_on_flash
, resp
->fw_on_flash_version_string
,
1888 sizeof(adapter
->fw_on_flash
));
1891 mutex_unlock(&adapter
->mcc_lock
);
1895 /* set the EQ delay interval of an EQ to specified value
1898 static int __be_cmd_modify_eqd(struct be_adapter
*adapter
,
1899 struct be_set_eqd
*set_eqd
, int num
)
1901 struct be_mcc_wrb
*wrb
;
1902 struct be_cmd_req_modify_eq_delay
*req
;
1905 mutex_lock(&adapter
->mcc_lock
);
1907 wrb
= wrb_from_mccq(adapter
);
1912 req
= embedded_payload(wrb
);
1914 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1915 OPCODE_COMMON_MODIFY_EQ_DELAY
, sizeof(*req
), wrb
,
1918 req
->num_eq
= cpu_to_le32(num
);
1919 for (i
= 0; i
< num
; i
++) {
1920 req
->set_eqd
[i
].eq_id
= cpu_to_le32(set_eqd
[i
].eq_id
);
1921 req
->set_eqd
[i
].phase
= 0;
1922 req
->set_eqd
[i
].delay_multiplier
=
1923 cpu_to_le32(set_eqd
[i
].delay_multiplier
);
1926 status
= be_mcc_notify(adapter
);
1928 mutex_unlock(&adapter
->mcc_lock
);
1932 int be_cmd_modify_eqd(struct be_adapter
*adapter
, struct be_set_eqd
*set_eqd
,
1938 num_eqs
= min(num
, 8);
1939 __be_cmd_modify_eqd(adapter
, &set_eqd
[i
], num_eqs
);
1947 /* Uses sycnhronous mcc */
1948 int be_cmd_vlan_config(struct be_adapter
*adapter
, u32 if_id
, u16
*vtag_array
,
1949 u32 num
, u32 domain
)
1951 struct be_mcc_wrb
*wrb
;
1952 struct be_cmd_req_vlan_config
*req
;
1955 mutex_lock(&adapter
->mcc_lock
);
1957 wrb
= wrb_from_mccq(adapter
);
1962 req
= embedded_payload(wrb
);
1964 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1965 OPCODE_COMMON_NTWK_VLAN_CONFIG
, sizeof(*req
),
1967 req
->hdr
.domain
= domain
;
1969 req
->interface_id
= if_id
;
1970 req
->untagged
= BE_IF_FLAGS_UNTAGGED
& be_if_cap_flags(adapter
) ? 1 : 0;
1971 req
->num_vlan
= num
;
1972 memcpy(req
->normal_vlan
, vtag_array
,
1973 req
->num_vlan
* sizeof(vtag_array
[0]));
1975 status
= be_mcc_notify_wait(adapter
);
1977 mutex_unlock(&adapter
->mcc_lock
);
1981 static int __be_cmd_rx_filter(struct be_adapter
*adapter
, u32 flags
, u32 value
)
1983 struct be_mcc_wrb
*wrb
;
1984 struct be_dma_mem
*mem
= &adapter
->rx_filter
;
1985 struct be_cmd_req_rx_filter
*req
= mem
->va
;
1988 mutex_lock(&adapter
->mcc_lock
);
1990 wrb
= wrb_from_mccq(adapter
);
1995 memset(req
, 0, sizeof(*req
));
1996 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
1997 OPCODE_COMMON_NTWK_RX_FILTER
, sizeof(*req
),
2000 req
->if_id
= cpu_to_le32(adapter
->if_handle
);
2001 req
->if_flags_mask
= cpu_to_le32(flags
);
2002 req
->if_flags
= (value
== ON
) ? req
->if_flags_mask
: 0;
2004 if (flags
& BE_IF_FLAGS_MULTICAST
) {
2007 /* Reset mcast promisc mode if already set by setting mask
2008 * and not setting flags field
2010 req
->if_flags_mask
|=
2011 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS
&
2012 be_if_cap_flags(adapter
));
2013 req
->mcast_num
= cpu_to_le32(adapter
->mc_count
);
2014 for (i
= 0; i
< adapter
->mc_count
; i
++)
2015 ether_addr_copy(req
->mcast_mac
[i
].byte
,
2016 adapter
->mc_list
[i
].mac
);
2019 status
= be_mcc_notify_wait(adapter
);
2021 mutex_unlock(&adapter
->mcc_lock
);
2025 int be_cmd_rx_filter(struct be_adapter
*adapter
, u32 flags
, u32 value
)
2027 struct device
*dev
= &adapter
->pdev
->dev
;
2029 if ((flags
& be_if_cap_flags(adapter
)) != flags
) {
2030 dev_warn(dev
, "Cannot set rx filter flags 0x%x\n", flags
);
2031 dev_warn(dev
, "Interface is capable of 0x%x flags only\n",
2032 be_if_cap_flags(adapter
));
2034 flags
&= be_if_cap_flags(adapter
);
2038 return __be_cmd_rx_filter(adapter
, flags
, value
);
2041 /* Uses synchrounous mcc */
2042 int be_cmd_set_flow_control(struct be_adapter
*adapter
, u32 tx_fc
, u32 rx_fc
)
2044 struct be_mcc_wrb
*wrb
;
2045 struct be_cmd_req_set_flow_control
*req
;
2048 if (!be_cmd_allowed(adapter
, OPCODE_COMMON_SET_FLOW_CONTROL
,
2049 CMD_SUBSYSTEM_COMMON
))
2052 mutex_lock(&adapter
->mcc_lock
);
2054 wrb
= wrb_from_mccq(adapter
);
2059 req
= embedded_payload(wrb
);
2061 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2062 OPCODE_COMMON_SET_FLOW_CONTROL
, sizeof(*req
),
2065 req
->hdr
.version
= 1;
2066 req
->tx_flow_control
= cpu_to_le16((u16
)tx_fc
);
2067 req
->rx_flow_control
= cpu_to_le16((u16
)rx_fc
);
2069 status
= be_mcc_notify_wait(adapter
);
2072 mutex_unlock(&adapter
->mcc_lock
);
2074 if (base_status(status
) == MCC_STATUS_FEATURE_NOT_SUPPORTED
)
2081 int be_cmd_get_flow_control(struct be_adapter
*adapter
, u32
*tx_fc
, u32
*rx_fc
)
2083 struct be_mcc_wrb
*wrb
;
2084 struct be_cmd_req_get_flow_control
*req
;
2087 if (!be_cmd_allowed(adapter
, OPCODE_COMMON_GET_FLOW_CONTROL
,
2088 CMD_SUBSYSTEM_COMMON
))
2091 mutex_lock(&adapter
->mcc_lock
);
2093 wrb
= wrb_from_mccq(adapter
);
2098 req
= embedded_payload(wrb
);
2100 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2101 OPCODE_COMMON_GET_FLOW_CONTROL
, sizeof(*req
),
2104 status
= be_mcc_notify_wait(adapter
);
2106 struct be_cmd_resp_get_flow_control
*resp
=
2107 embedded_payload(wrb
);
2109 *tx_fc
= le16_to_cpu(resp
->tx_flow_control
);
2110 *rx_fc
= le16_to_cpu(resp
->rx_flow_control
);
2114 mutex_unlock(&adapter
->mcc_lock
);
2119 int be_cmd_query_fw_cfg(struct be_adapter
*adapter
)
2121 struct be_mcc_wrb
*wrb
;
2122 struct be_cmd_req_query_fw_cfg
*req
;
2125 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
2128 wrb
= wrb_from_mbox(adapter
);
2129 req
= embedded_payload(wrb
);
2131 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2132 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG
,
2133 sizeof(*req
), wrb
, NULL
);
2135 status
= be_mbox_notify_wait(adapter
);
2137 struct be_cmd_resp_query_fw_cfg
*resp
= embedded_payload(wrb
);
2139 adapter
->port_num
= le32_to_cpu(resp
->phys_port
);
2140 adapter
->function_mode
= le32_to_cpu(resp
->function_mode
);
2141 adapter
->function_caps
= le32_to_cpu(resp
->function_caps
);
2142 adapter
->asic_rev
= le32_to_cpu(resp
->asic_revision
) & 0xFF;
2143 dev_info(&adapter
->pdev
->dev
,
2144 "FW config: function_mode=0x%x, function_caps=0x%x\n",
2145 adapter
->function_mode
, adapter
->function_caps
);
2148 mutex_unlock(&adapter
->mbox_lock
);
2153 int be_cmd_reset_function(struct be_adapter
*adapter
)
2155 struct be_mcc_wrb
*wrb
;
2156 struct be_cmd_req_hdr
*req
;
2159 if (lancer_chip(adapter
)) {
2160 iowrite32(SLI_PORT_CONTROL_IP_MASK
,
2161 adapter
->db
+ SLIPORT_CONTROL_OFFSET
);
2162 status
= lancer_wait_ready(adapter
);
2164 dev_err(&adapter
->pdev
->dev
,
2165 "Adapter in non recoverable error\n");
2169 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
2172 wrb
= wrb_from_mbox(adapter
);
2173 req
= embedded_payload(wrb
);
2175 be_wrb_cmd_hdr_prepare(req
, CMD_SUBSYSTEM_COMMON
,
2176 OPCODE_COMMON_FUNCTION_RESET
, sizeof(*req
), wrb
,
2179 status
= be_mbox_notify_wait(adapter
);
2181 mutex_unlock(&adapter
->mbox_lock
);
2185 int be_cmd_rss_config(struct be_adapter
*adapter
, u8
*rsstable
,
2186 u32 rss_hash_opts
, u16 table_size
, const u8
*rss_hkey
)
2188 struct be_mcc_wrb
*wrb
;
2189 struct be_cmd_req_rss_config
*req
;
2192 if (!(be_if_cap_flags(adapter
) & BE_IF_FLAGS_RSS
))
2195 mutex_lock(&adapter
->mcc_lock
);
2197 wrb
= wrb_from_mccq(adapter
);
2202 req
= embedded_payload(wrb
);
2204 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
2205 OPCODE_ETH_RSS_CONFIG
, sizeof(*req
), wrb
, NULL
);
2207 req
->if_id
= cpu_to_le32(adapter
->if_handle
);
2208 req
->enable_rss
= cpu_to_le16(rss_hash_opts
);
2209 req
->cpu_table_size_log2
= cpu_to_le16(fls(table_size
) - 1);
2211 if (!BEx_chip(adapter
))
2212 req
->hdr
.version
= 1;
2214 memcpy(req
->cpu_table
, rsstable
, table_size
);
2215 memcpy(req
->hash
, rss_hkey
, RSS_HASH_KEY_LEN
);
2216 be_dws_cpu_to_le(req
->hash
, sizeof(req
->hash
));
2218 status
= be_mcc_notify_wait(adapter
);
2220 mutex_unlock(&adapter
->mcc_lock
);
2225 int be_cmd_set_beacon_state(struct be_adapter
*adapter
, u8 port_num
,
2226 u8 bcn
, u8 sts
, u8 state
)
2228 struct be_mcc_wrb
*wrb
;
2229 struct be_cmd_req_enable_disable_beacon
*req
;
2232 mutex_lock(&adapter
->mcc_lock
);
2234 wrb
= wrb_from_mccq(adapter
);
2239 req
= embedded_payload(wrb
);
2241 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2242 OPCODE_COMMON_ENABLE_DISABLE_BEACON
,
2243 sizeof(*req
), wrb
, NULL
);
2245 req
->port_num
= port_num
;
2246 req
->beacon_state
= state
;
2247 req
->beacon_duration
= bcn
;
2248 req
->status_duration
= sts
;
2250 status
= be_mcc_notify_wait(adapter
);
2253 mutex_unlock(&adapter
->mcc_lock
);
2258 int be_cmd_get_beacon_state(struct be_adapter
*adapter
, u8 port_num
, u32
*state
)
2260 struct be_mcc_wrb
*wrb
;
2261 struct be_cmd_req_get_beacon_state
*req
;
2264 mutex_lock(&adapter
->mcc_lock
);
2266 wrb
= wrb_from_mccq(adapter
);
2271 req
= embedded_payload(wrb
);
2273 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2274 OPCODE_COMMON_GET_BEACON_STATE
, sizeof(*req
),
2277 req
->port_num
= port_num
;
2279 status
= be_mcc_notify_wait(adapter
);
2281 struct be_cmd_resp_get_beacon_state
*resp
=
2282 embedded_payload(wrb
);
2284 *state
= resp
->beacon_state
;
2288 mutex_unlock(&adapter
->mcc_lock
);
2293 int be_cmd_read_port_transceiver_data(struct be_adapter
*adapter
,
2294 u8 page_num
, u8
*data
)
2296 struct be_dma_mem cmd
;
2297 struct be_mcc_wrb
*wrb
;
2298 struct be_cmd_req_port_type
*req
;
2301 if (page_num
> TR_PAGE_A2
)
2304 cmd
.size
= sizeof(struct be_cmd_resp_port_type
);
2305 cmd
.va
= dma_zalloc_coherent(&adapter
->pdev
->dev
, cmd
.size
, &cmd
.dma
,
2308 dev_err(&adapter
->pdev
->dev
, "Memory allocation failed\n");
2312 mutex_lock(&adapter
->mcc_lock
);
2314 wrb
= wrb_from_mccq(adapter
);
2321 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2322 OPCODE_COMMON_READ_TRANSRECV_DATA
,
2323 cmd
.size
, wrb
, &cmd
);
2325 req
->port
= cpu_to_le32(adapter
->hba_port_num
);
2326 req
->page_num
= cpu_to_le32(page_num
);
2327 status
= be_mcc_notify_wait(adapter
);
2329 struct be_cmd_resp_port_type
*resp
= cmd
.va
;
2331 memcpy(data
, resp
->page_data
, PAGE_DATA_LEN
);
2334 mutex_unlock(&adapter
->mcc_lock
);
2335 dma_free_coherent(&adapter
->pdev
->dev
, cmd
.size
, cmd
.va
, cmd
.dma
);
2339 static int lancer_cmd_write_object(struct be_adapter
*adapter
,
2340 struct be_dma_mem
*cmd
, u32 data_size
,
2341 u32 data_offset
, const char *obj_name
,
2342 u32
*data_written
, u8
*change_status
,
2345 struct be_mcc_wrb
*wrb
;
2346 struct lancer_cmd_req_write_object
*req
;
2347 struct lancer_cmd_resp_write_object
*resp
;
2351 mutex_lock(&adapter
->mcc_lock
);
2352 adapter
->flash_status
= 0;
2354 wrb
= wrb_from_mccq(adapter
);
2360 req
= embedded_payload(wrb
);
2362 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2363 OPCODE_COMMON_WRITE_OBJECT
,
2364 sizeof(struct lancer_cmd_req_write_object
), wrb
,
2367 ctxt
= &req
->context
;
2368 AMAP_SET_BITS(struct amap_lancer_write_obj_context
,
2369 write_length
, ctxt
, data_size
);
2372 AMAP_SET_BITS(struct amap_lancer_write_obj_context
,
2375 AMAP_SET_BITS(struct amap_lancer_write_obj_context
,
2378 be_dws_cpu_to_le(ctxt
, sizeof(req
->context
));
2379 req
->write_offset
= cpu_to_le32(data_offset
);
2380 strlcpy(req
->object_name
, obj_name
, sizeof(req
->object_name
));
2381 req
->descriptor_count
= cpu_to_le32(1);
2382 req
->buf_len
= cpu_to_le32(data_size
);
2383 req
->addr_low
= cpu_to_le32((cmd
->dma
+
2384 sizeof(struct lancer_cmd_req_write_object
))
2386 req
->addr_high
= cpu_to_le32(upper_32_bits(cmd
->dma
+
2387 sizeof(struct lancer_cmd_req_write_object
)));
2389 status
= be_mcc_notify(adapter
);
2393 mutex_unlock(&adapter
->mcc_lock
);
2395 if (!wait_for_completion_timeout(&adapter
->et_cmd_compl
,
2396 msecs_to_jiffies(60000)))
2397 status
= -ETIMEDOUT
;
2399 status
= adapter
->flash_status
;
2401 resp
= embedded_payload(wrb
);
2403 *data_written
= le32_to_cpu(resp
->actual_write_len
);
2404 *change_status
= resp
->change_status
;
2406 *addn_status
= resp
->additional_status
;
2412 mutex_unlock(&adapter
->mcc_lock
);
2416 int be_cmd_query_cable_type(struct be_adapter
*adapter
)
2418 u8 page_data
[PAGE_DATA_LEN
];
2421 status
= be_cmd_read_port_transceiver_data(adapter
, TR_PAGE_A0
,
2424 switch (adapter
->phy
.interface_type
) {
2426 adapter
->phy
.cable_type
=
2427 page_data
[QSFP_PLUS_CABLE_TYPE_OFFSET
];
2429 case PHY_TYPE_SFP_PLUS_10GB
:
2430 adapter
->phy
.cable_type
=
2431 page_data
[SFP_PLUS_CABLE_TYPE_OFFSET
];
2434 adapter
->phy
.cable_type
= 0;
2441 int be_cmd_query_sfp_info(struct be_adapter
*adapter
)
2443 u8 page_data
[PAGE_DATA_LEN
];
2446 status
= be_cmd_read_port_transceiver_data(adapter
, TR_PAGE_A0
,
2449 strlcpy(adapter
->phy
.vendor_name
, page_data
+
2450 SFP_VENDOR_NAME_OFFSET
, SFP_VENDOR_NAME_LEN
- 1);
2451 strlcpy(adapter
->phy
.vendor_pn
,
2452 page_data
+ SFP_VENDOR_PN_OFFSET
,
2453 SFP_VENDOR_NAME_LEN
- 1);
2459 static int lancer_cmd_delete_object(struct be_adapter
*adapter
,
2460 const char *obj_name
)
2462 struct lancer_cmd_req_delete_object
*req
;
2463 struct be_mcc_wrb
*wrb
;
2466 mutex_lock(&adapter
->mcc_lock
);
2468 wrb
= wrb_from_mccq(adapter
);
2474 req
= embedded_payload(wrb
);
2476 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2477 OPCODE_COMMON_DELETE_OBJECT
,
2478 sizeof(*req
), wrb
, NULL
);
2480 strlcpy(req
->object_name
, obj_name
, sizeof(req
->object_name
));
2482 status
= be_mcc_notify_wait(adapter
);
2484 mutex_unlock(&adapter
->mcc_lock
);
2488 int lancer_cmd_read_object(struct be_adapter
*adapter
, struct be_dma_mem
*cmd
,
2489 u32 data_size
, u32 data_offset
, const char *obj_name
,
2490 u32
*data_read
, u32
*eof
, u8
*addn_status
)
2492 struct be_mcc_wrb
*wrb
;
2493 struct lancer_cmd_req_read_object
*req
;
2494 struct lancer_cmd_resp_read_object
*resp
;
2497 mutex_lock(&adapter
->mcc_lock
);
2499 wrb
= wrb_from_mccq(adapter
);
2505 req
= embedded_payload(wrb
);
2507 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2508 OPCODE_COMMON_READ_OBJECT
,
2509 sizeof(struct lancer_cmd_req_read_object
), wrb
,
2512 req
->desired_read_len
= cpu_to_le32(data_size
);
2513 req
->read_offset
= cpu_to_le32(data_offset
);
2514 strcpy(req
->object_name
, obj_name
);
2515 req
->descriptor_count
= cpu_to_le32(1);
2516 req
->buf_len
= cpu_to_le32(data_size
);
2517 req
->addr_low
= cpu_to_le32((cmd
->dma
& 0xFFFFFFFF));
2518 req
->addr_high
= cpu_to_le32(upper_32_bits(cmd
->dma
));
2520 status
= be_mcc_notify_wait(adapter
);
2522 resp
= embedded_payload(wrb
);
2524 *data_read
= le32_to_cpu(resp
->actual_read_len
);
2525 *eof
= le32_to_cpu(resp
->eof
);
2527 *addn_status
= resp
->additional_status
;
2531 mutex_unlock(&adapter
->mcc_lock
);
2535 static int be_cmd_write_flashrom(struct be_adapter
*adapter
,
2536 struct be_dma_mem
*cmd
, u32 flash_type
,
2537 u32 flash_opcode
, u32 img_offset
, u32 buf_size
)
2539 struct be_mcc_wrb
*wrb
;
2540 struct be_cmd_write_flashrom
*req
;
2543 mutex_lock(&adapter
->mcc_lock
);
2544 adapter
->flash_status
= 0;
2546 wrb
= wrb_from_mccq(adapter
);
2553 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2554 OPCODE_COMMON_WRITE_FLASHROM
, cmd
->size
, wrb
,
2557 req
->params
.op_type
= cpu_to_le32(flash_type
);
2558 if (flash_type
== OPTYPE_OFFSET_SPECIFIED
)
2559 req
->params
.offset
= cpu_to_le32(img_offset
);
2561 req
->params
.op_code
= cpu_to_le32(flash_opcode
);
2562 req
->params
.data_buf_size
= cpu_to_le32(buf_size
);
2564 status
= be_mcc_notify(adapter
);
2568 mutex_unlock(&adapter
->mcc_lock
);
2570 if (!wait_for_completion_timeout(&adapter
->et_cmd_compl
,
2571 msecs_to_jiffies(40000)))
2572 status
= -ETIMEDOUT
;
2574 status
= adapter
->flash_status
;
2579 mutex_unlock(&adapter
->mcc_lock
);
2583 static int be_cmd_get_flash_crc(struct be_adapter
*adapter
, u8
*flashed_crc
,
2584 u16 img_optype
, u32 img_offset
, u32 crc_offset
)
2586 struct be_cmd_read_flash_crc
*req
;
2587 struct be_mcc_wrb
*wrb
;
2590 mutex_lock(&adapter
->mcc_lock
);
2592 wrb
= wrb_from_mccq(adapter
);
2597 req
= embedded_payload(wrb
);
2599 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
2600 OPCODE_COMMON_READ_FLASHROM
, sizeof(*req
),
2603 req
->params
.op_type
= cpu_to_le32(img_optype
);
2604 if (img_optype
== OPTYPE_OFFSET_SPECIFIED
)
2605 req
->params
.offset
= cpu_to_le32(img_offset
+ crc_offset
);
2607 req
->params
.offset
= cpu_to_le32(crc_offset
);
2609 req
->params
.op_code
= cpu_to_le32(FLASHROM_OPER_REPORT
);
2610 req
->params
.data_buf_size
= cpu_to_le32(0x4);
2612 status
= be_mcc_notify_wait(adapter
);
2614 memcpy(flashed_crc
, req
->crc
, 4);
2617 mutex_unlock(&adapter
->mcc_lock
);
2621 static char flash_cookie
[2][16] = {"*** SE FLAS", "H DIRECTORY *** "};
2623 static bool phy_flashing_required(struct be_adapter
*adapter
)
2625 return (adapter
->phy
.phy_type
== PHY_TYPE_TN_8022
&&
2626 adapter
->phy
.interface_type
== PHY_TYPE_BASET_10GB
);
2629 static bool is_comp_in_ufi(struct be_adapter
*adapter
,
2630 struct flash_section_info
*fsec
, int type
)
2632 int i
= 0, img_type
= 0;
2633 struct flash_section_info_g2
*fsec_g2
= NULL
;
2635 if (BE2_chip(adapter
))
2636 fsec_g2
= (struct flash_section_info_g2
*)fsec
;
2638 for (i
= 0; i
< MAX_FLASH_COMP
; i
++) {
2640 img_type
= le32_to_cpu(fsec_g2
->fsec_entry
[i
].type
);
2642 img_type
= le32_to_cpu(fsec
->fsec_entry
[i
].type
);
2644 if (img_type
== type
)
2650 static struct flash_section_info
*get_fsec_info(struct be_adapter
*adapter
,
2652 const struct firmware
*fw
)
2654 struct flash_section_info
*fsec
= NULL
;
2655 const u8
*p
= fw
->data
;
2658 while (p
< (fw
->data
+ fw
->size
)) {
2659 fsec
= (struct flash_section_info
*)p
;
2660 if (!memcmp(flash_cookie
, fsec
->cookie
, sizeof(flash_cookie
)))
2667 static int be_check_flash_crc(struct be_adapter
*adapter
, const u8
*p
,
2668 u32 img_offset
, u32 img_size
, int hdr_size
,
2669 u16 img_optype
, bool *crc_match
)
2675 status
= be_cmd_get_flash_crc(adapter
, crc
, img_optype
, img_offset
,
2680 crc_offset
= hdr_size
+ img_offset
+ img_size
- 4;
2682 /* Skip flashing, if crc of flashed region matches */
2683 if (!memcmp(crc
, p
+ crc_offset
, 4))
2691 static int be_flash(struct be_adapter
*adapter
, const u8
*img
,
2692 struct be_dma_mem
*flash_cmd
, int optype
, int img_size
,
2695 u32 flash_op
, num_bytes
, total_bytes
= img_size
, bytes_sent
= 0;
2696 struct be_cmd_write_flashrom
*req
= flash_cmd
->va
;
2699 while (total_bytes
) {
2700 num_bytes
= min_t(u32
, 32 * 1024, total_bytes
);
2702 total_bytes
-= num_bytes
;
2705 if (optype
== OPTYPE_PHY_FW
)
2706 flash_op
= FLASHROM_OPER_PHY_FLASH
;
2708 flash_op
= FLASHROM_OPER_FLASH
;
2710 if (optype
== OPTYPE_PHY_FW
)
2711 flash_op
= FLASHROM_OPER_PHY_SAVE
;
2713 flash_op
= FLASHROM_OPER_SAVE
;
2716 memcpy(req
->data_buf
, img
, num_bytes
);
2718 status
= be_cmd_write_flashrom(adapter
, flash_cmd
, optype
,
2719 flash_op
, img_offset
+
2720 bytes_sent
, num_bytes
);
2721 if (base_status(status
) == MCC_STATUS_ILLEGAL_REQUEST
&&
2722 optype
== OPTYPE_PHY_FW
)
2727 bytes_sent
+= num_bytes
;
2732 #define NCSI_UPDATE_LOG "NCSI section update is not supported in FW ver %s\n"
2733 static bool be_fw_ncsi_supported(char *ver
)
2735 int v1
[4] = {3, 102, 148, 0}; /* Min ver that supports NCSI FW */
2739 if (sscanf(ver
, "%d.%d.%d.%d", &v2
[0], &v2
[1], &v2
[2], &v2
[3]) != 4)
2742 for (i
= 0; i
< 4; i
++) {
2745 else if (v1
[i
] > v2
[i
])
2752 /* For BE2, BE3 and BE3-R */
2753 static int be_flash_BEx(struct be_adapter
*adapter
,
2754 const struct firmware
*fw
,
2755 struct be_dma_mem
*flash_cmd
, int num_of_images
)
2757 int img_hdrs_size
= (num_of_images
* sizeof(struct image_hdr
));
2758 struct device
*dev
= &adapter
->pdev
->dev
;
2759 struct flash_section_info
*fsec
= NULL
;
2760 int status
, i
, filehdr_size
, num_comp
;
2761 const struct flash_comp
*pflashcomp
;
2765 struct flash_comp gen3_flash_types
[] = {
2766 { BE3_ISCSI_PRIMARY_IMAGE_START
, OPTYPE_ISCSI_ACTIVE
,
2767 BE3_COMP_MAX_SIZE
, IMAGE_FIRMWARE_ISCSI
},
2768 { BE3_REDBOOT_START
, OPTYPE_REDBOOT
,
2769 BE3_REDBOOT_COMP_MAX_SIZE
, IMAGE_BOOT_CODE
},
2770 { BE3_ISCSI_BIOS_START
, OPTYPE_BIOS
,
2771 BE3_BIOS_COMP_MAX_SIZE
, IMAGE_OPTION_ROM_ISCSI
},
2772 { BE3_PXE_BIOS_START
, OPTYPE_PXE_BIOS
,
2773 BE3_BIOS_COMP_MAX_SIZE
, IMAGE_OPTION_ROM_PXE
},
2774 { BE3_FCOE_BIOS_START
, OPTYPE_FCOE_BIOS
,
2775 BE3_BIOS_COMP_MAX_SIZE
, IMAGE_OPTION_ROM_FCOE
},
2776 { BE3_ISCSI_BACKUP_IMAGE_START
, OPTYPE_ISCSI_BACKUP
,
2777 BE3_COMP_MAX_SIZE
, IMAGE_FIRMWARE_BACKUP_ISCSI
},
2778 { BE3_FCOE_PRIMARY_IMAGE_START
, OPTYPE_FCOE_FW_ACTIVE
,
2779 BE3_COMP_MAX_SIZE
, IMAGE_FIRMWARE_FCOE
},
2780 { BE3_FCOE_BACKUP_IMAGE_START
, OPTYPE_FCOE_FW_BACKUP
,
2781 BE3_COMP_MAX_SIZE
, IMAGE_FIRMWARE_BACKUP_FCOE
},
2782 { BE3_NCSI_START
, OPTYPE_NCSI_FW
,
2783 BE3_NCSI_COMP_MAX_SIZE
, IMAGE_NCSI
},
2784 { BE3_PHY_FW_START
, OPTYPE_PHY_FW
,
2785 BE3_PHY_FW_COMP_MAX_SIZE
, IMAGE_FIRMWARE_PHY
}
2788 struct flash_comp gen2_flash_types
[] = {
2789 { BE2_ISCSI_PRIMARY_IMAGE_START
, OPTYPE_ISCSI_ACTIVE
,
2790 BE2_COMP_MAX_SIZE
, IMAGE_FIRMWARE_ISCSI
},
2791 { BE2_REDBOOT_START
, OPTYPE_REDBOOT
,
2792 BE2_REDBOOT_COMP_MAX_SIZE
, IMAGE_BOOT_CODE
},
2793 { BE2_ISCSI_BIOS_START
, OPTYPE_BIOS
,
2794 BE2_BIOS_COMP_MAX_SIZE
, IMAGE_OPTION_ROM_ISCSI
},
2795 { BE2_PXE_BIOS_START
, OPTYPE_PXE_BIOS
,
2796 BE2_BIOS_COMP_MAX_SIZE
, IMAGE_OPTION_ROM_PXE
},
2797 { BE2_FCOE_BIOS_START
, OPTYPE_FCOE_BIOS
,
2798 BE2_BIOS_COMP_MAX_SIZE
, IMAGE_OPTION_ROM_FCOE
},
2799 { BE2_ISCSI_BACKUP_IMAGE_START
, OPTYPE_ISCSI_BACKUP
,
2800 BE2_COMP_MAX_SIZE
, IMAGE_FIRMWARE_BACKUP_ISCSI
},
2801 { BE2_FCOE_PRIMARY_IMAGE_START
, OPTYPE_FCOE_FW_ACTIVE
,
2802 BE2_COMP_MAX_SIZE
, IMAGE_FIRMWARE_FCOE
},
2803 { BE2_FCOE_BACKUP_IMAGE_START
, OPTYPE_FCOE_FW_BACKUP
,
2804 BE2_COMP_MAX_SIZE
, IMAGE_FIRMWARE_BACKUP_FCOE
}
2807 if (BE3_chip(adapter
)) {
2808 pflashcomp
= gen3_flash_types
;
2809 filehdr_size
= sizeof(struct flash_file_hdr_g3
);
2810 num_comp
= ARRAY_SIZE(gen3_flash_types
);
2812 pflashcomp
= gen2_flash_types
;
2813 filehdr_size
= sizeof(struct flash_file_hdr_g2
);
2814 num_comp
= ARRAY_SIZE(gen2_flash_types
);
2818 /* Get flash section info*/
2819 fsec
= get_fsec_info(adapter
, filehdr_size
+ img_hdrs_size
, fw
);
2821 dev_err(dev
, "Invalid Cookie. FW image may be corrupted\n");
2824 for (i
= 0; i
< num_comp
; i
++) {
2825 if (!is_comp_in_ufi(adapter
, fsec
, pflashcomp
[i
].img_type
))
2828 if ((pflashcomp
[i
].optype
== OPTYPE_NCSI_FW
) &&
2829 !be_fw_ncsi_supported(adapter
->fw_ver
)) {
2830 dev_info(dev
, NCSI_UPDATE_LOG
, adapter
->fw_ver
);
2834 if (pflashcomp
[i
].optype
== OPTYPE_PHY_FW
&&
2835 !phy_flashing_required(adapter
))
2838 if (pflashcomp
[i
].optype
== OPTYPE_REDBOOT
) {
2839 status
= be_check_flash_crc(adapter
, fw
->data
,
2840 pflashcomp
[i
].offset
,
2844 OPTYPE_REDBOOT
, &crc_match
);
2847 "Could not get CRC for 0x%x region\n",
2848 pflashcomp
[i
].optype
);
2856 p
= fw
->data
+ filehdr_size
+ pflashcomp
[i
].offset
+
2858 if (p
+ pflashcomp
[i
].size
> fw
->data
+ fw
->size
)
2861 status
= be_flash(adapter
, p
, flash_cmd
, pflashcomp
[i
].optype
,
2862 pflashcomp
[i
].size
, 0);
2864 dev_err(dev
, "Flashing section type 0x%x failed\n",
2865 pflashcomp
[i
].img_type
);
2872 static u16
be_get_img_optype(struct flash_section_entry fsec_entry
)
2874 u32 img_type
= le32_to_cpu(fsec_entry
.type
);
2875 u16 img_optype
= le16_to_cpu(fsec_entry
.optype
);
2877 if (img_optype
!= 0xFFFF)
2881 case IMAGE_FIRMWARE_ISCSI
:
2882 img_optype
= OPTYPE_ISCSI_ACTIVE
;
2884 case IMAGE_BOOT_CODE
:
2885 img_optype
= OPTYPE_REDBOOT
;
2887 case IMAGE_OPTION_ROM_ISCSI
:
2888 img_optype
= OPTYPE_BIOS
;
2890 case IMAGE_OPTION_ROM_PXE
:
2891 img_optype
= OPTYPE_PXE_BIOS
;
2893 case IMAGE_OPTION_ROM_FCOE
:
2894 img_optype
= OPTYPE_FCOE_BIOS
;
2896 case IMAGE_FIRMWARE_BACKUP_ISCSI
:
2897 img_optype
= OPTYPE_ISCSI_BACKUP
;
2900 img_optype
= OPTYPE_NCSI_FW
;
2902 case IMAGE_FLASHISM_JUMPVECTOR
:
2903 img_optype
= OPTYPE_FLASHISM_JUMPVECTOR
;
2905 case IMAGE_FIRMWARE_PHY
:
2906 img_optype
= OPTYPE_SH_PHY_FW
;
2908 case IMAGE_REDBOOT_DIR
:
2909 img_optype
= OPTYPE_REDBOOT_DIR
;
2911 case IMAGE_REDBOOT_CONFIG
:
2912 img_optype
= OPTYPE_REDBOOT_CONFIG
;
2915 img_optype
= OPTYPE_UFI_DIR
;
2924 static int be_flash_skyhawk(struct be_adapter
*adapter
,
2925 const struct firmware
*fw
,
2926 struct be_dma_mem
*flash_cmd
, int num_of_images
)
2928 int img_hdrs_size
= num_of_images
* sizeof(struct image_hdr
);
2929 bool crc_match
, old_fw_img
, flash_offset_support
= true;
2930 struct device
*dev
= &adapter
->pdev
->dev
;
2931 struct flash_section_info
*fsec
= NULL
;
2932 u32 img_offset
, img_size
, img_type
;
2933 u16 img_optype
, flash_optype
;
2934 int status
, i
, filehdr_size
;
2937 filehdr_size
= sizeof(struct flash_file_hdr_g3
);
2938 fsec
= get_fsec_info(adapter
, filehdr_size
+ img_hdrs_size
, fw
);
2940 dev_err(dev
, "Invalid Cookie. FW image may be corrupted\n");
2945 for (i
= 0; i
< le32_to_cpu(fsec
->fsec_hdr
.num_images
); i
++) {
2946 img_offset
= le32_to_cpu(fsec
->fsec_entry
[i
].offset
);
2947 img_size
= le32_to_cpu(fsec
->fsec_entry
[i
].pad_size
);
2948 img_type
= le32_to_cpu(fsec
->fsec_entry
[i
].type
);
2949 img_optype
= be_get_img_optype(fsec
->fsec_entry
[i
]);
2950 old_fw_img
= fsec
->fsec_entry
[i
].optype
== 0xFFFF;
2952 if (img_optype
== 0xFFFF)
2955 if (flash_offset_support
)
2956 flash_optype
= OPTYPE_OFFSET_SPECIFIED
;
2958 flash_optype
= img_optype
;
2960 /* Don't bother verifying CRC if an old FW image is being
2966 status
= be_check_flash_crc(adapter
, fw
->data
, img_offset
,
2967 img_size
, filehdr_size
+
2968 img_hdrs_size
, flash_optype
,
2970 if (base_status(status
) == MCC_STATUS_ILLEGAL_REQUEST
||
2971 base_status(status
) == MCC_STATUS_ILLEGAL_FIELD
) {
2972 /* The current FW image on the card does not support
2973 * OFFSET based flashing. Retry using older mechanism
2974 * of OPTYPE based flashing
2976 if (flash_optype
== OPTYPE_OFFSET_SPECIFIED
) {
2977 flash_offset_support
= false;
2981 /* The current FW image on the card does not recognize
2982 * the new FLASH op_type. The FW download is partially
2983 * complete. Reboot the server now to enable FW image
2984 * to recognize the new FLASH op_type. To complete the
2985 * remaining process, download the same FW again after
2988 dev_err(dev
, "Flash incomplete. Reset the server\n");
2989 dev_err(dev
, "Download FW image again after reset\n");
2991 } else if (status
) {
2992 dev_err(dev
, "Could not get CRC for 0x%x region\n",
3001 p
= fw
->data
+ filehdr_size
+ img_offset
+ img_hdrs_size
;
3002 if (p
+ img_size
> fw
->data
+ fw
->size
)
3005 status
= be_flash(adapter
, p
, flash_cmd
, flash_optype
, img_size
,
3008 /* The current FW image on the card does not support OFFSET
3009 * based flashing. Retry using older mechanism of OPTYPE based
3012 if (base_status(status
) == MCC_STATUS_ILLEGAL_FIELD
&&
3013 flash_optype
== OPTYPE_OFFSET_SPECIFIED
) {
3014 flash_offset_support
= false;
3018 /* For old FW images ignore ILLEGAL_FIELD error or errors on
3022 (base_status(status
) == MCC_STATUS_ILLEGAL_FIELD
||
3023 (img_optype
== OPTYPE_UFI_DIR
&&
3024 base_status(status
) == MCC_STATUS_FAILED
))) {
3026 } else if (status
) {
3027 dev_err(dev
, "Flashing section type 0x%x failed\n",
3030 switch (addl_status(status
)) {
3031 case MCC_ADDL_STATUS_MISSING_SIGNATURE
:
3033 "Digital signature missing in FW\n");
3035 case MCC_ADDL_STATUS_INVALID_SIGNATURE
:
3037 "Invalid digital signature in FW\n");
3047 int lancer_fw_download(struct be_adapter
*adapter
,
3048 const struct firmware
*fw
)
3050 struct device
*dev
= &adapter
->pdev
->dev
;
3051 struct be_dma_mem flash_cmd
;
3052 const u8
*data_ptr
= NULL
;
3053 u8
*dest_image_ptr
= NULL
;
3054 size_t image_size
= 0;
3056 u32 data_written
= 0;
3062 if (!IS_ALIGNED(fw
->size
, sizeof(u32
))) {
3063 dev_err(dev
, "FW image size should be multiple of 4\n");
3067 flash_cmd
.size
= sizeof(struct lancer_cmd_req_write_object
)
3068 + LANCER_FW_DOWNLOAD_CHUNK
;
3069 flash_cmd
.va
= dma_zalloc_coherent(dev
, flash_cmd
.size
,
3070 &flash_cmd
.dma
, GFP_KERNEL
);
3074 dest_image_ptr
= flash_cmd
.va
+
3075 sizeof(struct lancer_cmd_req_write_object
);
3076 image_size
= fw
->size
;
3077 data_ptr
= fw
->data
;
3079 while (image_size
) {
3080 chunk_size
= min_t(u32
, image_size
, LANCER_FW_DOWNLOAD_CHUNK
);
3082 /* Copy the image chunk content. */
3083 memcpy(dest_image_ptr
, data_ptr
, chunk_size
);
3085 status
= lancer_cmd_write_object(adapter
, &flash_cmd
,
3087 LANCER_FW_DOWNLOAD_LOCATION
,
3088 &data_written
, &change_status
,
3093 offset
+= data_written
;
3094 data_ptr
+= data_written
;
3095 image_size
-= data_written
;
3099 /* Commit the FW written */
3100 status
= lancer_cmd_write_object(adapter
, &flash_cmd
,
3102 LANCER_FW_DOWNLOAD_LOCATION
,
3103 &data_written
, &change_status
,
3107 dma_free_coherent(dev
, flash_cmd
.size
, flash_cmd
.va
, flash_cmd
.dma
);
3109 dev_err(dev
, "Firmware load error\n");
3110 return be_cmd_status(status
);
3113 dev_info(dev
, "Firmware flashed successfully\n");
3115 if (change_status
== LANCER_FW_RESET_NEEDED
) {
3116 dev_info(dev
, "Resetting adapter to activate new FW\n");
3117 status
= lancer_physdev_ctrl(adapter
,
3118 PHYSDEV_CONTROL_FW_RESET_MASK
);
3120 dev_err(dev
, "Adapter busy, could not reset FW\n");
3121 dev_err(dev
, "Reboot server to activate new FW\n");
3123 } else if (change_status
!= LANCER_NO_RESET_NEEDED
) {
3124 dev_info(dev
, "Reboot server to activate new FW\n");
3130 /* Check if the flash image file is compatible with the adapter that
3133 static bool be_check_ufi_compatibility(struct be_adapter
*adapter
,
3134 struct flash_file_hdr_g3
*fhdr
)
3137 dev_err(&adapter
->pdev
->dev
, "Invalid FW UFI file");
3141 /* First letter of the build version is used to identify
3142 * which chip this image file is meant for.
3144 switch (fhdr
->build
[0]) {
3145 case BLD_STR_UFI_TYPE_SH
:
3146 if (!skyhawk_chip(adapter
))
3149 case BLD_STR_UFI_TYPE_BE3
:
3150 if (!BE3_chip(adapter
))
3153 case BLD_STR_UFI_TYPE_BE2
:
3154 if (!BE2_chip(adapter
))
3161 /* In BE3 FW images the "asic_type_rev" field doesn't track the
3162 * asic_rev of the chips it is compatible with.
3163 * When asic_type_rev is 0 the image is compatible only with
3164 * pre-BE3-R chips (asic_rev < 0x10)
3166 if (BEx_chip(adapter
) && fhdr
->asic_type_rev
== 0)
3167 return adapter
->asic_rev
< 0x10;
3169 return (fhdr
->asic_type_rev
>= adapter
->asic_rev
);
3172 int be_fw_download(struct be_adapter
*adapter
, const struct firmware
*fw
)
3174 struct device
*dev
= &adapter
->pdev
->dev
;
3175 struct flash_file_hdr_g3
*fhdr3
;
3176 struct image_hdr
*img_hdr_ptr
;
3177 int status
= 0, i
, num_imgs
;
3178 struct be_dma_mem flash_cmd
;
3180 fhdr3
= (struct flash_file_hdr_g3
*)fw
->data
;
3181 if (!be_check_ufi_compatibility(adapter
, fhdr3
)) {
3182 dev_err(dev
, "Flash image is not compatible with adapter\n");
3186 flash_cmd
.size
= sizeof(struct be_cmd_write_flashrom
);
3187 flash_cmd
.va
= dma_zalloc_coherent(dev
, flash_cmd
.size
, &flash_cmd
.dma
,
3192 num_imgs
= le32_to_cpu(fhdr3
->num_imgs
);
3193 for (i
= 0; i
< num_imgs
; i
++) {
3194 img_hdr_ptr
= (struct image_hdr
*)(fw
->data
+
3195 (sizeof(struct flash_file_hdr_g3
) +
3196 i
* sizeof(struct image_hdr
)));
3197 if (!BE2_chip(adapter
) &&
3198 le32_to_cpu(img_hdr_ptr
->imageid
) != 1)
3201 if (skyhawk_chip(adapter
))
3202 status
= be_flash_skyhawk(adapter
, fw
, &flash_cmd
,
3205 status
= be_flash_BEx(adapter
, fw
, &flash_cmd
,
3209 dma_free_coherent(dev
, flash_cmd
.size
, flash_cmd
.va
, flash_cmd
.dma
);
3211 dev_info(dev
, "Firmware flashed successfully\n");
3216 int be_cmd_enable_magic_wol(struct be_adapter
*adapter
, u8
*mac
,
3217 struct be_dma_mem
*nonemb_cmd
)
3219 struct be_mcc_wrb
*wrb
;
3220 struct be_cmd_req_acpi_wol_magic_config
*req
;
3223 mutex_lock(&adapter
->mcc_lock
);
3225 wrb
= wrb_from_mccq(adapter
);
3230 req
= nonemb_cmd
->va
;
3232 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
3233 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG
, sizeof(*req
),
3235 memcpy(req
->magic_mac
, mac
, ETH_ALEN
);
3237 status
= be_mcc_notify_wait(adapter
);
3240 mutex_unlock(&adapter
->mcc_lock
);
3244 int be_cmd_set_loopback(struct be_adapter
*adapter
, u8 port_num
,
3245 u8 loopback_type
, u8 enable
)
3247 struct be_mcc_wrb
*wrb
;
3248 struct be_cmd_req_set_lmode
*req
;
3251 if (!be_cmd_allowed(adapter
, OPCODE_LOWLEVEL_SET_LOOPBACK_MODE
,
3252 CMD_SUBSYSTEM_LOWLEVEL
))
3255 mutex_lock(&adapter
->mcc_lock
);
3257 wrb
= wrb_from_mccq(adapter
);
3263 req
= embedded_payload(wrb
);
3265 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
3266 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE
, sizeof(*req
),
3269 req
->src_port
= port_num
;
3270 req
->dest_port
= port_num
;
3271 req
->loopback_type
= loopback_type
;
3272 req
->loopback_state
= enable
;
3274 status
= be_mcc_notify(adapter
);
3278 mutex_unlock(&adapter
->mcc_lock
);
3280 if (!wait_for_completion_timeout(&adapter
->et_cmd_compl
,
3281 msecs_to_jiffies(SET_LB_MODE_TIMEOUT
)))
3282 status
= -ETIMEDOUT
;
3287 mutex_unlock(&adapter
->mcc_lock
);
3291 int be_cmd_loopback_test(struct be_adapter
*adapter
, u32 port_num
,
3292 u32 loopback_type
, u32 pkt_size
, u32 num_pkts
,
3295 struct be_mcc_wrb
*wrb
;
3296 struct be_cmd_req_loopback_test
*req
;
3297 struct be_cmd_resp_loopback_test
*resp
;
3300 if (!be_cmd_allowed(adapter
, OPCODE_LOWLEVEL_LOOPBACK_TEST
,
3301 CMD_SUBSYSTEM_LOWLEVEL
))
3304 mutex_lock(&adapter
->mcc_lock
);
3306 wrb
= wrb_from_mccq(adapter
);
3312 req
= embedded_payload(wrb
);
3314 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
3315 OPCODE_LOWLEVEL_LOOPBACK_TEST
, sizeof(*req
), wrb
,
3318 req
->hdr
.timeout
= cpu_to_le32(15);
3319 req
->pattern
= cpu_to_le64(pattern
);
3320 req
->src_port
= cpu_to_le32(port_num
);
3321 req
->dest_port
= cpu_to_le32(port_num
);
3322 req
->pkt_size
= cpu_to_le32(pkt_size
);
3323 req
->num_pkts
= cpu_to_le32(num_pkts
);
3324 req
->loopback_type
= cpu_to_le32(loopback_type
);
3326 status
= be_mcc_notify(adapter
);
3330 mutex_unlock(&adapter
->mcc_lock
);
3332 wait_for_completion(&adapter
->et_cmd_compl
);
3333 resp
= embedded_payload(wrb
);
3334 status
= le32_to_cpu(resp
->status
);
3338 mutex_unlock(&adapter
->mcc_lock
);
3342 int be_cmd_ddr_dma_test(struct be_adapter
*adapter
, u64 pattern
,
3343 u32 byte_cnt
, struct be_dma_mem
*cmd
)
3345 struct be_mcc_wrb
*wrb
;
3346 struct be_cmd_req_ddrdma_test
*req
;
3350 if (!be_cmd_allowed(adapter
, OPCODE_LOWLEVEL_HOST_DDR_DMA
,
3351 CMD_SUBSYSTEM_LOWLEVEL
))
3354 mutex_lock(&adapter
->mcc_lock
);
3356 wrb
= wrb_from_mccq(adapter
);
3362 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_LOWLEVEL
,
3363 OPCODE_LOWLEVEL_HOST_DDR_DMA
, cmd
->size
, wrb
,
3366 req
->pattern
= cpu_to_le64(pattern
);
3367 req
->byte_count
= cpu_to_le32(byte_cnt
);
3368 for (i
= 0; i
< byte_cnt
; i
++) {
3369 req
->snd_buff
[i
] = (u8
)(pattern
>> (j
*8));
3375 status
= be_mcc_notify_wait(adapter
);
3378 struct be_cmd_resp_ddrdma_test
*resp
;
3381 if ((memcmp(resp
->rcv_buff
, req
->snd_buff
, byte_cnt
) != 0) ||
3388 mutex_unlock(&adapter
->mcc_lock
);
3392 int be_cmd_get_seeprom_data(struct be_adapter
*adapter
,
3393 struct be_dma_mem
*nonemb_cmd
)
3395 struct be_mcc_wrb
*wrb
;
3396 struct be_cmd_req_seeprom_read
*req
;
3399 mutex_lock(&adapter
->mcc_lock
);
3401 wrb
= wrb_from_mccq(adapter
);
3406 req
= nonemb_cmd
->va
;
3408 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
3409 OPCODE_COMMON_SEEPROM_READ
, sizeof(*req
), wrb
,
3412 status
= be_mcc_notify_wait(adapter
);
3415 mutex_unlock(&adapter
->mcc_lock
);
3419 int be_cmd_get_phy_info(struct be_adapter
*adapter
)
3421 struct be_mcc_wrb
*wrb
;
3422 struct be_cmd_req_get_phy_info
*req
;
3423 struct be_dma_mem cmd
;
3426 if (!be_cmd_allowed(adapter
, OPCODE_COMMON_GET_PHY_DETAILS
,
3427 CMD_SUBSYSTEM_COMMON
))
3430 mutex_lock(&adapter
->mcc_lock
);
3432 wrb
= wrb_from_mccq(adapter
);
3437 cmd
.size
= sizeof(struct be_cmd_req_get_phy_info
);
3438 cmd
.va
= dma_zalloc_coherent(&adapter
->pdev
->dev
, cmd
.size
, &cmd
.dma
,
3441 dev_err(&adapter
->pdev
->dev
, "Memory alloc failure\n");
3448 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
3449 OPCODE_COMMON_GET_PHY_DETAILS
, sizeof(*req
),
3452 status
= be_mcc_notify_wait(adapter
);
3454 struct be_phy_info
*resp_phy_info
=
3455 cmd
.va
+ sizeof(struct be_cmd_req_hdr
);
3457 adapter
->phy
.phy_type
= le16_to_cpu(resp_phy_info
->phy_type
);
3458 adapter
->phy
.interface_type
=
3459 le16_to_cpu(resp_phy_info
->interface_type
);
3460 adapter
->phy
.auto_speeds_supported
=
3461 le16_to_cpu(resp_phy_info
->auto_speeds_supported
);
3462 adapter
->phy
.fixed_speeds_supported
=
3463 le16_to_cpu(resp_phy_info
->fixed_speeds_supported
);
3464 adapter
->phy
.misc_params
=
3465 le32_to_cpu(resp_phy_info
->misc_params
);
3467 if (BE2_chip(adapter
)) {
3468 adapter
->phy
.fixed_speeds_supported
=
3469 BE_SUPPORTED_SPEED_10GBPS
|
3470 BE_SUPPORTED_SPEED_1GBPS
;
3473 dma_free_coherent(&adapter
->pdev
->dev
, cmd
.size
, cmd
.va
, cmd
.dma
);
3475 mutex_unlock(&adapter
->mcc_lock
);
3479 static int be_cmd_set_qos(struct be_adapter
*adapter
, u32 bps
, u32 domain
)
3481 struct be_mcc_wrb
*wrb
;
3482 struct be_cmd_req_set_qos
*req
;
3485 mutex_lock(&adapter
->mcc_lock
);
3487 wrb
= wrb_from_mccq(adapter
);
3493 req
= embedded_payload(wrb
);
3495 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
3496 OPCODE_COMMON_SET_QOS
, sizeof(*req
), wrb
, NULL
);
3498 req
->hdr
.domain
= domain
;
3499 req
->valid_bits
= cpu_to_le32(BE_QOS_BITS_NIC
);
3500 req
->max_bps_nic
= cpu_to_le32(bps
);
3502 status
= be_mcc_notify_wait(adapter
);
3505 mutex_unlock(&adapter
->mcc_lock
);
3509 int be_cmd_get_cntl_attributes(struct be_adapter
*adapter
)
3511 struct be_mcc_wrb
*wrb
;
3512 struct be_cmd_req_cntl_attribs
*req
;
3513 struct be_cmd_resp_cntl_attribs
*resp
;
3515 int payload_len
= max(sizeof(*req
), sizeof(*resp
));
3516 struct mgmt_controller_attrib
*attribs
;
3517 struct be_dma_mem attribs_cmd
;
3520 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
3523 memset(&attribs_cmd
, 0, sizeof(struct be_dma_mem
));
3524 attribs_cmd
.size
= sizeof(struct be_cmd_resp_cntl_attribs
);
3525 attribs_cmd
.va
= dma_zalloc_coherent(&adapter
->pdev
->dev
,
3527 &attribs_cmd
.dma
, GFP_ATOMIC
);
3528 if (!attribs_cmd
.va
) {
3529 dev_err(&adapter
->pdev
->dev
, "Memory allocation failure\n");
3534 wrb
= wrb_from_mbox(adapter
);
3539 req
= attribs_cmd
.va
;
3541 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
3542 OPCODE_COMMON_GET_CNTL_ATTRIBUTES
, payload_len
,
3545 status
= be_mbox_notify_wait(adapter
);
3547 attribs
= attribs_cmd
.va
+ sizeof(struct be_cmd_resp_hdr
);
3548 adapter
->hba_port_num
= attribs
->hba_attribs
.phy_port
;
3549 serial_num
= attribs
->hba_attribs
.controller_serial_number
;
3550 for (i
= 0; i
< CNTL_SERIAL_NUM_WORDS
; i
++)
3551 adapter
->serial_num
[i
] = le32_to_cpu(serial_num
[i
]) &
3553 /* For BEx, since GET_FUNC_CONFIG command is not
3554 * supported, we read funcnum here as a workaround.
3556 if (BEx_chip(adapter
))
3557 adapter
->pf_num
= attribs
->hba_attribs
.pci_funcnum
;
3561 mutex_unlock(&adapter
->mbox_lock
);
3563 dma_free_coherent(&adapter
->pdev
->dev
, attribs_cmd
.size
,
3564 attribs_cmd
.va
, attribs_cmd
.dma
);
3569 int be_cmd_req_native_mode(struct be_adapter
*adapter
)
3571 struct be_mcc_wrb
*wrb
;
3572 struct be_cmd_req_set_func_cap
*req
;
3575 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
3578 wrb
= wrb_from_mbox(adapter
);
3584 req
= embedded_payload(wrb
);
3586 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
3587 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP
,
3588 sizeof(*req
), wrb
, NULL
);
3590 req
->valid_cap_flags
= cpu_to_le32(CAPABILITY_SW_TIMESTAMPS
|
3591 CAPABILITY_BE3_NATIVE_ERX_API
);
3592 req
->cap_flags
= cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API
);
3594 status
= be_mbox_notify_wait(adapter
);
3596 struct be_cmd_resp_set_func_cap
*resp
= embedded_payload(wrb
);
3598 adapter
->be3_native
= le32_to_cpu(resp
->cap_flags
) &
3599 CAPABILITY_BE3_NATIVE_ERX_API
;
3600 if (!adapter
->be3_native
)
3601 dev_warn(&adapter
->pdev
->dev
,
3602 "adapter not in advanced mode\n");
3605 mutex_unlock(&adapter
->mbox_lock
);
3609 /* Get privilege(s) for a function */
3610 int be_cmd_get_fn_privileges(struct be_adapter
*adapter
, u32
*privilege
,
3613 struct be_mcc_wrb
*wrb
;
3614 struct be_cmd_req_get_fn_privileges
*req
;
3617 mutex_lock(&adapter
->mcc_lock
);
3619 wrb
= wrb_from_mccq(adapter
);
3625 req
= embedded_payload(wrb
);
3627 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
3628 OPCODE_COMMON_GET_FN_PRIVILEGES
, sizeof(*req
),
3631 req
->hdr
.domain
= domain
;
3633 status
= be_mcc_notify_wait(adapter
);
3635 struct be_cmd_resp_get_fn_privileges
*resp
=
3636 embedded_payload(wrb
);
3638 *privilege
= le32_to_cpu(resp
->privilege_mask
);
3640 /* In UMC mode FW does not return right privileges.
3641 * Override with correct privilege equivalent to PF.
3643 if (BEx_chip(adapter
) && be_is_mc(adapter
) &&
3645 *privilege
= MAX_PRIVILEGES
;
3649 mutex_unlock(&adapter
->mcc_lock
);
3653 /* Set privilege(s) for a function */
3654 int be_cmd_set_fn_privileges(struct be_adapter
*adapter
, u32 privileges
,
3657 struct be_mcc_wrb
*wrb
;
3658 struct be_cmd_req_set_fn_privileges
*req
;
3661 mutex_lock(&adapter
->mcc_lock
);
3663 wrb
= wrb_from_mccq(adapter
);
3669 req
= embedded_payload(wrb
);
3670 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
3671 OPCODE_COMMON_SET_FN_PRIVILEGES
, sizeof(*req
),
3673 req
->hdr
.domain
= domain
;
3674 if (lancer_chip(adapter
))
3675 req
->privileges_lancer
= cpu_to_le32(privileges
);
3677 req
->privileges
= cpu_to_le32(privileges
);
3679 status
= be_mcc_notify_wait(adapter
);
3681 mutex_unlock(&adapter
->mcc_lock
);
3685 /* pmac_id_valid: true => pmac_id is supplied and MAC address is requested.
3686 * pmac_id_valid: false => pmac_id or MAC address is requested.
3687 * If pmac_id is returned, pmac_id_valid is returned as true
3689 int be_cmd_get_mac_from_list(struct be_adapter
*adapter
, u8
*mac
,
3690 bool *pmac_id_valid
, u32
*pmac_id
, u32 if_handle
,
3693 struct be_mcc_wrb
*wrb
;
3694 struct be_cmd_req_get_mac_list
*req
;
3697 struct be_dma_mem get_mac_list_cmd
;
3700 memset(&get_mac_list_cmd
, 0, sizeof(struct be_dma_mem
));
3701 get_mac_list_cmd
.size
= sizeof(struct be_cmd_resp_get_mac_list
);
3702 get_mac_list_cmd
.va
= dma_zalloc_coherent(&adapter
->pdev
->dev
,
3703 get_mac_list_cmd
.size
,
3704 &get_mac_list_cmd
.dma
,
3707 if (!get_mac_list_cmd
.va
) {
3708 dev_err(&adapter
->pdev
->dev
,
3709 "Memory allocation failure during GET_MAC_LIST\n");
3713 mutex_lock(&adapter
->mcc_lock
);
3715 wrb
= wrb_from_mccq(adapter
);
3721 req
= get_mac_list_cmd
.va
;
3723 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
3724 OPCODE_COMMON_GET_MAC_LIST
,
3725 get_mac_list_cmd
.size
, wrb
, &get_mac_list_cmd
);
3726 req
->hdr
.domain
= domain
;
3727 req
->mac_type
= MAC_ADDRESS_TYPE_NETWORK
;
3728 if (*pmac_id_valid
) {
3729 req
->mac_id
= cpu_to_le32(*pmac_id
);
3730 req
->iface_id
= cpu_to_le16(if_handle
);
3731 req
->perm_override
= 0;
3733 req
->perm_override
= 1;
3736 status
= be_mcc_notify_wait(adapter
);
3738 struct be_cmd_resp_get_mac_list
*resp
=
3739 get_mac_list_cmd
.va
;
3741 if (*pmac_id_valid
) {
3742 memcpy(mac
, resp
->macid_macaddr
.mac_addr_id
.macaddr
,
3747 mac_count
= resp
->true_mac_count
+ resp
->pseudo_mac_count
;
3748 /* Mac list returned could contain one or more active mac_ids
3749 * or one or more true or pseudo permanent mac addresses.
3750 * If an active mac_id is present, return first active mac_id
3753 for (i
= 0; i
< mac_count
; i
++) {
3754 struct get_list_macaddr
*mac_entry
;
3758 mac_entry
= &resp
->macaddr_list
[i
];
3759 mac_addr_size
= le16_to_cpu(mac_entry
->mac_addr_size
);
3760 /* mac_id is a 32 bit value and mac_addr size
3763 if (mac_addr_size
== sizeof(u32
)) {
3764 *pmac_id_valid
= true;
3765 mac_id
= mac_entry
->mac_addr_id
.s_mac_id
.mac_id
;
3766 *pmac_id
= le32_to_cpu(mac_id
);
3770 /* If no active mac_id found, return first mac addr */
3771 *pmac_id_valid
= false;
3772 memcpy(mac
, resp
->macaddr_list
[0].mac_addr_id
.macaddr
,
3777 mutex_unlock(&adapter
->mcc_lock
);
3778 dma_free_coherent(&adapter
->pdev
->dev
, get_mac_list_cmd
.size
,
3779 get_mac_list_cmd
.va
, get_mac_list_cmd
.dma
);
3783 int be_cmd_get_active_mac(struct be_adapter
*adapter
, u32 curr_pmac_id
,
3784 u8
*mac
, u32 if_handle
, bool active
, u32 domain
)
3787 be_cmd_get_mac_from_list(adapter
, mac
, &active
, &curr_pmac_id
,
3789 if (BEx_chip(adapter
))
3790 return be_cmd_mac_addr_query(adapter
, mac
, false,
3791 if_handle
, curr_pmac_id
);
3793 /* Fetch the MAC address using pmac_id */
3794 return be_cmd_get_mac_from_list(adapter
, mac
, &active
,
3799 int be_cmd_get_perm_mac(struct be_adapter
*adapter
, u8
*mac
)
3802 bool pmac_valid
= false;
3806 if (BEx_chip(adapter
)) {
3807 if (be_physfn(adapter
))
3808 status
= be_cmd_mac_addr_query(adapter
, mac
, true, 0,
3811 status
= be_cmd_mac_addr_query(adapter
, mac
, false,
3812 adapter
->if_handle
, 0);
3814 status
= be_cmd_get_mac_from_list(adapter
, mac
, &pmac_valid
,
3815 NULL
, adapter
->if_handle
, 0);
3821 /* Uses synchronous MCCQ */
3822 int be_cmd_set_mac_list(struct be_adapter
*adapter
, u8
*mac_array
,
3823 u8 mac_count
, u32 domain
)
3825 struct be_mcc_wrb
*wrb
;
3826 struct be_cmd_req_set_mac_list
*req
;
3828 struct be_dma_mem cmd
;
3830 memset(&cmd
, 0, sizeof(struct be_dma_mem
));
3831 cmd
.size
= sizeof(struct be_cmd_req_set_mac_list
);
3832 cmd
.va
= dma_zalloc_coherent(&adapter
->pdev
->dev
, cmd
.size
, &cmd
.dma
,
3837 mutex_lock(&adapter
->mcc_lock
);
3839 wrb
= wrb_from_mccq(adapter
);
3846 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
3847 OPCODE_COMMON_SET_MAC_LIST
, sizeof(*req
),
3850 req
->hdr
.domain
= domain
;
3851 req
->mac_count
= mac_count
;
3853 memcpy(req
->mac
, mac_array
, ETH_ALEN
*mac_count
);
3855 status
= be_mcc_notify_wait(adapter
);
3858 dma_free_coherent(&adapter
->pdev
->dev
, cmd
.size
, cmd
.va
, cmd
.dma
);
3859 mutex_unlock(&adapter
->mcc_lock
);
3863 /* Wrapper to delete any active MACs and provision the new mac.
3864 * Changes to MAC_LIST are allowed iff none of the MAC addresses in the
3865 * current list are active.
3867 int be_cmd_set_mac(struct be_adapter
*adapter
, u8
*mac
, int if_id
, u32 dom
)
3869 bool active_mac
= false;
3870 u8 old_mac
[ETH_ALEN
];
3874 status
= be_cmd_get_mac_from_list(adapter
, old_mac
, &active_mac
,
3875 &pmac_id
, if_id
, dom
);
3877 if (!status
&& active_mac
)
3878 be_cmd_pmac_del(adapter
, if_id
, pmac_id
, dom
);
3880 return be_cmd_set_mac_list(adapter
, mac
, mac
? 1 : 0, dom
);
3883 int be_cmd_set_hsw_config(struct be_adapter
*adapter
, u16 pvid
,
3884 u32 domain
, u16 intf_id
, u16 hsw_mode
, u8 spoofchk
)
3886 struct be_mcc_wrb
*wrb
;
3887 struct be_cmd_req_set_hsw_config
*req
;
3891 if (!be_cmd_allowed(adapter
, OPCODE_COMMON_SET_HSW_CONFIG
,
3892 CMD_SUBSYSTEM_COMMON
))
3895 mutex_lock(&adapter
->mcc_lock
);
3897 wrb
= wrb_from_mccq(adapter
);
3903 req
= embedded_payload(wrb
);
3904 ctxt
= &req
->context
;
3906 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
3907 OPCODE_COMMON_SET_HSW_CONFIG
, sizeof(*req
), wrb
,
3910 req
->hdr
.domain
= domain
;
3911 AMAP_SET_BITS(struct amap_set_hsw_context
, interface_id
, ctxt
, intf_id
);
3913 AMAP_SET_BITS(struct amap_set_hsw_context
, pvid_valid
, ctxt
, 1);
3914 AMAP_SET_BITS(struct amap_set_hsw_context
, pvid
, ctxt
, pvid
);
3917 AMAP_SET_BITS(struct amap_set_hsw_context
, interface_id
,
3918 ctxt
, adapter
->hba_port_num
);
3919 AMAP_SET_BITS(struct amap_set_hsw_context
, pport
, ctxt
, 1);
3920 AMAP_SET_BITS(struct amap_set_hsw_context
, port_fwd_type
,
3924 /* Enable/disable both mac and vlan spoof checking */
3925 if (!BEx_chip(adapter
) && spoofchk
) {
3926 AMAP_SET_BITS(struct amap_set_hsw_context
, mac_spoofchk
,
3928 AMAP_SET_BITS(struct amap_set_hsw_context
, vlan_spoofchk
,
3932 be_dws_cpu_to_le(req
->context
, sizeof(req
->context
));
3933 status
= be_mcc_notify_wait(adapter
);
3936 mutex_unlock(&adapter
->mcc_lock
);
3940 /* Get Hyper switch config */
3941 int be_cmd_get_hsw_config(struct be_adapter
*adapter
, u16
*pvid
,
3942 u32 domain
, u16 intf_id
, u8
*mode
, bool *spoofchk
)
3944 struct be_mcc_wrb
*wrb
;
3945 struct be_cmd_req_get_hsw_config
*req
;
3950 mutex_lock(&adapter
->mcc_lock
);
3952 wrb
= wrb_from_mccq(adapter
);
3958 req
= embedded_payload(wrb
);
3959 ctxt
= &req
->context
;
3961 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
3962 OPCODE_COMMON_GET_HSW_CONFIG
, sizeof(*req
), wrb
,
3965 req
->hdr
.domain
= domain
;
3966 AMAP_SET_BITS(struct amap_get_hsw_req_context
, interface_id
,
3968 AMAP_SET_BITS(struct amap_get_hsw_req_context
, pvid_valid
, ctxt
, 1);
3970 if (!BEx_chip(adapter
) && mode
) {
3971 AMAP_SET_BITS(struct amap_get_hsw_req_context
, interface_id
,
3972 ctxt
, adapter
->hba_port_num
);
3973 AMAP_SET_BITS(struct amap_get_hsw_req_context
, pport
, ctxt
, 1);
3975 be_dws_cpu_to_le(req
->context
, sizeof(req
->context
));
3977 status
= be_mcc_notify_wait(adapter
);
3979 struct be_cmd_resp_get_hsw_config
*resp
=
3980 embedded_payload(wrb
);
3982 be_dws_le_to_cpu(&resp
->context
, sizeof(resp
->context
));
3983 vid
= AMAP_GET_BITS(struct amap_get_hsw_resp_context
,
3984 pvid
, &resp
->context
);
3986 *pvid
= le16_to_cpu(vid
);
3988 *mode
= AMAP_GET_BITS(struct amap_get_hsw_resp_context
,
3989 port_fwd_type
, &resp
->context
);
3992 AMAP_GET_BITS(struct amap_get_hsw_resp_context
,
3993 spoofchk
, &resp
->context
);
3997 mutex_unlock(&adapter
->mcc_lock
);
4001 static bool be_is_wol_excluded(struct be_adapter
*adapter
)
4003 struct pci_dev
*pdev
= adapter
->pdev
;
4005 if (be_virtfn(adapter
))
4008 switch (pdev
->subsystem_device
) {
4009 case OC_SUBSYS_DEVICE_ID1
:
4010 case OC_SUBSYS_DEVICE_ID2
:
4011 case OC_SUBSYS_DEVICE_ID3
:
4012 case OC_SUBSYS_DEVICE_ID4
:
4019 int be_cmd_get_acpi_wol_cap(struct be_adapter
*adapter
)
4021 struct be_mcc_wrb
*wrb
;
4022 struct be_cmd_req_acpi_wol_magic_config_v1
*req
;
4024 struct be_dma_mem cmd
;
4026 if (!be_cmd_allowed(adapter
, OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG
,
4030 if (be_is_wol_excluded(adapter
))
4033 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
4036 memset(&cmd
, 0, sizeof(struct be_dma_mem
));
4037 cmd
.size
= sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1
);
4038 cmd
.va
= dma_zalloc_coherent(&adapter
->pdev
->dev
, cmd
.size
, &cmd
.dma
,
4041 dev_err(&adapter
->pdev
->dev
, "Memory allocation failure\n");
4046 wrb
= wrb_from_mbox(adapter
);
4054 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ETH
,
4055 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG
,
4056 sizeof(*req
), wrb
, &cmd
);
4058 req
->hdr
.version
= 1;
4059 req
->query_options
= BE_GET_WOL_CAP
;
4061 status
= be_mbox_notify_wait(adapter
);
4063 struct be_cmd_resp_acpi_wol_magic_config_v1
*resp
;
4065 resp
= (struct be_cmd_resp_acpi_wol_magic_config_v1
*)cmd
.va
;
4067 adapter
->wol_cap
= resp
->wol_settings
;
4069 /* Non-zero macaddr indicates WOL is enabled */
4070 if (adapter
->wol_cap
& BE_WOL_CAP
&&
4071 !is_zero_ether_addr(resp
->magic_mac
))
4072 adapter
->wol_en
= true;
4075 mutex_unlock(&adapter
->mbox_lock
);
4077 dma_free_coherent(&adapter
->pdev
->dev
, cmd
.size
, cmd
.va
,
4083 int be_cmd_set_fw_log_level(struct be_adapter
*adapter
, u32 level
)
4085 struct be_dma_mem extfat_cmd
;
4086 struct be_fat_conf_params
*cfgs
;
4090 memset(&extfat_cmd
, 0, sizeof(struct be_dma_mem
));
4091 extfat_cmd
.size
= sizeof(struct be_cmd_resp_get_ext_fat_caps
);
4092 extfat_cmd
.va
= dma_zalloc_coherent(&adapter
->pdev
->dev
,
4093 extfat_cmd
.size
, &extfat_cmd
.dma
,
4098 status
= be_cmd_get_ext_fat_capabilites(adapter
, &extfat_cmd
);
4102 cfgs
= (struct be_fat_conf_params
*)
4103 (extfat_cmd
.va
+ sizeof(struct be_cmd_resp_hdr
));
4104 for (i
= 0; i
< le32_to_cpu(cfgs
->num_modules
); i
++) {
4105 u32 num_modes
= le32_to_cpu(cfgs
->module
[i
].num_modes
);
4107 for (j
= 0; j
< num_modes
; j
++) {
4108 if (cfgs
->module
[i
].trace_lvl
[j
].mode
== MODE_UART
)
4109 cfgs
->module
[i
].trace_lvl
[j
].dbg_lvl
=
4114 status
= be_cmd_set_ext_fat_capabilites(adapter
, &extfat_cmd
, cfgs
);
4116 dma_free_coherent(&adapter
->pdev
->dev
, extfat_cmd
.size
, extfat_cmd
.va
,
4121 int be_cmd_get_fw_log_level(struct be_adapter
*adapter
)
4123 struct be_dma_mem extfat_cmd
;
4124 struct be_fat_conf_params
*cfgs
;
4128 memset(&extfat_cmd
, 0, sizeof(struct be_dma_mem
));
4129 extfat_cmd
.size
= sizeof(struct be_cmd_resp_get_ext_fat_caps
);
4130 extfat_cmd
.va
= dma_zalloc_coherent(&adapter
->pdev
->dev
,
4131 extfat_cmd
.size
, &extfat_cmd
.dma
,
4134 if (!extfat_cmd
.va
) {
4135 dev_err(&adapter
->pdev
->dev
, "%s: Memory allocation failure\n",
4140 status
= be_cmd_get_ext_fat_capabilites(adapter
, &extfat_cmd
);
4142 cfgs
= (struct be_fat_conf_params
*)(extfat_cmd
.va
+
4143 sizeof(struct be_cmd_resp_hdr
));
4145 for (j
= 0; j
< le32_to_cpu(cfgs
->module
[0].num_modes
); j
++) {
4146 if (cfgs
->module
[0].trace_lvl
[j
].mode
== MODE_UART
)
4147 level
= cfgs
->module
[0].trace_lvl
[j
].dbg_lvl
;
4150 dma_free_coherent(&adapter
->pdev
->dev
, extfat_cmd
.size
, extfat_cmd
.va
,
4156 int be_cmd_get_ext_fat_capabilites(struct be_adapter
*adapter
,
4157 struct be_dma_mem
*cmd
)
4159 struct be_mcc_wrb
*wrb
;
4160 struct be_cmd_req_get_ext_fat_caps
*req
;
4163 if (!be_cmd_allowed(adapter
, OPCODE_COMMON_GET_EXT_FAT_CAPABILITIES
,
4164 CMD_SUBSYSTEM_COMMON
))
4167 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
4170 wrb
= wrb_from_mbox(adapter
);
4177 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
4178 OPCODE_COMMON_GET_EXT_FAT_CAPABILITIES
,
4179 cmd
->size
, wrb
, cmd
);
4180 req
->parameter_type
= cpu_to_le32(1);
4182 status
= be_mbox_notify_wait(adapter
);
4184 mutex_unlock(&adapter
->mbox_lock
);
4188 int be_cmd_set_ext_fat_capabilites(struct be_adapter
*adapter
,
4189 struct be_dma_mem
*cmd
,
4190 struct be_fat_conf_params
*configs
)
4192 struct be_mcc_wrb
*wrb
;
4193 struct be_cmd_req_set_ext_fat_caps
*req
;
4196 mutex_lock(&adapter
->mcc_lock
);
4198 wrb
= wrb_from_mccq(adapter
);
4205 memcpy(&req
->set_params
, configs
, sizeof(struct be_fat_conf_params
));
4206 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
4207 OPCODE_COMMON_SET_EXT_FAT_CAPABILITIES
,
4208 cmd
->size
, wrb
, cmd
);
4210 status
= be_mcc_notify_wait(adapter
);
4212 mutex_unlock(&adapter
->mcc_lock
);
4216 int be_cmd_query_port_name(struct be_adapter
*adapter
)
4218 struct be_cmd_req_get_port_name
*req
;
4219 struct be_mcc_wrb
*wrb
;
4222 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
4225 wrb
= wrb_from_mbox(adapter
);
4226 req
= embedded_payload(wrb
);
4228 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
4229 OPCODE_COMMON_GET_PORT_NAME
, sizeof(*req
), wrb
,
4231 if (!BEx_chip(adapter
))
4232 req
->hdr
.version
= 1;
4234 status
= be_mbox_notify_wait(adapter
);
4236 struct be_cmd_resp_get_port_name
*resp
= embedded_payload(wrb
);
4238 adapter
->port_name
= resp
->port_name
[adapter
->hba_port_num
];
4240 adapter
->port_name
= adapter
->hba_port_num
+ '0';
4243 mutex_unlock(&adapter
->mbox_lock
);
4247 /* When more than 1 NIC descriptor is present in the descriptor list,
4248 * the caller must specify the pf_num to obtain the NIC descriptor
4249 * corresponding to its pci function.
4250 * get_vft must be true when the caller wants the VF-template desc of the
4252 * The pf_num should be set to PF_NUM_IGNORE when the caller knows
4253 * that only it's NIC descriptor is present in the descriptor list.
4255 static struct be_nic_res_desc
*be_get_nic_desc(u8
*buf
, u32 desc_count
,
4256 bool get_vft
, u8 pf_num
)
4258 struct be_res_desc_hdr
*hdr
= (struct be_res_desc_hdr
*)buf
;
4259 struct be_nic_res_desc
*nic
;
4262 for (i
= 0; i
< desc_count
; i
++) {
4263 if (hdr
->desc_type
== NIC_RESOURCE_DESC_TYPE_V0
||
4264 hdr
->desc_type
== NIC_RESOURCE_DESC_TYPE_V1
) {
4265 nic
= (struct be_nic_res_desc
*)hdr
;
4267 if ((pf_num
== PF_NUM_IGNORE
||
4268 nic
->pf_num
== pf_num
) &&
4269 (!get_vft
|| nic
->flags
& BIT(VFT_SHIFT
)))
4272 hdr
->desc_len
= hdr
->desc_len
? : RESOURCE_DESC_SIZE_V0
;
4273 hdr
= (void *)hdr
+ hdr
->desc_len
;
4278 static struct be_nic_res_desc
*be_get_vft_desc(u8
*buf
, u32 desc_count
,
4281 return be_get_nic_desc(buf
, desc_count
, true, pf_num
);
4284 static struct be_nic_res_desc
*be_get_func_nic_desc(u8
*buf
, u32 desc_count
,
4287 return be_get_nic_desc(buf
, desc_count
, false, pf_num
);
4290 static struct be_pcie_res_desc
*be_get_pcie_desc(u8
*buf
, u32 desc_count
,
4293 struct be_res_desc_hdr
*hdr
= (struct be_res_desc_hdr
*)buf
;
4294 struct be_pcie_res_desc
*pcie
;
4297 for (i
= 0; i
< desc_count
; i
++) {
4298 if (hdr
->desc_type
== PCIE_RESOURCE_DESC_TYPE_V0
||
4299 hdr
->desc_type
== PCIE_RESOURCE_DESC_TYPE_V1
) {
4300 pcie
= (struct be_pcie_res_desc
*)hdr
;
4301 if (pcie
->pf_num
== pf_num
)
4305 hdr
->desc_len
= hdr
->desc_len
? : RESOURCE_DESC_SIZE_V0
;
4306 hdr
= (void *)hdr
+ hdr
->desc_len
;
4311 static struct be_port_res_desc
*be_get_port_desc(u8
*buf
, u32 desc_count
)
4313 struct be_res_desc_hdr
*hdr
= (struct be_res_desc_hdr
*)buf
;
4316 for (i
= 0; i
< desc_count
; i
++) {
4317 if (hdr
->desc_type
== PORT_RESOURCE_DESC_TYPE_V1
)
4318 return (struct be_port_res_desc
*)hdr
;
4320 hdr
->desc_len
= hdr
->desc_len
? : RESOURCE_DESC_SIZE_V0
;
4321 hdr
= (void *)hdr
+ hdr
->desc_len
;
4326 static void be_copy_nic_desc(struct be_resources
*res
,
4327 struct be_nic_res_desc
*desc
)
4329 res
->max_uc_mac
= le16_to_cpu(desc
->unicast_mac_count
);
4330 res
->max_vlans
= le16_to_cpu(desc
->vlan_count
);
4331 res
->max_mcast_mac
= le16_to_cpu(desc
->mcast_mac_count
);
4332 res
->max_tx_qs
= le16_to_cpu(desc
->txq_count
);
4333 res
->max_rss_qs
= le16_to_cpu(desc
->rssq_count
);
4334 res
->max_rx_qs
= le16_to_cpu(desc
->rq_count
);
4335 res
->max_evt_qs
= le16_to_cpu(desc
->eq_count
);
4336 res
->max_cq_count
= le16_to_cpu(desc
->cq_count
);
4337 res
->max_iface_count
= le16_to_cpu(desc
->iface_count
);
4338 res
->max_mcc_count
= le16_to_cpu(desc
->mcc_count
);
4339 /* Clear flags that driver is not interested in */
4340 res
->if_cap_flags
= le32_to_cpu(desc
->cap_flags
) &
4341 BE_IF_CAP_FLAGS_WANT
;
4345 int be_cmd_get_func_config(struct be_adapter
*adapter
, struct be_resources
*res
)
4347 struct be_mcc_wrb
*wrb
;
4348 struct be_cmd_req_get_func_config
*req
;
4350 struct be_dma_mem cmd
;
4352 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
4355 memset(&cmd
, 0, sizeof(struct be_dma_mem
));
4356 cmd
.size
= sizeof(struct be_cmd_resp_get_func_config
);
4357 cmd
.va
= dma_zalloc_coherent(&adapter
->pdev
->dev
, cmd
.size
, &cmd
.dma
,
4360 dev_err(&adapter
->pdev
->dev
, "Memory alloc failure\n");
4365 wrb
= wrb_from_mbox(adapter
);
4373 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
4374 OPCODE_COMMON_GET_FUNC_CONFIG
,
4375 cmd
.size
, wrb
, &cmd
);
4377 if (skyhawk_chip(adapter
))
4378 req
->hdr
.version
= 1;
4380 status
= be_mbox_notify_wait(adapter
);
4382 struct be_cmd_resp_get_func_config
*resp
= cmd
.va
;
4383 u32 desc_count
= le32_to_cpu(resp
->desc_count
);
4384 struct be_nic_res_desc
*desc
;
4386 /* GET_FUNC_CONFIG returns resource descriptors of the
4387 * current function only. So, pf_num should be set to
4390 desc
= be_get_func_nic_desc(resp
->func_param
, desc_count
,
4397 /* Store pf_num & vf_num for later use in GET_PROFILE_CONFIG */
4398 adapter
->pf_num
= desc
->pf_num
;
4399 adapter
->vf_num
= desc
->vf_num
;
4402 be_copy_nic_desc(res
, desc
);
4405 mutex_unlock(&adapter
->mbox_lock
);
4407 dma_free_coherent(&adapter
->pdev
->dev
, cmd
.size
, cmd
.va
,
4412 /* This routine returns a list of all the NIC PF_nums in the adapter */
4413 static u16
be_get_nic_pf_num_list(u8
*buf
, u32 desc_count
, u16
*nic_pf_nums
)
4415 struct be_res_desc_hdr
*hdr
= (struct be_res_desc_hdr
*)buf
;
4416 struct be_pcie_res_desc
*pcie
= NULL
;
4418 u16 nic_pf_count
= 0;
4420 for (i
= 0; i
< desc_count
; i
++) {
4421 if (hdr
->desc_type
== PCIE_RESOURCE_DESC_TYPE_V0
||
4422 hdr
->desc_type
== PCIE_RESOURCE_DESC_TYPE_V1
) {
4423 pcie
= (struct be_pcie_res_desc
*)hdr
;
4424 if (pcie
->pf_state
&& (pcie
->pf_type
== MISSION_NIC
||
4425 pcie
->pf_type
== MISSION_RDMA
)) {
4426 nic_pf_nums
[nic_pf_count
++] = pcie
->pf_num
;
4430 hdr
->desc_len
= hdr
->desc_len
? : RESOURCE_DESC_SIZE_V0
;
4431 hdr
= (void *)hdr
+ hdr
->desc_len
;
4433 return nic_pf_count
;
4436 /* Will use MBOX only if MCCQ has not been created */
4437 int be_cmd_get_profile_config(struct be_adapter
*adapter
,
4438 struct be_resources
*res
,
4439 struct be_port_resources
*port_res
,
4440 u8 profile_type
, u8 query
, u8 domain
)
4442 struct be_cmd_resp_get_profile_config
*resp
;
4443 struct be_cmd_req_get_profile_config
*req
;
4444 struct be_nic_res_desc
*vf_res
;
4445 struct be_pcie_res_desc
*pcie
;
4446 struct be_port_res_desc
*port
;
4447 struct be_nic_res_desc
*nic
;
4448 struct be_mcc_wrb wrb
= {0};
4449 struct be_dma_mem cmd
;
4453 memset(&cmd
, 0, sizeof(struct be_dma_mem
));
4454 cmd
.size
= sizeof(struct be_cmd_resp_get_profile_config
);
4455 cmd
.va
= dma_zalloc_coherent(&adapter
->pdev
->dev
, cmd
.size
, &cmd
.dma
,
4461 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
4462 OPCODE_COMMON_GET_PROFILE_CONFIG
,
4463 cmd
.size
, &wrb
, &cmd
);
4465 if (!lancer_chip(adapter
))
4466 req
->hdr
.version
= 1;
4467 req
->type
= profile_type
;
4468 req
->hdr
.domain
= domain
;
4470 /* When QUERY_MODIFIABLE_FIELDS_TYPE bit is set, cmd returns the
4471 * descriptors with all bits set to "1" for the fields which can be
4472 * modified using SET_PROFILE_CONFIG cmd.
4474 if (query
== RESOURCE_MODIFIABLE
)
4475 req
->type
|= QUERY_MODIFIABLE_FIELDS_TYPE
;
4477 status
= be_cmd_notify_wait(adapter
, &wrb
);
4482 desc_count
= le16_to_cpu(resp
->desc_count
);
4485 u16 nic_pf_cnt
= 0, i
;
4486 u16 nic_pf_num_list
[MAX_NIC_FUNCS
];
4488 nic_pf_cnt
= be_get_nic_pf_num_list(resp
->func_param
,
4492 for (i
= 0; i
< nic_pf_cnt
; i
++) {
4493 nic
= be_get_func_nic_desc(resp
->func_param
, desc_count
,
4494 nic_pf_num_list
[i
]);
4495 if (nic
->link_param
== adapter
->port_num
) {
4496 port_res
->nic_pfs
++;
4497 pcie
= be_get_pcie_desc(resp
->func_param
,
4499 nic_pf_num_list
[i
]);
4500 port_res
->max_vfs
+= le16_to_cpu(pcie
->num_vfs
);
4506 pcie
= be_get_pcie_desc(resp
->func_param
, desc_count
,
4509 res
->max_vfs
= le16_to_cpu(pcie
->num_vfs
);
4511 port
= be_get_port_desc(resp
->func_param
, desc_count
);
4513 adapter
->mc_type
= port
->mc_type
;
4515 nic
= be_get_func_nic_desc(resp
->func_param
, desc_count
,
4518 be_copy_nic_desc(res
, nic
);
4520 vf_res
= be_get_vft_desc(resp
->func_param
, desc_count
,
4523 res
->vf_if_cap_flags
= vf_res
->cap_flags
;
4526 dma_free_coherent(&adapter
->pdev
->dev
, cmd
.size
, cmd
.va
,
4531 /* Will use MBOX only if MCCQ has not been created */
4532 static int be_cmd_set_profile_config(struct be_adapter
*adapter
, void *desc
,
4533 int size
, int count
, u8 version
, u8 domain
)
4535 struct be_cmd_req_set_profile_config
*req
;
4536 struct be_mcc_wrb wrb
= {0};
4537 struct be_dma_mem cmd
;
4540 memset(&cmd
, 0, sizeof(struct be_dma_mem
));
4541 cmd
.size
= sizeof(struct be_cmd_req_set_profile_config
);
4542 cmd
.va
= dma_zalloc_coherent(&adapter
->pdev
->dev
, cmd
.size
, &cmd
.dma
,
4548 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
4549 OPCODE_COMMON_SET_PROFILE_CONFIG
, cmd
.size
,
4551 req
->hdr
.version
= version
;
4552 req
->hdr
.domain
= domain
;
4553 req
->desc_count
= cpu_to_le32(count
);
4554 memcpy(req
->desc
, desc
, size
);
4556 status
= be_cmd_notify_wait(adapter
, &wrb
);
4559 dma_free_coherent(&adapter
->pdev
->dev
, cmd
.size
, cmd
.va
,
4564 /* Mark all fields invalid */
4565 static void be_reset_nic_desc(struct be_nic_res_desc
*nic
)
4567 memset(nic
, 0, sizeof(*nic
));
4568 nic
->unicast_mac_count
= 0xFFFF;
4569 nic
->mcc_count
= 0xFFFF;
4570 nic
->vlan_count
= 0xFFFF;
4571 nic
->mcast_mac_count
= 0xFFFF;
4572 nic
->txq_count
= 0xFFFF;
4573 nic
->rq_count
= 0xFFFF;
4574 nic
->rssq_count
= 0xFFFF;
4575 nic
->lro_count
= 0xFFFF;
4576 nic
->cq_count
= 0xFFFF;
4577 nic
->toe_conn_count
= 0xFFFF;
4578 nic
->eq_count
= 0xFFFF;
4579 nic
->iface_count
= 0xFFFF;
4580 nic
->link_param
= 0xFF;
4581 nic
->channel_id_param
= cpu_to_le16(0xF000);
4582 nic
->acpi_params
= 0xFF;
4583 nic
->wol_param
= 0x0F;
4584 nic
->tunnel_iface_count
= 0xFFFF;
4585 nic
->direct_tenant_iface_count
= 0xFFFF;
4586 nic
->bw_min
= 0xFFFFFFFF;
4587 nic
->bw_max
= 0xFFFFFFFF;
4590 /* Mark all fields invalid */
4591 static void be_reset_pcie_desc(struct be_pcie_res_desc
*pcie
)
4593 memset(pcie
, 0, sizeof(*pcie
));
4594 pcie
->sriov_state
= 0xFF;
4595 pcie
->pf_state
= 0xFF;
4596 pcie
->pf_type
= 0xFF;
4597 pcie
->num_vfs
= 0xFFFF;
4600 int be_cmd_config_qos(struct be_adapter
*adapter
, u32 max_rate
, u16 link_speed
,
4603 struct be_nic_res_desc nic_desc
;
4607 if (BE3_chip(adapter
))
4608 return be_cmd_set_qos(adapter
, max_rate
/ 10, domain
);
4610 be_reset_nic_desc(&nic_desc
);
4611 nic_desc
.pf_num
= adapter
->pf_num
;
4612 nic_desc
.vf_num
= domain
;
4613 nic_desc
.bw_min
= 0;
4614 if (lancer_chip(adapter
)) {
4615 nic_desc
.hdr
.desc_type
= NIC_RESOURCE_DESC_TYPE_V0
;
4616 nic_desc
.hdr
.desc_len
= RESOURCE_DESC_SIZE_V0
;
4617 nic_desc
.flags
= (1 << QUN_SHIFT
) | (1 << IMM_SHIFT
) |
4619 nic_desc
.bw_max
= cpu_to_le32(max_rate
/ 10);
4622 nic_desc
.hdr
.desc_type
= NIC_RESOURCE_DESC_TYPE_V1
;
4623 nic_desc
.hdr
.desc_len
= RESOURCE_DESC_SIZE_V1
;
4624 nic_desc
.flags
= (1 << IMM_SHIFT
) | (1 << NOSV_SHIFT
);
4625 bw_percent
= max_rate
? (max_rate
* 100) / link_speed
: 100;
4626 nic_desc
.bw_max
= cpu_to_le32(bw_percent
);
4629 return be_cmd_set_profile_config(adapter
, &nic_desc
,
4630 nic_desc
.hdr
.desc_len
,
4631 1, version
, domain
);
4634 int be_cmd_set_sriov_config(struct be_adapter
*adapter
,
4635 struct be_resources pool_res
, u16 num_vfs
,
4636 struct be_resources
*vft_res
)
4639 struct be_pcie_res_desc pcie
;
4640 struct be_nic_res_desc nic_vft
;
4643 /* PF PCIE descriptor */
4644 be_reset_pcie_desc(&desc
.pcie
);
4645 desc
.pcie
.hdr
.desc_type
= PCIE_RESOURCE_DESC_TYPE_V1
;
4646 desc
.pcie
.hdr
.desc_len
= RESOURCE_DESC_SIZE_V1
;
4647 desc
.pcie
.flags
= BIT(IMM_SHIFT
) | BIT(NOSV_SHIFT
);
4648 desc
.pcie
.pf_num
= adapter
->pdev
->devfn
;
4649 desc
.pcie
.sriov_state
= num_vfs
? 1 : 0;
4650 desc
.pcie
.num_vfs
= cpu_to_le16(num_vfs
);
4652 /* VF NIC Template descriptor */
4653 be_reset_nic_desc(&desc
.nic_vft
);
4654 desc
.nic_vft
.hdr
.desc_type
= NIC_RESOURCE_DESC_TYPE_V1
;
4655 desc
.nic_vft
.hdr
.desc_len
= RESOURCE_DESC_SIZE_V1
;
4656 desc
.nic_vft
.flags
= vft_res
->flags
| BIT(VFT_SHIFT
) |
4657 BIT(IMM_SHIFT
) | BIT(NOSV_SHIFT
);
4658 desc
.nic_vft
.pf_num
= adapter
->pdev
->devfn
;
4659 desc
.nic_vft
.vf_num
= 0;
4660 desc
.nic_vft
.cap_flags
= cpu_to_le32(vft_res
->vf_if_cap_flags
);
4661 desc
.nic_vft
.rq_count
= cpu_to_le16(vft_res
->max_rx_qs
);
4662 desc
.nic_vft
.txq_count
= cpu_to_le16(vft_res
->max_tx_qs
);
4663 desc
.nic_vft
.rssq_count
= cpu_to_le16(vft_res
->max_rss_qs
);
4664 desc
.nic_vft
.cq_count
= cpu_to_le16(vft_res
->max_cq_count
);
4666 if (vft_res
->max_uc_mac
)
4667 desc
.nic_vft
.unicast_mac_count
=
4668 cpu_to_le16(vft_res
->max_uc_mac
);
4669 if (vft_res
->max_vlans
)
4670 desc
.nic_vft
.vlan_count
= cpu_to_le16(vft_res
->max_vlans
);
4671 if (vft_res
->max_iface_count
)
4672 desc
.nic_vft
.iface_count
=
4673 cpu_to_le16(vft_res
->max_iface_count
);
4674 if (vft_res
->max_mcc_count
)
4675 desc
.nic_vft
.mcc_count
= cpu_to_le16(vft_res
->max_mcc_count
);
4677 return be_cmd_set_profile_config(adapter
, &desc
,
4678 2 * RESOURCE_DESC_SIZE_V1
, 2, 1, 0);
4681 int be_cmd_manage_iface(struct be_adapter
*adapter
, u32 iface
, u8 op
)
4683 struct be_mcc_wrb
*wrb
;
4684 struct be_cmd_req_manage_iface_filters
*req
;
4687 if (iface
== 0xFFFFFFFF)
4690 mutex_lock(&adapter
->mcc_lock
);
4692 wrb
= wrb_from_mccq(adapter
);
4697 req
= embedded_payload(wrb
);
4699 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
4700 OPCODE_COMMON_MANAGE_IFACE_FILTERS
, sizeof(*req
),
4703 req
->target_iface_id
= cpu_to_le32(iface
);
4705 status
= be_mcc_notify_wait(adapter
);
4707 mutex_unlock(&adapter
->mcc_lock
);
4711 int be_cmd_set_vxlan_port(struct be_adapter
*adapter
, __be16 port
)
4713 struct be_port_res_desc port_desc
;
4715 memset(&port_desc
, 0, sizeof(port_desc
));
4716 port_desc
.hdr
.desc_type
= PORT_RESOURCE_DESC_TYPE_V1
;
4717 port_desc
.hdr
.desc_len
= RESOURCE_DESC_SIZE_V1
;
4718 port_desc
.flags
= (1 << IMM_SHIFT
) | (1 << NOSV_SHIFT
);
4719 port_desc
.link_num
= adapter
->hba_port_num
;
4721 port_desc
.nv_flags
= NV_TYPE_VXLAN
| (1 << SOCVID_SHIFT
) |
4723 port_desc
.nv_port
= swab16(port
);
4725 port_desc
.nv_flags
= NV_TYPE_DISABLED
;
4726 port_desc
.nv_port
= 0;
4729 return be_cmd_set_profile_config(adapter
, &port_desc
,
4730 RESOURCE_DESC_SIZE_V1
, 1, 1, 0);
4733 int be_cmd_get_if_id(struct be_adapter
*adapter
, struct be_vf_cfg
*vf_cfg
,
4736 struct be_mcc_wrb
*wrb
;
4737 struct be_cmd_req_get_iface_list
*req
;
4738 struct be_cmd_resp_get_iface_list
*resp
;
4741 mutex_lock(&adapter
->mcc_lock
);
4743 wrb
= wrb_from_mccq(adapter
);
4748 req
= embedded_payload(wrb
);
4750 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
4751 OPCODE_COMMON_GET_IFACE_LIST
, sizeof(*resp
),
4753 req
->hdr
.domain
= vf_num
+ 1;
4755 status
= be_mcc_notify_wait(adapter
);
4757 resp
= (struct be_cmd_resp_get_iface_list
*)req
;
4758 vf_cfg
->if_handle
= le32_to_cpu(resp
->if_desc
.if_id
);
4762 mutex_unlock(&adapter
->mcc_lock
);
4766 static int lancer_wait_idle(struct be_adapter
*adapter
)
4768 #define SLIPORT_IDLE_TIMEOUT 30
4772 for (i
= 0; i
< SLIPORT_IDLE_TIMEOUT
; i
++) {
4773 reg_val
= ioread32(adapter
->db
+ PHYSDEV_CONTROL_OFFSET
);
4774 if ((reg_val
& PHYSDEV_CONTROL_INP_MASK
) == 0)
4780 if (i
== SLIPORT_IDLE_TIMEOUT
)
4786 int lancer_physdev_ctrl(struct be_adapter
*adapter
, u32 mask
)
4790 status
= lancer_wait_idle(adapter
);
4794 iowrite32(mask
, adapter
->db
+ PHYSDEV_CONTROL_OFFSET
);
4799 /* Routine to check whether dump image is present or not */
4800 bool dump_present(struct be_adapter
*adapter
)
4802 u32 sliport_status
= 0;
4804 sliport_status
= ioread32(adapter
->db
+ SLIPORT_STATUS_OFFSET
);
4805 return !!(sliport_status
& SLIPORT_STATUS_DIP_MASK
);
4808 int lancer_initiate_dump(struct be_adapter
*adapter
)
4810 struct device
*dev
= &adapter
->pdev
->dev
;
4813 if (dump_present(adapter
)) {
4814 dev_info(dev
, "Previous dump not cleared, not forcing dump\n");
4818 /* give firmware reset and diagnostic dump */
4819 status
= lancer_physdev_ctrl(adapter
, PHYSDEV_CONTROL_FW_RESET_MASK
|
4820 PHYSDEV_CONTROL_DD_MASK
);
4822 dev_err(dev
, "FW reset failed\n");
4826 status
= lancer_wait_idle(adapter
);
4830 if (!dump_present(adapter
)) {
4831 dev_err(dev
, "FW dump not generated\n");
4838 int lancer_delete_dump(struct be_adapter
*adapter
)
4842 status
= lancer_cmd_delete_object(adapter
, LANCER_FW_DUMP_FILE
);
4843 return be_cmd_status(status
);
4847 int be_cmd_enable_vf(struct be_adapter
*adapter
, u8 domain
)
4849 struct be_mcc_wrb
*wrb
;
4850 struct be_cmd_enable_disable_vf
*req
;
4853 if (BEx_chip(adapter
))
4856 mutex_lock(&adapter
->mcc_lock
);
4858 wrb
= wrb_from_mccq(adapter
);
4864 req
= embedded_payload(wrb
);
4866 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
4867 OPCODE_COMMON_ENABLE_DISABLE_VF
, sizeof(*req
),
4870 req
->hdr
.domain
= domain
;
4872 status
= be_mcc_notify_wait(adapter
);
4874 mutex_unlock(&adapter
->mcc_lock
);
4878 int be_cmd_intr_set(struct be_adapter
*adapter
, bool intr_enable
)
4880 struct be_mcc_wrb
*wrb
;
4881 struct be_cmd_req_intr_set
*req
;
4884 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
4887 wrb
= wrb_from_mbox(adapter
);
4889 req
= embedded_payload(wrb
);
4891 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
4892 OPCODE_COMMON_SET_INTERRUPT_ENABLE
, sizeof(*req
),
4895 req
->intr_enabled
= intr_enable
;
4897 status
= be_mbox_notify_wait(adapter
);
4899 mutex_unlock(&adapter
->mbox_lock
);
4904 int be_cmd_get_active_profile(struct be_adapter
*adapter
, u16
*profile_id
)
4906 struct be_cmd_req_get_active_profile
*req
;
4907 struct be_mcc_wrb
*wrb
;
4910 if (mutex_lock_interruptible(&adapter
->mbox_lock
))
4913 wrb
= wrb_from_mbox(adapter
);
4919 req
= embedded_payload(wrb
);
4921 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
4922 OPCODE_COMMON_GET_ACTIVE_PROFILE
, sizeof(*req
),
4925 status
= be_mbox_notify_wait(adapter
);
4927 struct be_cmd_resp_get_active_profile
*resp
=
4928 embedded_payload(wrb
);
4930 *profile_id
= le16_to_cpu(resp
->active_profile_id
);
4934 mutex_unlock(&adapter
->mbox_lock
);
4939 __be_cmd_set_logical_link_config(struct be_adapter
*adapter
,
4940 int link_state
, int version
, u8 domain
)
4942 struct be_mcc_wrb
*wrb
;
4943 struct be_cmd_req_set_ll_link
*req
;
4946 mutex_lock(&adapter
->mcc_lock
);
4948 wrb
= wrb_from_mccq(adapter
);
4954 req
= embedded_payload(wrb
);
4956 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
4957 OPCODE_COMMON_SET_LOGICAL_LINK_CONFIG
,
4958 sizeof(*req
), wrb
, NULL
);
4960 req
->hdr
.version
= version
;
4961 req
->hdr
.domain
= domain
;
4963 if (link_state
== IFLA_VF_LINK_STATE_ENABLE
||
4964 link_state
== IFLA_VF_LINK_STATE_AUTO
)
4965 req
->link_config
|= PLINK_ENABLE
;
4967 if (link_state
== IFLA_VF_LINK_STATE_AUTO
)
4968 req
->link_config
|= PLINK_TRACK
;
4970 status
= be_mcc_notify_wait(adapter
);
4972 mutex_unlock(&adapter
->mcc_lock
);
4976 int be_cmd_set_logical_link_config(struct be_adapter
*adapter
,
4977 int link_state
, u8 domain
)
4981 if (BE2_chip(adapter
))
4984 status
= __be_cmd_set_logical_link_config(adapter
, link_state
,
4987 /* Version 2 of the command will not be recognized by older FW.
4988 * On such a failure issue version 1 of the command.
4990 if (base_status(status
) == MCC_STATUS_ILLEGAL_REQUEST
)
4991 status
= __be_cmd_set_logical_link_config(adapter
, link_state
,
4996 int be_cmd_set_features(struct be_adapter
*adapter
)
4998 struct be_cmd_resp_set_features
*resp
;
4999 struct be_cmd_req_set_features
*req
;
5000 struct be_mcc_wrb
*wrb
;
5003 if (mutex_lock_interruptible(&adapter
->mcc_lock
))
5006 wrb
= wrb_from_mccq(adapter
);
5012 req
= embedded_payload(wrb
);
5014 be_wrb_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
5015 OPCODE_COMMON_SET_FEATURES
,
5016 sizeof(*req
), wrb
, NULL
);
5018 req
->features
= cpu_to_le32(BE_FEATURE_UE_RECOVERY
);
5019 req
->parameter_len
= cpu_to_le32(sizeof(struct be_req_ue_recovery
));
5020 req
->parameter
.req
.uer
= cpu_to_le32(BE_UE_RECOVERY_UER_MASK
);
5022 status
= be_mcc_notify_wait(adapter
);
5026 resp
= embedded_payload(wrb
);
5028 adapter
->error_recovery
.ue_to_poll_time
=
5029 le16_to_cpu(resp
->parameter
.resp
.ue2rp
);
5030 adapter
->error_recovery
.ue_to_reset_time
=
5031 le16_to_cpu(resp
->parameter
.resp
.ue2sr
);
5032 adapter
->error_recovery
.recovery_supported
= true;
5034 /* Checking "MCC_STATUS_INVALID_LENGTH" for SKH as FW
5035 * returns this error in older firmware versions
5037 if (base_status(status
) == MCC_STATUS_ILLEGAL_REQUEST
||
5038 base_status(status
) == MCC_STATUS_INVALID_LENGTH
)
5039 dev_info(&adapter
->pdev
->dev
,
5040 "Adapter does not support HW error recovery\n");
5042 mutex_unlock(&adapter
->mcc_lock
);
5046 int be_roce_mcc_cmd(void *netdev_handle
, void *wrb_payload
,
5047 int wrb_payload_size
, u16
*cmd_status
, u16
*ext_status
)
5049 struct be_adapter
*adapter
= netdev_priv(netdev_handle
);
5050 struct be_mcc_wrb
*wrb
;
5051 struct be_cmd_req_hdr
*hdr
= (struct be_cmd_req_hdr
*)wrb_payload
;
5052 struct be_cmd_req_hdr
*req
;
5053 struct be_cmd_resp_hdr
*resp
;
5056 mutex_lock(&adapter
->mcc_lock
);
5058 wrb
= wrb_from_mccq(adapter
);
5063 req
= embedded_payload(wrb
);
5064 resp
= embedded_payload(wrb
);
5066 be_wrb_cmd_hdr_prepare(req
, hdr
->subsystem
,
5067 hdr
->opcode
, wrb_payload_size
, wrb
, NULL
);
5068 memcpy(req
, wrb_payload
, wrb_payload_size
);
5069 be_dws_cpu_to_le(req
, wrb_payload_size
);
5071 status
= be_mcc_notify_wait(adapter
);
5073 *cmd_status
= (status
& 0xffff);
5076 memcpy(wrb_payload
, resp
, sizeof(*resp
) + resp
->response_length
);
5077 be_dws_le_to_cpu(wrb_payload
, sizeof(*resp
) + resp
->response_length
);
5079 mutex_unlock(&adapter
->mcc_lock
);
5082 EXPORT_SYMBOL(be_roce_mcc_cmd
);