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 |
Sreekanth Reddy | d648d5a | 2013-07-25 11:28:01 +0530 | [diff] [blame] | 5 | * Copyright (C) 2007-2013 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 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 44 | #include <linux/module.h> |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/init.h> |
| 47 | #include <linux/errno.h> |
| 48 | #include <linux/blkdev.h> |
| 49 | #include <linux/sched.h> |
| 50 | #include <linux/workqueue.h> |
| 51 | #include <linux/delay.h> |
| 52 | #include <linux/pci.h> |
| 53 | #include <linux/interrupt.h> |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 54 | #include <linux/aer.h> |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 55 | #include <linux/raid_class.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 56 | #include <linux/slab.h> |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 57 | |
| 58 | #include "mpt2sas_base.h" |
| 59 | |
| 60 | MODULE_AUTHOR(MPT2SAS_AUTHOR); |
| 61 | MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION); |
| 62 | MODULE_LICENSE("GPL"); |
| 63 | MODULE_VERSION(MPT2SAS_DRIVER_VERSION); |
| 64 | |
| 65 | #define RAID_CHANNEL 1 |
| 66 | |
| 67 | /* forward proto's */ |
| 68 | static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc, |
| 69 | struct _sas_node *sas_expander); |
| 70 | static void _firmware_event_work(struct work_struct *work); |
| 71 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 72 | static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid); |
| 73 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 74 | static void _scsih_scan_start(struct Scsi_Host *shost); |
| 75 | static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time); |
| 76 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 77 | /* global parameters */ |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 78 | LIST_HEAD(mpt2sas_ioc_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 79 | |
| 80 | /* local parameters */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 81 | static u8 scsi_io_cb_idx = -1; |
| 82 | static u8 tm_cb_idx = -1; |
| 83 | static u8 ctl_cb_idx = -1; |
| 84 | static u8 base_cb_idx = -1; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 85 | static u8 port_enable_cb_idx = -1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 86 | static u8 transport_cb_idx = -1; |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 87 | static u8 scsih_cb_idx = -1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 88 | static u8 config_cb_idx = -1; |
| 89 | static int mpt_ids; |
| 90 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 91 | static u8 tm_tr_cb_idx = -1 ; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 92 | static u8 tm_tr_volume_cb_idx = -1 ; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 93 | static u8 tm_sas_control_cb_idx = -1; |
| 94 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 95 | /* command line options */ |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 96 | static u32 logging_level; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 97 | MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info " |
| 98 | "(default=0)"); |
| 99 | |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 100 | static ushort max_sectors = 0xFFFF; |
| 101 | module_param(max_sectors, ushort, 0); |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 102 | MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767"); |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 103 | |
Reddy, Sreekanth | b0df96a0 | 2013-02-26 16:59:59 +0530 | [diff] [blame] | 104 | static int missing_delay[2] = {-1, -1}; |
| 105 | module_param_array(missing_delay, int, NULL, 0); |
| 106 | MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay"); |
| 107 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 108 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ |
| 109 | #define MPT2SAS_MAX_LUN (16895) |
| 110 | static int max_lun = MPT2SAS_MAX_LUN; |
| 111 | module_param(max_lun, int, 0); |
| 112 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); |
| 113 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 114 | /* diag_buffer_enable is bitwise |
| 115 | * bit 0 set = TRACE |
| 116 | * bit 1 set = SNAPSHOT |
| 117 | * bit 2 set = EXTENDED |
| 118 | * |
| 119 | * Either bit can be set, or both |
| 120 | */ |
| 121 | static int diag_buffer_enable = -1; |
| 122 | module_param(diag_buffer_enable, int, 0); |
| 123 | MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers " |
| 124 | "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); |
| 125 | |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 126 | static int disable_discovery = -1; |
| 127 | module_param(disable_discovery, int, 0); |
| 128 | MODULE_PARM_DESC(disable_discovery, " disable discovery "); |
| 129 | |
Martin K. Petersen | 5e95e73 | 2012-08-28 14:29:37 -0400 | [diff] [blame] | 130 | /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */ |
| 131 | static int prot_mask = 0; |
| 132 | module_param(prot_mask, int, 0); |
| 133 | MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 "); |
| 134 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 135 | /** |
| 136 | * struct sense_info - common structure for obtaining sense keys |
| 137 | * @skey: sense key |
| 138 | * @asc: additional sense code |
| 139 | * @ascq: additional sense code qualifier |
| 140 | */ |
| 141 | struct sense_info { |
| 142 | u8 skey; |
| 143 | u8 asc; |
| 144 | u8 ascq; |
| 145 | }; |
| 146 | |
| 147 | |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 148 | #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 149 | #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD) |
| 150 | #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 151 | /** |
| 152 | * struct fw_event_work - firmware event struct |
| 153 | * @list: link list framework |
| 154 | * @work: work object (ioc->fault_reset_work_q) |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 155 | * @cancel_pending_work: flag set during reset handling |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 156 | * @ioc: per adapter object |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 157 | * @device_handle: device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 158 | * @VF_ID: virtual function id |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 159 | * @VP_ID: virtual port id |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 160 | * @ignore: flag meaning this event has been marked to ignore |
| 161 | * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h |
| 162 | * @event_data: reply event data payload follows |
| 163 | * |
| 164 | * This object stored on ioc->fw_event_list. |
| 165 | */ |
| 166 | struct fw_event_work { |
| 167 | struct list_head list; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 168 | u8 cancel_pending_work; |
| 169 | struct delayed_work delayed_work; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 170 | struct MPT2SAS_ADAPTER *ioc; |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 171 | u16 device_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 172 | u8 VF_ID; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 173 | u8 VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 174 | u8 ignore; |
| 175 | u16 event; |
| 176 | void *event_data; |
| 177 | }; |
| 178 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 179 | /* raid transport support */ |
| 180 | static struct raid_template *mpt2sas_raid_template; |
| 181 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 182 | /** |
| 183 | * struct _scsi_io_transfer - scsi io transfer |
| 184 | * @handle: sas device handle (assigned by firmware) |
| 185 | * @is_raid: flag set for hidden raid components |
| 186 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, |
| 187 | * @data_length: data transfer length |
| 188 | * @data_dma: dma pointer to data |
| 189 | * @sense: sense data |
| 190 | * @lun: lun number |
| 191 | * @cdb_length: cdb length |
| 192 | * @cdb: cdb contents |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 193 | * @timeout: timeout for this command |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 194 | * @VF_ID: virtual function id |
| 195 | * @VP_ID: virtual port id |
| 196 | * @valid_reply: flag set for reply message |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 197 | * @sense_length: sense length |
| 198 | * @ioc_status: ioc status |
| 199 | * @scsi_state: scsi state |
| 200 | * @scsi_status: scsi staus |
| 201 | * @log_info: log information |
| 202 | * @transfer_length: data length transfer when there is a reply message |
| 203 | * |
| 204 | * Used for sending internal scsi commands to devices within this module. |
| 205 | * Refer to _scsi_send_scsi_io(). |
| 206 | */ |
| 207 | struct _scsi_io_transfer { |
| 208 | u16 handle; |
| 209 | u8 is_raid; |
| 210 | enum dma_data_direction dir; |
| 211 | u32 data_length; |
| 212 | dma_addr_t data_dma; |
| 213 | u8 sense[SCSI_SENSE_BUFFERSIZE]; |
| 214 | u32 lun; |
| 215 | u8 cdb_length; |
| 216 | u8 cdb[32]; |
| 217 | u8 timeout; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 218 | u8 VF_ID; |
| 219 | u8 VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 220 | u8 valid_reply; |
| 221 | /* the following bits are only valid when 'valid_reply = 1' */ |
| 222 | u32 sense_length; |
| 223 | u16 ioc_status; |
| 224 | u8 scsi_state; |
| 225 | u8 scsi_status; |
| 226 | u32 log_info; |
| 227 | u32 transfer_length; |
| 228 | }; |
| 229 | |
| 230 | /* |
| 231 | * The pci device ids are defined in mpi/mpi2_cnfg.h. |
| 232 | */ |
| 233 | static struct pci_device_id scsih_pci_table[] = { |
| 234 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, |
| 235 | PCI_ANY_ID, PCI_ANY_ID }, |
| 236 | /* Falcon ~ 2008*/ |
| 237 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, |
| 238 | PCI_ANY_ID, PCI_ANY_ID }, |
| 239 | /* Liberator ~ 2108 */ |
| 240 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, |
| 241 | PCI_ANY_ID, PCI_ANY_ID }, |
| 242 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, |
| 243 | PCI_ANY_ID, PCI_ANY_ID }, |
| 244 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, |
| 245 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 246 | /* Meteor ~ 2116 */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 247 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, |
| 248 | PCI_ANY_ID, PCI_ANY_ID }, |
| 249 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, |
| 250 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 251 | /* Thunderbolt ~ 2208 */ |
| 252 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, |
| 253 | PCI_ANY_ID, PCI_ANY_ID }, |
| 254 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, |
| 255 | PCI_ANY_ID, PCI_ANY_ID }, |
| 256 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, |
| 257 | PCI_ANY_ID, PCI_ANY_ID }, |
| 258 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, |
| 259 | PCI_ANY_ID, PCI_ANY_ID }, |
| 260 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, |
| 261 | PCI_ANY_ID, PCI_ANY_ID }, |
| 262 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, |
| 263 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 203d65b | 2010-06-17 13:37:59 +0530 | [diff] [blame] | 264 | /* Mustang ~ 2308 */ |
| 265 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 266 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 203d65b | 2010-06-17 13:37:59 +0530 | [diff] [blame] | 267 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, |
| 268 | PCI_ANY_ID, PCI_ANY_ID }, |
| 269 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 270 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 271 | /* SSS6200 */ |
| 272 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, |
| 273 | PCI_ANY_ID, PCI_ANY_ID }, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 274 | {0} /* Terminating entry */ |
| 275 | }; |
| 276 | MODULE_DEVICE_TABLE(pci, scsih_pci_table); |
| 277 | |
| 278 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 279 | * _scsih_set_debug_level - global setting of ioc->logging_level. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 280 | * |
| 281 | * Note: The logging levels are defined in mpt2sas_debug.h. |
| 282 | */ |
| 283 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 284 | _scsih_set_debug_level(const char *val, struct kernel_param *kp) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 285 | { |
| 286 | int ret = param_set_int(val, kp); |
| 287 | struct MPT2SAS_ADAPTER *ioc; |
| 288 | |
| 289 | if (ret) |
| 290 | return ret; |
| 291 | |
| 292 | printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 293 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 294 | ioc->logging_level = logging_level; |
| 295 | return 0; |
| 296 | } |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 297 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 298 | &logging_level, 0644); |
| 299 | |
| 300 | /** |
| 301 | * _scsih_srch_boot_sas_address - search based on sas_address |
| 302 | * @sas_address: sas address |
| 303 | * @boot_device: boot device object from bios page 2 |
| 304 | * |
| 305 | * Returns 1 when there's a match, 0 means no match. |
| 306 | */ |
| 307 | static inline int |
| 308 | _scsih_srch_boot_sas_address(u64 sas_address, |
| 309 | Mpi2BootDeviceSasWwid_t *boot_device) |
| 310 | { |
| 311 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * _scsih_srch_boot_device_name - search based on device name |
| 316 | * @device_name: device name specified in INDENTIFY fram |
| 317 | * @boot_device: boot device object from bios page 2 |
| 318 | * |
| 319 | * Returns 1 when there's a match, 0 means no match. |
| 320 | */ |
| 321 | static inline int |
| 322 | _scsih_srch_boot_device_name(u64 device_name, |
| 323 | Mpi2BootDeviceDeviceName_t *boot_device) |
| 324 | { |
| 325 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot |
| 330 | * @enclosure_logical_id: enclosure logical id |
| 331 | * @slot_number: slot number |
| 332 | * @boot_device: boot device object from bios page 2 |
| 333 | * |
| 334 | * Returns 1 when there's a match, 0 means no match. |
| 335 | */ |
| 336 | static inline int |
| 337 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, |
| 338 | Mpi2BootDeviceEnclosureSlot_t *boot_device) |
| 339 | { |
| 340 | return (enclosure_logical_id == le64_to_cpu(boot_device-> |
| 341 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> |
| 342 | SlotNumber)) ? 1 : 0; |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * _scsih_is_boot_device - search for matching boot device. |
| 347 | * @sas_address: sas address |
| 348 | * @device_name: device name specified in INDENTIFY fram |
| 349 | * @enclosure_logical_id: enclosure logical id |
| 350 | * @slot_number: slot number |
| 351 | * @form: specifies boot device form |
| 352 | * @boot_device: boot device object from bios page 2 |
| 353 | * |
| 354 | * Returns 1 when there's a match, 0 means no match. |
| 355 | */ |
| 356 | static int |
| 357 | _scsih_is_boot_device(u64 sas_address, u64 device_name, |
| 358 | u64 enclosure_logical_id, u16 slot, u8 form, |
| 359 | Mpi2BiosPage2BootDevice_t *boot_device) |
| 360 | { |
| 361 | int rc = 0; |
| 362 | |
| 363 | switch (form) { |
| 364 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: |
| 365 | if (!sas_address) |
| 366 | break; |
| 367 | rc = _scsih_srch_boot_sas_address( |
| 368 | sas_address, &boot_device->SasWwid); |
| 369 | break; |
| 370 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: |
| 371 | if (!enclosure_logical_id) |
| 372 | break; |
| 373 | rc = _scsih_srch_boot_encl_slot( |
| 374 | enclosure_logical_id, |
| 375 | slot, &boot_device->EnclosureSlot); |
| 376 | break; |
| 377 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: |
| 378 | if (!device_name) |
| 379 | break; |
| 380 | rc = _scsih_srch_boot_device_name( |
| 381 | device_name, &boot_device->DeviceName); |
| 382 | break; |
| 383 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: |
| 384 | break; |
| 385 | } |
| 386 | |
| 387 | return rc; |
| 388 | } |
| 389 | |
| 390 | /** |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 391 | * _scsih_get_sas_address - set the sas_address for given device handle |
| 392 | * @handle: device handle |
| 393 | * @sas_address: sas address |
| 394 | * |
| 395 | * Returns 0 success, non-zero when failure |
| 396 | */ |
| 397 | static int |
| 398 | _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle, |
| 399 | u64 *sas_address) |
| 400 | { |
| 401 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 402 | Mpi2ConfigReply_t mpi_reply; |
| 403 | u32 ioc_status; |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 404 | *sas_address = 0; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 405 | |
| 406 | if (handle <= ioc->sas_hba.num_phys) { |
| 407 | *sas_address = ioc->sas_hba.sas_address; |
| 408 | return 0; |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 409 | } |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 410 | |
| 411 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 412 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 413 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 414 | __FILE__, __LINE__, __func__); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 415 | return -ENXIO; |
| 416 | } |
| 417 | |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 418 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 419 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { |
| 420 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 421 | return 0; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 422 | } |
| 423 | |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 424 | /* we hit this becuase the given parent handle doesn't exist */ |
| 425 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 426 | return -ENXIO; |
| 427 | /* else error case */ |
| 428 | printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), " |
| 429 | "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status, |
| 430 | __FILE__, __LINE__, __func__); |
| 431 | return -EIO; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 435 | * _scsih_determine_boot_device - determine boot device. |
| 436 | * @ioc: per adapter object |
| 437 | * @device: either sas_device or raid_device object |
| 438 | * @is_raid: [flag] 1 = raid object, 0 = sas object |
| 439 | * |
| 440 | * Determines whether this device should be first reported device to |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 441 | * 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] | 442 | * There are primary, alternate, and current entries in bios page 2. The order |
| 443 | * priority is primary, alternate, then current. This routine saves |
| 444 | * the corresponding device object and is_raid flag in the ioc object. |
| 445 | * The saved data to be used later in _scsih_probe_boot_devices(). |
| 446 | */ |
| 447 | static void |
| 448 | _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc, |
| 449 | void *device, u8 is_raid) |
| 450 | { |
| 451 | struct _sas_device *sas_device; |
| 452 | struct _raid_device *raid_device; |
| 453 | u64 sas_address; |
| 454 | u64 device_name; |
| 455 | u64 enclosure_logical_id; |
| 456 | u16 slot; |
| 457 | |
| 458 | /* only process this function when driver loads */ |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 459 | if (!ioc->is_driver_loading) |
| 460 | return; |
| 461 | |
| 462 | /* no Bios, return immediately */ |
| 463 | if (!ioc->bios_pg3.BiosVersion) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 464 | return; |
| 465 | |
| 466 | if (!is_raid) { |
| 467 | sas_device = device; |
| 468 | sas_address = sas_device->sas_address; |
| 469 | device_name = sas_device->device_name; |
| 470 | enclosure_logical_id = sas_device->enclosure_logical_id; |
| 471 | slot = sas_device->slot; |
| 472 | } else { |
| 473 | raid_device = device; |
| 474 | sas_address = raid_device->wwid; |
| 475 | device_name = 0; |
| 476 | enclosure_logical_id = 0; |
| 477 | slot = 0; |
| 478 | } |
| 479 | |
| 480 | if (!ioc->req_boot_device.device) { |
| 481 | if (_scsih_is_boot_device(sas_address, device_name, |
| 482 | enclosure_logical_id, slot, |
| 483 | (ioc->bios_pg2.ReqBootDeviceForm & |
| 484 | MPI2_BIOSPAGE2_FORM_MASK), |
| 485 | &ioc->bios_pg2.RequestedBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 486 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 487 | "%s: req_boot_device(0x%016llx)\n", |
| 488 | ioc->name, __func__, |
| 489 | (unsigned long long)sas_address)); |
| 490 | ioc->req_boot_device.device = device; |
| 491 | ioc->req_boot_device.is_raid = is_raid; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | if (!ioc->req_alt_boot_device.device) { |
| 496 | if (_scsih_is_boot_device(sas_address, device_name, |
| 497 | enclosure_logical_id, slot, |
| 498 | (ioc->bios_pg2.ReqAltBootDeviceForm & |
| 499 | MPI2_BIOSPAGE2_FORM_MASK), |
| 500 | &ioc->bios_pg2.RequestedAltBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 501 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 502 | "%s: req_alt_boot_device(0x%016llx)\n", |
| 503 | ioc->name, __func__, |
| 504 | (unsigned long long)sas_address)); |
| 505 | ioc->req_alt_boot_device.device = device; |
| 506 | ioc->req_alt_boot_device.is_raid = is_raid; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | if (!ioc->current_boot_device.device) { |
| 511 | if (_scsih_is_boot_device(sas_address, device_name, |
| 512 | enclosure_logical_id, slot, |
| 513 | (ioc->bios_pg2.CurrentBootDeviceForm & |
| 514 | MPI2_BIOSPAGE2_FORM_MASK), |
| 515 | &ioc->bios_pg2.CurrentBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 516 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 517 | "%s: current_boot_device(0x%016llx)\n", |
| 518 | ioc->name, __func__, |
| 519 | (unsigned long long)sas_address)); |
| 520 | ioc->current_boot_device.device = device; |
| 521 | ioc->current_boot_device.is_raid = is_raid; |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search |
| 528 | * @ioc: per adapter object |
| 529 | * @sas_address: sas address |
| 530 | * Context: Calling function should acquire ioc->sas_device_lock |
| 531 | * |
| 532 | * This searches for sas_device based on sas_address, then return sas_device |
| 533 | * object. |
| 534 | */ |
| 535 | struct _sas_device * |
| 536 | mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 537 | u64 sas_address) |
| 538 | { |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 539 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 540 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 541 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) |
| 542 | if (sas_device->sas_address == sas_address) |
| 543 | return sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 544 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 545 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) |
| 546 | if (sas_device->sas_address == sas_address) |
| 547 | return sas_device; |
| 548 | |
| 549 | return NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | /** |
| 553 | * _scsih_sas_device_find_by_handle - sas device search |
| 554 | * @ioc: per adapter object |
| 555 | * @handle: sas device handle (assigned by firmware) |
| 556 | * Context: Calling function should acquire ioc->sas_device_lock |
| 557 | * |
| 558 | * This searches for sas_device based on sas_address, then return sas_device |
| 559 | * object. |
| 560 | */ |
| 561 | static struct _sas_device * |
| 562 | _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 563 | { |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 564 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 565 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 566 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) |
| 567 | if (sas_device->handle == handle) |
| 568 | return sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 569 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 570 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) |
| 571 | if (sas_device->handle == handle) |
| 572 | return sas_device; |
| 573 | |
| 574 | return NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /** |
| 578 | * _scsih_sas_device_remove - remove sas_device from list. |
| 579 | * @ioc: per adapter object |
| 580 | * @sas_device: the sas_device object |
| 581 | * Context: This function will acquire ioc->sas_device_lock. |
| 582 | * |
| 583 | * Removing object and freeing associated memory from the ioc->sas_device_list. |
| 584 | */ |
| 585 | static void |
| 586 | _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc, |
| 587 | struct _sas_device *sas_device) |
| 588 | { |
| 589 | unsigned long flags; |
| 590 | |
Kashyap, Desai | 980ead3 | 2010-04-08 17:55:22 +0530 | [diff] [blame] | 591 | if (!sas_device) |
| 592 | return; |
| 593 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 594 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 595 | list_del(&sas_device->list); |
| 596 | kfree(sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 597 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 598 | } |
| 599 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 600 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 601 | /** |
| 602 | * _scsih_sas_device_add - insert sas_device to the list. |
| 603 | * @ioc: per adapter object |
| 604 | * @sas_device: the sas_device object |
| 605 | * Context: This function will acquire ioc->sas_device_lock. |
| 606 | * |
| 607 | * Adding new object to the ioc->sas_device_list. |
| 608 | */ |
| 609 | static void |
| 610 | _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc, |
| 611 | struct _sas_device *sas_device) |
| 612 | { |
| 613 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 614 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 615 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 616 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 617 | sas_device->handle, (unsigned long long)sas_device->sas_address)); |
| 618 | |
| 619 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 620 | list_add_tail(&sas_device->list, &ioc->sas_device_list); |
| 621 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 622 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 623 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 624 | sas_device->sas_address_parent)) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 625 | _scsih_sas_device_remove(ioc, sas_device); |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 626 | } else if (!sas_device->starget) { |
| 627 | /* When asyn scanning is enabled, its not possible to remove |
| 628 | * devices while scanning is turned on due to an oops in |
| 629 | * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start() |
| 630 | */ |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 631 | if (!ioc->is_driver_loading) { |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 632 | mpt2sas_transport_port_remove(ioc, |
| 633 | sas_device->sas_address, |
| 634 | sas_device->sas_address_parent); |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 635 | _scsih_sas_device_remove(ioc, sas_device); |
| 636 | } |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 637 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /** |
| 641 | * _scsih_sas_device_init_add - insert sas_device to the list. |
| 642 | * @ioc: per adapter object |
| 643 | * @sas_device: the sas_device object |
| 644 | * Context: This function will acquire ioc->sas_device_lock. |
| 645 | * |
| 646 | * Adding new object at driver load time to the ioc->sas_device_init_list. |
| 647 | */ |
| 648 | static void |
| 649 | _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc, |
| 650 | struct _sas_device *sas_device) |
| 651 | { |
| 652 | unsigned long flags; |
| 653 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 654 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 655 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 656 | sas_device->handle, (unsigned long long)sas_device->sas_address)); |
| 657 | |
| 658 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 659 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 660 | _scsih_determine_boot_device(ioc, sas_device, 0); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 661 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 665 | * _scsih_raid_device_find_by_id - raid device search |
| 666 | * @ioc: per adapter object |
| 667 | * @id: sas device target id |
| 668 | * @channel: sas device channel |
| 669 | * Context: Calling function should acquire ioc->raid_device_lock |
| 670 | * |
| 671 | * This searches for raid_device based on target id, then return raid_device |
| 672 | * object. |
| 673 | */ |
| 674 | static struct _raid_device * |
| 675 | _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel) |
| 676 | { |
| 677 | struct _raid_device *raid_device, *r; |
| 678 | |
| 679 | r = NULL; |
| 680 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 681 | if (raid_device->id == id && raid_device->channel == channel) { |
| 682 | r = raid_device; |
| 683 | goto out; |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | out: |
| 688 | return r; |
| 689 | } |
| 690 | |
| 691 | /** |
| 692 | * _scsih_raid_device_find_by_handle - raid device search |
| 693 | * @ioc: per adapter object |
| 694 | * @handle: sas device handle (assigned by firmware) |
| 695 | * Context: Calling function should acquire ioc->raid_device_lock |
| 696 | * |
| 697 | * This searches for raid_device based on handle, then return raid_device |
| 698 | * object. |
| 699 | */ |
| 700 | static struct _raid_device * |
| 701 | _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 702 | { |
| 703 | struct _raid_device *raid_device, *r; |
| 704 | |
| 705 | r = NULL; |
| 706 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 707 | if (raid_device->handle != handle) |
| 708 | continue; |
| 709 | r = raid_device; |
| 710 | goto out; |
| 711 | } |
| 712 | |
| 713 | out: |
| 714 | return r; |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * _scsih_raid_device_find_by_wwid - raid device search |
| 719 | * @ioc: per adapter object |
| 720 | * @handle: sas device handle (assigned by firmware) |
| 721 | * Context: Calling function should acquire ioc->raid_device_lock |
| 722 | * |
| 723 | * This searches for raid_device based on wwid, then return raid_device |
| 724 | * object. |
| 725 | */ |
| 726 | static struct _raid_device * |
| 727 | _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid) |
| 728 | { |
| 729 | struct _raid_device *raid_device, *r; |
| 730 | |
| 731 | r = NULL; |
| 732 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 733 | if (raid_device->wwid != wwid) |
| 734 | continue; |
| 735 | r = raid_device; |
| 736 | goto out; |
| 737 | } |
| 738 | |
| 739 | out: |
| 740 | return r; |
| 741 | } |
| 742 | |
| 743 | /** |
| 744 | * _scsih_raid_device_add - add raid_device object |
| 745 | * @ioc: per adapter object |
| 746 | * @raid_device: raid_device object |
| 747 | * |
| 748 | * This is added to the raid_device_list link list. |
| 749 | */ |
| 750 | static void |
| 751 | _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc, |
| 752 | struct _raid_device *raid_device) |
| 753 | { |
| 754 | unsigned long flags; |
| 755 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 756 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 757 | "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, |
| 758 | raid_device->handle, (unsigned long long)raid_device->wwid)); |
| 759 | |
| 760 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 761 | list_add_tail(&raid_device->list, &ioc->raid_device_list); |
| 762 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 763 | } |
| 764 | |
| 765 | /** |
| 766 | * _scsih_raid_device_remove - delete raid_device object |
| 767 | * @ioc: per adapter object |
| 768 | * @raid_device: raid_device object |
| 769 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 770 | */ |
| 771 | static void |
| 772 | _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc, |
| 773 | struct _raid_device *raid_device) |
| 774 | { |
| 775 | unsigned long flags; |
| 776 | |
| 777 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 778 | list_del(&raid_device->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 779 | kfree(raid_device); |
| 780 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 781 | } |
| 782 | |
| 783 | /** |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 784 | * mpt2sas_scsih_expander_find_by_handle - expander device search |
| 785 | * @ioc: per adapter object |
| 786 | * @handle: expander handle (assigned by firmware) |
| 787 | * Context: Calling function should acquire ioc->sas_device_lock |
| 788 | * |
| 789 | * This searches for expander device based on handle, then returns the |
| 790 | * sas_node object. |
| 791 | */ |
| 792 | struct _sas_node * |
| 793 | mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 794 | { |
| 795 | struct _sas_node *sas_expander, *r; |
| 796 | |
| 797 | r = NULL; |
| 798 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 799 | if (sas_expander->handle != handle) |
| 800 | continue; |
| 801 | r = sas_expander; |
| 802 | goto out; |
| 803 | } |
| 804 | out: |
| 805 | return r; |
| 806 | } |
| 807 | |
| 808 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 809 | * mpt2sas_scsih_expander_find_by_sas_address - expander device search |
| 810 | * @ioc: per adapter object |
| 811 | * @sas_address: sas address |
| 812 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 813 | * |
| 814 | * This searches for expander device based on sas_address, then returns the |
| 815 | * sas_node object. |
| 816 | */ |
| 817 | struct _sas_node * |
| 818 | mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 819 | u64 sas_address) |
| 820 | { |
| 821 | struct _sas_node *sas_expander, *r; |
| 822 | |
| 823 | r = NULL; |
| 824 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 825 | if (sas_expander->sas_address != sas_address) |
| 826 | continue; |
| 827 | r = sas_expander; |
| 828 | goto out; |
| 829 | } |
| 830 | out: |
| 831 | return r; |
| 832 | } |
| 833 | |
| 834 | /** |
| 835 | * _scsih_expander_node_add - insert expander device to the list. |
| 836 | * @ioc: per adapter object |
| 837 | * @sas_expander: the sas_device object |
| 838 | * Context: This function will acquire ioc->sas_node_lock. |
| 839 | * |
| 840 | * Adding new object to the ioc->sas_expander_list. |
| 841 | * |
| 842 | * Return nothing. |
| 843 | */ |
| 844 | static void |
| 845 | _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc, |
| 846 | struct _sas_node *sas_expander) |
| 847 | { |
| 848 | unsigned long flags; |
| 849 | |
| 850 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 851 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); |
| 852 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 853 | } |
| 854 | |
| 855 | /** |
| 856 | * _scsih_is_end_device - determines if device is an end device |
| 857 | * @device_info: bitfield providing information about the device. |
| 858 | * Context: none |
| 859 | * |
| 860 | * Returns 1 if end device. |
| 861 | */ |
| 862 | static int |
| 863 | _scsih_is_end_device(u32 device_info) |
| 864 | { |
| 865 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && |
| 866 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | |
| 867 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
| 868 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) |
| 869 | return 1; |
| 870 | else |
| 871 | return 0; |
| 872 | } |
| 873 | |
| 874 | /** |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 875 | * _scsih_scsi_lookup_get - returns scmd entry |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 876 | * @ioc: per adapter object |
| 877 | * @smid: system request message index |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 878 | * |
| 879 | * Returns the smid stored scmd pointer. |
| 880 | */ |
| 881 | static struct scsi_cmnd * |
| 882 | _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 883 | { |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 884 | return ioc->scsi_lookup[smid - 1].scmd; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | /** |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 888 | * _scsih_scsi_lookup_get_clear - returns scmd entry |
| 889 | * @ioc: per adapter object |
| 890 | * @smid: system request message index |
| 891 | * |
| 892 | * Returns the smid stored scmd pointer. |
| 893 | * Then will derefrence the stored scmd pointer. |
| 894 | */ |
| 895 | static inline struct scsi_cmnd * |
| 896 | _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 897 | { |
| 898 | unsigned long flags; |
| 899 | struct scsi_cmnd *scmd; |
| 900 | |
| 901 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 902 | scmd = ioc->scsi_lookup[smid - 1].scmd; |
| 903 | ioc->scsi_lookup[smid - 1].scmd = NULL; |
| 904 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 905 | |
| 906 | return scmd; |
| 907 | } |
| 908 | |
| 909 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 910 | * _scsih_scsi_lookup_find_by_scmd - scmd lookup |
| 911 | * @ioc: per adapter object |
| 912 | * @smid: system request message index |
| 913 | * @scmd: pointer to scsi command object |
| 914 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 915 | * |
| 916 | * This will search for a scmd pointer in the scsi_lookup array, |
| 917 | * returning the revelent smid. A returned value of zero means invalid. |
| 918 | */ |
| 919 | static u16 |
| 920 | _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd |
| 921 | *scmd) |
| 922 | { |
| 923 | u16 smid; |
| 924 | unsigned long flags; |
| 925 | int i; |
| 926 | |
| 927 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 928 | smid = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 929 | for (i = 0; i < ioc->scsiio_depth; i++) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 930 | if (ioc->scsi_lookup[i].scmd == scmd) { |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 931 | smid = ioc->scsi_lookup[i].smid; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 932 | goto out; |
| 933 | } |
| 934 | } |
| 935 | out: |
| 936 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 937 | return smid; |
| 938 | } |
| 939 | |
| 940 | /** |
| 941 | * _scsih_scsi_lookup_find_by_target - search for matching channel:id |
| 942 | * @ioc: per adapter object |
| 943 | * @id: target id |
| 944 | * @channel: channel |
| 945 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 946 | * |
| 947 | * This will search for a matching channel:id in the scsi_lookup array, |
| 948 | * returning 1 if found. |
| 949 | */ |
| 950 | static u8 |
| 951 | _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id, |
| 952 | int channel) |
| 953 | { |
| 954 | u8 found; |
| 955 | unsigned long flags; |
| 956 | int i; |
| 957 | |
| 958 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 959 | found = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 960 | for (i = 0 ; i < ioc->scsiio_depth; i++) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 961 | if (ioc->scsi_lookup[i].scmd && |
| 962 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 963 | ioc->scsi_lookup[i].scmd->device->channel == channel)) { |
| 964 | found = 1; |
| 965 | goto out; |
| 966 | } |
| 967 | } |
| 968 | out: |
| 969 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 970 | return found; |
| 971 | } |
| 972 | |
| 973 | /** |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 974 | * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun |
| 975 | * @ioc: per adapter object |
| 976 | * @id: target id |
| 977 | * @lun: lun number |
| 978 | * @channel: channel |
| 979 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 980 | * |
| 981 | * This will search for a matching channel:id:lun in the scsi_lookup array, |
| 982 | * returning 1 if found. |
| 983 | */ |
| 984 | static u8 |
| 985 | _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id, |
| 986 | unsigned int lun, int channel) |
| 987 | { |
| 988 | u8 found; |
| 989 | unsigned long flags; |
| 990 | int i; |
| 991 | |
| 992 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 993 | found = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 994 | for (i = 0 ; i < ioc->scsiio_depth; i++) { |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 995 | if (ioc->scsi_lookup[i].scmd && |
| 996 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 997 | ioc->scsi_lookup[i].scmd->device->channel == channel && |
| 998 | ioc->scsi_lookup[i].scmd->device->lun == lun)) { |
| 999 | found = 1; |
| 1000 | goto out; |
| 1001 | } |
| 1002 | } |
| 1003 | out: |
| 1004 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1005 | return found; |
| 1006 | } |
| 1007 | |
| 1008 | /** |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1009 | * _scsih_get_chain_buffer_tracker - obtain chain tracker |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1010 | * @ioc: per adapter object |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1011 | * @smid: smid associated to an IO request |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1012 | * |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1013 | * Returns chain tracker(from ioc->free_chain_list) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1014 | */ |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1015 | static struct chain_tracker * |
| 1016 | _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1017 | { |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1018 | struct chain_tracker *chain_req; |
| 1019 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1020 | |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1021 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 1022 | if (list_empty(&ioc->free_chain_list)) { |
| 1023 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
nagalakshmi.nandigama@lsi.com | aff132d | 2011-12-01 07:53:08 +0530 | [diff] [blame] | 1024 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not " |
| 1025 | "available\n", ioc->name)); |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1026 | return NULL; |
| 1027 | } |
| 1028 | chain_req = list_entry(ioc->free_chain_list.next, |
| 1029 | struct chain_tracker, tracker_list); |
| 1030 | list_del_init(&chain_req->tracker_list); |
| 1031 | list_add_tail(&chain_req->tracker_list, |
| 1032 | &ioc->scsi_lookup[smid - 1].chain_list); |
| 1033 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1034 | return chain_req; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | /** |
| 1038 | * _scsih_build_scatter_gather - main sg creation routine |
| 1039 | * @ioc: per adapter object |
| 1040 | * @scmd: scsi command |
| 1041 | * @smid: system request message index |
| 1042 | * Context: none. |
| 1043 | * |
| 1044 | * The main routine that builds scatter gather table from a given |
| 1045 | * scsi request sent via the .queuecommand main handler. |
| 1046 | * |
| 1047 | * Returns 0 success, anything else error |
| 1048 | */ |
| 1049 | static int |
| 1050 | _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc, |
| 1051 | struct scsi_cmnd *scmd, u16 smid) |
| 1052 | { |
| 1053 | Mpi2SCSIIORequest_t *mpi_request; |
| 1054 | dma_addr_t chain_dma; |
| 1055 | struct scatterlist *sg_scmd; |
| 1056 | void *sg_local, *chain; |
| 1057 | u32 chain_offset; |
| 1058 | u32 chain_length; |
| 1059 | u32 chain_flags; |
FUJITA Tomonori | bb789d0 | 2010-03-09 11:09:50 +0900 | [diff] [blame] | 1060 | int sges_left; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1061 | u32 sges_in_segment; |
| 1062 | u32 sgl_flags; |
| 1063 | u32 sgl_flags_last_element; |
| 1064 | u32 sgl_flags_end_buffer; |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1065 | struct chain_tracker *chain_req; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1066 | |
| 1067 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 1068 | |
| 1069 | /* init scatter gather flags */ |
| 1070 | sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT; |
| 1071 | if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 1072 | sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC; |
| 1073 | sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT) |
| 1074 | << MPI2_SGE_FLAGS_SHIFT; |
| 1075 | sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT | |
| 1076 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST) |
| 1077 | << MPI2_SGE_FLAGS_SHIFT; |
| 1078 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1079 | |
| 1080 | sg_scmd = scsi_sglist(scmd); |
| 1081 | sges_left = scsi_dma_map(scmd); |
FUJITA Tomonori | bb789d0 | 2010-03-09 11:09:50 +0900 | [diff] [blame] | 1082 | if (sges_left < 0) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1083 | sdev_printk(KERN_ERR, scmd->device, "pci_map_sg" |
| 1084 | " failed: request for %d bytes!\n", scsi_bufflen(scmd)); |
| 1085 | return -ENOMEM; |
| 1086 | } |
| 1087 | |
| 1088 | sg_local = &mpi_request->SGL; |
| 1089 | sges_in_segment = ioc->max_sges_in_main_message; |
| 1090 | if (sges_left <= sges_in_segment) |
| 1091 | goto fill_in_last_segment; |
| 1092 | |
| 1093 | mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) + |
| 1094 | (sges_in_segment * ioc->sge_size))/4; |
| 1095 | |
| 1096 | /* fill in main message segment when there is a chain following */ |
| 1097 | while (sges_in_segment) { |
| 1098 | if (sges_in_segment == 1) |
| 1099 | ioc->base_add_sg_single(sg_local, |
| 1100 | sgl_flags_last_element | sg_dma_len(sg_scmd), |
| 1101 | sg_dma_address(sg_scmd)); |
| 1102 | else |
| 1103 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1104 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1105 | sg_scmd = sg_next(sg_scmd); |
| 1106 | sg_local += ioc->sge_size; |
| 1107 | sges_left--; |
| 1108 | sges_in_segment--; |
| 1109 | } |
| 1110 | |
| 1111 | /* initializing the chain flags and pointers */ |
| 1112 | chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT; |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1113 | chain_req = _scsih_get_chain_buffer_tracker(ioc, smid); |
| 1114 | if (!chain_req) |
| 1115 | return -1; |
| 1116 | chain = chain_req->chain_buffer; |
| 1117 | chain_dma = chain_req->chain_buffer_dma; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1118 | do { |
| 1119 | sges_in_segment = (sges_left <= |
| 1120 | ioc->max_sges_in_chain_message) ? sges_left : |
| 1121 | ioc->max_sges_in_chain_message; |
| 1122 | chain_offset = (sges_left == sges_in_segment) ? |
| 1123 | 0 : (sges_in_segment * ioc->sge_size)/4; |
| 1124 | chain_length = sges_in_segment * ioc->sge_size; |
| 1125 | if (chain_offset) { |
| 1126 | chain_offset = chain_offset << |
| 1127 | MPI2_SGE_CHAIN_OFFSET_SHIFT; |
| 1128 | chain_length += ioc->sge_size; |
| 1129 | } |
| 1130 | ioc->base_add_sg_single(sg_local, chain_flags | chain_offset | |
| 1131 | chain_length, chain_dma); |
| 1132 | sg_local = chain; |
| 1133 | if (!chain_offset) |
| 1134 | goto fill_in_last_segment; |
| 1135 | |
| 1136 | /* fill in chain segments */ |
| 1137 | while (sges_in_segment) { |
| 1138 | if (sges_in_segment == 1) |
| 1139 | ioc->base_add_sg_single(sg_local, |
| 1140 | sgl_flags_last_element | |
| 1141 | sg_dma_len(sg_scmd), |
| 1142 | sg_dma_address(sg_scmd)); |
| 1143 | else |
| 1144 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1145 | sg_dma_len(sg_scmd), |
| 1146 | sg_dma_address(sg_scmd)); |
| 1147 | sg_scmd = sg_next(sg_scmd); |
| 1148 | sg_local += ioc->sge_size; |
| 1149 | sges_left--; |
| 1150 | sges_in_segment--; |
| 1151 | } |
| 1152 | |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1153 | chain_req = _scsih_get_chain_buffer_tracker(ioc, smid); |
| 1154 | if (!chain_req) |
| 1155 | return -1; |
| 1156 | chain = chain_req->chain_buffer; |
| 1157 | chain_dma = chain_req->chain_buffer_dma; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1158 | } while (1); |
| 1159 | |
| 1160 | |
| 1161 | fill_in_last_segment: |
| 1162 | |
| 1163 | /* fill the last segment */ |
| 1164 | while (sges_left) { |
| 1165 | if (sges_left == 1) |
| 1166 | ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer | |
| 1167 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1168 | else |
| 1169 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1170 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1171 | sg_scmd = sg_next(sg_scmd); |
| 1172 | sg_local += ioc->sge_size; |
| 1173 | sges_left--; |
| 1174 | } |
| 1175 | |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
| 1179 | /** |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1180 | * _scsih_adjust_queue_depth - setting device queue depth |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1181 | * @sdev: scsi device struct |
| 1182 | * @qdepth: requested queue depth |
| 1183 | * |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1184 | * |
| 1185 | * Returns nothing |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1186 | */ |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1187 | static void |
| 1188 | _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1189 | { |
| 1190 | struct Scsi_Host *shost = sdev->host; |
| 1191 | int max_depth; |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1192 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1193 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1194 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1195 | struct _sas_device *sas_device; |
| 1196 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1197 | |
| 1198 | max_depth = shost->can_queue; |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1199 | |
| 1200 | /* limit max device queue for SATA to 32 */ |
| 1201 | sas_device_priv_data = sdev->hostdata; |
| 1202 | if (!sas_device_priv_data) |
| 1203 | goto not_sata; |
| 1204 | sas_target_priv_data = sas_device_priv_data->sas_target; |
| 1205 | if (!sas_target_priv_data) |
| 1206 | goto not_sata; |
| 1207 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) |
| 1208 | goto not_sata; |
| 1209 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1210 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1211 | sas_device_priv_data->sas_target->sas_address); |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1212 | if (sas_device && sas_device->device_info & |
| 1213 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1214 | max_depth = MPT2SAS_SATA_QUEUE_DEPTH; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1215 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1216 | |
| 1217 | not_sata: |
| 1218 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1219 | if (!sdev->tagged_supported) |
| 1220 | max_depth = 1; |
| 1221 | if (qdepth > max_depth) |
| 1222 | qdepth = max_depth; |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1223 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); |
| 1224 | } |
| 1225 | |
| 1226 | /** |
| 1227 | * _scsih_change_queue_depth - setting device queue depth |
| 1228 | * @sdev: scsi device struct |
| 1229 | * @qdepth: requested queue depth |
| 1230 | * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP |
| 1231 | * (see include/scsi/scsi_host.h for definition) |
| 1232 | * |
| 1233 | * Returns queue depth. |
| 1234 | */ |
| 1235 | static int |
| 1236 | _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) |
| 1237 | { |
| 1238 | if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP) |
| 1239 | _scsih_adjust_queue_depth(sdev, qdepth); |
| 1240 | else if (reason == SCSI_QDEPTH_QFULL) |
| 1241 | scsi_track_queue_full(sdev, qdepth); |
| 1242 | else |
| 1243 | return -EOPNOTSUPP; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1244 | |
| 1245 | if (sdev->inquiry_len > 7) |
| 1246 | sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " |
| 1247 | "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n", |
| 1248 | sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags, |
| 1249 | sdev->ordered_tags, sdev->scsi_level, |
| 1250 | (sdev->inquiry[7] & 2) >> 1); |
| 1251 | |
| 1252 | return sdev->queue_depth; |
| 1253 | } |
| 1254 | |
| 1255 | /** |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 1256 | * _scsih_change_queue_type - changing device queue tag type |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1257 | * @sdev: scsi device struct |
| 1258 | * @tag_type: requested tag type |
| 1259 | * |
| 1260 | * Returns queue tag type. |
| 1261 | */ |
| 1262 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1263 | _scsih_change_queue_type(struct scsi_device *sdev, int tag_type) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1264 | { |
| 1265 | if (sdev->tagged_supported) { |
| 1266 | scsi_set_tag_type(sdev, tag_type); |
| 1267 | if (tag_type) |
| 1268 | scsi_activate_tcq(sdev, sdev->queue_depth); |
| 1269 | else |
| 1270 | scsi_deactivate_tcq(sdev, sdev->queue_depth); |
| 1271 | } else |
| 1272 | tag_type = 0; |
| 1273 | |
| 1274 | return tag_type; |
| 1275 | } |
| 1276 | |
| 1277 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1278 | * _scsih_target_alloc - target add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1279 | * @starget: scsi target struct |
| 1280 | * |
| 1281 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1282 | * the device is ignored. |
| 1283 | */ |
| 1284 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1285 | _scsih_target_alloc(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1286 | { |
| 1287 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1288 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1289 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1290 | struct _sas_device *sas_device; |
| 1291 | struct _raid_device *raid_device; |
| 1292 | unsigned long flags; |
| 1293 | struct sas_rphy *rphy; |
| 1294 | |
| 1295 | sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL); |
| 1296 | if (!sas_target_priv_data) |
| 1297 | return -ENOMEM; |
| 1298 | |
| 1299 | starget->hostdata = sas_target_priv_data; |
| 1300 | sas_target_priv_data->starget = starget; |
| 1301 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; |
| 1302 | |
| 1303 | /* RAID volumes */ |
| 1304 | if (starget->channel == RAID_CHANNEL) { |
| 1305 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1306 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1307 | starget->channel); |
| 1308 | if (raid_device) { |
| 1309 | sas_target_priv_data->handle = raid_device->handle; |
| 1310 | sas_target_priv_data->sas_address = raid_device->wwid; |
| 1311 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1312 | if (ioc->is_warpdrive) |
| 1313 | sas_target_priv_data->raid_device = raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1314 | raid_device->starget = starget; |
| 1315 | } |
| 1316 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1317 | return 0; |
| 1318 | } |
| 1319 | |
| 1320 | /* sas/sata devices */ |
| 1321 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1322 | rphy = dev_to_rphy(starget->dev.parent); |
| 1323 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1324 | rphy->identify.sas_address); |
| 1325 | |
| 1326 | if (sas_device) { |
| 1327 | sas_target_priv_data->handle = sas_device->handle; |
| 1328 | sas_target_priv_data->sas_address = sas_device->sas_address; |
| 1329 | sas_device->starget = starget; |
| 1330 | sas_device->id = starget->id; |
| 1331 | sas_device->channel = starget->channel; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 1332 | if (test_bit(sas_device->handle, ioc->pd_handles)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1333 | sas_target_priv_data->flags |= |
| 1334 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 1335 | } |
| 1336 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1337 | |
| 1338 | return 0; |
| 1339 | } |
| 1340 | |
| 1341 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1342 | * _scsih_target_destroy - target destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1343 | * @starget: scsi target struct |
| 1344 | * |
| 1345 | * Returns nothing. |
| 1346 | */ |
| 1347 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1348 | _scsih_target_destroy(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1349 | { |
| 1350 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1351 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1352 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1353 | struct _sas_device *sas_device; |
| 1354 | struct _raid_device *raid_device; |
| 1355 | unsigned long flags; |
| 1356 | struct sas_rphy *rphy; |
| 1357 | |
| 1358 | sas_target_priv_data = starget->hostdata; |
| 1359 | if (!sas_target_priv_data) |
| 1360 | return; |
| 1361 | |
| 1362 | if (starget->channel == RAID_CHANNEL) { |
| 1363 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1364 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1365 | starget->channel); |
| 1366 | if (raid_device) { |
| 1367 | raid_device->starget = NULL; |
| 1368 | raid_device->sdev = NULL; |
| 1369 | } |
| 1370 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1371 | goto out; |
| 1372 | } |
| 1373 | |
| 1374 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1375 | rphy = dev_to_rphy(starget->dev.parent); |
| 1376 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1377 | rphy->identify.sas_address); |
Eric Moore | 8901cbb | 2009-04-21 15:41:32 -0600 | [diff] [blame] | 1378 | if (sas_device && (sas_device->starget == starget) && |
| 1379 | (sas_device->id == starget->id) && |
| 1380 | (sas_device->channel == starget->channel)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1381 | sas_device->starget = NULL; |
| 1382 | |
| 1383 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1384 | |
| 1385 | out: |
| 1386 | kfree(sas_target_priv_data); |
| 1387 | starget->hostdata = NULL; |
| 1388 | } |
| 1389 | |
| 1390 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1391 | * _scsih_slave_alloc - device add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1392 | * @sdev: scsi device struct |
| 1393 | * |
| 1394 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1395 | * the device is ignored. |
| 1396 | */ |
| 1397 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1398 | _scsih_slave_alloc(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1399 | { |
| 1400 | struct Scsi_Host *shost; |
| 1401 | struct MPT2SAS_ADAPTER *ioc; |
| 1402 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1403 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1404 | struct scsi_target *starget; |
| 1405 | struct _raid_device *raid_device; |
Sreekanth Reddy | 63e359d | 2013-07-25 11:32:51 +0530 | [diff] [blame] | 1406 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1407 | unsigned long flags; |
| 1408 | |
| 1409 | sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL); |
| 1410 | if (!sas_device_priv_data) |
| 1411 | return -ENOMEM; |
| 1412 | |
| 1413 | sas_device_priv_data->lun = sdev->lun; |
| 1414 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; |
| 1415 | |
| 1416 | starget = scsi_target(sdev); |
| 1417 | sas_target_priv_data = starget->hostdata; |
| 1418 | sas_target_priv_data->num_luns++; |
| 1419 | sas_device_priv_data->sas_target = sas_target_priv_data; |
| 1420 | sdev->hostdata = sas_device_priv_data; |
| 1421 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) |
| 1422 | sdev->no_uld_attach = 1; |
| 1423 | |
| 1424 | shost = dev_to_shost(&starget->dev); |
| 1425 | ioc = shost_priv(shost); |
| 1426 | if (starget->channel == RAID_CHANNEL) { |
| 1427 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1428 | raid_device = _scsih_raid_device_find_by_id(ioc, |
| 1429 | starget->id, starget->channel); |
| 1430 | if (raid_device) |
| 1431 | raid_device->sdev = sdev; /* raid is single lun */ |
| 1432 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1433 | } |
| 1434 | |
Sreekanth Reddy | 63e359d | 2013-07-25 11:32:51 +0530 | [diff] [blame] | 1435 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
| 1436 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1437 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1438 | sas_target_priv_data->sas_address); |
| 1439 | if (sas_device && (sas_device->starget == NULL)) { |
| 1440 | sdev_printk(KERN_INFO, sdev, |
| 1441 | "%s : sas_device->starget set to starget @ %d\n", |
| 1442 | __func__, __LINE__); |
| 1443 | sas_device->starget = starget; |
| 1444 | } |
| 1445 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1446 | } |
| 1447 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1448 | return 0; |
| 1449 | } |
| 1450 | |
| 1451 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1452 | * _scsih_slave_destroy - device destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1453 | * @sdev: scsi device struct |
| 1454 | * |
| 1455 | * Returns nothing. |
| 1456 | */ |
| 1457 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1458 | _scsih_slave_destroy(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1459 | { |
| 1460 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1461 | struct scsi_target *starget; |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1462 | struct Scsi_Host *shost; |
| 1463 | struct MPT2SAS_ADAPTER *ioc; |
| 1464 | struct _sas_device *sas_device; |
| 1465 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1466 | |
| 1467 | if (!sdev->hostdata) |
| 1468 | return; |
| 1469 | |
| 1470 | starget = scsi_target(sdev); |
| 1471 | sas_target_priv_data = starget->hostdata; |
| 1472 | sas_target_priv_data->num_luns--; |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1473 | |
| 1474 | shost = dev_to_shost(&starget->dev); |
| 1475 | ioc = shost_priv(shost); |
| 1476 | |
| 1477 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
| 1478 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1479 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1480 | sas_target_priv_data->sas_address); |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 1481 | if (sas_device && !sas_target_priv_data->num_luns) |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1482 | sas_device->starget = NULL; |
| 1483 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1484 | } |
| 1485 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1486 | kfree(sdev->hostdata); |
| 1487 | sdev->hostdata = NULL; |
| 1488 | } |
| 1489 | |
| 1490 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1491 | * _scsih_display_sata_capabilities - sata capabilities |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1492 | * @ioc: per adapter object |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1493 | * @handle: device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1494 | * @sdev: scsi device struct |
| 1495 | */ |
| 1496 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1497 | _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1498 | u16 handle, struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1499 | { |
| 1500 | Mpi2ConfigReply_t mpi_reply; |
| 1501 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1502 | u32 ioc_status; |
| 1503 | u16 flags; |
| 1504 | u32 device_info; |
| 1505 | |
| 1506 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1507 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1508 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1509 | ioc->name, __FILE__, __LINE__, __func__); |
| 1510 | return; |
| 1511 | } |
| 1512 | |
| 1513 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1514 | MPI2_IOCSTATUS_MASK; |
| 1515 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 1516 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1517 | ioc->name, __FILE__, __LINE__, __func__); |
| 1518 | return; |
| 1519 | } |
| 1520 | |
| 1521 | flags = le16_to_cpu(sas_device_pg0.Flags); |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 1522 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1523 | |
| 1524 | sdev_printk(KERN_INFO, sdev, |
| 1525 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " |
| 1526 | "sw_preserve(%s)\n", |
| 1527 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", |
| 1528 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", |
| 1529 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : |
| 1530 | "n", |
| 1531 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", |
| 1532 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", |
| 1533 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); |
| 1534 | } |
| 1535 | |
| 1536 | /** |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1537 | * _scsih_is_raid - return boolean indicating device is raid volume |
| 1538 | * @dev the device struct object |
| 1539 | */ |
| 1540 | static int |
| 1541 | _scsih_is_raid(struct device *dev) |
| 1542 | { |
| 1543 | struct scsi_device *sdev = to_scsi_device(dev); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1544 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1545 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1546 | if (ioc->is_warpdrive) |
| 1547 | return 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1548 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
| 1549 | } |
| 1550 | |
| 1551 | /** |
| 1552 | * _scsih_get_resync - get raid volume resync percent complete |
| 1553 | * @dev the device struct object |
| 1554 | */ |
| 1555 | static void |
| 1556 | _scsih_get_resync(struct device *dev) |
| 1557 | { |
| 1558 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1559 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1560 | static struct _raid_device *raid_device; |
| 1561 | unsigned long flags; |
| 1562 | Mpi2RaidVolPage0_t vol_pg0; |
| 1563 | Mpi2ConfigReply_t mpi_reply; |
| 1564 | u32 volume_status_flags; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1565 | u8 percent_complete; |
| 1566 | u16 handle; |
| 1567 | |
| 1568 | percent_complete = 0; |
| 1569 | handle = 0; |
| 1570 | if (ioc->is_warpdrive) |
| 1571 | goto out; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1572 | |
| 1573 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1574 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1575 | sdev->channel); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1576 | if (raid_device) { |
| 1577 | handle = raid_device->handle; |
| 1578 | percent_complete = raid_device->percent_complete; |
| 1579 | } |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1580 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1581 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1582 | if (!handle) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1583 | goto out; |
| 1584 | |
| 1585 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1586 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1587 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1588 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1589 | ioc->name, __FILE__, __LINE__, __func__); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1590 | percent_complete = 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1591 | goto out; |
| 1592 | } |
| 1593 | |
| 1594 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1595 | if (!(volume_status_flags & |
| 1596 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) |
| 1597 | percent_complete = 0; |
| 1598 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1599 | out: |
| 1600 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); |
| 1601 | } |
| 1602 | |
| 1603 | /** |
| 1604 | * _scsih_get_state - get raid volume level |
| 1605 | * @dev the device struct object |
| 1606 | */ |
| 1607 | static void |
| 1608 | _scsih_get_state(struct device *dev) |
| 1609 | { |
| 1610 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1611 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1612 | static struct _raid_device *raid_device; |
| 1613 | unsigned long flags; |
| 1614 | Mpi2RaidVolPage0_t vol_pg0; |
| 1615 | Mpi2ConfigReply_t mpi_reply; |
| 1616 | u32 volstate; |
| 1617 | enum raid_state state = RAID_STATE_UNKNOWN; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1618 | u16 handle = 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1619 | |
| 1620 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1621 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1622 | sdev->channel); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1623 | if (raid_device) |
| 1624 | handle = raid_device->handle; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1625 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1626 | |
| 1627 | if (!raid_device) |
| 1628 | goto out; |
| 1629 | |
| 1630 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1631 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1632 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1633 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1634 | ioc->name, __FILE__, __LINE__, __func__); |
| 1635 | goto out; |
| 1636 | } |
| 1637 | |
| 1638 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
| 1639 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { |
| 1640 | state = RAID_STATE_RESYNCING; |
| 1641 | goto out; |
| 1642 | } |
| 1643 | |
| 1644 | switch (vol_pg0.VolumeState) { |
| 1645 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
| 1646 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 1647 | state = RAID_STATE_ACTIVE; |
| 1648 | break; |
| 1649 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 1650 | state = RAID_STATE_DEGRADED; |
| 1651 | break; |
| 1652 | case MPI2_RAID_VOL_STATE_FAILED: |
| 1653 | case MPI2_RAID_VOL_STATE_MISSING: |
| 1654 | state = RAID_STATE_OFFLINE; |
| 1655 | break; |
| 1656 | } |
| 1657 | out: |
| 1658 | raid_set_state(mpt2sas_raid_template, dev, state); |
| 1659 | } |
| 1660 | |
| 1661 | /** |
| 1662 | * _scsih_set_level - set raid level |
| 1663 | * @sdev: scsi device struct |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1664 | * @volume_type: volume type |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1665 | */ |
| 1666 | static void |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1667 | _scsih_set_level(struct scsi_device *sdev, u8 volume_type) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1668 | { |
| 1669 | enum raid_level level = RAID_LEVEL_UNKNOWN; |
| 1670 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1671 | switch (volume_type) { |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1672 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 1673 | level = RAID_LEVEL_0; |
| 1674 | break; |
| 1675 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 1676 | level = RAID_LEVEL_10; |
| 1677 | break; |
| 1678 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 1679 | level = RAID_LEVEL_1E; |
| 1680 | break; |
| 1681 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 1682 | level = RAID_LEVEL_1; |
| 1683 | break; |
| 1684 | } |
| 1685 | |
| 1686 | raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level); |
| 1687 | } |
| 1688 | |
| 1689 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1690 | * _scsih_get_volume_capabilities - volume capabilities |
| 1691 | * @ioc: per adapter object |
| 1692 | * @sas_device: the raid_device object |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1693 | * |
| 1694 | * Returns 0 for success, else 1 |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1695 | */ |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1696 | static int |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1697 | _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc, |
| 1698 | struct _raid_device *raid_device) |
| 1699 | { |
| 1700 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1701 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1702 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1703 | Mpi2ConfigReply_t mpi_reply; |
| 1704 | u16 sz; |
| 1705 | u8 num_pds; |
| 1706 | |
| 1707 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1708 | &num_pds)) || !num_pds) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1709 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1710 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1711 | __func__)); |
| 1712 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | raid_device->num_pds = num_pds; |
| 1716 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1717 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1718 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1719 | if (!vol_pg0) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1720 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1721 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1722 | __func__)); |
| 1723 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1727 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1728 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1729 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1730 | __func__)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1731 | kfree(vol_pg0); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1732 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | raid_device->volume_type = vol_pg0->VolumeType; |
| 1736 | |
| 1737 | /* figure out what the underlying devices are by |
| 1738 | * obtaining the device_info bits for the 1st device |
| 1739 | */ |
| 1740 | if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1741 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1742 | vol_pg0->PhysDisk[0].PhysDiskNum))) { |
| 1743 | if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 1744 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 1745 | le16_to_cpu(pd_pg0.DevHandle)))) { |
| 1746 | raid_device->device_info = |
| 1747 | le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | kfree(vol_pg0); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1752 | return 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1753 | } |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1754 | /** |
| 1755 | * _scsih_disable_ddio - Disable direct I/O for all the volumes |
| 1756 | * @ioc: per adapter object |
| 1757 | */ |
| 1758 | static void |
| 1759 | _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc) |
| 1760 | { |
| 1761 | Mpi2RaidVolPage1_t vol_pg1; |
| 1762 | Mpi2ConfigReply_t mpi_reply; |
| 1763 | struct _raid_device *raid_device; |
| 1764 | u16 handle; |
| 1765 | u16 ioc_status; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1766 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1767 | |
| 1768 | handle = 0xFFFF; |
| 1769 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 1770 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 1771 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1772 | MPI2_IOCSTATUS_MASK; |
| 1773 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 1774 | break; |
| 1775 | handle = le16_to_cpu(vol_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1776 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1777 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 1778 | if (raid_device) |
| 1779 | raid_device->direct_io_enabled = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1780 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1781 | } |
| 1782 | return; |
| 1783 | } |
| 1784 | |
| 1785 | |
| 1786 | /** |
| 1787 | * _scsih_get_num_volumes - Get number of volumes in the ioc |
| 1788 | * @ioc: per adapter object |
| 1789 | */ |
| 1790 | static u8 |
| 1791 | _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc) |
| 1792 | { |
| 1793 | Mpi2RaidVolPage1_t vol_pg1; |
| 1794 | Mpi2ConfigReply_t mpi_reply; |
| 1795 | u16 handle; |
| 1796 | u8 vol_cnt = 0; |
| 1797 | u16 ioc_status; |
| 1798 | |
| 1799 | handle = 0xFFFF; |
| 1800 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 1801 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 1802 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1803 | MPI2_IOCSTATUS_MASK; |
| 1804 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 1805 | break; |
| 1806 | vol_cnt++; |
| 1807 | handle = le16_to_cpu(vol_pg1.DevHandle); |
| 1808 | } |
| 1809 | return vol_cnt; |
| 1810 | } |
| 1811 | |
| 1812 | |
| 1813 | /** |
| 1814 | * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O. |
| 1815 | * @ioc: per adapter object |
| 1816 | * @raid_device: the raid_device object |
| 1817 | */ |
| 1818 | static void |
| 1819 | _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc, |
| 1820 | struct _raid_device *raid_device) |
| 1821 | { |
| 1822 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1823 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1824 | Mpi2ConfigReply_t mpi_reply; |
| 1825 | u16 sz; |
| 1826 | u8 num_pds, count; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1827 | unsigned long stripe_sz, block_sz; |
| 1828 | u8 stripe_exp, block_exp; |
| 1829 | u64 dev_max_lba; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1830 | |
| 1831 | if (!ioc->is_warpdrive) |
| 1832 | return; |
| 1833 | |
| 1834 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) { |
| 1835 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1836 | "globally as drives are exposed\n", ioc->name); |
| 1837 | return; |
| 1838 | } |
| 1839 | if (_scsih_get_num_volumes(ioc) > 1) { |
| 1840 | _scsih_disable_ddio(ioc); |
| 1841 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1842 | "globally as number of drives > 1\n", ioc->name); |
| 1843 | return; |
| 1844 | } |
| 1845 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1846 | &num_pds)) || !num_pds) { |
| 1847 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1848 | "Failure in computing number of drives\n", ioc->name); |
| 1849 | return; |
| 1850 | } |
| 1851 | |
| 1852 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1853 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1854 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1855 | if (!vol_pg0) { |
| 1856 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1857 | "Memory allocation failure for RVPG0\n", ioc->name); |
| 1858 | return; |
| 1859 | } |
| 1860 | |
| 1861 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1862 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
| 1863 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1864 | "Failure in retrieving RVPG0\n", ioc->name); |
| 1865 | kfree(vol_pg0); |
| 1866 | return; |
| 1867 | } |
| 1868 | |
| 1869 | /* |
| 1870 | * WARPDRIVE:If number of physical disks in a volume exceeds the max pds |
| 1871 | * assumed for WARPDRIVE, disable direct I/O |
| 1872 | */ |
| 1873 | if (num_pds > MPT_MAX_WARPDRIVE_PDS) { |
| 1874 | printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled " |
| 1875 | "for the drive with handle(0x%04x): num_mem=%d, " |
| 1876 | "max_mem_allowed=%d\n", ioc->name, raid_device->handle, |
| 1877 | num_pds, MPT_MAX_WARPDRIVE_PDS); |
| 1878 | kfree(vol_pg0); |
| 1879 | return; |
| 1880 | } |
| 1881 | for (count = 0; count < num_pds; count++) { |
| 1882 | if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1883 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1884 | vol_pg0->PhysDisk[count].PhysDiskNum) || |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 1885 | le16_to_cpu(pd_pg0.DevHandle) == |
| 1886 | MPT2SAS_INVALID_DEVICE_HANDLE) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1887 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " |
| 1888 | "disabled for the drive with handle(0x%04x) member" |
| 1889 | "handle retrieval failed for member number=%d\n", |
| 1890 | ioc->name, raid_device->handle, |
| 1891 | vol_pg0->PhysDisk[count].PhysDiskNum); |
| 1892 | goto out_error; |
| 1893 | } |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1894 | /* Disable direct I/O if member drive lba exceeds 4 bytes */ |
| 1895 | dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA); |
| 1896 | if (dev_max_lba >> 32) { |
| 1897 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " |
| 1898 | "disabled for the drive with handle(0x%04x) member" |
| 1899 | "handle (0x%04x) unsupported max lba 0x%016llx\n", |
| 1900 | ioc->name, raid_device->handle, |
| 1901 | le16_to_cpu(pd_pg0.DevHandle), |
| 1902 | (unsigned long long)dev_max_lba); |
| 1903 | goto out_error; |
| 1904 | } |
| 1905 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1906 | raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle); |
| 1907 | } |
| 1908 | |
| 1909 | /* |
| 1910 | * Assumption for WD: Direct I/O is not supported if the volume is |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1911 | * not RAID0 |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1912 | */ |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1913 | if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1914 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1915 | "for the drive with handle(0x%04x): type=%d, " |
| 1916 | "s_sz=%uK, blk_size=%u\n", ioc->name, |
| 1917 | raid_device->handle, raid_device->volume_type, |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1918 | (le32_to_cpu(vol_pg0->StripeSize) * |
| 1919 | le16_to_cpu(vol_pg0->BlockSize)) / 1024, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1920 | le16_to_cpu(vol_pg0->BlockSize)); |
| 1921 | goto out_error; |
| 1922 | } |
| 1923 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1924 | stripe_sz = le32_to_cpu(vol_pg0->StripeSize); |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1925 | stripe_exp = find_first_bit(&stripe_sz, 32); |
| 1926 | if (stripe_exp == 32) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1927 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1928 | "for the drive with handle(0x%04x) invalid stripe sz %uK\n", |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1929 | ioc->name, raid_device->handle, |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1930 | (le32_to_cpu(vol_pg0->StripeSize) * |
| 1931 | le16_to_cpu(vol_pg0->BlockSize)) / 1024); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1932 | goto out_error; |
| 1933 | } |
| 1934 | raid_device->stripe_exponent = stripe_exp; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1935 | block_sz = le16_to_cpu(vol_pg0->BlockSize); |
| 1936 | block_exp = find_first_bit(&block_sz, 16); |
| 1937 | if (block_exp == 16) { |
| 1938 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1939 | "for the drive with handle(0x%04x) invalid block sz %u\n", |
| 1940 | ioc->name, raid_device->handle, |
| 1941 | le16_to_cpu(vol_pg0->BlockSize)); |
| 1942 | goto out_error; |
| 1943 | } |
| 1944 | raid_device->block_exponent = block_exp; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1945 | raid_device->direct_io_enabled = 1; |
| 1946 | |
| 1947 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive" |
| 1948 | " with handle(0x%04x)\n", ioc->name, raid_device->handle); |
| 1949 | /* |
| 1950 | * WARPDRIVE: Though the following fields are not used for direct IO, |
| 1951 | * stored for future purpose: |
| 1952 | */ |
| 1953 | raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA); |
| 1954 | raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize); |
| 1955 | raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize); |
| 1956 | |
| 1957 | |
| 1958 | kfree(vol_pg0); |
| 1959 | return; |
| 1960 | |
| 1961 | out_error: |
| 1962 | raid_device->direct_io_enabled = 0; |
| 1963 | for (count = 0; count < num_pds; count++) |
| 1964 | raid_device->pd_handle[count] = 0; |
| 1965 | kfree(vol_pg0); |
| 1966 | return; |
| 1967 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1968 | |
| 1969 | /** |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 1970 | * _scsih_enable_tlr - setting TLR flags |
| 1971 | * @ioc: per adapter object |
| 1972 | * @sdev: scsi device struct |
| 1973 | * |
| 1974 | * Enabling Transaction Layer Retries for tape devices when |
| 1975 | * vpd page 0x90 is present |
| 1976 | * |
| 1977 | */ |
| 1978 | static void |
| 1979 | _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev) |
| 1980 | { |
| 1981 | /* only for TAPE */ |
| 1982 | if (sdev->type != TYPE_TAPE) |
| 1983 | return; |
| 1984 | |
| 1985 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) |
| 1986 | return; |
| 1987 | |
| 1988 | sas_enable_tlr(sdev); |
| 1989 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", |
| 1990 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); |
| 1991 | return; |
| 1992 | |
| 1993 | } |
| 1994 | |
| 1995 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1996 | * _scsih_slave_configure - device configure routine. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1997 | * @sdev: scsi device struct |
| 1998 | * |
| 1999 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 2000 | * the device is ignored. |
| 2001 | */ |
| 2002 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2003 | _scsih_slave_configure(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2004 | { |
| 2005 | struct Scsi_Host *shost = sdev->host; |
| 2006 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2007 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2008 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 2009 | struct _sas_device *sas_device; |
| 2010 | struct _raid_device *raid_device; |
| 2011 | unsigned long flags; |
| 2012 | int qdepth; |
| 2013 | u8 ssp_target = 0; |
| 2014 | char *ds = ""; |
| 2015 | char *r_level = ""; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2016 | u16 handle, volume_handle = 0; |
| 2017 | u64 volume_wwid = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2018 | |
| 2019 | qdepth = 1; |
| 2020 | sas_device_priv_data = sdev->hostdata; |
| 2021 | sas_device_priv_data->configured_lun = 1; |
| 2022 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; |
| 2023 | sas_target_priv_data = sas_device_priv_data->sas_target; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2024 | handle = sas_target_priv_data->handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2025 | |
| 2026 | /* raid volume handling */ |
| 2027 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 2028 | |
| 2029 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2030 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2031 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 2032 | if (!raid_device) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2033 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2034 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2035 | __LINE__, __func__)); |
| 2036 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2037 | } |
| 2038 | |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2039 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { |
| 2040 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2041 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2042 | __LINE__, __func__)); |
| 2043 | return 1; |
| 2044 | } |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2045 | /* |
| 2046 | * WARPDRIVE: Initialize the required data for Direct IO |
| 2047 | */ |
| 2048 | _scsih_init_warpdrive_properties(ioc, raid_device); |
| 2049 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2050 | /* RAID Queue Depth Support |
| 2051 | * IS volume = underlying qdepth of drive type, either |
| 2052 | * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH |
| 2053 | * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH) |
| 2054 | */ |
| 2055 | if (raid_device->device_info & |
| 2056 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 2057 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 2058 | ds = "SSP"; |
| 2059 | } else { |
| 2060 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 2061 | if (raid_device->device_info & |
| 2062 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 2063 | ds = "SATA"; |
| 2064 | else |
| 2065 | ds = "STP"; |
| 2066 | } |
| 2067 | |
| 2068 | switch (raid_device->volume_type) { |
| 2069 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 2070 | r_level = "RAID0"; |
| 2071 | break; |
| 2072 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 2073 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 2074 | if (ioc->manu_pg10.OEMIdentifier && |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 2075 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 2076 | MFG10_GF0_R10_DISPLAY) && |
| 2077 | !(raid_device->num_pds % 2)) |
| 2078 | r_level = "RAID10"; |
| 2079 | else |
| 2080 | r_level = "RAID1E"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2081 | break; |
| 2082 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 2083 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2084 | r_level = "RAID1"; |
| 2085 | break; |
| 2086 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 2087 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2088 | r_level = "RAID10"; |
| 2089 | break; |
| 2090 | case MPI2_RAID_VOL_TYPE_UNKNOWN: |
| 2091 | default: |
| 2092 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2093 | r_level = "RAIDX"; |
| 2094 | break; |
| 2095 | } |
| 2096 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2097 | if (!ioc->hide_ir_msg) |
| 2098 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
| 2099 | "wwid(0x%016llx), pd_count(%d), type(%s)\n", |
| 2100 | r_level, raid_device->handle, |
| 2101 | (unsigned long long)raid_device->wwid, |
| 2102 | raid_device->num_pds, ds); |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 2103 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 2104 | /* raid transport support */ |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2105 | if (!ioc->is_warpdrive) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2106 | _scsih_set_level(sdev, raid_device->volume_type); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2107 | return 0; |
| 2108 | } |
| 2109 | |
| 2110 | /* non-raid handling */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2111 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2112 | if (mpt2sas_config_get_volume_handle(ioc, handle, |
| 2113 | &volume_handle)) { |
| 2114 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2115 | "failure at %s:%d/%s()!\n", ioc->name, |
| 2116 | __FILE__, __LINE__, __func__)); |
| 2117 | return 1; |
| 2118 | } |
| 2119 | if (volume_handle && mpt2sas_config_get_volume_wwid(ioc, |
| 2120 | volume_handle, &volume_wwid)) { |
| 2121 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2122 | "failure at %s:%d/%s()!\n", ioc->name, |
| 2123 | __FILE__, __LINE__, __func__)); |
| 2124 | return 1; |
| 2125 | } |
| 2126 | } |
| 2127 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2128 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2129 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2130 | sas_device_priv_data->sas_target->sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2131 | if (!sas_device) { |
| 2132 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2133 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2134 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2135 | __LINE__, __func__)); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2136 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2137 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2138 | sas_device->volume_handle = volume_handle; |
| 2139 | sas_device->volume_wwid = volume_wwid; |
| 2140 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 2141 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 2142 | ssp_target = 1; |
| 2143 | ds = "SSP"; |
| 2144 | } else { |
| 2145 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 2146 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
| 2147 | ds = "STP"; |
| 2148 | else if (sas_device->device_info & |
| 2149 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 2150 | ds = "SATA"; |
| 2151 | } |
| 2152 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
| 2153 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", |
| 2154 | ds, sas_device->handle, |
| 2155 | (unsigned long long)sas_device->sas_address, |
| 2156 | sas_device->phy, |
| 2157 | (unsigned long long)sas_device->device_name); |
| 2158 | sdev_printk(KERN_INFO, sdev, "%s: " |
| 2159 | "enclosure_logical_id(0x%016llx), slot(%d)\n", ds, |
| 2160 | (unsigned long long) sas_device->enclosure_logical_id, |
| 2161 | sas_device->slot); |
| 2162 | |
| 2163 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2164 | if (!ssp_target) |
| 2165 | _scsih_display_sata_capabilities(ioc, handle, sdev); |
| 2166 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2167 | |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 2168 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2169 | |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 2170 | if (ssp_target) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2171 | sas_read_port_mode_page(sdev); |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 2172 | _scsih_enable_tlr(ioc, sdev); |
| 2173 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2174 | return 0; |
| 2175 | } |
| 2176 | |
| 2177 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2178 | * _scsih_bios_param - fetch head, sector, cylinder info for a disk |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2179 | * @sdev: scsi device struct |
| 2180 | * @bdev: pointer to block device context |
| 2181 | * @capacity: device size (in 512 byte sectors) |
| 2182 | * @params: three element array to place output: |
| 2183 | * params[0] number of heads (max 255) |
| 2184 | * params[1] number of sectors (max 63) |
| 2185 | * params[2] number of cylinders |
| 2186 | * |
| 2187 | * Return nothing. |
| 2188 | */ |
| 2189 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2190 | _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2191 | sector_t capacity, int params[]) |
| 2192 | { |
| 2193 | int heads; |
| 2194 | int sectors; |
| 2195 | sector_t cylinders; |
| 2196 | ulong dummy; |
| 2197 | |
| 2198 | heads = 64; |
| 2199 | sectors = 32; |
| 2200 | |
| 2201 | dummy = heads * sectors; |
| 2202 | cylinders = capacity; |
| 2203 | sector_div(cylinders, dummy); |
| 2204 | |
| 2205 | /* |
| 2206 | * Handle extended translation size for logical drives |
| 2207 | * > 1Gb |
| 2208 | */ |
| 2209 | if ((ulong)capacity >= 0x200000) { |
| 2210 | heads = 255; |
| 2211 | sectors = 63; |
| 2212 | dummy = heads * sectors; |
| 2213 | cylinders = capacity; |
| 2214 | sector_div(cylinders, dummy); |
| 2215 | } |
| 2216 | |
| 2217 | /* return result */ |
| 2218 | params[0] = heads; |
| 2219 | params[1] = sectors; |
| 2220 | params[2] = cylinders; |
| 2221 | |
| 2222 | return 0; |
| 2223 | } |
| 2224 | |
| 2225 | /** |
| 2226 | * _scsih_response_code - translation of device response code |
| 2227 | * @ioc: per adapter object |
| 2228 | * @response_code: response code returned by the device |
| 2229 | * |
| 2230 | * Return nothing. |
| 2231 | */ |
| 2232 | static void |
| 2233 | _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code) |
| 2234 | { |
| 2235 | char *desc; |
| 2236 | |
| 2237 | switch (response_code) { |
| 2238 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: |
| 2239 | desc = "task management request completed"; |
| 2240 | break; |
| 2241 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: |
| 2242 | desc = "invalid frame"; |
| 2243 | break; |
| 2244 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: |
| 2245 | desc = "task management request not supported"; |
| 2246 | break; |
| 2247 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: |
| 2248 | desc = "task management request failed"; |
| 2249 | break; |
| 2250 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: |
| 2251 | desc = "task management request succeeded"; |
| 2252 | break; |
| 2253 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: |
| 2254 | desc = "invalid lun"; |
| 2255 | break; |
| 2256 | case 0xA: |
| 2257 | desc = "overlapped tag attempted"; |
| 2258 | break; |
| 2259 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: |
| 2260 | desc = "task queued, however not sent to target"; |
| 2261 | break; |
| 2262 | default: |
| 2263 | desc = "unknown"; |
| 2264 | break; |
| 2265 | } |
| 2266 | printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n", |
| 2267 | ioc->name, response_code, desc); |
| 2268 | } |
| 2269 | |
| 2270 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2271 | * _scsih_tm_done - tm completion routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2272 | * @ioc: per adapter object |
| 2273 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2274 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2275 | * @reply: reply message frame(lower 32bit addr) |
| 2276 | * Context: none. |
| 2277 | * |
| 2278 | * The callback handler when using scsih_issue_tm. |
| 2279 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2280 | * Return 1 meaning mf should be freed from _base_interrupt |
| 2281 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2282 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2283 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2284 | _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] | 2285 | { |
| 2286 | MPI2DefaultReply_t *mpi_reply; |
| 2287 | |
| 2288 | if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2289 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2290 | if (ioc->tm_cmds.smid != smid) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2291 | return 1; |
nagalakshmi.nandigama@lsi.com | 911ae94 | 2011-09-08 06:18:50 +0530 | [diff] [blame] | 2292 | mpt2sas_base_flush_reply_queues(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2293 | ioc->tm_cmds.status |= MPT2_CMD_COMPLETE; |
| 2294 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 2295 | if (mpi_reply) { |
| 2296 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 2297 | ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 2298 | } |
| 2299 | ioc->tm_cmds.status &= ~MPT2_CMD_PENDING; |
| 2300 | complete(&ioc->tm_cmds.done); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2301 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | /** |
| 2305 | * mpt2sas_scsih_set_tm_flag - set per target tm_busy |
| 2306 | * @ioc: per adapter object |
| 2307 | * @handle: device handle |
| 2308 | * |
| 2309 | * During taskmangement request, we need to freeze the device queue. |
| 2310 | */ |
| 2311 | void |
| 2312 | mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2313 | { |
| 2314 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2315 | struct scsi_device *sdev; |
| 2316 | u8 skip = 0; |
| 2317 | |
| 2318 | shost_for_each_device(sdev, ioc->shost) { |
| 2319 | if (skip) |
| 2320 | continue; |
| 2321 | sas_device_priv_data = sdev->hostdata; |
| 2322 | if (!sas_device_priv_data) |
| 2323 | continue; |
| 2324 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2325 | sas_device_priv_data->sas_target->tm_busy = 1; |
| 2326 | skip = 1; |
| 2327 | ioc->ignore_loginfos = 1; |
| 2328 | } |
| 2329 | } |
| 2330 | } |
| 2331 | |
| 2332 | /** |
| 2333 | * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy |
| 2334 | * @ioc: per adapter object |
| 2335 | * @handle: device handle |
| 2336 | * |
| 2337 | * During taskmangement request, we need to freeze the device queue. |
| 2338 | */ |
| 2339 | void |
| 2340 | mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2341 | { |
| 2342 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2343 | struct scsi_device *sdev; |
| 2344 | u8 skip = 0; |
| 2345 | |
| 2346 | shost_for_each_device(sdev, ioc->shost) { |
| 2347 | if (skip) |
| 2348 | continue; |
| 2349 | sas_device_priv_data = sdev->hostdata; |
| 2350 | if (!sas_device_priv_data) |
| 2351 | continue; |
| 2352 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2353 | sas_device_priv_data->sas_target->tm_busy = 0; |
| 2354 | skip = 1; |
| 2355 | ioc->ignore_loginfos = 0; |
| 2356 | } |
| 2357 | } |
| 2358 | } |
| 2359 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2360 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2361 | /** |
| 2362 | * mpt2sas_scsih_issue_tm - main routine for sending tm requests |
| 2363 | * @ioc: per adapter struct |
| 2364 | * @device_handle: device handle |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2365 | * @channel: the channel assigned by the OS |
| 2366 | * @id: the id assigned by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2367 | * @lun: lun number |
| 2368 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) |
| 2369 | * @smid_task: smid assigned to the task |
| 2370 | * @timeout: timeout in seconds |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2371 | * @serial_number: the serial_number from scmd |
| 2372 | * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2373 | * Context: user |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2374 | * |
| 2375 | * A generic API for sending task management requests to firmware. |
| 2376 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2377 | * The callback index is set inside `ioc->tm_cb_idx`. |
| 2378 | * |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2379 | * Return SUCCESS or FAILED. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2380 | */ |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2381 | int |
| 2382 | mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel, |
| 2383 | uint id, uint lun, u8 type, u16 smid_task, ulong timeout, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2384 | unsigned long serial_number, enum mutex_type m_type) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2385 | { |
| 2386 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 2387 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
| 2388 | u16 smid = 0; |
| 2389 | u32 ioc_state; |
| 2390 | unsigned long timeleft; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2391 | struct scsiio_tracker *scsi_lookup = NULL; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2392 | int rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2393 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2394 | if (m_type == TM_MUTEX_ON) |
| 2395 | mutex_lock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2396 | if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) { |
| 2397 | printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n", |
| 2398 | __func__, ioc->name); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2399 | rc = FAILED; |
| 2400 | goto err_out; |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2401 | } |
| 2402 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 2403 | if (ioc->shost_recovery || ioc->remove_host || |
| 2404 | ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2405 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 2406 | __func__, ioc->name); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2407 | rc = FAILED; |
| 2408 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2409 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2410 | |
| 2411 | ioc_state = mpt2sas_base_get_iocstate(ioc, 0); |
| 2412 | if (ioc_state & MPI2_DOORBELL_USED) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 2413 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2414 | "active!\n", ioc->name)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2415 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2416 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2417 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2418 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2419 | } |
| 2420 | |
| 2421 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 2422 | mpt2sas_base_fault_info(ioc, ioc_state & |
| 2423 | MPI2_DOORBELL_DATA_MASK); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2424 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2425 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2426 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2427 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2428 | } |
| 2429 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2430 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2431 | if (!smid) { |
| 2432 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 2433 | ioc->name, __func__); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2434 | rc = FAILED; |
| 2435 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2436 | } |
| 2437 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2438 | if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) |
| 2439 | scsi_lookup = &ioc->scsi_lookup[smid_task - 1]; |
| 2440 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2441 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x)," |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2442 | " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type, |
| 2443 | smid_task)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2444 | ioc->tm_cmds.status = MPT2_CMD_PENDING; |
| 2445 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 2446 | ioc->tm_cmds.smid = smid; |
| 2447 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2448 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2449 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 2450 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 2451 | mpi_request->TaskType = type; |
| 2452 | mpi_request->TaskMID = cpu_to_le16(smid_task); |
| 2453 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); |
| 2454 | mpt2sas_scsih_set_tm_flag(ioc, handle); |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 2455 | init_completion(&ioc->tm_cmds.done); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2456 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2457 | timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2458 | if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) { |
| 2459 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 2460 | ioc->name, __func__); |
| 2461 | _debug_dump_mf(mpi_request, |
| 2462 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2463 | if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) { |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2464 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2465 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2466 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2467 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
| 2468 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 2469 | goto err_out; |
| 2470 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 2474 | mpi_reply = ioc->tm_cmds.reply; |
| 2475 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: " |
| 2476 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", |
| 2477 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 2478 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 2479 | le32_to_cpu(mpi_reply->TerminationCount))); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2480 | if (ioc->logging_level & MPT_DEBUG_TM) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2481 | _scsih_response_code(ioc, mpi_reply->ResponseCode); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2482 | if (mpi_reply->IOCStatus) |
| 2483 | _debug_dump_mf(mpi_request, |
| 2484 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
| 2485 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2486 | } |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2487 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2488 | switch (type) { |
| 2489 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2490 | rc = SUCCESS; |
| 2491 | if (scsi_lookup->scmd == NULL) |
| 2492 | break; |
| 2493 | rc = FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2494 | break; |
| 2495 | |
| 2496 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: |
| 2497 | if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) |
| 2498 | rc = FAILED; |
| 2499 | else |
| 2500 | rc = SUCCESS; |
| 2501 | break; |
| 2502 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2503 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2504 | case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: |
| 2505 | if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) |
| 2506 | rc = FAILED; |
| 2507 | else |
| 2508 | rc = SUCCESS; |
| 2509 | break; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2510 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: |
| 2511 | rc = SUCCESS; |
| 2512 | break; |
| 2513 | default: |
| 2514 | rc = FAILED; |
| 2515 | break; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2516 | } |
| 2517 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2518 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 2519 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2520 | if (m_type == TM_MUTEX_ON) |
| 2521 | mutex_unlock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2522 | |
| 2523 | return rc; |
| 2524 | |
| 2525 | err_out: |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2526 | if (m_type == TM_MUTEX_ON) |
| 2527 | mutex_unlock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2528 | return rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2529 | } |
| 2530 | |
| 2531 | /** |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2532 | * _scsih_tm_display_info - displays info about the device |
| 2533 | * @ioc: per adapter struct |
| 2534 | * @scmd: pointer to scsi command object |
| 2535 | * |
| 2536 | * Called by task management callback handlers. |
| 2537 | */ |
| 2538 | static void |
| 2539 | _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) |
| 2540 | { |
| 2541 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2542 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; |
| 2543 | struct _sas_device *sas_device = NULL; |
| 2544 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2545 | char *device_str = NULL; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2546 | |
| 2547 | if (!priv_target) |
| 2548 | return; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2549 | if (ioc->hide_ir_msg) |
| 2550 | device_str = "WarpDrive"; |
| 2551 | else |
| 2552 | device_str = "volume"; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2553 | |
| 2554 | scsi_print_command(scmd); |
| 2555 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2556 | starget_printk(KERN_INFO, starget, "%s handle(0x%04x), " |
| 2557 | "%s wwid(0x%016llx)\n", device_str, priv_target->handle, |
| 2558 | device_str, (unsigned long long)priv_target->sas_address); |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2559 | } else { |
| 2560 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2561 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2562 | priv_target->sas_address); |
| 2563 | if (sas_device) { |
| 2564 | if (priv_target->flags & |
| 2565 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2566 | starget_printk(KERN_INFO, starget, |
| 2567 | "volume handle(0x%04x), " |
| 2568 | "volume wwid(0x%016llx)\n", |
| 2569 | sas_device->volume_handle, |
| 2570 | (unsigned long long)sas_device->volume_wwid); |
| 2571 | } |
| 2572 | starget_printk(KERN_INFO, starget, |
| 2573 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", |
| 2574 | sas_device->handle, |
| 2575 | (unsigned long long)sas_device->sas_address, |
| 2576 | sas_device->phy); |
| 2577 | starget_printk(KERN_INFO, starget, |
| 2578 | "enclosure_logical_id(0x%016llx), slot(%d)\n", |
| 2579 | (unsigned long long)sas_device->enclosure_logical_id, |
| 2580 | sas_device->slot); |
| 2581 | } |
| 2582 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2583 | } |
| 2584 | } |
| 2585 | |
| 2586 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2587 | * _scsih_abort - eh threads main abort routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2588 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2589 | * |
| 2590 | * Returns SUCCESS if command aborted else FAILED |
| 2591 | */ |
| 2592 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2593 | _scsih_abort(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2594 | { |
| 2595 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2596 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2597 | u16 smid; |
| 2598 | u16 handle; |
| 2599 | int r; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2600 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2601 | sdev_printk(KERN_INFO, scmd->device, "attempting task abort! " |
| 2602 | "scmd(%p)\n", scmd); |
| 2603 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2604 | |
| 2605 | sas_device_priv_data = scmd->device->hostdata; |
| 2606 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2607 | sdev_printk(KERN_INFO, scmd->device, "device been deleted! " |
| 2608 | "scmd(%p)\n", scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2609 | scmd->result = DID_NO_CONNECT << 16; |
| 2610 | scmd->scsi_done(scmd); |
| 2611 | r = SUCCESS; |
| 2612 | goto out; |
| 2613 | } |
| 2614 | |
| 2615 | /* search for the command */ |
| 2616 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); |
| 2617 | if (!smid) { |
| 2618 | scmd->result = DID_RESET << 16; |
| 2619 | r = SUCCESS; |
| 2620 | goto out; |
| 2621 | } |
| 2622 | |
| 2623 | /* for hidden raid components and volumes this is not supported */ |
| 2624 | if (sas_device_priv_data->sas_target->flags & |
| 2625 | MPT_TARGET_FLAGS_RAID_COMPONENT || |
| 2626 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 2627 | scmd->result = DID_RESET << 16; |
| 2628 | r = FAILED; |
| 2629 | goto out; |
| 2630 | } |
| 2631 | |
Kashyap, Desai | fa7f316 | 2009-09-23 17:26:58 +0530 | [diff] [blame] | 2632 | mpt2sas_halt_firmware(ioc); |
| 2633 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2634 | handle = sas_device_priv_data->sas_target->handle; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2635 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2636 | scmd->device->id, scmd->device->lun, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2637 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, |
| 2638 | scmd->serial_number, TM_MUTEX_ON); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2639 | |
| 2640 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2641 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", |
| 2642 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2643 | return r; |
| 2644 | } |
| 2645 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2646 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2647 | * _scsih_dev_reset - eh threads main device reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2648 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2649 | * |
| 2650 | * Returns SUCCESS if command aborted else FAILED |
| 2651 | */ |
| 2652 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2653 | _scsih_dev_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2654 | { |
| 2655 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2656 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2657 | struct _sas_device *sas_device; |
| 2658 | unsigned long flags; |
| 2659 | u16 handle; |
| 2660 | int r; |
| 2661 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2662 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2663 | |
Kashyap, Desai | 37aaa78 | 2010-11-13 04:41:32 +0530 | [diff] [blame] | 2664 | starget_printk(KERN_INFO, starget, "attempting device reset! " |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2665 | "scmd(%p)\n", scmd); |
| 2666 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2667 | |
| 2668 | sas_device_priv_data = scmd->device->hostdata; |
| 2669 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 37aaa78 | 2010-11-13 04:41:32 +0530 | [diff] [blame] | 2670 | starget_printk(KERN_INFO, starget, "device been deleted! " |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2671 | "scmd(%p)\n", scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2672 | scmd->result = DID_NO_CONNECT << 16; |
| 2673 | scmd->scsi_done(scmd); |
| 2674 | r = SUCCESS; |
| 2675 | goto out; |
| 2676 | } |
| 2677 | |
| 2678 | /* for hidden raid components obtain the volume_handle */ |
| 2679 | handle = 0; |
| 2680 | if (sas_device_priv_data->sas_target->flags & |
| 2681 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2682 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2683 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2684 | sas_device_priv_data->sas_target->handle); |
| 2685 | if (sas_device) |
| 2686 | handle = sas_device->volume_handle; |
| 2687 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2688 | } else |
| 2689 | handle = sas_device_priv_data->sas_target->handle; |
| 2690 | |
| 2691 | if (!handle) { |
| 2692 | scmd->result = DID_RESET << 16; |
| 2693 | r = FAILED; |
| 2694 | goto out; |
| 2695 | } |
| 2696 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2697 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2698 | scmd->device->id, scmd->device->lun, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2699 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, 0, |
| 2700 | TM_MUTEX_ON); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2701 | |
| 2702 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2703 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", |
| 2704 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2705 | return r; |
| 2706 | } |
| 2707 | |
| 2708 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2709 | * _scsih_target_reset - eh threads main target reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2710 | * @scmd: pointer to scsi command object |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2711 | * |
| 2712 | * Returns SUCCESS if command aborted else FAILED |
| 2713 | */ |
| 2714 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2715 | _scsih_target_reset(struct scsi_cmnd *scmd) |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2716 | { |
| 2717 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2718 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2719 | struct _sas_device *sas_device; |
| 2720 | unsigned long flags; |
| 2721 | u16 handle; |
| 2722 | int r; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2723 | struct scsi_target *starget = scmd->device->sdev_target; |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2724 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2725 | starget_printk(KERN_INFO, starget, "attempting target reset! " |
| 2726 | "scmd(%p)\n", scmd); |
| 2727 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2728 | |
| 2729 | sas_device_priv_data = scmd->device->hostdata; |
| 2730 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2731 | starget_printk(KERN_INFO, starget, "target been deleted! " |
| 2732 | "scmd(%p)\n", scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2733 | scmd->result = DID_NO_CONNECT << 16; |
| 2734 | scmd->scsi_done(scmd); |
| 2735 | r = SUCCESS; |
| 2736 | goto out; |
| 2737 | } |
| 2738 | |
| 2739 | /* for hidden raid components obtain the volume_handle */ |
| 2740 | handle = 0; |
| 2741 | if (sas_device_priv_data->sas_target->flags & |
| 2742 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2743 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2744 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2745 | sas_device_priv_data->sas_target->handle); |
| 2746 | if (sas_device) |
| 2747 | handle = sas_device->volume_handle; |
| 2748 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2749 | } else |
| 2750 | handle = sas_device_priv_data->sas_target->handle; |
| 2751 | |
| 2752 | if (!handle) { |
| 2753 | scmd->result = DID_RESET << 16; |
| 2754 | r = FAILED; |
| 2755 | goto out; |
| 2756 | } |
| 2757 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2758 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2759 | scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2760 | 30, 0, TM_MUTEX_ON); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2761 | |
| 2762 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2763 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", |
| 2764 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2765 | return r; |
| 2766 | } |
| 2767 | |
| 2768 | /** |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2769 | * _scsih_host_reset - eh threads main host reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2770 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2771 | * |
| 2772 | * Returns SUCCESS if command aborted else FAILED |
| 2773 | */ |
| 2774 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2775 | _scsih_host_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2776 | { |
| 2777 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2778 | int r, retval; |
| 2779 | |
| 2780 | printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n", |
| 2781 | ioc->name, scmd); |
| 2782 | scsi_print_command(scmd); |
| 2783 | |
| 2784 | retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2785 | FORCE_BIG_HAMMER); |
| 2786 | r = (retval < 0) ? FAILED : SUCCESS; |
| 2787 | printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n", |
| 2788 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 2789 | |
| 2790 | return r; |
| 2791 | } |
| 2792 | |
| 2793 | /** |
| 2794 | * _scsih_fw_event_add - insert and queue up fw_event |
| 2795 | * @ioc: per adapter object |
| 2796 | * @fw_event: object describing the event |
| 2797 | * Context: This function will acquire ioc->fw_event_lock. |
| 2798 | * |
| 2799 | * This adds the firmware event object into link list, then queues it up to |
| 2800 | * be processed from user context. |
| 2801 | * |
| 2802 | * Return nothing. |
| 2803 | */ |
| 2804 | static void |
| 2805 | _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event) |
| 2806 | { |
| 2807 | unsigned long flags; |
| 2808 | |
| 2809 | if (ioc->firmware_event_thread == NULL) |
| 2810 | return; |
| 2811 | |
| 2812 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2813 | list_add_tail(&fw_event->list, &ioc->fw_event_list); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2814 | INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work); |
| 2815 | queue_delayed_work(ioc->firmware_event_thread, |
| 2816 | &fw_event->delayed_work, 0); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2817 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2818 | } |
| 2819 | |
| 2820 | /** |
| 2821 | * _scsih_fw_event_free - delete fw_event |
| 2822 | * @ioc: per adapter object |
| 2823 | * @fw_event: object describing the event |
| 2824 | * Context: This function will acquire ioc->fw_event_lock. |
| 2825 | * |
| 2826 | * This removes firmware event object from link list, frees associated memory. |
| 2827 | * |
| 2828 | * Return nothing. |
| 2829 | */ |
| 2830 | static void |
| 2831 | _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work |
| 2832 | *fw_event) |
| 2833 | { |
| 2834 | unsigned long flags; |
| 2835 | |
| 2836 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2837 | list_del(&fw_event->list); |
| 2838 | kfree(fw_event->event_data); |
| 2839 | kfree(fw_event); |
| 2840 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2841 | } |
| 2842 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2843 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2844 | /** |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2845 | * _scsih_error_recovery_delete_devices - remove devices not responding |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2846 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2847 | * |
| 2848 | * Return nothing. |
| 2849 | */ |
| 2850 | static void |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2851 | _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2852 | { |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2853 | struct fw_event_work *fw_event; |
| 2854 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2855 | if (ioc->is_driver_loading) |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2856 | return; |
Dan Carpenter | 181a9d7 | 2011-11-04 21:25:01 +0300 | [diff] [blame] | 2857 | |
| 2858 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2859 | if (!fw_event) |
| 2860 | return; |
| 2861 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2862 | fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES; |
| 2863 | fw_event->ioc = ioc; |
| 2864 | _scsih_fw_event_add(ioc, fw_event); |
| 2865 | } |
| 2866 | |
| 2867 | /** |
| 2868 | * mpt2sas_port_enable_complete - port enable completed (fake event) |
| 2869 | * @ioc: per adapter object |
| 2870 | * |
| 2871 | * Return nothing. |
| 2872 | */ |
| 2873 | void |
| 2874 | mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc) |
| 2875 | { |
| 2876 | struct fw_event_work *fw_event; |
| 2877 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2878 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2879 | if (!fw_event) |
| 2880 | return; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2881 | fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2882 | fw_event->ioc = ioc; |
| 2883 | _scsih_fw_event_add(ioc, fw_event); |
| 2884 | } |
| 2885 | |
| 2886 | /** |
| 2887 | * _scsih_fw_event_cleanup_queue - cleanup event queue |
| 2888 | * @ioc: per adapter object |
| 2889 | * |
| 2890 | * Walk the firmware event queue, either killing timers, or waiting |
| 2891 | * for outstanding events to complete |
| 2892 | * |
| 2893 | * Return nothing. |
| 2894 | */ |
| 2895 | static void |
| 2896 | _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc) |
| 2897 | { |
| 2898 | struct fw_event_work *fw_event, *next; |
| 2899 | |
| 2900 | if (list_empty(&ioc->fw_event_list) || |
| 2901 | !ioc->firmware_event_thread || in_interrupt()) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2902 | return; |
| 2903 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2904 | list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) { |
| 2905 | if (cancel_delayed_work(&fw_event->delayed_work)) { |
| 2906 | _scsih_fw_event_free(ioc, fw_event); |
| 2907 | continue; |
| 2908 | } |
| 2909 | fw_event->cancel_pending_work = 1; |
| 2910 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2911 | } |
| 2912 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2913 | /** |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2914 | * _scsih_ublock_io_all_device - unblock every device |
| 2915 | * @ioc: per adapter object |
| 2916 | * |
| 2917 | * change the device state from block to running |
| 2918 | */ |
| 2919 | static void |
| 2920 | _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc) |
| 2921 | { |
| 2922 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2923 | struct scsi_device *sdev; |
| 2924 | |
| 2925 | shost_for_each_device(sdev, ioc->shost) { |
| 2926 | sas_device_priv_data = sdev->hostdata; |
| 2927 | if (!sas_device_priv_data) |
| 2928 | continue; |
| 2929 | if (!sas_device_priv_data->block) |
| 2930 | continue; |
| 2931 | sas_device_priv_data->block = 0; |
| 2932 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, " |
| 2933 | "handle(0x%04x)\n", |
| 2934 | sas_device_priv_data->sas_target->handle)); |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 2935 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2936 | } |
| 2937 | } |
| 2938 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2939 | * _scsih_ublock_io_device - set the device state to SDEV_RUNNING |
| 2940 | * @ioc: per adapter object |
| 2941 | * @handle: device handle |
| 2942 | * |
| 2943 | * During device pull we need to appropiately set the sdev state. |
| 2944 | */ |
| 2945 | static void |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2946 | _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2947 | { |
| 2948 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2949 | struct scsi_device *sdev; |
| 2950 | |
| 2951 | shost_for_each_device(sdev, ioc->shost) { |
| 2952 | sas_device_priv_data = sdev->hostdata; |
| 2953 | if (!sas_device_priv_data) |
| 2954 | continue; |
| 2955 | if (!sas_device_priv_data->block) |
| 2956 | continue; |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2957 | if (sas_device_priv_data->sas_target->sas_address == |
| 2958 | sas_address) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2959 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2960 | MPT2SAS_INFO_FMT "SDEV_RUNNING: " |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2961 | "sas address(0x%016llx)\n", ioc->name, |
| 2962 | (unsigned long long)sas_address)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2963 | sas_device_priv_data->block = 0; |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 2964 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2965 | } |
| 2966 | } |
| 2967 | } |
| 2968 | |
| 2969 | /** |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2970 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK |
| 2971 | * @ioc: per adapter object |
| 2972 | * @handle: device handle |
| 2973 | * |
| 2974 | * During device pull we need to appropiately set the sdev state. |
| 2975 | */ |
| 2976 | static void |
| 2977 | _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc) |
| 2978 | { |
| 2979 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2980 | struct scsi_device *sdev; |
| 2981 | |
| 2982 | shost_for_each_device(sdev, ioc->shost) { |
| 2983 | sas_device_priv_data = sdev->hostdata; |
| 2984 | if (!sas_device_priv_data) |
| 2985 | continue; |
| 2986 | if (sas_device_priv_data->block) |
| 2987 | continue; |
| 2988 | sas_device_priv_data->block = 1; |
| 2989 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, " |
| 2990 | "handle(0x%04x)\n", |
| 2991 | sas_device_priv_data->sas_target->handle)); |
| 2992 | scsi_internal_device_block(sdev); |
| 2993 | } |
| 2994 | } |
| 2995 | |
| 2996 | |
| 2997 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2998 | * _scsih_block_io_device - set the device state to SDEV_BLOCK |
| 2999 | * @ioc: per adapter object |
| 3000 | * @handle: device handle |
| 3001 | * |
| 3002 | * During device pull we need to appropiately set the sdev state. |
| 3003 | */ |
| 3004 | static void |
| 3005 | _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3006 | { |
| 3007 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 3008 | struct scsi_device *sdev; |
| 3009 | |
| 3010 | shost_for_each_device(sdev, ioc->shost) { |
| 3011 | sas_device_priv_data = sdev->hostdata; |
| 3012 | if (!sas_device_priv_data) |
| 3013 | continue; |
| 3014 | if (sas_device_priv_data->block) |
| 3015 | continue; |
| 3016 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 3017 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 3018 | MPT2SAS_INFO_FMT "SDEV_BLOCK: " |
| 3019 | "handle(0x%04x)\n", ioc->name, handle)); |
| 3020 | sas_device_priv_data->block = 1; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 3021 | scsi_internal_device_block(sdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3022 | } |
| 3023 | } |
| 3024 | } |
| 3025 | |
| 3026 | /** |
| 3027 | * _scsih_block_io_to_children_attached_to_ex |
| 3028 | * @ioc: per adapter object |
| 3029 | * @sas_expander: the sas_device object |
| 3030 | * |
| 3031 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 3032 | * attached to this expander. This function called when expander is |
| 3033 | * pulled. |
| 3034 | */ |
| 3035 | static void |
| 3036 | _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc, |
| 3037 | struct _sas_node *sas_expander) |
| 3038 | { |
| 3039 | struct _sas_port *mpt2sas_port; |
| 3040 | struct _sas_device *sas_device; |
| 3041 | struct _sas_node *expander_sibling; |
| 3042 | unsigned long flags; |
| 3043 | |
| 3044 | if (!sas_expander) |
| 3045 | return; |
| 3046 | |
| 3047 | list_for_each_entry(mpt2sas_port, |
| 3048 | &sas_expander->sas_port_list, port_list) { |
| 3049 | if (mpt2sas_port->remote_identify.device_type == |
| 3050 | SAS_END_DEVICE) { |
| 3051 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3052 | sas_device = |
| 3053 | mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 3054 | mpt2sas_port->remote_identify.sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 3055 | if (sas_device) |
| 3056 | set_bit(sas_device->handle, |
| 3057 | ioc->blocking_handles); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3058 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3059 | } |
| 3060 | } |
| 3061 | |
| 3062 | list_for_each_entry(mpt2sas_port, |
| 3063 | &sas_expander->sas_port_list, port_list) { |
| 3064 | |
| 3065 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 3066 | SAS_EDGE_EXPANDER_DEVICE || |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3067 | mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 3068 | SAS_FANOUT_EXPANDER_DEVICE) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3069 | expander_sibling = |
| 3070 | mpt2sas_scsih_expander_find_by_sas_address( |
| 3071 | ioc, mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3072 | _scsih_block_io_to_children_attached_to_ex(ioc, |
| 3073 | expander_sibling); |
| 3074 | } |
| 3075 | } |
| 3076 | } |
| 3077 | |
| 3078 | /** |
| 3079 | * _scsih_block_io_to_children_attached_directly |
| 3080 | * @ioc: per adapter object |
| 3081 | * @event_data: topology change event data |
| 3082 | * |
| 3083 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 3084 | * direct attached during device pull. |
| 3085 | */ |
| 3086 | static void |
| 3087 | _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc, |
| 3088 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3089 | { |
| 3090 | int i; |
| 3091 | u16 handle; |
| 3092 | u16 reason_code; |
| 3093 | u8 phy_number; |
| 3094 | |
| 3095 | for (i = 0; i < event_data->NumEntries; i++) { |
| 3096 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3097 | if (!handle) |
| 3098 | continue; |
| 3099 | phy_number = event_data->StartPhyNum + i; |
| 3100 | reason_code = event_data->PHY[i].PhyStatus & |
| 3101 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3102 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) |
| 3103 | _scsih_block_io_device(ioc, handle); |
| 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3108 | * _scsih_tm_tr_send - send task management request |
| 3109 | * @ioc: per adapter object |
| 3110 | * @handle: device handle |
| 3111 | * Context: interrupt time. |
| 3112 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3113 | * This code is to initiate the device removal handshake protocol |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3114 | * with controller firmware. This function will issue target reset |
| 3115 | * using high priority request queue. It will send a sas iounit |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3116 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3117 | * |
| 3118 | * This is designed to send muliple task management request at the same |
| 3119 | * time to the fifo. If the fifo is full, we will append the request, |
| 3120 | * and process it in a future completion. |
| 3121 | */ |
| 3122 | static void |
| 3123 | _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3124 | { |
| 3125 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3126 | u16 smid; |
| 3127 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3128 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; |
| 3129 | u64 sas_address = 0; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3130 | unsigned long flags; |
| 3131 | struct _tr_list *delayed_tr; |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3132 | u32 ioc_state; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3133 | |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3134 | if (ioc->remove_host) { |
| 3135 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been " |
| 3136 | "removed: handle(0x%04x)\n", __func__, ioc->name, handle)); |
| 3137 | return; |
| 3138 | } else if (ioc->pci_error_recovery) { |
| 3139 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci " |
| 3140 | "error recovery: handle(0x%04x)\n", __func__, ioc->name, |
| 3141 | handle)); |
| 3142 | return; |
| 3143 | } |
| 3144 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 3145 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 3146 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not " |
| 3147 | "operational: handle(0x%04x)\n", __func__, ioc->name, |
| 3148 | handle)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3149 | return; |
| 3150 | } |
| 3151 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3152 | /* if PD, then return */ |
| 3153 | if (test_bit(handle, ioc->pd_handles)) |
| 3154 | return; |
| 3155 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3156 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3157 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3158 | if (sas_device && sas_device->starget && |
| 3159 | sas_device->starget->hostdata) { |
| 3160 | sas_target_priv_data = sas_device->starget->hostdata; |
| 3161 | sas_target_priv_data->deleted = 1; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3162 | sas_address = sas_device->sas_address; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3163 | } |
| 3164 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3165 | |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3166 | if (sas_target_priv_data) { |
| 3167 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: " |
| 3168 | "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle, |
| 3169 | (unsigned long long)sas_address)); |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 3170 | _scsih_ublock_io_device(ioc, sas_address); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 3171 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3172 | } |
| 3173 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3174 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); |
| 3175 | if (!smid) { |
| 3176 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3177 | if (!delayed_tr) |
| 3178 | return; |
| 3179 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3180 | delayed_tr->handle = handle; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3181 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 3182 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3183 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 3184 | ioc->name, handle)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3185 | return; |
| 3186 | } |
| 3187 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3188 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " |
| 3189 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, |
| 3190 | ioc->tm_tr_cb_idx)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3191 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3192 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 3193 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3194 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3195 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3196 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
| 3197 | } |
| 3198 | |
| 3199 | |
| 3200 | |
| 3201 | /** |
| 3202 | * _scsih_sas_control_complete - completion routine |
| 3203 | * @ioc: per adapter object |
| 3204 | * @smid: system request message index |
| 3205 | * @msix_index: MSIX table index supplied by the OS |
| 3206 | * @reply: reply message frame(lower 32bit addr) |
| 3207 | * Context: interrupt time. |
| 3208 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3209 | * This is the sas iounit control completion routine. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3210 | * 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] | 3211 | * handshake protocol with controller firmware. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3212 | * |
| 3213 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3214 | * 0 means the mf is freed from this function. |
| 3215 | */ |
| 3216 | static u8 |
| 3217 | _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 3218 | u8 msix_index, u32 reply) |
| 3219 | { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3220 | Mpi2SasIoUnitControlReply_t *mpi_reply = |
| 3221 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3222 | if (likely(mpi_reply)) { |
| 3223 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3224 | "sc_complete:handle(0x%04x), (open) " |
| 3225 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 3226 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, |
| 3227 | le16_to_cpu(mpi_reply->IOCStatus), |
| 3228 | le32_to_cpu(mpi_reply->IOCLogInfo))); |
| 3229 | } else { |
| 3230 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3231 | ioc->name, __FILE__, __LINE__, __func__); |
| 3232 | } |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3233 | return 1; |
| 3234 | } |
| 3235 | |
| 3236 | /** |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3237 | * _scsih_tm_tr_volume_send - send target reset request for volumes |
| 3238 | * @ioc: per adapter object |
| 3239 | * @handle: device handle |
| 3240 | * Context: interrupt time. |
| 3241 | * |
| 3242 | * This is designed to send muliple task management request at the same |
| 3243 | * time to the fifo. If the fifo is full, we will append the request, |
| 3244 | * and process it in a future completion. |
| 3245 | */ |
| 3246 | static void |
| 3247 | _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3248 | { |
| 3249 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 3250 | u16 smid; |
| 3251 | struct _tr_list *delayed_tr; |
| 3252 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3253 | if (ioc->shost_recovery || ioc->remove_host || |
| 3254 | ioc->pci_error_recovery) { |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3255 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3256 | "progress!\n", __func__, ioc->name)); |
| 3257 | return; |
| 3258 | } |
| 3259 | |
| 3260 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); |
| 3261 | if (!smid) { |
| 3262 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3263 | if (!delayed_tr) |
| 3264 | return; |
| 3265 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3266 | delayed_tr->handle = handle; |
| 3267 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); |
| 3268 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3269 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 3270 | ioc->name, handle)); |
| 3271 | return; |
| 3272 | } |
| 3273 | |
| 3274 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " |
| 3275 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, |
| 3276 | ioc->tm_tr_volume_cb_idx)); |
| 3277 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3278 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 3279 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3280 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3281 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
| 3282 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
| 3283 | } |
| 3284 | |
| 3285 | /** |
| 3286 | * _scsih_tm_volume_tr_complete - target reset completion |
| 3287 | * @ioc: per adapter object |
| 3288 | * @smid: system request message index |
| 3289 | * @msix_index: MSIX table index supplied by the OS |
| 3290 | * @reply: reply message frame(lower 32bit addr) |
| 3291 | * Context: interrupt time. |
| 3292 | * |
| 3293 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3294 | * 0 means the mf is freed from this function. |
| 3295 | */ |
| 3296 | static u8 |
| 3297 | _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 3298 | u8 msix_index, u32 reply) |
| 3299 | { |
| 3300 | u16 handle; |
| 3301 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
| 3302 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3303 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 3304 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3305 | if (ioc->shost_recovery || ioc->remove_host || |
| 3306 | ioc->pci_error_recovery) { |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3307 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3308 | "progress!\n", __func__, ioc->name)); |
| 3309 | return 1; |
| 3310 | } |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3311 | if (unlikely(!mpi_reply)) { |
| 3312 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3313 | ioc->name, __FILE__, __LINE__, __func__); |
| 3314 | return 1; |
| 3315 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3316 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3317 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3318 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3319 | dewtprintk(ioc, printk("spurious interrupt: " |
| 3320 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle, |
| 3321 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3322 | return 0; |
| 3323 | } |
| 3324 | |
| 3325 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3326 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3327 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3328 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3329 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3330 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3331 | |
| 3332 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3333 | } |
| 3334 | |
| 3335 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3336 | * _scsih_tm_tr_complete - |
| 3337 | * @ioc: per adapter object |
| 3338 | * @smid: system request message index |
| 3339 | * @msix_index: MSIX table index supplied by the OS |
| 3340 | * @reply: reply message frame(lower 32bit addr) |
| 3341 | * Context: interrupt time. |
| 3342 | * |
| 3343 | * This is the target reset completion routine. |
| 3344 | * 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] | 3345 | * handshake protocol with controller firmware. |
| 3346 | * 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] | 3347 | * |
| 3348 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3349 | * 0 means the mf is freed from this function. |
| 3350 | */ |
| 3351 | static u8 |
| 3352 | _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 3353 | u32 reply) |
| 3354 | { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3355 | u16 handle; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3356 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3357 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3358 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 3359 | Mpi2SasIoUnitControlRequest_t *mpi_request; |
| 3360 | u16 smid_sas_ctrl; |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3361 | u32 ioc_state; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3362 | |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3363 | if (ioc->remove_host) { |
| 3364 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been " |
| 3365 | "removed\n", __func__, ioc->name)); |
| 3366 | return 1; |
| 3367 | } else if (ioc->pci_error_recovery) { |
| 3368 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci " |
| 3369 | "error recovery\n", __func__, ioc->name)); |
| 3370 | return 1; |
| 3371 | } |
| 3372 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 3373 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 3374 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not " |
| 3375 | "operational\n", __func__, ioc->name)); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3376 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3377 | } |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3378 | if (unlikely(!mpi_reply)) { |
| 3379 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3380 | ioc->name, __FILE__, __LINE__, __func__); |
| 3381 | return 1; |
| 3382 | } |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3383 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3384 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3385 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3386 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: " |
| 3387 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle, |
| 3388 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3389 | return 0; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3390 | } |
| 3391 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3392 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3393 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3394 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3395 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3396 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3397 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3398 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3399 | smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); |
| 3400 | if (!smid_sas_ctrl) { |
| 3401 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 3402 | ioc->name, __func__); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3403 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3404 | } |
| 3405 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3406 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), " |
| 3407 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl, |
| 3408 | ioc->tm_sas_control_cb_idx)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3409 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl); |
| 3410 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); |
| 3411 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; |
| 3412 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3413 | mpi_request->DevHandle = mpi_request_tm->DevHandle; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3414 | mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3415 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3416 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3417 | } |
| 3418 | |
| 3419 | /** |
| 3420 | * _scsih_check_for_pending_tm - check for pending task management |
| 3421 | * @ioc: per adapter object |
| 3422 | * @smid: system request message index |
| 3423 | * |
| 3424 | * This will check delayed target reset list, and feed the |
| 3425 | * next reqeust. |
| 3426 | * |
| 3427 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3428 | * 0 means the mf is freed from this function. |
| 3429 | */ |
| 3430 | static u8 |
| 3431 | _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 3432 | { |
| 3433 | struct _tr_list *delayed_tr; |
| 3434 | |
| 3435 | if (!list_empty(&ioc->delayed_tr_volume_list)) { |
| 3436 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, |
| 3437 | struct _tr_list, list); |
| 3438 | mpt2sas_base_free_smid(ioc, smid); |
| 3439 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); |
| 3440 | list_del(&delayed_tr->list); |
| 3441 | kfree(delayed_tr); |
| 3442 | return 0; |
| 3443 | } |
| 3444 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3445 | if (!list_empty(&ioc->delayed_tr_list)) { |
| 3446 | delayed_tr = list_entry(ioc->delayed_tr_list.next, |
| 3447 | struct _tr_list, list); |
| 3448 | mpt2sas_base_free_smid(ioc, smid); |
| 3449 | _scsih_tm_tr_send(ioc, delayed_tr->handle); |
| 3450 | list_del(&delayed_tr->list); |
| 3451 | kfree(delayed_tr); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3452 | return 0; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3453 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3454 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3455 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3459 | * _scsih_check_topo_delete_events - sanity check on topo events |
| 3460 | * @ioc: per adapter object |
| 3461 | * @event_data: the event data payload |
| 3462 | * |
| 3463 | * This routine added to better handle cable breaker. |
| 3464 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3465 | * This handles the case where driver receives multiple expander |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3466 | * add and delete events in a single shot. When there is a delete event |
| 3467 | * the routine will void any pending add events waiting in the event queue. |
| 3468 | * |
| 3469 | * Return nothing. |
| 3470 | */ |
| 3471 | static void |
| 3472 | _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 3473 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3474 | { |
| 3475 | struct fw_event_work *fw_event; |
| 3476 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; |
| 3477 | u16 expander_handle; |
| 3478 | struct _sas_node *sas_expander; |
| 3479 | unsigned long flags; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3480 | int i, reason_code; |
| 3481 | u16 handle; |
| 3482 | |
| 3483 | for (i = 0 ; i < event_data->NumEntries; i++) { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3484 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3485 | if (!handle) |
| 3486 | continue; |
| 3487 | reason_code = event_data->PHY[i].PhyStatus & |
| 3488 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3489 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) |
| 3490 | _scsih_tm_tr_send(ioc, handle); |
| 3491 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3492 | |
| 3493 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 3494 | if (expander_handle < ioc->sas_hba.num_phys) { |
| 3495 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3496 | return; |
| 3497 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 3498 | if (event_data->ExpStatus == |
| 3499 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { |
| 3500 | /* put expander attached devices into blocking state */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3501 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 3502 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 3503 | expander_handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3504 | _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 3505 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 3506 | do { |
| 3507 | handle = find_first_bit(ioc->blocking_handles, |
| 3508 | ioc->facts.MaxDevHandle); |
| 3509 | if (handle < ioc->facts.MaxDevHandle) |
| 3510 | _scsih_block_io_device(ioc, handle); |
| 3511 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3512 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) |
| 3513 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3514 | |
| 3515 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) |
| 3516 | return; |
| 3517 | |
| 3518 | /* mark ignore flag for pending events */ |
| 3519 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 3520 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { |
| 3521 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || |
| 3522 | fw_event->ignore) |
| 3523 | continue; |
| 3524 | local_event_data = fw_event->event_data; |
| 3525 | if (local_event_data->ExpStatus == |
| 3526 | MPI2_EVENT_SAS_TOPO_ES_ADDED || |
| 3527 | local_event_data->ExpStatus == |
| 3528 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { |
| 3529 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == |
| 3530 | expander_handle) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 3531 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3532 | "setting ignoring flag\n", ioc->name)); |
| 3533 | fw_event->ignore = 1; |
| 3534 | } |
| 3535 | } |
| 3536 | } |
| 3537 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 3538 | } |
| 3539 | |
| 3540 | /** |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3541 | * _scsih_set_volume_delete_flag - setting volume delete flag |
| 3542 | * @ioc: per adapter object |
| 3543 | * @handle: device handle |
| 3544 | * |
| 3545 | * This |
| 3546 | * Return nothing. |
| 3547 | */ |
| 3548 | static void |
| 3549 | _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3550 | { |
| 3551 | struct _raid_device *raid_device; |
| 3552 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 3553 | unsigned long flags; |
| 3554 | |
| 3555 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 3556 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 3557 | if (raid_device && raid_device->starget && |
| 3558 | raid_device->starget->hostdata) { |
| 3559 | sas_target_priv_data = |
| 3560 | raid_device->starget->hostdata; |
| 3561 | sas_target_priv_data->deleted = 1; |
| 3562 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3563 | "setting delete flag: handle(0x%04x), " |
| 3564 | "wwid(0x%016llx)\n", ioc->name, handle, |
| 3565 | (unsigned long long) raid_device->wwid)); |
| 3566 | } |
| 3567 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 3568 | } |
| 3569 | |
| 3570 | /** |
| 3571 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume |
| 3572 | * @handle: input handle |
| 3573 | * @a: handle for volume a |
| 3574 | * @b: handle for volume b |
| 3575 | * |
| 3576 | * IR firmware only supports two raid volumes. The purpose of this |
| 3577 | * routine is to set the volume handle in either a or b. When the given |
| 3578 | * input handle is non-zero, or when a and b have not been set before. |
| 3579 | */ |
| 3580 | static void |
| 3581 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) |
| 3582 | { |
| 3583 | if (!handle || handle == *a || handle == *b) |
| 3584 | return; |
| 3585 | if (!*a) |
| 3586 | *a = handle; |
| 3587 | else if (!*b) |
| 3588 | *b = handle; |
| 3589 | } |
| 3590 | |
| 3591 | /** |
| 3592 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events |
| 3593 | * @ioc: per adapter object |
| 3594 | * @event_data: the event data payload |
| 3595 | * Context: interrupt time. |
| 3596 | * |
| 3597 | * This routine will send target reset to volume, followed by target |
| 3598 | * resets to the PDs. This is called when a PD has been removed, or |
| 3599 | * volume has been deleted or removed. When the target reset is sent |
| 3600 | * to volume, the PD target resets need to be queued to start upon |
| 3601 | * completion of the volume target reset. |
| 3602 | * |
| 3603 | * Return nothing. |
| 3604 | */ |
| 3605 | static void |
| 3606 | _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc, |
| 3607 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 3608 | { |
| 3609 | Mpi2EventIrConfigElement_t *element; |
| 3610 | int i; |
| 3611 | u16 handle, volume_handle, a, b; |
| 3612 | struct _tr_list *delayed_tr; |
| 3613 | |
| 3614 | a = 0; |
| 3615 | b = 0; |
| 3616 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3617 | if (ioc->is_warpdrive) |
| 3618 | return; |
| 3619 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3620 | /* Volume Resets for Deleted or Removed */ |
| 3621 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3622 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3623 | if (element->ReasonCode == |
| 3624 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || |
| 3625 | element->ReasonCode == |
| 3626 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { |
| 3627 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3628 | _scsih_set_volume_delete_flag(ioc, volume_handle); |
| 3629 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3630 | } |
| 3631 | } |
| 3632 | |
| 3633 | /* Volume Resets for UNHIDE events */ |
| 3634 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3635 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3636 | if (le32_to_cpu(event_data->Flags) & |
| 3637 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) |
| 3638 | continue; |
| 3639 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { |
| 3640 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3641 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3642 | } |
| 3643 | } |
| 3644 | |
| 3645 | if (a) |
| 3646 | _scsih_tm_tr_volume_send(ioc, a); |
| 3647 | if (b) |
| 3648 | _scsih_tm_tr_volume_send(ioc, b); |
| 3649 | |
| 3650 | /* PD target resets */ |
| 3651 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3652 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3653 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) |
| 3654 | continue; |
| 3655 | handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 3656 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3657 | clear_bit(handle, ioc->pd_handles); |
| 3658 | if (!volume_handle) |
| 3659 | _scsih_tm_tr_send(ioc, handle); |
| 3660 | else if (volume_handle == a || volume_handle == b) { |
| 3661 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3662 | BUG_ON(!delayed_tr); |
| 3663 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3664 | delayed_tr->handle = handle; |
| 3665 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 3666 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3667 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, |
| 3668 | handle)); |
| 3669 | } else |
| 3670 | _scsih_tm_tr_send(ioc, handle); |
| 3671 | } |
| 3672 | } |
| 3673 | |
| 3674 | |
| 3675 | /** |
| 3676 | * _scsih_check_volume_delete_events - set delete flag for volumes |
| 3677 | * @ioc: per adapter object |
| 3678 | * @event_data: the event data payload |
| 3679 | * Context: interrupt time. |
| 3680 | * |
| 3681 | * This will handle the case when the cable connected to entire volume is |
| 3682 | * pulled. We will take care of setting the deleted flag so normal IO will |
| 3683 | * not be sent. |
| 3684 | * |
| 3685 | * Return nothing. |
| 3686 | */ |
| 3687 | static void |
| 3688 | _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 3689 | Mpi2EventDataIrVolume_t *event_data) |
| 3690 | { |
| 3691 | u32 state; |
| 3692 | |
| 3693 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 3694 | return; |
| 3695 | state = le32_to_cpu(event_data->NewValue); |
| 3696 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == |
| 3697 | MPI2_RAID_VOL_STATE_FAILED) |
| 3698 | _scsih_set_volume_delete_flag(ioc, |
| 3699 | le16_to_cpu(event_data->VolDevHandle)); |
| 3700 | } |
| 3701 | |
| 3702 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3703 | * _scsih_flush_running_cmds - completing outstanding commands. |
| 3704 | * @ioc: per adapter object |
| 3705 | * |
| 3706 | * The flushing out of all pending scmd commands following host reset, |
| 3707 | * where all IO is dropped to the floor. |
| 3708 | * |
| 3709 | * Return nothing. |
| 3710 | */ |
| 3711 | static void |
| 3712 | _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc) |
| 3713 | { |
| 3714 | struct scsi_cmnd *scmd; |
| 3715 | u16 smid; |
| 3716 | u16 count = 0; |
| 3717 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3718 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 3719 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3720 | if (!scmd) |
| 3721 | continue; |
| 3722 | count++; |
| 3723 | mpt2sas_base_free_smid(ioc, smid); |
| 3724 | scsi_dma_unmap(scmd); |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3725 | if (ioc->pci_error_recovery) |
| 3726 | scmd->result = DID_NO_CONNECT << 16; |
| 3727 | else |
| 3728 | scmd->result = DID_RESET << 16; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3729 | scmd->scsi_done(scmd); |
| 3730 | } |
| 3731 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n", |
| 3732 | ioc->name, count)); |
| 3733 | } |
| 3734 | |
| 3735 | /** |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3736 | * _scsih_setup_eedp - setup MPI request for EEDP transfer |
| 3737 | * @scmd: pointer to scsi command object |
| 3738 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3739 | * |
| 3740 | * Supporting protection 1 and 3. |
| 3741 | * |
| 3742 | * Returns nothing |
| 3743 | */ |
| 3744 | static void |
| 3745 | _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request) |
| 3746 | { |
| 3747 | u16 eedp_flags; |
| 3748 | unsigned char prot_op = scsi_get_prot_op(scmd); |
| 3749 | unsigned char prot_type = scsi_get_prot_type(scmd); |
| 3750 | |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3751 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3752 | return; |
| 3753 | |
| 3754 | if (prot_op == SCSI_PROT_READ_STRIP) |
| 3755 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; |
| 3756 | else if (prot_op == SCSI_PROT_WRITE_INSERT) |
| 3757 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; |
| 3758 | else |
| 3759 | return; |
| 3760 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3761 | switch (prot_type) { |
| 3762 | case SCSI_PROT_DIF_TYPE1: |
Martin K. Petersen | 756aca7 | 2011-05-18 00:45:22 -0400 | [diff] [blame] | 3763 | case SCSI_PROT_DIF_TYPE2: |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3764 | |
| 3765 | /* |
| 3766 | * enable ref/guard checking |
| 3767 | * auto increment ref tag |
| 3768 | */ |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3769 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3770 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | |
| 3771 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
| 3772 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = |
| 3773 | cpu_to_be32(scsi_get_lba(scmd)); |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3774 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3775 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3776 | case SCSI_PROT_DIF_TYPE3: |
| 3777 | |
| 3778 | /* |
| 3779 | * enable guard checking |
| 3780 | */ |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3781 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3782 | break; |
| 3783 | } |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3784 | mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size); |
| 3785 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3786 | } |
| 3787 | |
| 3788 | /** |
| 3789 | * _scsih_eedp_error_handling - return sense code for EEDP errors |
| 3790 | * @scmd: pointer to scsi command object |
| 3791 | * @ioc_status: ioc status |
| 3792 | * |
| 3793 | * Returns nothing |
| 3794 | */ |
| 3795 | static void |
| 3796 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) |
| 3797 | { |
| 3798 | u8 ascq; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3799 | |
| 3800 | switch (ioc_status) { |
| 3801 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 3802 | ascq = 0x01; |
| 3803 | break; |
| 3804 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 3805 | ascq = 0x02; |
| 3806 | break; |
| 3807 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 3808 | ascq = 0x03; |
| 3809 | break; |
| 3810 | default: |
| 3811 | ascq = 0x00; |
| 3812 | break; |
| 3813 | } |
| 3814 | |
Martin K. Petersen | 9b5cd13 | 2012-08-28 14:29:36 -0400 | [diff] [blame] | 3815 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq); |
| 3816 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3817 | SAM_STAT_CHECK_CONDITION; |
| 3818 | } |
| 3819 | |
| 3820 | /** |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3821 | * _scsih_scsi_direct_io_get - returns direct io flag |
| 3822 | * @ioc: per adapter object |
| 3823 | * @smid: system request message index |
| 3824 | * |
| 3825 | * Returns the smid stored scmd pointer. |
| 3826 | */ |
| 3827 | static inline u8 |
| 3828 | _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 3829 | { |
| 3830 | return ioc->scsi_lookup[smid - 1].direct_io; |
| 3831 | } |
| 3832 | |
| 3833 | /** |
| 3834 | * _scsih_scsi_direct_io_set - sets direct io flag |
| 3835 | * @ioc: per adapter object |
| 3836 | * @smid: system request message index |
| 3837 | * @direct_io: Zero or non-zero value to set in the direct_io flag |
| 3838 | * |
| 3839 | * Returns Nothing. |
| 3840 | */ |
| 3841 | static inline void |
| 3842 | _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io) |
| 3843 | { |
| 3844 | ioc->scsi_lookup[smid - 1].direct_io = direct_io; |
| 3845 | } |
| 3846 | |
| 3847 | |
| 3848 | /** |
| 3849 | * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O |
| 3850 | * @ioc: per adapter object |
| 3851 | * @scmd: pointer to scsi command object |
| 3852 | * @raid_device: pointer to raid device data structure |
| 3853 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3854 | * @smid: system request message index |
| 3855 | * |
| 3856 | * Returns nothing |
| 3857 | */ |
| 3858 | static void |
| 3859 | _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 3860 | struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request, |
| 3861 | u16 smid) |
| 3862 | { |
| 3863 | u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size; |
| 3864 | u32 stripe_sz, stripe_exp; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3865 | u8 num_pds, *cdb_ptr, i; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3866 | u8 cdb0 = scmd->cmnd[0]; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3867 | u64 v_llba; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3868 | |
| 3869 | /* |
| 3870 | * Try Direct I/O to RAID memeber disks |
| 3871 | */ |
| 3872 | if (cdb0 == READ_16 || cdb0 == READ_10 || |
| 3873 | cdb0 == WRITE_16 || cdb0 == WRITE_10) { |
| 3874 | cdb_ptr = mpi_request->CDB.CDB32; |
| 3875 | |
| 3876 | if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4] |
| 3877 | | cdb_ptr[5])) { |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3878 | io_size = scsi_bufflen(scmd) >> |
| 3879 | raid_device->block_exponent; |
| 3880 | i = (cdb0 < READ_16) ? 2 : 6; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3881 | /* get virtual lba */ |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3882 | v_lba = be32_to_cpu(*(__be32 *)(&cdb_ptr[i])); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3883 | |
| 3884 | if (((u64)v_lba + (u64)io_size - 1) <= |
| 3885 | (u32)raid_device->max_lba) { |
| 3886 | stripe_sz = raid_device->stripe_sz; |
| 3887 | stripe_exp = raid_device->stripe_exponent; |
| 3888 | stripe_off = v_lba & (stripe_sz - 1); |
| 3889 | |
| 3890 | /* Check whether IO falls within a stripe */ |
| 3891 | if ((stripe_off + io_size) <= stripe_sz) { |
| 3892 | num_pds = raid_device->num_pds; |
| 3893 | p_lba = v_lba >> stripe_exp; |
| 3894 | stripe_unit = p_lba / num_pds; |
| 3895 | column = p_lba % num_pds; |
| 3896 | p_lba = (stripe_unit << stripe_exp) + |
| 3897 | stripe_off; |
| 3898 | mpi_request->DevHandle = |
| 3899 | cpu_to_le16(raid_device-> |
| 3900 | pd_handle[column]); |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3901 | (*(__be32 *)(&cdb_ptr[i])) = |
| 3902 | cpu_to_be32(p_lba); |
| 3903 | /* |
| 3904 | * WD: To indicate this I/O is directI/O |
| 3905 | */ |
| 3906 | _scsih_scsi_direct_io_set(ioc, smid, 1); |
| 3907 | } |
| 3908 | } |
| 3909 | } else { |
| 3910 | io_size = scsi_bufflen(scmd) >> |
| 3911 | raid_device->block_exponent; |
| 3912 | /* get virtual lba */ |
| 3913 | v_llba = be64_to_cpu(*(__be64 *)(&cdb_ptr[2])); |
| 3914 | |
| 3915 | if ((v_llba + (u64)io_size - 1) <= |
| 3916 | raid_device->max_lba) { |
| 3917 | stripe_sz = raid_device->stripe_sz; |
| 3918 | stripe_exp = raid_device->stripe_exponent; |
| 3919 | stripe_off = (u32) (v_llba & (stripe_sz - 1)); |
| 3920 | |
| 3921 | /* Check whether IO falls within a stripe */ |
| 3922 | if ((stripe_off + io_size) <= stripe_sz) { |
| 3923 | num_pds = raid_device->num_pds; |
| 3924 | p_lba = (u32)(v_llba >> stripe_exp); |
| 3925 | stripe_unit = p_lba / num_pds; |
| 3926 | column = p_lba % num_pds; |
| 3927 | p_lba = (stripe_unit << stripe_exp) + |
| 3928 | stripe_off; |
| 3929 | mpi_request->DevHandle = |
| 3930 | cpu_to_le16(raid_device-> |
| 3931 | pd_handle[column]); |
| 3932 | (*(__be64 *)(&cdb_ptr[2])) = |
| 3933 | cpu_to_be64((u64)p_lba); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3934 | /* |
| 3935 | * WD: To indicate this I/O is directI/O |
| 3936 | */ |
| 3937 | _scsih_scsi_direct_io_set(ioc, smid, 1); |
| 3938 | } |
| 3939 | } |
| 3940 | } |
| 3941 | } |
| 3942 | } |
| 3943 | |
| 3944 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 3945 | * _scsih_qcmd - main scsi request entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3946 | * @scmd: pointer to scsi command object |
| 3947 | * @done: function pointer to be invoked on completion |
| 3948 | * |
| 3949 | * The callback index is set inside `ioc->scsi_io_cb_idx`. |
| 3950 | * |
| 3951 | * Returns 0 on success. If there's a failure, return either: |
| 3952 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or |
| 3953 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full |
| 3954 | */ |
| 3955 | static int |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 3956 | _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3957 | { |
| 3958 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 3959 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 3960 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3961 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3962 | Mpi2SCSIIORequest_t *mpi_request; |
| 3963 | u32 mpi_control; |
| 3964 | u16 smid; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3965 | |
| 3966 | scmd->scsi_done = done; |
| 3967 | sas_device_priv_data = scmd->device->hostdata; |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3968 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3969 | scmd->result = DID_NO_CONNECT << 16; |
| 3970 | scmd->scsi_done(scmd); |
| 3971 | return 0; |
| 3972 | } |
| 3973 | |
Kashyap, Desai | 7821578 | 2011-06-14 10:57:08 +0530 | [diff] [blame] | 3974 | if (ioc->pci_error_recovery || ioc->remove_host) { |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3975 | scmd->result = DID_NO_CONNECT << 16; |
| 3976 | scmd->scsi_done(scmd); |
| 3977 | return 0; |
| 3978 | } |
| 3979 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3980 | sas_target_priv_data = sas_device_priv_data->sas_target; |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3981 | /* invalid device handle */ |
| 3982 | if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3983 | scmd->result = DID_NO_CONNECT << 16; |
| 3984 | scmd->scsi_done(scmd); |
| 3985 | return 0; |
| 3986 | } |
| 3987 | |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3988 | /* host recovery or link resets sent via IOCTLs */ |
| 3989 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3990 | return SCSI_MLQUEUE_HOST_BUSY; |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 3991 | /* device busy with task management */ |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3992 | else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy) |
| 3993 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 3994 | /* device has been deleted */ |
| 3995 | else if (sas_target_priv_data->deleted) { |
| 3996 | scmd->result = DID_NO_CONNECT << 16; |
| 3997 | scmd->scsi_done(scmd); |
| 3998 | return 0; |
| 3999 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4000 | |
| 4001 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) |
| 4002 | mpi_control = MPI2_SCSIIO_CONTROL_READ; |
| 4003 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 4004 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; |
| 4005 | else |
| 4006 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; |
| 4007 | |
| 4008 | /* set tags */ |
| 4009 | if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) { |
| 4010 | if (scmd->device->tagged_supported) { |
| 4011 | if (scmd->device->ordered_tags) |
| 4012 | mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ; |
| 4013 | else |
| 4014 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
| 4015 | } else |
Sreekanth Reddy | 48ba2ef | 2013-02-02 00:58:20 +0530 | [diff] [blame] | 4016 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4017 | } else |
| 4018 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4019 | /* Make sure Device is not raid volume. |
| 4020 | * We do not expose raid functionality to upper layer for warpdrive. |
| 4021 | */ |
| 4022 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 4023 | sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4024 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
| 4025 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 4026 | 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] | 4027 | if (!smid) { |
| 4028 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 4029 | ioc->name, __func__); |
| 4030 | goto out; |
| 4031 | } |
| 4032 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 4033 | memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t)); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4034 | _scsih_setup_eedp(scmd, mpi_request); |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 4035 | if (scmd->cmd_len == 32) |
| 4036 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4037 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 4038 | if (sas_device_priv_data->sas_target->flags & |
| 4039 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 4040 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; |
| 4041 | else |
| 4042 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 4043 | mpi_request->DevHandle = |
| 4044 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 4045 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
| 4046 | mpi_request->Control = cpu_to_le32(mpi_control); |
| 4047 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); |
| 4048 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; |
| 4049 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; |
| 4050 | mpi_request->SenseBufferLowAddress = |
Kashyap, Desai | ec9472c | 2009-09-23 17:34:13 +0530 | [diff] [blame] | 4051 | mpt2sas_base_get_sense_buffer_dma(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4052 | mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4; |
| 4053 | mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI + |
| 4054 | MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4055 | mpi_request->VF_ID = 0; /* TODO */ |
| 4056 | mpi_request->VP_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4057 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
| 4058 | mpi_request->LUN); |
| 4059 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 4060 | |
| 4061 | if (!mpi_request->DataLength) { |
| 4062 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL); |
| 4063 | } else { |
| 4064 | if (_scsih_build_scatter_gather(ioc, scmd, smid)) { |
| 4065 | mpt2sas_base_free_smid(ioc, smid); |
| 4066 | goto out; |
| 4067 | } |
| 4068 | } |
| 4069 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4070 | raid_device = sas_target_priv_data->raid_device; |
| 4071 | if (raid_device && raid_device->direct_io_enabled) |
| 4072 | _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request, |
| 4073 | smid); |
| 4074 | |
Kashyap, Desai | 58287fd | 2010-03-17 16:27:25 +0530 | [diff] [blame] | 4075 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) |
| 4076 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4077 | le16_to_cpu(mpi_request->DevHandle)); |
Kashyap, Desai | 58287fd | 2010-03-17 16:27:25 +0530 | [diff] [blame] | 4078 | else |
| 4079 | mpt2sas_base_put_smid_default(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4080 | return 0; |
| 4081 | |
| 4082 | out: |
| 4083 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4084 | } |
| 4085 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 4086 | static DEF_SCSI_QCMD(_scsih_qcmd) |
| 4087 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4088 | /** |
| 4089 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data |
| 4090 | * @sense_buffer: sense data returned by target |
| 4091 | * @data: normalized skey/asc/ascq |
| 4092 | * |
| 4093 | * Return nothing. |
| 4094 | */ |
| 4095 | static void |
| 4096 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) |
| 4097 | { |
| 4098 | if ((sense_buffer[0] & 0x7F) >= 0x72) { |
| 4099 | /* descriptor format */ |
| 4100 | data->skey = sense_buffer[1] & 0x0F; |
| 4101 | data->asc = sense_buffer[2]; |
| 4102 | data->ascq = sense_buffer[3]; |
| 4103 | } else { |
| 4104 | /* fixed format */ |
| 4105 | data->skey = sense_buffer[2] & 0x0F; |
| 4106 | data->asc = sense_buffer[12]; |
| 4107 | data->ascq = sense_buffer[13]; |
| 4108 | } |
| 4109 | } |
| 4110 | |
| 4111 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4112 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4113 | * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4114 | * @ioc: per adapter object |
| 4115 | * @scmd: pointer to scsi command object |
| 4116 | * @mpi_reply: reply mf payload returned from firmware |
| 4117 | * |
| 4118 | * scsi_status - SCSI Status code returned from target device |
| 4119 | * scsi_state - state info associated with SCSI_IO determined by ioc |
| 4120 | * ioc_status - ioc supplied status info |
| 4121 | * |
| 4122 | * Return nothing. |
| 4123 | */ |
| 4124 | static void |
| 4125 | _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 4126 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) |
| 4127 | { |
| 4128 | u32 response_info; |
| 4129 | u8 *response_bytes; |
| 4130 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & |
| 4131 | MPI2_IOCSTATUS_MASK; |
| 4132 | u8 scsi_state = mpi_reply->SCSIState; |
| 4133 | u8 scsi_status = mpi_reply->SCSIStatus; |
| 4134 | char *desc_ioc_state = NULL; |
| 4135 | char *desc_scsi_status = NULL; |
| 4136 | char *desc_scsi_state = ioc->tmp_string; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4137 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4138 | struct _sas_device *sas_device = NULL; |
| 4139 | unsigned long flags; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4140 | struct scsi_target *starget = scmd->device->sdev_target; |
| 4141 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4142 | char *device_str = NULL; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4143 | |
| 4144 | if (!priv_target) |
| 4145 | return; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4146 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4147 | if (ioc->hide_ir_msg) |
| 4148 | device_str = "WarpDrive"; |
| 4149 | else |
| 4150 | device_str = "volume"; |
| 4151 | |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4152 | if (log_info == 0x31170000) |
| 4153 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4154 | |
| 4155 | switch (ioc_status) { |
| 4156 | case MPI2_IOCSTATUS_SUCCESS: |
| 4157 | desc_ioc_state = "success"; |
| 4158 | break; |
| 4159 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 4160 | desc_ioc_state = "invalid function"; |
| 4161 | break; |
| 4162 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 4163 | desc_ioc_state = "scsi recovered error"; |
| 4164 | break; |
| 4165 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: |
| 4166 | desc_ioc_state = "scsi invalid dev handle"; |
| 4167 | break; |
| 4168 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 4169 | desc_ioc_state = "scsi device not there"; |
| 4170 | break; |
| 4171 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 4172 | desc_ioc_state = "scsi data overrun"; |
| 4173 | break; |
| 4174 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 4175 | desc_ioc_state = "scsi data underrun"; |
| 4176 | break; |
| 4177 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 4178 | desc_ioc_state = "scsi io data error"; |
| 4179 | break; |
| 4180 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 4181 | desc_ioc_state = "scsi protocol error"; |
| 4182 | break; |
| 4183 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 4184 | desc_ioc_state = "scsi task terminated"; |
| 4185 | break; |
| 4186 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 4187 | desc_ioc_state = "scsi residual mismatch"; |
| 4188 | break; |
| 4189 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 4190 | desc_ioc_state = "scsi task mgmt failed"; |
| 4191 | break; |
| 4192 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 4193 | desc_ioc_state = "scsi ioc terminated"; |
| 4194 | break; |
| 4195 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 4196 | desc_ioc_state = "scsi ext terminated"; |
| 4197 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4198 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 4199 | desc_ioc_state = "eedp guard error"; |
| 4200 | break; |
| 4201 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 4202 | desc_ioc_state = "eedp ref tag error"; |
| 4203 | break; |
| 4204 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 4205 | desc_ioc_state = "eedp app tag error"; |
| 4206 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4207 | default: |
| 4208 | desc_ioc_state = "unknown"; |
| 4209 | break; |
| 4210 | } |
| 4211 | |
| 4212 | switch (scsi_status) { |
| 4213 | case MPI2_SCSI_STATUS_GOOD: |
| 4214 | desc_scsi_status = "good"; |
| 4215 | break; |
| 4216 | case MPI2_SCSI_STATUS_CHECK_CONDITION: |
| 4217 | desc_scsi_status = "check condition"; |
| 4218 | break; |
| 4219 | case MPI2_SCSI_STATUS_CONDITION_MET: |
| 4220 | desc_scsi_status = "condition met"; |
| 4221 | break; |
| 4222 | case MPI2_SCSI_STATUS_BUSY: |
| 4223 | desc_scsi_status = "busy"; |
| 4224 | break; |
| 4225 | case MPI2_SCSI_STATUS_INTERMEDIATE: |
| 4226 | desc_scsi_status = "intermediate"; |
| 4227 | break; |
| 4228 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: |
| 4229 | desc_scsi_status = "intermediate condmet"; |
| 4230 | break; |
| 4231 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: |
| 4232 | desc_scsi_status = "reservation conflict"; |
| 4233 | break; |
| 4234 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: |
| 4235 | desc_scsi_status = "command terminated"; |
| 4236 | break; |
| 4237 | case MPI2_SCSI_STATUS_TASK_SET_FULL: |
| 4238 | desc_scsi_status = "task set full"; |
| 4239 | break; |
| 4240 | case MPI2_SCSI_STATUS_ACA_ACTIVE: |
| 4241 | desc_scsi_status = "aca active"; |
| 4242 | break; |
| 4243 | case MPI2_SCSI_STATUS_TASK_ABORTED: |
| 4244 | desc_scsi_status = "task aborted"; |
| 4245 | break; |
| 4246 | default: |
| 4247 | desc_scsi_status = "unknown"; |
| 4248 | break; |
| 4249 | } |
| 4250 | |
| 4251 | desc_scsi_state[0] = '\0'; |
| 4252 | if (!scsi_state) |
| 4253 | desc_scsi_state = " "; |
| 4254 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 4255 | strcat(desc_scsi_state, "response info "); |
| 4256 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4257 | strcat(desc_scsi_state, "state terminated "); |
| 4258 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) |
| 4259 | strcat(desc_scsi_state, "no status "); |
| 4260 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) |
| 4261 | strcat(desc_scsi_state, "autosense failed "); |
| 4262 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) |
| 4263 | strcat(desc_scsi_state, "autosense valid "); |
| 4264 | |
| 4265 | scsi_print_command(scmd); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4266 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4267 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4268 | printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name, |
| 4269 | device_str, (unsigned long long)priv_target->sas_address); |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4270 | } else { |
| 4271 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4272 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 4273 | priv_target->sas_address); |
| 4274 | if (sas_device) { |
| 4275 | printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), " |
| 4276 | "phy(%d)\n", ioc->name, sas_device->sas_address, |
| 4277 | sas_device->phy); |
| 4278 | printk(MPT2SAS_WARN_FMT |
| 4279 | "\tenclosure_logical_id(0x%016llx), slot(%d)\n", |
| 4280 | ioc->name, sas_device->enclosure_logical_id, |
| 4281 | sas_device->slot); |
| 4282 | } |
| 4283 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4284 | } |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4285 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4286 | printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), " |
| 4287 | "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle), |
| 4288 | desc_ioc_state, ioc_status, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4289 | printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), " |
| 4290 | "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow, |
| 4291 | scsi_get_resid(scmd)); |
| 4292 | printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), " |
| 4293 | "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag), |
| 4294 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); |
| 4295 | printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), " |
| 4296 | "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status, |
| 4297 | scsi_status, desc_scsi_state, scsi_state); |
| 4298 | |
| 4299 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4300 | struct sense_info data; |
| 4301 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4302 | printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: " |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 4303 | "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey, |
| 4304 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { |
| 4308 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); |
| 4309 | response_bytes = (u8 *)&response_info; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4310 | _scsih_response_code(ioc, response_bytes[0]); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4311 | } |
| 4312 | } |
| 4313 | #endif |
| 4314 | |
| 4315 | /** |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4316 | * _scsih_turn_on_fault_led - illuminate Fault LED |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4317 | * @ioc: per adapter object |
| 4318 | * @handle: device handle |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4319 | * Context: process |
| 4320 | * |
| 4321 | * Return nothing. |
| 4322 | */ |
| 4323 | static void |
| 4324 | _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4325 | { |
| 4326 | Mpi2SepReply_t mpi_reply; |
| 4327 | Mpi2SepRequest_t mpi_request; |
| 4328 | |
| 4329 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
| 4330 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; |
| 4331 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; |
| 4332 | mpi_request.SlotStatus = |
| 4333 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); |
| 4334 | mpi_request.DevHandle = cpu_to_le16(handle); |
| 4335 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; |
| 4336 | if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply, |
| 4337 | &mpi_request)) != 0) { |
| 4338 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 4339 | __FILE__, __LINE__, __func__); |
| 4340 | return; |
| 4341 | } |
| 4342 | |
| 4343 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { |
| 4344 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: " |
| 4345 | "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name, |
| 4346 | le16_to_cpu(mpi_reply.IOCStatus), |
| 4347 | le32_to_cpu(mpi_reply.IOCLogInfo))); |
| 4348 | return; |
| 4349 | } |
| 4350 | } |
| 4351 | |
| 4352 | /** |
| 4353 | * _scsih_send_event_to_turn_on_fault_led - fire delayed event |
| 4354 | * @ioc: per adapter object |
| 4355 | * @handle: device handle |
| 4356 | * Context: interrupt. |
| 4357 | * |
| 4358 | * Return nothing. |
| 4359 | */ |
| 4360 | static void |
| 4361 | _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4362 | { |
| 4363 | struct fw_event_work *fw_event; |
| 4364 | |
| 4365 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 4366 | if (!fw_event) |
| 4367 | return; |
| 4368 | fw_event->event = MPT2SAS_TURN_ON_FAULT_LED; |
| 4369 | fw_event->device_handle = handle; |
| 4370 | fw_event->ioc = ioc; |
| 4371 | _scsih_fw_event_add(ioc, fw_event); |
| 4372 | } |
| 4373 | |
| 4374 | /** |
| 4375 | * _scsih_smart_predicted_fault - process smart errors |
| 4376 | * @ioc: per adapter object |
| 4377 | * @handle: device handle |
| 4378 | * Context: interrupt. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4379 | * |
| 4380 | * Return nothing. |
| 4381 | */ |
| 4382 | static void |
| 4383 | _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4384 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4385 | struct scsi_target *starget; |
| 4386 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 4387 | Mpi2EventNotificationReply_t *event_reply; |
| 4388 | Mpi2EventDataSasDeviceStatusChange_t *event_data; |
| 4389 | struct _sas_device *sas_device; |
| 4390 | ssize_t sz; |
| 4391 | unsigned long flags; |
| 4392 | |
| 4393 | /* only handle non-raid devices */ |
| 4394 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4395 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 4396 | if (!sas_device) { |
| 4397 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4398 | return; |
| 4399 | } |
| 4400 | starget = sas_device->starget; |
| 4401 | sas_target_priv_data = starget->hostdata; |
| 4402 | |
| 4403 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || |
| 4404 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) { |
| 4405 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4406 | return; |
| 4407 | } |
| 4408 | starget_printk(KERN_WARNING, starget, "predicted fault\n"); |
| 4409 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4410 | |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4411 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) |
| 4412 | _scsih_send_event_to_turn_on_fault_led(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4413 | |
| 4414 | /* insert into event log */ |
| 4415 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + |
| 4416 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); |
Anton Blanchard | f6a290b4 | 2011-11-07 22:05:21 +1100 | [diff] [blame] | 4417 | event_reply = kzalloc(sz, GFP_ATOMIC); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4418 | if (!event_reply) { |
| 4419 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4420 | ioc->name, __FILE__, __LINE__, __func__); |
| 4421 | return; |
| 4422 | } |
| 4423 | |
| 4424 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; |
| 4425 | event_reply->Event = |
| 4426 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); |
| 4427 | event_reply->MsgLength = sz/4; |
| 4428 | event_reply->EventDataLength = |
| 4429 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); |
| 4430 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) |
| 4431 | event_reply->EventData; |
| 4432 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; |
| 4433 | event_data->ASC = 0x5D; |
| 4434 | event_data->DevHandle = cpu_to_le16(handle); |
| 4435 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); |
| 4436 | mpt2sas_ctl_add_to_event_log(ioc, event_reply); |
| 4437 | kfree(event_reply); |
| 4438 | } |
| 4439 | |
| 4440 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 4441 | * _scsih_io_done - scsi request callback |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4442 | * @ioc: per adapter object |
| 4443 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4444 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4445 | * @reply: reply message frame(lower 32bit addr) |
| 4446 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4447 | * Callback handler when using _scsih_qcmd. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4448 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4449 | * Return 1 meaning mf should be freed from _base_interrupt |
| 4450 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4451 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4452 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4453 | _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] | 4454 | { |
| 4455 | Mpi2SCSIIORequest_t *mpi_request; |
| 4456 | Mpi2SCSIIOReply_t *mpi_reply; |
| 4457 | struct scsi_cmnd *scmd; |
| 4458 | u16 ioc_status; |
| 4459 | u32 xfer_cnt; |
| 4460 | u8 scsi_state; |
| 4461 | u8 scsi_status; |
| 4462 | u32 log_info; |
| 4463 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4464 | u32 response_code = 0; |
Kashyap, Desai | 82a4525 | 2011-07-05 12:40:23 +0530 | [diff] [blame] | 4465 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4466 | |
| 4467 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 4468 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4469 | if (scmd == NULL) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4470 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4471 | |
| 4472 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 4473 | |
| 4474 | if (mpi_reply == NULL) { |
| 4475 | scmd->result = DID_OK << 16; |
| 4476 | goto out; |
| 4477 | } |
| 4478 | |
| 4479 | sas_device_priv_data = scmd->device->hostdata; |
| 4480 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
| 4481 | sas_device_priv_data->sas_target->deleted) { |
| 4482 | scmd->result = DID_NO_CONNECT << 16; |
| 4483 | goto out; |
| 4484 | } |
nagalakshmi.nandigama@lsi.com | 4da7af9 | 2011-12-01 07:53:02 +0530 | [diff] [blame] | 4485 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4486 | /* |
| 4487 | * WARPDRIVE: If direct_io is set then it is directIO, |
| 4488 | * the failed direct I/O should be redirected to volume |
| 4489 | */ |
nagalakshmi.nandigama@lsi.com | 4da7af9 | 2011-12-01 07:53:02 +0530 | [diff] [blame] | 4490 | if (_scsih_scsi_direct_io_get(ioc, smid) && |
| 4491 | ((ioc_status & MPI2_IOCSTATUS_MASK) |
| 4492 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { |
Kashyap, Desai | 82a4525 | 2011-07-05 12:40:23 +0530 | [diff] [blame] | 4493 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 4494 | ioc->scsi_lookup[smid - 1].scmd = scmd; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4495 | _scsih_scsi_direct_io_set(ioc, smid, 0); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 4496 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4497 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 4498 | mpi_request->DevHandle = |
| 4499 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 4500 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
| 4501 | sas_device_priv_data->sas_target->handle); |
| 4502 | return 0; |
| 4503 | } |
| 4504 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4505 | |
| 4506 | /* turning off TLR */ |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4507 | scsi_state = mpi_reply->SCSIState; |
| 4508 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 4509 | response_code = |
| 4510 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4511 | if (!sas_device_priv_data->tlr_snoop_check) { |
| 4512 | sas_device_priv_data->tlr_snoop_check++; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4513 | /* Make sure Device is not raid volume. |
| 4514 | * We do not expose raid functionality to upper layer for warpdrive. |
| 4515 | */ |
| 4516 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && |
Kashyap, Desai | 3ed2152 | 2010-02-17 16:08:36 +0530 | [diff] [blame] | 4517 | sas_is_tlr_enabled(scmd->device) && |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 4518 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { |
| 4519 | sas_disable_tlr(scmd->device); |
| 4520 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); |
| 4521 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4522 | } |
| 4523 | |
| 4524 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); |
| 4525 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4526 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) |
| 4527 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
| 4528 | else |
| 4529 | log_info = 0; |
| 4530 | ioc_status &= MPI2_IOCSTATUS_MASK; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4531 | scsi_status = mpi_reply->SCSIStatus; |
| 4532 | |
| 4533 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && |
| 4534 | (scsi_status == MPI2_SCSI_STATUS_BUSY || |
| 4535 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || |
| 4536 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { |
| 4537 | ioc_status = MPI2_IOCSTATUS_SUCCESS; |
| 4538 | } |
| 4539 | |
| 4540 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4541 | struct sense_info data; |
| 4542 | const void *sense_data = mpt2sas_base_get_sense_buffer(ioc, |
| 4543 | smid); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 4544 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4545 | le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 4546 | memcpy(scmd->sense_buffer, sense_data, sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4547 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4548 | /* failure prediction threshold exceeded */ |
| 4549 | if (data.asc == 0x5D) |
| 4550 | _scsih_smart_predicted_fault(ioc, |
| 4551 | le16_to_cpu(mpi_reply->DevHandle)); |
| 4552 | } |
| 4553 | |
| 4554 | switch (ioc_status) { |
| 4555 | case MPI2_IOCSTATUS_BUSY: |
| 4556 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: |
| 4557 | scmd->result = SAM_STAT_BUSY; |
| 4558 | break; |
| 4559 | |
| 4560 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 4561 | scmd->result = DID_NO_CONNECT << 16; |
| 4562 | break; |
| 4563 | |
| 4564 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 4565 | if (sas_device_priv_data->block) { |
Kashyap, Desai | e4e7c7e | 2009-09-23 17:33:14 +0530 | [diff] [blame] | 4566 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; |
| 4567 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4568 | } |
nagalakshmi.nandigama@lsi.com | 3ade1ca | 2011-12-01 07:42:40 +0530 | [diff] [blame] | 4569 | scmd->result = DID_SOFT_ERROR << 16; |
| 4570 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4571 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 4572 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 4573 | scmd->result = DID_RESET << 16; |
| 4574 | break; |
| 4575 | |
| 4576 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 4577 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) |
| 4578 | scmd->result = DID_SOFT_ERROR << 16; |
| 4579 | else |
| 4580 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4581 | break; |
| 4582 | |
| 4583 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 4584 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4585 | |
| 4586 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) |
| 4587 | break; |
| 4588 | |
| 4589 | if (xfer_cnt < scmd->underflow) { |
| 4590 | if (scsi_status == SAM_STAT_BUSY) |
| 4591 | scmd->result = SAM_STAT_BUSY; |
| 4592 | else |
| 4593 | scmd->result = DID_SOFT_ERROR << 16; |
| 4594 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4595 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) |
| 4596 | scmd->result = DID_SOFT_ERROR << 16; |
| 4597 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4598 | scmd->result = DID_RESET << 16; |
| 4599 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { |
| 4600 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; |
| 4601 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; |
| 4602 | scmd->result = (DRIVER_SENSE << 24) | |
| 4603 | SAM_STAT_CHECK_CONDITION; |
| 4604 | scmd->sense_buffer[0] = 0x70; |
| 4605 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; |
| 4606 | scmd->sense_buffer[12] = 0x20; |
| 4607 | scmd->sense_buffer[13] = 0; |
| 4608 | } |
| 4609 | break; |
| 4610 | |
| 4611 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 4612 | scsi_set_resid(scmd, 0); |
| 4613 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 4614 | case MPI2_IOCSTATUS_SUCCESS: |
| 4615 | scmd->result = (DID_OK << 16) | scsi_status; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4616 | if (response_code == |
| 4617 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || |
| 4618 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4619 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4620 | scmd->result = DID_SOFT_ERROR << 16; |
| 4621 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4622 | scmd->result = DID_RESET << 16; |
| 4623 | break; |
| 4624 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4625 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 4626 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 4627 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 4628 | _scsih_eedp_error_handling(scmd, ioc_status); |
| 4629 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4630 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 4631 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 4632 | case MPI2_IOCSTATUS_INVALID_SGL: |
| 4633 | case MPI2_IOCSTATUS_INTERNAL_ERROR: |
| 4634 | case MPI2_IOCSTATUS_INVALID_FIELD: |
| 4635 | case MPI2_IOCSTATUS_INVALID_STATE: |
| 4636 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 4637 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 4638 | default: |
| 4639 | scmd->result = DID_SOFT_ERROR << 16; |
| 4640 | break; |
| 4641 | |
| 4642 | } |
| 4643 | |
| 4644 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4645 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
| 4646 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); |
| 4647 | #endif |
| 4648 | |
| 4649 | out: |
| 4650 | scsi_dma_unmap(scmd); |
| 4651 | scmd->scsi_done(scmd); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4652 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4656 | * _scsih_sas_host_refresh - refreshing sas host object contents |
| 4657 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4658 | * Context: user |
| 4659 | * |
| 4660 | * During port enable, fw will send topology events for every device. Its |
| 4661 | * possible that the handles may change from the previous setting, so this |
| 4662 | * code keeping handles updating if changed. |
| 4663 | * |
| 4664 | * Return nothing. |
| 4665 | */ |
| 4666 | static void |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4667 | _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4668 | { |
| 4669 | u16 sz; |
| 4670 | u16 ioc_status; |
| 4671 | int i; |
| 4672 | Mpi2ConfigReply_t mpi_reply; |
| 4673 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4674 | u16 attached_handle; |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4675 | u8 link_rate; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4676 | |
| 4677 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 4678 | "updating handles for sas_host(0x%016llx)\n", |
| 4679 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); |
| 4680 | |
| 4681 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys |
| 4682 | * sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4683 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4684 | if (!sas_iounit_pg0) { |
| 4685 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4686 | ioc->name, __FILE__, __LINE__, __func__); |
| 4687 | return; |
| 4688 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4689 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4690 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4691 | sas_iounit_pg0, sz)) != 0) |
| 4692 | goto out; |
| 4693 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 4694 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 4695 | goto out; |
| 4696 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4697 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4698 | if (i == 0) |
| 4699 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4700 | PhyData[0].ControllerDevHandle); |
| 4701 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
| 4702 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. |
| 4703 | AttachedDevHandle); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4704 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 4705 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4706 | mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address, |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4707 | attached_handle, i, link_rate); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4708 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4709 | out: |
| 4710 | kfree(sas_iounit_pg0); |
| 4711 | } |
| 4712 | |
| 4713 | /** |
| 4714 | * _scsih_sas_host_add - create sas host object |
| 4715 | * @ioc: per adapter object |
| 4716 | * |
| 4717 | * Creating host side data object, stored in ioc->sas_hba |
| 4718 | * |
| 4719 | * Return nothing. |
| 4720 | */ |
| 4721 | static void |
| 4722 | _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc) |
| 4723 | { |
| 4724 | int i; |
| 4725 | Mpi2ConfigReply_t mpi_reply; |
| 4726 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
| 4727 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; |
| 4728 | Mpi2SasPhyPage0_t phy_pg0; |
| 4729 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4730 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4731 | u16 ioc_status; |
| 4732 | u16 sz; |
| 4733 | u16 device_missing_delay; |
| 4734 | |
| 4735 | mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys); |
| 4736 | if (!ioc->sas_hba.num_phys) { |
| 4737 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4738 | ioc->name, __FILE__, __LINE__, __func__); |
| 4739 | return; |
| 4740 | } |
| 4741 | |
| 4742 | /* sas_iounit page 0 */ |
| 4743 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4744 | sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4745 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4746 | if (!sas_iounit_pg0) { |
| 4747 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4748 | ioc->name, __FILE__, __LINE__, __func__); |
| 4749 | return; |
| 4750 | } |
| 4751 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4752 | sas_iounit_pg0, sz))) { |
| 4753 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4754 | ioc->name, __FILE__, __LINE__, __func__); |
| 4755 | goto out; |
| 4756 | } |
| 4757 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4758 | MPI2_IOCSTATUS_MASK; |
| 4759 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4760 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4761 | ioc->name, __FILE__, __LINE__, __func__); |
| 4762 | goto out; |
| 4763 | } |
| 4764 | |
| 4765 | /* sas_iounit page 1 */ |
| 4766 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4767 | sizeof(Mpi2SasIOUnit1PhyData_t)); |
| 4768 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); |
| 4769 | if (!sas_iounit_pg1) { |
| 4770 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4771 | ioc->name, __FILE__, __LINE__, __func__); |
| 4772 | goto out; |
| 4773 | } |
| 4774 | if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, |
| 4775 | sas_iounit_pg1, sz))) { |
| 4776 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4777 | ioc->name, __FILE__, __LINE__, __func__); |
| 4778 | goto out; |
| 4779 | } |
| 4780 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4781 | MPI2_IOCSTATUS_MASK; |
| 4782 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4783 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4784 | ioc->name, __FILE__, __LINE__, __func__); |
| 4785 | goto out; |
| 4786 | } |
| 4787 | |
| 4788 | ioc->io_missing_delay = |
| 4789 | le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay); |
| 4790 | device_missing_delay = |
| 4791 | le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay); |
| 4792 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) |
| 4793 | ioc->device_missing_delay = (device_missing_delay & |
| 4794 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; |
| 4795 | else |
| 4796 | ioc->device_missing_delay = device_missing_delay & |
| 4797 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 4798 | |
| 4799 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; |
| 4800 | ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys, |
| 4801 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4802 | if (!ioc->sas_hba.phy) { |
| 4803 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4804 | ioc->name, __FILE__, __LINE__, __func__); |
| 4805 | goto out; |
| 4806 | } |
| 4807 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
| 4808 | if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, |
| 4809 | i))) { |
| 4810 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4811 | ioc->name, __FILE__, __LINE__, __func__); |
| 4812 | goto out; |
| 4813 | } |
| 4814 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4815 | MPI2_IOCSTATUS_MASK; |
| 4816 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4817 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4818 | ioc->name, __FILE__, __LINE__, __func__); |
| 4819 | goto out; |
| 4820 | } |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4821 | |
| 4822 | if (i == 0) |
| 4823 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4824 | PhyData[0].ControllerDevHandle); |
| 4825 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4826 | ioc->sas_hba.phy[i].phy_id = i; |
| 4827 | mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], |
| 4828 | phy_pg0, ioc->sas_hba.parent_dev); |
| 4829 | } |
| 4830 | 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] | 4831 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4832 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4833 | ioc->name, __FILE__, __LINE__, __func__); |
| 4834 | goto out; |
| 4835 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4836 | ioc->sas_hba.enclosure_handle = |
| 4837 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 4838 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 4839 | printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), " |
| 4840 | "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle, |
| 4841 | (unsigned long long) ioc->sas_hba.sas_address, |
| 4842 | ioc->sas_hba.num_phys) ; |
| 4843 | |
| 4844 | if (ioc->sas_hba.enclosure_handle) { |
| 4845 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4846 | &enclosure_pg0, |
| 4847 | MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4848 | ioc->sas_hba.enclosure_handle))) { |
| 4849 | ioc->sas_hba.enclosure_logical_id = |
| 4850 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4851 | } |
| 4852 | } |
| 4853 | |
| 4854 | out: |
| 4855 | kfree(sas_iounit_pg1); |
| 4856 | kfree(sas_iounit_pg0); |
| 4857 | } |
| 4858 | |
| 4859 | /** |
| 4860 | * _scsih_expander_add - creating expander object |
| 4861 | * @ioc: per adapter object |
| 4862 | * @handle: expander handle |
| 4863 | * |
| 4864 | * Creating expander object, stored in ioc->sas_expander_list. |
| 4865 | * |
| 4866 | * Return 0 for success, else error. |
| 4867 | */ |
| 4868 | static int |
| 4869 | _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4870 | { |
| 4871 | struct _sas_node *sas_expander; |
| 4872 | Mpi2ConfigReply_t mpi_reply; |
| 4873 | Mpi2ExpanderPage0_t expander_pg0; |
| 4874 | Mpi2ExpanderPage1_t expander_pg1; |
| 4875 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4876 | u32 ioc_status; |
| 4877 | u16 parent_handle; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 4878 | u64 sas_address, sas_address_parent = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4879 | int i; |
| 4880 | unsigned long flags; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4881 | struct _sas_port *mpt2sas_port = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4882 | int rc = 0; |
| 4883 | |
| 4884 | if (!handle) |
| 4885 | return -1; |
| 4886 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 4887 | if (ioc->shost_recovery || ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 4888 | return -1; |
| 4889 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4890 | if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 4891 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { |
| 4892 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4893 | ioc->name, __FILE__, __LINE__, __func__); |
| 4894 | return -1; |
| 4895 | } |
| 4896 | |
| 4897 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4898 | MPI2_IOCSTATUS_MASK; |
| 4899 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4900 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4901 | ioc->name, __FILE__, __LINE__, __func__); |
| 4902 | return -1; |
| 4903 | } |
| 4904 | |
| 4905 | /* handle out of order topology events */ |
| 4906 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4907 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) |
| 4908 | != 0) { |
| 4909 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4910 | ioc->name, __FILE__, __LINE__, __func__); |
| 4911 | return -1; |
| 4912 | } |
| 4913 | if (sas_address_parent != ioc->sas_hba.sas_address) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4914 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4915 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4916 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4917 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4918 | if (!sas_expander) { |
| 4919 | rc = _scsih_expander_add(ioc, parent_handle); |
| 4920 | if (rc != 0) |
| 4921 | return rc; |
| 4922 | } |
| 4923 | } |
| 4924 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4925 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 4926 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4927 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4928 | sas_address); |
| 4929 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4930 | |
| 4931 | if (sas_expander) |
| 4932 | return 0; |
| 4933 | |
| 4934 | sas_expander = kzalloc(sizeof(struct _sas_node), |
| 4935 | GFP_KERNEL); |
| 4936 | if (!sas_expander) { |
| 4937 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4938 | ioc->name, __FILE__, __LINE__, __func__); |
| 4939 | return -1; |
| 4940 | } |
| 4941 | |
| 4942 | sas_expander->handle = handle; |
| 4943 | sas_expander->num_phys = expander_pg0.NumPhys; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4944 | sas_expander->sas_address_parent = sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4945 | sas_expander->sas_address = sas_address; |
| 4946 | |
| 4947 | printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x)," |
| 4948 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4949 | handle, parent_handle, (unsigned long long) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4950 | sas_expander->sas_address, sas_expander->num_phys); |
| 4951 | |
| 4952 | if (!sas_expander->num_phys) |
| 4953 | goto out_fail; |
| 4954 | sas_expander->phy = kcalloc(sas_expander->num_phys, |
| 4955 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4956 | if (!sas_expander->phy) { |
| 4957 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4958 | ioc->name, __FILE__, __LINE__, __func__); |
| 4959 | rc = -1; |
| 4960 | goto out_fail; |
| 4961 | } |
| 4962 | |
| 4963 | INIT_LIST_HEAD(&sas_expander->sas_port_list); |
| 4964 | mpt2sas_port = mpt2sas_transport_port_add(ioc, handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4965 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4966 | if (!mpt2sas_port) { |
| 4967 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4968 | ioc->name, __FILE__, __LINE__, __func__); |
| 4969 | rc = -1; |
| 4970 | goto out_fail; |
| 4971 | } |
| 4972 | sas_expander->parent_dev = &mpt2sas_port->rphy->dev; |
| 4973 | |
| 4974 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 4975 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 4976 | &expander_pg1, i, handle))) { |
| 4977 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4978 | ioc->name, __FILE__, __LINE__, __func__); |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4979 | rc = -1; |
| 4980 | goto out_fail; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4981 | } |
| 4982 | sas_expander->phy[i].handle = handle; |
| 4983 | sas_expander->phy[i].phy_id = i; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4984 | |
| 4985 | if ((mpt2sas_transport_add_expander_phy(ioc, |
| 4986 | &sas_expander->phy[i], expander_pg1, |
| 4987 | sas_expander->parent_dev))) { |
| 4988 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4989 | ioc->name, __FILE__, __LINE__, __func__); |
| 4990 | rc = -1; |
| 4991 | goto out_fail; |
| 4992 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4993 | } |
| 4994 | |
| 4995 | if (sas_expander->enclosure_handle) { |
| 4996 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4997 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4998 | sas_expander->enclosure_handle))) { |
| 4999 | sas_expander->enclosure_logical_id = |
| 5000 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 5001 | } |
| 5002 | } |
| 5003 | |
| 5004 | _scsih_expander_node_add(ioc, sas_expander); |
| 5005 | return 0; |
| 5006 | |
| 5007 | out_fail: |
| 5008 | |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 5009 | if (mpt2sas_port) |
| 5010 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5011 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5012 | kfree(sas_expander); |
| 5013 | return rc; |
| 5014 | } |
| 5015 | |
| 5016 | /** |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 5017 | * _scsih_done - scsih callback handler. |
| 5018 | * @ioc: per adapter object |
| 5019 | * @smid: system request message index |
| 5020 | * @msix_index: MSIX table index supplied by the OS |
| 5021 | * @reply: reply message frame(lower 32bit addr) |
| 5022 | * |
| 5023 | * Callback handler when sending internal generated message frames. |
| 5024 | * The callback index passed is `ioc->scsih_cb_idx` |
| 5025 | * |
| 5026 | * Return 1 meaning mf should be freed from _base_interrupt |
| 5027 | * 0 means the mf is freed from this function. |
| 5028 | */ |
| 5029 | static u8 |
| 5030 | _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) |
| 5031 | { |
| 5032 | MPI2DefaultReply_t *mpi_reply; |
| 5033 | |
| 5034 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 5035 | if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED) |
| 5036 | return 1; |
| 5037 | if (ioc->scsih_cmds.smid != smid) |
| 5038 | return 1; |
| 5039 | ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE; |
| 5040 | if (mpi_reply) { |
| 5041 | memcpy(ioc->scsih_cmds.reply, mpi_reply, |
| 5042 | mpi_reply->MsgLength*4); |
| 5043 | ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 5044 | } |
| 5045 | ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING; |
| 5046 | complete(&ioc->scsih_cmds.done); |
| 5047 | return 1; |
| 5048 | } |
| 5049 | |
| 5050 | /** |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5051 | * mpt2sas_expander_remove - removing expander object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5052 | * @ioc: per adapter object |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5053 | * @sas_address: expander sas_address |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5054 | * |
| 5055 | * Return nothing. |
| 5056 | */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5057 | void |
| 5058 | mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5059 | { |
| 5060 | struct _sas_node *sas_expander; |
| 5061 | unsigned long flags; |
| 5062 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 5063 | if (ioc->shost_recovery) |
| 5064 | return; |
| 5065 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5066 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5067 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 5068 | sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5069 | if (sas_expander) |
| 5070 | list_del(&sas_expander->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5071 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5072 | if (sas_expander) |
| 5073 | _scsih_expander_node_remove(ioc, sas_expander); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5074 | } |
| 5075 | |
| 5076 | /** |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5077 | * _scsih_check_access_status - check access flags |
| 5078 | * @ioc: per adapter object |
| 5079 | * @sas_address: sas address |
| 5080 | * @handle: sas device handle |
| 5081 | * @access_flags: errors returned during discovery of the device |
| 5082 | * |
| 5083 | * Return 0 for success, else failure |
| 5084 | */ |
| 5085 | static u8 |
| 5086 | _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 5087 | u16 handle, u8 access_status) |
| 5088 | { |
| 5089 | u8 rc = 1; |
| 5090 | char *desc = NULL; |
| 5091 | |
| 5092 | switch (access_status) { |
| 5093 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: |
| 5094 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: |
| 5095 | rc = 0; |
| 5096 | break; |
| 5097 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: |
| 5098 | desc = "sata capability failed"; |
| 5099 | break; |
| 5100 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: |
| 5101 | desc = "sata affiliation conflict"; |
| 5102 | break; |
| 5103 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: |
| 5104 | desc = "route not addressable"; |
| 5105 | break; |
| 5106 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: |
| 5107 | desc = "smp error not addressable"; |
| 5108 | break; |
| 5109 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: |
| 5110 | desc = "device blocked"; |
| 5111 | break; |
| 5112 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: |
| 5113 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: |
| 5114 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: |
| 5115 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: |
| 5116 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: |
| 5117 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: |
| 5118 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: |
| 5119 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: |
| 5120 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: |
| 5121 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: |
| 5122 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: |
| 5123 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: |
| 5124 | desc = "sata initialization failed"; |
| 5125 | break; |
| 5126 | default: |
| 5127 | desc = "unknown"; |
| 5128 | break; |
| 5129 | } |
| 5130 | |
| 5131 | if (!rc) |
| 5132 | return 0; |
| 5133 | |
| 5134 | printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), " |
| 5135 | "handle(0x%04x)\n", ioc->name, desc, |
| 5136 | (unsigned long long)sas_address, handle); |
| 5137 | return rc; |
| 5138 | } |
| 5139 | |
| 5140 | static void |
| 5141 | _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 5142 | { |
| 5143 | Mpi2ConfigReply_t mpi_reply; |
| 5144 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 5145 | struct _sas_device *sas_device; |
| 5146 | u32 ioc_status; |
| 5147 | unsigned long flags; |
| 5148 | u64 sas_address; |
| 5149 | struct scsi_target *starget; |
| 5150 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 5151 | u32 device_info; |
| 5152 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5153 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5154 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 5155 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) |
| 5156 | return; |
| 5157 | |
| 5158 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 5159 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 5160 | return; |
| 5161 | |
| 5162 | /* check if this is end device */ |
| 5163 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 5164 | if (!(_scsih_is_end_device(device_info))) |
| 5165 | return; |
| 5166 | |
| 5167 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5168 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 5169 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5170 | sas_address); |
| 5171 | |
| 5172 | if (!sas_device) { |
| 5173 | printk(MPT2SAS_ERR_FMT "device is not present " |
| 5174 | "handle(0x%04x), no sas_device!!!\n", ioc->name, handle); |
| 5175 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5176 | return; |
| 5177 | } |
| 5178 | |
| 5179 | if (unlikely(sas_device->handle != handle)) { |
| 5180 | starget = sas_device->starget; |
| 5181 | sas_target_priv_data = starget->hostdata; |
| 5182 | starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)" |
| 5183 | " to (0x%04x)!!!\n", sas_device->handle, handle); |
| 5184 | sas_target_priv_data->handle = handle; |
| 5185 | sas_device->handle = handle; |
| 5186 | } |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5187 | |
| 5188 | /* check if device is present */ |
| 5189 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 5190 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 5191 | printk(MPT2SAS_ERR_FMT "device is not present " |
| 5192 | "handle(0x%04x), flags!!!\n", ioc->name, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5193 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5194 | return; |
| 5195 | } |
| 5196 | |
| 5197 | /* check if there were any issues with discovery */ |
| 5198 | if (_scsih_check_access_status(ioc, sas_address, handle, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5199 | sas_device_pg0.AccessStatus)) { |
| 5200 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5201 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5202 | } |
| 5203 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 5204 | _scsih_ublock_io_device(ioc, sas_address); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5205 | |
| 5206 | } |
| 5207 | |
| 5208 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5209 | * _scsih_add_device - creating sas device object |
| 5210 | * @ioc: per adapter object |
| 5211 | * @handle: sas device handle |
| 5212 | * @phy_num: phy number end device attached to |
| 5213 | * @is_pd: is this hidden raid component |
| 5214 | * |
| 5215 | * Creating end device object, stored in ioc->sas_device_list. |
| 5216 | * |
| 5217 | * Returns 0 for success, non-zero for failure. |
| 5218 | */ |
| 5219 | static int |
| 5220 | _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd) |
| 5221 | { |
| 5222 | Mpi2ConfigReply_t mpi_reply; |
| 5223 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 5224 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 5225 | struct _sas_device *sas_device; |
| 5226 | u32 ioc_status; |
| 5227 | __le64 sas_address; |
| 5228 | u32 device_info; |
| 5229 | unsigned long flags; |
| 5230 | |
| 5231 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 5232 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 5233 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5234 | ioc->name, __FILE__, __LINE__, __func__); |
| 5235 | return -1; |
| 5236 | } |
| 5237 | |
| 5238 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 5239 | MPI2_IOCSTATUS_MASK; |
| 5240 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5241 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5242 | ioc->name, __FILE__, __LINE__, __func__); |
| 5243 | return -1; |
| 5244 | } |
| 5245 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5246 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 5247 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5248 | /* check if device is present */ |
| 5249 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 5250 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 5251 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5252 | ioc->name, __FILE__, __LINE__, __func__); |
| 5253 | printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n", |
| 5254 | ioc->name, le16_to_cpu(sas_device_pg0.Flags)); |
| 5255 | return -1; |
| 5256 | } |
| 5257 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5258 | /* check if there were any issues with discovery */ |
| 5259 | if (_scsih_check_access_status(ioc, sas_address, handle, |
| 5260 | sas_device_pg0.AccessStatus)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5261 | return -1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5262 | |
| 5263 | /* check if this is end device */ |
| 5264 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 5265 | if (!(_scsih_is_end_device(device_info))) { |
| 5266 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5267 | ioc->name, __FILE__, __LINE__, __func__); |
| 5268 | return -1; |
| 5269 | } |
| 5270 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5271 | |
| 5272 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5273 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5274 | sas_address); |
| 5275 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5276 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5277 | if (sas_device) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5278 | return 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5279 | |
| 5280 | sas_device = kzalloc(sizeof(struct _sas_device), |
| 5281 | GFP_KERNEL); |
| 5282 | if (!sas_device) { |
| 5283 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5284 | ioc->name, __FILE__, __LINE__, __func__); |
| 5285 | return -1; |
| 5286 | } |
| 5287 | |
| 5288 | sas_device->handle = handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5289 | if (_scsih_get_sas_address(ioc, le16_to_cpu |
| 5290 | (sas_device_pg0.ParentDevHandle), |
| 5291 | &sas_device->sas_address_parent) != 0) |
| 5292 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5293 | ioc->name, __FILE__, __LINE__, __func__); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5294 | sas_device->enclosure_handle = |
| 5295 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 5296 | sas_device->slot = |
| 5297 | le16_to_cpu(sas_device_pg0.Slot); |
| 5298 | sas_device->device_info = device_info; |
| 5299 | sas_device->sas_address = sas_address; |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 5300 | sas_device->phy = sas_device_pg0.PhyNum; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5301 | |
| 5302 | /* get enclosure_logical_id */ |
Kashyap, Desai | 15052c9 | 2009-08-07 19:33:17 +0530 | [diff] [blame] | 5303 | if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0( |
| 5304 | ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 5305 | sas_device->enclosure_handle))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5306 | sas_device->enclosure_logical_id = |
| 5307 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5308 | |
| 5309 | /* get device name */ |
| 5310 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); |
| 5311 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5312 | if (ioc->wait_for_discovery_to_complete) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5313 | _scsih_sas_device_init_add(ioc, sas_device); |
| 5314 | else |
| 5315 | _scsih_sas_device_add(ioc, sas_device); |
| 5316 | |
| 5317 | return 0; |
| 5318 | } |
| 5319 | |
| 5320 | /** |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5321 | * _scsih_remove_device - removing sas device object |
| 5322 | * @ioc: per adapter object |
| 5323 | * @sas_device_delete: the sas_device object |
| 5324 | * |
| 5325 | * Return nothing. |
| 5326 | */ |
| 5327 | static void |
| 5328 | _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, |
| 5329 | struct _sas_device *sas_device) |
| 5330 | { |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5331 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 5332 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5333 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: " |
| 5334 | "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5335 | sas_device->handle, (unsigned long long) |
| 5336 | sas_device->sas_address)); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5337 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5338 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 5339 | sas_target_priv_data = sas_device->starget->hostdata; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5340 | sas_target_priv_data->deleted = 1; |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 5341 | _scsih_ublock_io_device(ioc, sas_device->sas_address); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5342 | sas_target_priv_data->handle = |
| 5343 | MPT2SAS_INVALID_DEVICE_HANDLE; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5344 | } |
| 5345 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 5346 | if (!ioc->hide_drives) |
| 5347 | mpt2sas_transport_port_remove(ioc, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5348 | sas_device->sas_address, |
| 5349 | sas_device->sas_address_parent); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5350 | |
| 5351 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr" |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5352 | "(0x%016llx)\n", ioc->name, sas_device->handle, |
| 5353 | (unsigned long long) sas_device->sas_address); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5354 | |
| 5355 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: " |
| 5356 | "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5357 | sas_device->handle, (unsigned long long) |
| 5358 | sas_device->sas_address)); |
| 5359 | kfree(sas_device); |
| 5360 | } |
| 5361 | /** |
| 5362 | * _scsih_device_remove_by_handle - removing device object by handle |
| 5363 | * @ioc: per adapter object |
| 5364 | * @handle: device handle |
| 5365 | * |
| 5366 | * Return nothing. |
| 5367 | */ |
| 5368 | static void |
| 5369 | _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 5370 | { |
| 5371 | struct _sas_device *sas_device; |
| 5372 | unsigned long flags; |
| 5373 | |
| 5374 | if (ioc->shost_recovery) |
| 5375 | return; |
| 5376 | |
| 5377 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5378 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 5379 | if (sas_device) |
| 5380 | list_del(&sas_device->list); |
| 5381 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5382 | if (sas_device) |
| 5383 | _scsih_remove_device(ioc, sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5384 | } |
| 5385 | |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5386 | /** |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5387 | * mpt2sas_device_remove_by_sas_address - removing device object by sas address |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5388 | * @ioc: per adapter object |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5389 | * @sas_address: device sas_address |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5390 | * |
| 5391 | * Return nothing. |
| 5392 | */ |
| 5393 | void |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5394 | mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 5395 | u64 sas_address) |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5396 | { |
| 5397 | struct _sas_device *sas_device; |
| 5398 | unsigned long flags; |
| 5399 | |
| 5400 | if (ioc->shost_recovery) |
| 5401 | return; |
| 5402 | |
| 5403 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5404 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5405 | sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5406 | if (sas_device) |
| 5407 | list_del(&sas_device->list); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5408 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5409 | if (sas_device) |
| 5410 | _scsih_remove_device(ioc, sas_device); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5411 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5412 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5413 | /** |
| 5414 | * _scsih_sas_topology_change_event_debug - debug for topology event |
| 5415 | * @ioc: per adapter object |
| 5416 | * @event_data: event data payload |
| 5417 | * Context: user. |
| 5418 | */ |
| 5419 | static void |
| 5420 | _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5421 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 5422 | { |
| 5423 | int i; |
| 5424 | u16 handle; |
| 5425 | u16 reason_code; |
| 5426 | u8 phy_number; |
| 5427 | char *status_str = NULL; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5428 | u8 link_rate, prev_link_rate; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5429 | |
| 5430 | switch (event_data->ExpStatus) { |
| 5431 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: |
| 5432 | status_str = "add"; |
| 5433 | break; |
| 5434 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: |
| 5435 | status_str = "remove"; |
| 5436 | break; |
| 5437 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5438 | case 0: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5439 | status_str = "responding"; |
| 5440 | break; |
| 5441 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: |
| 5442 | status_str = "remove delay"; |
| 5443 | break; |
| 5444 | default: |
| 5445 | status_str = "unknown status"; |
| 5446 | break; |
| 5447 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5448 | printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5449 | ioc->name, status_str); |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5450 | printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5451 | "start_phy(%02d), count(%d)\n", |
| 5452 | le16_to_cpu(event_data->ExpanderDevHandle), |
| 5453 | le16_to_cpu(event_data->EnclosureHandle), |
| 5454 | event_data->StartPhyNum, event_data->NumEntries); |
| 5455 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5456 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5457 | if (!handle) |
| 5458 | continue; |
| 5459 | phy_number = event_data->StartPhyNum + i; |
| 5460 | reason_code = event_data->PHY[i].PhyStatus & |
| 5461 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5462 | switch (reason_code) { |
| 5463 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5464 | status_str = "target add"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5465 | break; |
| 5466 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5467 | status_str = "target remove"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5468 | break; |
| 5469 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5470 | status_str = "delay target remove"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5471 | break; |
| 5472 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5473 | status_str = "link rate change"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5474 | break; |
| 5475 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5476 | status_str = "target responding"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5477 | break; |
| 5478 | default: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5479 | status_str = "unknown"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5480 | break; |
| 5481 | } |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5482 | link_rate = event_data->PHY[i].LinkRate >> 4; |
| 5483 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5484 | printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:" |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5485 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, |
| 5486 | handle, status_str, link_rate, prev_link_rate); |
| 5487 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5488 | } |
| 5489 | } |
| 5490 | #endif |
| 5491 | |
| 5492 | /** |
| 5493 | * _scsih_sas_topology_change_event - handle topology changes |
| 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 | */ |
| 5499 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5500 | _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5501 | struct fw_event_work *fw_event) |
| 5502 | { |
| 5503 | int i; |
| 5504 | u16 parent_handle, handle; |
| 5505 | u16 reason_code; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5506 | u8 phy_number, max_phys; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5507 | struct _sas_node *sas_expander; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5508 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5509 | unsigned long flags; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5510 | u8 link_rate, prev_link_rate; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5511 | Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5512 | |
| 5513 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5514 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5515 | _scsih_sas_topology_change_event_debug(ioc, event_data); |
| 5516 | #endif |
| 5517 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5518 | if (ioc->remove_host || ioc->pci_error_recovery) |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5519 | return; |
| 5520 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5521 | if (!ioc->sas_hba.num_phys) |
| 5522 | _scsih_sas_host_add(ioc); |
| 5523 | else |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5524 | _scsih_sas_host_refresh(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5525 | |
| 5526 | if (fw_event->ignore) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5527 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5528 | "event\n", ioc->name)); |
| 5529 | return; |
| 5530 | } |
| 5531 | |
| 5532 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 5533 | |
| 5534 | /* handle expander add */ |
| 5535 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) |
| 5536 | if (_scsih_expander_add(ioc, parent_handle) != 0) |
| 5537 | return; |
| 5538 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5539 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 5540 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 5541 | parent_handle); |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5542 | if (sas_expander) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5543 | sas_address = sas_expander->sas_address; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5544 | max_phys = sas_expander->num_phys; |
| 5545 | } else if (parent_handle < ioc->sas_hba.num_phys) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5546 | sas_address = ioc->sas_hba.sas_address; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5547 | max_phys = ioc->sas_hba.num_phys; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5548 | } else { |
| 5549 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5550 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5551 | } |
| 5552 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5553 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5554 | /* handle siblings events */ |
| 5555 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5556 | if (fw_event->ignore) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5557 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5558 | "expander event\n", ioc->name)); |
| 5559 | return; |
| 5560 | } |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 5561 | if (ioc->shost_recovery || ioc->remove_host || |
| 5562 | ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 5563 | return; |
Kashyap, Desai | 308609c | 2009-09-14 11:07:23 +0530 | [diff] [blame] | 5564 | phy_number = event_data->StartPhyNum + i; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5565 | if (phy_number >= max_phys) |
| 5566 | continue; |
Kashyap, Desai | 308609c | 2009-09-14 11:07:23 +0530 | [diff] [blame] | 5567 | reason_code = event_data->PHY[i].PhyStatus & |
| 5568 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5569 | if ((event_data->PHY[i].PhyStatus & |
| 5570 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != |
| 5571 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5572 | continue; |
| 5573 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5574 | if (!handle) |
| 5575 | continue; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5576 | link_rate = event_data->PHY[i].LinkRate >> 4; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5577 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5578 | switch (reason_code) { |
| 5579 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5580 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5581 | if (ioc->shost_recovery) |
| 5582 | break; |
| 5583 | |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5584 | if (link_rate == prev_link_rate) |
| 5585 | break; |
| 5586 | |
| 5587 | mpt2sas_transport_update_links(ioc, sas_address, |
| 5588 | handle, phy_number, link_rate); |
| 5589 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5590 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 5591 | break; |
| 5592 | |
| 5593 | _scsih_check_device(ioc, handle); |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5594 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5595 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5596 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5597 | if (ioc->shost_recovery) |
| 5598 | break; |
| 5599 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5600 | mpt2sas_transport_update_links(ioc, sas_address, |
| 5601 | handle, phy_number, link_rate); |
| 5602 | |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5603 | _scsih_add_device(ioc, handle, phy_number, 0); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5604 | break; |
| 5605 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5606 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5607 | _scsih_device_remove_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5608 | break; |
| 5609 | } |
| 5610 | } |
| 5611 | |
| 5612 | /* handle expander removal */ |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5613 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && |
| 5614 | sas_expander) |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5615 | mpt2sas_expander_remove(ioc, sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5616 | |
| 5617 | } |
| 5618 | |
| 5619 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5620 | /** |
| 5621 | * _scsih_sas_device_status_change_event_debug - debug for device event |
| 5622 | * @event_data: event data payload |
| 5623 | * Context: user. |
| 5624 | * |
| 5625 | * Return nothing. |
| 5626 | */ |
| 5627 | static void |
| 5628 | _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5629 | Mpi2EventDataSasDeviceStatusChange_t *event_data) |
| 5630 | { |
| 5631 | char *reason_str = NULL; |
| 5632 | |
| 5633 | switch (event_data->ReasonCode) { |
| 5634 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: |
| 5635 | reason_str = "smart data"; |
| 5636 | break; |
| 5637 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: |
| 5638 | reason_str = "unsupported device discovered"; |
| 5639 | break; |
| 5640 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: |
| 5641 | reason_str = "internal device reset"; |
| 5642 | break; |
| 5643 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: |
| 5644 | reason_str = "internal task abort"; |
| 5645 | break; |
| 5646 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: |
| 5647 | reason_str = "internal task abort set"; |
| 5648 | break; |
| 5649 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: |
| 5650 | reason_str = "internal clear task set"; |
| 5651 | break; |
| 5652 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: |
| 5653 | reason_str = "internal query task"; |
| 5654 | break; |
| 5655 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: |
| 5656 | reason_str = "sata init failure"; |
| 5657 | break; |
| 5658 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: |
| 5659 | reason_str = "internal device reset complete"; |
| 5660 | break; |
| 5661 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: |
| 5662 | reason_str = "internal task abort complete"; |
| 5663 | break; |
| 5664 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: |
| 5665 | reason_str = "internal async notification"; |
| 5666 | break; |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 5667 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5668 | reason_str = "expander reduced functionality"; |
| 5669 | break; |
| 5670 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5671 | reason_str = "expander reduced functionality complete"; |
| 5672 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5673 | default: |
| 5674 | reason_str = "unknown reason"; |
| 5675 | break; |
| 5676 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5677 | printk(MPT2SAS_INFO_FMT "device status change: (%s)\n" |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5678 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", |
| 5679 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), |
| 5680 | (unsigned long long)le64_to_cpu(event_data->SASAddress), |
| 5681 | le16_to_cpu(event_data->TaskTag)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5682 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5683 | 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] | 5684 | event_data->ASC, event_data->ASCQ); |
| 5685 | printk(KERN_INFO "\n"); |
| 5686 | } |
| 5687 | #endif |
| 5688 | |
| 5689 | /** |
| 5690 | * _scsih_sas_device_status_change_event - handle device status change |
| 5691 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5692 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5693 | * Context: user. |
| 5694 | * |
| 5695 | * Return nothing. |
| 5696 | */ |
| 5697 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5698 | _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 5699 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5700 | { |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5701 | struct MPT2SAS_TARGET *target_priv_data; |
| 5702 | struct _sas_device *sas_device; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 5703 | u64 sas_address; |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5704 | unsigned long flags; |
| 5705 | Mpi2EventDataSasDeviceStatusChange_t *event_data = |
| 5706 | fw_event->event_data; |
| 5707 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5708 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5709 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5710 | _scsih_sas_device_status_change_event_debug(ioc, |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5711 | event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5712 | #endif |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5713 | |
Kashyap, Desai | efe82a1 | 2011-01-04 11:34:17 +0530 | [diff] [blame] | 5714 | /* In MPI Revision K (0xC), the internal device reset complete was |
| 5715 | * implemented, so avoid setting tm_busy flag for older firmware. |
| 5716 | */ |
| 5717 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) |
| 5718 | return; |
| 5719 | |
Kashyap, Desai | f891dcf | 2010-03-17 16:22:21 +0530 | [diff] [blame] | 5720 | if (event_data->ReasonCode != |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5721 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && |
Kashyap, Desai | f891dcf | 2010-03-17 16:22:21 +0530 | [diff] [blame] | 5722 | event_data->ReasonCode != |
| 5723 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5724 | return; |
| 5725 | |
| 5726 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5727 | sas_address = le64_to_cpu(event_data->SASAddress); |
| 5728 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5729 | sas_address); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5730 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5731 | if (!sas_device || !sas_device->starget) { |
| 5732 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5733 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5734 | } |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5735 | |
| 5736 | target_priv_data = sas_device->starget->hostdata; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5737 | if (!target_priv_data) { |
| 5738 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5739 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5740 | } |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5741 | |
| 5742 | if (event_data->ReasonCode == |
| 5743 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) |
| 5744 | target_priv_data->tm_busy = 1; |
| 5745 | else |
| 5746 | target_priv_data->tm_busy = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5747 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5748 | } |
| 5749 | |
| 5750 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5751 | /** |
| 5752 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event |
| 5753 | * @ioc: per adapter object |
| 5754 | * @event_data: event data payload |
| 5755 | * Context: user. |
| 5756 | * |
| 5757 | * Return nothing. |
| 5758 | */ |
| 5759 | static void |
| 5760 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5761 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) |
| 5762 | { |
| 5763 | char *reason_str = NULL; |
| 5764 | |
| 5765 | switch (event_data->ReasonCode) { |
| 5766 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: |
| 5767 | reason_str = "enclosure add"; |
| 5768 | break; |
| 5769 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: |
| 5770 | reason_str = "enclosure remove"; |
| 5771 | break; |
| 5772 | default: |
| 5773 | reason_str = "unknown reason"; |
| 5774 | break; |
| 5775 | } |
| 5776 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5777 | printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5778 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" |
| 5779 | " number slots(%d)\n", ioc->name, reason_str, |
| 5780 | le16_to_cpu(event_data->EnclosureHandle), |
| 5781 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), |
| 5782 | le16_to_cpu(event_data->StartSlot)); |
| 5783 | } |
| 5784 | #endif |
| 5785 | |
| 5786 | /** |
| 5787 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events |
| 5788 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5789 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5790 | * Context: user. |
| 5791 | * |
| 5792 | * Return nothing. |
| 5793 | */ |
| 5794 | static void |
| 5795 | _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5796 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5797 | { |
| 5798 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5799 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5800 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5801 | fw_event->event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5802 | #endif |
| 5803 | } |
| 5804 | |
| 5805 | /** |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 5806 | * _scsih_sas_broadcast_primitive_event - handle broadcast events |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5807 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5808 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5809 | * Context: user. |
| 5810 | * |
| 5811 | * Return nothing. |
| 5812 | */ |
| 5813 | static void |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 5814 | _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5815 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5816 | { |
| 5817 | struct scsi_cmnd *scmd; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5818 | struct scsi_device *sdev; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5819 | u16 smid, handle; |
| 5820 | u32 lun; |
| 5821 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 5822 | u32 termination_count; |
| 5823 | u32 query_count; |
| 5824 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5825 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data; |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 5826 | u16 ioc_status; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5827 | unsigned long flags; |
| 5828 | int r; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5829 | u8 max_retries = 0; |
| 5830 | u8 task_abort_retries; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5831 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5832 | mutex_lock(&ioc->tm_cmds.mutex); |
Reddy, Sreekanth | c3a634b | 2013-02-26 17:36:12 +0530 | [diff] [blame] | 5833 | pr_info(MPT2SAS_FMT |
| 5834 | "%s: enter: phy number(%d), width(%d)\n", |
| 5835 | ioc->name, __func__, event_data->PhyNum, |
| 5836 | event_data->PortWidth); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5837 | |
| 5838 | _scsih_block_io_all_device(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5839 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5840 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5841 | mpi_reply = ioc->tm_cmds.reply; |
| 5842 | broadcast_aen_retry: |
| 5843 | |
| 5844 | /* sanity checks for retrying this loop */ |
| 5845 | if (max_retries++ == 5) { |
| 5846 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n", |
| 5847 | ioc->name, __func__)); |
| 5848 | goto out; |
| 5849 | } else if (max_retries > 1) |
| 5850 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n", |
| 5851 | ioc->name, __func__, max_retries - 1)); |
| 5852 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5853 | termination_count = 0; |
| 5854 | query_count = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 5855 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5856 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5857 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5858 | scmd = _scsih_scsi_lookup_get(ioc, smid); |
| 5859 | if (!scmd) |
| 5860 | continue; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5861 | sdev = scmd->device; |
| 5862 | sas_device_priv_data = sdev->hostdata; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5863 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) |
| 5864 | continue; |
| 5865 | /* skip hidden raid components */ |
| 5866 | if (sas_device_priv_data->sas_target->flags & |
| 5867 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 5868 | continue; |
| 5869 | /* skip volumes */ |
| 5870 | if (sas_device_priv_data->sas_target->flags & |
| 5871 | MPT_TARGET_FLAGS_VOLUME) |
| 5872 | continue; |
| 5873 | |
| 5874 | handle = sas_device_priv_data->sas_target->handle; |
| 5875 | lun = sas_device_priv_data->lun; |
| 5876 | query_count++; |
| 5877 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5878 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5879 | goto out; |
| 5880 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5881 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5882 | r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun, |
| 5883 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0, |
| 5884 | TM_MUTEX_OFF); |
| 5885 | if (r == FAILED) { |
| 5886 | sdev_printk(KERN_WARNING, sdev, |
| 5887 | "mpt2sas_scsih_issue_tm: FAILED when sending " |
| 5888 | "QUERY_TASK: scmd(%p)\n", scmd); |
| 5889 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5890 | goto broadcast_aen_retry; |
| 5891 | } |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 5892 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) |
| 5893 | & MPI2_IOCSTATUS_MASK; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5894 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5895 | sdev_printk(KERN_WARNING, sdev, "query task: FAILED " |
| 5896 | "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status, |
| 5897 | scmd); |
| 5898 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5899 | goto broadcast_aen_retry; |
| 5900 | } |
| 5901 | |
| 5902 | /* see if IO is still owned by IOC and target */ |
| 5903 | if (mpi_reply->ResponseCode == |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5904 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || |
| 5905 | mpi_reply->ResponseCode == |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5906 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5907 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5908 | continue; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5909 | } |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5910 | task_abort_retries = 0; |
| 5911 | tm_retry: |
| 5912 | if (task_abort_retries++ == 60) { |
| 5913 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 5914 | "%s: ABORT_TASK: giving up\n", ioc->name, |
| 5915 | __func__)); |
| 5916 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5917 | goto broadcast_aen_retry; |
| 5918 | } |
| 5919 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5920 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5921 | goto out_no_lock; |
| 5922 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5923 | r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, |
| 5924 | sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5925 | scmd->serial_number, TM_MUTEX_OFF); |
| 5926 | if (r == FAILED) { |
| 5927 | sdev_printk(KERN_WARNING, sdev, |
| 5928 | "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : " |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5929 | "scmd(%p)\n", scmd); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5930 | goto tm_retry; |
| 5931 | } |
| 5932 | |
| 5933 | if (task_abort_retries > 1) |
| 5934 | sdev_printk(KERN_WARNING, sdev, |
| 5935 | "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" |
| 5936 | " scmd(%p)\n", |
| 5937 | task_abort_retries - 1, scmd); |
| 5938 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5939 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5940 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5941 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5942 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5943 | if (ioc->broadcast_aen_pending) { |
| 5944 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to" |
| 5945 | " pending AEN\n", ioc->name, __func__)); |
| 5946 | ioc->broadcast_aen_pending = 0; |
| 5947 | goto broadcast_aen_retry; |
| 5948 | } |
| 5949 | |
| 5950 | out: |
| 5951 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 5952 | out_no_lock: |
| 5953 | |
| 5954 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5955 | "%s - exit, query_count = %d termination_count = %d\n", |
| 5956 | ioc->name, __func__, query_count, termination_count)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5957 | |
| 5958 | ioc->broadcast_aen_busy = 0; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5959 | if (!ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5960 | _scsih_ublock_io_all_device(ioc); |
| 5961 | mutex_unlock(&ioc->tm_cmds.mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5962 | } |
| 5963 | |
| 5964 | /** |
| 5965 | * _scsih_sas_discovery_event - handle discovery events |
| 5966 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5967 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5968 | * Context: user. |
| 5969 | * |
| 5970 | * Return nothing. |
| 5971 | */ |
| 5972 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5973 | _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc, |
| 5974 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5975 | { |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5976 | Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data; |
| 5977 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5978 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5979 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5980 | printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5981 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? |
| 5982 | "start" : "stop"); |
| 5983 | if (event_data->DiscoveryStatus) |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 5984 | printk("discovery_status(0x%08x)", |
| 5985 | le32_to_cpu(event_data->DiscoveryStatus)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5986 | printk("\n"); |
| 5987 | } |
| 5988 | #endif |
| 5989 | |
| 5990 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 5991 | !ioc->sas_hba.num_phys) { |
| 5992 | if (disable_discovery > 0 && ioc->shost_recovery) { |
| 5993 | /* Wait for the reset to complete */ |
| 5994 | while (ioc->shost_recovery) |
| 5995 | ssleep(1); |
| 5996 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5997 | _scsih_sas_host_add(ioc); |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 5998 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5999 | } |
| 6000 | |
| 6001 | /** |
| 6002 | * _scsih_reprobe_lun - reprobing lun |
| 6003 | * @sdev: scsi device struct |
| 6004 | * @no_uld_attach: sdev->no_uld_attach flag setting |
| 6005 | * |
| 6006 | **/ |
| 6007 | static void |
| 6008 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) |
| 6009 | { |
| 6010 | int rc; |
| 6011 | |
| 6012 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
| 6013 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", |
| 6014 | sdev->no_uld_attach ? "hidding" : "exposing"); |
| 6015 | rc = scsi_device_reprobe(sdev); |
| 6016 | } |
| 6017 | |
| 6018 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6019 | * _scsih_sas_volume_add - add new volume |
| 6020 | * @ioc: per adapter object |
| 6021 | * @element: IR config element data |
| 6022 | * Context: user. |
| 6023 | * |
| 6024 | * Return nothing. |
| 6025 | */ |
| 6026 | static void |
| 6027 | _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc, |
| 6028 | Mpi2EventIrConfigElement_t *element) |
| 6029 | { |
| 6030 | struct _raid_device *raid_device; |
| 6031 | unsigned long flags; |
| 6032 | u64 wwid; |
| 6033 | u16 handle = le16_to_cpu(element->VolDevHandle); |
| 6034 | int rc; |
| 6035 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6036 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 6037 | if (!wwid) { |
| 6038 | printk(MPT2SAS_ERR_FMT |
| 6039 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6040 | __FILE__, __LINE__, __func__); |
| 6041 | return; |
| 6042 | } |
| 6043 | |
| 6044 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6045 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); |
| 6046 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6047 | |
| 6048 | if (raid_device) |
| 6049 | return; |
| 6050 | |
| 6051 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 6052 | if (!raid_device) { |
| 6053 | printk(MPT2SAS_ERR_FMT |
| 6054 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6055 | __FILE__, __LINE__, __func__); |
| 6056 | return; |
| 6057 | } |
| 6058 | |
| 6059 | raid_device->id = ioc->sas_id++; |
| 6060 | raid_device->channel = RAID_CHANNEL; |
| 6061 | raid_device->handle = handle; |
| 6062 | raid_device->wwid = wwid; |
| 6063 | _scsih_raid_device_add(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6064 | if (!ioc->wait_for_discovery_to_complete) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6065 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 6066 | raid_device->id, 0); |
| 6067 | if (rc) |
| 6068 | _scsih_raid_device_remove(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6069 | } else { |
| 6070 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6071 | _scsih_determine_boot_device(ioc, raid_device, 1); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6072 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6073 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6074 | } |
| 6075 | |
| 6076 | /** |
| 6077 | * _scsih_sas_volume_delete - delete volume |
| 6078 | * @ioc: per adapter object |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6079 | * @handle: volume device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6080 | * Context: user. |
| 6081 | * |
| 6082 | * Return nothing. |
| 6083 | */ |
| 6084 | static void |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6085 | _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6086 | { |
| 6087 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6088 | unsigned long flags; |
| 6089 | struct MPT2SAS_TARGET *sas_target_priv_data; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6090 | struct scsi_target *starget = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6091 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6092 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6093 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6094 | if (raid_device) { |
| 6095 | if (raid_device->starget) { |
| 6096 | starget = raid_device->starget; |
| 6097 | sas_target_priv_data = starget->hostdata; |
| 6098 | sas_target_priv_data->deleted = 1; |
| 6099 | } |
| 6100 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" |
| 6101 | "(0x%016llx)\n", ioc->name, raid_device->handle, |
| 6102 | (unsigned long long) raid_device->wwid); |
| 6103 | list_del(&raid_device->list); |
| 6104 | kfree(raid_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6105 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6106 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6107 | if (starget) |
| 6108 | scsi_remove_target(&starget->dev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6109 | } |
| 6110 | |
| 6111 | /** |
| 6112 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX |
| 6113 | * @ioc: per adapter object |
| 6114 | * @element: IR config element data |
| 6115 | * Context: user. |
| 6116 | * |
| 6117 | * Return nothing. |
| 6118 | */ |
| 6119 | static void |
| 6120 | _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc, |
| 6121 | Mpi2EventIrConfigElement_t *element) |
| 6122 | { |
| 6123 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6124 | struct scsi_target *starget = NULL; |
| 6125 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6126 | unsigned long flags; |
| 6127 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 6128 | |
| 6129 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6130 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6131 | if (sas_device) { |
| 6132 | sas_device->volume_handle = 0; |
| 6133 | sas_device->volume_wwid = 0; |
| 6134 | clear_bit(handle, ioc->pd_handles); |
| 6135 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 6136 | starget = sas_device->starget; |
| 6137 | sas_target_priv_data = starget->hostdata; |
| 6138 | sas_target_priv_data->flags &= |
| 6139 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 6140 | } |
| 6141 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6142 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6143 | if (!sas_device) |
| 6144 | return; |
| 6145 | |
| 6146 | /* exposing raid component */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6147 | if (starget) |
| 6148 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6149 | } |
| 6150 | |
| 6151 | /** |
| 6152 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX |
| 6153 | * @ioc: per adapter object |
| 6154 | * @element: IR config element data |
| 6155 | * Context: user. |
| 6156 | * |
| 6157 | * Return nothing. |
| 6158 | */ |
| 6159 | static void |
| 6160 | _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc, |
| 6161 | Mpi2EventIrConfigElement_t *element) |
| 6162 | { |
| 6163 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6164 | struct scsi_target *starget = NULL; |
| 6165 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6166 | unsigned long flags; |
| 6167 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6168 | u16 volume_handle = 0; |
| 6169 | u64 volume_wwid = 0; |
| 6170 | |
| 6171 | mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle); |
| 6172 | if (volume_handle) |
| 6173 | mpt2sas_config_get_volume_wwid(ioc, volume_handle, |
| 6174 | &volume_wwid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6175 | |
| 6176 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6177 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6178 | if (sas_device) { |
| 6179 | set_bit(handle, ioc->pd_handles); |
| 6180 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 6181 | starget = sas_device->starget; |
| 6182 | sas_target_priv_data = starget->hostdata; |
| 6183 | sas_target_priv_data->flags |= |
| 6184 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 6185 | sas_device->volume_handle = volume_handle; |
| 6186 | sas_device->volume_wwid = volume_wwid; |
| 6187 | } |
| 6188 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6189 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6190 | if (!sas_device) |
| 6191 | return; |
| 6192 | |
| 6193 | /* hiding raid component */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6194 | if (starget) |
| 6195 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6196 | } |
| 6197 | |
| 6198 | /** |
| 6199 | * _scsih_sas_pd_delete - delete pd component |
| 6200 | * @ioc: per adapter object |
| 6201 | * @element: IR config element data |
| 6202 | * Context: user. |
| 6203 | * |
| 6204 | * Return nothing. |
| 6205 | */ |
| 6206 | static void |
| 6207 | _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc, |
| 6208 | Mpi2EventIrConfigElement_t *element) |
| 6209 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6210 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 6211 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6212 | _scsih_device_remove_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6213 | } |
| 6214 | |
| 6215 | /** |
| 6216 | * _scsih_sas_pd_add - remove pd component |
| 6217 | * @ioc: per adapter object |
| 6218 | * @element: IR config element data |
| 6219 | * Context: user. |
| 6220 | * |
| 6221 | * Return nothing. |
| 6222 | */ |
| 6223 | static void |
| 6224 | _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc, |
| 6225 | Mpi2EventIrConfigElement_t *element) |
| 6226 | { |
| 6227 | struct _sas_device *sas_device; |
| 6228 | unsigned long flags; |
| 6229 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6230 | Mpi2ConfigReply_t mpi_reply; |
| 6231 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6232 | u32 ioc_status; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6233 | u64 sas_address; |
| 6234 | u16 parent_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6235 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6236 | set_bit(handle, ioc->pd_handles); |
| 6237 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6238 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6239 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6240 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6241 | if (sas_device) |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6242 | return; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6243 | |
| 6244 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 6245 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 6246 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6247 | ioc->name, __FILE__, __LINE__, __func__); |
| 6248 | return; |
| 6249 | } |
| 6250 | |
| 6251 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6252 | MPI2_IOCSTATUS_MASK; |
| 6253 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6254 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6255 | ioc->name, __FILE__, __LINE__, __func__); |
| 6256 | return; |
| 6257 | } |
| 6258 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6259 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6260 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 6261 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 6262 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6263 | |
| 6264 | _scsih_add_device(ioc, handle, 0, 1); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6265 | } |
| 6266 | |
| 6267 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 6268 | /** |
| 6269 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events |
| 6270 | * @ioc: per adapter object |
| 6271 | * @event_data: event data payload |
| 6272 | * Context: user. |
| 6273 | * |
| 6274 | * Return nothing. |
| 6275 | */ |
| 6276 | static void |
| 6277 | _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 6278 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 6279 | { |
| 6280 | Mpi2EventIrConfigElement_t *element; |
| 6281 | u8 element_type; |
| 6282 | int i; |
| 6283 | char *reason_str = NULL, *element_str = NULL; |
| 6284 | |
| 6285 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 6286 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6287 | printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6288 | ioc->name, (le32_to_cpu(event_data->Flags) & |
| 6289 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? |
| 6290 | "foreign" : "native", event_data->NumElements); |
| 6291 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6292 | switch (element->ReasonCode) { |
| 6293 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
| 6294 | reason_str = "add"; |
| 6295 | break; |
| 6296 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
| 6297 | reason_str = "remove"; |
| 6298 | break; |
| 6299 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: |
| 6300 | reason_str = "no change"; |
| 6301 | break; |
| 6302 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
| 6303 | reason_str = "hide"; |
| 6304 | break; |
| 6305 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
| 6306 | reason_str = "unhide"; |
| 6307 | break; |
| 6308 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 6309 | reason_str = "volume_created"; |
| 6310 | break; |
| 6311 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 6312 | reason_str = "volume_deleted"; |
| 6313 | break; |
| 6314 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
| 6315 | reason_str = "pd_created"; |
| 6316 | break; |
| 6317 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
| 6318 | reason_str = "pd_deleted"; |
| 6319 | break; |
| 6320 | default: |
| 6321 | reason_str = "unknown reason"; |
| 6322 | break; |
| 6323 | } |
| 6324 | element_type = le16_to_cpu(element->ElementFlags) & |
| 6325 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; |
| 6326 | switch (element_type) { |
| 6327 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: |
| 6328 | element_str = "volume"; |
| 6329 | break; |
| 6330 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: |
| 6331 | element_str = "phys disk"; |
| 6332 | break; |
| 6333 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: |
| 6334 | element_str = "hot spare"; |
| 6335 | break; |
| 6336 | default: |
| 6337 | element_str = "unknown element"; |
| 6338 | break; |
| 6339 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6340 | printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6341 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, |
| 6342 | reason_str, le16_to_cpu(element->VolDevHandle), |
| 6343 | le16_to_cpu(element->PhysDiskDevHandle), |
| 6344 | element->PhysDiskNum); |
| 6345 | } |
| 6346 | } |
| 6347 | #endif |
| 6348 | |
| 6349 | /** |
| 6350 | * _scsih_sas_ir_config_change_event - handle ir configuration change events |
| 6351 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6352 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6353 | * Context: user. |
| 6354 | * |
| 6355 | * Return nothing. |
| 6356 | */ |
| 6357 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6358 | _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 6359 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6360 | { |
| 6361 | Mpi2EventIrConfigElement_t *element; |
| 6362 | int i; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6363 | u8 foreign_config; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6364 | Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6365 | |
| 6366 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6367 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6368 | && !ioc->hide_ir_msg) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6369 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
| 6370 | |
| 6371 | #endif |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6372 | |
| 6373 | if (ioc->shost_recovery) |
| 6374 | return; |
| 6375 | |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6376 | foreign_config = (le32_to_cpu(event_data->Flags) & |
| 6377 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6378 | |
| 6379 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 6380 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6381 | |
| 6382 | switch (element->ReasonCode) { |
| 6383 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 6384 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6385 | if (!foreign_config) |
| 6386 | _scsih_sas_volume_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6387 | break; |
| 6388 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 6389 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6390 | if (!foreign_config) |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6391 | _scsih_sas_volume_delete(ioc, |
| 6392 | le16_to_cpu(element->VolDevHandle)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6393 | break; |
| 6394 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6395 | if (!ioc->is_warpdrive) |
| 6396 | _scsih_sas_pd_hide(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6397 | break; |
| 6398 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6399 | if (!ioc->is_warpdrive) |
| 6400 | _scsih_sas_pd_expose(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6401 | break; |
| 6402 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6403 | if (!ioc->is_warpdrive) |
| 6404 | _scsih_sas_pd_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6405 | break; |
| 6406 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6407 | if (!ioc->is_warpdrive) |
| 6408 | _scsih_sas_pd_delete(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6409 | break; |
| 6410 | } |
| 6411 | } |
| 6412 | } |
| 6413 | |
| 6414 | /** |
| 6415 | * _scsih_sas_ir_volume_event - IR volume event |
| 6416 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6417 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6418 | * Context: user. |
| 6419 | * |
| 6420 | * Return nothing. |
| 6421 | */ |
| 6422 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6423 | _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc, |
| 6424 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6425 | { |
| 6426 | u64 wwid; |
| 6427 | unsigned long flags; |
| 6428 | struct _raid_device *raid_device; |
| 6429 | u16 handle; |
| 6430 | u32 state; |
| 6431 | int rc; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6432 | Mpi2EventDataIrVolume_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6433 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6434 | if (ioc->shost_recovery) |
| 6435 | return; |
| 6436 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6437 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 6438 | return; |
| 6439 | |
| 6440 | handle = le16_to_cpu(event_data->VolDevHandle); |
| 6441 | state = le32_to_cpu(event_data->NewValue); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6442 | if (!ioc->hide_ir_msg) |
| 6443 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " |
| 6444 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 6445 | le32_to_cpu(event_data->PreviousValue), state)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6446 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6447 | switch (state) { |
| 6448 | case MPI2_RAID_VOL_STATE_MISSING: |
| 6449 | case MPI2_RAID_VOL_STATE_FAILED: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6450 | _scsih_sas_volume_delete(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6451 | break; |
| 6452 | |
| 6453 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 6454 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 6455 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6456 | |
| 6457 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6458 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 6459 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6460 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6461 | if (raid_device) |
| 6462 | break; |
| 6463 | |
| 6464 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 6465 | if (!wwid) { |
| 6466 | printk(MPT2SAS_ERR_FMT |
| 6467 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6468 | __FILE__, __LINE__, __func__); |
| 6469 | break; |
| 6470 | } |
| 6471 | |
| 6472 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 6473 | if (!raid_device) { |
| 6474 | printk(MPT2SAS_ERR_FMT |
| 6475 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6476 | __FILE__, __LINE__, __func__); |
| 6477 | break; |
| 6478 | } |
| 6479 | |
| 6480 | raid_device->id = ioc->sas_id++; |
| 6481 | raid_device->channel = RAID_CHANNEL; |
| 6482 | raid_device->handle = handle; |
| 6483 | raid_device->wwid = wwid; |
| 6484 | _scsih_raid_device_add(ioc, raid_device); |
| 6485 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 6486 | raid_device->id, 0); |
| 6487 | if (rc) |
| 6488 | _scsih_raid_device_remove(ioc, raid_device); |
| 6489 | break; |
| 6490 | |
| 6491 | case MPI2_RAID_VOL_STATE_INITIALIZING: |
| 6492 | default: |
| 6493 | break; |
| 6494 | } |
| 6495 | } |
| 6496 | |
| 6497 | /** |
| 6498 | * _scsih_sas_ir_physical_disk_event - PD event |
| 6499 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6500 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6501 | * Context: user. |
| 6502 | * |
| 6503 | * Return nothing. |
| 6504 | */ |
| 6505 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6506 | _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc, |
| 6507 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6508 | { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6509 | u16 handle, parent_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6510 | u32 state; |
| 6511 | struct _sas_device *sas_device; |
| 6512 | unsigned long flags; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6513 | Mpi2ConfigReply_t mpi_reply; |
| 6514 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6515 | u32 ioc_status; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6516 | Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6517 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6518 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6519 | if (ioc->shost_recovery) |
| 6520 | return; |
| 6521 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6522 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) |
| 6523 | return; |
| 6524 | |
| 6525 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); |
| 6526 | state = le32_to_cpu(event_data->NewValue); |
| 6527 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6528 | if (!ioc->hide_ir_msg) |
| 6529 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " |
| 6530 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 6531 | le32_to_cpu(event_data->PreviousValue), state)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6532 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6533 | switch (state) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6534 | case MPI2_RAID_PD_STATE_ONLINE: |
| 6535 | case MPI2_RAID_PD_STATE_DEGRADED: |
| 6536 | case MPI2_RAID_PD_STATE_REBUILDING: |
| 6537 | case MPI2_RAID_PD_STATE_OPTIMAL: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6538 | case MPI2_RAID_PD_STATE_HOT_SPARE: |
| 6539 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6540 | if (!ioc->is_warpdrive) |
| 6541 | set_bit(handle, ioc->pd_handles); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6542 | |
| 6543 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6544 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6545 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6546 | |
| 6547 | if (sas_device) |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6548 | return; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6549 | |
| 6550 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6551 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 6552 | handle))) { |
| 6553 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6554 | ioc->name, __FILE__, __LINE__, __func__); |
| 6555 | return; |
| 6556 | } |
| 6557 | |
| 6558 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6559 | MPI2_IOCSTATUS_MASK; |
| 6560 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6561 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6562 | ioc->name, __FILE__, __LINE__, __func__); |
| 6563 | return; |
| 6564 | } |
| 6565 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6566 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6567 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 6568 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 6569 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6570 | |
| 6571 | _scsih_add_device(ioc, handle, 0, 1); |
| 6572 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6573 | break; |
| 6574 | |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6575 | case MPI2_RAID_PD_STATE_OFFLINE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6576 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: |
| 6577 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6578 | default: |
| 6579 | break; |
| 6580 | } |
| 6581 | } |
| 6582 | |
| 6583 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 6584 | /** |
| 6585 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event |
| 6586 | * @ioc: per adapter object |
| 6587 | * @event_data: event data payload |
| 6588 | * Context: user. |
| 6589 | * |
| 6590 | * Return nothing. |
| 6591 | */ |
| 6592 | static void |
| 6593 | _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 6594 | Mpi2EventDataIrOperationStatus_t *event_data) |
| 6595 | { |
| 6596 | char *reason_str = NULL; |
| 6597 | |
| 6598 | switch (event_data->RAIDOperation) { |
| 6599 | case MPI2_EVENT_IR_RAIDOP_RESYNC: |
| 6600 | reason_str = "resync"; |
| 6601 | break; |
| 6602 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: |
| 6603 | reason_str = "online capacity expansion"; |
| 6604 | break; |
| 6605 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: |
| 6606 | reason_str = "consistency check"; |
| 6607 | break; |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 6608 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: |
| 6609 | reason_str = "background init"; |
| 6610 | break; |
| 6611 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: |
| 6612 | reason_str = "make data consistent"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6613 | break; |
| 6614 | } |
| 6615 | |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 6616 | if (!reason_str) |
| 6617 | return; |
| 6618 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6619 | printk(MPT2SAS_INFO_FMT "raid operational status: (%s)" |
| 6620 | "\thandle(0x%04x), percent complete(%d)\n", |
| 6621 | ioc->name, reason_str, |
| 6622 | le16_to_cpu(event_data->VolDevHandle), |
| 6623 | event_data->PercentComplete); |
| 6624 | } |
| 6625 | #endif |
| 6626 | |
| 6627 | /** |
| 6628 | * _scsih_sas_ir_operation_status_event - handle RAID operation events |
| 6629 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6630 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6631 | * Context: user. |
| 6632 | * |
| 6633 | * Return nothing. |
| 6634 | */ |
| 6635 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6636 | _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc, |
| 6637 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6638 | { |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6639 | Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data; |
| 6640 | static struct _raid_device *raid_device; |
| 6641 | unsigned long flags; |
| 6642 | u16 handle; |
| 6643 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6644 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6645 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6646 | && !ioc->hide_ir_msg) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6647 | _scsih_sas_ir_operation_status_event_debug(ioc, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6648 | event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6649 | #endif |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6650 | |
| 6651 | /* code added for raid transport support */ |
| 6652 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { |
| 6653 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6654 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6655 | handle = le16_to_cpu(event_data->VolDevHandle); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6656 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6657 | if (raid_device) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6658 | raid_device->percent_complete = |
| 6659 | event_data->PercentComplete; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6660 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6661 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6662 | } |
| 6663 | |
| 6664 | /** |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6665 | * _scsih_prep_device_scan - initialize parameters prior to device scan |
| 6666 | * @ioc: per adapter object |
| 6667 | * |
| 6668 | * Set the deleted flag prior to device scan. If the device is found during |
| 6669 | * the scan, then we clear the deleted flag. |
| 6670 | */ |
| 6671 | static void |
| 6672 | _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc) |
| 6673 | { |
| 6674 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 6675 | struct scsi_device *sdev; |
| 6676 | |
| 6677 | shost_for_each_device(sdev, ioc->shost) { |
| 6678 | sas_device_priv_data = sdev->hostdata; |
| 6679 | if (sas_device_priv_data && sas_device_priv_data->sas_target) |
| 6680 | sas_device_priv_data->sas_target->deleted = 1; |
| 6681 | } |
| 6682 | } |
| 6683 | |
| 6684 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6685 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding |
| 6686 | * @ioc: per adapter object |
| 6687 | * @sas_address: sas address |
| 6688 | * @slot: enclosure slot id |
| 6689 | * @handle: device handle |
| 6690 | * |
| 6691 | * After host reset, find out whether devices are still responding. |
| 6692 | * Used in _scsi_remove_unresponsive_sas_devices. |
| 6693 | * |
| 6694 | * Return nothing. |
| 6695 | */ |
| 6696 | static void |
| 6697 | _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 6698 | u16 slot, u16 handle) |
| 6699 | { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6700 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6701 | struct scsi_target *starget; |
| 6702 | struct _sas_device *sas_device; |
| 6703 | unsigned long flags; |
| 6704 | |
| 6705 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6706 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { |
| 6707 | if (sas_device->sas_address == sas_address && |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6708 | sas_device->slot == slot) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6709 | sas_device->responding = 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6710 | starget = sas_device->starget; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6711 | if (starget && starget->hostdata) { |
| 6712 | sas_target_priv_data = starget->hostdata; |
| 6713 | sas_target_priv_data->tm_busy = 0; |
| 6714 | sas_target_priv_data->deleted = 0; |
| 6715 | } else |
| 6716 | sas_target_priv_data = NULL; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6717 | if (starget) |
| 6718 | starget_printk(KERN_INFO, starget, |
| 6719 | "handle(0x%04x), sas_addr(0x%016llx), " |
| 6720 | "enclosure logical id(0x%016llx), " |
| 6721 | "slot(%d)\n", handle, |
| 6722 | (unsigned long long)sas_device->sas_address, |
| 6723 | (unsigned long long) |
| 6724 | sas_device->enclosure_logical_id, |
| 6725 | sas_device->slot); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6726 | if (sas_device->handle == handle) |
| 6727 | goto out; |
| 6728 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 6729 | sas_device->handle); |
| 6730 | sas_device->handle = handle; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6731 | if (sas_target_priv_data) |
| 6732 | sas_target_priv_data->handle = handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6733 | goto out; |
| 6734 | } |
| 6735 | } |
| 6736 | out: |
| 6737 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6738 | } |
| 6739 | |
| 6740 | /** |
| 6741 | * _scsih_search_responding_sas_devices - |
| 6742 | * @ioc: per adapter object |
| 6743 | * |
| 6744 | * After host reset, find out whether devices are still responding. |
| 6745 | * If not remove. |
| 6746 | * |
| 6747 | * Return nothing. |
| 6748 | */ |
| 6749 | static void |
| 6750 | _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6751 | { |
| 6752 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6753 | Mpi2ConfigReply_t mpi_reply; |
| 6754 | u16 ioc_status; |
| 6755 | __le64 sas_address; |
| 6756 | u16 handle; |
| 6757 | u32 device_info; |
| 6758 | u16 slot; |
| 6759 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6760 | printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6761 | |
| 6762 | if (list_empty(&ioc->sas_device_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6763 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6764 | |
| 6765 | handle = 0xFFFF; |
| 6766 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6767 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 6768 | handle))) { |
| 6769 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6770 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 1c50e8d | 2013-07-25 11:29:45 +0530 | [diff] [blame] | 6771 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6772 | break; |
| 6773 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 6774 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 6775 | if (!(_scsih_is_end_device(device_info))) |
| 6776 | continue; |
| 6777 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 6778 | slot = le16_to_cpu(sas_device_pg0.Slot); |
| 6779 | _scsih_mark_responding_sas_device(ioc, sas_address, slot, |
| 6780 | handle); |
| 6781 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6782 | out: |
| 6783 | printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n", |
| 6784 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6785 | } |
| 6786 | |
| 6787 | /** |
| 6788 | * _scsih_mark_responding_raid_device - mark a raid_device as responding |
| 6789 | * @ioc: per adapter object |
| 6790 | * @wwid: world wide identifier for raid volume |
| 6791 | * @handle: device handle |
| 6792 | * |
| 6793 | * After host reset, find out whether devices are still responding. |
| 6794 | * Used in _scsi_remove_unresponsive_raid_devices. |
| 6795 | * |
| 6796 | * Return nothing. |
| 6797 | */ |
| 6798 | static void |
| 6799 | _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid, |
| 6800 | u16 handle) |
| 6801 | { |
| 6802 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 6803 | struct scsi_target *starget; |
| 6804 | struct _raid_device *raid_device; |
| 6805 | unsigned long flags; |
| 6806 | |
| 6807 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6808 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 6809 | if (raid_device->wwid == wwid && raid_device->starget) { |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6810 | starget = raid_device->starget; |
| 6811 | if (starget && starget->hostdata) { |
| 6812 | sas_target_priv_data = starget->hostdata; |
| 6813 | sas_target_priv_data->deleted = 0; |
| 6814 | } else |
| 6815 | sas_target_priv_data = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6816 | raid_device->responding = 1; |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6817 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6818 | starget_printk(KERN_INFO, raid_device->starget, |
| 6819 | "handle(0x%04x), wwid(0x%016llx)\n", handle, |
| 6820 | (unsigned long long)raid_device->wwid); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6821 | /* |
| 6822 | * WARPDRIVE: The handles of the PDs might have changed |
| 6823 | * across the host reset so re-initialize the |
| 6824 | * required data for Direct IO |
| 6825 | */ |
| 6826 | _scsih_init_warpdrive_properties(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6827 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6828 | if (raid_device->handle == handle) { |
| 6829 | spin_unlock_irqrestore(&ioc->raid_device_lock, |
| 6830 | flags); |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6831 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6832 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6833 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 6834 | raid_device->handle); |
| 6835 | raid_device->handle = handle; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6836 | if (sas_target_priv_data) |
| 6837 | sas_target_priv_data->handle = handle; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6838 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6839 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6840 | } |
| 6841 | } |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6842 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6843 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6844 | } |
| 6845 | |
| 6846 | /** |
| 6847 | * _scsih_search_responding_raid_devices - |
| 6848 | * @ioc: per adapter object |
| 6849 | * |
| 6850 | * After host reset, find out whether devices are still responding. |
| 6851 | * If not remove. |
| 6852 | * |
| 6853 | * Return nothing. |
| 6854 | */ |
| 6855 | static void |
| 6856 | _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6857 | { |
| 6858 | Mpi2RaidVolPage1_t volume_pg1; |
Kashyap, Desai | d417d1c | 2010-06-17 13:48:10 +0530 | [diff] [blame] | 6859 | Mpi2RaidVolPage0_t volume_pg0; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6860 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6861 | Mpi2ConfigReply_t mpi_reply; |
| 6862 | u16 ioc_status; |
| 6863 | u16 handle; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6864 | u8 phys_disk_num; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6865 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6866 | if (!ioc->ir_firmware) |
| 6867 | return; |
| 6868 | |
| 6869 | printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n", |
| 6870 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6871 | |
| 6872 | if (list_empty(&ioc->raid_device_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6873 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6874 | |
| 6875 | handle = 0xFFFF; |
| 6876 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 6877 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 6878 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6879 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 1c50e8d | 2013-07-25 11:29:45 +0530 | [diff] [blame] | 6880 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6881 | break; |
| 6882 | handle = le16_to_cpu(volume_pg1.DevHandle); |
Kashyap, Desai | d417d1c | 2010-06-17 13:48:10 +0530 | [diff] [blame] | 6883 | |
| 6884 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 6885 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 6886 | sizeof(Mpi2RaidVolPage0_t))) |
| 6887 | continue; |
| 6888 | |
| 6889 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 6890 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 6891 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) |
| 6892 | _scsih_mark_responding_raid_device(ioc, |
| 6893 | le64_to_cpu(volume_pg1.WWID), handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6894 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6895 | |
| 6896 | /* refresh the pd_handles */ |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6897 | if (!ioc->is_warpdrive) { |
| 6898 | phys_disk_num = 0xFF; |
| 6899 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); |
| 6900 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 6901 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 6902 | phys_disk_num))) { |
| 6903 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6904 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 1c50e8d | 2013-07-25 11:29:45 +0530 | [diff] [blame] | 6905 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6906 | break; |
| 6907 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 6908 | handle = le16_to_cpu(pd_pg0.DevHandle); |
| 6909 | set_bit(handle, ioc->pd_handles); |
| 6910 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6911 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6912 | out: |
| 6913 | printk(MPT2SAS_INFO_FMT "search for responding raid volumes: " |
| 6914 | "complete\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6915 | } |
| 6916 | |
| 6917 | /** |
| 6918 | * _scsih_mark_responding_expander - mark a expander as responding |
| 6919 | * @ioc: per adapter object |
| 6920 | * @sas_address: sas address |
| 6921 | * @handle: |
| 6922 | * |
| 6923 | * After host reset, find out whether devices are still responding. |
| 6924 | * Used in _scsi_remove_unresponsive_expanders. |
| 6925 | * |
| 6926 | * Return nothing. |
| 6927 | */ |
| 6928 | static void |
| 6929 | _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 6930 | u16 handle) |
| 6931 | { |
| 6932 | struct _sas_node *sas_expander; |
| 6933 | unsigned long flags; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6934 | int i; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6935 | |
| 6936 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 6937 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6938 | if (sas_expander->sas_address != sas_address) |
| 6939 | continue; |
| 6940 | sas_expander->responding = 1; |
| 6941 | if (sas_expander->handle == handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6942 | goto out; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6943 | printk(KERN_INFO "\texpander(0x%016llx): handle changed" |
| 6944 | " from(0x%04x) to (0x%04x)!!!\n", |
| 6945 | (unsigned long long)sas_expander->sas_address, |
| 6946 | sas_expander->handle, handle); |
| 6947 | sas_expander->handle = handle; |
| 6948 | for (i = 0 ; i < sas_expander->num_phys ; i++) |
| 6949 | sas_expander->phy[i].handle = handle; |
| 6950 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6951 | } |
| 6952 | out: |
| 6953 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 6954 | } |
| 6955 | |
| 6956 | /** |
| 6957 | * _scsih_search_responding_expanders - |
| 6958 | * @ioc: per adapter object |
| 6959 | * |
| 6960 | * After host reset, find out whether devices are still responding. |
| 6961 | * If not remove. |
| 6962 | * |
| 6963 | * Return nothing. |
| 6964 | */ |
| 6965 | static void |
| 6966 | _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc) |
| 6967 | { |
| 6968 | Mpi2ExpanderPage0_t expander_pg0; |
| 6969 | Mpi2ConfigReply_t mpi_reply; |
| 6970 | u16 ioc_status; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 6971 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6972 | u16 handle; |
| 6973 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6974 | printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6975 | |
| 6976 | if (list_empty(&ioc->sas_expander_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6977 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6978 | |
| 6979 | handle = 0xFFFF; |
| 6980 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 6981 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 6982 | |
| 6983 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6984 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 1c50e8d | 2013-07-25 11:29:45 +0530 | [diff] [blame] | 6985 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6986 | break; |
| 6987 | |
| 6988 | handle = le16_to_cpu(expander_pg0.DevHandle); |
| 6989 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
| 6990 | printk(KERN_INFO "\texpander present: handle(0x%04x), " |
| 6991 | "sas_addr(0x%016llx)\n", handle, |
| 6992 | (unsigned long long)sas_address); |
| 6993 | _scsih_mark_responding_expander(ioc, sas_address, handle); |
| 6994 | } |
| 6995 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6996 | out: |
| 6997 | printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6998 | } |
| 6999 | |
| 7000 | /** |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7001 | * _scsih_remove_unresponding_sas_devices - removing unresponding devices |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7002 | * @ioc: per adapter object |
| 7003 | * |
| 7004 | * Return nothing. |
| 7005 | */ |
| 7006 | static void |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7007 | _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7008 | { |
| 7009 | struct _sas_device *sas_device, *sas_device_next; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7010 | struct _sas_node *sas_expander, *sas_expander_next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7011 | struct _raid_device *raid_device, *raid_device_next; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7012 | struct list_head tmp_list; |
| 7013 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7014 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7015 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n", |
| 7016 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7017 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7018 | /* removing unresponding end devices */ |
| 7019 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n", |
| 7020 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7021 | list_for_each_entry_safe(sas_device, sas_device_next, |
| 7022 | &ioc->sas_device_list, list) { |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7023 | if (!sas_device->responding) |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 7024 | mpt2sas_device_remove_by_sas_address(ioc, |
| 7025 | sas_device->sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7026 | else |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7027 | sas_device->responding = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7028 | } |
| 7029 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7030 | /* removing unresponding volumes */ |
| 7031 | if (ioc->ir_firmware) { |
| 7032 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: " |
| 7033 | "volumes\n", ioc->name); |
| 7034 | list_for_each_entry_safe(raid_device, raid_device_next, |
| 7035 | &ioc->raid_device_list, list) { |
| 7036 | if (!raid_device->responding) |
| 7037 | _scsih_sas_volume_delete(ioc, |
| 7038 | raid_device->handle); |
| 7039 | else |
| 7040 | raid_device->responding = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7041 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7042 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7043 | /* removing unresponding expanders */ |
| 7044 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n", |
| 7045 | ioc->name); |
| 7046 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 7047 | INIT_LIST_HEAD(&tmp_list); |
| 7048 | list_for_each_entry_safe(sas_expander, sas_expander_next, |
| 7049 | &ioc->sas_expander_list, list) { |
| 7050 | if (!sas_expander->responding) |
| 7051 | list_move_tail(&sas_expander->list, &tmp_list); |
| 7052 | else |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7053 | sas_expander->responding = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7054 | } |
| 7055 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 7056 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, |
| 7057 | list) { |
| 7058 | list_del(&sas_expander->list); |
| 7059 | _scsih_expander_node_remove(ioc, sas_expander); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7060 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7061 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n", |
| 7062 | ioc->name); |
| 7063 | /* unblock devices */ |
| 7064 | _scsih_ublock_io_all_device(ioc); |
| 7065 | } |
| 7066 | |
| 7067 | static void |
| 7068 | _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc, |
| 7069 | struct _sas_node *sas_expander, u16 handle) |
| 7070 | { |
| 7071 | Mpi2ExpanderPage1_t expander_pg1; |
| 7072 | Mpi2ConfigReply_t mpi_reply; |
| 7073 | int i; |
| 7074 | |
| 7075 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 7076 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 7077 | &expander_pg1, i, handle))) { |
| 7078 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7079 | ioc->name, __FILE__, __LINE__, __func__); |
| 7080 | return; |
| 7081 | } |
| 7082 | |
| 7083 | mpt2sas_transport_update_links(ioc, sas_expander->sas_address, |
| 7084 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, |
| 7085 | expander_pg1.NegotiatedLinkRate >> 4); |
| 7086 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7087 | } |
| 7088 | |
| 7089 | /** |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7090 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7091 | * @ioc: per adapter object |
| 7092 | * |
| 7093 | * Return nothing. |
| 7094 | */ |
| 7095 | static void |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7096 | _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc) |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7097 | { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7098 | Mpi2ExpanderPage0_t expander_pg0; |
| 7099 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 7100 | Mpi2RaidVolPage1_t volume_pg1; |
| 7101 | Mpi2RaidVolPage0_t volume_pg0; |
| 7102 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 7103 | Mpi2EventIrConfigElement_t element; |
| 7104 | Mpi2ConfigReply_t mpi_reply; |
| 7105 | u8 phys_disk_num; |
| 7106 | u16 ioc_status; |
| 7107 | u16 handle, parent_handle; |
| 7108 | u64 sas_address; |
| 7109 | struct _sas_device *sas_device; |
| 7110 | struct _sas_node *expander_device; |
| 7111 | static struct _raid_device *raid_device; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7112 | u8 retry_count; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7113 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7114 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7115 | printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7116 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7117 | _scsih_sas_host_refresh(ioc); |
| 7118 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7119 | printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n", |
| 7120 | ioc->name); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7121 | /* expanders */ |
| 7122 | handle = 0xFFFF; |
| 7123 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 7124 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 7125 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7126 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7127 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7128 | printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: " |
| 7129 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7130 | ioc->name, ioc_status, |
| 7131 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7132 | break; |
| 7133 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7134 | handle = le16_to_cpu(expander_pg0.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7135 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7136 | expander_device = mpt2sas_scsih_expander_find_by_sas_address( |
| 7137 | ioc, le64_to_cpu(expander_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7138 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7139 | if (expander_device) |
| 7140 | _scsih_refresh_expander_links(ioc, expander_device, |
| 7141 | handle); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7142 | else { |
| 7143 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: " |
| 7144 | "handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7145 | ioc->name, handle, (unsigned long long) |
| 7146 | le64_to_cpu(expander_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7147 | _scsih_expander_add(ioc, handle); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7148 | printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: " |
| 7149 | "handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7150 | ioc->name, handle, (unsigned long long) |
| 7151 | le64_to_cpu(expander_pg0.SASAddress)); |
| 7152 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7153 | } |
| 7154 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7155 | printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n", |
| 7156 | ioc->name); |
| 7157 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7158 | if (!ioc->ir_firmware) |
| 7159 | goto skip_to_sas; |
| 7160 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7161 | printk(MPT2SAS_INFO_FMT "\tscan devices phys disk start\n", ioc->name); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7162 | /* phys disk */ |
| 7163 | phys_disk_num = 0xFF; |
| 7164 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 7165 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 7166 | phys_disk_num))) { |
| 7167 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7168 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7169 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7170 | printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:" |
| 7171 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7172 | ioc->name, ioc_status, |
| 7173 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7174 | break; |
| 7175 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7176 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 7177 | handle = le16_to_cpu(pd_pg0.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7178 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7179 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7180 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7181 | if (sas_device) |
| 7182 | continue; |
| 7183 | if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 7184 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 7185 | handle) != 0) |
| 7186 | continue; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7187 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7188 | MPI2_IOCSTATUS_MASK; |
| 7189 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7190 | printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan " |
| 7191 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7192 | ioc->name, ioc_status, |
| 7193 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7194 | break; |
| 7195 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7196 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 7197 | if (!_scsih_get_sas_address(ioc, parent_handle, |
| 7198 | &sas_address)) { |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7199 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: " |
| 7200 | " handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7201 | ioc->name, handle, (unsigned long long) |
| 7202 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7203 | mpt2sas_transport_update_links(ioc, sas_address, |
| 7204 | handle, sas_device_pg0.PhyNum, |
| 7205 | MPI2_SAS_NEG_LINK_RATE_1_5); |
| 7206 | set_bit(handle, ioc->pd_handles); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7207 | retry_count = 0; |
| 7208 | /* This will retry adding the end device. |
| 7209 | * _scsih_add_device() will decide on retries and |
| 7210 | * return "1" when it should be retried |
| 7211 | */ |
| 7212 | while (_scsih_add_device(ioc, handle, retry_count++, |
| 7213 | 1)) { |
| 7214 | ssleep(1); |
| 7215 | } |
| 7216 | printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: " |
| 7217 | " handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7218 | ioc->name, handle, (unsigned long long) |
| 7219 | le64_to_cpu(sas_device_pg0.SASAddress)); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7220 | } |
| 7221 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7222 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7223 | printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n", |
| 7224 | ioc->name); |
| 7225 | |
| 7226 | printk(MPT2SAS_INFO_FMT "\tscan devices: volumes start\n", ioc->name); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7227 | /* volumes */ |
| 7228 | handle = 0xFFFF; |
| 7229 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 7230 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 7231 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7232 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7233 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7234 | printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: " |
| 7235 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7236 | ioc->name, ioc_status, |
| 7237 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7238 | break; |
| 7239 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7240 | handle = le16_to_cpu(volume_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7241 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7242 | raid_device = _scsih_raid_device_find_by_wwid(ioc, |
| 7243 | le64_to_cpu(volume_pg1.WWID)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7244 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7245 | if (raid_device) |
| 7246 | continue; |
| 7247 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 7248 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 7249 | sizeof(Mpi2RaidVolPage0_t))) |
| 7250 | continue; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7251 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7252 | MPI2_IOCSTATUS_MASK; |
| 7253 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7254 | printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: " |
| 7255 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7256 | ioc->name, ioc_status, |
| 7257 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7258 | break; |
| 7259 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7260 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 7261 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 7262 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { |
| 7263 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); |
| 7264 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; |
| 7265 | element.VolDevHandle = volume_pg1.DevHandle; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7266 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: " |
| 7267 | " handle (0x%04x)\n", ioc->name, |
| 7268 | volume_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7269 | _scsih_sas_volume_add(ioc, &element); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7270 | printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: " |
| 7271 | " handle (0x%04x)\n", ioc->name, |
| 7272 | volume_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7273 | } |
| 7274 | } |
| 7275 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7276 | printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n", |
| 7277 | ioc->name); |
| 7278 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7279 | skip_to_sas: |
| 7280 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7281 | printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n", |
| 7282 | ioc->name); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7283 | /* sas devices */ |
| 7284 | handle = 0xFFFF; |
| 7285 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 7286 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 7287 | handle))) { |
| 7288 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7289 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7290 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7291 | printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:" |
| 7292 | " ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7293 | ioc->name, ioc_status, |
| 7294 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7295 | break; |
| 7296 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7297 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 7298 | if (!(_scsih_is_end_device( |
| 7299 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) |
| 7300 | continue; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7301 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7302 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 7303 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7304 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7305 | if (sas_device) |
| 7306 | continue; |
| 7307 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 7308 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7309 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: " |
| 7310 | "handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7311 | ioc->name, handle, (unsigned long long) |
| 7312 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7313 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 7314 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7315 | retry_count = 0; |
| 7316 | /* This will retry adding the end device. |
| 7317 | * _scsih_add_device() will decide on retries and |
| 7318 | * return "1" when it should be retried |
| 7319 | */ |
| 7320 | while (_scsih_add_device(ioc, handle, retry_count++, |
| 7321 | 0)) { |
| 7322 | ssleep(1); |
| 7323 | } |
| 7324 | printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: " |
| 7325 | "handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7326 | ioc->name, handle, (unsigned long long) |
| 7327 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7328 | } |
| 7329 | } |
| 7330 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7331 | printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n", |
| 7332 | ioc->name); |
| 7333 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7334 | printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7335 | } |
| 7336 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7337 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7338 | /** |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7339 | * mpt2sas_scsih_reset_handler - reset callback handler (for scsih) |
| 7340 | * @ioc: per adapter object |
| 7341 | * @reset_phase: phase |
| 7342 | * |
| 7343 | * The handler for doing any required cleanup or initialization. |
| 7344 | * |
| 7345 | * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET, |
| 7346 | * MPT2_IOC_DONE_RESET |
| 7347 | * |
| 7348 | * Return nothing. |
| 7349 | */ |
| 7350 | void |
| 7351 | mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase) |
| 7352 | { |
| 7353 | switch (reset_phase) { |
| 7354 | case MPT2_IOC_PRE_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7355 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7356 | "MPT2_IOC_PRE_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7357 | break; |
| 7358 | case MPT2_IOC_AFTER_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7359 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7360 | "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7361 | if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) { |
| 7362 | ioc->scsih_cmds.status |= MPT2_CMD_RESET; |
| 7363 | mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid); |
| 7364 | complete(&ioc->scsih_cmds.done); |
| 7365 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7366 | if (ioc->tm_cmds.status & MPT2_CMD_PENDING) { |
| 7367 | ioc->tm_cmds.status |= MPT2_CMD_RESET; |
| 7368 | mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid); |
| 7369 | complete(&ioc->tm_cmds.done); |
| 7370 | } |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7371 | _scsih_fw_event_cleanup_queue(ioc); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7372 | _scsih_flush_running_cmds(ioc); |
| 7373 | break; |
| 7374 | case MPT2_IOC_DONE_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7375 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7376 | "MPT2_IOC_DONE_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7377 | _scsih_sas_host_refresh(ioc); |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 7378 | _scsih_prep_device_scan(ioc); |
| 7379 | _scsih_search_responding_sas_devices(ioc); |
| 7380 | _scsih_search_responding_raid_devices(ioc); |
| 7381 | _scsih_search_responding_expanders(ioc); |
sreekanth.reddy@lsi.com | 14aa7f7 | 2012-07-17 15:56:13 +0530 | [diff] [blame] | 7382 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && |
| 7383 | !ioc->sas_hba.num_phys)) { |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7384 | _scsih_prep_device_scan(ioc); |
| 7385 | _scsih_search_responding_sas_devices(ioc); |
| 7386 | _scsih_search_responding_raid_devices(ioc); |
| 7387 | _scsih_search_responding_expanders(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7388 | _scsih_error_recovery_delete_devices(ioc); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7389 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7390 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7391 | } |
| 7392 | } |
| 7393 | |
| 7394 | /** |
| 7395 | * _firmware_event_work - delayed task for processing firmware events |
| 7396 | * @ioc: per adapter object |
| 7397 | * @work: equal to the fw_event_work object |
| 7398 | * Context: user. |
| 7399 | * |
| 7400 | * Return nothing. |
| 7401 | */ |
| 7402 | static void |
| 7403 | _firmware_event_work(struct work_struct *work) |
| 7404 | { |
| 7405 | struct fw_event_work *fw_event = container_of(work, |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7406 | struct fw_event_work, delayed_work.work); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7407 | struct MPT2SAS_ADAPTER *ioc = fw_event->ioc; |
| 7408 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7409 | /* the queue is being flushed so ignore this event */ |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7410 | if (ioc->remove_host || fw_event->cancel_pending_work || |
| 7411 | ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7412 | _scsih_fw_event_free(ioc, fw_event); |
| 7413 | return; |
| 7414 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7415 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7416 | switch (fw_event->event) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7417 | case MPT2SAS_REMOVE_UNRESPONDING_DEVICES: |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7418 | while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7419 | ssleep(1); |
| 7420 | _scsih_remove_unresponding_sas_devices(ioc); |
| 7421 | _scsih_scan_for_devices_after_reset(ioc); |
| 7422 | break; |
| 7423 | case MPT2SAS_PORT_ENABLE_COMPLETE: |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7424 | ioc->start_scan = 0; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7425 | |
Reddy, Sreekanth | b0df96a0 | 2013-02-26 16:59:59 +0530 | [diff] [blame] | 7426 | if (missing_delay[0] != -1 && missing_delay[1] != -1) |
| 7427 | mpt2sas_base_update_missing_delay(ioc, missing_delay[0], |
| 7428 | missing_delay[1]); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7429 | |
| 7430 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete " |
| 7431 | "from worker thread\n", ioc->name)); |
| 7432 | break; |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 7433 | case MPT2SAS_TURN_ON_FAULT_LED: |
| 7434 | _scsih_turn_on_fault_led(ioc, fw_event->device_handle); |
| 7435 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7436 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7437 | _scsih_sas_topology_change_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7438 | break; |
| 7439 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7440 | _scsih_sas_device_status_change_event(ioc, |
| 7441 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7442 | break; |
| 7443 | case MPI2_EVENT_SAS_DISCOVERY: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7444 | _scsih_sas_discovery_event(ioc, |
| 7445 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7446 | break; |
| 7447 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 7448 | _scsih_sas_broadcast_primitive_event(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7449 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7450 | break; |
| 7451 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
| 7452 | _scsih_sas_enclosure_dev_status_change_event(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7453 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7454 | break; |
| 7455 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7456 | _scsih_sas_ir_config_change_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7457 | break; |
| 7458 | case MPI2_EVENT_IR_VOLUME: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7459 | _scsih_sas_ir_volume_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7460 | break; |
| 7461 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7462 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7463 | break; |
| 7464 | case MPI2_EVENT_IR_OPERATION_STATUS: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7465 | _scsih_sas_ir_operation_status_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7466 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7467 | } |
| 7468 | _scsih_fw_event_free(ioc, fw_event); |
| 7469 | } |
| 7470 | |
| 7471 | /** |
| 7472 | * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time) |
| 7473 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7474 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7475 | * @reply: reply message frame(lower 32bit addr) |
| 7476 | * Context: interrupt. |
| 7477 | * |
| 7478 | * This function merely adds a new work task into ioc->firmware_event_thread. |
| 7479 | * The tasks are worked from _firmware_event_work in user context. |
| 7480 | * |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7481 | * Returns void. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7482 | */ |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7483 | void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7484 | mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, |
| 7485 | u32 reply) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7486 | { |
| 7487 | struct fw_event_work *fw_event; |
| 7488 | Mpi2EventNotificationReply_t *mpi_reply; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7489 | u16 event; |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 7490 | u16 sz; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7491 | |
| 7492 | /* events turned off due to host reset or driver unloading */ |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7493 | if (ioc->remove_host || ioc->pci_error_recovery) |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7494 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7495 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7496 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 7497 | |
| 7498 | if (unlikely(!mpi_reply)) { |
| 7499 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 7500 | ioc->name, __FILE__, __LINE__, __func__); |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7501 | return; |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 7502 | } |
| 7503 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7504 | event = le16_to_cpu(mpi_reply->Event); |
| 7505 | |
| 7506 | switch (event) { |
| 7507 | /* handle these */ |
| 7508 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 7509 | { |
| 7510 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = |
| 7511 | (Mpi2EventDataSasBroadcastPrimitive_t *) |
| 7512 | mpi_reply->EventData; |
| 7513 | |
| 7514 | if (baen_data->Primitive != |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7515 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7516 | return; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7517 | |
| 7518 | if (ioc->broadcast_aen_busy) { |
| 7519 | ioc->broadcast_aen_pending++; |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7520 | return; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7521 | } else |
| 7522 | ioc->broadcast_aen_busy = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7523 | break; |
| 7524 | } |
| 7525 | |
| 7526 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
| 7527 | _scsih_check_topo_delete_events(ioc, |
| 7528 | (Mpi2EventDataSasTopologyChangeList_t *) |
| 7529 | mpi_reply->EventData); |
| 7530 | break; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 7531 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
| 7532 | _scsih_check_ir_config_unhide_events(ioc, |
| 7533 | (Mpi2EventDataIrConfigChangeList_t *) |
| 7534 | mpi_reply->EventData); |
| 7535 | break; |
| 7536 | case MPI2_EVENT_IR_VOLUME: |
| 7537 | _scsih_check_volume_delete_events(ioc, |
| 7538 | (Mpi2EventDataIrVolume_t *) |
| 7539 | mpi_reply->EventData); |
| 7540 | break; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7541 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
| 7542 | { |
| 7543 | Mpi2EventDataLogEntryAdded_t *log_entry; |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 7544 | __le32 *log_code; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7545 | |
| 7546 | if (!ioc->is_warpdrive) |
| 7547 | break; |
| 7548 | |
| 7549 | log_entry = (Mpi2EventDataLogEntryAdded_t *) |
| 7550 | mpi_reply->EventData; |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 7551 | log_code = (__le32 *)log_entry->LogData; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7552 | |
| 7553 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
| 7554 | != MPT2_WARPDRIVE_LOGENTRY) |
| 7555 | break; |
| 7556 | |
| 7557 | switch (le32_to_cpu(*log_code)) { |
| 7558 | case MPT2_WARPDRIVE_LC_SSDT: |
| 7559 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " |
| 7560 | "IO Throttling has occurred in the WarpDrive " |
| 7561 | "subsystem. Check WarpDrive documentation for " |
| 7562 | "additional details.\n", ioc->name); |
| 7563 | break; |
| 7564 | case MPT2_WARPDRIVE_LC_SSDLW: |
| 7565 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " |
| 7566 | "Program/Erase Cycles for the WarpDrive subsystem " |
| 7567 | "in degraded range. Check WarpDrive documentation " |
| 7568 | "for additional details.\n", ioc->name); |
| 7569 | break; |
| 7570 | case MPT2_WARPDRIVE_LC_SSDLF: |
| 7571 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " |
| 7572 | "There are no Program/Erase Cycles for the " |
| 7573 | "WarpDrive subsystem. The storage device will be " |
| 7574 | "in read-only mode. Check WarpDrive documentation " |
| 7575 | "for additional details.\n", ioc->name); |
| 7576 | break; |
| 7577 | case MPT2_WARPDRIVE_LC_BRMF: |
| 7578 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " |
| 7579 | "The Backup Rail Monitor has failed on the " |
| 7580 | "WarpDrive subsystem. Check WarpDrive " |
| 7581 | "documentation for additional details.\n", |
| 7582 | ioc->name); |
| 7583 | break; |
| 7584 | } |
| 7585 | |
| 7586 | break; |
| 7587 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7588 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 7589 | case MPI2_EVENT_IR_OPERATION_STATUS: |
| 7590 | case MPI2_EVENT_SAS_DISCOVERY: |
| 7591 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7592 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7593 | break; |
| 7594 | |
| 7595 | default: /* ignore the rest */ |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7596 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7597 | } |
| 7598 | |
| 7599 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 7600 | if (!fw_event) { |
| 7601 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7602 | ioc->name, __FILE__, __LINE__, __func__); |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7603 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7604 | } |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 7605 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
| 7606 | fw_event->event_data = kzalloc(sz, GFP_ATOMIC); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7607 | if (!fw_event->event_data) { |
| 7608 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7609 | ioc->name, __FILE__, __LINE__, __func__); |
| 7610 | kfree(fw_event); |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7611 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7612 | } |
| 7613 | |
| 7614 | memcpy(fw_event->event_data, mpi_reply->EventData, |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 7615 | sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7616 | fw_event->ioc = ioc; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7617 | fw_event->VF_ID = mpi_reply->VF_ID; |
| 7618 | fw_event->VP_ID = mpi_reply->VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7619 | fw_event->event = event; |
| 7620 | _scsih_fw_event_add(ioc, fw_event); |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7621 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7622 | } |
| 7623 | |
| 7624 | /* shost template */ |
| 7625 | static struct scsi_host_template scsih_driver_template = { |
| 7626 | .module = THIS_MODULE, |
| 7627 | .name = "Fusion MPT SAS Host", |
| 7628 | .proc_name = MPT2SAS_DRIVER_NAME, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7629 | .queuecommand = _scsih_qcmd, |
| 7630 | .target_alloc = _scsih_target_alloc, |
| 7631 | .slave_alloc = _scsih_slave_alloc, |
| 7632 | .slave_configure = _scsih_slave_configure, |
| 7633 | .target_destroy = _scsih_target_destroy, |
| 7634 | .slave_destroy = _scsih_slave_destroy, |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7635 | .scan_finished = _scsih_scan_finished, |
| 7636 | .scan_start = _scsih_scan_start, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7637 | .change_queue_depth = _scsih_change_queue_depth, |
| 7638 | .change_queue_type = _scsih_change_queue_type, |
| 7639 | .eh_abort_handler = _scsih_abort, |
| 7640 | .eh_device_reset_handler = _scsih_dev_reset, |
| 7641 | .eh_target_reset_handler = _scsih_target_reset, |
| 7642 | .eh_host_reset_handler = _scsih_host_reset, |
| 7643 | .bios_param = _scsih_bios_param, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7644 | .can_queue = 1, |
| 7645 | .this_id = -1, |
| 7646 | .sg_tablesize = MPT2SAS_SG_DEPTH, |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 7647 | .max_sectors = 32767, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7648 | .cmd_per_lun = 7, |
| 7649 | .use_clustering = ENABLE_CLUSTERING, |
| 7650 | .shost_attrs = mpt2sas_host_attrs, |
| 7651 | .sdev_attrs = mpt2sas_dev_attrs, |
| 7652 | }; |
| 7653 | |
| 7654 | /** |
| 7655 | * _scsih_expander_node_remove - removing expander device from list. |
| 7656 | * @ioc: per adapter object |
| 7657 | * @sas_expander: the sas_device object |
| 7658 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 7659 | * |
| 7660 | * Removing object and freeing associated memory from the |
| 7661 | * ioc->sas_expander_list. |
| 7662 | * |
| 7663 | * Return nothing. |
| 7664 | */ |
| 7665 | static void |
| 7666 | _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc, |
| 7667 | struct _sas_node *sas_expander) |
| 7668 | { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7669 | struct _sas_port *mpt2sas_port, *next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7670 | |
| 7671 | /* remove sibling ports attached to this expander */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7672 | list_for_each_entry_safe(mpt2sas_port, next, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7673 | &sas_expander->sas_port_list, port_list) { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7674 | if (ioc->shost_recovery) |
| 7675 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7676 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7677 | SAS_END_DEVICE) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7678 | mpt2sas_device_remove_by_sas_address(ioc, |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7679 | mpt2sas_port->remote_identify.sas_address); |
| 7680 | else if (mpt2sas_port->remote_identify.device_type == |
| 7681 | SAS_EDGE_EXPANDER_DEVICE || |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7682 | mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7683 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7684 | mpt2sas_expander_remove(ioc, |
| 7685 | mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7686 | } |
| 7687 | |
| 7688 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7689 | sas_expander->sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7690 | |
| 7691 | printk(MPT2SAS_INFO_FMT "expander_remove: handle" |
| 7692 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, |
| 7693 | sas_expander->handle, (unsigned long long) |
| 7694 | sas_expander->sas_address); |
| 7695 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7696 | kfree(sas_expander->phy); |
| 7697 | kfree(sas_expander); |
| 7698 | } |
| 7699 | |
| 7700 | /** |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7701 | * _scsih_ir_shutdown - IR shutdown notification |
| 7702 | * @ioc: per adapter object |
| 7703 | * |
| 7704 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that |
| 7705 | * the host system is shutting down. |
| 7706 | * |
| 7707 | * Return nothing. |
| 7708 | */ |
| 7709 | static void |
| 7710 | _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc) |
| 7711 | { |
| 7712 | Mpi2RaidActionRequest_t *mpi_request; |
| 7713 | Mpi2RaidActionReply_t *mpi_reply; |
| 7714 | u16 smid; |
| 7715 | |
| 7716 | /* is IR firmware build loaded ? */ |
| 7717 | if (!ioc->ir_firmware) |
| 7718 | return; |
| 7719 | |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7720 | mutex_lock(&ioc->scsih_cmds.mutex); |
| 7721 | |
| 7722 | if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) { |
| 7723 | printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n", |
| 7724 | ioc->name, __func__); |
| 7725 | goto out; |
| 7726 | } |
| 7727 | ioc->scsih_cmds.status = MPT2_CMD_PENDING; |
| 7728 | |
| 7729 | smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx); |
| 7730 | if (!smid) { |
| 7731 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 7732 | ioc->name, __func__); |
| 7733 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; |
| 7734 | goto out; |
| 7735 | } |
| 7736 | |
| 7737 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 7738 | ioc->scsih_cmds.smid = smid; |
| 7739 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); |
| 7740 | |
| 7741 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; |
| 7742 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; |
| 7743 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7744 | if (!ioc->hide_ir_msg) |
| 7745 | printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7746 | init_completion(&ioc->scsih_cmds.done); |
| 7747 | mpt2sas_base_put_smid_default(ioc, smid); |
| 7748 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
| 7749 | |
| 7750 | if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) { |
| 7751 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 7752 | ioc->name, __func__); |
| 7753 | goto out; |
| 7754 | } |
| 7755 | |
| 7756 | if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 7757 | mpi_reply = ioc->scsih_cmds.reply; |
| 7758 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7759 | if (!ioc->hide_ir_msg) |
| 7760 | printk(MPT2SAS_INFO_FMT "IR shutdown (complete): " |
| 7761 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7762 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 7763 | le32_to_cpu(mpi_reply->IOCLogInfo)); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7764 | } |
| 7765 | |
| 7766 | out: |
| 7767 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; |
| 7768 | mutex_unlock(&ioc->scsih_cmds.mutex); |
| 7769 | } |
| 7770 | |
| 7771 | /** |
| 7772 | * _scsih_shutdown - routine call during system shutdown |
| 7773 | * @pdev: PCI device struct |
| 7774 | * |
| 7775 | * Return nothing. |
| 7776 | */ |
| 7777 | static void |
| 7778 | _scsih_shutdown(struct pci_dev *pdev) |
| 7779 | { |
| 7780 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7781 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7782 | struct workqueue_struct *wq; |
| 7783 | unsigned long flags; |
| 7784 | |
| 7785 | ioc->remove_host = 1; |
| 7786 | _scsih_fw_event_cleanup_queue(ioc); |
| 7787 | |
| 7788 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7789 | wq = ioc->firmware_event_thread; |
| 7790 | ioc->firmware_event_thread = NULL; |
| 7791 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7792 | if (wq) |
| 7793 | destroy_workqueue(wq); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7794 | |
| 7795 | _scsih_ir_shutdown(ioc); |
| 7796 | mpt2sas_base_detach(ioc); |
| 7797 | } |
| 7798 | |
| 7799 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7800 | * _scsih_remove - detach and remove add host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7801 | * @pdev: PCI device struct |
| 7802 | * |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7803 | * Routine called when unloading the driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7804 | * Return nothing. |
| 7805 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7806 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7807 | _scsih_remove(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7808 | { |
| 7809 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7810 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7811 | struct _sas_port *mpt2sas_port, *next_port; |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7812 | struct _raid_device *raid_device, *next; |
| 7813 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7814 | struct workqueue_struct *wq; |
| 7815 | unsigned long flags; |
| 7816 | |
| 7817 | ioc->remove_host = 1; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7818 | _scsih_fw_event_cleanup_queue(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7819 | |
| 7820 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7821 | wq = ioc->firmware_event_thread; |
| 7822 | ioc->firmware_event_thread = NULL; |
| 7823 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7824 | if (wq) |
| 7825 | destroy_workqueue(wq); |
| 7826 | |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7827 | /* release all the volumes */ |
Kashyap, Desai | 3a9c913 | 2011-01-04 11:40:23 +0530 | [diff] [blame] | 7828 | _scsih_ir_shutdown(ioc); |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7829 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, |
| 7830 | list) { |
| 7831 | if (raid_device->starget) { |
| 7832 | sas_target_priv_data = |
| 7833 | raid_device->starget->hostdata; |
| 7834 | sas_target_priv_data->deleted = 1; |
| 7835 | scsi_remove_target(&raid_device->starget->dev); |
| 7836 | } |
| 7837 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" |
| 7838 | "(0x%016llx)\n", ioc->name, raid_device->handle, |
| 7839 | (unsigned long long) raid_device->wwid); |
| 7840 | _scsih_raid_device_remove(ioc, raid_device); |
| 7841 | } |
| 7842 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7843 | /* free ports attached to the sas_host */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7844 | list_for_each_entry_safe(mpt2sas_port, next_port, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7845 | &ioc->sas_hba.sas_port_list, port_list) { |
| 7846 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7847 | SAS_END_DEVICE) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7848 | mpt2sas_device_remove_by_sas_address(ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7849 | mpt2sas_port->remote_identify.sas_address); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7850 | else if (mpt2sas_port->remote_identify.device_type == |
| 7851 | SAS_EDGE_EXPANDER_DEVICE || |
| 7852 | mpt2sas_port->remote_identify.device_type == |
| 7853 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7854 | mpt2sas_expander_remove(ioc, |
| 7855 | mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7856 | } |
| 7857 | |
| 7858 | /* free phys attached to the sas_host */ |
| 7859 | if (ioc->sas_hba.num_phys) { |
| 7860 | kfree(ioc->sas_hba.phy); |
| 7861 | ioc->sas_hba.phy = NULL; |
| 7862 | ioc->sas_hba.num_phys = 0; |
| 7863 | } |
| 7864 | |
| 7865 | sas_remove_host(shost); |
kashyap.desai@lsi.com | 9ae89b0 | 2011-08-04 16:47:50 +0530 | [diff] [blame] | 7866 | mpt2sas_base_detach(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7867 | list_del(&ioc->list); |
| 7868 | scsi_remove_host(shost); |
| 7869 | scsi_host_put(shost); |
| 7870 | } |
| 7871 | |
| 7872 | /** |
| 7873 | * _scsih_probe_boot_devices - reports 1st device |
| 7874 | * @ioc: per adapter object |
| 7875 | * |
| 7876 | * If specified in bios page 2, this routine reports the 1st |
| 7877 | * device scsi-ml or sas transport for persistent boot device |
| 7878 | * purposes. Please refer to function _scsih_determine_boot_device() |
| 7879 | */ |
| 7880 | static void |
| 7881 | _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc) |
| 7882 | { |
| 7883 | u8 is_raid; |
| 7884 | void *device; |
| 7885 | struct _sas_device *sas_device; |
| 7886 | struct _raid_device *raid_device; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7887 | u16 handle; |
| 7888 | u64 sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7889 | u64 sas_address; |
| 7890 | unsigned long flags; |
| 7891 | int rc; |
| 7892 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7893 | /* no Bios, return immediately */ |
| 7894 | if (!ioc->bios_pg3.BiosVersion) |
| 7895 | return; |
| 7896 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7897 | device = NULL; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7898 | is_raid = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7899 | if (ioc->req_boot_device.device) { |
| 7900 | device = ioc->req_boot_device.device; |
| 7901 | is_raid = ioc->req_boot_device.is_raid; |
| 7902 | } else if (ioc->req_alt_boot_device.device) { |
| 7903 | device = ioc->req_alt_boot_device.device; |
| 7904 | is_raid = ioc->req_alt_boot_device.is_raid; |
| 7905 | } else if (ioc->current_boot_device.device) { |
| 7906 | device = ioc->current_boot_device.device; |
| 7907 | is_raid = ioc->current_boot_device.is_raid; |
| 7908 | } |
| 7909 | |
| 7910 | if (!device) |
| 7911 | return; |
| 7912 | |
| 7913 | if (is_raid) { |
| 7914 | raid_device = device; |
| 7915 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7916 | raid_device->id, 0); |
| 7917 | if (rc) |
| 7918 | _scsih_raid_device_remove(ioc, raid_device); |
| 7919 | } else { |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7920 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7921 | sas_device = device; |
| 7922 | handle = sas_device->handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7923 | sas_address_parent = sas_device->sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7924 | sas_address = sas_device->sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7925 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 7926 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7927 | |
| 7928 | if (ioc->hide_drives) |
| 7929 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7930 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7931 | sas_device->sas_address_parent)) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7932 | _scsih_sas_device_remove(ioc, sas_device); |
| 7933 | } else if (!sas_device->starget) { |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 7934 | if (!ioc->is_driver_loading) { |
| 7935 | mpt2sas_transport_port_remove(ioc, |
| 7936 | sas_address, |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 7937 | sas_address_parent); |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 7938 | _scsih_sas_device_remove(ioc, sas_device); |
| 7939 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7940 | } |
| 7941 | } |
| 7942 | } |
| 7943 | |
| 7944 | /** |
| 7945 | * _scsih_probe_raid - reporting raid volumes to scsi-ml |
| 7946 | * @ioc: per adapter object |
| 7947 | * |
| 7948 | * Called during initial loading of the driver. |
| 7949 | */ |
| 7950 | static void |
| 7951 | _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc) |
| 7952 | { |
| 7953 | struct _raid_device *raid_device, *raid_next; |
| 7954 | int rc; |
| 7955 | |
| 7956 | list_for_each_entry_safe(raid_device, raid_next, |
| 7957 | &ioc->raid_device_list, list) { |
| 7958 | if (raid_device->starget) |
| 7959 | continue; |
| 7960 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7961 | raid_device->id, 0); |
| 7962 | if (rc) |
| 7963 | _scsih_raid_device_remove(ioc, raid_device); |
| 7964 | } |
| 7965 | } |
| 7966 | |
| 7967 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7968 | * _scsih_probe_sas - reporting sas devices to sas transport |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7969 | * @ioc: per adapter object |
| 7970 | * |
| 7971 | * Called during initial loading of the driver. |
| 7972 | */ |
| 7973 | static void |
| 7974 | _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc) |
| 7975 | { |
| 7976 | struct _sas_device *sas_device, *next; |
| 7977 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7978 | |
| 7979 | /* SAS Device List */ |
| 7980 | list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list, |
| 7981 | list) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7982 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7983 | if (ioc->hide_drives) |
| 7984 | continue; |
| 7985 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7986 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
| 7987 | sas_device->sas_address_parent)) { |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 7988 | list_del(&sas_device->list); |
| 7989 | kfree(sas_device); |
| 7990 | continue; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7991 | } else if (!sas_device->starget) { |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 7992 | if (!ioc->is_driver_loading) { |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 7993 | mpt2sas_transport_port_remove(ioc, |
| 7994 | sas_device->sas_address, |
| 7995 | sas_device->sas_address_parent); |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 7996 | list_del(&sas_device->list); |
| 7997 | kfree(sas_device); |
| 7998 | continue; |
| 7999 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8000 | } |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 8001 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 8002 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 8003 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8004 | } |
| 8005 | } |
| 8006 | |
| 8007 | /** |
| 8008 | * _scsih_probe_devices - probing for devices |
| 8009 | * @ioc: per adapter object |
| 8010 | * |
| 8011 | * Called during initial loading of the driver. |
| 8012 | */ |
| 8013 | static void |
| 8014 | _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc) |
| 8015 | { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8016 | u16 volume_mapping_flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8017 | |
| 8018 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) |
| 8019 | return; /* return when IOC doesn't support initiator mode */ |
| 8020 | |
| 8021 | _scsih_probe_boot_devices(ioc); |
| 8022 | |
| 8023 | if (ioc->ir_firmware) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8024 | volume_mapping_flags = |
| 8025 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & |
| 8026 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; |
| 8027 | if (volume_mapping_flags == |
| 8028 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8029 | _scsih_probe_raid(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8030 | _scsih_probe_sas(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8031 | } else { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8032 | _scsih_probe_sas(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8033 | _scsih_probe_raid(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8034 | } |
| 8035 | } else |
| 8036 | _scsih_probe_sas(ioc); |
| 8037 | } |
| 8038 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8039 | |
| 8040 | /** |
| 8041 | * _scsih_scan_start - scsi lld callback for .scan_start |
| 8042 | * @shost: SCSI host pointer |
| 8043 | * |
| 8044 | * The shost has the ability to discover targets on its own instead |
| 8045 | * of scanning the entire bus. In our implemention, we will kick off |
| 8046 | * firmware discovery. |
| 8047 | */ |
| 8048 | static void |
| 8049 | _scsih_scan_start(struct Scsi_Host *shost) |
| 8050 | { |
| 8051 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8052 | int rc; |
| 8053 | |
| 8054 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) |
| 8055 | mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable); |
| 8056 | |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 8057 | if (disable_discovery > 0) |
| 8058 | return; |
| 8059 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8060 | ioc->start_scan = 1; |
| 8061 | rc = mpt2sas_port_enable(ioc); |
| 8062 | |
| 8063 | if (rc != 0) |
| 8064 | printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name); |
| 8065 | } |
| 8066 | |
| 8067 | /** |
| 8068 | * _scsih_scan_finished - scsi lld callback for .scan_finished |
| 8069 | * @shost: SCSI host pointer |
| 8070 | * @time: elapsed time of the scan in jiffies |
| 8071 | * |
| 8072 | * This function will be called periodically until it returns 1 with the |
| 8073 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, |
| 8074 | * we wait for firmware discovery to complete, then return 1. |
| 8075 | */ |
| 8076 | static int |
| 8077 | _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 8078 | { |
| 8079 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8080 | |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 8081 | if (disable_discovery > 0) { |
| 8082 | ioc->is_driver_loading = 0; |
| 8083 | ioc->wait_for_discovery_to_complete = 0; |
| 8084 | return 1; |
| 8085 | } |
| 8086 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8087 | if (time >= (300 * HZ)) { |
| 8088 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 8089 | printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout " |
| 8090 | "(timeout=300s)\n", ioc->name); |
| 8091 | ioc->is_driver_loading = 0; |
| 8092 | return 1; |
| 8093 | } |
| 8094 | |
| 8095 | if (ioc->start_scan) |
| 8096 | return 0; |
| 8097 | |
| 8098 | if (ioc->start_scan_failed) { |
| 8099 | printk(MPT2SAS_INFO_FMT "port enable: FAILED with " |
| 8100 | "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed); |
| 8101 | ioc->is_driver_loading = 0; |
| 8102 | ioc->wait_for_discovery_to_complete = 0; |
| 8103 | ioc->remove_host = 1; |
| 8104 | return 1; |
| 8105 | } |
| 8106 | |
| 8107 | printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name); |
| 8108 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 8109 | |
| 8110 | if (ioc->wait_for_discovery_to_complete) { |
| 8111 | ioc->wait_for_discovery_to_complete = 0; |
| 8112 | _scsih_probe_devices(ioc); |
| 8113 | } |
| 8114 | mpt2sas_base_start_watchdog(ioc); |
| 8115 | ioc->is_driver_loading = 0; |
| 8116 | return 1; |
| 8117 | } |
| 8118 | |
| 8119 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8120 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8121 | * _scsih_probe - attach and add scsi host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8122 | * @pdev: PCI device struct |
| 8123 | * @id: pci device id |
| 8124 | * |
| 8125 | * Returns 0 success, anything else error. |
| 8126 | */ |
| 8127 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8128 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8129 | { |
| 8130 | struct MPT2SAS_ADAPTER *ioc; |
| 8131 | struct Scsi_Host *shost; |
| 8132 | |
| 8133 | shost = scsi_host_alloc(&scsih_driver_template, |
| 8134 | sizeof(struct MPT2SAS_ADAPTER)); |
| 8135 | if (!shost) |
| 8136 | return -ENODEV; |
| 8137 | |
| 8138 | /* init local params */ |
| 8139 | ioc = shost_priv(shost); |
| 8140 | memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER)); |
| 8141 | INIT_LIST_HEAD(&ioc->list); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 8142 | list_add_tail(&ioc->list, &mpt2sas_ioc_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8143 | ioc->shost = shost; |
| 8144 | ioc->id = mpt_ids++; |
| 8145 | sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id); |
| 8146 | ioc->pdev = pdev; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8147 | if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) { |
| 8148 | ioc->is_warpdrive = 1; |
| 8149 | ioc->hide_ir_msg = 1; |
| 8150 | } else |
| 8151 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8152 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; |
| 8153 | ioc->tm_cb_idx = tm_cb_idx; |
| 8154 | ioc->ctl_cb_idx = ctl_cb_idx; |
| 8155 | ioc->base_cb_idx = base_cb_idx; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8156 | ioc->port_enable_cb_idx = port_enable_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8157 | ioc->transport_cb_idx = transport_cb_idx; |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8158 | ioc->scsih_cb_idx = scsih_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8159 | ioc->config_cb_idx = config_cb_idx; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8160 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8161 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8162 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8163 | ioc->logging_level = logging_level; |
nagalakshmi.nandigama@lsi.com | 845a0e4 | 2011-12-01 07:42:04 +0530 | [diff] [blame] | 8164 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8165 | /* misc semaphores and spin locks */ |
Kashyap, Desai | d274213 | 2010-06-17 13:28:55 +0530 | [diff] [blame] | 8166 | mutex_init(&ioc->reset_in_progress_mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8167 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
| 8168 | spin_lock_init(&ioc->scsi_lookup_lock); |
| 8169 | spin_lock_init(&ioc->sas_device_lock); |
| 8170 | spin_lock_init(&ioc->sas_node_lock); |
| 8171 | spin_lock_init(&ioc->fw_event_lock); |
| 8172 | spin_lock_init(&ioc->raid_device_lock); |
| 8173 | |
| 8174 | INIT_LIST_HEAD(&ioc->sas_device_list); |
| 8175 | INIT_LIST_HEAD(&ioc->sas_device_init_list); |
| 8176 | INIT_LIST_HEAD(&ioc->sas_expander_list); |
| 8177 | INIT_LIST_HEAD(&ioc->fw_event_list); |
| 8178 | INIT_LIST_HEAD(&ioc->raid_device_list); |
| 8179 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8180 | INIT_LIST_HEAD(&ioc->delayed_tr_list); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8181 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
Joe Lawrence | 3b3e6f8 | 2013-08-08 16:45:38 -0400 | [diff] [blame] | 8182 | INIT_LIST_HEAD(&ioc->reply_queue_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8183 | |
| 8184 | /* init shost parameters */ |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 8185 | shost->max_cmd_len = 32; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8186 | shost->max_lun = max_lun; |
| 8187 | shost->transportt = mpt2sas_transport_template; |
| 8188 | shost->unique_id = ioc->id; |
| 8189 | |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8190 | if (max_sectors != 0xFFFF) { |
| 8191 | if (max_sectors < 64) { |
| 8192 | shost->max_sectors = 64; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 8193 | printk(MPT2SAS_WARN_FMT "Invalid value %d passed " |
| 8194 | "for max_sectors, range is 64 to 32767. Assigning " |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8195 | "value of 64.\n", ioc->name, max_sectors); |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 8196 | } else if (max_sectors > 32767) { |
| 8197 | shost->max_sectors = 32767; |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8198 | printk(MPT2SAS_WARN_FMT "Invalid value %d passed " |
| 8199 | "for max_sectors, range is 64 to 8192. Assigning " |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 8200 | "default value of 32767.\n", ioc->name, |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8201 | max_sectors); |
| 8202 | } else { |
| 8203 | shost->max_sectors = max_sectors & 0xFFFE; |
| 8204 | printk(MPT2SAS_INFO_FMT "The max_sectors value is " |
| 8205 | "set to %d\n", ioc->name, shost->max_sectors); |
| 8206 | } |
| 8207 | } |
| 8208 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8209 | if ((scsi_add_host(shost, &pdev->dev))) { |
| 8210 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8211 | ioc->name, __FILE__, __LINE__, __func__); |
| 8212 | list_del(&ioc->list); |
| 8213 | goto out_add_shost_fail; |
| 8214 | } |
| 8215 | |
Martin K. Petersen | 5e95e73 | 2012-08-28 14:29:37 -0400 | [diff] [blame] | 8216 | /* register EEDP capabilities with SCSI layer */ |
| 8217 | if (prot_mask) |
| 8218 | scsi_host_set_prot(shost, prot_mask); |
| 8219 | else |
| 8220 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION |
| 8221 | | SHOST_DIF_TYPE2_PROTECTION |
| 8222 | | SHOST_DIF_TYPE3_PROTECTION); |
| 8223 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8224 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 8225 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8226 | /* event thread */ |
| 8227 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), |
| 8228 | "fw_event%d", ioc->id); |
| 8229 | ioc->firmware_event_thread = create_singlethread_workqueue( |
| 8230 | ioc->firmware_event_name); |
| 8231 | if (!ioc->firmware_event_thread) { |
| 8232 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8233 | ioc->name, __FILE__, __LINE__, __func__); |
| 8234 | goto out_thread_fail; |
| 8235 | } |
| 8236 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8237 | ioc->is_driver_loading = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8238 | if ((mpt2sas_base_attach(ioc))) { |
| 8239 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8240 | ioc->name, __FILE__, __LINE__, __func__); |
| 8241 | goto out_attach_fail; |
| 8242 | } |
| 8243 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8244 | if (ioc->is_warpdrive) { |
| 8245 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) |
| 8246 | ioc->hide_drives = 0; |
| 8247 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) |
| 8248 | ioc->hide_drives = 1; |
| 8249 | else { |
| 8250 | if (_scsih_get_num_volumes(ioc)) |
| 8251 | ioc->hide_drives = 1; |
| 8252 | else |
| 8253 | ioc->hide_drives = 0; |
| 8254 | } |
| 8255 | } else |
| 8256 | ioc->hide_drives = 0; |
nagalakshmi.nandigama@lsi.com | 2cb6fc8 | 2011-12-13 09:29:15 +0530 | [diff] [blame] | 8257 | scsi_scan_host(shost); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8258 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8259 | return 0; |
| 8260 | |
| 8261 | out_attach_fail: |
| 8262 | destroy_workqueue(ioc->firmware_event_thread); |
| 8263 | out_thread_fail: |
| 8264 | list_del(&ioc->list); |
| 8265 | scsi_remove_host(shost); |
| 8266 | out_add_shost_fail: |
Tomas Henzl | f555e05 | 2012-04-17 15:24:48 +0200 | [diff] [blame] | 8267 | scsi_host_put(shost); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8268 | return -ENODEV; |
| 8269 | } |
| 8270 | |
| 8271 | #ifdef CONFIG_PM |
| 8272 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8273 | * _scsih_suspend - power management suspend main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8274 | * @pdev: PCI device struct |
| 8275 | * @state: PM state change to (usually PCI_D3) |
| 8276 | * |
| 8277 | * Returns 0 success, anything else error. |
| 8278 | */ |
| 8279 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8280 | _scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8281 | { |
| 8282 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8283 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 8284 | pci_power_t device_state; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8285 | |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 8286 | mpt2sas_base_stop_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8287 | scsi_block_requests(shost); |
Sreekanth Reddy | 3627dba | 2013-07-25 11:25:57 +0530 | [diff] [blame] | 8288 | _scsih_ir_shutdown(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8289 | device_state = pci_choose_state(pdev, state); |
| 8290 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering " |
| 8291 | "operating state [D%d]\n", ioc->name, pdev, |
| 8292 | pci_name(pdev), device_state); |
| 8293 | |
| 8294 | mpt2sas_base_free_resources(ioc); |
| 8295 | pci_save_state(pdev); |
| 8296 | pci_disable_device(pdev); |
| 8297 | pci_set_power_state(pdev, device_state); |
| 8298 | return 0; |
| 8299 | } |
| 8300 | |
| 8301 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8302 | * _scsih_resume - power management resume main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8303 | * @pdev: PCI device struct |
| 8304 | * |
| 8305 | * Returns 0 success, anything else error. |
| 8306 | */ |
| 8307 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8308 | _scsih_resume(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8309 | { |
| 8310 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8311 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 8312 | pci_power_t device_state = pdev->current_state; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8313 | int r; |
| 8314 | |
| 8315 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous " |
| 8316 | "operating state [D%d]\n", ioc->name, pdev, |
| 8317 | pci_name(pdev), device_state); |
| 8318 | |
| 8319 | pci_set_power_state(pdev, PCI_D0); |
| 8320 | pci_enable_wake(pdev, PCI_D0, 0); |
| 8321 | pci_restore_state(pdev); |
| 8322 | ioc->pdev = pdev; |
| 8323 | r = mpt2sas_base_map_resources(ioc); |
| 8324 | if (r) |
| 8325 | return r; |
| 8326 | |
| 8327 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET); |
| 8328 | scsi_unblock_requests(shost); |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 8329 | mpt2sas_base_start_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8330 | return 0; |
| 8331 | } |
| 8332 | #endif /* CONFIG_PM */ |
| 8333 | |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8334 | /** |
| 8335 | * _scsih_pci_error_detected - Called when a PCI error is detected. |
| 8336 | * @pdev: PCI device struct |
| 8337 | * @state: PCI channel state |
| 8338 | * |
| 8339 | * Description: Called when a PCI error is detected. |
| 8340 | * |
| 8341 | * Return value: |
| 8342 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT |
| 8343 | */ |
| 8344 | static pci_ers_result_t |
| 8345 | _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 8346 | { |
| 8347 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8348 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8349 | |
| 8350 | printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n", |
| 8351 | ioc->name, state); |
| 8352 | |
| 8353 | switch (state) { |
| 8354 | case pci_channel_io_normal: |
| 8355 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 8356 | case pci_channel_io_frozen: |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8357 | /* Fatal error, prepare for slot reset */ |
| 8358 | ioc->pci_error_recovery = 1; |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8359 | scsi_block_requests(ioc->shost); |
| 8360 | mpt2sas_base_stop_watchdog(ioc); |
| 8361 | mpt2sas_base_free_resources(ioc); |
| 8362 | return PCI_ERS_RESULT_NEED_RESET; |
| 8363 | case pci_channel_io_perm_failure: |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8364 | /* Permanent error, prepare for device removal */ |
| 8365 | ioc->pci_error_recovery = 1; |
| 8366 | mpt2sas_base_stop_watchdog(ioc); |
| 8367 | _scsih_flush_running_cmds(ioc); |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8368 | return PCI_ERS_RESULT_DISCONNECT; |
| 8369 | } |
| 8370 | return PCI_ERS_RESULT_NEED_RESET; |
| 8371 | } |
| 8372 | |
| 8373 | /** |
| 8374 | * _scsih_pci_slot_reset - Called when PCI slot has been reset. |
| 8375 | * @pdev: PCI device struct |
| 8376 | * |
| 8377 | * Description: This routine is called by the pci error recovery |
| 8378 | * code after the PCI slot has been reset, just before we |
| 8379 | * should resume normal operations. |
| 8380 | */ |
| 8381 | static pci_ers_result_t |
| 8382 | _scsih_pci_slot_reset(struct pci_dev *pdev) |
| 8383 | { |
| 8384 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8385 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8386 | int rc; |
| 8387 | |
| 8388 | printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n", |
| 8389 | ioc->name); |
| 8390 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8391 | ioc->pci_error_recovery = 0; |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8392 | ioc->pdev = pdev; |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8393 | pci_restore_state(pdev); |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8394 | rc = mpt2sas_base_map_resources(ioc); |
| 8395 | if (rc) |
| 8396 | return PCI_ERS_RESULT_DISCONNECT; |
| 8397 | |
| 8398 | |
| 8399 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 8400 | FORCE_BIG_HAMMER); |
| 8401 | |
| 8402 | printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name, |
| 8403 | (rc == 0) ? "success" : "failed"); |
| 8404 | |
| 8405 | if (!rc) |
| 8406 | return PCI_ERS_RESULT_RECOVERED; |
| 8407 | else |
| 8408 | return PCI_ERS_RESULT_DISCONNECT; |
| 8409 | } |
| 8410 | |
| 8411 | /** |
| 8412 | * _scsih_pci_resume() - resume normal ops after PCI reset |
| 8413 | * @pdev: pointer to PCI device |
| 8414 | * |
| 8415 | * Called when the error recovery driver tells us that its |
| 8416 | * OK to resume normal operation. Use completion to allow |
| 8417 | * halted scsi ops to resume. |
| 8418 | */ |
| 8419 | static void |
| 8420 | _scsih_pci_resume(struct pci_dev *pdev) |
| 8421 | { |
| 8422 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8423 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8424 | |
| 8425 | printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name); |
| 8426 | |
| 8427 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8428 | mpt2sas_base_start_watchdog(ioc); |
| 8429 | scsi_unblock_requests(ioc->shost); |
| 8430 | } |
| 8431 | |
| 8432 | /** |
| 8433 | * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
| 8434 | * @pdev: pointer to PCI device |
| 8435 | */ |
| 8436 | static pci_ers_result_t |
| 8437 | _scsih_pci_mmio_enabled(struct pci_dev *pdev) |
| 8438 | { |
| 8439 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8440 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8441 | |
| 8442 | printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n", |
| 8443 | ioc->name); |
| 8444 | |
| 8445 | /* TODO - dump whatever for debugging purposes */ |
| 8446 | |
| 8447 | /* Request a slot reset. */ |
| 8448 | return PCI_ERS_RESULT_NEED_RESET; |
| 8449 | } |
| 8450 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 8451 | static const struct pci_error_handlers _scsih_err_handler = { |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8452 | .error_detected = _scsih_pci_error_detected, |
| 8453 | .mmio_enabled = _scsih_pci_mmio_enabled, |
| 8454 | .slot_reset = _scsih_pci_slot_reset, |
| 8455 | .resume = _scsih_pci_resume, |
| 8456 | }; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8457 | |
| 8458 | static struct pci_driver scsih_driver = { |
| 8459 | .name = MPT2SAS_DRIVER_NAME, |
| 8460 | .id_table = scsih_pci_table, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8461 | .probe = _scsih_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8462 | .remove = _scsih_remove, |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8463 | .shutdown = _scsih_shutdown, |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8464 | .err_handler = &_scsih_err_handler, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8465 | #ifdef CONFIG_PM |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8466 | .suspend = _scsih_suspend, |
| 8467 | .resume = _scsih_resume, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8468 | #endif |
| 8469 | }; |
| 8470 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8471 | /* raid transport support */ |
| 8472 | static struct raid_function_template mpt2sas_raid_functions = { |
| 8473 | .cookie = &scsih_driver_template, |
| 8474 | .is_raid = _scsih_is_raid, |
| 8475 | .get_resync = _scsih_get_resync, |
| 8476 | .get_state = _scsih_get_state, |
| 8477 | }; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8478 | |
| 8479 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8480 | * _scsih_init - main entry point for this driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8481 | * |
| 8482 | * Returns 0 success, anything else error. |
| 8483 | */ |
| 8484 | static int __init |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8485 | _scsih_init(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8486 | { |
| 8487 | int error; |
| 8488 | |
| 8489 | mpt_ids = 0; |
| 8490 | printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME, |
| 8491 | MPT2SAS_DRIVER_VERSION); |
| 8492 | |
| 8493 | mpt2sas_transport_template = |
| 8494 | sas_attach_transport(&mpt2sas_transport_functions); |
| 8495 | if (!mpt2sas_transport_template) |
| 8496 | return -ENODEV; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8497 | /* raid transport support */ |
| 8498 | mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions); |
| 8499 | if (!mpt2sas_raid_template) { |
| 8500 | sas_release_transport(mpt2sas_transport_template); |
| 8501 | return -ENODEV; |
| 8502 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8503 | |
| 8504 | mpt2sas_base_initialize_callback_handler(); |
| 8505 | |
| 8506 | /* queuecommand callback hander */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8507 | scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8508 | |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 8509 | /* task management callback handler */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8510 | tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8511 | |
| 8512 | /* base internal commands callback handler */ |
| 8513 | base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8514 | port_enable_cb_idx = mpt2sas_base_register_callback_handler( |
| 8515 | mpt2sas_port_enable_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8516 | |
| 8517 | /* transport internal commands callback handler */ |
| 8518 | transport_cb_idx = mpt2sas_base_register_callback_handler( |
| 8519 | mpt2sas_transport_done); |
| 8520 | |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8521 | /* scsih internal commands callback handler */ |
| 8522 | scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done); |
| 8523 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8524 | /* configuration page API internal commands callback handler */ |
| 8525 | config_cb_idx = mpt2sas_base_register_callback_handler( |
| 8526 | mpt2sas_config_done); |
| 8527 | |
| 8528 | /* ctl module callback handler */ |
| 8529 | ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done); |
| 8530 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8531 | tm_tr_cb_idx = mpt2sas_base_register_callback_handler( |
| 8532 | _scsih_tm_tr_complete); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8533 | |
| 8534 | tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler( |
| 8535 | _scsih_tm_volume_tr_complete); |
| 8536 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8537 | tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler( |
| 8538 | _scsih_sas_control_complete); |
| 8539 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8540 | mpt2sas_ctl_init(); |
| 8541 | |
| 8542 | error = pci_register_driver(&scsih_driver); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8543 | if (error) { |
| 8544 | /* raid transport support */ |
| 8545 | raid_class_release(mpt2sas_raid_template); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8546 | sas_release_transport(mpt2sas_transport_template); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8547 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8548 | |
| 8549 | return error; |
| 8550 | } |
| 8551 | |
| 8552 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8553 | * _scsih_exit - exit point for this driver (when it is a module). |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8554 | * |
| 8555 | * Returns 0 success, anything else error. |
| 8556 | */ |
| 8557 | static void __exit |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8558 | _scsih_exit(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8559 | { |
| 8560 | printk(KERN_INFO "mpt2sas version %s unloading\n", |
| 8561 | MPT2SAS_DRIVER_VERSION); |
| 8562 | |
| 8563 | pci_unregister_driver(&scsih_driver); |
| 8564 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8565 | mpt2sas_ctl_exit(); |
| 8566 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8567 | mpt2sas_base_release_callback_handler(scsi_io_cb_idx); |
| 8568 | mpt2sas_base_release_callback_handler(tm_cb_idx); |
| 8569 | mpt2sas_base_release_callback_handler(base_cb_idx); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8570 | mpt2sas_base_release_callback_handler(port_enable_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8571 | mpt2sas_base_release_callback_handler(transport_cb_idx); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8572 | mpt2sas_base_release_callback_handler(scsih_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8573 | mpt2sas_base_release_callback_handler(config_cb_idx); |
| 8574 | mpt2sas_base_release_callback_handler(ctl_cb_idx); |
| 8575 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8576 | mpt2sas_base_release_callback_handler(tm_tr_cb_idx); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8577 | mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8578 | mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx); |
| 8579 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8580 | /* raid transport support */ |
| 8581 | raid_class_release(mpt2sas_raid_template); |
| 8582 | sas_release_transport(mpt2sas_transport_template); |
| 8583 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8584 | } |
| 8585 | |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8586 | module_init(_scsih_init); |
| 8587 | module_exit(_scsih_exit); |