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 qlcnic_83xx_initialize_nic(adapter, 1);
619 err = qlcnic_sriov_pf_reinit(adapter);
623 qlcnic_83xx_enable_mbx_interrupt(adapter);
625 if (qlcnic_83xx_configure_opmode(adapter)) {
626 qlcnic_83xx_idc_enter_failed_state(adapter, 1);
630 if (adapter->nic_ops->init_driver(adapter)) {
631 qlcnic_83xx_idc_enter_failed_state(adapter, 1);
635 if (adapter->portnum == 0)
636 qlcnic_set_drv_version(adapter);
638 qlcnic_dcb_get_info(adapter->dcb);
639 qlcnic_83xx_idc_attach_driver(adapter);
644 static void qlcnic_83xx_idc_update_idc_params(struct qlcnic_adapter *adapter)
646 struct qlcnic_hardware_context *ahw = adapter->ahw;
648 qlcnic_83xx_idc_update_drv_presence_reg(adapter, 1, 1);
649 qlcnic_83xx_idc_update_audit_reg(adapter, 0, 1);
650 set_bit(QLC_83XX_MODULE_LOADED, &adapter->ahw->idc.status);
652 ahw->idc.quiesce_req = 0;
653 ahw->idc.delay = QLC_83XX_IDC_FW_POLL_DELAY;
654 ahw->idc.err_code = 0;
655 ahw->idc.collect_dump = 0;
656 ahw->reset_context = 0;
657 adapter->tx_timeo_cnt = 0;
658 ahw->idc.delay_reset = 0;
660 clear_bit(__QLCNIC_RESETTING, &adapter->state);
664 * qlcnic_83xx_idc_ready_state_entry
666 * @adapter: adapter structure
668 * Perform ready state initialization, this routine will get invoked only
669 * once from READY state.
671 * Returns: Error code or Success(0)
674 int qlcnic_83xx_idc_ready_state_entry(struct qlcnic_adapter *adapter)
676 struct qlcnic_hardware_context *ahw = adapter->ahw;
678 if (ahw->idc.prev_state != QLC_83XX_IDC_DEV_READY) {
679 qlcnic_83xx_idc_update_idc_params(adapter);
680 /* Re-attach the device if required */
681 if ((ahw->idc.prev_state == QLC_83XX_IDC_DEV_NEED_RESET) ||
682 (ahw->idc.prev_state == QLC_83XX_IDC_DEV_INIT)) {
683 if (qlcnic_83xx_idc_reattach_driver(adapter))
692 * qlcnic_83xx_idc_vnic_pf_entry
694 * @adapter: adapter structure
696 * Ensure vNIC mode privileged function starts only after vNIC mode is
697 * enabled by management function.
698 * If vNIC mode is ready, start initialization.
703 int qlcnic_83xx_idc_vnic_pf_entry(struct qlcnic_adapter *adapter)
706 struct qlcnic_hardware_context *ahw = adapter->ahw;
708 /* Privileged function waits till mgmt function enables VNIC mode */
709 state = QLCRDX(adapter->ahw, QLC_83XX_VNIC_STATE);
710 if (state != QLCNIC_DEV_NPAR_OPER) {
711 if (!ahw->idc.vnic_wait_limit--) {
712 qlcnic_83xx_idc_enter_failed_state(adapter, 1);
715 dev_info(&adapter->pdev->dev, "vNIC mode disabled\n");
719 /* Perform one time initialization from ready state */
720 if (ahw->idc.vnic_state != QLCNIC_DEV_NPAR_OPER) {
721 qlcnic_83xx_idc_update_idc_params(adapter);
723 /* If the previous state is UNKNOWN, device will be
724 already attached properly by Init routine*/
725 if (ahw->idc.prev_state != QLC_83XX_IDC_DEV_UNKNOWN) {
726 if (qlcnic_83xx_idc_reattach_driver(adapter))
729 adapter->ahw->idc.vnic_state = QLCNIC_DEV_NPAR_OPER;
730 dev_info(&adapter->pdev->dev, "vNIC mode enabled\n");
737 static int qlcnic_83xx_idc_unknown_state(struct qlcnic_adapter *adapter)
739 adapter->ahw->idc.err_code = -EIO;
740 dev_err(&adapter->pdev->dev,
741 "%s: Device in unknown state\n", __func__);
742 clear_bit(__QLCNIC_RESETTING, &adapter->state);
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);
850 netdev_info(adapter->netdev, "%s: Auto firmware recovery is disabled\n",
852 qlcnic_83xx_idc_enter_failed_state(adapter, 1);
857 if ((val & QLC_83XX_IDC_GRACEFULL_RESET) || ahw->idc.collect_dump) {
858 clear_bit(QLC_83XX_MBX_READY, &mbx->status);
860 /* Move to need reset state and prepare for reset */
861 qlcnic_83xx_idc_enter_need_reset_state(adapter, 1);
865 /* Check for soft reset request */
866 if (ahw->reset_context &&
867 !(val & QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY)) {
868 adapter->ahw->reset_context = 0;
869 qlcnic_83xx_idc_tx_soft_reset(adapter);
873 /* Move to need quiesce state if requested */
874 if (adapter->ahw->idc.quiesce_req) {
875 qlcnic_83xx_idc_enter_need_quiesce(adapter, 1);
876 qlcnic_83xx_idc_update_audit_reg(adapter, 0, 1);
884 * qlcnic_83xx_idc_need_reset_state
886 * @adapter: adapter structure
888 * Device will remain in this state until:
889 * Reset request ACK's are recieved from all the functions
890 * Wait time exceeds max time limit
892 * Returns: Error code or Success(0)
895 static int qlcnic_83xx_idc_need_reset_state(struct qlcnic_adapter *adapter)
897 struct qlcnic_mailbox *mbx = adapter->ahw->mailbox;
900 if (adapter->ahw->idc.prev_state != QLC_83XX_IDC_DEV_NEED_RESET) {
901 qlcnic_83xx_idc_update_audit_reg(adapter, 0, 1);
902 set_bit(__QLCNIC_RESETTING, &adapter->state);
903 clear_bit(QLC_83XX_MBX_READY, &mbx->status);
904 if (adapter->ahw->nic_mode == QLCNIC_VNIC_MODE)
905 qlcnic_83xx_disable_vnic_mode(adapter, 1);
907 if (qlcnic_check_diag_status(adapter)) {
908 dev_info(&adapter->pdev->dev,
909 "%s: Wait for diag completion\n", __func__);
910 adapter->ahw->idc.delay_reset = 1;
913 qlcnic_83xx_idc_update_drv_ack_reg(adapter, 1, 1);
914 qlcnic_83xx_idc_detach_driver(adapter);
918 if (qlcnic_check_diag_status(adapter)) {
919 dev_info(&adapter->pdev->dev,
920 "%s: Wait for diag completion\n", __func__);
923 if (adapter->ahw->idc.delay_reset) {
924 qlcnic_83xx_idc_update_drv_ack_reg(adapter, 1, 1);
925 qlcnic_83xx_idc_detach_driver(adapter);
926 adapter->ahw->idc.delay_reset = 0;
929 /* Check for ACK from other functions */
930 ret = qlcnic_83xx_idc_check_reset_ack_reg(adapter);
932 dev_info(&adapter->pdev->dev,
933 "%s: Waiting for reset ACK\n", __func__);
938 /* Transit to INIT state and restart the HW */
939 qlcnic_83xx_idc_enter_init_state(adapter, 1);
944 static int qlcnic_83xx_idc_need_quiesce_state(struct qlcnic_adapter *adapter)
946 dev_err(&adapter->pdev->dev, "%s: TBD\n", __func__);
950 static void qlcnic_83xx_idc_failed_state(struct qlcnic_adapter *adapter)
952 struct qlcnic_hardware_context *ahw = adapter->ahw;
955 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
956 if (val & QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY) {
957 owner = qlcnic_83xx_idc_find_reset_owner_id(adapter);
958 if (ahw->pci_func == owner) {
959 qlcnic_83xx_stop_hw(adapter);
960 qlcnic_dump_fw(adapter);
964 netdev_warn(adapter->netdev, "%s: Reboot will be required to recover the adapter!!\n",
966 clear_bit(__QLCNIC_RESETTING, &adapter->state);
967 ahw->idc.err_code = -EIO;
972 static int qlcnic_83xx_idc_quiesce_state(struct qlcnic_adapter *adapter)
974 dev_info(&adapter->pdev->dev, "%s: TBD\n", __func__);
978 static int qlcnic_83xx_idc_check_state_validity(struct qlcnic_adapter *adapter,
983 cur = adapter->ahw->idc.curr_state;
984 prev = adapter->ahw->idc.prev_state;
987 if ((next < QLC_83XX_IDC_DEV_COLD) ||
988 (next > QLC_83XX_IDC_DEV_QUISCENT)) {
989 dev_err(&adapter->pdev->dev,
990 "%s: curr %d, prev %d, next state %d is invalid\n",
991 __func__, cur, prev, state);
995 if ((cur == QLC_83XX_IDC_DEV_UNKNOWN) &&
996 (prev == QLC_83XX_IDC_DEV_UNKNOWN)) {
997 if ((next != QLC_83XX_IDC_DEV_COLD) &&
998 (next != QLC_83XX_IDC_DEV_READY)) {
999 dev_err(&adapter->pdev->dev,
1000 "%s: failed, cur %d prev %d next %d\n",
1001 __func__, cur, prev, next);
1006 if (next == QLC_83XX_IDC_DEV_INIT) {
1007 if ((prev != QLC_83XX_IDC_DEV_INIT) &&
1008 (prev != QLC_83XX_IDC_DEV_COLD) &&
1009 (prev != QLC_83XX_IDC_DEV_NEED_RESET)) {
1010 dev_err(&adapter->pdev->dev,
1011 "%s: failed, cur %d prev %d next %d\n",
1012 __func__, cur, prev, next);
1020 static void qlcnic_83xx_periodic_tasks(struct qlcnic_adapter *adapter)
1022 if (adapter->fhash.fnum)
1023 qlcnic_prune_lb_filters(adapter);
1027 * qlcnic_83xx_idc_poll_dev_state
1029 * @work: kernel work queue structure used to schedule the function
1031 * Poll device state periodically and perform state specific
1032 * actions defined by Inter Driver Communication (IDC) protocol.
1037 void qlcnic_83xx_idc_poll_dev_state(struct work_struct *work)
1039 struct qlcnic_adapter *adapter;
1042 adapter = container_of(work, struct qlcnic_adapter, fw_work.work);
1043 state = QLCRDX(adapter->ahw, QLC_83XX_IDC_DEV_STATE);
1045 if (qlcnic_83xx_idc_check_state_validity(adapter, state)) {
1046 qlcnic_83xx_idc_log_state_history(adapter);
1047 adapter->ahw->idc.curr_state = QLC_83XX_IDC_DEV_UNKNOWN;
1049 adapter->ahw->idc.curr_state = state;
1052 switch (adapter->ahw->idc.curr_state) {
1053 case QLC_83XX_IDC_DEV_READY:
1054 qlcnic_83xx_idc_ready_state(adapter);
1056 case QLC_83XX_IDC_DEV_NEED_RESET:
1057 qlcnic_83xx_idc_need_reset_state(adapter);
1059 case QLC_83XX_IDC_DEV_NEED_QUISCENT:
1060 qlcnic_83xx_idc_need_quiesce_state(adapter);
1062 case QLC_83XX_IDC_DEV_FAILED:
1063 qlcnic_83xx_idc_failed_state(adapter);
1065 case QLC_83XX_IDC_DEV_INIT:
1066 qlcnic_83xx_idc_init_state(adapter);
1068 case QLC_83XX_IDC_DEV_QUISCENT:
1069 qlcnic_83xx_idc_quiesce_state(adapter);
1072 qlcnic_83xx_idc_unknown_state(adapter);
1075 adapter->ahw->idc.prev_state = adapter->ahw->idc.curr_state;
1076 qlcnic_83xx_periodic_tasks(adapter);
1078 /* Re-schedule the function */
1079 if (test_bit(QLC_83XX_MODULE_LOADED, &adapter->ahw->idc.status))
1080 qlcnic_schedule_work(adapter, qlcnic_83xx_idc_poll_dev_state,
1081 adapter->ahw->idc.delay);
1084 static void qlcnic_83xx_setup_idc_parameters(struct qlcnic_adapter *adapter)
1086 u32 idc_params, val;
1088 if (qlcnic_83xx_lockless_flash_read32(adapter,
1089 QLC_83XX_IDC_FLASH_PARAM_ADDR,
1090 (u8 *)&idc_params, 1)) {
1091 dev_info(&adapter->pdev->dev,
1092 "%s:failed to get IDC params from flash\n", __func__);
1093 adapter->dev_init_timeo = QLC_83XX_IDC_INIT_TIMEOUT_SECS;
1094 adapter->reset_ack_timeo = QLC_83XX_IDC_RESET_TIMEOUT_SECS;
1096 adapter->dev_init_timeo = idc_params & 0xFFFF;
1097 adapter->reset_ack_timeo = ((idc_params >> 16) & 0xFFFF);
1100 adapter->ahw->idc.curr_state = QLC_83XX_IDC_DEV_UNKNOWN;
1101 adapter->ahw->idc.prev_state = QLC_83XX_IDC_DEV_UNKNOWN;
1102 adapter->ahw->idc.delay = QLC_83XX_IDC_FW_POLL_DELAY;
1103 adapter->ahw->idc.err_code = 0;
1104 adapter->ahw->idc.collect_dump = 0;
1105 adapter->ahw->idc.name = (char **)qlc_83xx_idc_states;
1107 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1108 set_bit(QLC_83XX_MODULE_LOADED, &adapter->ahw->idc.status);
1110 /* Check if reset recovery is disabled */
1111 if (!qlcnic_auto_fw_reset) {
1112 /* Propagate do not reset request to other functions */
1113 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1114 val = val | QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY;
1115 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
1120 qlcnic_83xx_idc_first_to_load_function_handler(struct qlcnic_adapter *adapter)
1124 if (qlcnic_83xx_lock_driver(adapter))
1127 /* Clear driver lock register */
1128 QLCWRX(adapter->ahw, QLC_83XX_RECOVER_DRV_LOCK, 0);
1129 if (qlcnic_83xx_idc_update_major_version(adapter, 0)) {
1130 qlcnic_83xx_unlock_driver(adapter);
1134 state = QLCRDX(adapter->ahw, QLC_83XX_IDC_DEV_STATE);
1135 if (qlcnic_83xx_idc_check_state_validity(adapter, state)) {
1136 qlcnic_83xx_unlock_driver(adapter);
1140 if (state != QLC_83XX_IDC_DEV_COLD && qlcnic_load_fw_file) {
1141 QLCWRX(adapter->ahw, QLC_83XX_IDC_DEV_STATE,
1142 QLC_83XX_IDC_DEV_COLD);
1143 state = QLC_83XX_IDC_DEV_COLD;
1146 adapter->ahw->idc.curr_state = state;
1147 /* First to load function should cold boot the device */
1148 if (state == QLC_83XX_IDC_DEV_COLD)
1149 qlcnic_83xx_idc_cold_state_handler(adapter);
1151 /* Check if reset recovery is enabled */
1152 if (qlcnic_auto_fw_reset) {
1153 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1154 val = val & ~QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY;
1155 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
1158 qlcnic_83xx_unlock_driver(adapter);
1163 int qlcnic_83xx_idc_init(struct qlcnic_adapter *adapter)
1167 qlcnic_83xx_setup_idc_parameters(adapter);
1169 if (qlcnic_83xx_get_reset_instruction_template(adapter))
1172 if (!qlcnic_83xx_idc_check_driver_presence_reg(adapter)) {
1173 if (qlcnic_83xx_idc_first_to_load_function_handler(adapter))
1176 if (qlcnic_83xx_idc_check_major_version(adapter))
1180 qlcnic_83xx_idc_update_audit_reg(adapter, 0, 1);
1185 void qlcnic_83xx_idc_exit(struct qlcnic_adapter *adapter)
1190 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1191 usleep_range(10000, 11000);
1193 id = QLCRDX(adapter->ahw, QLC_83XX_DRV_LOCK_ID);
1196 if (id == adapter->portnum) {
1197 dev_err(&adapter->pdev->dev,
1198 "%s: wait for lock recovery.. %d\n", __func__, id);
1200 id = QLCRDX(adapter->ahw, QLC_83XX_DRV_LOCK_ID);
1204 /* Clear driver presence bit */
1205 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE);
1206 val = val & ~(1 << adapter->portnum);
1207 QLCWRX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE, val);
1208 clear_bit(QLC_83XX_MODULE_LOADED, &adapter->ahw->idc.status);
1209 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1211 cancel_delayed_work_sync(&adapter->fw_work);
1214 void qlcnic_83xx_idc_request_reset(struct qlcnic_adapter *adapter, u32 key)
1218 if (qlcnic_sriov_vf_check(adapter))
1221 if (qlcnic_83xx_lock_driver(adapter)) {
1222 dev_err(&adapter->pdev->dev,
1223 "%s:failed, please retry\n", __func__);
1227 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1228 if (val & QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY) {
1229 netdev_info(adapter->netdev, "%s: Auto firmware recovery is disabled\n",
1231 qlcnic_83xx_idc_enter_failed_state(adapter, 0);
1232 qlcnic_83xx_unlock_driver(adapter);
1236 if (key == QLCNIC_FORCE_FW_RESET) {
1237 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1238 val = val | QLC_83XX_IDC_GRACEFULL_RESET;
1239 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
1240 } else if (key == QLCNIC_FORCE_FW_DUMP_KEY) {
1241 adapter->ahw->idc.collect_dump = 1;
1244 qlcnic_83xx_unlock_driver(adapter);
1248 static int qlcnic_83xx_copy_bootloader(struct qlcnic_adapter *adapter)
1255 src = QLC_83XX_BOOTLOADER_FLASH_ADDR;
1256 dest = QLCRDX(adapter->ahw, QLCNIC_BOOTLOADER_ADDR);
1257 size = QLCRDX(adapter->ahw, QLCNIC_BOOTLOADER_SIZE);
1259 /* alignment check */
1261 size = (size + 16) & ~0xF;
1263 p_cache = vzalloc(size);
1264 if (p_cache == NULL)
1267 ret = qlcnic_83xx_lockless_flash_read32(adapter, src, p_cache,
1268 size / sizeof(u32));
1273 /* 16 byte write to MS memory */
1274 ret = qlcnic_83xx_ms_mem_write128(adapter, dest, (u32 *)p_cache,
1285 static int qlcnic_83xx_copy_fw_file(struct qlcnic_adapter *adapter)
1287 struct qlc_83xx_fw_info *fw_info = adapter->ahw->fw_info;
1288 const struct firmware *fw = fw_info->fw;
1295 dest = QLCRDX(adapter->ahw, QLCNIC_FW_IMAGE_ADDR);
1296 size = (fw->size & ~0xF);
1297 p_cache = (u32 *)fw->data;
1300 ret = qlcnic_83xx_ms_mem_write128(adapter, addr,
1301 (u32 *)p_cache, size / 16);
1303 dev_err(&adapter->pdev->dev, "MS memory write failed\n");
1304 release_firmware(fw);
1309 /* alignment check */
1310 if (fw->size & 0xF) {
1312 for (i = 0; i < (fw->size & 0xF); i++)
1313 data[i] = fw->data[size + i];
1316 ret = qlcnic_83xx_ms_mem_write128(adapter, addr,
1319 dev_err(&adapter->pdev->dev,
1320 "MS memory write failed\n");
1321 release_firmware(fw);
1326 release_firmware(fw);
1332 static void qlcnic_83xx_dump_pause_control_regs(struct qlcnic_adapter *adapter)
1335 u32 val = 0, val1 = 0, reg = 0;
1338 val = QLCRD32(adapter, QLC_83XX_SRE_SHIM_REG, &err);
1341 dev_info(&adapter->pdev->dev, "SRE-Shim Ctrl:0x%x\n", val);
1343 for (j = 0; j < 2; j++) {
1345 dev_info(&adapter->pdev->dev,
1346 "Port 0 RxB Pause Threshold Regs[TC7..TC0]:");
1347 reg = QLC_83XX_PORT0_THRESHOLD;
1348 } else if (j == 1) {
1349 dev_info(&adapter->pdev->dev,
1350 "Port 1 RxB Pause Threshold Regs[TC7..TC0]:");
1351 reg = QLC_83XX_PORT1_THRESHOLD;
1353 for (i = 0; i < 8; i++) {
1354 val = QLCRD32(adapter, reg + (i * 0x4), &err);
1357 dev_info(&adapter->pdev->dev, "0x%x ", val);
1359 dev_info(&adapter->pdev->dev, "\n");
1362 for (j = 0; j < 2; j++) {
1364 dev_info(&adapter->pdev->dev,
1365 "Port 0 RxB TC Max Cell Registers[4..1]:");
1366 reg = QLC_83XX_PORT0_TC_MC_REG;
1367 } else if (j == 1) {
1368 dev_info(&adapter->pdev->dev,
1369 "Port 1 RxB TC Max Cell Registers[4..1]:");
1370 reg = QLC_83XX_PORT1_TC_MC_REG;
1372 for (i = 0; i < 4; i++) {
1373 val = QLCRD32(adapter, reg + (i * 0x4), &err);
1376 dev_info(&adapter->pdev->dev, "0x%x ", val);
1378 dev_info(&adapter->pdev->dev, "\n");
1381 for (j = 0; j < 2; j++) {
1383 dev_info(&adapter->pdev->dev,
1384 "Port 0 RxB Rx TC Stats[TC7..TC0]:");
1385 reg = QLC_83XX_PORT0_TC_STATS;
1386 } else if (j == 1) {
1387 dev_info(&adapter->pdev->dev,
1388 "Port 1 RxB Rx TC Stats[TC7..TC0]:");
1389 reg = QLC_83XX_PORT1_TC_STATS;
1391 for (i = 7; i >= 0; i--) {
1392 val = QLCRD32(adapter, reg, &err);
1395 val &= ~(0x7 << 29); /* Reset bits 29 to 31 */
1396 QLCWR32(adapter, reg, (val | (i << 29)));
1397 val = QLCRD32(adapter, reg, &err);
1400 dev_info(&adapter->pdev->dev, "0x%x ", val);
1402 dev_info(&adapter->pdev->dev, "\n");
1405 val = QLCRD32(adapter, QLC_83XX_PORT2_IFB_THRESHOLD, &err);
1408 val1 = QLCRD32(adapter, QLC_83XX_PORT3_IFB_THRESHOLD, &err);
1411 dev_info(&adapter->pdev->dev,
1412 "IFB-Pause Thresholds: Port 2:0x%x, Port 3:0x%x\n",
1417 static void qlcnic_83xx_disable_pause_frames(struct qlcnic_adapter *adapter)
1421 if (qlcnic_83xx_lock_driver(adapter)) {
1422 dev_err(&adapter->pdev->dev,
1423 "%s:failed to acquire driver lock\n", __func__);
1427 qlcnic_83xx_dump_pause_control_regs(adapter);
1428 QLCWR32(adapter, QLC_83XX_SRE_SHIM_REG, 0x0);
1430 for (j = 0; j < 2; j++) {
1432 reg = QLC_83XX_PORT0_THRESHOLD;
1434 reg = QLC_83XX_PORT1_THRESHOLD;
1436 for (i = 0; i < 8; i++)
1437 QLCWR32(adapter, reg + (i * 0x4), 0x0);
1440 for (j = 0; j < 2; j++) {
1442 reg = QLC_83XX_PORT0_TC_MC_REG;
1444 reg = QLC_83XX_PORT1_TC_MC_REG;
1446 for (i = 0; i < 4; i++)
1447 QLCWR32(adapter, reg + (i * 0x4), 0x03FF03FF);
1450 QLCWR32(adapter, QLC_83XX_PORT2_IFB_THRESHOLD, 0);
1451 QLCWR32(adapter, QLC_83XX_PORT3_IFB_THRESHOLD, 0);
1452 dev_info(&adapter->pdev->dev,
1453 "Disabled pause frames successfully on all ports\n");
1454 qlcnic_83xx_unlock_driver(adapter);
1457 static void qlcnic_83xx_take_eport_out_of_reset(struct qlcnic_adapter *adapter)
1459 QLCWR32(adapter, QLC_83XX_RESET_REG, 0);
1460 QLCWR32(adapter, QLC_83XX_RESET_PORT0, 0);
1461 QLCWR32(adapter, QLC_83XX_RESET_PORT1, 0);
1462 QLCWR32(adapter, QLC_83XX_RESET_PORT2, 0);
1463 QLCWR32(adapter, QLC_83XX_RESET_PORT3, 0);
1464 QLCWR32(adapter, QLC_83XX_RESET_SRESHIM, 0);
1465 QLCWR32(adapter, QLC_83XX_RESET_EPGSHIM, 0);
1466 QLCWR32(adapter, QLC_83XX_RESET_ETHERPCS, 0);
1467 QLCWR32(adapter, QLC_83XX_RESET_CONTROL, 1);
1470 static int qlcnic_83xx_check_heartbeat(struct qlcnic_adapter *p_dev)
1472 u32 heartbeat, peg_status;
1473 int retries, ret = -EIO, err = 0;
1475 retries = QLCNIC_HEARTBEAT_CHECK_RETRY_COUNT;
1476 p_dev->heartbeat = QLC_SHARED_REG_RD32(p_dev,
1477 QLCNIC_PEG_ALIVE_COUNTER);
1480 msleep(QLCNIC_HEARTBEAT_PERIOD_MSECS);
1481 heartbeat = QLC_SHARED_REG_RD32(p_dev,
1482 QLCNIC_PEG_ALIVE_COUNTER);
1483 if (heartbeat != p_dev->heartbeat) {
1484 ret = QLCNIC_RCODE_SUCCESS;
1487 } while (--retries);
1490 dev_err(&p_dev->pdev->dev, "firmware hang detected\n");
1491 qlcnic_83xx_take_eport_out_of_reset(p_dev);
1492 qlcnic_83xx_disable_pause_frames(p_dev);
1493 peg_status = QLC_SHARED_REG_RD32(p_dev,
1494 QLCNIC_PEG_HALT_STATUS1);
1495 dev_info(&p_dev->pdev->dev, "Dumping HW/FW registers\n"
1496 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
1497 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
1498 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
1499 "PEG_NET_4_PC: 0x%x\n", peg_status,
1500 QLC_SHARED_REG_RD32(p_dev, QLCNIC_PEG_HALT_STATUS2),
1501 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_0, &err),
1502 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_1, &err),
1503 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_2, &err),
1504 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_3, &err),
1505 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_4, &err));
1507 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
1508 dev_err(&p_dev->pdev->dev,
1509 "Device is being reset err code 0x00006700.\n");
1515 static int qlcnic_83xx_check_cmd_peg_status(struct qlcnic_adapter *p_dev)
1517 int retries = QLCNIC_CMDPEG_CHECK_RETRY_COUNT;
1521 val = QLC_SHARED_REG_RD32(p_dev, QLCNIC_CMDPEG_STATE);
1522 if (val == QLC_83XX_CMDPEG_COMPLETE)
1524 msleep(QLCNIC_CMDPEG_CHECK_DELAY);
1525 } while (--retries);
1527 dev_err(&p_dev->pdev->dev, "%s: failed, state = 0x%x\n", __func__, val);
1531 int qlcnic_83xx_check_hw_status(struct qlcnic_adapter *p_dev)
1535 err = qlcnic_83xx_check_cmd_peg_status(p_dev);
1539 err = qlcnic_83xx_check_heartbeat(p_dev);
1546 static int qlcnic_83xx_poll_reg(struct qlcnic_adapter *p_dev, u32 addr,
1547 int duration, u32 mask, u32 status)
1549 int timeout_error, err = 0;
1553 value = QLCRD32(p_dev, addr, &err);
1556 retries = duration / 10;
1559 if ((value & mask) != status) {
1561 msleep(duration / 10);
1562 value = QLCRD32(p_dev, addr, &err);
1569 } while (retries--);
1571 if (timeout_error) {
1572 p_dev->ahw->reset.seq_error++;
1573 dev_err(&p_dev->pdev->dev,
1574 "%s: Timeout Err, entry_num = %d\n",
1575 __func__, p_dev->ahw->reset.seq_index);
1576 dev_err(&p_dev->pdev->dev,
1577 "0x%08x 0x%08x 0x%08x\n",
1578 value, mask, status);
1581 return timeout_error;
1584 static int qlcnic_83xx_reset_template_checksum(struct qlcnic_adapter *p_dev)
1587 u16 *buff = (u16 *)p_dev->ahw->reset.buff;
1588 int count = p_dev->ahw->reset.hdr->size / sizeof(u16);
1594 sum = (sum & 0xFFFF) + (sum >> 16);
1599 dev_err(&p_dev->pdev->dev, "%s: failed\n", __func__);
1604 int qlcnic_83xx_get_reset_instruction_template(struct qlcnic_adapter *p_dev)
1606 struct qlcnic_hardware_context *ahw = p_dev->ahw;
1607 u32 addr, count, prev_ver, curr_ver;
1610 if (ahw->reset.buff != NULL) {
1611 prev_ver = p_dev->fw_version;
1612 curr_ver = qlcnic_83xx_get_fw_version(p_dev);
1613 if (curr_ver > prev_ver)
1614 kfree(ahw->reset.buff);
1619 ahw->reset.seq_error = 0;
1620 ahw->reset.buff = kzalloc(QLC_83XX_RESTART_TEMPLATE_SIZE, GFP_KERNEL);
1621 if (p_dev->ahw->reset.buff == NULL)
1624 p_buff = p_dev->ahw->reset.buff;
1625 addr = QLC_83XX_RESET_TEMPLATE_ADDR;
1626 count = sizeof(struct qlc_83xx_reset_hdr) / sizeof(u32);
1628 /* Copy template header from flash */
1629 if (qlcnic_83xx_flash_read32(p_dev, addr, p_buff, count)) {
1630 dev_err(&p_dev->pdev->dev, "%s: flash read failed\n", __func__);
1633 ahw->reset.hdr = (struct qlc_83xx_reset_hdr *)ahw->reset.buff;
1634 addr = QLC_83XX_RESET_TEMPLATE_ADDR + ahw->reset.hdr->hdr_size;
1635 p_buff = ahw->reset.buff + ahw->reset.hdr->hdr_size;
1636 count = (ahw->reset.hdr->size - ahw->reset.hdr->hdr_size) / sizeof(u32);
1638 /* Copy rest of the template */
1639 if (qlcnic_83xx_flash_read32(p_dev, addr, p_buff, count)) {
1640 dev_err(&p_dev->pdev->dev, "%s: flash read failed\n", __func__);
1644 if (qlcnic_83xx_reset_template_checksum(p_dev))
1646 /* Get Stop, Start and Init command offsets */
1647 ahw->reset.init_offset = ahw->reset.buff + ahw->reset.hdr->init_offset;
1648 ahw->reset.start_offset = ahw->reset.buff +
1649 ahw->reset.hdr->start_offset;
1650 ahw->reset.stop_offset = ahw->reset.buff + ahw->reset.hdr->hdr_size;
1654 /* Read Write HW register command */
1655 static void qlcnic_83xx_read_write_crb_reg(struct qlcnic_adapter *p_dev,
1656 u32 raddr, u32 waddr)
1661 value = QLCRD32(p_dev, raddr, &err);
1664 qlcnic_83xx_wrt_reg_indirect(p_dev, waddr, value);
1667 /* Read Modify Write HW register command */
1668 static void qlcnic_83xx_rmw_crb_reg(struct qlcnic_adapter *p_dev,
1669 u32 raddr, u32 waddr,
1670 struct qlc_83xx_rmw *p_rmw_hdr)
1675 if (p_rmw_hdr->index_a) {
1676 value = p_dev->ahw->reset.array[p_rmw_hdr->index_a];
1678 value = QLCRD32(p_dev, raddr, &err);
1683 value &= p_rmw_hdr->mask;
1684 value <<= p_rmw_hdr->shl;
1685 value >>= p_rmw_hdr->shr;
1686 value |= p_rmw_hdr->or_value;
1687 value ^= p_rmw_hdr->xor_value;
1688 qlcnic_83xx_wrt_reg_indirect(p_dev, waddr, value);
1691 /* Write HW register command */
1692 static void qlcnic_83xx_write_list(struct qlcnic_adapter *p_dev,
1693 struct qlc_83xx_entry_hdr *p_hdr)
1696 struct qlc_83xx_entry *entry;
1698 entry = (struct qlc_83xx_entry *)((char *)p_hdr +
1699 sizeof(struct qlc_83xx_entry_hdr));
1701 for (i = 0; i < p_hdr->count; i++, entry++) {
1702 qlcnic_83xx_wrt_reg_indirect(p_dev, entry->arg1,
1705 udelay((u32)(p_hdr->delay));
1709 /* Read and Write instruction */
1710 static void qlcnic_83xx_read_write_list(struct qlcnic_adapter *p_dev,
1711 struct qlc_83xx_entry_hdr *p_hdr)
1714 struct qlc_83xx_entry *entry;
1716 entry = (struct qlc_83xx_entry *)((char *)p_hdr +
1717 sizeof(struct qlc_83xx_entry_hdr));
1719 for (i = 0; i < p_hdr->count; i++, entry++) {
1720 qlcnic_83xx_read_write_crb_reg(p_dev, entry->arg1,
1723 udelay((u32)(p_hdr->delay));
1727 /* Poll HW register command */
1728 static void qlcnic_83xx_poll_list(struct qlcnic_adapter *p_dev,
1729 struct qlc_83xx_entry_hdr *p_hdr)
1732 struct qlc_83xx_entry *entry;
1733 struct qlc_83xx_poll *poll;
1735 unsigned long arg1, arg2;
1737 poll = (struct qlc_83xx_poll *)((char *)p_hdr +
1738 sizeof(struct qlc_83xx_entry_hdr));
1740 entry = (struct qlc_83xx_entry *)((char *)poll +
1741 sizeof(struct qlc_83xx_poll));
1742 delay = (long)p_hdr->delay;
1745 for (i = 0; i < p_hdr->count; i++, entry++)
1746 qlcnic_83xx_poll_reg(p_dev, entry->arg1,
1750 for (i = 0; i < p_hdr->count; i++, entry++) {
1754 if (qlcnic_83xx_poll_reg(p_dev,
1758 QLCRD32(p_dev, arg1, &err);
1761 QLCRD32(p_dev, arg2, &err);
1770 /* Poll and write HW register command */
1771 static void qlcnic_83xx_poll_write_list(struct qlcnic_adapter *p_dev,
1772 struct qlc_83xx_entry_hdr *p_hdr)
1776 struct qlc_83xx_quad_entry *entry;
1777 struct qlc_83xx_poll *poll;
1779 poll = (struct qlc_83xx_poll *)((char *)p_hdr +
1780 sizeof(struct qlc_83xx_entry_hdr));
1781 entry = (struct qlc_83xx_quad_entry *)((char *)poll +
1782 sizeof(struct qlc_83xx_poll));
1783 delay = (long)p_hdr->delay;
1785 for (i = 0; i < p_hdr->count; i++, entry++) {
1786 qlcnic_83xx_wrt_reg_indirect(p_dev, entry->dr_addr,
1788 qlcnic_83xx_wrt_reg_indirect(p_dev, entry->ar_addr,
1791 qlcnic_83xx_poll_reg(p_dev, entry->ar_addr, delay,
1792 poll->mask, poll->status);
1796 /* Read Modify Write register command */
1797 static void qlcnic_83xx_read_modify_write(struct qlcnic_adapter *p_dev,
1798 struct qlc_83xx_entry_hdr *p_hdr)
1801 struct qlc_83xx_entry *entry;
1802 struct qlc_83xx_rmw *rmw_hdr;
1804 rmw_hdr = (struct qlc_83xx_rmw *)((char *)p_hdr +
1805 sizeof(struct qlc_83xx_entry_hdr));
1807 entry = (struct qlc_83xx_entry *)((char *)rmw_hdr +
1808 sizeof(struct qlc_83xx_rmw));
1810 for (i = 0; i < p_hdr->count; i++, entry++) {
1811 qlcnic_83xx_rmw_crb_reg(p_dev, entry->arg1,
1812 entry->arg2, rmw_hdr);
1814 udelay((u32)(p_hdr->delay));
1818 static void qlcnic_83xx_pause(struct qlc_83xx_entry_hdr *p_hdr)
1821 mdelay((u32)((long)p_hdr->delay));
1824 /* Read and poll register command */
1825 static void qlcnic_83xx_poll_read_list(struct qlcnic_adapter *p_dev,
1826 struct qlc_83xx_entry_hdr *p_hdr)
1829 int index, i, j, err;
1830 struct qlc_83xx_quad_entry *entry;
1831 struct qlc_83xx_poll *poll;
1834 poll = (struct qlc_83xx_poll *)((char *)p_hdr +
1835 sizeof(struct qlc_83xx_entry_hdr));
1837 entry = (struct qlc_83xx_quad_entry *)((char *)poll +
1838 sizeof(struct qlc_83xx_poll));
1839 delay = (long)p_hdr->delay;
1841 for (i = 0; i < p_hdr->count; i++, entry++) {
1842 qlcnic_83xx_wrt_reg_indirect(p_dev, entry->ar_addr,
1845 if (!qlcnic_83xx_poll_reg(p_dev, entry->ar_addr, delay,
1846 poll->mask, poll->status)){
1847 index = p_dev->ahw->reset.array_index;
1848 addr = entry->dr_addr;
1849 j = QLCRD32(p_dev, addr, &err);
1853 p_dev->ahw->reset.array[index++] = j;
1855 if (index == QLC_83XX_MAX_RESET_SEQ_ENTRIES)
1856 p_dev->ahw->reset.array_index = 1;
1862 static inline void qlcnic_83xx_seq_end(struct qlcnic_adapter *p_dev)
1864 p_dev->ahw->reset.seq_end = 1;
1867 static void qlcnic_83xx_template_end(struct qlcnic_adapter *p_dev)
1869 p_dev->ahw->reset.template_end = 1;
1870 if (p_dev->ahw->reset.seq_error == 0)
1871 dev_err(&p_dev->pdev->dev,
1872 "HW restart process completed successfully.\n");
1874 dev_err(&p_dev->pdev->dev,
1875 "HW restart completed with timeout errors.\n");
1879 * qlcnic_83xx_exec_template_cmd
1881 * @p_dev: adapter structure
1882 * @p_buff: Poiter to instruction template
1884 * Template provides instructions to stop, restart and initalize firmware.
1885 * These instructions are abstracted as a series of read, write and
1886 * poll operations on hardware registers. Register information and operation
1887 * specifics are not exposed to the driver. Driver reads the template from
1888 * flash and executes the instructions located at pre-defined offsets.
1892 static void qlcnic_83xx_exec_template_cmd(struct qlcnic_adapter *p_dev,
1896 struct qlc_83xx_entry_hdr *p_hdr;
1897 char *entry = p_buff;
1899 p_dev->ahw->reset.seq_end = 0;
1900 p_dev->ahw->reset.template_end = 0;
1901 entries = p_dev->ahw->reset.hdr->entries;
1902 index = p_dev->ahw->reset.seq_index;
1904 for (; (!p_dev->ahw->reset.seq_end) && (index < entries); index++) {
1905 p_hdr = (struct qlc_83xx_entry_hdr *)entry;
1907 switch (p_hdr->cmd) {
1908 case QLC_83XX_OPCODE_NOP:
1910 case QLC_83XX_OPCODE_WRITE_LIST:
1911 qlcnic_83xx_write_list(p_dev, p_hdr);
1913 case QLC_83XX_OPCODE_READ_WRITE_LIST:
1914 qlcnic_83xx_read_write_list(p_dev, p_hdr);
1916 case QLC_83XX_OPCODE_POLL_LIST:
1917 qlcnic_83xx_poll_list(p_dev, p_hdr);
1919 case QLC_83XX_OPCODE_POLL_WRITE_LIST:
1920 qlcnic_83xx_poll_write_list(p_dev, p_hdr);
1922 case QLC_83XX_OPCODE_READ_MODIFY_WRITE:
1923 qlcnic_83xx_read_modify_write(p_dev, p_hdr);
1925 case QLC_83XX_OPCODE_SEQ_PAUSE:
1926 qlcnic_83xx_pause(p_hdr);
1928 case QLC_83XX_OPCODE_SEQ_END:
1929 qlcnic_83xx_seq_end(p_dev);
1931 case QLC_83XX_OPCODE_TMPL_END:
1932 qlcnic_83xx_template_end(p_dev);
1934 case QLC_83XX_OPCODE_POLL_READ_LIST:
1935 qlcnic_83xx_poll_read_list(p_dev, p_hdr);
1938 dev_err(&p_dev->pdev->dev,
1939 "%s: Unknown opcode 0x%04x in template %d\n",
1940 __func__, p_hdr->cmd, index);
1943 entry += p_hdr->size;
1945 p_dev->ahw->reset.seq_index = index;
1948 void qlcnic_83xx_stop_hw(struct qlcnic_adapter *p_dev)
1950 p_dev->ahw->reset.seq_index = 0;
1952 qlcnic_83xx_exec_template_cmd(p_dev, p_dev->ahw->reset.stop_offset);
1953 if (p_dev->ahw->reset.seq_end != 1)
1954 dev_err(&p_dev->pdev->dev, "%s: failed\n", __func__);
1957 static void qlcnic_83xx_start_hw(struct qlcnic_adapter *p_dev)
1959 qlcnic_83xx_exec_template_cmd(p_dev, p_dev->ahw->reset.start_offset);
1960 if (p_dev->ahw->reset.template_end != 1)
1961 dev_err(&p_dev->pdev->dev, "%s: failed\n", __func__);
1964 static void qlcnic_83xx_init_hw(struct qlcnic_adapter *p_dev)
1966 qlcnic_83xx_exec_template_cmd(p_dev, p_dev->ahw->reset.init_offset);
1967 if (p_dev->ahw->reset.seq_end != 1)
1968 dev_err(&p_dev->pdev->dev, "%s: failed\n", __func__);
1971 static int qlcnic_83xx_load_fw_image_from_host(struct qlcnic_adapter *adapter)
1973 struct qlc_83xx_fw_info *fw_info = adapter->ahw->fw_info;
1976 if (request_firmware(&fw_info->fw, fw_info->fw_file_name,
1977 &(adapter->pdev->dev))) {
1978 dev_err(&adapter->pdev->dev,
1979 "No file FW image, loading flash FW image.\n");
1980 QLC_SHARED_REG_WR32(adapter, QLCNIC_FW_IMG_VALID,
1981 QLC_83XX_BOOT_FROM_FLASH);
1983 if (qlcnic_83xx_copy_fw_file(adapter))
1985 QLC_SHARED_REG_WR32(adapter, QLCNIC_FW_IMG_VALID,
1986 QLC_83XX_BOOT_FROM_FILE);
1992 static int qlcnic_83xx_restart_hw(struct qlcnic_adapter *adapter)
1997 qlcnic_83xx_stop_hw(adapter);
1999 /* Collect FW register dump if required */
2000 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
2001 if (!(val & QLC_83XX_IDC_GRACEFULL_RESET))
2002 qlcnic_dump_fw(adapter);
2004 if (val & QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY) {
2005 netdev_info(adapter->netdev, "%s: Auto firmware recovery is disabled\n",
2007 qlcnic_83xx_idc_enter_failed_state(adapter, 1);
2011 qlcnic_83xx_init_hw(adapter);
2013 if (qlcnic_83xx_copy_bootloader(adapter))
2015 /* Boot either flash image or firmware image from host file system */
2016 if (qlcnic_load_fw_file) {
2017 if (qlcnic_83xx_load_fw_image_from_host(adapter))
2020 QLC_SHARED_REG_WR32(adapter, QLCNIC_FW_IMG_VALID,
2021 QLC_83XX_BOOT_FROM_FLASH);
2024 qlcnic_83xx_start_hw(adapter);
2025 if (qlcnic_83xx_check_hw_status(adapter))
2031 int qlcnic_83xx_get_nic_configuration(struct qlcnic_adapter *adapter)
2034 struct qlcnic_info nic_info;
2035 struct qlcnic_hardware_context *ahw = adapter->ahw;
2037 memset(&nic_info, 0, sizeof(struct qlcnic_info));
2038 err = qlcnic_get_nic_info(adapter, &nic_info, ahw->pci_func);
2042 ahw->physical_port = (u8) nic_info.phys_port;
2043 ahw->switch_mode = nic_info.switch_mode;
2044 ahw->max_tx_ques = nic_info.max_tx_ques;
2045 ahw->max_rx_ques = nic_info.max_rx_ques;
2046 ahw->capabilities = nic_info.capabilities;
2047 ahw->max_mac_filters = nic_info.max_mac_filters;
2048 ahw->max_mtu = nic_info.max_mtu;
2050 adapter->max_tx_rings = ahw->max_tx_ques;
2051 adapter->max_sds_rings = ahw->max_rx_ques;
2052 /* eSwitch capability indicates vNIC mode.
2053 * vNIC and SRIOV are mutually exclusive operational modes.
2054 * If SR-IOV capability is detected, SR-IOV physical function
2055 * will get initialized in default mode.
2056 * SR-IOV virtual function initialization follows a
2057 * different code path and opmode.
2058 * SRIOV mode has precedence over vNIC mode.
2060 if (test_bit(__QLCNIC_SRIOV_CAPABLE, &adapter->state))
2061 return QLC_83XX_DEFAULT_OPMODE;
2063 if (ahw->capabilities & QLC_83XX_ESWITCH_CAPABILITY)
2064 return QLCNIC_VNIC_MODE;
2066 return QLC_83XX_DEFAULT_OPMODE;
2069 int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
2071 struct qlcnic_hardware_context *ahw = adapter->ahw;
2074 ret = qlcnic_83xx_get_nic_configuration(adapter);
2078 if (ret == QLCNIC_VNIC_MODE) {
2079 ahw->nic_mode = QLCNIC_VNIC_MODE;
2081 if (qlcnic_83xx_config_vnic_opmode(adapter))
2084 adapter->max_sds_rings = QLCNIC_MAX_VNIC_SDS_RINGS;
2085 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
2086 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
2087 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
2088 adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
2089 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
2090 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
2091 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
2099 static void qlcnic_83xx_config_buff_descriptors(struct qlcnic_adapter *adapter)
2101 struct qlcnic_hardware_context *ahw = adapter->ahw;
2103 if (ahw->port_type == QLCNIC_XGBE) {
2104 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
2105 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
2106 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
2107 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
2109 } else if (ahw->port_type == QLCNIC_GBE) {
2110 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
2111 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
2112 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
2113 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
2115 adapter->num_txd = MAX_CMD_DESCRIPTORS;
2116 adapter->max_rds_rings = MAX_RDS_RINGS;
2119 static int qlcnic_83xx_init_default_driver(struct qlcnic_adapter *adapter)
2123 qlcnic_83xx_get_minidump_template(adapter);
2124 if (qlcnic_83xx_get_port_info(adapter))
2127 qlcnic_83xx_config_buff_descriptors(adapter);
2128 adapter->ahw->msix_supported = !!qlcnic_use_msi_x;
2129 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
2131 dev_info(&adapter->pdev->dev, "HAL Version: %d\n",
2132 adapter->ahw->fw_hal_version);
2137 #define IS_QLC_83XX_USED(a, b, c) (((1 << a->portnum) & b) || ((c >> 6) & 0x1))
2138 static void qlcnic_83xx_clear_function_resources(struct qlcnic_adapter *adapter)
2140 struct qlcnic_cmd_args cmd;
2141 u32 presence_mask, audit_mask;
2144 presence_mask = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE);
2145 audit_mask = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_AUDIT);
2147 if (IS_QLC_83XX_USED(adapter, presence_mask, audit_mask)) {
2148 status = qlcnic_alloc_mbx_args(&cmd, adapter,
2149 QLCNIC_CMD_STOP_NIC_FUNC);
2153 cmd.req.arg[1] = BIT_31;
2154 status = qlcnic_issue_cmd(adapter, &cmd);
2156 dev_err(&adapter->pdev->dev,
2157 "Failed to clean up the function resources\n");
2158 qlcnic_free_mbx_args(&cmd);
2162 static int qlcnic_83xx_get_fw_info(struct qlcnic_adapter *adapter)
2164 struct qlcnic_hardware_context *ahw = adapter->ahw;
2165 struct pci_dev *pdev = adapter->pdev;
2166 struct qlc_83xx_fw_info *fw_info;
2169 ahw->fw_info = kzalloc(sizeof(*fw_info), GFP_KERNEL);
2170 if (!ahw->fw_info) {
2173 fw_info = ahw->fw_info;
2174 switch (pdev->device) {
2175 case PCI_DEVICE_ID_QLOGIC_QLE834X:
2176 strncpy(fw_info->fw_file_name, QLC_83XX_FW_FILE_NAME,
2177 QLC_FW_FILE_NAME_LEN);
2179 case PCI_DEVICE_ID_QLOGIC_QLE844X:
2180 strncpy(fw_info->fw_file_name, QLC_84XX_FW_FILE_NAME,
2181 QLC_FW_FILE_NAME_LEN);
2184 dev_err(&pdev->dev, "%s: Invalid device id\n",
2194 static void qlcnic_83xx_init_rings(struct qlcnic_adapter *adapter)
2196 u8 rx_cnt = QLCNIC_DEF_SDS_RINGS;
2197 u8 tx_cnt = QLCNIC_DEF_TX_RINGS;
2199 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
2200 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
2202 if (!adapter->ahw->msix_supported) {
2203 rx_cnt = QLCNIC_SINGLE_RING;
2204 tx_cnt = QLCNIC_SINGLE_RING;
2207 /* compute and set drv sds rings */
2208 qlcnic_set_tx_ring_count(adapter, tx_cnt);
2209 qlcnic_set_sds_ring_count(adapter, rx_cnt);
2212 int qlcnic_83xx_init(struct qlcnic_adapter *adapter, int pci_using_dac)
2214 struct qlcnic_hardware_context *ahw = adapter->ahw;
2217 adapter->rx_mac_learn = 0;
2218 ahw->msix_supported = !!qlcnic_use_msi_x;
2220 qlcnic_83xx_init_rings(adapter);
2222 err = qlcnic_83xx_init_mailbox_work(adapter);
2226 if (qlcnic_sriov_vf_check(adapter)) {
2227 err = qlcnic_sriov_vf_init(adapter, pci_using_dac);
2234 if (qlcnic_83xx_read_flash_descriptor_table(adapter) ||
2235 qlcnic_83xx_read_flash_mfg_id(adapter)) {
2236 dev_err(&adapter->pdev->dev, "Failed reading flash mfg id\n");
2237 err = -ENOTRECOVERABLE;
2241 err = qlcnic_83xx_check_hw_status(adapter);
2245 err = qlcnic_83xx_get_fw_info(adapter);
2249 err = qlcnic_83xx_idc_init(adapter);
2253 err = qlcnic_setup_intr(adapter);
2255 dev_err(&adapter->pdev->dev, "Failed to setup interrupt\n");
2259 err = qlcnic_83xx_setup_mbx_intr(adapter);
2261 goto disable_mbx_intr;
2263 qlcnic_83xx_clear_function_resources(adapter);
2265 INIT_DELAYED_WORK(&adapter->idc_aen_work, qlcnic_83xx_idc_aen_work);
2267 qlcnic_83xx_initialize_nic(adapter, 1);
2269 /* Configure default, SR-IOV or Virtual NIC mode of operation */
2270 err = qlcnic_83xx_configure_opmode(adapter);
2272 goto disable_mbx_intr;
2275 /* Perform operating mode specific initialization */
2276 err = adapter->nic_ops->init_driver(adapter);
2278 goto disable_mbx_intr;
2280 /* Periodically monitor device status */
2281 qlcnic_83xx_idc_poll_dev_state(&adapter->fw_work.work);
2285 qlcnic_83xx_free_mbx_intr(adapter);
2288 qlcnic_teardown_intr(adapter);
2291 qlcnic_83xx_detach_mailbox_work(adapter);
2292 qlcnic_83xx_free_mailbox(ahw->mailbox);
2293 ahw->mailbox = NULL;
2298 void qlcnic_83xx_aer_stop_poll_work(struct qlcnic_adapter *adapter)
2300 struct qlcnic_hardware_context *ahw = adapter->ahw;
2301 struct qlc_83xx_idc *idc = &ahw->idc;
2303 clear_bit(QLC_83XX_MBX_READY, &idc->status);
2304 cancel_delayed_work_sync(&adapter->fw_work);
2306 if (ahw->nic_mode == QLCNIC_VNIC_MODE)
2307 qlcnic_83xx_disable_vnic_mode(adapter, 1);
2309 qlcnic_83xx_idc_detach_driver(adapter);
2310 qlcnic_83xx_initialize_nic(adapter, 0);
2312 cancel_delayed_work_sync(&adapter->idc_aen_work);
2315 int qlcnic_83xx_aer_reset(struct qlcnic_adapter *adapter)
2317 struct qlcnic_hardware_context *ahw = adapter->ahw;
2318 struct qlc_83xx_idc *idc = &ahw->idc;
2322 /* Mark the previous IDC state as NEED_RESET so
2323 * that state_entry() will perform the reattachment
2324 * and bringup the device
2326 idc->prev_state = QLC_83XX_IDC_DEV_NEED_RESET;
2327 owner = qlcnic_83xx_idc_find_reset_owner_id(adapter);
2328 if (ahw->pci_func == owner) {
2329 ret = qlcnic_83xx_restart_hw(adapter);
2332 qlcnic_83xx_idc_clear_registers(adapter, 0);
2335 ret = idc->state_entry(adapter);
2339 void qlcnic_83xx_aer_start_poll_work(struct qlcnic_adapter *adapter)
2341 struct qlcnic_hardware_context *ahw = adapter->ahw;
2342 struct qlc_83xx_idc *idc = &ahw->idc;
2345 idc->prev_state = QLC_83XX_IDC_DEV_READY;
2346 owner = qlcnic_83xx_idc_find_reset_owner_id(adapter);
2347 if (ahw->pci_func == owner)
2348 qlcnic_83xx_idc_enter_ready_state(adapter, 0);
2350 qlcnic_schedule_work(adapter, qlcnic_83xx_idc_poll_dev_state, 0);