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 |
Sreekanth Reddy | d648d5a | 2013-07-25 11:28:01 +0530 | [diff] [blame] | 5 | * Copyright (C) 2007-2013 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 52 | #include <linux/slab.h> |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 53 | |
| 54 | #include <scsi/scsi.h> |
| 55 | #include <scsi/scsi_cmnd.h> |
| 56 | #include <scsi/scsi_device.h> |
| 57 | #include <scsi/scsi_host.h> |
| 58 | #include <scsi/scsi_transport_sas.h> |
| 59 | #include <scsi/scsi_dbg.h> |
| 60 | |
| 61 | #include "mpt2sas_base.h" |
| 62 | /** |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 63 | * _transport_sas_node_find_by_sas_address - sas node search |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 64 | * @ioc: per adapter object |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 65 | * @sas_address: sas address of expander or sas host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 66 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 67 | * |
| 68 | * Search for either hba phys or expander device based on handle, then returns |
| 69 | * the sas_node object. |
| 70 | */ |
| 71 | static struct _sas_node * |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 72 | _transport_sas_node_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 73 | u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 74 | { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 75 | if (ioc->sas_hba.sas_address == sas_address) |
| 76 | return &ioc->sas_hba; |
| 77 | else |
| 78 | return mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 79 | sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /** |
| 83 | * _transport_convert_phy_link_rate - |
| 84 | * @link_rate: link rate returned from mpt firmware |
| 85 | * |
| 86 | * Convert link_rate from mpi fusion into sas_transport form. |
| 87 | */ |
| 88 | static enum sas_linkrate |
| 89 | _transport_convert_phy_link_rate(u8 link_rate) |
| 90 | { |
| 91 | enum sas_linkrate rc; |
| 92 | |
| 93 | switch (link_rate) { |
| 94 | case MPI2_SAS_NEG_LINK_RATE_1_5: |
| 95 | rc = SAS_LINK_RATE_1_5_GBPS; |
| 96 | break; |
| 97 | case MPI2_SAS_NEG_LINK_RATE_3_0: |
| 98 | rc = SAS_LINK_RATE_3_0_GBPS; |
| 99 | break; |
| 100 | case MPI2_SAS_NEG_LINK_RATE_6_0: |
| 101 | rc = SAS_LINK_RATE_6_0_GBPS; |
| 102 | break; |
| 103 | case MPI2_SAS_NEG_LINK_RATE_PHY_DISABLED: |
| 104 | rc = SAS_PHY_DISABLED; |
| 105 | break; |
| 106 | case MPI2_SAS_NEG_LINK_RATE_NEGOTIATION_FAILED: |
| 107 | rc = SAS_LINK_RATE_FAILED; |
| 108 | break; |
| 109 | case MPI2_SAS_NEG_LINK_RATE_PORT_SELECTOR: |
| 110 | rc = SAS_SATA_PORT_SELECTOR; |
| 111 | break; |
| 112 | case MPI2_SAS_NEG_LINK_RATE_SMP_RESET_IN_PROGRESS: |
| 113 | rc = SAS_PHY_RESET_IN_PROGRESS; |
| 114 | break; |
| 115 | default: |
| 116 | case MPI2_SAS_NEG_LINK_RATE_SATA_OOB_COMPLETE: |
| 117 | case MPI2_SAS_NEG_LINK_RATE_UNKNOWN_LINK_RATE: |
| 118 | rc = SAS_LINK_RATE_UNKNOWN; |
| 119 | break; |
| 120 | } |
| 121 | return rc; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * _transport_set_identify - set identify for phys and end devices |
| 126 | * @ioc: per adapter object |
| 127 | * @handle: device handle |
| 128 | * @identify: sas identify info |
| 129 | * |
| 130 | * Populates sas identify info. |
| 131 | * |
| 132 | * Returns 0 for success, non-zero for failure. |
| 133 | */ |
| 134 | static int |
| 135 | _transport_set_identify(struct MPT2SAS_ADAPTER *ioc, u16 handle, |
| 136 | struct sas_identify *identify) |
| 137 | { |
| 138 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 139 | Mpi2ConfigReply_t mpi_reply; |
| 140 | u32 device_info; |
| 141 | u32 ioc_status; |
| 142 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 143 | if (ioc->shost_recovery || ioc->pci_error_recovery) { |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 144 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 145 | __func__, ioc->name); |
| 146 | return -EFAULT; |
| 147 | } |
| 148 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 149 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 150 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 151 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 152 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 153 | ioc->name, __FILE__, __LINE__, __func__); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 154 | return -ENXIO; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 158 | MPI2_IOCSTATUS_MASK; |
| 159 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 160 | printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x)" |
| 161 | "\nfailure at %s:%d/%s()!\n", ioc->name, handle, ioc_status, |
| 162 | __FILE__, __LINE__, __func__); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 163 | return -EIO; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 164 | } |
| 165 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 166 | memset(identify, 0, sizeof(struct sas_identify)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 167 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 168 | |
| 169 | /* sas_address */ |
| 170 | identify->sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 171 | |
nagalakshmi.nandigama@lsi.com | 64bb813 | 2012-03-20 12:08:40 +0530 | [diff] [blame] | 172 | /* phy number of the parent device this device is linked to */ |
| 173 | identify->phy_identifier = sas_device_pg0.PhyNum; |
| 174 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 175 | /* device_type */ |
| 176 | switch (device_info & MPI2_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) { |
| 177 | case MPI2_SAS_DEVICE_INFO_NO_DEVICE: |
| 178 | identify->device_type = SAS_PHY_UNUSED; |
| 179 | break; |
| 180 | case MPI2_SAS_DEVICE_INFO_END_DEVICE: |
| 181 | identify->device_type = SAS_END_DEVICE; |
| 182 | break; |
| 183 | case MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER: |
| 184 | identify->device_type = SAS_EDGE_EXPANDER_DEVICE; |
| 185 | break; |
| 186 | case MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER: |
| 187 | identify->device_type = SAS_FANOUT_EXPANDER_DEVICE; |
| 188 | break; |
| 189 | } |
| 190 | |
| 191 | /* initiator_port_protocols */ |
| 192 | if (device_info & MPI2_SAS_DEVICE_INFO_SSP_INITIATOR) |
| 193 | identify->initiator_port_protocols |= SAS_PROTOCOL_SSP; |
| 194 | if (device_info & MPI2_SAS_DEVICE_INFO_STP_INITIATOR) |
| 195 | identify->initiator_port_protocols |= SAS_PROTOCOL_STP; |
| 196 | if (device_info & MPI2_SAS_DEVICE_INFO_SMP_INITIATOR) |
| 197 | identify->initiator_port_protocols |= SAS_PROTOCOL_SMP; |
| 198 | if (device_info & MPI2_SAS_DEVICE_INFO_SATA_HOST) |
| 199 | identify->initiator_port_protocols |= SAS_PROTOCOL_SATA; |
| 200 | |
| 201 | /* target_port_protocols */ |
| 202 | if (device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
| 203 | identify->target_port_protocols |= SAS_PROTOCOL_SSP; |
| 204 | if (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
| 205 | identify->target_port_protocols |= SAS_PROTOCOL_STP; |
| 206 | if (device_info & MPI2_SAS_DEVICE_INFO_SMP_TARGET) |
| 207 | identify->target_port_protocols |= SAS_PROTOCOL_SMP; |
| 208 | if (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 209 | identify->target_port_protocols |= SAS_PROTOCOL_SATA; |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * mpt2sas_transport_done - internal transport layer callback handler. |
| 216 | * @ioc: per adapter object |
| 217 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 218 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 219 | * @reply: reply message frame(lower 32bit addr) |
| 220 | * |
| 221 | * Callback handler when sending internal generated transport cmds. |
| 222 | * The callback index passed is `ioc->transport_cb_idx` |
| 223 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 224 | * Return 1 meaning mf should be freed from _base_interrupt |
| 225 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 226 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 227 | u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 228 | mpt2sas_transport_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 229 | u32 reply) |
| 230 | { |
| 231 | MPI2DefaultReply_t *mpi_reply; |
| 232 | |
| 233 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 234 | if (ioc->transport_cmds.status == MPT2_CMD_NOT_USED) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 235 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 236 | if (ioc->transport_cmds.smid != smid) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 237 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 238 | ioc->transport_cmds.status |= MPT2_CMD_COMPLETE; |
| 239 | if (mpi_reply) { |
| 240 | memcpy(ioc->transport_cmds.reply, mpi_reply, |
| 241 | mpi_reply->MsgLength*4); |
| 242 | ioc->transport_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 243 | } |
| 244 | ioc->transport_cmds.status &= ~MPT2_CMD_PENDING; |
| 245 | complete(&ioc->transport_cmds.done); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 246 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /* report manufacture request structure */ |
| 250 | struct rep_manu_request{ |
| 251 | u8 smp_frame_type; |
| 252 | u8 function; |
| 253 | u8 reserved; |
| 254 | u8 request_length; |
| 255 | }; |
| 256 | |
| 257 | /* report manufacture reply structure */ |
| 258 | struct rep_manu_reply{ |
| 259 | u8 smp_frame_type; /* 0x41 */ |
| 260 | u8 function; /* 0x01 */ |
| 261 | u8 function_result; |
| 262 | u8 response_length; |
| 263 | u16 expander_change_count; |
| 264 | u8 reserved0[2]; |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 265 | u8 sas_format; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 266 | u8 reserved2[3]; |
| 267 | u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN]; |
| 268 | u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN]; |
| 269 | u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN]; |
| 270 | u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN]; |
| 271 | u16 component_id; |
| 272 | u8 component_revision_id; |
| 273 | u8 reserved3; |
| 274 | u8 vendor_specific[8]; |
| 275 | }; |
| 276 | |
| 277 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 278 | * _transport_expander_report_manufacture - obtain SMP report_manufacture |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 279 | * @ioc: per adapter object |
| 280 | * @sas_address: expander sas address |
| 281 | * @edev: the sas_expander_device object |
| 282 | * |
| 283 | * Fills in the sas_expander_device object when SMP port is created. |
| 284 | * |
| 285 | * Returns 0 for success, non-zero for failure. |
| 286 | */ |
| 287 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 288 | _transport_expander_report_manufacture(struct MPT2SAS_ADAPTER *ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 289 | u64 sas_address, struct sas_expander_device *edev) |
| 290 | { |
| 291 | Mpi2SmpPassthroughRequest_t *mpi_request; |
| 292 | Mpi2SmpPassthroughReply_t *mpi_reply; |
| 293 | struct rep_manu_reply *manufacture_reply; |
| 294 | struct rep_manu_request *manufacture_request; |
| 295 | int rc; |
| 296 | u16 smid; |
| 297 | u32 ioc_state; |
| 298 | unsigned long timeleft; |
| 299 | void *psge; |
| 300 | u32 sgl_flags; |
| 301 | u8 issue_reset = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 302 | void *data_out = NULL; |
| 303 | dma_addr_t data_out_dma; |
| 304 | u32 sz; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 305 | u16 wait_state_count; |
| 306 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 307 | if (ioc->shost_recovery || ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 308 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 309 | __func__, ioc->name); |
| 310 | return -EFAULT; |
| 311 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 312 | |
| 313 | mutex_lock(&ioc->transport_cmds.mutex); |
| 314 | |
| 315 | if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) { |
| 316 | printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n", |
| 317 | ioc->name, __func__); |
| 318 | rc = -EAGAIN; |
| 319 | goto out; |
| 320 | } |
| 321 | ioc->transport_cmds.status = MPT2_CMD_PENDING; |
| 322 | |
| 323 | wait_state_count = 0; |
| 324 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 325 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 326 | if (wait_state_count++ == 10) { |
| 327 | printk(MPT2SAS_ERR_FMT |
| 328 | "%s: failed due to ioc not operational\n", |
| 329 | ioc->name, __func__); |
| 330 | rc = -EFAULT; |
| 331 | goto out; |
| 332 | } |
| 333 | ssleep(1); |
| 334 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 335 | printk(MPT2SAS_INFO_FMT "%s: waiting for " |
| 336 | "operational state(count=%d)\n", ioc->name, |
| 337 | __func__, wait_state_count); |
| 338 | } |
| 339 | if (wait_state_count) |
| 340 | printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n", |
| 341 | ioc->name, __func__); |
| 342 | |
| 343 | smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx); |
| 344 | if (!smid) { |
| 345 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 346 | ioc->name, __func__); |
| 347 | rc = -EAGAIN; |
| 348 | goto out; |
| 349 | } |
| 350 | |
| 351 | rc = 0; |
| 352 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 353 | ioc->transport_cmds.smid = smid; |
| 354 | |
| 355 | sz = sizeof(struct rep_manu_request) + sizeof(struct rep_manu_reply); |
| 356 | data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma); |
| 357 | |
| 358 | if (!data_out) { |
| 359 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, |
| 360 | __LINE__, __func__); |
| 361 | rc = -ENOMEM; |
| 362 | mpt2sas_base_free_smid(ioc, smid); |
| 363 | goto out; |
| 364 | } |
| 365 | |
| 366 | manufacture_request = data_out; |
| 367 | manufacture_request->smp_frame_type = 0x40; |
| 368 | manufacture_request->function = 1; |
| 369 | manufacture_request->reserved = 0; |
| 370 | manufacture_request->request_length = 0; |
| 371 | |
| 372 | memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t)); |
| 373 | mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH; |
| 374 | mpi_request->PhysicalPort = 0xFF; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 375 | mpi_request->VF_ID = 0; /* TODO */ |
| 376 | mpi_request->VP_ID = 0; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 377 | mpi_request->SASAddress = cpu_to_le64(sas_address); |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 378 | mpi_request->RequestDataLength = |
| 379 | cpu_to_le16(sizeof(struct rep_manu_request)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 380 | psge = &mpi_request->SGL; |
| 381 | |
| 382 | /* WRITE sgel first */ |
| 383 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 384 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); |
| 385 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 386 | ioc->base_add_sg_single(psge, sgl_flags | |
| 387 | sizeof(struct rep_manu_request), data_out_dma); |
| 388 | |
| 389 | /* incr sgel */ |
| 390 | psge += ioc->sge_size; |
| 391 | |
| 392 | /* READ sgel last */ |
| 393 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 394 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 395 | MPI2_SGE_FLAGS_END_OF_LIST); |
| 396 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 397 | ioc->base_add_sg_single(psge, sgl_flags | |
| 398 | sizeof(struct rep_manu_reply), data_out_dma + |
| 399 | sizeof(struct rep_manu_request)); |
| 400 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 401 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "report_manufacture - " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 402 | "send to sas_addr(0x%016llx)\n", ioc->name, |
| 403 | (unsigned long long)sas_address)); |
Kashyap, Desai | bcfb6e6 | 2009-09-14 11:05:24 +0530 | [diff] [blame] | 404 | init_completion(&ioc->transport_cmds.done); |
nagalakshmi.nandigama@lsi.com | f01690d | 2011-12-01 07:43:58 +0530 | [diff] [blame] | 405 | mpt2sas_base_put_smid_default(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 406 | timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done, |
| 407 | 10*HZ); |
| 408 | |
| 409 | if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) { |
| 410 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 411 | ioc->name, __func__); |
| 412 | _debug_dump_mf(mpi_request, |
| 413 | sizeof(Mpi2SmpPassthroughRequest_t)/4); |
| 414 | if (!(ioc->transport_cmds.status & MPT2_CMD_RESET)) |
| 415 | issue_reset = 1; |
| 416 | goto issue_host_reset; |
| 417 | } |
| 418 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 419 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "report_manufacture - " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 420 | "complete\n", ioc->name)); |
| 421 | |
| 422 | if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 423 | u8 *tmp; |
| 424 | |
| 425 | mpi_reply = ioc->transport_cmds.reply; |
| 426 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 427 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 428 | "report_manufacture - reply data transfer size(%d)\n", |
| 429 | ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength))); |
| 430 | |
| 431 | if (le16_to_cpu(mpi_reply->ResponseDataLength) != |
| 432 | sizeof(struct rep_manu_reply)) |
| 433 | goto out; |
| 434 | |
| 435 | manufacture_reply = data_out + sizeof(struct rep_manu_request); |
| 436 | strncpy(edev->vendor_id, manufacture_reply->vendor_id, |
| 437 | SAS_EXPANDER_VENDOR_ID_LEN); |
| 438 | strncpy(edev->product_id, manufacture_reply->product_id, |
| 439 | SAS_EXPANDER_PRODUCT_ID_LEN); |
| 440 | strncpy(edev->product_rev, manufacture_reply->product_rev, |
| 441 | SAS_EXPANDER_PRODUCT_REV_LEN); |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 442 | edev->level = manufacture_reply->sas_format & 1; |
| 443 | if (edev->level) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 444 | strncpy(edev->component_vendor_id, |
| 445 | manufacture_reply->component_vendor_id, |
| 446 | SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN); |
| 447 | tmp = (u8 *)&manufacture_reply->component_id; |
| 448 | edev->component_id = tmp[0] << 8 | tmp[1]; |
| 449 | edev->component_revision_id = |
| 450 | manufacture_reply->component_revision_id; |
| 451 | } |
| 452 | } else |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 453 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 454 | "report_manufacture - no reply\n", ioc->name)); |
| 455 | |
| 456 | issue_host_reset: |
| 457 | if (issue_reset) |
| 458 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 459 | FORCE_BIG_HAMMER); |
| 460 | out: |
| 461 | ioc->transport_cmds.status = MPT2_CMD_NOT_USED; |
| 462 | if (data_out) |
| 463 | pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma); |
| 464 | |
| 465 | mutex_unlock(&ioc->transport_cmds.mutex); |
| 466 | return rc; |
| 467 | } |
| 468 | |
Kashyap, Desai | 38c2911 | 2010-04-05 14:18:34 +0530 | [diff] [blame] | 469 | /** |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 470 | * _transport_delete_port - helper function to removing a port |
Kashyap, Desai | 38c2911 | 2010-04-05 14:18:34 +0530 | [diff] [blame] | 471 | * @ioc: per adapter object |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 472 | * @mpt2sas_port: mpt2sas per port object |
Kashyap, Desai | 38c2911 | 2010-04-05 14:18:34 +0530 | [diff] [blame] | 473 | * |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 474 | * Returns nothing. |
Kashyap, Desai | 38c2911 | 2010-04-05 14:18:34 +0530 | [diff] [blame] | 475 | */ |
| 476 | static void |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 477 | _transport_delete_port(struct MPT2SAS_ADAPTER *ioc, |
| 478 | struct _sas_port *mpt2sas_port) |
Kashyap, Desai | 38c2911 | 2010-04-05 14:18:34 +0530 | [diff] [blame] | 479 | { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 480 | u64 sas_address = mpt2sas_port->remote_identify.sas_address; |
| 481 | enum sas_device_type device_type = |
| 482 | mpt2sas_port->remote_identify.device_type; |
Kashyap, Desai | 38c2911 | 2010-04-05 14:18:34 +0530 | [diff] [blame] | 483 | |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 484 | dev_printk(KERN_INFO, &mpt2sas_port->port->dev, |
| 485 | "remove: sas_addr(0x%016llx)\n", |
| 486 | (unsigned long long) sas_address); |
Kashyap, Desai | 38c2911 | 2010-04-05 14:18:34 +0530 | [diff] [blame] | 487 | |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 488 | ioc->logging_level |= MPT_DEBUG_TRANSPORT; |
| 489 | if (device_type == SAS_END_DEVICE) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 490 | mpt2sas_device_remove_by_sas_address(ioc, sas_address); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 491 | else if (device_type == SAS_EDGE_EXPANDER_DEVICE || |
| 492 | device_type == SAS_FANOUT_EXPANDER_DEVICE) |
| 493 | mpt2sas_expander_remove(ioc, sas_address); |
| 494 | ioc->logging_level &= ~MPT_DEBUG_TRANSPORT; |
| 495 | } |
Kashyap, Desai | 38c2911 | 2010-04-05 14:18:34 +0530 | [diff] [blame] | 496 | |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 497 | /** |
| 498 | * _transport_delete_phy - helper function to removing single phy from port |
| 499 | * @ioc: per adapter object |
| 500 | * @mpt2sas_port: mpt2sas per port object |
| 501 | * @mpt2sas_phy: mpt2sas per phy object |
| 502 | * |
| 503 | * Returns nothing. |
| 504 | */ |
| 505 | static void |
| 506 | _transport_delete_phy(struct MPT2SAS_ADAPTER *ioc, |
| 507 | struct _sas_port *mpt2sas_port, struct _sas_phy *mpt2sas_phy) |
| 508 | { |
| 509 | u64 sas_address = mpt2sas_port->remote_identify.sas_address; |
| 510 | |
| 511 | dev_printk(KERN_INFO, &mpt2sas_phy->phy->dev, |
| 512 | "remove: sas_addr(0x%016llx), phy(%d)\n", |
| 513 | (unsigned long long) sas_address, mpt2sas_phy->phy_id); |
| 514 | |
| 515 | list_del(&mpt2sas_phy->port_siblings); |
| 516 | mpt2sas_port->num_phys--; |
| 517 | sas_port_delete_phy(mpt2sas_port->port, mpt2sas_phy->phy); |
| 518 | mpt2sas_phy->phy_belongs_to_port = 0; |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * _transport_add_phy - helper function to adding single phy to port |
| 523 | * @ioc: per adapter object |
| 524 | * @mpt2sas_port: mpt2sas per port object |
| 525 | * @mpt2sas_phy: mpt2sas per phy object |
| 526 | * |
| 527 | * Returns nothing. |
| 528 | */ |
| 529 | static void |
| 530 | _transport_add_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_port *mpt2sas_port, |
| 531 | struct _sas_phy *mpt2sas_phy) |
| 532 | { |
| 533 | u64 sas_address = mpt2sas_port->remote_identify.sas_address; |
| 534 | |
| 535 | dev_printk(KERN_INFO, &mpt2sas_phy->phy->dev, |
| 536 | "add: sas_addr(0x%016llx), phy(%d)\n", (unsigned long long) |
| 537 | sas_address, mpt2sas_phy->phy_id); |
| 538 | |
| 539 | list_add_tail(&mpt2sas_phy->port_siblings, &mpt2sas_port->phy_list); |
| 540 | mpt2sas_port->num_phys++; |
| 541 | sas_port_add_phy(mpt2sas_port->port, mpt2sas_phy->phy); |
| 542 | mpt2sas_phy->phy_belongs_to_port = 1; |
| 543 | } |
| 544 | |
| 545 | /** |
| 546 | * _transport_add_phy_to_an_existing_port - adding new phy to existing port |
| 547 | * @ioc: per adapter object |
| 548 | * @sas_node: sas node object (either expander or sas host) |
| 549 | * @mpt2sas_phy: mpt2sas per phy object |
| 550 | * @sas_address: sas address of device/expander were phy needs to be added to |
| 551 | * |
| 552 | * Returns nothing. |
| 553 | */ |
| 554 | static void |
| 555 | _transport_add_phy_to_an_existing_port(struct MPT2SAS_ADAPTER *ioc, |
| 556 | struct _sas_node *sas_node, struct _sas_phy *mpt2sas_phy, u64 sas_address) |
| 557 | { |
| 558 | struct _sas_port *mpt2sas_port; |
| 559 | struct _sas_phy *phy_srch; |
| 560 | |
| 561 | if (mpt2sas_phy->phy_belongs_to_port == 1) |
Kashyap, Desai | 38c2911 | 2010-04-05 14:18:34 +0530 | [diff] [blame] | 562 | return; |
| 563 | |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 564 | list_for_each_entry(mpt2sas_port, &sas_node->sas_port_list, |
| 565 | port_list) { |
| 566 | if (mpt2sas_port->remote_identify.sas_address != |
| 567 | sas_address) |
| 568 | continue; |
| 569 | list_for_each_entry(phy_srch, &mpt2sas_port->phy_list, |
| 570 | port_siblings) { |
| 571 | if (phy_srch == mpt2sas_phy) |
| 572 | return; |
| 573 | } |
| 574 | _transport_add_phy(ioc, mpt2sas_port, mpt2sas_phy); |
| 575 | return; |
| 576 | } |
| 577 | |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * _transport_del_phy_from_an_existing_port - delete phy from existing port |
| 582 | * @ioc: per adapter object |
| 583 | * @sas_node: sas node object (either expander or sas host) |
| 584 | * @mpt2sas_phy: mpt2sas per phy object |
| 585 | * |
| 586 | * Returns nothing. |
| 587 | */ |
| 588 | static void |
| 589 | _transport_del_phy_from_an_existing_port(struct MPT2SAS_ADAPTER *ioc, |
| 590 | struct _sas_node *sas_node, struct _sas_phy *mpt2sas_phy) |
| 591 | { |
| 592 | struct _sas_port *mpt2sas_port, *next; |
| 593 | struct _sas_phy *phy_srch; |
| 594 | |
| 595 | if (mpt2sas_phy->phy_belongs_to_port == 0) |
| 596 | return; |
| 597 | |
| 598 | list_for_each_entry_safe(mpt2sas_port, next, &sas_node->sas_port_list, |
| 599 | port_list) { |
| 600 | list_for_each_entry(phy_srch, &mpt2sas_port->phy_list, |
| 601 | port_siblings) { |
| 602 | if (phy_srch != mpt2sas_phy) |
| 603 | continue; |
| 604 | if (mpt2sas_port->num_phys == 1) |
| 605 | _transport_delete_port(ioc, mpt2sas_port); |
| 606 | else |
| 607 | _transport_delete_phy(ioc, mpt2sas_port, |
| 608 | mpt2sas_phy); |
| 609 | return; |
| 610 | } |
| 611 | } |
Kashyap, Desai | 38c2911 | 2010-04-05 14:18:34 +0530 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | /** |
| 615 | * _transport_sanity_check - sanity check when adding a new port |
| 616 | * @ioc: per adapter object |
| 617 | * @sas_node: sas node object (either expander or sas host) |
| 618 | * @sas_address: sas address of device being added |
| 619 | * |
| 620 | * See the explanation above from _transport_delete_duplicate_port |
| 621 | */ |
| 622 | static void |
| 623 | _transport_sanity_check(struct MPT2SAS_ADAPTER *ioc, struct _sas_node *sas_node, |
| 624 | u64 sas_address) |
| 625 | { |
| 626 | int i; |
| 627 | |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 628 | for (i = 0; i < sas_node->num_phys; i++) { |
| 629 | if (sas_node->phy[i].remote_identify.sas_address != sas_address) |
| 630 | continue; |
| 631 | if (sas_node->phy[i].phy_belongs_to_port == 1) |
| 632 | _transport_del_phy_from_an_existing_port(ioc, sas_node, |
| 633 | &sas_node->phy[i]); |
| 634 | } |
Kashyap, Desai | 38c2911 | 2010-04-05 14:18:34 +0530 | [diff] [blame] | 635 | } |
| 636 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 637 | /** |
| 638 | * mpt2sas_transport_port_add - insert port to the list |
| 639 | * @ioc: per adapter object |
| 640 | * @handle: handle of attached device |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 641 | * @sas_address: sas address of parent expander or sas host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 642 | * Context: This function will acquire ioc->sas_node_lock. |
| 643 | * |
| 644 | * Adding new port object to the sas_node->sas_port_list. |
| 645 | * |
| 646 | * Returns mpt2sas_port. |
| 647 | */ |
| 648 | struct _sas_port * |
| 649 | mpt2sas_transport_port_add(struct MPT2SAS_ADAPTER *ioc, u16 handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 650 | u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 651 | { |
| 652 | struct _sas_phy *mpt2sas_phy, *next; |
| 653 | struct _sas_port *mpt2sas_port; |
| 654 | unsigned long flags; |
| 655 | struct _sas_node *sas_node; |
| 656 | struct sas_rphy *rphy; |
| 657 | int i; |
| 658 | struct sas_port *port; |
| 659 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 660 | mpt2sas_port = kzalloc(sizeof(struct _sas_port), |
| 661 | GFP_KERNEL); |
| 662 | if (!mpt2sas_port) { |
| 663 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 664 | ioc->name, __FILE__, __LINE__, __func__); |
| 665 | return NULL; |
| 666 | } |
| 667 | |
| 668 | INIT_LIST_HEAD(&mpt2sas_port->port_list); |
| 669 | INIT_LIST_HEAD(&mpt2sas_port->phy_list); |
| 670 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 671 | sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 672 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 673 | |
| 674 | if (!sas_node) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 675 | printk(MPT2SAS_ERR_FMT "%s: Could not find " |
| 676 | "parent sas_address(0x%016llx)!\n", ioc->name, |
| 677 | __func__, (unsigned long long)sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 678 | goto out_fail; |
| 679 | } |
| 680 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 681 | if ((_transport_set_identify(ioc, handle, |
| 682 | &mpt2sas_port->remote_identify))) { |
| 683 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 684 | ioc->name, __FILE__, __LINE__, __func__); |
| 685 | goto out_fail; |
| 686 | } |
| 687 | |
| 688 | if (mpt2sas_port->remote_identify.device_type == SAS_PHY_UNUSED) { |
| 689 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 690 | ioc->name, __FILE__, __LINE__, __func__); |
| 691 | goto out_fail; |
| 692 | } |
| 693 | |
Kashyap, Desai | 38c2911 | 2010-04-05 14:18:34 +0530 | [diff] [blame] | 694 | _transport_sanity_check(ioc, sas_node, |
| 695 | mpt2sas_port->remote_identify.sas_address); |
| 696 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 697 | for (i = 0; i < sas_node->num_phys; i++) { |
| 698 | if (sas_node->phy[i].remote_identify.sas_address != |
| 699 | mpt2sas_port->remote_identify.sas_address) |
| 700 | continue; |
| 701 | list_add_tail(&sas_node->phy[i].port_siblings, |
| 702 | &mpt2sas_port->phy_list); |
| 703 | mpt2sas_port->num_phys++; |
| 704 | } |
| 705 | |
| 706 | if (!mpt2sas_port->num_phys) { |
| 707 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 708 | ioc->name, __FILE__, __LINE__, __func__); |
| 709 | goto out_fail; |
| 710 | } |
| 711 | |
| 712 | port = sas_port_alloc_num(sas_node->parent_dev); |
| 713 | if ((sas_port_add(port))) { |
| 714 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 715 | ioc->name, __FILE__, __LINE__, __func__); |
| 716 | goto out_fail; |
| 717 | } |
| 718 | |
| 719 | list_for_each_entry(mpt2sas_phy, &mpt2sas_port->phy_list, |
| 720 | port_siblings) { |
| 721 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) |
| 722 | dev_printk(KERN_INFO, &port->dev, "add: handle(0x%04x)" |
| 723 | ", sas_addr(0x%016llx), phy(%d)\n", handle, |
| 724 | (unsigned long long) |
| 725 | mpt2sas_port->remote_identify.sas_address, |
| 726 | mpt2sas_phy->phy_id); |
| 727 | sas_port_add_phy(port, mpt2sas_phy->phy); |
Kashyap, Desai | 38c2911 | 2010-04-05 14:18:34 +0530 | [diff] [blame] | 728 | mpt2sas_phy->phy_belongs_to_port = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | mpt2sas_port->port = port; |
| 732 | if (mpt2sas_port->remote_identify.device_type == SAS_END_DEVICE) |
| 733 | rphy = sas_end_device_alloc(port); |
| 734 | else |
| 735 | rphy = sas_expander_alloc(port, |
| 736 | mpt2sas_port->remote_identify.device_type); |
| 737 | |
| 738 | rphy->identify = mpt2sas_port->remote_identify; |
| 739 | if ((sas_rphy_add(rphy))) { |
| 740 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 741 | ioc->name, __FILE__, __LINE__, __func__); |
| 742 | } |
| 743 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) |
| 744 | dev_printk(KERN_INFO, &rphy->dev, "add: handle(0x%04x), " |
| 745 | "sas_addr(0x%016llx)\n", handle, |
| 746 | (unsigned long long) |
| 747 | mpt2sas_port->remote_identify.sas_address); |
| 748 | mpt2sas_port->rphy = rphy; |
| 749 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 750 | list_add_tail(&mpt2sas_port->port_list, &sas_node->sas_port_list); |
| 751 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 752 | |
| 753 | /* fill in report manufacture */ |
| 754 | if (mpt2sas_port->remote_identify.device_type == |
| 755 | MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER || |
| 756 | mpt2sas_port->remote_identify.device_type == |
| 757 | MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 758 | _transport_expander_report_manufacture(ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 759 | mpt2sas_port->remote_identify.sas_address, |
| 760 | rphy_to_expander_device(rphy)); |
| 761 | |
| 762 | return mpt2sas_port; |
| 763 | |
| 764 | out_fail: |
| 765 | list_for_each_entry_safe(mpt2sas_phy, next, &mpt2sas_port->phy_list, |
| 766 | port_siblings) |
| 767 | list_del(&mpt2sas_phy->port_siblings); |
| 768 | kfree(mpt2sas_port); |
| 769 | return NULL; |
| 770 | } |
| 771 | |
| 772 | /** |
| 773 | * mpt2sas_transport_port_remove - remove port from the list |
| 774 | * @ioc: per adapter object |
| 775 | * @sas_address: sas address of attached device |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 776 | * @sas_address_parent: sas address of parent expander or sas host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 777 | * Context: This function will acquire ioc->sas_node_lock. |
| 778 | * |
| 779 | * Removing object and freeing associated memory from the |
| 780 | * ioc->sas_port_list. |
| 781 | * |
| 782 | * Return nothing. |
| 783 | */ |
| 784 | void |
| 785 | mpt2sas_transport_port_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 786 | u64 sas_address_parent) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 787 | { |
| 788 | int i; |
| 789 | unsigned long flags; |
| 790 | struct _sas_port *mpt2sas_port, *next; |
| 791 | struct _sas_node *sas_node; |
| 792 | u8 found = 0; |
| 793 | struct _sas_phy *mpt2sas_phy, *next_phy; |
| 794 | |
| 795 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 796 | sas_node = _transport_sas_node_find_by_sas_address(ioc, |
| 797 | sas_address_parent); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 798 | if (!sas_node) { |
| 799 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 800 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 801 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 802 | list_for_each_entry_safe(mpt2sas_port, next, &sas_node->sas_port_list, |
| 803 | port_list) { |
| 804 | if (mpt2sas_port->remote_identify.sas_address != sas_address) |
| 805 | continue; |
| 806 | found = 1; |
| 807 | list_del(&mpt2sas_port->port_list); |
| 808 | goto out; |
| 809 | } |
| 810 | out: |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 811 | if (!found) { |
| 812 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 813 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 814 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 815 | |
| 816 | for (i = 0; i < sas_node->num_phys; i++) { |
| 817 | if (sas_node->phy[i].remote_identify.sas_address == sas_address) |
| 818 | memset(&sas_node->phy[i].remote_identify, 0 , |
| 819 | sizeof(struct sas_identify)); |
| 820 | } |
| 821 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 822 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 823 | list_for_each_entry_safe(mpt2sas_phy, next_phy, |
| 824 | &mpt2sas_port->phy_list, port_siblings) { |
| 825 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) |
| 826 | dev_printk(KERN_INFO, &mpt2sas_port->port->dev, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 827 | "remove: sas_addr(0x%016llx), phy(%d)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 828 | (unsigned long long) |
| 829 | mpt2sas_port->remote_identify.sas_address, |
| 830 | mpt2sas_phy->phy_id); |
Kashyap, Desai | 38c2911 | 2010-04-05 14:18:34 +0530 | [diff] [blame] | 831 | mpt2sas_phy->phy_belongs_to_port = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 832 | sas_port_delete_phy(mpt2sas_port->port, mpt2sas_phy->phy); |
| 833 | list_del(&mpt2sas_phy->port_siblings); |
| 834 | } |
| 835 | sas_port_delete(mpt2sas_port->port); |
| 836 | kfree(mpt2sas_port); |
| 837 | } |
| 838 | |
| 839 | /** |
| 840 | * mpt2sas_transport_add_host_phy - report sas_host phy to transport |
| 841 | * @ioc: per adapter object |
| 842 | * @mpt2sas_phy: mpt2sas per phy object |
| 843 | * @phy_pg0: sas phy page 0 |
| 844 | * @parent_dev: parent device class object |
| 845 | * |
| 846 | * Returns 0 for success, non-zero for failure. |
| 847 | */ |
| 848 | int |
| 849 | mpt2sas_transport_add_host_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy |
| 850 | *mpt2sas_phy, Mpi2SasPhyPage0_t phy_pg0, struct device *parent_dev) |
| 851 | { |
| 852 | struct sas_phy *phy; |
| 853 | int phy_index = mpt2sas_phy->phy_id; |
| 854 | |
| 855 | |
| 856 | INIT_LIST_HEAD(&mpt2sas_phy->port_siblings); |
| 857 | phy = sas_phy_alloc(parent_dev, phy_index); |
| 858 | if (!phy) { |
| 859 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 860 | ioc->name, __FILE__, __LINE__, __func__); |
| 861 | return -1; |
| 862 | } |
| 863 | if ((_transport_set_identify(ioc, mpt2sas_phy->handle, |
| 864 | &mpt2sas_phy->identify))) { |
| 865 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 866 | ioc->name, __FILE__, __LINE__, __func__); |
| 867 | return -1; |
| 868 | } |
| 869 | phy->identify = mpt2sas_phy->identify; |
| 870 | mpt2sas_phy->attached_handle = le16_to_cpu(phy_pg0.AttachedDevHandle); |
| 871 | if (mpt2sas_phy->attached_handle) |
| 872 | _transport_set_identify(ioc, mpt2sas_phy->attached_handle, |
| 873 | &mpt2sas_phy->remote_identify); |
| 874 | phy->identify.phy_identifier = mpt2sas_phy->phy_id; |
| 875 | phy->negotiated_linkrate = _transport_convert_phy_link_rate( |
| 876 | phy_pg0.NegotiatedLinkRate & MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL); |
| 877 | phy->minimum_linkrate_hw = _transport_convert_phy_link_rate( |
| 878 | phy_pg0.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK); |
| 879 | phy->maximum_linkrate_hw = _transport_convert_phy_link_rate( |
| 880 | phy_pg0.HwLinkRate >> 4); |
| 881 | phy->minimum_linkrate = _transport_convert_phy_link_rate( |
| 882 | phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK); |
| 883 | phy->maximum_linkrate = _transport_convert_phy_link_rate( |
| 884 | phy_pg0.ProgrammedLinkRate >> 4); |
| 885 | |
| 886 | if ((sas_phy_add(phy))) { |
| 887 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 888 | ioc->name, __FILE__, __LINE__, __func__); |
| 889 | sas_phy_free(phy); |
| 890 | return -1; |
| 891 | } |
| 892 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) |
| 893 | dev_printk(KERN_INFO, &phy->dev, |
| 894 | "add: handle(0x%04x), sas_addr(0x%016llx)\n" |
| 895 | "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n", |
| 896 | mpt2sas_phy->handle, (unsigned long long) |
| 897 | mpt2sas_phy->identify.sas_address, |
| 898 | mpt2sas_phy->attached_handle, |
| 899 | (unsigned long long) |
| 900 | mpt2sas_phy->remote_identify.sas_address); |
| 901 | mpt2sas_phy->phy = phy; |
| 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | |
| 906 | /** |
| 907 | * mpt2sas_transport_add_expander_phy - report expander phy to transport |
| 908 | * @ioc: per adapter object |
| 909 | * @mpt2sas_phy: mpt2sas per phy object |
| 910 | * @expander_pg1: expander page 1 |
| 911 | * @parent_dev: parent device class object |
| 912 | * |
| 913 | * Returns 0 for success, non-zero for failure. |
| 914 | */ |
| 915 | int |
| 916 | mpt2sas_transport_add_expander_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy |
| 917 | *mpt2sas_phy, Mpi2ExpanderPage1_t expander_pg1, struct device *parent_dev) |
| 918 | { |
| 919 | struct sas_phy *phy; |
| 920 | int phy_index = mpt2sas_phy->phy_id; |
| 921 | |
| 922 | INIT_LIST_HEAD(&mpt2sas_phy->port_siblings); |
| 923 | phy = sas_phy_alloc(parent_dev, phy_index); |
| 924 | if (!phy) { |
| 925 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 926 | ioc->name, __FILE__, __LINE__, __func__); |
| 927 | return -1; |
| 928 | } |
| 929 | if ((_transport_set_identify(ioc, mpt2sas_phy->handle, |
| 930 | &mpt2sas_phy->identify))) { |
| 931 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 932 | ioc->name, __FILE__, __LINE__, __func__); |
| 933 | return -1; |
| 934 | } |
| 935 | phy->identify = mpt2sas_phy->identify; |
| 936 | mpt2sas_phy->attached_handle = |
| 937 | le16_to_cpu(expander_pg1.AttachedDevHandle); |
| 938 | if (mpt2sas_phy->attached_handle) |
| 939 | _transport_set_identify(ioc, mpt2sas_phy->attached_handle, |
| 940 | &mpt2sas_phy->remote_identify); |
| 941 | phy->identify.phy_identifier = mpt2sas_phy->phy_id; |
| 942 | phy->negotiated_linkrate = _transport_convert_phy_link_rate( |
| 943 | expander_pg1.NegotiatedLinkRate & |
| 944 | MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL); |
| 945 | phy->minimum_linkrate_hw = _transport_convert_phy_link_rate( |
| 946 | expander_pg1.HwLinkRate & MPI2_SAS_HWRATE_MIN_RATE_MASK); |
| 947 | phy->maximum_linkrate_hw = _transport_convert_phy_link_rate( |
| 948 | expander_pg1.HwLinkRate >> 4); |
| 949 | phy->minimum_linkrate = _transport_convert_phy_link_rate( |
| 950 | expander_pg1.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK); |
| 951 | phy->maximum_linkrate = _transport_convert_phy_link_rate( |
| 952 | expander_pg1.ProgrammedLinkRate >> 4); |
| 953 | |
| 954 | if ((sas_phy_add(phy))) { |
| 955 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 956 | ioc->name, __FILE__, __LINE__, __func__); |
| 957 | sas_phy_free(phy); |
| 958 | return -1; |
| 959 | } |
| 960 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) |
| 961 | dev_printk(KERN_INFO, &phy->dev, |
| 962 | "add: handle(0x%04x), sas_addr(0x%016llx)\n" |
| 963 | "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n", |
| 964 | mpt2sas_phy->handle, (unsigned long long) |
| 965 | mpt2sas_phy->identify.sas_address, |
| 966 | mpt2sas_phy->attached_handle, |
| 967 | (unsigned long long) |
| 968 | mpt2sas_phy->remote_identify.sas_address); |
| 969 | mpt2sas_phy->phy = phy; |
| 970 | return 0; |
| 971 | } |
| 972 | |
| 973 | /** |
Kashyap, Desai | cc0f520 | 2009-08-20 13:22:39 +0530 | [diff] [blame] | 974 | * mpt2sas_transport_update_links - refreshing phy link changes |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 975 | * @ioc: per adapter object |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 976 | * @sas_address: sas address of parent expander or sas host |
| 977 | * @handle: attached device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 978 | * @phy_numberv: phy number |
| 979 | * @link_rate: new link rate |
| 980 | * |
| 981 | * Returns nothing. |
| 982 | */ |
| 983 | void |
Kashyap, Desai | cc0f520 | 2009-08-20 13:22:39 +0530 | [diff] [blame] | 984 | mpt2sas_transport_update_links(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 985 | u64 sas_address, u16 handle, u8 phy_number, u8 link_rate) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 986 | { |
| 987 | unsigned long flags; |
| 988 | struct _sas_node *sas_node; |
| 989 | struct _sas_phy *mpt2sas_phy; |
| 990 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 991 | if (ioc->shost_recovery || ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 992 | return; |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 993 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 994 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 995 | sas_node = _transport_sas_node_find_by_sas_address(ioc, sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 996 | if (!sas_node) { |
| 997 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 998 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 999 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1000 | |
| 1001 | mpt2sas_phy = &sas_node->phy[phy_number]; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 1002 | mpt2sas_phy->attached_handle = handle; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1003 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 1004 | if (handle && (link_rate >= MPI2_SAS_NEG_LINK_RATE_1_5)) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 1005 | _transport_set_identify(ioc, handle, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1006 | &mpt2sas_phy->remote_identify); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 1007 | _transport_add_phy_to_an_existing_port(ioc, sas_node, |
| 1008 | mpt2sas_phy, mpt2sas_phy->remote_identify.sas_address); |
Jan Vesely | 3520f9c | 2013-08-01 12:01:30 +0200 | [diff] [blame] | 1009 | } else { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1010 | memset(&mpt2sas_phy->remote_identify, 0 , sizeof(struct |
| 1011 | sas_identify)); |
Jan Vesely | 3520f9c | 2013-08-01 12:01:30 +0200 | [diff] [blame] | 1012 | _transport_del_phy_from_an_existing_port(ioc, sas_node, |
| 1013 | mpt2sas_phy); |
| 1014 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1015 | |
| 1016 | if (mpt2sas_phy->phy) |
| 1017 | mpt2sas_phy->phy->negotiated_linkrate = |
| 1018 | _transport_convert_phy_link_rate(link_rate); |
| 1019 | |
| 1020 | if ((ioc->logging_level & MPT_DEBUG_TRANSPORT)) |
| 1021 | dev_printk(KERN_INFO, &mpt2sas_phy->phy->dev, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 1022 | "refresh: parent sas_addr(0x%016llx),\n" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1023 | "\tlink_rate(0x%02x), phy(%d)\n" |
| 1024 | "\tattached_handle(0x%04x), sas_addr(0x%016llx)\n", |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 1025 | (unsigned long long)sas_address, |
| 1026 | link_rate, phy_number, handle, (unsigned long long) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1027 | mpt2sas_phy->remote_identify.sas_address); |
| 1028 | } |
| 1029 | |
| 1030 | static inline void * |
| 1031 | phy_to_ioc(struct sas_phy *phy) |
| 1032 | { |
| 1033 | struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); |
| 1034 | return shost_priv(shost); |
| 1035 | } |
| 1036 | |
| 1037 | static inline void * |
| 1038 | rphy_to_ioc(struct sas_rphy *rphy) |
| 1039 | { |
| 1040 | struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent); |
| 1041 | return shost_priv(shost); |
| 1042 | } |
| 1043 | |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1044 | |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1045 | /* report phy error log structure */ |
| 1046 | struct phy_error_log_request{ |
| 1047 | u8 smp_frame_type; /* 0x40 */ |
| 1048 | u8 function; /* 0x11 */ |
| 1049 | u8 allocated_response_length; |
| 1050 | u8 request_length; /* 02 */ |
| 1051 | u8 reserved_1[5]; |
| 1052 | u8 phy_identifier; |
| 1053 | u8 reserved_2[2]; |
| 1054 | }; |
| 1055 | |
| 1056 | /* report phy error log reply structure */ |
| 1057 | struct phy_error_log_reply{ |
| 1058 | u8 smp_frame_type; /* 0x41 */ |
| 1059 | u8 function; /* 0x11 */ |
| 1060 | u8 function_result; |
| 1061 | u8 response_length; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 1062 | __be16 expander_change_count; |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1063 | u8 reserved_1[3]; |
| 1064 | u8 phy_identifier; |
| 1065 | u8 reserved_2[2]; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 1066 | __be32 invalid_dword; |
| 1067 | __be32 running_disparity_error; |
| 1068 | __be32 loss_of_dword_sync; |
| 1069 | __be32 phy_reset_problem; |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1070 | }; |
| 1071 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1072 | /** |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1073 | * _transport_get_expander_phy_error_log - return expander counters |
| 1074 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1075 | * @phy: The sas phy object |
| 1076 | * |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1077 | * Returns 0 for success, non-zero for failure. |
| 1078 | * |
| 1079 | */ |
| 1080 | static int |
| 1081 | _transport_get_expander_phy_error_log(struct MPT2SAS_ADAPTER *ioc, |
| 1082 | struct sas_phy *phy) |
| 1083 | { |
| 1084 | Mpi2SmpPassthroughRequest_t *mpi_request; |
| 1085 | Mpi2SmpPassthroughReply_t *mpi_reply; |
| 1086 | struct phy_error_log_request *phy_error_log_request; |
| 1087 | struct phy_error_log_reply *phy_error_log_reply; |
| 1088 | int rc; |
| 1089 | u16 smid; |
| 1090 | u32 ioc_state; |
| 1091 | unsigned long timeleft; |
| 1092 | void *psge; |
| 1093 | u32 sgl_flags; |
| 1094 | u8 issue_reset = 0; |
| 1095 | void *data_out = NULL; |
| 1096 | dma_addr_t data_out_dma; |
| 1097 | u32 sz; |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1098 | u16 wait_state_count; |
| 1099 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 1100 | if (ioc->shost_recovery || ioc->pci_error_recovery) { |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1101 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 1102 | __func__, ioc->name); |
| 1103 | return -EFAULT; |
| 1104 | } |
| 1105 | |
| 1106 | mutex_lock(&ioc->transport_cmds.mutex); |
| 1107 | |
| 1108 | if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) { |
| 1109 | printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n", |
| 1110 | ioc->name, __func__); |
| 1111 | rc = -EAGAIN; |
| 1112 | goto out; |
| 1113 | } |
| 1114 | ioc->transport_cmds.status = MPT2_CMD_PENDING; |
| 1115 | |
| 1116 | wait_state_count = 0; |
| 1117 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 1118 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 1119 | if (wait_state_count++ == 10) { |
| 1120 | printk(MPT2SAS_ERR_FMT |
| 1121 | "%s: failed due to ioc not operational\n", |
| 1122 | ioc->name, __func__); |
| 1123 | rc = -EFAULT; |
| 1124 | goto out; |
| 1125 | } |
| 1126 | ssleep(1); |
| 1127 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 1128 | printk(MPT2SAS_INFO_FMT "%s: waiting for " |
| 1129 | "operational state(count=%d)\n", ioc->name, |
| 1130 | __func__, wait_state_count); |
| 1131 | } |
| 1132 | if (wait_state_count) |
| 1133 | printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n", |
| 1134 | ioc->name, __func__); |
| 1135 | |
| 1136 | smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx); |
| 1137 | if (!smid) { |
| 1138 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 1139 | ioc->name, __func__); |
| 1140 | rc = -EAGAIN; |
| 1141 | goto out; |
| 1142 | } |
| 1143 | |
| 1144 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 1145 | ioc->transport_cmds.smid = smid; |
| 1146 | |
| 1147 | sz = sizeof(struct phy_error_log_request) + |
| 1148 | sizeof(struct phy_error_log_reply); |
| 1149 | data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma); |
| 1150 | if (!data_out) { |
| 1151 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, |
| 1152 | __LINE__, __func__); |
| 1153 | rc = -ENOMEM; |
| 1154 | mpt2sas_base_free_smid(ioc, smid); |
| 1155 | goto out; |
| 1156 | } |
| 1157 | |
| 1158 | rc = -EINVAL; |
| 1159 | memset(data_out, 0, sz); |
| 1160 | phy_error_log_request = data_out; |
| 1161 | phy_error_log_request->smp_frame_type = 0x40; |
| 1162 | phy_error_log_request->function = 0x11; |
| 1163 | phy_error_log_request->request_length = 2; |
| 1164 | phy_error_log_request->allocated_response_length = 0; |
| 1165 | phy_error_log_request->phy_identifier = phy->number; |
| 1166 | |
| 1167 | memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t)); |
| 1168 | mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH; |
| 1169 | mpi_request->PhysicalPort = 0xFF; |
| 1170 | mpi_request->VF_ID = 0; /* TODO */ |
| 1171 | mpi_request->VP_ID = 0; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 1172 | mpi_request->SASAddress = cpu_to_le64(phy->identify.sas_address); |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1173 | mpi_request->RequestDataLength = |
| 1174 | cpu_to_le16(sizeof(struct phy_error_log_request)); |
| 1175 | psge = &mpi_request->SGL; |
| 1176 | |
| 1177 | /* WRITE sgel first */ |
| 1178 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1179 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); |
| 1180 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1181 | ioc->base_add_sg_single(psge, sgl_flags | |
| 1182 | sizeof(struct phy_error_log_request), data_out_dma); |
| 1183 | |
| 1184 | /* incr sgel */ |
| 1185 | psge += ioc->sge_size; |
| 1186 | |
| 1187 | /* READ sgel last */ |
| 1188 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1189 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 1190 | MPI2_SGE_FLAGS_END_OF_LIST); |
| 1191 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1192 | ioc->base_add_sg_single(psge, sgl_flags | |
| 1193 | sizeof(struct phy_error_log_reply), data_out_dma + |
| 1194 | sizeof(struct phy_error_log_request)); |
| 1195 | |
| 1196 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_error_log - " |
| 1197 | "send to sas_addr(0x%016llx), phy(%d)\n", ioc->name, |
| 1198 | (unsigned long long)phy->identify.sas_address, phy->number)); |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1199 | init_completion(&ioc->transport_cmds.done); |
nagalakshmi.nandigama@lsi.com | f01690d | 2011-12-01 07:43:58 +0530 | [diff] [blame] | 1200 | mpt2sas_base_put_smid_default(ioc, smid); |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1201 | timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done, |
| 1202 | 10*HZ); |
| 1203 | |
| 1204 | if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) { |
| 1205 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 1206 | ioc->name, __func__); |
| 1207 | _debug_dump_mf(mpi_request, |
| 1208 | sizeof(Mpi2SmpPassthroughRequest_t)/4); |
| 1209 | if (!(ioc->transport_cmds.status & MPT2_CMD_RESET)) |
| 1210 | issue_reset = 1; |
| 1211 | goto issue_host_reset; |
| 1212 | } |
| 1213 | |
| 1214 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_error_log - " |
| 1215 | "complete\n", ioc->name)); |
| 1216 | |
| 1217 | if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 1218 | |
| 1219 | mpi_reply = ioc->transport_cmds.reply; |
| 1220 | |
| 1221 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 1222 | "phy_error_log - reply data transfer size(%d)\n", |
| 1223 | ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength))); |
| 1224 | |
| 1225 | if (le16_to_cpu(mpi_reply->ResponseDataLength) != |
| 1226 | sizeof(struct phy_error_log_reply)) |
| 1227 | goto out; |
| 1228 | |
| 1229 | phy_error_log_reply = data_out + |
| 1230 | sizeof(struct phy_error_log_request); |
| 1231 | |
| 1232 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 1233 | "phy_error_log - function_result(%d)\n", |
| 1234 | ioc->name, phy_error_log_reply->function_result)); |
| 1235 | |
| 1236 | phy->invalid_dword_count = |
| 1237 | be32_to_cpu(phy_error_log_reply->invalid_dword); |
| 1238 | phy->running_disparity_error_count = |
| 1239 | be32_to_cpu(phy_error_log_reply->running_disparity_error); |
| 1240 | phy->loss_of_dword_sync_count = |
| 1241 | be32_to_cpu(phy_error_log_reply->loss_of_dword_sync); |
| 1242 | phy->phy_reset_problem_count = |
| 1243 | be32_to_cpu(phy_error_log_reply->phy_reset_problem); |
| 1244 | rc = 0; |
| 1245 | } else |
| 1246 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 1247 | "phy_error_log - no reply\n", ioc->name)); |
| 1248 | |
| 1249 | issue_host_reset: |
| 1250 | if (issue_reset) |
| 1251 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 1252 | FORCE_BIG_HAMMER); |
| 1253 | out: |
| 1254 | ioc->transport_cmds.status = MPT2_CMD_NOT_USED; |
| 1255 | if (data_out) |
| 1256 | pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma); |
| 1257 | |
| 1258 | mutex_unlock(&ioc->transport_cmds.mutex); |
| 1259 | return rc; |
| 1260 | } |
| 1261 | |
| 1262 | /** |
| 1263 | * _transport_get_linkerrors - return phy counters for both hba and expanders |
| 1264 | * @phy: The sas phy object |
| 1265 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1266 | * Returns 0 for success, non-zero for failure. |
| 1267 | * |
| 1268 | */ |
| 1269 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1270 | _transport_get_linkerrors(struct sas_phy *phy) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1271 | { |
| 1272 | struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy); |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1273 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1274 | Mpi2ConfigReply_t mpi_reply; |
| 1275 | Mpi2SasPhyPage1_t phy_pg1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1276 | |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1277 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 1278 | if (_transport_sas_node_find_by_sas_address(ioc, |
| 1279 | phy->identify.sas_address) == NULL) { |
| 1280 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1281 | return -EINVAL; |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1282 | } |
| 1283 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1284 | |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1285 | if (phy->identify.sas_address != ioc->sas_hba.sas_address) |
| 1286 | return _transport_get_expander_phy_error_log(ioc, phy); |
| 1287 | |
| 1288 | /* get hba phy error logs */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1289 | if ((mpt2sas_config_get_phy_pg1(ioc, &mpi_reply, &phy_pg1, |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1290 | phy->number))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1291 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1292 | ioc->name, __FILE__, __LINE__, __func__); |
| 1293 | return -ENXIO; |
| 1294 | } |
| 1295 | |
| 1296 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) |
| 1297 | printk(MPT2SAS_INFO_FMT "phy(%d), ioc_status" |
| 1298 | "(0x%04x), loginfo(0x%08x)\n", ioc->name, |
Kashyap, Desai | d5f491e | 2010-06-17 13:32:54 +0530 | [diff] [blame] | 1299 | phy->number, le16_to_cpu(mpi_reply.IOCStatus), |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1300 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 1301 | |
| 1302 | phy->invalid_dword_count = le32_to_cpu(phy_pg1.InvalidDwordCount); |
| 1303 | phy->running_disparity_error_count = |
| 1304 | le32_to_cpu(phy_pg1.RunningDisparityErrorCount); |
| 1305 | phy->loss_of_dword_sync_count = |
| 1306 | le32_to_cpu(phy_pg1.LossDwordSynchCount); |
| 1307 | phy->phy_reset_problem_count = |
| 1308 | le32_to_cpu(phy_pg1.PhyResetProblemCount); |
| 1309 | return 0; |
| 1310 | } |
| 1311 | |
| 1312 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1313 | * _transport_get_enclosure_identifier - |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1314 | * @phy: The sas phy object |
| 1315 | * |
| 1316 | * Obtain the enclosure logical id for an expander. |
| 1317 | * Returns 0 for success, non-zero for failure. |
| 1318 | */ |
| 1319 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1320 | _transport_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1321 | { |
| 1322 | struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy); |
Kashyap, Desai | ab6ce92 | 2010-06-17 13:25:13 +0530 | [diff] [blame] | 1323 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1324 | unsigned long flags; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1325 | int rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1326 | |
Kashyap, Desai | ab6ce92 | 2010-06-17 13:25:13 +0530 | [diff] [blame] | 1327 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1328 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1329 | rphy->identify.sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1330 | if (sas_device) { |
| 1331 | *identifier = sas_device->enclosure_logical_id; |
| 1332 | rc = 0; |
| 1333 | } else { |
| 1334 | *identifier = 0; |
| 1335 | rc = -ENXIO; |
| 1336 | } |
Kashyap, Desai | ab6ce92 | 2010-06-17 13:25:13 +0530 | [diff] [blame] | 1337 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1338 | return rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1342 | * _transport_get_bay_identifier - |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1343 | * @phy: The sas phy object |
| 1344 | * |
| 1345 | * Returns the slot id for a device that resides inside an enclosure. |
| 1346 | */ |
| 1347 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1348 | _transport_get_bay_identifier(struct sas_rphy *rphy) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1349 | { |
| 1350 | struct MPT2SAS_ADAPTER *ioc = rphy_to_ioc(rphy); |
| 1351 | struct _sas_device *sas_device; |
| 1352 | unsigned long flags; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1353 | int rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1354 | |
| 1355 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1356 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1357 | rphy->identify.sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1358 | if (sas_device) |
| 1359 | rc = sas_device->slot; |
| 1360 | else |
| 1361 | rc = -ENXIO; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1362 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1363 | return rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1364 | } |
| 1365 | |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1366 | /* phy control request structure */ |
| 1367 | struct phy_control_request{ |
| 1368 | u8 smp_frame_type; /* 0x40 */ |
| 1369 | u8 function; /* 0x91 */ |
| 1370 | u8 allocated_response_length; |
| 1371 | u8 request_length; /* 0x09 */ |
| 1372 | u16 expander_change_count; |
| 1373 | u8 reserved_1[3]; |
| 1374 | u8 phy_identifier; |
| 1375 | u8 phy_operation; |
| 1376 | u8 reserved_2[13]; |
| 1377 | u64 attached_device_name; |
| 1378 | u8 programmed_min_physical_link_rate; |
| 1379 | u8 programmed_max_physical_link_rate; |
| 1380 | u8 reserved_3[6]; |
| 1381 | }; |
| 1382 | |
| 1383 | /* phy control reply structure */ |
| 1384 | struct phy_control_reply{ |
| 1385 | u8 smp_frame_type; /* 0x41 */ |
| 1386 | u8 function; /* 0x11 */ |
| 1387 | u8 function_result; |
| 1388 | u8 response_length; |
| 1389 | }; |
| 1390 | |
| 1391 | #define SMP_PHY_CONTROL_LINK_RESET (0x01) |
| 1392 | #define SMP_PHY_CONTROL_HARD_RESET (0x02) |
| 1393 | #define SMP_PHY_CONTROL_DISABLE (0x03) |
| 1394 | |
| 1395 | /** |
| 1396 | * _transport_expander_phy_control - expander phy control |
| 1397 | * @ioc: per adapter object |
| 1398 | * @phy: The sas phy object |
| 1399 | * |
| 1400 | * Returns 0 for success, non-zero for failure. |
| 1401 | * |
| 1402 | */ |
| 1403 | static int |
| 1404 | _transport_expander_phy_control(struct MPT2SAS_ADAPTER *ioc, |
| 1405 | struct sas_phy *phy, u8 phy_operation) |
| 1406 | { |
| 1407 | Mpi2SmpPassthroughRequest_t *mpi_request; |
| 1408 | Mpi2SmpPassthroughReply_t *mpi_reply; |
| 1409 | struct phy_control_request *phy_control_request; |
| 1410 | struct phy_control_reply *phy_control_reply; |
| 1411 | int rc; |
| 1412 | u16 smid; |
| 1413 | u32 ioc_state; |
| 1414 | unsigned long timeleft; |
| 1415 | void *psge; |
| 1416 | u32 sgl_flags; |
| 1417 | u8 issue_reset = 0; |
| 1418 | void *data_out = NULL; |
| 1419 | dma_addr_t data_out_dma; |
| 1420 | u32 sz; |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1421 | u16 wait_state_count; |
| 1422 | |
| 1423 | if (ioc->shost_recovery) { |
| 1424 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 1425 | __func__, ioc->name); |
| 1426 | return -EFAULT; |
| 1427 | } |
| 1428 | |
| 1429 | mutex_lock(&ioc->transport_cmds.mutex); |
| 1430 | |
| 1431 | if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) { |
| 1432 | printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n", |
| 1433 | ioc->name, __func__); |
| 1434 | rc = -EAGAIN; |
| 1435 | goto out; |
| 1436 | } |
| 1437 | ioc->transport_cmds.status = MPT2_CMD_PENDING; |
| 1438 | |
| 1439 | wait_state_count = 0; |
| 1440 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 1441 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 1442 | if (wait_state_count++ == 10) { |
| 1443 | printk(MPT2SAS_ERR_FMT |
| 1444 | "%s: failed due to ioc not operational\n", |
| 1445 | ioc->name, __func__); |
| 1446 | rc = -EFAULT; |
| 1447 | goto out; |
| 1448 | } |
| 1449 | ssleep(1); |
| 1450 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 1451 | printk(MPT2SAS_INFO_FMT "%s: waiting for " |
| 1452 | "operational state(count=%d)\n", ioc->name, |
| 1453 | __func__, wait_state_count); |
| 1454 | } |
| 1455 | if (wait_state_count) |
| 1456 | printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n", |
| 1457 | ioc->name, __func__); |
| 1458 | |
| 1459 | smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx); |
| 1460 | if (!smid) { |
| 1461 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 1462 | ioc->name, __func__); |
| 1463 | rc = -EAGAIN; |
| 1464 | goto out; |
| 1465 | } |
| 1466 | |
| 1467 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 1468 | ioc->transport_cmds.smid = smid; |
| 1469 | |
| 1470 | sz = sizeof(struct phy_control_request) + |
| 1471 | sizeof(struct phy_control_reply); |
| 1472 | data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma); |
| 1473 | if (!data_out) { |
| 1474 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, |
| 1475 | __LINE__, __func__); |
| 1476 | rc = -ENOMEM; |
| 1477 | mpt2sas_base_free_smid(ioc, smid); |
| 1478 | goto out; |
| 1479 | } |
| 1480 | |
| 1481 | rc = -EINVAL; |
| 1482 | memset(data_out, 0, sz); |
| 1483 | phy_control_request = data_out; |
| 1484 | phy_control_request->smp_frame_type = 0x40; |
| 1485 | phy_control_request->function = 0x91; |
| 1486 | phy_control_request->request_length = 9; |
| 1487 | phy_control_request->allocated_response_length = 0; |
| 1488 | phy_control_request->phy_identifier = phy->number; |
| 1489 | phy_control_request->phy_operation = phy_operation; |
| 1490 | phy_control_request->programmed_min_physical_link_rate = |
| 1491 | phy->minimum_linkrate << 4; |
| 1492 | phy_control_request->programmed_max_physical_link_rate = |
| 1493 | phy->maximum_linkrate << 4; |
| 1494 | |
| 1495 | memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t)); |
| 1496 | mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH; |
| 1497 | mpi_request->PhysicalPort = 0xFF; |
| 1498 | mpi_request->VF_ID = 0; /* TODO */ |
| 1499 | mpi_request->VP_ID = 0; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 1500 | mpi_request->SASAddress = cpu_to_le64(phy->identify.sas_address); |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1501 | mpi_request->RequestDataLength = |
| 1502 | cpu_to_le16(sizeof(struct phy_error_log_request)); |
| 1503 | psge = &mpi_request->SGL; |
| 1504 | |
| 1505 | /* WRITE sgel first */ |
| 1506 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1507 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); |
| 1508 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1509 | ioc->base_add_sg_single(psge, sgl_flags | |
| 1510 | sizeof(struct phy_control_request), data_out_dma); |
| 1511 | |
| 1512 | /* incr sgel */ |
| 1513 | psge += ioc->sge_size; |
| 1514 | |
| 1515 | /* READ sgel last */ |
| 1516 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1517 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 1518 | MPI2_SGE_FLAGS_END_OF_LIST); |
| 1519 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1520 | ioc->base_add_sg_single(psge, sgl_flags | |
| 1521 | sizeof(struct phy_control_reply), data_out_dma + |
| 1522 | sizeof(struct phy_control_request)); |
| 1523 | |
| 1524 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_control - " |
| 1525 | "send to sas_addr(0x%016llx), phy(%d), opcode(%d)\n", ioc->name, |
| 1526 | (unsigned long long)phy->identify.sas_address, phy->number, |
| 1527 | phy_operation)); |
nagalakshmi.nandigama@lsi.com | f01690d | 2011-12-01 07:43:58 +0530 | [diff] [blame] | 1528 | |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1529 | init_completion(&ioc->transport_cmds.done); |
nagalakshmi.nandigama@lsi.com | f01690d | 2011-12-01 07:43:58 +0530 | [diff] [blame] | 1530 | mpt2sas_base_put_smid_default(ioc, smid); |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1531 | timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done, |
| 1532 | 10*HZ); |
| 1533 | |
| 1534 | if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) { |
| 1535 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 1536 | ioc->name, __func__); |
| 1537 | _debug_dump_mf(mpi_request, |
| 1538 | sizeof(Mpi2SmpPassthroughRequest_t)/4); |
| 1539 | if (!(ioc->transport_cmds.status & MPT2_CMD_RESET)) |
| 1540 | issue_reset = 1; |
| 1541 | goto issue_host_reset; |
| 1542 | } |
| 1543 | |
| 1544 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "phy_control - " |
| 1545 | "complete\n", ioc->name)); |
| 1546 | |
| 1547 | if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 1548 | |
| 1549 | mpi_reply = ioc->transport_cmds.reply; |
| 1550 | |
| 1551 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 1552 | "phy_control - reply data transfer size(%d)\n", |
| 1553 | ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength))); |
| 1554 | |
| 1555 | if (le16_to_cpu(mpi_reply->ResponseDataLength) != |
| 1556 | sizeof(struct phy_control_reply)) |
| 1557 | goto out; |
| 1558 | |
| 1559 | phy_control_reply = data_out + |
| 1560 | sizeof(struct phy_control_request); |
| 1561 | |
| 1562 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 1563 | "phy_control - function_result(%d)\n", |
| 1564 | ioc->name, phy_control_reply->function_result)); |
| 1565 | |
| 1566 | rc = 0; |
| 1567 | } else |
| 1568 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 1569 | "phy_control - no reply\n", ioc->name)); |
| 1570 | |
| 1571 | issue_host_reset: |
| 1572 | if (issue_reset) |
| 1573 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 1574 | FORCE_BIG_HAMMER); |
| 1575 | out: |
| 1576 | ioc->transport_cmds.status = MPT2_CMD_NOT_USED; |
| 1577 | if (data_out) |
| 1578 | pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma); |
| 1579 | |
| 1580 | mutex_unlock(&ioc->transport_cmds.mutex); |
| 1581 | return rc; |
| 1582 | } |
| 1583 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1584 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1585 | * _transport_phy_reset - |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1586 | * @phy: The sas phy object |
| 1587 | * @hard_reset: |
| 1588 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1589 | * Returns 0 for success, non-zero for failure. |
| 1590 | */ |
| 1591 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1592 | _transport_phy_reset(struct sas_phy *phy, int hard_reset) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1593 | { |
| 1594 | struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1595 | Mpi2SasIoUnitControlReply_t mpi_reply; |
| 1596 | Mpi2SasIoUnitControlRequest_t mpi_request; |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1597 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1598 | |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1599 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 1600 | if (_transport_sas_node_find_by_sas_address(ioc, |
| 1601 | phy->identify.sas_address) == NULL) { |
| 1602 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1603 | return -EINVAL; |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1604 | } |
| 1605 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1606 | |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1607 | /* handle expander phys */ |
| 1608 | if (phy->identify.sas_address != ioc->sas_hba.sas_address) |
| 1609 | return _transport_expander_phy_control(ioc, phy, |
| 1610 | (hard_reset == 1) ? SMP_PHY_CONTROL_HARD_RESET : |
| 1611 | SMP_PHY_CONTROL_LINK_RESET); |
| 1612 | |
| 1613 | /* handle hba phys */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1614 | memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlReply_t)); |
| 1615 | mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; |
| 1616 | mpi_request.Operation = hard_reset ? |
| 1617 | MPI2_SAS_OP_PHY_HARD_RESET : MPI2_SAS_OP_PHY_LINK_RESET; |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1618 | mpi_request.PhyNum = phy->number; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1619 | |
| 1620 | if ((mpt2sas_base_sas_iounit_control(ioc, &mpi_reply, &mpi_request))) { |
| 1621 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1622 | ioc->name, __FILE__, __LINE__, __func__); |
| 1623 | return -ENXIO; |
| 1624 | } |
| 1625 | |
| 1626 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) |
| 1627 | printk(MPT2SAS_INFO_FMT "phy(%d), ioc_status" |
| 1628 | "(0x%04x), loginfo(0x%08x)\n", ioc->name, |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1629 | phy->number, le16_to_cpu(mpi_reply.IOCStatus), |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1630 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 1631 | |
| 1632 | return 0; |
| 1633 | } |
| 1634 | |
| 1635 | /** |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1636 | * _transport_phy_enable - enable/disable phys |
| 1637 | * @phy: The sas phy object |
| 1638 | * @enable: enable phy when true |
| 1639 | * |
| 1640 | * Only support sas_host direct attached phys. |
| 1641 | * Returns 0 for success, non-zero for failure. |
| 1642 | */ |
| 1643 | static int |
| 1644 | _transport_phy_enable(struct sas_phy *phy, int enable) |
| 1645 | { |
| 1646 | struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy); |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1647 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; |
nagalakshmi.nandigama@lsi.com | 43d6ddf | 2012-03-20 12:08:11 +0530 | [diff] [blame] | 1648 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1649 | Mpi2ConfigReply_t mpi_reply; |
| 1650 | u16 ioc_status; |
| 1651 | u16 sz; |
| 1652 | int rc = 0; |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1653 | unsigned long flags; |
nagalakshmi.nandigama@lsi.com | 43d6ddf | 2012-03-20 12:08:11 +0530 | [diff] [blame] | 1654 | int i, discovery_active; |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1655 | |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1656 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 1657 | if (_transport_sas_node_find_by_sas_address(ioc, |
| 1658 | phy->identify.sas_address) == NULL) { |
| 1659 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1660 | return -EINVAL; |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1661 | } |
| 1662 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 1663 | |
| 1664 | /* handle expander phys */ |
| 1665 | if (phy->identify.sas_address != ioc->sas_hba.sas_address) |
| 1666 | return _transport_expander_phy_control(ioc, phy, |
| 1667 | (enable == 1) ? SMP_PHY_CONTROL_LINK_RESET : |
| 1668 | SMP_PHY_CONTROL_DISABLE); |
| 1669 | |
| 1670 | /* handle hba phys */ |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1671 | |
nagalakshmi.nandigama@lsi.com | 43d6ddf | 2012-03-20 12:08:11 +0530 | [diff] [blame] | 1672 | /* read sas_iounit page 0 */ |
| 1673 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * |
| 1674 | sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 1675 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1676 | if (!sas_iounit_pg0) { |
| 1677 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1678 | ioc->name, __FILE__, __LINE__, __func__); |
| 1679 | rc = -ENOMEM; |
| 1680 | goto out; |
| 1681 | } |
| 1682 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 1683 | sas_iounit_pg0, sz))) { |
| 1684 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1685 | ioc->name, __FILE__, __LINE__, __func__); |
| 1686 | rc = -ENXIO; |
| 1687 | goto out; |
| 1688 | } |
| 1689 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1690 | MPI2_IOCSTATUS_MASK; |
| 1691 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 1692 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1693 | ioc->name, __FILE__, __LINE__, __func__); |
| 1694 | rc = -EIO; |
| 1695 | goto out; |
| 1696 | } |
| 1697 | |
| 1698 | /* unable to enable/disable phys when when discovery is active */ |
| 1699 | for (i = 0, discovery_active = 0; i < ioc->sas_hba.num_phys ; i++) { |
| 1700 | if (sas_iounit_pg0->PhyData[i].PortFlags & |
| 1701 | MPI2_SASIOUNIT0_PORTFLAGS_DISCOVERY_IN_PROGRESS) { |
| 1702 | printk(MPT2SAS_ERR_FMT "discovery is active on " |
| 1703 | "port = %d, phy = %d: unable to enable/disable " |
| 1704 | "phys, try again later!\n", ioc->name, |
| 1705 | sas_iounit_pg0->PhyData[i].Port, i); |
| 1706 | discovery_active = 1; |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | if (discovery_active) { |
| 1711 | rc = -EAGAIN; |
| 1712 | goto out; |
| 1713 | } |
| 1714 | |
| 1715 | /* read sas_iounit page 1 */ |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1716 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * |
| 1717 | sizeof(Mpi2SasIOUnit1PhyData_t)); |
| 1718 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); |
| 1719 | if (!sas_iounit_pg1) { |
| 1720 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1721 | ioc->name, __FILE__, __LINE__, __func__); |
| 1722 | rc = -ENOMEM; |
| 1723 | goto out; |
| 1724 | } |
| 1725 | if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, |
| 1726 | sas_iounit_pg1, sz))) { |
| 1727 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1728 | ioc->name, __FILE__, __LINE__, __func__); |
| 1729 | rc = -ENXIO; |
| 1730 | goto out; |
| 1731 | } |
| 1732 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1733 | MPI2_IOCSTATUS_MASK; |
| 1734 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 1735 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1736 | ioc->name, __FILE__, __LINE__, __func__); |
| 1737 | rc = -EIO; |
| 1738 | goto out; |
| 1739 | } |
nagalakshmi.nandigama@lsi.com | 43d6ddf | 2012-03-20 12:08:11 +0530 | [diff] [blame] | 1740 | /* copy Port/PortFlags/PhyFlags from page 0 */ |
| 1741 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
| 1742 | sas_iounit_pg1->PhyData[i].Port = |
| 1743 | sas_iounit_pg0->PhyData[i].Port; |
| 1744 | sas_iounit_pg1->PhyData[i].PortFlags = |
| 1745 | (sas_iounit_pg0->PhyData[i].PortFlags & |
| 1746 | MPI2_SASIOUNIT0_PORTFLAGS_AUTO_PORT_CONFIG); |
| 1747 | sas_iounit_pg1->PhyData[i].PhyFlags = |
| 1748 | (sas_iounit_pg0->PhyData[i].PhyFlags & |
| 1749 | (MPI2_SASIOUNIT0_PHYFLAGS_ZONING_ENABLED + |
| 1750 | MPI2_SASIOUNIT0_PHYFLAGS_PHY_DISABLED)); |
| 1751 | } |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1752 | if (enable) |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1753 | sas_iounit_pg1->PhyData[phy->number].PhyFlags |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1754 | &= ~MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE; |
| 1755 | else |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1756 | sas_iounit_pg1->PhyData[phy->number].PhyFlags |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1757 | |= MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE; |
| 1758 | |
| 1759 | mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, sz); |
| 1760 | |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1761 | /* link reset */ |
| 1762 | if (enable) |
| 1763 | _transport_phy_reset(phy, 0); |
| 1764 | |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1765 | out: |
| 1766 | kfree(sas_iounit_pg1); |
nagalakshmi.nandigama@lsi.com | 43d6ddf | 2012-03-20 12:08:11 +0530 | [diff] [blame] | 1767 | kfree(sas_iounit_pg0); |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1768 | return rc; |
| 1769 | } |
| 1770 | |
| 1771 | /** |
| 1772 | * _transport_phy_speed - set phy min/max link rates |
| 1773 | * @phy: The sas phy object |
| 1774 | * @rates: rates defined in sas_phy_linkrates |
| 1775 | * |
| 1776 | * Only support sas_host direct attached phys. |
| 1777 | * Returns 0 for success, non-zero for failure. |
| 1778 | */ |
| 1779 | static int |
| 1780 | _transport_phy_speed(struct sas_phy *phy, struct sas_phy_linkrates *rates) |
| 1781 | { |
| 1782 | struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy); |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1783 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; |
| 1784 | Mpi2SasPhyPage0_t phy_pg0; |
| 1785 | Mpi2ConfigReply_t mpi_reply; |
| 1786 | u16 ioc_status; |
| 1787 | u16 sz; |
| 1788 | int i; |
| 1789 | int rc = 0; |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1790 | unsigned long flags; |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1791 | |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1792 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 1793 | if (_transport_sas_node_find_by_sas_address(ioc, |
| 1794 | phy->identify.sas_address) == NULL) { |
| 1795 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1796 | return -EINVAL; |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1797 | } |
| 1798 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1799 | |
| 1800 | if (!rates->minimum_linkrate) |
| 1801 | rates->minimum_linkrate = phy->minimum_linkrate; |
| 1802 | else if (rates->minimum_linkrate < phy->minimum_linkrate_hw) |
| 1803 | rates->minimum_linkrate = phy->minimum_linkrate_hw; |
| 1804 | |
| 1805 | if (!rates->maximum_linkrate) |
| 1806 | rates->maximum_linkrate = phy->maximum_linkrate; |
| 1807 | else if (rates->maximum_linkrate > phy->maximum_linkrate_hw) |
| 1808 | rates->maximum_linkrate = phy->maximum_linkrate_hw; |
| 1809 | |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1810 | /* handle expander phys */ |
| 1811 | if (phy->identify.sas_address != ioc->sas_hba.sas_address) { |
| 1812 | phy->minimum_linkrate = rates->minimum_linkrate; |
| 1813 | phy->maximum_linkrate = rates->maximum_linkrate; |
| 1814 | return _transport_expander_phy_control(ioc, phy, |
| 1815 | SMP_PHY_CONTROL_LINK_RESET); |
| 1816 | } |
| 1817 | |
| 1818 | /* handle hba phys */ |
| 1819 | |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1820 | /* sas_iounit page 1 */ |
| 1821 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * |
| 1822 | sizeof(Mpi2SasIOUnit1PhyData_t)); |
| 1823 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); |
| 1824 | if (!sas_iounit_pg1) { |
| 1825 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1826 | ioc->name, __FILE__, __LINE__, __func__); |
| 1827 | rc = -ENOMEM; |
| 1828 | goto out; |
| 1829 | } |
| 1830 | if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, |
| 1831 | sas_iounit_pg1, sz))) { |
| 1832 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1833 | ioc->name, __FILE__, __LINE__, __func__); |
| 1834 | rc = -ENXIO; |
| 1835 | goto out; |
| 1836 | } |
| 1837 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1838 | MPI2_IOCSTATUS_MASK; |
| 1839 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 1840 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1841 | ioc->name, __FILE__, __LINE__, __func__); |
| 1842 | rc = -EIO; |
| 1843 | goto out; |
| 1844 | } |
| 1845 | |
| 1846 | for (i = 0; i < ioc->sas_hba.num_phys; i++) { |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1847 | if (phy->number != i) { |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1848 | sas_iounit_pg1->PhyData[i].MaxMinLinkRate = |
| 1849 | (ioc->sas_hba.phy[i].phy->minimum_linkrate + |
| 1850 | (ioc->sas_hba.phy[i].phy->maximum_linkrate << 4)); |
| 1851 | } else { |
| 1852 | sas_iounit_pg1->PhyData[i].MaxMinLinkRate = |
| 1853 | (rates->minimum_linkrate + |
| 1854 | (rates->maximum_linkrate << 4)); |
| 1855 | } |
| 1856 | } |
| 1857 | |
| 1858 | if (mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, |
| 1859 | sz)) { |
| 1860 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1861 | ioc->name, __FILE__, __LINE__, __func__); |
| 1862 | rc = -ENXIO; |
| 1863 | goto out; |
| 1864 | } |
| 1865 | |
| 1866 | /* link reset */ |
| 1867 | _transport_phy_reset(phy, 0); |
| 1868 | |
| 1869 | /* read phy page 0, then update the rates in the sas transport phy */ |
| 1870 | if (!mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, |
Kashyap, Desai | b8d7d7b | 2010-06-17 13:34:31 +0530 | [diff] [blame] | 1871 | phy->number)) { |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 1872 | phy->minimum_linkrate = _transport_convert_phy_link_rate( |
| 1873 | phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK); |
| 1874 | phy->maximum_linkrate = _transport_convert_phy_link_rate( |
| 1875 | phy_pg0.ProgrammedLinkRate >> 4); |
| 1876 | phy->negotiated_linkrate = _transport_convert_phy_link_rate( |
| 1877 | phy_pg0.NegotiatedLinkRate & |
| 1878 | MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL); |
| 1879 | } |
| 1880 | |
| 1881 | out: |
| 1882 | kfree(sas_iounit_pg1); |
| 1883 | return rc; |
| 1884 | } |
| 1885 | |
| 1886 | |
| 1887 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1888 | * _transport_smp_handler - transport portal for smp passthru |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1889 | * @shost: shost object |
| 1890 | * @rphy: sas transport rphy object |
| 1891 | * @req: |
| 1892 | * |
| 1893 | * This used primarily for smp_utils. |
| 1894 | * Example: |
| 1895 | * smp_rep_general /sys/class/bsg/expander-5:0 |
| 1896 | */ |
| 1897 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1898 | _transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1899 | struct request *req) |
| 1900 | { |
| 1901 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1902 | Mpi2SmpPassthroughRequest_t *mpi_request; |
| 1903 | Mpi2SmpPassthroughReply_t *mpi_reply; |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 1904 | int rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1905 | u16 smid; |
| 1906 | u32 ioc_state; |
| 1907 | unsigned long timeleft; |
| 1908 | void *psge; |
| 1909 | u32 sgl_flags; |
| 1910 | u8 issue_reset = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1911 | dma_addr_t dma_addr_in = 0; |
| 1912 | dma_addr_t dma_addr_out = 0; |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 1913 | dma_addr_t pci_dma_in = 0; |
| 1914 | dma_addr_t pci_dma_out = 0; |
| 1915 | void *pci_addr_in = NULL; |
| 1916 | void *pci_addr_out = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1917 | u16 wait_state_count; |
| 1918 | struct request *rsp = req->next_rq; |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 1919 | struct bio_vec bvec; |
| 1920 | struct bvec_iter iter; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1921 | |
| 1922 | if (!rsp) { |
| 1923 | printk(MPT2SAS_ERR_FMT "%s: the smp response space is " |
| 1924 | "missing\n", ioc->name, __func__); |
| 1925 | return -EINVAL; |
| 1926 | } |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 1927 | if (ioc->shost_recovery || ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1928 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 1929 | __func__, ioc->name); |
| 1930 | return -EFAULT; |
| 1931 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1932 | |
| 1933 | rc = mutex_lock_interruptible(&ioc->transport_cmds.mutex); |
| 1934 | if (rc) |
| 1935 | return rc; |
| 1936 | |
| 1937 | if (ioc->transport_cmds.status != MPT2_CMD_NOT_USED) { |
| 1938 | printk(MPT2SAS_ERR_FMT "%s: transport_cmds in use\n", ioc->name, |
| 1939 | __func__); |
| 1940 | rc = -EAGAIN; |
| 1941 | goto out; |
| 1942 | } |
| 1943 | ioc->transport_cmds.status = MPT2_CMD_PENDING; |
| 1944 | |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 1945 | /* Check if the request is split across multiple segments */ |
Kent Overstreet | 458b76e | 2013-09-24 16:26:05 -0700 | [diff] [blame] | 1946 | if (bio_multiple_segments(req->bio)) { |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 1947 | u32 offset = 0; |
| 1948 | |
| 1949 | /* Allocate memory and copy the request */ |
| 1950 | pci_addr_out = pci_alloc_consistent(ioc->pdev, |
| 1951 | blk_rq_bytes(req), &pci_dma_out); |
| 1952 | if (!pci_addr_out) { |
| 1953 | printk(MPT2SAS_INFO_FMT "%s(): PCI Addr out = NULL\n", |
| 1954 | ioc->name, __func__); |
| 1955 | rc = -ENOMEM; |
| 1956 | goto out; |
| 1957 | } |
| 1958 | |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 1959 | bio_for_each_segment(bvec, req->bio, iter) { |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 1960 | memcpy(pci_addr_out + offset, |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 1961 | page_address(bvec.bv_page) + bvec.bv_offset, |
| 1962 | bvec.bv_len); |
| 1963 | offset += bvec.bv_len; |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 1964 | } |
| 1965 | } else { |
| 1966 | dma_addr_out = pci_map_single(ioc->pdev, bio_data(req->bio), |
| 1967 | blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL); |
| 1968 | if (!dma_addr_out) { |
| 1969 | printk(MPT2SAS_INFO_FMT "%s(): DMA Addr out = NULL\n", |
| 1970 | ioc->name, __func__); |
| 1971 | rc = -ENOMEM; |
| 1972 | goto free_pci; |
| 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | /* Check if the response needs to be populated across |
| 1977 | * multiple segments */ |
Kent Overstreet | 458b76e | 2013-09-24 16:26:05 -0700 | [diff] [blame] | 1978 | if (bio_multiple_segments(rsp->bio)) { |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 1979 | pci_addr_in = pci_alloc_consistent(ioc->pdev, blk_rq_bytes(rsp), |
| 1980 | &pci_dma_in); |
| 1981 | if (!pci_addr_in) { |
| 1982 | printk(MPT2SAS_INFO_FMT "%s(): PCI Addr in = NULL\n", |
| 1983 | ioc->name, __func__); |
| 1984 | rc = -ENOMEM; |
| 1985 | goto unmap; |
| 1986 | } |
| 1987 | } else { |
| 1988 | dma_addr_in = pci_map_single(ioc->pdev, bio_data(rsp->bio), |
| 1989 | blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL); |
| 1990 | if (!dma_addr_in) { |
| 1991 | printk(MPT2SAS_INFO_FMT "%s(): DMA Addr in = NULL\n", |
| 1992 | ioc->name, __func__); |
| 1993 | rc = -ENOMEM; |
| 1994 | goto unmap; |
| 1995 | } |
| 1996 | } |
| 1997 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1998 | wait_state_count = 0; |
| 1999 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 2000 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 2001 | if (wait_state_count++ == 10) { |
| 2002 | printk(MPT2SAS_ERR_FMT |
| 2003 | "%s: failed due to ioc not operational\n", |
| 2004 | ioc->name, __func__); |
| 2005 | rc = -EFAULT; |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 2006 | goto unmap; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2007 | } |
| 2008 | ssleep(1); |
| 2009 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 2010 | printk(MPT2SAS_INFO_FMT "%s: waiting for " |
| 2011 | "operational state(count=%d)\n", ioc->name, |
| 2012 | __func__, wait_state_count); |
| 2013 | } |
| 2014 | if (wait_state_count) |
| 2015 | printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n", |
| 2016 | ioc->name, __func__); |
| 2017 | |
| 2018 | smid = mpt2sas_base_get_smid(ioc, ioc->transport_cb_idx); |
| 2019 | if (!smid) { |
| 2020 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 2021 | ioc->name, __func__); |
| 2022 | rc = -EAGAIN; |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 2023 | goto unmap; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | rc = 0; |
| 2027 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 2028 | ioc->transport_cmds.smid = smid; |
| 2029 | |
| 2030 | memset(mpi_request, 0, sizeof(Mpi2SmpPassthroughRequest_t)); |
| 2031 | mpi_request->Function = MPI2_FUNCTION_SMP_PASSTHROUGH; |
| 2032 | mpi_request->PhysicalPort = 0xFF; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2033 | mpi_request->VF_ID = 0; /* TODO */ |
| 2034 | mpi_request->VP_ID = 0; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 2035 | mpi_request->SASAddress = (rphy) ? |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2036 | cpu_to_le64(rphy->identify.sas_address) : |
| 2037 | cpu_to_le64(ioc->sas_hba.sas_address); |
Tejun Heo | b079041 | 2009-05-07 22:24:42 +0900 | [diff] [blame] | 2038 | mpi_request->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2039 | psge = &mpi_request->SGL; |
| 2040 | |
| 2041 | /* WRITE sgel first */ |
| 2042 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 2043 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); |
| 2044 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
Kent Overstreet | 458b76e | 2013-09-24 16:26:05 -0700 | [diff] [blame] | 2045 | if (bio_multiple_segments(req->bio)) { |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 2046 | ioc->base_add_sg_single(psge, sgl_flags | |
| 2047 | (blk_rq_bytes(req) - 4), pci_dma_out); |
| 2048 | } else { |
| 2049 | ioc->base_add_sg_single(psge, sgl_flags | |
| 2050 | (blk_rq_bytes(req) - 4), dma_addr_out); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2051 | } |
| 2052 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2053 | /* incr sgel */ |
| 2054 | psge += ioc->sge_size; |
| 2055 | |
| 2056 | /* READ sgel last */ |
| 2057 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 2058 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 2059 | MPI2_SGE_FLAGS_END_OF_LIST); |
| 2060 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
Kent Overstreet | 458b76e | 2013-09-24 16:26:05 -0700 | [diff] [blame] | 2061 | if (bio_multiple_segments(rsp->bio)) { |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 2062 | ioc->base_add_sg_single(psge, sgl_flags | |
| 2063 | (blk_rq_bytes(rsp) + 4), pci_dma_in); |
| 2064 | } else { |
| 2065 | ioc->base_add_sg_single(psge, sgl_flags | |
| 2066 | (blk_rq_bytes(rsp) + 4), dma_addr_in); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2067 | } |
| 2068 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 2069 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "%s - " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2070 | "sending smp request\n", ioc->name, __func__)); |
| 2071 | |
Kashyap, Desai | bcfb6e6 | 2009-09-14 11:05:24 +0530 | [diff] [blame] | 2072 | init_completion(&ioc->transport_cmds.done); |
nagalakshmi.nandigama@lsi.com | f01690d | 2011-12-01 07:43:58 +0530 | [diff] [blame] | 2073 | mpt2sas_base_put_smid_default(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2074 | timeleft = wait_for_completion_timeout(&ioc->transport_cmds.done, |
| 2075 | 10*HZ); |
| 2076 | |
| 2077 | if (!(ioc->transport_cmds.status & MPT2_CMD_COMPLETE)) { |
| 2078 | printk(MPT2SAS_ERR_FMT "%s : timeout\n", |
| 2079 | __func__, ioc->name); |
| 2080 | _debug_dump_mf(mpi_request, |
| 2081 | sizeof(Mpi2SmpPassthroughRequest_t)/4); |
| 2082 | if (!(ioc->transport_cmds.status & MPT2_CMD_RESET)) |
| 2083 | issue_reset = 1; |
| 2084 | goto issue_host_reset; |
| 2085 | } |
| 2086 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 2087 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT "%s - " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2088 | "complete\n", ioc->name, __func__)); |
| 2089 | |
| 2090 | if (ioc->transport_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 2091 | |
| 2092 | mpi_reply = ioc->transport_cmds.reply; |
| 2093 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 2094 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2095 | "%s - reply data transfer size(%d)\n", |
| 2096 | ioc->name, __func__, |
| 2097 | le16_to_cpu(mpi_reply->ResponseDataLength))); |
| 2098 | |
| 2099 | memcpy(req->sense, mpi_reply, sizeof(*mpi_reply)); |
| 2100 | req->sense_len = sizeof(*mpi_reply); |
Tejun Heo | 5f49f63 | 2009-05-19 18:33:05 +0900 | [diff] [blame] | 2101 | req->resid_len = 0; |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 2102 | rsp->resid_len -= |
| 2103 | le16_to_cpu(mpi_reply->ResponseDataLength); |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 2104 | /* check if the resp needs to be copied from the allocated |
| 2105 | * pci mem */ |
Kent Overstreet | 458b76e | 2013-09-24 16:26:05 -0700 | [diff] [blame] | 2106 | if (bio_multiple_segments(rsp->bio)) { |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 2107 | u32 offset = 0; |
| 2108 | u32 bytes_to_copy = |
| 2109 | le16_to_cpu(mpi_reply->ResponseDataLength); |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 2110 | bio_for_each_segment(bvec, rsp->bio, iter) { |
| 2111 | if (bytes_to_copy <= bvec.bv_len) { |
| 2112 | memcpy(page_address(bvec.bv_page) + |
| 2113 | bvec.bv_offset, pci_addr_in + |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 2114 | offset, bytes_to_copy); |
| 2115 | break; |
| 2116 | } else { |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 2117 | memcpy(page_address(bvec.bv_page) + |
| 2118 | bvec.bv_offset, pci_addr_in + |
| 2119 | offset, bvec.bv_len); |
| 2120 | bytes_to_copy -= bvec.bv_len; |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 2121 | } |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 2122 | offset += bvec.bv_len; |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 2123 | } |
| 2124 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2125 | } else { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 2126 | dtransportprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2127 | "%s - no reply\n", ioc->name, __func__)); |
| 2128 | rc = -ENXIO; |
| 2129 | } |
| 2130 | |
| 2131 | issue_host_reset: |
| 2132 | if (issue_reset) { |
| 2133 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2134 | FORCE_BIG_HAMMER); |
| 2135 | rc = -ETIMEDOUT; |
| 2136 | } |
| 2137 | |
| 2138 | unmap: |
| 2139 | if (dma_addr_out) |
Tejun Heo | b079041 | 2009-05-07 22:24:42 +0900 | [diff] [blame] | 2140 | pci_unmap_single(ioc->pdev, dma_addr_out, blk_rq_bytes(req), |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2141 | PCI_DMA_BIDIRECTIONAL); |
| 2142 | if (dma_addr_in) |
Tejun Heo | b079041 | 2009-05-07 22:24:42 +0900 | [diff] [blame] | 2143 | pci_unmap_single(ioc->pdev, dma_addr_in, blk_rq_bytes(rsp), |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2144 | PCI_DMA_BIDIRECTIONAL); |
| 2145 | |
nagalakshmi.nandigama@lsi.com | 77a6edf | 2012-03-20 12:04:43 +0530 | [diff] [blame] | 2146 | free_pci: |
| 2147 | if (pci_addr_out) |
| 2148 | pci_free_consistent(ioc->pdev, blk_rq_bytes(req), pci_addr_out, |
| 2149 | pci_dma_out); |
| 2150 | |
| 2151 | if (pci_addr_in) |
| 2152 | pci_free_consistent(ioc->pdev, blk_rq_bytes(rsp), pci_addr_in, |
| 2153 | pci_dma_in); |
| 2154 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2155 | out: |
| 2156 | ioc->transport_cmds.status = MPT2_CMD_NOT_USED; |
| 2157 | mutex_unlock(&ioc->transport_cmds.mutex); |
| 2158 | return rc; |
| 2159 | } |
| 2160 | |
| 2161 | struct sas_function_template mpt2sas_transport_functions = { |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2162 | .get_linkerrors = _transport_get_linkerrors, |
| 2163 | .get_enclosure_identifier = _transport_get_enclosure_identifier, |
| 2164 | .get_bay_identifier = _transport_get_bay_identifier, |
| 2165 | .phy_reset = _transport_phy_reset, |
Kashyap, Desai | 50d5c60 | 2009-12-16 18:55:26 +0530 | [diff] [blame] | 2166 | .phy_enable = _transport_phy_enable, |
| 2167 | .set_phy_speed = _transport_phy_speed, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2168 | .smp_handler = _transport_smp_handler, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2169 | }; |
| 2170 | |
| 2171 | struct scsi_transport_template *mpt2sas_transport_template; |