Lines Matching +full:sha +full:- +full:1

1 // SPDX-License-Identifier: GPL-2.0-or-later
11 ((!dev) || (dev->dev_type == SAS_PHY_UNUSED))
28 switch (fis->command) { in hisi_sas_get_ata_protocol()
81 switch (fis->features) { in hisi_sas_get_ata_protocol()
107 struct task_status_struct *ts = &task->task_status; in hisi_sas_sata_done()
108 struct ata_task_resp *resp = (struct ata_task_resp *)ts->buf; in hisi_sas_sata_done()
111 u8 *iu = &status_buf->iu[0]; in hisi_sas_sata_done()
114 resp->frame_len = sizeof(struct dev_to_host_fis); in hisi_sas_sata_done()
115 memcpy(&resp->ending_fis[0], d2h, sizeof(struct dev_to_host_fis)); in hisi_sas_sata_done()
117 ts->buf_valid_size = sizeof(*resp); in hisi_sas_sata_done()
130 max -= SAS_LINK_RATE_1_5_GBPS; in hisi_sas_get_prog_phy_linkrate_mask()
132 rate |= 1 << (i * 2); in hisi_sas_get_prog_phy_linkrate_mask()
139 return device->port->ha->lldd_ha; in dev_to_hisi_hba()
152 for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) in hisi_sas_stop_phys()
159 void *bitmap = hisi_hba->slot_index_tags; in hisi_sas_slot_index_clear()
166 if (hisi_hba->hw->slot_index_alloc || in hisi_sas_slot_index_free()
168 spin_lock(&hisi_hba->lock); in hisi_sas_slot_index_free()
170 spin_unlock(&hisi_hba->lock); in hisi_sas_slot_index_free()
176 void *bitmap = hisi_hba->slot_index_tags; in hisi_sas_slot_index_set()
185 void *bitmap = hisi_hba->slot_index_tags; in hisi_sas_slot_index_alloc()
188 return scsi_cmd_to_rq(scsi_cmnd)->tag; in hisi_sas_slot_index_alloc()
190 spin_lock(&hisi_hba->lock); in hisi_sas_slot_index_alloc()
191 index = find_next_zero_bit(bitmap, hisi_hba->slot_index_count, in hisi_sas_slot_index_alloc()
192 hisi_hba->last_slot_index + 1); in hisi_sas_slot_index_alloc()
193 if (index >= hisi_hba->slot_index_count) { in hisi_sas_slot_index_alloc()
195 hisi_hba->slot_index_count, in hisi_sas_slot_index_alloc()
197 if (index >= hisi_hba->slot_index_count) { in hisi_sas_slot_index_alloc()
198 spin_unlock(&hisi_hba->lock); in hisi_sas_slot_index_alloc()
199 return -SAS_QUEUE_FULL; in hisi_sas_slot_index_alloc()
203 hisi_hba->last_slot_index = index; in hisi_sas_slot_index_alloc()
204 spin_unlock(&hisi_hba->lock); in hisi_sas_slot_index_alloc()
213 for (i = 0; i < hisi_hba->slot_index_count; ++i) in hisi_sas_slot_index_init()
220 int device_id = slot->device_id; in hisi_sas_slot_task_free()
221 struct hisi_sas_device *sas_dev = &hisi_hba->devices[device_id]; in hisi_sas_slot_task_free()
224 struct device *dev = hisi_hba->dev; in hisi_sas_slot_task_free()
226 if (!task->lldd_task) in hisi_sas_slot_task_free()
229 task->lldd_task = NULL; in hisi_sas_slot_task_free()
231 if (!sas_protocol_ata(task->task_proto)) { in hisi_sas_slot_task_free()
232 if (slot->n_elem) in hisi_sas_slot_task_free()
233 dma_unmap_sg(dev, task->scatter, in hisi_sas_slot_task_free()
234 task->num_scatter, in hisi_sas_slot_task_free()
235 task->data_dir); in hisi_sas_slot_task_free()
236 if (slot->n_elem_dif) { in hisi_sas_slot_task_free()
237 struct sas_ssp_task *ssp_task = &task->ssp_task; in hisi_sas_slot_task_free()
238 struct scsi_cmnd *scsi_cmnd = ssp_task->cmd; in hisi_sas_slot_task_free()
242 task->data_dir); in hisi_sas_slot_task_free()
247 spin_lock(&sas_dev->lock); in hisi_sas_slot_task_free()
248 list_del_init(&slot->entry); in hisi_sas_slot_task_free()
249 spin_unlock(&sas_dev->lock); in hisi_sas_slot_task_free()
253 hisi_sas_slot_index_free(hisi_hba, slot->idx); in hisi_sas_slot_task_free()
260 hisi_hba->hw->prep_smp(hisi_hba, slot); in hisi_sas_task_prep_smp()
266 hisi_hba->hw->prep_ssp(hisi_hba, slot); in hisi_sas_task_prep_ssp()
272 hisi_hba->hw->prep_stp(hisi_hba, slot); in hisi_sas_task_prep_ata()
279 hisi_hba->hw->prep_abort(hisi_hba, slot, in hisi_sas_task_prep_abort()
287 struct device *dev = hisi_hba->dev; in hisi_sas_dma_unmap()
289 if (!sas_protocol_ata(task->task_proto)) { in hisi_sas_dma_unmap()
290 if (task->num_scatter) { in hisi_sas_dma_unmap()
292 dma_unmap_sg(dev, task->scatter, in hisi_sas_dma_unmap()
293 task->num_scatter, in hisi_sas_dma_unmap()
294 task->data_dir); in hisi_sas_dma_unmap()
295 } else if (task->task_proto & SAS_PROTOCOL_SMP) { in hisi_sas_dma_unmap()
297 dma_unmap_sg(dev, &task->smp_task.smp_req, in hisi_sas_dma_unmap()
298 1, DMA_TO_DEVICE); in hisi_sas_dma_unmap()
307 struct device *dev = hisi_hba->dev; in hisi_sas_dma_map()
310 if (sas_protocol_ata(task->task_proto)) { in hisi_sas_dma_map()
311 *n_elem = task->num_scatter; in hisi_sas_dma_map()
315 if (task->num_scatter) { in hisi_sas_dma_map()
316 *n_elem = dma_map_sg(dev, task->scatter, in hisi_sas_dma_map()
317 task->num_scatter, task->data_dir); in hisi_sas_dma_map()
319 rc = -ENOMEM; in hisi_sas_dma_map()
322 } else if (task->task_proto & SAS_PROTOCOL_SMP) { in hisi_sas_dma_map()
323 *n_elem_req = dma_map_sg(dev, &task->smp_task.smp_req, in hisi_sas_dma_map()
324 1, DMA_TO_DEVICE); in hisi_sas_dma_map()
326 rc = -ENOMEM; in hisi_sas_dma_map()
329 req_len = sg_dma_len(&task->smp_task.smp_req); in hisi_sas_dma_map()
331 rc = -EINVAL; in hisi_sas_dma_map()
340 rc = -EINVAL; in hisi_sas_dma_map()
356 struct device *dev = hisi_hba->dev; in hisi_sas_dif_dma_unmap()
359 struct sas_ssp_task *ssp_task = &task->ssp_task; in hisi_sas_dif_dma_unmap()
360 struct scsi_cmnd *scsi_cmnd = ssp_task->cmd; in hisi_sas_dif_dma_unmap()
364 task->data_dir); in hisi_sas_dif_dma_unmap()
371 struct device *dev = hisi_hba->dev; in hisi_sas_dif_dma_map()
376 if (task->num_scatter) { in hisi_sas_dif_dma_map()
377 ssp_task = &task->ssp_task; in hisi_sas_dif_dma_map()
378 scsi_cmnd = ssp_task->cmd; in hisi_sas_dif_dma_map()
384 task->data_dir); in hisi_sas_dif_dma_map()
387 return -ENOMEM; in hisi_sas_dif_dma_map()
392 rc = -EINVAL; in hisi_sas_dif_dma_map()
402 scsi_prot_sg_count(scsi_cmnd), task->data_dir); in hisi_sas_dif_dma_map()
411 struct domain_device *device = task->dev; in hisi_sas_task_prep()
413 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_task_prep()
417 struct asd_sas_port *sas_port = device->port; in hisi_sas_task_prep()
418 struct device *dev = hisi_hba->dev; in hisi_sas_task_prep()
429 sas_dev->device_id); in hisi_sas_task_prep()
432 SAS_ADDR(device->sas_addr)); in hisi_sas_task_prep()
434 return -ECOMM; in hisi_sas_task_prep()
437 if (task->uldd_task) { in hisi_sas_task_prep()
441 qc = task->uldd_task; in hisi_sas_task_prep()
442 scmd = qc->scsicmd; in hisi_sas_task_prep()
444 scmd = task->uldd_task; in hisi_sas_task_prep()
454 *dq_pointer = dq = &hisi_hba->dq[dq_index]; in hisi_sas_task_prep()
456 struct Scsi_Host *shost = hisi_hba->shost; in hisi_sas_task_prep()
457 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT]; in hisi_sas_task_prep()
458 int queue = qmap->mq_map[raw_smp_processor_id()]; in hisi_sas_task_prep()
460 *dq_pointer = dq = &hisi_hba->dq[queue]; in hisi_sas_task_prep()
464 if (port && !port->port_attached) { in hisi_sas_task_prep()
468 device->port->id); in hisi_sas_task_prep()
470 return -ECOMM; in hisi_sas_task_prep()
478 if (!sas_protocol_ata(task->task_proto)) { in hisi_sas_task_prep()
484 if (hisi_hba->hw->slot_index_alloc) in hisi_sas_task_prep()
485 rc = hisi_hba->hw->slot_index_alloc(hisi_hba, device); in hisi_sas_task_prep()
493 slot = &hisi_hba->slot_info[slot_idx]; in hisi_sas_task_prep()
495 spin_lock(&dq->lock); in hisi_sas_task_prep()
496 wr_q_index = dq->wr_point; in hisi_sas_task_prep()
497 dq->wr_point = (dq->wr_point + 1) % HISI_SAS_QUEUE_SLOTS; in hisi_sas_task_prep()
498 list_add_tail(&slot->delivery, &dq->list); in hisi_sas_task_prep()
499 spin_unlock(&dq->lock); in hisi_sas_task_prep()
500 spin_lock(&sas_dev->lock); in hisi_sas_task_prep()
501 list_add_tail(&slot->entry, &sas_dev->list); in hisi_sas_task_prep()
502 spin_unlock(&sas_dev->lock); in hisi_sas_task_prep()
504 dlvry_queue = dq->id; in hisi_sas_task_prep()
507 slot->device_id = sas_dev->device_id; in hisi_sas_task_prep()
508 slot->n_elem = n_elem; in hisi_sas_task_prep()
509 slot->n_elem_dif = n_elem_dif; in hisi_sas_task_prep()
510 slot->dlvry_queue = dlvry_queue; in hisi_sas_task_prep()
511 slot->dlvry_queue_slot = dlvry_queue_slot; in hisi_sas_task_prep()
512 cmd_hdr_base = hisi_hba->cmd_hdr[dlvry_queue]; in hisi_sas_task_prep()
513 slot->cmd_hdr = &cmd_hdr_base[dlvry_queue_slot]; in hisi_sas_task_prep()
514 slot->task = task; in hisi_sas_task_prep()
515 slot->port = port; in hisi_sas_task_prep()
516 slot->tmf = tmf; in hisi_sas_task_prep()
517 slot->is_internal = is_tmf; in hisi_sas_task_prep()
518 task->lldd_task = slot; in hisi_sas_task_prep()
520 memset(slot->cmd_hdr, 0, sizeof(struct hisi_sas_cmd_hdr)); in hisi_sas_task_prep()
525 switch (task->task_proto) { in hisi_sas_task_prep()
539 task->task_proto); in hisi_sas_task_prep()
543 spin_lock_irqsave(&task->task_state_lock, flags); in hisi_sas_task_prep()
544 task->task_state_flags |= SAS_TASK_AT_INITIATOR; in hisi_sas_task_prep()
545 spin_unlock_irqrestore(&task->task_state_lock, flags); in hisi_sas_task_prep()
548 WRITE_ONCE(slot->ready, 1); in hisi_sas_task_prep()
553 if (!sas_protocol_ata(task->task_proto)) in hisi_sas_task_prep()
570 struct domain_device *device = task->dev; in hisi_sas_task_exec()
571 struct asd_sas_port *sas_port = device->port; in hisi_sas_task_exec()
575 struct task_status_struct *ts = &task->task_status; in hisi_sas_task_exec()
577 ts->resp = SAS_TASK_UNDELIVERED; in hisi_sas_task_exec()
578 ts->stat = SAS_PHY_DOWN; in hisi_sas_task_exec()
580 * libsas will use dev->port, should in hisi_sas_task_exec()
583 if (device->dev_type != SAS_SATA_DEV) in hisi_sas_task_exec()
584 task->task_done(task); in hisi_sas_task_exec()
585 return -ECOMM; in hisi_sas_task_exec()
589 dev = hisi_hba->dev; in hisi_sas_task_exec()
591 if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags))) { in hisi_sas_task_exec()
593 return -EINVAL; in hisi_sas_task_exec()
595 down(&hisi_hba->sem); in hisi_sas_task_exec()
596 up(&hisi_hba->sem); in hisi_sas_task_exec()
605 spin_lock(&dq->lock); in hisi_sas_task_exec()
606 hisi_hba->hw->start_delivery(dq); in hisi_sas_task_exec()
607 spin_unlock(&dq->lock); in hisi_sas_task_exec()
616 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_bytes_dmaed()
617 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_bytes_dmaed()
619 if (!phy->phy_attached) in hisi_sas_bytes_dmaed()
622 if (test_bit(HISI_SAS_PM_BIT, &hisi_hba->flags) && in hisi_sas_bytes_dmaed()
623 !sas_phy->suspended) { in hisi_sas_bytes_dmaed()
624 dev_warn(hisi_hba->dev, "phy%d during suspend filtered out\n", phy_no); in hisi_sas_bytes_dmaed()
630 if (sas_phy->phy) { in hisi_sas_bytes_dmaed()
631 struct sas_phy *sphy = sas_phy->phy; in hisi_sas_bytes_dmaed()
633 sphy->negotiated_linkrate = sas_phy->linkrate; in hisi_sas_bytes_dmaed()
634 sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; in hisi_sas_bytes_dmaed()
635 sphy->maximum_linkrate_hw = in hisi_sas_bytes_dmaed()
636 hisi_hba->hw->phy_get_max_linkrate(); in hisi_sas_bytes_dmaed()
637 if (sphy->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) in hisi_sas_bytes_dmaed()
638 sphy->minimum_linkrate = phy->minimum_linkrate; in hisi_sas_bytes_dmaed()
640 if (sphy->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) in hisi_sas_bytes_dmaed()
641 sphy->maximum_linkrate = phy->maximum_linkrate; in hisi_sas_bytes_dmaed()
644 if (phy->phy_type & PORT_TYPE_SAS) { in hisi_sas_bytes_dmaed()
647 id = (struct sas_identify_frame *)phy->frame_rcvd; in hisi_sas_bytes_dmaed()
648 id->dev_type = phy->identify.device_type; in hisi_sas_bytes_dmaed()
649 id->initiator_bits = SAS_PROTOCOL_ALL; in hisi_sas_bytes_dmaed()
650 id->target_bits = phy->identify.target_port_protocols; in hisi_sas_bytes_dmaed()
651 } else if (phy->phy_type & PORT_TYPE_SATA) { in hisi_sas_bytes_dmaed()
655 sas_phy->frame_rcvd_size = phy->frame_rcvd_size; in hisi_sas_bytes_dmaed()
663 int last = hisi_hba->last_dev_id; in hisi_sas_alloc_dev()
664 int first = (hisi_hba->last_dev_id + 1) % HISI_SAS_MAX_DEVICES; in hisi_sas_alloc_dev()
667 spin_lock(&hisi_hba->lock); in hisi_sas_alloc_dev()
669 if (hisi_hba->devices[i].dev_type == SAS_PHY_UNUSED) { in hisi_sas_alloc_dev()
670 int queue = i % hisi_hba->queue_count; in hisi_sas_alloc_dev()
671 struct hisi_sas_dq *dq = &hisi_hba->dq[queue]; in hisi_sas_alloc_dev()
673 hisi_hba->devices[i].device_id = i; in hisi_sas_alloc_dev()
674 sas_dev = &hisi_hba->devices[i]; in hisi_sas_alloc_dev()
675 sas_dev->dev_status = HISI_SAS_DEV_INIT; in hisi_sas_alloc_dev()
676 sas_dev->dev_type = device->dev_type; in hisi_sas_alloc_dev()
677 sas_dev->hisi_hba = hisi_hba; in hisi_sas_alloc_dev()
678 sas_dev->sas_device = device; in hisi_sas_alloc_dev()
679 sas_dev->dq = dq; in hisi_sas_alloc_dev()
680 spin_lock_init(&sas_dev->lock); in hisi_sas_alloc_dev()
681 INIT_LIST_HEAD(&hisi_hba->devices[i].list); in hisi_sas_alloc_dev()
686 hisi_hba->last_dev_id = i; in hisi_sas_alloc_dev()
687 spin_unlock(&hisi_hba->lock); in hisi_sas_alloc_dev()
700 struct device *dev = hisi_hba->dev; in hisi_sas_init_device()
703 switch (device->dev_type) { in hisi_sas_init_device()
708 while (retry-- > 0) { in hisi_sas_init_device()
727 !test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags)) { in hisi_sas_init_device()
729 struct sata_device *sata_dev = &device->sata_dev; in hisi_sas_init_device()
730 struct ata_host *ata_host = sata_dev->ata_host; in hisi_sas_init_device()
731 struct ata_port_operations *ops = ata_host->ops; in hisi_sas_init_device()
732 struct ata_port *ap = sata_dev->ap; in hisi_sas_init_device()
737 rc = ops->hardreset(link, &classes, in hisi_sas_init_device()
746 while (retry-- > 0) { in hisi_sas_init_device()
762 struct domain_device *parent_dev = device->parent; in hisi_sas_dev_found()
764 struct device *dev = hisi_hba->dev; in hisi_sas_dev_found()
767 if (hisi_hba->hw->alloc_dev) in hisi_sas_dev_found()
768 sas_dev = hisi_hba->hw->alloc_dev(device); in hisi_sas_dev_found()
774 return -EINVAL; in hisi_sas_dev_found()
777 device->lldd_dev = sas_dev; in hisi_sas_dev_found()
778 hisi_hba->hw->setup_itct(hisi_hba, sas_dev); in hisi_sas_dev_found()
780 if (parent_dev && dev_is_expander(parent_dev->dev_type)) { in hisi_sas_dev_found()
782 u8 phy_num = parent_dev->ex_dev.num_phys; in hisi_sas_dev_found()
786 phy = &parent_dev->ex_dev.ex_phy[phy_no]; in hisi_sas_dev_found()
787 if (SAS_ADDR(phy->attached_sas_addr) == in hisi_sas_dev_found()
788 SAS_ADDR(device->sas_addr)) in hisi_sas_dev_found()
795 SAS_ADDR(device->sas_addr), in hisi_sas_dev_found()
796 SAS_ADDR(parent_dev->sas_addr)); in hisi_sas_dev_found()
797 rc = -EINVAL; in hisi_sas_dev_found()
803 sas_dev->device_id, sas_dev->dev_type); in hisi_sas_dev_found()
808 sas_dev->dev_status = HISI_SAS_DEV_NORMAL; in hisi_sas_dev_found()
834 hisi_hba->hw->phys_init(hisi_hba); in hisi_sas_scan_start()
841 struct sas_ha_struct *sha = &hisi_hba->sha; in hisi_sas_scan_finished() local
847 sas_drain_work(sha); in hisi_sas_scan_finished()
848 return 1; in hisi_sas_scan_finished()
856 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_phyup_work()
857 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phyup_work()
858 int phy_no = sas_phy->id; in hisi_sas_phyup_work()
860 phy->wait_phyup_cnt = 0; in hisi_sas_phyup_work()
861 if (phy->identify.target_port_protocols == SAS_PROTOCOL_SSP) in hisi_sas_phyup_work()
862 hisi_hba->hw->sl_notify_ssp(hisi_hba, phy_no); in hisi_sas_phyup_work()
870 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_linkreset_work()
883 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_notify_phy_event()
888 return queue_work(hisi_hba->wq, &phy->works[event]); in hisi_sas_notify_phy_event()
895 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_wait_phyup_timedout()
896 struct device *dev = hisi_hba->dev; in hisi_sas_wait_phyup_timedout()
897 int phy_no = phy->sas_phy.id; in hisi_sas_wait_phyup_timedout()
907 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_oob_ready()
908 struct device *dev = hisi_hba->dev; in hisi_sas_phy_oob_ready()
911 if (phy->phy_attached) in hisi_sas_phy_oob_ready()
914 if (!timer_pending(&phy->timer)) { in hisi_sas_phy_oob_ready()
915 if (phy->wait_phyup_cnt < HISI_SAS_WAIT_PHYUP_RETRIES) { in hisi_sas_phy_oob_ready()
916 phy->wait_phyup_cnt++; in hisi_sas_phy_oob_ready()
917 phy->timer.expires = jiffies + in hisi_sas_phy_oob_ready()
919 add_timer(&phy->timer); in hisi_sas_phy_oob_ready()
922 phy_no, phy->wait_phyup_cnt); in hisi_sas_phy_oob_ready()
923 phy->wait_phyup_cnt = 0; in hisi_sas_phy_oob_ready()
931 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_init()
932 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phy_init()
935 phy->hisi_hba = hisi_hba; in hisi_sas_phy_init()
936 phy->port = NULL; in hisi_sas_phy_init()
937 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS; in hisi_sas_phy_init()
938 phy->maximum_linkrate = hisi_hba->hw->phy_get_max_linkrate(); in hisi_sas_phy_init()
939 sas_phy->enabled = (phy_no < hisi_hba->n_phy) ? 1 : 0; in hisi_sas_phy_init()
940 sas_phy->class = SAS; in hisi_sas_phy_init()
941 sas_phy->iproto = SAS_PROTOCOL_ALL; in hisi_sas_phy_init()
942 sas_phy->tproto = 0; in hisi_sas_phy_init()
943 sas_phy->type = PHY_TYPE_PHYSICAL; in hisi_sas_phy_init()
944 sas_phy->role = PHY_ROLE_INITIATOR; in hisi_sas_phy_init()
945 sas_phy->oob_mode = OOB_NOT_CONNECTED; in hisi_sas_phy_init()
946 sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN; in hisi_sas_phy_init()
947 sas_phy->id = phy_no; in hisi_sas_phy_init()
948 sas_phy->sas_addr = &hisi_hba->sas_addr[0]; in hisi_sas_phy_init()
949 sas_phy->frame_rcvd = &phy->frame_rcvd[0]; in hisi_sas_phy_init()
950 sas_phy->ha = (struct sas_ha_struct *)hisi_hba->shost->hostdata; in hisi_sas_phy_init()
951 sas_phy->lldd_phy = phy; in hisi_sas_phy_init()
954 INIT_WORK(&phy->works[i], hisi_sas_phye_fns[i]); in hisi_sas_phy_init()
956 spin_lock_init(&phy->lock); in hisi_sas_phy_init()
958 timer_setup(&phy->timer, hisi_sas_wait_phyup_timedout, 0); in hisi_sas_phy_init()
964 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_enable()
965 struct asd_sas_phy *aphy = &phy->sas_phy; in hisi_sas_phy_enable()
966 struct sas_phy *sphy = aphy->phy; in hisi_sas_phy_enable()
969 spin_lock_irqsave(&phy->lock, flags); in hisi_sas_phy_enable()
973 if (!phy->enable) in hisi_sas_phy_enable()
974 sphy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN; in hisi_sas_phy_enable()
975 hisi_hba->hw->phy_start(hisi_hba, phy_no); in hisi_sas_phy_enable()
977 sphy->negotiated_linkrate = SAS_PHY_DISABLED; in hisi_sas_phy_enable()
978 hisi_hba->hw->phy_disable(hisi_hba, phy_no); in hisi_sas_phy_enable()
980 phy->enable = enable; in hisi_sas_phy_enable()
981 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_phy_enable()
987 struct sas_ha_struct *sas_ha = sas_phy->ha; in hisi_sas_port_notify_formed()
988 struct hisi_hba *hisi_hba = sas_ha->lldd_ha; in hisi_sas_port_notify_formed()
989 struct hisi_sas_phy *phy = sas_phy->lldd_phy; in hisi_sas_port_notify_formed()
990 struct asd_sas_port *sas_port = sas_phy->port; in hisi_sas_port_notify_formed()
998 spin_lock_irqsave(&hisi_hba->lock, flags); in hisi_sas_port_notify_formed()
999 port->port_attached = 1; in hisi_sas_port_notify_formed()
1000 port->id = phy->port_id; in hisi_sas_port_notify_formed()
1001 phy->port = port; in hisi_sas_port_notify_formed()
1002 sas_port->lldd_port = port; in hisi_sas_port_notify_formed()
1003 spin_unlock_irqrestore(&hisi_hba->lock, flags); in hisi_sas_port_notify_formed()
1013 ts = &task->task_status; in hisi_sas_do_release_task()
1015 ts->resp = SAS_TASK_COMPLETE; in hisi_sas_do_release_task()
1016 ts->stat = SAS_ABORTED_TASK; in hisi_sas_do_release_task()
1017 spin_lock_irqsave(&task->task_state_lock, flags); in hisi_sas_do_release_task()
1018 task->task_state_flags &= in hisi_sas_do_release_task()
1020 if (!slot->is_internal && task->task_proto != SAS_PROTOCOL_SMP) in hisi_sas_do_release_task()
1021 task->task_state_flags |= SAS_TASK_STATE_DONE; in hisi_sas_do_release_task()
1022 spin_unlock_irqrestore(&task->task_state_lock, flags); in hisi_sas_do_release_task()
1032 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_release_task()
1034 list_for_each_entry_safe(slot, slot2, &sas_dev->list, entry) in hisi_sas_release_task()
1035 hisi_sas_do_release_task(hisi_hba, slot->task, slot); in hisi_sas_release_task()
1045 sas_dev = &hisi_hba->devices[i]; in hisi_sas_release_tasks()
1046 device = sas_dev->sas_device; in hisi_sas_release_tasks()
1048 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || in hisi_sas_release_tasks()
1060 if (hisi_hba->hw->dereg_device) in hisi_sas_dereg_device()
1061 hisi_hba->hw->dereg_device(hisi_hba, device); in hisi_sas_dereg_device()
1066 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_dev_gone()
1068 struct device *dev = hisi_hba->dev; in hisi_sas_dev_gone()
1072 sas_dev->device_id, sas_dev->dev_type); in hisi_sas_dev_gone()
1074 down(&hisi_hba->sem); in hisi_sas_dev_gone()
1075 if (!test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags)) { in hisi_sas_dev_gone()
1081 ret = hisi_hba->hw->clear_itct(hisi_hba, sas_dev); in hisi_sas_dev_gone()
1082 device->lldd_dev = NULL; in hisi_sas_dev_gone()
1085 if (hisi_hba->hw->free_device) in hisi_sas_dev_gone()
1086 hisi_hba->hw->free_device(sas_dev); in hisi_sas_dev_gone()
1090 sas_dev->dev_type = SAS_PHY_UNUSED; in hisi_sas_dev_gone()
1091 sas_dev->sas_device = NULL; in hisi_sas_dev_gone()
1092 up(&hisi_hba->sem); in hisi_sas_dev_gone()
1105 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_set_linkrate()
1106 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phy_set_linkrate()
1109 if (r->minimum_linkrate > SAS_LINK_RATE_1_5_GBPS) in hisi_sas_phy_set_linkrate()
1110 return -EINVAL; in hisi_sas_phy_set_linkrate()
1112 if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) { in hisi_sas_phy_set_linkrate()
1113 max = sas_phy->phy->maximum_linkrate; in hisi_sas_phy_set_linkrate()
1114 min = r->minimum_linkrate; in hisi_sas_phy_set_linkrate()
1115 } else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) { in hisi_sas_phy_set_linkrate()
1116 max = r->maximum_linkrate; in hisi_sas_phy_set_linkrate()
1117 min = sas_phy->phy->minimum_linkrate; in hisi_sas_phy_set_linkrate()
1119 return -EINVAL; in hisi_sas_phy_set_linkrate()
1124 sas_phy->phy->maximum_linkrate = max; in hisi_sas_phy_set_linkrate()
1125 sas_phy->phy->minimum_linkrate = min; in hisi_sas_phy_set_linkrate()
1129 hisi_hba->hw->phy_set_linkrate(hisi_hba, phy_no, &_r); in hisi_sas_phy_set_linkrate()
1130 hisi_sas_phy_enable(hisi_hba, phy_no, 1); in hisi_sas_phy_set_linkrate()
1138 struct sas_ha_struct *sas_ha = sas_phy->ha; in hisi_sas_control_phy()
1139 struct hisi_hba *hisi_hba = sas_ha->lldd_ha; in hisi_sas_control_phy()
1140 int phy_no = sas_phy->id; in hisi_sas_control_phy()
1144 hisi_hba->hw->phy_hard_reset(hisi_hba, phy_no); in hisi_sas_control_phy()
1150 hisi_sas_phy_enable(hisi_hba, phy_no, 1); in hisi_sas_control_phy()
1160 if (hisi_hba->hw->get_events) { in hisi_sas_control_phy()
1161 hisi_hba->hw->get_events(hisi_hba, phy_no); in hisi_sas_control_phy()
1167 return -EOPNOTSUPP; in hisi_sas_control_phy()
1174 del_timer(&task->slow_task->timer); in hisi_sas_task_done()
1175 complete(&task->slow_task->completion); in hisi_sas_task_done()
1181 struct sas_task *task = slow->task; in hisi_sas_tmf_timedout()
1185 spin_lock_irqsave(&task->task_state_lock, flags); in hisi_sas_tmf_timedout()
1186 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { in hisi_sas_tmf_timedout()
1187 task->task_state_flags |= SAS_TASK_STATE_ABORTED; in hisi_sas_tmf_timedout()
1190 spin_unlock_irqrestore(&task->task_state_lock, flags); in hisi_sas_tmf_timedout()
1193 complete(&task->slow_task->completion); in hisi_sas_tmf_timedout()
1203 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_exec_internal_tmf_task()
1204 struct hisi_hba *hisi_hba = sas_dev->hisi_hba; in hisi_sas_exec_internal_tmf_task()
1205 struct device *dev = hisi_hba->dev; in hisi_sas_exec_internal_tmf_task()
1212 return -ENOMEM; in hisi_sas_exec_internal_tmf_task()
1214 task->dev = device; in hisi_sas_exec_internal_tmf_task()
1215 task->task_proto = device->tproto; in hisi_sas_exec_internal_tmf_task()
1218 task->ata_task.device_control_reg_update = 1; in hisi_sas_exec_internal_tmf_task()
1219 memcpy(&task->ata_task.fis, parameter, para_len); in hisi_sas_exec_internal_tmf_task()
1221 memcpy(&task->ssp_task, parameter, para_len); in hisi_sas_exec_internal_tmf_task()
1223 task->task_done = hisi_sas_task_done; in hisi_sas_exec_internal_tmf_task()
1225 task->slow_task->timer.function = hisi_sas_tmf_timedout; in hisi_sas_exec_internal_tmf_task()
1226 task->slow_task->timer.expires = jiffies + TASK_TIMEOUT; in hisi_sas_exec_internal_tmf_task()
1227 add_timer(&task->slow_task->timer); in hisi_sas_exec_internal_tmf_task()
1229 res = hisi_sas_task_exec(task, GFP_KERNEL, 1, tmf); in hisi_sas_exec_internal_tmf_task()
1232 del_timer(&task->slow_task->timer); in hisi_sas_exec_internal_tmf_task()
1238 wait_for_completion(&task->slow_task->completion); in hisi_sas_exec_internal_tmf_task()
1241 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) { in hisi_sas_exec_internal_tmf_task()
1242 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { in hisi_sas_exec_internal_tmf_task()
1243 struct hisi_sas_slot *slot = task->lldd_task; in hisi_sas_exec_internal_tmf_task()
1248 &hisi_hba->cq[slot->dlvry_queue]; in hisi_sas_exec_internal_tmf_task()
1253 synchronize_irq(cq->irq_no); in hisi_sas_exec_internal_tmf_task()
1254 slot->task = NULL; in hisi_sas_exec_internal_tmf_task()
1262 if (task->task_status.resp == SAS_TASK_COMPLETE && in hisi_sas_exec_internal_tmf_task()
1263 task->task_status.stat == TMF_RESP_FUNC_COMPLETE) { in hisi_sas_exec_internal_tmf_task()
1268 if (task->task_status.resp == SAS_TASK_COMPLETE && in hisi_sas_exec_internal_tmf_task()
1269 task->task_status.stat == TMF_RESP_FUNC_SUCC) { in hisi_sas_exec_internal_tmf_task()
1274 if (task->task_status.resp == SAS_TASK_COMPLETE && in hisi_sas_exec_internal_tmf_task()
1275 task->task_status.stat == SAS_DATA_UNDERRUN) { in hisi_sas_exec_internal_tmf_task()
1280 SAS_ADDR(device->sas_addr), in hisi_sas_exec_internal_tmf_task()
1281 task->task_status.resp, in hisi_sas_exec_internal_tmf_task()
1282 task->task_status.stat); in hisi_sas_exec_internal_tmf_task()
1283 res = task->task_status.residual; in hisi_sas_exec_internal_tmf_task()
1287 if (task->task_status.resp == SAS_TASK_COMPLETE && in hisi_sas_exec_internal_tmf_task()
1288 task->task_status.stat == SAS_DATA_OVERRUN) { in hisi_sas_exec_internal_tmf_task()
1290 res = -EMSGSIZE; in hisi_sas_exec_internal_tmf_task()
1294 if (task->task_status.resp == SAS_TASK_COMPLETE && in hisi_sas_exec_internal_tmf_task()
1295 task->task_status.stat == SAS_OPEN_REJECT) { in hisi_sas_exec_internal_tmf_task()
1297 res = -EIO; in hisi_sas_exec_internal_tmf_task()
1300 SAS_ADDR(device->sas_addr), in hisi_sas_exec_internal_tmf_task()
1301 task->task_status.resp, in hisi_sas_exec_internal_tmf_task()
1302 task->task_status.stat); in hisi_sas_exec_internal_tmf_task()
1331 struct ata_port *ap = device->sata_dev.ap; in hisi_sas_softreset_ata_disk()
1335 struct device *dev = hisi_hba->dev; in hisi_sas_softreset_ata_disk()
1341 hisi_sas_fill_ata_reset_cmd(link->device, 1, pmp, fis); in hisi_sas_softreset_ata_disk()
1351 hisi_sas_fill_ata_reset_cmd(link->device, 0, pmp, fis); in hisi_sas_softreset_ata_disk()
1355 dev_err(dev, "ata disk %016llx de-reset failed\n", in hisi_sas_softreset_ata_disk()
1356 SAS_ADDR(device->sas_addr)); in hisi_sas_softreset_ata_disk()
1360 SAS_ADDR(device->sas_addr)); in hisi_sas_softreset_ata_disk()
1374 if (!(device->tproto & SAS_PROTOCOL_SSP)) in hisi_sas_debug_issue_ssp_tmf()
1385 u32 state = hisi_hba->hw->get_phys_state(hisi_hba); in hisi_sas_refresh_port_id()
1389 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i]; in hisi_sas_refresh_port_id()
1390 struct domain_device *device = sas_dev->sas_device; in hisi_sas_refresh_port_id()
1396 if ((sas_dev->dev_type == SAS_PHY_UNUSED) in hisi_sas_refresh_port_id()
1397 || !device || !device->port) in hisi_sas_refresh_port_id()
1400 sas_port = device->port; in hisi_sas_refresh_port_id()
1403 list_for_each_entry(sas_phy, &sas_port->phy_list, port_phy_el) in hisi_sas_refresh_port_id()
1404 if (state & BIT(sas_phy->id)) { in hisi_sas_refresh_port_id()
1405 phy = sas_phy->lldd_phy; in hisi_sas_refresh_port_id()
1410 port->id = phy->port_id; in hisi_sas_refresh_port_id()
1413 if (!device->parent) in hisi_sas_refresh_port_id()
1414 device->linkrate = phy->sas_phy.linkrate; in hisi_sas_refresh_port_id()
1416 hisi_hba->hw->setup_itct(hisi_hba, sas_dev); in hisi_sas_refresh_port_id()
1418 port->id = 0xff; in hisi_sas_refresh_port_id()
1427 for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) { in hisi_sas_rescan_topology()
1428 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_rescan_topology()
1429 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_rescan_topology()
1430 struct asd_sas_port *sas_port = sas_phy->port; in hisi_sas_rescan_topology()
1433 if (!sas_phy->phy->enabled) in hisi_sas_rescan_topology()
1438 if (do_port_check && sas_port && sas_port->port_dev) { in hisi_sas_rescan_topology()
1439 struct domain_device *dev = sas_port->port_dev; in hisi_sas_rescan_topology()
1443 if (dev_is_expander(dev->dev_type)) in hisi_sas_rescan_topology()
1461 sas_dev = &hisi_hba->devices[i]; in hisi_sas_reset_init_all_devices()
1462 device = sas_dev->sas_device; in hisi_sas_reset_init_all_devices()
1464 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device) in hisi_sas_reset_init_all_devices()
1475 struct hisi_sas_tmf_task tmf_task = { .force_phy = 1 }; in hisi_sas_send_ata_reset_each_phy()
1476 struct ata_port *ap = device->sata_dev.ap; in hisi_sas_send_ata_reset_each_phy()
1477 struct device *dev = hisi_hba->dev; in hisi_sas_send_ata_reset_each_phy()
1485 state = hisi_hba->hw->get_phys_state(hisi_hba); in hisi_sas_send_ata_reset_each_phy()
1486 list_for_each_entry(sas_phy, &sas_port->phy_list, port_phy_el) { in hisi_sas_send_ata_reset_each_phy()
1487 if (!(state & BIT(sas_phy->id))) in hisi_sas_send_ata_reset_each_phy()
1493 tmf_task.phy_id = sas_phy->id; in hisi_sas_send_ata_reset_each_phy()
1494 hisi_sas_fill_ata_reset_cmd(link->device, 1, pmp, fis); in hisi_sas_send_ata_reset_each_phy()
1499 sas_phy->id, rc); in hisi_sas_send_ata_reset_each_phy()
1508 struct device *dev = hisi_hba->dev; in hisi_sas_terminate_stp_reject()
1512 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i]; in hisi_sas_terminate_stp_reject()
1513 struct domain_device *device = sas_dev->sas_device; in hisi_sas_terminate_stp_reject()
1515 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device) in hisi_sas_terminate_stp_reject()
1525 for (port_no = 0; port_no < hisi_hba->n_phy; port_no++) { in hisi_sas_terminate_stp_reject()
1526 struct hisi_sas_port *port = &hisi_hba->port[port_no]; in hisi_sas_terminate_stp_reject()
1527 struct asd_sas_port *sas_port = &port->sas_port; in hisi_sas_terminate_stp_reject()
1528 struct domain_device *port_dev = sas_port->port_dev; in hisi_sas_terminate_stp_reject()
1531 if (!port_dev || !dev_is_expander(port_dev->dev_type)) in hisi_sas_terminate_stp_reject()
1535 list_for_each_entry(device, &sas_port->dev_list, in hisi_sas_terminate_stp_reject()
1549 struct Scsi_Host *shost = hisi_hba->shost; in hisi_sas_controller_reset_prepare()
1551 down(&hisi_hba->sem); in hisi_sas_controller_reset_prepare()
1552 hisi_hba->phy_state = hisi_hba->hw->get_phys_state(hisi_hba); in hisi_sas_controller_reset_prepare()
1555 hisi_hba->hw->wait_cmds_complete_timeout(hisi_hba, 100, 5000); in hisi_sas_controller_reset_prepare()
1557 if (timer_pending(&hisi_hba->timer)) in hisi_sas_controller_reset_prepare()
1558 del_timer_sync(&hisi_hba->timer); in hisi_sas_controller_reset_prepare()
1560 set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); in hisi_sas_controller_reset_prepare()
1566 struct Scsi_Host *shost = hisi_hba->shost; in hisi_sas_controller_reset_done()
1569 hisi_hba->hw->phys_init(hisi_hba); in hisi_sas_controller_reset_done()
1572 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); in hisi_sas_controller_reset_done()
1574 if (hisi_hba->reject_stp_links_msk) in hisi_sas_controller_reset_done()
1577 up(&hisi_hba->sem); in hisi_sas_controller_reset_done()
1579 clear_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags); in hisi_sas_controller_reset_done()
1581 hisi_sas_rescan_topology(hisi_hba, hisi_hba->phy_state); in hisi_sas_controller_reset_done()
1587 if (!hisi_hba->hw->soft_reset) in hisi_sas_controller_prereset()
1588 return -1; in hisi_sas_controller_prereset()
1590 if (test_and_set_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags)) in hisi_sas_controller_prereset()
1591 return -1; in hisi_sas_controller_prereset()
1593 if (hisi_sas_debugfs_enable && hisi_hba->debugfs_itct[0].itct) in hisi_sas_controller_prereset()
1594 hisi_hba->hw->debugfs_snapshot_regs(hisi_hba); in hisi_sas_controller_prereset()
1601 struct device *dev = hisi_hba->dev; in hisi_sas_controller_reset()
1602 struct Scsi_Host *shost = hisi_hba->shost; in hisi_sas_controller_reset()
1608 rc = hisi_hba->hw->soft_reset(hisi_hba); in hisi_sas_controller_reset()
1611 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); in hisi_sas_controller_reset()
1612 up(&hisi_hba->sem); in hisi_sas_controller_reset()
1614 clear_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags); in hisi_sas_controller_reset()
1619 clear_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags); in hisi_sas_controller_reset()
1629 struct domain_device *device = task->dev; in hisi_sas_abort_task()
1630 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_abort_task()
1639 hisi_hba = dev_to_hisi_hba(task->dev); in hisi_sas_abort_task()
1640 dev = hisi_hba->dev; in hisi_sas_abort_task()
1642 spin_lock_irqsave(&task->task_state_lock, flags); in hisi_sas_abort_task()
1643 if (task->task_state_flags & SAS_TASK_STATE_DONE) { in hisi_sas_abort_task()
1644 struct hisi_sas_slot *slot = task->lldd_task; in hisi_sas_abort_task()
1652 cq = &hisi_hba->cq[slot->dlvry_queue]; in hisi_sas_abort_task()
1653 synchronize_irq(cq->irq_no); in hisi_sas_abort_task()
1655 spin_unlock_irqrestore(&task->task_state_lock, flags); in hisi_sas_abort_task()
1659 task->task_state_flags |= SAS_TASK_STATE_ABORTED; in hisi_sas_abort_task()
1660 spin_unlock_irqrestore(&task->task_state_lock, flags); in hisi_sas_abort_task()
1662 if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) { in hisi_sas_abort_task()
1663 struct scsi_cmnd *cmnd = task->uldd_task; in hisi_sas_abort_task()
1664 struct hisi_sas_slot *slot = task->lldd_task; in hisi_sas_abort_task()
1665 u16 tag = slot->idx; in hisi_sas_abort_task()
1668 int_to_scsilun(cmnd->device->lun, &lun); in hisi_sas_abort_task()
1672 rc = hisi_sas_debug_issue_ssp_tmf(task->dev, lun.scsi_lun, in hisi_sas_abort_task()
1691 if (task->lldd_task) in hisi_sas_abort_task()
1694 } else if (task->task_proto & SAS_PROTOCOL_SATA || in hisi_sas_abort_task()
1695 task->task_proto & SAS_PROTOCOL_STP) { in hisi_sas_abort_task()
1696 if (task->dev->dev_type == SAS_SATA_DEV) { in hisi_sas_abort_task()
1707 } else if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SMP) { in hisi_sas_abort_task()
1709 struct hisi_sas_slot *slot = task->lldd_task; in hisi_sas_abort_task()
1710 u32 tag = slot->idx; in hisi_sas_abort_task()
1711 struct hisi_sas_cq *cq = &hisi_hba->cq[slot->dlvry_queue]; in hisi_sas_abort_task()
1717 task->lldd_task) { in hisi_sas_abort_task()
1722 synchronize_irq(cq->irq_no); in hisi_sas_abort_task()
1723 slot->task = NULL; in hisi_sas_abort_task()
1736 struct device *dev = hisi_hba->dev; in hisi_sas_abort_task_set()
1773 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_debug_I_T_nexus_reset()
1775 struct sas_ha_struct *sas_ha = &hisi_hba->sha; in hisi_sas_debug_I_T_nexus_reset()
1779 if (!local_phy->enabled) { in hisi_sas_debug_I_T_nexus_reset()
1781 return -ENODEV; in hisi_sas_debug_I_T_nexus_reset()
1786 sas_ha->sas_phy[local_phy->number]; in hisi_sas_debug_I_T_nexus_reset()
1789 phy->in_reset = 1; in hisi_sas_debug_I_T_nexus_reset()
1790 phy->reset_completion = &phyreset; in hisi_sas_debug_I_T_nexus_reset()
1793 reset_type = (sas_dev->dev_status == HISI_SAS_DEV_INIT || in hisi_sas_debug_I_T_nexus_reset()
1801 sas_ha->sas_phy[local_phy->number]; in hisi_sas_debug_I_T_nexus_reset()
1808 spin_lock_irqsave(&phy->lock, flags); in hisi_sas_debug_I_T_nexus_reset()
1809 phy->reset_completion = NULL; in hisi_sas_debug_I_T_nexus_reset()
1810 phy->in_reset = 0; in hisi_sas_debug_I_T_nexus_reset()
1811 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_debug_I_T_nexus_reset()
1815 hisi_sas_phy_down(hisi_hba, sas_phy->id, 0, GFP_KERNEL); in hisi_sas_debug_I_T_nexus_reset()
1816 } else if (sas_dev->dev_status != HISI_SAS_DEV_INIT) { in hisi_sas_debug_I_T_nexus_reset()
1831 struct device *dev = hisi_hba->dev; in hisi_sas_I_T_nexus_reset()
1850 if ((rc == TMF_RESP_FUNC_COMPLETE) || (rc == -ENODEV)) in hisi_sas_I_T_nexus_reset()
1858 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_lu_reset()
1860 struct device *dev = hisi_hba->dev; in hisi_sas_lu_reset()
1892 sas_dev->device_id, rc); in hisi_sas_lu_reset()
1904 dev_info(hisi_hba->dev, "I_T_nexus reset fail for dev:%016llx rc=%d\n", in hisi_sas_async_I_T_nexus_reset()
1905 SAS_ADDR(device->sas_addr), rc); in hisi_sas_async_I_T_nexus_reset()
1910 struct hisi_hba *hisi_hba = sas_ha->lldd_ha; in hisi_sas_clear_nexus_ha()
1915 queue_work(hisi_hba->wq, &r.work); in hisi_sas_clear_nexus_ha()
1921 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i]; in hisi_sas_clear_nexus_ha()
1922 struct domain_device *device = sas_dev->sas_device; in hisi_sas_clear_nexus_ha()
1924 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device || in hisi_sas_clear_nexus_ha()
1925 dev_is_expander(device->dev_type)) in hisi_sas_clear_nexus_ha()
1944 if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) { in hisi_sas_query_task()
1945 struct scsi_cmnd *cmnd = task->uldd_task; in hisi_sas_query_task()
1946 struct domain_device *device = task->dev; in hisi_sas_query_task()
1947 struct hisi_sas_slot *slot = task->lldd_task; in hisi_sas_query_task()
1948 u32 tag = slot->idx; in hisi_sas_query_task()
1950 int_to_scsilun(cmnd->device->lun, &lun); in hisi_sas_query_task()
1977 struct domain_device *device = task->dev; in hisi_sas_internal_abort_task_exec()
1978 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_internal_abort_task_exec()
1979 struct device *dev = hisi_hba->dev; in hisi_sas_internal_abort_task_exec()
1982 struct asd_sas_port *sas_port = device->port; in hisi_sas_internal_abort_task_exec()
1988 if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags))) in hisi_sas_internal_abort_task_exec()
1989 return -EINVAL; in hisi_sas_internal_abort_task_exec()
1991 if (!device->port) in hisi_sas_internal_abort_task_exec()
1992 return -1; in hisi_sas_internal_abort_task_exec()
2002 slot = &hisi_hba->slot_info[slot_idx]; in hisi_sas_internal_abort_task_exec()
2004 spin_lock(&dq->lock); in hisi_sas_internal_abort_task_exec()
2005 wr_q_index = dq->wr_point; in hisi_sas_internal_abort_task_exec()
2006 dq->wr_point = (dq->wr_point + 1) % HISI_SAS_QUEUE_SLOTS; in hisi_sas_internal_abort_task_exec()
2007 list_add_tail(&slot->delivery, &dq->list); in hisi_sas_internal_abort_task_exec()
2008 spin_unlock(&dq->lock); in hisi_sas_internal_abort_task_exec()
2009 spin_lock(&sas_dev->lock); in hisi_sas_internal_abort_task_exec()
2010 list_add_tail(&slot->entry, &sas_dev->list); in hisi_sas_internal_abort_task_exec()
2011 spin_unlock(&sas_dev->lock); in hisi_sas_internal_abort_task_exec()
2013 dlvry_queue = dq->id; in hisi_sas_internal_abort_task_exec()
2016 slot->device_id = sas_dev->device_id; in hisi_sas_internal_abort_task_exec()
2017 slot->n_elem = n_elem; in hisi_sas_internal_abort_task_exec()
2018 slot->dlvry_queue = dlvry_queue; in hisi_sas_internal_abort_task_exec()
2019 slot->dlvry_queue_slot = dlvry_queue_slot; in hisi_sas_internal_abort_task_exec()
2020 cmd_hdr_base = hisi_hba->cmd_hdr[dlvry_queue]; in hisi_sas_internal_abort_task_exec()
2021 slot->cmd_hdr = &cmd_hdr_base[dlvry_queue_slot]; in hisi_sas_internal_abort_task_exec()
2022 slot->task = task; in hisi_sas_internal_abort_task_exec()
2023 slot->port = port; in hisi_sas_internal_abort_task_exec()
2024 slot->is_internal = true; in hisi_sas_internal_abort_task_exec()
2025 task->lldd_task = slot; in hisi_sas_internal_abort_task_exec()
2027 memset(slot->cmd_hdr, 0, sizeof(struct hisi_sas_cmd_hdr)); in hisi_sas_internal_abort_task_exec()
2035 spin_lock_irqsave(&task->task_state_lock, flags); in hisi_sas_internal_abort_task_exec()
2036 task->task_state_flags |= SAS_TASK_AT_INITIATOR; in hisi_sas_internal_abort_task_exec()
2037 spin_unlock_irqrestore(&task->task_state_lock, flags); in hisi_sas_internal_abort_task_exec()
2038 WRITE_ONCE(slot->ready, 1); in hisi_sas_internal_abort_task_exec()
2040 spin_lock(&dq->lock); in hisi_sas_internal_abort_task_exec()
2041 hisi_hba->hw->start_delivery(dq); in hisi_sas_internal_abort_task_exec()
2042 spin_unlock(&dq->lock); in hisi_sas_internal_abort_task_exec()
2053 * _hisi_sas_internal_task_abort -- execute an internal
2070 struct hisi_sas_device *sas_dev = device->lldd_dev; in _hisi_sas_internal_task_abort()
2071 struct device *dev = hisi_hba->dev; in _hisi_sas_internal_task_abort()
2080 if (!hisi_hba->hw->prep_abort) in _hisi_sas_internal_task_abort()
2083 if (test_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags)) in _hisi_sas_internal_task_abort()
2084 return -EIO; in _hisi_sas_internal_task_abort()
2088 return -ENOMEM; in _hisi_sas_internal_task_abort()
2090 task->dev = device; in _hisi_sas_internal_task_abort()
2091 task->task_proto = device->tproto; in _hisi_sas_internal_task_abort()
2092 task->task_done = hisi_sas_task_done; in _hisi_sas_internal_task_abort()
2093 task->slow_task->timer.function = hisi_sas_tmf_timedout; in _hisi_sas_internal_task_abort()
2094 task->slow_task->timer.expires = jiffies + INTERNAL_ABORT_TIMEOUT; in _hisi_sas_internal_task_abort()
2095 add_timer(&task->slow_task->timer); in _hisi_sas_internal_task_abort()
2097 res = hisi_sas_internal_abort_task_exec(hisi_hba, sas_dev->device_id, in _hisi_sas_internal_task_abort()
2100 del_timer(&task->slow_task->timer); in _hisi_sas_internal_task_abort()
2105 wait_for_completion(&task->slow_task->completion); in _hisi_sas_internal_task_abort()
2109 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) { in _hisi_sas_internal_task_abort()
2110 if (hisi_sas_debugfs_enable && hisi_hba->debugfs_itct[0].itct) in _hisi_sas_internal_task_abort()
2111 queue_work(hisi_hba->wq, &hisi_hba->debugfs_work); in _hisi_sas_internal_task_abort()
2113 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { in _hisi_sas_internal_task_abort()
2114 struct hisi_sas_slot *slot = task->lldd_task; in _hisi_sas_internal_task_abort()
2116 set_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags); in _hisi_sas_internal_task_abort()
2120 &hisi_hba->cq[slot->dlvry_queue]; in _hisi_sas_internal_task_abort()
2125 synchronize_irq(cq->irq_no); in _hisi_sas_internal_task_abort()
2126 slot->task = NULL; in _hisi_sas_internal_task_abort()
2131 queue_work(hisi_hba->wq, &hisi_hba->rst_work); in _hisi_sas_internal_task_abort()
2136 res = -EIO; in _hisi_sas_internal_task_abort()
2142 if (task->task_status.resp == SAS_TASK_COMPLETE && in _hisi_sas_internal_task_abort()
2143 task->task_status.stat == TMF_RESP_FUNC_COMPLETE) { in _hisi_sas_internal_task_abort()
2148 if (task->task_status.resp == SAS_TASK_COMPLETE && in _hisi_sas_internal_task_abort()
2149 task->task_status.stat == TMF_RESP_FUNC_SUCC) { in _hisi_sas_internal_task_abort()
2156 SAS_ADDR(device->sas_addr), task, in _hisi_sas_internal_task_abort()
2157 task->task_status.resp, /* 0 is complete, -1 is undelivered */ in _hisi_sas_internal_task_abort()
2158 task->task_status.stat); in _hisi_sas_internal_task_abort()
2170 struct device *dev = hisi_hba->dev; in hisi_sas_internal_task_abort()
2176 slot = &hisi_hba->slot_info[tag]; in hisi_sas_internal_task_abort()
2177 dq = &hisi_hba->dq[slot->dlvry_queue]; in hisi_sas_internal_task_abort()
2182 for (i = 0; i < hisi_hba->cq_nvecs; i++) { in hisi_sas_internal_task_abort()
2183 struct hisi_sas_cq *cq = &hisi_hba->cq[i]; in hisi_sas_internal_task_abort()
2184 const struct cpumask *mask = cq->irq_mask; in hisi_sas_internal_task_abort()
2188 dq = &hisi_hba->dq[i]; in hisi_sas_internal_task_abort()
2199 return -EINVAL; in hisi_sas_internal_task_abort()
2210 static int hisi_sas_write_gpio(struct sas_ha_struct *sha, u8 reg_type, in hisi_sas_write_gpio() argument
2213 struct hisi_hba *hisi_hba = sha->lldd_ha; in hisi_sas_write_gpio()
2215 if (!hisi_hba->hw->write_gpio) in hisi_sas_write_gpio()
2216 return -EOPNOTSUPP; in hisi_sas_write_gpio()
2218 return hisi_hba->hw->write_gpio(hisi_hba, reg_type, in hisi_sas_write_gpio()
2224 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phy_disconnected()
2225 struct sas_phy *sphy = sas_phy->phy; in hisi_sas_phy_disconnected()
2228 phy->phy_attached = 0; in hisi_sas_phy_disconnected()
2229 phy->phy_type = 0; in hisi_sas_phy_disconnected()
2230 phy->port = NULL; in hisi_sas_phy_disconnected()
2232 spin_lock_irqsave(&phy->lock, flags); in hisi_sas_phy_disconnected()
2233 if (phy->enable) in hisi_sas_phy_disconnected()
2234 sphy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN; in hisi_sas_phy_disconnected()
2236 sphy->negotiated_linkrate = SAS_PHY_DISABLED; in hisi_sas_phy_disconnected()
2237 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_phy_disconnected()
2243 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_down()
2244 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phy_down()
2245 struct device *dev = hisi_hba->dev; in hisi_sas_phy_down()
2252 struct hisi_sas_port *port = phy->port; in hisi_sas_phy_down()
2254 if (test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags) || in hisi_sas_phy_down()
2255 phy->in_reset) { in hisi_sas_phy_down()
2264 if (phy->phy_type & PORT_TYPE_SAS) { in hisi_sas_phy_down()
2265 int port_id = port->id; in hisi_sas_phy_down()
2267 if (!hisi_hba->hw->get_wideport_bitmap(hisi_hba, in hisi_sas_phy_down()
2269 port->port_attached = 0; in hisi_sas_phy_down()
2270 } else if (phy->phy_type & PORT_TYPE_SATA) in hisi_sas_phy_down()
2271 port->port_attached = 0; in hisi_sas_phy_down()
2282 for (i = 0; i < hisi_hba->cq_nvecs; i++) { in hisi_sas_sync_irqs()
2283 struct hisi_sas_cq *cq = &hisi_hba->cq[i]; in hisi_sas_sync_irqs()
2285 synchronize_irq(cq->irq_no); in hisi_sas_sync_irqs()
2295 return -EOPNOTSUPP; in hisi_sas_host_reset()
2297 queue_work(hisi_hba->wq, &hisi_hba->rst_work); in hisi_sas_host_reset()
2325 struct hisi_sas_breakpoint *sata_breakpoint = hisi_hba->sata_breakpoint; in hisi_sas_init_mem()
2327 for (i = 0; i < hisi_hba->queue_count; i++) { in hisi_sas_init_mem()
2328 struct hisi_sas_cq *cq = &hisi_hba->cq[i]; in hisi_sas_init_mem()
2329 struct hisi_sas_dq *dq = &hisi_hba->dq[i]; in hisi_sas_init_mem()
2330 struct hisi_sas_cmd_hdr *cmd_hdr = hisi_hba->cmd_hdr[i]; in hisi_sas_init_mem()
2336 dq->wr_point = 0; in hisi_sas_init_mem()
2338 s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS; in hisi_sas_init_mem()
2339 memset(hisi_hba->complete_hdr[i], 0, s); in hisi_sas_init_mem()
2340 cq->rd_point = 0; in hisi_sas_init_mem()
2343 s = sizeof(struct hisi_sas_initial_fis) * hisi_hba->n_phy; in hisi_sas_init_mem()
2344 memset(hisi_hba->initial_fis, 0, s); in hisi_sas_init_mem()
2347 memset(hisi_hba->iost, 0, s); in hisi_sas_init_mem()
2350 memset(hisi_hba->breakpoint, 0, s); in hisi_sas_init_mem()
2360 struct device *dev = hisi_hba->dev; in hisi_sas_alloc()
2365 sema_init(&hisi_hba->sem, 1); in hisi_sas_alloc()
2366 spin_lock_init(&hisi_hba->lock); in hisi_sas_alloc()
2367 for (i = 0; i < hisi_hba->n_phy; i++) { in hisi_sas_alloc()
2369 hisi_hba->port[i].port_attached = 0; in hisi_sas_alloc()
2370 hisi_hba->port[i].id = -1; in hisi_sas_alloc()
2374 hisi_hba->devices[i].dev_type = SAS_PHY_UNUSED; in hisi_sas_alloc()
2375 hisi_hba->devices[i].device_id = i; in hisi_sas_alloc()
2376 hisi_hba->devices[i].dev_status = HISI_SAS_DEV_INIT; in hisi_sas_alloc()
2379 for (i = 0; i < hisi_hba->queue_count; i++) { in hisi_sas_alloc()
2380 struct hisi_sas_cq *cq = &hisi_hba->cq[i]; in hisi_sas_alloc()
2381 struct hisi_sas_dq *dq = &hisi_hba->dq[i]; in hisi_sas_alloc()
2384 cq->id = i; in hisi_sas_alloc()
2385 cq->hisi_hba = hisi_hba; in hisi_sas_alloc()
2388 spin_lock_init(&dq->lock); in hisi_sas_alloc()
2389 INIT_LIST_HEAD(&dq->list); in hisi_sas_alloc()
2390 dq->id = i; in hisi_sas_alloc()
2391 dq->hisi_hba = hisi_hba; in hisi_sas_alloc()
2395 hisi_hba->cmd_hdr[i] = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2396 &hisi_hba->cmd_hdr_dma[i], in hisi_sas_alloc()
2398 if (!hisi_hba->cmd_hdr[i]) in hisi_sas_alloc()
2402 s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS; in hisi_sas_alloc()
2403 hisi_hba->complete_hdr[i] = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2404 &hisi_hba->complete_hdr_dma[i], in hisi_sas_alloc()
2406 if (!hisi_hba->complete_hdr[i]) in hisi_sas_alloc()
2411 hisi_hba->itct = dmam_alloc_coherent(dev, s, &hisi_hba->itct_dma, in hisi_sas_alloc()
2413 if (!hisi_hba->itct) in hisi_sas_alloc()
2416 hisi_hba->slot_info = devm_kcalloc(dev, max_command_entries, in hisi_sas_alloc()
2419 if (!hisi_hba->slot_info) in hisi_sas_alloc()
2424 if (hisi_hba->prot_mask & HISI_SAS_DIX_PROT_MASK) in hisi_sas_alloc()
2446 slot = &hisi_hba->slot_info[slot_index]; in hisi_sas_alloc()
2447 slot->buf = buf; in hisi_sas_alloc()
2448 slot->buf_dma = buf_dma; in hisi_sas_alloc()
2449 slot->idx = slot_index; in hisi_sas_alloc()
2457 hisi_hba->iost = dmam_alloc_coherent(dev, s, &hisi_hba->iost_dma, in hisi_sas_alloc()
2459 if (!hisi_hba->iost) in hisi_sas_alloc()
2463 hisi_hba->breakpoint = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2464 &hisi_hba->breakpoint_dma, in hisi_sas_alloc()
2466 if (!hisi_hba->breakpoint) in hisi_sas_alloc()
2469 hisi_hba->slot_index_count = max_command_entries; in hisi_sas_alloc()
2470 s = hisi_hba->slot_index_count / BITS_PER_BYTE; in hisi_sas_alloc()
2471 hisi_hba->slot_index_tags = devm_kzalloc(dev, s, GFP_KERNEL); in hisi_sas_alloc()
2472 if (!hisi_hba->slot_index_tags) in hisi_sas_alloc()
2476 hisi_hba->initial_fis = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2477 &hisi_hba->initial_fis_dma, in hisi_sas_alloc()
2479 if (!hisi_hba->initial_fis) in hisi_sas_alloc()
2483 hisi_hba->sata_breakpoint = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2484 &hisi_hba->sata_breakpoint_dma, in hisi_sas_alloc()
2486 if (!hisi_hba->sata_breakpoint) in hisi_sas_alloc()
2490 hisi_hba->last_slot_index = HISI_SAS_UNRESERVED_IPTT; in hisi_sas_alloc()
2492 hisi_hba->wq = create_singlethread_workqueue(dev_name(dev)); in hisi_sas_alloc()
2493 if (!hisi_hba->wq) { in hisi_sas_alloc()
2500 return -ENOMEM; in hisi_sas_alloc()
2508 for (i = 0; i < hisi_hba->n_phy; i++) { in hisi_sas_free()
2509 struct hisi_sas_phy *phy = &hisi_hba->phy[i]; in hisi_sas_free()
2511 del_timer_sync(&phy->timer); in hisi_sas_free()
2514 if (hisi_hba->wq) in hisi_sas_free()
2515 destroy_workqueue(hisi_hba->wq); in hisi_sas_free()
2536 if (hisi_sas_controller_prereset(rst->hisi_hba)) in hisi_sas_sync_rst_work_handler()
2539 if (!hisi_sas_controller_reset(rst->hisi_hba)) in hisi_sas_sync_rst_work_handler()
2540 rst->done = true; in hisi_sas_sync_rst_work_handler()
2542 complete(rst->completion); in hisi_sas_sync_rst_work_handler()
2548 struct device *dev = hisi_hba->dev; in hisi_sas_get_fw_info()
2549 struct platform_device *pdev = hisi_hba->platform_dev; in hisi_sas_get_fw_info()
2550 struct device_node *np = pdev ? pdev->dev.of_node : NULL; in hisi_sas_get_fw_info()
2553 if (device_property_read_u8_array(dev, "sas-addr", hisi_hba->sas_addr, in hisi_sas_get_fw_info()
2555 dev_err(dev, "could not get property sas-addr\n"); in hisi_sas_get_fw_info()
2556 return -ENOENT; in hisi_sas_get_fw_info()
2561 * These properties are only required for platform device-based in hisi_sas_get_fw_info()
2564 hisi_hba->ctrl = syscon_regmap_lookup_by_phandle(np, in hisi_sas_get_fw_info()
2565 "hisilicon,sas-syscon"); in hisi_sas_get_fw_info()
2566 if (IS_ERR(hisi_hba->ctrl)) { in hisi_sas_get_fw_info()
2568 return -ENOENT; in hisi_sas_get_fw_info()
2571 if (device_property_read_u32(dev, "ctrl-reset-reg", in hisi_sas_get_fw_info()
2572 &hisi_hba->ctrl_reset_reg)) { in hisi_sas_get_fw_info()
2573 dev_err(dev, "could not get property ctrl-reset-reg\n"); in hisi_sas_get_fw_info()
2574 return -ENOENT; in hisi_sas_get_fw_info()
2577 if (device_property_read_u32(dev, "ctrl-reset-sts-reg", in hisi_sas_get_fw_info()
2578 &hisi_hba->ctrl_reset_sts_reg)) { in hisi_sas_get_fw_info()
2579 dev_err(dev, "could not get property ctrl-reset-sts-reg\n"); in hisi_sas_get_fw_info()
2580 return -ENOENT; in hisi_sas_get_fw_info()
2583 if (device_property_read_u32(dev, "ctrl-clock-ena-reg", in hisi_sas_get_fw_info()
2584 &hisi_hba->ctrl_clock_ena_reg)) { in hisi_sas_get_fw_info()
2585 dev_err(dev, "could not get property ctrl-clock-ena-reg\n"); in hisi_sas_get_fw_info()
2586 return -ENOENT; in hisi_sas_get_fw_info()
2594 hisi_hba->refclk_frequency_mhz = clk_get_rate(refclk) / 1000000; in hisi_sas_get_fw_info()
2596 if (device_property_read_u32(dev, "phy-count", &hisi_hba->n_phy)) { in hisi_sas_get_fw_info()
2597 dev_err(dev, "could not get property phy-count\n"); in hisi_sas_get_fw_info()
2598 return -ENOENT; in hisi_sas_get_fw_info()
2601 if (device_property_read_u32(dev, "queue-count", in hisi_sas_get_fw_info()
2602 &hisi_hba->queue_count)) { in hisi_sas_get_fw_info()
2603 dev_err(dev, "could not get property queue-count\n"); in hisi_sas_get_fw_info()
2604 return -ENOENT; in hisi_sas_get_fw_info()
2617 struct device *dev = &pdev->dev; in hisi_sas_shost_alloc()
2620 shost = scsi_host_alloc(hw->sht, sizeof(*hisi_hba)); in hisi_sas_shost_alloc()
2627 INIT_WORK(&hisi_hba->rst_work, hisi_sas_rst_work_handler); in hisi_sas_shost_alloc()
2628 hisi_hba->hw = hw; in hisi_sas_shost_alloc()
2629 hisi_hba->dev = dev; in hisi_sas_shost_alloc()
2630 hisi_hba->platform_dev = pdev; in hisi_sas_shost_alloc()
2631 hisi_hba->shost = shost; in hisi_sas_shost_alloc()
2632 SHOST_TO_SAS_HA(shost) = &hisi_hba->sha; in hisi_sas_shost_alloc()
2634 timer_setup(&hisi_hba->timer, NULL, 0); in hisi_sas_shost_alloc()
2648 hisi_hba->regs = devm_platform_ioremap_resource(pdev, 0); in hisi_sas_shost_alloc()
2649 if (IS_ERR(hisi_hba->regs)) in hisi_sas_shost_alloc()
2652 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); in hisi_sas_shost_alloc()
2654 hisi_hba->sgpio_regs = devm_ioremap_resource(dev, res); in hisi_sas_shost_alloc()
2655 if (IS_ERR(hisi_hba->sgpio_regs)) in hisi_sas_shost_alloc()
2673 if (hisi_hba->hw->interrupt_preinit) in hisi_sas_interrupt_preinit()
2674 return hisi_hba->hw->interrupt_preinit(hisi_hba); in hisi_sas_interrupt_preinit()
2683 struct device *dev = &pdev->dev; in hisi_sas_probe()
2686 struct sas_ha_struct *sha; in hisi_sas_probe() local
2691 return -ENOMEM; in hisi_sas_probe()
2693 sha = SHOST_TO_SAS_HA(shost); in hisi_sas_probe()
2695 platform_set_drvdata(pdev, sha); in hisi_sas_probe()
2697 phy_nr = port_nr = hisi_hba->n_phy; in hisi_sas_probe()
2702 rc = -ENOMEM; in hisi_sas_probe()
2706 sha->sas_phy = arr_phy; in hisi_sas_probe()
2707 sha->sas_port = arr_port; in hisi_sas_probe()
2708 sha->lldd_ha = hisi_hba; in hisi_sas_probe()
2710 shost->transportt = hisi_sas_stt; in hisi_sas_probe()
2711 shost->max_id = HISI_SAS_MAX_DEVICES; in hisi_sas_probe()
2712 shost->max_lun = ~0; in hisi_sas_probe()
2713 shost->max_channel = 1; in hisi_sas_probe()
2714 shost->max_cmd_len = 16; in hisi_sas_probe()
2715 if (hisi_hba->hw->slot_index_alloc) { in hisi_sas_probe()
2716 shost->can_queue = HISI_SAS_MAX_COMMANDS; in hisi_sas_probe()
2717 shost->cmd_per_lun = HISI_SAS_MAX_COMMANDS; in hisi_sas_probe()
2719 shost->can_queue = HISI_SAS_UNRESERVED_IPTT; in hisi_sas_probe()
2720 shost->cmd_per_lun = HISI_SAS_UNRESERVED_IPTT; in hisi_sas_probe()
2723 sha->sas_ha_name = DRV_NAME; in hisi_sas_probe()
2724 sha->dev = hisi_hba->dev; in hisi_sas_probe()
2725 sha->lldd_module = THIS_MODULE; in hisi_sas_probe()
2726 sha->sas_addr = &hisi_hba->sas_addr[0]; in hisi_sas_probe()
2727 sha->num_phys = hisi_hba->n_phy; in hisi_sas_probe()
2728 sha->core.shost = hisi_hba->shost; in hisi_sas_probe()
2730 for (i = 0; i < hisi_hba->n_phy; i++) { in hisi_sas_probe()
2731 sha->sas_phy[i] = &hisi_hba->phy[i].sas_phy; in hisi_sas_probe()
2732 sha->sas_port[i] = &hisi_hba->port[i].sas_port; in hisi_sas_probe()
2739 rc = scsi_add_host(shost, &pdev->dev); in hisi_sas_probe()
2743 rc = sas_register_ha(sha); in hisi_sas_probe()
2747 rc = hisi_hba->hw->hw_init(hisi_hba); in hisi_sas_probe()
2756 sas_unregister_ha(sha); in hisi_sas_probe()
2768 struct sas_ha_struct *sha = platform_get_drvdata(pdev); in hisi_sas_remove() local
2769 struct hisi_hba *hisi_hba = sha->lldd_ha; in hisi_sas_remove()
2770 struct Scsi_Host *shost = sha->core.shost; in hisi_sas_remove()
2772 if (timer_pending(&hisi_hba->timer)) in hisi_sas_remove()
2773 del_timer(&hisi_hba->timer); in hisi_sas_remove()
2775 sas_unregister_ha(sha); in hisi_sas_remove()
2776 sas_remove_host(sha->core.shost); in hisi_sas_remove()
2791 u32 hisi_sas_debugfs_dump_count = 1;
2810 return -ENOMEM; in hisi_sas_init()