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