2 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2013 QLogic Corporation
5 * See LICENSE.qlcnic for copyright and licensing details.
11 /* Reset template definitions */
12 #define QLC_83XX_RESTART_TEMPLATE_SIZE 0x2000
13 #define QLC_83XX_RESET_TEMPLATE_ADDR 0x4F0000
14 #define QLC_83XX_RESET_SEQ_VERSION 0x0101
16 #define QLC_83XX_OPCODE_NOP 0x0000
17 #define QLC_83XX_OPCODE_WRITE_LIST 0x0001
18 #define QLC_83XX_OPCODE_READ_WRITE_LIST 0x0002
19 #define QLC_83XX_OPCODE_POLL_LIST 0x0004
20 #define QLC_83XX_OPCODE_POLL_WRITE_LIST 0x0008
21 #define QLC_83XX_OPCODE_READ_MODIFY_WRITE 0x0010
22 #define QLC_83XX_OPCODE_SEQ_PAUSE 0x0020
23 #define QLC_83XX_OPCODE_SEQ_END 0x0040
24 #define QLC_83XX_OPCODE_TMPL_END 0x0080
25 #define QLC_83XX_OPCODE_POLL_READ_LIST 0x0100
27 static int qlcnic_83xx_init_default_driver(struct qlcnic_adapter *adapter);
28 static int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter);
29 static int qlcnic_83xx_check_heartbeat(struct qlcnic_adapter *p_dev);
30 static int qlcnic_83xx_restart_hw(struct qlcnic_adapter *adapter);
33 struct qlc_83xx_reset_hdr {
44 /* Command entry header. */
45 struct qlc_83xx_entry_hdr {
52 /* Generic poll command */
53 struct qlc_83xx_poll {
58 /* Read modify write command */
69 /* Generic command with 2 DWORD */
70 struct qlc_83xx_entry {
75 /* Generic command with 4 DWORD */
76 struct qlc_83xx_quad_entry {
82 static const char *const qlc_83xx_idc_states[] = {
94 enum qlcnic_83xx_states {
95 QLC_83XX_IDC_DEV_UNKNOWN,
96 QLC_83XX_IDC_DEV_COLD,
97 QLC_83XX_IDC_DEV_INIT,
98 QLC_83XX_IDC_DEV_READY,
99 QLC_83XX_IDC_DEV_NEED_RESET,
100 QLC_83XX_IDC_DEV_NEED_QUISCENT,
101 QLC_83XX_IDC_DEV_FAILED,
102 QLC_83XX_IDC_DEV_QUISCENT
106 qlcnic_83xx_idc_check_driver_presence_reg(struct qlcnic_adapter *adapter)
110 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE);
117 static void qlcnic_83xx_idc_log_state_history(struct qlcnic_adapter *adapter)
120 cur = adapter->ahw->idc.curr_state;
121 prev = adapter->ahw->idc.prev_state;
123 dev_info(&adapter->pdev->dev,
124 "current state = %s, prev state = %s\n",
125 adapter->ahw->idc.name[cur],
126 adapter->ahw->idc.name[prev]);
129 static int qlcnic_83xx_idc_update_audit_reg(struct qlcnic_adapter *adapter,
136 if (qlcnic_83xx_lock_driver(adapter))
140 val = adapter->portnum & 0xf;
143 seconds = jiffies / HZ - adapter->ahw->idc.sec_counter;
145 seconds = jiffies / HZ;
148 QLCWRX(adapter->ahw, QLC_83XX_IDC_DRV_AUDIT, val);
149 adapter->ahw->idc.sec_counter = jiffies / HZ;
152 qlcnic_83xx_unlock_driver(adapter);
157 static void qlcnic_83xx_idc_update_minor_version(struct qlcnic_adapter *adapter)
161 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_MIN_VERSION);
162 val = val & ~(0x3 << (adapter->portnum * 2));
163 val = val | (QLC_83XX_IDC_MINOR_VERSION << (adapter->portnum * 2));
164 QLCWRX(adapter->ahw, QLC_83XX_IDC_MIN_VERSION, val);
167 static int qlcnic_83xx_idc_update_major_version(struct qlcnic_adapter *adapter,
173 if (qlcnic_83xx_lock_driver(adapter))
177 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_MAJ_VERSION);
179 val = val | QLC_83XX_IDC_MAJOR_VERSION;
180 QLCWRX(adapter->ahw, QLC_83XX_IDC_MAJ_VERSION, val);
183 qlcnic_83xx_unlock_driver(adapter);
189 qlcnic_83xx_idc_update_drv_presence_reg(struct qlcnic_adapter *adapter,
190 int status, int lock)
195 if (qlcnic_83xx_lock_driver(adapter))
199 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE);
202 val = val | (1 << adapter->portnum);
204 val = val & ~(1 << adapter->portnum);
206 QLCWRX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE, val);
207 qlcnic_83xx_idc_update_minor_version(adapter);
210 qlcnic_83xx_unlock_driver(adapter);
215 static int qlcnic_83xx_idc_check_major_version(struct qlcnic_adapter *adapter)
220 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_MAJ_VERSION);
221 version = val & 0xFF;
223 if (version != QLC_83XX_IDC_MAJOR_VERSION) {
224 dev_info(&adapter->pdev->dev,
225 "%s:mismatch. version 0x%x, expected version 0x%x\n",
226 __func__, version, QLC_83XX_IDC_MAJOR_VERSION);
233 static int qlcnic_83xx_idc_clear_registers(struct qlcnic_adapter *adapter,
239 if (qlcnic_83xx_lock_driver(adapter))
243 QLCWRX(adapter->ahw, QLC_83XX_IDC_DRV_ACK, 0);
244 /* Clear gracefull reset bit */
245 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
246 val &= ~QLC_83XX_IDC_GRACEFULL_RESET;
247 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
250 qlcnic_83xx_unlock_driver(adapter);
255 static int qlcnic_83xx_idc_update_drv_ack_reg(struct qlcnic_adapter *adapter,
261 if (qlcnic_83xx_lock_driver(adapter))
265 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_ACK);
267 val = val | (1 << adapter->portnum);
269 val = val & ~(1 << adapter->portnum);
270 QLCWRX(adapter->ahw, QLC_83XX_IDC_DRV_ACK, val);
273 qlcnic_83xx_unlock_driver(adapter);
278 static int qlcnic_83xx_idc_check_timeout(struct qlcnic_adapter *adapter,
283 seconds = jiffies / HZ - adapter->ahw->idc.sec_counter;
284 if (seconds <= time_limit)
291 * qlcnic_83xx_idc_check_reset_ack_reg
293 * @adapter: adapter structure
295 * Check ACK wait limit and clear the functions which failed to ACK
297 * Return 0 if all functions have acknowledged the reset request.
299 static int qlcnic_83xx_idc_check_reset_ack_reg(struct qlcnic_adapter *adapter)
302 u32 ack, presence, val;
304 timeout = QLC_83XX_IDC_RESET_TIMEOUT_SECS;
305 ack = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_ACK);
306 presence = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE);
307 dev_info(&adapter->pdev->dev,
308 "%s: ack = 0x%x, presence = 0x%x\n", __func__, ack, presence);
309 if (!((ack & presence) == presence)) {
310 if (qlcnic_83xx_idc_check_timeout(adapter, timeout)) {
311 /* Clear functions which failed to ACK */
312 dev_info(&adapter->pdev->dev,
313 "%s: ACK wait exceeds time limit\n", __func__);
314 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE);
315 val = val & ~(ack ^ presence);
316 if (qlcnic_83xx_lock_driver(adapter))
318 QLCWRX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE, val);
319 dev_info(&adapter->pdev->dev,
320 "%s: updated drv presence reg = 0x%x\n",
322 qlcnic_83xx_unlock_driver(adapter);
329 dev_info(&adapter->pdev->dev,
330 "%s: Reset ACK received from all functions\n",
337 * qlcnic_83xx_idc_tx_soft_reset
339 * @adapter: adapter structure
341 * Handle context deletion and recreation request from transmit routine
343 * Returns -EBUSY or Success (0)
346 static int qlcnic_83xx_idc_tx_soft_reset(struct qlcnic_adapter *adapter)
348 struct net_device *netdev = adapter->netdev;
350 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
353 netif_device_detach(netdev);
354 qlcnic_down(adapter, netdev);
355 qlcnic_up(adapter, netdev);
356 netif_device_attach(netdev);
357 clear_bit(__QLCNIC_RESETTING, &adapter->state);
358 dev_err(&adapter->pdev->dev, "%s:\n", __func__);
360 adapter->netdev->trans_start = jiffies;
366 * qlcnic_83xx_idc_detach_driver
368 * @adapter: adapter structure
369 * Detach net interface, stop TX and cleanup resources before the HW reset.
373 static void qlcnic_83xx_idc_detach_driver(struct qlcnic_adapter *adapter)
376 struct net_device *netdev = adapter->netdev;
378 netif_device_detach(netdev);
379 /* Disable mailbox interrupt */
380 QLCWRX(adapter->ahw, QLCNIC_MBX_INTR_ENBL, 0);
381 qlcnic_down(adapter, netdev);
382 for (i = 0; i < adapter->ahw->num_msix; i++) {
383 adapter->ahw->intr_tbl[i].id = i;
384 adapter->ahw->intr_tbl[i].enabled = 0;
385 adapter->ahw->intr_tbl[i].src = 0;
390 * qlcnic_83xx_idc_attach_driver
392 * @adapter: adapter structure
394 * Re-attach and re-enable net interface
398 static void qlcnic_83xx_idc_attach_driver(struct qlcnic_adapter *adapter)
400 struct net_device *netdev = adapter->netdev;
402 if (netif_running(netdev)) {
403 if (qlcnic_up(adapter, netdev))
405 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
408 netif_device_attach(netdev);
409 if (netif_running(netdev)) {
410 netif_carrier_on(netdev);
411 netif_wake_queue(netdev);
415 static int qlcnic_83xx_idc_enter_failed_state(struct qlcnic_adapter *adapter,
419 if (qlcnic_83xx_lock_driver(adapter))
423 qlcnic_83xx_idc_clear_registers(adapter, 0);
424 QLCWRX(adapter->ahw, QLC_83XX_IDC_DEV_STATE, QLC_83XX_IDC_DEV_FAILED);
426 qlcnic_83xx_unlock_driver(adapter);
428 qlcnic_83xx_idc_log_state_history(adapter);
429 dev_info(&adapter->pdev->dev, "Device will enter failed state\n");
434 static int qlcnic_83xx_idc_enter_init_state(struct qlcnic_adapter *adapter,
438 if (qlcnic_83xx_lock_driver(adapter))
442 QLCWRX(adapter->ahw, QLC_83XX_IDC_DEV_STATE, QLC_83XX_IDC_DEV_INIT);
445 qlcnic_83xx_unlock_driver(adapter);
450 static int qlcnic_83xx_idc_enter_need_quiesce(struct qlcnic_adapter *adapter,
454 if (qlcnic_83xx_lock_driver(adapter))
458 QLCWRX(adapter->ahw, QLC_83XX_IDC_DEV_STATE,
459 QLC_83XX_IDC_DEV_NEED_QUISCENT);
462 qlcnic_83xx_unlock_driver(adapter);
468 qlcnic_83xx_idc_enter_need_reset_state(struct qlcnic_adapter *adapter, int lock)
471 if (qlcnic_83xx_lock_driver(adapter))
475 QLCWRX(adapter->ahw, QLC_83XX_IDC_DEV_STATE,
476 QLC_83XX_IDC_DEV_NEED_RESET);
479 qlcnic_83xx_unlock_driver(adapter);
484 static int qlcnic_83xx_idc_enter_ready_state(struct qlcnic_adapter *adapter,
488 if (qlcnic_83xx_lock_driver(adapter))
492 QLCWRX(adapter->ahw, QLC_83XX_IDC_DEV_STATE, QLC_83XX_IDC_DEV_READY);
494 qlcnic_83xx_unlock_driver(adapter);
500 * qlcnic_83xx_idc_find_reset_owner_id
502 * @adapter: adapter structure
504 * NIC gets precedence over ISCSI and ISCSI has precedence over FCOE.
505 * Within the same class, function with lowest PCI ID assumes ownership
507 * Returns: reset owner id or failure indication (-EIO)
510 static int qlcnic_83xx_idc_find_reset_owner_id(struct qlcnic_adapter *adapter)
512 u32 reg, reg1, reg2, i, j, owner, class;
514 reg1 = QLCRDX(adapter->ahw, QLC_83XX_IDC_DEV_PARTITION_INFO_1);
515 reg2 = QLCRDX(adapter->ahw, QLC_83XX_IDC_DEV_PARTITION_INFO_2);
516 owner = QLCNIC_TYPE_NIC;
522 class = (((reg & (0xF << j * 4)) >> j * 4) & 0x3);
525 if (i == (QLC_83XX_IDC_MAX_FUNC_PER_PARTITION_INFO - 1)) {
532 if (i == (QLC_83XX_IDC_MAX_CNA_FUNCTIONS - 1)) {
533 if (owner == QLCNIC_TYPE_NIC)
534 owner = QLCNIC_TYPE_ISCSI;
535 else if (owner == QLCNIC_TYPE_ISCSI)
536 owner = QLCNIC_TYPE_FCOE;
537 else if (owner == QLCNIC_TYPE_FCOE)
543 } while (i++ < QLC_83XX_IDC_MAX_CNA_FUNCTIONS);
548 static int qlcnic_83xx_idc_restart_hw(struct qlcnic_adapter *adapter, int lock)
552 ret = qlcnic_83xx_restart_hw(adapter);
555 qlcnic_83xx_idc_enter_failed_state(adapter, lock);
557 qlcnic_83xx_idc_clear_registers(adapter, lock);
558 ret = qlcnic_83xx_idc_enter_ready_state(adapter, lock);
564 static int qlcnic_83xx_idc_check_fan_failure(struct qlcnic_adapter *adapter)
568 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
570 if (status & QLCNIC_RCODE_FATAL_ERROR) {
571 dev_err(&adapter->pdev->dev,
572 "peg halt status1=0x%x\n", status);
573 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
574 dev_err(&adapter->pdev->dev,
575 "On board active cooling fan failed. "
576 "Device has been halted.\n");
577 dev_err(&adapter->pdev->dev,
578 "Replace the adapter.\n");
586 static int qlcnic_83xx_idc_reattach_driver(struct qlcnic_adapter *adapter)
588 /* register for NIC IDC AEN Events */
589 qlcnic_83xx_register_nic_idc_func(adapter, 1);
591 qlcnic_83xx_enable_mbx_intrpt(adapter);
592 if ((adapter->flags & QLCNIC_MSIX_ENABLED)) {
593 if (qlcnic_83xx_config_intrpt(adapter, 1)) {
594 netdev_err(adapter->netdev,
595 "Failed to enable mbx intr\n");
600 if (qlcnic_83xx_configure_opmode(adapter)) {
601 qlcnic_83xx_idc_enter_failed_state(adapter, 1);
605 if (adapter->nic_ops->init_driver(adapter)) {
606 qlcnic_83xx_idc_enter_failed_state(adapter, 1);
610 qlcnic_83xx_idc_attach_driver(adapter);
615 static void qlcnic_83xx_idc_update_idc_params(struct qlcnic_adapter *adapter)
617 qlcnic_83xx_idc_update_drv_presence_reg(adapter, 1, 1);
618 clear_bit(__QLCNIC_RESETTING, &adapter->state);
619 set_bit(QLC_83XX_MBX_READY, &adapter->ahw->idc.status);
620 qlcnic_83xx_idc_update_audit_reg(adapter, 0, 1);
621 set_bit(QLC_83XX_MODULE_LOADED, &adapter->ahw->idc.status);
622 adapter->ahw->idc.quiesce_req = 0;
623 adapter->ahw->idc.delay = QLC_83XX_IDC_FW_POLL_DELAY;
624 adapter->ahw->idc.err_code = 0;
625 adapter->ahw->idc.collect_dump = 0;
629 * qlcnic_83xx_idc_ready_state_entry
631 * @adapter: adapter structure
633 * Perform ready state initialization, this routine will get invoked only
634 * once from READY state.
636 * Returns: Error code or Success(0)
639 int qlcnic_83xx_idc_ready_state_entry(struct qlcnic_adapter *adapter)
641 struct qlcnic_hardware_context *ahw = adapter->ahw;
643 if (ahw->idc.prev_state != QLC_83XX_IDC_DEV_READY) {
644 qlcnic_83xx_idc_update_idc_params(adapter);
645 /* Re-attach the device if required */
646 if ((ahw->idc.prev_state == QLC_83XX_IDC_DEV_NEED_RESET) ||
647 (ahw->idc.prev_state == QLC_83XX_IDC_DEV_INIT)) {
648 if (qlcnic_83xx_idc_reattach_driver(adapter))
657 * qlcnic_83xx_idc_vnic_pf_entry
659 * @adapter: adapter structure
661 * Ensure vNIC mode privileged function starts only after vNIC mode is
662 * enabled by management function.
663 * If vNIC mode is ready, start initialization.
668 int qlcnic_83xx_idc_vnic_pf_entry(struct qlcnic_adapter *adapter)
671 struct qlcnic_hardware_context *ahw = adapter->ahw;
673 /* Privileged function waits till mgmt function enables VNIC mode */
674 state = QLCRDX(adapter->ahw, QLC_83XX_VNIC_STATE);
675 if (state != QLCNIC_DEV_NPAR_OPER) {
676 if (!ahw->idc.vnic_wait_limit--) {
677 qlcnic_83xx_idc_enter_failed_state(adapter, 1);
680 dev_info(&adapter->pdev->dev, "vNIC mode disabled\n");
684 /* Perform one time initialization from ready state */
685 if (ahw->idc.vnic_state != QLCNIC_DEV_NPAR_OPER) {
686 qlcnic_83xx_idc_update_idc_params(adapter);
688 /* If the previous state is UNKNOWN, device will be
689 already attached properly by Init routine*/
690 if (ahw->idc.prev_state != QLC_83XX_IDC_DEV_UNKNOWN) {
691 if (qlcnic_83xx_idc_reattach_driver(adapter))
694 adapter->ahw->idc.vnic_state = QLCNIC_DEV_NPAR_OPER;
695 dev_info(&adapter->pdev->dev, "vNIC mode enabled\n");
702 static int qlcnic_83xx_idc_unknown_state(struct qlcnic_adapter *adapter)
704 adapter->ahw->idc.err_code = -EIO;
705 dev_err(&adapter->pdev->dev,
706 "%s: Device in unknown state\n", __func__);
711 * qlcnic_83xx_idc_cold_state
713 * @adapter: adapter structure
715 * If HW is up and running device will enter READY state.
716 * If firmware image from host needs to be loaded, device is
717 * forced to start with the file firmware image.
719 * Returns: Error code or Success(0)
722 static int qlcnic_83xx_idc_cold_state_handler(struct qlcnic_adapter *adapter)
724 qlcnic_83xx_idc_update_drv_presence_reg(adapter, 1, 0);
725 qlcnic_83xx_idc_update_audit_reg(adapter, 1, 0);
727 if (qlcnic_load_fw_file) {
728 qlcnic_83xx_idc_restart_hw(adapter, 0);
730 if (qlcnic_83xx_check_hw_status(adapter)) {
731 qlcnic_83xx_idc_enter_failed_state(adapter, 0);
734 qlcnic_83xx_idc_enter_ready_state(adapter, 0);
741 * qlcnic_83xx_idc_init_state
743 * @adapter: adapter structure
745 * Reset owner will restart the device from this state.
746 * Device will enter failed state if it remains
747 * in this state for more than DEV_INIT time limit.
749 * Returns: Error code or Success(0)
752 static int qlcnic_83xx_idc_init_state(struct qlcnic_adapter *adapter)
754 int timeout, ret = 0;
757 timeout = QLC_83XX_IDC_INIT_TIMEOUT_SECS;
758 if (adapter->ahw->idc.prev_state == QLC_83XX_IDC_DEV_NEED_RESET) {
759 owner = qlcnic_83xx_idc_find_reset_owner_id(adapter);
760 if (adapter->ahw->pci_func == owner)
761 ret = qlcnic_83xx_idc_restart_hw(adapter, 1);
763 ret = qlcnic_83xx_idc_check_timeout(adapter, timeout);
771 * qlcnic_83xx_idc_ready_state
773 * @adapter: adapter structure
775 * Perform IDC protocol specicifed actions after monitoring device state and
778 * Returns: Error code or Success(0)
781 static int qlcnic_83xx_idc_ready_state(struct qlcnic_adapter *adapter)
784 struct qlcnic_hardware_context *ahw = adapter->ahw;
787 /* Perform NIC configuration based ready state entry actions */
788 if (ahw->idc.state_entry(adapter))
791 if (qlcnic_check_temp(adapter)) {
792 if (ahw->temp == QLCNIC_TEMP_PANIC) {
793 qlcnic_83xx_idc_check_fan_failure(adapter);
794 dev_err(&adapter->pdev->dev,
795 "Error: device temperature %d above limits\n",
797 clear_bit(QLC_83XX_MBX_READY, &ahw->idc.status);
798 set_bit(__QLCNIC_RESETTING, &adapter->state);
799 qlcnic_83xx_idc_detach_driver(adapter);
800 qlcnic_83xx_idc_enter_failed_state(adapter, 1);
805 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
806 ret = qlcnic_83xx_check_heartbeat(adapter);
808 adapter->flags |= QLCNIC_FW_HANG;
809 if (!(val & QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY)) {
810 clear_bit(QLC_83XX_MBX_READY, &ahw->idc.status);
811 set_bit(__QLCNIC_RESETTING, &adapter->state);
812 qlcnic_83xx_idc_enter_need_reset_state(adapter, 1);
817 if ((val & QLC_83XX_IDC_GRACEFULL_RESET) || ahw->idc.collect_dump) {
818 /* Move to need reset state and prepare for reset */
819 qlcnic_83xx_idc_enter_need_reset_state(adapter, 1);
823 /* Check for soft reset request */
824 if (ahw->reset_context &&
825 !(val & QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY)) {
826 qlcnic_83xx_idc_tx_soft_reset(adapter);
830 /* Move to need quiesce state if requested */
831 if (adapter->ahw->idc.quiesce_req) {
832 qlcnic_83xx_idc_enter_need_quiesce(adapter, 1);
833 qlcnic_83xx_idc_update_audit_reg(adapter, 0, 1);
841 * qlcnic_83xx_idc_need_reset_state
843 * @adapter: adapter structure
845 * Device will remain in this state until:
846 * Reset request ACK's are recieved from all the functions
847 * Wait time exceeds max time limit
849 * Returns: Error code or Success(0)
852 static int qlcnic_83xx_idc_need_reset_state(struct qlcnic_adapter *adapter)
856 if (adapter->ahw->idc.prev_state != QLC_83XX_IDC_DEV_NEED_RESET) {
857 qlcnic_83xx_idc_update_drv_ack_reg(adapter, 1, 1);
858 qlcnic_83xx_idc_update_audit_reg(adapter, 0, 1);
859 set_bit(__QLCNIC_RESETTING, &adapter->state);
860 clear_bit(QLC_83XX_MBX_READY, &adapter->ahw->idc.status);
861 if (adapter->ahw->nic_mode == QLC_83XX_VIRTUAL_NIC_MODE)
862 qlcnic_83xx_disable_vnic_mode(adapter, 1);
863 qlcnic_83xx_idc_detach_driver(adapter);
866 /* Check ACK from other functions */
867 ret = qlcnic_83xx_idc_check_reset_ack_reg(adapter);
869 dev_info(&adapter->pdev->dev,
870 "%s: Waiting for reset ACK\n", __func__);
874 /* Transit to INIT state and restart the HW */
875 qlcnic_83xx_idc_enter_init_state(adapter, 1);
880 static int qlcnic_83xx_idc_need_quiesce_state(struct qlcnic_adapter *adapter)
882 dev_err(&adapter->pdev->dev, "%s: TBD\n", __func__);
886 static int qlcnic_83xx_idc_failed_state(struct qlcnic_adapter *adapter)
888 dev_err(&adapter->pdev->dev, "%s: please restart!!\n", __func__);
889 adapter->ahw->idc.err_code = -EIO;
894 static int qlcnic_83xx_idc_quiesce_state(struct qlcnic_adapter *adapter)
896 dev_info(&adapter->pdev->dev, "%s: TBD\n", __func__);
900 static int qlcnic_83xx_idc_check_state_validity(struct qlcnic_adapter *adapter,
905 cur = adapter->ahw->idc.curr_state;
906 prev = adapter->ahw->idc.prev_state;
909 if ((next < QLC_83XX_IDC_DEV_COLD) ||
910 (next > QLC_83XX_IDC_DEV_QUISCENT)) {
911 dev_err(&adapter->pdev->dev,
912 "%s: curr %d, prev %d, next state %d is invalid\n",
913 __func__, cur, prev, state);
917 if ((cur == QLC_83XX_IDC_DEV_UNKNOWN) &&
918 (prev == QLC_83XX_IDC_DEV_UNKNOWN)) {
919 if ((next != QLC_83XX_IDC_DEV_COLD) &&
920 (next != QLC_83XX_IDC_DEV_READY)) {
921 dev_err(&adapter->pdev->dev,
922 "%s: failed, cur %d prev %d next %d\n",
923 __func__, cur, prev, next);
928 if (next == QLC_83XX_IDC_DEV_INIT) {
929 if ((prev != QLC_83XX_IDC_DEV_INIT) &&
930 (prev != QLC_83XX_IDC_DEV_COLD) &&
931 (prev != QLC_83XX_IDC_DEV_NEED_RESET)) {
932 dev_err(&adapter->pdev->dev,
933 "%s: failed, cur %d prev %d next %d\n",
934 __func__, cur, prev, next);
942 static void qlcnic_83xx_periodic_tasks(struct qlcnic_adapter *adapter)
944 if (adapter->fhash.fnum)
945 qlcnic_prune_lb_filters(adapter);
949 * qlcnic_83xx_idc_poll_dev_state
951 * @work: kernel work queue structure used to schedule the function
953 * Poll device state periodically and perform state specific
954 * actions defined by Inter Driver Communication (IDC) protocol.
959 void qlcnic_83xx_idc_poll_dev_state(struct work_struct *work)
961 struct qlcnic_adapter *adapter;
964 adapter = container_of(work, struct qlcnic_adapter, fw_work.work);
965 state = QLCRDX(adapter->ahw, QLC_83XX_IDC_DEV_STATE);
967 if (qlcnic_83xx_idc_check_state_validity(adapter, state)) {
968 qlcnic_83xx_idc_log_state_history(adapter);
969 adapter->ahw->idc.curr_state = QLC_83XX_IDC_DEV_UNKNOWN;
971 adapter->ahw->idc.curr_state = state;
974 switch (adapter->ahw->idc.curr_state) {
975 case QLC_83XX_IDC_DEV_READY:
976 qlcnic_83xx_idc_ready_state(adapter);
978 case QLC_83XX_IDC_DEV_NEED_RESET:
979 qlcnic_83xx_idc_need_reset_state(adapter);
981 case QLC_83XX_IDC_DEV_NEED_QUISCENT:
982 qlcnic_83xx_idc_need_quiesce_state(adapter);
984 case QLC_83XX_IDC_DEV_FAILED:
985 qlcnic_83xx_idc_failed_state(adapter);
987 case QLC_83XX_IDC_DEV_INIT:
988 qlcnic_83xx_idc_init_state(adapter);
990 case QLC_83XX_IDC_DEV_QUISCENT:
991 qlcnic_83xx_idc_quiesce_state(adapter);
994 qlcnic_83xx_idc_unknown_state(adapter);
997 adapter->ahw->idc.prev_state = adapter->ahw->idc.curr_state;
998 qlcnic_83xx_periodic_tasks(adapter);
1000 /* Re-schedule the function */
1001 if (test_bit(QLC_83XX_MODULE_LOADED, &adapter->ahw->idc.status))
1002 qlcnic_schedule_work(adapter, qlcnic_83xx_idc_poll_dev_state,
1003 adapter->ahw->idc.delay);
1006 static void qlcnic_83xx_setup_idc_parameters(struct qlcnic_adapter *adapter)
1008 u32 idc_params, val;
1010 if (qlcnic_83xx_lockless_flash_read32(adapter,
1011 QLC_83XX_IDC_FLASH_PARAM_ADDR,
1012 (u8 *)&idc_params, 1)) {
1013 dev_info(&adapter->pdev->dev,
1014 "%s:failed to get IDC params from flash\n", __func__);
1015 adapter->dev_init_timeo = QLC_83XX_IDC_INIT_TIMEOUT_SECS;
1016 adapter->reset_ack_timeo = QLC_83XX_IDC_RESET_TIMEOUT_SECS;
1018 adapter->dev_init_timeo = idc_params & 0xFFFF;
1019 adapter->reset_ack_timeo = ((idc_params >> 16) & 0xFFFF);
1022 adapter->ahw->idc.curr_state = QLC_83XX_IDC_DEV_UNKNOWN;
1023 adapter->ahw->idc.prev_state = QLC_83XX_IDC_DEV_UNKNOWN;
1024 adapter->ahw->idc.delay = QLC_83XX_IDC_FW_POLL_DELAY;
1025 adapter->ahw->idc.err_code = 0;
1026 adapter->ahw->idc.collect_dump = 0;
1027 adapter->ahw->idc.name = (char **)qlc_83xx_idc_states;
1029 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1030 set_bit(QLC_83XX_MBX_READY, &adapter->ahw->idc.status);
1031 set_bit(QLC_83XX_MODULE_LOADED, &adapter->ahw->idc.status);
1033 /* Check if reset recovery is disabled */
1034 if (!qlcnic_auto_fw_reset) {
1035 /* Propagate do not reset request to other functions */
1036 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1037 val = val | QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY;
1038 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
1043 qlcnic_83xx_idc_first_to_load_function_handler(struct qlcnic_adapter *adapter)
1047 if (qlcnic_83xx_lock_driver(adapter))
1050 /* Clear driver lock register */
1051 QLCWRX(adapter->ahw, QLC_83XX_RECOVER_DRV_LOCK, 0);
1052 if (qlcnic_83xx_idc_update_major_version(adapter, 0)) {
1053 qlcnic_83xx_unlock_driver(adapter);
1057 state = QLCRDX(adapter->ahw, QLC_83XX_IDC_DEV_STATE);
1058 if (qlcnic_83xx_idc_check_state_validity(adapter, state)) {
1059 qlcnic_83xx_unlock_driver(adapter);
1063 if (state != QLC_83XX_IDC_DEV_COLD && qlcnic_load_fw_file) {
1064 QLCWRX(adapter->ahw, QLC_83XX_IDC_DEV_STATE,
1065 QLC_83XX_IDC_DEV_COLD);
1066 state = QLC_83XX_IDC_DEV_COLD;
1069 adapter->ahw->idc.curr_state = state;
1070 /* First to load function should cold boot the device */
1071 if (state == QLC_83XX_IDC_DEV_COLD)
1072 qlcnic_83xx_idc_cold_state_handler(adapter);
1074 /* Check if reset recovery is enabled */
1075 if (qlcnic_auto_fw_reset) {
1076 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1077 val = val & ~QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY;
1078 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
1081 qlcnic_83xx_unlock_driver(adapter);
1086 static int qlcnic_83xx_idc_init(struct qlcnic_adapter *adapter)
1090 qlcnic_83xx_setup_idc_parameters(adapter);
1092 if (qlcnic_83xx_get_reset_instruction_template(adapter))
1095 if (!qlcnic_83xx_idc_check_driver_presence_reg(adapter)) {
1096 if (qlcnic_83xx_idc_first_to_load_function_handler(adapter))
1099 if (qlcnic_83xx_idc_check_major_version(adapter))
1103 qlcnic_83xx_idc_update_audit_reg(adapter, 0, 1);
1108 void qlcnic_83xx_idc_exit(struct qlcnic_adapter *adapter)
1113 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1114 usleep_range(10000, 11000);
1116 id = QLCRDX(adapter->ahw, QLC_83XX_DRV_LOCK_ID);
1119 if (id == adapter->portnum) {
1120 dev_err(&adapter->pdev->dev,
1121 "%s: wait for lock recovery.. %d\n", __func__, id);
1123 id = QLCRDX(adapter->ahw, QLC_83XX_DRV_LOCK_ID);
1127 /* Clear driver presence bit */
1128 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE);
1129 val = val & ~(1 << adapter->portnum);
1130 QLCWRX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE, val);
1131 clear_bit(QLC_83XX_MODULE_LOADED, &adapter->ahw->idc.status);
1132 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1134 cancel_delayed_work_sync(&adapter->fw_work);
1137 void qlcnic_83xx_idc_request_reset(struct qlcnic_adapter *adapter, u32 key)
1141 if (qlcnic_83xx_lock_driver(adapter)) {
1142 dev_err(&adapter->pdev->dev,
1143 "%s:failed, please retry\n", __func__);
1147 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1148 if ((val & QLC_83XX_IDC_DISABLE_FW_RESET_RECOVERY) ||
1149 !qlcnic_auto_fw_reset) {
1150 dev_err(&adapter->pdev->dev,
1151 "%s:failed, device in non reset mode\n", __func__);
1152 qlcnic_83xx_unlock_driver(adapter);
1156 if (key == QLCNIC_FORCE_FW_RESET) {
1157 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1158 val = val | QLC_83XX_IDC_GRACEFULL_RESET;
1159 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
1160 } else if (key == QLCNIC_FORCE_FW_DUMP_KEY) {
1161 adapter->ahw->idc.collect_dump = 1;
1164 qlcnic_83xx_unlock_driver(adapter);
1168 static int qlcnic_83xx_copy_bootloader(struct qlcnic_adapter *adapter)
1175 src = QLC_83XX_BOOTLOADER_FLASH_ADDR;
1176 dest = QLCRDX(adapter->ahw, QLCNIC_BOOTLOADER_ADDR);
1177 size = QLCRDX(adapter->ahw, QLCNIC_BOOTLOADER_SIZE);
1179 /* alignment check */
1181 size = (size + 16) & ~0xF;
1183 p_cache = kzalloc(size, GFP_KERNEL);
1184 if (p_cache == NULL)
1187 ret = qlcnic_83xx_lockless_flash_read32(adapter, src, p_cache,
1188 size / sizeof(u32));
1193 /* 16 byte write to MS memory */
1194 ret = qlcnic_83xx_ms_mem_write128(adapter, dest, (u32 *)p_cache,
1205 static int qlcnic_83xx_copy_fw_file(struct qlcnic_adapter *adapter)
1213 dest = QLCRDX(adapter->ahw, QLCNIC_FW_IMAGE_ADDR);
1214 size = (adapter->ahw->fw_info.fw->size & ~0xF);
1215 p_cache = (u32 *)adapter->ahw->fw_info.fw->data;
1218 ret = qlcnic_83xx_ms_mem_write128(adapter, addr,
1219 (u32 *)p_cache, size / 16);
1221 dev_err(&adapter->pdev->dev, "MS memory write failed\n");
1222 release_firmware(adapter->ahw->fw_info.fw);
1223 adapter->ahw->fw_info.fw = NULL;
1227 /* alignment check */
1228 if (adapter->ahw->fw_info.fw->size & 0xF) {
1230 for (i = 0; i < (adapter->ahw->fw_info.fw->size & 0xF); i++)
1231 data[i] = adapter->ahw->fw_info.fw->data[size + i];
1234 ret = qlcnic_83xx_ms_mem_write128(adapter, addr,
1237 dev_err(&adapter->pdev->dev,
1238 "MS memory write failed\n");
1239 release_firmware(adapter->ahw->fw_info.fw);
1240 adapter->ahw->fw_info.fw = NULL;
1244 release_firmware(adapter->ahw->fw_info.fw);
1245 adapter->ahw->fw_info.fw = NULL;
1250 static void qlcnic_83xx_dump_pause_control_regs(struct qlcnic_adapter *adapter)
1253 u32 val = 0, val1 = 0, reg = 0;
1255 val = QLCRD32(adapter, QLC_83XX_SRE_SHIM_REG);
1256 dev_info(&adapter->pdev->dev, "SRE-Shim Ctrl:0x%x\n", val);
1258 for (j = 0; j < 2; j++) {
1260 dev_info(&adapter->pdev->dev,
1261 "Port 0 RxB Pause Threshold Regs[TC7..TC0]:");
1262 reg = QLC_83XX_PORT0_THRESHOLD;
1263 } else if (j == 1) {
1264 dev_info(&adapter->pdev->dev,
1265 "Port 1 RxB Pause Threshold Regs[TC7..TC0]:");
1266 reg = QLC_83XX_PORT1_THRESHOLD;
1268 for (i = 0; i < 8; i++) {
1269 val = QLCRD32(adapter, reg + (i * 0x4));
1270 dev_info(&adapter->pdev->dev, "0x%x ", val);
1272 dev_info(&adapter->pdev->dev, "\n");
1275 for (j = 0; j < 2; j++) {
1277 dev_info(&adapter->pdev->dev,
1278 "Port 0 RxB TC Max Cell Registers[4..1]:");
1279 reg = QLC_83XX_PORT0_TC_MC_REG;
1280 } else if (j == 1) {
1281 dev_info(&adapter->pdev->dev,
1282 "Port 1 RxB TC Max Cell Registers[4..1]:");
1283 reg = QLC_83XX_PORT1_TC_MC_REG;
1285 for (i = 0; i < 4; i++) {
1286 val = QLCRD32(adapter, reg + (i * 0x4));
1287 dev_info(&adapter->pdev->dev, "0x%x ", val);
1289 dev_info(&adapter->pdev->dev, "\n");
1292 for (j = 0; j < 2; j++) {
1294 dev_info(&adapter->pdev->dev,
1295 "Port 0 RxB Rx TC Stats[TC7..TC0]:");
1296 reg = QLC_83XX_PORT0_TC_STATS;
1297 } else if (j == 1) {
1298 dev_info(&adapter->pdev->dev,
1299 "Port 1 RxB Rx TC Stats[TC7..TC0]:");
1300 reg = QLC_83XX_PORT1_TC_STATS;
1302 for (i = 7; i >= 0; i--) {
1303 val = QLCRD32(adapter, reg);
1304 val &= ~(0x7 << 29); /* Reset bits 29 to 31 */
1305 QLCWR32(adapter, reg, (val | (i << 29)));
1306 val = QLCRD32(adapter, reg);
1307 dev_info(&adapter->pdev->dev, "0x%x ", val);
1309 dev_info(&adapter->pdev->dev, "\n");
1312 val = QLCRD32(adapter, QLC_83XX_PORT2_IFB_THRESHOLD);
1313 val1 = QLCRD32(adapter, QLC_83XX_PORT3_IFB_THRESHOLD);
1314 dev_info(&adapter->pdev->dev,
1315 "IFB-Pause Thresholds: Port 2:0x%x, Port 3:0x%x\n",
1320 static void qlcnic_83xx_disable_pause_frames(struct qlcnic_adapter *adapter)
1324 if (qlcnic_83xx_lock_driver(adapter)) {
1325 dev_err(&adapter->pdev->dev,
1326 "%s:failed to acquire driver lock\n", __func__);
1330 qlcnic_83xx_dump_pause_control_regs(adapter);
1331 QLCWR32(adapter, QLC_83XX_SRE_SHIM_REG, 0x0);
1333 for (j = 0; j < 2; j++) {
1335 reg = QLC_83XX_PORT0_THRESHOLD;
1337 reg = QLC_83XX_PORT1_THRESHOLD;
1339 for (i = 0; i < 8; i++)
1340 QLCWR32(adapter, reg + (i * 0x4), 0x0);
1343 for (j = 0; j < 2; j++) {
1345 reg = QLC_83XX_PORT0_TC_MC_REG;
1347 reg = QLC_83XX_PORT1_TC_MC_REG;
1349 for (i = 0; i < 4; i++)
1350 QLCWR32(adapter, reg + (i * 0x4), 0x03FF03FF);
1353 QLCWR32(adapter, QLC_83XX_PORT2_IFB_THRESHOLD, 0);
1354 QLCWR32(adapter, QLC_83XX_PORT3_IFB_THRESHOLD, 0);
1355 dev_info(&adapter->pdev->dev,
1356 "Disabled pause frames successfully on all ports\n");
1357 qlcnic_83xx_unlock_driver(adapter);
1360 static int qlcnic_83xx_check_heartbeat(struct qlcnic_adapter *p_dev)
1362 u32 heartbeat, peg_status;
1363 int retries, ret = -EIO;
1365 retries = QLCNIC_HEARTBEAT_CHECK_RETRY_COUNT;
1366 p_dev->heartbeat = QLC_SHARED_REG_RD32(p_dev,
1367 QLCNIC_PEG_ALIVE_COUNTER);
1370 msleep(QLCNIC_HEARTBEAT_PERIOD_MSECS);
1371 heartbeat = QLC_SHARED_REG_RD32(p_dev,
1372 QLCNIC_PEG_ALIVE_COUNTER);
1373 if (heartbeat != p_dev->heartbeat) {
1374 ret = QLCNIC_RCODE_SUCCESS;
1377 } while (--retries);
1380 dev_err(&p_dev->pdev->dev, "firmware hang detected\n");
1381 qlcnic_83xx_disable_pause_frames(p_dev);
1382 peg_status = QLC_SHARED_REG_RD32(p_dev,
1383 QLCNIC_PEG_HALT_STATUS1);
1384 dev_info(&p_dev->pdev->dev, "Dumping HW/FW registers\n"
1385 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
1386 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
1387 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
1388 "PEG_NET_4_PC: 0x%x\n", peg_status,
1389 QLC_SHARED_REG_RD32(p_dev, QLCNIC_PEG_HALT_STATUS2),
1390 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_0),
1391 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_1),
1392 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_2),
1393 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_3),
1394 QLCRD32(p_dev, QLC_83XX_CRB_PEG_NET_4));
1396 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
1397 dev_err(&p_dev->pdev->dev,
1398 "Device is being reset err code 0x00006700.\n");
1404 static int qlcnic_83xx_check_cmd_peg_status(struct qlcnic_adapter *p_dev)
1406 int retries = QLCNIC_CMDPEG_CHECK_RETRY_COUNT;
1410 val = QLC_SHARED_REG_RD32(p_dev, QLCNIC_CMDPEG_STATE);
1411 if (val == QLC_83XX_CMDPEG_COMPLETE)
1413 msleep(QLCNIC_CMDPEG_CHECK_DELAY);
1414 } while (--retries);
1416 dev_err(&p_dev->pdev->dev, "%s: failed, state = 0x%x\n", __func__, val);
1420 int qlcnic_83xx_check_hw_status(struct qlcnic_adapter *p_dev)
1424 err = qlcnic_83xx_check_cmd_peg_status(p_dev);
1428 err = qlcnic_83xx_check_heartbeat(p_dev);
1435 static int qlcnic_83xx_poll_reg(struct qlcnic_adapter *p_dev, u32 addr,
1436 int duration, u32 mask, u32 status)
1442 value = qlcnic_83xx_rd_reg_indirect(p_dev, addr);
1443 retries = duration / 10;
1446 if ((value & mask) != status) {
1448 msleep(duration / 10);
1449 value = qlcnic_83xx_rd_reg_indirect(p_dev, addr);
1454 } while (retries--);
1456 if (timeout_error) {
1457 p_dev->ahw->reset.seq_error++;
1458 dev_err(&p_dev->pdev->dev,
1459 "%s: Timeout Err, entry_num = %d\n",
1460 __func__, p_dev->ahw->reset.seq_index);
1461 dev_err(&p_dev->pdev->dev,
1462 "0x%08x 0x%08x 0x%08x\n",
1463 value, mask, status);
1466 return timeout_error;
1469 static int qlcnic_83xx_reset_template_checksum(struct qlcnic_adapter *p_dev)
1472 u16 *buff = (u16 *)p_dev->ahw->reset.buff;
1473 int count = p_dev->ahw->reset.hdr->size / sizeof(u16);
1479 sum = (sum & 0xFFFF) + (sum >> 16);
1484 dev_err(&p_dev->pdev->dev, "%s: failed\n", __func__);
1489 int qlcnic_83xx_get_reset_instruction_template(struct qlcnic_adapter *p_dev)
1493 struct qlcnic_hardware_context *ahw = p_dev->ahw;
1495 ahw->reset.seq_error = 0;
1496 ahw->reset.buff = kzalloc(QLC_83XX_RESTART_TEMPLATE_SIZE, GFP_KERNEL);
1497 if (p_dev->ahw->reset.buff == NULL)
1500 p_buff = p_dev->ahw->reset.buff;
1501 addr = QLC_83XX_RESET_TEMPLATE_ADDR;
1502 count = sizeof(struct qlc_83xx_reset_hdr) / sizeof(u32);
1504 /* Copy template header from flash */
1505 if (qlcnic_83xx_flash_read32(p_dev, addr, p_buff, count)) {
1506 dev_err(&p_dev->pdev->dev, "%s: flash read failed\n", __func__);
1509 ahw->reset.hdr = (struct qlc_83xx_reset_hdr *)ahw->reset.buff;
1510 addr = QLC_83XX_RESET_TEMPLATE_ADDR + ahw->reset.hdr->hdr_size;
1511 p_buff = ahw->reset.buff + ahw->reset.hdr->hdr_size;
1512 count = (ahw->reset.hdr->size - ahw->reset.hdr->hdr_size) / sizeof(u32);
1514 /* Copy rest of the template */
1515 if (qlcnic_83xx_flash_read32(p_dev, addr, p_buff, count)) {
1516 dev_err(&p_dev->pdev->dev, "%s: flash read failed\n", __func__);
1520 if (qlcnic_83xx_reset_template_checksum(p_dev))
1522 /* Get Stop, Start and Init command offsets */
1523 ahw->reset.init_offset = ahw->reset.buff + ahw->reset.hdr->init_offset;
1524 ahw->reset.start_offset = ahw->reset.buff +
1525 ahw->reset.hdr->start_offset;
1526 ahw->reset.stop_offset = ahw->reset.buff + ahw->reset.hdr->hdr_size;
1530 /* Read Write HW register command */
1531 static void qlcnic_83xx_read_write_crb_reg(struct qlcnic_adapter *p_dev,
1532 u32 raddr, u32 waddr)
1536 value = qlcnic_83xx_rd_reg_indirect(p_dev, raddr);
1537 qlcnic_83xx_wrt_reg_indirect(p_dev, waddr, value);
1540 /* Read Modify Write HW register command */
1541 static void qlcnic_83xx_rmw_crb_reg(struct qlcnic_adapter *p_dev,
1542 u32 raddr, u32 waddr,
1543 struct qlc_83xx_rmw *p_rmw_hdr)
1547 if (p_rmw_hdr->index_a)
1548 value = p_dev->ahw->reset.array[p_rmw_hdr->index_a];
1550 value = qlcnic_83xx_rd_reg_indirect(p_dev, raddr);
1552 value &= p_rmw_hdr->mask;
1553 value <<= p_rmw_hdr->shl;
1554 value >>= p_rmw_hdr->shr;
1555 value |= p_rmw_hdr->or_value;
1556 value ^= p_rmw_hdr->xor_value;
1557 qlcnic_83xx_wrt_reg_indirect(p_dev, waddr, value);
1560 /* Write HW register command */
1561 static void qlcnic_83xx_write_list(struct qlcnic_adapter *p_dev,
1562 struct qlc_83xx_entry_hdr *p_hdr)
1565 struct qlc_83xx_entry *entry;
1567 entry = (struct qlc_83xx_entry *)((char *)p_hdr +
1568 sizeof(struct qlc_83xx_entry_hdr));
1570 for (i = 0; i < p_hdr->count; i++, entry++) {
1571 qlcnic_83xx_wrt_reg_indirect(p_dev, entry->arg1,
1574 udelay((u32)(p_hdr->delay));
1578 /* Read and Write instruction */
1579 static void qlcnic_83xx_read_write_list(struct qlcnic_adapter *p_dev,
1580 struct qlc_83xx_entry_hdr *p_hdr)
1583 struct qlc_83xx_entry *entry;
1585 entry = (struct qlc_83xx_entry *)((char *)p_hdr +
1586 sizeof(struct qlc_83xx_entry_hdr));
1588 for (i = 0; i < p_hdr->count; i++, entry++) {
1589 qlcnic_83xx_read_write_crb_reg(p_dev, entry->arg1,
1592 udelay((u32)(p_hdr->delay));
1596 /* Poll HW register command */
1597 static void qlcnic_83xx_poll_list(struct qlcnic_adapter *p_dev,
1598 struct qlc_83xx_entry_hdr *p_hdr)
1601 struct qlc_83xx_entry *entry;
1602 struct qlc_83xx_poll *poll;
1604 unsigned long arg1, arg2;
1606 poll = (struct qlc_83xx_poll *)((char *)p_hdr +
1607 sizeof(struct qlc_83xx_entry_hdr));
1609 entry = (struct qlc_83xx_entry *)((char *)poll +
1610 sizeof(struct qlc_83xx_poll));
1611 delay = (long)p_hdr->delay;
1614 for (i = 0; i < p_hdr->count; i++, entry++)
1615 qlcnic_83xx_poll_reg(p_dev, entry->arg1,
1619 for (i = 0; i < p_hdr->count; i++, entry++) {
1623 if (qlcnic_83xx_poll_reg(p_dev,
1627 qlcnic_83xx_rd_reg_indirect(p_dev,
1629 qlcnic_83xx_rd_reg_indirect(p_dev,
1637 /* Poll and write HW register command */
1638 static void qlcnic_83xx_poll_write_list(struct qlcnic_adapter *p_dev,
1639 struct qlc_83xx_entry_hdr *p_hdr)
1643 struct qlc_83xx_quad_entry *entry;
1644 struct qlc_83xx_poll *poll;
1646 poll = (struct qlc_83xx_poll *)((char *)p_hdr +
1647 sizeof(struct qlc_83xx_entry_hdr));
1648 entry = (struct qlc_83xx_quad_entry *)((char *)poll +
1649 sizeof(struct qlc_83xx_poll));
1650 delay = (long)p_hdr->delay;
1652 for (i = 0; i < p_hdr->count; i++, entry++) {
1653 qlcnic_83xx_wrt_reg_indirect(p_dev, entry->dr_addr,
1655 qlcnic_83xx_wrt_reg_indirect(p_dev, entry->ar_addr,
1658 qlcnic_83xx_poll_reg(p_dev, entry->ar_addr, delay,
1659 poll->mask, poll->status);
1663 /* Read Modify Write register command */
1664 static void qlcnic_83xx_read_modify_write(struct qlcnic_adapter *p_dev,
1665 struct qlc_83xx_entry_hdr *p_hdr)
1668 struct qlc_83xx_entry *entry;
1669 struct qlc_83xx_rmw *rmw_hdr;
1671 rmw_hdr = (struct qlc_83xx_rmw *)((char *)p_hdr +
1672 sizeof(struct qlc_83xx_entry_hdr));
1674 entry = (struct qlc_83xx_entry *)((char *)rmw_hdr +
1675 sizeof(struct qlc_83xx_rmw));
1677 for (i = 0; i < p_hdr->count; i++, entry++) {
1678 qlcnic_83xx_rmw_crb_reg(p_dev, entry->arg1,
1679 entry->arg2, rmw_hdr);
1681 udelay((u32)(p_hdr->delay));
1685 static void qlcnic_83xx_pause(struct qlc_83xx_entry_hdr *p_hdr)
1688 mdelay((u32)((long)p_hdr->delay));
1691 /* Read and poll register command */
1692 static void qlcnic_83xx_poll_read_list(struct qlcnic_adapter *p_dev,
1693 struct qlc_83xx_entry_hdr *p_hdr)
1697 struct qlc_83xx_quad_entry *entry;
1698 struct qlc_83xx_poll *poll;
1701 poll = (struct qlc_83xx_poll *)((char *)p_hdr +
1702 sizeof(struct qlc_83xx_entry_hdr));
1704 entry = (struct qlc_83xx_quad_entry *)((char *)poll +
1705 sizeof(struct qlc_83xx_poll));
1706 delay = (long)p_hdr->delay;
1708 for (i = 0; i < p_hdr->count; i++, entry++) {
1709 qlcnic_83xx_wrt_reg_indirect(p_dev, entry->ar_addr,
1712 if (!qlcnic_83xx_poll_reg(p_dev, entry->ar_addr, delay,
1713 poll->mask, poll->status)){
1714 index = p_dev->ahw->reset.array_index;
1715 addr = entry->dr_addr;
1716 j = qlcnic_83xx_rd_reg_indirect(p_dev, addr);
1717 p_dev->ahw->reset.array[index++] = j;
1719 if (index == QLC_83XX_MAX_RESET_SEQ_ENTRIES)
1720 p_dev->ahw->reset.array_index = 1;
1726 static inline void qlcnic_83xx_seq_end(struct qlcnic_adapter *p_dev)
1728 p_dev->ahw->reset.seq_end = 1;
1731 static void qlcnic_83xx_template_end(struct qlcnic_adapter *p_dev)
1733 p_dev->ahw->reset.template_end = 1;
1734 if (p_dev->ahw->reset.seq_error == 0)
1735 dev_err(&p_dev->pdev->dev,
1736 "HW restart process completed successfully.\n");
1738 dev_err(&p_dev->pdev->dev,
1739 "HW restart completed with timeout errors.\n");
1743 * qlcnic_83xx_exec_template_cmd
1745 * @p_dev: adapter structure
1746 * @p_buff: Poiter to instruction template
1748 * Template provides instructions to stop, restart and initalize firmware.
1749 * These instructions are abstracted as a series of read, write and
1750 * poll operations on hardware registers. Register information and operation
1751 * specifics are not exposed to the driver. Driver reads the template from
1752 * flash and executes the instructions located at pre-defined offsets.
1756 static void qlcnic_83xx_exec_template_cmd(struct qlcnic_adapter *p_dev,
1760 struct qlc_83xx_entry_hdr *p_hdr;
1761 char *entry = p_buff;
1763 p_dev->ahw->reset.seq_end = 0;
1764 p_dev->ahw->reset.template_end = 0;
1765 entries = p_dev->ahw->reset.hdr->entries;
1766 index = p_dev->ahw->reset.seq_index;
1768 for (; (!p_dev->ahw->reset.seq_end) && (index < entries); index++) {
1769 p_hdr = (struct qlc_83xx_entry_hdr *)entry;
1771 switch (p_hdr->cmd) {
1772 case QLC_83XX_OPCODE_NOP:
1774 case QLC_83XX_OPCODE_WRITE_LIST:
1775 qlcnic_83xx_write_list(p_dev, p_hdr);
1777 case QLC_83XX_OPCODE_READ_WRITE_LIST:
1778 qlcnic_83xx_read_write_list(p_dev, p_hdr);
1780 case QLC_83XX_OPCODE_POLL_LIST:
1781 qlcnic_83xx_poll_list(p_dev, p_hdr);
1783 case QLC_83XX_OPCODE_POLL_WRITE_LIST:
1784 qlcnic_83xx_poll_write_list(p_dev, p_hdr);
1786 case QLC_83XX_OPCODE_READ_MODIFY_WRITE:
1787 qlcnic_83xx_read_modify_write(p_dev, p_hdr);
1789 case QLC_83XX_OPCODE_SEQ_PAUSE:
1790 qlcnic_83xx_pause(p_hdr);
1792 case QLC_83XX_OPCODE_SEQ_END:
1793 qlcnic_83xx_seq_end(p_dev);
1795 case QLC_83XX_OPCODE_TMPL_END:
1796 qlcnic_83xx_template_end(p_dev);
1798 case QLC_83XX_OPCODE_POLL_READ_LIST:
1799 qlcnic_83xx_poll_read_list(p_dev, p_hdr);
1802 dev_err(&p_dev->pdev->dev,
1803 "%s: Unknown opcode 0x%04x in template %d\n",
1804 __func__, p_hdr->cmd, index);
1807 entry += p_hdr->size;
1809 p_dev->ahw->reset.seq_index = index;
1812 static void qlcnic_83xx_stop_hw(struct qlcnic_adapter *p_dev)
1814 p_dev->ahw->reset.seq_index = 0;
1816 qlcnic_83xx_exec_template_cmd(p_dev, p_dev->ahw->reset.stop_offset);
1817 if (p_dev->ahw->reset.seq_end != 1)
1818 dev_err(&p_dev->pdev->dev, "%s: failed\n", __func__);
1821 static void qlcnic_83xx_start_hw(struct qlcnic_adapter *p_dev)
1823 qlcnic_83xx_exec_template_cmd(p_dev, p_dev->ahw->reset.start_offset);
1824 if (p_dev->ahw->reset.template_end != 1)
1825 dev_err(&p_dev->pdev->dev, "%s: failed\n", __func__);
1828 static void qlcnic_83xx_init_hw(struct qlcnic_adapter *p_dev)
1830 qlcnic_83xx_exec_template_cmd(p_dev, p_dev->ahw->reset.init_offset);
1831 if (p_dev->ahw->reset.seq_end != 1)
1832 dev_err(&p_dev->pdev->dev, "%s: failed\n", __func__);
1835 static int qlcnic_83xx_load_fw_image_from_host(struct qlcnic_adapter *adapter)
1839 if (request_firmware(&adapter->ahw->fw_info.fw,
1840 QLC_83XX_FW_FILE_NAME, &(adapter->pdev->dev))) {
1841 dev_err(&adapter->pdev->dev,
1842 "No file FW image, loading flash FW image.\n");
1843 QLC_SHARED_REG_WR32(adapter, QLCNIC_FW_IMG_VALID,
1844 QLC_83XX_BOOT_FROM_FLASH);
1846 if (qlcnic_83xx_copy_fw_file(adapter))
1848 QLC_SHARED_REG_WR32(adapter, QLCNIC_FW_IMG_VALID,
1849 QLC_83XX_BOOT_FROM_FILE);
1855 static int qlcnic_83xx_restart_hw(struct qlcnic_adapter *adapter)
1860 qlcnic_83xx_stop_hw(adapter);
1862 /* Collect FW register dump if required */
1863 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1864 if (!(val & QLC_83XX_IDC_GRACEFULL_RESET))
1865 qlcnic_dump_fw(adapter);
1866 qlcnic_83xx_init_hw(adapter);
1868 if (qlcnic_83xx_copy_bootloader(adapter))
1870 /* Boot either flash image or firmware image from host file system */
1871 if (qlcnic_load_fw_file) {
1872 if (qlcnic_83xx_load_fw_image_from_host(adapter))
1875 QLC_SHARED_REG_WR32(adapter, QLCNIC_FW_IMG_VALID,
1876 QLC_83XX_BOOT_FROM_FLASH);
1879 qlcnic_83xx_start_hw(adapter);
1880 if (qlcnic_83xx_check_hw_status(adapter))
1887 * qlcnic_83xx_config_default_opmode
1889 * @adapter: adapter structure
1891 * Configure default driver operating mode
1893 * Returns: Error code or Success(0)
1895 int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
1898 struct qlcnic_hardware_context *ahw = adapter->ahw;
1900 qlcnic_get_func_no(adapter);
1901 op_mode = QLCRDX(ahw, QLC_83XX_DRV_OP_MODE);
1903 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
1904 adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
1905 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
1913 int qlcnic_83xx_get_nic_configuration(struct qlcnic_adapter *adapter)
1916 struct qlcnic_info nic_info;
1917 struct qlcnic_hardware_context *ahw = adapter->ahw;
1919 memset(&nic_info, 0, sizeof(struct qlcnic_info));
1920 err = qlcnic_get_nic_info(adapter, &nic_info, ahw->pci_func);
1924 ahw->physical_port = (u8) nic_info.phys_port;
1925 ahw->switch_mode = nic_info.switch_mode;
1926 ahw->max_tx_ques = nic_info.max_tx_ques;
1927 ahw->max_rx_ques = nic_info.max_rx_ques;
1928 ahw->capabilities = nic_info.capabilities;
1929 ahw->max_mac_filters = nic_info.max_mac_filters;
1930 ahw->max_mtu = nic_info.max_mtu;
1932 if (ahw->capabilities & BIT_23)
1933 ahw->nic_mode = QLC_83XX_VIRTUAL_NIC_MODE;
1935 ahw->nic_mode = QLC_83XX_DEFAULT_MODE;
1937 return ahw->nic_mode;
1940 static int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
1944 ret = qlcnic_83xx_get_nic_configuration(adapter);
1948 if (ret == QLC_83XX_VIRTUAL_NIC_MODE) {
1949 if (qlcnic_83xx_config_vnic_opmode(adapter))
1951 } else if (ret == QLC_83XX_DEFAULT_MODE) {
1952 if (qlcnic_83xx_config_default_opmode(adapter))
1959 static void qlcnic_83xx_config_buff_descriptors(struct qlcnic_adapter *adapter)
1961 struct qlcnic_hardware_context *ahw = adapter->ahw;
1963 if (ahw->port_type == QLCNIC_XGBE) {
1964 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
1965 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
1966 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
1967 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
1969 } else if (ahw->port_type == QLCNIC_GBE) {
1970 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
1971 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
1972 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
1973 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
1975 adapter->num_txd = MAX_CMD_DESCRIPTORS;
1976 adapter->max_rds_rings = MAX_RDS_RINGS;
1979 static int qlcnic_83xx_init_default_driver(struct qlcnic_adapter *adapter)
1983 qlcnic_83xx_get_minidump_template(adapter);
1984 if (qlcnic_83xx_get_port_info(adapter))
1987 qlcnic_83xx_config_buff_descriptors(adapter);
1988 adapter->ahw->msix_supported = !!qlcnic_use_msi_x;
1989 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
1991 dev_info(&adapter->pdev->dev, "HAL Version: %d\n",
1992 adapter->ahw->fw_hal_version);
1997 #define IS_QLC_83XX_USED(a, b, c) (((1 << a->portnum) & b) || ((c >> 6) & 0x1))
1998 static void qlcnic_83xx_clear_function_resources(struct qlcnic_adapter *adapter)
2000 struct qlcnic_cmd_args cmd;
2001 u32 presence_mask, audit_mask;
2004 presence_mask = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_PRESENCE);
2005 audit_mask = QLCRDX(adapter->ahw, QLC_83XX_IDC_DRV_AUDIT);
2007 if (IS_QLC_83XX_USED(adapter, presence_mask, audit_mask)) {
2008 qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_STOP_NIC_FUNC);
2009 cmd.req.arg[1] = BIT_31;
2010 status = qlcnic_issue_cmd(adapter, &cmd);
2012 dev_err(&adapter->pdev->dev,
2013 "Failed to clean up the function resources\n");
2014 qlcnic_free_mbx_args(&cmd);
2018 int qlcnic_83xx_init(struct qlcnic_adapter *adapter)
2020 struct qlcnic_hardware_context *ahw = adapter->ahw;
2022 if (qlcnic_83xx_check_hw_status(adapter))
2025 /* Initilaize 83xx mailbox spinlock */
2026 spin_lock_init(&ahw->mbx_lock);
2028 set_bit(QLC_83XX_MBX_READY, &adapter->ahw->idc.status);
2029 qlcnic_83xx_clear_function_resources(adapter);
2031 /* register for NIC IDC AEN Events */
2032 qlcnic_83xx_register_nic_idc_func(adapter, 1);
2034 if (!qlcnic_83xx_read_flash_descriptor_table(adapter))
2035 qlcnic_83xx_read_flash_mfg_id(adapter);
2037 if (qlcnic_83xx_idc_init(adapter))
2040 /* Configure default, SR-IOV or Virtual NIC mode of operation */
2041 if (qlcnic_83xx_configure_opmode(adapter))
2044 /* Perform operating mode specific initialization */
2045 if (adapter->nic_ops->init_driver(adapter))
2048 INIT_DELAYED_WORK(&adapter->idc_aen_work, qlcnic_83xx_idc_aen_work);
2050 /* Periodically monitor device status */
2051 qlcnic_83xx_idc_poll_dev_state(&adapter->fw_work.work);
2053 return adapter->ahw->idc.err_code;