2 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2013 QLogic Corporation
5 * See LICENSE.qlcnic for copyright and licensing details.
8 #include "qlcnic_sriov.h"
10 #include "qlcnic_hw.h"
12 /* Reset template definitions */
13 #define QLC_83XX_RESTART_TEMPLATE_SIZE 0x2000
14 #define QLC_83XX_RESET_TEMPLATE_ADDR 0x4F0000
15 #define QLC_83XX_RESET_SEQ_VERSION 0x0101
17 #define QLC_83XX_OPCODE_NOP 0x0000
18 #define QLC_83XX_OPCODE_WRITE_LIST 0x0001
19 #define QLC_83XX_OPCODE_READ_WRITE_LIST 0x0002
20 #define QLC_83XX_OPCODE_POLL_LIST 0x0004
21 #define QLC_83XX_OPCODE_POLL_WRITE_LIST 0x0008
22 #define QLC_83XX_OPCODE_READ_MODIFY_WRITE 0x0010
23 #define QLC_83XX_OPCODE_SEQ_PAUSE 0x0020
24 #define QLC_83XX_OPCODE_SEQ_END 0x0040
25 #define QLC_83XX_OPCODE_TMPL_END 0x0080
26 #define QLC_83XX_OPCODE_POLL_READ_LIST 0x0100
28 /* EPORT control registers */
29 #define QLC_83XX_RESET_CONTROL 0x28084E50
30 #define QLC_83XX_RESET_REG 0x28084E60
31 #define QLC_83XX_RESET_PORT0 0x28084E70
32 #define QLC_83XX_RESET_PORT1 0x28084E80
33 #define QLC_83XX_RESET_PORT2 0x28084E90
34 #define QLC_83XX_RESET_PORT3 0x28084EA0
35 #define QLC_83XX_RESET_SRESHIM 0x28084EB0
36 #define QLC_83XX_RESET_EPGSHIM 0x28084EC0
37 #define QLC_83XX_RESET_ETHERPCS 0x28084ED0
39 static int qlcnic_83xx_init_default_driver(struct qlcnic_adapter
*adapter
);
40 static int qlcnic_83xx_check_heartbeat(struct qlcnic_adapter
*p_dev
);
41 static int qlcnic_83xx_restart_hw(struct qlcnic_adapter
*adapter
);
42 static int qlcnic_83xx_check_hw_status(struct qlcnic_adapter
*p_dev
);
43 static int qlcnic_83xx_get_reset_instruction_template(struct qlcnic_adapter
*);
44 static void qlcnic_83xx_stop_hw(struct qlcnic_adapter
*);
47 struct qlc_83xx_reset_hdr
{
48 #if defined(__LITTLE_ENDIAN)
57 #elif defined(__BIG_ENDIAN)
69 /* Command entry header. */
70 struct qlc_83xx_entry_hdr
{
71 #if defined(__LITTLE_ENDIAN)
76 #elif defined(__BIG_ENDIAN)
84 /* Generic poll command */
85 struct qlc_83xx_poll
{
90 /* Read modify write command */
95 #if defined(__LITTLE_ENDIAN)
100 #elif defined(__BIG_ENDIAN)
108 /* Generic command with 2 DWORD */
109 struct qlc_83xx_entry
{
114 /* Generic command with 4 DWORD */
115 struct qlc_83xx_quad_entry
{
121 static const char *const qlc_83xx_idc_states
[] = {
133 qlcnic_83xx_idc_check_driver_presence_reg(struct qlcnic_adapter
*adapter
)
137 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
);
144 static void qlcnic_83xx_idc_log_state_history(struct qlcnic_adapter
*adapter
)
147 cur
= adapter
->ahw
->idc
.curr_state
;
148 prev
= adapter
->ahw
->idc
.prev_state
;
150 dev_info(&adapter
->pdev
->dev
,
151 "current state = %s, prev state = %s\n",
152 adapter
->ahw
->idc
.name
[cur
],
153 adapter
->ahw
->idc
.name
[prev
]);
156 static int qlcnic_83xx_idc_update_audit_reg(struct qlcnic_adapter
*adapter
,
163 if (qlcnic_83xx_lock_driver(adapter
))
167 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_AUDIT
);
168 val
|= (adapter
->portnum
& 0xf);
171 seconds
= jiffies
/ HZ
- adapter
->ahw
->idc
.sec_counter
;
173 seconds
= jiffies
/ HZ
;
176 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DRV_AUDIT
, val
);
177 adapter
->ahw
->idc
.sec_counter
= jiffies
/ HZ
;
180 qlcnic_83xx_unlock_driver(adapter
);
185 static void qlcnic_83xx_idc_update_minor_version(struct qlcnic_adapter
*adapter
)
189 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_MIN_VERSION
);
190 val
= val
& ~(0x3 << (adapter
->portnum
* 2));
191 val
= val
| (QLC_83XX_IDC_MINOR_VERSION
<< (adapter
->portnum
* 2));
192 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_MIN_VERSION
, val
);
195 static int qlcnic_83xx_idc_update_major_version(struct qlcnic_adapter
*adapter
,
201 if (qlcnic_83xx_lock_driver(adapter
))
205 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_MAJ_VERSION
);
207 val
= val
| QLC_83XX_IDC_MAJOR_VERSION
;
208 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_MAJ_VERSION
, val
);
211 qlcnic_83xx_unlock_driver(adapter
);
217 qlcnic_83xx_idc_update_drv_presence_reg(struct qlcnic_adapter
*adapter
,
218 int status
, int lock
)
223 if (qlcnic_83xx_lock_driver(adapter
))
227 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
);
230 val
= val
| (1 << adapter
->portnum
);
232 val
= val
& ~(1 << adapter
->portnum
);
234 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
, val
);
235 qlcnic_83xx_idc_update_minor_version(adapter
);
238 qlcnic_83xx_unlock_driver(adapter
);
243 static int qlcnic_83xx_idc_check_major_version(struct qlcnic_adapter
*adapter
)
248 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_MAJ_VERSION
);
249 version
= val
& 0xFF;
251 if (version
!= QLC_83XX_IDC_MAJOR_VERSION
) {
252 dev_info(&adapter
->pdev
->dev
,
253 "%s:mismatch. version 0x%x, expected version 0x%x\n",
254 __func__
, version
, QLC_83XX_IDC_MAJOR_VERSION
);
261 static int qlcnic_83xx_idc_clear_registers(struct qlcnic_adapter
*adapter
,
267 if (qlcnic_83xx_lock_driver(adapter
))
271 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DRV_ACK
, 0);
272 /* Clear graceful reset bit */
273 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
274 val
&= ~QLC_83XX_IDC_GRACEFULL_RESET
;
275 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_CTRL
, val
);
278 qlcnic_83xx_unlock_driver(adapter
);
283 static int qlcnic_83xx_idc_update_drv_ack_reg(struct qlcnic_adapter
*adapter
,
289 if (qlcnic_83xx_lock_driver(adapter
))
293 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_ACK
);
295 val
= val
| (1 << adapter
->portnum
);
297 val
= val
& ~(1 << adapter
->portnum
);
298 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DRV_ACK
, val
);
301 qlcnic_83xx_unlock_driver(adapter
);
306 static int qlcnic_83xx_idc_check_timeout(struct qlcnic_adapter
*adapter
,
311 seconds
= jiffies
/ HZ
- adapter
->ahw
->idc
.sec_counter
;
312 if (seconds
<= time_limit
)
319 * qlcnic_83xx_idc_check_reset_ack_reg
321 * @adapter: adapter structure
323 * Check ACK wait limit and clear the functions which failed to ACK
325 * Return 0 if all functions have acknowledged the reset request.
327 static int qlcnic_83xx_idc_check_reset_ack_reg(struct qlcnic_adapter
*adapter
)
330 u32 ack
, presence
, val
;
332 timeout
= QLC_83XX_IDC_RESET_TIMEOUT_SECS
;
333 ack
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_ACK
);
334 presence
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
);
335 dev_info(&adapter
->pdev
->dev
,
336 "%s: ack = 0x%x, presence = 0x%x\n", __func__
, ack
, presence
);
337 if (!((ack
& presence
) == presence
)) {
338 if (qlcnic_83xx_idc_check_timeout(adapter
, timeout
)) {
339 /* Clear functions which failed to ACK */
340 dev_info(&adapter
->pdev
->dev
,
341 "%s: ACK wait exceeds time limit\n", __func__
);
342 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
);
343 val
= val
& ~(ack
^ presence
);
344 if (qlcnic_83xx_lock_driver(adapter
))
346 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
, val
);
347 dev_info(&adapter
->pdev
->dev
,
348 "%s: updated drv presence reg = 0x%x\n",
350 qlcnic_83xx_unlock_driver(adapter
);
357 dev_info(&adapter
->pdev
->dev
,
358 "%s: Reset ACK received from all functions\n",
365 * qlcnic_83xx_idc_tx_soft_reset
367 * @adapter: adapter structure
369 * Handle context deletion and recreation request from transmit routine
371 * Returns -EBUSY or Success (0)
374 static int qlcnic_83xx_idc_tx_soft_reset(struct qlcnic_adapter
*adapter
)
376 struct net_device
*netdev
= adapter
->netdev
;
378 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
381 netif_device_detach(netdev
);
382 qlcnic_down(adapter
, netdev
);
383 qlcnic_up(adapter
, netdev
);
384 netif_device_attach(netdev
);
385 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
386 netdev_info(adapter
->netdev
, "%s: soft reset complete.\n", __func__
);
392 * qlcnic_83xx_idc_detach_driver
394 * @adapter: adapter structure
395 * Detach net interface, stop TX and cleanup resources before the HW reset.
399 static void qlcnic_83xx_idc_detach_driver(struct qlcnic_adapter
*adapter
)
402 struct net_device
*netdev
= adapter
->netdev
;
404 netif_device_detach(netdev
);
405 qlcnic_83xx_detach_mailbox_work(adapter
);
407 /* Disable mailbox interrupt */
408 qlcnic_83xx_disable_mbx_intr(adapter
);
409 qlcnic_down(adapter
, netdev
);
410 for (i
= 0; i
< adapter
->ahw
->num_msix
; i
++) {
411 adapter
->ahw
->intr_tbl
[i
].id
= i
;
412 adapter
->ahw
->intr_tbl
[i
].enabled
= 0;
413 adapter
->ahw
->intr_tbl
[i
].src
= 0;
416 if (qlcnic_sriov_pf_check(adapter
))
417 qlcnic_sriov_pf_reset(adapter
);
421 * qlcnic_83xx_idc_attach_driver
423 * @adapter: adapter structure
425 * Re-attach and re-enable net interface
429 static void qlcnic_83xx_idc_attach_driver(struct qlcnic_adapter
*adapter
)
431 struct net_device
*netdev
= adapter
->netdev
;
433 if (netif_running(netdev
)) {
434 if (qlcnic_up(adapter
, netdev
))
436 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
439 netif_device_attach(netdev
);
442 static int qlcnic_83xx_idc_enter_failed_state(struct qlcnic_adapter
*adapter
,
446 if (qlcnic_83xx_lock_driver(adapter
))
450 qlcnic_83xx_idc_clear_registers(adapter
, 0);
451 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
, QLC_83XX_IDC_DEV_FAILED
);
453 qlcnic_83xx_unlock_driver(adapter
);
455 qlcnic_83xx_idc_log_state_history(adapter
);
456 dev_info(&adapter
->pdev
->dev
, "Device will enter failed state\n");
461 static int qlcnic_83xx_idc_enter_init_state(struct qlcnic_adapter
*adapter
,
465 if (qlcnic_83xx_lock_driver(adapter
))
469 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
, QLC_83XX_IDC_DEV_INIT
);
472 qlcnic_83xx_unlock_driver(adapter
);
477 static int qlcnic_83xx_idc_enter_need_quiesce(struct qlcnic_adapter
*adapter
,
481 if (qlcnic_83xx_lock_driver(adapter
))
485 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
,
486 QLC_83XX_IDC_DEV_NEED_QUISCENT
);
489 qlcnic_83xx_unlock_driver(adapter
);
495 qlcnic_83xx_idc_enter_need_reset_state(struct qlcnic_adapter
*adapter
, int lock
)
498 if (qlcnic_83xx_lock_driver(adapter
))
502 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
,
503 QLC_83XX_IDC_DEV_NEED_RESET
);
506 qlcnic_83xx_unlock_driver(adapter
);
511 static int qlcnic_83xx_idc_enter_ready_state(struct qlcnic_adapter
*adapter
,
515 if (qlcnic_83xx_lock_driver(adapter
))
519 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
, QLC_83XX_IDC_DEV_READY
);
521 qlcnic_83xx_unlock_driver(adapter
);
527 * qlcnic_83xx_idc_find_reset_owner_id
529 * @adapter: adapter structure
531 * NIC gets precedence over ISCSI and ISCSI has precedence over FCOE.
532 * Within the same class, function with lowest PCI ID assumes ownership
534 * Returns: reset owner id or failure indication (-EIO)
537 static int qlcnic_83xx_idc_find_reset_owner_id(struct qlcnic_adapter
*adapter
)
539 u32 reg
, reg1
, reg2
, i
, j
, owner
, class;
541 reg1
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DEV_PARTITION_INFO_1
);
542 reg2
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DEV_PARTITION_INFO_2
);
543 owner
= QLCNIC_TYPE_NIC
;
549 class = (((reg
& (0xF << j
* 4)) >> j
* 4) & 0x3);
552 if (i
== (QLC_83XX_IDC_MAX_FUNC_PER_PARTITION_INFO
- 1)) {
559 if (i
== (QLC_83XX_IDC_MAX_CNA_FUNCTIONS
- 1)) {
560 if (owner
== QLCNIC_TYPE_NIC
)
561 owner
= QLCNIC_TYPE_ISCSI
;
562 else if (owner
== QLCNIC_TYPE_ISCSI
)
563 owner
= QLCNIC_TYPE_FCOE
;
564 else if (owner
== QLCNIC_TYPE_FCOE
)
570 } while (i
++ < QLC_83XX_IDC_MAX_CNA_FUNCTIONS
);
575 static int qlcnic_83xx_idc_restart_hw(struct qlcnic_adapter
*adapter
, int lock
)
579 ret
= qlcnic_83xx_restart_hw(adapter
);
582 qlcnic_83xx_idc_enter_failed_state(adapter
, lock
);
584 qlcnic_83xx_idc_clear_registers(adapter
, lock
);
585 ret
= qlcnic_83xx_idc_enter_ready_state(adapter
, lock
);
591 static int qlcnic_83xx_idc_check_fan_failure(struct qlcnic_adapter
*adapter
)
595 status
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
597 if (status
& QLCNIC_RCODE_FATAL_ERROR
) {
598 dev_err(&adapter
->pdev
->dev
,
599 "peg halt status1=0x%x\n", status
);
600 if (QLCNIC_FWERROR_CODE(status
) == QLCNIC_FWERROR_FAN_FAILURE
) {
601 dev_err(&adapter
->pdev
->dev
,
602 "On board active cooling fan failed. "
603 "Device has been halted.\n");
604 dev_err(&adapter
->pdev
->dev
,
605 "Replace the adapter.\n");
613 int qlcnic_83xx_idc_reattach_driver(struct qlcnic_adapter
*adapter
)
617 qlcnic_83xx_reinit_mbx_work(adapter
->ahw
->mailbox
);
618 qlcnic_83xx_enable_mbx_interrupt(adapter
);
620 qlcnic_83xx_initialize_nic(adapter
, 1);
622 err
= qlcnic_sriov_pf_reinit(adapter
);
626 qlcnic_83xx_enable_mbx_interrupt(adapter
);
628 if (qlcnic_83xx_configure_opmode(adapter
)) {
629 qlcnic_83xx_idc_enter_failed_state(adapter
, 1);
633 if (adapter
->nic_ops
->init_driver(adapter
)) {
634 qlcnic_83xx_idc_enter_failed_state(adapter
, 1);
638 if (adapter
->portnum
== 0)
639 qlcnic_set_drv_version(adapter
);
641 qlcnic_dcb_get_info(adapter
->dcb
);
642 qlcnic_83xx_idc_attach_driver(adapter
);
647 static void qlcnic_83xx_idc_update_idc_params(struct qlcnic_adapter
*adapter
)
649 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
651 qlcnic_83xx_idc_update_drv_presence_reg(adapter
, 1, 1);
652 qlcnic_83xx_idc_update_audit_reg(adapter
, 0, 1);
653 set_bit(QLC_83XX_MODULE_LOADED
, &adapter
->ahw
->idc
.status
);
655 ahw
->idc
.quiesce_req
= 0;
656 ahw
->idc
.delay
= QLC_83XX_IDC_FW_POLL_DELAY
;
657 ahw
->idc
.err_code
= 0;
658 ahw
->idc
.collect_dump
= 0;
659 ahw
->reset_context
= 0;
660 adapter
->tx_timeo_cnt
= 0;
661 ahw
->idc
.delay_reset
= 0;
663 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
667 * qlcnic_83xx_idc_ready_state_entry
669 * @adapter: adapter structure
671 * Perform ready state initialization, this routine will get invoked only
672 * once from READY state.
674 * Returns: Error code or Success(0)
677 int qlcnic_83xx_idc_ready_state_entry(struct qlcnic_adapter
*adapter
)
679 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
681 if (ahw
->idc
.prev_state
!= QLC_83XX_IDC_DEV_READY
) {
682 qlcnic_83xx_idc_update_idc_params(adapter
);
683 /* Re-attach the device if required */
684 if ((ahw
->idc
.prev_state
== QLC_83XX_IDC_DEV_NEED_RESET
) ||
685 (ahw
->idc
.prev_state
== QLC_83XX_IDC_DEV_INIT
)) {
686 if (qlcnic_83xx_idc_reattach_driver(adapter
))
695 * qlcnic_83xx_idc_vnic_pf_entry
697 * @adapter: adapter structure
699 * Ensure vNIC mode privileged function starts only after vNIC mode is
700 * enabled by management function.
701 * If vNIC mode is ready, start initialization.
706 int qlcnic_83xx_idc_vnic_pf_entry(struct qlcnic_adapter
*adapter
)
709 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
711 /* Privileged function waits till mgmt function enables VNIC mode */
712 state
= QLCRDX(adapter
->ahw
, QLC_83XX_VNIC_STATE
);
713 if (state
!= QLCNIC_DEV_NPAR_OPER
) {
714 if (!ahw
->idc
.vnic_wait_limit
--) {
715 qlcnic_83xx_idc_enter_failed_state(adapter
, 1);
718 dev_info(&adapter
->pdev
->dev
, "vNIC mode disabled\n");
722 /* Perform one time initialization from ready state */
723 if (ahw
->idc
.vnic_state
!= QLCNIC_DEV_NPAR_OPER
) {
724 qlcnic_83xx_idc_update_idc_params(adapter
);
726 /* If the previous state is UNKNOWN, device will be
727 already attached properly by Init routine*/
728 if (ahw
->idc
.prev_state
!= QLC_83XX_IDC_DEV_UNKNOWN
) {
729 if (qlcnic_83xx_idc_reattach_driver(adapter
))
732 adapter
->ahw
->idc
.vnic_state
= QLCNIC_DEV_NPAR_OPER
;
733 dev_info(&adapter
->pdev
->dev
, "vNIC mode enabled\n");
740 static int qlcnic_83xx_idc_unknown_state(struct qlcnic_adapter
*adapter
)
742 adapter
->ahw
->idc
.err_code
= -EIO
;
743 dev_err(&adapter
->pdev
->dev
,
744 "%s: Device in unknown state\n", __func__
);
745 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
750 * qlcnic_83xx_idc_cold_state
752 * @adapter: adapter structure
754 * If HW is up and running device will enter READY state.
755 * If firmware image from host needs to be loaded, device is
756 * forced to start with the file firmware image.
758 * Returns: Error code or Success(0)
761 static int qlcnic_83xx_idc_cold_state_handler(struct qlcnic_adapter
*adapter
)
763 qlcnic_83xx_idc_update_drv_presence_reg(adapter
, 1, 0);
764 qlcnic_83xx_idc_update_audit_reg(adapter
, 1, 0);
766 if (qlcnic_load_fw_file
) {
767 qlcnic_83xx_idc_restart_hw(adapter
, 0);
769 if (qlcnic_83xx_check_hw_status(adapter
)) {
770 qlcnic_83xx_idc_enter_failed_state(adapter
, 0);
773 qlcnic_83xx_idc_enter_ready_state(adapter
, 0);
780 * qlcnic_83xx_idc_init_state
782 * @adapter: adapter structure
784 * Reset owner will restart the device from this state.
785 * Device will enter failed state if it remains
786 * in this state for more than DEV_INIT time limit.
788 * Returns: Error code or Success(0)
791 static int qlcnic_83xx_idc_init_state(struct qlcnic_adapter
*adapter
)
793 int timeout
, ret
= 0;
796 timeout
= QLC_83XX_IDC_INIT_TIMEOUT_SECS
;
797 if (adapter
->ahw
->idc
.prev_state
== QLC_83XX_IDC_DEV_NEED_RESET
) {
798 owner
= qlcnic_83xx_idc_find_reset_owner_id(adapter
);
799 if (adapter
->ahw
->pci_func
== owner
)
800 ret
= qlcnic_83xx_idc_restart_hw(adapter
, 1);
802 ret
= qlcnic_83xx_idc_check_timeout(adapter
, timeout
);
809 * qlcnic_83xx_idc_ready_state
811 * @adapter: adapter structure
813 * Perform IDC protocol specicifed actions after monitoring device state and
816 * Returns: Error code or Success(0)
819 static int qlcnic_83xx_idc_ready_state(struct qlcnic_adapter
*adapter
)
821 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
822 struct qlcnic_mailbox
*mbx
= ahw
->mailbox
;
826 /* Perform NIC configuration based ready state entry actions */
827 if (ahw
->idc
.state_entry(adapter
))
830 if (qlcnic_check_temp(adapter
)) {
831 if (ahw
->temp
== QLCNIC_TEMP_PANIC
) {
832 qlcnic_83xx_idc_check_fan_failure(adapter
);
833 dev_err(&adapter
->pdev
->dev
,
834 "Error: device temperature %d above limits\n",
836 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
837 set_bit(__QLCNIC_RESETTING
, &adapter
->state
);
838 qlcnic_83xx_idc_detach_driver(adapter
);
839 qlcnic_83xx_idc_enter_failed_state(adapter
, 1);
844 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
845 ret
= qlcnic_83xx_check_heartbeat(adapter
);
847 adapter
->flags
|= QLCNIC_FW_HANG
;
848 if (!(val
& QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY
)) {
849 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
850 set_bit(__QLCNIC_RESETTING
, &adapter
->state
);
851 qlcnic_83xx_idc_enter_need_reset_state(adapter
, 1);
853 netdev_info(adapter
->netdev
, "%s: Auto firmware recovery is disabled\n",
855 qlcnic_83xx_idc_enter_failed_state(adapter
, 1);
860 if ((val
& QLC_83XX_IDC_GRACEFULL_RESET
) || ahw
->idc
.collect_dump
) {
861 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
863 /* Move to need reset state and prepare for reset */
864 qlcnic_83xx_idc_enter_need_reset_state(adapter
, 1);
868 /* Check for soft reset request */
869 if (ahw
->reset_context
&&
870 !(val
& QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY
)) {
871 adapter
->ahw
->reset_context
= 0;
872 qlcnic_83xx_idc_tx_soft_reset(adapter
);
876 /* Move to need quiesce state if requested */
877 if (adapter
->ahw
->idc
.quiesce_req
) {
878 qlcnic_83xx_idc_enter_need_quiesce(adapter
, 1);
879 qlcnic_83xx_idc_update_audit_reg(adapter
, 0, 1);
887 * qlcnic_83xx_idc_need_reset_state
889 * @adapter: adapter structure
891 * Device will remain in this state until:
892 * Reset request ACK's are received from all the functions
893 * Wait time exceeds max time limit
895 * Returns: Error code or Success(0)
898 static int qlcnic_83xx_idc_need_reset_state(struct qlcnic_adapter
*adapter
)
900 struct qlcnic_mailbox
*mbx
= adapter
->ahw
->mailbox
;
903 if (adapter
->ahw
->idc
.prev_state
!= QLC_83XX_IDC_DEV_NEED_RESET
) {
904 qlcnic_83xx_idc_update_audit_reg(adapter
, 0, 1);
905 set_bit(__QLCNIC_RESETTING
, &adapter
->state
);
906 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
907 if (adapter
->ahw
->nic_mode
== QLCNIC_VNIC_MODE
)
908 qlcnic_83xx_disable_vnic_mode(adapter
, 1);
910 if (qlcnic_check_diag_status(adapter
)) {
911 dev_info(&adapter
->pdev
->dev
,
912 "%s: Wait for diag completion\n", __func__
);
913 adapter
->ahw
->idc
.delay_reset
= 1;
916 qlcnic_83xx_idc_update_drv_ack_reg(adapter
, 1, 1);
917 qlcnic_83xx_idc_detach_driver(adapter
);
921 if (qlcnic_check_diag_status(adapter
)) {
922 dev_info(&adapter
->pdev
->dev
,
923 "%s: Wait for diag completion\n", __func__
);
926 if (adapter
->ahw
->idc
.delay_reset
) {
927 qlcnic_83xx_idc_update_drv_ack_reg(adapter
, 1, 1);
928 qlcnic_83xx_idc_detach_driver(adapter
);
929 adapter
->ahw
->idc
.delay_reset
= 0;
932 /* Check for ACK from other functions */
933 ret
= qlcnic_83xx_idc_check_reset_ack_reg(adapter
);
935 dev_info(&adapter
->pdev
->dev
,
936 "%s: Waiting for reset ACK\n", __func__
);
941 /* Transit to INIT state and restart the HW */
942 qlcnic_83xx_idc_enter_init_state(adapter
, 1);
947 static int qlcnic_83xx_idc_need_quiesce_state(struct qlcnic_adapter
*adapter
)
949 dev_err(&adapter
->pdev
->dev
, "%s: TBD\n", __func__
);
953 static void qlcnic_83xx_idc_failed_state(struct qlcnic_adapter
*adapter
)
955 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
958 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
959 if (val
& QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY
) {
960 owner
= qlcnic_83xx_idc_find_reset_owner_id(adapter
);
961 if (ahw
->pci_func
== owner
) {
962 qlcnic_83xx_stop_hw(adapter
);
963 qlcnic_dump_fw(adapter
);
967 netdev_warn(adapter
->netdev
, "%s: Reboot will be required to recover the adapter!!\n",
969 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
970 ahw
->idc
.err_code
= -EIO
;
975 static int qlcnic_83xx_idc_quiesce_state(struct qlcnic_adapter
*adapter
)
977 dev_info(&adapter
->pdev
->dev
, "%s: TBD\n", __func__
);
981 static int qlcnic_83xx_idc_check_state_validity(struct qlcnic_adapter
*adapter
,
986 cur
= adapter
->ahw
->idc
.curr_state
;
987 prev
= adapter
->ahw
->idc
.prev_state
;
990 if ((next
< QLC_83XX_IDC_DEV_COLD
) ||
991 (next
> QLC_83XX_IDC_DEV_QUISCENT
)) {
992 dev_err(&adapter
->pdev
->dev
,
993 "%s: curr %d, prev %d, next state %d is invalid\n",
994 __func__
, cur
, prev
, state
);
998 if ((cur
== QLC_83XX_IDC_DEV_UNKNOWN
) &&
999 (prev
== QLC_83XX_IDC_DEV_UNKNOWN
)) {
1000 if ((next
!= QLC_83XX_IDC_DEV_COLD
) &&
1001 (next
!= QLC_83XX_IDC_DEV_READY
)) {
1002 dev_err(&adapter
->pdev
->dev
,
1003 "%s: failed, cur %d prev %d next %d\n",
1004 __func__
, cur
, prev
, next
);
1009 if (next
== QLC_83XX_IDC_DEV_INIT
) {
1010 if ((prev
!= QLC_83XX_IDC_DEV_INIT
) &&
1011 (prev
!= QLC_83XX_IDC_DEV_COLD
) &&
1012 (prev
!= QLC_83XX_IDC_DEV_NEED_RESET
)) {
1013 dev_err(&adapter
->pdev
->dev
,
1014 "%s: failed, cur %d prev %d next %d\n",
1015 __func__
, cur
, prev
, next
);
1023 #define QLC_83XX_ENCAP_TYPE_VXLAN BIT_1
1024 #define QLC_83XX_MATCH_ENCAP_ID BIT_2
1025 #define QLC_83XX_SET_VXLAN_UDP_DPORT BIT_3
1026 #define QLC_83XX_VXLAN_UDP_DPORT(PORT) ((PORT & 0xffff) << 16)
1028 #define QLCNIC_ENABLE_INGRESS_ENCAP_PARSING 1
1029 #define QLCNIC_DISABLE_INGRESS_ENCAP_PARSING 0
1031 static int qlcnic_set_vxlan_port(struct qlcnic_adapter
*adapter
)
1033 u16 port
= adapter
->ahw
->vxlan_port
;
1034 struct qlcnic_cmd_args cmd
;
1037 memset(&cmd
, 0, sizeof(cmd
));
1039 ret
= qlcnic_alloc_mbx_args(&cmd
, adapter
,
1040 QLCNIC_CMD_INIT_NIC_FUNC
);
1044 cmd
.req
.arg
[1] = QLC_83XX_MULTI_TENANCY_INFO
;
1045 cmd
.req
.arg
[2] = QLC_83XX_ENCAP_TYPE_VXLAN
|
1046 QLC_83XX_SET_VXLAN_UDP_DPORT
|
1047 QLC_83XX_VXLAN_UDP_DPORT(port
);
1049 ret
= qlcnic_issue_cmd(adapter
, &cmd
);
1051 netdev_err(adapter
->netdev
,
1052 "Failed to set VXLAN port %d in adapter\n",
1055 qlcnic_free_mbx_args(&cmd
);
1060 static int qlcnic_set_vxlan_parsing(struct qlcnic_adapter
*adapter
,
1063 u16 vxlan_port
= adapter
->ahw
->vxlan_port
;
1064 struct qlcnic_cmd_args cmd
;
1067 memset(&cmd
, 0, sizeof(cmd
));
1069 ret
= qlcnic_alloc_mbx_args(&cmd
, adapter
,
1070 QLCNIC_CMD_SET_INGRESS_ENCAP
);
1074 cmd
.req
.arg
[1] = state
? QLCNIC_ENABLE_INGRESS_ENCAP_PARSING
:
1075 QLCNIC_DISABLE_INGRESS_ENCAP_PARSING
;
1077 ret
= qlcnic_issue_cmd(adapter
, &cmd
);
1079 netdev_err(adapter
->netdev
,
1080 "Failed to %s VXLAN parsing for port %d\n",
1081 state
? "enable" : "disable", vxlan_port
);
1083 netdev_info(adapter
->netdev
,
1084 "%s VXLAN parsing for port %d\n",
1085 state
? "Enabled" : "Disabled", vxlan_port
);
1087 qlcnic_free_mbx_args(&cmd
);
1092 static void qlcnic_83xx_periodic_tasks(struct qlcnic_adapter
*adapter
)
1094 if (adapter
->fhash
.fnum
)
1095 qlcnic_prune_lb_filters(adapter
);
1097 if (adapter
->flags
& QLCNIC_ADD_VXLAN_PORT
) {
1098 if (qlcnic_set_vxlan_port(adapter
))
1101 if (qlcnic_set_vxlan_parsing(adapter
, true))
1104 adapter
->flags
&= ~QLCNIC_ADD_VXLAN_PORT
;
1105 } else if (adapter
->flags
& QLCNIC_DEL_VXLAN_PORT
) {
1106 if (qlcnic_set_vxlan_parsing(adapter
, false))
1109 adapter
->ahw
->vxlan_port
= 0;
1110 adapter
->flags
&= ~QLCNIC_DEL_VXLAN_PORT
;
1115 * qlcnic_83xx_idc_poll_dev_state
1117 * @work: kernel work queue structure used to schedule the function
1119 * Poll device state periodically and perform state specific
1120 * actions defined by Inter Driver Communication (IDC) protocol.
1125 void qlcnic_83xx_idc_poll_dev_state(struct work_struct
*work
)
1127 struct qlcnic_adapter
*adapter
;
1130 adapter
= container_of(work
, struct qlcnic_adapter
, fw_work
.work
);
1131 state
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
);
1133 if (qlcnic_83xx_idc_check_state_validity(adapter
, state
)) {
1134 qlcnic_83xx_idc_log_state_history(adapter
);
1135 adapter
->ahw
->idc
.curr_state
= QLC_83XX_IDC_DEV_UNKNOWN
;
1137 adapter
->ahw
->idc
.curr_state
= state
;
1140 switch (adapter
->ahw
->idc
.curr_state
) {
1141 case QLC_83XX_IDC_DEV_READY
:
1142 qlcnic_83xx_idc_ready_state(adapter
);
1144 case QLC_83XX_IDC_DEV_NEED_RESET
:
1145 qlcnic_83xx_idc_need_reset_state(adapter
);
1147 case QLC_83XX_IDC_DEV_NEED_QUISCENT
:
1148 qlcnic_83xx_idc_need_quiesce_state(adapter
);
1150 case QLC_83XX_IDC_DEV_FAILED
:
1151 qlcnic_83xx_idc_failed_state(adapter
);
1153 case QLC_83XX_IDC_DEV_INIT
:
1154 qlcnic_83xx_idc_init_state(adapter
);
1156 case QLC_83XX_IDC_DEV_QUISCENT
:
1157 qlcnic_83xx_idc_quiesce_state(adapter
);
1160 qlcnic_83xx_idc_unknown_state(adapter
);
1163 adapter
->ahw
->idc
.prev_state
= adapter
->ahw
->idc
.curr_state
;
1164 qlcnic_83xx_periodic_tasks(adapter
);
1166 /* Re-schedule the function */
1167 if (test_bit(QLC_83XX_MODULE_LOADED
, &adapter
->ahw
->idc
.status
))
1168 qlcnic_schedule_work(adapter
, qlcnic_83xx_idc_poll_dev_state
,
1169 adapter
->ahw
->idc
.delay
);
1172 static void qlcnic_83xx_setup_idc_parameters(struct qlcnic_adapter
*adapter
)
1174 u32 idc_params
, val
;
1176 if (qlcnic_83xx_flash_read32(adapter
, QLC_83XX_IDC_FLASH_PARAM_ADDR
,
1177 (u8
*)&idc_params
, 1)) {
1178 dev_info(&adapter
->pdev
->dev
,
1179 "%s:failed to get IDC params from flash\n", __func__
);
1180 adapter
->dev_init_timeo
= QLC_83XX_IDC_INIT_TIMEOUT_SECS
;
1181 adapter
->reset_ack_timeo
= QLC_83XX_IDC_RESET_TIMEOUT_SECS
;
1183 adapter
->dev_init_timeo
= idc_params
& 0xFFFF;
1184 adapter
->reset_ack_timeo
= ((idc_params
>> 16) & 0xFFFF);
1187 adapter
->ahw
->idc
.curr_state
= QLC_83XX_IDC_DEV_UNKNOWN
;
1188 adapter
->ahw
->idc
.prev_state
= QLC_83XX_IDC_DEV_UNKNOWN
;
1189 adapter
->ahw
->idc
.delay
= QLC_83XX_IDC_FW_POLL_DELAY
;
1190 adapter
->ahw
->idc
.err_code
= 0;
1191 adapter
->ahw
->idc
.collect_dump
= 0;
1192 adapter
->ahw
->idc
.name
= (char **)qlc_83xx_idc_states
;
1194 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1195 set_bit(QLC_83XX_MODULE_LOADED
, &adapter
->ahw
->idc
.status
);
1197 /* Check if reset recovery is disabled */
1198 if (!qlcnic_auto_fw_reset
) {
1199 /* Propagate do not reset request to other functions */
1200 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
1201 val
= val
| QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY
;
1202 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_CTRL
, val
);
1207 qlcnic_83xx_idc_first_to_load_function_handler(struct qlcnic_adapter
*adapter
)
1211 if (qlcnic_83xx_lock_driver(adapter
))
1214 /* Clear driver lock register */
1215 QLCWRX(adapter
->ahw
, QLC_83XX_RECOVER_DRV_LOCK
, 0);
1216 if (qlcnic_83xx_idc_update_major_version(adapter
, 0)) {
1217 qlcnic_83xx_unlock_driver(adapter
);
1221 state
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
);
1222 if (qlcnic_83xx_idc_check_state_validity(adapter
, state
)) {
1223 qlcnic_83xx_unlock_driver(adapter
);
1227 if (state
!= QLC_83XX_IDC_DEV_COLD
&& qlcnic_load_fw_file
) {
1228 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
,
1229 QLC_83XX_IDC_DEV_COLD
);
1230 state
= QLC_83XX_IDC_DEV_COLD
;
1233 adapter
->ahw
->idc
.curr_state
= state
;
1234 /* First to load function should cold boot the device */
1235 if (state
== QLC_83XX_IDC_DEV_COLD
)
1236 qlcnic_83xx_idc_cold_state_handler(adapter
);
1238 /* Check if reset recovery is enabled */
1239 if (qlcnic_auto_fw_reset
) {
1240 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
1241 val
= val
& ~QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY
;
1242 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_CTRL
, val
);
1245 qlcnic_83xx_unlock_driver(adapter
);
1250 int qlcnic_83xx_idc_init(struct qlcnic_adapter
*adapter
)
1254 qlcnic_83xx_setup_idc_parameters(adapter
);
1256 if (qlcnic_83xx_get_reset_instruction_template(adapter
))
1259 if (!qlcnic_83xx_idc_check_driver_presence_reg(adapter
)) {
1260 if (qlcnic_83xx_idc_first_to_load_function_handler(adapter
))
1263 if (qlcnic_83xx_idc_check_major_version(adapter
))
1267 qlcnic_83xx_idc_update_audit_reg(adapter
, 0, 1);
1272 void qlcnic_83xx_idc_exit(struct qlcnic_adapter
*adapter
)
1277 while (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1278 usleep_range(10000, 11000);
1280 id
= QLCRDX(adapter
->ahw
, QLC_83XX_DRV_LOCK_ID
);
1283 if (id
== adapter
->portnum
) {
1284 dev_err(&adapter
->pdev
->dev
,
1285 "%s: wait for lock recovery.. %d\n", __func__
, id
);
1287 id
= QLCRDX(adapter
->ahw
, QLC_83XX_DRV_LOCK_ID
);
1291 /* Clear driver presence bit */
1292 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
);
1293 val
= val
& ~(1 << adapter
->portnum
);
1294 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
, val
);
1295 clear_bit(QLC_83XX_MODULE_LOADED
, &adapter
->ahw
->idc
.status
);
1296 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1298 cancel_delayed_work_sync(&adapter
->fw_work
);
1301 void qlcnic_83xx_idc_request_reset(struct qlcnic_adapter
*adapter
, u32 key
)
1305 if (qlcnic_sriov_vf_check(adapter
))
1308 if (qlcnic_83xx_lock_driver(adapter
)) {
1309 dev_err(&adapter
->pdev
->dev
,
1310 "%s:failed, please retry\n", __func__
);
1314 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
1315 if (val
& QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY
) {
1316 netdev_info(adapter
->netdev
, "%s: Auto firmware recovery is disabled\n",
1318 qlcnic_83xx_idc_enter_failed_state(adapter
, 0);
1319 qlcnic_83xx_unlock_driver(adapter
);
1323 if (key
== QLCNIC_FORCE_FW_RESET
) {
1324 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
1325 val
= val
| QLC_83XX_IDC_GRACEFULL_RESET
;
1326 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_CTRL
, val
);
1327 } else if (key
== QLCNIC_FORCE_FW_DUMP_KEY
) {
1328 adapter
->ahw
->idc
.collect_dump
= 1;
1331 qlcnic_83xx_unlock_driver(adapter
);
1335 static int qlcnic_83xx_copy_bootloader(struct qlcnic_adapter
*adapter
)
1342 src
= QLC_83XX_BOOTLOADER_FLASH_ADDR
;
1343 dest
= QLCRDX(adapter
->ahw
, QLCNIC_BOOTLOADER_ADDR
);
1344 size
= QLCRDX(adapter
->ahw
, QLCNIC_BOOTLOADER_SIZE
);
1346 /* alignment check */
1348 size
= (size
+ 16) & ~0xF;
1350 p_cache
= vzalloc(size
);
1351 if (p_cache
== NULL
)
1354 ret
= qlcnic_83xx_lockless_flash_read32(adapter
, src
, p_cache
,
1355 size
/ sizeof(u32
));
1360 /* 16 byte write to MS memory */
1361 ret
= qlcnic_ms_mem_write128(adapter
, dest
, (u32
*)p_cache
,
1372 static int qlcnic_83xx_copy_fw_file(struct qlcnic_adapter
*adapter
)
1374 struct qlc_83xx_fw_info
*fw_info
= adapter
->ahw
->fw_info
;
1375 const struct firmware
*fw
= fw_info
->fw
;
1376 u32 dest
, *p_cache
, *temp
;
1383 temp
= vzalloc(fw
->size
);
1385 release_firmware(fw
);
1390 temp_le
= (__le32
*)fw
->data
;
1392 /* FW image in file is in little endian, swap the data to nullify
1393 * the effect of writel() operation on big endian platform.
1395 for (i
= 0; i
< fw
->size
/ sizeof(u32
); i
++)
1396 temp
[i
] = __le32_to_cpu(temp_le
[i
]);
1398 dest
= QLCRDX(adapter
->ahw
, QLCNIC_FW_IMAGE_ADDR
);
1399 size
= (fw
->size
& ~0xF);
1403 ret
= qlcnic_ms_mem_write128(adapter
, addr
,
1404 p_cache
, size
/ 16);
1406 dev_err(&adapter
->pdev
->dev
, "MS memory write failed\n");
1410 /* alignment check */
1411 if (fw
->size
& 0xF) {
1413 for (i
= 0; i
< (fw
->size
& 0xF); i
++)
1414 data
[i
] = ((u8
*)temp
)[size
+ i
];
1417 ret
= qlcnic_ms_mem_write128(adapter
, addr
,
1420 dev_err(&adapter
->pdev
->dev
,
1421 "MS memory write failed\n");
1427 release_firmware(fw
);
1434 static void qlcnic_83xx_dump_pause_control_regs(struct qlcnic_adapter
*adapter
)
1437 u32 val
= 0, val1
= 0, reg
= 0;
1440 val
= QLCRD32(adapter
, QLC_83XX_SRE_SHIM_REG
, &err
);
1443 dev_info(&adapter
->pdev
->dev
, "SRE-Shim Ctrl:0x%x\n", val
);
1445 for (j
= 0; j
< 2; j
++) {
1447 dev_info(&adapter
->pdev
->dev
,
1448 "Port 0 RxB Pause Threshold Regs[TC7..TC0]:");
1449 reg
= QLC_83XX_PORT0_THRESHOLD
;
1450 } else if (j
== 1) {
1451 dev_info(&adapter
->pdev
->dev
,
1452 "Port 1 RxB Pause Threshold Regs[TC7..TC0]:");
1453 reg
= QLC_83XX_PORT1_THRESHOLD
;
1455 for (i
= 0; i
< 8; i
++) {
1456 val
= QLCRD32(adapter
, reg
+ (i
* 0x4), &err
);
1459 dev_info(&adapter
->pdev
->dev
, "0x%x ", val
);
1461 dev_info(&adapter
->pdev
->dev
, "\n");
1464 for (j
= 0; j
< 2; j
++) {
1466 dev_info(&adapter
->pdev
->dev
,
1467 "Port 0 RxB TC Max Cell Registers[4..1]:");
1468 reg
= QLC_83XX_PORT0_TC_MC_REG
;
1469 } else if (j
== 1) {
1470 dev_info(&adapter
->pdev
->dev
,
1471 "Port 1 RxB TC Max Cell Registers[4..1]:");
1472 reg
= QLC_83XX_PORT1_TC_MC_REG
;
1474 for (i
= 0; i
< 4; i
++) {
1475 val
= QLCRD32(adapter
, reg
+ (i
* 0x4), &err
);
1478 dev_info(&adapter
->pdev
->dev
, "0x%x ", val
);
1480 dev_info(&adapter
->pdev
->dev
, "\n");
1483 for (j
= 0; j
< 2; j
++) {
1485 dev_info(&adapter
->pdev
->dev
,
1486 "Port 0 RxB Rx TC Stats[TC7..TC0]:");
1487 reg
= QLC_83XX_PORT0_TC_STATS
;
1488 } else if (j
== 1) {
1489 dev_info(&adapter
->pdev
->dev
,
1490 "Port 1 RxB Rx TC Stats[TC7..TC0]:");
1491 reg
= QLC_83XX_PORT1_TC_STATS
;
1493 for (i
= 7; i
>= 0; i
--) {
1494 val
= QLCRD32(adapter
, reg
, &err
);
1497 val
&= ~(0x7 << 29); /* Reset bits 29 to 31 */
1498 QLCWR32(adapter
, reg
, (val
| (i
<< 29)));
1499 val
= QLCRD32(adapter
, reg
, &err
);
1502 dev_info(&adapter
->pdev
->dev
, "0x%x ", val
);
1504 dev_info(&adapter
->pdev
->dev
, "\n");
1507 val
= QLCRD32(adapter
, QLC_83XX_PORT2_IFB_THRESHOLD
, &err
);
1510 val1
= QLCRD32(adapter
, QLC_83XX_PORT3_IFB_THRESHOLD
, &err
);
1513 dev_info(&adapter
->pdev
->dev
,
1514 "IFB-Pause Thresholds: Port 2:0x%x, Port 3:0x%x\n",
1519 static void qlcnic_83xx_disable_pause_frames(struct qlcnic_adapter
*adapter
)
1523 if (qlcnic_83xx_lock_driver(adapter
)) {
1524 dev_err(&adapter
->pdev
->dev
,
1525 "%s:failed to acquire driver lock\n", __func__
);
1529 qlcnic_83xx_dump_pause_control_regs(adapter
);
1530 QLCWR32(adapter
, QLC_83XX_SRE_SHIM_REG
, 0x0);
1532 for (j
= 0; j
< 2; j
++) {
1534 reg
= QLC_83XX_PORT0_THRESHOLD
;
1536 reg
= QLC_83XX_PORT1_THRESHOLD
;
1538 for (i
= 0; i
< 8; i
++)
1539 QLCWR32(adapter
, reg
+ (i
* 0x4), 0x0);
1542 for (j
= 0; j
< 2; j
++) {
1544 reg
= QLC_83XX_PORT0_TC_MC_REG
;
1546 reg
= QLC_83XX_PORT1_TC_MC_REG
;
1548 for (i
= 0; i
< 4; i
++)
1549 QLCWR32(adapter
, reg
+ (i
* 0x4), 0x03FF03FF);
1552 QLCWR32(adapter
, QLC_83XX_PORT2_IFB_THRESHOLD
, 0);
1553 QLCWR32(adapter
, QLC_83XX_PORT3_IFB_THRESHOLD
, 0);
1554 dev_info(&adapter
->pdev
->dev
,
1555 "Disabled pause frames successfully on all ports\n");
1556 qlcnic_83xx_unlock_driver(adapter
);
1559 static void qlcnic_83xx_take_eport_out_of_reset(struct qlcnic_adapter
*adapter
)
1561 QLCWR32(adapter
, QLC_83XX_RESET_REG
, 0);
1562 QLCWR32(adapter
, QLC_83XX_RESET_PORT0
, 0);
1563 QLCWR32(adapter
, QLC_83XX_RESET_PORT1
, 0);
1564 QLCWR32(adapter
, QLC_83XX_RESET_PORT2
, 0);
1565 QLCWR32(adapter
, QLC_83XX_RESET_PORT3
, 0);
1566 QLCWR32(adapter
, QLC_83XX_RESET_SRESHIM
, 0);
1567 QLCWR32(adapter
, QLC_83XX_RESET_EPGSHIM
, 0);
1568 QLCWR32(adapter
, QLC_83XX_RESET_ETHERPCS
, 0);
1569 QLCWR32(adapter
, QLC_83XX_RESET_CONTROL
, 1);
1572 static int qlcnic_83xx_check_heartbeat(struct qlcnic_adapter
*p_dev
)
1574 u32 heartbeat
, peg_status
;
1575 int retries
, ret
= -EIO
, err
= 0;
1577 retries
= QLCNIC_HEARTBEAT_CHECK_RETRY_COUNT
;
1578 p_dev
->heartbeat
= QLC_SHARED_REG_RD32(p_dev
,
1579 QLCNIC_PEG_ALIVE_COUNTER
);
1582 msleep(QLCNIC_HEARTBEAT_PERIOD_MSECS
);
1583 heartbeat
= QLC_SHARED_REG_RD32(p_dev
,
1584 QLCNIC_PEG_ALIVE_COUNTER
);
1585 if (heartbeat
!= p_dev
->heartbeat
) {
1586 ret
= QLCNIC_RCODE_SUCCESS
;
1589 } while (--retries
);
1592 dev_err(&p_dev
->pdev
->dev
, "firmware hang detected\n");
1593 qlcnic_83xx_take_eport_out_of_reset(p_dev
);
1594 qlcnic_83xx_disable_pause_frames(p_dev
);
1595 peg_status
= QLC_SHARED_REG_RD32(p_dev
,
1596 QLCNIC_PEG_HALT_STATUS1
);
1597 dev_info(&p_dev
->pdev
->dev
, "Dumping HW/FW registers\n"
1598 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
1599 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
1600 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
1601 "PEG_NET_4_PC: 0x%x\n", peg_status
,
1602 QLC_SHARED_REG_RD32(p_dev
, QLCNIC_PEG_HALT_STATUS2
),
1603 QLCRD32(p_dev
, QLC_83XX_CRB_PEG_NET_0
, &err
),
1604 QLCRD32(p_dev
, QLC_83XX_CRB_PEG_NET_1
, &err
),
1605 QLCRD32(p_dev
, QLC_83XX_CRB_PEG_NET_2
, &err
),
1606 QLCRD32(p_dev
, QLC_83XX_CRB_PEG_NET_3
, &err
),
1607 QLCRD32(p_dev
, QLC_83XX_CRB_PEG_NET_4
, &err
));
1609 if (QLCNIC_FWERROR_CODE(peg_status
) == 0x67)
1610 dev_err(&p_dev
->pdev
->dev
,
1611 "Device is being reset err code 0x00006700.\n");
1617 static int qlcnic_83xx_check_cmd_peg_status(struct qlcnic_adapter
*p_dev
)
1619 int retries
= QLCNIC_CMDPEG_CHECK_RETRY_COUNT
;
1623 val
= QLC_SHARED_REG_RD32(p_dev
, QLCNIC_CMDPEG_STATE
);
1624 if (val
== QLC_83XX_CMDPEG_COMPLETE
)
1626 msleep(QLCNIC_CMDPEG_CHECK_DELAY
);
1627 } while (--retries
);
1629 dev_err(&p_dev
->pdev
->dev
, "%s: failed, state = 0x%x\n", __func__
, val
);
1633 static int qlcnic_83xx_check_hw_status(struct qlcnic_adapter
*p_dev
)
1637 err
= qlcnic_83xx_check_cmd_peg_status(p_dev
);
1641 err
= qlcnic_83xx_check_heartbeat(p_dev
);
1648 static int qlcnic_83xx_poll_reg(struct qlcnic_adapter
*p_dev
, u32 addr
,
1649 int duration
, u32 mask
, u32 status
)
1651 int timeout_error
, err
= 0;
1655 value
= QLCRD32(p_dev
, addr
, &err
);
1658 retries
= duration
/ 10;
1661 if ((value
& mask
) != status
) {
1663 msleep(duration
/ 10);
1664 value
= QLCRD32(p_dev
, addr
, &err
);
1671 } while (retries
--);
1673 if (timeout_error
) {
1674 p_dev
->ahw
->reset
.seq_error
++;
1675 dev_err(&p_dev
->pdev
->dev
,
1676 "%s: Timeout Err, entry_num = %d\n",
1677 __func__
, p_dev
->ahw
->reset
.seq_index
);
1678 dev_err(&p_dev
->pdev
->dev
,
1679 "0x%08x 0x%08x 0x%08x\n",
1680 value
, mask
, status
);
1683 return timeout_error
;
1686 static int qlcnic_83xx_reset_template_checksum(struct qlcnic_adapter
*p_dev
)
1689 u16
*buff
= (u16
*)p_dev
->ahw
->reset
.buff
;
1690 int count
= p_dev
->ahw
->reset
.hdr
->size
/ sizeof(u16
);
1696 sum
= (sum
& 0xFFFF) + (sum
>> 16);
1701 dev_err(&p_dev
->pdev
->dev
, "%s: failed\n", __func__
);
1706 static int qlcnic_83xx_get_reset_instruction_template(struct qlcnic_adapter
*p_dev
)
1708 struct qlcnic_hardware_context
*ahw
= p_dev
->ahw
;
1709 u32 addr
, count
, prev_ver
, curr_ver
;
1712 if (ahw
->reset
.buff
!= NULL
) {
1713 prev_ver
= p_dev
->fw_version
;
1714 curr_ver
= qlcnic_83xx_get_fw_version(p_dev
);
1715 if (curr_ver
> prev_ver
)
1716 kfree(ahw
->reset
.buff
);
1721 ahw
->reset
.seq_error
= 0;
1722 ahw
->reset
.buff
= kzalloc(QLC_83XX_RESTART_TEMPLATE_SIZE
, GFP_KERNEL
);
1723 if (p_dev
->ahw
->reset
.buff
== NULL
)
1726 p_buff
= p_dev
->ahw
->reset
.buff
;
1727 addr
= QLC_83XX_RESET_TEMPLATE_ADDR
;
1728 count
= sizeof(struct qlc_83xx_reset_hdr
) / sizeof(u32
);
1730 /* Copy template header from flash */
1731 if (qlcnic_83xx_flash_read32(p_dev
, addr
, p_buff
, count
)) {
1732 dev_err(&p_dev
->pdev
->dev
, "%s: flash read failed\n", __func__
);
1735 ahw
->reset
.hdr
= (struct qlc_83xx_reset_hdr
*)ahw
->reset
.buff
;
1736 addr
= QLC_83XX_RESET_TEMPLATE_ADDR
+ ahw
->reset
.hdr
->hdr_size
;
1737 p_buff
= ahw
->reset
.buff
+ ahw
->reset
.hdr
->hdr_size
;
1738 count
= (ahw
->reset
.hdr
->size
- ahw
->reset
.hdr
->hdr_size
) / sizeof(u32
);
1740 /* Copy rest of the template */
1741 if (qlcnic_83xx_flash_read32(p_dev
, addr
, p_buff
, count
)) {
1742 dev_err(&p_dev
->pdev
->dev
, "%s: flash read failed\n", __func__
);
1746 if (qlcnic_83xx_reset_template_checksum(p_dev
))
1748 /* Get Stop, Start and Init command offsets */
1749 ahw
->reset
.init_offset
= ahw
->reset
.buff
+ ahw
->reset
.hdr
->init_offset
;
1750 ahw
->reset
.start_offset
= ahw
->reset
.buff
+
1751 ahw
->reset
.hdr
->start_offset
;
1752 ahw
->reset
.stop_offset
= ahw
->reset
.buff
+ ahw
->reset
.hdr
->hdr_size
;
1756 /* Read Write HW register command */
1757 static void qlcnic_83xx_read_write_crb_reg(struct qlcnic_adapter
*p_dev
,
1758 u32 raddr
, u32 waddr
)
1763 value
= QLCRD32(p_dev
, raddr
, &err
);
1766 qlcnic_83xx_wrt_reg_indirect(p_dev
, waddr
, value
);
1769 /* Read Modify Write HW register command */
1770 static void qlcnic_83xx_rmw_crb_reg(struct qlcnic_adapter
*p_dev
,
1771 u32 raddr
, u32 waddr
,
1772 struct qlc_83xx_rmw
*p_rmw_hdr
)
1777 if (p_rmw_hdr
->index_a
) {
1778 value
= p_dev
->ahw
->reset
.array
[p_rmw_hdr
->index_a
];
1780 value
= QLCRD32(p_dev
, raddr
, &err
);
1785 value
&= p_rmw_hdr
->mask
;
1786 value
<<= p_rmw_hdr
->shl
;
1787 value
>>= p_rmw_hdr
->shr
;
1788 value
|= p_rmw_hdr
->or_value
;
1789 value
^= p_rmw_hdr
->xor_value
;
1790 qlcnic_83xx_wrt_reg_indirect(p_dev
, waddr
, value
);
1793 /* Write HW register command */
1794 static void qlcnic_83xx_write_list(struct qlcnic_adapter
*p_dev
,
1795 struct qlc_83xx_entry_hdr
*p_hdr
)
1798 struct qlc_83xx_entry
*entry
;
1800 entry
= (struct qlc_83xx_entry
*)((char *)p_hdr
+
1801 sizeof(struct qlc_83xx_entry_hdr
));
1803 for (i
= 0; i
< p_hdr
->count
; i
++, entry
++) {
1804 qlcnic_83xx_wrt_reg_indirect(p_dev
, entry
->arg1
,
1807 udelay((u32
)(p_hdr
->delay
));
1811 /* Read and Write instruction */
1812 static void qlcnic_83xx_read_write_list(struct qlcnic_adapter
*p_dev
,
1813 struct qlc_83xx_entry_hdr
*p_hdr
)
1816 struct qlc_83xx_entry
*entry
;
1818 entry
= (struct qlc_83xx_entry
*)((char *)p_hdr
+
1819 sizeof(struct qlc_83xx_entry_hdr
));
1821 for (i
= 0; i
< p_hdr
->count
; i
++, entry
++) {
1822 qlcnic_83xx_read_write_crb_reg(p_dev
, entry
->arg1
,
1825 udelay((u32
)(p_hdr
->delay
));
1829 /* Poll HW register command */
1830 static void qlcnic_83xx_poll_list(struct qlcnic_adapter
*p_dev
,
1831 struct qlc_83xx_entry_hdr
*p_hdr
)
1834 struct qlc_83xx_entry
*entry
;
1835 struct qlc_83xx_poll
*poll
;
1837 unsigned long arg1
, arg2
;
1839 poll
= (struct qlc_83xx_poll
*)((char *)p_hdr
+
1840 sizeof(struct qlc_83xx_entry_hdr
));
1842 entry
= (struct qlc_83xx_entry
*)((char *)poll
+
1843 sizeof(struct qlc_83xx_poll
));
1844 delay
= (long)p_hdr
->delay
;
1847 for (i
= 0; i
< p_hdr
->count
; i
++, entry
++)
1848 qlcnic_83xx_poll_reg(p_dev
, entry
->arg1
,
1852 for (i
= 0; i
< p_hdr
->count
; i
++, entry
++) {
1856 if (qlcnic_83xx_poll_reg(p_dev
,
1860 QLCRD32(p_dev
, arg1
, &err
);
1863 QLCRD32(p_dev
, arg2
, &err
);
1872 /* Poll and write HW register command */
1873 static void qlcnic_83xx_poll_write_list(struct qlcnic_adapter
*p_dev
,
1874 struct qlc_83xx_entry_hdr
*p_hdr
)
1878 struct qlc_83xx_quad_entry
*entry
;
1879 struct qlc_83xx_poll
*poll
;
1881 poll
= (struct qlc_83xx_poll
*)((char *)p_hdr
+
1882 sizeof(struct qlc_83xx_entry_hdr
));
1883 entry
= (struct qlc_83xx_quad_entry
*)((char *)poll
+
1884 sizeof(struct qlc_83xx_poll
));
1885 delay
= (long)p_hdr
->delay
;
1887 for (i
= 0; i
< p_hdr
->count
; i
++, entry
++) {
1888 qlcnic_83xx_wrt_reg_indirect(p_dev
, entry
->dr_addr
,
1890 qlcnic_83xx_wrt_reg_indirect(p_dev
, entry
->ar_addr
,
1893 qlcnic_83xx_poll_reg(p_dev
, entry
->ar_addr
, delay
,
1894 poll
->mask
, poll
->status
);
1898 /* Read Modify Write register command */
1899 static void qlcnic_83xx_read_modify_write(struct qlcnic_adapter
*p_dev
,
1900 struct qlc_83xx_entry_hdr
*p_hdr
)
1903 struct qlc_83xx_entry
*entry
;
1904 struct qlc_83xx_rmw
*rmw_hdr
;
1906 rmw_hdr
= (struct qlc_83xx_rmw
*)((char *)p_hdr
+
1907 sizeof(struct qlc_83xx_entry_hdr
));
1909 entry
= (struct qlc_83xx_entry
*)((char *)rmw_hdr
+
1910 sizeof(struct qlc_83xx_rmw
));
1912 for (i
= 0; i
< p_hdr
->count
; i
++, entry
++) {
1913 qlcnic_83xx_rmw_crb_reg(p_dev
, entry
->arg1
,
1914 entry
->arg2
, rmw_hdr
);
1916 udelay((u32
)(p_hdr
->delay
));
1920 static void qlcnic_83xx_pause(struct qlc_83xx_entry_hdr
*p_hdr
)
1923 mdelay((u32
)((long)p_hdr
->delay
));
1926 /* Read and poll register command */
1927 static void qlcnic_83xx_poll_read_list(struct qlcnic_adapter
*p_dev
,
1928 struct qlc_83xx_entry_hdr
*p_hdr
)
1931 int index
, i
, j
, err
;
1932 struct qlc_83xx_quad_entry
*entry
;
1933 struct qlc_83xx_poll
*poll
;
1936 poll
= (struct qlc_83xx_poll
*)((char *)p_hdr
+
1937 sizeof(struct qlc_83xx_entry_hdr
));
1939 entry
= (struct qlc_83xx_quad_entry
*)((char *)poll
+
1940 sizeof(struct qlc_83xx_poll
));
1941 delay
= (long)p_hdr
->delay
;
1943 for (i
= 0; i
< p_hdr
->count
; i
++, entry
++) {
1944 qlcnic_83xx_wrt_reg_indirect(p_dev
, entry
->ar_addr
,
1947 if (!qlcnic_83xx_poll_reg(p_dev
, entry
->ar_addr
, delay
,
1948 poll
->mask
, poll
->status
)){
1949 index
= p_dev
->ahw
->reset
.array_index
;
1950 addr
= entry
->dr_addr
;
1951 j
= QLCRD32(p_dev
, addr
, &err
);
1955 p_dev
->ahw
->reset
.array
[index
++] = j
;
1957 if (index
== QLC_83XX_MAX_RESET_SEQ_ENTRIES
)
1958 p_dev
->ahw
->reset
.array_index
= 1;
1964 static inline void qlcnic_83xx_seq_end(struct qlcnic_adapter
*p_dev
)
1966 p_dev
->ahw
->reset
.seq_end
= 1;
1969 static void qlcnic_83xx_template_end(struct qlcnic_adapter
*p_dev
)
1971 p_dev
->ahw
->reset
.template_end
= 1;
1972 if (p_dev
->ahw
->reset
.seq_error
== 0)
1973 dev_err(&p_dev
->pdev
->dev
,
1974 "HW restart process completed successfully.\n");
1976 dev_err(&p_dev
->pdev
->dev
,
1977 "HW restart completed with timeout errors.\n");
1981 * qlcnic_83xx_exec_template_cmd
1983 * @p_dev: adapter structure
1984 * @p_buff: Poiter to instruction template
1986 * Template provides instructions to stop, restart and initalize firmware.
1987 * These instructions are abstracted as a series of read, write and
1988 * poll operations on hardware registers. Register information and operation
1989 * specifics are not exposed to the driver. Driver reads the template from
1990 * flash and executes the instructions located at pre-defined offsets.
1994 static void qlcnic_83xx_exec_template_cmd(struct qlcnic_adapter
*p_dev
,
1998 struct qlc_83xx_entry_hdr
*p_hdr
;
1999 char *entry
= p_buff
;
2001 p_dev
->ahw
->reset
.seq_end
= 0;
2002 p_dev
->ahw
->reset
.template_end
= 0;
2003 entries
= p_dev
->ahw
->reset
.hdr
->entries
;
2004 index
= p_dev
->ahw
->reset
.seq_index
;
2006 for (; (!p_dev
->ahw
->reset
.seq_end
) && (index
< entries
); index
++) {
2007 p_hdr
= (struct qlc_83xx_entry_hdr
*)entry
;
2009 switch (p_hdr
->cmd
) {
2010 case QLC_83XX_OPCODE_NOP
:
2012 case QLC_83XX_OPCODE_WRITE_LIST
:
2013 qlcnic_83xx_write_list(p_dev
, p_hdr
);
2015 case QLC_83XX_OPCODE_READ_WRITE_LIST
:
2016 qlcnic_83xx_read_write_list(p_dev
, p_hdr
);
2018 case QLC_83XX_OPCODE_POLL_LIST
:
2019 qlcnic_83xx_poll_list(p_dev
, p_hdr
);
2021 case QLC_83XX_OPCODE_POLL_WRITE_LIST
:
2022 qlcnic_83xx_poll_write_list(p_dev
, p_hdr
);
2024 case QLC_83XX_OPCODE_READ_MODIFY_WRITE
:
2025 qlcnic_83xx_read_modify_write(p_dev
, p_hdr
);
2027 case QLC_83XX_OPCODE_SEQ_PAUSE
:
2028 qlcnic_83xx_pause(p_hdr
);
2030 case QLC_83XX_OPCODE_SEQ_END
:
2031 qlcnic_83xx_seq_end(p_dev
);
2033 case QLC_83XX_OPCODE_TMPL_END
:
2034 qlcnic_83xx_template_end(p_dev
);
2036 case QLC_83XX_OPCODE_POLL_READ_LIST
:
2037 qlcnic_83xx_poll_read_list(p_dev
, p_hdr
);
2040 dev_err(&p_dev
->pdev
->dev
,
2041 "%s: Unknown opcode 0x%04x in template %d\n",
2042 __func__
, p_hdr
->cmd
, index
);
2045 entry
+= p_hdr
->size
;
2048 p_dev
->ahw
->reset
.seq_index
= index
;
2051 static void qlcnic_83xx_stop_hw(struct qlcnic_adapter
*p_dev
)
2053 p_dev
->ahw
->reset
.seq_index
= 0;
2055 qlcnic_83xx_exec_template_cmd(p_dev
, p_dev
->ahw
->reset
.stop_offset
);
2056 if (p_dev
->ahw
->reset
.seq_end
!= 1)
2057 dev_err(&p_dev
->pdev
->dev
, "%s: failed\n", __func__
);
2060 static void qlcnic_83xx_start_hw(struct qlcnic_adapter
*p_dev
)
2062 qlcnic_83xx_exec_template_cmd(p_dev
, p_dev
->ahw
->reset
.start_offset
);
2063 if (p_dev
->ahw
->reset
.template_end
!= 1)
2064 dev_err(&p_dev
->pdev
->dev
, "%s: failed\n", __func__
);
2067 static void qlcnic_83xx_init_hw(struct qlcnic_adapter
*p_dev
)
2069 qlcnic_83xx_exec_template_cmd(p_dev
, p_dev
->ahw
->reset
.init_offset
);
2070 if (p_dev
->ahw
->reset
.seq_end
!= 1)
2071 dev_err(&p_dev
->pdev
->dev
, "%s: failed\n", __func__
);
2074 /* POST FW related definations*/
2075 #define QLC_83XX_POST_SIGNATURE_REG 0x41602014
2076 #define QLC_83XX_POST_MODE_REG 0x41602018
2077 #define QLC_83XX_POST_FAST_MODE 0
2078 #define QLC_83XX_POST_MEDIUM_MODE 1
2079 #define QLC_83XX_POST_SLOW_MODE 2
2081 /* POST Timeout values in milliseconds */
2082 #define QLC_83XX_POST_FAST_MODE_TIMEOUT 690
2083 #define QLC_83XX_POST_MED_MODE_TIMEOUT 2930
2084 #define QLC_83XX_POST_SLOW_MODE_TIMEOUT 7500
2086 /* POST result values */
2087 #define QLC_83XX_POST_PASS 0xfffffff0
2088 #define QLC_83XX_POST_ASIC_STRESS_TEST_FAIL 0xffffffff
2089 #define QLC_83XX_POST_DDR_TEST_FAIL 0xfffffffe
2090 #define QLC_83XX_POST_ASIC_MEMORY_TEST_FAIL 0xfffffffc
2091 #define QLC_83XX_POST_FLASH_TEST_FAIL 0xfffffff8
2093 static int qlcnic_83xx_run_post(struct qlcnic_adapter
*adapter
)
2095 struct qlc_83xx_fw_info
*fw_info
= adapter
->ahw
->fw_info
;
2096 struct device
*dev
= &adapter
->pdev
->dev
;
2097 int timeout
, count
, ret
= 0;
2100 /* Set timeout values with extra 2 seconds of buffer */
2101 switch (adapter
->ahw
->post_mode
) {
2102 case QLC_83XX_POST_FAST_MODE
:
2103 timeout
= QLC_83XX_POST_FAST_MODE_TIMEOUT
+ 2000;
2105 case QLC_83XX_POST_MEDIUM_MODE
:
2106 timeout
= QLC_83XX_POST_MED_MODE_TIMEOUT
+ 2000;
2108 case QLC_83XX_POST_SLOW_MODE
:
2109 timeout
= QLC_83XX_POST_SLOW_MODE_TIMEOUT
+ 2000;
2115 strncpy(fw_info
->fw_file_name
, QLC_83XX_POST_FW_FILE_NAME
,
2116 QLC_FW_FILE_NAME_LEN
);
2118 ret
= request_firmware(&fw_info
->fw
, fw_info
->fw_file_name
, dev
);
2120 dev_err(dev
, "POST firmware can not be loaded, skipping POST\n");
2124 ret
= qlcnic_83xx_copy_fw_file(adapter
);
2128 /* clear QLC_83XX_POST_SIGNATURE_REG register */
2129 qlcnic_ind_wr(adapter
, QLC_83XX_POST_SIGNATURE_REG
, 0);
2132 qlcnic_ind_wr(adapter
, QLC_83XX_POST_MODE_REG
,
2133 adapter
->ahw
->post_mode
);
2135 QLC_SHARED_REG_WR32(adapter
, QLCNIC_FW_IMG_VALID
,
2136 QLC_83XX_BOOT_FROM_FILE
);
2138 qlcnic_83xx_start_hw(adapter
);
2145 signature
= qlcnic_ind_rd(adapter
, QLC_83XX_POST_SIGNATURE_REG
);
2146 if (signature
== QLC_83XX_POST_PASS
)
2148 } while (timeout
> count
);
2150 if (timeout
<= count
) {
2151 dev_err(dev
, "POST timed out, signature = 0x%08x\n", signature
);
2155 switch (signature
) {
2156 case QLC_83XX_POST_PASS
:
2157 dev_info(dev
, "POST passed, Signature = 0x%08x\n", signature
);
2159 case QLC_83XX_POST_ASIC_STRESS_TEST_FAIL
:
2160 dev_err(dev
, "POST failed, Test case : ASIC STRESS TEST, Signature = 0x%08x\n",
2164 case QLC_83XX_POST_DDR_TEST_FAIL
:
2165 dev_err(dev
, "POST failed, Test case : DDT TEST, Signature = 0x%08x\n",
2169 case QLC_83XX_POST_ASIC_MEMORY_TEST_FAIL
:
2170 dev_err(dev
, "POST failed, Test case : ASIC MEMORY TEST, Signature = 0x%08x\n",
2174 case QLC_83XX_POST_FLASH_TEST_FAIL
:
2175 dev_err(dev
, "POST failed, Test case : FLASH TEST, Signature = 0x%08x\n",
2180 dev_err(dev
, "POST failed, Test case : INVALID, Signature = 0x%08x\n",
2189 static int qlcnic_83xx_load_fw_image_from_host(struct qlcnic_adapter
*adapter
)
2191 struct qlc_83xx_fw_info
*fw_info
= adapter
->ahw
->fw_info
;
2194 if (request_firmware(&fw_info
->fw
, fw_info
->fw_file_name
,
2195 &(adapter
->pdev
->dev
))) {
2196 dev_err(&adapter
->pdev
->dev
,
2197 "No file FW image, loading flash FW image.\n");
2198 QLC_SHARED_REG_WR32(adapter
, QLCNIC_FW_IMG_VALID
,
2199 QLC_83XX_BOOT_FROM_FLASH
);
2201 if (qlcnic_83xx_copy_fw_file(adapter
))
2203 QLC_SHARED_REG_WR32(adapter
, QLCNIC_FW_IMG_VALID
,
2204 QLC_83XX_BOOT_FROM_FILE
);
2210 static int qlcnic_83xx_restart_hw(struct qlcnic_adapter
*adapter
)
2215 qlcnic_83xx_stop_hw(adapter
);
2217 /* Collect FW register dump if required */
2218 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
2219 if (!(val
& QLC_83XX_IDC_GRACEFULL_RESET
))
2220 qlcnic_dump_fw(adapter
);
2222 if (val
& QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY
) {
2223 netdev_info(adapter
->netdev
, "%s: Auto firmware recovery is disabled\n",
2225 qlcnic_83xx_idc_enter_failed_state(adapter
, 1);
2229 qlcnic_83xx_init_hw(adapter
);
2231 if (qlcnic_83xx_copy_bootloader(adapter
))
2234 /* Check if POST needs to be run */
2235 if (adapter
->ahw
->run_post
) {
2236 err
= qlcnic_83xx_run_post(adapter
);
2240 /* No need to run POST in next reset sequence */
2241 adapter
->ahw
->run_post
= false;
2243 /* Again reset the adapter to load regular firmware */
2244 qlcnic_83xx_stop_hw(adapter
);
2245 qlcnic_83xx_init_hw(adapter
);
2247 err
= qlcnic_83xx_copy_bootloader(adapter
);
2252 /* Boot either flash image or firmware image from host file system */
2253 if (qlcnic_load_fw_file
== 1) {
2254 if (qlcnic_83xx_load_fw_image_from_host(adapter
))
2257 QLC_SHARED_REG_WR32(adapter
, QLCNIC_FW_IMG_VALID
,
2258 QLC_83XX_BOOT_FROM_FLASH
);
2261 qlcnic_83xx_start_hw(adapter
);
2262 if (qlcnic_83xx_check_hw_status(adapter
))
2268 static int qlcnic_83xx_get_nic_configuration(struct qlcnic_adapter
*adapter
)
2271 struct qlcnic_info nic_info
;
2272 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2274 memset(&nic_info
, 0, sizeof(struct qlcnic_info
));
2275 err
= qlcnic_get_nic_info(adapter
, &nic_info
, ahw
->pci_func
);
2279 ahw
->physical_port
= (u8
) nic_info
.phys_port
;
2280 ahw
->switch_mode
= nic_info
.switch_mode
;
2281 ahw
->max_tx_ques
= nic_info
.max_tx_ques
;
2282 ahw
->max_rx_ques
= nic_info
.max_rx_ques
;
2283 ahw
->capabilities
= nic_info
.capabilities
;
2284 ahw
->max_mac_filters
= nic_info
.max_mac_filters
;
2285 ahw
->max_mtu
= nic_info
.max_mtu
;
2287 /* eSwitch capability indicates vNIC mode.
2288 * vNIC and SRIOV are mutually exclusive operational modes.
2289 * If SR-IOV capability is detected, SR-IOV physical function
2290 * will get initialized in default mode.
2291 * SR-IOV virtual function initialization follows a
2292 * different code path and opmode.
2293 * SRIOV mode has precedence over vNIC mode.
2295 if (test_bit(__QLCNIC_SRIOV_CAPABLE
, &adapter
->state
))
2296 return QLC_83XX_DEFAULT_OPMODE
;
2298 if (ahw
->capabilities
& QLC_83XX_ESWITCH_CAPABILITY
)
2299 return QLCNIC_VNIC_MODE
;
2301 return QLC_83XX_DEFAULT_OPMODE
;
2304 int qlcnic_83xx_configure_opmode(struct qlcnic_adapter
*adapter
)
2306 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2307 u16 max_sds_rings
, max_tx_rings
;
2310 ret
= qlcnic_83xx_get_nic_configuration(adapter
);
2314 if (ret
== QLCNIC_VNIC_MODE
) {
2315 ahw
->nic_mode
= QLCNIC_VNIC_MODE
;
2317 if (qlcnic_83xx_config_vnic_opmode(adapter
))
2320 max_sds_rings
= QLCNIC_MAX_VNIC_SDS_RINGS
;
2321 max_tx_rings
= QLCNIC_MAX_VNIC_TX_RINGS
;
2322 } else if (ret
== QLC_83XX_DEFAULT_OPMODE
) {
2323 ahw
->nic_mode
= QLCNIC_DEFAULT_MODE
;
2324 adapter
->nic_ops
->init_driver
= qlcnic_83xx_init_default_driver
;
2325 ahw
->idc
.state_entry
= qlcnic_83xx_idc_ready_state_entry
;
2326 max_sds_rings
= QLCNIC_MAX_SDS_RINGS
;
2327 max_tx_rings
= QLCNIC_MAX_TX_RINGS
;
2329 dev_err(&adapter
->pdev
->dev
, "%s: Invalid opmode %d\n",
2334 adapter
->max_sds_rings
= min(ahw
->max_rx_ques
, max_sds_rings
);
2335 adapter
->max_tx_rings
= min(ahw
->max_tx_ques
, max_tx_rings
);
2340 static void qlcnic_83xx_config_buff_descriptors(struct qlcnic_adapter
*adapter
)
2342 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2344 if (ahw
->port_type
== QLCNIC_XGBE
) {
2345 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
2346 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_10G
;
2347 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
2348 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
2350 } else if (ahw
->port_type
== QLCNIC_GBE
) {
2351 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
2352 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
2353 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
2354 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_1G
;
2356 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
2357 adapter
->max_rds_rings
= MAX_RDS_RINGS
;
2360 static int qlcnic_83xx_init_default_driver(struct qlcnic_adapter
*adapter
)
2364 qlcnic_83xx_get_minidump_template(adapter
);
2365 if (qlcnic_83xx_get_port_info(adapter
))
2368 qlcnic_83xx_config_buff_descriptors(adapter
);
2369 adapter
->ahw
->msix_supported
= !!qlcnic_use_msi_x
;
2370 adapter
->flags
|= QLCNIC_ADAPTER_INITIALIZED
;
2372 dev_info(&adapter
->pdev
->dev
, "HAL Version: %d\n",
2373 adapter
->ahw
->fw_hal_version
);
2378 #define IS_QLC_83XX_USED(a, b, c) (((1 << a->portnum) & b) || ((c >> 6) & 0x1))
2379 static void qlcnic_83xx_clear_function_resources(struct qlcnic_adapter
*adapter
)
2381 struct qlcnic_cmd_args cmd
;
2382 u32 presence_mask
, audit_mask
;
2385 presence_mask
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
);
2386 audit_mask
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_AUDIT
);
2388 if (IS_QLC_83XX_USED(adapter
, presence_mask
, audit_mask
)) {
2389 status
= qlcnic_alloc_mbx_args(&cmd
, adapter
,
2390 QLCNIC_CMD_STOP_NIC_FUNC
);
2394 cmd
.req
.arg
[1] = BIT_31
;
2395 status
= qlcnic_issue_cmd(adapter
, &cmd
);
2397 dev_err(&adapter
->pdev
->dev
,
2398 "Failed to clean up the function resources\n");
2399 qlcnic_free_mbx_args(&cmd
);
2403 static int qlcnic_83xx_get_fw_info(struct qlcnic_adapter
*adapter
)
2405 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2406 struct pci_dev
*pdev
= adapter
->pdev
;
2407 struct qlc_83xx_fw_info
*fw_info
;
2410 ahw
->fw_info
= kzalloc(sizeof(*fw_info
), GFP_KERNEL
);
2411 if (!ahw
->fw_info
) {
2414 fw_info
= ahw
->fw_info
;
2415 switch (pdev
->device
) {
2416 case PCI_DEVICE_ID_QLOGIC_QLE834X
:
2417 case PCI_DEVICE_ID_QLOGIC_QLE8830
:
2418 strncpy(fw_info
->fw_file_name
, QLC_83XX_FW_FILE_NAME
,
2419 QLC_FW_FILE_NAME_LEN
);
2421 case PCI_DEVICE_ID_QLOGIC_QLE844X
:
2422 strncpy(fw_info
->fw_file_name
, QLC_84XX_FW_FILE_NAME
,
2423 QLC_FW_FILE_NAME_LEN
);
2426 dev_err(&pdev
->dev
, "%s: Invalid device id\n",
2436 static void qlcnic_83xx_init_rings(struct qlcnic_adapter
*adapter
)
2438 u8 rx_cnt
= QLCNIC_DEF_SDS_RINGS
;
2439 u8 tx_cnt
= QLCNIC_DEF_TX_RINGS
;
2441 adapter
->max_tx_rings
= QLCNIC_MAX_TX_RINGS
;
2442 adapter
->max_sds_rings
= QLCNIC_MAX_SDS_RINGS
;
2444 if (!adapter
->ahw
->msix_supported
) {
2445 rx_cnt
= QLCNIC_SINGLE_RING
;
2446 tx_cnt
= QLCNIC_SINGLE_RING
;
2449 /* compute and set drv sds rings */
2450 qlcnic_set_tx_ring_count(adapter
, tx_cnt
);
2451 qlcnic_set_sds_ring_count(adapter
, rx_cnt
);
2454 int qlcnic_83xx_init(struct qlcnic_adapter
*adapter
, int pci_using_dac
)
2456 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2459 adapter
->rx_mac_learn
= false;
2460 ahw
->msix_supported
= !!qlcnic_use_msi_x
;
2462 /* Check if POST needs to be run */
2463 switch (qlcnic_load_fw_file
) {
2465 ahw
->post_mode
= QLC_83XX_POST_FAST_MODE
;
2466 ahw
->run_post
= true;
2469 ahw
->post_mode
= QLC_83XX_POST_MEDIUM_MODE
;
2470 ahw
->run_post
= true;
2473 ahw
->post_mode
= QLC_83XX_POST_SLOW_MODE
;
2474 ahw
->run_post
= true;
2477 ahw
->run_post
= false;
2481 qlcnic_83xx_init_rings(adapter
);
2483 err
= qlcnic_83xx_init_mailbox_work(adapter
);
2487 if (qlcnic_sriov_vf_check(adapter
)) {
2488 err
= qlcnic_sriov_vf_init(adapter
, pci_using_dac
);
2495 if (qlcnic_83xx_read_flash_descriptor_table(adapter
) ||
2496 qlcnic_83xx_read_flash_mfg_id(adapter
)) {
2497 dev_err(&adapter
->pdev
->dev
, "Failed reading flash mfg id\n");
2498 err
= -ENOTRECOVERABLE
;
2502 err
= qlcnic_83xx_check_hw_status(adapter
);
2506 err
= qlcnic_83xx_get_fw_info(adapter
);
2510 err
= qlcnic_83xx_idc_init(adapter
);
2514 err
= qlcnic_setup_intr(adapter
);
2516 dev_err(&adapter
->pdev
->dev
, "Failed to setup interrupt\n");
2520 INIT_DELAYED_WORK(&adapter
->idc_aen_work
, qlcnic_83xx_idc_aen_work
);
2522 err
= qlcnic_83xx_setup_mbx_intr(adapter
);
2524 goto disable_mbx_intr
;
2526 qlcnic_83xx_clear_function_resources(adapter
);
2527 qlcnic_dcb_enable(adapter
->dcb
);
2528 qlcnic_83xx_initialize_nic(adapter
, 1);
2529 qlcnic_dcb_get_info(adapter
->dcb
);
2531 /* Configure default, SR-IOV or Virtual NIC mode of operation */
2532 err
= qlcnic_83xx_configure_opmode(adapter
);
2534 goto disable_mbx_intr
;
2537 /* Perform operating mode specific initialization */
2538 err
= adapter
->nic_ops
->init_driver(adapter
);
2540 goto disable_mbx_intr
;
2542 /* Periodically monitor device status */
2543 qlcnic_83xx_idc_poll_dev_state(&adapter
->fw_work
.work
);
2547 qlcnic_83xx_free_mbx_intr(adapter
);
2550 qlcnic_teardown_intr(adapter
);
2553 qlcnic_83xx_detach_mailbox_work(adapter
);
2554 qlcnic_83xx_free_mailbox(ahw
->mailbox
);
2555 ahw
->mailbox
= NULL
;
2560 void qlcnic_83xx_aer_stop_poll_work(struct qlcnic_adapter
*adapter
)
2562 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2563 struct qlc_83xx_idc
*idc
= &ahw
->idc
;
2565 clear_bit(QLC_83XX_MBX_READY
, &idc
->status
);
2566 cancel_delayed_work_sync(&adapter
->fw_work
);
2568 if (ahw
->nic_mode
== QLCNIC_VNIC_MODE
)
2569 qlcnic_83xx_disable_vnic_mode(adapter
, 1);
2571 qlcnic_83xx_idc_detach_driver(adapter
);
2572 qlcnic_83xx_initialize_nic(adapter
, 0);
2574 cancel_delayed_work_sync(&adapter
->idc_aen_work
);
2577 int qlcnic_83xx_aer_reset(struct qlcnic_adapter
*adapter
)
2579 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2580 struct qlc_83xx_idc
*idc
= &ahw
->idc
;
2584 /* Mark the previous IDC state as NEED_RESET so
2585 * that state_entry() will perform the reattachment
2586 * and bringup the device
2588 idc
->prev_state
= QLC_83XX_IDC_DEV_NEED_RESET
;
2589 owner
= qlcnic_83xx_idc_find_reset_owner_id(adapter
);
2590 if (ahw
->pci_func
== owner
) {
2591 ret
= qlcnic_83xx_restart_hw(adapter
);
2594 qlcnic_83xx_idc_clear_registers(adapter
, 0);
2597 ret
= idc
->state_entry(adapter
);
2601 void qlcnic_83xx_aer_start_poll_work(struct qlcnic_adapter
*adapter
)
2603 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2604 struct qlc_83xx_idc
*idc
= &ahw
->idc
;
2607 idc
->prev_state
= QLC_83XX_IDC_DEV_READY
;
2608 owner
= qlcnic_83xx_idc_find_reset_owner_id(adapter
);
2609 if (ahw
->pci_func
== owner
)
2610 qlcnic_83xx_idc_enter_ready_state(adapter
, 0);
2612 qlcnic_schedule_work(adapter
, qlcnic_83xx_idc_poll_dev_state
, 0);