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);
403 /* Disable mailbox interrupt */
404 qlcnic_83xx_disable_mbx_intr(adapter);
405 qlcnic_down(adapter, netdev);
406 for (i = 0; i < adapter->ahw->num_msix; i++) {
407 adapter->ahw->intr_tbl[i].id = i;
408 adapter->ahw->intr_tbl[i].enabled = 0;
409 adapter->ahw->intr_tbl[i].src = 0;
412 if (qlcnic_sriov_pf_check(adapter))
413 qlcnic_sriov_pf_reset(adapter);
417 * qlcnic_83xx_idc_attach_driver
419 * @adapter: adapter structure
421 * Re-attach and re-enable net interface
425 static void qlcnic_83xx_idc_attach_driver(struct qlcnic_adapter *adapter)
427 struct net_device *netdev = adapter->netdev;
429 if (netif_running(netdev)) {
430 if (qlcnic_up(adapter, netdev))
432 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
435 netif_device_attach(netdev);
438 static int qlcnic_83xx_idc_enter_failed_state(struct qlcnic_adapter *adapter,
442 if (qlcnic_83xx_lock_driver(adapter))
446 qlcnic_83xx_idc_clear_registers(adapter, 0);
447 QLCWRX(adapter->ahw, QLC_83XX_IDC_DEV_STATE, QLC_83XX_IDC_DEV_FAILED);
449 qlcnic_83xx_unlock_driver(adapter);
451 qlcnic_83xx_idc_log_state_history(adapter);
452 dev_info(&adapter->pdev->dev, "Device will enter failed state\n");
457 static int qlcnic_83xx_idc_enter_init_state(struct qlcnic_adapter *adapter,
461 if (qlcnic_83xx_lock_driver(adapter))
465 QLCWRX(adapter->ahw, QLC_83XX_IDC_DEV_STATE, QLC_83XX_IDC_DEV_INIT);
468 qlcnic_83xx_unlock_driver(adapter);
473 static int qlcnic_83xx_idc_enter_need_quiesce(struct qlcnic_adapter *adapter,
477 if (qlcnic_83xx_lock_driver(adapter))
481 QLCWRX(adapter->ahw, QLC_83XX_IDC_DEV_STATE,
482 QLC_83XX_IDC_DEV_NEED_QUISCENT);
485 qlcnic_83xx_unlock_driver(adapter);
491 qlcnic_83xx_idc_enter_need_reset_state(struct qlcnic_adapter *adapter, int lock)
494 if (qlcnic_83xx_lock_driver(adapter))
498 QLCWRX(adapter->ahw, QLC_83XX_IDC_DEV_STATE,
499 QLC_83XX_IDC_DEV_NEED_RESET);
502 qlcnic_83xx_unlock_driver(adapter);
507 static int qlcnic_83xx_idc_enter_ready_state(struct qlcnic_adapter *adapter,
511 if (qlcnic_83xx_lock_driver(adapter))
515 QLCWRX(adapter->ahw, QLC_83XX_IDC_DEV_STATE, QLC_83XX_IDC_DEV_READY);
517 qlcnic_83xx_unlock_driver(adapter);
523 * qlcnic_83xx_idc_find_reset_owner_id
525 * @adapter: adapter structure
527 * NIC gets precedence over ISCSI and ISCSI has precedence over FCOE.
528 * Within the same class, function with lowest PCI ID assumes ownership
530 * Returns: reset owner id or failure indication (-EIO)
533 static int qlcnic_83xx_idc_find_reset_owner_id(struct qlcnic_adapter *adapter)
535 u32 reg, reg1, reg2, i, j, owner, class;
537 reg1 = QLCRDX(adapter->ahw, QLC_83XX_IDC_DEV_PARTITION_INFO_1);
538 reg2 = QLCRDX(adapter->ahw, QLC_83XX_IDC_DEV_PARTITION_INFO_2);
539 owner = QLCNIC_TYPE_NIC;
545 class = (((reg & (0xF << j * 4)) >> j * 4) & 0x3);
548 if (i == (QLC_83XX_IDC_MAX_FUNC_PER_PARTITION_INFO - 1)) {
555 if (i == (QLC_83XX_IDC_MAX_CNA_FUNCTIONS - 1)) {
556 if (owner == QLCNIC_TYPE_NIC)
557 owner = QLCNIC_TYPE_ISCSI;
558 else if (owner == QLCNIC_TYPE_ISCSI)
559 owner = QLCNIC_TYPE_FCOE;
560 else if (owner == QLCNIC_TYPE_FCOE)
566 } while (i++ < QLC_83XX_IDC_MAX_CNA_FUNCTIONS);
571 static int qlcnic_83xx_idc_restart_hw(struct qlcnic_adapter *adapter, int lock)
575 ret = qlcnic_83xx_restart_hw(adapter);
578 qlcnic_83xx_idc_enter_failed_state(adapter, lock);
580 qlcnic_83xx_idc_clear_registers(adapter, lock);
581 ret = qlcnic_83xx_idc_enter_ready_state(adapter, lock);
587 static int qlcnic_83xx_idc_check_fan_failure(struct qlcnic_adapter *adapter)
591 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
593 if (status & QLCNIC_RCODE_FATAL_ERROR) {
594 dev_err(&adapter->pdev->dev,
595 "peg halt status1=0x%x\n", status);
596 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
597 dev_err(&adapter->pdev->dev,
598 "On board active cooling fan failed. "
599 "Device has been halted.\n");
600 dev_err(&adapter->pdev->dev,
601 "Replace the adapter.\n");
609 static int qlcnic_83xx_idc_reattach_driver(struct qlcnic_adapter *adapter)
613 /* register for NIC IDC AEN Events */
614 qlcnic_83xx_register_nic_idc_func(adapter, 1);
616 err = qlcnic_sriov_pf_reinit(adapter);
620 qlcnic_83xx_enable_mbx_intrpt(adapter);
622 if (qlcnic_83xx_configure_opmode(adapter)) {
623 qlcnic_83xx_idc_enter_failed_state(adapter, 1);
627 if (adapter->nic_ops->init_driver(adapter)) {
628 qlcnic_83xx_idc_enter_failed_state(adapter, 1);
632 qlcnic_83xx_idc_attach_driver(adapter);
637 static void qlcnic_83xx_idc_update_idc_params(struct qlcnic_adapter *adapter)
639 struct qlcnic_hardware_context *ahw = adapter->ahw;
641 qlcnic_83xx_idc_update_drv_presence_reg(adapter, 1, 1);
642 set_bit(QLC_83XX_MBX_READY, &adapter->ahw->idc.status);
643 qlcnic_83xx_idc_update_audit_reg(adapter, 0, 1);
644 set_bit(QLC_83XX_MODULE_LOADED, &adapter->ahw->idc.status);
646 ahw->idc.quiesce_req = 0;
647 ahw->idc.delay = QLC_83XX_IDC_FW_POLL_DELAY;
648 ahw->idc.err_code = 0;
649 ahw->idc.collect_dump = 0;
650 ahw->reset_context = 0;
651 adapter->tx_timeo_cnt = 0;
653 clear_bit(__QLCNIC_RESETTING, &adapter->state);
657 * qlcnic_83xx_idc_ready_state_entry
659 * @adapter: adapter structure
661 * Perform ready state initialization, this routine will get invoked only
662 * once from READY state.
664 * Returns: Error code or Success(0)
667 int qlcnic_83xx_idc_ready_state_entry(struct qlcnic_adapter *adapter)
669 struct qlcnic_hardware_context *ahw = adapter->ahw;
671 if (ahw->idc.prev_state != QLC_83XX_IDC_DEV_READY) {
672 qlcnic_83xx_idc_update_idc_params(adapter);
673 /* Re-attach the device if required */
674 if ((ahw->idc.prev_state == QLC_83XX_IDC_DEV_NEED_RESET) ||
675 (ahw->idc.prev_state == QLC_83XX_IDC_DEV_INIT)) {
676 if (qlcnic_83xx_idc_reattach_driver(adapter))
685 * qlcnic_83xx_idc_vnic_pf_entry
687 * @adapter: adapter structure
689 * Ensure vNIC mode privileged function starts only after vNIC mode is
690 * enabled by management function.
691 * If vNIC mode is ready, start initialization.
696 int qlcnic_83xx_idc_vnic_pf_entry(struct qlcnic_adapter *adapter)
699 struct qlcnic_hardware_context *ahw = adapter->ahw;
701 /* Privileged function waits till mgmt function enables VNIC mode */
702 state = QLCRDX(adapter->ahw, QLC_83XX_VNIC_STATE);
703 if (state != QLCNIC_DEV_NPAR_OPER) {
704 if (!ahw->idc.vnic_wait_limit--) {
705 qlcnic_83xx_idc_enter_failed_state(adapter, 1);
708 dev_info(&adapter->pdev->dev, "vNIC mode disabled\n");
712 /* Perform one time initialization from ready state */
713 if (ahw->idc.vnic_state != QLCNIC_DEV_NPAR_OPER) {
714 qlcnic_83xx_idc_update_idc_params(adapter);
716 /* If the previous state is UNKNOWN, device will be
717 already attached properly by Init routine*/
718 if (ahw->idc.prev_state != QLC_83XX_IDC_DEV_UNKNOWN) {
719 if (qlcnic_83xx_idc_reattach_driver(adapter))
722 adapter->ahw->idc.vnic_state = QLCNIC_DEV_NPAR_OPER;
723 dev_info(&adapter->pdev->dev, "vNIC mode enabled\n");
730 static int qlcnic_83xx_idc_unknown_state(struct qlcnic_adapter *adapter)
732 adapter->ahw->idc.err_code = -EIO;
733 dev_err(&adapter->pdev->dev,
734 "%s: Device in unknown state\n", __func__);
739 * qlcnic_83xx_idc_cold_state
741 * @adapter: adapter structure
743 * If HW is up and running device will enter READY state.
744 * If firmware image from host needs to be loaded, device is
745 * forced to start with the file firmware image.
747 * Returns: Error code or Success(0)
750 static int qlcnic_83xx_idc_cold_state_handler(struct qlcnic_adapter *adapter)
752 qlcnic_83xx_idc_update_drv_presence_reg(adapter, 1, 0);
753 qlcnic_83xx_idc_update_audit_reg(adapter, 1, 0);
755 if (qlcnic_load_fw_file) {
756 qlcnic_83xx_idc_restart_hw(adapter, 0);
758 if (qlcnic_83xx_check_hw_status(adapter)) {
759 qlcnic_83xx_idc_enter_failed_state(adapter, 0);
762 qlcnic_83xx_idc_enter_ready_state(adapter, 0);
769 * qlcnic_83xx_idc_init_state
771 * @adapter: adapter structure
773 * Reset owner will restart the device from this state.
774 * Device will enter failed state if it remains
775 * in this state for more than DEV_INIT time limit.
777 * Returns: Error code or Success(0)
780 static int qlcnic_83xx_idc_init_state(struct qlcnic_adapter *adapter)
782 int timeout, ret = 0;
785 timeout = QLC_83XX_IDC_INIT_TIMEOUT_SECS;
786 if (adapter->ahw->idc.prev_state == QLC_83XX_IDC_DEV_NEED_RESET) {
787 owner = qlcnic_83xx_idc_find_reset_owner_id(adapter);
788 if (adapter->ahw->pci_func == owner)
789 ret = qlcnic_83xx_idc_restart_hw(adapter, 1);
791 ret = qlcnic_83xx_idc_check_timeout(adapter, timeout);
799 * qlcnic_83xx_idc_ready_state
801 * @adapter: adapter structure
803 * Perform IDC protocol specicifed actions after monitoring device state and
806 * Returns: Error code or Success(0)
809 static int qlcnic_83xx_idc_ready_state(struct qlcnic_adapter *adapter)
812 struct qlcnic_hardware_context *ahw = adapter->ahw;
815 /* Perform NIC configuration based ready state entry actions */
816 if (ahw->idc.state_entry(adapter))
819 if (qlcnic_check_temp(adapter)) {
820 if (ahw->temp == QLCNIC_TEMP_PANIC) {
821 qlcnic_83xx_idc_check_fan_failure(adapter);
822 dev_err(&adapter->pdev->dev,
823 "Error: device temperature %d above limits\n",
825 clear_bit(QLC_83XX_MBX_READY, &ahw->idc.status);
826 set_bit(__QLCNIC_RESETTING, &adapter->state);
827 qlcnic_83xx_idc_detach_driver(adapter);
828 qlcnic_83xx_idc_enter_failed_state(adapter, 1);
833 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
834 ret = qlcnic_83xx_check_heartbeat(adapter);
836 adapter->flags |= QLCNIC_FW_HANG;
837 if (!(val & QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY)) {
838 clear_bit(QLC_83XX_MBX_READY, &ahw->idc.status);
839 set_bit(__QLCNIC_RESETTING, &adapter->state);
840 qlcnic_83xx_idc_enter_need_reset_state(adapter, 1);
845 if ((val & QLC_83XX_IDC_GRACEFULL_RESET) || ahw->idc.collect_dump) {
846 /* Move to need reset state and prepare for reset */
847 qlcnic_83xx_idc_enter_need_reset_state(adapter, 1);
851 /* Check for soft reset request */
852 if (ahw->reset_context &&
853 !(val & QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY)) {
854 adapter->ahw->reset_context = 0;
855 qlcnic_83xx_idc_tx_soft_reset(adapter);
859 /* Move to need quiesce state if requested */
860 if (adapter->ahw->idc.quiesce_req) {
861 qlcnic_83xx_idc_enter_need_quiesce(adapter, 1);
862 qlcnic_83xx_idc_update_audit_reg(adapter, 0, 1);
870 * qlcnic_83xx_idc_need_reset_state
872 * @adapter: adapter structure
874 * Device will remain in this state until:
875 * Reset request ACK's are recieved from all the functions
876 * Wait time exceeds max time limit
878 * Returns: Error code or Success(0)
881 static int qlcnic_83xx_idc_need_reset_state(struct qlcnic_adapter *adapter)
885 if (adapter->ahw->idc.prev_state != QLC_83XX_IDC_DEV_NEED_RESET) {
886 qlcnic_83xx_idc_update_drv_ack_reg(adapter, 1, 1);
887 qlcnic_83xx_idc_update_audit_reg(adapter, 0, 1);
888 set_bit(__QLCNIC_RESETTING, &adapter->state);
889 clear_bit(QLC_83XX_MBX_READY, &adapter->ahw->idc.status);
890 if (adapter->ahw->nic_mode == QLC_83XX_VIRTUAL_NIC_MODE)
891 qlcnic_83xx_disable_vnic_mode(adapter, 1);
892 qlcnic_83xx_idc_detach_driver(adapter);
895 /* Check ACK from other functions */
896 ret = qlcnic_83xx_idc_check_reset_ack_reg(adapter);
898 dev_info(&adapter->pdev->dev,
899 "%s: Waiting for reset ACK\n", __func__);
903 /* Transit to INIT state and restart the HW */
904 qlcnic_83xx_idc_enter_init_state(adapter, 1);
909 static int qlcnic_83xx_idc_need_quiesce_state(struct qlcnic_adapter *adapter)
911 dev_err(&adapter->pdev->dev, "%s: TBD\n", __func__);
915 static int qlcnic_83xx_idc_failed_state(struct qlcnic_adapter *adapter)
917 dev_err(&adapter->pdev->dev, "%s: please restart!!\n", __func__);
918 clear_bit(__QLCNIC_RESETTING, &adapter->state);
919 adapter->ahw->idc.err_code = -EIO;
924 static int qlcnic_83xx_idc_quiesce_state(struct qlcnic_adapter *adapter)
926 dev_info(&adapter->pdev->dev, "%s: TBD\n", __func__);
930 static int qlcnic_83xx_idc_check_state_validity(struct qlcnic_adapter *adapter,
935 cur = adapter->ahw->idc.curr_state;
936 prev = adapter->ahw->idc.prev_state;
939 if ((next < QLC_83XX_IDC_DEV_COLD) ||
940 (next > QLC_83XX_IDC_DEV_QUISCENT)) {
941 dev_err(&adapter->pdev->dev,
942 "%s: curr %d, prev %d, next state %d is invalid\n",
943 __func__, cur, prev, state);
947 if ((cur == QLC_83XX_IDC_DEV_UNKNOWN) &&
948 (prev == QLC_83XX_IDC_DEV_UNKNOWN)) {
949 if ((next != QLC_83XX_IDC_DEV_COLD) &&
950 (next != QLC_83XX_IDC_DEV_READY)) {
951 dev_err(&adapter->pdev->dev,
952 "%s: failed, cur %d prev %d next %d\n",
953 __func__, cur, prev, next);
958 if (next == QLC_83XX_IDC_DEV_INIT) {
959 if ((prev != QLC_83XX_IDC_DEV_INIT) &&
960 (prev != QLC_83XX_IDC_DEV_COLD) &&
961 (prev != QLC_83XX_IDC_DEV_NEED_RESET)) {
962 dev_err(&adapter->pdev->dev,
963 "%s: failed, cur %d prev %d next %d\n",
964 __func__, cur, prev, next);
972 static void qlcnic_83xx_periodic_tasks(struct qlcnic_adapter *adapter)
974 if (adapter->fhash.fnum)
975 qlcnic_prune_lb_filters(adapter);
979 * qlcnic_83xx_idc_poll_dev_state
981 * @work: kernel work queue structure used to schedule the function
983 * Poll device state periodically and perform state specific
984 * actions defined by Inter Driver Communication (IDC) protocol.
989 void qlcnic_83xx_idc_poll_dev_state(struct work_struct *work)
991 struct qlcnic_adapter *adapter;
994 adapter = container_of(work, struct qlcnic_adapter, fw_work.work);
995 state = QLCRDX(adapter->ahw, QLC_83XX_IDC_DEV_STATE);
997 if (qlcnic_83xx_idc_check_state_validity(adapter, state)) {
998 qlcnic_83xx_idc_log_state_history(adapter);
999 adapter->ahw->idc.curr_state = QLC_83XX_IDC_DEV_UNKNOWN;
1001 adapter->ahw->idc.curr_state = state;
1004 switch (adapter->ahw->idc.curr_state) {
1005 case QLC_83XX_IDC_DEV_READY:
1006 qlcnic_83xx_idc_ready_state(adapter);
1008 case QLC_83XX_IDC_DEV_NEED_RESET:
1009 qlcnic_83xx_idc_need_reset_state(adapter);
1011 case QLC_83XX_IDC_DEV_NEED_QUISCENT:
1012 qlcnic_83xx_idc_need_quiesce_state(adapter);
1014 case QLC_83XX_IDC_DEV_FAILED:
1015 qlcnic_83xx_idc_failed_state(adapter);
1017 case QLC_83XX_IDC_DEV_INIT:
1018 qlcnic_83xx_idc_init_state(adapter);
1020 case QLC_83XX_IDC_DEV_QUISCENT:
1021 qlcnic_83xx_idc_quiesce_state(adapter);
1024 qlcnic_83xx_idc_unknown_state(adapter);
1027 adapter->ahw->idc.prev_state = adapter->ahw->idc.curr_state;
1028 qlcnic_83xx_periodic_tasks(adapter);
1030 /* Re-schedule the function */
1031 if (test_bit(QLC_83XX_MODULE_LOADED, &adapter->ahw->idc.status))
1032 qlcnic_schedule_work(adapter, qlcnic_83xx_idc_poll_dev_state,
1033 adapter->ahw->idc.delay);
1036 static void qlcnic_83xx_setup_idc_parameters(struct qlcnic_adapter *adapter)
1038 u32 idc_params, val;
1040 if (qlcnic_83xx_lockless_flash_read32(adapter,
1041 QLC_83XX_IDC_FLASH_PARAM_ADDR,
1042 (u8 *)&idc_params, 1)) {
1043 dev_info(&adapter->pdev->dev,
1044 "%s:failed to get IDC params from flash\n", __func__);
1045 adapter->dev_init_timeo = QLC_83XX_IDC_INIT_TIMEOUT_SECS;
1046 adapter->reset_ack_timeo = QLC_83XX_IDC_RESET_TIMEOUT_SECS;
1048 adapter->dev_init_timeo = idc_params & 0xFFFF;
1049 adapter->reset_ack_timeo = ((idc_params >> 16) & 0xFFFF);
1052 adapter->ahw->idc.curr_state = QLC_83XX_IDC_DEV_UNKNOWN;
1053 adapter->ahw->idc.prev_state = QLC_83XX_IDC_DEV_UNKNOWN;
1054 adapter->ahw->idc.delay = QLC_83XX_IDC_FW_POLL_DELAY;
1055 adapter->ahw->idc.err_code = 0;
1056 adapter->ahw->idc.collect_dump = 0;
1057 adapter->ahw->idc.name = (char **)qlc_83xx_idc_states;
1059 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1060 set_bit(QLC_83XX_MBX_READY, &adapter->ahw->idc.status);
1061 set_bit(QLC_83XX_MODULE_LOADED, &adapter->ahw->idc.status);
1063 /* Check if reset recovery is disabled */
1064 if (!qlcnic_auto_fw_reset) {
1065 /* Propagate do not reset request to other functions */
1066 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1067 val = val | QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY;
1068 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
1073 qlcnic_83xx_idc_first_to_load_function_handler(struct qlcnic_adapter *adapter)
1077 if (qlcnic_83xx_lock_driver(adapter))
1080 /* Clear driver lock register */
1081 QLCWRX(adapter->ahw, QLC_83XX_RECOVER_DRV_LOCK, 0);
1082 if (qlcnic_83xx_idc_update_major_version(adapter, 0)) {
1083 qlcnic_83xx_unlock_driver(adapter);
1087 state = QLCRDX(adapter->ahw, QLC_83XX_IDC_DEV_STATE);
1088 if (qlcnic_83xx_idc_check_state_validity(adapter, state)) {
1089 qlcnic_83xx_unlock_driver(adapter);
1093 if (state != QLC_83XX_IDC_DEV_COLD && qlcnic_load_fw_file) {
1094 QLCWRX(adapter->ahw, QLC_83XX_IDC_DEV_STATE,
1095 QLC_83XX_IDC_DEV_COLD);
1096 state = QLC_83XX_IDC_DEV_COLD;
1099 adapter->ahw->idc.curr_state = state;
1100 /* First to load function should cold boot the device */
1101 if (state == QLC_83XX_IDC_DEV_COLD)
1102 qlcnic_83xx_idc_cold_state_handler(adapter);
1104 /* Check if reset recovery is enabled */
1105 if (qlcnic_auto_fw_reset) {
1106 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1107 val = val & ~QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY;
1108 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
1111 qlcnic_83xx_unlock_driver(adapter);
1116 static int qlcnic_83xx_idc_init(struct qlcnic_adapter *adapter)
1120 qlcnic_83xx_setup_idc_parameters(adapter);
1122 if (qlcnic_83xx_get_reset_instruction_template(adapter))
1125 if (!qlcnic_83xx_idc_check_driver_presence_reg(adapter)) {
1126 if (qlcnic_83xx_idc_first_to_load_function_handler(adapter))
1129 if (qlcnic_83xx_idc_check_major_version(adapter))
1133 qlcnic_83xx_idc_update_audit_reg(adapter, 0, 1);
1138 void qlcnic_83xx_idc_exit(struct qlcnic_adapter *adapter)
1143 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1144 usleep_range(10000, 11000);
1146 id = QLCRDX(adapter->ahw, QLC_83XX_DRV_LOCK_ID);
1149 if (id == adapter->portnum) {
1150 dev_err(&adapter->pdev->dev,
1151 "%s: wait for lock recovery.. %d\n", __func__, id);
1153 id = QLCRDX(adapter->ahw, QLC_83XX_DRV_LOCK_ID);
1157 /* Clear driver presence bit */
1158 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE);
1159 val = val & ~(1 << adapter->portnum);
1160 QLCWRX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE, val);
1161 clear_bit(QLC_83XX_MODULE_LOADED, &adapter->ahw->idc.status);
1162 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1164 cancel_delayed_work_sync(&adapter->fw_work);
1167 void qlcnic_83xx_idc_request_reset(struct qlcnic_adapter *adapter, u32 key)
1171 if (qlcnic_83xx_lock_driver(adapter)) {
1172 dev_err(&adapter->pdev->dev,
1173 "%s:failed, please retry\n", __func__);
1177 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1178 if ((val & QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY) ||
1179 !qlcnic_auto_fw_reset) {
1180 dev_err(&adapter->pdev->dev,
1181 "%s:failed, device in non reset mode\n", __func__);
1182 qlcnic_83xx_unlock_driver(adapter);
1186 if (key == QLCNIC_FORCE_FW_RESET) {
1187 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1188 val = val | QLC_83XX_IDC_GRACEFULL_RESET;
1189 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
1190 } else if (key == QLCNIC_FORCE_FW_DUMP_KEY) {
1191 adapter->ahw->idc.collect_dump = 1;
1194 qlcnic_83xx_unlock_driver(adapter);
1198 static int qlcnic_83xx_copy_bootloader(struct qlcnic_adapter *adapter)
1205 src = QLC_83XX_BOOTLOADER_FLASH_ADDR;
1206 dest = QLCRDX(adapter->ahw, QLCNIC_BOOTLOADER_ADDR);
1207 size = QLCRDX(adapter->ahw, QLCNIC_BOOTLOADER_SIZE);
1209 /* alignment check */
1211 size = (size + 16) & ~0xF;
1213 p_cache = kzalloc(size, GFP_KERNEL);
1214 if (p_cache == NULL)
1217 ret = qlcnic_83xx_lockless_flash_read32(adapter, src, p_cache,
1218 size / sizeof(u32));
1223 /* 16 byte write to MS memory */
1224 ret = qlcnic_83xx_ms_mem_write128(adapter, dest, (u32 *)p_cache,
1235 static int qlcnic_83xx_copy_fw_file(struct qlcnic_adapter *adapter)
1243 dest = QLCRDX(adapter->ahw, QLCNIC_FW_IMAGE_ADDR);
1244 size = (adapter->ahw->fw_info.fw->size & ~0xF);
1245 p_cache = (u32 *)adapter->ahw->fw_info.fw->data;
1248 ret = qlcnic_83xx_ms_mem_write128(adapter, addr,
1249 (u32 *)p_cache, size / 16);
1251 dev_err(&adapter->pdev->dev, "MS memory write failed\n");
1252 release_firmware(adapter->ahw->fw_info.fw);
1253 adapter->ahw->fw_info.fw = NULL;
1257 /* alignment check */
1258 if (adapter->ahw->fw_info.fw->size & 0xF) {
1260 for (i = 0; i < (adapter->ahw->fw_info.fw->size & 0xF); i++)
1261 data[i] = adapter->ahw->fw_info.fw->data[size + i];
1264 ret = qlcnic_83xx_ms_mem_write128(adapter, addr,
1267 dev_err(&adapter->pdev->dev,
1268 "MS memory write failed\n");
1269 release_firmware(adapter->ahw->fw_info.fw);
1270 adapter->ahw->fw_info.fw = NULL;
1274 release_firmware(adapter->ahw->fw_info.fw);
1275 adapter->ahw->fw_info.fw = NULL;
1280 static void qlcnic_83xx_dump_pause_control_regs(struct qlcnic_adapter *adapter)
1283 u32 val = 0, val1 = 0, reg = 0;
1285 val = QLCRD32(adapter, QLC_83XX_SRE_SHIM_REG);
1286 dev_info(&adapter->pdev->dev, "SRE-Shim Ctrl:0x%x\n", val);
1288 for (j = 0; j < 2; j++) {
1290 dev_info(&adapter->pdev->dev,
1291 "Port 0 RxB Pause Threshold Regs[TC7..TC0]:");
1292 reg = QLC_83XX_PORT0_THRESHOLD;
1293 } else if (j == 1) {
1294 dev_info(&adapter->pdev->dev,
1295 "Port 1 RxB Pause Threshold Regs[TC7..TC0]:");
1296 reg = QLC_83XX_PORT1_THRESHOLD;
1298 for (i = 0; i < 8; i++) {
1299 val = QLCRD32(adapter, reg + (i * 0x4));
1300 dev_info(&adapter->pdev->dev, "0x%x ", val);
1302 dev_info(&adapter->pdev->dev, "\n");
1305 for (j = 0; j < 2; j++) {
1307 dev_info(&adapter->pdev->dev,
1308 "Port 0 RxB TC Max Cell Registers[4..1]:");
1309 reg = QLC_83XX_PORT0_TC_MC_REG;
1310 } else if (j == 1) {
1311 dev_info(&adapter->pdev->dev,
1312 "Port 1 RxB TC Max Cell Registers[4..1]:");
1313 reg = QLC_83XX_PORT1_TC_MC_REG;
1315 for (i = 0; i < 4; i++) {
1316 val = QLCRD32(adapter, reg + (i * 0x4));
1317 dev_info(&adapter->pdev->dev, "0x%x ", val);
1319 dev_info(&adapter->pdev->dev, "\n");
1322 for (j = 0; j < 2; j++) {
1324 dev_info(&adapter->pdev->dev,
1325 "Port 0 RxB Rx TC Stats[TC7..TC0]:");
1326 reg = QLC_83XX_PORT0_TC_STATS;
1327 } else if (j == 1) {
1328 dev_info(&adapter->pdev->dev,
1329 "Port 1 RxB Rx TC Stats[TC7..TC0]:");
1330 reg = QLC_83XX_PORT1_TC_STATS;
1332 for (i = 7; i >= 0; i--) {
1333 val = QLCRD32(adapter, reg);
1334 val &= ~(0x7 << 29); /* Reset bits 29 to 31 */
1335 QLCWR32(adapter, reg, (val | (i << 29)));
1336 val = QLCRD32(adapter, reg);
1337 dev_info(&adapter->pdev->dev, "0x%x ", val);
1339 dev_info(&adapter->pdev->dev, "\n");
1342 val = QLCRD32(adapter, QLC_83XX_PORT2_IFB_THRESHOLD);
1343 val1 = QLCRD32(adapter, QLC_83XX_PORT3_IFB_THRESHOLD);
1344 dev_info(&adapter->pdev->dev,
1345 "IFB-Pause Thresholds: Port 2:0x%x, Port 3:0x%x\n",
1350 static void qlcnic_83xx_disable_pause_frames(struct qlcnic_adapter *adapter)
1354 if (qlcnic_83xx_lock_driver(adapter)) {
1355 dev_err(&adapter->pdev->dev,
1356 "%s:failed to acquire driver lock\n", __func__);
1360 qlcnic_83xx_dump_pause_control_regs(adapter);
1361 QLCWR32(adapter, QLC_83XX_SRE_SHIM_REG, 0x0);
1363 for (j = 0; j < 2; j++) {
1365 reg = QLC_83XX_PORT0_THRESHOLD;
1367 reg = QLC_83XX_PORT1_THRESHOLD;
1369 for (i = 0; i < 8; i++)
1370 QLCWR32(adapter, reg + (i * 0x4), 0x0);
1373 for (j = 0; j < 2; j++) {
1375 reg = QLC_83XX_PORT0_TC_MC_REG;
1377 reg = QLC_83XX_PORT1_TC_MC_REG;
1379 for (i = 0; i < 4; i++)
1380 QLCWR32(adapter, reg + (i * 0x4), 0x03FF03FF);
1383 QLCWR32(adapter, QLC_83XX_PORT2_IFB_THRESHOLD, 0);
1384 QLCWR32(adapter, QLC_83XX_PORT3_IFB_THRESHOLD, 0);
1385 dev_info(&adapter->pdev->dev,
1386 "Disabled pause frames successfully on all ports\n");
1387 qlcnic_83xx_unlock_driver(adapter);
1390 static void qlcnic_83xx_take_eport_out_of_reset(struct qlcnic_adapter *adapter)
1392 QLCWR32(adapter, QLC_83XX_RESET_REG, 0);
1393 QLCWR32(adapter, QLC_83XX_RESET_PORT0, 0);
1394 QLCWR32(adapter, QLC_83XX_RESET_PORT1, 0);
1395 QLCWR32(adapter, QLC_83XX_RESET_PORT2, 0);
1396 QLCWR32(adapter, QLC_83XX_RESET_PORT3, 0);
1397 QLCWR32(adapter, QLC_83XX_RESET_SRESHIM, 0);
1398 QLCWR32(adapter, QLC_83XX_RESET_EPGSHIM, 0);
1399 QLCWR32(adapter, QLC_83XX_RESET_ETHERPCS, 0);
1400 QLCWR32(adapter, QLC_83XX_RESET_CONTROL, 1);
1403 static int qlcnic_83xx_check_heartbeat(struct qlcnic_adapter *p_dev)
1405 u32 heartbeat, peg_status;
1406 int retries, ret = -EIO;
1408 retries = QLCNIC_HEARTBEAT_CHECK_RETRY_COUNT;
1409 p_dev->heartbeat = QLC_SHARED_REG_RD32(p_dev,
1410 QLCNIC_PEG_ALIVE_COUNTER);
1413 msleep(QLCNIC_HEARTBEAT_PERIOD_MSECS);
1414 heartbeat = QLC_SHARED_REG_RD32(p_dev,
1415 QLCNIC_PEG_ALIVE_COUNTER);
1416 if (heartbeat != p_dev->heartbeat) {
1417 ret = QLCNIC_RCODE_SUCCESS;
1420 } while (--retries);
1423 dev_err(&p_dev->pdev->dev, "firmware hang detected\n");
1424 qlcnic_83xx_take_eport_out_of_reset(p_dev);
1425 qlcnic_83xx_disable_pause_frames(p_dev);
1426 peg_status = QLC_SHARED_REG_RD32(p_dev,
1427 QLCNIC_PEG_HALT_STATUS1);
1428 dev_info(&p_dev->pdev->dev, "Dumping HW/FW registers\n"
1429 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
1430 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
1431 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
1432 "PEG_NET_4_PC: 0x%x\n", peg_status,
1433 QLC_SHARED_REG_RD32(p_dev, QLCNIC_PEG_HALT_STATUS2),
1434 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_0),
1435 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_1),
1436 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_2),
1437 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_3),
1438 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_4));
1440 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
1441 dev_err(&p_dev->pdev->dev,
1442 "Device is being reset err code 0x00006700.\n");
1448 static int qlcnic_83xx_check_cmd_peg_status(struct qlcnic_adapter *p_dev)
1450 int retries = QLCNIC_CMDPEG_CHECK_RETRY_COUNT;
1454 val = QLC_SHARED_REG_RD32(p_dev, QLCNIC_CMDPEG_STATE);
1455 if (val == QLC_83XX_CMDPEG_COMPLETE)
1457 msleep(QLCNIC_CMDPEG_CHECK_DELAY);
1458 } while (--retries);
1460 dev_err(&p_dev->pdev->dev, "%s: failed, state = 0x%x\n", __func__, val);
1464 int qlcnic_83xx_check_hw_status(struct qlcnic_adapter *p_dev)
1468 err = qlcnic_83xx_check_cmd_peg_status(p_dev);
1472 err = qlcnic_83xx_check_heartbeat(p_dev);
1479 static int qlcnic_83xx_poll_reg(struct qlcnic_adapter *p_dev, u32 addr,
1480 int duration, u32 mask, u32 status)
1486 value = qlcnic_83xx_rd_reg_indirect(p_dev, addr);
1487 retries = duration / 10;
1490 if ((value & mask) != status) {
1492 msleep(duration / 10);
1493 value = qlcnic_83xx_rd_reg_indirect(p_dev, addr);
1498 } while (retries--);
1500 if (timeout_error) {
1501 p_dev->ahw->reset.seq_error++;
1502 dev_err(&p_dev->pdev->dev,
1503 "%s: Timeout Err, entry_num = %d\n",
1504 __func__, p_dev->ahw->reset.seq_index);
1505 dev_err(&p_dev->pdev->dev,
1506 "0x%08x 0x%08x 0x%08x\n",
1507 value, mask, status);
1510 return timeout_error;
1513 static int qlcnic_83xx_reset_template_checksum(struct qlcnic_adapter *p_dev)
1516 u16 *buff = (u16 *)p_dev->ahw->reset.buff;
1517 int count = p_dev->ahw->reset.hdr->size / sizeof(u16);
1523 sum = (sum & 0xFFFF) + (sum >> 16);
1528 dev_err(&p_dev->pdev->dev, "%s: failed\n", __func__);
1533 int qlcnic_83xx_get_reset_instruction_template(struct qlcnic_adapter *p_dev)
1537 struct qlcnic_hardware_context *ahw = p_dev->ahw;
1539 ahw->reset.seq_error = 0;
1540 ahw->reset.buff = kzalloc(QLC_83XX_RESTART_TEMPLATE_SIZE, GFP_KERNEL);
1541 if (p_dev->ahw->reset.buff == NULL)
1544 p_buff = p_dev->ahw->reset.buff;
1545 addr = QLC_83XX_RESET_TEMPLATE_ADDR;
1546 count = sizeof(struct qlc_83xx_reset_hdr) / sizeof(u32);
1548 /* Copy template header from flash */
1549 if (qlcnic_83xx_flash_read32(p_dev, addr, p_buff, count)) {
1550 dev_err(&p_dev->pdev->dev, "%s: flash read failed\n", __func__);
1553 ahw->reset.hdr = (struct qlc_83xx_reset_hdr *)ahw->reset.buff;
1554 addr = QLC_83XX_RESET_TEMPLATE_ADDR + ahw->reset.hdr->hdr_size;
1555 p_buff = ahw->reset.buff + ahw->reset.hdr->hdr_size;
1556 count = (ahw->reset.hdr->size - ahw->reset.hdr->hdr_size) / sizeof(u32);
1558 /* Copy rest of the template */
1559 if (qlcnic_83xx_flash_read32(p_dev, addr, p_buff, count)) {
1560 dev_err(&p_dev->pdev->dev, "%s: flash read failed\n", __func__);
1564 if (qlcnic_83xx_reset_template_checksum(p_dev))
1566 /* Get Stop, Start and Init command offsets */
1567 ahw->reset.init_offset = ahw->reset.buff + ahw->reset.hdr->init_offset;
1568 ahw->reset.start_offset = ahw->reset.buff +
1569 ahw->reset.hdr->start_offset;
1570 ahw->reset.stop_offset = ahw->reset.buff + ahw->reset.hdr->hdr_size;
1574 /* Read Write HW register command */
1575 static void qlcnic_83xx_read_write_crb_reg(struct qlcnic_adapter *p_dev,
1576 u32 raddr, u32 waddr)
1580 value = qlcnic_83xx_rd_reg_indirect(p_dev, raddr);
1581 qlcnic_83xx_wrt_reg_indirect(p_dev, waddr, value);
1584 /* Read Modify Write HW register command */
1585 static void qlcnic_83xx_rmw_crb_reg(struct qlcnic_adapter *p_dev,
1586 u32 raddr, u32 waddr,
1587 struct qlc_83xx_rmw *p_rmw_hdr)
1591 if (p_rmw_hdr->index_a)
1592 value = p_dev->ahw->reset.array[p_rmw_hdr->index_a];
1594 value = qlcnic_83xx_rd_reg_indirect(p_dev, raddr);
1596 value &= p_rmw_hdr->mask;
1597 value <<= p_rmw_hdr->shl;
1598 value >>= p_rmw_hdr->shr;
1599 value |= p_rmw_hdr->or_value;
1600 value ^= p_rmw_hdr->xor_value;
1601 qlcnic_83xx_wrt_reg_indirect(p_dev, waddr, value);
1604 /* Write HW register command */
1605 static void qlcnic_83xx_write_list(struct qlcnic_adapter *p_dev,
1606 struct qlc_83xx_entry_hdr *p_hdr)
1609 struct qlc_83xx_entry *entry;
1611 entry = (struct qlc_83xx_entry *)((char *)p_hdr +
1612 sizeof(struct qlc_83xx_entry_hdr));
1614 for (i = 0; i < p_hdr->count; i++, entry++) {
1615 qlcnic_83xx_wrt_reg_indirect(p_dev, entry->arg1,
1618 udelay((u32)(p_hdr->delay));
1622 /* Read and Write instruction */
1623 static void qlcnic_83xx_read_write_list(struct qlcnic_adapter *p_dev,
1624 struct qlc_83xx_entry_hdr *p_hdr)
1627 struct qlc_83xx_entry *entry;
1629 entry = (struct qlc_83xx_entry *)((char *)p_hdr +
1630 sizeof(struct qlc_83xx_entry_hdr));
1632 for (i = 0; i < p_hdr->count; i++, entry++) {
1633 qlcnic_83xx_read_write_crb_reg(p_dev, entry->arg1,
1636 udelay((u32)(p_hdr->delay));
1640 /* Poll HW register command */
1641 static void qlcnic_83xx_poll_list(struct qlcnic_adapter *p_dev,
1642 struct qlc_83xx_entry_hdr *p_hdr)
1645 struct qlc_83xx_entry *entry;
1646 struct qlc_83xx_poll *poll;
1648 unsigned long arg1, arg2;
1650 poll = (struct qlc_83xx_poll *)((char *)p_hdr +
1651 sizeof(struct qlc_83xx_entry_hdr));
1653 entry = (struct qlc_83xx_entry *)((char *)poll +
1654 sizeof(struct qlc_83xx_poll));
1655 delay = (long)p_hdr->delay;
1658 for (i = 0; i < p_hdr->count; i++, entry++)
1659 qlcnic_83xx_poll_reg(p_dev, entry->arg1,
1663 for (i = 0; i < p_hdr->count; i++, entry++) {
1667 if (qlcnic_83xx_poll_reg(p_dev,
1671 qlcnic_83xx_rd_reg_indirect(p_dev,
1673 qlcnic_83xx_rd_reg_indirect(p_dev,
1681 /* Poll and write HW register command */
1682 static void qlcnic_83xx_poll_write_list(struct qlcnic_adapter *p_dev,
1683 struct qlc_83xx_entry_hdr *p_hdr)
1687 struct qlc_83xx_quad_entry *entry;
1688 struct qlc_83xx_poll *poll;
1690 poll = (struct qlc_83xx_poll *)((char *)p_hdr +
1691 sizeof(struct qlc_83xx_entry_hdr));
1692 entry = (struct qlc_83xx_quad_entry *)((char *)poll +
1693 sizeof(struct qlc_83xx_poll));
1694 delay = (long)p_hdr->delay;
1696 for (i = 0; i < p_hdr->count; i++, entry++) {
1697 qlcnic_83xx_wrt_reg_indirect(p_dev, entry->dr_addr,
1699 qlcnic_83xx_wrt_reg_indirect(p_dev, entry->ar_addr,
1702 qlcnic_83xx_poll_reg(p_dev, entry->ar_addr, delay,
1703 poll->mask, poll->status);
1707 /* Read Modify Write register command */
1708 static void qlcnic_83xx_read_modify_write(struct qlcnic_adapter *p_dev,
1709 struct qlc_83xx_entry_hdr *p_hdr)
1712 struct qlc_83xx_entry *entry;
1713 struct qlc_83xx_rmw *rmw_hdr;
1715 rmw_hdr = (struct qlc_83xx_rmw *)((char *)p_hdr +
1716 sizeof(struct qlc_83xx_entry_hdr));
1718 entry = (struct qlc_83xx_entry *)((char *)rmw_hdr +
1719 sizeof(struct qlc_83xx_rmw));
1721 for (i = 0; i < p_hdr->count; i++, entry++) {
1722 qlcnic_83xx_rmw_crb_reg(p_dev, entry->arg1,
1723 entry->arg2, rmw_hdr);
1725 udelay((u32)(p_hdr->delay));
1729 static void qlcnic_83xx_pause(struct qlc_83xx_entry_hdr *p_hdr)
1732 mdelay((u32)((long)p_hdr->delay));
1735 /* Read and poll register command */
1736 static void qlcnic_83xx_poll_read_list(struct qlcnic_adapter *p_dev,
1737 struct qlc_83xx_entry_hdr *p_hdr)
1741 struct qlc_83xx_quad_entry *entry;
1742 struct qlc_83xx_poll *poll;
1745 poll = (struct qlc_83xx_poll *)((char *)p_hdr +
1746 sizeof(struct qlc_83xx_entry_hdr));
1748 entry = (struct qlc_83xx_quad_entry *)((char *)poll +
1749 sizeof(struct qlc_83xx_poll));
1750 delay = (long)p_hdr->delay;
1752 for (i = 0; i < p_hdr->count; i++, entry++) {
1753 qlcnic_83xx_wrt_reg_indirect(p_dev, entry->ar_addr,
1756 if (!qlcnic_83xx_poll_reg(p_dev, entry->ar_addr, delay,
1757 poll->mask, poll->status)){
1758 index = p_dev->ahw->reset.array_index;
1759 addr = entry->dr_addr;
1760 j = qlcnic_83xx_rd_reg_indirect(p_dev, addr);
1761 p_dev->ahw->reset.array[index++] = j;
1763 if (index == QLC_83XX_MAX_RESET_SEQ_ENTRIES)
1764 p_dev->ahw->reset.array_index = 1;
1770 static inline void qlcnic_83xx_seq_end(struct qlcnic_adapter *p_dev)
1772 p_dev->ahw->reset.seq_end = 1;
1775 static void qlcnic_83xx_template_end(struct qlcnic_adapter *p_dev)
1777 p_dev->ahw->reset.template_end = 1;
1778 if (p_dev->ahw->reset.seq_error == 0)
1779 dev_err(&p_dev->pdev->dev,
1780 "HW restart process completed successfully.\n");
1782 dev_err(&p_dev->pdev->dev,
1783 "HW restart completed with timeout errors.\n");
1787 * qlcnic_83xx_exec_template_cmd
1789 * @p_dev: adapter structure
1790 * @p_buff: Poiter to instruction template
1792 * Template provides instructions to stop, restart and initalize firmware.
1793 * These instructions are abstracted as a series of read, write and
1794 * poll operations on hardware registers. Register information and operation
1795 * specifics are not exposed to the driver. Driver reads the template from
1796 * flash and executes the instructions located at pre-defined offsets.
1800 static void qlcnic_83xx_exec_template_cmd(struct qlcnic_adapter *p_dev,
1804 struct qlc_83xx_entry_hdr *p_hdr;
1805 char *entry = p_buff;
1807 p_dev->ahw->reset.seq_end = 0;
1808 p_dev->ahw->reset.template_end = 0;
1809 entries = p_dev->ahw->reset.hdr->entries;
1810 index = p_dev->ahw->reset.seq_index;
1812 for (; (!p_dev->ahw->reset.seq_end) && (index < entries); index++) {
1813 p_hdr = (struct qlc_83xx_entry_hdr *)entry;
1815 switch (p_hdr->cmd) {
1816 case QLC_83XX_OPCODE_NOP:
1818 case QLC_83XX_OPCODE_WRITE_LIST:
1819 qlcnic_83xx_write_list(p_dev, p_hdr);
1821 case QLC_83XX_OPCODE_READ_WRITE_LIST:
1822 qlcnic_83xx_read_write_list(p_dev, p_hdr);
1824 case QLC_83XX_OPCODE_POLL_LIST:
1825 qlcnic_83xx_poll_list(p_dev, p_hdr);
1827 case QLC_83XX_OPCODE_POLL_WRITE_LIST:
1828 qlcnic_83xx_poll_write_list(p_dev, p_hdr);
1830 case QLC_83XX_OPCODE_READ_MODIFY_WRITE:
1831 qlcnic_83xx_read_modify_write(p_dev, p_hdr);
1833 case QLC_83XX_OPCODE_SEQ_PAUSE:
1834 qlcnic_83xx_pause(p_hdr);
1836 case QLC_83XX_OPCODE_SEQ_END:
1837 qlcnic_83xx_seq_end(p_dev);
1839 case QLC_83XX_OPCODE_TMPL_END:
1840 qlcnic_83xx_template_end(p_dev);
1842 case QLC_83XX_OPCODE_POLL_READ_LIST:
1843 qlcnic_83xx_poll_read_list(p_dev, p_hdr);
1846 dev_err(&p_dev->pdev->dev,
1847 "%s: Unknown opcode 0x%04x in template %d\n",
1848 __func__, p_hdr->cmd, index);
1851 entry += p_hdr->size;
1853 p_dev->ahw->reset.seq_index = index;
1856 static void qlcnic_83xx_stop_hw(struct qlcnic_adapter *p_dev)
1858 p_dev->ahw->reset.seq_index = 0;
1860 qlcnic_83xx_exec_template_cmd(p_dev, p_dev->ahw->reset.stop_offset);
1861 if (p_dev->ahw->reset.seq_end != 1)
1862 dev_err(&p_dev->pdev->dev, "%s: failed\n", __func__);
1865 static void qlcnic_83xx_start_hw(struct qlcnic_adapter *p_dev)
1867 qlcnic_83xx_exec_template_cmd(p_dev, p_dev->ahw->reset.start_offset);
1868 if (p_dev->ahw->reset.template_end != 1)
1869 dev_err(&p_dev->pdev->dev, "%s: failed\n", __func__);
1872 static void qlcnic_83xx_init_hw(struct qlcnic_adapter *p_dev)
1874 qlcnic_83xx_exec_template_cmd(p_dev, p_dev->ahw->reset.init_offset);
1875 if (p_dev->ahw->reset.seq_end != 1)
1876 dev_err(&p_dev->pdev->dev, "%s: failed\n", __func__);
1879 static int qlcnic_83xx_load_fw_image_from_host(struct qlcnic_adapter *adapter)
1883 if (reject_firmware(&adapter->ahw->fw_info.fw,
1884 QLC_83XX_FW_FILE_NAME, &(adapter->pdev->dev))) {
1885 dev_err(&adapter->pdev->dev,
1886 "No file FW image, loading flash FW image.\n");
1887 QLC_SHARED_REG_WR32(adapter, QLCNIC_FW_IMG_VALID,
1888 QLC_83XX_BOOT_FROM_FLASH);
1890 if (qlcnic_83xx_copy_fw_file(adapter))
1892 QLC_SHARED_REG_WR32(adapter, QLCNIC_FW_IMG_VALID,
1893 QLC_83XX_BOOT_FROM_FILE);
1899 static int qlcnic_83xx_restart_hw(struct qlcnic_adapter *adapter)
1904 qlcnic_83xx_stop_hw(adapter);
1906 /* Collect FW register dump if required */
1907 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1908 if (!(val & QLC_83XX_IDC_GRACEFULL_RESET))
1909 qlcnic_dump_fw(adapter);
1910 qlcnic_83xx_init_hw(adapter);
1912 if (qlcnic_83xx_copy_bootloader(adapter))
1914 /* Boot either flash image or firmware image from host file system */
1915 if (qlcnic_load_fw_file) {
1916 if (qlcnic_83xx_load_fw_image_from_host(adapter))
1919 QLC_SHARED_REG_WR32(adapter, QLCNIC_FW_IMG_VALID,
1920 QLC_83XX_BOOT_FROM_FLASH);
1923 qlcnic_83xx_start_hw(adapter);
1924 if (qlcnic_83xx_check_hw_status(adapter))
1931 * qlcnic_83xx_config_default_opmode
1933 * @adapter: adapter structure
1935 * Configure default driver operating mode
1937 * Returns: Error code or Success(0)
1939 int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
1942 struct qlcnic_hardware_context *ahw = adapter->ahw;
1944 qlcnic_get_func_no(adapter);
1945 op_mode = QLCRDX(ahw, QLC_83XX_DRV_OP_MODE);
1947 if (test_bit(__QLCNIC_SRIOV_CAPABLE, &adapter->state))
1948 op_mode = QLC_83XX_DEFAULT_OPMODE;
1950 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
1951 adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
1952 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
1960 int qlcnic_83xx_get_nic_configuration(struct qlcnic_adapter *adapter)
1963 struct qlcnic_info nic_info;
1964 struct qlcnic_hardware_context *ahw = adapter->ahw;
1966 memset(&nic_info, 0, sizeof(struct qlcnic_info));
1967 err = qlcnic_get_nic_info(adapter, &nic_info, ahw->pci_func);
1971 ahw->physical_port = (u8) nic_info.phys_port;
1972 ahw->switch_mode = nic_info.switch_mode;
1973 ahw->max_tx_ques = nic_info.max_tx_ques;
1974 ahw->max_rx_ques = nic_info.max_rx_ques;
1975 ahw->capabilities = nic_info.capabilities;
1976 ahw->max_mac_filters = nic_info.max_mac_filters;
1977 ahw->max_mtu = nic_info.max_mtu;
1979 /* VNIC mode is detected by BIT_23 in capabilities. This bit is also
1980 * set in case device is SRIOV capable. VNIC and SRIOV are mutually
1981 * exclusive. So in case of sriov capable device load driver in
1984 if (test_bit(__QLCNIC_SRIOV_CAPABLE, &adapter->state)) {
1985 ahw->nic_mode = QLC_83XX_DEFAULT_MODE;
1986 return ahw->nic_mode;
1989 if (ahw->capabilities & BIT_23)
1990 ahw->nic_mode = QLC_83XX_VIRTUAL_NIC_MODE;
1992 ahw->nic_mode = QLC_83XX_DEFAULT_MODE;
1994 return ahw->nic_mode;
1997 int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
2001 ret = qlcnic_83xx_get_nic_configuration(adapter);
2005 if (ret == QLC_83XX_VIRTUAL_NIC_MODE) {
2006 if (qlcnic_83xx_config_vnic_opmode(adapter))
2008 } else if (ret == QLC_83XX_DEFAULT_MODE) {
2009 if (qlcnic_83xx_config_default_opmode(adapter))
2016 static void qlcnic_83xx_config_buff_descriptors(struct qlcnic_adapter *adapter)
2018 struct qlcnic_hardware_context *ahw = adapter->ahw;
2020 if (ahw->port_type == QLCNIC_XGBE) {
2021 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
2022 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
2023 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
2024 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
2026 } else if (ahw->port_type == QLCNIC_GBE) {
2027 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
2028 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
2029 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
2030 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
2032 adapter->num_txd = MAX_CMD_DESCRIPTORS;
2033 adapter->max_rds_rings = MAX_RDS_RINGS;
2036 static int qlcnic_83xx_init_default_driver(struct qlcnic_adapter *adapter)
2040 qlcnic_83xx_get_minidump_template(adapter);
2041 if (qlcnic_83xx_get_port_info(adapter))
2044 qlcnic_83xx_config_buff_descriptors(adapter);
2045 adapter->ahw->msix_supported = !!qlcnic_use_msi_x;
2046 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
2048 dev_info(&adapter->pdev->dev, "HAL Version: %d\n",
2049 adapter->ahw->fw_hal_version);
2054 #define IS_QLC_83XX_USED(a, b, c) (((1 << a->portnum) & b) || ((c >> 6) & 0x1))
2055 static void qlcnic_83xx_clear_function_resources(struct qlcnic_adapter *adapter)
2057 struct qlcnic_cmd_args cmd;
2058 u32 presence_mask, audit_mask;
2061 presence_mask = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE);
2062 audit_mask = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_AUDIT);
2064 if (IS_QLC_83XX_USED(adapter, presence_mask, audit_mask)) {
2065 qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_STOP_NIC_FUNC);
2066 cmd.req.arg[1] = BIT_31;
2067 status = qlcnic_issue_cmd(adapter, &cmd);
2069 dev_err(&adapter->pdev->dev,
2070 "Failed to clean up the function resources\n");
2071 qlcnic_free_mbx_args(&cmd);
2075 int qlcnic_83xx_init(struct qlcnic_adapter *adapter, int pci_using_dac)
2077 struct qlcnic_hardware_context *ahw = adapter->ahw;
2079 if (qlcnic_sriov_vf_check(adapter))
2080 return qlcnic_sriov_vf_init(adapter, pci_using_dac);
2082 if (qlcnic_83xx_check_hw_status(adapter))
2085 /* Initilaize 83xx mailbox spinlock */
2086 spin_lock_init(&ahw->mbx_lock);
2088 set_bit(QLC_83XX_MBX_READY, &adapter->ahw->idc.status);
2089 qlcnic_83xx_clear_function_resources(adapter);
2091 /* register for NIC IDC AEN Events */
2092 qlcnic_83xx_register_nic_idc_func(adapter, 1);
2094 if (!qlcnic_83xx_read_flash_descriptor_table(adapter))
2095 qlcnic_83xx_read_flash_mfg_id(adapter);
2097 if (qlcnic_83xx_idc_init(adapter))
2100 /* Configure default, SR-IOV or Virtual NIC mode of operation */
2101 if (qlcnic_83xx_configure_opmode(adapter))
2104 /* Perform operating mode specific initialization */
2105 if (adapter->nic_ops->init_driver(adapter))
2108 INIT_DELAYED_WORK(&adapter->idc_aen_work, qlcnic_83xx_idc_aen_work);
2110 /* Periodically monitor device status */
2111 qlcnic_83xx_idc_poll_dev_state(&adapter->fw_work.work);
2113 return adapter->ahw->idc.err_code;