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