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