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);
26 switch (fis->command) { in hisi_sas_get_ata_protocol()
79 switch (fis->features) { in hisi_sas_get_ata_protocol()
105 struct task_status_struct *ts = &task->task_status; in hisi_sas_sata_done()
106 struct ata_task_resp *resp = (struct ata_task_resp *)ts->buf; in hisi_sas_sata_done()
109 u8 *iu = &status_buf->iu[0]; in hisi_sas_sata_done()
112 resp->frame_len = sizeof(struct dev_to_host_fis); in hisi_sas_sata_done()
113 memcpy(&resp->ending_fis[0], d2h, sizeof(struct dev_to_host_fis)); in hisi_sas_sata_done()
115 ts->buf_valid_size = sizeof(*resp); in hisi_sas_sata_done()
128 max -= SAS_LINK_RATE_1_5_GBPS; in hisi_sas_get_prog_phy_linkrate_mask()
135 static struct hisi_hba *dev_to_hisi_hba(struct domain_device *device) in dev_to_hisi_hba() argument
137 return device->port->ha->lldd_ha; in dev_to_hisi_hba()
150 for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) in hisi_sas_stop_phys()
157 void *bitmap = hisi_hba->slot_index_tags; in hisi_sas_slot_index_clear()
164 if (hisi_hba->hw->slot_index_alloc || in hisi_sas_slot_index_free()
166 spin_lock(&hisi_hba->lock); in hisi_sas_slot_index_free()
168 spin_unlock(&hisi_hba->lock); in hisi_sas_slot_index_free()
174 void *bitmap = hisi_hba->slot_index_tags; in hisi_sas_slot_index_set()
183 void *bitmap = hisi_hba->slot_index_tags; in hisi_sas_slot_index_alloc()
186 return rq->tag + HISI_SAS_RESERVED_IPTT; in hisi_sas_slot_index_alloc()
188 spin_lock(&hisi_hba->lock); in hisi_sas_slot_index_alloc()
190 hisi_hba->last_slot_index + 1); in hisi_sas_slot_index_alloc()
196 spin_unlock(&hisi_hba->lock); in hisi_sas_slot_index_alloc()
197 return -SAS_QUEUE_FULL; in hisi_sas_slot_index_alloc()
201 hisi_hba->last_slot_index = index; in hisi_sas_slot_index_alloc()
202 spin_unlock(&hisi_hba->lock); in hisi_sas_slot_index_alloc()
210 int device_id = slot->device_id; in hisi_sas_slot_task_free()
211 struct hisi_sas_device *sas_dev = &hisi_hba->devices[device_id]; in hisi_sas_slot_task_free()
214 struct device *dev = hisi_hba->dev; in hisi_sas_slot_task_free()
216 if (!task->lldd_task) in hisi_sas_slot_task_free()
219 task->lldd_task = NULL; in hisi_sas_slot_task_free()
221 if (!sas_protocol_ata(task->task_proto)) { in hisi_sas_slot_task_free()
222 if (slot->n_elem) { in hisi_sas_slot_task_free()
223 if (task->task_proto & SAS_PROTOCOL_SSP) in hisi_sas_slot_task_free()
224 dma_unmap_sg(dev, task->scatter, in hisi_sas_slot_task_free()
225 task->num_scatter, in hisi_sas_slot_task_free()
226 task->data_dir); in hisi_sas_slot_task_free()
228 dma_unmap_sg(dev, &task->smp_task.smp_req, in hisi_sas_slot_task_free()
231 if (slot->n_elem_dif) { in hisi_sas_slot_task_free()
232 struct sas_ssp_task *ssp_task = &task->ssp_task; in hisi_sas_slot_task_free()
233 struct scsi_cmnd *scsi_cmnd = ssp_task->cmd; in hisi_sas_slot_task_free()
237 task->data_dir); in hisi_sas_slot_task_free()
243 spin_lock(&sas_dev->lock); in hisi_sas_slot_task_free()
244 list_del_init(&slot->entry); in hisi_sas_slot_task_free()
245 spin_unlock(&sas_dev->lock); in hisi_sas_slot_task_free()
247 list_del_init(&slot->entry); in hisi_sas_slot_task_free()
252 hisi_sas_slot_index_free(hisi_hba, slot->idx); in hisi_sas_slot_task_free()
259 hisi_hba->hw->prep_smp(hisi_hba, slot); in hisi_sas_task_prep_smp()
265 hisi_hba->hw->prep_ssp(hisi_hba, slot); in hisi_sas_task_prep_ssp()
271 hisi_hba->hw->prep_stp(hisi_hba, slot); in hisi_sas_task_prep_ata()
277 hisi_hba->hw->prep_abort(hisi_hba, slot); in hisi_sas_task_prep_abort()
283 struct device *dev = hisi_hba->dev; in hisi_sas_dma_unmap()
285 if (!sas_protocol_ata(task->task_proto) && n_elem) { in hisi_sas_dma_unmap()
286 if (task->num_scatter) { in hisi_sas_dma_unmap()
287 dma_unmap_sg(dev, task->scatter, task->num_scatter, in hisi_sas_dma_unmap()
288 task->data_dir); in hisi_sas_dma_unmap()
289 } else if (task->task_proto & SAS_PROTOCOL_SMP) { in hisi_sas_dma_unmap()
290 dma_unmap_sg(dev, &task->smp_task.smp_req, in hisi_sas_dma_unmap()
299 struct device *dev = hisi_hba->dev; in hisi_sas_dma_map()
302 if (sas_protocol_ata(task->task_proto)) { in hisi_sas_dma_map()
303 *n_elem = task->num_scatter; in hisi_sas_dma_map()
307 if (task->num_scatter) { in hisi_sas_dma_map()
308 *n_elem = dma_map_sg(dev, task->scatter, in hisi_sas_dma_map()
309 task->num_scatter, task->data_dir); in hisi_sas_dma_map()
311 rc = -ENOMEM; in hisi_sas_dma_map()
314 } else if (task->task_proto & SAS_PROTOCOL_SMP) { in hisi_sas_dma_map()
315 *n_elem = dma_map_sg(dev, &task->smp_task.smp_req, in hisi_sas_dma_map()
318 rc = -ENOMEM; in hisi_sas_dma_map()
321 req_len = sg_dma_len(&task->smp_task.smp_req); in hisi_sas_dma_map()
323 rc = -EINVAL; in hisi_sas_dma_map()
332 rc = -EINVAL; in hisi_sas_dma_map()
347 struct device *dev = hisi_hba->dev; in hisi_sas_dif_dma_unmap()
350 struct sas_ssp_task *ssp_task = &task->ssp_task; in hisi_sas_dif_dma_unmap()
351 struct scsi_cmnd *scsi_cmnd = ssp_task->cmd; in hisi_sas_dif_dma_unmap()
355 task->data_dir); in hisi_sas_dif_dma_unmap()
362 struct device *dev = hisi_hba->dev; in hisi_sas_dif_dma_map()
367 if (task->num_scatter) { in hisi_sas_dif_dma_map()
368 ssp_task = &task->ssp_task; in hisi_sas_dif_dma_map()
369 scsi_cmnd = ssp_task->cmd; in hisi_sas_dif_dma_map()
375 task->data_dir); in hisi_sas_dif_dma_map()
378 return -ENOMEM; in hisi_sas_dif_dma_map()
383 rc = -EINVAL; in hisi_sas_dif_dma_map()
393 scsi_prot_sg_count(scsi_cmnd), task->data_dir); in hisi_sas_dif_dma_map()
405 struct sas_task *task = slot->task; in hisi_sas_task_deliver()
408 spin_lock(&dq->lock); in hisi_sas_task_deliver()
409 wr_q_index = dq->wr_point; in hisi_sas_task_deliver()
410 dq->wr_point = (dq->wr_point + 1) % HISI_SAS_QUEUE_SLOTS; in hisi_sas_task_deliver()
411 list_add_tail(&slot->delivery, &dq->list); in hisi_sas_task_deliver()
412 spin_unlock(&dq->lock); in hisi_sas_task_deliver()
413 spin_lock(&sas_dev->lock); in hisi_sas_task_deliver()
414 list_add_tail(&slot->entry, &sas_dev->list); in hisi_sas_task_deliver()
415 spin_unlock(&sas_dev->lock); in hisi_sas_task_deliver()
417 dlvry_queue = dq->id; in hisi_sas_task_deliver()
420 slot->device_id = sas_dev->device_id; in hisi_sas_task_deliver()
421 slot->dlvry_queue = dlvry_queue; in hisi_sas_task_deliver()
422 slot->dlvry_queue_slot = dlvry_queue_slot; in hisi_sas_task_deliver()
423 cmd_hdr_base = hisi_hba->cmd_hdr[dlvry_queue]; in hisi_sas_task_deliver()
424 slot->cmd_hdr = &cmd_hdr_base[dlvry_queue_slot]; in hisi_sas_task_deliver()
426 task->lldd_task = slot; in hisi_sas_task_deliver()
428 memset(slot->cmd_hdr, 0, sizeof(struct hisi_sas_cmd_hdr)); in hisi_sas_task_deliver()
433 switch (task->task_proto) { in hisi_sas_task_deliver()
454 WRITE_ONCE(slot->ready, 1); in hisi_sas_task_deliver()
456 spin_lock(&dq->lock); in hisi_sas_task_deliver()
457 hisi_hba->hw->start_delivery(dq); in hisi_sas_task_deliver()
458 spin_unlock(&dq->lock); in hisi_sas_task_deliver()
464 struct domain_device *device = task->dev; in hisi_sas_queue_command() local
465 struct asd_sas_port *sas_port = device->port; in hisi_sas_queue_command()
466 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_queue_command()
473 struct device *dev; in hisi_sas_queue_command()
477 struct task_status_struct *ts = &task->task_status; in hisi_sas_queue_command()
479 ts->resp = SAS_TASK_UNDELIVERED; in hisi_sas_queue_command()
480 ts->stat = SAS_PHY_DOWN; in hisi_sas_queue_command()
482 * libsas will use dev->port, should in hisi_sas_queue_command()
485 if (device->dev_type != SAS_SATA_DEV && !internal_abort) in hisi_sas_queue_command()
486 task->task_done(task); in hisi_sas_queue_command()
487 return -ECOMM; in hisi_sas_queue_command()
490 hisi_hba = dev_to_hisi_hba(device); in hisi_sas_queue_command()
491 dev = hisi_hba->dev; in hisi_sas_queue_command()
493 switch (task->task_proto) { in hisi_sas_queue_command()
499 if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags))) { in hisi_sas_queue_command()
501 return -EINVAL; in hisi_sas_queue_command()
503 down(&hisi_hba->sem); in hisi_sas_queue_command()
504 up(&hisi_hba->sem); in hisi_sas_queue_command()
509 dev_info(dev, "task prep: device %d not ready\n", in hisi_sas_queue_command()
510 sas_dev->device_id); in hisi_sas_queue_command()
512 dev_info(dev, "task prep: device %016llx not ready\n", in hisi_sas_queue_command()
513 SAS_ADDR(device->sas_addr)); in hisi_sas_queue_command()
515 return -ECOMM; in hisi_sas_queue_command()
519 if (!port->port_attached) { in hisi_sas_queue_command()
520 dev_info(dev, "task prep: %s port%d not attach device\n", in hisi_sas_queue_command()
521 dev_is_sata(device) ? "SATA/STP" : "SAS", in hisi_sas_queue_command()
522 device->port->id); in hisi_sas_queue_command()
524 return -ECOMM; in hisi_sas_queue_command()
534 dq = &hisi_hba->dq[dq_index]; in hisi_sas_queue_command()
538 if (hisi_hba->iopoll_q_cnt) { in hisi_sas_queue_command()
546 struct Scsi_Host *shost = hisi_hba->shost; in hisi_sas_queue_command()
547 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT]; in hisi_sas_queue_command()
549 queue = qmap->mq_map[raw_smp_processor_id()]; in hisi_sas_queue_command()
551 dq = &hisi_hba->dq[queue]; in hisi_sas_queue_command()
555 if (!hisi_hba->hw->prep_abort) in hisi_sas_queue_command()
558 if (test_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags)) in hisi_sas_queue_command()
559 return -EIO; in hisi_sas_queue_command()
561 hisi_hba = dev_to_hisi_hba(device); in hisi_sas_queue_command()
563 if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags))) in hisi_sas_queue_command()
564 return -EINVAL; in hisi_sas_queue_command()
567 dq = &hisi_hba->dq[task->abort_task.qid]; in hisi_sas_queue_command()
570 dev_err(hisi_hba->dev, "task prep: unknown/unsupported proto (0x%x)\n", in hisi_sas_queue_command()
571 task->task_proto); in hisi_sas_queue_command()
572 return -EINVAL; in hisi_sas_queue_command()
579 if (!sas_protocol_ata(task->task_proto)) { in hisi_sas_queue_command()
585 if (!internal_abort && hisi_hba->hw->slot_index_alloc) in hisi_sas_queue_command()
586 rc = hisi_hba->hw->slot_index_alloc(hisi_hba, device); in hisi_sas_queue_command()
593 slot = &hisi_hba->slot_info[rc]; in hisi_sas_queue_command()
594 slot->n_elem = n_elem; in hisi_sas_queue_command()
595 slot->n_elem_dif = n_elem_dif; in hisi_sas_queue_command()
596 slot->task = task; in hisi_sas_queue_command()
597 slot->port = port; in hisi_sas_queue_command()
599 slot->tmf = task->tmf; in hisi_sas_queue_command()
600 slot->is_internal = !!task->tmf || internal_abort; in hisi_sas_queue_command()
608 if (!sas_protocol_ata(task->task_proto)) in hisi_sas_queue_command()
620 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_bytes_dmaed() local
621 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_bytes_dmaed()
623 if (!phy->phy_attached) in hisi_sas_bytes_dmaed()
628 if (sas_phy->phy) { in hisi_sas_bytes_dmaed()
629 struct sas_phy *sphy = sas_phy->phy; in hisi_sas_bytes_dmaed()
631 sphy->negotiated_linkrate = sas_phy->linkrate; in hisi_sas_bytes_dmaed()
632 sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; in hisi_sas_bytes_dmaed()
633 sphy->maximum_linkrate_hw = in hisi_sas_bytes_dmaed()
634 hisi_hba->hw->phy_get_max_linkrate(); in hisi_sas_bytes_dmaed()
635 if (sphy->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) in hisi_sas_bytes_dmaed()
636 sphy->minimum_linkrate = phy->minimum_linkrate; in hisi_sas_bytes_dmaed()
638 if (sphy->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) in hisi_sas_bytes_dmaed()
639 sphy->maximum_linkrate = phy->maximum_linkrate; in hisi_sas_bytes_dmaed()
642 if (phy->phy_type & PORT_TYPE_SAS) { in hisi_sas_bytes_dmaed()
645 id = (struct sas_identify_frame *)phy->frame_rcvd; in hisi_sas_bytes_dmaed()
646 id->dev_type = phy->identify.device_type; in hisi_sas_bytes_dmaed()
647 id->initiator_bits = SAS_PROTOCOL_ALL; in hisi_sas_bytes_dmaed()
648 id->target_bits = phy->identify.target_port_protocols; in hisi_sas_bytes_dmaed()
649 } else if (phy->phy_type & PORT_TYPE_SATA) { in hisi_sas_bytes_dmaed()
653 sas_phy->frame_rcvd_size = phy->frame_rcvd_size; in hisi_sas_bytes_dmaed()
657 static struct hisi_sas_device *hisi_sas_alloc_dev(struct domain_device *device) in hisi_sas_alloc_dev() argument
659 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_alloc_dev()
661 int last = hisi_hba->last_dev_id; in hisi_sas_alloc_dev()
662 int first = (hisi_hba->last_dev_id + 1) % HISI_SAS_MAX_DEVICES; in hisi_sas_alloc_dev()
665 spin_lock(&hisi_hba->lock); in hisi_sas_alloc_dev()
667 if (hisi_hba->devices[i].dev_type == SAS_PHY_UNUSED) { in hisi_sas_alloc_dev()
668 int queue = i % hisi_hba->queue_count; in hisi_sas_alloc_dev()
669 struct hisi_sas_dq *dq = &hisi_hba->dq[queue]; in hisi_sas_alloc_dev()
671 hisi_hba->devices[i].device_id = i; in hisi_sas_alloc_dev()
672 sas_dev = &hisi_hba->devices[i]; in hisi_sas_alloc_dev()
673 sas_dev->dev_status = HISI_SAS_DEV_INIT; in hisi_sas_alloc_dev()
674 sas_dev->dev_type = device->dev_type; in hisi_sas_alloc_dev()
675 sas_dev->hisi_hba = hisi_hba; in hisi_sas_alloc_dev()
676 sas_dev->sas_device = device; in hisi_sas_alloc_dev()
677 sas_dev->dq = dq; in hisi_sas_alloc_dev()
678 spin_lock_init(&sas_dev->lock); in hisi_sas_alloc_dev()
679 INIT_LIST_HEAD(&hisi_hba->devices[i].list); in hisi_sas_alloc_dev()
684 hisi_hba->last_dev_id = i; in hisi_sas_alloc_dev()
685 spin_unlock(&hisi_hba->lock); in hisi_sas_alloc_dev()
693 spin_lock(&cq->poll_lock); in hisi_sas_sync_poll_cq()
694 spin_unlock(&cq->poll_lock); in hisi_sas_sync_poll_cq()
699 struct hisi_hba *hisi_hba = cq->hisi_hba; in hisi_sas_queue_is_poll()
701 if (cq->id < hisi_hba->queue_count - hisi_hba->iopoll_q_cnt) in hisi_sas_queue_is_poll()
711 synchronize_irq(cq->irq_no); in hisi_sas_sync_cq()
718 for (i = 0; i < hisi_hba->queue_count; i++) { in hisi_sas_sync_poll_cqs()
719 struct hisi_sas_cq *cq = &hisi_hba->cq[i]; in hisi_sas_sync_poll_cqs()
731 for (i = 0; i < hisi_hba->queue_count; i++) { in hisi_sas_sync_cqs()
732 struct hisi_sas_cq *cq = &hisi_hba->cq[i]; in hisi_sas_sync_cqs()
741 struct hisi_sas_slot *slot = task->lldd_task; in hisi_sas_tmf_aborted()
742 struct domain_device *device = task->dev; in hisi_sas_tmf_aborted() local
743 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_tmf_aborted()
744 struct hisi_hba *hisi_hba = sas_dev->hisi_hba; in hisi_sas_tmf_aborted()
748 &hisi_hba->cq[slot->dlvry_queue]; in hisi_sas_tmf_aborted()
754 slot->task = NULL; in hisi_sas_tmf_aborted()
759 static int hisi_sas_init_device(struct domain_device *device) in hisi_sas_init_device() argument
764 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_init_device()
766 switch (device->dev_type) { in hisi_sas_init_device()
770 while (retry-- > 0) { in hisi_sas_init_device()
771 rc = sas_abort_task_set(device, lun.scsi_lun); in hisi_sas_init_device()
773 hisi_sas_release_task(hisi_hba, device); in hisi_sas_init_device()
789 * a. When probing the device, libsas/libata already issues a in hisi_sas_init_device()
790 * hard reset in sas_probe_sata() -> ata_port_probe(). in hisi_sas_init_device()
795 while (retry-- > 0) { in hisi_sas_init_device()
796 rc = hisi_sas_softreset_ata_disk(device); in hisi_sas_init_device()
811 struct hisi_sas_device *sas_dev = ddev->lldd_dev; in hisi_sas_slave_alloc()
821 sas_dev->dev_status = HISI_SAS_DEV_NORMAL; in hisi_sas_slave_alloc()
826 static int hisi_sas_dev_found(struct domain_device *device) in hisi_sas_dev_found() argument
828 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_dev_found()
829 struct domain_device *parent_dev = device->parent; in hisi_sas_dev_found()
831 struct device *dev = hisi_hba->dev; in hisi_sas_dev_found()
834 if (hisi_hba->hw->alloc_dev) in hisi_sas_dev_found()
835 sas_dev = hisi_hba->hw->alloc_dev(device); in hisi_sas_dev_found()
837 sas_dev = hisi_sas_alloc_dev(device); in hisi_sas_dev_found()
841 return -EINVAL; in hisi_sas_dev_found()
844 device->lldd_dev = sas_dev; in hisi_sas_dev_found()
845 hisi_hba->hw->setup_itct(hisi_hba, sas_dev); in hisi_sas_dev_found()
847 if (parent_dev && dev_is_expander(parent_dev->dev_type)) { in hisi_sas_dev_found()
850 phy_no = sas_find_attached_phy_id(&parent_dev->ex_dev, device); in hisi_sas_dev_found()
854 SAS_ADDR(device->sas_addr), in hisi_sas_dev_found()
855 SAS_ADDR(parent_dev->sas_addr)); in hisi_sas_dev_found()
862 sas_dev->device_id, sas_dev->dev_type); in hisi_sas_dev_found()
867 hisi_sas_dev_gone(device); in hisi_sas_dev_found()
890 hisi_hba->hw->phys_init(hisi_hba); in hisi_sas_scan_start()
897 struct sas_ha_struct *sha = &hisi_hba->sha; in hisi_sas_scan_finished()
899 /* Wait for PHY up interrupt to occur */ in hisi_sas_scan_finished()
911 struct hisi_sas_phy *phy = in hisi_sas_phyup_work_common() local
912 container_of(work, typeof(*phy), works[event]); in hisi_sas_phyup_work_common()
913 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_phyup_work_common()
914 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phyup_work_common()
915 int phy_no = sas_phy->id; in hisi_sas_phyup_work_common()
917 phy->wait_phyup_cnt = 0; in hisi_sas_phyup_work_common()
918 if (phy->identify.target_port_protocols == SAS_PROTOCOL_SSP) in hisi_sas_phyup_work_common()
919 hisi_hba->hw->sl_notify_ssp(hisi_hba, phy_no); in hisi_sas_phyup_work_common()
930 struct hisi_sas_phy *phy = in hisi_sas_linkreset_work() local
931 container_of(work, typeof(*phy), works[HISI_PHYE_LINK_RESET]); in hisi_sas_linkreset_work()
932 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_linkreset_work()
939 struct hisi_sas_phy *phy = in hisi_sas_phyup_pm_work() local
940 container_of(work, typeof(*phy), works[HISI_PHYE_PHY_UP_PM]); in hisi_sas_phyup_pm_work()
941 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_phyup_pm_work()
942 struct device *dev = hisi_hba->dev; in hisi_sas_phyup_pm_work()
954 bool hisi_sas_notify_phy_event(struct hisi_sas_phy *phy, in hisi_sas_notify_phy_event() argument
957 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_notify_phy_event()
962 return queue_work(hisi_hba->wq, &phy->works[event]); in hisi_sas_notify_phy_event()
968 struct hisi_sas_phy *phy = from_timer(phy, t, timer); in hisi_sas_wait_phyup_timedout() local
969 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_wait_phyup_timedout()
970 struct device *dev = hisi_hba->dev; in hisi_sas_wait_phyup_timedout()
971 int phy_no = phy->sas_phy.id; in hisi_sas_wait_phyup_timedout()
973 dev_warn(dev, "phy%d wait phyup timeout, issuing link reset\n", phy_no); in hisi_sas_wait_phyup_timedout()
974 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET); in hisi_sas_wait_phyup_timedout()
981 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_oob_ready() local
982 struct device *dev = hisi_hba->dev; in hisi_sas_phy_oob_ready()
985 dev_dbg(dev, "phy%d OOB ready\n", phy_no); in hisi_sas_phy_oob_ready()
986 spin_lock_irqsave(&phy->lock, flags); in hisi_sas_phy_oob_ready()
987 if (phy->phy_attached) { in hisi_sas_phy_oob_ready()
988 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_phy_oob_ready()
992 if (!timer_pending(&phy->timer)) { in hisi_sas_phy_oob_ready()
993 if (phy->wait_phyup_cnt < HISI_SAS_WAIT_PHYUP_RETRIES) { in hisi_sas_phy_oob_ready()
994 phy->wait_phyup_cnt++; in hisi_sas_phy_oob_ready()
995 phy->timer.expires = jiffies + in hisi_sas_phy_oob_ready()
997 add_timer(&phy->timer); in hisi_sas_phy_oob_ready()
998 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_phy_oob_ready()
1002 dev_warn(dev, "phy%d failed to come up %d times, giving up\n", in hisi_sas_phy_oob_ready()
1003 phy_no, phy->wait_phyup_cnt); in hisi_sas_phy_oob_ready()
1004 phy->wait_phyup_cnt = 0; in hisi_sas_phy_oob_ready()
1006 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_phy_oob_ready()
1013 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_init() local
1014 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phy_init()
1017 phy->hisi_hba = hisi_hba; in hisi_sas_phy_init()
1018 phy->port = NULL; in hisi_sas_phy_init()
1019 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS; in hisi_sas_phy_init()
1020 phy->maximum_linkrate = hisi_hba->hw->phy_get_max_linkrate(); in hisi_sas_phy_init()
1021 sas_phy->enabled = (phy_no < hisi_hba->n_phy) ? 1 : 0; in hisi_sas_phy_init()
1022 sas_phy->iproto = SAS_PROTOCOL_ALL; in hisi_sas_phy_init()
1023 sas_phy->tproto = 0; in hisi_sas_phy_init()
1024 sas_phy->role = PHY_ROLE_INITIATOR; in hisi_sas_phy_init()
1025 sas_phy->oob_mode = OOB_NOT_CONNECTED; in hisi_sas_phy_init()
1026 sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN; in hisi_sas_phy_init()
1027 sas_phy->id = phy_no; in hisi_sas_phy_init()
1028 sas_phy->sas_addr = &hisi_hba->sas_addr[0]; in hisi_sas_phy_init()
1029 sas_phy->frame_rcvd = &phy->frame_rcvd[0]; in hisi_sas_phy_init()
1030 sas_phy->ha = (struct sas_ha_struct *)hisi_hba->shost->hostdata; in hisi_sas_phy_init()
1031 sas_phy->lldd_phy = phy; in hisi_sas_phy_init()
1034 INIT_WORK(&phy->works[i], hisi_sas_phye_fns[i]); in hisi_sas_phy_init()
1036 spin_lock_init(&phy->lock); in hisi_sas_phy_init()
1038 timer_setup(&phy->timer, hisi_sas_wait_phyup_timedout, 0); in hisi_sas_phy_init()
1044 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_enable() local
1045 struct asd_sas_phy *aphy = &phy->sas_phy; in hisi_sas_phy_enable()
1046 struct sas_phy *sphy = aphy->phy; in hisi_sas_phy_enable()
1049 spin_lock_irqsave(&phy->lock, flags); in hisi_sas_phy_enable()
1053 if (!phy->enable) in hisi_sas_phy_enable()
1054 sphy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN; in hisi_sas_phy_enable()
1055 hisi_hba->hw->phy_start(hisi_hba, phy_no); in hisi_sas_phy_enable()
1057 sphy->negotiated_linkrate = SAS_PHY_DISABLED; in hisi_sas_phy_enable()
1058 hisi_hba->hw->phy_disable(hisi_hba, phy_no); in hisi_sas_phy_enable()
1060 phy->enable = enable; in hisi_sas_phy_enable()
1061 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_phy_enable()
1067 struct hisi_sas_phy *phy = sas_phy->lldd_phy; in hisi_sas_port_notify_formed() local
1068 struct asd_sas_port *sas_port = sas_phy->port; in hisi_sas_port_notify_formed()
1075 port->port_attached = 1; in hisi_sas_port_notify_formed()
1076 port->id = phy->port_id; in hisi_sas_port_notify_formed()
1077 phy->port = port; in hisi_sas_port_notify_formed()
1078 sas_port->lldd_port = port; in hisi_sas_port_notify_formed()
1088 ts = &task->task_status; in hisi_sas_do_release_task()
1090 ts->resp = SAS_TASK_COMPLETE; in hisi_sas_do_release_task()
1091 ts->stat = SAS_ABORTED_TASK; in hisi_sas_do_release_task()
1092 spin_lock_irqsave(&task->task_state_lock, flags); in hisi_sas_do_release_task()
1093 task->task_state_flags &= ~SAS_TASK_STATE_PENDING; in hisi_sas_do_release_task()
1094 if (!slot->is_internal && task->task_proto != SAS_PROTOCOL_SMP) in hisi_sas_do_release_task()
1095 task->task_state_flags |= SAS_TASK_STATE_DONE; in hisi_sas_do_release_task()
1096 spin_unlock_irqrestore(&task->task_state_lock, flags); in hisi_sas_do_release_task()
1103 struct domain_device *device) in hisi_sas_release_task() argument
1106 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_release_task()
1108 spin_lock(&sas_dev->lock); in hisi_sas_release_task()
1109 list_for_each_entry_safe(slot, slot2, &sas_dev->list, entry) in hisi_sas_release_task()
1110 hisi_sas_do_release_task(hisi_hba, slot->task, slot, false); in hisi_sas_release_task()
1112 spin_unlock(&sas_dev->lock); in hisi_sas_release_task()
1118 struct domain_device *device; in hisi_sas_release_tasks() local
1122 sas_dev = &hisi_hba->devices[i]; in hisi_sas_release_tasks()
1123 device = sas_dev->sas_device; in hisi_sas_release_tasks()
1125 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || in hisi_sas_release_tasks()
1126 !device) in hisi_sas_release_tasks()
1129 hisi_sas_release_task(hisi_hba, device); in hisi_sas_release_tasks()
1135 struct domain_device *device) in hisi_sas_dereg_device() argument
1137 if (hisi_hba->hw->dereg_device) in hisi_sas_dereg_device()
1138 hisi_hba->hw->dereg_device(hisi_hba, device); in hisi_sas_dereg_device()
1146 struct domain_device *device = sas_dev->sas_device; in hisi_sas_internal_task_abort_dev() local
1147 struct hisi_hba *hisi_hba = sas_dev->hisi_hba; in hisi_sas_internal_task_abort_dev()
1150 for (i = 0; i < hisi_hba->cq_nvecs; i++) { in hisi_sas_internal_task_abort_dev()
1151 struct hisi_sas_cq *cq = &hisi_hba->cq[i]; in hisi_sas_internal_task_abort_dev()
1152 const struct cpumask *mask = cq->irq_mask; in hisi_sas_internal_task_abort_dev()
1156 rc = sas_execute_internal_abort_dev(device, i, &data); in hisi_sas_internal_task_abort_dev()
1164 static void hisi_sas_dev_gone(struct domain_device *device) in hisi_sas_dev_gone() argument
1166 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_dev_gone()
1167 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_dev_gone()
1168 struct device *dev = hisi_hba->dev; in hisi_sas_dev_gone()
1172 sas_dev->device_id, sas_dev->dev_type); in hisi_sas_dev_gone()
1174 down(&hisi_hba->sem); in hisi_sas_dev_gone()
1175 if (!test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags)) { in hisi_sas_dev_gone()
1178 hisi_sas_dereg_device(hisi_hba, device); in hisi_sas_dev_gone()
1180 ret = hisi_hba->hw->clear_itct(hisi_hba, sas_dev); in hisi_sas_dev_gone()
1181 device->lldd_dev = NULL; in hisi_sas_dev_gone()
1184 if (hisi_hba->hw->free_device) in hisi_sas_dev_gone()
1185 hisi_hba->hw->free_device(sas_dev); in hisi_sas_dev_gone()
1189 sas_dev->dev_type = SAS_PHY_UNUSED; in hisi_sas_dev_gone()
1190 sas_dev->sas_device = NULL; in hisi_sas_dev_gone()
1191 up(&hisi_hba->sem); in hisi_sas_dev_gone()
1199 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_set_linkrate() local
1200 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phy_set_linkrate()
1203 if (r->minimum_linkrate > SAS_LINK_RATE_1_5_GBPS) in hisi_sas_phy_set_linkrate()
1204 return -EINVAL; in hisi_sas_phy_set_linkrate()
1206 if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) { in hisi_sas_phy_set_linkrate()
1207 max = sas_phy->phy->maximum_linkrate; in hisi_sas_phy_set_linkrate()
1208 min = r->minimum_linkrate; in hisi_sas_phy_set_linkrate()
1209 } else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) { in hisi_sas_phy_set_linkrate()
1210 max = r->maximum_linkrate; in hisi_sas_phy_set_linkrate()
1211 min = sas_phy->phy->minimum_linkrate; in hisi_sas_phy_set_linkrate()
1213 return -EINVAL; in hisi_sas_phy_set_linkrate()
1218 sas_phy->phy->maximum_linkrate = max; in hisi_sas_phy_set_linkrate()
1219 sas_phy->phy->minimum_linkrate = min; in hisi_sas_phy_set_linkrate()
1223 hisi_hba->hw->phy_set_linkrate(hisi_hba, phy_no, &_r); in hisi_sas_phy_set_linkrate()
1232 struct hisi_sas_phy *phy = container_of(sas_phy, in hisi_sas_control_phy() local
1234 struct sas_ha_struct *sas_ha = sas_phy->ha; in hisi_sas_control_phy()
1235 struct hisi_hba *hisi_hba = sas_ha->lldd_ha; in hisi_sas_control_phy()
1236 struct device *dev = hisi_hba->dev; in hisi_sas_control_phy()
1238 int phy_no = sas_phy->id; in hisi_sas_control_phy()
1239 u8 sts = phy->phy_attached; in hisi_sas_control_phy()
1242 down(&hisi_hba->sem); in hisi_sas_control_phy()
1243 phy->reset_completion = &completion; in hisi_sas_control_phy()
1247 hisi_hba->hw->phy_hard_reset(hisi_hba, phy_no); in hisi_sas_control_phy()
1265 if (hisi_hba->hw->get_events) { in hisi_sas_control_phy()
1266 hisi_hba->hw->get_events(hisi_hba, phy_no); in hisi_sas_control_phy()
1272 ret = -EOPNOTSUPP; in hisi_sas_control_phy()
1278 dev_warn(dev, "phy%d wait phyup timed out for func %d\n", in hisi_sas_control_phy()
1280 if (phy->in_reset) in hisi_sas_control_phy()
1281 ret = -ETIMEDOUT; in hisi_sas_control_phy()
1285 phy->reset_completion = NULL; in hisi_sas_control_phy()
1287 up(&hisi_hba->sem); in hisi_sas_control_phy()
1305 static int hisi_sas_softreset_ata_disk(struct domain_device *device) in hisi_sas_softreset_ata_disk() argument
1308 struct ata_port *ap = device->sata_dev.ap; in hisi_sas_softreset_ata_disk()
1311 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_softreset_ata_disk()
1312 struct device *dev = hisi_hba->dev; in hisi_sas_softreset_ata_disk()
1317 hisi_sas_fill_ata_reset_cmd(link->device, 1, pmp, fis); in hisi_sas_softreset_ata_disk()
1318 rc = sas_execute_ata_cmd(device, fis, -1); in hisi_sas_softreset_ata_disk()
1327 hisi_sas_fill_ata_reset_cmd(link->device, 0, pmp, fis); in hisi_sas_softreset_ata_disk()
1328 rc = sas_execute_ata_cmd(device, fis, -1); in hisi_sas_softreset_ata_disk()
1330 dev_err(dev, "ata disk %016llx de-reset failed\n", in hisi_sas_softreset_ata_disk()
1331 SAS_ADDR(device->sas_addr)); in hisi_sas_softreset_ata_disk()
1335 SAS_ADDR(device->sas_addr)); in hisi_sas_softreset_ata_disk()
1339 hisi_sas_release_task(hisi_hba, device); in hisi_sas_softreset_ata_disk()
1346 u32 state = hisi_hba->hw->get_phys_state(hisi_hba); in hisi_sas_refresh_port_id()
1350 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i]; in hisi_sas_refresh_port_id()
1351 struct domain_device *device = sas_dev->sas_device; in hisi_sas_refresh_port_id() local
1354 struct hisi_sas_phy *phy = NULL; in hisi_sas_refresh_port_id() local
1357 if ((sas_dev->dev_type == SAS_PHY_UNUSED) in hisi_sas_refresh_port_id()
1358 || !device || !device->port) in hisi_sas_refresh_port_id()
1361 sas_port = device->port; in hisi_sas_refresh_port_id()
1364 spin_lock(&sas_port->phy_list_lock); in hisi_sas_refresh_port_id()
1365 list_for_each_entry(sas_phy, &sas_port->phy_list, port_phy_el) in hisi_sas_refresh_port_id()
1366 if (state & BIT(sas_phy->id)) { in hisi_sas_refresh_port_id()
1367 phy = sas_phy->lldd_phy; in hisi_sas_refresh_port_id()
1370 spin_unlock(&sas_port->phy_list_lock); in hisi_sas_refresh_port_id()
1372 if (phy) { in hisi_sas_refresh_port_id()
1373 port->id = phy->port_id; in hisi_sas_refresh_port_id()
1375 /* Update linkrate of directly attached device. */ in hisi_sas_refresh_port_id()
1376 if (!device->parent) in hisi_sas_refresh_port_id()
1377 device->linkrate = phy->sas_phy.linkrate; in hisi_sas_refresh_port_id()
1379 hisi_hba->hw->setup_itct(hisi_hba, sas_dev); in hisi_sas_refresh_port_id()
1380 } else if (!port->port_attached) in hisi_sas_refresh_port_id()
1381 port->id = 0xff; in hisi_sas_refresh_port_id()
1390 for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) { in hisi_sas_rescan_topology()
1391 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_rescan_topology() local
1392 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_rescan_topology()
1393 struct asd_sas_port *sas_port = sas_phy->port; in hisi_sas_rescan_topology()
1396 if (!sas_phy->phy->enabled) in hisi_sas_rescan_topology()
1399 /* Report PHY state change to libsas */ in hisi_sas_rescan_topology()
1401 if (do_port_check && sas_port && sas_port->port_dev) { in hisi_sas_rescan_topology()
1402 struct domain_device *dev = sas_port->port_dev; in hisi_sas_rescan_topology()
1406 if (dev_is_expander(dev->dev_type)) in hisi_sas_rescan_topology()
1420 struct domain_device *device; in hisi_sas_reset_init_all_devices() local
1424 sas_dev = &hisi_hba->devices[i]; in hisi_sas_reset_init_all_devices()
1425 device = sas_dev->sas_device; in hisi_sas_reset_init_all_devices()
1427 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device) in hisi_sas_reset_init_all_devices()
1430 hisi_sas_init_device(device); in hisi_sas_reset_init_all_devices()
1436 struct domain_device *device) in hisi_sas_send_ata_reset_each_phy() argument
1438 struct ata_port *ap = device->sata_dev.ap; in hisi_sas_send_ata_reset_each_phy()
1439 struct device *dev = hisi_hba->dev; in hisi_sas_send_ata_reset_each_phy()
1445 for (i = 0; i < hisi_hba->n_phy; i++) { in hisi_sas_send_ata_reset_each_phy()
1446 if (!(sas_port->phy_mask & BIT(i))) in hisi_sas_send_ata_reset_each_phy()
1452 hisi_sas_fill_ata_reset_cmd(link->device, 1, pmp, fis); in hisi_sas_send_ata_reset_each_phy()
1453 rc = sas_execute_ata_cmd(device, fis, i); in hisi_sas_send_ata_reset_each_phy()
1455 dev_err(dev, "phy%d ata reset failed rc=%d\n", in hisi_sas_send_ata_reset_each_phy()
1465 struct device *dev = hisi_hba->dev; in hisi_sas_terminate_stp_reject()
1469 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i]; in hisi_sas_terminate_stp_reject()
1470 struct domain_device *device = sas_dev->sas_device; in hisi_sas_terminate_stp_reject() local
1472 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device) in hisi_sas_terminate_stp_reject()
1480 for (port_no = 0; port_no < hisi_hba->n_phy; port_no++) { in hisi_sas_terminate_stp_reject()
1481 struct hisi_sas_port *port = &hisi_hba->port[port_no]; in hisi_sas_terminate_stp_reject()
1482 struct asd_sas_port *sas_port = &port->sas_port; in hisi_sas_terminate_stp_reject()
1483 struct domain_device *port_dev = sas_port->port_dev; in hisi_sas_terminate_stp_reject()
1484 struct domain_device *device; in hisi_sas_terminate_stp_reject() local
1486 if (!port_dev || !dev_is_expander(port_dev->dev_type)) in hisi_sas_terminate_stp_reject()
1489 /* Try to find a SATA device */ in hisi_sas_terminate_stp_reject()
1490 list_for_each_entry(device, &sas_port->dev_list, in hisi_sas_terminate_stp_reject()
1492 if (dev_is_sata(device)) { in hisi_sas_terminate_stp_reject()
1495 device); in hisi_sas_terminate_stp_reject()
1504 struct Scsi_Host *shost = hisi_hba->shost; in hisi_sas_controller_reset_prepare()
1506 hisi_hba->phy_state = hisi_hba->hw->get_phys_state(hisi_hba); in hisi_sas_controller_reset_prepare()
1509 hisi_hba->hw->wait_cmds_complete_timeout(hisi_hba, 100, 5000); in hisi_sas_controller_reset_prepare()
1512 * hisi_hba->timer is only used for v1/v2 hw, and check hw->sht in hisi_sas_controller_reset_prepare()
1515 if (hisi_hba->hw->sht) in hisi_sas_controller_reset_prepare()
1516 del_timer_sync(&hisi_hba->timer); in hisi_sas_controller_reset_prepare()
1518 set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); in hisi_sas_controller_reset_prepare()
1524 struct hisi_sas_phy *phy = data; in hisi_sas_async_init_wait_phyup() local
1525 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_async_init_wait_phyup()
1526 struct device *dev = hisi_hba->dev; in hisi_sas_async_init_wait_phyup()
1528 int phy_no = phy->sas_phy.id; in hisi_sas_async_init_wait_phyup()
1530 phy->reset_completion = &completion; in hisi_sas_async_init_wait_phyup()
1534 dev_warn(dev, "phy%d wait phyup timed out\n", phy_no); in hisi_sas_async_init_wait_phyup()
1536 phy->reset_completion = NULL; in hisi_sas_async_init_wait_phyup()
1541 struct Scsi_Host *shost = hisi_hba->shost; in hisi_sas_controller_reset_done()
1546 for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) { in hisi_sas_controller_reset_done()
1547 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_controller_reset_done() local
1549 if (!(hisi_hba->phy_state & BIT(phy_no))) in hisi_sas_controller_reset_done()
1553 phy, &async); in hisi_sas_controller_reset_done()
1558 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); in hisi_sas_controller_reset_done()
1560 if (hisi_hba->reject_stp_links_msk) in hisi_sas_controller_reset_done()
1564 clear_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags); in hisi_sas_controller_reset_done()
1565 up(&hisi_hba->sem); in hisi_sas_controller_reset_done()
1567 hisi_sas_rescan_topology(hisi_hba, hisi_hba->phy_state); in hisi_sas_controller_reset_done()
1573 if (!hisi_hba->hw->soft_reset) in hisi_sas_controller_prereset()
1574 return -ENOENT; in hisi_sas_controller_prereset()
1576 down(&hisi_hba->sem); in hisi_sas_controller_prereset()
1577 if (test_and_set_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags)) { in hisi_sas_controller_prereset()
1578 up(&hisi_hba->sem); in hisi_sas_controller_prereset()
1579 return -EPERM; in hisi_sas_controller_prereset()
1583 hisi_hba->hw->debugfs_snapshot_regs(hisi_hba); in hisi_sas_controller_prereset()
1590 struct device *dev = hisi_hba->dev; in hisi_sas_controller_reset()
1591 struct Scsi_Host *shost = hisi_hba->shost; in hisi_sas_controller_reset()
1597 rc = hisi_hba->hw->soft_reset(hisi_hba); in hisi_sas_controller_reset()
1600 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); in hisi_sas_controller_reset()
1601 up(&hisi_hba->sem); in hisi_sas_controller_reset()
1603 clear_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags); in hisi_sas_controller_reset()
1606 clear_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags); in hisi_sas_controller_reset()
1617 struct domain_device *device = task->dev; in hisi_sas_abort_task() local
1618 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_abort_task()
1619 struct hisi_sas_slot *slot = task->lldd_task; in hisi_sas_abort_task()
1621 struct device *dev; in hisi_sas_abort_task()
1628 hisi_hba = dev_to_hisi_hba(task->dev); in hisi_sas_abort_task()
1629 dev = hisi_hba->dev; in hisi_sas_abort_task()
1631 spin_lock_irqsave(&task->task_state_lock, flags); in hisi_sas_abort_task()
1632 if (task->task_state_flags & SAS_TASK_STATE_DONE) { in hisi_sas_abort_task()
1640 cq = &hisi_hba->cq[slot->dlvry_queue]; in hisi_sas_abort_task()
1643 spin_unlock_irqrestore(&task->task_state_lock, flags); in hisi_sas_abort_task()
1647 task->task_state_flags |= SAS_TASK_STATE_ABORTED; in hisi_sas_abort_task()
1648 spin_unlock_irqrestore(&task->task_state_lock, flags); in hisi_sas_abort_task()
1653 if (task->task_proto & SAS_PROTOCOL_SSP) { in hisi_sas_abort_task()
1654 u16 tag = slot->idx; in hisi_sas_abort_task()
1658 rc2 = sas_execute_internal_abort_single(device, tag, in hisi_sas_abort_task()
1659 slot->dlvry_queue, &internal_abort_data); in hisi_sas_abort_task()
1666 * If the TMF finds that the IO is not in the device and also in hisi_sas_abort_task()
1673 if (task->lldd_task) in hisi_sas_abort_task()
1676 } else if (task->task_proto & SAS_PROTOCOL_SATA || in hisi_sas_abort_task()
1677 task->task_proto & SAS_PROTOCOL_STP) { in hisi_sas_abort_task()
1678 if (task->dev->dev_type == SAS_SATA_DEV) { in hisi_sas_abort_task()
1679 struct ata_queued_cmd *qc = task->uldd_task; in hisi_sas_abort_task()
1686 hisi_sas_dereg_device(hisi_hba, device); in hisi_sas_abort_task()
1692 if ((sas_dev->dev_status == HISI_SAS_DEV_NCQ_ERR) && in hisi_sas_abort_task()
1693 qc && qc->scsicmd) { in hisi_sas_abort_task()
1697 rc = hisi_sas_softreset_ata_disk(device); in hisi_sas_abort_task()
1700 } else if (task->task_proto & SAS_PROTOCOL_SMP) { in hisi_sas_abort_task()
1702 u32 tag = slot->idx; in hisi_sas_abort_task()
1703 struct hisi_sas_cq *cq = &hisi_hba->cq[slot->dlvry_queue]; in hisi_sas_abort_task()
1705 rc = sas_execute_internal_abort_single(device, in hisi_sas_abort_task()
1706 tag, slot->dlvry_queue, in hisi_sas_abort_task()
1709 task->lldd_task) { in hisi_sas_abort_task()
1715 slot->task = NULL; in hisi_sas_abort_task()
1725 static int hisi_sas_abort_task_set(struct domain_device *device, u8 *lun) in hisi_sas_abort_task_set() argument
1727 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_abort_task_set()
1728 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_abort_task_set()
1729 struct device *dev = hisi_hba->dev; in hisi_sas_abort_task_set()
1737 hisi_sas_dereg_device(hisi_hba, device); in hisi_sas_abort_task_set()
1739 rc = sas_abort_task_set(device, lun); in hisi_sas_abort_task_set()
1741 hisi_sas_release_task(hisi_hba, device); in hisi_sas_abort_task_set()
1746 static int hisi_sas_debug_I_T_nexus_reset(struct domain_device *device) in hisi_sas_debug_I_T_nexus_reset() argument
1748 struct sas_phy *local_phy = sas_get_local_phy(device); in hisi_sas_debug_I_T_nexus_reset()
1749 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_debug_I_T_nexus_reset()
1750 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_debug_I_T_nexus_reset()
1751 struct sas_ha_struct *sas_ha = &hisi_hba->sha; in hisi_sas_debug_I_T_nexus_reset()
1754 if (!local_phy->enabled) { in hisi_sas_debug_I_T_nexus_reset()
1756 return -ENODEV; in hisi_sas_debug_I_T_nexus_reset()
1761 sas_ha->sas_phy[local_phy->number]; in hisi_sas_debug_I_T_nexus_reset()
1762 struct hisi_sas_phy *phy = in hisi_sas_debug_I_T_nexus_reset() local
1766 spin_lock_irqsave(&phy->lock, flags); in hisi_sas_debug_I_T_nexus_reset()
1767 phy->in_reset = 1; in hisi_sas_debug_I_T_nexus_reset()
1768 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_debug_I_T_nexus_reset()
1771 reset_type = (sas_dev->dev_status == HISI_SAS_DEV_INIT || in hisi_sas_debug_I_T_nexus_reset()
1772 !dev_is_sata(device)) ? true : false; in hisi_sas_debug_I_T_nexus_reset()
1779 sas_ha->sas_phy[local_phy->number]; in hisi_sas_debug_I_T_nexus_reset()
1780 struct hisi_sas_phy *phy = in hisi_sas_debug_I_T_nexus_reset() local
1784 spin_lock_irqsave(&phy->lock, flags); in hisi_sas_debug_I_T_nexus_reset()
1785 phy->in_reset = 0; in hisi_sas_debug_I_T_nexus_reset()
1786 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_debug_I_T_nexus_reset()
1788 /* report PHY down if timed out */ in hisi_sas_debug_I_T_nexus_reset()
1789 if (rc == -ETIMEDOUT) in hisi_sas_debug_I_T_nexus_reset()
1790 hisi_sas_phy_down(hisi_hba, sas_phy->id, 0, GFP_KERNEL); in hisi_sas_debug_I_T_nexus_reset()
1794 /* Remote phy */ in hisi_sas_debug_I_T_nexus_reset()
1798 if (dev_is_sata(device)) { in hisi_sas_debug_I_T_nexus_reset()
1799 struct ata_link *link = &device->sata_dev.ap->link; in hisi_sas_debug_I_T_nexus_reset()
1810 static int hisi_sas_I_T_nexus_reset(struct domain_device *device) in hisi_sas_I_T_nexus_reset() argument
1812 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_I_T_nexus_reset()
1813 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_I_T_nexus_reset()
1814 struct device *dev = hisi_hba->dev; in hisi_sas_I_T_nexus_reset()
1817 if (sas_dev->dev_status == HISI_SAS_DEV_NCQ_ERR) in hisi_sas_I_T_nexus_reset()
1818 sas_dev->dev_status = HISI_SAS_DEV_NORMAL; in hisi_sas_I_T_nexus_reset()
1825 hisi_sas_dereg_device(hisi_hba, device); in hisi_sas_I_T_nexus_reset()
1827 rc = hisi_sas_debug_I_T_nexus_reset(device); in hisi_sas_I_T_nexus_reset()
1828 if (rc == TMF_RESP_FUNC_COMPLETE && dev_is_sata(device)) { in hisi_sas_I_T_nexus_reset()
1831 rc = hisi_sas_softreset_ata_disk(device); in hisi_sas_I_T_nexus_reset()
1833 case -ECOMM: in hisi_sas_I_T_nexus_reset()
1834 rc = -ENODEV; in hisi_sas_I_T_nexus_reset()
1837 case -EMSGSIZE: in hisi_sas_I_T_nexus_reset()
1838 case -EIO: in hisi_sas_I_T_nexus_reset()
1839 local_phy = sas_get_local_phy(device); in hisi_sas_I_T_nexus_reset()
1842 local_phy->enabled = 0; in hisi_sas_I_T_nexus_reset()
1843 dev_err(dev, "Disabled local phy of ATA disk %016llx due to softreset fail (%d)\n", in hisi_sas_I_T_nexus_reset()
1844 SAS_ADDR(device->sas_addr), rc); in hisi_sas_I_T_nexus_reset()
1845 rc = -ENODEV; in hisi_sas_I_T_nexus_reset()
1854 if ((rc == TMF_RESP_FUNC_COMPLETE) || (rc == -ENODEV)) in hisi_sas_I_T_nexus_reset()
1855 hisi_sas_release_task(hisi_hba, device); in hisi_sas_I_T_nexus_reset()
1860 static int hisi_sas_lu_reset(struct domain_device *device, u8 *lun) in hisi_sas_lu_reset() argument
1862 struct hisi_sas_device *sas_dev = device->lldd_dev; in hisi_sas_lu_reset()
1863 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_lu_reset()
1864 struct device *dev = hisi_hba->dev; in hisi_sas_lu_reset()
1873 hisi_sas_dereg_device(hisi_hba, device); in hisi_sas_lu_reset()
1875 if (dev_is_sata(device)) { in hisi_sas_lu_reset()
1876 struct sas_phy *phy; in hisi_sas_lu_reset() local
1878 phy = sas_get_local_phy(device); in hisi_sas_lu_reset()
1880 rc = sas_phy_reset(phy, true); in hisi_sas_lu_reset()
1883 hisi_sas_release_task(hisi_hba, device); in hisi_sas_lu_reset()
1884 sas_put_local_phy(phy); in hisi_sas_lu_reset()
1886 rc = sas_lu_reset(device, lun); in hisi_sas_lu_reset()
1888 hisi_sas_release_task(hisi_hba, device); in hisi_sas_lu_reset()
1892 dev_err(dev, "lu_reset: for device[%d]:rc= %d\n", in hisi_sas_lu_reset()
1893 sas_dev->device_id, rc); in hisi_sas_lu_reset()
1899 struct domain_device *device = data; in hisi_sas_async_I_T_nexus_reset() local
1900 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_async_I_T_nexus_reset()
1903 rc = hisi_sas_debug_I_T_nexus_reset(device); in hisi_sas_async_I_T_nexus_reset()
1905 dev_info(hisi_hba->dev, "I_T_nexus reset fail for dev:%016llx rc=%d\n", in hisi_sas_async_I_T_nexus_reset()
1906 SAS_ADDR(device->sas_addr), rc); in hisi_sas_async_I_T_nexus_reset()
1911 struct hisi_hba *hisi_hba = sas_ha->lldd_ha; in hisi_sas_clear_nexus_ha()
1916 queue_work(hisi_hba->wq, &r.work); in hisi_sas_clear_nexus_ha()
1922 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i]; in hisi_sas_clear_nexus_ha()
1923 struct domain_device *device = sas_dev->sas_device; in hisi_sas_clear_nexus_ha() local
1925 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device || in hisi_sas_clear_nexus_ha()
1926 dev_is_expander(device->dev_type)) in hisi_sas_clear_nexus_ha()
1930 device, &async); in hisi_sas_clear_nexus_ha()
1943 if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) { in hisi_sas_query_task()
1944 struct hisi_sas_slot *slot = task->lldd_task; in hisi_sas_query_task()
1945 u32 tag = slot->idx; in hisi_sas_query_task()
1951 /* The task is not in Lun or failed, reset the phy */ in hisi_sas_query_task()
1966 struct domain_device *device = task->dev; in hisi_sas_internal_abort_timeout() local
1967 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); in hisi_sas_internal_abort_timeout()
1972 * If timeout occurs in device gone scenario, to avoid in hisi_sas_internal_abort_timeout()
1974 * hisi_sas_dev_gone() -> down() -> ... -> in hisi_sas_internal_abort_timeout()
1975 * hisi_sas_internal_abort_timeout() -> down(). in hisi_sas_internal_abort_timeout()
1977 if (!timeout->rst_ha_timeout) in hisi_sas_internal_abort_timeout()
1978 down(&hisi_hba->sem); in hisi_sas_internal_abort_timeout()
1979 hisi_hba->hw->debugfs_snapshot_regs(hisi_hba); in hisi_sas_internal_abort_timeout()
1980 if (!timeout->rst_ha_timeout) in hisi_sas_internal_abort_timeout()
1981 up(&hisi_hba->sem); in hisi_sas_internal_abort_timeout()
1984 if (task->task_state_flags & SAS_TASK_STATE_DONE) { in hisi_sas_internal_abort_timeout()
1986 SAS_ADDR(device->sas_addr)); in hisi_sas_internal_abort_timeout()
1988 struct hisi_sas_slot *slot = task->lldd_task; in hisi_sas_internal_abort_timeout()
1990 set_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags); in hisi_sas_internal_abort_timeout()
1994 &hisi_hba->cq[slot->dlvry_queue]; in hisi_sas_internal_abort_timeout()
2000 slot->task = NULL; in hisi_sas_internal_abort_timeout()
2003 if (timeout->rst_ha_timeout) { in hisi_sas_internal_abort_timeout()
2005 SAS_ADDR(device->sas_addr)); in hisi_sas_internal_abort_timeout()
2006 queue_work(hisi_hba->wq, &hisi_hba->rst_work); in hisi_sas_internal_abort_timeout()
2009 SAS_ADDR(device->sas_addr)); in hisi_sas_internal_abort_timeout()
2026 struct hisi_hba *hisi_hba = sha->lldd_ha; in hisi_sas_write_gpio()
2028 if (!hisi_hba->hw->write_gpio) in hisi_sas_write_gpio()
2029 return -EOPNOTSUPP; in hisi_sas_write_gpio()
2031 return hisi_hba->hw->write_gpio(hisi_hba, reg_type, in hisi_sas_write_gpio()
2035 static void hisi_sas_phy_disconnected(struct hisi_sas_phy *phy) in hisi_sas_phy_disconnected() argument
2037 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phy_disconnected()
2038 struct sas_phy *sphy = sas_phy->phy; in hisi_sas_phy_disconnected()
2041 phy->phy_attached = 0; in hisi_sas_phy_disconnected()
2042 phy->phy_type = 0; in hisi_sas_phy_disconnected()
2043 phy->port = NULL; in hisi_sas_phy_disconnected()
2045 spin_lock_irqsave(&phy->lock, flags); in hisi_sas_phy_disconnected()
2046 if (phy->enable) in hisi_sas_phy_disconnected()
2047 sphy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN; in hisi_sas_phy_disconnected()
2049 sphy->negotiated_linkrate = SAS_PHY_DISABLED; in hisi_sas_phy_disconnected()
2050 spin_unlock_irqrestore(&phy->lock, flags); in hisi_sas_phy_disconnected()
2056 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; in hisi_sas_phy_down() local
2057 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phy_down()
2058 struct device *dev = hisi_hba->dev; in hisi_sas_phy_down()
2061 /* Phy down but ready */ in hisi_sas_phy_down()
2065 struct hisi_sas_port *port = phy->port; in hisi_sas_phy_down()
2067 if (test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags) || in hisi_sas_phy_down()
2068 phy->in_reset) { in hisi_sas_phy_down()
2069 dev_info(dev, "ignore flutter phy%d down\n", phy_no); in hisi_sas_phy_down()
2072 /* Phy down and not ready */ in hisi_sas_phy_down()
2077 if (phy->phy_type & PORT_TYPE_SAS) { in hisi_sas_phy_down()
2078 int port_id = port->id; in hisi_sas_phy_down()
2080 if (!hisi_hba->hw->get_wideport_bitmap(hisi_hba, in hisi_sas_phy_down()
2082 port->port_attached = 0; in hisi_sas_phy_down()
2083 } else if (phy->phy_type & PORT_TYPE_SATA) in hisi_sas_phy_down()
2084 port->port_attached = 0; in hisi_sas_phy_down()
2086 hisi_sas_phy_disconnected(phy); in hisi_sas_phy_down()
2091 void hisi_sas_phy_bcast(struct hisi_sas_phy *phy) in hisi_sas_phy_bcast() argument
2093 struct asd_sas_phy *sas_phy = &phy->sas_phy; in hisi_sas_phy_bcast()
2094 struct hisi_hba *hisi_hba = phy->hisi_hba; in hisi_sas_phy_bcast()
2096 if (test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags)) in hisi_sas_phy_bcast()
2108 return -EOPNOTSUPP; in hisi_sas_host_reset()
2110 queue_work(hisi_hba->wq, &hisi_hba->rst_work); in hisi_sas_host_reset()
2139 struct hisi_sas_breakpoint *sata_breakpoint = hisi_hba->sata_breakpoint; in hisi_sas_init_mem()
2141 for (i = 0; i < hisi_hba->queue_count; i++) { in hisi_sas_init_mem()
2142 struct hisi_sas_cq *cq = &hisi_hba->cq[i]; in hisi_sas_init_mem()
2143 struct hisi_sas_dq *dq = &hisi_hba->dq[i]; in hisi_sas_init_mem()
2144 struct hisi_sas_cmd_hdr *cmd_hdr = hisi_hba->cmd_hdr[i]; in hisi_sas_init_mem()
2150 dq->wr_point = 0; in hisi_sas_init_mem()
2152 s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS; in hisi_sas_init_mem()
2153 memset(hisi_hba->complete_hdr[i], 0, s); in hisi_sas_init_mem()
2154 cq->rd_point = 0; in hisi_sas_init_mem()
2157 s = sizeof(struct hisi_sas_initial_fis) * hisi_hba->n_phy; in hisi_sas_init_mem()
2158 memset(hisi_hba->initial_fis, 0, s); in hisi_sas_init_mem()
2161 memset(hisi_hba->iost, 0, s); in hisi_sas_init_mem()
2164 memset(hisi_hba->breakpoint, 0, s); in hisi_sas_init_mem()
2174 struct device *dev = hisi_hba->dev; in hisi_sas_alloc()
2179 sema_init(&hisi_hba->sem, 1); in hisi_sas_alloc()
2180 spin_lock_init(&hisi_hba->lock); in hisi_sas_alloc()
2181 for (i = 0; i < hisi_hba->n_phy; i++) { in hisi_sas_alloc()
2183 hisi_hba->port[i].port_attached = 0; in hisi_sas_alloc()
2184 hisi_hba->port[i].id = -1; in hisi_sas_alloc()
2188 hisi_hba->devices[i].dev_type = SAS_PHY_UNUSED; in hisi_sas_alloc()
2189 hisi_hba->devices[i].device_id = i; in hisi_sas_alloc()
2190 hisi_hba->devices[i].dev_status = HISI_SAS_DEV_INIT; in hisi_sas_alloc()
2193 for (i = 0; i < hisi_hba->queue_count; i++) { in hisi_sas_alloc()
2194 struct hisi_sas_cq *cq = &hisi_hba->cq[i]; in hisi_sas_alloc()
2195 struct hisi_sas_dq *dq = &hisi_hba->dq[i]; in hisi_sas_alloc()
2198 cq->id = i; in hisi_sas_alloc()
2199 cq->hisi_hba = hisi_hba; in hisi_sas_alloc()
2200 spin_lock_init(&cq->poll_lock); in hisi_sas_alloc()
2203 spin_lock_init(&dq->lock); in hisi_sas_alloc()
2204 INIT_LIST_HEAD(&dq->list); in hisi_sas_alloc()
2205 dq->id = i; in hisi_sas_alloc()
2206 dq->hisi_hba = hisi_hba; in hisi_sas_alloc()
2210 hisi_hba->cmd_hdr[i] = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2211 &hisi_hba->cmd_hdr_dma[i], in hisi_sas_alloc()
2213 if (!hisi_hba->cmd_hdr[i]) in hisi_sas_alloc()
2217 s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS; in hisi_sas_alloc()
2218 hisi_hba->complete_hdr[i] = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2219 &hisi_hba->complete_hdr_dma[i], in hisi_sas_alloc()
2221 if (!hisi_hba->complete_hdr[i]) in hisi_sas_alloc()
2226 hisi_hba->itct = dmam_alloc_coherent(dev, s, &hisi_hba->itct_dma, in hisi_sas_alloc()
2228 if (!hisi_hba->itct) in hisi_sas_alloc()
2231 hisi_hba->slot_info = devm_kcalloc(dev, max_command_entries, in hisi_sas_alloc()
2234 if (!hisi_hba->slot_info) in hisi_sas_alloc()
2239 if (hisi_hba->prot_mask & HISI_SAS_DIX_PROT_MASK) in hisi_sas_alloc()
2261 slot = &hisi_hba->slot_info[slot_index]; in hisi_sas_alloc()
2262 slot->buf = buf; in hisi_sas_alloc()
2263 slot->buf_dma = buf_dma; in hisi_sas_alloc()
2264 slot->idx = slot_index; in hisi_sas_alloc()
2272 hisi_hba->iost = dmam_alloc_coherent(dev, s, &hisi_hba->iost_dma, in hisi_sas_alloc()
2274 if (!hisi_hba->iost) in hisi_sas_alloc()
2278 hisi_hba->breakpoint = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2279 &hisi_hba->breakpoint_dma, in hisi_sas_alloc()
2281 if (!hisi_hba->breakpoint) in hisi_sas_alloc()
2284 s = hisi_hba->slot_index_count = max_command_entries; in hisi_sas_alloc()
2285 hisi_hba->slot_index_tags = devm_bitmap_zalloc(dev, s, GFP_KERNEL); in hisi_sas_alloc()
2286 if (!hisi_hba->slot_index_tags) in hisi_sas_alloc()
2290 hisi_hba->initial_fis = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2291 &hisi_hba->initial_fis_dma, in hisi_sas_alloc()
2293 if (!hisi_hba->initial_fis) in hisi_sas_alloc()
2297 hisi_hba->sata_breakpoint = dmam_alloc_coherent(dev, s, in hisi_sas_alloc()
2298 &hisi_hba->sata_breakpoint_dma, in hisi_sas_alloc()
2300 if (!hisi_hba->sata_breakpoint) in hisi_sas_alloc()
2303 hisi_hba->last_slot_index = 0; in hisi_sas_alloc()
2305 hisi_hba->wq = in hisi_sas_alloc()
2307 if (!hisi_hba->wq) { in hisi_sas_alloc()
2314 return -ENOMEM; in hisi_sas_alloc()
2322 for (i = 0; i < hisi_hba->n_phy; i++) { in hisi_sas_free()
2323 struct hisi_sas_phy *phy = &hisi_hba->phy[i]; in hisi_sas_free() local
2325 del_timer_sync(&phy->timer); in hisi_sas_free()
2328 if (hisi_hba->wq) in hisi_sas_free()
2329 destroy_workqueue(hisi_hba->wq); in hisi_sas_free()
2350 if (hisi_sas_controller_prereset(rst->hisi_hba)) in hisi_sas_sync_rst_work_handler()
2353 if (!hisi_sas_controller_reset(rst->hisi_hba)) in hisi_sas_sync_rst_work_handler()
2354 rst->done = true; in hisi_sas_sync_rst_work_handler()
2356 complete(rst->completion); in hisi_sas_sync_rst_work_handler()
2362 struct device *dev = hisi_hba->dev; in hisi_sas_get_fw_info()
2363 struct platform_device *pdev = hisi_hba->platform_dev; in hisi_sas_get_fw_info()
2364 struct device_node *np = pdev ? pdev->dev.of_node : NULL; in hisi_sas_get_fw_info()
2367 if (device_property_read_u8_array(dev, "sas-addr", hisi_hba->sas_addr, in hisi_sas_get_fw_info()
2369 dev_err(dev, "could not get property sas-addr\n"); in hisi_sas_get_fw_info()
2370 return -ENOENT; in hisi_sas_get_fw_info()
2375 * These properties are only required for platform device-based in hisi_sas_get_fw_info()
2378 hisi_hba->ctrl = syscon_regmap_lookup_by_phandle(np, in hisi_sas_get_fw_info()
2379 "hisilicon,sas-syscon"); in hisi_sas_get_fw_info()
2380 if (IS_ERR(hisi_hba->ctrl)) { in hisi_sas_get_fw_info()
2382 return -ENOENT; in hisi_sas_get_fw_info()
2385 if (device_property_read_u32(dev, "ctrl-reset-reg", in hisi_sas_get_fw_info()
2386 &hisi_hba->ctrl_reset_reg)) { in hisi_sas_get_fw_info()
2387 dev_err(dev, "could not get property ctrl-reset-reg\n"); in hisi_sas_get_fw_info()
2388 return -ENOENT; in hisi_sas_get_fw_info()
2391 if (device_property_read_u32(dev, "ctrl-reset-sts-reg", in hisi_sas_get_fw_info()
2392 &hisi_hba->ctrl_reset_sts_reg)) { in hisi_sas_get_fw_info()
2393 dev_err(dev, "could not get property ctrl-reset-sts-reg\n"); in hisi_sas_get_fw_info()
2394 return -ENOENT; in hisi_sas_get_fw_info()
2397 if (device_property_read_u32(dev, "ctrl-clock-ena-reg", in hisi_sas_get_fw_info()
2398 &hisi_hba->ctrl_clock_ena_reg)) { in hisi_sas_get_fw_info()
2399 dev_err(dev, "could not get property ctrl-clock-ena-reg\n"); in hisi_sas_get_fw_info()
2400 return -ENOENT; in hisi_sas_get_fw_info()
2408 hisi_hba->refclk_frequency_mhz = clk_get_rate(refclk) / 1000000; in hisi_sas_get_fw_info()
2410 if (device_property_read_u32(dev, "phy-count", &hisi_hba->n_phy)) { in hisi_sas_get_fw_info()
2411 dev_err(dev, "could not get property phy-count\n"); in hisi_sas_get_fw_info()
2412 return -ENOENT; in hisi_sas_get_fw_info()
2415 if (device_property_read_u32(dev, "queue-count", in hisi_sas_get_fw_info()
2416 &hisi_hba->queue_count)) { in hisi_sas_get_fw_info()
2417 dev_err(dev, "could not get property queue-count\n"); in hisi_sas_get_fw_info()
2418 return -ENOENT; in hisi_sas_get_fw_info()
2431 struct device *dev = &pdev->dev; in hisi_sas_shost_alloc()
2434 shost = scsi_host_alloc(hw->sht, sizeof(*hisi_hba)); in hisi_sas_shost_alloc()
2441 INIT_WORK(&hisi_hba->rst_work, hisi_sas_rst_work_handler); in hisi_sas_shost_alloc()
2442 hisi_hba->hw = hw; in hisi_sas_shost_alloc()
2443 hisi_hba->dev = dev; in hisi_sas_shost_alloc()
2444 hisi_hba->platform_dev = pdev; in hisi_sas_shost_alloc()
2445 hisi_hba->shost = shost; in hisi_sas_shost_alloc()
2446 SHOST_TO_SAS_HA(shost) = &hisi_hba->sha; in hisi_sas_shost_alloc()
2448 timer_setup(&hisi_hba->timer, NULL, 0); in hisi_sas_shost_alloc()
2459 hisi_hba->regs = devm_platform_ioremap_resource(pdev, 0); in hisi_sas_shost_alloc()
2460 if (IS_ERR(hisi_hba->regs)) in hisi_sas_shost_alloc()
2465 hisi_hba->sgpio_regs = devm_ioremap_resource(dev, res); in hisi_sas_shost_alloc()
2466 if (IS_ERR(hisi_hba->sgpio_regs)) in hisi_sas_shost_alloc()
2484 if (hisi_hba->hw->interrupt_preinit) in hisi_sas_interrupt_preinit()
2485 return hisi_hba->hw->interrupt_preinit(hisi_hba); in hisi_sas_interrupt_preinit()
2494 struct device *dev = &pdev->dev; in hisi_sas_probe()
2502 return -ENOMEM; in hisi_sas_probe()
2508 phy_nr = port_nr = hisi_hba->n_phy; in hisi_sas_probe()
2513 rc = -ENOMEM; in hisi_sas_probe()
2517 sha->sas_phy = arr_phy; in hisi_sas_probe()
2518 sha->sas_port = arr_port; in hisi_sas_probe()
2519 sha->lldd_ha = hisi_hba; in hisi_sas_probe()
2521 shost->transportt = hisi_sas_stt; in hisi_sas_probe()
2522 shost->max_id = HISI_SAS_MAX_DEVICES; in hisi_sas_probe()
2523 shost->max_lun = ~0; in hisi_sas_probe()
2524 shost->max_channel = 1; in hisi_sas_probe()
2525 shost->max_cmd_len = 16; in hisi_sas_probe()
2526 if (hisi_hba->hw->slot_index_alloc) { in hisi_sas_probe()
2527 shost->can_queue = HISI_SAS_MAX_COMMANDS; in hisi_sas_probe()
2528 shost->cmd_per_lun = HISI_SAS_MAX_COMMANDS; in hisi_sas_probe()
2530 shost->can_queue = HISI_SAS_UNRESERVED_IPTT; in hisi_sas_probe()
2531 shost->cmd_per_lun = HISI_SAS_UNRESERVED_IPTT; in hisi_sas_probe()
2534 sha->sas_ha_name = DRV_NAME; in hisi_sas_probe()
2535 sha->dev = hisi_hba->dev; in hisi_sas_probe()
2536 sha->sas_addr = &hisi_hba->sas_addr[0]; in hisi_sas_probe()
2537 sha->num_phys = hisi_hba->n_phy; in hisi_sas_probe()
2538 sha->shost = hisi_hba->shost; in hisi_sas_probe()
2540 for (i = 0; i < hisi_hba->n_phy; i++) { in hisi_sas_probe()
2541 sha->sas_phy[i] = &hisi_hba->phy[i].sas_phy; in hisi_sas_probe()
2542 sha->sas_port[i] = &hisi_hba->port[i].sas_port; in hisi_sas_probe()
2549 rc = scsi_add_host(shost, &pdev->dev); in hisi_sas_probe()
2557 rc = hisi_hba->hw->hw_init(hisi_hba); in hisi_sas_probe()
2579 struct hisi_hba *hisi_hba = sha->lldd_ha; in hisi_sas_remove()
2580 struct Scsi_Host *shost = sha->shost; in hisi_sas_remove()
2582 del_timer_sync(&hisi_hba->timer); in hisi_sas_remove()
2618 return -ENOMEM; in hisi_sas_init()