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