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