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