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 | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame^] | 116 | #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC) |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 117 | #define MPT2SAS_RESCAN_AFTER_HOST_RESET (0xFFFF) |
| 118 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 119 | /** |
| 120 | * struct fw_event_work - firmware event struct |
| 121 | * @list: link list framework |
| 122 | * @work: work object (ioc->fault_reset_work_q) |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 123 | * @cancel_pending_work: flag set during reset handling |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 124 | * @ioc: per adapter object |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame^] | 125 | * @device_handle: device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 126 | * @VF_ID: virtual function id |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 127 | * @VP_ID: virtual port id |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 128 | * @ignore: flag meaning this event has been marked to ignore |
| 129 | * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h |
| 130 | * @event_data: reply event data payload follows |
| 131 | * |
| 132 | * This object stored on ioc->fw_event_list. |
| 133 | */ |
| 134 | struct fw_event_work { |
| 135 | struct list_head list; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 136 | u8 cancel_pending_work; |
| 137 | struct delayed_work delayed_work; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 138 | struct MPT2SAS_ADAPTER *ioc; |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame^] | 139 | u16 device_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 140 | u8 VF_ID; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 141 | u8 VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 142 | u8 ignore; |
| 143 | u16 event; |
| 144 | void *event_data; |
| 145 | }; |
| 146 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 147 | /* raid transport support */ |
| 148 | static struct raid_template *mpt2sas_raid_template; |
| 149 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 150 | /** |
| 151 | * struct _scsi_io_transfer - scsi io transfer |
| 152 | * @handle: sas device handle (assigned by firmware) |
| 153 | * @is_raid: flag set for hidden raid components |
| 154 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, |
| 155 | * @data_length: data transfer length |
| 156 | * @data_dma: dma pointer to data |
| 157 | * @sense: sense data |
| 158 | * @lun: lun number |
| 159 | * @cdb_length: cdb length |
| 160 | * @cdb: cdb contents |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 161 | * @timeout: timeout for this command |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 162 | * @VF_ID: virtual function id |
| 163 | * @VP_ID: virtual port id |
| 164 | * @valid_reply: flag set for reply message |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 165 | * @sense_length: sense length |
| 166 | * @ioc_status: ioc status |
| 167 | * @scsi_state: scsi state |
| 168 | * @scsi_status: scsi staus |
| 169 | * @log_info: log information |
| 170 | * @transfer_length: data length transfer when there is a reply message |
| 171 | * |
| 172 | * Used for sending internal scsi commands to devices within this module. |
| 173 | * Refer to _scsi_send_scsi_io(). |
| 174 | */ |
| 175 | struct _scsi_io_transfer { |
| 176 | u16 handle; |
| 177 | u8 is_raid; |
| 178 | enum dma_data_direction dir; |
| 179 | u32 data_length; |
| 180 | dma_addr_t data_dma; |
| 181 | u8 sense[SCSI_SENSE_BUFFERSIZE]; |
| 182 | u32 lun; |
| 183 | u8 cdb_length; |
| 184 | u8 cdb[32]; |
| 185 | u8 timeout; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 186 | u8 VF_ID; |
| 187 | u8 VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 188 | u8 valid_reply; |
| 189 | /* the following bits are only valid when 'valid_reply = 1' */ |
| 190 | u32 sense_length; |
| 191 | u16 ioc_status; |
| 192 | u8 scsi_state; |
| 193 | u8 scsi_status; |
| 194 | u32 log_info; |
| 195 | u32 transfer_length; |
| 196 | }; |
| 197 | |
| 198 | /* |
| 199 | * The pci device ids are defined in mpi/mpi2_cnfg.h. |
| 200 | */ |
| 201 | static struct pci_device_id scsih_pci_table[] = { |
| 202 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, |
| 203 | PCI_ANY_ID, PCI_ANY_ID }, |
| 204 | /* Falcon ~ 2008*/ |
| 205 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, |
| 206 | PCI_ANY_ID, PCI_ANY_ID }, |
| 207 | /* Liberator ~ 2108 */ |
| 208 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, |
| 209 | PCI_ANY_ID, PCI_ANY_ID }, |
| 210 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, |
| 211 | PCI_ANY_ID, PCI_ANY_ID }, |
| 212 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, |
| 213 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 214 | /* Meteor ~ 2116 */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 215 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, |
| 216 | PCI_ANY_ID, PCI_ANY_ID }, |
| 217 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, |
| 218 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 219 | /* Thunderbolt ~ 2208 */ |
| 220 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, |
| 221 | PCI_ANY_ID, PCI_ANY_ID }, |
| 222 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, |
| 223 | PCI_ANY_ID, PCI_ANY_ID }, |
| 224 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, |
| 225 | PCI_ANY_ID, PCI_ANY_ID }, |
| 226 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, |
| 227 | PCI_ANY_ID, PCI_ANY_ID }, |
| 228 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, |
| 229 | PCI_ANY_ID, PCI_ANY_ID }, |
| 230 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, |
| 231 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 203d65b | 2010-06-17 13:37:59 +0530 | [diff] [blame] | 232 | /* Mustang ~ 2308 */ |
| 233 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 234 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 203d65b | 2010-06-17 13:37:59 +0530 | [diff] [blame] | 235 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, |
| 236 | PCI_ANY_ID, PCI_ANY_ID }, |
| 237 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 238 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 239 | /* SSS6200 */ |
| 240 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, |
| 241 | PCI_ANY_ID, PCI_ANY_ID }, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 242 | {0} /* Terminating entry */ |
| 243 | }; |
| 244 | MODULE_DEVICE_TABLE(pci, scsih_pci_table); |
| 245 | |
| 246 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 247 | * _scsih_set_debug_level - global setting of ioc->logging_level. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 248 | * |
| 249 | * Note: The logging levels are defined in mpt2sas_debug.h. |
| 250 | */ |
| 251 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 252 | _scsih_set_debug_level(const char *val, struct kernel_param *kp) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 253 | { |
| 254 | int ret = param_set_int(val, kp); |
| 255 | struct MPT2SAS_ADAPTER *ioc; |
| 256 | |
| 257 | if (ret) |
| 258 | return ret; |
| 259 | |
| 260 | printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 261 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 262 | ioc->logging_level = logging_level; |
| 263 | return 0; |
| 264 | } |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 265 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 266 | &logging_level, 0644); |
| 267 | |
| 268 | /** |
| 269 | * _scsih_srch_boot_sas_address - search based on sas_address |
| 270 | * @sas_address: sas address |
| 271 | * @boot_device: boot device object from bios page 2 |
| 272 | * |
| 273 | * Returns 1 when there's a match, 0 means no match. |
| 274 | */ |
| 275 | static inline int |
| 276 | _scsih_srch_boot_sas_address(u64 sas_address, |
| 277 | Mpi2BootDeviceSasWwid_t *boot_device) |
| 278 | { |
| 279 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * _scsih_srch_boot_device_name - search based on device name |
| 284 | * @device_name: device name specified in INDENTIFY fram |
| 285 | * @boot_device: boot device object from bios page 2 |
| 286 | * |
| 287 | * Returns 1 when there's a match, 0 means no match. |
| 288 | */ |
| 289 | static inline int |
| 290 | _scsih_srch_boot_device_name(u64 device_name, |
| 291 | Mpi2BootDeviceDeviceName_t *boot_device) |
| 292 | { |
| 293 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot |
| 298 | * @enclosure_logical_id: enclosure logical id |
| 299 | * @slot_number: slot number |
| 300 | * @boot_device: boot device object from bios page 2 |
| 301 | * |
| 302 | * Returns 1 when there's a match, 0 means no match. |
| 303 | */ |
| 304 | static inline int |
| 305 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, |
| 306 | Mpi2BootDeviceEnclosureSlot_t *boot_device) |
| 307 | { |
| 308 | return (enclosure_logical_id == le64_to_cpu(boot_device-> |
| 309 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> |
| 310 | SlotNumber)) ? 1 : 0; |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * _scsih_is_boot_device - search for matching boot device. |
| 315 | * @sas_address: sas address |
| 316 | * @device_name: device name specified in INDENTIFY fram |
| 317 | * @enclosure_logical_id: enclosure logical id |
| 318 | * @slot_number: slot number |
| 319 | * @form: specifies boot device form |
| 320 | * @boot_device: boot device object from bios page 2 |
| 321 | * |
| 322 | * Returns 1 when there's a match, 0 means no match. |
| 323 | */ |
| 324 | static int |
| 325 | _scsih_is_boot_device(u64 sas_address, u64 device_name, |
| 326 | u64 enclosure_logical_id, u16 slot, u8 form, |
| 327 | Mpi2BiosPage2BootDevice_t *boot_device) |
| 328 | { |
| 329 | int rc = 0; |
| 330 | |
| 331 | switch (form) { |
| 332 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: |
| 333 | if (!sas_address) |
| 334 | break; |
| 335 | rc = _scsih_srch_boot_sas_address( |
| 336 | sas_address, &boot_device->SasWwid); |
| 337 | break; |
| 338 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: |
| 339 | if (!enclosure_logical_id) |
| 340 | break; |
| 341 | rc = _scsih_srch_boot_encl_slot( |
| 342 | enclosure_logical_id, |
| 343 | slot, &boot_device->EnclosureSlot); |
| 344 | break; |
| 345 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: |
| 346 | if (!device_name) |
| 347 | break; |
| 348 | rc = _scsih_srch_boot_device_name( |
| 349 | device_name, &boot_device->DeviceName); |
| 350 | break; |
| 351 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: |
| 352 | break; |
| 353 | } |
| 354 | |
| 355 | return rc; |
| 356 | } |
| 357 | |
| 358 | /** |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 359 | * _scsih_get_sas_address - set the sas_address for given device handle |
| 360 | * @handle: device handle |
| 361 | * @sas_address: sas address |
| 362 | * |
| 363 | * Returns 0 success, non-zero when failure |
| 364 | */ |
| 365 | static int |
| 366 | _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle, |
| 367 | u64 *sas_address) |
| 368 | { |
| 369 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 370 | Mpi2ConfigReply_t mpi_reply; |
| 371 | u32 ioc_status; |
| 372 | |
| 373 | if (handle <= ioc->sas_hba.num_phys) { |
| 374 | *sas_address = ioc->sas_hba.sas_address; |
| 375 | return 0; |
| 376 | } else |
| 377 | *sas_address = 0; |
| 378 | |
| 379 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 380 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 381 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 382 | ioc->name, __FILE__, __LINE__, __func__); |
| 383 | return -ENXIO; |
| 384 | } |
| 385 | |
| 386 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 387 | MPI2_IOCSTATUS_MASK; |
| 388 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 389 | printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x)" |
| 390 | "\nfailure at %s:%d/%s()!\n", ioc->name, handle, ioc_status, |
| 391 | __FILE__, __LINE__, __func__); |
| 392 | return -EIO; |
| 393 | } |
| 394 | |
| 395 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 400 | * _scsih_determine_boot_device - determine boot device. |
| 401 | * @ioc: per adapter object |
| 402 | * @device: either sas_device or raid_device object |
| 403 | * @is_raid: [flag] 1 = raid object, 0 = sas object |
| 404 | * |
| 405 | * Determines whether this device should be first reported device to |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 406 | * to scsi-ml or sas transport, this purpose is for persistent boot device. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 407 | * There are primary, alternate, and current entries in bios page 2. The order |
| 408 | * priority is primary, alternate, then current. This routine saves |
| 409 | * the corresponding device object and is_raid flag in the ioc object. |
| 410 | * The saved data to be used later in _scsih_probe_boot_devices(). |
| 411 | */ |
| 412 | static void |
| 413 | _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc, |
| 414 | void *device, u8 is_raid) |
| 415 | { |
| 416 | struct _sas_device *sas_device; |
| 417 | struct _raid_device *raid_device; |
| 418 | u64 sas_address; |
| 419 | u64 device_name; |
| 420 | u64 enclosure_logical_id; |
| 421 | u16 slot; |
| 422 | |
| 423 | /* only process this function when driver loads */ |
| 424 | if (!ioc->wait_for_port_enable_to_complete) |
| 425 | return; |
| 426 | |
| 427 | if (!is_raid) { |
| 428 | sas_device = device; |
| 429 | sas_address = sas_device->sas_address; |
| 430 | device_name = sas_device->device_name; |
| 431 | enclosure_logical_id = sas_device->enclosure_logical_id; |
| 432 | slot = sas_device->slot; |
| 433 | } else { |
| 434 | raid_device = device; |
| 435 | sas_address = raid_device->wwid; |
| 436 | device_name = 0; |
| 437 | enclosure_logical_id = 0; |
| 438 | slot = 0; |
| 439 | } |
| 440 | |
| 441 | if (!ioc->req_boot_device.device) { |
| 442 | if (_scsih_is_boot_device(sas_address, device_name, |
| 443 | enclosure_logical_id, slot, |
| 444 | (ioc->bios_pg2.ReqBootDeviceForm & |
| 445 | MPI2_BIOSPAGE2_FORM_MASK), |
| 446 | &ioc->bios_pg2.RequestedBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 447 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 448 | "%s: req_boot_device(0x%016llx)\n", |
| 449 | ioc->name, __func__, |
| 450 | (unsigned long long)sas_address)); |
| 451 | ioc->req_boot_device.device = device; |
| 452 | ioc->req_boot_device.is_raid = is_raid; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | if (!ioc->req_alt_boot_device.device) { |
| 457 | if (_scsih_is_boot_device(sas_address, device_name, |
| 458 | enclosure_logical_id, slot, |
| 459 | (ioc->bios_pg2.ReqAltBootDeviceForm & |
| 460 | MPI2_BIOSPAGE2_FORM_MASK), |
| 461 | &ioc->bios_pg2.RequestedAltBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 462 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 463 | "%s: req_alt_boot_device(0x%016llx)\n", |
| 464 | ioc->name, __func__, |
| 465 | (unsigned long long)sas_address)); |
| 466 | ioc->req_alt_boot_device.device = device; |
| 467 | ioc->req_alt_boot_device.is_raid = is_raid; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | if (!ioc->current_boot_device.device) { |
| 472 | if (_scsih_is_boot_device(sas_address, device_name, |
| 473 | enclosure_logical_id, slot, |
| 474 | (ioc->bios_pg2.CurrentBootDeviceForm & |
| 475 | MPI2_BIOSPAGE2_FORM_MASK), |
| 476 | &ioc->bios_pg2.CurrentBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 477 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 478 | "%s: current_boot_device(0x%016llx)\n", |
| 479 | ioc->name, __func__, |
| 480 | (unsigned long long)sas_address)); |
| 481 | ioc->current_boot_device.device = device; |
| 482 | ioc->current_boot_device.is_raid = is_raid; |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search |
| 489 | * @ioc: per adapter object |
| 490 | * @sas_address: sas address |
| 491 | * Context: Calling function should acquire ioc->sas_device_lock |
| 492 | * |
| 493 | * This searches for sas_device based on sas_address, then return sas_device |
| 494 | * object. |
| 495 | */ |
| 496 | struct _sas_device * |
| 497 | mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 498 | u64 sas_address) |
| 499 | { |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 500 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 501 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 502 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) |
| 503 | if (sas_device->sas_address == sas_address) |
| 504 | return sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 505 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 506 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) |
| 507 | if (sas_device->sas_address == sas_address) |
| 508 | return sas_device; |
| 509 | |
| 510 | return NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /** |
| 514 | * _scsih_sas_device_find_by_handle - sas device search |
| 515 | * @ioc: per adapter object |
| 516 | * @handle: sas device handle (assigned by firmware) |
| 517 | * Context: Calling function should acquire ioc->sas_device_lock |
| 518 | * |
| 519 | * This searches for sas_device based on sas_address, then return sas_device |
| 520 | * object. |
| 521 | */ |
| 522 | static struct _sas_device * |
| 523 | _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 524 | { |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 525 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 526 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 527 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) |
| 528 | if (sas_device->handle == handle) |
| 529 | return sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 530 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 531 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) |
| 532 | if (sas_device->handle == handle) |
| 533 | return sas_device; |
| 534 | |
| 535 | return NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | /** |
| 539 | * _scsih_sas_device_remove - remove sas_device from list. |
| 540 | * @ioc: per adapter object |
| 541 | * @sas_device: the sas_device object |
| 542 | * Context: This function will acquire ioc->sas_device_lock. |
| 543 | * |
| 544 | * Removing object and freeing associated memory from the ioc->sas_device_list. |
| 545 | */ |
| 546 | static void |
| 547 | _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc, |
| 548 | struct _sas_device *sas_device) |
| 549 | { |
| 550 | unsigned long flags; |
| 551 | |
Kashyap, Desai | 980ead3 | 2010-04-08 17:55:22 +0530 | [diff] [blame] | 552 | if (!sas_device) |
| 553 | return; |
| 554 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 555 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 980ead3 | 2010-04-08 17:55:22 +0530 | [diff] [blame] | 556 | if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 557 | sas_device->sas_address)) { |
| 558 | list_del(&sas_device->list); |
| 559 | kfree(sas_device); |
| 560 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 561 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 562 | } |
| 563 | |
| 564 | /** |
| 565 | * _scsih_sas_device_add - insert sas_device to the list. |
| 566 | * @ioc: per adapter object |
| 567 | * @sas_device: the sas_device object |
| 568 | * Context: This function will acquire ioc->sas_device_lock. |
| 569 | * |
| 570 | * Adding new object to the ioc->sas_device_list. |
| 571 | */ |
| 572 | static void |
| 573 | _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc, |
| 574 | struct _sas_device *sas_device) |
| 575 | { |
| 576 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 577 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 578 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 579 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 580 | sas_device->handle, (unsigned long long)sas_device->sas_address)); |
| 581 | |
| 582 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 583 | list_add_tail(&sas_device->list, &ioc->sas_device_list); |
| 584 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 585 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 586 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
| 587 | sas_device->sas_address_parent)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 588 | _scsih_sas_device_remove(ioc, sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | /** |
| 592 | * _scsih_sas_device_init_add - insert sas_device to the list. |
| 593 | * @ioc: per adapter object |
| 594 | * @sas_device: the sas_device object |
| 595 | * Context: This function will acquire ioc->sas_device_lock. |
| 596 | * |
| 597 | * Adding new object at driver load time to the ioc->sas_device_init_list. |
| 598 | */ |
| 599 | static void |
| 600 | _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc, |
| 601 | struct _sas_device *sas_device) |
| 602 | { |
| 603 | unsigned long flags; |
| 604 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 605 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 606 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 607 | sas_device->handle, (unsigned long long)sas_device->sas_address)); |
| 608 | |
| 609 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 610 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); |
| 611 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 612 | _scsih_determine_boot_device(ioc, sas_device, 0); |
| 613 | } |
| 614 | |
| 615 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 616 | * _scsih_raid_device_find_by_id - raid device search |
| 617 | * @ioc: per adapter object |
| 618 | * @id: sas device target id |
| 619 | * @channel: sas device channel |
| 620 | * Context: Calling function should acquire ioc->raid_device_lock |
| 621 | * |
| 622 | * This searches for raid_device based on target id, then return raid_device |
| 623 | * object. |
| 624 | */ |
| 625 | static struct _raid_device * |
| 626 | _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel) |
| 627 | { |
| 628 | struct _raid_device *raid_device, *r; |
| 629 | |
| 630 | r = NULL; |
| 631 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 632 | if (raid_device->id == id && raid_device->channel == channel) { |
| 633 | r = raid_device; |
| 634 | goto out; |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | out: |
| 639 | return r; |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * _scsih_raid_device_find_by_handle - raid device search |
| 644 | * @ioc: per adapter object |
| 645 | * @handle: sas device handle (assigned by firmware) |
| 646 | * Context: Calling function should acquire ioc->raid_device_lock |
| 647 | * |
| 648 | * This searches for raid_device based on handle, then return raid_device |
| 649 | * object. |
| 650 | */ |
| 651 | static struct _raid_device * |
| 652 | _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 653 | { |
| 654 | struct _raid_device *raid_device, *r; |
| 655 | |
| 656 | r = NULL; |
| 657 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 658 | if (raid_device->handle != handle) |
| 659 | continue; |
| 660 | r = raid_device; |
| 661 | goto out; |
| 662 | } |
| 663 | |
| 664 | out: |
| 665 | return r; |
| 666 | } |
| 667 | |
| 668 | /** |
| 669 | * _scsih_raid_device_find_by_wwid - raid device search |
| 670 | * @ioc: per adapter object |
| 671 | * @handle: sas device handle (assigned by firmware) |
| 672 | * Context: Calling function should acquire ioc->raid_device_lock |
| 673 | * |
| 674 | * This searches for raid_device based on wwid, then return raid_device |
| 675 | * object. |
| 676 | */ |
| 677 | static struct _raid_device * |
| 678 | _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid) |
| 679 | { |
| 680 | struct _raid_device *raid_device, *r; |
| 681 | |
| 682 | r = NULL; |
| 683 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 684 | if (raid_device->wwid != wwid) |
| 685 | continue; |
| 686 | r = raid_device; |
| 687 | goto out; |
| 688 | } |
| 689 | |
| 690 | out: |
| 691 | return r; |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * _scsih_raid_device_add - add raid_device object |
| 696 | * @ioc: per adapter object |
| 697 | * @raid_device: raid_device object |
| 698 | * |
| 699 | * This is added to the raid_device_list link list. |
| 700 | */ |
| 701 | static void |
| 702 | _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc, |
| 703 | struct _raid_device *raid_device) |
| 704 | { |
| 705 | unsigned long flags; |
| 706 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 707 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 708 | "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, |
| 709 | raid_device->handle, (unsigned long long)raid_device->wwid)); |
| 710 | |
| 711 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 712 | list_add_tail(&raid_device->list, &ioc->raid_device_list); |
| 713 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 714 | } |
| 715 | |
| 716 | /** |
| 717 | * _scsih_raid_device_remove - delete raid_device object |
| 718 | * @ioc: per adapter object |
| 719 | * @raid_device: raid_device object |
| 720 | * |
| 721 | * This is removed from the raid_device_list link list. |
| 722 | */ |
| 723 | static void |
| 724 | _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc, |
| 725 | struct _raid_device *raid_device) |
| 726 | { |
| 727 | unsigned long flags; |
| 728 | |
| 729 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 730 | list_del(&raid_device->list); |
| 731 | memset(raid_device, 0, sizeof(struct _raid_device)); |
| 732 | kfree(raid_device); |
| 733 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 734 | } |
| 735 | |
| 736 | /** |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 737 | * mpt2sas_scsih_expander_find_by_handle - expander device search |
| 738 | * @ioc: per adapter object |
| 739 | * @handle: expander handle (assigned by firmware) |
| 740 | * Context: Calling function should acquire ioc->sas_device_lock |
| 741 | * |
| 742 | * This searches for expander device based on handle, then returns the |
| 743 | * sas_node object. |
| 744 | */ |
| 745 | struct _sas_node * |
| 746 | mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 747 | { |
| 748 | struct _sas_node *sas_expander, *r; |
| 749 | |
| 750 | r = NULL; |
| 751 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 752 | if (sas_expander->handle != handle) |
| 753 | continue; |
| 754 | r = sas_expander; |
| 755 | goto out; |
| 756 | } |
| 757 | out: |
| 758 | return r; |
| 759 | } |
| 760 | |
| 761 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 762 | * mpt2sas_scsih_expander_find_by_sas_address - expander device search |
| 763 | * @ioc: per adapter object |
| 764 | * @sas_address: sas address |
| 765 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 766 | * |
| 767 | * This searches for expander device based on sas_address, then returns the |
| 768 | * sas_node object. |
| 769 | */ |
| 770 | struct _sas_node * |
| 771 | mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 772 | u64 sas_address) |
| 773 | { |
| 774 | struct _sas_node *sas_expander, *r; |
| 775 | |
| 776 | r = NULL; |
| 777 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 778 | if (sas_expander->sas_address != sas_address) |
| 779 | continue; |
| 780 | r = sas_expander; |
| 781 | goto out; |
| 782 | } |
| 783 | out: |
| 784 | return r; |
| 785 | } |
| 786 | |
| 787 | /** |
| 788 | * _scsih_expander_node_add - insert expander device to the list. |
| 789 | * @ioc: per adapter object |
| 790 | * @sas_expander: the sas_device object |
| 791 | * Context: This function will acquire ioc->sas_node_lock. |
| 792 | * |
| 793 | * Adding new object to the ioc->sas_expander_list. |
| 794 | * |
| 795 | * Return nothing. |
| 796 | */ |
| 797 | static void |
| 798 | _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc, |
| 799 | struct _sas_node *sas_expander) |
| 800 | { |
| 801 | unsigned long flags; |
| 802 | |
| 803 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 804 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); |
| 805 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 806 | } |
| 807 | |
| 808 | /** |
| 809 | * _scsih_is_end_device - determines if device is an end device |
| 810 | * @device_info: bitfield providing information about the device. |
| 811 | * Context: none |
| 812 | * |
| 813 | * Returns 1 if end device. |
| 814 | */ |
| 815 | static int |
| 816 | _scsih_is_end_device(u32 device_info) |
| 817 | { |
| 818 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && |
| 819 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | |
| 820 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
| 821 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) |
| 822 | return 1; |
| 823 | else |
| 824 | return 0; |
| 825 | } |
| 826 | |
| 827 | /** |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 828 | * _scsih_scsi_lookup_get - returns scmd entry |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 829 | * @ioc: per adapter object |
| 830 | * @smid: system request message index |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 831 | * |
| 832 | * Returns the smid stored scmd pointer. |
| 833 | */ |
| 834 | static struct scsi_cmnd * |
| 835 | _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 836 | { |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 837 | return ioc->scsi_lookup[smid - 1].scmd; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | /** |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 841 | * _scsih_scsi_lookup_get_clear - returns scmd entry |
| 842 | * @ioc: per adapter object |
| 843 | * @smid: system request message index |
| 844 | * |
| 845 | * Returns the smid stored scmd pointer. |
| 846 | * Then will derefrence the stored scmd pointer. |
| 847 | */ |
| 848 | static inline struct scsi_cmnd * |
| 849 | _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 850 | { |
| 851 | unsigned long flags; |
| 852 | struct scsi_cmnd *scmd; |
| 853 | |
| 854 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 855 | scmd = ioc->scsi_lookup[smid - 1].scmd; |
| 856 | ioc->scsi_lookup[smid - 1].scmd = NULL; |
| 857 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 858 | |
| 859 | return scmd; |
| 860 | } |
| 861 | |
| 862 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 863 | * _scsih_scsi_lookup_find_by_scmd - scmd lookup |
| 864 | * @ioc: per adapter object |
| 865 | * @smid: system request message index |
| 866 | * @scmd: pointer to scsi command object |
| 867 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 868 | * |
| 869 | * This will search for a scmd pointer in the scsi_lookup array, |
| 870 | * returning the revelent smid. A returned value of zero means invalid. |
| 871 | */ |
| 872 | static u16 |
| 873 | _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd |
| 874 | *scmd) |
| 875 | { |
| 876 | u16 smid; |
| 877 | unsigned long flags; |
| 878 | int i; |
| 879 | |
| 880 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 881 | smid = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 882 | for (i = 0; i < ioc->scsiio_depth; i++) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 883 | if (ioc->scsi_lookup[i].scmd == scmd) { |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 884 | smid = ioc->scsi_lookup[i].smid; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 885 | goto out; |
| 886 | } |
| 887 | } |
| 888 | out: |
| 889 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 890 | return smid; |
| 891 | } |
| 892 | |
| 893 | /** |
| 894 | * _scsih_scsi_lookup_find_by_target - search for matching channel:id |
| 895 | * @ioc: per adapter object |
| 896 | * @id: target id |
| 897 | * @channel: channel |
| 898 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 899 | * |
| 900 | * This will search for a matching channel:id in the scsi_lookup array, |
| 901 | * returning 1 if found. |
| 902 | */ |
| 903 | static u8 |
| 904 | _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id, |
| 905 | int channel) |
| 906 | { |
| 907 | u8 found; |
| 908 | unsigned long flags; |
| 909 | int i; |
| 910 | |
| 911 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 912 | found = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 913 | for (i = 0 ; i < ioc->scsiio_depth; i++) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 914 | if (ioc->scsi_lookup[i].scmd && |
| 915 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 916 | ioc->scsi_lookup[i].scmd->device->channel == channel)) { |
| 917 | found = 1; |
| 918 | goto out; |
| 919 | } |
| 920 | } |
| 921 | out: |
| 922 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 923 | return found; |
| 924 | } |
| 925 | |
| 926 | /** |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 927 | * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun |
| 928 | * @ioc: per adapter object |
| 929 | * @id: target id |
| 930 | * @lun: lun number |
| 931 | * @channel: channel |
| 932 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 933 | * |
| 934 | * This will search for a matching channel:id:lun in the scsi_lookup array, |
| 935 | * returning 1 if found. |
| 936 | */ |
| 937 | static u8 |
| 938 | _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id, |
| 939 | unsigned int lun, int channel) |
| 940 | { |
| 941 | u8 found; |
| 942 | unsigned long flags; |
| 943 | int i; |
| 944 | |
| 945 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 946 | found = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 947 | for (i = 0 ; i < ioc->scsiio_depth; i++) { |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 948 | if (ioc->scsi_lookup[i].scmd && |
| 949 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 950 | ioc->scsi_lookup[i].scmd->device->channel == channel && |
| 951 | ioc->scsi_lookup[i].scmd->device->lun == lun)) { |
| 952 | found = 1; |
| 953 | goto out; |
| 954 | } |
| 955 | } |
| 956 | out: |
| 957 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 958 | return found; |
| 959 | } |
| 960 | |
| 961 | /** |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 962 | * _scsih_get_chain_buffer_tracker - obtain chain tracker |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 963 | * @ioc: per adapter object |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 964 | * @smid: smid associated to an IO request |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 965 | * |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 966 | * Returns chain tracker(from ioc->free_chain_list) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 967 | */ |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 968 | static struct chain_tracker * |
| 969 | _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 970 | { |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 971 | struct chain_tracker *chain_req; |
| 972 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 973 | |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 974 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 975 | if (list_empty(&ioc->free_chain_list)) { |
| 976 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 977 | printk(MPT2SAS_WARN_FMT "chain buffers not available\n", |
| 978 | ioc->name); |
| 979 | return NULL; |
| 980 | } |
| 981 | chain_req = list_entry(ioc->free_chain_list.next, |
| 982 | struct chain_tracker, tracker_list); |
| 983 | list_del_init(&chain_req->tracker_list); |
| 984 | list_add_tail(&chain_req->tracker_list, |
| 985 | &ioc->scsi_lookup[smid - 1].chain_list); |
| 986 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 987 | return chain_req; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | /** |
| 991 | * _scsih_build_scatter_gather - main sg creation routine |
| 992 | * @ioc: per adapter object |
| 993 | * @scmd: scsi command |
| 994 | * @smid: system request message index |
| 995 | * Context: none. |
| 996 | * |
| 997 | * The main routine that builds scatter gather table from a given |
| 998 | * scsi request sent via the .queuecommand main handler. |
| 999 | * |
| 1000 | * Returns 0 success, anything else error |
| 1001 | */ |
| 1002 | static int |
| 1003 | _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc, |
| 1004 | struct scsi_cmnd *scmd, u16 smid) |
| 1005 | { |
| 1006 | Mpi2SCSIIORequest_t *mpi_request; |
| 1007 | dma_addr_t chain_dma; |
| 1008 | struct scatterlist *sg_scmd; |
| 1009 | void *sg_local, *chain; |
| 1010 | u32 chain_offset; |
| 1011 | u32 chain_length; |
| 1012 | u32 chain_flags; |
FUJITA Tomonori | bb789d0 | 2010-03-09 11:09:50 +0900 | [diff] [blame] | 1013 | int sges_left; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1014 | u32 sges_in_segment; |
| 1015 | u32 sgl_flags; |
| 1016 | u32 sgl_flags_last_element; |
| 1017 | u32 sgl_flags_end_buffer; |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1018 | struct chain_tracker *chain_req; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1019 | |
| 1020 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 1021 | |
| 1022 | /* init scatter gather flags */ |
| 1023 | sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT; |
| 1024 | if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 1025 | sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC; |
| 1026 | sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT) |
| 1027 | << MPI2_SGE_FLAGS_SHIFT; |
| 1028 | sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT | |
| 1029 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST) |
| 1030 | << MPI2_SGE_FLAGS_SHIFT; |
| 1031 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1032 | |
| 1033 | sg_scmd = scsi_sglist(scmd); |
| 1034 | sges_left = scsi_dma_map(scmd); |
FUJITA Tomonori | bb789d0 | 2010-03-09 11:09:50 +0900 | [diff] [blame] | 1035 | if (sges_left < 0) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1036 | sdev_printk(KERN_ERR, scmd->device, "pci_map_sg" |
| 1037 | " failed: request for %d bytes!\n", scsi_bufflen(scmd)); |
| 1038 | return -ENOMEM; |
| 1039 | } |
| 1040 | |
| 1041 | sg_local = &mpi_request->SGL; |
| 1042 | sges_in_segment = ioc->max_sges_in_main_message; |
| 1043 | if (sges_left <= sges_in_segment) |
| 1044 | goto fill_in_last_segment; |
| 1045 | |
| 1046 | mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) + |
| 1047 | (sges_in_segment * ioc->sge_size))/4; |
| 1048 | |
| 1049 | /* fill in main message segment when there is a chain following */ |
| 1050 | while (sges_in_segment) { |
| 1051 | if (sges_in_segment == 1) |
| 1052 | ioc->base_add_sg_single(sg_local, |
| 1053 | sgl_flags_last_element | sg_dma_len(sg_scmd), |
| 1054 | sg_dma_address(sg_scmd)); |
| 1055 | else |
| 1056 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1057 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1058 | sg_scmd = sg_next(sg_scmd); |
| 1059 | sg_local += ioc->sge_size; |
| 1060 | sges_left--; |
| 1061 | sges_in_segment--; |
| 1062 | } |
| 1063 | |
| 1064 | /* initializing the chain flags and pointers */ |
| 1065 | chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT; |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1066 | chain_req = _scsih_get_chain_buffer_tracker(ioc, smid); |
| 1067 | if (!chain_req) |
| 1068 | return -1; |
| 1069 | chain = chain_req->chain_buffer; |
| 1070 | chain_dma = chain_req->chain_buffer_dma; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1071 | do { |
| 1072 | sges_in_segment = (sges_left <= |
| 1073 | ioc->max_sges_in_chain_message) ? sges_left : |
| 1074 | ioc->max_sges_in_chain_message; |
| 1075 | chain_offset = (sges_left == sges_in_segment) ? |
| 1076 | 0 : (sges_in_segment * ioc->sge_size)/4; |
| 1077 | chain_length = sges_in_segment * ioc->sge_size; |
| 1078 | if (chain_offset) { |
| 1079 | chain_offset = chain_offset << |
| 1080 | MPI2_SGE_CHAIN_OFFSET_SHIFT; |
| 1081 | chain_length += ioc->sge_size; |
| 1082 | } |
| 1083 | ioc->base_add_sg_single(sg_local, chain_flags | chain_offset | |
| 1084 | chain_length, chain_dma); |
| 1085 | sg_local = chain; |
| 1086 | if (!chain_offset) |
| 1087 | goto fill_in_last_segment; |
| 1088 | |
| 1089 | /* fill in chain segments */ |
| 1090 | while (sges_in_segment) { |
| 1091 | if (sges_in_segment == 1) |
| 1092 | ioc->base_add_sg_single(sg_local, |
| 1093 | sgl_flags_last_element | |
| 1094 | sg_dma_len(sg_scmd), |
| 1095 | sg_dma_address(sg_scmd)); |
| 1096 | else |
| 1097 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1098 | sg_dma_len(sg_scmd), |
| 1099 | sg_dma_address(sg_scmd)); |
| 1100 | sg_scmd = sg_next(sg_scmd); |
| 1101 | sg_local += ioc->sge_size; |
| 1102 | sges_left--; |
| 1103 | sges_in_segment--; |
| 1104 | } |
| 1105 | |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1106 | chain_req = _scsih_get_chain_buffer_tracker(ioc, smid); |
| 1107 | if (!chain_req) |
| 1108 | return -1; |
| 1109 | chain = chain_req->chain_buffer; |
| 1110 | chain_dma = chain_req->chain_buffer_dma; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1111 | } while (1); |
| 1112 | |
| 1113 | |
| 1114 | fill_in_last_segment: |
| 1115 | |
| 1116 | /* fill the last segment */ |
| 1117 | while (sges_left) { |
| 1118 | if (sges_left == 1) |
| 1119 | ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer | |
| 1120 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1121 | else |
| 1122 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1123 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1124 | sg_scmd = sg_next(sg_scmd); |
| 1125 | sg_local += ioc->sge_size; |
| 1126 | sges_left--; |
| 1127 | } |
| 1128 | |
| 1129 | return 0; |
| 1130 | } |
| 1131 | |
| 1132 | /** |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1133 | * _scsih_adjust_queue_depth - setting device queue depth |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1134 | * @sdev: scsi device struct |
| 1135 | * @qdepth: requested queue depth |
| 1136 | * |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1137 | * |
| 1138 | * Returns nothing |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1139 | */ |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1140 | static void |
| 1141 | _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1142 | { |
| 1143 | struct Scsi_Host *shost = sdev->host; |
| 1144 | int max_depth; |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1145 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1146 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1147 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1148 | struct _sas_device *sas_device; |
| 1149 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1150 | |
| 1151 | max_depth = shost->can_queue; |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1152 | |
| 1153 | /* limit max device queue for SATA to 32 */ |
| 1154 | sas_device_priv_data = sdev->hostdata; |
| 1155 | if (!sas_device_priv_data) |
| 1156 | goto not_sata; |
| 1157 | sas_target_priv_data = sas_device_priv_data->sas_target; |
| 1158 | if (!sas_target_priv_data) |
| 1159 | goto not_sata; |
| 1160 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) |
| 1161 | goto not_sata; |
| 1162 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1163 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1164 | sas_device_priv_data->sas_target->sas_address); |
| 1165 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1166 | if (sas_device && sas_device->device_info & |
| 1167 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1168 | max_depth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 1169 | |
| 1170 | not_sata: |
| 1171 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1172 | if (!sdev->tagged_supported) |
| 1173 | max_depth = 1; |
| 1174 | if (qdepth > max_depth) |
| 1175 | qdepth = max_depth; |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1176 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); |
| 1177 | } |
| 1178 | |
| 1179 | /** |
| 1180 | * _scsih_change_queue_depth - setting device queue depth |
| 1181 | * @sdev: scsi device struct |
| 1182 | * @qdepth: requested queue depth |
| 1183 | * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP |
| 1184 | * (see include/scsi/scsi_host.h for definition) |
| 1185 | * |
| 1186 | * Returns queue depth. |
| 1187 | */ |
| 1188 | static int |
| 1189 | _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) |
| 1190 | { |
| 1191 | if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP) |
| 1192 | _scsih_adjust_queue_depth(sdev, qdepth); |
| 1193 | else if (reason == SCSI_QDEPTH_QFULL) |
| 1194 | scsi_track_queue_full(sdev, qdepth); |
| 1195 | else |
| 1196 | return -EOPNOTSUPP; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1197 | |
| 1198 | if (sdev->inquiry_len > 7) |
| 1199 | sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " |
| 1200 | "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n", |
| 1201 | sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags, |
| 1202 | sdev->ordered_tags, sdev->scsi_level, |
| 1203 | (sdev->inquiry[7] & 2) >> 1); |
| 1204 | |
| 1205 | return sdev->queue_depth; |
| 1206 | } |
| 1207 | |
| 1208 | /** |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 1209 | * _scsih_change_queue_type - changing device queue tag type |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1210 | * @sdev: scsi device struct |
| 1211 | * @tag_type: requested tag type |
| 1212 | * |
| 1213 | * Returns queue tag type. |
| 1214 | */ |
| 1215 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1216 | _scsih_change_queue_type(struct scsi_device *sdev, int tag_type) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1217 | { |
| 1218 | if (sdev->tagged_supported) { |
| 1219 | scsi_set_tag_type(sdev, tag_type); |
| 1220 | if (tag_type) |
| 1221 | scsi_activate_tcq(sdev, sdev->queue_depth); |
| 1222 | else |
| 1223 | scsi_deactivate_tcq(sdev, sdev->queue_depth); |
| 1224 | } else |
| 1225 | tag_type = 0; |
| 1226 | |
| 1227 | return tag_type; |
| 1228 | } |
| 1229 | |
| 1230 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1231 | * _scsih_target_alloc - target add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1232 | * @starget: scsi target struct |
| 1233 | * |
| 1234 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1235 | * the device is ignored. |
| 1236 | */ |
| 1237 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1238 | _scsih_target_alloc(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1239 | { |
| 1240 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1241 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1242 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1243 | struct _sas_device *sas_device; |
| 1244 | struct _raid_device *raid_device; |
| 1245 | unsigned long flags; |
| 1246 | struct sas_rphy *rphy; |
| 1247 | |
| 1248 | sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL); |
| 1249 | if (!sas_target_priv_data) |
| 1250 | return -ENOMEM; |
| 1251 | |
| 1252 | starget->hostdata = sas_target_priv_data; |
| 1253 | sas_target_priv_data->starget = starget; |
| 1254 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; |
| 1255 | |
| 1256 | /* RAID volumes */ |
| 1257 | if (starget->channel == RAID_CHANNEL) { |
| 1258 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1259 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1260 | starget->channel); |
| 1261 | if (raid_device) { |
| 1262 | sas_target_priv_data->handle = raid_device->handle; |
| 1263 | sas_target_priv_data->sas_address = raid_device->wwid; |
| 1264 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1265 | sas_target_priv_data->raid_device = raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1266 | raid_device->starget = starget; |
| 1267 | } |
| 1268 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1269 | return 0; |
| 1270 | } |
| 1271 | |
| 1272 | /* sas/sata devices */ |
| 1273 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1274 | rphy = dev_to_rphy(starget->dev.parent); |
| 1275 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1276 | rphy->identify.sas_address); |
| 1277 | |
| 1278 | if (sas_device) { |
| 1279 | sas_target_priv_data->handle = sas_device->handle; |
| 1280 | sas_target_priv_data->sas_address = sas_device->sas_address; |
| 1281 | sas_device->starget = starget; |
| 1282 | sas_device->id = starget->id; |
| 1283 | sas_device->channel = starget->channel; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 1284 | if (test_bit(sas_device->handle, ioc->pd_handles)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1285 | sas_target_priv_data->flags |= |
| 1286 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 1287 | } |
| 1288 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1289 | |
| 1290 | return 0; |
| 1291 | } |
| 1292 | |
| 1293 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1294 | * _scsih_target_destroy - target destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1295 | * @starget: scsi target struct |
| 1296 | * |
| 1297 | * Returns nothing. |
| 1298 | */ |
| 1299 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1300 | _scsih_target_destroy(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1301 | { |
| 1302 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1303 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1304 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1305 | struct _sas_device *sas_device; |
| 1306 | struct _raid_device *raid_device; |
| 1307 | unsigned long flags; |
| 1308 | struct sas_rphy *rphy; |
| 1309 | |
| 1310 | sas_target_priv_data = starget->hostdata; |
| 1311 | if (!sas_target_priv_data) |
| 1312 | return; |
| 1313 | |
| 1314 | if (starget->channel == RAID_CHANNEL) { |
| 1315 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1316 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1317 | starget->channel); |
| 1318 | if (raid_device) { |
| 1319 | raid_device->starget = NULL; |
| 1320 | raid_device->sdev = NULL; |
| 1321 | } |
| 1322 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1323 | goto out; |
| 1324 | } |
| 1325 | |
| 1326 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1327 | rphy = dev_to_rphy(starget->dev.parent); |
| 1328 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1329 | rphy->identify.sas_address); |
Eric Moore | 8901cbb | 2009-04-21 15:41:32 -0600 | [diff] [blame] | 1330 | if (sas_device && (sas_device->starget == starget) && |
| 1331 | (sas_device->id == starget->id) && |
| 1332 | (sas_device->channel == starget->channel)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1333 | sas_device->starget = NULL; |
| 1334 | |
| 1335 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1336 | |
| 1337 | out: |
| 1338 | kfree(sas_target_priv_data); |
| 1339 | starget->hostdata = NULL; |
| 1340 | } |
| 1341 | |
| 1342 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1343 | * _scsih_slave_alloc - device add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1344 | * @sdev: scsi device struct |
| 1345 | * |
| 1346 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1347 | * the device is ignored. |
| 1348 | */ |
| 1349 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1350 | _scsih_slave_alloc(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1351 | { |
| 1352 | struct Scsi_Host *shost; |
| 1353 | struct MPT2SAS_ADAPTER *ioc; |
| 1354 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1355 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1356 | struct scsi_target *starget; |
| 1357 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1358 | unsigned long flags; |
| 1359 | |
| 1360 | sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL); |
| 1361 | if (!sas_device_priv_data) |
| 1362 | return -ENOMEM; |
| 1363 | |
| 1364 | sas_device_priv_data->lun = sdev->lun; |
| 1365 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; |
| 1366 | |
| 1367 | starget = scsi_target(sdev); |
| 1368 | sas_target_priv_data = starget->hostdata; |
| 1369 | sas_target_priv_data->num_luns++; |
| 1370 | sas_device_priv_data->sas_target = sas_target_priv_data; |
| 1371 | sdev->hostdata = sas_device_priv_data; |
| 1372 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) |
| 1373 | sdev->no_uld_attach = 1; |
| 1374 | |
| 1375 | shost = dev_to_shost(&starget->dev); |
| 1376 | ioc = shost_priv(shost); |
| 1377 | if (starget->channel == RAID_CHANNEL) { |
| 1378 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1379 | raid_device = _scsih_raid_device_find_by_id(ioc, |
| 1380 | starget->id, starget->channel); |
| 1381 | if (raid_device) |
| 1382 | raid_device->sdev = sdev; /* raid is single lun */ |
| 1383 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1384 | } |
| 1385 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1386 | return 0; |
| 1387 | } |
| 1388 | |
| 1389 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1390 | * _scsih_slave_destroy - device destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1391 | * @sdev: scsi device struct |
| 1392 | * |
| 1393 | * Returns nothing. |
| 1394 | */ |
| 1395 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1396 | _scsih_slave_destroy(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1397 | { |
| 1398 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1399 | struct scsi_target *starget; |
| 1400 | |
| 1401 | if (!sdev->hostdata) |
| 1402 | return; |
| 1403 | |
| 1404 | starget = scsi_target(sdev); |
| 1405 | sas_target_priv_data = starget->hostdata; |
| 1406 | sas_target_priv_data->num_luns--; |
| 1407 | kfree(sdev->hostdata); |
| 1408 | sdev->hostdata = NULL; |
| 1409 | } |
| 1410 | |
| 1411 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1412 | * _scsih_display_sata_capabilities - sata capabilities |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1413 | * @ioc: per adapter object |
| 1414 | * @sas_device: the sas_device object |
| 1415 | * @sdev: scsi device struct |
| 1416 | */ |
| 1417 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1418 | _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1419 | struct _sas_device *sas_device, struct scsi_device *sdev) |
| 1420 | { |
| 1421 | Mpi2ConfigReply_t mpi_reply; |
| 1422 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1423 | u32 ioc_status; |
| 1424 | u16 flags; |
| 1425 | u32 device_info; |
| 1426 | |
| 1427 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 1428 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) { |
| 1429 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1430 | ioc->name, __FILE__, __LINE__, __func__); |
| 1431 | return; |
| 1432 | } |
| 1433 | |
| 1434 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1435 | MPI2_IOCSTATUS_MASK; |
| 1436 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 1437 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1438 | ioc->name, __FILE__, __LINE__, __func__); |
| 1439 | return; |
| 1440 | } |
| 1441 | |
| 1442 | flags = le16_to_cpu(sas_device_pg0.Flags); |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 1443 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1444 | |
| 1445 | sdev_printk(KERN_INFO, sdev, |
| 1446 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " |
| 1447 | "sw_preserve(%s)\n", |
| 1448 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", |
| 1449 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", |
| 1450 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : |
| 1451 | "n", |
| 1452 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", |
| 1453 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", |
| 1454 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); |
| 1455 | } |
| 1456 | |
| 1457 | /** |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1458 | * _scsih_is_raid - return boolean indicating device is raid volume |
| 1459 | * @dev the device struct object |
| 1460 | */ |
| 1461 | static int |
| 1462 | _scsih_is_raid(struct device *dev) |
| 1463 | { |
| 1464 | struct scsi_device *sdev = to_scsi_device(dev); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1465 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1466 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1467 | if (ioc->is_warpdrive) |
| 1468 | return 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1469 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
| 1470 | } |
| 1471 | |
| 1472 | /** |
| 1473 | * _scsih_get_resync - get raid volume resync percent complete |
| 1474 | * @dev the device struct object |
| 1475 | */ |
| 1476 | static void |
| 1477 | _scsih_get_resync(struct device *dev) |
| 1478 | { |
| 1479 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1480 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1481 | static struct _raid_device *raid_device; |
| 1482 | unsigned long flags; |
| 1483 | Mpi2RaidVolPage0_t vol_pg0; |
| 1484 | Mpi2ConfigReply_t mpi_reply; |
| 1485 | u32 volume_status_flags; |
| 1486 | u8 percent_complete = 0; |
| 1487 | |
| 1488 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1489 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1490 | sdev->channel); |
| 1491 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1492 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1493 | if (!raid_device || ioc->is_warpdrive) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1494 | goto out; |
| 1495 | |
| 1496 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, |
| 1497 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, |
| 1498 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1499 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1500 | ioc->name, __FILE__, __LINE__, __func__); |
| 1501 | goto out; |
| 1502 | } |
| 1503 | |
| 1504 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
| 1505 | if (volume_status_flags & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) |
| 1506 | percent_complete = raid_device->percent_complete; |
| 1507 | out: |
| 1508 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); |
| 1509 | } |
| 1510 | |
| 1511 | /** |
| 1512 | * _scsih_get_state - get raid volume level |
| 1513 | * @dev the device struct object |
| 1514 | */ |
| 1515 | static void |
| 1516 | _scsih_get_state(struct device *dev) |
| 1517 | { |
| 1518 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1519 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1520 | static struct _raid_device *raid_device; |
| 1521 | unsigned long flags; |
| 1522 | Mpi2RaidVolPage0_t vol_pg0; |
| 1523 | Mpi2ConfigReply_t mpi_reply; |
| 1524 | u32 volstate; |
| 1525 | enum raid_state state = RAID_STATE_UNKNOWN; |
| 1526 | |
| 1527 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1528 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1529 | sdev->channel); |
| 1530 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1531 | |
| 1532 | if (!raid_device) |
| 1533 | goto out; |
| 1534 | |
| 1535 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, |
| 1536 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, |
| 1537 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1538 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1539 | ioc->name, __FILE__, __LINE__, __func__); |
| 1540 | goto out; |
| 1541 | } |
| 1542 | |
| 1543 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
| 1544 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { |
| 1545 | state = RAID_STATE_RESYNCING; |
| 1546 | goto out; |
| 1547 | } |
| 1548 | |
| 1549 | switch (vol_pg0.VolumeState) { |
| 1550 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
| 1551 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 1552 | state = RAID_STATE_ACTIVE; |
| 1553 | break; |
| 1554 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 1555 | state = RAID_STATE_DEGRADED; |
| 1556 | break; |
| 1557 | case MPI2_RAID_VOL_STATE_FAILED: |
| 1558 | case MPI2_RAID_VOL_STATE_MISSING: |
| 1559 | state = RAID_STATE_OFFLINE; |
| 1560 | break; |
| 1561 | } |
| 1562 | out: |
| 1563 | raid_set_state(mpt2sas_raid_template, dev, state); |
| 1564 | } |
| 1565 | |
| 1566 | /** |
| 1567 | * _scsih_set_level - set raid level |
| 1568 | * @sdev: scsi device struct |
| 1569 | * @raid_device: raid_device object |
| 1570 | */ |
| 1571 | static void |
| 1572 | _scsih_set_level(struct scsi_device *sdev, struct _raid_device *raid_device) |
| 1573 | { |
| 1574 | enum raid_level level = RAID_LEVEL_UNKNOWN; |
| 1575 | |
| 1576 | switch (raid_device->volume_type) { |
| 1577 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 1578 | level = RAID_LEVEL_0; |
| 1579 | break; |
| 1580 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 1581 | level = RAID_LEVEL_10; |
| 1582 | break; |
| 1583 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 1584 | level = RAID_LEVEL_1E; |
| 1585 | break; |
| 1586 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 1587 | level = RAID_LEVEL_1; |
| 1588 | break; |
| 1589 | } |
| 1590 | |
| 1591 | raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level); |
| 1592 | } |
| 1593 | |
| 1594 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1595 | * _scsih_get_volume_capabilities - volume capabilities |
| 1596 | * @ioc: per adapter object |
| 1597 | * @sas_device: the raid_device object |
| 1598 | */ |
| 1599 | static void |
| 1600 | _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc, |
| 1601 | struct _raid_device *raid_device) |
| 1602 | { |
| 1603 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1604 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1605 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1606 | Mpi2ConfigReply_t mpi_reply; |
| 1607 | u16 sz; |
| 1608 | u8 num_pds; |
| 1609 | |
| 1610 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1611 | &num_pds)) || !num_pds) { |
| 1612 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1613 | ioc->name, __FILE__, __LINE__, __func__); |
| 1614 | return; |
| 1615 | } |
| 1616 | |
| 1617 | raid_device->num_pds = num_pds; |
| 1618 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1619 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1620 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1621 | if (!vol_pg0) { |
| 1622 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1623 | ioc->name, __FILE__, __LINE__, __func__); |
| 1624 | return; |
| 1625 | } |
| 1626 | |
| 1627 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1628 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
| 1629 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1630 | ioc->name, __FILE__, __LINE__, __func__); |
| 1631 | kfree(vol_pg0); |
| 1632 | return; |
| 1633 | } |
| 1634 | |
| 1635 | raid_device->volume_type = vol_pg0->VolumeType; |
| 1636 | |
| 1637 | /* figure out what the underlying devices are by |
| 1638 | * obtaining the device_info bits for the 1st device |
| 1639 | */ |
| 1640 | if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1641 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1642 | vol_pg0->PhysDisk[0].PhysDiskNum))) { |
| 1643 | if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 1644 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 1645 | le16_to_cpu(pd_pg0.DevHandle)))) { |
| 1646 | raid_device->device_info = |
| 1647 | le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | kfree(vol_pg0); |
| 1652 | } |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1653 | /** |
| 1654 | * _scsih_disable_ddio - Disable direct I/O for all the volumes |
| 1655 | * @ioc: per adapter object |
| 1656 | */ |
| 1657 | static void |
| 1658 | _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc) |
| 1659 | { |
| 1660 | Mpi2RaidVolPage1_t vol_pg1; |
| 1661 | Mpi2ConfigReply_t mpi_reply; |
| 1662 | struct _raid_device *raid_device; |
| 1663 | u16 handle; |
| 1664 | u16 ioc_status; |
| 1665 | |
| 1666 | handle = 0xFFFF; |
| 1667 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 1668 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 1669 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1670 | MPI2_IOCSTATUS_MASK; |
| 1671 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 1672 | break; |
| 1673 | handle = le16_to_cpu(vol_pg1.DevHandle); |
| 1674 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 1675 | if (raid_device) |
| 1676 | raid_device->direct_io_enabled = 0; |
| 1677 | } |
| 1678 | return; |
| 1679 | } |
| 1680 | |
| 1681 | |
| 1682 | /** |
| 1683 | * _scsih_get_num_volumes - Get number of volumes in the ioc |
| 1684 | * @ioc: per adapter object |
| 1685 | */ |
| 1686 | static u8 |
| 1687 | _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc) |
| 1688 | { |
| 1689 | Mpi2RaidVolPage1_t vol_pg1; |
| 1690 | Mpi2ConfigReply_t mpi_reply; |
| 1691 | u16 handle; |
| 1692 | u8 vol_cnt = 0; |
| 1693 | u16 ioc_status; |
| 1694 | |
| 1695 | handle = 0xFFFF; |
| 1696 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 1697 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 1698 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1699 | MPI2_IOCSTATUS_MASK; |
| 1700 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 1701 | break; |
| 1702 | vol_cnt++; |
| 1703 | handle = le16_to_cpu(vol_pg1.DevHandle); |
| 1704 | } |
| 1705 | return vol_cnt; |
| 1706 | } |
| 1707 | |
| 1708 | |
| 1709 | /** |
| 1710 | * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O. |
| 1711 | * @ioc: per adapter object |
| 1712 | * @raid_device: the raid_device object |
| 1713 | */ |
| 1714 | static void |
| 1715 | _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc, |
| 1716 | struct _raid_device *raid_device) |
| 1717 | { |
| 1718 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1719 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1720 | Mpi2ConfigReply_t mpi_reply; |
| 1721 | u16 sz; |
| 1722 | u8 num_pds, count; |
| 1723 | u64 mb = 1024 * 1024; |
| 1724 | u64 tb_2 = 2 * mb * mb; |
| 1725 | u64 capacity; |
| 1726 | u32 stripe_sz; |
| 1727 | u8 i, stripe_exp; |
| 1728 | |
| 1729 | if (!ioc->is_warpdrive) |
| 1730 | return; |
| 1731 | |
| 1732 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) { |
| 1733 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1734 | "globally as drives are exposed\n", ioc->name); |
| 1735 | return; |
| 1736 | } |
| 1737 | if (_scsih_get_num_volumes(ioc) > 1) { |
| 1738 | _scsih_disable_ddio(ioc); |
| 1739 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1740 | "globally as number of drives > 1\n", ioc->name); |
| 1741 | return; |
| 1742 | } |
| 1743 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1744 | &num_pds)) || !num_pds) { |
| 1745 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1746 | "Failure in computing number of drives\n", ioc->name); |
| 1747 | return; |
| 1748 | } |
| 1749 | |
| 1750 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1751 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1752 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1753 | if (!vol_pg0) { |
| 1754 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1755 | "Memory allocation failure for RVPG0\n", ioc->name); |
| 1756 | return; |
| 1757 | } |
| 1758 | |
| 1759 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1760 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
| 1761 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1762 | "Failure in retrieving RVPG0\n", ioc->name); |
| 1763 | kfree(vol_pg0); |
| 1764 | return; |
| 1765 | } |
| 1766 | |
| 1767 | /* |
| 1768 | * WARPDRIVE:If number of physical disks in a volume exceeds the max pds |
| 1769 | * assumed for WARPDRIVE, disable direct I/O |
| 1770 | */ |
| 1771 | if (num_pds > MPT_MAX_WARPDRIVE_PDS) { |
| 1772 | printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled " |
| 1773 | "for the drive with handle(0x%04x): num_mem=%d, " |
| 1774 | "max_mem_allowed=%d\n", ioc->name, raid_device->handle, |
| 1775 | num_pds, MPT_MAX_WARPDRIVE_PDS); |
| 1776 | kfree(vol_pg0); |
| 1777 | return; |
| 1778 | } |
| 1779 | for (count = 0; count < num_pds; count++) { |
| 1780 | if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1781 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1782 | vol_pg0->PhysDisk[count].PhysDiskNum) || |
| 1783 | pd_pg0.DevHandle == MPT2SAS_INVALID_DEVICE_HANDLE) { |
| 1784 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " |
| 1785 | "disabled for the drive with handle(0x%04x) member" |
| 1786 | "handle retrieval failed for member number=%d\n", |
| 1787 | ioc->name, raid_device->handle, |
| 1788 | vol_pg0->PhysDisk[count].PhysDiskNum); |
| 1789 | goto out_error; |
| 1790 | } |
| 1791 | raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle); |
| 1792 | } |
| 1793 | |
| 1794 | /* |
| 1795 | * Assumption for WD: Direct I/O is not supported if the volume is |
| 1796 | * not RAID0, if the stripe size is not 64KB, if the block size is |
| 1797 | * not 512 and if the volume size is >2TB |
| 1798 | */ |
| 1799 | if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0 || |
| 1800 | le16_to_cpu(vol_pg0->BlockSize) != 512) { |
| 1801 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1802 | "for the drive with handle(0x%04x): type=%d, " |
| 1803 | "s_sz=%uK, blk_size=%u\n", ioc->name, |
| 1804 | raid_device->handle, raid_device->volume_type, |
| 1805 | le32_to_cpu(vol_pg0->StripeSize)/2, |
| 1806 | le16_to_cpu(vol_pg0->BlockSize)); |
| 1807 | goto out_error; |
| 1808 | } |
| 1809 | |
| 1810 | capacity = (u64) le16_to_cpu(vol_pg0->BlockSize) * |
| 1811 | (le64_to_cpu(vol_pg0->MaxLBA) + 1); |
| 1812 | |
| 1813 | if (capacity > tb_2) { |
| 1814 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1815 | "for the drive with handle(0x%04x) since drive sz > 2TB\n", |
| 1816 | ioc->name, raid_device->handle); |
| 1817 | goto out_error; |
| 1818 | } |
| 1819 | |
| 1820 | stripe_sz = le32_to_cpu(vol_pg0->StripeSize); |
| 1821 | stripe_exp = 0; |
| 1822 | for (i = 0; i < 32; i++) { |
| 1823 | if (stripe_sz & 1) |
| 1824 | break; |
| 1825 | stripe_exp++; |
| 1826 | stripe_sz >>= 1; |
| 1827 | } |
| 1828 | if (i == 32) { |
| 1829 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1830 | "for the drive with handle(0x%04x) invalid stripe sz %uK\n", |
| 1831 | ioc->name, raid_device->handle, |
| 1832 | le32_to_cpu(vol_pg0->StripeSize)/2); |
| 1833 | goto out_error; |
| 1834 | } |
| 1835 | raid_device->stripe_exponent = stripe_exp; |
| 1836 | raid_device->direct_io_enabled = 1; |
| 1837 | |
| 1838 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive" |
| 1839 | " with handle(0x%04x)\n", ioc->name, raid_device->handle); |
| 1840 | /* |
| 1841 | * WARPDRIVE: Though the following fields are not used for direct IO, |
| 1842 | * stored for future purpose: |
| 1843 | */ |
| 1844 | raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA); |
| 1845 | raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize); |
| 1846 | raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize); |
| 1847 | |
| 1848 | |
| 1849 | kfree(vol_pg0); |
| 1850 | return; |
| 1851 | |
| 1852 | out_error: |
| 1853 | raid_device->direct_io_enabled = 0; |
| 1854 | for (count = 0; count < num_pds; count++) |
| 1855 | raid_device->pd_handle[count] = 0; |
| 1856 | kfree(vol_pg0); |
| 1857 | return; |
| 1858 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1859 | |
| 1860 | /** |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 1861 | * _scsih_enable_tlr - setting TLR flags |
| 1862 | * @ioc: per adapter object |
| 1863 | * @sdev: scsi device struct |
| 1864 | * |
| 1865 | * Enabling Transaction Layer Retries for tape devices when |
| 1866 | * vpd page 0x90 is present |
| 1867 | * |
| 1868 | */ |
| 1869 | static void |
| 1870 | _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev) |
| 1871 | { |
| 1872 | /* only for TAPE */ |
| 1873 | if (sdev->type != TYPE_TAPE) |
| 1874 | return; |
| 1875 | |
| 1876 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) |
| 1877 | return; |
| 1878 | |
| 1879 | sas_enable_tlr(sdev); |
| 1880 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", |
| 1881 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); |
| 1882 | return; |
| 1883 | |
| 1884 | } |
| 1885 | |
| 1886 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1887 | * _scsih_slave_configure - device configure routine. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1888 | * @sdev: scsi device struct |
| 1889 | * |
| 1890 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1891 | * the device is ignored. |
| 1892 | */ |
| 1893 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1894 | _scsih_slave_configure(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1895 | { |
| 1896 | struct Scsi_Host *shost = sdev->host; |
| 1897 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1898 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1899 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1900 | struct _sas_device *sas_device; |
| 1901 | struct _raid_device *raid_device; |
| 1902 | unsigned long flags; |
| 1903 | int qdepth; |
| 1904 | u8 ssp_target = 0; |
| 1905 | char *ds = ""; |
| 1906 | char *r_level = ""; |
| 1907 | |
| 1908 | qdepth = 1; |
| 1909 | sas_device_priv_data = sdev->hostdata; |
| 1910 | sas_device_priv_data->configured_lun = 1; |
| 1911 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; |
| 1912 | sas_target_priv_data = sas_device_priv_data->sas_target; |
| 1913 | |
| 1914 | /* raid volume handling */ |
| 1915 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 1916 | |
| 1917 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1918 | raid_device = _scsih_raid_device_find_by_handle(ioc, |
| 1919 | sas_target_priv_data->handle); |
| 1920 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1921 | if (!raid_device) { |
| 1922 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1923 | ioc->name, __FILE__, __LINE__, __func__); |
| 1924 | return 0; |
| 1925 | } |
| 1926 | |
| 1927 | _scsih_get_volume_capabilities(ioc, raid_device); |
| 1928 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1929 | /* |
| 1930 | * WARPDRIVE: Initialize the required data for Direct IO |
| 1931 | */ |
| 1932 | _scsih_init_warpdrive_properties(ioc, raid_device); |
| 1933 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1934 | /* RAID Queue Depth Support |
| 1935 | * IS volume = underlying qdepth of drive type, either |
| 1936 | * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH |
| 1937 | * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH) |
| 1938 | */ |
| 1939 | if (raid_device->device_info & |
| 1940 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 1941 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 1942 | ds = "SSP"; |
| 1943 | } else { |
| 1944 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 1945 | if (raid_device->device_info & |
| 1946 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1947 | ds = "SATA"; |
| 1948 | else |
| 1949 | ds = "STP"; |
| 1950 | } |
| 1951 | |
| 1952 | switch (raid_device->volume_type) { |
| 1953 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 1954 | r_level = "RAID0"; |
| 1955 | break; |
| 1956 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 1957 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 1958 | if (ioc->manu_pg10.OEMIdentifier && |
| 1959 | (ioc->manu_pg10.GenericFlags0 & |
| 1960 | MFG10_GF0_R10_DISPLAY) && |
| 1961 | !(raid_device->num_pds % 2)) |
| 1962 | r_level = "RAID10"; |
| 1963 | else |
| 1964 | r_level = "RAID1E"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1965 | break; |
| 1966 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 1967 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 1968 | r_level = "RAID1"; |
| 1969 | break; |
| 1970 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 1971 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 1972 | r_level = "RAID10"; |
| 1973 | break; |
| 1974 | case MPI2_RAID_VOL_TYPE_UNKNOWN: |
| 1975 | default: |
| 1976 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 1977 | r_level = "RAIDX"; |
| 1978 | break; |
| 1979 | } |
| 1980 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1981 | if (!ioc->hide_ir_msg) |
| 1982 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
| 1983 | "wwid(0x%016llx), pd_count(%d), type(%s)\n", |
| 1984 | r_level, raid_device->handle, |
| 1985 | (unsigned long long)raid_device->wwid, |
| 1986 | raid_device->num_pds, ds); |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 1987 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1988 | /* raid transport support */ |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1989 | if (!ioc->is_warpdrive) |
| 1990 | _scsih_set_level(sdev, raid_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1991 | return 0; |
| 1992 | } |
| 1993 | |
| 1994 | /* non-raid handling */ |
| 1995 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1996 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1997 | sas_device_priv_data->sas_target->sas_address); |
| 1998 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1999 | if (sas_device) { |
| 2000 | if (sas_target_priv_data->flags & |
| 2001 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2002 | mpt2sas_config_get_volume_handle(ioc, |
| 2003 | sas_device->handle, &sas_device->volume_handle); |
| 2004 | mpt2sas_config_get_volume_wwid(ioc, |
| 2005 | sas_device->volume_handle, |
| 2006 | &sas_device->volume_wwid); |
| 2007 | } |
| 2008 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 2009 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 2010 | ssp_target = 1; |
| 2011 | ds = "SSP"; |
| 2012 | } else { |
| 2013 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 2014 | if (sas_device->device_info & |
| 2015 | MPI2_SAS_DEVICE_INFO_STP_TARGET) |
| 2016 | ds = "STP"; |
| 2017 | else if (sas_device->device_info & |
| 2018 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 2019 | ds = "SATA"; |
| 2020 | } |
| 2021 | |
| 2022 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 2023 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2024 | ds, sas_device->handle, |
| 2025 | (unsigned long long)sas_device->sas_address, |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 2026 | sas_device->phy, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2027 | (unsigned long long)sas_device->device_name); |
| 2028 | sdev_printk(KERN_INFO, sdev, "%s: " |
| 2029 | "enclosure_logical_id(0x%016llx), slot(%d)\n", ds, |
| 2030 | (unsigned long long) sas_device->enclosure_logical_id, |
| 2031 | sas_device->slot); |
| 2032 | |
| 2033 | if (!ssp_target) |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2034 | _scsih_display_sata_capabilities(ioc, sas_device, sdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2035 | } |
| 2036 | |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 2037 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2038 | |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 2039 | if (ssp_target) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2040 | sas_read_port_mode_page(sdev); |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 2041 | _scsih_enable_tlr(ioc, sdev); |
| 2042 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2043 | return 0; |
| 2044 | } |
| 2045 | |
| 2046 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2047 | * _scsih_bios_param - fetch head, sector, cylinder info for a disk |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2048 | * @sdev: scsi device struct |
| 2049 | * @bdev: pointer to block device context |
| 2050 | * @capacity: device size (in 512 byte sectors) |
| 2051 | * @params: three element array to place output: |
| 2052 | * params[0] number of heads (max 255) |
| 2053 | * params[1] number of sectors (max 63) |
| 2054 | * params[2] number of cylinders |
| 2055 | * |
| 2056 | * Return nothing. |
| 2057 | */ |
| 2058 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2059 | _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2060 | sector_t capacity, int params[]) |
| 2061 | { |
| 2062 | int heads; |
| 2063 | int sectors; |
| 2064 | sector_t cylinders; |
| 2065 | ulong dummy; |
| 2066 | |
| 2067 | heads = 64; |
| 2068 | sectors = 32; |
| 2069 | |
| 2070 | dummy = heads * sectors; |
| 2071 | cylinders = capacity; |
| 2072 | sector_div(cylinders, dummy); |
| 2073 | |
| 2074 | /* |
| 2075 | * Handle extended translation size for logical drives |
| 2076 | * > 1Gb |
| 2077 | */ |
| 2078 | if ((ulong)capacity >= 0x200000) { |
| 2079 | heads = 255; |
| 2080 | sectors = 63; |
| 2081 | dummy = heads * sectors; |
| 2082 | cylinders = capacity; |
| 2083 | sector_div(cylinders, dummy); |
| 2084 | } |
| 2085 | |
| 2086 | /* return result */ |
| 2087 | params[0] = heads; |
| 2088 | params[1] = sectors; |
| 2089 | params[2] = cylinders; |
| 2090 | |
| 2091 | return 0; |
| 2092 | } |
| 2093 | |
| 2094 | /** |
| 2095 | * _scsih_response_code - translation of device response code |
| 2096 | * @ioc: per adapter object |
| 2097 | * @response_code: response code returned by the device |
| 2098 | * |
| 2099 | * Return nothing. |
| 2100 | */ |
| 2101 | static void |
| 2102 | _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code) |
| 2103 | { |
| 2104 | char *desc; |
| 2105 | |
| 2106 | switch (response_code) { |
| 2107 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: |
| 2108 | desc = "task management request completed"; |
| 2109 | break; |
| 2110 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: |
| 2111 | desc = "invalid frame"; |
| 2112 | break; |
| 2113 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: |
| 2114 | desc = "task management request not supported"; |
| 2115 | break; |
| 2116 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: |
| 2117 | desc = "task management request failed"; |
| 2118 | break; |
| 2119 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: |
| 2120 | desc = "task management request succeeded"; |
| 2121 | break; |
| 2122 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: |
| 2123 | desc = "invalid lun"; |
| 2124 | break; |
| 2125 | case 0xA: |
| 2126 | desc = "overlapped tag attempted"; |
| 2127 | break; |
| 2128 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: |
| 2129 | desc = "task queued, however not sent to target"; |
| 2130 | break; |
| 2131 | default: |
| 2132 | desc = "unknown"; |
| 2133 | break; |
| 2134 | } |
| 2135 | printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n", |
| 2136 | ioc->name, response_code, desc); |
| 2137 | } |
| 2138 | |
| 2139 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2140 | * _scsih_tm_done - tm completion routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2141 | * @ioc: per adapter object |
| 2142 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2143 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2144 | * @reply: reply message frame(lower 32bit addr) |
| 2145 | * Context: none. |
| 2146 | * |
| 2147 | * The callback handler when using scsih_issue_tm. |
| 2148 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2149 | * Return 1 meaning mf should be freed from _base_interrupt |
| 2150 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2151 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2152 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2153 | _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] | 2154 | { |
| 2155 | MPI2DefaultReply_t *mpi_reply; |
| 2156 | |
| 2157 | if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2158 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2159 | if (ioc->tm_cmds.smid != smid) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2160 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2161 | ioc->tm_cmds.status |= MPT2_CMD_COMPLETE; |
| 2162 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 2163 | if (mpi_reply) { |
| 2164 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 2165 | ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 2166 | } |
| 2167 | ioc->tm_cmds.status &= ~MPT2_CMD_PENDING; |
| 2168 | complete(&ioc->tm_cmds.done); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2169 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | /** |
| 2173 | * mpt2sas_scsih_set_tm_flag - set per target tm_busy |
| 2174 | * @ioc: per adapter object |
| 2175 | * @handle: device handle |
| 2176 | * |
| 2177 | * During taskmangement request, we need to freeze the device queue. |
| 2178 | */ |
| 2179 | void |
| 2180 | mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2181 | { |
| 2182 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2183 | struct scsi_device *sdev; |
| 2184 | u8 skip = 0; |
| 2185 | |
| 2186 | shost_for_each_device(sdev, ioc->shost) { |
| 2187 | if (skip) |
| 2188 | continue; |
| 2189 | sas_device_priv_data = sdev->hostdata; |
| 2190 | if (!sas_device_priv_data) |
| 2191 | continue; |
| 2192 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2193 | sas_device_priv_data->sas_target->tm_busy = 1; |
| 2194 | skip = 1; |
| 2195 | ioc->ignore_loginfos = 1; |
| 2196 | } |
| 2197 | } |
| 2198 | } |
| 2199 | |
| 2200 | /** |
| 2201 | * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy |
| 2202 | * @ioc: per adapter object |
| 2203 | * @handle: device handle |
| 2204 | * |
| 2205 | * During taskmangement request, we need to freeze the device queue. |
| 2206 | */ |
| 2207 | void |
| 2208 | mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2209 | { |
| 2210 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2211 | struct scsi_device *sdev; |
| 2212 | u8 skip = 0; |
| 2213 | |
| 2214 | shost_for_each_device(sdev, ioc->shost) { |
| 2215 | if (skip) |
| 2216 | continue; |
| 2217 | sas_device_priv_data = sdev->hostdata; |
| 2218 | if (!sas_device_priv_data) |
| 2219 | continue; |
| 2220 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2221 | sas_device_priv_data->sas_target->tm_busy = 0; |
| 2222 | skip = 1; |
| 2223 | ioc->ignore_loginfos = 0; |
| 2224 | } |
| 2225 | } |
| 2226 | } |
| 2227 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2228 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2229 | /** |
| 2230 | * mpt2sas_scsih_issue_tm - main routine for sending tm requests |
| 2231 | * @ioc: per adapter struct |
| 2232 | * @device_handle: device handle |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2233 | * @channel: the channel assigned by the OS |
| 2234 | * @id: the id assigned by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2235 | * @lun: lun number |
| 2236 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) |
| 2237 | * @smid_task: smid assigned to the task |
| 2238 | * @timeout: timeout in seconds |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2239 | * Context: user |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2240 | * |
| 2241 | * A generic API for sending task management requests to firmware. |
| 2242 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2243 | * The callback index is set inside `ioc->tm_cb_idx`. |
| 2244 | * |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2245 | * Return SUCCESS or FAILED. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2246 | */ |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2247 | int |
| 2248 | mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel, |
| 2249 | uint id, uint lun, u8 type, u16 smid_task, ulong timeout, |
| 2250 | struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2251 | { |
| 2252 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 2253 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
| 2254 | u16 smid = 0; |
| 2255 | u32 ioc_state; |
| 2256 | unsigned long timeleft; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2257 | struct scsi_cmnd *scmd_lookup; |
| 2258 | int rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2259 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2260 | mutex_lock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2261 | if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) { |
| 2262 | printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n", |
| 2263 | __func__, ioc->name); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2264 | rc = FAILED; |
| 2265 | goto err_out; |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2266 | } |
| 2267 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 2268 | if (ioc->shost_recovery || ioc->remove_host || |
| 2269 | ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2270 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 2271 | __func__, ioc->name); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2272 | rc = FAILED; |
| 2273 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2274 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2275 | |
| 2276 | ioc_state = mpt2sas_base_get_iocstate(ioc, 0); |
| 2277 | if (ioc_state & MPI2_DOORBELL_USED) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 2278 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2279 | "active!\n", ioc->name)); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2280 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2281 | FORCE_BIG_HAMMER); |
| 2282 | rc = SUCCESS; |
| 2283 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 2287 | mpt2sas_base_fault_info(ioc, ioc_state & |
| 2288 | MPI2_DOORBELL_DATA_MASK); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2289 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2290 | FORCE_BIG_HAMMER); |
| 2291 | rc = SUCCESS; |
| 2292 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2293 | } |
| 2294 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2295 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2296 | if (!smid) { |
| 2297 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 2298 | ioc->name, __func__); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2299 | rc = FAILED; |
| 2300 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x)," |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2304 | " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type, |
| 2305 | smid_task)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2306 | ioc->tm_cmds.status = MPT2_CMD_PENDING; |
| 2307 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 2308 | ioc->tm_cmds.smid = smid; |
| 2309 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 2310 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 2311 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 2312 | mpi_request->TaskType = type; |
| 2313 | mpi_request->TaskMID = cpu_to_le16(smid_task); |
| 2314 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); |
| 2315 | mpt2sas_scsih_set_tm_flag(ioc, handle); |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 2316 | init_completion(&ioc->tm_cmds.done); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2317 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2318 | timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2319 | if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) { |
| 2320 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 2321 | ioc->name, __func__); |
| 2322 | _debug_dump_mf(mpi_request, |
| 2323 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2324 | if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) { |
| 2325 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2326 | FORCE_BIG_HAMMER); |
| 2327 | rc = SUCCESS; |
| 2328 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
| 2329 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 2330 | goto err_out; |
| 2331 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 2335 | mpi_reply = ioc->tm_cmds.reply; |
| 2336 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: " |
| 2337 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", |
| 2338 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 2339 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 2340 | le32_to_cpu(mpi_reply->TerminationCount))); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2341 | if (ioc->logging_level & MPT_DEBUG_TM) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2342 | _scsih_response_code(ioc, mpi_reply->ResponseCode); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2343 | if (mpi_reply->IOCStatus) |
| 2344 | _debug_dump_mf(mpi_request, |
| 2345 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
| 2346 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2347 | } |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2348 | |
| 2349 | /* sanity check: |
| 2350 | * Check to see the commands were terminated. |
| 2351 | * This is only needed for eh callbacks, hence the scmd check. |
| 2352 | */ |
| 2353 | rc = FAILED; |
| 2354 | if (scmd == NULL) |
| 2355 | goto bypass_sanity_checks; |
| 2356 | switch (type) { |
| 2357 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: |
| 2358 | scmd_lookup = _scsih_scsi_lookup_get(ioc, smid_task); |
Christoph Hellwig | a7c44d4 | 2011-04-04 09:42:30 -0400 | [diff] [blame] | 2359 | if (scmd_lookup) |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2360 | rc = FAILED; |
| 2361 | else |
| 2362 | rc = SUCCESS; |
| 2363 | break; |
| 2364 | |
| 2365 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: |
| 2366 | if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) |
| 2367 | rc = FAILED; |
| 2368 | else |
| 2369 | rc = SUCCESS; |
| 2370 | break; |
| 2371 | |
| 2372 | case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: |
| 2373 | if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) |
| 2374 | rc = FAILED; |
| 2375 | else |
| 2376 | rc = SUCCESS; |
| 2377 | break; |
| 2378 | } |
| 2379 | |
| 2380 | bypass_sanity_checks: |
| 2381 | |
| 2382 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 2383 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
| 2384 | mutex_unlock(&ioc->tm_cmds.mutex); |
| 2385 | |
| 2386 | return rc; |
| 2387 | |
| 2388 | err_out: |
| 2389 | mutex_unlock(&ioc->tm_cmds.mutex); |
| 2390 | return rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | /** |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2394 | * _scsih_tm_display_info - displays info about the device |
| 2395 | * @ioc: per adapter struct |
| 2396 | * @scmd: pointer to scsi command object |
| 2397 | * |
| 2398 | * Called by task management callback handlers. |
| 2399 | */ |
| 2400 | static void |
| 2401 | _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) |
| 2402 | { |
| 2403 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2404 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; |
| 2405 | struct _sas_device *sas_device = NULL; |
| 2406 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2407 | char *device_str = NULL; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2408 | |
| 2409 | if (!priv_target) |
| 2410 | return; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2411 | if (ioc->hide_ir_msg) |
| 2412 | device_str = "WarpDrive"; |
| 2413 | else |
| 2414 | device_str = "volume"; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2415 | |
| 2416 | scsi_print_command(scmd); |
| 2417 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2418 | starget_printk(KERN_INFO, starget, "%s handle(0x%04x), " |
| 2419 | "%s wwid(0x%016llx)\n", device_str, priv_target->handle, |
| 2420 | device_str, (unsigned long long)priv_target->sas_address); |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2421 | } else { |
| 2422 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2423 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2424 | priv_target->sas_address); |
| 2425 | if (sas_device) { |
| 2426 | if (priv_target->flags & |
| 2427 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2428 | starget_printk(KERN_INFO, starget, |
| 2429 | "volume handle(0x%04x), " |
| 2430 | "volume wwid(0x%016llx)\n", |
| 2431 | sas_device->volume_handle, |
| 2432 | (unsigned long long)sas_device->volume_wwid); |
| 2433 | } |
| 2434 | starget_printk(KERN_INFO, starget, |
| 2435 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", |
| 2436 | sas_device->handle, |
| 2437 | (unsigned long long)sas_device->sas_address, |
| 2438 | sas_device->phy); |
| 2439 | starget_printk(KERN_INFO, starget, |
| 2440 | "enclosure_logical_id(0x%016llx), slot(%d)\n", |
| 2441 | (unsigned long long)sas_device->enclosure_logical_id, |
| 2442 | sas_device->slot); |
| 2443 | } |
| 2444 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2445 | } |
| 2446 | } |
| 2447 | |
| 2448 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2449 | * _scsih_abort - eh threads main abort routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2450 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2451 | * |
| 2452 | * Returns SUCCESS if command aborted else FAILED |
| 2453 | */ |
| 2454 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2455 | _scsih_abort(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2456 | { |
| 2457 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2458 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2459 | u16 smid; |
| 2460 | u16 handle; |
| 2461 | int r; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2462 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2463 | sdev_printk(KERN_INFO, scmd->device, "attempting task abort! " |
| 2464 | "scmd(%p)\n", scmd); |
| 2465 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2466 | |
| 2467 | sas_device_priv_data = scmd->device->hostdata; |
| 2468 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2469 | sdev_printk(KERN_INFO, scmd->device, "device been deleted! " |
| 2470 | "scmd(%p)\n", scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2471 | scmd->result = DID_NO_CONNECT << 16; |
| 2472 | scmd->scsi_done(scmd); |
| 2473 | r = SUCCESS; |
| 2474 | goto out; |
| 2475 | } |
| 2476 | |
| 2477 | /* search for the command */ |
| 2478 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); |
| 2479 | if (!smid) { |
| 2480 | scmd->result = DID_RESET << 16; |
| 2481 | r = SUCCESS; |
| 2482 | goto out; |
| 2483 | } |
| 2484 | |
| 2485 | /* for hidden raid components and volumes this is not supported */ |
| 2486 | if (sas_device_priv_data->sas_target->flags & |
| 2487 | MPT_TARGET_FLAGS_RAID_COMPONENT || |
| 2488 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 2489 | scmd->result = DID_RESET << 16; |
| 2490 | r = FAILED; |
| 2491 | goto out; |
| 2492 | } |
| 2493 | |
Kashyap, Desai | fa7f316 | 2009-09-23 17:26:58 +0530 | [diff] [blame] | 2494 | mpt2sas_halt_firmware(ioc); |
| 2495 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2496 | handle = sas_device_priv_data->sas_target->handle; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2497 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2498 | scmd->device->id, scmd->device->lun, |
| 2499 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2500 | |
| 2501 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2502 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", |
| 2503 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2504 | return r; |
| 2505 | } |
| 2506 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2507 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2508 | * _scsih_dev_reset - eh threads main device reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2509 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2510 | * |
| 2511 | * Returns SUCCESS if command aborted else FAILED |
| 2512 | */ |
| 2513 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2514 | _scsih_dev_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2515 | { |
| 2516 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2517 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2518 | struct _sas_device *sas_device; |
| 2519 | unsigned long flags; |
| 2520 | u16 handle; |
| 2521 | int r; |
| 2522 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2523 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2524 | |
Kashyap, Desai | 37aaa78 | 2010-11-13 04:41:32 +0530 | [diff] [blame] | 2525 | starget_printk(KERN_INFO, starget, "attempting device reset! " |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2526 | "scmd(%p)\n", scmd); |
| 2527 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2528 | |
| 2529 | sas_device_priv_data = scmd->device->hostdata; |
| 2530 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 37aaa78 | 2010-11-13 04:41:32 +0530 | [diff] [blame] | 2531 | starget_printk(KERN_INFO, starget, "device been deleted! " |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2532 | "scmd(%p)\n", scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2533 | scmd->result = DID_NO_CONNECT << 16; |
| 2534 | scmd->scsi_done(scmd); |
| 2535 | r = SUCCESS; |
| 2536 | goto out; |
| 2537 | } |
| 2538 | |
| 2539 | /* for hidden raid components obtain the volume_handle */ |
| 2540 | handle = 0; |
| 2541 | if (sas_device_priv_data->sas_target->flags & |
| 2542 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2543 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2544 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2545 | sas_device_priv_data->sas_target->handle); |
| 2546 | if (sas_device) |
| 2547 | handle = sas_device->volume_handle; |
| 2548 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2549 | } else |
| 2550 | handle = sas_device_priv_data->sas_target->handle; |
| 2551 | |
| 2552 | if (!handle) { |
| 2553 | scmd->result = DID_RESET << 16; |
| 2554 | r = FAILED; |
| 2555 | goto out; |
| 2556 | } |
| 2557 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2558 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2559 | scmd->device->id, scmd->device->lun, |
| 2560 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2561 | |
| 2562 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2563 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", |
| 2564 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2565 | return r; |
| 2566 | } |
| 2567 | |
| 2568 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2569 | * _scsih_target_reset - eh threads main target reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2570 | * @scmd: pointer to scsi command object |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2571 | * |
| 2572 | * Returns SUCCESS if command aborted else FAILED |
| 2573 | */ |
| 2574 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2575 | _scsih_target_reset(struct scsi_cmnd *scmd) |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2576 | { |
| 2577 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2578 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2579 | struct _sas_device *sas_device; |
| 2580 | unsigned long flags; |
| 2581 | u16 handle; |
| 2582 | int r; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2583 | struct scsi_target *starget = scmd->device->sdev_target; |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2584 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2585 | starget_printk(KERN_INFO, starget, "attempting target reset! " |
| 2586 | "scmd(%p)\n", scmd); |
| 2587 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2588 | |
| 2589 | sas_device_priv_data = scmd->device->hostdata; |
| 2590 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2591 | starget_printk(KERN_INFO, starget, "target been deleted! " |
| 2592 | "scmd(%p)\n", scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2593 | scmd->result = DID_NO_CONNECT << 16; |
| 2594 | scmd->scsi_done(scmd); |
| 2595 | r = SUCCESS; |
| 2596 | goto out; |
| 2597 | } |
| 2598 | |
| 2599 | /* for hidden raid components obtain the volume_handle */ |
| 2600 | handle = 0; |
| 2601 | if (sas_device_priv_data->sas_target->flags & |
| 2602 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2603 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2604 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2605 | sas_device_priv_data->sas_target->handle); |
| 2606 | if (sas_device) |
| 2607 | handle = sas_device->volume_handle; |
| 2608 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2609 | } else |
| 2610 | handle = sas_device_priv_data->sas_target->handle; |
| 2611 | |
| 2612 | if (!handle) { |
| 2613 | scmd->result = DID_RESET << 16; |
| 2614 | r = FAILED; |
| 2615 | goto out; |
| 2616 | } |
| 2617 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2618 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2619 | scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, |
| 2620 | 30, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2621 | |
| 2622 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2623 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", |
| 2624 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2625 | return r; |
| 2626 | } |
| 2627 | |
| 2628 | /** |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2629 | * _scsih_host_reset - eh threads main host reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2630 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2631 | * |
| 2632 | * Returns SUCCESS if command aborted else FAILED |
| 2633 | */ |
| 2634 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2635 | _scsih_host_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2636 | { |
| 2637 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2638 | int r, retval; |
| 2639 | |
| 2640 | printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n", |
| 2641 | ioc->name, scmd); |
| 2642 | scsi_print_command(scmd); |
| 2643 | |
| 2644 | retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2645 | FORCE_BIG_HAMMER); |
| 2646 | r = (retval < 0) ? FAILED : SUCCESS; |
| 2647 | printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n", |
| 2648 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 2649 | |
| 2650 | return r; |
| 2651 | } |
| 2652 | |
| 2653 | /** |
| 2654 | * _scsih_fw_event_add - insert and queue up fw_event |
| 2655 | * @ioc: per adapter object |
| 2656 | * @fw_event: object describing the event |
| 2657 | * Context: This function will acquire ioc->fw_event_lock. |
| 2658 | * |
| 2659 | * This adds the firmware event object into link list, then queues it up to |
| 2660 | * be processed from user context. |
| 2661 | * |
| 2662 | * Return nothing. |
| 2663 | */ |
| 2664 | static void |
| 2665 | _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event) |
| 2666 | { |
| 2667 | unsigned long flags; |
| 2668 | |
| 2669 | if (ioc->firmware_event_thread == NULL) |
| 2670 | return; |
| 2671 | |
| 2672 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2673 | list_add_tail(&fw_event->list, &ioc->fw_event_list); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2674 | INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work); |
| 2675 | queue_delayed_work(ioc->firmware_event_thread, |
| 2676 | &fw_event->delayed_work, 0); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2677 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2678 | } |
| 2679 | |
| 2680 | /** |
| 2681 | * _scsih_fw_event_free - delete fw_event |
| 2682 | * @ioc: per adapter object |
| 2683 | * @fw_event: object describing the event |
| 2684 | * Context: This function will acquire ioc->fw_event_lock. |
| 2685 | * |
| 2686 | * This removes firmware event object from link list, frees associated memory. |
| 2687 | * |
| 2688 | * Return nothing. |
| 2689 | */ |
| 2690 | static void |
| 2691 | _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work |
| 2692 | *fw_event) |
| 2693 | { |
| 2694 | unsigned long flags; |
| 2695 | |
| 2696 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2697 | list_del(&fw_event->list); |
| 2698 | kfree(fw_event->event_data); |
| 2699 | kfree(fw_event); |
| 2700 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2701 | } |
| 2702 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2703 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2704 | /** |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2705 | * _scsih_queue_rescan - queue a topology rescan from user context |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2706 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2707 | * |
| 2708 | * Return nothing. |
| 2709 | */ |
| 2710 | static void |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2711 | _scsih_queue_rescan(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2712 | { |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2713 | struct fw_event_work *fw_event; |
| 2714 | |
| 2715 | if (ioc->wait_for_port_enable_to_complete) |
| 2716 | return; |
| 2717 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2718 | if (!fw_event) |
| 2719 | return; |
| 2720 | fw_event->event = MPT2SAS_RESCAN_AFTER_HOST_RESET; |
| 2721 | fw_event->ioc = ioc; |
| 2722 | _scsih_fw_event_add(ioc, fw_event); |
| 2723 | } |
| 2724 | |
| 2725 | /** |
| 2726 | * _scsih_fw_event_cleanup_queue - cleanup event queue |
| 2727 | * @ioc: per adapter object |
| 2728 | * |
| 2729 | * Walk the firmware event queue, either killing timers, or waiting |
| 2730 | * for outstanding events to complete |
| 2731 | * |
| 2732 | * Return nothing. |
| 2733 | */ |
| 2734 | static void |
| 2735 | _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc) |
| 2736 | { |
| 2737 | struct fw_event_work *fw_event, *next; |
| 2738 | |
| 2739 | if (list_empty(&ioc->fw_event_list) || |
| 2740 | !ioc->firmware_event_thread || in_interrupt()) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2741 | return; |
| 2742 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2743 | list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) { |
| 2744 | if (cancel_delayed_work(&fw_event->delayed_work)) { |
| 2745 | _scsih_fw_event_free(ioc, fw_event); |
| 2746 | continue; |
| 2747 | } |
| 2748 | fw_event->cancel_pending_work = 1; |
| 2749 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2750 | } |
| 2751 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2752 | /** |
| 2753 | * _scsih_ublock_io_device - set the device state to SDEV_RUNNING |
| 2754 | * @ioc: per adapter object |
| 2755 | * @handle: device handle |
| 2756 | * |
| 2757 | * During device pull we need to appropiately set the sdev state. |
| 2758 | */ |
| 2759 | static void |
| 2760 | _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2761 | { |
| 2762 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2763 | struct scsi_device *sdev; |
| 2764 | |
| 2765 | shost_for_each_device(sdev, ioc->shost) { |
| 2766 | sas_device_priv_data = sdev->hostdata; |
| 2767 | if (!sas_device_priv_data) |
| 2768 | continue; |
| 2769 | if (!sas_device_priv_data->block) |
| 2770 | continue; |
| 2771 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2772 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2773 | MPT2SAS_INFO_FMT "SDEV_RUNNING: " |
| 2774 | "handle(0x%04x)\n", ioc->name, handle)); |
| 2775 | sas_device_priv_data->block = 0; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 2776 | scsi_internal_device_unblock(sdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2777 | } |
| 2778 | } |
| 2779 | } |
| 2780 | |
| 2781 | /** |
| 2782 | * _scsih_block_io_device - set the device state to SDEV_BLOCK |
| 2783 | * @ioc: per adapter object |
| 2784 | * @handle: device handle |
| 2785 | * |
| 2786 | * During device pull we need to appropiately set the sdev state. |
| 2787 | */ |
| 2788 | static void |
| 2789 | _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2790 | { |
| 2791 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2792 | struct scsi_device *sdev; |
| 2793 | |
| 2794 | shost_for_each_device(sdev, ioc->shost) { |
| 2795 | sas_device_priv_data = sdev->hostdata; |
| 2796 | if (!sas_device_priv_data) |
| 2797 | continue; |
| 2798 | if (sas_device_priv_data->block) |
| 2799 | continue; |
| 2800 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2801 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2802 | MPT2SAS_INFO_FMT "SDEV_BLOCK: " |
| 2803 | "handle(0x%04x)\n", ioc->name, handle)); |
| 2804 | sas_device_priv_data->block = 1; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 2805 | scsi_internal_device_block(sdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2806 | } |
| 2807 | } |
| 2808 | } |
| 2809 | |
| 2810 | /** |
| 2811 | * _scsih_block_io_to_children_attached_to_ex |
| 2812 | * @ioc: per adapter object |
| 2813 | * @sas_expander: the sas_device object |
| 2814 | * |
| 2815 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 2816 | * attached to this expander. This function called when expander is |
| 2817 | * pulled. |
| 2818 | */ |
| 2819 | static void |
| 2820 | _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc, |
| 2821 | struct _sas_node *sas_expander) |
| 2822 | { |
| 2823 | struct _sas_port *mpt2sas_port; |
| 2824 | struct _sas_device *sas_device; |
| 2825 | struct _sas_node *expander_sibling; |
| 2826 | unsigned long flags; |
| 2827 | |
| 2828 | if (!sas_expander) |
| 2829 | return; |
| 2830 | |
| 2831 | list_for_each_entry(mpt2sas_port, |
| 2832 | &sas_expander->sas_port_list, port_list) { |
| 2833 | if (mpt2sas_port->remote_identify.device_type == |
| 2834 | SAS_END_DEVICE) { |
| 2835 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2836 | sas_device = |
| 2837 | mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2838 | mpt2sas_port->remote_identify.sas_address); |
| 2839 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2840 | if (!sas_device) |
| 2841 | continue; |
| 2842 | _scsih_block_io_device(ioc, sas_device->handle); |
| 2843 | } |
| 2844 | } |
| 2845 | |
| 2846 | list_for_each_entry(mpt2sas_port, |
| 2847 | &sas_expander->sas_port_list, port_list) { |
| 2848 | |
| 2849 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 2850 | SAS_EDGE_EXPANDER_DEVICE || |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2851 | mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 2852 | SAS_FANOUT_EXPANDER_DEVICE) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2853 | |
| 2854 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 2855 | expander_sibling = |
| 2856 | mpt2sas_scsih_expander_find_by_sas_address( |
| 2857 | ioc, mpt2sas_port->remote_identify.sas_address); |
| 2858 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 2859 | _scsih_block_io_to_children_attached_to_ex(ioc, |
| 2860 | expander_sibling); |
| 2861 | } |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | /** |
| 2866 | * _scsih_block_io_to_children_attached_directly |
| 2867 | * @ioc: per adapter object |
| 2868 | * @event_data: topology change event data |
| 2869 | * |
| 2870 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 2871 | * direct attached during device pull. |
| 2872 | */ |
| 2873 | static void |
| 2874 | _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc, |
| 2875 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 2876 | { |
| 2877 | int i; |
| 2878 | u16 handle; |
| 2879 | u16 reason_code; |
| 2880 | u8 phy_number; |
| 2881 | |
| 2882 | for (i = 0; i < event_data->NumEntries; i++) { |
| 2883 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 2884 | if (!handle) |
| 2885 | continue; |
| 2886 | phy_number = event_data->StartPhyNum + i; |
| 2887 | reason_code = event_data->PHY[i].PhyStatus & |
| 2888 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 2889 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) |
| 2890 | _scsih_block_io_device(ioc, handle); |
| 2891 | } |
| 2892 | } |
| 2893 | |
| 2894 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2895 | * _scsih_tm_tr_send - send task management request |
| 2896 | * @ioc: per adapter object |
| 2897 | * @handle: device handle |
| 2898 | * Context: interrupt time. |
| 2899 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2900 | * This code is to initiate the device removal handshake protocol |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2901 | * with controller firmware. This function will issue target reset |
| 2902 | * using high priority request queue. It will send a sas iounit |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2903 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2904 | * |
| 2905 | * This is designed to send muliple task management request at the same |
| 2906 | * time to the fifo. If the fifo is full, we will append the request, |
| 2907 | * and process it in a future completion. |
| 2908 | */ |
| 2909 | static void |
| 2910 | _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2911 | { |
| 2912 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2913 | u16 smid; |
| 2914 | struct _sas_device *sas_device; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 2915 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2916 | unsigned long flags; |
| 2917 | struct _tr_list *delayed_tr; |
| 2918 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 2919 | if (ioc->shost_recovery || ioc->remove_host || |
| 2920 | ioc->pci_error_recovery) { |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 2921 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 2922 | "progress!\n", __func__, ioc->name)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2923 | return; |
| 2924 | } |
| 2925 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 2926 | /* if PD, then return */ |
| 2927 | if (test_bit(handle, ioc->pd_handles)) |
| 2928 | return; |
| 2929 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2930 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2931 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 2932 | if (sas_device && sas_device->starget && |
| 2933 | sas_device->starget->hostdata) { |
| 2934 | sas_target_priv_data = sas_device->starget->hostdata; |
| 2935 | sas_target_priv_data->deleted = 1; |
| 2936 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 2937 | "setting delete flag: handle(0x%04x), " |
| 2938 | "sas_addr(0x%016llx)\n", ioc->name, handle, |
| 2939 | (unsigned long long) sas_device->sas_address)); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 2940 | } |
| 2941 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2942 | |
| 2943 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); |
| 2944 | if (!smid) { |
| 2945 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 2946 | if (!delayed_tr) |
| 2947 | return; |
| 2948 | INIT_LIST_HEAD(&delayed_tr->list); |
| 2949 | delayed_tr->handle = handle; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 2950 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 2951 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 2952 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 2953 | ioc->name, handle)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2954 | return; |
| 2955 | } |
| 2956 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 2957 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " |
| 2958 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, |
| 2959 | ioc->tm_tr_cb_idx)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2960 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 2961 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 2962 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 2963 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 2964 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2965 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
| 2966 | } |
| 2967 | |
| 2968 | |
| 2969 | |
| 2970 | /** |
| 2971 | * _scsih_sas_control_complete - completion routine |
| 2972 | * @ioc: per adapter object |
| 2973 | * @smid: system request message index |
| 2974 | * @msix_index: MSIX table index supplied by the OS |
| 2975 | * @reply: reply message frame(lower 32bit addr) |
| 2976 | * Context: interrupt time. |
| 2977 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2978 | * This is the sas iounit control completion routine. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2979 | * This code is part of the code to initiate the device removal |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2980 | * handshake protocol with controller firmware. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2981 | * |
| 2982 | * Return 1 meaning mf should be freed from _base_interrupt |
| 2983 | * 0 means the mf is freed from this function. |
| 2984 | */ |
| 2985 | static u8 |
| 2986 | _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 2987 | u8 msix_index, u32 reply) |
| 2988 | { |
Kashyap, Desai | 363fa50f | 2010-11-13 04:29:20 +0530 | [diff] [blame] | 2989 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2990 | Mpi2SasIoUnitControlReply_t *mpi_reply = |
| 2991 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
Kashyap, Desai | 363fa50f | 2010-11-13 04:29:20 +0530 | [diff] [blame] | 2992 | #endif |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 2993 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 2994 | "sc_complete:handle(0x%04x), (open) " |
| 2995 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 2996 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, |
| 2997 | le16_to_cpu(mpi_reply->IOCStatus), |
| 2998 | le32_to_cpu(mpi_reply->IOCLogInfo))); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2999 | return 1; |
| 3000 | } |
| 3001 | |
| 3002 | /** |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3003 | * _scsih_tm_tr_volume_send - send target reset request for volumes |
| 3004 | * @ioc: per adapter object |
| 3005 | * @handle: device handle |
| 3006 | * Context: interrupt time. |
| 3007 | * |
| 3008 | * This is designed to send muliple task management request at the same |
| 3009 | * time to the fifo. If the fifo is full, we will append the request, |
| 3010 | * and process it in a future completion. |
| 3011 | */ |
| 3012 | static void |
| 3013 | _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3014 | { |
| 3015 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 3016 | u16 smid; |
| 3017 | struct _tr_list *delayed_tr; |
| 3018 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3019 | if (ioc->shost_recovery || ioc->remove_host || |
| 3020 | ioc->pci_error_recovery) { |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3021 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3022 | "progress!\n", __func__, ioc->name)); |
| 3023 | return; |
| 3024 | } |
| 3025 | |
| 3026 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); |
| 3027 | if (!smid) { |
| 3028 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3029 | if (!delayed_tr) |
| 3030 | return; |
| 3031 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3032 | delayed_tr->handle = handle; |
| 3033 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); |
| 3034 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3035 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 3036 | ioc->name, handle)); |
| 3037 | return; |
| 3038 | } |
| 3039 | |
| 3040 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " |
| 3041 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, |
| 3042 | ioc->tm_tr_volume_cb_idx)); |
| 3043 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3044 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 3045 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3046 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3047 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
| 3048 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
| 3049 | } |
| 3050 | |
| 3051 | /** |
| 3052 | * _scsih_tm_volume_tr_complete - target reset completion |
| 3053 | * @ioc: per adapter object |
| 3054 | * @smid: system request message index |
| 3055 | * @msix_index: MSIX table index supplied by the OS |
| 3056 | * @reply: reply message frame(lower 32bit addr) |
| 3057 | * Context: interrupt time. |
| 3058 | * |
| 3059 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3060 | * 0 means the mf is freed from this function. |
| 3061 | */ |
| 3062 | static u8 |
| 3063 | _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 3064 | u8 msix_index, u32 reply) |
| 3065 | { |
| 3066 | u16 handle; |
| 3067 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
| 3068 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3069 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 3070 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3071 | if (ioc->shost_recovery || ioc->remove_host || |
| 3072 | ioc->pci_error_recovery) { |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3073 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3074 | "progress!\n", __func__, ioc->name)); |
| 3075 | return 1; |
| 3076 | } |
| 3077 | |
| 3078 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3079 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3080 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3081 | dewtprintk(ioc, printk("spurious interrupt: " |
| 3082 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle, |
| 3083 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3084 | return 0; |
| 3085 | } |
| 3086 | |
| 3087 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3088 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3089 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3090 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3091 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3092 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3093 | |
| 3094 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3095 | } |
| 3096 | |
| 3097 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3098 | * _scsih_tm_tr_complete - |
| 3099 | * @ioc: per adapter object |
| 3100 | * @smid: system request message index |
| 3101 | * @msix_index: MSIX table index supplied by the OS |
| 3102 | * @reply: reply message frame(lower 32bit addr) |
| 3103 | * Context: interrupt time. |
| 3104 | * |
| 3105 | * This is the target reset completion routine. |
| 3106 | * This code is part of the code to initiate the device removal |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3107 | * handshake protocol with controller firmware. |
| 3108 | * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3109 | * |
| 3110 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3111 | * 0 means the mf is freed from this function. |
| 3112 | */ |
| 3113 | static u8 |
| 3114 | _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 3115 | u32 reply) |
| 3116 | { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3117 | u16 handle; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3118 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3119 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3120 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 3121 | Mpi2SasIoUnitControlRequest_t *mpi_request; |
| 3122 | u16 smid_sas_ctrl; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3123 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3124 | if (ioc->shost_recovery || ioc->remove_host || |
| 3125 | ioc->pci_error_recovery) { |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3126 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3127 | "progress!\n", __func__, ioc->name)); |
| 3128 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3129 | } |
| 3130 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3131 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3132 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3133 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3134 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: " |
| 3135 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle, |
| 3136 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3137 | return 0; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3138 | } |
| 3139 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3140 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3141 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3142 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3143 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3144 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3145 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3146 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3147 | smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); |
| 3148 | if (!smid_sas_ctrl) { |
| 3149 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 3150 | ioc->name, __func__); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3151 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3152 | } |
| 3153 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3154 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), " |
| 3155 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl, |
| 3156 | ioc->tm_sas_control_cb_idx)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3157 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl); |
| 3158 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); |
| 3159 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; |
| 3160 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3161 | mpi_request->DevHandle = mpi_request_tm->DevHandle; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3162 | mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3163 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3164 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3165 | } |
| 3166 | |
| 3167 | /** |
| 3168 | * _scsih_check_for_pending_tm - check for pending task management |
| 3169 | * @ioc: per adapter object |
| 3170 | * @smid: system request message index |
| 3171 | * |
| 3172 | * This will check delayed target reset list, and feed the |
| 3173 | * next reqeust. |
| 3174 | * |
| 3175 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3176 | * 0 means the mf is freed from this function. |
| 3177 | */ |
| 3178 | static u8 |
| 3179 | _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 3180 | { |
| 3181 | struct _tr_list *delayed_tr; |
| 3182 | |
| 3183 | if (!list_empty(&ioc->delayed_tr_volume_list)) { |
| 3184 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, |
| 3185 | struct _tr_list, list); |
| 3186 | mpt2sas_base_free_smid(ioc, smid); |
| 3187 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); |
| 3188 | list_del(&delayed_tr->list); |
| 3189 | kfree(delayed_tr); |
| 3190 | return 0; |
| 3191 | } |
| 3192 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3193 | if (!list_empty(&ioc->delayed_tr_list)) { |
| 3194 | delayed_tr = list_entry(ioc->delayed_tr_list.next, |
| 3195 | struct _tr_list, list); |
| 3196 | mpt2sas_base_free_smid(ioc, smid); |
| 3197 | _scsih_tm_tr_send(ioc, delayed_tr->handle); |
| 3198 | list_del(&delayed_tr->list); |
| 3199 | kfree(delayed_tr); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3200 | return 0; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3201 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3202 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3203 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3204 | } |
| 3205 | |
| 3206 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3207 | * _scsih_check_topo_delete_events - sanity check on topo events |
| 3208 | * @ioc: per adapter object |
| 3209 | * @event_data: the event data payload |
| 3210 | * |
| 3211 | * This routine added to better handle cable breaker. |
| 3212 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3213 | * This handles the case where driver receives multiple expander |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3214 | * add and delete events in a single shot. When there is a delete event |
| 3215 | * the routine will void any pending add events waiting in the event queue. |
| 3216 | * |
| 3217 | * Return nothing. |
| 3218 | */ |
| 3219 | static void |
| 3220 | _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 3221 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3222 | { |
| 3223 | struct fw_event_work *fw_event; |
| 3224 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; |
| 3225 | u16 expander_handle; |
| 3226 | struct _sas_node *sas_expander; |
| 3227 | unsigned long flags; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3228 | int i, reason_code; |
| 3229 | u16 handle; |
| 3230 | |
| 3231 | for (i = 0 ; i < event_data->NumEntries; i++) { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3232 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3233 | if (!handle) |
| 3234 | continue; |
| 3235 | reason_code = event_data->PHY[i].PhyStatus & |
| 3236 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3237 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) |
| 3238 | _scsih_tm_tr_send(ioc, handle); |
| 3239 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3240 | |
| 3241 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 3242 | if (expander_handle < ioc->sas_hba.num_phys) { |
| 3243 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3244 | return; |
| 3245 | } |
| 3246 | |
| 3247 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING |
| 3248 | || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) { |
| 3249 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 3250 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 3251 | expander_handle); |
| 3252 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 3253 | _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); |
| 3254 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) |
| 3255 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3256 | |
| 3257 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) |
| 3258 | return; |
| 3259 | |
| 3260 | /* mark ignore flag for pending events */ |
| 3261 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 3262 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { |
| 3263 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || |
| 3264 | fw_event->ignore) |
| 3265 | continue; |
| 3266 | local_event_data = fw_event->event_data; |
| 3267 | if (local_event_data->ExpStatus == |
| 3268 | MPI2_EVENT_SAS_TOPO_ES_ADDED || |
| 3269 | local_event_data->ExpStatus == |
| 3270 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { |
| 3271 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == |
| 3272 | expander_handle) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 3273 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3274 | "setting ignoring flag\n", ioc->name)); |
| 3275 | fw_event->ignore = 1; |
| 3276 | } |
| 3277 | } |
| 3278 | } |
| 3279 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 3280 | } |
| 3281 | |
| 3282 | /** |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3283 | * _scsih_set_volume_delete_flag - setting volume delete flag |
| 3284 | * @ioc: per adapter object |
| 3285 | * @handle: device handle |
| 3286 | * |
| 3287 | * This |
| 3288 | * Return nothing. |
| 3289 | */ |
| 3290 | static void |
| 3291 | _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3292 | { |
| 3293 | struct _raid_device *raid_device; |
| 3294 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 3295 | unsigned long flags; |
| 3296 | |
| 3297 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 3298 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 3299 | if (raid_device && raid_device->starget && |
| 3300 | raid_device->starget->hostdata) { |
| 3301 | sas_target_priv_data = |
| 3302 | raid_device->starget->hostdata; |
| 3303 | sas_target_priv_data->deleted = 1; |
| 3304 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3305 | "setting delete flag: handle(0x%04x), " |
| 3306 | "wwid(0x%016llx)\n", ioc->name, handle, |
| 3307 | (unsigned long long) raid_device->wwid)); |
| 3308 | } |
| 3309 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 3310 | } |
| 3311 | |
| 3312 | /** |
| 3313 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume |
| 3314 | * @handle: input handle |
| 3315 | * @a: handle for volume a |
| 3316 | * @b: handle for volume b |
| 3317 | * |
| 3318 | * IR firmware only supports two raid volumes. The purpose of this |
| 3319 | * routine is to set the volume handle in either a or b. When the given |
| 3320 | * input handle is non-zero, or when a and b have not been set before. |
| 3321 | */ |
| 3322 | static void |
| 3323 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) |
| 3324 | { |
| 3325 | if (!handle || handle == *a || handle == *b) |
| 3326 | return; |
| 3327 | if (!*a) |
| 3328 | *a = handle; |
| 3329 | else if (!*b) |
| 3330 | *b = handle; |
| 3331 | } |
| 3332 | |
| 3333 | /** |
| 3334 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events |
| 3335 | * @ioc: per adapter object |
| 3336 | * @event_data: the event data payload |
| 3337 | * Context: interrupt time. |
| 3338 | * |
| 3339 | * This routine will send target reset to volume, followed by target |
| 3340 | * resets to the PDs. This is called when a PD has been removed, or |
| 3341 | * volume has been deleted or removed. When the target reset is sent |
| 3342 | * to volume, the PD target resets need to be queued to start upon |
| 3343 | * completion of the volume target reset. |
| 3344 | * |
| 3345 | * Return nothing. |
| 3346 | */ |
| 3347 | static void |
| 3348 | _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc, |
| 3349 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 3350 | { |
| 3351 | Mpi2EventIrConfigElement_t *element; |
| 3352 | int i; |
| 3353 | u16 handle, volume_handle, a, b; |
| 3354 | struct _tr_list *delayed_tr; |
| 3355 | |
| 3356 | a = 0; |
| 3357 | b = 0; |
| 3358 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3359 | if (ioc->is_warpdrive) |
| 3360 | return; |
| 3361 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3362 | /* Volume Resets for Deleted or Removed */ |
| 3363 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3364 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3365 | if (element->ReasonCode == |
| 3366 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || |
| 3367 | element->ReasonCode == |
| 3368 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { |
| 3369 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3370 | _scsih_set_volume_delete_flag(ioc, volume_handle); |
| 3371 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3372 | } |
| 3373 | } |
| 3374 | |
| 3375 | /* Volume Resets for UNHIDE events */ |
| 3376 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3377 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3378 | if (le32_to_cpu(event_data->Flags) & |
| 3379 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) |
| 3380 | continue; |
| 3381 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { |
| 3382 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3383 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | if (a) |
| 3388 | _scsih_tm_tr_volume_send(ioc, a); |
| 3389 | if (b) |
| 3390 | _scsih_tm_tr_volume_send(ioc, b); |
| 3391 | |
| 3392 | /* PD target resets */ |
| 3393 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3394 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3395 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) |
| 3396 | continue; |
| 3397 | handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 3398 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3399 | clear_bit(handle, ioc->pd_handles); |
| 3400 | if (!volume_handle) |
| 3401 | _scsih_tm_tr_send(ioc, handle); |
| 3402 | else if (volume_handle == a || volume_handle == b) { |
| 3403 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3404 | BUG_ON(!delayed_tr); |
| 3405 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3406 | delayed_tr->handle = handle; |
| 3407 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 3408 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3409 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, |
| 3410 | handle)); |
| 3411 | } else |
| 3412 | _scsih_tm_tr_send(ioc, handle); |
| 3413 | } |
| 3414 | } |
| 3415 | |
| 3416 | |
| 3417 | /** |
| 3418 | * _scsih_check_volume_delete_events - set delete flag for volumes |
| 3419 | * @ioc: per adapter object |
| 3420 | * @event_data: the event data payload |
| 3421 | * Context: interrupt time. |
| 3422 | * |
| 3423 | * This will handle the case when the cable connected to entire volume is |
| 3424 | * pulled. We will take care of setting the deleted flag so normal IO will |
| 3425 | * not be sent. |
| 3426 | * |
| 3427 | * Return nothing. |
| 3428 | */ |
| 3429 | static void |
| 3430 | _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 3431 | Mpi2EventDataIrVolume_t *event_data) |
| 3432 | { |
| 3433 | u32 state; |
| 3434 | |
| 3435 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 3436 | return; |
| 3437 | state = le32_to_cpu(event_data->NewValue); |
| 3438 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == |
| 3439 | MPI2_RAID_VOL_STATE_FAILED) |
| 3440 | _scsih_set_volume_delete_flag(ioc, |
| 3441 | le16_to_cpu(event_data->VolDevHandle)); |
| 3442 | } |
| 3443 | |
| 3444 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3445 | * _scsih_flush_running_cmds - completing outstanding commands. |
| 3446 | * @ioc: per adapter object |
| 3447 | * |
| 3448 | * The flushing out of all pending scmd commands following host reset, |
| 3449 | * where all IO is dropped to the floor. |
| 3450 | * |
| 3451 | * Return nothing. |
| 3452 | */ |
| 3453 | static void |
| 3454 | _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc) |
| 3455 | { |
| 3456 | struct scsi_cmnd *scmd; |
| 3457 | u16 smid; |
| 3458 | u16 count = 0; |
| 3459 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3460 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 3461 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3462 | if (!scmd) |
| 3463 | continue; |
| 3464 | count++; |
| 3465 | mpt2sas_base_free_smid(ioc, smid); |
| 3466 | scsi_dma_unmap(scmd); |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3467 | if (ioc->pci_error_recovery) |
| 3468 | scmd->result = DID_NO_CONNECT << 16; |
| 3469 | else |
| 3470 | scmd->result = DID_RESET << 16; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3471 | scmd->scsi_done(scmd); |
| 3472 | } |
| 3473 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n", |
| 3474 | ioc->name, count)); |
| 3475 | } |
| 3476 | |
| 3477 | /** |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3478 | * _scsih_setup_eedp - setup MPI request for EEDP transfer |
| 3479 | * @scmd: pointer to scsi command object |
| 3480 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3481 | * |
| 3482 | * Supporting protection 1 and 3. |
| 3483 | * |
| 3484 | * Returns nothing |
| 3485 | */ |
| 3486 | static void |
| 3487 | _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request) |
| 3488 | { |
| 3489 | u16 eedp_flags; |
| 3490 | unsigned char prot_op = scsi_get_prot_op(scmd); |
| 3491 | unsigned char prot_type = scsi_get_prot_type(scmd); |
| 3492 | |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3493 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3494 | return; |
| 3495 | |
| 3496 | if (prot_op == SCSI_PROT_READ_STRIP) |
| 3497 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; |
| 3498 | else if (prot_op == SCSI_PROT_WRITE_INSERT) |
| 3499 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; |
| 3500 | else |
| 3501 | return; |
| 3502 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3503 | switch (prot_type) { |
| 3504 | case SCSI_PROT_DIF_TYPE1: |
| 3505 | |
| 3506 | /* |
| 3507 | * enable ref/guard checking |
| 3508 | * auto increment ref tag |
| 3509 | */ |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3510 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3511 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | |
| 3512 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
| 3513 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = |
| 3514 | cpu_to_be32(scsi_get_lba(scmd)); |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3515 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3516 | |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3517 | case SCSI_PROT_DIF_TYPE2: |
| 3518 | |
| 3519 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
| 3520 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | |
| 3521 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3522 | break; |
| 3523 | |
| 3524 | case SCSI_PROT_DIF_TYPE3: |
| 3525 | |
| 3526 | /* |
| 3527 | * enable guard checking |
| 3528 | */ |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3529 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3530 | break; |
| 3531 | } |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3532 | mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size); |
| 3533 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3534 | } |
| 3535 | |
| 3536 | /** |
| 3537 | * _scsih_eedp_error_handling - return sense code for EEDP errors |
| 3538 | * @scmd: pointer to scsi command object |
| 3539 | * @ioc_status: ioc status |
| 3540 | * |
| 3541 | * Returns nothing |
| 3542 | */ |
| 3543 | static void |
| 3544 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) |
| 3545 | { |
| 3546 | u8 ascq; |
| 3547 | u8 sk; |
| 3548 | u8 host_byte; |
| 3549 | |
| 3550 | switch (ioc_status) { |
| 3551 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 3552 | ascq = 0x01; |
| 3553 | break; |
| 3554 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 3555 | ascq = 0x02; |
| 3556 | break; |
| 3557 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 3558 | ascq = 0x03; |
| 3559 | break; |
| 3560 | default: |
| 3561 | ascq = 0x00; |
| 3562 | break; |
| 3563 | } |
| 3564 | |
| 3565 | if (scmd->sc_data_direction == DMA_TO_DEVICE) { |
| 3566 | sk = ILLEGAL_REQUEST; |
| 3567 | host_byte = DID_ABORT; |
| 3568 | } else { |
| 3569 | sk = ABORTED_COMMAND; |
| 3570 | host_byte = DID_OK; |
| 3571 | } |
| 3572 | |
| 3573 | scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq); |
| 3574 | scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) | |
| 3575 | SAM_STAT_CHECK_CONDITION; |
| 3576 | } |
| 3577 | |
| 3578 | /** |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3579 | * _scsih_scsi_direct_io_get - returns direct io flag |
| 3580 | * @ioc: per adapter object |
| 3581 | * @smid: system request message index |
| 3582 | * |
| 3583 | * Returns the smid stored scmd pointer. |
| 3584 | */ |
| 3585 | static inline u8 |
| 3586 | _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 3587 | { |
| 3588 | return ioc->scsi_lookup[smid - 1].direct_io; |
| 3589 | } |
| 3590 | |
| 3591 | /** |
| 3592 | * _scsih_scsi_direct_io_set - sets direct io flag |
| 3593 | * @ioc: per adapter object |
| 3594 | * @smid: system request message index |
| 3595 | * @direct_io: Zero or non-zero value to set in the direct_io flag |
| 3596 | * |
| 3597 | * Returns Nothing. |
| 3598 | */ |
| 3599 | static inline void |
| 3600 | _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io) |
| 3601 | { |
| 3602 | ioc->scsi_lookup[smid - 1].direct_io = direct_io; |
| 3603 | } |
| 3604 | |
| 3605 | |
| 3606 | /** |
| 3607 | * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O |
| 3608 | * @ioc: per adapter object |
| 3609 | * @scmd: pointer to scsi command object |
| 3610 | * @raid_device: pointer to raid device data structure |
| 3611 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3612 | * @smid: system request message index |
| 3613 | * |
| 3614 | * Returns nothing |
| 3615 | */ |
| 3616 | static void |
| 3617 | _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 3618 | struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request, |
| 3619 | u16 smid) |
| 3620 | { |
| 3621 | u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size; |
| 3622 | u32 stripe_sz, stripe_exp; |
| 3623 | u8 num_pds, *cdb_ptr, *tmp_ptr, *lba_ptr1, *lba_ptr2; |
| 3624 | u8 cdb0 = scmd->cmnd[0]; |
| 3625 | |
| 3626 | /* |
| 3627 | * Try Direct I/O to RAID memeber disks |
| 3628 | */ |
| 3629 | if (cdb0 == READ_16 || cdb0 == READ_10 || |
| 3630 | cdb0 == WRITE_16 || cdb0 == WRITE_10) { |
| 3631 | cdb_ptr = mpi_request->CDB.CDB32; |
| 3632 | |
| 3633 | if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4] |
| 3634 | | cdb_ptr[5])) { |
| 3635 | io_size = scsi_bufflen(scmd) >> 9; |
| 3636 | /* get virtual lba */ |
| 3637 | lba_ptr1 = lba_ptr2 = (cdb0 < READ_16) ? &cdb_ptr[2] : |
| 3638 | &cdb_ptr[6]; |
| 3639 | tmp_ptr = (u8 *)&v_lba + 3; |
| 3640 | *tmp_ptr-- = *lba_ptr1++; |
| 3641 | *tmp_ptr-- = *lba_ptr1++; |
| 3642 | *tmp_ptr-- = *lba_ptr1++; |
| 3643 | *tmp_ptr = *lba_ptr1; |
| 3644 | |
| 3645 | if (((u64)v_lba + (u64)io_size - 1) <= |
| 3646 | (u32)raid_device->max_lba) { |
| 3647 | stripe_sz = raid_device->stripe_sz; |
| 3648 | stripe_exp = raid_device->stripe_exponent; |
| 3649 | stripe_off = v_lba & (stripe_sz - 1); |
| 3650 | |
| 3651 | /* Check whether IO falls within a stripe */ |
| 3652 | if ((stripe_off + io_size) <= stripe_sz) { |
| 3653 | num_pds = raid_device->num_pds; |
| 3654 | p_lba = v_lba >> stripe_exp; |
| 3655 | stripe_unit = p_lba / num_pds; |
| 3656 | column = p_lba % num_pds; |
| 3657 | p_lba = (stripe_unit << stripe_exp) + |
| 3658 | stripe_off; |
| 3659 | mpi_request->DevHandle = |
| 3660 | cpu_to_le16(raid_device-> |
| 3661 | pd_handle[column]); |
| 3662 | tmp_ptr = (u8 *)&p_lba + 3; |
| 3663 | *lba_ptr2++ = *tmp_ptr--; |
| 3664 | *lba_ptr2++ = *tmp_ptr--; |
| 3665 | *lba_ptr2++ = *tmp_ptr--; |
| 3666 | *lba_ptr2 = *tmp_ptr; |
| 3667 | /* |
| 3668 | * WD: To indicate this I/O is directI/O |
| 3669 | */ |
| 3670 | _scsih_scsi_direct_io_set(ioc, smid, 1); |
| 3671 | } |
| 3672 | } |
| 3673 | } |
| 3674 | } |
| 3675 | } |
| 3676 | |
| 3677 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 3678 | * _scsih_qcmd - main scsi request entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3679 | * @scmd: pointer to scsi command object |
| 3680 | * @done: function pointer to be invoked on completion |
| 3681 | * |
| 3682 | * The callback index is set inside `ioc->scsi_io_cb_idx`. |
| 3683 | * |
| 3684 | * Returns 0 on success. If there's a failure, return either: |
| 3685 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or |
| 3686 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full |
| 3687 | */ |
| 3688 | static int |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 3689 | _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3690 | { |
| 3691 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 3692 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 3693 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3694 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3695 | Mpi2SCSIIORequest_t *mpi_request; |
| 3696 | u32 mpi_control; |
| 3697 | u16 smid; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3698 | |
| 3699 | scmd->scsi_done = done; |
| 3700 | sas_device_priv_data = scmd->device->hostdata; |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3701 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3702 | scmd->result = DID_NO_CONNECT << 16; |
| 3703 | scmd->scsi_done(scmd); |
| 3704 | return 0; |
| 3705 | } |
| 3706 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3707 | if (ioc->pci_error_recovery) { |
| 3708 | scmd->result = DID_NO_CONNECT << 16; |
| 3709 | scmd->scsi_done(scmd); |
| 3710 | return 0; |
| 3711 | } |
| 3712 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3713 | sas_target_priv_data = sas_device_priv_data->sas_target; |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3714 | /* invalid device handle */ |
| 3715 | if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3716 | scmd->result = DID_NO_CONNECT << 16; |
| 3717 | scmd->scsi_done(scmd); |
| 3718 | return 0; |
| 3719 | } |
| 3720 | |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3721 | /* host recovery or link resets sent via IOCTLs */ |
| 3722 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3723 | return SCSI_MLQUEUE_HOST_BUSY; |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 3724 | /* device busy with task management */ |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3725 | else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy) |
| 3726 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 3727 | /* device has been deleted */ |
| 3728 | else if (sas_target_priv_data->deleted) { |
| 3729 | scmd->result = DID_NO_CONNECT << 16; |
| 3730 | scmd->scsi_done(scmd); |
| 3731 | return 0; |
| 3732 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3733 | |
| 3734 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) |
| 3735 | mpi_control = MPI2_SCSIIO_CONTROL_READ; |
| 3736 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 3737 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; |
| 3738 | else |
| 3739 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; |
| 3740 | |
| 3741 | /* set tags */ |
| 3742 | if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) { |
| 3743 | if (scmd->device->tagged_supported) { |
| 3744 | if (scmd->device->ordered_tags) |
| 3745 | mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ; |
| 3746 | else |
| 3747 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
| 3748 | } else |
| 3749 | /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */ |
| 3750 | /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED; |
| 3751 | */ |
| 3752 | mpi_control |= (0x500); |
| 3753 | |
| 3754 | } else |
| 3755 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3756 | /* Make sure Device is not raid volume. |
| 3757 | * We do not expose raid functionality to upper layer for warpdrive. |
| 3758 | */ |
| 3759 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3760 | sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3761 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
| 3762 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3763 | 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] | 3764 | if (!smid) { |
| 3765 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 3766 | ioc->name, __func__); |
| 3767 | goto out; |
| 3768 | } |
| 3769 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3770 | memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t)); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3771 | _scsih_setup_eedp(scmd, mpi_request); |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3772 | if (scmd->cmd_len == 32) |
| 3773 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3774 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 3775 | if (sas_device_priv_data->sas_target->flags & |
| 3776 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 3777 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; |
| 3778 | else |
| 3779 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 3780 | mpi_request->DevHandle = |
| 3781 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 3782 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
| 3783 | mpi_request->Control = cpu_to_le32(mpi_control); |
| 3784 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); |
| 3785 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; |
| 3786 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; |
| 3787 | mpi_request->SenseBufferLowAddress = |
Kashyap, Desai | ec9472c | 2009-09-23 17:34:13 +0530 | [diff] [blame] | 3788 | mpt2sas_base_get_sense_buffer_dma(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3789 | mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4; |
| 3790 | mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI + |
| 3791 | MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3792 | mpi_request->VF_ID = 0; /* TODO */ |
| 3793 | mpi_request->VP_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3794 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
| 3795 | mpi_request->LUN); |
| 3796 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 3797 | |
| 3798 | if (!mpi_request->DataLength) { |
| 3799 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL); |
| 3800 | } else { |
| 3801 | if (_scsih_build_scatter_gather(ioc, scmd, smid)) { |
| 3802 | mpt2sas_base_free_smid(ioc, smid); |
| 3803 | goto out; |
| 3804 | } |
| 3805 | } |
| 3806 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3807 | raid_device = sas_target_priv_data->raid_device; |
| 3808 | if (raid_device && raid_device->direct_io_enabled) |
| 3809 | _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request, |
| 3810 | smid); |
| 3811 | |
Kashyap, Desai | 58287fd | 2010-03-17 16:27:25 +0530 | [diff] [blame] | 3812 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) |
| 3813 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3814 | le16_to_cpu(mpi_request->DevHandle)); |
Kashyap, Desai | 58287fd | 2010-03-17 16:27:25 +0530 | [diff] [blame] | 3815 | else |
| 3816 | mpt2sas_base_put_smid_default(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3817 | return 0; |
| 3818 | |
| 3819 | out: |
| 3820 | return SCSI_MLQUEUE_HOST_BUSY; |
| 3821 | } |
| 3822 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 3823 | static DEF_SCSI_QCMD(_scsih_qcmd) |
| 3824 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3825 | /** |
| 3826 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data |
| 3827 | * @sense_buffer: sense data returned by target |
| 3828 | * @data: normalized skey/asc/ascq |
| 3829 | * |
| 3830 | * Return nothing. |
| 3831 | */ |
| 3832 | static void |
| 3833 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) |
| 3834 | { |
| 3835 | if ((sense_buffer[0] & 0x7F) >= 0x72) { |
| 3836 | /* descriptor format */ |
| 3837 | data->skey = sense_buffer[1] & 0x0F; |
| 3838 | data->asc = sense_buffer[2]; |
| 3839 | data->ascq = sense_buffer[3]; |
| 3840 | } else { |
| 3841 | /* fixed format */ |
| 3842 | data->skey = sense_buffer[2] & 0x0F; |
| 3843 | data->asc = sense_buffer[12]; |
| 3844 | data->ascq = sense_buffer[13]; |
| 3845 | } |
| 3846 | } |
| 3847 | |
| 3848 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 3849 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3850 | * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3851 | * @ioc: per adapter object |
| 3852 | * @scmd: pointer to scsi command object |
| 3853 | * @mpi_reply: reply mf payload returned from firmware |
| 3854 | * |
| 3855 | * scsi_status - SCSI Status code returned from target device |
| 3856 | * scsi_state - state info associated with SCSI_IO determined by ioc |
| 3857 | * ioc_status - ioc supplied status info |
| 3858 | * |
| 3859 | * Return nothing. |
| 3860 | */ |
| 3861 | static void |
| 3862 | _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 3863 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) |
| 3864 | { |
| 3865 | u32 response_info; |
| 3866 | u8 *response_bytes; |
| 3867 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & |
| 3868 | MPI2_IOCSTATUS_MASK; |
| 3869 | u8 scsi_state = mpi_reply->SCSIState; |
| 3870 | u8 scsi_status = mpi_reply->SCSIStatus; |
| 3871 | char *desc_ioc_state = NULL; |
| 3872 | char *desc_scsi_status = NULL; |
| 3873 | char *desc_scsi_state = ioc->tmp_string; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 3874 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 3875 | struct _sas_device *sas_device = NULL; |
| 3876 | unsigned long flags; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 3877 | struct scsi_target *starget = scmd->device->sdev_target; |
| 3878 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3879 | char *device_str = NULL; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 3880 | |
| 3881 | if (!priv_target) |
| 3882 | return; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 3883 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3884 | if (ioc->hide_ir_msg) |
| 3885 | device_str = "WarpDrive"; |
| 3886 | else |
| 3887 | device_str = "volume"; |
| 3888 | |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 3889 | if (log_info == 0x31170000) |
| 3890 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3891 | |
| 3892 | switch (ioc_status) { |
| 3893 | case MPI2_IOCSTATUS_SUCCESS: |
| 3894 | desc_ioc_state = "success"; |
| 3895 | break; |
| 3896 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 3897 | desc_ioc_state = "invalid function"; |
| 3898 | break; |
| 3899 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 3900 | desc_ioc_state = "scsi recovered error"; |
| 3901 | break; |
| 3902 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: |
| 3903 | desc_ioc_state = "scsi invalid dev handle"; |
| 3904 | break; |
| 3905 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 3906 | desc_ioc_state = "scsi device not there"; |
| 3907 | break; |
| 3908 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 3909 | desc_ioc_state = "scsi data overrun"; |
| 3910 | break; |
| 3911 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 3912 | desc_ioc_state = "scsi data underrun"; |
| 3913 | break; |
| 3914 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 3915 | desc_ioc_state = "scsi io data error"; |
| 3916 | break; |
| 3917 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 3918 | desc_ioc_state = "scsi protocol error"; |
| 3919 | break; |
| 3920 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 3921 | desc_ioc_state = "scsi task terminated"; |
| 3922 | break; |
| 3923 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 3924 | desc_ioc_state = "scsi residual mismatch"; |
| 3925 | break; |
| 3926 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 3927 | desc_ioc_state = "scsi task mgmt failed"; |
| 3928 | break; |
| 3929 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 3930 | desc_ioc_state = "scsi ioc terminated"; |
| 3931 | break; |
| 3932 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 3933 | desc_ioc_state = "scsi ext terminated"; |
| 3934 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3935 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 3936 | desc_ioc_state = "eedp guard error"; |
| 3937 | break; |
| 3938 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 3939 | desc_ioc_state = "eedp ref tag error"; |
| 3940 | break; |
| 3941 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 3942 | desc_ioc_state = "eedp app tag error"; |
| 3943 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3944 | default: |
| 3945 | desc_ioc_state = "unknown"; |
| 3946 | break; |
| 3947 | } |
| 3948 | |
| 3949 | switch (scsi_status) { |
| 3950 | case MPI2_SCSI_STATUS_GOOD: |
| 3951 | desc_scsi_status = "good"; |
| 3952 | break; |
| 3953 | case MPI2_SCSI_STATUS_CHECK_CONDITION: |
| 3954 | desc_scsi_status = "check condition"; |
| 3955 | break; |
| 3956 | case MPI2_SCSI_STATUS_CONDITION_MET: |
| 3957 | desc_scsi_status = "condition met"; |
| 3958 | break; |
| 3959 | case MPI2_SCSI_STATUS_BUSY: |
| 3960 | desc_scsi_status = "busy"; |
| 3961 | break; |
| 3962 | case MPI2_SCSI_STATUS_INTERMEDIATE: |
| 3963 | desc_scsi_status = "intermediate"; |
| 3964 | break; |
| 3965 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: |
| 3966 | desc_scsi_status = "intermediate condmet"; |
| 3967 | break; |
| 3968 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: |
| 3969 | desc_scsi_status = "reservation conflict"; |
| 3970 | break; |
| 3971 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: |
| 3972 | desc_scsi_status = "command terminated"; |
| 3973 | break; |
| 3974 | case MPI2_SCSI_STATUS_TASK_SET_FULL: |
| 3975 | desc_scsi_status = "task set full"; |
| 3976 | break; |
| 3977 | case MPI2_SCSI_STATUS_ACA_ACTIVE: |
| 3978 | desc_scsi_status = "aca active"; |
| 3979 | break; |
| 3980 | case MPI2_SCSI_STATUS_TASK_ABORTED: |
| 3981 | desc_scsi_status = "task aborted"; |
| 3982 | break; |
| 3983 | default: |
| 3984 | desc_scsi_status = "unknown"; |
| 3985 | break; |
| 3986 | } |
| 3987 | |
| 3988 | desc_scsi_state[0] = '\0'; |
| 3989 | if (!scsi_state) |
| 3990 | desc_scsi_state = " "; |
| 3991 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 3992 | strcat(desc_scsi_state, "response info "); |
| 3993 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 3994 | strcat(desc_scsi_state, "state terminated "); |
| 3995 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) |
| 3996 | strcat(desc_scsi_state, "no status "); |
| 3997 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) |
| 3998 | strcat(desc_scsi_state, "autosense failed "); |
| 3999 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) |
| 4000 | strcat(desc_scsi_state, "autosense valid "); |
| 4001 | |
| 4002 | scsi_print_command(scmd); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4003 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4004 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4005 | printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name, |
| 4006 | device_str, (unsigned long long)priv_target->sas_address); |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4007 | } else { |
| 4008 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4009 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 4010 | priv_target->sas_address); |
| 4011 | if (sas_device) { |
| 4012 | printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), " |
| 4013 | "phy(%d)\n", ioc->name, sas_device->sas_address, |
| 4014 | sas_device->phy); |
| 4015 | printk(MPT2SAS_WARN_FMT |
| 4016 | "\tenclosure_logical_id(0x%016llx), slot(%d)\n", |
| 4017 | ioc->name, sas_device->enclosure_logical_id, |
| 4018 | sas_device->slot); |
| 4019 | } |
| 4020 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4021 | } |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4022 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4023 | printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), " |
| 4024 | "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle), |
| 4025 | desc_ioc_state, ioc_status, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4026 | printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), " |
| 4027 | "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow, |
| 4028 | scsi_get_resid(scmd)); |
| 4029 | printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), " |
| 4030 | "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag), |
| 4031 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); |
| 4032 | printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), " |
| 4033 | "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status, |
| 4034 | scsi_status, desc_scsi_state, scsi_state); |
| 4035 | |
| 4036 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4037 | struct sense_info data; |
| 4038 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4039 | printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: " |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 4040 | "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey, |
| 4041 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4042 | } |
| 4043 | |
| 4044 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { |
| 4045 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); |
| 4046 | response_bytes = (u8 *)&response_info; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4047 | _scsih_response_code(ioc, response_bytes[0]); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4048 | } |
| 4049 | } |
| 4050 | #endif |
| 4051 | |
| 4052 | /** |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame^] | 4053 | * _scsih_turn_on_fault_led - illuminate Fault LED |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4054 | * @ioc: per adapter object |
| 4055 | * @handle: device handle |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame^] | 4056 | * Context: process |
| 4057 | * |
| 4058 | * Return nothing. |
| 4059 | */ |
| 4060 | static void |
| 4061 | _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4062 | { |
| 4063 | Mpi2SepReply_t mpi_reply; |
| 4064 | Mpi2SepRequest_t mpi_request; |
| 4065 | |
| 4066 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
| 4067 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; |
| 4068 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; |
| 4069 | mpi_request.SlotStatus = |
| 4070 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); |
| 4071 | mpi_request.DevHandle = cpu_to_le16(handle); |
| 4072 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; |
| 4073 | if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply, |
| 4074 | &mpi_request)) != 0) { |
| 4075 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 4076 | __FILE__, __LINE__, __func__); |
| 4077 | return; |
| 4078 | } |
| 4079 | |
| 4080 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { |
| 4081 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: " |
| 4082 | "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name, |
| 4083 | le16_to_cpu(mpi_reply.IOCStatus), |
| 4084 | le32_to_cpu(mpi_reply.IOCLogInfo))); |
| 4085 | return; |
| 4086 | } |
| 4087 | } |
| 4088 | |
| 4089 | /** |
| 4090 | * _scsih_send_event_to_turn_on_fault_led - fire delayed event |
| 4091 | * @ioc: per adapter object |
| 4092 | * @handle: device handle |
| 4093 | * Context: interrupt. |
| 4094 | * |
| 4095 | * Return nothing. |
| 4096 | */ |
| 4097 | static void |
| 4098 | _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4099 | { |
| 4100 | struct fw_event_work *fw_event; |
| 4101 | |
| 4102 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 4103 | if (!fw_event) |
| 4104 | return; |
| 4105 | fw_event->event = MPT2SAS_TURN_ON_FAULT_LED; |
| 4106 | fw_event->device_handle = handle; |
| 4107 | fw_event->ioc = ioc; |
| 4108 | _scsih_fw_event_add(ioc, fw_event); |
| 4109 | } |
| 4110 | |
| 4111 | /** |
| 4112 | * _scsih_smart_predicted_fault - process smart errors |
| 4113 | * @ioc: per adapter object |
| 4114 | * @handle: device handle |
| 4115 | * Context: interrupt. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4116 | * |
| 4117 | * Return nothing. |
| 4118 | */ |
| 4119 | static void |
| 4120 | _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4121 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4122 | struct scsi_target *starget; |
| 4123 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 4124 | Mpi2EventNotificationReply_t *event_reply; |
| 4125 | Mpi2EventDataSasDeviceStatusChange_t *event_data; |
| 4126 | struct _sas_device *sas_device; |
| 4127 | ssize_t sz; |
| 4128 | unsigned long flags; |
| 4129 | |
| 4130 | /* only handle non-raid devices */ |
| 4131 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4132 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 4133 | if (!sas_device) { |
| 4134 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4135 | return; |
| 4136 | } |
| 4137 | starget = sas_device->starget; |
| 4138 | sas_target_priv_data = starget->hostdata; |
| 4139 | |
| 4140 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || |
| 4141 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) { |
| 4142 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4143 | return; |
| 4144 | } |
| 4145 | starget_printk(KERN_WARNING, starget, "predicted fault\n"); |
| 4146 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4147 | |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame^] | 4148 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) |
| 4149 | _scsih_send_event_to_turn_on_fault_led(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4150 | |
| 4151 | /* insert into event log */ |
| 4152 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + |
| 4153 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); |
| 4154 | event_reply = kzalloc(sz, GFP_KERNEL); |
| 4155 | if (!event_reply) { |
| 4156 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4157 | ioc->name, __FILE__, __LINE__, __func__); |
| 4158 | return; |
| 4159 | } |
| 4160 | |
| 4161 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; |
| 4162 | event_reply->Event = |
| 4163 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); |
| 4164 | event_reply->MsgLength = sz/4; |
| 4165 | event_reply->EventDataLength = |
| 4166 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); |
| 4167 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) |
| 4168 | event_reply->EventData; |
| 4169 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; |
| 4170 | event_data->ASC = 0x5D; |
| 4171 | event_data->DevHandle = cpu_to_le16(handle); |
| 4172 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); |
| 4173 | mpt2sas_ctl_add_to_event_log(ioc, event_reply); |
| 4174 | kfree(event_reply); |
| 4175 | } |
| 4176 | |
| 4177 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 4178 | * _scsih_io_done - scsi request callback |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4179 | * @ioc: per adapter object |
| 4180 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4181 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4182 | * @reply: reply message frame(lower 32bit addr) |
| 4183 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4184 | * Callback handler when using _scsih_qcmd. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4185 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4186 | * Return 1 meaning mf should be freed from _base_interrupt |
| 4187 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4188 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4189 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4190 | _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] | 4191 | { |
| 4192 | Mpi2SCSIIORequest_t *mpi_request; |
| 4193 | Mpi2SCSIIOReply_t *mpi_reply; |
| 4194 | struct scsi_cmnd *scmd; |
| 4195 | u16 ioc_status; |
| 4196 | u32 xfer_cnt; |
| 4197 | u8 scsi_state; |
| 4198 | u8 scsi_status; |
| 4199 | u32 log_info; |
| 4200 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4201 | u32 response_code = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4202 | |
| 4203 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 4204 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4205 | if (scmd == NULL) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4206 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4207 | |
| 4208 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 4209 | |
| 4210 | if (mpi_reply == NULL) { |
| 4211 | scmd->result = DID_OK << 16; |
| 4212 | goto out; |
| 4213 | } |
| 4214 | |
| 4215 | sas_device_priv_data = scmd->device->hostdata; |
| 4216 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
| 4217 | sas_device_priv_data->sas_target->deleted) { |
| 4218 | scmd->result = DID_NO_CONNECT << 16; |
| 4219 | goto out; |
| 4220 | } |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4221 | /* |
| 4222 | * WARPDRIVE: If direct_io is set then it is directIO, |
| 4223 | * the failed direct I/O should be redirected to volume |
| 4224 | */ |
| 4225 | if (_scsih_scsi_direct_io_get(ioc, smid)) { |
| 4226 | _scsih_scsi_direct_io_set(ioc, smid, 0); |
| 4227 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 4228 | mpi_request->DevHandle = |
| 4229 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 4230 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
| 4231 | sas_device_priv_data->sas_target->handle); |
| 4232 | return 0; |
| 4233 | } |
| 4234 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4235 | |
| 4236 | /* turning off TLR */ |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4237 | scsi_state = mpi_reply->SCSIState; |
| 4238 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 4239 | response_code = |
| 4240 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4241 | if (!sas_device_priv_data->tlr_snoop_check) { |
| 4242 | sas_device_priv_data->tlr_snoop_check++; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4243 | /* Make sure Device is not raid volume. |
| 4244 | * We do not expose raid functionality to upper layer for warpdrive. |
| 4245 | */ |
| 4246 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && |
Kashyap, Desai | 3ed2152 | 2010-02-17 16:08:36 +0530 | [diff] [blame] | 4247 | sas_is_tlr_enabled(scmd->device) && |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 4248 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { |
| 4249 | sas_disable_tlr(scmd->device); |
| 4250 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); |
| 4251 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4252 | } |
| 4253 | |
| 4254 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); |
| 4255 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); |
| 4256 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); |
| 4257 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) |
| 4258 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
| 4259 | else |
| 4260 | log_info = 0; |
| 4261 | ioc_status &= MPI2_IOCSTATUS_MASK; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4262 | scsi_status = mpi_reply->SCSIStatus; |
| 4263 | |
| 4264 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && |
| 4265 | (scsi_status == MPI2_SCSI_STATUS_BUSY || |
| 4266 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || |
| 4267 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { |
| 4268 | ioc_status = MPI2_IOCSTATUS_SUCCESS; |
| 4269 | } |
| 4270 | |
| 4271 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4272 | struct sense_info data; |
| 4273 | const void *sense_data = mpt2sas_base_get_sense_buffer(ioc, |
| 4274 | smid); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 4275 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4276 | le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 4277 | memcpy(scmd->sense_buffer, sense_data, sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4278 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4279 | /* failure prediction threshold exceeded */ |
| 4280 | if (data.asc == 0x5D) |
| 4281 | _scsih_smart_predicted_fault(ioc, |
| 4282 | le16_to_cpu(mpi_reply->DevHandle)); |
| 4283 | } |
| 4284 | |
| 4285 | switch (ioc_status) { |
| 4286 | case MPI2_IOCSTATUS_BUSY: |
| 4287 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: |
| 4288 | scmd->result = SAM_STAT_BUSY; |
| 4289 | break; |
| 4290 | |
| 4291 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 4292 | scmd->result = DID_NO_CONNECT << 16; |
| 4293 | break; |
| 4294 | |
| 4295 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 4296 | if (sas_device_priv_data->block) { |
Kashyap, Desai | e4e7c7e | 2009-09-23 17:33:14 +0530 | [diff] [blame] | 4297 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; |
| 4298 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4299 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4300 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 4301 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 4302 | scmd->result = DID_RESET << 16; |
| 4303 | break; |
| 4304 | |
| 4305 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 4306 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) |
| 4307 | scmd->result = DID_SOFT_ERROR << 16; |
| 4308 | else |
| 4309 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4310 | break; |
| 4311 | |
| 4312 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 4313 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4314 | |
| 4315 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) |
| 4316 | break; |
| 4317 | |
| 4318 | if (xfer_cnt < scmd->underflow) { |
| 4319 | if (scsi_status == SAM_STAT_BUSY) |
| 4320 | scmd->result = SAM_STAT_BUSY; |
| 4321 | else |
| 4322 | scmd->result = DID_SOFT_ERROR << 16; |
| 4323 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4324 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) |
| 4325 | scmd->result = DID_SOFT_ERROR << 16; |
| 4326 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4327 | scmd->result = DID_RESET << 16; |
| 4328 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { |
| 4329 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; |
| 4330 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; |
| 4331 | scmd->result = (DRIVER_SENSE << 24) | |
| 4332 | SAM_STAT_CHECK_CONDITION; |
| 4333 | scmd->sense_buffer[0] = 0x70; |
| 4334 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; |
| 4335 | scmd->sense_buffer[12] = 0x20; |
| 4336 | scmd->sense_buffer[13] = 0; |
| 4337 | } |
| 4338 | break; |
| 4339 | |
| 4340 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 4341 | scsi_set_resid(scmd, 0); |
| 4342 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 4343 | case MPI2_IOCSTATUS_SUCCESS: |
| 4344 | scmd->result = (DID_OK << 16) | scsi_status; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4345 | if (response_code == |
| 4346 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || |
| 4347 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4348 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4349 | scmd->result = DID_SOFT_ERROR << 16; |
| 4350 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4351 | scmd->result = DID_RESET << 16; |
| 4352 | break; |
| 4353 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4354 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 4355 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 4356 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 4357 | _scsih_eedp_error_handling(scmd, ioc_status); |
| 4358 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4359 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 4360 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 4361 | case MPI2_IOCSTATUS_INVALID_SGL: |
| 4362 | case MPI2_IOCSTATUS_INTERNAL_ERROR: |
| 4363 | case MPI2_IOCSTATUS_INVALID_FIELD: |
| 4364 | case MPI2_IOCSTATUS_INVALID_STATE: |
| 4365 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 4366 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 4367 | default: |
| 4368 | scmd->result = DID_SOFT_ERROR << 16; |
| 4369 | break; |
| 4370 | |
| 4371 | } |
| 4372 | |
| 4373 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4374 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
| 4375 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); |
| 4376 | #endif |
| 4377 | |
| 4378 | out: |
| 4379 | scsi_dma_unmap(scmd); |
| 4380 | scmd->scsi_done(scmd); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4381 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4382 | } |
| 4383 | |
| 4384 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4385 | * _scsih_sas_host_refresh - refreshing sas host object contents |
| 4386 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4387 | * Context: user |
| 4388 | * |
| 4389 | * During port enable, fw will send topology events for every device. Its |
| 4390 | * possible that the handles may change from the previous setting, so this |
| 4391 | * code keeping handles updating if changed. |
| 4392 | * |
| 4393 | * Return nothing. |
| 4394 | */ |
| 4395 | static void |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4396 | _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4397 | { |
| 4398 | u16 sz; |
| 4399 | u16 ioc_status; |
| 4400 | int i; |
| 4401 | Mpi2ConfigReply_t mpi_reply; |
| 4402 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4403 | u16 attached_handle; |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4404 | u8 link_rate; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4405 | |
| 4406 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 4407 | "updating handles for sas_host(0x%016llx)\n", |
| 4408 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); |
| 4409 | |
| 4410 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys |
| 4411 | * sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4412 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4413 | if (!sas_iounit_pg0) { |
| 4414 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4415 | ioc->name, __FILE__, __LINE__, __func__); |
| 4416 | return; |
| 4417 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4418 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4419 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4420 | sas_iounit_pg0, sz)) != 0) |
| 4421 | goto out; |
| 4422 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 4423 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 4424 | goto out; |
| 4425 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4426 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4427 | if (i == 0) |
| 4428 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4429 | PhyData[0].ControllerDevHandle); |
| 4430 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
| 4431 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. |
| 4432 | AttachedDevHandle); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4433 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 4434 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4435 | mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address, |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4436 | attached_handle, i, link_rate); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4437 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4438 | out: |
| 4439 | kfree(sas_iounit_pg0); |
| 4440 | } |
| 4441 | |
| 4442 | /** |
| 4443 | * _scsih_sas_host_add - create sas host object |
| 4444 | * @ioc: per adapter object |
| 4445 | * |
| 4446 | * Creating host side data object, stored in ioc->sas_hba |
| 4447 | * |
| 4448 | * Return nothing. |
| 4449 | */ |
| 4450 | static void |
| 4451 | _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc) |
| 4452 | { |
| 4453 | int i; |
| 4454 | Mpi2ConfigReply_t mpi_reply; |
| 4455 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
| 4456 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; |
| 4457 | Mpi2SasPhyPage0_t phy_pg0; |
| 4458 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4459 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4460 | u16 ioc_status; |
| 4461 | u16 sz; |
| 4462 | u16 device_missing_delay; |
| 4463 | |
| 4464 | mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys); |
| 4465 | if (!ioc->sas_hba.num_phys) { |
| 4466 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4467 | ioc->name, __FILE__, __LINE__, __func__); |
| 4468 | return; |
| 4469 | } |
| 4470 | |
| 4471 | /* sas_iounit page 0 */ |
| 4472 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4473 | sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4474 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4475 | if (!sas_iounit_pg0) { |
| 4476 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4477 | ioc->name, __FILE__, __LINE__, __func__); |
| 4478 | return; |
| 4479 | } |
| 4480 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4481 | sas_iounit_pg0, sz))) { |
| 4482 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4483 | ioc->name, __FILE__, __LINE__, __func__); |
| 4484 | goto out; |
| 4485 | } |
| 4486 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4487 | MPI2_IOCSTATUS_MASK; |
| 4488 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4489 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4490 | ioc->name, __FILE__, __LINE__, __func__); |
| 4491 | goto out; |
| 4492 | } |
| 4493 | |
| 4494 | /* sas_iounit page 1 */ |
| 4495 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4496 | sizeof(Mpi2SasIOUnit1PhyData_t)); |
| 4497 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); |
| 4498 | if (!sas_iounit_pg1) { |
| 4499 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4500 | ioc->name, __FILE__, __LINE__, __func__); |
| 4501 | goto out; |
| 4502 | } |
| 4503 | if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, |
| 4504 | sas_iounit_pg1, sz))) { |
| 4505 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4506 | ioc->name, __FILE__, __LINE__, __func__); |
| 4507 | goto out; |
| 4508 | } |
| 4509 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4510 | MPI2_IOCSTATUS_MASK; |
| 4511 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4512 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4513 | ioc->name, __FILE__, __LINE__, __func__); |
| 4514 | goto out; |
| 4515 | } |
| 4516 | |
| 4517 | ioc->io_missing_delay = |
| 4518 | le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay); |
| 4519 | device_missing_delay = |
| 4520 | le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay); |
| 4521 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) |
| 4522 | ioc->device_missing_delay = (device_missing_delay & |
| 4523 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; |
| 4524 | else |
| 4525 | ioc->device_missing_delay = device_missing_delay & |
| 4526 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 4527 | |
| 4528 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; |
| 4529 | ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys, |
| 4530 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4531 | if (!ioc->sas_hba.phy) { |
| 4532 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4533 | ioc->name, __FILE__, __LINE__, __func__); |
| 4534 | goto out; |
| 4535 | } |
| 4536 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
| 4537 | if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, |
| 4538 | i))) { |
| 4539 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4540 | ioc->name, __FILE__, __LINE__, __func__); |
| 4541 | goto out; |
| 4542 | } |
| 4543 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4544 | MPI2_IOCSTATUS_MASK; |
| 4545 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4546 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4547 | ioc->name, __FILE__, __LINE__, __func__); |
| 4548 | goto out; |
| 4549 | } |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4550 | |
| 4551 | if (i == 0) |
| 4552 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4553 | PhyData[0].ControllerDevHandle); |
| 4554 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4555 | ioc->sas_hba.phy[i].phy_id = i; |
| 4556 | mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], |
| 4557 | phy_pg0, ioc->sas_hba.parent_dev); |
| 4558 | } |
| 4559 | 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] | 4560 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4561 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4562 | ioc->name, __FILE__, __LINE__, __func__); |
| 4563 | goto out; |
| 4564 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4565 | ioc->sas_hba.enclosure_handle = |
| 4566 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 4567 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 4568 | printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), " |
| 4569 | "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle, |
| 4570 | (unsigned long long) ioc->sas_hba.sas_address, |
| 4571 | ioc->sas_hba.num_phys) ; |
| 4572 | |
| 4573 | if (ioc->sas_hba.enclosure_handle) { |
| 4574 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4575 | &enclosure_pg0, |
| 4576 | MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4577 | ioc->sas_hba.enclosure_handle))) { |
| 4578 | ioc->sas_hba.enclosure_logical_id = |
| 4579 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4580 | } |
| 4581 | } |
| 4582 | |
| 4583 | out: |
| 4584 | kfree(sas_iounit_pg1); |
| 4585 | kfree(sas_iounit_pg0); |
| 4586 | } |
| 4587 | |
| 4588 | /** |
| 4589 | * _scsih_expander_add - creating expander object |
| 4590 | * @ioc: per adapter object |
| 4591 | * @handle: expander handle |
| 4592 | * |
| 4593 | * Creating expander object, stored in ioc->sas_expander_list. |
| 4594 | * |
| 4595 | * Return 0 for success, else error. |
| 4596 | */ |
| 4597 | static int |
| 4598 | _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4599 | { |
| 4600 | struct _sas_node *sas_expander; |
| 4601 | Mpi2ConfigReply_t mpi_reply; |
| 4602 | Mpi2ExpanderPage0_t expander_pg0; |
| 4603 | Mpi2ExpanderPage1_t expander_pg1; |
| 4604 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4605 | u32 ioc_status; |
| 4606 | u16 parent_handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4607 | __le64 sas_address, sas_address_parent = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4608 | int i; |
| 4609 | unsigned long flags; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4610 | struct _sas_port *mpt2sas_port = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4611 | int rc = 0; |
| 4612 | |
| 4613 | if (!handle) |
| 4614 | return -1; |
| 4615 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 4616 | if (ioc->shost_recovery || ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 4617 | return -1; |
| 4618 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4619 | if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 4620 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { |
| 4621 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4622 | ioc->name, __FILE__, __LINE__, __func__); |
| 4623 | return -1; |
| 4624 | } |
| 4625 | |
| 4626 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4627 | MPI2_IOCSTATUS_MASK; |
| 4628 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4629 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4630 | ioc->name, __FILE__, __LINE__, __func__); |
| 4631 | return -1; |
| 4632 | } |
| 4633 | |
| 4634 | /* handle out of order topology events */ |
| 4635 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4636 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) |
| 4637 | != 0) { |
| 4638 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4639 | ioc->name, __FILE__, __LINE__, __func__); |
| 4640 | return -1; |
| 4641 | } |
| 4642 | if (sas_address_parent != ioc->sas_hba.sas_address) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4643 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4644 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4645 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4646 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4647 | if (!sas_expander) { |
| 4648 | rc = _scsih_expander_add(ioc, parent_handle); |
| 4649 | if (rc != 0) |
| 4650 | return rc; |
| 4651 | } |
| 4652 | } |
| 4653 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4654 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 4655 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4656 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4657 | sas_address); |
| 4658 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4659 | |
| 4660 | if (sas_expander) |
| 4661 | return 0; |
| 4662 | |
| 4663 | sas_expander = kzalloc(sizeof(struct _sas_node), |
| 4664 | GFP_KERNEL); |
| 4665 | if (!sas_expander) { |
| 4666 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4667 | ioc->name, __FILE__, __LINE__, __func__); |
| 4668 | return -1; |
| 4669 | } |
| 4670 | |
| 4671 | sas_expander->handle = handle; |
| 4672 | sas_expander->num_phys = expander_pg0.NumPhys; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4673 | sas_expander->sas_address_parent = sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4674 | sas_expander->sas_address = sas_address; |
| 4675 | |
| 4676 | printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x)," |
| 4677 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4678 | handle, parent_handle, (unsigned long long) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4679 | sas_expander->sas_address, sas_expander->num_phys); |
| 4680 | |
| 4681 | if (!sas_expander->num_phys) |
| 4682 | goto out_fail; |
| 4683 | sas_expander->phy = kcalloc(sas_expander->num_phys, |
| 4684 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4685 | if (!sas_expander->phy) { |
| 4686 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4687 | ioc->name, __FILE__, __LINE__, __func__); |
| 4688 | rc = -1; |
| 4689 | goto out_fail; |
| 4690 | } |
| 4691 | |
| 4692 | INIT_LIST_HEAD(&sas_expander->sas_port_list); |
| 4693 | mpt2sas_port = mpt2sas_transport_port_add(ioc, handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4694 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4695 | if (!mpt2sas_port) { |
| 4696 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4697 | ioc->name, __FILE__, __LINE__, __func__); |
| 4698 | rc = -1; |
| 4699 | goto out_fail; |
| 4700 | } |
| 4701 | sas_expander->parent_dev = &mpt2sas_port->rphy->dev; |
| 4702 | |
| 4703 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 4704 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 4705 | &expander_pg1, i, handle))) { |
| 4706 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4707 | ioc->name, __FILE__, __LINE__, __func__); |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4708 | rc = -1; |
| 4709 | goto out_fail; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4710 | } |
| 4711 | sas_expander->phy[i].handle = handle; |
| 4712 | sas_expander->phy[i].phy_id = i; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4713 | |
| 4714 | if ((mpt2sas_transport_add_expander_phy(ioc, |
| 4715 | &sas_expander->phy[i], expander_pg1, |
| 4716 | sas_expander->parent_dev))) { |
| 4717 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4718 | ioc->name, __FILE__, __LINE__, __func__); |
| 4719 | rc = -1; |
| 4720 | goto out_fail; |
| 4721 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4722 | } |
| 4723 | |
| 4724 | if (sas_expander->enclosure_handle) { |
| 4725 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4726 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4727 | sas_expander->enclosure_handle))) { |
| 4728 | sas_expander->enclosure_logical_id = |
| 4729 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4730 | } |
| 4731 | } |
| 4732 | |
| 4733 | _scsih_expander_node_add(ioc, sas_expander); |
| 4734 | return 0; |
| 4735 | |
| 4736 | out_fail: |
| 4737 | |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4738 | if (mpt2sas_port) |
| 4739 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4740 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4741 | kfree(sas_expander); |
| 4742 | return rc; |
| 4743 | } |
| 4744 | |
| 4745 | /** |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 4746 | * _scsih_done - scsih callback handler. |
| 4747 | * @ioc: per adapter object |
| 4748 | * @smid: system request message index |
| 4749 | * @msix_index: MSIX table index supplied by the OS |
| 4750 | * @reply: reply message frame(lower 32bit addr) |
| 4751 | * |
| 4752 | * Callback handler when sending internal generated message frames. |
| 4753 | * The callback index passed is `ioc->scsih_cb_idx` |
| 4754 | * |
| 4755 | * Return 1 meaning mf should be freed from _base_interrupt |
| 4756 | * 0 means the mf is freed from this function. |
| 4757 | */ |
| 4758 | static u8 |
| 4759 | _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) |
| 4760 | { |
| 4761 | MPI2DefaultReply_t *mpi_reply; |
| 4762 | |
| 4763 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 4764 | if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED) |
| 4765 | return 1; |
| 4766 | if (ioc->scsih_cmds.smid != smid) |
| 4767 | return 1; |
| 4768 | ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE; |
| 4769 | if (mpi_reply) { |
| 4770 | memcpy(ioc->scsih_cmds.reply, mpi_reply, |
| 4771 | mpi_reply->MsgLength*4); |
| 4772 | ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 4773 | } |
| 4774 | ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING; |
| 4775 | complete(&ioc->scsih_cmds.done); |
| 4776 | return 1; |
| 4777 | } |
| 4778 | |
| 4779 | /** |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4780 | * mpt2sas_expander_remove - removing expander object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4781 | * @ioc: per adapter object |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4782 | * @sas_address: expander sas_address |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4783 | * |
| 4784 | * Return nothing. |
| 4785 | */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4786 | void |
| 4787 | mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4788 | { |
| 4789 | struct _sas_node *sas_expander; |
| 4790 | unsigned long flags; |
| 4791 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 4792 | if (ioc->shost_recovery) |
| 4793 | return; |
| 4794 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4795 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4796 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4797 | sas_address); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4798 | if (!sas_expander) { |
| 4799 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4800 | return; |
| 4801 | } |
| 4802 | list_del(&sas_expander->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4803 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4804 | _scsih_expander_node_remove(ioc, sas_expander); |
| 4805 | } |
| 4806 | |
| 4807 | /** |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 4808 | * _scsih_check_access_status - check access flags |
| 4809 | * @ioc: per adapter object |
| 4810 | * @sas_address: sas address |
| 4811 | * @handle: sas device handle |
| 4812 | * @access_flags: errors returned during discovery of the device |
| 4813 | * |
| 4814 | * Return 0 for success, else failure |
| 4815 | */ |
| 4816 | static u8 |
| 4817 | _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 4818 | u16 handle, u8 access_status) |
| 4819 | { |
| 4820 | u8 rc = 1; |
| 4821 | char *desc = NULL; |
| 4822 | |
| 4823 | switch (access_status) { |
| 4824 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: |
| 4825 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: |
| 4826 | rc = 0; |
| 4827 | break; |
| 4828 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: |
| 4829 | desc = "sata capability failed"; |
| 4830 | break; |
| 4831 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: |
| 4832 | desc = "sata affiliation conflict"; |
| 4833 | break; |
| 4834 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: |
| 4835 | desc = "route not addressable"; |
| 4836 | break; |
| 4837 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: |
| 4838 | desc = "smp error not addressable"; |
| 4839 | break; |
| 4840 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: |
| 4841 | desc = "device blocked"; |
| 4842 | break; |
| 4843 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: |
| 4844 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: |
| 4845 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: |
| 4846 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: |
| 4847 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: |
| 4848 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: |
| 4849 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: |
| 4850 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: |
| 4851 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: |
| 4852 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: |
| 4853 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: |
| 4854 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: |
| 4855 | desc = "sata initialization failed"; |
| 4856 | break; |
| 4857 | default: |
| 4858 | desc = "unknown"; |
| 4859 | break; |
| 4860 | } |
| 4861 | |
| 4862 | if (!rc) |
| 4863 | return 0; |
| 4864 | |
| 4865 | printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), " |
| 4866 | "handle(0x%04x)\n", ioc->name, desc, |
| 4867 | (unsigned long long)sas_address, handle); |
| 4868 | return rc; |
| 4869 | } |
| 4870 | |
| 4871 | static void |
| 4872 | _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4873 | { |
| 4874 | Mpi2ConfigReply_t mpi_reply; |
| 4875 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4876 | struct _sas_device *sas_device; |
| 4877 | u32 ioc_status; |
| 4878 | unsigned long flags; |
| 4879 | u64 sas_address; |
| 4880 | struct scsi_target *starget; |
| 4881 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 4882 | u32 device_info; |
| 4883 | |
| 4884 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 4885 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) |
| 4886 | return; |
| 4887 | |
| 4888 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 4889 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 4890 | return; |
| 4891 | |
| 4892 | /* check if this is end device */ |
| 4893 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 4894 | if (!(_scsih_is_end_device(device_info))) |
| 4895 | return; |
| 4896 | |
| 4897 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4898 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 4899 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 4900 | sas_address); |
| 4901 | |
| 4902 | if (!sas_device) { |
| 4903 | printk(MPT2SAS_ERR_FMT "device is not present " |
| 4904 | "handle(0x%04x), no sas_device!!!\n", ioc->name, handle); |
| 4905 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4906 | return; |
| 4907 | } |
| 4908 | |
| 4909 | if (unlikely(sas_device->handle != handle)) { |
| 4910 | starget = sas_device->starget; |
| 4911 | sas_target_priv_data = starget->hostdata; |
| 4912 | starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)" |
| 4913 | " to (0x%04x)!!!\n", sas_device->handle, handle); |
| 4914 | sas_target_priv_data->handle = handle; |
| 4915 | sas_device->handle = handle; |
| 4916 | } |
| 4917 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4918 | |
| 4919 | /* check if device is present */ |
| 4920 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 4921 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 4922 | printk(MPT2SAS_ERR_FMT "device is not present " |
| 4923 | "handle(0x%04x), flags!!!\n", ioc->name, handle); |
| 4924 | return; |
| 4925 | } |
| 4926 | |
| 4927 | /* check if there were any issues with discovery */ |
| 4928 | if (_scsih_check_access_status(ioc, sas_address, handle, |
| 4929 | sas_device_pg0.AccessStatus)) |
| 4930 | return; |
| 4931 | _scsih_ublock_io_device(ioc, handle); |
| 4932 | |
| 4933 | } |
| 4934 | |
| 4935 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4936 | * _scsih_add_device - creating sas device object |
| 4937 | * @ioc: per adapter object |
| 4938 | * @handle: sas device handle |
| 4939 | * @phy_num: phy number end device attached to |
| 4940 | * @is_pd: is this hidden raid component |
| 4941 | * |
| 4942 | * Creating end device object, stored in ioc->sas_device_list. |
| 4943 | * |
| 4944 | * Returns 0 for success, non-zero for failure. |
| 4945 | */ |
| 4946 | static int |
| 4947 | _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd) |
| 4948 | { |
| 4949 | Mpi2ConfigReply_t mpi_reply; |
| 4950 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4951 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4952 | struct _sas_device *sas_device; |
| 4953 | u32 ioc_status; |
| 4954 | __le64 sas_address; |
| 4955 | u32 device_info; |
| 4956 | unsigned long flags; |
| 4957 | |
| 4958 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 4959 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 4960 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4961 | ioc->name, __FILE__, __LINE__, __func__); |
| 4962 | return -1; |
| 4963 | } |
| 4964 | |
| 4965 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4966 | MPI2_IOCSTATUS_MASK; |
| 4967 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4968 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4969 | ioc->name, __FILE__, __LINE__, __func__); |
| 4970 | return -1; |
| 4971 | } |
| 4972 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 4973 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 4974 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4975 | /* check if device is present */ |
| 4976 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 4977 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 4978 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4979 | ioc->name, __FILE__, __LINE__, __func__); |
| 4980 | printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n", |
| 4981 | ioc->name, le16_to_cpu(sas_device_pg0.Flags)); |
| 4982 | return -1; |
| 4983 | } |
| 4984 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 4985 | /* check if there were any issues with discovery */ |
| 4986 | if (_scsih_check_access_status(ioc, sas_address, handle, |
| 4987 | sas_device_pg0.AccessStatus)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4988 | return -1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4989 | |
| 4990 | /* check if this is end device */ |
| 4991 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 4992 | if (!(_scsih_is_end_device(device_info))) { |
| 4993 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4994 | ioc->name, __FILE__, __LINE__, __func__); |
| 4995 | return -1; |
| 4996 | } |
| 4997 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4998 | |
| 4999 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5000 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5001 | sas_address); |
| 5002 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5003 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5004 | if (sas_device) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5005 | return 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5006 | |
| 5007 | sas_device = kzalloc(sizeof(struct _sas_device), |
| 5008 | GFP_KERNEL); |
| 5009 | if (!sas_device) { |
| 5010 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5011 | ioc->name, __FILE__, __LINE__, __func__); |
| 5012 | return -1; |
| 5013 | } |
| 5014 | |
| 5015 | sas_device->handle = handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5016 | if (_scsih_get_sas_address(ioc, le16_to_cpu |
| 5017 | (sas_device_pg0.ParentDevHandle), |
| 5018 | &sas_device->sas_address_parent) != 0) |
| 5019 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5020 | ioc->name, __FILE__, __LINE__, __func__); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5021 | sas_device->enclosure_handle = |
| 5022 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 5023 | sas_device->slot = |
| 5024 | le16_to_cpu(sas_device_pg0.Slot); |
| 5025 | sas_device->device_info = device_info; |
| 5026 | sas_device->sas_address = sas_address; |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 5027 | sas_device->phy = sas_device_pg0.PhyNum; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5028 | |
| 5029 | /* get enclosure_logical_id */ |
Kashyap, Desai | 15052c9 | 2009-08-07 19:33:17 +0530 | [diff] [blame] | 5030 | if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0( |
| 5031 | ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 5032 | sas_device->enclosure_handle))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5033 | sas_device->enclosure_logical_id = |
| 5034 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5035 | |
| 5036 | /* get device name */ |
| 5037 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); |
| 5038 | |
| 5039 | if (ioc->wait_for_port_enable_to_complete) |
| 5040 | _scsih_sas_device_init_add(ioc, sas_device); |
| 5041 | else |
| 5042 | _scsih_sas_device_add(ioc, sas_device); |
| 5043 | |
| 5044 | return 0; |
| 5045 | } |
| 5046 | |
| 5047 | /** |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5048 | * _scsih_remove_device - removing sas device object |
| 5049 | * @ioc: per adapter object |
| 5050 | * @sas_device_delete: the sas_device object |
| 5051 | * |
| 5052 | * Return nothing. |
| 5053 | */ |
| 5054 | static void |
| 5055 | _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, |
| 5056 | struct _sas_device *sas_device) |
| 5057 | { |
| 5058 | struct _sas_device sas_device_backup; |
| 5059 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 5060 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5061 | if (!sas_device) |
| 5062 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5063 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5064 | memcpy(&sas_device_backup, sas_device, sizeof(struct _sas_device)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5065 | _scsih_sas_device_remove(ioc, sas_device); |
| 5066 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5067 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: " |
| 5068 | "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 5069 | sas_device_backup.handle, (unsigned long long) |
| 5070 | sas_device_backup.sas_address)); |
| 5071 | |
| 5072 | if (sas_device_backup.starget && sas_device_backup.starget->hostdata) { |
| 5073 | sas_target_priv_data = sas_device_backup.starget->hostdata; |
| 5074 | sas_target_priv_data->deleted = 1; |
| 5075 | } |
| 5076 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5077 | _scsih_ublock_io_device(ioc, sas_device_backup.handle); |
| 5078 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 5079 | if (!ioc->hide_drives) |
| 5080 | mpt2sas_transport_port_remove(ioc, |
| 5081 | sas_device_backup.sas_address, |
| 5082 | sas_device_backup.sas_address_parent); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5083 | |
| 5084 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr" |
| 5085 | "(0x%016llx)\n", ioc->name, sas_device_backup.handle, |
| 5086 | (unsigned long long) sas_device_backup.sas_address); |
| 5087 | |
| 5088 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: " |
| 5089 | "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 5090 | sas_device_backup.handle, (unsigned long long) |
| 5091 | sas_device_backup.sas_address)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5092 | } |
| 5093 | |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5094 | /** |
| 5095 | * mpt2sas_device_remove - removing device object |
| 5096 | * @ioc: per adapter object |
| 5097 | * @sas_address: expander sas_address |
| 5098 | * |
| 5099 | * Return nothing. |
| 5100 | */ |
| 5101 | void |
| 5102 | mpt2sas_device_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) |
| 5103 | { |
| 5104 | struct _sas_device *sas_device; |
| 5105 | unsigned long flags; |
| 5106 | |
| 5107 | if (ioc->shost_recovery) |
| 5108 | return; |
| 5109 | |
| 5110 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5111 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5112 | sas_address); |
| 5113 | if (!sas_device) { |
| 5114 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5115 | return; |
| 5116 | } |
| 5117 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5118 | _scsih_remove_device(ioc, sas_device); |
| 5119 | } |
| 5120 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5121 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5122 | /** |
| 5123 | * _scsih_sas_topology_change_event_debug - debug for topology event |
| 5124 | * @ioc: per adapter object |
| 5125 | * @event_data: event data payload |
| 5126 | * Context: user. |
| 5127 | */ |
| 5128 | static void |
| 5129 | _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5130 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 5131 | { |
| 5132 | int i; |
| 5133 | u16 handle; |
| 5134 | u16 reason_code; |
| 5135 | u8 phy_number; |
| 5136 | char *status_str = NULL; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5137 | u8 link_rate, prev_link_rate; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5138 | |
| 5139 | switch (event_data->ExpStatus) { |
| 5140 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: |
| 5141 | status_str = "add"; |
| 5142 | break; |
| 5143 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: |
| 5144 | status_str = "remove"; |
| 5145 | break; |
| 5146 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5147 | case 0: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5148 | status_str = "responding"; |
| 5149 | break; |
| 5150 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: |
| 5151 | status_str = "remove delay"; |
| 5152 | break; |
| 5153 | default: |
| 5154 | status_str = "unknown status"; |
| 5155 | break; |
| 5156 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5157 | printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5158 | ioc->name, status_str); |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5159 | printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5160 | "start_phy(%02d), count(%d)\n", |
| 5161 | le16_to_cpu(event_data->ExpanderDevHandle), |
| 5162 | le16_to_cpu(event_data->EnclosureHandle), |
| 5163 | event_data->StartPhyNum, event_data->NumEntries); |
| 5164 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5165 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5166 | if (!handle) |
| 5167 | continue; |
| 5168 | phy_number = event_data->StartPhyNum + i; |
| 5169 | reason_code = event_data->PHY[i].PhyStatus & |
| 5170 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5171 | switch (reason_code) { |
| 5172 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5173 | status_str = "target add"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5174 | break; |
| 5175 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5176 | status_str = "target remove"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5177 | break; |
| 5178 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5179 | status_str = "delay target remove"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5180 | break; |
| 5181 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5182 | status_str = "link rate change"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5183 | break; |
| 5184 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5185 | status_str = "target responding"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5186 | break; |
| 5187 | default: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5188 | status_str = "unknown"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5189 | break; |
| 5190 | } |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5191 | link_rate = event_data->PHY[i].LinkRate >> 4; |
| 5192 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5193 | printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:" |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5194 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, |
| 5195 | handle, status_str, link_rate, prev_link_rate); |
| 5196 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5197 | } |
| 5198 | } |
| 5199 | #endif |
| 5200 | |
| 5201 | /** |
| 5202 | * _scsih_sas_topology_change_event - handle topology changes |
| 5203 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5204 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5205 | * Context: user. |
| 5206 | * |
| 5207 | */ |
| 5208 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5209 | _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5210 | struct fw_event_work *fw_event) |
| 5211 | { |
| 5212 | int i; |
| 5213 | u16 parent_handle, handle; |
| 5214 | u16 reason_code; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5215 | u8 phy_number, max_phys; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5216 | struct _sas_node *sas_expander; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5217 | struct _sas_device *sas_device; |
| 5218 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5219 | unsigned long flags; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5220 | u8 link_rate, prev_link_rate; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5221 | Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5222 | |
| 5223 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5224 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5225 | _scsih_sas_topology_change_event_debug(ioc, event_data); |
| 5226 | #endif |
| 5227 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 5228 | if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5229 | return; |
| 5230 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5231 | if (!ioc->sas_hba.num_phys) |
| 5232 | _scsih_sas_host_add(ioc); |
| 5233 | else |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5234 | _scsih_sas_host_refresh(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5235 | |
| 5236 | if (fw_event->ignore) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5237 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5238 | "event\n", ioc->name)); |
| 5239 | return; |
| 5240 | } |
| 5241 | |
| 5242 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 5243 | |
| 5244 | /* handle expander add */ |
| 5245 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) |
| 5246 | if (_scsih_expander_add(ioc, parent_handle) != 0) |
| 5247 | return; |
| 5248 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5249 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 5250 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 5251 | parent_handle); |
| 5252 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5253 | if (sas_expander) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5254 | sas_address = sas_expander->sas_address; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5255 | max_phys = sas_expander->num_phys; |
| 5256 | } else if (parent_handle < ioc->sas_hba.num_phys) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5257 | sas_address = ioc->sas_hba.sas_address; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5258 | max_phys = ioc->sas_hba.num_phys; |
| 5259 | } else |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5260 | return; |
| 5261 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5262 | /* handle siblings events */ |
| 5263 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5264 | if (fw_event->ignore) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5265 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5266 | "expander event\n", ioc->name)); |
| 5267 | return; |
| 5268 | } |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 5269 | if (ioc->shost_recovery || ioc->remove_host || |
| 5270 | ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 5271 | return; |
Kashyap, Desai | 308609c | 2009-09-14 11:07:23 +0530 | [diff] [blame] | 5272 | phy_number = event_data->StartPhyNum + i; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5273 | if (phy_number >= max_phys) |
| 5274 | continue; |
Kashyap, Desai | 308609c | 2009-09-14 11:07:23 +0530 | [diff] [blame] | 5275 | reason_code = event_data->PHY[i].PhyStatus & |
| 5276 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5277 | if ((event_data->PHY[i].PhyStatus & |
| 5278 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != |
| 5279 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5280 | continue; |
| 5281 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5282 | if (!handle) |
| 5283 | continue; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5284 | link_rate = event_data->PHY[i].LinkRate >> 4; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5285 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5286 | switch (reason_code) { |
| 5287 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5288 | |
| 5289 | if (link_rate == prev_link_rate) |
| 5290 | break; |
| 5291 | |
| 5292 | mpt2sas_transport_update_links(ioc, sas_address, |
| 5293 | handle, phy_number, link_rate); |
| 5294 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5295 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 5296 | break; |
| 5297 | |
| 5298 | _scsih_check_device(ioc, handle); |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5299 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5300 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5301 | |
| 5302 | mpt2sas_transport_update_links(ioc, sas_address, |
| 5303 | handle, phy_number, link_rate); |
| 5304 | |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5305 | _scsih_add_device(ioc, handle, phy_number, 0); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5306 | break; |
| 5307 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5308 | |
| 5309 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5310 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 5311 | handle); |
| 5312 | if (!sas_device) { |
| 5313 | spin_unlock_irqrestore(&ioc->sas_device_lock, |
| 5314 | flags); |
| 5315 | break; |
| 5316 | } |
| 5317 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5318 | _scsih_remove_device(ioc, sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5319 | break; |
| 5320 | } |
| 5321 | } |
| 5322 | |
| 5323 | /* handle expander removal */ |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5324 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && |
| 5325 | sas_expander) |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5326 | mpt2sas_expander_remove(ioc, sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5327 | |
| 5328 | } |
| 5329 | |
| 5330 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5331 | /** |
| 5332 | * _scsih_sas_device_status_change_event_debug - debug for device event |
| 5333 | * @event_data: event data payload |
| 5334 | * Context: user. |
| 5335 | * |
| 5336 | * Return nothing. |
| 5337 | */ |
| 5338 | static void |
| 5339 | _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5340 | Mpi2EventDataSasDeviceStatusChange_t *event_data) |
| 5341 | { |
| 5342 | char *reason_str = NULL; |
| 5343 | |
| 5344 | switch (event_data->ReasonCode) { |
| 5345 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: |
| 5346 | reason_str = "smart data"; |
| 5347 | break; |
| 5348 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: |
| 5349 | reason_str = "unsupported device discovered"; |
| 5350 | break; |
| 5351 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: |
| 5352 | reason_str = "internal device reset"; |
| 5353 | break; |
| 5354 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: |
| 5355 | reason_str = "internal task abort"; |
| 5356 | break; |
| 5357 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: |
| 5358 | reason_str = "internal task abort set"; |
| 5359 | break; |
| 5360 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: |
| 5361 | reason_str = "internal clear task set"; |
| 5362 | break; |
| 5363 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: |
| 5364 | reason_str = "internal query task"; |
| 5365 | break; |
| 5366 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: |
| 5367 | reason_str = "sata init failure"; |
| 5368 | break; |
| 5369 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: |
| 5370 | reason_str = "internal device reset complete"; |
| 5371 | break; |
| 5372 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: |
| 5373 | reason_str = "internal task abort complete"; |
| 5374 | break; |
| 5375 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: |
| 5376 | reason_str = "internal async notification"; |
| 5377 | break; |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 5378 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5379 | reason_str = "expander reduced functionality"; |
| 5380 | break; |
| 5381 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5382 | reason_str = "expander reduced functionality complete"; |
| 5383 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5384 | default: |
| 5385 | reason_str = "unknown reason"; |
| 5386 | break; |
| 5387 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5388 | printk(MPT2SAS_INFO_FMT "device status change: (%s)\n" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5389 | "\thandle(0x%04x), sas address(0x%016llx)", ioc->name, |
| 5390 | reason_str, le16_to_cpu(event_data->DevHandle), |
| 5391 | (unsigned long long)le64_to_cpu(event_data->SASAddress)); |
| 5392 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5393 | 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] | 5394 | event_data->ASC, event_data->ASCQ); |
| 5395 | printk(KERN_INFO "\n"); |
| 5396 | } |
| 5397 | #endif |
| 5398 | |
| 5399 | /** |
| 5400 | * _scsih_sas_device_status_change_event - handle device status change |
| 5401 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5402 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5403 | * Context: user. |
| 5404 | * |
| 5405 | * Return nothing. |
| 5406 | */ |
| 5407 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5408 | _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 5409 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5410 | { |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5411 | struct MPT2SAS_TARGET *target_priv_data; |
| 5412 | struct _sas_device *sas_device; |
| 5413 | __le64 sas_address; |
| 5414 | unsigned long flags; |
| 5415 | Mpi2EventDataSasDeviceStatusChange_t *event_data = |
| 5416 | fw_event->event_data; |
| 5417 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5418 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5419 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5420 | _scsih_sas_device_status_change_event_debug(ioc, |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5421 | event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5422 | #endif |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5423 | |
Kashyap, Desai | efe82a1 | 2011-01-04 11:34:17 +0530 | [diff] [blame] | 5424 | /* In MPI Revision K (0xC), the internal device reset complete was |
| 5425 | * implemented, so avoid setting tm_busy flag for older firmware. |
| 5426 | */ |
| 5427 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) |
| 5428 | return; |
| 5429 | |
Kashyap, Desai | f891dcf | 2010-03-17 16:22:21 +0530 | [diff] [blame] | 5430 | if (event_data->ReasonCode != |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5431 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && |
Kashyap, Desai | f891dcf | 2010-03-17 16:22:21 +0530 | [diff] [blame] | 5432 | event_data->ReasonCode != |
| 5433 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5434 | return; |
| 5435 | |
| 5436 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5437 | sas_address = le64_to_cpu(event_data->SASAddress); |
| 5438 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5439 | sas_address); |
| 5440 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5441 | |
| 5442 | if (!sas_device || !sas_device->starget) |
| 5443 | return; |
| 5444 | |
| 5445 | target_priv_data = sas_device->starget->hostdata; |
| 5446 | if (!target_priv_data) |
| 5447 | return; |
| 5448 | |
| 5449 | if (event_data->ReasonCode == |
| 5450 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) |
| 5451 | target_priv_data->tm_busy = 1; |
| 5452 | else |
| 5453 | target_priv_data->tm_busy = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5454 | } |
| 5455 | |
| 5456 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5457 | /** |
| 5458 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event |
| 5459 | * @ioc: per adapter object |
| 5460 | * @event_data: event data payload |
| 5461 | * Context: user. |
| 5462 | * |
| 5463 | * Return nothing. |
| 5464 | */ |
| 5465 | static void |
| 5466 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5467 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) |
| 5468 | { |
| 5469 | char *reason_str = NULL; |
| 5470 | |
| 5471 | switch (event_data->ReasonCode) { |
| 5472 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: |
| 5473 | reason_str = "enclosure add"; |
| 5474 | break; |
| 5475 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: |
| 5476 | reason_str = "enclosure remove"; |
| 5477 | break; |
| 5478 | default: |
| 5479 | reason_str = "unknown reason"; |
| 5480 | break; |
| 5481 | } |
| 5482 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5483 | printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5484 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" |
| 5485 | " number slots(%d)\n", ioc->name, reason_str, |
| 5486 | le16_to_cpu(event_data->EnclosureHandle), |
| 5487 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), |
| 5488 | le16_to_cpu(event_data->StartSlot)); |
| 5489 | } |
| 5490 | #endif |
| 5491 | |
| 5492 | /** |
| 5493 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events |
| 5494 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5495 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5496 | * Context: user. |
| 5497 | * |
| 5498 | * Return nothing. |
| 5499 | */ |
| 5500 | static void |
| 5501 | _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5502 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5503 | { |
| 5504 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5505 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5506 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5507 | fw_event->event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5508 | #endif |
| 5509 | } |
| 5510 | |
| 5511 | /** |
| 5512 | * _scsih_sas_broadcast_primative_event - handle broadcast events |
| 5513 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5514 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5515 | * Context: user. |
| 5516 | * |
| 5517 | * Return nothing. |
| 5518 | */ |
| 5519 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5520 | _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc, |
| 5521 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5522 | { |
| 5523 | struct scsi_cmnd *scmd; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5524 | struct scsi_device *sdev; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5525 | u16 smid, handle; |
| 5526 | u32 lun; |
| 5527 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 5528 | u32 termination_count; |
| 5529 | u32 query_count; |
| 5530 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5531 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5532 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data; |
| 5533 | #endif |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 5534 | u16 ioc_status; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5535 | unsigned long flags; |
| 5536 | int r; |
| 5537 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5538 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "broadcast primitive: " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5539 | "phy number(%d), width(%d)\n", ioc->name, event_data->PhyNum, |
| 5540 | event_data->PortWidth)); |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5541 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5542 | __func__)); |
| 5543 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5544 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5545 | ioc->broadcast_aen_busy = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5546 | termination_count = 0; |
| 5547 | query_count = 0; |
| 5548 | mpi_reply = ioc->tm_cmds.reply; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 5549 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5550 | scmd = _scsih_scsi_lookup_get(ioc, smid); |
| 5551 | if (!scmd) |
| 5552 | continue; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5553 | sdev = scmd->device; |
| 5554 | sas_device_priv_data = sdev->hostdata; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5555 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) |
| 5556 | continue; |
| 5557 | /* skip hidden raid components */ |
| 5558 | if (sas_device_priv_data->sas_target->flags & |
| 5559 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 5560 | continue; |
| 5561 | /* skip volumes */ |
| 5562 | if (sas_device_priv_data->sas_target->flags & |
| 5563 | MPT_TARGET_FLAGS_VOLUME) |
| 5564 | continue; |
| 5565 | |
| 5566 | handle = sas_device_priv_data->sas_target->handle; |
| 5567 | lun = sas_device_priv_data->lun; |
| 5568 | query_count++; |
| 5569 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5570 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 5571 | mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun, |
| 5572 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, NULL); |
Eric Moore | 8901cbb | 2009-04-21 15:41:32 -0600 | [diff] [blame] | 5573 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 5574 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) |
| 5575 | & MPI2_IOCSTATUS_MASK; |
| 5576 | if ((ioc_status == MPI2_IOCSTATUS_SUCCESS) && |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5577 | (mpi_reply->ResponseCode == |
| 5578 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || |
| 5579 | mpi_reply->ResponseCode == |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5580 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC)) { |
| 5581 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5582 | continue; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5583 | } |
| 5584 | r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, |
| 5585 | sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, |
| 5586 | scmd); |
| 5587 | if (r == FAILED) |
| 5588 | sdev_printk(KERN_WARNING, sdev, "task abort: FAILED " |
| 5589 | "scmd(%p)\n", scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5590 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5591 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5592 | } |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5593 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5594 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5595 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5596 | "%s - exit, query_count = %d termination_count = %d\n", |
| 5597 | ioc->name, __func__, query_count, termination_count)); |
| 5598 | } |
| 5599 | |
| 5600 | /** |
| 5601 | * _scsih_sas_discovery_event - handle discovery events |
| 5602 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5603 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5604 | * Context: user. |
| 5605 | * |
| 5606 | * Return nothing. |
| 5607 | */ |
| 5608 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5609 | _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc, |
| 5610 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5611 | { |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5612 | Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data; |
| 5613 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5614 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5615 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5616 | printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5617 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? |
| 5618 | "start" : "stop"); |
| 5619 | if (event_data->DiscoveryStatus) |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 5620 | printk("discovery_status(0x%08x)", |
| 5621 | le32_to_cpu(event_data->DiscoveryStatus)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5622 | printk("\n"); |
| 5623 | } |
| 5624 | #endif |
| 5625 | |
| 5626 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && |
| 5627 | !ioc->sas_hba.num_phys) |
| 5628 | _scsih_sas_host_add(ioc); |
| 5629 | } |
| 5630 | |
| 5631 | /** |
| 5632 | * _scsih_reprobe_lun - reprobing lun |
| 5633 | * @sdev: scsi device struct |
| 5634 | * @no_uld_attach: sdev->no_uld_attach flag setting |
| 5635 | * |
| 5636 | **/ |
| 5637 | static void |
| 5638 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) |
| 5639 | { |
| 5640 | int rc; |
| 5641 | |
| 5642 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
| 5643 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", |
| 5644 | sdev->no_uld_attach ? "hidding" : "exposing"); |
| 5645 | rc = scsi_device_reprobe(sdev); |
| 5646 | } |
| 5647 | |
| 5648 | /** |
| 5649 | * _scsih_reprobe_target - reprobing target |
| 5650 | * @starget: scsi target struct |
| 5651 | * @no_uld_attach: sdev->no_uld_attach flag setting |
| 5652 | * |
| 5653 | * Note: no_uld_attach flag determines whether the disk device is attached |
| 5654 | * to block layer. A value of `1` means to not attach. |
| 5655 | **/ |
| 5656 | static void |
| 5657 | _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach) |
| 5658 | { |
| 5659 | struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata; |
| 5660 | |
| 5661 | if (no_uld_attach) |
| 5662 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 5663 | else |
| 5664 | sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 5665 | |
| 5666 | starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL, |
| 5667 | _scsih_reprobe_lun); |
| 5668 | } |
| 5669 | /** |
| 5670 | * _scsih_sas_volume_add - add new volume |
| 5671 | * @ioc: per adapter object |
| 5672 | * @element: IR config element data |
| 5673 | * Context: user. |
| 5674 | * |
| 5675 | * Return nothing. |
| 5676 | */ |
| 5677 | static void |
| 5678 | _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc, |
| 5679 | Mpi2EventIrConfigElement_t *element) |
| 5680 | { |
| 5681 | struct _raid_device *raid_device; |
| 5682 | unsigned long flags; |
| 5683 | u64 wwid; |
| 5684 | u16 handle = le16_to_cpu(element->VolDevHandle); |
| 5685 | int rc; |
| 5686 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5687 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 5688 | if (!wwid) { |
| 5689 | printk(MPT2SAS_ERR_FMT |
| 5690 | "failure at %s:%d/%s()!\n", ioc->name, |
| 5691 | __FILE__, __LINE__, __func__); |
| 5692 | return; |
| 5693 | } |
| 5694 | |
| 5695 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 5696 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); |
| 5697 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 5698 | |
| 5699 | if (raid_device) |
| 5700 | return; |
| 5701 | |
| 5702 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 5703 | if (!raid_device) { |
| 5704 | printk(MPT2SAS_ERR_FMT |
| 5705 | "failure at %s:%d/%s()!\n", ioc->name, |
| 5706 | __FILE__, __LINE__, __func__); |
| 5707 | return; |
| 5708 | } |
| 5709 | |
| 5710 | raid_device->id = ioc->sas_id++; |
| 5711 | raid_device->channel = RAID_CHANNEL; |
| 5712 | raid_device->handle = handle; |
| 5713 | raid_device->wwid = wwid; |
| 5714 | _scsih_raid_device_add(ioc, raid_device); |
| 5715 | if (!ioc->wait_for_port_enable_to_complete) { |
| 5716 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 5717 | raid_device->id, 0); |
| 5718 | if (rc) |
| 5719 | _scsih_raid_device_remove(ioc, raid_device); |
| 5720 | } else |
| 5721 | _scsih_determine_boot_device(ioc, raid_device, 1); |
| 5722 | } |
| 5723 | |
| 5724 | /** |
| 5725 | * _scsih_sas_volume_delete - delete volume |
| 5726 | * @ioc: per adapter object |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 5727 | * @handle: volume device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5728 | * Context: user. |
| 5729 | * |
| 5730 | * Return nothing. |
| 5731 | */ |
| 5732 | static void |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 5733 | _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5734 | { |
| 5735 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5736 | unsigned long flags; |
| 5737 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 5738 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5739 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 5740 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 5741 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 5742 | if (!raid_device) |
| 5743 | return; |
| 5744 | if (raid_device->starget) { |
| 5745 | sas_target_priv_data = raid_device->starget->hostdata; |
| 5746 | sas_target_priv_data->deleted = 1; |
| 5747 | scsi_remove_target(&raid_device->starget->dev); |
| 5748 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 5749 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" |
| 5750 | "(0x%016llx)\n", ioc->name, raid_device->handle, |
| 5751 | (unsigned long long) raid_device->wwid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5752 | _scsih_raid_device_remove(ioc, raid_device); |
| 5753 | } |
| 5754 | |
| 5755 | /** |
| 5756 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX |
| 5757 | * @ioc: per adapter object |
| 5758 | * @element: IR config element data |
| 5759 | * Context: user. |
| 5760 | * |
| 5761 | * Return nothing. |
| 5762 | */ |
| 5763 | static void |
| 5764 | _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc, |
| 5765 | Mpi2EventIrConfigElement_t *element) |
| 5766 | { |
| 5767 | struct _sas_device *sas_device; |
| 5768 | unsigned long flags; |
| 5769 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 5770 | |
| 5771 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5772 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 5773 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5774 | if (!sas_device) |
| 5775 | return; |
| 5776 | |
| 5777 | /* exposing raid component */ |
| 5778 | sas_device->volume_handle = 0; |
| 5779 | sas_device->volume_wwid = 0; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 5780 | clear_bit(handle, ioc->pd_handles); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5781 | _scsih_reprobe_target(sas_device->starget, 0); |
| 5782 | } |
| 5783 | |
| 5784 | /** |
| 5785 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX |
| 5786 | * @ioc: per adapter object |
| 5787 | * @element: IR config element data |
| 5788 | * Context: user. |
| 5789 | * |
| 5790 | * Return nothing. |
| 5791 | */ |
| 5792 | static void |
| 5793 | _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc, |
| 5794 | Mpi2EventIrConfigElement_t *element) |
| 5795 | { |
| 5796 | struct _sas_device *sas_device; |
| 5797 | unsigned long flags; |
| 5798 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 5799 | |
| 5800 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5801 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 5802 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5803 | if (!sas_device) |
| 5804 | return; |
| 5805 | |
| 5806 | /* hiding raid component */ |
| 5807 | mpt2sas_config_get_volume_handle(ioc, handle, |
| 5808 | &sas_device->volume_handle); |
| 5809 | mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle, |
| 5810 | &sas_device->volume_wwid); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 5811 | set_bit(handle, ioc->pd_handles); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5812 | _scsih_reprobe_target(sas_device->starget, 1); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 5813 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | /** |
| 5817 | * _scsih_sas_pd_delete - delete pd component |
| 5818 | * @ioc: per adapter object |
| 5819 | * @element: IR config element data |
| 5820 | * Context: user. |
| 5821 | * |
| 5822 | * Return nothing. |
| 5823 | */ |
| 5824 | static void |
| 5825 | _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc, |
| 5826 | Mpi2EventIrConfigElement_t *element) |
| 5827 | { |
| 5828 | struct _sas_device *sas_device; |
| 5829 | unsigned long flags; |
| 5830 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 5831 | |
| 5832 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5833 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 5834 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5835 | if (!sas_device) |
| 5836 | return; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5837 | _scsih_remove_device(ioc, sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | /** |
| 5841 | * _scsih_sas_pd_add - remove pd component |
| 5842 | * @ioc: per adapter object |
| 5843 | * @element: IR config element data |
| 5844 | * Context: user. |
| 5845 | * |
| 5846 | * Return nothing. |
| 5847 | */ |
| 5848 | static void |
| 5849 | _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc, |
| 5850 | Mpi2EventIrConfigElement_t *element) |
| 5851 | { |
| 5852 | struct _sas_device *sas_device; |
| 5853 | unsigned long flags; |
| 5854 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 5855 | Mpi2ConfigReply_t mpi_reply; |
| 5856 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 5857 | u32 ioc_status; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5858 | u64 sas_address; |
| 5859 | u16 parent_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5860 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 5861 | set_bit(handle, ioc->pd_handles); |
| 5862 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5863 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5864 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 5865 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 5866 | if (sas_device) |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 5867 | return; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 5868 | |
| 5869 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 5870 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 5871 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5872 | ioc->name, __FILE__, __LINE__, __func__); |
| 5873 | return; |
| 5874 | } |
| 5875 | |
| 5876 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 5877 | MPI2_IOCSTATUS_MASK; |
| 5878 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5879 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5880 | ioc->name, __FILE__, __LINE__, __func__); |
| 5881 | return; |
| 5882 | } |
| 5883 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5884 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 5885 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 5886 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 5887 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 5888 | |
| 5889 | _scsih_add_device(ioc, handle, 0, 1); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5890 | } |
| 5891 | |
| 5892 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5893 | /** |
| 5894 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events |
| 5895 | * @ioc: per adapter object |
| 5896 | * @event_data: event data payload |
| 5897 | * Context: user. |
| 5898 | * |
| 5899 | * Return nothing. |
| 5900 | */ |
| 5901 | static void |
| 5902 | _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5903 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 5904 | { |
| 5905 | Mpi2EventIrConfigElement_t *element; |
| 5906 | u8 element_type; |
| 5907 | int i; |
| 5908 | char *reason_str = NULL, *element_str = NULL; |
| 5909 | |
| 5910 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 5911 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5912 | printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5913 | ioc->name, (le32_to_cpu(event_data->Flags) & |
| 5914 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? |
| 5915 | "foreign" : "native", event_data->NumElements); |
| 5916 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 5917 | switch (element->ReasonCode) { |
| 5918 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
| 5919 | reason_str = "add"; |
| 5920 | break; |
| 5921 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
| 5922 | reason_str = "remove"; |
| 5923 | break; |
| 5924 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: |
| 5925 | reason_str = "no change"; |
| 5926 | break; |
| 5927 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
| 5928 | reason_str = "hide"; |
| 5929 | break; |
| 5930 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
| 5931 | reason_str = "unhide"; |
| 5932 | break; |
| 5933 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 5934 | reason_str = "volume_created"; |
| 5935 | break; |
| 5936 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 5937 | reason_str = "volume_deleted"; |
| 5938 | break; |
| 5939 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
| 5940 | reason_str = "pd_created"; |
| 5941 | break; |
| 5942 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
| 5943 | reason_str = "pd_deleted"; |
| 5944 | break; |
| 5945 | default: |
| 5946 | reason_str = "unknown reason"; |
| 5947 | break; |
| 5948 | } |
| 5949 | element_type = le16_to_cpu(element->ElementFlags) & |
| 5950 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; |
| 5951 | switch (element_type) { |
| 5952 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: |
| 5953 | element_str = "volume"; |
| 5954 | break; |
| 5955 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: |
| 5956 | element_str = "phys disk"; |
| 5957 | break; |
| 5958 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: |
| 5959 | element_str = "hot spare"; |
| 5960 | break; |
| 5961 | default: |
| 5962 | element_str = "unknown element"; |
| 5963 | break; |
| 5964 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5965 | printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5966 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, |
| 5967 | reason_str, le16_to_cpu(element->VolDevHandle), |
| 5968 | le16_to_cpu(element->PhysDiskDevHandle), |
| 5969 | element->PhysDiskNum); |
| 5970 | } |
| 5971 | } |
| 5972 | #endif |
| 5973 | |
| 5974 | /** |
| 5975 | * _scsih_sas_ir_config_change_event - handle ir configuration change events |
| 5976 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5977 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5978 | * Context: user. |
| 5979 | * |
| 5980 | * Return nothing. |
| 5981 | */ |
| 5982 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5983 | _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 5984 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5985 | { |
| 5986 | Mpi2EventIrConfigElement_t *element; |
| 5987 | int i; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 5988 | u8 foreign_config; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5989 | Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5990 | |
| 5991 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 5992 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5993 | && !ioc->hide_ir_msg) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5994 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
| 5995 | |
| 5996 | #endif |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 5997 | foreign_config = (le32_to_cpu(event_data->Flags) & |
| 5998 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5999 | |
| 6000 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 6001 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6002 | |
| 6003 | switch (element->ReasonCode) { |
| 6004 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 6005 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6006 | if (!foreign_config) |
| 6007 | _scsih_sas_volume_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6008 | break; |
| 6009 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 6010 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6011 | if (!foreign_config) |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6012 | _scsih_sas_volume_delete(ioc, |
| 6013 | le16_to_cpu(element->VolDevHandle)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6014 | break; |
| 6015 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6016 | if (!ioc->is_warpdrive) |
| 6017 | _scsih_sas_pd_hide(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6018 | break; |
| 6019 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6020 | if (!ioc->is_warpdrive) |
| 6021 | _scsih_sas_pd_expose(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6022 | break; |
| 6023 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6024 | if (!ioc->is_warpdrive) |
| 6025 | _scsih_sas_pd_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6026 | break; |
| 6027 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6028 | if (!ioc->is_warpdrive) |
| 6029 | _scsih_sas_pd_delete(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6030 | break; |
| 6031 | } |
| 6032 | } |
| 6033 | } |
| 6034 | |
| 6035 | /** |
| 6036 | * _scsih_sas_ir_volume_event - IR volume event |
| 6037 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6038 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6039 | * Context: user. |
| 6040 | * |
| 6041 | * Return nothing. |
| 6042 | */ |
| 6043 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6044 | _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc, |
| 6045 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6046 | { |
| 6047 | u64 wwid; |
| 6048 | unsigned long flags; |
| 6049 | struct _raid_device *raid_device; |
| 6050 | u16 handle; |
| 6051 | u32 state; |
| 6052 | int rc; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6053 | Mpi2EventDataIrVolume_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6054 | |
| 6055 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 6056 | return; |
| 6057 | |
| 6058 | handle = le16_to_cpu(event_data->VolDevHandle); |
| 6059 | state = le32_to_cpu(event_data->NewValue); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6060 | if (!ioc->hide_ir_msg) |
| 6061 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " |
| 6062 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 6063 | le32_to_cpu(event_data->PreviousValue), state)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6064 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6065 | switch (state) { |
| 6066 | case MPI2_RAID_VOL_STATE_MISSING: |
| 6067 | case MPI2_RAID_VOL_STATE_FAILED: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6068 | _scsih_sas_volume_delete(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6069 | break; |
| 6070 | |
| 6071 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 6072 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 6073 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6074 | |
| 6075 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6076 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 6077 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6078 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6079 | if (raid_device) |
| 6080 | break; |
| 6081 | |
| 6082 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 6083 | if (!wwid) { |
| 6084 | printk(MPT2SAS_ERR_FMT |
| 6085 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6086 | __FILE__, __LINE__, __func__); |
| 6087 | break; |
| 6088 | } |
| 6089 | |
| 6090 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 6091 | if (!raid_device) { |
| 6092 | printk(MPT2SAS_ERR_FMT |
| 6093 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6094 | __FILE__, __LINE__, __func__); |
| 6095 | break; |
| 6096 | } |
| 6097 | |
| 6098 | raid_device->id = ioc->sas_id++; |
| 6099 | raid_device->channel = RAID_CHANNEL; |
| 6100 | raid_device->handle = handle; |
| 6101 | raid_device->wwid = wwid; |
| 6102 | _scsih_raid_device_add(ioc, raid_device); |
| 6103 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 6104 | raid_device->id, 0); |
| 6105 | if (rc) |
| 6106 | _scsih_raid_device_remove(ioc, raid_device); |
| 6107 | break; |
| 6108 | |
| 6109 | case MPI2_RAID_VOL_STATE_INITIALIZING: |
| 6110 | default: |
| 6111 | break; |
| 6112 | } |
| 6113 | } |
| 6114 | |
| 6115 | /** |
| 6116 | * _scsih_sas_ir_physical_disk_event - PD event |
| 6117 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6118 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6119 | * Context: user. |
| 6120 | * |
| 6121 | * Return nothing. |
| 6122 | */ |
| 6123 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6124 | _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc, |
| 6125 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6126 | { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6127 | u16 handle, parent_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6128 | u32 state; |
| 6129 | struct _sas_device *sas_device; |
| 6130 | unsigned long flags; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6131 | Mpi2ConfigReply_t mpi_reply; |
| 6132 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6133 | u32 ioc_status; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6134 | Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6135 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6136 | |
| 6137 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) |
| 6138 | return; |
| 6139 | |
| 6140 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); |
| 6141 | state = le32_to_cpu(event_data->NewValue); |
| 6142 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6143 | if (!ioc->hide_ir_msg) |
| 6144 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " |
| 6145 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 6146 | le32_to_cpu(event_data->PreviousValue), state)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6147 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6148 | switch (state) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6149 | case MPI2_RAID_PD_STATE_ONLINE: |
| 6150 | case MPI2_RAID_PD_STATE_DEGRADED: |
| 6151 | case MPI2_RAID_PD_STATE_REBUILDING: |
| 6152 | case MPI2_RAID_PD_STATE_OPTIMAL: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6153 | case MPI2_RAID_PD_STATE_HOT_SPARE: |
| 6154 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6155 | if (!ioc->is_warpdrive) |
| 6156 | set_bit(handle, ioc->pd_handles); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6157 | |
| 6158 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6159 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6160 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6161 | |
| 6162 | if (sas_device) |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6163 | return; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6164 | |
| 6165 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6166 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 6167 | handle))) { |
| 6168 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6169 | ioc->name, __FILE__, __LINE__, __func__); |
| 6170 | return; |
| 6171 | } |
| 6172 | |
| 6173 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6174 | MPI2_IOCSTATUS_MASK; |
| 6175 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6176 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6177 | ioc->name, __FILE__, __LINE__, __func__); |
| 6178 | return; |
| 6179 | } |
| 6180 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6181 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6182 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 6183 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 6184 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6185 | |
| 6186 | _scsih_add_device(ioc, handle, 0, 1); |
| 6187 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6188 | break; |
| 6189 | |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6190 | case MPI2_RAID_PD_STATE_OFFLINE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6191 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: |
| 6192 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6193 | default: |
| 6194 | break; |
| 6195 | } |
| 6196 | } |
| 6197 | |
| 6198 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 6199 | /** |
| 6200 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event |
| 6201 | * @ioc: per adapter object |
| 6202 | * @event_data: event data payload |
| 6203 | * Context: user. |
| 6204 | * |
| 6205 | * Return nothing. |
| 6206 | */ |
| 6207 | static void |
| 6208 | _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 6209 | Mpi2EventDataIrOperationStatus_t *event_data) |
| 6210 | { |
| 6211 | char *reason_str = NULL; |
| 6212 | |
| 6213 | switch (event_data->RAIDOperation) { |
| 6214 | case MPI2_EVENT_IR_RAIDOP_RESYNC: |
| 6215 | reason_str = "resync"; |
| 6216 | break; |
| 6217 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: |
| 6218 | reason_str = "online capacity expansion"; |
| 6219 | break; |
| 6220 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: |
| 6221 | reason_str = "consistency check"; |
| 6222 | break; |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 6223 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: |
| 6224 | reason_str = "background init"; |
| 6225 | break; |
| 6226 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: |
| 6227 | reason_str = "make data consistent"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6228 | break; |
| 6229 | } |
| 6230 | |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 6231 | if (!reason_str) |
| 6232 | return; |
| 6233 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6234 | printk(MPT2SAS_INFO_FMT "raid operational status: (%s)" |
| 6235 | "\thandle(0x%04x), percent complete(%d)\n", |
| 6236 | ioc->name, reason_str, |
| 6237 | le16_to_cpu(event_data->VolDevHandle), |
| 6238 | event_data->PercentComplete); |
| 6239 | } |
| 6240 | #endif |
| 6241 | |
| 6242 | /** |
| 6243 | * _scsih_sas_ir_operation_status_event - handle RAID operation events |
| 6244 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6245 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6246 | * Context: user. |
| 6247 | * |
| 6248 | * Return nothing. |
| 6249 | */ |
| 6250 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6251 | _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc, |
| 6252 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6253 | { |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6254 | Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data; |
| 6255 | static struct _raid_device *raid_device; |
| 6256 | unsigned long flags; |
| 6257 | u16 handle; |
| 6258 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6259 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6260 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6261 | && !ioc->hide_ir_msg) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6262 | _scsih_sas_ir_operation_status_event_debug(ioc, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6263 | event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6264 | #endif |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6265 | |
| 6266 | /* code added for raid transport support */ |
| 6267 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { |
| 6268 | |
| 6269 | handle = le16_to_cpu(event_data->VolDevHandle); |
| 6270 | |
| 6271 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6272 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 6273 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6274 | |
| 6275 | if (!raid_device) |
| 6276 | return; |
| 6277 | |
| 6278 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) |
| 6279 | raid_device->percent_complete = |
| 6280 | event_data->PercentComplete; |
| 6281 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6282 | } |
| 6283 | |
| 6284 | /** |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6285 | * _scsih_prep_device_scan - initialize parameters prior to device scan |
| 6286 | * @ioc: per adapter object |
| 6287 | * |
| 6288 | * Set the deleted flag prior to device scan. If the device is found during |
| 6289 | * the scan, then we clear the deleted flag. |
| 6290 | */ |
| 6291 | static void |
| 6292 | _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc) |
| 6293 | { |
| 6294 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 6295 | struct scsi_device *sdev; |
| 6296 | |
| 6297 | shost_for_each_device(sdev, ioc->shost) { |
| 6298 | sas_device_priv_data = sdev->hostdata; |
| 6299 | if (sas_device_priv_data && sas_device_priv_data->sas_target) |
| 6300 | sas_device_priv_data->sas_target->deleted = 1; |
| 6301 | } |
| 6302 | } |
| 6303 | |
| 6304 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6305 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding |
| 6306 | * @ioc: per adapter object |
| 6307 | * @sas_address: sas address |
| 6308 | * @slot: enclosure slot id |
| 6309 | * @handle: device handle |
| 6310 | * |
| 6311 | * After host reset, find out whether devices are still responding. |
| 6312 | * Used in _scsi_remove_unresponsive_sas_devices. |
| 6313 | * |
| 6314 | * Return nothing. |
| 6315 | */ |
| 6316 | static void |
| 6317 | _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 6318 | u16 slot, u16 handle) |
| 6319 | { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6320 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6321 | struct scsi_target *starget; |
| 6322 | struct _sas_device *sas_device; |
| 6323 | unsigned long flags; |
| 6324 | |
| 6325 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6326 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { |
| 6327 | if (sas_device->sas_address == sas_address && |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6328 | sas_device->slot == slot) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6329 | sas_device->responding = 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6330 | starget = sas_device->starget; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6331 | if (starget && starget->hostdata) { |
| 6332 | sas_target_priv_data = starget->hostdata; |
| 6333 | sas_target_priv_data->tm_busy = 0; |
| 6334 | sas_target_priv_data->deleted = 0; |
| 6335 | } else |
| 6336 | sas_target_priv_data = NULL; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6337 | if (starget) |
| 6338 | starget_printk(KERN_INFO, starget, |
| 6339 | "handle(0x%04x), sas_addr(0x%016llx), " |
| 6340 | "enclosure logical id(0x%016llx), " |
| 6341 | "slot(%d)\n", handle, |
| 6342 | (unsigned long long)sas_device->sas_address, |
| 6343 | (unsigned long long) |
| 6344 | sas_device->enclosure_logical_id, |
| 6345 | sas_device->slot); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6346 | if (sas_device->handle == handle) |
| 6347 | goto out; |
| 6348 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 6349 | sas_device->handle); |
| 6350 | sas_device->handle = handle; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6351 | if (sas_target_priv_data) |
| 6352 | sas_target_priv_data->handle = handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6353 | goto out; |
| 6354 | } |
| 6355 | } |
| 6356 | out: |
| 6357 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6358 | } |
| 6359 | |
| 6360 | /** |
| 6361 | * _scsih_search_responding_sas_devices - |
| 6362 | * @ioc: per adapter object |
| 6363 | * |
| 6364 | * After host reset, find out whether devices are still responding. |
| 6365 | * If not remove. |
| 6366 | * |
| 6367 | * Return nothing. |
| 6368 | */ |
| 6369 | static void |
| 6370 | _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6371 | { |
| 6372 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6373 | Mpi2ConfigReply_t mpi_reply; |
| 6374 | u16 ioc_status; |
| 6375 | __le64 sas_address; |
| 6376 | u16 handle; |
| 6377 | u32 device_info; |
| 6378 | u16 slot; |
| 6379 | |
| 6380 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__); |
| 6381 | |
| 6382 | if (list_empty(&ioc->sas_device_list)) |
| 6383 | return; |
| 6384 | |
| 6385 | handle = 0xFFFF; |
| 6386 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6387 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 6388 | handle))) { |
| 6389 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6390 | MPI2_IOCSTATUS_MASK; |
| 6391 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6392 | break; |
| 6393 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 6394 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 6395 | if (!(_scsih_is_end_device(device_info))) |
| 6396 | continue; |
| 6397 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 6398 | slot = le16_to_cpu(sas_device_pg0.Slot); |
| 6399 | _scsih_mark_responding_sas_device(ioc, sas_address, slot, |
| 6400 | handle); |
| 6401 | } |
| 6402 | } |
| 6403 | |
| 6404 | /** |
| 6405 | * _scsih_mark_responding_raid_device - mark a raid_device as responding |
| 6406 | * @ioc: per adapter object |
| 6407 | * @wwid: world wide identifier for raid volume |
| 6408 | * @handle: device handle |
| 6409 | * |
| 6410 | * After host reset, find out whether devices are still responding. |
| 6411 | * Used in _scsi_remove_unresponsive_raid_devices. |
| 6412 | * |
| 6413 | * Return nothing. |
| 6414 | */ |
| 6415 | static void |
| 6416 | _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid, |
| 6417 | u16 handle) |
| 6418 | { |
| 6419 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 6420 | struct scsi_target *starget; |
| 6421 | struct _raid_device *raid_device; |
| 6422 | unsigned long flags; |
| 6423 | |
| 6424 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6425 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 6426 | if (raid_device->wwid == wwid && raid_device->starget) { |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6427 | starget = raid_device->starget; |
| 6428 | if (starget && starget->hostdata) { |
| 6429 | sas_target_priv_data = starget->hostdata; |
| 6430 | sas_target_priv_data->deleted = 0; |
| 6431 | } else |
| 6432 | sas_target_priv_data = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6433 | raid_device->responding = 1; |
| 6434 | starget_printk(KERN_INFO, raid_device->starget, |
| 6435 | "handle(0x%04x), wwid(0x%016llx)\n", handle, |
| 6436 | (unsigned long long)raid_device->wwid); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6437 | /* |
| 6438 | * WARPDRIVE: The handles of the PDs might have changed |
| 6439 | * across the host reset so re-initialize the |
| 6440 | * required data for Direct IO |
| 6441 | */ |
| 6442 | _scsih_init_warpdrive_properties(ioc, raid_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6443 | if (raid_device->handle == handle) |
| 6444 | goto out; |
| 6445 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 6446 | raid_device->handle); |
| 6447 | raid_device->handle = handle; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6448 | if (sas_target_priv_data) |
| 6449 | sas_target_priv_data->handle = handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6450 | goto out; |
| 6451 | } |
| 6452 | } |
| 6453 | out: |
| 6454 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6455 | } |
| 6456 | |
| 6457 | /** |
| 6458 | * _scsih_search_responding_raid_devices - |
| 6459 | * @ioc: per adapter object |
| 6460 | * |
| 6461 | * After host reset, find out whether devices are still responding. |
| 6462 | * If not remove. |
| 6463 | * |
| 6464 | * Return nothing. |
| 6465 | */ |
| 6466 | static void |
| 6467 | _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6468 | { |
| 6469 | Mpi2RaidVolPage1_t volume_pg1; |
Kashyap, Desai | d417d1c | 2010-06-17 13:48:10 +0530 | [diff] [blame] | 6470 | Mpi2RaidVolPage0_t volume_pg0; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6471 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6472 | Mpi2ConfigReply_t mpi_reply; |
| 6473 | u16 ioc_status; |
| 6474 | u16 handle; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6475 | u8 phys_disk_num; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6476 | |
| 6477 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__); |
| 6478 | |
| 6479 | if (list_empty(&ioc->raid_device_list)) |
| 6480 | return; |
| 6481 | |
| 6482 | handle = 0xFFFF; |
| 6483 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 6484 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 6485 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6486 | MPI2_IOCSTATUS_MASK; |
| 6487 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6488 | break; |
| 6489 | handle = le16_to_cpu(volume_pg1.DevHandle); |
Kashyap, Desai | d417d1c | 2010-06-17 13:48:10 +0530 | [diff] [blame] | 6490 | |
| 6491 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 6492 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 6493 | sizeof(Mpi2RaidVolPage0_t))) |
| 6494 | continue; |
| 6495 | |
| 6496 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 6497 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 6498 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) |
| 6499 | _scsih_mark_responding_raid_device(ioc, |
| 6500 | le64_to_cpu(volume_pg1.WWID), handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6501 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6502 | |
| 6503 | /* refresh the pd_handles */ |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6504 | if (!ioc->is_warpdrive) { |
| 6505 | phys_disk_num = 0xFF; |
| 6506 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); |
| 6507 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 6508 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 6509 | phys_disk_num))) { |
| 6510 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6511 | MPI2_IOCSTATUS_MASK; |
| 6512 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6513 | break; |
| 6514 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 6515 | handle = le16_to_cpu(pd_pg0.DevHandle); |
| 6516 | set_bit(handle, ioc->pd_handles); |
| 6517 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6518 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6519 | } |
| 6520 | |
| 6521 | /** |
| 6522 | * _scsih_mark_responding_expander - mark a expander as responding |
| 6523 | * @ioc: per adapter object |
| 6524 | * @sas_address: sas address |
| 6525 | * @handle: |
| 6526 | * |
| 6527 | * After host reset, find out whether devices are still responding. |
| 6528 | * Used in _scsi_remove_unresponsive_expanders. |
| 6529 | * |
| 6530 | * Return nothing. |
| 6531 | */ |
| 6532 | static void |
| 6533 | _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 6534 | u16 handle) |
| 6535 | { |
| 6536 | struct _sas_node *sas_expander; |
| 6537 | unsigned long flags; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6538 | int i; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6539 | |
| 6540 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 6541 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6542 | if (sas_expander->sas_address != sas_address) |
| 6543 | continue; |
| 6544 | sas_expander->responding = 1; |
| 6545 | if (sas_expander->handle == handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6546 | goto out; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6547 | printk(KERN_INFO "\texpander(0x%016llx): handle changed" |
| 6548 | " from(0x%04x) to (0x%04x)!!!\n", |
| 6549 | (unsigned long long)sas_expander->sas_address, |
| 6550 | sas_expander->handle, handle); |
| 6551 | sas_expander->handle = handle; |
| 6552 | for (i = 0 ; i < sas_expander->num_phys ; i++) |
| 6553 | sas_expander->phy[i].handle = handle; |
| 6554 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6555 | } |
| 6556 | out: |
| 6557 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 6558 | } |
| 6559 | |
| 6560 | /** |
| 6561 | * _scsih_search_responding_expanders - |
| 6562 | * @ioc: per adapter object |
| 6563 | * |
| 6564 | * After host reset, find out whether devices are still responding. |
| 6565 | * If not remove. |
| 6566 | * |
| 6567 | * Return nothing. |
| 6568 | */ |
| 6569 | static void |
| 6570 | _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc) |
| 6571 | { |
| 6572 | Mpi2ExpanderPage0_t expander_pg0; |
| 6573 | Mpi2ConfigReply_t mpi_reply; |
| 6574 | u16 ioc_status; |
| 6575 | __le64 sas_address; |
| 6576 | u16 handle; |
| 6577 | |
| 6578 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__); |
| 6579 | |
| 6580 | if (list_empty(&ioc->sas_expander_list)) |
| 6581 | return; |
| 6582 | |
| 6583 | handle = 0xFFFF; |
| 6584 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 6585 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 6586 | |
| 6587 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6588 | MPI2_IOCSTATUS_MASK; |
| 6589 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6590 | break; |
| 6591 | |
| 6592 | handle = le16_to_cpu(expander_pg0.DevHandle); |
| 6593 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
| 6594 | printk(KERN_INFO "\texpander present: handle(0x%04x), " |
| 6595 | "sas_addr(0x%016llx)\n", handle, |
| 6596 | (unsigned long long)sas_address); |
| 6597 | _scsih_mark_responding_expander(ioc, sas_address, handle); |
| 6598 | } |
| 6599 | |
| 6600 | } |
| 6601 | |
| 6602 | /** |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6603 | * _scsih_remove_unresponding_sas_devices - removing unresponding devices |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6604 | * @ioc: per adapter object |
| 6605 | * |
| 6606 | * Return nothing. |
| 6607 | */ |
| 6608 | static void |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6609 | _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6610 | { |
| 6611 | struct _sas_device *sas_device, *sas_device_next; |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 6612 | struct _sas_node *sas_expander; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6613 | struct _raid_device *raid_device, *raid_device_next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6614 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6615 | |
| 6616 | list_for_each_entry_safe(sas_device, sas_device_next, |
| 6617 | &ioc->sas_device_list, list) { |
| 6618 | if (sas_device->responding) { |
| 6619 | sas_device->responding = 0; |
| 6620 | continue; |
| 6621 | } |
| 6622 | if (sas_device->starget) |
| 6623 | starget_printk(KERN_INFO, sas_device->starget, |
| 6624 | "removing: handle(0x%04x), sas_addr(0x%016llx), " |
| 6625 | "enclosure logical id(0x%016llx), slot(%d)\n", |
| 6626 | sas_device->handle, |
| 6627 | (unsigned long long)sas_device->sas_address, |
| 6628 | (unsigned long long) |
| 6629 | sas_device->enclosure_logical_id, |
| 6630 | sas_device->slot); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6631 | _scsih_remove_device(ioc, sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6632 | } |
| 6633 | |
| 6634 | list_for_each_entry_safe(raid_device, raid_device_next, |
| 6635 | &ioc->raid_device_list, list) { |
| 6636 | if (raid_device->responding) { |
| 6637 | raid_device->responding = 0; |
| 6638 | continue; |
| 6639 | } |
| 6640 | if (raid_device->starget) { |
| 6641 | starget_printk(KERN_INFO, raid_device->starget, |
| 6642 | "removing: handle(0x%04x), wwid(0x%016llx)\n", |
| 6643 | raid_device->handle, |
| 6644 | (unsigned long long)raid_device->wwid); |
| 6645 | scsi_remove_target(&raid_device->starget->dev); |
| 6646 | } |
| 6647 | _scsih_raid_device_remove(ioc, raid_device); |
| 6648 | } |
| 6649 | |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 6650 | retry_expander_search: |
| 6651 | sas_expander = NULL; |
| 6652 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6653 | if (sas_expander->responding) { |
| 6654 | sas_expander->responding = 0; |
| 6655 | continue; |
| 6656 | } |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 6657 | mpt2sas_expander_remove(ioc, sas_expander->sas_address); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 6658 | goto retry_expander_search; |
| 6659 | } |
| 6660 | } |
| 6661 | |
| 6662 | /** |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6663 | * _scsih_hide_unhide_sas_devices - add/remove device to/from OS |
| 6664 | * @ioc: per adapter object |
| 6665 | * |
| 6666 | * Return nothing. |
| 6667 | */ |
| 6668 | static void |
| 6669 | _scsih_hide_unhide_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6670 | { |
| 6671 | struct _sas_device *sas_device, *sas_device_next; |
| 6672 | |
| 6673 | if (!ioc->is_warpdrive || ioc->mfg_pg10_hide_flag != |
| 6674 | MFG_PAGE10_HIDE_IF_VOL_PRESENT) |
| 6675 | return; |
| 6676 | |
| 6677 | if (ioc->hide_drives) { |
| 6678 | if (_scsih_get_num_volumes(ioc)) |
| 6679 | return; |
| 6680 | ioc->hide_drives = 0; |
| 6681 | list_for_each_entry_safe(sas_device, sas_device_next, |
| 6682 | &ioc->sas_device_list, list) { |
| 6683 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
| 6684 | sas_device->sas_address_parent)) { |
| 6685 | _scsih_sas_device_remove(ioc, sas_device); |
| 6686 | } else if (!sas_device->starget) { |
| 6687 | mpt2sas_transport_port_remove(ioc, |
| 6688 | sas_device->sas_address, |
| 6689 | sas_device->sas_address_parent); |
| 6690 | _scsih_sas_device_remove(ioc, sas_device); |
| 6691 | } |
| 6692 | } |
| 6693 | } else { |
| 6694 | if (!_scsih_get_num_volumes(ioc)) |
| 6695 | return; |
| 6696 | ioc->hide_drives = 1; |
| 6697 | list_for_each_entry_safe(sas_device, sas_device_next, |
| 6698 | &ioc->sas_device_list, list) { |
| 6699 | mpt2sas_transport_port_remove(ioc, |
| 6700 | sas_device->sas_address, |
| 6701 | sas_device->sas_address_parent); |
| 6702 | } |
| 6703 | } |
| 6704 | } |
| 6705 | |
| 6706 | /** |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 6707 | * mpt2sas_scsih_reset_handler - reset callback handler (for scsih) |
| 6708 | * @ioc: per adapter object |
| 6709 | * @reset_phase: phase |
| 6710 | * |
| 6711 | * The handler for doing any required cleanup or initialization. |
| 6712 | * |
| 6713 | * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET, |
| 6714 | * MPT2_IOC_DONE_RESET |
| 6715 | * |
| 6716 | * Return nothing. |
| 6717 | */ |
| 6718 | void |
| 6719 | mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase) |
| 6720 | { |
| 6721 | switch (reset_phase) { |
| 6722 | case MPT2_IOC_PRE_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6723 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 6724 | "MPT2_IOC_PRE_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 6725 | break; |
| 6726 | case MPT2_IOC_AFTER_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6727 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 6728 | "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6729 | if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) { |
| 6730 | ioc->scsih_cmds.status |= MPT2_CMD_RESET; |
| 6731 | mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid); |
| 6732 | complete(&ioc->scsih_cmds.done); |
| 6733 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 6734 | if (ioc->tm_cmds.status & MPT2_CMD_PENDING) { |
| 6735 | ioc->tm_cmds.status |= MPT2_CMD_RESET; |
| 6736 | mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid); |
| 6737 | complete(&ioc->tm_cmds.done); |
| 6738 | } |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6739 | _scsih_fw_event_cleanup_queue(ioc); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 6740 | _scsih_flush_running_cmds(ioc); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6741 | _scsih_queue_rescan(ioc); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 6742 | break; |
| 6743 | case MPT2_IOC_DONE_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6744 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 6745 | "MPT2_IOC_DONE_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6746 | _scsih_sas_host_refresh(ioc); |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6747 | _scsih_prep_device_scan(ioc); |
| 6748 | _scsih_search_responding_sas_devices(ioc); |
| 6749 | _scsih_search_responding_raid_devices(ioc); |
| 6750 | _scsih_search_responding_expanders(ioc); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 6751 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6752 | } |
| 6753 | } |
| 6754 | |
| 6755 | /** |
| 6756 | * _firmware_event_work - delayed task for processing firmware events |
| 6757 | * @ioc: per adapter object |
| 6758 | * @work: equal to the fw_event_work object |
| 6759 | * Context: user. |
| 6760 | * |
| 6761 | * Return nothing. |
| 6762 | */ |
| 6763 | static void |
| 6764 | _firmware_event_work(struct work_struct *work) |
| 6765 | { |
| 6766 | struct fw_event_work *fw_event = container_of(work, |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6767 | struct fw_event_work, delayed_work.work); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6768 | unsigned long flags; |
| 6769 | struct MPT2SAS_ADAPTER *ioc = fw_event->ioc; |
| 6770 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6771 | /* the queue is being flushed so ignore this event */ |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 6772 | if (ioc->remove_host || fw_event->cancel_pending_work || |
| 6773 | ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6774 | _scsih_fw_event_free(ioc, fw_event); |
| 6775 | return; |
| 6776 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6777 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6778 | if (fw_event->event == MPT2SAS_RESCAN_AFTER_HOST_RESET) { |
| 6779 | _scsih_fw_event_free(ioc, fw_event); |
| 6780 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
| 6781 | if (ioc->shost_recovery) { |
| 6782 | init_completion(&ioc->shost_recovery_done); |
| 6783 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, |
| 6784 | flags); |
| 6785 | wait_for_completion(&ioc->shost_recovery_done); |
| 6786 | } else |
| 6787 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, |
| 6788 | flags); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6789 | _scsih_remove_unresponding_sas_devices(ioc); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6790 | _scsih_hide_unhide_sas_devices(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6791 | return; |
| 6792 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6793 | |
| 6794 | switch (fw_event->event) { |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame^] | 6795 | case MPT2SAS_TURN_ON_FAULT_LED: |
| 6796 | _scsih_turn_on_fault_led(ioc, fw_event->device_handle); |
| 6797 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6798 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6799 | _scsih_sas_topology_change_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6800 | break; |
| 6801 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6802 | _scsih_sas_device_status_change_event(ioc, |
| 6803 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6804 | break; |
| 6805 | case MPI2_EVENT_SAS_DISCOVERY: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6806 | _scsih_sas_discovery_event(ioc, |
| 6807 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6808 | break; |
| 6809 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6810 | _scsih_sas_broadcast_primative_event(ioc, |
| 6811 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6812 | break; |
| 6813 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
| 6814 | _scsih_sas_enclosure_dev_status_change_event(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6815 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6816 | break; |
| 6817 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6818 | _scsih_sas_ir_config_change_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6819 | break; |
| 6820 | case MPI2_EVENT_IR_VOLUME: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6821 | _scsih_sas_ir_volume_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6822 | break; |
| 6823 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6824 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6825 | break; |
| 6826 | case MPI2_EVENT_IR_OPERATION_STATUS: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6827 | _scsih_sas_ir_operation_status_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6828 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6829 | } |
| 6830 | _scsih_fw_event_free(ioc, fw_event); |
| 6831 | } |
| 6832 | |
| 6833 | /** |
| 6834 | * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time) |
| 6835 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6836 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6837 | * @reply: reply message frame(lower 32bit addr) |
| 6838 | * Context: interrupt. |
| 6839 | * |
| 6840 | * This function merely adds a new work task into ioc->firmware_event_thread. |
| 6841 | * The tasks are worked from _firmware_event_work in user context. |
| 6842 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6843 | * Return 1 meaning mf should be freed from _base_interrupt |
| 6844 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6845 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6846 | u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6847 | mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, |
| 6848 | u32 reply) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6849 | { |
| 6850 | struct fw_event_work *fw_event; |
| 6851 | Mpi2EventNotificationReply_t *mpi_reply; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6852 | u16 event; |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 6853 | u16 sz; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6854 | |
| 6855 | /* events turned off due to host reset or driver unloading */ |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 6856 | if (ioc->remove_host || ioc->pci_error_recovery) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6857 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6858 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6859 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6860 | event = le16_to_cpu(mpi_reply->Event); |
| 6861 | |
| 6862 | switch (event) { |
| 6863 | /* handle these */ |
| 6864 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 6865 | { |
| 6866 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = |
| 6867 | (Mpi2EventDataSasBroadcastPrimitive_t *) |
| 6868 | mpi_reply->EventData; |
| 6869 | |
| 6870 | if (baen_data->Primitive != |
| 6871 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT || |
| 6872 | ioc->broadcast_aen_busy) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6873 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6874 | ioc->broadcast_aen_busy = 1; |
| 6875 | break; |
| 6876 | } |
| 6877 | |
| 6878 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
| 6879 | _scsih_check_topo_delete_events(ioc, |
| 6880 | (Mpi2EventDataSasTopologyChangeList_t *) |
| 6881 | mpi_reply->EventData); |
| 6882 | break; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6883 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
| 6884 | _scsih_check_ir_config_unhide_events(ioc, |
| 6885 | (Mpi2EventDataIrConfigChangeList_t *) |
| 6886 | mpi_reply->EventData); |
| 6887 | break; |
| 6888 | case MPI2_EVENT_IR_VOLUME: |
| 6889 | _scsih_check_volume_delete_events(ioc, |
| 6890 | (Mpi2EventDataIrVolume_t *) |
| 6891 | mpi_reply->EventData); |
| 6892 | break; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6893 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
| 6894 | { |
| 6895 | Mpi2EventDataLogEntryAdded_t *log_entry; |
| 6896 | u32 *log_code; |
| 6897 | |
| 6898 | if (!ioc->is_warpdrive) |
| 6899 | break; |
| 6900 | |
| 6901 | log_entry = (Mpi2EventDataLogEntryAdded_t *) |
| 6902 | mpi_reply->EventData; |
| 6903 | log_code = (u32 *)log_entry->LogData; |
| 6904 | |
| 6905 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
| 6906 | != MPT2_WARPDRIVE_LOGENTRY) |
| 6907 | break; |
| 6908 | |
| 6909 | switch (le32_to_cpu(*log_code)) { |
| 6910 | case MPT2_WARPDRIVE_LC_SSDT: |
| 6911 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " |
| 6912 | "IO Throttling has occurred in the WarpDrive " |
| 6913 | "subsystem. Check WarpDrive documentation for " |
| 6914 | "additional details.\n", ioc->name); |
| 6915 | break; |
| 6916 | case MPT2_WARPDRIVE_LC_SSDLW: |
| 6917 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " |
| 6918 | "Program/Erase Cycles for the WarpDrive subsystem " |
| 6919 | "in degraded range. Check WarpDrive documentation " |
| 6920 | "for additional details.\n", ioc->name); |
| 6921 | break; |
| 6922 | case MPT2_WARPDRIVE_LC_SSDLF: |
| 6923 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " |
| 6924 | "There are no Program/Erase Cycles for the " |
| 6925 | "WarpDrive subsystem. The storage device will be " |
| 6926 | "in read-only mode. Check WarpDrive documentation " |
| 6927 | "for additional details.\n", ioc->name); |
| 6928 | break; |
| 6929 | case MPT2_WARPDRIVE_LC_BRMF: |
| 6930 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " |
| 6931 | "The Backup Rail Monitor has failed on the " |
| 6932 | "WarpDrive subsystem. Check WarpDrive " |
| 6933 | "documentation for additional details.\n", |
| 6934 | ioc->name); |
| 6935 | break; |
| 6936 | } |
| 6937 | |
| 6938 | break; |
| 6939 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6940 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 6941 | case MPI2_EVENT_IR_OPERATION_STATUS: |
| 6942 | case MPI2_EVENT_SAS_DISCOVERY: |
| 6943 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6944 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6945 | break; |
| 6946 | |
| 6947 | default: /* ignore the rest */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6948 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6949 | } |
| 6950 | |
| 6951 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 6952 | if (!fw_event) { |
| 6953 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6954 | ioc->name, __FILE__, __LINE__, __func__); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6955 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6956 | } |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 6957 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
| 6958 | fw_event->event_data = kzalloc(sz, GFP_ATOMIC); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6959 | if (!fw_event->event_data) { |
| 6960 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6961 | ioc->name, __FILE__, __LINE__, __func__); |
| 6962 | kfree(fw_event); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6963 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6964 | } |
| 6965 | |
| 6966 | memcpy(fw_event->event_data, mpi_reply->EventData, |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 6967 | sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6968 | fw_event->ioc = ioc; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6969 | fw_event->VF_ID = mpi_reply->VF_ID; |
| 6970 | fw_event->VP_ID = mpi_reply->VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6971 | fw_event->event = event; |
| 6972 | _scsih_fw_event_add(ioc, fw_event); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6973 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6974 | } |
| 6975 | |
| 6976 | /* shost template */ |
| 6977 | static struct scsi_host_template scsih_driver_template = { |
| 6978 | .module = THIS_MODULE, |
| 6979 | .name = "Fusion MPT SAS Host", |
| 6980 | .proc_name = MPT2SAS_DRIVER_NAME, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 6981 | .queuecommand = _scsih_qcmd, |
| 6982 | .target_alloc = _scsih_target_alloc, |
| 6983 | .slave_alloc = _scsih_slave_alloc, |
| 6984 | .slave_configure = _scsih_slave_configure, |
| 6985 | .target_destroy = _scsih_target_destroy, |
| 6986 | .slave_destroy = _scsih_slave_destroy, |
| 6987 | .change_queue_depth = _scsih_change_queue_depth, |
| 6988 | .change_queue_type = _scsih_change_queue_type, |
| 6989 | .eh_abort_handler = _scsih_abort, |
| 6990 | .eh_device_reset_handler = _scsih_dev_reset, |
| 6991 | .eh_target_reset_handler = _scsih_target_reset, |
| 6992 | .eh_host_reset_handler = _scsih_host_reset, |
| 6993 | .bios_param = _scsih_bios_param, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6994 | .can_queue = 1, |
| 6995 | .this_id = -1, |
| 6996 | .sg_tablesize = MPT2SAS_SG_DEPTH, |
| 6997 | .max_sectors = 8192, |
| 6998 | .cmd_per_lun = 7, |
| 6999 | .use_clustering = ENABLE_CLUSTERING, |
| 7000 | .shost_attrs = mpt2sas_host_attrs, |
| 7001 | .sdev_attrs = mpt2sas_dev_attrs, |
| 7002 | }; |
| 7003 | |
| 7004 | /** |
| 7005 | * _scsih_expander_node_remove - removing expander device from list. |
| 7006 | * @ioc: per adapter object |
| 7007 | * @sas_expander: the sas_device object |
| 7008 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 7009 | * |
| 7010 | * Removing object and freeing associated memory from the |
| 7011 | * ioc->sas_expander_list. |
| 7012 | * |
| 7013 | * Return nothing. |
| 7014 | */ |
| 7015 | static void |
| 7016 | _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc, |
| 7017 | struct _sas_node *sas_expander) |
| 7018 | { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7019 | struct _sas_port *mpt2sas_port, *next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7020 | |
| 7021 | /* remove sibling ports attached to this expander */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7022 | list_for_each_entry_safe(mpt2sas_port, next, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7023 | &sas_expander->sas_port_list, port_list) { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7024 | if (ioc->shost_recovery) |
| 7025 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7026 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7027 | SAS_END_DEVICE) |
| 7028 | mpt2sas_device_remove(ioc, |
| 7029 | mpt2sas_port->remote_identify.sas_address); |
| 7030 | else if (mpt2sas_port->remote_identify.device_type == |
| 7031 | SAS_EDGE_EXPANDER_DEVICE || |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7032 | mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7033 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7034 | mpt2sas_expander_remove(ioc, |
| 7035 | mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7036 | } |
| 7037 | |
| 7038 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7039 | sas_expander->sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7040 | |
| 7041 | printk(MPT2SAS_INFO_FMT "expander_remove: handle" |
| 7042 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, |
| 7043 | sas_expander->handle, (unsigned long long) |
| 7044 | sas_expander->sas_address); |
| 7045 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7046 | kfree(sas_expander->phy); |
| 7047 | kfree(sas_expander); |
| 7048 | } |
| 7049 | |
| 7050 | /** |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7051 | * _scsih_ir_shutdown - IR shutdown notification |
| 7052 | * @ioc: per adapter object |
| 7053 | * |
| 7054 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that |
| 7055 | * the host system is shutting down. |
| 7056 | * |
| 7057 | * Return nothing. |
| 7058 | */ |
| 7059 | static void |
| 7060 | _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc) |
| 7061 | { |
| 7062 | Mpi2RaidActionRequest_t *mpi_request; |
| 7063 | Mpi2RaidActionReply_t *mpi_reply; |
| 7064 | u16 smid; |
| 7065 | |
| 7066 | /* is IR firmware build loaded ? */ |
| 7067 | if (!ioc->ir_firmware) |
| 7068 | return; |
| 7069 | |
| 7070 | /* are there any volumes ? */ |
| 7071 | if (list_empty(&ioc->raid_device_list)) |
| 7072 | return; |
| 7073 | |
| 7074 | mutex_lock(&ioc->scsih_cmds.mutex); |
| 7075 | |
| 7076 | if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) { |
| 7077 | printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n", |
| 7078 | ioc->name, __func__); |
| 7079 | goto out; |
| 7080 | } |
| 7081 | ioc->scsih_cmds.status = MPT2_CMD_PENDING; |
| 7082 | |
| 7083 | smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx); |
| 7084 | if (!smid) { |
| 7085 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 7086 | ioc->name, __func__); |
| 7087 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; |
| 7088 | goto out; |
| 7089 | } |
| 7090 | |
| 7091 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 7092 | ioc->scsih_cmds.smid = smid; |
| 7093 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); |
| 7094 | |
| 7095 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; |
| 7096 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; |
| 7097 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7098 | if (!ioc->hide_ir_msg) |
| 7099 | printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7100 | init_completion(&ioc->scsih_cmds.done); |
| 7101 | mpt2sas_base_put_smid_default(ioc, smid); |
| 7102 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
| 7103 | |
| 7104 | if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) { |
| 7105 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 7106 | ioc->name, __func__); |
| 7107 | goto out; |
| 7108 | } |
| 7109 | |
| 7110 | if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 7111 | mpi_reply = ioc->scsih_cmds.reply; |
| 7112 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7113 | if (!ioc->hide_ir_msg) |
| 7114 | printk(MPT2SAS_INFO_FMT "IR shutdown (complete): " |
| 7115 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7116 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 7117 | le32_to_cpu(mpi_reply->IOCLogInfo)); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7118 | } |
| 7119 | |
| 7120 | out: |
| 7121 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; |
| 7122 | mutex_unlock(&ioc->scsih_cmds.mutex); |
| 7123 | } |
| 7124 | |
| 7125 | /** |
| 7126 | * _scsih_shutdown - routine call during system shutdown |
| 7127 | * @pdev: PCI device struct |
| 7128 | * |
| 7129 | * Return nothing. |
| 7130 | */ |
| 7131 | static void |
| 7132 | _scsih_shutdown(struct pci_dev *pdev) |
| 7133 | { |
| 7134 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7135 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7136 | struct workqueue_struct *wq; |
| 7137 | unsigned long flags; |
| 7138 | |
| 7139 | ioc->remove_host = 1; |
| 7140 | _scsih_fw_event_cleanup_queue(ioc); |
| 7141 | |
| 7142 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7143 | wq = ioc->firmware_event_thread; |
| 7144 | ioc->firmware_event_thread = NULL; |
| 7145 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7146 | if (wq) |
| 7147 | destroy_workqueue(wq); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7148 | |
| 7149 | _scsih_ir_shutdown(ioc); |
| 7150 | mpt2sas_base_detach(ioc); |
| 7151 | } |
| 7152 | |
| 7153 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7154 | * _scsih_remove - detach and remove add host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7155 | * @pdev: PCI device struct |
| 7156 | * |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7157 | * Routine called when unloading the driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7158 | * Return nothing. |
| 7159 | */ |
| 7160 | static void __devexit |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7161 | _scsih_remove(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7162 | { |
| 7163 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7164 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7165 | struct _sas_port *mpt2sas_port, *next_port; |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7166 | struct _raid_device *raid_device, *next; |
| 7167 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7168 | struct workqueue_struct *wq; |
| 7169 | unsigned long flags; |
| 7170 | |
| 7171 | ioc->remove_host = 1; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7172 | _scsih_fw_event_cleanup_queue(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7173 | |
| 7174 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7175 | wq = ioc->firmware_event_thread; |
| 7176 | ioc->firmware_event_thread = NULL; |
| 7177 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7178 | if (wq) |
| 7179 | destroy_workqueue(wq); |
| 7180 | |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7181 | /* release all the volumes */ |
Kashyap, Desai | 3a9c913 | 2011-01-04 11:40:23 +0530 | [diff] [blame] | 7182 | _scsih_ir_shutdown(ioc); |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7183 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, |
| 7184 | list) { |
| 7185 | if (raid_device->starget) { |
| 7186 | sas_target_priv_data = |
| 7187 | raid_device->starget->hostdata; |
| 7188 | sas_target_priv_data->deleted = 1; |
| 7189 | scsi_remove_target(&raid_device->starget->dev); |
| 7190 | } |
| 7191 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" |
| 7192 | "(0x%016llx)\n", ioc->name, raid_device->handle, |
| 7193 | (unsigned long long) raid_device->wwid); |
| 7194 | _scsih_raid_device_remove(ioc, raid_device); |
| 7195 | } |
| 7196 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7197 | /* free ports attached to the sas_host */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7198 | list_for_each_entry_safe(mpt2sas_port, next_port, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7199 | &ioc->sas_hba.sas_port_list, port_list) { |
| 7200 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7201 | SAS_END_DEVICE) |
| 7202 | mpt2sas_device_remove(ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7203 | mpt2sas_port->remote_identify.sas_address); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7204 | else if (mpt2sas_port->remote_identify.device_type == |
| 7205 | SAS_EDGE_EXPANDER_DEVICE || |
| 7206 | mpt2sas_port->remote_identify.device_type == |
| 7207 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7208 | mpt2sas_expander_remove(ioc, |
| 7209 | mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7210 | } |
| 7211 | |
| 7212 | /* free phys attached to the sas_host */ |
| 7213 | if (ioc->sas_hba.num_phys) { |
| 7214 | kfree(ioc->sas_hba.phy); |
| 7215 | ioc->sas_hba.phy = NULL; |
| 7216 | ioc->sas_hba.num_phys = 0; |
| 7217 | } |
| 7218 | |
| 7219 | sas_remove_host(shost); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7220 | _scsih_shutdown(pdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7221 | list_del(&ioc->list); |
| 7222 | scsi_remove_host(shost); |
| 7223 | scsi_host_put(shost); |
| 7224 | } |
| 7225 | |
| 7226 | /** |
| 7227 | * _scsih_probe_boot_devices - reports 1st device |
| 7228 | * @ioc: per adapter object |
| 7229 | * |
| 7230 | * If specified in bios page 2, this routine reports the 1st |
| 7231 | * device scsi-ml or sas transport for persistent boot device |
| 7232 | * purposes. Please refer to function _scsih_determine_boot_device() |
| 7233 | */ |
| 7234 | static void |
| 7235 | _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc) |
| 7236 | { |
| 7237 | u8 is_raid; |
| 7238 | void *device; |
| 7239 | struct _sas_device *sas_device; |
| 7240 | struct _raid_device *raid_device; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7241 | u16 handle; |
| 7242 | u64 sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7243 | u64 sas_address; |
| 7244 | unsigned long flags; |
| 7245 | int rc; |
| 7246 | |
| 7247 | device = NULL; |
| 7248 | if (ioc->req_boot_device.device) { |
| 7249 | device = ioc->req_boot_device.device; |
| 7250 | is_raid = ioc->req_boot_device.is_raid; |
| 7251 | } else if (ioc->req_alt_boot_device.device) { |
| 7252 | device = ioc->req_alt_boot_device.device; |
| 7253 | is_raid = ioc->req_alt_boot_device.is_raid; |
| 7254 | } else if (ioc->current_boot_device.device) { |
| 7255 | device = ioc->current_boot_device.device; |
| 7256 | is_raid = ioc->current_boot_device.is_raid; |
| 7257 | } |
| 7258 | |
| 7259 | if (!device) |
| 7260 | return; |
| 7261 | |
| 7262 | if (is_raid) { |
| 7263 | raid_device = device; |
| 7264 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7265 | raid_device->id, 0); |
| 7266 | if (rc) |
| 7267 | _scsih_raid_device_remove(ioc, raid_device); |
| 7268 | } else { |
| 7269 | sas_device = device; |
| 7270 | handle = sas_device->handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7271 | sas_address_parent = sas_device->sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7272 | sas_address = sas_device->sas_address; |
| 7273 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 7274 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 7275 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7276 | |
| 7277 | if (ioc->hide_drives) |
| 7278 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7279 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7280 | sas_device->sas_address_parent)) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7281 | _scsih_sas_device_remove(ioc, sas_device); |
| 7282 | } else if (!sas_device->starget) { |
| 7283 | mpt2sas_transport_port_remove(ioc, sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7284 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7285 | _scsih_sas_device_remove(ioc, sas_device); |
| 7286 | } |
| 7287 | } |
| 7288 | } |
| 7289 | |
| 7290 | /** |
| 7291 | * _scsih_probe_raid - reporting raid volumes to scsi-ml |
| 7292 | * @ioc: per adapter object |
| 7293 | * |
| 7294 | * Called during initial loading of the driver. |
| 7295 | */ |
| 7296 | static void |
| 7297 | _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc) |
| 7298 | { |
| 7299 | struct _raid_device *raid_device, *raid_next; |
| 7300 | int rc; |
| 7301 | |
| 7302 | list_for_each_entry_safe(raid_device, raid_next, |
| 7303 | &ioc->raid_device_list, list) { |
| 7304 | if (raid_device->starget) |
| 7305 | continue; |
| 7306 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7307 | raid_device->id, 0); |
| 7308 | if (rc) |
| 7309 | _scsih_raid_device_remove(ioc, raid_device); |
| 7310 | } |
| 7311 | } |
| 7312 | |
| 7313 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7314 | * _scsih_probe_sas - reporting sas devices to sas transport |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7315 | * @ioc: per adapter object |
| 7316 | * |
| 7317 | * Called during initial loading of the driver. |
| 7318 | */ |
| 7319 | static void |
| 7320 | _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc) |
| 7321 | { |
| 7322 | struct _sas_device *sas_device, *next; |
| 7323 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7324 | |
| 7325 | /* SAS Device List */ |
| 7326 | list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list, |
| 7327 | list) { |
| 7328 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 7329 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 7330 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 7331 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7332 | if (ioc->hide_drives) |
| 7333 | continue; |
| 7334 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7335 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
| 7336 | sas_device->sas_address_parent)) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7337 | _scsih_sas_device_remove(ioc, sas_device); |
| 7338 | } else if (!sas_device->starget) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7339 | mpt2sas_transport_port_remove(ioc, |
| 7340 | sas_device->sas_address, |
| 7341 | sas_device->sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7342 | _scsih_sas_device_remove(ioc, sas_device); |
| 7343 | } |
| 7344 | } |
| 7345 | } |
| 7346 | |
| 7347 | /** |
| 7348 | * _scsih_probe_devices - probing for devices |
| 7349 | * @ioc: per adapter object |
| 7350 | * |
| 7351 | * Called during initial loading of the driver. |
| 7352 | */ |
| 7353 | static void |
| 7354 | _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc) |
| 7355 | { |
| 7356 | u16 volume_mapping_flags = |
| 7357 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & |
| 7358 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; |
| 7359 | |
| 7360 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) |
| 7361 | return; /* return when IOC doesn't support initiator mode */ |
| 7362 | |
| 7363 | _scsih_probe_boot_devices(ioc); |
| 7364 | |
| 7365 | if (ioc->ir_firmware) { |
| 7366 | if ((volume_mapping_flags & |
| 7367 | MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING)) { |
| 7368 | _scsih_probe_sas(ioc); |
| 7369 | _scsih_probe_raid(ioc); |
| 7370 | } else { |
| 7371 | _scsih_probe_raid(ioc); |
| 7372 | _scsih_probe_sas(ioc); |
| 7373 | } |
| 7374 | } else |
| 7375 | _scsih_probe_sas(ioc); |
| 7376 | } |
| 7377 | |
| 7378 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7379 | * _scsih_probe - attach and add scsi host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7380 | * @pdev: PCI device struct |
| 7381 | * @id: pci device id |
| 7382 | * |
| 7383 | * Returns 0 success, anything else error. |
| 7384 | */ |
| 7385 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7386 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7387 | { |
| 7388 | struct MPT2SAS_ADAPTER *ioc; |
| 7389 | struct Scsi_Host *shost; |
| 7390 | |
| 7391 | shost = scsi_host_alloc(&scsih_driver_template, |
| 7392 | sizeof(struct MPT2SAS_ADAPTER)); |
| 7393 | if (!shost) |
| 7394 | return -ENODEV; |
| 7395 | |
| 7396 | /* init local params */ |
| 7397 | ioc = shost_priv(shost); |
| 7398 | memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER)); |
| 7399 | INIT_LIST_HEAD(&ioc->list); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 7400 | list_add_tail(&ioc->list, &mpt2sas_ioc_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7401 | ioc->shost = shost; |
| 7402 | ioc->id = mpt_ids++; |
| 7403 | sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id); |
| 7404 | ioc->pdev = pdev; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7405 | if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) { |
| 7406 | ioc->is_warpdrive = 1; |
| 7407 | ioc->hide_ir_msg = 1; |
| 7408 | } else |
| 7409 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7410 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; |
| 7411 | ioc->tm_cb_idx = tm_cb_idx; |
| 7412 | ioc->ctl_cb_idx = ctl_cb_idx; |
| 7413 | ioc->base_cb_idx = base_cb_idx; |
| 7414 | ioc->transport_cb_idx = transport_cb_idx; |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7415 | ioc->scsih_cb_idx = scsih_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7416 | ioc->config_cb_idx = config_cb_idx; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7417 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 7418 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7419 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7420 | ioc->logging_level = logging_level; |
| 7421 | /* misc semaphores and spin locks */ |
Kashyap, Desai | d274213 | 2010-06-17 13:28:55 +0530 | [diff] [blame] | 7422 | mutex_init(&ioc->reset_in_progress_mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7423 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
| 7424 | spin_lock_init(&ioc->scsi_lookup_lock); |
| 7425 | spin_lock_init(&ioc->sas_device_lock); |
| 7426 | spin_lock_init(&ioc->sas_node_lock); |
| 7427 | spin_lock_init(&ioc->fw_event_lock); |
| 7428 | spin_lock_init(&ioc->raid_device_lock); |
| 7429 | |
| 7430 | INIT_LIST_HEAD(&ioc->sas_device_list); |
| 7431 | INIT_LIST_HEAD(&ioc->sas_device_init_list); |
| 7432 | INIT_LIST_HEAD(&ioc->sas_expander_list); |
| 7433 | INIT_LIST_HEAD(&ioc->fw_event_list); |
| 7434 | INIT_LIST_HEAD(&ioc->raid_device_list); |
| 7435 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7436 | INIT_LIST_HEAD(&ioc->delayed_tr_list); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 7437 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7438 | |
| 7439 | /* init shost parameters */ |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 7440 | shost->max_cmd_len = 32; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7441 | shost->max_lun = max_lun; |
| 7442 | shost->transportt = mpt2sas_transport_template; |
| 7443 | shost->unique_id = ioc->id; |
| 7444 | |
| 7445 | if ((scsi_add_host(shost, &pdev->dev))) { |
| 7446 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7447 | ioc->name, __FILE__, __LINE__, __func__); |
| 7448 | list_del(&ioc->list); |
| 7449 | goto out_add_shost_fail; |
| 7450 | } |
| 7451 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 7452 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 7453 | | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7454 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 7455 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7456 | /* event thread */ |
| 7457 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), |
| 7458 | "fw_event%d", ioc->id); |
| 7459 | ioc->firmware_event_thread = create_singlethread_workqueue( |
| 7460 | ioc->firmware_event_name); |
| 7461 | if (!ioc->firmware_event_thread) { |
| 7462 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7463 | ioc->name, __FILE__, __LINE__, __func__); |
| 7464 | goto out_thread_fail; |
| 7465 | } |
| 7466 | |
| 7467 | ioc->wait_for_port_enable_to_complete = 1; |
| 7468 | if ((mpt2sas_base_attach(ioc))) { |
| 7469 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7470 | ioc->name, __FILE__, __LINE__, __func__); |
| 7471 | goto out_attach_fail; |
| 7472 | } |
| 7473 | |
| 7474 | ioc->wait_for_port_enable_to_complete = 0; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7475 | if (ioc->is_warpdrive) { |
| 7476 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) |
| 7477 | ioc->hide_drives = 0; |
| 7478 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) |
| 7479 | ioc->hide_drives = 1; |
| 7480 | else { |
| 7481 | if (_scsih_get_num_volumes(ioc)) |
| 7482 | ioc->hide_drives = 1; |
| 7483 | else |
| 7484 | ioc->hide_drives = 0; |
| 7485 | } |
| 7486 | } else |
| 7487 | ioc->hide_drives = 0; |
| 7488 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7489 | _scsih_probe_devices(ioc); |
| 7490 | return 0; |
| 7491 | |
| 7492 | out_attach_fail: |
| 7493 | destroy_workqueue(ioc->firmware_event_thread); |
| 7494 | out_thread_fail: |
| 7495 | list_del(&ioc->list); |
| 7496 | scsi_remove_host(shost); |
| 7497 | out_add_shost_fail: |
| 7498 | return -ENODEV; |
| 7499 | } |
| 7500 | |
| 7501 | #ifdef CONFIG_PM |
| 7502 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7503 | * _scsih_suspend - power management suspend main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7504 | * @pdev: PCI device struct |
| 7505 | * @state: PM state change to (usually PCI_D3) |
| 7506 | * |
| 7507 | * Returns 0 success, anything else error. |
| 7508 | */ |
| 7509 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7510 | _scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7511 | { |
| 7512 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7513 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 7514 | u32 device_state; |
| 7515 | |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 7516 | mpt2sas_base_stop_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7517 | scsi_block_requests(shost); |
| 7518 | device_state = pci_choose_state(pdev, state); |
| 7519 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering " |
| 7520 | "operating state [D%d]\n", ioc->name, pdev, |
| 7521 | pci_name(pdev), device_state); |
| 7522 | |
| 7523 | mpt2sas_base_free_resources(ioc); |
| 7524 | pci_save_state(pdev); |
| 7525 | pci_disable_device(pdev); |
| 7526 | pci_set_power_state(pdev, device_state); |
| 7527 | return 0; |
| 7528 | } |
| 7529 | |
| 7530 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7531 | * _scsih_resume - power management resume main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7532 | * @pdev: PCI device struct |
| 7533 | * |
| 7534 | * Returns 0 success, anything else error. |
| 7535 | */ |
| 7536 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7537 | _scsih_resume(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7538 | { |
| 7539 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7540 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 7541 | u32 device_state = pdev->current_state; |
| 7542 | int r; |
| 7543 | |
| 7544 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous " |
| 7545 | "operating state [D%d]\n", ioc->name, pdev, |
| 7546 | pci_name(pdev), device_state); |
| 7547 | |
| 7548 | pci_set_power_state(pdev, PCI_D0); |
| 7549 | pci_enable_wake(pdev, PCI_D0, 0); |
| 7550 | pci_restore_state(pdev); |
| 7551 | ioc->pdev = pdev; |
| 7552 | r = mpt2sas_base_map_resources(ioc); |
| 7553 | if (r) |
| 7554 | return r; |
| 7555 | |
| 7556 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET); |
| 7557 | scsi_unblock_requests(shost); |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 7558 | mpt2sas_base_start_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7559 | return 0; |
| 7560 | } |
| 7561 | #endif /* CONFIG_PM */ |
| 7562 | |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 7563 | /** |
| 7564 | * _scsih_pci_error_detected - Called when a PCI error is detected. |
| 7565 | * @pdev: PCI device struct |
| 7566 | * @state: PCI channel state |
| 7567 | * |
| 7568 | * Description: Called when a PCI error is detected. |
| 7569 | * |
| 7570 | * Return value: |
| 7571 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT |
| 7572 | */ |
| 7573 | static pci_ers_result_t |
| 7574 | _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 7575 | { |
| 7576 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7577 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 7578 | |
| 7579 | printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n", |
| 7580 | ioc->name, state); |
| 7581 | |
| 7582 | switch (state) { |
| 7583 | case pci_channel_io_normal: |
| 7584 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 7585 | case pci_channel_io_frozen: |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7586 | /* Fatal error, prepare for slot reset */ |
| 7587 | ioc->pci_error_recovery = 1; |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 7588 | scsi_block_requests(ioc->shost); |
| 7589 | mpt2sas_base_stop_watchdog(ioc); |
| 7590 | mpt2sas_base_free_resources(ioc); |
| 7591 | return PCI_ERS_RESULT_NEED_RESET; |
| 7592 | case pci_channel_io_perm_failure: |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7593 | /* Permanent error, prepare for device removal */ |
| 7594 | ioc->pci_error_recovery = 1; |
| 7595 | mpt2sas_base_stop_watchdog(ioc); |
| 7596 | _scsih_flush_running_cmds(ioc); |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 7597 | return PCI_ERS_RESULT_DISCONNECT; |
| 7598 | } |
| 7599 | return PCI_ERS_RESULT_NEED_RESET; |
| 7600 | } |
| 7601 | |
| 7602 | /** |
| 7603 | * _scsih_pci_slot_reset - Called when PCI slot has been reset. |
| 7604 | * @pdev: PCI device struct |
| 7605 | * |
| 7606 | * Description: This routine is called by the pci error recovery |
| 7607 | * code after the PCI slot has been reset, just before we |
| 7608 | * should resume normal operations. |
| 7609 | */ |
| 7610 | static pci_ers_result_t |
| 7611 | _scsih_pci_slot_reset(struct pci_dev *pdev) |
| 7612 | { |
| 7613 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7614 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 7615 | int rc; |
| 7616 | |
| 7617 | printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n", |
| 7618 | ioc->name); |
| 7619 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7620 | ioc->pci_error_recovery = 0; |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 7621 | ioc->pdev = pdev; |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7622 | pci_restore_state(pdev); |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 7623 | rc = mpt2sas_base_map_resources(ioc); |
| 7624 | if (rc) |
| 7625 | return PCI_ERS_RESULT_DISCONNECT; |
| 7626 | |
| 7627 | |
| 7628 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 7629 | FORCE_BIG_HAMMER); |
| 7630 | |
| 7631 | printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name, |
| 7632 | (rc == 0) ? "success" : "failed"); |
| 7633 | |
| 7634 | if (!rc) |
| 7635 | return PCI_ERS_RESULT_RECOVERED; |
| 7636 | else |
| 7637 | return PCI_ERS_RESULT_DISCONNECT; |
| 7638 | } |
| 7639 | |
| 7640 | /** |
| 7641 | * _scsih_pci_resume() - resume normal ops after PCI reset |
| 7642 | * @pdev: pointer to PCI device |
| 7643 | * |
| 7644 | * Called when the error recovery driver tells us that its |
| 7645 | * OK to resume normal operation. Use completion to allow |
| 7646 | * halted scsi ops to resume. |
| 7647 | */ |
| 7648 | static void |
| 7649 | _scsih_pci_resume(struct pci_dev *pdev) |
| 7650 | { |
| 7651 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7652 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 7653 | |
| 7654 | printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name); |
| 7655 | |
| 7656 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 7657 | mpt2sas_base_start_watchdog(ioc); |
| 7658 | scsi_unblock_requests(ioc->shost); |
| 7659 | } |
| 7660 | |
| 7661 | /** |
| 7662 | * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
| 7663 | * @pdev: pointer to PCI device |
| 7664 | */ |
| 7665 | static pci_ers_result_t |
| 7666 | _scsih_pci_mmio_enabled(struct pci_dev *pdev) |
| 7667 | { |
| 7668 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7669 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 7670 | |
| 7671 | printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n", |
| 7672 | ioc->name); |
| 7673 | |
| 7674 | /* TODO - dump whatever for debugging purposes */ |
| 7675 | |
| 7676 | /* Request a slot reset. */ |
| 7677 | return PCI_ERS_RESULT_NEED_RESET; |
| 7678 | } |
| 7679 | |
| 7680 | static struct pci_error_handlers _scsih_err_handler = { |
| 7681 | .error_detected = _scsih_pci_error_detected, |
| 7682 | .mmio_enabled = _scsih_pci_mmio_enabled, |
| 7683 | .slot_reset = _scsih_pci_slot_reset, |
| 7684 | .resume = _scsih_pci_resume, |
| 7685 | }; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7686 | |
| 7687 | static struct pci_driver scsih_driver = { |
| 7688 | .name = MPT2SAS_DRIVER_NAME, |
| 7689 | .id_table = scsih_pci_table, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7690 | .probe = _scsih_probe, |
| 7691 | .remove = __devexit_p(_scsih_remove), |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7692 | .shutdown = _scsih_shutdown, |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 7693 | .err_handler = &_scsih_err_handler, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7694 | #ifdef CONFIG_PM |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7695 | .suspend = _scsih_suspend, |
| 7696 | .resume = _scsih_resume, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7697 | #endif |
| 7698 | }; |
| 7699 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 7700 | /* raid transport support */ |
| 7701 | static struct raid_function_template mpt2sas_raid_functions = { |
| 7702 | .cookie = &scsih_driver_template, |
| 7703 | .is_raid = _scsih_is_raid, |
| 7704 | .get_resync = _scsih_get_resync, |
| 7705 | .get_state = _scsih_get_state, |
| 7706 | }; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7707 | |
| 7708 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7709 | * _scsih_init - main entry point for this driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7710 | * |
| 7711 | * Returns 0 success, anything else error. |
| 7712 | */ |
| 7713 | static int __init |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7714 | _scsih_init(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7715 | { |
| 7716 | int error; |
| 7717 | |
| 7718 | mpt_ids = 0; |
| 7719 | printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME, |
| 7720 | MPT2SAS_DRIVER_VERSION); |
| 7721 | |
| 7722 | mpt2sas_transport_template = |
| 7723 | sas_attach_transport(&mpt2sas_transport_functions); |
| 7724 | if (!mpt2sas_transport_template) |
| 7725 | return -ENODEV; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 7726 | /* raid transport support */ |
| 7727 | mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions); |
| 7728 | if (!mpt2sas_raid_template) { |
| 7729 | sas_release_transport(mpt2sas_transport_template); |
| 7730 | return -ENODEV; |
| 7731 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7732 | |
| 7733 | mpt2sas_base_initialize_callback_handler(); |
| 7734 | |
| 7735 | /* queuecommand callback hander */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7736 | scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7737 | |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 7738 | /* task management callback handler */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7739 | tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7740 | |
| 7741 | /* base internal commands callback handler */ |
| 7742 | base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done); |
| 7743 | |
| 7744 | /* transport internal commands callback handler */ |
| 7745 | transport_cb_idx = mpt2sas_base_register_callback_handler( |
| 7746 | mpt2sas_transport_done); |
| 7747 | |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7748 | /* scsih internal commands callback handler */ |
| 7749 | scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done); |
| 7750 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7751 | /* configuration page API internal commands callback handler */ |
| 7752 | config_cb_idx = mpt2sas_base_register_callback_handler( |
| 7753 | mpt2sas_config_done); |
| 7754 | |
| 7755 | /* ctl module callback handler */ |
| 7756 | ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done); |
| 7757 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7758 | tm_tr_cb_idx = mpt2sas_base_register_callback_handler( |
| 7759 | _scsih_tm_tr_complete); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 7760 | |
| 7761 | tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler( |
| 7762 | _scsih_tm_volume_tr_complete); |
| 7763 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7764 | tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler( |
| 7765 | _scsih_sas_control_complete); |
| 7766 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7767 | mpt2sas_ctl_init(); |
| 7768 | |
| 7769 | error = pci_register_driver(&scsih_driver); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 7770 | if (error) { |
| 7771 | /* raid transport support */ |
| 7772 | raid_class_release(mpt2sas_raid_template); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7773 | sas_release_transport(mpt2sas_transport_template); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 7774 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7775 | |
| 7776 | return error; |
| 7777 | } |
| 7778 | |
| 7779 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7780 | * _scsih_exit - exit point for this driver (when it is a module). |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7781 | * |
| 7782 | * Returns 0 success, anything else error. |
| 7783 | */ |
| 7784 | static void __exit |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7785 | _scsih_exit(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7786 | { |
| 7787 | printk(KERN_INFO "mpt2sas version %s unloading\n", |
| 7788 | MPT2SAS_DRIVER_VERSION); |
| 7789 | |
| 7790 | pci_unregister_driver(&scsih_driver); |
| 7791 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 7792 | mpt2sas_ctl_exit(); |
| 7793 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7794 | mpt2sas_base_release_callback_handler(scsi_io_cb_idx); |
| 7795 | mpt2sas_base_release_callback_handler(tm_cb_idx); |
| 7796 | mpt2sas_base_release_callback_handler(base_cb_idx); |
| 7797 | mpt2sas_base_release_callback_handler(transport_cb_idx); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7798 | mpt2sas_base_release_callback_handler(scsih_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7799 | mpt2sas_base_release_callback_handler(config_cb_idx); |
| 7800 | mpt2sas_base_release_callback_handler(ctl_cb_idx); |
| 7801 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7802 | mpt2sas_base_release_callback_handler(tm_tr_cb_idx); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 7803 | mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7804 | mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx); |
| 7805 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 7806 | /* raid transport support */ |
| 7807 | raid_class_release(mpt2sas_raid_template); |
| 7808 | sas_release_transport(mpt2sas_transport_template); |
| 7809 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7810 | } |
| 7811 | |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7812 | module_init(_scsih_init); |
| 7813 | module_exit(_scsih_exit); |