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