Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1 | /* |
| 2 | * SAS Transport Layer for MPT (Message Passing Technology) based controllers |
| 3 | * |
| 4 | * This code is based on drivers/scsi/mpt2sas/mpt2_transport.c |
Kashyap, Desai | 19d3ebe | 2009-09-14 11:01:36 +0530 | [diff] [blame] | 5 | * Copyright (C) 2007-2009 LSI Corporation |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6 | * (mailto:DL-MPTFusionLinux@lsi.com) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * as published by the Free Software Foundation; either version 2 |
| 11 | * of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * NO WARRANTY |
| 19 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 20 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT |
| 21 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, |
| 22 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is |
| 23 | * solely responsible for determining the appropriateness of using and |
| 24 | * distributing the Program and assumes all risks associated with its |
| 25 | * exercise of rights under this Agreement, including but not limited to |
| 26 | * the risks and costs of program errors, damage to or loss of data, |
| 27 | * programs or equipment, and unavailability or interruption of operations. |
| 28 | |
| 29 | * DISCLAIMER OF LIABILITY |
| 30 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY |
| 31 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 32 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND |
| 33 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 34 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 35 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED |
| 36 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES |
| 37 | |
| 38 | * You should have received a copy of the GNU General Public License |
| 39 | * along with this program; if not, write to the Free Software |
| 40 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 41 | * USA. |
| 42 | */ |
| 43 | |
| 44 | #include <linux/module.h> |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/init.h> |
| 47 | #include <linux/errno.h> |
| 48 | #include <linux/sched.h> |
| 49 | #include <linux/workqueue.h> |
| 50 | #include <linux/delay.h> |
| 51 | #include <linux/pci.h> |
| 52 | |
| 53 | #include <scsi/scsi.h> |
| 54 | #include <scsi/scsi_cmnd.h> |
| 55 | #include <scsi/scsi_device.h> |
| 56 | #include <scsi/scsi_host.h> |
| 57 | #include <scsi/scsi_transport_sas.h> |
| 58 | #include <scsi/scsi_dbg.h> |
| 59 | |
| 60 | #include "mpt2sas_base.h" |
| 61 | /** |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 62 | * _transport_sas_node_find_by_sas_address - sas node search |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 63 | * @ioc: per adapter object |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 64 | * @sas_address: sas address of expander or sas host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 65 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 66 | * |
| 67 | * Search for either hba phys or expander device based on handle, then returns |
| 68 | * the sas_node object. |
| 69 | */ |
| 70 | static struct _sas_node * |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 71 | _transport_sas_node_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 72 | u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 73 | { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 74 | if (ioc->sas_hba.sas_address == sas_address) |
| 75 | return &ioc->sas_hba; |
| 76 | else |
| 77 | return mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 78 | sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /** |
| 82 | * _transport_convert_phy_link_rate - |
| 83 | * @link_rate: link rate returned from mpt firmware |
| 84 | * |
| 85 | * Convert link_rate from mpi fusion into sas_transport form. |
| 86 | */ |
| 87 | static enum sas_linkrate |
| 88 | _transport_convert_phy_link_rate(u8 link_rate) |
| 89 | { |
| 90 | enum sas_linkrate rc; |
| 91 | |
| 92 | switch (link_rate) { |
| 93 | case MPI2_SAS_NEG_LINK_RATE_1_5: |
| 94 | rc = SAS_LINK_RATE_1_5_GBPS; |
| 95 | break; |
| 96 | case MPI2_SAS_NEG_LINK_RATE_3_0: |
| 97 | rc = SAS_LINK_RATE_3_0_GBPS; |
| 98 | break; |
| 99 | case MPI2_SAS_NEG_LINK_RATE_6_0: |
| 100 | rc = SAS_LINK_RATE_6_0_GBPS; |
| 101 | break; |
| 102 | case MPI2_SAS_NEG_LINK_RATE_PHY_DISABLED: |
| 103 | rc = SAS_PHY_DISABLED; |
| 104 | break; |
| 105 | case MPI2_SAS_NEG_LINK_RATE_NEGOTIATION_FAILED: |
| 106 | rc = SAS_LINK_RATE_FAILED; |
| 107 | break; |
| 108 | case MPI2_SAS_NEG_LINK_RATE_PORT_SELECTOR: |
| 109 | rc = SAS_SATA_PORT_SELECTOR; |
| 110 | break; |
| 111 | case MPI2_SAS_NEG_LINK_RATE_SMP_RESET_IN_PROGRESS: |
| 112 | rc = SAS_PHY_RESET_IN_PROGRESS; |
| 113 | break; |
| 114 | default: |
| 115 | case MPI2_SAS_NEG_LINK_RATE_SATA_OOB_COMPLETE: |
| 116 | case MPI2_SAS_NEG_LINK_RATE_UNKNOWN_LINK_RATE: |
| 117 | rc = SAS_LINK_RATE_UNKNOWN; |
| 118 | break; |
| 119 | } |
| 120 | return rc; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * _transport_set_identify - set identify for phys and end devices |
| 125 | * @ioc: per adapter object |
| 126 | * @handle: device handle |
| 127 | * @identify: sas identify info |
| 128 | * |
| 129 | * Populates sas identify info. |
| 130 | * |
| 131 | * Returns 0 for success, non-zero for failure. |
| 132 | */ |
| 133 | static int |
| 134 | _transport_set_identify(struct MPT2SAS_ADAPTER *ioc, u16 handle, |
| 135 | struct sas_identify *identify) |
| 136 | { |
| 137 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 138 | Mpi2ConfigReply_t mpi_reply; |
| 139 | u32 device_info; |
| 140 | u32 ioc_status; |
| 141 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 142 | if (ioc->shost_recovery) { |
| 143 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 144 | __func__, ioc->name); |
| 145 | return -EFAULT; |
| 146 | } |
| 147 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 148 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 149 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 150 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 151 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 152 | ioc->name, __FILE__, __LINE__, __func__); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 153 | return -ENXIO; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 157 | MPI2_IOCSTATUS_MASK; |
| 158 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 159 | printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x)" |
| 160 | "\nfailure at %s:%d/%s()!\n", ioc->name, handle, ioc_status, |
| 161 | __FILE__, __LINE__, __func__); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 162 | return -EIO; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | memset(identify, 0, sizeof(identify)); |
| 166 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 167 | |
| 168 | /* sas_address */ |
| 169 | identify->sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 170 | |
| 171 | /* device_type */ |
| 172 | switch (device_info & MPI2_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) { |
| 173 | case MPI2_SAS_DEVICE_INFO_NO_DEVICE: |
| 174 | identify->device_type = SAS_PHY_UNUSED; |
| 175 | break; |
| 176 | case MPI2_SAS_DEVICE_INFO_END_DEVICE: |
| 177 | identify->device_type = SAS_END_DEVICE; |
| 178 | break; |
| 179 | case MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER: |
| 180 | identify->device_type = SAS_EDGE_EXPANDER_DEVICE; |
| 181 | break; |
| 182 | case MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER: |
| 183 | identify->device_type = SAS_FANOUT_EXPANDER_DEVICE; |
| 184 | break; |
| 185 | } |
| 186 | |
| 187 | /* initiator_port_protocols */ |
| 188 | if (device_info & MPI2_SAS_DEVICE_INFO_SSP_INITIATOR) |
| 189 | identify->initiator_port_protocols |= SAS_PROTOCOL_SSP; |
| 190 | if (device_info & MPI2_SAS_DEVICE_INFO_STP_INITIATOR) |
| 191 | identify->initiator_port_protocols |= SAS_PROTOCOL_STP; |
| 192 | if (device_info & MPI2_SAS_DEVICE_INFO_SMP_INITIATOR) |
| 193 | identify->initiator_port_protocols |= SAS_PROTOCOL_SMP; |
| 194 | if (device_info & MPI2_SAS_DEVICE_INFO_SATA_HOST) |
| 195 | identify->initiator_port_protocols |= SAS_PROTOCOL_SATA; |
| 196 | |
| 197 | /* target_port_protocols */ |
| 198 | if (device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
| 199 | identify->target_port_protocols |= SAS_PROTOCOL_SSP; |
| 200 | if (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
| 201 | identify->target_port_protocols |= SAS_PROTOCOL_STP; |
| 202 | if (device_info & MPI2_SAS_DEVICE_INFO_SMP_TARGET) |
| 203 | identify->target_port_protocols |= SAS_PROTOCOL_SMP; |
| 204 | if (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 205 | identify->target_port_protocols |= SAS_PROTOCOL_SATA; |
| 206 | |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * mpt2sas_transport_done - internal transport layer callback handler. |
| 212 | * @ioc: per adapter object |
| 213 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 214 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 215 | * @reply: reply message frame(lower 32bit addr) |
| 216 | * |
| 217 | * Callback handler when sending internal generated transport cmds. |
| 218 | * The callback index passed is `ioc->transport_cb_idx` |
| 219 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 220 | * Return 1 meaning mf should be freed from _base_interrupt |
| 221 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 222 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 223 | u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 224 | mpt2sas_transport_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 225 | u32 reply) |
| 226 | { |
| 227 | MPI2DefaultReply_t *mpi_reply; |
| 228 | |
| 229 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 230 | if (ioc->transport_cmds.status == MPT2_CMD_NOT_USED) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 231 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 232 | if (ioc->transport_cmds.smid != smid) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 233 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 234 | ioc->transport_cmds.status |= MPT2_CMD_COMPLETE; |
| 235 | if (mpi_reply) { |
| 236 | memcpy(ioc->transport_cmds.reply, mpi_reply, |
| 237 | mpi_reply->MsgLength*4); |
| 238 | ioc->transport_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 239 | } |
| 240 | ioc->transport_cmds.status &= ~MPT2_CMD_PENDING; |
| 241 | complete(&ioc->transport_cmds.done); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 242 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /* report manufacture request structure */ |
| 246 | struct rep_manu_request{ |
| 247 | u8 smp_frame_type; |
| 248 | u8 function; |
| 249 | u8 reserved; |
| 250 | u8 request_length; |
| 251 | }; |
| 252 | |
| 253 | /* report manufacture reply structure */ |
| 254 | struct rep_manu_reply{ |
| 255 | u8 smp_frame_type; /* 0x41 */ |
| 256 | u8 function; /* 0x01 */ |
| 257 | u8 function_result; |
| 258 | u8 response_length; |
| 259 | u16 expander_change_count; |
| 260 | u8 reserved0[2]; |
| 261 | u8 sas_format:1; |
| 262 | u8 reserved1:7; |
| 263 | u8 reserved2[3]; |
| 264 | u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN]; |
| 265 | u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN]; |
| 266 | u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN]; |
| 267 | u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN]; |
| 268 | u16 component_id; |
| 269 | u8 component_revision_id; |
| 270 | u8 reserved3; |
| 271 | u8 vendor_specific[8]; |
| 272 | }; |
| 273 | |
| 274 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 275 | * _transport_expander_report_manufacture - obtain SMP report_manufacture |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 276 | * @ioc: per adapter object |
| 277 | * @sas_address: expander sas address |
| 278 | * @edev: the sas_expander_device object |
| 279 | * |
| 280 | * Fills in the sas_expander_device object when SMP port is created. |
| 281 | * |
| 282 | * Returns 0 for success, non-zero for failure. |
| 283 | */ |
| 284 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 285 | _transport_expander_report_manufacture(struct MPT2SAS_ADAPTER *ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 286 | u64 sas_address, struct sas_expander_device *edev) |
| 287 | { |
| 288 | Mpi2SmpPassthroughRequest_t *mpi_request; |
| 289 | Mpi2SmpPassthroughReply_t *mpi_reply; |
| 290 | struct rep_manu_reply *manufacture_reply; |
| 291 | struct rep_manu_request *manufacture_request; |
| 292 | int rc; |
| 293 | u16 smid; |
| 294 | u32 ioc_state; |
| 295 | unsigned long timeleft; |
| 296 | void *psge; |
| 297 | u32 sgl_flags; |
| 298 | u8 issue_reset = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 299 | void *data_out = NULL; |
| 300 | dma_addr_t data_out_dma; |
| 301 | u32 sz; |
| 302 | u64 *sas_address_le; |
| 303 | u16 wait_state_count; |
| 304 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 305 | if (ioc->shost_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 306 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 307 | __func__, ioc->name); |
| 308 | return -EFAULT; |
| 309 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 310 | |
| 311 | mutex_lock(&ioc->transport_cmds.mutex); |
| 312 | |
| 313 | if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) { |
| 314 | printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n", |
| 315 | ioc->name, __func__); |
| 316 | rc = -EAGAIN; |
| 317 | goto out; |
| 318 | } |
| 319 | ioc->transport_cmds.status = MPT2_CMD_PENDING; |
| 320 | |
| 321 | wait_state_count = 0; |
| 322 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 323 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 324 | if (wait_state_count++ == 10) { |
| 325 | printk(MPT2SAS_ERR_FMT |
| 326 | "%s: failed due to ioc not operational\n", |
| 327 | ioc->name, __func__); |
| 328 | rc = -EFAULT; |
| 329 | goto out; |
| 330 | } |
| 331 | ssleep(1); |
| 332 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 333 | printk(MPT2SAS_INFO_FMT "%s: waiting for " |
| 334 | "operational state(count=%d)\n", ioc->name, |
| 335 | __func__, wait_state_count); |
| 336 | } |
| 337 | if (wait_state_count) |
| 338 | printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n", |
| 339 | ioc->name, __func__); |
| 340 | |
| 341 | smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx); |
| 342 | if (!smid) { |
| 343 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 344 | ioc->name, __func__); |
| 345 | rc = -EAGAIN; |
| 346 | goto out; |
| 347 | } |
| 348 | |
| 349 | rc = 0; |
| 350 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 351 | ioc->transport_cmds.smid = smid; |
| 352 | |
| 353 | sz = sizeof(struct rep_manu_request) + sizeof(struct rep_manu_reply); |
| 354 | data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma); |
| 355 | |
| 356 | if (!data_out) { |
| 357 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, |
| 358 | __LINE__, __func__); |
| 359 | rc = -ENOMEM; |
| 360 | mpt2sas_base_free_smid(ioc, smid); |
| 361 | goto out; |
| 362 | } |
| 363 | |
| 364 | manufacture_request = data_out; |
| 365 | manufacture_request->smp_frame_type = 0x40; |
| 366 | manufacture_request->function = 1; |
| 367 | manufacture_request->reserved = 0; |
| 368 | manufacture_request->request_length = 0; |
| 369 | |
| 370 | memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t)); |
| 371 | mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH; |
| 372 | mpi_request->PhysicalPort = 0xFF; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 373 | mpi_request->VF_ID = 0; /* TODO */ |
| 374 | mpi_request->VP_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 375 | sas_address_le = (u64 *)&mpi_request->SASAddress; |
| 376 | *sas_address_le = cpu_to_le64(sas_address); |
| 377 | mpi_request->RequestDataLength = sizeof(struct rep_manu_request); |
| 378 | psge = &mpi_request->SGL; |
| 379 | |
| 380 | /* WRITE sgel first */ |
| 381 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 382 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); |
| 383 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 384 | ioc->base_add_sg_single(psge, sgl_flags | |
| 385 | sizeof(struct rep_manu_request), data_out_dma); |
| 386 | |
| 387 | /* incr sgel */ |
| 388 | psge += ioc->sge_size; |
| 389 | |
| 390 | /* READ sgel last */ |
| 391 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 392 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 393 | MPI2_SGE_FLAGS_END_OF_LIST); |
| 394 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 395 | ioc->base_add_sg_single(psge, sgl_flags | |
| 396 | sizeof(struct rep_manu_reply), data_out_dma + |
| 397 | sizeof(struct rep_manu_request)); |
| 398 | |
| 399 | dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT "report_manufacture - " |
| 400 | "send to sas_addr(0x%016llx)\n", ioc->name, |
| 401 | (unsigned long long)sas_address)); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 402 | mpt2sas_base_put_smid_default(ioc, smid); |
Kashyap, Desai | bcfb6e6 | 2009-09-14 11:05:24 +0530 | [diff] [blame] | 403 | init_completion(&ioc->transport_cmds.done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 404 | timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done, |
| 405 | 10*HZ); |
| 406 | |
| 407 | if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) { |
| 408 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 409 | ioc->name, __func__); |
| 410 | _debug_dump_mf(mpi_request, |
| 411 | sizeof(Mpi2SmpPassthroughRequest_t)/4); |
| 412 | if (!(ioc->transport_cmds.status & MPT2_CMD_RESET)) |
| 413 | issue_reset = 1; |
| 414 | goto issue_host_reset; |
| 415 | } |
| 416 | |
| 417 | dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT "report_manufacture - " |
| 418 | "complete\n", ioc->name)); |
| 419 | |
| 420 | if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 421 | u8 *tmp; |
| 422 | |
| 423 | mpi_reply = ioc->transport_cmds.reply; |
| 424 | |
| 425 | dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT |
| 426 | "report_manufacture - reply data transfer size(%d)\n", |
| 427 | ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength))); |
| 428 | |
| 429 | if (le16_to_cpu(mpi_reply->ResponseDataLength) != |
| 430 | sizeof(struct rep_manu_reply)) |
| 431 | goto out; |
| 432 | |
| 433 | manufacture_reply = data_out + sizeof(struct rep_manu_request); |
| 434 | strncpy(edev->vendor_id, manufacture_reply->vendor_id, |
| 435 | SAS_EXPANDER_VENDOR_ID_LEN); |
| 436 | strncpy(edev->product_id, manufacture_reply->product_id, |
| 437 | SAS_EXPANDER_PRODUCT_ID_LEN); |
| 438 | strncpy(edev->product_rev, manufacture_reply->product_rev, |
| 439 | SAS_EXPANDER_PRODUCT_REV_LEN); |
| 440 | edev->level = manufacture_reply->sas_format; |
| 441 | if (manufacture_reply->sas_format) { |
| 442 | strncpy(edev->component_vendor_id, |
| 443 | manufacture_reply->component_vendor_id, |
| 444 | SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN); |
| 445 | tmp = (u8 *)&manufacture_reply->component_id; |
| 446 | edev->component_id = tmp[0] << 8 | tmp[1]; |
| 447 | edev->component_revision_id = |
| 448 | manufacture_reply->component_revision_id; |
| 449 | } |
| 450 | } else |
| 451 | dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT |
| 452 | "report_manufacture - no reply\n", ioc->name)); |
| 453 | |
| 454 | issue_host_reset: |
| 455 | if (issue_reset) |
| 456 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 457 | FORCE_BIG_HAMMER); |
| 458 | out: |
| 459 | ioc->transport_cmds.status = MPT2_CMD_NOT_USED; |
| 460 | if (data_out) |
| 461 | pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma); |
| 462 | |
| 463 | mutex_unlock(&ioc->transport_cmds.mutex); |
| 464 | return rc; |
| 465 | } |
| 466 | |
| 467 | /** |
| 468 | * mpt2sas_transport_port_add - insert port to the list |
| 469 | * @ioc: per adapter object |
| 470 | * @handle: handle of attached device |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 471 | * @sas_address: sas address of parent expander or sas host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 472 | * Context: This function will acquire ioc->sas_node_lock. |
| 473 | * |
| 474 | * Adding new port object to the sas_node->sas_port_list. |
| 475 | * |
| 476 | * Returns mpt2sas_port. |
| 477 | */ |
| 478 | struct _sas_port * |
| 479 | mpt2sas_transport_port_add(struct MPT2SAS_ADAPTER *ioc, u16 handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 480 | u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 481 | { |
| 482 | struct _sas_phy *mpt2sas_phy, *next; |
| 483 | struct _sas_port *mpt2sas_port; |
| 484 | unsigned long flags; |
| 485 | struct _sas_node *sas_node; |
| 486 | struct sas_rphy *rphy; |
| 487 | int i; |
| 488 | struct sas_port *port; |
| 489 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 490 | mpt2sas_port = kzalloc(sizeof(struct _sas_port), |
| 491 | GFP_KERNEL); |
| 492 | if (!mpt2sas_port) { |
| 493 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 494 | ioc->name, __FILE__, __LINE__, __func__); |
| 495 | return NULL; |
| 496 | } |
| 497 | |
| 498 | INIT_LIST_HEAD(&mpt2sas_port->port_list); |
| 499 | INIT_LIST_HEAD(&mpt2sas_port->phy_list); |
| 500 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 501 | sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 502 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 503 | |
| 504 | if (!sas_node) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 505 | printk(MPT2SAS_ERR_FMT "%s: Could not find " |
| 506 | "parent sas_address(0x%016llx)!\n", ioc->name, |
| 507 | __func__, (unsigned long long)sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 508 | goto out_fail; |
| 509 | } |
| 510 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 511 | if ((_transport_set_identify(ioc, handle, |
| 512 | &mpt2sas_port->remote_identify))) { |
| 513 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 514 | ioc->name, __FILE__, __LINE__, __func__); |
| 515 | goto out_fail; |
| 516 | } |
| 517 | |
| 518 | if (mpt2sas_port->remote_identify.device_type == SAS_PHY_UNUSED) { |
| 519 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 520 | ioc->name, __FILE__, __LINE__, __func__); |
| 521 | goto out_fail; |
| 522 | } |
| 523 | |
| 524 | for (i = 0; i < sas_node->num_phys; i++) { |
| 525 | if (sas_node->phy[i].remote_identify.sas_address != |
| 526 | mpt2sas_port->remote_identify.sas_address) |
| 527 | continue; |
| 528 | list_add_tail(&sas_node->phy[i].port_siblings, |
| 529 | &mpt2sas_port->phy_list); |
| 530 | mpt2sas_port->num_phys++; |
| 531 | } |
| 532 | |
| 533 | if (!mpt2sas_port->num_phys) { |
| 534 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 535 | ioc->name, __FILE__, __LINE__, __func__); |
| 536 | goto out_fail; |
| 537 | } |
| 538 | |
| 539 | port = sas_port_alloc_num(sas_node->parent_dev); |
| 540 | if ((sas_port_add(port))) { |
| 541 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 542 | ioc->name, __FILE__, __LINE__, __func__); |
| 543 | goto out_fail; |
| 544 | } |
| 545 | |
| 546 | list_for_each_entry(mpt2sas_phy, &mpt2sas_port->phy_list, |
| 547 | port_siblings) { |
| 548 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) |
| 549 | dev_printk(KERN_INFO, &port->dev, "add: handle(0x%04x)" |
| 550 | ", sas_addr(0x%016llx), phy(%d)\n", handle, |
| 551 | (unsigned long long) |
| 552 | mpt2sas_port->remote_identify.sas_address, |
| 553 | mpt2sas_phy->phy_id); |
| 554 | sas_port_add_phy(port, mpt2sas_phy->phy); |
| 555 | } |
| 556 | |
| 557 | mpt2sas_port->port = port; |
| 558 | if (mpt2sas_port->remote_identify.device_type == SAS_END_DEVICE) |
| 559 | rphy = sas_end_device_alloc(port); |
| 560 | else |
| 561 | rphy = sas_expander_alloc(port, |
| 562 | mpt2sas_port->remote_identify.device_type); |
| 563 | |
| 564 | rphy->identify = mpt2sas_port->remote_identify; |
| 565 | if ((sas_rphy_add(rphy))) { |
| 566 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 567 | ioc->name, __FILE__, __LINE__, __func__); |
| 568 | } |
| 569 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) |
| 570 | dev_printk(KERN_INFO, &rphy->dev, "add: handle(0x%04x), " |
| 571 | "sas_addr(0x%016llx)\n", handle, |
| 572 | (unsigned long long) |
| 573 | mpt2sas_port->remote_identify.sas_address); |
| 574 | mpt2sas_port->rphy = rphy; |
| 575 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 576 | list_add_tail(&mpt2sas_port->port_list, &sas_node->sas_port_list); |
| 577 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 578 | |
| 579 | /* fill in report manufacture */ |
| 580 | if (mpt2sas_port->remote_identify.device_type == |
| 581 | MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER || |
| 582 | mpt2sas_port->remote_identify.device_type == |
| 583 | MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 584 | _transport_expander_report_manufacture(ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 585 | mpt2sas_port->remote_identify.sas_address, |
| 586 | rphy_to_expander_device(rphy)); |
| 587 | |
| 588 | return mpt2sas_port; |
| 589 | |
| 590 | out_fail: |
| 591 | list_for_each_entry_safe(mpt2sas_phy, next, &mpt2sas_port->phy_list, |
| 592 | port_siblings) |
| 593 | list_del(&mpt2sas_phy->port_siblings); |
| 594 | kfree(mpt2sas_port); |
| 595 | return NULL; |
| 596 | } |
| 597 | |
| 598 | /** |
| 599 | * mpt2sas_transport_port_remove - remove port from the list |
| 600 | * @ioc: per adapter object |
| 601 | * @sas_address: sas address of attached device |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 602 | * @sas_address_parent: sas address of parent expander or sas host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 603 | * Context: This function will acquire ioc->sas_node_lock. |
| 604 | * |
| 605 | * Removing object and freeing associated memory from the |
| 606 | * ioc->sas_port_list. |
| 607 | * |
| 608 | * Return nothing. |
| 609 | */ |
| 610 | void |
| 611 | mpt2sas_transport_port_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 612 | u64 sas_address_parent) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 613 | { |
| 614 | int i; |
| 615 | unsigned long flags; |
| 616 | struct _sas_port *mpt2sas_port, *next; |
| 617 | struct _sas_node *sas_node; |
| 618 | u8 found = 0; |
| 619 | struct _sas_phy *mpt2sas_phy, *next_phy; |
| 620 | |
| 621 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 622 | sas_node = _transport_sas_node_find_by_sas_address(ioc, |
| 623 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 624 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 625 | if (!sas_node) |
| 626 | return; |
| 627 | list_for_each_entry_safe(mpt2sas_port, next, &sas_node->sas_port_list, |
| 628 | port_list) { |
| 629 | if (mpt2sas_port->remote_identify.sas_address != sas_address) |
| 630 | continue; |
| 631 | found = 1; |
| 632 | list_del(&mpt2sas_port->port_list); |
| 633 | goto out; |
| 634 | } |
| 635 | out: |
| 636 | if (!found) |
| 637 | return; |
| 638 | |
| 639 | for (i = 0; i < sas_node->num_phys; i++) { |
| 640 | if (sas_node->phy[i].remote_identify.sas_address == sas_address) |
| 641 | memset(&sas_node->phy[i].remote_identify, 0 , |
| 642 | sizeof(struct sas_identify)); |
| 643 | } |
| 644 | |
| 645 | list_for_each_entry_safe(mpt2sas_phy, next_phy, |
| 646 | &mpt2sas_port->phy_list, port_siblings) { |
| 647 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) |
| 648 | dev_printk(KERN_INFO, &mpt2sas_port->port->dev, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 649 | "remove: sas_addr(0x%016llx), phy(%d)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 650 | (unsigned long long) |
| 651 | mpt2sas_port->remote_identify.sas_address, |
| 652 | mpt2sas_phy->phy_id); |
| 653 | sas_port_delete_phy(mpt2sas_port->port, mpt2sas_phy->phy); |
| 654 | list_del(&mpt2sas_phy->port_siblings); |
| 655 | } |
| 656 | sas_port_delete(mpt2sas_port->port); |
| 657 | kfree(mpt2sas_port); |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * mpt2sas_transport_add_host_phy - report sas_host phy to transport |
| 662 | * @ioc: per adapter object |
| 663 | * @mpt2sas_phy: mpt2sas per phy object |
| 664 | * @phy_pg0: sas phy page 0 |
| 665 | * @parent_dev: parent device class object |
| 666 | * |
| 667 | * Returns 0 for success, non-zero for failure. |
| 668 | */ |
| 669 | int |
| 670 | mpt2sas_transport_add_host_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy |
| 671 | *mpt2sas_phy, Mpi2SasPhyPage0_t phy_pg0, struct device *parent_dev) |
| 672 | { |
| 673 | struct sas_phy *phy; |
| 674 | int phy_index = mpt2sas_phy->phy_id; |
| 675 | |
| 676 | |
| 677 | INIT_LIST_HEAD(&mpt2sas_phy->port_siblings); |
| 678 | phy = sas_phy_alloc(parent_dev, phy_index); |
| 679 | if (!phy) { |
| 680 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 681 | ioc->name, __FILE__, __LINE__, __func__); |
| 682 | return -1; |
| 683 | } |
| 684 | if ((_transport_set_identify(ioc, mpt2sas_phy->handle, |
| 685 | &mpt2sas_phy->identify))) { |
| 686 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 687 | ioc->name, __FILE__, __LINE__, __func__); |
| 688 | return -1; |
| 689 | } |
| 690 | phy->identify = mpt2sas_phy->identify; |
| 691 | mpt2sas_phy->attached_handle = le16_to_cpu(phy_pg0.AttachedDevHandle); |
| 692 | if (mpt2sas_phy->attached_handle) |
| 693 | _transport_set_identify(ioc, mpt2sas_phy->attached_handle, |
| 694 | &mpt2sas_phy->remote_identify); |
| 695 | phy->identify.phy_identifier = mpt2sas_phy->phy_id; |
| 696 | phy->negotiated_linkrate = _transport_convert_phy_link_rate( |
| 697 | phy_pg0.NegotiatedLinkRate & MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL); |
| 698 | phy->minimum_linkrate_hw = _transport_convert_phy_link_rate( |
| 699 | phy_pg0.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK); |
| 700 | phy->maximum_linkrate_hw = _transport_convert_phy_link_rate( |
| 701 | phy_pg0.HwLinkRate >> 4); |
| 702 | phy->minimum_linkrate = _transport_convert_phy_link_rate( |
| 703 | phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK); |
| 704 | phy->maximum_linkrate = _transport_convert_phy_link_rate( |
| 705 | phy_pg0.ProgrammedLinkRate >> 4); |
| 706 | |
| 707 | if ((sas_phy_add(phy))) { |
| 708 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 709 | ioc->name, __FILE__, __LINE__, __func__); |
| 710 | sas_phy_free(phy); |
| 711 | return -1; |
| 712 | } |
| 713 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) |
| 714 | dev_printk(KERN_INFO, &phy->dev, |
| 715 | "add: handle(0x%04x), sas_addr(0x%016llx)\n" |
| 716 | "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n", |
| 717 | mpt2sas_phy->handle, (unsigned long long) |
| 718 | mpt2sas_phy->identify.sas_address, |
| 719 | mpt2sas_phy->attached_handle, |
| 720 | (unsigned long long) |
| 721 | mpt2sas_phy->remote_identify.sas_address); |
| 722 | mpt2sas_phy->phy = phy; |
| 723 | return 0; |
| 724 | } |
| 725 | |
| 726 | |
| 727 | /** |
| 728 | * mpt2sas_transport_add_expander_phy - report expander phy to transport |
| 729 | * @ioc: per adapter object |
| 730 | * @mpt2sas_phy: mpt2sas per phy object |
| 731 | * @expander_pg1: expander page 1 |
| 732 | * @parent_dev: parent device class object |
| 733 | * |
| 734 | * Returns 0 for success, non-zero for failure. |
| 735 | */ |
| 736 | int |
| 737 | mpt2sas_transport_add_expander_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy |
| 738 | *mpt2sas_phy, Mpi2ExpanderPage1_t expander_pg1, struct device *parent_dev) |
| 739 | { |
| 740 | struct sas_phy *phy; |
| 741 | int phy_index = mpt2sas_phy->phy_id; |
| 742 | |
| 743 | INIT_LIST_HEAD(&mpt2sas_phy->port_siblings); |
| 744 | phy = sas_phy_alloc(parent_dev, phy_index); |
| 745 | if (!phy) { |
| 746 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 747 | ioc->name, __FILE__, __LINE__, __func__); |
| 748 | return -1; |
| 749 | } |
| 750 | if ((_transport_set_identify(ioc, mpt2sas_phy->handle, |
| 751 | &mpt2sas_phy->identify))) { |
| 752 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 753 | ioc->name, __FILE__, __LINE__, __func__); |
| 754 | return -1; |
| 755 | } |
| 756 | phy->identify = mpt2sas_phy->identify; |
| 757 | mpt2sas_phy->attached_handle = |
| 758 | le16_to_cpu(expander_pg1.AttachedDevHandle); |
| 759 | if (mpt2sas_phy->attached_handle) |
| 760 | _transport_set_identify(ioc, mpt2sas_phy->attached_handle, |
| 761 | &mpt2sas_phy->remote_identify); |
| 762 | phy->identify.phy_identifier = mpt2sas_phy->phy_id; |
| 763 | phy->negotiated_linkrate = _transport_convert_phy_link_rate( |
| 764 | expander_pg1.NegotiatedLinkRate & |
| 765 | MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL); |
| 766 | phy->minimum_linkrate_hw = _transport_convert_phy_link_rate( |
| 767 | expander_pg1.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK); |
| 768 | phy->maximum_linkrate_hw = _transport_convert_phy_link_rate( |
| 769 | expander_pg1.HwLinkRate >> 4); |
| 770 | phy->minimum_linkrate = _transport_convert_phy_link_rate( |
| 771 | expander_pg1.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK); |
| 772 | phy->maximum_linkrate = _transport_convert_phy_link_rate( |
| 773 | expander_pg1.ProgrammedLinkRate >> 4); |
| 774 | |
| 775 | if ((sas_phy_add(phy))) { |
| 776 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 777 | ioc->name, __FILE__, __LINE__, __func__); |
| 778 | sas_phy_free(phy); |
| 779 | return -1; |
| 780 | } |
| 781 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) |
| 782 | dev_printk(KERN_INFO, &phy->dev, |
| 783 | "add: handle(0x%04x), sas_addr(0x%016llx)\n" |
| 784 | "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n", |
| 785 | mpt2sas_phy->handle, (unsigned long long) |
| 786 | mpt2sas_phy->identify.sas_address, |
| 787 | mpt2sas_phy->attached_handle, |
| 788 | (unsigned long long) |
| 789 | mpt2sas_phy->remote_identify.sas_address); |
| 790 | mpt2sas_phy->phy = phy; |
| 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | /** |
Kashyap, Desai | cc0f520 | 2009-08-20 13:22:39 +0530 | [diff] [blame] | 795 | * mpt2sas_transport_update_links - refreshing phy link changes |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 796 | * @ioc: per adapter object |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 797 | * @sas_address: sas address of parent expander or sas host |
| 798 | * @handle: attached device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 799 | * @phy_numberv: phy number |
| 800 | * @link_rate: new link rate |
| 801 | * |
| 802 | * Returns nothing. |
| 803 | */ |
| 804 | void |
Kashyap, Desai | cc0f520 | 2009-08-20 13:22:39 +0530 | [diff] [blame] | 805 | mpt2sas_transport_update_links(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 806 | u64 sas_address, u16 handle, u8 phy_number, u8 link_rate) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 807 | { |
| 808 | unsigned long flags; |
| 809 | struct _sas_node *sas_node; |
| 810 | struct _sas_phy *mpt2sas_phy; |
| 811 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 812 | if (ioc->shost_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 813 | return; |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 814 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 815 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 816 | sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 817 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 818 | if (!sas_node) |
| 819 | return; |
| 820 | |
| 821 | mpt2sas_phy = &sas_node->phy[phy_number]; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 822 | mpt2sas_phy->attached_handle = handle; |
| 823 | if (handle && (link_rate >= MPI2_SAS_NEG_LINK_RATE_1_5)) |
| 824 | _transport_set_identify(ioc, handle, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 825 | &mpt2sas_phy->remote_identify); |
| 826 | else |
| 827 | memset(&mpt2sas_phy->remote_identify, 0 , sizeof(struct |
| 828 | sas_identify)); |
| 829 | |
| 830 | if (mpt2sas_phy->phy) |
| 831 | mpt2sas_phy->phy->negotiated_linkrate = |
| 832 | _transport_convert_phy_link_rate(link_rate); |
| 833 | |
| 834 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) |
| 835 | dev_printk(KERN_INFO, &mpt2sas_phy->phy->dev, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 836 | "refresh: parent sas_addr(0x%016llx),\n" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 837 | "\tlink_rate(0x%02x), phy(%d)\n" |
| 838 | "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n", |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame^] | 839 | (unsigned long long)sas_address, |
| 840 | link_rate, phy_number, handle, (unsigned long long) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 841 | mpt2sas_phy->remote_identify.sas_address); |
| 842 | } |
| 843 | |
| 844 | static inline void * |
| 845 | phy_to_ioc(struct sas_phy *phy) |
| 846 | { |
| 847 | struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); |
| 848 | return shost_priv(shost); |
| 849 | } |
| 850 | |
| 851 | static inline void * |
| 852 | rphy_to_ioc(struct sas_rphy *rphy) |
| 853 | { |
| 854 | struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent); |
| 855 | return shost_priv(shost); |
| 856 | } |
| 857 | |
| 858 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 859 | * _transport_get_linkerrors - |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 860 | * @phy: The sas phy object |
| 861 | * |
| 862 | * Only support sas_host direct attached phys. |
| 863 | * Returns 0 for success, non-zero for failure. |
| 864 | * |
| 865 | */ |
| 866 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 867 | _transport_get_linkerrors(struct sas_phy *phy) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 868 | { |
| 869 | struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy); |
| 870 | struct _sas_phy *mpt2sas_phy; |
| 871 | Mpi2ConfigReply_t mpi_reply; |
| 872 | Mpi2SasPhyPage1_t phy_pg1; |
| 873 | int i; |
| 874 | |
| 875 | for (i = 0, mpt2sas_phy = NULL; i < ioc->sas_hba.num_phys && |
| 876 | !mpt2sas_phy; i++) { |
| 877 | if (ioc->sas_hba.phy[i].phy != phy) |
| 878 | continue; |
| 879 | mpt2sas_phy = &ioc->sas_hba.phy[i]; |
| 880 | } |
| 881 | |
| 882 | if (!mpt2sas_phy) /* this phy not on sas_host */ |
| 883 | return -EINVAL; |
| 884 | |
| 885 | if ((mpt2sas_config_get_phy_pg1(ioc, &mpi_reply, &phy_pg1, |
| 886 | mpt2sas_phy->phy_id))) { |
| 887 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 888 | ioc->name, __FILE__, __LINE__, __func__); |
| 889 | return -ENXIO; |
| 890 | } |
| 891 | |
| 892 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) |
| 893 | printk(MPT2SAS_INFO_FMT "phy(%d), ioc_status" |
| 894 | "(0x%04x), loginfo(0x%08x)\n", ioc->name, |
| 895 | mpt2sas_phy->phy_id, |
| 896 | le16_to_cpu(mpi_reply.IOCStatus), |
| 897 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 898 | |
| 899 | phy->invalid_dword_count = le32_to_cpu(phy_pg1.InvalidDwordCount); |
| 900 | phy->running_disparity_error_count = |
| 901 | le32_to_cpu(phy_pg1.RunningDisparityErrorCount); |
| 902 | phy->loss_of_dword_sync_count = |
| 903 | le32_to_cpu(phy_pg1.LossDwordSynchCount); |
| 904 | phy->phy_reset_problem_count = |
| 905 | le32_to_cpu(phy_pg1.PhyResetProblemCount); |
| 906 | return 0; |
| 907 | } |
| 908 | |
| 909 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 910 | * _transport_get_enclosure_identifier - |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 911 | * @phy: The sas phy object |
| 912 | * |
| 913 | * Obtain the enclosure logical id for an expander. |
| 914 | * Returns 0 for success, non-zero for failure. |
| 915 | */ |
| 916 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 917 | _transport_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 918 | { |
| 919 | struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy); |
| 920 | struct _sas_node *sas_expander; |
| 921 | unsigned long flags; |
| 922 | |
| 923 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 924 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 925 | rphy->identify.sas_address); |
| 926 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 927 | |
| 928 | if (!sas_expander) |
| 929 | return -ENXIO; |
| 930 | |
| 931 | *identifier = sas_expander->enclosure_logical_id; |
| 932 | return 0; |
| 933 | } |
| 934 | |
| 935 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 936 | * _transport_get_bay_identifier - |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 937 | * @phy: The sas phy object |
| 938 | * |
| 939 | * Returns the slot id for a device that resides inside an enclosure. |
| 940 | */ |
| 941 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 942 | _transport_get_bay_identifier(struct sas_rphy *rphy) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 943 | { |
| 944 | struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy); |
| 945 | struct _sas_device *sas_device; |
| 946 | unsigned long flags; |
| 947 | |
| 948 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 949 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 950 | rphy->identify.sas_address); |
| 951 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 952 | |
| 953 | if (!sas_device) |
| 954 | return -ENXIO; |
| 955 | |
| 956 | return sas_device->slot; |
| 957 | } |
| 958 | |
| 959 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 960 | * _transport_phy_reset - |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 961 | * @phy: The sas phy object |
| 962 | * @hard_reset: |
| 963 | * |
| 964 | * Only support sas_host direct attached phys. |
| 965 | * Returns 0 for success, non-zero for failure. |
| 966 | */ |
| 967 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 968 | _transport_phy_reset(struct sas_phy *phy, int hard_reset) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 969 | { |
| 970 | struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy); |
| 971 | struct _sas_phy *mpt2sas_phy; |
| 972 | Mpi2SasIoUnitControlReply_t mpi_reply; |
| 973 | Mpi2SasIoUnitControlRequest_t mpi_request; |
| 974 | int i; |
| 975 | |
| 976 | for (i = 0, mpt2sas_phy = NULL; i < ioc->sas_hba.num_phys && |
| 977 | !mpt2sas_phy; i++) { |
| 978 | if (ioc->sas_hba.phy[i].phy != phy) |
| 979 | continue; |
| 980 | mpt2sas_phy = &ioc->sas_hba.phy[i]; |
| 981 | } |
| 982 | |
| 983 | if (!mpt2sas_phy) /* this phy not on sas_host */ |
| 984 | return -EINVAL; |
| 985 | |
| 986 | memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlReply_t)); |
| 987 | mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; |
| 988 | mpi_request.Operation = hard_reset ? |
| 989 | MPI2_SAS_OP_PHY_HARD_RESET : MPI2_SAS_OP_PHY_LINK_RESET; |
| 990 | mpi_request.PhyNum = mpt2sas_phy->phy_id; |
| 991 | |
| 992 | if ((mpt2sas_base_sas_iounit_control(ioc, &mpi_reply, &mpi_request))) { |
| 993 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 994 | ioc->name, __FILE__, __LINE__, __func__); |
| 995 | return -ENXIO; |
| 996 | } |
| 997 | |
| 998 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) |
| 999 | printk(MPT2SAS_INFO_FMT "phy(%d), ioc_status" |
| 1000 | "(0x%04x), loginfo(0x%08x)\n", ioc->name, |
| 1001 | mpt2sas_phy->phy_id, |
| 1002 | le16_to_cpu(mpi_reply.IOCStatus), |
| 1003 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 1004 | |
| 1005 | return 0; |
| 1006 | } |
| 1007 | |
| 1008 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1009 | * _transport_smp_handler - transport portal for smp passthru |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1010 | * @shost: shost object |
| 1011 | * @rphy: sas transport rphy object |
| 1012 | * @req: |
| 1013 | * |
| 1014 | * This used primarily for smp_utils. |
| 1015 | * Example: |
| 1016 | * smp_rep_general /sys/class/bsg/expander-5:0 |
| 1017 | */ |
| 1018 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1019 | _transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1020 | struct request *req) |
| 1021 | { |
| 1022 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1023 | Mpi2SmpPassthroughRequest_t *mpi_request; |
| 1024 | Mpi2SmpPassthroughReply_t *mpi_reply; |
| 1025 | int rc; |
| 1026 | u16 smid; |
| 1027 | u32 ioc_state; |
| 1028 | unsigned long timeleft; |
| 1029 | void *psge; |
| 1030 | u32 sgl_flags; |
| 1031 | u8 issue_reset = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1032 | dma_addr_t dma_addr_in = 0; |
| 1033 | dma_addr_t dma_addr_out = 0; |
| 1034 | u16 wait_state_count; |
| 1035 | struct request *rsp = req->next_rq; |
| 1036 | |
| 1037 | if (!rsp) { |
| 1038 | printk(MPT2SAS_ERR_FMT "%s: the smp response space is " |
| 1039 | "missing\n", ioc->name, __func__); |
| 1040 | return -EINVAL; |
| 1041 | } |
| 1042 | |
| 1043 | /* do we need to support multiple segments? */ |
| 1044 | if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) { |
| 1045 | printk(MPT2SAS_ERR_FMT "%s: multiple segments req %u %u, " |
| 1046 | "rsp %u %u\n", ioc->name, __func__, req->bio->bi_vcnt, |
Tejun Heo | b079041 | 2009-05-07 22:24:42 +0900 | [diff] [blame] | 1047 | blk_rq_bytes(req), rsp->bio->bi_vcnt, blk_rq_bytes(rsp)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1048 | return -EINVAL; |
| 1049 | } |
| 1050 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 1051 | if (ioc->shost_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1052 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 1053 | __func__, ioc->name); |
| 1054 | return -EFAULT; |
| 1055 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1056 | |
| 1057 | rc = mutex_lock_interruptible(&ioc->transport_cmds.mutex); |
| 1058 | if (rc) |
| 1059 | return rc; |
| 1060 | |
| 1061 | if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) { |
| 1062 | printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n", ioc->name, |
| 1063 | __func__); |
| 1064 | rc = -EAGAIN; |
| 1065 | goto out; |
| 1066 | } |
| 1067 | ioc->transport_cmds.status = MPT2_CMD_PENDING; |
| 1068 | |
| 1069 | wait_state_count = 0; |
| 1070 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 1071 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 1072 | if (wait_state_count++ == 10) { |
| 1073 | printk(MPT2SAS_ERR_FMT |
| 1074 | "%s: failed due to ioc not operational\n", |
| 1075 | ioc->name, __func__); |
| 1076 | rc = -EFAULT; |
| 1077 | goto out; |
| 1078 | } |
| 1079 | ssleep(1); |
| 1080 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 1081 | printk(MPT2SAS_INFO_FMT "%s: waiting for " |
| 1082 | "operational state(count=%d)\n", ioc->name, |
| 1083 | __func__, wait_state_count); |
| 1084 | } |
| 1085 | if (wait_state_count) |
| 1086 | printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n", |
| 1087 | ioc->name, __func__); |
| 1088 | |
| 1089 | smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx); |
| 1090 | if (!smid) { |
| 1091 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 1092 | ioc->name, __func__); |
| 1093 | rc = -EAGAIN; |
| 1094 | goto out; |
| 1095 | } |
| 1096 | |
| 1097 | rc = 0; |
| 1098 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 1099 | ioc->transport_cmds.smid = smid; |
| 1100 | |
| 1101 | memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t)); |
| 1102 | mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH; |
| 1103 | mpi_request->PhysicalPort = 0xFF; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1104 | mpi_request->VF_ID = 0; /* TODO */ |
| 1105 | mpi_request->VP_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1106 | *((u64 *)&mpi_request->SASAddress) = (rphy) ? |
| 1107 | cpu_to_le64(rphy->identify.sas_address) : |
| 1108 | cpu_to_le64(ioc->sas_hba.sas_address); |
Tejun Heo | b079041 | 2009-05-07 22:24:42 +0900 | [diff] [blame] | 1109 | mpi_request->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1110 | psge = &mpi_request->SGL; |
| 1111 | |
| 1112 | /* WRITE sgel first */ |
| 1113 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1114 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); |
| 1115 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1116 | dma_addr_out = pci_map_single(ioc->pdev, bio_data(req->bio), |
Tejun Heo | b079041 | 2009-05-07 22:24:42 +0900 | [diff] [blame] | 1117 | blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1118 | if (!dma_addr_out) { |
| 1119 | mpt2sas_base_free_smid(ioc, le16_to_cpu(smid)); |
| 1120 | goto unmap; |
| 1121 | } |
| 1122 | |
Tejun Heo | b079041 | 2009-05-07 22:24:42 +0900 | [diff] [blame] | 1123 | ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(req) - 4), |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1124 | dma_addr_out); |
| 1125 | |
| 1126 | /* incr sgel */ |
| 1127 | psge += ioc->sge_size; |
| 1128 | |
| 1129 | /* READ sgel last */ |
| 1130 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1131 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 1132 | MPI2_SGE_FLAGS_END_OF_LIST); |
| 1133 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
Tejun Heo | b079041 | 2009-05-07 22:24:42 +0900 | [diff] [blame] | 1134 | dma_addr_in = pci_map_single(ioc->pdev, bio_data(rsp->bio), |
| 1135 | blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1136 | if (!dma_addr_in) { |
| 1137 | mpt2sas_base_free_smid(ioc, le16_to_cpu(smid)); |
| 1138 | goto unmap; |
| 1139 | } |
| 1140 | |
Tejun Heo | b079041 | 2009-05-07 22:24:42 +0900 | [diff] [blame] | 1141 | ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(rsp) + 4), |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1142 | dma_addr_in); |
| 1143 | |
| 1144 | dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s - " |
| 1145 | "sending smp request\n", ioc->name, __func__)); |
| 1146 | |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1147 | mpt2sas_base_put_smid_default(ioc, smid); |
Kashyap, Desai | bcfb6e6 | 2009-09-14 11:05:24 +0530 | [diff] [blame] | 1148 | init_completion(&ioc->transport_cmds.done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1149 | timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done, |
| 1150 | 10*HZ); |
| 1151 | |
| 1152 | if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) { |
| 1153 | printk(MPT2SAS_ERR_FMT "%s : timeout\n", |
| 1154 | __func__, ioc->name); |
| 1155 | _debug_dump_mf(mpi_request, |
| 1156 | sizeof(Mpi2SmpPassthroughRequest_t)/4); |
| 1157 | if (!(ioc->transport_cmds.status & MPT2_CMD_RESET)) |
| 1158 | issue_reset = 1; |
| 1159 | goto issue_host_reset; |
| 1160 | } |
| 1161 | |
| 1162 | dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s - " |
| 1163 | "complete\n", ioc->name, __func__)); |
| 1164 | |
| 1165 | if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 1166 | |
| 1167 | mpi_reply = ioc->transport_cmds.reply; |
| 1168 | |
| 1169 | dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT |
| 1170 | "%s - reply data transfer size(%d)\n", |
| 1171 | ioc->name, __func__, |
| 1172 | le16_to_cpu(mpi_reply->ResponseDataLength))); |
| 1173 | |
| 1174 | memcpy(req->sense, mpi_reply, sizeof(*mpi_reply)); |
| 1175 | req->sense_len = sizeof(*mpi_reply); |
Tejun Heo | 5f49f63 | 2009-05-19 18:33:05 +0900 | [diff] [blame] | 1176 | req->resid_len = 0; |
| 1177 | rsp->resid_len -= mpi_reply->ResponseDataLength; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1178 | } else { |
| 1179 | dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT |
| 1180 | "%s - no reply\n", ioc->name, __func__)); |
| 1181 | rc = -ENXIO; |
| 1182 | } |
| 1183 | |
| 1184 | issue_host_reset: |
| 1185 | if (issue_reset) { |
| 1186 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 1187 | FORCE_BIG_HAMMER); |
| 1188 | rc = -ETIMEDOUT; |
| 1189 | } |
| 1190 | |
| 1191 | unmap: |
| 1192 | if (dma_addr_out) |
Tejun Heo | b079041 | 2009-05-07 22:24:42 +0900 | [diff] [blame] | 1193 | pci_unmap_single(ioc->pdev, dma_addr_out, blk_rq_bytes(req), |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1194 | PCI_DMA_BIDIRECTIONAL); |
| 1195 | if (dma_addr_in) |
Tejun Heo | b079041 | 2009-05-07 22:24:42 +0900 | [diff] [blame] | 1196 | pci_unmap_single(ioc->pdev, dma_addr_in, blk_rq_bytes(rsp), |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1197 | PCI_DMA_BIDIRECTIONAL); |
| 1198 | |
| 1199 | out: |
| 1200 | ioc->transport_cmds.status = MPT2_CMD_NOT_USED; |
| 1201 | mutex_unlock(&ioc->transport_cmds.mutex); |
| 1202 | return rc; |
| 1203 | } |
| 1204 | |
| 1205 | struct sas_function_template mpt2sas_transport_functions = { |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1206 | .get_linkerrors = _transport_get_linkerrors, |
| 1207 | .get_enclosure_identifier = _transport_get_enclosure_identifier, |
| 1208 | .get_bay_identifier = _transport_get_bay_identifier, |
| 1209 | .phy_reset = _transport_phy_reset, |
| 1210 | .smp_handler = _transport_smp_handler, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1211 | }; |
| 1212 | |
| 1213 | struct scsi_transport_template *mpt2sas_transport_template; |