Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Scsi Host Layer for MPT (Message Passing Technology) based controllers |
| 3 | * |
| 4 | * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c |
| 5 | * Copyright (C) 2007-2008 LSI Corporation |
| 6 | * (mailto:DL-MPTFusionLinux@lsi.com) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * as published by the Free Software Foundation; either version 2 |
| 11 | * of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * NO WARRANTY |
| 19 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 20 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT |
| 21 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, |
| 22 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is |
| 23 | * solely responsible for determining the appropriateness of using and |
| 24 | * distributing the Program and assumes all risks associated with its |
| 25 | * exercise of rights under this Agreement, including but not limited to |
| 26 | * the risks and costs of program errors, damage to or loss of data, |
| 27 | * programs or equipment, and unavailability or interruption of operations. |
| 28 | |
| 29 | * DISCLAIMER OF LIABILITY |
| 30 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY |
| 31 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 32 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND |
| 33 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 34 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 35 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED |
| 36 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES |
| 37 | |
| 38 | * You should have received a copy of the GNU General Public License |
| 39 | * along with this program; if not, write to the Free Software |
| 40 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 41 | * USA. |
| 42 | */ |
| 43 | |
| 44 | #include <linux/version.h> |
| 45 | #include <linux/module.h> |
| 46 | #include <linux/kernel.h> |
| 47 | #include <linux/init.h> |
| 48 | #include <linux/errno.h> |
| 49 | #include <linux/blkdev.h> |
| 50 | #include <linux/sched.h> |
| 51 | #include <linux/workqueue.h> |
| 52 | #include <linux/delay.h> |
| 53 | #include <linux/pci.h> |
| 54 | #include <linux/interrupt.h> |
| 55 | |
| 56 | #include "mpt2sas_base.h" |
| 57 | |
| 58 | MODULE_AUTHOR(MPT2SAS_AUTHOR); |
| 59 | MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION); |
| 60 | MODULE_LICENSE("GPL"); |
| 61 | MODULE_VERSION(MPT2SAS_DRIVER_VERSION); |
| 62 | |
| 63 | #define RAID_CHANNEL 1 |
| 64 | |
| 65 | /* forward proto's */ |
| 66 | static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc, |
| 67 | struct _sas_node *sas_expander); |
| 68 | static void _firmware_event_work(struct work_struct *work); |
| 69 | |
| 70 | /* global parameters */ |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 71 | LIST_HEAD(mpt2sas_ioc_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 72 | |
| 73 | /* local parameters */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 74 | static u8 scsi_io_cb_idx = -1; |
| 75 | static u8 tm_cb_idx = -1; |
| 76 | static u8 ctl_cb_idx = -1; |
| 77 | static u8 base_cb_idx = -1; |
| 78 | static u8 transport_cb_idx = -1; |
| 79 | static u8 config_cb_idx = -1; |
| 80 | static int mpt_ids; |
| 81 | |
| 82 | /* command line options */ |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 83 | static u32 logging_level; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 84 | MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info " |
| 85 | "(default=0)"); |
| 86 | |
| 87 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ |
| 88 | #define MPT2SAS_MAX_LUN (16895) |
| 89 | static int max_lun = MPT2SAS_MAX_LUN; |
| 90 | module_param(max_lun, int, 0); |
| 91 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); |
| 92 | |
| 93 | /** |
| 94 | * struct sense_info - common structure for obtaining sense keys |
| 95 | * @skey: sense key |
| 96 | * @asc: additional sense code |
| 97 | * @ascq: additional sense code qualifier |
| 98 | */ |
| 99 | struct sense_info { |
| 100 | u8 skey; |
| 101 | u8 asc; |
| 102 | u8 ascq; |
| 103 | }; |
| 104 | |
| 105 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 106 | /** |
| 107 | * struct fw_event_work - firmware event struct |
| 108 | * @list: link list framework |
| 109 | * @work: work object (ioc->fault_reset_work_q) |
| 110 | * @ioc: per adapter object |
| 111 | * @VF_ID: virtual function id |
| 112 | * @host_reset_handling: handling events during host reset |
| 113 | * @ignore: flag meaning this event has been marked to ignore |
| 114 | * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h |
| 115 | * @event_data: reply event data payload follows |
| 116 | * |
| 117 | * This object stored on ioc->fw_event_list. |
| 118 | */ |
| 119 | struct fw_event_work { |
| 120 | struct list_head list; |
Eric Moore | 6f92a7a | 2009-04-21 15:43:33 -0600 | [diff] [blame] | 121 | struct work_struct work; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 122 | struct MPT2SAS_ADAPTER *ioc; |
| 123 | u8 VF_ID; |
| 124 | u8 host_reset_handling; |
| 125 | u8 ignore; |
| 126 | u16 event; |
| 127 | void *event_data; |
| 128 | }; |
| 129 | |
| 130 | /** |
| 131 | * struct _scsi_io_transfer - scsi io transfer |
| 132 | * @handle: sas device handle (assigned by firmware) |
| 133 | * @is_raid: flag set for hidden raid components |
| 134 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, |
| 135 | * @data_length: data transfer length |
| 136 | * @data_dma: dma pointer to data |
| 137 | * @sense: sense data |
| 138 | * @lun: lun number |
| 139 | * @cdb_length: cdb length |
| 140 | * @cdb: cdb contents |
| 141 | * @valid_reply: flag set for reply message |
| 142 | * @timeout: timeout for this command |
| 143 | * @sense_length: sense length |
| 144 | * @ioc_status: ioc status |
| 145 | * @scsi_state: scsi state |
| 146 | * @scsi_status: scsi staus |
| 147 | * @log_info: log information |
| 148 | * @transfer_length: data length transfer when there is a reply message |
| 149 | * |
| 150 | * Used for sending internal scsi commands to devices within this module. |
| 151 | * Refer to _scsi_send_scsi_io(). |
| 152 | */ |
| 153 | struct _scsi_io_transfer { |
| 154 | u16 handle; |
| 155 | u8 is_raid; |
| 156 | enum dma_data_direction dir; |
| 157 | u32 data_length; |
| 158 | dma_addr_t data_dma; |
| 159 | u8 sense[SCSI_SENSE_BUFFERSIZE]; |
| 160 | u32 lun; |
| 161 | u8 cdb_length; |
| 162 | u8 cdb[32]; |
| 163 | u8 timeout; |
| 164 | u8 valid_reply; |
| 165 | /* the following bits are only valid when 'valid_reply = 1' */ |
| 166 | u32 sense_length; |
| 167 | u16 ioc_status; |
| 168 | u8 scsi_state; |
| 169 | u8 scsi_status; |
| 170 | u32 log_info; |
| 171 | u32 transfer_length; |
| 172 | }; |
| 173 | |
| 174 | /* |
| 175 | * The pci device ids are defined in mpi/mpi2_cnfg.h. |
| 176 | */ |
| 177 | static struct pci_device_id scsih_pci_table[] = { |
| 178 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, |
| 179 | PCI_ANY_ID, PCI_ANY_ID }, |
| 180 | /* Falcon ~ 2008*/ |
| 181 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, |
| 182 | PCI_ANY_ID, PCI_ANY_ID }, |
| 183 | /* Liberator ~ 2108 */ |
| 184 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, |
| 185 | PCI_ANY_ID, PCI_ANY_ID }, |
| 186 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, |
| 187 | PCI_ANY_ID, PCI_ANY_ID }, |
| 188 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, |
| 189 | PCI_ANY_ID, PCI_ANY_ID }, |
| 190 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, |
| 191 | PCI_ANY_ID, PCI_ANY_ID }, |
| 192 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, |
| 193 | PCI_ANY_ID, PCI_ANY_ID }, |
| 194 | {0} /* Terminating entry */ |
| 195 | }; |
| 196 | MODULE_DEVICE_TABLE(pci, scsih_pci_table); |
| 197 | |
| 198 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 199 | * _scsih_set_debug_level - global setting of ioc->logging_level. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 200 | * |
| 201 | * Note: The logging levels are defined in mpt2sas_debug.h. |
| 202 | */ |
| 203 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 204 | _scsih_set_debug_level(const char *val, struct kernel_param *kp) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 205 | { |
| 206 | int ret = param_set_int(val, kp); |
| 207 | struct MPT2SAS_ADAPTER *ioc; |
| 208 | |
| 209 | if (ret) |
| 210 | return ret; |
| 211 | |
| 212 | printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 213 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 214 | ioc->logging_level = logging_level; |
| 215 | return 0; |
| 216 | } |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 217 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 218 | &logging_level, 0644); |
| 219 | |
| 220 | /** |
| 221 | * _scsih_srch_boot_sas_address - search based on sas_address |
| 222 | * @sas_address: sas address |
| 223 | * @boot_device: boot device object from bios page 2 |
| 224 | * |
| 225 | * Returns 1 when there's a match, 0 means no match. |
| 226 | */ |
| 227 | static inline int |
| 228 | _scsih_srch_boot_sas_address(u64 sas_address, |
| 229 | Mpi2BootDeviceSasWwid_t *boot_device) |
| 230 | { |
| 231 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * _scsih_srch_boot_device_name - search based on device name |
| 236 | * @device_name: device name specified in INDENTIFY fram |
| 237 | * @boot_device: boot device object from bios page 2 |
| 238 | * |
| 239 | * Returns 1 when there's a match, 0 means no match. |
| 240 | */ |
| 241 | static inline int |
| 242 | _scsih_srch_boot_device_name(u64 device_name, |
| 243 | Mpi2BootDeviceDeviceName_t *boot_device) |
| 244 | { |
| 245 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot |
| 250 | * @enclosure_logical_id: enclosure logical id |
| 251 | * @slot_number: slot number |
| 252 | * @boot_device: boot device object from bios page 2 |
| 253 | * |
| 254 | * Returns 1 when there's a match, 0 means no match. |
| 255 | */ |
| 256 | static inline int |
| 257 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, |
| 258 | Mpi2BootDeviceEnclosureSlot_t *boot_device) |
| 259 | { |
| 260 | return (enclosure_logical_id == le64_to_cpu(boot_device-> |
| 261 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> |
| 262 | SlotNumber)) ? 1 : 0; |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * _scsih_is_boot_device - search for matching boot device. |
| 267 | * @sas_address: sas address |
| 268 | * @device_name: device name specified in INDENTIFY fram |
| 269 | * @enclosure_logical_id: enclosure logical id |
| 270 | * @slot_number: slot number |
| 271 | * @form: specifies boot device form |
| 272 | * @boot_device: boot device object from bios page 2 |
| 273 | * |
| 274 | * Returns 1 when there's a match, 0 means no match. |
| 275 | */ |
| 276 | static int |
| 277 | _scsih_is_boot_device(u64 sas_address, u64 device_name, |
| 278 | u64 enclosure_logical_id, u16 slot, u8 form, |
| 279 | Mpi2BiosPage2BootDevice_t *boot_device) |
| 280 | { |
| 281 | int rc = 0; |
| 282 | |
| 283 | switch (form) { |
| 284 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: |
| 285 | if (!sas_address) |
| 286 | break; |
| 287 | rc = _scsih_srch_boot_sas_address( |
| 288 | sas_address, &boot_device->SasWwid); |
| 289 | break; |
| 290 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: |
| 291 | if (!enclosure_logical_id) |
| 292 | break; |
| 293 | rc = _scsih_srch_boot_encl_slot( |
| 294 | enclosure_logical_id, |
| 295 | slot, &boot_device->EnclosureSlot); |
| 296 | break; |
| 297 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: |
| 298 | if (!device_name) |
| 299 | break; |
| 300 | rc = _scsih_srch_boot_device_name( |
| 301 | device_name, &boot_device->DeviceName); |
| 302 | break; |
| 303 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: |
| 304 | break; |
| 305 | } |
| 306 | |
| 307 | return rc; |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * _scsih_determine_boot_device - determine boot device. |
| 312 | * @ioc: per adapter object |
| 313 | * @device: either sas_device or raid_device object |
| 314 | * @is_raid: [flag] 1 = raid object, 0 = sas object |
| 315 | * |
| 316 | * Determines whether this device should be first reported device to |
| 317 | * to scsi-ml or sas transport, this purpose is for persistant boot device. |
| 318 | * There are primary, alternate, and current entries in bios page 2. The order |
| 319 | * priority is primary, alternate, then current. This routine saves |
| 320 | * the corresponding device object and is_raid flag in the ioc object. |
| 321 | * The saved data to be used later in _scsih_probe_boot_devices(). |
| 322 | */ |
| 323 | static void |
| 324 | _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc, |
| 325 | void *device, u8 is_raid) |
| 326 | { |
| 327 | struct _sas_device *sas_device; |
| 328 | struct _raid_device *raid_device; |
| 329 | u64 sas_address; |
| 330 | u64 device_name; |
| 331 | u64 enclosure_logical_id; |
| 332 | u16 slot; |
| 333 | |
| 334 | /* only process this function when driver loads */ |
| 335 | if (!ioc->wait_for_port_enable_to_complete) |
| 336 | return; |
| 337 | |
| 338 | if (!is_raid) { |
| 339 | sas_device = device; |
| 340 | sas_address = sas_device->sas_address; |
| 341 | device_name = sas_device->device_name; |
| 342 | enclosure_logical_id = sas_device->enclosure_logical_id; |
| 343 | slot = sas_device->slot; |
| 344 | } else { |
| 345 | raid_device = device; |
| 346 | sas_address = raid_device->wwid; |
| 347 | device_name = 0; |
| 348 | enclosure_logical_id = 0; |
| 349 | slot = 0; |
| 350 | } |
| 351 | |
| 352 | if (!ioc->req_boot_device.device) { |
| 353 | if (_scsih_is_boot_device(sas_address, device_name, |
| 354 | enclosure_logical_id, slot, |
| 355 | (ioc->bios_pg2.ReqBootDeviceForm & |
| 356 | MPI2_BIOSPAGE2_FORM_MASK), |
| 357 | &ioc->bios_pg2.RequestedBootDevice)) { |
| 358 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT |
| 359 | "%s: req_boot_device(0x%016llx)\n", |
| 360 | ioc->name, __func__, |
| 361 | (unsigned long long)sas_address)); |
| 362 | ioc->req_boot_device.device = device; |
| 363 | ioc->req_boot_device.is_raid = is_raid; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | if (!ioc->req_alt_boot_device.device) { |
| 368 | if (_scsih_is_boot_device(sas_address, device_name, |
| 369 | enclosure_logical_id, slot, |
| 370 | (ioc->bios_pg2.ReqAltBootDeviceForm & |
| 371 | MPI2_BIOSPAGE2_FORM_MASK), |
| 372 | &ioc->bios_pg2.RequestedAltBootDevice)) { |
| 373 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT |
| 374 | "%s: req_alt_boot_device(0x%016llx)\n", |
| 375 | ioc->name, __func__, |
| 376 | (unsigned long long)sas_address)); |
| 377 | ioc->req_alt_boot_device.device = device; |
| 378 | ioc->req_alt_boot_device.is_raid = is_raid; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | if (!ioc->current_boot_device.device) { |
| 383 | if (_scsih_is_boot_device(sas_address, device_name, |
| 384 | enclosure_logical_id, slot, |
| 385 | (ioc->bios_pg2.CurrentBootDeviceForm & |
| 386 | MPI2_BIOSPAGE2_FORM_MASK), |
| 387 | &ioc->bios_pg2.CurrentBootDevice)) { |
| 388 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT |
| 389 | "%s: current_boot_device(0x%016llx)\n", |
| 390 | ioc->name, __func__, |
| 391 | (unsigned long long)sas_address)); |
| 392 | ioc->current_boot_device.device = device; |
| 393 | ioc->current_boot_device.is_raid = is_raid; |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search |
| 400 | * @ioc: per adapter object |
| 401 | * @sas_address: sas address |
| 402 | * Context: Calling function should acquire ioc->sas_device_lock |
| 403 | * |
| 404 | * This searches for sas_device based on sas_address, then return sas_device |
| 405 | * object. |
| 406 | */ |
| 407 | struct _sas_device * |
| 408 | mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 409 | u64 sas_address) |
| 410 | { |
| 411 | struct _sas_device *sas_device, *r; |
| 412 | |
| 413 | r = NULL; |
| 414 | /* check the sas_device_init_list */ |
| 415 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, |
| 416 | list) { |
| 417 | if (sas_device->sas_address != sas_address) |
| 418 | continue; |
| 419 | r = sas_device; |
| 420 | goto out; |
| 421 | } |
| 422 | |
| 423 | /* then check the sas_device_list */ |
| 424 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { |
| 425 | if (sas_device->sas_address != sas_address) |
| 426 | continue; |
| 427 | r = sas_device; |
| 428 | goto out; |
| 429 | } |
| 430 | out: |
| 431 | return r; |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * _scsih_sas_device_find_by_handle - sas device search |
| 436 | * @ioc: per adapter object |
| 437 | * @handle: sas device handle (assigned by firmware) |
| 438 | * Context: Calling function should acquire ioc->sas_device_lock |
| 439 | * |
| 440 | * This searches for sas_device based on sas_address, then return sas_device |
| 441 | * object. |
| 442 | */ |
| 443 | static struct _sas_device * |
| 444 | _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 445 | { |
| 446 | struct _sas_device *sas_device, *r; |
| 447 | |
| 448 | r = NULL; |
| 449 | if (ioc->wait_for_port_enable_to_complete) { |
| 450 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, |
| 451 | list) { |
| 452 | if (sas_device->handle != handle) |
| 453 | continue; |
| 454 | r = sas_device; |
| 455 | goto out; |
| 456 | } |
| 457 | } else { |
| 458 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { |
| 459 | if (sas_device->handle != handle) |
| 460 | continue; |
| 461 | r = sas_device; |
| 462 | goto out; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | out: |
| 467 | return r; |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * _scsih_sas_device_remove - remove sas_device from list. |
| 472 | * @ioc: per adapter object |
| 473 | * @sas_device: the sas_device object |
| 474 | * Context: This function will acquire ioc->sas_device_lock. |
| 475 | * |
| 476 | * Removing object and freeing associated memory from the ioc->sas_device_list. |
| 477 | */ |
| 478 | static void |
| 479 | _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc, |
| 480 | struct _sas_device *sas_device) |
| 481 | { |
| 482 | unsigned long flags; |
| 483 | |
| 484 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 485 | list_del(&sas_device->list); |
| 486 | memset(sas_device, 0, sizeof(struct _sas_device)); |
| 487 | kfree(sas_device); |
| 488 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * _scsih_sas_device_add - insert sas_device to the list. |
| 493 | * @ioc: per adapter object |
| 494 | * @sas_device: the sas_device object |
| 495 | * Context: This function will acquire ioc->sas_device_lock. |
| 496 | * |
| 497 | * Adding new object to the ioc->sas_device_list. |
| 498 | */ |
| 499 | static void |
| 500 | _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc, |
| 501 | struct _sas_device *sas_device) |
| 502 | { |
| 503 | unsigned long flags; |
| 504 | u16 handle, parent_handle; |
| 505 | u64 sas_address; |
| 506 | |
| 507 | dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle" |
| 508 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 509 | sas_device->handle, (unsigned long long)sas_device->sas_address)); |
| 510 | |
| 511 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 512 | list_add_tail(&sas_device->list, &ioc->sas_device_list); |
| 513 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 514 | |
| 515 | handle = sas_device->handle; |
| 516 | parent_handle = sas_device->parent_handle; |
| 517 | sas_address = sas_device->sas_address; |
Eric Moore | 8901cbb | 2009-04-21 15:41:32 -0600 | [diff] [blame] | 518 | if (!mpt2sas_transport_port_add(ioc, handle, parent_handle)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 519 | _scsih_sas_device_remove(ioc, sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | /** |
| 523 | * _scsih_sas_device_init_add - insert sas_device to the list. |
| 524 | * @ioc: per adapter object |
| 525 | * @sas_device: the sas_device object |
| 526 | * Context: This function will acquire ioc->sas_device_lock. |
| 527 | * |
| 528 | * Adding new object at driver load time to the ioc->sas_device_init_list. |
| 529 | */ |
| 530 | static void |
| 531 | _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc, |
| 532 | struct _sas_device *sas_device) |
| 533 | { |
| 534 | unsigned long flags; |
| 535 | |
| 536 | dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle" |
| 537 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 538 | sas_device->handle, (unsigned long long)sas_device->sas_address)); |
| 539 | |
| 540 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 541 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); |
| 542 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 543 | _scsih_determine_boot_device(ioc, sas_device, 0); |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * mpt2sas_scsih_expander_find_by_handle - expander device search |
| 548 | * @ioc: per adapter object |
| 549 | * @handle: expander handle (assigned by firmware) |
| 550 | * Context: Calling function should acquire ioc->sas_device_lock |
| 551 | * |
| 552 | * This searches for expander device based on handle, then returns the |
| 553 | * sas_node object. |
| 554 | */ |
| 555 | struct _sas_node * |
| 556 | mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 557 | { |
| 558 | struct _sas_node *sas_expander, *r; |
| 559 | |
| 560 | r = NULL; |
| 561 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 562 | if (sas_expander->handle != handle) |
| 563 | continue; |
| 564 | r = sas_expander; |
| 565 | goto out; |
| 566 | } |
| 567 | out: |
| 568 | return r; |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * _scsih_raid_device_find_by_id - raid device search |
| 573 | * @ioc: per adapter object |
| 574 | * @id: sas device target id |
| 575 | * @channel: sas device channel |
| 576 | * Context: Calling function should acquire ioc->raid_device_lock |
| 577 | * |
| 578 | * This searches for raid_device based on target id, then return raid_device |
| 579 | * object. |
| 580 | */ |
| 581 | static struct _raid_device * |
| 582 | _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel) |
| 583 | { |
| 584 | struct _raid_device *raid_device, *r; |
| 585 | |
| 586 | r = NULL; |
| 587 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 588 | if (raid_device->id == id && raid_device->channel == channel) { |
| 589 | r = raid_device; |
| 590 | goto out; |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | out: |
| 595 | return r; |
| 596 | } |
| 597 | |
| 598 | /** |
| 599 | * _scsih_raid_device_find_by_handle - raid device search |
| 600 | * @ioc: per adapter object |
| 601 | * @handle: sas device handle (assigned by firmware) |
| 602 | * Context: Calling function should acquire ioc->raid_device_lock |
| 603 | * |
| 604 | * This searches for raid_device based on handle, then return raid_device |
| 605 | * object. |
| 606 | */ |
| 607 | static struct _raid_device * |
| 608 | _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 609 | { |
| 610 | struct _raid_device *raid_device, *r; |
| 611 | |
| 612 | r = NULL; |
| 613 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 614 | if (raid_device->handle != handle) |
| 615 | continue; |
| 616 | r = raid_device; |
| 617 | goto out; |
| 618 | } |
| 619 | |
| 620 | out: |
| 621 | return r; |
| 622 | } |
| 623 | |
| 624 | /** |
| 625 | * _scsih_raid_device_find_by_wwid - raid device search |
| 626 | * @ioc: per adapter object |
| 627 | * @handle: sas device handle (assigned by firmware) |
| 628 | * Context: Calling function should acquire ioc->raid_device_lock |
| 629 | * |
| 630 | * This searches for raid_device based on wwid, then return raid_device |
| 631 | * object. |
| 632 | */ |
| 633 | static struct _raid_device * |
| 634 | _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid) |
| 635 | { |
| 636 | struct _raid_device *raid_device, *r; |
| 637 | |
| 638 | r = NULL; |
| 639 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 640 | if (raid_device->wwid != wwid) |
| 641 | continue; |
| 642 | r = raid_device; |
| 643 | goto out; |
| 644 | } |
| 645 | |
| 646 | out: |
| 647 | return r; |
| 648 | } |
| 649 | |
| 650 | /** |
| 651 | * _scsih_raid_device_add - add raid_device object |
| 652 | * @ioc: per adapter object |
| 653 | * @raid_device: raid_device object |
| 654 | * |
| 655 | * This is added to the raid_device_list link list. |
| 656 | */ |
| 657 | static void |
| 658 | _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc, |
| 659 | struct _raid_device *raid_device) |
| 660 | { |
| 661 | unsigned long flags; |
| 662 | |
| 663 | dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle" |
| 664 | "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, |
| 665 | raid_device->handle, (unsigned long long)raid_device->wwid)); |
| 666 | |
| 667 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 668 | list_add_tail(&raid_device->list, &ioc->raid_device_list); |
| 669 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 670 | } |
| 671 | |
| 672 | /** |
| 673 | * _scsih_raid_device_remove - delete raid_device object |
| 674 | * @ioc: per adapter object |
| 675 | * @raid_device: raid_device object |
| 676 | * |
| 677 | * This is removed from the raid_device_list link list. |
| 678 | */ |
| 679 | static void |
| 680 | _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc, |
| 681 | struct _raid_device *raid_device) |
| 682 | { |
| 683 | unsigned long flags; |
| 684 | |
| 685 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 686 | list_del(&raid_device->list); |
| 687 | memset(raid_device, 0, sizeof(struct _raid_device)); |
| 688 | kfree(raid_device); |
| 689 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 690 | } |
| 691 | |
| 692 | /** |
| 693 | * mpt2sas_scsih_expander_find_by_sas_address - expander device search |
| 694 | * @ioc: per adapter object |
| 695 | * @sas_address: sas address |
| 696 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 697 | * |
| 698 | * This searches for expander device based on sas_address, then returns the |
| 699 | * sas_node object. |
| 700 | */ |
| 701 | struct _sas_node * |
| 702 | mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 703 | u64 sas_address) |
| 704 | { |
| 705 | struct _sas_node *sas_expander, *r; |
| 706 | |
| 707 | r = NULL; |
| 708 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 709 | if (sas_expander->sas_address != sas_address) |
| 710 | continue; |
| 711 | r = sas_expander; |
| 712 | goto out; |
| 713 | } |
| 714 | out: |
| 715 | return r; |
| 716 | } |
| 717 | |
| 718 | /** |
| 719 | * _scsih_expander_node_add - insert expander device to the list. |
| 720 | * @ioc: per adapter object |
| 721 | * @sas_expander: the sas_device object |
| 722 | * Context: This function will acquire ioc->sas_node_lock. |
| 723 | * |
| 724 | * Adding new object to the ioc->sas_expander_list. |
| 725 | * |
| 726 | * Return nothing. |
| 727 | */ |
| 728 | static void |
| 729 | _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc, |
| 730 | struct _sas_node *sas_expander) |
| 731 | { |
| 732 | unsigned long flags; |
| 733 | |
| 734 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 735 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); |
| 736 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * _scsih_is_end_device - determines if device is an end device |
| 741 | * @device_info: bitfield providing information about the device. |
| 742 | * Context: none |
| 743 | * |
| 744 | * Returns 1 if end device. |
| 745 | */ |
| 746 | static int |
| 747 | _scsih_is_end_device(u32 device_info) |
| 748 | { |
| 749 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && |
| 750 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | |
| 751 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
| 752 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) |
| 753 | return 1; |
| 754 | else |
| 755 | return 0; |
| 756 | } |
| 757 | |
| 758 | /** |
| 759 | * _scsih_scsi_lookup_get - returns scmd entry |
| 760 | * @ioc: per adapter object |
| 761 | * @smid: system request message index |
| 762 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 763 | * |
| 764 | * Returns the smid stored scmd pointer. |
| 765 | */ |
| 766 | static struct scsi_cmnd * |
| 767 | _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 768 | { |
| 769 | unsigned long flags; |
| 770 | struct scsi_cmnd *scmd; |
| 771 | |
| 772 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 773 | scmd = ioc->scsi_lookup[smid - 1].scmd; |
| 774 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 775 | return scmd; |
| 776 | } |
| 777 | |
| 778 | /** |
| 779 | * mptscsih_getclear_scsi_lookup - returns scmd entry |
| 780 | * @ioc: per adapter object |
| 781 | * @smid: system request message index |
| 782 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 783 | * |
| 784 | * Returns the smid stored scmd pointer, as well as clearing the scmd pointer. |
| 785 | */ |
| 786 | static struct scsi_cmnd * |
| 787 | _scsih_scsi_lookup_getclear(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 788 | { |
| 789 | unsigned long flags; |
| 790 | struct scsi_cmnd *scmd; |
| 791 | |
| 792 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 793 | scmd = ioc->scsi_lookup[smid - 1].scmd; |
| 794 | ioc->scsi_lookup[smid - 1].scmd = NULL; |
| 795 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 796 | return scmd; |
| 797 | } |
| 798 | |
| 799 | /** |
| 800 | * _scsih_scsi_lookup_set - updates scmd entry in lookup |
| 801 | * @ioc: per adapter object |
| 802 | * @smid: system request message index |
| 803 | * @scmd: pointer to scsi command object |
| 804 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 805 | * |
| 806 | * This will save scmd pointer in the scsi_lookup array. |
| 807 | * |
| 808 | * Return nothing. |
| 809 | */ |
| 810 | static void |
| 811 | _scsih_scsi_lookup_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 812 | struct scsi_cmnd *scmd) |
| 813 | { |
| 814 | unsigned long flags; |
| 815 | |
| 816 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 817 | ioc->scsi_lookup[smid - 1].scmd = scmd; |
| 818 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 819 | } |
| 820 | |
| 821 | /** |
| 822 | * _scsih_scsi_lookup_find_by_scmd - scmd lookup |
| 823 | * @ioc: per adapter object |
| 824 | * @smid: system request message index |
| 825 | * @scmd: pointer to scsi command object |
| 826 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 827 | * |
| 828 | * This will search for a scmd pointer in the scsi_lookup array, |
| 829 | * returning the revelent smid. A returned value of zero means invalid. |
| 830 | */ |
| 831 | static u16 |
| 832 | _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd |
| 833 | *scmd) |
| 834 | { |
| 835 | u16 smid; |
| 836 | unsigned long flags; |
| 837 | int i; |
| 838 | |
| 839 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 840 | smid = 0; |
| 841 | for (i = 0; i < ioc->request_depth; i++) { |
| 842 | if (ioc->scsi_lookup[i].scmd == scmd) { |
| 843 | smid = i + 1; |
| 844 | goto out; |
| 845 | } |
| 846 | } |
| 847 | out: |
| 848 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 849 | return smid; |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * _scsih_scsi_lookup_find_by_target - search for matching channel:id |
| 854 | * @ioc: per adapter object |
| 855 | * @id: target id |
| 856 | * @channel: channel |
| 857 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 858 | * |
| 859 | * This will search for a matching channel:id in the scsi_lookup array, |
| 860 | * returning 1 if found. |
| 861 | */ |
| 862 | static u8 |
| 863 | _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id, |
| 864 | int channel) |
| 865 | { |
| 866 | u8 found; |
| 867 | unsigned long flags; |
| 868 | int i; |
| 869 | |
| 870 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 871 | found = 0; |
| 872 | for (i = 0 ; i < ioc->request_depth; i++) { |
| 873 | if (ioc->scsi_lookup[i].scmd && |
| 874 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 875 | ioc->scsi_lookup[i].scmd->device->channel == channel)) { |
| 876 | found = 1; |
| 877 | goto out; |
| 878 | } |
| 879 | } |
| 880 | out: |
| 881 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 882 | return found; |
| 883 | } |
| 884 | |
| 885 | /** |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 886 | * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun |
| 887 | * @ioc: per adapter object |
| 888 | * @id: target id |
| 889 | * @lun: lun number |
| 890 | * @channel: channel |
| 891 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 892 | * |
| 893 | * This will search for a matching channel:id:lun in the scsi_lookup array, |
| 894 | * returning 1 if found. |
| 895 | */ |
| 896 | static u8 |
| 897 | _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id, |
| 898 | unsigned int lun, int channel) |
| 899 | { |
| 900 | u8 found; |
| 901 | unsigned long flags; |
| 902 | int i; |
| 903 | |
| 904 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 905 | found = 0; |
| 906 | for (i = 0 ; i < ioc->request_depth; i++) { |
| 907 | if (ioc->scsi_lookup[i].scmd && |
| 908 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 909 | ioc->scsi_lookup[i].scmd->device->channel == channel && |
| 910 | ioc->scsi_lookup[i].scmd->device->lun == lun)) { |
| 911 | found = 1; |
| 912 | goto out; |
| 913 | } |
| 914 | } |
| 915 | out: |
| 916 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 917 | return found; |
| 918 | } |
| 919 | |
| 920 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 921 | * _scsih_get_chain_buffer_dma - obtain block of chains (dma address) |
| 922 | * @ioc: per adapter object |
| 923 | * @smid: system request message index |
| 924 | * |
| 925 | * Returns phys pointer to chain buffer. |
| 926 | */ |
| 927 | static dma_addr_t |
| 928 | _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 929 | { |
| 930 | return ioc->chain_dma + ((smid - 1) * (ioc->request_sz * |
| 931 | ioc->chains_needed_per_io)); |
| 932 | } |
| 933 | |
| 934 | /** |
| 935 | * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request |
| 936 | * @ioc: per adapter object |
| 937 | * @smid: system request message index |
| 938 | * |
| 939 | * Returns virt pointer to chain buffer. |
| 940 | */ |
| 941 | static void * |
| 942 | _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 943 | { |
| 944 | return (void *)(ioc->chain + ((smid - 1) * (ioc->request_sz * |
| 945 | ioc->chains_needed_per_io))); |
| 946 | } |
| 947 | |
| 948 | /** |
| 949 | * _scsih_build_scatter_gather - main sg creation routine |
| 950 | * @ioc: per adapter object |
| 951 | * @scmd: scsi command |
| 952 | * @smid: system request message index |
| 953 | * Context: none. |
| 954 | * |
| 955 | * The main routine that builds scatter gather table from a given |
| 956 | * scsi request sent via the .queuecommand main handler. |
| 957 | * |
| 958 | * Returns 0 success, anything else error |
| 959 | */ |
| 960 | static int |
| 961 | _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc, |
| 962 | struct scsi_cmnd *scmd, u16 smid) |
| 963 | { |
| 964 | Mpi2SCSIIORequest_t *mpi_request; |
| 965 | dma_addr_t chain_dma; |
| 966 | struct scatterlist *sg_scmd; |
| 967 | void *sg_local, *chain; |
| 968 | u32 chain_offset; |
| 969 | u32 chain_length; |
| 970 | u32 chain_flags; |
| 971 | u32 sges_left; |
| 972 | u32 sges_in_segment; |
| 973 | u32 sgl_flags; |
| 974 | u32 sgl_flags_last_element; |
| 975 | u32 sgl_flags_end_buffer; |
| 976 | |
| 977 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 978 | |
| 979 | /* init scatter gather flags */ |
| 980 | sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT; |
| 981 | if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 982 | sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC; |
| 983 | sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT) |
| 984 | << MPI2_SGE_FLAGS_SHIFT; |
| 985 | sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT | |
| 986 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST) |
| 987 | << MPI2_SGE_FLAGS_SHIFT; |
| 988 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 989 | |
| 990 | sg_scmd = scsi_sglist(scmd); |
| 991 | sges_left = scsi_dma_map(scmd); |
| 992 | if (!sges_left) { |
| 993 | sdev_printk(KERN_ERR, scmd->device, "pci_map_sg" |
| 994 | " failed: request for %d bytes!\n", scsi_bufflen(scmd)); |
| 995 | return -ENOMEM; |
| 996 | } |
| 997 | |
| 998 | sg_local = &mpi_request->SGL; |
| 999 | sges_in_segment = ioc->max_sges_in_main_message; |
| 1000 | if (sges_left <= sges_in_segment) |
| 1001 | goto fill_in_last_segment; |
| 1002 | |
| 1003 | mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) + |
| 1004 | (sges_in_segment * ioc->sge_size))/4; |
| 1005 | |
| 1006 | /* fill in main message segment when there is a chain following */ |
| 1007 | while (sges_in_segment) { |
| 1008 | if (sges_in_segment == 1) |
| 1009 | ioc->base_add_sg_single(sg_local, |
| 1010 | sgl_flags_last_element | sg_dma_len(sg_scmd), |
| 1011 | sg_dma_address(sg_scmd)); |
| 1012 | else |
| 1013 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1014 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1015 | sg_scmd = sg_next(sg_scmd); |
| 1016 | sg_local += ioc->sge_size; |
| 1017 | sges_left--; |
| 1018 | sges_in_segment--; |
| 1019 | } |
| 1020 | |
| 1021 | /* initializing the chain flags and pointers */ |
| 1022 | chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT; |
| 1023 | chain = _scsih_get_chain_buffer(ioc, smid); |
| 1024 | chain_dma = _scsih_get_chain_buffer_dma(ioc, smid); |
| 1025 | do { |
| 1026 | sges_in_segment = (sges_left <= |
| 1027 | ioc->max_sges_in_chain_message) ? sges_left : |
| 1028 | ioc->max_sges_in_chain_message; |
| 1029 | chain_offset = (sges_left == sges_in_segment) ? |
| 1030 | 0 : (sges_in_segment * ioc->sge_size)/4; |
| 1031 | chain_length = sges_in_segment * ioc->sge_size; |
| 1032 | if (chain_offset) { |
| 1033 | chain_offset = chain_offset << |
| 1034 | MPI2_SGE_CHAIN_OFFSET_SHIFT; |
| 1035 | chain_length += ioc->sge_size; |
| 1036 | } |
| 1037 | ioc->base_add_sg_single(sg_local, chain_flags | chain_offset | |
| 1038 | chain_length, chain_dma); |
| 1039 | sg_local = chain; |
| 1040 | if (!chain_offset) |
| 1041 | goto fill_in_last_segment; |
| 1042 | |
| 1043 | /* fill in chain segments */ |
| 1044 | while (sges_in_segment) { |
| 1045 | if (sges_in_segment == 1) |
| 1046 | ioc->base_add_sg_single(sg_local, |
| 1047 | sgl_flags_last_element | |
| 1048 | sg_dma_len(sg_scmd), |
| 1049 | sg_dma_address(sg_scmd)); |
| 1050 | else |
| 1051 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1052 | sg_dma_len(sg_scmd), |
| 1053 | sg_dma_address(sg_scmd)); |
| 1054 | sg_scmd = sg_next(sg_scmd); |
| 1055 | sg_local += ioc->sge_size; |
| 1056 | sges_left--; |
| 1057 | sges_in_segment--; |
| 1058 | } |
| 1059 | |
| 1060 | chain_dma += ioc->request_sz; |
| 1061 | chain += ioc->request_sz; |
| 1062 | } while (1); |
| 1063 | |
| 1064 | |
| 1065 | fill_in_last_segment: |
| 1066 | |
| 1067 | /* fill the last segment */ |
| 1068 | while (sges_left) { |
| 1069 | if (sges_left == 1) |
| 1070 | ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer | |
| 1071 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1072 | else |
| 1073 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1074 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1075 | sg_scmd = sg_next(sg_scmd); |
| 1076 | sg_local += ioc->sge_size; |
| 1077 | sges_left--; |
| 1078 | } |
| 1079 | |
| 1080 | return 0; |
| 1081 | } |
| 1082 | |
| 1083 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1084 | * _scsih_change_queue_depth - setting device queue depth |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1085 | * @sdev: scsi device struct |
| 1086 | * @qdepth: requested queue depth |
| 1087 | * |
| 1088 | * Returns queue depth. |
| 1089 | */ |
| 1090 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1091 | _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1092 | { |
| 1093 | struct Scsi_Host *shost = sdev->host; |
| 1094 | int max_depth; |
| 1095 | int tag_type; |
| 1096 | |
| 1097 | max_depth = shost->can_queue; |
| 1098 | if (!sdev->tagged_supported) |
| 1099 | max_depth = 1; |
| 1100 | if (qdepth > max_depth) |
| 1101 | qdepth = max_depth; |
| 1102 | tag_type = (qdepth == 1) ? 0 : MSG_SIMPLE_TAG; |
| 1103 | scsi_adjust_queue_depth(sdev, tag_type, qdepth); |
| 1104 | |
| 1105 | if (sdev->inquiry_len > 7) |
| 1106 | sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " |
| 1107 | "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n", |
| 1108 | sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags, |
| 1109 | sdev->ordered_tags, sdev->scsi_level, |
| 1110 | (sdev->inquiry[7] & 2) >> 1); |
| 1111 | |
| 1112 | return sdev->queue_depth; |
| 1113 | } |
| 1114 | |
| 1115 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1116 | * _scsih_change_queue_depth - changing device queue tag type |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1117 | * @sdev: scsi device struct |
| 1118 | * @tag_type: requested tag type |
| 1119 | * |
| 1120 | * Returns queue tag type. |
| 1121 | */ |
| 1122 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1123 | _scsih_change_queue_type(struct scsi_device *sdev, int tag_type) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1124 | { |
| 1125 | if (sdev->tagged_supported) { |
| 1126 | scsi_set_tag_type(sdev, tag_type); |
| 1127 | if (tag_type) |
| 1128 | scsi_activate_tcq(sdev, sdev->queue_depth); |
| 1129 | else |
| 1130 | scsi_deactivate_tcq(sdev, sdev->queue_depth); |
| 1131 | } else |
| 1132 | tag_type = 0; |
| 1133 | |
| 1134 | return tag_type; |
| 1135 | } |
| 1136 | |
| 1137 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1138 | * _scsih_target_alloc - target add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1139 | * @starget: scsi target struct |
| 1140 | * |
| 1141 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1142 | * the device is ignored. |
| 1143 | */ |
| 1144 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1145 | _scsih_target_alloc(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1146 | { |
| 1147 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1148 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1149 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1150 | struct _sas_device *sas_device; |
| 1151 | struct _raid_device *raid_device; |
| 1152 | unsigned long flags; |
| 1153 | struct sas_rphy *rphy; |
| 1154 | |
| 1155 | sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL); |
| 1156 | if (!sas_target_priv_data) |
| 1157 | return -ENOMEM; |
| 1158 | |
| 1159 | starget->hostdata = sas_target_priv_data; |
| 1160 | sas_target_priv_data->starget = starget; |
| 1161 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; |
| 1162 | |
| 1163 | /* RAID volumes */ |
| 1164 | if (starget->channel == RAID_CHANNEL) { |
| 1165 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1166 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1167 | starget->channel); |
| 1168 | if (raid_device) { |
| 1169 | sas_target_priv_data->handle = raid_device->handle; |
| 1170 | sas_target_priv_data->sas_address = raid_device->wwid; |
| 1171 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; |
| 1172 | raid_device->starget = starget; |
| 1173 | } |
| 1174 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1175 | return 0; |
| 1176 | } |
| 1177 | |
| 1178 | /* sas/sata devices */ |
| 1179 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1180 | rphy = dev_to_rphy(starget->dev.parent); |
| 1181 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1182 | rphy->identify.sas_address); |
| 1183 | |
| 1184 | if (sas_device) { |
| 1185 | sas_target_priv_data->handle = sas_device->handle; |
| 1186 | sas_target_priv_data->sas_address = sas_device->sas_address; |
| 1187 | sas_device->starget = starget; |
| 1188 | sas_device->id = starget->id; |
| 1189 | sas_device->channel = starget->channel; |
| 1190 | if (sas_device->hidden_raid_component) |
| 1191 | sas_target_priv_data->flags |= |
| 1192 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 1193 | } |
| 1194 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1195 | |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1200 | * _scsih_target_destroy - target destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1201 | * @starget: scsi target struct |
| 1202 | * |
| 1203 | * Returns nothing. |
| 1204 | */ |
| 1205 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1206 | _scsih_target_destroy(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1207 | { |
| 1208 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1209 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1210 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1211 | struct _sas_device *sas_device; |
| 1212 | struct _raid_device *raid_device; |
| 1213 | unsigned long flags; |
| 1214 | struct sas_rphy *rphy; |
| 1215 | |
| 1216 | sas_target_priv_data = starget->hostdata; |
| 1217 | if (!sas_target_priv_data) |
| 1218 | return; |
| 1219 | |
| 1220 | if (starget->channel == RAID_CHANNEL) { |
| 1221 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1222 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1223 | starget->channel); |
| 1224 | if (raid_device) { |
| 1225 | raid_device->starget = NULL; |
| 1226 | raid_device->sdev = NULL; |
| 1227 | } |
| 1228 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1229 | goto out; |
| 1230 | } |
| 1231 | |
| 1232 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1233 | rphy = dev_to_rphy(starget->dev.parent); |
| 1234 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1235 | rphy->identify.sas_address); |
Eric Moore | 8901cbb | 2009-04-21 15:41:32 -0600 | [diff] [blame] | 1236 | if (sas_device && (sas_device->starget == starget) && |
| 1237 | (sas_device->id == starget->id) && |
| 1238 | (sas_device->channel == starget->channel)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1239 | sas_device->starget = NULL; |
| 1240 | |
| 1241 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1242 | |
| 1243 | out: |
| 1244 | kfree(sas_target_priv_data); |
| 1245 | starget->hostdata = NULL; |
| 1246 | } |
| 1247 | |
| 1248 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1249 | * _scsih_slave_alloc - device add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1250 | * @sdev: scsi device struct |
| 1251 | * |
| 1252 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1253 | * the device is ignored. |
| 1254 | */ |
| 1255 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1256 | _scsih_slave_alloc(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1257 | { |
| 1258 | struct Scsi_Host *shost; |
| 1259 | struct MPT2SAS_ADAPTER *ioc; |
| 1260 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1261 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1262 | struct scsi_target *starget; |
| 1263 | struct _raid_device *raid_device; |
| 1264 | struct _sas_device *sas_device; |
| 1265 | unsigned long flags; |
| 1266 | |
| 1267 | sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL); |
| 1268 | if (!sas_device_priv_data) |
| 1269 | return -ENOMEM; |
| 1270 | |
| 1271 | sas_device_priv_data->lun = sdev->lun; |
| 1272 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; |
| 1273 | |
| 1274 | starget = scsi_target(sdev); |
| 1275 | sas_target_priv_data = starget->hostdata; |
| 1276 | sas_target_priv_data->num_luns++; |
| 1277 | sas_device_priv_data->sas_target = sas_target_priv_data; |
| 1278 | sdev->hostdata = sas_device_priv_data; |
| 1279 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) |
| 1280 | sdev->no_uld_attach = 1; |
| 1281 | |
| 1282 | shost = dev_to_shost(&starget->dev); |
| 1283 | ioc = shost_priv(shost); |
| 1284 | if (starget->channel == RAID_CHANNEL) { |
| 1285 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1286 | raid_device = _scsih_raid_device_find_by_id(ioc, |
| 1287 | starget->id, starget->channel); |
| 1288 | if (raid_device) |
| 1289 | raid_device->sdev = sdev; /* raid is single lun */ |
| 1290 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1291 | } else { |
| 1292 | /* set TLR bit for SSP devices */ |
| 1293 | if (!(ioc->facts.IOCCapabilities & |
| 1294 | MPI2_IOCFACTS_CAPABILITY_TLR)) |
| 1295 | goto out; |
| 1296 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1297 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1298 | sas_device_priv_data->sas_target->sas_address); |
| 1299 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1300 | if (sas_device && sas_device->device_info & |
| 1301 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
| 1302 | sas_device_priv_data->flags |= MPT_DEVICE_TLR_ON; |
| 1303 | } |
| 1304 | |
| 1305 | out: |
| 1306 | return 0; |
| 1307 | } |
| 1308 | |
| 1309 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1310 | * _scsih_slave_destroy - device destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1311 | * @sdev: scsi device struct |
| 1312 | * |
| 1313 | * Returns nothing. |
| 1314 | */ |
| 1315 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1316 | _scsih_slave_destroy(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1317 | { |
| 1318 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1319 | struct scsi_target *starget; |
| 1320 | |
| 1321 | if (!sdev->hostdata) |
| 1322 | return; |
| 1323 | |
| 1324 | starget = scsi_target(sdev); |
| 1325 | sas_target_priv_data = starget->hostdata; |
| 1326 | sas_target_priv_data->num_luns--; |
| 1327 | kfree(sdev->hostdata); |
| 1328 | sdev->hostdata = NULL; |
| 1329 | } |
| 1330 | |
| 1331 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1332 | * _scsih_display_sata_capabilities - sata capabilities |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1333 | * @ioc: per adapter object |
| 1334 | * @sas_device: the sas_device object |
| 1335 | * @sdev: scsi device struct |
| 1336 | */ |
| 1337 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1338 | _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1339 | struct _sas_device *sas_device, struct scsi_device *sdev) |
| 1340 | { |
| 1341 | Mpi2ConfigReply_t mpi_reply; |
| 1342 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1343 | u32 ioc_status; |
| 1344 | u16 flags; |
| 1345 | u32 device_info; |
| 1346 | |
| 1347 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 1348 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) { |
| 1349 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1350 | ioc->name, __FILE__, __LINE__, __func__); |
| 1351 | return; |
| 1352 | } |
| 1353 | |
| 1354 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1355 | MPI2_IOCSTATUS_MASK; |
| 1356 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 1357 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1358 | ioc->name, __FILE__, __LINE__, __func__); |
| 1359 | return; |
| 1360 | } |
| 1361 | |
| 1362 | flags = le16_to_cpu(sas_device_pg0.Flags); |
| 1363 | device_info = le16_to_cpu(sas_device_pg0.DeviceInfo); |
| 1364 | |
| 1365 | sdev_printk(KERN_INFO, sdev, |
| 1366 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " |
| 1367 | "sw_preserve(%s)\n", |
| 1368 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", |
| 1369 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", |
| 1370 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : |
| 1371 | "n", |
| 1372 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", |
| 1373 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", |
| 1374 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); |
| 1375 | } |
| 1376 | |
| 1377 | /** |
| 1378 | * _scsih_get_volume_capabilities - volume capabilities |
| 1379 | * @ioc: per adapter object |
| 1380 | * @sas_device: the raid_device object |
| 1381 | */ |
| 1382 | static void |
| 1383 | _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc, |
| 1384 | struct _raid_device *raid_device) |
| 1385 | { |
| 1386 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1387 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1388 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1389 | Mpi2ConfigReply_t mpi_reply; |
| 1390 | u16 sz; |
| 1391 | u8 num_pds; |
| 1392 | |
| 1393 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1394 | &num_pds)) || !num_pds) { |
| 1395 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1396 | ioc->name, __FILE__, __LINE__, __func__); |
| 1397 | return; |
| 1398 | } |
| 1399 | |
| 1400 | raid_device->num_pds = num_pds; |
| 1401 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1402 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1403 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1404 | if (!vol_pg0) { |
| 1405 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1406 | ioc->name, __FILE__, __LINE__, __func__); |
| 1407 | return; |
| 1408 | } |
| 1409 | |
| 1410 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1411 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
| 1412 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1413 | ioc->name, __FILE__, __LINE__, __func__); |
| 1414 | kfree(vol_pg0); |
| 1415 | return; |
| 1416 | } |
| 1417 | |
| 1418 | raid_device->volume_type = vol_pg0->VolumeType; |
| 1419 | |
| 1420 | /* figure out what the underlying devices are by |
| 1421 | * obtaining the device_info bits for the 1st device |
| 1422 | */ |
| 1423 | if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1424 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1425 | vol_pg0->PhysDisk[0].PhysDiskNum))) { |
| 1426 | if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 1427 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 1428 | le16_to_cpu(pd_pg0.DevHandle)))) { |
| 1429 | raid_device->device_info = |
| 1430 | le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 1431 | } |
| 1432 | } |
| 1433 | |
| 1434 | kfree(vol_pg0); |
| 1435 | } |
| 1436 | |
| 1437 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1438 | * _scsih_slave_configure - device configure routine. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1439 | * @sdev: scsi device struct |
| 1440 | * |
| 1441 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1442 | * the device is ignored. |
| 1443 | */ |
| 1444 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1445 | _scsih_slave_configure(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1446 | { |
| 1447 | struct Scsi_Host *shost = sdev->host; |
| 1448 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1449 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1450 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1451 | struct _sas_device *sas_device; |
| 1452 | struct _raid_device *raid_device; |
| 1453 | unsigned long flags; |
| 1454 | int qdepth; |
| 1455 | u8 ssp_target = 0; |
| 1456 | char *ds = ""; |
| 1457 | char *r_level = ""; |
| 1458 | |
| 1459 | qdepth = 1; |
| 1460 | sas_device_priv_data = sdev->hostdata; |
| 1461 | sas_device_priv_data->configured_lun = 1; |
| 1462 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; |
| 1463 | sas_target_priv_data = sas_device_priv_data->sas_target; |
| 1464 | |
| 1465 | /* raid volume handling */ |
| 1466 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 1467 | |
| 1468 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1469 | raid_device = _scsih_raid_device_find_by_handle(ioc, |
| 1470 | sas_target_priv_data->handle); |
| 1471 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1472 | if (!raid_device) { |
| 1473 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1474 | ioc->name, __FILE__, __LINE__, __func__); |
| 1475 | return 0; |
| 1476 | } |
| 1477 | |
| 1478 | _scsih_get_volume_capabilities(ioc, raid_device); |
| 1479 | |
| 1480 | /* RAID Queue Depth Support |
| 1481 | * IS volume = underlying qdepth of drive type, either |
| 1482 | * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH |
| 1483 | * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH) |
| 1484 | */ |
| 1485 | if (raid_device->device_info & |
| 1486 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 1487 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 1488 | ds = "SSP"; |
| 1489 | } else { |
| 1490 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 1491 | if (raid_device->device_info & |
| 1492 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1493 | ds = "SATA"; |
| 1494 | else |
| 1495 | ds = "STP"; |
| 1496 | } |
| 1497 | |
| 1498 | switch (raid_device->volume_type) { |
| 1499 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 1500 | r_level = "RAID0"; |
| 1501 | break; |
| 1502 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 1503 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 1504 | r_level = "RAID1E"; |
| 1505 | break; |
| 1506 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 1507 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 1508 | r_level = "RAID1"; |
| 1509 | break; |
| 1510 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 1511 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 1512 | r_level = "RAID10"; |
| 1513 | break; |
| 1514 | case MPI2_RAID_VOL_TYPE_UNKNOWN: |
| 1515 | default: |
| 1516 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 1517 | r_level = "RAIDX"; |
| 1518 | break; |
| 1519 | } |
| 1520 | |
| 1521 | sdev_printk(KERN_INFO, sdev, "%s: " |
| 1522 | "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n", |
| 1523 | r_level, raid_device->handle, |
| 1524 | (unsigned long long)raid_device->wwid, |
| 1525 | raid_device->num_pds, ds); |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1526 | _scsih_change_queue_depth(sdev, qdepth); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1527 | return 0; |
| 1528 | } |
| 1529 | |
| 1530 | /* non-raid handling */ |
| 1531 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1532 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1533 | sas_device_priv_data->sas_target->sas_address); |
| 1534 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1535 | if (sas_device) { |
| 1536 | if (sas_target_priv_data->flags & |
| 1537 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 1538 | mpt2sas_config_get_volume_handle(ioc, |
| 1539 | sas_device->handle, &sas_device->volume_handle); |
| 1540 | mpt2sas_config_get_volume_wwid(ioc, |
| 1541 | sas_device->volume_handle, |
| 1542 | &sas_device->volume_wwid); |
| 1543 | } |
| 1544 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 1545 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 1546 | ssp_target = 1; |
| 1547 | ds = "SSP"; |
| 1548 | } else { |
| 1549 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 1550 | if (sas_device->device_info & |
| 1551 | MPI2_SAS_DEVICE_INFO_STP_TARGET) |
| 1552 | ds = "STP"; |
| 1553 | else if (sas_device->device_info & |
| 1554 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1555 | ds = "SATA"; |
| 1556 | } |
| 1557 | |
| 1558 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
| 1559 | "sas_addr(0x%016llx), device_name(0x%016llx)\n", |
| 1560 | ds, sas_device->handle, |
| 1561 | (unsigned long long)sas_device->sas_address, |
| 1562 | (unsigned long long)sas_device->device_name); |
| 1563 | sdev_printk(KERN_INFO, sdev, "%s: " |
| 1564 | "enclosure_logical_id(0x%016llx), slot(%d)\n", ds, |
| 1565 | (unsigned long long) sas_device->enclosure_logical_id, |
| 1566 | sas_device->slot); |
| 1567 | |
| 1568 | if (!ssp_target) |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1569 | _scsih_display_sata_capabilities(ioc, sas_device, sdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1570 | } |
| 1571 | |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1572 | _scsih_change_queue_depth(sdev, qdepth); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1573 | |
| 1574 | if (ssp_target) |
| 1575 | sas_read_port_mode_page(sdev); |
| 1576 | return 0; |
| 1577 | } |
| 1578 | |
| 1579 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1580 | * _scsih_bios_param - fetch head, sector, cylinder info for a disk |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1581 | * @sdev: scsi device struct |
| 1582 | * @bdev: pointer to block device context |
| 1583 | * @capacity: device size (in 512 byte sectors) |
| 1584 | * @params: three element array to place output: |
| 1585 | * params[0] number of heads (max 255) |
| 1586 | * params[1] number of sectors (max 63) |
| 1587 | * params[2] number of cylinders |
| 1588 | * |
| 1589 | * Return nothing. |
| 1590 | */ |
| 1591 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1592 | _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1593 | sector_t capacity, int params[]) |
| 1594 | { |
| 1595 | int heads; |
| 1596 | int sectors; |
| 1597 | sector_t cylinders; |
| 1598 | ulong dummy; |
| 1599 | |
| 1600 | heads = 64; |
| 1601 | sectors = 32; |
| 1602 | |
| 1603 | dummy = heads * sectors; |
| 1604 | cylinders = capacity; |
| 1605 | sector_div(cylinders, dummy); |
| 1606 | |
| 1607 | /* |
| 1608 | * Handle extended translation size for logical drives |
| 1609 | * > 1Gb |
| 1610 | */ |
| 1611 | if ((ulong)capacity >= 0x200000) { |
| 1612 | heads = 255; |
| 1613 | sectors = 63; |
| 1614 | dummy = heads * sectors; |
| 1615 | cylinders = capacity; |
| 1616 | sector_div(cylinders, dummy); |
| 1617 | } |
| 1618 | |
| 1619 | /* return result */ |
| 1620 | params[0] = heads; |
| 1621 | params[1] = sectors; |
| 1622 | params[2] = cylinders; |
| 1623 | |
| 1624 | return 0; |
| 1625 | } |
| 1626 | |
| 1627 | /** |
| 1628 | * _scsih_response_code - translation of device response code |
| 1629 | * @ioc: per adapter object |
| 1630 | * @response_code: response code returned by the device |
| 1631 | * |
| 1632 | * Return nothing. |
| 1633 | */ |
| 1634 | static void |
| 1635 | _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code) |
| 1636 | { |
| 1637 | char *desc; |
| 1638 | |
| 1639 | switch (response_code) { |
| 1640 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: |
| 1641 | desc = "task management request completed"; |
| 1642 | break; |
| 1643 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: |
| 1644 | desc = "invalid frame"; |
| 1645 | break; |
| 1646 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: |
| 1647 | desc = "task management request not supported"; |
| 1648 | break; |
| 1649 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: |
| 1650 | desc = "task management request failed"; |
| 1651 | break; |
| 1652 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: |
| 1653 | desc = "task management request succeeded"; |
| 1654 | break; |
| 1655 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: |
| 1656 | desc = "invalid lun"; |
| 1657 | break; |
| 1658 | case 0xA: |
| 1659 | desc = "overlapped tag attempted"; |
| 1660 | break; |
| 1661 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: |
| 1662 | desc = "task queued, however not sent to target"; |
| 1663 | break; |
| 1664 | default: |
| 1665 | desc = "unknown"; |
| 1666 | break; |
| 1667 | } |
| 1668 | printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n", |
| 1669 | ioc->name, response_code, desc); |
| 1670 | } |
| 1671 | |
| 1672 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1673 | * _scsih_tm_done - tm completion routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1674 | * @ioc: per adapter object |
| 1675 | * @smid: system request message index |
| 1676 | * @VF_ID: virtual function id |
| 1677 | * @reply: reply message frame(lower 32bit addr) |
| 1678 | * Context: none. |
| 1679 | * |
| 1680 | * The callback handler when using scsih_issue_tm. |
| 1681 | * |
| 1682 | * Return nothing. |
| 1683 | */ |
| 1684 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1685 | _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1686 | { |
| 1687 | MPI2DefaultReply_t *mpi_reply; |
| 1688 | |
| 1689 | if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED) |
| 1690 | return; |
| 1691 | if (ioc->tm_cmds.smid != smid) |
| 1692 | return; |
| 1693 | ioc->tm_cmds.status |= MPT2_CMD_COMPLETE; |
| 1694 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 1695 | if (mpi_reply) { |
| 1696 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 1697 | ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 1698 | } |
| 1699 | ioc->tm_cmds.status &= ~MPT2_CMD_PENDING; |
| 1700 | complete(&ioc->tm_cmds.done); |
| 1701 | } |
| 1702 | |
| 1703 | /** |
| 1704 | * mpt2sas_scsih_set_tm_flag - set per target tm_busy |
| 1705 | * @ioc: per adapter object |
| 1706 | * @handle: device handle |
| 1707 | * |
| 1708 | * During taskmangement request, we need to freeze the device queue. |
| 1709 | */ |
| 1710 | void |
| 1711 | mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 1712 | { |
| 1713 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1714 | struct scsi_device *sdev; |
| 1715 | u8 skip = 0; |
| 1716 | |
| 1717 | shost_for_each_device(sdev, ioc->shost) { |
| 1718 | if (skip) |
| 1719 | continue; |
| 1720 | sas_device_priv_data = sdev->hostdata; |
| 1721 | if (!sas_device_priv_data) |
| 1722 | continue; |
| 1723 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 1724 | sas_device_priv_data->sas_target->tm_busy = 1; |
| 1725 | skip = 1; |
| 1726 | ioc->ignore_loginfos = 1; |
| 1727 | } |
| 1728 | } |
| 1729 | } |
| 1730 | |
| 1731 | /** |
| 1732 | * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy |
| 1733 | * @ioc: per adapter object |
| 1734 | * @handle: device handle |
| 1735 | * |
| 1736 | * During taskmangement request, we need to freeze the device queue. |
| 1737 | */ |
| 1738 | void |
| 1739 | mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 1740 | { |
| 1741 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1742 | struct scsi_device *sdev; |
| 1743 | u8 skip = 0; |
| 1744 | |
| 1745 | shost_for_each_device(sdev, ioc->shost) { |
| 1746 | if (skip) |
| 1747 | continue; |
| 1748 | sas_device_priv_data = sdev->hostdata; |
| 1749 | if (!sas_device_priv_data) |
| 1750 | continue; |
| 1751 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 1752 | sas_device_priv_data->sas_target->tm_busy = 0; |
| 1753 | skip = 1; |
| 1754 | ioc->ignore_loginfos = 0; |
| 1755 | } |
| 1756 | } |
| 1757 | } |
| 1758 | |
| 1759 | /** |
| 1760 | * mpt2sas_scsih_issue_tm - main routine for sending tm requests |
| 1761 | * @ioc: per adapter struct |
| 1762 | * @device_handle: device handle |
| 1763 | * @lun: lun number |
| 1764 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) |
| 1765 | * @smid_task: smid assigned to the task |
| 1766 | * @timeout: timeout in seconds |
| 1767 | * Context: The calling function needs to acquire the tm_cmds.mutex |
| 1768 | * |
| 1769 | * A generic API for sending task management requests to firmware. |
| 1770 | * |
| 1771 | * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling |
| 1772 | * this API. |
| 1773 | * |
| 1774 | * The callback index is set inside `ioc->tm_cb_idx`. |
| 1775 | * |
| 1776 | * Return nothing. |
| 1777 | */ |
| 1778 | void |
| 1779 | mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint lun, |
| 1780 | u8 type, u16 smid_task, ulong timeout) |
| 1781 | { |
| 1782 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 1783 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
| 1784 | u16 smid = 0; |
| 1785 | u32 ioc_state; |
| 1786 | unsigned long timeleft; |
| 1787 | u8 VF_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1788 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame^] | 1789 | if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) { |
| 1790 | printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n", |
| 1791 | __func__, ioc->name); |
| 1792 | return; |
| 1793 | } |
| 1794 | |
| 1795 | if (ioc->shost_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1796 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 1797 | __func__, ioc->name); |
| 1798 | return; |
| 1799 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1800 | |
| 1801 | ioc_state = mpt2sas_base_get_iocstate(ioc, 0); |
| 1802 | if (ioc_state & MPI2_DOORBELL_USED) { |
| 1803 | dhsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "unexpected doorbell " |
| 1804 | "active!\n", ioc->name)); |
| 1805 | goto issue_host_reset; |
| 1806 | } |
| 1807 | |
| 1808 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 1809 | mpt2sas_base_fault_info(ioc, ioc_state & |
| 1810 | MPI2_DOORBELL_DATA_MASK); |
| 1811 | goto issue_host_reset; |
| 1812 | } |
| 1813 | |
| 1814 | smid = mpt2sas_base_get_smid(ioc, ioc->tm_cb_idx); |
| 1815 | if (!smid) { |
| 1816 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 1817 | ioc->name, __func__); |
| 1818 | return; |
| 1819 | } |
| 1820 | |
| 1821 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x)," |
| 1822 | " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type, smid)); |
| 1823 | ioc->tm_cmds.status = MPT2_CMD_PENDING; |
| 1824 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 1825 | ioc->tm_cmds.smid = smid; |
| 1826 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 1827 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 1828 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 1829 | mpi_request->TaskType = type; |
| 1830 | mpi_request->TaskMID = cpu_to_le16(smid_task); |
| 1831 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); |
| 1832 | mpt2sas_scsih_set_tm_flag(ioc, handle); |
| 1833 | mpt2sas_base_put_smid_hi_priority(ioc, smid, VF_ID); |
| 1834 | timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
| 1835 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 1836 | if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) { |
| 1837 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 1838 | ioc->name, __func__); |
| 1839 | _debug_dump_mf(mpi_request, |
| 1840 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
| 1841 | if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) |
| 1842 | goto issue_host_reset; |
| 1843 | } |
| 1844 | |
| 1845 | if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 1846 | mpi_reply = ioc->tm_cmds.reply; |
| 1847 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: " |
| 1848 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", |
| 1849 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 1850 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 1851 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 1852 | if (ioc->logging_level & MPT_DEBUG_TM) |
| 1853 | _scsih_response_code(ioc, mpi_reply->ResponseCode); |
| 1854 | } |
| 1855 | return; |
| 1856 | issue_host_reset: |
| 1857 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, FORCE_BIG_HAMMER); |
| 1858 | } |
| 1859 | |
| 1860 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1861 | * _scsih_abort - eh threads main abort routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1862 | * @sdev: scsi device struct |
| 1863 | * |
| 1864 | * Returns SUCCESS if command aborted else FAILED |
| 1865 | */ |
| 1866 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1867 | _scsih_abort(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1868 | { |
| 1869 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 1870 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1871 | u16 smid; |
| 1872 | u16 handle; |
| 1873 | int r; |
| 1874 | struct scsi_cmnd *scmd_lookup; |
| 1875 | |
| 1876 | printk(MPT2SAS_INFO_FMT "attempting task abort! scmd(%p)\n", |
| 1877 | ioc->name, scmd); |
| 1878 | scsi_print_command(scmd); |
| 1879 | |
| 1880 | sas_device_priv_data = scmd->device->hostdata; |
| 1881 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
| 1882 | printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n", |
| 1883 | ioc->name, scmd); |
| 1884 | scmd->result = DID_NO_CONNECT << 16; |
| 1885 | scmd->scsi_done(scmd); |
| 1886 | r = SUCCESS; |
| 1887 | goto out; |
| 1888 | } |
| 1889 | |
| 1890 | /* search for the command */ |
| 1891 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); |
| 1892 | if (!smid) { |
| 1893 | scmd->result = DID_RESET << 16; |
| 1894 | r = SUCCESS; |
| 1895 | goto out; |
| 1896 | } |
| 1897 | |
| 1898 | /* for hidden raid components and volumes this is not supported */ |
| 1899 | if (sas_device_priv_data->sas_target->flags & |
| 1900 | MPT_TARGET_FLAGS_RAID_COMPONENT || |
| 1901 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 1902 | scmd->result = DID_RESET << 16; |
| 1903 | r = FAILED; |
| 1904 | goto out; |
| 1905 | } |
| 1906 | |
| 1907 | mutex_lock(&ioc->tm_cmds.mutex); |
| 1908 | handle = sas_device_priv_data->sas_target->handle; |
| 1909 | mpt2sas_scsih_issue_tm(ioc, handle, sas_device_priv_data->lun, |
| 1910 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30); |
| 1911 | |
| 1912 | /* sanity check - see whether command actually completed */ |
| 1913 | scmd_lookup = _scsih_scsi_lookup_get(ioc, smid); |
| 1914 | if (scmd_lookup && (scmd_lookup->serial_number == scmd->serial_number)) |
| 1915 | r = FAILED; |
| 1916 | else |
| 1917 | r = SUCCESS; |
| 1918 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
| 1919 | mutex_unlock(&ioc->tm_cmds.mutex); |
| 1920 | |
| 1921 | out: |
| 1922 | printk(MPT2SAS_INFO_FMT "task abort: %s scmd(%p)\n", |
| 1923 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 1924 | return r; |
| 1925 | } |
| 1926 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1927 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1928 | * _scsih_dev_reset - eh threads main device reset routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1929 | * @sdev: scsi device struct |
| 1930 | * |
| 1931 | * Returns SUCCESS if command aborted else FAILED |
| 1932 | */ |
| 1933 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1934 | _scsih_dev_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1935 | { |
| 1936 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 1937 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1938 | struct _sas_device *sas_device; |
| 1939 | unsigned long flags; |
| 1940 | u16 handle; |
| 1941 | int r; |
| 1942 | |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 1943 | printk(MPT2SAS_INFO_FMT "attempting device reset! scmd(%p)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1944 | ioc->name, scmd); |
| 1945 | scsi_print_command(scmd); |
| 1946 | |
| 1947 | sas_device_priv_data = scmd->device->hostdata; |
| 1948 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
| 1949 | printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n", |
| 1950 | ioc->name, scmd); |
| 1951 | scmd->result = DID_NO_CONNECT << 16; |
| 1952 | scmd->scsi_done(scmd); |
| 1953 | r = SUCCESS; |
| 1954 | goto out; |
| 1955 | } |
| 1956 | |
| 1957 | /* for hidden raid components obtain the volume_handle */ |
| 1958 | handle = 0; |
| 1959 | if (sas_device_priv_data->sas_target->flags & |
| 1960 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 1961 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1962 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 1963 | sas_device_priv_data->sas_target->handle); |
| 1964 | if (sas_device) |
| 1965 | handle = sas_device->volume_handle; |
| 1966 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1967 | } else |
| 1968 | handle = sas_device_priv_data->sas_target->handle; |
| 1969 | |
| 1970 | if (!handle) { |
| 1971 | scmd->result = DID_RESET << 16; |
| 1972 | r = FAILED; |
| 1973 | goto out; |
| 1974 | } |
| 1975 | |
| 1976 | mutex_lock(&ioc->tm_cmds.mutex); |
| 1977 | mpt2sas_scsih_issue_tm(ioc, handle, 0, |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 1978 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, scmd->device->lun, |
| 1979 | 30); |
| 1980 | |
| 1981 | /* |
| 1982 | * sanity check see whether all commands to this device been |
| 1983 | * completed |
| 1984 | */ |
| 1985 | if (_scsih_scsi_lookup_find_by_lun(ioc, scmd->device->id, |
| 1986 | scmd->device->lun, scmd->device->channel)) |
| 1987 | r = FAILED; |
| 1988 | else |
| 1989 | r = SUCCESS; |
| 1990 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
| 1991 | mutex_unlock(&ioc->tm_cmds.mutex); |
| 1992 | |
| 1993 | out: |
| 1994 | printk(MPT2SAS_INFO_FMT "device reset: %s scmd(%p)\n", |
| 1995 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 1996 | return r; |
| 1997 | } |
| 1998 | |
| 1999 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2000 | * _scsih_target_reset - eh threads main target reset routine |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2001 | * @sdev: scsi device struct |
| 2002 | * |
| 2003 | * Returns SUCCESS if command aborted else FAILED |
| 2004 | */ |
| 2005 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2006 | _scsih_target_reset(struct scsi_cmnd *scmd) |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2007 | { |
| 2008 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2009 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2010 | struct _sas_device *sas_device; |
| 2011 | unsigned long flags; |
| 2012 | u16 handle; |
| 2013 | int r; |
| 2014 | |
| 2015 | printk(MPT2SAS_INFO_FMT "attempting target reset! scmd(%p)\n", |
| 2016 | ioc->name, scmd); |
| 2017 | scsi_print_command(scmd); |
| 2018 | |
| 2019 | sas_device_priv_data = scmd->device->hostdata; |
| 2020 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
| 2021 | printk(MPT2SAS_INFO_FMT "target been deleted! scmd(%p)\n", |
| 2022 | ioc->name, scmd); |
| 2023 | scmd->result = DID_NO_CONNECT << 16; |
| 2024 | scmd->scsi_done(scmd); |
| 2025 | r = SUCCESS; |
| 2026 | goto out; |
| 2027 | } |
| 2028 | |
| 2029 | /* for hidden raid components obtain the volume_handle */ |
| 2030 | handle = 0; |
| 2031 | if (sas_device_priv_data->sas_target->flags & |
| 2032 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2033 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2034 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2035 | sas_device_priv_data->sas_target->handle); |
| 2036 | if (sas_device) |
| 2037 | handle = sas_device->volume_handle; |
| 2038 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2039 | } else |
| 2040 | handle = sas_device_priv_data->sas_target->handle; |
| 2041 | |
| 2042 | if (!handle) { |
| 2043 | scmd->result = DID_RESET << 16; |
| 2044 | r = FAILED; |
| 2045 | goto out; |
| 2046 | } |
| 2047 | |
| 2048 | mutex_lock(&ioc->tm_cmds.mutex); |
| 2049 | mpt2sas_scsih_issue_tm(ioc, handle, 0, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2050 | MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 30); |
| 2051 | |
| 2052 | /* |
| 2053 | * sanity check see whether all commands to this target been |
| 2054 | * completed |
| 2055 | */ |
| 2056 | if (_scsih_scsi_lookup_find_by_target(ioc, scmd->device->id, |
| 2057 | scmd->device->channel)) |
| 2058 | r = FAILED; |
| 2059 | else |
| 2060 | r = SUCCESS; |
| 2061 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
| 2062 | mutex_unlock(&ioc->tm_cmds.mutex); |
| 2063 | |
| 2064 | out: |
| 2065 | printk(MPT2SAS_INFO_FMT "target reset: %s scmd(%p)\n", |
| 2066 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 2067 | return r; |
| 2068 | } |
| 2069 | |
| 2070 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2071 | * _scsih_abort - eh threads main host reset routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2072 | * @sdev: scsi device struct |
| 2073 | * |
| 2074 | * Returns SUCCESS if command aborted else FAILED |
| 2075 | */ |
| 2076 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2077 | _scsih_host_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2078 | { |
| 2079 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2080 | int r, retval; |
| 2081 | |
| 2082 | printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n", |
| 2083 | ioc->name, scmd); |
| 2084 | scsi_print_command(scmd); |
| 2085 | |
| 2086 | retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2087 | FORCE_BIG_HAMMER); |
| 2088 | r = (retval < 0) ? FAILED : SUCCESS; |
| 2089 | printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n", |
| 2090 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 2091 | |
| 2092 | return r; |
| 2093 | } |
| 2094 | |
| 2095 | /** |
| 2096 | * _scsih_fw_event_add - insert and queue up fw_event |
| 2097 | * @ioc: per adapter object |
| 2098 | * @fw_event: object describing the event |
| 2099 | * Context: This function will acquire ioc->fw_event_lock. |
| 2100 | * |
| 2101 | * This adds the firmware event object into link list, then queues it up to |
| 2102 | * be processed from user context. |
| 2103 | * |
| 2104 | * Return nothing. |
| 2105 | */ |
| 2106 | static void |
| 2107 | _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event) |
| 2108 | { |
| 2109 | unsigned long flags; |
| 2110 | |
| 2111 | if (ioc->firmware_event_thread == NULL) |
| 2112 | return; |
| 2113 | |
| 2114 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2115 | list_add_tail(&fw_event->list, &ioc->fw_event_list); |
Eric Moore | 6f92a7a | 2009-04-21 15:43:33 -0600 | [diff] [blame] | 2116 | INIT_WORK(&fw_event->work, _firmware_event_work); |
| 2117 | queue_work(ioc->firmware_event_thread, &fw_event->work); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2118 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2119 | } |
| 2120 | |
| 2121 | /** |
| 2122 | * _scsih_fw_event_free - delete fw_event |
| 2123 | * @ioc: per adapter object |
| 2124 | * @fw_event: object describing the event |
| 2125 | * Context: This function will acquire ioc->fw_event_lock. |
| 2126 | * |
| 2127 | * This removes firmware event object from link list, frees associated memory. |
| 2128 | * |
| 2129 | * Return nothing. |
| 2130 | */ |
| 2131 | static void |
| 2132 | _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work |
| 2133 | *fw_event) |
| 2134 | { |
| 2135 | unsigned long flags; |
| 2136 | |
| 2137 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2138 | list_del(&fw_event->list); |
| 2139 | kfree(fw_event->event_data); |
| 2140 | kfree(fw_event); |
| 2141 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2142 | } |
| 2143 | |
| 2144 | /** |
| 2145 | * _scsih_fw_event_add - requeue an event |
| 2146 | * @ioc: per adapter object |
| 2147 | * @fw_event: object describing the event |
| 2148 | * Context: This function will acquire ioc->fw_event_lock. |
| 2149 | * |
| 2150 | * Return nothing. |
| 2151 | */ |
| 2152 | static void |
| 2153 | _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work |
| 2154 | *fw_event, unsigned long delay) |
| 2155 | { |
| 2156 | unsigned long flags; |
| 2157 | if (ioc->firmware_event_thread == NULL) |
| 2158 | return; |
| 2159 | |
| 2160 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
Eric Moore | 6f92a7a | 2009-04-21 15:43:33 -0600 | [diff] [blame] | 2161 | queue_work(ioc->firmware_event_thread, &fw_event->work); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2162 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2163 | } |
| 2164 | |
| 2165 | /** |
| 2166 | * _scsih_fw_event_off - turn flag off preventing event handling |
| 2167 | * @ioc: per adapter object |
| 2168 | * |
| 2169 | * Used to prevent handling of firmware events during adapter reset |
| 2170 | * driver unload. |
| 2171 | * |
| 2172 | * Return nothing. |
| 2173 | */ |
| 2174 | static void |
| 2175 | _scsih_fw_event_off(struct MPT2SAS_ADAPTER *ioc) |
| 2176 | { |
| 2177 | unsigned long flags; |
| 2178 | |
| 2179 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2180 | ioc->fw_events_off = 1; |
| 2181 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2182 | |
| 2183 | } |
| 2184 | |
| 2185 | /** |
| 2186 | * _scsih_fw_event_on - turn flag on allowing firmware event handling |
| 2187 | * @ioc: per adapter object |
| 2188 | * |
| 2189 | * Returns nothing. |
| 2190 | */ |
| 2191 | static void |
| 2192 | _scsih_fw_event_on(struct MPT2SAS_ADAPTER *ioc) |
| 2193 | { |
| 2194 | unsigned long flags; |
| 2195 | |
| 2196 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2197 | ioc->fw_events_off = 0; |
| 2198 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2199 | } |
| 2200 | |
| 2201 | /** |
| 2202 | * _scsih_ublock_io_device - set the device state to SDEV_RUNNING |
| 2203 | * @ioc: per adapter object |
| 2204 | * @handle: device handle |
| 2205 | * |
| 2206 | * During device pull we need to appropiately set the sdev state. |
| 2207 | */ |
| 2208 | static void |
| 2209 | _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2210 | { |
| 2211 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2212 | struct scsi_device *sdev; |
| 2213 | |
| 2214 | shost_for_each_device(sdev, ioc->shost) { |
| 2215 | sas_device_priv_data = sdev->hostdata; |
| 2216 | if (!sas_device_priv_data) |
| 2217 | continue; |
| 2218 | if (!sas_device_priv_data->block) |
| 2219 | continue; |
| 2220 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2221 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2222 | MPT2SAS_INFO_FMT "SDEV_RUNNING: " |
| 2223 | "handle(0x%04x)\n", ioc->name, handle)); |
| 2224 | sas_device_priv_data->block = 0; |
| 2225 | scsi_device_set_state(sdev, SDEV_RUNNING); |
| 2226 | } |
| 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | /** |
| 2231 | * _scsih_block_io_device - set the device state to SDEV_BLOCK |
| 2232 | * @ioc: per adapter object |
| 2233 | * @handle: device handle |
| 2234 | * |
| 2235 | * During device pull we need to appropiately set the sdev state. |
| 2236 | */ |
| 2237 | static void |
| 2238 | _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2239 | { |
| 2240 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2241 | struct scsi_device *sdev; |
| 2242 | |
| 2243 | shost_for_each_device(sdev, ioc->shost) { |
| 2244 | sas_device_priv_data = sdev->hostdata; |
| 2245 | if (!sas_device_priv_data) |
| 2246 | continue; |
| 2247 | if (sas_device_priv_data->block) |
| 2248 | continue; |
| 2249 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2250 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2251 | MPT2SAS_INFO_FMT "SDEV_BLOCK: " |
| 2252 | "handle(0x%04x)\n", ioc->name, handle)); |
| 2253 | sas_device_priv_data->block = 1; |
| 2254 | scsi_device_set_state(sdev, SDEV_BLOCK); |
| 2255 | } |
| 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | /** |
| 2260 | * _scsih_block_io_to_children_attached_to_ex |
| 2261 | * @ioc: per adapter object |
| 2262 | * @sas_expander: the sas_device object |
| 2263 | * |
| 2264 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 2265 | * attached to this expander. This function called when expander is |
| 2266 | * pulled. |
| 2267 | */ |
| 2268 | static void |
| 2269 | _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc, |
| 2270 | struct _sas_node *sas_expander) |
| 2271 | { |
| 2272 | struct _sas_port *mpt2sas_port; |
| 2273 | struct _sas_device *sas_device; |
| 2274 | struct _sas_node *expander_sibling; |
| 2275 | unsigned long flags; |
| 2276 | |
| 2277 | if (!sas_expander) |
| 2278 | return; |
| 2279 | |
| 2280 | list_for_each_entry(mpt2sas_port, |
| 2281 | &sas_expander->sas_port_list, port_list) { |
| 2282 | if (mpt2sas_port->remote_identify.device_type == |
| 2283 | SAS_END_DEVICE) { |
| 2284 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2285 | sas_device = |
| 2286 | mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2287 | mpt2sas_port->remote_identify.sas_address); |
| 2288 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2289 | if (!sas_device) |
| 2290 | continue; |
| 2291 | _scsih_block_io_device(ioc, sas_device->handle); |
| 2292 | } |
| 2293 | } |
| 2294 | |
| 2295 | list_for_each_entry(mpt2sas_port, |
| 2296 | &sas_expander->sas_port_list, port_list) { |
| 2297 | |
| 2298 | if (mpt2sas_port->remote_identify.device_type == |
| 2299 | MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER || |
| 2300 | mpt2sas_port->remote_identify.device_type == |
| 2301 | MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) { |
| 2302 | |
| 2303 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 2304 | expander_sibling = |
| 2305 | mpt2sas_scsih_expander_find_by_sas_address( |
| 2306 | ioc, mpt2sas_port->remote_identify.sas_address); |
| 2307 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 2308 | _scsih_block_io_to_children_attached_to_ex(ioc, |
| 2309 | expander_sibling); |
| 2310 | } |
| 2311 | } |
| 2312 | } |
| 2313 | |
| 2314 | /** |
| 2315 | * _scsih_block_io_to_children_attached_directly |
| 2316 | * @ioc: per adapter object |
| 2317 | * @event_data: topology change event data |
| 2318 | * |
| 2319 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 2320 | * direct attached during device pull. |
| 2321 | */ |
| 2322 | static void |
| 2323 | _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc, |
| 2324 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 2325 | { |
| 2326 | int i; |
| 2327 | u16 handle; |
| 2328 | u16 reason_code; |
| 2329 | u8 phy_number; |
| 2330 | |
| 2331 | for (i = 0; i < event_data->NumEntries; i++) { |
| 2332 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 2333 | if (!handle) |
| 2334 | continue; |
| 2335 | phy_number = event_data->StartPhyNum + i; |
| 2336 | reason_code = event_data->PHY[i].PhyStatus & |
| 2337 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 2338 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) |
| 2339 | _scsih_block_io_device(ioc, handle); |
| 2340 | } |
| 2341 | } |
| 2342 | |
| 2343 | /** |
| 2344 | * _scsih_check_topo_delete_events - sanity check on topo events |
| 2345 | * @ioc: per adapter object |
| 2346 | * @event_data: the event data payload |
| 2347 | * |
| 2348 | * This routine added to better handle cable breaker. |
| 2349 | * |
| 2350 | * This handles the case where driver recieves multiple expander |
| 2351 | * add and delete events in a single shot. When there is a delete event |
| 2352 | * the routine will void any pending add events waiting in the event queue. |
| 2353 | * |
| 2354 | * Return nothing. |
| 2355 | */ |
| 2356 | static void |
| 2357 | _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 2358 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 2359 | { |
| 2360 | struct fw_event_work *fw_event; |
| 2361 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; |
| 2362 | u16 expander_handle; |
| 2363 | struct _sas_node *sas_expander; |
| 2364 | unsigned long flags; |
| 2365 | |
| 2366 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 2367 | if (expander_handle < ioc->sas_hba.num_phys) { |
| 2368 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 2369 | return; |
| 2370 | } |
| 2371 | |
| 2372 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING |
| 2373 | || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) { |
| 2374 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 2375 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 2376 | expander_handle); |
| 2377 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 2378 | _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); |
| 2379 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) |
| 2380 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 2381 | |
| 2382 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) |
| 2383 | return; |
| 2384 | |
| 2385 | /* mark ignore flag for pending events */ |
| 2386 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2387 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { |
| 2388 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || |
| 2389 | fw_event->ignore) |
| 2390 | continue; |
| 2391 | local_event_data = fw_event->event_data; |
| 2392 | if (local_event_data->ExpStatus == |
| 2393 | MPI2_EVENT_SAS_TOPO_ES_ADDED || |
| 2394 | local_event_data->ExpStatus == |
| 2395 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { |
| 2396 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == |
| 2397 | expander_handle) { |
| 2398 | dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT |
| 2399 | "setting ignoring flag\n", ioc->name)); |
| 2400 | fw_event->ignore = 1; |
| 2401 | } |
| 2402 | } |
| 2403 | } |
| 2404 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2405 | } |
| 2406 | |
| 2407 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2408 | * _scsih_flush_running_cmds - completing outstanding commands. |
| 2409 | * @ioc: per adapter object |
| 2410 | * |
| 2411 | * The flushing out of all pending scmd commands following host reset, |
| 2412 | * where all IO is dropped to the floor. |
| 2413 | * |
| 2414 | * Return nothing. |
| 2415 | */ |
| 2416 | static void |
| 2417 | _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc) |
| 2418 | { |
| 2419 | struct scsi_cmnd *scmd; |
| 2420 | u16 smid; |
| 2421 | u16 count = 0; |
| 2422 | |
| 2423 | for (smid = 1; smid <= ioc->request_depth; smid++) { |
| 2424 | scmd = _scsih_scsi_lookup_getclear(ioc, smid); |
| 2425 | if (!scmd) |
| 2426 | continue; |
| 2427 | count++; |
| 2428 | mpt2sas_base_free_smid(ioc, smid); |
| 2429 | scsi_dma_unmap(scmd); |
| 2430 | scmd->result = DID_RESET << 16; |
| 2431 | scmd->scsi_done(scmd); |
| 2432 | } |
| 2433 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n", |
| 2434 | ioc->name, count)); |
| 2435 | } |
| 2436 | |
| 2437 | /** |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 2438 | * _scsih_setup_eedp - setup MPI request for EEDP transfer |
| 2439 | * @scmd: pointer to scsi command object |
| 2440 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 2441 | * |
| 2442 | * Supporting protection 1 and 3. |
| 2443 | * |
| 2444 | * Returns nothing |
| 2445 | */ |
| 2446 | static void |
| 2447 | _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request) |
| 2448 | { |
| 2449 | u16 eedp_flags; |
| 2450 | unsigned char prot_op = scsi_get_prot_op(scmd); |
| 2451 | unsigned char prot_type = scsi_get_prot_type(scmd); |
| 2452 | |
| 2453 | if (prot_type == SCSI_PROT_DIF_TYPE0 || |
| 2454 | prot_type == SCSI_PROT_DIF_TYPE2 || |
| 2455 | prot_op == SCSI_PROT_NORMAL) |
| 2456 | return; |
| 2457 | |
| 2458 | if (prot_op == SCSI_PROT_READ_STRIP) |
| 2459 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; |
| 2460 | else if (prot_op == SCSI_PROT_WRITE_INSERT) |
| 2461 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; |
| 2462 | else |
| 2463 | return; |
| 2464 | |
| 2465 | mpi_request->EEDPBlockSize = scmd->device->sector_size; |
| 2466 | |
| 2467 | switch (prot_type) { |
| 2468 | case SCSI_PROT_DIF_TYPE1: |
| 2469 | |
| 2470 | /* |
| 2471 | * enable ref/guard checking |
| 2472 | * auto increment ref tag |
| 2473 | */ |
| 2474 | mpi_request->EEDPFlags = eedp_flags | |
| 2475 | MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
| 2476 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | |
| 2477 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
| 2478 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = |
| 2479 | cpu_to_be32(scsi_get_lba(scmd)); |
| 2480 | |
| 2481 | break; |
| 2482 | |
| 2483 | case SCSI_PROT_DIF_TYPE3: |
| 2484 | |
| 2485 | /* |
| 2486 | * enable guard checking |
| 2487 | */ |
| 2488 | mpi_request->EEDPFlags = eedp_flags | |
| 2489 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
| 2490 | |
| 2491 | break; |
| 2492 | } |
| 2493 | } |
| 2494 | |
| 2495 | /** |
| 2496 | * _scsih_eedp_error_handling - return sense code for EEDP errors |
| 2497 | * @scmd: pointer to scsi command object |
| 2498 | * @ioc_status: ioc status |
| 2499 | * |
| 2500 | * Returns nothing |
| 2501 | */ |
| 2502 | static void |
| 2503 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) |
| 2504 | { |
| 2505 | u8 ascq; |
| 2506 | u8 sk; |
| 2507 | u8 host_byte; |
| 2508 | |
| 2509 | switch (ioc_status) { |
| 2510 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 2511 | ascq = 0x01; |
| 2512 | break; |
| 2513 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 2514 | ascq = 0x02; |
| 2515 | break; |
| 2516 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 2517 | ascq = 0x03; |
| 2518 | break; |
| 2519 | default: |
| 2520 | ascq = 0x00; |
| 2521 | break; |
| 2522 | } |
| 2523 | |
| 2524 | if (scmd->sc_data_direction == DMA_TO_DEVICE) { |
| 2525 | sk = ILLEGAL_REQUEST; |
| 2526 | host_byte = DID_ABORT; |
| 2527 | } else { |
| 2528 | sk = ABORTED_COMMAND; |
| 2529 | host_byte = DID_OK; |
| 2530 | } |
| 2531 | |
| 2532 | scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq); |
| 2533 | scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) | |
| 2534 | SAM_STAT_CHECK_CONDITION; |
| 2535 | } |
| 2536 | |
| 2537 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2538 | * _scsih_qcmd - main scsi request entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2539 | * @scmd: pointer to scsi command object |
| 2540 | * @done: function pointer to be invoked on completion |
| 2541 | * |
| 2542 | * The callback index is set inside `ioc->scsi_io_cb_idx`. |
| 2543 | * |
| 2544 | * Returns 0 on success. If there's a failure, return either: |
| 2545 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or |
| 2546 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full |
| 2547 | */ |
| 2548 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2549 | _scsih_qcmd(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2550 | { |
| 2551 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2552 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2553 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 2554 | Mpi2SCSIIORequest_t *mpi_request; |
| 2555 | u32 mpi_control; |
| 2556 | u16 smid; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2557 | |
| 2558 | scmd->scsi_done = done; |
| 2559 | sas_device_priv_data = scmd->device->hostdata; |
| 2560 | if (!sas_device_priv_data) { |
| 2561 | scmd->result = DID_NO_CONNECT << 16; |
| 2562 | scmd->scsi_done(scmd); |
| 2563 | return 0; |
| 2564 | } |
| 2565 | |
| 2566 | sas_target_priv_data = sas_device_priv_data->sas_target; |
| 2567 | if (!sas_target_priv_data || sas_target_priv_data->handle == |
| 2568 | MPT2SAS_INVALID_DEVICE_HANDLE || sas_target_priv_data->deleted) { |
| 2569 | scmd->result = DID_NO_CONNECT << 16; |
| 2570 | scmd->scsi_done(scmd); |
| 2571 | return 0; |
| 2572 | } |
| 2573 | |
| 2574 | /* see if we are busy with task managment stuff */ |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame^] | 2575 | if (sas_target_priv_data->tm_busy) |
| 2576 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 2577 | else if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2578 | return SCSI_MLQUEUE_HOST_BUSY; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2579 | |
| 2580 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) |
| 2581 | mpi_control = MPI2_SCSIIO_CONTROL_READ; |
| 2582 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 2583 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; |
| 2584 | else |
| 2585 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; |
| 2586 | |
| 2587 | /* set tags */ |
| 2588 | if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) { |
| 2589 | if (scmd->device->tagged_supported) { |
| 2590 | if (scmd->device->ordered_tags) |
| 2591 | mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ; |
| 2592 | else |
| 2593 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
| 2594 | } else |
| 2595 | /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */ |
| 2596 | /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED; |
| 2597 | */ |
| 2598 | mpi_control |= (0x500); |
| 2599 | |
| 2600 | } else |
| 2601 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
| 2602 | |
| 2603 | if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON)) |
| 2604 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
| 2605 | |
| 2606 | smid = mpt2sas_base_get_smid(ioc, ioc->scsi_io_cb_idx); |
| 2607 | if (!smid) { |
| 2608 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 2609 | ioc->name, __func__); |
| 2610 | goto out; |
| 2611 | } |
| 2612 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 2613 | memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t)); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 2614 | _scsih_setup_eedp(scmd, mpi_request); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2615 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 2616 | if (sas_device_priv_data->sas_target->flags & |
| 2617 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 2618 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; |
| 2619 | else |
| 2620 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 2621 | mpi_request->DevHandle = |
| 2622 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 2623 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
| 2624 | mpi_request->Control = cpu_to_le32(mpi_control); |
| 2625 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); |
| 2626 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; |
| 2627 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; |
| 2628 | mpi_request->SenseBufferLowAddress = |
| 2629 | (u32)mpt2sas_base_get_sense_buffer_dma(ioc, smid); |
| 2630 | mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4; |
| 2631 | mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI + |
| 2632 | MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR); |
| 2633 | |
| 2634 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
| 2635 | mpi_request->LUN); |
| 2636 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 2637 | |
| 2638 | if (!mpi_request->DataLength) { |
| 2639 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL); |
| 2640 | } else { |
| 2641 | if (_scsih_build_scatter_gather(ioc, scmd, smid)) { |
| 2642 | mpt2sas_base_free_smid(ioc, smid); |
| 2643 | goto out; |
| 2644 | } |
| 2645 | } |
| 2646 | |
| 2647 | _scsih_scsi_lookup_set(ioc, smid, scmd); |
| 2648 | mpt2sas_base_put_smid_scsi_io(ioc, smid, 0, |
| 2649 | sas_device_priv_data->sas_target->handle); |
| 2650 | return 0; |
| 2651 | |
| 2652 | out: |
| 2653 | return SCSI_MLQUEUE_HOST_BUSY; |
| 2654 | } |
| 2655 | |
| 2656 | /** |
| 2657 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data |
| 2658 | * @sense_buffer: sense data returned by target |
| 2659 | * @data: normalized skey/asc/ascq |
| 2660 | * |
| 2661 | * Return nothing. |
| 2662 | */ |
| 2663 | static void |
| 2664 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) |
| 2665 | { |
| 2666 | if ((sense_buffer[0] & 0x7F) >= 0x72) { |
| 2667 | /* descriptor format */ |
| 2668 | data->skey = sense_buffer[1] & 0x0F; |
| 2669 | data->asc = sense_buffer[2]; |
| 2670 | data->ascq = sense_buffer[3]; |
| 2671 | } else { |
| 2672 | /* fixed format */ |
| 2673 | data->skey = sense_buffer[2] & 0x0F; |
| 2674 | data->asc = sense_buffer[12]; |
| 2675 | data->ascq = sense_buffer[13]; |
| 2676 | } |
| 2677 | } |
| 2678 | |
| 2679 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 2680 | /** |
| 2681 | * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request |
| 2682 | * @ioc: per adapter object |
| 2683 | * @scmd: pointer to scsi command object |
| 2684 | * @mpi_reply: reply mf payload returned from firmware |
| 2685 | * |
| 2686 | * scsi_status - SCSI Status code returned from target device |
| 2687 | * scsi_state - state info associated with SCSI_IO determined by ioc |
| 2688 | * ioc_status - ioc supplied status info |
| 2689 | * |
| 2690 | * Return nothing. |
| 2691 | */ |
| 2692 | static void |
| 2693 | _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 2694 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) |
| 2695 | { |
| 2696 | u32 response_info; |
| 2697 | u8 *response_bytes; |
| 2698 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & |
| 2699 | MPI2_IOCSTATUS_MASK; |
| 2700 | u8 scsi_state = mpi_reply->SCSIState; |
| 2701 | u8 scsi_status = mpi_reply->SCSIStatus; |
| 2702 | char *desc_ioc_state = NULL; |
| 2703 | char *desc_scsi_status = NULL; |
| 2704 | char *desc_scsi_state = ioc->tmp_string; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 2705 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
| 2706 | |
| 2707 | if (log_info == 0x31170000) |
| 2708 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2709 | |
| 2710 | switch (ioc_status) { |
| 2711 | case MPI2_IOCSTATUS_SUCCESS: |
| 2712 | desc_ioc_state = "success"; |
| 2713 | break; |
| 2714 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 2715 | desc_ioc_state = "invalid function"; |
| 2716 | break; |
| 2717 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 2718 | desc_ioc_state = "scsi recovered error"; |
| 2719 | break; |
| 2720 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: |
| 2721 | desc_ioc_state = "scsi invalid dev handle"; |
| 2722 | break; |
| 2723 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 2724 | desc_ioc_state = "scsi device not there"; |
| 2725 | break; |
| 2726 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 2727 | desc_ioc_state = "scsi data overrun"; |
| 2728 | break; |
| 2729 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 2730 | desc_ioc_state = "scsi data underrun"; |
| 2731 | break; |
| 2732 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 2733 | desc_ioc_state = "scsi io data error"; |
| 2734 | break; |
| 2735 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 2736 | desc_ioc_state = "scsi protocol error"; |
| 2737 | break; |
| 2738 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 2739 | desc_ioc_state = "scsi task terminated"; |
| 2740 | break; |
| 2741 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 2742 | desc_ioc_state = "scsi residual mismatch"; |
| 2743 | break; |
| 2744 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 2745 | desc_ioc_state = "scsi task mgmt failed"; |
| 2746 | break; |
| 2747 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 2748 | desc_ioc_state = "scsi ioc terminated"; |
| 2749 | break; |
| 2750 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 2751 | desc_ioc_state = "scsi ext terminated"; |
| 2752 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 2753 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 2754 | desc_ioc_state = "eedp guard error"; |
| 2755 | break; |
| 2756 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 2757 | desc_ioc_state = "eedp ref tag error"; |
| 2758 | break; |
| 2759 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 2760 | desc_ioc_state = "eedp app tag error"; |
| 2761 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2762 | default: |
| 2763 | desc_ioc_state = "unknown"; |
| 2764 | break; |
| 2765 | } |
| 2766 | |
| 2767 | switch (scsi_status) { |
| 2768 | case MPI2_SCSI_STATUS_GOOD: |
| 2769 | desc_scsi_status = "good"; |
| 2770 | break; |
| 2771 | case MPI2_SCSI_STATUS_CHECK_CONDITION: |
| 2772 | desc_scsi_status = "check condition"; |
| 2773 | break; |
| 2774 | case MPI2_SCSI_STATUS_CONDITION_MET: |
| 2775 | desc_scsi_status = "condition met"; |
| 2776 | break; |
| 2777 | case MPI2_SCSI_STATUS_BUSY: |
| 2778 | desc_scsi_status = "busy"; |
| 2779 | break; |
| 2780 | case MPI2_SCSI_STATUS_INTERMEDIATE: |
| 2781 | desc_scsi_status = "intermediate"; |
| 2782 | break; |
| 2783 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: |
| 2784 | desc_scsi_status = "intermediate condmet"; |
| 2785 | break; |
| 2786 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: |
| 2787 | desc_scsi_status = "reservation conflict"; |
| 2788 | break; |
| 2789 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: |
| 2790 | desc_scsi_status = "command terminated"; |
| 2791 | break; |
| 2792 | case MPI2_SCSI_STATUS_TASK_SET_FULL: |
| 2793 | desc_scsi_status = "task set full"; |
| 2794 | break; |
| 2795 | case MPI2_SCSI_STATUS_ACA_ACTIVE: |
| 2796 | desc_scsi_status = "aca active"; |
| 2797 | break; |
| 2798 | case MPI2_SCSI_STATUS_TASK_ABORTED: |
| 2799 | desc_scsi_status = "task aborted"; |
| 2800 | break; |
| 2801 | default: |
| 2802 | desc_scsi_status = "unknown"; |
| 2803 | break; |
| 2804 | } |
| 2805 | |
| 2806 | desc_scsi_state[0] = '\0'; |
| 2807 | if (!scsi_state) |
| 2808 | desc_scsi_state = " "; |
| 2809 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 2810 | strcat(desc_scsi_state, "response info "); |
| 2811 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 2812 | strcat(desc_scsi_state, "state terminated "); |
| 2813 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) |
| 2814 | strcat(desc_scsi_state, "no status "); |
| 2815 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) |
| 2816 | strcat(desc_scsi_state, "autosense failed "); |
| 2817 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) |
| 2818 | strcat(desc_scsi_state, "autosense valid "); |
| 2819 | |
| 2820 | scsi_print_command(scmd); |
| 2821 | printk(MPT2SAS_WARN_FMT "\tdev handle(0x%04x), " |
| 2822 | "ioc_status(%s)(0x%04x), smid(%d)\n", ioc->name, |
| 2823 | le16_to_cpu(mpi_reply->DevHandle), desc_ioc_state, |
| 2824 | ioc_status, smid); |
| 2825 | printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), " |
| 2826 | "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow, |
| 2827 | scsi_get_resid(scmd)); |
| 2828 | printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), " |
| 2829 | "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag), |
| 2830 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); |
| 2831 | printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), " |
| 2832 | "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status, |
| 2833 | scsi_status, desc_scsi_state, scsi_state); |
| 2834 | |
| 2835 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 2836 | struct sense_info data; |
| 2837 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 2838 | printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: " |
| 2839 | "[0x%02x,0x%02x,0x%02x]\n", ioc->name, data.skey, |
| 2840 | data.asc, data.ascq); |
| 2841 | } |
| 2842 | |
| 2843 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { |
| 2844 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); |
| 2845 | response_bytes = (u8 *)&response_info; |
| 2846 | _scsih_response_code(ioc, response_bytes[3]); |
| 2847 | } |
| 2848 | } |
| 2849 | #endif |
| 2850 | |
| 2851 | /** |
| 2852 | * _scsih_smart_predicted_fault - illuminate Fault LED |
| 2853 | * @ioc: per adapter object |
| 2854 | * @handle: device handle |
| 2855 | * |
| 2856 | * Return nothing. |
| 2857 | */ |
| 2858 | static void |
| 2859 | _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2860 | { |
| 2861 | Mpi2SepReply_t mpi_reply; |
| 2862 | Mpi2SepRequest_t mpi_request; |
| 2863 | struct scsi_target *starget; |
| 2864 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 2865 | Mpi2EventNotificationReply_t *event_reply; |
| 2866 | Mpi2EventDataSasDeviceStatusChange_t *event_data; |
| 2867 | struct _sas_device *sas_device; |
| 2868 | ssize_t sz; |
| 2869 | unsigned long flags; |
| 2870 | |
| 2871 | /* only handle non-raid devices */ |
| 2872 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2873 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 2874 | if (!sas_device) { |
| 2875 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2876 | return; |
| 2877 | } |
| 2878 | starget = sas_device->starget; |
| 2879 | sas_target_priv_data = starget->hostdata; |
| 2880 | |
| 2881 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || |
| 2882 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) { |
| 2883 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2884 | return; |
| 2885 | } |
| 2886 | starget_printk(KERN_WARNING, starget, "predicted fault\n"); |
| 2887 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2888 | |
| 2889 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) { |
| 2890 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
| 2891 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; |
| 2892 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; |
| 2893 | mpi_request.SlotStatus = |
| 2894 | MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT; |
| 2895 | mpi_request.DevHandle = cpu_to_le16(handle); |
| 2896 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; |
| 2897 | if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply, |
| 2898 | &mpi_request)) != 0) { |
| 2899 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 2900 | ioc->name, __FILE__, __LINE__, __func__); |
| 2901 | return; |
| 2902 | } |
| 2903 | |
| 2904 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { |
| 2905 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 2906 | "enclosure_processor: ioc_status (0x%04x), " |
| 2907 | "loginfo(0x%08x)\n", ioc->name, |
| 2908 | le16_to_cpu(mpi_reply.IOCStatus), |
| 2909 | le32_to_cpu(mpi_reply.IOCLogInfo))); |
| 2910 | return; |
| 2911 | } |
| 2912 | } |
| 2913 | |
| 2914 | /* insert into event log */ |
| 2915 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + |
| 2916 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); |
| 2917 | event_reply = kzalloc(sz, GFP_KERNEL); |
| 2918 | if (!event_reply) { |
| 2919 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 2920 | ioc->name, __FILE__, __LINE__, __func__); |
| 2921 | return; |
| 2922 | } |
| 2923 | |
| 2924 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; |
| 2925 | event_reply->Event = |
| 2926 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); |
| 2927 | event_reply->MsgLength = sz/4; |
| 2928 | event_reply->EventDataLength = |
| 2929 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); |
| 2930 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) |
| 2931 | event_reply->EventData; |
| 2932 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; |
| 2933 | event_data->ASC = 0x5D; |
| 2934 | event_data->DevHandle = cpu_to_le16(handle); |
| 2935 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); |
| 2936 | mpt2sas_ctl_add_to_event_log(ioc, event_reply); |
| 2937 | kfree(event_reply); |
| 2938 | } |
| 2939 | |
| 2940 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2941 | * _scsih_io_done - scsi request callback |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2942 | * @ioc: per adapter object |
| 2943 | * @smid: system request message index |
| 2944 | * @VF_ID: virtual function id |
| 2945 | * @reply: reply message frame(lower 32bit addr) |
| 2946 | * |
| 2947 | * Callback handler when using scsih_qcmd. |
| 2948 | * |
| 2949 | * Return nothing. |
| 2950 | */ |
| 2951 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2952 | _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2953 | { |
| 2954 | Mpi2SCSIIORequest_t *mpi_request; |
| 2955 | Mpi2SCSIIOReply_t *mpi_reply; |
| 2956 | struct scsi_cmnd *scmd; |
| 2957 | u16 ioc_status; |
| 2958 | u32 xfer_cnt; |
| 2959 | u8 scsi_state; |
| 2960 | u8 scsi_status; |
| 2961 | u32 log_info; |
| 2962 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2963 | u32 response_code; |
| 2964 | |
| 2965 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 2966 | scmd = _scsih_scsi_lookup_getclear(ioc, smid); |
| 2967 | if (scmd == NULL) |
| 2968 | return; |
| 2969 | |
| 2970 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 2971 | |
| 2972 | if (mpi_reply == NULL) { |
| 2973 | scmd->result = DID_OK << 16; |
| 2974 | goto out; |
| 2975 | } |
| 2976 | |
| 2977 | sas_device_priv_data = scmd->device->hostdata; |
| 2978 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
| 2979 | sas_device_priv_data->sas_target->deleted) { |
| 2980 | scmd->result = DID_NO_CONNECT << 16; |
| 2981 | goto out; |
| 2982 | } |
| 2983 | |
| 2984 | /* turning off TLR */ |
| 2985 | if (!sas_device_priv_data->tlr_snoop_check) { |
| 2986 | sas_device_priv_data->tlr_snoop_check++; |
| 2987 | if (sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) { |
| 2988 | response_code = (le32_to_cpu(mpi_reply->ResponseInfo) |
| 2989 | >> 24); |
| 2990 | if (response_code == |
| 2991 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) |
| 2992 | sas_device_priv_data->flags &= |
| 2993 | ~MPT_DEVICE_TLR_ON; |
| 2994 | } |
| 2995 | } |
| 2996 | |
| 2997 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); |
| 2998 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); |
| 2999 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); |
| 3000 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) |
| 3001 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
| 3002 | else |
| 3003 | log_info = 0; |
| 3004 | ioc_status &= MPI2_IOCSTATUS_MASK; |
| 3005 | scsi_state = mpi_reply->SCSIState; |
| 3006 | scsi_status = mpi_reply->SCSIStatus; |
| 3007 | |
| 3008 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && |
| 3009 | (scsi_status == MPI2_SCSI_STATUS_BUSY || |
| 3010 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || |
| 3011 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { |
| 3012 | ioc_status = MPI2_IOCSTATUS_SUCCESS; |
| 3013 | } |
| 3014 | |
| 3015 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 3016 | struct sense_info data; |
| 3017 | const void *sense_data = mpt2sas_base_get_sense_buffer(ioc, |
| 3018 | smid); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 3019 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3020 | le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 3021 | memcpy(scmd->sense_buffer, sense_data, sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3022 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 3023 | /* failure prediction threshold exceeded */ |
| 3024 | if (data.asc == 0x5D) |
| 3025 | _scsih_smart_predicted_fault(ioc, |
| 3026 | le16_to_cpu(mpi_reply->DevHandle)); |
| 3027 | } |
| 3028 | |
| 3029 | switch (ioc_status) { |
| 3030 | case MPI2_IOCSTATUS_BUSY: |
| 3031 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: |
| 3032 | scmd->result = SAM_STAT_BUSY; |
| 3033 | break; |
| 3034 | |
| 3035 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 3036 | scmd->result = DID_NO_CONNECT << 16; |
| 3037 | break; |
| 3038 | |
| 3039 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 3040 | if (sas_device_priv_data->block) { |
| 3041 | scmd->result = (DID_BUS_BUSY << 16); |
| 3042 | break; |
| 3043 | } |
| 3044 | |
| 3045 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 3046 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 3047 | scmd->result = DID_RESET << 16; |
| 3048 | break; |
| 3049 | |
| 3050 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 3051 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) |
| 3052 | scmd->result = DID_SOFT_ERROR << 16; |
| 3053 | else |
| 3054 | scmd->result = (DID_OK << 16) | scsi_status; |
| 3055 | break; |
| 3056 | |
| 3057 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 3058 | scmd->result = (DID_OK << 16) | scsi_status; |
| 3059 | |
| 3060 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) |
| 3061 | break; |
| 3062 | |
| 3063 | if (xfer_cnt < scmd->underflow) { |
| 3064 | if (scsi_status == SAM_STAT_BUSY) |
| 3065 | scmd->result = SAM_STAT_BUSY; |
| 3066 | else |
| 3067 | scmd->result = DID_SOFT_ERROR << 16; |
| 3068 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 3069 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) |
| 3070 | scmd->result = DID_SOFT_ERROR << 16; |
| 3071 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 3072 | scmd->result = DID_RESET << 16; |
| 3073 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { |
| 3074 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; |
| 3075 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; |
| 3076 | scmd->result = (DRIVER_SENSE << 24) | |
| 3077 | SAM_STAT_CHECK_CONDITION; |
| 3078 | scmd->sense_buffer[0] = 0x70; |
| 3079 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; |
| 3080 | scmd->sense_buffer[12] = 0x20; |
| 3081 | scmd->sense_buffer[13] = 0; |
| 3082 | } |
| 3083 | break; |
| 3084 | |
| 3085 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 3086 | scsi_set_resid(scmd, 0); |
| 3087 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 3088 | case MPI2_IOCSTATUS_SUCCESS: |
| 3089 | scmd->result = (DID_OK << 16) | scsi_status; |
| 3090 | if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 3091 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) |
| 3092 | scmd->result = DID_SOFT_ERROR << 16; |
| 3093 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 3094 | scmd->result = DID_RESET << 16; |
| 3095 | break; |
| 3096 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3097 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 3098 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 3099 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 3100 | _scsih_eedp_error_handling(scmd, ioc_status); |
| 3101 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3102 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 3103 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 3104 | case MPI2_IOCSTATUS_INVALID_SGL: |
| 3105 | case MPI2_IOCSTATUS_INTERNAL_ERROR: |
| 3106 | case MPI2_IOCSTATUS_INVALID_FIELD: |
| 3107 | case MPI2_IOCSTATUS_INVALID_STATE: |
| 3108 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 3109 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 3110 | default: |
| 3111 | scmd->result = DID_SOFT_ERROR << 16; |
| 3112 | break; |
| 3113 | |
| 3114 | } |
| 3115 | |
| 3116 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 3117 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
| 3118 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); |
| 3119 | #endif |
| 3120 | |
| 3121 | out: |
| 3122 | scsi_dma_unmap(scmd); |
| 3123 | scmd->scsi_done(scmd); |
| 3124 | } |
| 3125 | |
| 3126 | /** |
| 3127 | * _scsih_link_change - process phy link changes |
| 3128 | * @ioc: per adapter object |
| 3129 | * @handle: phy handle |
| 3130 | * @attached_handle: valid for devices attached to link |
| 3131 | * @phy_number: phy number |
| 3132 | * @link_rate: new link rate |
| 3133 | * Context: user. |
| 3134 | * |
| 3135 | * Return nothing. |
| 3136 | */ |
| 3137 | static void |
| 3138 | _scsih_link_change(struct MPT2SAS_ADAPTER *ioc, u16 handle, u16 attached_handle, |
| 3139 | u8 phy_number, u8 link_rate) |
| 3140 | { |
| 3141 | mpt2sas_transport_update_phy_link_change(ioc, handle, attached_handle, |
| 3142 | phy_number, link_rate); |
| 3143 | } |
| 3144 | |
| 3145 | /** |
| 3146 | * _scsih_sas_host_refresh - refreshing sas host object contents |
| 3147 | * @ioc: per adapter object |
| 3148 | * @update: update link information |
| 3149 | * Context: user |
| 3150 | * |
| 3151 | * During port enable, fw will send topology events for every device. Its |
| 3152 | * possible that the handles may change from the previous setting, so this |
| 3153 | * code keeping handles updating if changed. |
| 3154 | * |
| 3155 | * Return nothing. |
| 3156 | */ |
| 3157 | static void |
| 3158 | _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc, u8 update) |
| 3159 | { |
| 3160 | u16 sz; |
| 3161 | u16 ioc_status; |
| 3162 | int i; |
| 3163 | Mpi2ConfigReply_t mpi_reply; |
| 3164 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
| 3165 | |
| 3166 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3167 | "updating handles for sas_host(0x%016llx)\n", |
| 3168 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); |
| 3169 | |
| 3170 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys |
| 3171 | * sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 3172 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 3173 | if (!sas_iounit_pg0) { |
| 3174 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3175 | ioc->name, __FILE__, __LINE__, __func__); |
| 3176 | return; |
| 3177 | } |
| 3178 | if (!(mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 3179 | sas_iounit_pg0, sz))) { |
| 3180 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 3181 | MPI2_IOCSTATUS_MASK; |
| 3182 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 3183 | goto out; |
| 3184 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
| 3185 | ioc->sas_hba.phy[i].handle = |
| 3186 | le16_to_cpu(sas_iounit_pg0->PhyData[i]. |
| 3187 | ControllerDevHandle); |
| 3188 | if (update) |
| 3189 | _scsih_link_change(ioc, |
| 3190 | ioc->sas_hba.phy[i].handle, |
| 3191 | le16_to_cpu(sas_iounit_pg0->PhyData[i]. |
| 3192 | AttachedDevHandle), i, |
| 3193 | sas_iounit_pg0->PhyData[i]. |
| 3194 | NegotiatedLinkRate >> 4); |
| 3195 | } |
| 3196 | } |
| 3197 | |
| 3198 | out: |
| 3199 | kfree(sas_iounit_pg0); |
| 3200 | } |
| 3201 | |
| 3202 | /** |
| 3203 | * _scsih_sas_host_add - create sas host object |
| 3204 | * @ioc: per adapter object |
| 3205 | * |
| 3206 | * Creating host side data object, stored in ioc->sas_hba |
| 3207 | * |
| 3208 | * Return nothing. |
| 3209 | */ |
| 3210 | static void |
| 3211 | _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc) |
| 3212 | { |
| 3213 | int i; |
| 3214 | Mpi2ConfigReply_t mpi_reply; |
| 3215 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
| 3216 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; |
| 3217 | Mpi2SasPhyPage0_t phy_pg0; |
| 3218 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 3219 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 3220 | u16 ioc_status; |
| 3221 | u16 sz; |
| 3222 | u16 device_missing_delay; |
| 3223 | |
| 3224 | mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys); |
| 3225 | if (!ioc->sas_hba.num_phys) { |
| 3226 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3227 | ioc->name, __FILE__, __LINE__, __func__); |
| 3228 | return; |
| 3229 | } |
| 3230 | |
| 3231 | /* sas_iounit page 0 */ |
| 3232 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * |
| 3233 | sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 3234 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 3235 | if (!sas_iounit_pg0) { |
| 3236 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3237 | ioc->name, __FILE__, __LINE__, __func__); |
| 3238 | return; |
| 3239 | } |
| 3240 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 3241 | sas_iounit_pg0, sz))) { |
| 3242 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3243 | ioc->name, __FILE__, __LINE__, __func__); |
| 3244 | goto out; |
| 3245 | } |
| 3246 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 3247 | MPI2_IOCSTATUS_MASK; |
| 3248 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 3249 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3250 | ioc->name, __FILE__, __LINE__, __func__); |
| 3251 | goto out; |
| 3252 | } |
| 3253 | |
| 3254 | /* sas_iounit page 1 */ |
| 3255 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * |
| 3256 | sizeof(Mpi2SasIOUnit1PhyData_t)); |
| 3257 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); |
| 3258 | if (!sas_iounit_pg1) { |
| 3259 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3260 | ioc->name, __FILE__, __LINE__, __func__); |
| 3261 | goto out; |
| 3262 | } |
| 3263 | if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, |
| 3264 | sas_iounit_pg1, sz))) { |
| 3265 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3266 | ioc->name, __FILE__, __LINE__, __func__); |
| 3267 | goto out; |
| 3268 | } |
| 3269 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 3270 | MPI2_IOCSTATUS_MASK; |
| 3271 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 3272 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3273 | ioc->name, __FILE__, __LINE__, __func__); |
| 3274 | goto out; |
| 3275 | } |
| 3276 | |
| 3277 | ioc->io_missing_delay = |
| 3278 | le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay); |
| 3279 | device_missing_delay = |
| 3280 | le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay); |
| 3281 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) |
| 3282 | ioc->device_missing_delay = (device_missing_delay & |
| 3283 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; |
| 3284 | else |
| 3285 | ioc->device_missing_delay = device_missing_delay & |
| 3286 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 3287 | |
| 3288 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; |
| 3289 | ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys, |
| 3290 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 3291 | if (!ioc->sas_hba.phy) { |
| 3292 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3293 | ioc->name, __FILE__, __LINE__, __func__); |
| 3294 | goto out; |
| 3295 | } |
| 3296 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
| 3297 | if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, |
| 3298 | i))) { |
| 3299 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3300 | ioc->name, __FILE__, __LINE__, __func__); |
| 3301 | goto out; |
| 3302 | } |
| 3303 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 3304 | MPI2_IOCSTATUS_MASK; |
| 3305 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 3306 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3307 | ioc->name, __FILE__, __LINE__, __func__); |
| 3308 | goto out; |
| 3309 | } |
| 3310 | ioc->sas_hba.phy[i].handle = |
| 3311 | le16_to_cpu(sas_iounit_pg0->PhyData[i].ControllerDevHandle); |
| 3312 | ioc->sas_hba.phy[i].phy_id = i; |
| 3313 | mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], |
| 3314 | phy_pg0, ioc->sas_hba.parent_dev); |
| 3315 | } |
| 3316 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 3317 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.phy[0].handle))) { |
| 3318 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3319 | ioc->name, __FILE__, __LINE__, __func__); |
| 3320 | goto out; |
| 3321 | } |
| 3322 | ioc->sas_hba.handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 3323 | ioc->sas_hba.enclosure_handle = |
| 3324 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 3325 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 3326 | printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), " |
| 3327 | "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle, |
| 3328 | (unsigned long long) ioc->sas_hba.sas_address, |
| 3329 | ioc->sas_hba.num_phys) ; |
| 3330 | |
| 3331 | if (ioc->sas_hba.enclosure_handle) { |
| 3332 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 3333 | &enclosure_pg0, |
| 3334 | MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 3335 | ioc->sas_hba.enclosure_handle))) { |
| 3336 | ioc->sas_hba.enclosure_logical_id = |
| 3337 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 3338 | } |
| 3339 | } |
| 3340 | |
| 3341 | out: |
| 3342 | kfree(sas_iounit_pg1); |
| 3343 | kfree(sas_iounit_pg0); |
| 3344 | } |
| 3345 | |
| 3346 | /** |
| 3347 | * _scsih_expander_add - creating expander object |
| 3348 | * @ioc: per adapter object |
| 3349 | * @handle: expander handle |
| 3350 | * |
| 3351 | * Creating expander object, stored in ioc->sas_expander_list. |
| 3352 | * |
| 3353 | * Return 0 for success, else error. |
| 3354 | */ |
| 3355 | static int |
| 3356 | _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3357 | { |
| 3358 | struct _sas_node *sas_expander; |
| 3359 | Mpi2ConfigReply_t mpi_reply; |
| 3360 | Mpi2ExpanderPage0_t expander_pg0; |
| 3361 | Mpi2ExpanderPage1_t expander_pg1; |
| 3362 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 3363 | u32 ioc_status; |
| 3364 | u16 parent_handle; |
| 3365 | __le64 sas_address; |
| 3366 | int i; |
| 3367 | unsigned long flags; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 3368 | struct _sas_port *mpt2sas_port = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3369 | int rc = 0; |
| 3370 | |
| 3371 | if (!handle) |
| 3372 | return -1; |
| 3373 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame^] | 3374 | if (ioc->shost_recovery) |
| 3375 | return -1; |
| 3376 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3377 | if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 3378 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { |
| 3379 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3380 | ioc->name, __FILE__, __LINE__, __func__); |
| 3381 | return -1; |
| 3382 | } |
| 3383 | |
| 3384 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 3385 | MPI2_IOCSTATUS_MASK; |
| 3386 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 3387 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3388 | ioc->name, __FILE__, __LINE__, __func__); |
| 3389 | return -1; |
| 3390 | } |
| 3391 | |
| 3392 | /* handle out of order topology events */ |
| 3393 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); |
| 3394 | if (parent_handle >= ioc->sas_hba.num_phys) { |
| 3395 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 3396 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 3397 | parent_handle); |
| 3398 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 3399 | if (!sas_expander) { |
| 3400 | rc = _scsih_expander_add(ioc, parent_handle); |
| 3401 | if (rc != 0) |
| 3402 | return rc; |
| 3403 | } |
| 3404 | } |
| 3405 | |
| 3406 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
| 3407 | |
| 3408 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 3409 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 3410 | sas_address); |
| 3411 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 3412 | |
| 3413 | if (sas_expander) |
| 3414 | return 0; |
| 3415 | |
| 3416 | sas_expander = kzalloc(sizeof(struct _sas_node), |
| 3417 | GFP_KERNEL); |
| 3418 | if (!sas_expander) { |
| 3419 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3420 | ioc->name, __FILE__, __LINE__, __func__); |
| 3421 | return -1; |
| 3422 | } |
| 3423 | |
| 3424 | sas_expander->handle = handle; |
| 3425 | sas_expander->num_phys = expander_pg0.NumPhys; |
| 3426 | sas_expander->parent_handle = parent_handle; |
| 3427 | sas_expander->enclosure_handle = |
| 3428 | le16_to_cpu(expander_pg0.EnclosureHandle); |
| 3429 | sas_expander->sas_address = sas_address; |
| 3430 | |
| 3431 | printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x)," |
| 3432 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, |
| 3433 | handle, sas_expander->parent_handle, (unsigned long long) |
| 3434 | sas_expander->sas_address, sas_expander->num_phys); |
| 3435 | |
| 3436 | if (!sas_expander->num_phys) |
| 3437 | goto out_fail; |
| 3438 | sas_expander->phy = kcalloc(sas_expander->num_phys, |
| 3439 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 3440 | if (!sas_expander->phy) { |
| 3441 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3442 | ioc->name, __FILE__, __LINE__, __func__); |
| 3443 | rc = -1; |
| 3444 | goto out_fail; |
| 3445 | } |
| 3446 | |
| 3447 | INIT_LIST_HEAD(&sas_expander->sas_port_list); |
| 3448 | mpt2sas_port = mpt2sas_transport_port_add(ioc, handle, |
| 3449 | sas_expander->parent_handle); |
| 3450 | if (!mpt2sas_port) { |
| 3451 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3452 | ioc->name, __FILE__, __LINE__, __func__); |
| 3453 | rc = -1; |
| 3454 | goto out_fail; |
| 3455 | } |
| 3456 | sas_expander->parent_dev = &mpt2sas_port->rphy->dev; |
| 3457 | |
| 3458 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 3459 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 3460 | &expander_pg1, i, handle))) { |
| 3461 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3462 | ioc->name, __FILE__, __LINE__, __func__); |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 3463 | rc = -1; |
| 3464 | goto out_fail; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3465 | } |
| 3466 | sas_expander->phy[i].handle = handle; |
| 3467 | sas_expander->phy[i].phy_id = i; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 3468 | |
| 3469 | if ((mpt2sas_transport_add_expander_phy(ioc, |
| 3470 | &sas_expander->phy[i], expander_pg1, |
| 3471 | sas_expander->parent_dev))) { |
| 3472 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3473 | ioc->name, __FILE__, __LINE__, __func__); |
| 3474 | rc = -1; |
| 3475 | goto out_fail; |
| 3476 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | if (sas_expander->enclosure_handle) { |
| 3480 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 3481 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 3482 | sas_expander->enclosure_handle))) { |
| 3483 | sas_expander->enclosure_logical_id = |
| 3484 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 3485 | } |
| 3486 | } |
| 3487 | |
| 3488 | _scsih_expander_node_add(ioc, sas_expander); |
| 3489 | return 0; |
| 3490 | |
| 3491 | out_fail: |
| 3492 | |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 3493 | if (mpt2sas_port) |
| 3494 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
| 3495 | sas_expander->parent_handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3496 | kfree(sas_expander); |
| 3497 | return rc; |
| 3498 | } |
| 3499 | |
| 3500 | /** |
| 3501 | * _scsih_expander_remove - removing expander object |
| 3502 | * @ioc: per adapter object |
| 3503 | * @handle: expander handle |
| 3504 | * |
| 3505 | * Return nothing. |
| 3506 | */ |
| 3507 | static void |
| 3508 | _scsih_expander_remove(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3509 | { |
| 3510 | struct _sas_node *sas_expander; |
| 3511 | unsigned long flags; |
| 3512 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame^] | 3513 | if (ioc->shost_recovery) |
| 3514 | return; |
| 3515 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3516 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 3517 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, handle); |
| 3518 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 3519 | _scsih_expander_node_remove(ioc, sas_expander); |
| 3520 | } |
| 3521 | |
| 3522 | /** |
| 3523 | * _scsih_add_device - creating sas device object |
| 3524 | * @ioc: per adapter object |
| 3525 | * @handle: sas device handle |
| 3526 | * @phy_num: phy number end device attached to |
| 3527 | * @is_pd: is this hidden raid component |
| 3528 | * |
| 3529 | * Creating end device object, stored in ioc->sas_device_list. |
| 3530 | * |
| 3531 | * Returns 0 for success, non-zero for failure. |
| 3532 | */ |
| 3533 | static int |
| 3534 | _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd) |
| 3535 | { |
| 3536 | Mpi2ConfigReply_t mpi_reply; |
| 3537 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 3538 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 3539 | struct _sas_device *sas_device; |
| 3540 | u32 ioc_status; |
| 3541 | __le64 sas_address; |
| 3542 | u32 device_info; |
| 3543 | unsigned long flags; |
| 3544 | |
| 3545 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 3546 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 3547 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3548 | ioc->name, __FILE__, __LINE__, __func__); |
| 3549 | return -1; |
| 3550 | } |
| 3551 | |
| 3552 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 3553 | MPI2_IOCSTATUS_MASK; |
| 3554 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 3555 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3556 | ioc->name, __FILE__, __LINE__, __func__); |
| 3557 | return -1; |
| 3558 | } |
| 3559 | |
| 3560 | /* check if device is present */ |
| 3561 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 3562 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 3563 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3564 | ioc->name, __FILE__, __LINE__, __func__); |
| 3565 | printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n", |
| 3566 | ioc->name, le16_to_cpu(sas_device_pg0.Flags)); |
| 3567 | return -1; |
| 3568 | } |
| 3569 | |
| 3570 | /* check if there were any issus with discovery */ |
| 3571 | if (sas_device_pg0.AccessStatus == |
| 3572 | MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED) { |
| 3573 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3574 | ioc->name, __FILE__, __LINE__, __func__); |
| 3575 | printk(MPT2SAS_ERR_FMT "AccessStatus = 0x%02x\n", |
| 3576 | ioc->name, sas_device_pg0.AccessStatus); |
| 3577 | return -1; |
| 3578 | } |
| 3579 | |
| 3580 | /* check if this is end device */ |
| 3581 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 3582 | if (!(_scsih_is_end_device(device_info))) { |
| 3583 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3584 | ioc->name, __FILE__, __LINE__, __func__); |
| 3585 | return -1; |
| 3586 | } |
| 3587 | |
| 3588 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 3589 | |
| 3590 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3591 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 3592 | sas_address); |
| 3593 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 3594 | |
| 3595 | if (sas_device) { |
| 3596 | _scsih_ublock_io_device(ioc, handle); |
| 3597 | return 0; |
| 3598 | } |
| 3599 | |
| 3600 | sas_device = kzalloc(sizeof(struct _sas_device), |
| 3601 | GFP_KERNEL); |
| 3602 | if (!sas_device) { |
| 3603 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3604 | ioc->name, __FILE__, __LINE__, __func__); |
| 3605 | return -1; |
| 3606 | } |
| 3607 | |
| 3608 | sas_device->handle = handle; |
| 3609 | sas_device->parent_handle = |
| 3610 | le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 3611 | sas_device->enclosure_handle = |
| 3612 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 3613 | sas_device->slot = |
| 3614 | le16_to_cpu(sas_device_pg0.Slot); |
| 3615 | sas_device->device_info = device_info; |
| 3616 | sas_device->sas_address = sas_address; |
| 3617 | sas_device->hidden_raid_component = is_pd; |
| 3618 | |
| 3619 | /* get enclosure_logical_id */ |
Kashyap, Desai | 15052c9 | 2009-08-07 19:33:17 +0530 | [diff] [blame] | 3620 | if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0( |
| 3621 | ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 3622 | sas_device->enclosure_handle))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3623 | sas_device->enclosure_logical_id = |
| 3624 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3625 | |
| 3626 | /* get device name */ |
| 3627 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); |
| 3628 | |
| 3629 | if (ioc->wait_for_port_enable_to_complete) |
| 3630 | _scsih_sas_device_init_add(ioc, sas_device); |
| 3631 | else |
| 3632 | _scsih_sas_device_add(ioc, sas_device); |
| 3633 | |
| 3634 | return 0; |
| 3635 | } |
| 3636 | |
| 3637 | /** |
| 3638 | * _scsih_remove_device - removing sas device object |
| 3639 | * @ioc: per adapter object |
| 3640 | * @handle: sas device handle |
| 3641 | * |
| 3642 | * Return nothing. |
| 3643 | */ |
| 3644 | static void |
| 3645 | _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3646 | { |
| 3647 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 3648 | struct _sas_device *sas_device; |
| 3649 | unsigned long flags; |
| 3650 | Mpi2SasIoUnitControlReply_t mpi_reply; |
| 3651 | Mpi2SasIoUnitControlRequest_t mpi_request; |
| 3652 | u16 device_handle; |
| 3653 | |
| 3654 | /* lookup sas_device */ |
| 3655 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3656 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 3657 | if (!sas_device) { |
| 3658 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 3659 | return; |
| 3660 | } |
| 3661 | |
| 3662 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: handle" |
| 3663 | "(0x%04x)\n", ioc->name, __func__, handle)); |
| 3664 | |
| 3665 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 3666 | sas_target_priv_data = sas_device->starget->hostdata; |
| 3667 | sas_target_priv_data->deleted = 1; |
| 3668 | } |
| 3669 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 3670 | |
| 3671 | if (ioc->remove_host) |
| 3672 | goto out; |
| 3673 | |
| 3674 | /* Target Reset to flush out all the outstanding IO */ |
| 3675 | device_handle = (sas_device->hidden_raid_component) ? |
| 3676 | sas_device->volume_handle : handle; |
| 3677 | if (device_handle) { |
| 3678 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "issue target reset: " |
| 3679 | "handle(0x%04x)\n", ioc->name, device_handle)); |
| 3680 | mutex_lock(&ioc->tm_cmds.mutex); |
| 3681 | mpt2sas_scsih_issue_tm(ioc, device_handle, 0, |
| 3682 | MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 10); |
| 3683 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
| 3684 | mutex_unlock(&ioc->tm_cmds.mutex); |
| 3685 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "issue target reset " |
| 3686 | "done: handle(0x%04x)\n", ioc->name, device_handle)); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame^] | 3687 | if (ioc->shost_recovery) |
| 3688 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3689 | } |
| 3690 | |
| 3691 | /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */ |
| 3692 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sas_iounit: handle" |
| 3693 | "(0x%04x)\n", ioc->name, handle)); |
| 3694 | memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); |
| 3695 | mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; |
| 3696 | mpi_request.Operation = MPI2_SAS_OP_REMOVE_DEVICE; |
| 3697 | mpi_request.DevHandle = handle; |
| 3698 | mpi_request.VF_ID = 0; |
| 3699 | if ((mpt2sas_base_sas_iounit_control(ioc, &mpi_reply, |
| 3700 | &mpi_request)) != 0) { |
| 3701 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 3702 | ioc->name, __FILE__, __LINE__, __func__); |
| 3703 | } |
| 3704 | |
| 3705 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sas_iounit: ioc_status" |
| 3706 | "(0x%04x), loginfo(0x%08x)\n", ioc->name, |
| 3707 | le16_to_cpu(mpi_reply.IOCStatus), |
| 3708 | le32_to_cpu(mpi_reply.IOCLogInfo))); |
| 3709 | |
| 3710 | out: |
| 3711 | mpt2sas_transport_port_remove(ioc, sas_device->sas_address, |
| 3712 | sas_device->parent_handle); |
| 3713 | |
| 3714 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr" |
| 3715 | "(0x%016llx)\n", ioc->name, sas_device->handle, |
| 3716 | (unsigned long long) sas_device->sas_address); |
| 3717 | _scsih_sas_device_remove(ioc, sas_device); |
| 3718 | |
| 3719 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: handle" |
| 3720 | "(0x%04x)\n", ioc->name, __func__, handle)); |
| 3721 | } |
| 3722 | |
| 3723 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 3724 | /** |
| 3725 | * _scsih_sas_topology_change_event_debug - debug for topology event |
| 3726 | * @ioc: per adapter object |
| 3727 | * @event_data: event data payload |
| 3728 | * Context: user. |
| 3729 | */ |
| 3730 | static void |
| 3731 | _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 3732 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3733 | { |
| 3734 | int i; |
| 3735 | u16 handle; |
| 3736 | u16 reason_code; |
| 3737 | u8 phy_number; |
| 3738 | char *status_str = NULL; |
| 3739 | char link_rate[25]; |
| 3740 | |
| 3741 | switch (event_data->ExpStatus) { |
| 3742 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: |
| 3743 | status_str = "add"; |
| 3744 | break; |
| 3745 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: |
| 3746 | status_str = "remove"; |
| 3747 | break; |
| 3748 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: |
| 3749 | status_str = "responding"; |
| 3750 | break; |
| 3751 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: |
| 3752 | status_str = "remove delay"; |
| 3753 | break; |
| 3754 | default: |
| 3755 | status_str = "unknown status"; |
| 3756 | break; |
| 3757 | } |
| 3758 | printk(MPT2SAS_DEBUG_FMT "sas topology change: (%s)\n", |
| 3759 | ioc->name, status_str); |
| 3760 | printk(KERN_DEBUG "\thandle(0x%04x), enclosure_handle(0x%04x) " |
| 3761 | "start_phy(%02d), count(%d)\n", |
| 3762 | le16_to_cpu(event_data->ExpanderDevHandle), |
| 3763 | le16_to_cpu(event_data->EnclosureHandle), |
| 3764 | event_data->StartPhyNum, event_data->NumEntries); |
| 3765 | for (i = 0; i < event_data->NumEntries; i++) { |
| 3766 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3767 | if (!handle) |
| 3768 | continue; |
| 3769 | phy_number = event_data->StartPhyNum + i; |
| 3770 | reason_code = event_data->PHY[i].PhyStatus & |
| 3771 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3772 | switch (reason_code) { |
| 3773 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
| 3774 | snprintf(link_rate, 25, ": add, link(0x%02x)", |
| 3775 | (event_data->PHY[i].LinkRate >> 4)); |
| 3776 | status_str = link_rate; |
| 3777 | break; |
| 3778 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
| 3779 | status_str = ": remove"; |
| 3780 | break; |
| 3781 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: |
| 3782 | status_str = ": remove_delay"; |
| 3783 | break; |
| 3784 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
| 3785 | snprintf(link_rate, 25, ": link(0x%02x)", |
| 3786 | (event_data->PHY[i].LinkRate >> 4)); |
| 3787 | status_str = link_rate; |
| 3788 | break; |
| 3789 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: |
| 3790 | status_str = ": responding"; |
| 3791 | break; |
| 3792 | default: |
| 3793 | status_str = ": unknown"; |
| 3794 | break; |
| 3795 | } |
| 3796 | printk(KERN_DEBUG "\tphy(%02d), attached_handle(0x%04x)%s\n", |
| 3797 | phy_number, handle, status_str); |
| 3798 | } |
| 3799 | } |
| 3800 | #endif |
| 3801 | |
| 3802 | /** |
| 3803 | * _scsih_sas_topology_change_event - handle topology changes |
| 3804 | * @ioc: per adapter object |
| 3805 | * @VF_ID: |
| 3806 | * @event_data: event data payload |
| 3807 | * fw_event: |
| 3808 | * Context: user. |
| 3809 | * |
| 3810 | */ |
| 3811 | static void |
| 3812 | _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, |
| 3813 | Mpi2EventDataSasTopologyChangeList_t *event_data, |
| 3814 | struct fw_event_work *fw_event) |
| 3815 | { |
| 3816 | int i; |
| 3817 | u16 parent_handle, handle; |
| 3818 | u16 reason_code; |
| 3819 | u8 phy_number; |
| 3820 | struct _sas_node *sas_expander; |
| 3821 | unsigned long flags; |
| 3822 | u8 link_rate_; |
| 3823 | |
| 3824 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 3825 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 3826 | _scsih_sas_topology_change_event_debug(ioc, event_data); |
| 3827 | #endif |
| 3828 | |
| 3829 | if (!ioc->sas_hba.num_phys) |
| 3830 | _scsih_sas_host_add(ioc); |
| 3831 | else |
| 3832 | _scsih_sas_host_refresh(ioc, 0); |
| 3833 | |
| 3834 | if (fw_event->ignore) { |
| 3835 | dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ignoring expander " |
| 3836 | "event\n", ioc->name)); |
| 3837 | return; |
| 3838 | } |
| 3839 | |
| 3840 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 3841 | |
| 3842 | /* handle expander add */ |
| 3843 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) |
| 3844 | if (_scsih_expander_add(ioc, parent_handle) != 0) |
| 3845 | return; |
| 3846 | |
| 3847 | /* handle siblings events */ |
| 3848 | for (i = 0; i < event_data->NumEntries; i++) { |
| 3849 | if (fw_event->ignore) { |
| 3850 | dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ignoring " |
| 3851 | "expander event\n", ioc->name)); |
| 3852 | return; |
| 3853 | } |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame^] | 3854 | if (ioc->shost_recovery) |
| 3855 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3856 | if (event_data->PHY[i].PhyStatus & |
| 3857 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) |
| 3858 | continue; |
| 3859 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3860 | if (!handle) |
| 3861 | continue; |
| 3862 | phy_number = event_data->StartPhyNum + i; |
| 3863 | reason_code = event_data->PHY[i].PhyStatus & |
| 3864 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3865 | link_rate_ = event_data->PHY[i].LinkRate >> 4; |
| 3866 | switch (reason_code) { |
| 3867 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
| 3868 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
| 3869 | if (!parent_handle) { |
| 3870 | if (phy_number < ioc->sas_hba.num_phys) |
| 3871 | _scsih_link_change(ioc, |
| 3872 | ioc->sas_hba.phy[phy_number].handle, |
| 3873 | handle, phy_number, link_rate_); |
| 3874 | } else { |
| 3875 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 3876 | sas_expander = |
| 3877 | mpt2sas_scsih_expander_find_by_handle(ioc, |
| 3878 | parent_handle); |
| 3879 | spin_unlock_irqrestore(&ioc->sas_node_lock, |
| 3880 | flags); |
| 3881 | if (sas_expander) { |
| 3882 | if (phy_number < sas_expander->num_phys) |
| 3883 | _scsih_link_change(ioc, |
| 3884 | sas_expander-> |
| 3885 | phy[phy_number].handle, |
| 3886 | handle, phy_number, |
| 3887 | link_rate_); |
| 3888 | } |
| 3889 | } |
| 3890 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED) { |
| 3891 | if (link_rate_ >= MPI2_SAS_NEG_LINK_RATE_1_5) |
| 3892 | _scsih_ublock_io_device(ioc, handle); |
| 3893 | } |
| 3894 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED) { |
| 3895 | if (link_rate_ < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 3896 | break; |
| 3897 | _scsih_add_device(ioc, handle, phy_number, 0); |
| 3898 | } |
| 3899 | break; |
| 3900 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
| 3901 | _scsih_remove_device(ioc, handle); |
| 3902 | break; |
| 3903 | } |
| 3904 | } |
| 3905 | |
| 3906 | /* handle expander removal */ |
| 3907 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) |
| 3908 | _scsih_expander_remove(ioc, parent_handle); |
| 3909 | |
| 3910 | } |
| 3911 | |
| 3912 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 3913 | /** |
| 3914 | * _scsih_sas_device_status_change_event_debug - debug for device event |
| 3915 | * @event_data: event data payload |
| 3916 | * Context: user. |
| 3917 | * |
| 3918 | * Return nothing. |
| 3919 | */ |
| 3920 | static void |
| 3921 | _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 3922 | Mpi2EventDataSasDeviceStatusChange_t *event_data) |
| 3923 | { |
| 3924 | char *reason_str = NULL; |
| 3925 | |
| 3926 | switch (event_data->ReasonCode) { |
| 3927 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: |
| 3928 | reason_str = "smart data"; |
| 3929 | break; |
| 3930 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: |
| 3931 | reason_str = "unsupported device discovered"; |
| 3932 | break; |
| 3933 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: |
| 3934 | reason_str = "internal device reset"; |
| 3935 | break; |
| 3936 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: |
| 3937 | reason_str = "internal task abort"; |
| 3938 | break; |
| 3939 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: |
| 3940 | reason_str = "internal task abort set"; |
| 3941 | break; |
| 3942 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: |
| 3943 | reason_str = "internal clear task set"; |
| 3944 | break; |
| 3945 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: |
| 3946 | reason_str = "internal query task"; |
| 3947 | break; |
| 3948 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: |
| 3949 | reason_str = "sata init failure"; |
| 3950 | break; |
| 3951 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: |
| 3952 | reason_str = "internal device reset complete"; |
| 3953 | break; |
| 3954 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: |
| 3955 | reason_str = "internal task abort complete"; |
| 3956 | break; |
| 3957 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: |
| 3958 | reason_str = "internal async notification"; |
| 3959 | break; |
| 3960 | default: |
| 3961 | reason_str = "unknown reason"; |
| 3962 | break; |
| 3963 | } |
| 3964 | printk(MPT2SAS_DEBUG_FMT "device status change: (%s)\n" |
| 3965 | "\thandle(0x%04x), sas address(0x%016llx)", ioc->name, |
| 3966 | reason_str, le16_to_cpu(event_data->DevHandle), |
| 3967 | (unsigned long long)le64_to_cpu(event_data->SASAddress)); |
| 3968 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) |
| 3969 | printk(MPT2SAS_DEBUG_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name, |
| 3970 | event_data->ASC, event_data->ASCQ); |
| 3971 | printk(KERN_INFO "\n"); |
| 3972 | } |
| 3973 | #endif |
| 3974 | |
| 3975 | /** |
| 3976 | * _scsih_sas_device_status_change_event - handle device status change |
| 3977 | * @ioc: per adapter object |
| 3978 | * @VF_ID: |
| 3979 | * @event_data: event data payload |
| 3980 | * Context: user. |
| 3981 | * |
| 3982 | * Return nothing. |
| 3983 | */ |
| 3984 | static void |
| 3985 | _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, |
| 3986 | Mpi2EventDataSasDeviceStatusChange_t *event_data) |
| 3987 | { |
| 3988 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 3989 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 3990 | _scsih_sas_device_status_change_event_debug(ioc, event_data); |
| 3991 | #endif |
| 3992 | } |
| 3993 | |
| 3994 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 3995 | /** |
| 3996 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event |
| 3997 | * @ioc: per adapter object |
| 3998 | * @event_data: event data payload |
| 3999 | * Context: user. |
| 4000 | * |
| 4001 | * Return nothing. |
| 4002 | */ |
| 4003 | static void |
| 4004 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 4005 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) |
| 4006 | { |
| 4007 | char *reason_str = NULL; |
| 4008 | |
| 4009 | switch (event_data->ReasonCode) { |
| 4010 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: |
| 4011 | reason_str = "enclosure add"; |
| 4012 | break; |
| 4013 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: |
| 4014 | reason_str = "enclosure remove"; |
| 4015 | break; |
| 4016 | default: |
| 4017 | reason_str = "unknown reason"; |
| 4018 | break; |
| 4019 | } |
| 4020 | |
| 4021 | printk(MPT2SAS_DEBUG_FMT "enclosure status change: (%s)\n" |
| 4022 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" |
| 4023 | " number slots(%d)\n", ioc->name, reason_str, |
| 4024 | le16_to_cpu(event_data->EnclosureHandle), |
| 4025 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), |
| 4026 | le16_to_cpu(event_data->StartSlot)); |
| 4027 | } |
| 4028 | #endif |
| 4029 | |
| 4030 | /** |
| 4031 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events |
| 4032 | * @ioc: per adapter object |
| 4033 | * @VF_ID: |
| 4034 | * @event_data: event data payload |
| 4035 | * Context: user. |
| 4036 | * |
| 4037 | * Return nothing. |
| 4038 | */ |
| 4039 | static void |
| 4040 | _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 4041 | u8 VF_ID, Mpi2EventDataSasEnclDevStatusChange_t *event_data) |
| 4042 | { |
| 4043 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4044 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 4045 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, |
| 4046 | event_data); |
| 4047 | #endif |
| 4048 | } |
| 4049 | |
| 4050 | /** |
| 4051 | * _scsih_sas_broadcast_primative_event - handle broadcast events |
| 4052 | * @ioc: per adapter object |
| 4053 | * @event_data: event data payload |
| 4054 | * Context: user. |
| 4055 | * |
| 4056 | * Return nothing. |
| 4057 | */ |
| 4058 | static void |
| 4059 | _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, |
| 4060 | Mpi2EventDataSasBroadcastPrimitive_t *event_data) |
| 4061 | { |
| 4062 | struct scsi_cmnd *scmd; |
| 4063 | u16 smid, handle; |
| 4064 | u32 lun; |
| 4065 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 4066 | u32 termination_count; |
| 4067 | u32 query_count; |
| 4068 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
| 4069 | |
| 4070 | dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "broadcast primative: " |
| 4071 | "phy number(%d), width(%d)\n", ioc->name, event_data->PhyNum, |
| 4072 | event_data->PortWidth)); |
| 4073 | |
| 4074 | dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name, |
| 4075 | __func__)); |
| 4076 | |
| 4077 | mutex_lock(&ioc->tm_cmds.mutex); |
| 4078 | termination_count = 0; |
| 4079 | query_count = 0; |
| 4080 | mpi_reply = ioc->tm_cmds.reply; |
| 4081 | for (smid = 1; smid <= ioc->request_depth; smid++) { |
| 4082 | scmd = _scsih_scsi_lookup_get(ioc, smid); |
| 4083 | if (!scmd) |
| 4084 | continue; |
| 4085 | sas_device_priv_data = scmd->device->hostdata; |
| 4086 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) |
| 4087 | continue; |
| 4088 | /* skip hidden raid components */ |
| 4089 | if (sas_device_priv_data->sas_target->flags & |
| 4090 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 4091 | continue; |
| 4092 | /* skip volumes */ |
| 4093 | if (sas_device_priv_data->sas_target->flags & |
| 4094 | MPT_TARGET_FLAGS_VOLUME) |
| 4095 | continue; |
| 4096 | |
| 4097 | handle = sas_device_priv_data->sas_target->handle; |
| 4098 | lun = sas_device_priv_data->lun; |
| 4099 | query_count++; |
| 4100 | |
| 4101 | mpt2sas_scsih_issue_tm(ioc, handle, lun, |
| 4102 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30); |
Eric Moore | 8901cbb | 2009-04-21 15:41:32 -0600 | [diff] [blame] | 4103 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4104 | |
| 4105 | if ((mpi_reply->IOCStatus == MPI2_IOCSTATUS_SUCCESS) && |
| 4106 | (mpi_reply->ResponseCode == |
| 4107 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || |
| 4108 | mpi_reply->ResponseCode == |
| 4109 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC)) |
| 4110 | continue; |
| 4111 | |
| 4112 | mpt2sas_scsih_issue_tm(ioc, handle, lun, |
Eric Moore | 8901cbb | 2009-04-21 15:41:32 -0600 | [diff] [blame] | 4113 | MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, 0, 30); |
| 4114 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4115 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); |
| 4116 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4117 | ioc->broadcast_aen_busy = 0; |
| 4118 | mutex_unlock(&ioc->tm_cmds.mutex); |
| 4119 | |
| 4120 | dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT |
| 4121 | "%s - exit, query_count = %d termination_count = %d\n", |
| 4122 | ioc->name, __func__, query_count, termination_count)); |
| 4123 | } |
| 4124 | |
| 4125 | /** |
| 4126 | * _scsih_sas_discovery_event - handle discovery events |
| 4127 | * @ioc: per adapter object |
| 4128 | * @event_data: event data payload |
| 4129 | * Context: user. |
| 4130 | * |
| 4131 | * Return nothing. |
| 4132 | */ |
| 4133 | static void |
| 4134 | _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, |
| 4135 | Mpi2EventDataSasDiscovery_t *event_data) |
| 4136 | { |
| 4137 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4138 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
| 4139 | printk(MPT2SAS_DEBUG_FMT "discovery event: (%s)", ioc->name, |
| 4140 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? |
| 4141 | "start" : "stop"); |
| 4142 | if (event_data->DiscoveryStatus) |
| 4143 | printk(MPT2SAS_DEBUG_FMT ", discovery_status(0x%08x)", |
| 4144 | ioc->name, le32_to_cpu(event_data->DiscoveryStatus)); |
| 4145 | printk("\n"); |
| 4146 | } |
| 4147 | #endif |
| 4148 | |
| 4149 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && |
| 4150 | !ioc->sas_hba.num_phys) |
| 4151 | _scsih_sas_host_add(ioc); |
| 4152 | } |
| 4153 | |
| 4154 | /** |
| 4155 | * _scsih_reprobe_lun - reprobing lun |
| 4156 | * @sdev: scsi device struct |
| 4157 | * @no_uld_attach: sdev->no_uld_attach flag setting |
| 4158 | * |
| 4159 | **/ |
| 4160 | static void |
| 4161 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) |
| 4162 | { |
| 4163 | int rc; |
| 4164 | |
| 4165 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
| 4166 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", |
| 4167 | sdev->no_uld_attach ? "hidding" : "exposing"); |
| 4168 | rc = scsi_device_reprobe(sdev); |
| 4169 | } |
| 4170 | |
| 4171 | /** |
| 4172 | * _scsih_reprobe_target - reprobing target |
| 4173 | * @starget: scsi target struct |
| 4174 | * @no_uld_attach: sdev->no_uld_attach flag setting |
| 4175 | * |
| 4176 | * Note: no_uld_attach flag determines whether the disk device is attached |
| 4177 | * to block layer. A value of `1` means to not attach. |
| 4178 | **/ |
| 4179 | static void |
| 4180 | _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach) |
| 4181 | { |
| 4182 | struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata; |
| 4183 | |
| 4184 | if (no_uld_attach) |
| 4185 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 4186 | else |
| 4187 | sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 4188 | |
| 4189 | starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL, |
| 4190 | _scsih_reprobe_lun); |
| 4191 | } |
| 4192 | /** |
| 4193 | * _scsih_sas_volume_add - add new volume |
| 4194 | * @ioc: per adapter object |
| 4195 | * @element: IR config element data |
| 4196 | * Context: user. |
| 4197 | * |
| 4198 | * Return nothing. |
| 4199 | */ |
| 4200 | static void |
| 4201 | _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc, |
| 4202 | Mpi2EventIrConfigElement_t *element) |
| 4203 | { |
| 4204 | struct _raid_device *raid_device; |
| 4205 | unsigned long flags; |
| 4206 | u64 wwid; |
| 4207 | u16 handle = le16_to_cpu(element->VolDevHandle); |
| 4208 | int rc; |
| 4209 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4210 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 4211 | if (!wwid) { |
| 4212 | printk(MPT2SAS_ERR_FMT |
| 4213 | "failure at %s:%d/%s()!\n", ioc->name, |
| 4214 | __FILE__, __LINE__, __func__); |
| 4215 | return; |
| 4216 | } |
| 4217 | |
| 4218 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 4219 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); |
| 4220 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 4221 | |
| 4222 | if (raid_device) |
| 4223 | return; |
| 4224 | |
| 4225 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 4226 | if (!raid_device) { |
| 4227 | printk(MPT2SAS_ERR_FMT |
| 4228 | "failure at %s:%d/%s()!\n", ioc->name, |
| 4229 | __FILE__, __LINE__, __func__); |
| 4230 | return; |
| 4231 | } |
| 4232 | |
| 4233 | raid_device->id = ioc->sas_id++; |
| 4234 | raid_device->channel = RAID_CHANNEL; |
| 4235 | raid_device->handle = handle; |
| 4236 | raid_device->wwid = wwid; |
| 4237 | _scsih_raid_device_add(ioc, raid_device); |
| 4238 | if (!ioc->wait_for_port_enable_to_complete) { |
| 4239 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 4240 | raid_device->id, 0); |
| 4241 | if (rc) |
| 4242 | _scsih_raid_device_remove(ioc, raid_device); |
| 4243 | } else |
| 4244 | _scsih_determine_boot_device(ioc, raid_device, 1); |
| 4245 | } |
| 4246 | |
| 4247 | /** |
| 4248 | * _scsih_sas_volume_delete - delete volume |
| 4249 | * @ioc: per adapter object |
| 4250 | * @element: IR config element data |
| 4251 | * Context: user. |
| 4252 | * |
| 4253 | * Return nothing. |
| 4254 | */ |
| 4255 | static void |
| 4256 | _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, |
| 4257 | Mpi2EventIrConfigElement_t *element) |
| 4258 | { |
| 4259 | struct _raid_device *raid_device; |
| 4260 | u16 handle = le16_to_cpu(element->VolDevHandle); |
| 4261 | unsigned long flags; |
| 4262 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 4263 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4264 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 4265 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 4266 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 4267 | if (!raid_device) |
| 4268 | return; |
| 4269 | if (raid_device->starget) { |
| 4270 | sas_target_priv_data = raid_device->starget->hostdata; |
| 4271 | sas_target_priv_data->deleted = 1; |
| 4272 | scsi_remove_target(&raid_device->starget->dev); |
| 4273 | } |
| 4274 | _scsih_raid_device_remove(ioc, raid_device); |
| 4275 | } |
| 4276 | |
| 4277 | /** |
| 4278 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX |
| 4279 | * @ioc: per adapter object |
| 4280 | * @element: IR config element data |
| 4281 | * Context: user. |
| 4282 | * |
| 4283 | * Return nothing. |
| 4284 | */ |
| 4285 | static void |
| 4286 | _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc, |
| 4287 | Mpi2EventIrConfigElement_t *element) |
| 4288 | { |
| 4289 | struct _sas_device *sas_device; |
| 4290 | unsigned long flags; |
| 4291 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 4292 | |
| 4293 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4294 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 4295 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4296 | if (!sas_device) |
| 4297 | return; |
| 4298 | |
| 4299 | /* exposing raid component */ |
| 4300 | sas_device->volume_handle = 0; |
| 4301 | sas_device->volume_wwid = 0; |
| 4302 | sas_device->hidden_raid_component = 0; |
| 4303 | _scsih_reprobe_target(sas_device->starget, 0); |
| 4304 | } |
| 4305 | |
| 4306 | /** |
| 4307 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX |
| 4308 | * @ioc: per adapter object |
| 4309 | * @element: IR config element data |
| 4310 | * Context: user. |
| 4311 | * |
| 4312 | * Return nothing. |
| 4313 | */ |
| 4314 | static void |
| 4315 | _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc, |
| 4316 | Mpi2EventIrConfigElement_t *element) |
| 4317 | { |
| 4318 | struct _sas_device *sas_device; |
| 4319 | unsigned long flags; |
| 4320 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 4321 | |
| 4322 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4323 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 4324 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4325 | if (!sas_device) |
| 4326 | return; |
| 4327 | |
| 4328 | /* hiding raid component */ |
| 4329 | mpt2sas_config_get_volume_handle(ioc, handle, |
| 4330 | &sas_device->volume_handle); |
| 4331 | mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle, |
| 4332 | &sas_device->volume_wwid); |
| 4333 | sas_device->hidden_raid_component = 1; |
| 4334 | _scsih_reprobe_target(sas_device->starget, 1); |
| 4335 | } |
| 4336 | |
| 4337 | /** |
| 4338 | * _scsih_sas_pd_delete - delete pd component |
| 4339 | * @ioc: per adapter object |
| 4340 | * @element: IR config element data |
| 4341 | * Context: user. |
| 4342 | * |
| 4343 | * Return nothing. |
| 4344 | */ |
| 4345 | static void |
| 4346 | _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc, |
| 4347 | Mpi2EventIrConfigElement_t *element) |
| 4348 | { |
| 4349 | struct _sas_device *sas_device; |
| 4350 | unsigned long flags; |
| 4351 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 4352 | |
| 4353 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4354 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 4355 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4356 | if (!sas_device) |
| 4357 | return; |
| 4358 | _scsih_remove_device(ioc, handle); |
| 4359 | } |
| 4360 | |
| 4361 | /** |
| 4362 | * _scsih_sas_pd_add - remove pd component |
| 4363 | * @ioc: per adapter object |
| 4364 | * @element: IR config element data |
| 4365 | * Context: user. |
| 4366 | * |
| 4367 | * Return nothing. |
| 4368 | */ |
| 4369 | static void |
| 4370 | _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc, |
| 4371 | Mpi2EventIrConfigElement_t *element) |
| 4372 | { |
| 4373 | struct _sas_device *sas_device; |
| 4374 | unsigned long flags; |
| 4375 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 4376 | Mpi2ConfigReply_t mpi_reply; |
| 4377 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4378 | u32 ioc_status; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4379 | |
| 4380 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4381 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 4382 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 4383 | if (sas_device) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4384 | sas_device->hidden_raid_component = 1; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 4385 | return; |
| 4386 | } |
| 4387 | |
| 4388 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 4389 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 4390 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4391 | ioc->name, __FILE__, __LINE__, __func__); |
| 4392 | return; |
| 4393 | } |
| 4394 | |
| 4395 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4396 | MPI2_IOCSTATUS_MASK; |
| 4397 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4398 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4399 | ioc->name, __FILE__, __LINE__, __func__); |
| 4400 | return; |
| 4401 | } |
| 4402 | |
| 4403 | _scsih_link_change(ioc, |
| 4404 | le16_to_cpu(sas_device_pg0.ParentDevHandle), |
| 4405 | handle, sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
| 4406 | |
| 4407 | _scsih_add_device(ioc, handle, 0, 1); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4408 | } |
| 4409 | |
| 4410 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4411 | /** |
| 4412 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events |
| 4413 | * @ioc: per adapter object |
| 4414 | * @event_data: event data payload |
| 4415 | * Context: user. |
| 4416 | * |
| 4417 | * Return nothing. |
| 4418 | */ |
| 4419 | static void |
| 4420 | _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 4421 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 4422 | { |
| 4423 | Mpi2EventIrConfigElement_t *element; |
| 4424 | u8 element_type; |
| 4425 | int i; |
| 4426 | char *reason_str = NULL, *element_str = NULL; |
| 4427 | |
| 4428 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 4429 | |
| 4430 | printk(MPT2SAS_DEBUG_FMT "raid config change: (%s), elements(%d)\n", |
| 4431 | ioc->name, (le32_to_cpu(event_data->Flags) & |
| 4432 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? |
| 4433 | "foreign" : "native", event_data->NumElements); |
| 4434 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 4435 | switch (element->ReasonCode) { |
| 4436 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
| 4437 | reason_str = "add"; |
| 4438 | break; |
| 4439 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
| 4440 | reason_str = "remove"; |
| 4441 | break; |
| 4442 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: |
| 4443 | reason_str = "no change"; |
| 4444 | break; |
| 4445 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
| 4446 | reason_str = "hide"; |
| 4447 | break; |
| 4448 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
| 4449 | reason_str = "unhide"; |
| 4450 | break; |
| 4451 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 4452 | reason_str = "volume_created"; |
| 4453 | break; |
| 4454 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 4455 | reason_str = "volume_deleted"; |
| 4456 | break; |
| 4457 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
| 4458 | reason_str = "pd_created"; |
| 4459 | break; |
| 4460 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
| 4461 | reason_str = "pd_deleted"; |
| 4462 | break; |
| 4463 | default: |
| 4464 | reason_str = "unknown reason"; |
| 4465 | break; |
| 4466 | } |
| 4467 | element_type = le16_to_cpu(element->ElementFlags) & |
| 4468 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; |
| 4469 | switch (element_type) { |
| 4470 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: |
| 4471 | element_str = "volume"; |
| 4472 | break; |
| 4473 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: |
| 4474 | element_str = "phys disk"; |
| 4475 | break; |
| 4476 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: |
| 4477 | element_str = "hot spare"; |
| 4478 | break; |
| 4479 | default: |
| 4480 | element_str = "unknown element"; |
| 4481 | break; |
| 4482 | } |
| 4483 | printk(KERN_DEBUG "\t(%s:%s), vol handle(0x%04x), " |
| 4484 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, |
| 4485 | reason_str, le16_to_cpu(element->VolDevHandle), |
| 4486 | le16_to_cpu(element->PhysDiskDevHandle), |
| 4487 | element->PhysDiskNum); |
| 4488 | } |
| 4489 | } |
| 4490 | #endif |
| 4491 | |
| 4492 | /** |
| 4493 | * _scsih_sas_ir_config_change_event - handle ir configuration change events |
| 4494 | * @ioc: per adapter object |
| 4495 | * @VF_ID: |
| 4496 | * @event_data: event data payload |
| 4497 | * Context: user. |
| 4498 | * |
| 4499 | * Return nothing. |
| 4500 | */ |
| 4501 | static void |
| 4502 | _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, |
| 4503 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 4504 | { |
| 4505 | Mpi2EventIrConfigElement_t *element; |
| 4506 | int i; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 4507 | u8 foreign_config; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4508 | |
| 4509 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4510 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 4511 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
| 4512 | |
| 4513 | #endif |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 4514 | foreign_config = (le32_to_cpu(event_data->Flags) & |
| 4515 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4516 | |
| 4517 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 4518 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 4519 | |
| 4520 | switch (element->ReasonCode) { |
| 4521 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 4522 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 4523 | if (!foreign_config) |
| 4524 | _scsih_sas_volume_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4525 | break; |
| 4526 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 4527 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 4528 | if (!foreign_config) |
| 4529 | _scsih_sas_volume_delete(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4530 | break; |
| 4531 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
| 4532 | _scsih_sas_pd_hide(ioc, element); |
| 4533 | break; |
| 4534 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
| 4535 | _scsih_sas_pd_expose(ioc, element); |
| 4536 | break; |
| 4537 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
| 4538 | _scsih_sas_pd_add(ioc, element); |
| 4539 | break; |
| 4540 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
| 4541 | _scsih_sas_pd_delete(ioc, element); |
| 4542 | break; |
| 4543 | } |
| 4544 | } |
| 4545 | } |
| 4546 | |
| 4547 | /** |
| 4548 | * _scsih_sas_ir_volume_event - IR volume event |
| 4549 | * @ioc: per adapter object |
| 4550 | * @event_data: event data payload |
| 4551 | * Context: user. |
| 4552 | * |
| 4553 | * Return nothing. |
| 4554 | */ |
| 4555 | static void |
| 4556 | _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, |
| 4557 | Mpi2EventDataIrVolume_t *event_data) |
| 4558 | { |
| 4559 | u64 wwid; |
| 4560 | unsigned long flags; |
| 4561 | struct _raid_device *raid_device; |
| 4562 | u16 handle; |
| 4563 | u32 state; |
| 4564 | int rc; |
| 4565 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 4566 | |
| 4567 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 4568 | return; |
| 4569 | |
| 4570 | handle = le16_to_cpu(event_data->VolDevHandle); |
| 4571 | state = le32_to_cpu(event_data->NewValue); |
| 4572 | dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle(0x%04x), " |
| 4573 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 4574 | le32_to_cpu(event_data->PreviousValue), state)); |
| 4575 | |
| 4576 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 4577 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 4578 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 4579 | |
| 4580 | switch (state) { |
| 4581 | case MPI2_RAID_VOL_STATE_MISSING: |
| 4582 | case MPI2_RAID_VOL_STATE_FAILED: |
| 4583 | if (!raid_device) |
| 4584 | break; |
| 4585 | if (raid_device->starget) { |
| 4586 | sas_target_priv_data = raid_device->starget->hostdata; |
| 4587 | sas_target_priv_data->deleted = 1; |
| 4588 | scsi_remove_target(&raid_device->starget->dev); |
| 4589 | } |
| 4590 | _scsih_raid_device_remove(ioc, raid_device); |
| 4591 | break; |
| 4592 | |
| 4593 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 4594 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 4595 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
| 4596 | if (raid_device) |
| 4597 | break; |
| 4598 | |
| 4599 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 4600 | if (!wwid) { |
| 4601 | printk(MPT2SAS_ERR_FMT |
| 4602 | "failure at %s:%d/%s()!\n", ioc->name, |
| 4603 | __FILE__, __LINE__, __func__); |
| 4604 | break; |
| 4605 | } |
| 4606 | |
| 4607 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 4608 | if (!raid_device) { |
| 4609 | printk(MPT2SAS_ERR_FMT |
| 4610 | "failure at %s:%d/%s()!\n", ioc->name, |
| 4611 | __FILE__, __LINE__, __func__); |
| 4612 | break; |
| 4613 | } |
| 4614 | |
| 4615 | raid_device->id = ioc->sas_id++; |
| 4616 | raid_device->channel = RAID_CHANNEL; |
| 4617 | raid_device->handle = handle; |
| 4618 | raid_device->wwid = wwid; |
| 4619 | _scsih_raid_device_add(ioc, raid_device); |
| 4620 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 4621 | raid_device->id, 0); |
| 4622 | if (rc) |
| 4623 | _scsih_raid_device_remove(ioc, raid_device); |
| 4624 | break; |
| 4625 | |
| 4626 | case MPI2_RAID_VOL_STATE_INITIALIZING: |
| 4627 | default: |
| 4628 | break; |
| 4629 | } |
| 4630 | } |
| 4631 | |
| 4632 | /** |
| 4633 | * _scsih_sas_ir_physical_disk_event - PD event |
| 4634 | * @ioc: per adapter object |
| 4635 | * @event_data: event data payload |
| 4636 | * Context: user. |
| 4637 | * |
| 4638 | * Return nothing. |
| 4639 | */ |
| 4640 | static void |
| 4641 | _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, |
| 4642 | Mpi2EventDataIrPhysicalDisk_t *event_data) |
| 4643 | { |
| 4644 | u16 handle; |
| 4645 | u32 state; |
| 4646 | struct _sas_device *sas_device; |
| 4647 | unsigned long flags; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 4648 | Mpi2ConfigReply_t mpi_reply; |
| 4649 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4650 | u32 ioc_status; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4651 | |
| 4652 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) |
| 4653 | return; |
| 4654 | |
| 4655 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); |
| 4656 | state = le32_to_cpu(event_data->NewValue); |
| 4657 | |
| 4658 | dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle(0x%04x), " |
| 4659 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 4660 | le32_to_cpu(event_data->PreviousValue), state)); |
| 4661 | |
| 4662 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4663 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 4664 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4665 | |
| 4666 | switch (state) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4667 | case MPI2_RAID_PD_STATE_ONLINE: |
| 4668 | case MPI2_RAID_PD_STATE_DEGRADED: |
| 4669 | case MPI2_RAID_PD_STATE_REBUILDING: |
| 4670 | case MPI2_RAID_PD_STATE_OPTIMAL: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 4671 | if (sas_device) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4672 | sas_device->hidden_raid_component = 1; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 4673 | return; |
| 4674 | } |
| 4675 | |
| 4676 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 4677 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 4678 | handle))) { |
| 4679 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4680 | ioc->name, __FILE__, __LINE__, __func__); |
| 4681 | return; |
| 4682 | } |
| 4683 | |
| 4684 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4685 | MPI2_IOCSTATUS_MASK; |
| 4686 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4687 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4688 | ioc->name, __FILE__, __LINE__, __func__); |
| 4689 | return; |
| 4690 | } |
| 4691 | |
| 4692 | _scsih_link_change(ioc, |
| 4693 | le16_to_cpu(sas_device_pg0.ParentDevHandle), |
| 4694 | handle, sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
| 4695 | |
| 4696 | _scsih_add_device(ioc, handle, 0, 1); |
| 4697 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4698 | break; |
| 4699 | |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 4700 | case MPI2_RAID_PD_STATE_OFFLINE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4701 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: |
| 4702 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: |
| 4703 | case MPI2_RAID_PD_STATE_HOT_SPARE: |
| 4704 | default: |
| 4705 | break; |
| 4706 | } |
| 4707 | } |
| 4708 | |
| 4709 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4710 | /** |
| 4711 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event |
| 4712 | * @ioc: per adapter object |
| 4713 | * @event_data: event data payload |
| 4714 | * Context: user. |
| 4715 | * |
| 4716 | * Return nothing. |
| 4717 | */ |
| 4718 | static void |
| 4719 | _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 4720 | Mpi2EventDataIrOperationStatus_t *event_data) |
| 4721 | { |
| 4722 | char *reason_str = NULL; |
| 4723 | |
| 4724 | switch (event_data->RAIDOperation) { |
| 4725 | case MPI2_EVENT_IR_RAIDOP_RESYNC: |
| 4726 | reason_str = "resync"; |
| 4727 | break; |
| 4728 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: |
| 4729 | reason_str = "online capacity expansion"; |
| 4730 | break; |
| 4731 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: |
| 4732 | reason_str = "consistency check"; |
| 4733 | break; |
| 4734 | default: |
| 4735 | reason_str = "unknown reason"; |
| 4736 | break; |
| 4737 | } |
| 4738 | |
| 4739 | printk(MPT2SAS_INFO_FMT "raid operational status: (%s)" |
| 4740 | "\thandle(0x%04x), percent complete(%d)\n", |
| 4741 | ioc->name, reason_str, |
| 4742 | le16_to_cpu(event_data->VolDevHandle), |
| 4743 | event_data->PercentComplete); |
| 4744 | } |
| 4745 | #endif |
| 4746 | |
| 4747 | /** |
| 4748 | * _scsih_sas_ir_operation_status_event - handle RAID operation events |
| 4749 | * @ioc: per adapter object |
| 4750 | * @VF_ID: |
| 4751 | * @event_data: event data payload |
| 4752 | * Context: user. |
| 4753 | * |
| 4754 | * Return nothing. |
| 4755 | */ |
| 4756 | static void |
| 4757 | _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, |
| 4758 | Mpi2EventDataIrOperationStatus_t *event_data) |
| 4759 | { |
| 4760 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4761 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 4762 | _scsih_sas_ir_operation_status_event_debug(ioc, event_data); |
| 4763 | #endif |
| 4764 | } |
| 4765 | |
| 4766 | /** |
| 4767 | * _scsih_task_set_full - handle task set full |
| 4768 | * @ioc: per adapter object |
| 4769 | * @event_data: event data payload |
| 4770 | * Context: user. |
| 4771 | * |
| 4772 | * Throttle back qdepth. |
| 4773 | */ |
| 4774 | static void |
| 4775 | _scsih_task_set_full(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, |
| 4776 | Mpi2EventDataTaskSetFull_t *event_data) |
| 4777 | { |
| 4778 | unsigned long flags; |
| 4779 | struct _sas_device *sas_device; |
| 4780 | static struct _raid_device *raid_device; |
| 4781 | struct scsi_device *sdev; |
| 4782 | int depth; |
| 4783 | u16 current_depth; |
| 4784 | u16 handle; |
| 4785 | int id, channel; |
| 4786 | u64 sas_address; |
| 4787 | |
| 4788 | current_depth = le16_to_cpu(event_data->CurrentDepth); |
| 4789 | handle = le16_to_cpu(event_data->DevHandle); |
| 4790 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4791 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 4792 | if (!sas_device) { |
| 4793 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4794 | return; |
| 4795 | } |
| 4796 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4797 | id = sas_device->id; |
| 4798 | channel = sas_device->channel; |
| 4799 | sas_address = sas_device->sas_address; |
| 4800 | |
| 4801 | /* if hidden raid component, then change to volume characteristics */ |
| 4802 | if (sas_device->hidden_raid_component && sas_device->volume_handle) { |
| 4803 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 4804 | raid_device = _scsih_raid_device_find_by_handle( |
| 4805 | ioc, sas_device->volume_handle); |
| 4806 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 4807 | if (raid_device) { |
| 4808 | id = raid_device->id; |
| 4809 | channel = raid_device->channel; |
| 4810 | handle = raid_device->handle; |
| 4811 | sas_address = raid_device->wwid; |
| 4812 | } |
| 4813 | } |
| 4814 | |
| 4815 | if (ioc->logging_level & MPT_DEBUG_TASK_SET_FULL) |
| 4816 | starget_printk(KERN_DEBUG, sas_device->starget, "task set " |
| 4817 | "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n", |
| 4818 | handle, (unsigned long long)sas_address, current_depth); |
| 4819 | |
| 4820 | shost_for_each_device(sdev, ioc->shost) { |
| 4821 | if (sdev->id == id && sdev->channel == channel) { |
| 4822 | if (current_depth > sdev->queue_depth) { |
| 4823 | if (ioc->logging_level & |
| 4824 | MPT_DEBUG_TASK_SET_FULL) |
| 4825 | sdev_printk(KERN_INFO, sdev, "strange " |
| 4826 | "observation, the queue depth is" |
| 4827 | " (%d) meanwhile fw queue depth " |
| 4828 | "is (%d)\n", sdev->queue_depth, |
| 4829 | current_depth); |
| 4830 | continue; |
| 4831 | } |
| 4832 | depth = scsi_track_queue_full(sdev, |
| 4833 | current_depth - 1); |
| 4834 | if (depth > 0) |
| 4835 | sdev_printk(KERN_INFO, sdev, "Queue depth " |
| 4836 | "reduced to (%d)\n", depth); |
| 4837 | else if (depth < 0) |
| 4838 | sdev_printk(KERN_INFO, sdev, "Tagged Command " |
| 4839 | "Queueing is being disabled\n"); |
| 4840 | else if (depth == 0) |
| 4841 | if (ioc->logging_level & |
| 4842 | MPT_DEBUG_TASK_SET_FULL) |
| 4843 | sdev_printk(KERN_INFO, sdev, |
| 4844 | "Queue depth not changed yet\n"); |
| 4845 | } |
| 4846 | } |
| 4847 | } |
| 4848 | |
| 4849 | /** |
| 4850 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding |
| 4851 | * @ioc: per adapter object |
| 4852 | * @sas_address: sas address |
| 4853 | * @slot: enclosure slot id |
| 4854 | * @handle: device handle |
| 4855 | * |
| 4856 | * After host reset, find out whether devices are still responding. |
| 4857 | * Used in _scsi_remove_unresponsive_sas_devices. |
| 4858 | * |
| 4859 | * Return nothing. |
| 4860 | */ |
| 4861 | static void |
| 4862 | _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 4863 | u16 slot, u16 handle) |
| 4864 | { |
| 4865 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 4866 | struct scsi_target *starget; |
| 4867 | struct _sas_device *sas_device; |
| 4868 | unsigned long flags; |
| 4869 | |
| 4870 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4871 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { |
| 4872 | if (sas_device->sas_address == sas_address && |
| 4873 | sas_device->slot == slot && sas_device->starget) { |
| 4874 | sas_device->responding = 1; |
| 4875 | starget_printk(KERN_INFO, sas_device->starget, |
| 4876 | "handle(0x%04x), sas_addr(0x%016llx), enclosure " |
| 4877 | "logical id(0x%016llx), slot(%d)\n", handle, |
| 4878 | (unsigned long long)sas_device->sas_address, |
| 4879 | (unsigned long long) |
| 4880 | sas_device->enclosure_logical_id, |
| 4881 | sas_device->slot); |
| 4882 | if (sas_device->handle == handle) |
| 4883 | goto out; |
| 4884 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 4885 | sas_device->handle); |
| 4886 | sas_device->handle = handle; |
| 4887 | starget = sas_device->starget; |
| 4888 | sas_target_priv_data = starget->hostdata; |
| 4889 | sas_target_priv_data->handle = handle; |
| 4890 | goto out; |
| 4891 | } |
| 4892 | } |
| 4893 | out: |
| 4894 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4895 | } |
| 4896 | |
| 4897 | /** |
| 4898 | * _scsih_search_responding_sas_devices - |
| 4899 | * @ioc: per adapter object |
| 4900 | * |
| 4901 | * After host reset, find out whether devices are still responding. |
| 4902 | * If not remove. |
| 4903 | * |
| 4904 | * Return nothing. |
| 4905 | */ |
| 4906 | static void |
| 4907 | _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
| 4908 | { |
| 4909 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4910 | Mpi2ConfigReply_t mpi_reply; |
| 4911 | u16 ioc_status; |
| 4912 | __le64 sas_address; |
| 4913 | u16 handle; |
| 4914 | u32 device_info; |
| 4915 | u16 slot; |
| 4916 | |
| 4917 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__); |
| 4918 | |
| 4919 | if (list_empty(&ioc->sas_device_list)) |
| 4920 | return; |
| 4921 | |
| 4922 | handle = 0xFFFF; |
| 4923 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 4924 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 4925 | handle))) { |
| 4926 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4927 | MPI2_IOCSTATUS_MASK; |
| 4928 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 4929 | break; |
| 4930 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 4931 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 4932 | if (!(_scsih_is_end_device(device_info))) |
| 4933 | continue; |
| 4934 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 4935 | slot = le16_to_cpu(sas_device_pg0.Slot); |
| 4936 | _scsih_mark_responding_sas_device(ioc, sas_address, slot, |
| 4937 | handle); |
| 4938 | } |
| 4939 | } |
| 4940 | |
| 4941 | /** |
| 4942 | * _scsih_mark_responding_raid_device - mark a raid_device as responding |
| 4943 | * @ioc: per adapter object |
| 4944 | * @wwid: world wide identifier for raid volume |
| 4945 | * @handle: device handle |
| 4946 | * |
| 4947 | * After host reset, find out whether devices are still responding. |
| 4948 | * Used in _scsi_remove_unresponsive_raid_devices. |
| 4949 | * |
| 4950 | * Return nothing. |
| 4951 | */ |
| 4952 | static void |
| 4953 | _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid, |
| 4954 | u16 handle) |
| 4955 | { |
| 4956 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 4957 | struct scsi_target *starget; |
| 4958 | struct _raid_device *raid_device; |
| 4959 | unsigned long flags; |
| 4960 | |
| 4961 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 4962 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 4963 | if (raid_device->wwid == wwid && raid_device->starget) { |
| 4964 | raid_device->responding = 1; |
| 4965 | starget_printk(KERN_INFO, raid_device->starget, |
| 4966 | "handle(0x%04x), wwid(0x%016llx)\n", handle, |
| 4967 | (unsigned long long)raid_device->wwid); |
| 4968 | if (raid_device->handle == handle) |
| 4969 | goto out; |
| 4970 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 4971 | raid_device->handle); |
| 4972 | raid_device->handle = handle; |
| 4973 | starget = raid_device->starget; |
| 4974 | sas_target_priv_data = starget->hostdata; |
| 4975 | sas_target_priv_data->handle = handle; |
| 4976 | goto out; |
| 4977 | } |
| 4978 | } |
| 4979 | out: |
| 4980 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 4981 | } |
| 4982 | |
| 4983 | /** |
| 4984 | * _scsih_search_responding_raid_devices - |
| 4985 | * @ioc: per adapter object |
| 4986 | * |
| 4987 | * After host reset, find out whether devices are still responding. |
| 4988 | * If not remove. |
| 4989 | * |
| 4990 | * Return nothing. |
| 4991 | */ |
| 4992 | static void |
| 4993 | _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc) |
| 4994 | { |
| 4995 | Mpi2RaidVolPage1_t volume_pg1; |
| 4996 | Mpi2ConfigReply_t mpi_reply; |
| 4997 | u16 ioc_status; |
| 4998 | u16 handle; |
| 4999 | |
| 5000 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__); |
| 5001 | |
| 5002 | if (list_empty(&ioc->raid_device_list)) |
| 5003 | return; |
| 5004 | |
| 5005 | handle = 0xFFFF; |
| 5006 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 5007 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 5008 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 5009 | MPI2_IOCSTATUS_MASK; |
| 5010 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 5011 | break; |
| 5012 | handle = le16_to_cpu(volume_pg1.DevHandle); |
| 5013 | _scsih_mark_responding_raid_device(ioc, |
| 5014 | le64_to_cpu(volume_pg1.WWID), handle); |
| 5015 | } |
| 5016 | } |
| 5017 | |
| 5018 | /** |
| 5019 | * _scsih_mark_responding_expander - mark a expander as responding |
| 5020 | * @ioc: per adapter object |
| 5021 | * @sas_address: sas address |
| 5022 | * @handle: |
| 5023 | * |
| 5024 | * After host reset, find out whether devices are still responding. |
| 5025 | * Used in _scsi_remove_unresponsive_expanders. |
| 5026 | * |
| 5027 | * Return nothing. |
| 5028 | */ |
| 5029 | static void |
| 5030 | _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 5031 | u16 handle) |
| 5032 | { |
| 5033 | struct _sas_node *sas_expander; |
| 5034 | unsigned long flags; |
| 5035 | |
| 5036 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 5037 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 5038 | if (sas_expander->sas_address == sas_address) { |
| 5039 | sas_expander->responding = 1; |
| 5040 | if (sas_expander->handle != handle) { |
| 5041 | printk(KERN_INFO "old handle(0x%04x)\n", |
| 5042 | sas_expander->handle); |
| 5043 | sas_expander->handle = handle; |
| 5044 | } |
| 5045 | goto out; |
| 5046 | } |
| 5047 | } |
| 5048 | out: |
| 5049 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 5050 | } |
| 5051 | |
| 5052 | /** |
| 5053 | * _scsih_search_responding_expanders - |
| 5054 | * @ioc: per adapter object |
| 5055 | * |
| 5056 | * After host reset, find out whether devices are still responding. |
| 5057 | * If not remove. |
| 5058 | * |
| 5059 | * Return nothing. |
| 5060 | */ |
| 5061 | static void |
| 5062 | _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc) |
| 5063 | { |
| 5064 | Mpi2ExpanderPage0_t expander_pg0; |
| 5065 | Mpi2ConfigReply_t mpi_reply; |
| 5066 | u16 ioc_status; |
| 5067 | __le64 sas_address; |
| 5068 | u16 handle; |
| 5069 | |
| 5070 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__); |
| 5071 | |
| 5072 | if (list_empty(&ioc->sas_expander_list)) |
| 5073 | return; |
| 5074 | |
| 5075 | handle = 0xFFFF; |
| 5076 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 5077 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 5078 | |
| 5079 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 5080 | MPI2_IOCSTATUS_MASK; |
| 5081 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 5082 | break; |
| 5083 | |
| 5084 | handle = le16_to_cpu(expander_pg0.DevHandle); |
| 5085 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
| 5086 | printk(KERN_INFO "\texpander present: handle(0x%04x), " |
| 5087 | "sas_addr(0x%016llx)\n", handle, |
| 5088 | (unsigned long long)sas_address); |
| 5089 | _scsih_mark_responding_expander(ioc, sas_address, handle); |
| 5090 | } |
| 5091 | |
| 5092 | } |
| 5093 | |
| 5094 | /** |
| 5095 | * _scsih_remove_unresponding_devices - removing unresponding devices |
| 5096 | * @ioc: per adapter object |
| 5097 | * |
| 5098 | * Return nothing. |
| 5099 | */ |
| 5100 | static void |
| 5101 | _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER *ioc) |
| 5102 | { |
| 5103 | struct _sas_device *sas_device, *sas_device_next; |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 5104 | struct _sas_node *sas_expander; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5105 | struct _raid_device *raid_device, *raid_device_next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5106 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5107 | |
| 5108 | list_for_each_entry_safe(sas_device, sas_device_next, |
| 5109 | &ioc->sas_device_list, list) { |
| 5110 | if (sas_device->responding) { |
| 5111 | sas_device->responding = 0; |
| 5112 | continue; |
| 5113 | } |
| 5114 | if (sas_device->starget) |
| 5115 | starget_printk(KERN_INFO, sas_device->starget, |
| 5116 | "removing: handle(0x%04x), sas_addr(0x%016llx), " |
| 5117 | "enclosure logical id(0x%016llx), slot(%d)\n", |
| 5118 | sas_device->handle, |
| 5119 | (unsigned long long)sas_device->sas_address, |
| 5120 | (unsigned long long) |
| 5121 | sas_device->enclosure_logical_id, |
| 5122 | sas_device->slot); |
| 5123 | _scsih_remove_device(ioc, sas_device->handle); |
| 5124 | } |
| 5125 | |
| 5126 | list_for_each_entry_safe(raid_device, raid_device_next, |
| 5127 | &ioc->raid_device_list, list) { |
| 5128 | if (raid_device->responding) { |
| 5129 | raid_device->responding = 0; |
| 5130 | continue; |
| 5131 | } |
| 5132 | if (raid_device->starget) { |
| 5133 | starget_printk(KERN_INFO, raid_device->starget, |
| 5134 | "removing: handle(0x%04x), wwid(0x%016llx)\n", |
| 5135 | raid_device->handle, |
| 5136 | (unsigned long long)raid_device->wwid); |
| 5137 | scsi_remove_target(&raid_device->starget->dev); |
| 5138 | } |
| 5139 | _scsih_raid_device_remove(ioc, raid_device); |
| 5140 | } |
| 5141 | |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 5142 | retry_expander_search: |
| 5143 | sas_expander = NULL; |
| 5144 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5145 | if (sas_expander->responding) { |
| 5146 | sas_expander->responding = 0; |
| 5147 | continue; |
| 5148 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5149 | _scsih_expander_remove(ioc, sas_expander->handle); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 5150 | goto retry_expander_search; |
| 5151 | } |
| 5152 | } |
| 5153 | |
| 5154 | /** |
| 5155 | * mpt2sas_scsih_reset_handler - reset callback handler (for scsih) |
| 5156 | * @ioc: per adapter object |
| 5157 | * @reset_phase: phase |
| 5158 | * |
| 5159 | * The handler for doing any required cleanup or initialization. |
| 5160 | * |
| 5161 | * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET, |
| 5162 | * MPT2_IOC_DONE_RESET |
| 5163 | * |
| 5164 | * Return nothing. |
| 5165 | */ |
| 5166 | void |
| 5167 | mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase) |
| 5168 | { |
| 5169 | switch (reset_phase) { |
| 5170 | case MPT2_IOC_PRE_RESET: |
| 5171 | dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 5172 | "MPT2_IOC_PRE_RESET\n", ioc->name, __func__)); |
| 5173 | _scsih_fw_event_off(ioc); |
| 5174 | break; |
| 5175 | case MPT2_IOC_AFTER_RESET: |
| 5176 | dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 5177 | "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__)); |
| 5178 | if (ioc->tm_cmds.status & MPT2_CMD_PENDING) { |
| 5179 | ioc->tm_cmds.status |= MPT2_CMD_RESET; |
| 5180 | mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid); |
| 5181 | complete(&ioc->tm_cmds.done); |
| 5182 | } |
| 5183 | _scsih_fw_event_on(ioc); |
| 5184 | _scsih_flush_running_cmds(ioc); |
| 5185 | break; |
| 5186 | case MPT2_IOC_DONE_RESET: |
| 5187 | dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 5188 | "MPT2_IOC_DONE_RESET\n", ioc->name, __func__)); |
| 5189 | _scsih_sas_host_refresh(ioc, 0); |
| 5190 | _scsih_search_responding_sas_devices(ioc); |
| 5191 | _scsih_search_responding_raid_devices(ioc); |
| 5192 | _scsih_search_responding_expanders(ioc); |
| 5193 | break; |
| 5194 | case MPT2_IOC_RUNNING: |
| 5195 | dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 5196 | "MPT2_IOC_RUNNING\n", ioc->name, __func__)); |
| 5197 | _scsih_remove_unresponding_devices(ioc); |
| 5198 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5199 | } |
| 5200 | } |
| 5201 | |
| 5202 | /** |
| 5203 | * _firmware_event_work - delayed task for processing firmware events |
| 5204 | * @ioc: per adapter object |
| 5205 | * @work: equal to the fw_event_work object |
| 5206 | * Context: user. |
| 5207 | * |
| 5208 | * Return nothing. |
| 5209 | */ |
| 5210 | static void |
| 5211 | _firmware_event_work(struct work_struct *work) |
| 5212 | { |
| 5213 | struct fw_event_work *fw_event = container_of(work, |
Eric Moore | 6f92a7a | 2009-04-21 15:43:33 -0600 | [diff] [blame] | 5214 | struct fw_event_work, work); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5215 | unsigned long flags; |
| 5216 | struct MPT2SAS_ADAPTER *ioc = fw_event->ioc; |
| 5217 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5218 | /* the queue is being flushed so ignore this event */ |
| 5219 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 5220 | if (ioc->fw_events_off || ioc->remove_host) { |
| 5221 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 5222 | _scsih_fw_event_free(ioc, fw_event); |
| 5223 | return; |
| 5224 | } |
| 5225 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 5226 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5227 | if (ioc->shost_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5228 | _scsih_fw_event_requeue(ioc, fw_event, 1000); |
| 5229 | return; |
| 5230 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5231 | |
| 5232 | switch (fw_event->event) { |
| 5233 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
| 5234 | _scsih_sas_topology_change_event(ioc, fw_event->VF_ID, |
| 5235 | fw_event->event_data, fw_event); |
| 5236 | break; |
| 5237 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 5238 | _scsih_sas_device_status_change_event(ioc, fw_event->VF_ID, |
| 5239 | fw_event->event_data); |
| 5240 | break; |
| 5241 | case MPI2_EVENT_SAS_DISCOVERY: |
| 5242 | _scsih_sas_discovery_event(ioc, fw_event->VF_ID, |
| 5243 | fw_event->event_data); |
| 5244 | break; |
| 5245 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 5246 | _scsih_sas_broadcast_primative_event(ioc, fw_event->VF_ID, |
| 5247 | fw_event->event_data); |
| 5248 | break; |
| 5249 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
| 5250 | _scsih_sas_enclosure_dev_status_change_event(ioc, |
| 5251 | fw_event->VF_ID, fw_event->event_data); |
| 5252 | break; |
| 5253 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
| 5254 | _scsih_sas_ir_config_change_event(ioc, fw_event->VF_ID, |
| 5255 | fw_event->event_data); |
| 5256 | break; |
| 5257 | case MPI2_EVENT_IR_VOLUME: |
| 5258 | _scsih_sas_ir_volume_event(ioc, fw_event->VF_ID, |
| 5259 | fw_event->event_data); |
| 5260 | break; |
| 5261 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
| 5262 | _scsih_sas_ir_physical_disk_event(ioc, fw_event->VF_ID, |
| 5263 | fw_event->event_data); |
| 5264 | break; |
| 5265 | case MPI2_EVENT_IR_OPERATION_STATUS: |
| 5266 | _scsih_sas_ir_operation_status_event(ioc, fw_event->VF_ID, |
| 5267 | fw_event->event_data); |
| 5268 | break; |
| 5269 | case MPI2_EVENT_TASK_SET_FULL: |
| 5270 | _scsih_task_set_full(ioc, fw_event->VF_ID, |
| 5271 | fw_event->event_data); |
| 5272 | break; |
| 5273 | } |
| 5274 | _scsih_fw_event_free(ioc, fw_event); |
| 5275 | } |
| 5276 | |
| 5277 | /** |
| 5278 | * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time) |
| 5279 | * @ioc: per adapter object |
| 5280 | * @VF_ID: virtual function id |
| 5281 | * @reply: reply message frame(lower 32bit addr) |
| 5282 | * Context: interrupt. |
| 5283 | * |
| 5284 | * This function merely adds a new work task into ioc->firmware_event_thread. |
| 5285 | * The tasks are worked from _firmware_event_work in user context. |
| 5286 | * |
| 5287 | * Return nothing. |
| 5288 | */ |
| 5289 | void |
| 5290 | mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, u32 reply) |
| 5291 | { |
| 5292 | struct fw_event_work *fw_event; |
| 5293 | Mpi2EventNotificationReply_t *mpi_reply; |
| 5294 | unsigned long flags; |
| 5295 | u16 event; |
| 5296 | |
| 5297 | /* events turned off due to host reset or driver unloading */ |
| 5298 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 5299 | if (ioc->fw_events_off || ioc->remove_host) { |
| 5300 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 5301 | return; |
| 5302 | } |
| 5303 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 5304 | |
| 5305 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 5306 | event = le16_to_cpu(mpi_reply->Event); |
| 5307 | |
| 5308 | switch (event) { |
| 5309 | /* handle these */ |
| 5310 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 5311 | { |
| 5312 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = |
| 5313 | (Mpi2EventDataSasBroadcastPrimitive_t *) |
| 5314 | mpi_reply->EventData; |
| 5315 | |
| 5316 | if (baen_data->Primitive != |
| 5317 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT || |
| 5318 | ioc->broadcast_aen_busy) |
| 5319 | return; |
| 5320 | ioc->broadcast_aen_busy = 1; |
| 5321 | break; |
| 5322 | } |
| 5323 | |
| 5324 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
| 5325 | _scsih_check_topo_delete_events(ioc, |
| 5326 | (Mpi2EventDataSasTopologyChangeList_t *) |
| 5327 | mpi_reply->EventData); |
| 5328 | break; |
| 5329 | |
| 5330 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 5331 | case MPI2_EVENT_IR_OPERATION_STATUS: |
| 5332 | case MPI2_EVENT_SAS_DISCOVERY: |
| 5333 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
| 5334 | case MPI2_EVENT_IR_VOLUME: |
| 5335 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
| 5336 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
| 5337 | case MPI2_EVENT_TASK_SET_FULL: |
| 5338 | break; |
| 5339 | |
| 5340 | default: /* ignore the rest */ |
| 5341 | return; |
| 5342 | } |
| 5343 | |
| 5344 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 5345 | if (!fw_event) { |
| 5346 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5347 | ioc->name, __FILE__, __LINE__, __func__); |
| 5348 | return; |
| 5349 | } |
| 5350 | fw_event->event_data = |
| 5351 | kzalloc(mpi_reply->EventDataLength*4, GFP_ATOMIC); |
| 5352 | if (!fw_event->event_data) { |
| 5353 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5354 | ioc->name, __FILE__, __LINE__, __func__); |
| 5355 | kfree(fw_event); |
| 5356 | return; |
| 5357 | } |
| 5358 | |
| 5359 | memcpy(fw_event->event_data, mpi_reply->EventData, |
| 5360 | mpi_reply->EventDataLength*4); |
| 5361 | fw_event->ioc = ioc; |
| 5362 | fw_event->VF_ID = VF_ID; |
| 5363 | fw_event->event = event; |
| 5364 | _scsih_fw_event_add(ioc, fw_event); |
| 5365 | } |
| 5366 | |
| 5367 | /* shost template */ |
| 5368 | static struct scsi_host_template scsih_driver_template = { |
| 5369 | .module = THIS_MODULE, |
| 5370 | .name = "Fusion MPT SAS Host", |
| 5371 | .proc_name = MPT2SAS_DRIVER_NAME, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5372 | .queuecommand = _scsih_qcmd, |
| 5373 | .target_alloc = _scsih_target_alloc, |
| 5374 | .slave_alloc = _scsih_slave_alloc, |
| 5375 | .slave_configure = _scsih_slave_configure, |
| 5376 | .target_destroy = _scsih_target_destroy, |
| 5377 | .slave_destroy = _scsih_slave_destroy, |
| 5378 | .change_queue_depth = _scsih_change_queue_depth, |
| 5379 | .change_queue_type = _scsih_change_queue_type, |
| 5380 | .eh_abort_handler = _scsih_abort, |
| 5381 | .eh_device_reset_handler = _scsih_dev_reset, |
| 5382 | .eh_target_reset_handler = _scsih_target_reset, |
| 5383 | .eh_host_reset_handler = _scsih_host_reset, |
| 5384 | .bios_param = _scsih_bios_param, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5385 | .can_queue = 1, |
| 5386 | .this_id = -1, |
| 5387 | .sg_tablesize = MPT2SAS_SG_DEPTH, |
| 5388 | .max_sectors = 8192, |
| 5389 | .cmd_per_lun = 7, |
| 5390 | .use_clustering = ENABLE_CLUSTERING, |
| 5391 | .shost_attrs = mpt2sas_host_attrs, |
| 5392 | .sdev_attrs = mpt2sas_dev_attrs, |
| 5393 | }; |
| 5394 | |
| 5395 | /** |
| 5396 | * _scsih_expander_node_remove - removing expander device from list. |
| 5397 | * @ioc: per adapter object |
| 5398 | * @sas_expander: the sas_device object |
| 5399 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 5400 | * |
| 5401 | * Removing object and freeing associated memory from the |
| 5402 | * ioc->sas_expander_list. |
| 5403 | * |
| 5404 | * Return nothing. |
| 5405 | */ |
| 5406 | static void |
| 5407 | _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc, |
| 5408 | struct _sas_node *sas_expander) |
| 5409 | { |
| 5410 | struct _sas_port *mpt2sas_port; |
| 5411 | struct _sas_device *sas_device; |
| 5412 | struct _sas_node *expander_sibling; |
| 5413 | unsigned long flags; |
| 5414 | |
| 5415 | if (!sas_expander) |
| 5416 | return; |
| 5417 | |
| 5418 | /* remove sibling ports attached to this expander */ |
| 5419 | retry_device_search: |
| 5420 | list_for_each_entry(mpt2sas_port, |
| 5421 | &sas_expander->sas_port_list, port_list) { |
| 5422 | if (mpt2sas_port->remote_identify.device_type == |
| 5423 | SAS_END_DEVICE) { |
| 5424 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5425 | sas_device = |
| 5426 | mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5427 | mpt2sas_port->remote_identify.sas_address); |
| 5428 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5429 | if (!sas_device) |
| 5430 | continue; |
| 5431 | _scsih_remove_device(ioc, sas_device->handle); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame^] | 5432 | if (ioc->shost_recovery) |
| 5433 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5434 | goto retry_device_search; |
| 5435 | } |
| 5436 | } |
| 5437 | |
| 5438 | retry_expander_search: |
| 5439 | list_for_each_entry(mpt2sas_port, |
| 5440 | &sas_expander->sas_port_list, port_list) { |
| 5441 | |
| 5442 | if (mpt2sas_port->remote_identify.device_type == |
| 5443 | MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER || |
| 5444 | mpt2sas_port->remote_identify.device_type == |
| 5445 | MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) { |
| 5446 | |
| 5447 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 5448 | expander_sibling = |
| 5449 | mpt2sas_scsih_expander_find_by_sas_address( |
| 5450 | ioc, mpt2sas_port->remote_identify.sas_address); |
| 5451 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 5452 | if (!expander_sibling) |
| 5453 | continue; |
| 5454 | _scsih_expander_remove(ioc, expander_sibling->handle); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame^] | 5455 | if (ioc->shost_recovery) |
| 5456 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5457 | goto retry_expander_search; |
| 5458 | } |
| 5459 | } |
| 5460 | |
| 5461 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
| 5462 | sas_expander->parent_handle); |
| 5463 | |
| 5464 | printk(MPT2SAS_INFO_FMT "expander_remove: handle" |
| 5465 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, |
| 5466 | sas_expander->handle, (unsigned long long) |
| 5467 | sas_expander->sas_address); |
| 5468 | |
| 5469 | list_del(&sas_expander->list); |
| 5470 | kfree(sas_expander->phy); |
| 5471 | kfree(sas_expander); |
| 5472 | } |
| 5473 | |
| 5474 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5475 | * _scsih_remove - detach and remove add host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5476 | * @pdev: PCI device struct |
| 5477 | * |
| 5478 | * Return nothing. |
| 5479 | */ |
| 5480 | static void __devexit |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5481 | _scsih_remove(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5482 | { |
| 5483 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 5484 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 5485 | struct _sas_port *mpt2sas_port; |
| 5486 | struct _sas_device *sas_device; |
| 5487 | struct _sas_node *expander_sibling; |
| 5488 | struct workqueue_struct *wq; |
| 5489 | unsigned long flags; |
| 5490 | |
| 5491 | ioc->remove_host = 1; |
| 5492 | _scsih_fw_event_off(ioc); |
| 5493 | |
| 5494 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 5495 | wq = ioc->firmware_event_thread; |
| 5496 | ioc->firmware_event_thread = NULL; |
| 5497 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 5498 | if (wq) |
| 5499 | destroy_workqueue(wq); |
| 5500 | |
| 5501 | /* free ports attached to the sas_host */ |
| 5502 | retry_again: |
| 5503 | list_for_each_entry(mpt2sas_port, |
| 5504 | &ioc->sas_hba.sas_port_list, port_list) { |
| 5505 | if (mpt2sas_port->remote_identify.device_type == |
| 5506 | SAS_END_DEVICE) { |
| 5507 | sas_device = |
| 5508 | mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5509 | mpt2sas_port->remote_identify.sas_address); |
| 5510 | if (sas_device) { |
| 5511 | _scsih_remove_device(ioc, sas_device->handle); |
| 5512 | goto retry_again; |
| 5513 | } |
| 5514 | } else { |
| 5515 | expander_sibling = |
| 5516 | mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 5517 | mpt2sas_port->remote_identify.sas_address); |
| 5518 | if (expander_sibling) { |
| 5519 | _scsih_expander_remove(ioc, |
| 5520 | expander_sibling->handle); |
| 5521 | goto retry_again; |
| 5522 | } |
| 5523 | } |
| 5524 | } |
| 5525 | |
| 5526 | /* free phys attached to the sas_host */ |
| 5527 | if (ioc->sas_hba.num_phys) { |
| 5528 | kfree(ioc->sas_hba.phy); |
| 5529 | ioc->sas_hba.phy = NULL; |
| 5530 | ioc->sas_hba.num_phys = 0; |
| 5531 | } |
| 5532 | |
| 5533 | sas_remove_host(shost); |
| 5534 | mpt2sas_base_detach(ioc); |
| 5535 | list_del(&ioc->list); |
| 5536 | scsi_remove_host(shost); |
| 5537 | scsi_host_put(shost); |
| 5538 | } |
| 5539 | |
| 5540 | /** |
| 5541 | * _scsih_probe_boot_devices - reports 1st device |
| 5542 | * @ioc: per adapter object |
| 5543 | * |
| 5544 | * If specified in bios page 2, this routine reports the 1st |
| 5545 | * device scsi-ml or sas transport for persistent boot device |
| 5546 | * purposes. Please refer to function _scsih_determine_boot_device() |
| 5547 | */ |
| 5548 | static void |
| 5549 | _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc) |
| 5550 | { |
| 5551 | u8 is_raid; |
| 5552 | void *device; |
| 5553 | struct _sas_device *sas_device; |
| 5554 | struct _raid_device *raid_device; |
| 5555 | u16 handle, parent_handle; |
| 5556 | u64 sas_address; |
| 5557 | unsigned long flags; |
| 5558 | int rc; |
| 5559 | |
| 5560 | device = NULL; |
| 5561 | if (ioc->req_boot_device.device) { |
| 5562 | device = ioc->req_boot_device.device; |
| 5563 | is_raid = ioc->req_boot_device.is_raid; |
| 5564 | } else if (ioc->req_alt_boot_device.device) { |
| 5565 | device = ioc->req_alt_boot_device.device; |
| 5566 | is_raid = ioc->req_alt_boot_device.is_raid; |
| 5567 | } else if (ioc->current_boot_device.device) { |
| 5568 | device = ioc->current_boot_device.device; |
| 5569 | is_raid = ioc->current_boot_device.is_raid; |
| 5570 | } |
| 5571 | |
| 5572 | if (!device) |
| 5573 | return; |
| 5574 | |
| 5575 | if (is_raid) { |
| 5576 | raid_device = device; |
| 5577 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 5578 | raid_device->id, 0); |
| 5579 | if (rc) |
| 5580 | _scsih_raid_device_remove(ioc, raid_device); |
| 5581 | } else { |
| 5582 | sas_device = device; |
| 5583 | handle = sas_device->handle; |
| 5584 | parent_handle = sas_device->parent_handle; |
| 5585 | sas_address = sas_device->sas_address; |
| 5586 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5587 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 5588 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5589 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
| 5590 | sas_device->parent_handle)) { |
| 5591 | _scsih_sas_device_remove(ioc, sas_device); |
| 5592 | } else if (!sas_device->starget) { |
| 5593 | mpt2sas_transport_port_remove(ioc, sas_address, |
| 5594 | parent_handle); |
| 5595 | _scsih_sas_device_remove(ioc, sas_device); |
| 5596 | } |
| 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | /** |
| 5601 | * _scsih_probe_raid - reporting raid volumes to scsi-ml |
| 5602 | * @ioc: per adapter object |
| 5603 | * |
| 5604 | * Called during initial loading of the driver. |
| 5605 | */ |
| 5606 | static void |
| 5607 | _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc) |
| 5608 | { |
| 5609 | struct _raid_device *raid_device, *raid_next; |
| 5610 | int rc; |
| 5611 | |
| 5612 | list_for_each_entry_safe(raid_device, raid_next, |
| 5613 | &ioc->raid_device_list, list) { |
| 5614 | if (raid_device->starget) |
| 5615 | continue; |
| 5616 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 5617 | raid_device->id, 0); |
| 5618 | if (rc) |
| 5619 | _scsih_raid_device_remove(ioc, raid_device); |
| 5620 | } |
| 5621 | } |
| 5622 | |
| 5623 | /** |
| 5624 | * _scsih_probe_sas - reporting raid volumes to sas transport |
| 5625 | * @ioc: per adapter object |
| 5626 | * |
| 5627 | * Called during initial loading of the driver. |
| 5628 | */ |
| 5629 | static void |
| 5630 | _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc) |
| 5631 | { |
| 5632 | struct _sas_device *sas_device, *next; |
| 5633 | unsigned long flags; |
| 5634 | u16 handle, parent_handle; |
| 5635 | u64 sas_address; |
| 5636 | |
| 5637 | /* SAS Device List */ |
| 5638 | list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list, |
| 5639 | list) { |
| 5640 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5641 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 5642 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5643 | |
| 5644 | handle = sas_device->handle; |
| 5645 | parent_handle = sas_device->parent_handle; |
| 5646 | sas_address = sas_device->sas_address; |
| 5647 | if (!mpt2sas_transport_port_add(ioc, handle, parent_handle)) { |
| 5648 | _scsih_sas_device_remove(ioc, sas_device); |
| 5649 | } else if (!sas_device->starget) { |
| 5650 | mpt2sas_transport_port_remove(ioc, sas_address, |
| 5651 | parent_handle); |
| 5652 | _scsih_sas_device_remove(ioc, sas_device); |
| 5653 | } |
| 5654 | } |
| 5655 | } |
| 5656 | |
| 5657 | /** |
| 5658 | * _scsih_probe_devices - probing for devices |
| 5659 | * @ioc: per adapter object |
| 5660 | * |
| 5661 | * Called during initial loading of the driver. |
| 5662 | */ |
| 5663 | static void |
| 5664 | _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc) |
| 5665 | { |
| 5666 | u16 volume_mapping_flags = |
| 5667 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & |
| 5668 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; |
| 5669 | |
| 5670 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) |
| 5671 | return; /* return when IOC doesn't support initiator mode */ |
| 5672 | |
| 5673 | _scsih_probe_boot_devices(ioc); |
| 5674 | |
| 5675 | if (ioc->ir_firmware) { |
| 5676 | if ((volume_mapping_flags & |
| 5677 | MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING)) { |
| 5678 | _scsih_probe_sas(ioc); |
| 5679 | _scsih_probe_raid(ioc); |
| 5680 | } else { |
| 5681 | _scsih_probe_raid(ioc); |
| 5682 | _scsih_probe_sas(ioc); |
| 5683 | } |
| 5684 | } else |
| 5685 | _scsih_probe_sas(ioc); |
| 5686 | } |
| 5687 | |
| 5688 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5689 | * _scsih_probe - attach and add scsi host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5690 | * @pdev: PCI device struct |
| 5691 | * @id: pci device id |
| 5692 | * |
| 5693 | * Returns 0 success, anything else error. |
| 5694 | */ |
| 5695 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5696 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5697 | { |
| 5698 | struct MPT2SAS_ADAPTER *ioc; |
| 5699 | struct Scsi_Host *shost; |
| 5700 | |
| 5701 | shost = scsi_host_alloc(&scsih_driver_template, |
| 5702 | sizeof(struct MPT2SAS_ADAPTER)); |
| 5703 | if (!shost) |
| 5704 | return -ENODEV; |
| 5705 | |
| 5706 | /* init local params */ |
| 5707 | ioc = shost_priv(shost); |
| 5708 | memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER)); |
| 5709 | INIT_LIST_HEAD(&ioc->list); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 5710 | list_add_tail(&ioc->list, &mpt2sas_ioc_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5711 | ioc->shost = shost; |
| 5712 | ioc->id = mpt_ids++; |
| 5713 | sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id); |
| 5714 | ioc->pdev = pdev; |
| 5715 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; |
| 5716 | ioc->tm_cb_idx = tm_cb_idx; |
| 5717 | ioc->ctl_cb_idx = ctl_cb_idx; |
| 5718 | ioc->base_cb_idx = base_cb_idx; |
| 5719 | ioc->transport_cb_idx = transport_cb_idx; |
| 5720 | ioc->config_cb_idx = config_cb_idx; |
| 5721 | ioc->logging_level = logging_level; |
| 5722 | /* misc semaphores and spin locks */ |
| 5723 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
| 5724 | spin_lock_init(&ioc->scsi_lookup_lock); |
| 5725 | spin_lock_init(&ioc->sas_device_lock); |
| 5726 | spin_lock_init(&ioc->sas_node_lock); |
| 5727 | spin_lock_init(&ioc->fw_event_lock); |
| 5728 | spin_lock_init(&ioc->raid_device_lock); |
| 5729 | |
| 5730 | INIT_LIST_HEAD(&ioc->sas_device_list); |
| 5731 | INIT_LIST_HEAD(&ioc->sas_device_init_list); |
| 5732 | INIT_LIST_HEAD(&ioc->sas_expander_list); |
| 5733 | INIT_LIST_HEAD(&ioc->fw_event_list); |
| 5734 | INIT_LIST_HEAD(&ioc->raid_device_list); |
| 5735 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); |
| 5736 | |
| 5737 | /* init shost parameters */ |
| 5738 | shost->max_cmd_len = 16; |
| 5739 | shost->max_lun = max_lun; |
| 5740 | shost->transportt = mpt2sas_transport_template; |
| 5741 | shost->unique_id = ioc->id; |
| 5742 | |
| 5743 | if ((scsi_add_host(shost, &pdev->dev))) { |
| 5744 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5745 | ioc->name, __FILE__, __LINE__, __func__); |
| 5746 | list_del(&ioc->list); |
| 5747 | goto out_add_shost_fail; |
| 5748 | } |
| 5749 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 5750 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION |
| 5751 | | SHOST_DIF_TYPE3_PROTECTION); |
| 5752 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5753 | /* event thread */ |
| 5754 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), |
| 5755 | "fw_event%d", ioc->id); |
| 5756 | ioc->firmware_event_thread = create_singlethread_workqueue( |
| 5757 | ioc->firmware_event_name); |
| 5758 | if (!ioc->firmware_event_thread) { |
| 5759 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5760 | ioc->name, __FILE__, __LINE__, __func__); |
| 5761 | goto out_thread_fail; |
| 5762 | } |
| 5763 | |
| 5764 | ioc->wait_for_port_enable_to_complete = 1; |
| 5765 | if ((mpt2sas_base_attach(ioc))) { |
| 5766 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5767 | ioc->name, __FILE__, __LINE__, __func__); |
| 5768 | goto out_attach_fail; |
| 5769 | } |
| 5770 | |
| 5771 | ioc->wait_for_port_enable_to_complete = 0; |
| 5772 | _scsih_probe_devices(ioc); |
| 5773 | return 0; |
| 5774 | |
| 5775 | out_attach_fail: |
| 5776 | destroy_workqueue(ioc->firmware_event_thread); |
| 5777 | out_thread_fail: |
| 5778 | list_del(&ioc->list); |
| 5779 | scsi_remove_host(shost); |
| 5780 | out_add_shost_fail: |
| 5781 | return -ENODEV; |
| 5782 | } |
| 5783 | |
| 5784 | #ifdef CONFIG_PM |
| 5785 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5786 | * _scsih_suspend - power management suspend main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5787 | * @pdev: PCI device struct |
| 5788 | * @state: PM state change to (usually PCI_D3) |
| 5789 | * |
| 5790 | * Returns 0 success, anything else error. |
| 5791 | */ |
| 5792 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5793 | _scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5794 | { |
| 5795 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 5796 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 5797 | u32 device_state; |
| 5798 | |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 5799 | mpt2sas_base_stop_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5800 | flush_scheduled_work(); |
| 5801 | scsi_block_requests(shost); |
| 5802 | device_state = pci_choose_state(pdev, state); |
| 5803 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering " |
| 5804 | "operating state [D%d]\n", ioc->name, pdev, |
| 5805 | pci_name(pdev), device_state); |
| 5806 | |
| 5807 | mpt2sas_base_free_resources(ioc); |
| 5808 | pci_save_state(pdev); |
| 5809 | pci_disable_device(pdev); |
| 5810 | pci_set_power_state(pdev, device_state); |
| 5811 | return 0; |
| 5812 | } |
| 5813 | |
| 5814 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5815 | * _scsih_resume - power management resume main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5816 | * @pdev: PCI device struct |
| 5817 | * |
| 5818 | * Returns 0 success, anything else error. |
| 5819 | */ |
| 5820 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5821 | _scsih_resume(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5822 | { |
| 5823 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 5824 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 5825 | u32 device_state = pdev->current_state; |
| 5826 | int r; |
| 5827 | |
| 5828 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous " |
| 5829 | "operating state [D%d]\n", ioc->name, pdev, |
| 5830 | pci_name(pdev), device_state); |
| 5831 | |
| 5832 | pci_set_power_state(pdev, PCI_D0); |
| 5833 | pci_enable_wake(pdev, PCI_D0, 0); |
| 5834 | pci_restore_state(pdev); |
| 5835 | ioc->pdev = pdev; |
| 5836 | r = mpt2sas_base_map_resources(ioc); |
| 5837 | if (r) |
| 5838 | return r; |
| 5839 | |
| 5840 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET); |
| 5841 | scsi_unblock_requests(shost); |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 5842 | mpt2sas_base_start_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5843 | return 0; |
| 5844 | } |
| 5845 | #endif /* CONFIG_PM */ |
| 5846 | |
| 5847 | |
| 5848 | static struct pci_driver scsih_driver = { |
| 5849 | .name = MPT2SAS_DRIVER_NAME, |
| 5850 | .id_table = scsih_pci_table, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5851 | .probe = _scsih_probe, |
| 5852 | .remove = __devexit_p(_scsih_remove), |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5853 | #ifdef CONFIG_PM |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5854 | .suspend = _scsih_suspend, |
| 5855 | .resume = _scsih_resume, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5856 | #endif |
| 5857 | }; |
| 5858 | |
| 5859 | |
| 5860 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5861 | * _scsih_init - main entry point for this driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5862 | * |
| 5863 | * Returns 0 success, anything else error. |
| 5864 | */ |
| 5865 | static int __init |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5866 | _scsih_init(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5867 | { |
| 5868 | int error; |
| 5869 | |
| 5870 | mpt_ids = 0; |
| 5871 | printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME, |
| 5872 | MPT2SAS_DRIVER_VERSION); |
| 5873 | |
| 5874 | mpt2sas_transport_template = |
| 5875 | sas_attach_transport(&mpt2sas_transport_functions); |
| 5876 | if (!mpt2sas_transport_template) |
| 5877 | return -ENODEV; |
| 5878 | |
| 5879 | mpt2sas_base_initialize_callback_handler(); |
| 5880 | |
| 5881 | /* queuecommand callback hander */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5882 | scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5883 | |
| 5884 | /* task managment callback handler */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5885 | tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5886 | |
| 5887 | /* base internal commands callback handler */ |
| 5888 | base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done); |
| 5889 | |
| 5890 | /* transport internal commands callback handler */ |
| 5891 | transport_cb_idx = mpt2sas_base_register_callback_handler( |
| 5892 | mpt2sas_transport_done); |
| 5893 | |
| 5894 | /* configuration page API internal commands callback handler */ |
| 5895 | config_cb_idx = mpt2sas_base_register_callback_handler( |
| 5896 | mpt2sas_config_done); |
| 5897 | |
| 5898 | /* ctl module callback handler */ |
| 5899 | ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done); |
| 5900 | |
| 5901 | mpt2sas_ctl_init(); |
| 5902 | |
| 5903 | error = pci_register_driver(&scsih_driver); |
| 5904 | if (error) |
| 5905 | sas_release_transport(mpt2sas_transport_template); |
| 5906 | |
| 5907 | return error; |
| 5908 | } |
| 5909 | |
| 5910 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5911 | * _scsih_exit - exit point for this driver (when it is a module). |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5912 | * |
| 5913 | * Returns 0 success, anything else error. |
| 5914 | */ |
| 5915 | static void __exit |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5916 | _scsih_exit(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5917 | { |
| 5918 | printk(KERN_INFO "mpt2sas version %s unloading\n", |
| 5919 | MPT2SAS_DRIVER_VERSION); |
| 5920 | |
| 5921 | pci_unregister_driver(&scsih_driver); |
| 5922 | |
| 5923 | sas_release_transport(mpt2sas_transport_template); |
| 5924 | mpt2sas_base_release_callback_handler(scsi_io_cb_idx); |
| 5925 | mpt2sas_base_release_callback_handler(tm_cb_idx); |
| 5926 | mpt2sas_base_release_callback_handler(base_cb_idx); |
| 5927 | mpt2sas_base_release_callback_handler(transport_cb_idx); |
| 5928 | mpt2sas_base_release_callback_handler(config_cb_idx); |
| 5929 | mpt2sas_base_release_callback_handler(ctl_cb_idx); |
| 5930 | |
| 5931 | mpt2sas_ctl_exit(); |
| 5932 | } |
| 5933 | |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 5934 | module_init(_scsih_init); |
| 5935 | module_exit(_scsih_exit); |