1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2015 Linaro Ltd.
4 * Copyright (c) 2015 Hisilicon Limited.
8 #define DRV_NAME "hisi_sas"
10 #define DEV_IS_GONE(dev) \
11 ((!dev) || (dev->dev_type == SAS_PHY_UNUSED))
13 static int hisi_sas_debug_issue_ssp_tmf(struct domain_device *device,
14 u8 *lun, struct hisi_sas_tmf_task *tmf);
16 hisi_sas_internal_task_abort(struct hisi_hba *hisi_hba,
17 struct domain_device *device,
18 int abort_flag, int tag, bool rst_to_recover);
19 static int hisi_sas_softreset_ata_disk(struct domain_device *device);
20 static int hisi_sas_control_phy(struct asd_sas_phy *sas_phy, enum phy_func func,
22 static void hisi_sas_release_task(struct hisi_hba *hisi_hba,
23 struct domain_device *device);
24 static void hisi_sas_dev_gone(struct domain_device *device);
26 u8 hisi_sas_get_ata_protocol(struct host_to_dev_fis *fis, int direction)
28 switch (fis->command) {
29 case ATA_CMD_FPDMA_WRITE:
30 case ATA_CMD_FPDMA_READ:
31 case ATA_CMD_FPDMA_RECV:
32 case ATA_CMD_FPDMA_SEND:
33 case ATA_CMD_NCQ_NON_DATA:
34 return HISI_SAS_SATA_PROTOCOL_FPDMA;
36 case ATA_CMD_DOWNLOAD_MICRO:
38 case ATA_CMD_PMP_READ:
39 case ATA_CMD_READ_LOG_EXT:
40 case ATA_CMD_PIO_READ:
41 case ATA_CMD_PIO_READ_EXT:
42 case ATA_CMD_PMP_WRITE:
43 case ATA_CMD_WRITE_LOG_EXT:
44 case ATA_CMD_PIO_WRITE:
45 case ATA_CMD_PIO_WRITE_EXT:
46 return HISI_SAS_SATA_PROTOCOL_PIO;
49 case ATA_CMD_DOWNLOAD_MICRO_DMA:
50 case ATA_CMD_PMP_READ_DMA:
51 case ATA_CMD_PMP_WRITE_DMA:
53 case ATA_CMD_READ_EXT:
54 case ATA_CMD_READ_LOG_DMA_EXT:
55 case ATA_CMD_READ_STREAM_DMA_EXT:
56 case ATA_CMD_TRUSTED_RCV_DMA:
57 case ATA_CMD_TRUSTED_SND_DMA:
59 case ATA_CMD_WRITE_EXT:
60 case ATA_CMD_WRITE_FUA_EXT:
61 case ATA_CMD_WRITE_QUEUED:
62 case ATA_CMD_WRITE_LOG_DMA_EXT:
63 case ATA_CMD_WRITE_STREAM_DMA_EXT:
64 case ATA_CMD_ZAC_MGMT_IN:
65 return HISI_SAS_SATA_PROTOCOL_DMA;
67 case ATA_CMD_CHK_POWER:
68 case ATA_CMD_DEV_RESET:
71 case ATA_CMD_FLUSH_EXT:
73 case ATA_CMD_VERIFY_EXT:
74 case ATA_CMD_SET_FEATURES:
76 case ATA_CMD_STANDBYNOW1:
77 case ATA_CMD_ZAC_MGMT_OUT:
78 return HISI_SAS_SATA_PROTOCOL_NONDATA;
81 switch (fis->features) {
82 case ATA_SET_MAX_PASSWD:
83 case ATA_SET_MAX_LOCK:
84 return HISI_SAS_SATA_PROTOCOL_PIO;
86 case ATA_SET_MAX_PASSWD_DMA:
87 case ATA_SET_MAX_UNLOCK_DMA:
88 return HISI_SAS_SATA_PROTOCOL_DMA;
91 return HISI_SAS_SATA_PROTOCOL_NONDATA;
96 if (direction == DMA_NONE)
97 return HISI_SAS_SATA_PROTOCOL_NONDATA;
98 return HISI_SAS_SATA_PROTOCOL_PIO;
102 EXPORT_SYMBOL_GPL(hisi_sas_get_ata_protocol);
104 void hisi_sas_sata_done(struct sas_task *task,
105 struct hisi_sas_slot *slot)
107 struct task_status_struct *ts = &task->task_status;
108 struct ata_task_resp *resp = (struct ata_task_resp *)ts->buf;
109 struct hisi_sas_status_buffer *status_buf =
110 hisi_sas_status_buf_addr_mem(slot);
111 u8 *iu = &status_buf->iu[0];
112 struct dev_to_host_fis *d2h = (struct dev_to_host_fis *)iu;
114 resp->frame_len = sizeof(struct dev_to_host_fis);
115 memcpy(&resp->ending_fis[0], d2h, sizeof(struct dev_to_host_fis));
117 ts->buf_valid_size = sizeof(*resp);
119 EXPORT_SYMBOL_GPL(hisi_sas_sata_done);
122 * This function assumes linkrate mask fits in 8 bits, which it
123 * does for all HW versions supported.
125 u8 hisi_sas_get_prog_phy_linkrate_mask(enum sas_linkrate max)
130 max -= SAS_LINK_RATE_1_5_GBPS;
131 for (i = 0; i <= max; i++)
132 rate |= 1 << (i * 2);
135 EXPORT_SYMBOL_GPL(hisi_sas_get_prog_phy_linkrate_mask);
137 static struct hisi_hba *dev_to_hisi_hba(struct domain_device *device)
139 return device->port->ha->lldd_ha;
142 struct hisi_sas_port *to_hisi_sas_port(struct asd_sas_port *sas_port)
144 return container_of(sas_port, struct hisi_sas_port, sas_port);
146 EXPORT_SYMBOL_GPL(to_hisi_sas_port);
148 void hisi_sas_stop_phys(struct hisi_hba *hisi_hba)
152 for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++)
153 hisi_sas_phy_enable(hisi_hba, phy_no, 0);
155 EXPORT_SYMBOL_GPL(hisi_sas_stop_phys);
157 static void hisi_sas_slot_index_clear(struct hisi_hba *hisi_hba, int slot_idx)
159 void *bitmap = hisi_hba->slot_index_tags;
161 __clear_bit(slot_idx, bitmap);
164 static void hisi_sas_slot_index_free(struct hisi_hba *hisi_hba, int slot_idx)
166 if (hisi_hba->hw->slot_index_alloc ||
167 slot_idx >= HISI_SAS_UNRESERVED_IPTT) {
168 spin_lock(&hisi_hba->lock);
169 hisi_sas_slot_index_clear(hisi_hba, slot_idx);
170 spin_unlock(&hisi_hba->lock);
174 static void hisi_sas_slot_index_set(struct hisi_hba *hisi_hba, int slot_idx)
176 void *bitmap = hisi_hba->slot_index_tags;
178 __set_bit(slot_idx, bitmap);
181 static int hisi_sas_slot_index_alloc(struct hisi_hba *hisi_hba,
182 struct scsi_cmnd *scsi_cmnd)
185 void *bitmap = hisi_hba->slot_index_tags;
188 return scsi_cmd_to_rq(scsi_cmnd)->tag;
190 spin_lock(&hisi_hba->lock);
191 index = find_next_zero_bit(bitmap, hisi_hba->slot_index_count,
192 hisi_hba->last_slot_index + 1);
193 if (index >= hisi_hba->slot_index_count) {
194 index = find_next_zero_bit(bitmap,
195 hisi_hba->slot_index_count,
196 HISI_SAS_UNRESERVED_IPTT);
197 if (index >= hisi_hba->slot_index_count) {
198 spin_unlock(&hisi_hba->lock);
199 return -SAS_QUEUE_FULL;
202 hisi_sas_slot_index_set(hisi_hba, index);
203 hisi_hba->last_slot_index = index;
204 spin_unlock(&hisi_hba->lock);
209 void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, struct sas_task *task,
210 struct hisi_sas_slot *slot)
212 int device_id = slot->device_id;
213 struct hisi_sas_device *sas_dev = &hisi_hba->devices[device_id];
216 struct device *dev = hisi_hba->dev;
218 if (!task->lldd_task)
221 task->lldd_task = NULL;
223 if (!sas_protocol_ata(task->task_proto)) {
225 dma_unmap_sg(dev, task->scatter,
228 if (slot->n_elem_dif) {
229 struct sas_ssp_task *ssp_task = &task->ssp_task;
230 struct scsi_cmnd *scsi_cmnd = ssp_task->cmd;
232 dma_unmap_sg(dev, scsi_prot_sglist(scsi_cmnd),
233 scsi_prot_sg_count(scsi_cmnd),
239 spin_lock(&sas_dev->lock);
240 list_del_init(&slot->entry);
241 spin_unlock(&sas_dev->lock);
243 memset(slot, 0, offsetof(struct hisi_sas_slot, buf));
245 hisi_sas_slot_index_free(hisi_hba, slot->idx);
247 EXPORT_SYMBOL_GPL(hisi_sas_slot_task_free);
249 static void hisi_sas_task_prep_smp(struct hisi_hba *hisi_hba,
250 struct hisi_sas_slot *slot)
252 hisi_hba->hw->prep_smp(hisi_hba, slot);
255 static void hisi_sas_task_prep_ssp(struct hisi_hba *hisi_hba,
256 struct hisi_sas_slot *slot)
258 hisi_hba->hw->prep_ssp(hisi_hba, slot);
261 static void hisi_sas_task_prep_ata(struct hisi_hba *hisi_hba,
262 struct hisi_sas_slot *slot)
264 hisi_hba->hw->prep_stp(hisi_hba, slot);
267 static void hisi_sas_task_prep_abort(struct hisi_hba *hisi_hba,
268 struct hisi_sas_internal_abort *abort,
269 struct hisi_sas_slot *slot, int device_id)
271 hisi_hba->hw->prep_abort(hisi_hba, slot,
272 device_id, abort->flag, abort->tag);
275 static void hisi_sas_dma_unmap(struct hisi_hba *hisi_hba,
276 struct sas_task *task, int n_elem,
279 struct device *dev = hisi_hba->dev;
281 if (!sas_protocol_ata(task->task_proto)) {
282 if (task->num_scatter) {
284 dma_unmap_sg(dev, task->scatter,
287 } else if (task->task_proto & SAS_PROTOCOL_SMP) {
289 dma_unmap_sg(dev, &task->smp_task.smp_req,
295 static int hisi_sas_dma_map(struct hisi_hba *hisi_hba,
296 struct sas_task *task, int *n_elem,
299 struct device *dev = hisi_hba->dev;
302 if (sas_protocol_ata(task->task_proto)) {
303 *n_elem = task->num_scatter;
305 unsigned int req_len;
307 if (task->num_scatter) {
308 *n_elem = dma_map_sg(dev, task->scatter,
309 task->num_scatter, task->data_dir);
314 } else if (task->task_proto & SAS_PROTOCOL_SMP) {
315 *n_elem_req = dma_map_sg(dev, &task->smp_task.smp_req,
321 req_len = sg_dma_len(&task->smp_task.smp_req);
324 goto err_out_dma_unmap;
329 if (*n_elem > HISI_SAS_SGE_PAGE_CNT) {
330 dev_err(dev, "task prep: n_elem(%d) > HISI_SAS_SGE_PAGE_CNT\n",
333 goto err_out_dma_unmap;
338 /* It would be better to call dma_unmap_sg() here, but it's messy */
339 hisi_sas_dma_unmap(hisi_hba, task, *n_elem,
345 static void hisi_sas_dif_dma_unmap(struct hisi_hba *hisi_hba,
346 struct sas_task *task, int n_elem_dif)
348 struct device *dev = hisi_hba->dev;
351 struct sas_ssp_task *ssp_task = &task->ssp_task;
352 struct scsi_cmnd *scsi_cmnd = ssp_task->cmd;
354 dma_unmap_sg(dev, scsi_prot_sglist(scsi_cmnd),
355 scsi_prot_sg_count(scsi_cmnd),
360 static int hisi_sas_dif_dma_map(struct hisi_hba *hisi_hba,
361 int *n_elem_dif, struct sas_task *task)
363 struct device *dev = hisi_hba->dev;
364 struct sas_ssp_task *ssp_task;
365 struct scsi_cmnd *scsi_cmnd;
368 if (task->num_scatter) {
369 ssp_task = &task->ssp_task;
370 scsi_cmnd = ssp_task->cmd;
372 if (scsi_prot_sg_count(scsi_cmnd)) {
373 *n_elem_dif = dma_map_sg(dev,
374 scsi_prot_sglist(scsi_cmnd),
375 scsi_prot_sg_count(scsi_cmnd),
381 if (*n_elem_dif > HISI_SAS_SGE_DIF_PAGE_CNT) {
382 dev_err(dev, "task prep: n_elem_dif(%d) too large\n",
385 goto err_out_dif_dma_unmap;
392 err_out_dif_dma_unmap:
393 dma_unmap_sg(dev, scsi_prot_sglist(scsi_cmnd),
394 scsi_prot_sg_count(scsi_cmnd), task->data_dir);
399 void hisi_sas_task_deliver(struct hisi_hba *hisi_hba,
400 struct hisi_sas_slot *slot,
401 struct hisi_sas_dq *dq,
402 struct hisi_sas_device *sas_dev,
403 struct hisi_sas_internal_abort *abort,
404 struct hisi_sas_tmf_task *tmf)
406 struct hisi_sas_cmd_hdr *cmd_hdr_base;
407 int dlvry_queue_slot, dlvry_queue;
408 struct sas_task *task = slot->task;
412 spin_lock(&dq->lock);
413 wr_q_index = dq->wr_point;
414 dq->wr_point = (dq->wr_point + 1) % HISI_SAS_QUEUE_SLOTS;
415 list_add_tail(&slot->delivery, &dq->list);
416 spin_unlock(&dq->lock);
417 spin_lock(&sas_dev->lock);
418 list_add_tail(&slot->entry, &sas_dev->list);
419 spin_unlock(&sas_dev->lock);
421 dlvry_queue = dq->id;
422 dlvry_queue_slot = wr_q_index;
424 slot->device_id = sas_dev->device_id;
425 slot->dlvry_queue = dlvry_queue;
426 slot->dlvry_queue_slot = dlvry_queue_slot;
427 cmd_hdr_base = hisi_hba->cmd_hdr[dlvry_queue];
428 slot->cmd_hdr = &cmd_hdr_base[dlvry_queue_slot];
431 slot->is_internal = tmf;
432 task->lldd_task = slot;
434 memset(slot->cmd_hdr, 0, sizeof(struct hisi_sas_cmd_hdr));
435 memset(hisi_sas_cmd_hdr_addr_mem(slot), 0, HISI_SAS_COMMAND_TABLE_SZ);
436 memset(hisi_sas_status_buf_addr_mem(slot), 0,
437 sizeof(struct hisi_sas_err_record));
439 switch (task->task_proto) {
440 case SAS_PROTOCOL_SMP:
441 hisi_sas_task_prep_smp(hisi_hba, slot);
443 case SAS_PROTOCOL_SSP:
444 hisi_sas_task_prep_ssp(hisi_hba, slot);
446 case SAS_PROTOCOL_SATA:
447 case SAS_PROTOCOL_STP:
448 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
449 hisi_sas_task_prep_ata(hisi_hba, slot);
451 case SAS_PROTOCOL_NONE:
453 hisi_sas_task_prep_abort(hisi_hba, abort, slot, sas_dev->device_id);
458 dev_err(hisi_hba->dev, "task prep: unknown/unsupported proto (0x%x)\n",
463 spin_lock_irqsave(&task->task_state_lock, flags);
464 task->task_state_flags |= SAS_TASK_AT_INITIATOR;
465 spin_unlock_irqrestore(&task->task_state_lock, flags);
467 WRITE_ONCE(slot->ready, 1);
469 spin_lock(&dq->lock);
470 hisi_hba->hw->start_delivery(dq);
471 spin_unlock(&dq->lock);
474 static int hisi_sas_task_exec(struct sas_task *task, gfp_t gfp_flags,
475 struct hisi_sas_tmf_task *tmf)
477 int n_elem = 0, n_elem_dif = 0, n_elem_req = 0;
478 struct domain_device *device = task->dev;
479 struct asd_sas_port *sas_port = device->port;
480 struct hisi_sas_device *sas_dev = device->lldd_dev;
481 struct scsi_cmnd *scmd = NULL;
482 struct hisi_sas_dq *dq = NULL;
483 struct hisi_sas_port *port;
484 struct hisi_hba *hisi_hba;
485 struct hisi_sas_slot *slot;
490 struct task_status_struct *ts = &task->task_status;
492 ts->resp = SAS_TASK_UNDELIVERED;
493 ts->stat = SAS_PHY_DOWN;
495 * libsas will use dev->port, should
496 * not call task_done for sata
498 if (device->dev_type != SAS_SATA_DEV)
499 task->task_done(task);
503 hisi_hba = dev_to_hisi_hba(device);
506 if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags))) {
507 if (!gfpflags_allow_blocking(gfp_flags))
510 down(&hisi_hba->sem);
514 if (DEV_IS_GONE(sas_dev)) {
516 dev_info(dev, "task prep: device %d not ready\n",
519 dev_info(dev, "task prep: device %016llx not ready\n",
520 SAS_ADDR(device->sas_addr));
525 if (task->uldd_task) {
526 struct ata_queued_cmd *qc;
528 if (dev_is_sata(device)) {
529 qc = task->uldd_task;
532 scmd = task->uldd_task;
537 unsigned int dq_index;
540 blk_tag = blk_mq_unique_tag(scsi_cmd_to_rq(scmd));
541 dq_index = blk_mq_unique_tag_to_hwq(blk_tag);
542 dq = &hisi_hba->dq[dq_index];
544 struct Scsi_Host *shost = hisi_hba->shost;
545 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
546 int queue = qmap->mq_map[raw_smp_processor_id()];
548 dq = &hisi_hba->dq[queue];
551 port = to_hisi_sas_port(sas_port);
552 if (port && !port->port_attached) {
553 dev_info(dev, "task prep: %s port%d not attach device\n",
554 (dev_is_sata(device)) ?
561 rc = hisi_sas_dma_map(hisi_hba, task, &n_elem,
566 if (!sas_protocol_ata(task->task_proto)) {
567 rc = hisi_sas_dif_dma_map(hisi_hba, &n_elem_dif, task);
569 goto err_out_dma_unmap;
572 if (hisi_hba->hw->slot_index_alloc)
573 rc = hisi_hba->hw->slot_index_alloc(hisi_hba, device);
575 rc = hisi_sas_slot_index_alloc(hisi_hba, scmd);
578 goto err_out_dif_dma_unmap;
580 slot = &hisi_hba->slot_info[rc];
581 slot->n_elem = n_elem;
582 slot->n_elem_dif = n_elem_dif;
587 slot->is_internal = tmf;
589 /* protect task_prep and start_delivery sequence */
590 hisi_sas_task_deliver(hisi_hba, slot, dq, sas_dev, NULL, tmf);
594 err_out_dif_dma_unmap:
595 if (!sas_protocol_ata(task->task_proto))
596 hisi_sas_dif_dma_unmap(hisi_hba, task, n_elem_dif);
598 hisi_sas_dma_unmap(hisi_hba, task, n_elem,
601 dev_err(dev, "task exec: failed[%d]!\n", rc);
605 static void hisi_sas_bytes_dmaed(struct hisi_hba *hisi_hba, int phy_no,
608 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
609 struct asd_sas_phy *sas_phy = &phy->sas_phy;
611 if (!phy->phy_attached)
614 sas_notify_phy_event(sas_phy, PHYE_OOB_DONE, gfp_flags);
617 struct sas_phy *sphy = sas_phy->phy;
619 sphy->negotiated_linkrate = sas_phy->linkrate;
620 sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
621 sphy->maximum_linkrate_hw =
622 hisi_hba->hw->phy_get_max_linkrate();
623 if (sphy->minimum_linkrate == SAS_LINK_RATE_UNKNOWN)
624 sphy->minimum_linkrate = phy->minimum_linkrate;
626 if (sphy->maximum_linkrate == SAS_LINK_RATE_UNKNOWN)
627 sphy->maximum_linkrate = phy->maximum_linkrate;
630 if (phy->phy_type & PORT_TYPE_SAS) {
631 struct sas_identify_frame *id;
633 id = (struct sas_identify_frame *)phy->frame_rcvd;
634 id->dev_type = phy->identify.device_type;
635 id->initiator_bits = SAS_PROTOCOL_ALL;
636 id->target_bits = phy->identify.target_port_protocols;
637 } else if (phy->phy_type & PORT_TYPE_SATA) {
641 sas_phy->frame_rcvd_size = phy->frame_rcvd_size;
642 sas_notify_port_event(sas_phy, PORTE_BYTES_DMAED, gfp_flags);
645 static struct hisi_sas_device *hisi_sas_alloc_dev(struct domain_device *device)
647 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
648 struct hisi_sas_device *sas_dev = NULL;
649 int last = hisi_hba->last_dev_id;
650 int first = (hisi_hba->last_dev_id + 1) % HISI_SAS_MAX_DEVICES;
653 spin_lock(&hisi_hba->lock);
654 for (i = first; i != last; i %= HISI_SAS_MAX_DEVICES) {
655 if (hisi_hba->devices[i].dev_type == SAS_PHY_UNUSED) {
656 int queue = i % hisi_hba->queue_count;
657 struct hisi_sas_dq *dq = &hisi_hba->dq[queue];
659 hisi_hba->devices[i].device_id = i;
660 sas_dev = &hisi_hba->devices[i];
661 sas_dev->dev_status = HISI_SAS_DEV_INIT;
662 sas_dev->dev_type = device->dev_type;
663 sas_dev->hisi_hba = hisi_hba;
664 sas_dev->sas_device = device;
666 spin_lock_init(&sas_dev->lock);
667 INIT_LIST_HEAD(&hisi_hba->devices[i].list);
672 hisi_hba->last_dev_id = i;
673 spin_unlock(&hisi_hba->lock);
678 #define HISI_SAS_DISK_RECOVER_CNT 3
679 static int hisi_sas_init_device(struct domain_device *device)
681 int rc = TMF_RESP_FUNC_COMPLETE;
683 struct hisi_sas_tmf_task tmf_task;
684 int retry = HISI_SAS_DISK_RECOVER_CNT;
685 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
686 struct device *dev = hisi_hba->dev;
687 struct sas_phy *local_phy;
689 switch (device->dev_type) {
691 int_to_scsilun(0, &lun);
693 tmf_task.tmf = TMF_CLEAR_TASK_SET;
694 while (retry-- > 0) {
695 rc = hisi_sas_debug_issue_ssp_tmf(device, lun.scsi_lun,
697 if (rc == TMF_RESP_FUNC_COMPLETE) {
698 hisi_sas_release_task(hisi_hba, device);
705 case SAS_SATA_PM_PORT:
706 case SAS_SATA_PENDING:
708 * send HARD RESET to clear previous affiliation of
711 local_phy = sas_get_local_phy(device);
712 if (!scsi_is_sas_phy_local(local_phy) &&
713 !test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags)) {
714 unsigned long deadline = ata_deadline(jiffies, 20000);
715 struct sata_device *sata_dev = &device->sata_dev;
716 struct ata_host *ata_host = sata_dev->ata_host;
717 struct ata_port_operations *ops = ata_host->ops;
718 struct ata_port *ap = sata_dev->ap;
719 struct ata_link *link;
720 unsigned int classes;
722 ata_for_each_link(link, ap, EDGE)
723 rc = ops->hardreset(link, &classes,
726 sas_put_local_phy(local_phy);
728 dev_warn(dev, "SATA disk hardreset fail: %d\n", rc);
732 while (retry-- > 0) {
733 rc = hisi_sas_softreset_ata_disk(device);
745 int hisi_sas_slave_alloc(struct scsi_device *sdev)
747 struct domain_device *ddev;
750 rc = sas_slave_alloc(sdev);
753 ddev = sdev_to_domain_dev(sdev);
755 return hisi_sas_init_device(ddev);
757 EXPORT_SYMBOL_GPL(hisi_sas_slave_alloc);
759 static int hisi_sas_dev_found(struct domain_device *device)
761 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
762 struct domain_device *parent_dev = device->parent;
763 struct hisi_sas_device *sas_dev;
764 struct device *dev = hisi_hba->dev;
767 if (hisi_hba->hw->alloc_dev)
768 sas_dev = hisi_hba->hw->alloc_dev(device);
770 sas_dev = hisi_sas_alloc_dev(device);
772 dev_err(dev, "fail alloc dev: max support %d devices\n",
773 HISI_SAS_MAX_DEVICES);
777 device->lldd_dev = sas_dev;
778 hisi_hba->hw->setup_itct(hisi_hba, sas_dev);
780 if (parent_dev && dev_is_expander(parent_dev->dev_type)) {
782 u8 phy_num = parent_dev->ex_dev.num_phys;
785 for (phy_no = 0; phy_no < phy_num; phy_no++) {
786 phy = &parent_dev->ex_dev.ex_phy[phy_no];
787 if (SAS_ADDR(phy->attached_sas_addr) ==
788 SAS_ADDR(device->sas_addr))
792 if (phy_no == phy_num) {
793 dev_info(dev, "dev found: no attached "
794 "dev:%016llx at ex:%016llx\n",
795 SAS_ADDR(device->sas_addr),
796 SAS_ADDR(parent_dev->sas_addr));
802 dev_info(dev, "dev[%d:%x] found\n",
803 sas_dev->device_id, sas_dev->dev_type);
805 sas_dev->dev_status = HISI_SAS_DEV_NORMAL;
809 hisi_sas_dev_gone(device);
813 int hisi_sas_slave_configure(struct scsi_device *sdev)
815 struct domain_device *dev = sdev_to_domain_dev(sdev);
816 int ret = sas_slave_configure(sdev);
820 if (!dev_is_sata(dev))
821 sas_change_queue_depth(sdev, 64);
825 EXPORT_SYMBOL_GPL(hisi_sas_slave_configure);
827 void hisi_sas_scan_start(struct Scsi_Host *shost)
829 struct hisi_hba *hisi_hba = shost_priv(shost);
831 hisi_hba->hw->phys_init(hisi_hba);
833 EXPORT_SYMBOL_GPL(hisi_sas_scan_start);
835 int hisi_sas_scan_finished(struct Scsi_Host *shost, unsigned long time)
837 struct hisi_hba *hisi_hba = shost_priv(shost);
838 struct sas_ha_struct *sha = &hisi_hba->sha;
840 /* Wait for PHY up interrupt to occur */
847 EXPORT_SYMBOL_GPL(hisi_sas_scan_finished);
849 static void hisi_sas_phyup_work_common(struct work_struct *work,
850 enum hisi_sas_phy_event event)
852 struct hisi_sas_phy *phy =
853 container_of(work, typeof(*phy), works[event]);
854 struct hisi_hba *hisi_hba = phy->hisi_hba;
855 struct asd_sas_phy *sas_phy = &phy->sas_phy;
856 int phy_no = sas_phy->id;
858 phy->wait_phyup_cnt = 0;
859 if (phy->identify.target_port_protocols == SAS_PROTOCOL_SSP)
860 hisi_hba->hw->sl_notify_ssp(hisi_hba, phy_no);
861 hisi_sas_bytes_dmaed(hisi_hba, phy_no, GFP_KERNEL);
864 static void hisi_sas_phyup_work(struct work_struct *work)
866 hisi_sas_phyup_work_common(work, HISI_PHYE_PHY_UP);
869 static void hisi_sas_linkreset_work(struct work_struct *work)
871 struct hisi_sas_phy *phy =
872 container_of(work, typeof(*phy), works[HISI_PHYE_LINK_RESET]);
873 struct asd_sas_phy *sas_phy = &phy->sas_phy;
875 hisi_sas_control_phy(sas_phy, PHY_FUNC_LINK_RESET, NULL);
878 static void hisi_sas_phyup_pm_work(struct work_struct *work)
880 struct hisi_sas_phy *phy =
881 container_of(work, typeof(*phy), works[HISI_PHYE_PHY_UP_PM]);
882 struct hisi_hba *hisi_hba = phy->hisi_hba;
883 struct device *dev = hisi_hba->dev;
885 hisi_sas_phyup_work_common(work, HISI_PHYE_PHY_UP_PM);
886 pm_runtime_put_sync(dev);
889 static const work_func_t hisi_sas_phye_fns[HISI_PHYES_NUM] = {
890 [HISI_PHYE_PHY_UP] = hisi_sas_phyup_work,
891 [HISI_PHYE_LINK_RESET] = hisi_sas_linkreset_work,
892 [HISI_PHYE_PHY_UP_PM] = hisi_sas_phyup_pm_work,
895 bool hisi_sas_notify_phy_event(struct hisi_sas_phy *phy,
896 enum hisi_sas_phy_event event)
898 struct hisi_hba *hisi_hba = phy->hisi_hba;
900 if (WARN_ON(event >= HISI_PHYES_NUM))
903 return queue_work(hisi_hba->wq, &phy->works[event]);
905 EXPORT_SYMBOL_GPL(hisi_sas_notify_phy_event);
907 static void hisi_sas_wait_phyup_timedout(struct timer_list *t)
909 struct hisi_sas_phy *phy = from_timer(phy, t, timer);
910 struct hisi_hba *hisi_hba = phy->hisi_hba;
911 struct device *dev = hisi_hba->dev;
912 int phy_no = phy->sas_phy.id;
914 dev_warn(dev, "phy%d wait phyup timeout, issuing link reset\n", phy_no);
915 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
918 #define HISI_SAS_WAIT_PHYUP_RETRIES 10
920 void hisi_sas_phy_oob_ready(struct hisi_hba *hisi_hba, int phy_no)
922 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
923 struct device *dev = hisi_hba->dev;
926 dev_dbg(dev, "phy%d OOB ready\n", phy_no);
927 spin_lock_irqsave(&phy->lock, flags);
928 if (phy->phy_attached) {
929 spin_unlock_irqrestore(&phy->lock, flags);
933 if (!timer_pending(&phy->timer)) {
934 if (phy->wait_phyup_cnt < HISI_SAS_WAIT_PHYUP_RETRIES) {
935 phy->wait_phyup_cnt++;
936 phy->timer.expires = jiffies +
937 HISI_SAS_WAIT_PHYUP_TIMEOUT;
938 add_timer(&phy->timer);
939 spin_unlock_irqrestore(&phy->lock, flags);
943 dev_warn(dev, "phy%d failed to come up %d times, giving up\n",
944 phy_no, phy->wait_phyup_cnt);
945 phy->wait_phyup_cnt = 0;
947 spin_unlock_irqrestore(&phy->lock, flags);
950 EXPORT_SYMBOL_GPL(hisi_sas_phy_oob_ready);
952 static void hisi_sas_phy_init(struct hisi_hba *hisi_hba, int phy_no)
954 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
955 struct asd_sas_phy *sas_phy = &phy->sas_phy;
958 phy->hisi_hba = hisi_hba;
960 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
961 phy->maximum_linkrate = hisi_hba->hw->phy_get_max_linkrate();
962 sas_phy->enabled = (phy_no < hisi_hba->n_phy) ? 1 : 0;
963 sas_phy->class = SAS;
964 sas_phy->iproto = SAS_PROTOCOL_ALL;
966 sas_phy->type = PHY_TYPE_PHYSICAL;
967 sas_phy->role = PHY_ROLE_INITIATOR;
968 sas_phy->oob_mode = OOB_NOT_CONNECTED;
969 sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN;
970 sas_phy->id = phy_no;
971 sas_phy->sas_addr = &hisi_hba->sas_addr[0];
972 sas_phy->frame_rcvd = &phy->frame_rcvd[0];
973 sas_phy->ha = (struct sas_ha_struct *)hisi_hba->shost->hostdata;
974 sas_phy->lldd_phy = phy;
976 for (i = 0; i < HISI_PHYES_NUM; i++)
977 INIT_WORK(&phy->works[i], hisi_sas_phye_fns[i]);
979 spin_lock_init(&phy->lock);
981 timer_setup(&phy->timer, hisi_sas_wait_phyup_timedout, 0);
984 /* Wrapper to ensure we track hisi_sas_phy.enable properly */
985 void hisi_sas_phy_enable(struct hisi_hba *hisi_hba, int phy_no, int enable)
987 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
988 struct asd_sas_phy *aphy = &phy->sas_phy;
989 struct sas_phy *sphy = aphy->phy;
992 spin_lock_irqsave(&phy->lock, flags);
995 /* We may have been enabled already; if so, don't touch */
997 sphy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
998 hisi_hba->hw->phy_start(hisi_hba, phy_no);
1000 sphy->negotiated_linkrate = SAS_PHY_DISABLED;
1001 hisi_hba->hw->phy_disable(hisi_hba, phy_no);
1003 phy->enable = enable;
1004 spin_unlock_irqrestore(&phy->lock, flags);
1006 EXPORT_SYMBOL_GPL(hisi_sas_phy_enable);
1008 static void hisi_sas_port_notify_formed(struct asd_sas_phy *sas_phy)
1010 struct sas_ha_struct *sas_ha = sas_phy->ha;
1011 struct hisi_hba *hisi_hba = sas_ha->lldd_ha;
1012 struct hisi_sas_phy *phy = sas_phy->lldd_phy;
1013 struct asd_sas_port *sas_port = sas_phy->port;
1014 struct hisi_sas_port *port;
1015 unsigned long flags;
1020 port = to_hisi_sas_port(sas_port);
1021 spin_lock_irqsave(&hisi_hba->lock, flags);
1022 port->port_attached = 1;
1023 port->id = phy->port_id;
1025 sas_port->lldd_port = port;
1026 spin_unlock_irqrestore(&hisi_hba->lock, flags);
1029 static void hisi_sas_do_release_task(struct hisi_hba *hisi_hba, struct sas_task *task,
1030 struct hisi_sas_slot *slot)
1033 unsigned long flags;
1034 struct task_status_struct *ts;
1036 ts = &task->task_status;
1038 ts->resp = SAS_TASK_COMPLETE;
1039 ts->stat = SAS_ABORTED_TASK;
1040 spin_lock_irqsave(&task->task_state_lock, flags);
1041 task->task_state_flags &=
1042 ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR);
1043 if (!slot->is_internal && task->task_proto != SAS_PROTOCOL_SMP)
1044 task->task_state_flags |= SAS_TASK_STATE_DONE;
1045 spin_unlock_irqrestore(&task->task_state_lock, flags);
1048 hisi_sas_slot_task_free(hisi_hba, task, slot);
1051 static void hisi_sas_release_task(struct hisi_hba *hisi_hba,
1052 struct domain_device *device)
1054 struct hisi_sas_slot *slot, *slot2;
1055 struct hisi_sas_device *sas_dev = device->lldd_dev;
1057 list_for_each_entry_safe(slot, slot2, &sas_dev->list, entry)
1058 hisi_sas_do_release_task(hisi_hba, slot->task, slot);
1061 void hisi_sas_release_tasks(struct hisi_hba *hisi_hba)
1063 struct hisi_sas_device *sas_dev;
1064 struct domain_device *device;
1067 for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
1068 sas_dev = &hisi_hba->devices[i];
1069 device = sas_dev->sas_device;
1071 if ((sas_dev->dev_type == SAS_PHY_UNUSED) ||
1075 hisi_sas_release_task(hisi_hba, device);
1078 EXPORT_SYMBOL_GPL(hisi_sas_release_tasks);
1080 static void hisi_sas_dereg_device(struct hisi_hba *hisi_hba,
1081 struct domain_device *device)
1083 if (hisi_hba->hw->dereg_device)
1084 hisi_hba->hw->dereg_device(hisi_hba, device);
1087 static void hisi_sas_dev_gone(struct domain_device *device)
1089 struct hisi_sas_device *sas_dev = device->lldd_dev;
1090 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1091 struct device *dev = hisi_hba->dev;
1094 dev_info(dev, "dev[%d:%x] is gone\n",
1095 sas_dev->device_id, sas_dev->dev_type);
1097 down(&hisi_hba->sem);
1098 if (!test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags)) {
1099 hisi_sas_internal_task_abort(hisi_hba, device,
1100 HISI_SAS_INT_ABT_DEV, 0, true);
1102 hisi_sas_dereg_device(hisi_hba, device);
1104 ret = hisi_hba->hw->clear_itct(hisi_hba, sas_dev);
1105 device->lldd_dev = NULL;
1108 if (hisi_hba->hw->free_device)
1109 hisi_hba->hw->free_device(sas_dev);
1111 /* Don't mark it as SAS_PHY_UNUSED if failed to clear ITCT */
1113 sas_dev->dev_type = SAS_PHY_UNUSED;
1114 sas_dev->sas_device = NULL;
1118 static int hisi_sas_queue_command(struct sas_task *task, gfp_t gfp_flags)
1120 return hisi_sas_task_exec(task, gfp_flags, NULL);
1123 static int hisi_sas_phy_set_linkrate(struct hisi_hba *hisi_hba, int phy_no,
1124 struct sas_phy_linkrates *r)
1126 struct sas_phy_linkrates _r;
1128 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1129 struct asd_sas_phy *sas_phy = &phy->sas_phy;
1130 enum sas_linkrate min, max;
1132 if (r->minimum_linkrate > SAS_LINK_RATE_1_5_GBPS)
1135 if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) {
1136 max = sas_phy->phy->maximum_linkrate;
1137 min = r->minimum_linkrate;
1138 } else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) {
1139 max = r->maximum_linkrate;
1140 min = sas_phy->phy->minimum_linkrate;
1144 _r.maximum_linkrate = max;
1145 _r.minimum_linkrate = min;
1147 sas_phy->phy->maximum_linkrate = max;
1148 sas_phy->phy->minimum_linkrate = min;
1150 hisi_sas_phy_enable(hisi_hba, phy_no, 0);
1152 hisi_hba->hw->phy_set_linkrate(hisi_hba, phy_no, &_r);
1153 hisi_sas_phy_enable(hisi_hba, phy_no, 1);
1158 static int hisi_sas_control_phy(struct asd_sas_phy *sas_phy, enum phy_func func,
1161 struct hisi_sas_phy *phy = container_of(sas_phy,
1162 struct hisi_sas_phy, sas_phy);
1163 struct sas_ha_struct *sas_ha = sas_phy->ha;
1164 struct hisi_hba *hisi_hba = sas_ha->lldd_ha;
1165 struct device *dev = hisi_hba->dev;
1166 DECLARE_COMPLETION_ONSTACK(completion);
1167 int phy_no = sas_phy->id;
1168 u8 sts = phy->phy_attached;
1171 down(&hisi_hba->sem);
1172 phy->reset_completion = &completion;
1175 case PHY_FUNC_HARD_RESET:
1176 hisi_hba->hw->phy_hard_reset(hisi_hba, phy_no);
1179 case PHY_FUNC_LINK_RESET:
1180 hisi_sas_phy_enable(hisi_hba, phy_no, 0);
1182 hisi_sas_phy_enable(hisi_hba, phy_no, 1);
1185 case PHY_FUNC_DISABLE:
1186 hisi_sas_phy_enable(hisi_hba, phy_no, 0);
1189 case PHY_FUNC_SET_LINK_RATE:
1190 ret = hisi_sas_phy_set_linkrate(hisi_hba, phy_no, funcdata);
1193 case PHY_FUNC_GET_EVENTS:
1194 if (hisi_hba->hw->get_events) {
1195 hisi_hba->hw->get_events(hisi_hba, phy_no);
1199 case PHY_FUNC_RELEASE_SPINUP_HOLD:
1205 if (sts && !wait_for_completion_timeout(&completion, 2 * HZ)) {
1206 dev_warn(dev, "phy%d wait phyup timed out for func %d\n",
1213 phy->reset_completion = NULL;
1219 static void hisi_sas_task_done(struct sas_task *task)
1221 del_timer_sync(&task->slow_task->timer);
1222 complete(&task->slow_task->completion);
1225 static void hisi_sas_tmf_timedout(struct timer_list *t)
1227 struct sas_task_slow *slow = from_timer(slow, t, timer);
1228 struct sas_task *task = slow->task;
1229 unsigned long flags;
1230 bool is_completed = true;
1232 spin_lock_irqsave(&task->task_state_lock, flags);
1233 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
1234 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
1235 is_completed = false;
1237 spin_unlock_irqrestore(&task->task_state_lock, flags);
1240 complete(&task->slow_task->completion);
1243 #define TASK_TIMEOUT (20 * HZ)
1244 #define TASK_RETRY 3
1245 #define INTERNAL_ABORT_TIMEOUT (6 * HZ)
1246 static int hisi_sas_exec_internal_tmf_task(struct domain_device *device,
1247 void *parameter, u32 para_len,
1248 struct hisi_sas_tmf_task *tmf)
1250 struct hisi_sas_device *sas_dev = device->lldd_dev;
1251 struct hisi_hba *hisi_hba = sas_dev->hisi_hba;
1252 struct device *dev = hisi_hba->dev;
1253 struct sas_task *task;
1256 for (retry = 0; retry < TASK_RETRY; retry++) {
1257 task = sas_alloc_slow_task(GFP_KERNEL);
1262 task->task_proto = device->tproto;
1264 if (dev_is_sata(device)) {
1265 task->ata_task.device_control_reg_update = 1;
1266 memcpy(&task->ata_task.fis, parameter, para_len);
1268 memcpy(&task->ssp_task, parameter, para_len);
1270 task->task_done = hisi_sas_task_done;
1272 task->slow_task->timer.function = hisi_sas_tmf_timedout;
1273 task->slow_task->timer.expires = jiffies + TASK_TIMEOUT;
1274 add_timer(&task->slow_task->timer);
1276 res = hisi_sas_task_exec(task, GFP_KERNEL, tmf);
1278 del_timer_sync(&task->slow_task->timer);
1279 dev_err(dev, "abort tmf: executing internal task failed: %d\n",
1284 wait_for_completion(&task->slow_task->completion);
1285 res = TMF_RESP_FUNC_FAILED;
1286 /* Even TMF timed out, return direct. */
1287 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
1288 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
1289 struct hisi_sas_slot *slot = task->lldd_task;
1291 dev_err(dev, "abort tmf: TMF task timeout and not done\n");
1293 struct hisi_sas_cq *cq =
1294 &hisi_hba->cq[slot->dlvry_queue];
1296 * sync irq to avoid free'ing task
1297 * before using task in IO completion
1299 synchronize_irq(cq->irq_no);
1305 dev_err(dev, "abort tmf: TMF task timeout\n");
1308 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1309 task->task_status.stat == TMF_RESP_FUNC_COMPLETE) {
1310 res = TMF_RESP_FUNC_COMPLETE;
1314 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1315 task->task_status.stat == TMF_RESP_FUNC_SUCC) {
1316 res = TMF_RESP_FUNC_SUCC;
1320 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1321 task->task_status.stat == SAS_DATA_UNDERRUN) {
1322 /* no error, but return the number of bytes of
1325 dev_warn(dev, "abort tmf: task to dev %016llx resp: 0x%x sts 0x%x underrun\n",
1326 SAS_ADDR(device->sas_addr),
1327 task->task_status.resp,
1328 task->task_status.stat);
1329 res = task->task_status.residual;
1333 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1334 task->task_status.stat == SAS_DATA_OVERRUN) {
1335 dev_warn(dev, "abort tmf: blocked task error\n");
1340 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1341 task->task_status.stat == SAS_OPEN_REJECT) {
1342 dev_warn(dev, "abort tmf: open reject failed\n");
1345 dev_warn(dev, "abort tmf: task to dev %016llx resp: 0x%x status 0x%x\n",
1346 SAS_ADDR(device->sas_addr),
1347 task->task_status.resp,
1348 task->task_status.stat);
1350 sas_free_task(task);
1354 if (retry == TASK_RETRY)
1355 dev_warn(dev, "abort tmf: executing internal task failed!\n");
1356 sas_free_task(task);
1360 static void hisi_sas_fill_ata_reset_cmd(struct ata_device *dev,
1361 bool reset, int pmp, u8 *fis)
1363 struct ata_taskfile tf;
1365 ata_tf_init(dev, &tf);
1369 tf.ctl &= ~ATA_SRST;
1370 tf.command = ATA_CMD_DEV_RESET;
1371 ata_tf_to_fis(&tf, pmp, 0, fis);
1374 static int hisi_sas_softreset_ata_disk(struct domain_device *device)
1377 struct ata_port *ap = device->sata_dev.ap;
1378 struct ata_link *link;
1379 int rc = TMF_RESP_FUNC_FAILED;
1380 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1381 struct device *dev = hisi_hba->dev;
1382 int s = sizeof(struct host_to_dev_fis);
1384 ata_for_each_link(link, ap, EDGE) {
1385 int pmp = sata_srst_pmp(link);
1387 hisi_sas_fill_ata_reset_cmd(link->device, 1, pmp, fis);
1388 rc = hisi_sas_exec_internal_tmf_task(device, fis, s, NULL);
1389 if (rc != TMF_RESP_FUNC_COMPLETE)
1393 if (rc == TMF_RESP_FUNC_COMPLETE) {
1394 ata_for_each_link(link, ap, EDGE) {
1395 int pmp = sata_srst_pmp(link);
1397 hisi_sas_fill_ata_reset_cmd(link->device, 0, pmp, fis);
1398 rc = hisi_sas_exec_internal_tmf_task(device, fis,
1400 if (rc != TMF_RESP_FUNC_COMPLETE)
1401 dev_err(dev, "ata disk %016llx de-reset failed\n",
1402 SAS_ADDR(device->sas_addr));
1405 dev_err(dev, "ata disk %016llx reset failed\n",
1406 SAS_ADDR(device->sas_addr));
1409 if (rc == TMF_RESP_FUNC_COMPLETE)
1410 hisi_sas_release_task(hisi_hba, device);
1415 static int hisi_sas_debug_issue_ssp_tmf(struct domain_device *device,
1416 u8 *lun, struct hisi_sas_tmf_task *tmf)
1418 struct sas_ssp_task ssp_task;
1420 if (!(device->tproto & SAS_PROTOCOL_SSP))
1421 return TMF_RESP_FUNC_ESUPP;
1423 memcpy(ssp_task.LUN, lun, 8);
1425 return hisi_sas_exec_internal_tmf_task(device, &ssp_task,
1426 sizeof(ssp_task), tmf);
1429 static void hisi_sas_refresh_port_id(struct hisi_hba *hisi_hba)
1431 u32 state = hisi_hba->hw->get_phys_state(hisi_hba);
1434 for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
1435 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i];
1436 struct domain_device *device = sas_dev->sas_device;
1437 struct asd_sas_port *sas_port;
1438 struct hisi_sas_port *port;
1439 struct hisi_sas_phy *phy = NULL;
1440 struct asd_sas_phy *sas_phy;
1442 if ((sas_dev->dev_type == SAS_PHY_UNUSED)
1443 || !device || !device->port)
1446 sas_port = device->port;
1447 port = to_hisi_sas_port(sas_port);
1449 spin_lock(&sas_port->phy_list_lock);
1450 list_for_each_entry(sas_phy, &sas_port->phy_list, port_phy_el)
1451 if (state & BIT(sas_phy->id)) {
1452 phy = sas_phy->lldd_phy;
1455 spin_unlock(&sas_port->phy_list_lock);
1458 port->id = phy->port_id;
1460 /* Update linkrate of directly attached device. */
1461 if (!device->parent)
1462 device->linkrate = phy->sas_phy.linkrate;
1464 hisi_hba->hw->setup_itct(hisi_hba, sas_dev);
1470 static void hisi_sas_rescan_topology(struct hisi_hba *hisi_hba, u32 state)
1472 struct asd_sas_port *_sas_port = NULL;
1475 for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) {
1476 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1477 struct asd_sas_phy *sas_phy = &phy->sas_phy;
1478 struct asd_sas_port *sas_port = sas_phy->port;
1479 bool do_port_check = _sas_port != sas_port;
1481 if (!sas_phy->phy->enabled)
1484 /* Report PHY state change to libsas */
1485 if (state & BIT(phy_no)) {
1486 if (do_port_check && sas_port && sas_port->port_dev) {
1487 struct domain_device *dev = sas_port->port_dev;
1489 _sas_port = sas_port;
1491 if (dev_is_expander(dev->dev_type))
1492 sas_notify_port_event(sas_phy,
1493 PORTE_BROADCAST_RCVD,
1497 hisi_sas_phy_down(hisi_hba, phy_no, 0, GFP_KERNEL);
1502 static void hisi_sas_reset_init_all_devices(struct hisi_hba *hisi_hba)
1504 struct hisi_sas_device *sas_dev;
1505 struct domain_device *device;
1508 for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
1509 sas_dev = &hisi_hba->devices[i];
1510 device = sas_dev->sas_device;
1512 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device)
1515 hisi_sas_init_device(device);
1519 static void hisi_sas_send_ata_reset_each_phy(struct hisi_hba *hisi_hba,
1520 struct asd_sas_port *sas_port,
1521 struct domain_device *device)
1523 struct hisi_sas_tmf_task tmf_task = { .force_phy = 1 };
1524 struct ata_port *ap = device->sata_dev.ap;
1525 struct device *dev = hisi_hba->dev;
1526 int s = sizeof(struct host_to_dev_fis);
1527 int rc = TMF_RESP_FUNC_FAILED;
1528 struct ata_link *link;
1532 for (i = 0; i < hisi_hba->n_phy; i++) {
1533 if (!(sas_port->phy_mask & BIT(i)))
1536 ata_for_each_link(link, ap, EDGE) {
1537 int pmp = sata_srst_pmp(link);
1539 tmf_task.phy_id = i;
1540 hisi_sas_fill_ata_reset_cmd(link->device, 1, pmp, fis);
1541 rc = hisi_sas_exec_internal_tmf_task(device, fis, s,
1543 if (rc != TMF_RESP_FUNC_COMPLETE) {
1544 dev_err(dev, "phy%d ata reset failed rc=%d\n",
1552 static void hisi_sas_terminate_stp_reject(struct hisi_hba *hisi_hba)
1554 struct device *dev = hisi_hba->dev;
1557 for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
1558 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i];
1559 struct domain_device *device = sas_dev->sas_device;
1561 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device)
1564 rc = hisi_sas_internal_task_abort(hisi_hba, device,
1565 HISI_SAS_INT_ABT_DEV, 0,
1568 dev_err(dev, "STP reject: abort dev failed %d\n", rc);
1571 for (port_no = 0; port_no < hisi_hba->n_phy; port_no++) {
1572 struct hisi_sas_port *port = &hisi_hba->port[port_no];
1573 struct asd_sas_port *sas_port = &port->sas_port;
1574 struct domain_device *port_dev = sas_port->port_dev;
1575 struct domain_device *device;
1577 if (!port_dev || !dev_is_expander(port_dev->dev_type))
1580 /* Try to find a SATA device */
1581 list_for_each_entry(device, &sas_port->dev_list,
1583 if (dev_is_sata(device)) {
1584 hisi_sas_send_ata_reset_each_phy(hisi_hba,
1593 void hisi_sas_controller_reset_prepare(struct hisi_hba *hisi_hba)
1595 struct Scsi_Host *shost = hisi_hba->shost;
1597 hisi_hba->phy_state = hisi_hba->hw->get_phys_state(hisi_hba);
1599 scsi_block_requests(shost);
1600 hisi_hba->hw->wait_cmds_complete_timeout(hisi_hba, 100, 5000);
1602 del_timer_sync(&hisi_hba->timer);
1604 set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
1606 EXPORT_SYMBOL_GPL(hisi_sas_controller_reset_prepare);
1608 void hisi_sas_controller_reset_done(struct hisi_hba *hisi_hba)
1610 struct Scsi_Host *shost = hisi_hba->shost;
1612 /* Init and wait for PHYs to come up and all libsas event finished. */
1613 hisi_hba->hw->phys_init(hisi_hba);
1615 hisi_sas_refresh_port_id(hisi_hba);
1616 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
1618 if (hisi_hba->reject_stp_links_msk)
1619 hisi_sas_terminate_stp_reject(hisi_hba);
1620 hisi_sas_reset_init_all_devices(hisi_hba);
1621 scsi_unblock_requests(shost);
1622 clear_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags);
1625 hisi_sas_rescan_topology(hisi_hba, hisi_hba->phy_state);
1627 EXPORT_SYMBOL_GPL(hisi_sas_controller_reset_done);
1629 static int hisi_sas_controller_prereset(struct hisi_hba *hisi_hba)
1631 if (!hisi_hba->hw->soft_reset)
1634 down(&hisi_hba->sem);
1635 if (test_and_set_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags)) {
1640 if (hisi_sas_debugfs_enable && hisi_hba->debugfs_itct[0].itct)
1641 hisi_hba->hw->debugfs_snapshot_regs(hisi_hba);
1646 static int hisi_sas_controller_reset(struct hisi_hba *hisi_hba)
1648 struct device *dev = hisi_hba->dev;
1649 struct Scsi_Host *shost = hisi_hba->shost;
1652 dev_info(dev, "controller resetting...\n");
1653 hisi_sas_controller_reset_prepare(hisi_hba);
1655 rc = hisi_hba->hw->soft_reset(hisi_hba);
1657 dev_warn(dev, "controller reset failed (%d)\n", rc);
1658 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
1660 scsi_unblock_requests(shost);
1661 clear_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags);
1665 hisi_sas_controller_reset_done(hisi_hba);
1666 clear_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags);
1667 dev_info(dev, "controller reset complete\n");
1672 static int hisi_sas_abort_task(struct sas_task *task)
1674 struct scsi_lun lun;
1675 struct hisi_sas_tmf_task tmf_task;
1676 struct domain_device *device = task->dev;
1677 struct hisi_sas_device *sas_dev = device->lldd_dev;
1678 struct hisi_hba *hisi_hba;
1680 int rc = TMF_RESP_FUNC_FAILED;
1681 unsigned long flags;
1684 return TMF_RESP_FUNC_FAILED;
1686 hisi_hba = dev_to_hisi_hba(task->dev);
1687 dev = hisi_hba->dev;
1689 spin_lock_irqsave(&task->task_state_lock, flags);
1690 if (task->task_state_flags & SAS_TASK_STATE_DONE) {
1691 struct hisi_sas_slot *slot = task->lldd_task;
1692 struct hisi_sas_cq *cq;
1696 * sync irq to avoid free'ing task
1697 * before using task in IO completion
1699 cq = &hisi_hba->cq[slot->dlvry_queue];
1700 synchronize_irq(cq->irq_no);
1702 spin_unlock_irqrestore(&task->task_state_lock, flags);
1703 rc = TMF_RESP_FUNC_COMPLETE;
1706 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
1707 spin_unlock_irqrestore(&task->task_state_lock, flags);
1709 if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) {
1710 struct scsi_cmnd *cmnd = task->uldd_task;
1711 struct hisi_sas_slot *slot = task->lldd_task;
1712 u16 tag = slot->idx;
1715 int_to_scsilun(cmnd->device->lun, &lun);
1716 tmf_task.tmf = TMF_ABORT_TASK;
1717 tmf_task.tag_of_task_to_be_managed = tag;
1719 rc = hisi_sas_debug_issue_ssp_tmf(task->dev, lun.scsi_lun,
1722 rc2 = hisi_sas_internal_task_abort(hisi_hba, device,
1723 HISI_SAS_INT_ABT_CMD, tag,
1726 dev_err(dev, "abort task: internal abort (%d)\n", rc2);
1727 return TMF_RESP_FUNC_FAILED;
1731 * If the TMF finds that the IO is not in the device and also
1732 * the internal abort does not succeed, then it is safe to
1734 * Note: if the internal abort succeeds then the slot
1735 * will have already been completed
1737 if (rc == TMF_RESP_FUNC_COMPLETE && rc2 != TMF_RESP_FUNC_SUCC) {
1738 if (task->lldd_task)
1739 hisi_sas_do_release_task(hisi_hba, task, slot);
1741 } else if (task->task_proto & SAS_PROTOCOL_SATA ||
1742 task->task_proto & SAS_PROTOCOL_STP) {
1743 if (task->dev->dev_type == SAS_SATA_DEV) {
1744 rc = hisi_sas_internal_task_abort(hisi_hba, device,
1745 HISI_SAS_INT_ABT_DEV,
1748 dev_err(dev, "abort task: internal abort failed\n");
1751 hisi_sas_dereg_device(hisi_hba, device);
1752 rc = hisi_sas_softreset_ata_disk(device);
1754 } else if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SMP) {
1756 struct hisi_sas_slot *slot = task->lldd_task;
1757 u32 tag = slot->idx;
1758 struct hisi_sas_cq *cq = &hisi_hba->cq[slot->dlvry_queue];
1760 rc = hisi_sas_internal_task_abort(hisi_hba, device,
1761 HISI_SAS_INT_ABT_CMD, tag,
1763 if (((rc < 0) || (rc == TMF_RESP_FUNC_FAILED)) &&
1766 * sync irq to avoid free'ing task
1767 * before using task in IO completion
1769 synchronize_irq(cq->irq_no);
1775 if (rc != TMF_RESP_FUNC_COMPLETE)
1776 dev_notice(dev, "abort task: rc=%d\n", rc);
1780 static int hisi_sas_abort_task_set(struct domain_device *device, u8 *lun)
1782 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1783 struct device *dev = hisi_hba->dev;
1784 struct hisi_sas_tmf_task tmf_task;
1787 rc = hisi_sas_internal_task_abort(hisi_hba, device,
1788 HISI_SAS_INT_ABT_DEV, 0, false);
1790 dev_err(dev, "abort task set: internal abort rc=%d\n", rc);
1791 return TMF_RESP_FUNC_FAILED;
1793 hisi_sas_dereg_device(hisi_hba, device);
1795 tmf_task.tmf = TMF_ABORT_TASK_SET;
1796 rc = hisi_sas_debug_issue_ssp_tmf(device, lun, &tmf_task);
1798 if (rc == TMF_RESP_FUNC_COMPLETE)
1799 hisi_sas_release_task(hisi_hba, device);
1804 static int hisi_sas_clear_aca(struct domain_device *device, u8 *lun)
1806 struct hisi_sas_tmf_task tmf_task;
1809 tmf_task.tmf = TMF_CLEAR_ACA;
1810 rc = hisi_sas_debug_issue_ssp_tmf(device, lun, &tmf_task);
1815 #define I_T_NEXUS_RESET_PHYUP_TIMEOUT (2 * HZ)
1817 static int hisi_sas_debug_I_T_nexus_reset(struct domain_device *device)
1819 struct sas_phy *local_phy = sas_get_local_phy(device);
1820 struct hisi_sas_device *sas_dev = device->lldd_dev;
1821 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1822 struct sas_ha_struct *sas_ha = &hisi_hba->sha;
1825 if (!local_phy->enabled) {
1826 sas_put_local_phy(local_phy);
1830 if (scsi_is_sas_phy_local(local_phy)) {
1831 struct asd_sas_phy *sas_phy =
1832 sas_ha->sas_phy[local_phy->number];
1833 struct hisi_sas_phy *phy =
1834 container_of(sas_phy, struct hisi_sas_phy, sas_phy);
1835 unsigned long flags;
1837 spin_lock_irqsave(&phy->lock, flags);
1839 spin_unlock_irqrestore(&phy->lock, flags);
1842 reset_type = (sas_dev->dev_status == HISI_SAS_DEV_INIT ||
1843 !dev_is_sata(device)) ? true : false;
1845 rc = sas_phy_reset(local_phy, reset_type);
1846 sas_put_local_phy(local_phy);
1848 if (scsi_is_sas_phy_local(local_phy)) {
1849 struct asd_sas_phy *sas_phy =
1850 sas_ha->sas_phy[local_phy->number];
1851 struct hisi_sas_phy *phy =
1852 container_of(sas_phy, struct hisi_sas_phy, sas_phy);
1853 unsigned long flags;
1855 spin_lock_irqsave(&phy->lock, flags);
1857 spin_unlock_irqrestore(&phy->lock, flags);
1859 /* report PHY down if timed out */
1860 if (rc == -ETIMEDOUT)
1861 hisi_sas_phy_down(hisi_hba, sas_phy->id, 0, GFP_KERNEL);
1862 } else if (sas_dev->dev_status != HISI_SAS_DEV_INIT) {
1864 * If in init state, we rely on caller to wait for link to be
1865 * ready; otherwise, except phy reset is fail, delay.
1874 static int hisi_sas_I_T_nexus_reset(struct domain_device *device)
1876 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1877 struct device *dev = hisi_hba->dev;
1880 rc = hisi_sas_internal_task_abort(hisi_hba, device,
1881 HISI_SAS_INT_ABT_DEV, 0, false);
1883 dev_err(dev, "I_T nexus reset: internal abort (%d)\n", rc);
1884 return TMF_RESP_FUNC_FAILED;
1886 hisi_sas_dereg_device(hisi_hba, device);
1888 rc = hisi_sas_debug_I_T_nexus_reset(device);
1889 if (rc == TMF_RESP_FUNC_COMPLETE && dev_is_sata(device)) {
1890 struct sas_phy *local_phy;
1892 rc = hisi_sas_softreset_ata_disk(device);
1897 case TMF_RESP_FUNC_FAILED:
1900 local_phy = sas_get_local_phy(device);
1901 rc = sas_phy_enable(local_phy, 0);
1903 local_phy->enabled = 0;
1904 dev_err(dev, "Disabled local phy of ATA disk %016llx due to softreset fail (%d)\n",
1905 SAS_ADDR(device->sas_addr), rc);
1908 sas_put_local_phy(local_phy);
1915 if ((rc == TMF_RESP_FUNC_COMPLETE) || (rc == -ENODEV))
1916 hisi_sas_release_task(hisi_hba, device);
1921 static int hisi_sas_lu_reset(struct domain_device *device, u8 *lun)
1923 struct hisi_sas_device *sas_dev = device->lldd_dev;
1924 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1925 struct device *dev = hisi_hba->dev;
1926 int rc = TMF_RESP_FUNC_FAILED;
1928 /* Clear internal IO and then lu reset */
1929 rc = hisi_sas_internal_task_abort(hisi_hba, device,
1930 HISI_SAS_INT_ABT_DEV, 0, false);
1932 dev_err(dev, "lu_reset: internal abort failed\n");
1935 hisi_sas_dereg_device(hisi_hba, device);
1937 if (dev_is_sata(device)) {
1938 struct sas_phy *phy;
1940 phy = sas_get_local_phy(device);
1942 rc = sas_phy_reset(phy, true);
1945 hisi_sas_release_task(hisi_hba, device);
1946 sas_put_local_phy(phy);
1948 struct hisi_sas_tmf_task tmf_task = { .tmf = TMF_LU_RESET };
1950 rc = hisi_sas_debug_issue_ssp_tmf(device, lun, &tmf_task);
1951 if (rc == TMF_RESP_FUNC_COMPLETE)
1952 hisi_sas_release_task(hisi_hba, device);
1955 if (rc != TMF_RESP_FUNC_COMPLETE)
1956 dev_err(dev, "lu_reset: for device[%d]:rc= %d\n",
1957 sas_dev->device_id, rc);
1961 static void hisi_sas_async_I_T_nexus_reset(void *data, async_cookie_t cookie)
1963 struct domain_device *device = data;
1964 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1967 rc = hisi_sas_debug_I_T_nexus_reset(device);
1968 if (rc != TMF_RESP_FUNC_COMPLETE)
1969 dev_info(hisi_hba->dev, "I_T_nexus reset fail for dev:%016llx rc=%d\n",
1970 SAS_ADDR(device->sas_addr), rc);
1973 static int hisi_sas_clear_nexus_ha(struct sas_ha_struct *sas_ha)
1975 struct hisi_hba *hisi_hba = sas_ha->lldd_ha;
1976 HISI_SAS_DECLARE_RST_WORK_ON_STACK(r);
1977 ASYNC_DOMAIN_EXCLUSIVE(async);
1980 queue_work(hisi_hba->wq, &r.work);
1981 wait_for_completion(r.completion);
1983 return TMF_RESP_FUNC_FAILED;
1985 for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
1986 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i];
1987 struct domain_device *device = sas_dev->sas_device;
1989 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device ||
1990 dev_is_expander(device->dev_type))
1993 async_schedule_domain(hisi_sas_async_I_T_nexus_reset,
1997 async_synchronize_full_domain(&async);
1998 hisi_sas_release_tasks(hisi_hba);
2000 return TMF_RESP_FUNC_COMPLETE;
2003 static int hisi_sas_query_task(struct sas_task *task)
2005 struct scsi_lun lun;
2006 struct hisi_sas_tmf_task tmf_task;
2007 int rc = TMF_RESP_FUNC_FAILED;
2009 if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) {
2010 struct scsi_cmnd *cmnd = task->uldd_task;
2011 struct domain_device *device = task->dev;
2012 struct hisi_sas_slot *slot = task->lldd_task;
2013 u32 tag = slot->idx;
2015 int_to_scsilun(cmnd->device->lun, &lun);
2016 tmf_task.tmf = TMF_QUERY_TASK;
2017 tmf_task.tag_of_task_to_be_managed = tag;
2019 rc = hisi_sas_debug_issue_ssp_tmf(device,
2023 /* The task is still in Lun, release it then */
2024 case TMF_RESP_FUNC_SUCC:
2025 /* The task is not in Lun or failed, reset the phy */
2026 case TMF_RESP_FUNC_FAILED:
2027 case TMF_RESP_FUNC_COMPLETE:
2030 rc = TMF_RESP_FUNC_FAILED;
2038 hisi_sas_internal_abort_task_exec(struct hisi_hba *hisi_hba, int device_id,
2039 struct hisi_sas_internal_abort *abort,
2040 struct sas_task *task,
2041 struct hisi_sas_dq *dq)
2043 struct domain_device *device = task->dev;
2044 struct hisi_sas_device *sas_dev = device->lldd_dev;
2045 struct device *dev = hisi_hba->dev;
2046 struct hisi_sas_port *port;
2047 struct asd_sas_port *sas_port = device->port;
2048 struct hisi_sas_slot *slot;
2051 if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags)))
2057 port = to_hisi_sas_port(sas_port);
2059 /* simply get a slot and send abort command */
2060 slot_idx = hisi_sas_slot_index_alloc(hisi_hba, NULL);
2064 slot = &hisi_hba->slot_info[slot_idx];
2068 slot->is_internal = true;
2070 hisi_sas_task_deliver(hisi_hba, slot, dq, sas_dev, abort, NULL);
2075 dev_err(dev, "internal abort task prep: failed[%d]!\n", slot_idx);
2081 * _hisi_sas_internal_task_abort -- execute an internal
2082 * abort command for single IO command or a device
2083 * @hisi_hba: host controller struct
2084 * @device: domain device
2085 * @abort_flag: mode of operation, device or single IO
2086 * @tag: tag of IO to be aborted (only relevant to single
2088 * @dq: delivery queue for this internal abort command
2089 * @rst_to_recover: If rst_to_recover set, queue a controller
2090 * reset if an internal abort times out.
2093 _hisi_sas_internal_task_abort(struct hisi_hba *hisi_hba,
2094 struct domain_device *device, int abort_flag,
2095 int tag, struct hisi_sas_dq *dq, bool rst_to_recover)
2097 struct sas_task *task;
2098 struct hisi_sas_device *sas_dev = device->lldd_dev;
2099 struct hisi_sas_internal_abort abort = {
2103 struct device *dev = hisi_hba->dev;
2106 * The interface is not realized means this HW don't support internal
2107 * abort, or don't need to do internal abort. Then here, we return
2108 * TMF_RESP_FUNC_FAILED and let other steps go on, which depends that
2109 * the internal abort has been executed and returned CQ.
2111 if (!hisi_hba->hw->prep_abort)
2112 return TMF_RESP_FUNC_FAILED;
2114 if (test_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags))
2117 task = sas_alloc_slow_task(GFP_KERNEL);
2122 task->task_proto = SAS_PROTOCOL_NONE;
2123 task->task_done = hisi_sas_task_done;
2124 task->slow_task->timer.function = hisi_sas_tmf_timedout;
2125 task->slow_task->timer.expires = jiffies + INTERNAL_ABORT_TIMEOUT;
2126 add_timer(&task->slow_task->timer);
2128 res = hisi_sas_internal_abort_task_exec(hisi_hba, sas_dev->device_id,
2131 del_timer_sync(&task->slow_task->timer);
2132 dev_err(dev, "internal task abort: executing internal task failed: %d\n",
2136 wait_for_completion(&task->slow_task->completion);
2137 res = TMF_RESP_FUNC_FAILED;
2139 /* Internal abort timed out */
2140 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
2141 if (hisi_sas_debugfs_enable && hisi_hba->debugfs_itct[0].itct)
2142 queue_work(hisi_hba->wq, &hisi_hba->debugfs_work);
2144 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
2145 struct hisi_sas_slot *slot = task->lldd_task;
2147 set_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags);
2150 struct hisi_sas_cq *cq =
2151 &hisi_hba->cq[slot->dlvry_queue];
2153 * sync irq to avoid free'ing task
2154 * before using task in IO completion
2156 synchronize_irq(cq->irq_no);
2160 if (rst_to_recover) {
2161 dev_err(dev, "internal task abort: timeout and not done. Queuing reset.\n");
2162 queue_work(hisi_hba->wq, &hisi_hba->rst_work);
2164 dev_err(dev, "internal task abort: timeout and not done.\n");
2170 dev_err(dev, "internal task abort: timeout.\n");
2173 if (task->task_status.resp == SAS_TASK_COMPLETE &&
2174 task->task_status.stat == TMF_RESP_FUNC_COMPLETE) {
2175 res = TMF_RESP_FUNC_COMPLETE;
2179 if (task->task_status.resp == SAS_TASK_COMPLETE &&
2180 task->task_status.stat == TMF_RESP_FUNC_SUCC) {
2181 res = TMF_RESP_FUNC_SUCC;
2186 dev_dbg(dev, "internal task abort: task to dev %016llx task=%pK resp: 0x%x sts 0x%x\n",
2187 SAS_ADDR(device->sas_addr), task,
2188 task->task_status.resp, /* 0 is complete, -1 is undelivered */
2189 task->task_status.stat);
2190 sas_free_task(task);
2196 hisi_sas_internal_task_abort(struct hisi_hba *hisi_hba,
2197 struct domain_device *device,
2198 int abort_flag, int tag, bool rst_to_recover)
2200 struct hisi_sas_slot *slot;
2201 struct device *dev = hisi_hba->dev;
2202 struct hisi_sas_dq *dq;
2205 switch (abort_flag) {
2206 case HISI_SAS_INT_ABT_CMD:
2207 slot = &hisi_hba->slot_info[tag];
2208 dq = &hisi_hba->dq[slot->dlvry_queue];
2209 return _hisi_sas_internal_task_abort(hisi_hba, device,
2210 abort_flag, tag, dq,
2212 case HISI_SAS_INT_ABT_DEV:
2213 for (i = 0; i < hisi_hba->cq_nvecs; i++) {
2214 struct hisi_sas_cq *cq = &hisi_hba->cq[i];
2215 const struct cpumask *mask = cq->irq_mask;
2217 if (mask && !cpumask_intersects(cpu_online_mask, mask))
2219 dq = &hisi_hba->dq[i];
2220 rc = _hisi_sas_internal_task_abort(hisi_hba, device,
2222 dq, rst_to_recover);
2228 dev_err(dev, "Unrecognised internal abort flag (%d)\n",
2236 static void hisi_sas_port_formed(struct asd_sas_phy *sas_phy)
2238 hisi_sas_port_notify_formed(sas_phy);
2241 static int hisi_sas_write_gpio(struct sas_ha_struct *sha, u8 reg_type,
2242 u8 reg_index, u8 reg_count, u8 *write_data)
2244 struct hisi_hba *hisi_hba = sha->lldd_ha;
2246 if (!hisi_hba->hw->write_gpio)
2249 return hisi_hba->hw->write_gpio(hisi_hba, reg_type,
2250 reg_index, reg_count, write_data);
2253 static void hisi_sas_phy_disconnected(struct hisi_sas_phy *phy)
2255 struct asd_sas_phy *sas_phy = &phy->sas_phy;
2256 struct sas_phy *sphy = sas_phy->phy;
2257 unsigned long flags;
2259 phy->phy_attached = 0;
2263 spin_lock_irqsave(&phy->lock, flags);
2265 sphy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
2267 sphy->negotiated_linkrate = SAS_PHY_DISABLED;
2268 spin_unlock_irqrestore(&phy->lock, flags);
2271 void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy,
2274 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
2275 struct asd_sas_phy *sas_phy = &phy->sas_phy;
2276 struct device *dev = hisi_hba->dev;
2279 /* Phy down but ready */
2280 hisi_sas_bytes_dmaed(hisi_hba, phy_no, gfp_flags);
2281 hisi_sas_port_notify_formed(sas_phy);
2283 struct hisi_sas_port *port = phy->port;
2285 if (test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags) ||
2287 dev_info(dev, "ignore flutter phy%d down\n", phy_no);
2290 /* Phy down and not ready */
2291 sas_notify_phy_event(sas_phy, PHYE_LOSS_OF_SIGNAL, gfp_flags);
2292 sas_phy_disconnected(sas_phy);
2295 if (phy->phy_type & PORT_TYPE_SAS) {
2296 int port_id = port->id;
2298 if (!hisi_hba->hw->get_wideport_bitmap(hisi_hba,
2300 port->port_attached = 0;
2301 } else if (phy->phy_type & PORT_TYPE_SATA)
2302 port->port_attached = 0;
2304 hisi_sas_phy_disconnected(phy);
2307 EXPORT_SYMBOL_GPL(hisi_sas_phy_down);
2309 void hisi_sas_sync_irqs(struct hisi_hba *hisi_hba)
2313 for (i = 0; i < hisi_hba->cq_nvecs; i++) {
2314 struct hisi_sas_cq *cq = &hisi_hba->cq[i];
2316 synchronize_irq(cq->irq_no);
2319 EXPORT_SYMBOL_GPL(hisi_sas_sync_irqs);
2321 int hisi_sas_host_reset(struct Scsi_Host *shost, int reset_type)
2323 struct hisi_hba *hisi_hba = shost_priv(shost);
2325 if (reset_type != SCSI_ADAPTER_RESET)
2328 queue_work(hisi_hba->wq, &hisi_hba->rst_work);
2332 EXPORT_SYMBOL_GPL(hisi_sas_host_reset);
2334 struct scsi_transport_template *hisi_sas_stt;
2335 EXPORT_SYMBOL_GPL(hisi_sas_stt);
2337 static struct sas_domain_function_template hisi_sas_transport_ops = {
2338 .lldd_dev_found = hisi_sas_dev_found,
2339 .lldd_dev_gone = hisi_sas_dev_gone,
2340 .lldd_execute_task = hisi_sas_queue_command,
2341 .lldd_control_phy = hisi_sas_control_phy,
2342 .lldd_abort_task = hisi_sas_abort_task,
2343 .lldd_abort_task_set = hisi_sas_abort_task_set,
2344 .lldd_clear_aca = hisi_sas_clear_aca,
2345 .lldd_I_T_nexus_reset = hisi_sas_I_T_nexus_reset,
2346 .lldd_lu_reset = hisi_sas_lu_reset,
2347 .lldd_query_task = hisi_sas_query_task,
2348 .lldd_clear_nexus_ha = hisi_sas_clear_nexus_ha,
2349 .lldd_port_formed = hisi_sas_port_formed,
2350 .lldd_write_gpio = hisi_sas_write_gpio,
2353 void hisi_sas_init_mem(struct hisi_hba *hisi_hba)
2355 int i, s, j, max_command_entries = HISI_SAS_MAX_COMMANDS;
2356 struct hisi_sas_breakpoint *sata_breakpoint = hisi_hba->sata_breakpoint;
2358 for (i = 0; i < hisi_hba->queue_count; i++) {
2359 struct hisi_sas_cq *cq = &hisi_hba->cq[i];
2360 struct hisi_sas_dq *dq = &hisi_hba->dq[i];
2361 struct hisi_sas_cmd_hdr *cmd_hdr = hisi_hba->cmd_hdr[i];
2363 s = sizeof(struct hisi_sas_cmd_hdr);
2364 for (j = 0; j < HISI_SAS_QUEUE_SLOTS; j++)
2365 memset(&cmd_hdr[j], 0, s);
2369 s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS;
2370 memset(hisi_hba->complete_hdr[i], 0, s);
2374 s = sizeof(struct hisi_sas_initial_fis) * hisi_hba->n_phy;
2375 memset(hisi_hba->initial_fis, 0, s);
2377 s = max_command_entries * sizeof(struct hisi_sas_iost);
2378 memset(hisi_hba->iost, 0, s);
2380 s = max_command_entries * sizeof(struct hisi_sas_breakpoint);
2381 memset(hisi_hba->breakpoint, 0, s);
2383 s = sizeof(struct hisi_sas_sata_breakpoint);
2384 for (j = 0; j < HISI_SAS_MAX_ITCT_ENTRIES; j++)
2385 memset(&sata_breakpoint[j], 0, s);
2387 EXPORT_SYMBOL_GPL(hisi_sas_init_mem);
2389 int hisi_sas_alloc(struct hisi_hba *hisi_hba)
2391 struct device *dev = hisi_hba->dev;
2392 int i, j, s, max_command_entries = HISI_SAS_MAX_COMMANDS;
2393 int max_command_entries_ru, sz_slot_buf_ru;
2394 int blk_cnt, slots_per_blk;
2396 sema_init(&hisi_hba->sem, 1);
2397 spin_lock_init(&hisi_hba->lock);
2398 for (i = 0; i < hisi_hba->n_phy; i++) {
2399 hisi_sas_phy_init(hisi_hba, i);
2400 hisi_hba->port[i].port_attached = 0;
2401 hisi_hba->port[i].id = -1;
2404 for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
2405 hisi_hba->devices[i].dev_type = SAS_PHY_UNUSED;
2406 hisi_hba->devices[i].device_id = i;
2407 hisi_hba->devices[i].dev_status = HISI_SAS_DEV_INIT;
2410 for (i = 0; i < hisi_hba->queue_count; i++) {
2411 struct hisi_sas_cq *cq = &hisi_hba->cq[i];
2412 struct hisi_sas_dq *dq = &hisi_hba->dq[i];
2414 /* Completion queue structure */
2416 cq->hisi_hba = hisi_hba;
2418 /* Delivery queue structure */
2419 spin_lock_init(&dq->lock);
2420 INIT_LIST_HEAD(&dq->list);
2422 dq->hisi_hba = hisi_hba;
2424 /* Delivery queue */
2425 s = sizeof(struct hisi_sas_cmd_hdr) * HISI_SAS_QUEUE_SLOTS;
2426 hisi_hba->cmd_hdr[i] = dmam_alloc_coherent(dev, s,
2427 &hisi_hba->cmd_hdr_dma[i],
2429 if (!hisi_hba->cmd_hdr[i])
2432 /* Completion queue */
2433 s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS;
2434 hisi_hba->complete_hdr[i] = dmam_alloc_coherent(dev, s,
2435 &hisi_hba->complete_hdr_dma[i],
2437 if (!hisi_hba->complete_hdr[i])
2441 s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_itct);
2442 hisi_hba->itct = dmam_alloc_coherent(dev, s, &hisi_hba->itct_dma,
2444 if (!hisi_hba->itct)
2447 hisi_hba->slot_info = devm_kcalloc(dev, max_command_entries,
2448 sizeof(struct hisi_sas_slot),
2450 if (!hisi_hba->slot_info)
2453 /* roundup to avoid overly large block size */
2454 max_command_entries_ru = roundup(max_command_entries, 64);
2455 if (hisi_hba->prot_mask & HISI_SAS_DIX_PROT_MASK)
2456 sz_slot_buf_ru = sizeof(struct hisi_sas_slot_dif_buf_table);
2458 sz_slot_buf_ru = sizeof(struct hisi_sas_slot_buf_table);
2459 sz_slot_buf_ru = roundup(sz_slot_buf_ru, 64);
2460 s = max(lcm(max_command_entries_ru, sz_slot_buf_ru), PAGE_SIZE);
2461 blk_cnt = (max_command_entries_ru * sz_slot_buf_ru) / s;
2462 slots_per_blk = s / sz_slot_buf_ru;
2464 for (i = 0; i < blk_cnt; i++) {
2465 int slot_index = i * slots_per_blk;
2469 buf = dmam_alloc_coherent(dev, s, &buf_dma,
2474 for (j = 0; j < slots_per_blk; j++, slot_index++) {
2475 struct hisi_sas_slot *slot;
2477 slot = &hisi_hba->slot_info[slot_index];
2479 slot->buf_dma = buf_dma;
2480 slot->idx = slot_index;
2482 buf += sz_slot_buf_ru;
2483 buf_dma += sz_slot_buf_ru;
2487 s = max_command_entries * sizeof(struct hisi_sas_iost);
2488 hisi_hba->iost = dmam_alloc_coherent(dev, s, &hisi_hba->iost_dma,
2490 if (!hisi_hba->iost)
2493 s = max_command_entries * sizeof(struct hisi_sas_breakpoint);
2494 hisi_hba->breakpoint = dmam_alloc_coherent(dev, s,
2495 &hisi_hba->breakpoint_dma,
2497 if (!hisi_hba->breakpoint)
2500 s = hisi_hba->slot_index_count = max_command_entries;
2501 hisi_hba->slot_index_tags = devm_bitmap_zalloc(dev, s, GFP_KERNEL);
2502 if (!hisi_hba->slot_index_tags)
2505 s = sizeof(struct hisi_sas_initial_fis) * HISI_SAS_MAX_PHYS;
2506 hisi_hba->initial_fis = dmam_alloc_coherent(dev, s,
2507 &hisi_hba->initial_fis_dma,
2509 if (!hisi_hba->initial_fis)
2512 s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_sata_breakpoint);
2513 hisi_hba->sata_breakpoint = dmam_alloc_coherent(dev, s,
2514 &hisi_hba->sata_breakpoint_dma,
2516 if (!hisi_hba->sata_breakpoint)
2519 hisi_hba->last_slot_index = HISI_SAS_UNRESERVED_IPTT;
2521 hisi_hba->wq = create_singlethread_workqueue(dev_name(dev));
2522 if (!hisi_hba->wq) {
2523 dev_err(dev, "sas_alloc: failed to create workqueue\n");
2531 EXPORT_SYMBOL_GPL(hisi_sas_alloc);
2533 void hisi_sas_free(struct hisi_hba *hisi_hba)
2537 for (i = 0; i < hisi_hba->n_phy; i++) {
2538 struct hisi_sas_phy *phy = &hisi_hba->phy[i];
2540 del_timer_sync(&phy->timer);
2544 destroy_workqueue(hisi_hba->wq);
2546 EXPORT_SYMBOL_GPL(hisi_sas_free);
2548 void hisi_sas_rst_work_handler(struct work_struct *work)
2550 struct hisi_hba *hisi_hba =
2551 container_of(work, struct hisi_hba, rst_work);
2553 if (hisi_sas_controller_prereset(hisi_hba))
2556 hisi_sas_controller_reset(hisi_hba);
2558 EXPORT_SYMBOL_GPL(hisi_sas_rst_work_handler);
2560 void hisi_sas_sync_rst_work_handler(struct work_struct *work)
2562 struct hisi_sas_rst *rst =
2563 container_of(work, struct hisi_sas_rst, work);
2565 if (hisi_sas_controller_prereset(rst->hisi_hba))
2568 if (!hisi_sas_controller_reset(rst->hisi_hba))
2571 complete(rst->completion);
2573 EXPORT_SYMBOL_GPL(hisi_sas_sync_rst_work_handler);
2575 int hisi_sas_get_fw_info(struct hisi_hba *hisi_hba)
2577 struct device *dev = hisi_hba->dev;
2578 struct platform_device *pdev = hisi_hba->platform_dev;
2579 struct device_node *np = pdev ? pdev->dev.of_node : NULL;
2582 if (device_property_read_u8_array(dev, "sas-addr", hisi_hba->sas_addr,
2584 dev_err(dev, "could not get property sas-addr\n");
2590 * These properties are only required for platform device-based
2591 * controller with DT firmware.
2593 hisi_hba->ctrl = syscon_regmap_lookup_by_phandle(np,
2594 "hisilicon,sas-syscon");
2595 if (IS_ERR(hisi_hba->ctrl)) {
2596 dev_err(dev, "could not get syscon\n");
2600 if (device_property_read_u32(dev, "ctrl-reset-reg",
2601 &hisi_hba->ctrl_reset_reg)) {
2602 dev_err(dev, "could not get property ctrl-reset-reg\n");
2606 if (device_property_read_u32(dev, "ctrl-reset-sts-reg",
2607 &hisi_hba->ctrl_reset_sts_reg)) {
2608 dev_err(dev, "could not get property ctrl-reset-sts-reg\n");
2612 if (device_property_read_u32(dev, "ctrl-clock-ena-reg",
2613 &hisi_hba->ctrl_clock_ena_reg)) {
2614 dev_err(dev, "could not get property ctrl-clock-ena-reg\n");
2619 refclk = devm_clk_get(dev, NULL);
2621 dev_dbg(dev, "no ref clk property\n");
2623 hisi_hba->refclk_frequency_mhz = clk_get_rate(refclk) / 1000000;
2625 if (device_property_read_u32(dev, "phy-count", &hisi_hba->n_phy)) {
2626 dev_err(dev, "could not get property phy-count\n");
2630 if (device_property_read_u32(dev, "queue-count",
2631 &hisi_hba->queue_count)) {
2632 dev_err(dev, "could not get property queue-count\n");
2638 EXPORT_SYMBOL_GPL(hisi_sas_get_fw_info);
2640 static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device *pdev,
2641 const struct hisi_sas_hw *hw)
2643 struct resource *res;
2644 struct Scsi_Host *shost;
2645 struct hisi_hba *hisi_hba;
2646 struct device *dev = &pdev->dev;
2649 shost = scsi_host_alloc(hw->sht, sizeof(*hisi_hba));
2651 dev_err(dev, "scsi host alloc failed\n");
2654 hisi_hba = shost_priv(shost);
2656 INIT_WORK(&hisi_hba->rst_work, hisi_sas_rst_work_handler);
2658 hisi_hba->dev = dev;
2659 hisi_hba->platform_dev = pdev;
2660 hisi_hba->shost = shost;
2661 SHOST_TO_SAS_HA(shost) = &hisi_hba->sha;
2663 timer_setup(&hisi_hba->timer, NULL, 0);
2665 if (hisi_sas_get_fw_info(hisi_hba) < 0)
2668 error = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
2670 dev_err(dev, "No usable DMA addressing method\n");
2674 hisi_hba->regs = devm_platform_ioremap_resource(pdev, 0);
2675 if (IS_ERR(hisi_hba->regs))
2678 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2680 hisi_hba->sgpio_regs = devm_ioremap_resource(dev, res);
2681 if (IS_ERR(hisi_hba->sgpio_regs))
2685 if (hisi_sas_alloc(hisi_hba)) {
2686 hisi_sas_free(hisi_hba);
2692 scsi_host_put(shost);
2693 dev_err(dev, "shost alloc failed\n");
2697 static int hisi_sas_interrupt_preinit(struct hisi_hba *hisi_hba)
2699 if (hisi_hba->hw->interrupt_preinit)
2700 return hisi_hba->hw->interrupt_preinit(hisi_hba);
2704 int hisi_sas_probe(struct platform_device *pdev,
2705 const struct hisi_sas_hw *hw)
2707 struct Scsi_Host *shost;
2708 struct hisi_hba *hisi_hba;
2709 struct device *dev = &pdev->dev;
2710 struct asd_sas_phy **arr_phy;
2711 struct asd_sas_port **arr_port;
2712 struct sas_ha_struct *sha;
2713 int rc, phy_nr, port_nr, i;
2715 shost = hisi_sas_shost_alloc(pdev, hw);
2719 sha = SHOST_TO_SAS_HA(shost);
2720 hisi_hba = shost_priv(shost);
2721 platform_set_drvdata(pdev, sha);
2723 phy_nr = port_nr = hisi_hba->n_phy;
2725 arr_phy = devm_kcalloc(dev, phy_nr, sizeof(void *), GFP_KERNEL);
2726 arr_port = devm_kcalloc(dev, port_nr, sizeof(void *), GFP_KERNEL);
2727 if (!arr_phy || !arr_port) {
2732 sha->sas_phy = arr_phy;
2733 sha->sas_port = arr_port;
2734 sha->lldd_ha = hisi_hba;
2736 shost->transportt = hisi_sas_stt;
2737 shost->max_id = HISI_SAS_MAX_DEVICES;
2738 shost->max_lun = ~0;
2739 shost->max_channel = 1;
2740 shost->max_cmd_len = 16;
2741 if (hisi_hba->hw->slot_index_alloc) {
2742 shost->can_queue = HISI_SAS_MAX_COMMANDS;
2743 shost->cmd_per_lun = HISI_SAS_MAX_COMMANDS;
2745 shost->can_queue = HISI_SAS_UNRESERVED_IPTT;
2746 shost->cmd_per_lun = HISI_SAS_UNRESERVED_IPTT;
2749 sha->sas_ha_name = DRV_NAME;
2750 sha->dev = hisi_hba->dev;
2751 sha->lldd_module = THIS_MODULE;
2752 sha->sas_addr = &hisi_hba->sas_addr[0];
2753 sha->num_phys = hisi_hba->n_phy;
2754 sha->core.shost = hisi_hba->shost;
2756 for (i = 0; i < hisi_hba->n_phy; i++) {
2757 sha->sas_phy[i] = &hisi_hba->phy[i].sas_phy;
2758 sha->sas_port[i] = &hisi_hba->port[i].sas_port;
2761 rc = hisi_sas_interrupt_preinit(hisi_hba);
2765 rc = scsi_add_host(shost, &pdev->dev);
2769 rc = sas_register_ha(sha);
2771 goto err_out_register_ha;
2773 rc = hisi_hba->hw->hw_init(hisi_hba);
2775 goto err_out_hw_init;
2777 scsi_scan_host(shost);
2782 sas_unregister_ha(sha);
2783 err_out_register_ha:
2784 scsi_remove_host(shost);
2786 hisi_sas_free(hisi_hba);
2787 scsi_host_put(shost);
2790 EXPORT_SYMBOL_GPL(hisi_sas_probe);
2792 int hisi_sas_remove(struct platform_device *pdev)
2794 struct sas_ha_struct *sha = platform_get_drvdata(pdev);
2795 struct hisi_hba *hisi_hba = sha->lldd_ha;
2796 struct Scsi_Host *shost = sha->core.shost;
2798 del_timer_sync(&hisi_hba->timer);
2800 sas_unregister_ha(sha);
2801 sas_remove_host(sha->core.shost);
2803 hisi_sas_free(hisi_hba);
2804 scsi_host_put(shost);
2807 EXPORT_SYMBOL_GPL(hisi_sas_remove);
2809 #if IS_ENABLED(CONFIG_SCSI_HISI_SAS_DEBUGFS_DEFAULT_ENABLE)
2810 #define DEBUGFS_ENABLE_DEFAULT "enabled"
2811 bool hisi_sas_debugfs_enable = true;
2812 u32 hisi_sas_debugfs_dump_count = 50;
2814 #define DEBUGFS_ENABLE_DEFAULT "disabled"
2815 bool hisi_sas_debugfs_enable;
2816 u32 hisi_sas_debugfs_dump_count = 1;
2819 EXPORT_SYMBOL_GPL(hisi_sas_debugfs_enable);
2820 module_param_named(debugfs_enable, hisi_sas_debugfs_enable, bool, 0444);
2821 MODULE_PARM_DESC(hisi_sas_debugfs_enable,
2822 "Enable driver debugfs (default "DEBUGFS_ENABLE_DEFAULT")");
2824 EXPORT_SYMBOL_GPL(hisi_sas_debugfs_dump_count);
2825 module_param_named(debugfs_dump_count, hisi_sas_debugfs_dump_count, uint, 0444);
2826 MODULE_PARM_DESC(hisi_sas_debugfs_dump_count, "Number of debugfs dumps to allow");
2828 struct dentry *hisi_sas_debugfs_dir;
2829 EXPORT_SYMBOL_GPL(hisi_sas_debugfs_dir);
2831 static __init int hisi_sas_init(void)
2833 hisi_sas_stt = sas_domain_attach_transport(&hisi_sas_transport_ops);
2837 if (hisi_sas_debugfs_enable) {
2838 hisi_sas_debugfs_dir = debugfs_create_dir("hisi_sas", NULL);
2839 if (hisi_sas_debugfs_dump_count > HISI_SAS_MAX_DEBUGFS_DUMP) {
2840 pr_info("hisi_sas: Limiting debugfs dump count\n");
2841 hisi_sas_debugfs_dump_count = HISI_SAS_MAX_DEBUGFS_DUMP;
2848 static __exit void hisi_sas_exit(void)
2850 sas_release_transport(hisi_sas_stt);
2852 debugfs_remove(hisi_sas_debugfs_dir);
2855 module_init(hisi_sas_init);
2856 module_exit(hisi_sas_exit);
2858 MODULE_LICENSE("GPL");
2859 MODULE_AUTHOR("John Garry <john.garry@huawei.com>");
2860 MODULE_DESCRIPTION("HISILICON SAS controller driver");
2861 MODULE_ALIAS("platform:" DRV_NAME);