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
);
44 struct qlc_83xx_reset_hdr
{
45 #if defined(__LITTLE_ENDIAN)
54 #elif defined(__BIG_ENDIAN)
66 /* Command entry header. */
67 struct qlc_83xx_entry_hdr
{
68 #if defined(__LITTLE_ENDIAN)
73 #elif defined(__BIG_ENDIAN)
81 /* Generic poll command */
82 struct qlc_83xx_poll
{
87 /* Read modify write command */
92 #if defined(__LITTLE_ENDIAN)
97 #elif defined(__BIG_ENDIAN)
105 /* Generic command with 2 DWORD */
106 struct qlc_83xx_entry
{
111 /* Generic command with 4 DWORD */
112 struct qlc_83xx_quad_entry
{
118 static const char *const qlc_83xx_idc_states
[] = {
130 qlcnic_83xx_idc_check_driver_presence_reg(struct qlcnic_adapter
*adapter
)
134 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
);
141 static void qlcnic_83xx_idc_log_state_history(struct qlcnic_adapter
*adapter
)
144 cur
= adapter
->ahw
->idc
.curr_state
;
145 prev
= adapter
->ahw
->idc
.prev_state
;
147 dev_info(&adapter
->pdev
->dev
,
148 "current state = %s, prev state = %s\n",
149 adapter
->ahw
->idc
.name
[cur
],
150 adapter
->ahw
->idc
.name
[prev
]);
153 static int qlcnic_83xx_idc_update_audit_reg(struct qlcnic_adapter
*adapter
,
160 if (qlcnic_83xx_lock_driver(adapter
))
164 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_AUDIT
);
165 val
|= (adapter
->portnum
& 0xf);
168 seconds
= jiffies
/ HZ
- adapter
->ahw
->idc
.sec_counter
;
170 seconds
= jiffies
/ HZ
;
173 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DRV_AUDIT
, val
);
174 adapter
->ahw
->idc
.sec_counter
= jiffies
/ HZ
;
177 qlcnic_83xx_unlock_driver(adapter
);
182 static void qlcnic_83xx_idc_update_minor_version(struct qlcnic_adapter
*adapter
)
186 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_MIN_VERSION
);
187 val
= val
& ~(0x3 << (adapter
->portnum
* 2));
188 val
= val
| (QLC_83XX_IDC_MINOR_VERSION
<< (adapter
->portnum
* 2));
189 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_MIN_VERSION
, val
);
192 static int qlcnic_83xx_idc_update_major_version(struct qlcnic_adapter
*adapter
,
198 if (qlcnic_83xx_lock_driver(adapter
))
202 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_MAJ_VERSION
);
204 val
= val
| QLC_83XX_IDC_MAJOR_VERSION
;
205 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_MAJ_VERSION
, val
);
208 qlcnic_83xx_unlock_driver(adapter
);
214 qlcnic_83xx_idc_update_drv_presence_reg(struct qlcnic_adapter
*adapter
,
215 int status
, int lock
)
220 if (qlcnic_83xx_lock_driver(adapter
))
224 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
);
227 val
= val
| (1 << adapter
->portnum
);
229 val
= val
& ~(1 << adapter
->portnum
);
231 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
, val
);
232 qlcnic_83xx_idc_update_minor_version(adapter
);
235 qlcnic_83xx_unlock_driver(adapter
);
240 static int qlcnic_83xx_idc_check_major_version(struct qlcnic_adapter
*adapter
)
245 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_MAJ_VERSION
);
246 version
= val
& 0xFF;
248 if (version
!= QLC_83XX_IDC_MAJOR_VERSION
) {
249 dev_info(&adapter
->pdev
->dev
,
250 "%s:mismatch. version 0x%x, expected version 0x%x\n",
251 __func__
, version
, QLC_83XX_IDC_MAJOR_VERSION
);
258 static int qlcnic_83xx_idc_clear_registers(struct qlcnic_adapter
*adapter
,
264 if (qlcnic_83xx_lock_driver(adapter
))
268 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DRV_ACK
, 0);
269 /* Clear gracefull reset bit */
270 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
271 val
&= ~QLC_83XX_IDC_GRACEFULL_RESET
;
272 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_CTRL
, val
);
275 qlcnic_83xx_unlock_driver(adapter
);
280 static int qlcnic_83xx_idc_update_drv_ack_reg(struct qlcnic_adapter
*adapter
,
286 if (qlcnic_83xx_lock_driver(adapter
))
290 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_ACK
);
292 val
= val
| (1 << adapter
->portnum
);
294 val
= val
& ~(1 << adapter
->portnum
);
295 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DRV_ACK
, val
);
298 qlcnic_83xx_unlock_driver(adapter
);
303 static int qlcnic_83xx_idc_check_timeout(struct qlcnic_adapter
*adapter
,
308 seconds
= jiffies
/ HZ
- adapter
->ahw
->idc
.sec_counter
;
309 if (seconds
<= time_limit
)
316 * qlcnic_83xx_idc_check_reset_ack_reg
318 * @adapter: adapter structure
320 * Check ACK wait limit and clear the functions which failed to ACK
322 * Return 0 if all functions have acknowledged the reset request.
324 static int qlcnic_83xx_idc_check_reset_ack_reg(struct qlcnic_adapter
*adapter
)
327 u32 ack
, presence
, val
;
329 timeout
= QLC_83XX_IDC_RESET_TIMEOUT_SECS
;
330 ack
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_ACK
);
331 presence
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
);
332 dev_info(&adapter
->pdev
->dev
,
333 "%s: ack = 0x%x, presence = 0x%x\n", __func__
, ack
, presence
);
334 if (!((ack
& presence
) == presence
)) {
335 if (qlcnic_83xx_idc_check_timeout(adapter
, timeout
)) {
336 /* Clear functions which failed to ACK */
337 dev_info(&adapter
->pdev
->dev
,
338 "%s: ACK wait exceeds time limit\n", __func__
);
339 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
);
340 val
= val
& ~(ack
^ presence
);
341 if (qlcnic_83xx_lock_driver(adapter
))
343 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
, val
);
344 dev_info(&adapter
->pdev
->dev
,
345 "%s: updated drv presence reg = 0x%x\n",
347 qlcnic_83xx_unlock_driver(adapter
);
354 dev_info(&adapter
->pdev
->dev
,
355 "%s: Reset ACK received from all functions\n",
362 * qlcnic_83xx_idc_tx_soft_reset
364 * @adapter: adapter structure
366 * Handle context deletion and recreation request from transmit routine
368 * Returns -EBUSY or Success (0)
371 static int qlcnic_83xx_idc_tx_soft_reset(struct qlcnic_adapter
*adapter
)
373 struct net_device
*netdev
= adapter
->netdev
;
375 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
378 netif_device_detach(netdev
);
379 qlcnic_down(adapter
, netdev
);
380 qlcnic_up(adapter
, netdev
);
381 netif_device_attach(netdev
);
382 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
383 dev_err(&adapter
->pdev
->dev
, "%s:\n", __func__
);
389 * qlcnic_83xx_idc_detach_driver
391 * @adapter: adapter structure
392 * Detach net interface, stop TX and cleanup resources before the HW reset.
396 static void qlcnic_83xx_idc_detach_driver(struct qlcnic_adapter
*adapter
)
399 struct net_device
*netdev
= adapter
->netdev
;
401 netif_device_detach(netdev
);
402 qlcnic_83xx_detach_mailbox_work(adapter
);
404 /* Disable mailbox interrupt */
405 qlcnic_83xx_disable_mbx_intr(adapter
);
406 qlcnic_down(adapter
, netdev
);
407 for (i
= 0; i
< adapter
->ahw
->num_msix
; i
++) {
408 adapter
->ahw
->intr_tbl
[i
].id
= i
;
409 adapter
->ahw
->intr_tbl
[i
].enabled
= 0;
410 adapter
->ahw
->intr_tbl
[i
].src
= 0;
413 if (qlcnic_sriov_pf_check(adapter
))
414 qlcnic_sriov_pf_reset(adapter
);
418 * qlcnic_83xx_idc_attach_driver
420 * @adapter: adapter structure
422 * Re-attach and re-enable net interface
426 static void qlcnic_83xx_idc_attach_driver(struct qlcnic_adapter
*adapter
)
428 struct net_device
*netdev
= adapter
->netdev
;
430 if (netif_running(netdev
)) {
431 if (qlcnic_up(adapter
, netdev
))
433 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
436 netif_device_attach(netdev
);
439 static int qlcnic_83xx_idc_enter_failed_state(struct qlcnic_adapter
*adapter
,
443 if (qlcnic_83xx_lock_driver(adapter
))
447 qlcnic_83xx_idc_clear_registers(adapter
, 0);
448 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
, QLC_83XX_IDC_DEV_FAILED
);
450 qlcnic_83xx_unlock_driver(adapter
);
452 qlcnic_83xx_idc_log_state_history(adapter
);
453 dev_info(&adapter
->pdev
->dev
, "Device will enter failed state\n");
458 static int qlcnic_83xx_idc_enter_init_state(struct qlcnic_adapter
*adapter
,
462 if (qlcnic_83xx_lock_driver(adapter
))
466 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
, QLC_83XX_IDC_DEV_INIT
);
469 qlcnic_83xx_unlock_driver(adapter
);
474 static int qlcnic_83xx_idc_enter_need_quiesce(struct qlcnic_adapter
*adapter
,
478 if (qlcnic_83xx_lock_driver(adapter
))
482 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
,
483 QLC_83XX_IDC_DEV_NEED_QUISCENT
);
486 qlcnic_83xx_unlock_driver(adapter
);
492 qlcnic_83xx_idc_enter_need_reset_state(struct qlcnic_adapter
*adapter
, int lock
)
495 if (qlcnic_83xx_lock_driver(adapter
))
499 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
,
500 QLC_83XX_IDC_DEV_NEED_RESET
);
503 qlcnic_83xx_unlock_driver(adapter
);
508 static int qlcnic_83xx_idc_enter_ready_state(struct qlcnic_adapter
*adapter
,
512 if (qlcnic_83xx_lock_driver(adapter
))
516 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
, QLC_83XX_IDC_DEV_READY
);
518 qlcnic_83xx_unlock_driver(adapter
);
524 * qlcnic_83xx_idc_find_reset_owner_id
526 * @adapter: adapter structure
528 * NIC gets precedence over ISCSI and ISCSI has precedence over FCOE.
529 * Within the same class, function with lowest PCI ID assumes ownership
531 * Returns: reset owner id or failure indication (-EIO)
534 static int qlcnic_83xx_idc_find_reset_owner_id(struct qlcnic_adapter
*adapter
)
536 u32 reg
, reg1
, reg2
, i
, j
, owner
, class;
538 reg1
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DEV_PARTITION_INFO_1
);
539 reg2
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DEV_PARTITION_INFO_2
);
540 owner
= QLCNIC_TYPE_NIC
;
546 class = (((reg
& (0xF << j
* 4)) >> j
* 4) & 0x3);
549 if (i
== (QLC_83XX_IDC_MAX_FUNC_PER_PARTITION_INFO
- 1)) {
556 if (i
== (QLC_83XX_IDC_MAX_CNA_FUNCTIONS
- 1)) {
557 if (owner
== QLCNIC_TYPE_NIC
)
558 owner
= QLCNIC_TYPE_ISCSI
;
559 else if (owner
== QLCNIC_TYPE_ISCSI
)
560 owner
= QLCNIC_TYPE_FCOE
;
561 else if (owner
== QLCNIC_TYPE_FCOE
)
567 } while (i
++ < QLC_83XX_IDC_MAX_CNA_FUNCTIONS
);
572 static int qlcnic_83xx_idc_restart_hw(struct qlcnic_adapter
*adapter
, int lock
)
576 ret
= qlcnic_83xx_restart_hw(adapter
);
579 qlcnic_83xx_idc_enter_failed_state(adapter
, lock
);
581 qlcnic_83xx_idc_clear_registers(adapter
, lock
);
582 ret
= qlcnic_83xx_idc_enter_ready_state(adapter
, lock
);
588 static int qlcnic_83xx_idc_check_fan_failure(struct qlcnic_adapter
*adapter
)
592 status
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
594 if (status
& QLCNIC_RCODE_FATAL_ERROR
) {
595 dev_err(&adapter
->pdev
->dev
,
596 "peg halt status1=0x%x\n", status
);
597 if (QLCNIC_FWERROR_CODE(status
) == QLCNIC_FWERROR_FAN_FAILURE
) {
598 dev_err(&adapter
->pdev
->dev
,
599 "On board active cooling fan failed. "
600 "Device has been halted.\n");
601 dev_err(&adapter
->pdev
->dev
,
602 "Replace the adapter.\n");
610 int qlcnic_83xx_idc_reattach_driver(struct qlcnic_adapter
*adapter
)
614 qlcnic_83xx_reinit_mbx_work(adapter
->ahw
->mailbox
);
615 qlcnic_83xx_enable_mbx_interrupt(adapter
);
617 /* register for NIC IDC AEN Events */
618 qlcnic_83xx_register_nic_idc_func(adapter
, 1);
620 err
= qlcnic_sriov_pf_reinit(adapter
);
624 qlcnic_83xx_enable_mbx_interrupt(adapter
);
626 if (qlcnic_83xx_configure_opmode(adapter
)) {
627 qlcnic_83xx_idc_enter_failed_state(adapter
, 1);
631 if (adapter
->nic_ops
->init_driver(adapter
)) {
632 qlcnic_83xx_idc_enter_failed_state(adapter
, 1);
636 if (adapter
->portnum
== 0)
637 qlcnic_set_drv_version(adapter
);
639 qlcnic_dcb_get_info(adapter
);
640 qlcnic_83xx_idc_attach_driver(adapter
);
645 static void qlcnic_83xx_idc_update_idc_params(struct qlcnic_adapter
*adapter
)
647 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
649 qlcnic_83xx_idc_update_drv_presence_reg(adapter
, 1, 1);
650 qlcnic_83xx_idc_update_audit_reg(adapter
, 0, 1);
651 set_bit(QLC_83XX_MODULE_LOADED
, &adapter
->ahw
->idc
.status
);
653 ahw
->idc
.quiesce_req
= 0;
654 ahw
->idc
.delay
= QLC_83XX_IDC_FW_POLL_DELAY
;
655 ahw
->idc
.err_code
= 0;
656 ahw
->idc
.collect_dump
= 0;
657 ahw
->reset_context
= 0;
658 adapter
->tx_timeo_cnt
= 0;
659 ahw
->idc
.delay_reset
= 0;
661 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
665 * qlcnic_83xx_idc_ready_state_entry
667 * @adapter: adapter structure
669 * Perform ready state initialization, this routine will get invoked only
670 * once from READY state.
672 * Returns: Error code or Success(0)
675 int qlcnic_83xx_idc_ready_state_entry(struct qlcnic_adapter
*adapter
)
677 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
679 if (ahw
->idc
.prev_state
!= QLC_83XX_IDC_DEV_READY
) {
680 qlcnic_83xx_idc_update_idc_params(adapter
);
681 /* Re-attach the device if required */
682 if ((ahw
->idc
.prev_state
== QLC_83XX_IDC_DEV_NEED_RESET
) ||
683 (ahw
->idc
.prev_state
== QLC_83XX_IDC_DEV_INIT
)) {
684 if (qlcnic_83xx_idc_reattach_driver(adapter
))
693 * qlcnic_83xx_idc_vnic_pf_entry
695 * @adapter: adapter structure
697 * Ensure vNIC mode privileged function starts only after vNIC mode is
698 * enabled by management function.
699 * If vNIC mode is ready, start initialization.
704 int qlcnic_83xx_idc_vnic_pf_entry(struct qlcnic_adapter
*adapter
)
707 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
709 /* Privileged function waits till mgmt function enables VNIC mode */
710 state
= QLCRDX(adapter
->ahw
, QLC_83XX_VNIC_STATE
);
711 if (state
!= QLCNIC_DEV_NPAR_OPER
) {
712 if (!ahw
->idc
.vnic_wait_limit
--) {
713 qlcnic_83xx_idc_enter_failed_state(adapter
, 1);
716 dev_info(&adapter
->pdev
->dev
, "vNIC mode disabled\n");
720 /* Perform one time initialization from ready state */
721 if (ahw
->idc
.vnic_state
!= QLCNIC_DEV_NPAR_OPER
) {
722 qlcnic_83xx_idc_update_idc_params(adapter
);
724 /* If the previous state is UNKNOWN, device will be
725 already attached properly by Init routine*/
726 if (ahw
->idc
.prev_state
!= QLC_83XX_IDC_DEV_UNKNOWN
) {
727 if (qlcnic_83xx_idc_reattach_driver(adapter
))
730 adapter
->ahw
->idc
.vnic_state
= QLCNIC_DEV_NPAR_OPER
;
731 dev_info(&adapter
->pdev
->dev
, "vNIC mode enabled\n");
738 static int qlcnic_83xx_idc_unknown_state(struct qlcnic_adapter
*adapter
)
740 adapter
->ahw
->idc
.err_code
= -EIO
;
741 dev_err(&adapter
->pdev
->dev
,
742 "%s: Device in unknown state\n", __func__
);
747 * qlcnic_83xx_idc_cold_state
749 * @adapter: adapter structure
751 * If HW is up and running device will enter READY state.
752 * If firmware image from host needs to be loaded, device is
753 * forced to start with the file firmware image.
755 * Returns: Error code or Success(0)
758 static int qlcnic_83xx_idc_cold_state_handler(struct qlcnic_adapter
*adapter
)
760 qlcnic_83xx_idc_update_drv_presence_reg(adapter
, 1, 0);
761 qlcnic_83xx_idc_update_audit_reg(adapter
, 1, 0);
763 if (qlcnic_load_fw_file
) {
764 qlcnic_83xx_idc_restart_hw(adapter
, 0);
766 if (qlcnic_83xx_check_hw_status(adapter
)) {
767 qlcnic_83xx_idc_enter_failed_state(adapter
, 0);
770 qlcnic_83xx_idc_enter_ready_state(adapter
, 0);
777 * qlcnic_83xx_idc_init_state
779 * @adapter: adapter structure
781 * Reset owner will restart the device from this state.
782 * Device will enter failed state if it remains
783 * in this state for more than DEV_INIT time limit.
785 * Returns: Error code or Success(0)
788 static int qlcnic_83xx_idc_init_state(struct qlcnic_adapter
*adapter
)
790 int timeout
, ret
= 0;
793 timeout
= QLC_83XX_IDC_INIT_TIMEOUT_SECS
;
794 if (adapter
->ahw
->idc
.prev_state
== QLC_83XX_IDC_DEV_NEED_RESET
) {
795 owner
= qlcnic_83xx_idc_find_reset_owner_id(adapter
);
796 if (adapter
->ahw
->pci_func
== owner
)
797 ret
= qlcnic_83xx_idc_restart_hw(adapter
, 1);
799 ret
= qlcnic_83xx_idc_check_timeout(adapter
, timeout
);
806 * qlcnic_83xx_idc_ready_state
808 * @adapter: adapter structure
810 * Perform IDC protocol specicifed actions after monitoring device state and
813 * Returns: Error code or Success(0)
816 static int qlcnic_83xx_idc_ready_state(struct qlcnic_adapter
*adapter
)
818 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
819 struct qlcnic_mailbox
*mbx
= ahw
->mailbox
;
823 /* Perform NIC configuration based ready state entry actions */
824 if (ahw
->idc
.state_entry(adapter
))
827 if (qlcnic_check_temp(adapter
)) {
828 if (ahw
->temp
== QLCNIC_TEMP_PANIC
) {
829 qlcnic_83xx_idc_check_fan_failure(adapter
);
830 dev_err(&adapter
->pdev
->dev
,
831 "Error: device temperature %d above limits\n",
833 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
834 set_bit(__QLCNIC_RESETTING
, &adapter
->state
);
835 qlcnic_83xx_idc_detach_driver(adapter
);
836 qlcnic_83xx_idc_enter_failed_state(adapter
, 1);
841 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
842 ret
= qlcnic_83xx_check_heartbeat(adapter
);
844 adapter
->flags
|= QLCNIC_FW_HANG
;
845 if (!(val
& QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY
)) {
846 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
847 set_bit(__QLCNIC_RESETTING
, &adapter
->state
);
848 qlcnic_83xx_idc_enter_need_reset_state(adapter
, 1);
853 if ((val
& QLC_83XX_IDC_GRACEFULL_RESET
) || ahw
->idc
.collect_dump
) {
854 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
856 /* Move to need reset state and prepare for reset */
857 qlcnic_83xx_idc_enter_need_reset_state(adapter
, 1);
861 /* Check for soft reset request */
862 if (ahw
->reset_context
&&
863 !(val
& QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY
)) {
864 adapter
->ahw
->reset_context
= 0;
865 qlcnic_83xx_idc_tx_soft_reset(adapter
);
869 /* Move to need quiesce state if requested */
870 if (adapter
->ahw
->idc
.quiesce_req
) {
871 qlcnic_83xx_idc_enter_need_quiesce(adapter
, 1);
872 qlcnic_83xx_idc_update_audit_reg(adapter
, 0, 1);
880 * qlcnic_83xx_idc_need_reset_state
882 * @adapter: adapter structure
884 * Device will remain in this state until:
885 * Reset request ACK's are recieved from all the functions
886 * Wait time exceeds max time limit
888 * Returns: Error code or Success(0)
891 static int qlcnic_83xx_idc_need_reset_state(struct qlcnic_adapter
*adapter
)
893 struct qlcnic_mailbox
*mbx
= adapter
->ahw
->mailbox
;
896 if (adapter
->ahw
->idc
.prev_state
!= QLC_83XX_IDC_DEV_NEED_RESET
) {
897 qlcnic_83xx_idc_update_audit_reg(adapter
, 0, 1);
898 set_bit(__QLCNIC_RESETTING
, &adapter
->state
);
899 clear_bit(QLC_83XX_MBX_READY
, &mbx
->status
);
900 if (adapter
->ahw
->nic_mode
== QLC_83XX_VIRTUAL_NIC_MODE
)
901 qlcnic_83xx_disable_vnic_mode(adapter
, 1);
903 if (qlcnic_check_diag_status(adapter
)) {
904 dev_info(&adapter
->pdev
->dev
,
905 "%s: Wait for diag completion\n", __func__
);
906 adapter
->ahw
->idc
.delay_reset
= 1;
909 qlcnic_83xx_idc_update_drv_ack_reg(adapter
, 1, 1);
910 qlcnic_83xx_idc_detach_driver(adapter
);
914 if (qlcnic_check_diag_status(adapter
)) {
915 dev_info(&adapter
->pdev
->dev
,
916 "%s: Wait for diag completion\n", __func__
);
919 if (adapter
->ahw
->idc
.delay_reset
) {
920 qlcnic_83xx_idc_update_drv_ack_reg(adapter
, 1, 1);
921 qlcnic_83xx_idc_detach_driver(adapter
);
922 adapter
->ahw
->idc
.delay_reset
= 0;
925 /* Check for ACK from other functions */
926 ret
= qlcnic_83xx_idc_check_reset_ack_reg(adapter
);
928 dev_info(&adapter
->pdev
->dev
,
929 "%s: Waiting for reset ACK\n", __func__
);
934 /* Transit to INIT state and restart the HW */
935 qlcnic_83xx_idc_enter_init_state(adapter
, 1);
940 static int qlcnic_83xx_idc_need_quiesce_state(struct qlcnic_adapter
*adapter
)
942 dev_err(&adapter
->pdev
->dev
, "%s: TBD\n", __func__
);
946 static int qlcnic_83xx_idc_failed_state(struct qlcnic_adapter
*adapter
)
948 dev_err(&adapter
->pdev
->dev
, "%s: please restart!!\n", __func__
);
949 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
950 adapter
->ahw
->idc
.err_code
= -EIO
;
955 static int qlcnic_83xx_idc_quiesce_state(struct qlcnic_adapter
*adapter
)
957 dev_info(&adapter
->pdev
->dev
, "%s: TBD\n", __func__
);
961 static int qlcnic_83xx_idc_check_state_validity(struct qlcnic_adapter
*adapter
,
966 cur
= adapter
->ahw
->idc
.curr_state
;
967 prev
= adapter
->ahw
->idc
.prev_state
;
970 if ((next
< QLC_83XX_IDC_DEV_COLD
) ||
971 (next
> QLC_83XX_IDC_DEV_QUISCENT
)) {
972 dev_err(&adapter
->pdev
->dev
,
973 "%s: curr %d, prev %d, next state %d is invalid\n",
974 __func__
, cur
, prev
, state
);
978 if ((cur
== QLC_83XX_IDC_DEV_UNKNOWN
) &&
979 (prev
== QLC_83XX_IDC_DEV_UNKNOWN
)) {
980 if ((next
!= QLC_83XX_IDC_DEV_COLD
) &&
981 (next
!= QLC_83XX_IDC_DEV_READY
)) {
982 dev_err(&adapter
->pdev
->dev
,
983 "%s: failed, cur %d prev %d next %d\n",
984 __func__
, cur
, prev
, next
);
989 if (next
== QLC_83XX_IDC_DEV_INIT
) {
990 if ((prev
!= QLC_83XX_IDC_DEV_INIT
) &&
991 (prev
!= QLC_83XX_IDC_DEV_COLD
) &&
992 (prev
!= QLC_83XX_IDC_DEV_NEED_RESET
)) {
993 dev_err(&adapter
->pdev
->dev
,
994 "%s: failed, cur %d prev %d next %d\n",
995 __func__
, cur
, prev
, next
);
1003 static void qlcnic_83xx_periodic_tasks(struct qlcnic_adapter
*adapter
)
1005 if (adapter
->fhash
.fnum
)
1006 qlcnic_prune_lb_filters(adapter
);
1010 * qlcnic_83xx_idc_poll_dev_state
1012 * @work: kernel work queue structure used to schedule the function
1014 * Poll device state periodically and perform state specific
1015 * actions defined by Inter Driver Communication (IDC) protocol.
1020 void qlcnic_83xx_idc_poll_dev_state(struct work_struct
*work
)
1022 struct qlcnic_adapter
*adapter
;
1025 adapter
= container_of(work
, struct qlcnic_adapter
, fw_work
.work
);
1026 state
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
);
1028 if (qlcnic_83xx_idc_check_state_validity(adapter
, state
)) {
1029 qlcnic_83xx_idc_log_state_history(adapter
);
1030 adapter
->ahw
->idc
.curr_state
= QLC_83XX_IDC_DEV_UNKNOWN
;
1032 adapter
->ahw
->idc
.curr_state
= state
;
1035 switch (adapter
->ahw
->idc
.curr_state
) {
1036 case QLC_83XX_IDC_DEV_READY
:
1037 qlcnic_83xx_idc_ready_state(adapter
);
1039 case QLC_83XX_IDC_DEV_NEED_RESET
:
1040 qlcnic_83xx_idc_need_reset_state(adapter
);
1042 case QLC_83XX_IDC_DEV_NEED_QUISCENT
:
1043 qlcnic_83xx_idc_need_quiesce_state(adapter
);
1045 case QLC_83XX_IDC_DEV_FAILED
:
1046 qlcnic_83xx_idc_failed_state(adapter
);
1048 case QLC_83XX_IDC_DEV_INIT
:
1049 qlcnic_83xx_idc_init_state(adapter
);
1051 case QLC_83XX_IDC_DEV_QUISCENT
:
1052 qlcnic_83xx_idc_quiesce_state(adapter
);
1055 qlcnic_83xx_idc_unknown_state(adapter
);
1058 adapter
->ahw
->idc
.prev_state
= adapter
->ahw
->idc
.curr_state
;
1059 qlcnic_83xx_periodic_tasks(adapter
);
1061 /* Re-schedule the function */
1062 if (test_bit(QLC_83XX_MODULE_LOADED
, &adapter
->ahw
->idc
.status
))
1063 qlcnic_schedule_work(adapter
, qlcnic_83xx_idc_poll_dev_state
,
1064 adapter
->ahw
->idc
.delay
);
1067 static void qlcnic_83xx_setup_idc_parameters(struct qlcnic_adapter
*adapter
)
1069 u32 idc_params
, val
;
1071 if (qlcnic_83xx_lockless_flash_read32(adapter
,
1072 QLC_83XX_IDC_FLASH_PARAM_ADDR
,
1073 (u8
*)&idc_params
, 1)) {
1074 dev_info(&adapter
->pdev
->dev
,
1075 "%s:failed to get IDC params from flash\n", __func__
);
1076 adapter
->dev_init_timeo
= QLC_83XX_IDC_INIT_TIMEOUT_SECS
;
1077 adapter
->reset_ack_timeo
= QLC_83XX_IDC_RESET_TIMEOUT_SECS
;
1079 adapter
->dev_init_timeo
= idc_params
& 0xFFFF;
1080 adapter
->reset_ack_timeo
= ((idc_params
>> 16) & 0xFFFF);
1083 adapter
->ahw
->idc
.curr_state
= QLC_83XX_IDC_DEV_UNKNOWN
;
1084 adapter
->ahw
->idc
.prev_state
= QLC_83XX_IDC_DEV_UNKNOWN
;
1085 adapter
->ahw
->idc
.delay
= QLC_83XX_IDC_FW_POLL_DELAY
;
1086 adapter
->ahw
->idc
.err_code
= 0;
1087 adapter
->ahw
->idc
.collect_dump
= 0;
1088 adapter
->ahw
->idc
.name
= (char **)qlc_83xx_idc_states
;
1090 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1091 set_bit(QLC_83XX_MODULE_LOADED
, &adapter
->ahw
->idc
.status
);
1093 /* Check if reset recovery is disabled */
1094 if (!qlcnic_auto_fw_reset
) {
1095 /* Propagate do not reset request to other functions */
1096 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
1097 val
= val
| QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY
;
1098 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_CTRL
, val
);
1103 qlcnic_83xx_idc_first_to_load_function_handler(struct qlcnic_adapter
*adapter
)
1107 if (qlcnic_83xx_lock_driver(adapter
))
1110 /* Clear driver lock register */
1111 QLCWRX(adapter
->ahw
, QLC_83XX_RECOVER_DRV_LOCK
, 0);
1112 if (qlcnic_83xx_idc_update_major_version(adapter
, 0)) {
1113 qlcnic_83xx_unlock_driver(adapter
);
1117 state
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
);
1118 if (qlcnic_83xx_idc_check_state_validity(adapter
, state
)) {
1119 qlcnic_83xx_unlock_driver(adapter
);
1123 if (state
!= QLC_83XX_IDC_DEV_COLD
&& qlcnic_load_fw_file
) {
1124 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DEV_STATE
,
1125 QLC_83XX_IDC_DEV_COLD
);
1126 state
= QLC_83XX_IDC_DEV_COLD
;
1129 adapter
->ahw
->idc
.curr_state
= state
;
1130 /* First to load function should cold boot the device */
1131 if (state
== QLC_83XX_IDC_DEV_COLD
)
1132 qlcnic_83xx_idc_cold_state_handler(adapter
);
1134 /* Check if reset recovery is enabled */
1135 if (qlcnic_auto_fw_reset
) {
1136 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
1137 val
= val
& ~QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY
;
1138 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_CTRL
, val
);
1141 qlcnic_83xx_unlock_driver(adapter
);
1146 int qlcnic_83xx_idc_init(struct qlcnic_adapter
*adapter
)
1150 qlcnic_83xx_setup_idc_parameters(adapter
);
1152 if (qlcnic_83xx_get_reset_instruction_template(adapter
))
1155 if (!qlcnic_83xx_idc_check_driver_presence_reg(adapter
)) {
1156 if (qlcnic_83xx_idc_first_to_load_function_handler(adapter
))
1159 if (qlcnic_83xx_idc_check_major_version(adapter
))
1163 qlcnic_83xx_idc_update_audit_reg(adapter
, 0, 1);
1168 void qlcnic_83xx_idc_exit(struct qlcnic_adapter
*adapter
)
1173 while (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1174 usleep_range(10000, 11000);
1176 id
= QLCRDX(adapter
->ahw
, QLC_83XX_DRV_LOCK_ID
);
1179 if (id
== adapter
->portnum
) {
1180 dev_err(&adapter
->pdev
->dev
,
1181 "%s: wait for lock recovery.. %d\n", __func__
, id
);
1183 id
= QLCRDX(adapter
->ahw
, QLC_83XX_DRV_LOCK_ID
);
1187 /* Clear driver presence bit */
1188 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
);
1189 val
= val
& ~(1 << adapter
->portnum
);
1190 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
, val
);
1191 clear_bit(QLC_83XX_MODULE_LOADED
, &adapter
->ahw
->idc
.status
);
1192 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1194 cancel_delayed_work_sync(&adapter
->fw_work
);
1197 void qlcnic_83xx_idc_request_reset(struct qlcnic_adapter
*adapter
, u32 key
)
1201 if (qlcnic_sriov_vf_check(adapter
))
1204 if (qlcnic_83xx_lock_driver(adapter
)) {
1205 dev_err(&adapter
->pdev
->dev
,
1206 "%s:failed, please retry\n", __func__
);
1210 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
1211 if ((val
& QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY
) ||
1212 !qlcnic_auto_fw_reset
) {
1213 dev_err(&adapter
->pdev
->dev
,
1214 "%s:failed, device in non reset mode\n", __func__
);
1215 qlcnic_83xx_unlock_driver(adapter
);
1219 if (key
== QLCNIC_FORCE_FW_RESET
) {
1220 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
1221 val
= val
| QLC_83XX_IDC_GRACEFULL_RESET
;
1222 QLCWRX(adapter
->ahw
, QLC_83XX_IDC_CTRL
, val
);
1223 } else if (key
== QLCNIC_FORCE_FW_DUMP_KEY
) {
1224 adapter
->ahw
->idc
.collect_dump
= 1;
1227 qlcnic_83xx_unlock_driver(adapter
);
1231 static int qlcnic_83xx_copy_bootloader(struct qlcnic_adapter
*adapter
)
1238 src
= QLC_83XX_BOOTLOADER_FLASH_ADDR
;
1239 dest
= QLCRDX(adapter
->ahw
, QLCNIC_BOOTLOADER_ADDR
);
1240 size
= QLCRDX(adapter
->ahw
, QLCNIC_BOOTLOADER_SIZE
);
1242 /* alignment check */
1244 size
= (size
+ 16) & ~0xF;
1246 p_cache
= kzalloc(size
, GFP_KERNEL
);
1247 if (p_cache
== NULL
)
1250 ret
= qlcnic_83xx_lockless_flash_read32(adapter
, src
, p_cache
,
1251 size
/ sizeof(u32
));
1256 /* 16 byte write to MS memory */
1257 ret
= qlcnic_83xx_ms_mem_write128(adapter
, dest
, (u32
*)p_cache
,
1268 static int qlcnic_83xx_copy_fw_file(struct qlcnic_adapter
*adapter
)
1270 struct qlc_83xx_fw_info
*fw_info
= adapter
->ahw
->fw_info
;
1271 const struct firmware
*fw
= fw_info
->fw
;
1278 dest
= QLCRDX(adapter
->ahw
, QLCNIC_FW_IMAGE_ADDR
);
1279 size
= (fw
->size
& ~0xF);
1280 p_cache
= (u32
*)fw
->data
;
1283 ret
= qlcnic_83xx_ms_mem_write128(adapter
, addr
,
1284 (u32
*)p_cache
, size
/ 16);
1286 dev_err(&adapter
->pdev
->dev
, "MS memory write failed\n");
1287 release_firmware(fw
);
1292 /* alignment check */
1293 if (fw
->size
& 0xF) {
1295 for (i
= 0; i
< (fw
->size
& 0xF); i
++)
1296 data
[i
] = fw
->data
[size
+ i
];
1299 ret
= qlcnic_83xx_ms_mem_write128(adapter
, addr
,
1302 dev_err(&adapter
->pdev
->dev
,
1303 "MS memory write failed\n");
1304 release_firmware(fw
);
1309 release_firmware(fw
);
1315 static void qlcnic_83xx_dump_pause_control_regs(struct qlcnic_adapter
*adapter
)
1318 u32 val
= 0, val1
= 0, reg
= 0;
1321 val
= QLCRD32(adapter
, QLC_83XX_SRE_SHIM_REG
, &err
);
1324 dev_info(&adapter
->pdev
->dev
, "SRE-Shim Ctrl:0x%x\n", val
);
1326 for (j
= 0; j
< 2; j
++) {
1328 dev_info(&adapter
->pdev
->dev
,
1329 "Port 0 RxB Pause Threshold Regs[TC7..TC0]:");
1330 reg
= QLC_83XX_PORT0_THRESHOLD
;
1331 } else if (j
== 1) {
1332 dev_info(&adapter
->pdev
->dev
,
1333 "Port 1 RxB Pause Threshold Regs[TC7..TC0]:");
1334 reg
= QLC_83XX_PORT1_THRESHOLD
;
1336 for (i
= 0; i
< 8; i
++) {
1337 val
= QLCRD32(adapter
, reg
+ (i
* 0x4), &err
);
1340 dev_info(&adapter
->pdev
->dev
, "0x%x ", val
);
1342 dev_info(&adapter
->pdev
->dev
, "\n");
1345 for (j
= 0; j
< 2; j
++) {
1347 dev_info(&adapter
->pdev
->dev
,
1348 "Port 0 RxB TC Max Cell Registers[4..1]:");
1349 reg
= QLC_83XX_PORT0_TC_MC_REG
;
1350 } else if (j
== 1) {
1351 dev_info(&adapter
->pdev
->dev
,
1352 "Port 1 RxB TC Max Cell Registers[4..1]:");
1353 reg
= QLC_83XX_PORT1_TC_MC_REG
;
1355 for (i
= 0; i
< 4; i
++) {
1356 val
= QLCRD32(adapter
, reg
+ (i
* 0x4), &err
);
1359 dev_info(&adapter
->pdev
->dev
, "0x%x ", val
);
1361 dev_info(&adapter
->pdev
->dev
, "\n");
1364 for (j
= 0; j
< 2; j
++) {
1366 dev_info(&adapter
->pdev
->dev
,
1367 "Port 0 RxB Rx TC Stats[TC7..TC0]:");
1368 reg
= QLC_83XX_PORT0_TC_STATS
;
1369 } else if (j
== 1) {
1370 dev_info(&adapter
->pdev
->dev
,
1371 "Port 1 RxB Rx TC Stats[TC7..TC0]:");
1372 reg
= QLC_83XX_PORT1_TC_STATS
;
1374 for (i
= 7; i
>= 0; i
--) {
1375 val
= QLCRD32(adapter
, reg
, &err
);
1378 val
&= ~(0x7 << 29); /* Reset bits 29 to 31 */
1379 QLCWR32(adapter
, reg
, (val
| (i
<< 29)));
1380 val
= QLCRD32(adapter
, reg
, &err
);
1383 dev_info(&adapter
->pdev
->dev
, "0x%x ", val
);
1385 dev_info(&adapter
->pdev
->dev
, "\n");
1388 val
= QLCRD32(adapter
, QLC_83XX_PORT2_IFB_THRESHOLD
, &err
);
1391 val1
= QLCRD32(adapter
, QLC_83XX_PORT3_IFB_THRESHOLD
, &err
);
1394 dev_info(&adapter
->pdev
->dev
,
1395 "IFB-Pause Thresholds: Port 2:0x%x, Port 3:0x%x\n",
1400 static void qlcnic_83xx_disable_pause_frames(struct qlcnic_adapter
*adapter
)
1404 if (qlcnic_83xx_lock_driver(adapter
)) {
1405 dev_err(&adapter
->pdev
->dev
,
1406 "%s:failed to acquire driver lock\n", __func__
);
1410 qlcnic_83xx_dump_pause_control_regs(adapter
);
1411 QLCWR32(adapter
, QLC_83XX_SRE_SHIM_REG
, 0x0);
1413 for (j
= 0; j
< 2; j
++) {
1415 reg
= QLC_83XX_PORT0_THRESHOLD
;
1417 reg
= QLC_83XX_PORT1_THRESHOLD
;
1419 for (i
= 0; i
< 8; i
++)
1420 QLCWR32(adapter
, reg
+ (i
* 0x4), 0x0);
1423 for (j
= 0; j
< 2; j
++) {
1425 reg
= QLC_83XX_PORT0_TC_MC_REG
;
1427 reg
= QLC_83XX_PORT1_TC_MC_REG
;
1429 for (i
= 0; i
< 4; i
++)
1430 QLCWR32(adapter
, reg
+ (i
* 0x4), 0x03FF03FF);
1433 QLCWR32(adapter
, QLC_83XX_PORT2_IFB_THRESHOLD
, 0);
1434 QLCWR32(adapter
, QLC_83XX_PORT3_IFB_THRESHOLD
, 0);
1435 dev_info(&adapter
->pdev
->dev
,
1436 "Disabled pause frames successfully on all ports\n");
1437 qlcnic_83xx_unlock_driver(adapter
);
1440 static void qlcnic_83xx_take_eport_out_of_reset(struct qlcnic_adapter
*adapter
)
1442 QLCWR32(adapter
, QLC_83XX_RESET_REG
, 0);
1443 QLCWR32(adapter
, QLC_83XX_RESET_PORT0
, 0);
1444 QLCWR32(adapter
, QLC_83XX_RESET_PORT1
, 0);
1445 QLCWR32(adapter
, QLC_83XX_RESET_PORT2
, 0);
1446 QLCWR32(adapter
, QLC_83XX_RESET_PORT3
, 0);
1447 QLCWR32(adapter
, QLC_83XX_RESET_SRESHIM
, 0);
1448 QLCWR32(adapter
, QLC_83XX_RESET_EPGSHIM
, 0);
1449 QLCWR32(adapter
, QLC_83XX_RESET_ETHERPCS
, 0);
1450 QLCWR32(adapter
, QLC_83XX_RESET_CONTROL
, 1);
1453 static int qlcnic_83xx_check_heartbeat(struct qlcnic_adapter
*p_dev
)
1455 u32 heartbeat
, peg_status
;
1456 int retries
, ret
= -EIO
, err
= 0;
1458 retries
= QLCNIC_HEARTBEAT_CHECK_RETRY_COUNT
;
1459 p_dev
->heartbeat
= QLC_SHARED_REG_RD32(p_dev
,
1460 QLCNIC_PEG_ALIVE_COUNTER
);
1463 msleep(QLCNIC_HEARTBEAT_PERIOD_MSECS
);
1464 heartbeat
= QLC_SHARED_REG_RD32(p_dev
,
1465 QLCNIC_PEG_ALIVE_COUNTER
);
1466 if (heartbeat
!= p_dev
->heartbeat
) {
1467 ret
= QLCNIC_RCODE_SUCCESS
;
1470 } while (--retries
);
1473 dev_err(&p_dev
->pdev
->dev
, "firmware hang detected\n");
1474 qlcnic_83xx_take_eport_out_of_reset(p_dev
);
1475 qlcnic_83xx_disable_pause_frames(p_dev
);
1476 peg_status
= QLC_SHARED_REG_RD32(p_dev
,
1477 QLCNIC_PEG_HALT_STATUS1
);
1478 dev_info(&p_dev
->pdev
->dev
, "Dumping HW/FW registers\n"
1479 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
1480 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
1481 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
1482 "PEG_NET_4_PC: 0x%x\n", peg_status
,
1483 QLC_SHARED_REG_RD32(p_dev
, QLCNIC_PEG_HALT_STATUS2
),
1484 QLCRD32(p_dev
, QLC_83XX_CRB_PEG_NET_0
, &err
),
1485 QLCRD32(p_dev
, QLC_83XX_CRB_PEG_NET_1
, &err
),
1486 QLCRD32(p_dev
, QLC_83XX_CRB_PEG_NET_2
, &err
),
1487 QLCRD32(p_dev
, QLC_83XX_CRB_PEG_NET_3
, &err
),
1488 QLCRD32(p_dev
, QLC_83XX_CRB_PEG_NET_4
, &err
));
1490 if (QLCNIC_FWERROR_CODE(peg_status
) == 0x67)
1491 dev_err(&p_dev
->pdev
->dev
,
1492 "Device is being reset err code 0x00006700.\n");
1498 static int qlcnic_83xx_check_cmd_peg_status(struct qlcnic_adapter
*p_dev
)
1500 int retries
= QLCNIC_CMDPEG_CHECK_RETRY_COUNT
;
1504 val
= QLC_SHARED_REG_RD32(p_dev
, QLCNIC_CMDPEG_STATE
);
1505 if (val
== QLC_83XX_CMDPEG_COMPLETE
)
1507 msleep(QLCNIC_CMDPEG_CHECK_DELAY
);
1508 } while (--retries
);
1510 dev_err(&p_dev
->pdev
->dev
, "%s: failed, state = 0x%x\n", __func__
, val
);
1514 int qlcnic_83xx_check_hw_status(struct qlcnic_adapter
*p_dev
)
1518 err
= qlcnic_83xx_check_cmd_peg_status(p_dev
);
1522 err
= qlcnic_83xx_check_heartbeat(p_dev
);
1529 static int qlcnic_83xx_poll_reg(struct qlcnic_adapter
*p_dev
, u32 addr
,
1530 int duration
, u32 mask
, u32 status
)
1532 int timeout_error
, err
= 0;
1536 value
= QLCRD32(p_dev
, addr
, &err
);
1539 retries
= duration
/ 10;
1542 if ((value
& mask
) != status
) {
1544 msleep(duration
/ 10);
1545 value
= QLCRD32(p_dev
, addr
, &err
);
1552 } while (retries
--);
1554 if (timeout_error
) {
1555 p_dev
->ahw
->reset
.seq_error
++;
1556 dev_err(&p_dev
->pdev
->dev
,
1557 "%s: Timeout Err, entry_num = %d\n",
1558 __func__
, p_dev
->ahw
->reset
.seq_index
);
1559 dev_err(&p_dev
->pdev
->dev
,
1560 "0x%08x 0x%08x 0x%08x\n",
1561 value
, mask
, status
);
1564 return timeout_error
;
1567 static int qlcnic_83xx_reset_template_checksum(struct qlcnic_adapter
*p_dev
)
1570 u16
*buff
= (u16
*)p_dev
->ahw
->reset
.buff
;
1571 int count
= p_dev
->ahw
->reset
.hdr
->size
/ sizeof(u16
);
1577 sum
= (sum
& 0xFFFF) + (sum
>> 16);
1582 dev_err(&p_dev
->pdev
->dev
, "%s: failed\n", __func__
);
1587 int qlcnic_83xx_get_reset_instruction_template(struct qlcnic_adapter
*p_dev
)
1589 struct qlcnic_hardware_context
*ahw
= p_dev
->ahw
;
1590 u32 addr
, count
, prev_ver
, curr_ver
;
1593 if (ahw
->reset
.buff
!= NULL
) {
1594 prev_ver
= p_dev
->fw_version
;
1595 curr_ver
= qlcnic_83xx_get_fw_version(p_dev
);
1596 if (curr_ver
> prev_ver
)
1597 kfree(ahw
->reset
.buff
);
1602 ahw
->reset
.seq_error
= 0;
1603 ahw
->reset
.buff
= kzalloc(QLC_83XX_RESTART_TEMPLATE_SIZE
, GFP_KERNEL
);
1604 if (p_dev
->ahw
->reset
.buff
== NULL
)
1607 p_buff
= p_dev
->ahw
->reset
.buff
;
1608 addr
= QLC_83XX_RESET_TEMPLATE_ADDR
;
1609 count
= sizeof(struct qlc_83xx_reset_hdr
) / sizeof(u32
);
1611 /* Copy template header from flash */
1612 if (qlcnic_83xx_flash_read32(p_dev
, addr
, p_buff
, count
)) {
1613 dev_err(&p_dev
->pdev
->dev
, "%s: flash read failed\n", __func__
);
1616 ahw
->reset
.hdr
= (struct qlc_83xx_reset_hdr
*)ahw
->reset
.buff
;
1617 addr
= QLC_83XX_RESET_TEMPLATE_ADDR
+ ahw
->reset
.hdr
->hdr_size
;
1618 p_buff
= ahw
->reset
.buff
+ ahw
->reset
.hdr
->hdr_size
;
1619 count
= (ahw
->reset
.hdr
->size
- ahw
->reset
.hdr
->hdr_size
) / sizeof(u32
);
1621 /* Copy rest of the template */
1622 if (qlcnic_83xx_flash_read32(p_dev
, addr
, p_buff
, count
)) {
1623 dev_err(&p_dev
->pdev
->dev
, "%s: flash read failed\n", __func__
);
1627 if (qlcnic_83xx_reset_template_checksum(p_dev
))
1629 /* Get Stop, Start and Init command offsets */
1630 ahw
->reset
.init_offset
= ahw
->reset
.buff
+ ahw
->reset
.hdr
->init_offset
;
1631 ahw
->reset
.start_offset
= ahw
->reset
.buff
+
1632 ahw
->reset
.hdr
->start_offset
;
1633 ahw
->reset
.stop_offset
= ahw
->reset
.buff
+ ahw
->reset
.hdr
->hdr_size
;
1637 /* Read Write HW register command */
1638 static void qlcnic_83xx_read_write_crb_reg(struct qlcnic_adapter
*p_dev
,
1639 u32 raddr
, u32 waddr
)
1644 value
= QLCRD32(p_dev
, raddr
, &err
);
1647 qlcnic_83xx_wrt_reg_indirect(p_dev
, waddr
, value
);
1650 /* Read Modify Write HW register command */
1651 static void qlcnic_83xx_rmw_crb_reg(struct qlcnic_adapter
*p_dev
,
1652 u32 raddr
, u32 waddr
,
1653 struct qlc_83xx_rmw
*p_rmw_hdr
)
1658 if (p_rmw_hdr
->index_a
) {
1659 value
= p_dev
->ahw
->reset
.array
[p_rmw_hdr
->index_a
];
1661 value
= QLCRD32(p_dev
, raddr
, &err
);
1666 value
&= p_rmw_hdr
->mask
;
1667 value
<<= p_rmw_hdr
->shl
;
1668 value
>>= p_rmw_hdr
->shr
;
1669 value
|= p_rmw_hdr
->or_value
;
1670 value
^= p_rmw_hdr
->xor_value
;
1671 qlcnic_83xx_wrt_reg_indirect(p_dev
, waddr
, value
);
1674 /* Write HW register command */
1675 static void qlcnic_83xx_write_list(struct qlcnic_adapter
*p_dev
,
1676 struct qlc_83xx_entry_hdr
*p_hdr
)
1679 struct qlc_83xx_entry
*entry
;
1681 entry
= (struct qlc_83xx_entry
*)((char *)p_hdr
+
1682 sizeof(struct qlc_83xx_entry_hdr
));
1684 for (i
= 0; i
< p_hdr
->count
; i
++, entry
++) {
1685 qlcnic_83xx_wrt_reg_indirect(p_dev
, entry
->arg1
,
1688 udelay((u32
)(p_hdr
->delay
));
1692 /* Read and Write instruction */
1693 static void qlcnic_83xx_read_write_list(struct qlcnic_adapter
*p_dev
,
1694 struct qlc_83xx_entry_hdr
*p_hdr
)
1697 struct qlc_83xx_entry
*entry
;
1699 entry
= (struct qlc_83xx_entry
*)((char *)p_hdr
+
1700 sizeof(struct qlc_83xx_entry_hdr
));
1702 for (i
= 0; i
< p_hdr
->count
; i
++, entry
++) {
1703 qlcnic_83xx_read_write_crb_reg(p_dev
, entry
->arg1
,
1706 udelay((u32
)(p_hdr
->delay
));
1710 /* Poll HW register command */
1711 static void qlcnic_83xx_poll_list(struct qlcnic_adapter
*p_dev
,
1712 struct qlc_83xx_entry_hdr
*p_hdr
)
1715 struct qlc_83xx_entry
*entry
;
1716 struct qlc_83xx_poll
*poll
;
1718 unsigned long arg1
, arg2
;
1720 poll
= (struct qlc_83xx_poll
*)((char *)p_hdr
+
1721 sizeof(struct qlc_83xx_entry_hdr
));
1723 entry
= (struct qlc_83xx_entry
*)((char *)poll
+
1724 sizeof(struct qlc_83xx_poll
));
1725 delay
= (long)p_hdr
->delay
;
1728 for (i
= 0; i
< p_hdr
->count
; i
++, entry
++)
1729 qlcnic_83xx_poll_reg(p_dev
, entry
->arg1
,
1733 for (i
= 0; i
< p_hdr
->count
; i
++, entry
++) {
1737 if (qlcnic_83xx_poll_reg(p_dev
,
1741 QLCRD32(p_dev
, arg1
, &err
);
1744 QLCRD32(p_dev
, arg2
, &err
);
1753 /* Poll and write HW register command */
1754 static void qlcnic_83xx_poll_write_list(struct qlcnic_adapter
*p_dev
,
1755 struct qlc_83xx_entry_hdr
*p_hdr
)
1759 struct qlc_83xx_quad_entry
*entry
;
1760 struct qlc_83xx_poll
*poll
;
1762 poll
= (struct qlc_83xx_poll
*)((char *)p_hdr
+
1763 sizeof(struct qlc_83xx_entry_hdr
));
1764 entry
= (struct qlc_83xx_quad_entry
*)((char *)poll
+
1765 sizeof(struct qlc_83xx_poll
));
1766 delay
= (long)p_hdr
->delay
;
1768 for (i
= 0; i
< p_hdr
->count
; i
++, entry
++) {
1769 qlcnic_83xx_wrt_reg_indirect(p_dev
, entry
->dr_addr
,
1771 qlcnic_83xx_wrt_reg_indirect(p_dev
, entry
->ar_addr
,
1774 qlcnic_83xx_poll_reg(p_dev
, entry
->ar_addr
, delay
,
1775 poll
->mask
, poll
->status
);
1779 /* Read Modify Write register command */
1780 static void qlcnic_83xx_read_modify_write(struct qlcnic_adapter
*p_dev
,
1781 struct qlc_83xx_entry_hdr
*p_hdr
)
1784 struct qlc_83xx_entry
*entry
;
1785 struct qlc_83xx_rmw
*rmw_hdr
;
1787 rmw_hdr
= (struct qlc_83xx_rmw
*)((char *)p_hdr
+
1788 sizeof(struct qlc_83xx_entry_hdr
));
1790 entry
= (struct qlc_83xx_entry
*)((char *)rmw_hdr
+
1791 sizeof(struct qlc_83xx_rmw
));
1793 for (i
= 0; i
< p_hdr
->count
; i
++, entry
++) {
1794 qlcnic_83xx_rmw_crb_reg(p_dev
, entry
->arg1
,
1795 entry
->arg2
, rmw_hdr
);
1797 udelay((u32
)(p_hdr
->delay
));
1801 static void qlcnic_83xx_pause(struct qlc_83xx_entry_hdr
*p_hdr
)
1804 mdelay((u32
)((long)p_hdr
->delay
));
1807 /* Read and poll register command */
1808 static void qlcnic_83xx_poll_read_list(struct qlcnic_adapter
*p_dev
,
1809 struct qlc_83xx_entry_hdr
*p_hdr
)
1812 int index
, i
, j
, err
;
1813 struct qlc_83xx_quad_entry
*entry
;
1814 struct qlc_83xx_poll
*poll
;
1817 poll
= (struct qlc_83xx_poll
*)((char *)p_hdr
+
1818 sizeof(struct qlc_83xx_entry_hdr
));
1820 entry
= (struct qlc_83xx_quad_entry
*)((char *)poll
+
1821 sizeof(struct qlc_83xx_poll
));
1822 delay
= (long)p_hdr
->delay
;
1824 for (i
= 0; i
< p_hdr
->count
; i
++, entry
++) {
1825 qlcnic_83xx_wrt_reg_indirect(p_dev
, entry
->ar_addr
,
1828 if (!qlcnic_83xx_poll_reg(p_dev
, entry
->ar_addr
, delay
,
1829 poll
->mask
, poll
->status
)){
1830 index
= p_dev
->ahw
->reset
.array_index
;
1831 addr
= entry
->dr_addr
;
1832 j
= QLCRD32(p_dev
, addr
, &err
);
1836 p_dev
->ahw
->reset
.array
[index
++] = j
;
1838 if (index
== QLC_83XX_MAX_RESET_SEQ_ENTRIES
)
1839 p_dev
->ahw
->reset
.array_index
= 1;
1845 static inline void qlcnic_83xx_seq_end(struct qlcnic_adapter
*p_dev
)
1847 p_dev
->ahw
->reset
.seq_end
= 1;
1850 static void qlcnic_83xx_template_end(struct qlcnic_adapter
*p_dev
)
1852 p_dev
->ahw
->reset
.template_end
= 1;
1853 if (p_dev
->ahw
->reset
.seq_error
== 0)
1854 dev_err(&p_dev
->pdev
->dev
,
1855 "HW restart process completed successfully.\n");
1857 dev_err(&p_dev
->pdev
->dev
,
1858 "HW restart completed with timeout errors.\n");
1862 * qlcnic_83xx_exec_template_cmd
1864 * @p_dev: adapter structure
1865 * @p_buff: Poiter to instruction template
1867 * Template provides instructions to stop, restart and initalize firmware.
1868 * These instructions are abstracted as a series of read, write and
1869 * poll operations on hardware registers. Register information and operation
1870 * specifics are not exposed to the driver. Driver reads the template from
1871 * flash and executes the instructions located at pre-defined offsets.
1875 static void qlcnic_83xx_exec_template_cmd(struct qlcnic_adapter
*p_dev
,
1879 struct qlc_83xx_entry_hdr
*p_hdr
;
1880 char *entry
= p_buff
;
1882 p_dev
->ahw
->reset
.seq_end
= 0;
1883 p_dev
->ahw
->reset
.template_end
= 0;
1884 entries
= p_dev
->ahw
->reset
.hdr
->entries
;
1885 index
= p_dev
->ahw
->reset
.seq_index
;
1887 for (; (!p_dev
->ahw
->reset
.seq_end
) && (index
< entries
); index
++) {
1888 p_hdr
= (struct qlc_83xx_entry_hdr
*)entry
;
1890 switch (p_hdr
->cmd
) {
1891 case QLC_83XX_OPCODE_NOP
:
1893 case QLC_83XX_OPCODE_WRITE_LIST
:
1894 qlcnic_83xx_write_list(p_dev
, p_hdr
);
1896 case QLC_83XX_OPCODE_READ_WRITE_LIST
:
1897 qlcnic_83xx_read_write_list(p_dev
, p_hdr
);
1899 case QLC_83XX_OPCODE_POLL_LIST
:
1900 qlcnic_83xx_poll_list(p_dev
, p_hdr
);
1902 case QLC_83XX_OPCODE_POLL_WRITE_LIST
:
1903 qlcnic_83xx_poll_write_list(p_dev
, p_hdr
);
1905 case QLC_83XX_OPCODE_READ_MODIFY_WRITE
:
1906 qlcnic_83xx_read_modify_write(p_dev
, p_hdr
);
1908 case QLC_83XX_OPCODE_SEQ_PAUSE
:
1909 qlcnic_83xx_pause(p_hdr
);
1911 case QLC_83XX_OPCODE_SEQ_END
:
1912 qlcnic_83xx_seq_end(p_dev
);
1914 case QLC_83XX_OPCODE_TMPL_END
:
1915 qlcnic_83xx_template_end(p_dev
);
1917 case QLC_83XX_OPCODE_POLL_READ_LIST
:
1918 qlcnic_83xx_poll_read_list(p_dev
, p_hdr
);
1921 dev_err(&p_dev
->pdev
->dev
,
1922 "%s: Unknown opcode 0x%04x in template %d\n",
1923 __func__
, p_hdr
->cmd
, index
);
1926 entry
+= p_hdr
->size
;
1928 p_dev
->ahw
->reset
.seq_index
= index
;
1931 static void qlcnic_83xx_stop_hw(struct qlcnic_adapter
*p_dev
)
1933 p_dev
->ahw
->reset
.seq_index
= 0;
1935 qlcnic_83xx_exec_template_cmd(p_dev
, p_dev
->ahw
->reset
.stop_offset
);
1936 if (p_dev
->ahw
->reset
.seq_end
!= 1)
1937 dev_err(&p_dev
->pdev
->dev
, "%s: failed\n", __func__
);
1940 static void qlcnic_83xx_start_hw(struct qlcnic_adapter
*p_dev
)
1942 qlcnic_83xx_exec_template_cmd(p_dev
, p_dev
->ahw
->reset
.start_offset
);
1943 if (p_dev
->ahw
->reset
.template_end
!= 1)
1944 dev_err(&p_dev
->pdev
->dev
, "%s: failed\n", __func__
);
1947 static void qlcnic_83xx_init_hw(struct qlcnic_adapter
*p_dev
)
1949 qlcnic_83xx_exec_template_cmd(p_dev
, p_dev
->ahw
->reset
.init_offset
);
1950 if (p_dev
->ahw
->reset
.seq_end
!= 1)
1951 dev_err(&p_dev
->pdev
->dev
, "%s: failed\n", __func__
);
1954 static int qlcnic_83xx_load_fw_image_from_host(struct qlcnic_adapter
*adapter
)
1956 struct qlc_83xx_fw_info
*fw_info
= adapter
->ahw
->fw_info
;
1959 if (request_firmware(&fw_info
->fw
, fw_info
->fw_file_name
,
1960 &(adapter
->pdev
->dev
))) {
1961 dev_err(&adapter
->pdev
->dev
,
1962 "No file FW image, loading flash FW image.\n");
1963 QLC_SHARED_REG_WR32(adapter
, QLCNIC_FW_IMG_VALID
,
1964 QLC_83XX_BOOT_FROM_FLASH
);
1966 if (qlcnic_83xx_copy_fw_file(adapter
))
1968 QLC_SHARED_REG_WR32(adapter
, QLCNIC_FW_IMG_VALID
,
1969 QLC_83XX_BOOT_FROM_FILE
);
1975 static int qlcnic_83xx_restart_hw(struct qlcnic_adapter
*adapter
)
1980 qlcnic_83xx_stop_hw(adapter
);
1982 /* Collect FW register dump if required */
1983 val
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_CTRL
);
1984 if (!(val
& QLC_83XX_IDC_GRACEFULL_RESET
))
1985 qlcnic_dump_fw(adapter
);
1986 qlcnic_83xx_init_hw(adapter
);
1988 if (qlcnic_83xx_copy_bootloader(adapter
))
1990 /* Boot either flash image or firmware image from host file system */
1991 if (qlcnic_load_fw_file
) {
1992 if (qlcnic_83xx_load_fw_image_from_host(adapter
))
1995 QLC_SHARED_REG_WR32(adapter
, QLCNIC_FW_IMG_VALID
,
1996 QLC_83XX_BOOT_FROM_FLASH
);
1999 qlcnic_83xx_start_hw(adapter
);
2000 if (qlcnic_83xx_check_hw_status(adapter
))
2006 int qlcnic_83xx_get_nic_configuration(struct qlcnic_adapter
*adapter
)
2009 struct qlcnic_info nic_info
;
2010 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2012 memset(&nic_info
, 0, sizeof(struct qlcnic_info
));
2013 err
= qlcnic_get_nic_info(adapter
, &nic_info
, ahw
->pci_func
);
2017 ahw
->physical_port
= (u8
) nic_info
.phys_port
;
2018 ahw
->switch_mode
= nic_info
.switch_mode
;
2019 ahw
->max_tx_ques
= nic_info
.max_tx_ques
;
2020 ahw
->max_rx_ques
= nic_info
.max_rx_ques
;
2021 ahw
->capabilities
= nic_info
.capabilities
;
2022 ahw
->max_mac_filters
= nic_info
.max_mac_filters
;
2023 ahw
->max_mtu
= nic_info
.max_mtu
;
2025 /* eSwitch capability indicates vNIC mode.
2026 * vNIC and SRIOV are mutually exclusive operational modes.
2027 * If SR-IOV capability is detected, SR-IOV physical function
2028 * will get initialized in default mode.
2029 * SR-IOV virtual function initialization follows a
2030 * different code path and opmode.
2031 * SRIOV mode has precedence over vNIC mode.
2033 if (test_bit(__QLCNIC_SRIOV_CAPABLE
, &adapter
->state
))
2034 return QLC_83XX_DEFAULT_OPMODE
;
2036 if (ahw
->capabilities
& QLC_83XX_ESWITCH_CAPABILITY
)
2037 return QLC_83XX_VIRTUAL_NIC_MODE
;
2039 return QLC_83XX_DEFAULT_OPMODE
;
2042 int qlcnic_83xx_configure_opmode(struct qlcnic_adapter
*adapter
)
2044 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2047 ret
= qlcnic_83xx_get_nic_configuration(adapter
);
2051 if (ret
== QLC_83XX_VIRTUAL_NIC_MODE
) {
2052 ahw
->nic_mode
= QLC_83XX_VIRTUAL_NIC_MODE
;
2053 if (qlcnic_83xx_config_vnic_opmode(adapter
))
2056 } else if (ret
== QLC_83XX_DEFAULT_OPMODE
) {
2057 ahw
->nic_mode
= QLC_83XX_DEFAULT_MODE
;
2058 adapter
->nic_ops
->init_driver
= qlcnic_83xx_init_default_driver
;
2059 ahw
->idc
.state_entry
= qlcnic_83xx_idc_ready_state_entry
;
2067 static void qlcnic_83xx_config_buff_descriptors(struct qlcnic_adapter
*adapter
)
2069 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2071 if (ahw
->port_type
== QLCNIC_XGBE
) {
2072 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
2073 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_10G
;
2074 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
2075 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
2077 } else if (ahw
->port_type
== QLCNIC_GBE
) {
2078 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
2079 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
2080 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
2081 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_1G
;
2083 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
2084 adapter
->max_rds_rings
= MAX_RDS_RINGS
;
2087 static int qlcnic_83xx_init_default_driver(struct qlcnic_adapter
*adapter
)
2091 qlcnic_83xx_get_minidump_template(adapter
);
2092 if (qlcnic_83xx_get_port_info(adapter
))
2095 qlcnic_83xx_config_buff_descriptors(adapter
);
2096 adapter
->ahw
->msix_supported
= !!qlcnic_use_msi_x
;
2097 adapter
->flags
|= QLCNIC_ADAPTER_INITIALIZED
;
2099 dev_info(&adapter
->pdev
->dev
, "HAL Version: %d\n",
2100 adapter
->ahw
->fw_hal_version
);
2105 #define IS_QLC_83XX_USED(a, b, c) (((1 << a->portnum) & b) || ((c >> 6) & 0x1))
2106 static void qlcnic_83xx_clear_function_resources(struct qlcnic_adapter
*adapter
)
2108 struct qlcnic_cmd_args cmd
;
2109 u32 presence_mask
, audit_mask
;
2112 presence_mask
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_PRESENCE
);
2113 audit_mask
= QLCRDX(adapter
->ahw
, QLC_83XX_IDC_DRV_AUDIT
);
2115 if (IS_QLC_83XX_USED(adapter
, presence_mask
, audit_mask
)) {
2116 status
= qlcnic_alloc_mbx_args(&cmd
, adapter
,
2117 QLCNIC_CMD_STOP_NIC_FUNC
);
2121 cmd
.req
.arg
[1] = BIT_31
;
2122 status
= qlcnic_issue_cmd(adapter
, &cmd
);
2124 dev_err(&adapter
->pdev
->dev
,
2125 "Failed to clean up the function resources\n");
2126 qlcnic_free_mbx_args(&cmd
);
2130 static int qlcnic_83xx_get_fw_info(struct qlcnic_adapter
*adapter
)
2132 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2133 struct pci_dev
*pdev
= adapter
->pdev
;
2134 struct qlc_83xx_fw_info
*fw_info
;
2137 ahw
->fw_info
= kzalloc(sizeof(*fw_info
), GFP_KERNEL
);
2138 if (!ahw
->fw_info
) {
2141 fw_info
= ahw
->fw_info
;
2142 switch (pdev
->device
) {
2143 case PCI_DEVICE_ID_QLOGIC_QLE834X
:
2144 strncpy(fw_info
->fw_file_name
, QLC_83XX_FW_FILE_NAME
,
2145 QLC_FW_FILE_NAME_LEN
);
2147 case PCI_DEVICE_ID_QLOGIC_QLE844X
:
2148 strncpy(fw_info
->fw_file_name
, QLC_84XX_FW_FILE_NAME
,
2149 QLC_FW_FILE_NAME_LEN
);
2152 dev_err(&pdev
->dev
, "%s: Invalid device id\n",
2163 int qlcnic_83xx_init(struct qlcnic_adapter
*adapter
, int pci_using_dac
)
2165 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2168 ahw
->msix_supported
= !!qlcnic_use_msi_x
;
2169 err
= qlcnic_83xx_init_mailbox_work(adapter
);
2173 if (qlcnic_sriov_vf_check(adapter
)) {
2174 err
= qlcnic_sriov_vf_init(adapter
, pci_using_dac
);
2181 err
= qlcnic_83xx_check_hw_status(adapter
);
2185 if (!qlcnic_83xx_read_flash_descriptor_table(adapter
))
2186 qlcnic_83xx_read_flash_mfg_id(adapter
);
2188 err
= qlcnic_83xx_get_fw_info(adapter
);
2192 err
= qlcnic_83xx_idc_init(adapter
);
2196 err
= qlcnic_setup_intr(adapter
, 0, 0);
2198 dev_err(&adapter
->pdev
->dev
, "Failed to setup interrupt\n");
2202 err
= qlcnic_83xx_setup_mbx_intr(adapter
);
2204 goto disable_mbx_intr
;
2206 qlcnic_83xx_clear_function_resources(adapter
);
2208 INIT_DELAYED_WORK(&adapter
->idc_aen_work
, qlcnic_83xx_idc_aen_work
);
2210 /* register for NIC IDC AEN Events */
2211 qlcnic_83xx_register_nic_idc_func(adapter
, 1);
2213 /* Configure default, SR-IOV or Virtual NIC mode of operation */
2214 err
= qlcnic_83xx_configure_opmode(adapter
);
2216 goto disable_mbx_intr
;
2218 /* Perform operating mode specific initialization */
2219 err
= adapter
->nic_ops
->init_driver(adapter
);
2221 goto disable_mbx_intr
;
2223 if (adapter
->dcb
&& qlcnic_dcb_attach(adapter
))
2224 qlcnic_clear_dcb_ops(adapter
);
2226 /* Periodically monitor device status */
2227 qlcnic_83xx_idc_poll_dev_state(&adapter
->fw_work
.work
);
2231 qlcnic_83xx_free_mbx_intr(adapter
);
2234 qlcnic_teardown_intr(adapter
);
2237 kfree(ahw
->fw_info
);
2240 qlcnic_83xx_detach_mailbox_work(adapter
);
2241 qlcnic_83xx_free_mailbox(ahw
->mailbox
);
2246 void qlcnic_83xx_aer_stop_poll_work(struct qlcnic_adapter
*adapter
)
2248 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2249 struct qlc_83xx_idc
*idc
= &ahw
->idc
;
2251 clear_bit(QLC_83XX_MBX_READY
, &idc
->status
);
2252 cancel_delayed_work_sync(&adapter
->fw_work
);
2254 if (ahw
->nic_mode
== QLC_83XX_VIRTUAL_NIC_MODE
)
2255 qlcnic_83xx_disable_vnic_mode(adapter
, 1);
2257 qlcnic_83xx_idc_detach_driver(adapter
);
2258 qlcnic_83xx_register_nic_idc_func(adapter
, 0);
2260 cancel_delayed_work_sync(&adapter
->idc_aen_work
);
2263 int qlcnic_83xx_aer_reset(struct qlcnic_adapter
*adapter
)
2265 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2266 struct qlc_83xx_idc
*idc
= &ahw
->idc
;
2270 /* Mark the previous IDC state as NEED_RESET so
2271 * that state_entry() will perform the reattachment
2272 * and bringup the device
2274 idc
->prev_state
= QLC_83XX_IDC_DEV_NEED_RESET
;
2275 owner
= qlcnic_83xx_idc_find_reset_owner_id(adapter
);
2276 if (ahw
->pci_func
== owner
) {
2277 ret
= qlcnic_83xx_restart_hw(adapter
);
2280 qlcnic_83xx_idc_clear_registers(adapter
, 0);
2283 ret
= idc
->state_entry(adapter
);
2287 void qlcnic_83xx_aer_start_poll_work(struct qlcnic_adapter
*adapter
)
2289 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2290 struct qlc_83xx_idc
*idc
= &ahw
->idc
;
2293 idc
->prev_state
= QLC_83XX_IDC_DEV_READY
;
2294 owner
= qlcnic_83xx_idc_find_reset_owner_id(adapter
);
2295 if (ahw
->pci_func
== owner
)
2296 qlcnic_83xx_idc_enter_ready_state(adapter
, 0);
2298 qlcnic_schedule_work(adapter
, qlcnic_83xx_idc_poll_dev_state
, 0);