Lines Matching +full:phy +full:- +full:device

1 // SPDX-License-Identifier: GPL-2.0-or-later
11 ((!dev) || (dev->dev_type == SAS_PHY_UNUSED))
13 static int hisi_sas_softreset_ata_disk(struct domain_device *device);
17 struct domain_device *device);
18 static void hisi_sas_dev_gone(struct domain_device *device);
29 switch (qc->tf.protocol) { in hisi_sas_get_ata_protocol_from_tf()
46 struct host_to_dev_fis *fis = &task->ata_task.fis; in hisi_sas_get_ata_protocol()
47 struct ata_queued_cmd *qc = task->uldd_task; in hisi_sas_get_ata_protocol()
48 int direction = task->data_dir; in hisi_sas_get_ata_protocol()
50 switch (fis->command) { in hisi_sas_get_ata_protocol()
103 switch (fis->features) { in hisi_sas_get_ata_protocol()
129 struct task_status_struct *ts = &task->task_status; in hisi_sas_sata_done()
130 struct ata_task_resp *resp = (struct ata_task_resp *)ts->buf; in hisi_sas_sata_done()
133 u8 *iu = &status_buf->iu[0]; in hisi_sas_sata_done()
136 resp->frame_len = sizeof(struct dev_to_host_fis); in hisi_sas_sata_done()
137 memcpy(&resp->ending_fis[0], d2h, sizeof(struct dev_to_host_fis)); in hisi_sas_sata_done()
139 ts->buf_valid_size = sizeof(*resp); in hisi_sas_sata_done()
152 max -= SAS_LINK_RATE_1_5_GBPS; in hisi_sas_get_prog_phy_linkrate_mask()
159 static struct hisi_hba *dev_to_hisi_hba(struct domain_device *device) in dev_to_hisi_hba() argument
161 return device->port->ha->lldd_ha; in dev_to_hisi_hba()
174 for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) in hisi_sas_stop_phys()
181 void *bitmap = hisi_hba->slot_index_tags; in hisi_sas_slot_index_clear()
188 if (hisi_hba->hw->slot_index_alloc || in hisi_sas_slot_index_free()
190 spin_lock(&hisi_hba->lock); in hisi_sas_slot_index_free()
192 spin_unlock(&hisi_hba->lock); in hisi_sas_slot_index_free()
198 void *bitmap = hisi_hba->slot_index_tags; in hisi_sas_slot_index_set()
207 void *bitmap = hisi_hba->slot_index_tags; in hisi_sas_slot_index_alloc()
210 return rq->tag + HISI_SAS_RESERVED_IPTT; in hisi_sas_slot_index_alloc()
212 spin_lock(&hisi_hba->lock); in hisi_sas_slot_index_alloc()
214 hisi_hba->last_slot_index + 1); in hisi_sas_slot_index_alloc()
220 spin_unlock(&hisi_hba->lock); in hisi_sas_slot_index_alloc()
221 return -SAS_QUEUE_FULL; in hisi_sas_slot_index_alloc()
225 hisi_hba->last_slot_index = index; in hisi_sas_slot_index_alloc()
226 spin_unlock(&hisi_hba->lock); in hisi_sas_slot_index_alloc()
234 int device_id = slot->device_id; in hisi_sas_slot_task_free()
235 struct hisi_sas_device *sas_dev = &hisi_hba->devices[device_id]; in hisi_sas_slot_task_free()
238 struct device *dev = hisi_hba->dev; in hisi_sas_slot_task_free()
240 if (!task->lldd_task) in hisi_sas_slot_task_free()
243 task->lldd_task = NULL; in hisi_sas_slot_task_free()
245 if (!sas_protocol_ata(task->task_proto)) { in hisi_sas_slot_task_free()
246 if (slot->n_elem) { in hisi_sas_slot_task_free()
247 if (task->task_proto & SAS_PROTOCOL_SSP) in hisi_sas_slot_task_free()
248 dma_unmap_sg(dev, task->scatter, in hisi_sas_slot_task_free()
249 task->num_scatter, in hisi_sas_slot_task_free()
250 task->data_dir); in hisi_sas_slot_task_free()
252 dma_unmap_sg(dev, &task->smp_task.smp_req, in hisi_sas_slot_task_free()
255 if (slot->n_elem_dif) { in hisi_sas_slot_task_free()
256 struct sas_ssp_task *ssp_task = &task->ssp_task; in hisi_sas_slot_task_free()
257 struct scsi_cmnd *scsi_cmnd = ssp_task->cmd; in hisi_sas_slot_task_free()
261 task->data_dir); in hisi_sas_slot_task_free()
267 spin_lock(&sas_dev->lock); in hisi_sas_slot_task_free()
268 list_del_init(&slot->entry); in hisi_sas_slot_task_free()
269 spin_unlock(&sas_dev->lock); in hisi_sas_slot_task_free()
271 list_del_init(&slot->entry); in hisi_sas_slot_task_free()
276 hisi_sas_slot_index_free(hisi_hba, slot->idx); in hisi_sas_slot_task_free()
283 hisi_hba->hw->prep_smp(hisi_hba, slot); in hisi_sas_task_prep_smp()
289 hisi_hba->hw->prep_ssp(hisi_hba, slot); in hisi_sas_task_prep_ssp()
295 hisi_hba->hw->prep_stp(hisi_hba, slot); in hisi_sas_task_prep_ata()
301 hisi_hba->hw->prep_abort(hisi_hba, slot); in hisi_sas_task_prep_abort()
307 struct device *dev = hisi_hba->dev; in hisi_sas_dma_unmap()
309 if (!sas_protocol_ata(task->task_proto) && n_elem) { in hisi_sas_dma_unmap()
310 if (task->num_scatter) { in hisi_sas_dma_unmap()
311 dma_unmap_sg(dev, task->scatter, task->num_scatter, in hisi_sas_dma_unmap()
312 task->data_dir); in hisi_sas_dma_unmap()
313 } else if (task->task_proto & SAS_PROTOCOL_SMP) { in hisi_sas_dma_unmap()
314 dma_unmap_sg(dev, &task->smp_task.smp_req, in hisi_sas_dma_unmap()
323 struct device *dev = hisi_hba->dev; in hisi_sas_dma_map()
326 if (sas_protocol_ata(task->task_proto)) { in hisi_sas_dma_map()
327 *n_elem = task->num_scatter; in hisi_sas_dma_map()
331 if (task->num_scatter) { in hisi_sas_dma_map()
332 *n_elem = dma_map_sg(dev, task->scatter, in hisi_sas_dma_map()
333 task->num_scatter, task->data_dir); in hisi_sas_dma_map()
335 rc = -ENOMEM; in hisi_sas_dma_map()
338 } else if (task->task_proto & SAS_PROTOCOL_SMP) { in hisi_sas_dma_map()
339 *n_elem = dma_map_sg(dev, &task->smp_task.smp_req, in hisi_sas_dma_map()
342 rc = -ENOMEM; in hisi_sas_dma_map()
345 req_len = sg_dma_len(&task->smp_task.smp_req); in hisi_sas_dma_map()
347 rc = -EINVAL; in hisi_sas_dma_map()
356 rc = -EINVAL; in hisi_sas_dma_map()
371 struct device *dev = hisi_hba->dev; in hisi_sas_dif_dma_unmap()
374 struct sas_ssp_task *ssp_task = &task->ssp_task; in hisi_sas_dif_dma_unmap()
375 struct scsi_cmnd *scsi_cmnd = ssp_task->cmd; in hisi_sas_dif_dma_unmap()
379 task->data_dir); in hisi_sas_dif_dma_unmap()
386 struct device *dev = hisi_hba->dev; in hisi_sas_dif_dma_map()
391 if (task->num_scatter) { in hisi_sas_dif_dma_map()
392 ssp_task = &task->ssp_task; in hisi_sas_dif_dma_map()
393 scsi_cmnd = ssp_task->cmd; in hisi_sas_dif_dma_map()
399 task->data_dir); in hisi_sas_dif_dma_map()
402 return -ENOMEM; in hisi_sas_dif_dma_map()
407 rc = -EINVAL; in hisi_sas_dif_dma_map()
417 scsi_prot_sg_count(scsi_cmnd), task->data_dir); in hisi_sas_dif_dma_map()
429 struct sas_task *task = slot->task; in hisi_sas_task_deliver()
432 spin_lock(&dq->lock); in hisi_sas_task_deliver()
433 wr_q_index = dq->wr_point; in hisi_sas_task_deliver()
434 dq->wr_point = (dq->wr_point + 1) % HISI_SAS_QUEUE_SLOTS; in hisi_sas_task_deliver()
435 list_add_tail(&slot->delivery, &dq->list); in hisi_sas_task_deliver()
436 spin_unlock(&dq->lock); in hisi_sas_task_deliver()
437 spin_lock(&sas_dev->lock); in hisi_sas_task_deliver()
438 list_add_tail(&slot->entry, &sas_dev->list); in hisi_sas_task_deliver()
439 spin_unlock(&sas_dev->lock); in hisi_sas_task_deliver()
441 dlvry_queue = dq->id; in hisi_sas_task_deliver()
444 slot->device_id = sas_dev->device_id; in hisi_sas_task_deliver()
445 slot->dlvry_queue = dlvry_queue; in hisi_sas_task_deliver()
446 slot->dlvry_queue_slot = dlvry_queue_slot; in hisi_sas_task_deliver()
447 cmd_hdr_base = hisi_hba->cmd_hdr[dlvry_queue]; in hisi_sas_task_deliver()
448 slot->cmd_hdr = &cmd_hdr_base[dlvry_queue_slot]; in hisi_sas_task_deliver()
450 task->lldd_task = slot; in hisi_sas_task_deliver()
452 memset(slot->cmd_hdr, 0, sizeof(struct hisi_sas_cmd_hdr)); in hisi_sas_task_deliver()
457 switch (task->task_proto) { in hisi_sas_task_deliver()
478 WRITE_ONCE(slot->ready, 1); in hisi_sas_task_deliver()
480 spin_lock(&dq->lock); in hisi_sas_task_deliver()
481 hisi_hba->hw->start_delivery(dq); in hisi_sas_task_deliver()
482 spin_unlock(&dq->lock); in hisi_sas_task_deliver()
488 struct domain_device *device = task->dev; in hisi_sas_queue_command() local
489 struct asd_sas_port *sas_port = device->port; in hisi_sas_queue_command()
490 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_queue_command()
497 struct device *dev; in hisi_sas_queue_command()
501 struct task_status_struct *ts = &task->task_status; in hisi_sas_queue_command()
503 ts->resp = SAS_TASK_UNDELIVERED; in hisi_sas_queue_command()
504 ts->stat = SAS_PHY_DOWN; in hisi_sas_queue_command()
506 * libsas will use dev->port, should in hisi_sas_queue_command()
509 if (device->dev_type != SAS_SATA_DEV && !internal_abort) in hisi_sas_queue_command()
510 task->task_done(task); in hisi_sas_queue_command()
511 return -ECOMM; in hisi_sas_queue_command()
514 hisi_hba = dev_to_hisi_hba(device); in hisi_sas_queue_command()
515 dev = hisi_hba->dev; in hisi_sas_queue_command()
517 switch (task->task_proto) { in hisi_sas_queue_command()
523 if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags))) { in hisi_sas_queue_command()
525 return -EINVAL; in hisi_sas_queue_command()
527 down(&hisi_hba->sem); in hisi_sas_queue_command()
528 up(&hisi_hba->sem); in hisi_sas_queue_command()
533 dev_info(dev, "task prep: device %d not ready\n", in hisi_sas_queue_command()
534 sas_dev->device_id); in hisi_sas_queue_command()
536 dev_info(dev, "task prep: device %016llx not ready\n", in hisi_sas_queue_command()
537 SAS_ADDR(device->sas_addr)); in hisi_sas_queue_command()
539 return -ECOMM; in hisi_sas_queue_command()
543 if (!port->port_attached) { in hisi_sas_queue_command()
544 dev_info(dev, "task prep: %s port%d not attach device\n", in hisi_sas_queue_command()
545 dev_is_sata(device) ? "SATA/STP" : "SAS", in hisi_sas_queue_command()
546 device->port->id); in hisi_sas_queue_command()
548 return -ECOMM; in hisi_sas_queue_command()
558 dq = &hisi_hba->dq[dq_index]; in hisi_sas_queue_command()
562 if (hisi_hba->iopoll_q_cnt) { in hisi_sas_queue_command()
570 struct Scsi_Host *shost = hisi_hba->shost; in hisi_sas_queue_command()
571 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT]; in hisi_sas_queue_command()
573 queue = qmap->mq_map[raw_smp_processor_id()]; in hisi_sas_queue_command()
575 dq = &hisi_hba->dq[queue]; in hisi_sas_queue_command()
579 if (!hisi_hba->hw->prep_abort) in hisi_sas_queue_command()
582 if (test_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags)) in hisi_sas_queue_command()
583 return -EIO; in hisi_sas_queue_command()
585 hisi_hba = dev_to_hisi_hba(device); in hisi_sas_queue_command()
587 if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags))) in hisi_sas_queue_command()
588 return -EINVAL; in hisi_sas_queue_command()
591 dq = &hisi_hba->dq[task->abort_task.qid]; in hisi_sas_queue_command()
594 dev_err(hisi_hba->dev, "task prep: unknown/unsupported proto (0x%x)\n", in hisi_sas_queue_command()
595 task->task_proto); in hisi_sas_queue_command()
596 return -EINVAL; in hisi_sas_queue_command()
603 if (!sas_protocol_ata(task->task_proto)) { in hisi_sas_queue_command()
609 if (!internal_abort && hisi_hba->hw->slot_index_alloc) in hisi_sas_queue_command()
610 rc = hisi_hba->hw->slot_index_alloc(hisi_hba, device); in hisi_sas_queue_command()
617 slot = &hisi_hba->slot_info[rc]; in hisi_sas_queue_command()
618 slot->n_elem = n_elem; in hisi_sas_queue_command()
619 slot->n_elem_dif = n_elem_dif; in hisi_sas_queue_command()
620 slot->task = task; in hisi_sas_queue_command()
621 slot->port = port; in hisi_sas_queue_command()
623 slot->tmf = task->tmf; in hisi_sas_queue_command()
624 slot->is_internal = !!task->tmf || internal_abort; in hisi_sas_queue_command()
632 if (!sas_protocol_ata(task->task_proto)) in hisi_sas_queue_command()
644 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_bytes_dmaed() local
645 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_bytes_dmaed()
647 if (!phy->phy_attached) in hisi_sas_bytes_dmaed()
652 if (sas_phy->phy) { in hisi_sas_bytes_dmaed()
653 struct sas_phy *sphy = sas_phy->phy; in hisi_sas_bytes_dmaed()
655 sphy->negotiated_linkrate = sas_phy->linkrate; in hisi_sas_bytes_dmaed()
656 sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; in hisi_sas_bytes_dmaed()
657 sphy->maximum_linkrate_hw = in hisi_sas_bytes_dmaed()
658 hisi_hba->hw->phy_get_max_linkrate(); in hisi_sas_bytes_dmaed()
659 if (sphy->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) in hisi_sas_bytes_dmaed()
660 sphy->minimum_linkrate = phy->minimum_linkrate; in hisi_sas_bytes_dmaed()
662 if (sphy->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) in hisi_sas_bytes_dmaed()
663 sphy->maximum_linkrate = phy->maximum_linkrate; in hisi_sas_bytes_dmaed()
666 if (phy->phy_type & PORT_TYPE_SAS) { in hisi_sas_bytes_dmaed()
669 id = (struct sas_identify_frame *)phy->frame_rcvd; in hisi_sas_bytes_dmaed()
670 id->dev_type = phy->identify.device_type; in hisi_sas_bytes_dmaed()
671 id->initiator_bits = SAS_PROTOCOL_ALL; in hisi_sas_bytes_dmaed()
672 id->target_bits = phy->identify.target_port_protocols; in hisi_sas_bytes_dmaed()
673 } else if (phy->phy_type & PORT_TYPE_SATA) { in hisi_sas_bytes_dmaed()
677 sas_phy->frame_rcvd_size = phy->frame_rcvd_size; in hisi_sas_bytes_dmaed()
681 static struct hisi_sas_device *hisi_sas_alloc_dev(struct domain_device *device) in hisi_sas_alloc_dev() argument
683 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_alloc_dev()
685 int last = hisi_hba->last_dev_id; in hisi_sas_alloc_dev()
686 int first = (hisi_hba->last_dev_id + 1) % HISI_SAS_MAX_DEVICES; in hisi_sas_alloc_dev()
689 spin_lock(&hisi_hba->lock); in hisi_sas_alloc_dev()
691 if (hisi_hba->devices[i].dev_type == SAS_PHY_UNUSED) { in hisi_sas_alloc_dev()
692 int queue = i % hisi_hba->queue_count; in hisi_sas_alloc_dev()
693 struct hisi_sas_dq *dq = &hisi_hba->dq[queue]; in hisi_sas_alloc_dev()
695 hisi_hba->devices[i].device_id = i; in hisi_sas_alloc_dev()
696 sas_dev = &hisi_hba->devices[i]; in hisi_sas_alloc_dev()
697 sas_dev->dev_status = HISI_SAS_DEV_INIT; in hisi_sas_alloc_dev()
698 sas_dev->dev_type = device->dev_type; in hisi_sas_alloc_dev()
699 sas_dev->hisi_hba = hisi_hba; in hisi_sas_alloc_dev()
700 sas_dev->sas_device = device; in hisi_sas_alloc_dev()
701 sas_dev->dq = dq; in hisi_sas_alloc_dev()
702 spin_lock_init(&sas_dev->lock); in hisi_sas_alloc_dev()
703 INIT_LIST_HEAD(&hisi_hba->devices[i].list); in hisi_sas_alloc_dev()
708 hisi_hba->last_dev_id = i; in hisi_sas_alloc_dev()
709 spin_unlock(&hisi_hba->lock); in hisi_sas_alloc_dev()
717 spin_lock(&cq->poll_lock); in hisi_sas_sync_poll_cq()
718 spin_unlock(&cq->poll_lock); in hisi_sas_sync_poll_cq()
723 struct hisi_hba *hisi_hba = cq->hisi_hba; in hisi_sas_queue_is_poll()
725 if (cq->id < hisi_hba->queue_count - hisi_hba->iopoll_q_cnt) in hisi_sas_queue_is_poll()
735 synchronize_irq(cq->irq_no); in hisi_sas_sync_cq()
742 for (i = 0; i < hisi_hba->queue_count; i++) { in hisi_sas_sync_poll_cqs()
743 struct hisi_sas_cq *cq = &hisi_hba->cq[i]; in hisi_sas_sync_poll_cqs()
755 for (i = 0; i < hisi_hba->queue_count; i++) { in hisi_sas_sync_cqs()
756 struct hisi_sas_cq *cq = &hisi_hba->cq[i]; in hisi_sas_sync_cqs()
765 struct hisi_sas_slot *slot = task->lldd_task; in hisi_sas_tmf_aborted()
766 struct domain_device *device = task->dev; in hisi_sas_tmf_aborted() local
767 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_tmf_aborted()
768 struct hisi_hba *hisi_hba = sas_dev->hisi_hba; in hisi_sas_tmf_aborted()
772 &hisi_hba->cq[slot->dlvry_queue]; in hisi_sas_tmf_aborted()
778 slot->task = NULL; in hisi_sas_tmf_aborted()
783 static int hisi_sas_init_device(struct domain_device *device) in hisi_sas_init_device() argument
788 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_init_device()
790 switch (device->dev_type) { in hisi_sas_init_device()
794 while (retry-- > 0) { in hisi_sas_init_device()
795 rc = sas_abort_task_set(device, lun.scsi_lun); in hisi_sas_init_device()
797 hisi_sas_release_task(hisi_hba, device); in hisi_sas_init_device()
813 * a. When probing the device, libsas/libata already issues a in hisi_sas_init_device()
814 * hard reset in sas_probe_sata() -> ata_port_probe(). in hisi_sas_init_device()
819 while (retry-- > 0) { in hisi_sas_init_device()
820 rc = hisi_sas_softreset_ata_disk(device); in hisi_sas_init_device()
835 struct hisi_sas_device *sas_dev = ddev->lldd_dev; in hisi_sas_sdev_init()
845 sas_dev->dev_status = HISI_SAS_DEV_NORMAL; in hisi_sas_sdev_init()
850 static int hisi_sas_dev_found(struct domain_device *device) in hisi_sas_dev_found() argument
852 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_dev_found()
853 struct domain_device *parent_dev = device->parent; in hisi_sas_dev_found()
855 struct device *dev = hisi_hba->dev; in hisi_sas_dev_found()
858 if (hisi_hba->hw->alloc_dev) in hisi_sas_dev_found()
859 sas_dev = hisi_hba->hw->alloc_dev(device); in hisi_sas_dev_found()
861 sas_dev = hisi_sas_alloc_dev(device); in hisi_sas_dev_found()
865 return -EINVAL; in hisi_sas_dev_found()
868 device->lldd_dev = sas_dev; in hisi_sas_dev_found()
869 hisi_hba->hw->setup_itct(hisi_hba, sas_dev); in hisi_sas_dev_found()
871 if (parent_dev && dev_is_expander(parent_dev->dev_type)) { in hisi_sas_dev_found()
874 phy_no = sas_find_attached_phy_id(&parent_dev->ex_dev, device); in hisi_sas_dev_found()
878 SAS_ADDR(device->sas_addr), in hisi_sas_dev_found()
879 SAS_ADDR(parent_dev->sas_addr)); in hisi_sas_dev_found()
886 sas_dev->device_id, sas_dev->dev_type); in hisi_sas_dev_found()
891 hisi_sas_dev_gone(device); in hisi_sas_dev_found()
913 hisi_hba->hw->phys_init(hisi_hba); in hisi_sas_scan_start()
920 struct sas_ha_struct *sha = &hisi_hba->sha; in hisi_sas_scan_finished()
922 /* Wait for PHY up interrupt to occur */ in hisi_sas_scan_finished()
934 struct hisi_sas_phy *phy = in hisi_sas_phyup_work_common() local
935 container_of(work, typeof(*phy), works[event]); in hisi_sas_phyup_work_common()
936 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_phyup_work_common()
937 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phyup_work_common()
938 struct asd_sas_port *sas_port = sas_phy->port; in hisi_sas_phyup_work_common()
939 struct hisi_sas_port *port = phy->port; in hisi_sas_phyup_work_common()
940 struct device *dev = hisi_hba->dev; in hisi_sas_phyup_work_common()
942 int phy_no = sas_phy->id; in hisi_sas_phyup_work_common()
944 if (!test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags) && in hisi_sas_phyup_work_common()
945 sas_port && port && (port->id != phy->port_id)) { in hisi_sas_phyup_work_common()
946 dev_info(dev, "phy%d's hw port id changed from %d to %llu\n", in hisi_sas_phyup_work_common()
947 phy_no, port->id, phy->port_id); in hisi_sas_phyup_work_common()
948 port_dev = sas_port->port_dev; in hisi_sas_phyup_work_common()
949 if (port_dev && !dev_is_expander(port_dev->dev_type)) { in hisi_sas_phyup_work_common()
951 * Set the device state to gone to block in hisi_sas_phyup_work_common()
952 * sending IO to the device. in hisi_sas_phyup_work_common()
954 set_bit(SAS_DEV_GONE, &port_dev->state); in hisi_sas_phyup_work_common()
955 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET); in hisi_sas_phyup_work_common()
960 phy->wait_phyup_cnt = 0; in hisi_sas_phyup_work_common()
961 if (phy->identify.target_port_protocols == SAS_PROTOCOL_SSP) in hisi_sas_phyup_work_common()
962 hisi_hba->hw->sl_notify_ssp(hisi_hba, phy_no); in hisi_sas_phyup_work_common()
973 struct hisi_sas_phy *phy = in hisi_sas_linkreset_work() local
974 container_of(work, typeof(*phy), works[HISI_PHYE_LINK_RESET]); in hisi_sas_linkreset_work()
975 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_linkreset_work()
982 struct hisi_sas_phy *phy = in hisi_sas_phyup_pm_work() local
983 container_of(work, typeof(*phy), works[HISI_PHYE_PHY_UP_PM]); in hisi_sas_phyup_pm_work()
984 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_phyup_pm_work()
985 struct device *dev = hisi_hba->dev; in hisi_sas_phyup_pm_work()
997 bool hisi_sas_notify_phy_event(struct hisi_sas_phy *phy, in hisi_sas_notify_phy_event() argument
1000 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_notify_phy_event()
1005 return queue_work(hisi_hba->wq, &phy->works[event]); in hisi_sas_notify_phy_event()
1011 struct hisi_sas_phy *phy = from_timer(phy, t, timer); in hisi_sas_wait_phyup_timedout() local
1012 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_wait_phyup_timedout()
1013 struct device *dev = hisi_hba->dev; in hisi_sas_wait_phyup_timedout()
1014 int phy_no = phy->sas_phy.id; in hisi_sas_wait_phyup_timedout()
1016 dev_warn(dev, "phy%d wait phyup timeout, issuing link reset\n", phy_no); in hisi_sas_wait_phyup_timedout()
1017 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET); in hisi_sas_wait_phyup_timedout()
1024 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_oob_ready() local
1025 struct device *dev = hisi_hba->dev; in hisi_sas_phy_oob_ready()
1028 dev_dbg(dev, "phy%d OOB ready\n", phy_no); in hisi_sas_phy_oob_ready()
1029 spin_lock_irqsave(&phy->lock, flags); in hisi_sas_phy_oob_ready()
1030 if (phy->phy_attached) { in hisi_sas_phy_oob_ready()
1031 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_phy_oob_ready()
1035 if (!timer_pending(&phy->timer)) { in hisi_sas_phy_oob_ready()
1036 if (phy->wait_phyup_cnt < HISI_SAS_WAIT_PHYUP_RETRIES) { in hisi_sas_phy_oob_ready()
1037 phy->wait_phyup_cnt++; in hisi_sas_phy_oob_ready()
1038 phy->timer.expires = jiffies + in hisi_sas_phy_oob_ready()
1040 add_timer(&phy->timer); in hisi_sas_phy_oob_ready()
1041 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_phy_oob_ready()
1045 dev_warn(dev, "phy%d failed to come up %d times, giving up\n", in hisi_sas_phy_oob_ready()
1046 phy_no, phy->wait_phyup_cnt); in hisi_sas_phy_oob_ready()
1047 phy->wait_phyup_cnt = 0; in hisi_sas_phy_oob_ready()
1049 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_phy_oob_ready()
1056 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_init() local
1057 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phy_init()
1060 phy->hisi_hba = hisi_hba; in hisi_sas_phy_init()
1061 phy->port = NULL; in hisi_sas_phy_init()
1062 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS; in hisi_sas_phy_init()
1063 phy->maximum_linkrate = hisi_hba->hw->phy_get_max_linkrate(); in hisi_sas_phy_init()
1064 sas_phy->enabled = (phy_no < hisi_hba->n_phy) ? 1 : 0; in hisi_sas_phy_init()
1065 sas_phy->iproto = SAS_PROTOCOL_ALL; in hisi_sas_phy_init()
1066 sas_phy->tproto = 0; in hisi_sas_phy_init()
1067 sas_phy->role = PHY_ROLE_INITIATOR; in hisi_sas_phy_init()
1068 sas_phy->oob_mode = OOB_NOT_CONNECTED; in hisi_sas_phy_init()
1069 sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN; in hisi_sas_phy_init()
1070 sas_phy->id = phy_no; in hisi_sas_phy_init()
1071 sas_phy->sas_addr = &hisi_hba->sas_addr[0]; in hisi_sas_phy_init()
1072 sas_phy->frame_rcvd = &phy->frame_rcvd[0]; in hisi_sas_phy_init()
1073 sas_phy->ha = (struct sas_ha_struct *)hisi_hba->shost->hostdata; in hisi_sas_phy_init()
1074 sas_phy->lldd_phy = phy; in hisi_sas_phy_init()
1077 INIT_WORK(&phy->works[i], hisi_sas_phye_fns[i]); in hisi_sas_phy_init()
1079 spin_lock_init(&phy->lock); in hisi_sas_phy_init()
1081 timer_setup(&phy->timer, hisi_sas_wait_phyup_timedout, 0); in hisi_sas_phy_init()
1087 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_enable() local
1088 struct asd_sas_phy *aphy = &phy->sas_phy; in hisi_sas_phy_enable()
1089 struct sas_phy *sphy = aphy->phy; in hisi_sas_phy_enable()
1092 spin_lock_irqsave(&phy->lock, flags); in hisi_sas_phy_enable()
1096 if (!phy->enable) in hisi_sas_phy_enable()
1097 sphy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN; in hisi_sas_phy_enable()
1098 hisi_hba->hw->phy_start(hisi_hba, phy_no); in hisi_sas_phy_enable()
1100 sphy->negotiated_linkrate = SAS_PHY_DISABLED; in hisi_sas_phy_enable()
1101 hisi_hba->hw->phy_disable(hisi_hba, phy_no); in hisi_sas_phy_enable()
1103 phy->enable = enable; in hisi_sas_phy_enable()
1104 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_phy_enable()
1110 struct hisi_sas_phy *phy = sas_phy->lldd_phy; in hisi_sas_port_notify_formed() local
1111 struct asd_sas_port *sas_port = sas_phy->port; in hisi_sas_port_notify_formed()
1118 port->port_attached = 1; in hisi_sas_port_notify_formed()
1119 port->id = phy->port_id; in hisi_sas_port_notify_formed()
1120 phy->port = port; in hisi_sas_port_notify_formed()
1121 sas_port->lldd_port = port; in hisi_sas_port_notify_formed()
1131 ts = &task->task_status; in hisi_sas_do_release_task()
1133 ts->resp = SAS_TASK_COMPLETE; in hisi_sas_do_release_task()
1134 ts->stat = SAS_ABORTED_TASK; in hisi_sas_do_release_task()
1135 spin_lock_irqsave(&task->task_state_lock, flags); in hisi_sas_do_release_task()
1136 task->task_state_flags &= ~SAS_TASK_STATE_PENDING; in hisi_sas_do_release_task()
1137 if (!slot->is_internal && task->task_proto != SAS_PROTOCOL_SMP) in hisi_sas_do_release_task()
1138 task->task_state_flags |= SAS_TASK_STATE_DONE; in hisi_sas_do_release_task()
1139 spin_unlock_irqrestore(&task->task_state_lock, flags); in hisi_sas_do_release_task()
1146 struct domain_device *device) in hisi_sas_release_task() argument
1149 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_release_task()
1151 spin_lock(&sas_dev->lock); in hisi_sas_release_task()
1152 list_for_each_entry_safe(slot, slot2, &sas_dev->list, entry) in hisi_sas_release_task()
1153 hisi_sas_do_release_task(hisi_hba, slot->task, slot, false); in hisi_sas_release_task()
1155 spin_unlock(&sas_dev->lock); in hisi_sas_release_task()
1161 struct domain_device *device; in hisi_sas_release_tasks() local
1165 sas_dev = &hisi_hba->devices[i]; in hisi_sas_release_tasks()
1166 device = sas_dev->sas_device; in hisi_sas_release_tasks()
1168 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || in hisi_sas_release_tasks()
1169 !device) in hisi_sas_release_tasks()
1172 hisi_sas_release_task(hisi_hba, device); in hisi_sas_release_tasks()
1178 struct domain_device *device) in hisi_sas_dereg_device() argument
1180 if (hisi_hba->hw->dereg_device) in hisi_sas_dereg_device()
1181 hisi_hba->hw->dereg_device(hisi_hba, device); in hisi_sas_dereg_device()
1189 struct domain_device *device = sas_dev->sas_device; in hisi_sas_internal_task_abort_dev() local
1190 struct hisi_hba *hisi_hba = sas_dev->hisi_hba; in hisi_sas_internal_task_abort_dev()
1193 for (i = 0; i < hisi_hba->cq_nvecs; i++) { in hisi_sas_internal_task_abort_dev()
1194 struct hisi_sas_cq *cq = &hisi_hba->cq[i]; in hisi_sas_internal_task_abort_dev()
1195 const struct cpumask *mask = cq->irq_mask; in hisi_sas_internal_task_abort_dev()
1199 rc = sas_execute_internal_abort_dev(device, i, &data); in hisi_sas_internal_task_abort_dev()
1207 static void hisi_sas_dev_gone(struct domain_device *device) in hisi_sas_dev_gone() argument
1209 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_dev_gone()
1210 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_dev_gone()
1211 struct device *dev = hisi_hba->dev; in hisi_sas_dev_gone()
1215 sas_dev->device_id, sas_dev->dev_type); in hisi_sas_dev_gone()
1217 down(&hisi_hba->sem); in hisi_sas_dev_gone()
1218 if (!test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags)) { in hisi_sas_dev_gone()
1221 hisi_sas_dereg_device(hisi_hba, device); in hisi_sas_dev_gone()
1223 ret = hisi_hba->hw->clear_itct(hisi_hba, sas_dev); in hisi_sas_dev_gone()
1224 device->lldd_dev = NULL; in hisi_sas_dev_gone()
1227 if (hisi_hba->hw->free_device) in hisi_sas_dev_gone()
1228 hisi_hba->hw->free_device(sas_dev); in hisi_sas_dev_gone()
1232 sas_dev->dev_type = SAS_PHY_UNUSED; in hisi_sas_dev_gone()
1233 sas_dev->sas_device = NULL; in hisi_sas_dev_gone()
1234 up(&hisi_hba->sem); in hisi_sas_dev_gone()
1242 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_set_linkrate() local
1243 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phy_set_linkrate()
1246 if (r->minimum_linkrate > SAS_LINK_RATE_1_5_GBPS) in hisi_sas_phy_set_linkrate()
1247 return -EINVAL; in hisi_sas_phy_set_linkrate()
1249 if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) { in hisi_sas_phy_set_linkrate()
1250 max = sas_phy->phy->maximum_linkrate; in hisi_sas_phy_set_linkrate()
1251 min = r->minimum_linkrate; in hisi_sas_phy_set_linkrate()
1252 } else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) { in hisi_sas_phy_set_linkrate()
1253 max = r->maximum_linkrate; in hisi_sas_phy_set_linkrate()
1254 min = sas_phy->phy->minimum_linkrate; in hisi_sas_phy_set_linkrate()
1256 return -EINVAL; in hisi_sas_phy_set_linkrate()
1261 sas_phy->phy->maximum_linkrate = max; in hisi_sas_phy_set_linkrate()
1262 sas_phy->phy->minimum_linkrate = min; in hisi_sas_phy_set_linkrate()
1266 hisi_hba->hw->phy_set_linkrate(hisi_hba, phy_no, &_r); in hisi_sas_phy_set_linkrate()
1275 struct hisi_sas_phy *phy = container_of(sas_phy, in hisi_sas_control_phy() local
1277 struct sas_ha_struct *sas_ha = sas_phy->ha; in hisi_sas_control_phy()
1278 struct hisi_hba *hisi_hba = sas_ha->lldd_ha; in hisi_sas_control_phy()
1279 struct device *dev = hisi_hba->dev; in hisi_sas_control_phy()
1281 int phy_no = sas_phy->id; in hisi_sas_control_phy()
1282 u8 sts = phy->phy_attached; in hisi_sas_control_phy()
1285 down(&hisi_hba->sem); in hisi_sas_control_phy()
1286 phy->reset_completion = &completion; in hisi_sas_control_phy()
1290 hisi_hba->hw->phy_hard_reset(hisi_hba, phy_no); in hisi_sas_control_phy()
1308 if (hisi_hba->hw->get_events) { in hisi_sas_control_phy()
1309 hisi_hba->hw->get_events(hisi_hba, phy_no); in hisi_sas_control_phy()
1315 ret = -EOPNOTSUPP; in hisi_sas_control_phy()
1321 dev_warn(dev, "phy%d wait phyup timed out for func %d\n", in hisi_sas_control_phy()
1323 if (phy->in_reset) in hisi_sas_control_phy()
1324 ret = -ETIMEDOUT; in hisi_sas_control_phy()
1328 phy->reset_completion = NULL; in hisi_sas_control_phy()
1330 up(&hisi_hba->sem); in hisi_sas_control_phy()
1348 static int hisi_sas_softreset_ata_disk(struct domain_device *device) in hisi_sas_softreset_ata_disk() argument
1351 struct ata_port *ap = device->sata_dev.ap; in hisi_sas_softreset_ata_disk()
1354 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_softreset_ata_disk()
1355 struct device *dev = hisi_hba->dev; in hisi_sas_softreset_ata_disk()
1360 hisi_sas_fill_ata_reset_cmd(link->device, 1, pmp, fis); in hisi_sas_softreset_ata_disk()
1361 rc = sas_execute_ata_cmd(device, fis, -1); in hisi_sas_softreset_ata_disk()
1371 hisi_sas_fill_ata_reset_cmd(link->device, 0, pmp, fis); in hisi_sas_softreset_ata_disk()
1372 rc = sas_execute_ata_cmd(device, fis, -1); in hisi_sas_softreset_ata_disk()
1374 dev_err(dev, "ata disk %016llx de-reset failed\n", in hisi_sas_softreset_ata_disk()
1375 SAS_ADDR(device->sas_addr)); in hisi_sas_softreset_ata_disk()
1379 SAS_ADDR(device->sas_addr)); in hisi_sas_softreset_ata_disk()
1383 hisi_sas_release_task(hisi_hba, device); in hisi_sas_softreset_ata_disk()
1390 u32 state = hisi_hba->hw->get_phys_state(hisi_hba); in hisi_sas_refresh_port_id()
1394 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i]; in hisi_sas_refresh_port_id()
1395 struct domain_device *device = sas_dev->sas_device; in hisi_sas_refresh_port_id() local
1398 struct hisi_sas_phy *phy = NULL; in hisi_sas_refresh_port_id() local
1401 if ((sas_dev->dev_type == SAS_PHY_UNUSED) in hisi_sas_refresh_port_id()
1402 || !device || !device->port) in hisi_sas_refresh_port_id()
1405 sas_port = device->port; in hisi_sas_refresh_port_id()
1408 spin_lock(&sas_port->phy_list_lock); in hisi_sas_refresh_port_id()
1409 list_for_each_entry(sas_phy, &sas_port->phy_list, port_phy_el) in hisi_sas_refresh_port_id()
1410 if (state & BIT(sas_phy->id)) { in hisi_sas_refresh_port_id()
1411 phy = sas_phy->lldd_phy; in hisi_sas_refresh_port_id()
1414 spin_unlock(&sas_port->phy_list_lock); in hisi_sas_refresh_port_id()
1416 if (phy) { in hisi_sas_refresh_port_id()
1417 port->id = phy->port_id; in hisi_sas_refresh_port_id()
1419 /* Update linkrate of directly attached device. */ in hisi_sas_refresh_port_id()
1420 if (!device->parent) in hisi_sas_refresh_port_id()
1421 device->linkrate = phy->sas_phy.linkrate; in hisi_sas_refresh_port_id()
1423 hisi_hba->hw->setup_itct(hisi_hba, sas_dev); in hisi_sas_refresh_port_id()
1424 } else if (!port->port_attached) in hisi_sas_refresh_port_id()
1425 port->id = 0xff; in hisi_sas_refresh_port_id()
1431 u32 new_state = hisi_hba->hw->get_phys_state(hisi_hba); in hisi_sas_rescan_topology()
1435 for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) { in hisi_sas_rescan_topology()
1436 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_rescan_topology() local
1437 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_rescan_topology()
1438 struct asd_sas_port *sas_port = sas_phy->port; in hisi_sas_rescan_topology()
1441 if (!sas_phy->phy->enabled) in hisi_sas_rescan_topology()
1444 /* Report PHY state change to libsas */ in hisi_sas_rescan_topology()
1446 if (do_port_check && sas_port && sas_port->port_dev) { in hisi_sas_rescan_topology()
1447 struct domain_device *dev = sas_port->port_dev; in hisi_sas_rescan_topology()
1451 if (dev_is_expander(dev->dev_type)) in hisi_sas_rescan_topology()
1462 * 1. The connected device is removed in hisi_sas_rescan_topology()
1463 * 2. Device exists but phyup timed out in hisi_sas_rescan_topology()
1466 hisi_sas_notify_phy_event(phy, in hisi_sas_rescan_topology()
1475 struct domain_device *device; in hisi_sas_reset_init_all_devices() local
1479 sas_dev = &hisi_hba->devices[i]; in hisi_sas_reset_init_all_devices()
1480 device = sas_dev->sas_device; in hisi_sas_reset_init_all_devices()
1482 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device) in hisi_sas_reset_init_all_devices()
1485 hisi_sas_init_device(device); in hisi_sas_reset_init_all_devices()
1491 struct domain_device *device) in hisi_sas_send_ata_reset_each_phy() argument
1493 struct ata_port *ap = device->sata_dev.ap; in hisi_sas_send_ata_reset_each_phy()
1494 struct device *dev = hisi_hba->dev; in hisi_sas_send_ata_reset_each_phy()
1500 for (i = 0; i < hisi_hba->n_phy; i++) { in hisi_sas_send_ata_reset_each_phy()
1501 if (!(sas_port->phy_mask & BIT(i))) in hisi_sas_send_ata_reset_each_phy()
1507 hisi_sas_fill_ata_reset_cmd(link->device, 1, pmp, fis); in hisi_sas_send_ata_reset_each_phy()
1508 rc = sas_execute_ata_cmd(device, fis, i); in hisi_sas_send_ata_reset_each_phy()
1510 dev_err(dev, "phy%d ata reset failed rc=%d\n", in hisi_sas_send_ata_reset_each_phy()
1520 struct device *dev = hisi_hba->dev; in hisi_sas_terminate_stp_reject()
1524 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i]; in hisi_sas_terminate_stp_reject()
1525 struct domain_device *device = sas_dev->sas_device; in hisi_sas_terminate_stp_reject() local
1527 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device) in hisi_sas_terminate_stp_reject()
1535 for (port_no = 0; port_no < hisi_hba->n_phy; port_no++) { in hisi_sas_terminate_stp_reject()
1536 struct hisi_sas_port *port = &hisi_hba->port[port_no]; in hisi_sas_terminate_stp_reject()
1537 struct asd_sas_port *sas_port = &port->sas_port; in hisi_sas_terminate_stp_reject()
1538 struct domain_device *port_dev = sas_port->port_dev; in hisi_sas_terminate_stp_reject()
1539 struct domain_device *device; in hisi_sas_terminate_stp_reject() local
1541 if (!port_dev || !dev_is_expander(port_dev->dev_type)) in hisi_sas_terminate_stp_reject()
1544 /* Try to find a SATA device */ in hisi_sas_terminate_stp_reject()
1545 list_for_each_entry(device, &sas_port->dev_list, in hisi_sas_terminate_stp_reject()
1547 if (dev_is_sata(device)) { in hisi_sas_terminate_stp_reject()
1550 device); in hisi_sas_terminate_stp_reject()
1559 struct Scsi_Host *shost = hisi_hba->shost; in hisi_sas_controller_reset_prepare()
1561 hisi_hba->phy_state = hisi_hba->hw->get_phys_state(hisi_hba); in hisi_sas_controller_reset_prepare()
1564 hisi_hba->hw->wait_cmds_complete_timeout(hisi_hba, 100, 5000); in hisi_sas_controller_reset_prepare()
1567 * hisi_hba->timer is only used for v1/v2 hw, and check hw->sht in hisi_sas_controller_reset_prepare()
1570 if (hisi_hba->hw->sht) in hisi_sas_controller_reset_prepare()
1571 timer_delete_sync(&hisi_hba->timer); in hisi_sas_controller_reset_prepare()
1573 set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); in hisi_sas_controller_reset_prepare()
1579 struct hisi_sas_phy *phy = data; in hisi_sas_async_init_wait_phyup() local
1580 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_async_init_wait_phyup()
1581 struct device *dev = hisi_hba->dev; in hisi_sas_async_init_wait_phyup()
1583 int phy_no = phy->sas_phy.id; in hisi_sas_async_init_wait_phyup()
1585 phy->reset_completion = &completion; in hisi_sas_async_init_wait_phyup()
1589 dev_warn(dev, "phy%d wait phyup timed out\n", phy_no); in hisi_sas_async_init_wait_phyup()
1591 phy->reset_completion = NULL; in hisi_sas_async_init_wait_phyup()
1596 struct Scsi_Host *shost = hisi_hba->shost; in hisi_sas_controller_reset_done()
1601 for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) { in hisi_sas_controller_reset_done()
1602 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_controller_reset_done() local
1603 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_controller_reset_done()
1605 if (!sas_phy->phy->enabled) in hisi_sas_controller_reset_done()
1608 if (!(hisi_hba->phy_state & BIT(phy_no))) { in hisi_sas_controller_reset_done()
1614 phy, &async); in hisi_sas_controller_reset_done()
1619 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); in hisi_sas_controller_reset_done()
1621 if (hisi_hba->reject_stp_links_msk) in hisi_sas_controller_reset_done()
1625 clear_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags); in hisi_sas_controller_reset_done()
1626 up(&hisi_hba->sem); in hisi_sas_controller_reset_done()
1628 hisi_sas_rescan_topology(hisi_hba, hisi_hba->phy_state); in hisi_sas_controller_reset_done()
1634 if (!hisi_hba->hw->soft_reset) in hisi_sas_controller_prereset()
1635 return -ENOENT; in hisi_sas_controller_prereset()
1637 down(&hisi_hba->sem); in hisi_sas_controller_prereset()
1638 if (test_and_set_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags)) { in hisi_sas_controller_prereset()
1639 up(&hisi_hba->sem); in hisi_sas_controller_prereset()
1640 return -EPERM; in hisi_sas_controller_prereset()
1644 hisi_hba->hw->debugfs_snapshot_regs(hisi_hba); in hisi_sas_controller_prereset()
1651 struct device *dev = hisi_hba->dev; in hisi_sas_controller_reset()
1652 struct Scsi_Host *shost = hisi_hba->shost; in hisi_sas_controller_reset()
1658 rc = hisi_hba->hw->soft_reset(hisi_hba); in hisi_sas_controller_reset()
1661 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); in hisi_sas_controller_reset()
1662 up(&hisi_hba->sem); in hisi_sas_controller_reset()
1664 clear_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags); in hisi_sas_controller_reset()
1667 clear_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags); in hisi_sas_controller_reset()
1678 struct domain_device *device = task->dev; in hisi_sas_abort_task() local
1679 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_abort_task()
1680 struct hisi_sas_slot *slot = task->lldd_task; in hisi_sas_abort_task()
1682 struct device *dev; in hisi_sas_abort_task()
1689 hisi_hba = dev_to_hisi_hba(task->dev); in hisi_sas_abort_task()
1690 dev = hisi_hba->dev; in hisi_sas_abort_task()
1692 spin_lock_irqsave(&task->task_state_lock, flags); in hisi_sas_abort_task()
1693 if (task->task_state_flags & SAS_TASK_STATE_DONE) { in hisi_sas_abort_task()
1701 cq = &hisi_hba->cq[slot->dlvry_queue]; in hisi_sas_abort_task()
1704 spin_unlock_irqrestore(&task->task_state_lock, flags); in hisi_sas_abort_task()
1708 task->task_state_flags |= SAS_TASK_STATE_ABORTED; in hisi_sas_abort_task()
1709 spin_unlock_irqrestore(&task->task_state_lock, flags); in hisi_sas_abort_task()
1714 if (task->task_proto & SAS_PROTOCOL_SSP) { in hisi_sas_abort_task()
1715 u16 tag = slot->idx; in hisi_sas_abort_task()
1719 rc2 = sas_execute_internal_abort_single(device, tag, in hisi_sas_abort_task()
1720 slot->dlvry_queue, &internal_abort_data); in hisi_sas_abort_task()
1727 * If the TMF finds that the IO is not in the device and also in hisi_sas_abort_task()
1734 if (task->lldd_task) in hisi_sas_abort_task()
1737 } else if (task->task_proto & SAS_PROTOCOL_SATA || in hisi_sas_abort_task()
1738 task->task_proto & SAS_PROTOCOL_STP) { in hisi_sas_abort_task()
1739 if (task->dev->dev_type == SAS_SATA_DEV) { in hisi_sas_abort_task()
1740 struct ata_queued_cmd *qc = task->uldd_task; in hisi_sas_abort_task()
1747 hisi_sas_dereg_device(hisi_hba, device); in hisi_sas_abort_task()
1753 if ((sas_dev->dev_status == HISI_SAS_DEV_NCQ_ERR) && in hisi_sas_abort_task()
1754 qc && qc->scsicmd) { in hisi_sas_abort_task()
1758 rc = hisi_sas_softreset_ata_disk(device); in hisi_sas_abort_task()
1761 } else if (task->task_proto & SAS_PROTOCOL_SMP) { in hisi_sas_abort_task()
1763 u32 tag = slot->idx; in hisi_sas_abort_task()
1764 struct hisi_sas_cq *cq = &hisi_hba->cq[slot->dlvry_queue]; in hisi_sas_abort_task()
1766 rc = sas_execute_internal_abort_single(device, in hisi_sas_abort_task()
1767 tag, slot->dlvry_queue, in hisi_sas_abort_task()
1770 task->lldd_task) { in hisi_sas_abort_task()
1776 slot->task = NULL; in hisi_sas_abort_task()
1786 static int hisi_sas_abort_task_set(struct domain_device *device, u8 *lun) in hisi_sas_abort_task_set() argument
1788 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_abort_task_set()
1789 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_abort_task_set()
1790 struct device *dev = hisi_hba->dev; in hisi_sas_abort_task_set()
1798 hisi_sas_dereg_device(hisi_hba, device); in hisi_sas_abort_task_set()
1800 rc = sas_abort_task_set(device, lun); in hisi_sas_abort_task_set()
1802 hisi_sas_release_task(hisi_hba, device); in hisi_sas_abort_task_set()
1807 static int hisi_sas_debug_I_T_nexus_reset(struct domain_device *device) in hisi_sas_debug_I_T_nexus_reset() argument
1809 struct sas_phy *local_phy = sas_get_local_phy(device); in hisi_sas_debug_I_T_nexus_reset()
1810 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_debug_I_T_nexus_reset()
1811 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_debug_I_T_nexus_reset()
1812 struct sas_ha_struct *sas_ha = &hisi_hba->sha; in hisi_sas_debug_I_T_nexus_reset()
1815 if (!local_phy->enabled) { in hisi_sas_debug_I_T_nexus_reset()
1817 return -ENODEV; in hisi_sas_debug_I_T_nexus_reset()
1822 sas_ha->sas_phy[local_phy->number]; in hisi_sas_debug_I_T_nexus_reset()
1823 struct hisi_sas_phy *phy = in hisi_sas_debug_I_T_nexus_reset() local
1827 spin_lock_irqsave(&phy->lock, flags); in hisi_sas_debug_I_T_nexus_reset()
1828 phy->in_reset = 1; in hisi_sas_debug_I_T_nexus_reset()
1829 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_debug_I_T_nexus_reset()
1832 reset_type = (sas_dev->dev_status == HISI_SAS_DEV_INIT || in hisi_sas_debug_I_T_nexus_reset()
1833 !dev_is_sata(device)) ? true : false; in hisi_sas_debug_I_T_nexus_reset()
1840 sas_ha->sas_phy[local_phy->number]; in hisi_sas_debug_I_T_nexus_reset()
1841 struct hisi_sas_phy *phy = in hisi_sas_debug_I_T_nexus_reset() local
1845 spin_lock_irqsave(&phy->lock, flags); in hisi_sas_debug_I_T_nexus_reset()
1846 phy->in_reset = 0; in hisi_sas_debug_I_T_nexus_reset()
1847 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_debug_I_T_nexus_reset()
1849 /* report PHY down if timed out */ in hisi_sas_debug_I_T_nexus_reset()
1850 if (rc == -ETIMEDOUT) in hisi_sas_debug_I_T_nexus_reset()
1851 hisi_sas_phy_down(hisi_hba, sas_phy->id, 0, GFP_KERNEL); in hisi_sas_debug_I_T_nexus_reset()
1855 /* Remote phy */ in hisi_sas_debug_I_T_nexus_reset()
1859 if (dev_is_sata(device)) { in hisi_sas_debug_I_T_nexus_reset()
1860 struct ata_link *link = &device->sata_dev.ap->link; in hisi_sas_debug_I_T_nexus_reset()
1871 static int hisi_sas_I_T_nexus_reset(struct domain_device *device) in hisi_sas_I_T_nexus_reset() argument
1873 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_I_T_nexus_reset()
1874 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_I_T_nexus_reset()
1875 struct device *dev = hisi_hba->dev; in hisi_sas_I_T_nexus_reset()
1878 if (sas_dev->dev_status == HISI_SAS_DEV_NCQ_ERR) in hisi_sas_I_T_nexus_reset()
1879 sas_dev->dev_status = HISI_SAS_DEV_NORMAL; in hisi_sas_I_T_nexus_reset()
1886 hisi_sas_dereg_device(hisi_hba, device); in hisi_sas_I_T_nexus_reset()
1888 rc = hisi_sas_debug_I_T_nexus_reset(device); in hisi_sas_I_T_nexus_reset()
1889 if (rc == TMF_RESP_FUNC_COMPLETE && dev_is_sata(device)) { in hisi_sas_I_T_nexus_reset()
1892 rc = hisi_sas_softreset_ata_disk(device); in hisi_sas_I_T_nexus_reset()
1894 case -ECOMM: in hisi_sas_I_T_nexus_reset()
1895 rc = -ENODEV; in hisi_sas_I_T_nexus_reset()
1898 case -EMSGSIZE: in hisi_sas_I_T_nexus_reset()
1899 case -EIO: in hisi_sas_I_T_nexus_reset()
1900 local_phy = sas_get_local_phy(device); in hisi_sas_I_T_nexus_reset()
1903 local_phy->enabled = 0; in hisi_sas_I_T_nexus_reset()
1904 dev_err(dev, "Disabled local phy of ATA disk %016llx due to softreset fail (%d)\n", in hisi_sas_I_T_nexus_reset()
1905 SAS_ADDR(device->sas_addr), rc); in hisi_sas_I_T_nexus_reset()
1906 rc = -ENODEV; in hisi_sas_I_T_nexus_reset()
1915 if ((rc == TMF_RESP_FUNC_COMPLETE) || (rc == -ENODEV)) in hisi_sas_I_T_nexus_reset()
1916 hisi_sas_release_task(hisi_hba, device); in hisi_sas_I_T_nexus_reset()
1921 static int hisi_sas_lu_reset(struct domain_device *device, u8 *lun) in hisi_sas_lu_reset() argument
1923 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_lu_reset()
1924 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_lu_reset()
1925 struct device *dev = hisi_hba->dev; in hisi_sas_lu_reset()
1934 hisi_sas_dereg_device(hisi_hba, device); in hisi_sas_lu_reset()
1936 if (dev_is_sata(device)) { in hisi_sas_lu_reset()
1937 struct sas_phy *phy; in hisi_sas_lu_reset() local
1939 phy = sas_get_local_phy(device); in hisi_sas_lu_reset()
1941 rc = sas_phy_reset(phy, true); in hisi_sas_lu_reset()
1944 hisi_sas_release_task(hisi_hba, device); in hisi_sas_lu_reset()
1945 sas_put_local_phy(phy); in hisi_sas_lu_reset()
1947 rc = sas_lu_reset(device, lun); in hisi_sas_lu_reset()
1949 hisi_sas_release_task(hisi_hba, device); in hisi_sas_lu_reset()
1953 dev_err(dev, "lu_reset: for device[%d]:rc= %d\n", in hisi_sas_lu_reset()
1954 sas_dev->device_id, rc); in hisi_sas_lu_reset()
1960 struct domain_device *device = data; in hisi_sas_async_I_T_nexus_reset() local
1961 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_async_I_T_nexus_reset()
1964 rc = hisi_sas_debug_I_T_nexus_reset(device); in hisi_sas_async_I_T_nexus_reset()
1966 dev_info(hisi_hba->dev, "I_T_nexus reset fail for dev:%016llx rc=%d\n", in hisi_sas_async_I_T_nexus_reset()
1967 SAS_ADDR(device->sas_addr), rc); in hisi_sas_async_I_T_nexus_reset()
1972 struct hisi_hba *hisi_hba = sas_ha->lldd_ha; in hisi_sas_clear_nexus_ha()
1977 queue_work(hisi_hba->wq, &r.work); in hisi_sas_clear_nexus_ha()
1983 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i]; in hisi_sas_clear_nexus_ha()
1984 struct domain_device *device = sas_dev->sas_device; in hisi_sas_clear_nexus_ha() local
1986 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device || in hisi_sas_clear_nexus_ha()
1987 dev_is_expander(device->dev_type)) in hisi_sas_clear_nexus_ha()
1991 device, &async); in hisi_sas_clear_nexus_ha()
2004 if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) { in hisi_sas_query_task()
2005 struct hisi_sas_slot *slot = task->lldd_task; in hisi_sas_query_task()
2006 u32 tag = slot->idx; in hisi_sas_query_task()
2012 /* The task is not in Lun or failed, reset the phy */ in hisi_sas_query_task()
2027 struct domain_device *device = task->dev; in hisi_sas_internal_abort_timeout() local
2028 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_internal_abort_timeout()
2033 * If timeout occurs in device gone scenario, to avoid in hisi_sas_internal_abort_timeout()
2035 * hisi_sas_dev_gone() -> down() -> ... -> in hisi_sas_internal_abort_timeout()
2036 * hisi_sas_internal_abort_timeout() -> down(). in hisi_sas_internal_abort_timeout()
2038 if (!timeout->rst_ha_timeout) in hisi_sas_internal_abort_timeout()
2039 down(&hisi_hba->sem); in hisi_sas_internal_abort_timeout()
2040 hisi_hba->hw->debugfs_snapshot_regs(hisi_hba); in hisi_sas_internal_abort_timeout()
2041 if (!timeout->rst_ha_timeout) in hisi_sas_internal_abort_timeout()
2042 up(&hisi_hba->sem); in hisi_sas_internal_abort_timeout()
2045 if (task->task_state_flags & SAS_TASK_STATE_DONE) { in hisi_sas_internal_abort_timeout()
2047 SAS_ADDR(device->sas_addr)); in hisi_sas_internal_abort_timeout()
2049 struct hisi_sas_slot *slot = task->lldd_task; in hisi_sas_internal_abort_timeout()
2051 set_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags); in hisi_sas_internal_abort_timeout()
2055 &hisi_hba->cq[slot->dlvry_queue]; in hisi_sas_internal_abort_timeout()
2061 slot->task = NULL; in hisi_sas_internal_abort_timeout()
2064 if (timeout->rst_ha_timeout) { in hisi_sas_internal_abort_timeout()
2066 SAS_ADDR(device->sas_addr)); in hisi_sas_internal_abort_timeout()
2067 queue_work(hisi_hba->wq, &hisi_hba->rst_work); in hisi_sas_internal_abort_timeout()
2070 SAS_ADDR(device->sas_addr)); in hisi_sas_internal_abort_timeout()
2087 struct hisi_hba *hisi_hba = sha->lldd_ha; in hisi_sas_write_gpio()
2089 if (!hisi_hba->hw->write_gpio) in hisi_sas_write_gpio()
2090 return -EOPNOTSUPP; in hisi_sas_write_gpio()
2092 return hisi_hba->hw->write_gpio(hisi_hba, reg_type, in hisi_sas_write_gpio()
2096 static void hisi_sas_phy_disconnected(struct hisi_sas_phy *phy) in hisi_sas_phy_disconnected() argument
2098 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phy_disconnected()
2099 struct sas_phy *sphy = sas_phy->phy; in hisi_sas_phy_disconnected()
2102 phy->phy_attached = 0; in hisi_sas_phy_disconnected()
2103 phy->phy_type = 0; in hisi_sas_phy_disconnected()
2104 phy->port = NULL; in hisi_sas_phy_disconnected()
2106 spin_lock_irqsave(&phy->lock, flags); in hisi_sas_phy_disconnected()
2107 if (phy->enable) in hisi_sas_phy_disconnected()
2108 sphy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN; in hisi_sas_phy_disconnected()
2110 sphy->negotiated_linkrate = SAS_PHY_DISABLED; in hisi_sas_phy_disconnected()
2111 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_phy_disconnected()
2117 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_down() local
2118 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phy_down()
2119 struct device *dev = hisi_hba->dev; in hisi_sas_phy_down()
2122 /* Phy down but ready */ in hisi_sas_phy_down()
2126 struct hisi_sas_port *port = phy->port; in hisi_sas_phy_down()
2128 if (test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags) || in hisi_sas_phy_down()
2129 phy->in_reset) { in hisi_sas_phy_down()
2130 dev_info(dev, "ignore flutter phy%d down\n", phy_no); in hisi_sas_phy_down()
2133 /* Phy down and not ready */ in hisi_sas_phy_down()
2138 if (phy->phy_type & PORT_TYPE_SAS) { in hisi_sas_phy_down()
2139 int port_id = port->id; in hisi_sas_phy_down()
2141 if (!hisi_hba->hw->get_wideport_bitmap(hisi_hba, in hisi_sas_phy_down()
2143 port->port_attached = 0; in hisi_sas_phy_down()
2144 } else if (phy->phy_type & PORT_TYPE_SATA) in hisi_sas_phy_down()
2145 port->port_attached = 0; in hisi_sas_phy_down()
2147 hisi_sas_phy_disconnected(phy); in hisi_sas_phy_down()
2152 void hisi_sas_phy_bcast(struct hisi_sas_phy *phy) in hisi_sas_phy_bcast() argument
2154 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phy_bcast()
2155 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_phy_bcast()
2157 if (test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags)) in hisi_sas_phy_bcast()
2169 return -EOPNOTSUPP; in hisi_sas_host_reset()
2171 queue_work(hisi_hba->wq, &hisi_hba->rst_work); in hisi_sas_host_reset()
2200 struct hisi_sas_breakpoint *sata_breakpoint = hisi_hba->sata_breakpoint; in hisi_sas_init_mem()
2202 for (i = 0; i < hisi_hba->queue_count; i++) { in hisi_sas_init_mem()
2203 struct hisi_sas_cq *cq = &hisi_hba->cq[i]; in hisi_sas_init_mem()
2204 struct hisi_sas_dq *dq = &hisi_hba->dq[i]; in hisi_sas_init_mem()
2205 struct hisi_sas_cmd_hdr *cmd_hdr = hisi_hba->cmd_hdr[i]; in hisi_sas_init_mem()
2211 dq->wr_point = 0; in hisi_sas_init_mem()
2213 s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS; in hisi_sas_init_mem()
2214 memset(hisi_hba->complete_hdr[i], 0, s); in hisi_sas_init_mem()
2215 cq->rd_point = 0; in hisi_sas_init_mem()
2218 s = sizeof(struct hisi_sas_initial_fis) * hisi_hba->n_phy; in hisi_sas_init_mem()
2219 memset(hisi_hba->initial_fis, 0, s); in hisi_sas_init_mem()
2222 memset(hisi_hba->iost, 0, s); in hisi_sas_init_mem()
2225 memset(hisi_hba->breakpoint, 0, s); in hisi_sas_init_mem()
2235 struct device *dev = hisi_hba->dev; in hisi_sas_alloc()
2240 sema_init(&hisi_hba->sem, 1); in hisi_sas_alloc()
2241 spin_lock_init(&hisi_hba->lock); in hisi_sas_alloc()
2242 for (i = 0; i < hisi_hba->n_phy; i++) { in hisi_sas_alloc()
2244 hisi_hba->port[i].port_attached = 0; in hisi_sas_alloc()
2245 hisi_hba->port[i].id = -1; in hisi_sas_alloc()
2249 hisi_hba->devices[i].dev_type = SAS_PHY_UNUSED; in hisi_sas_alloc()
2250 hisi_hba->devices[i].device_id = i; in hisi_sas_alloc()
2251 hisi_hba->devices[i].dev_status = HISI_SAS_DEV_INIT; in hisi_sas_alloc()
2254 for (i = 0; i < hisi_hba->queue_count; i++) { in hisi_sas_alloc()
2255 struct hisi_sas_cq *cq = &hisi_hba->cq[i]; in hisi_sas_alloc()
2256 struct hisi_sas_dq *dq = &hisi_hba->dq[i]; in hisi_sas_alloc()
2259 cq->id = i; in hisi_sas_alloc()
2260 cq->hisi_hba = hisi_hba; in hisi_sas_alloc()
2261 spin_lock_init(&cq->poll_lock); in hisi_sas_alloc()
2264 spin_lock_init(&dq->lock); in hisi_sas_alloc()
2265 INIT_LIST_HEAD(&dq->list); in hisi_sas_alloc()
2266 dq->id = i; in hisi_sas_alloc()
2267 dq->hisi_hba = hisi_hba; in hisi_sas_alloc()
2271 hisi_hba->cmd_hdr[i] = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2272 &hisi_hba->cmd_hdr_dma[i], in hisi_sas_alloc()
2274 if (!hisi_hba->cmd_hdr[i]) in hisi_sas_alloc()
2278 s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS; in hisi_sas_alloc()
2279 hisi_hba->complete_hdr[i] = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2280 &hisi_hba->complete_hdr_dma[i], in hisi_sas_alloc()
2282 if (!hisi_hba->complete_hdr[i]) in hisi_sas_alloc()
2287 hisi_hba->itct = dmam_alloc_coherent(dev, s, &hisi_hba->itct_dma, in hisi_sas_alloc()
2289 if (!hisi_hba->itct) in hisi_sas_alloc()
2292 hisi_hba->slot_info = devm_kcalloc(dev, max_command_entries, in hisi_sas_alloc()
2295 if (!hisi_hba->slot_info) in hisi_sas_alloc()
2300 if (hisi_hba->prot_mask & HISI_SAS_DIX_PROT_MASK) in hisi_sas_alloc()
2322 slot = &hisi_hba->slot_info[slot_index]; in hisi_sas_alloc()
2323 slot->buf = buf; in hisi_sas_alloc()
2324 slot->buf_dma = buf_dma; in hisi_sas_alloc()
2325 slot->idx = slot_index; in hisi_sas_alloc()
2333 hisi_hba->iost = dmam_alloc_coherent(dev, s, &hisi_hba->iost_dma, in hisi_sas_alloc()
2335 if (!hisi_hba->iost) in hisi_sas_alloc()
2339 hisi_hba->breakpoint = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2340 &hisi_hba->breakpoint_dma, in hisi_sas_alloc()
2342 if (!hisi_hba->breakpoint) in hisi_sas_alloc()
2345 s = hisi_hba->slot_index_count = max_command_entries; in hisi_sas_alloc()
2346 hisi_hba->slot_index_tags = devm_bitmap_zalloc(dev, s, GFP_KERNEL); in hisi_sas_alloc()
2347 if (!hisi_hba->slot_index_tags) in hisi_sas_alloc()
2351 hisi_hba->initial_fis = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2352 &hisi_hba->initial_fis_dma, in hisi_sas_alloc()
2354 if (!hisi_hba->initial_fis) in hisi_sas_alloc()
2358 hisi_hba->sata_breakpoint = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2359 &hisi_hba->sata_breakpoint_dma, in hisi_sas_alloc()
2361 if (!hisi_hba->sata_breakpoint) in hisi_sas_alloc()
2364 hisi_hba->last_slot_index = 0; in hisi_sas_alloc()
2366 hisi_hba->wq = in hisi_sas_alloc()
2368 if (!hisi_hba->wq) { in hisi_sas_alloc()
2375 return -ENOMEM; in hisi_sas_alloc()
2383 for (i = 0; i < hisi_hba->n_phy; i++) { in hisi_sas_free()
2384 struct hisi_sas_phy *phy = &hisi_hba->phy[i]; in hisi_sas_free() local
2386 timer_delete_sync(&phy->timer); in hisi_sas_free()
2389 if (hisi_hba->wq) in hisi_sas_free()
2390 destroy_workqueue(hisi_hba->wq); in hisi_sas_free()
2411 if (hisi_sas_controller_prereset(rst->hisi_hba)) in hisi_sas_sync_rst_work_handler()
2414 if (!hisi_sas_controller_reset(rst->hisi_hba)) in hisi_sas_sync_rst_work_handler()
2415 rst->done = true; in hisi_sas_sync_rst_work_handler()
2417 complete(rst->completion); in hisi_sas_sync_rst_work_handler()
2423 struct device *dev = hisi_hba->dev; in hisi_sas_get_fw_info()
2424 struct platform_device *pdev = hisi_hba->platform_dev; in hisi_sas_get_fw_info()
2425 struct device_node *np = pdev ? pdev->dev.of_node : NULL; in hisi_sas_get_fw_info()
2428 if (device_property_read_u8_array(dev, "sas-addr", hisi_hba->sas_addr, in hisi_sas_get_fw_info()
2430 dev_err(dev, "could not get property sas-addr\n"); in hisi_sas_get_fw_info()
2431 return -ENOENT; in hisi_sas_get_fw_info()
2436 * These properties are only required for platform device-based in hisi_sas_get_fw_info()
2439 hisi_hba->ctrl = syscon_regmap_lookup_by_phandle(np, in hisi_sas_get_fw_info()
2440 "hisilicon,sas-syscon"); in hisi_sas_get_fw_info()
2441 if (IS_ERR(hisi_hba->ctrl)) { in hisi_sas_get_fw_info()
2443 return -ENOENT; in hisi_sas_get_fw_info()
2446 if (device_property_read_u32(dev, "ctrl-reset-reg", in hisi_sas_get_fw_info()
2447 &hisi_hba->ctrl_reset_reg)) { in hisi_sas_get_fw_info()
2448 dev_err(dev, "could not get property ctrl-reset-reg\n"); in hisi_sas_get_fw_info()
2449 return -ENOENT; in hisi_sas_get_fw_info()
2452 if (device_property_read_u32(dev, "ctrl-reset-sts-reg", in hisi_sas_get_fw_info()
2453 &hisi_hba->ctrl_reset_sts_reg)) { in hisi_sas_get_fw_info()
2454 dev_err(dev, "could not get property ctrl-reset-sts-reg\n"); in hisi_sas_get_fw_info()
2455 return -ENOENT; in hisi_sas_get_fw_info()
2458 if (device_property_read_u32(dev, "ctrl-clock-ena-reg", in hisi_sas_get_fw_info()
2459 &hisi_hba->ctrl_clock_ena_reg)) { in hisi_sas_get_fw_info()
2460 dev_err(dev, "could not get property ctrl-clock-ena-reg\n"); in hisi_sas_get_fw_info()
2461 return -ENOENT; in hisi_sas_get_fw_info()
2469 hisi_hba->refclk_frequency_mhz = clk_get_rate(refclk) / 1000000; in hisi_sas_get_fw_info()
2471 if (device_property_read_u32(dev, "phy-count", &hisi_hba->n_phy)) { in hisi_sas_get_fw_info()
2472 dev_err(dev, "could not get property phy-count\n"); in hisi_sas_get_fw_info()
2473 return -ENOENT; in hisi_sas_get_fw_info()
2476 if (device_property_read_u32(dev, "queue-count", in hisi_sas_get_fw_info()
2477 &hisi_hba->queue_count)) { in hisi_sas_get_fw_info()
2478 dev_err(dev, "could not get property queue-count\n"); in hisi_sas_get_fw_info()
2479 return -ENOENT; in hisi_sas_get_fw_info()
2492 struct device *dev = &pdev->dev; in hisi_sas_shost_alloc()
2495 shost = scsi_host_alloc(hw->sht, sizeof(*hisi_hba)); in hisi_sas_shost_alloc()
2502 INIT_WORK(&hisi_hba->rst_work, hisi_sas_rst_work_handler); in hisi_sas_shost_alloc()
2503 hisi_hba->hw = hw; in hisi_sas_shost_alloc()
2504 hisi_hba->dev = dev; in hisi_sas_shost_alloc()
2505 hisi_hba->platform_dev = pdev; in hisi_sas_shost_alloc()
2506 hisi_hba->shost = shost; in hisi_sas_shost_alloc()
2507 SHOST_TO_SAS_HA(shost) = &hisi_hba->sha; in hisi_sas_shost_alloc()
2509 timer_setup(&hisi_hba->timer, NULL, 0); in hisi_sas_shost_alloc()
2514 if (hisi_hba->hw->fw_info_check) { in hisi_sas_shost_alloc()
2515 if (hisi_hba->hw->fw_info_check(hisi_hba)) in hisi_sas_shost_alloc()
2525 hisi_hba->regs = devm_platform_ioremap_resource(pdev, 0); in hisi_sas_shost_alloc()
2526 if (IS_ERR(hisi_hba->regs)) in hisi_sas_shost_alloc()
2531 hisi_hba->sgpio_regs = devm_ioremap_resource(dev, res); in hisi_sas_shost_alloc()
2532 if (IS_ERR(hisi_hba->sgpio_regs)) in hisi_sas_shost_alloc()
2550 if (hisi_hba->hw->interrupt_preinit) in hisi_sas_interrupt_preinit()
2551 return hisi_hba->hw->interrupt_preinit(hisi_hba); in hisi_sas_interrupt_preinit()
2560 struct device *dev = &pdev->dev; in hisi_sas_probe()
2568 return -ENOMEM; in hisi_sas_probe()
2574 phy_nr = port_nr = hisi_hba->n_phy; in hisi_sas_probe()
2579 rc = -ENOMEM; in hisi_sas_probe()
2583 sha->sas_phy = arr_phy; in hisi_sas_probe()
2584 sha->sas_port = arr_port; in hisi_sas_probe()
2585 sha->lldd_ha = hisi_hba; in hisi_sas_probe()
2587 shost->transportt = hisi_sas_stt; in hisi_sas_probe()
2588 shost->max_id = HISI_SAS_MAX_DEVICES; in hisi_sas_probe()
2589 shost->max_lun = ~0; in hisi_sas_probe()
2590 shost->max_channel = 1; in hisi_sas_probe()
2591 shost->max_cmd_len = 16; in hisi_sas_probe()
2592 if (hisi_hba->hw->slot_index_alloc) { in hisi_sas_probe()
2593 shost->can_queue = HISI_SAS_MAX_COMMANDS; in hisi_sas_probe()
2594 shost->cmd_per_lun = HISI_SAS_MAX_COMMANDS; in hisi_sas_probe()
2596 shost->can_queue = HISI_SAS_UNRESERVED_IPTT; in hisi_sas_probe()
2597 shost->cmd_per_lun = HISI_SAS_UNRESERVED_IPTT; in hisi_sas_probe()
2600 sha->sas_ha_name = DRV_NAME; in hisi_sas_probe()
2601 sha->dev = hisi_hba->dev; in hisi_sas_probe()
2602 sha->sas_addr = &hisi_hba->sas_addr[0]; in hisi_sas_probe()
2603 sha->num_phys = hisi_hba->n_phy; in hisi_sas_probe()
2604 sha->shost = hisi_hba->shost; in hisi_sas_probe()
2606 for (i = 0; i < hisi_hba->n_phy; i++) { in hisi_sas_probe()
2607 sha->sas_phy[i] = &hisi_hba->phy[i].sas_phy; in hisi_sas_probe()
2608 sha->sas_port[i] = &hisi_hba->port[i].sas_port; in hisi_sas_probe()
2615 rc = scsi_add_host(shost, &pdev->dev); in hisi_sas_probe()
2623 rc = hisi_hba->hw->hw_init(hisi_hba); in hisi_sas_probe()
2645 struct hisi_hba *hisi_hba = sha->lldd_ha; in hisi_sas_remove()
2646 struct Scsi_Host *shost = sha->shost; in hisi_sas_remove()
2648 timer_delete_sync(&hisi_hba->timer); in hisi_sas_remove()
2684 return -ENOMEM; in hisi_sas_init()