Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 1 | /* |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 2 | * Marvell 88SE64xx/88SE94xx main function |
| 3 | * |
| 4 | * Copyright 2007 Red Hat, Inc. |
| 5 | * Copyright 2008 Marvell. <kewei@marvell.com> |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 6 | * Copyright 2009-2011 Marvell. <yuxiangl@marvell.com> |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 7 | * |
| 8 | * This file is licensed under GPLv2. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; version 2 of the |
| 13 | * License. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 23 | * USA |
| 24 | */ |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 25 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 26 | #include "mv_sas.h" |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 27 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 28 | static int mvs_find_tag(struct mvs_info *mvi, struct sas_task *task, u32 *tag) |
| 29 | { |
| 30 | if (task->lldd_task) { |
| 31 | struct mvs_slot_info *slot; |
Andy Yan | f9da3be | 2009-05-14 20:41:21 -0400 | [diff] [blame] | 32 | slot = task->lldd_task; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 33 | *tag = slot->slot_tag; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 34 | return 1; |
| 35 | } |
| 36 | return 0; |
| 37 | } |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 38 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 39 | void mvs_tag_clear(struct mvs_info *mvi, u32 tag) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 40 | { |
Xiangliang Yu | b89e8f5 | 2011-05-24 22:35:09 +0800 | [diff] [blame] | 41 | void *bitmap = mvi->tags; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 42 | clear_bit(tag, bitmap); |
| 43 | } |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 44 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 45 | void mvs_tag_free(struct mvs_info *mvi, u32 tag) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 46 | { |
| 47 | mvs_tag_clear(mvi, tag); |
| 48 | } |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 49 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 50 | void mvs_tag_set(struct mvs_info *mvi, unsigned int tag) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 51 | { |
Xiangliang Yu | b89e8f5 | 2011-05-24 22:35:09 +0800 | [diff] [blame] | 52 | void *bitmap = mvi->tags; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 53 | set_bit(tag, bitmap); |
| 54 | } |
| 55 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 56 | inline int mvs_tag_alloc(struct mvs_info *mvi, u32 *tag_out) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 57 | { |
| 58 | unsigned int index, tag; |
Xiangliang Yu | b89e8f5 | 2011-05-24 22:35:09 +0800 | [diff] [blame] | 59 | void *bitmap = mvi->tags; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 60 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 61 | index = find_first_zero_bit(bitmap, mvi->tags_num); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 62 | tag = index; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 63 | if (tag >= mvi->tags_num) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 64 | return -SAS_QUEUE_FULL; |
| 65 | mvs_tag_set(mvi, tag); |
| 66 | *tag_out = tag; |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | void mvs_tag_init(struct mvs_info *mvi) |
| 71 | { |
| 72 | int i; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 73 | for (i = 0; i < mvi->tags_num; ++i) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 74 | mvs_tag_clear(mvi, i); |
| 75 | } |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 76 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 77 | struct mvs_info *mvs_find_dev_mvi(struct domain_device *dev) |
| 78 | { |
| 79 | unsigned long i = 0, j = 0, hi = 0; |
| 80 | struct sas_ha_struct *sha = dev->port->ha; |
| 81 | struct mvs_info *mvi = NULL; |
| 82 | struct asd_sas_phy *phy; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 83 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 84 | while (sha->sas_port[i]) { |
| 85 | if (sha->sas_port[i] == dev->port) { |
| 86 | phy = container_of(sha->sas_port[i]->phy_list.next, |
| 87 | struct asd_sas_phy, port_phy_el); |
| 88 | j = 0; |
| 89 | while (sha->sas_phy[j]) { |
| 90 | if (sha->sas_phy[j] == phy) |
| 91 | break; |
| 92 | j++; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 93 | } |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 94 | break; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 95 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 96 | i++; |
| 97 | } |
| 98 | hi = j/((struct mvs_prv_info *)sha->lldd_ha)->n_phy; |
| 99 | mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[hi]; |
| 100 | |
| 101 | return mvi; |
| 102 | |
| 103 | } |
| 104 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 105 | int mvs_find_dev_phyno(struct domain_device *dev, int *phyno) |
| 106 | { |
| 107 | unsigned long i = 0, j = 0, n = 0, num = 0; |
Andy Yan | 9870d9a | 2009-05-11 22:19:25 +0800 | [diff] [blame] | 108 | struct mvs_device *mvi_dev = (struct mvs_device *)dev->lldd_dev; |
| 109 | struct mvs_info *mvi = mvi_dev->mvi_info; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 110 | struct sas_ha_struct *sha = dev->port->ha; |
| 111 | |
| 112 | while (sha->sas_port[i]) { |
| 113 | if (sha->sas_port[i] == dev->port) { |
| 114 | struct asd_sas_phy *phy; |
| 115 | list_for_each_entry(phy, |
| 116 | &sha->sas_port[i]->phy_list, port_phy_el) { |
| 117 | j = 0; |
| 118 | while (sha->sas_phy[j]) { |
| 119 | if (sha->sas_phy[j] == phy) |
| 120 | break; |
| 121 | j++; |
| 122 | } |
| 123 | phyno[n] = (j >= mvi->chip->n_phy) ? |
| 124 | (j - mvi->chip->n_phy) : j; |
| 125 | num++; |
| 126 | n++; |
| 127 | } |
| 128 | break; |
| 129 | } |
| 130 | i++; |
| 131 | } |
| 132 | return num; |
| 133 | } |
| 134 | |
Xiangliang Yu | 534ff10 | 2011-05-24 22:26:50 +0800 | [diff] [blame] | 135 | struct mvs_device *mvs_find_dev_by_reg_set(struct mvs_info *mvi, |
| 136 | u8 reg_set) |
| 137 | { |
| 138 | u32 dev_no; |
| 139 | for (dev_no = 0; dev_no < MVS_MAX_DEVICES; dev_no++) { |
| 140 | if (mvi->devices[dev_no].taskfileset == MVS_ID_NOT_MAPPED) |
| 141 | continue; |
| 142 | |
| 143 | if (mvi->devices[dev_no].taskfileset == reg_set) |
| 144 | return &mvi->devices[dev_no]; |
| 145 | } |
| 146 | return NULL; |
| 147 | } |
| 148 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 149 | static inline void mvs_free_reg_set(struct mvs_info *mvi, |
| 150 | struct mvs_device *dev) |
| 151 | { |
| 152 | if (!dev) { |
| 153 | mv_printk("device has been free.\n"); |
| 154 | return; |
| 155 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 156 | if (dev->taskfileset == MVS_ID_NOT_MAPPED) |
| 157 | return; |
| 158 | MVS_CHIP_DISP->free_reg_set(mvi, &dev->taskfileset); |
| 159 | } |
| 160 | |
| 161 | static inline u8 mvs_assign_reg_set(struct mvs_info *mvi, |
| 162 | struct mvs_device *dev) |
| 163 | { |
| 164 | if (dev->taskfileset != MVS_ID_NOT_MAPPED) |
| 165 | return 0; |
| 166 | return MVS_CHIP_DISP->assign_reg_set(mvi, &dev->taskfileset); |
| 167 | } |
| 168 | |
| 169 | void mvs_phys_reset(struct mvs_info *mvi, u32 phy_mask, int hard) |
| 170 | { |
| 171 | u32 no; |
| 172 | for_each_phy(phy_mask, phy_mask, no) { |
| 173 | if (!(phy_mask & 1)) |
| 174 | continue; |
| 175 | MVS_CHIP_DISP->phy_reset(mvi, no, hard); |
| 176 | } |
| 177 | } |
| 178 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 179 | int mvs_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func, |
| 180 | void *funcdata) |
| 181 | { |
| 182 | int rc = 0, phy_id = sas_phy->id; |
| 183 | u32 tmp, i = 0, hi; |
| 184 | struct sas_ha_struct *sha = sas_phy->ha; |
| 185 | struct mvs_info *mvi = NULL; |
| 186 | |
| 187 | while (sha->sas_phy[i]) { |
| 188 | if (sha->sas_phy[i] == sas_phy) |
| 189 | break; |
| 190 | i++; |
| 191 | } |
| 192 | hi = i/((struct mvs_prv_info *)sha->lldd_ha)->n_phy; |
| 193 | mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[hi]; |
| 194 | |
| 195 | switch (func) { |
| 196 | case PHY_FUNC_SET_LINK_RATE: |
| 197 | MVS_CHIP_DISP->phy_set_link_rate(mvi, phy_id, funcdata); |
| 198 | break; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 199 | |
| 200 | case PHY_FUNC_HARD_RESET: |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 201 | tmp = MVS_CHIP_DISP->read_phy_ctl(mvi, phy_id); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 202 | if (tmp & PHY_RST_HARD) |
| 203 | break; |
Xiangliang Yu | a4632aa | 2011-05-24 22:36:02 +0800 | [diff] [blame] | 204 | MVS_CHIP_DISP->phy_reset(mvi, phy_id, MVS_HARD_RESET); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 205 | break; |
| 206 | |
| 207 | case PHY_FUNC_LINK_RESET: |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 208 | MVS_CHIP_DISP->phy_enable(mvi, phy_id); |
Xiangliang Yu | a4632aa | 2011-05-24 22:36:02 +0800 | [diff] [blame] | 209 | MVS_CHIP_DISP->phy_reset(mvi, phy_id, MVS_SOFT_RESET); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 210 | break; |
| 211 | |
| 212 | case PHY_FUNC_DISABLE: |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 213 | MVS_CHIP_DISP->phy_disable(mvi, phy_id); |
| 214 | break; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 215 | case PHY_FUNC_RELEASE_SPINUP_HOLD: |
| 216 | default: |
Dan Williams | ac013ed1 | 2011-09-28 18:48:02 -0700 | [diff] [blame] | 217 | rc = -ENOSYS; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 218 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 219 | msleep(200); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 220 | return rc; |
| 221 | } |
| 222 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 223 | void mvs_set_sas_addr(struct mvs_info *mvi, int port_id, u32 off_lo, |
| 224 | u32 off_hi, u64 sas_addr) |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 225 | { |
| 226 | u32 lo = (u32)sas_addr; |
| 227 | u32 hi = (u32)(sas_addr>>32); |
| 228 | |
| 229 | MVS_CHIP_DISP->write_port_cfg_addr(mvi, port_id, off_lo); |
| 230 | MVS_CHIP_DISP->write_port_cfg_data(mvi, port_id, lo); |
| 231 | MVS_CHIP_DISP->write_port_cfg_addr(mvi, port_id, off_hi); |
| 232 | MVS_CHIP_DISP->write_port_cfg_data(mvi, port_id, hi); |
| 233 | } |
| 234 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 235 | static void mvs_bytes_dmaed(struct mvs_info *mvi, int i) |
| 236 | { |
| 237 | struct mvs_phy *phy = &mvi->phy[i]; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 238 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
| 239 | struct sas_ha_struct *sas_ha; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 240 | if (!phy->phy_attached) |
| 241 | return; |
| 242 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 243 | if (!(phy->att_dev_info & PORT_DEV_TRGT_MASK) |
| 244 | && phy->phy_type & PORT_TYPE_SAS) { |
| 245 | return; |
| 246 | } |
| 247 | |
| 248 | sas_ha = mvi->sas; |
| 249 | sas_ha->notify_phy_event(sas_phy, PHYE_OOB_DONE); |
| 250 | |
Ke Wei | ee1f1c2 | 2008-03-27 14:53:47 +0800 | [diff] [blame] | 251 | if (sas_phy->phy) { |
| 252 | struct sas_phy *sphy = sas_phy->phy; |
| 253 | |
| 254 | sphy->negotiated_linkrate = sas_phy->linkrate; |
| 255 | sphy->minimum_linkrate = phy->minimum_linkrate; |
| 256 | sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; |
| 257 | sphy->maximum_linkrate = phy->maximum_linkrate; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 258 | sphy->maximum_linkrate_hw = MVS_CHIP_DISP->phy_max_link_rate(); |
Ke Wei | ee1f1c2 | 2008-03-27 14:53:47 +0800 | [diff] [blame] | 259 | } |
| 260 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 261 | if (phy->phy_type & PORT_TYPE_SAS) { |
| 262 | struct sas_identify_frame *id; |
| 263 | |
| 264 | id = (struct sas_identify_frame *)phy->frame_rcvd; |
| 265 | id->dev_type = phy->identify.device_type; |
| 266 | id->initiator_bits = SAS_PROTOCOL_ALL; |
| 267 | id->target_bits = phy->identify.target_port_protocols; |
Xiangliang Yu | 477f6d1 | 2011-09-29 00:33:49 -0700 | [diff] [blame] | 268 | |
| 269 | /* direct attached SAS device */ |
| 270 | if (phy->att_dev_info & PORT_SSP_TRGT_MASK) { |
| 271 | MVS_CHIP_DISP->write_port_cfg_addr(mvi, i, PHYR_PHY_STAT); |
| 272 | MVS_CHIP_DISP->write_port_cfg_data(mvi, i, 0x00); |
| 273 | } |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 274 | } else if (phy->phy_type & PORT_TYPE_SATA) { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 275 | /*Nothing*/ |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 276 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 277 | mv_dprintk("phy %d byte dmaded.\n", i + mvi->id * mvi->chip->n_phy); |
| 278 | |
| 279 | sas_phy->frame_rcvd_size = phy->frame_rcvd_size; |
| 280 | |
| 281 | mvi->sas->notify_port_event(sas_phy, |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 282 | PORTE_BYTES_DMAED); |
| 283 | } |
| 284 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 285 | void mvs_scan_start(struct Scsi_Host *shost) |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 286 | { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 287 | int i, j; |
| 288 | unsigned short core_nr; |
| 289 | struct mvs_info *mvi; |
| 290 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 291 | struct mvs_prv_info *mvs_prv = sha->lldd_ha; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 292 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 293 | core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host; |
| 294 | |
| 295 | for (j = 0; j < core_nr; j++) { |
| 296 | mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[j]; |
| 297 | for (i = 0; i < mvi->chip->n_phy; ++i) |
| 298 | mvs_bytes_dmaed(mvi, i); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 299 | } |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 300 | mvs_prv->scan_finished = 1; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 301 | } |
| 302 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 303 | int mvs_scan_finished(struct Scsi_Host *shost, unsigned long time) |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 304 | { |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 305 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
| 306 | struct mvs_prv_info *mvs_prv = sha->lldd_ha; |
| 307 | |
| 308 | if (mvs_prv->scan_finished == 0) |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 309 | return 0; |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 310 | |
Dan Williams | b1124cd | 2011-12-19 16:42:34 -0800 | [diff] [blame] | 311 | sas_drain_work(sha); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 312 | return 1; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 313 | } |
| 314 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 315 | static int mvs_task_prep_smp(struct mvs_info *mvi, |
| 316 | struct mvs_task_exec_info *tei) |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 317 | { |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 318 | int elem, rc, i; |
Xiangliang Yu | 7c237c5 | 2013-01-30 00:25:53 +0800 | [diff] [blame] | 319 | struct sas_ha_struct *sha = mvi->sas; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 320 | struct sas_task *task = tei->task; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 321 | struct mvs_cmd_hdr *hdr = tei->hdr; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 322 | struct domain_device *dev = task->dev; |
| 323 | struct asd_sas_port *sas_port = dev->port; |
Xiangliang Yu | 7c237c5 | 2013-01-30 00:25:53 +0800 | [diff] [blame] | 324 | struct sas_phy *sphy = dev->phy; |
| 325 | struct asd_sas_phy *sas_phy = sha->sas_phy[sphy->number]; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 326 | struct scatterlist *sg_req, *sg_resp; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 327 | u32 req_len, resp_len, tag = tei->tag; |
| 328 | void *buf_tmp; |
| 329 | u8 *buf_oaf; |
| 330 | dma_addr_t buf_tmp_dma; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 331 | void *buf_prd; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 332 | struct mvs_slot_info *slot = &mvi->slot_info[tag]; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 333 | u32 flags = (tei->n_elem << MCH_PRD_LEN_SHIFT); |
Xiangliang Yu | b89e8f5 | 2011-05-24 22:35:09 +0800 | [diff] [blame] | 334 | |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 335 | /* |
| 336 | * DMA-map SMP request, response buffers |
| 337 | */ |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 338 | sg_req = &task->smp_task.smp_req; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 339 | elem = dma_map_sg(mvi->dev, sg_req, 1, PCI_DMA_TODEVICE); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 340 | if (!elem) |
| 341 | return -ENOMEM; |
| 342 | req_len = sg_dma_len(sg_req); |
| 343 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 344 | sg_resp = &task->smp_task.smp_resp; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 345 | elem = dma_map_sg(mvi->dev, sg_resp, 1, PCI_DMA_FROMDEVICE); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 346 | if (!elem) { |
| 347 | rc = -ENOMEM; |
| 348 | goto err_out; |
| 349 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 350 | resp_len = SB_RFB_MAX; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 351 | |
| 352 | /* must be in dwords */ |
| 353 | if ((req_len & 0x3) || (resp_len & 0x3)) { |
| 354 | rc = -EINVAL; |
| 355 | goto err_out_2; |
| 356 | } |
| 357 | |
| 358 | /* |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 359 | * arrange MVS_SLOT_BUF_SZ-sized DMA buffer according to our needs |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 360 | */ |
| 361 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 362 | /* region 1: command table area (MVS_SSP_CMD_SZ bytes) ***** */ |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 363 | buf_tmp = slot->buf; |
| 364 | buf_tmp_dma = slot->buf_dma; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 365 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 366 | hdr->cmd_tbl = cpu_to_le64(sg_dma_address(sg_req)); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 367 | |
| 368 | /* region 2: open address frame area (MVS_OAF_SZ bytes) ********* */ |
| 369 | buf_oaf = buf_tmp; |
| 370 | hdr->open_frame = cpu_to_le64(buf_tmp_dma); |
| 371 | |
| 372 | buf_tmp += MVS_OAF_SZ; |
| 373 | buf_tmp_dma += MVS_OAF_SZ; |
| 374 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 375 | /* region 3: PRD table *********************************** */ |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 376 | buf_prd = buf_tmp; |
| 377 | if (tei->n_elem) |
| 378 | hdr->prd_tbl = cpu_to_le64(buf_tmp_dma); |
| 379 | else |
| 380 | hdr->prd_tbl = 0; |
| 381 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 382 | i = MVS_CHIP_DISP->prd_size() * tei->n_elem; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 383 | buf_tmp += i; |
| 384 | buf_tmp_dma += i; |
| 385 | |
| 386 | /* region 4: status buffer (larger the PRD, smaller this buf) ****** */ |
| 387 | slot->response = buf_tmp; |
| 388 | hdr->status_buf = cpu_to_le64(buf_tmp_dma); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 389 | if (mvi->flags & MVF_FLAG_SOC) |
| 390 | hdr->reserved[0] = 0; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 391 | |
| 392 | /* |
| 393 | * Fill in TX ring and command slot header |
| 394 | */ |
| 395 | slot->tx = mvi->tx_prod; |
| 396 | mvi->tx[mvi->tx_prod] = cpu_to_le32((TXQ_CMD_SMP << TXQ_CMD_SHIFT) | |
| 397 | TXQ_MODE_I | tag | |
Xiangliang Yu | 7c237c5 | 2013-01-30 00:25:53 +0800 | [diff] [blame] | 398 | (MVS_PHY_ID << TXQ_PHY_SHIFT)); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 399 | |
| 400 | hdr->flags |= flags; |
| 401 | hdr->lens = cpu_to_le32(((resp_len / 4) << 16) | ((req_len - 4) / 4)); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 402 | hdr->tags = cpu_to_le32(tag); |
| 403 | hdr->data_len = 0; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 404 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 405 | /* generate open address frame hdr (first 12 bytes) */ |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 406 | /* initiator, SMP, ftype 1h */ |
| 407 | buf_oaf[0] = (1 << 7) | (PROTOCOL_SMP << 4) | 0x01; |
Xiangliang Yu | 6ceae7c | 2011-09-29 00:32:37 -0700 | [diff] [blame] | 408 | buf_oaf[1] = min(sas_port->linkrate, dev->linkrate) & 0xf; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 409 | *(u16 *)(buf_oaf + 2) = 0xFFFF; /* SAS SPEC */ |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 410 | memcpy(buf_oaf + 4, dev->sas_addr, SAS_ADDR_SIZE); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 411 | |
| 412 | /* fill in PRD (scatter/gather) table, if any */ |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 413 | MVS_CHIP_DISP->make_prd(task->scatter, tei->n_elem, buf_prd); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 414 | |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 415 | return 0; |
| 416 | |
| 417 | err_out_2: |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 418 | dma_unmap_sg(mvi->dev, &tei->task->smp_task.smp_resp, 1, |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 419 | PCI_DMA_FROMDEVICE); |
| 420 | err_out: |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 421 | dma_unmap_sg(mvi->dev, &tei->task->smp_task.smp_req, 1, |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 422 | PCI_DMA_TODEVICE); |
| 423 | return rc; |
| 424 | } |
| 425 | |
Ke Wei | 4e52fc0 | 2008-03-27 14:54:50 +0800 | [diff] [blame] | 426 | static u32 mvs_get_ncq_tag(struct sas_task *task, u32 *tag) |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 427 | { |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 428 | struct ata_queued_cmd *qc = task->uldd_task; |
| 429 | |
Ke Wei | 4e52fc0 | 2008-03-27 14:54:50 +0800 | [diff] [blame] | 430 | if (qc) { |
| 431 | if (qc->tf.command == ATA_CMD_FPDMA_WRITE || |
| 432 | qc->tf.command == ATA_CMD_FPDMA_READ) { |
| 433 | *tag = qc->tag; |
| 434 | return 1; |
| 435 | } |
| 436 | } |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 437 | |
Ke Wei | 4e52fc0 | 2008-03-27 14:54:50 +0800 | [diff] [blame] | 438 | return 0; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 439 | } |
| 440 | |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 441 | static int mvs_task_prep_ata(struct mvs_info *mvi, |
| 442 | struct mvs_task_exec_info *tei) |
| 443 | { |
| 444 | struct sas_task *task = tei->task; |
| 445 | struct domain_device *dev = task->dev; |
Andy Yan | f9da3be | 2009-05-14 20:41:21 -0400 | [diff] [blame] | 446 | struct mvs_device *mvi_dev = dev->lldd_dev; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 447 | struct mvs_cmd_hdr *hdr = tei->hdr; |
| 448 | struct asd_sas_port *sas_port = dev->port; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 449 | struct mvs_slot_info *slot; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 450 | void *buf_prd; |
| 451 | u32 tag = tei->tag, hdr_tag; |
| 452 | u32 flags, del_q; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 453 | void *buf_tmp; |
| 454 | u8 *buf_cmd, *buf_oaf; |
| 455 | dma_addr_t buf_tmp_dma; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 456 | u32 i, req_len, resp_len; |
| 457 | const u32 max_resp_len = SB_RFB_MAX; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 458 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 459 | if (mvs_assign_reg_set(mvi, mvi_dev) == MVS_ID_NOT_MAPPED) { |
| 460 | mv_dprintk("Have not enough regiset for dev %d.\n", |
| 461 | mvi_dev->device_id); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 462 | return -EBUSY; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 463 | } |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 464 | slot = &mvi->slot_info[tag]; |
| 465 | slot->tx = mvi->tx_prod; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 466 | del_q = TXQ_MODE_I | tag | |
| 467 | (TXQ_CMD_STP << TXQ_CMD_SHIFT) | |
James Bottomley | 56cbd0c | 2015-04-15 22:16:01 -0700 | [diff] [blame] | 468 | ((sas_port->phy_mask & TXQ_PHY_MASK) << TXQ_PHY_SHIFT) | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 469 | (mvi_dev->taskfileset << TXQ_SRS_SHIFT); |
| 470 | mvi->tx[mvi->tx_prod] = cpu_to_le32(del_q); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 471 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 472 | if (task->data_dir == DMA_FROM_DEVICE) |
| 473 | flags = (MVS_CHIP_DISP->prd_count() << MCH_PRD_LEN_SHIFT); |
| 474 | else |
| 475 | flags = (tei->n_elem << MCH_PRD_LEN_SHIFT); |
Xiangliang Yu | 8882f08 | 2011-05-24 22:33:11 +0800 | [diff] [blame] | 476 | |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 477 | if (task->ata_task.use_ncq) |
| 478 | flags |= MCH_FPDMA; |
Hannes Reinecke | 1cbd772 | 2014-11-05 13:08:20 +0100 | [diff] [blame] | 479 | if (dev->sata_dev.class == ATA_DEV_ATAPI) { |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 480 | if (task->ata_task.fis.command != ATA_CMD_ID_ATAPI) |
| 481 | flags |= MCH_ATAPI; |
| 482 | } |
| 483 | |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 484 | hdr->flags = cpu_to_le32(flags); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 485 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 486 | if (task->ata_task.use_ncq && mvs_get_ncq_tag(task, &hdr_tag)) |
| 487 | task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3); |
Ke Wei | 4e52fc0 | 2008-03-27 14:54:50 +0800 | [diff] [blame] | 488 | else |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 489 | hdr_tag = tag; |
| 490 | |
| 491 | hdr->tags = cpu_to_le32(hdr_tag); |
| 492 | |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 493 | hdr->data_len = cpu_to_le32(task->total_xfer_len); |
| 494 | |
| 495 | /* |
| 496 | * arrange MVS_SLOT_BUF_SZ-sized DMA buffer according to our needs |
| 497 | */ |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 498 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 499 | /* region 1: command table area (MVS_ATA_CMD_SZ bytes) ************** */ |
| 500 | buf_cmd = buf_tmp = slot->buf; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 501 | buf_tmp_dma = slot->buf_dma; |
| 502 | |
| 503 | hdr->cmd_tbl = cpu_to_le64(buf_tmp_dma); |
| 504 | |
| 505 | buf_tmp += MVS_ATA_CMD_SZ; |
| 506 | buf_tmp_dma += MVS_ATA_CMD_SZ; |
| 507 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 508 | /* region 2: open address frame area (MVS_OAF_SZ bytes) ********* */ |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 509 | /* used for STP. unused for SATA? */ |
| 510 | buf_oaf = buf_tmp; |
| 511 | hdr->open_frame = cpu_to_le64(buf_tmp_dma); |
| 512 | |
| 513 | buf_tmp += MVS_OAF_SZ; |
| 514 | buf_tmp_dma += MVS_OAF_SZ; |
| 515 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 516 | /* region 3: PRD table ********************************************* */ |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 517 | buf_prd = buf_tmp; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 518 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 519 | if (tei->n_elem) |
| 520 | hdr->prd_tbl = cpu_to_le64(buf_tmp_dma); |
| 521 | else |
| 522 | hdr->prd_tbl = 0; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 523 | i = MVS_CHIP_DISP->prd_size() * MVS_CHIP_DISP->prd_count(); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 524 | |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 525 | buf_tmp += i; |
| 526 | buf_tmp_dma += i; |
| 527 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 528 | /* region 4: status buffer (larger the PRD, smaller this buf) ****** */ |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 529 | slot->response = buf_tmp; |
| 530 | hdr->status_buf = cpu_to_le64(buf_tmp_dma); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 531 | if (mvi->flags & MVF_FLAG_SOC) |
| 532 | hdr->reserved[0] = 0; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 533 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 534 | req_len = sizeof(struct host_to_dev_fis); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 535 | resp_len = MVS_SLOT_BUF_SZ - MVS_ATA_CMD_SZ - |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 536 | sizeof(struct mvs_err_info) - i; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 537 | |
| 538 | /* request, response lengths */ |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 539 | resp_len = min(resp_len, max_resp_len); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 540 | hdr->lens = cpu_to_le32(((resp_len / 4) << 16) | (req_len / 4)); |
| 541 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 542 | if (likely(!task->ata_task.device_control_reg_update)) |
| 543 | task->ata_task.fis.flags |= 0x80; /* C=1: update ATA cmd reg */ |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 544 | /* fill in command FIS and ATAPI CDB */ |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 545 | memcpy(buf_cmd, &task->ata_task.fis, sizeof(struct host_to_dev_fis)); |
Hannes Reinecke | 1cbd772 | 2014-11-05 13:08:20 +0100 | [diff] [blame] | 546 | if (dev->sata_dev.class == ATA_DEV_ATAPI) |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 547 | memcpy(buf_cmd + STP_ATAPI_CMD, |
| 548 | task->ata_task.atapi_packet, 16); |
| 549 | |
| 550 | /* generate open address frame hdr (first 12 bytes) */ |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 551 | /* initiator, STP, ftype 1h */ |
| 552 | buf_oaf[0] = (1 << 7) | (PROTOCOL_STP << 4) | 0x1; |
Xiangliang Yu | 6ceae7c | 2011-09-29 00:32:37 -0700 | [diff] [blame] | 553 | buf_oaf[1] = min(sas_port->linkrate, dev->linkrate) & 0xf; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 554 | *(u16 *)(buf_oaf + 2) = cpu_to_be16(mvi_dev->device_id + 1); |
| 555 | memcpy(buf_oaf + 4, dev->sas_addr, SAS_ADDR_SIZE); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 556 | |
| 557 | /* fill in PRD (scatter/gather) table, if any */ |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 558 | MVS_CHIP_DISP->make_prd(task->scatter, tei->n_elem, buf_prd); |
Xiangliang Yu | 8882f08 | 2011-05-24 22:33:11 +0800 | [diff] [blame] | 559 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 560 | if (task->data_dir == DMA_FROM_DEVICE) |
Xiangliang Yu | 8882f08 | 2011-05-24 22:33:11 +0800 | [diff] [blame] | 561 | MVS_CHIP_DISP->dma_fix(mvi, sas_port->phy_mask, |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 562 | TRASH_BUCKET_SIZE, tei->n_elem, buf_prd); |
Xiangliang Yu | 8882f08 | 2011-05-24 22:33:11 +0800 | [diff] [blame] | 563 | |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | static int mvs_task_prep_ssp(struct mvs_info *mvi, |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 568 | struct mvs_task_exec_info *tei, int is_tmf, |
| 569 | struct mvs_tmf_task *tmf) |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 570 | { |
| 571 | struct sas_task *task = tei->task; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 572 | struct mvs_cmd_hdr *hdr = tei->hdr; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 573 | struct mvs_port *port = tei->port; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 574 | struct domain_device *dev = task->dev; |
Andy Yan | f9da3be | 2009-05-14 20:41:21 -0400 | [diff] [blame] | 575 | struct mvs_device *mvi_dev = dev->lldd_dev; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 576 | struct asd_sas_port *sas_port = dev->port; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 577 | struct mvs_slot_info *slot; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 578 | void *buf_prd; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 579 | struct ssp_frame_hdr *ssp_hdr; |
| 580 | void *buf_tmp; |
| 581 | u8 *buf_cmd, *buf_oaf, fburst = 0; |
| 582 | dma_addr_t buf_tmp_dma; |
| 583 | u32 flags; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 584 | u32 resp_len, req_len, i, tag = tei->tag; |
| 585 | const u32 max_resp_len = SB_RFB_MAX; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 586 | u32 phy_mask; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 587 | |
| 588 | slot = &mvi->slot_info[tag]; |
| 589 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 590 | phy_mask = ((port->wide_port_phymap) ? port->wide_port_phymap : |
| 591 | sas_port->phy_mask) & TXQ_PHY_MASK; |
| 592 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 593 | slot->tx = mvi->tx_prod; |
| 594 | mvi->tx[mvi->tx_prod] = cpu_to_le32(TXQ_MODE_I | tag | |
| 595 | (TXQ_CMD_SSP << TXQ_CMD_SHIFT) | |
Ke Wei | 4e52fc0 | 2008-03-27 14:54:50 +0800 | [diff] [blame] | 596 | (phy_mask << TXQ_PHY_SHIFT)); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 597 | |
| 598 | flags = MCH_RETRY; |
| 599 | if (task->ssp_task.enable_first_burst) { |
| 600 | flags |= MCH_FBURST; |
| 601 | fburst = (1 << 7); |
| 602 | } |
Andy Yan | 2b28813 | 2009-05-11 20:01:55 +0800 | [diff] [blame] | 603 | if (is_tmf) |
| 604 | flags |= (MCH_SSP_FR_TASK << MCH_SSP_FR_TYPE_SHIFT); |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 605 | else |
| 606 | flags |= (MCH_SSP_FR_CMD << MCH_SSP_FR_TYPE_SHIFT); |
| 607 | |
Andy Yan | 2b28813 | 2009-05-11 20:01:55 +0800 | [diff] [blame] | 608 | hdr->flags = cpu_to_le32(flags | (tei->n_elem << MCH_PRD_LEN_SHIFT)); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 609 | hdr->tags = cpu_to_le32(tag); |
| 610 | hdr->data_len = cpu_to_le32(task->total_xfer_len); |
| 611 | |
| 612 | /* |
| 613 | * arrange MVS_SLOT_BUF_SZ-sized DMA buffer according to our needs |
| 614 | */ |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 615 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 616 | /* region 1: command table area (MVS_SSP_CMD_SZ bytes) ************** */ |
| 617 | buf_cmd = buf_tmp = slot->buf; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 618 | buf_tmp_dma = slot->buf_dma; |
| 619 | |
| 620 | hdr->cmd_tbl = cpu_to_le64(buf_tmp_dma); |
| 621 | |
| 622 | buf_tmp += MVS_SSP_CMD_SZ; |
| 623 | buf_tmp_dma += MVS_SSP_CMD_SZ; |
| 624 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 625 | /* region 2: open address frame area (MVS_OAF_SZ bytes) ********* */ |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 626 | buf_oaf = buf_tmp; |
| 627 | hdr->open_frame = cpu_to_le64(buf_tmp_dma); |
| 628 | |
| 629 | buf_tmp += MVS_OAF_SZ; |
| 630 | buf_tmp_dma += MVS_OAF_SZ; |
| 631 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 632 | /* region 3: PRD table ********************************************* */ |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 633 | buf_prd = buf_tmp; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 634 | if (tei->n_elem) |
| 635 | hdr->prd_tbl = cpu_to_le64(buf_tmp_dma); |
| 636 | else |
| 637 | hdr->prd_tbl = 0; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 638 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 639 | i = MVS_CHIP_DISP->prd_size() * tei->n_elem; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 640 | buf_tmp += i; |
| 641 | buf_tmp_dma += i; |
| 642 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 643 | /* region 4: status buffer (larger the PRD, smaller this buf) ****** */ |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 644 | slot->response = buf_tmp; |
| 645 | hdr->status_buf = cpu_to_le64(buf_tmp_dma); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 646 | if (mvi->flags & MVF_FLAG_SOC) |
| 647 | hdr->reserved[0] = 0; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 648 | |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 649 | resp_len = MVS_SLOT_BUF_SZ - MVS_SSP_CMD_SZ - MVS_OAF_SZ - |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 650 | sizeof(struct mvs_err_info) - i; |
| 651 | resp_len = min(resp_len, max_resp_len); |
| 652 | |
| 653 | req_len = sizeof(struct ssp_frame_hdr) + 28; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 654 | |
| 655 | /* request, response lengths */ |
| 656 | hdr->lens = cpu_to_le32(((resp_len / 4) << 16) | (req_len / 4)); |
| 657 | |
| 658 | /* generate open address frame hdr (first 12 bytes) */ |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 659 | /* initiator, SSP, ftype 1h */ |
| 660 | buf_oaf[0] = (1 << 7) | (PROTOCOL_SSP << 4) | 0x1; |
Xiangliang Yu | 6ceae7c | 2011-09-29 00:32:37 -0700 | [diff] [blame] | 661 | buf_oaf[1] = min(sas_port->linkrate, dev->linkrate) & 0xf; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 662 | *(u16 *)(buf_oaf + 2) = cpu_to_be16(mvi_dev->device_id + 1); |
| 663 | memcpy(buf_oaf + 4, dev->sas_addr, SAS_ADDR_SIZE); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 664 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 665 | /* fill in SSP frame header (Command Table.SSP frame header) */ |
| 666 | ssp_hdr = (struct ssp_frame_hdr *)buf_cmd; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 667 | |
| 668 | if (is_tmf) |
| 669 | ssp_hdr->frame_type = SSP_TASK; |
| 670 | else |
| 671 | ssp_hdr->frame_type = SSP_COMMAND; |
| 672 | |
| 673 | memcpy(ssp_hdr->hashed_dest_addr, dev->hashed_sas_addr, |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 674 | HASHED_SAS_ADDR_SIZE); |
| 675 | memcpy(ssp_hdr->hashed_src_addr, |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 676 | dev->hashed_sas_addr, HASHED_SAS_ADDR_SIZE); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 677 | ssp_hdr->tag = cpu_to_be16(tag); |
| 678 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 679 | /* fill in IU for TASK and Command Frame */ |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 680 | buf_cmd += sizeof(*ssp_hdr); |
| 681 | memcpy(buf_cmd, &task->ssp_task.LUN, 8); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 682 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 683 | if (ssp_hdr->frame_type != SSP_TASK) { |
| 684 | buf_cmd[9] = fburst | task->ssp_task.task_attr | |
| 685 | (task->ssp_task.task_prio << 3); |
James Bottomley | e73823f | 2013-05-07 15:38:18 -0700 | [diff] [blame] | 686 | memcpy(buf_cmd + 12, task->ssp_task.cmd->cmnd, |
| 687 | task->ssp_task.cmd->cmd_len); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 688 | } else{ |
| 689 | buf_cmd[10] = tmf->tmf; |
| 690 | switch (tmf->tmf) { |
| 691 | case TMF_ABORT_TASK: |
| 692 | case TMF_QUERY_TASK: |
| 693 | buf_cmd[12] = |
| 694 | (tmf->tag_of_task_to_be_managed >> 8) & 0xff; |
| 695 | buf_cmd[13] = |
| 696 | tmf->tag_of_task_to_be_managed & 0xff; |
| 697 | break; |
| 698 | default: |
| 699 | break; |
| 700 | } |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 701 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 702 | /* fill in PRD (scatter/gather) table, if any */ |
| 703 | MVS_CHIP_DISP->make_prd(task->scatter, tei->n_elem, buf_prd); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 704 | return 0; |
| 705 | } |
| 706 | |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 707 | #define DEV_IS_GONE(mvi_dev) ((!mvi_dev || (mvi_dev->dev_type == SAS_PHY_UNUSED))) |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 708 | static int mvs_task_prep(struct sas_task *task, struct mvs_info *mvi, int is_tmf, |
| 709 | struct mvs_tmf_task *tmf, int *pass) |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 710 | { |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 711 | struct domain_device *dev = task->dev; |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 712 | struct mvs_device *mvi_dev = dev->lldd_dev; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 713 | struct mvs_task_exec_info tei; |
Ke Wei | 4e52fc0 | 2008-03-27 14:54:50 +0800 | [diff] [blame] | 714 | struct mvs_slot_info *slot; |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 715 | u32 tag = 0xdeadbeef, n_elem = 0; |
| 716 | int rc = 0; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 717 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 718 | if (!dev->port) { |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 719 | struct task_status_struct *tsm = &task->task_status; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 720 | |
| 721 | tsm->resp = SAS_TASK_UNDELIVERED; |
| 722 | tsm->stat = SAS_PHY_DOWN; |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 723 | /* |
| 724 | * libsas will use dev->port, should |
| 725 | * not call task_done for sata |
| 726 | */ |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 727 | if (dev->dev_type != SAS_SATA_DEV) |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 728 | task->task_done(task); |
| 729 | return rc; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 730 | } |
| 731 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 732 | if (DEV_IS_GONE(mvi_dev)) { |
| 733 | if (mvi_dev) |
| 734 | mv_dprintk("device %d not ready.\n", |
| 735 | mvi_dev->device_id); |
| 736 | else |
| 737 | mv_dprintk("device %016llx not ready.\n", |
| 738 | SAS_ADDR(dev->sas_addr)); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 739 | |
| 740 | rc = SAS_PHY_DOWN; |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 741 | return rc; |
| 742 | } |
| 743 | tei.port = dev->port->lldd_port; |
| 744 | if (tei.port && !tei.port->port_attached && !tmf) { |
| 745 | if (sas_protocol_ata(task->task_proto)) { |
| 746 | struct task_status_struct *ts = &task->task_status; |
| 747 | mv_dprintk("SATA/STP port %d does not attach" |
| 748 | "device.\n", dev->port->id); |
| 749 | ts->resp = SAS_TASK_COMPLETE; |
| 750 | ts->stat = SAS_PHY_DOWN; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 751 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 752 | task->task_done(task); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 753 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 754 | } else { |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 755 | struct task_status_struct *ts = &task->task_status; |
| 756 | mv_dprintk("SAS port %d does not attach" |
| 757 | "device.\n", dev->port->id); |
| 758 | ts->resp = SAS_TASK_UNDELIVERED; |
| 759 | ts->stat = SAS_PHY_DOWN; |
| 760 | task->task_done(task); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 761 | } |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 762 | return rc; |
| 763 | } |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 764 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 765 | if (!sas_protocol_ata(task->task_proto)) { |
| 766 | if (task->num_scatter) { |
| 767 | n_elem = dma_map_sg(mvi->dev, |
| 768 | task->scatter, |
| 769 | task->num_scatter, |
| 770 | task->data_dir); |
| 771 | if (!n_elem) { |
| 772 | rc = -ENOMEM; |
| 773 | goto prep_out; |
| 774 | } |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 775 | } |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 776 | } else { |
| 777 | n_elem = task->num_scatter; |
| 778 | } |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 779 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 780 | rc = mvs_tag_alloc(mvi, &tag); |
| 781 | if (rc) |
| 782 | goto err_out; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 783 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 784 | slot = &mvi->slot_info[tag]; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 785 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 786 | task->lldd_task = NULL; |
| 787 | slot->n_elem = n_elem; |
| 788 | slot->slot_tag = tag; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 789 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 790 | slot->buf = pci_pool_alloc(mvi->dma_pool, GFP_ATOMIC, &slot->buf_dma); |
| 791 | if (!slot->buf) |
| 792 | goto err_out_tag; |
| 793 | memset(slot->buf, 0, MVS_SLOT_BUF_SZ); |
| 794 | |
| 795 | tei.task = task; |
| 796 | tei.hdr = &mvi->slot[tag]; |
| 797 | tei.tag = tag; |
| 798 | tei.n_elem = n_elem; |
| 799 | switch (task->task_proto) { |
| 800 | case SAS_PROTOCOL_SMP: |
| 801 | rc = mvs_task_prep_smp(mvi, &tei); |
| 802 | break; |
| 803 | case SAS_PROTOCOL_SSP: |
| 804 | rc = mvs_task_prep_ssp(mvi, &tei, is_tmf, tmf); |
| 805 | break; |
| 806 | case SAS_PROTOCOL_SATA: |
| 807 | case SAS_PROTOCOL_STP: |
| 808 | case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: |
| 809 | rc = mvs_task_prep_ata(mvi, &tei); |
| 810 | break; |
| 811 | default: |
| 812 | dev_printk(KERN_ERR, mvi->dev, |
| 813 | "unknown sas_task proto: 0x%x\n", |
| 814 | task->task_proto); |
| 815 | rc = -EINVAL; |
| 816 | break; |
| 817 | } |
| 818 | |
| 819 | if (rc) { |
| 820 | mv_dprintk("rc is %x\n", rc); |
| 821 | goto err_out_slot_buf; |
| 822 | } |
| 823 | slot->task = task; |
| 824 | slot->port = tei.port; |
| 825 | task->lldd_task = slot; |
| 826 | list_add_tail(&slot->entry, &tei.port->list); |
| 827 | spin_lock(&task->task_state_lock); |
| 828 | task->task_state_flags |= SAS_TASK_AT_INITIATOR; |
| 829 | spin_unlock(&task->task_state_lock); |
| 830 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 831 | mvi_dev->running_req++; |
| 832 | ++(*pass); |
| 833 | mvi->tx_prod = (mvi->tx_prod + 1) & (MVS_CHIP_SLOT_SZ - 1); |
| 834 | |
| 835 | return rc; |
| 836 | |
| 837 | err_out_slot_buf: |
| 838 | pci_pool_free(mvi->dma_pool, slot->buf, slot->buf_dma); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 839 | err_out_tag: |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 840 | mvs_tag_free(mvi, tag); |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 841 | err_out: |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 842 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 843 | dev_printk(KERN_ERR, mvi->dev, "mvsas prep failed[%d]!\n", rc); |
| 844 | if (!sas_protocol_ata(task->task_proto)) |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 845 | if (n_elem) |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 846 | dma_unmap_sg(mvi->dev, task->scatter, n_elem, |
| 847 | task->data_dir); |
| 848 | prep_out: |
| 849 | return rc; |
| 850 | } |
| 851 | |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 852 | static int mvs_task_exec(struct sas_task *task, gfp_t gfp_flags, |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 853 | struct completion *completion, int is_tmf, |
| 854 | struct mvs_tmf_task *tmf) |
| 855 | { |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 856 | struct mvs_info *mvi = NULL; |
| 857 | u32 rc = 0; |
| 858 | u32 pass = 0; |
| 859 | unsigned long flags = 0; |
| 860 | |
| 861 | mvi = ((struct mvs_device *)task->dev->lldd_dev)->mvi_info; |
| 862 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 863 | spin_lock_irqsave(&mvi->lock, flags); |
| 864 | rc = mvs_task_prep(task, mvi, is_tmf, tmf, &pass); |
| 865 | if (rc) |
| 866 | dev_printk(KERN_ERR, mvi->dev, "mvsas exec failed[%d]!\n", rc); |
| 867 | |
| 868 | if (likely(pass)) |
| 869 | MVS_CHIP_DISP->start_delivery(mvi, (mvi->tx_prod - 1) & |
| 870 | (MVS_CHIP_SLOT_SZ - 1)); |
Andy Yan | 0b84b70 | 2009-05-11 20:05:26 +0800 | [diff] [blame] | 871 | spin_unlock_irqrestore(&mvi->lock, flags); |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 872 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 873 | return rc; |
| 874 | } |
| 875 | |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 876 | int mvs_queue_command(struct sas_task *task, gfp_t gfp_flags) |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 877 | { |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 878 | return mvs_task_exec(task, gfp_flags, NULL, 0, NULL); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 879 | } |
| 880 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 881 | static void mvs_slot_free(struct mvs_info *mvi, u32 rx_desc) |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 882 | { |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 883 | u32 slot_idx = rx_desc & RXQ_SLOT_MASK; |
| 884 | mvs_tag_clear(mvi, slot_idx); |
| 885 | } |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 886 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 887 | static void mvs_slot_task_free(struct mvs_info *mvi, struct sas_task *task, |
| 888 | struct mvs_slot_info *slot, u32 slot_idx) |
| 889 | { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 890 | if (!slot->task) |
| 891 | return; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 892 | if (!sas_protocol_ata(task->task_proto)) |
| 893 | if (slot->n_elem) |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 894 | dma_unmap_sg(mvi->dev, task->scatter, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 895 | slot->n_elem, task->data_dir); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 896 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 897 | switch (task->task_proto) { |
| 898 | case SAS_PROTOCOL_SMP: |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 899 | dma_unmap_sg(mvi->dev, &task->smp_task.smp_resp, 1, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 900 | PCI_DMA_FROMDEVICE); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 901 | dma_unmap_sg(mvi->dev, &task->smp_task.smp_req, 1, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 902 | PCI_DMA_TODEVICE); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 903 | break; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 904 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 905 | case SAS_PROTOCOL_SATA: |
| 906 | case SAS_PROTOCOL_STP: |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 907 | case SAS_PROTOCOL_SSP: |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 908 | default: |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 909 | /* do nothing */ |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 910 | break; |
| 911 | } |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 912 | |
| 913 | if (slot->buf) { |
| 914 | pci_pool_free(mvi->dma_pool, slot->buf, slot->buf_dma); |
| 915 | slot->buf = NULL; |
| 916 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 917 | list_del_init(&slot->entry); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 918 | task->lldd_task = NULL; |
| 919 | slot->task = NULL; |
| 920 | slot->port = NULL; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 921 | slot->slot_tag = 0xFFFFFFFF; |
| 922 | mvs_slot_free(mvi, slot_idx); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 923 | } |
| 924 | |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 925 | static void mvs_update_wideport(struct mvs_info *mvi, int phy_no) |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 926 | { |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 927 | struct mvs_phy *phy = &mvi->phy[phy_no]; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 928 | struct mvs_port *port = phy->port; |
| 929 | int j, no; |
| 930 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 931 | for_each_phy(port->wide_port_phymap, j, no) { |
| 932 | if (j & 1) { |
| 933 | MVS_CHIP_DISP->write_port_cfg_addr(mvi, no, |
| 934 | PHYR_WIDE_PORT); |
| 935 | MVS_CHIP_DISP->write_port_cfg_data(mvi, no, |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 936 | port->wide_port_phymap); |
| 937 | } else { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 938 | MVS_CHIP_DISP->write_port_cfg_addr(mvi, no, |
| 939 | PHYR_WIDE_PORT); |
| 940 | MVS_CHIP_DISP->write_port_cfg_data(mvi, no, |
| 941 | 0); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 942 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 943 | } |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | static u32 mvs_is_phy_ready(struct mvs_info *mvi, int i) |
| 947 | { |
| 948 | u32 tmp; |
| 949 | struct mvs_phy *phy = &mvi->phy[i]; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 950 | struct mvs_port *port = phy->port; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 951 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 952 | tmp = MVS_CHIP_DISP->read_phy_ctl(mvi, i); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 953 | if ((tmp & PHY_READY_MASK) && !(phy->irq_status & PHYEV_POOF)) { |
Ke Wei | 963829e | 2008-03-27 14:55:23 +0800 | [diff] [blame] | 954 | if (!port) |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 955 | phy->phy_attached = 1; |
| 956 | return tmp; |
| 957 | } |
| 958 | |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 959 | if (port) { |
| 960 | if (phy->phy_type & PORT_TYPE_SAS) { |
| 961 | port->wide_port_phymap &= ~(1U << i); |
| 962 | if (!port->wide_port_phymap) |
| 963 | port->port_attached = 0; |
| 964 | mvs_update_wideport(mvi, i); |
| 965 | } else if (phy->phy_type & PORT_TYPE_SATA) |
| 966 | port->port_attached = 0; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 967 | phy->port = NULL; |
| 968 | phy->phy_attached = 0; |
| 969 | phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA); |
| 970 | } |
| 971 | return 0; |
| 972 | } |
| 973 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 974 | static void *mvs_get_d2h_reg(struct mvs_info *mvi, int i, void *buf) |
| 975 | { |
| 976 | u32 *s = (u32 *) buf; |
| 977 | |
| 978 | if (!s) |
| 979 | return NULL; |
| 980 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 981 | MVS_CHIP_DISP->write_port_cfg_addr(mvi, i, PHYR_SATA_SIG3); |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 982 | s[3] = cpu_to_le32(MVS_CHIP_DISP->read_port_cfg_data(mvi, i)); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 983 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 984 | MVS_CHIP_DISP->write_port_cfg_addr(mvi, i, PHYR_SATA_SIG2); |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 985 | s[2] = cpu_to_le32(MVS_CHIP_DISP->read_port_cfg_data(mvi, i)); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 986 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 987 | MVS_CHIP_DISP->write_port_cfg_addr(mvi, i, PHYR_SATA_SIG1); |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 988 | s[1] = cpu_to_le32(MVS_CHIP_DISP->read_port_cfg_data(mvi, i)); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 989 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 990 | MVS_CHIP_DISP->write_port_cfg_addr(mvi, i, PHYR_SATA_SIG0); |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 991 | s[0] = cpu_to_le32(MVS_CHIP_DISP->read_port_cfg_data(mvi, i)); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 992 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 993 | if (((s[1] & 0x00FFFFFF) == 0x00EB1401) && (*(u8 *)&s[3] == 0x01)) |
| 994 | s[1] = 0x00EB1401 | (*((u8 *)&s[1] + 3) & 0x10); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 995 | |
Andy Yan | f9da3be | 2009-05-14 20:41:21 -0400 | [diff] [blame] | 996 | return s; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | static u32 mvs_is_sig_fis_received(u32 irq_status) |
| 1000 | { |
| 1001 | return irq_status & PHYEV_SIG_FIS; |
| 1002 | } |
| 1003 | |
Xiangliang Yu | 8882f08 | 2011-05-24 22:33:11 +0800 | [diff] [blame] | 1004 | static void mvs_sig_remove_timer(struct mvs_phy *phy) |
| 1005 | { |
| 1006 | if (phy->timer.function) |
| 1007 | del_timer(&phy->timer); |
| 1008 | phy->timer.function = NULL; |
| 1009 | } |
| 1010 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1011 | void mvs_update_phyinfo(struct mvs_info *mvi, int i, int get_st) |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1012 | { |
| 1013 | struct mvs_phy *phy = &mvi->phy[i]; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1014 | struct sas_identify_frame *id; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1015 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1016 | id = (struct sas_identify_frame *)phy->frame_rcvd; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1017 | |
| 1018 | if (get_st) { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1019 | phy->irq_status = MVS_CHIP_DISP->read_port_irq_stat(mvi, i); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1020 | phy->phy_status = mvs_is_phy_ready(mvi, i); |
| 1021 | } |
| 1022 | |
| 1023 | if (phy->phy_status) { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1024 | int oob_done = 0; |
| 1025 | struct asd_sas_phy *sas_phy = &mvi->phy[i].sas_phy; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1026 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1027 | oob_done = MVS_CHIP_DISP->oob_done(mvi, i); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1028 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1029 | MVS_CHIP_DISP->fix_phy_info(mvi, i, id); |
| 1030 | if (phy->phy_type & PORT_TYPE_SATA) { |
| 1031 | phy->identify.target_port_protocols = SAS_PROTOCOL_STP; |
| 1032 | if (mvs_is_sig_fis_received(phy->irq_status)) { |
Xiangliang Yu | 8882f08 | 2011-05-24 22:33:11 +0800 | [diff] [blame] | 1033 | mvs_sig_remove_timer(phy); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1034 | phy->phy_attached = 1; |
| 1035 | phy->att_dev_sas_addr = |
| 1036 | i + mvi->id * mvi->chip->n_phy; |
| 1037 | if (oob_done) |
| 1038 | sas_phy->oob_mode = SATA_OOB_MODE; |
| 1039 | phy->frame_rcvd_size = |
| 1040 | sizeof(struct dev_to_host_fis); |
Andy Yan | f9da3be | 2009-05-14 20:41:21 -0400 | [diff] [blame] | 1041 | mvs_get_d2h_reg(mvi, i, id); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1042 | } else { |
| 1043 | u32 tmp; |
| 1044 | dev_printk(KERN_DEBUG, mvi->dev, |
| 1045 | "Phy%d : No sig fis\n", i); |
| 1046 | tmp = MVS_CHIP_DISP->read_port_irq_mask(mvi, i); |
| 1047 | MVS_CHIP_DISP->write_port_irq_mask(mvi, i, |
| 1048 | tmp | PHYEV_SIG_FIS); |
| 1049 | phy->phy_attached = 0; |
| 1050 | phy->phy_type &= ~PORT_TYPE_SATA; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1051 | goto out_done; |
| 1052 | } |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1053 | } else if (phy->phy_type & PORT_TYPE_SAS |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1054 | || phy->att_dev_info & PORT_SSP_INIT_MASK) { |
| 1055 | phy->phy_attached = 1; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1056 | phy->identify.device_type = |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1057 | phy->att_dev_info & PORT_DEV_TYPE_MASK; |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1058 | |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 1059 | if (phy->identify.device_type == SAS_END_DEVICE) |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1060 | phy->identify.target_port_protocols = |
| 1061 | SAS_PROTOCOL_SSP; |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 1062 | else if (phy->identify.device_type != SAS_PHY_UNUSED) |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1063 | phy->identify.target_port_protocols = |
| 1064 | SAS_PROTOCOL_SMP; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1065 | if (oob_done) |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1066 | sas_phy->oob_mode = SAS_OOB_MODE; |
| 1067 | phy->frame_rcvd_size = |
| 1068 | sizeof(struct sas_identify_frame); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1069 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1070 | memcpy(sas_phy->attached_sas_addr, |
| 1071 | &phy->att_dev_sas_addr, SAS_ADDR_SIZE); |
Ke Wei | e9ff91b | 2008-03-27 14:55:33 +0800 | [diff] [blame] | 1072 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1073 | if (MVS_CHIP_DISP->phy_work_around) |
| 1074 | MVS_CHIP_DISP->phy_work_around(mvi, i); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1075 | } |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1076 | mv_dprintk("phy %d attach dev info is %x\n", |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1077 | i + mvi->id * mvi->chip->n_phy, phy->att_dev_info); |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1078 | mv_dprintk("phy %d attach sas addr is %llx\n", |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1079 | i + mvi->id * mvi->chip->n_phy, phy->att_dev_sas_addr); |
Ke Wei | e9ff91b | 2008-03-27 14:55:33 +0800 | [diff] [blame] | 1080 | out_done: |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1081 | if (get_st) |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1082 | MVS_CHIP_DISP->write_port_irq_stat(mvi, i, phy->irq_status); |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1083 | } |
| 1084 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1085 | static void mvs_port_notify_formed(struct asd_sas_phy *sas_phy, int lock) |
| 1086 | { |
| 1087 | struct sas_ha_struct *sas_ha = sas_phy->ha; |
| 1088 | struct mvs_info *mvi = NULL; int i = 0, hi; |
| 1089 | struct mvs_phy *phy = sas_phy->lldd_phy; |
| 1090 | struct asd_sas_port *sas_port = sas_phy->port; |
| 1091 | struct mvs_port *port; |
| 1092 | unsigned long flags = 0; |
| 1093 | if (!sas_port) |
| 1094 | return; |
| 1095 | |
| 1096 | while (sas_ha->sas_phy[i]) { |
| 1097 | if (sas_ha->sas_phy[i] == sas_phy) |
| 1098 | break; |
| 1099 | i++; |
| 1100 | } |
| 1101 | hi = i/((struct mvs_prv_info *)sas_ha->lldd_ha)->n_phy; |
| 1102 | mvi = ((struct mvs_prv_info *)sas_ha->lldd_ha)->mvi[hi]; |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1103 | if (i >= mvi->chip->n_phy) |
| 1104 | port = &mvi->port[i - mvi->chip->n_phy]; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1105 | else |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1106 | port = &mvi->port[i]; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1107 | if (lock) |
| 1108 | spin_lock_irqsave(&mvi->lock, flags); |
| 1109 | port->port_attached = 1; |
| 1110 | phy->port = port; |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 1111 | sas_port->lldd_port = port; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1112 | if (phy->phy_type & PORT_TYPE_SAS) { |
| 1113 | port->wide_port_phymap = sas_port->phy_mask; |
| 1114 | mv_printk("set wide port phy map %x\n", sas_port->phy_mask); |
| 1115 | mvs_update_wideport(mvi, sas_phy->id); |
Xiangliang Yu | 477f6d1 | 2011-09-29 00:33:49 -0700 | [diff] [blame] | 1116 | |
| 1117 | /* direct attached SAS device */ |
| 1118 | if (phy->att_dev_info & PORT_SSP_TRGT_MASK) { |
| 1119 | MVS_CHIP_DISP->write_port_cfg_addr(mvi, i, PHYR_PHY_STAT); |
| 1120 | MVS_CHIP_DISP->write_port_cfg_data(mvi, i, 0x04); |
| 1121 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1122 | } |
| 1123 | if (lock) |
| 1124 | spin_unlock_irqrestore(&mvi->lock, flags); |
| 1125 | } |
| 1126 | |
| 1127 | static void mvs_port_notify_deformed(struct asd_sas_phy *sas_phy, int lock) |
| 1128 | { |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1129 | struct domain_device *dev; |
| 1130 | struct mvs_phy *phy = sas_phy->lldd_phy; |
| 1131 | struct mvs_info *mvi = phy->mvi; |
| 1132 | struct asd_sas_port *port = sas_phy->port; |
| 1133 | int phy_no = 0; |
| 1134 | |
| 1135 | while (phy != &mvi->phy[phy_no]) { |
| 1136 | phy_no++; |
| 1137 | if (phy_no >= MVS_MAX_PHYS) |
| 1138 | return; |
| 1139 | } |
| 1140 | list_for_each_entry(dev, &port->dev_list, dev_list_node) |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1141 | mvs_do_release_task(phy->mvi, phy_no, dev); |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1142 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1146 | void mvs_port_formed(struct asd_sas_phy *sas_phy) |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1147 | { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1148 | mvs_port_notify_formed(sas_phy, 1); |
| 1149 | } |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1150 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1151 | void mvs_port_deformed(struct asd_sas_phy *sas_phy) |
| 1152 | { |
| 1153 | mvs_port_notify_deformed(sas_phy, 1); |
| 1154 | } |
| 1155 | |
| 1156 | struct mvs_device *mvs_alloc_dev(struct mvs_info *mvi) |
| 1157 | { |
| 1158 | u32 dev; |
| 1159 | for (dev = 0; dev < MVS_MAX_DEVICES; dev++) { |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 1160 | if (mvi->devices[dev].dev_type == SAS_PHY_UNUSED) { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1161 | mvi->devices[dev].device_id = dev; |
| 1162 | return &mvi->devices[dev]; |
| 1163 | } |
Ke Wei | 8f261aa | 2008-02-23 21:15:27 +0800 | [diff] [blame] | 1164 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1165 | |
| 1166 | if (dev == MVS_MAX_DEVICES) |
| 1167 | mv_printk("max support %d devices, ignore ..\n", |
| 1168 | MVS_MAX_DEVICES); |
| 1169 | |
| 1170 | return NULL; |
| 1171 | } |
| 1172 | |
| 1173 | void mvs_free_dev(struct mvs_device *mvi_dev) |
| 1174 | { |
| 1175 | u32 id = mvi_dev->device_id; |
| 1176 | memset(mvi_dev, 0, sizeof(*mvi_dev)); |
| 1177 | mvi_dev->device_id = id; |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 1178 | mvi_dev->dev_type = SAS_PHY_UNUSED; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1179 | mvi_dev->dev_status = MVS_DEV_NORMAL; |
| 1180 | mvi_dev->taskfileset = MVS_ID_NOT_MAPPED; |
| 1181 | } |
| 1182 | |
| 1183 | int mvs_dev_found_notify(struct domain_device *dev, int lock) |
| 1184 | { |
| 1185 | unsigned long flags = 0; |
| 1186 | int res = 0; |
| 1187 | struct mvs_info *mvi = NULL; |
| 1188 | struct domain_device *parent_dev = dev->parent; |
| 1189 | struct mvs_device *mvi_device; |
| 1190 | |
| 1191 | mvi = mvs_find_dev_mvi(dev); |
| 1192 | |
| 1193 | if (lock) |
| 1194 | spin_lock_irqsave(&mvi->lock, flags); |
| 1195 | |
| 1196 | mvi_device = mvs_alloc_dev(mvi); |
| 1197 | if (!mvi_device) { |
| 1198 | res = -1; |
| 1199 | goto found_out; |
| 1200 | } |
Andy Yan | f9da3be | 2009-05-14 20:41:21 -0400 | [diff] [blame] | 1201 | dev->lldd_dev = mvi_device; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1202 | mvi_device->dev_status = MVS_DEV_NORMAL; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1203 | mvi_device->dev_type = dev->dev_type; |
Andy Yan | 9870d9a | 2009-05-11 22:19:25 +0800 | [diff] [blame] | 1204 | mvi_device->mvi_info = mvi; |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1205 | mvi_device->sas_device = dev; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1206 | if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type)) { |
| 1207 | int phy_id; |
| 1208 | u8 phy_num = parent_dev->ex_dev.num_phys; |
| 1209 | struct ex_phy *phy; |
| 1210 | for (phy_id = 0; phy_id < phy_num; phy_id++) { |
| 1211 | phy = &parent_dev->ex_dev.ex_phy[phy_id]; |
| 1212 | if (SAS_ADDR(phy->attached_sas_addr) == |
| 1213 | SAS_ADDR(dev->sas_addr)) { |
| 1214 | mvi_device->attached_phy = phy_id; |
| 1215 | break; |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | if (phy_id == phy_num) { |
| 1220 | mv_printk("Error: no attached dev:%016llx" |
| 1221 | "at ex:%016llx.\n", |
| 1222 | SAS_ADDR(dev->sas_addr), |
| 1223 | SAS_ADDR(parent_dev->sas_addr)); |
| 1224 | res = -1; |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | found_out: |
| 1229 | if (lock) |
| 1230 | spin_unlock_irqrestore(&mvi->lock, flags); |
| 1231 | return res; |
| 1232 | } |
| 1233 | |
| 1234 | int mvs_dev_found(struct domain_device *dev) |
| 1235 | { |
| 1236 | return mvs_dev_found_notify(dev, 1); |
| 1237 | } |
| 1238 | |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1239 | void mvs_dev_gone_notify(struct domain_device *dev) |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1240 | { |
| 1241 | unsigned long flags = 0; |
Andy Yan | f9da3be | 2009-05-14 20:41:21 -0400 | [diff] [blame] | 1242 | struct mvs_device *mvi_dev = dev->lldd_dev; |
Rickard Strandqvist | eaa015d | 2014-05-18 18:12:26 +0200 | [diff] [blame] | 1243 | struct mvs_info *mvi; |
| 1244 | |
| 1245 | if (!mvi_dev) { |
| 1246 | mv_dprintk("found dev has gone.\n"); |
| 1247 | return; |
| 1248 | } |
| 1249 | |
| 1250 | mvi = mvi_dev->mvi_info; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1251 | |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1252 | spin_lock_irqsave(&mvi->lock, flags); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1253 | |
Rickard Strandqvist | eaa015d | 2014-05-18 18:12:26 +0200 | [diff] [blame] | 1254 | mv_dprintk("found dev[%d:%x] is gone.\n", |
| 1255 | mvi_dev->device_id, mvi_dev->dev_type); |
| 1256 | mvs_release_task(mvi, dev); |
| 1257 | mvs_free_reg_set(mvi, mvi_dev); |
| 1258 | mvs_free_dev(mvi_dev); |
| 1259 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1260 | dev->lldd_dev = NULL; |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1261 | mvi_dev->sas_device = NULL; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1262 | |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1263 | spin_unlock_irqrestore(&mvi->lock, flags); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | |
| 1267 | void mvs_dev_gone(struct domain_device *dev) |
| 1268 | { |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1269 | mvs_dev_gone_notify(dev); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1270 | } |
| 1271 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1272 | static void mvs_task_done(struct sas_task *task) |
| 1273 | { |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 1274 | if (!del_timer(&task->slow_task->timer)) |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1275 | return; |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 1276 | complete(&task->slow_task->completion); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | static void mvs_tmf_timedout(unsigned long data) |
| 1280 | { |
| 1281 | struct sas_task *task = (struct sas_task *)data; |
| 1282 | |
| 1283 | task->task_state_flags |= SAS_TASK_STATE_ABORTED; |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 1284 | complete(&task->slow_task->completion); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1285 | } |
| 1286 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1287 | #define MVS_TASK_TIMEOUT 20 |
| 1288 | static int mvs_exec_internal_tmf_task(struct domain_device *dev, |
| 1289 | void *parameter, u32 para_len, struct mvs_tmf_task *tmf) |
| 1290 | { |
| 1291 | int res, retry; |
| 1292 | struct sas_task *task = NULL; |
| 1293 | |
| 1294 | for (retry = 0; retry < 3; retry++) { |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 1295 | task = sas_alloc_slow_task(GFP_KERNEL); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1296 | if (!task) |
| 1297 | return -ENOMEM; |
| 1298 | |
| 1299 | task->dev = dev; |
| 1300 | task->task_proto = dev->tproto; |
| 1301 | |
| 1302 | memcpy(&task->ssp_task, parameter, para_len); |
| 1303 | task->task_done = mvs_task_done; |
| 1304 | |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 1305 | task->slow_task->timer.data = (unsigned long) task; |
| 1306 | task->slow_task->timer.function = mvs_tmf_timedout; |
| 1307 | task->slow_task->timer.expires = jiffies + MVS_TASK_TIMEOUT*HZ; |
| 1308 | add_timer(&task->slow_task->timer); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1309 | |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 1310 | res = mvs_task_exec(task, GFP_KERNEL, NULL, 1, tmf); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1311 | |
| 1312 | if (res) { |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 1313 | del_timer(&task->slow_task->timer); |
Masanari Iida | 6d3be30 | 2013-09-30 23:19:09 +0900 | [diff] [blame] | 1314 | mv_printk("executing internal task failed:%d\n", res); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1315 | goto ex_err; |
| 1316 | } |
| 1317 | |
Dan Williams | f0bf750 | 2012-06-21 23:36:30 -0700 | [diff] [blame] | 1318 | wait_for_completion(&task->slow_task->completion); |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1319 | res = TMF_RESP_FUNC_FAILED; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1320 | /* Even TMF timed out, return direct. */ |
| 1321 | if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) { |
| 1322 | if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { |
| 1323 | mv_printk("TMF task[%x] timeout.\n", tmf->tmf); |
| 1324 | goto ex_err; |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
James Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 1329 | task->task_status.stat == SAM_STAT_GOOD) { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1330 | res = TMF_RESP_FUNC_COMPLETE; |
| 1331 | break; |
| 1332 | } |
| 1333 | |
| 1334 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
| 1335 | task->task_status.stat == SAS_DATA_UNDERRUN) { |
| 1336 | /* no error, but return the number of bytes of |
| 1337 | * underrun */ |
| 1338 | res = task->task_status.residual; |
| 1339 | break; |
| 1340 | } |
| 1341 | |
| 1342 | if (task->task_status.resp == SAS_TASK_COMPLETE && |
| 1343 | task->task_status.stat == SAS_DATA_OVERRUN) { |
| 1344 | mv_dprintk("blocked task error.\n"); |
| 1345 | res = -EMSGSIZE; |
| 1346 | break; |
| 1347 | } else { |
| 1348 | mv_dprintk(" task to dev %016llx response: 0x%x " |
| 1349 | "status 0x%x\n", |
| 1350 | SAS_ADDR(dev->sas_addr), |
| 1351 | task->task_status.resp, |
| 1352 | task->task_status.stat); |
Dan Williams | 4fcf812 | 2011-07-29 17:26:39 -0700 | [diff] [blame] | 1353 | sas_free_task(task); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1354 | task = NULL; |
| 1355 | |
| 1356 | } |
| 1357 | } |
| 1358 | ex_err: |
| 1359 | BUG_ON(retry == 3 && task != NULL); |
Dan Williams | 4fcf812 | 2011-07-29 17:26:39 -0700 | [diff] [blame] | 1360 | sas_free_task(task); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1361 | return res; |
| 1362 | } |
| 1363 | |
| 1364 | static int mvs_debug_issue_ssp_tmf(struct domain_device *dev, |
| 1365 | u8 *lun, struct mvs_tmf_task *tmf) |
| 1366 | { |
| 1367 | struct sas_ssp_task ssp_task; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1368 | if (!(dev->tproto & SAS_PROTOCOL_SSP)) |
| 1369 | return TMF_RESP_FUNC_ESUPP; |
| 1370 | |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1371 | memcpy(ssp_task.LUN, lun, 8); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1372 | |
| 1373 | return mvs_exec_internal_tmf_task(dev, &ssp_task, |
| 1374 | sizeof(ssp_task), tmf); |
| 1375 | } |
| 1376 | |
| 1377 | |
| 1378 | /* Standard mandates link reset for ATA (type 0) |
| 1379 | and hard reset for SSP (type 1) , only for RECOVERY */ |
| 1380 | static int mvs_debug_I_T_nexus_reset(struct domain_device *dev) |
| 1381 | { |
| 1382 | int rc; |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 1383 | struct sas_phy *phy = sas_get_local_phy(dev); |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 1384 | int reset_type = (dev->dev_type == SAS_SATA_DEV || |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1385 | (dev->tproto & SAS_PROTOCOL_STP)) ? 0 : 1; |
| 1386 | rc = sas_phy_reset(phy, reset_type); |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 1387 | sas_put_local_phy(phy); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1388 | msleep(2000); |
| 1389 | return rc; |
| 1390 | } |
| 1391 | |
| 1392 | /* mandatory SAM-3 */ |
| 1393 | int mvs_lu_reset(struct domain_device *dev, u8 *lun) |
| 1394 | { |
| 1395 | unsigned long flags; |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1396 | int rc = TMF_RESP_FUNC_FAILED; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1397 | struct mvs_tmf_task tmf_task; |
Andy Yan | f9da3be | 2009-05-14 20:41:21 -0400 | [diff] [blame] | 1398 | struct mvs_device * mvi_dev = dev->lldd_dev; |
Andy Yan | 9870d9a | 2009-05-11 22:19:25 +0800 | [diff] [blame] | 1399 | struct mvs_info *mvi = mvi_dev->mvi_info; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1400 | |
| 1401 | tmf_task.tmf = TMF_LU_RESET; |
| 1402 | mvi_dev->dev_status = MVS_DEV_EH; |
| 1403 | rc = mvs_debug_issue_ssp_tmf(dev, lun, &tmf_task); |
| 1404 | if (rc == TMF_RESP_FUNC_COMPLETE) { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1405 | spin_lock_irqsave(&mvi->lock, flags); |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1406 | mvs_release_task(mvi, dev); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1407 | spin_unlock_irqrestore(&mvi->lock, flags); |
| 1408 | } |
| 1409 | /* If failed, fall-through I_T_Nexus reset */ |
| 1410 | mv_printk("%s for device[%x]:rc= %d\n", __func__, |
| 1411 | mvi_dev->device_id, rc); |
| 1412 | return rc; |
Jeff Garzik | b576294 | 2007-10-25 20:58:22 -0400 | [diff] [blame] | 1413 | } |
| 1414 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1415 | int mvs_I_T_nexus_reset(struct domain_device *dev) |
Ke Wei | e9ff91b | 2008-03-27 14:55:33 +0800 | [diff] [blame] | 1416 | { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1417 | unsigned long flags; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1418 | int rc = TMF_RESP_FUNC_FAILED; |
| 1419 | struct mvs_device * mvi_dev = (struct mvs_device *)dev->lldd_dev; |
Andy Yan | 9870d9a | 2009-05-11 22:19:25 +0800 | [diff] [blame] | 1420 | struct mvs_info *mvi = mvi_dev->mvi_info; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1421 | |
| 1422 | if (mvi_dev->dev_status != MVS_DEV_EH) |
| 1423 | return TMF_RESP_FUNC_COMPLETE; |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1424 | else |
| 1425 | mvi_dev->dev_status = MVS_DEV_NORMAL; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1426 | rc = mvs_debug_I_T_nexus_reset(dev); |
| 1427 | mv_printk("%s for device[%x]:rc= %d\n", |
| 1428 | __func__, mvi_dev->device_id, rc); |
| 1429 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1430 | spin_lock_irqsave(&mvi->lock, flags); |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1431 | mvs_release_task(mvi, dev); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1432 | spin_unlock_irqrestore(&mvi->lock, flags); |
| 1433 | |
| 1434 | return rc; |
| 1435 | } |
| 1436 | /* optional SAM-3 */ |
| 1437 | int mvs_query_task(struct sas_task *task) |
| 1438 | { |
| 1439 | u32 tag; |
| 1440 | struct scsi_lun lun; |
| 1441 | struct mvs_tmf_task tmf_task; |
| 1442 | int rc = TMF_RESP_FUNC_FAILED; |
| 1443 | |
| 1444 | if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) { |
| 1445 | struct scsi_cmnd * cmnd = (struct scsi_cmnd *)task->uldd_task; |
| 1446 | struct domain_device *dev = task->dev; |
Andy Yan | 9870d9a | 2009-05-11 22:19:25 +0800 | [diff] [blame] | 1447 | struct mvs_device *mvi_dev = (struct mvs_device *)dev->lldd_dev; |
| 1448 | struct mvs_info *mvi = mvi_dev->mvi_info; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1449 | |
| 1450 | int_to_scsilun(cmnd->device->lun, &lun); |
| 1451 | rc = mvs_find_tag(mvi, task, &tag); |
| 1452 | if (rc == 0) { |
| 1453 | rc = TMF_RESP_FUNC_FAILED; |
| 1454 | return rc; |
| 1455 | } |
| 1456 | |
| 1457 | tmf_task.tmf = TMF_QUERY_TASK; |
| 1458 | tmf_task.tag_of_task_to_be_managed = cpu_to_le16(tag); |
| 1459 | |
| 1460 | rc = mvs_debug_issue_ssp_tmf(dev, lun.scsi_lun, &tmf_task); |
| 1461 | switch (rc) { |
| 1462 | /* The task is still in Lun, release it then */ |
| 1463 | case TMF_RESP_FUNC_SUCC: |
| 1464 | /* The task is not in Lun or failed, reset the phy */ |
| 1465 | case TMF_RESP_FUNC_FAILED: |
| 1466 | case TMF_RESP_FUNC_COMPLETE: |
| 1467 | break; |
| 1468 | } |
| 1469 | } |
| 1470 | mv_printk("%s:rc= %d\n", __func__, rc); |
| 1471 | return rc; |
| 1472 | } |
| 1473 | |
| 1474 | /* mandatory SAM-3, still need free task/slot info */ |
| 1475 | int mvs_abort_task(struct sas_task *task) |
| 1476 | { |
| 1477 | struct scsi_lun lun; |
| 1478 | struct mvs_tmf_task tmf_task; |
| 1479 | struct domain_device *dev = task->dev; |
Andy Yan | 9870d9a | 2009-05-11 22:19:25 +0800 | [diff] [blame] | 1480 | struct mvs_device *mvi_dev = (struct mvs_device *)dev->lldd_dev; |
Jiri Slaby | 24ae163 | 2010-06-22 13:42:02 +0200 | [diff] [blame] | 1481 | struct mvs_info *mvi; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1482 | int rc = TMF_RESP_FUNC_FAILED; |
| 1483 | unsigned long flags; |
| 1484 | u32 tag; |
Andy Yan | 9870d9a | 2009-05-11 22:19:25 +0800 | [diff] [blame] | 1485 | |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1486 | if (!mvi_dev) { |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1487 | mv_printk("Device has removed\n"); |
| 1488 | return TMF_RESP_FUNC_FAILED; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1489 | } |
| 1490 | |
Jiri Slaby | 24ae163 | 2010-06-22 13:42:02 +0200 | [diff] [blame] | 1491 | mvi = mvi_dev->mvi_info; |
| 1492 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1493 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 1494 | if (task->task_state_flags & SAS_TASK_STATE_DONE) { |
| 1495 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 1496 | rc = TMF_RESP_FUNC_COMPLETE; |
| 1497 | goto out; |
| 1498 | } |
| 1499 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1500 | mvi_dev->dev_status = MVS_DEV_EH; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1501 | if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) { |
| 1502 | struct scsi_cmnd * cmnd = (struct scsi_cmnd *)task->uldd_task; |
| 1503 | |
| 1504 | int_to_scsilun(cmnd->device->lun, &lun); |
| 1505 | rc = mvs_find_tag(mvi, task, &tag); |
| 1506 | if (rc == 0) { |
| 1507 | mv_printk("No such tag in %s\n", __func__); |
| 1508 | rc = TMF_RESP_FUNC_FAILED; |
| 1509 | return rc; |
| 1510 | } |
| 1511 | |
| 1512 | tmf_task.tmf = TMF_ABORT_TASK; |
| 1513 | tmf_task.tag_of_task_to_be_managed = cpu_to_le16(tag); |
| 1514 | |
| 1515 | rc = mvs_debug_issue_ssp_tmf(dev, lun.scsi_lun, &tmf_task); |
| 1516 | |
| 1517 | /* if successful, clear the task and callback forwards.*/ |
| 1518 | if (rc == TMF_RESP_FUNC_COMPLETE) { |
| 1519 | u32 slot_no; |
| 1520 | struct mvs_slot_info *slot; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1521 | |
| 1522 | if (task->lldd_task) { |
Andy Yan | f9da3be | 2009-05-14 20:41:21 -0400 | [diff] [blame] | 1523 | slot = task->lldd_task; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1524 | slot_no = (u32) (slot - mvi->slot_info); |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1525 | spin_lock_irqsave(&mvi->lock, flags); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1526 | mvs_slot_complete(mvi, slot_no, 1); |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1527 | spin_unlock_irqrestore(&mvi->lock, flags); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1528 | } |
| 1529 | } |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1530 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1531 | } else if (task->task_proto & SAS_PROTOCOL_SATA || |
| 1532 | task->task_proto & SAS_PROTOCOL_STP) { |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 1533 | if (SAS_SATA_DEV == dev->dev_type) { |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1534 | struct mvs_slot_info *slot = task->lldd_task; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1535 | u32 slot_idx = (u32)(slot - mvi->slot_info); |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1536 | mv_dprintk("mvs_abort_task() mvi=%p task=%p " |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1537 | "slot=%p slot_idx=x%x\n", |
| 1538 | mvi, task, slot, slot_idx); |
Jianpeng Ma | 95ab000 | 2012-08-04 10:34:14 +0800 | [diff] [blame] | 1539 | task->task_state_flags |= SAS_TASK_STATE_ABORTED; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1540 | mvs_slot_task_free(mvi, task, slot, slot_idx); |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1541 | rc = TMF_RESP_FUNC_COMPLETE; |
| 1542 | goto out; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1543 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1544 | |
| 1545 | } |
| 1546 | out: |
| 1547 | if (rc != TMF_RESP_FUNC_COMPLETE) |
| 1548 | mv_printk("%s:rc= %d\n", __func__, rc); |
| 1549 | return rc; |
| 1550 | } |
| 1551 | |
| 1552 | int mvs_abort_task_set(struct domain_device *dev, u8 *lun) |
| 1553 | { |
| 1554 | int rc = TMF_RESP_FUNC_FAILED; |
| 1555 | struct mvs_tmf_task tmf_task; |
| 1556 | |
| 1557 | tmf_task.tmf = TMF_ABORT_TASK_SET; |
| 1558 | rc = mvs_debug_issue_ssp_tmf(dev, lun, &tmf_task); |
| 1559 | |
| 1560 | return rc; |
| 1561 | } |
| 1562 | |
| 1563 | int mvs_clear_aca(struct domain_device *dev, u8 *lun) |
| 1564 | { |
| 1565 | int rc = TMF_RESP_FUNC_FAILED; |
| 1566 | struct mvs_tmf_task tmf_task; |
| 1567 | |
| 1568 | tmf_task.tmf = TMF_CLEAR_ACA; |
| 1569 | rc = mvs_debug_issue_ssp_tmf(dev, lun, &tmf_task); |
| 1570 | |
| 1571 | return rc; |
| 1572 | } |
| 1573 | |
| 1574 | int mvs_clear_task_set(struct domain_device *dev, u8 *lun) |
| 1575 | { |
| 1576 | int rc = TMF_RESP_FUNC_FAILED; |
| 1577 | struct mvs_tmf_task tmf_task; |
| 1578 | |
| 1579 | tmf_task.tmf = TMF_CLEAR_TASK_SET; |
| 1580 | rc = mvs_debug_issue_ssp_tmf(dev, lun, &tmf_task); |
| 1581 | |
| 1582 | return rc; |
Ke Wei | e9ff91b | 2008-03-27 14:55:33 +0800 | [diff] [blame] | 1583 | } |
| 1584 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1585 | static int mvs_sata_done(struct mvs_info *mvi, struct sas_task *task, |
| 1586 | u32 slot_idx, int err) |
| 1587 | { |
Andy Yan | f9da3be | 2009-05-14 20:41:21 -0400 | [diff] [blame] | 1588 | struct mvs_device *mvi_dev = task->dev->lldd_dev; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1589 | struct task_status_struct *tstat = &task->task_status; |
| 1590 | struct ata_task_resp *resp = (struct ata_task_resp *)tstat->buf; |
James Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 1591 | int stat = SAM_STAT_GOOD; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1592 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1593 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1594 | resp->frame_len = sizeof(struct dev_to_host_fis); |
| 1595 | memcpy(&resp->ending_fis[0], |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1596 | SATA_RECEIVED_D2H_FIS(mvi_dev->taskfileset), |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1597 | sizeof(struct dev_to_host_fis)); |
| 1598 | tstat->buf_valid_size = sizeof(*resp); |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1599 | if (unlikely(err)) { |
| 1600 | if (unlikely(err & CMD_ISS_STPD)) |
| 1601 | stat = SAS_OPEN_REJECT; |
| 1602 | else |
| 1603 | stat = SAS_PROTO_RESPONSE; |
| 1604 | } |
| 1605 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1606 | return stat; |
| 1607 | } |
| 1608 | |
Xiangliang Yu | a4632aa | 2011-05-24 22:36:02 +0800 | [diff] [blame] | 1609 | void mvs_set_sense(u8 *buffer, int len, int d_sense, |
| 1610 | int key, int asc, int ascq) |
| 1611 | { |
| 1612 | memset(buffer, 0, len); |
| 1613 | |
| 1614 | if (d_sense) { |
| 1615 | /* Descriptor format */ |
| 1616 | if (len < 4) { |
| 1617 | mv_printk("Length %d of sense buffer too small to " |
| 1618 | "fit sense %x:%x:%x", len, key, asc, ascq); |
| 1619 | } |
| 1620 | |
| 1621 | buffer[0] = 0x72; /* Response Code */ |
| 1622 | if (len > 1) |
| 1623 | buffer[1] = key; /* Sense Key */ |
| 1624 | if (len > 2) |
| 1625 | buffer[2] = asc; /* ASC */ |
| 1626 | if (len > 3) |
| 1627 | buffer[3] = ascq; /* ASCQ */ |
| 1628 | } else { |
| 1629 | if (len < 14) { |
| 1630 | mv_printk("Length %d of sense buffer too small to " |
| 1631 | "fit sense %x:%x:%x", len, key, asc, ascq); |
| 1632 | } |
| 1633 | |
| 1634 | buffer[0] = 0x70; /* Response Code */ |
| 1635 | if (len > 2) |
| 1636 | buffer[2] = key; /* Sense Key */ |
| 1637 | if (len > 7) |
| 1638 | buffer[7] = 0x0a; /* Additional Sense Length */ |
| 1639 | if (len > 12) |
| 1640 | buffer[12] = asc; /* ASC */ |
| 1641 | if (len > 13) |
| 1642 | buffer[13] = ascq; /* ASCQ */ |
| 1643 | } |
| 1644 | |
| 1645 | return; |
| 1646 | } |
| 1647 | |
| 1648 | void mvs_fill_ssp_resp_iu(struct ssp_response_iu *iu, |
| 1649 | u8 key, u8 asc, u8 asc_q) |
| 1650 | { |
| 1651 | iu->datapres = 2; |
| 1652 | iu->response_data_len = 0; |
| 1653 | iu->sense_data_len = 17; |
| 1654 | iu->status = 02; |
| 1655 | mvs_set_sense(iu->sense_data, 17, 0, |
| 1656 | key, asc, asc_q); |
| 1657 | } |
| 1658 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1659 | static int mvs_slot_err(struct mvs_info *mvi, struct sas_task *task, |
| 1660 | u32 slot_idx) |
| 1661 | { |
| 1662 | struct mvs_slot_info *slot = &mvi->slot_info[slot_idx]; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1663 | int stat; |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1664 | u32 err_dw0 = le32_to_cpu(*(u32 *)slot->response); |
Xiangliang Yu | a4632aa | 2011-05-24 22:36:02 +0800 | [diff] [blame] | 1665 | u32 err_dw1 = le32_to_cpu(*((u32 *)slot->response + 1)); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1666 | u32 tfs = 0; |
| 1667 | enum mvs_port_type type = PORT_TYPE_SAS; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1668 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1669 | if (err_dw0 & CMD_ISS_STPD) |
| 1670 | MVS_CHIP_DISP->issue_stop(mvi, type, tfs); |
| 1671 | |
| 1672 | MVS_CHIP_DISP->command_active(mvi, slot_idx); |
| 1673 | |
James Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 1674 | stat = SAM_STAT_CHECK_CONDITION; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1675 | switch (task->task_proto) { |
| 1676 | case SAS_PROTOCOL_SSP: |
Xiangliang Yu | a4632aa | 2011-05-24 22:36:02 +0800 | [diff] [blame] | 1677 | { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1678 | stat = SAS_ABORTED_TASK; |
Xiangliang Yu | a4632aa | 2011-05-24 22:36:02 +0800 | [diff] [blame] | 1679 | if ((err_dw0 & NO_DEST) || err_dw1 & bit(31)) { |
| 1680 | struct ssp_response_iu *iu = slot->response + |
| 1681 | sizeof(struct mvs_err_info); |
| 1682 | mvs_fill_ssp_resp_iu(iu, NOT_READY, 0x04, 01); |
| 1683 | sas_ssp_task_response(mvi->dev, task, iu); |
| 1684 | stat = SAM_STAT_CHECK_CONDITION; |
| 1685 | } |
| 1686 | if (err_dw1 & bit(31)) |
| 1687 | mv_printk("reuse same slot, retry command.\n"); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1688 | break; |
Xiangliang Yu | a4632aa | 2011-05-24 22:36:02 +0800 | [diff] [blame] | 1689 | } |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1690 | case SAS_PROTOCOL_SMP: |
James Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 1691 | stat = SAM_STAT_CHECK_CONDITION; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1692 | break; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1693 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1694 | case SAS_PROTOCOL_SATA: |
| 1695 | case SAS_PROTOCOL_STP: |
| 1696 | case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1697 | { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1698 | task->ata_task.use_ncq = 0; |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1699 | stat = SAS_PROTO_RESPONSE; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1700 | mvs_sata_done(mvi, task, slot_idx, err_dw0); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1701 | } |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1702 | break; |
| 1703 | default: |
| 1704 | break; |
| 1705 | } |
| 1706 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1707 | return stat; |
| 1708 | } |
| 1709 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1710 | int mvs_slot_complete(struct mvs_info *mvi, u32 rx_desc, u32 flags) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1711 | { |
| 1712 | u32 slot_idx = rx_desc & RXQ_SLOT_MASK; |
| 1713 | struct mvs_slot_info *slot = &mvi->slot_info[slot_idx]; |
| 1714 | struct sas_task *task = slot->task; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1715 | struct mvs_device *mvi_dev = NULL; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1716 | struct task_status_struct *tstat; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1717 | struct domain_device *dev; |
| 1718 | u32 aborted; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1719 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1720 | void *to; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1721 | enum exec_status sts; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1722 | |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1723 | if (unlikely(!task || !task->lldd_task || !task->dev)) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1724 | return -1; |
| 1725 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1726 | tstat = &task->task_status; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1727 | dev = task->dev; |
| 1728 | mvi_dev = dev->lldd_dev; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1729 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1730 | spin_lock(&task->task_state_lock); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1731 | task->task_state_flags &= |
| 1732 | ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR); |
| 1733 | task->task_state_flags |= SAS_TASK_STATE_DONE; |
| 1734 | /* race condition*/ |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1735 | aborted = task->task_state_flags & SAS_TASK_STATE_ABORTED; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1736 | spin_unlock(&task->task_state_lock); |
| 1737 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1738 | memset(tstat, 0, sizeof(*tstat)); |
| 1739 | tstat->resp = SAS_TASK_COMPLETE; |
| 1740 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1741 | if (unlikely(aborted)) { |
| 1742 | tstat->stat = SAS_ABORTED_TASK; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1743 | if (mvi_dev && mvi_dev->running_req) |
| 1744 | mvi_dev->running_req--; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1745 | if (sas_protocol_ata(task->task_proto)) |
| 1746 | mvs_free_reg_set(mvi, mvi_dev); |
| 1747 | |
| 1748 | mvs_slot_task_free(mvi, task, slot, slot_idx); |
| 1749 | return -1; |
| 1750 | } |
| 1751 | |
Xiangliang Yu | e144f7e | 2011-05-24 22:38:10 +0800 | [diff] [blame] | 1752 | /* when no device attaching, go ahead and complete by error handling*/ |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1753 | if (unlikely(!mvi_dev || flags)) { |
| 1754 | if (!mvi_dev) |
| 1755 | mv_dprintk("port has not device.\n"); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1756 | tstat->stat = SAS_PHY_DOWN; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1757 | goto out; |
| 1758 | } |
| 1759 | |
James Bottomley | 53a983c | 2013-06-09 09:23:16 -0700 | [diff] [blame] | 1760 | /* |
| 1761 | * error info record present; slot->response is 32 bit aligned but may |
| 1762 | * not be 64 bit aligned, so check for zero in two 32 bit reads |
| 1763 | */ |
| 1764 | if (unlikely((rx_desc & RXQ_ERR) |
| 1765 | && (*((u32 *)slot->response) |
| 1766 | || *(((u32 *)slot->response) + 1)))) { |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1767 | mv_dprintk("port %d slot %d rx_desc %X has error info" |
| 1768 | "%016llX.\n", slot->port->sas_port.id, slot_idx, |
James Bottomley | 53a983c | 2013-06-09 09:23:16 -0700 | [diff] [blame] | 1769 | rx_desc, get_unaligned_le64(slot->response)); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1770 | tstat->stat = mvs_slot_err(mvi, task, slot_idx); |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1771 | tstat->resp = SAS_TASK_COMPLETE; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1772 | goto out; |
| 1773 | } |
| 1774 | |
| 1775 | switch (task->task_proto) { |
| 1776 | case SAS_PROTOCOL_SSP: |
| 1777 | /* hw says status == 0, datapres == 0 */ |
| 1778 | if (rx_desc & RXQ_GOOD) { |
James Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 1779 | tstat->stat = SAM_STAT_GOOD; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1780 | tstat->resp = SAS_TASK_COMPLETE; |
| 1781 | } |
| 1782 | /* response frame present */ |
| 1783 | else if (rx_desc & RXQ_RSP) { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1784 | struct ssp_response_iu *iu = slot->response + |
| 1785 | sizeof(struct mvs_err_info); |
| 1786 | sas_ssp_task_response(mvi->dev, task, iu); |
| 1787 | } else |
James Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 1788 | tstat->stat = SAM_STAT_CHECK_CONDITION; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1789 | break; |
| 1790 | |
| 1791 | case SAS_PROTOCOL_SMP: { |
| 1792 | struct scatterlist *sg_resp = &task->smp_task.smp_resp; |
James Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 1793 | tstat->stat = SAM_STAT_GOOD; |
Cong Wang | 77dfce0 | 2011-11-25 23:14:23 +0800 | [diff] [blame] | 1794 | to = kmap_atomic(sg_page(sg_resp)); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1795 | memcpy(to + sg_resp->offset, |
| 1796 | slot->response + sizeof(struct mvs_err_info), |
| 1797 | sg_dma_len(sg_resp)); |
Cong Wang | 77dfce0 | 2011-11-25 23:14:23 +0800 | [diff] [blame] | 1798 | kunmap_atomic(to); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1799 | break; |
| 1800 | } |
| 1801 | |
| 1802 | case SAS_PROTOCOL_SATA: |
| 1803 | case SAS_PROTOCOL_STP: |
| 1804 | case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: { |
| 1805 | tstat->stat = mvs_sata_done(mvi, task, slot_idx, 0); |
| 1806 | break; |
| 1807 | } |
| 1808 | |
| 1809 | default: |
James Bottomley | df64d3c | 2010-07-27 15:51:13 -0500 | [diff] [blame] | 1810 | tstat->stat = SAM_STAT_CHECK_CONDITION; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1811 | break; |
| 1812 | } |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1813 | if (!slot->port->port_attached) { |
| 1814 | mv_dprintk("port %d has removed.\n", slot->port->sas_port.id); |
| 1815 | tstat->stat = SAS_PHY_DOWN; |
| 1816 | } |
| 1817 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1818 | |
| 1819 | out: |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1820 | if (mvi_dev && mvi_dev->running_req) { |
| 1821 | mvi_dev->running_req--; |
| 1822 | if (sas_protocol_ata(task->task_proto) && !mvi_dev->running_req) |
Andy Yan | 0f980a8 | 2009-05-11 21:49:52 +0800 | [diff] [blame] | 1823 | mvs_free_reg_set(mvi, mvi_dev); |
| 1824 | } |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1825 | mvs_slot_task_free(mvi, task, slot, slot_idx); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1826 | sts = tstat->stat; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1827 | |
| 1828 | spin_unlock(&mvi->lock); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1829 | if (task->task_done) |
| 1830 | task->task_done(task); |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1831 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1832 | spin_lock(&mvi->lock); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1833 | |
| 1834 | return sts; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1835 | } |
| 1836 | |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1837 | void mvs_do_release_task(struct mvs_info *mvi, |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1838 | int phy_no, struct domain_device *dev) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1839 | { |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1840 | u32 slot_idx; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1841 | struct mvs_phy *phy; |
| 1842 | struct mvs_port *port; |
| 1843 | struct mvs_slot_info *slot, *slot2; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1844 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1845 | phy = &mvi->phy[phy_no]; |
| 1846 | port = phy->port; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1847 | if (!port) |
| 1848 | return; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1849 | /* clean cmpl queue in case request is already finished */ |
| 1850 | mvs_int_rx(mvi, false); |
| 1851 | |
| 1852 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1853 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1854 | list_for_each_entry_safe(slot, slot2, &port->list, entry) { |
| 1855 | struct sas_task *task; |
| 1856 | slot_idx = (u32) (slot - mvi->slot_info); |
| 1857 | task = slot->task; |
| 1858 | |
| 1859 | if (dev && task->dev != dev) |
| 1860 | continue; |
| 1861 | |
| 1862 | mv_printk("Release slot [%x] tag[%x], task [%p]:\n", |
| 1863 | slot_idx, slot->slot_tag, task); |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1864 | MVS_CHIP_DISP->command_active(mvi, slot_idx); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1865 | |
| 1866 | mvs_slot_complete(mvi, slot_idx, 1); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1867 | } |
| 1868 | } |
| 1869 | |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1870 | void mvs_release_task(struct mvs_info *mvi, |
| 1871 | struct domain_device *dev) |
| 1872 | { |
| 1873 | int i, phyno[WIDE_PORT_MAX_PHY], num; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1874 | num = mvs_find_dev_phyno(dev, phyno); |
| 1875 | for (i = 0; i < num; i++) |
| 1876 | mvs_do_release_task(mvi, phyno[i], dev); |
| 1877 | } |
| 1878 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1879 | static void mvs_phy_disconnected(struct mvs_phy *phy) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1880 | { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1881 | phy->phy_attached = 0; |
| 1882 | phy->att_dev_info = 0; |
| 1883 | phy->att_dev_sas_addr = 0; |
| 1884 | } |
| 1885 | |
| 1886 | static void mvs_work_queue(struct work_struct *work) |
| 1887 | { |
| 1888 | struct delayed_work *dw = container_of(work, struct delayed_work, work); |
| 1889 | struct mvs_wq *mwq = container_of(dw, struct mvs_wq, work_q); |
| 1890 | struct mvs_info *mvi = mwq->mvi; |
| 1891 | unsigned long flags; |
Xiangliang Yu | a4632aa | 2011-05-24 22:36:02 +0800 | [diff] [blame] | 1892 | u32 phy_no = (unsigned long) mwq->data; |
| 1893 | struct sas_ha_struct *sas_ha = mvi->sas; |
| 1894 | struct mvs_phy *phy = &mvi->phy[phy_no]; |
| 1895 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1896 | |
| 1897 | spin_lock_irqsave(&mvi->lock, flags); |
| 1898 | if (mwq->handler & PHY_PLUG_EVENT) { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1899 | |
| 1900 | if (phy->phy_event & PHY_PLUG_OUT) { |
| 1901 | u32 tmp; |
| 1902 | struct sas_identify_frame *id; |
| 1903 | id = (struct sas_identify_frame *)phy->frame_rcvd; |
| 1904 | tmp = MVS_CHIP_DISP->read_phy_ctl(mvi, phy_no); |
| 1905 | phy->phy_event &= ~PHY_PLUG_OUT; |
| 1906 | if (!(tmp & PHY_READY_MASK)) { |
| 1907 | sas_phy_disconnected(sas_phy); |
| 1908 | mvs_phy_disconnected(phy); |
| 1909 | sas_ha->notify_phy_event(sas_phy, |
| 1910 | PHYE_LOSS_OF_SIGNAL); |
| 1911 | mv_dprintk("phy%d Removed Device\n", phy_no); |
| 1912 | } else { |
| 1913 | MVS_CHIP_DISP->detect_porttype(mvi, phy_no); |
| 1914 | mvs_update_phyinfo(mvi, phy_no, 1); |
| 1915 | mvs_bytes_dmaed(mvi, phy_no); |
| 1916 | mvs_port_notify_formed(sas_phy, 0); |
| 1917 | mv_dprintk("phy%d Attached Device\n", phy_no); |
| 1918 | } |
| 1919 | } |
Xiangliang Yu | a4632aa | 2011-05-24 22:36:02 +0800 | [diff] [blame] | 1920 | } else if (mwq->handler & EXP_BRCT_CHG) { |
| 1921 | phy->phy_event &= ~EXP_BRCT_CHG; |
| 1922 | sas_ha->notify_port_event(sas_phy, |
| 1923 | PORTE_BROADCAST_RCVD); |
| 1924 | mv_dprintk("phy%d Got Broadcast Change\n", phy_no); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1925 | } |
| 1926 | list_del(&mwq->entry); |
| 1927 | spin_unlock_irqrestore(&mvi->lock, flags); |
| 1928 | kfree(mwq); |
| 1929 | } |
| 1930 | |
| 1931 | static int mvs_handle_event(struct mvs_info *mvi, void *data, int handler) |
| 1932 | { |
| 1933 | struct mvs_wq *mwq; |
| 1934 | int ret = 0; |
| 1935 | |
| 1936 | mwq = kmalloc(sizeof(struct mvs_wq), GFP_ATOMIC); |
| 1937 | if (mwq) { |
| 1938 | mwq->mvi = mvi; |
| 1939 | mwq->data = data; |
| 1940 | mwq->handler = handler; |
| 1941 | MV_INIT_DELAYED_WORK(&mwq->work_q, mvs_work_queue, mwq); |
| 1942 | list_add_tail(&mwq->entry, &mvi->wq_list); |
| 1943 | schedule_delayed_work(&mwq->work_q, HZ * 2); |
| 1944 | } else |
| 1945 | ret = -ENOMEM; |
| 1946 | |
| 1947 | return ret; |
| 1948 | } |
| 1949 | |
| 1950 | static void mvs_sig_time_out(unsigned long tphy) |
| 1951 | { |
| 1952 | struct mvs_phy *phy = (struct mvs_phy *)tphy; |
| 1953 | struct mvs_info *mvi = phy->mvi; |
| 1954 | u8 phy_no; |
| 1955 | |
| 1956 | for (phy_no = 0; phy_no < mvi->chip->n_phy; phy_no++) { |
| 1957 | if (&mvi->phy[phy_no] == phy) { |
| 1958 | mv_dprintk("Get signature time out, reset phy %d\n", |
| 1959 | phy_no+mvi->id*mvi->chip->n_phy); |
Xiangliang Yu | a4632aa | 2011-05-24 22:36:02 +0800 | [diff] [blame] | 1960 | MVS_CHIP_DISP->phy_reset(mvi, phy_no, MVS_HARD_RESET); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1961 | } |
| 1962 | } |
| 1963 | } |
| 1964 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1965 | void mvs_int_port(struct mvs_info *mvi, int phy_no, u32 events) |
| 1966 | { |
| 1967 | u32 tmp; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1968 | struct mvs_phy *phy = &mvi->phy[phy_no]; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1969 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1970 | phy->irq_status = MVS_CHIP_DISP->read_port_irq_stat(mvi, phy_no); |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1971 | MVS_CHIP_DISP->write_port_irq_stat(mvi, phy_no, phy->irq_status); |
| 1972 | mv_dprintk("phy %d ctrl sts=0x%08X.\n", phy_no+mvi->id*mvi->chip->n_phy, |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1973 | MVS_CHIP_DISP->read_phy_ctl(mvi, phy_no)); |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1974 | mv_dprintk("phy %d irq sts = 0x%08X\n", phy_no+mvi->id*mvi->chip->n_phy, |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1975 | phy->irq_status); |
| 1976 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1977 | /* |
| 1978 | * events is port event now , |
| 1979 | * we need check the interrupt status which belongs to per port. |
| 1980 | */ |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1981 | |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1982 | if (phy->irq_status & PHYEV_DCDR_ERR) { |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1983 | mv_dprintk("phy %d STP decoding error.\n", |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1984 | phy_no + mvi->id*mvi->chip->n_phy); |
| 1985 | } |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1986 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1987 | if (phy->irq_status & PHYEV_POOF) { |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 1988 | mdelay(500); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1989 | if (!(phy->phy_event & PHY_PLUG_OUT)) { |
| 1990 | int dev_sata = phy->phy_type & PORT_TYPE_SATA; |
| 1991 | int ready; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1992 | mvs_do_release_task(mvi, phy_no, NULL); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1993 | phy->phy_event |= PHY_PLUG_OUT; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 1994 | MVS_CHIP_DISP->clear_srs_irq(mvi, 0, 1); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1995 | mvs_handle_event(mvi, |
| 1996 | (void *)(unsigned long)phy_no, |
| 1997 | PHY_PLUG_EVENT); |
| 1998 | ready = mvs_is_phy_ready(mvi, phy_no); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 1999 | if (ready || dev_sata) { |
| 2000 | if (MVS_CHIP_DISP->stp_reset) |
| 2001 | MVS_CHIP_DISP->stp_reset(mvi, |
| 2002 | phy_no); |
| 2003 | else |
| 2004 | MVS_CHIP_DISP->phy_reset(mvi, |
Xiangliang Yu | a4632aa | 2011-05-24 22:36:02 +0800 | [diff] [blame] | 2005 | phy_no, MVS_SOFT_RESET); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 2006 | return; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 2007 | } |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 2008 | } |
| 2009 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 2010 | |
| 2011 | if (phy->irq_status & PHYEV_COMWAKE) { |
| 2012 | tmp = MVS_CHIP_DISP->read_port_irq_mask(mvi, phy_no); |
| 2013 | MVS_CHIP_DISP->write_port_irq_mask(mvi, phy_no, |
| 2014 | tmp | PHYEV_SIG_FIS); |
| 2015 | if (phy->timer.function == NULL) { |
| 2016 | phy->timer.data = (unsigned long)phy; |
| 2017 | phy->timer.function = mvs_sig_time_out; |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 2018 | phy->timer.expires = jiffies + 5*HZ; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 2019 | add_timer(&phy->timer); |
| 2020 | } |
| 2021 | } |
| 2022 | if (phy->irq_status & (PHYEV_SIG_FIS | PHYEV_ID_DONE)) { |
| 2023 | phy->phy_status = mvs_is_phy_ready(mvi, phy_no); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 2024 | mv_dprintk("notify plug in on phy[%d]\n", phy_no); |
| 2025 | if (phy->phy_status) { |
| 2026 | mdelay(10); |
| 2027 | MVS_CHIP_DISP->detect_porttype(mvi, phy_no); |
| 2028 | if (phy->phy_type & PORT_TYPE_SATA) { |
| 2029 | tmp = MVS_CHIP_DISP->read_port_irq_mask( |
| 2030 | mvi, phy_no); |
| 2031 | tmp &= ~PHYEV_SIG_FIS; |
| 2032 | MVS_CHIP_DISP->write_port_irq_mask(mvi, |
| 2033 | phy_no, tmp); |
| 2034 | } |
| 2035 | mvs_update_phyinfo(mvi, phy_no, 0); |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 2036 | if (phy->phy_type & PORT_TYPE_SAS) { |
Xiangliang Yu | a4632aa | 2011-05-24 22:36:02 +0800 | [diff] [blame] | 2037 | MVS_CHIP_DISP->phy_reset(mvi, phy_no, MVS_PHY_TUNE); |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 2038 | mdelay(10); |
| 2039 | } |
| 2040 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 2041 | mvs_bytes_dmaed(mvi, phy_no); |
| 2042 | /* whether driver is going to handle hot plug */ |
| 2043 | if (phy->phy_event & PHY_PLUG_OUT) { |
Xiangliang Yu | a4632aa | 2011-05-24 22:36:02 +0800 | [diff] [blame] | 2044 | mvs_port_notify_formed(&phy->sas_phy, 0); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 2045 | phy->phy_event &= ~PHY_PLUG_OUT; |
| 2046 | } |
| 2047 | } else { |
| 2048 | mv_dprintk("plugin interrupt but phy%d is gone\n", |
| 2049 | phy_no + mvi->id*mvi->chip->n_phy); |
| 2050 | } |
| 2051 | } else if (phy->irq_status & PHYEV_BROAD_CH) { |
Xiangliang Yu | 84fbd0c | 2011-05-24 22:37:25 +0800 | [diff] [blame] | 2052 | mv_dprintk("phy %d broadcast change.\n", |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 2053 | phy_no + mvi->id*mvi->chip->n_phy); |
Xiangliang Yu | a4632aa | 2011-05-24 22:36:02 +0800 | [diff] [blame] | 2054 | mvs_handle_event(mvi, (void *)(unsigned long)phy_no, |
| 2055 | EXP_BRCT_CHG); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 2056 | } |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 2057 | } |
| 2058 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 2059 | int mvs_int_rx(struct mvs_info *mvi, bool self_clear) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 2060 | { |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 2061 | u32 rx_prod_idx, rx_desc; |
| 2062 | bool attn = false; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 2063 | |
| 2064 | /* the first dword in the RX ring is special: it contains |
| 2065 | * a mirror of the hardware's RX producer index, so that |
| 2066 | * we don't have to stall the CPU reading that register. |
| 2067 | * The actual RX ring is offset by one dword, due to this. |
| 2068 | */ |
| 2069 | rx_prod_idx = mvi->rx_cons; |
| 2070 | mvi->rx_cons = le32_to_cpu(mvi->rx[0]); |
| 2071 | if (mvi->rx_cons == 0xfff) /* h/w hasn't touched RX ring yet */ |
| 2072 | return 0; |
| 2073 | |
| 2074 | /* The CMPL_Q may come late, read from register and try again |
| 2075 | * note: if coalescing is enabled, |
| 2076 | * it will need to read from register every time for sure |
| 2077 | */ |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 2078 | if (unlikely(mvi->rx_cons == rx_prod_idx)) |
| 2079 | mvi->rx_cons = MVS_CHIP_DISP->rx_update(mvi) & RX_RING_SZ_MASK; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 2080 | |
| 2081 | if (mvi->rx_cons == rx_prod_idx) |
| 2082 | return 0; |
| 2083 | |
| 2084 | while (mvi->rx_cons != rx_prod_idx) { |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 2085 | /* increment our internal RX consumer pointer */ |
| 2086 | rx_prod_idx = (rx_prod_idx + 1) & (MVS_RX_RING_SZ - 1); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 2087 | rx_desc = le32_to_cpu(mvi->rx[rx_prod_idx + 1]); |
| 2088 | |
| 2089 | if (likely(rx_desc & RXQ_DONE)) |
| 2090 | mvs_slot_complete(mvi, rx_desc, 0); |
| 2091 | if (rx_desc & RXQ_ATTN) { |
| 2092 | attn = true; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 2093 | } else if (rx_desc & RXQ_ERR) { |
| 2094 | if (!(rx_desc & RXQ_DONE)) |
| 2095 | mvs_slot_complete(mvi, rx_desc, 0); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 2096 | } else if (rx_desc & RXQ_SLOT_RESET) { |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 2097 | mvs_slot_free(mvi, rx_desc); |
| 2098 | } |
| 2099 | } |
| 2100 | |
| 2101 | if (attn && self_clear) |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 2102 | MVS_CHIP_DISP->int_full(mvi); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 2103 | return 0; |
| 2104 | } |
| 2105 | |