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