John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Linaro Ltd. |
| 3 | * Copyright (c) 2015 Hisilicon Limited. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #include "hisi_sas.h" |
| 13 | #define DRV_NAME "hisi_sas" |
| 14 | |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 15 | #define DEV_IS_GONE(dev) \ |
| 16 | ((!dev) || (dev->dev_type == SAS_PHY_UNUSED)) |
| 17 | |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 18 | static int hisi_sas_debug_issue_ssp_tmf(struct domain_device *device, |
| 19 | u8 *lun, struct hisi_sas_tmf_task *tmf); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 20 | static int |
| 21 | hisi_sas_internal_task_abort(struct hisi_hba *hisi_hba, |
| 22 | struct domain_device *device, |
| 23 | int abort_flag, int tag); |
Xiang Chen | 7c594f0 | 2017-03-23 01:25:20 +0800 | [diff] [blame] | 24 | static int hisi_sas_softreset_ata_disk(struct domain_device *device); |
Xiaofei Tan | 057c3d1 | 2017-12-09 01:16:45 +0800 | [diff] [blame] | 25 | static int hisi_sas_control_phy(struct asd_sas_phy *sas_phy, enum phy_func func, |
| 26 | void *funcdata); |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 27 | |
chenxiang | 468f4b8 | 2017-12-28 18:20:47 +0800 | [diff] [blame] | 28 | u8 hisi_sas_get_ata_protocol(struct host_to_dev_fis *fis, int direction) |
Xiang Chen | 6c7bb8a | 2017-06-14 23:33:14 +0800 | [diff] [blame] | 29 | { |
chenxiang | 468f4b8 | 2017-12-28 18:20:47 +0800 | [diff] [blame] | 30 | switch (fis->command) { |
Xiang Chen | 6c7bb8a | 2017-06-14 23:33:14 +0800 | [diff] [blame] | 31 | case ATA_CMD_FPDMA_WRITE: |
| 32 | case ATA_CMD_FPDMA_READ: |
| 33 | case ATA_CMD_FPDMA_RECV: |
| 34 | case ATA_CMD_FPDMA_SEND: |
| 35 | case ATA_CMD_NCQ_NON_DATA: |
| 36 | return HISI_SAS_SATA_PROTOCOL_FPDMA; |
| 37 | |
| 38 | case ATA_CMD_DOWNLOAD_MICRO: |
| 39 | case ATA_CMD_ID_ATA: |
| 40 | case ATA_CMD_PMP_READ: |
| 41 | case ATA_CMD_READ_LOG_EXT: |
| 42 | case ATA_CMD_PIO_READ: |
| 43 | case ATA_CMD_PIO_READ_EXT: |
| 44 | case ATA_CMD_PMP_WRITE: |
| 45 | case ATA_CMD_WRITE_LOG_EXT: |
| 46 | case ATA_CMD_PIO_WRITE: |
| 47 | case ATA_CMD_PIO_WRITE_EXT: |
| 48 | return HISI_SAS_SATA_PROTOCOL_PIO; |
| 49 | |
| 50 | case ATA_CMD_DSM: |
| 51 | case ATA_CMD_DOWNLOAD_MICRO_DMA: |
| 52 | case ATA_CMD_PMP_READ_DMA: |
| 53 | case ATA_CMD_PMP_WRITE_DMA: |
| 54 | case ATA_CMD_READ: |
| 55 | case ATA_CMD_READ_EXT: |
| 56 | case ATA_CMD_READ_LOG_DMA_EXT: |
| 57 | case ATA_CMD_READ_STREAM_DMA_EXT: |
| 58 | case ATA_CMD_TRUSTED_RCV_DMA: |
| 59 | case ATA_CMD_TRUSTED_SND_DMA: |
| 60 | case ATA_CMD_WRITE: |
| 61 | case ATA_CMD_WRITE_EXT: |
| 62 | case ATA_CMD_WRITE_FUA_EXT: |
| 63 | case ATA_CMD_WRITE_QUEUED: |
| 64 | case ATA_CMD_WRITE_LOG_DMA_EXT: |
| 65 | case ATA_CMD_WRITE_STREAM_DMA_EXT: |
Xiaofei Tan | c3fe8a2b | 2017-08-11 00:09:34 +0800 | [diff] [blame] | 66 | case ATA_CMD_ZAC_MGMT_IN: |
Xiang Chen | 6c7bb8a | 2017-06-14 23:33:14 +0800 | [diff] [blame] | 67 | return HISI_SAS_SATA_PROTOCOL_DMA; |
| 68 | |
| 69 | case ATA_CMD_CHK_POWER: |
| 70 | case ATA_CMD_DEV_RESET: |
| 71 | case ATA_CMD_EDD: |
| 72 | case ATA_CMD_FLUSH: |
| 73 | case ATA_CMD_FLUSH_EXT: |
| 74 | case ATA_CMD_VERIFY: |
| 75 | case ATA_CMD_VERIFY_EXT: |
| 76 | case ATA_CMD_SET_FEATURES: |
| 77 | case ATA_CMD_STANDBY: |
| 78 | case ATA_CMD_STANDBYNOW1: |
Xiaofei Tan | c3fe8a2b | 2017-08-11 00:09:34 +0800 | [diff] [blame] | 79 | case ATA_CMD_ZAC_MGMT_OUT: |
Xiang Chen | 6c7bb8a | 2017-06-14 23:33:14 +0800 | [diff] [blame] | 80 | return HISI_SAS_SATA_PROTOCOL_NONDATA; |
| 81 | default: |
chenxiang | 468f4b8 | 2017-12-28 18:20:47 +0800 | [diff] [blame] | 82 | { |
| 83 | if (fis->command == ATA_CMD_SET_MAX) { |
| 84 | switch (fis->features) { |
| 85 | case ATA_SET_MAX_PASSWD: |
| 86 | case ATA_SET_MAX_LOCK: |
| 87 | return HISI_SAS_SATA_PROTOCOL_PIO; |
| 88 | |
| 89 | case ATA_SET_MAX_PASSWD_DMA: |
| 90 | case ATA_SET_MAX_UNLOCK_DMA: |
| 91 | return HISI_SAS_SATA_PROTOCOL_DMA; |
| 92 | |
| 93 | default: |
| 94 | return HISI_SAS_SATA_PROTOCOL_NONDATA; |
| 95 | } |
| 96 | } |
Xiang Chen | 6c7bb8a | 2017-06-14 23:33:14 +0800 | [diff] [blame] | 97 | if (direction == DMA_NONE) |
| 98 | return HISI_SAS_SATA_PROTOCOL_NONDATA; |
| 99 | return HISI_SAS_SATA_PROTOCOL_PIO; |
| 100 | } |
chenxiang | 468f4b8 | 2017-12-28 18:20:47 +0800 | [diff] [blame] | 101 | } |
Xiang Chen | 6c7bb8a | 2017-06-14 23:33:14 +0800 | [diff] [blame] | 102 | } |
| 103 | EXPORT_SYMBOL_GPL(hisi_sas_get_ata_protocol); |
| 104 | |
Xiang Chen | 7590407 | 2017-06-14 23:33:15 +0800 | [diff] [blame] | 105 | void hisi_sas_sata_done(struct sas_task *task, |
| 106 | struct hisi_sas_slot *slot) |
| 107 | { |
| 108 | struct task_status_struct *ts = &task->task_status; |
| 109 | struct ata_task_resp *resp = (struct ata_task_resp *)ts->buf; |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 110 | struct hisi_sas_status_buffer *status_buf = |
| 111 | hisi_sas_status_buf_addr_mem(slot); |
| 112 | u8 *iu = &status_buf->iu[0]; |
| 113 | struct dev_to_host_fis *d2h = (struct dev_to_host_fis *)iu; |
Xiang Chen | 7590407 | 2017-06-14 23:33:15 +0800 | [diff] [blame] | 114 | |
| 115 | resp->frame_len = sizeof(struct dev_to_host_fis); |
| 116 | memcpy(&resp->ending_fis[0], d2h, sizeof(struct dev_to_host_fis)); |
| 117 | |
| 118 | ts->buf_valid_size = sizeof(*resp); |
| 119 | } |
| 120 | EXPORT_SYMBOL_GPL(hisi_sas_sata_done); |
| 121 | |
Xiang Chen | 318913c | 2017-06-14 23:33:16 +0800 | [diff] [blame] | 122 | int hisi_sas_get_ncq_tag(struct sas_task *task, u32 *tag) |
| 123 | { |
| 124 | struct ata_queued_cmd *qc = task->uldd_task; |
| 125 | |
| 126 | if (qc) { |
| 127 | if (qc->tf.command == ATA_CMD_FPDMA_WRITE || |
| 128 | qc->tf.command == ATA_CMD_FPDMA_READ) { |
| 129 | *tag = qc->tag; |
| 130 | return 1; |
| 131 | } |
| 132 | } |
| 133 | return 0; |
| 134 | } |
| 135 | EXPORT_SYMBOL_GPL(hisi_sas_get_ncq_tag); |
| 136 | |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 137 | static struct hisi_hba *dev_to_hisi_hba(struct domain_device *device) |
| 138 | { |
| 139 | return device->port->ha->lldd_ha; |
| 140 | } |
| 141 | |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 142 | struct hisi_sas_port *to_hisi_sas_port(struct asd_sas_port *sas_port) |
| 143 | { |
| 144 | return container_of(sas_port, struct hisi_sas_port, sas_port); |
| 145 | } |
| 146 | EXPORT_SYMBOL_GPL(to_hisi_sas_port); |
| 147 | |
Xiang Chen | a25d0d3 | 2017-08-11 00:09:40 +0800 | [diff] [blame] | 148 | void hisi_sas_stop_phys(struct hisi_hba *hisi_hba) |
| 149 | { |
| 150 | int phy_no; |
| 151 | |
| 152 | for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) |
| 153 | hisi_hba->hw->phy_disable(hisi_hba, phy_no); |
| 154 | } |
| 155 | EXPORT_SYMBOL_GPL(hisi_sas_stop_phys); |
| 156 | |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 157 | static void hisi_sas_slot_index_clear(struct hisi_hba *hisi_hba, int slot_idx) |
| 158 | { |
| 159 | void *bitmap = hisi_hba->slot_index_tags; |
| 160 | |
| 161 | clear_bit(slot_idx, bitmap); |
| 162 | } |
| 163 | |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 164 | static void hisi_sas_slot_index_free(struct hisi_hba *hisi_hba, int slot_idx) |
| 165 | { |
| 166 | hisi_sas_slot_index_clear(hisi_hba, slot_idx); |
| 167 | } |
| 168 | |
| 169 | static void hisi_sas_slot_index_set(struct hisi_hba *hisi_hba, int slot_idx) |
| 170 | { |
| 171 | void *bitmap = hisi_hba->slot_index_tags; |
| 172 | |
| 173 | set_bit(slot_idx, bitmap); |
| 174 | } |
| 175 | |
| 176 | static int hisi_sas_slot_index_alloc(struct hisi_hba *hisi_hba, int *slot_idx) |
| 177 | { |
| 178 | unsigned int index; |
| 179 | void *bitmap = hisi_hba->slot_index_tags; |
| 180 | |
| 181 | index = find_first_zero_bit(bitmap, hisi_hba->slot_index_count); |
| 182 | if (index >= hisi_hba->slot_index_count) |
| 183 | return -SAS_QUEUE_FULL; |
| 184 | hisi_sas_slot_index_set(hisi_hba, index); |
| 185 | *slot_idx = index; |
| 186 | return 0; |
| 187 | } |
| 188 | |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 189 | static void hisi_sas_slot_index_init(struct hisi_hba *hisi_hba) |
| 190 | { |
| 191 | int i; |
| 192 | |
| 193 | for (i = 0; i < hisi_hba->slot_index_count; ++i) |
| 194 | hisi_sas_slot_index_clear(hisi_hba, i); |
| 195 | } |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 196 | |
| 197 | void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, struct sas_task *task, |
| 198 | struct hisi_sas_slot *slot) |
| 199 | { |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 200 | |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 201 | if (task) { |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 202 | struct device *dev = hisi_hba->dev; |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 203 | struct domain_device *device = task->dev; |
| 204 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 205 | |
Xiaofei Tan | 6ba0fbc | 2017-10-24 23:51:38 +0800 | [diff] [blame] | 206 | if (!task->lldd_task) |
| 207 | return; |
| 208 | |
| 209 | task->lldd_task = NULL; |
| 210 | |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 211 | if (!sas_protocol_ata(task->task_proto)) |
| 212 | if (slot->n_elem) |
Xiang Chen | dc1e473 | 2017-12-09 01:16:33 +0800 | [diff] [blame] | 213 | dma_unmap_sg(dev, task->scatter, |
| 214 | task->num_scatter, |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 215 | task->data_dir); |
| 216 | |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 217 | if (sas_dev) |
| 218 | atomic64_dec(&sas_dev->running_req); |
| 219 | } |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 220 | |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 221 | if (slot->buf) |
| 222 | dma_pool_free(hisi_hba->buffer_pool, slot->buf, slot->buf_dma); |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 223 | |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 224 | list_del_init(&slot->entry); |
Xiaofei Tan | 6ba0fbc | 2017-10-24 23:51:38 +0800 | [diff] [blame] | 225 | slot->buf = NULL; |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 226 | slot->task = NULL; |
| 227 | slot->port = NULL; |
| 228 | hisi_sas_slot_index_free(hisi_hba, slot->idx); |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 229 | |
John Garry | 59ba49f | 2016-09-06 23:36:14 +0800 | [diff] [blame] | 230 | /* slot memory is fully zeroed when it is reused */ |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 231 | } |
| 232 | EXPORT_SYMBOL_GPL(hisi_sas_slot_task_free); |
| 233 | |
John Garry | 66ee999 | 2015-11-18 00:50:54 +0800 | [diff] [blame] | 234 | static int hisi_sas_task_prep_smp(struct hisi_hba *hisi_hba, |
| 235 | struct hisi_sas_slot *slot) |
| 236 | { |
| 237 | return hisi_hba->hw->prep_smp(hisi_hba, slot); |
| 238 | } |
| 239 | |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 240 | static int hisi_sas_task_prep_ssp(struct hisi_hba *hisi_hba, |
| 241 | struct hisi_sas_slot *slot, int is_tmf, |
| 242 | struct hisi_sas_tmf_task *tmf) |
| 243 | { |
| 244 | return hisi_hba->hw->prep_ssp(hisi_hba, slot, is_tmf, tmf); |
| 245 | } |
| 246 | |
John Garry | 6f2ff1a | 2016-01-26 02:47:20 +0800 | [diff] [blame] | 247 | static int hisi_sas_task_prep_ata(struct hisi_hba *hisi_hba, |
| 248 | struct hisi_sas_slot *slot) |
| 249 | { |
| 250 | return hisi_hba->hw->prep_stp(hisi_hba, slot); |
| 251 | } |
| 252 | |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 253 | static int hisi_sas_task_prep_abort(struct hisi_hba *hisi_hba, |
| 254 | struct hisi_sas_slot *slot, |
| 255 | int device_id, int abort_flag, int tag_to_abort) |
| 256 | { |
| 257 | return hisi_hba->hw->prep_abort(hisi_hba, slot, |
| 258 | device_id, abort_flag, tag_to_abort); |
| 259 | } |
| 260 | |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 261 | /* |
| 262 | * This function will issue an abort TMF regardless of whether the |
| 263 | * task is in the sdev or not. Then it will do the task complete |
| 264 | * cleanup and callbacks. |
| 265 | */ |
| 266 | static void hisi_sas_slot_abort(struct work_struct *work) |
| 267 | { |
| 268 | struct hisi_sas_slot *abort_slot = |
| 269 | container_of(work, struct hisi_sas_slot, abort_slot); |
| 270 | struct sas_task *task = abort_slot->task; |
| 271 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(task->dev); |
| 272 | struct scsi_cmnd *cmnd = task->uldd_task; |
| 273 | struct hisi_sas_tmf_task tmf_task; |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 274 | struct scsi_lun lun; |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 275 | struct device *dev = hisi_hba->dev; |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 276 | int tag = abort_slot->idx; |
John Garry | da7b66e | 2017-01-03 20:24:50 +0800 | [diff] [blame] | 277 | unsigned long flags; |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 278 | |
| 279 | if (!(task->task_proto & SAS_PROTOCOL_SSP)) { |
| 280 | dev_err(dev, "cannot abort slot for non-ssp task\n"); |
| 281 | goto out; |
| 282 | } |
| 283 | |
| 284 | int_to_scsilun(cmnd->device->lun, &lun); |
| 285 | tmf_task.tmf = TMF_ABORT_TASK; |
| 286 | tmf_task.tag_of_task_to_be_managed = cpu_to_le16(tag); |
| 287 | |
| 288 | hisi_sas_debug_issue_ssp_tmf(task->dev, lun.scsi_lun, &tmf_task); |
| 289 | out: |
| 290 | /* Do cleanup for this task */ |
John Garry | da7b66e | 2017-01-03 20:24:50 +0800 | [diff] [blame] | 291 | spin_lock_irqsave(&hisi_hba->lock, flags); |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 292 | hisi_sas_slot_task_free(hisi_hba, task, abort_slot); |
John Garry | da7b66e | 2017-01-03 20:24:50 +0800 | [diff] [blame] | 293 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 294 | if (task->task_done) |
| 295 | task->task_done(task); |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 296 | } |
| 297 | |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 298 | static int hisi_sas_task_prep(struct sas_task *task, struct hisi_sas_dq |
| 299 | *dq, int is_tmf, struct hisi_sas_tmf_task *tmf, |
| 300 | int *pass) |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 301 | { |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 302 | struct hisi_hba *hisi_hba = dq->hisi_hba; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 303 | struct domain_device *device = task->dev; |
| 304 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 305 | struct hisi_sas_port *port; |
| 306 | struct hisi_sas_slot *slot; |
| 307 | struct hisi_sas_cmd_hdr *cmd_hdr_base; |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 308 | struct asd_sas_port *sas_port = device->port; |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 309 | struct device *dev = hisi_hba->dev; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 310 | int dlvry_queue_slot, dlvry_queue, n_elem = 0, rc, slot_idx; |
John Garry | 54c9dd2 | 2017-03-23 01:25:29 +0800 | [diff] [blame] | 311 | unsigned long flags; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 312 | |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 313 | if (!sas_port) { |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 314 | struct task_status_struct *ts = &task->task_status; |
| 315 | |
| 316 | ts->resp = SAS_TASK_UNDELIVERED; |
| 317 | ts->stat = SAS_PHY_DOWN; |
| 318 | /* |
| 319 | * libsas will use dev->port, should |
| 320 | * not call task_done for sata |
| 321 | */ |
| 322 | if (device->dev_type != SAS_SATA_DEV) |
| 323 | task->task_done(task); |
John Garry | ddabca2 | 2017-03-23 01:25:22 +0800 | [diff] [blame] | 324 | return SAS_PHY_DOWN; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | if (DEV_IS_GONE(sas_dev)) { |
| 328 | if (sas_dev) |
John Garry | ad60483 | 2017-06-14 23:33:12 +0800 | [diff] [blame] | 329 | dev_info(dev, "task prep: device %d not ready\n", |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 330 | sas_dev->device_id); |
| 331 | else |
| 332 | dev_info(dev, "task prep: device %016llx not ready\n", |
| 333 | SAS_ADDR(device->sas_addr)); |
| 334 | |
John Garry | ddabca2 | 2017-03-23 01:25:22 +0800 | [diff] [blame] | 335 | return SAS_PHY_DOWN; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 336 | } |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 337 | |
| 338 | port = to_hisi_sas_port(sas_port); |
John Garry | 9859f24 | 2016-08-24 19:05:52 +0800 | [diff] [blame] | 339 | if (port && !port->port_attached) { |
John Garry | 09fe9ec | 2016-09-06 23:36:18 +0800 | [diff] [blame] | 340 | dev_info(dev, "task prep: %s port%d not attach device\n", |
Xiang Chen | 6073b77 | 2017-03-23 01:25:38 +0800 | [diff] [blame] | 341 | (dev_is_sata(device)) ? |
John Garry | 09fe9ec | 2016-09-06 23:36:18 +0800 | [diff] [blame] | 342 | "SATA/STP" : "SAS", |
| 343 | device->port->id); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 344 | |
John Garry | 09fe9ec | 2016-09-06 23:36:18 +0800 | [diff] [blame] | 345 | return SAS_PHY_DOWN; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | if (!sas_protocol_ata(task->task_proto)) { |
| 349 | if (task->num_scatter) { |
| 350 | n_elem = dma_map_sg(dev, task->scatter, |
| 351 | task->num_scatter, task->data_dir); |
| 352 | if (!n_elem) { |
| 353 | rc = -ENOMEM; |
| 354 | goto prep_out; |
| 355 | } |
| 356 | } |
| 357 | } else |
| 358 | n_elem = task->num_scatter; |
| 359 | |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 360 | spin_lock_irqsave(&hisi_hba->lock, flags); |
John Garry | 685b6d6 | 2016-04-15 21:36:36 +0800 | [diff] [blame] | 361 | if (hisi_hba->hw->slot_index_alloc) |
| 362 | rc = hisi_hba->hw->slot_index_alloc(hisi_hba, &slot_idx, |
| 363 | device); |
| 364 | else |
| 365 | rc = hisi_sas_slot_index_alloc(hisi_hba, &slot_idx); |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 366 | if (rc) { |
| 367 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 368 | goto err_out; |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 369 | } |
| 370 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 371 | |
| 372 | rc = hisi_hba->hw->get_free_slot(hisi_hba, dq); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 373 | if (rc) |
| 374 | goto err_out_tag; |
| 375 | |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 376 | dlvry_queue = dq->id; |
| 377 | dlvry_queue_slot = dq->wr_point; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 378 | slot = &hisi_hba->slot_info[slot_idx]; |
| 379 | memset(slot, 0, sizeof(struct hisi_sas_slot)); |
| 380 | |
| 381 | slot->idx = slot_idx; |
| 382 | slot->n_elem = n_elem; |
| 383 | slot->dlvry_queue = dlvry_queue; |
| 384 | slot->dlvry_queue_slot = dlvry_queue_slot; |
| 385 | cmd_hdr_base = hisi_hba->cmd_hdr[dlvry_queue]; |
| 386 | slot->cmd_hdr = &cmd_hdr_base[dlvry_queue_slot]; |
| 387 | slot->task = task; |
| 388 | slot->port = port; |
| 389 | task->lldd_task = slot; |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 390 | INIT_WORK(&slot->abort_slot, hisi_sas_slot_abort); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 391 | |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 392 | slot->buf = dma_pool_alloc(hisi_hba->buffer_pool, |
| 393 | GFP_ATOMIC, &slot->buf_dma); |
| 394 | if (!slot->buf) { |
Dan Carpenter | 9c9d18e | 2015-12-09 13:48:36 +0300 | [diff] [blame] | 395 | rc = -ENOMEM; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 396 | goto err_out_slot_buf; |
Dan Carpenter | 9c9d18e | 2015-12-09 13:48:36 +0300 | [diff] [blame] | 397 | } |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 398 | memset(slot->cmd_hdr, 0, sizeof(struct hisi_sas_cmd_hdr)); |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 399 | memset(hisi_sas_cmd_hdr_addr_mem(slot), 0, HISI_SAS_COMMAND_TABLE_SZ); |
| 400 | memset(hisi_sas_status_buf_addr_mem(slot), 0, HISI_SAS_STATUS_BUF_SZ); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 401 | |
| 402 | switch (task->task_proto) { |
John Garry | 66ee999 | 2015-11-18 00:50:54 +0800 | [diff] [blame] | 403 | case SAS_PROTOCOL_SMP: |
| 404 | rc = hisi_sas_task_prep_smp(hisi_hba, slot); |
| 405 | break; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 406 | case SAS_PROTOCOL_SSP: |
| 407 | rc = hisi_sas_task_prep_ssp(hisi_hba, slot, is_tmf, tmf); |
| 408 | break; |
| 409 | case SAS_PROTOCOL_SATA: |
| 410 | case SAS_PROTOCOL_STP: |
| 411 | case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: |
John Garry | 6f2ff1a | 2016-01-26 02:47:20 +0800 | [diff] [blame] | 412 | rc = hisi_sas_task_prep_ata(hisi_hba, slot); |
| 413 | break; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 414 | default: |
| 415 | dev_err(dev, "task prep: unknown/unsupported proto (0x%x)\n", |
| 416 | task->task_proto); |
| 417 | rc = -EINVAL; |
| 418 | break; |
| 419 | } |
| 420 | |
| 421 | if (rc) { |
| 422 | dev_err(dev, "task prep: rc = 0x%x\n", rc); |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 423 | goto err_out_buf; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 424 | } |
| 425 | |
Xiang Chen | 9feaf90 | 2017-10-24 23:51:34 +0800 | [diff] [blame] | 426 | spin_lock_irqsave(&hisi_hba->lock, flags); |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 427 | list_add_tail(&slot->entry, &sas_dev->list); |
Xiang Chen | 9feaf90 | 2017-10-24 23:51:34 +0800 | [diff] [blame] | 428 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
John Garry | 54c9dd2 | 2017-03-23 01:25:29 +0800 | [diff] [blame] | 429 | spin_lock_irqsave(&task->task_state_lock, flags); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 430 | task->task_state_flags |= SAS_TASK_AT_INITIATOR; |
John Garry | 54c9dd2 | 2017-03-23 01:25:29 +0800 | [diff] [blame] | 431 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 432 | |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 433 | dq->slot_prep = slot; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 434 | |
John Garry | f696cc3 | 2016-11-07 20:48:39 +0800 | [diff] [blame] | 435 | atomic64_inc(&sas_dev->running_req); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 436 | ++(*pass); |
| 437 | |
Dan Carpenter | 9c9d18e | 2015-12-09 13:48:36 +0300 | [diff] [blame] | 438 | return 0; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 439 | |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 440 | err_out_buf: |
| 441 | dma_pool_free(hisi_hba->buffer_pool, slot->buf, |
| 442 | slot->buf_dma); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 443 | err_out_slot_buf: |
| 444 | /* Nothing to be done */ |
| 445 | err_out_tag: |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 446 | spin_lock_irqsave(&hisi_hba->lock, flags); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 447 | hisi_sas_slot_index_free(hisi_hba, slot_idx); |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 448 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 449 | err_out: |
| 450 | dev_err(dev, "task prep: failed[%d]!\n", rc); |
| 451 | if (!sas_protocol_ata(task->task_proto)) |
| 452 | if (n_elem) |
Xiang Chen | dc1e473 | 2017-12-09 01:16:33 +0800 | [diff] [blame] | 453 | dma_unmap_sg(dev, task->scatter, |
| 454 | task->num_scatter, |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 455 | task->data_dir); |
| 456 | prep_out: |
| 457 | return rc; |
| 458 | } |
| 459 | |
| 460 | static int hisi_sas_task_exec(struct sas_task *task, gfp_t gfp_flags, |
| 461 | int is_tmf, struct hisi_sas_tmf_task *tmf) |
| 462 | { |
| 463 | u32 rc; |
| 464 | u32 pass = 0; |
| 465 | unsigned long flags; |
| 466 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(task->dev); |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 467 | struct device *dev = hisi_hba->dev; |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 468 | struct domain_device *device = task->dev; |
| 469 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 470 | struct hisi_sas_dq *dq = sas_dev->dq; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 471 | |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 472 | if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags))) |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 473 | return -EINVAL; |
| 474 | |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 475 | /* protect task_prep and start_delivery sequence */ |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 476 | spin_lock_irqsave(&dq->lock, flags); |
| 477 | rc = hisi_sas_task_prep(task, dq, is_tmf, tmf, &pass); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 478 | if (rc) |
| 479 | dev_err(dev, "task exec: failed[%d]!\n", rc); |
| 480 | |
| 481 | if (likely(pass)) |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 482 | hisi_hba->hw->start_delivery(dq); |
| 483 | spin_unlock_irqrestore(&dq->lock, flags); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 484 | |
| 485 | return rc; |
| 486 | } |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 487 | |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 488 | static void hisi_sas_bytes_dmaed(struct hisi_hba *hisi_hba, int phy_no) |
| 489 | { |
| 490 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; |
| 491 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
| 492 | struct sas_ha_struct *sas_ha; |
| 493 | |
| 494 | if (!phy->phy_attached) |
| 495 | return; |
| 496 | |
| 497 | sas_ha = &hisi_hba->sha; |
| 498 | sas_ha->notify_phy_event(sas_phy, PHYE_OOB_DONE); |
| 499 | |
| 500 | if (sas_phy->phy) { |
| 501 | struct sas_phy *sphy = sas_phy->phy; |
| 502 | |
| 503 | sphy->negotiated_linkrate = sas_phy->linkrate; |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 504 | sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; |
Xiang Chen | 2ae7578 | 2016-11-07 20:48:40 +0800 | [diff] [blame] | 505 | sphy->maximum_linkrate_hw = |
| 506 | hisi_hba->hw->phy_get_max_linkrate(); |
| 507 | if (sphy->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) |
| 508 | sphy->minimum_linkrate = phy->minimum_linkrate; |
| 509 | |
| 510 | if (sphy->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) |
| 511 | sphy->maximum_linkrate = phy->maximum_linkrate; |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | if (phy->phy_type & PORT_TYPE_SAS) { |
| 515 | struct sas_identify_frame *id; |
| 516 | |
| 517 | id = (struct sas_identify_frame *)phy->frame_rcvd; |
| 518 | id->dev_type = phy->identify.device_type; |
| 519 | id->initiator_bits = SAS_PROTOCOL_ALL; |
| 520 | id->target_bits = phy->identify.target_port_protocols; |
| 521 | } else if (phy->phy_type & PORT_TYPE_SATA) { |
| 522 | /*Nothing*/ |
| 523 | } |
| 524 | |
| 525 | sas_phy->frame_rcvd_size = phy->frame_rcvd_size; |
| 526 | sas_ha->notify_port_event(sas_phy, PORTE_BYTES_DMAED); |
| 527 | } |
| 528 | |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 529 | static struct hisi_sas_device *hisi_sas_alloc_dev(struct domain_device *device) |
| 530 | { |
| 531 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); |
| 532 | struct hisi_sas_device *sas_dev = NULL; |
Xiaofei Tan | 302e090 | 2017-10-24 23:51:33 +0800 | [diff] [blame] | 533 | unsigned long flags; |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 534 | int i; |
| 535 | |
Xiaofei Tan | 302e090 | 2017-10-24 23:51:33 +0800 | [diff] [blame] | 536 | spin_lock_irqsave(&hisi_hba->lock, flags); |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 537 | for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) { |
| 538 | if (hisi_hba->devices[i].dev_type == SAS_PHY_UNUSED) { |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 539 | int queue = i % hisi_hba->queue_count; |
| 540 | struct hisi_sas_dq *dq = &hisi_hba->dq[queue]; |
| 541 | |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 542 | hisi_hba->devices[i].device_id = i; |
| 543 | sas_dev = &hisi_hba->devices[i]; |
| 544 | sas_dev->dev_status = HISI_SAS_DEV_NORMAL; |
| 545 | sas_dev->dev_type = device->dev_type; |
| 546 | sas_dev->hisi_hba = hisi_hba; |
| 547 | sas_dev->sas_device = device; |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 548 | sas_dev->dq = dq; |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 549 | INIT_LIST_HEAD(&hisi_hba->devices[i].list); |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 550 | break; |
| 551 | } |
| 552 | } |
Xiaofei Tan | 302e090 | 2017-10-24 23:51:33 +0800 | [diff] [blame] | 553 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 554 | |
| 555 | return sas_dev; |
| 556 | } |
| 557 | |
| 558 | static int hisi_sas_dev_found(struct domain_device *device) |
| 559 | { |
| 560 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); |
| 561 | struct domain_device *parent_dev = device->parent; |
| 562 | struct hisi_sas_device *sas_dev; |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 563 | struct device *dev = hisi_hba->dev; |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 564 | |
John Garry | 685b6d6 | 2016-04-15 21:36:36 +0800 | [diff] [blame] | 565 | if (hisi_hba->hw->alloc_dev) |
| 566 | sas_dev = hisi_hba->hw->alloc_dev(device); |
| 567 | else |
| 568 | sas_dev = hisi_sas_alloc_dev(device); |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 569 | if (!sas_dev) { |
| 570 | dev_err(dev, "fail alloc dev: max support %d devices\n", |
| 571 | HISI_SAS_MAX_DEVICES); |
| 572 | return -EINVAL; |
| 573 | } |
| 574 | |
| 575 | device->lldd_dev = sas_dev; |
| 576 | hisi_hba->hw->setup_itct(hisi_hba, sas_dev); |
| 577 | |
| 578 | if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type)) { |
| 579 | int phy_no; |
| 580 | u8 phy_num = parent_dev->ex_dev.num_phys; |
| 581 | struct ex_phy *phy; |
| 582 | |
| 583 | for (phy_no = 0; phy_no < phy_num; phy_no++) { |
| 584 | phy = &parent_dev->ex_dev.ex_phy[phy_no]; |
| 585 | if (SAS_ADDR(phy->attached_sas_addr) == |
| 586 | SAS_ADDR(device->sas_addr)) { |
| 587 | sas_dev->attached_phy = phy_no; |
| 588 | break; |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | if (phy_no == phy_num) { |
| 593 | dev_info(dev, "dev found: no attached " |
| 594 | "dev:%016llx at ex:%016llx\n", |
| 595 | SAS_ADDR(device->sas_addr), |
| 596 | SAS_ADDR(parent_dev->sas_addr)); |
| 597 | return -EINVAL; |
| 598 | } |
| 599 | } |
| 600 | |
Xiang Chen | f1c8821 | 2017-12-09 01:16:41 +0800 | [diff] [blame] | 601 | dev_info(dev, "dev[%d:%x] found\n", |
| 602 | sas_dev->device_id, sas_dev->dev_type); |
| 603 | |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 604 | return 0; |
| 605 | } |
| 606 | |
John Garry | 31eec8a | 2016-02-25 17:42:14 +0800 | [diff] [blame] | 607 | static int hisi_sas_slave_configure(struct scsi_device *sdev) |
| 608 | { |
| 609 | struct domain_device *dev = sdev_to_domain_dev(sdev); |
| 610 | int ret = sas_slave_configure(sdev); |
| 611 | |
| 612 | if (ret) |
| 613 | return ret; |
| 614 | if (!dev_is_sata(dev)) |
| 615 | sas_change_queue_depth(sdev, 64); |
| 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
John Garry | 701f75e | 2015-11-18 00:50:55 +0800 | [diff] [blame] | 620 | static void hisi_sas_scan_start(struct Scsi_Host *shost) |
| 621 | { |
| 622 | struct hisi_hba *hisi_hba = shost_priv(shost); |
John Garry | 701f75e | 2015-11-18 00:50:55 +0800 | [diff] [blame] | 623 | |
John Garry | 396b804 | 2017-03-23 01:25:19 +0800 | [diff] [blame] | 624 | hisi_hba->hw->phys_init(hisi_hba); |
John Garry | 701f75e | 2015-11-18 00:50:55 +0800 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | static int hisi_sas_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 628 | { |
| 629 | struct hisi_hba *hisi_hba = shost_priv(shost); |
| 630 | struct sas_ha_struct *sha = &hisi_hba->sha; |
| 631 | |
John Garry | 396b804 | 2017-03-23 01:25:19 +0800 | [diff] [blame] | 632 | /* Wait for PHY up interrupt to occur */ |
| 633 | if (time < HZ) |
John Garry | 701f75e | 2015-11-18 00:50:55 +0800 | [diff] [blame] | 634 | return 0; |
| 635 | |
| 636 | sas_drain_work(sha); |
| 637 | return 1; |
| 638 | } |
| 639 | |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 640 | static void hisi_sas_phyup_work(struct work_struct *work) |
| 641 | { |
| 642 | struct hisi_sas_phy *phy = |
Xiaofei Tan | e537b62 | 2017-12-09 01:16:44 +0800 | [diff] [blame] | 643 | container_of(work, typeof(*phy), works[HISI_PHYE_PHY_UP]); |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 644 | struct hisi_hba *hisi_hba = phy->hisi_hba; |
| 645 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
| 646 | int phy_no = sas_phy->id; |
| 647 | |
| 648 | hisi_hba->hw->sl_notify(hisi_hba, phy_no); /* This requires a sleep */ |
| 649 | hisi_sas_bytes_dmaed(hisi_hba, phy_no); |
| 650 | } |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 651 | |
Xiaofei Tan | 057c3d1 | 2017-12-09 01:16:45 +0800 | [diff] [blame] | 652 | static void hisi_sas_linkreset_work(struct work_struct *work) |
| 653 | { |
| 654 | struct hisi_sas_phy *phy = |
| 655 | container_of(work, typeof(*phy), works[HISI_PHYE_LINK_RESET]); |
| 656 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
| 657 | |
| 658 | hisi_sas_control_phy(sas_phy, PHY_FUNC_LINK_RESET, NULL); |
| 659 | } |
| 660 | |
Xiaofei Tan | e537b62 | 2017-12-09 01:16:44 +0800 | [diff] [blame] | 661 | static const work_func_t hisi_sas_phye_fns[HISI_PHYES_NUM] = { |
| 662 | [HISI_PHYE_PHY_UP] = hisi_sas_phyup_work, |
Xiaofei Tan | 057c3d1 | 2017-12-09 01:16:45 +0800 | [diff] [blame] | 663 | [HISI_PHYE_LINK_RESET] = hisi_sas_linkreset_work, |
Xiaofei Tan | e537b62 | 2017-12-09 01:16:44 +0800 | [diff] [blame] | 664 | }; |
| 665 | |
| 666 | bool hisi_sas_notify_phy_event(struct hisi_sas_phy *phy, |
| 667 | enum hisi_sas_phy_event event) |
| 668 | { |
| 669 | struct hisi_hba *hisi_hba = phy->hisi_hba; |
| 670 | |
| 671 | if (WARN_ON(event >= HISI_PHYES_NUM)) |
| 672 | return false; |
| 673 | |
| 674 | return queue_work(hisi_hba->wq, &phy->works[event]); |
| 675 | } |
| 676 | EXPORT_SYMBOL_GPL(hisi_sas_notify_phy_event); |
| 677 | |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 678 | static void hisi_sas_phy_init(struct hisi_hba *hisi_hba, int phy_no) |
| 679 | { |
| 680 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; |
| 681 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
Xiaofei Tan | e537b62 | 2017-12-09 01:16:44 +0800 | [diff] [blame] | 682 | int i; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 683 | |
| 684 | phy->hisi_hba = hisi_hba; |
| 685 | phy->port = NULL; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 686 | sas_phy->enabled = (phy_no < hisi_hba->n_phy) ? 1 : 0; |
| 687 | sas_phy->class = SAS; |
| 688 | sas_phy->iproto = SAS_PROTOCOL_ALL; |
| 689 | sas_phy->tproto = 0; |
| 690 | sas_phy->type = PHY_TYPE_PHYSICAL; |
| 691 | sas_phy->role = PHY_ROLE_INITIATOR; |
| 692 | sas_phy->oob_mode = OOB_NOT_CONNECTED; |
| 693 | sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN; |
| 694 | sas_phy->id = phy_no; |
| 695 | sas_phy->sas_addr = &hisi_hba->sas_addr[0]; |
| 696 | sas_phy->frame_rcvd = &phy->frame_rcvd[0]; |
| 697 | sas_phy->ha = (struct sas_ha_struct *)hisi_hba->shost->hostdata; |
| 698 | sas_phy->lldd_phy = phy; |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 699 | |
Xiaofei Tan | e537b62 | 2017-12-09 01:16:44 +0800 | [diff] [blame] | 700 | for (i = 0; i < HISI_PHYES_NUM; i++) |
| 701 | INIT_WORK(&phy->works[i], hisi_sas_phye_fns[i]); |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 702 | } |
| 703 | |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 704 | static void hisi_sas_port_notify_formed(struct asd_sas_phy *sas_phy) |
| 705 | { |
| 706 | struct sas_ha_struct *sas_ha = sas_phy->ha; |
| 707 | struct hisi_hba *hisi_hba = sas_ha->lldd_ha; |
| 708 | struct hisi_sas_phy *phy = sas_phy->lldd_phy; |
| 709 | struct asd_sas_port *sas_port = sas_phy->port; |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 710 | struct hisi_sas_port *port = to_hisi_sas_port(sas_port); |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 711 | unsigned long flags; |
| 712 | |
| 713 | if (!sas_port) |
| 714 | return; |
| 715 | |
| 716 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 717 | port->port_attached = 1; |
| 718 | port->id = phy->port_id; |
| 719 | phy->port = port; |
| 720 | sas_port->lldd_port = port; |
| 721 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 722 | } |
| 723 | |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 724 | static void hisi_sas_do_release_task(struct hisi_hba *hisi_hba, struct sas_task *task, |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 725 | struct hisi_sas_slot *slot) |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 726 | { |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 727 | if (task) { |
| 728 | unsigned long flags; |
| 729 | struct task_status_struct *ts; |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 730 | |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 731 | ts = &task->task_status; |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 732 | |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 733 | ts->resp = SAS_TASK_COMPLETE; |
| 734 | ts->stat = SAS_ABORTED_TASK; |
| 735 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 736 | task->task_state_flags &= |
| 737 | ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR); |
| 738 | task->task_state_flags |= SAS_TASK_STATE_DONE; |
| 739 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 740 | } |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 741 | |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 742 | hisi_sas_slot_task_free(hisi_hba, task, slot); |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 743 | } |
| 744 | |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 745 | /* hisi_hba.lock should be locked */ |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 746 | static void hisi_sas_release_task(struct hisi_hba *hisi_hba, |
| 747 | struct domain_device *device) |
| 748 | { |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 749 | struct hisi_sas_slot *slot, *slot2; |
| 750 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 751 | |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 752 | list_for_each_entry_safe(slot, slot2, &sas_dev->list, entry) |
| 753 | hisi_sas_do_release_task(hisi_hba, slot->task, slot); |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 754 | } |
| 755 | |
Xiang Chen | 4d0951e | 2017-12-09 01:16:50 +0800 | [diff] [blame] | 756 | void hisi_sas_release_tasks(struct hisi_hba *hisi_hba) |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 757 | { |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 758 | struct hisi_sas_device *sas_dev; |
| 759 | struct domain_device *device; |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 760 | int i; |
| 761 | |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 762 | for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) { |
| 763 | sas_dev = &hisi_hba->devices[i]; |
| 764 | device = sas_dev->sas_device; |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 765 | |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 766 | if ((sas_dev->dev_type == SAS_PHY_UNUSED) || |
| 767 | !device) |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 768 | continue; |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 769 | |
| 770 | hisi_sas_release_task(hisi_hba, device); |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 771 | } |
| 772 | } |
Xiang Chen | 4d0951e | 2017-12-09 01:16:50 +0800 | [diff] [blame] | 773 | EXPORT_SYMBOL_GPL(hisi_sas_release_tasks); |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 774 | |
Xiang Chen | d30ff26 | 2017-06-14 23:33:32 +0800 | [diff] [blame] | 775 | static void hisi_sas_dereg_device(struct hisi_hba *hisi_hba, |
| 776 | struct domain_device *device) |
| 777 | { |
| 778 | if (hisi_hba->hw->dereg_device) |
| 779 | hisi_hba->hw->dereg_device(hisi_hba, device); |
| 780 | } |
| 781 | |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 782 | static void hisi_sas_dev_gone(struct domain_device *device) |
| 783 | { |
| 784 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 785 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 786 | struct device *dev = hisi_hba->dev; |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 787 | |
Xiang Chen | f1c8821 | 2017-12-09 01:16:41 +0800 | [diff] [blame] | 788 | dev_info(dev, "dev[%d:%x] is gone\n", |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 789 | sas_dev->device_id, sas_dev->dev_type); |
| 790 | |
Xiang Chen | f8e45ec | 2017-12-09 01:16:37 +0800 | [diff] [blame] | 791 | if (!test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags)) { |
| 792 | hisi_sas_internal_task_abort(hisi_hba, device, |
John Garry | 40f2702 | 2016-08-24 19:05:48 +0800 | [diff] [blame] | 793 | HISI_SAS_INT_ABT_DEV, 0); |
| 794 | |
Xiang Chen | f8e45ec | 2017-12-09 01:16:37 +0800 | [diff] [blame] | 795 | hisi_sas_dereg_device(hisi_hba, device); |
Xiang Chen | d30ff26 | 2017-06-14 23:33:32 +0800 | [diff] [blame] | 796 | |
Xiang Chen | f8e45ec | 2017-12-09 01:16:37 +0800 | [diff] [blame] | 797 | hisi_hba->hw->clear_itct(hisi_hba, sas_dev); |
| 798 | device->lldd_dev = NULL; |
| 799 | memset(sas_dev, 0, sizeof(*sas_dev)); |
| 800 | } |
| 801 | |
Xiaofei Tan | 0258141 | 2017-12-09 01:16:34 +0800 | [diff] [blame] | 802 | if (hisi_hba->hw->free_device) |
| 803 | hisi_hba->hw->free_device(sas_dev); |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 804 | sas_dev->dev_type = SAS_PHY_UNUSED; |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 805 | } |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 806 | |
| 807 | static int hisi_sas_queue_command(struct sas_task *task, gfp_t gfp_flags) |
| 808 | { |
| 809 | return hisi_sas_task_exec(task, gfp_flags, 0, NULL); |
| 810 | } |
| 811 | |
John Garry | e4189d5 | 2015-11-18 00:50:57 +0800 | [diff] [blame] | 812 | static int hisi_sas_control_phy(struct asd_sas_phy *sas_phy, enum phy_func func, |
| 813 | void *funcdata) |
| 814 | { |
| 815 | struct sas_ha_struct *sas_ha = sas_phy->ha; |
| 816 | struct hisi_hba *hisi_hba = sas_ha->lldd_ha; |
| 817 | int phy_no = sas_phy->id; |
| 818 | |
| 819 | switch (func) { |
| 820 | case PHY_FUNC_HARD_RESET: |
| 821 | hisi_hba->hw->phy_hard_reset(hisi_hba, phy_no); |
| 822 | break; |
| 823 | |
| 824 | case PHY_FUNC_LINK_RESET: |
John Garry | b4c67a6 | 2017-03-23 01:25:23 +0800 | [diff] [blame] | 825 | hisi_hba->hw->phy_disable(hisi_hba, phy_no); |
| 826 | msleep(100); |
Xiang Chen | 1eb8eea | 2017-10-24 23:51:36 +0800 | [diff] [blame] | 827 | hisi_hba->hw->phy_start(hisi_hba, phy_no); |
John Garry | e4189d5 | 2015-11-18 00:50:57 +0800 | [diff] [blame] | 828 | break; |
| 829 | |
| 830 | case PHY_FUNC_DISABLE: |
| 831 | hisi_hba->hw->phy_disable(hisi_hba, phy_no); |
| 832 | break; |
| 833 | |
| 834 | case PHY_FUNC_SET_LINK_RATE: |
Xiang Chen | 2ae7578 | 2016-11-07 20:48:40 +0800 | [diff] [blame] | 835 | hisi_hba->hw->phy_set_linkrate(hisi_hba, phy_no, funcdata); |
| 836 | break; |
Xiaofei Tan | c52108c | 2017-08-11 00:09:29 +0800 | [diff] [blame] | 837 | case PHY_FUNC_GET_EVENTS: |
| 838 | if (hisi_hba->hw->get_events) { |
| 839 | hisi_hba->hw->get_events(hisi_hba, phy_no); |
| 840 | break; |
| 841 | } |
| 842 | /* fallthru */ |
John Garry | e4189d5 | 2015-11-18 00:50:57 +0800 | [diff] [blame] | 843 | case PHY_FUNC_RELEASE_SPINUP_HOLD: |
| 844 | default: |
| 845 | return -EOPNOTSUPP; |
| 846 | } |
| 847 | return 0; |
| 848 | } |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 849 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 850 | static void hisi_sas_task_done(struct sas_task *task) |
| 851 | { |
| 852 | if (!del_timer(&task->slow_task->timer)) |
| 853 | return; |
| 854 | complete(&task->slow_task->completion); |
| 855 | } |
| 856 | |
Kees Cook | 77570ee | 2017-08-22 16:05:14 -0700 | [diff] [blame] | 857 | static void hisi_sas_tmf_timedout(struct timer_list *t) |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 858 | { |
Kees Cook | 77570ee | 2017-08-22 16:05:14 -0700 | [diff] [blame] | 859 | struct sas_task_slow *slow = from_timer(slow, t, timer); |
| 860 | struct sas_task *task = slow->task; |
Xiang Chen | f64a698 | 2017-06-14 23:33:11 +0800 | [diff] [blame] | 861 | unsigned long flags; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 862 | |
Xiang Chen | f64a698 | 2017-06-14 23:33:11 +0800 | [diff] [blame] | 863 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 864 | if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) |
| 865 | task->task_state_flags |= SAS_TASK_STATE_ABORTED; |
| 866 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 867 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 868 | complete(&task->slow_task->completion); |
| 869 | } |
| 870 | |
| 871 | #define TASK_TIMEOUT 20 |
| 872 | #define TASK_RETRY 3 |
| 873 | static int hisi_sas_exec_internal_tmf_task(struct domain_device *device, |
| 874 | void *parameter, u32 para_len, |
| 875 | struct hisi_sas_tmf_task *tmf) |
| 876 | { |
| 877 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 878 | struct hisi_hba *hisi_hba = sas_dev->hisi_hba; |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 879 | struct device *dev = hisi_hba->dev; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 880 | struct sas_task *task; |
| 881 | int res, retry; |
| 882 | |
| 883 | for (retry = 0; retry < TASK_RETRY; retry++) { |
| 884 | task = sas_alloc_slow_task(GFP_KERNEL); |
| 885 | if (!task) |
| 886 | return -ENOMEM; |
| 887 | |
| 888 | task->dev = device; |
| 889 | task->task_proto = device->tproto; |
| 890 | |
Xiang Chen | 7c594f0 | 2017-03-23 01:25:20 +0800 | [diff] [blame] | 891 | if (dev_is_sata(device)) { |
| 892 | task->ata_task.device_control_reg_update = 1; |
| 893 | memcpy(&task->ata_task.fis, parameter, para_len); |
| 894 | } else { |
| 895 | memcpy(&task->ssp_task, parameter, para_len); |
| 896 | } |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 897 | task->task_done = hisi_sas_task_done; |
| 898 | |
Kees Cook | 841b86f | 2017-10-23 09:40:42 +0200 | [diff] [blame] | 899 | task->slow_task->timer.function = hisi_sas_tmf_timedout; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 900 | task->slow_task->timer.expires = jiffies + TASK_TIMEOUT*HZ; |
| 901 | add_timer(&task->slow_task->timer); |
| 902 | |
| 903 | res = hisi_sas_task_exec(task, GFP_KERNEL, 1, tmf); |
| 904 | |
| 905 | if (res) { |
| 906 | del_timer(&task->slow_task->timer); |
| 907 | dev_err(dev, "abort tmf: executing internal task failed: %d\n", |
| 908 | res); |
| 909 | goto ex_err; |
| 910 | } |
| 911 | |
| 912 | wait_for_completion(&task->slow_task->completion); |
| 913 | res = TMF_RESP_FUNC_FAILED; |
| 914 | /* Even TMF timed out, return direct. */ |
| 915 | if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) { |
| 916 | if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 917 | struct hisi_sas_slot *slot = task->lldd_task; |
| 918 | |
Xiang Chen | f1c8821 | 2017-12-09 01:16:41 +0800 | [diff] [blame] | 919 | dev_err(dev, "abort tmf: TMF task timeout and not done\n"); |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 920 | if (slot) |
| 921 | slot->task = NULL; |
| 922 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 923 | goto ex_err; |
Xiang Chen | f1c8821 | 2017-12-09 01:16:41 +0800 | [diff] [blame] | 924 | } else |
| 925 | dev_err(dev, "abort tmf: TMF task timeout\n"); |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
John Garry | 1af1b80 | 2016-02-25 17:42:10 +0800 | [diff] [blame] | 929 | task->task_status.stat == TMF_RESP_FUNC_COMPLETE) { |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 930 | res = TMF_RESP_FUNC_COMPLETE; |
| 931 | break; |
| 932 | } |
| 933 | |
| 934 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
John Garry | 4ffde48 | 2016-08-24 19:05:53 +0800 | [diff] [blame] | 935 | task->task_status.stat == TMF_RESP_FUNC_SUCC) { |
| 936 | res = TMF_RESP_FUNC_SUCC; |
| 937 | break; |
| 938 | } |
| 939 | |
| 940 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 941 | task->task_status.stat == SAS_DATA_UNDERRUN) { |
| 942 | /* no error, but return the number of bytes of |
| 943 | * underrun |
| 944 | */ |
| 945 | dev_warn(dev, "abort tmf: task to dev %016llx " |
| 946 | "resp: 0x%x sts 0x%x underrun\n", |
| 947 | SAS_ADDR(device->sas_addr), |
| 948 | task->task_status.resp, |
| 949 | task->task_status.stat); |
| 950 | res = task->task_status.residual; |
| 951 | break; |
| 952 | } |
| 953 | |
| 954 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
| 955 | task->task_status.stat == SAS_DATA_OVERRUN) { |
| 956 | dev_warn(dev, "abort tmf: blocked task error\n"); |
| 957 | res = -EMSGSIZE; |
| 958 | break; |
| 959 | } |
| 960 | |
| 961 | dev_warn(dev, "abort tmf: task to dev " |
| 962 | "%016llx resp: 0x%x status 0x%x\n", |
| 963 | SAS_ADDR(device->sas_addr), task->task_status.resp, |
| 964 | task->task_status.stat); |
| 965 | sas_free_task(task); |
| 966 | task = NULL; |
| 967 | } |
| 968 | ex_err: |
Xiang Chen | d2d7e7a | 2016-11-07 20:48:34 +0800 | [diff] [blame] | 969 | if (retry == TASK_RETRY) |
| 970 | dev_warn(dev, "abort tmf: executing internal task failed!\n"); |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 971 | sas_free_task(task); |
| 972 | return res; |
| 973 | } |
| 974 | |
Xiang Chen | 7c594f0 | 2017-03-23 01:25:20 +0800 | [diff] [blame] | 975 | static void hisi_sas_fill_ata_reset_cmd(struct ata_device *dev, |
| 976 | bool reset, int pmp, u8 *fis) |
| 977 | { |
| 978 | struct ata_taskfile tf; |
| 979 | |
| 980 | ata_tf_init(dev, &tf); |
| 981 | if (reset) |
| 982 | tf.ctl |= ATA_SRST; |
| 983 | else |
| 984 | tf.ctl &= ~ATA_SRST; |
| 985 | tf.command = ATA_CMD_DEV_RESET; |
| 986 | ata_tf_to_fis(&tf, pmp, 0, fis); |
| 987 | } |
| 988 | |
| 989 | static int hisi_sas_softreset_ata_disk(struct domain_device *device) |
| 990 | { |
| 991 | u8 fis[20] = {0}; |
| 992 | struct ata_port *ap = device->sata_dev.ap; |
| 993 | struct ata_link *link; |
| 994 | int rc = TMF_RESP_FUNC_FAILED; |
| 995 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 996 | struct device *dev = hisi_hba->dev; |
Xiang Chen | 7c594f0 | 2017-03-23 01:25:20 +0800 | [diff] [blame] | 997 | int s = sizeof(struct host_to_dev_fis); |
| 998 | unsigned long flags; |
| 999 | |
| 1000 | ata_for_each_link(link, ap, EDGE) { |
| 1001 | int pmp = sata_srst_pmp(link); |
| 1002 | |
| 1003 | hisi_sas_fill_ata_reset_cmd(link->device, 1, pmp, fis); |
| 1004 | rc = hisi_sas_exec_internal_tmf_task(device, fis, s, NULL); |
| 1005 | if (rc != TMF_RESP_FUNC_COMPLETE) |
| 1006 | break; |
| 1007 | } |
| 1008 | |
| 1009 | if (rc == TMF_RESP_FUNC_COMPLETE) { |
| 1010 | ata_for_each_link(link, ap, EDGE) { |
| 1011 | int pmp = sata_srst_pmp(link); |
| 1012 | |
| 1013 | hisi_sas_fill_ata_reset_cmd(link->device, 0, pmp, fis); |
| 1014 | rc = hisi_sas_exec_internal_tmf_task(device, fis, |
| 1015 | s, NULL); |
| 1016 | if (rc != TMF_RESP_FUNC_COMPLETE) |
| 1017 | dev_err(dev, "ata disk de-reset failed\n"); |
| 1018 | } |
| 1019 | } else { |
| 1020 | dev_err(dev, "ata disk reset failed\n"); |
| 1021 | } |
| 1022 | |
| 1023 | if (rc == TMF_RESP_FUNC_COMPLETE) { |
| 1024 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 1025 | hisi_sas_release_task(hisi_hba, device); |
| 1026 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 1027 | } |
| 1028 | |
| 1029 | return rc; |
| 1030 | } |
| 1031 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1032 | static int hisi_sas_debug_issue_ssp_tmf(struct domain_device *device, |
| 1033 | u8 *lun, struct hisi_sas_tmf_task *tmf) |
| 1034 | { |
| 1035 | struct sas_ssp_task ssp_task; |
| 1036 | |
| 1037 | if (!(device->tproto & SAS_PROTOCOL_SSP)) |
| 1038 | return TMF_RESP_FUNC_ESUPP; |
| 1039 | |
| 1040 | memcpy(ssp_task.LUN, lun, 8); |
| 1041 | |
| 1042 | return hisi_sas_exec_internal_tmf_task(device, &ssp_task, |
| 1043 | sizeof(ssp_task), tmf); |
| 1044 | } |
| 1045 | |
Xiaofei Tan | a669bdb | 2017-12-09 01:16:35 +0800 | [diff] [blame] | 1046 | static void hisi_sas_refresh_port_id(struct hisi_hba *hisi_hba) |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1047 | { |
Xiaofei Tan | a669bdb | 2017-12-09 01:16:35 +0800 | [diff] [blame] | 1048 | u32 state = hisi_hba->hw->get_phys_state(hisi_hba); |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1049 | int i; |
| 1050 | |
| 1051 | for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) { |
Xiaofei Tan | a669bdb | 2017-12-09 01:16:35 +0800 | [diff] [blame] | 1052 | struct hisi_sas_device *sas_dev = &hisi_hba->devices[i]; |
| 1053 | struct domain_device *device = sas_dev->sas_device; |
| 1054 | struct asd_sas_port *sas_port; |
| 1055 | struct hisi_sas_port *port; |
| 1056 | struct hisi_sas_phy *phy = NULL; |
| 1057 | struct asd_sas_phy *sas_phy; |
| 1058 | |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1059 | if ((sas_dev->dev_type == SAS_PHY_UNUSED) |
Xiaofei Tan | a669bdb | 2017-12-09 01:16:35 +0800 | [diff] [blame] | 1060 | || !device || !device->port) |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1061 | continue; |
| 1062 | |
Xiaofei Tan | a669bdb | 2017-12-09 01:16:35 +0800 | [diff] [blame] | 1063 | sas_port = device->port; |
| 1064 | port = to_hisi_sas_port(sas_port); |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1065 | |
Xiaofei Tan | a669bdb | 2017-12-09 01:16:35 +0800 | [diff] [blame] | 1066 | list_for_each_entry(sas_phy, &sas_port->phy_list, port_phy_el) |
| 1067 | if (state & BIT(sas_phy->id)) { |
| 1068 | phy = sas_phy->lldd_phy; |
| 1069 | break; |
| 1070 | } |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1071 | |
Xiaofei Tan | a669bdb | 2017-12-09 01:16:35 +0800 | [diff] [blame] | 1072 | if (phy) { |
| 1073 | port->id = phy->port_id; |
| 1074 | |
| 1075 | /* Update linkrate of directly attached device. */ |
| 1076 | if (!device->parent) |
| 1077 | device->linkrate = phy->sas_phy.linkrate; |
| 1078 | |
| 1079 | hisi_hba->hw->setup_itct(hisi_hba, sas_dev); |
| 1080 | } else |
| 1081 | port->id = 0xff; |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | static void hisi_sas_rescan_topology(struct hisi_hba *hisi_hba, u32 old_state, |
| 1086 | u32 state) |
| 1087 | { |
| 1088 | struct sas_ha_struct *sas_ha = &hisi_hba->sha; |
| 1089 | struct asd_sas_port *_sas_port = NULL; |
| 1090 | int phy_no; |
| 1091 | |
| 1092 | for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) { |
| 1093 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; |
| 1094 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
| 1095 | struct asd_sas_port *sas_port = sas_phy->port; |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1096 | bool do_port_check = !!(_sas_port != sas_port); |
| 1097 | |
| 1098 | if (!sas_phy->phy->enabled) |
| 1099 | continue; |
| 1100 | |
| 1101 | /* Report PHY state change to libsas */ |
Xiaofei Tan | a669bdb | 2017-12-09 01:16:35 +0800 | [diff] [blame] | 1102 | if (state & BIT(phy_no)) { |
| 1103 | if (do_port_check && sas_port && sas_port->port_dev) { |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1104 | struct domain_device *dev = sas_port->port_dev; |
| 1105 | |
| 1106 | _sas_port = sas_port; |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1107 | |
| 1108 | if (DEV_IS_EXPANDER(dev->dev_type)) |
| 1109 | sas_ha->notify_port_event(sas_phy, |
| 1110 | PORTE_BROADCAST_RCVD); |
| 1111 | } |
| 1112 | } else if (old_state & (1 << phy_no)) |
| 1113 | /* PHY down but was up before */ |
| 1114 | hisi_sas_phy_down(hisi_hba, phy_no, 0); |
| 1115 | |
| 1116 | } |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1117 | } |
| 1118 | |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1119 | static int hisi_sas_controller_reset(struct hisi_hba *hisi_hba) |
| 1120 | { |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1121 | struct device *dev = hisi_hba->dev; |
| 1122 | struct Scsi_Host *shost = hisi_hba->shost; |
| 1123 | u32 old_state, state; |
| 1124 | unsigned long flags; |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1125 | int rc; |
| 1126 | |
| 1127 | if (!hisi_hba->hw->soft_reset) |
| 1128 | return -1; |
| 1129 | |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1130 | if (test_and_set_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags)) |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1131 | return -1; |
| 1132 | |
Xiaofei Tan | fb51e7a | 2017-12-09 01:16:36 +0800 | [diff] [blame] | 1133 | dev_info(dev, "controller resetting...\n"); |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1134 | old_state = hisi_hba->hw->get_phys_state(hisi_hba); |
| 1135 | |
| 1136 | scsi_block_requests(shost); |
| 1137 | set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); |
| 1138 | rc = hisi_hba->hw->soft_reset(hisi_hba); |
| 1139 | if (rc) { |
| 1140 | dev_warn(dev, "controller reset failed (%d)\n", rc); |
| 1141 | clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); |
Xiaofei Tan | fb51e7a | 2017-12-09 01:16:36 +0800 | [diff] [blame] | 1142 | scsi_unblock_requests(shost); |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1143 | goto out; |
| 1144 | } |
| 1145 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 1146 | hisi_sas_release_tasks(hisi_hba); |
| 1147 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 1148 | |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1149 | clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); |
| 1150 | |
| 1151 | /* Init and wait for PHYs to come up and all libsas event finished. */ |
| 1152 | hisi_hba->hw->phys_init(hisi_hba); |
| 1153 | msleep(1000); |
Xiaofei Tan | a669bdb | 2017-12-09 01:16:35 +0800 | [diff] [blame] | 1154 | hisi_sas_refresh_port_id(hisi_hba); |
Xiaofei Tan | fb51e7a | 2017-12-09 01:16:36 +0800 | [diff] [blame] | 1155 | scsi_unblock_requests(shost); |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1156 | |
| 1157 | state = hisi_hba->hw->get_phys_state(hisi_hba); |
| 1158 | hisi_sas_rescan_topology(hisi_hba, old_state, state); |
Xiaofei Tan | fb51e7a | 2017-12-09 01:16:36 +0800 | [diff] [blame] | 1159 | dev_info(dev, "controller reset complete\n"); |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1160 | |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1161 | out: |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1162 | clear_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags); |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1163 | |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1164 | return rc; |
| 1165 | } |
| 1166 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1167 | static int hisi_sas_abort_task(struct sas_task *task) |
| 1168 | { |
| 1169 | struct scsi_lun lun; |
| 1170 | struct hisi_sas_tmf_task tmf_task; |
| 1171 | struct domain_device *device = task->dev; |
| 1172 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 1173 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(task->dev); |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 1174 | struct device *dev = hisi_hba->dev; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1175 | int rc = TMF_RESP_FUNC_FAILED; |
| 1176 | unsigned long flags; |
| 1177 | |
| 1178 | if (!sas_dev) { |
| 1179 | dev_warn(dev, "Device has been removed\n"); |
| 1180 | return TMF_RESP_FUNC_FAILED; |
| 1181 | } |
| 1182 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1183 | if (task->task_state_flags & SAS_TASK_STATE_DONE) { |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1184 | rc = TMF_RESP_FUNC_COMPLETE; |
| 1185 | goto out; |
| 1186 | } |
| 1187 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1188 | sas_dev->dev_status = HISI_SAS_DEV_EH; |
| 1189 | if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) { |
| 1190 | struct scsi_cmnd *cmnd = task->uldd_task; |
| 1191 | struct hisi_sas_slot *slot = task->lldd_task; |
| 1192 | u32 tag = slot->idx; |
John Garry | c35279f | 2017-03-23 01:25:25 +0800 | [diff] [blame] | 1193 | int rc2; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1194 | |
| 1195 | int_to_scsilun(cmnd->device->lun, &lun); |
| 1196 | tmf_task.tmf = TMF_ABORT_TASK; |
| 1197 | tmf_task.tag_of_task_to_be_managed = cpu_to_le16(tag); |
| 1198 | |
| 1199 | rc = hisi_sas_debug_issue_ssp_tmf(task->dev, lun.scsi_lun, |
| 1200 | &tmf_task); |
| 1201 | |
John Garry | c35279f | 2017-03-23 01:25:25 +0800 | [diff] [blame] | 1202 | rc2 = hisi_sas_internal_task_abort(hisi_hba, device, |
| 1203 | HISI_SAS_INT_ABT_CMD, tag); |
Xiaofei Tan | 813709f | 2017-12-09 01:16:46 +0800 | [diff] [blame] | 1204 | if (rc2 < 0) { |
| 1205 | dev_err(dev, "abort task: internal abort (%d)\n", rc2); |
| 1206 | return TMF_RESP_FUNC_FAILED; |
| 1207 | } |
| 1208 | |
John Garry | c35279f | 2017-03-23 01:25:25 +0800 | [diff] [blame] | 1209 | /* |
| 1210 | * If the TMF finds that the IO is not in the device and also |
| 1211 | * the internal abort does not succeed, then it is safe to |
| 1212 | * free the slot. |
| 1213 | * Note: if the internal abort succeeds then the slot |
| 1214 | * will have already been completed |
| 1215 | */ |
| 1216 | if (rc == TMF_RESP_FUNC_COMPLETE && rc2 != TMF_RESP_FUNC_SUCC) { |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1217 | if (task->lldd_task) { |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1218 | spin_lock_irqsave(&hisi_hba->lock, flags); |
John Garry | c35279f | 2017-03-23 01:25:25 +0800 | [diff] [blame] | 1219 | hisi_sas_do_release_task(hisi_hba, task, slot); |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1220 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 1221 | } |
| 1222 | } |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1223 | } else if (task->task_proto & SAS_PROTOCOL_SATA || |
| 1224 | task->task_proto & SAS_PROTOCOL_STP) { |
| 1225 | if (task->dev->dev_type == SAS_SATA_DEV) { |
Xiaofei Tan | 813709f | 2017-12-09 01:16:46 +0800 | [diff] [blame] | 1226 | rc = hisi_sas_internal_task_abort(hisi_hba, device, |
| 1227 | HISI_SAS_INT_ABT_DEV, 0); |
| 1228 | if (rc < 0) { |
| 1229 | dev_err(dev, "abort task: internal abort failed\n"); |
| 1230 | goto out; |
| 1231 | } |
Xiang Chen | d30ff26 | 2017-06-14 23:33:32 +0800 | [diff] [blame] | 1232 | hisi_sas_dereg_device(hisi_hba, device); |
Xiang Chen | 7c594f0 | 2017-03-23 01:25:20 +0800 | [diff] [blame] | 1233 | rc = hisi_sas_softreset_ata_disk(device); |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1234 | } |
Gustavo A. R. Silva | eb045e0 | 2017-05-22 13:00:29 -0500 | [diff] [blame] | 1235 | } else if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SMP) { |
John Garry | dc8a49c | 2016-08-24 19:05:49 +0800 | [diff] [blame] | 1236 | /* SMP */ |
| 1237 | struct hisi_sas_slot *slot = task->lldd_task; |
| 1238 | u32 tag = slot->idx; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1239 | |
Xiang Chen | ccbfe5a | 2017-03-23 01:25:36 +0800 | [diff] [blame] | 1240 | rc = hisi_sas_internal_task_abort(hisi_hba, device, |
| 1241 | HISI_SAS_INT_ABT_CMD, tag); |
Xiaofei Tan | 813709f | 2017-12-09 01:16:46 +0800 | [diff] [blame] | 1242 | if (((rc < 0) || (rc == TMF_RESP_FUNC_FAILED)) && |
| 1243 | task->lldd_task) { |
Xiang Chen | ccbfe5a | 2017-03-23 01:25:36 +0800 | [diff] [blame] | 1244 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 1245 | hisi_sas_do_release_task(hisi_hba, task, slot); |
| 1246 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 1247 | } |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | out: |
| 1251 | if (rc != TMF_RESP_FUNC_COMPLETE) |
| 1252 | dev_notice(dev, "abort task: rc=%d\n", rc); |
| 1253 | return rc; |
| 1254 | } |
| 1255 | |
| 1256 | static int hisi_sas_abort_task_set(struct domain_device *device, u8 *lun) |
| 1257 | { |
Xiaofei Tan | 2a03813 | 2017-12-09 01:16:47 +0800 | [diff] [blame] | 1258 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); |
| 1259 | struct device *dev = hisi_hba->dev; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1260 | struct hisi_sas_tmf_task tmf_task; |
| 1261 | int rc = TMF_RESP_FUNC_FAILED; |
Xiaofei Tan | 2a03813 | 2017-12-09 01:16:47 +0800 | [diff] [blame] | 1262 | unsigned long flags; |
| 1263 | |
| 1264 | rc = hisi_sas_internal_task_abort(hisi_hba, device, |
| 1265 | HISI_SAS_INT_ABT_DEV, 0); |
| 1266 | if (rc < 0) { |
| 1267 | dev_err(dev, "abort task set: internal abort rc=%d\n", rc); |
| 1268 | return TMF_RESP_FUNC_FAILED; |
| 1269 | } |
| 1270 | hisi_sas_dereg_device(hisi_hba, device); |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1271 | |
| 1272 | tmf_task.tmf = TMF_ABORT_TASK_SET; |
| 1273 | rc = hisi_sas_debug_issue_ssp_tmf(device, lun, &tmf_task); |
| 1274 | |
Xiaofei Tan | 2a03813 | 2017-12-09 01:16:47 +0800 | [diff] [blame] | 1275 | if (rc == TMF_RESP_FUNC_COMPLETE) { |
| 1276 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 1277 | hisi_sas_release_task(hisi_hba, device); |
| 1278 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 1279 | } |
| 1280 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1281 | return rc; |
| 1282 | } |
| 1283 | |
| 1284 | static int hisi_sas_clear_aca(struct domain_device *device, u8 *lun) |
| 1285 | { |
| 1286 | int rc = TMF_RESP_FUNC_FAILED; |
| 1287 | struct hisi_sas_tmf_task tmf_task; |
| 1288 | |
| 1289 | tmf_task.tmf = TMF_CLEAR_ACA; |
| 1290 | rc = hisi_sas_debug_issue_ssp_tmf(device, lun, &tmf_task); |
| 1291 | |
| 1292 | return rc; |
| 1293 | } |
| 1294 | |
| 1295 | static int hisi_sas_debug_I_T_nexus_reset(struct domain_device *device) |
| 1296 | { |
| 1297 | struct sas_phy *phy = sas_get_local_phy(device); |
| 1298 | int rc, reset_type = (device->dev_type == SAS_SATA_DEV || |
| 1299 | (device->tproto & SAS_PROTOCOL_STP)) ? 0 : 1; |
| 1300 | rc = sas_phy_reset(phy, reset_type); |
| 1301 | sas_put_local_phy(phy); |
| 1302 | msleep(2000); |
| 1303 | return rc; |
| 1304 | } |
| 1305 | |
| 1306 | static int hisi_sas_I_T_nexus_reset(struct domain_device *device) |
| 1307 | { |
| 1308 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 1309 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); |
Xiaofei Tan | 813709f | 2017-12-09 01:16:46 +0800 | [diff] [blame] | 1310 | struct device *dev = hisi_hba->dev; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1311 | int rc = TMF_RESP_FUNC_FAILED; |
Xiaofei Tan | 813709f | 2017-12-09 01:16:46 +0800 | [diff] [blame] | 1312 | unsigned long flags; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1313 | |
| 1314 | if (sas_dev->dev_status != HISI_SAS_DEV_EH) |
| 1315 | return TMF_RESP_FUNC_FAILED; |
| 1316 | sas_dev->dev_status = HISI_SAS_DEV_NORMAL; |
| 1317 | |
Xiaofei Tan | 813709f | 2017-12-09 01:16:46 +0800 | [diff] [blame] | 1318 | rc = hisi_sas_internal_task_abort(hisi_hba, device, |
Xiang Chen | d30ff26 | 2017-06-14 23:33:32 +0800 | [diff] [blame] | 1319 | HISI_SAS_INT_ABT_DEV, 0); |
Xiaofei Tan | 813709f | 2017-12-09 01:16:46 +0800 | [diff] [blame] | 1320 | if (rc < 0) { |
| 1321 | dev_err(dev, "I_T nexus reset: internal abort (%d)\n", rc); |
| 1322 | return TMF_RESP_FUNC_FAILED; |
| 1323 | } |
Xiang Chen | d30ff26 | 2017-06-14 23:33:32 +0800 | [diff] [blame] | 1324 | hisi_sas_dereg_device(hisi_hba, device); |
| 1325 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1326 | rc = hisi_sas_debug_I_T_nexus_reset(device); |
| 1327 | |
Xiang Chen | 9960a24 | 2017-12-09 01:16:48 +0800 | [diff] [blame] | 1328 | if ((rc == TMF_RESP_FUNC_COMPLETE) || (rc == -ENODEV)) { |
Xiang Chen | 6131243 | 2017-03-23 01:25:28 +0800 | [diff] [blame] | 1329 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 1330 | hisi_sas_release_task(hisi_hba, device); |
| 1331 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 1332 | } |
| 1333 | return rc; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | static int hisi_sas_lu_reset(struct domain_device *device, u8 *lun) |
| 1337 | { |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1338 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 1339 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 1340 | struct device *dev = hisi_hba->dev; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1341 | unsigned long flags; |
| 1342 | int rc = TMF_RESP_FUNC_FAILED; |
| 1343 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1344 | sas_dev->dev_status = HISI_SAS_DEV_EH; |
John Garry | 055945d | 2017-03-23 01:25:26 +0800 | [diff] [blame] | 1345 | if (dev_is_sata(device)) { |
| 1346 | struct sas_phy *phy; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1347 | |
John Garry | 055945d | 2017-03-23 01:25:26 +0800 | [diff] [blame] | 1348 | /* Clear internal IO and then hardreset */ |
| 1349 | rc = hisi_sas_internal_task_abort(hisi_hba, device, |
| 1350 | HISI_SAS_INT_ABT_DEV, 0); |
Xiaofei Tan | 813709f | 2017-12-09 01:16:46 +0800 | [diff] [blame] | 1351 | if (rc < 0) { |
| 1352 | dev_err(dev, "lu_reset: internal abort failed\n"); |
John Garry | 055945d | 2017-03-23 01:25:26 +0800 | [diff] [blame] | 1353 | goto out; |
Xiaofei Tan | 813709f | 2017-12-09 01:16:46 +0800 | [diff] [blame] | 1354 | } |
Xiang Chen | d30ff26 | 2017-06-14 23:33:32 +0800 | [diff] [blame] | 1355 | hisi_sas_dereg_device(hisi_hba, device); |
John Garry | 055945d | 2017-03-23 01:25:26 +0800 | [diff] [blame] | 1356 | |
| 1357 | phy = sas_get_local_phy(device); |
| 1358 | |
| 1359 | rc = sas_phy_reset(phy, 1); |
| 1360 | |
| 1361 | if (rc == 0) { |
| 1362 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 1363 | hisi_sas_release_task(hisi_hba, device); |
| 1364 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 1365 | } |
| 1366 | sas_put_local_phy(phy); |
| 1367 | } else { |
| 1368 | struct hisi_sas_tmf_task tmf_task = { .tmf = TMF_LU_RESET }; |
| 1369 | |
Xiaofei Tan | 2a03813 | 2017-12-09 01:16:47 +0800 | [diff] [blame] | 1370 | rc = hisi_sas_internal_task_abort(hisi_hba, device, |
| 1371 | HISI_SAS_INT_ABT_DEV, 0); |
| 1372 | if (rc < 0) { |
| 1373 | dev_err(dev, "lu_reset: internal abort failed\n"); |
| 1374 | goto out; |
| 1375 | } |
| 1376 | hisi_sas_dereg_device(hisi_hba, device); |
| 1377 | |
John Garry | 055945d | 2017-03-23 01:25:26 +0800 | [diff] [blame] | 1378 | rc = hisi_sas_debug_issue_ssp_tmf(device, lun, &tmf_task); |
| 1379 | if (rc == TMF_RESP_FUNC_COMPLETE) { |
| 1380 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 1381 | hisi_sas_release_task(hisi_hba, device); |
| 1382 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 1383 | } |
| 1384 | } |
| 1385 | out: |
John Garry | 14d3f39 | 2017-03-23 01:25:37 +0800 | [diff] [blame] | 1386 | if (rc != TMF_RESP_FUNC_COMPLETE) |
John Garry | ad60483 | 2017-06-14 23:33:12 +0800 | [diff] [blame] | 1387 | dev_err(dev, "lu_reset: for device[%d]:rc= %d\n", |
John Garry | 14d3f39 | 2017-03-23 01:25:37 +0800 | [diff] [blame] | 1388 | sas_dev->device_id, rc); |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1389 | return rc; |
| 1390 | } |
| 1391 | |
John Garry | 8b05ad6 | 2017-03-23 01:25:35 +0800 | [diff] [blame] | 1392 | static int hisi_sas_clear_nexus_ha(struct sas_ha_struct *sas_ha) |
| 1393 | { |
| 1394 | struct hisi_hba *hisi_hba = sas_ha->lldd_ha; |
Xiaofei Tan | e402acd | 2017-12-09 01:16:38 +0800 | [diff] [blame] | 1395 | HISI_SAS_DECLARE_RST_WORK_ON_STACK(r); |
John Garry | 8b05ad6 | 2017-03-23 01:25:35 +0800 | [diff] [blame] | 1396 | |
Xiaofei Tan | e402acd | 2017-12-09 01:16:38 +0800 | [diff] [blame] | 1397 | queue_work(hisi_hba->wq, &r.work); |
| 1398 | wait_for_completion(r.completion); |
| 1399 | if (r.done) |
| 1400 | return TMF_RESP_FUNC_COMPLETE; |
| 1401 | |
| 1402 | return TMF_RESP_FUNC_FAILED; |
John Garry | 8b05ad6 | 2017-03-23 01:25:35 +0800 | [diff] [blame] | 1403 | } |
| 1404 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1405 | static int hisi_sas_query_task(struct sas_task *task) |
| 1406 | { |
| 1407 | struct scsi_lun lun; |
| 1408 | struct hisi_sas_tmf_task tmf_task; |
| 1409 | int rc = TMF_RESP_FUNC_FAILED; |
| 1410 | |
| 1411 | if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) { |
| 1412 | struct scsi_cmnd *cmnd = task->uldd_task; |
| 1413 | struct domain_device *device = task->dev; |
| 1414 | struct hisi_sas_slot *slot = task->lldd_task; |
| 1415 | u32 tag = slot->idx; |
| 1416 | |
| 1417 | int_to_scsilun(cmnd->device->lun, &lun); |
| 1418 | tmf_task.tmf = TMF_QUERY_TASK; |
| 1419 | tmf_task.tag_of_task_to_be_managed = cpu_to_le16(tag); |
| 1420 | |
| 1421 | rc = hisi_sas_debug_issue_ssp_tmf(device, |
| 1422 | lun.scsi_lun, |
| 1423 | &tmf_task); |
| 1424 | switch (rc) { |
| 1425 | /* The task is still in Lun, release it then */ |
| 1426 | case TMF_RESP_FUNC_SUCC: |
| 1427 | /* The task is not in Lun or failed, reset the phy */ |
| 1428 | case TMF_RESP_FUNC_FAILED: |
| 1429 | case TMF_RESP_FUNC_COMPLETE: |
| 1430 | break; |
Xiang Chen | 997ee43 | 2016-11-07 20:48:35 +0800 | [diff] [blame] | 1431 | default: |
| 1432 | rc = TMF_RESP_FUNC_FAILED; |
| 1433 | break; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1434 | } |
| 1435 | } |
| 1436 | return rc; |
| 1437 | } |
| 1438 | |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1439 | static int |
John Garry | ad60483 | 2017-06-14 23:33:12 +0800 | [diff] [blame] | 1440 | hisi_sas_internal_abort_task_exec(struct hisi_hba *hisi_hba, int device_id, |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1441 | struct sas_task *task, int abort_flag, |
| 1442 | int task_tag) |
| 1443 | { |
| 1444 | struct domain_device *device = task->dev; |
| 1445 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 1446 | struct device *dev = hisi_hba->dev; |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1447 | struct hisi_sas_port *port; |
| 1448 | struct hisi_sas_slot *slot; |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 1449 | struct asd_sas_port *sas_port = device->port; |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1450 | struct hisi_sas_cmd_hdr *cmd_hdr_base; |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 1451 | struct hisi_sas_dq *dq = sas_dev->dq; |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1452 | int dlvry_queue_slot, dlvry_queue, n_elem = 0, rc, slot_idx; |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 1453 | unsigned long flags, flags_dq; |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1454 | |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 1455 | if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags))) |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1456 | return -EINVAL; |
| 1457 | |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1458 | if (!device->port) |
| 1459 | return -1; |
| 1460 | |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 1461 | port = to_hisi_sas_port(sas_port); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1462 | |
| 1463 | /* simply get a slot and send abort command */ |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 1464 | spin_lock_irqsave(&hisi_hba->lock, flags); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1465 | rc = hisi_sas_slot_index_alloc(hisi_hba, &slot_idx); |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 1466 | if (rc) { |
| 1467 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1468 | goto err_out; |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 1469 | } |
| 1470 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 1471 | |
| 1472 | spin_lock_irqsave(&dq->lock, flags_dq); |
| 1473 | rc = hisi_hba->hw->get_free_slot(hisi_hba, dq); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1474 | if (rc) |
| 1475 | goto err_out_tag; |
| 1476 | |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 1477 | dlvry_queue = dq->id; |
| 1478 | dlvry_queue_slot = dq->wr_point; |
| 1479 | |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1480 | slot = &hisi_hba->slot_info[slot_idx]; |
| 1481 | memset(slot, 0, sizeof(struct hisi_sas_slot)); |
| 1482 | |
| 1483 | slot->idx = slot_idx; |
| 1484 | slot->n_elem = n_elem; |
| 1485 | slot->dlvry_queue = dlvry_queue; |
| 1486 | slot->dlvry_queue_slot = dlvry_queue_slot; |
| 1487 | cmd_hdr_base = hisi_hba->cmd_hdr[dlvry_queue]; |
| 1488 | slot->cmd_hdr = &cmd_hdr_base[dlvry_queue_slot]; |
| 1489 | slot->task = task; |
| 1490 | slot->port = port; |
| 1491 | task->lldd_task = slot; |
| 1492 | |
Xiang Chen | 031da09 | 2017-08-11 00:09:35 +0800 | [diff] [blame] | 1493 | slot->buf = dma_pool_alloc(hisi_hba->buffer_pool, |
| 1494 | GFP_ATOMIC, &slot->buf_dma); |
| 1495 | if (!slot->buf) { |
| 1496 | rc = -ENOMEM; |
| 1497 | goto err_out_tag; |
| 1498 | } |
| 1499 | |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1500 | memset(slot->cmd_hdr, 0, sizeof(struct hisi_sas_cmd_hdr)); |
Xiang Chen | 031da09 | 2017-08-11 00:09:35 +0800 | [diff] [blame] | 1501 | memset(hisi_sas_cmd_hdr_addr_mem(slot), 0, HISI_SAS_COMMAND_TABLE_SZ); |
| 1502 | memset(hisi_sas_status_buf_addr_mem(slot), 0, HISI_SAS_STATUS_BUF_SZ); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1503 | |
| 1504 | rc = hisi_sas_task_prep_abort(hisi_hba, slot, device_id, |
| 1505 | abort_flag, task_tag); |
| 1506 | if (rc) |
Xiang Chen | 031da09 | 2017-08-11 00:09:35 +0800 | [diff] [blame] | 1507 | goto err_out_buf; |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1508 | |
Xiang Chen | 9feaf90 | 2017-10-24 23:51:34 +0800 | [diff] [blame] | 1509 | spin_lock_irqsave(&hisi_hba->lock, flags); |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 1510 | list_add_tail(&slot->entry, &sas_dev->list); |
Xiang Chen | 9feaf90 | 2017-10-24 23:51:34 +0800 | [diff] [blame] | 1511 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
John Garry | 54c9dd2 | 2017-03-23 01:25:29 +0800 | [diff] [blame] | 1512 | spin_lock_irqsave(&task->task_state_lock, flags); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1513 | task->task_state_flags |= SAS_TASK_AT_INITIATOR; |
John Garry | 54c9dd2 | 2017-03-23 01:25:29 +0800 | [diff] [blame] | 1514 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1515 | |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 1516 | dq->slot_prep = slot; |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1517 | |
John Garry | f696cc3 | 2016-11-07 20:48:39 +0800 | [diff] [blame] | 1518 | atomic64_inc(&sas_dev->running_req); |
| 1519 | |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 1520 | /* send abort command to the chip */ |
| 1521 | hisi_hba->hw->start_delivery(dq); |
| 1522 | spin_unlock_irqrestore(&dq->lock, flags_dq); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1523 | |
| 1524 | return 0; |
| 1525 | |
Xiang Chen | 031da09 | 2017-08-11 00:09:35 +0800 | [diff] [blame] | 1526 | err_out_buf: |
| 1527 | dma_pool_free(hisi_hba->buffer_pool, slot->buf, |
| 1528 | slot->buf_dma); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1529 | err_out_tag: |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 1530 | spin_lock_irqsave(&hisi_hba->lock, flags); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1531 | hisi_sas_slot_index_free(hisi_hba, slot_idx); |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 1532 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 1533 | spin_unlock_irqrestore(&dq->lock, flags_dq); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1534 | err_out: |
| 1535 | dev_err(dev, "internal abort task prep: failed[%d]!\n", rc); |
| 1536 | |
| 1537 | return rc; |
| 1538 | } |
| 1539 | |
| 1540 | /** |
| 1541 | * hisi_sas_internal_task_abort -- execute an internal |
| 1542 | * abort command for single IO command or a device |
| 1543 | * @hisi_hba: host controller struct |
| 1544 | * @device: domain device |
| 1545 | * @abort_flag: mode of operation, device or single IO |
| 1546 | * @tag: tag of IO to be aborted (only relevant to single |
| 1547 | * IO mode) |
| 1548 | */ |
| 1549 | static int |
| 1550 | hisi_sas_internal_task_abort(struct hisi_hba *hisi_hba, |
| 1551 | struct domain_device *device, |
| 1552 | int abort_flag, int tag) |
| 1553 | { |
| 1554 | struct sas_task *task; |
| 1555 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 1556 | struct device *dev = hisi_hba->dev; |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1557 | int res; |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1558 | |
Xiaofei Tan | 813709f | 2017-12-09 01:16:46 +0800 | [diff] [blame] | 1559 | /* |
| 1560 | * The interface is not realized means this HW don't support internal |
| 1561 | * abort, or don't need to do internal abort. Then here, we return |
| 1562 | * TMF_RESP_FUNC_FAILED and let other steps go on, which depends that |
| 1563 | * the internal abort has been executed and returned CQ. |
| 1564 | */ |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1565 | if (!hisi_hba->hw->prep_abort) |
Xiaofei Tan | 813709f | 2017-12-09 01:16:46 +0800 | [diff] [blame] | 1566 | return TMF_RESP_FUNC_FAILED; |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1567 | |
| 1568 | task = sas_alloc_slow_task(GFP_KERNEL); |
| 1569 | if (!task) |
| 1570 | return -ENOMEM; |
| 1571 | |
| 1572 | task->dev = device; |
| 1573 | task->task_proto = device->tproto; |
| 1574 | task->task_done = hisi_sas_task_done; |
Kees Cook | 841b86f | 2017-10-23 09:40:42 +0200 | [diff] [blame] | 1575 | task->slow_task->timer.function = hisi_sas_tmf_timedout; |
John Garry | 0844a3f | 2017-04-10 21:21:59 +0800 | [diff] [blame] | 1576 | task->slow_task->timer.expires = jiffies + msecs_to_jiffies(110); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1577 | add_timer(&task->slow_task->timer); |
| 1578 | |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1579 | res = hisi_sas_internal_abort_task_exec(hisi_hba, sas_dev->device_id, |
| 1580 | task, abort_flag, tag); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1581 | if (res) { |
| 1582 | del_timer(&task->slow_task->timer); |
| 1583 | dev_err(dev, "internal task abort: executing internal task failed: %d\n", |
| 1584 | res); |
| 1585 | goto exit; |
| 1586 | } |
| 1587 | wait_for_completion(&task->slow_task->completion); |
| 1588 | res = TMF_RESP_FUNC_FAILED; |
| 1589 | |
Xiang Chen | f64a698 | 2017-06-14 23:33:11 +0800 | [diff] [blame] | 1590 | /* Internal abort timed out */ |
| 1591 | if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) { |
| 1592 | if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { |
| 1593 | struct hisi_sas_slot *slot = task->lldd_task; |
| 1594 | |
| 1595 | if (slot) |
| 1596 | slot->task = NULL; |
Xiang Chen | f1c8821 | 2017-12-09 01:16:41 +0800 | [diff] [blame] | 1597 | dev_err(dev, "internal task abort: timeout and not done.\n"); |
Xiaofei Tan | 813709f | 2017-12-09 01:16:46 +0800 | [diff] [blame] | 1598 | res = -EIO; |
Xiang Chen | f692a67 | 2017-10-24 23:51:32 +0800 | [diff] [blame] | 1599 | goto exit; |
Xiang Chen | f1c8821 | 2017-12-09 01:16:41 +0800 | [diff] [blame] | 1600 | } else |
| 1601 | dev_err(dev, "internal task abort: timeout.\n"); |
Xiang Chen | f64a698 | 2017-06-14 23:33:11 +0800 | [diff] [blame] | 1602 | } |
| 1603 | |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1604 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
| 1605 | task->task_status.stat == TMF_RESP_FUNC_COMPLETE) { |
| 1606 | res = TMF_RESP_FUNC_COMPLETE; |
| 1607 | goto exit; |
| 1608 | } |
| 1609 | |
John Garry | c35279f | 2017-03-23 01:25:25 +0800 | [diff] [blame] | 1610 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
| 1611 | task->task_status.stat == TMF_RESP_FUNC_SUCC) { |
| 1612 | res = TMF_RESP_FUNC_SUCC; |
| 1613 | goto exit; |
| 1614 | } |
| 1615 | |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1616 | exit: |
John Garry | 297d730 | 2017-01-20 20:45:22 +0800 | [diff] [blame] | 1617 | dev_dbg(dev, "internal task abort: task to dev %016llx task=%p " |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1618 | "resp: 0x%x sts 0x%x\n", |
| 1619 | SAS_ADDR(device->sas_addr), |
| 1620 | task, |
| 1621 | task->task_status.resp, /* 0 is complete, -1 is undelivered */ |
| 1622 | task->task_status.stat); |
| 1623 | sas_free_task(task); |
| 1624 | |
| 1625 | return res; |
| 1626 | } |
| 1627 | |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 1628 | static void hisi_sas_port_formed(struct asd_sas_phy *sas_phy) |
| 1629 | { |
| 1630 | hisi_sas_port_notify_formed(sas_phy); |
| 1631 | } |
| 1632 | |
Xiang Chen | 336bd78 | 2017-12-09 01:16:49 +0800 | [diff] [blame] | 1633 | static void hisi_sas_port_deformed(struct asd_sas_phy *sas_phy) |
| 1634 | { |
| 1635 | } |
| 1636 | |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 1637 | static void hisi_sas_phy_disconnected(struct hisi_sas_phy *phy) |
| 1638 | { |
| 1639 | phy->phy_attached = 0; |
| 1640 | phy->phy_type = 0; |
| 1641 | phy->port = NULL; |
| 1642 | } |
| 1643 | |
| 1644 | void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy) |
| 1645 | { |
| 1646 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; |
| 1647 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
| 1648 | struct sas_ha_struct *sas_ha = &hisi_hba->sha; |
| 1649 | |
| 1650 | if (rdy) { |
| 1651 | /* Phy down but ready */ |
| 1652 | hisi_sas_bytes_dmaed(hisi_hba, phy_no); |
| 1653 | hisi_sas_port_notify_formed(sas_phy); |
| 1654 | } else { |
| 1655 | struct hisi_sas_port *port = phy->port; |
| 1656 | |
| 1657 | /* Phy down and not ready */ |
| 1658 | sas_ha->notify_phy_event(sas_phy, PHYE_LOSS_OF_SIGNAL); |
| 1659 | sas_phy_disconnected(sas_phy); |
| 1660 | |
| 1661 | if (port) { |
| 1662 | if (phy->phy_type & PORT_TYPE_SAS) { |
| 1663 | int port_id = port->id; |
| 1664 | |
| 1665 | if (!hisi_hba->hw->get_wideport_bitmap(hisi_hba, |
| 1666 | port_id)) |
| 1667 | port->port_attached = 0; |
| 1668 | } else if (phy->phy_type & PORT_TYPE_SATA) |
| 1669 | port->port_attached = 0; |
| 1670 | } |
| 1671 | hisi_sas_phy_disconnected(phy); |
| 1672 | } |
| 1673 | } |
| 1674 | EXPORT_SYMBOL_GPL(hisi_sas_phy_down); |
| 1675 | |
Xiaofei Tan | 571295f | 2017-10-24 23:51:47 +0800 | [diff] [blame] | 1676 | void hisi_sas_kill_tasklets(struct hisi_hba *hisi_hba) |
| 1677 | { |
| 1678 | int i; |
| 1679 | |
| 1680 | for (i = 0; i < hisi_hba->queue_count; i++) { |
| 1681 | struct hisi_sas_cq *cq = &hisi_hba->cq[i]; |
| 1682 | |
| 1683 | tasklet_kill(&cq->tasklet); |
| 1684 | } |
| 1685 | } |
| 1686 | EXPORT_SYMBOL_GPL(hisi_sas_kill_tasklets); |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1687 | |
John Garry | e21fe3a | 2017-06-14 23:33:20 +0800 | [diff] [blame] | 1688 | struct scsi_transport_template *hisi_sas_stt; |
| 1689 | EXPORT_SYMBOL_GPL(hisi_sas_stt); |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 1690 | |
Wei Yongjun | 1e15fea | 2018-01-11 11:13:58 +0000 | [diff] [blame^] | 1691 | static struct device_attribute *host_attrs[] = { |
Jason Yan | 8eea9dd | 2017-12-08 17:42:06 +0800 | [diff] [blame] | 1692 | &dev_attr_phy_event_threshold, |
| 1693 | NULL, |
| 1694 | }; |
| 1695 | |
John Garry | e21fe3a | 2017-06-14 23:33:20 +0800 | [diff] [blame] | 1696 | static struct scsi_host_template _hisi_sas_sht = { |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1697 | .module = THIS_MODULE, |
| 1698 | .name = DRV_NAME, |
| 1699 | .queuecommand = sas_queuecommand, |
| 1700 | .target_alloc = sas_target_alloc, |
John Garry | 31eec8a | 2016-02-25 17:42:14 +0800 | [diff] [blame] | 1701 | .slave_configure = hisi_sas_slave_configure, |
John Garry | 701f75e | 2015-11-18 00:50:55 +0800 | [diff] [blame] | 1702 | .scan_finished = hisi_sas_scan_finished, |
| 1703 | .scan_start = hisi_sas_scan_start, |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1704 | .change_queue_depth = sas_change_queue_depth, |
| 1705 | .bios_param = sas_bios_param, |
| 1706 | .can_queue = 1, |
| 1707 | .this_id = -1, |
| 1708 | .sg_tablesize = SG_ALL, |
| 1709 | .max_sectors = SCSI_DEFAULT_MAX_SECTORS, |
| 1710 | .use_clustering = ENABLE_CLUSTERING, |
| 1711 | .eh_device_reset_handler = sas_eh_device_reset_handler, |
Hannes Reinecke | cc199e7 | 2017-08-25 13:57:02 +0200 | [diff] [blame] | 1712 | .eh_target_reset_handler = sas_eh_target_reset_handler, |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1713 | .target_destroy = sas_target_destroy, |
| 1714 | .ioctl = sas_ioctl, |
Jason Yan | 8eea9dd | 2017-12-08 17:42:06 +0800 | [diff] [blame] | 1715 | .shost_attrs = host_attrs, |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1716 | }; |
John Garry | e21fe3a | 2017-06-14 23:33:20 +0800 | [diff] [blame] | 1717 | struct scsi_host_template *hisi_sas_sht = &_hisi_sas_sht; |
| 1718 | EXPORT_SYMBOL_GPL(hisi_sas_sht); |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1719 | |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 1720 | static struct sas_domain_function_template hisi_sas_transport_ops = { |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 1721 | .lldd_dev_found = hisi_sas_dev_found, |
| 1722 | .lldd_dev_gone = hisi_sas_dev_gone, |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 1723 | .lldd_execute_task = hisi_sas_queue_command, |
John Garry | e4189d5 | 2015-11-18 00:50:57 +0800 | [diff] [blame] | 1724 | .lldd_control_phy = hisi_sas_control_phy, |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1725 | .lldd_abort_task = hisi_sas_abort_task, |
| 1726 | .lldd_abort_task_set = hisi_sas_abort_task_set, |
| 1727 | .lldd_clear_aca = hisi_sas_clear_aca, |
| 1728 | .lldd_I_T_nexus_reset = hisi_sas_I_T_nexus_reset, |
| 1729 | .lldd_lu_reset = hisi_sas_lu_reset, |
| 1730 | .lldd_query_task = hisi_sas_query_task, |
John Garry | 8b05ad6 | 2017-03-23 01:25:35 +0800 | [diff] [blame] | 1731 | .lldd_clear_nexus_ha = hisi_sas_clear_nexus_ha, |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 1732 | .lldd_port_formed = hisi_sas_port_formed, |
Xiang Chen | 336bd78 | 2017-12-09 01:16:49 +0800 | [diff] [blame] | 1733 | .lldd_port_deformed = hisi_sas_port_deformed, |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 1734 | }; |
| 1735 | |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1736 | void hisi_sas_init_mem(struct hisi_hba *hisi_hba) |
| 1737 | { |
| 1738 | int i, s, max_command_entries = hisi_hba->hw->max_command_entries; |
| 1739 | |
| 1740 | for (i = 0; i < hisi_hba->queue_count; i++) { |
| 1741 | struct hisi_sas_cq *cq = &hisi_hba->cq[i]; |
| 1742 | struct hisi_sas_dq *dq = &hisi_hba->dq[i]; |
| 1743 | |
| 1744 | s = sizeof(struct hisi_sas_cmd_hdr) * HISI_SAS_QUEUE_SLOTS; |
| 1745 | memset(hisi_hba->cmd_hdr[i], 0, s); |
| 1746 | dq->wr_point = 0; |
| 1747 | |
| 1748 | s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS; |
| 1749 | memset(hisi_hba->complete_hdr[i], 0, s); |
| 1750 | cq->rd_point = 0; |
| 1751 | } |
| 1752 | |
| 1753 | s = sizeof(struct hisi_sas_initial_fis) * hisi_hba->n_phy; |
| 1754 | memset(hisi_hba->initial_fis, 0, s); |
| 1755 | |
| 1756 | s = max_command_entries * sizeof(struct hisi_sas_iost); |
| 1757 | memset(hisi_hba->iost, 0, s); |
| 1758 | |
| 1759 | s = max_command_entries * sizeof(struct hisi_sas_breakpoint); |
| 1760 | memset(hisi_hba->breakpoint, 0, s); |
| 1761 | |
Xiang Chen | 3297ded | 2017-10-24 23:51:35 +0800 | [diff] [blame] | 1762 | s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_sata_breakpoint); |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1763 | memset(hisi_hba->sata_breakpoint, 0, s); |
| 1764 | } |
| 1765 | EXPORT_SYMBOL_GPL(hisi_sas_init_mem); |
| 1766 | |
John Garry | e21fe3a | 2017-06-14 23:33:20 +0800 | [diff] [blame] | 1767 | int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost) |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1768 | { |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 1769 | struct device *dev = hisi_hba->dev; |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1770 | int i, s, max_command_entries = hisi_hba->hw->max_command_entries; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1771 | |
John Garry | fa42d80 | 2015-11-18 00:50:43 +0800 | [diff] [blame] | 1772 | spin_lock_init(&hisi_hba->lock); |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 1773 | for (i = 0; i < hisi_hba->n_phy; i++) { |
| 1774 | hisi_sas_phy_init(hisi_hba, i); |
| 1775 | hisi_hba->port[i].port_attached = 0; |
| 1776 | hisi_hba->port[i].id = -1; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 1777 | } |
| 1778 | |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 1779 | for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) { |
| 1780 | hisi_hba->devices[i].dev_type = SAS_PHY_UNUSED; |
| 1781 | hisi_hba->devices[i].device_id = i; |
| 1782 | hisi_hba->devices[i].dev_status = HISI_SAS_DEV_NORMAL; |
| 1783 | } |
| 1784 | |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1785 | for (i = 0; i < hisi_hba->queue_count; i++) { |
John Garry | 9101a07 | 2015-11-18 00:50:37 +0800 | [diff] [blame] | 1786 | struct hisi_sas_cq *cq = &hisi_hba->cq[i]; |
John Garry | 4fde02a | 2016-09-06 23:36:12 +0800 | [diff] [blame] | 1787 | struct hisi_sas_dq *dq = &hisi_hba->dq[i]; |
John Garry | 9101a07 | 2015-11-18 00:50:37 +0800 | [diff] [blame] | 1788 | |
| 1789 | /* Completion queue structure */ |
| 1790 | cq->id = i; |
| 1791 | cq->hisi_hba = hisi_hba; |
| 1792 | |
John Garry | 4fde02a | 2016-09-06 23:36:12 +0800 | [diff] [blame] | 1793 | /* Delivery queue structure */ |
Xiang Chen | 39bade0 | 2017-12-09 01:16:32 +0800 | [diff] [blame] | 1794 | spin_lock_init(&dq->lock); |
John Garry | 4fde02a | 2016-09-06 23:36:12 +0800 | [diff] [blame] | 1795 | dq->id = i; |
| 1796 | dq->hisi_hba = hisi_hba; |
| 1797 | |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1798 | /* Delivery queue */ |
| 1799 | s = sizeof(struct hisi_sas_cmd_hdr) * HISI_SAS_QUEUE_SLOTS; |
| 1800 | hisi_hba->cmd_hdr[i] = dma_alloc_coherent(dev, s, |
| 1801 | &hisi_hba->cmd_hdr_dma[i], GFP_KERNEL); |
| 1802 | if (!hisi_hba->cmd_hdr[i]) |
| 1803 | goto err_out; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1804 | |
| 1805 | /* Completion queue */ |
| 1806 | s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS; |
| 1807 | hisi_hba->complete_hdr[i] = dma_alloc_coherent(dev, s, |
| 1808 | &hisi_hba->complete_hdr_dma[i], GFP_KERNEL); |
| 1809 | if (!hisi_hba->complete_hdr[i]) |
| 1810 | goto err_out; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1811 | } |
| 1812 | |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 1813 | s = sizeof(struct hisi_sas_slot_buf_table); |
| 1814 | hisi_hba->buffer_pool = dma_pool_create("dma_buffer", dev, s, 16, 0); |
| 1815 | if (!hisi_hba->buffer_pool) |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1816 | goto err_out; |
| 1817 | |
| 1818 | s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_itct); |
| 1819 | hisi_hba->itct = dma_alloc_coherent(dev, s, &hisi_hba->itct_dma, |
| 1820 | GFP_KERNEL); |
| 1821 | if (!hisi_hba->itct) |
| 1822 | goto err_out; |
| 1823 | |
| 1824 | memset(hisi_hba->itct, 0, s); |
| 1825 | |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1826 | hisi_hba->slot_info = devm_kcalloc(dev, max_command_entries, |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1827 | sizeof(struct hisi_sas_slot), |
| 1828 | GFP_KERNEL); |
| 1829 | if (!hisi_hba->slot_info) |
| 1830 | goto err_out; |
| 1831 | |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1832 | s = max_command_entries * sizeof(struct hisi_sas_iost); |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1833 | hisi_hba->iost = dma_alloc_coherent(dev, s, &hisi_hba->iost_dma, |
| 1834 | GFP_KERNEL); |
| 1835 | if (!hisi_hba->iost) |
| 1836 | goto err_out; |
| 1837 | |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1838 | s = max_command_entries * sizeof(struct hisi_sas_breakpoint); |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1839 | hisi_hba->breakpoint = dma_alloc_coherent(dev, s, |
| 1840 | &hisi_hba->breakpoint_dma, GFP_KERNEL); |
| 1841 | if (!hisi_hba->breakpoint) |
| 1842 | goto err_out; |
| 1843 | |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1844 | hisi_hba->slot_index_count = max_command_entries; |
John Garry | 433f569 | 2016-09-06 23:36:15 +0800 | [diff] [blame] | 1845 | s = hisi_hba->slot_index_count / BITS_PER_BYTE; |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 1846 | hisi_hba->slot_index_tags = devm_kzalloc(dev, s, GFP_KERNEL); |
| 1847 | if (!hisi_hba->slot_index_tags) |
| 1848 | goto err_out; |
| 1849 | |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1850 | s = sizeof(struct hisi_sas_initial_fis) * HISI_SAS_MAX_PHYS; |
| 1851 | hisi_hba->initial_fis = dma_alloc_coherent(dev, s, |
| 1852 | &hisi_hba->initial_fis_dma, GFP_KERNEL); |
| 1853 | if (!hisi_hba->initial_fis) |
| 1854 | goto err_out; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1855 | |
Xiang Chen | 3297ded | 2017-10-24 23:51:35 +0800 | [diff] [blame] | 1856 | s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_sata_breakpoint); |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1857 | hisi_hba->sata_breakpoint = dma_alloc_coherent(dev, s, |
| 1858 | &hisi_hba->sata_breakpoint_dma, GFP_KERNEL); |
| 1859 | if (!hisi_hba->sata_breakpoint) |
| 1860 | goto err_out; |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1861 | hisi_sas_init_mem(hisi_hba); |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1862 | |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 1863 | hisi_sas_slot_index_init(hisi_hba); |
| 1864 | |
John Garry | 7e9080e | 2015-11-18 00:50:40 +0800 | [diff] [blame] | 1865 | hisi_hba->wq = create_singlethread_workqueue(dev_name(dev)); |
| 1866 | if (!hisi_hba->wq) { |
| 1867 | dev_err(dev, "sas_alloc: failed to create workqueue\n"); |
| 1868 | goto err_out; |
| 1869 | } |
| 1870 | |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1871 | return 0; |
| 1872 | err_out: |
| 1873 | return -ENOMEM; |
| 1874 | } |
John Garry | e21fe3a | 2017-06-14 23:33:20 +0800 | [diff] [blame] | 1875 | EXPORT_SYMBOL_GPL(hisi_sas_alloc); |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1876 | |
John Garry | e21fe3a | 2017-06-14 23:33:20 +0800 | [diff] [blame] | 1877 | void hisi_sas_free(struct hisi_hba *hisi_hba) |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1878 | { |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 1879 | struct device *dev = hisi_hba->dev; |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1880 | int i, s, max_command_entries = hisi_hba->hw->max_command_entries; |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1881 | |
| 1882 | for (i = 0; i < hisi_hba->queue_count; i++) { |
| 1883 | s = sizeof(struct hisi_sas_cmd_hdr) * HISI_SAS_QUEUE_SLOTS; |
| 1884 | if (hisi_hba->cmd_hdr[i]) |
| 1885 | dma_free_coherent(dev, s, |
| 1886 | hisi_hba->cmd_hdr[i], |
| 1887 | hisi_hba->cmd_hdr_dma[i]); |
| 1888 | |
| 1889 | s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS; |
| 1890 | if (hisi_hba->complete_hdr[i]) |
| 1891 | dma_free_coherent(dev, s, |
| 1892 | hisi_hba->complete_hdr[i], |
| 1893 | hisi_hba->complete_hdr_dma[i]); |
| 1894 | } |
| 1895 | |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 1896 | dma_pool_destroy(hisi_hba->buffer_pool); |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1897 | |
| 1898 | s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_itct); |
| 1899 | if (hisi_hba->itct) |
| 1900 | dma_free_coherent(dev, s, |
| 1901 | hisi_hba->itct, hisi_hba->itct_dma); |
| 1902 | |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1903 | s = max_command_entries * sizeof(struct hisi_sas_iost); |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1904 | if (hisi_hba->iost) |
| 1905 | dma_free_coherent(dev, s, |
| 1906 | hisi_hba->iost, hisi_hba->iost_dma); |
| 1907 | |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1908 | s = max_command_entries * sizeof(struct hisi_sas_breakpoint); |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1909 | if (hisi_hba->breakpoint) |
| 1910 | dma_free_coherent(dev, s, |
| 1911 | hisi_hba->breakpoint, |
| 1912 | hisi_hba->breakpoint_dma); |
| 1913 | |
| 1914 | |
| 1915 | s = sizeof(struct hisi_sas_initial_fis) * HISI_SAS_MAX_PHYS; |
| 1916 | if (hisi_hba->initial_fis) |
| 1917 | dma_free_coherent(dev, s, |
| 1918 | hisi_hba->initial_fis, |
| 1919 | hisi_hba->initial_fis_dma); |
| 1920 | |
Xiang Chen | 3297ded | 2017-10-24 23:51:35 +0800 | [diff] [blame] | 1921 | s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_sata_breakpoint); |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1922 | if (hisi_hba->sata_breakpoint) |
| 1923 | dma_free_coherent(dev, s, |
| 1924 | hisi_hba->sata_breakpoint, |
| 1925 | hisi_hba->sata_breakpoint_dma); |
| 1926 | |
John Garry | 7e9080e | 2015-11-18 00:50:40 +0800 | [diff] [blame] | 1927 | if (hisi_hba->wq) |
| 1928 | destroy_workqueue(hisi_hba->wq); |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1929 | } |
John Garry | e21fe3a | 2017-06-14 23:33:20 +0800 | [diff] [blame] | 1930 | EXPORT_SYMBOL_GPL(hisi_sas_free); |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1931 | |
Xiaofei Tan | b4241f0 | 2017-10-24 23:51:45 +0800 | [diff] [blame] | 1932 | void hisi_sas_rst_work_handler(struct work_struct *work) |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1933 | { |
| 1934 | struct hisi_hba *hisi_hba = |
| 1935 | container_of(work, struct hisi_hba, rst_work); |
| 1936 | |
| 1937 | hisi_sas_controller_reset(hisi_hba); |
| 1938 | } |
Xiaofei Tan | b4241f0 | 2017-10-24 23:51:45 +0800 | [diff] [blame] | 1939 | EXPORT_SYMBOL_GPL(hisi_sas_rst_work_handler); |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1940 | |
Xiaofei Tan | e402acd | 2017-12-09 01:16:38 +0800 | [diff] [blame] | 1941 | void hisi_sas_sync_rst_work_handler(struct work_struct *work) |
| 1942 | { |
| 1943 | struct hisi_sas_rst *rst = |
| 1944 | container_of(work, struct hisi_sas_rst, work); |
| 1945 | |
| 1946 | if (!hisi_sas_controller_reset(rst->hisi_hba)) |
| 1947 | rst->done = true; |
| 1948 | complete(rst->completion); |
| 1949 | } |
| 1950 | EXPORT_SYMBOL_GPL(hisi_sas_sync_rst_work_handler); |
| 1951 | |
John Garry | 0fa24c1 | 2017-06-14 23:33:18 +0800 | [diff] [blame] | 1952 | int hisi_sas_get_fw_info(struct hisi_hba *hisi_hba) |
| 1953 | { |
| 1954 | struct device *dev = hisi_hba->dev; |
| 1955 | struct platform_device *pdev = hisi_hba->platform_dev; |
| 1956 | struct device_node *np = pdev ? pdev->dev.of_node : NULL; |
| 1957 | struct clk *refclk; |
| 1958 | |
| 1959 | if (device_property_read_u8_array(dev, "sas-addr", hisi_hba->sas_addr, |
| 1960 | SAS_ADDR_SIZE)) { |
| 1961 | dev_err(dev, "could not get property sas-addr\n"); |
| 1962 | return -ENOENT; |
| 1963 | } |
| 1964 | |
| 1965 | if (np) { |
| 1966 | /* |
| 1967 | * These properties are only required for platform device-based |
| 1968 | * controller with DT firmware. |
| 1969 | */ |
| 1970 | hisi_hba->ctrl = syscon_regmap_lookup_by_phandle(np, |
| 1971 | "hisilicon,sas-syscon"); |
| 1972 | if (IS_ERR(hisi_hba->ctrl)) { |
| 1973 | dev_err(dev, "could not get syscon\n"); |
| 1974 | return -ENOENT; |
| 1975 | } |
| 1976 | |
| 1977 | if (device_property_read_u32(dev, "ctrl-reset-reg", |
| 1978 | &hisi_hba->ctrl_reset_reg)) { |
| 1979 | dev_err(dev, |
| 1980 | "could not get property ctrl-reset-reg\n"); |
| 1981 | return -ENOENT; |
| 1982 | } |
| 1983 | |
| 1984 | if (device_property_read_u32(dev, "ctrl-reset-sts-reg", |
| 1985 | &hisi_hba->ctrl_reset_sts_reg)) { |
| 1986 | dev_err(dev, |
| 1987 | "could not get property ctrl-reset-sts-reg\n"); |
| 1988 | return -ENOENT; |
| 1989 | } |
| 1990 | |
| 1991 | if (device_property_read_u32(dev, "ctrl-clock-ena-reg", |
| 1992 | &hisi_hba->ctrl_clock_ena_reg)) { |
| 1993 | dev_err(dev, |
| 1994 | "could not get property ctrl-clock-ena-reg\n"); |
| 1995 | return -ENOENT; |
| 1996 | } |
| 1997 | } |
| 1998 | |
| 1999 | refclk = devm_clk_get(dev, NULL); |
| 2000 | if (IS_ERR(refclk)) |
| 2001 | dev_dbg(dev, "no ref clk property\n"); |
| 2002 | else |
| 2003 | hisi_hba->refclk_frequency_mhz = clk_get_rate(refclk) / 1000000; |
| 2004 | |
| 2005 | if (device_property_read_u32(dev, "phy-count", &hisi_hba->n_phy)) { |
| 2006 | dev_err(dev, "could not get property phy-count\n"); |
| 2007 | return -ENOENT; |
| 2008 | } |
| 2009 | |
| 2010 | if (device_property_read_u32(dev, "queue-count", |
| 2011 | &hisi_hba->queue_count)) { |
| 2012 | dev_err(dev, "could not get property queue-count\n"); |
| 2013 | return -ENOENT; |
| 2014 | } |
| 2015 | |
| 2016 | return 0; |
| 2017 | } |
| 2018 | EXPORT_SYMBOL_GPL(hisi_sas_get_fw_info); |
| 2019 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2020 | static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device *pdev, |
| 2021 | const struct hisi_sas_hw *hw) |
| 2022 | { |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 2023 | struct resource *res; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2024 | struct Scsi_Host *shost; |
| 2025 | struct hisi_hba *hisi_hba; |
| 2026 | struct device *dev = &pdev->dev; |
| 2027 | |
John Garry | e21fe3a | 2017-06-14 23:33:20 +0800 | [diff] [blame] | 2028 | shost = scsi_host_alloc(hisi_sas_sht, sizeof(*hisi_hba)); |
Xiaofei Tan | d37a008 | 2016-11-29 23:45:57 +0800 | [diff] [blame] | 2029 | if (!shost) { |
| 2030 | dev_err(dev, "scsi host alloc failed\n"); |
| 2031 | return NULL; |
| 2032 | } |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2033 | hisi_hba = shost_priv(shost); |
| 2034 | |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 2035 | INIT_WORK(&hisi_hba->rst_work, hisi_sas_rst_work_handler); |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2036 | hisi_hba->hw = hw; |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 2037 | hisi_hba->dev = dev; |
John Garry | 0fa24c1 | 2017-06-14 23:33:18 +0800 | [diff] [blame] | 2038 | hisi_hba->platform_dev = pdev; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2039 | hisi_hba->shost = shost; |
| 2040 | SHOST_TO_SAS_HA(shost) = &hisi_hba->sha; |
| 2041 | |
Kees Cook | 77570ee | 2017-08-22 16:05:14 -0700 | [diff] [blame] | 2042 | timer_setup(&hisi_hba->timer, NULL, 0); |
John Garry | fa42d80 | 2015-11-18 00:50:43 +0800 | [diff] [blame] | 2043 | |
John Garry | 0fa24c1 | 2017-06-14 23:33:18 +0800 | [diff] [blame] | 2044 | if (hisi_sas_get_fw_info(hisi_hba) < 0) |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 2045 | goto err_out; |
| 2046 | |
John Garry | a6f2c7f | 2016-09-06 23:36:19 +0800 | [diff] [blame] | 2047 | if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) && |
| 2048 | dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32))) { |
| 2049 | dev_err(dev, "No usable DMA addressing method\n"); |
| 2050 | goto err_out; |
| 2051 | } |
| 2052 | |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 2053 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2054 | hisi_hba->regs = devm_ioremap_resource(dev, res); |
| 2055 | if (IS_ERR(hisi_hba->regs)) |
| 2056 | goto err_out; |
| 2057 | |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 2058 | if (hisi_sas_alloc(hisi_hba, shost)) { |
| 2059 | hisi_sas_free(hisi_hba); |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 2060 | goto err_out; |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 2061 | } |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 2062 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2063 | return shost; |
| 2064 | err_out: |
John Garry | 76aae5f | 2017-08-11 00:09:43 +0800 | [diff] [blame] | 2065 | scsi_host_put(shost); |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2066 | dev_err(dev, "shost alloc failed\n"); |
| 2067 | return NULL; |
| 2068 | } |
| 2069 | |
John Garry | e21fe3a | 2017-06-14 23:33:20 +0800 | [diff] [blame] | 2070 | void hisi_sas_init_add(struct hisi_hba *hisi_hba) |
John Garry | 5d74242 | 2015-11-18 00:50:38 +0800 | [diff] [blame] | 2071 | { |
| 2072 | int i; |
| 2073 | |
| 2074 | for (i = 0; i < hisi_hba->n_phy; i++) |
| 2075 | memcpy(&hisi_hba->phy[i].dev_sas_addr, |
| 2076 | hisi_hba->sas_addr, |
| 2077 | SAS_ADDR_SIZE); |
| 2078 | } |
John Garry | e21fe3a | 2017-06-14 23:33:20 +0800 | [diff] [blame] | 2079 | EXPORT_SYMBOL_GPL(hisi_sas_init_add); |
John Garry | 5d74242 | 2015-11-18 00:50:38 +0800 | [diff] [blame] | 2080 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2081 | int hisi_sas_probe(struct platform_device *pdev, |
| 2082 | const struct hisi_sas_hw *hw) |
| 2083 | { |
| 2084 | struct Scsi_Host *shost; |
| 2085 | struct hisi_hba *hisi_hba; |
| 2086 | struct device *dev = &pdev->dev; |
| 2087 | struct asd_sas_phy **arr_phy; |
| 2088 | struct asd_sas_port **arr_port; |
| 2089 | struct sas_ha_struct *sha; |
| 2090 | int rc, phy_nr, port_nr, i; |
| 2091 | |
| 2092 | shost = hisi_sas_shost_alloc(pdev, hw); |
Xiaofei Tan | d37a008 | 2016-11-29 23:45:57 +0800 | [diff] [blame] | 2093 | if (!shost) |
| 2094 | return -ENOMEM; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2095 | |
| 2096 | sha = SHOST_TO_SAS_HA(shost); |
| 2097 | hisi_hba = shost_priv(shost); |
| 2098 | platform_set_drvdata(pdev, sha); |
John Garry | 50cb916 | 2015-11-18 00:50:39 +0800 | [diff] [blame] | 2099 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2100 | phy_nr = port_nr = hisi_hba->n_phy; |
| 2101 | |
| 2102 | arr_phy = devm_kcalloc(dev, phy_nr, sizeof(void *), GFP_KERNEL); |
| 2103 | arr_port = devm_kcalloc(dev, port_nr, sizeof(void *), GFP_KERNEL); |
Xiaofei Tan | d37a008 | 2016-11-29 23:45:57 +0800 | [diff] [blame] | 2104 | if (!arr_phy || !arr_port) { |
| 2105 | rc = -ENOMEM; |
| 2106 | goto err_out_ha; |
| 2107 | } |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2108 | |
| 2109 | sha->sas_phy = arr_phy; |
| 2110 | sha->sas_port = arr_port; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2111 | sha->lldd_ha = hisi_hba; |
| 2112 | |
| 2113 | shost->transportt = hisi_sas_stt; |
| 2114 | shost->max_id = HISI_SAS_MAX_DEVICES; |
| 2115 | shost->max_lun = ~0; |
| 2116 | shost->max_channel = 1; |
| 2117 | shost->max_cmd_len = 16; |
| 2118 | shost->sg_tablesize = min_t(u16, SG_ALL, HISI_SAS_SGE_PAGE_CNT); |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 2119 | shost->can_queue = hisi_hba->hw->max_command_entries; |
| 2120 | shost->cmd_per_lun = hisi_hba->hw->max_command_entries; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2121 | |
| 2122 | sha->sas_ha_name = DRV_NAME; |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 2123 | sha->dev = hisi_hba->dev; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2124 | sha->lldd_module = THIS_MODULE; |
| 2125 | sha->sas_addr = &hisi_hba->sas_addr[0]; |
| 2126 | sha->num_phys = hisi_hba->n_phy; |
| 2127 | sha->core.shost = hisi_hba->shost; |
| 2128 | |
| 2129 | for (i = 0; i < hisi_hba->n_phy; i++) { |
| 2130 | sha->sas_phy[i] = &hisi_hba->phy[i].sas_phy; |
| 2131 | sha->sas_port[i] = &hisi_hba->port[i].sas_port; |
| 2132 | } |
| 2133 | |
John Garry | 5d74242 | 2015-11-18 00:50:38 +0800 | [diff] [blame] | 2134 | hisi_sas_init_add(hisi_hba); |
| 2135 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2136 | rc = scsi_add_host(shost, &pdev->dev); |
| 2137 | if (rc) |
| 2138 | goto err_out_ha; |
| 2139 | |
| 2140 | rc = sas_register_ha(sha); |
| 2141 | if (rc) |
| 2142 | goto err_out_register_ha; |
| 2143 | |
Xiang Chen | 0757f04 | 2017-01-20 20:45:23 +0800 | [diff] [blame] | 2144 | rc = hisi_hba->hw->hw_init(hisi_hba); |
| 2145 | if (rc) |
| 2146 | goto err_out_register_ha; |
| 2147 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2148 | scsi_scan_host(shost); |
| 2149 | |
| 2150 | return 0; |
| 2151 | |
| 2152 | err_out_register_ha: |
| 2153 | scsi_remove_host(shost); |
| 2154 | err_out_ha: |
Xiaofei Tan | d37a008 | 2016-11-29 23:45:57 +0800 | [diff] [blame] | 2155 | hisi_sas_free(hisi_hba); |
John Garry | 76aae5f | 2017-08-11 00:09:43 +0800 | [diff] [blame] | 2156 | scsi_host_put(shost); |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 2157 | return rc; |
| 2158 | } |
| 2159 | EXPORT_SYMBOL_GPL(hisi_sas_probe); |
| 2160 | |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 2161 | int hisi_sas_remove(struct platform_device *pdev) |
| 2162 | { |
| 2163 | struct sas_ha_struct *sha = platform_get_drvdata(pdev); |
| 2164 | struct hisi_hba *hisi_hba = sha->lldd_ha; |
Xiaofei Tan | d37a008 | 2016-11-29 23:45:57 +0800 | [diff] [blame] | 2165 | struct Scsi_Host *shost = sha->core.shost; |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 2166 | |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 2167 | sas_unregister_ha(sha); |
| 2168 | sas_remove_host(sha->core.shost); |
| 2169 | |
| 2170 | hisi_sas_free(hisi_hba); |
John Garry | 76aae5f | 2017-08-11 00:09:43 +0800 | [diff] [blame] | 2171 | scsi_host_put(shost); |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 2172 | return 0; |
| 2173 | } |
| 2174 | EXPORT_SYMBOL_GPL(hisi_sas_remove); |
| 2175 | |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 2176 | static __init int hisi_sas_init(void) |
| 2177 | { |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 2178 | hisi_sas_stt = sas_domain_attach_transport(&hisi_sas_transport_ops); |
| 2179 | if (!hisi_sas_stt) |
| 2180 | return -ENOMEM; |
| 2181 | |
| 2182 | return 0; |
| 2183 | } |
| 2184 | |
| 2185 | static __exit void hisi_sas_exit(void) |
| 2186 | { |
| 2187 | sas_release_transport(hisi_sas_stt); |
| 2188 | } |
| 2189 | |
| 2190 | module_init(hisi_sas_init); |
| 2191 | module_exit(hisi_sas_exit); |
| 2192 | |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 2193 | MODULE_LICENSE("GPL"); |
| 2194 | MODULE_AUTHOR("John Garry <john.garry@huawei.com>"); |
| 2195 | MODULE_DESCRIPTION("HISILICON SAS controller driver"); |
| 2196 | MODULE_ALIAS("platform:" DRV_NAME); |