jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1 | /* |
Sakthivel K | f586099 | 2013-04-17 16:37:02 +0530 | [diff] [blame] | 2 | * PMC-Sierra PM8001/8081/8088/8089 SAS/SATA based host adapters driver |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 2008-2009 USI Co., Ltd. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions, and the following disclaimer, |
| 12 | * without modification. |
| 13 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 14 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 15 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 16 | * including a substantially similar Disclaimer requirement for further |
| 17 | * binary redistribution. |
| 18 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 19 | * of any contributors may be used to endorse or promote products derived |
| 20 | * from this software without specific prior written permission. |
| 21 | * |
| 22 | * Alternatively, this software may be distributed under the terms of the |
| 23 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 24 | * Software Foundation. |
| 25 | * |
| 26 | * NO WARRANTY |
| 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 30 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 31 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 35 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 36 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 37 | * POSSIBILITY OF SUCH DAMAGES. |
| 38 | * |
| 39 | */ |
| 40 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 41 | #include <linux/slab.h> |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 42 | #include "pm8001_sas.h" |
| 43 | |
| 44 | /** |
| 45 | * pm8001_find_tag - from sas task to find out tag that belongs to this task |
| 46 | * @task: the task sent to the LLDD |
| 47 | * @tag: the found tag associated with the task |
| 48 | */ |
| 49 | static int pm8001_find_tag(struct sas_task *task, u32 *tag) |
| 50 | { |
| 51 | if (task->lldd_task) { |
| 52 | struct pm8001_ccb_info *ccb; |
| 53 | ccb = task->lldd_task; |
| 54 | *tag = ccb->ccb_tag; |
| 55 | return 1; |
| 56 | } |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | /** |
Tomas Henzl | ef30054 | 2014-07-09 17:20:40 +0530 | [diff] [blame] | 61 | * pm8001_tag_free - free the no more needed tag |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 62 | * @pm8001_ha: our hba struct |
| 63 | * @tag: the found tag associated with the task |
| 64 | */ |
Tomas Henzl | ef30054 | 2014-07-09 17:20:40 +0530 | [diff] [blame] | 65 | void pm8001_tag_free(struct pm8001_hba_info *pm8001_ha, u32 tag) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 66 | { |
| 67 | void *bitmap = pm8001_ha->tags; |
| 68 | clear_bit(tag, bitmap); |
| 69 | } |
| 70 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 71 | /** |
| 72 | * pm8001_tag_alloc - allocate a empty tag for task used. |
| 73 | * @pm8001_ha: our hba struct |
| 74 | * @tag_out: the found empty tag . |
| 75 | */ |
| 76 | inline int pm8001_tag_alloc(struct pm8001_hba_info *pm8001_ha, u32 *tag_out) |
| 77 | { |
Tomas Henzl | ef30054 | 2014-07-09 17:20:40 +0530 | [diff] [blame] | 78 | unsigned int tag; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 79 | void *bitmap = pm8001_ha->tags; |
Tomas Henzl | 646cdf0 | 2014-07-09 17:21:01 +0530 | [diff] [blame] | 80 | unsigned long flags; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 81 | |
Tomas Henzl | 646cdf0 | 2014-07-09 17:21:01 +0530 | [diff] [blame] | 82 | spin_lock_irqsave(&pm8001_ha->bitmap_lock, flags); |
Tomas Henzl | ef30054 | 2014-07-09 17:20:40 +0530 | [diff] [blame] | 83 | tag = find_first_zero_bit(bitmap, pm8001_ha->tags_num); |
Tomas Henzl | 646cdf0 | 2014-07-09 17:21:01 +0530 | [diff] [blame] | 84 | if (tag >= pm8001_ha->tags_num) { |
| 85 | spin_unlock_irqrestore(&pm8001_ha->bitmap_lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 86 | return -SAS_QUEUE_FULL; |
Tomas Henzl | 646cdf0 | 2014-07-09 17:21:01 +0530 | [diff] [blame] | 87 | } |
Tomas Henzl | ef30054 | 2014-07-09 17:20:40 +0530 | [diff] [blame] | 88 | set_bit(tag, bitmap); |
Tomas Henzl | 646cdf0 | 2014-07-09 17:21:01 +0530 | [diff] [blame] | 89 | spin_unlock_irqrestore(&pm8001_ha->bitmap_lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 90 | *tag_out = tag; |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | void pm8001_tag_init(struct pm8001_hba_info *pm8001_ha) |
| 95 | { |
| 96 | int i; |
| 97 | for (i = 0; i < pm8001_ha->tags_num; ++i) |
Tomas Henzl | ef30054 | 2014-07-09 17:20:40 +0530 | [diff] [blame] | 98 | pm8001_tag_free(pm8001_ha, i); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /** |
| 102 | * pm8001_mem_alloc - allocate memory for pm8001. |
| 103 | * @pdev: pci device. |
| 104 | * @virt_addr: the allocated virtual address |
| 105 | * @pphys_addr_hi: the physical address high byte address. |
| 106 | * @pphys_addr_lo: the physical address low byte address. |
| 107 | * @mem_size: memory size. |
| 108 | */ |
| 109 | int pm8001_mem_alloc(struct pci_dev *pdev, void **virt_addr, |
| 110 | dma_addr_t *pphys_addr, u32 *pphys_addr_hi, |
| 111 | u32 *pphys_addr_lo, u32 mem_size, u32 align) |
| 112 | { |
| 113 | caddr_t mem_virt_alloc; |
| 114 | dma_addr_t mem_dma_handle; |
| 115 | u64 phys_align; |
| 116 | u64 align_offset = 0; |
| 117 | if (align) |
| 118 | align_offset = (dma_addr_t)align - 1; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 119 | mem_virt_alloc = dma_alloc_coherent(&pdev->dev, mem_size + align, |
| 120 | &mem_dma_handle, GFP_KERNEL); |
Zhen Lei | 4ee8c40 | 2021-06-10 17:46:05 +0800 | [diff] [blame^] | 121 | if (!mem_virt_alloc) |
| 122 | return -ENOMEM; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 123 | *pphys_addr = mem_dma_handle; |
| 124 | phys_align = (*pphys_addr + align_offset) & ~align_offset; |
| 125 | *virt_addr = (void *)mem_virt_alloc + phys_align - *pphys_addr; |
| 126 | *pphys_addr_hi = upper_32_bits(phys_align); |
| 127 | *pphys_addr_lo = lower_32_bits(phys_align); |
| 128 | return 0; |
| 129 | } |
Lee Jones | a0cf5ce | 2020-07-21 17:41:18 +0100 | [diff] [blame] | 130 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 131 | /** |
| 132 | * pm8001_find_ha_by_dev - from domain device which come from sas layer to |
| 133 | * find out our hba struct. |
| 134 | * @dev: the domain device which from sas layer. |
| 135 | */ |
| 136 | static |
| 137 | struct pm8001_hba_info *pm8001_find_ha_by_dev(struct domain_device *dev) |
| 138 | { |
| 139 | struct sas_ha_struct *sha = dev->port->ha; |
| 140 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; |
| 141 | return pm8001_ha; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * pm8001_phy_control - this function should be registered to |
| 146 | * sas_domain_function_template to provide libsas used, note: this is just |
| 147 | * control the HBA phy rather than other expander phy if you want control |
| 148 | * other phy, you should use SMP command. |
| 149 | * @sas_phy: which phy in HBA phys. |
| 150 | * @func: the operation. |
| 151 | * @funcdata: always NULL. |
| 152 | */ |
| 153 | int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func, |
| 154 | void *funcdata) |
| 155 | { |
| 156 | int rc = 0, phy_id = sas_phy->id; |
| 157 | struct pm8001_hba_info *pm8001_ha = NULL; |
| 158 | struct sas_phy_linkrates *rates; |
Deepak Ukey | cd13575 | 2018-09-11 14:18:02 +0530 | [diff] [blame] | 159 | struct pm8001_phy *phy; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 160 | DECLARE_COMPLETION_ONSTACK(completion); |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 161 | unsigned long flags; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 162 | pm8001_ha = sas_phy->ha->lldd_ha; |
Deepak Ukey | cd13575 | 2018-09-11 14:18:02 +0530 | [diff] [blame] | 163 | phy = &pm8001_ha->phy[phy_id]; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 164 | pm8001_ha->phy[phy_id].enable_completion = &completion; |
| 165 | switch (func) { |
| 166 | case PHY_FUNC_SET_LINK_RATE: |
| 167 | rates = funcdata; |
| 168 | if (rates->minimum_linkrate) { |
| 169 | pm8001_ha->phy[phy_id].minimum_linkrate = |
| 170 | rates->minimum_linkrate; |
| 171 | } |
| 172 | if (rates->maximum_linkrate) { |
| 173 | pm8001_ha->phy[phy_id].maximum_linkrate = |
| 174 | rates->maximum_linkrate; |
| 175 | } |
Deepak Ukey | cd13575 | 2018-09-11 14:18:02 +0530 | [diff] [blame] | 176 | if (pm8001_ha->phy[phy_id].phy_state == PHY_LINK_DISABLE) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 177 | PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id); |
| 178 | wait_for_completion(&completion); |
| 179 | } |
| 180 | PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id, |
| 181 | PHY_LINK_RESET); |
| 182 | break; |
| 183 | case PHY_FUNC_HARD_RESET: |
Deepak Ukey | cd13575 | 2018-09-11 14:18:02 +0530 | [diff] [blame] | 184 | if (pm8001_ha->phy[phy_id].phy_state == PHY_LINK_DISABLE) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 185 | PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id); |
| 186 | wait_for_completion(&completion); |
| 187 | } |
| 188 | PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id, |
| 189 | PHY_HARD_RESET); |
| 190 | break; |
| 191 | case PHY_FUNC_LINK_RESET: |
Deepak Ukey | cd13575 | 2018-09-11 14:18:02 +0530 | [diff] [blame] | 192 | if (pm8001_ha->phy[phy_id].phy_state == PHY_LINK_DISABLE) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 193 | PM8001_CHIP_DISP->phy_start_req(pm8001_ha, phy_id); |
| 194 | wait_for_completion(&completion); |
| 195 | } |
| 196 | PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id, |
| 197 | PHY_LINK_RESET); |
| 198 | break; |
| 199 | case PHY_FUNC_RELEASE_SPINUP_HOLD: |
| 200 | PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id, |
| 201 | PHY_LINK_RESET); |
| 202 | break; |
| 203 | case PHY_FUNC_DISABLE: |
Deepak Ukey | cd13575 | 2018-09-11 14:18:02 +0530 | [diff] [blame] | 204 | if (pm8001_ha->chip_id != chip_8001) { |
| 205 | if (pm8001_ha->phy[phy_id].phy_state == |
| 206 | PHY_STATE_LINK_UP_SPCV) { |
Deepak Ukey | cd13575 | 2018-09-11 14:18:02 +0530 | [diff] [blame] | 207 | sas_phy_disconnected(&phy->sas_phy); |
Ahmed S. Darwish | de6d754 | 2021-01-18 11:09:51 +0100 | [diff] [blame] | 208 | sas_notify_phy_event(&phy->sas_phy, |
Ahmed S. Darwish | cd4e817 | 2021-01-18 11:09:45 +0100 | [diff] [blame] | 209 | PHYE_LOSS_OF_SIGNAL, GFP_KERNEL); |
Deepak Ukey | cd13575 | 2018-09-11 14:18:02 +0530 | [diff] [blame] | 210 | phy->phy_attached = 0; |
| 211 | } |
| 212 | } else { |
| 213 | if (pm8001_ha->phy[phy_id].phy_state == |
| 214 | PHY_STATE_LINK_UP_SPC) { |
Deepak Ukey | cd13575 | 2018-09-11 14:18:02 +0530 | [diff] [blame] | 215 | sas_phy_disconnected(&phy->sas_phy); |
Ahmed S. Darwish | de6d754 | 2021-01-18 11:09:51 +0100 | [diff] [blame] | 216 | sas_notify_phy_event(&phy->sas_phy, |
Ahmed S. Darwish | cd4e817 | 2021-01-18 11:09:45 +0100 | [diff] [blame] | 217 | PHYE_LOSS_OF_SIGNAL, GFP_KERNEL); |
Deepak Ukey | cd13575 | 2018-09-11 14:18:02 +0530 | [diff] [blame] | 218 | phy->phy_attached = 0; |
| 219 | } |
| 220 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 221 | PM8001_CHIP_DISP->phy_stop_req(pm8001_ha, phy_id); |
| 222 | break; |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 223 | case PHY_FUNC_GET_EVENTS: |
| 224 | spin_lock_irqsave(&pm8001_ha->lock, flags); |
Sakthivel K | f586099 | 2013-04-17 16:37:02 +0530 | [diff] [blame] | 225 | if (pm8001_ha->chip_id == chip_8001) { |
| 226 | if (-1 == pm8001_bar4_shift(pm8001_ha, |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 227 | (phy_id < 4) ? 0x30000 : 0x40000)) { |
Sakthivel K | f586099 | 2013-04-17 16:37:02 +0530 | [diff] [blame] | 228 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
| 229 | return -EINVAL; |
| 230 | } |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 231 | } |
| 232 | { |
| 233 | struct sas_phy *phy = sas_phy->phy; |
| 234 | uint32_t *qp = (uint32_t *)(((char *) |
| 235 | pm8001_ha->io_mem[2].memvirtaddr) |
| 236 | + 0x1034 + (0x4000 * (phy_id & 3))); |
| 237 | |
| 238 | phy->invalid_dword_count = qp[0]; |
| 239 | phy->running_disparity_error_count = qp[1]; |
| 240 | phy->loss_of_dword_sync_count = qp[3]; |
| 241 | phy->phy_reset_problem_count = qp[4]; |
| 242 | } |
Sakthivel K | f586099 | 2013-04-17 16:37:02 +0530 | [diff] [blame] | 243 | if (pm8001_ha->chip_id == chip_8001) |
| 244 | pm8001_bar4_shift(pm8001_ha, 0); |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 245 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
| 246 | return 0; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 247 | default: |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 248 | pm8001_dbg(pm8001_ha, DEVIO, "func 0x%x\n", func); |
Mark Salyzyn | d95d000 | 2012-01-17 09:18:57 -0500 | [diff] [blame] | 249 | rc = -EOPNOTSUPP; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 250 | } |
| 251 | msleep(300); |
| 252 | return rc; |
| 253 | } |
| 254 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 255 | /** |
| 256 | * pm8001_scan_start - we should enable all HBA phys by sending the phy_start |
| 257 | * command to HBA. |
| 258 | * @shost: the scsi host data. |
| 259 | */ |
| 260 | void pm8001_scan_start(struct Scsi_Host *shost) |
| 261 | { |
| 262 | int i; |
| 263 | struct pm8001_hba_info *pm8001_ha; |
| 264 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
| 265 | pm8001_ha = sha->lldd_ha; |
Sakthivel K | f586099 | 2013-04-17 16:37:02 +0530 | [diff] [blame] | 266 | /* SAS_RE_INITIALIZATION not available in SPCv/ve */ |
| 267 | if (pm8001_ha->chip_id == chip_8001) |
| 268 | PM8001_CHIP_DISP->sas_re_init_req(pm8001_ha); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 269 | for (i = 0; i < pm8001_ha->chip->n_phy; ++i) |
| 270 | PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i); |
| 271 | } |
| 272 | |
| 273 | int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 274 | { |
Dan Williams | b1124cd | 2011-12-19 16:42:34 -0800 | [diff] [blame] | 275 | struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost); |
| 276 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 277 | /* give the phy enabling interrupt event time to come in (1s |
| 278 | * is empirically about all it takes) */ |
| 279 | if (time < HZ) |
| 280 | return 0; |
| 281 | /* Wait for discovery to finish */ |
Dan Williams | b1124cd | 2011-12-19 16:42:34 -0800 | [diff] [blame] | 282 | sas_drain_work(ha); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 283 | return 1; |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * pm8001_task_prep_smp - the dispatcher function, prepare data for smp task |
| 288 | * @pm8001_ha: our hba card information |
| 289 | * @ccb: the ccb which attached to smp task |
| 290 | */ |
| 291 | static int pm8001_task_prep_smp(struct pm8001_hba_info *pm8001_ha, |
| 292 | struct pm8001_ccb_info *ccb) |
| 293 | { |
| 294 | return PM8001_CHIP_DISP->smp_req(pm8001_ha, ccb); |
| 295 | } |
| 296 | |
| 297 | u32 pm8001_get_ncq_tag(struct sas_task *task, u32 *tag) |
| 298 | { |
| 299 | struct ata_queued_cmd *qc = task->uldd_task; |
| 300 | if (qc) { |
| 301 | if (qc->tf.command == ATA_CMD_FPDMA_WRITE || |
Hannes Reinecke | ef026b1 | 2016-04-25 12:45:44 +0200 | [diff] [blame] | 302 | qc->tf.command == ATA_CMD_FPDMA_READ || |
| 303 | qc->tf.command == ATA_CMD_FPDMA_RECV || |
Hannes Reinecke | 661ce1f | 2016-04-25 12:45:45 +0200 | [diff] [blame] | 304 | qc->tf.command == ATA_CMD_FPDMA_SEND || |
| 305 | qc->tf.command == ATA_CMD_NCQ_NON_DATA) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 306 | *tag = qc->tag; |
| 307 | return 1; |
| 308 | } |
| 309 | } |
| 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * pm8001_task_prep_ata - the dispatcher function, prepare data for sata task |
| 315 | * @pm8001_ha: our hba card information |
| 316 | * @ccb: the ccb which attached to sata task |
| 317 | */ |
| 318 | static int pm8001_task_prep_ata(struct pm8001_hba_info *pm8001_ha, |
| 319 | struct pm8001_ccb_info *ccb) |
| 320 | { |
| 321 | return PM8001_CHIP_DISP->sata_req(pm8001_ha, ccb); |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * pm8001_task_prep_ssp_tm - the dispatcher function, prepare task management data |
| 326 | * @pm8001_ha: our hba card information |
| 327 | * @ccb: the ccb which attached to TM |
| 328 | * @tmf: the task management IU |
| 329 | */ |
| 330 | static int pm8001_task_prep_ssp_tm(struct pm8001_hba_info *pm8001_ha, |
| 331 | struct pm8001_ccb_info *ccb, struct pm8001_tmf_task *tmf) |
| 332 | { |
| 333 | return PM8001_CHIP_DISP->ssp_tm_req(pm8001_ha, ccb, tmf); |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * pm8001_task_prep_ssp - the dispatcher function,prepare ssp data for ssp task |
| 338 | * @pm8001_ha: our hba card information |
| 339 | * @ccb: the ccb which attached to ssp task |
| 340 | */ |
| 341 | static int pm8001_task_prep_ssp(struct pm8001_hba_info *pm8001_ha, |
| 342 | struct pm8001_ccb_info *ccb) |
| 343 | { |
| 344 | return PM8001_CHIP_DISP->ssp_io_req(pm8001_ha, ccb); |
| 345 | } |
Dan Williams | 11e1636 | 2011-09-20 15:11:03 -0700 | [diff] [blame] | 346 | |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 347 | /* Find the local port id that's attached to this device */ |
| 348 | static int sas_find_local_port_id(struct domain_device *dev) |
| 349 | { |
| 350 | struct domain_device *pdev = dev->parent; |
| 351 | |
| 352 | /* Directly attached device */ |
| 353 | if (!pdev) |
| 354 | return dev->port->id; |
| 355 | while (pdev) { |
| 356 | struct domain_device *pdev_p = pdev->parent; |
| 357 | if (!pdev_p) |
| 358 | return pdev->port->id; |
| 359 | pdev = pdev->parent; |
| 360 | } |
| 361 | return 0; |
| 362 | } |
| 363 | |
Lee Jones | a0cf5ce | 2020-07-21 17:41:18 +0100 | [diff] [blame] | 364 | #define DEV_IS_GONE(pm8001_dev) \ |
| 365 | ((!pm8001_dev || (pm8001_dev->dev_type == SAS_PHY_UNUSED))) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 366 | /** |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 367 | * pm8001_task_exec - queue the task(ssp, smp && ata) to the hardware. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 368 | * @task: the task to be execute. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 369 | * @gfp_flags: gfp_flags. |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 370 | * @is_tmf: if it is task management task. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 371 | * @tmf: the task management IU |
| 372 | */ |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 373 | static int pm8001_task_exec(struct sas_task *task, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 374 | gfp_t gfp_flags, int is_tmf, struct pm8001_tmf_task *tmf) |
| 375 | { |
| 376 | struct domain_device *dev = task->dev; |
| 377 | struct pm8001_hba_info *pm8001_ha; |
| 378 | struct pm8001_device *pm8001_dev; |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 379 | struct pm8001_port *port = NULL; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 380 | struct sas_task *t = task; |
| 381 | struct pm8001_ccb_info *ccb; |
John Sperbeck | cef1538 | 2019-11-14 15:39:00 +0530 | [diff] [blame] | 382 | u32 tag = 0xdeadbeef, rc = 0, n_elem = 0; |
Dan Williams | 312d3e5 | 2011-11-17 17:59:50 -0800 | [diff] [blame] | 383 | unsigned long flags = 0; |
Vikram Auradkar | a88d9db | 2019-11-14 15:39:04 +0530 | [diff] [blame] | 384 | enum sas_protocol task_proto = t->task_proto; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 385 | |
| 386 | if (!dev->port) { |
| 387 | struct task_status_struct *tsm = &t->task_status; |
| 388 | tsm->resp = SAS_TASK_UNDELIVERED; |
| 389 | tsm->stat = SAS_PHY_DOWN; |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 390 | if (dev->dev_type != SAS_SATA_DEV) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 391 | t->task_done(t); |
| 392 | return 0; |
| 393 | } |
| 394 | pm8001_ha = pm8001_find_ha_by_dev(task->dev); |
Deepak Ukey | 72349b6 | 2018-09-11 14:18:04 +0530 | [diff] [blame] | 395 | if (pm8001_ha->controller_fatal_error) { |
| 396 | struct task_status_struct *ts = &t->task_status; |
| 397 | |
| 398 | ts->resp = SAS_TASK_UNDELIVERED; |
| 399 | t->task_done(t); |
| 400 | return 0; |
| 401 | } |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 402 | pm8001_dbg(pm8001_ha, IO, "pm8001_task_exec device\n"); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 403 | spin_lock_irqsave(&pm8001_ha->lock, flags); |
| 404 | do { |
| 405 | dev = t->dev; |
| 406 | pm8001_dev = dev->lldd_dev; |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 407 | port = &pm8001_ha->port[sas_find_local_port_id(dev)]; |
Mark Salyzyn | b90b378 | 2011-09-22 08:50:01 -0700 | [diff] [blame] | 408 | if (DEV_IS_GONE(pm8001_dev) || !port->port_attached) { |
Vikram Auradkar | a88d9db | 2019-11-14 15:39:04 +0530 | [diff] [blame] | 409 | if (sas_protocol_ata(task_proto)) { |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 410 | struct task_status_struct *ts = &t->task_status; |
| 411 | ts->resp = SAS_TASK_UNDELIVERED; |
| 412 | ts->stat = SAS_PHY_DOWN; |
| 413 | |
| 414 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 415 | t->task_done(t); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 416 | spin_lock_irqsave(&pm8001_ha->lock, flags); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 417 | continue; |
| 418 | } else { |
| 419 | struct task_status_struct *ts = &t->task_status; |
| 420 | ts->resp = SAS_TASK_UNDELIVERED; |
| 421 | ts->stat = SAS_PHY_DOWN; |
| 422 | t->task_done(t); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 423 | continue; |
| 424 | } |
| 425 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 426 | rc = pm8001_tag_alloc(pm8001_ha, &tag); |
| 427 | if (rc) |
| 428 | goto err_out; |
| 429 | ccb = &pm8001_ha->ccb_info[tag]; |
| 430 | |
Vikram Auradkar | a88d9db | 2019-11-14 15:39:04 +0530 | [diff] [blame] | 431 | if (!sas_protocol_ata(task_proto)) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 432 | if (t->num_scatter) { |
| 433 | n_elem = dma_map_sg(pm8001_ha->dev, |
| 434 | t->scatter, |
| 435 | t->num_scatter, |
| 436 | t->data_dir); |
| 437 | if (!n_elem) { |
| 438 | rc = -ENOMEM; |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 439 | goto err_out_tag; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | } else { |
| 443 | n_elem = t->num_scatter; |
| 444 | } |
| 445 | |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 446 | t->lldd_task = ccb; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 447 | ccb->n_elem = n_elem; |
| 448 | ccb->ccb_tag = tag; |
| 449 | ccb->task = t; |
XinHong Zhu | aed97b8 | 2014-02-14 16:01:28 +0800 | [diff] [blame] | 450 | ccb->device = pm8001_dev; |
Vikram Auradkar | a88d9db | 2019-11-14 15:39:04 +0530 | [diff] [blame] | 451 | switch (task_proto) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 452 | case SAS_PROTOCOL_SMP: |
Viswas G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 453 | atomic_inc(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 454 | rc = pm8001_task_prep_smp(pm8001_ha, ccb); |
| 455 | break; |
| 456 | case SAS_PROTOCOL_SSP: |
Viswas G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 457 | atomic_inc(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 458 | if (is_tmf) |
| 459 | rc = pm8001_task_prep_ssp_tm(pm8001_ha, |
| 460 | ccb, tmf); |
| 461 | else |
| 462 | rc = pm8001_task_prep_ssp(pm8001_ha, ccb); |
| 463 | break; |
| 464 | case SAS_PROTOCOL_SATA: |
| 465 | case SAS_PROTOCOL_STP: |
Viswas G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 466 | atomic_inc(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 467 | rc = pm8001_task_prep_ata(pm8001_ha, ccb); |
| 468 | break; |
| 469 | default: |
| 470 | dev_printk(KERN_ERR, pm8001_ha->dev, |
Vikram Auradkar | a88d9db | 2019-11-14 15:39:04 +0530 | [diff] [blame] | 471 | "unknown sas_task proto: 0x%x\n", task_proto); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 472 | rc = -EINVAL; |
| 473 | break; |
| 474 | } |
| 475 | |
| 476 | if (rc) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 477 | pm8001_dbg(pm8001_ha, IO, "rc is %x\n", rc); |
Viswas G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 478 | atomic_dec(&pm8001_dev->running_req); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 479 | goto err_out_tag; |
| 480 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 481 | /* TODO: select normal or high priority */ |
| 482 | spin_lock(&t->task_state_lock); |
| 483 | t->task_state_flags |= SAS_TASK_AT_INITIATOR; |
| 484 | spin_unlock(&t->task_state_lock); |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 485 | } while (0); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 486 | rc = 0; |
| 487 | goto out_done; |
| 488 | |
| 489 | err_out_tag: |
| 490 | pm8001_tag_free(pm8001_ha, tag); |
| 491 | err_out: |
| 492 | dev_printk(KERN_ERR, pm8001_ha->dev, "pm8001 exec failed[%d]!\n", rc); |
Vikram Auradkar | a88d9db | 2019-11-14 15:39:04 +0530 | [diff] [blame] | 493 | if (!sas_protocol_ata(task_proto)) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 494 | if (n_elem) |
Deepak Ukey | 76cb25b | 2018-09-11 14:18:03 +0530 | [diff] [blame] | 495 | dma_unmap_sg(pm8001_ha->dev, t->scatter, t->num_scatter, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 496 | t->data_dir); |
| 497 | out_done: |
| 498 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
| 499 | return rc; |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * pm8001_queue_command - register for upper layer used, all IO commands sent |
| 504 | * to HBA are from this interface. |
| 505 | * @task: the task to be execute. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 506 | * @gfp_flags: gfp_flags |
| 507 | */ |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 508 | int pm8001_queue_command(struct sas_task *task, gfp_t gfp_flags) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 509 | { |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 510 | return pm8001_task_exec(task, gfp_flags, 0, NULL); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 511 | } |
| 512 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 513 | /** |
| 514 | * pm8001_ccb_task_free - free the sg for ssp and smp command, free the ccb. |
| 515 | * @pm8001_ha: our hba card information |
| 516 | * @ccb: the ccb which attached to ssp task |
| 517 | * @task: the task to be free. |
| 518 | * @ccb_idx: ccb index. |
| 519 | */ |
| 520 | void pm8001_ccb_task_free(struct pm8001_hba_info *pm8001_ha, |
| 521 | struct sas_task *task, struct pm8001_ccb_info *ccb, u32 ccb_idx) |
| 522 | { |
| 523 | if (!ccb->task) |
| 524 | return; |
| 525 | if (!sas_protocol_ata(task->task_proto)) |
| 526 | if (ccb->n_elem) |
| 527 | dma_unmap_sg(pm8001_ha->dev, task->scatter, |
| 528 | task->num_scatter, task->data_dir); |
| 529 | |
| 530 | switch (task->task_proto) { |
| 531 | case SAS_PROTOCOL_SMP: |
| 532 | dma_unmap_sg(pm8001_ha->dev, &task->smp_task.smp_resp, 1, |
Christoph Hellwig | f73bdeb | 2018-10-10 19:59:50 +0200 | [diff] [blame] | 533 | DMA_FROM_DEVICE); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 534 | dma_unmap_sg(pm8001_ha->dev, &task->smp_task.smp_req, 1, |
Christoph Hellwig | f73bdeb | 2018-10-10 19:59:50 +0200 | [diff] [blame] | 535 | DMA_TO_DEVICE); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 536 | break; |
| 537 | |
| 538 | case SAS_PROTOCOL_SATA: |
| 539 | case SAS_PROTOCOL_STP: |
| 540 | case SAS_PROTOCOL_SSP: |
| 541 | default: |
| 542 | /* do nothing */ |
| 543 | break; |
| 544 | } |
| 545 | task->lldd_task = NULL; |
| 546 | ccb->task = NULL; |
| 547 | ccb->ccb_tag = 0xFFFFFFFF; |
Mark Salyzyn | 5954d73 | 2012-01-17 11:52:24 -0500 | [diff] [blame] | 548 | ccb->open_retry = 0; |
Tomas Henzl | ef30054 | 2014-07-09 17:20:40 +0530 | [diff] [blame] | 549 | pm8001_tag_free(pm8001_ha, ccb_idx); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | /** |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 553 | * pm8001_alloc_dev - find a empty pm8001_device |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 554 | * @pm8001_ha: our hba card information |
| 555 | */ |
Baoyou Xie | 7efa59e | 2016-09-23 21:54:22 +0800 | [diff] [blame] | 556 | static struct pm8001_device *pm8001_alloc_dev(struct pm8001_hba_info *pm8001_ha) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 557 | { |
| 558 | u32 dev; |
| 559 | for (dev = 0; dev < PM8001_MAX_DEVICES; dev++) { |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 560 | if (pm8001_ha->devices[dev].dev_type == SAS_PHY_UNUSED) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 561 | pm8001_ha->devices[dev].id = dev; |
| 562 | return &pm8001_ha->devices[dev]; |
| 563 | } |
| 564 | } |
| 565 | if (dev == PM8001_MAX_DEVICES) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 566 | pm8001_dbg(pm8001_ha, FAIL, |
| 567 | "max support %d devices, ignore ..\n", |
| 568 | PM8001_MAX_DEVICES); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 569 | } |
| 570 | return NULL; |
| 571 | } |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 572 | /** |
| 573 | * pm8001_find_dev - find a matching pm8001_device |
| 574 | * @pm8001_ha: our hba card information |
Lee Jones | a0cf5ce | 2020-07-21 17:41:18 +0100 | [diff] [blame] | 575 | * @device_id: device ID to match against |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 576 | */ |
| 577 | struct pm8001_device *pm8001_find_dev(struct pm8001_hba_info *pm8001_ha, |
| 578 | u32 device_id) |
| 579 | { |
| 580 | u32 dev; |
| 581 | for (dev = 0; dev < PM8001_MAX_DEVICES; dev++) { |
| 582 | if (pm8001_ha->devices[dev].device_id == device_id) |
| 583 | return &pm8001_ha->devices[dev]; |
| 584 | } |
| 585 | if (dev == PM8001_MAX_DEVICES) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 586 | pm8001_dbg(pm8001_ha, FAIL, "NO MATCHING DEVICE FOUND !!!\n"); |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 587 | } |
| 588 | return NULL; |
| 589 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 590 | |
Ruksar Devadi | 4f5deeb | 2021-04-15 16:03:50 +0530 | [diff] [blame] | 591 | void pm8001_free_dev(struct pm8001_device *pm8001_dev) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 592 | { |
| 593 | u32 id = pm8001_dev->id; |
| 594 | memset(pm8001_dev, 0, sizeof(*pm8001_dev)); |
| 595 | pm8001_dev->id = id; |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 596 | pm8001_dev->dev_type = SAS_PHY_UNUSED; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 597 | pm8001_dev->device_id = PM8001_MAX_DEVICES; |
| 598 | pm8001_dev->sas_device = NULL; |
| 599 | } |
| 600 | |
| 601 | /** |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 602 | * pm8001_dev_found_notify - libsas notify a device is found. |
| 603 | * @dev: the device structure which sas layer used. |
| 604 | * |
| 605 | * when libsas find a sas domain device, it should tell the LLDD that |
| 606 | * device is found, and then LLDD register this device to HBA firmware |
| 607 | * by the command "OPC_INB_REG_DEV", after that the HBA will assign a |
| 608 | * device ID(according to device's sas address) and returned it to LLDD. From |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 609 | * now on, we communicate with HBA FW with the device ID which HBA assigned |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 610 | * rather than sas address. it is the necessary step for our HBA but it is |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 611 | * the optional for other HBA driver. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 612 | */ |
| 613 | static int pm8001_dev_found_notify(struct domain_device *dev) |
| 614 | { |
| 615 | unsigned long flags = 0; |
| 616 | int res = 0; |
| 617 | struct pm8001_hba_info *pm8001_ha = NULL; |
| 618 | struct domain_device *parent_dev = dev->parent; |
| 619 | struct pm8001_device *pm8001_device; |
| 620 | DECLARE_COMPLETION_ONSTACK(completion); |
| 621 | u32 flag = 0; |
| 622 | pm8001_ha = pm8001_find_ha_by_dev(dev); |
| 623 | spin_lock_irqsave(&pm8001_ha->lock, flags); |
| 624 | |
| 625 | pm8001_device = pm8001_alloc_dev(pm8001_ha); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 626 | if (!pm8001_device) { |
| 627 | res = -1; |
| 628 | goto found_out; |
| 629 | } |
jack wang | f01f4e6 | 2009-12-07 17:22:55 +0800 | [diff] [blame] | 630 | pm8001_device->sas_device = dev; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 631 | dev->lldd_dev = pm8001_device; |
| 632 | pm8001_device->dev_type = dev->dev_type; |
| 633 | pm8001_device->dcompletion = &completion; |
John Garry | 924a354 | 2019-06-10 20:41:41 +0800 | [diff] [blame] | 634 | if (parent_dev && dev_is_expander(parent_dev->dev_type)) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 635 | int phy_id; |
| 636 | struct ex_phy *phy; |
| 637 | for (phy_id = 0; phy_id < parent_dev->ex_dev.num_phys; |
| 638 | phy_id++) { |
| 639 | phy = &parent_dev->ex_dev.ex_phy[phy_id]; |
| 640 | if (SAS_ADDR(phy->attached_sas_addr) |
| 641 | == SAS_ADDR(dev->sas_addr)) { |
| 642 | pm8001_device->attached_phy = phy_id; |
| 643 | break; |
| 644 | } |
| 645 | } |
| 646 | if (phy_id == parent_dev->ex_dev.num_phys) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 647 | pm8001_dbg(pm8001_ha, FAIL, |
| 648 | "Error: no attached dev:%016llx at ex:%016llx.\n", |
| 649 | SAS_ADDR(dev->sas_addr), |
| 650 | SAS_ADDR(parent_dev->sas_addr)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 651 | res = -1; |
| 652 | } |
| 653 | } else { |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 654 | if (dev->dev_type == SAS_SATA_DEV) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 655 | pm8001_device->attached_phy = |
| 656 | dev->rphy->identify.phy_identifier; |
Julia Lawall | 251f24e | 2018-12-30 16:53:13 +0100 | [diff] [blame] | 657 | flag = 1; /* directly sata */ |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 658 | } |
| 659 | } /*register this device to HBA*/ |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 660 | pm8001_dbg(pm8001_ha, DISC, "Found device\n"); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 661 | PM8001_CHIP_DISP->reg_dev_req(pm8001_ha, pm8001_device, flag); |
| 662 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
| 663 | wait_for_completion(&completion); |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 664 | if (dev->dev_type == SAS_END_DEVICE) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 665 | msleep(50); |
Mark Salyzyn | 5c4fb76 | 2012-01-17 12:56:45 -0500 | [diff] [blame] | 666 | pm8001_ha->flags = PM8001F_RUN_TIME; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 667 | return 0; |
| 668 | found_out: |
| 669 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
| 670 | return res; |
| 671 | } |
| 672 | |
| 673 | int pm8001_dev_found(struct domain_device *dev) |
| 674 | { |
| 675 | return pm8001_dev_found_notify(dev); |
| 676 | } |
| 677 | |
Sakthivel K | c6b9ef5 | 2013-03-19 18:08:08 +0530 | [diff] [blame] | 678 | void pm8001_task_done(struct sas_task *task) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 679 | { |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 680 | if (!del_timer(&task->slow_task->timer)) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 681 | return; |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 682 | complete(&task->slow_task->completion); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 683 | } |
| 684 | |
Kees Cook | 77570ee | 2017-08-22 16:05:14 -0700 | [diff] [blame] | 685 | static void pm8001_tmf_timedout(struct timer_list *t) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 686 | { |
Kees Cook | 77570ee | 2017-08-22 16:05:14 -0700 | [diff] [blame] | 687 | struct sas_task_slow *slow = from_timer(slow, t, timer); |
| 688 | struct sas_task *task = slow->task; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 689 | |
| 690 | task->task_state_flags |= SAS_TASK_STATE_ABORTED; |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 691 | complete(&task->slow_task->completion); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | #define PM8001_TASK_TIMEOUT 20 |
| 695 | /** |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 696 | * pm8001_exec_internal_tmf_task - execute some task management commands. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 697 | * @dev: the wanted device. |
| 698 | * @tmf: which task management wanted to be take. |
| 699 | * @para_len: para_len. |
| 700 | * @parameter: ssp task parameter. |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 701 | * |
| 702 | * when errors or exception happened, we may want to do something, for example |
| 703 | * abort the issued task which result in this execption, it is done by calling |
| 704 | * this function, note it is also with the task execute interface. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 705 | */ |
| 706 | static int pm8001_exec_internal_tmf_task(struct domain_device *dev, |
| 707 | void *parameter, u32 para_len, struct pm8001_tmf_task *tmf) |
| 708 | { |
| 709 | int res, retry; |
| 710 | struct sas_task *task = NULL; |
| 711 | struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev); |
Anand Kumar Santhanam | e912457b | 2013-09-17 16:58:10 +0530 | [diff] [blame] | 712 | struct pm8001_device *pm8001_dev = dev->lldd_dev; |
| 713 | DECLARE_COMPLETION_ONSTACK(completion_setstate); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 714 | |
| 715 | for (retry = 0; retry < 3; retry++) { |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 716 | task = sas_alloc_slow_task(GFP_KERNEL); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 717 | if (!task) |
| 718 | return -ENOMEM; |
| 719 | |
| 720 | task->dev = dev; |
| 721 | task->task_proto = dev->tproto; |
| 722 | memcpy(&task->ssp_task, parameter, para_len); |
| 723 | task->task_done = pm8001_task_done; |
Kees Cook | 841b86f | 2017-10-23 09:40:42 +0200 | [diff] [blame] | 724 | task->slow_task->timer.function = pm8001_tmf_timedout; |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 725 | task->slow_task->timer.expires = jiffies + PM8001_TASK_TIMEOUT*HZ; |
| 726 | add_timer(&task->slow_task->timer); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 727 | |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 728 | res = pm8001_task_exec(task, GFP_KERNEL, 1, tmf); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 729 | |
| 730 | if (res) { |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 731 | del_timer(&task->slow_task->timer); |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 732 | pm8001_dbg(pm8001_ha, FAIL, "Executing internal task failed\n"); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 733 | goto ex_err; |
| 734 | } |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 735 | wait_for_completion(&task->slow_task->completion); |
Anand Kumar Santhanam | e912457b | 2013-09-17 16:58:10 +0530 | [diff] [blame] | 736 | if (pm8001_ha->chip_id != chip_8001) { |
| 737 | pm8001_dev->setds_completion = &completion_setstate; |
Colin Ian King | 9e2a07e | 2019-03-17 18:15:32 +0000 | [diff] [blame] | 738 | PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha, |
Igor Pylypiv | 9ec3d4c | 2021-03-04 22:09:08 -0800 | [diff] [blame] | 739 | pm8001_dev, DS_OPERATIONAL); |
Anand Kumar Santhanam | e912457b | 2013-09-17 16:58:10 +0530 | [diff] [blame] | 740 | wait_for_completion(&completion_setstate); |
| 741 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 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)) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 746 | pm8001_dbg(pm8001_ha, FAIL, |
| 747 | "TMF task[%x]timeout.\n", |
| 748 | tmf->tmf); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 749 | goto ex_err; |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
Bart Van Assche | d377f41 | 2021-05-23 19:54:55 -0700 | [diff] [blame] | 754 | task->task_status.stat == SAS_SAM_STAT_GOOD) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 755 | res = TMF_RESP_FUNC_COMPLETE; |
| 756 | break; |
| 757 | } |
| 758 | |
| 759 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
| 760 | task->task_status.stat == SAS_DATA_UNDERRUN) { |
| 761 | /* no error, but return the number of bytes of |
| 762 | * underrun */ |
| 763 | res = task->task_status.residual; |
| 764 | break; |
| 765 | } |
| 766 | |
| 767 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
| 768 | task->task_status.stat == SAS_DATA_OVERRUN) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 769 | pm8001_dbg(pm8001_ha, FAIL, "Blocked task error.\n"); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 770 | res = -EMSGSIZE; |
| 771 | break; |
| 772 | } else { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 773 | pm8001_dbg(pm8001_ha, EH, |
| 774 | " Task to dev %016llx response:0x%x status 0x%x\n", |
| 775 | SAS_ADDR(dev->sas_addr), |
| 776 | task->task_status.resp, |
| 777 | task->task_status.stat); |
Dan Williams | 4fcf812 | 2011-07-29 17:26:39 -0700 | [diff] [blame] | 778 | sas_free_task(task); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 779 | task = NULL; |
| 780 | } |
| 781 | } |
| 782 | ex_err: |
| 783 | BUG_ON(retry == 3 && task != NULL); |
Dan Williams | 4fcf812 | 2011-07-29 17:26:39 -0700 | [diff] [blame] | 784 | sas_free_task(task); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 785 | return res; |
| 786 | } |
| 787 | |
| 788 | static int |
| 789 | pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha, |
| 790 | struct pm8001_device *pm8001_dev, struct domain_device *dev, u32 flag, |
| 791 | u32 task_tag) |
| 792 | { |
| 793 | int res, retry; |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 794 | u32 ccb_tag; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 795 | struct pm8001_ccb_info *ccb; |
| 796 | struct sas_task *task = NULL; |
| 797 | |
| 798 | for (retry = 0; retry < 3; retry++) { |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 799 | task = sas_alloc_slow_task(GFP_KERNEL); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 800 | if (!task) |
| 801 | return -ENOMEM; |
| 802 | |
| 803 | task->dev = dev; |
| 804 | task->task_proto = dev->tproto; |
| 805 | task->task_done = pm8001_task_done; |
Kees Cook | 841b86f | 2017-10-23 09:40:42 +0200 | [diff] [blame] | 806 | task->slow_task->timer.function = pm8001_tmf_timedout; |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 807 | task->slow_task->timer.expires = jiffies + PM8001_TASK_TIMEOUT * HZ; |
| 808 | add_timer(&task->slow_task->timer); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 809 | |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 810 | res = pm8001_tag_alloc(pm8001_ha, &ccb_tag); |
| 811 | if (res) |
Dinghao Liu | ea403fd | 2020-08-23 17:14:53 +0800 | [diff] [blame] | 812 | goto ex_err; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 813 | ccb = &pm8001_ha->ccb_info[ccb_tag]; |
| 814 | ccb->device = pm8001_dev; |
| 815 | ccb->ccb_tag = ccb_tag; |
| 816 | ccb->task = task; |
Viswas G | 3b700e3 | 2015-08-11 15:06:28 +0530 | [diff] [blame] | 817 | ccb->n_elem = 0; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 818 | |
| 819 | res = PM8001_CHIP_DISP->task_abort(pm8001_ha, |
| 820 | pm8001_dev, flag, task_tag, ccb_tag); |
| 821 | |
| 822 | if (res) { |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 823 | del_timer(&task->slow_task->timer); |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 824 | pm8001_dbg(pm8001_ha, FAIL, "Executing internal task failed\n"); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 825 | goto ex_err; |
| 826 | } |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 827 | wait_for_completion(&task->slow_task->completion); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 828 | res = TMF_RESP_FUNC_FAILED; |
| 829 | /* Even TMF timed out, return direct. */ |
| 830 | if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) { |
| 831 | if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 832 | pm8001_dbg(pm8001_ha, FAIL, |
| 833 | "TMF task timeout.\n"); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 834 | goto ex_err; |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
Bart Van Assche | d377f41 | 2021-05-23 19:54:55 -0700 | [diff] [blame] | 839 | task->task_status.stat == SAS_SAM_STAT_GOOD) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 840 | res = TMF_RESP_FUNC_COMPLETE; |
| 841 | break; |
| 842 | |
| 843 | } else { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 844 | pm8001_dbg(pm8001_ha, EH, |
| 845 | " Task to dev %016llx response: 0x%x status 0x%x\n", |
| 846 | SAS_ADDR(dev->sas_addr), |
| 847 | task->task_status.resp, |
| 848 | task->task_status.stat); |
Dan Williams | 4fcf812 | 2011-07-29 17:26:39 -0700 | [diff] [blame] | 849 | sas_free_task(task); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 850 | task = NULL; |
| 851 | } |
| 852 | } |
| 853 | ex_err: |
| 854 | BUG_ON(retry == 3 && task != NULL); |
Dan Williams | 4fcf812 | 2011-07-29 17:26:39 -0700 | [diff] [blame] | 855 | sas_free_task(task); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 856 | return res; |
| 857 | } |
| 858 | |
| 859 | /** |
| 860 | * pm8001_dev_gone_notify - see the comments for "pm8001_dev_found_notify" |
| 861 | * @dev: the device structure which sas layer used. |
| 862 | */ |
| 863 | static void pm8001_dev_gone_notify(struct domain_device *dev) |
| 864 | { |
| 865 | unsigned long flags = 0; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 866 | struct pm8001_hba_info *pm8001_ha; |
| 867 | struct pm8001_device *pm8001_dev = dev->lldd_dev; |
Dan Carpenter | 2471b89 | 2010-04-23 14:01:04 +0200 | [diff] [blame] | 868 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 869 | pm8001_ha = pm8001_find_ha_by_dev(dev); |
| 870 | spin_lock_irqsave(&pm8001_ha->lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 871 | if (pm8001_dev) { |
Dan Carpenter | 2471b89 | 2010-04-23 14:01:04 +0200 | [diff] [blame] | 872 | u32 device_id = pm8001_dev->device_id; |
| 873 | |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 874 | pm8001_dbg(pm8001_ha, DISC, "found dev[%d:%x] is gone.\n", |
| 875 | pm8001_dev->device_id, pm8001_dev->dev_type); |
Viswas G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 876 | if (atomic_read(&pm8001_dev->running_req)) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 877 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
Luo Jiaxing | 8a23dbc | 2021-04-08 20:56:32 +0800 | [diff] [blame] | 878 | pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev, |
| 879 | dev, 1, 0); |
Viswas G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 880 | while (atomic_read(&pm8001_dev->running_req)) |
Deepak Ukey | 196ba66 | 2019-07-09 15:30:48 +0530 | [diff] [blame] | 881 | msleep(20); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 882 | spin_lock_irqsave(&pm8001_ha->lock, flags); |
| 883 | } |
| 884 | PM8001_CHIP_DISP->dereg_dev_req(pm8001_ha, device_id); |
| 885 | pm8001_free_dev(pm8001_dev); |
| 886 | } else { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 887 | pm8001_dbg(pm8001_ha, DISC, "Found dev has gone.\n"); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 888 | } |
| 889 | dev->lldd_dev = NULL; |
| 890 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
| 891 | } |
| 892 | |
| 893 | void pm8001_dev_gone(struct domain_device *dev) |
| 894 | { |
| 895 | pm8001_dev_gone_notify(dev); |
| 896 | } |
| 897 | |
| 898 | static int pm8001_issue_ssp_tmf(struct domain_device *dev, |
| 899 | u8 *lun, struct pm8001_tmf_task *tmf) |
| 900 | { |
| 901 | struct sas_ssp_task ssp_task; |
| 902 | if (!(dev->tproto & SAS_PROTOCOL_SSP)) |
| 903 | return TMF_RESP_FUNC_ESUPP; |
| 904 | |
Lee Jones | 412b51f | 2020-11-02 10:25:43 +0000 | [diff] [blame] | 905 | memcpy((u8 *)&ssp_task.LUN, lun, 8); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 906 | return pm8001_exec_internal_tmf_task(dev, &ssp_task, sizeof(ssp_task), |
| 907 | tmf); |
| 908 | } |
| 909 | |
Mark Salyzyn | 5954d73 | 2012-01-17 11:52:24 -0500 | [diff] [blame] | 910 | /* retry commands by ha, by task and/or by device */ |
| 911 | void pm8001_open_reject_retry( |
| 912 | struct pm8001_hba_info *pm8001_ha, |
| 913 | struct sas_task *task_to_close, |
| 914 | struct pm8001_device *device_to_close) |
| 915 | { |
| 916 | int i; |
| 917 | unsigned long flags; |
| 918 | |
| 919 | if (pm8001_ha == NULL) |
| 920 | return; |
| 921 | |
| 922 | spin_lock_irqsave(&pm8001_ha->lock, flags); |
| 923 | |
| 924 | for (i = 0; i < PM8001_MAX_CCB; i++) { |
| 925 | struct sas_task *task; |
| 926 | struct task_status_struct *ts; |
| 927 | struct pm8001_device *pm8001_dev; |
| 928 | unsigned long flags1; |
| 929 | u32 tag; |
| 930 | struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[i]; |
| 931 | |
| 932 | pm8001_dev = ccb->device; |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 933 | if (!pm8001_dev || (pm8001_dev->dev_type == SAS_PHY_UNUSED)) |
Mark Salyzyn | 5954d73 | 2012-01-17 11:52:24 -0500 | [diff] [blame] | 934 | continue; |
| 935 | if (!device_to_close) { |
| 936 | uintptr_t d = (uintptr_t)pm8001_dev |
| 937 | - (uintptr_t)&pm8001_ha->devices; |
| 938 | if (((d % sizeof(*pm8001_dev)) != 0) |
| 939 | || ((d / sizeof(*pm8001_dev)) >= PM8001_MAX_DEVICES)) |
| 940 | continue; |
| 941 | } else if (pm8001_dev != device_to_close) |
| 942 | continue; |
| 943 | tag = ccb->ccb_tag; |
| 944 | if (!tag || (tag == 0xFFFFFFFF)) |
| 945 | continue; |
| 946 | task = ccb->task; |
| 947 | if (!task || !task->task_done) |
| 948 | continue; |
| 949 | if (task_to_close && (task != task_to_close)) |
| 950 | continue; |
| 951 | ts = &task->task_status; |
| 952 | ts->resp = SAS_TASK_COMPLETE; |
| 953 | /* Force the midlayer to retry */ |
| 954 | ts->stat = SAS_OPEN_REJECT; |
| 955 | ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; |
| 956 | if (pm8001_dev) |
Viswas G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 957 | atomic_dec(&pm8001_dev->running_req); |
Mark Salyzyn | 5954d73 | 2012-01-17 11:52:24 -0500 | [diff] [blame] | 958 | spin_lock_irqsave(&task->task_state_lock, flags1); |
| 959 | task->task_state_flags &= ~SAS_TASK_STATE_PENDING; |
| 960 | task->task_state_flags &= ~SAS_TASK_AT_INITIATOR; |
| 961 | task->task_state_flags |= SAS_TASK_STATE_DONE; |
| 962 | if (unlikely((task->task_state_flags |
| 963 | & SAS_TASK_STATE_ABORTED))) { |
| 964 | spin_unlock_irqrestore(&task->task_state_lock, |
| 965 | flags1); |
| 966 | pm8001_ccb_task_free(pm8001_ha, task, ccb, tag); |
| 967 | } else { |
| 968 | spin_unlock_irqrestore(&task->task_state_lock, |
| 969 | flags1); |
| 970 | pm8001_ccb_task_free(pm8001_ha, task, ccb, tag); |
| 971 | mb();/* in order to force CPU ordering */ |
| 972 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
| 973 | task->task_done(task); |
| 974 | spin_lock_irqsave(&pm8001_ha->lock, flags); |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | spin_unlock_irqrestore(&pm8001_ha->lock, flags); |
| 979 | } |
| 980 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 981 | /** |
Lee Jones | 62690c0 | 2021-03-03 14:46:12 +0000 | [diff] [blame] | 982 | * pm8001_I_T_nexus_reset() |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 983 | * Standard mandates link reset for ATA (type 0) and hard reset for |
| 984 | * SSP (type 1) , only for RECOVERY |
Lee Jones | a0cf5ce | 2020-07-21 17:41:18 +0100 | [diff] [blame] | 985 | * @dev: the device structure for the device to reset. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 986 | */ |
| 987 | int pm8001_I_T_nexus_reset(struct domain_device *dev) |
| 988 | { |
| 989 | int rc = TMF_RESP_FUNC_FAILED; |
| 990 | struct pm8001_device *pm8001_dev; |
| 991 | struct pm8001_hba_info *pm8001_ha; |
| 992 | struct sas_phy *phy; |
Dan Williams | e7db822 | 2012-06-21 23:30:58 -0700 | [diff] [blame] | 993 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 994 | if (!dev || !dev->lldd_dev) |
Dan Williams | e7db822 | 2012-06-21 23:30:58 -0700 | [diff] [blame] | 995 | return -ENODEV; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 996 | |
| 997 | pm8001_dev = dev->lldd_dev; |
| 998 | pm8001_ha = pm8001_find_ha_by_dev(dev); |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 999 | phy = sas_get_local_phy(dev); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1000 | |
| 1001 | if (dev_is_sata(dev)) { |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 1002 | if (scsi_is_sas_phy_local(phy)) { |
| 1003 | rc = 0; |
| 1004 | goto out; |
| 1005 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1006 | rc = sas_phy_reset(phy, 1); |
Viswas G | 3a1ae96 | 2015-08-11 15:06:26 +0530 | [diff] [blame] | 1007 | if (rc) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1008 | pm8001_dbg(pm8001_ha, EH, |
| 1009 | "phy reset failed for device %x\n" |
| 1010 | "with rc %d\n", pm8001_dev->device_id, rc); |
Viswas G | 3a1ae96 | 2015-08-11 15:06:26 +0530 | [diff] [blame] | 1011 | rc = TMF_RESP_FUNC_FAILED; |
| 1012 | goto out; |
| 1013 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1014 | msleep(2000); |
Luo Jiaxing | 8a23dbc | 2021-04-08 20:56:32 +0800 | [diff] [blame] | 1015 | rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev, |
| 1016 | dev, 1, 0); |
Viswas G | 3a1ae96 | 2015-08-11 15:06:26 +0530 | [diff] [blame] | 1017 | if (rc) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1018 | pm8001_dbg(pm8001_ha, EH, "task abort failed %x\n" |
| 1019 | "with rc %d\n", pm8001_dev->device_id, rc); |
Viswas G | 3a1ae96 | 2015-08-11 15:06:26 +0530 | [diff] [blame] | 1020 | rc = TMF_RESP_FUNC_FAILED; |
| 1021 | } |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 1022 | } else { |
| 1023 | rc = sas_phy_reset(phy, 1); |
| 1024 | msleep(2000); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1025 | } |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1026 | pm8001_dbg(pm8001_ha, EH, " for device[%x]:rc=%d\n", |
| 1027 | pm8001_dev->device_id, rc); |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 1028 | out: |
| 1029 | sas_put_local_phy(phy); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1030 | return rc; |
| 1031 | } |
| 1032 | |
Sakthivel K | a6cb3d0 | 2013-03-19 18:08:40 +0530 | [diff] [blame] | 1033 | /* |
| 1034 | * This function handle the IT_NEXUS_XXX event or completion |
| 1035 | * status code for SSP/SATA/SMP I/O request. |
| 1036 | */ |
| 1037 | int pm8001_I_T_nexus_event_handler(struct domain_device *dev) |
| 1038 | { |
| 1039 | int rc = TMF_RESP_FUNC_FAILED; |
| 1040 | struct pm8001_device *pm8001_dev; |
| 1041 | struct pm8001_hba_info *pm8001_ha; |
| 1042 | struct sas_phy *phy; |
Sakthivel K | a6cb3d0 | 2013-03-19 18:08:40 +0530 | [diff] [blame] | 1043 | |
| 1044 | if (!dev || !dev->lldd_dev) |
| 1045 | return -1; |
| 1046 | |
| 1047 | pm8001_dev = dev->lldd_dev; |
Sakthivel K | a6cb3d0 | 2013-03-19 18:08:40 +0530 | [diff] [blame] | 1048 | pm8001_ha = pm8001_find_ha_by_dev(dev); |
| 1049 | |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1050 | pm8001_dbg(pm8001_ha, EH, "I_T_Nexus handler invoked !!\n"); |
Sakthivel K | a6cb3d0 | 2013-03-19 18:08:40 +0530 | [diff] [blame] | 1051 | |
| 1052 | phy = sas_get_local_phy(dev); |
| 1053 | |
| 1054 | if (dev_is_sata(dev)) { |
| 1055 | DECLARE_COMPLETION_ONSTACK(completion_setstate); |
| 1056 | if (scsi_is_sas_phy_local(phy)) { |
| 1057 | rc = 0; |
| 1058 | goto out; |
| 1059 | } |
| 1060 | /* send internal ssp/sata/smp abort command to FW */ |
Luo Jiaxing | 8a23dbc | 2021-04-08 20:56:32 +0800 | [diff] [blame] | 1061 | rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev, |
| 1062 | dev, 1, 0); |
Sakthivel K | a6cb3d0 | 2013-03-19 18:08:40 +0530 | [diff] [blame] | 1063 | msleep(100); |
| 1064 | |
| 1065 | /* deregister the target device */ |
| 1066 | pm8001_dev_gone_notify(dev); |
| 1067 | msleep(200); |
| 1068 | |
| 1069 | /*send phy reset to hard reset target */ |
| 1070 | rc = sas_phy_reset(phy, 1); |
| 1071 | msleep(2000); |
| 1072 | pm8001_dev->setds_completion = &completion_setstate; |
| 1073 | |
| 1074 | wait_for_completion(&completion_setstate); |
| 1075 | } else { |
| 1076 | /* send internal ssp/sata/smp abort command to FW */ |
Luo Jiaxing | 8a23dbc | 2021-04-08 20:56:32 +0800 | [diff] [blame] | 1077 | rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev, |
| 1078 | dev, 1, 0); |
Sakthivel K | a6cb3d0 | 2013-03-19 18:08:40 +0530 | [diff] [blame] | 1079 | msleep(100); |
| 1080 | |
| 1081 | /* deregister the target device */ |
| 1082 | pm8001_dev_gone_notify(dev); |
| 1083 | msleep(200); |
| 1084 | |
| 1085 | /*send phy reset to hard reset target */ |
| 1086 | rc = sas_phy_reset(phy, 1); |
| 1087 | msleep(2000); |
| 1088 | } |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1089 | pm8001_dbg(pm8001_ha, EH, " for device[%x]:rc=%d\n", |
| 1090 | pm8001_dev->device_id, rc); |
Sakthivel K | a6cb3d0 | 2013-03-19 18:08:40 +0530 | [diff] [blame] | 1091 | out: |
| 1092 | sas_put_local_phy(phy); |
| 1093 | |
| 1094 | return rc; |
| 1095 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1096 | /* mandatory SAM-3, the task reset the specified LUN*/ |
| 1097 | int pm8001_lu_reset(struct domain_device *dev, u8 *lun) |
| 1098 | { |
| 1099 | int rc = TMF_RESP_FUNC_FAILED; |
| 1100 | struct pm8001_tmf_task tmf_task; |
| 1101 | struct pm8001_device *pm8001_dev = dev->lldd_dev; |
| 1102 | struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev); |
Nikith Ganigarakoppal | 34a9b81 | 2013-10-30 16:13:22 +0530 | [diff] [blame] | 1103 | DECLARE_COMPLETION_ONSTACK(completion_setstate); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1104 | if (dev_is_sata(dev)) { |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 1105 | struct sas_phy *phy = sas_get_local_phy(dev); |
Luo Jiaxing | 8a23dbc | 2021-04-08 20:56:32 +0800 | [diff] [blame] | 1106 | rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev, |
| 1107 | dev, 1, 0); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1108 | rc = sas_phy_reset(phy, 1); |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 1109 | sas_put_local_phy(phy); |
Nikith Ganigarakoppal | 34a9b81 | 2013-10-30 16:13:22 +0530 | [diff] [blame] | 1110 | pm8001_dev->setds_completion = &completion_setstate; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1111 | rc = PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha, |
Igor Pylypiv | 9ec3d4c | 2021-03-04 22:09:08 -0800 | [diff] [blame] | 1112 | pm8001_dev, DS_OPERATIONAL); |
Nikith Ganigarakoppal | 34a9b81 | 2013-10-30 16:13:22 +0530 | [diff] [blame] | 1113 | wait_for_completion(&completion_setstate); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1114 | } else { |
| 1115 | tmf_task.tmf = TMF_LU_RESET; |
| 1116 | rc = pm8001_issue_ssp_tmf(dev, lun, &tmf_task); |
| 1117 | } |
| 1118 | /* If failed, fall-through I_T_Nexus reset */ |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1119 | pm8001_dbg(pm8001_ha, EH, "for device[%x]:rc=%d\n", |
| 1120 | pm8001_dev->device_id, rc); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1121 | return rc; |
| 1122 | } |
| 1123 | |
| 1124 | /* optional SAM-3 */ |
| 1125 | int pm8001_query_task(struct sas_task *task) |
| 1126 | { |
| 1127 | u32 tag = 0xdeadbeef; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1128 | struct scsi_lun lun; |
| 1129 | struct pm8001_tmf_task tmf_task; |
| 1130 | int rc = TMF_RESP_FUNC_FAILED; |
| 1131 | if (unlikely(!task || !task->lldd_task || !task->dev)) |
| 1132 | return rc; |
| 1133 | |
| 1134 | if (task->task_proto & SAS_PROTOCOL_SSP) { |
| 1135 | struct scsi_cmnd *cmnd = task->uldd_task; |
| 1136 | struct domain_device *dev = task->dev; |
| 1137 | struct pm8001_hba_info *pm8001_ha = |
| 1138 | pm8001_find_ha_by_dev(dev); |
| 1139 | |
| 1140 | int_to_scsilun(cmnd->device->lun, &lun); |
| 1141 | rc = pm8001_find_tag(task, &tag); |
| 1142 | if (rc == 0) { |
| 1143 | rc = TMF_RESP_FUNC_FAILED; |
| 1144 | return rc; |
| 1145 | } |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1146 | pm8001_dbg(pm8001_ha, EH, "Query:[%16ph]\n", cmnd->cmnd); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1147 | tmf_task.tmf = TMF_QUERY_TASK; |
| 1148 | tmf_task.tag_of_task_to_be_managed = tag; |
| 1149 | |
| 1150 | rc = pm8001_issue_ssp_tmf(dev, lun.scsi_lun, &tmf_task); |
| 1151 | switch (rc) { |
| 1152 | /* The task is still in Lun, release it then */ |
| 1153 | case TMF_RESP_FUNC_SUCC: |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1154 | pm8001_dbg(pm8001_ha, EH, |
| 1155 | "The task is still in Lun\n"); |
Mark Salyzyn | 6fbc769 | 2011-09-26 07:57:36 -0700 | [diff] [blame] | 1156 | break; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1157 | /* The task is not in Lun or failed, reset the phy */ |
| 1158 | case TMF_RESP_FUNC_FAILED: |
| 1159 | case TMF_RESP_FUNC_COMPLETE: |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1160 | pm8001_dbg(pm8001_ha, EH, |
| 1161 | "The task is not in Lun or failed, reset the phy\n"); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1162 | break; |
| 1163 | } |
| 1164 | } |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 1165 | pr_err("pm80xx: rc= %d\n", rc); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1166 | return rc; |
| 1167 | } |
| 1168 | |
Weitao Hou | 3287794 | 2019-05-20 11:24:03 +0800 | [diff] [blame] | 1169 | /* mandatory SAM-3, still need free task/ccb info, abort the specified task */ |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1170 | int pm8001_abort_task(struct sas_task *task) |
| 1171 | { |
| 1172 | unsigned long flags; |
Viswas G | 1db4990 | 2017-10-18 11:39:11 +0530 | [diff] [blame] | 1173 | u32 tag; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1174 | struct domain_device *dev ; |
Viswas G | 1db4990 | 2017-10-18 11:39:11 +0530 | [diff] [blame] | 1175 | struct pm8001_hba_info *pm8001_ha; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1176 | struct scsi_lun lun; |
| 1177 | struct pm8001_device *pm8001_dev; |
| 1178 | struct pm8001_tmf_task tmf_task; |
Viswas G | 869ddbd | 2017-10-18 11:39:13 +0530 | [diff] [blame] | 1179 | int rc = TMF_RESP_FUNC_FAILED, ret; |
| 1180 | u32 phy_id; |
| 1181 | struct sas_task_slow slow_task; |
akshatzen | a961ea0 | 2021-01-09 18:08:43 +0530 | [diff] [blame] | 1182 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1183 | if (unlikely(!task || !task->lldd_task || !task->dev)) |
Viswas G | 1db4990 | 2017-10-18 11:39:11 +0530 | [diff] [blame] | 1184 | return TMF_RESP_FUNC_FAILED; |
akshatzen | a961ea0 | 2021-01-09 18:08:43 +0530 | [diff] [blame] | 1185 | |
Viswas G | 1db4990 | 2017-10-18 11:39:11 +0530 | [diff] [blame] | 1186 | dev = task->dev; |
| 1187 | pm8001_dev = dev->lldd_dev; |
| 1188 | pm8001_ha = pm8001_find_ha_by_dev(dev); |
Viswas G | 869ddbd | 2017-10-18 11:39:13 +0530 | [diff] [blame] | 1189 | phy_id = pm8001_dev->attached_phy; |
akshatzen | a961ea0 | 2021-01-09 18:08:43 +0530 | [diff] [blame] | 1190 | |
| 1191 | if (PM8001_CHIP_DISP->fatal_errors(pm8001_ha)) { |
| 1192 | // If the controller is seeing fatal errors |
| 1193 | // abort task will not get a response from the controller |
| 1194 | return TMF_RESP_FUNC_FAILED; |
| 1195 | } |
| 1196 | |
peter chang | 51c1c5f6 | 2019-11-14 15:39:06 +0530 | [diff] [blame] | 1197 | ret = pm8001_find_tag(task, &tag); |
| 1198 | if (ret == 0) { |
Joe Perches | 2ce6e20 | 2020-11-23 20:36:03 -0800 | [diff] [blame] | 1199 | pm8001_info(pm8001_ha, "no tag for task:%p\n", task); |
Viswas G | 1db4990 | 2017-10-18 11:39:11 +0530 | [diff] [blame] | 1200 | return TMF_RESP_FUNC_FAILED; |
| 1201 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1202 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 1203 | if (task->task_state_flags & SAS_TASK_STATE_DONE) { |
| 1204 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
Viswas G | 1db4990 | 2017-10-18 11:39:11 +0530 | [diff] [blame] | 1205 | return TMF_RESP_FUNC_COMPLETE; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1206 | } |
Viswas G | 869ddbd | 2017-10-18 11:39:13 +0530 | [diff] [blame] | 1207 | task->task_state_flags |= SAS_TASK_STATE_ABORTED; |
| 1208 | if (task->slow_task == NULL) { |
| 1209 | init_completion(&slow_task.completion); |
| 1210 | task->slow_task = &slow_task; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1211 | } |
| 1212 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 1213 | if (task->task_proto & SAS_PROTOCOL_SSP) { |
| 1214 | struct scsi_cmnd *cmnd = task->uldd_task; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1215 | int_to_scsilun(cmnd->device->lun, &lun); |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 1216 | tmf_task.tmf = TMF_ABORT_TASK; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1217 | tmf_task.tag_of_task_to_be_managed = tag; |
| 1218 | rc = pm8001_issue_ssp_tmf(dev, lun.scsi_lun, &tmf_task); |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 1219 | pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1220 | pm8001_dev->sas_device, 0, tag); |
| 1221 | } else if (task->task_proto & SAS_PROTOCOL_SATA || |
| 1222 | task->task_proto & SAS_PROTOCOL_STP) { |
Viswas G | 869ddbd | 2017-10-18 11:39:13 +0530 | [diff] [blame] | 1223 | if (pm8001_ha->chip_id == chip_8006) { |
| 1224 | DECLARE_COMPLETION_ONSTACK(completion_reset); |
| 1225 | DECLARE_COMPLETION_ONSTACK(completion); |
| 1226 | struct pm8001_phy *phy = pm8001_ha->phy + phy_id; |
| 1227 | |
| 1228 | /* 1. Set Device state as Recovery */ |
| 1229 | pm8001_dev->setds_completion = &completion; |
| 1230 | PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha, |
Igor Pylypiv | 9ec3d4c | 2021-03-04 22:09:08 -0800 | [diff] [blame] | 1231 | pm8001_dev, DS_IN_RECOVERY); |
Viswas G | 869ddbd | 2017-10-18 11:39:13 +0530 | [diff] [blame] | 1232 | wait_for_completion(&completion); |
| 1233 | |
| 1234 | /* 2. Send Phy Control Hard Reset */ |
| 1235 | reinit_completion(&completion); |
peter chang | 51c1c5f6 | 2019-11-14 15:39:06 +0530 | [diff] [blame] | 1236 | phy->port_reset_status = PORT_RESET_TMO; |
Viswas G | 869ddbd | 2017-10-18 11:39:13 +0530 | [diff] [blame] | 1237 | phy->reset_success = false; |
| 1238 | phy->enable_completion = &completion; |
| 1239 | phy->reset_completion = &completion_reset; |
| 1240 | ret = PM8001_CHIP_DISP->phy_ctl_req(pm8001_ha, phy_id, |
| 1241 | PHY_HARD_RESET); |
peter chang | 51c1c5f6 | 2019-11-14 15:39:06 +0530 | [diff] [blame] | 1242 | if (ret) { |
| 1243 | phy->enable_completion = NULL; |
| 1244 | phy->reset_completion = NULL; |
Viswas G | 869ddbd | 2017-10-18 11:39:13 +0530 | [diff] [blame] | 1245 | goto out; |
peter chang | 51c1c5f6 | 2019-11-14 15:39:06 +0530 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | /* In the case of the reset timeout/fail we still |
| 1249 | * abort the command at the firmware. The assumption |
| 1250 | * here is that the drive is off doing something so |
| 1251 | * that it's not processing requests, and we want to |
| 1252 | * avoid getting a completion for this and either |
| 1253 | * leaking the task in libsas or losing the race and |
| 1254 | * getting a double free. |
| 1255 | */ |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1256 | pm8001_dbg(pm8001_ha, MSG, |
| 1257 | "Waiting for local phy ctl\n"); |
peter chang | 51c1c5f6 | 2019-11-14 15:39:06 +0530 | [diff] [blame] | 1258 | ret = wait_for_completion_timeout(&completion, |
| 1259 | PM8001_TASK_TIMEOUT * HZ); |
| 1260 | if (!ret || !phy->reset_success) { |
| 1261 | phy->enable_completion = NULL; |
| 1262 | phy->reset_completion = NULL; |
| 1263 | } else { |
| 1264 | /* 3. Wait for Port Reset complete or |
| 1265 | * Port reset TMO |
| 1266 | */ |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1267 | pm8001_dbg(pm8001_ha, MSG, |
| 1268 | "Waiting for Port reset\n"); |
peter chang | 51c1c5f6 | 2019-11-14 15:39:06 +0530 | [diff] [blame] | 1269 | ret = wait_for_completion_timeout( |
| 1270 | &completion_reset, |
| 1271 | PM8001_TASK_TIMEOUT * HZ); |
| 1272 | if (!ret) |
| 1273 | phy->reset_completion = NULL; |
| 1274 | WARN_ON(phy->port_reset_status == |
| 1275 | PORT_RESET_TMO); |
| 1276 | if (phy->port_reset_status == PORT_RESET_TMO) { |
| 1277 | pm8001_dev_gone_notify(dev); |
| 1278 | goto out; |
| 1279 | } |
Deepak Ukey | 196ba66 | 2019-07-09 15:30:48 +0530 | [diff] [blame] | 1280 | } |
Viswas G | 869ddbd | 2017-10-18 11:39:13 +0530 | [diff] [blame] | 1281 | |
| 1282 | /* |
| 1283 | * 4. SATA Abort ALL |
| 1284 | * we wait for the task to be aborted so that the task |
| 1285 | * is removed from the ccb. on success the caller is |
| 1286 | * going to free the task. |
| 1287 | */ |
| 1288 | ret = pm8001_exec_internal_task_abort(pm8001_ha, |
| 1289 | pm8001_dev, pm8001_dev->sas_device, 1, tag); |
| 1290 | if (ret) |
| 1291 | goto out; |
| 1292 | ret = wait_for_completion_timeout( |
| 1293 | &task->slow_task->completion, |
| 1294 | PM8001_TASK_TIMEOUT * HZ); |
| 1295 | if (!ret) |
| 1296 | goto out; |
| 1297 | |
| 1298 | /* 5. Set Device State as Operational */ |
| 1299 | reinit_completion(&completion); |
| 1300 | pm8001_dev->setds_completion = &completion; |
| 1301 | PM8001_CHIP_DISP->set_dev_state_req(pm8001_ha, |
Igor Pylypiv | 9ec3d4c | 2021-03-04 22:09:08 -0800 | [diff] [blame] | 1302 | pm8001_dev, DS_OPERATIONAL); |
Viswas G | 869ddbd | 2017-10-18 11:39:13 +0530 | [diff] [blame] | 1303 | wait_for_completion(&completion); |
| 1304 | } else { |
| 1305 | rc = pm8001_exec_internal_task_abort(pm8001_ha, |
| 1306 | pm8001_dev, pm8001_dev->sas_device, 0, tag); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1307 | } |
Viswas G | 869ddbd | 2017-10-18 11:39:13 +0530 | [diff] [blame] | 1308 | rc = TMF_RESP_FUNC_COMPLETE; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1309 | } else if (task->task_proto & SAS_PROTOCOL_SMP) { |
| 1310 | /* SMP */ |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1311 | rc = pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev, |
| 1312 | pm8001_dev->sas_device, 0, tag); |
| 1313 | |
| 1314 | } |
| 1315 | out: |
Viswas G | 869ddbd | 2017-10-18 11:39:13 +0530 | [diff] [blame] | 1316 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 1317 | if (task->slow_task == &slow_task) |
| 1318 | task->slow_task = NULL; |
| 1319 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1320 | if (rc != TMF_RESP_FUNC_COMPLETE) |
Joe Perches | 2ce6e20 | 2020-11-23 20:36:03 -0800 | [diff] [blame] | 1321 | pm8001_info(pm8001_ha, "rc= %d\n", rc); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1322 | return rc; |
| 1323 | } |
| 1324 | |
| 1325 | int pm8001_abort_task_set(struct domain_device *dev, u8 *lun) |
| 1326 | { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1327 | struct pm8001_tmf_task tmf_task; |
| 1328 | |
| 1329 | tmf_task.tmf = TMF_ABORT_TASK_SET; |
Colin Ian King | afcd609 | 2019-07-31 23:22:14 +0100 | [diff] [blame] | 1330 | return pm8001_issue_ssp_tmf(dev, lun, &tmf_task); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | int pm8001_clear_aca(struct domain_device *dev, u8 *lun) |
| 1334 | { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1335 | struct pm8001_tmf_task tmf_task; |
| 1336 | |
| 1337 | tmf_task.tmf = TMF_CLEAR_ACA; |
Colin Ian King | afcd609 | 2019-07-31 23:22:14 +0100 | [diff] [blame] | 1338 | return pm8001_issue_ssp_tmf(dev, lun, &tmf_task); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | int pm8001_clear_task_set(struct domain_device *dev, u8 *lun) |
| 1342 | { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1343 | struct pm8001_tmf_task tmf_task; |
| 1344 | struct pm8001_device *pm8001_dev = dev->lldd_dev; |
| 1345 | struct pm8001_hba_info *pm8001_ha = pm8001_find_ha_by_dev(dev); |
| 1346 | |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1347 | pm8001_dbg(pm8001_ha, EH, "I_T_L_Q clear task set[%x]\n", |
| 1348 | pm8001_dev->device_id); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1349 | tmf_task.tmf = TMF_CLEAR_TASK_SET; |
Colin Ian King | afcd609 | 2019-07-31 23:22:14 +0100 | [diff] [blame] | 1350 | return pm8001_issue_ssp_tmf(dev, lun, &tmf_task); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1351 | } |