Lines Matching refs:adapter
20 static void leapraid_remove_device(struct leapraid_adapter *adapter,
22 static void leapraid_set_led(struct leapraid_adapter *adapter,
24 static void leapraid_ublk_io_dev(struct leapraid_adapter *adapter,
27 static void leapraid_clear_cached_boot_dev(struct leapraid_adapter *adapter,
29 static int leapraid_make_adapter_available(struct leapraid_adapter *adapter);
30 static void leapraid_sync_irqs_for_cleanup(struct leapraid_adapter *adapter);
31 static int leapraid_fw_log_init(struct leapraid_adapter *adapter);
32 static bool leapraid_should_skip_poll_work(struct leapraid_adapter *adapter);
33 static int leapraid_make_adapter_ready(struct leapraid_adapter *adapter,
55 bool leapraid_pci_removed(struct leapraid_adapter *adapter) in leapraid_pci_removed() argument
57 struct pci_dev *pdev = adapter->pdev; in leapraid_pci_removed()
70 static bool leapraid_pci_active(struct leapraid_adapter *adapter) in leapraid_pci_active() argument
72 return !(adapter->access_ctrl.pcie_recovering || in leapraid_pci_active()
73 leapraid_pci_removed(adapter)); in leapraid_pci_active()
76 void *leapraid_get_reply_vaddr(struct leapraid_adapter *adapter, u32 rep_paddr) in leapraid_get_reply_vaddr() argument
81 return adapter->mem_desc.rep_msg + in leapraid_get_reply_vaddr()
82 (rep_paddr - (u32)adapter->mem_desc.rep_msg_dma); in leapraid_get_reply_vaddr()
85 void *leapraid_get_task_desc(struct leapraid_adapter *adapter, u16 taskid) in leapraid_get_task_desc() argument
87 return adapter->mem_desc.task_desc + in leapraid_get_task_desc()
91 void *leapraid_get_sense_buffer(struct leapraid_adapter *adapter, u16 taskid) in leapraid_get_sense_buffer() argument
93 return adapter->mem_desc.sense_data + in leapraid_get_sense_buffer()
97 __le32 leapraid_get_sense_buffer_dma(struct leapraid_adapter *adapter, in leapraid_get_sense_buffer_dma() argument
100 return cpu_to_le32(adapter->mem_desc.sense_data_dma + in leapraid_get_sense_buffer_dma()
104 void leapraid_mask_int(struct leapraid_adapter *adapter) in leapraid_mask_int() argument
108 adapter->mask_int = 1; in leapraid_mask_int()
109 reg = leapraid_readl(&adapter->iomem_base->host_int_mask); in leapraid_mask_int()
112 writel(reg, &adapter->iomem_base->host_int_mask); in leapraid_mask_int()
113 leapraid_readl(&adapter->iomem_base->host_int_mask); in leapraid_mask_int()
116 void leapraid_unmask_int(struct leapraid_adapter *adapter) in leapraid_unmask_int() argument
120 reg = leapraid_readl(&adapter->iomem_base->host_int_mask); in leapraid_unmask_int()
122 writel(reg, &adapter->iomem_base->host_int_mask); in leapraid_unmask_int()
123 adapter->mask_int = 0; in leapraid_unmask_int()
126 static void leapraid_overheat_suspend(struct leapraid_adapter *adapter) in leapraid_overheat_suspend() argument
132 if (!adapter) in leapraid_overheat_suspend()
135 pdev = adapter->pdev; in leapraid_overheat_suspend()
143 wq = adapter->overheat_desc.fault_overheat_wq; in leapraid_overheat_suspend()
147 if (atomic_cmpxchg(&adapter->overheat_desc.thermal_alert, 0, 1)) in leapraid_overheat_suspend()
150 queue_work(wq, &adapter->overheat_desc.fault_overheat_work); in leapraid_overheat_suspend()
153 static void leapraid_stop_adapter_on_fault(struct leapraid_adapter *adapter, in leapraid_stop_adapter_on_fault() argument
168 dev_err(&adapter->pdev->dev, in leapraid_stop_adapter_on_fault()
171 dev_err(&adapter->pdev->dev, in leapraid_stop_adapter_on_fault()
174 leapraid_overheat_suspend(adapter); in leapraid_stop_adapter_on_fault()
177 u32 leapraid_get_adapter_state(struct leapraid_adapter *adapter) in leapraid_get_adapter_state() argument
182 db = leapraid_readl(&adapter->iomem_base->db); in leapraid_get_adapter_state()
184 leapraid_stop_adapter_on_fault(adapter, db); in leapraid_get_adapter_state()
188 static bool leapraid_wait_adapter_ready(struct leapraid_adapter *adapter) in leapraid_wait_adapter_ready() argument
194 cur_state = leapraid_get_adapter_state(adapter); in leapraid_wait_adapter_ready()
207 static int leapraid_db_wait_int_host(struct leapraid_adapter *adapter) in leapraid_db_wait_int_host() argument
212 if (leapraid_readl(&adapter->iomem_base->host_int_status) & in leapraid_db_wait_int_host()
222 static int leapraid_db_wait_ack_and_clear_int(struct leapraid_adapter *adapter) in leapraid_db_wait_ack_and_clear_int() argument
230 leapraid_readl(&adapter->iomem_base->host_int_status); in leapraid_db_wait_ack_and_clear_int()
239 adapter_state = leapraid_get_adapter_state(adapter); in leapraid_db_wait_ack_and_clear_int()
251 static int leapraid_handshake_func(struct leapraid_adapter *adapter, in leapraid_handshake_func() argument
257 if (leapraid_readl(&adapter->iomem_base->db) & LEAPRAID_DB_USED) { in leapraid_handshake_func()
258 dev_err(&adapter->pdev->dev, "doorbell used\n"); in leapraid_handshake_func()
262 if (leapraid_readl(&adapter->iomem_base->host_int_status) & in leapraid_handshake_func()
264 writel(0, &adapter->iomem_base->host_int_status); in leapraid_handshake_func()
269 &adapter->iomem_base->db); in leapraid_handshake_func()
271 if (leapraid_db_wait_int_host(adapter)) { in leapraid_handshake_func()
272 dev_err(&adapter->pdev->dev, "%d: Wait db interrupt timeout\n", in leapraid_handshake_func()
277 writel(0, &adapter->iomem_base->host_int_status); in leapraid_handshake_func()
279 if (leapraid_db_wait_ack_and_clear_int(adapter)) { in leapraid_handshake_func()
280 dev_err(&adapter->pdev->dev, "%d: Wait ack failure\n", in leapraid_handshake_func()
288 writel((u32)req[i], &adapter->iomem_base->db); in leapraid_handshake_func()
289 if (leapraid_db_wait_ack_and_clear_int(adapter)) in leapraid_handshake_func()
293 dev_err(&adapter->pdev->dev, "%d: Wait ack failure\n", in leapraid_handshake_func()
299 if (leapraid_db_wait_int_host(adapter)) { in leapraid_handshake_func()
300 dev_err(&adapter->pdev->dev, in leapraid_handshake_func()
304 rep[i] = (u16)(leapraid_readl(&adapter->iomem_base->db) in leapraid_handshake_func()
306 writel(0, &adapter->iomem_base->host_int_status); in leapraid_handshake_func()
309 if (leapraid_db_wait_int_host(adapter)) { in leapraid_handshake_func()
310 dev_err(&adapter->pdev->dev, "%d: Wait db interrupt timeout\n", in leapraid_handshake_func()
315 writel(0, &adapter->iomem_base->host_int_status); in leapraid_handshake_func()
320 int leapraid_check_adapter_is_op(struct leapraid_adapter *adapter, int wait, in leapraid_check_adapter_is_op() argument
326 if (READ_ONCE(adapter->access_ctrl.host_removing)) { in leapraid_check_adapter_is_op()
327 dev_warn(&adapter->pdev->dev, in leapraid_check_adapter_is_op()
332 if (leapraid_pci_removed(adapter)) { in leapraid_check_adapter_is_op()
333 dev_warn(&adapter->pdev->dev, in leapraid_check_adapter_is_op()
338 if (leapraid_get_adapter_state(adapter) == in leapraid_check_adapter_is_op()
342 dev_dbg(&adapter->pdev->dev, in leapraid_check_adapter_is_op()
349 dev_err(&adapter->pdev->dev, in leapraid_check_adapter_is_op()
351 caller, leapraid_get_adapter_state(adapter)); in leapraid_check_adapter_is_op()
357 struct leapraid_adapter *adapter, u16 taskid) in leapraid_get_io_tracker_from_taskid() argument
364 if (WARN_ON(taskid > adapter->shost->can_queue)) in leapraid_get_io_tracker_from_taskid()
367 scmd = leapraid_get_scmd_from_taskid(adapter, taskid); in leapraid_get_io_tracker_from_taskid()
374 static u8 leapraid_get_cb_idx(struct leapraid_adapter *adapter, u16 taskid) in leapraid_get_cb_idx() argument
382 list_for_each_entry(sp_cmd, &adapter->driver_cmds.special_cmd_list, in leapraid_get_cb_idx()
394 struct leapraid_adapter *adapter, in leapraid_get_scmd_from_taskid() argument
402 if (taskid <= 0 || taskid > adapter->shost->can_queue) in leapraid_get_scmd_from_taskid()
405 uniq_tag = adapter->mem_desc.taskid_to_uniq_tag[taskid - 1] << in leapraid_get_scmd_from_taskid()
407 leap_mpi_req = leapraid_get_task_desc(adapter, taskid); in leapraid_get_scmd_from_taskid()
411 scmd = scsi_host_find_tag(adapter->shost, uniq_tag); in leapraid_get_scmd_from_taskid()
421 u16 leapraid_alloc_scsiio_taskid(struct leapraid_adapter *adapter, in leapraid_alloc_scsiio_taskid() argument
431 adapter->mem_desc.taskid_to_uniq_tag[tag] = in leapraid_alloc_scsiio_taskid()
441 static void leapraid_check_pending_io(struct leapraid_adapter *adapter) in leapraid_check_pending_io() argument
443 if (adapter->access_ctrl.shost_recovering && in leapraid_check_pending_io()
444 adapter->reset_desc.pending_io_cnt) { in leapraid_check_pending_io()
445 if (adapter->reset_desc.pending_io_cnt == 1) in leapraid_check_pending_io()
446 wake_up(&adapter->reset_desc.reset_wait_queue); in leapraid_check_pending_io()
447 adapter->reset_desc.pending_io_cnt--; in leapraid_check_pending_io()
452 struct leapraid_adapter *adapter, in leapraid_clear_io_tracker() argument
464 static bool leapraid_is_fixed_taskid(struct leapraid_adapter *adapter, in leapraid_is_fixed_taskid() argument
467 struct leapraid_driver_cmds *driver_cmds = &adapter->driver_cmds; in leapraid_is_fixed_taskid()
479 void leapraid_free_taskid(struct leapraid_adapter *adapter, u16 taskid) in leapraid_free_taskid() argument
484 if (leapraid_is_fixed_taskid(adapter, taskid)) in leapraid_free_taskid()
487 if (taskid <= adapter->shost->can_queue) { in leapraid_free_taskid()
488 io_tracker = leapraid_get_io_tracker_from_taskid(adapter, in leapraid_free_taskid()
491 leapraid_check_pending_io(adapter); in leapraid_free_taskid()
495 task_desc = leapraid_get_task_desc(adapter, taskid); in leapraid_free_taskid()
497 leapraid_clear_io_tracker(adapter, io_tracker); in leapraid_free_taskid()
498 leapraid_check_pending_io(adapter); in leapraid_free_taskid()
499 adapter->mem_desc.taskid_to_uniq_tag[taskid - 1] = 0xFFFF; in leapraid_free_taskid()
503 static u8 leapraid_get_msix_idx(struct leapraid_adapter *adapter, in leapraid_get_msix_idx() argument
506 if (scmd && adapter->shost->nr_hw_queues > 1) { in leapraid_get_msix_idx()
511 return adapter->notification_desc.msix_cpu_map[raw_smp_processor_id()]; in leapraid_get_msix_idx()
515 struct leapraid_adapter *adapter, u16 taskid) in leapraid_get_and_set_msix_idx_from_taskid() argument
519 if (taskid <= adapter->shost->can_queue) in leapraid_get_and_set_msix_idx_from_taskid()
520 io_tracker = leapraid_get_io_tracker_from_taskid(adapter, in leapraid_get_and_set_msix_idx_from_taskid()
524 return leapraid_get_msix_idx(adapter, NULL); in leapraid_get_and_set_msix_idx_from_taskid()
526 io_tracker->msix_io = leapraid_get_msix_idx(adapter, io_tracker->scmd); in leapraid_get_and_set_msix_idx_from_taskid()
531 void leapraid_fire_scsi_io(struct leapraid_adapter *adapter, u16 taskid, in leapraid_fire_scsi_io() argument
537 desc.msix_idx = leapraid_get_and_set_msix_idx_from_taskid(adapter, in leapraid_fire_scsi_io()
541 &adapter->iomem_base->atomic_req_desc_post); in leapraid_fire_scsi_io()
544 void leapraid_fire_hpr_task(struct leapraid_adapter *adapter, u16 taskid, in leapraid_fire_hpr_task() argument
553 &adapter->iomem_base->atomic_req_desc_post); in leapraid_fire_hpr_task()
556 void leapraid_fire_task(struct leapraid_adapter *adapter, u16 taskid) in leapraid_fire_task() argument
561 desc.msix_idx = leapraid_get_and_set_msix_idx_from_taskid(adapter, in leapraid_fire_task()
565 &adapter->iomem_base->atomic_req_desc_post); in leapraid_fire_task()
568 void leapraid_clean_active_scsi_cmds(struct leapraid_adapter *adapter) in leapraid_clean_active_scsi_cmds() argument
575 leapraid_sync_irqs_for_cleanup(adapter); in leapraid_clean_active_scsi_cmds()
577 for (taskid = 1; taskid <= adapter->shost->can_queue; taskid++) { in leapraid_clean_active_scsi_cmds()
578 scmd = leapraid_get_scmd_from_taskid(adapter, taskid); in leapraid_clean_active_scsi_cmds()
587 task_desc = leapraid_get_task_desc(adapter, taskid); in leapraid_clean_active_scsi_cmds()
589 leapraid_clear_io_tracker(adapter, io_tracker); in leapraid_clean_active_scsi_cmds()
590 if (!leapraid_pci_active(adapter) || in leapraid_clean_active_scsi_cmds()
591 adapter->reset_desc.adapter_reset_results != 0 || in leapraid_clean_active_scsi_cmds()
592 atomic_read(&adapter->overheat_desc.thermal_alert) || in leapraid_clean_active_scsi_cmds()
593 adapter->access_ctrl.host_removing) in leapraid_clean_active_scsi_cmds()
609 static void leapraid_clean_active_driver_cmds(struct leapraid_adapter *adapter) in leapraid_clean_active_driver_cmds() argument
613 driver_cmds = &adapter->driver_cmds; in leapraid_clean_active_driver_cmds()
622 adapter->scan_dev_desc.scan_dev_failed = 1; in leapraid_clean_active_driver_cmds()
624 if (adapter->scan_dev_desc.driver_loading) { in leapraid_clean_active_driver_cmds()
625 adapter->scan_dev_desc.scan_start_failed = in leapraid_clean_active_driver_cmds()
627 adapter->scan_dev_desc.scan_start = 0; in leapraid_clean_active_driver_cmds()
634 static void leapraid_clean_active_cmds(struct leapraid_adapter *adapter) in leapraid_clean_active_cmds() argument
636 leapraid_clean_active_driver_cmds(adapter); in leapraid_clean_active_cmds()
637 leapraid_clean_active_fw_evt(adapter); in leapraid_clean_active_cmds()
638 leapraid_clean_active_scsi_cmds(adapter); in leapraid_clean_active_cmds()
641 static void leapraid_tgt_not_responding(struct leapraid_adapter *adapter, in leapraid_tgt_not_responding() argument
649 if (adapter->access_ctrl.pcie_recovering) in leapraid_tgt_not_responding()
652 adapter_state = leapraid_get_adapter_state(adapter); in leapraid_tgt_not_responding()
656 if (!hdl || hdl > adapter->adapter_attr.features.max_dev_handle || in leapraid_tgt_not_responding()
657 test_bit(hdl, adapter->dev_topo.pd_hdls)) in leapraid_tgt_not_responding()
660 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_tgt_not_responding()
661 sas_dev = leapraid_hold_lock_get_sas_dev_by_hdl(adapter, hdl); in leapraid_tgt_not_responding()
666 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_tgt_not_responding()
675 static void leapraid_tgt_rst_send(struct leapraid_adapter *adapter, u16 hdl) in leapraid_tgt_rst_send() argument
684 if (adapter->access_ctrl.pcie_recovering) in leapraid_tgt_rst_send()
687 adapter_state = leapraid_get_adapter_state(adapter); in leapraid_tgt_rst_send()
691 if (!hdl || hdl > adapter->adapter_attr.features.max_dev_handle || in leapraid_tgt_rst_send()
692 test_bit(hdl, adapter->dev_topo.pd_hdls)) in leapraid_tgt_rst_send()
695 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_tgt_rst_send()
696 sas_dev = leapraid_hold_lock_get_sas_dev_by_hdl(adapter, hdl); in leapraid_tgt_rst_send()
703 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_tgt_rst_send()
706 leapraid_ublk_io_dev(adapter, sas_address, port); in leapraid_tgt_rst_send()
714 struct leapraid_adapter *adapter, in leapraid_single_mpi_sg_append() argument
719 if (adapter->adapter_attr.use_32_dma_mask) { in leapraid_single_mpi_sg_append()
753 static void leapraid_build_nodata_mpi_sg(struct leapraid_adapter *adapter, in leapraid_build_nodata_mpi_sg() argument
756 leapraid_single_mpi_sg_append(adapter, in leapraid_build_nodata_mpi_sg()
766 void leapraid_build_mpi_sg(struct leapraid_adapter *adapter, void *sge, in leapraid_build_mpi_sg() argument
771 leapraid_single_mpi_sg_append(adapter, in leapraid_build_mpi_sg()
782 leapraid_single_mpi_sg_append(adapter, in leapraid_build_mpi_sg()
792 leapraid_single_mpi_sg_append(adapter, in leapraid_build_mpi_sg()
800 if (adapter->adapter_attr.use_32_dma_mask) in leapraid_build_mpi_sg()
804 leapraid_single_mpi_sg_append(adapter, in leapraid_build_mpi_sg()
814 leapraid_build_nodata_mpi_sg(adapter, sge); in leapraid_build_mpi_sg()
818 void leapraid_build_ieee_nodata_sg(struct leapraid_adapter *adapter, void *sge) in leapraid_build_ieee_nodata_sg() argument
829 int leapraid_build_scmd_ieee_sg(struct leapraid_adapter *adapter, in leapraid_build_scmd_ieee_sg() argument
845 scsiio_req = leapraid_get_task_desc(adapter, taskid); in leapraid_build_scmd_ieee_sg()
927 void leapraid_build_ieee_sg(struct leapraid_adapter *adapter, void *sge, in leapraid_build_ieee_sg() argument
968 leapraid_build_ieee_nodata_sg(adapter, sge); in leapraid_build_ieee_sg()
973 struct leapraid_adapter *adapter, in leapraid_hold_lock_get_sas_dev_from_tgt() argument
976 assert_spin_locked(&adapter->dev_topo.sas_dev_lock); in leapraid_hold_lock_get_sas_dev_from_tgt()
984 struct leapraid_adapter *adapter, in leapraid_get_sas_dev_from_tgt() argument
990 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_get_sas_dev_from_tgt()
991 sas_dev = leapraid_hold_lock_get_sas_dev_from_tgt(adapter, tgt_priv); in leapraid_get_sas_dev_from_tgt()
992 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_get_sas_dev_from_tgt()
997 struct leapraid_adapter *adapter, in leapraid_get_port_by_id() argument
1003 if (!adapter->adapter_attr.enable_mp) in leapraid_get_port_by_id()
1006 list_for_each_entry(port, &adapter->dev_topo.card_port_list, list) { in leapraid_get_port_by_id()
1020 if (unlikely(!adapter->adapter_attr.enable_mp)) { in leapraid_get_port_by_id()
1023 dev_warn(&adapter->pdev->dev, in leapraid_get_port_by_id()
1029 list_add_tail(&port->list, &adapter->dev_topo.card_port_list); in leapraid_get_port_by_id()
1053 struct leapraid_adapter *adapter, in leapraid_hold_lock_get_sas_dev_by_addr_and_rphy() argument
1059 assert_spin_locked(&adapter->dev_topo.sas_dev_lock); in leapraid_hold_lock_get_sas_dev_by_addr_and_rphy()
1060 list_for_each_entry(sas_dev, &adapter->dev_topo.sas_dev_list, list) in leapraid_hold_lock_get_sas_dev_by_addr_and_rphy()
1067 list_for_each_entry(sas_dev, &adapter->dev_topo.sas_dev_init_list, in leapraid_hold_lock_get_sas_dev_by_addr_and_rphy()
1079 struct leapraid_adapter *adapter, in leapraid_hold_lock_get_sas_dev_by_addr() argument
1085 dev_warn(&adapter->pdev->dev, "%s: Invalid port\n", __func__); in leapraid_hold_lock_get_sas_dev_by_addr()
1089 assert_spin_locked(&adapter->dev_topo.sas_dev_lock); in leapraid_hold_lock_get_sas_dev_by_addr()
1090 list_for_each_entry(sas_dev, &adapter->dev_topo.sas_dev_list, list) in leapraid_hold_lock_get_sas_dev_by_addr()
1097 list_for_each_entry(sas_dev, &adapter->dev_topo.sas_dev_init_list, in leapraid_hold_lock_get_sas_dev_by_addr()
1109 struct leapraid_adapter *adapter, in leapraid_get_sas_dev_by_addr() argument
1116 dev_warn(&adapter->pdev->dev, "%s: Invalid port\n", __func__); in leapraid_get_sas_dev_by_addr()
1120 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_get_sas_dev_by_addr()
1121 sas_dev = leapraid_hold_lock_get_sas_dev_by_addr(adapter, sas_address, in leapraid_get_sas_dev_by_addr()
1123 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_get_sas_dev_by_addr()
1128 struct leapraid_adapter *adapter, u16 hdl) in leapraid_hold_lock_get_sas_dev_by_hdl() argument
1132 assert_spin_locked(&adapter->dev_topo.sas_dev_lock); in leapraid_hold_lock_get_sas_dev_by_hdl()
1133 list_for_each_entry(sas_dev, &adapter->dev_topo.sas_dev_list, list) in leapraid_hold_lock_get_sas_dev_by_hdl()
1139 list_for_each_entry(sas_dev, &adapter->dev_topo.sas_dev_init_list, in leapraid_hold_lock_get_sas_dev_by_hdl()
1150 struct leapraid_adapter *adapter, u16 hdl) in leapraid_get_sas_dev_by_hdl() argument
1155 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_get_sas_dev_by_hdl()
1156 sas_dev = leapraid_hold_lock_get_sas_dev_by_hdl(adapter, hdl); in leapraid_get_sas_dev_by_hdl()
1157 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_get_sas_dev_by_hdl()
1161 void leapraid_sas_dev_remove(struct leapraid_adapter *adapter, in leapraid_sas_dev_remove() argument
1168 dev_warn(&adapter->pdev->dev, in leapraid_sas_dev_remove()
1174 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_sas_dev_remove()
1179 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_sas_dev_remove()
1182 leapraid_clear_cached_boot_dev(adapter, sas_dev, 0); in leapraid_sas_dev_remove()
1187 static void leapraid_sas_dev_remove_by_hdl(struct leapraid_adapter *adapter, in leapraid_sas_dev_remove_by_hdl() argument
1194 if (adapter->access_ctrl.shost_recovering) in leapraid_sas_dev_remove_by_hdl()
1198 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_sas_dev_remove_by_hdl()
1199 sas_dev = leapraid_hold_lock_get_sas_dev_by_hdl(adapter, hdl); in leapraid_sas_dev_remove_by_hdl()
1205 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_sas_dev_remove_by_hdl()
1208 leapraid_remove_device(adapter, sas_dev); in leapraid_sas_dev_remove_by_hdl()
1213 void leapraid_sas_dev_remove_by_sas_address(struct leapraid_adapter *adapter, in leapraid_sas_dev_remove_by_sas_address() argument
1221 if (adapter->access_ctrl.shost_recovering) in leapraid_sas_dev_remove_by_sas_address()
1225 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_sas_dev_remove_by_sas_address()
1226 sas_dev = leapraid_hold_lock_get_sas_dev_by_addr(adapter, sas_address, in leapraid_sas_dev_remove_by_sas_address()
1233 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_sas_dev_remove_by_sas_address()
1236 leapraid_remove_device(adapter, sas_dev); in leapraid_sas_dev_remove_by_sas_address()
1242 struct leapraid_adapter *adapter, uint id, uint channel) in leapraid_raid_volume_find_by_id() argument
1247 spin_lock_irqsave(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_raid_volume_find_by_id()
1248 list_for_each_entry(raid_volume, &adapter->dev_topo.raid_volume_list, in leapraid_raid_volume_find_by_id()
1253 &adapter->dev_topo.raid_volume_lock, flags); in leapraid_raid_volume_find_by_id()
1257 spin_unlock_irqrestore(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_raid_volume_find_by_id()
1263 struct leapraid_adapter *adapter, u16 hdl) in leapraid_raid_volume_find_by_hdl() argument
1268 spin_lock_irqsave(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_raid_volume_find_by_hdl()
1269 list_for_each_entry(raid_volume, &adapter->dev_topo.raid_volume_list, in leapraid_raid_volume_find_by_hdl()
1274 &adapter->dev_topo.raid_volume_lock, flags); in leapraid_raid_volume_find_by_hdl()
1278 spin_unlock_irqrestore(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_raid_volume_find_by_hdl()
1284 struct leapraid_adapter *adapter, u64 wwid) in leapraid_raid_volume_find_by_wwid() argument
1289 spin_lock_irqsave(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_raid_volume_find_by_wwid()
1290 list_for_each_entry(raid_volume, &adapter->dev_topo.raid_volume_list, in leapraid_raid_volume_find_by_wwid()
1295 &adapter->dev_topo.raid_volume_lock, flags); in leapraid_raid_volume_find_by_wwid()
1299 spin_unlock_irqrestore(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_raid_volume_find_by_wwid()
1304 static void leapraid_raid_volume_add(struct leapraid_adapter *adapter, in leapraid_raid_volume_add() argument
1309 spin_lock_irqsave(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_raid_volume_add()
1311 list_add_tail(&raid_volume->list, &adapter->dev_topo.raid_volume_list); in leapraid_raid_volume_add()
1312 spin_unlock_irqrestore(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_raid_volume_add()
1315 void leapraid_raid_volume_remove(struct leapraid_adapter *adapter, in leapraid_raid_volume_remove() argument
1322 dev_warn(&adapter->pdev->dev, in leapraid_raid_volume_remove()
1327 spin_lock_irqsave(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_raid_volume_remove()
1332 spin_unlock_irqrestore(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_raid_volume_remove()
1334 leapraid_clear_cached_boot_dev(adapter, raid_volume, RAID_CHANNEL); in leapraid_raid_volume_remove()
1340 struct leapraid_adapter *adapter, u16 hdl) in leapraid_enc_find_by_hdl() argument
1344 list_for_each_entry(enc_dev, &adapter->dev_topo.enc_list, list) in leapraid_enc_find_by_hdl()
1352 struct leapraid_adapter *adapter, in leapraid_exp_find_by_sas_address() argument
1358 dev_warn(&adapter->pdev->dev, "%s: Invalid port\n", __func__); in leapraid_exp_find_by_sas_address()
1362 list_for_each_entry(sas_exp, &adapter->dev_topo.exp_list, list) in leapraid_exp_find_by_sas_address()
1367 dev_warn(&adapter->pdev->dev, in leapraid_exp_find_by_sas_address()
1373 bool leapraid_scmd_find_by_tgt(struct leapraid_adapter *adapter, uint id, in leapraid_scmd_find_by_tgt() argument
1379 for (taskid = 1; taskid <= adapter->shost->can_queue; taskid++) { in leapraid_scmd_find_by_tgt()
1380 scmd = leapraid_get_scmd_from_taskid(adapter, taskid); in leapraid_scmd_find_by_tgt()
1391 bool leapraid_scmd_find_by_lun(struct leapraid_adapter *adapter, uint id, in leapraid_scmd_find_by_lun() argument
1397 for (taskid = 1; taskid <= adapter->shost->can_queue; taskid++) { in leapraid_scmd_find_by_lun()
1398 scmd = leapraid_get_scmd_from_taskid(adapter, taskid); in leapraid_scmd_find_by_lun()
1412 struct leapraid_adapter *adapter, u16 hdl) in leapraid_exp_find_by_hdl() argument
1416 list_for_each_entry(sas_exp, &adapter->dev_topo.exp_list, list) in leapraid_exp_find_by_hdl()
1482 struct leapraid_adapter *adapter, in leapraid_check_card_port() argument
1496 list_for_each_entry(old_card_port, &adapter->dev_topo.card_port_list, in leapraid_check_card_port()
1514 struct leapraid_adapter *adapter, in leapraid_del_phy_part_of_anther_port() argument
1522 card_topo_node = &adapter->dev_topo.card; in leapraid_del_phy_part_of_anther_port()
1529 adapter, in leapraid_del_phy_part_of_anther_port()
1542 struct leapraid_adapter *adapter, in leapraid_add_or_del_phys_from_existing_port() argument
1551 card_topo_node = &adapter->dev_topo.card; in leapraid_add_or_del_phys_from_existing_port()
1554 for (offset = 0; offset < adapter->dev_topo.card.phys_num; offset++) { in leapraid_add_or_del_phys_from_existing_port()
1559 leapraid_del_phy_part_of_anther_port(adapter, in leapraid_add_or_del_phys_from_existing_port()
1568 adapter, in leapraid_add_or_del_phys_from_existing_port()
1573 adapter, in leapraid_add_or_del_phys_from_existing_port()
1582 struct leapraid_adapter *adapter) in leapraid_get_next_sas_dev_from_init_list() argument
1587 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_get_next_sas_dev_from_init_list()
1588 if (!list_empty(&adapter->dev_topo.sas_dev_init_list)) { in leapraid_get_next_sas_dev_from_init_list()
1589 sas_dev = list_first_entry(&adapter->dev_topo.sas_dev_init_list, in leapraid_get_next_sas_dev_from_init_list()
1594 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_get_next_sas_dev_from_init_list()
1683 static void leapraid_clear_boot_dev(struct leapraid_adapter *adapter, in leapraid_clear_boot_dev() argument
1691 spin_lock_irqsave(&adapter->boot_devs.lock, flags); in leapraid_clear_boot_dev()
1699 spin_unlock_irqrestore(&adapter->boot_devs.lock, flags); in leapraid_clear_boot_dev()
1704 spin_unlock_irqrestore(&adapter->boot_devs.lock, flags); in leapraid_clear_boot_dev()
1707 static void leapraid_clear_cached_boot_dev(struct leapraid_adapter *adapter, in leapraid_clear_cached_boot_dev() argument
1710 leapraid_clear_boot_dev(adapter, in leapraid_clear_cached_boot_dev()
1711 &adapter->boot_devs.requested_boot_dev, in leapraid_clear_cached_boot_dev()
1713 leapraid_clear_boot_dev(adapter, in leapraid_clear_cached_boot_dev()
1714 &adapter->boot_devs.requested_alt_boot_dev, in leapraid_clear_cached_boot_dev()
1716 leapraid_clear_boot_dev(adapter, in leapraid_clear_cached_boot_dev()
1717 &adapter->boot_devs.current_boot_dev, in leapraid_clear_cached_boot_dev()
1721 static void leapraid_check_boot_dev(struct leapraid_adapter *adapter, in leapraid_check_boot_dev() argument
1731 if (!adapter->scan_dev_desc.driver_loading) in leapraid_check_boot_dev()
1748 leapraid_try_set_boot_dev(&adapter->boot_devs.requested_boot_dev, in leapraid_check_boot_dev()
1751 leapraid_try_set_boot_dev(&adapter->boot_devs.requested_alt_boot_dev, in leapraid_check_boot_dev()
1754 leapraid_try_set_boot_dev(&adapter->boot_devs.current_boot_dev, in leapraid_check_boot_dev()
1907 void leapraid_log_req_context(struct leapraid_adapter *adapter, u16 smid, in leapraid_log_req_context() argument
1912 if (!adapter || !adapter->pdev || !req_data) in leapraid_log_req_context()
1919 dev_err(&adapter->pdev->dev, in leapraid_log_req_context()
1924 dev_err(&adapter->pdev->dev, in leapraid_log_req_context()
1930 dev_err(&adapter->pdev->dev, in leapraid_log_req_context()
1935 dev_err(&adapter->pdev->dev, "cfg-req: page_addr=0x%08x\n", in leapraid_log_req_context()
1942 dev_err(&adapter->pdev->dev, in leapraid_log_req_context()
1947 dev_err(&adapter->pdev->dev, in leapraid_log_req_context()
1956 dev_err(&adapter->pdev->dev, in leapraid_log_req_context()
1961 dev_err(&adapter->pdev->dev, in leapraid_log_req_context()
1971 dev_err(&adapter->pdev->dev, in leapraid_log_req_context()
1975 dev_err(&adapter->pdev->dev, in leapraid_log_req_context()
1984 dev_err(&adapter->pdev->dev, in leapraid_log_req_context()
1988 dev_err(&adapter->pdev->dev, in leapraid_log_req_context()
1992 dev_err(&adapter->pdev->dev, "smp_cmd: sas_addr=0x%016llx\n", in leapraid_log_req_context()
1997 dev_err(&adapter->pdev->dev, in leapraid_log_req_context()
2005 struct leapraid_adapter *adapter, in leapraid_build_and_fire_cfg_req() argument
2013 memset(&adapter->driver_cmds.cfg_op_cmd.reply, 0, in leapraid_build_and_fire_cfg_req()
2015 adapter->driver_cmds.cfg_op_cmd.status = LEAPRAID_CMD_PENDING; in leapraid_build_and_fire_cfg_req()
2016 smid = adapter->driver_cmds.cfg_op_cmd.inter_taskid; in leapraid_build_and_fire_cfg_req()
2017 local_leap_cfg_req = leapraid_get_task_desc(adapter, smid); in leapraid_build_and_fire_cfg_req()
2020 init_completion(&adapter->driver_cmds.cfg_op_cmd.done); in leapraid_build_and_fire_cfg_req()
2021 leapraid_fire_task(adapter, smid); in leapraid_build_and_fire_cfg_req()
2022 wait_for_completion_timeout(&adapter->driver_cmds.cfg_op_cmd.done, in leapraid_build_and_fire_cfg_req()
2026 static int leapraid_req_cfg_func(struct leapraid_adapter *adapter, in leapraid_req_cfg_func() argument
2039 mutex_lock(&adapter->driver_cmds.cfg_op_cmd.mutex); in leapraid_req_cfg_func()
2040 smid = adapter->driver_cmds.cfg_op_cmd.inter_taskid; in leapraid_req_cfg_func()
2047 dev_warn(&adapter->pdev->dev, in leapraid_req_cfg_func()
2051 rc = leapraid_check_adapter_is_op(adapter, LEAPRAID_DB_WAIT_OP_SHORT, in leapraid_req_cfg_func()
2054 dev_err(&adapter->pdev->dev, in leapraid_req_cfg_func()
2059 leapraid_build_and_fire_cfg_req(adapter, leap_mpi_cfgp_req, in leapraid_req_cfg_func()
2061 if (!(adapter->driver_cmds.cfg_op_cmd.status & LEAPRAID_CMD_DONE)) { in leapraid_req_cfg_func()
2063 if (adapter->driver_cmds.cfg_op_cmd.status & in leapraid_req_cfg_func()
2065 dev_warn(&adapter->pdev->dev, in leapraid_req_cfg_func()
2070 if (adapter->access_ctrl.shost_recovering || in leapraid_req_cfg_func()
2071 adapter->access_ctrl.pcie_recovering) { in leapraid_req_cfg_func()
2072 dev_err(&adapter->pdev->dev, in leapraid_req_cfg_func()
2074 adapter->access_ctrl.shost_recovering ? in leapraid_req_cfg_func()
2076 adapter->driver_cmds.cfg_op_cmd.status); in leapraid_req_cfg_func()
2077 leapraid_log_req_context(adapter, smid, in leapraid_req_cfg_func()
2082 dev_err(&adapter->pdev->dev, in leapraid_req_cfg_func()
2084 adapter->driver_cmds.cfg_op_cmd.status); in leapraid_req_cfg_func()
2085 leapraid_log_req_context(adapter, smid, in leapraid_req_cfg_func()
2093 if (adapter->driver_cmds.cfg_op_cmd.status & in leapraid_req_cfg_func()
2096 &adapter->driver_cmds.cfg_op_cmd.reply, in leapraid_req_cfg_func()
2111 dev_err(&adapter->pdev->dev, in leapraid_req_cfg_func()
2117 dev_err(&adapter->pdev->dev, "cfg-rep: Reply invalid\n"); in leapraid_req_cfg_func()
2122 adapter->driver_cmds.cfg_op_cmd.status = LEAPRAID_CMD_NOT_USED; in leapraid_req_cfg_func()
2123 mutex_unlock(&adapter->driver_cmds.cfg_op_cmd.mutex); in leapraid_req_cfg_func()
2125 if (adapter->scan_dev_desc.first_scan_dev_fired) { in leapraid_req_cfg_func()
2126 dev_warn(&adapter->pdev->dev, in leapraid_req_cfg_func()
2129 leapraid_hard_reset_handler(adapter, FULL_RESET); in leapraid_req_cfg_func()
2131 dev_warn(&adapter->pdev->dev, in leapraid_req_cfg_func()
2140 struct leapraid_adapter *adapter, in leapraid_request_cfg_pg_header() argument
2144 return leapraid_req_cfg_func(adapter, leap_mpi_cfgp_req, in leapraid_request_cfg_pg_header()
2148 static int leapraid_request_cfg_pg(struct leapraid_adapter *adapter, in leapraid_request_cfg_pg() argument
2154 return leapraid_req_cfg_func(adapter, leap_mpi_cfgp_req, in leapraid_request_cfg_pg()
2159 int leapraid_op_config_page(struct leapraid_adapter *adapter, in leapraid_op_config_page() argument
2261 dev_err(&adapter->pdev->dev, in leapraid_op_config_page()
2266 leapraid_build_nodata_mpi_sg(adapter, in leapraid_op_config_page()
2268 rc = leapraid_request_cfg_pg_header(adapter, in leapraid_op_config_page()
2272 dev_err(&adapter->pdev->dev, in leapraid_op_config_page()
2312 real_cfg_pg_addr = dma_alloc_coherent(&adapter->pdev->dev, in leapraid_op_config_page()
2320 leapraid_single_mpi_sg_append(adapter, in leapraid_op_config_page()
2334 leapraid_single_mpi_sg_append(adapter, in leapraid_op_config_page()
2347 rc = leapraid_request_cfg_pg(adapter, in leapraid_op_config_page()
2359 dev_err(&adapter->pdev->dev, in leapraid_op_config_page()
2367 dma_free_coherent(&adapter->pdev->dev, in leapraid_op_config_page()
2416 struct leapraid_adapter *adapter, in leapraid_cfg_get_volume_hdl_dispatch() argument
2435 adapter, cfg_req, cfg_rep, in leapraid_cfg_get_volume_hdl_dispatch()
2463 int leapraid_cfg_get_volume_hdl(struct leapraid_adapter *adapter, in leapraid_cfg_get_volume_hdl() argument
2482 leapraid_build_nodata_mpi_sg(adapter, &cfg_req.page_buf_sge); in leapraid_cfg_get_volume_hdl()
2483 rc = leapraid_request_cfg_pg_header(adapter, &cfg_req, &cfg_rep); in leapraid_cfg_get_volume_hdl()
2498 real_cfg_pg_addr = dma_alloc_coherent(&adapter->pdev->dev, in leapraid_cfg_get_volume_hdl()
2507 leapraid_single_mpi_sg_append(adapter, in leapraid_cfg_get_volume_hdl()
2519 rc = leapraid_cfg_get_volume_hdl_dispatch(adapter, in leapraid_cfg_get_volume_hdl()
2529 dma_free_coherent(&adapter->pdev->dev, in leapraid_cfg_get_volume_hdl()
2536 static int leapraid_get_adapter_phys(struct leapraid_adapter *adapter, in leapraid_get_adapter_phys() argument
2546 rc = leapraid_op_config_page(adapter, &sas_io_unit_page0, cfgp1, in leapraid_get_adapter_phys()
2556 static int leapraid_cfg_get_number_pds(struct leapraid_adapter *adapter, in leapraid_cfg_get_number_pds() argument
2567 rc = leapraid_op_config_page(adapter, &raidvol_p0, cfgp1, in leapraid_cfg_get_number_pds()
2575 int leapraid_cfg_get_volume_wwid(struct leapraid_adapter *adapter, in leapraid_cfg_get_volume_wwid() argument
2586 rc = leapraid_op_config_page(adapter, &raidvol_p1, cfgp1, in leapraid_cfg_get_volume_wwid()
2595 struct leapraid_adapter *adapter, in leapraid_get_sas_io_unit_page0() argument
2603 return leapraid_op_config_page(adapter, sas_io_unit_p0, cfgp1, in leapraid_get_sas_io_unit_page0()
2607 static int leapraid_get_sas_address(struct leapraid_adapter *adapter, in leapraid_get_sas_address() argument
2617 if (leapraid_op_config_page(adapter, &sas_dev_p0, cfgp1, in leapraid_get_sas_address()
2621 if (hdl <= adapter->dev_topo.card.phys_num && in leapraid_get_sas_address()
2623 *sas_address = adapter->dev_topo.card.sas_address; in leapraid_get_sas_address()
2630 int leapraid_get_volume_cap(struct leapraid_adapter *adapter, in leapraid_get_volume_cap() argument
2642 if (leapraid_cfg_get_number_pds(adapter, raid_volume->hdl, in leapraid_get_volume_cap()
2655 if (leapraid_op_config_page(adapter, raidvol_p0, cfgp1, cfgp2, in leapraid_get_volume_cap()
2664 if (!(leapraid_op_config_page(adapter, &raidpd_p0, cfgp1, cfgp2, in leapraid_get_volume_cap()
2668 if (!(leapraid_op_config_page(adapter, &sas_dev_p0, cfgp1, in leapraid_get_volume_cap()
2679 static bool leapraid_should_skip_poll_work(struct leapraid_adapter *adapter) in leapraid_should_skip_poll_work() argument
2684 spin_lock_irqsave(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_should_skip_poll_work()
2685 skip = adapter->access_ctrl.shost_recovering || in leapraid_should_skip_poll_work()
2686 adapter->access_ctrl.pcie_recovering || in leapraid_should_skip_poll_work()
2687 adapter->access_ctrl.host_removing; in leapraid_should_skip_poll_work()
2688 spin_unlock_irqrestore(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_should_skip_poll_work()
2695 struct leapraid_adapter *adapter = container_of(work, in leapraid_fw_log_work() local
2701 if (leapraid_should_skip_poll_work(adapter)) in leapraid_fw_log_work()
2705 (adapter->fw_log_desc.fw_log_buffer + in leapraid_fw_log_work()
2708 iomem_base = adapter->iomem_base; in leapraid_fw_log_work()
2709 if (adapter->fw_log_desc.fw_log_init_flag == 0) { in leapraid_fw_log_work()
2714 adapter->fw_log_desc.fw_log_init_flag++; in leapraid_fw_log_work()
2722 spin_lock_irqsave(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_fw_log_work()
2723 if (adapter->fw_log_desc.fw_log_wq) in leapraid_fw_log_work()
2725 adapter->fw_log_desc.fw_log_wq, in leapraid_fw_log_work()
2726 &adapter->fw_log_desc.fw_log_work, in leapraid_fw_log_work()
2728 spin_unlock_irqrestore(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_fw_log_work()
2731 void leapraid_fw_log_stop(struct leapraid_adapter *adapter) in leapraid_fw_log_stop() argument
2736 if (!adapter->fw_log_desc.open_pcie_trace) in leapraid_fw_log_stop()
2739 spin_lock_irqsave(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_fw_log_stop()
2740 wq = adapter->fw_log_desc.fw_log_wq; in leapraid_fw_log_stop()
2741 adapter->fw_log_desc.fw_log_wq = NULL; in leapraid_fw_log_stop()
2742 spin_unlock_irqrestore(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_fw_log_stop()
2744 if (!cancel_delayed_work_sync(&adapter->fw_log_desc in leapraid_fw_log_stop()
2751 void leapraid_fw_log_start(struct leapraid_adapter *adapter) in leapraid_fw_log_start() argument
2755 if (!adapter->fw_log_desc.open_pcie_trace) in leapraid_fw_log_start()
2758 if (adapter->fw_log_desc.fw_log_wq) in leapraid_fw_log_start()
2761 INIT_DELAYED_WORK(&adapter->fw_log_desc.fw_log_work, in leapraid_fw_log_start()
2763 snprintf(adapter->fw_log_desc.fw_log_wq_name, in leapraid_fw_log_start()
2764 sizeof(adapter->fw_log_desc.fw_log_wq_name), in leapraid_fw_log_start()
2766 LEAPRAID_DRIVER_NAME, adapter->adapter_attr.id); in leapraid_fw_log_start()
2767 adapter->fw_log_desc.fw_log_wq = in leapraid_fw_log_start()
2769 adapter->fw_log_desc.fw_log_wq_name); in leapraid_fw_log_start()
2770 if (!adapter->fw_log_desc.fw_log_wq) in leapraid_fw_log_start()
2773 spin_lock_irqsave(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_fw_log_start()
2774 if (adapter->fw_log_desc.fw_log_wq) in leapraid_fw_log_start()
2776 adapter->fw_log_desc.fw_log_wq, in leapraid_fw_log_start()
2777 &adapter->fw_log_desc.fw_log_work, in leapraid_fw_log_start()
2779 spin_unlock_irqrestore(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_fw_log_start()
2784 struct leapraid_adapter *adapter; in leapraid_check_scheduled_fault_work() local
2789 adapter = container_of(work, struct leapraid_adapter, in leapraid_check_scheduled_fault_work()
2792 if (leapraid_should_skip_poll_work(adapter)) in leapraid_check_scheduled_fault_work()
2795 adapter_state = leapraid_get_adapter_state(adapter); in leapraid_check_scheduled_fault_work()
2797 dev_info(&adapter->pdev->dev, "%s:%d: call hard_reset 0x%x\n", in leapraid_check_scheduled_fault_work()
2799 rc = leapraid_hard_reset_handler(adapter, FULL_RESET); in leapraid_check_scheduled_fault_work()
2800 adapter_state = leapraid_get_adapter_state(adapter); in leapraid_check_scheduled_fault_work()
2802 dev_err(&adapter->pdev->dev, in leapraid_check_scheduled_fault_work()
2810 spin_lock_irqsave(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_check_scheduled_fault_work()
2811 if (adapter->reset_desc.fault_reset_wq) in leapraid_check_scheduled_fault_work()
2813 adapter->reset_desc.fault_reset_wq, in leapraid_check_scheduled_fault_work()
2814 &adapter->reset_desc.fault_reset_work, in leapraid_check_scheduled_fault_work()
2816 spin_unlock_irqrestore(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_check_scheduled_fault_work()
2819 void leapraid_check_scheduled_fault_start(struct leapraid_adapter *adapter) in leapraid_check_scheduled_fault_start() argument
2823 if (adapter->reset_desc.fault_reset_wq) in leapraid_check_scheduled_fault_start()
2826 INIT_DELAYED_WORK(&adapter->reset_desc.fault_reset_work, in leapraid_check_scheduled_fault_start()
2828 snprintf(adapter->reset_desc.fault_reset_wq_name, in leapraid_check_scheduled_fault_start()
2829 sizeof(adapter->reset_desc.fault_reset_wq_name), in leapraid_check_scheduled_fault_start()
2831 LEAPRAID_DRIVER_NAME, adapter->adapter_attr.id); in leapraid_check_scheduled_fault_start()
2832 adapter->reset_desc.fault_reset_wq = in leapraid_check_scheduled_fault_start()
2834 adapter->reset_desc.fault_reset_wq_name); in leapraid_check_scheduled_fault_start()
2835 if (!adapter->reset_desc.fault_reset_wq) { in leapraid_check_scheduled_fault_start()
2836 dev_err(&adapter->pdev->dev, in leapraid_check_scheduled_fault_start()
2841 spin_lock_irqsave(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_check_scheduled_fault_start()
2842 if (adapter->reset_desc.fault_reset_wq) in leapraid_check_scheduled_fault_start()
2844 adapter->reset_desc.fault_reset_wq, in leapraid_check_scheduled_fault_start()
2845 &adapter->reset_desc.fault_reset_work, in leapraid_check_scheduled_fault_start()
2847 spin_unlock_irqrestore(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_check_scheduled_fault_start()
2850 void leapraid_check_scheduled_fault_stop(struct leapraid_adapter *adapter) in leapraid_check_scheduled_fault_stop() argument
2855 spin_lock_irqsave(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_check_scheduled_fault_stop()
2856 wq = adapter->reset_desc.fault_reset_wq; in leapraid_check_scheduled_fault_stop()
2857 adapter->reset_desc.fault_reset_wq = NULL; in leapraid_check_scheduled_fault_stop()
2858 spin_unlock_irqrestore(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_check_scheduled_fault_stop()
2863 if (!cancel_delayed_work_sync(&adapter->reset_desc.fault_reset_work)) in leapraid_check_scheduled_fault_stop()
2871 struct leapraid_adapter *adapter; in leapraid_overheat_work() local
2879 adapter = container_of(desc, struct leapraid_adapter, overheat_desc); in leapraid_overheat_work()
2880 pdev = adapter->pdev; in leapraid_overheat_work()
2886 atomic_set(&adapter->overheat_desc.thermal_alert, 0); in leapraid_overheat_work()
2887 wake_up(&adapter->scan_dev_desc.wait_driver_loading); in leapraid_overheat_work()
2891 if (adapter->access_ctrl.host_removing) { in leapraid_overheat_work()
2892 atomic_set(&adapter->overheat_desc.thermal_alert, 0); in leapraid_overheat_work()
2893 wake_up(&adapter->scan_dev_desc.wait_driver_loading); in leapraid_overheat_work()
2897 adapter->access_ctrl.host_removing = 1; in leapraid_overheat_work()
2898 adapter->access_ctrl.shost_recover_async = 0; in leapraid_overheat_work()
2899 adapter->scan_dev_desc.scan_start = 0; in leapraid_overheat_work()
2900 adapter->scan_dev_desc.wait_scan_dev_done = 0; in leapraid_overheat_work()
2901 adapter->scan_dev_desc.driver_loading = 0; in leapraid_overheat_work()
2902 wake_up(&adapter->access_ctrl.shost_recover_wq); in leapraid_overheat_work()
2903 wake_up(&adapter->scan_dev_desc.wait_driver_loading); in leapraid_overheat_work()
2905 leapraid_mask_int(adapter); in leapraid_overheat_work()
2907 leapraid_check_scheduled_fault_stop(adapter); in leapraid_overheat_work()
2908 leapraid_fw_log_stop(adapter); in leapraid_overheat_work()
2909 leapraid_mq_polling_pause(adapter); in leapraid_overheat_work()
2911 leapraid_clean_active_cmds(adapter); in leapraid_overheat_work()
2912 spin_lock_irqsave(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_overheat_work()
2913 wq = adapter->fw_evt_s.fw_evt_thread; in leapraid_overheat_work()
2914 adapter->fw_evt_s.fw_evt_thread = NULL; in leapraid_overheat_work()
2915 spin_unlock_irqrestore(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_overheat_work()
2920 leapraid_cleanup_lists(adapter); in leapraid_overheat_work()
2921 atomic_set(&adapter->overheat_desc.thermal_alert, 0); in leapraid_overheat_work()
2922 wake_up(&adapter->scan_dev_desc.wait_driver_loading); in leapraid_overheat_work()
2926 static void leapraid_overheat_init(struct leapraid_adapter *adapter) in leapraid_overheat_init() argument
2928 if (adapter->overheat_desc.fault_overheat_wq) in leapraid_overheat_init()
2931 atomic_set(&adapter->overheat_desc.thermal_alert, 0); in leapraid_overheat_init()
2932 snprintf(adapter->overheat_desc.fault_overheat_wq_name, in leapraid_overheat_init()
2933 sizeof(adapter->overheat_desc.fault_overheat_wq_name), in leapraid_overheat_init()
2936 adapter->adapter_attr.id); in leapraid_overheat_init()
2937 adapter->overheat_desc.fault_overheat_wq = in leapraid_overheat_init()
2939 adapter->overheat_desc.fault_overheat_wq_name); in leapraid_overheat_init()
2940 if (!adapter->overheat_desc.fault_overheat_wq) { in leapraid_overheat_init()
2941 dev_err(&adapter->pdev->dev, in leapraid_overheat_init()
2946 INIT_WORK(&adapter->overheat_desc.fault_overheat_work, in leapraid_overheat_init()
2950 void leapraid_overheat_cleanup(struct leapraid_adapter *adapter) in leapraid_overheat_cleanup() argument
2954 wq = xchg(&adapter->overheat_desc.fault_overheat_wq, NULL); in leapraid_overheat_cleanup()
2958 cancel_work_sync(&adapter->overheat_desc.fault_overheat_work); in leapraid_overheat_cleanup()
2962 static void leapraid_fw_work(struct leapraid_adapter *adapter,
3000 leapraid_fw_work(fw_evt->adapter, fw_evt); in leapraid_run_fw_evt_work()
3003 static void leapraid_fw_evt_add(struct leapraid_adapter *adapter, in leapraid_fw_evt_add() argument
3008 spin_lock_irqsave(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_fw_evt_add()
3009 if (adapter->access_ctrl.host_removing || in leapraid_fw_evt_add()
3010 adapter->access_ctrl.pcie_recovering || in leapraid_fw_evt_add()
3011 !adapter->fw_evt_s.fw_evt_thread) { in leapraid_fw_evt_add()
3012 spin_unlock_irqrestore(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_fw_evt_add()
3018 list_add_tail(&fw_evt->list, &adapter->fw_evt_s.fw_evt_list); in leapraid_fw_evt_add()
3021 queue_work(adapter->fw_evt_s.fw_evt_thread, &fw_evt->work); in leapraid_fw_evt_add()
3022 spin_unlock_irqrestore(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_fw_evt_add()
3025 static void leapraid_del_fw_evt_from_list(struct leapraid_adapter *adapter, in leapraid_del_fw_evt_from_list() argument
3030 spin_lock_irqsave(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_del_fw_evt_from_list()
3035 spin_unlock_irqrestore(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_del_fw_evt_from_list()
3039 struct leapraid_adapter *adapter) in leapraid_next_fw_evt() argument
3044 spin_lock_irqsave(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_next_fw_evt()
3045 if (!list_empty(&adapter->fw_evt_s.fw_evt_list)) { in leapraid_next_fw_evt()
3046 fw_evt = list_first_entry(&adapter->fw_evt_s.fw_evt_list, in leapraid_next_fw_evt()
3050 spin_unlock_irqrestore(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_next_fw_evt()
3054 void leapraid_clean_active_fw_evt(struct leapraid_adapter *adapter) in leapraid_clean_active_fw_evt() argument
3061 if ((list_empty(&adapter->fw_evt_s.fw_evt_list) && in leapraid_clean_active_fw_evt()
3062 !adapter->fw_evt_s.cur_evt) || !adapter->fw_evt_s.fw_evt_thread) in leapraid_clean_active_fw_evt()
3065 adapter->fw_evt_s.fw_evt_cleanup = 1; in leapraid_clean_active_fw_evt()
3066 if (adapter->access_ctrl.shost_recovering && in leapraid_clean_active_fw_evt()
3067 adapter->fw_evt_s.cur_evt) in leapraid_clean_active_fw_evt()
3068 adapter->fw_evt_s.cur_evt->ignore = 1; in leapraid_clean_active_fw_evt()
3070 while ((fw_evt = leapraid_next_fw_evt(adapter))) { in leapraid_clean_active_fw_evt()
3077 spin_lock_irqsave(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_clean_active_fw_evt()
3078 fw_evt = adapter->fw_evt_s.cur_evt; in leapraid_clean_active_fw_evt()
3080 in_fw_evt_context = adapter->fw_evt_s.cur_evt_task == current; in leapraid_clean_active_fw_evt()
3083 spin_unlock_irqrestore(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_clean_active_fw_evt()
3090 adapter->fw_evt_s.fw_evt_cleanup = 0; in leapraid_clean_active_fw_evt()
3123 static void leapraid_ublk_io_dev(struct leapraid_adapter *adapter, in leapraid_ublk_io_dev() argument
3130 shost_for_each_device(sdev, adapter->shost) { in leapraid_ublk_io_dev()
3148 static void leapraid_ublk_io_all_dev(struct leapraid_adapter *adapter) in leapraid_ublk_io_all_dev() argument
3154 shost_for_each_device(sdev, adapter->shost) { in leapraid_ublk_io_all_dev()
3190 static void leapraid_imm_blkio_to_end_dev(struct leapraid_adapter *adapter, in leapraid_imm_blkio_to_end_dev() argument
3198 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_imm_blkio_to_end_dev()
3200 adapter, in leapraid_imm_blkio_to_end_dev()
3205 shost_for_each_device(sdev, adapter->shost) { in leapraid_imm_blkio_to_end_dev()
3231 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_imm_blkio_to_end_dev()
3235 struct leapraid_adapter *adapter, in leapraid_imm_blkio_set_end_dev_blk_hdls() argument
3243 leapraid_imm_blkio_to_end_dev(adapter, sas_port); in leapraid_imm_blkio_set_end_dev_blk_hdls()
3248 struct leapraid_adapter *adapter,
3252 struct leapraid_adapter *adapter, in leapraid_imm_blkio_to_sib_exp() argument
3266 adapter, in leapraid_imm_blkio_to_sib_exp()
3270 adapter, in leapraid_imm_blkio_to_sib_exp()
3277 struct leapraid_adapter *adapter, in leapraid_imm_blkio_to_kids_attchd_to_ex() argument
3283 leapraid_imm_blkio_set_end_dev_blk_hdls(adapter, topo_node_exp); in leapraid_imm_blkio_to_kids_attchd_to_ex()
3285 leapraid_imm_blkio_to_sib_exp(adapter, topo_node_exp); in leapraid_imm_blkio_to_kids_attchd_to_ex()
3288 static void leapraid_report_sdev_directly(struct leapraid_adapter *adapter, in leapraid_report_sdev_directly() argument
3293 sas_port = leapraid_transport_port_add(adapter, in leapraid_report_sdev_directly()
3298 leapraid_sas_dev_remove(adapter, sas_dev); in leapraid_report_sdev_directly()
3303 if (!adapter->scan_dev_desc.driver_loading) { in leapraid_report_sdev_directly()
3305 adapter, in leapraid_report_sdev_directly()
3309 leapraid_sas_dev_remove(adapter, sas_dev); in leapraid_report_sdev_directly()
3316 struct leapraid_adapter *adapter, in leapraid_init_sas_dev() argument
3353 spin_lock_irqsave(&adapter->dev_topo.enc_lock, flags); in leapraid_init_sas_dev()
3354 enc_dev = leapraid_enc_find_by_hdl(adapter, sas_dev->enc_hdl); in leapraid_init_sas_dev()
3357 spin_unlock_irqrestore(&adapter->dev_topo.enc_lock, flags); in leapraid_init_sas_dev()
3359 dev_info(&adapter->pdev->dev, in leapraid_init_sas_dev()
3366 static void leapraid_add_dev(struct leapraid_adapter *adapter, u16 hdl) in leapraid_add_dev() argument
3381 if (leapraid_op_config_page(adapter, &sas_dev_pg0, in leapraid_add_dev()
3395 card_port = leapraid_get_port_by_id(adapter, port_id, false); in leapraid_add_dev()
3399 sas_dev = leapraid_get_sas_dev_by_addr(adapter, sas_addr, card_port); in leapraid_add_dev()
3405 if (leapraid_get_sas_address(adapter, in leapraid_add_dev()
3410 sas_dev = leapraid_init_sas_dev(adapter, &sas_dev_pg0, card_port, in leapraid_add_dev()
3416 if (adapter->scan_dev_desc.wait_scan_dev_done) { in leapraid_add_dev()
3417 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_add_dev()
3420 &adapter->dev_topo.sas_dev_init_list); in leapraid_add_dev()
3421 leapraid_check_boot_dev(adapter, sas_dev, 0); in leapraid_add_dev()
3422 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_add_dev()
3424 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_add_dev()
3426 list_add_tail(&sas_dev->list, &adapter->dev_topo.sas_dev_list); in leapraid_add_dev()
3427 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_add_dev()
3428 leapraid_report_sdev_directly(adapter, sas_dev); in leapraid_add_dev()
3433 static void leapraid_remove_device(struct leapraid_adapter *adapter, in leapraid_remove_device() argument
3438 leapraid_clear_cached_boot_dev(adapter, sas_dev, 0); in leapraid_remove_device()
3440 leapraid_set_led(adapter, sas_dev, false); in leapraid_remove_device()
3447 leapraid_ublk_io_dev(adapter, in leapraid_remove_device()
3452 leapraid_transport_port_remove(adapter, in leapraid_remove_device()
3457 dev_info(&adapter->pdev->dev, in leapraid_remove_device()
3463 struct leapraid_adapter *adapter, in leapraid_alloc_vphy() argument
3469 port = leapraid_get_port_by_id(adapter, port_id, false); in leapraid_alloc_vphy()
3490 struct leapraid_adapter *adapter, in leapraid_add_port_to_card_port_list() argument
3495 card_port = leapraid_get_port_by_id(adapter, port_id, false); in leapraid_add_port_to_card_port_list()
3503 dev_dbg(&adapter->pdev->dev, in leapraid_add_port_to_card_port_list()
3507 if (refresh && adapter->access_ctrl.shost_recovering) in leapraid_add_port_to_card_port_list()
3509 list_add_tail(&card_port->list, &adapter->dev_topo.card_port_list); in leapraid_add_port_to_card_port_list()
3513 static int leapraid_add_card_phy(struct leapraid_adapter *adapter, in leapraid_add_card_phy() argument
3520 struct leapraid_topo_node *card = &adapter->dev_topo.card; in leapraid_add_card_phy()
3525 if (leapraid_op_config_page(adapter, &phy_pg0, in leapraid_add_card_phy()
3531 if (leapraid_add_port_to_card_port_list(adapter, port_id, false)) in leapraid_add_card_phy()
3539 if (!leapraid_alloc_vphy(adapter, port_id, i)) in leapraid_add_card_phy()
3548 leapraid_get_port_by_id(adapter, port_id, false); in leapraid_add_card_phy()
3550 leapraid_transport_add_card_phy(adapter, in leapraid_add_card_phy()
3558 static int leapraid_refresh_card_phy(struct leapraid_adapter *adapter, in leapraid_refresh_card_phy() argument
3562 struct leapraid_topo_node *card = &adapter->dev_topo.card; in leapraid_refresh_card_phy()
3574 if (leapraid_add_port_to_card_port_list(adapter, port_id, true)) in leapraid_refresh_card_phy()
3582 if (leapraid_op_config_page(adapter, &phy_pg0, in leapraid_refresh_card_phy()
3588 if (!leapraid_alloc_vphy(adapter, port_id, i)) in leapraid_refresh_card_phy()
3601 leapraid_get_port_by_id(adapter, port_id, false); in leapraid_refresh_card_phy()
3605 if (leapraid_op_config_page(adapter, &phy_pg0, in leapraid_refresh_card_phy()
3611 leapraid_transport_add_card_phy(adapter, in leapraid_refresh_card_phy()
3618 leapraid_transport_update_links(adapter, in leapraid_refresh_card_phy()
3628 static void leapraid_sas_host_add(struct leapraid_adapter *adapter, in leapraid_sas_host_add() argument
3642 if (leapraid_get_adapter_phys(adapter, &phys_num) || !phys_num) in leapraid_sas_host_add()
3645 adapter->dev_topo.card.card_phy = in leapraid_sas_host_add()
3647 if (!adapter->dev_topo.card.card_phy) in leapraid_sas_host_add()
3650 adapter->dev_topo.card.phys_num = phys_num; in leapraid_sas_host_add()
3655 (adapter->dev_topo.card.phys_num * in leapraid_sas_host_add()
3661 if (leapraid_get_sas_io_unit_page0(adapter, in leapraid_sas_host_add()
3666 adapter->dev_topo.card.parent_dev = &adapter->shost->shost_gendev; in leapraid_sas_host_add()
3667 adapter->dev_topo.card.hdl = in leapraid_sas_host_add()
3669 for (i = 0; i < adapter->dev_topo.card.phys_num; i++) { in leapraid_sas_host_add()
3671 rc = leapraid_add_card_phy(adapter, sas_iou_pg0, i); in leapraid_sas_host_add()
3673 rc = leapraid_refresh_card_phy(adapter, in leapraid_sas_host_add()
3682 cfgp2.handle = adapter->dev_topo.card.hdl; in leapraid_sas_host_add()
3683 if (leapraid_op_config_page(adapter, &sas_dev_pg0, cfgp1, in leapraid_sas_host_add()
3687 adapter->dev_topo.card.enc_hdl = in leapraid_sas_host_add()
3689 adapter->dev_topo.card.sas_address = in leapraid_sas_host_add()
3691 dev_info(&adapter->pdev->dev, in leapraid_sas_host_add()
3693 adapter->dev_topo.card.hdl, in leapraid_sas_host_add()
3694 (unsigned long long)adapter->dev_topo.card.sas_address, in leapraid_sas_host_add()
3695 adapter->dev_topo.card.phys_num); in leapraid_sas_host_add()
3697 if (adapter->dev_topo.card.enc_hdl) { in leapraid_sas_host_add()
3699 cfgp2.handle = adapter->dev_topo.card.enc_hdl; in leapraid_sas_host_add()
3700 if (!(leapraid_op_config_page(adapter, &enc_pg0, in leapraid_sas_host_add()
3703 adapter->dev_topo.card.enc_lid = in leapraid_sas_host_add()
3711 static int leapraid_internal_exp_add(struct leapraid_adapter *adapter, in leapraid_internal_exp_add() argument
3732 rc = leapraid_get_sas_address(adapter, in leapraid_internal_exp_add()
3745 leapraid_get_port_by_id(adapter, port_id, false); in leapraid_internal_exp_add()
3751 dev_info(&adapter->pdev->dev, in leapraid_internal_exp_add()
3757 dev_err(&adapter->pdev->dev, in leapraid_internal_exp_add()
3766 dev_err(&adapter->pdev->dev, in leapraid_internal_exp_add()
3774 sas_port = leapraid_transport_port_add(adapter, hdl, sas_addr_parent, in leapraid_internal_exp_add()
3786 if (leapraid_op_config_page(adapter, &exp_pg1, *cfgp1, *cfgp2, in leapraid_internal_exp_add()
3788 dev_err(&adapter->pdev->dev, in leapraid_internal_exp_add()
3798 leapraid_get_port_by_id(adapter, port_id, false); in leapraid_internal_exp_add()
3800 adapter, in leapraid_internal_exp_add()
3811 spin_lock_irqsave(&adapter->dev_topo.enc_lock, flags); in leapraid_internal_exp_add()
3812 enc_dev = leapraid_enc_find_by_hdl(adapter, in leapraid_internal_exp_add()
3817 spin_unlock_irqrestore(&adapter->dev_topo.enc_lock, flags); in leapraid_internal_exp_add()
3820 spin_lock_irqsave(&adapter->dev_topo.topo_node_lock, flags); in leapraid_internal_exp_add()
3821 list_add_tail(&topo_node_exp->list, &adapter->dev_topo.exp_list); in leapraid_internal_exp_add()
3822 spin_unlock_irqrestore(&adapter->dev_topo.topo_node_lock, flags); in leapraid_internal_exp_add()
3827 leapraid_transport_port_remove(adapter, in leapraid_internal_exp_add()
3836 static int leapraid_exp_add(struct leapraid_adapter *adapter, u16 hdl) in leapraid_exp_add() argument
3849 dev_warn(&adapter->pdev->dev, "%s: Invalid hdl\n", __func__); in leapraid_exp_add()
3853 if (adapter->access_ctrl.shost_recovering || in leapraid_exp_add()
3854 adapter->access_ctrl.pcie_recovering) { in leapraid_exp_add()
3855 dev_warn(&adapter->pdev->dev, in leapraid_exp_add()
3857 __func__, adapter->access_ctrl.shost_recovering, in leapraid_exp_add()
3858 adapter->access_ctrl.pcie_recovering); in leapraid_exp_add()
3864 if (leapraid_op_config_page(adapter, &exp_pg0, cfgp1, cfgp2, in leapraid_exp_add()
3869 if (leapraid_get_sas_address(adapter, parent_handle, &sas_addr_parent)) in leapraid_exp_add()
3873 if (sas_addr_parent != adapter->dev_topo.card.sas_address) { in leapraid_exp_add()
3874 spin_lock_irqsave(&adapter->dev_topo.topo_node_lock, flags); in leapraid_exp_add()
3877 adapter, in leapraid_exp_add()
3879 leapraid_get_port_by_id(adapter, in leapraid_exp_add()
3882 spin_unlock_irqrestore(&adapter->dev_topo.topo_node_lock, in leapraid_exp_add()
3885 rc = leapraid_exp_add(adapter, parent_handle); in leapraid_exp_add()
3891 spin_lock_irqsave(&adapter->dev_topo.topo_node_lock, flags); in leapraid_exp_add()
3895 adapter, in leapraid_exp_add()
3897 leapraid_get_port_by_id(adapter, port_id, false)); in leapraid_exp_add()
3898 spin_unlock_irqrestore(&adapter->dev_topo.topo_node_lock, flags); in leapraid_exp_add()
3903 return leapraid_internal_exp_add(adapter, &exp_pg0, &cfgp1, in leapraid_exp_add()
3907 static void leapraid_exp_node_rm(struct leapraid_adapter *adapter, in leapraid_exp_node_rm() argument
3917 if (adapter->access_ctrl.shost_recovering) in leapraid_exp_node_rm()
3923 adapter, in leapraid_exp_node_rm()
3930 adapter, in leapraid_exp_node_rm()
3940 leapraid_transport_port_remove(adapter, topo_node_exp->sas_address, in leapraid_exp_node_rm()
3943 dev_info(&adapter->pdev->dev, in leapraid_exp_node_rm()
3947 spin_lock_irqsave(&adapter->dev_topo.topo_node_lock, flags); in leapraid_exp_node_rm()
3949 spin_unlock_irqrestore(&adapter->dev_topo.topo_node_lock, flags); in leapraid_exp_node_rm()
3954 void leapraid_exp_rm(struct leapraid_adapter *adapter, u64 sas_addr, in leapraid_exp_rm() argument
3960 if (adapter->access_ctrl.shost_recovering) in leapraid_exp_rm()
3966 spin_lock_irqsave(&adapter->dev_topo.topo_node_lock, flags); in leapraid_exp_rm()
3967 topo_node_exp = leapraid_exp_find_by_sas_address(adapter, in leapraid_exp_rm()
3970 spin_unlock_irqrestore(&adapter->dev_topo.topo_node_lock, flags); in leapraid_exp_rm()
3973 leapraid_exp_node_rm(adapter, topo_node_exp); in leapraid_exp_rm()
3977 struct leapraid_adapter *adapter, in leapraid_internal_sas_topo_chg_evt() argument
3995 if (adapter->access_ctrl.host_removing || in leapraid_internal_sas_topo_chg_evt()
3996 adapter->access_ctrl.pcie_recovering) in leapraid_internal_sas_topo_chg_evt()
4008 hdl > adapter->adapter_attr.features.max_dev_handle) { in leapraid_internal_sas_topo_chg_evt()
4009 dev_warn(&adapter->pdev->dev, in leapraid_internal_sas_topo_chg_evt()
4017 if (adapter->access_ctrl.shost_recovering) in leapraid_internal_sas_topo_chg_evt()
4019 leapraid_transport_update_links(adapter, sas_addr, in leapraid_internal_sas_topo_chg_evt()
4024 leapraid_add_dev(adapter, hdl); in leapraid_internal_sas_topo_chg_evt()
4027 leapraid_sas_dev_remove_by_hdl(adapter, hdl); in leapraid_internal_sas_topo_chg_evt()
4034 leapraid_exp_rm(adapter, sas_addr, card_port); in leapraid_internal_sas_topo_chg_evt()
4037 static void leapraid_sas_topo_chg_evt(struct leapraid_adapter *adapter, in leapraid_sas_topo_chg_evt() argument
4048 if (adapter->access_ctrl.shost_recovering || in leapraid_sas_topo_chg_evt()
4049 adapter->access_ctrl.host_removing || in leapraid_sas_topo_chg_evt()
4050 adapter->access_ctrl.pcie_recovering) in leapraid_sas_topo_chg_evt()
4054 leapraid_sas_host_add(adapter, adapter->dev_topo.card.phys_num > 0); in leapraid_sas_topo_chg_evt()
4060 card_port = leapraid_get_port_by_id(adapter, in leapraid_sas_topo_chg_evt()
4064 leapraid_exp_add(adapter, phdl) != 0) in leapraid_sas_topo_chg_evt()
4067 spin_lock_irqsave(&adapter->dev_topo.topo_node_lock, flags); in leapraid_sas_topo_chg_evt()
4068 topo_node_exp = leapraid_exp_find_by_hdl(adapter, phdl); in leapraid_sas_topo_chg_evt()
4073 } else if (phdl < adapter->dev_topo.card.phys_num) { in leapraid_sas_topo_chg_evt()
4074 sas_addr = adapter->dev_topo.card.sas_address; in leapraid_sas_topo_chg_evt()
4075 max_phys = adapter->dev_topo.card.phys_num; in leapraid_sas_topo_chg_evt()
4077 spin_unlock_irqrestore(&adapter->dev_topo.topo_node_lock, in leapraid_sas_topo_chg_evt()
4081 spin_unlock_irqrestore(&adapter->dev_topo.topo_node_lock, flags); in leapraid_sas_topo_chg_evt()
4083 leapraid_internal_sas_topo_chg_evt(adapter, card_port, in leapraid_sas_topo_chg_evt()
4098 struct leapraid_adapter *adapter, in leapraid_sas_pd_add() argument
4110 if (!hdl || hdl > adapter->adapter_attr.features.max_dev_handle) { in leapraid_sas_pd_add()
4111 dev_warn(&adapter->pdev->dev, in leapraid_sas_pd_add()
4116 set_bit(hdl, adapter->dev_topo.pd_hdls); in leapraid_sas_pd_add()
4117 sas_dev = leapraid_get_sas_dev_by_hdl(adapter, hdl); in leapraid_sas_pd_add()
4120 dev_warn(&adapter->pdev->dev, in leapraid_sas_pd_add()
4127 if (leapraid_op_config_page(adapter, &sas_dev_p0, cfgp1, cfgp2, in leapraid_sas_pd_add()
4129 dev_warn(&adapter->pdev->dev, "Failed to read dev page0\n"); in leapraid_sas_pd_add()
4134 if (!leapraid_get_sas_address(adapter, parent_hdl, &sas_address)) in leapraid_sas_pd_add()
4135 leapraid_transport_update_links(adapter, sas_address, hdl, in leapraid_sas_pd_add()
4138 leapraid_get_port_by_id(adapter, in leapraid_sas_pd_add()
4141 leapraid_add_dev(adapter, hdl); in leapraid_sas_pd_add()
4145 struct leapraid_adapter *adapter, in leapraid_sas_pd_delete() argument
4151 leapraid_sas_dev_remove_by_hdl(adapter, hdl); in leapraid_sas_pd_delete()
4155 struct leapraid_adapter *adapter, in leapraid_sas_pd_hide() argument
4167 if (!hdl || hdl > adapter->adapter_attr.features.max_dev_handle) { in leapraid_sas_pd_hide()
4168 dev_warn(&adapter->pdev->dev, in leapraid_sas_pd_hide()
4172 leapraid_cfg_get_volume_hdl(adapter, hdl, &volume_hdl); in leapraid_sas_pd_hide()
4174 leapraid_cfg_get_volume_wwid(adapter, in leapraid_sas_pd_hide()
4178 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_sas_pd_hide()
4179 sas_dev = leapraid_hold_lock_get_sas_dev_by_hdl(adapter, hdl); in leapraid_sas_pd_hide()
4181 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_sas_pd_hide()
4185 set_bit(hdl, adapter->dev_topo.pd_hdls); in leapraid_sas_pd_hide()
4193 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_sas_pd_hide()
4204 struct leapraid_adapter *adapter, in leapraid_sas_pd_expose() argument
4214 if (!hdl || hdl > adapter->adapter_attr.features.max_dev_handle) { in leapraid_sas_pd_expose()
4215 dev_warn(&adapter->pdev->dev, in leapraid_sas_pd_expose()
4220 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_sas_pd_expose()
4221 sas_dev = leapraid_hold_lock_get_sas_dev_by_hdl(adapter, hdl); in leapraid_sas_pd_expose()
4223 dev_warn(&adapter->pdev->dev, in leapraid_sas_pd_expose()
4226 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_sas_pd_expose()
4232 clear_bit(hdl, adapter->dev_topo.pd_hdls); in leapraid_sas_pd_expose()
4239 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_sas_pd_expose()
4251 struct leapraid_adapter *adapter, in leapraid_sas_vol_visibility() argument
4264 raid_volume = leapraid_raid_volume_find_by_hdl(adapter, hdl); in leapraid_sas_vol_visibility()
4266 dev_warn(&adapter->pdev->dev, in leapraid_sas_vol_visibility()
4272 spin_lock_irqsave(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_sas_vol_visibility()
4275 spin_unlock_irqrestore(&adapter->dev_topo.raid_volume_lock, in leapraid_sas_vol_visibility()
4278 dev_warn(&adapter->pdev->dev, in leapraid_sas_vol_visibility()
4296 spin_unlock_irqrestore(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_sas_vol_visibility()
4300 dev_warn(&adapter->pdev->dev, in leapraid_sas_vol_visibility()
4307 dev_warn(&adapter->pdev->dev, in leapraid_sas_vol_visibility()
4323 struct leapraid_adapter *adapter, in leapraid_sas_volume_add() argument
4333 if (leapraid_cfg_get_volume_wwid(adapter, hdl, &wwid)) { in leapraid_sas_volume_add()
4334 dev_warn(&adapter->pdev->dev, "Failed to read volume page1\n"); in leapraid_sas_volume_add()
4339 dev_warn(&adapter->pdev->dev, "Invalid WWID(handle=0x%x)\n", in leapraid_sas_volume_add()
4344 raid_volume = leapraid_raid_volume_find_by_wwid(adapter, wwid); in leapraid_sas_volume_add()
4346 dev_warn(&adapter->pdev->dev, in leapraid_sas_volume_add()
4358 raid_volume->id = adapter->dev_topo.sas_id++; in leapraid_sas_volume_add()
4362 leapraid_raid_volume_add(adapter, raid_volume); in leapraid_sas_volume_add()
4363 if (!adapter->scan_dev_desc.wait_scan_dev_done) { in leapraid_sas_volume_add()
4364 if (scsi_add_device(adapter->shost, RAID_CHANNEL, in leapraid_sas_volume_add()
4366 leapraid_raid_volume_remove(adapter, raid_volume); in leapraid_sas_volume_add()
4367 dev_info(&adapter->pdev->dev, in leapraid_sas_volume_add()
4370 spin_lock_irqsave(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_sas_volume_add()
4371 leapraid_check_boot_dev(adapter, raid_volume, RAID_CHANNEL); in leapraid_sas_volume_add()
4372 spin_unlock_irqrestore(&adapter->dev_topo.raid_volume_lock, in leapraid_sas_volume_add()
4379 struct leapraid_adapter *adapter, in leapraid_sas_volume_delete_by_ptr() argument
4390 spin_lock_irqsave(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_sas_volume_delete_by_ptr()
4398 spin_unlock_irqrestore(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_sas_volume_delete_by_ptr()
4403 dev_info(&adapter->pdev->dev, in leapraid_sas_volume_delete_by_ptr()
4406 leapraid_raid_volume_remove(adapter, raid_volume); in leapraid_sas_volume_delete_by_ptr()
4412 static void leapraid_sas_volume_delete(struct leapraid_adapter *adapter, in leapraid_sas_volume_delete() argument
4417 raid_volume = leapraid_raid_volume_find_by_hdl(adapter, hdl); in leapraid_sas_volume_delete()
4419 dev_warn(&adapter->pdev->dev, in leapraid_sas_volume_delete()
4425 leapraid_sas_volume_delete_by_ptr(adapter, raid_volume); in leapraid_sas_volume_delete()
4429 static void leapraid_sas_ir_chg_evt(struct leapraid_adapter *adapter, in leapraid_sas_ir_chg_evt() argument
4438 leapraid_sas_volume_add(adapter, evt_data); in leapraid_sas_ir_chg_evt()
4441 leapraid_sas_volume_delete(adapter, in leapraid_sas_ir_chg_evt()
4445 leapraid_sas_pd_add(adapter, evt_data); in leapraid_sas_ir_chg_evt()
4448 leapraid_sas_pd_delete(adapter, evt_data); in leapraid_sas_ir_chg_evt()
4451 leapraid_sas_pd_hide(adapter, evt_data); in leapraid_sas_ir_chg_evt()
4454 leapraid_sas_pd_expose(adapter, evt_data); in leapraid_sas_ir_chg_evt()
4458 leapraid_sas_vol_visibility(adapter, evt_data); in leapraid_sas_ir_chg_evt()
4466 struct leapraid_adapter *adapter, u16 hdl) in leapraid_sas_enc_dev_stat_add_node() argument
4481 rc = leapraid_op_config_page(adapter, &enc_node->pg0, cfgp1, cfgp2, in leapraid_sas_enc_dev_stat_add_node()
4488 spin_lock_irqsave(&adapter->dev_topo.enc_lock, flags); in leapraid_sas_enc_dev_stat_add_node()
4489 enc_exist = leapraid_enc_find_by_hdl(adapter, hdl); in leapraid_sas_enc_dev_stat_add_node()
4491 spin_unlock_irqrestore(&adapter->dev_topo.enc_lock, flags); in leapraid_sas_enc_dev_stat_add_node()
4495 list_add_tail(&enc_node->list, &adapter->dev_topo.enc_list); in leapraid_sas_enc_dev_stat_add_node()
4496 spin_unlock_irqrestore(&adapter->dev_topo.enc_lock, flags); in leapraid_sas_enc_dev_stat_add_node()
4500 struct leapraid_adapter *adapter, u16 hdl) in leapraid_sas_enc_dev_stat_del_node() argument
4508 spin_lock_irqsave(&adapter->dev_topo.enc_lock, flags); in leapraid_sas_enc_dev_stat_del_node()
4509 enc_node = leapraid_enc_find_by_hdl(adapter, hdl); in leapraid_sas_enc_dev_stat_del_node()
4512 spin_unlock_irqrestore(&adapter->dev_topo.enc_lock, flags); in leapraid_sas_enc_dev_stat_del_node()
4518 struct leapraid_adapter *adapter, in leapraid_sas_enc_dev_stat_chg_evt() argument
4524 if (adapter->access_ctrl.shost_recovering) in leapraid_sas_enc_dev_stat_chg_evt()
4532 leapraid_sas_enc_dev_stat_add_node(adapter, enc_hdl); in leapraid_sas_enc_dev_stat_chg_evt()
4535 leapraid_sas_enc_dev_stat_del_node(adapter, enc_hdl); in leapraid_sas_enc_dev_stat_chg_evt()
4543 struct leapraid_adapter *adapter) in leapraid_remove_unresp_sas_end_dev() argument
4549 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_remove_unresp_sas_end_dev()
4551 &adapter->dev_topo.sas_dev_init_list, list) { in leapraid_remove_unresp_sas_end_dev()
4556 leapraid_clear_cached_boot_dev(adapter, sas_dev, 0); in leapraid_remove_unresp_sas_end_dev()
4560 &adapter->dev_topo.sas_dev_list, list) { in leapraid_remove_unresp_sas_end_dev()
4566 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_remove_unresp_sas_end_dev()
4569 leapraid_remove_device(adapter, sas_dev); in leapraid_remove_unresp_sas_end_dev()
4574 dev_warn(&adapter->pdev->dev, in leapraid_remove_unresp_sas_end_dev()
4579 struct leapraid_adapter *adapter) in leapraid_remove_unresp_raid_volumes() argument
4585 spin_lock_irqsave(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_remove_unresp_raid_volumes()
4587 &adapter->dev_topo.raid_volume_list, list) { in leapraid_remove_unresp_raid_volumes()
4593 spin_unlock_irqrestore(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_remove_unresp_raid_volumes()
4596 leapraid_sas_volume_delete_by_ptr(adapter, raid_volume); in leapraid_remove_unresp_raid_volumes()
4599 dev_warn(&adapter->pdev->dev, in leapraid_remove_unresp_raid_volumes()
4603 static void leapraid_remove_unresp_sas_exp(struct leapraid_adapter *adapter) in leapraid_remove_unresp_sas_exp() argument
4609 spin_lock_irqsave(&adapter->dev_topo.topo_node_lock, flags); in leapraid_remove_unresp_sas_exp()
4611 &adapter->dev_topo.exp_list, list) { in leapraid_remove_unresp_sas_exp()
4617 spin_unlock_irqrestore(&adapter->dev_topo.topo_node_lock, flags); in leapraid_remove_unresp_sas_exp()
4621 leapraid_exp_node_rm(adapter, topo_node_exp); in leapraid_remove_unresp_sas_exp()
4623 dev_warn(&adapter->pdev->dev, in leapraid_remove_unresp_sas_exp()
4627 static void leapraid_remove_unresp_dev(struct leapraid_adapter *adapter) in leapraid_remove_unresp_dev() argument
4629 leapraid_remove_unresp_sas_end_dev(adapter); in leapraid_remove_unresp_dev()
4630 if (adapter->adapter_attr.raid_support) in leapraid_remove_unresp_dev()
4631 leapraid_remove_unresp_raid_volumes(adapter); in leapraid_remove_unresp_dev()
4632 leapraid_remove_unresp_sas_exp(adapter); in leapraid_remove_unresp_dev()
4633 leapraid_ublk_io_all_dev(adapter); in leapraid_remove_unresp_dev()
4636 static void leapraid_del_dirty_vphy(struct leapraid_adapter *adapter) in leapraid_del_dirty_vphy() argument
4642 &adapter->dev_topo.card_port_list, list) { in leapraid_del_dirty_vphy()
4661 static void leapraid_del_dirty_card_port(struct leapraid_adapter *adapter) in leapraid_del_dirty_card_port() argument
4666 &adapter->dev_topo.card_port_list, list) { in leapraid_del_dirty_card_port()
4676 static void leapraid_update_dev_qdepth(struct leapraid_adapter *adapter) in leapraid_update_dev_qdepth() argument
4684 attr = &adapter->adapter_attr; in leapraid_update_dev_qdepth()
4685 shost_for_each_device(sdev, adapter->shost) { in leapraid_update_dev_qdepth()
4704 static void leapraid_update_exp_links(struct leapraid_adapter *adapter, in leapraid_update_exp_links() argument
4716 if (leapraid_op_config_page(adapter, &exp_p1, cfgp1, cfgp2, in leapraid_update_exp_links()
4721 adapter, in leapraid_update_exp_links()
4731 static void leapraid_scan_exp_after_reset(struct leapraid_adapter *adapter) in leapraid_scan_exp_after_reset() argument
4743 !leapraid_op_config_page(adapter, &exp_p0, cfgp1, cfgp2, in leapraid_scan_exp_after_reset()
4748 spin_lock_irqsave(&adapter->dev_topo.topo_node_lock, flags); in leapraid_scan_exp_after_reset()
4751 adapter, in leapraid_scan_exp_after_reset()
4753 leapraid_get_port_by_id(adapter, in leapraid_scan_exp_after_reset()
4756 spin_unlock_irqrestore(&adapter->dev_topo.topo_node_lock, in leapraid_scan_exp_after_reset()
4760 leapraid_update_exp_links(adapter, topo_node_exp, hdl); in leapraid_scan_exp_after_reset()
4762 leapraid_exp_add(adapter, hdl); in leapraid_scan_exp_after_reset()
4764 dev_info(&adapter->pdev->dev, in leapraid_scan_exp_after_reset()
4774 struct leapraid_adapter *adapter) in leapraid_scan_phy_disks_after_reset() argument
4789 !leapraid_op_config_page(adapter, &raidpd_p0, in leapraid_scan_phy_disks_after_reset()
4794 sas_dev = leapraid_get_sas_dev_by_hdl(adapter, hdl); in leapraid_scan_phy_disks_after_reset()
4802 if (leapraid_op_config_page(adapter, &sas_dev_p0, cfgp1_extra, in leapraid_scan_phy_disks_after_reset()
4808 if (!leapraid_get_sas_address(adapter, in leapraid_scan_phy_disks_after_reset()
4813 adapter, sas_addr, hdl, in leapraid_scan_phy_disks_after_reset()
4817 adapter, port_id, false)); in leapraid_scan_phy_disks_after_reset()
4819 adapter->adapter_attr.features.max_dev_handle) { in leapraid_scan_phy_disks_after_reset()
4820 dev_warn(&adapter->pdev->dev, in leapraid_scan_phy_disks_after_reset()
4824 set_bit(hdl, adapter->dev_topo.pd_hdls); in leapraid_scan_phy_disks_after_reset()
4825 leapraid_add_dev(adapter, hdl); in leapraid_scan_phy_disks_after_reset()
4827 dev_info(&adapter->pdev->dev, in leapraid_scan_phy_disks_after_reset()
4837 static void leapraid_scan_vol_after_reset(struct leapraid_adapter *adapter) in leapraid_scan_vol_after_reset() argument
4861 !leapraid_op_config_page(adapter, vol_p1, cfgp1, in leapraid_scan_vol_after_reset()
4866 adapter, in leapraid_scan_vol_after_reset()
4875 if (leapraid_op_config_page(adapter, vol_p0, cfgp1_extra, in leapraid_scan_vol_after_reset()
4886 leapraid_sas_volume_add(adapter, &evt_data); in leapraid_scan_vol_after_reset()
4887 dev_info(&adapter->pdev->dev, in leapraid_scan_vol_after_reset()
4897 static void leapraid_scan_sas_dev_after_reset(struct leapraid_adapter *adapter) in leapraid_scan_sas_dev_after_reset() argument
4909 !leapraid_op_config_page(adapter, &sas_dev_p0, cfgp1, cfgp2, in leapraid_scan_sas_dev_after_reset()
4914 hdl > adapter->adapter_attr.features.max_dev_handle) { in leapraid_scan_sas_dev_after_reset()
4915 dev_warn(&adapter->pdev->dev, in leapraid_scan_sas_dev_after_reset()
4925 adapter, in leapraid_scan_sas_dev_after_reset()
4928 adapter, in leapraid_scan_sas_dev_after_reset()
4937 if (!leapraid_get_sas_address(adapter, parent_hdl, in leapraid_scan_sas_dev_after_reset()
4940 adapter, in leapraid_scan_sas_dev_after_reset()
4945 leapraid_get_port_by_id(adapter, in leapraid_scan_sas_dev_after_reset()
4948 leapraid_add_dev(adapter, hdl); in leapraid_scan_sas_dev_after_reset()
4949 dev_info(&adapter->pdev->dev, in leapraid_scan_sas_dev_after_reset()
4958 static void leapraid_scan_all_dev_after_reset(struct leapraid_adapter *adapter) in leapraid_scan_all_dev_after_reset() argument
4960 leapraid_sas_host_add(adapter, adapter->dev_topo.card.phys_num > 0); in leapraid_scan_all_dev_after_reset()
4961 leapraid_scan_exp_after_reset(adapter); in leapraid_scan_all_dev_after_reset()
4962 if (adapter->adapter_attr.raid_support) { in leapraid_scan_all_dev_after_reset()
4963 leapraid_scan_phy_disks_after_reset(adapter); in leapraid_scan_all_dev_after_reset()
4964 leapraid_scan_vol_after_reset(adapter); in leapraid_scan_all_dev_after_reset()
4966 leapraid_scan_sas_dev_after_reset(adapter); in leapraid_scan_all_dev_after_reset()
4969 static void leapraid_hardreset_async_logic(struct leapraid_adapter *adapter) in leapraid_hardreset_async_logic() argument
4973 leapraid_remove_unresp_dev(adapter); in leapraid_hardreset_async_logic()
4974 leapraid_del_dirty_vphy(adapter); in leapraid_hardreset_async_logic()
4975 leapraid_del_dirty_card_port(adapter); in leapraid_hardreset_async_logic()
4976 leapraid_update_dev_qdepth(adapter); in leapraid_hardreset_async_logic()
4977 leapraid_scan_all_dev_after_reset(adapter); in leapraid_hardreset_async_logic()
4979 if (adapter->scan_dev_desc.driver_loading) in leapraid_hardreset_async_logic()
4980 leapraid_scan_dev_done(adapter); in leapraid_hardreset_async_logic()
4981 spin_lock_irqsave(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_hardreset_async_logic()
4982 adapter->access_ctrl.shost_recover_async = 0; in leapraid_hardreset_async_logic()
4983 spin_unlock_irqrestore(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_hardreset_async_logic()
4984 wake_up(&adapter->access_ctrl.shost_recover_wq); in leapraid_hardreset_async_logic()
4987 static int leapraid_send_enc_cmd(struct leapraid_adapter *adapter, in leapraid_send_enc_cmd() argument
4996 mutex_lock(&adapter->driver_cmds.enc_cmd.mutex); in leapraid_send_enc_cmd()
4997 rc = leapraid_check_adapter_is_op(adapter, LEAPRAID_DB_WAIT_OP_SHORT, in leapraid_send_enc_cmd()
5002 adapter->driver_cmds.enc_cmd.status = LEAPRAID_CMD_PENDING; in leapraid_send_enc_cmd()
5003 smid = adapter->driver_cmds.enc_cmd.inter_taskid; in leapraid_send_enc_cmd()
5004 req = leapraid_get_task_desc(adapter, smid); in leapraid_send_enc_cmd()
5007 init_completion(&adapter->driver_cmds.enc_cmd.done); in leapraid_send_enc_cmd()
5008 leapraid_fire_task(adapter, smid); in leapraid_send_enc_cmd()
5009 wait_for_completion_timeout(&adapter->driver_cmds.enc_cmd.done, in leapraid_send_enc_cmd()
5011 if (!(adapter->driver_cmds.enc_cmd.status & LEAPRAID_CMD_DONE)) { in leapraid_send_enc_cmd()
5012 dev_err(&adapter->pdev->dev, in leapraid_send_enc_cmd()
5014 __func__, adapter->driver_cmds.enc_cmd.status); in leapraid_send_enc_cmd()
5015 leapraid_log_req_context(adapter, smid, sep_req); in leapraid_send_enc_cmd()
5018 adapter->driver_cmds.enc_cmd.status); in leapraid_send_enc_cmd()
5023 if (adapter->driver_cmds.enc_cmd.status & LEAPRAID_CMD_REPLY_VALID) in leapraid_send_enc_cmd()
5024 memcpy(sep_rep, &adapter->driver_cmds.enc_cmd.reply, in leapraid_send_enc_cmd()
5028 dev_info(&adapter->pdev->dev, "%s:%d: call hard_reset\n", in leapraid_send_enc_cmd()
5030 leapraid_hard_reset_handler(adapter, FULL_RESET); in leapraid_send_enc_cmd()
5033 adapter->driver_cmds.enc_cmd.status = LEAPRAID_CMD_NOT_USED; in leapraid_send_enc_cmd()
5035 mutex_unlock(&adapter->driver_cmds.enc_cmd.mutex); in leapraid_send_enc_cmd()
5039 static void leapraid_set_led(struct leapraid_adapter *adapter, in leapraid_set_led() argument
5058 if (leapraid_send_enc_cmd(adapter, &sep_rep, &sep_req)) { in leapraid_set_led()
5071 leapraid_send_enc_cmd(adapter, &sep_rep, &sep_req); in leapraid_set_led()
5075 static int leapraid_wait_adapter_recovery(struct leapraid_adapter *adapter) in leapraid_wait_adapter_recovery() argument
5079 while (leapraid_shost_in_recovery(adapter->shost) || in leapraid_wait_adapter_recovery()
5080 READ_ONCE(adapter->access_ctrl.shost_recovering)) { in leapraid_wait_adapter_recovery()
5081 if (READ_ONCE(adapter->access_ctrl.host_removing) || in leapraid_wait_adapter_recovery()
5082 READ_ONCE(adapter->fw_evt_s.fw_evt_cleanup)) { in leapraid_wait_adapter_recovery()
5084 &adapter->reset_desc.adapter_reset_lock, in leapraid_wait_adapter_recovery()
5086 adapter->access_ctrl.shost_recover_async = 0; in leapraid_wait_adapter_recovery()
5088 &adapter->reset_desc.adapter_reset_lock, in leapraid_wait_adapter_recovery()
5091 wake_up(&adapter->access_ctrl.shost_recover_wq); in leapraid_wait_adapter_recovery()
5093 dev_warn(&adapter->pdev->dev, in leapraid_wait_adapter_recovery()
5096 adapter->access_ctrl.shost_recovering, in leapraid_wait_adapter_recovery()
5097 adapter->access_ctrl.host_removing); in leapraid_wait_adapter_recovery()
5103 adapter->access_ctrl.recovery_waitq, in leapraid_wait_adapter_recovery()
5104 (!leapraid_shost_in_recovery(adapter->shost) && in leapraid_wait_adapter_recovery()
5105 !READ_ONCE(adapter->access_ctrl.shost_recovering)), in leapraid_wait_adapter_recovery()
5112 static void leapraid_fw_work(struct leapraid_adapter *adapter, in leapraid_fw_work() argument
5118 spin_lock_irqsave(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_fw_work()
5119 adapter->fw_evt_s.cur_evt = fw_evt; in leapraid_fw_work()
5120 adapter->fw_evt_s.cur_evt_task = current; in leapraid_fw_work()
5121 spin_unlock_irqrestore(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_fw_work()
5122 leapraid_del_fw_evt_from_list(adapter, fw_evt); in leapraid_fw_work()
5123 if (adapter->access_ctrl.host_removing || in leapraid_fw_work()
5124 adapter->access_ctrl.pcie_recovering) { in leapraid_fw_work()
5125 spin_lock_irqsave(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_fw_work()
5127 adapter->fw_evt_s.cur_evt = NULL; in leapraid_fw_work()
5128 adapter->fw_evt_s.cur_evt_task = NULL; in leapraid_fw_work()
5129 spin_unlock_irqrestore(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_fw_work()
5134 leapraid_sas_topo_chg_evt(adapter, fw_evt); in leapraid_fw_work()
5137 leapraid_sas_ir_chg_evt(adapter, fw_evt); in leapraid_fw_work()
5140 leapraid_sas_enc_dev_stat_chg_evt(adapter, fw_evt); in leapraid_fw_work()
5143 if (leapraid_wait_adapter_recovery(adapter)) in leapraid_fw_work()
5146 leapraid_hardreset_async_logic(adapter); in leapraid_fw_work()
5149 sas_dev = leapraid_get_sas_dev_by_hdl(adapter, in leapraid_fw_work()
5151 leapraid_set_led(adapter, sas_dev, true); in leapraid_fw_work()
5154 adapter->scan_dev_desc.scan_start = 0; in leapraid_fw_work()
5160 spin_lock_irqsave(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_fw_work()
5162 adapter->fw_evt_s.cur_evt = NULL; in leapraid_fw_work()
5163 adapter->fw_evt_s.cur_evt_task = NULL; in leapraid_fw_work()
5164 spin_unlock_irqrestore(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_fw_work()
5168 struct leapraid_adapter *adapter, in leapraid_sas_dev_stat_chg_evt() argument
5184 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_sas_dev_stat_chg_evt()
5188 adapter, in leapraid_sas_dev_stat_chg_evt()
5190 leapraid_get_port_by_id(adapter, in leapraid_sas_dev_stat_chg_evt()
5211 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_sas_dev_stat_chg_evt()
5214 static void leapraid_set_volume_delete_flag(struct leapraid_adapter *adapter, in leapraid_set_volume_delete_flag() argument
5221 raid_volume = leapraid_raid_volume_find_by_hdl(adapter, handle); in leapraid_set_volume_delete_flag()
5223 spin_lock_irqsave(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_set_volume_delete_flag()
5229 spin_unlock_irqrestore(&adapter->dev_topo.raid_volume_lock, in leapraid_set_volume_delete_flag()
5236 struct leapraid_adapter *adapter, in leapraid_check_ir_change_evt() argument
5244 adapter, in leapraid_check_ir_change_evt()
5252 adapter->adapter_attr.features.max_dev_handle) { in leapraid_check_ir_change_evt()
5253 dev_warn(&adapter->pdev->dev, in leapraid_check_ir_change_evt()
5257 adapter->dev_topo.pd_hdls); in leapraid_check_ir_change_evt()
5258 leapraid_tgt_rst_send(adapter, phys_disk_dev_hdl); in leapraid_check_ir_change_evt()
5265 struct leapraid_adapter *adapter, in leapraid_topo_del_evts_process_exp_status() argument
5277 spin_lock_irqsave(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_topo_del_evts_process_exp_status()
5279 &adapter->fw_evt_s.fw_evt_list, list) { in leapraid_topo_del_evts_process_exp_status()
5293 spin_unlock_irqrestore(&adapter->fw_evt_s.fw_evt_lock, flags); in leapraid_topo_del_evts_process_exp_status()
5301 struct leapraid_adapter *adapter, in leapraid_check_topo_del_evts() argument
5317 leapraid_tgt_not_responding(adapter, hdl); in leapraid_check_topo_del_evts()
5319 leapraid_topo_del_evts_process_exp_status(adapter, evt_data); in leapraid_check_topo_del_evts()
5323 struct leapraid_adapter *adapter, in leapraid_async_evt_validate() argument
5334 dev_warn(&adapter->pdev->dev, in leapraid_async_evt_validate()
5344 dev_warn(&adapter->pdev->dev, in leapraid_async_evt_validate()
5390 dev_warn(&adapter->pdev->dev, in leapraid_async_evt_validate()
5397 struct leapraid_adapter *adapter, in leapraid_async_process_evt() argument
5403 if (adapter->access_ctrl.host_removing || in leapraid_async_process_evt()
5404 adapter->access_ctrl.pcie_recovering) in leapraid_async_process_evt()
5410 adapter, in leapraid_async_process_evt()
5416 adapter, in leapraid_async_process_evt()
5422 adapter, in leapraid_async_process_evt()
5425 if (adapter->access_ctrl.shost_recovering) { in leapraid_async_process_evt()
5441 struct leapraid_adapter *adapter, in leapraid_async_evt_cb_enqueue() argument
5458 fw_evt->adapter = adapter; in leapraid_async_evt_cb_enqueue()
5460 leapraid_fw_evt_add(adapter, fw_evt); in leapraid_async_evt_cb_enqueue()
5464 static void leapraid_async_evt_cb(struct leapraid_adapter *adapter, in leapraid_async_evt_cb() argument
5469 if (adapter->access_ctrl.host_removing || in leapraid_async_evt_cb()
5470 adapter->access_ctrl.pcie_recovering) in leapraid_async_evt_cb()
5473 evt_notify_rep = leapraid_get_reply_vaddr(adapter, rep_paddr); in leapraid_async_evt_cb()
5477 if (!leapraid_async_evt_validate(adapter, evt_notify_rep)) in leapraid_async_evt_cb()
5480 if (leapraid_async_process_evt(adapter, evt_notify_rep)) in leapraid_async_evt_cb()
5483 leapraid_async_evt_cb_enqueue(adapter, evt_notify_rep); in leapraid_async_evt_cb()
5486 static void leapraid_handle_async_event(struct leapraid_adapter *adapter, in leapraid_handle_async_event() argument
5490 leapraid_get_reply_vaddr(adapter, reply); in leapraid_handle_async_event()
5498 leapraid_async_evt_cb(adapter, msix_index, reply); in leapraid_handle_async_event()
5501 void leapraid_async_turn_on_led(struct leapraid_adapter *adapter, u16 handle) in leapraid_async_turn_on_led() argument
5510 fw_event->adapter = adapter; in leapraid_async_turn_on_led()
5512 leapraid_fw_evt_add(adapter, fw_event); in leapraid_async_turn_on_led()
5516 static void leapraid_hardreset_barrier(struct leapraid_adapter *adapter) in leapraid_hardreset_barrier() argument
5524 fw_event->adapter = adapter; in leapraid_hardreset_barrier()
5526 leapraid_fw_evt_add(adapter, fw_event); in leapraid_hardreset_barrier()
5530 static void leapraid_scan_dev_complete(struct leapraid_adapter *adapter) in leapraid_scan_dev_complete() argument
5539 fw_evt->adapter = adapter; in leapraid_scan_dev_complete()
5540 leapraid_fw_evt_add(adapter, fw_evt); in leapraid_scan_dev_complete()
5544 static void leapraid_handle_scan_cb(struct leapraid_adapter *adapter, in leapraid_handle_scan_cb() argument
5555 adapter->scan_dev_desc.scan_dev_failed = 1; in leapraid_handle_scan_cb()
5563 leapraid_scan_dev_complete(adapter); in leapraid_handle_scan_cb()
5565 adapter->scan_dev_desc.scan_start_failed = status; in leapraid_handle_scan_cb()
5568 static void leapraid_handle_ctl_cb(struct leapraid_adapter *adapter, in leapraid_handle_ctl_cb() argument
5583 memcpy(&adapter->driver_cmds.ctl_cmd.sense, in leapraid_handle_ctl_cb()
5584 leapraid_get_sense_buffer(adapter, taskid), in leapraid_handle_ctl_cb()
5589 static bool leapraid_driver_cmds_done(struct leapraid_adapter *adapter, in leapraid_driver_cmds_done() argument
5594 leapraid_get_reply_vaddr(adapter, rep_paddr); in leapraid_driver_cmds_done()
5598 list_for_each_entry(sp_cmd, &adapter->driver_cmds.special_cmd_list, in leapraid_driver_cmds_done()
5622 leapraid_handle_scan_cb(adapter, _sp_cmd, in leapraid_driver_cmds_done()
5628 leapraid_handle_ctl_cb(adapter, leap_mpi_rep, taskid); in leapraid_driver_cmds_done()
5637 static void leapraid_complete_task(struct leapraid_adapter *adapter, in leapraid_complete_task() argument
5640 bool scsiio_task = taskid <= adapter->shost->can_queue; in leapraid_complete_task()
5643 if (leapraid_scsiio_done(adapter, taskid, msix_idx, rep)) in leapraid_complete_task()
5644 leapraid_free_taskid(adapter, taskid); in leapraid_complete_task()
5648 if (leapraid_driver_cmds_done(adapter, taskid, msix_idx, rep, in leapraid_complete_task()
5649 leapraid_get_cb_idx(adapter, taskid))) in leapraid_complete_task()
5650 leapraid_free_taskid(adapter, taskid); in leapraid_complete_task()
5654 struct leapraid_adapter *adapter, in leapraid_request_descript_handler() argument
5666 leapraid_complete_task(adapter, taskid, msix_idx, 0); in leapraid_request_descript_handler()
5670 if (rep > (u32)adapter->mem_desc.rep_msg_dma + in leapraid_request_descript_handler()
5671 adapter->adapter_attr.rep_msg_qd * in leapraid_request_descript_handler()
5673 rep < (u32)adapter->mem_desc.rep_msg_dma) in leapraid_request_descript_handler()
5677 leapraid_complete_task(adapter, taskid, msix_idx, rep); in leapraid_request_descript_handler()
5679 leapraid_handle_async_event(adapter, msix_idx, rep); in leapraid_request_descript_handler()
5684 adapter->rep_msg_host_idx = in leapraid_request_descript_handler()
5685 (adapter->rep_msg_host_idx == in leapraid_request_descript_handler()
5686 (adapter->adapter_attr.rep_msg_qd - 1)) ? in leapraid_request_descript_handler()
5687 0 : adapter->rep_msg_host_idx + 1; in leapraid_request_descript_handler()
5688 adapter->mem_desc.rep_msg_addr[adapter->rep_msg_host_idx] = in leapraid_request_descript_handler()
5691 writel(adapter->rep_msg_host_idx, in leapraid_request_descript_handler()
5692 &adapter->iomem_base->rep_msg_host_idx); in leapraid_request_descript_handler()
5702 struct leapraid_adapter *adapter = rq->adapter; in leapraid_rep_queue_handler() local
5727 leapraid_request_descript_handler(adapter, rep_desc, in leapraid_rep_queue_handler()
5729 dev_dbg(&adapter->pdev->dev, in leapraid_rep_queue_handler()
5735 (adapter->adapter_attr.rep_desc_qd - in leapraid_rep_queue_handler()
5755 &adapter->iomem_base->rep_post_reg_idx[ in leapraid_rep_queue_handler()
5764 struct leapraid_adapter *adapter = rq->adapter; in leapraid_irq_handler() local
5766 dev_dbg(&adapter->pdev->dev, in leapraid_irq_handler()
5770 if (adapter->mask_int) in leapraid_irq_handler()
5777 void leapraid_sync_irqs(struct leapraid_adapter *adapter, bool poll) in leapraid_sync_irqs() argument
5783 if (!adapter->notification_desc.msix_enable) in leapraid_sync_irqs()
5786 if (adapter->access_ctrl.shost_recovering || in leapraid_sync_irqs()
5787 adapter->access_ctrl.host_removing || in leapraid_sync_irqs()
5788 adapter->access_ctrl.pcie_recovering) in leapraid_sync_irqs()
5791 for (i = 0; i < adapter->notification_desc.iopoll_qdex; i++) { in leapraid_sync_irqs()
5792 int_rq = &adapter->notification_desc.int_rqs[i]; in leapraid_sync_irqs()
5793 if (adapter->access_ctrl.shost_recovering || in leapraid_sync_irqs()
5794 adapter->access_ctrl.host_removing || in leapraid_sync_irqs()
5795 adapter->access_ctrl.pcie_recovering) in leapraid_sync_irqs()
5801 synchronize_irq(pci_irq_vector(adapter->pdev, in leapraid_sync_irqs()
5807 for (i = 0; i < adapter->notification_desc.iopoll_qcnt; i++) { in leapraid_sync_irqs()
5809 &adapter->notification_desc.blk_mq_poll_rqs[i]; in leapraid_sync_irqs()
5810 if (adapter->access_ctrl.shost_recovering || in leapraid_sync_irqs()
5811 adapter->access_ctrl.host_removing || in leapraid_sync_irqs()
5812 adapter->access_ctrl.pcie_recovering) in leapraid_sync_irqs()
5822 static void leapraid_sync_irqs_for_cleanup(struct leapraid_adapter *adapter) in leapraid_sync_irqs_for_cleanup() argument
5824 struct leapraid_notification_desc *desc = &adapter->notification_desc; in leapraid_sync_irqs_for_cleanup()
5828 if (!adapter->mask_int && leapraid_pci_active(adapter)) in leapraid_sync_irqs_for_cleanup()
5829 leapraid_mask_int(adapter); in leapraid_sync_irqs_for_cleanup()
5833 synchronize_irq(pci_irq_vector(adapter->pdev, in leapraid_sync_irqs_for_cleanup()
5838 void leapraid_mq_polling_pause(struct leapraid_adapter *adapter) in leapraid_mq_polling_pause() argument
5844 desc = &adapter->notification_desc; in leapraid_mq_polling_pause()
5845 iopoll_q_count = adapter->adapter_attr.rq_cnt - desc->iopoll_qdex; in leapraid_mq_polling_pause()
5858 void leapraid_mq_polling_resume(struct leapraid_adapter *adapter) in leapraid_mq_polling_resume() argument
5864 desc = &adapter->notification_desc; in leapraid_mq_polling_resume()
5865 iopoll_q_count = adapter->adapter_attr.rq_cnt - desc->iopoll_qdex; in leapraid_mq_polling_resume()
5871 static int leapraid_unlock_host_diag(struct leapraid_adapter *adapter, in leapraid_unlock_host_diag() argument
5891 writel(unlock_seq[i], &adapter->iomem_base->ws); in leapraid_unlock_host_diag()
5895 *host_diag = leapraid_readl(&adapter->iomem_base->host_diag); in leapraid_unlock_host_diag()
5900 dev_err(&adapter->pdev->dev, "Try host reset timeout!\n"); in leapraid_unlock_host_diag()
5904 static int leapraid_host_diag_reset(struct leapraid_adapter *adapter) in leapraid_host_diag_reset() argument
5908 pci_cfg_access_lock(adapter->pdev); in leapraid_host_diag_reset()
5910 mutex_lock(&adapter->reset_desc.host_diag_mutex); in leapraid_host_diag_reset()
5911 if (leapraid_unlock_host_diag(adapter, &host_diag)) in leapraid_host_diag_reset()
5915 &adapter->iomem_base->host_diag); in leapraid_host_diag_reset()
5920 host_diag = leapraid_readl(&adapter->iomem_base->host_diag); in leapraid_host_diag_reset()
5925 writel(0x0, &adapter->iomem_base->ws); in leapraid_host_diag_reset()
5926 mutex_unlock(&adapter->reset_desc.host_diag_mutex); in leapraid_host_diag_reset()
5927 if (!leapraid_wait_adapter_ready(adapter)) in leapraid_host_diag_reset()
5930 pci_cfg_access_unlock(adapter->pdev); in leapraid_host_diag_reset()
5934 mutex_unlock(&adapter->reset_desc.host_diag_mutex); in leapraid_host_diag_reset()
5936 pci_cfg_access_unlock(adapter->pdev); in leapraid_host_diag_reset()
5937 dev_err(&adapter->pdev->dev, "Host diag failed\n"); in leapraid_host_diag_reset()
5956 struct leapraid_adapter *adapter, in leapraid_fill_card_port_table() argument
5965 for (i = 0; i < adapter->dev_topo.card.phys_num; i++) { in leapraid_fill_card_port_table()
5973 if (leapraid_get_sas_address(adapter, in leapraid_fill_card_port_table()
5999 struct leapraid_adapter *adapter, in leapraid_set_new_card_port_table_after_reset() argument
6009 (adapter->dev_topo.card.phys_num * in leapraid_set_new_card_port_table_after_reset()
6016 if (leapraid_op_config_page(adapter, sas_iounit_p0, cfgp1, cfgp2, in leapraid_set_new_card_port_table_after_reset()
6020 port_entry_num = leapraid_fill_card_port_table(adapter, in leapraid_set_new_card_port_table_after_reset()
6028 static void leapraid_update_existing_port(struct leapraid_adapter *adapter, in leapraid_update_existing_port() argument
6038 matched_code = leapraid_check_card_port(adapter, in leapraid_update_existing_port()
6048 leapraid_add_or_del_phys_from_existing_port(adapter, in leapraid_update_existing_port()
6062 leapraid_add_or_del_phys_from_existing_port(adapter, in leapraid_update_existing_port()
6077 struct leapraid_adapter *adapter) in leapraid_update_card_port_after_reset() argument
6085 if (leapraid_get_adapter_phys(adapter, &nr_phys) || !nr_phys) in leapraid_update_card_port_after_reset()
6088 if (!adapter->dev_topo.card.card_phy) { in leapraid_update_card_port_after_reset()
6089 adapter->dev_topo.card.card_phy = in leapraid_update_card_port_after_reset()
6091 if (!adapter->dev_topo.card.card_phy) in leapraid_update_card_port_after_reset()
6095 adapter->dev_topo.card.phys_num = nr_phys; in leapraid_update_card_port_after_reset()
6098 adapter->dev_topo.card.phys_num); in leapraid_update_card_port_after_reset()
6104 adapter, in leapraid_update_card_port_after_reset()
6110 &adapter->dev_topo.card_port_list, list) in leapraid_update_card_port_after_reset()
6115 leapraid_update_existing_port(adapter, in leapraid_update_card_port_after_reset()
6123 struct leapraid_adapter *adapter, in leapraid_is_valid_vphy() argument
6143 if (leapraid_op_config_page(adapter, &phy_p0, cfgp1, cfgp2, in leapraid_is_valid_vphy()
6153 static void leapraid_update_vphy_binding(struct leapraid_adapter *adapter, in leapraid_update_vphy_binding() argument
6162 may_new_card_port = leapraid_get_port_by_id(adapter, in leapraid_update_vphy_binding()
6170 dev_err(&adapter->pdev->dev, in leapraid_update_vphy_binding()
6174 &adapter->dev_topo.card_port_list); in leapraid_update_vphy_binding()
6184 sas_dev = leapraid_get_sas_dev_by_addr(adapter, in leapraid_update_vphy_binding()
6201 static void leapraid_update_vphys_after_reset(struct leapraid_adapter *adapter) in leapraid_update_vphys_after_reset() argument
6216 &adapter->dev_topo.card_port_list, list) { in leapraid_update_vphys_after_reset()
6226 (adapter->dev_topo.card.phys_num * in leapraid_update_vphys_after_reset()
6233 if (leapraid_op_config_page(adapter, sas_iounit_p0, cfgp1, cfgp2, in leapraid_update_vphys_after_reset()
6237 for (i = 0; i < adapter->dev_topo.card.phys_num; i++) { in leapraid_update_vphys_after_reset()
6238 if (!leapraid_is_valid_vphy(adapter, sas_iounit_p0, i)) in leapraid_update_vphys_after_reset()
6244 if (leapraid_get_sas_address(adapter, attached_hdl, in leapraid_update_vphys_after_reset()
6252 &adapter->dev_topo.card_port_list, in leapraid_update_vphys_after_reset()
6271 leapraid_update_vphy_binding(adapter, in leapraid_update_vphys_after_reset()
6289 static void leapraid_mark_all_dev_deleted(struct leapraid_adapter *adapter) in leapraid_mark_all_dev_deleted() argument
6294 shost_for_each_device(sdev, adapter->shost) { in leapraid_mark_all_dev_deleted()
6301 static void leapraid_free_enc_list(struct leapraid_adapter *adapter) in leapraid_free_enc_list() argument
6307 spin_lock_irqsave(&adapter->dev_topo.enc_lock, flags); in leapraid_free_enc_list()
6308 list_splice_init(&adapter->dev_topo.enc_list, &free_list); in leapraid_free_enc_list()
6309 spin_unlock_irqrestore(&adapter->dev_topo.enc_lock, flags); in leapraid_free_enc_list()
6318 struct leapraid_adapter *adapter) in leapraid_rebuild_enc_list_after_reset() argument
6327 leapraid_free_enc_list(adapter); in leapraid_rebuild_enc_list_after_reset()
6336 rc = leapraid_op_config_page(adapter, &enc_node->pg0, cfgp1, in leapraid_rebuild_enc_list_after_reset()
6343 spin_lock_irqsave(&adapter->dev_topo.enc_lock, flags); in leapraid_rebuild_enc_list_after_reset()
6344 list_add_tail(&enc_node->list, &adapter->dev_topo.enc_list); in leapraid_rebuild_enc_list_after_reset()
6345 spin_unlock_irqrestore(&adapter->dev_topo.enc_lock, flags); in leapraid_rebuild_enc_list_after_reset()
6349 static void leapraid_mark_resp_sas_dev(struct leapraid_adapter *adapter, in leapraid_mark_resp_sas_dev() argument
6362 card_port = leapraid_get_port_by_id(adapter, sas_dev_p0->physical_port, in leapraid_mark_resp_sas_dev()
6366 spin_lock_irqsave(&adapter->dev_topo.enc_lock, enc_flags); in leapraid_mark_resp_sas_dev()
6367 enc_node = leapraid_enc_find_by_hdl(adapter, enc_hdl); in leapraid_mark_resp_sas_dev()
6370 spin_unlock_irqrestore(&adapter->dev_topo.enc_lock, enc_flags); in leapraid_mark_resp_sas_dev()
6372 dev_info(&adapter->pdev->dev, in leapraid_mark_resp_sas_dev()
6377 spin_lock_irqsave(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_mark_resp_sas_dev()
6378 list_for_each_entry(sas_dev, &adapter->dev_topo.sas_dev_list, list) { in leapraid_mark_resp_sas_dev()
6429 dev_info(&adapter->pdev->dev, in leapraid_mark_resp_sas_dev()
6439 spin_unlock_irqrestore(&adapter->dev_topo.sas_dev_lock, flags); in leapraid_mark_resp_sas_dev()
6442 static void leapraid_search_resp_sas_dev(struct leapraid_adapter *adapter) in leapraid_search_resp_sas_dev() argument
6449 if (list_empty(&adapter->dev_topo.sas_dev_list)) in leapraid_search_resp_sas_dev()
6454 !leapraid_op_config_page(adapter, &sas_dev_p0, in leapraid_search_resp_sas_dev()
6461 leapraid_mark_resp_sas_dev(adapter, &sas_dev_p0); in leapraid_search_resp_sas_dev()
6465 static void leapraid_mark_resp_raid_volume(struct leapraid_adapter *adapter, in leapraid_mark_resp_raid_volume() argument
6475 raid_volume = leapraid_raid_volume_find_by_wwid(adapter, wwid); in leapraid_mark_resp_raid_volume()
6479 spin_lock_irqsave(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_mark_resp_raid_volume()
6481 spin_unlock_irqrestore(&adapter->dev_topo.raid_volume_lock, in leapraid_mark_resp_raid_volume()
6501 spin_unlock_irqrestore(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_mark_resp_raid_volume()
6507 dev_info(&adapter->pdev->dev, in leapraid_mark_resp_raid_volume()
6514 static void leapraid_search_resp_raid_volume(struct leapraid_adapter *adapter) in leapraid_search_resp_raid_volume() argument
6528 if (!adapter->adapter_attr.raid_support) in leapraid_search_resp_raid_volume()
6531 spin_lock_irqsave(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_search_resp_raid_volume()
6532 is_empty = list_empty(&adapter->dev_topo.raid_volume_list); in leapraid_search_resp_raid_volume()
6533 spin_unlock_irqrestore(&adapter->dev_topo.raid_volume_lock, flags); in leapraid_search_resp_raid_volume()
6539 !leapraid_op_config_page(adapter, &raidvol_p1, cfgp1, cfgp2, in leapraid_search_resp_raid_volume()
6545 if (leapraid_op_config_page(adapter, &raidvol_p0, cfgp1_extra, in leapraid_search_resp_raid_volume()
6553 adapter, in leapraid_search_resp_raid_volume()
6558 memset(adapter->dev_topo.pd_hdls, 0, adapter->dev_topo.pd_hdls_sz); in leapraid_search_resp_raid_volume()
6561 !leapraid_op_config_page(adapter, &raidpd_p0, cfgp1, cfgp2, in leapraid_search_resp_raid_volume()
6567 hdl > adapter->adapter_attr.features.max_dev_handle) in leapraid_search_resp_raid_volume()
6568 dev_warn(&adapter->pdev->dev, in leapraid_search_resp_raid_volume()
6571 set_bit(hdl, adapter->dev_topo.pd_hdls); in leapraid_search_resp_raid_volume()
6575 static void leapraid_mark_resp_exp(struct leapraid_adapter *adapter, in leapraid_mark_resp_exp() argument
6584 struct leapraid_card_port *card_port = leapraid_get_port_by_id(adapter, in leapraid_mark_resp_exp()
6593 spin_lock_irqsave(&adapter->dev_topo.enc_lock, enc_flags); in leapraid_mark_resp_exp()
6594 enc_node = leapraid_enc_find_by_hdl(adapter, enc_hdl); in leapraid_mark_resp_exp()
6597 spin_unlock_irqrestore(&adapter->dev_topo.enc_lock, enc_flags); in leapraid_mark_resp_exp()
6600 spin_lock_irqsave(&adapter->dev_topo.topo_node_lock, flags); in leapraid_mark_resp_exp()
6601 list_for_each_entry(topo_node_exp, &adapter->dev_topo.exp_list, list) { in leapraid_mark_resp_exp()
6612 dev_info(&adapter->pdev->dev, in leapraid_mark_resp_exp()
6621 spin_unlock_irqrestore(&adapter->dev_topo.topo_node_lock, flags); in leapraid_mark_resp_exp()
6624 static void leapraid_search_resp_exp(struct leapraid_adapter *adapter) in leapraid_search_resp_exp() argument
6633 if (list_empty(&adapter->dev_topo.exp_list)) in leapraid_search_resp_exp()
6638 !leapraid_op_config_page(adapter, &exp_p0, cfgp1, cfgp2, in leapraid_search_resp_exp()
6645 dev_dbg(&adapter->pdev->dev, in leapraid_search_resp_exp()
6648 adapter->adapter_attr.enable_mp ? port : in leapraid_search_resp_exp()
6650 leapraid_mark_resp_exp(adapter, &exp_p0); in leapraid_search_resp_exp()
6654 void leapraid_wait_cmds_done(struct leapraid_adapter *adapter) in leapraid_wait_cmds_done() argument
6660 adapter->reset_desc.pending_io_cnt = 0; in leapraid_wait_cmds_done()
6661 if (!leapraid_pci_active(adapter)) { in leapraid_wait_cmds_done()
6662 dev_err(&adapter->pdev->dev, in leapraid_wait_cmds_done()
6664 adapter->adapter_attr.name, __func__); in leapraid_wait_cmds_done()
6668 if (leapraid_get_adapter_state(adapter) != LEAPRAID_DB_OPERATIONAL) in leapraid_wait_cmds_done()
6671 spin_lock_irqsave(&adapter->dynamic_task_desc.task_lock, flags); in leapraid_wait_cmds_done()
6672 for (i = 1; i <= adapter->shost->can_queue; i++) { in leapraid_wait_cmds_done()
6673 io_req_tracker = leapraid_get_io_tracker_from_taskid(adapter, in leapraid_wait_cmds_done()
6677 adapter->reset_desc.pending_io_cnt++; in leapraid_wait_cmds_done()
6679 spin_unlock_irqrestore(&adapter->dynamic_task_desc.task_lock, flags); in leapraid_wait_cmds_done()
6681 if (!adapter->reset_desc.pending_io_cnt) in leapraid_wait_cmds_done()
6684 wait_event_timeout(adapter->reset_desc.reset_wait_queue, in leapraid_wait_cmds_done()
6685 adapter->reset_desc.pending_io_cnt == 0, in leapraid_wait_cmds_done()
6689 int leapraid_hard_reset_handler(struct leapraid_adapter *adapter, in leapraid_hard_reset_handler() argument
6696 mutex_lock(&adapter->reset_desc.adapter_reset_mutex); in leapraid_hard_reset_handler()
6698 if (adapter->access_ctrl.shost_recover_async) { in leapraid_hard_reset_handler()
6699 rc = adapter->reset_desc.adapter_reset_results; in leapraid_hard_reset_handler()
6700 dev_info(&adapter->pdev->dev, in leapraid_hard_reset_handler()
6703 mutex_unlock(&adapter->reset_desc.adapter_reset_mutex); in leapraid_hard_reset_handler()
6707 if (!leapraid_pci_active(adapter)) { in leapraid_hard_reset_handler()
6708 if (leapraid_pci_removed(adapter)) { in leapraid_hard_reset_handler()
6709 dev_info(&adapter->pdev->dev, in leapraid_hard_reset_handler()
6711 leapraid_mq_polling_pause(adapter); in leapraid_hard_reset_handler()
6712 leapraid_clean_active_scsi_cmds(adapter); in leapraid_hard_reset_handler()
6713 leapraid_mq_polling_resume(adapter); in leapraid_hard_reset_handler()
6715 dev_err(&adapter->pdev->dev, "PCIe unavailable!\n"); in leapraid_hard_reset_handler()
6716 mutex_unlock(&adapter->reset_desc.adapter_reset_mutex); in leapraid_hard_reset_handler()
6720 dev_info(&adapter->pdev->dev, "Starting hard reset\n"); in leapraid_hard_reset_handler()
6722 spin_lock_irqsave(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_hard_reset_handler()
6723 adapter->access_ctrl.shost_recovering = 1; in leapraid_hard_reset_handler()
6724 adapter->access_ctrl.shost_recover_async = 1; in leapraid_hard_reset_handler()
6725 spin_unlock_irqrestore(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_hard_reset_handler()
6727 leapraid_wait_cmds_done(adapter); in leapraid_hard_reset_handler()
6728 leapraid_mask_int(adapter); in leapraid_hard_reset_handler()
6729 leapraid_mq_polling_pause(adapter); in leapraid_hard_reset_handler()
6730 rc = leapraid_make_adapter_ready(adapter, type); in leapraid_hard_reset_handler()
6732 dev_err(&adapter->pdev->dev, in leapraid_hard_reset_handler()
6737 rc = leapraid_fw_log_init(adapter); in leapraid_hard_reset_handler()
6739 dev_err(&adapter->pdev->dev, "Firmware log init failed\n"); in leapraid_hard_reset_handler()
6743 leapraid_clean_active_cmds(adapter); in leapraid_hard_reset_handler()
6744 if (adapter->scan_dev_desc.driver_loading && in leapraid_hard_reset_handler()
6745 adapter->scan_dev_desc.scan_dev_failed) { in leapraid_hard_reset_handler()
6746 dev_err(&adapter->pdev->dev, in leapraid_hard_reset_handler()
6748 adapter->access_ctrl.host_removing = 1; in leapraid_hard_reset_handler()
6753 rc = leapraid_make_adapter_available(adapter); in leapraid_hard_reset_handler()
6755 dev_info(&adapter->pdev->dev, in leapraid_hard_reset_handler()
6757 if (adapter->adapter_attr.enable_mp) { in leapraid_hard_reset_handler()
6758 leapraid_update_card_port_after_reset(adapter); in leapraid_hard_reset_handler()
6759 leapraid_update_vphys_after_reset(adapter); in leapraid_hard_reset_handler()
6761 leapraid_mark_all_dev_deleted(adapter); in leapraid_hard_reset_handler()
6762 leapraid_rebuild_enc_list_after_reset(adapter); in leapraid_hard_reset_handler()
6763 leapraid_search_resp_sas_dev(adapter); in leapraid_hard_reset_handler()
6764 leapraid_search_resp_raid_volume(adapter); in leapraid_hard_reset_handler()
6765 leapraid_search_resp_exp(adapter); in leapraid_hard_reset_handler()
6766 leapraid_hardreset_barrier(adapter); in leapraid_hard_reset_handler()
6770 dev_err(&adapter->pdev->dev, "Hard reset failed\n"); in leapraid_hard_reset_handler()
6772 spin_lock_irqsave(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_hard_reset_handler()
6773 adapter->reset_desc.adapter_reset_results = rc; in leapraid_hard_reset_handler()
6774 adapter->access_ctrl.shost_recovering = 0; in leapraid_hard_reset_handler()
6775 wake_up(&adapter->access_ctrl.recovery_waitq); in leapraid_hard_reset_handler()
6777 adapter->access_ctrl.shost_recover_async = 0; in leapraid_hard_reset_handler()
6780 spin_unlock_irqrestore(&adapter->reset_desc.adapter_reset_lock, flags); in leapraid_hard_reset_handler()
6782 wake_up(&adapter->access_ctrl.shost_recover_wq); in leapraid_hard_reset_handler()
6784 adapter->reset_desc.reset_cnt++; in leapraid_hard_reset_handler()
6785 mutex_unlock(&adapter->reset_desc.adapter_reset_mutex); in leapraid_hard_reset_handler()
6788 leapraid_clean_active_scsi_cmds(adapter); in leapraid_hard_reset_handler()
6789 leapraid_mq_polling_resume(adapter); in leapraid_hard_reset_handler()
6794 static int leapraid_get_adapter_features(struct leapraid_adapter *adapter) in leapraid_get_adapter_features() argument
6804 db = leapraid_readl(&adapter->iomem_base->db); in leapraid_get_adapter_features()
6807 dev_err(&adapter->pdev->dev, in leapraid_get_adapter_features()
6814 !leapraid_wait_adapter_ready(adapter)) { in leapraid_get_adapter_features()
6815 dev_err(&adapter->pdev->dev, in leapraid_get_adapter_features()
6825 r = leapraid_handshake_func(adapter, in leapraid_get_adapter_features()
6831 dev_err(&adapter->pdev->dev, in leapraid_get_adapter_features()
6833 adapter->adapter_attr.name, __func__, r); in leapraid_get_adapter_features()
6837 memset(&adapter->adapter_attr.features, 0, in leapraid_get_adapter_features()
6839 adapter->adapter_attr.features.req_slot = in leapraid_get_adapter_features()
6841 adapter->adapter_attr.features.hp_slot = in leapraid_get_adapter_features()
6843 adapter->adapter_attr.features.adapter_caps = in leapraid_get_adapter_features()
6845 adapter->adapter_attr.features.max_msix_vectors = in leapraid_get_adapter_features()
6847 adapter->adapter_attr.features.max_volumes = in leapraid_get_adapter_features()
6849 if (!adapter->adapter_attr.features.max_volumes) in leapraid_get_adapter_features()
6850 adapter->adapter_attr.features.max_volumes = in leapraid_get_adapter_features()
6852 adapter->adapter_attr.features.max_dev_handle = in leapraid_get_adapter_features()
6854 if (!adapter->adapter_attr.features.max_dev_handle) in leapraid_get_adapter_features()
6855 adapter->adapter_attr.features.max_dev_handle = in leapraid_get_adapter_features()
6857 adapter->adapter_attr.features.min_dev_handle = in leapraid_get_adapter_features()
6859 if (adapter->adapter_attr.features.adapter_caps & in leapraid_get_adapter_features()
6861 adapter->adapter_attr.raid_support = 1; in leapraid_get_adapter_features()
6862 adapter->adapter_attr.wideport_max_queue_depth = in leapraid_get_adapter_features()
6866 adapter->adapter_attr.narrowport_max_queue_depth = in leapraid_get_adapter_features()
6870 adapter->adapter_attr.sata_max_queue_depth = in leapraid_get_adapter_features()
6874 adapter->adapter_attr.raid_volume_max_queue_depth = in leapraid_get_adapter_features()
6876 dev_info(&adapter->pdev->dev, in leapraid_get_adapter_features()
6878 adapter->adapter_attr.wideport_max_queue_depth, in leapraid_get_adapter_features()
6879 adapter->adapter_attr.narrowport_max_queue_depth, in leapraid_get_adapter_features()
6880 adapter->adapter_attr.sata_max_queue_depth, in leapraid_get_adapter_features()
6881 adapter->adapter_attr.raid_volume_max_queue_depth); in leapraid_get_adapter_features()
6882 if (WARN_ON(!(adapter->adapter_attr.features.adapter_caps & in leapraid_get_adapter_features()
6885 adapter->adapter_attr.features.fw_version = in leapraid_get_adapter_features()
6888 fw_major = (adapter->adapter_attr.features.fw_version >> in leapraid_get_adapter_features()
6890 fw_minor = (adapter->adapter_attr.features.fw_version >> in leapraid_get_adapter_features()
6892 fw_build = (adapter->adapter_attr.features.fw_version >> in leapraid_get_adapter_features()
6895 adapter->adapter_attr.features.fw_version & LEAPRAID_VER_MASK; in leapraid_get_adapter_features()
6897 dev_info(&adapter->pdev->dev, in leapraid_get_adapter_features()
6900 adapter->adapter_attr.features.fw_version); in leapraid_get_adapter_features()
6902 adapter->adapter_attr.features.msg_ver = in leapraid_get_adapter_features()
6904 adapter->adapter_attr.features.product_id = in leapraid_get_adapter_features()
6906 dev_info(&adapter->pdev->dev, in leapraid_get_adapter_features()
6908 adapter->adapter_attr.features.msg_ver, in leapraid_get_adapter_features()
6909 adapter->adapter_attr.features.product_id); in leapraid_get_adapter_features()
6911 if (adapter->adapter_attr.features.msg_ver < 0x1000) { in leapraid_get_adapter_features()
6912 dev_err(&adapter->pdev->dev, "Device not supported\n"); in leapraid_get_adapter_features()
6915 adapter->shost->max_id = LEAPRAID_INVALID_INITIAL_VALUE; in leapraid_get_adapter_features()
6920 static inline void leapraid_disable_pcie(struct leapraid_adapter *adapter) in leapraid_disable_pcie() argument
6922 mutex_lock(&adapter->access_ctrl.pci_access_lock); in leapraid_disable_pcie()
6923 if (adapter->iomem_base) { in leapraid_disable_pcie()
6924 iounmap(adapter->iomem_base); in leapraid_disable_pcie()
6925 adapter->iomem_base = NULL; in leapraid_disable_pcie()
6927 if (pci_is_enabled(adapter->pdev)) { in leapraid_disable_pcie()
6928 pci_release_regions(adapter->pdev); in leapraid_disable_pcie()
6929 pci_disable_device(adapter->pdev); in leapraid_disable_pcie()
6931 mutex_unlock(&adapter->access_ctrl.pci_access_lock); in leapraid_disable_pcie()
6934 static int leapraid_enable_pcie(struct leapraid_adapter *adapter) in leapraid_enable_pcie() argument
6939 rc = pci_enable_device(adapter->pdev); in leapraid_enable_pcie()
6941 dev_err(&adapter->pdev->dev, "Failed to enable PCI device\n"); in leapraid_enable_pcie()
6945 rc = pci_request_regions(adapter->pdev, LEAPRAID_DRIVER_NAME); in leapraid_enable_pcie()
6947 dev_err(&adapter->pdev->dev, in leapraid_enable_pcie()
6954 adapter->adapter_attr.use_32_dma_mask = 0; in leapraid_enable_pcie()
6957 adapter->adapter_attr.use_32_dma_mask = 1; in leapraid_enable_pcie()
6960 rc = dma_set_mask_and_coherent(&adapter->pdev->dev, dma_mask); in leapraid_enable_pcie()
6962 dev_err(&adapter->pdev->dev, in leapraid_enable_pcie()
6966 adapter->iomem_base = ioremap(pci_resource_start(adapter->pdev, 0), in leapraid_enable_pcie()
6968 if (!adapter->iomem_base) { in leapraid_enable_pcie()
6969 dev_err(&adapter->pdev->dev, in leapraid_enable_pcie()
6974 pci_set_master(adapter->pdev); in leapraid_enable_pcie()
6979 static void leapraid_cpus_on_irq(struct leapraid_adapter *adapter) in leapraid_cpus_on_irq() argument
6985 total_msix = adapter->notification_desc.iopoll_qdex; in leapraid_cpus_on_irq()
6993 for (index = 0; index < adapter->notification_desc.iopoll_qdex; in leapraid_cpus_on_irq()
6995 int_rq = &adapter->notification_desc.int_rqs[index]; in leapraid_cpus_on_irq()
6997 if (cpu >= adapter->notification_desc.msix_cpu_map_sz) in leapraid_cpus_on_irq()
7004 if (cpu >= adapter->notification_desc.msix_cpu_map_sz) in leapraid_cpus_on_irq()
7007 adapter->notification_desc.msix_cpu_map[cpu] = in leapraid_cpus_on_irq()
7014 static void leapraid_map_msix_to_cpu(struct leapraid_adapter *adapter) in leapraid_map_msix_to_cpu() argument
7021 if (!adapter->adapter_attr.rq_cnt) in leapraid_map_msix_to_cpu()
7024 for (i = 0; i < adapter->notification_desc.iopoll_qdex; i++) { in leapraid_map_msix_to_cpu()
7025 int_rq = &adapter->notification_desc.int_rqs[i]; in leapraid_map_msix_to_cpu()
7026 affinity_mask = pci_irq_get_affinity(adapter->pdev, in leapraid_map_msix_to_cpu()
7029 dev_warn(&adapter->pdev->dev, in leapraid_map_msix_to_cpu()
7036 if (cpu >= adapter->notification_desc.msix_cpu_map_sz) in leapraid_map_msix_to_cpu()
7039 adapter->notification_desc.msix_cpu_map[cpu] = in leapraid_map_msix_to_cpu()
7045 leapraid_cpus_on_irq(adapter); in leapraid_map_msix_to_cpu()
7048 static int leapraid_alloc_msix_cpu_map(struct leapraid_adapter *adapter) in leapraid_alloc_msix_cpu_map() argument
7050 adapter->notification_desc.msix_cpu_map_sz = nr_cpu_ids; in leapraid_alloc_msix_cpu_map()
7051 adapter->notification_desc.msix_cpu_map = in leapraid_alloc_msix_cpu_map()
7052 kzalloc(adapter->notification_desc.msix_cpu_map_sz, in leapraid_alloc_msix_cpu_map()
7054 if (!adapter->notification_desc.msix_cpu_map) in leapraid_alloc_msix_cpu_map()
7061 struct leapraid_adapter *adapter) in leapraid_configure_reply_queue_affinity() argument
7063 if (!adapter || !adapter->notification_desc.msix_enable) in leapraid_configure_reply_queue_affinity()
7066 leapraid_map_msix_to_cpu(adapter); in leapraid_configure_reply_queue_affinity()
7069 static void leapraid_free_irq(struct leapraid_adapter *adapter) in leapraid_free_irq() argument
7075 for (i = 0; adapter->notification_desc.int_rqs && in leapraid_free_irq()
7076 i < adapter->notification_desc.int_rqs_allocated; i++) { in leapraid_free_irq()
7077 int_rq = &adapter->notification_desc.int_rqs[i]; in leapraid_free_irq()
7081 irq = pci_irq_vector(adapter->pdev, int_rq->rq.msix_idx); in leapraid_free_irq()
7085 adapter->notification_desc.int_rqs_allocated = 0; in leapraid_free_irq()
7087 if (adapter->notification_desc.irq_vectors_allocated) { in leapraid_free_irq()
7088 pci_free_irq_vectors(adapter->pdev); in leapraid_free_irq()
7089 adapter->notification_desc.irq_vectors_allocated = 0; in leapraid_free_irq()
7092 adapter->notification_desc.msix_enable = 0; in leapraid_free_irq()
7094 kfree(adapter->notification_desc.blk_mq_poll_rqs); in leapraid_free_irq()
7095 adapter->notification_desc.blk_mq_poll_rqs = NULL; in leapraid_free_irq()
7097 kfree(adapter->notification_desc.int_rqs); in leapraid_free_irq()
7098 adapter->notification_desc.int_rqs = NULL; in leapraid_free_irq()
7100 kfree(adapter->notification_desc.msix_cpu_map); in leapraid_free_irq()
7101 adapter->notification_desc.msix_cpu_map = NULL; in leapraid_free_irq()
7102 adapter->notification_desc.msix_cpu_map_sz = 0; in leapraid_free_irq()
7103 adapter->notification_desc.iopoll_qdex = 0; in leapraid_free_irq()
7104 adapter->notification_desc.iopoll_qcnt = 0; in leapraid_free_irq()
7107 static int leapraid_setup_irqs(struct leapraid_adapter *adapter) in leapraid_setup_irqs() argument
7109 int irq_mode = adapter->notification_desc.irq_mode; in leapraid_setup_irqs()
7115 adapter->pdev, in leapraid_setup_irqs()
7116 adapter->notification_desc.iopoll_qdex, in leapraid_setup_irqs()
7117 adapter->notification_desc.iopoll_qdex, in leapraid_setup_irqs()
7120 dev_err(&adapter->pdev->dev, in leapraid_setup_irqs()
7122 adapter->notification_desc.iopoll_qdex); in leapraid_setup_irqs()
7126 adapter->notification_desc.irq_vectors_allocated = 1; in leapraid_setup_irqs()
7129 for (i = 0; i < adapter->notification_desc.iopoll_qdex; i++) { in leapraid_setup_irqs()
7130 adapter->notification_desc.int_rqs[i].rq.adapter = adapter; in leapraid_setup_irqs()
7131 adapter->notification_desc.int_rqs[i].rq.msix_idx = i; in leapraid_setup_irqs()
7132 atomic_set(&adapter->notification_desc.int_rqs[i].rq.busy, 0); in leapraid_setup_irqs()
7134 snprintf(adapter->notification_desc.int_rqs[i].rq.name, in leapraid_setup_irqs()
7137 adapter->adapter_attr.id, i); in leapraid_setup_irqs()
7139 snprintf(adapter->notification_desc.int_rqs[i].rq.name, in leapraid_setup_irqs()
7142 adapter->adapter_attr.id, i); in leapraid_setup_irqs()
7144 rc = request_irq(pci_irq_vector(adapter->pdev, i), in leapraid_setup_irqs()
7147 adapter->notification_desc.int_rqs[i].rq.name, in leapraid_setup_irqs()
7148 &adapter->notification_desc.int_rqs[i].rq); in leapraid_setup_irqs()
7150 dev_err(&adapter->pdev->dev, in leapraid_setup_irqs()
7152 adapter->notification_desc.int_rqs[i].rq.name); in leapraid_setup_irqs()
7155 adapter->notification_desc.int_rqs_allocated++; in leapraid_setup_irqs()
7161 static int leapraid_setup_legacy_int(struct leapraid_adapter *adapter) in leapraid_setup_legacy_int() argument
7165 adapter->notification_desc.int_rqs[0].rq.adapter = adapter; in leapraid_setup_legacy_int()
7166 adapter->notification_desc.int_rqs[0].rq.msix_idx = 0; in leapraid_setup_legacy_int()
7167 atomic_set(&adapter->notification_desc.int_rqs[0].rq.busy, 0); in leapraid_setup_legacy_int()
7168 snprintf(adapter->notification_desc.int_rqs[0].rq.name, in leapraid_setup_legacy_int()
7170 LEAPRAID_DRIVER_NAME, adapter->adapter_attr.id); in leapraid_setup_legacy_int()
7173 adapter->pdev, in leapraid_setup_legacy_int()
7174 adapter->notification_desc.iopoll_qdex, in leapraid_setup_legacy_int()
7175 adapter->notification_desc.iopoll_qdex, in leapraid_setup_legacy_int()
7179 dev_err(&adapter->pdev->dev, in leapraid_setup_legacy_int()
7184 adapter->notification_desc.irq_vectors_allocated = 1; in leapraid_setup_legacy_int()
7185 adapter->notification_desc.irq_mode = LEAPRAID_INTERRUPT_MODE_LEGACY; in leapraid_setup_legacy_int()
7186 rc = request_irq(pci_irq_vector(adapter->pdev, 0), in leapraid_setup_legacy_int()
7189 adapter->notification_desc.int_rqs[0].rq.name, in leapraid_setup_legacy_int()
7190 &adapter->notification_desc.int_rqs[0].rq); in leapraid_setup_legacy_int()
7192 irq_set_affinity_hint(pci_irq_vector(adapter->pdev, 0), NULL); in leapraid_setup_legacy_int()
7193 pci_free_irq_vectors(adapter->pdev); in leapraid_setup_legacy_int()
7194 adapter->notification_desc.irq_vectors_allocated = 0; in leapraid_setup_legacy_int()
7195 dev_err(&adapter->pdev->dev, in leapraid_setup_legacy_int()
7197 adapter->notification_desc.int_rqs[0].rq.name); in leapraid_setup_legacy_int()
7200 adapter->notification_desc.int_rqs_allocated = 1; in leapraid_setup_legacy_int()
7204 static int leapraid_set_legacy_int(struct leapraid_adapter *adapter) in leapraid_set_legacy_int() argument
7208 rc = leapraid_alloc_msix_cpu_map(adapter); in leapraid_set_legacy_int()
7212 adapter->adapter_attr.rq_cnt = 1; in leapraid_set_legacy_int()
7213 adapter->notification_desc.iopoll_qdex = in leapraid_set_legacy_int()
7214 adapter->adapter_attr.rq_cnt; in leapraid_set_legacy_int()
7215 adapter->notification_desc.iopoll_qcnt = 0; in leapraid_set_legacy_int()
7216 dev_info(&adapter->pdev->dev, in leapraid_set_legacy_int()
7218 adapter->adapter_attr.rq_cnt, in leapraid_set_legacy_int()
7219 adapter->notification_desc.iopoll_qdex, in leapraid_set_legacy_int()
7220 adapter->notification_desc.iopoll_qcnt); in leapraid_set_legacy_int()
7221 adapter->notification_desc.int_rqs = in leapraid_set_legacy_int()
7223 adapter->notification_desc.iopoll_qdex); in leapraid_set_legacy_int()
7224 if (!adapter->notification_desc.int_rqs) in leapraid_set_legacy_int()
7227 return leapraid_setup_legacy_int(adapter); in leapraid_set_legacy_int()
7230 static int leapraid_set_msix(struct leapraid_adapter *adapter) in leapraid_set_msix() argument
7236 msix_cnt = pci_msix_vec_count(adapter->pdev); in leapraid_set_msix()
7238 adapter->adapter_attr.features.max_msix_vectors == 0) { in leapraid_set_msix()
7239 dev_info(&adapter->pdev->dev, "MSIX unsupported!\n"); in leapraid_set_msix()
7244 adapter->adapter_attr.features.max_msix_vectors); in leapraid_set_msix()
7247 adapter->adapter_attr.rq_cnt = 1; in leapraid_set_msix()
7249 adapter->adapter_attr.rq_cnt = min_t(int, in leapraid_set_msix()
7254 adapter->adapter_attr.rq_cnt = min_t( in leapraid_set_msix()
7255 int, max_msix_vectors, adapter->adapter_attr.rq_cnt); in leapraid_set_msix()
7257 if (adapter->adapter_attr.rq_cnt <= 1) in leapraid_set_msix()
7258 adapter->shost->host_tagset = 0; in leapraid_set_msix()
7259 if (adapter->shost->host_tagset) { in leapraid_set_msix()
7261 if (iopoll_qcnt >= adapter->adapter_attr.rq_cnt) in leapraid_set_msix()
7265 adapter->notification_desc.blk_mq_poll_rqs = in leapraid_set_msix()
7268 if (!adapter->notification_desc.blk_mq_poll_rqs) in leapraid_set_msix()
7270 adapter->adapter_attr.rq_cnt = in leapraid_set_msix()
7271 min(adapter->adapter_attr.rq_cnt + iopoll_qcnt, in leapraid_set_msix()
7275 adapter->notification_desc.iopoll_qdex = in leapraid_set_msix()
7276 adapter->adapter_attr.rq_cnt - iopoll_qcnt; in leapraid_set_msix()
7278 adapter->notification_desc.iopoll_qcnt = iopoll_qcnt; in leapraid_set_msix()
7279 dev_info(&adapter->pdev->dev, in leapraid_set_msix()
7281 adapter->adapter_attr.rq_cnt, in leapraid_set_msix()
7282 adapter->notification_desc.iopoll_qdex, in leapraid_set_msix()
7283 adapter->notification_desc.iopoll_qcnt); in leapraid_set_msix()
7285 adapter->notification_desc.int_rqs = in leapraid_set_msix()
7287 adapter->notification_desc.iopoll_qdex); in leapraid_set_msix()
7288 if (!adapter->notification_desc.int_rqs) in leapraid_set_msix()
7291 for (i = 0; i < adapter->notification_desc.iopoll_qcnt; i++) { in leapraid_set_msix()
7292 adapter->notification_desc.blk_mq_poll_rqs[i].rq.adapter = in leapraid_set_msix()
7293 adapter; in leapraid_set_msix()
7294 adapter->notification_desc.blk_mq_poll_rqs[i].rq.msix_idx = in leapraid_set_msix()
7295 i + adapter->notification_desc.iopoll_qdex; in leapraid_set_msix()
7297 &adapter->notification_desc.blk_mq_poll_rqs[i].rq.busy, in leapraid_set_msix()
7299 snprintf(adapter->notification_desc.blk_mq_poll_rqs[i].rq.name, in leapraid_set_msix()
7302 adapter->adapter_attr.id, i); in leapraid_set_msix()
7303 atomic_set(&adapter->notification_desc.blk_mq_poll_rqs[i].busy, in leapraid_set_msix()
7305 atomic_set(&adapter->notification_desc.blk_mq_poll_rqs[i].pause, in leapraid_set_msix()
7309 rc = leapraid_alloc_msix_cpu_map(adapter); in leapraid_set_msix()
7313 adapter->notification_desc.irq_mode = LEAPRAID_INTERRUPT_MODE_MSIX; in leapraid_set_msix()
7314 adapter->notification_desc.msix_enable = 1; in leapraid_set_msix()
7315 rc = leapraid_setup_irqs(adapter); in leapraid_set_msix()
7317 leapraid_free_irq(adapter); in leapraid_set_msix()
7318 adapter->notification_desc.msix_enable = 0; in leapraid_set_msix()
7325 static int leapraid_set_msi(struct leapraid_adapter *adapter) in leapraid_set_msi() argument
7331 msi_cnt = pci_msi_vec_count(adapter->pdev); in leapraid_set_msi()
7333 adapter->adapter_attr.features.max_msix_vectors == 0) { in leapraid_set_msi()
7334 dev_info(&adapter->pdev->dev, "MSI unsupported!\n"); in leapraid_set_msi()
7339 adapter->adapter_attr.features.max_msix_vectors); in leapraid_set_msi()
7342 adapter->adapter_attr.rq_cnt = 1; in leapraid_set_msi()
7344 adapter->adapter_attr.rq_cnt = min_t(int, in leapraid_set_msi()
7349 adapter->adapter_attr.rq_cnt = min_t( in leapraid_set_msi()
7350 int, max_msix_vectors, adapter->adapter_attr.rq_cnt); in leapraid_set_msi()
7352 if (adapter->adapter_attr.rq_cnt <= 1) in leapraid_set_msi()
7353 adapter->shost->host_tagset = 0; in leapraid_set_msi()
7354 if (adapter->shost->host_tagset) { in leapraid_set_msi()
7356 if (iopoll_qcnt >= adapter->adapter_attr.rq_cnt) in leapraid_set_msi()
7361 adapter->notification_desc.blk_mq_poll_rqs = in leapraid_set_msi()
7364 if (!adapter->notification_desc.blk_mq_poll_rqs) in leapraid_set_msi()
7367 adapter->adapter_attr.rq_cnt = in leapraid_set_msi()
7368 min(adapter->adapter_attr.rq_cnt + iopoll_qcnt, in leapraid_set_msi()
7372 adapter->notification_desc.iopoll_qdex = in leapraid_set_msi()
7373 adapter->adapter_attr.rq_cnt - iopoll_qcnt; in leapraid_set_msi()
7375 adapter->pdev, in leapraid_set_msi()
7377 adapter->notification_desc.iopoll_qdex, in leapraid_set_msi()
7380 dev_err(&adapter->pdev->dev, in leapraid_set_msi()
7382 adapter->notification_desc.iopoll_qdex); in leapraid_set_msi()
7383 leapraid_free_irq(adapter); in leapraid_set_msi()
7386 adapter->notification_desc.irq_vectors_allocated = 1; in leapraid_set_msi()
7387 if (rc != adapter->notification_desc.iopoll_qdex) { in leapraid_set_msi()
7388 adapter->notification_desc.iopoll_qdex = rc; in leapraid_set_msi()
7389 adapter->adapter_attr.rq_cnt = in leapraid_set_msi()
7390 adapter->notification_desc.iopoll_qdex + iopoll_qcnt; in leapraid_set_msi()
7392 adapter->notification_desc.iopoll_qcnt = iopoll_qcnt; in leapraid_set_msi()
7393 dev_info(&adapter->pdev->dev, in leapraid_set_msi()
7395 adapter->adapter_attr.rq_cnt, in leapraid_set_msi()
7396 adapter->notification_desc.iopoll_qdex, in leapraid_set_msi()
7397 adapter->notification_desc.iopoll_qcnt); in leapraid_set_msi()
7399 adapter->notification_desc.int_rqs = in leapraid_set_msi()
7401 adapter->notification_desc.iopoll_qdex); in leapraid_set_msi()
7402 if (!adapter->notification_desc.int_rqs) in leapraid_set_msi()
7405 for (i = 0; i < adapter->notification_desc.iopoll_qcnt; i++) { in leapraid_set_msi()
7406 adapter->notification_desc.blk_mq_poll_rqs[i].rq.adapter = in leapraid_set_msi()
7407 adapter; in leapraid_set_msi()
7408 adapter->notification_desc.blk_mq_poll_rqs[i].rq.msix_idx = in leapraid_set_msi()
7409 i + adapter->notification_desc.iopoll_qdex; in leapraid_set_msi()
7411 &adapter->notification_desc.blk_mq_poll_rqs[i].rq.busy, in leapraid_set_msi()
7413 snprintf(adapter->notification_desc.blk_mq_poll_rqs[i].rq.name, in leapraid_set_msi()
7416 adapter->adapter_attr.id, i); in leapraid_set_msi()
7418 &adapter->notification_desc.blk_mq_poll_rqs[i].busy, in leapraid_set_msi()
7421 &adapter->notification_desc.blk_mq_poll_rqs[i].pause, in leapraid_set_msi()
7425 rc = leapraid_alloc_msix_cpu_map(adapter); in leapraid_set_msi()
7429 adapter->notification_desc.irq_mode = LEAPRAID_INTERRUPT_MODE_MSI; in leapraid_set_msi()
7430 adapter->notification_desc.msix_enable = 1; in leapraid_set_msi()
7431 rc = leapraid_setup_irqs(adapter); in leapraid_set_msi()
7433 leapraid_free_irq(adapter); in leapraid_set_msi()
7434 adapter->notification_desc.msix_enable = 0; in leapraid_set_msi()
7441 static int leapraid_set_notification_auto(struct leapraid_adapter *adapter) in leapraid_set_notification_auto() argument
7445 rc = leapraid_set_msix(adapter); in leapraid_set_notification_auto()
7449 leapraid_free_irq(adapter); in leapraid_set_notification_auto()
7450 dev_info(&adapter->pdev->dev, in leapraid_set_notification_auto()
7453 rc = leapraid_set_msi(adapter); in leapraid_set_notification_auto()
7457 leapraid_free_irq(adapter); in leapraid_set_notification_auto()
7458 dev_info(&adapter->pdev->dev, in leapraid_set_notification_auto()
7461 rc = leapraid_set_legacy_int(adapter); in leapraid_set_notification_auto()
7463 dev_err(&adapter->pdev->dev, in leapraid_set_notification_auto()
7469 int leapraid_set_pcie_and_notification(struct leapraid_adapter *adapter) in leapraid_set_pcie_and_notification() argument
7473 rc = leapraid_enable_pcie(adapter); in leapraid_set_pcie_and_notification()
7477 leapraid_mask_int(adapter); in leapraid_set_pcie_and_notification()
7479 rc = leapraid_make_adapter_ready(adapter, PART_RESET); in leapraid_set_pcie_and_notification()
7481 dev_err(&adapter->pdev->dev, "Make adapter ready failure\n"); in leapraid_set_pcie_and_notification()
7485 rc = leapraid_get_adapter_features(adapter); in leapraid_set_pcie_and_notification()
7487 dev_err(&adapter->pdev->dev, "Get adapter feature failure\n"); in leapraid_set_pcie_and_notification()
7491 rc = leapraid_set_notification_auto(adapter); in leapraid_set_pcie_and_notification()
7495 pci_save_state(adapter->pdev); in leapraid_set_pcie_and_notification()
7500 leapraid_free_irq(adapter); in leapraid_set_pcie_and_notification()
7501 leapraid_disable_pcie(adapter); in leapraid_set_pcie_and_notification()
7505 void leapraid_disable_controller(struct leapraid_adapter *adapter) in leapraid_disable_controller() argument
7507 if (!adapter->iomem_base) in leapraid_disable_controller()
7510 leapraid_mask_int(adapter); in leapraid_disable_controller()
7512 adapter->access_ctrl.shost_recovering = 1; in leapraid_disable_controller()
7513 leapraid_make_adapter_ready(adapter, PART_RESET); in leapraid_disable_controller()
7514 adapter->access_ctrl.shost_recovering = 0; in leapraid_disable_controller()
7515 wake_up(&adapter->access_ctrl.recovery_waitq); in leapraid_disable_controller()
7517 leapraid_free_irq(adapter); in leapraid_disable_controller()
7518 leapraid_disable_pcie(adapter); in leapraid_disable_controller()
7521 static int leapraid_adapter_unit_reset(struct leapraid_adapter *adapter) in leapraid_adapter_unit_reset() argument
7526 &adapter->iomem_base->db); in leapraid_adapter_unit_reset()
7527 if (leapraid_db_wait_ack_and_clear_int(adapter)) in leapraid_adapter_unit_reset()
7530 if (!leapraid_wait_adapter_ready(adapter)) { in leapraid_adapter_unit_reset()
7531 dev_err(&adapter->pdev->dev, "unit reset failed\n"); in leapraid_adapter_unit_reset()
7538 static int leapraid_make_adapter_ready(struct leapraid_adapter *adapter, in leapraid_make_adapter_ready() argument
7544 if (!leapraid_pci_active(adapter)) in leapraid_make_adapter_ready()
7548 db = leapraid_readl(&adapter->iomem_base->db); in leapraid_make_adapter_ready()
7552 dev_err(&adapter->pdev->dev, in leapraid_make_adapter_ready()
7557 db = leapraid_readl(&adapter->iomem_base->db); in leapraid_make_adapter_ready()
7558 dev_info(&adapter->pdev->dev, in leapraid_make_adapter_ready()
7576 !leapraid_adapter_unit_reset(adapter)) in leapraid_make_adapter_ready()
7580 return leapraid_host_diag_reset(adapter); in leapraid_make_adapter_ready()
7583 static void leapraid_fw_log_exit(struct leapraid_adapter *adapter) in leapraid_fw_log_exit() argument
7585 if (!adapter->fw_log_desc.open_pcie_trace) in leapraid_fw_log_exit()
7588 if (adapter->fw_log_desc.fw_log_buffer) { in leapraid_fw_log_exit()
7589 wait_event(adapter->fw_log_desc.mmap_waitq, in leapraid_fw_log_exit()
7590 !atomic_read(&adapter->fw_log_desc.mmap_refcnt)); in leapraid_fw_log_exit()
7591 dma_free_coherent(&adapter->pdev->dev, in leapraid_fw_log_exit()
7594 adapter->fw_log_desc.fw_log_buffer, in leapraid_fw_log_exit()
7595 adapter->fw_log_desc.fw_log_buffer_dma); in leapraid_fw_log_exit()
7596 adapter->fw_log_desc.fw_log_buffer = NULL; in leapraid_fw_log_exit()
7600 static int leapraid_fw_log_init(struct leapraid_adapter *adapter) in leapraid_fw_log_init() argument
7608 if (!adapter->fw_log_desc.open_pcie_trace) in leapraid_fw_log_init()
7611 if (!adapter->fw_log_desc.fw_log_buffer) { in leapraid_fw_log_init()
7612 adapter->fw_log_desc.fw_log_buffer = in leapraid_fw_log_init()
7614 &adapter->pdev->dev, in leapraid_fw_log_init()
7617 &adapter->fw_log_desc.fw_log_buffer_dma, in leapraid_fw_log_init()
7619 if (!adapter->fw_log_desc.fw_log_buffer) in leapraid_fw_log_init()
7625 buf_addr = adapter->fw_log_desc.fw_log_buffer_dma; in leapraid_fw_log_init()
7633 rc = leapraid_handshake_func(adapter, in leapraid_fw_log_init()
7639 dev_err(&adapter->pdev->dev, "%s: Handshake failed, rc=%d\n", in leapraid_fw_log_init()
7647 dev_err(&adapter->pdev->dev, "%s: failed!\n", __func__); in leapraid_fw_log_init()
7654 static void leapraid_free_host_memory(struct leapraid_adapter *adapter) in leapraid_free_host_memory() argument
7658 if (adapter->mem_desc.task_desc) { in leapraid_free_host_memory()
7659 dma_free_coherent(&adapter->pdev->dev, in leapraid_free_host_memory()
7660 adapter->adapter_attr.task_desc_dma_size, in leapraid_free_host_memory()
7661 adapter->mem_desc.task_desc, in leapraid_free_host_memory()
7662 adapter->mem_desc.task_desc_dma); in leapraid_free_host_memory()
7663 adapter->mem_desc.task_desc = NULL; in leapraid_free_host_memory()
7666 if (adapter->mem_desc.sense_data) { in leapraid_free_host_memory()
7668 &adapter->pdev->dev, in leapraid_free_host_memory()
7669 adapter->adapter_attr.io_qd * SCSI_SENSE_BUFFERSIZE, in leapraid_free_host_memory()
7670 adapter->mem_desc.sense_data, in leapraid_free_host_memory()
7671 adapter->mem_desc.sense_data_dma); in leapraid_free_host_memory()
7672 adapter->mem_desc.sense_data = NULL; in leapraid_free_host_memory()
7675 if (adapter->mem_desc.rep_msg) { in leapraid_free_host_memory()
7677 &adapter->pdev->dev, in leapraid_free_host_memory()
7678 adapter->adapter_attr.rep_msg_qd * LEAPRAID_REPLY_SIZE, in leapraid_free_host_memory()
7679 adapter->mem_desc.rep_msg, in leapraid_free_host_memory()
7680 adapter->mem_desc.rep_msg_dma); in leapraid_free_host_memory()
7681 adapter->mem_desc.rep_msg = NULL; in leapraid_free_host_memory()
7684 if (adapter->mem_desc.rep_msg_addr) { in leapraid_free_host_memory()
7685 dma_free_coherent(&adapter->pdev->dev, in leapraid_free_host_memory()
7686 adapter->adapter_attr.rep_msg_qd * in leapraid_free_host_memory()
7688 adapter->mem_desc.rep_msg_addr, in leapraid_free_host_memory()
7689 adapter->mem_desc.rep_msg_addr_dma); in leapraid_free_host_memory()
7690 adapter->mem_desc.rep_msg_addr = NULL; in leapraid_free_host_memory()
7693 if (adapter->mem_desc.rep_desc_seg_maint) { in leapraid_free_host_memory()
7694 for (i = 0; i < adapter->adapter_attr.rep_desc_q_seg_cnt; in leapraid_free_host_memory()
7696 if (adapter->mem_desc.rep_desc_seg_maint[i] in leapraid_free_host_memory()
7699 &adapter->pdev->dev, in leapraid_free_host_memory()
7700 (adapter->adapter_attr.rep_desc_qd * in leapraid_free_host_memory()
7703 adapter->mem_desc.rep_desc_seg_maint[i] in leapraid_free_host_memory()
7705 adapter->mem_desc.rep_desc_seg_maint[i] in leapraid_free_host_memory()
7707 adapter->mem_desc.rep_desc_seg_maint[i] in leapraid_free_host_memory()
7712 if (adapter->mem_desc.rep_desc_q_arr) { in leapraid_free_host_memory()
7714 &adapter->pdev->dev, in leapraid_free_host_memory()
7715 adapter->adapter_attr.rq_cnt * in leapraid_free_host_memory()
7717 adapter->mem_desc.rep_desc_q_arr, in leapraid_free_host_memory()
7718 adapter->mem_desc.rep_desc_q_arr_dma); in leapraid_free_host_memory()
7719 adapter->mem_desc.rep_desc_q_arr = NULL; in leapraid_free_host_memory()
7722 for (i = 0; i < adapter->adapter_attr.rep_desc_q_seg_cnt; i++) { in leapraid_free_host_memory()
7724 &adapter->mem_desc; in leapraid_free_host_memory()
7725 kfree(adapter->mem_desc.rep_desc_seg_maint[i] in leapraid_free_host_memory()
7729 kfree(adapter->mem_desc.rep_desc_seg_maint); in leapraid_free_host_memory()
7730 adapter->mem_desc.rep_desc_seg_maint = NULL; in leapraid_free_host_memory()
7733 kfree(adapter->mem_desc.taskid_to_uniq_tag); in leapraid_free_host_memory()
7734 adapter->mem_desc.taskid_to_uniq_tag = NULL; in leapraid_free_host_memory()
7736 dma_pool_destroy(adapter->mem_desc.sg_chain_pool); in leapraid_free_host_memory()
7737 adapter->mem_desc.sg_chain_pool = NULL; in leapraid_free_host_memory()
7745 int leapraid_internal_init_cmd_priv(struct leapraid_adapter *adapter, in leapraid_internal_init_cmd_priv() argument
7749 dma_pool_alloc(adapter->mem_desc.sg_chain_pool, in leapraid_internal_init_cmd_priv()
7759 void leapraid_internal_exit_cmd_priv(struct leapraid_adapter *adapter, in leapraid_internal_exit_cmd_priv() argument
7763 dma_pool_free(adapter->mem_desc.sg_chain_pool, in leapraid_internal_exit_cmd_priv()
7768 static int leapraid_request_host_memory(struct leapraid_adapter *adapter) in leapraid_request_host_memory() argument
7771 &adapter->adapter_attr.features; in leapraid_request_host_memory()
7777 adapter->shost->sg_tablesize = LEAPRAID_SG_DEPTH; in leapraid_request_host_memory()
7779 adapter->shost->sg_tablesize = in leapraid_request_host_memory()
7782 adapter->dynamic_task_desc.hp_cmd_qd = LEAPRAID_FIXED_HP_CMDS; in leapraid_request_host_memory()
7784 adapter->dynamic_task_desc.inter_cmd_qd = LEAPRAID_FIXED_INTER_CMDS; in leapraid_request_host_memory()
7787 adapter->adapter_attr.adapter_total_qd = in leapraid_request_host_memory()
7789 adapter->dynamic_task_desc.inter_cmd_qd + in leapraid_request_host_memory()
7790 adapter->dynamic_task_desc.hp_cmd_qd; in leapraid_request_host_memory()
7792 adapter->adapter_attr.adapter_total_qd = facts->req_slot + in leapraid_request_host_memory()
7793 adapter->dynamic_task_desc.hp_cmd_qd; in leapraid_request_host_memory()
7795 adapter->adapter_attr.rep_msg_qd = in leapraid_request_host_memory()
7796 adapter->adapter_attr.adapter_total_qd + in leapraid_request_host_memory()
7799 adapter->adapter_attr.rep_desc_qd = in leapraid_request_host_memory()
7800 round_up(adapter->adapter_attr.adapter_total_qd + in leapraid_request_host_memory()
7801 adapter->adapter_attr.rep_msg_qd + in leapraid_request_host_memory()
7805 adapter->adapter_attr.io_qd = in leapraid_request_host_memory()
7806 adapter->adapter_attr.adapter_total_qd - in leapraid_request_host_memory()
7807 adapter->dynamic_task_desc.hp_cmd_qd - in leapraid_request_host_memory()
7808 adapter->dynamic_task_desc.inter_cmd_qd; in leapraid_request_host_memory()
7810 adapter->shost->can_queue = adapter->adapter_attr.io_qd - in leapraid_request_host_memory()
7812 adapter->driver_cmds.ctl_cmd.taskid = adapter->shost->can_queue + in leapraid_request_host_memory()
7817 adapter->adapter_attr.task_desc_dma_size = in leapraid_request_host_memory()
7818 (adapter->adapter_attr.adapter_total_qd + in leapraid_request_host_memory()
7821 adapter->mem_desc.task_desc = in leapraid_request_host_memory()
7822 dma_alloc_coherent(&adapter->pdev->dev, in leapraid_request_host_memory()
7823 adapter->adapter_attr.task_desc_dma_size, in leapraid_request_host_memory()
7824 &adapter->mem_desc.task_desc_dma, in leapraid_request_host_memory()
7826 if (!adapter->mem_desc.task_desc) in leapraid_request_host_memory()
7830 adapter->mem_desc.sg_chain_pool_size = in leapraid_request_host_memory()
7832 adapter->mem_desc.sg_chain_pool = in leapraid_request_host_memory()
7834 &adapter->pdev->dev, in leapraid_request_host_memory()
7835 adapter->mem_desc.sg_chain_pool_size, in leapraid_request_host_memory()
7837 if (!adapter->mem_desc.sg_chain_pool) in leapraid_request_host_memory()
7841 adapter->mem_desc.taskid_to_uniq_tag = in leapraid_request_host_memory()
7842 kcalloc(adapter->shost->can_queue, sizeof(u16), GFP_KERNEL); in leapraid_request_host_memory()
7843 if (!adapter->mem_desc.taskid_to_uniq_tag) in leapraid_request_host_memory()
7846 adapter->dynamic_task_desc.hp_taskid = in leapraid_request_host_memory()
7847 adapter->adapter_attr.io_qd + in leapraid_request_host_memory()
7850 adapter->driver_cmds.ctl_cmd.hp_taskid = in leapraid_request_host_memory()
7851 adapter->dynamic_task_desc.hp_taskid; in leapraid_request_host_memory()
7852 adapter->driver_cmds.tm_cmd.hp_taskid = in leapraid_request_host_memory()
7853 adapter->dynamic_task_desc.hp_taskid + in leapraid_request_host_memory()
7856 adapter->dynamic_task_desc.inter_taskid = in leapraid_request_host_memory()
7857 adapter->dynamic_task_desc.hp_taskid + in leapraid_request_host_memory()
7858 adapter->dynamic_task_desc.hp_cmd_qd; in leapraid_request_host_memory()
7859 adapter->driver_cmds.scan_dev_cmd.inter_taskid = in leapraid_request_host_memory()
7860 adapter->dynamic_task_desc.inter_taskid; in leapraid_request_host_memory()
7861 adapter->driver_cmds.cfg_op_cmd.inter_taskid = in leapraid_request_host_memory()
7862 adapter->dynamic_task_desc.inter_taskid + in leapraid_request_host_memory()
7864 adapter->driver_cmds.transport_cmd.inter_taskid = in leapraid_request_host_memory()
7865 adapter->dynamic_task_desc.inter_taskid + in leapraid_request_host_memory()
7867 adapter->driver_cmds.enc_cmd.inter_taskid = in leapraid_request_host_memory()
7868 adapter->dynamic_task_desc.inter_taskid + in leapraid_request_host_memory()
7870 adapter->driver_cmds.notify_event_cmd.inter_taskid = in leapraid_request_host_memory()
7871 adapter->dynamic_task_desc.inter_taskid + in leapraid_request_host_memory()
7873 dev_info(&adapter->pdev->dev, "queue depth:\n"); in leapraid_request_host_memory()
7874 dev_info(&adapter->pdev->dev, " host->can_queue: %d\n", in leapraid_request_host_memory()
7875 adapter->shost->can_queue); in leapraid_request_host_memory()
7876 dev_info(&adapter->pdev->dev, " io_qd: %d\n", in leapraid_request_host_memory()
7877 adapter->adapter_attr.io_qd); in leapraid_request_host_memory()
7878 dev_info(&adapter->pdev->dev, " hpr_cmd_qd: %d\n", in leapraid_request_host_memory()
7879 adapter->dynamic_task_desc.hp_cmd_qd); in leapraid_request_host_memory()
7880 dev_info(&adapter->pdev->dev, " inter_cmd_qd: %d\n", in leapraid_request_host_memory()
7881 adapter->dynamic_task_desc.inter_cmd_qd); in leapraid_request_host_memory()
7882 dev_info(&adapter->pdev->dev, " adapter_total_qd: %d\n", in leapraid_request_host_memory()
7883 adapter->adapter_attr.adapter_total_qd); in leapraid_request_host_memory()
7885 dev_info(&adapter->pdev->dev, "taskid range:\n"); in leapraid_request_host_memory()
7886 dev_info(&adapter->pdev->dev, in leapraid_request_host_memory()
7888 adapter->dynamic_task_desc.hp_taskid); in leapraid_request_host_memory()
7889 dev_info(&adapter->pdev->dev, in leapraid_request_host_memory()
7891 adapter->dynamic_task_desc.inter_taskid); in leapraid_request_host_memory()
7898 adapter->mem_desc.sense_data = in leapraid_request_host_memory()
7900 &adapter->pdev->dev, in leapraid_request_host_memory()
7901 adapter->adapter_attr.io_qd * SCSI_SENSE_BUFFERSIZE, in leapraid_request_host_memory()
7902 &adapter->mem_desc.sense_data_dma, in leapraid_request_host_memory()
7904 if (!adapter->mem_desc.sense_data) in leapraid_request_host_memory()
7907 if (!leapraid_is_in_same_4g_seg(adapter->mem_desc.sense_data_dma, in leapraid_request_host_memory()
7908 adapter->adapter_attr.io_qd * in leapraid_request_host_memory()
7910 dev_warn(&adapter->pdev->dev, in leapraid_request_host_memory()
7920 adapter->mem_desc.rep_msg = in leapraid_request_host_memory()
7921 dma_alloc_coherent(&adapter->pdev->dev, in leapraid_request_host_memory()
7922 adapter->adapter_attr.rep_msg_qd * in leapraid_request_host_memory()
7924 &adapter->mem_desc.rep_msg_dma, in leapraid_request_host_memory()
7926 if (!adapter->mem_desc.rep_msg) { in leapraid_request_host_memory()
7931 if (!leapraid_is_in_same_4g_seg(adapter->mem_desc.rep_msg_dma, in leapraid_request_host_memory()
7932 adapter->adapter_attr.rep_msg_qd * in leapraid_request_host_memory()
7934 dev_warn(&adapter->pdev->dev, in leapraid_request_host_memory()
7941 adapter->mem_desc.rep_msg_addr = in leapraid_request_host_memory()
7942 dma_alloc_coherent(&adapter->pdev->dev, in leapraid_request_host_memory()
7943 adapter->adapter_attr.rep_msg_qd * in leapraid_request_host_memory()
7945 &adapter->mem_desc.rep_msg_addr_dma, in leapraid_request_host_memory()
7947 if (!adapter->mem_desc.rep_msg_addr) in leapraid_request_host_memory()
7949 adapter->adapter_attr.rep_desc_q_seg_cnt = in leapraid_request_host_memory()
7950 DIV_ROUND_UP(adapter->adapter_attr.rq_cnt, in leapraid_request_host_memory()
7952 adapter->mem_desc.rep_desc_seg_maint = in leapraid_request_host_memory()
7954 adapter->adapter_attr.rep_desc_q_seg_cnt); in leapraid_request_host_memory()
7955 if (!adapter->mem_desc.rep_desc_seg_maint) in leapraid_request_host_memory()
7959 for (i = 0; i < adapter->adapter_attr.rep_desc_q_seg_cnt; i++) { in leapraid_request_host_memory()
7960 adapter->mem_desc.rep_desc_seg_maint[i].rep_desc_maint = in leapraid_request_host_memory()
7963 if (!adapter->mem_desc.rep_desc_seg_maint[i].rep_desc_maint) in leapraid_request_host_memory()
7966 adapter->mem_desc.rep_desc_seg_maint[i].rep_desc_seg = in leapraid_request_host_memory()
7968 &adapter->pdev->dev, in leapraid_request_host_memory()
7969 (adapter->adapter_attr.rep_desc_qd * in leapraid_request_host_memory()
7972 &adapter->mem_desc.rep_desc_seg_maint[i] in leapraid_request_host_memory()
7975 if (!adapter->mem_desc.rep_desc_seg_maint[i].rep_desc_seg) in leapraid_request_host_memory()
7980 adapter->adapter_attr.rq_cnt) in leapraid_request_host_memory()
7982 adapter->mem_desc in leapraid_request_host_memory()
7987 adapter->mem_desc in leapraid_request_host_memory()
7991 (adapter->adapter_attr.rep_desc_qd * in leapraid_request_host_memory()
7993 adapter->mem_desc in leapraid_request_host_memory()
7997 adapter->mem_desc in leapraid_request_host_memory()
8001 (adapter->adapter_attr.rep_desc_qd * in leapraid_request_host_memory()
8008 adapter->mem_desc.rep_desc_q_arr = in leapraid_request_host_memory()
8010 &adapter->pdev->dev, in leapraid_request_host_memory()
8011 adapter->adapter_attr.rq_cnt * in leapraid_request_host_memory()
8013 &adapter->mem_desc.rep_desc_q_arr_dma, in leapraid_request_host_memory()
8015 if (!adapter->mem_desc.rep_desc_q_arr) in leapraid_request_host_memory()
8022 leapraid_free_host_memory(adapter); in leapraid_request_host_memory()
8023 adapter->adapter_attr.use_32_dma_mask = 1; in leapraid_request_host_memory()
8024 rc = dma_set_mask_and_coherent(&adapter->pdev->dev, in leapraid_request_host_memory()
8027 dev_err(&adapter->pdev->dev, in leapraid_request_host_memory()
8036 static int leapraid_alloc_dev_topo_bitmaps(struct leapraid_adapter *adapter) in leapraid_alloc_dev_topo_bitmaps() argument
8042 adapter->adapter_attr.features.max_dev_handle + 1) * in leapraid_alloc_dev_topo_bitmaps()
8045 adapter->dev_topo.pd_hdls_sz = pd_hdls_sz; in leapraid_alloc_dev_topo_bitmaps()
8046 adapter->dev_topo.pd_hdls = in leapraid_alloc_dev_topo_bitmaps()
8047 kzalloc(adapter->dev_topo.pd_hdls_sz, GFP_KERNEL); in leapraid_alloc_dev_topo_bitmaps()
8048 if (!adapter->dev_topo.pd_hdls) in leapraid_alloc_dev_topo_bitmaps()
8051 adapter->dev_topo.blocking_hdls = in leapraid_alloc_dev_topo_bitmaps()
8052 kzalloc(adapter->dev_topo.pd_hdls_sz, GFP_KERNEL); in leapraid_alloc_dev_topo_bitmaps()
8053 if (!adapter->dev_topo.blocking_hdls) in leapraid_alloc_dev_topo_bitmaps()
8059 static void leapraid_free_dev_topo_bitmaps(struct leapraid_adapter *adapter) in leapraid_free_dev_topo_bitmaps() argument
8061 kfree(adapter->dev_topo.pd_hdls); in leapraid_free_dev_topo_bitmaps()
8062 kfree(adapter->dev_topo.blocking_hdls); in leapraid_free_dev_topo_bitmaps()
8065 static int leapraid_init_driver_cmds(struct leapraid_adapter *adapter) in leapraid_init_driver_cmds() argument
8067 INIT_LIST_HEAD(&adapter->driver_cmds.special_cmd_list); in leapraid_init_driver_cmds()
8069 adapter->driver_cmds.scan_dev_cmd.status = LEAPRAID_CMD_NOT_USED; in leapraid_init_driver_cmds()
8070 adapter->driver_cmds.scan_dev_cmd.cb_idx = LEAPRAID_SCAN_DEV_CB_IDX; in leapraid_init_driver_cmds()
8071 list_add_tail(&adapter->driver_cmds.scan_dev_cmd.list, in leapraid_init_driver_cmds()
8072 &adapter->driver_cmds.special_cmd_list); in leapraid_init_driver_cmds()
8074 adapter->driver_cmds.cfg_op_cmd.status = LEAPRAID_CMD_NOT_USED; in leapraid_init_driver_cmds()
8075 adapter->driver_cmds.cfg_op_cmd.cb_idx = LEAPRAID_CONFIG_CB_IDX; in leapraid_init_driver_cmds()
8076 mutex_init(&adapter->driver_cmds.cfg_op_cmd.mutex); in leapraid_init_driver_cmds()
8077 list_add_tail(&adapter->driver_cmds.cfg_op_cmd.list, in leapraid_init_driver_cmds()
8078 &adapter->driver_cmds.special_cmd_list); in leapraid_init_driver_cmds()
8080 adapter->driver_cmds.transport_cmd.status = LEAPRAID_CMD_NOT_USED; in leapraid_init_driver_cmds()
8081 adapter->driver_cmds.transport_cmd.cb_idx = LEAPRAID_TRANSPORT_CB_IDX; in leapraid_init_driver_cmds()
8082 mutex_init(&adapter->driver_cmds.transport_cmd.mutex); in leapraid_init_driver_cmds()
8083 list_add_tail(&adapter->driver_cmds.transport_cmd.list, in leapraid_init_driver_cmds()
8084 &adapter->driver_cmds.special_cmd_list); in leapraid_init_driver_cmds()
8086 adapter->driver_cmds.enc_cmd.status = LEAPRAID_CMD_NOT_USED; in leapraid_init_driver_cmds()
8087 adapter->driver_cmds.enc_cmd.cb_idx = LEAPRAID_ENC_CB_IDX; in leapraid_init_driver_cmds()
8088 mutex_init(&adapter->driver_cmds.enc_cmd.mutex); in leapraid_init_driver_cmds()
8089 list_add_tail(&adapter->driver_cmds.enc_cmd.list, in leapraid_init_driver_cmds()
8090 &adapter->driver_cmds.special_cmd_list); in leapraid_init_driver_cmds()
8092 adapter->driver_cmds.notify_event_cmd.status = LEAPRAID_CMD_NOT_USED; in leapraid_init_driver_cmds()
8093 adapter->driver_cmds.notify_event_cmd.cb_idx = in leapraid_init_driver_cmds()
8095 mutex_init(&adapter->driver_cmds.notify_event_cmd.mutex); in leapraid_init_driver_cmds()
8096 list_add_tail(&adapter->driver_cmds.notify_event_cmd.list, in leapraid_init_driver_cmds()
8097 &adapter->driver_cmds.special_cmd_list); in leapraid_init_driver_cmds()
8099 adapter->driver_cmds.ctl_cmd.status = LEAPRAID_CMD_NOT_USED; in leapraid_init_driver_cmds()
8100 adapter->driver_cmds.ctl_cmd.cb_idx = LEAPRAID_CTL_CB_IDX; in leapraid_init_driver_cmds()
8101 mutex_init(&adapter->driver_cmds.ctl_cmd.mutex); in leapraid_init_driver_cmds()
8102 list_add_tail(&adapter->driver_cmds.ctl_cmd.list, in leapraid_init_driver_cmds()
8103 &adapter->driver_cmds.special_cmd_list); in leapraid_init_driver_cmds()
8105 adapter->driver_cmds.tm_cmd.status = LEAPRAID_CMD_NOT_USED; in leapraid_init_driver_cmds()
8106 adapter->driver_cmds.tm_cmd.cb_idx = LEAPRAID_TM_CB_IDX; in leapraid_init_driver_cmds()
8107 mutex_init(&adapter->driver_cmds.tm_cmd.mutex); in leapraid_init_driver_cmds()
8108 list_add_tail(&adapter->driver_cmds.tm_cmd.list, in leapraid_init_driver_cmds()
8109 &adapter->driver_cmds.special_cmd_list); in leapraid_init_driver_cmds()
8114 static void leapraid_unmask_evts(struct leapraid_adapter *adapter, u16 evt) in leapraid_unmask_evts() argument
8119 clear_bit(evt, (unsigned long *)adapter->fw_evt_s.leapraid_evt_masks); in leapraid_unmask_evts()
8122 static void leapraid_init_event_mask(struct leapraid_adapter *adapter) in leapraid_init_event_mask() argument
8127 adapter->fw_evt_s.leapraid_evt_masks[i] = in leapraid_init_event_mask()
8130 leapraid_unmask_evts(adapter, LEAPRAID_EVT_SAS_TOPO_CHANGE_LIST); in leapraid_init_event_mask()
8131 leapraid_unmask_evts(adapter, LEAPRAID_EVT_SAS_ENCL_DEV_STATUS_CHANGE); in leapraid_init_event_mask()
8132 leapraid_unmask_evts(adapter, LEAPRAID_EVT_SAS_DEV_STATUS_CHANGE); in leapraid_init_event_mask()
8133 leapraid_unmask_evts(adapter, LEAPRAID_EVT_IR_CHANGE); in leapraid_init_event_mask()
8137 struct leapraid_adapter *adapter, in leapraid_prepare_adapter_init_req() argument
8155 if (adapter->notification_desc.msix_enable) in leapraid_prepare_adapter_init_req()
8156 init_req->host_msix_vectors = adapter->adapter_attr.rq_cnt; in leapraid_prepare_adapter_init_req()
8161 cpu_to_le16(adapter->adapter_attr.rep_desc_qd); in leapraid_prepare_adapter_init_req()
8163 cpu_to_le16(adapter->adapter_attr.rep_msg_qd); in leapraid_prepare_adapter_init_req()
8165 cpu_to_le32((u64)adapter->mem_desc.sense_data_dma >> 32); in leapraid_prepare_adapter_init_req()
8167 cpu_to_le32((u64)adapter->mem_desc.rep_msg_dma >> 32); in leapraid_prepare_adapter_init_req()
8169 cpu_to_le64((u64)adapter->mem_desc.task_desc_dma); in leapraid_prepare_adapter_init_req()
8171 cpu_to_le64((u64)adapter->mem_desc.rep_msg_addr_dma); in leapraid_prepare_adapter_init_req()
8174 adapter->adapter_attr.rq_cnt * LEAPRAID_REP_RQ_CNT_SIZE; in leapraid_prepare_adapter_init_req()
8175 memset(adapter->mem_desc.rep_desc_q_arr, 0, in leapraid_prepare_adapter_init_req()
8179 for (i = 0; i < adapter->adapter_attr.rq_cnt; i++) in leapraid_prepare_adapter_init_req()
8180 adapter->mem_desc.rep_desc_q_arr[i].rep_desc_base_addr = in leapraid_prepare_adapter_init_req()
8181 cpu_to_le64 ((u64)adapter->mem_desc in leapraid_prepare_adapter_init_req()
8189 cpu_to_le64((u64)adapter->mem_desc.rep_desc_q_arr_dma); in leapraid_prepare_adapter_init_req()
8192 cpu_to_le64((u64)adapter->mem_desc in leapraid_prepare_adapter_init_req()
8201 static int leapraid_send_adapter_init(struct leapraid_adapter *adapter) in leapraid_send_adapter_init() argument
8208 leapraid_prepare_adapter_init_req(adapter, &init_req); in leapraid_send_adapter_init()
8210 rc = leapraid_handshake_func(adapter, in leapraid_send_adapter_init()
8216 dev_err(&adapter->pdev->dev, "%s: Handshake failed, rc=%d\n", in leapraid_send_adapter_init()
8225 dev_err(&adapter->pdev->dev, "%s: failed\n", __func__); in leapraid_send_adapter_init()
8232 static int leapraid_cfg_pages(struct leapraid_adapter *adapter) in leapraid_cfg_pages() argument
8243 rc = leapraid_op_config_page(adapter, &cfg_page.bios_page3, cfgp1, in leapraid_cfg_pages()
8248 adapter->adapter_attr.bios_version = in leapraid_cfg_pages()
8251 rc = leapraid_op_config_page(adapter, &cfg_page.bios_page2, cfgp1, in leapraid_cfg_pages()
8256 adapter->boot_devs.requested_boot_dev.form = in leapraid_cfg_pages()
8258 memcpy(adapter->boot_devs.requested_boot_dev.pg_dev, in leapraid_cfg_pages()
8261 adapter->boot_devs.requested_alt_boot_dev.form = in leapraid_cfg_pages()
8263 memcpy(adapter->boot_devs.requested_alt_boot_dev.pg_dev, in leapraid_cfg_pages()
8266 adapter->boot_devs.current_boot_dev.form = in leapraid_cfg_pages()
8268 memcpy(adapter->boot_devs.current_boot_dev.pg_dev, in leapraid_cfg_pages()
8272 rc = leapraid_op_config_page(adapter, &cfg_page.manufacturing_page0, in leapraid_cfg_pages()
8277 snprintf(adapter->adapter_attr.board_name, in leapraid_cfg_pages()
8278 sizeof(adapter->adapter_attr.board_name), in leapraid_cfg_pages()
8285 static int leapraid_evt_notify(struct leapraid_adapter *adapter) in leapraid_evt_notify() argument
8293 mutex_lock(&adapter->driver_cmds.notify_event_cmd.mutex); in leapraid_evt_notify()
8294 adapter->driver_cmds.notify_event_cmd.status = LEAPRAID_CMD_PENDING; in leapraid_evt_notify()
8297 adapter, in leapraid_evt_notify()
8298 adapter->driver_cmds.notify_event_cmd.inter_taskid); in leapraid_evt_notify()
8303 cpu_to_le32(adapter->fw_evt_s.leapraid_evt_masks[i]); in leapraid_evt_notify()
8304 init_completion(&adapter->driver_cmds.notify_event_cmd.done); in leapraid_evt_notify()
8305 leapraid_fire_task(adapter, in leapraid_evt_notify()
8306 adapter->driver_cmds.notify_event_cmd.inter_taskid); in leapraid_evt_notify()
8308 &adapter->driver_cmds.notify_event_cmd.done, in leapraid_evt_notify()
8311 if (!(adapter->driver_cmds.notify_event_cmd.status & in leapraid_evt_notify()
8317 if (!(adapter->driver_cmds.notify_event_cmd.status & in leapraid_evt_notify()
8323 evt_notify_rep = (void *)&adapter->driver_cmds.notify_event_cmd.reply; in leapraid_evt_notify()
8330 adapter->driver_cmds.notify_event_cmd.status = LEAPRAID_CMD_NOT_USED; in leapraid_evt_notify()
8331 mutex_unlock(&adapter->driver_cmds.notify_event_cmd.mutex); in leapraid_evt_notify()
8336 int leapraid_scan_dev(struct leapraid_adapter *adapter, bool async_scan_dev) in leapraid_scan_dev() argument
8343 dev_info(&adapter->pdev->dev, in leapraid_scan_dev()
8346 adapter->driver_cmds.scan_dev_cmd.status = LEAPRAID_CMD_PENDING; in leapraid_scan_dev()
8347 adapter->driver_cmds.scan_dev_cmd.async_scan_dev = async_scan_dev; in leapraid_scan_dev()
8350 adapter, in leapraid_scan_dev()
8351 adapter->driver_cmds.scan_dev_cmd.inter_taskid); in leapraid_scan_dev()
8356 adapter->scan_dev_desc.first_scan_dev_fired = 1; in leapraid_scan_dev()
8358 adapter, in leapraid_scan_dev()
8359 adapter->driver_cmds.scan_dev_cmd.inter_taskid); in leapraid_scan_dev()
8363 init_completion(&adapter->driver_cmds.scan_dev_cmd.done); in leapraid_scan_dev()
8364 leapraid_fire_task(adapter, in leapraid_scan_dev()
8365 adapter->driver_cmds.scan_dev_cmd.inter_taskid); in leapraid_scan_dev()
8366 wait_for_completion_timeout(&adapter->driver_cmds.scan_dev_cmd.done, in leapraid_scan_dev()
8368 if (!(adapter->driver_cmds.scan_dev_cmd.status & LEAPRAID_CMD_DONE)) { in leapraid_scan_dev()
8369 dev_err(&adapter->pdev->dev, "Device scan timeout!\n"); in leapraid_scan_dev()
8370 if (adapter->driver_cmds.scan_dev_cmd.status & in leapraid_scan_dev()
8378 scan_dev_rep = (void *)&adapter->driver_cmds.scan_dev_cmd.reply; in leapraid_scan_dev()
8383 dev_err(&adapter->pdev->dev, "Device scan failure!\n"); in leapraid_scan_dev()
8389 adapter->driver_cmds.scan_dev_cmd.status = LEAPRAID_CMD_NOT_USED; in leapraid_scan_dev()
8393 static void leapraid_init_task_tracker(struct leapraid_adapter *adapter) in leapraid_init_task_tracker() argument
8397 spin_lock_irqsave(&adapter->dynamic_task_desc.task_lock, flags); in leapraid_init_task_tracker()
8399 spin_unlock_irqrestore(&adapter->dynamic_task_desc.task_lock, flags); in leapraid_init_task_tracker()
8402 static void leapraid_init_rep_msg_addr(struct leapraid_adapter *adapter) in leapraid_init_rep_msg_addr() argument
8407 for (i = 0, reply_address = (u32)adapter->mem_desc.rep_msg_dma; in leapraid_init_rep_msg_addr()
8408 i < adapter->adapter_attr.rep_msg_qd; in leapraid_init_rep_msg_addr()
8410 adapter->mem_desc.rep_msg_addr[i] = cpu_to_le32(reply_address); in leapraid_init_rep_msg_addr()
8418 struct leapraid_adapter *adapter = rq->adapter; in init_rep_desc() local
8423 adapter->mem_desc in init_rep_desc()
8433 for (i = 0; i < adapter->adapter_attr.rep_desc_qd; i++) in init_rep_desc()
8437 static void leapraid_init_rep_desc(struct leapraid_adapter *adapter) in leapraid_init_rep_desc() argument
8446 reply_post_free_contig = adapter->mem_desc in leapraid_init_rep_desc()
8451 for (i = 0; i < adapter->notification_desc.iopoll_qdex; i++) { in leapraid_init_rep_desc()
8452 int_rq = &adapter->notification_desc.int_rqs[i]; in leapraid_init_rep_desc()
8458 adapter->adapter_attr.rep_desc_qd; in leapraid_init_rep_desc()
8461 for (i = 0; i < adapter->notification_desc.iopoll_qcnt; i++) { in leapraid_init_rep_desc()
8462 blk_mq_poll_rq = &adapter->notification_desc.blk_mq_poll_rqs[i]; in leapraid_init_rep_desc()
8469 adapter->adapter_attr.rep_desc_qd; in leapraid_init_rep_desc()
8473 static void leapraid_init_bar_idx_regs(struct leapraid_adapter *adapter) in leapraid_init_bar_idx_regs() argument
8479 adapter->rep_msg_host_idx = adapter->adapter_attr.rep_msg_qd - 1; in leapraid_init_bar_idx_regs()
8480 writel(adapter->rep_msg_host_idx, in leapraid_init_bar_idx_regs()
8481 &adapter->iomem_base->rep_msg_host_idx); in leapraid_init_bar_idx_regs()
8483 for (i = 0; i < adapter->notification_desc.iopoll_qdex; i++) { in leapraid_init_bar_idx_regs()
8484 int_rq = &adapter->notification_desc.int_rqs[i]; in leapraid_init_bar_idx_regs()
8488 &adapter->iomem_base->rep_post_reg_idx[j].idx); in leapraid_init_bar_idx_regs()
8491 for (i = 0; i < adapter->notification_desc.iopoll_qcnt; i++) { in leapraid_init_bar_idx_regs()
8493 &adapter->notification_desc.blk_mq_poll_rqs[i]; in leapraid_init_bar_idx_regs()
8497 &adapter->iomem_base->rep_post_reg_idx[j].idx); in leapraid_init_bar_idx_regs()
8501 static int leapraid_make_adapter_available(struct leapraid_adapter *adapter) in leapraid_make_adapter_available() argument
8505 leapraid_init_task_tracker(adapter); in leapraid_make_adapter_available()
8506 leapraid_init_rep_msg_addr(adapter); in leapraid_make_adapter_available()
8508 if (adapter->scan_dev_desc.driver_loading) in leapraid_make_adapter_available()
8509 leapraid_configure_reply_queue_affinity(adapter); in leapraid_make_adapter_available()
8511 leapraid_init_rep_desc(adapter); in leapraid_make_adapter_available()
8512 rc = leapraid_send_adapter_init(adapter); in leapraid_make_adapter_available()
8516 leapraid_init_bar_idx_regs(adapter); in leapraid_make_adapter_available()
8517 leapraid_unmask_int(adapter); in leapraid_make_adapter_available()
8518 rc = leapraid_cfg_pages(adapter); in leapraid_make_adapter_available()
8522 rc = leapraid_evt_notify(adapter); in leapraid_make_adapter_available()
8526 if (!adapter->access_ctrl.shost_recovering) { in leapraid_make_adapter_available()
8527 adapter->scan_dev_desc.wait_scan_dev_done = 1; in leapraid_make_adapter_available()
8531 return leapraid_scan_dev(adapter, false); in leapraid_make_adapter_available()
8534 int leapraid_ctrl_init(struct leapraid_adapter *adapter) in leapraid_ctrl_init() argument
8539 rc = leapraid_init_driver_cmds(adapter); in leapraid_ctrl_init()
8541 dev_err(&adapter->pdev->dev, "Init driver cmds failure\n"); in leapraid_ctrl_init()
8545 rc = leapraid_set_pcie_and_notification(adapter); in leapraid_ctrl_init()
8549 pci_set_drvdata(adapter->pdev, adapter->shost); in leapraid_ctrl_init()
8551 pcie_capability_read_dword(adapter->pdev, PCI_EXP_DEVCAP, &cap); in leapraid_ctrl_init()
8554 pcie_capability_set_word(adapter->pdev, PCI_EXP_DEVCTL, in leapraid_ctrl_init()
8557 rc = leapraid_fw_log_init(adapter); in leapraid_ctrl_init()
8559 dev_err(&adapter->pdev->dev, "FW log init failure\n"); in leapraid_ctrl_init()
8563 rc = leapraid_request_host_memory(adapter); in leapraid_ctrl_init()
8565 dev_err(&adapter->pdev->dev, "Request host memory failure\n"); in leapraid_ctrl_init()
8569 init_waitqueue_head(&adapter->reset_desc.reset_wait_queue); in leapraid_ctrl_init()
8570 init_waitqueue_head(&adapter->access_ctrl.shost_recover_wq); in leapraid_ctrl_init()
8572 rc = leapraid_alloc_dev_topo_bitmaps(adapter); in leapraid_ctrl_init()
8574 dev_err(&adapter->pdev->dev, "Alloc topo bitmaps failure\n"); in leapraid_ctrl_init()
8578 leapraid_init_event_mask(adapter); in leapraid_ctrl_init()
8580 rc = leapraid_make_adapter_available(adapter); in leapraid_ctrl_init()
8582 dev_err(&adapter->pdev->dev, in leapraid_ctrl_init()
8587 leapraid_overheat_init(adapter); in leapraid_ctrl_init()
8588 if (!adapter->overheat_desc.fault_overheat_wq) { in leapraid_ctrl_init()
8596 adapter->access_ctrl.host_removing = 1; in leapraid_ctrl_init()
8597 leapraid_fw_log_exit(adapter); in leapraid_ctrl_init()
8598 leapraid_disable_controller(adapter); in leapraid_ctrl_init()
8599 leapraid_free_host_memory(adapter); in leapraid_ctrl_init()
8600 leapraid_free_dev_topo_bitmaps(adapter); in leapraid_ctrl_init()
8601 pci_set_drvdata(adapter->pdev, NULL); in leapraid_ctrl_init()
8605 void leapraid_remove_ctrl(struct leapraid_adapter *adapter) in leapraid_remove_ctrl() argument
8607 leapraid_overheat_cleanup(adapter); in leapraid_remove_ctrl()
8608 leapraid_check_scheduled_fault_stop(adapter); in leapraid_remove_ctrl()
8609 leapraid_fw_log_stop(adapter); in leapraid_remove_ctrl()
8610 leapraid_fw_log_exit(adapter); in leapraid_remove_ctrl()
8611 leapraid_disable_controller(adapter); in leapraid_remove_ctrl()
8612 leapraid_free_host_memory(adapter); in leapraid_remove_ctrl()
8613 leapraid_free_dev_topo_bitmaps(adapter); in leapraid_remove_ctrl()
8614 leapraid_free_enc_list(adapter); in leapraid_remove_ctrl()
8615 pci_set_drvdata(adapter->pdev, NULL); in leapraid_remove_ctrl()