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)
405 struct hisi_sas_cmd_hdr *cmd_hdr_base;
406 int dlvry_queue_slot, dlvry_queue;
407 struct sas_task *task = slot->task;
411 spin_lock(&dq->lock);
412 wr_q_index = dq->wr_point;
413 dq->wr_point = (dq->wr_point + 1) % HISI_SAS_QUEUE_SLOTS;
414 list_add_tail(&slot->delivery, &dq->list);
415 spin_unlock(&dq->lock);
416 spin_lock(&sas_dev->lock);
417 list_add_tail(&slot->entry, &sas_dev->list);
418 spin_unlock(&sas_dev->lock);
420 dlvry_queue = dq->id;
421 dlvry_queue_slot = wr_q_index;
423 slot->device_id = sas_dev->device_id;
424 slot->dlvry_queue = dlvry_queue;
425 slot->dlvry_queue_slot = dlvry_queue_slot;
426 cmd_hdr_base = hisi_hba->cmd_hdr[dlvry_queue];
427 slot->cmd_hdr = &cmd_hdr_base[dlvry_queue_slot];
429 task->lldd_task = slot;
431 memset(slot->cmd_hdr, 0, sizeof(struct hisi_sas_cmd_hdr));
432 memset(hisi_sas_cmd_hdr_addr_mem(slot), 0, HISI_SAS_COMMAND_TABLE_SZ);
433 memset(hisi_sas_status_buf_addr_mem(slot), 0,
434 sizeof(struct hisi_sas_err_record));
436 switch (task->task_proto) {
437 case SAS_PROTOCOL_SMP:
438 hisi_sas_task_prep_smp(hisi_hba, slot);
440 case SAS_PROTOCOL_SSP:
441 hisi_sas_task_prep_ssp(hisi_hba, slot);
443 case SAS_PROTOCOL_SATA:
444 case SAS_PROTOCOL_STP:
445 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
446 hisi_sas_task_prep_ata(hisi_hba, slot);
448 case SAS_PROTOCOL_NONE:
450 hisi_sas_task_prep_abort(hisi_hba, abort, slot, sas_dev->device_id);
455 dev_err(hisi_hba->dev, "task prep: unknown/unsupported proto (0x%x)\n",
460 spin_lock_irqsave(&task->task_state_lock, flags);
461 task->task_state_flags |= SAS_TASK_AT_INITIATOR;
462 spin_unlock_irqrestore(&task->task_state_lock, flags);
464 WRITE_ONCE(slot->ready, 1);
466 spin_lock(&dq->lock);
467 hisi_hba->hw->start_delivery(dq);
468 spin_unlock(&dq->lock);
471 static int hisi_sas_task_exec(struct sas_task *task, gfp_t gfp_flags,
472 struct hisi_sas_tmf_task *tmf)
474 int n_elem = 0, n_elem_dif = 0, n_elem_req = 0;
475 struct domain_device *device = task->dev;
476 struct asd_sas_port *sas_port = device->port;
477 struct hisi_sas_device *sas_dev = device->lldd_dev;
478 struct scsi_cmnd *scmd = NULL;
479 struct hisi_sas_dq *dq = NULL;
480 struct hisi_sas_port *port;
481 struct hisi_hba *hisi_hba;
482 struct hisi_sas_slot *slot;
487 struct task_status_struct *ts = &task->task_status;
489 ts->resp = SAS_TASK_UNDELIVERED;
490 ts->stat = SAS_PHY_DOWN;
492 * libsas will use dev->port, should
493 * not call task_done for sata
495 if (device->dev_type != SAS_SATA_DEV)
496 task->task_done(task);
500 hisi_hba = dev_to_hisi_hba(device);
503 if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags))) {
504 if (!gfpflags_allow_blocking(gfp_flags))
507 down(&hisi_hba->sem);
511 if (DEV_IS_GONE(sas_dev)) {
513 dev_info(dev, "task prep: device %d not ready\n",
516 dev_info(dev, "task prep: device %016llx not ready\n",
517 SAS_ADDR(device->sas_addr));
522 if (task->uldd_task) {
523 struct ata_queued_cmd *qc;
525 if (dev_is_sata(device)) {
526 qc = task->uldd_task;
529 scmd = task->uldd_task;
534 unsigned int dq_index;
537 blk_tag = blk_mq_unique_tag(scsi_cmd_to_rq(scmd));
538 dq_index = blk_mq_unique_tag_to_hwq(blk_tag);
539 dq = &hisi_hba->dq[dq_index];
541 struct Scsi_Host *shost = hisi_hba->shost;
542 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
543 int queue = qmap->mq_map[raw_smp_processor_id()];
545 dq = &hisi_hba->dq[queue];
548 port = to_hisi_sas_port(sas_port);
549 if (port && !port->port_attached) {
550 dev_info(dev, "task prep: %s port%d not attach device\n",
551 (dev_is_sata(device)) ?
558 rc = hisi_sas_dma_map(hisi_hba, task, &n_elem,
563 if (!sas_protocol_ata(task->task_proto)) {
564 rc = hisi_sas_dif_dma_map(hisi_hba, &n_elem_dif, task);
566 goto err_out_dma_unmap;
569 if (hisi_hba->hw->slot_index_alloc)
570 rc = hisi_hba->hw->slot_index_alloc(hisi_hba, device);
572 rc = hisi_sas_slot_index_alloc(hisi_hba, scmd);
575 goto err_out_dif_dma_unmap;
577 slot = &hisi_hba->slot_info[rc];
578 slot->n_elem = n_elem;
579 slot->n_elem_dif = n_elem_dif;
584 slot->is_internal = tmf;
586 /* protect task_prep and start_delivery sequence */
587 hisi_sas_task_deliver(hisi_hba, slot, dq, sas_dev, NULL);
591 err_out_dif_dma_unmap:
592 if (!sas_protocol_ata(task->task_proto))
593 hisi_sas_dif_dma_unmap(hisi_hba, task, n_elem_dif);
595 hisi_sas_dma_unmap(hisi_hba, task, n_elem,
598 dev_err(dev, "task exec: failed[%d]!\n", rc);
602 static void hisi_sas_bytes_dmaed(struct hisi_hba *hisi_hba, int phy_no,
605 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
606 struct asd_sas_phy *sas_phy = &phy->sas_phy;
608 if (!phy->phy_attached)
611 sas_notify_phy_event(sas_phy, PHYE_OOB_DONE, gfp_flags);
614 struct sas_phy *sphy = sas_phy->phy;
616 sphy->negotiated_linkrate = sas_phy->linkrate;
617 sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
618 sphy->maximum_linkrate_hw =
619 hisi_hba->hw->phy_get_max_linkrate();
620 if (sphy->minimum_linkrate == SAS_LINK_RATE_UNKNOWN)
621 sphy->minimum_linkrate = phy->minimum_linkrate;
623 if (sphy->maximum_linkrate == SAS_LINK_RATE_UNKNOWN)
624 sphy->maximum_linkrate = phy->maximum_linkrate;
627 if (phy->phy_type & PORT_TYPE_SAS) {
628 struct sas_identify_frame *id;
630 id = (struct sas_identify_frame *)phy->frame_rcvd;
631 id->dev_type = phy->identify.device_type;
632 id->initiator_bits = SAS_PROTOCOL_ALL;
633 id->target_bits = phy->identify.target_port_protocols;
634 } else if (phy->phy_type & PORT_TYPE_SATA) {
638 sas_phy->frame_rcvd_size = phy->frame_rcvd_size;
639 sas_notify_port_event(sas_phy, PORTE_BYTES_DMAED, gfp_flags);
642 static struct hisi_sas_device *hisi_sas_alloc_dev(struct domain_device *device)
644 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
645 struct hisi_sas_device *sas_dev = NULL;
646 int last = hisi_hba->last_dev_id;
647 int first = (hisi_hba->last_dev_id + 1) % HISI_SAS_MAX_DEVICES;
650 spin_lock(&hisi_hba->lock);
651 for (i = first; i != last; i %= HISI_SAS_MAX_DEVICES) {
652 if (hisi_hba->devices[i].dev_type == SAS_PHY_UNUSED) {
653 int queue = i % hisi_hba->queue_count;
654 struct hisi_sas_dq *dq = &hisi_hba->dq[queue];
656 hisi_hba->devices[i].device_id = i;
657 sas_dev = &hisi_hba->devices[i];
658 sas_dev->dev_status = HISI_SAS_DEV_INIT;
659 sas_dev->dev_type = device->dev_type;
660 sas_dev->hisi_hba = hisi_hba;
661 sas_dev->sas_device = device;
663 spin_lock_init(&sas_dev->lock);
664 INIT_LIST_HEAD(&hisi_hba->devices[i].list);
669 hisi_hba->last_dev_id = i;
670 spin_unlock(&hisi_hba->lock);
675 #define HISI_SAS_DISK_RECOVER_CNT 3
676 static int hisi_sas_init_device(struct domain_device *device)
678 int rc = TMF_RESP_FUNC_COMPLETE;
680 struct hisi_sas_tmf_task tmf_task;
681 int retry = HISI_SAS_DISK_RECOVER_CNT;
682 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
683 struct device *dev = hisi_hba->dev;
684 struct sas_phy *local_phy;
686 switch (device->dev_type) {
688 int_to_scsilun(0, &lun);
690 tmf_task.tmf = TMF_CLEAR_TASK_SET;
691 while (retry-- > 0) {
692 rc = hisi_sas_debug_issue_ssp_tmf(device, lun.scsi_lun,
694 if (rc == TMF_RESP_FUNC_COMPLETE) {
695 hisi_sas_release_task(hisi_hba, device);
702 case SAS_SATA_PM_PORT:
703 case SAS_SATA_PENDING:
705 * send HARD RESET to clear previous affiliation of
708 local_phy = sas_get_local_phy(device);
709 if (!scsi_is_sas_phy_local(local_phy) &&
710 !test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags)) {
711 unsigned long deadline = ata_deadline(jiffies, 20000);
712 struct sata_device *sata_dev = &device->sata_dev;
713 struct ata_host *ata_host = sata_dev->ata_host;
714 struct ata_port_operations *ops = ata_host->ops;
715 struct ata_port *ap = sata_dev->ap;
716 struct ata_link *link;
717 unsigned int classes;
719 ata_for_each_link(link, ap, EDGE)
720 rc = ops->hardreset(link, &classes,
723 sas_put_local_phy(local_phy);
725 dev_warn(dev, "SATA disk hardreset fail: %d\n", rc);
729 while (retry-- > 0) {
730 rc = hisi_sas_softreset_ata_disk(device);
742 int hisi_sas_slave_alloc(struct scsi_device *sdev)
744 struct domain_device *ddev;
747 rc = sas_slave_alloc(sdev);
750 ddev = sdev_to_domain_dev(sdev);
752 return hisi_sas_init_device(ddev);
754 EXPORT_SYMBOL_GPL(hisi_sas_slave_alloc);
756 static int hisi_sas_dev_found(struct domain_device *device)
758 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
759 struct domain_device *parent_dev = device->parent;
760 struct hisi_sas_device *sas_dev;
761 struct device *dev = hisi_hba->dev;
764 if (hisi_hba->hw->alloc_dev)
765 sas_dev = hisi_hba->hw->alloc_dev(device);
767 sas_dev = hisi_sas_alloc_dev(device);
769 dev_err(dev, "fail alloc dev: max support %d devices\n",
770 HISI_SAS_MAX_DEVICES);
774 device->lldd_dev = sas_dev;
775 hisi_hba->hw->setup_itct(hisi_hba, sas_dev);
777 if (parent_dev && dev_is_expander(parent_dev->dev_type)) {
779 u8 phy_num = parent_dev->ex_dev.num_phys;
782 for (phy_no = 0; phy_no < phy_num; phy_no++) {
783 phy = &parent_dev->ex_dev.ex_phy[phy_no];
784 if (SAS_ADDR(phy->attached_sas_addr) ==
785 SAS_ADDR(device->sas_addr))
789 if (phy_no == phy_num) {
790 dev_info(dev, "dev found: no attached "
791 "dev:%016llx at ex:%016llx\n",
792 SAS_ADDR(device->sas_addr),
793 SAS_ADDR(parent_dev->sas_addr));
799 dev_info(dev, "dev[%d:%x] found\n",
800 sas_dev->device_id, sas_dev->dev_type);
802 sas_dev->dev_status = HISI_SAS_DEV_NORMAL;
806 hisi_sas_dev_gone(device);
810 int hisi_sas_slave_configure(struct scsi_device *sdev)
812 struct domain_device *dev = sdev_to_domain_dev(sdev);
813 int ret = sas_slave_configure(sdev);
817 if (!dev_is_sata(dev))
818 sas_change_queue_depth(sdev, 64);
822 EXPORT_SYMBOL_GPL(hisi_sas_slave_configure);
824 void hisi_sas_scan_start(struct Scsi_Host *shost)
826 struct hisi_hba *hisi_hba = shost_priv(shost);
828 hisi_hba->hw->phys_init(hisi_hba);
830 EXPORT_SYMBOL_GPL(hisi_sas_scan_start);
832 int hisi_sas_scan_finished(struct Scsi_Host *shost, unsigned long time)
834 struct hisi_hba *hisi_hba = shost_priv(shost);
835 struct sas_ha_struct *sha = &hisi_hba->sha;
837 /* Wait for PHY up interrupt to occur */
844 EXPORT_SYMBOL_GPL(hisi_sas_scan_finished);
846 static void hisi_sas_phyup_work_common(struct work_struct *work,
847 enum hisi_sas_phy_event event)
849 struct hisi_sas_phy *phy =
850 container_of(work, typeof(*phy), works[event]);
851 struct hisi_hba *hisi_hba = phy->hisi_hba;
852 struct asd_sas_phy *sas_phy = &phy->sas_phy;
853 int phy_no = sas_phy->id;
855 phy->wait_phyup_cnt = 0;
856 if (phy->identify.target_port_protocols == SAS_PROTOCOL_SSP)
857 hisi_hba->hw->sl_notify_ssp(hisi_hba, phy_no);
858 hisi_sas_bytes_dmaed(hisi_hba, phy_no, GFP_KERNEL);
861 static void hisi_sas_phyup_work(struct work_struct *work)
863 hisi_sas_phyup_work_common(work, HISI_PHYE_PHY_UP);
866 static void hisi_sas_linkreset_work(struct work_struct *work)
868 struct hisi_sas_phy *phy =
869 container_of(work, typeof(*phy), works[HISI_PHYE_LINK_RESET]);
870 struct asd_sas_phy *sas_phy = &phy->sas_phy;
872 hisi_sas_control_phy(sas_phy, PHY_FUNC_LINK_RESET, NULL);
875 static void hisi_sas_phyup_pm_work(struct work_struct *work)
877 struct hisi_sas_phy *phy =
878 container_of(work, typeof(*phy), works[HISI_PHYE_PHY_UP_PM]);
879 struct hisi_hba *hisi_hba = phy->hisi_hba;
880 struct device *dev = hisi_hba->dev;
882 hisi_sas_phyup_work_common(work, HISI_PHYE_PHY_UP_PM);
883 pm_runtime_put_sync(dev);
886 static const work_func_t hisi_sas_phye_fns[HISI_PHYES_NUM] = {
887 [HISI_PHYE_PHY_UP] = hisi_sas_phyup_work,
888 [HISI_PHYE_LINK_RESET] = hisi_sas_linkreset_work,
889 [HISI_PHYE_PHY_UP_PM] = hisi_sas_phyup_pm_work,
892 bool hisi_sas_notify_phy_event(struct hisi_sas_phy *phy,
893 enum hisi_sas_phy_event event)
895 struct hisi_hba *hisi_hba = phy->hisi_hba;
897 if (WARN_ON(event >= HISI_PHYES_NUM))
900 return queue_work(hisi_hba->wq, &phy->works[event]);
902 EXPORT_SYMBOL_GPL(hisi_sas_notify_phy_event);
904 static void hisi_sas_wait_phyup_timedout(struct timer_list *t)
906 struct hisi_sas_phy *phy = from_timer(phy, t, timer);
907 struct hisi_hba *hisi_hba = phy->hisi_hba;
908 struct device *dev = hisi_hba->dev;
909 int phy_no = phy->sas_phy.id;
911 dev_warn(dev, "phy%d wait phyup timeout, issuing link reset\n", phy_no);
912 hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
915 #define HISI_SAS_WAIT_PHYUP_RETRIES 10
917 void hisi_sas_phy_oob_ready(struct hisi_hba *hisi_hba, int phy_no)
919 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
920 struct device *dev = hisi_hba->dev;
923 dev_dbg(dev, "phy%d OOB ready\n", phy_no);
924 spin_lock_irqsave(&phy->lock, flags);
925 if (phy->phy_attached) {
926 spin_unlock_irqrestore(&phy->lock, flags);
930 if (!timer_pending(&phy->timer)) {
931 if (phy->wait_phyup_cnt < HISI_SAS_WAIT_PHYUP_RETRIES) {
932 phy->wait_phyup_cnt++;
933 phy->timer.expires = jiffies +
934 HISI_SAS_WAIT_PHYUP_TIMEOUT;
935 add_timer(&phy->timer);
936 spin_unlock_irqrestore(&phy->lock, flags);
940 dev_warn(dev, "phy%d failed to come up %d times, giving up\n",
941 phy_no, phy->wait_phyup_cnt);
942 phy->wait_phyup_cnt = 0;
944 spin_unlock_irqrestore(&phy->lock, flags);
947 EXPORT_SYMBOL_GPL(hisi_sas_phy_oob_ready);
949 static void hisi_sas_phy_init(struct hisi_hba *hisi_hba, int phy_no)
951 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
952 struct asd_sas_phy *sas_phy = &phy->sas_phy;
955 phy->hisi_hba = hisi_hba;
957 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
958 phy->maximum_linkrate = hisi_hba->hw->phy_get_max_linkrate();
959 sas_phy->enabled = (phy_no < hisi_hba->n_phy) ? 1 : 0;
960 sas_phy->class = SAS;
961 sas_phy->iproto = SAS_PROTOCOL_ALL;
963 sas_phy->type = PHY_TYPE_PHYSICAL;
964 sas_phy->role = PHY_ROLE_INITIATOR;
965 sas_phy->oob_mode = OOB_NOT_CONNECTED;
966 sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN;
967 sas_phy->id = phy_no;
968 sas_phy->sas_addr = &hisi_hba->sas_addr[0];
969 sas_phy->frame_rcvd = &phy->frame_rcvd[0];
970 sas_phy->ha = (struct sas_ha_struct *)hisi_hba->shost->hostdata;
971 sas_phy->lldd_phy = phy;
973 for (i = 0; i < HISI_PHYES_NUM; i++)
974 INIT_WORK(&phy->works[i], hisi_sas_phye_fns[i]);
976 spin_lock_init(&phy->lock);
978 timer_setup(&phy->timer, hisi_sas_wait_phyup_timedout, 0);
981 /* Wrapper to ensure we track hisi_sas_phy.enable properly */
982 void hisi_sas_phy_enable(struct hisi_hba *hisi_hba, int phy_no, int enable)
984 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
985 struct asd_sas_phy *aphy = &phy->sas_phy;
986 struct sas_phy *sphy = aphy->phy;
989 spin_lock_irqsave(&phy->lock, flags);
992 /* We may have been enabled already; if so, don't touch */
994 sphy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
995 hisi_hba->hw->phy_start(hisi_hba, phy_no);
997 sphy->negotiated_linkrate = SAS_PHY_DISABLED;
998 hisi_hba->hw->phy_disable(hisi_hba, phy_no);
1000 phy->enable = enable;
1001 spin_unlock_irqrestore(&phy->lock, flags);
1003 EXPORT_SYMBOL_GPL(hisi_sas_phy_enable);
1005 static void hisi_sas_port_notify_formed(struct asd_sas_phy *sas_phy)
1007 struct sas_ha_struct *sas_ha = sas_phy->ha;
1008 struct hisi_hba *hisi_hba = sas_ha->lldd_ha;
1009 struct hisi_sas_phy *phy = sas_phy->lldd_phy;
1010 struct asd_sas_port *sas_port = sas_phy->port;
1011 struct hisi_sas_port *port;
1012 unsigned long flags;
1017 port = to_hisi_sas_port(sas_port);
1018 spin_lock_irqsave(&hisi_hba->lock, flags);
1019 port->port_attached = 1;
1020 port->id = phy->port_id;
1022 sas_port->lldd_port = port;
1023 spin_unlock_irqrestore(&hisi_hba->lock, flags);
1026 static void hisi_sas_do_release_task(struct hisi_hba *hisi_hba, struct sas_task *task,
1027 struct hisi_sas_slot *slot)
1030 unsigned long flags;
1031 struct task_status_struct *ts;
1033 ts = &task->task_status;
1035 ts->resp = SAS_TASK_COMPLETE;
1036 ts->stat = SAS_ABORTED_TASK;
1037 spin_lock_irqsave(&task->task_state_lock, flags);
1038 task->task_state_flags &=
1039 ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR);
1040 if (!slot->is_internal && task->task_proto != SAS_PROTOCOL_SMP)
1041 task->task_state_flags |= SAS_TASK_STATE_DONE;
1042 spin_unlock_irqrestore(&task->task_state_lock, flags);
1045 hisi_sas_slot_task_free(hisi_hba, task, slot);
1048 static void hisi_sas_release_task(struct hisi_hba *hisi_hba,
1049 struct domain_device *device)
1051 struct hisi_sas_slot *slot, *slot2;
1052 struct hisi_sas_device *sas_dev = device->lldd_dev;
1054 list_for_each_entry_safe(slot, slot2, &sas_dev->list, entry)
1055 hisi_sas_do_release_task(hisi_hba, slot->task, slot);
1058 void hisi_sas_release_tasks(struct hisi_hba *hisi_hba)
1060 struct hisi_sas_device *sas_dev;
1061 struct domain_device *device;
1064 for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
1065 sas_dev = &hisi_hba->devices[i];
1066 device = sas_dev->sas_device;
1068 if ((sas_dev->dev_type == SAS_PHY_UNUSED) ||
1072 hisi_sas_release_task(hisi_hba, device);
1075 EXPORT_SYMBOL_GPL(hisi_sas_release_tasks);
1077 static void hisi_sas_dereg_device(struct hisi_hba *hisi_hba,
1078 struct domain_device *device)
1080 if (hisi_hba->hw->dereg_device)
1081 hisi_hba->hw->dereg_device(hisi_hba, device);
1084 static void hisi_sas_dev_gone(struct domain_device *device)
1086 struct hisi_sas_device *sas_dev = device->lldd_dev;
1087 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1088 struct device *dev = hisi_hba->dev;
1091 dev_info(dev, "dev[%d:%x] is gone\n",
1092 sas_dev->device_id, sas_dev->dev_type);
1094 down(&hisi_hba->sem);
1095 if (!test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags)) {
1096 hisi_sas_internal_task_abort(hisi_hba, device,
1097 HISI_SAS_INT_ABT_DEV, 0, true);
1099 hisi_sas_dereg_device(hisi_hba, device);
1101 ret = hisi_hba->hw->clear_itct(hisi_hba, sas_dev);
1102 device->lldd_dev = NULL;
1105 if (hisi_hba->hw->free_device)
1106 hisi_hba->hw->free_device(sas_dev);
1108 /* Don't mark it as SAS_PHY_UNUSED if failed to clear ITCT */
1110 sas_dev->dev_type = SAS_PHY_UNUSED;
1111 sas_dev->sas_device = NULL;
1115 static int hisi_sas_queue_command(struct sas_task *task, gfp_t gfp_flags)
1117 return hisi_sas_task_exec(task, gfp_flags, NULL);
1120 static int hisi_sas_phy_set_linkrate(struct hisi_hba *hisi_hba, int phy_no,
1121 struct sas_phy_linkrates *r)
1123 struct sas_phy_linkrates _r;
1125 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1126 struct asd_sas_phy *sas_phy = &phy->sas_phy;
1127 enum sas_linkrate min, max;
1129 if (r->minimum_linkrate > SAS_LINK_RATE_1_5_GBPS)
1132 if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) {
1133 max = sas_phy->phy->maximum_linkrate;
1134 min = r->minimum_linkrate;
1135 } else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) {
1136 max = r->maximum_linkrate;
1137 min = sas_phy->phy->minimum_linkrate;
1141 _r.maximum_linkrate = max;
1142 _r.minimum_linkrate = min;
1144 sas_phy->phy->maximum_linkrate = max;
1145 sas_phy->phy->minimum_linkrate = min;
1147 hisi_sas_phy_enable(hisi_hba, phy_no, 0);
1149 hisi_hba->hw->phy_set_linkrate(hisi_hba, phy_no, &_r);
1150 hisi_sas_phy_enable(hisi_hba, phy_no, 1);
1155 static int hisi_sas_control_phy(struct asd_sas_phy *sas_phy, enum phy_func func,
1158 struct hisi_sas_phy *phy = container_of(sas_phy,
1159 struct hisi_sas_phy, sas_phy);
1160 struct sas_ha_struct *sas_ha = sas_phy->ha;
1161 struct hisi_hba *hisi_hba = sas_ha->lldd_ha;
1162 struct device *dev = hisi_hba->dev;
1163 DECLARE_COMPLETION_ONSTACK(completion);
1164 int phy_no = sas_phy->id;
1165 u8 sts = phy->phy_attached;
1168 down(&hisi_hba->sem);
1169 phy->reset_completion = &completion;
1172 case PHY_FUNC_HARD_RESET:
1173 hisi_hba->hw->phy_hard_reset(hisi_hba, phy_no);
1176 case PHY_FUNC_LINK_RESET:
1177 hisi_sas_phy_enable(hisi_hba, phy_no, 0);
1179 hisi_sas_phy_enable(hisi_hba, phy_no, 1);
1182 case PHY_FUNC_DISABLE:
1183 hisi_sas_phy_enable(hisi_hba, phy_no, 0);
1186 case PHY_FUNC_SET_LINK_RATE:
1187 ret = hisi_sas_phy_set_linkrate(hisi_hba, phy_no, funcdata);
1190 case PHY_FUNC_GET_EVENTS:
1191 if (hisi_hba->hw->get_events) {
1192 hisi_hba->hw->get_events(hisi_hba, phy_no);
1196 case PHY_FUNC_RELEASE_SPINUP_HOLD:
1202 if (sts && !wait_for_completion_timeout(&completion, 2 * HZ)) {
1203 dev_warn(dev, "phy%d wait phyup timed out for func %d\n",
1210 phy->reset_completion = NULL;
1216 static void hisi_sas_task_done(struct sas_task *task)
1218 del_timer_sync(&task->slow_task->timer);
1219 complete(&task->slow_task->completion);
1222 static void hisi_sas_tmf_timedout(struct timer_list *t)
1224 struct sas_task_slow *slow = from_timer(slow, t, timer);
1225 struct sas_task *task = slow->task;
1226 unsigned long flags;
1227 bool is_completed = true;
1229 spin_lock_irqsave(&task->task_state_lock, flags);
1230 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
1231 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
1232 is_completed = false;
1234 spin_unlock_irqrestore(&task->task_state_lock, flags);
1237 complete(&task->slow_task->completion);
1240 #define TASK_TIMEOUT (20 * HZ)
1241 #define TASK_RETRY 3
1242 #define INTERNAL_ABORT_TIMEOUT (6 * HZ)
1243 static int hisi_sas_exec_internal_tmf_task(struct domain_device *device,
1244 void *parameter, u32 para_len,
1245 struct hisi_sas_tmf_task *tmf)
1247 struct hisi_sas_device *sas_dev = device->lldd_dev;
1248 struct hisi_hba *hisi_hba = sas_dev->hisi_hba;
1249 struct device *dev = hisi_hba->dev;
1250 struct sas_task *task;
1253 for (retry = 0; retry < TASK_RETRY; retry++) {
1254 task = sas_alloc_slow_task(GFP_KERNEL);
1259 task->task_proto = device->tproto;
1261 if (dev_is_sata(device)) {
1262 task->ata_task.device_control_reg_update = 1;
1263 memcpy(&task->ata_task.fis, parameter, para_len);
1265 memcpy(&task->ssp_task, parameter, para_len);
1267 task->task_done = hisi_sas_task_done;
1269 task->slow_task->timer.function = hisi_sas_tmf_timedout;
1270 task->slow_task->timer.expires = jiffies + TASK_TIMEOUT;
1271 add_timer(&task->slow_task->timer);
1273 res = hisi_sas_task_exec(task, GFP_KERNEL, tmf);
1275 del_timer_sync(&task->slow_task->timer);
1276 dev_err(dev, "abort tmf: executing internal task failed: %d\n",
1281 wait_for_completion(&task->slow_task->completion);
1282 res = TMF_RESP_FUNC_FAILED;
1283 /* Even TMF timed out, return direct. */
1284 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
1285 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
1286 struct hisi_sas_slot *slot = task->lldd_task;
1288 dev_err(dev, "abort tmf: TMF task timeout and not done\n");
1290 struct hisi_sas_cq *cq =
1291 &hisi_hba->cq[slot->dlvry_queue];
1293 * sync irq to avoid free'ing task
1294 * before using task in IO completion
1296 synchronize_irq(cq->irq_no);
1302 dev_err(dev, "abort tmf: TMF task timeout\n");
1305 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1306 task->task_status.stat == TMF_RESP_FUNC_COMPLETE) {
1307 res = TMF_RESP_FUNC_COMPLETE;
1311 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1312 task->task_status.stat == TMF_RESP_FUNC_SUCC) {
1313 res = TMF_RESP_FUNC_SUCC;
1317 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1318 task->task_status.stat == SAS_DATA_UNDERRUN) {
1319 /* no error, but return the number of bytes of
1322 dev_warn(dev, "abort tmf: task to dev %016llx resp: 0x%x sts 0x%x underrun\n",
1323 SAS_ADDR(device->sas_addr),
1324 task->task_status.resp,
1325 task->task_status.stat);
1326 res = task->task_status.residual;
1330 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1331 task->task_status.stat == SAS_DATA_OVERRUN) {
1332 dev_warn(dev, "abort tmf: blocked task error\n");
1337 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1338 task->task_status.stat == SAS_OPEN_REJECT) {
1339 dev_warn(dev, "abort tmf: open reject failed\n");
1342 dev_warn(dev, "abort tmf: task to dev %016llx resp: 0x%x status 0x%x\n",
1343 SAS_ADDR(device->sas_addr),
1344 task->task_status.resp,
1345 task->task_status.stat);
1347 sas_free_task(task);
1351 if (retry == TASK_RETRY)
1352 dev_warn(dev, "abort tmf: executing internal task failed!\n");
1353 sas_free_task(task);
1357 static void hisi_sas_fill_ata_reset_cmd(struct ata_device *dev,
1358 bool reset, int pmp, u8 *fis)
1360 struct ata_taskfile tf;
1362 ata_tf_init(dev, &tf);
1366 tf.ctl &= ~ATA_SRST;
1367 tf.command = ATA_CMD_DEV_RESET;
1368 ata_tf_to_fis(&tf, pmp, 0, fis);
1371 static int hisi_sas_softreset_ata_disk(struct domain_device *device)
1374 struct ata_port *ap = device->sata_dev.ap;
1375 struct ata_link *link;
1376 int rc = TMF_RESP_FUNC_FAILED;
1377 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1378 struct device *dev = hisi_hba->dev;
1379 int s = sizeof(struct host_to_dev_fis);
1380 struct hisi_sas_tmf_task tmf = {};
1382 ata_for_each_link(link, ap, EDGE) {
1383 int pmp = sata_srst_pmp(link);
1385 hisi_sas_fill_ata_reset_cmd(link->device, 1, pmp, fis);
1386 rc = hisi_sas_exec_internal_tmf_task(device, fis, s, &tmf);
1387 if (rc != TMF_RESP_FUNC_COMPLETE)
1391 if (rc == TMF_RESP_FUNC_COMPLETE) {
1392 ata_for_each_link(link, ap, EDGE) {
1393 int pmp = sata_srst_pmp(link);
1395 hisi_sas_fill_ata_reset_cmd(link->device, 0, pmp, fis);
1396 rc = hisi_sas_exec_internal_tmf_task(device, fis,
1398 if (rc != TMF_RESP_FUNC_COMPLETE)
1399 dev_err(dev, "ata disk %016llx de-reset failed\n",
1400 SAS_ADDR(device->sas_addr));
1403 dev_err(dev, "ata disk %016llx reset failed\n",
1404 SAS_ADDR(device->sas_addr));
1407 if (rc == TMF_RESP_FUNC_COMPLETE)
1408 hisi_sas_release_task(hisi_hba, device);
1413 static int hisi_sas_debug_issue_ssp_tmf(struct domain_device *device,
1414 u8 *lun, struct hisi_sas_tmf_task *tmf)
1416 struct sas_ssp_task ssp_task;
1418 if (!(device->tproto & SAS_PROTOCOL_SSP))
1419 return TMF_RESP_FUNC_ESUPP;
1421 memcpy(ssp_task.LUN, lun, 8);
1423 return hisi_sas_exec_internal_tmf_task(device, &ssp_task,
1424 sizeof(ssp_task), tmf);
1427 static void hisi_sas_refresh_port_id(struct hisi_hba *hisi_hba)
1429 u32 state = hisi_hba->hw->get_phys_state(hisi_hba);
1432 for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
1433 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i];
1434 struct domain_device *device = sas_dev->sas_device;
1435 struct asd_sas_port *sas_port;
1436 struct hisi_sas_port *port;
1437 struct hisi_sas_phy *phy = NULL;
1438 struct asd_sas_phy *sas_phy;
1440 if ((sas_dev->dev_type == SAS_PHY_UNUSED)
1441 || !device || !device->port)
1444 sas_port = device->port;
1445 port = to_hisi_sas_port(sas_port);
1447 spin_lock(&sas_port->phy_list_lock);
1448 list_for_each_entry(sas_phy, &sas_port->phy_list, port_phy_el)
1449 if (state & BIT(sas_phy->id)) {
1450 phy = sas_phy->lldd_phy;
1453 spin_unlock(&sas_port->phy_list_lock);
1456 port->id = phy->port_id;
1458 /* Update linkrate of directly attached device. */
1459 if (!device->parent)
1460 device->linkrate = phy->sas_phy.linkrate;
1462 hisi_hba->hw->setup_itct(hisi_hba, sas_dev);
1468 static void hisi_sas_rescan_topology(struct hisi_hba *hisi_hba, u32 state)
1470 struct asd_sas_port *_sas_port = NULL;
1473 for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) {
1474 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1475 struct asd_sas_phy *sas_phy = &phy->sas_phy;
1476 struct asd_sas_port *sas_port = sas_phy->port;
1477 bool do_port_check = _sas_port != sas_port;
1479 if (!sas_phy->phy->enabled)
1482 /* Report PHY state change to libsas */
1483 if (state & BIT(phy_no)) {
1484 if (do_port_check && sas_port && sas_port->port_dev) {
1485 struct domain_device *dev = sas_port->port_dev;
1487 _sas_port = sas_port;
1489 if (dev_is_expander(dev->dev_type))
1490 sas_notify_port_event(sas_phy,
1491 PORTE_BROADCAST_RCVD,
1495 hisi_sas_phy_down(hisi_hba, phy_no, 0, GFP_KERNEL);
1500 static void hisi_sas_reset_init_all_devices(struct hisi_hba *hisi_hba)
1502 struct hisi_sas_device *sas_dev;
1503 struct domain_device *device;
1506 for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
1507 sas_dev = &hisi_hba->devices[i];
1508 device = sas_dev->sas_device;
1510 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device)
1513 hisi_sas_init_device(device);
1517 static void hisi_sas_send_ata_reset_each_phy(struct hisi_hba *hisi_hba,
1518 struct asd_sas_port *sas_port,
1519 struct domain_device *device)
1521 struct hisi_sas_tmf_task tmf_task = { .force_phy = 1 };
1522 struct ata_port *ap = device->sata_dev.ap;
1523 struct device *dev = hisi_hba->dev;
1524 int s = sizeof(struct host_to_dev_fis);
1525 int rc = TMF_RESP_FUNC_FAILED;
1526 struct ata_link *link;
1530 for (i = 0; i < hisi_hba->n_phy; i++) {
1531 if (!(sas_port->phy_mask & BIT(i)))
1534 ata_for_each_link(link, ap, EDGE) {
1535 int pmp = sata_srst_pmp(link);
1537 tmf_task.phy_id = i;
1538 hisi_sas_fill_ata_reset_cmd(link->device, 1, pmp, fis);
1539 rc = hisi_sas_exec_internal_tmf_task(device, fis, s,
1541 if (rc != TMF_RESP_FUNC_COMPLETE) {
1542 dev_err(dev, "phy%d ata reset failed rc=%d\n",
1550 static void hisi_sas_terminate_stp_reject(struct hisi_hba *hisi_hba)
1552 struct device *dev = hisi_hba->dev;
1555 for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
1556 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i];
1557 struct domain_device *device = sas_dev->sas_device;
1559 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device)
1562 rc = hisi_sas_internal_task_abort(hisi_hba, device,
1563 HISI_SAS_INT_ABT_DEV, 0,
1566 dev_err(dev, "STP reject: abort dev failed %d\n", rc);
1569 for (port_no = 0; port_no < hisi_hba->n_phy; port_no++) {
1570 struct hisi_sas_port *port = &hisi_hba->port[port_no];
1571 struct asd_sas_port *sas_port = &port->sas_port;
1572 struct domain_device *port_dev = sas_port->port_dev;
1573 struct domain_device *device;
1575 if (!port_dev || !dev_is_expander(port_dev->dev_type))
1578 /* Try to find a SATA device */
1579 list_for_each_entry(device, &sas_port->dev_list,
1581 if (dev_is_sata(device)) {
1582 hisi_sas_send_ata_reset_each_phy(hisi_hba,
1591 void hisi_sas_controller_reset_prepare(struct hisi_hba *hisi_hba)
1593 struct Scsi_Host *shost = hisi_hba->shost;
1595 hisi_hba->phy_state = hisi_hba->hw->get_phys_state(hisi_hba);
1597 scsi_block_requests(shost);
1598 hisi_hba->hw->wait_cmds_complete_timeout(hisi_hba, 100, 5000);
1600 del_timer_sync(&hisi_hba->timer);
1602 set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
1604 EXPORT_SYMBOL_GPL(hisi_sas_controller_reset_prepare);
1606 void hisi_sas_controller_reset_done(struct hisi_hba *hisi_hba)
1608 struct Scsi_Host *shost = hisi_hba->shost;
1610 /* Init and wait for PHYs to come up and all libsas event finished. */
1611 hisi_hba->hw->phys_init(hisi_hba);
1613 hisi_sas_refresh_port_id(hisi_hba);
1614 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
1616 if (hisi_hba->reject_stp_links_msk)
1617 hisi_sas_terminate_stp_reject(hisi_hba);
1618 hisi_sas_reset_init_all_devices(hisi_hba);
1619 scsi_unblock_requests(shost);
1620 clear_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags);
1623 hisi_sas_rescan_topology(hisi_hba, hisi_hba->phy_state);
1625 EXPORT_SYMBOL_GPL(hisi_sas_controller_reset_done);
1627 static int hisi_sas_controller_prereset(struct hisi_hba *hisi_hba)
1629 if (!hisi_hba->hw->soft_reset)
1632 down(&hisi_hba->sem);
1633 if (test_and_set_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags)) {
1638 if (hisi_sas_debugfs_enable && hisi_hba->debugfs_itct[0].itct)
1639 hisi_hba->hw->debugfs_snapshot_regs(hisi_hba);
1644 static int hisi_sas_controller_reset(struct hisi_hba *hisi_hba)
1646 struct device *dev = hisi_hba->dev;
1647 struct Scsi_Host *shost = hisi_hba->shost;
1650 dev_info(dev, "controller resetting...\n");
1651 hisi_sas_controller_reset_prepare(hisi_hba);
1653 rc = hisi_hba->hw->soft_reset(hisi_hba);
1655 dev_warn(dev, "controller reset failed (%d)\n", rc);
1656 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
1658 scsi_unblock_requests(shost);
1659 clear_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags);
1663 hisi_sas_controller_reset_done(hisi_hba);
1664 clear_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags);
1665 dev_info(dev, "controller reset complete\n");
1670 static int hisi_sas_abort_task(struct sas_task *task)
1672 struct scsi_lun lun;
1673 struct hisi_sas_tmf_task tmf_task;
1674 struct domain_device *device = task->dev;
1675 struct hisi_sas_device *sas_dev = device->lldd_dev;
1676 struct hisi_hba *hisi_hba;
1678 int rc = TMF_RESP_FUNC_FAILED;
1679 unsigned long flags;
1682 return TMF_RESP_FUNC_FAILED;
1684 hisi_hba = dev_to_hisi_hba(task->dev);
1685 dev = hisi_hba->dev;
1687 spin_lock_irqsave(&task->task_state_lock, flags);
1688 if (task->task_state_flags & SAS_TASK_STATE_DONE) {
1689 struct hisi_sas_slot *slot = task->lldd_task;
1690 struct hisi_sas_cq *cq;
1694 * sync irq to avoid free'ing task
1695 * before using task in IO completion
1697 cq = &hisi_hba->cq[slot->dlvry_queue];
1698 synchronize_irq(cq->irq_no);
1700 spin_unlock_irqrestore(&task->task_state_lock, flags);
1701 rc = TMF_RESP_FUNC_COMPLETE;
1704 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
1705 spin_unlock_irqrestore(&task->task_state_lock, flags);
1707 if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) {
1708 struct scsi_cmnd *cmnd = task->uldd_task;
1709 struct hisi_sas_slot *slot = task->lldd_task;
1710 u16 tag = slot->idx;
1713 int_to_scsilun(cmnd->device->lun, &lun);
1714 tmf_task.tmf = TMF_ABORT_TASK;
1715 tmf_task.tag_of_task_to_be_managed = tag;
1717 rc = hisi_sas_debug_issue_ssp_tmf(task->dev, lun.scsi_lun,
1720 rc2 = hisi_sas_internal_task_abort(hisi_hba, device,
1721 HISI_SAS_INT_ABT_CMD, tag,
1724 dev_err(dev, "abort task: internal abort (%d)\n", rc2);
1725 return TMF_RESP_FUNC_FAILED;
1729 * If the TMF finds that the IO is not in the device and also
1730 * the internal abort does not succeed, then it is safe to
1732 * Note: if the internal abort succeeds then the slot
1733 * will have already been completed
1735 if (rc == TMF_RESP_FUNC_COMPLETE && rc2 != TMF_RESP_FUNC_SUCC) {
1736 if (task->lldd_task)
1737 hisi_sas_do_release_task(hisi_hba, task, slot);
1739 } else if (task->task_proto & SAS_PROTOCOL_SATA ||
1740 task->task_proto & SAS_PROTOCOL_STP) {
1741 if (task->dev->dev_type == SAS_SATA_DEV) {
1742 rc = hisi_sas_internal_task_abort(hisi_hba, device,
1743 HISI_SAS_INT_ABT_DEV,
1746 dev_err(dev, "abort task: internal abort failed\n");
1749 hisi_sas_dereg_device(hisi_hba, device);
1750 rc = hisi_sas_softreset_ata_disk(device);
1752 } else if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SMP) {
1754 struct hisi_sas_slot *slot = task->lldd_task;
1755 u32 tag = slot->idx;
1756 struct hisi_sas_cq *cq = &hisi_hba->cq[slot->dlvry_queue];
1758 rc = hisi_sas_internal_task_abort(hisi_hba, device,
1759 HISI_SAS_INT_ABT_CMD, tag,
1761 if (((rc < 0) || (rc == TMF_RESP_FUNC_FAILED)) &&
1764 * sync irq to avoid free'ing task
1765 * before using task in IO completion
1767 synchronize_irq(cq->irq_no);
1773 if (rc != TMF_RESP_FUNC_COMPLETE)
1774 dev_notice(dev, "abort task: rc=%d\n", rc);
1778 static int hisi_sas_abort_task_set(struct domain_device *device, u8 *lun)
1780 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1781 struct device *dev = hisi_hba->dev;
1782 struct hisi_sas_tmf_task tmf_task;
1785 rc = hisi_sas_internal_task_abort(hisi_hba, device,
1786 HISI_SAS_INT_ABT_DEV, 0, false);
1788 dev_err(dev, "abort task set: internal abort rc=%d\n", rc);
1789 return TMF_RESP_FUNC_FAILED;
1791 hisi_sas_dereg_device(hisi_hba, device);
1793 tmf_task.tmf = TMF_ABORT_TASK_SET;
1794 rc = hisi_sas_debug_issue_ssp_tmf(device, lun, &tmf_task);
1796 if (rc == TMF_RESP_FUNC_COMPLETE)
1797 hisi_sas_release_task(hisi_hba, device);
1802 static int hisi_sas_clear_aca(struct domain_device *device, u8 *lun)
1804 struct hisi_sas_tmf_task tmf_task;
1807 tmf_task.tmf = TMF_CLEAR_ACA;
1808 rc = hisi_sas_debug_issue_ssp_tmf(device, lun, &tmf_task);
1813 #define I_T_NEXUS_RESET_PHYUP_TIMEOUT (2 * HZ)
1815 static int hisi_sas_debug_I_T_nexus_reset(struct domain_device *device)
1817 struct sas_phy *local_phy = sas_get_local_phy(device);
1818 struct hisi_sas_device *sas_dev = device->lldd_dev;
1819 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1820 struct sas_ha_struct *sas_ha = &hisi_hba->sha;
1823 if (!local_phy->enabled) {
1824 sas_put_local_phy(local_phy);
1828 if (scsi_is_sas_phy_local(local_phy)) {
1829 struct asd_sas_phy *sas_phy =
1830 sas_ha->sas_phy[local_phy->number];
1831 struct hisi_sas_phy *phy =
1832 container_of(sas_phy, struct hisi_sas_phy, sas_phy);
1833 unsigned long flags;
1835 spin_lock_irqsave(&phy->lock, flags);
1837 spin_unlock_irqrestore(&phy->lock, flags);
1840 reset_type = (sas_dev->dev_status == HISI_SAS_DEV_INIT ||
1841 !dev_is_sata(device)) ? true : false;
1843 rc = sas_phy_reset(local_phy, reset_type);
1844 sas_put_local_phy(local_phy);
1846 if (scsi_is_sas_phy_local(local_phy)) {
1847 struct asd_sas_phy *sas_phy =
1848 sas_ha->sas_phy[local_phy->number];
1849 struct hisi_sas_phy *phy =
1850 container_of(sas_phy, struct hisi_sas_phy, sas_phy);
1851 unsigned long flags;
1853 spin_lock_irqsave(&phy->lock, flags);
1855 spin_unlock_irqrestore(&phy->lock, flags);
1857 /* report PHY down if timed out */
1858 if (rc == -ETIMEDOUT)
1859 hisi_sas_phy_down(hisi_hba, sas_phy->id, 0, GFP_KERNEL);
1860 } else if (sas_dev->dev_status != HISI_SAS_DEV_INIT) {
1862 * If in init state, we rely on caller to wait for link to be
1863 * ready; otherwise, except phy reset is fail, delay.
1872 static int hisi_sas_I_T_nexus_reset(struct domain_device *device)
1874 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1875 struct device *dev = hisi_hba->dev;
1878 rc = hisi_sas_internal_task_abort(hisi_hba, device,
1879 HISI_SAS_INT_ABT_DEV, 0, false);
1881 dev_err(dev, "I_T nexus reset: internal abort (%d)\n", rc);
1882 return TMF_RESP_FUNC_FAILED;
1884 hisi_sas_dereg_device(hisi_hba, device);
1886 rc = hisi_sas_debug_I_T_nexus_reset(device);
1887 if (rc == TMF_RESP_FUNC_COMPLETE && dev_is_sata(device)) {
1888 struct sas_phy *local_phy;
1890 rc = hisi_sas_softreset_ata_disk(device);
1895 case TMF_RESP_FUNC_FAILED:
1898 local_phy = sas_get_local_phy(device);
1899 rc = sas_phy_enable(local_phy, 0);
1901 local_phy->enabled = 0;
1902 dev_err(dev, "Disabled local phy of ATA disk %016llx due to softreset fail (%d)\n",
1903 SAS_ADDR(device->sas_addr), rc);
1906 sas_put_local_phy(local_phy);
1913 if ((rc == TMF_RESP_FUNC_COMPLETE) || (rc == -ENODEV))
1914 hisi_sas_release_task(hisi_hba, device);
1919 static int hisi_sas_lu_reset(struct domain_device *device, u8 *lun)
1921 struct hisi_sas_device *sas_dev = device->lldd_dev;
1922 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1923 struct device *dev = hisi_hba->dev;
1924 int rc = TMF_RESP_FUNC_FAILED;
1926 /* Clear internal IO and then lu reset */
1927 rc = hisi_sas_internal_task_abort(hisi_hba, device,
1928 HISI_SAS_INT_ABT_DEV, 0, false);
1930 dev_err(dev, "lu_reset: internal abort failed\n");
1933 hisi_sas_dereg_device(hisi_hba, device);
1935 if (dev_is_sata(device)) {
1936 struct sas_phy *phy;
1938 phy = sas_get_local_phy(device);
1940 rc = sas_phy_reset(phy, true);
1943 hisi_sas_release_task(hisi_hba, device);
1944 sas_put_local_phy(phy);
1946 struct hisi_sas_tmf_task tmf_task = { .tmf = TMF_LU_RESET };
1948 rc = hisi_sas_debug_issue_ssp_tmf(device, lun, &tmf_task);
1949 if (rc == TMF_RESP_FUNC_COMPLETE)
1950 hisi_sas_release_task(hisi_hba, device);
1953 if (rc != TMF_RESP_FUNC_COMPLETE)
1954 dev_err(dev, "lu_reset: for device[%d]:rc= %d\n",
1955 sas_dev->device_id, rc);
1959 static void hisi_sas_async_I_T_nexus_reset(void *data, async_cookie_t cookie)
1961 struct domain_device *device = data;
1962 struct hisi_hba *hisi_hba = dev_to_hisi_hba(device);
1965 rc = hisi_sas_debug_I_T_nexus_reset(device);
1966 if (rc != TMF_RESP_FUNC_COMPLETE)
1967 dev_info(hisi_hba->dev, "I_T_nexus reset fail for dev:%016llx rc=%d\n",
1968 SAS_ADDR(device->sas_addr), rc);
1971 static int hisi_sas_clear_nexus_ha(struct sas_ha_struct *sas_ha)
1973 struct hisi_hba *hisi_hba = sas_ha->lldd_ha;
1974 HISI_SAS_DECLARE_RST_WORK_ON_STACK(r);
1975 ASYNC_DOMAIN_EXCLUSIVE(async);
1978 queue_work(hisi_hba->wq, &r.work);
1979 wait_for_completion(r.completion);
1981 return TMF_RESP_FUNC_FAILED;
1983 for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
1984 struct hisi_sas_device *sas_dev = &hisi_hba->devices[i];
1985 struct domain_device *device = sas_dev->sas_device;
1987 if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device ||
1988 dev_is_expander(device->dev_type))
1991 async_schedule_domain(hisi_sas_async_I_T_nexus_reset,
1995 async_synchronize_full_domain(&async);
1996 hisi_sas_release_tasks(hisi_hba);
1998 return TMF_RESP_FUNC_COMPLETE;
2001 static int hisi_sas_query_task(struct sas_task *task)
2003 struct scsi_lun lun;
2004 struct hisi_sas_tmf_task tmf_task;
2005 int rc = TMF_RESP_FUNC_FAILED;
2007 if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) {
2008 struct scsi_cmnd *cmnd = task->uldd_task;
2009 struct domain_device *device = task->dev;
2010 struct hisi_sas_slot *slot = task->lldd_task;
2011 u32 tag = slot->idx;
2013 int_to_scsilun(cmnd->device->lun, &lun);
2014 tmf_task.tmf = TMF_QUERY_TASK;
2015 tmf_task.tag_of_task_to_be_managed = tag;
2017 rc = hisi_sas_debug_issue_ssp_tmf(device,
2021 /* The task is still in Lun, release it then */
2022 case TMF_RESP_FUNC_SUCC:
2023 /* The task is not in Lun or failed, reset the phy */
2024 case TMF_RESP_FUNC_FAILED:
2025 case TMF_RESP_FUNC_COMPLETE:
2028 rc = TMF_RESP_FUNC_FAILED;
2036 hisi_sas_internal_abort_task_exec(struct hisi_hba *hisi_hba, int device_id,
2037 struct hisi_sas_internal_abort *abort,
2038 struct sas_task *task,
2039 struct hisi_sas_dq *dq)
2041 struct domain_device *device = task->dev;
2042 struct hisi_sas_device *sas_dev = device->lldd_dev;
2043 struct device *dev = hisi_hba->dev;
2044 struct hisi_sas_port *port;
2045 struct asd_sas_port *sas_port = device->port;
2046 struct hisi_sas_slot *slot;
2049 if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags)))
2055 port = to_hisi_sas_port(sas_port);
2057 /* simply get a slot and send abort command */
2058 slot_idx = hisi_sas_slot_index_alloc(hisi_hba, NULL);
2062 slot = &hisi_hba->slot_info[slot_idx];
2066 slot->is_internal = true;
2068 hisi_sas_task_deliver(hisi_hba, slot, dq, sas_dev, abort);
2073 dev_err(dev, "internal abort task prep: failed[%d]!\n", slot_idx);
2079 * _hisi_sas_internal_task_abort -- execute an internal
2080 * abort command for single IO command or a device
2081 * @hisi_hba: host controller struct
2082 * @device: domain device
2083 * @abort_flag: mode of operation, device or single IO
2084 * @tag: tag of IO to be aborted (only relevant to single
2086 * @dq: delivery queue for this internal abort command
2087 * @rst_to_recover: If rst_to_recover set, queue a controller
2088 * reset if an internal abort times out.
2091 _hisi_sas_internal_task_abort(struct hisi_hba *hisi_hba,
2092 struct domain_device *device, int abort_flag,
2093 int tag, struct hisi_sas_dq *dq, bool rst_to_recover)
2095 struct sas_task *task;
2096 struct hisi_sas_device *sas_dev = device->lldd_dev;
2097 struct hisi_sas_internal_abort abort = {
2101 struct device *dev = hisi_hba->dev;
2104 * The interface is not realized means this HW don't support internal
2105 * abort, or don't need to do internal abort. Then here, we return
2106 * TMF_RESP_FUNC_FAILED and let other steps go on, which depends that
2107 * the internal abort has been executed and returned CQ.
2109 if (!hisi_hba->hw->prep_abort)
2110 return TMF_RESP_FUNC_FAILED;
2112 if (test_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags))
2115 task = sas_alloc_slow_task(GFP_KERNEL);
2120 task->task_proto = SAS_PROTOCOL_NONE;
2121 task->task_done = hisi_sas_task_done;
2122 task->slow_task->timer.function = hisi_sas_tmf_timedout;
2123 task->slow_task->timer.expires = jiffies + INTERNAL_ABORT_TIMEOUT;
2124 add_timer(&task->slow_task->timer);
2126 res = hisi_sas_internal_abort_task_exec(hisi_hba, sas_dev->device_id,
2129 del_timer_sync(&task->slow_task->timer);
2130 dev_err(dev, "internal task abort: executing internal task failed: %d\n",
2134 wait_for_completion(&task->slow_task->completion);
2135 res = TMF_RESP_FUNC_FAILED;
2137 /* Internal abort timed out */
2138 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
2139 if (hisi_sas_debugfs_enable && hisi_hba->debugfs_itct[0].itct)
2140 queue_work(hisi_hba->wq, &hisi_hba->debugfs_work);
2142 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
2143 struct hisi_sas_slot *slot = task->lldd_task;
2145 set_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags);
2148 struct hisi_sas_cq *cq =
2149 &hisi_hba->cq[slot->dlvry_queue];
2151 * sync irq to avoid free'ing task
2152 * before using task in IO completion
2154 synchronize_irq(cq->irq_no);
2158 if (rst_to_recover) {
2159 dev_err(dev, "internal task abort: timeout and not done. Queuing reset.\n");
2160 queue_work(hisi_hba->wq, &hisi_hba->rst_work);
2162 dev_err(dev, "internal task abort: timeout and not done.\n");
2168 dev_err(dev, "internal task abort: timeout.\n");
2171 if (task->task_status.resp == SAS_TASK_COMPLETE &&
2172 task->task_status.stat == TMF_RESP_FUNC_COMPLETE) {
2173 res = TMF_RESP_FUNC_COMPLETE;
2177 if (task->task_status.resp == SAS_TASK_COMPLETE &&
2178 task->task_status.stat == TMF_RESP_FUNC_SUCC) {
2179 res = TMF_RESP_FUNC_SUCC;
2184 dev_dbg(dev, "internal task abort: task to dev %016llx task=%pK resp: 0x%x sts 0x%x\n",
2185 SAS_ADDR(device->sas_addr), task,
2186 task->task_status.resp, /* 0 is complete, -1 is undelivered */
2187 task->task_status.stat);
2188 sas_free_task(task);
2194 hisi_sas_internal_task_abort(struct hisi_hba *hisi_hba,
2195 struct domain_device *device,
2196 int abort_flag, int tag, bool rst_to_recover)
2198 struct hisi_sas_slot *slot;
2199 struct device *dev = hisi_hba->dev;
2200 struct hisi_sas_dq *dq;
2203 switch (abort_flag) {
2204 case HISI_SAS_INT_ABT_CMD:
2205 slot = &hisi_hba->slot_info[tag];
2206 dq = &hisi_hba->dq[slot->dlvry_queue];
2207 return _hisi_sas_internal_task_abort(hisi_hba, device,
2208 abort_flag, tag, dq,
2210 case HISI_SAS_INT_ABT_DEV:
2211 for (i = 0; i < hisi_hba->cq_nvecs; i++) {
2212 struct hisi_sas_cq *cq = &hisi_hba->cq[i];
2213 const struct cpumask *mask = cq->irq_mask;
2215 if (mask && !cpumask_intersects(cpu_online_mask, mask))
2217 dq = &hisi_hba->dq[i];
2218 rc = _hisi_sas_internal_task_abort(hisi_hba, device,
2220 dq, rst_to_recover);
2226 dev_err(dev, "Unrecognised internal abort flag (%d)\n",
2234 static void hisi_sas_port_formed(struct asd_sas_phy *sas_phy)
2236 hisi_sas_port_notify_formed(sas_phy);
2239 static int hisi_sas_write_gpio(struct sas_ha_struct *sha, u8 reg_type,
2240 u8 reg_index, u8 reg_count, u8 *write_data)
2242 struct hisi_hba *hisi_hba = sha->lldd_ha;
2244 if (!hisi_hba->hw->write_gpio)
2247 return hisi_hba->hw->write_gpio(hisi_hba, reg_type,
2248 reg_index, reg_count, write_data);
2251 static void hisi_sas_phy_disconnected(struct hisi_sas_phy *phy)
2253 struct asd_sas_phy *sas_phy = &phy->sas_phy;
2254 struct sas_phy *sphy = sas_phy->phy;
2255 unsigned long flags;
2257 phy->phy_attached = 0;
2261 spin_lock_irqsave(&phy->lock, flags);
2263 sphy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
2265 sphy->negotiated_linkrate = SAS_PHY_DISABLED;
2266 spin_unlock_irqrestore(&phy->lock, flags);
2269 void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy,
2272 struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
2273 struct asd_sas_phy *sas_phy = &phy->sas_phy;
2274 struct device *dev = hisi_hba->dev;
2277 /* Phy down but ready */
2278 hisi_sas_bytes_dmaed(hisi_hba, phy_no, gfp_flags);
2279 hisi_sas_port_notify_formed(sas_phy);
2281 struct hisi_sas_port *port = phy->port;
2283 if (test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags) ||
2285 dev_info(dev, "ignore flutter phy%d down\n", phy_no);
2288 /* Phy down and not ready */
2289 sas_notify_phy_event(sas_phy, PHYE_LOSS_OF_SIGNAL, gfp_flags);
2290 sas_phy_disconnected(sas_phy);
2293 if (phy->phy_type & PORT_TYPE_SAS) {
2294 int port_id = port->id;
2296 if (!hisi_hba->hw->get_wideport_bitmap(hisi_hba,
2298 port->port_attached = 0;
2299 } else if (phy->phy_type & PORT_TYPE_SATA)
2300 port->port_attached = 0;
2302 hisi_sas_phy_disconnected(phy);
2305 EXPORT_SYMBOL_GPL(hisi_sas_phy_down);
2307 void hisi_sas_sync_irqs(struct hisi_hba *hisi_hba)
2311 for (i = 0; i < hisi_hba->cq_nvecs; i++) {
2312 struct hisi_sas_cq *cq = &hisi_hba->cq[i];
2314 synchronize_irq(cq->irq_no);
2317 EXPORT_SYMBOL_GPL(hisi_sas_sync_irqs);
2319 int hisi_sas_host_reset(struct Scsi_Host *shost, int reset_type)
2321 struct hisi_hba *hisi_hba = shost_priv(shost);
2323 if (reset_type != SCSI_ADAPTER_RESET)
2326 queue_work(hisi_hba->wq, &hisi_hba->rst_work);
2330 EXPORT_SYMBOL_GPL(hisi_sas_host_reset);
2332 struct scsi_transport_template *hisi_sas_stt;
2333 EXPORT_SYMBOL_GPL(hisi_sas_stt);
2335 static struct sas_domain_function_template hisi_sas_transport_ops = {
2336 .lldd_dev_found = hisi_sas_dev_found,
2337 .lldd_dev_gone = hisi_sas_dev_gone,
2338 .lldd_execute_task = hisi_sas_queue_command,
2339 .lldd_control_phy = hisi_sas_control_phy,
2340 .lldd_abort_task = hisi_sas_abort_task,
2341 .lldd_abort_task_set = hisi_sas_abort_task_set,
2342 .lldd_clear_aca = hisi_sas_clear_aca,
2343 .lldd_I_T_nexus_reset = hisi_sas_I_T_nexus_reset,
2344 .lldd_lu_reset = hisi_sas_lu_reset,
2345 .lldd_query_task = hisi_sas_query_task,
2346 .lldd_clear_nexus_ha = hisi_sas_clear_nexus_ha,
2347 .lldd_port_formed = hisi_sas_port_formed,
2348 .lldd_write_gpio = hisi_sas_write_gpio,
2351 void hisi_sas_init_mem(struct hisi_hba *hisi_hba)
2353 int i, s, j, max_command_entries = HISI_SAS_MAX_COMMANDS;
2354 struct hisi_sas_breakpoint *sata_breakpoint = hisi_hba->sata_breakpoint;
2356 for (i = 0; i < hisi_hba->queue_count; i++) {
2357 struct hisi_sas_cq *cq = &hisi_hba->cq[i];
2358 struct hisi_sas_dq *dq = &hisi_hba->dq[i];
2359 struct hisi_sas_cmd_hdr *cmd_hdr = hisi_hba->cmd_hdr[i];
2361 s = sizeof(struct hisi_sas_cmd_hdr);
2362 for (j = 0; j < HISI_SAS_QUEUE_SLOTS; j++)
2363 memset(&cmd_hdr[j], 0, s);
2367 s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS;
2368 memset(hisi_hba->complete_hdr[i], 0, s);
2372 s = sizeof(struct hisi_sas_initial_fis) * hisi_hba->n_phy;
2373 memset(hisi_hba->initial_fis, 0, s);
2375 s = max_command_entries * sizeof(struct hisi_sas_iost);
2376 memset(hisi_hba->iost, 0, s);
2378 s = max_command_entries * sizeof(struct hisi_sas_breakpoint);
2379 memset(hisi_hba->breakpoint, 0, s);
2381 s = sizeof(struct hisi_sas_sata_breakpoint);
2382 for (j = 0; j < HISI_SAS_MAX_ITCT_ENTRIES; j++)
2383 memset(&sata_breakpoint[j], 0, s);
2385 EXPORT_SYMBOL_GPL(hisi_sas_init_mem);
2387 int hisi_sas_alloc(struct hisi_hba *hisi_hba)
2389 struct device *dev = hisi_hba->dev;
2390 int i, j, s, max_command_entries = HISI_SAS_MAX_COMMANDS;
2391 int max_command_entries_ru, sz_slot_buf_ru;
2392 int blk_cnt, slots_per_blk;
2394 sema_init(&hisi_hba->sem, 1);
2395 spin_lock_init(&hisi_hba->lock);
2396 for (i = 0; i < hisi_hba->n_phy; i++) {
2397 hisi_sas_phy_init(hisi_hba, i);
2398 hisi_hba->port[i].port_attached = 0;
2399 hisi_hba->port[i].id = -1;
2402 for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
2403 hisi_hba->devices[i].dev_type = SAS_PHY_UNUSED;
2404 hisi_hba->devices[i].device_id = i;
2405 hisi_hba->devices[i].dev_status = HISI_SAS_DEV_INIT;
2408 for (i = 0; i < hisi_hba->queue_count; i++) {
2409 struct hisi_sas_cq *cq = &hisi_hba->cq[i];
2410 struct hisi_sas_dq *dq = &hisi_hba->dq[i];
2412 /* Completion queue structure */
2414 cq->hisi_hba = hisi_hba;
2416 /* Delivery queue structure */
2417 spin_lock_init(&dq->lock);
2418 INIT_LIST_HEAD(&dq->list);
2420 dq->hisi_hba = hisi_hba;
2422 /* Delivery queue */
2423 s = sizeof(struct hisi_sas_cmd_hdr) * HISI_SAS_QUEUE_SLOTS;
2424 hisi_hba->cmd_hdr[i] = dmam_alloc_coherent(dev, s,
2425 &hisi_hba->cmd_hdr_dma[i],
2427 if (!hisi_hba->cmd_hdr[i])
2430 /* Completion queue */
2431 s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS;
2432 hisi_hba->complete_hdr[i] = dmam_alloc_coherent(dev, s,
2433 &hisi_hba->complete_hdr_dma[i],
2435 if (!hisi_hba->complete_hdr[i])
2439 s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_itct);
2440 hisi_hba->itct = dmam_alloc_coherent(dev, s, &hisi_hba->itct_dma,
2442 if (!hisi_hba->itct)
2445 hisi_hba->slot_info = devm_kcalloc(dev, max_command_entries,
2446 sizeof(struct hisi_sas_slot),
2448 if (!hisi_hba->slot_info)
2451 /* roundup to avoid overly large block size */
2452 max_command_entries_ru = roundup(max_command_entries, 64);
2453 if (hisi_hba->prot_mask & HISI_SAS_DIX_PROT_MASK)
2454 sz_slot_buf_ru = sizeof(struct hisi_sas_slot_dif_buf_table);
2456 sz_slot_buf_ru = sizeof(struct hisi_sas_slot_buf_table);
2457 sz_slot_buf_ru = roundup(sz_slot_buf_ru, 64);
2458 s = max(lcm(max_command_entries_ru, sz_slot_buf_ru), PAGE_SIZE);
2459 blk_cnt = (max_command_entries_ru * sz_slot_buf_ru) / s;
2460 slots_per_blk = s / sz_slot_buf_ru;
2462 for (i = 0; i < blk_cnt; i++) {
2463 int slot_index = i * slots_per_blk;
2467 buf = dmam_alloc_coherent(dev, s, &buf_dma,
2472 for (j = 0; j < slots_per_blk; j++, slot_index++) {
2473 struct hisi_sas_slot *slot;
2475 slot = &hisi_hba->slot_info[slot_index];
2477 slot->buf_dma = buf_dma;
2478 slot->idx = slot_index;
2480 buf += sz_slot_buf_ru;
2481 buf_dma += sz_slot_buf_ru;
2485 s = max_command_entries * sizeof(struct hisi_sas_iost);
2486 hisi_hba->iost = dmam_alloc_coherent(dev, s, &hisi_hba->iost_dma,
2488 if (!hisi_hba->iost)
2491 s = max_command_entries * sizeof(struct hisi_sas_breakpoint);
2492 hisi_hba->breakpoint = dmam_alloc_coherent(dev, s,
2493 &hisi_hba->breakpoint_dma,
2495 if (!hisi_hba->breakpoint)
2498 s = hisi_hba->slot_index_count = max_command_entries;
2499 hisi_hba->slot_index_tags = devm_bitmap_zalloc(dev, s, GFP_KERNEL);
2500 if (!hisi_hba->slot_index_tags)
2503 s = sizeof(struct hisi_sas_initial_fis) * HISI_SAS_MAX_PHYS;
2504 hisi_hba->initial_fis = dmam_alloc_coherent(dev, s,
2505 &hisi_hba->initial_fis_dma,
2507 if (!hisi_hba->initial_fis)
2510 s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_sata_breakpoint);
2511 hisi_hba->sata_breakpoint = dmam_alloc_coherent(dev, s,
2512 &hisi_hba->sata_breakpoint_dma,
2514 if (!hisi_hba->sata_breakpoint)
2517 hisi_hba->last_slot_index = HISI_SAS_UNRESERVED_IPTT;
2519 hisi_hba->wq = create_singlethread_workqueue(dev_name(dev));
2520 if (!hisi_hba->wq) {
2521 dev_err(dev, "sas_alloc: failed to create workqueue\n");
2529 EXPORT_SYMBOL_GPL(hisi_sas_alloc);
2531 void hisi_sas_free(struct hisi_hba *hisi_hba)
2535 for (i = 0; i < hisi_hba->n_phy; i++) {
2536 struct hisi_sas_phy *phy = &hisi_hba->phy[i];
2538 del_timer_sync(&phy->timer);
2542 destroy_workqueue(hisi_hba->wq);
2544 EXPORT_SYMBOL_GPL(hisi_sas_free);
2546 void hisi_sas_rst_work_handler(struct work_struct *work)
2548 struct hisi_hba *hisi_hba =
2549 container_of(work, struct hisi_hba, rst_work);
2551 if (hisi_sas_controller_prereset(hisi_hba))
2554 hisi_sas_controller_reset(hisi_hba);
2556 EXPORT_SYMBOL_GPL(hisi_sas_rst_work_handler);
2558 void hisi_sas_sync_rst_work_handler(struct work_struct *work)
2560 struct hisi_sas_rst *rst =
2561 container_of(work, struct hisi_sas_rst, work);
2563 if (hisi_sas_controller_prereset(rst->hisi_hba))
2566 if (!hisi_sas_controller_reset(rst->hisi_hba))
2569 complete(rst->completion);
2571 EXPORT_SYMBOL_GPL(hisi_sas_sync_rst_work_handler);
2573 int hisi_sas_get_fw_info(struct hisi_hba *hisi_hba)
2575 struct device *dev = hisi_hba->dev;
2576 struct platform_device *pdev = hisi_hba->platform_dev;
2577 struct device_node *np = pdev ? pdev->dev.of_node : NULL;
2580 if (device_property_read_u8_array(dev, "sas-addr", hisi_hba->sas_addr,
2582 dev_err(dev, "could not get property sas-addr\n");
2588 * These properties are only required for platform device-based
2589 * controller with DT firmware.
2591 hisi_hba->ctrl = syscon_regmap_lookup_by_phandle(np,
2592 "hisilicon,sas-syscon");
2593 if (IS_ERR(hisi_hba->ctrl)) {
2594 dev_err(dev, "could not get syscon\n");
2598 if (device_property_read_u32(dev, "ctrl-reset-reg",
2599 &hisi_hba->ctrl_reset_reg)) {
2600 dev_err(dev, "could not get property ctrl-reset-reg\n");
2604 if (device_property_read_u32(dev, "ctrl-reset-sts-reg",
2605 &hisi_hba->ctrl_reset_sts_reg)) {
2606 dev_err(dev, "could not get property ctrl-reset-sts-reg\n");
2610 if (device_property_read_u32(dev, "ctrl-clock-ena-reg",
2611 &hisi_hba->ctrl_clock_ena_reg)) {
2612 dev_err(dev, "could not get property ctrl-clock-ena-reg\n");
2617 refclk = devm_clk_get(dev, NULL);
2619 dev_dbg(dev, "no ref clk property\n");
2621 hisi_hba->refclk_frequency_mhz = clk_get_rate(refclk) / 1000000;
2623 if (device_property_read_u32(dev, "phy-count", &hisi_hba->n_phy)) {
2624 dev_err(dev, "could not get property phy-count\n");
2628 if (device_property_read_u32(dev, "queue-count",
2629 &hisi_hba->queue_count)) {
2630 dev_err(dev, "could not get property queue-count\n");
2636 EXPORT_SYMBOL_GPL(hisi_sas_get_fw_info);
2638 static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device *pdev,
2639 const struct hisi_sas_hw *hw)
2641 struct resource *res;
2642 struct Scsi_Host *shost;
2643 struct hisi_hba *hisi_hba;
2644 struct device *dev = &pdev->dev;
2647 shost = scsi_host_alloc(hw->sht, sizeof(*hisi_hba));
2649 dev_err(dev, "scsi host alloc failed\n");
2652 hisi_hba = shost_priv(shost);
2654 INIT_WORK(&hisi_hba->rst_work, hisi_sas_rst_work_handler);
2656 hisi_hba->dev = dev;
2657 hisi_hba->platform_dev = pdev;
2658 hisi_hba->shost = shost;
2659 SHOST_TO_SAS_HA(shost) = &hisi_hba->sha;
2661 timer_setup(&hisi_hba->timer, NULL, 0);
2663 if (hisi_sas_get_fw_info(hisi_hba) < 0)
2666 error = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
2668 dev_err(dev, "No usable DMA addressing method\n");
2672 hisi_hba->regs = devm_platform_ioremap_resource(pdev, 0);
2673 if (IS_ERR(hisi_hba->regs))
2676 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2678 hisi_hba->sgpio_regs = devm_ioremap_resource(dev, res);
2679 if (IS_ERR(hisi_hba->sgpio_regs))
2683 if (hisi_sas_alloc(hisi_hba)) {
2684 hisi_sas_free(hisi_hba);
2690 scsi_host_put(shost);
2691 dev_err(dev, "shost alloc failed\n");
2695 static int hisi_sas_interrupt_preinit(struct hisi_hba *hisi_hba)
2697 if (hisi_hba->hw->interrupt_preinit)
2698 return hisi_hba->hw->interrupt_preinit(hisi_hba);
2702 int hisi_sas_probe(struct platform_device *pdev,
2703 const struct hisi_sas_hw *hw)
2705 struct Scsi_Host *shost;
2706 struct hisi_hba *hisi_hba;
2707 struct device *dev = &pdev->dev;
2708 struct asd_sas_phy **arr_phy;
2709 struct asd_sas_port **arr_port;
2710 struct sas_ha_struct *sha;
2711 int rc, phy_nr, port_nr, i;
2713 shost = hisi_sas_shost_alloc(pdev, hw);
2717 sha = SHOST_TO_SAS_HA(shost);
2718 hisi_hba = shost_priv(shost);
2719 platform_set_drvdata(pdev, sha);
2721 phy_nr = port_nr = hisi_hba->n_phy;
2723 arr_phy = devm_kcalloc(dev, phy_nr, sizeof(void *), GFP_KERNEL);
2724 arr_port = devm_kcalloc(dev, port_nr, sizeof(void *), GFP_KERNEL);
2725 if (!arr_phy || !arr_port) {
2730 sha->sas_phy = arr_phy;
2731 sha->sas_port = arr_port;
2732 sha->lldd_ha = hisi_hba;
2734 shost->transportt = hisi_sas_stt;
2735 shost->max_id = HISI_SAS_MAX_DEVICES;
2736 shost->max_lun = ~0;
2737 shost->max_channel = 1;
2738 shost->max_cmd_len = 16;
2739 if (hisi_hba->hw->slot_index_alloc) {
2740 shost->can_queue = HISI_SAS_MAX_COMMANDS;
2741 shost->cmd_per_lun = HISI_SAS_MAX_COMMANDS;
2743 shost->can_queue = HISI_SAS_UNRESERVED_IPTT;
2744 shost->cmd_per_lun = HISI_SAS_UNRESERVED_IPTT;
2747 sha->sas_ha_name = DRV_NAME;
2748 sha->dev = hisi_hba->dev;
2749 sha->lldd_module = THIS_MODULE;
2750 sha->sas_addr = &hisi_hba->sas_addr[0];
2751 sha->num_phys = hisi_hba->n_phy;
2752 sha->core.shost = hisi_hba->shost;
2754 for (i = 0; i < hisi_hba->n_phy; i++) {
2755 sha->sas_phy[i] = &hisi_hba->phy[i].sas_phy;
2756 sha->sas_port[i] = &hisi_hba->port[i].sas_port;
2759 rc = hisi_sas_interrupt_preinit(hisi_hba);
2763 rc = scsi_add_host(shost, &pdev->dev);
2767 rc = sas_register_ha(sha);
2769 goto err_out_register_ha;
2771 rc = hisi_hba->hw->hw_init(hisi_hba);
2773 goto err_out_hw_init;
2775 scsi_scan_host(shost);
2780 sas_unregister_ha(sha);
2781 err_out_register_ha:
2782 scsi_remove_host(shost);
2784 hisi_sas_free(hisi_hba);
2785 scsi_host_put(shost);
2788 EXPORT_SYMBOL_GPL(hisi_sas_probe);
2790 int hisi_sas_remove(struct platform_device *pdev)
2792 struct sas_ha_struct *sha = platform_get_drvdata(pdev);
2793 struct hisi_hba *hisi_hba = sha->lldd_ha;
2794 struct Scsi_Host *shost = sha->core.shost;
2796 del_timer_sync(&hisi_hba->timer);
2798 sas_unregister_ha(sha);
2799 sas_remove_host(sha->core.shost);
2801 hisi_sas_free(hisi_hba);
2802 scsi_host_put(shost);
2805 EXPORT_SYMBOL_GPL(hisi_sas_remove);
2807 #if IS_ENABLED(CONFIG_SCSI_HISI_SAS_DEBUGFS_DEFAULT_ENABLE)
2808 #define DEBUGFS_ENABLE_DEFAULT "enabled"
2809 bool hisi_sas_debugfs_enable = true;
2810 u32 hisi_sas_debugfs_dump_count = 50;
2812 #define DEBUGFS_ENABLE_DEFAULT "disabled"
2813 bool hisi_sas_debugfs_enable;
2814 u32 hisi_sas_debugfs_dump_count = 1;
2817 EXPORT_SYMBOL_GPL(hisi_sas_debugfs_enable);
2818 module_param_named(debugfs_enable, hisi_sas_debugfs_enable, bool, 0444);
2819 MODULE_PARM_DESC(hisi_sas_debugfs_enable,
2820 "Enable driver debugfs (default "DEBUGFS_ENABLE_DEFAULT")");
2822 EXPORT_SYMBOL_GPL(hisi_sas_debugfs_dump_count);
2823 module_param_named(debugfs_dump_count, hisi_sas_debugfs_dump_count, uint, 0444);
2824 MODULE_PARM_DESC(hisi_sas_debugfs_dump_count, "Number of debugfs dumps to allow");
2826 struct dentry *hisi_sas_debugfs_dir;
2827 EXPORT_SYMBOL_GPL(hisi_sas_debugfs_dir);
2829 static __init int hisi_sas_init(void)
2831 hisi_sas_stt = sas_domain_attach_transport(&hisi_sas_transport_ops);
2835 if (hisi_sas_debugfs_enable) {
2836 hisi_sas_debugfs_dir = debugfs_create_dir("hisi_sas", NULL);
2837 if (hisi_sas_debugfs_dump_count > HISI_SAS_MAX_DEBUGFS_DUMP) {
2838 pr_info("hisi_sas: Limiting debugfs dump count\n");
2839 hisi_sas_debugfs_dump_count = HISI_SAS_MAX_DEBUGFS_DUMP;
2846 static __exit void hisi_sas_exit(void)
2848 sas_release_transport(hisi_sas_stt);
2850 debugfs_remove(hisi_sas_debugfs_dir);
2853 module_init(hisi_sas_init);
2854 module_exit(hisi_sas_exit);
2856 MODULE_LICENSE("GPL");
2857 MODULE_AUTHOR("John Garry <john.garry@huawei.com>");
2858 MODULE_DESCRIPTION("HISILICON SAS controller driver");
2859 MODULE_ALIAS("platform:" DRV_NAME);