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