Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Scsi Host Layer for MPT (Message Passing Technology) based controllers |
| 3 | * |
| 4 | * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c |
Sreekanth Reddy | 48e3b98 | 2013-06-29 03:50:34 +0530 | [diff] [blame] | 5 | * Copyright (C) 2012-2013 LSI Corporation |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [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 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 44 | #include <linux/module.h> |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/init.h> |
| 47 | #include <linux/errno.h> |
| 48 | #include <linux/blkdev.h> |
| 49 | #include <linux/sched.h> |
| 50 | #include <linux/workqueue.h> |
| 51 | #include <linux/delay.h> |
| 52 | #include <linux/pci.h> |
| 53 | #include <linux/interrupt.h> |
| 54 | #include <linux/aer.h> |
| 55 | #include <linux/raid_class.h> |
| 56 | |
| 57 | #include "mpt3sas_base.h" |
| 58 | |
| 59 | MODULE_AUTHOR(MPT3SAS_AUTHOR); |
| 60 | MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION); |
| 61 | MODULE_LICENSE("GPL"); |
| 62 | MODULE_VERSION(MPT3SAS_DRIVER_VERSION); |
| 63 | |
| 64 | #define RAID_CHANNEL 1 |
| 65 | /* forward proto's */ |
| 66 | static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, |
| 67 | struct _sas_node *sas_expander); |
| 68 | static void _firmware_event_work(struct work_struct *work); |
| 69 | |
| 70 | static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, |
| 71 | struct _sas_device *sas_device); |
| 72 | static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, |
| 73 | u8 retry_count, u8 is_pd); |
| 74 | |
| 75 | static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid); |
| 76 | |
| 77 | static void _scsih_scan_start(struct Scsi_Host *shost); |
| 78 | static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time); |
| 79 | |
| 80 | /* global parameters */ |
| 81 | LIST_HEAD(mpt3sas_ioc_list); |
| 82 | |
| 83 | /* local parameters */ |
| 84 | static u8 scsi_io_cb_idx = -1; |
| 85 | static u8 tm_cb_idx = -1; |
| 86 | static u8 ctl_cb_idx = -1; |
| 87 | static u8 base_cb_idx = -1; |
| 88 | static u8 port_enable_cb_idx = -1; |
| 89 | static u8 transport_cb_idx = -1; |
| 90 | static u8 scsih_cb_idx = -1; |
| 91 | static u8 config_cb_idx = -1; |
| 92 | static int mpt_ids; |
| 93 | |
| 94 | static u8 tm_tr_cb_idx = -1 ; |
| 95 | static u8 tm_tr_volume_cb_idx = -1 ; |
| 96 | static u8 tm_sas_control_cb_idx = -1; |
| 97 | |
| 98 | /* command line options */ |
| 99 | static u32 logging_level; |
| 100 | MODULE_PARM_DESC(logging_level, |
| 101 | " bits for enabling additional logging info (default=0)"); |
| 102 | |
| 103 | |
| 104 | static ushort max_sectors = 0xFFFF; |
| 105 | module_param(max_sectors, ushort, 0); |
| 106 | MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767"); |
| 107 | |
| 108 | |
| 109 | static int missing_delay[2] = {-1, -1}; |
| 110 | module_param_array(missing_delay, int, NULL, 0); |
| 111 | MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay"); |
| 112 | |
| 113 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ |
| 114 | #define MPT3SAS_MAX_LUN (16895) |
| 115 | static int max_lun = MPT3SAS_MAX_LUN; |
| 116 | module_param(max_lun, int, 0); |
| 117 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | /* diag_buffer_enable is bitwise |
| 123 | * bit 0 set = TRACE |
| 124 | * bit 1 set = SNAPSHOT |
| 125 | * bit 2 set = EXTENDED |
| 126 | * |
| 127 | * Either bit can be set, or both |
| 128 | */ |
| 129 | static int diag_buffer_enable = -1; |
| 130 | module_param(diag_buffer_enable, int, 0); |
| 131 | MODULE_PARM_DESC(diag_buffer_enable, |
| 132 | " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); |
| 133 | static int disable_discovery = -1; |
| 134 | module_param(disable_discovery, int, 0); |
| 135 | MODULE_PARM_DESC(disable_discovery, " disable discovery "); |
| 136 | |
| 137 | |
| 138 | /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */ |
| 139 | static int prot_mask = -1; |
| 140 | module_param(prot_mask, int, 0); |
| 141 | MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 "); |
| 142 | |
| 143 | |
| 144 | /* raid transport support */ |
| 145 | |
| 146 | static struct raid_template *mpt3sas_raid_template; |
| 147 | |
| 148 | |
| 149 | /** |
| 150 | * struct sense_info - common structure for obtaining sense keys |
| 151 | * @skey: sense key |
| 152 | * @asc: additional sense code |
| 153 | * @ascq: additional sense code qualifier |
| 154 | */ |
| 155 | struct sense_info { |
| 156 | u8 skey; |
| 157 | u8 asc; |
| 158 | u8 ascq; |
| 159 | }; |
| 160 | |
| 161 | #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB) |
| 162 | #define MPT3SAS_TURN_ON_FAULT_LED (0xFFFC) |
| 163 | #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD) |
| 164 | #define MPT3SAS_ABRT_TASK_SET (0xFFFE) |
| 165 | #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF) |
| 166 | /** |
| 167 | * struct fw_event_work - firmware event struct |
| 168 | * @list: link list framework |
| 169 | * @work: work object (ioc->fault_reset_work_q) |
| 170 | * @cancel_pending_work: flag set during reset handling |
| 171 | * @ioc: per adapter object |
| 172 | * @device_handle: device handle |
| 173 | * @VF_ID: virtual function id |
| 174 | * @VP_ID: virtual port id |
| 175 | * @ignore: flag meaning this event has been marked to ignore |
| 176 | * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h |
| 177 | * @event_data: reply event data payload follows |
| 178 | * |
| 179 | * This object stored on ioc->fw_event_list. |
| 180 | */ |
| 181 | struct fw_event_work { |
| 182 | struct list_head list; |
| 183 | struct work_struct work; |
| 184 | u8 cancel_pending_work; |
| 185 | struct delayed_work delayed_work; |
| 186 | |
| 187 | struct MPT3SAS_ADAPTER *ioc; |
| 188 | u16 device_handle; |
| 189 | u8 VF_ID; |
| 190 | u8 VP_ID; |
| 191 | u8 ignore; |
| 192 | u16 event; |
| 193 | void *event_data; |
| 194 | }; |
| 195 | |
| 196 | /* raid transport support */ |
| 197 | static struct raid_template *mpt3sas_raid_template; |
| 198 | |
| 199 | /** |
| 200 | * struct _scsi_io_transfer - scsi io transfer |
| 201 | * @handle: sas device handle (assigned by firmware) |
| 202 | * @is_raid: flag set for hidden raid components |
| 203 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, |
| 204 | * @data_length: data transfer length |
| 205 | * @data_dma: dma pointer to data |
| 206 | * @sense: sense data |
| 207 | * @lun: lun number |
| 208 | * @cdb_length: cdb length |
| 209 | * @cdb: cdb contents |
| 210 | * @timeout: timeout for this command |
| 211 | * @VF_ID: virtual function id |
| 212 | * @VP_ID: virtual port id |
| 213 | * @valid_reply: flag set for reply message |
| 214 | * @sense_length: sense length |
| 215 | * @ioc_status: ioc status |
| 216 | * @scsi_state: scsi state |
| 217 | * @scsi_status: scsi staus |
| 218 | * @log_info: log information |
| 219 | * @transfer_length: data length transfer when there is a reply message |
| 220 | * |
| 221 | * Used for sending internal scsi commands to devices within this module. |
| 222 | * Refer to _scsi_send_scsi_io(). |
| 223 | */ |
| 224 | struct _scsi_io_transfer { |
| 225 | u16 handle; |
| 226 | u8 is_raid; |
| 227 | enum dma_data_direction dir; |
| 228 | u32 data_length; |
| 229 | dma_addr_t data_dma; |
| 230 | u8 sense[SCSI_SENSE_BUFFERSIZE]; |
| 231 | u32 lun; |
| 232 | u8 cdb_length; |
| 233 | u8 cdb[32]; |
| 234 | u8 timeout; |
| 235 | u8 VF_ID; |
| 236 | u8 VP_ID; |
| 237 | u8 valid_reply; |
| 238 | /* the following bits are only valid when 'valid_reply = 1' */ |
| 239 | u32 sense_length; |
| 240 | u16 ioc_status; |
| 241 | u8 scsi_state; |
| 242 | u8 scsi_status; |
| 243 | u32 log_info; |
| 244 | u32 transfer_length; |
| 245 | }; |
| 246 | |
| 247 | /* |
| 248 | * The pci device ids are defined in mpi/mpi2_cnfg.h. |
| 249 | */ |
| 250 | static DEFINE_PCI_DEVICE_TABLE(scsih_pci_table) = { |
| 251 | /* Fury ~ 3004 and 3008 */ |
| 252 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004, |
| 253 | PCI_ANY_ID, PCI_ANY_ID }, |
| 254 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008, |
| 255 | PCI_ANY_ID, PCI_ANY_ID }, |
| 256 | /* Invader ~ 3108 */ |
| 257 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1, |
| 258 | PCI_ANY_ID, PCI_ANY_ID }, |
| 259 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2, |
| 260 | PCI_ANY_ID, PCI_ANY_ID }, |
| 261 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5, |
| 262 | PCI_ANY_ID, PCI_ANY_ID }, |
| 263 | { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6, |
| 264 | PCI_ANY_ID, PCI_ANY_ID }, |
| 265 | {0} /* Terminating entry */ |
| 266 | }; |
| 267 | MODULE_DEVICE_TABLE(pci, scsih_pci_table); |
| 268 | |
| 269 | /** |
| 270 | * _scsih_set_debug_level - global setting of ioc->logging_level. |
| 271 | * |
| 272 | * Note: The logging levels are defined in mpt3sas_debug.h. |
| 273 | */ |
| 274 | static int |
| 275 | _scsih_set_debug_level(const char *val, struct kernel_param *kp) |
| 276 | { |
| 277 | int ret = param_set_int(val, kp); |
| 278 | struct MPT3SAS_ADAPTER *ioc; |
| 279 | |
| 280 | if (ret) |
| 281 | return ret; |
| 282 | |
| 283 | pr_info("setting logging_level(0x%08x)\n", logging_level); |
| 284 | list_for_each_entry(ioc, &mpt3sas_ioc_list, list) |
| 285 | ioc->logging_level = logging_level; |
| 286 | return 0; |
| 287 | } |
| 288 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, |
| 289 | &logging_level, 0644); |
| 290 | |
| 291 | /** |
| 292 | * _scsih_srch_boot_sas_address - search based on sas_address |
| 293 | * @sas_address: sas address |
| 294 | * @boot_device: boot device object from bios page 2 |
| 295 | * |
| 296 | * Returns 1 when there's a match, 0 means no match. |
| 297 | */ |
| 298 | static inline int |
| 299 | _scsih_srch_boot_sas_address(u64 sas_address, |
| 300 | Mpi2BootDeviceSasWwid_t *boot_device) |
| 301 | { |
| 302 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * _scsih_srch_boot_device_name - search based on device name |
| 307 | * @device_name: device name specified in INDENTIFY fram |
| 308 | * @boot_device: boot device object from bios page 2 |
| 309 | * |
| 310 | * Returns 1 when there's a match, 0 means no match. |
| 311 | */ |
| 312 | static inline int |
| 313 | _scsih_srch_boot_device_name(u64 device_name, |
| 314 | Mpi2BootDeviceDeviceName_t *boot_device) |
| 315 | { |
| 316 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot |
| 321 | * @enclosure_logical_id: enclosure logical id |
| 322 | * @slot_number: slot number |
| 323 | * @boot_device: boot device object from bios page 2 |
| 324 | * |
| 325 | * Returns 1 when there's a match, 0 means no match. |
| 326 | */ |
| 327 | static inline int |
| 328 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, |
| 329 | Mpi2BootDeviceEnclosureSlot_t *boot_device) |
| 330 | { |
| 331 | return (enclosure_logical_id == le64_to_cpu(boot_device-> |
| 332 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> |
| 333 | SlotNumber)) ? 1 : 0; |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * _scsih_is_boot_device - search for matching boot device. |
| 338 | * @sas_address: sas address |
| 339 | * @device_name: device name specified in INDENTIFY fram |
| 340 | * @enclosure_logical_id: enclosure logical id |
| 341 | * @slot_number: slot number |
| 342 | * @form: specifies boot device form |
| 343 | * @boot_device: boot device object from bios page 2 |
| 344 | * |
| 345 | * Returns 1 when there's a match, 0 means no match. |
| 346 | */ |
| 347 | static int |
| 348 | _scsih_is_boot_device(u64 sas_address, u64 device_name, |
| 349 | u64 enclosure_logical_id, u16 slot, u8 form, |
| 350 | Mpi2BiosPage2BootDevice_t *boot_device) |
| 351 | { |
| 352 | int rc = 0; |
| 353 | |
| 354 | switch (form) { |
| 355 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: |
| 356 | if (!sas_address) |
| 357 | break; |
| 358 | rc = _scsih_srch_boot_sas_address( |
| 359 | sas_address, &boot_device->SasWwid); |
| 360 | break; |
| 361 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: |
| 362 | if (!enclosure_logical_id) |
| 363 | break; |
| 364 | rc = _scsih_srch_boot_encl_slot( |
| 365 | enclosure_logical_id, |
| 366 | slot, &boot_device->EnclosureSlot); |
| 367 | break; |
| 368 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: |
| 369 | if (!device_name) |
| 370 | break; |
| 371 | rc = _scsih_srch_boot_device_name( |
| 372 | device_name, &boot_device->DeviceName); |
| 373 | break; |
| 374 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: |
| 375 | break; |
| 376 | } |
| 377 | |
| 378 | return rc; |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * _scsih_get_sas_address - set the sas_address for given device handle |
| 383 | * @handle: device handle |
| 384 | * @sas_address: sas address |
| 385 | * |
| 386 | * Returns 0 success, non-zero when failure |
| 387 | */ |
| 388 | static int |
| 389 | _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle, |
| 390 | u64 *sas_address) |
| 391 | { |
| 392 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 393 | Mpi2ConfigReply_t mpi_reply; |
| 394 | u32 ioc_status; |
| 395 | |
| 396 | *sas_address = 0; |
| 397 | |
| 398 | if (handle <= ioc->sas_hba.num_phys) { |
| 399 | *sas_address = ioc->sas_hba.sas_address; |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 404 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 405 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 406 | __FILE__, __LINE__, __func__); |
| 407 | return -ENXIO; |
| 408 | } |
| 409 | |
| 410 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 411 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { |
| 412 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | /* we hit this becuase the given parent handle doesn't exist */ |
| 417 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 418 | return -ENXIO; |
| 419 | |
| 420 | /* else error case */ |
| 421 | pr_err(MPT3SAS_FMT |
| 422 | "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n", |
| 423 | ioc->name, handle, ioc_status, |
| 424 | __FILE__, __LINE__, __func__); |
| 425 | return -EIO; |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * _scsih_determine_boot_device - determine boot device. |
| 430 | * @ioc: per adapter object |
| 431 | * @device: either sas_device or raid_device object |
| 432 | * @is_raid: [flag] 1 = raid object, 0 = sas object |
| 433 | * |
| 434 | * Determines whether this device should be first reported device to |
| 435 | * to scsi-ml or sas transport, this purpose is for persistent boot device. |
| 436 | * There are primary, alternate, and current entries in bios page 2. The order |
| 437 | * priority is primary, alternate, then current. This routine saves |
| 438 | * the corresponding device object and is_raid flag in the ioc object. |
| 439 | * The saved data to be used later in _scsih_probe_boot_devices(). |
| 440 | */ |
| 441 | static void |
| 442 | _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc, |
| 443 | void *device, u8 is_raid) |
| 444 | { |
| 445 | struct _sas_device *sas_device; |
| 446 | struct _raid_device *raid_device; |
| 447 | u64 sas_address; |
| 448 | u64 device_name; |
| 449 | u64 enclosure_logical_id; |
| 450 | u16 slot; |
| 451 | |
| 452 | /* only process this function when driver loads */ |
| 453 | if (!ioc->is_driver_loading) |
| 454 | return; |
| 455 | |
| 456 | /* no Bios, return immediately */ |
| 457 | if (!ioc->bios_pg3.BiosVersion) |
| 458 | return; |
| 459 | |
| 460 | if (!is_raid) { |
| 461 | sas_device = device; |
| 462 | sas_address = sas_device->sas_address; |
| 463 | device_name = sas_device->device_name; |
| 464 | enclosure_logical_id = sas_device->enclosure_logical_id; |
| 465 | slot = sas_device->slot; |
| 466 | } else { |
| 467 | raid_device = device; |
| 468 | sas_address = raid_device->wwid; |
| 469 | device_name = 0; |
| 470 | enclosure_logical_id = 0; |
| 471 | slot = 0; |
| 472 | } |
| 473 | |
| 474 | if (!ioc->req_boot_device.device) { |
| 475 | if (_scsih_is_boot_device(sas_address, device_name, |
| 476 | enclosure_logical_id, slot, |
| 477 | (ioc->bios_pg2.ReqBootDeviceForm & |
| 478 | MPI2_BIOSPAGE2_FORM_MASK), |
| 479 | &ioc->bios_pg2.RequestedBootDevice)) { |
| 480 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 481 | "%s: req_boot_device(0x%016llx)\n", |
| 482 | ioc->name, __func__, |
| 483 | (unsigned long long)sas_address)); |
| 484 | ioc->req_boot_device.device = device; |
| 485 | ioc->req_boot_device.is_raid = is_raid; |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | if (!ioc->req_alt_boot_device.device) { |
| 490 | if (_scsih_is_boot_device(sas_address, device_name, |
| 491 | enclosure_logical_id, slot, |
| 492 | (ioc->bios_pg2.ReqAltBootDeviceForm & |
| 493 | MPI2_BIOSPAGE2_FORM_MASK), |
| 494 | &ioc->bios_pg2.RequestedAltBootDevice)) { |
| 495 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 496 | "%s: req_alt_boot_device(0x%016llx)\n", |
| 497 | ioc->name, __func__, |
| 498 | (unsigned long long)sas_address)); |
| 499 | ioc->req_alt_boot_device.device = device; |
| 500 | ioc->req_alt_boot_device.is_raid = is_raid; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | if (!ioc->current_boot_device.device) { |
| 505 | if (_scsih_is_boot_device(sas_address, device_name, |
| 506 | enclosure_logical_id, slot, |
| 507 | (ioc->bios_pg2.CurrentBootDeviceForm & |
| 508 | MPI2_BIOSPAGE2_FORM_MASK), |
| 509 | &ioc->bios_pg2.CurrentBootDevice)) { |
| 510 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 511 | "%s: current_boot_device(0x%016llx)\n", |
| 512 | ioc->name, __func__, |
| 513 | (unsigned long long)sas_address)); |
| 514 | ioc->current_boot_device.device = device; |
| 515 | ioc->current_boot_device.is_raid = is_raid; |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | /** |
| 521 | * mpt3sas_scsih_sas_device_find_by_sas_address - sas device search |
| 522 | * @ioc: per adapter object |
| 523 | * @sas_address: sas address |
| 524 | * Context: Calling function should acquire ioc->sas_device_lock |
| 525 | * |
| 526 | * This searches for sas_device based on sas_address, then return sas_device |
| 527 | * object. |
| 528 | */ |
| 529 | struct _sas_device * |
| 530 | mpt3sas_scsih_sas_device_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc, |
| 531 | u64 sas_address) |
| 532 | { |
| 533 | struct _sas_device *sas_device; |
| 534 | |
| 535 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) |
| 536 | if (sas_device->sas_address == sas_address) |
| 537 | return sas_device; |
| 538 | |
| 539 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) |
| 540 | if (sas_device->sas_address == sas_address) |
| 541 | return sas_device; |
| 542 | |
| 543 | return NULL; |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * _scsih_sas_device_find_by_handle - sas device search |
| 548 | * @ioc: per adapter object |
| 549 | * @handle: sas device handle (assigned by firmware) |
| 550 | * Context: Calling function should acquire ioc->sas_device_lock |
| 551 | * |
| 552 | * This searches for sas_device based on sas_address, then return sas_device |
| 553 | * object. |
| 554 | */ |
| 555 | static struct _sas_device * |
| 556 | _scsih_sas_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 557 | { |
| 558 | struct _sas_device *sas_device; |
| 559 | |
| 560 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) |
| 561 | if (sas_device->handle == handle) |
| 562 | return sas_device; |
| 563 | |
| 564 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) |
| 565 | if (sas_device->handle == handle) |
| 566 | return sas_device; |
| 567 | |
| 568 | return NULL; |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * _scsih_sas_device_remove - remove sas_device from list. |
| 573 | * @ioc: per adapter object |
| 574 | * @sas_device: the sas_device object |
| 575 | * Context: This function will acquire ioc->sas_device_lock. |
| 576 | * |
| 577 | * Removing object and freeing associated memory from the ioc->sas_device_list. |
| 578 | */ |
| 579 | static void |
| 580 | _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc, |
| 581 | struct _sas_device *sas_device) |
| 582 | { |
| 583 | unsigned long flags; |
| 584 | |
| 585 | if (!sas_device) |
| 586 | return; |
| 587 | |
| 588 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 589 | list_del(&sas_device->list); |
| 590 | kfree(sas_device); |
| 591 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 592 | } |
| 593 | |
| 594 | /** |
| 595 | * _scsih_device_remove_by_handle - removing device object by handle |
| 596 | * @ioc: per adapter object |
| 597 | * @handle: device handle |
| 598 | * |
| 599 | * Return nothing. |
| 600 | */ |
| 601 | static void |
| 602 | _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 603 | { |
| 604 | struct _sas_device *sas_device; |
| 605 | unsigned long flags; |
| 606 | |
| 607 | if (ioc->shost_recovery) |
| 608 | return; |
| 609 | |
| 610 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 611 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 612 | if (sas_device) |
| 613 | list_del(&sas_device->list); |
| 614 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 615 | if (sas_device) |
| 616 | _scsih_remove_device(ioc, sas_device); |
| 617 | } |
| 618 | |
| 619 | /** |
| 620 | * mpt3sas_device_remove_by_sas_address - removing device object by sas address |
| 621 | * @ioc: per adapter object |
| 622 | * @sas_address: device sas_address |
| 623 | * |
| 624 | * Return nothing. |
| 625 | */ |
| 626 | void |
| 627 | mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc, |
| 628 | u64 sas_address) |
| 629 | { |
| 630 | struct _sas_device *sas_device; |
| 631 | unsigned long flags; |
| 632 | |
| 633 | if (ioc->shost_recovery) |
| 634 | return; |
| 635 | |
| 636 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 637 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, |
| 638 | sas_address); |
| 639 | if (sas_device) |
| 640 | list_del(&sas_device->list); |
| 641 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 642 | if (sas_device) |
| 643 | _scsih_remove_device(ioc, sas_device); |
| 644 | } |
| 645 | |
| 646 | /** |
| 647 | * _scsih_sas_device_add - insert sas_device to the list. |
| 648 | * @ioc: per adapter object |
| 649 | * @sas_device: the sas_device object |
| 650 | * Context: This function will acquire ioc->sas_device_lock. |
| 651 | * |
| 652 | * Adding new object to the ioc->sas_device_list. |
| 653 | */ |
| 654 | static void |
| 655 | _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc, |
| 656 | struct _sas_device *sas_device) |
| 657 | { |
| 658 | unsigned long flags; |
| 659 | |
| 660 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 661 | "%s: handle(0x%04x), sas_addr(0x%016llx)\n", |
| 662 | ioc->name, __func__, sas_device->handle, |
| 663 | (unsigned long long)sas_device->sas_address)); |
| 664 | |
| 665 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 666 | list_add_tail(&sas_device->list, &ioc->sas_device_list); |
| 667 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 668 | |
| 669 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
| 670 | sas_device->sas_address_parent)) { |
| 671 | _scsih_sas_device_remove(ioc, sas_device); |
| 672 | } else if (!sas_device->starget) { |
| 673 | /* |
| 674 | * When asyn scanning is enabled, its not possible to remove |
| 675 | * devices while scanning is turned on due to an oops in |
| 676 | * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start() |
| 677 | */ |
Sreekanth Reddy | f5edbe7 | 2013-06-29 03:54:51 +0530 | [diff] [blame] | 678 | if (!ioc->is_driver_loading) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 679 | mpt3sas_transport_port_remove(ioc, |
| 680 | sas_device->sas_address, |
| 681 | sas_device->sas_address_parent); |
Sreekanth Reddy | f5edbe7 | 2013-06-29 03:54:51 +0530 | [diff] [blame] | 682 | _scsih_sas_device_remove(ioc, sas_device); |
| 683 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 684 | } |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * _scsih_sas_device_init_add - insert sas_device to the list. |
| 689 | * @ioc: per adapter object |
| 690 | * @sas_device: the sas_device object |
| 691 | * Context: This function will acquire ioc->sas_device_lock. |
| 692 | * |
| 693 | * Adding new object at driver load time to the ioc->sas_device_init_list. |
| 694 | */ |
| 695 | static void |
| 696 | _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc, |
| 697 | struct _sas_device *sas_device) |
| 698 | { |
| 699 | unsigned long flags; |
| 700 | |
| 701 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 702 | "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, |
| 703 | __func__, sas_device->handle, |
| 704 | (unsigned long long)sas_device->sas_address)); |
| 705 | |
| 706 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 707 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); |
| 708 | _scsih_determine_boot_device(ioc, sas_device, 0); |
| 709 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 710 | } |
| 711 | |
| 712 | /** |
| 713 | * _scsih_raid_device_find_by_id - raid device search |
| 714 | * @ioc: per adapter object |
| 715 | * @id: sas device target id |
| 716 | * @channel: sas device channel |
| 717 | * Context: Calling function should acquire ioc->raid_device_lock |
| 718 | * |
| 719 | * This searches for raid_device based on target id, then return raid_device |
| 720 | * object. |
| 721 | */ |
| 722 | static struct _raid_device * |
| 723 | _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel) |
| 724 | { |
| 725 | struct _raid_device *raid_device, *r; |
| 726 | |
| 727 | r = NULL; |
| 728 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 729 | if (raid_device->id == id && raid_device->channel == channel) { |
| 730 | r = raid_device; |
| 731 | goto out; |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | out: |
| 736 | return r; |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * _scsih_raid_device_find_by_handle - raid device search |
| 741 | * @ioc: per adapter object |
| 742 | * @handle: sas device handle (assigned by firmware) |
| 743 | * Context: Calling function should acquire ioc->raid_device_lock |
| 744 | * |
| 745 | * This searches for raid_device based on handle, then return raid_device |
| 746 | * object. |
| 747 | */ |
| 748 | static struct _raid_device * |
| 749 | _scsih_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 750 | { |
| 751 | struct _raid_device *raid_device, *r; |
| 752 | |
| 753 | r = NULL; |
| 754 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 755 | if (raid_device->handle != handle) |
| 756 | continue; |
| 757 | r = raid_device; |
| 758 | goto out; |
| 759 | } |
| 760 | |
| 761 | out: |
| 762 | return r; |
| 763 | } |
| 764 | |
| 765 | /** |
| 766 | * _scsih_raid_device_find_by_wwid - raid device search |
| 767 | * @ioc: per adapter object |
| 768 | * @handle: sas device handle (assigned by firmware) |
| 769 | * Context: Calling function should acquire ioc->raid_device_lock |
| 770 | * |
| 771 | * This searches for raid_device based on wwid, then return raid_device |
| 772 | * object. |
| 773 | */ |
| 774 | static struct _raid_device * |
| 775 | _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid) |
| 776 | { |
| 777 | struct _raid_device *raid_device, *r; |
| 778 | |
| 779 | r = NULL; |
| 780 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 781 | if (raid_device->wwid != wwid) |
| 782 | continue; |
| 783 | r = raid_device; |
| 784 | goto out; |
| 785 | } |
| 786 | |
| 787 | out: |
| 788 | return r; |
| 789 | } |
| 790 | |
| 791 | /** |
| 792 | * _scsih_raid_device_add - add raid_device object |
| 793 | * @ioc: per adapter object |
| 794 | * @raid_device: raid_device object |
| 795 | * |
| 796 | * This is added to the raid_device_list link list. |
| 797 | */ |
| 798 | static void |
| 799 | _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc, |
| 800 | struct _raid_device *raid_device) |
| 801 | { |
| 802 | unsigned long flags; |
| 803 | |
| 804 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 805 | "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, |
| 806 | raid_device->handle, (unsigned long long)raid_device->wwid)); |
| 807 | |
| 808 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 809 | list_add_tail(&raid_device->list, &ioc->raid_device_list); |
| 810 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 811 | } |
| 812 | |
| 813 | /** |
| 814 | * _scsih_raid_device_remove - delete raid_device object |
| 815 | * @ioc: per adapter object |
| 816 | * @raid_device: raid_device object |
| 817 | * |
| 818 | */ |
| 819 | static void |
| 820 | _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc, |
| 821 | struct _raid_device *raid_device) |
| 822 | { |
| 823 | unsigned long flags; |
| 824 | |
| 825 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 826 | list_del(&raid_device->list); |
| 827 | kfree(raid_device); |
| 828 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 829 | } |
| 830 | |
| 831 | /** |
| 832 | * mpt3sas_scsih_expander_find_by_handle - expander device search |
| 833 | * @ioc: per adapter object |
| 834 | * @handle: expander handle (assigned by firmware) |
| 835 | * Context: Calling function should acquire ioc->sas_device_lock |
| 836 | * |
| 837 | * This searches for expander device based on handle, then returns the |
| 838 | * sas_node object. |
| 839 | */ |
| 840 | struct _sas_node * |
| 841 | mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 842 | { |
| 843 | struct _sas_node *sas_expander, *r; |
| 844 | |
| 845 | r = NULL; |
| 846 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 847 | if (sas_expander->handle != handle) |
| 848 | continue; |
| 849 | r = sas_expander; |
| 850 | goto out; |
| 851 | } |
| 852 | out: |
| 853 | return r; |
| 854 | } |
| 855 | |
| 856 | /** |
| 857 | * mpt3sas_scsih_expander_find_by_sas_address - expander device search |
| 858 | * @ioc: per adapter object |
| 859 | * @sas_address: sas address |
| 860 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 861 | * |
| 862 | * This searches for expander device based on sas_address, then returns the |
| 863 | * sas_node object. |
| 864 | */ |
| 865 | struct _sas_node * |
| 866 | mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc, |
| 867 | u64 sas_address) |
| 868 | { |
| 869 | struct _sas_node *sas_expander, *r; |
| 870 | |
| 871 | r = NULL; |
| 872 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 873 | if (sas_expander->sas_address != sas_address) |
| 874 | continue; |
| 875 | r = sas_expander; |
| 876 | goto out; |
| 877 | } |
| 878 | out: |
| 879 | return r; |
| 880 | } |
| 881 | |
| 882 | /** |
| 883 | * _scsih_expander_node_add - insert expander device to the list. |
| 884 | * @ioc: per adapter object |
| 885 | * @sas_expander: the sas_device object |
| 886 | * Context: This function will acquire ioc->sas_node_lock. |
| 887 | * |
| 888 | * Adding new object to the ioc->sas_expander_list. |
| 889 | * |
| 890 | * Return nothing. |
| 891 | */ |
| 892 | static void |
| 893 | _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc, |
| 894 | struct _sas_node *sas_expander) |
| 895 | { |
| 896 | unsigned long flags; |
| 897 | |
| 898 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 899 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); |
| 900 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 901 | } |
| 902 | |
| 903 | /** |
| 904 | * _scsih_is_end_device - determines if device is an end device |
| 905 | * @device_info: bitfield providing information about the device. |
| 906 | * Context: none |
| 907 | * |
| 908 | * Returns 1 if end device. |
| 909 | */ |
| 910 | static int |
| 911 | _scsih_is_end_device(u32 device_info) |
| 912 | { |
| 913 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && |
| 914 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | |
| 915 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
| 916 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) |
| 917 | return 1; |
| 918 | else |
| 919 | return 0; |
| 920 | } |
| 921 | |
| 922 | /** |
| 923 | * _scsih_scsi_lookup_get - returns scmd entry |
| 924 | * @ioc: per adapter object |
| 925 | * @smid: system request message index |
| 926 | * |
| 927 | * Returns the smid stored scmd pointer. |
| 928 | */ |
| 929 | static struct scsi_cmnd * |
| 930 | _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 931 | { |
| 932 | return ioc->scsi_lookup[smid - 1].scmd; |
| 933 | } |
| 934 | |
| 935 | /** |
| 936 | * _scsih_scsi_lookup_get_clear - returns scmd entry |
| 937 | * @ioc: per adapter object |
| 938 | * @smid: system request message index |
| 939 | * |
| 940 | * Returns the smid stored scmd pointer. |
| 941 | * Then will derefrence the stored scmd pointer. |
| 942 | */ |
| 943 | static inline struct scsi_cmnd * |
| 944 | _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 945 | { |
| 946 | unsigned long flags; |
| 947 | struct scsi_cmnd *scmd; |
| 948 | |
| 949 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 950 | scmd = ioc->scsi_lookup[smid - 1].scmd; |
| 951 | ioc->scsi_lookup[smid - 1].scmd = NULL; |
| 952 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 953 | |
| 954 | return scmd; |
| 955 | } |
| 956 | |
| 957 | /** |
| 958 | * _scsih_scsi_lookup_find_by_scmd - scmd lookup |
| 959 | * @ioc: per adapter object |
| 960 | * @smid: system request message index |
| 961 | * @scmd: pointer to scsi command object |
| 962 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 963 | * |
| 964 | * This will search for a scmd pointer in the scsi_lookup array, |
| 965 | * returning the revelent smid. A returned value of zero means invalid. |
| 966 | */ |
| 967 | static u16 |
| 968 | _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd |
| 969 | *scmd) |
| 970 | { |
| 971 | u16 smid; |
| 972 | unsigned long flags; |
| 973 | int i; |
| 974 | |
| 975 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 976 | smid = 0; |
| 977 | for (i = 0; i < ioc->scsiio_depth; i++) { |
| 978 | if (ioc->scsi_lookup[i].scmd == scmd) { |
| 979 | smid = ioc->scsi_lookup[i].smid; |
| 980 | goto out; |
| 981 | } |
| 982 | } |
| 983 | out: |
| 984 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 985 | return smid; |
| 986 | } |
| 987 | |
| 988 | /** |
| 989 | * _scsih_scsi_lookup_find_by_target - search for matching channel:id |
| 990 | * @ioc: per adapter object |
| 991 | * @id: target id |
| 992 | * @channel: channel |
| 993 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 994 | * |
| 995 | * This will search for a matching channel:id in the scsi_lookup array, |
| 996 | * returning 1 if found. |
| 997 | */ |
| 998 | static u8 |
| 999 | _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id, |
| 1000 | int channel) |
| 1001 | { |
| 1002 | u8 found; |
| 1003 | unsigned long flags; |
| 1004 | int i; |
| 1005 | |
| 1006 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 1007 | found = 0; |
| 1008 | for (i = 0 ; i < ioc->scsiio_depth; i++) { |
| 1009 | if (ioc->scsi_lookup[i].scmd && |
| 1010 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 1011 | ioc->scsi_lookup[i].scmd->device->channel == channel)) { |
| 1012 | found = 1; |
| 1013 | goto out; |
| 1014 | } |
| 1015 | } |
| 1016 | out: |
| 1017 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1018 | return found; |
| 1019 | } |
| 1020 | |
| 1021 | /** |
| 1022 | * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun |
| 1023 | * @ioc: per adapter object |
| 1024 | * @id: target id |
| 1025 | * @lun: lun number |
| 1026 | * @channel: channel |
| 1027 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 1028 | * |
| 1029 | * This will search for a matching channel:id:lun in the scsi_lookup array, |
| 1030 | * returning 1 if found. |
| 1031 | */ |
| 1032 | static u8 |
| 1033 | _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id, |
| 1034 | unsigned int lun, int channel) |
| 1035 | { |
| 1036 | u8 found; |
| 1037 | unsigned long flags; |
| 1038 | int i; |
| 1039 | |
| 1040 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 1041 | found = 0; |
| 1042 | for (i = 0 ; i < ioc->scsiio_depth; i++) { |
| 1043 | if (ioc->scsi_lookup[i].scmd && |
| 1044 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 1045 | ioc->scsi_lookup[i].scmd->device->channel == channel && |
| 1046 | ioc->scsi_lookup[i].scmd->device->lun == lun)) { |
| 1047 | found = 1; |
| 1048 | goto out; |
| 1049 | } |
| 1050 | } |
| 1051 | out: |
| 1052 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1053 | return found; |
| 1054 | } |
| 1055 | |
| 1056 | |
| 1057 | static void |
| 1058 | _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth) |
| 1059 | { |
| 1060 | struct Scsi_Host *shost = sdev->host; |
| 1061 | int max_depth; |
| 1062 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 1063 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 1064 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 1065 | struct _sas_device *sas_device; |
| 1066 | unsigned long flags; |
| 1067 | |
| 1068 | max_depth = shost->can_queue; |
| 1069 | |
| 1070 | /* limit max device queue for SATA to 32 */ |
| 1071 | sas_device_priv_data = sdev->hostdata; |
| 1072 | if (!sas_device_priv_data) |
| 1073 | goto not_sata; |
| 1074 | sas_target_priv_data = sas_device_priv_data->sas_target; |
| 1075 | if (!sas_target_priv_data) |
| 1076 | goto not_sata; |
| 1077 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) |
| 1078 | goto not_sata; |
| 1079 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1080 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1081 | sas_device_priv_data->sas_target->sas_address); |
| 1082 | if (sas_device && sas_device->device_info & |
| 1083 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1084 | max_depth = MPT3SAS_SATA_QUEUE_DEPTH; |
| 1085 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1086 | |
| 1087 | not_sata: |
| 1088 | |
| 1089 | if (!sdev->tagged_supported) |
| 1090 | max_depth = 1; |
| 1091 | if (qdepth > max_depth) |
| 1092 | qdepth = max_depth; |
| 1093 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); |
| 1094 | } |
| 1095 | |
| 1096 | /** |
| 1097 | * _scsih_change_queue_depth - setting device queue depth |
| 1098 | * @sdev: scsi device struct |
| 1099 | * @qdepth: requested queue depth |
| 1100 | * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP |
| 1101 | * (see include/scsi/scsi_host.h for definition) |
| 1102 | * |
| 1103 | * Returns queue depth. |
| 1104 | */ |
| 1105 | static int |
| 1106 | _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) |
| 1107 | { |
| 1108 | if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP) |
| 1109 | _scsih_adjust_queue_depth(sdev, qdepth); |
| 1110 | else if (reason == SCSI_QDEPTH_QFULL) |
| 1111 | scsi_track_queue_full(sdev, qdepth); |
| 1112 | else |
| 1113 | return -EOPNOTSUPP; |
| 1114 | |
| 1115 | if (sdev->inquiry_len > 7) |
| 1116 | sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " \ |
| 1117 | "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n", |
| 1118 | sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags, |
| 1119 | sdev->ordered_tags, sdev->scsi_level, |
| 1120 | (sdev->inquiry[7] & 2) >> 1); |
| 1121 | |
| 1122 | return sdev->queue_depth; |
| 1123 | } |
| 1124 | |
| 1125 | /** |
| 1126 | * _scsih_change_queue_type - changing device queue tag type |
| 1127 | * @sdev: scsi device struct |
| 1128 | * @tag_type: requested tag type |
| 1129 | * |
| 1130 | * Returns queue tag type. |
| 1131 | */ |
| 1132 | static int |
| 1133 | _scsih_change_queue_type(struct scsi_device *sdev, int tag_type) |
| 1134 | { |
| 1135 | if (sdev->tagged_supported) { |
| 1136 | scsi_set_tag_type(sdev, tag_type); |
| 1137 | if (tag_type) |
| 1138 | scsi_activate_tcq(sdev, sdev->queue_depth); |
| 1139 | else |
| 1140 | scsi_deactivate_tcq(sdev, sdev->queue_depth); |
| 1141 | } else |
| 1142 | tag_type = 0; |
| 1143 | |
| 1144 | return tag_type; |
| 1145 | } |
| 1146 | |
| 1147 | |
| 1148 | /** |
| 1149 | * _scsih_target_alloc - target add routine |
| 1150 | * @starget: scsi target struct |
| 1151 | * |
| 1152 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1153 | * the device is ignored. |
| 1154 | */ |
| 1155 | static int |
| 1156 | _scsih_target_alloc(struct scsi_target *starget) |
| 1157 | { |
| 1158 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1159 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 1160 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 1161 | struct _sas_device *sas_device; |
| 1162 | struct _raid_device *raid_device; |
| 1163 | unsigned long flags; |
| 1164 | struct sas_rphy *rphy; |
| 1165 | |
| 1166 | sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL); |
| 1167 | if (!sas_target_priv_data) |
| 1168 | return -ENOMEM; |
| 1169 | |
| 1170 | starget->hostdata = sas_target_priv_data; |
| 1171 | sas_target_priv_data->starget = starget; |
| 1172 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; |
| 1173 | |
| 1174 | /* RAID volumes */ |
| 1175 | if (starget->channel == RAID_CHANNEL) { |
| 1176 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1177 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1178 | starget->channel); |
| 1179 | if (raid_device) { |
| 1180 | sas_target_priv_data->handle = raid_device->handle; |
| 1181 | sas_target_priv_data->sas_address = raid_device->wwid; |
| 1182 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; |
| 1183 | raid_device->starget = starget; |
| 1184 | } |
| 1185 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1186 | return 0; |
| 1187 | } |
| 1188 | |
| 1189 | /* sas/sata devices */ |
| 1190 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1191 | rphy = dev_to_rphy(starget->dev.parent); |
| 1192 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1193 | rphy->identify.sas_address); |
| 1194 | |
| 1195 | if (sas_device) { |
| 1196 | sas_target_priv_data->handle = sas_device->handle; |
| 1197 | sas_target_priv_data->sas_address = sas_device->sas_address; |
| 1198 | sas_device->starget = starget; |
| 1199 | sas_device->id = starget->id; |
| 1200 | sas_device->channel = starget->channel; |
| 1201 | if (test_bit(sas_device->handle, ioc->pd_handles)) |
| 1202 | sas_target_priv_data->flags |= |
| 1203 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 1204 | if (sas_device->fast_path) |
| 1205 | sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO; |
| 1206 | } |
| 1207 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1208 | |
| 1209 | return 0; |
| 1210 | } |
| 1211 | |
| 1212 | /** |
| 1213 | * _scsih_target_destroy - target destroy routine |
| 1214 | * @starget: scsi target struct |
| 1215 | * |
| 1216 | * Returns nothing. |
| 1217 | */ |
| 1218 | static void |
| 1219 | _scsih_target_destroy(struct scsi_target *starget) |
| 1220 | { |
| 1221 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1222 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 1223 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 1224 | struct _sas_device *sas_device; |
| 1225 | struct _raid_device *raid_device; |
| 1226 | unsigned long flags; |
| 1227 | struct sas_rphy *rphy; |
| 1228 | |
| 1229 | sas_target_priv_data = starget->hostdata; |
| 1230 | if (!sas_target_priv_data) |
| 1231 | return; |
| 1232 | |
| 1233 | if (starget->channel == RAID_CHANNEL) { |
| 1234 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1235 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1236 | starget->channel); |
| 1237 | if (raid_device) { |
| 1238 | raid_device->starget = NULL; |
| 1239 | raid_device->sdev = NULL; |
| 1240 | } |
| 1241 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1242 | goto out; |
| 1243 | } |
| 1244 | |
| 1245 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1246 | rphy = dev_to_rphy(starget->dev.parent); |
| 1247 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1248 | rphy->identify.sas_address); |
| 1249 | if (sas_device && (sas_device->starget == starget) && |
| 1250 | (sas_device->id == starget->id) && |
| 1251 | (sas_device->channel == starget->channel)) |
| 1252 | sas_device->starget = NULL; |
| 1253 | |
| 1254 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1255 | |
| 1256 | out: |
| 1257 | kfree(sas_target_priv_data); |
| 1258 | starget->hostdata = NULL; |
| 1259 | } |
| 1260 | |
| 1261 | /** |
| 1262 | * _scsih_slave_alloc - device add routine |
| 1263 | * @sdev: scsi device struct |
| 1264 | * |
| 1265 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1266 | * the device is ignored. |
| 1267 | */ |
| 1268 | static int |
| 1269 | _scsih_slave_alloc(struct scsi_device *sdev) |
| 1270 | { |
| 1271 | struct Scsi_Host *shost; |
| 1272 | struct MPT3SAS_ADAPTER *ioc; |
| 1273 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 1274 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 1275 | struct scsi_target *starget; |
| 1276 | struct _raid_device *raid_device; |
Sreekanth Reddy | b65cfed | 2013-06-29 03:52:03 +0530 | [diff] [blame] | 1277 | struct _sas_device *sas_device; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1278 | unsigned long flags; |
| 1279 | |
| 1280 | sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL); |
| 1281 | if (!sas_device_priv_data) |
| 1282 | return -ENOMEM; |
| 1283 | |
| 1284 | sas_device_priv_data->lun = sdev->lun; |
| 1285 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; |
| 1286 | |
| 1287 | starget = scsi_target(sdev); |
| 1288 | sas_target_priv_data = starget->hostdata; |
| 1289 | sas_target_priv_data->num_luns++; |
| 1290 | sas_device_priv_data->sas_target = sas_target_priv_data; |
| 1291 | sdev->hostdata = sas_device_priv_data; |
| 1292 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) |
| 1293 | sdev->no_uld_attach = 1; |
| 1294 | |
| 1295 | shost = dev_to_shost(&starget->dev); |
| 1296 | ioc = shost_priv(shost); |
| 1297 | if (starget->channel == RAID_CHANNEL) { |
| 1298 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1299 | raid_device = _scsih_raid_device_find_by_id(ioc, |
| 1300 | starget->id, starget->channel); |
| 1301 | if (raid_device) |
| 1302 | raid_device->sdev = sdev; /* raid is single lun */ |
| 1303 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1304 | } |
| 1305 | |
Sreekanth Reddy | b65cfed | 2013-06-29 03:52:03 +0530 | [diff] [blame] | 1306 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
| 1307 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1308 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1309 | sas_target_priv_data->sas_address); |
| 1310 | if (sas_device && (sas_device->starget == NULL)) { |
| 1311 | sdev_printk(KERN_INFO, sdev, |
| 1312 | "%s : sas_device->starget set to starget @ %d\n", |
| 1313 | __func__, __LINE__); |
| 1314 | sas_device->starget = starget; |
| 1315 | } |
| 1316 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1317 | } |
| 1318 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1319 | return 0; |
| 1320 | } |
| 1321 | |
| 1322 | /** |
| 1323 | * _scsih_slave_destroy - device destroy routine |
| 1324 | * @sdev: scsi device struct |
| 1325 | * |
| 1326 | * Returns nothing. |
| 1327 | */ |
| 1328 | static void |
| 1329 | _scsih_slave_destroy(struct scsi_device *sdev) |
| 1330 | { |
| 1331 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 1332 | struct scsi_target *starget; |
| 1333 | struct Scsi_Host *shost; |
| 1334 | struct MPT3SAS_ADAPTER *ioc; |
| 1335 | struct _sas_device *sas_device; |
| 1336 | unsigned long flags; |
| 1337 | |
| 1338 | if (!sdev->hostdata) |
| 1339 | return; |
| 1340 | |
| 1341 | starget = scsi_target(sdev); |
| 1342 | sas_target_priv_data = starget->hostdata; |
| 1343 | sas_target_priv_data->num_luns--; |
| 1344 | |
| 1345 | shost = dev_to_shost(&starget->dev); |
| 1346 | ioc = shost_priv(shost); |
| 1347 | |
| 1348 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
| 1349 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1350 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1351 | sas_target_priv_data->sas_address); |
| 1352 | if (sas_device && !sas_target_priv_data->num_luns) |
| 1353 | sas_device->starget = NULL; |
| 1354 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1355 | } |
| 1356 | |
| 1357 | kfree(sdev->hostdata); |
| 1358 | sdev->hostdata = NULL; |
| 1359 | } |
| 1360 | |
| 1361 | /** |
| 1362 | * _scsih_display_sata_capabilities - sata capabilities |
| 1363 | * @ioc: per adapter object |
| 1364 | * @handle: device handle |
| 1365 | * @sdev: scsi device struct |
| 1366 | */ |
| 1367 | static void |
| 1368 | _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc, |
| 1369 | u16 handle, struct scsi_device *sdev) |
| 1370 | { |
| 1371 | Mpi2ConfigReply_t mpi_reply; |
| 1372 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1373 | u32 ioc_status; |
| 1374 | u16 flags; |
| 1375 | u32 device_info; |
| 1376 | |
| 1377 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 1378 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 1379 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 1380 | ioc->name, __FILE__, __LINE__, __func__); |
| 1381 | return; |
| 1382 | } |
| 1383 | |
| 1384 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1385 | MPI2_IOCSTATUS_MASK; |
| 1386 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 1387 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 1388 | ioc->name, __FILE__, __LINE__, __func__); |
| 1389 | return; |
| 1390 | } |
| 1391 | |
| 1392 | flags = le16_to_cpu(sas_device_pg0.Flags); |
| 1393 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 1394 | |
| 1395 | sdev_printk(KERN_INFO, sdev, |
| 1396 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " |
| 1397 | "sw_preserve(%s)\n", |
| 1398 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", |
| 1399 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", |
| 1400 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : |
| 1401 | "n", |
| 1402 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", |
| 1403 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", |
| 1404 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); |
| 1405 | } |
| 1406 | |
| 1407 | /* |
| 1408 | * raid transport support - |
| 1409 | * Enabled for SLES11 and newer, in older kernels the driver will panic when |
| 1410 | * unloading the driver followed by a load - I beleive that the subroutine |
| 1411 | * raid_class_release() is not cleaning up properly. |
| 1412 | */ |
| 1413 | |
| 1414 | /** |
| 1415 | * _scsih_is_raid - return boolean indicating device is raid volume |
| 1416 | * @dev the device struct object |
| 1417 | */ |
| 1418 | static int |
| 1419 | _scsih_is_raid(struct device *dev) |
| 1420 | { |
| 1421 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1422 | |
| 1423 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
| 1424 | } |
| 1425 | |
| 1426 | /** |
| 1427 | * _scsih_get_resync - get raid volume resync percent complete |
| 1428 | * @dev the device struct object |
| 1429 | */ |
| 1430 | static void |
| 1431 | _scsih_get_resync(struct device *dev) |
| 1432 | { |
| 1433 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1434 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1435 | static struct _raid_device *raid_device; |
| 1436 | unsigned long flags; |
| 1437 | Mpi2RaidVolPage0_t vol_pg0; |
| 1438 | Mpi2ConfigReply_t mpi_reply; |
| 1439 | u32 volume_status_flags; |
| 1440 | u8 percent_complete; |
| 1441 | u16 handle; |
| 1442 | |
| 1443 | percent_complete = 0; |
| 1444 | handle = 0; |
| 1445 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1446 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1447 | sdev->channel); |
| 1448 | if (raid_device) { |
| 1449 | handle = raid_device->handle; |
| 1450 | percent_complete = raid_device->percent_complete; |
| 1451 | } |
| 1452 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1453 | |
| 1454 | if (!handle) |
| 1455 | goto out; |
| 1456 | |
| 1457 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, |
| 1458 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 1459 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1460 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 1461 | ioc->name, __FILE__, __LINE__, __func__); |
| 1462 | percent_complete = 0; |
| 1463 | goto out; |
| 1464 | } |
| 1465 | |
| 1466 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
| 1467 | if (!(volume_status_flags & |
| 1468 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) |
| 1469 | percent_complete = 0; |
| 1470 | |
| 1471 | out: |
| 1472 | raid_set_resync(mpt3sas_raid_template, dev, percent_complete); |
| 1473 | } |
| 1474 | |
| 1475 | /** |
| 1476 | * _scsih_get_state - get raid volume level |
| 1477 | * @dev the device struct object |
| 1478 | */ |
| 1479 | static void |
| 1480 | _scsih_get_state(struct device *dev) |
| 1481 | { |
| 1482 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1483 | struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1484 | static struct _raid_device *raid_device; |
| 1485 | unsigned long flags; |
| 1486 | Mpi2RaidVolPage0_t vol_pg0; |
| 1487 | Mpi2ConfigReply_t mpi_reply; |
| 1488 | u32 volstate; |
| 1489 | enum raid_state state = RAID_STATE_UNKNOWN; |
| 1490 | u16 handle = 0; |
| 1491 | |
| 1492 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1493 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1494 | sdev->channel); |
| 1495 | if (raid_device) |
| 1496 | handle = raid_device->handle; |
| 1497 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1498 | |
| 1499 | if (!raid_device) |
| 1500 | goto out; |
| 1501 | |
| 1502 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, |
| 1503 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 1504 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1505 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 1506 | ioc->name, __FILE__, __LINE__, __func__); |
| 1507 | goto out; |
| 1508 | } |
| 1509 | |
| 1510 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
| 1511 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { |
| 1512 | state = RAID_STATE_RESYNCING; |
| 1513 | goto out; |
| 1514 | } |
| 1515 | |
| 1516 | switch (vol_pg0.VolumeState) { |
| 1517 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
| 1518 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 1519 | state = RAID_STATE_ACTIVE; |
| 1520 | break; |
| 1521 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 1522 | state = RAID_STATE_DEGRADED; |
| 1523 | break; |
| 1524 | case MPI2_RAID_VOL_STATE_FAILED: |
| 1525 | case MPI2_RAID_VOL_STATE_MISSING: |
| 1526 | state = RAID_STATE_OFFLINE; |
| 1527 | break; |
| 1528 | } |
| 1529 | out: |
| 1530 | raid_set_state(mpt3sas_raid_template, dev, state); |
| 1531 | } |
| 1532 | |
| 1533 | /** |
| 1534 | * _scsih_set_level - set raid level |
| 1535 | * @sdev: scsi device struct |
| 1536 | * @volume_type: volume type |
| 1537 | */ |
| 1538 | static void |
| 1539 | _scsih_set_level(struct scsi_device *sdev, u8 volume_type) |
| 1540 | { |
| 1541 | enum raid_level level = RAID_LEVEL_UNKNOWN; |
| 1542 | |
| 1543 | switch (volume_type) { |
| 1544 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 1545 | level = RAID_LEVEL_0; |
| 1546 | break; |
| 1547 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 1548 | level = RAID_LEVEL_10; |
| 1549 | break; |
| 1550 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 1551 | level = RAID_LEVEL_1E; |
| 1552 | break; |
| 1553 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 1554 | level = RAID_LEVEL_1; |
| 1555 | break; |
| 1556 | } |
| 1557 | |
| 1558 | raid_set_level(mpt3sas_raid_template, &sdev->sdev_gendev, level); |
| 1559 | } |
| 1560 | |
| 1561 | |
| 1562 | /** |
| 1563 | * _scsih_get_volume_capabilities - volume capabilities |
| 1564 | * @ioc: per adapter object |
| 1565 | * @sas_device: the raid_device object |
| 1566 | * |
| 1567 | * Returns 0 for success, else 1 |
| 1568 | */ |
| 1569 | static int |
| 1570 | _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc, |
| 1571 | struct _raid_device *raid_device) |
| 1572 | { |
| 1573 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1574 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1575 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1576 | Mpi2ConfigReply_t mpi_reply; |
| 1577 | u16 sz; |
| 1578 | u8 num_pds; |
| 1579 | |
| 1580 | if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle, |
| 1581 | &num_pds)) || !num_pds) { |
| 1582 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT |
| 1583 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1584 | __func__)); |
| 1585 | return 1; |
| 1586 | } |
| 1587 | |
| 1588 | raid_device->num_pds = num_pds; |
| 1589 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1590 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1591 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1592 | if (!vol_pg0) { |
| 1593 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT |
| 1594 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1595 | __func__)); |
| 1596 | return 1; |
| 1597 | } |
| 1598 | |
| 1599 | if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1600 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
| 1601 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT |
| 1602 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1603 | __func__)); |
| 1604 | kfree(vol_pg0); |
| 1605 | return 1; |
| 1606 | } |
| 1607 | |
| 1608 | raid_device->volume_type = vol_pg0->VolumeType; |
| 1609 | |
| 1610 | /* figure out what the underlying devices are by |
| 1611 | * obtaining the device_info bits for the 1st device |
| 1612 | */ |
| 1613 | if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1614 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1615 | vol_pg0->PhysDisk[0].PhysDiskNum))) { |
| 1616 | if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 1617 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 1618 | le16_to_cpu(pd_pg0.DevHandle)))) { |
| 1619 | raid_device->device_info = |
| 1620 | le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 1621 | } |
| 1622 | } |
| 1623 | |
| 1624 | kfree(vol_pg0); |
| 1625 | return 0; |
| 1626 | } |
| 1627 | |
| 1628 | |
| 1629 | |
| 1630 | /** |
| 1631 | * _scsih_enable_tlr - setting TLR flags |
| 1632 | * @ioc: per adapter object |
| 1633 | * @sdev: scsi device struct |
| 1634 | * |
| 1635 | * Enabling Transaction Layer Retries for tape devices when |
| 1636 | * vpd page 0x90 is present |
| 1637 | * |
| 1638 | */ |
| 1639 | static void |
| 1640 | _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev) |
| 1641 | { |
| 1642 | |
| 1643 | /* only for TAPE */ |
| 1644 | if (sdev->type != TYPE_TAPE) |
| 1645 | return; |
| 1646 | |
| 1647 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) |
| 1648 | return; |
| 1649 | |
| 1650 | sas_enable_tlr(sdev); |
| 1651 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", |
| 1652 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); |
| 1653 | return; |
| 1654 | |
| 1655 | } |
| 1656 | |
| 1657 | /** |
| 1658 | * _scsih_slave_configure - device configure routine. |
| 1659 | * @sdev: scsi device struct |
| 1660 | * |
| 1661 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1662 | * the device is ignored. |
| 1663 | */ |
| 1664 | static int |
| 1665 | _scsih_slave_configure(struct scsi_device *sdev) |
| 1666 | { |
| 1667 | struct Scsi_Host *shost = sdev->host; |
| 1668 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 1669 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 1670 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 1671 | struct _sas_device *sas_device; |
| 1672 | struct _raid_device *raid_device; |
| 1673 | unsigned long flags; |
| 1674 | int qdepth; |
| 1675 | u8 ssp_target = 0; |
| 1676 | char *ds = ""; |
| 1677 | char *r_level = ""; |
| 1678 | u16 handle, volume_handle = 0; |
| 1679 | u64 volume_wwid = 0; |
| 1680 | |
| 1681 | qdepth = 1; |
| 1682 | sas_device_priv_data = sdev->hostdata; |
| 1683 | sas_device_priv_data->configured_lun = 1; |
| 1684 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; |
| 1685 | sas_target_priv_data = sas_device_priv_data->sas_target; |
| 1686 | handle = sas_target_priv_data->handle; |
| 1687 | |
| 1688 | /* raid volume handling */ |
| 1689 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 1690 | |
| 1691 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1692 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 1693 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1694 | if (!raid_device) { |
| 1695 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT |
| 1696 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 1697 | __LINE__, __func__)); |
| 1698 | return 1; |
| 1699 | } |
| 1700 | |
| 1701 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { |
| 1702 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT |
| 1703 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 1704 | __LINE__, __func__)); |
| 1705 | return 1; |
| 1706 | } |
| 1707 | |
| 1708 | |
| 1709 | /* RAID Queue Depth Support |
| 1710 | * IS volume = underlying qdepth of drive type, either |
| 1711 | * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH |
| 1712 | * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH) |
| 1713 | */ |
| 1714 | if (raid_device->device_info & |
| 1715 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 1716 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; |
| 1717 | ds = "SSP"; |
| 1718 | } else { |
| 1719 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; |
| 1720 | if (raid_device->device_info & |
| 1721 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1722 | ds = "SATA"; |
| 1723 | else |
| 1724 | ds = "STP"; |
| 1725 | } |
| 1726 | |
| 1727 | switch (raid_device->volume_type) { |
| 1728 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 1729 | r_level = "RAID0"; |
| 1730 | break; |
| 1731 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 1732 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; |
| 1733 | if (ioc->manu_pg10.OEMIdentifier && |
| 1734 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & |
| 1735 | MFG10_GF0_R10_DISPLAY) && |
| 1736 | !(raid_device->num_pds % 2)) |
| 1737 | r_level = "RAID10"; |
| 1738 | else |
| 1739 | r_level = "RAID1E"; |
| 1740 | break; |
| 1741 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 1742 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; |
| 1743 | r_level = "RAID1"; |
| 1744 | break; |
| 1745 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 1746 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; |
| 1747 | r_level = "RAID10"; |
| 1748 | break; |
| 1749 | case MPI2_RAID_VOL_TYPE_UNKNOWN: |
| 1750 | default: |
| 1751 | qdepth = MPT3SAS_RAID_QUEUE_DEPTH; |
| 1752 | r_level = "RAIDX"; |
| 1753 | break; |
| 1754 | } |
| 1755 | |
| 1756 | sdev_printk(KERN_INFO, sdev, |
| 1757 | "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n", |
| 1758 | r_level, raid_device->handle, |
| 1759 | (unsigned long long)raid_device->wwid, |
| 1760 | raid_device->num_pds, ds); |
| 1761 | |
| 1762 | |
| 1763 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); |
| 1764 | |
| 1765 | /* raid transport support */ |
| 1766 | _scsih_set_level(sdev, raid_device->volume_type); |
| 1767 | return 0; |
| 1768 | } |
| 1769 | |
| 1770 | /* non-raid handling */ |
| 1771 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 1772 | if (mpt3sas_config_get_volume_handle(ioc, handle, |
| 1773 | &volume_handle)) { |
| 1774 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT |
| 1775 | "failure at %s:%d/%s()!\n", ioc->name, |
| 1776 | __FILE__, __LINE__, __func__)); |
| 1777 | return 1; |
| 1778 | } |
| 1779 | if (volume_handle && mpt3sas_config_get_volume_wwid(ioc, |
| 1780 | volume_handle, &volume_wwid)) { |
| 1781 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT |
| 1782 | "failure at %s:%d/%s()!\n", ioc->name, |
| 1783 | __FILE__, __LINE__, __func__)); |
| 1784 | return 1; |
| 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1789 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1790 | sas_device_priv_data->sas_target->sas_address); |
| 1791 | if (!sas_device) { |
| 1792 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1793 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT |
| 1794 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1795 | __func__)); |
| 1796 | return 1; |
| 1797 | } |
| 1798 | |
| 1799 | sas_device->volume_handle = volume_handle; |
| 1800 | sas_device->volume_wwid = volume_wwid; |
| 1801 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 1802 | qdepth = MPT3SAS_SAS_QUEUE_DEPTH; |
| 1803 | ssp_target = 1; |
| 1804 | ds = "SSP"; |
| 1805 | } else { |
| 1806 | qdepth = MPT3SAS_SATA_QUEUE_DEPTH; |
| 1807 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
| 1808 | ds = "STP"; |
| 1809 | else if (sas_device->device_info & |
| 1810 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1811 | ds = "SATA"; |
| 1812 | } |
| 1813 | |
| 1814 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \ |
| 1815 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", |
| 1816 | ds, handle, (unsigned long long)sas_device->sas_address, |
| 1817 | sas_device->phy, (unsigned long long)sas_device->device_name); |
| 1818 | sdev_printk(KERN_INFO, sdev, |
| 1819 | "%s: enclosure_logical_id(0x%016llx), slot(%d)\n", |
| 1820 | ds, (unsigned long long) |
| 1821 | sas_device->enclosure_logical_id, sas_device->slot); |
| 1822 | |
| 1823 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1824 | |
| 1825 | if (!ssp_target) |
| 1826 | _scsih_display_sata_capabilities(ioc, handle, sdev); |
| 1827 | |
| 1828 | |
| 1829 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); |
| 1830 | |
| 1831 | if (ssp_target) { |
| 1832 | sas_read_port_mode_page(sdev); |
| 1833 | _scsih_enable_tlr(ioc, sdev); |
| 1834 | } |
| 1835 | |
| 1836 | return 0; |
| 1837 | } |
| 1838 | |
| 1839 | /** |
| 1840 | * _scsih_bios_param - fetch head, sector, cylinder info for a disk |
| 1841 | * @sdev: scsi device struct |
| 1842 | * @bdev: pointer to block device context |
| 1843 | * @capacity: device size (in 512 byte sectors) |
| 1844 | * @params: three element array to place output: |
| 1845 | * params[0] number of heads (max 255) |
| 1846 | * params[1] number of sectors (max 63) |
| 1847 | * params[2] number of cylinders |
| 1848 | * |
| 1849 | * Return nothing. |
| 1850 | */ |
| 1851 | static int |
| 1852 | _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
| 1853 | sector_t capacity, int params[]) |
| 1854 | { |
| 1855 | int heads; |
| 1856 | int sectors; |
| 1857 | sector_t cylinders; |
| 1858 | ulong dummy; |
| 1859 | |
| 1860 | heads = 64; |
| 1861 | sectors = 32; |
| 1862 | |
| 1863 | dummy = heads * sectors; |
| 1864 | cylinders = capacity; |
| 1865 | sector_div(cylinders, dummy); |
| 1866 | |
| 1867 | /* |
| 1868 | * Handle extended translation size for logical drives |
| 1869 | * > 1Gb |
| 1870 | */ |
| 1871 | if ((ulong)capacity >= 0x200000) { |
| 1872 | heads = 255; |
| 1873 | sectors = 63; |
| 1874 | dummy = heads * sectors; |
| 1875 | cylinders = capacity; |
| 1876 | sector_div(cylinders, dummy); |
| 1877 | } |
| 1878 | |
| 1879 | /* return result */ |
| 1880 | params[0] = heads; |
| 1881 | params[1] = sectors; |
| 1882 | params[2] = cylinders; |
| 1883 | |
| 1884 | return 0; |
| 1885 | } |
| 1886 | |
| 1887 | /** |
| 1888 | * _scsih_response_code - translation of device response code |
| 1889 | * @ioc: per adapter object |
| 1890 | * @response_code: response code returned by the device |
| 1891 | * |
| 1892 | * Return nothing. |
| 1893 | */ |
| 1894 | static void |
| 1895 | _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code) |
| 1896 | { |
| 1897 | char *desc; |
| 1898 | |
| 1899 | switch (response_code) { |
| 1900 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: |
| 1901 | desc = "task management request completed"; |
| 1902 | break; |
| 1903 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: |
| 1904 | desc = "invalid frame"; |
| 1905 | break; |
| 1906 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: |
| 1907 | desc = "task management request not supported"; |
| 1908 | break; |
| 1909 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: |
| 1910 | desc = "task management request failed"; |
| 1911 | break; |
| 1912 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: |
| 1913 | desc = "task management request succeeded"; |
| 1914 | break; |
| 1915 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: |
| 1916 | desc = "invalid lun"; |
| 1917 | break; |
| 1918 | case 0xA: |
| 1919 | desc = "overlapped tag attempted"; |
| 1920 | break; |
| 1921 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: |
| 1922 | desc = "task queued, however not sent to target"; |
| 1923 | break; |
| 1924 | default: |
| 1925 | desc = "unknown"; |
| 1926 | break; |
| 1927 | } |
| 1928 | pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n", |
| 1929 | ioc->name, response_code, desc); |
| 1930 | } |
| 1931 | |
| 1932 | /** |
| 1933 | * _scsih_tm_done - tm completion routine |
| 1934 | * @ioc: per adapter object |
| 1935 | * @smid: system request message index |
| 1936 | * @msix_index: MSIX table index supplied by the OS |
| 1937 | * @reply: reply message frame(lower 32bit addr) |
| 1938 | * Context: none. |
| 1939 | * |
| 1940 | * The callback handler when using scsih_issue_tm. |
| 1941 | * |
| 1942 | * Return 1 meaning mf should be freed from _base_interrupt |
| 1943 | * 0 means the mf is freed from this function. |
| 1944 | */ |
| 1945 | static u8 |
| 1946 | _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) |
| 1947 | { |
| 1948 | MPI2DefaultReply_t *mpi_reply; |
| 1949 | |
| 1950 | if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED) |
| 1951 | return 1; |
| 1952 | if (ioc->tm_cmds.smid != smid) |
| 1953 | return 1; |
| 1954 | mpt3sas_base_flush_reply_queues(ioc); |
| 1955 | ioc->tm_cmds.status |= MPT3_CMD_COMPLETE; |
| 1956 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 1957 | if (mpi_reply) { |
| 1958 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 1959 | ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID; |
| 1960 | } |
| 1961 | ioc->tm_cmds.status &= ~MPT3_CMD_PENDING; |
| 1962 | complete(&ioc->tm_cmds.done); |
| 1963 | return 1; |
| 1964 | } |
| 1965 | |
| 1966 | /** |
| 1967 | * mpt3sas_scsih_set_tm_flag - set per target tm_busy |
| 1968 | * @ioc: per adapter object |
| 1969 | * @handle: device handle |
| 1970 | * |
| 1971 | * During taskmangement request, we need to freeze the device queue. |
| 1972 | */ |
| 1973 | void |
| 1974 | mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 1975 | { |
| 1976 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 1977 | struct scsi_device *sdev; |
| 1978 | u8 skip = 0; |
| 1979 | |
| 1980 | shost_for_each_device(sdev, ioc->shost) { |
| 1981 | if (skip) |
| 1982 | continue; |
| 1983 | sas_device_priv_data = sdev->hostdata; |
| 1984 | if (!sas_device_priv_data) |
| 1985 | continue; |
| 1986 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 1987 | sas_device_priv_data->sas_target->tm_busy = 1; |
| 1988 | skip = 1; |
| 1989 | ioc->ignore_loginfos = 1; |
| 1990 | } |
| 1991 | } |
| 1992 | } |
| 1993 | |
| 1994 | /** |
| 1995 | * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy |
| 1996 | * @ioc: per adapter object |
| 1997 | * @handle: device handle |
| 1998 | * |
| 1999 | * During taskmangement request, we need to freeze the device queue. |
| 2000 | */ |
| 2001 | void |
| 2002 | mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 2003 | { |
| 2004 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 2005 | struct scsi_device *sdev; |
| 2006 | u8 skip = 0; |
| 2007 | |
| 2008 | shost_for_each_device(sdev, ioc->shost) { |
| 2009 | if (skip) |
| 2010 | continue; |
| 2011 | sas_device_priv_data = sdev->hostdata; |
| 2012 | if (!sas_device_priv_data) |
| 2013 | continue; |
| 2014 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2015 | sas_device_priv_data->sas_target->tm_busy = 0; |
| 2016 | skip = 1; |
| 2017 | ioc->ignore_loginfos = 0; |
| 2018 | } |
| 2019 | } |
| 2020 | } |
| 2021 | |
| 2022 | /** |
| 2023 | * mpt3sas_scsih_issue_tm - main routine for sending tm requests |
| 2024 | * @ioc: per adapter struct |
| 2025 | * @device_handle: device handle |
| 2026 | * @channel: the channel assigned by the OS |
| 2027 | * @id: the id assigned by the OS |
| 2028 | * @lun: lun number |
| 2029 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) |
| 2030 | * @smid_task: smid assigned to the task |
| 2031 | * @timeout: timeout in seconds |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2032 | * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF |
| 2033 | * Context: user |
| 2034 | * |
| 2035 | * A generic API for sending task management requests to firmware. |
| 2036 | * |
| 2037 | * The callback index is set inside `ioc->tm_cb_idx`. |
| 2038 | * |
| 2039 | * Return SUCCESS or FAILED. |
| 2040 | */ |
| 2041 | int |
| 2042 | mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel, |
| 2043 | uint id, uint lun, u8 type, u16 smid_task, ulong timeout, |
Matthew Wilcox | c62e46d | 2014-03-27 16:40:30 -0400 | [diff] [blame^] | 2044 | enum mutex_type m_type) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2045 | { |
| 2046 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 2047 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
| 2048 | u16 smid = 0; |
| 2049 | u32 ioc_state; |
| 2050 | unsigned long timeleft; |
| 2051 | struct scsiio_tracker *scsi_lookup = NULL; |
| 2052 | int rc; |
| 2053 | |
| 2054 | if (m_type == TM_MUTEX_ON) |
| 2055 | mutex_lock(&ioc->tm_cmds.mutex); |
| 2056 | if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) { |
| 2057 | pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n", |
| 2058 | __func__, ioc->name); |
| 2059 | rc = FAILED; |
| 2060 | goto err_out; |
| 2061 | } |
| 2062 | |
| 2063 | if (ioc->shost_recovery || ioc->remove_host || |
| 2064 | ioc->pci_error_recovery) { |
| 2065 | pr_info(MPT3SAS_FMT "%s: host reset in progress!\n", |
| 2066 | __func__, ioc->name); |
| 2067 | rc = FAILED; |
| 2068 | goto err_out; |
| 2069 | } |
| 2070 | |
| 2071 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); |
| 2072 | if (ioc_state & MPI2_DOORBELL_USED) { |
| 2073 | dhsprintk(ioc, pr_info(MPT3SAS_FMT |
| 2074 | "unexpected doorbell active!\n", ioc->name)); |
| 2075 | rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2076 | FORCE_BIG_HAMMER); |
| 2077 | rc = (!rc) ? SUCCESS : FAILED; |
| 2078 | goto err_out; |
| 2079 | } |
| 2080 | |
| 2081 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 2082 | mpt3sas_base_fault_info(ioc, ioc_state & |
| 2083 | MPI2_DOORBELL_DATA_MASK); |
| 2084 | rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2085 | FORCE_BIG_HAMMER); |
| 2086 | rc = (!rc) ? SUCCESS : FAILED; |
| 2087 | goto err_out; |
| 2088 | } |
| 2089 | |
| 2090 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); |
| 2091 | if (!smid) { |
| 2092 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 2093 | ioc->name, __func__); |
| 2094 | rc = FAILED; |
| 2095 | goto err_out; |
| 2096 | } |
| 2097 | |
| 2098 | if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) |
| 2099 | scsi_lookup = &ioc->scsi_lookup[smid_task - 1]; |
| 2100 | |
| 2101 | dtmprintk(ioc, pr_info(MPT3SAS_FMT |
| 2102 | "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n", |
| 2103 | ioc->name, handle, type, smid_task)); |
| 2104 | ioc->tm_cmds.status = MPT3_CMD_PENDING; |
| 2105 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 2106 | ioc->tm_cmds.smid = smid; |
| 2107 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 2108 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); |
| 2109 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 2110 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 2111 | mpi_request->TaskType = type; |
| 2112 | mpi_request->TaskMID = cpu_to_le16(smid_task); |
| 2113 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); |
| 2114 | mpt3sas_scsih_set_tm_flag(ioc, handle); |
| 2115 | init_completion(&ioc->tm_cmds.done); |
| 2116 | mpt3sas_base_put_smid_hi_priority(ioc, smid); |
| 2117 | timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
| 2118 | if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) { |
| 2119 | pr_err(MPT3SAS_FMT "%s: timeout\n", |
| 2120 | ioc->name, __func__); |
| 2121 | _debug_dump_mf(mpi_request, |
| 2122 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
| 2123 | if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) { |
| 2124 | rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2125 | FORCE_BIG_HAMMER); |
| 2126 | rc = (!rc) ? SUCCESS : FAILED; |
| 2127 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; |
| 2128 | mpt3sas_scsih_clear_tm_flag(ioc, handle); |
| 2129 | goto err_out; |
| 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) { |
| 2134 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); |
| 2135 | mpi_reply = ioc->tm_cmds.reply; |
| 2136 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \ |
| 2137 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", |
| 2138 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 2139 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 2140 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 2141 | if (ioc->logging_level & MPT_DEBUG_TM) { |
| 2142 | _scsih_response_code(ioc, mpi_reply->ResponseCode); |
| 2143 | if (mpi_reply->IOCStatus) |
| 2144 | _debug_dump_mf(mpi_request, |
| 2145 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
| 2146 | } |
| 2147 | } |
| 2148 | |
| 2149 | switch (type) { |
| 2150 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: |
| 2151 | rc = SUCCESS; |
| 2152 | if (scsi_lookup->scmd == NULL) |
| 2153 | break; |
| 2154 | rc = FAILED; |
| 2155 | break; |
| 2156 | |
| 2157 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: |
| 2158 | if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) |
| 2159 | rc = FAILED; |
| 2160 | else |
| 2161 | rc = SUCCESS; |
| 2162 | break; |
| 2163 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: |
| 2164 | case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: |
| 2165 | if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) |
| 2166 | rc = FAILED; |
| 2167 | else |
| 2168 | rc = SUCCESS; |
| 2169 | break; |
| 2170 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: |
| 2171 | rc = SUCCESS; |
| 2172 | break; |
| 2173 | default: |
| 2174 | rc = FAILED; |
| 2175 | break; |
| 2176 | } |
| 2177 | |
| 2178 | mpt3sas_scsih_clear_tm_flag(ioc, handle); |
| 2179 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; |
| 2180 | if (m_type == TM_MUTEX_ON) |
| 2181 | mutex_unlock(&ioc->tm_cmds.mutex); |
| 2182 | |
| 2183 | return rc; |
| 2184 | |
| 2185 | err_out: |
| 2186 | if (m_type == TM_MUTEX_ON) |
| 2187 | mutex_unlock(&ioc->tm_cmds.mutex); |
| 2188 | return rc; |
| 2189 | } |
| 2190 | |
| 2191 | /** |
| 2192 | * _scsih_tm_display_info - displays info about the device |
| 2193 | * @ioc: per adapter struct |
| 2194 | * @scmd: pointer to scsi command object |
| 2195 | * |
| 2196 | * Called by task management callback handlers. |
| 2197 | */ |
| 2198 | static void |
| 2199 | _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) |
| 2200 | { |
| 2201 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2202 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; |
| 2203 | struct _sas_device *sas_device = NULL; |
| 2204 | unsigned long flags; |
| 2205 | char *device_str = NULL; |
| 2206 | |
| 2207 | if (!priv_target) |
| 2208 | return; |
| 2209 | device_str = "volume"; |
| 2210 | |
| 2211 | scsi_print_command(scmd); |
| 2212 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 2213 | starget_printk(KERN_INFO, starget, |
| 2214 | "%s handle(0x%04x), %s wwid(0x%016llx)\n", |
| 2215 | device_str, priv_target->handle, |
| 2216 | device_str, (unsigned long long)priv_target->sas_address); |
| 2217 | } else { |
| 2218 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2219 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2220 | priv_target->sas_address); |
| 2221 | if (sas_device) { |
| 2222 | if (priv_target->flags & |
| 2223 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2224 | starget_printk(KERN_INFO, starget, |
| 2225 | "volume handle(0x%04x), " |
| 2226 | "volume wwid(0x%016llx)\n", |
| 2227 | sas_device->volume_handle, |
| 2228 | (unsigned long long)sas_device->volume_wwid); |
| 2229 | } |
| 2230 | starget_printk(KERN_INFO, starget, |
| 2231 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", |
| 2232 | sas_device->handle, |
| 2233 | (unsigned long long)sas_device->sas_address, |
| 2234 | sas_device->phy); |
| 2235 | starget_printk(KERN_INFO, starget, |
| 2236 | "enclosure_logical_id(0x%016llx), slot(%d)\n", |
| 2237 | (unsigned long long)sas_device->enclosure_logical_id, |
| 2238 | sas_device->slot); |
| 2239 | } |
| 2240 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2241 | } |
| 2242 | } |
| 2243 | |
| 2244 | /** |
| 2245 | * _scsih_abort - eh threads main abort routine |
| 2246 | * @scmd: pointer to scsi command object |
| 2247 | * |
| 2248 | * Returns SUCCESS if command aborted else FAILED |
| 2249 | */ |
| 2250 | static int |
| 2251 | _scsih_abort(struct scsi_cmnd *scmd) |
| 2252 | { |
| 2253 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2254 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 2255 | u16 smid; |
| 2256 | u16 handle; |
| 2257 | int r; |
| 2258 | |
| 2259 | sdev_printk(KERN_INFO, scmd->device, |
| 2260 | "attempting task abort! scmd(%p)\n", scmd); |
| 2261 | _scsih_tm_display_info(ioc, scmd); |
| 2262 | |
| 2263 | sas_device_priv_data = scmd->device->hostdata; |
| 2264 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
| 2265 | sdev_printk(KERN_INFO, scmd->device, |
| 2266 | "device been deleted! scmd(%p)\n", scmd); |
| 2267 | scmd->result = DID_NO_CONNECT << 16; |
| 2268 | scmd->scsi_done(scmd); |
| 2269 | r = SUCCESS; |
| 2270 | goto out; |
| 2271 | } |
| 2272 | |
| 2273 | /* search for the command */ |
| 2274 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); |
| 2275 | if (!smid) { |
| 2276 | scmd->result = DID_RESET << 16; |
| 2277 | r = SUCCESS; |
| 2278 | goto out; |
| 2279 | } |
| 2280 | |
| 2281 | /* for hidden raid components and volumes this is not supported */ |
| 2282 | if (sas_device_priv_data->sas_target->flags & |
| 2283 | MPT_TARGET_FLAGS_RAID_COMPONENT || |
| 2284 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 2285 | scmd->result = DID_RESET << 16; |
| 2286 | r = FAILED; |
| 2287 | goto out; |
| 2288 | } |
| 2289 | |
| 2290 | mpt3sas_halt_firmware(ioc); |
| 2291 | |
| 2292 | handle = sas_device_priv_data->sas_target->handle; |
| 2293 | r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2294 | scmd->device->id, scmd->device->lun, |
Matthew Wilcox | c62e46d | 2014-03-27 16:40:30 -0400 | [diff] [blame^] | 2295 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2296 | |
| 2297 | out: |
| 2298 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", |
| 2299 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 2300 | return r; |
| 2301 | } |
| 2302 | |
| 2303 | /** |
| 2304 | * _scsih_dev_reset - eh threads main device reset routine |
| 2305 | * @scmd: pointer to scsi command object |
| 2306 | * |
| 2307 | * Returns SUCCESS if command aborted else FAILED |
| 2308 | */ |
| 2309 | static int |
| 2310 | _scsih_dev_reset(struct scsi_cmnd *scmd) |
| 2311 | { |
| 2312 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2313 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 2314 | struct _sas_device *sas_device; |
| 2315 | unsigned long flags; |
| 2316 | u16 handle; |
| 2317 | int r; |
| 2318 | |
| 2319 | sdev_printk(KERN_INFO, scmd->device, |
| 2320 | "attempting device reset! scmd(%p)\n", scmd); |
| 2321 | _scsih_tm_display_info(ioc, scmd); |
| 2322 | |
| 2323 | sas_device_priv_data = scmd->device->hostdata; |
| 2324 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
| 2325 | sdev_printk(KERN_INFO, scmd->device, |
| 2326 | "device been deleted! scmd(%p)\n", scmd); |
| 2327 | scmd->result = DID_NO_CONNECT << 16; |
| 2328 | scmd->scsi_done(scmd); |
| 2329 | r = SUCCESS; |
| 2330 | goto out; |
| 2331 | } |
| 2332 | |
| 2333 | /* for hidden raid components obtain the volume_handle */ |
| 2334 | handle = 0; |
| 2335 | if (sas_device_priv_data->sas_target->flags & |
| 2336 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2337 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2338 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2339 | sas_device_priv_data->sas_target->handle); |
| 2340 | if (sas_device) |
| 2341 | handle = sas_device->volume_handle; |
| 2342 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2343 | } else |
| 2344 | handle = sas_device_priv_data->sas_target->handle; |
| 2345 | |
| 2346 | if (!handle) { |
| 2347 | scmd->result = DID_RESET << 16; |
| 2348 | r = FAILED; |
| 2349 | goto out; |
| 2350 | } |
| 2351 | |
| 2352 | r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2353 | scmd->device->id, scmd->device->lun, |
Matthew Wilcox | c62e46d | 2014-03-27 16:40:30 -0400 | [diff] [blame^] | 2354 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2355 | |
| 2356 | out: |
| 2357 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", |
| 2358 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 2359 | return r; |
| 2360 | } |
| 2361 | |
| 2362 | /** |
| 2363 | * _scsih_target_reset - eh threads main target reset routine |
| 2364 | * @scmd: pointer to scsi command object |
| 2365 | * |
| 2366 | * Returns SUCCESS if command aborted else FAILED |
| 2367 | */ |
| 2368 | static int |
| 2369 | _scsih_target_reset(struct scsi_cmnd *scmd) |
| 2370 | { |
| 2371 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2372 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 2373 | struct _sas_device *sas_device; |
| 2374 | unsigned long flags; |
| 2375 | u16 handle; |
| 2376 | int r; |
| 2377 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2378 | |
| 2379 | starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n", |
| 2380 | scmd); |
| 2381 | _scsih_tm_display_info(ioc, scmd); |
| 2382 | |
| 2383 | sas_device_priv_data = scmd->device->hostdata; |
| 2384 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
| 2385 | starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n", |
| 2386 | scmd); |
| 2387 | scmd->result = DID_NO_CONNECT << 16; |
| 2388 | scmd->scsi_done(scmd); |
| 2389 | r = SUCCESS; |
| 2390 | goto out; |
| 2391 | } |
| 2392 | |
| 2393 | /* for hidden raid components obtain the volume_handle */ |
| 2394 | handle = 0; |
| 2395 | if (sas_device_priv_data->sas_target->flags & |
| 2396 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2397 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2398 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2399 | sas_device_priv_data->sas_target->handle); |
| 2400 | if (sas_device) |
| 2401 | handle = sas_device->volume_handle; |
| 2402 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2403 | } else |
| 2404 | handle = sas_device_priv_data->sas_target->handle; |
| 2405 | |
| 2406 | if (!handle) { |
| 2407 | scmd->result = DID_RESET << 16; |
| 2408 | r = FAILED; |
| 2409 | goto out; |
| 2410 | } |
| 2411 | |
| 2412 | r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2413 | scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, |
Matthew Wilcox | c62e46d | 2014-03-27 16:40:30 -0400 | [diff] [blame^] | 2414 | 30, TM_MUTEX_ON); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2415 | |
| 2416 | out: |
| 2417 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", |
| 2418 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 2419 | return r; |
| 2420 | } |
| 2421 | |
| 2422 | |
| 2423 | /** |
| 2424 | * _scsih_host_reset - eh threads main host reset routine |
| 2425 | * @scmd: pointer to scsi command object |
| 2426 | * |
| 2427 | * Returns SUCCESS if command aborted else FAILED |
| 2428 | */ |
| 2429 | static int |
| 2430 | _scsih_host_reset(struct scsi_cmnd *scmd) |
| 2431 | { |
| 2432 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2433 | int r, retval; |
| 2434 | |
| 2435 | pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n", |
| 2436 | ioc->name, scmd); |
| 2437 | scsi_print_command(scmd); |
| 2438 | |
| 2439 | retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2440 | FORCE_BIG_HAMMER); |
| 2441 | r = (retval < 0) ? FAILED : SUCCESS; |
| 2442 | pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n", |
| 2443 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 2444 | |
| 2445 | return r; |
| 2446 | } |
| 2447 | |
| 2448 | /** |
| 2449 | * _scsih_fw_event_add - insert and queue up fw_event |
| 2450 | * @ioc: per adapter object |
| 2451 | * @fw_event: object describing the event |
| 2452 | * Context: This function will acquire ioc->fw_event_lock. |
| 2453 | * |
| 2454 | * This adds the firmware event object into link list, then queues it up to |
| 2455 | * be processed from user context. |
| 2456 | * |
| 2457 | * Return nothing. |
| 2458 | */ |
| 2459 | static void |
| 2460 | _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) |
| 2461 | { |
| 2462 | unsigned long flags; |
| 2463 | |
| 2464 | if (ioc->firmware_event_thread == NULL) |
| 2465 | return; |
| 2466 | |
| 2467 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2468 | INIT_LIST_HEAD(&fw_event->list); |
| 2469 | list_add_tail(&fw_event->list, &ioc->fw_event_list); |
| 2470 | INIT_WORK(&fw_event->work, _firmware_event_work); |
| 2471 | queue_work(ioc->firmware_event_thread, &fw_event->work); |
| 2472 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2473 | } |
| 2474 | |
| 2475 | /** |
| 2476 | * _scsih_fw_event_free - delete fw_event |
| 2477 | * @ioc: per adapter object |
| 2478 | * @fw_event: object describing the event |
| 2479 | * Context: This function will acquire ioc->fw_event_lock. |
| 2480 | * |
| 2481 | * This removes firmware event object from link list, frees associated memory. |
| 2482 | * |
| 2483 | * Return nothing. |
| 2484 | */ |
| 2485 | static void |
| 2486 | _scsih_fw_event_free(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work |
| 2487 | *fw_event) |
| 2488 | { |
| 2489 | unsigned long flags; |
| 2490 | |
| 2491 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2492 | list_del(&fw_event->list); |
| 2493 | kfree(fw_event->event_data); |
| 2494 | kfree(fw_event); |
| 2495 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2496 | } |
| 2497 | |
| 2498 | |
| 2499 | /** |
| 2500 | * mpt3sas_send_trigger_data_event - send event for processing trigger data |
| 2501 | * @ioc: per adapter object |
| 2502 | * @event_data: trigger event data |
| 2503 | * |
| 2504 | * Return nothing. |
| 2505 | */ |
| 2506 | void |
| 2507 | mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc, |
| 2508 | struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data) |
| 2509 | { |
| 2510 | struct fw_event_work *fw_event; |
| 2511 | |
| 2512 | if (ioc->is_driver_loading) |
| 2513 | return; |
| 2514 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2515 | if (!fw_event) |
| 2516 | return; |
| 2517 | fw_event->event_data = kzalloc(sizeof(*event_data), GFP_ATOMIC); |
| 2518 | if (!fw_event->event_data) |
| 2519 | return; |
| 2520 | fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG; |
| 2521 | fw_event->ioc = ioc; |
| 2522 | memcpy(fw_event->event_data, event_data, sizeof(*event_data)); |
| 2523 | _scsih_fw_event_add(ioc, fw_event); |
| 2524 | } |
| 2525 | |
| 2526 | /** |
| 2527 | * _scsih_error_recovery_delete_devices - remove devices not responding |
| 2528 | * @ioc: per adapter object |
| 2529 | * |
| 2530 | * Return nothing. |
| 2531 | */ |
| 2532 | static void |
| 2533 | _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc) |
| 2534 | { |
| 2535 | struct fw_event_work *fw_event; |
| 2536 | |
| 2537 | if (ioc->is_driver_loading) |
| 2538 | return; |
| 2539 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2540 | if (!fw_event) |
| 2541 | return; |
| 2542 | fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES; |
| 2543 | fw_event->ioc = ioc; |
| 2544 | _scsih_fw_event_add(ioc, fw_event); |
| 2545 | } |
| 2546 | |
| 2547 | /** |
| 2548 | * mpt3sas_port_enable_complete - port enable completed (fake event) |
| 2549 | * @ioc: per adapter object |
| 2550 | * |
| 2551 | * Return nothing. |
| 2552 | */ |
| 2553 | void |
| 2554 | mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc) |
| 2555 | { |
| 2556 | struct fw_event_work *fw_event; |
| 2557 | |
| 2558 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2559 | if (!fw_event) |
| 2560 | return; |
| 2561 | fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE; |
| 2562 | fw_event->ioc = ioc; |
| 2563 | _scsih_fw_event_add(ioc, fw_event); |
| 2564 | } |
| 2565 | |
| 2566 | /** |
| 2567 | * _scsih_fw_event_cleanup_queue - cleanup event queue |
| 2568 | * @ioc: per adapter object |
| 2569 | * |
| 2570 | * Walk the firmware event queue, either killing timers, or waiting |
| 2571 | * for outstanding events to complete |
| 2572 | * |
| 2573 | * Return nothing. |
| 2574 | */ |
| 2575 | static void |
| 2576 | _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc) |
| 2577 | { |
| 2578 | struct fw_event_work *fw_event, *next; |
| 2579 | |
| 2580 | if (list_empty(&ioc->fw_event_list) || |
| 2581 | !ioc->firmware_event_thread || in_interrupt()) |
| 2582 | return; |
| 2583 | |
| 2584 | list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) { |
| 2585 | if (cancel_delayed_work(&fw_event->delayed_work)) { |
| 2586 | _scsih_fw_event_free(ioc, fw_event); |
| 2587 | continue; |
| 2588 | } |
| 2589 | fw_event->cancel_pending_work = 1; |
| 2590 | } |
| 2591 | } |
| 2592 | |
| 2593 | /** |
| 2594 | * _scsih_ublock_io_all_device - unblock every device |
| 2595 | * @ioc: per adapter object |
| 2596 | * |
| 2597 | * change the device state from block to running |
| 2598 | */ |
| 2599 | static void |
| 2600 | _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc) |
| 2601 | { |
| 2602 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 2603 | struct scsi_device *sdev; |
| 2604 | |
| 2605 | shost_for_each_device(sdev, ioc->shost) { |
| 2606 | sas_device_priv_data = sdev->hostdata; |
| 2607 | if (!sas_device_priv_data) |
| 2608 | continue; |
| 2609 | if (!sas_device_priv_data->block) |
| 2610 | continue; |
| 2611 | |
| 2612 | sas_device_priv_data->block = 0; |
| 2613 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2614 | "device_running, handle(0x%04x)\n", |
| 2615 | sas_device_priv_data->sas_target->handle)); |
| 2616 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); |
| 2617 | } |
| 2618 | } |
| 2619 | |
| 2620 | |
| 2621 | /** |
| 2622 | * _scsih_ublock_io_device - prepare device to be deleted |
| 2623 | * @ioc: per adapter object |
| 2624 | * @sas_addr: sas address |
| 2625 | * |
| 2626 | * unblock then put device in offline state |
| 2627 | */ |
| 2628 | static void |
| 2629 | _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) |
| 2630 | { |
| 2631 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 2632 | struct scsi_device *sdev; |
| 2633 | |
| 2634 | shost_for_each_device(sdev, ioc->shost) { |
| 2635 | sas_device_priv_data = sdev->hostdata; |
| 2636 | if (!sas_device_priv_data) |
| 2637 | continue; |
| 2638 | if (sas_device_priv_data->sas_target->sas_address |
| 2639 | != sas_address) |
| 2640 | continue; |
| 2641 | if (sas_device_priv_data->block) { |
| 2642 | sas_device_priv_data->block = 0; |
| 2643 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); |
| 2644 | } |
| 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | /** |
| 2649 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK |
| 2650 | * @ioc: per adapter object |
| 2651 | * @handle: device handle |
| 2652 | * |
| 2653 | * During device pull we need to appropiately set the sdev state. |
| 2654 | */ |
| 2655 | static void |
| 2656 | _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc) |
| 2657 | { |
| 2658 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 2659 | struct scsi_device *sdev; |
| 2660 | |
| 2661 | shost_for_each_device(sdev, ioc->shost) { |
| 2662 | sas_device_priv_data = sdev->hostdata; |
| 2663 | if (!sas_device_priv_data) |
| 2664 | continue; |
| 2665 | if (sas_device_priv_data->block) |
| 2666 | continue; |
| 2667 | sas_device_priv_data->block = 1; |
| 2668 | scsi_internal_device_block(sdev); |
| 2669 | sdev_printk(KERN_INFO, sdev, "device_blocked, handle(0x%04x)\n", |
| 2670 | sas_device_priv_data->sas_target->handle); |
| 2671 | } |
| 2672 | } |
| 2673 | |
| 2674 | /** |
| 2675 | * _scsih_block_io_device - set the device state to SDEV_BLOCK |
| 2676 | * @ioc: per adapter object |
| 2677 | * @handle: device handle |
| 2678 | * |
| 2679 | * During device pull we need to appropiately set the sdev state. |
| 2680 | */ |
| 2681 | static void |
| 2682 | _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 2683 | { |
| 2684 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 2685 | struct scsi_device *sdev; |
| 2686 | |
| 2687 | shost_for_each_device(sdev, ioc->shost) { |
| 2688 | sas_device_priv_data = sdev->hostdata; |
| 2689 | if (!sas_device_priv_data) |
| 2690 | continue; |
| 2691 | if (sas_device_priv_data->sas_target->handle != handle) |
| 2692 | continue; |
| 2693 | if (sas_device_priv_data->block) |
| 2694 | continue; |
| 2695 | sas_device_priv_data->block = 1; |
| 2696 | scsi_internal_device_block(sdev); |
| 2697 | sdev_printk(KERN_INFO, sdev, |
| 2698 | "device_blocked, handle(0x%04x)\n", handle); |
| 2699 | } |
| 2700 | } |
| 2701 | |
| 2702 | /** |
| 2703 | * _scsih_block_io_to_children_attached_to_ex |
| 2704 | * @ioc: per adapter object |
| 2705 | * @sas_expander: the sas_device object |
| 2706 | * |
| 2707 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 2708 | * attached to this expander. This function called when expander is |
| 2709 | * pulled. |
| 2710 | */ |
| 2711 | static void |
| 2712 | _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc, |
| 2713 | struct _sas_node *sas_expander) |
| 2714 | { |
| 2715 | struct _sas_port *mpt3sas_port; |
| 2716 | struct _sas_device *sas_device; |
| 2717 | struct _sas_node *expander_sibling; |
| 2718 | unsigned long flags; |
| 2719 | |
| 2720 | if (!sas_expander) |
| 2721 | return; |
| 2722 | |
| 2723 | list_for_each_entry(mpt3sas_port, |
| 2724 | &sas_expander->sas_port_list, port_list) { |
| 2725 | if (mpt3sas_port->remote_identify.device_type == |
| 2726 | SAS_END_DEVICE) { |
| 2727 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2728 | sas_device = |
| 2729 | mpt3sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2730 | mpt3sas_port->remote_identify.sas_address); |
| 2731 | if (sas_device) |
| 2732 | set_bit(sas_device->handle, |
| 2733 | ioc->blocking_handles); |
| 2734 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2735 | } |
| 2736 | } |
| 2737 | |
| 2738 | list_for_each_entry(mpt3sas_port, |
| 2739 | &sas_expander->sas_port_list, port_list) { |
| 2740 | |
| 2741 | if (mpt3sas_port->remote_identify.device_type == |
| 2742 | SAS_EDGE_EXPANDER_DEVICE || |
| 2743 | mpt3sas_port->remote_identify.device_type == |
| 2744 | SAS_FANOUT_EXPANDER_DEVICE) { |
| 2745 | expander_sibling = |
| 2746 | mpt3sas_scsih_expander_find_by_sas_address( |
| 2747 | ioc, mpt3sas_port->remote_identify.sas_address); |
| 2748 | _scsih_block_io_to_children_attached_to_ex(ioc, |
| 2749 | expander_sibling); |
| 2750 | } |
| 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | /** |
| 2755 | * _scsih_block_io_to_children_attached_directly |
| 2756 | * @ioc: per adapter object |
| 2757 | * @event_data: topology change event data |
| 2758 | * |
| 2759 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 2760 | * direct attached during device pull. |
| 2761 | */ |
| 2762 | static void |
| 2763 | _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc, |
| 2764 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 2765 | { |
| 2766 | int i; |
| 2767 | u16 handle; |
| 2768 | u16 reason_code; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2769 | |
| 2770 | for (i = 0; i < event_data->NumEntries; i++) { |
| 2771 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 2772 | if (!handle) |
| 2773 | continue; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2774 | reason_code = event_data->PHY[i].PhyStatus & |
| 2775 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 2776 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) |
| 2777 | _scsih_block_io_device(ioc, handle); |
| 2778 | } |
| 2779 | } |
| 2780 | |
| 2781 | /** |
| 2782 | * _scsih_tm_tr_send - send task management request |
| 2783 | * @ioc: per adapter object |
| 2784 | * @handle: device handle |
| 2785 | * Context: interrupt time. |
| 2786 | * |
| 2787 | * This code is to initiate the device removal handshake protocol |
| 2788 | * with controller firmware. This function will issue target reset |
| 2789 | * using high priority request queue. It will send a sas iounit |
| 2790 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. |
| 2791 | * |
| 2792 | * This is designed to send muliple task management request at the same |
| 2793 | * time to the fifo. If the fifo is full, we will append the request, |
| 2794 | * and process it in a future completion. |
| 2795 | */ |
| 2796 | static void |
| 2797 | _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 2798 | { |
| 2799 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 2800 | u16 smid; |
| 2801 | struct _sas_device *sas_device; |
| 2802 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
| 2803 | u64 sas_address = 0; |
| 2804 | unsigned long flags; |
| 2805 | struct _tr_list *delayed_tr; |
| 2806 | u32 ioc_state; |
| 2807 | |
| 2808 | if (ioc->remove_host) { |
| 2809 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 2810 | "%s: host has been removed: handle(0x%04x)\n", |
| 2811 | __func__, ioc->name, handle)); |
| 2812 | return; |
| 2813 | } else if (ioc->pci_error_recovery) { |
| 2814 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 2815 | "%s: host in pci error recovery: handle(0x%04x)\n", |
| 2816 | __func__, ioc->name, |
| 2817 | handle)); |
| 2818 | return; |
| 2819 | } |
| 2820 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); |
| 2821 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 2822 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 2823 | "%s: host is not operational: handle(0x%04x)\n", |
| 2824 | __func__, ioc->name, |
| 2825 | handle)); |
| 2826 | return; |
| 2827 | } |
| 2828 | |
| 2829 | /* if PD, then return */ |
| 2830 | if (test_bit(handle, ioc->pd_handles)) |
| 2831 | return; |
| 2832 | |
| 2833 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2834 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 2835 | if (sas_device && sas_device->starget && |
| 2836 | sas_device->starget->hostdata) { |
| 2837 | sas_target_priv_data = sas_device->starget->hostdata; |
| 2838 | sas_target_priv_data->deleted = 1; |
| 2839 | sas_address = sas_device->sas_address; |
| 2840 | } |
| 2841 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2842 | |
| 2843 | if (sas_target_priv_data) { |
| 2844 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 2845 | "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n", |
| 2846 | ioc->name, handle, |
| 2847 | (unsigned long long)sas_address)); |
| 2848 | _scsih_ublock_io_device(ioc, sas_address); |
| 2849 | sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE; |
| 2850 | } |
| 2851 | |
| 2852 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); |
| 2853 | if (!smid) { |
| 2854 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 2855 | if (!delayed_tr) |
| 2856 | return; |
| 2857 | INIT_LIST_HEAD(&delayed_tr->list); |
| 2858 | delayed_tr->handle = handle; |
| 2859 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 2860 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 2861 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 2862 | ioc->name, handle)); |
| 2863 | return; |
| 2864 | } |
| 2865 | |
| 2866 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 2867 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", |
| 2868 | ioc->name, handle, smid, |
| 2869 | ioc->tm_tr_cb_idx)); |
| 2870 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 2871 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 2872 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 2873 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 2874 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
| 2875 | mpt3sas_base_put_smid_hi_priority(ioc, smid); |
| 2876 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL); |
| 2877 | } |
| 2878 | |
| 2879 | /** |
| 2880 | * _scsih_tm_tr_complete - |
| 2881 | * @ioc: per adapter object |
| 2882 | * @smid: system request message index |
| 2883 | * @msix_index: MSIX table index supplied by the OS |
| 2884 | * @reply: reply message frame(lower 32bit addr) |
| 2885 | * Context: interrupt time. |
| 2886 | * |
| 2887 | * This is the target reset completion routine. |
| 2888 | * This code is part of the code to initiate the device removal |
| 2889 | * handshake protocol with controller firmware. |
| 2890 | * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE) |
| 2891 | * |
| 2892 | * Return 1 meaning mf should be freed from _base_interrupt |
| 2893 | * 0 means the mf is freed from this function. |
| 2894 | */ |
| 2895 | static u8 |
| 2896 | _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 2897 | u32 reply) |
| 2898 | { |
| 2899 | u16 handle; |
| 2900 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
| 2901 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 2902 | mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 2903 | Mpi2SasIoUnitControlRequest_t *mpi_request; |
| 2904 | u16 smid_sas_ctrl; |
| 2905 | u32 ioc_state; |
| 2906 | |
| 2907 | if (ioc->remove_host) { |
| 2908 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 2909 | "%s: host has been removed\n", __func__, ioc->name)); |
| 2910 | return 1; |
| 2911 | } else if (ioc->pci_error_recovery) { |
| 2912 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 2913 | "%s: host in pci error recovery\n", __func__, |
| 2914 | ioc->name)); |
| 2915 | return 1; |
| 2916 | } |
| 2917 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); |
| 2918 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 2919 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 2920 | "%s: host is not operational\n", __func__, ioc->name)); |
| 2921 | return 1; |
| 2922 | } |
| 2923 | if (unlikely(!mpi_reply)) { |
| 2924 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 2925 | ioc->name, __FILE__, __LINE__, __func__); |
| 2926 | return 1; |
| 2927 | } |
| 2928 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); |
| 2929 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 2930 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 2931 | dewtprintk(ioc, pr_err(MPT3SAS_FMT |
| 2932 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", |
| 2933 | ioc->name, handle, |
| 2934 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 2935 | return 0; |
| 2936 | } |
| 2937 | |
| 2938 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); |
| 2939 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 2940 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 2941 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 2942 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 2943 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 2944 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 2945 | |
| 2946 | smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); |
| 2947 | if (!smid_sas_ctrl) { |
| 2948 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 2949 | ioc->name, __func__); |
| 2950 | return 1; |
| 2951 | } |
| 2952 | |
| 2953 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 2954 | "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", |
| 2955 | ioc->name, handle, smid_sas_ctrl, |
| 2956 | ioc->tm_sas_control_cb_idx)); |
| 2957 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl); |
| 2958 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); |
| 2959 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; |
| 2960 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; |
| 2961 | mpi_request->DevHandle = mpi_request_tm->DevHandle; |
| 2962 | mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl); |
| 2963 | |
| 2964 | return _scsih_check_for_pending_tm(ioc, smid); |
| 2965 | } |
| 2966 | |
| 2967 | |
| 2968 | /** |
| 2969 | * _scsih_sas_control_complete - completion routine |
| 2970 | * @ioc: per adapter object |
| 2971 | * @smid: system request message index |
| 2972 | * @msix_index: MSIX table index supplied by the OS |
| 2973 | * @reply: reply message frame(lower 32bit addr) |
| 2974 | * Context: interrupt time. |
| 2975 | * |
| 2976 | * This is the sas iounit control completion routine. |
| 2977 | * This code is part of the code to initiate the device removal |
| 2978 | * handshake protocol with controller firmware. |
| 2979 | * |
| 2980 | * Return 1 meaning mf should be freed from _base_interrupt |
| 2981 | * 0 means the mf is freed from this function. |
| 2982 | */ |
| 2983 | static u8 |
| 2984 | _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, |
| 2985 | u8 msix_index, u32 reply) |
| 2986 | { |
| 2987 | Mpi2SasIoUnitControlReply_t *mpi_reply = |
| 2988 | mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 2989 | |
| 2990 | if (likely(mpi_reply)) { |
| 2991 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 2992 | "sc_complete:handle(0x%04x), (open) " |
| 2993 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 2994 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, |
| 2995 | le16_to_cpu(mpi_reply->IOCStatus), |
| 2996 | le32_to_cpu(mpi_reply->IOCLogInfo))); |
| 2997 | } else { |
| 2998 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 2999 | ioc->name, __FILE__, __LINE__, __func__); |
| 3000 | } |
| 3001 | return 1; |
| 3002 | } |
| 3003 | |
| 3004 | /** |
| 3005 | * _scsih_tm_tr_volume_send - send target reset request for volumes |
| 3006 | * @ioc: per adapter object |
| 3007 | * @handle: device handle |
| 3008 | * Context: interrupt time. |
| 3009 | * |
| 3010 | * This is designed to send muliple task management request at the same |
| 3011 | * time to the fifo. If the fifo is full, we will append the request, |
| 3012 | * and process it in a future completion. |
| 3013 | */ |
| 3014 | static void |
| 3015 | _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 3016 | { |
| 3017 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 3018 | u16 smid; |
| 3019 | struct _tr_list *delayed_tr; |
| 3020 | |
| 3021 | if (ioc->shost_recovery || ioc->remove_host || |
| 3022 | ioc->pci_error_recovery) { |
| 3023 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 3024 | "%s: host reset in progress!\n", |
| 3025 | __func__, ioc->name)); |
| 3026 | return; |
| 3027 | } |
| 3028 | |
| 3029 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); |
| 3030 | if (!smid) { |
| 3031 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3032 | if (!delayed_tr) |
| 3033 | return; |
| 3034 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3035 | delayed_tr->handle = handle; |
| 3036 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); |
| 3037 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 3038 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 3039 | ioc->name, handle)); |
| 3040 | return; |
| 3041 | } |
| 3042 | |
| 3043 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 3044 | "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n", |
| 3045 | ioc->name, handle, smid, |
| 3046 | ioc->tm_tr_volume_cb_idx)); |
| 3047 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 3048 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 3049 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3050 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3051 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
| 3052 | mpt3sas_base_put_smid_hi_priority(ioc, smid); |
| 3053 | } |
| 3054 | |
| 3055 | /** |
| 3056 | * _scsih_tm_volume_tr_complete - target reset completion |
| 3057 | * @ioc: per adapter object |
| 3058 | * @smid: system request message index |
| 3059 | * @msix_index: MSIX table index supplied by the OS |
| 3060 | * @reply: reply message frame(lower 32bit addr) |
| 3061 | * Context: interrupt time. |
| 3062 | * |
| 3063 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3064 | * 0 means the mf is freed from this function. |
| 3065 | */ |
| 3066 | static u8 |
| 3067 | _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, |
| 3068 | u8 msix_index, u32 reply) |
| 3069 | { |
| 3070 | u16 handle; |
| 3071 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
| 3072 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3073 | mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 3074 | |
| 3075 | if (ioc->shost_recovery || ioc->remove_host || |
| 3076 | ioc->pci_error_recovery) { |
| 3077 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 3078 | "%s: host reset in progress!\n", |
| 3079 | __func__, ioc->name)); |
| 3080 | return 1; |
| 3081 | } |
| 3082 | if (unlikely(!mpi_reply)) { |
| 3083 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3084 | ioc->name, __FILE__, __LINE__, __func__); |
| 3085 | return 1; |
| 3086 | } |
| 3087 | |
| 3088 | mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid); |
| 3089 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3090 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3091 | dewtprintk(ioc, pr_err(MPT3SAS_FMT |
| 3092 | "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n", |
| 3093 | ioc->name, handle, |
| 3094 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3095 | return 0; |
| 3096 | } |
| 3097 | |
| 3098 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 3099 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3100 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3101 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3102 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3103 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3104 | |
| 3105 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3106 | } |
| 3107 | |
| 3108 | |
| 3109 | /** |
| 3110 | * _scsih_check_for_pending_tm - check for pending task management |
| 3111 | * @ioc: per adapter object |
| 3112 | * @smid: system request message index |
| 3113 | * |
| 3114 | * This will check delayed target reset list, and feed the |
| 3115 | * next reqeust. |
| 3116 | * |
| 3117 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3118 | * 0 means the mf is freed from this function. |
| 3119 | */ |
| 3120 | static u8 |
| 3121 | _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 3122 | { |
| 3123 | struct _tr_list *delayed_tr; |
| 3124 | |
| 3125 | if (!list_empty(&ioc->delayed_tr_volume_list)) { |
| 3126 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, |
| 3127 | struct _tr_list, list); |
| 3128 | mpt3sas_base_free_smid(ioc, smid); |
| 3129 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); |
| 3130 | list_del(&delayed_tr->list); |
| 3131 | kfree(delayed_tr); |
| 3132 | return 0; |
| 3133 | } |
| 3134 | |
| 3135 | if (!list_empty(&ioc->delayed_tr_list)) { |
| 3136 | delayed_tr = list_entry(ioc->delayed_tr_list.next, |
| 3137 | struct _tr_list, list); |
| 3138 | mpt3sas_base_free_smid(ioc, smid); |
| 3139 | _scsih_tm_tr_send(ioc, delayed_tr->handle); |
| 3140 | list_del(&delayed_tr->list); |
| 3141 | kfree(delayed_tr); |
| 3142 | return 0; |
| 3143 | } |
| 3144 | |
| 3145 | return 1; |
| 3146 | } |
| 3147 | |
| 3148 | /** |
| 3149 | * _scsih_check_topo_delete_events - sanity check on topo events |
| 3150 | * @ioc: per adapter object |
| 3151 | * @event_data: the event data payload |
| 3152 | * |
| 3153 | * This routine added to better handle cable breaker. |
| 3154 | * |
| 3155 | * This handles the case where driver receives multiple expander |
| 3156 | * add and delete events in a single shot. When there is a delete event |
| 3157 | * the routine will void any pending add events waiting in the event queue. |
| 3158 | * |
| 3159 | * Return nothing. |
| 3160 | */ |
| 3161 | static void |
| 3162 | _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc, |
| 3163 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3164 | { |
| 3165 | struct fw_event_work *fw_event; |
| 3166 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; |
| 3167 | u16 expander_handle; |
| 3168 | struct _sas_node *sas_expander; |
| 3169 | unsigned long flags; |
| 3170 | int i, reason_code; |
| 3171 | u16 handle; |
| 3172 | |
| 3173 | for (i = 0 ; i < event_data->NumEntries; i++) { |
| 3174 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3175 | if (!handle) |
| 3176 | continue; |
| 3177 | reason_code = event_data->PHY[i].PhyStatus & |
| 3178 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3179 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) |
| 3180 | _scsih_tm_tr_send(ioc, handle); |
| 3181 | } |
| 3182 | |
| 3183 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 3184 | if (expander_handle < ioc->sas_hba.num_phys) { |
| 3185 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3186 | return; |
| 3187 | } |
| 3188 | if (event_data->ExpStatus == |
| 3189 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { |
| 3190 | /* put expander attached devices into blocking state */ |
| 3191 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 3192 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, |
| 3193 | expander_handle); |
| 3194 | _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); |
| 3195 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 3196 | do { |
| 3197 | handle = find_first_bit(ioc->blocking_handles, |
| 3198 | ioc->facts.MaxDevHandle); |
| 3199 | if (handle < ioc->facts.MaxDevHandle) |
| 3200 | _scsih_block_io_device(ioc, handle); |
| 3201 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); |
| 3202 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) |
| 3203 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3204 | |
| 3205 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) |
| 3206 | return; |
| 3207 | |
| 3208 | /* mark ignore flag for pending events */ |
| 3209 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 3210 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { |
| 3211 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || |
| 3212 | fw_event->ignore) |
| 3213 | continue; |
| 3214 | local_event_data = fw_event->event_data; |
| 3215 | if (local_event_data->ExpStatus == |
| 3216 | MPI2_EVENT_SAS_TOPO_ES_ADDED || |
| 3217 | local_event_data->ExpStatus == |
| 3218 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { |
| 3219 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == |
| 3220 | expander_handle) { |
| 3221 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 3222 | "setting ignoring flag\n", ioc->name)); |
| 3223 | fw_event->ignore = 1; |
| 3224 | } |
| 3225 | } |
| 3226 | } |
| 3227 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 3228 | } |
| 3229 | |
| 3230 | /** |
| 3231 | * _scsih_set_volume_delete_flag - setting volume delete flag |
| 3232 | * @ioc: per adapter object |
| 3233 | * @handle: device handle |
| 3234 | * |
| 3235 | * This returns nothing. |
| 3236 | */ |
| 3237 | static void |
| 3238 | _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 3239 | { |
| 3240 | struct _raid_device *raid_device; |
| 3241 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 3242 | unsigned long flags; |
| 3243 | |
| 3244 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 3245 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 3246 | if (raid_device && raid_device->starget && |
| 3247 | raid_device->starget->hostdata) { |
| 3248 | sas_target_priv_data = |
| 3249 | raid_device->starget->hostdata; |
| 3250 | sas_target_priv_data->deleted = 1; |
| 3251 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 3252 | "setting delete flag: handle(0x%04x), " |
| 3253 | "wwid(0x%016llx)\n", ioc->name, handle, |
| 3254 | (unsigned long long) raid_device->wwid)); |
| 3255 | } |
| 3256 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 3257 | } |
| 3258 | |
| 3259 | /** |
| 3260 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume |
| 3261 | * @handle: input handle |
| 3262 | * @a: handle for volume a |
| 3263 | * @b: handle for volume b |
| 3264 | * |
| 3265 | * IR firmware only supports two raid volumes. The purpose of this |
| 3266 | * routine is to set the volume handle in either a or b. When the given |
| 3267 | * input handle is non-zero, or when a and b have not been set before. |
| 3268 | */ |
| 3269 | static void |
| 3270 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) |
| 3271 | { |
| 3272 | if (!handle || handle == *a || handle == *b) |
| 3273 | return; |
| 3274 | if (!*a) |
| 3275 | *a = handle; |
| 3276 | else if (!*b) |
| 3277 | *b = handle; |
| 3278 | } |
| 3279 | |
| 3280 | /** |
| 3281 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events |
| 3282 | * @ioc: per adapter object |
| 3283 | * @event_data: the event data payload |
| 3284 | * Context: interrupt time. |
| 3285 | * |
| 3286 | * This routine will send target reset to volume, followed by target |
| 3287 | * resets to the PDs. This is called when a PD has been removed, or |
| 3288 | * volume has been deleted or removed. When the target reset is sent |
| 3289 | * to volume, the PD target resets need to be queued to start upon |
| 3290 | * completion of the volume target reset. |
| 3291 | * |
| 3292 | * Return nothing. |
| 3293 | */ |
| 3294 | static void |
| 3295 | _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc, |
| 3296 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 3297 | { |
| 3298 | Mpi2EventIrConfigElement_t *element; |
| 3299 | int i; |
| 3300 | u16 handle, volume_handle, a, b; |
| 3301 | struct _tr_list *delayed_tr; |
| 3302 | |
| 3303 | a = 0; |
| 3304 | b = 0; |
| 3305 | |
| 3306 | /* Volume Resets for Deleted or Removed */ |
| 3307 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3308 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3309 | if (le32_to_cpu(event_data->Flags) & |
| 3310 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) |
| 3311 | continue; |
| 3312 | if (element->ReasonCode == |
| 3313 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || |
| 3314 | element->ReasonCode == |
| 3315 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { |
| 3316 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3317 | _scsih_set_volume_delete_flag(ioc, volume_handle); |
| 3318 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3319 | } |
| 3320 | } |
| 3321 | |
| 3322 | /* Volume Resets for UNHIDE events */ |
| 3323 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3324 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3325 | if (le32_to_cpu(event_data->Flags) & |
| 3326 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) |
| 3327 | continue; |
| 3328 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { |
| 3329 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3330 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3331 | } |
| 3332 | } |
| 3333 | |
| 3334 | if (a) |
| 3335 | _scsih_tm_tr_volume_send(ioc, a); |
| 3336 | if (b) |
| 3337 | _scsih_tm_tr_volume_send(ioc, b); |
| 3338 | |
| 3339 | /* PD target resets */ |
| 3340 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3341 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3342 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) |
| 3343 | continue; |
| 3344 | handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 3345 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3346 | clear_bit(handle, ioc->pd_handles); |
| 3347 | if (!volume_handle) |
| 3348 | _scsih_tm_tr_send(ioc, handle); |
| 3349 | else if (volume_handle == a || volume_handle == b) { |
| 3350 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3351 | BUG_ON(!delayed_tr); |
| 3352 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3353 | delayed_tr->handle = handle; |
| 3354 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 3355 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 3356 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, |
| 3357 | handle)); |
| 3358 | } else |
| 3359 | _scsih_tm_tr_send(ioc, handle); |
| 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | |
| 3364 | /** |
| 3365 | * _scsih_check_volume_delete_events - set delete flag for volumes |
| 3366 | * @ioc: per adapter object |
| 3367 | * @event_data: the event data payload |
| 3368 | * Context: interrupt time. |
| 3369 | * |
| 3370 | * This will handle the case when the cable connected to entire volume is |
| 3371 | * pulled. We will take care of setting the deleted flag so normal IO will |
| 3372 | * not be sent. |
| 3373 | * |
| 3374 | * Return nothing. |
| 3375 | */ |
| 3376 | static void |
| 3377 | _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc, |
| 3378 | Mpi2EventDataIrVolume_t *event_data) |
| 3379 | { |
| 3380 | u32 state; |
| 3381 | |
| 3382 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 3383 | return; |
| 3384 | state = le32_to_cpu(event_data->NewValue); |
| 3385 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == |
| 3386 | MPI2_RAID_VOL_STATE_FAILED) |
| 3387 | _scsih_set_volume_delete_flag(ioc, |
| 3388 | le16_to_cpu(event_data->VolDevHandle)); |
| 3389 | } |
| 3390 | |
| 3391 | /** |
| 3392 | * _scsih_flush_running_cmds - completing outstanding commands. |
| 3393 | * @ioc: per adapter object |
| 3394 | * |
| 3395 | * The flushing out of all pending scmd commands following host reset, |
| 3396 | * where all IO is dropped to the floor. |
| 3397 | * |
| 3398 | * Return nothing. |
| 3399 | */ |
| 3400 | static void |
| 3401 | _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc) |
| 3402 | { |
| 3403 | struct scsi_cmnd *scmd; |
| 3404 | u16 smid; |
| 3405 | u16 count = 0; |
| 3406 | |
| 3407 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
| 3408 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
| 3409 | if (!scmd) |
| 3410 | continue; |
| 3411 | count++; |
| 3412 | mpt3sas_base_free_smid(ioc, smid); |
| 3413 | scsi_dma_unmap(scmd); |
| 3414 | if (ioc->pci_error_recovery) |
| 3415 | scmd->result = DID_NO_CONNECT << 16; |
| 3416 | else |
| 3417 | scmd->result = DID_RESET << 16; |
| 3418 | scmd->scsi_done(scmd); |
| 3419 | } |
| 3420 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n", |
| 3421 | ioc->name, count)); |
| 3422 | } |
| 3423 | |
| 3424 | /** |
| 3425 | * _scsih_setup_eedp - setup MPI request for EEDP transfer |
| 3426 | * @ioc: per adapter object |
| 3427 | * @scmd: pointer to scsi command object |
| 3428 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3429 | * |
| 3430 | * Supporting protection 1 and 3. |
| 3431 | * |
| 3432 | * Returns nothing |
| 3433 | */ |
| 3434 | static void |
| 3435 | _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 3436 | Mpi2SCSIIORequest_t *mpi_request) |
| 3437 | { |
| 3438 | u16 eedp_flags; |
| 3439 | unsigned char prot_op = scsi_get_prot_op(scmd); |
| 3440 | unsigned char prot_type = scsi_get_prot_type(scmd); |
| 3441 | Mpi25SCSIIORequest_t *mpi_request_3v = |
| 3442 | (Mpi25SCSIIORequest_t *)mpi_request; |
| 3443 | |
| 3444 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) |
| 3445 | return; |
| 3446 | |
| 3447 | if (prot_op == SCSI_PROT_READ_STRIP) |
| 3448 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; |
| 3449 | else if (prot_op == SCSI_PROT_WRITE_INSERT) |
| 3450 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; |
| 3451 | else |
| 3452 | return; |
| 3453 | |
| 3454 | switch (prot_type) { |
| 3455 | case SCSI_PROT_DIF_TYPE1: |
| 3456 | case SCSI_PROT_DIF_TYPE2: |
| 3457 | |
| 3458 | /* |
| 3459 | * enable ref/guard checking |
| 3460 | * auto increment ref tag |
| 3461 | */ |
| 3462 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
| 3463 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | |
| 3464 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
| 3465 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = |
| 3466 | cpu_to_be32(scsi_get_lba(scmd)); |
| 3467 | break; |
| 3468 | |
| 3469 | case SCSI_PROT_DIF_TYPE3: |
| 3470 | |
| 3471 | /* |
| 3472 | * enable guard checking |
| 3473 | */ |
| 3474 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
| 3475 | |
| 3476 | break; |
| 3477 | } |
| 3478 | |
| 3479 | mpi_request_3v->EEDPBlockSize = |
| 3480 | cpu_to_le16(scmd->device->sector_size); |
| 3481 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
| 3482 | } |
| 3483 | |
| 3484 | /** |
| 3485 | * _scsih_eedp_error_handling - return sense code for EEDP errors |
| 3486 | * @scmd: pointer to scsi command object |
| 3487 | * @ioc_status: ioc status |
| 3488 | * |
| 3489 | * Returns nothing |
| 3490 | */ |
| 3491 | static void |
| 3492 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) |
| 3493 | { |
| 3494 | u8 ascq; |
| 3495 | |
| 3496 | switch (ioc_status) { |
| 3497 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 3498 | ascq = 0x01; |
| 3499 | break; |
| 3500 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 3501 | ascq = 0x02; |
| 3502 | break; |
| 3503 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 3504 | ascq = 0x03; |
| 3505 | break; |
| 3506 | default: |
| 3507 | ascq = 0x00; |
| 3508 | break; |
| 3509 | } |
| 3510 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, |
| 3511 | ascq); |
| 3512 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | |
| 3513 | SAM_STAT_CHECK_CONDITION; |
| 3514 | } |
| 3515 | |
| 3516 | |
| 3517 | /** |
| 3518 | * _scsih_qcmd_lck - main scsi request entry point |
| 3519 | * @scmd: pointer to scsi command object |
| 3520 | * @done: function pointer to be invoked on completion |
| 3521 | * |
| 3522 | * The callback index is set inside `ioc->scsi_io_cb_idx`. |
| 3523 | * |
| 3524 | * Returns 0 on success. If there's a failure, return either: |
| 3525 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or |
| 3526 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full |
| 3527 | */ |
| 3528 | static int |
| 3529 | _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *)) |
| 3530 | { |
| 3531 | struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 3532 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 3533 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 3534 | Mpi2SCSIIORequest_t *mpi_request; |
| 3535 | u32 mpi_control; |
| 3536 | u16 smid; |
| 3537 | u16 handle; |
| 3538 | |
| 3539 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING |
| 3540 | if (ioc->logging_level & MPT_DEBUG_SCSI) |
| 3541 | scsi_print_command(scmd); |
| 3542 | #endif |
| 3543 | |
| 3544 | scmd->scsi_done = done; |
| 3545 | sas_device_priv_data = scmd->device->hostdata; |
| 3546 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
| 3547 | scmd->result = DID_NO_CONNECT << 16; |
| 3548 | scmd->scsi_done(scmd); |
| 3549 | return 0; |
| 3550 | } |
| 3551 | |
| 3552 | if (ioc->pci_error_recovery || ioc->remove_host) { |
| 3553 | scmd->result = DID_NO_CONNECT << 16; |
| 3554 | scmd->scsi_done(scmd); |
| 3555 | return 0; |
| 3556 | } |
| 3557 | |
| 3558 | sas_target_priv_data = sas_device_priv_data->sas_target; |
| 3559 | |
| 3560 | /* invalid device handle */ |
| 3561 | handle = sas_target_priv_data->handle; |
| 3562 | if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) { |
| 3563 | scmd->result = DID_NO_CONNECT << 16; |
| 3564 | scmd->scsi_done(scmd); |
| 3565 | return 0; |
| 3566 | } |
| 3567 | |
| 3568 | |
| 3569 | /* host recovery or link resets sent via IOCTLs */ |
| 3570 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) |
| 3571 | return SCSI_MLQUEUE_HOST_BUSY; |
| 3572 | |
| 3573 | /* device has been deleted */ |
| 3574 | else if (sas_target_priv_data->deleted) { |
| 3575 | scmd->result = DID_NO_CONNECT << 16; |
| 3576 | scmd->scsi_done(scmd); |
| 3577 | return 0; |
| 3578 | /* device busy with task managment */ |
| 3579 | } else if (sas_target_priv_data->tm_busy || |
| 3580 | sas_device_priv_data->block) |
| 3581 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 3582 | |
| 3583 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) |
| 3584 | mpi_control = MPI2_SCSIIO_CONTROL_READ; |
| 3585 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 3586 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; |
| 3587 | else |
| 3588 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; |
| 3589 | |
| 3590 | /* set tags */ |
| 3591 | if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) { |
| 3592 | if (scmd->device->tagged_supported) { |
| 3593 | if (scmd->device->ordered_tags) |
| 3594 | mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ; |
| 3595 | else |
| 3596 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
| 3597 | } else |
| 3598 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
| 3599 | } else |
| 3600 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
| 3601 | |
| 3602 | if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) && |
| 3603 | scmd->cmd_len != 32) |
| 3604 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
| 3605 | |
| 3606 | smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd); |
| 3607 | if (!smid) { |
| 3608 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 3609 | ioc->name, __func__); |
| 3610 | goto out; |
| 3611 | } |
| 3612 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 3613 | memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t)); |
| 3614 | _scsih_setup_eedp(ioc, scmd, mpi_request); |
| 3615 | |
| 3616 | if (scmd->cmd_len == 32) |
| 3617 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; |
| 3618 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 3619 | if (sas_device_priv_data->sas_target->flags & |
| 3620 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 3621 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; |
| 3622 | else |
| 3623 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 3624 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3625 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
| 3626 | mpi_request->Control = cpu_to_le32(mpi_control); |
| 3627 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); |
| 3628 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; |
| 3629 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; |
| 3630 | mpi_request->SenseBufferLowAddress = |
| 3631 | mpt3sas_base_get_sense_buffer_dma(ioc, smid); |
| 3632 | mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4; |
| 3633 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
| 3634 | mpi_request->LUN); |
| 3635 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 3636 | |
| 3637 | if (mpi_request->DataLength) { |
| 3638 | if (ioc->build_sg_scmd(ioc, scmd, smid)) { |
| 3639 | mpt3sas_base_free_smid(ioc, smid); |
| 3640 | goto out; |
| 3641 | } |
| 3642 | } else |
| 3643 | ioc->build_zero_len_sge(ioc, &mpi_request->SGL); |
| 3644 | |
| 3645 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) { |
| 3646 | if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) { |
| 3647 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len | |
| 3648 | MPI25_SCSIIO_IOFLAGS_FAST_PATH); |
| 3649 | mpt3sas_base_put_smid_fast_path(ioc, smid, handle); |
| 3650 | } else |
| 3651 | mpt3sas_base_put_smid_scsi_io(ioc, smid, handle); |
| 3652 | } else |
| 3653 | mpt3sas_base_put_smid_default(ioc, smid); |
| 3654 | return 0; |
| 3655 | |
| 3656 | out: |
| 3657 | return SCSI_MLQUEUE_HOST_BUSY; |
| 3658 | } |
| 3659 | static DEF_SCSI_QCMD(_scsih_qcmd) |
| 3660 | |
| 3661 | |
| 3662 | /** |
| 3663 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data |
| 3664 | * @sense_buffer: sense data returned by target |
| 3665 | * @data: normalized skey/asc/ascq |
| 3666 | * |
| 3667 | * Return nothing. |
| 3668 | */ |
| 3669 | static void |
| 3670 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) |
| 3671 | { |
| 3672 | if ((sense_buffer[0] & 0x7F) >= 0x72) { |
| 3673 | /* descriptor format */ |
| 3674 | data->skey = sense_buffer[1] & 0x0F; |
| 3675 | data->asc = sense_buffer[2]; |
| 3676 | data->ascq = sense_buffer[3]; |
| 3677 | } else { |
| 3678 | /* fixed format */ |
| 3679 | data->skey = sense_buffer[2] & 0x0F; |
| 3680 | data->asc = sense_buffer[12]; |
| 3681 | data->ascq = sense_buffer[13]; |
| 3682 | } |
| 3683 | } |
| 3684 | |
| 3685 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING |
| 3686 | /** |
| 3687 | * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request |
| 3688 | * @ioc: per adapter object |
| 3689 | * @scmd: pointer to scsi command object |
| 3690 | * @mpi_reply: reply mf payload returned from firmware |
| 3691 | * |
| 3692 | * scsi_status - SCSI Status code returned from target device |
| 3693 | * scsi_state - state info associated with SCSI_IO determined by ioc |
| 3694 | * ioc_status - ioc supplied status info |
| 3695 | * |
| 3696 | * Return nothing. |
| 3697 | */ |
| 3698 | static void |
| 3699 | _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 3700 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) |
| 3701 | { |
| 3702 | u32 response_info; |
| 3703 | u8 *response_bytes; |
| 3704 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & |
| 3705 | MPI2_IOCSTATUS_MASK; |
| 3706 | u8 scsi_state = mpi_reply->SCSIState; |
| 3707 | u8 scsi_status = mpi_reply->SCSIStatus; |
| 3708 | char *desc_ioc_state = NULL; |
| 3709 | char *desc_scsi_status = NULL; |
| 3710 | char *desc_scsi_state = ioc->tmp_string; |
| 3711 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
| 3712 | struct _sas_device *sas_device = NULL; |
| 3713 | unsigned long flags; |
| 3714 | struct scsi_target *starget = scmd->device->sdev_target; |
| 3715 | struct MPT3SAS_TARGET *priv_target = starget->hostdata; |
| 3716 | char *device_str = NULL; |
| 3717 | |
| 3718 | if (!priv_target) |
| 3719 | return; |
| 3720 | device_str = "volume"; |
| 3721 | |
| 3722 | if (log_info == 0x31170000) |
| 3723 | return; |
| 3724 | |
| 3725 | switch (ioc_status) { |
| 3726 | case MPI2_IOCSTATUS_SUCCESS: |
| 3727 | desc_ioc_state = "success"; |
| 3728 | break; |
| 3729 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 3730 | desc_ioc_state = "invalid function"; |
| 3731 | break; |
| 3732 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 3733 | desc_ioc_state = "scsi recovered error"; |
| 3734 | break; |
| 3735 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: |
| 3736 | desc_ioc_state = "scsi invalid dev handle"; |
| 3737 | break; |
| 3738 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 3739 | desc_ioc_state = "scsi device not there"; |
| 3740 | break; |
| 3741 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 3742 | desc_ioc_state = "scsi data overrun"; |
| 3743 | break; |
| 3744 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 3745 | desc_ioc_state = "scsi data underrun"; |
| 3746 | break; |
| 3747 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 3748 | desc_ioc_state = "scsi io data error"; |
| 3749 | break; |
| 3750 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 3751 | desc_ioc_state = "scsi protocol error"; |
| 3752 | break; |
| 3753 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 3754 | desc_ioc_state = "scsi task terminated"; |
| 3755 | break; |
| 3756 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 3757 | desc_ioc_state = "scsi residual mismatch"; |
| 3758 | break; |
| 3759 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 3760 | desc_ioc_state = "scsi task mgmt failed"; |
| 3761 | break; |
| 3762 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 3763 | desc_ioc_state = "scsi ioc terminated"; |
| 3764 | break; |
| 3765 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 3766 | desc_ioc_state = "scsi ext terminated"; |
| 3767 | break; |
| 3768 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 3769 | desc_ioc_state = "eedp guard error"; |
| 3770 | break; |
| 3771 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 3772 | desc_ioc_state = "eedp ref tag error"; |
| 3773 | break; |
| 3774 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 3775 | desc_ioc_state = "eedp app tag error"; |
| 3776 | break; |
| 3777 | default: |
| 3778 | desc_ioc_state = "unknown"; |
| 3779 | break; |
| 3780 | } |
| 3781 | |
| 3782 | switch (scsi_status) { |
| 3783 | case MPI2_SCSI_STATUS_GOOD: |
| 3784 | desc_scsi_status = "good"; |
| 3785 | break; |
| 3786 | case MPI2_SCSI_STATUS_CHECK_CONDITION: |
| 3787 | desc_scsi_status = "check condition"; |
| 3788 | break; |
| 3789 | case MPI2_SCSI_STATUS_CONDITION_MET: |
| 3790 | desc_scsi_status = "condition met"; |
| 3791 | break; |
| 3792 | case MPI2_SCSI_STATUS_BUSY: |
| 3793 | desc_scsi_status = "busy"; |
| 3794 | break; |
| 3795 | case MPI2_SCSI_STATUS_INTERMEDIATE: |
| 3796 | desc_scsi_status = "intermediate"; |
| 3797 | break; |
| 3798 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: |
| 3799 | desc_scsi_status = "intermediate condmet"; |
| 3800 | break; |
| 3801 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: |
| 3802 | desc_scsi_status = "reservation conflict"; |
| 3803 | break; |
| 3804 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: |
| 3805 | desc_scsi_status = "command terminated"; |
| 3806 | break; |
| 3807 | case MPI2_SCSI_STATUS_TASK_SET_FULL: |
| 3808 | desc_scsi_status = "task set full"; |
| 3809 | break; |
| 3810 | case MPI2_SCSI_STATUS_ACA_ACTIVE: |
| 3811 | desc_scsi_status = "aca active"; |
| 3812 | break; |
| 3813 | case MPI2_SCSI_STATUS_TASK_ABORTED: |
| 3814 | desc_scsi_status = "task aborted"; |
| 3815 | break; |
| 3816 | default: |
| 3817 | desc_scsi_status = "unknown"; |
| 3818 | break; |
| 3819 | } |
| 3820 | |
| 3821 | desc_scsi_state[0] = '\0'; |
| 3822 | if (!scsi_state) |
| 3823 | desc_scsi_state = " "; |
| 3824 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 3825 | strcat(desc_scsi_state, "response info "); |
| 3826 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 3827 | strcat(desc_scsi_state, "state terminated "); |
| 3828 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) |
| 3829 | strcat(desc_scsi_state, "no status "); |
| 3830 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) |
| 3831 | strcat(desc_scsi_state, "autosense failed "); |
| 3832 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) |
| 3833 | strcat(desc_scsi_state, "autosense valid "); |
| 3834 | |
| 3835 | scsi_print_command(scmd); |
| 3836 | |
| 3837 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 3838 | pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name, |
| 3839 | device_str, (unsigned long long)priv_target->sas_address); |
| 3840 | } else { |
| 3841 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3842 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, |
| 3843 | priv_target->sas_address); |
| 3844 | if (sas_device) { |
| 3845 | pr_warn(MPT3SAS_FMT |
| 3846 | "\tsas_address(0x%016llx), phy(%d)\n", |
| 3847 | ioc->name, (unsigned long long) |
| 3848 | sas_device->sas_address, sas_device->phy); |
| 3849 | pr_warn(MPT3SAS_FMT |
| 3850 | "\tenclosure_logical_id(0x%016llx), slot(%d)\n", |
| 3851 | ioc->name, (unsigned long long) |
| 3852 | sas_device->enclosure_logical_id, sas_device->slot); |
| 3853 | } |
| 3854 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 3855 | } |
| 3856 | |
| 3857 | pr_warn(MPT3SAS_FMT |
| 3858 | "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n", |
| 3859 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), |
| 3860 | desc_ioc_state, ioc_status, smid); |
| 3861 | pr_warn(MPT3SAS_FMT |
| 3862 | "\trequest_len(%d), underflow(%d), resid(%d)\n", |
| 3863 | ioc->name, scsi_bufflen(scmd), scmd->underflow, |
| 3864 | scsi_get_resid(scmd)); |
| 3865 | pr_warn(MPT3SAS_FMT |
| 3866 | "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n", |
| 3867 | ioc->name, le16_to_cpu(mpi_reply->TaskTag), |
| 3868 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); |
| 3869 | pr_warn(MPT3SAS_FMT |
| 3870 | "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n", |
| 3871 | ioc->name, desc_scsi_status, |
| 3872 | scsi_status, desc_scsi_state, scsi_state); |
| 3873 | |
| 3874 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 3875 | struct sense_info data; |
| 3876 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 3877 | pr_warn(MPT3SAS_FMT |
| 3878 | "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n", |
| 3879 | ioc->name, data.skey, |
| 3880 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); |
| 3881 | } |
| 3882 | |
| 3883 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { |
| 3884 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); |
| 3885 | response_bytes = (u8 *)&response_info; |
| 3886 | _scsih_response_code(ioc, response_bytes[0]); |
| 3887 | } |
| 3888 | } |
| 3889 | #endif |
| 3890 | |
| 3891 | /** |
| 3892 | * _scsih_turn_on_fault_led - illuminate Fault LED |
| 3893 | * @ioc: per adapter object |
| 3894 | * @handle: device handle |
| 3895 | * Context: process |
| 3896 | * |
| 3897 | * Return nothing. |
| 3898 | */ |
| 3899 | static void |
| 3900 | _scsih_turn_on_fault_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 3901 | { |
| 3902 | Mpi2SepReply_t mpi_reply; |
| 3903 | Mpi2SepRequest_t mpi_request; |
| 3904 | |
| 3905 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
| 3906 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; |
| 3907 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; |
| 3908 | mpi_request.SlotStatus = |
| 3909 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); |
| 3910 | mpi_request.DevHandle = cpu_to_le16(handle); |
| 3911 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; |
| 3912 | if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply, |
| 3913 | &mpi_request)) != 0) { |
| 3914 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 3915 | __FILE__, __LINE__, __func__); |
| 3916 | return; |
| 3917 | } |
| 3918 | |
| 3919 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { |
| 3920 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 3921 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", |
| 3922 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), |
| 3923 | le32_to_cpu(mpi_reply.IOCLogInfo))); |
| 3924 | return; |
| 3925 | } |
| 3926 | } |
| 3927 | |
| 3928 | /** |
| 3929 | * _scsih_send_event_to_turn_on_fault_led - fire delayed event |
| 3930 | * @ioc: per adapter object |
| 3931 | * @handle: device handle |
| 3932 | * Context: interrupt. |
| 3933 | * |
| 3934 | * Return nothing. |
| 3935 | */ |
| 3936 | static void |
| 3937 | _scsih_send_event_to_turn_on_fault_led(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 3938 | { |
| 3939 | struct fw_event_work *fw_event; |
| 3940 | |
| 3941 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 3942 | if (!fw_event) |
| 3943 | return; |
| 3944 | fw_event->event = MPT3SAS_TURN_ON_FAULT_LED; |
| 3945 | fw_event->device_handle = handle; |
| 3946 | fw_event->ioc = ioc; |
| 3947 | _scsih_fw_event_add(ioc, fw_event); |
| 3948 | } |
| 3949 | |
| 3950 | /** |
| 3951 | * _scsih_smart_predicted_fault - process smart errors |
| 3952 | * @ioc: per adapter object |
| 3953 | * @handle: device handle |
| 3954 | * Context: interrupt. |
| 3955 | * |
| 3956 | * Return nothing. |
| 3957 | */ |
| 3958 | static void |
| 3959 | _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 3960 | { |
| 3961 | struct scsi_target *starget; |
| 3962 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 3963 | Mpi2EventNotificationReply_t *event_reply; |
| 3964 | Mpi2EventDataSasDeviceStatusChange_t *event_data; |
| 3965 | struct _sas_device *sas_device; |
| 3966 | ssize_t sz; |
| 3967 | unsigned long flags; |
| 3968 | |
| 3969 | /* only handle non-raid devices */ |
| 3970 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3971 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 3972 | if (!sas_device) { |
| 3973 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 3974 | return; |
| 3975 | } |
| 3976 | starget = sas_device->starget; |
| 3977 | sas_target_priv_data = starget->hostdata; |
| 3978 | |
| 3979 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || |
| 3980 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) { |
| 3981 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 3982 | return; |
| 3983 | } |
| 3984 | starget_printk(KERN_WARNING, starget, "predicted fault\n"); |
| 3985 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 3986 | |
| 3987 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) |
| 3988 | _scsih_send_event_to_turn_on_fault_led(ioc, handle); |
| 3989 | |
| 3990 | /* insert into event log */ |
| 3991 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + |
| 3992 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); |
| 3993 | event_reply = kzalloc(sz, GFP_KERNEL); |
| 3994 | if (!event_reply) { |
| 3995 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 3996 | ioc->name, __FILE__, __LINE__, __func__); |
| 3997 | return; |
| 3998 | } |
| 3999 | |
| 4000 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; |
| 4001 | event_reply->Event = |
| 4002 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); |
| 4003 | event_reply->MsgLength = sz/4; |
| 4004 | event_reply->EventDataLength = |
| 4005 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); |
| 4006 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) |
| 4007 | event_reply->EventData; |
| 4008 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; |
| 4009 | event_data->ASC = 0x5D; |
| 4010 | event_data->DevHandle = cpu_to_le16(handle); |
| 4011 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); |
| 4012 | mpt3sas_ctl_add_to_event_log(ioc, event_reply); |
| 4013 | kfree(event_reply); |
| 4014 | } |
| 4015 | |
| 4016 | /** |
| 4017 | * _scsih_io_done - scsi request callback |
| 4018 | * @ioc: per adapter object |
| 4019 | * @smid: system request message index |
| 4020 | * @msix_index: MSIX table index supplied by the OS |
| 4021 | * @reply: reply message frame(lower 32bit addr) |
| 4022 | * |
| 4023 | * Callback handler when using _scsih_qcmd. |
| 4024 | * |
| 4025 | * Return 1 meaning mf should be freed from _base_interrupt |
| 4026 | * 0 means the mf is freed from this function. |
| 4027 | */ |
| 4028 | static u8 |
| 4029 | _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) |
| 4030 | { |
| 4031 | Mpi2SCSIIORequest_t *mpi_request; |
| 4032 | Mpi2SCSIIOReply_t *mpi_reply; |
| 4033 | struct scsi_cmnd *scmd; |
| 4034 | u16 ioc_status; |
| 4035 | u32 xfer_cnt; |
| 4036 | u8 scsi_state; |
| 4037 | u8 scsi_status; |
| 4038 | u32 log_info; |
| 4039 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 4040 | u32 response_code = 0; |
| 4041 | |
| 4042 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 4043 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
| 4044 | if (scmd == NULL) |
| 4045 | return 1; |
| 4046 | |
| 4047 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 4048 | |
| 4049 | if (mpi_reply == NULL) { |
| 4050 | scmd->result = DID_OK << 16; |
| 4051 | goto out; |
| 4052 | } |
| 4053 | |
| 4054 | sas_device_priv_data = scmd->device->hostdata; |
| 4055 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
| 4056 | sas_device_priv_data->sas_target->deleted) { |
| 4057 | scmd->result = DID_NO_CONNECT << 16; |
| 4058 | goto out; |
| 4059 | } |
| 4060 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); |
| 4061 | |
| 4062 | /* turning off TLR */ |
| 4063 | scsi_state = mpi_reply->SCSIState; |
| 4064 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 4065 | response_code = |
| 4066 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; |
| 4067 | if (!sas_device_priv_data->tlr_snoop_check) { |
| 4068 | sas_device_priv_data->tlr_snoop_check++; |
| 4069 | if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) && |
| 4070 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) |
| 4071 | sas_device_priv_data->flags &= |
| 4072 | ~MPT_DEVICE_TLR_ON; |
| 4073 | } |
| 4074 | |
| 4075 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); |
| 4076 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); |
| 4077 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) |
| 4078 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
| 4079 | else |
| 4080 | log_info = 0; |
| 4081 | ioc_status &= MPI2_IOCSTATUS_MASK; |
| 4082 | scsi_status = mpi_reply->SCSIStatus; |
| 4083 | |
| 4084 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && |
| 4085 | (scsi_status == MPI2_SCSI_STATUS_BUSY || |
| 4086 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || |
| 4087 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { |
| 4088 | ioc_status = MPI2_IOCSTATUS_SUCCESS; |
| 4089 | } |
| 4090 | |
| 4091 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4092 | struct sense_info data; |
| 4093 | const void *sense_data = mpt3sas_base_get_sense_buffer(ioc, |
| 4094 | smid); |
| 4095 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, |
| 4096 | le32_to_cpu(mpi_reply->SenseCount)); |
| 4097 | memcpy(scmd->sense_buffer, sense_data, sz); |
| 4098 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4099 | /* failure prediction threshold exceeded */ |
| 4100 | if (data.asc == 0x5D) |
| 4101 | _scsih_smart_predicted_fault(ioc, |
| 4102 | le16_to_cpu(mpi_reply->DevHandle)); |
| 4103 | mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq); |
| 4104 | } |
| 4105 | |
| 4106 | switch (ioc_status) { |
| 4107 | case MPI2_IOCSTATUS_BUSY: |
| 4108 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: |
| 4109 | scmd->result = SAM_STAT_BUSY; |
| 4110 | break; |
| 4111 | |
| 4112 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 4113 | scmd->result = DID_NO_CONNECT << 16; |
| 4114 | break; |
| 4115 | |
| 4116 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 4117 | if (sas_device_priv_data->block) { |
| 4118 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; |
| 4119 | goto out; |
| 4120 | } |
| 4121 | if (log_info == 0x31110630) { |
| 4122 | if (scmd->retries > 2) { |
| 4123 | scmd->result = DID_NO_CONNECT << 16; |
| 4124 | scsi_device_set_state(scmd->device, |
| 4125 | SDEV_OFFLINE); |
| 4126 | } else { |
| 4127 | scmd->result = DID_SOFT_ERROR << 16; |
| 4128 | scmd->device->expecting_cc_ua = 1; |
| 4129 | } |
| 4130 | break; |
| 4131 | } |
| 4132 | scmd->result = DID_SOFT_ERROR << 16; |
| 4133 | break; |
| 4134 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 4135 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 4136 | scmd->result = DID_RESET << 16; |
| 4137 | break; |
| 4138 | |
| 4139 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 4140 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) |
| 4141 | scmd->result = DID_SOFT_ERROR << 16; |
| 4142 | else |
| 4143 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4144 | break; |
| 4145 | |
| 4146 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 4147 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4148 | |
| 4149 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) |
| 4150 | break; |
| 4151 | |
| 4152 | if (xfer_cnt < scmd->underflow) { |
| 4153 | if (scsi_status == SAM_STAT_BUSY) |
| 4154 | scmd->result = SAM_STAT_BUSY; |
| 4155 | else |
| 4156 | scmd->result = DID_SOFT_ERROR << 16; |
| 4157 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4158 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) |
| 4159 | scmd->result = DID_SOFT_ERROR << 16; |
| 4160 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4161 | scmd->result = DID_RESET << 16; |
| 4162 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { |
| 4163 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; |
| 4164 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; |
| 4165 | scmd->result = (DRIVER_SENSE << 24) | |
| 4166 | SAM_STAT_CHECK_CONDITION; |
| 4167 | scmd->sense_buffer[0] = 0x70; |
| 4168 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; |
| 4169 | scmd->sense_buffer[12] = 0x20; |
| 4170 | scmd->sense_buffer[13] = 0; |
| 4171 | } |
| 4172 | break; |
| 4173 | |
| 4174 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 4175 | scsi_set_resid(scmd, 0); |
| 4176 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 4177 | case MPI2_IOCSTATUS_SUCCESS: |
| 4178 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4179 | if (response_code == |
| 4180 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || |
| 4181 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4182 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) |
| 4183 | scmd->result = DID_SOFT_ERROR << 16; |
| 4184 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4185 | scmd->result = DID_RESET << 16; |
| 4186 | break; |
| 4187 | |
| 4188 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 4189 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 4190 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 4191 | _scsih_eedp_error_handling(scmd, ioc_status); |
| 4192 | break; |
| 4193 | |
| 4194 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 4195 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 4196 | case MPI2_IOCSTATUS_INVALID_SGL: |
| 4197 | case MPI2_IOCSTATUS_INTERNAL_ERROR: |
| 4198 | case MPI2_IOCSTATUS_INVALID_FIELD: |
| 4199 | case MPI2_IOCSTATUS_INVALID_STATE: |
| 4200 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 4201 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 4202 | default: |
| 4203 | scmd->result = DID_SOFT_ERROR << 16; |
| 4204 | break; |
| 4205 | |
| 4206 | } |
| 4207 | |
| 4208 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING |
| 4209 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
| 4210 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); |
| 4211 | #endif |
| 4212 | |
| 4213 | out: |
| 4214 | |
| 4215 | scsi_dma_unmap(scmd); |
| 4216 | |
| 4217 | scmd->scsi_done(scmd); |
| 4218 | return 1; |
| 4219 | } |
| 4220 | |
| 4221 | /** |
| 4222 | * _scsih_sas_host_refresh - refreshing sas host object contents |
| 4223 | * @ioc: per adapter object |
| 4224 | * Context: user |
| 4225 | * |
| 4226 | * During port enable, fw will send topology events for every device. Its |
| 4227 | * possible that the handles may change from the previous setting, so this |
| 4228 | * code keeping handles updating if changed. |
| 4229 | * |
| 4230 | * Return nothing. |
| 4231 | */ |
| 4232 | static void |
| 4233 | _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc) |
| 4234 | { |
| 4235 | u16 sz; |
| 4236 | u16 ioc_status; |
| 4237 | int i; |
| 4238 | Mpi2ConfigReply_t mpi_reply; |
| 4239 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
| 4240 | u16 attached_handle; |
| 4241 | u8 link_rate; |
| 4242 | |
| 4243 | dtmprintk(ioc, pr_info(MPT3SAS_FMT |
| 4244 | "updating handles for sas_host(0x%016llx)\n", |
| 4245 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); |
| 4246 | |
| 4247 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys |
| 4248 | * sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4249 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4250 | if (!sas_iounit_pg0) { |
| 4251 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4252 | ioc->name, __FILE__, __LINE__, __func__); |
| 4253 | return; |
| 4254 | } |
| 4255 | |
| 4256 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4257 | sas_iounit_pg0, sz)) != 0) |
| 4258 | goto out; |
| 4259 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 4260 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 4261 | goto out; |
| 4262 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
| 4263 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; |
| 4264 | if (i == 0) |
| 4265 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4266 | PhyData[0].ControllerDevHandle); |
| 4267 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
| 4268 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. |
| 4269 | AttachedDevHandle); |
| 4270 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 4271 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; |
| 4272 | mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address, |
| 4273 | attached_handle, i, link_rate); |
| 4274 | } |
| 4275 | out: |
| 4276 | kfree(sas_iounit_pg0); |
| 4277 | } |
| 4278 | |
| 4279 | /** |
| 4280 | * _scsih_sas_host_add - create sas host object |
| 4281 | * @ioc: per adapter object |
| 4282 | * |
| 4283 | * Creating host side data object, stored in ioc->sas_hba |
| 4284 | * |
| 4285 | * Return nothing. |
| 4286 | */ |
| 4287 | static void |
| 4288 | _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc) |
| 4289 | { |
| 4290 | int i; |
| 4291 | Mpi2ConfigReply_t mpi_reply; |
| 4292 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
| 4293 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; |
| 4294 | Mpi2SasPhyPage0_t phy_pg0; |
| 4295 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4296 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4297 | u16 ioc_status; |
| 4298 | u16 sz; |
| 4299 | u8 device_missing_delay; |
| 4300 | |
| 4301 | mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys); |
| 4302 | if (!ioc->sas_hba.num_phys) { |
| 4303 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4304 | ioc->name, __FILE__, __LINE__, __func__); |
| 4305 | return; |
| 4306 | } |
| 4307 | |
| 4308 | /* sas_iounit page 0 */ |
| 4309 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4310 | sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4311 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4312 | if (!sas_iounit_pg0) { |
| 4313 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4314 | ioc->name, __FILE__, __LINE__, __func__); |
| 4315 | return; |
| 4316 | } |
| 4317 | if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4318 | sas_iounit_pg0, sz))) { |
| 4319 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4320 | ioc->name, __FILE__, __LINE__, __func__); |
| 4321 | goto out; |
| 4322 | } |
| 4323 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4324 | MPI2_IOCSTATUS_MASK; |
| 4325 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4326 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4327 | ioc->name, __FILE__, __LINE__, __func__); |
| 4328 | goto out; |
| 4329 | } |
| 4330 | |
| 4331 | /* sas_iounit page 1 */ |
| 4332 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4333 | sizeof(Mpi2SasIOUnit1PhyData_t)); |
| 4334 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); |
| 4335 | if (!sas_iounit_pg1) { |
| 4336 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4337 | ioc->name, __FILE__, __LINE__, __func__); |
| 4338 | goto out; |
| 4339 | } |
| 4340 | if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, |
| 4341 | sas_iounit_pg1, sz))) { |
| 4342 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4343 | ioc->name, __FILE__, __LINE__, __func__); |
| 4344 | goto out; |
| 4345 | } |
| 4346 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4347 | MPI2_IOCSTATUS_MASK; |
| 4348 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4349 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4350 | ioc->name, __FILE__, __LINE__, __func__); |
| 4351 | goto out; |
| 4352 | } |
| 4353 | |
| 4354 | ioc->io_missing_delay = |
| 4355 | sas_iounit_pg1->IODeviceMissingDelay; |
| 4356 | device_missing_delay = |
| 4357 | sas_iounit_pg1->ReportDeviceMissingDelay; |
| 4358 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) |
| 4359 | ioc->device_missing_delay = (device_missing_delay & |
| 4360 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; |
| 4361 | else |
| 4362 | ioc->device_missing_delay = device_missing_delay & |
| 4363 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 4364 | |
| 4365 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; |
| 4366 | ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys, |
| 4367 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4368 | if (!ioc->sas_hba.phy) { |
| 4369 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4370 | ioc->name, __FILE__, __LINE__, __func__); |
| 4371 | goto out; |
| 4372 | } |
| 4373 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
| 4374 | if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, |
| 4375 | i))) { |
| 4376 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4377 | ioc->name, __FILE__, __LINE__, __func__); |
| 4378 | goto out; |
| 4379 | } |
| 4380 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4381 | MPI2_IOCSTATUS_MASK; |
| 4382 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4383 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4384 | ioc->name, __FILE__, __LINE__, __func__); |
| 4385 | goto out; |
| 4386 | } |
| 4387 | |
| 4388 | if (i == 0) |
| 4389 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4390 | PhyData[0].ControllerDevHandle); |
| 4391 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
| 4392 | ioc->sas_hba.phy[i].phy_id = i; |
| 4393 | mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], |
| 4394 | phy_pg0, ioc->sas_hba.parent_dev); |
| 4395 | } |
| 4396 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 4397 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { |
| 4398 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4399 | ioc->name, __FILE__, __LINE__, __func__); |
| 4400 | goto out; |
| 4401 | } |
| 4402 | ioc->sas_hba.enclosure_handle = |
| 4403 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 4404 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 4405 | pr_info(MPT3SAS_FMT |
| 4406 | "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n", |
| 4407 | ioc->name, ioc->sas_hba.handle, |
| 4408 | (unsigned long long) ioc->sas_hba.sas_address, |
| 4409 | ioc->sas_hba.num_phys) ; |
| 4410 | |
| 4411 | if (ioc->sas_hba.enclosure_handle) { |
| 4412 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4413 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4414 | ioc->sas_hba.enclosure_handle))) |
| 4415 | ioc->sas_hba.enclosure_logical_id = |
| 4416 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4417 | } |
| 4418 | |
| 4419 | out: |
| 4420 | kfree(sas_iounit_pg1); |
| 4421 | kfree(sas_iounit_pg0); |
| 4422 | } |
| 4423 | |
| 4424 | /** |
| 4425 | * _scsih_expander_add - creating expander object |
| 4426 | * @ioc: per adapter object |
| 4427 | * @handle: expander handle |
| 4428 | * |
| 4429 | * Creating expander object, stored in ioc->sas_expander_list. |
| 4430 | * |
| 4431 | * Return 0 for success, else error. |
| 4432 | */ |
| 4433 | static int |
| 4434 | _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 4435 | { |
| 4436 | struct _sas_node *sas_expander; |
| 4437 | Mpi2ConfigReply_t mpi_reply; |
| 4438 | Mpi2ExpanderPage0_t expander_pg0; |
| 4439 | Mpi2ExpanderPage1_t expander_pg1; |
| 4440 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4441 | u32 ioc_status; |
| 4442 | u16 parent_handle; |
| 4443 | u64 sas_address, sas_address_parent = 0; |
| 4444 | int i; |
| 4445 | unsigned long flags; |
| 4446 | struct _sas_port *mpt3sas_port = NULL; |
| 4447 | |
| 4448 | int rc = 0; |
| 4449 | |
| 4450 | if (!handle) |
| 4451 | return -1; |
| 4452 | |
| 4453 | if (ioc->shost_recovery || ioc->pci_error_recovery) |
| 4454 | return -1; |
| 4455 | |
| 4456 | if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 4457 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { |
| 4458 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4459 | ioc->name, __FILE__, __LINE__, __func__); |
| 4460 | return -1; |
| 4461 | } |
| 4462 | |
| 4463 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4464 | MPI2_IOCSTATUS_MASK; |
| 4465 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4466 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4467 | ioc->name, __FILE__, __LINE__, __func__); |
| 4468 | return -1; |
| 4469 | } |
| 4470 | |
| 4471 | /* handle out of order topology events */ |
| 4472 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); |
| 4473 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) |
| 4474 | != 0) { |
| 4475 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4476 | ioc->name, __FILE__, __LINE__, __func__); |
| 4477 | return -1; |
| 4478 | } |
| 4479 | if (sas_address_parent != ioc->sas_hba.sas_address) { |
| 4480 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 4481 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, |
| 4482 | sas_address_parent); |
| 4483 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4484 | if (!sas_expander) { |
| 4485 | rc = _scsih_expander_add(ioc, parent_handle); |
| 4486 | if (rc != 0) |
| 4487 | return rc; |
| 4488 | } |
| 4489 | } |
| 4490 | |
| 4491 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 4492 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
| 4493 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, |
| 4494 | sas_address); |
| 4495 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4496 | |
| 4497 | if (sas_expander) |
| 4498 | return 0; |
| 4499 | |
| 4500 | sas_expander = kzalloc(sizeof(struct _sas_node), |
| 4501 | GFP_KERNEL); |
| 4502 | if (!sas_expander) { |
| 4503 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4504 | ioc->name, __FILE__, __LINE__, __func__); |
| 4505 | return -1; |
| 4506 | } |
| 4507 | |
| 4508 | sas_expander->handle = handle; |
| 4509 | sas_expander->num_phys = expander_pg0.NumPhys; |
| 4510 | sas_expander->sas_address_parent = sas_address_parent; |
| 4511 | sas_expander->sas_address = sas_address; |
| 4512 | |
| 4513 | pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \ |
| 4514 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, |
| 4515 | handle, parent_handle, (unsigned long long) |
| 4516 | sas_expander->sas_address, sas_expander->num_phys); |
| 4517 | |
| 4518 | if (!sas_expander->num_phys) |
| 4519 | goto out_fail; |
| 4520 | sas_expander->phy = kcalloc(sas_expander->num_phys, |
| 4521 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4522 | if (!sas_expander->phy) { |
| 4523 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4524 | ioc->name, __FILE__, __LINE__, __func__); |
| 4525 | rc = -1; |
| 4526 | goto out_fail; |
| 4527 | } |
| 4528 | |
| 4529 | INIT_LIST_HEAD(&sas_expander->sas_port_list); |
| 4530 | mpt3sas_port = mpt3sas_transport_port_add(ioc, handle, |
| 4531 | sas_address_parent); |
| 4532 | if (!mpt3sas_port) { |
| 4533 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4534 | ioc->name, __FILE__, __LINE__, __func__); |
| 4535 | rc = -1; |
| 4536 | goto out_fail; |
| 4537 | } |
| 4538 | sas_expander->parent_dev = &mpt3sas_port->rphy->dev; |
| 4539 | |
| 4540 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 4541 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 4542 | &expander_pg1, i, handle))) { |
| 4543 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4544 | ioc->name, __FILE__, __LINE__, __func__); |
| 4545 | rc = -1; |
| 4546 | goto out_fail; |
| 4547 | } |
| 4548 | sas_expander->phy[i].handle = handle; |
| 4549 | sas_expander->phy[i].phy_id = i; |
| 4550 | |
| 4551 | if ((mpt3sas_transport_add_expander_phy(ioc, |
| 4552 | &sas_expander->phy[i], expander_pg1, |
| 4553 | sas_expander->parent_dev))) { |
| 4554 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4555 | ioc->name, __FILE__, __LINE__, __func__); |
| 4556 | rc = -1; |
| 4557 | goto out_fail; |
| 4558 | } |
| 4559 | } |
| 4560 | |
| 4561 | if (sas_expander->enclosure_handle) { |
| 4562 | if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4563 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4564 | sas_expander->enclosure_handle))) |
| 4565 | sas_expander->enclosure_logical_id = |
| 4566 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4567 | } |
| 4568 | |
| 4569 | _scsih_expander_node_add(ioc, sas_expander); |
| 4570 | return 0; |
| 4571 | |
| 4572 | out_fail: |
| 4573 | |
| 4574 | if (mpt3sas_port) |
| 4575 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, |
| 4576 | sas_address_parent); |
| 4577 | kfree(sas_expander); |
| 4578 | return rc; |
| 4579 | } |
| 4580 | |
| 4581 | /** |
| 4582 | * mpt3sas_expander_remove - removing expander object |
| 4583 | * @ioc: per adapter object |
| 4584 | * @sas_address: expander sas_address |
| 4585 | * |
| 4586 | * Return nothing. |
| 4587 | */ |
| 4588 | void |
| 4589 | mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) |
| 4590 | { |
| 4591 | struct _sas_node *sas_expander; |
| 4592 | unsigned long flags; |
| 4593 | |
| 4594 | if (ioc->shost_recovery) |
| 4595 | return; |
| 4596 | |
| 4597 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 4598 | sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc, |
| 4599 | sas_address); |
| 4600 | if (sas_expander) |
| 4601 | list_del(&sas_expander->list); |
| 4602 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4603 | if (sas_expander) |
| 4604 | _scsih_expander_node_remove(ioc, sas_expander); |
| 4605 | } |
| 4606 | |
| 4607 | /** |
| 4608 | * _scsih_done - internal SCSI_IO callback handler. |
| 4609 | * @ioc: per adapter object |
| 4610 | * @smid: system request message index |
| 4611 | * @msix_index: MSIX table index supplied by the OS |
| 4612 | * @reply: reply message frame(lower 32bit addr) |
| 4613 | * |
| 4614 | * Callback handler when sending internal generated SCSI_IO. |
| 4615 | * The callback index passed is `ioc->scsih_cb_idx` |
| 4616 | * |
| 4617 | * Return 1 meaning mf should be freed from _base_interrupt |
| 4618 | * 0 means the mf is freed from this function. |
| 4619 | */ |
| 4620 | static u8 |
| 4621 | _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) |
| 4622 | { |
| 4623 | MPI2DefaultReply_t *mpi_reply; |
| 4624 | |
| 4625 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 4626 | if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED) |
| 4627 | return 1; |
| 4628 | if (ioc->scsih_cmds.smid != smid) |
| 4629 | return 1; |
| 4630 | ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE; |
| 4631 | if (mpi_reply) { |
| 4632 | memcpy(ioc->scsih_cmds.reply, mpi_reply, |
| 4633 | mpi_reply->MsgLength*4); |
| 4634 | ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID; |
| 4635 | } |
| 4636 | ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING; |
| 4637 | complete(&ioc->scsih_cmds.done); |
| 4638 | return 1; |
| 4639 | } |
| 4640 | |
| 4641 | |
| 4642 | |
| 4643 | |
| 4644 | #define MPT3_MAX_LUNS (255) |
| 4645 | |
| 4646 | |
| 4647 | /** |
| 4648 | * _scsih_check_access_status - check access flags |
| 4649 | * @ioc: per adapter object |
| 4650 | * @sas_address: sas address |
| 4651 | * @handle: sas device handle |
| 4652 | * @access_flags: errors returned during discovery of the device |
| 4653 | * |
| 4654 | * Return 0 for success, else failure |
| 4655 | */ |
| 4656 | static u8 |
| 4657 | _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, |
| 4658 | u16 handle, u8 access_status) |
| 4659 | { |
| 4660 | u8 rc = 1; |
| 4661 | char *desc = NULL; |
| 4662 | |
| 4663 | switch (access_status) { |
| 4664 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: |
| 4665 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: |
| 4666 | rc = 0; |
| 4667 | break; |
| 4668 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: |
| 4669 | desc = "sata capability failed"; |
| 4670 | break; |
| 4671 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: |
| 4672 | desc = "sata affiliation conflict"; |
| 4673 | break; |
| 4674 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: |
| 4675 | desc = "route not addressable"; |
| 4676 | break; |
| 4677 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: |
| 4678 | desc = "smp error not addressable"; |
| 4679 | break; |
| 4680 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: |
| 4681 | desc = "device blocked"; |
| 4682 | break; |
| 4683 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: |
| 4684 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: |
| 4685 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: |
| 4686 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: |
| 4687 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: |
| 4688 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: |
| 4689 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: |
| 4690 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: |
| 4691 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: |
| 4692 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: |
| 4693 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: |
| 4694 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: |
| 4695 | desc = "sata initialization failed"; |
| 4696 | break; |
| 4697 | default: |
| 4698 | desc = "unknown"; |
| 4699 | break; |
| 4700 | } |
| 4701 | |
| 4702 | if (!rc) |
| 4703 | return 0; |
| 4704 | |
| 4705 | pr_err(MPT3SAS_FMT |
| 4706 | "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n", |
| 4707 | ioc->name, desc, (unsigned long long)sas_address, handle); |
| 4708 | return rc; |
| 4709 | } |
| 4710 | |
| 4711 | /** |
| 4712 | * _scsih_check_device - checking device responsiveness |
| 4713 | * @ioc: per adapter object |
| 4714 | * @parent_sas_address: sas address of parent expander or sas host |
| 4715 | * @handle: attached device handle |
| 4716 | * @phy_numberv: phy number |
| 4717 | * @link_rate: new link rate |
| 4718 | * |
| 4719 | * Returns nothing. |
| 4720 | */ |
| 4721 | static void |
| 4722 | _scsih_check_device(struct MPT3SAS_ADAPTER *ioc, |
| 4723 | u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate) |
| 4724 | { |
| 4725 | Mpi2ConfigReply_t mpi_reply; |
| 4726 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4727 | struct _sas_device *sas_device; |
| 4728 | u32 ioc_status; |
| 4729 | unsigned long flags; |
| 4730 | u64 sas_address; |
| 4731 | struct scsi_target *starget; |
| 4732 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 4733 | u32 device_info; |
| 4734 | |
| 4735 | |
| 4736 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 4737 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) |
| 4738 | return; |
| 4739 | |
| 4740 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 4741 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 4742 | return; |
| 4743 | |
| 4744 | /* wide port handling ~ we need only handle device once for the phy that |
| 4745 | * is matched in sas device page zero |
| 4746 | */ |
| 4747 | if (phy_number != sas_device_pg0.PhyNum) |
| 4748 | return; |
| 4749 | |
| 4750 | /* check if this is end device */ |
| 4751 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 4752 | if (!(_scsih_is_end_device(device_info))) |
| 4753 | return; |
| 4754 | |
| 4755 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4756 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 4757 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, |
| 4758 | sas_address); |
| 4759 | |
| 4760 | if (!sas_device) { |
| 4761 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4762 | return; |
| 4763 | } |
| 4764 | |
| 4765 | if (unlikely(sas_device->handle != handle)) { |
| 4766 | starget = sas_device->starget; |
| 4767 | sas_target_priv_data = starget->hostdata; |
| 4768 | starget_printk(KERN_INFO, starget, |
| 4769 | "handle changed from(0x%04x) to (0x%04x)!!!\n", |
| 4770 | sas_device->handle, handle); |
| 4771 | sas_target_priv_data->handle = handle; |
| 4772 | sas_device->handle = handle; |
| 4773 | } |
| 4774 | |
| 4775 | /* check if device is present */ |
| 4776 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 4777 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 4778 | pr_err(MPT3SAS_FMT |
| 4779 | "device is not present handle(0x%04x), flags!!!\n", |
| 4780 | ioc->name, handle); |
| 4781 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4782 | return; |
| 4783 | } |
| 4784 | |
| 4785 | /* check if there were any issues with discovery */ |
| 4786 | if (_scsih_check_access_status(ioc, sas_address, handle, |
| 4787 | sas_device_pg0.AccessStatus)) { |
| 4788 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4789 | return; |
| 4790 | } |
| 4791 | |
| 4792 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4793 | _scsih_ublock_io_device(ioc, sas_address); |
| 4794 | |
| 4795 | } |
| 4796 | |
| 4797 | /** |
| 4798 | * _scsih_add_device - creating sas device object |
| 4799 | * @ioc: per adapter object |
| 4800 | * @handle: sas device handle |
| 4801 | * @phy_num: phy number end device attached to |
| 4802 | * @is_pd: is this hidden raid component |
| 4803 | * |
| 4804 | * Creating end device object, stored in ioc->sas_device_list. |
| 4805 | * |
| 4806 | * Returns 0 for success, non-zero for failure. |
| 4807 | */ |
| 4808 | static int |
| 4809 | _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num, |
| 4810 | u8 is_pd) |
| 4811 | { |
| 4812 | Mpi2ConfigReply_t mpi_reply; |
| 4813 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4814 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4815 | struct _sas_device *sas_device; |
| 4816 | u32 ioc_status; |
| 4817 | u64 sas_address; |
| 4818 | u32 device_info; |
| 4819 | unsigned long flags; |
| 4820 | |
| 4821 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 4822 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 4823 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4824 | ioc->name, __FILE__, __LINE__, __func__); |
| 4825 | return -1; |
| 4826 | } |
| 4827 | |
| 4828 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4829 | MPI2_IOCSTATUS_MASK; |
| 4830 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4831 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4832 | ioc->name, __FILE__, __LINE__, __func__); |
| 4833 | return -1; |
| 4834 | } |
| 4835 | |
| 4836 | /* check if this is end device */ |
| 4837 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 4838 | if (!(_scsih_is_end_device(device_info))) |
| 4839 | return -1; |
| 4840 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 4841 | |
| 4842 | /* check if device is present */ |
| 4843 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 4844 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 4845 | pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n", |
| 4846 | ioc->name, handle); |
| 4847 | return -1; |
| 4848 | } |
| 4849 | |
| 4850 | /* check if there were any issues with discovery */ |
| 4851 | if (_scsih_check_access_status(ioc, sas_address, handle, |
| 4852 | sas_device_pg0.AccessStatus)) |
| 4853 | return -1; |
| 4854 | |
| 4855 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4856 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, |
| 4857 | sas_address); |
| 4858 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4859 | |
| 4860 | if (sas_device) |
| 4861 | return -1; |
| 4862 | |
| 4863 | sas_device = kzalloc(sizeof(struct _sas_device), |
| 4864 | GFP_KERNEL); |
| 4865 | if (!sas_device) { |
| 4866 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4867 | ioc->name, __FILE__, __LINE__, __func__); |
| 4868 | return 0; |
| 4869 | } |
| 4870 | |
| 4871 | sas_device->handle = handle; |
| 4872 | if (_scsih_get_sas_address(ioc, |
| 4873 | le16_to_cpu(sas_device_pg0.ParentDevHandle), |
| 4874 | &sas_device->sas_address_parent) != 0) |
| 4875 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 4876 | ioc->name, __FILE__, __LINE__, __func__); |
| 4877 | sas_device->enclosure_handle = |
| 4878 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 4879 | sas_device->slot = |
| 4880 | le16_to_cpu(sas_device_pg0.Slot); |
| 4881 | sas_device->device_info = device_info; |
| 4882 | sas_device->sas_address = sas_address; |
| 4883 | sas_device->phy = sas_device_pg0.PhyNum; |
| 4884 | sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) & |
| 4885 | MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0; |
| 4886 | |
| 4887 | /* get enclosure_logical_id */ |
| 4888 | if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0( |
| 4889 | ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4890 | sas_device->enclosure_handle))) |
| 4891 | sas_device->enclosure_logical_id = |
| 4892 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4893 | |
| 4894 | /* get device name */ |
| 4895 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); |
| 4896 | |
| 4897 | if (ioc->wait_for_discovery_to_complete) |
| 4898 | _scsih_sas_device_init_add(ioc, sas_device); |
| 4899 | else |
| 4900 | _scsih_sas_device_add(ioc, sas_device); |
| 4901 | |
| 4902 | return 0; |
| 4903 | } |
| 4904 | |
| 4905 | /** |
| 4906 | * _scsih_remove_device - removing sas device object |
| 4907 | * @ioc: per adapter object |
| 4908 | * @sas_device_delete: the sas_device object |
| 4909 | * |
| 4910 | * Return nothing. |
| 4911 | */ |
| 4912 | static void |
| 4913 | _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc, |
| 4914 | struct _sas_device *sas_device) |
| 4915 | { |
| 4916 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 4917 | |
| 4918 | |
| 4919 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 4920 | "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n", |
| 4921 | ioc->name, __func__, |
| 4922 | sas_device->handle, (unsigned long long) |
| 4923 | sas_device->sas_address)); |
| 4924 | |
| 4925 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 4926 | sas_target_priv_data = sas_device->starget->hostdata; |
| 4927 | sas_target_priv_data->deleted = 1; |
| 4928 | _scsih_ublock_io_device(ioc, sas_device->sas_address); |
| 4929 | sas_target_priv_data->handle = |
| 4930 | MPT3SAS_INVALID_DEVICE_HANDLE; |
| 4931 | } |
| 4932 | mpt3sas_transport_port_remove(ioc, |
| 4933 | sas_device->sas_address, |
| 4934 | sas_device->sas_address_parent); |
| 4935 | |
| 4936 | pr_info(MPT3SAS_FMT |
| 4937 | "removing handle(0x%04x), sas_addr(0x%016llx)\n", |
| 4938 | ioc->name, sas_device->handle, |
| 4939 | (unsigned long long) sas_device->sas_address); |
| 4940 | |
| 4941 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 4942 | "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n", |
| 4943 | ioc->name, __func__, |
| 4944 | sas_device->handle, (unsigned long long) |
| 4945 | sas_device->sas_address)); |
| 4946 | |
| 4947 | kfree(sas_device); |
| 4948 | } |
| 4949 | |
| 4950 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING |
| 4951 | /** |
| 4952 | * _scsih_sas_topology_change_event_debug - debug for topology event |
| 4953 | * @ioc: per adapter object |
| 4954 | * @event_data: event data payload |
| 4955 | * Context: user. |
| 4956 | */ |
| 4957 | static void |
| 4958 | _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc, |
| 4959 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 4960 | { |
| 4961 | int i; |
| 4962 | u16 handle; |
| 4963 | u16 reason_code; |
| 4964 | u8 phy_number; |
| 4965 | char *status_str = NULL; |
| 4966 | u8 link_rate, prev_link_rate; |
| 4967 | |
| 4968 | switch (event_data->ExpStatus) { |
| 4969 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: |
| 4970 | status_str = "add"; |
| 4971 | break; |
| 4972 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: |
| 4973 | status_str = "remove"; |
| 4974 | break; |
| 4975 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: |
| 4976 | case 0: |
| 4977 | status_str = "responding"; |
| 4978 | break; |
| 4979 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: |
| 4980 | status_str = "remove delay"; |
| 4981 | break; |
| 4982 | default: |
| 4983 | status_str = "unknown status"; |
| 4984 | break; |
| 4985 | } |
| 4986 | pr_info(MPT3SAS_FMT "sas topology change: (%s)\n", |
| 4987 | ioc->name, status_str); |
| 4988 | pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \ |
| 4989 | "start_phy(%02d), count(%d)\n", |
| 4990 | le16_to_cpu(event_data->ExpanderDevHandle), |
| 4991 | le16_to_cpu(event_data->EnclosureHandle), |
| 4992 | event_data->StartPhyNum, event_data->NumEntries); |
| 4993 | for (i = 0; i < event_data->NumEntries; i++) { |
| 4994 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 4995 | if (!handle) |
| 4996 | continue; |
| 4997 | phy_number = event_data->StartPhyNum + i; |
| 4998 | reason_code = event_data->PHY[i].PhyStatus & |
| 4999 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5000 | switch (reason_code) { |
| 5001 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
| 5002 | status_str = "target add"; |
| 5003 | break; |
| 5004 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
| 5005 | status_str = "target remove"; |
| 5006 | break; |
| 5007 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: |
| 5008 | status_str = "delay target remove"; |
| 5009 | break; |
| 5010 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
| 5011 | status_str = "link rate change"; |
| 5012 | break; |
| 5013 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: |
| 5014 | status_str = "target responding"; |
| 5015 | break; |
| 5016 | default: |
| 5017 | status_str = "unknown"; |
| 5018 | break; |
| 5019 | } |
| 5020 | link_rate = event_data->PHY[i].LinkRate >> 4; |
| 5021 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
| 5022 | pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \ |
| 5023 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, |
| 5024 | handle, status_str, link_rate, prev_link_rate); |
| 5025 | |
| 5026 | } |
| 5027 | } |
| 5028 | #endif |
| 5029 | |
| 5030 | /** |
| 5031 | * _scsih_sas_topology_change_event - handle topology changes |
| 5032 | * @ioc: per adapter object |
| 5033 | * @fw_event: The fw_event_work object |
| 5034 | * Context: user. |
| 5035 | * |
| 5036 | */ |
| 5037 | static int |
| 5038 | _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc, |
| 5039 | struct fw_event_work *fw_event) |
| 5040 | { |
| 5041 | int i; |
| 5042 | u16 parent_handle, handle; |
| 5043 | u16 reason_code; |
| 5044 | u8 phy_number, max_phys; |
| 5045 | struct _sas_node *sas_expander; |
| 5046 | u64 sas_address; |
| 5047 | unsigned long flags; |
| 5048 | u8 link_rate, prev_link_rate; |
| 5049 | Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data; |
| 5050 | |
| 5051 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING |
| 5052 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5053 | _scsih_sas_topology_change_event_debug(ioc, event_data); |
| 5054 | #endif |
| 5055 | |
| 5056 | if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) |
| 5057 | return 0; |
| 5058 | |
| 5059 | if (!ioc->sas_hba.num_phys) |
| 5060 | _scsih_sas_host_add(ioc); |
| 5061 | else |
| 5062 | _scsih_sas_host_refresh(ioc); |
| 5063 | |
| 5064 | if (fw_event->ignore) { |
| 5065 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 5066 | "ignoring expander event\n", ioc->name)); |
| 5067 | return 0; |
| 5068 | } |
| 5069 | |
| 5070 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 5071 | |
| 5072 | /* handle expander add */ |
| 5073 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) |
| 5074 | if (_scsih_expander_add(ioc, parent_handle) != 0) |
| 5075 | return 0; |
| 5076 | |
| 5077 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 5078 | sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc, |
| 5079 | parent_handle); |
| 5080 | if (sas_expander) { |
| 5081 | sas_address = sas_expander->sas_address; |
| 5082 | max_phys = sas_expander->num_phys; |
| 5083 | } else if (parent_handle < ioc->sas_hba.num_phys) { |
| 5084 | sas_address = ioc->sas_hba.sas_address; |
| 5085 | max_phys = ioc->sas_hba.num_phys; |
| 5086 | } else { |
| 5087 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 5088 | return 0; |
| 5089 | } |
| 5090 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 5091 | |
| 5092 | /* handle siblings events */ |
| 5093 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5094 | if (fw_event->ignore) { |
| 5095 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 5096 | "ignoring expander event\n", ioc->name)); |
| 5097 | return 0; |
| 5098 | } |
| 5099 | if (ioc->remove_host || ioc->pci_error_recovery) |
| 5100 | return 0; |
| 5101 | phy_number = event_data->StartPhyNum + i; |
| 5102 | if (phy_number >= max_phys) |
| 5103 | continue; |
| 5104 | reason_code = event_data->PHY[i].PhyStatus & |
| 5105 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5106 | if ((event_data->PHY[i].PhyStatus & |
| 5107 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != |
| 5108 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) |
| 5109 | continue; |
| 5110 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5111 | if (!handle) |
| 5112 | continue; |
| 5113 | link_rate = event_data->PHY[i].LinkRate >> 4; |
| 5114 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
| 5115 | switch (reason_code) { |
| 5116 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
| 5117 | |
| 5118 | if (ioc->shost_recovery) |
| 5119 | break; |
| 5120 | |
| 5121 | if (link_rate == prev_link_rate) |
| 5122 | break; |
| 5123 | |
| 5124 | mpt3sas_transport_update_links(ioc, sas_address, |
| 5125 | handle, phy_number, link_rate); |
| 5126 | |
| 5127 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 5128 | break; |
| 5129 | |
| 5130 | _scsih_check_device(ioc, sas_address, handle, |
| 5131 | phy_number, link_rate); |
| 5132 | |
| 5133 | |
| 5134 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
| 5135 | |
| 5136 | if (ioc->shost_recovery) |
| 5137 | break; |
| 5138 | |
| 5139 | mpt3sas_transport_update_links(ioc, sas_address, |
| 5140 | handle, phy_number, link_rate); |
| 5141 | |
| 5142 | _scsih_add_device(ioc, handle, phy_number, 0); |
| 5143 | |
| 5144 | break; |
| 5145 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
| 5146 | |
| 5147 | _scsih_device_remove_by_handle(ioc, handle); |
| 5148 | break; |
| 5149 | } |
| 5150 | } |
| 5151 | |
| 5152 | /* handle expander removal */ |
| 5153 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && |
| 5154 | sas_expander) |
| 5155 | mpt3sas_expander_remove(ioc, sas_address); |
| 5156 | |
| 5157 | return 0; |
| 5158 | } |
| 5159 | |
| 5160 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING |
| 5161 | /** |
| 5162 | * _scsih_sas_device_status_change_event_debug - debug for device event |
| 5163 | * @event_data: event data payload |
| 5164 | * Context: user. |
| 5165 | * |
| 5166 | * Return nothing. |
| 5167 | */ |
| 5168 | static void |
| 5169 | _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, |
| 5170 | Mpi2EventDataSasDeviceStatusChange_t *event_data) |
| 5171 | { |
| 5172 | char *reason_str = NULL; |
| 5173 | |
| 5174 | switch (event_data->ReasonCode) { |
| 5175 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: |
| 5176 | reason_str = "smart data"; |
| 5177 | break; |
| 5178 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: |
| 5179 | reason_str = "unsupported device discovered"; |
| 5180 | break; |
| 5181 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: |
| 5182 | reason_str = "internal device reset"; |
| 5183 | break; |
| 5184 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: |
| 5185 | reason_str = "internal task abort"; |
| 5186 | break; |
| 5187 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: |
| 5188 | reason_str = "internal task abort set"; |
| 5189 | break; |
| 5190 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: |
| 5191 | reason_str = "internal clear task set"; |
| 5192 | break; |
| 5193 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: |
| 5194 | reason_str = "internal query task"; |
| 5195 | break; |
| 5196 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: |
| 5197 | reason_str = "sata init failure"; |
| 5198 | break; |
| 5199 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: |
| 5200 | reason_str = "internal device reset complete"; |
| 5201 | break; |
| 5202 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: |
| 5203 | reason_str = "internal task abort complete"; |
| 5204 | break; |
| 5205 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: |
| 5206 | reason_str = "internal async notification"; |
| 5207 | break; |
| 5208 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5209 | reason_str = "expander reduced functionality"; |
| 5210 | break; |
| 5211 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5212 | reason_str = "expander reduced functionality complete"; |
| 5213 | break; |
| 5214 | default: |
| 5215 | reason_str = "unknown reason"; |
| 5216 | break; |
| 5217 | } |
| 5218 | pr_info(MPT3SAS_FMT "device status change: (%s)\n" |
| 5219 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", |
| 5220 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), |
| 5221 | (unsigned long long)le64_to_cpu(event_data->SASAddress), |
| 5222 | le16_to_cpu(event_data->TaskTag)); |
| 5223 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) |
| 5224 | pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name, |
| 5225 | event_data->ASC, event_data->ASCQ); |
| 5226 | pr_info("\n"); |
| 5227 | } |
| 5228 | #endif |
| 5229 | |
| 5230 | /** |
| 5231 | * _scsih_sas_device_status_change_event - handle device status change |
| 5232 | * @ioc: per adapter object |
| 5233 | * @fw_event: The fw_event_work object |
| 5234 | * Context: user. |
| 5235 | * |
| 5236 | * Return nothing. |
| 5237 | */ |
| 5238 | static void |
| 5239 | _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc, |
| 5240 | struct fw_event_work *fw_event) |
| 5241 | { |
| 5242 | struct MPT3SAS_TARGET *target_priv_data; |
| 5243 | struct _sas_device *sas_device; |
| 5244 | u64 sas_address; |
| 5245 | unsigned long flags; |
| 5246 | Mpi2EventDataSasDeviceStatusChange_t *event_data = |
| 5247 | fw_event->event_data; |
| 5248 | |
| 5249 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING |
| 5250 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5251 | _scsih_sas_device_status_change_event_debug(ioc, |
| 5252 | event_data); |
| 5253 | #endif |
| 5254 | |
| 5255 | /* In MPI Revision K (0xC), the internal device reset complete was |
| 5256 | * implemented, so avoid setting tm_busy flag for older firmware. |
| 5257 | */ |
| 5258 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) |
| 5259 | return; |
| 5260 | |
| 5261 | if (event_data->ReasonCode != |
| 5262 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && |
| 5263 | event_data->ReasonCode != |
| 5264 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) |
| 5265 | return; |
| 5266 | |
| 5267 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5268 | sas_address = le64_to_cpu(event_data->SASAddress); |
| 5269 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5270 | sas_address); |
| 5271 | |
| 5272 | if (!sas_device || !sas_device->starget) { |
| 5273 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5274 | return; |
| 5275 | } |
| 5276 | |
| 5277 | target_priv_data = sas_device->starget->hostdata; |
| 5278 | if (!target_priv_data) { |
| 5279 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5280 | return; |
| 5281 | } |
| 5282 | |
| 5283 | if (event_data->ReasonCode == |
| 5284 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) |
| 5285 | target_priv_data->tm_busy = 1; |
| 5286 | else |
| 5287 | target_priv_data->tm_busy = 0; |
| 5288 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5289 | } |
| 5290 | |
| 5291 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING |
| 5292 | /** |
| 5293 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure |
| 5294 | * event |
| 5295 | * @ioc: per adapter object |
| 5296 | * @event_data: event data payload |
| 5297 | * Context: user. |
| 5298 | * |
| 5299 | * Return nothing. |
| 5300 | */ |
| 5301 | static void |
| 5302 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc, |
| 5303 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) |
| 5304 | { |
| 5305 | char *reason_str = NULL; |
| 5306 | |
| 5307 | switch (event_data->ReasonCode) { |
| 5308 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: |
| 5309 | reason_str = "enclosure add"; |
| 5310 | break; |
| 5311 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: |
| 5312 | reason_str = "enclosure remove"; |
| 5313 | break; |
| 5314 | default: |
| 5315 | reason_str = "unknown reason"; |
| 5316 | break; |
| 5317 | } |
| 5318 | |
| 5319 | pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n" |
| 5320 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" |
| 5321 | " number slots(%d)\n", ioc->name, reason_str, |
| 5322 | le16_to_cpu(event_data->EnclosureHandle), |
| 5323 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), |
| 5324 | le16_to_cpu(event_data->StartSlot)); |
| 5325 | } |
| 5326 | #endif |
| 5327 | |
| 5328 | /** |
| 5329 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events |
| 5330 | * @ioc: per adapter object |
| 5331 | * @fw_event: The fw_event_work object |
| 5332 | * Context: user. |
| 5333 | * |
| 5334 | * Return nothing. |
| 5335 | */ |
| 5336 | static void |
| 5337 | _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc, |
| 5338 | struct fw_event_work *fw_event) |
| 5339 | { |
| 5340 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING |
| 5341 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5342 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, |
| 5343 | fw_event->event_data); |
| 5344 | #endif |
| 5345 | } |
| 5346 | |
| 5347 | /** |
| 5348 | * _scsih_sas_broadcast_primitive_event - handle broadcast events |
| 5349 | * @ioc: per adapter object |
| 5350 | * @fw_event: The fw_event_work object |
| 5351 | * Context: user. |
| 5352 | * |
| 5353 | * Return nothing. |
| 5354 | */ |
| 5355 | static void |
| 5356 | _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc, |
| 5357 | struct fw_event_work *fw_event) |
| 5358 | { |
| 5359 | struct scsi_cmnd *scmd; |
| 5360 | struct scsi_device *sdev; |
| 5361 | u16 smid, handle; |
| 5362 | u32 lun; |
| 5363 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 5364 | u32 termination_count; |
| 5365 | u32 query_count; |
| 5366 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
| 5367 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data; |
| 5368 | u16 ioc_status; |
| 5369 | unsigned long flags; |
| 5370 | int r; |
| 5371 | u8 max_retries = 0; |
| 5372 | u8 task_abort_retries; |
| 5373 | |
| 5374 | mutex_lock(&ioc->tm_cmds.mutex); |
| 5375 | pr_info(MPT3SAS_FMT |
| 5376 | "%s: enter: phy number(%d), width(%d)\n", |
| 5377 | ioc->name, __func__, event_data->PhyNum, |
| 5378 | event_data->PortWidth); |
| 5379 | |
| 5380 | _scsih_block_io_all_device(ioc); |
| 5381 | |
| 5382 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5383 | mpi_reply = ioc->tm_cmds.reply; |
| 5384 | broadcast_aen_retry: |
| 5385 | |
| 5386 | /* sanity checks for retrying this loop */ |
| 5387 | if (max_retries++ == 5) { |
| 5388 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n", |
| 5389 | ioc->name, __func__)); |
| 5390 | goto out; |
| 5391 | } else if (max_retries > 1) |
| 5392 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n", |
| 5393 | ioc->name, __func__, max_retries - 1)); |
| 5394 | |
| 5395 | termination_count = 0; |
| 5396 | query_count = 0; |
| 5397 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
| 5398 | if (ioc->shost_recovery) |
| 5399 | goto out; |
| 5400 | scmd = _scsih_scsi_lookup_get(ioc, smid); |
| 5401 | if (!scmd) |
| 5402 | continue; |
| 5403 | sdev = scmd->device; |
| 5404 | sas_device_priv_data = sdev->hostdata; |
| 5405 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) |
| 5406 | continue; |
| 5407 | /* skip hidden raid components */ |
| 5408 | if (sas_device_priv_data->sas_target->flags & |
| 5409 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 5410 | continue; |
| 5411 | /* skip volumes */ |
| 5412 | if (sas_device_priv_data->sas_target->flags & |
| 5413 | MPT_TARGET_FLAGS_VOLUME) |
| 5414 | continue; |
| 5415 | |
| 5416 | handle = sas_device_priv_data->sas_target->handle; |
| 5417 | lun = sas_device_priv_data->lun; |
| 5418 | query_count++; |
| 5419 | |
| 5420 | if (ioc->shost_recovery) |
| 5421 | goto out; |
| 5422 | |
| 5423 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 5424 | r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun, |
Matthew Wilcox | c62e46d | 2014-03-27 16:40:30 -0400 | [diff] [blame^] | 5425 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5426 | TM_MUTEX_OFF); |
| 5427 | if (r == FAILED) { |
| 5428 | sdev_printk(KERN_WARNING, sdev, |
| 5429 | "mpt3sas_scsih_issue_tm: FAILED when sending " |
| 5430 | "QUERY_TASK: scmd(%p)\n", scmd); |
| 5431 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5432 | goto broadcast_aen_retry; |
| 5433 | } |
| 5434 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) |
| 5435 | & MPI2_IOCSTATUS_MASK; |
| 5436 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5437 | sdev_printk(KERN_WARNING, sdev, |
| 5438 | "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n", |
| 5439 | ioc_status, scmd); |
| 5440 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5441 | goto broadcast_aen_retry; |
| 5442 | } |
| 5443 | |
| 5444 | /* see if IO is still owned by IOC and target */ |
| 5445 | if (mpi_reply->ResponseCode == |
| 5446 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || |
| 5447 | mpi_reply->ResponseCode == |
| 5448 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { |
| 5449 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5450 | continue; |
| 5451 | } |
| 5452 | task_abort_retries = 0; |
| 5453 | tm_retry: |
| 5454 | if (task_abort_retries++ == 60) { |
| 5455 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 5456 | "%s: ABORT_TASK: giving up\n", ioc->name, |
| 5457 | __func__)); |
| 5458 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5459 | goto broadcast_aen_retry; |
| 5460 | } |
| 5461 | |
| 5462 | if (ioc->shost_recovery) |
| 5463 | goto out_no_lock; |
| 5464 | |
| 5465 | r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, |
| 5466 | sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, |
Matthew Wilcox | c62e46d | 2014-03-27 16:40:30 -0400 | [diff] [blame^] | 5467 | TM_MUTEX_OFF); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5468 | if (r == FAILED) { |
| 5469 | sdev_printk(KERN_WARNING, sdev, |
| 5470 | "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : " |
| 5471 | "scmd(%p)\n", scmd); |
| 5472 | goto tm_retry; |
| 5473 | } |
| 5474 | |
| 5475 | if (task_abort_retries > 1) |
| 5476 | sdev_printk(KERN_WARNING, sdev, |
| 5477 | "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" |
| 5478 | " scmd(%p)\n", |
| 5479 | task_abort_retries - 1, scmd); |
| 5480 | |
| 5481 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); |
| 5482 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5483 | } |
| 5484 | |
| 5485 | if (ioc->broadcast_aen_pending) { |
| 5486 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 5487 | "%s: loop back due to pending AEN\n", |
| 5488 | ioc->name, __func__)); |
| 5489 | ioc->broadcast_aen_pending = 0; |
| 5490 | goto broadcast_aen_retry; |
| 5491 | } |
| 5492 | |
| 5493 | out: |
| 5494 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 5495 | out_no_lock: |
| 5496 | |
| 5497 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 5498 | "%s - exit, query_count = %d termination_count = %d\n", |
| 5499 | ioc->name, __func__, query_count, termination_count)); |
| 5500 | |
| 5501 | ioc->broadcast_aen_busy = 0; |
| 5502 | if (!ioc->shost_recovery) |
| 5503 | _scsih_ublock_io_all_device(ioc); |
| 5504 | mutex_unlock(&ioc->tm_cmds.mutex); |
| 5505 | } |
| 5506 | |
| 5507 | /** |
| 5508 | * _scsih_sas_discovery_event - handle discovery events |
| 5509 | * @ioc: per adapter object |
| 5510 | * @fw_event: The fw_event_work object |
| 5511 | * Context: user. |
| 5512 | * |
| 5513 | * Return nothing. |
| 5514 | */ |
| 5515 | static void |
| 5516 | _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc, |
| 5517 | struct fw_event_work *fw_event) |
| 5518 | { |
| 5519 | Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data; |
| 5520 | |
| 5521 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING |
| 5522 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
| 5523 | pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name, |
| 5524 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? |
| 5525 | "start" : "stop"); |
| 5526 | if (event_data->DiscoveryStatus) |
| 5527 | pr_info("discovery_status(0x%08x)", |
| 5528 | le32_to_cpu(event_data->DiscoveryStatus)); |
| 5529 | pr_info("\n"); |
| 5530 | } |
| 5531 | #endif |
| 5532 | |
| 5533 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && |
| 5534 | !ioc->sas_hba.num_phys) { |
| 5535 | if (disable_discovery > 0 && ioc->shost_recovery) { |
| 5536 | /* Wait for the reset to complete */ |
| 5537 | while (ioc->shost_recovery) |
| 5538 | ssleep(1); |
| 5539 | } |
| 5540 | _scsih_sas_host_add(ioc); |
| 5541 | } |
| 5542 | } |
| 5543 | |
| 5544 | /** |
| 5545 | * _scsih_ir_fastpath - turn on fastpath for IR physdisk |
| 5546 | * @ioc: per adapter object |
| 5547 | * @handle: device handle for physical disk |
| 5548 | * @phys_disk_num: physical disk number |
| 5549 | * |
| 5550 | * Return 0 for success, else failure. |
| 5551 | */ |
| 5552 | static int |
| 5553 | _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num) |
| 5554 | { |
| 5555 | Mpi2RaidActionRequest_t *mpi_request; |
| 5556 | Mpi2RaidActionReply_t *mpi_reply; |
| 5557 | u16 smid; |
| 5558 | u8 issue_reset = 0; |
| 5559 | int rc = 0; |
| 5560 | u16 ioc_status; |
| 5561 | u32 log_info; |
| 5562 | |
| 5563 | |
| 5564 | mutex_lock(&ioc->scsih_cmds.mutex); |
| 5565 | |
| 5566 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { |
| 5567 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", |
| 5568 | ioc->name, __func__); |
| 5569 | rc = -EAGAIN; |
| 5570 | goto out; |
| 5571 | } |
| 5572 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; |
| 5573 | |
| 5574 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); |
| 5575 | if (!smid) { |
| 5576 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 5577 | ioc->name, __func__); |
| 5578 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; |
| 5579 | rc = -EAGAIN; |
| 5580 | goto out; |
| 5581 | } |
| 5582 | |
| 5583 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 5584 | ioc->scsih_cmds.smid = smid; |
| 5585 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); |
| 5586 | |
| 5587 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; |
| 5588 | mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN; |
| 5589 | mpi_request->PhysDiskNum = phys_disk_num; |
| 5590 | |
| 5591 | dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\ |
| 5592 | "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name, |
| 5593 | handle, phys_disk_num)); |
| 5594 | |
| 5595 | init_completion(&ioc->scsih_cmds.done); |
| 5596 | mpt3sas_base_put_smid_default(ioc, smid); |
| 5597 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
| 5598 | |
| 5599 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { |
| 5600 | pr_err(MPT3SAS_FMT "%s: timeout\n", |
| 5601 | ioc->name, __func__); |
| 5602 | if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET)) |
| 5603 | issue_reset = 1; |
| 5604 | rc = -EFAULT; |
| 5605 | goto out; |
| 5606 | } |
| 5607 | |
| 5608 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { |
| 5609 | |
| 5610 | mpi_reply = ioc->scsih_cmds.reply; |
| 5611 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); |
| 5612 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) |
| 5613 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
| 5614 | else |
| 5615 | log_info = 0; |
| 5616 | ioc_status &= MPI2_IOCSTATUS_MASK; |
| 5617 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5618 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 5619 | "IR RAID_ACTION: failed: ioc_status(0x%04x), " |
| 5620 | "loginfo(0x%08x)!!!\n", ioc->name, ioc_status, |
| 5621 | log_info)); |
| 5622 | rc = -EFAULT; |
| 5623 | } else |
| 5624 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 5625 | "IR RAID_ACTION: completed successfully\n", |
| 5626 | ioc->name)); |
| 5627 | } |
| 5628 | |
| 5629 | out: |
| 5630 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; |
| 5631 | mutex_unlock(&ioc->scsih_cmds.mutex); |
| 5632 | |
| 5633 | if (issue_reset) |
| 5634 | mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 5635 | FORCE_BIG_HAMMER); |
| 5636 | return rc; |
| 5637 | } |
| 5638 | |
| 5639 | /** |
| 5640 | * _scsih_reprobe_lun - reprobing lun |
| 5641 | * @sdev: scsi device struct |
| 5642 | * @no_uld_attach: sdev->no_uld_attach flag setting |
| 5643 | * |
| 5644 | **/ |
| 5645 | static void |
| 5646 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) |
| 5647 | { |
| 5648 | int rc; |
| 5649 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
| 5650 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", |
| 5651 | sdev->no_uld_attach ? "hidding" : "exposing"); |
| 5652 | rc = scsi_device_reprobe(sdev); |
| 5653 | } |
| 5654 | |
| 5655 | /** |
| 5656 | * _scsih_sas_volume_add - add new volume |
| 5657 | * @ioc: per adapter object |
| 5658 | * @element: IR config element data |
| 5659 | * Context: user. |
| 5660 | * |
| 5661 | * Return nothing. |
| 5662 | */ |
| 5663 | static void |
| 5664 | _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc, |
| 5665 | Mpi2EventIrConfigElement_t *element) |
| 5666 | { |
| 5667 | struct _raid_device *raid_device; |
| 5668 | unsigned long flags; |
| 5669 | u64 wwid; |
| 5670 | u16 handle = le16_to_cpu(element->VolDevHandle); |
| 5671 | int rc; |
| 5672 | |
| 5673 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 5674 | if (!wwid) { |
| 5675 | pr_err(MPT3SAS_FMT |
| 5676 | "failure at %s:%d/%s()!\n", ioc->name, |
| 5677 | __FILE__, __LINE__, __func__); |
| 5678 | return; |
| 5679 | } |
| 5680 | |
| 5681 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 5682 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); |
| 5683 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 5684 | |
| 5685 | if (raid_device) |
| 5686 | return; |
| 5687 | |
| 5688 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 5689 | if (!raid_device) { |
| 5690 | pr_err(MPT3SAS_FMT |
| 5691 | "failure at %s:%d/%s()!\n", ioc->name, |
| 5692 | __FILE__, __LINE__, __func__); |
| 5693 | return; |
| 5694 | } |
| 5695 | |
| 5696 | raid_device->id = ioc->sas_id++; |
| 5697 | raid_device->channel = RAID_CHANNEL; |
| 5698 | raid_device->handle = handle; |
| 5699 | raid_device->wwid = wwid; |
| 5700 | _scsih_raid_device_add(ioc, raid_device); |
| 5701 | if (!ioc->wait_for_discovery_to_complete) { |
| 5702 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 5703 | raid_device->id, 0); |
| 5704 | if (rc) |
| 5705 | _scsih_raid_device_remove(ioc, raid_device); |
| 5706 | } else { |
| 5707 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 5708 | _scsih_determine_boot_device(ioc, raid_device, 1); |
| 5709 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 5710 | } |
| 5711 | } |
| 5712 | |
| 5713 | /** |
| 5714 | * _scsih_sas_volume_delete - delete volume |
| 5715 | * @ioc: per adapter object |
| 5716 | * @handle: volume device handle |
| 5717 | * Context: user. |
| 5718 | * |
| 5719 | * Return nothing. |
| 5720 | */ |
| 5721 | static void |
| 5722 | _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle) |
| 5723 | { |
| 5724 | struct _raid_device *raid_device; |
| 5725 | unsigned long flags; |
| 5726 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 5727 | struct scsi_target *starget = NULL; |
| 5728 | |
| 5729 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 5730 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 5731 | if (raid_device) { |
| 5732 | if (raid_device->starget) { |
| 5733 | starget = raid_device->starget; |
| 5734 | sas_target_priv_data = starget->hostdata; |
| 5735 | sas_target_priv_data->deleted = 1; |
| 5736 | } |
| 5737 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", |
| 5738 | ioc->name, raid_device->handle, |
| 5739 | (unsigned long long) raid_device->wwid); |
| 5740 | list_del(&raid_device->list); |
| 5741 | kfree(raid_device); |
| 5742 | } |
| 5743 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 5744 | if (starget) |
| 5745 | scsi_remove_target(&starget->dev); |
| 5746 | } |
| 5747 | |
| 5748 | /** |
| 5749 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX |
| 5750 | * @ioc: per adapter object |
| 5751 | * @element: IR config element data |
| 5752 | * Context: user. |
| 5753 | * |
| 5754 | * Return nothing. |
| 5755 | */ |
| 5756 | static void |
| 5757 | _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc, |
| 5758 | Mpi2EventIrConfigElement_t *element) |
| 5759 | { |
| 5760 | struct _sas_device *sas_device; |
| 5761 | struct scsi_target *starget = NULL; |
| 5762 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 5763 | unsigned long flags; |
| 5764 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 5765 | |
| 5766 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5767 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 5768 | if (sas_device) { |
| 5769 | sas_device->volume_handle = 0; |
| 5770 | sas_device->volume_wwid = 0; |
| 5771 | clear_bit(handle, ioc->pd_handles); |
| 5772 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 5773 | starget = sas_device->starget; |
| 5774 | sas_target_priv_data = starget->hostdata; |
| 5775 | sas_target_priv_data->flags &= |
| 5776 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 5777 | } |
| 5778 | } |
| 5779 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5780 | if (!sas_device) |
| 5781 | return; |
| 5782 | |
| 5783 | /* exposing raid component */ |
| 5784 | if (starget) |
| 5785 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); |
| 5786 | } |
| 5787 | |
| 5788 | /** |
| 5789 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX |
| 5790 | * @ioc: per adapter object |
| 5791 | * @element: IR config element data |
| 5792 | * Context: user. |
| 5793 | * |
| 5794 | * Return nothing. |
| 5795 | */ |
| 5796 | static void |
| 5797 | _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc, |
| 5798 | Mpi2EventIrConfigElement_t *element) |
| 5799 | { |
| 5800 | struct _sas_device *sas_device; |
| 5801 | struct scsi_target *starget = NULL; |
| 5802 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 5803 | unsigned long flags; |
| 5804 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 5805 | u16 volume_handle = 0; |
| 5806 | u64 volume_wwid = 0; |
| 5807 | |
| 5808 | mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle); |
| 5809 | if (volume_handle) |
| 5810 | mpt3sas_config_get_volume_wwid(ioc, volume_handle, |
| 5811 | &volume_wwid); |
| 5812 | |
| 5813 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5814 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 5815 | if (sas_device) { |
| 5816 | set_bit(handle, ioc->pd_handles); |
| 5817 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 5818 | starget = sas_device->starget; |
| 5819 | sas_target_priv_data = starget->hostdata; |
| 5820 | sas_target_priv_data->flags |= |
| 5821 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 5822 | sas_device->volume_handle = volume_handle; |
| 5823 | sas_device->volume_wwid = volume_wwid; |
| 5824 | } |
| 5825 | } |
| 5826 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5827 | if (!sas_device) |
| 5828 | return; |
| 5829 | |
| 5830 | /* hiding raid component */ |
| 5831 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); |
| 5832 | if (starget) |
| 5833 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); |
| 5834 | } |
| 5835 | |
| 5836 | /** |
| 5837 | * _scsih_sas_pd_delete - delete pd component |
| 5838 | * @ioc: per adapter object |
| 5839 | * @element: IR config element data |
| 5840 | * Context: user. |
| 5841 | * |
| 5842 | * Return nothing. |
| 5843 | */ |
| 5844 | static void |
| 5845 | _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc, |
| 5846 | Mpi2EventIrConfigElement_t *element) |
| 5847 | { |
| 5848 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 5849 | |
| 5850 | _scsih_device_remove_by_handle(ioc, handle); |
| 5851 | } |
| 5852 | |
| 5853 | /** |
| 5854 | * _scsih_sas_pd_add - remove pd component |
| 5855 | * @ioc: per adapter object |
| 5856 | * @element: IR config element data |
| 5857 | * Context: user. |
| 5858 | * |
| 5859 | * Return nothing. |
| 5860 | */ |
| 5861 | static void |
| 5862 | _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc, |
| 5863 | Mpi2EventIrConfigElement_t *element) |
| 5864 | { |
| 5865 | struct _sas_device *sas_device; |
| 5866 | unsigned long flags; |
| 5867 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 5868 | Mpi2ConfigReply_t mpi_reply; |
| 5869 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 5870 | u32 ioc_status; |
| 5871 | u64 sas_address; |
| 5872 | u16 parent_handle; |
| 5873 | |
| 5874 | set_bit(handle, ioc->pd_handles); |
| 5875 | |
| 5876 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5877 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 5878 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5879 | if (sas_device) { |
| 5880 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); |
| 5881 | return; |
| 5882 | } |
| 5883 | |
| 5884 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 5885 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 5886 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 5887 | ioc->name, __FILE__, __LINE__, __func__); |
| 5888 | return; |
| 5889 | } |
| 5890 | |
| 5891 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 5892 | MPI2_IOCSTATUS_MASK; |
| 5893 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5894 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 5895 | ioc->name, __FILE__, __LINE__, __func__); |
| 5896 | return; |
| 5897 | } |
| 5898 | |
| 5899 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 5900 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 5901 | mpt3sas_transport_update_links(ioc, sas_address, handle, |
| 5902 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
| 5903 | |
| 5904 | _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum); |
| 5905 | _scsih_add_device(ioc, handle, 0, 1); |
| 5906 | } |
| 5907 | |
| 5908 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING |
| 5909 | /** |
| 5910 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events |
| 5911 | * @ioc: per adapter object |
| 5912 | * @event_data: event data payload |
| 5913 | * Context: user. |
| 5914 | * |
| 5915 | * Return nothing. |
| 5916 | */ |
| 5917 | static void |
| 5918 | _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc, |
| 5919 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 5920 | { |
| 5921 | Mpi2EventIrConfigElement_t *element; |
| 5922 | u8 element_type; |
| 5923 | int i; |
| 5924 | char *reason_str = NULL, *element_str = NULL; |
| 5925 | |
| 5926 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 5927 | |
| 5928 | pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n", |
| 5929 | ioc->name, (le32_to_cpu(event_data->Flags) & |
| 5930 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? |
| 5931 | "foreign" : "native", event_data->NumElements); |
| 5932 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 5933 | switch (element->ReasonCode) { |
| 5934 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
| 5935 | reason_str = "add"; |
| 5936 | break; |
| 5937 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
| 5938 | reason_str = "remove"; |
| 5939 | break; |
| 5940 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: |
| 5941 | reason_str = "no change"; |
| 5942 | break; |
| 5943 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
| 5944 | reason_str = "hide"; |
| 5945 | break; |
| 5946 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
| 5947 | reason_str = "unhide"; |
| 5948 | break; |
| 5949 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 5950 | reason_str = "volume_created"; |
| 5951 | break; |
| 5952 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 5953 | reason_str = "volume_deleted"; |
| 5954 | break; |
| 5955 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
| 5956 | reason_str = "pd_created"; |
| 5957 | break; |
| 5958 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
| 5959 | reason_str = "pd_deleted"; |
| 5960 | break; |
| 5961 | default: |
| 5962 | reason_str = "unknown reason"; |
| 5963 | break; |
| 5964 | } |
| 5965 | element_type = le16_to_cpu(element->ElementFlags) & |
| 5966 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; |
| 5967 | switch (element_type) { |
| 5968 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: |
| 5969 | element_str = "volume"; |
| 5970 | break; |
| 5971 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: |
| 5972 | element_str = "phys disk"; |
| 5973 | break; |
| 5974 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: |
| 5975 | element_str = "hot spare"; |
| 5976 | break; |
| 5977 | default: |
| 5978 | element_str = "unknown element"; |
| 5979 | break; |
| 5980 | } |
| 5981 | pr_info("\t(%s:%s), vol handle(0x%04x), " \ |
| 5982 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, |
| 5983 | reason_str, le16_to_cpu(element->VolDevHandle), |
| 5984 | le16_to_cpu(element->PhysDiskDevHandle), |
| 5985 | element->PhysDiskNum); |
| 5986 | } |
| 5987 | } |
| 5988 | #endif |
| 5989 | |
| 5990 | /** |
| 5991 | * _scsih_sas_ir_config_change_event - handle ir configuration change events |
| 5992 | * @ioc: per adapter object |
| 5993 | * @fw_event: The fw_event_work object |
| 5994 | * Context: user. |
| 5995 | * |
| 5996 | * Return nothing. |
| 5997 | */ |
| 5998 | static void |
| 5999 | _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc, |
| 6000 | struct fw_event_work *fw_event) |
| 6001 | { |
| 6002 | Mpi2EventIrConfigElement_t *element; |
| 6003 | int i; |
| 6004 | u8 foreign_config; |
| 6005 | Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data; |
| 6006 | |
| 6007 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING |
| 6008 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6009 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
| 6010 | |
| 6011 | #endif |
| 6012 | |
| 6013 | foreign_config = (le32_to_cpu(event_data->Flags) & |
| 6014 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; |
| 6015 | |
| 6016 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 6017 | if (ioc->shost_recovery) { |
| 6018 | |
| 6019 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6020 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE) |
| 6021 | _scsih_ir_fastpath(ioc, |
| 6022 | le16_to_cpu(element->PhysDiskDevHandle), |
| 6023 | element->PhysDiskNum); |
| 6024 | } |
| 6025 | return; |
| 6026 | } |
| 6027 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6028 | |
| 6029 | switch (element->ReasonCode) { |
| 6030 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 6031 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
| 6032 | if (!foreign_config) |
| 6033 | _scsih_sas_volume_add(ioc, element); |
| 6034 | break; |
| 6035 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 6036 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
| 6037 | if (!foreign_config) |
| 6038 | _scsih_sas_volume_delete(ioc, |
| 6039 | le16_to_cpu(element->VolDevHandle)); |
| 6040 | break; |
| 6041 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
| 6042 | _scsih_sas_pd_hide(ioc, element); |
| 6043 | break; |
| 6044 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
| 6045 | _scsih_sas_pd_expose(ioc, element); |
| 6046 | break; |
| 6047 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
| 6048 | _scsih_sas_pd_add(ioc, element); |
| 6049 | break; |
| 6050 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
| 6051 | _scsih_sas_pd_delete(ioc, element); |
| 6052 | break; |
| 6053 | } |
| 6054 | } |
| 6055 | } |
| 6056 | |
| 6057 | /** |
| 6058 | * _scsih_sas_ir_volume_event - IR volume event |
| 6059 | * @ioc: per adapter object |
| 6060 | * @fw_event: The fw_event_work object |
| 6061 | * Context: user. |
| 6062 | * |
| 6063 | * Return nothing. |
| 6064 | */ |
| 6065 | static void |
| 6066 | _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc, |
| 6067 | struct fw_event_work *fw_event) |
| 6068 | { |
| 6069 | u64 wwid; |
| 6070 | unsigned long flags; |
| 6071 | struct _raid_device *raid_device; |
| 6072 | u16 handle; |
| 6073 | u32 state; |
| 6074 | int rc; |
| 6075 | Mpi2EventDataIrVolume_t *event_data = fw_event->event_data; |
| 6076 | |
| 6077 | if (ioc->shost_recovery) |
| 6078 | return; |
| 6079 | |
| 6080 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 6081 | return; |
| 6082 | |
| 6083 | handle = le16_to_cpu(event_data->VolDevHandle); |
| 6084 | state = le32_to_cpu(event_data->NewValue); |
| 6085 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 6086 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", |
| 6087 | ioc->name, __func__, handle, |
| 6088 | le32_to_cpu(event_data->PreviousValue), state)); |
| 6089 | switch (state) { |
| 6090 | case MPI2_RAID_VOL_STATE_MISSING: |
| 6091 | case MPI2_RAID_VOL_STATE_FAILED: |
| 6092 | _scsih_sas_volume_delete(ioc, handle); |
| 6093 | break; |
| 6094 | |
| 6095 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 6096 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 6097 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
| 6098 | |
| 6099 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6100 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 6101 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6102 | |
| 6103 | if (raid_device) |
| 6104 | break; |
| 6105 | |
| 6106 | mpt3sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 6107 | if (!wwid) { |
| 6108 | pr_err(MPT3SAS_FMT |
| 6109 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6110 | __FILE__, __LINE__, __func__); |
| 6111 | break; |
| 6112 | } |
| 6113 | |
| 6114 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 6115 | if (!raid_device) { |
| 6116 | pr_err(MPT3SAS_FMT |
| 6117 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6118 | __FILE__, __LINE__, __func__); |
| 6119 | break; |
| 6120 | } |
| 6121 | |
| 6122 | raid_device->id = ioc->sas_id++; |
| 6123 | raid_device->channel = RAID_CHANNEL; |
| 6124 | raid_device->handle = handle; |
| 6125 | raid_device->wwid = wwid; |
| 6126 | _scsih_raid_device_add(ioc, raid_device); |
| 6127 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 6128 | raid_device->id, 0); |
| 6129 | if (rc) |
| 6130 | _scsih_raid_device_remove(ioc, raid_device); |
| 6131 | break; |
| 6132 | |
| 6133 | case MPI2_RAID_VOL_STATE_INITIALIZING: |
| 6134 | default: |
| 6135 | break; |
| 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | /** |
| 6140 | * _scsih_sas_ir_physical_disk_event - PD event |
| 6141 | * @ioc: per adapter object |
| 6142 | * @fw_event: The fw_event_work object |
| 6143 | * Context: user. |
| 6144 | * |
| 6145 | * Return nothing. |
| 6146 | */ |
| 6147 | static void |
| 6148 | _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc, |
| 6149 | struct fw_event_work *fw_event) |
| 6150 | { |
| 6151 | u16 handle, parent_handle; |
| 6152 | u32 state; |
| 6153 | struct _sas_device *sas_device; |
| 6154 | unsigned long flags; |
| 6155 | Mpi2ConfigReply_t mpi_reply; |
| 6156 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6157 | u32 ioc_status; |
| 6158 | Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data; |
| 6159 | u64 sas_address; |
| 6160 | |
| 6161 | if (ioc->shost_recovery) |
| 6162 | return; |
| 6163 | |
| 6164 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) |
| 6165 | return; |
| 6166 | |
| 6167 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); |
| 6168 | state = le32_to_cpu(event_data->NewValue); |
| 6169 | |
| 6170 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 6171 | "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n", |
| 6172 | ioc->name, __func__, handle, |
| 6173 | le32_to_cpu(event_data->PreviousValue), state)); |
| 6174 | switch (state) { |
| 6175 | case MPI2_RAID_PD_STATE_ONLINE: |
| 6176 | case MPI2_RAID_PD_STATE_DEGRADED: |
| 6177 | case MPI2_RAID_PD_STATE_REBUILDING: |
| 6178 | case MPI2_RAID_PD_STATE_OPTIMAL: |
| 6179 | case MPI2_RAID_PD_STATE_HOT_SPARE: |
| 6180 | |
| 6181 | set_bit(handle, ioc->pd_handles); |
| 6182 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6183 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6184 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6185 | |
| 6186 | if (sas_device) |
| 6187 | return; |
| 6188 | |
| 6189 | if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6190 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 6191 | handle))) { |
| 6192 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 6193 | ioc->name, __FILE__, __LINE__, __func__); |
| 6194 | return; |
| 6195 | } |
| 6196 | |
| 6197 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6198 | MPI2_IOCSTATUS_MASK; |
| 6199 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6200 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 6201 | ioc->name, __FILE__, __LINE__, __func__); |
| 6202 | return; |
| 6203 | } |
| 6204 | |
| 6205 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6206 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 6207 | mpt3sas_transport_update_links(ioc, sas_address, handle, |
| 6208 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
| 6209 | |
| 6210 | _scsih_add_device(ioc, handle, 0, 1); |
| 6211 | |
| 6212 | break; |
| 6213 | |
| 6214 | case MPI2_RAID_PD_STATE_OFFLINE: |
| 6215 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: |
| 6216 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: |
| 6217 | default: |
| 6218 | break; |
| 6219 | } |
| 6220 | } |
| 6221 | |
| 6222 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING |
| 6223 | /** |
| 6224 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event |
| 6225 | * @ioc: per adapter object |
| 6226 | * @event_data: event data payload |
| 6227 | * Context: user. |
| 6228 | * |
| 6229 | * Return nothing. |
| 6230 | */ |
| 6231 | static void |
| 6232 | _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc, |
| 6233 | Mpi2EventDataIrOperationStatus_t *event_data) |
| 6234 | { |
| 6235 | char *reason_str = NULL; |
| 6236 | |
| 6237 | switch (event_data->RAIDOperation) { |
| 6238 | case MPI2_EVENT_IR_RAIDOP_RESYNC: |
| 6239 | reason_str = "resync"; |
| 6240 | break; |
| 6241 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: |
| 6242 | reason_str = "online capacity expansion"; |
| 6243 | break; |
| 6244 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: |
| 6245 | reason_str = "consistency check"; |
| 6246 | break; |
| 6247 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: |
| 6248 | reason_str = "background init"; |
| 6249 | break; |
| 6250 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: |
| 6251 | reason_str = "make data consistent"; |
| 6252 | break; |
| 6253 | } |
| 6254 | |
| 6255 | if (!reason_str) |
| 6256 | return; |
| 6257 | |
| 6258 | pr_info(MPT3SAS_FMT "raid operational status: (%s)" \ |
| 6259 | "\thandle(0x%04x), percent complete(%d)\n", |
| 6260 | ioc->name, reason_str, |
| 6261 | le16_to_cpu(event_data->VolDevHandle), |
| 6262 | event_data->PercentComplete); |
| 6263 | } |
| 6264 | #endif |
| 6265 | |
| 6266 | /** |
| 6267 | * _scsih_sas_ir_operation_status_event - handle RAID operation events |
| 6268 | * @ioc: per adapter object |
| 6269 | * @fw_event: The fw_event_work object |
| 6270 | * Context: user. |
| 6271 | * |
| 6272 | * Return nothing. |
| 6273 | */ |
| 6274 | static void |
| 6275 | _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc, |
| 6276 | struct fw_event_work *fw_event) |
| 6277 | { |
| 6278 | Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data; |
| 6279 | static struct _raid_device *raid_device; |
| 6280 | unsigned long flags; |
| 6281 | u16 handle; |
| 6282 | |
| 6283 | #ifdef CONFIG_SCSI_MPT3SAS_LOGGING |
| 6284 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6285 | _scsih_sas_ir_operation_status_event_debug(ioc, |
| 6286 | event_data); |
| 6287 | #endif |
| 6288 | |
| 6289 | /* code added for raid transport support */ |
| 6290 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { |
| 6291 | |
| 6292 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6293 | handle = le16_to_cpu(event_data->VolDevHandle); |
| 6294 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 6295 | if (raid_device) |
| 6296 | raid_device->percent_complete = |
| 6297 | event_data->PercentComplete; |
| 6298 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6299 | } |
| 6300 | } |
| 6301 | |
| 6302 | /** |
| 6303 | * _scsih_prep_device_scan - initialize parameters prior to device scan |
| 6304 | * @ioc: per adapter object |
| 6305 | * |
| 6306 | * Set the deleted flag prior to device scan. If the device is found during |
| 6307 | * the scan, then we clear the deleted flag. |
| 6308 | */ |
| 6309 | static void |
| 6310 | _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc) |
| 6311 | { |
| 6312 | struct MPT3SAS_DEVICE *sas_device_priv_data; |
| 6313 | struct scsi_device *sdev; |
| 6314 | |
| 6315 | shost_for_each_device(sdev, ioc->shost) { |
| 6316 | sas_device_priv_data = sdev->hostdata; |
| 6317 | if (sas_device_priv_data && sas_device_priv_data->sas_target) |
| 6318 | sas_device_priv_data->sas_target->deleted = 1; |
| 6319 | } |
| 6320 | } |
| 6321 | |
| 6322 | /** |
| 6323 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding |
| 6324 | * @ioc: per adapter object |
| 6325 | * @sas_address: sas address |
| 6326 | * @slot: enclosure slot id |
| 6327 | * @handle: device handle |
| 6328 | * |
| 6329 | * After host reset, find out whether devices are still responding. |
| 6330 | * Used in _scsih_remove_unresponsive_sas_devices. |
| 6331 | * |
| 6332 | * Return nothing. |
| 6333 | */ |
| 6334 | static void |
| 6335 | _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, |
| 6336 | u16 slot, u16 handle) |
| 6337 | { |
| 6338 | struct MPT3SAS_TARGET *sas_target_priv_data = NULL; |
| 6339 | struct scsi_target *starget; |
| 6340 | struct _sas_device *sas_device; |
| 6341 | unsigned long flags; |
| 6342 | |
| 6343 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6344 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { |
| 6345 | if (sas_device->sas_address == sas_address && |
| 6346 | sas_device->slot == slot) { |
| 6347 | sas_device->responding = 1; |
| 6348 | starget = sas_device->starget; |
| 6349 | if (starget && starget->hostdata) { |
| 6350 | sas_target_priv_data = starget->hostdata; |
| 6351 | sas_target_priv_data->tm_busy = 0; |
| 6352 | sas_target_priv_data->deleted = 0; |
| 6353 | } else |
| 6354 | sas_target_priv_data = NULL; |
| 6355 | if (starget) |
| 6356 | starget_printk(KERN_INFO, starget, |
| 6357 | "handle(0x%04x), sas_addr(0x%016llx), " |
| 6358 | "enclosure logical id(0x%016llx), " |
| 6359 | "slot(%d)\n", handle, |
| 6360 | (unsigned long long)sas_device->sas_address, |
| 6361 | (unsigned long long) |
| 6362 | sas_device->enclosure_logical_id, |
| 6363 | sas_device->slot); |
| 6364 | if (sas_device->handle == handle) |
| 6365 | goto out; |
| 6366 | pr_info("\thandle changed from(0x%04x)!!!\n", |
| 6367 | sas_device->handle); |
| 6368 | sas_device->handle = handle; |
| 6369 | if (sas_target_priv_data) |
| 6370 | sas_target_priv_data->handle = handle; |
| 6371 | goto out; |
| 6372 | } |
| 6373 | } |
| 6374 | out: |
| 6375 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6376 | } |
| 6377 | |
| 6378 | /** |
| 6379 | * _scsih_search_responding_sas_devices - |
| 6380 | * @ioc: per adapter object |
| 6381 | * |
| 6382 | * After host reset, find out whether devices are still responding. |
| 6383 | * If not remove. |
| 6384 | * |
| 6385 | * Return nothing. |
| 6386 | */ |
| 6387 | static void |
| 6388 | _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc) |
| 6389 | { |
| 6390 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6391 | Mpi2ConfigReply_t mpi_reply; |
| 6392 | u16 ioc_status; |
| 6393 | u16 handle; |
| 6394 | u32 device_info; |
| 6395 | |
| 6396 | pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name); |
| 6397 | |
| 6398 | if (list_empty(&ioc->sas_device_list)) |
| 6399 | goto out; |
| 6400 | |
| 6401 | handle = 0xFFFF; |
| 6402 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6403 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 6404 | handle))) { |
| 6405 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6406 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 14be49a | 2013-06-29 03:53:02 +0530 | [diff] [blame] | 6407 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6408 | break; |
| 6409 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 6410 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 6411 | if (!(_scsih_is_end_device(device_info))) |
| 6412 | continue; |
| 6413 | _scsih_mark_responding_sas_device(ioc, |
| 6414 | le64_to_cpu(sas_device_pg0.SASAddress), |
| 6415 | le16_to_cpu(sas_device_pg0.Slot), handle); |
| 6416 | } |
| 6417 | |
| 6418 | out: |
| 6419 | pr_info(MPT3SAS_FMT "search for end-devices: complete\n", |
| 6420 | ioc->name); |
| 6421 | } |
| 6422 | |
| 6423 | /** |
| 6424 | * _scsih_mark_responding_raid_device - mark a raid_device as responding |
| 6425 | * @ioc: per adapter object |
| 6426 | * @wwid: world wide identifier for raid volume |
| 6427 | * @handle: device handle |
| 6428 | * |
| 6429 | * After host reset, find out whether devices are still responding. |
| 6430 | * Used in _scsih_remove_unresponsive_raid_devices. |
| 6431 | * |
| 6432 | * Return nothing. |
| 6433 | */ |
| 6434 | static void |
| 6435 | _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid, |
| 6436 | u16 handle) |
| 6437 | { |
| 6438 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 6439 | struct scsi_target *starget; |
| 6440 | struct _raid_device *raid_device; |
| 6441 | unsigned long flags; |
| 6442 | |
| 6443 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6444 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 6445 | if (raid_device->wwid == wwid && raid_device->starget) { |
| 6446 | starget = raid_device->starget; |
| 6447 | if (starget && starget->hostdata) { |
| 6448 | sas_target_priv_data = starget->hostdata; |
| 6449 | sas_target_priv_data->deleted = 0; |
| 6450 | } else |
| 6451 | sas_target_priv_data = NULL; |
| 6452 | raid_device->responding = 1; |
| 6453 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6454 | starget_printk(KERN_INFO, raid_device->starget, |
| 6455 | "handle(0x%04x), wwid(0x%016llx)\n", handle, |
| 6456 | (unsigned long long)raid_device->wwid); |
| 6457 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6458 | if (raid_device->handle == handle) { |
| 6459 | spin_unlock_irqrestore(&ioc->raid_device_lock, |
| 6460 | flags); |
| 6461 | return; |
| 6462 | } |
| 6463 | pr_info("\thandle changed from(0x%04x)!!!\n", |
| 6464 | raid_device->handle); |
| 6465 | raid_device->handle = handle; |
| 6466 | if (sas_target_priv_data) |
| 6467 | sas_target_priv_data->handle = handle; |
| 6468 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6469 | return; |
| 6470 | } |
| 6471 | } |
| 6472 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6473 | } |
| 6474 | |
| 6475 | /** |
| 6476 | * _scsih_search_responding_raid_devices - |
| 6477 | * @ioc: per adapter object |
| 6478 | * |
| 6479 | * After host reset, find out whether devices are still responding. |
| 6480 | * If not remove. |
| 6481 | * |
| 6482 | * Return nothing. |
| 6483 | */ |
| 6484 | static void |
| 6485 | _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc) |
| 6486 | { |
| 6487 | Mpi2RaidVolPage1_t volume_pg1; |
| 6488 | Mpi2RaidVolPage0_t volume_pg0; |
| 6489 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 6490 | Mpi2ConfigReply_t mpi_reply; |
| 6491 | u16 ioc_status; |
| 6492 | u16 handle; |
| 6493 | u8 phys_disk_num; |
| 6494 | |
| 6495 | if (!ioc->ir_firmware) |
| 6496 | return; |
| 6497 | |
| 6498 | pr_info(MPT3SAS_FMT "search for raid volumes: start\n", |
| 6499 | ioc->name); |
| 6500 | |
| 6501 | if (list_empty(&ioc->raid_device_list)) |
| 6502 | goto out; |
| 6503 | |
| 6504 | handle = 0xFFFF; |
| 6505 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 6506 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 6507 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6508 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 14be49a | 2013-06-29 03:53:02 +0530 | [diff] [blame] | 6509 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6510 | break; |
| 6511 | handle = le16_to_cpu(volume_pg1.DevHandle); |
| 6512 | |
| 6513 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 6514 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 6515 | sizeof(Mpi2RaidVolPage0_t))) |
| 6516 | continue; |
| 6517 | |
| 6518 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 6519 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 6520 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) |
| 6521 | _scsih_mark_responding_raid_device(ioc, |
| 6522 | le64_to_cpu(volume_pg1.WWID), handle); |
| 6523 | } |
| 6524 | |
| 6525 | /* refresh the pd_handles */ |
| 6526 | phys_disk_num = 0xFF; |
| 6527 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); |
| 6528 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 6529 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 6530 | phys_disk_num))) { |
| 6531 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6532 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 14be49a | 2013-06-29 03:53:02 +0530 | [diff] [blame] | 6533 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6534 | break; |
| 6535 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 6536 | handle = le16_to_cpu(pd_pg0.DevHandle); |
| 6537 | set_bit(handle, ioc->pd_handles); |
| 6538 | } |
| 6539 | out: |
| 6540 | pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n", |
| 6541 | ioc->name); |
| 6542 | } |
| 6543 | |
| 6544 | /** |
| 6545 | * _scsih_mark_responding_expander - mark a expander as responding |
| 6546 | * @ioc: per adapter object |
| 6547 | * @sas_address: sas address |
| 6548 | * @handle: |
| 6549 | * |
| 6550 | * After host reset, find out whether devices are still responding. |
| 6551 | * Used in _scsih_remove_unresponsive_expanders. |
| 6552 | * |
| 6553 | * Return nothing. |
| 6554 | */ |
| 6555 | static void |
| 6556 | _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, |
| 6557 | u16 handle) |
| 6558 | { |
| 6559 | struct _sas_node *sas_expander; |
| 6560 | unsigned long flags; |
| 6561 | int i; |
| 6562 | |
| 6563 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 6564 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 6565 | if (sas_expander->sas_address != sas_address) |
| 6566 | continue; |
| 6567 | sas_expander->responding = 1; |
| 6568 | if (sas_expander->handle == handle) |
| 6569 | goto out; |
| 6570 | pr_info("\texpander(0x%016llx): handle changed" \ |
| 6571 | " from(0x%04x) to (0x%04x)!!!\n", |
| 6572 | (unsigned long long)sas_expander->sas_address, |
| 6573 | sas_expander->handle, handle); |
| 6574 | sas_expander->handle = handle; |
| 6575 | for (i = 0 ; i < sas_expander->num_phys ; i++) |
| 6576 | sas_expander->phy[i].handle = handle; |
| 6577 | goto out; |
| 6578 | } |
| 6579 | out: |
| 6580 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 6581 | } |
| 6582 | |
| 6583 | /** |
| 6584 | * _scsih_search_responding_expanders - |
| 6585 | * @ioc: per adapter object |
| 6586 | * |
| 6587 | * After host reset, find out whether devices are still responding. |
| 6588 | * If not remove. |
| 6589 | * |
| 6590 | * Return nothing. |
| 6591 | */ |
| 6592 | static void |
| 6593 | _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc) |
| 6594 | { |
| 6595 | Mpi2ExpanderPage0_t expander_pg0; |
| 6596 | Mpi2ConfigReply_t mpi_reply; |
| 6597 | u16 ioc_status; |
| 6598 | u64 sas_address; |
| 6599 | u16 handle; |
| 6600 | |
| 6601 | pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name); |
| 6602 | |
| 6603 | if (list_empty(&ioc->sas_expander_list)) |
| 6604 | goto out; |
| 6605 | |
| 6606 | handle = 0xFFFF; |
| 6607 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 6608 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 6609 | |
| 6610 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6611 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 14be49a | 2013-06-29 03:53:02 +0530 | [diff] [blame] | 6612 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6613 | break; |
| 6614 | |
| 6615 | handle = le16_to_cpu(expander_pg0.DevHandle); |
| 6616 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
| 6617 | pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n", |
| 6618 | handle, |
| 6619 | (unsigned long long)sas_address); |
| 6620 | _scsih_mark_responding_expander(ioc, sas_address, handle); |
| 6621 | } |
| 6622 | |
| 6623 | out: |
| 6624 | pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name); |
| 6625 | } |
| 6626 | |
| 6627 | /** |
| 6628 | * _scsih_remove_unresponding_sas_devices - removing unresponding devices |
| 6629 | * @ioc: per adapter object |
| 6630 | * |
| 6631 | * Return nothing. |
| 6632 | */ |
| 6633 | static void |
| 6634 | _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc) |
| 6635 | { |
| 6636 | struct _sas_device *sas_device, *sas_device_next; |
| 6637 | struct _sas_node *sas_expander, *sas_expander_next; |
| 6638 | struct _raid_device *raid_device, *raid_device_next; |
| 6639 | struct list_head tmp_list; |
| 6640 | unsigned long flags; |
| 6641 | |
| 6642 | pr_info(MPT3SAS_FMT "removing unresponding devices: start\n", |
| 6643 | ioc->name); |
| 6644 | |
| 6645 | /* removing unresponding end devices */ |
| 6646 | pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n", |
| 6647 | ioc->name); |
| 6648 | list_for_each_entry_safe(sas_device, sas_device_next, |
| 6649 | &ioc->sas_device_list, list) { |
| 6650 | if (!sas_device->responding) |
| 6651 | mpt3sas_device_remove_by_sas_address(ioc, |
| 6652 | sas_device->sas_address); |
| 6653 | else |
| 6654 | sas_device->responding = 0; |
| 6655 | } |
| 6656 | |
| 6657 | /* removing unresponding volumes */ |
| 6658 | if (ioc->ir_firmware) { |
| 6659 | pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n", |
| 6660 | ioc->name); |
| 6661 | list_for_each_entry_safe(raid_device, raid_device_next, |
| 6662 | &ioc->raid_device_list, list) { |
| 6663 | if (!raid_device->responding) |
| 6664 | _scsih_sas_volume_delete(ioc, |
| 6665 | raid_device->handle); |
| 6666 | else |
| 6667 | raid_device->responding = 0; |
| 6668 | } |
| 6669 | } |
| 6670 | |
| 6671 | /* removing unresponding expanders */ |
| 6672 | pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n", |
| 6673 | ioc->name); |
| 6674 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 6675 | INIT_LIST_HEAD(&tmp_list); |
| 6676 | list_for_each_entry_safe(sas_expander, sas_expander_next, |
| 6677 | &ioc->sas_expander_list, list) { |
| 6678 | if (!sas_expander->responding) |
| 6679 | list_move_tail(&sas_expander->list, &tmp_list); |
| 6680 | else |
| 6681 | sas_expander->responding = 0; |
| 6682 | } |
| 6683 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 6684 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, |
| 6685 | list) { |
| 6686 | list_del(&sas_expander->list); |
| 6687 | _scsih_expander_node_remove(ioc, sas_expander); |
| 6688 | } |
| 6689 | |
| 6690 | pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n", |
| 6691 | ioc->name); |
| 6692 | |
| 6693 | /* unblock devices */ |
| 6694 | _scsih_ublock_io_all_device(ioc); |
| 6695 | } |
| 6696 | |
| 6697 | static void |
| 6698 | _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc, |
| 6699 | struct _sas_node *sas_expander, u16 handle) |
| 6700 | { |
| 6701 | Mpi2ExpanderPage1_t expander_pg1; |
| 6702 | Mpi2ConfigReply_t mpi_reply; |
| 6703 | int i; |
| 6704 | |
| 6705 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 6706 | if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 6707 | &expander_pg1, i, handle))) { |
| 6708 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 6709 | ioc->name, __FILE__, __LINE__, __func__); |
| 6710 | return; |
| 6711 | } |
| 6712 | |
| 6713 | mpt3sas_transport_update_links(ioc, sas_expander->sas_address, |
| 6714 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, |
| 6715 | expander_pg1.NegotiatedLinkRate >> 4); |
| 6716 | } |
| 6717 | } |
| 6718 | |
| 6719 | /** |
| 6720 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset |
| 6721 | * @ioc: per adapter object |
| 6722 | * |
| 6723 | * Return nothing. |
| 6724 | */ |
| 6725 | static void |
| 6726 | _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc) |
| 6727 | { |
| 6728 | Mpi2ExpanderPage0_t expander_pg0; |
| 6729 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6730 | Mpi2RaidVolPage1_t volume_pg1; |
| 6731 | Mpi2RaidVolPage0_t volume_pg0; |
| 6732 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 6733 | Mpi2EventIrConfigElement_t element; |
| 6734 | Mpi2ConfigReply_t mpi_reply; |
| 6735 | u8 phys_disk_num; |
| 6736 | u16 ioc_status; |
| 6737 | u16 handle, parent_handle; |
| 6738 | u64 sas_address; |
| 6739 | struct _sas_device *sas_device; |
| 6740 | struct _sas_node *expander_device; |
| 6741 | static struct _raid_device *raid_device; |
| 6742 | u8 retry_count; |
| 6743 | unsigned long flags; |
| 6744 | |
| 6745 | pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name); |
| 6746 | |
| 6747 | _scsih_sas_host_refresh(ioc); |
| 6748 | |
| 6749 | pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name); |
| 6750 | |
| 6751 | /* expanders */ |
| 6752 | handle = 0xFFFF; |
| 6753 | while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 6754 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 6755 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6756 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6757 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6758 | pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \ |
| 6759 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 6760 | ioc->name, ioc_status, |
| 6761 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 6762 | break; |
| 6763 | } |
| 6764 | handle = le16_to_cpu(expander_pg0.DevHandle); |
| 6765 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 6766 | expander_device = mpt3sas_scsih_expander_find_by_sas_address( |
| 6767 | ioc, le64_to_cpu(expander_pg0.SASAddress)); |
| 6768 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 6769 | if (expander_device) |
| 6770 | _scsih_refresh_expander_links(ioc, expander_device, |
| 6771 | handle); |
| 6772 | else { |
| 6773 | pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \ |
| 6774 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, |
| 6775 | handle, (unsigned long long) |
| 6776 | le64_to_cpu(expander_pg0.SASAddress)); |
| 6777 | _scsih_expander_add(ioc, handle); |
| 6778 | pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \ |
| 6779 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, |
| 6780 | handle, (unsigned long long) |
| 6781 | le64_to_cpu(expander_pg0.SASAddress)); |
| 6782 | } |
| 6783 | } |
| 6784 | |
| 6785 | pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n", |
| 6786 | ioc->name); |
| 6787 | |
| 6788 | if (!ioc->ir_firmware) |
| 6789 | goto skip_to_sas; |
| 6790 | |
| 6791 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name); |
| 6792 | |
| 6793 | /* phys disk */ |
| 6794 | phys_disk_num = 0xFF; |
| 6795 | while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 6796 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 6797 | phys_disk_num))) { |
| 6798 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6799 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6800 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6801 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\ |
| 6802 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 6803 | ioc->name, ioc_status, |
| 6804 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 6805 | break; |
| 6806 | } |
| 6807 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 6808 | handle = le16_to_cpu(pd_pg0.DevHandle); |
| 6809 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6810 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6811 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6812 | if (sas_device) |
| 6813 | continue; |
| 6814 | if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6815 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 6816 | handle) != 0) |
| 6817 | continue; |
| 6818 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6819 | MPI2_IOCSTATUS_MASK; |
| 6820 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6821 | pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \ |
| 6822 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 6823 | ioc->name, ioc_status, |
| 6824 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 6825 | break; |
| 6826 | } |
| 6827 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6828 | if (!_scsih_get_sas_address(ioc, parent_handle, |
| 6829 | &sas_address)) { |
| 6830 | pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \ |
| 6831 | " handle (0x%04x), sas_addr(0x%016llx)\n", |
| 6832 | ioc->name, handle, (unsigned long long) |
| 6833 | le64_to_cpu(sas_device_pg0.SASAddress)); |
| 6834 | mpt3sas_transport_update_links(ioc, sas_address, |
| 6835 | handle, sas_device_pg0.PhyNum, |
| 6836 | MPI2_SAS_NEG_LINK_RATE_1_5); |
| 6837 | set_bit(handle, ioc->pd_handles); |
| 6838 | retry_count = 0; |
| 6839 | /* This will retry adding the end device. |
| 6840 | * _scsih_add_device() will decide on retries and |
| 6841 | * return "1" when it should be retried |
| 6842 | */ |
| 6843 | while (_scsih_add_device(ioc, handle, retry_count++, |
| 6844 | 1)) { |
| 6845 | ssleep(1); |
| 6846 | } |
| 6847 | pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \ |
| 6848 | " handle (0x%04x), sas_addr(0x%016llx)\n", |
| 6849 | ioc->name, handle, (unsigned long long) |
| 6850 | le64_to_cpu(sas_device_pg0.SASAddress)); |
| 6851 | } |
| 6852 | } |
| 6853 | |
| 6854 | pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n", |
| 6855 | ioc->name); |
| 6856 | |
| 6857 | pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name); |
| 6858 | |
| 6859 | /* volumes */ |
| 6860 | handle = 0xFFFF; |
| 6861 | while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 6862 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 6863 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6864 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6865 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6866 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ |
| 6867 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 6868 | ioc->name, ioc_status, |
| 6869 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 6870 | break; |
| 6871 | } |
| 6872 | handle = le16_to_cpu(volume_pg1.DevHandle); |
| 6873 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6874 | raid_device = _scsih_raid_device_find_by_wwid(ioc, |
| 6875 | le64_to_cpu(volume_pg1.WWID)); |
| 6876 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6877 | if (raid_device) |
| 6878 | continue; |
| 6879 | if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 6880 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 6881 | sizeof(Mpi2RaidVolPage0_t))) |
| 6882 | continue; |
| 6883 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6884 | MPI2_IOCSTATUS_MASK; |
| 6885 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6886 | pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \ |
| 6887 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 6888 | ioc->name, ioc_status, |
| 6889 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 6890 | break; |
| 6891 | } |
| 6892 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 6893 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 6894 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { |
| 6895 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); |
| 6896 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; |
| 6897 | element.VolDevHandle = volume_pg1.DevHandle; |
| 6898 | pr_info(MPT3SAS_FMT |
| 6899 | "\tBEFORE adding volume: handle (0x%04x)\n", |
| 6900 | ioc->name, volume_pg1.DevHandle); |
| 6901 | _scsih_sas_volume_add(ioc, &element); |
| 6902 | pr_info(MPT3SAS_FMT |
| 6903 | "\tAFTER adding volume: handle (0x%04x)\n", |
| 6904 | ioc->name, volume_pg1.DevHandle); |
| 6905 | } |
| 6906 | } |
| 6907 | |
| 6908 | pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n", |
| 6909 | ioc->name); |
| 6910 | |
| 6911 | skip_to_sas: |
| 6912 | |
| 6913 | pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n", |
| 6914 | ioc->name); |
| 6915 | |
| 6916 | /* sas devices */ |
| 6917 | handle = 0xFFFF; |
| 6918 | while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6919 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 6920 | handle))) { |
| 6921 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6922 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6923 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6924 | pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\ |
| 6925 | " ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 6926 | ioc->name, ioc_status, |
| 6927 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 6928 | break; |
| 6929 | } |
| 6930 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 6931 | if (!(_scsih_is_end_device( |
| 6932 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) |
| 6933 | continue; |
| 6934 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6935 | sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc, |
| 6936 | le64_to_cpu(sas_device_pg0.SASAddress)); |
| 6937 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6938 | if (sas_device) |
| 6939 | continue; |
| 6940 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6941 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { |
| 6942 | pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \ |
| 6943 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, |
| 6944 | handle, (unsigned long long) |
| 6945 | le64_to_cpu(sas_device_pg0.SASAddress)); |
| 6946 | mpt3sas_transport_update_links(ioc, sas_address, handle, |
| 6947 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
| 6948 | retry_count = 0; |
| 6949 | /* This will retry adding the end device. |
| 6950 | * _scsih_add_device() will decide on retries and |
| 6951 | * return "1" when it should be retried |
| 6952 | */ |
| 6953 | while (_scsih_add_device(ioc, handle, retry_count++, |
| 6954 | 0)) { |
| 6955 | ssleep(1); |
| 6956 | } |
| 6957 | pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \ |
| 6958 | "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name, |
| 6959 | handle, (unsigned long long) |
| 6960 | le64_to_cpu(sas_device_pg0.SASAddress)); |
| 6961 | } |
| 6962 | } |
| 6963 | pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n", |
| 6964 | ioc->name); |
| 6965 | |
| 6966 | pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name); |
| 6967 | } |
| 6968 | /** |
| 6969 | * mpt3sas_scsih_reset_handler - reset callback handler (for scsih) |
| 6970 | * @ioc: per adapter object |
| 6971 | * @reset_phase: phase |
| 6972 | * |
| 6973 | * The handler for doing any required cleanup or initialization. |
| 6974 | * |
| 6975 | * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET, |
| 6976 | * MPT3_IOC_DONE_RESET |
| 6977 | * |
| 6978 | * Return nothing. |
| 6979 | */ |
| 6980 | void |
| 6981 | mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase) |
| 6982 | { |
| 6983 | switch (reset_phase) { |
| 6984 | case MPT3_IOC_PRE_RESET: |
| 6985 | dtmprintk(ioc, pr_info(MPT3SAS_FMT |
| 6986 | "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__)); |
| 6987 | break; |
| 6988 | case MPT3_IOC_AFTER_RESET: |
| 6989 | dtmprintk(ioc, pr_info(MPT3SAS_FMT |
| 6990 | "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__)); |
| 6991 | if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) { |
| 6992 | ioc->scsih_cmds.status |= MPT3_CMD_RESET; |
| 6993 | mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid); |
| 6994 | complete(&ioc->scsih_cmds.done); |
| 6995 | } |
| 6996 | if (ioc->tm_cmds.status & MPT3_CMD_PENDING) { |
| 6997 | ioc->tm_cmds.status |= MPT3_CMD_RESET; |
| 6998 | mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid); |
| 6999 | complete(&ioc->tm_cmds.done); |
| 7000 | } |
| 7001 | |
| 7002 | _scsih_fw_event_cleanup_queue(ioc); |
| 7003 | _scsih_flush_running_cmds(ioc); |
| 7004 | break; |
| 7005 | case MPT3_IOC_DONE_RESET: |
| 7006 | dtmprintk(ioc, pr_info(MPT3SAS_FMT |
| 7007 | "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__)); |
| 7008 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && |
| 7009 | !ioc->sas_hba.num_phys)) { |
| 7010 | _scsih_prep_device_scan(ioc); |
| 7011 | _scsih_search_responding_sas_devices(ioc); |
| 7012 | _scsih_search_responding_raid_devices(ioc); |
| 7013 | _scsih_search_responding_expanders(ioc); |
| 7014 | _scsih_error_recovery_delete_devices(ioc); |
| 7015 | } |
| 7016 | break; |
| 7017 | } |
| 7018 | } |
| 7019 | |
| 7020 | /** |
| 7021 | * _mpt3sas_fw_work - delayed task for processing firmware events |
| 7022 | * @ioc: per adapter object |
| 7023 | * @fw_event: The fw_event_work object |
| 7024 | * Context: user. |
| 7025 | * |
| 7026 | * Return nothing. |
| 7027 | */ |
| 7028 | static void |
| 7029 | _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event) |
| 7030 | { |
| 7031 | /* the queue is being flushed so ignore this event */ |
| 7032 | if (ioc->remove_host || fw_event->cancel_pending_work || |
| 7033 | ioc->pci_error_recovery) { |
| 7034 | _scsih_fw_event_free(ioc, fw_event); |
| 7035 | return; |
| 7036 | } |
| 7037 | |
| 7038 | switch (fw_event->event) { |
| 7039 | case MPT3SAS_PROCESS_TRIGGER_DIAG: |
| 7040 | mpt3sas_process_trigger_data(ioc, fw_event->event_data); |
| 7041 | break; |
| 7042 | case MPT3SAS_REMOVE_UNRESPONDING_DEVICES: |
| 7043 | while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery) |
| 7044 | ssleep(1); |
| 7045 | _scsih_remove_unresponding_sas_devices(ioc); |
| 7046 | _scsih_scan_for_devices_after_reset(ioc); |
| 7047 | break; |
| 7048 | case MPT3SAS_PORT_ENABLE_COMPLETE: |
| 7049 | ioc->start_scan = 0; |
| 7050 | if (missing_delay[0] != -1 && missing_delay[1] != -1) |
| 7051 | mpt3sas_base_update_missing_delay(ioc, missing_delay[0], |
| 7052 | missing_delay[1]); |
| 7053 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 7054 | "port enable: complete from worker thread\n", |
| 7055 | ioc->name)); |
| 7056 | break; |
| 7057 | case MPT3SAS_TURN_ON_FAULT_LED: |
| 7058 | _scsih_turn_on_fault_led(ioc, fw_event->device_handle); |
| 7059 | break; |
| 7060 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
| 7061 | _scsih_sas_topology_change_event(ioc, fw_event); |
| 7062 | break; |
| 7063 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 7064 | _scsih_sas_device_status_change_event(ioc, fw_event); |
| 7065 | break; |
| 7066 | case MPI2_EVENT_SAS_DISCOVERY: |
| 7067 | _scsih_sas_discovery_event(ioc, fw_event); |
| 7068 | break; |
| 7069 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 7070 | _scsih_sas_broadcast_primitive_event(ioc, fw_event); |
| 7071 | break; |
| 7072 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
| 7073 | _scsih_sas_enclosure_dev_status_change_event(ioc, |
| 7074 | fw_event); |
| 7075 | break; |
| 7076 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
| 7077 | _scsih_sas_ir_config_change_event(ioc, fw_event); |
| 7078 | break; |
| 7079 | case MPI2_EVENT_IR_VOLUME: |
| 7080 | _scsih_sas_ir_volume_event(ioc, fw_event); |
| 7081 | break; |
| 7082 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
| 7083 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); |
| 7084 | break; |
| 7085 | case MPI2_EVENT_IR_OPERATION_STATUS: |
| 7086 | _scsih_sas_ir_operation_status_event(ioc, fw_event); |
| 7087 | break; |
| 7088 | } |
| 7089 | _scsih_fw_event_free(ioc, fw_event); |
| 7090 | } |
| 7091 | |
| 7092 | /** |
| 7093 | * _firmware_event_work |
| 7094 | * @ioc: per adapter object |
| 7095 | * @work: The fw_event_work object |
| 7096 | * Context: user. |
| 7097 | * |
| 7098 | * wrappers for the work thread handling firmware events |
| 7099 | * |
| 7100 | * Return nothing. |
| 7101 | */ |
| 7102 | |
| 7103 | static void |
| 7104 | _firmware_event_work(struct work_struct *work) |
| 7105 | { |
| 7106 | struct fw_event_work *fw_event = container_of(work, |
| 7107 | struct fw_event_work, work); |
| 7108 | |
| 7109 | _mpt3sas_fw_work(fw_event->ioc, fw_event); |
| 7110 | } |
| 7111 | |
| 7112 | /** |
| 7113 | * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time) |
| 7114 | * @ioc: per adapter object |
| 7115 | * @msix_index: MSIX table index supplied by the OS |
| 7116 | * @reply: reply message frame(lower 32bit addr) |
| 7117 | * Context: interrupt. |
| 7118 | * |
| 7119 | * This function merely adds a new work task into ioc->firmware_event_thread. |
| 7120 | * The tasks are worked from _firmware_event_work in user context. |
| 7121 | * |
| 7122 | * Return 1 meaning mf should be freed from _base_interrupt |
| 7123 | * 0 means the mf is freed from this function. |
| 7124 | */ |
| 7125 | u8 |
| 7126 | mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, |
| 7127 | u32 reply) |
| 7128 | { |
| 7129 | struct fw_event_work *fw_event; |
| 7130 | Mpi2EventNotificationReply_t *mpi_reply; |
| 7131 | u16 event; |
| 7132 | u16 sz; |
| 7133 | |
| 7134 | /* events turned off due to host reset or driver unloading */ |
| 7135 | if (ioc->remove_host || ioc->pci_error_recovery) |
| 7136 | return 1; |
| 7137 | |
| 7138 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 7139 | |
| 7140 | if (unlikely(!mpi_reply)) { |
| 7141 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 7142 | ioc->name, __FILE__, __LINE__, __func__); |
| 7143 | return 1; |
| 7144 | } |
| 7145 | |
| 7146 | event = le16_to_cpu(mpi_reply->Event); |
| 7147 | |
| 7148 | if (event != MPI2_EVENT_LOG_ENTRY_ADDED) |
| 7149 | mpt3sas_trigger_event(ioc, event, 0); |
| 7150 | |
| 7151 | switch (event) { |
| 7152 | /* handle these */ |
| 7153 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 7154 | { |
| 7155 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = |
| 7156 | (Mpi2EventDataSasBroadcastPrimitive_t *) |
| 7157 | mpi_reply->EventData; |
| 7158 | |
| 7159 | if (baen_data->Primitive != |
| 7160 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) |
| 7161 | return 1; |
| 7162 | |
| 7163 | if (ioc->broadcast_aen_busy) { |
| 7164 | ioc->broadcast_aen_pending++; |
| 7165 | return 1; |
| 7166 | } else |
| 7167 | ioc->broadcast_aen_busy = 1; |
| 7168 | break; |
| 7169 | } |
| 7170 | |
| 7171 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
| 7172 | _scsih_check_topo_delete_events(ioc, |
| 7173 | (Mpi2EventDataSasTopologyChangeList_t *) |
| 7174 | mpi_reply->EventData); |
| 7175 | break; |
| 7176 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
| 7177 | _scsih_check_ir_config_unhide_events(ioc, |
| 7178 | (Mpi2EventDataIrConfigChangeList_t *) |
| 7179 | mpi_reply->EventData); |
| 7180 | break; |
| 7181 | case MPI2_EVENT_IR_VOLUME: |
| 7182 | _scsih_check_volume_delete_events(ioc, |
| 7183 | (Mpi2EventDataIrVolume_t *) |
| 7184 | mpi_reply->EventData); |
| 7185 | break; |
| 7186 | |
| 7187 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 7188 | case MPI2_EVENT_IR_OPERATION_STATUS: |
| 7189 | case MPI2_EVENT_SAS_DISCOVERY: |
| 7190 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
| 7191 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
| 7192 | break; |
| 7193 | |
| 7194 | default: /* ignore the rest */ |
| 7195 | return 1; |
| 7196 | } |
| 7197 | |
| 7198 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 7199 | if (!fw_event) { |
| 7200 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 7201 | ioc->name, __FILE__, __LINE__, __func__); |
| 7202 | return 1; |
| 7203 | } |
| 7204 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
| 7205 | fw_event->event_data = kzalloc(sz, GFP_ATOMIC); |
| 7206 | if (!fw_event->event_data) { |
| 7207 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 7208 | ioc->name, __FILE__, __LINE__, __func__); |
| 7209 | kfree(fw_event); |
| 7210 | return 1; |
| 7211 | } |
| 7212 | |
| 7213 | memcpy(fw_event->event_data, mpi_reply->EventData, sz); |
| 7214 | fw_event->ioc = ioc; |
| 7215 | fw_event->VF_ID = mpi_reply->VF_ID; |
| 7216 | fw_event->VP_ID = mpi_reply->VP_ID; |
| 7217 | fw_event->event = event; |
| 7218 | _scsih_fw_event_add(ioc, fw_event); |
| 7219 | return 1; |
| 7220 | } |
| 7221 | |
| 7222 | /* shost template */ |
| 7223 | static struct scsi_host_template scsih_driver_template = { |
| 7224 | .module = THIS_MODULE, |
| 7225 | .name = "Fusion MPT SAS Host", |
| 7226 | .proc_name = MPT3SAS_DRIVER_NAME, |
| 7227 | .queuecommand = _scsih_qcmd, |
| 7228 | .target_alloc = _scsih_target_alloc, |
| 7229 | .slave_alloc = _scsih_slave_alloc, |
| 7230 | .slave_configure = _scsih_slave_configure, |
| 7231 | .target_destroy = _scsih_target_destroy, |
| 7232 | .slave_destroy = _scsih_slave_destroy, |
| 7233 | .scan_finished = _scsih_scan_finished, |
| 7234 | .scan_start = _scsih_scan_start, |
| 7235 | .change_queue_depth = _scsih_change_queue_depth, |
| 7236 | .change_queue_type = _scsih_change_queue_type, |
| 7237 | .eh_abort_handler = _scsih_abort, |
| 7238 | .eh_device_reset_handler = _scsih_dev_reset, |
| 7239 | .eh_target_reset_handler = _scsih_target_reset, |
| 7240 | .eh_host_reset_handler = _scsih_host_reset, |
| 7241 | .bios_param = _scsih_bios_param, |
| 7242 | .can_queue = 1, |
| 7243 | .this_id = -1, |
| 7244 | .sg_tablesize = MPT3SAS_SG_DEPTH, |
| 7245 | .max_sectors = 32767, |
| 7246 | .cmd_per_lun = 7, |
| 7247 | .use_clustering = ENABLE_CLUSTERING, |
| 7248 | .shost_attrs = mpt3sas_host_attrs, |
| 7249 | .sdev_attrs = mpt3sas_dev_attrs, |
| 7250 | }; |
| 7251 | |
| 7252 | /** |
| 7253 | * _scsih_expander_node_remove - removing expander device from list. |
| 7254 | * @ioc: per adapter object |
| 7255 | * @sas_expander: the sas_device object |
| 7256 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 7257 | * |
| 7258 | * Removing object and freeing associated memory from the |
| 7259 | * ioc->sas_expander_list. |
| 7260 | * |
| 7261 | * Return nothing. |
| 7262 | */ |
| 7263 | static void |
| 7264 | _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc, |
| 7265 | struct _sas_node *sas_expander) |
| 7266 | { |
| 7267 | struct _sas_port *mpt3sas_port, *next; |
| 7268 | |
| 7269 | /* remove sibling ports attached to this expander */ |
| 7270 | list_for_each_entry_safe(mpt3sas_port, next, |
| 7271 | &sas_expander->sas_port_list, port_list) { |
| 7272 | if (ioc->shost_recovery) |
| 7273 | return; |
| 7274 | if (mpt3sas_port->remote_identify.device_type == |
| 7275 | SAS_END_DEVICE) |
| 7276 | mpt3sas_device_remove_by_sas_address(ioc, |
| 7277 | mpt3sas_port->remote_identify.sas_address); |
| 7278 | else if (mpt3sas_port->remote_identify.device_type == |
| 7279 | SAS_EDGE_EXPANDER_DEVICE || |
| 7280 | mpt3sas_port->remote_identify.device_type == |
| 7281 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7282 | mpt3sas_expander_remove(ioc, |
| 7283 | mpt3sas_port->remote_identify.sas_address); |
| 7284 | } |
| 7285 | |
| 7286 | mpt3sas_transport_port_remove(ioc, sas_expander->sas_address, |
| 7287 | sas_expander->sas_address_parent); |
| 7288 | |
| 7289 | pr_info(MPT3SAS_FMT |
| 7290 | "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n", |
| 7291 | ioc->name, |
| 7292 | sas_expander->handle, (unsigned long long) |
| 7293 | sas_expander->sas_address); |
| 7294 | |
| 7295 | kfree(sas_expander->phy); |
| 7296 | kfree(sas_expander); |
| 7297 | } |
| 7298 | |
| 7299 | /** |
| 7300 | * _scsih_ir_shutdown - IR shutdown notification |
| 7301 | * @ioc: per adapter object |
| 7302 | * |
| 7303 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that |
| 7304 | * the host system is shutting down. |
| 7305 | * |
| 7306 | * Return nothing. |
| 7307 | */ |
| 7308 | static void |
| 7309 | _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc) |
| 7310 | { |
| 7311 | Mpi2RaidActionRequest_t *mpi_request; |
| 7312 | Mpi2RaidActionReply_t *mpi_reply; |
| 7313 | u16 smid; |
| 7314 | |
| 7315 | /* is IR firmware build loaded ? */ |
| 7316 | if (!ioc->ir_firmware) |
| 7317 | return; |
| 7318 | |
| 7319 | /* are there any volumes ? */ |
| 7320 | if (list_empty(&ioc->raid_device_list)) |
| 7321 | return; |
| 7322 | |
| 7323 | mutex_lock(&ioc->scsih_cmds.mutex); |
| 7324 | |
| 7325 | if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { |
| 7326 | pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n", |
| 7327 | ioc->name, __func__); |
| 7328 | goto out; |
| 7329 | } |
| 7330 | ioc->scsih_cmds.status = MPT3_CMD_PENDING; |
| 7331 | |
| 7332 | smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx); |
| 7333 | if (!smid) { |
| 7334 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 7335 | ioc->name, __func__); |
| 7336 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; |
| 7337 | goto out; |
| 7338 | } |
| 7339 | |
| 7340 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 7341 | ioc->scsih_cmds.smid = smid; |
| 7342 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); |
| 7343 | |
| 7344 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; |
| 7345 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; |
| 7346 | |
| 7347 | pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name); |
| 7348 | init_completion(&ioc->scsih_cmds.done); |
| 7349 | mpt3sas_base_put_smid_default(ioc, smid); |
| 7350 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
| 7351 | |
| 7352 | if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) { |
| 7353 | pr_err(MPT3SAS_FMT "%s: timeout\n", |
| 7354 | ioc->name, __func__); |
| 7355 | goto out; |
| 7356 | } |
| 7357 | |
| 7358 | if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) { |
| 7359 | mpi_reply = ioc->scsih_cmds.reply; |
| 7360 | pr_info(MPT3SAS_FMT |
| 7361 | "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7362 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 7363 | le32_to_cpu(mpi_reply->IOCLogInfo)); |
| 7364 | } |
| 7365 | |
| 7366 | out: |
| 7367 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; |
| 7368 | mutex_unlock(&ioc->scsih_cmds.mutex); |
| 7369 | } |
| 7370 | |
| 7371 | /** |
| 7372 | * _scsih_remove - detach and remove add host |
| 7373 | * @pdev: PCI device struct |
| 7374 | * |
| 7375 | * Routine called when unloading the driver. |
| 7376 | * Return nothing. |
| 7377 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7378 | static void _scsih_remove(struct pci_dev *pdev) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 7379 | { |
| 7380 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7381 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 7382 | struct _sas_port *mpt3sas_port, *next_port; |
| 7383 | struct _raid_device *raid_device, *next; |
| 7384 | struct MPT3SAS_TARGET *sas_target_priv_data; |
| 7385 | struct workqueue_struct *wq; |
| 7386 | unsigned long flags; |
| 7387 | |
| 7388 | ioc->remove_host = 1; |
| 7389 | _scsih_fw_event_cleanup_queue(ioc); |
| 7390 | |
| 7391 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7392 | wq = ioc->firmware_event_thread; |
| 7393 | ioc->firmware_event_thread = NULL; |
| 7394 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7395 | if (wq) |
| 7396 | destroy_workqueue(wq); |
| 7397 | |
| 7398 | /* release all the volumes */ |
| 7399 | _scsih_ir_shutdown(ioc); |
| 7400 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, |
| 7401 | list) { |
| 7402 | if (raid_device->starget) { |
| 7403 | sas_target_priv_data = |
| 7404 | raid_device->starget->hostdata; |
| 7405 | sas_target_priv_data->deleted = 1; |
| 7406 | scsi_remove_target(&raid_device->starget->dev); |
| 7407 | } |
| 7408 | pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n", |
| 7409 | ioc->name, raid_device->handle, |
| 7410 | (unsigned long long) raid_device->wwid); |
| 7411 | _scsih_raid_device_remove(ioc, raid_device); |
| 7412 | } |
| 7413 | |
| 7414 | /* free ports attached to the sas_host */ |
| 7415 | list_for_each_entry_safe(mpt3sas_port, next_port, |
| 7416 | &ioc->sas_hba.sas_port_list, port_list) { |
| 7417 | if (mpt3sas_port->remote_identify.device_type == |
| 7418 | SAS_END_DEVICE) |
| 7419 | mpt3sas_device_remove_by_sas_address(ioc, |
| 7420 | mpt3sas_port->remote_identify.sas_address); |
| 7421 | else if (mpt3sas_port->remote_identify.device_type == |
| 7422 | SAS_EDGE_EXPANDER_DEVICE || |
| 7423 | mpt3sas_port->remote_identify.device_type == |
| 7424 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7425 | mpt3sas_expander_remove(ioc, |
| 7426 | mpt3sas_port->remote_identify.sas_address); |
| 7427 | } |
| 7428 | |
| 7429 | /* free phys attached to the sas_host */ |
| 7430 | if (ioc->sas_hba.num_phys) { |
| 7431 | kfree(ioc->sas_hba.phy); |
| 7432 | ioc->sas_hba.phy = NULL; |
| 7433 | ioc->sas_hba.num_phys = 0; |
| 7434 | } |
| 7435 | |
| 7436 | sas_remove_host(shost); |
| 7437 | mpt3sas_base_detach(ioc); |
| 7438 | list_del(&ioc->list); |
| 7439 | scsi_remove_host(shost); |
| 7440 | scsi_host_put(shost); |
| 7441 | } |
| 7442 | |
| 7443 | /** |
| 7444 | * _scsih_shutdown - routine call during system shutdown |
| 7445 | * @pdev: PCI device struct |
| 7446 | * |
| 7447 | * Return nothing. |
| 7448 | */ |
| 7449 | static void |
| 7450 | _scsih_shutdown(struct pci_dev *pdev) |
| 7451 | { |
| 7452 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7453 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 7454 | struct workqueue_struct *wq; |
| 7455 | unsigned long flags; |
| 7456 | |
| 7457 | ioc->remove_host = 1; |
| 7458 | _scsih_fw_event_cleanup_queue(ioc); |
| 7459 | |
| 7460 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7461 | wq = ioc->firmware_event_thread; |
| 7462 | ioc->firmware_event_thread = NULL; |
| 7463 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7464 | if (wq) |
| 7465 | destroy_workqueue(wq); |
| 7466 | |
| 7467 | _scsih_ir_shutdown(ioc); |
| 7468 | mpt3sas_base_detach(ioc); |
| 7469 | } |
| 7470 | |
| 7471 | |
| 7472 | /** |
| 7473 | * _scsih_probe_boot_devices - reports 1st device |
| 7474 | * @ioc: per adapter object |
| 7475 | * |
| 7476 | * If specified in bios page 2, this routine reports the 1st |
| 7477 | * device scsi-ml or sas transport for persistent boot device |
| 7478 | * purposes. Please refer to function _scsih_determine_boot_device() |
| 7479 | */ |
| 7480 | static void |
| 7481 | _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc) |
| 7482 | { |
| 7483 | u8 is_raid; |
| 7484 | void *device; |
| 7485 | struct _sas_device *sas_device; |
| 7486 | struct _raid_device *raid_device; |
| 7487 | u16 handle; |
| 7488 | u64 sas_address_parent; |
| 7489 | u64 sas_address; |
| 7490 | unsigned long flags; |
| 7491 | int rc; |
| 7492 | |
| 7493 | /* no Bios, return immediately */ |
| 7494 | if (!ioc->bios_pg3.BiosVersion) |
| 7495 | return; |
| 7496 | |
| 7497 | device = NULL; |
| 7498 | is_raid = 0; |
| 7499 | if (ioc->req_boot_device.device) { |
| 7500 | device = ioc->req_boot_device.device; |
| 7501 | is_raid = ioc->req_boot_device.is_raid; |
| 7502 | } else if (ioc->req_alt_boot_device.device) { |
| 7503 | device = ioc->req_alt_boot_device.device; |
| 7504 | is_raid = ioc->req_alt_boot_device.is_raid; |
| 7505 | } else if (ioc->current_boot_device.device) { |
| 7506 | device = ioc->current_boot_device.device; |
| 7507 | is_raid = ioc->current_boot_device.is_raid; |
| 7508 | } |
| 7509 | |
| 7510 | if (!device) |
| 7511 | return; |
| 7512 | |
| 7513 | if (is_raid) { |
| 7514 | raid_device = device; |
| 7515 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7516 | raid_device->id, 0); |
| 7517 | if (rc) |
| 7518 | _scsih_raid_device_remove(ioc, raid_device); |
| 7519 | } else { |
| 7520 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 7521 | sas_device = device; |
| 7522 | handle = sas_device->handle; |
| 7523 | sas_address_parent = sas_device->sas_address_parent; |
| 7524 | sas_address = sas_device->sas_address; |
| 7525 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 7526 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 7527 | |
| 7528 | if (!mpt3sas_transport_port_add(ioc, handle, |
| 7529 | sas_address_parent)) { |
| 7530 | _scsih_sas_device_remove(ioc, sas_device); |
| 7531 | } else if (!sas_device->starget) { |
Sreekanth Reddy | f5edbe7 | 2013-06-29 03:54:51 +0530 | [diff] [blame] | 7532 | if (!ioc->is_driver_loading) { |
| 7533 | mpt3sas_transport_port_remove(ioc, |
| 7534 | sas_address, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 7535 | sas_address_parent); |
Sreekanth Reddy | f5edbe7 | 2013-06-29 03:54:51 +0530 | [diff] [blame] | 7536 | _scsih_sas_device_remove(ioc, sas_device); |
| 7537 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 7538 | } |
| 7539 | } |
| 7540 | } |
| 7541 | |
| 7542 | /** |
| 7543 | * _scsih_probe_raid - reporting raid volumes to scsi-ml |
| 7544 | * @ioc: per adapter object |
| 7545 | * |
| 7546 | * Called during initial loading of the driver. |
| 7547 | */ |
| 7548 | static void |
| 7549 | _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc) |
| 7550 | { |
| 7551 | struct _raid_device *raid_device, *raid_next; |
| 7552 | int rc; |
| 7553 | |
| 7554 | list_for_each_entry_safe(raid_device, raid_next, |
| 7555 | &ioc->raid_device_list, list) { |
| 7556 | if (raid_device->starget) |
| 7557 | continue; |
| 7558 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7559 | raid_device->id, 0); |
| 7560 | if (rc) |
| 7561 | _scsih_raid_device_remove(ioc, raid_device); |
| 7562 | } |
| 7563 | } |
| 7564 | |
| 7565 | /** |
| 7566 | * _scsih_probe_sas - reporting sas devices to sas transport |
| 7567 | * @ioc: per adapter object |
| 7568 | * |
| 7569 | * Called during initial loading of the driver. |
| 7570 | */ |
| 7571 | static void |
| 7572 | _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc) |
| 7573 | { |
| 7574 | struct _sas_device *sas_device, *next; |
| 7575 | unsigned long flags; |
| 7576 | |
| 7577 | /* SAS Device List */ |
| 7578 | list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list, |
| 7579 | list) { |
| 7580 | |
| 7581 | if (!mpt3sas_transport_port_add(ioc, sas_device->handle, |
| 7582 | sas_device->sas_address_parent)) { |
| 7583 | list_del(&sas_device->list); |
| 7584 | kfree(sas_device); |
| 7585 | continue; |
| 7586 | } else if (!sas_device->starget) { |
| 7587 | /* |
| 7588 | * When asyn scanning is enabled, its not possible to |
| 7589 | * remove devices while scanning is turned on due to an |
| 7590 | * oops in scsi_sysfs_add_sdev()->add_device()-> |
| 7591 | * sysfs_addrm_start() |
| 7592 | */ |
Sreekanth Reddy | f5edbe7 | 2013-06-29 03:54:51 +0530 | [diff] [blame] | 7593 | if (!ioc->is_driver_loading) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 7594 | mpt3sas_transport_port_remove(ioc, |
| 7595 | sas_device->sas_address, |
| 7596 | sas_device->sas_address_parent); |
Sreekanth Reddy | f5edbe7 | 2013-06-29 03:54:51 +0530 | [diff] [blame] | 7597 | list_del(&sas_device->list); |
| 7598 | kfree(sas_device); |
| 7599 | continue; |
| 7600 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 7601 | } |
| 7602 | |
| 7603 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 7604 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 7605 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 7606 | } |
| 7607 | } |
| 7608 | |
| 7609 | /** |
| 7610 | * _scsih_probe_devices - probing for devices |
| 7611 | * @ioc: per adapter object |
| 7612 | * |
| 7613 | * Called during initial loading of the driver. |
| 7614 | */ |
| 7615 | static void |
| 7616 | _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc) |
| 7617 | { |
| 7618 | u16 volume_mapping_flags; |
| 7619 | |
| 7620 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) |
| 7621 | return; /* return when IOC doesn't support initiator mode */ |
| 7622 | |
| 7623 | _scsih_probe_boot_devices(ioc); |
| 7624 | |
| 7625 | if (ioc->ir_firmware) { |
| 7626 | volume_mapping_flags = |
| 7627 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & |
| 7628 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; |
| 7629 | if (volume_mapping_flags == |
| 7630 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { |
| 7631 | _scsih_probe_raid(ioc); |
| 7632 | _scsih_probe_sas(ioc); |
| 7633 | } else { |
| 7634 | _scsih_probe_sas(ioc); |
| 7635 | _scsih_probe_raid(ioc); |
| 7636 | } |
| 7637 | } else |
| 7638 | _scsih_probe_sas(ioc); |
| 7639 | } |
| 7640 | |
| 7641 | /** |
| 7642 | * _scsih_scan_start - scsi lld callback for .scan_start |
| 7643 | * @shost: SCSI host pointer |
| 7644 | * |
| 7645 | * The shost has the ability to discover targets on its own instead |
| 7646 | * of scanning the entire bus. In our implemention, we will kick off |
| 7647 | * firmware discovery. |
| 7648 | */ |
| 7649 | static void |
| 7650 | _scsih_scan_start(struct Scsi_Host *shost) |
| 7651 | { |
| 7652 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 7653 | int rc; |
| 7654 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) |
| 7655 | mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable); |
| 7656 | |
| 7657 | if (disable_discovery > 0) |
| 7658 | return; |
| 7659 | |
| 7660 | ioc->start_scan = 1; |
| 7661 | rc = mpt3sas_port_enable(ioc); |
| 7662 | |
| 7663 | if (rc != 0) |
| 7664 | pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name); |
| 7665 | } |
| 7666 | |
| 7667 | /** |
| 7668 | * _scsih_scan_finished - scsi lld callback for .scan_finished |
| 7669 | * @shost: SCSI host pointer |
| 7670 | * @time: elapsed time of the scan in jiffies |
| 7671 | * |
| 7672 | * This function will be called periodicallyn until it returns 1 with the |
| 7673 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, |
| 7674 | * we wait for firmware discovery to complete, then return 1. |
| 7675 | */ |
| 7676 | static int |
| 7677 | _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 7678 | { |
| 7679 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 7680 | |
| 7681 | if (disable_discovery > 0) { |
| 7682 | ioc->is_driver_loading = 0; |
| 7683 | ioc->wait_for_discovery_to_complete = 0; |
| 7684 | return 1; |
| 7685 | } |
| 7686 | |
| 7687 | if (time >= (300 * HZ)) { |
| 7688 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; |
| 7689 | pr_info(MPT3SAS_FMT |
| 7690 | "port enable: FAILED with timeout (timeout=300s)\n", |
| 7691 | ioc->name); |
| 7692 | ioc->is_driver_loading = 0; |
| 7693 | return 1; |
| 7694 | } |
| 7695 | |
| 7696 | if (ioc->start_scan) |
| 7697 | return 0; |
| 7698 | |
| 7699 | if (ioc->start_scan_failed) { |
| 7700 | pr_info(MPT3SAS_FMT |
| 7701 | "port enable: FAILED with (ioc_status=0x%08x)\n", |
| 7702 | ioc->name, ioc->start_scan_failed); |
| 7703 | ioc->is_driver_loading = 0; |
| 7704 | ioc->wait_for_discovery_to_complete = 0; |
| 7705 | ioc->remove_host = 1; |
| 7706 | return 1; |
| 7707 | } |
| 7708 | |
| 7709 | pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name); |
| 7710 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; |
| 7711 | |
| 7712 | if (ioc->wait_for_discovery_to_complete) { |
| 7713 | ioc->wait_for_discovery_to_complete = 0; |
| 7714 | _scsih_probe_devices(ioc); |
| 7715 | } |
| 7716 | mpt3sas_base_start_watchdog(ioc); |
| 7717 | ioc->is_driver_loading = 0; |
| 7718 | return 1; |
| 7719 | } |
| 7720 | |
| 7721 | /** |
| 7722 | * _scsih_probe - attach and add scsi host |
| 7723 | * @pdev: PCI device struct |
| 7724 | * @id: pci device id |
| 7725 | * |
| 7726 | * Returns 0 success, anything else error. |
| 7727 | */ |
| 7728 | static int |
| 7729 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 7730 | { |
| 7731 | struct MPT3SAS_ADAPTER *ioc; |
| 7732 | struct Scsi_Host *shost; |
| 7733 | |
| 7734 | shost = scsi_host_alloc(&scsih_driver_template, |
| 7735 | sizeof(struct MPT3SAS_ADAPTER)); |
| 7736 | if (!shost) |
| 7737 | return -ENODEV; |
| 7738 | |
| 7739 | /* init local params */ |
| 7740 | ioc = shost_priv(shost); |
| 7741 | memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER)); |
| 7742 | INIT_LIST_HEAD(&ioc->list); |
| 7743 | list_add_tail(&ioc->list, &mpt3sas_ioc_list); |
| 7744 | ioc->shost = shost; |
| 7745 | ioc->id = mpt_ids++; |
| 7746 | sprintf(ioc->name, "%s%d", MPT3SAS_DRIVER_NAME, ioc->id); |
| 7747 | ioc->pdev = pdev; |
| 7748 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; |
| 7749 | ioc->tm_cb_idx = tm_cb_idx; |
| 7750 | ioc->ctl_cb_idx = ctl_cb_idx; |
| 7751 | ioc->base_cb_idx = base_cb_idx; |
| 7752 | ioc->port_enable_cb_idx = port_enable_cb_idx; |
| 7753 | ioc->transport_cb_idx = transport_cb_idx; |
| 7754 | ioc->scsih_cb_idx = scsih_cb_idx; |
| 7755 | ioc->config_cb_idx = config_cb_idx; |
| 7756 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; |
| 7757 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; |
| 7758 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; |
| 7759 | ioc->logging_level = logging_level; |
| 7760 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; |
| 7761 | /* misc semaphores and spin locks */ |
| 7762 | mutex_init(&ioc->reset_in_progress_mutex); |
| 7763 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
| 7764 | spin_lock_init(&ioc->scsi_lookup_lock); |
| 7765 | spin_lock_init(&ioc->sas_device_lock); |
| 7766 | spin_lock_init(&ioc->sas_node_lock); |
| 7767 | spin_lock_init(&ioc->fw_event_lock); |
| 7768 | spin_lock_init(&ioc->raid_device_lock); |
| 7769 | spin_lock_init(&ioc->diag_trigger_lock); |
| 7770 | |
| 7771 | INIT_LIST_HEAD(&ioc->sas_device_list); |
| 7772 | INIT_LIST_HEAD(&ioc->sas_device_init_list); |
| 7773 | INIT_LIST_HEAD(&ioc->sas_expander_list); |
| 7774 | INIT_LIST_HEAD(&ioc->fw_event_list); |
| 7775 | INIT_LIST_HEAD(&ioc->raid_device_list); |
| 7776 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); |
| 7777 | INIT_LIST_HEAD(&ioc->delayed_tr_list); |
| 7778 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
Joe Lawrence | cf9bd21a | 2013-08-08 16:45:39 -0400 | [diff] [blame] | 7779 | INIT_LIST_HEAD(&ioc->reply_queue_list); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 7780 | |
| 7781 | /* init shost parameters */ |
| 7782 | shost->max_cmd_len = 32; |
| 7783 | shost->max_lun = max_lun; |
| 7784 | shost->transportt = mpt3sas_transport_template; |
| 7785 | shost->unique_id = ioc->id; |
| 7786 | |
| 7787 | if (max_sectors != 0xFFFF) { |
| 7788 | if (max_sectors < 64) { |
| 7789 | shost->max_sectors = 64; |
| 7790 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ |
| 7791 | "for max_sectors, range is 64 to 32767. Assigning " |
| 7792 | "value of 64.\n", ioc->name, max_sectors); |
| 7793 | } else if (max_sectors > 32767) { |
| 7794 | shost->max_sectors = 32767; |
| 7795 | pr_warn(MPT3SAS_FMT "Invalid value %d passed " \ |
| 7796 | "for max_sectors, range is 64 to 32767. Assigning " |
| 7797 | "default value of 32767.\n", ioc->name, |
| 7798 | max_sectors); |
| 7799 | } else { |
| 7800 | shost->max_sectors = max_sectors & 0xFFFE; |
| 7801 | pr_info(MPT3SAS_FMT |
| 7802 | "The max_sectors value is set to %d\n", |
| 7803 | ioc->name, shost->max_sectors); |
| 7804 | } |
| 7805 | } |
| 7806 | |
| 7807 | if ((scsi_add_host(shost, &pdev->dev))) { |
| 7808 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 7809 | ioc->name, __FILE__, __LINE__, __func__); |
| 7810 | list_del(&ioc->list); |
| 7811 | goto out_add_shost_fail; |
| 7812 | } |
| 7813 | |
| 7814 | /* register EEDP capabilities with SCSI layer */ |
| 7815 | if (prot_mask > 0) |
| 7816 | scsi_host_set_prot(shost, prot_mask); |
| 7817 | else |
| 7818 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION |
| 7819 | | SHOST_DIF_TYPE2_PROTECTION |
| 7820 | | SHOST_DIF_TYPE3_PROTECTION); |
| 7821 | |
| 7822 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); |
| 7823 | |
| 7824 | /* event thread */ |
| 7825 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), |
| 7826 | "fw_event%d", ioc->id); |
| 7827 | ioc->firmware_event_thread = create_singlethread_workqueue( |
| 7828 | ioc->firmware_event_name); |
| 7829 | if (!ioc->firmware_event_thread) { |
| 7830 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 7831 | ioc->name, __FILE__, __LINE__, __func__); |
| 7832 | goto out_thread_fail; |
| 7833 | } |
| 7834 | |
| 7835 | ioc->is_driver_loading = 1; |
| 7836 | if ((mpt3sas_base_attach(ioc))) { |
| 7837 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 7838 | ioc->name, __FILE__, __LINE__, __func__); |
| 7839 | goto out_attach_fail; |
| 7840 | } |
| 7841 | scsi_scan_host(shost); |
| 7842 | return 0; |
| 7843 | |
| 7844 | out_attach_fail: |
| 7845 | destroy_workqueue(ioc->firmware_event_thread); |
| 7846 | out_thread_fail: |
| 7847 | list_del(&ioc->list); |
| 7848 | scsi_remove_host(shost); |
| 7849 | out_add_shost_fail: |
| 7850 | scsi_host_put(shost); |
| 7851 | return -ENODEV; |
| 7852 | } |
| 7853 | |
| 7854 | #ifdef CONFIG_PM |
| 7855 | /** |
| 7856 | * _scsih_suspend - power management suspend main entry point |
| 7857 | * @pdev: PCI device struct |
| 7858 | * @state: PM state change to (usually PCI_D3) |
| 7859 | * |
| 7860 | * Returns 0 success, anything else error. |
| 7861 | */ |
| 7862 | static int |
| 7863 | _scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
| 7864 | { |
| 7865 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7866 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 7867 | pci_power_t device_state; |
| 7868 | |
| 7869 | mpt3sas_base_stop_watchdog(ioc); |
| 7870 | flush_scheduled_work(); |
| 7871 | scsi_block_requests(shost); |
| 7872 | device_state = pci_choose_state(pdev, state); |
| 7873 | pr_info(MPT3SAS_FMT |
| 7874 | "pdev=0x%p, slot=%s, entering operating state [D%d]\n", |
| 7875 | ioc->name, pdev, pci_name(pdev), device_state); |
| 7876 | |
| 7877 | pci_save_state(pdev); |
| 7878 | mpt3sas_base_free_resources(ioc); |
| 7879 | pci_set_power_state(pdev, device_state); |
| 7880 | return 0; |
| 7881 | } |
| 7882 | |
| 7883 | /** |
| 7884 | * _scsih_resume - power management resume main entry point |
| 7885 | * @pdev: PCI device struct |
| 7886 | * |
| 7887 | * Returns 0 success, anything else error. |
| 7888 | */ |
| 7889 | static int |
| 7890 | _scsih_resume(struct pci_dev *pdev) |
| 7891 | { |
| 7892 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7893 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 7894 | pci_power_t device_state = pdev->current_state; |
| 7895 | int r; |
| 7896 | |
| 7897 | pr_info(MPT3SAS_FMT |
| 7898 | "pdev=0x%p, slot=%s, previous operating state [D%d]\n", |
| 7899 | ioc->name, pdev, pci_name(pdev), device_state); |
| 7900 | |
| 7901 | pci_set_power_state(pdev, PCI_D0); |
| 7902 | pci_enable_wake(pdev, PCI_D0, 0); |
| 7903 | pci_restore_state(pdev); |
| 7904 | ioc->pdev = pdev; |
| 7905 | r = mpt3sas_base_map_resources(ioc); |
| 7906 | if (r) |
| 7907 | return r; |
| 7908 | |
| 7909 | mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET); |
| 7910 | scsi_unblock_requests(shost); |
| 7911 | mpt3sas_base_start_watchdog(ioc); |
| 7912 | return 0; |
| 7913 | } |
| 7914 | #endif /* CONFIG_PM */ |
| 7915 | |
| 7916 | /** |
| 7917 | * _scsih_pci_error_detected - Called when a PCI error is detected. |
| 7918 | * @pdev: PCI device struct |
| 7919 | * @state: PCI channel state |
| 7920 | * |
| 7921 | * Description: Called when a PCI error is detected. |
| 7922 | * |
| 7923 | * Return value: |
| 7924 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT |
| 7925 | */ |
| 7926 | static pci_ers_result_t |
| 7927 | _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 7928 | { |
| 7929 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7930 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 7931 | |
| 7932 | pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n", |
| 7933 | ioc->name, state); |
| 7934 | |
| 7935 | switch (state) { |
| 7936 | case pci_channel_io_normal: |
| 7937 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 7938 | case pci_channel_io_frozen: |
| 7939 | /* Fatal error, prepare for slot reset */ |
| 7940 | ioc->pci_error_recovery = 1; |
| 7941 | scsi_block_requests(ioc->shost); |
| 7942 | mpt3sas_base_stop_watchdog(ioc); |
| 7943 | mpt3sas_base_free_resources(ioc); |
| 7944 | return PCI_ERS_RESULT_NEED_RESET; |
| 7945 | case pci_channel_io_perm_failure: |
| 7946 | /* Permanent error, prepare for device removal */ |
| 7947 | ioc->pci_error_recovery = 1; |
| 7948 | mpt3sas_base_stop_watchdog(ioc); |
| 7949 | _scsih_flush_running_cmds(ioc); |
| 7950 | return PCI_ERS_RESULT_DISCONNECT; |
| 7951 | } |
| 7952 | return PCI_ERS_RESULT_NEED_RESET; |
| 7953 | } |
| 7954 | |
| 7955 | /** |
| 7956 | * _scsih_pci_slot_reset - Called when PCI slot has been reset. |
| 7957 | * @pdev: PCI device struct |
| 7958 | * |
| 7959 | * Description: This routine is called by the pci error recovery |
| 7960 | * code after the PCI slot has been reset, just before we |
| 7961 | * should resume normal operations. |
| 7962 | */ |
| 7963 | static pci_ers_result_t |
| 7964 | _scsih_pci_slot_reset(struct pci_dev *pdev) |
| 7965 | { |
| 7966 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7967 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 7968 | int rc; |
| 7969 | |
| 7970 | pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n", |
| 7971 | ioc->name); |
| 7972 | |
| 7973 | ioc->pci_error_recovery = 0; |
| 7974 | ioc->pdev = pdev; |
| 7975 | pci_restore_state(pdev); |
| 7976 | rc = mpt3sas_base_map_resources(ioc); |
| 7977 | if (rc) |
| 7978 | return PCI_ERS_RESULT_DISCONNECT; |
| 7979 | |
| 7980 | rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 7981 | FORCE_BIG_HAMMER); |
| 7982 | |
| 7983 | pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name, |
| 7984 | (rc == 0) ? "success" : "failed"); |
| 7985 | |
| 7986 | if (!rc) |
| 7987 | return PCI_ERS_RESULT_RECOVERED; |
| 7988 | else |
| 7989 | return PCI_ERS_RESULT_DISCONNECT; |
| 7990 | } |
| 7991 | |
| 7992 | /** |
| 7993 | * _scsih_pci_resume() - resume normal ops after PCI reset |
| 7994 | * @pdev: pointer to PCI device |
| 7995 | * |
| 7996 | * Called when the error recovery driver tells us that its |
| 7997 | * OK to resume normal operation. Use completion to allow |
| 7998 | * halted scsi ops to resume. |
| 7999 | */ |
| 8000 | static void |
| 8001 | _scsih_pci_resume(struct pci_dev *pdev) |
| 8002 | { |
| 8003 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8004 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 8005 | |
| 8006 | pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name); |
| 8007 | |
| 8008 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8009 | mpt3sas_base_start_watchdog(ioc); |
| 8010 | scsi_unblock_requests(ioc->shost); |
| 8011 | } |
| 8012 | |
| 8013 | /** |
| 8014 | * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
| 8015 | * @pdev: pointer to PCI device |
| 8016 | */ |
| 8017 | static pci_ers_result_t |
| 8018 | _scsih_pci_mmio_enabled(struct pci_dev *pdev) |
| 8019 | { |
| 8020 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8021 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 8022 | |
| 8023 | pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n", |
| 8024 | ioc->name); |
| 8025 | |
| 8026 | /* TODO - dump whatever for debugging purposes */ |
| 8027 | |
| 8028 | /* Request a slot reset. */ |
| 8029 | return PCI_ERS_RESULT_NEED_RESET; |
| 8030 | } |
| 8031 | |
| 8032 | /* raid transport support */ |
| 8033 | static struct raid_function_template mpt3sas_raid_functions = { |
| 8034 | .cookie = &scsih_driver_template, |
| 8035 | .is_raid = _scsih_is_raid, |
| 8036 | .get_resync = _scsih_get_resync, |
| 8037 | .get_state = _scsih_get_state, |
| 8038 | }; |
| 8039 | |
| 8040 | static struct pci_error_handlers _scsih_err_handler = { |
| 8041 | .error_detected = _scsih_pci_error_detected, |
| 8042 | .mmio_enabled = _scsih_pci_mmio_enabled, |
| 8043 | .slot_reset = _scsih_pci_slot_reset, |
| 8044 | .resume = _scsih_pci_resume, |
| 8045 | }; |
| 8046 | |
| 8047 | static struct pci_driver scsih_driver = { |
| 8048 | .name = MPT3SAS_DRIVER_NAME, |
| 8049 | .id_table = scsih_pci_table, |
| 8050 | .probe = _scsih_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8051 | .remove = _scsih_remove, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 8052 | .shutdown = _scsih_shutdown, |
| 8053 | .err_handler = &_scsih_err_handler, |
| 8054 | #ifdef CONFIG_PM |
| 8055 | .suspend = _scsih_suspend, |
| 8056 | .resume = _scsih_resume, |
| 8057 | #endif |
| 8058 | }; |
| 8059 | |
| 8060 | |
| 8061 | /** |
| 8062 | * _scsih_init - main entry point for this driver. |
| 8063 | * |
| 8064 | * Returns 0 success, anything else error. |
| 8065 | */ |
| 8066 | static int __init |
| 8067 | _scsih_init(void) |
| 8068 | { |
| 8069 | int error; |
| 8070 | |
| 8071 | mpt_ids = 0; |
| 8072 | |
| 8073 | pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME, |
| 8074 | MPT3SAS_DRIVER_VERSION); |
| 8075 | |
| 8076 | mpt3sas_transport_template = |
| 8077 | sas_attach_transport(&mpt3sas_transport_functions); |
| 8078 | if (!mpt3sas_transport_template) |
| 8079 | return -ENODEV; |
| 8080 | |
| 8081 | /* raid transport support */ |
| 8082 | mpt3sas_raid_template = raid_class_attach(&mpt3sas_raid_functions); |
| 8083 | if (!mpt3sas_raid_template) { |
| 8084 | sas_release_transport(mpt3sas_transport_template); |
| 8085 | return -ENODEV; |
| 8086 | } |
| 8087 | |
| 8088 | mpt3sas_base_initialize_callback_handler(); |
| 8089 | |
| 8090 | /* queuecommand callback hander */ |
| 8091 | scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done); |
| 8092 | |
| 8093 | /* task managment callback handler */ |
| 8094 | tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done); |
| 8095 | |
| 8096 | /* base internal commands callback handler */ |
| 8097 | base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done); |
| 8098 | port_enable_cb_idx = mpt3sas_base_register_callback_handler( |
| 8099 | mpt3sas_port_enable_done); |
| 8100 | |
| 8101 | /* transport internal commands callback handler */ |
| 8102 | transport_cb_idx = mpt3sas_base_register_callback_handler( |
| 8103 | mpt3sas_transport_done); |
| 8104 | |
| 8105 | /* scsih internal commands callback handler */ |
| 8106 | scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done); |
| 8107 | |
| 8108 | /* configuration page API internal commands callback handler */ |
| 8109 | config_cb_idx = mpt3sas_base_register_callback_handler( |
| 8110 | mpt3sas_config_done); |
| 8111 | |
| 8112 | /* ctl module callback handler */ |
| 8113 | ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done); |
| 8114 | |
| 8115 | tm_tr_cb_idx = mpt3sas_base_register_callback_handler( |
| 8116 | _scsih_tm_tr_complete); |
| 8117 | |
| 8118 | tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler( |
| 8119 | _scsih_tm_volume_tr_complete); |
| 8120 | |
| 8121 | tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler( |
| 8122 | _scsih_sas_control_complete); |
| 8123 | |
| 8124 | mpt3sas_ctl_init(); |
| 8125 | |
| 8126 | error = pci_register_driver(&scsih_driver); |
| 8127 | if (error) { |
| 8128 | /* raid transport support */ |
| 8129 | raid_class_release(mpt3sas_raid_template); |
| 8130 | sas_release_transport(mpt3sas_transport_template); |
| 8131 | } |
| 8132 | |
| 8133 | return error; |
| 8134 | } |
| 8135 | |
| 8136 | /** |
| 8137 | * _scsih_exit - exit point for this driver (when it is a module). |
| 8138 | * |
| 8139 | * Returns 0 success, anything else error. |
| 8140 | */ |
| 8141 | static void __exit |
| 8142 | _scsih_exit(void) |
| 8143 | { |
| 8144 | pr_info("mpt3sas version %s unloading\n", |
| 8145 | MPT3SAS_DRIVER_VERSION); |
| 8146 | |
| 8147 | mpt3sas_ctl_exit(); |
| 8148 | |
| 8149 | pci_unregister_driver(&scsih_driver); |
| 8150 | |
| 8151 | |
| 8152 | mpt3sas_base_release_callback_handler(scsi_io_cb_idx); |
| 8153 | mpt3sas_base_release_callback_handler(tm_cb_idx); |
| 8154 | mpt3sas_base_release_callback_handler(base_cb_idx); |
| 8155 | mpt3sas_base_release_callback_handler(port_enable_cb_idx); |
| 8156 | mpt3sas_base_release_callback_handler(transport_cb_idx); |
| 8157 | mpt3sas_base_release_callback_handler(scsih_cb_idx); |
| 8158 | mpt3sas_base_release_callback_handler(config_cb_idx); |
| 8159 | mpt3sas_base_release_callback_handler(ctl_cb_idx); |
| 8160 | |
| 8161 | mpt3sas_base_release_callback_handler(tm_tr_cb_idx); |
| 8162 | mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx); |
| 8163 | mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx); |
| 8164 | |
| 8165 | /* raid transport support */ |
| 8166 | raid_class_release(mpt3sas_raid_template); |
| 8167 | sas_release_transport(mpt3sas_transport_template); |
| 8168 | } |
| 8169 | |
| 8170 | module_init(_scsih_init); |
| 8171 | module_exit(_scsih_exit); |