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