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); |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 25 | |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 26 | static struct hisi_hba *dev_to_hisi_hba(struct domain_device *device) |
| 27 | { |
| 28 | return device->port->ha->lldd_ha; |
| 29 | } |
| 30 | |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 31 | struct hisi_sas_port *to_hisi_sas_port(struct asd_sas_port *sas_port) |
| 32 | { |
| 33 | return container_of(sas_port, struct hisi_sas_port, sas_port); |
| 34 | } |
| 35 | EXPORT_SYMBOL_GPL(to_hisi_sas_port); |
| 36 | |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 37 | static void hisi_sas_slot_index_clear(struct hisi_hba *hisi_hba, int slot_idx) |
| 38 | { |
| 39 | void *bitmap = hisi_hba->slot_index_tags; |
| 40 | |
| 41 | clear_bit(slot_idx, bitmap); |
| 42 | } |
| 43 | |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 44 | static void hisi_sas_slot_index_free(struct hisi_hba *hisi_hba, int slot_idx) |
| 45 | { |
| 46 | hisi_sas_slot_index_clear(hisi_hba, slot_idx); |
| 47 | } |
| 48 | |
| 49 | static void hisi_sas_slot_index_set(struct hisi_hba *hisi_hba, int slot_idx) |
| 50 | { |
| 51 | void *bitmap = hisi_hba->slot_index_tags; |
| 52 | |
| 53 | set_bit(slot_idx, bitmap); |
| 54 | } |
| 55 | |
| 56 | static int hisi_sas_slot_index_alloc(struct hisi_hba *hisi_hba, int *slot_idx) |
| 57 | { |
| 58 | unsigned int index; |
| 59 | void *bitmap = hisi_hba->slot_index_tags; |
| 60 | |
| 61 | index = find_first_zero_bit(bitmap, hisi_hba->slot_index_count); |
| 62 | if (index >= hisi_hba->slot_index_count) |
| 63 | return -SAS_QUEUE_FULL; |
| 64 | hisi_sas_slot_index_set(hisi_hba, index); |
| 65 | *slot_idx = index; |
| 66 | return 0; |
| 67 | } |
| 68 | |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 69 | static void hisi_sas_slot_index_init(struct hisi_hba *hisi_hba) |
| 70 | { |
| 71 | int i; |
| 72 | |
| 73 | for (i = 0; i < hisi_hba->slot_index_count; ++i) |
| 74 | hisi_sas_slot_index_clear(hisi_hba, i); |
| 75 | } |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 76 | |
| 77 | void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, struct sas_task *task, |
| 78 | struct hisi_sas_slot *slot) |
| 79 | { |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 80 | |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 81 | if (task) { |
| 82 | struct device *dev = &hisi_hba->pdev->dev; |
| 83 | struct domain_device *device = task->dev; |
| 84 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 85 | |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 86 | if (!sas_protocol_ata(task->task_proto)) |
| 87 | if (slot->n_elem) |
| 88 | dma_unmap_sg(dev, task->scatter, slot->n_elem, |
| 89 | task->data_dir); |
| 90 | |
| 91 | task->lldd_task = NULL; |
| 92 | |
| 93 | if (sas_dev) |
| 94 | atomic64_dec(&sas_dev->running_req); |
| 95 | } |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 96 | |
| 97 | if (slot->command_table) |
| 98 | dma_pool_free(hisi_hba->command_table_pool, |
| 99 | slot->command_table, slot->command_table_dma); |
| 100 | |
| 101 | if (slot->status_buffer) |
| 102 | dma_pool_free(hisi_hba->status_buffer_pool, |
| 103 | slot->status_buffer, slot->status_buffer_dma); |
| 104 | |
| 105 | if (slot->sge_page) |
| 106 | dma_pool_free(hisi_hba->sge_page_pool, slot->sge_page, |
| 107 | slot->sge_page_dma); |
| 108 | |
| 109 | list_del_init(&slot->entry); |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 110 | slot->task = NULL; |
| 111 | slot->port = NULL; |
| 112 | hisi_sas_slot_index_free(hisi_hba, slot->idx); |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 113 | |
John Garry | 59ba49f | 2016-09-06 23:36:14 +0800 | [diff] [blame] | 114 | /* slot memory is fully zeroed when it is reused */ |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 115 | } |
| 116 | EXPORT_SYMBOL_GPL(hisi_sas_slot_task_free); |
| 117 | |
John Garry | 66ee999 | 2015-11-18 00:50:54 +0800 | [diff] [blame] | 118 | static int hisi_sas_task_prep_smp(struct hisi_hba *hisi_hba, |
| 119 | struct hisi_sas_slot *slot) |
| 120 | { |
| 121 | return hisi_hba->hw->prep_smp(hisi_hba, slot); |
| 122 | } |
| 123 | |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 124 | static int hisi_sas_task_prep_ssp(struct hisi_hba *hisi_hba, |
| 125 | struct hisi_sas_slot *slot, int is_tmf, |
| 126 | struct hisi_sas_tmf_task *tmf) |
| 127 | { |
| 128 | return hisi_hba->hw->prep_ssp(hisi_hba, slot, is_tmf, tmf); |
| 129 | } |
| 130 | |
John Garry | 6f2ff1a | 2016-01-26 02:47:20 +0800 | [diff] [blame] | 131 | static int hisi_sas_task_prep_ata(struct hisi_hba *hisi_hba, |
| 132 | struct hisi_sas_slot *slot) |
| 133 | { |
| 134 | return hisi_hba->hw->prep_stp(hisi_hba, slot); |
| 135 | } |
| 136 | |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 137 | static int hisi_sas_task_prep_abort(struct hisi_hba *hisi_hba, |
| 138 | struct hisi_sas_slot *slot, |
| 139 | int device_id, int abort_flag, int tag_to_abort) |
| 140 | { |
| 141 | return hisi_hba->hw->prep_abort(hisi_hba, slot, |
| 142 | device_id, abort_flag, tag_to_abort); |
| 143 | } |
| 144 | |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 145 | /* |
| 146 | * This function will issue an abort TMF regardless of whether the |
| 147 | * task is in the sdev or not. Then it will do the task complete |
| 148 | * cleanup and callbacks. |
| 149 | */ |
| 150 | static void hisi_sas_slot_abort(struct work_struct *work) |
| 151 | { |
| 152 | struct hisi_sas_slot *abort_slot = |
| 153 | container_of(work, struct hisi_sas_slot, abort_slot); |
| 154 | struct sas_task *task = abort_slot->task; |
| 155 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(task->dev); |
| 156 | struct scsi_cmnd *cmnd = task->uldd_task; |
| 157 | struct hisi_sas_tmf_task tmf_task; |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 158 | struct scsi_lun lun; |
| 159 | struct device *dev = &hisi_hba->pdev->dev; |
| 160 | int tag = abort_slot->idx; |
John Garry | da7b66e | 2017-01-03 20:24:50 +0800 | [diff] [blame] | 161 | unsigned long flags; |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 162 | |
| 163 | if (!(task->task_proto & SAS_PROTOCOL_SSP)) { |
| 164 | dev_err(dev, "cannot abort slot for non-ssp task\n"); |
| 165 | goto out; |
| 166 | } |
| 167 | |
| 168 | int_to_scsilun(cmnd->device->lun, &lun); |
| 169 | tmf_task.tmf = TMF_ABORT_TASK; |
| 170 | tmf_task.tag_of_task_to_be_managed = cpu_to_le16(tag); |
| 171 | |
| 172 | hisi_sas_debug_issue_ssp_tmf(task->dev, lun.scsi_lun, &tmf_task); |
| 173 | out: |
| 174 | /* Do cleanup for this task */ |
John Garry | da7b66e | 2017-01-03 20:24:50 +0800 | [diff] [blame] | 175 | spin_lock_irqsave(&hisi_hba->lock, flags); |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 176 | hisi_sas_slot_task_free(hisi_hba, task, abort_slot); |
John Garry | da7b66e | 2017-01-03 20:24:50 +0800 | [diff] [blame] | 177 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 178 | if (task->task_done) |
| 179 | task->task_done(task); |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 180 | } |
| 181 | |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 182 | static int hisi_sas_task_prep(struct sas_task *task, struct hisi_hba *hisi_hba, |
| 183 | int is_tmf, struct hisi_sas_tmf_task *tmf, |
| 184 | int *pass) |
| 185 | { |
| 186 | struct domain_device *device = task->dev; |
| 187 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 188 | struct hisi_sas_port *port; |
| 189 | struct hisi_sas_slot *slot; |
| 190 | struct hisi_sas_cmd_hdr *cmd_hdr_base; |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 191 | struct asd_sas_port *sas_port = device->port; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 192 | struct device *dev = &hisi_hba->pdev->dev; |
| 193 | int dlvry_queue_slot, dlvry_queue, n_elem = 0, rc, slot_idx; |
John Garry | 54c9dd2 | 2017-03-23 01:25:29 +0800 | [diff] [blame] | 194 | unsigned long flags; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 195 | |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 196 | if (!sas_port) { |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 197 | struct task_status_struct *ts = &task->task_status; |
| 198 | |
| 199 | ts->resp = SAS_TASK_UNDELIVERED; |
| 200 | ts->stat = SAS_PHY_DOWN; |
| 201 | /* |
| 202 | * libsas will use dev->port, should |
| 203 | * not call task_done for sata |
| 204 | */ |
| 205 | if (device->dev_type != SAS_SATA_DEV) |
| 206 | task->task_done(task); |
John Garry | ddabca2 | 2017-03-23 01:25:22 +0800 | [diff] [blame] | 207 | return SAS_PHY_DOWN; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | if (DEV_IS_GONE(sas_dev)) { |
| 211 | if (sas_dev) |
| 212 | dev_info(dev, "task prep: device %llu not ready\n", |
| 213 | sas_dev->device_id); |
| 214 | else |
| 215 | dev_info(dev, "task prep: device %016llx not ready\n", |
| 216 | SAS_ADDR(device->sas_addr)); |
| 217 | |
John Garry | ddabca2 | 2017-03-23 01:25:22 +0800 | [diff] [blame] | 218 | return SAS_PHY_DOWN; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 219 | } |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 220 | |
| 221 | port = to_hisi_sas_port(sas_port); |
John Garry | 9859f24 | 2016-08-24 19:05:52 +0800 | [diff] [blame] | 222 | if (port && !port->port_attached) { |
John Garry | 09fe9ec | 2016-09-06 23:36:18 +0800 | [diff] [blame] | 223 | dev_info(dev, "task prep: %s port%d not attach device\n", |
Xiang Chen | 6073b77 | 2017-03-23 01:25:38 +0800 | [diff] [blame] | 224 | (dev_is_sata(device)) ? |
John Garry | 09fe9ec | 2016-09-06 23:36:18 +0800 | [diff] [blame] | 225 | "SATA/STP" : "SAS", |
| 226 | device->port->id); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 227 | |
John Garry | 09fe9ec | 2016-09-06 23:36:18 +0800 | [diff] [blame] | 228 | return SAS_PHY_DOWN; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | if (!sas_protocol_ata(task->task_proto)) { |
| 232 | if (task->num_scatter) { |
| 233 | n_elem = dma_map_sg(dev, task->scatter, |
| 234 | task->num_scatter, task->data_dir); |
| 235 | if (!n_elem) { |
| 236 | rc = -ENOMEM; |
| 237 | goto prep_out; |
| 238 | } |
| 239 | } |
| 240 | } else |
| 241 | n_elem = task->num_scatter; |
| 242 | |
John Garry | 685b6d6 | 2016-04-15 21:36:36 +0800 | [diff] [blame] | 243 | if (hisi_hba->hw->slot_index_alloc) |
| 244 | rc = hisi_hba->hw->slot_index_alloc(hisi_hba, &slot_idx, |
| 245 | device); |
| 246 | else |
| 247 | rc = hisi_sas_slot_index_alloc(hisi_hba, &slot_idx); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 248 | if (rc) |
| 249 | goto err_out; |
Xiang Chen | c70f1fb | 2016-11-07 20:48:31 +0800 | [diff] [blame] | 250 | rc = hisi_hba->hw->get_free_slot(hisi_hba, sas_dev->device_id, |
| 251 | &dlvry_queue, &dlvry_queue_slot); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 252 | if (rc) |
| 253 | goto err_out_tag; |
| 254 | |
| 255 | slot = &hisi_hba->slot_info[slot_idx]; |
| 256 | memset(slot, 0, sizeof(struct hisi_sas_slot)); |
| 257 | |
| 258 | slot->idx = slot_idx; |
| 259 | slot->n_elem = n_elem; |
| 260 | slot->dlvry_queue = dlvry_queue; |
| 261 | slot->dlvry_queue_slot = dlvry_queue_slot; |
| 262 | cmd_hdr_base = hisi_hba->cmd_hdr[dlvry_queue]; |
| 263 | slot->cmd_hdr = &cmd_hdr_base[dlvry_queue_slot]; |
| 264 | slot->task = task; |
| 265 | slot->port = port; |
| 266 | task->lldd_task = slot; |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 267 | INIT_WORK(&slot->abort_slot, hisi_sas_slot_abort); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 268 | |
| 269 | slot->status_buffer = dma_pool_alloc(hisi_hba->status_buffer_pool, |
| 270 | GFP_ATOMIC, |
| 271 | &slot->status_buffer_dma); |
Dan Carpenter | 9c9d18e | 2015-12-09 13:48:36 +0300 | [diff] [blame] | 272 | if (!slot->status_buffer) { |
| 273 | rc = -ENOMEM; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 274 | goto err_out_slot_buf; |
Dan Carpenter | 9c9d18e | 2015-12-09 13:48:36 +0300 | [diff] [blame] | 275 | } |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 276 | memset(slot->status_buffer, 0, HISI_SAS_STATUS_BUF_SZ); |
| 277 | |
| 278 | slot->command_table = dma_pool_alloc(hisi_hba->command_table_pool, |
| 279 | GFP_ATOMIC, |
| 280 | &slot->command_table_dma); |
Dan Carpenter | 9c9d18e | 2015-12-09 13:48:36 +0300 | [diff] [blame] | 281 | if (!slot->command_table) { |
| 282 | rc = -ENOMEM; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 283 | goto err_out_status_buf; |
Dan Carpenter | 9c9d18e | 2015-12-09 13:48:36 +0300 | [diff] [blame] | 284 | } |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 285 | memset(slot->command_table, 0, HISI_SAS_COMMAND_TABLE_SZ); |
| 286 | memset(slot->cmd_hdr, 0, sizeof(struct hisi_sas_cmd_hdr)); |
| 287 | |
| 288 | switch (task->task_proto) { |
John Garry | 66ee999 | 2015-11-18 00:50:54 +0800 | [diff] [blame] | 289 | case SAS_PROTOCOL_SMP: |
| 290 | rc = hisi_sas_task_prep_smp(hisi_hba, slot); |
| 291 | break; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 292 | case SAS_PROTOCOL_SSP: |
| 293 | rc = hisi_sas_task_prep_ssp(hisi_hba, slot, is_tmf, tmf); |
| 294 | break; |
| 295 | case SAS_PROTOCOL_SATA: |
| 296 | case SAS_PROTOCOL_STP: |
| 297 | case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: |
John Garry | 6f2ff1a | 2016-01-26 02:47:20 +0800 | [diff] [blame] | 298 | rc = hisi_sas_task_prep_ata(hisi_hba, slot); |
| 299 | break; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 300 | default: |
| 301 | dev_err(dev, "task prep: unknown/unsupported proto (0x%x)\n", |
| 302 | task->task_proto); |
| 303 | rc = -EINVAL; |
| 304 | break; |
| 305 | } |
| 306 | |
| 307 | if (rc) { |
| 308 | dev_err(dev, "task prep: rc = 0x%x\n", rc); |
| 309 | if (slot->sge_page) |
| 310 | goto err_out_sge; |
| 311 | goto err_out_command_table; |
| 312 | } |
| 313 | |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 314 | list_add_tail(&slot->entry, &sas_dev->list); |
John Garry | 54c9dd2 | 2017-03-23 01:25:29 +0800 | [diff] [blame] | 315 | spin_lock_irqsave(&task->task_state_lock, flags); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 316 | task->task_state_flags |= SAS_TASK_AT_INITIATOR; |
John Garry | 54c9dd2 | 2017-03-23 01:25:29 +0800 | [diff] [blame] | 317 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 318 | |
| 319 | hisi_hba->slot_prep = slot; |
| 320 | |
John Garry | f696cc3 | 2016-11-07 20:48:39 +0800 | [diff] [blame] | 321 | atomic64_inc(&sas_dev->running_req); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 322 | ++(*pass); |
| 323 | |
Dan Carpenter | 9c9d18e | 2015-12-09 13:48:36 +0300 | [diff] [blame] | 324 | return 0; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 325 | |
| 326 | err_out_sge: |
| 327 | dma_pool_free(hisi_hba->sge_page_pool, slot->sge_page, |
| 328 | slot->sge_page_dma); |
| 329 | err_out_command_table: |
| 330 | dma_pool_free(hisi_hba->command_table_pool, slot->command_table, |
| 331 | slot->command_table_dma); |
| 332 | err_out_status_buf: |
| 333 | dma_pool_free(hisi_hba->status_buffer_pool, slot->status_buffer, |
| 334 | slot->status_buffer_dma); |
| 335 | err_out_slot_buf: |
| 336 | /* Nothing to be done */ |
| 337 | err_out_tag: |
| 338 | hisi_sas_slot_index_free(hisi_hba, slot_idx); |
| 339 | err_out: |
| 340 | dev_err(dev, "task prep: failed[%d]!\n", rc); |
| 341 | if (!sas_protocol_ata(task->task_proto)) |
| 342 | if (n_elem) |
| 343 | dma_unmap_sg(dev, task->scatter, n_elem, |
| 344 | task->data_dir); |
| 345 | prep_out: |
| 346 | return rc; |
| 347 | } |
| 348 | |
| 349 | static int hisi_sas_task_exec(struct sas_task *task, gfp_t gfp_flags, |
| 350 | int is_tmf, struct hisi_sas_tmf_task *tmf) |
| 351 | { |
| 352 | u32 rc; |
| 353 | u32 pass = 0; |
| 354 | unsigned long flags; |
| 355 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(task->dev); |
| 356 | struct device *dev = &hisi_hba->pdev->dev; |
| 357 | |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 358 | if (unlikely(test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags))) |
| 359 | return -EINVAL; |
| 360 | |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 361 | /* protect task_prep and start_delivery sequence */ |
| 362 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 363 | rc = hisi_sas_task_prep(task, hisi_hba, is_tmf, tmf, &pass); |
| 364 | if (rc) |
| 365 | dev_err(dev, "task exec: failed[%d]!\n", rc); |
| 366 | |
| 367 | if (likely(pass)) |
| 368 | hisi_hba->hw->start_delivery(hisi_hba); |
| 369 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 370 | |
| 371 | return rc; |
| 372 | } |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 373 | |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 374 | static void hisi_sas_bytes_dmaed(struct hisi_hba *hisi_hba, int phy_no) |
| 375 | { |
| 376 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; |
| 377 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
| 378 | struct sas_ha_struct *sas_ha; |
| 379 | |
| 380 | if (!phy->phy_attached) |
| 381 | return; |
| 382 | |
| 383 | sas_ha = &hisi_hba->sha; |
| 384 | sas_ha->notify_phy_event(sas_phy, PHYE_OOB_DONE); |
| 385 | |
| 386 | if (sas_phy->phy) { |
| 387 | struct sas_phy *sphy = sas_phy->phy; |
| 388 | |
| 389 | sphy->negotiated_linkrate = sas_phy->linkrate; |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 390 | sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; |
Xiang Chen | 2ae7578 | 2016-11-07 20:48:40 +0800 | [diff] [blame] | 391 | sphy->maximum_linkrate_hw = |
| 392 | hisi_hba->hw->phy_get_max_linkrate(); |
| 393 | if (sphy->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) |
| 394 | sphy->minimum_linkrate = phy->minimum_linkrate; |
| 395 | |
| 396 | if (sphy->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) |
| 397 | sphy->maximum_linkrate = phy->maximum_linkrate; |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | if (phy->phy_type & PORT_TYPE_SAS) { |
| 401 | struct sas_identify_frame *id; |
| 402 | |
| 403 | id = (struct sas_identify_frame *)phy->frame_rcvd; |
| 404 | id->dev_type = phy->identify.device_type; |
| 405 | id->initiator_bits = SAS_PROTOCOL_ALL; |
| 406 | id->target_bits = phy->identify.target_port_protocols; |
| 407 | } else if (phy->phy_type & PORT_TYPE_SATA) { |
| 408 | /*Nothing*/ |
| 409 | } |
| 410 | |
| 411 | sas_phy->frame_rcvd_size = phy->frame_rcvd_size; |
| 412 | sas_ha->notify_port_event(sas_phy, PORTE_BYTES_DMAED); |
| 413 | } |
| 414 | |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 415 | static struct hisi_sas_device *hisi_sas_alloc_dev(struct domain_device *device) |
| 416 | { |
| 417 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); |
| 418 | struct hisi_sas_device *sas_dev = NULL; |
| 419 | int i; |
| 420 | |
| 421 | spin_lock(&hisi_hba->lock); |
| 422 | for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) { |
| 423 | if (hisi_hba->devices[i].dev_type == SAS_PHY_UNUSED) { |
| 424 | hisi_hba->devices[i].device_id = i; |
| 425 | sas_dev = &hisi_hba->devices[i]; |
| 426 | sas_dev->dev_status = HISI_SAS_DEV_NORMAL; |
| 427 | sas_dev->dev_type = device->dev_type; |
| 428 | sas_dev->hisi_hba = hisi_hba; |
| 429 | sas_dev->sas_device = device; |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 430 | INIT_LIST_HEAD(&hisi_hba->devices[i].list); |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 431 | break; |
| 432 | } |
| 433 | } |
| 434 | spin_unlock(&hisi_hba->lock); |
| 435 | |
| 436 | return sas_dev; |
| 437 | } |
| 438 | |
| 439 | static int hisi_sas_dev_found(struct domain_device *device) |
| 440 | { |
| 441 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); |
| 442 | struct domain_device *parent_dev = device->parent; |
| 443 | struct hisi_sas_device *sas_dev; |
| 444 | struct device *dev = &hisi_hba->pdev->dev; |
| 445 | |
John Garry | 685b6d6 | 2016-04-15 21:36:36 +0800 | [diff] [blame] | 446 | if (hisi_hba->hw->alloc_dev) |
| 447 | sas_dev = hisi_hba->hw->alloc_dev(device); |
| 448 | else |
| 449 | sas_dev = hisi_sas_alloc_dev(device); |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 450 | if (!sas_dev) { |
| 451 | dev_err(dev, "fail alloc dev: max support %d devices\n", |
| 452 | HISI_SAS_MAX_DEVICES); |
| 453 | return -EINVAL; |
| 454 | } |
| 455 | |
| 456 | device->lldd_dev = sas_dev; |
| 457 | hisi_hba->hw->setup_itct(hisi_hba, sas_dev); |
| 458 | |
| 459 | if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type)) { |
| 460 | int phy_no; |
| 461 | u8 phy_num = parent_dev->ex_dev.num_phys; |
| 462 | struct ex_phy *phy; |
| 463 | |
| 464 | for (phy_no = 0; phy_no < phy_num; phy_no++) { |
| 465 | phy = &parent_dev->ex_dev.ex_phy[phy_no]; |
| 466 | if (SAS_ADDR(phy->attached_sas_addr) == |
| 467 | SAS_ADDR(device->sas_addr)) { |
| 468 | sas_dev->attached_phy = phy_no; |
| 469 | break; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | if (phy_no == phy_num) { |
| 474 | dev_info(dev, "dev found: no attached " |
| 475 | "dev:%016llx at ex:%016llx\n", |
| 476 | SAS_ADDR(device->sas_addr), |
| 477 | SAS_ADDR(parent_dev->sas_addr)); |
| 478 | return -EINVAL; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | |
John Garry | 31eec8a | 2016-02-25 17:42:14 +0800 | [diff] [blame] | 485 | static int hisi_sas_slave_configure(struct scsi_device *sdev) |
| 486 | { |
| 487 | struct domain_device *dev = sdev_to_domain_dev(sdev); |
| 488 | int ret = sas_slave_configure(sdev); |
| 489 | |
| 490 | if (ret) |
| 491 | return ret; |
| 492 | if (!dev_is_sata(dev)) |
| 493 | sas_change_queue_depth(sdev, 64); |
| 494 | |
| 495 | return 0; |
| 496 | } |
| 497 | |
John Garry | 701f75e | 2015-11-18 00:50:55 +0800 | [diff] [blame] | 498 | static void hisi_sas_scan_start(struct Scsi_Host *shost) |
| 499 | { |
| 500 | struct hisi_hba *hisi_hba = shost_priv(shost); |
John Garry | 701f75e | 2015-11-18 00:50:55 +0800 | [diff] [blame] | 501 | |
John Garry | 396b804 | 2017-03-23 01:25:19 +0800 | [diff] [blame] | 502 | hisi_hba->hw->phys_init(hisi_hba); |
John Garry | 701f75e | 2015-11-18 00:50:55 +0800 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | static int hisi_sas_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 506 | { |
| 507 | struct hisi_hba *hisi_hba = shost_priv(shost); |
| 508 | struct sas_ha_struct *sha = &hisi_hba->sha; |
| 509 | |
John Garry | 396b804 | 2017-03-23 01:25:19 +0800 | [diff] [blame] | 510 | /* Wait for PHY up interrupt to occur */ |
| 511 | if (time < HZ) |
John Garry | 701f75e | 2015-11-18 00:50:55 +0800 | [diff] [blame] | 512 | return 0; |
| 513 | |
| 514 | sas_drain_work(sha); |
| 515 | return 1; |
| 516 | } |
| 517 | |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 518 | static void hisi_sas_phyup_work(struct work_struct *work) |
| 519 | { |
| 520 | struct hisi_sas_phy *phy = |
| 521 | container_of(work, struct hisi_sas_phy, phyup_ws); |
| 522 | struct hisi_hba *hisi_hba = phy->hisi_hba; |
| 523 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
| 524 | int phy_no = sas_phy->id; |
| 525 | |
| 526 | hisi_hba->hw->sl_notify(hisi_hba, phy_no); /* This requires a sleep */ |
| 527 | hisi_sas_bytes_dmaed(hisi_hba, phy_no); |
| 528 | } |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 529 | |
| 530 | static void hisi_sas_phy_init(struct hisi_hba *hisi_hba, int phy_no) |
| 531 | { |
| 532 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; |
| 533 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
| 534 | |
| 535 | phy->hisi_hba = hisi_hba; |
| 536 | phy->port = NULL; |
| 537 | init_timer(&phy->timer); |
| 538 | sas_phy->enabled = (phy_no < hisi_hba->n_phy) ? 1 : 0; |
| 539 | sas_phy->class = SAS; |
| 540 | sas_phy->iproto = SAS_PROTOCOL_ALL; |
| 541 | sas_phy->tproto = 0; |
| 542 | sas_phy->type = PHY_TYPE_PHYSICAL; |
| 543 | sas_phy->role = PHY_ROLE_INITIATOR; |
| 544 | sas_phy->oob_mode = OOB_NOT_CONNECTED; |
| 545 | sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN; |
| 546 | sas_phy->id = phy_no; |
| 547 | sas_phy->sas_addr = &hisi_hba->sas_addr[0]; |
| 548 | sas_phy->frame_rcvd = &phy->frame_rcvd[0]; |
| 549 | sas_phy->ha = (struct sas_ha_struct *)hisi_hba->shost->hostdata; |
| 550 | sas_phy->lldd_phy = phy; |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 551 | |
| 552 | INIT_WORK(&phy->phyup_ws, hisi_sas_phyup_work); |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 553 | } |
| 554 | |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 555 | static void hisi_sas_port_notify_formed(struct asd_sas_phy *sas_phy) |
| 556 | { |
| 557 | struct sas_ha_struct *sas_ha = sas_phy->ha; |
| 558 | struct hisi_hba *hisi_hba = sas_ha->lldd_ha; |
| 559 | struct hisi_sas_phy *phy = sas_phy->lldd_phy; |
| 560 | struct asd_sas_port *sas_port = sas_phy->port; |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 561 | struct hisi_sas_port *port = to_hisi_sas_port(sas_port); |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 562 | unsigned long flags; |
| 563 | |
| 564 | if (!sas_port) |
| 565 | return; |
| 566 | |
| 567 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 568 | port->port_attached = 1; |
| 569 | port->id = phy->port_id; |
| 570 | phy->port = port; |
| 571 | sas_port->lldd_port = port; |
| 572 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 573 | } |
| 574 | |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 575 | 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] | 576 | struct hisi_sas_slot *slot) |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 577 | { |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 578 | if (task) { |
| 579 | unsigned long flags; |
| 580 | struct task_status_struct *ts; |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 581 | |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 582 | ts = &task->task_status; |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 583 | |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 584 | ts->resp = SAS_TASK_COMPLETE; |
| 585 | ts->stat = SAS_ABORTED_TASK; |
| 586 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 587 | task->task_state_flags &= |
| 588 | ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR); |
| 589 | task->task_state_flags |= SAS_TASK_STATE_DONE; |
| 590 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 591 | } |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 592 | |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 593 | hisi_sas_slot_task_free(hisi_hba, task, slot); |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 594 | } |
| 595 | |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 596 | /* hisi_hba.lock should be locked */ |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 597 | static void hisi_sas_release_task(struct hisi_hba *hisi_hba, |
| 598 | struct domain_device *device) |
| 599 | { |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 600 | struct hisi_sas_slot *slot, *slot2; |
| 601 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 602 | |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 603 | list_for_each_entry_safe(slot, slot2, &sas_dev->list, entry) |
| 604 | hisi_sas_do_release_task(hisi_hba, slot->task, slot); |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 605 | } |
| 606 | |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 607 | static void hisi_sas_release_tasks(struct hisi_hba *hisi_hba) |
| 608 | { |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 609 | struct hisi_sas_device *sas_dev; |
| 610 | struct domain_device *device; |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 611 | int i; |
| 612 | |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 613 | for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) { |
| 614 | sas_dev = &hisi_hba->devices[i]; |
| 615 | device = sas_dev->sas_device; |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 616 | |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 617 | if ((sas_dev->dev_type == SAS_PHY_UNUSED) || |
| 618 | !device) |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 619 | continue; |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 620 | |
| 621 | hisi_sas_release_task(hisi_hba, device); |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 625 | static void hisi_sas_dev_gone(struct domain_device *device) |
| 626 | { |
| 627 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 628 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); |
| 629 | struct device *dev = &hisi_hba->pdev->dev; |
| 630 | u64 dev_id = sas_dev->device_id; |
| 631 | |
| 632 | dev_info(dev, "found dev[%lld:%x] is gone\n", |
| 633 | sas_dev->device_id, sas_dev->dev_type); |
| 634 | |
John Garry | 40f2702 | 2016-08-24 19:05:48 +0800 | [diff] [blame] | 635 | hisi_sas_internal_task_abort(hisi_hba, device, |
| 636 | HISI_SAS_INT_ABT_DEV, 0); |
| 637 | |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 638 | hisi_hba->hw->free_device(hisi_hba, sas_dev); |
| 639 | device->lldd_dev = NULL; |
| 640 | memset(sas_dev, 0, sizeof(*sas_dev)); |
| 641 | sas_dev->device_id = dev_id; |
| 642 | sas_dev->dev_type = SAS_PHY_UNUSED; |
| 643 | sas_dev->dev_status = HISI_SAS_DEV_NORMAL; |
| 644 | } |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 645 | |
| 646 | static int hisi_sas_queue_command(struct sas_task *task, gfp_t gfp_flags) |
| 647 | { |
| 648 | return hisi_sas_task_exec(task, gfp_flags, 0, NULL); |
| 649 | } |
| 650 | |
John Garry | e4189d5 | 2015-11-18 00:50:57 +0800 | [diff] [blame] | 651 | static int hisi_sas_control_phy(struct asd_sas_phy *sas_phy, enum phy_func func, |
| 652 | void *funcdata) |
| 653 | { |
| 654 | struct sas_ha_struct *sas_ha = sas_phy->ha; |
| 655 | struct hisi_hba *hisi_hba = sas_ha->lldd_ha; |
| 656 | int phy_no = sas_phy->id; |
| 657 | |
| 658 | switch (func) { |
| 659 | case PHY_FUNC_HARD_RESET: |
| 660 | hisi_hba->hw->phy_hard_reset(hisi_hba, phy_no); |
| 661 | break; |
| 662 | |
| 663 | case PHY_FUNC_LINK_RESET: |
John Garry | b4c67a6 | 2017-03-23 01:25:23 +0800 | [diff] [blame] | 664 | hisi_hba->hw->phy_disable(hisi_hba, phy_no); |
| 665 | msleep(100); |
John Garry | e4189d5 | 2015-11-18 00:50:57 +0800 | [diff] [blame] | 666 | hisi_hba->hw->phy_enable(hisi_hba, phy_no); |
John Garry | e4189d5 | 2015-11-18 00:50:57 +0800 | [diff] [blame] | 667 | break; |
| 668 | |
| 669 | case PHY_FUNC_DISABLE: |
| 670 | hisi_hba->hw->phy_disable(hisi_hba, phy_no); |
| 671 | break; |
| 672 | |
| 673 | case PHY_FUNC_SET_LINK_RATE: |
Xiang Chen | 2ae7578 | 2016-11-07 20:48:40 +0800 | [diff] [blame] | 674 | hisi_hba->hw->phy_set_linkrate(hisi_hba, phy_no, funcdata); |
| 675 | break; |
| 676 | |
John Garry | e4189d5 | 2015-11-18 00:50:57 +0800 | [diff] [blame] | 677 | case PHY_FUNC_RELEASE_SPINUP_HOLD: |
| 678 | default: |
| 679 | return -EOPNOTSUPP; |
| 680 | } |
| 681 | return 0; |
| 682 | } |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 683 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 684 | static void hisi_sas_task_done(struct sas_task *task) |
| 685 | { |
| 686 | if (!del_timer(&task->slow_task->timer)) |
| 687 | return; |
| 688 | complete(&task->slow_task->completion); |
| 689 | } |
| 690 | |
| 691 | static void hisi_sas_tmf_timedout(unsigned long data) |
| 692 | { |
| 693 | struct sas_task *task = (struct sas_task *)data; |
| 694 | |
| 695 | task->task_state_flags |= SAS_TASK_STATE_ABORTED; |
| 696 | complete(&task->slow_task->completion); |
| 697 | } |
| 698 | |
| 699 | #define TASK_TIMEOUT 20 |
| 700 | #define TASK_RETRY 3 |
| 701 | static int hisi_sas_exec_internal_tmf_task(struct domain_device *device, |
| 702 | void *parameter, u32 para_len, |
| 703 | struct hisi_sas_tmf_task *tmf) |
| 704 | { |
| 705 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 706 | struct hisi_hba *hisi_hba = sas_dev->hisi_hba; |
| 707 | struct device *dev = &hisi_hba->pdev->dev; |
| 708 | struct sas_task *task; |
| 709 | int res, retry; |
| 710 | |
| 711 | for (retry = 0; retry < TASK_RETRY; retry++) { |
| 712 | task = sas_alloc_slow_task(GFP_KERNEL); |
| 713 | if (!task) |
| 714 | return -ENOMEM; |
| 715 | |
| 716 | task->dev = device; |
| 717 | task->task_proto = device->tproto; |
| 718 | |
Xiang Chen | 7c594f0 | 2017-03-23 01:25:20 +0800 | [diff] [blame] | 719 | if (dev_is_sata(device)) { |
| 720 | task->ata_task.device_control_reg_update = 1; |
| 721 | memcpy(&task->ata_task.fis, parameter, para_len); |
| 722 | } else { |
| 723 | memcpy(&task->ssp_task, parameter, para_len); |
| 724 | } |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 725 | task->task_done = hisi_sas_task_done; |
| 726 | |
| 727 | task->slow_task->timer.data = (unsigned long) task; |
| 728 | task->slow_task->timer.function = hisi_sas_tmf_timedout; |
| 729 | task->slow_task->timer.expires = jiffies + TASK_TIMEOUT*HZ; |
| 730 | add_timer(&task->slow_task->timer); |
| 731 | |
| 732 | res = hisi_sas_task_exec(task, GFP_KERNEL, 1, tmf); |
| 733 | |
| 734 | if (res) { |
| 735 | del_timer(&task->slow_task->timer); |
| 736 | dev_err(dev, "abort tmf: executing internal task failed: %d\n", |
| 737 | res); |
| 738 | goto ex_err; |
| 739 | } |
| 740 | |
| 741 | wait_for_completion(&task->slow_task->completion); |
| 742 | res = TMF_RESP_FUNC_FAILED; |
| 743 | /* Even TMF timed out, return direct. */ |
| 744 | if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) { |
| 745 | if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 746 | struct hisi_sas_slot *slot = task->lldd_task; |
| 747 | |
Xiang Chen | 7c594f0 | 2017-03-23 01:25:20 +0800 | [diff] [blame] | 748 | dev_err(dev, "abort tmf: TMF task timeout\n"); |
John Garry | d3c4dd4 | 2017-04-10 21:22:00 +0800 | [diff] [blame] | 749 | if (slot) |
| 750 | slot->task = NULL; |
| 751 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 752 | goto ex_err; |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
John Garry | 1af1b80 | 2016-02-25 17:42:10 +0800 | [diff] [blame] | 757 | task->task_status.stat == TMF_RESP_FUNC_COMPLETE) { |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 758 | res = TMF_RESP_FUNC_COMPLETE; |
| 759 | break; |
| 760 | } |
| 761 | |
| 762 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
John Garry | 4ffde48 | 2016-08-24 19:05:53 +0800 | [diff] [blame] | 763 | task->task_status.stat == TMF_RESP_FUNC_SUCC) { |
| 764 | res = TMF_RESP_FUNC_SUCC; |
| 765 | break; |
| 766 | } |
| 767 | |
| 768 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 769 | task->task_status.stat == SAS_DATA_UNDERRUN) { |
| 770 | /* no error, but return the number of bytes of |
| 771 | * underrun |
| 772 | */ |
| 773 | dev_warn(dev, "abort tmf: task to dev %016llx " |
| 774 | "resp: 0x%x sts 0x%x underrun\n", |
| 775 | SAS_ADDR(device->sas_addr), |
| 776 | task->task_status.resp, |
| 777 | task->task_status.stat); |
| 778 | res = task->task_status.residual; |
| 779 | break; |
| 780 | } |
| 781 | |
| 782 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
| 783 | task->task_status.stat == SAS_DATA_OVERRUN) { |
| 784 | dev_warn(dev, "abort tmf: blocked task error\n"); |
| 785 | res = -EMSGSIZE; |
| 786 | break; |
| 787 | } |
| 788 | |
| 789 | dev_warn(dev, "abort tmf: task to dev " |
| 790 | "%016llx resp: 0x%x status 0x%x\n", |
| 791 | SAS_ADDR(device->sas_addr), task->task_status.resp, |
| 792 | task->task_status.stat); |
| 793 | sas_free_task(task); |
| 794 | task = NULL; |
| 795 | } |
| 796 | ex_err: |
Xiang Chen | d2d7e7a | 2016-11-07 20:48:34 +0800 | [diff] [blame] | 797 | if (retry == TASK_RETRY) |
| 798 | dev_warn(dev, "abort tmf: executing internal task failed!\n"); |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 799 | sas_free_task(task); |
| 800 | return res; |
| 801 | } |
| 802 | |
Xiang Chen | 7c594f0 | 2017-03-23 01:25:20 +0800 | [diff] [blame] | 803 | static void hisi_sas_fill_ata_reset_cmd(struct ata_device *dev, |
| 804 | bool reset, int pmp, u8 *fis) |
| 805 | { |
| 806 | struct ata_taskfile tf; |
| 807 | |
| 808 | ata_tf_init(dev, &tf); |
| 809 | if (reset) |
| 810 | tf.ctl |= ATA_SRST; |
| 811 | else |
| 812 | tf.ctl &= ~ATA_SRST; |
| 813 | tf.command = ATA_CMD_DEV_RESET; |
| 814 | ata_tf_to_fis(&tf, pmp, 0, fis); |
| 815 | } |
| 816 | |
| 817 | static int hisi_sas_softreset_ata_disk(struct domain_device *device) |
| 818 | { |
| 819 | u8 fis[20] = {0}; |
| 820 | struct ata_port *ap = device->sata_dev.ap; |
| 821 | struct ata_link *link; |
| 822 | int rc = TMF_RESP_FUNC_FAILED; |
| 823 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); |
| 824 | struct device *dev = &hisi_hba->pdev->dev; |
| 825 | int s = sizeof(struct host_to_dev_fis); |
| 826 | unsigned long flags; |
| 827 | |
| 828 | ata_for_each_link(link, ap, EDGE) { |
| 829 | int pmp = sata_srst_pmp(link); |
| 830 | |
| 831 | hisi_sas_fill_ata_reset_cmd(link->device, 1, pmp, fis); |
| 832 | rc = hisi_sas_exec_internal_tmf_task(device, fis, s, NULL); |
| 833 | if (rc != TMF_RESP_FUNC_COMPLETE) |
| 834 | break; |
| 835 | } |
| 836 | |
| 837 | if (rc == TMF_RESP_FUNC_COMPLETE) { |
| 838 | ata_for_each_link(link, ap, EDGE) { |
| 839 | int pmp = sata_srst_pmp(link); |
| 840 | |
| 841 | hisi_sas_fill_ata_reset_cmd(link->device, 0, pmp, fis); |
| 842 | rc = hisi_sas_exec_internal_tmf_task(device, fis, |
| 843 | s, NULL); |
| 844 | if (rc != TMF_RESP_FUNC_COMPLETE) |
| 845 | dev_err(dev, "ata disk de-reset failed\n"); |
| 846 | } |
| 847 | } else { |
| 848 | dev_err(dev, "ata disk reset failed\n"); |
| 849 | } |
| 850 | |
| 851 | if (rc == TMF_RESP_FUNC_COMPLETE) { |
| 852 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 853 | hisi_sas_release_task(hisi_hba, device); |
| 854 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 855 | } |
| 856 | |
| 857 | return rc; |
| 858 | } |
| 859 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 860 | static int hisi_sas_debug_issue_ssp_tmf(struct domain_device *device, |
| 861 | u8 *lun, struct hisi_sas_tmf_task *tmf) |
| 862 | { |
| 863 | struct sas_ssp_task ssp_task; |
| 864 | |
| 865 | if (!(device->tproto & SAS_PROTOCOL_SSP)) |
| 866 | return TMF_RESP_FUNC_ESUPP; |
| 867 | |
| 868 | memcpy(ssp_task.LUN, lun, 8); |
| 869 | |
| 870 | return hisi_sas_exec_internal_tmf_task(device, &ssp_task, |
| 871 | sizeof(ssp_task), tmf); |
| 872 | } |
| 873 | |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 874 | static int hisi_sas_controller_reset(struct hisi_hba *hisi_hba) |
| 875 | { |
| 876 | int rc; |
| 877 | |
| 878 | if (!hisi_hba->hw->soft_reset) |
| 879 | return -1; |
| 880 | |
| 881 | if (!test_and_set_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags)) { |
| 882 | struct device *dev = &hisi_hba->pdev->dev; |
| 883 | struct sas_ha_struct *sas_ha = &hisi_hba->sha; |
| 884 | unsigned long flags; |
| 885 | |
| 886 | dev_dbg(dev, "controller reset begins!\n"); |
| 887 | scsi_block_requests(hisi_hba->shost); |
| 888 | rc = hisi_hba->hw->soft_reset(hisi_hba); |
| 889 | if (rc) { |
| 890 | dev_warn(dev, "controller reset failed (%d)\n", rc); |
| 891 | goto out; |
| 892 | } |
| 893 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 894 | hisi_sas_release_tasks(hisi_hba); |
| 895 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 896 | |
| 897 | sas_ha->notify_ha_event(sas_ha, HAE_RESET); |
| 898 | dev_dbg(dev, "controller reset successful!\n"); |
| 899 | } else |
| 900 | return -1; |
| 901 | |
| 902 | out: |
| 903 | scsi_unblock_requests(hisi_hba->shost); |
| 904 | clear_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags); |
| 905 | return rc; |
| 906 | } |
| 907 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 908 | static int hisi_sas_abort_task(struct sas_task *task) |
| 909 | { |
| 910 | struct scsi_lun lun; |
| 911 | struct hisi_sas_tmf_task tmf_task; |
| 912 | struct domain_device *device = task->dev; |
| 913 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 914 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(task->dev); |
| 915 | struct device *dev = &hisi_hba->pdev->dev; |
| 916 | int rc = TMF_RESP_FUNC_FAILED; |
| 917 | unsigned long flags; |
| 918 | |
| 919 | if (!sas_dev) { |
| 920 | dev_warn(dev, "Device has been removed\n"); |
| 921 | return TMF_RESP_FUNC_FAILED; |
| 922 | } |
| 923 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 924 | if (task->task_state_flags & SAS_TASK_STATE_DONE) { |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 925 | rc = TMF_RESP_FUNC_COMPLETE; |
| 926 | goto out; |
| 927 | } |
| 928 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 929 | sas_dev->dev_status = HISI_SAS_DEV_EH; |
| 930 | if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) { |
| 931 | struct scsi_cmnd *cmnd = task->uldd_task; |
| 932 | struct hisi_sas_slot *slot = task->lldd_task; |
| 933 | u32 tag = slot->idx; |
John Garry | c35279f | 2017-03-23 01:25:25 +0800 | [diff] [blame] | 934 | int rc2; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 935 | |
| 936 | int_to_scsilun(cmnd->device->lun, &lun); |
| 937 | tmf_task.tmf = TMF_ABORT_TASK; |
| 938 | tmf_task.tag_of_task_to_be_managed = cpu_to_le16(tag); |
| 939 | |
| 940 | rc = hisi_sas_debug_issue_ssp_tmf(task->dev, lun.scsi_lun, |
| 941 | &tmf_task); |
| 942 | |
John Garry | c35279f | 2017-03-23 01:25:25 +0800 | [diff] [blame] | 943 | rc2 = hisi_sas_internal_task_abort(hisi_hba, device, |
| 944 | HISI_SAS_INT_ABT_CMD, tag); |
| 945 | /* |
| 946 | * If the TMF finds that the IO is not in the device and also |
| 947 | * the internal abort does not succeed, then it is safe to |
| 948 | * free the slot. |
| 949 | * Note: if the internal abort succeeds then the slot |
| 950 | * will have already been completed |
| 951 | */ |
| 952 | if (rc == TMF_RESP_FUNC_COMPLETE && rc2 != TMF_RESP_FUNC_SUCC) { |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 953 | if (task->lldd_task) { |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 954 | spin_lock_irqsave(&hisi_hba->lock, flags); |
John Garry | c35279f | 2017-03-23 01:25:25 +0800 | [diff] [blame] | 955 | hisi_sas_do_release_task(hisi_hba, task, slot); |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 956 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 957 | } |
| 958 | } |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 959 | } else if (task->task_proto & SAS_PROTOCOL_SATA || |
| 960 | task->task_proto & SAS_PROTOCOL_STP) { |
| 961 | if (task->dev->dev_type == SAS_SATA_DEV) { |
John Garry | dc8a49c | 2016-08-24 19:05:49 +0800 | [diff] [blame] | 962 | hisi_sas_internal_task_abort(hisi_hba, device, |
| 963 | HISI_SAS_INT_ABT_DEV, 0); |
Xiang Chen | 7c594f0 | 2017-03-23 01:25:20 +0800 | [diff] [blame] | 964 | rc = hisi_sas_softreset_ata_disk(device); |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 965 | } |
Gustavo A. R. Silva | eb045e0 | 2017-05-22 13:00:29 -0500 | [diff] [blame^] | 966 | } else if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SMP) { |
John Garry | dc8a49c | 2016-08-24 19:05:49 +0800 | [diff] [blame] | 967 | /* SMP */ |
| 968 | struct hisi_sas_slot *slot = task->lldd_task; |
| 969 | u32 tag = slot->idx; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 970 | |
Xiang Chen | ccbfe5a | 2017-03-23 01:25:36 +0800 | [diff] [blame] | 971 | rc = hisi_sas_internal_task_abort(hisi_hba, device, |
| 972 | HISI_SAS_INT_ABT_CMD, tag); |
| 973 | if (rc == TMF_RESP_FUNC_FAILED) { |
| 974 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 975 | hisi_sas_do_release_task(hisi_hba, task, slot); |
| 976 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 977 | } |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | out: |
| 981 | if (rc != TMF_RESP_FUNC_COMPLETE) |
| 982 | dev_notice(dev, "abort task: rc=%d\n", rc); |
| 983 | return rc; |
| 984 | } |
| 985 | |
| 986 | static int hisi_sas_abort_task_set(struct domain_device *device, u8 *lun) |
| 987 | { |
| 988 | struct hisi_sas_tmf_task tmf_task; |
| 989 | int rc = TMF_RESP_FUNC_FAILED; |
| 990 | |
| 991 | tmf_task.tmf = TMF_ABORT_TASK_SET; |
| 992 | rc = hisi_sas_debug_issue_ssp_tmf(device, lun, &tmf_task); |
| 993 | |
| 994 | return rc; |
| 995 | } |
| 996 | |
| 997 | static int hisi_sas_clear_aca(struct domain_device *device, u8 *lun) |
| 998 | { |
| 999 | int rc = TMF_RESP_FUNC_FAILED; |
| 1000 | struct hisi_sas_tmf_task tmf_task; |
| 1001 | |
| 1002 | tmf_task.tmf = TMF_CLEAR_ACA; |
| 1003 | rc = hisi_sas_debug_issue_ssp_tmf(device, lun, &tmf_task); |
| 1004 | |
| 1005 | return rc; |
| 1006 | } |
| 1007 | |
| 1008 | static int hisi_sas_debug_I_T_nexus_reset(struct domain_device *device) |
| 1009 | { |
| 1010 | struct sas_phy *phy = sas_get_local_phy(device); |
| 1011 | int rc, reset_type = (device->dev_type == SAS_SATA_DEV || |
| 1012 | (device->tproto & SAS_PROTOCOL_STP)) ? 0 : 1; |
| 1013 | rc = sas_phy_reset(phy, reset_type); |
| 1014 | sas_put_local_phy(phy); |
| 1015 | msleep(2000); |
| 1016 | return rc; |
| 1017 | } |
| 1018 | |
| 1019 | static int hisi_sas_I_T_nexus_reset(struct domain_device *device) |
| 1020 | { |
| 1021 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 1022 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); |
| 1023 | unsigned long flags; |
| 1024 | int rc = TMF_RESP_FUNC_FAILED; |
| 1025 | |
| 1026 | if (sas_dev->dev_status != HISI_SAS_DEV_EH) |
| 1027 | return TMF_RESP_FUNC_FAILED; |
| 1028 | sas_dev->dev_status = HISI_SAS_DEV_NORMAL; |
| 1029 | |
| 1030 | rc = hisi_sas_debug_I_T_nexus_reset(device); |
| 1031 | |
Xiang Chen | 6131243 | 2017-03-23 01:25:28 +0800 | [diff] [blame] | 1032 | if (rc == TMF_RESP_FUNC_COMPLETE) { |
| 1033 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 1034 | hisi_sas_release_task(hisi_hba, device); |
| 1035 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 1036 | } |
| 1037 | return rc; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | static int hisi_sas_lu_reset(struct domain_device *device, u8 *lun) |
| 1041 | { |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1042 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 1043 | struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); |
| 1044 | struct device *dev = &hisi_hba->pdev->dev; |
| 1045 | unsigned long flags; |
| 1046 | int rc = TMF_RESP_FUNC_FAILED; |
| 1047 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1048 | sas_dev->dev_status = HISI_SAS_DEV_EH; |
John Garry | 055945d | 2017-03-23 01:25:26 +0800 | [diff] [blame] | 1049 | if (dev_is_sata(device)) { |
| 1050 | struct sas_phy *phy; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1051 | |
John Garry | 055945d | 2017-03-23 01:25:26 +0800 | [diff] [blame] | 1052 | /* Clear internal IO and then hardreset */ |
| 1053 | rc = hisi_sas_internal_task_abort(hisi_hba, device, |
| 1054 | HISI_SAS_INT_ABT_DEV, 0); |
| 1055 | if (rc == TMF_RESP_FUNC_FAILED) |
| 1056 | goto out; |
| 1057 | |
| 1058 | phy = sas_get_local_phy(device); |
| 1059 | |
| 1060 | rc = sas_phy_reset(phy, 1); |
| 1061 | |
| 1062 | if (rc == 0) { |
| 1063 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 1064 | hisi_sas_release_task(hisi_hba, device); |
| 1065 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 1066 | } |
| 1067 | sas_put_local_phy(phy); |
| 1068 | } else { |
| 1069 | struct hisi_sas_tmf_task tmf_task = { .tmf = TMF_LU_RESET }; |
| 1070 | |
| 1071 | rc = hisi_sas_debug_issue_ssp_tmf(device, lun, &tmf_task); |
| 1072 | if (rc == TMF_RESP_FUNC_COMPLETE) { |
| 1073 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 1074 | hisi_sas_release_task(hisi_hba, device); |
| 1075 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 1076 | } |
| 1077 | } |
| 1078 | out: |
John Garry | 14d3f39 | 2017-03-23 01:25:37 +0800 | [diff] [blame] | 1079 | if (rc != TMF_RESP_FUNC_COMPLETE) |
| 1080 | dev_err(dev, "lu_reset: for device[%llx]:rc= %d\n", |
| 1081 | sas_dev->device_id, rc); |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1082 | return rc; |
| 1083 | } |
| 1084 | |
John Garry | 8b05ad6 | 2017-03-23 01:25:35 +0800 | [diff] [blame] | 1085 | static int hisi_sas_clear_nexus_ha(struct sas_ha_struct *sas_ha) |
| 1086 | { |
| 1087 | struct hisi_hba *hisi_hba = sas_ha->lldd_ha; |
| 1088 | |
| 1089 | return hisi_sas_controller_reset(hisi_hba); |
| 1090 | } |
| 1091 | |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1092 | static int hisi_sas_query_task(struct sas_task *task) |
| 1093 | { |
| 1094 | struct scsi_lun lun; |
| 1095 | struct hisi_sas_tmf_task tmf_task; |
| 1096 | int rc = TMF_RESP_FUNC_FAILED; |
| 1097 | |
| 1098 | if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) { |
| 1099 | struct scsi_cmnd *cmnd = task->uldd_task; |
| 1100 | struct domain_device *device = task->dev; |
| 1101 | struct hisi_sas_slot *slot = task->lldd_task; |
| 1102 | u32 tag = slot->idx; |
| 1103 | |
| 1104 | int_to_scsilun(cmnd->device->lun, &lun); |
| 1105 | tmf_task.tmf = TMF_QUERY_TASK; |
| 1106 | tmf_task.tag_of_task_to_be_managed = cpu_to_le16(tag); |
| 1107 | |
| 1108 | rc = hisi_sas_debug_issue_ssp_tmf(device, |
| 1109 | lun.scsi_lun, |
| 1110 | &tmf_task); |
| 1111 | switch (rc) { |
| 1112 | /* The task is still in Lun, release it then */ |
| 1113 | case TMF_RESP_FUNC_SUCC: |
| 1114 | /* The task is not in Lun or failed, reset the phy */ |
| 1115 | case TMF_RESP_FUNC_FAILED: |
| 1116 | case TMF_RESP_FUNC_COMPLETE: |
| 1117 | break; |
Xiang Chen | 997ee43 | 2016-11-07 20:48:35 +0800 | [diff] [blame] | 1118 | default: |
| 1119 | rc = TMF_RESP_FUNC_FAILED; |
| 1120 | break; |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1121 | } |
| 1122 | } |
| 1123 | return rc; |
| 1124 | } |
| 1125 | |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1126 | static int |
| 1127 | hisi_sas_internal_abort_task_exec(struct hisi_hba *hisi_hba, u64 device_id, |
| 1128 | struct sas_task *task, int abort_flag, |
| 1129 | int task_tag) |
| 1130 | { |
| 1131 | struct domain_device *device = task->dev; |
| 1132 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 1133 | struct device *dev = &hisi_hba->pdev->dev; |
| 1134 | struct hisi_sas_port *port; |
| 1135 | struct hisi_sas_slot *slot; |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 1136 | struct asd_sas_port *sas_port = device->port; |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1137 | struct hisi_sas_cmd_hdr *cmd_hdr_base; |
| 1138 | int dlvry_queue_slot, dlvry_queue, n_elem = 0, rc, slot_idx; |
John Garry | 54c9dd2 | 2017-03-23 01:25:29 +0800 | [diff] [blame] | 1139 | unsigned long flags; |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1140 | |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1141 | if (unlikely(test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags))) |
| 1142 | return -EINVAL; |
| 1143 | |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1144 | if (!device->port) |
| 1145 | return -1; |
| 1146 | |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 1147 | port = to_hisi_sas_port(sas_port); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1148 | |
| 1149 | /* simply get a slot and send abort command */ |
| 1150 | rc = hisi_sas_slot_index_alloc(hisi_hba, &slot_idx); |
| 1151 | if (rc) |
| 1152 | goto err_out; |
Xiang Chen | c70f1fb | 2016-11-07 20:48:31 +0800 | [diff] [blame] | 1153 | rc = hisi_hba->hw->get_free_slot(hisi_hba, sas_dev->device_id, |
| 1154 | &dlvry_queue, &dlvry_queue_slot); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1155 | if (rc) |
| 1156 | goto err_out_tag; |
| 1157 | |
| 1158 | slot = &hisi_hba->slot_info[slot_idx]; |
| 1159 | memset(slot, 0, sizeof(struct hisi_sas_slot)); |
| 1160 | |
| 1161 | slot->idx = slot_idx; |
| 1162 | slot->n_elem = n_elem; |
| 1163 | slot->dlvry_queue = dlvry_queue; |
| 1164 | slot->dlvry_queue_slot = dlvry_queue_slot; |
| 1165 | cmd_hdr_base = hisi_hba->cmd_hdr[dlvry_queue]; |
| 1166 | slot->cmd_hdr = &cmd_hdr_base[dlvry_queue_slot]; |
| 1167 | slot->task = task; |
| 1168 | slot->port = port; |
| 1169 | task->lldd_task = slot; |
| 1170 | |
| 1171 | memset(slot->cmd_hdr, 0, sizeof(struct hisi_sas_cmd_hdr)); |
| 1172 | |
| 1173 | rc = hisi_sas_task_prep_abort(hisi_hba, slot, device_id, |
| 1174 | abort_flag, task_tag); |
| 1175 | if (rc) |
| 1176 | goto err_out_tag; |
| 1177 | |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 1178 | |
| 1179 | list_add_tail(&slot->entry, &sas_dev->list); |
John Garry | 54c9dd2 | 2017-03-23 01:25:29 +0800 | [diff] [blame] | 1180 | spin_lock_irqsave(&task->task_state_lock, flags); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1181 | task->task_state_flags |= SAS_TASK_AT_INITIATOR; |
John Garry | 54c9dd2 | 2017-03-23 01:25:29 +0800 | [diff] [blame] | 1182 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1183 | |
| 1184 | hisi_hba->slot_prep = slot; |
| 1185 | |
John Garry | f696cc3 | 2016-11-07 20:48:39 +0800 | [diff] [blame] | 1186 | atomic64_inc(&sas_dev->running_req); |
| 1187 | |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1188 | /* send abort command to our chip */ |
| 1189 | hisi_hba->hw->start_delivery(hisi_hba); |
| 1190 | |
| 1191 | return 0; |
| 1192 | |
| 1193 | err_out_tag: |
| 1194 | hisi_sas_slot_index_free(hisi_hba, slot_idx); |
| 1195 | err_out: |
| 1196 | dev_err(dev, "internal abort task prep: failed[%d]!\n", rc); |
| 1197 | |
| 1198 | return rc; |
| 1199 | } |
| 1200 | |
| 1201 | /** |
| 1202 | * hisi_sas_internal_task_abort -- execute an internal |
| 1203 | * abort command for single IO command or a device |
| 1204 | * @hisi_hba: host controller struct |
| 1205 | * @device: domain device |
| 1206 | * @abort_flag: mode of operation, device or single IO |
| 1207 | * @tag: tag of IO to be aborted (only relevant to single |
| 1208 | * IO mode) |
| 1209 | */ |
| 1210 | static int |
| 1211 | hisi_sas_internal_task_abort(struct hisi_hba *hisi_hba, |
| 1212 | struct domain_device *device, |
| 1213 | int abort_flag, int tag) |
| 1214 | { |
| 1215 | struct sas_task *task; |
| 1216 | struct hisi_sas_device *sas_dev = device->lldd_dev; |
| 1217 | struct device *dev = &hisi_hba->pdev->dev; |
| 1218 | int res; |
| 1219 | unsigned long flags; |
| 1220 | |
| 1221 | if (!hisi_hba->hw->prep_abort) |
| 1222 | return -EOPNOTSUPP; |
| 1223 | |
| 1224 | task = sas_alloc_slow_task(GFP_KERNEL); |
| 1225 | if (!task) |
| 1226 | return -ENOMEM; |
| 1227 | |
| 1228 | task->dev = device; |
| 1229 | task->task_proto = device->tproto; |
| 1230 | task->task_done = hisi_sas_task_done; |
| 1231 | task->slow_task->timer.data = (unsigned long)task; |
| 1232 | task->slow_task->timer.function = hisi_sas_tmf_timedout; |
John Garry | 0844a3f | 2017-04-10 21:21:59 +0800 | [diff] [blame] | 1233 | task->slow_task->timer.expires = jiffies + msecs_to_jiffies(110); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1234 | add_timer(&task->slow_task->timer); |
| 1235 | |
| 1236 | /* Lock as we are alloc'ing a slot, which cannot be interrupted */ |
| 1237 | spin_lock_irqsave(&hisi_hba->lock, flags); |
| 1238 | res = hisi_sas_internal_abort_task_exec(hisi_hba, sas_dev->device_id, |
| 1239 | task, abort_flag, tag); |
| 1240 | spin_unlock_irqrestore(&hisi_hba->lock, flags); |
| 1241 | if (res) { |
| 1242 | del_timer(&task->slow_task->timer); |
| 1243 | dev_err(dev, "internal task abort: executing internal task failed: %d\n", |
| 1244 | res); |
| 1245 | goto exit; |
| 1246 | } |
| 1247 | wait_for_completion(&task->slow_task->completion); |
| 1248 | res = TMF_RESP_FUNC_FAILED; |
| 1249 | |
| 1250 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
| 1251 | task->task_status.stat == TMF_RESP_FUNC_COMPLETE) { |
| 1252 | res = TMF_RESP_FUNC_COMPLETE; |
| 1253 | goto exit; |
| 1254 | } |
| 1255 | |
John Garry | c35279f | 2017-03-23 01:25:25 +0800 | [diff] [blame] | 1256 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
| 1257 | task->task_status.stat == TMF_RESP_FUNC_SUCC) { |
| 1258 | res = TMF_RESP_FUNC_SUCC; |
| 1259 | goto exit; |
| 1260 | } |
| 1261 | |
John Garry | 6fcdda8 | 2017-03-23 01:25:30 +0800 | [diff] [blame] | 1262 | /* Internal abort timed out */ |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1263 | if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) { |
| 1264 | if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { |
| 1265 | dev_err(dev, "internal task abort: timeout.\n"); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | exit: |
John Garry | 297d730 | 2017-01-20 20:45:22 +0800 | [diff] [blame] | 1270 | dev_dbg(dev, "internal task abort: task to dev %016llx task=%p " |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 1271 | "resp: 0x%x sts 0x%x\n", |
| 1272 | SAS_ADDR(device->sas_addr), |
| 1273 | task, |
| 1274 | task->task_status.resp, /* 0 is complete, -1 is undelivered */ |
| 1275 | task->task_status.stat); |
| 1276 | sas_free_task(task); |
| 1277 | |
| 1278 | return res; |
| 1279 | } |
| 1280 | |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 1281 | static void hisi_sas_port_formed(struct asd_sas_phy *sas_phy) |
| 1282 | { |
| 1283 | hisi_sas_port_notify_formed(sas_phy); |
| 1284 | } |
| 1285 | |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 1286 | static void hisi_sas_phy_disconnected(struct hisi_sas_phy *phy) |
| 1287 | { |
| 1288 | phy->phy_attached = 0; |
| 1289 | phy->phy_type = 0; |
| 1290 | phy->port = NULL; |
| 1291 | } |
| 1292 | |
| 1293 | void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy) |
| 1294 | { |
| 1295 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; |
| 1296 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
| 1297 | struct sas_ha_struct *sas_ha = &hisi_hba->sha; |
| 1298 | |
| 1299 | if (rdy) { |
| 1300 | /* Phy down but ready */ |
| 1301 | hisi_sas_bytes_dmaed(hisi_hba, phy_no); |
| 1302 | hisi_sas_port_notify_formed(sas_phy); |
| 1303 | } else { |
| 1304 | struct hisi_sas_port *port = phy->port; |
| 1305 | |
| 1306 | /* Phy down and not ready */ |
| 1307 | sas_ha->notify_phy_event(sas_phy, PHYE_LOSS_OF_SIGNAL); |
| 1308 | sas_phy_disconnected(sas_phy); |
| 1309 | |
| 1310 | if (port) { |
| 1311 | if (phy->phy_type & PORT_TYPE_SAS) { |
| 1312 | int port_id = port->id; |
| 1313 | |
| 1314 | if (!hisi_hba->hw->get_wideport_bitmap(hisi_hba, |
| 1315 | port_id)) |
| 1316 | port->port_attached = 0; |
| 1317 | } else if (phy->phy_type & PORT_TYPE_SATA) |
| 1318 | port->port_attached = 0; |
| 1319 | } |
| 1320 | hisi_sas_phy_disconnected(phy); |
| 1321 | } |
| 1322 | } |
| 1323 | EXPORT_SYMBOL_GPL(hisi_sas_phy_down); |
| 1324 | |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1325 | void hisi_sas_rescan_topology(struct hisi_hba *hisi_hba, u32 old_state, |
| 1326 | u32 state) |
| 1327 | { |
| 1328 | struct sas_ha_struct *sas_ha = &hisi_hba->sha; |
| 1329 | int phy_no; |
| 1330 | |
| 1331 | for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) { |
| 1332 | struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; |
| 1333 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
| 1334 | struct asd_sas_port *sas_port = sas_phy->port; |
| 1335 | struct domain_device *dev; |
| 1336 | |
| 1337 | if (sas_phy->enabled) { |
| 1338 | /* Report PHY state change to libsas */ |
| 1339 | if (state & (1 << phy_no)) |
| 1340 | continue; |
| 1341 | |
| 1342 | if (old_state & (1 << phy_no)) |
| 1343 | /* PHY down but was up before */ |
| 1344 | hisi_sas_phy_down(hisi_hba, phy_no, 0); |
| 1345 | } |
| 1346 | if (!sas_port) |
| 1347 | continue; |
| 1348 | dev = sas_port->port_dev; |
| 1349 | |
| 1350 | if (DEV_IS_EXPANDER(dev->dev_type)) |
| 1351 | sas_ha->notify_phy_event(sas_phy, PORTE_BROADCAST_RCVD); |
| 1352 | } |
| 1353 | } |
| 1354 | EXPORT_SYMBOL_GPL(hisi_sas_rescan_topology); |
| 1355 | |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 1356 | static struct scsi_transport_template *hisi_sas_stt; |
| 1357 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1358 | static struct scsi_host_template hisi_sas_sht = { |
| 1359 | .module = THIS_MODULE, |
| 1360 | .name = DRV_NAME, |
| 1361 | .queuecommand = sas_queuecommand, |
| 1362 | .target_alloc = sas_target_alloc, |
John Garry | 31eec8a | 2016-02-25 17:42:14 +0800 | [diff] [blame] | 1363 | .slave_configure = hisi_sas_slave_configure, |
John Garry | 701f75e | 2015-11-18 00:50:55 +0800 | [diff] [blame] | 1364 | .scan_finished = hisi_sas_scan_finished, |
| 1365 | .scan_start = hisi_sas_scan_start, |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1366 | .change_queue_depth = sas_change_queue_depth, |
| 1367 | .bios_param = sas_bios_param, |
| 1368 | .can_queue = 1, |
| 1369 | .this_id = -1, |
| 1370 | .sg_tablesize = SG_ALL, |
| 1371 | .max_sectors = SCSI_DEFAULT_MAX_SECTORS, |
| 1372 | .use_clustering = ENABLE_CLUSTERING, |
| 1373 | .eh_device_reset_handler = sas_eh_device_reset_handler, |
| 1374 | .eh_bus_reset_handler = sas_eh_bus_reset_handler, |
| 1375 | .target_destroy = sas_target_destroy, |
| 1376 | .ioctl = sas_ioctl, |
| 1377 | }; |
| 1378 | |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 1379 | static struct sas_domain_function_template hisi_sas_transport_ops = { |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 1380 | .lldd_dev_found = hisi_sas_dev_found, |
| 1381 | .lldd_dev_gone = hisi_sas_dev_gone, |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 1382 | .lldd_execute_task = hisi_sas_queue_command, |
John Garry | e4189d5 | 2015-11-18 00:50:57 +0800 | [diff] [blame] | 1383 | .lldd_control_phy = hisi_sas_control_phy, |
John Garry | 0efff30 | 2015-11-18 00:50:56 +0800 | [diff] [blame] | 1384 | .lldd_abort_task = hisi_sas_abort_task, |
| 1385 | .lldd_abort_task_set = hisi_sas_abort_task_set, |
| 1386 | .lldd_clear_aca = hisi_sas_clear_aca, |
| 1387 | .lldd_I_T_nexus_reset = hisi_sas_I_T_nexus_reset, |
| 1388 | .lldd_lu_reset = hisi_sas_lu_reset, |
| 1389 | .lldd_query_task = hisi_sas_query_task, |
John Garry | 8b05ad6 | 2017-03-23 01:25:35 +0800 | [diff] [blame] | 1390 | .lldd_clear_nexus_ha = hisi_sas_clear_nexus_ha, |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 1391 | .lldd_port_formed = hisi_sas_port_formed, |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 1392 | }; |
| 1393 | |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1394 | void hisi_sas_init_mem(struct hisi_hba *hisi_hba) |
| 1395 | { |
| 1396 | int i, s, max_command_entries = hisi_hba->hw->max_command_entries; |
| 1397 | |
| 1398 | for (i = 0; i < hisi_hba->queue_count; i++) { |
| 1399 | struct hisi_sas_cq *cq = &hisi_hba->cq[i]; |
| 1400 | struct hisi_sas_dq *dq = &hisi_hba->dq[i]; |
| 1401 | |
| 1402 | s = sizeof(struct hisi_sas_cmd_hdr) * HISI_SAS_QUEUE_SLOTS; |
| 1403 | memset(hisi_hba->cmd_hdr[i], 0, s); |
| 1404 | dq->wr_point = 0; |
| 1405 | |
| 1406 | s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS; |
| 1407 | memset(hisi_hba->complete_hdr[i], 0, s); |
| 1408 | cq->rd_point = 0; |
| 1409 | } |
| 1410 | |
| 1411 | s = sizeof(struct hisi_sas_initial_fis) * hisi_hba->n_phy; |
| 1412 | memset(hisi_hba->initial_fis, 0, s); |
| 1413 | |
| 1414 | s = max_command_entries * sizeof(struct hisi_sas_iost); |
| 1415 | memset(hisi_hba->iost, 0, s); |
| 1416 | |
| 1417 | s = max_command_entries * sizeof(struct hisi_sas_breakpoint); |
| 1418 | memset(hisi_hba->breakpoint, 0, s); |
| 1419 | |
| 1420 | s = max_command_entries * sizeof(struct hisi_sas_breakpoint) * 2; |
| 1421 | memset(hisi_hba->sata_breakpoint, 0, s); |
| 1422 | } |
| 1423 | EXPORT_SYMBOL_GPL(hisi_sas_init_mem); |
| 1424 | |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1425 | static int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost) |
| 1426 | { |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1427 | struct platform_device *pdev = hisi_hba->pdev; |
| 1428 | struct device *dev = &pdev->dev; |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1429 | int i, s, max_command_entries = hisi_hba->hw->max_command_entries; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1430 | |
John Garry | fa42d80 | 2015-11-18 00:50:43 +0800 | [diff] [blame] | 1431 | spin_lock_init(&hisi_hba->lock); |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 1432 | for (i = 0; i < hisi_hba->n_phy; i++) { |
| 1433 | hisi_sas_phy_init(hisi_hba, i); |
| 1434 | hisi_hba->port[i].port_attached = 0; |
| 1435 | hisi_hba->port[i].id = -1; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 1436 | } |
| 1437 | |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 1438 | for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) { |
| 1439 | hisi_hba->devices[i].dev_type = SAS_PHY_UNUSED; |
| 1440 | hisi_hba->devices[i].device_id = i; |
| 1441 | hisi_hba->devices[i].dev_status = HISI_SAS_DEV_NORMAL; |
| 1442 | } |
| 1443 | |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1444 | for (i = 0; i < hisi_hba->queue_count; i++) { |
John Garry | 9101a07 | 2015-11-18 00:50:37 +0800 | [diff] [blame] | 1445 | struct hisi_sas_cq *cq = &hisi_hba->cq[i]; |
John Garry | 4fde02a | 2016-09-06 23:36:12 +0800 | [diff] [blame] | 1446 | struct hisi_sas_dq *dq = &hisi_hba->dq[i]; |
John Garry | 9101a07 | 2015-11-18 00:50:37 +0800 | [diff] [blame] | 1447 | |
| 1448 | /* Completion queue structure */ |
| 1449 | cq->id = i; |
| 1450 | cq->hisi_hba = hisi_hba; |
| 1451 | |
John Garry | 4fde02a | 2016-09-06 23:36:12 +0800 | [diff] [blame] | 1452 | /* Delivery queue structure */ |
| 1453 | dq->id = i; |
| 1454 | dq->hisi_hba = hisi_hba; |
| 1455 | |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1456 | /* Delivery queue */ |
| 1457 | s = sizeof(struct hisi_sas_cmd_hdr) * HISI_SAS_QUEUE_SLOTS; |
| 1458 | hisi_hba->cmd_hdr[i] = dma_alloc_coherent(dev, s, |
| 1459 | &hisi_hba->cmd_hdr_dma[i], GFP_KERNEL); |
| 1460 | if (!hisi_hba->cmd_hdr[i]) |
| 1461 | goto err_out; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1462 | |
| 1463 | /* Completion queue */ |
| 1464 | s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS; |
| 1465 | hisi_hba->complete_hdr[i] = dma_alloc_coherent(dev, s, |
| 1466 | &hisi_hba->complete_hdr_dma[i], GFP_KERNEL); |
| 1467 | if (!hisi_hba->complete_hdr[i]) |
| 1468 | goto err_out; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | s = HISI_SAS_STATUS_BUF_SZ; |
| 1472 | hisi_hba->status_buffer_pool = dma_pool_create("status_buffer", |
| 1473 | dev, s, 16, 0); |
| 1474 | if (!hisi_hba->status_buffer_pool) |
| 1475 | goto err_out; |
| 1476 | |
| 1477 | s = HISI_SAS_COMMAND_TABLE_SZ; |
| 1478 | hisi_hba->command_table_pool = dma_pool_create("command_table", |
| 1479 | dev, s, 16, 0); |
| 1480 | if (!hisi_hba->command_table_pool) |
| 1481 | goto err_out; |
| 1482 | |
| 1483 | s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_itct); |
| 1484 | hisi_hba->itct = dma_alloc_coherent(dev, s, &hisi_hba->itct_dma, |
| 1485 | GFP_KERNEL); |
| 1486 | if (!hisi_hba->itct) |
| 1487 | goto err_out; |
| 1488 | |
| 1489 | memset(hisi_hba->itct, 0, s); |
| 1490 | |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1491 | hisi_hba->slot_info = devm_kcalloc(dev, max_command_entries, |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1492 | sizeof(struct hisi_sas_slot), |
| 1493 | GFP_KERNEL); |
| 1494 | if (!hisi_hba->slot_info) |
| 1495 | goto err_out; |
| 1496 | |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1497 | s = max_command_entries * sizeof(struct hisi_sas_iost); |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1498 | hisi_hba->iost = dma_alloc_coherent(dev, s, &hisi_hba->iost_dma, |
| 1499 | GFP_KERNEL); |
| 1500 | if (!hisi_hba->iost) |
| 1501 | goto err_out; |
| 1502 | |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1503 | s = max_command_entries * sizeof(struct hisi_sas_breakpoint); |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1504 | hisi_hba->breakpoint = dma_alloc_coherent(dev, s, |
| 1505 | &hisi_hba->breakpoint_dma, GFP_KERNEL); |
| 1506 | if (!hisi_hba->breakpoint) |
| 1507 | goto err_out; |
| 1508 | |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1509 | hisi_hba->slot_index_count = max_command_entries; |
John Garry | 433f569 | 2016-09-06 23:36:15 +0800 | [diff] [blame] | 1510 | s = hisi_hba->slot_index_count / BITS_PER_BYTE; |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 1511 | hisi_hba->slot_index_tags = devm_kzalloc(dev, s, GFP_KERNEL); |
| 1512 | if (!hisi_hba->slot_index_tags) |
| 1513 | goto err_out; |
| 1514 | |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1515 | hisi_hba->sge_page_pool = dma_pool_create("status_sge", dev, |
| 1516 | sizeof(struct hisi_sas_sge_page), 16, 0); |
| 1517 | if (!hisi_hba->sge_page_pool) |
| 1518 | goto err_out; |
| 1519 | |
| 1520 | s = sizeof(struct hisi_sas_initial_fis) * HISI_SAS_MAX_PHYS; |
| 1521 | hisi_hba->initial_fis = dma_alloc_coherent(dev, s, |
| 1522 | &hisi_hba->initial_fis_dma, GFP_KERNEL); |
| 1523 | if (!hisi_hba->initial_fis) |
| 1524 | goto err_out; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1525 | |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1526 | s = max_command_entries * sizeof(struct hisi_sas_breakpoint) * 2; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1527 | hisi_hba->sata_breakpoint = dma_alloc_coherent(dev, s, |
| 1528 | &hisi_hba->sata_breakpoint_dma, GFP_KERNEL); |
| 1529 | if (!hisi_hba->sata_breakpoint) |
| 1530 | goto err_out; |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1531 | hisi_sas_init_mem(hisi_hba); |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1532 | |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 1533 | hisi_sas_slot_index_init(hisi_hba); |
| 1534 | |
John Garry | 7e9080e | 2015-11-18 00:50:40 +0800 | [diff] [blame] | 1535 | hisi_hba->wq = create_singlethread_workqueue(dev_name(dev)); |
| 1536 | if (!hisi_hba->wq) { |
| 1537 | dev_err(dev, "sas_alloc: failed to create workqueue\n"); |
| 1538 | goto err_out; |
| 1539 | } |
| 1540 | |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1541 | return 0; |
| 1542 | err_out: |
| 1543 | return -ENOMEM; |
| 1544 | } |
| 1545 | |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1546 | static void hisi_sas_free(struct hisi_hba *hisi_hba) |
| 1547 | { |
| 1548 | struct device *dev = &hisi_hba->pdev->dev; |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1549 | int i, s, max_command_entries = hisi_hba->hw->max_command_entries; |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1550 | |
| 1551 | for (i = 0; i < hisi_hba->queue_count; i++) { |
| 1552 | s = sizeof(struct hisi_sas_cmd_hdr) * HISI_SAS_QUEUE_SLOTS; |
| 1553 | if (hisi_hba->cmd_hdr[i]) |
| 1554 | dma_free_coherent(dev, s, |
| 1555 | hisi_hba->cmd_hdr[i], |
| 1556 | hisi_hba->cmd_hdr_dma[i]); |
| 1557 | |
| 1558 | s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS; |
| 1559 | if (hisi_hba->complete_hdr[i]) |
| 1560 | dma_free_coherent(dev, s, |
| 1561 | hisi_hba->complete_hdr[i], |
| 1562 | hisi_hba->complete_hdr_dma[i]); |
| 1563 | } |
| 1564 | |
| 1565 | dma_pool_destroy(hisi_hba->status_buffer_pool); |
| 1566 | dma_pool_destroy(hisi_hba->command_table_pool); |
| 1567 | dma_pool_destroy(hisi_hba->sge_page_pool); |
| 1568 | |
| 1569 | s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_itct); |
| 1570 | if (hisi_hba->itct) |
| 1571 | dma_free_coherent(dev, s, |
| 1572 | hisi_hba->itct, hisi_hba->itct_dma); |
| 1573 | |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1574 | s = max_command_entries * sizeof(struct hisi_sas_iost); |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1575 | if (hisi_hba->iost) |
| 1576 | dma_free_coherent(dev, s, |
| 1577 | hisi_hba->iost, hisi_hba->iost_dma); |
| 1578 | |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1579 | s = max_command_entries * sizeof(struct hisi_sas_breakpoint); |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1580 | if (hisi_hba->breakpoint) |
| 1581 | dma_free_coherent(dev, s, |
| 1582 | hisi_hba->breakpoint, |
| 1583 | hisi_hba->breakpoint_dma); |
| 1584 | |
| 1585 | |
| 1586 | s = sizeof(struct hisi_sas_initial_fis) * HISI_SAS_MAX_PHYS; |
| 1587 | if (hisi_hba->initial_fis) |
| 1588 | dma_free_coherent(dev, s, |
| 1589 | hisi_hba->initial_fis, |
| 1590 | hisi_hba->initial_fis_dma); |
| 1591 | |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 1592 | s = max_command_entries * sizeof(struct hisi_sas_breakpoint) * 2; |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1593 | if (hisi_hba->sata_breakpoint) |
| 1594 | dma_free_coherent(dev, s, |
| 1595 | hisi_hba->sata_breakpoint, |
| 1596 | hisi_hba->sata_breakpoint_dma); |
| 1597 | |
John Garry | 7e9080e | 2015-11-18 00:50:40 +0800 | [diff] [blame] | 1598 | if (hisi_hba->wq) |
| 1599 | destroy_workqueue(hisi_hba->wq); |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1600 | } |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1601 | |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1602 | static void hisi_sas_rst_work_handler(struct work_struct *work) |
| 1603 | { |
| 1604 | struct hisi_hba *hisi_hba = |
| 1605 | container_of(work, struct hisi_hba, rst_work); |
| 1606 | |
| 1607 | hisi_sas_controller_reset(hisi_hba); |
| 1608 | } |
| 1609 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1610 | static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device *pdev, |
| 1611 | const struct hisi_sas_hw *hw) |
| 1612 | { |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 1613 | struct resource *res; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1614 | struct Scsi_Host *shost; |
| 1615 | struct hisi_hba *hisi_hba; |
| 1616 | struct device *dev = &pdev->dev; |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 1617 | struct device_node *np = pdev->dev.of_node; |
John Garry | 3bc45af | 2016-10-04 19:11:11 +0800 | [diff] [blame] | 1618 | struct clk *refclk; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1619 | |
| 1620 | shost = scsi_host_alloc(&hisi_sas_sht, sizeof(*hisi_hba)); |
Xiaofei Tan | d37a008 | 2016-11-29 23:45:57 +0800 | [diff] [blame] | 1621 | if (!shost) { |
| 1622 | dev_err(dev, "scsi host alloc failed\n"); |
| 1623 | return NULL; |
| 1624 | } |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1625 | hisi_hba = shost_priv(shost); |
| 1626 | |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 1627 | INIT_WORK(&hisi_hba->rst_work, hisi_sas_rst_work_handler); |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1628 | hisi_hba->hw = hw; |
| 1629 | hisi_hba->pdev = pdev; |
| 1630 | hisi_hba->shost = shost; |
| 1631 | SHOST_TO_SAS_HA(shost) = &hisi_hba->sha; |
| 1632 | |
John Garry | fa42d80 | 2015-11-18 00:50:43 +0800 | [diff] [blame] | 1633 | init_timer(&hisi_hba->timer); |
| 1634 | |
John Garry | 4d558c7 | 2016-02-04 02:26:08 +0800 | [diff] [blame] | 1635 | if (device_property_read_u8_array(dev, "sas-addr", hisi_hba->sas_addr, |
| 1636 | SAS_ADDR_SIZE)) |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 1637 | goto err_out; |
| 1638 | |
John Garry | 4d558c7 | 2016-02-04 02:26:08 +0800 | [diff] [blame] | 1639 | if (np) { |
| 1640 | hisi_hba->ctrl = syscon_regmap_lookup_by_phandle(np, |
| 1641 | "hisilicon,sas-syscon"); |
| 1642 | if (IS_ERR(hisi_hba->ctrl)) |
| 1643 | goto err_out; |
| 1644 | |
| 1645 | if (device_property_read_u32(dev, "ctrl-reset-reg", |
| 1646 | &hisi_hba->ctrl_reset_reg)) |
| 1647 | goto err_out; |
| 1648 | |
| 1649 | if (device_property_read_u32(dev, "ctrl-reset-sts-reg", |
| 1650 | &hisi_hba->ctrl_reset_sts_reg)) |
| 1651 | goto err_out; |
| 1652 | |
| 1653 | if (device_property_read_u32(dev, "ctrl-clock-ena-reg", |
| 1654 | &hisi_hba->ctrl_clock_ena_reg)) |
| 1655 | goto err_out; |
| 1656 | } |
| 1657 | |
John Garry | 3bc45af | 2016-10-04 19:11:11 +0800 | [diff] [blame] | 1658 | refclk = devm_clk_get(&pdev->dev, NULL); |
| 1659 | if (IS_ERR(refclk)) |
John Garry | 87e287c | 2017-01-20 20:45:20 +0800 | [diff] [blame] | 1660 | dev_dbg(dev, "no ref clk property\n"); |
John Garry | 3bc45af | 2016-10-04 19:11:11 +0800 | [diff] [blame] | 1661 | else |
| 1662 | hisi_hba->refclk_frequency_mhz = clk_get_rate(refclk) / 1000000; |
| 1663 | |
John Garry | 4d558c7 | 2016-02-04 02:26:08 +0800 | [diff] [blame] | 1664 | if (device_property_read_u32(dev, "phy-count", &hisi_hba->n_phy)) |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 1665 | goto err_out; |
| 1666 | |
John Garry | 4d558c7 | 2016-02-04 02:26:08 +0800 | [diff] [blame] | 1667 | if (device_property_read_u32(dev, "queue-count", |
| 1668 | &hisi_hba->queue_count)) |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 1669 | goto err_out; |
| 1670 | |
John Garry | a6f2c7f | 2016-09-06 23:36:19 +0800 | [diff] [blame] | 1671 | if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) && |
| 1672 | dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32))) { |
| 1673 | dev_err(dev, "No usable DMA addressing method\n"); |
| 1674 | goto err_out; |
| 1675 | } |
| 1676 | |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 1677 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1678 | hisi_hba->regs = devm_ioremap_resource(dev, res); |
| 1679 | if (IS_ERR(hisi_hba->regs)) |
| 1680 | goto err_out; |
| 1681 | |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1682 | if (hisi_sas_alloc(hisi_hba, shost)) { |
| 1683 | hisi_sas_free(hisi_hba); |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1684 | goto err_out; |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1685 | } |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 1686 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1687 | return shost; |
| 1688 | err_out: |
Xiaofei Tan | d37a008 | 2016-11-29 23:45:57 +0800 | [diff] [blame] | 1689 | kfree(shost); |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1690 | dev_err(dev, "shost alloc failed\n"); |
| 1691 | return NULL; |
| 1692 | } |
| 1693 | |
John Garry | 5d74242 | 2015-11-18 00:50:38 +0800 | [diff] [blame] | 1694 | static void hisi_sas_init_add(struct hisi_hba *hisi_hba) |
| 1695 | { |
| 1696 | int i; |
| 1697 | |
| 1698 | for (i = 0; i < hisi_hba->n_phy; i++) |
| 1699 | memcpy(&hisi_hba->phy[i].dev_sas_addr, |
| 1700 | hisi_hba->sas_addr, |
| 1701 | SAS_ADDR_SIZE); |
| 1702 | } |
| 1703 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1704 | int hisi_sas_probe(struct platform_device *pdev, |
| 1705 | const struct hisi_sas_hw *hw) |
| 1706 | { |
| 1707 | struct Scsi_Host *shost; |
| 1708 | struct hisi_hba *hisi_hba; |
| 1709 | struct device *dev = &pdev->dev; |
| 1710 | struct asd_sas_phy **arr_phy; |
| 1711 | struct asd_sas_port **arr_port; |
| 1712 | struct sas_ha_struct *sha; |
| 1713 | int rc, phy_nr, port_nr, i; |
| 1714 | |
| 1715 | shost = hisi_sas_shost_alloc(pdev, hw); |
Xiaofei Tan | d37a008 | 2016-11-29 23:45:57 +0800 | [diff] [blame] | 1716 | if (!shost) |
| 1717 | return -ENOMEM; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1718 | |
| 1719 | sha = SHOST_TO_SAS_HA(shost); |
| 1720 | hisi_hba = shost_priv(shost); |
| 1721 | platform_set_drvdata(pdev, sha); |
John Garry | 50cb916 | 2015-11-18 00:50:39 +0800 | [diff] [blame] | 1722 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1723 | phy_nr = port_nr = hisi_hba->n_phy; |
| 1724 | |
| 1725 | arr_phy = devm_kcalloc(dev, phy_nr, sizeof(void *), GFP_KERNEL); |
| 1726 | arr_port = devm_kcalloc(dev, port_nr, sizeof(void *), GFP_KERNEL); |
Xiaofei Tan | d37a008 | 2016-11-29 23:45:57 +0800 | [diff] [blame] | 1727 | if (!arr_phy || !arr_port) { |
| 1728 | rc = -ENOMEM; |
| 1729 | goto err_out_ha; |
| 1730 | } |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1731 | |
| 1732 | sha->sas_phy = arr_phy; |
| 1733 | sha->sas_port = arr_port; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1734 | sha->lldd_ha = hisi_hba; |
| 1735 | |
| 1736 | shost->transportt = hisi_sas_stt; |
| 1737 | shost->max_id = HISI_SAS_MAX_DEVICES; |
| 1738 | shost->max_lun = ~0; |
| 1739 | shost->max_channel = 1; |
| 1740 | shost->max_cmd_len = 16; |
| 1741 | 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] | 1742 | shost->can_queue = hisi_hba->hw->max_command_entries; |
| 1743 | shost->cmd_per_lun = hisi_hba->hw->max_command_entries; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1744 | |
| 1745 | sha->sas_ha_name = DRV_NAME; |
| 1746 | sha->dev = &hisi_hba->pdev->dev; |
| 1747 | sha->lldd_module = THIS_MODULE; |
| 1748 | sha->sas_addr = &hisi_hba->sas_addr[0]; |
| 1749 | sha->num_phys = hisi_hba->n_phy; |
| 1750 | sha->core.shost = hisi_hba->shost; |
| 1751 | |
| 1752 | for (i = 0; i < hisi_hba->n_phy; i++) { |
| 1753 | sha->sas_phy[i] = &hisi_hba->phy[i].sas_phy; |
| 1754 | sha->sas_port[i] = &hisi_hba->port[i].sas_port; |
| 1755 | } |
| 1756 | |
John Garry | 5d74242 | 2015-11-18 00:50:38 +0800 | [diff] [blame] | 1757 | hisi_sas_init_add(hisi_hba); |
| 1758 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1759 | rc = scsi_add_host(shost, &pdev->dev); |
| 1760 | if (rc) |
| 1761 | goto err_out_ha; |
| 1762 | |
| 1763 | rc = sas_register_ha(sha); |
| 1764 | if (rc) |
| 1765 | goto err_out_register_ha; |
| 1766 | |
Xiang Chen | 0757f04 | 2017-01-20 20:45:23 +0800 | [diff] [blame] | 1767 | rc = hisi_hba->hw->hw_init(hisi_hba); |
| 1768 | if (rc) |
| 1769 | goto err_out_register_ha; |
| 1770 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1771 | scsi_scan_host(shost); |
| 1772 | |
| 1773 | return 0; |
| 1774 | |
| 1775 | err_out_register_ha: |
| 1776 | scsi_remove_host(shost); |
| 1777 | err_out_ha: |
Xiaofei Tan | d37a008 | 2016-11-29 23:45:57 +0800 | [diff] [blame] | 1778 | hisi_sas_free(hisi_hba); |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 1779 | kfree(shost); |
| 1780 | return rc; |
| 1781 | } |
| 1782 | EXPORT_SYMBOL_GPL(hisi_sas_probe); |
| 1783 | |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1784 | int hisi_sas_remove(struct platform_device *pdev) |
| 1785 | { |
| 1786 | struct sas_ha_struct *sha = platform_get_drvdata(pdev); |
| 1787 | struct hisi_hba *hisi_hba = sha->lldd_ha; |
Xiaofei Tan | d37a008 | 2016-11-29 23:45:57 +0800 | [diff] [blame] | 1788 | struct Scsi_Host *shost = sha->core.shost; |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1789 | |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1790 | sas_unregister_ha(sha); |
| 1791 | sas_remove_host(sha->core.shost); |
| 1792 | |
| 1793 | hisi_sas_free(hisi_hba); |
Xiaofei Tan | d37a008 | 2016-11-29 23:45:57 +0800 | [diff] [blame] | 1794 | kfree(shost); |
John Garry | 89d5332 | 2015-11-18 00:50:35 +0800 | [diff] [blame] | 1795 | return 0; |
| 1796 | } |
| 1797 | EXPORT_SYMBOL_GPL(hisi_sas_remove); |
| 1798 | |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 1799 | static __init int hisi_sas_init(void) |
| 1800 | { |
| 1801 | pr_info("hisi_sas: driver version %s\n", DRV_VERSION); |
| 1802 | |
| 1803 | hisi_sas_stt = sas_domain_attach_transport(&hisi_sas_transport_ops); |
| 1804 | if (!hisi_sas_stt) |
| 1805 | return -ENOMEM; |
| 1806 | |
| 1807 | return 0; |
| 1808 | } |
| 1809 | |
| 1810 | static __exit void hisi_sas_exit(void) |
| 1811 | { |
| 1812 | sas_release_transport(hisi_sas_stt); |
| 1813 | } |
| 1814 | |
| 1815 | module_init(hisi_sas_init); |
| 1816 | module_exit(hisi_sas_exit); |
| 1817 | |
| 1818 | MODULE_VERSION(DRV_VERSION); |
| 1819 | MODULE_LICENSE("GPL"); |
| 1820 | MODULE_AUTHOR("John Garry <john.garry@huawei.com>"); |
| 1821 | MODULE_DESCRIPTION("HISILICON SAS controller driver"); |
| 1822 | MODULE_ALIAS("platform:" DRV_NAME); |