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