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