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; |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 176 | char event_data[0] __aligned(4); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 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 | |
Joe Lawrence | feafe7c | 2014-06-25 17:03:14 -0400 | [diff] [blame] | 1295 | sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data), |
| 1296 | GFP_KERNEL); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1297 | if (!sas_target_priv_data) |
| 1298 | return -ENOMEM; |
| 1299 | |
| 1300 | starget->hostdata = sas_target_priv_data; |
| 1301 | sas_target_priv_data->starget = starget; |
| 1302 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; |
| 1303 | |
| 1304 | /* RAID volumes */ |
| 1305 | if (starget->channel == RAID_CHANNEL) { |
| 1306 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1307 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1308 | starget->channel); |
| 1309 | if (raid_device) { |
| 1310 | sas_target_priv_data->handle = raid_device->handle; |
| 1311 | sas_target_priv_data->sas_address = raid_device->wwid; |
| 1312 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1313 | if (ioc->is_warpdrive) |
| 1314 | sas_target_priv_data->raid_device = raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1315 | raid_device->starget = starget; |
| 1316 | } |
| 1317 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1318 | return 0; |
| 1319 | } |
| 1320 | |
| 1321 | /* sas/sata devices */ |
| 1322 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1323 | rphy = dev_to_rphy(starget->dev.parent); |
| 1324 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1325 | rphy->identify.sas_address); |
| 1326 | |
| 1327 | if (sas_device) { |
| 1328 | sas_target_priv_data->handle = sas_device->handle; |
| 1329 | sas_target_priv_data->sas_address = sas_device->sas_address; |
| 1330 | sas_device->starget = starget; |
| 1331 | sas_device->id = starget->id; |
| 1332 | sas_device->channel = starget->channel; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 1333 | if (test_bit(sas_device->handle, ioc->pd_handles)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1334 | sas_target_priv_data->flags |= |
| 1335 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 1336 | } |
| 1337 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1338 | |
| 1339 | return 0; |
| 1340 | } |
| 1341 | |
| 1342 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1343 | * _scsih_target_destroy - target destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1344 | * @starget: scsi target struct |
| 1345 | * |
| 1346 | * Returns nothing. |
| 1347 | */ |
| 1348 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1349 | _scsih_target_destroy(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1350 | { |
| 1351 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1352 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1353 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1354 | struct _sas_device *sas_device; |
| 1355 | struct _raid_device *raid_device; |
| 1356 | unsigned long flags; |
| 1357 | struct sas_rphy *rphy; |
| 1358 | |
| 1359 | sas_target_priv_data = starget->hostdata; |
| 1360 | if (!sas_target_priv_data) |
| 1361 | return; |
| 1362 | |
| 1363 | if (starget->channel == RAID_CHANNEL) { |
| 1364 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1365 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1366 | starget->channel); |
| 1367 | if (raid_device) { |
| 1368 | raid_device->starget = NULL; |
| 1369 | raid_device->sdev = NULL; |
| 1370 | } |
| 1371 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1372 | goto out; |
| 1373 | } |
| 1374 | |
| 1375 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1376 | rphy = dev_to_rphy(starget->dev.parent); |
| 1377 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1378 | rphy->identify.sas_address); |
Eric Moore | 8901cbb | 2009-04-21 15:41:32 -0600 | [diff] [blame] | 1379 | if (sas_device && (sas_device->starget == starget) && |
| 1380 | (sas_device->id == starget->id) && |
| 1381 | (sas_device->channel == starget->channel)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1382 | sas_device->starget = NULL; |
| 1383 | |
| 1384 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1385 | |
| 1386 | out: |
| 1387 | kfree(sas_target_priv_data); |
| 1388 | starget->hostdata = NULL; |
| 1389 | } |
| 1390 | |
| 1391 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1392 | * _scsih_slave_alloc - device add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1393 | * @sdev: scsi device struct |
| 1394 | * |
| 1395 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1396 | * the device is ignored. |
| 1397 | */ |
| 1398 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1399 | _scsih_slave_alloc(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1400 | { |
| 1401 | struct Scsi_Host *shost; |
| 1402 | struct MPT2SAS_ADAPTER *ioc; |
| 1403 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1404 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1405 | struct scsi_target *starget; |
| 1406 | struct _raid_device *raid_device; |
Sreekanth Reddy | 63e359d | 2013-07-25 11:32:51 +0530 | [diff] [blame] | 1407 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1408 | unsigned long flags; |
| 1409 | |
Joe Lawrence | feafe7c | 2014-06-25 17:03:14 -0400 | [diff] [blame] | 1410 | sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data), |
| 1411 | GFP_KERNEL); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1412 | if (!sas_device_priv_data) |
| 1413 | return -ENOMEM; |
| 1414 | |
| 1415 | sas_device_priv_data->lun = sdev->lun; |
| 1416 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; |
| 1417 | |
| 1418 | starget = scsi_target(sdev); |
| 1419 | sas_target_priv_data = starget->hostdata; |
| 1420 | sas_target_priv_data->num_luns++; |
| 1421 | sas_device_priv_data->sas_target = sas_target_priv_data; |
| 1422 | sdev->hostdata = sas_device_priv_data; |
| 1423 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) |
| 1424 | sdev->no_uld_attach = 1; |
| 1425 | |
| 1426 | shost = dev_to_shost(&starget->dev); |
| 1427 | ioc = shost_priv(shost); |
| 1428 | if (starget->channel == RAID_CHANNEL) { |
| 1429 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1430 | raid_device = _scsih_raid_device_find_by_id(ioc, |
| 1431 | starget->id, starget->channel); |
| 1432 | if (raid_device) |
| 1433 | raid_device->sdev = sdev; /* raid is single lun */ |
| 1434 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1435 | } |
| 1436 | |
Sreekanth Reddy | 63e359d | 2013-07-25 11:32:51 +0530 | [diff] [blame] | 1437 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
| 1438 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1439 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1440 | sas_target_priv_data->sas_address); |
| 1441 | if (sas_device && (sas_device->starget == NULL)) { |
| 1442 | sdev_printk(KERN_INFO, sdev, |
| 1443 | "%s : sas_device->starget set to starget @ %d\n", |
| 1444 | __func__, __LINE__); |
| 1445 | sas_device->starget = starget; |
| 1446 | } |
| 1447 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1448 | } |
| 1449 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1450 | return 0; |
| 1451 | } |
| 1452 | |
| 1453 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1454 | * _scsih_slave_destroy - device destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1455 | * @sdev: scsi device struct |
| 1456 | * |
| 1457 | * Returns nothing. |
| 1458 | */ |
| 1459 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1460 | _scsih_slave_destroy(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1461 | { |
| 1462 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1463 | struct scsi_target *starget; |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1464 | struct Scsi_Host *shost; |
| 1465 | struct MPT2SAS_ADAPTER *ioc; |
| 1466 | struct _sas_device *sas_device; |
| 1467 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1468 | |
| 1469 | if (!sdev->hostdata) |
| 1470 | return; |
| 1471 | |
| 1472 | starget = scsi_target(sdev); |
| 1473 | sas_target_priv_data = starget->hostdata; |
| 1474 | sas_target_priv_data->num_luns--; |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1475 | |
| 1476 | shost = dev_to_shost(&starget->dev); |
| 1477 | ioc = shost_priv(shost); |
| 1478 | |
| 1479 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
| 1480 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1481 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1482 | sas_target_priv_data->sas_address); |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 1483 | if (sas_device && !sas_target_priv_data->num_luns) |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1484 | sas_device->starget = NULL; |
| 1485 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1486 | } |
| 1487 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1488 | kfree(sdev->hostdata); |
| 1489 | sdev->hostdata = NULL; |
| 1490 | } |
| 1491 | |
| 1492 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1493 | * _scsih_display_sata_capabilities - sata capabilities |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1494 | * @ioc: per adapter object |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1495 | * @handle: device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1496 | * @sdev: scsi device struct |
| 1497 | */ |
| 1498 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1499 | _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1500 | u16 handle, struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1501 | { |
| 1502 | Mpi2ConfigReply_t mpi_reply; |
| 1503 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1504 | u32 ioc_status; |
| 1505 | u16 flags; |
| 1506 | u32 device_info; |
| 1507 | |
| 1508 | 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] | 1509 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1510 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1511 | ioc->name, __FILE__, __LINE__, __func__); |
| 1512 | return; |
| 1513 | } |
| 1514 | |
| 1515 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1516 | MPI2_IOCSTATUS_MASK; |
| 1517 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 1518 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1519 | ioc->name, __FILE__, __LINE__, __func__); |
| 1520 | return; |
| 1521 | } |
| 1522 | |
| 1523 | flags = le16_to_cpu(sas_device_pg0.Flags); |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 1524 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1525 | |
| 1526 | sdev_printk(KERN_INFO, sdev, |
| 1527 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " |
| 1528 | "sw_preserve(%s)\n", |
| 1529 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", |
| 1530 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", |
| 1531 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : |
| 1532 | "n", |
| 1533 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", |
| 1534 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", |
| 1535 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); |
| 1536 | } |
| 1537 | |
| 1538 | /** |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1539 | * _scsih_is_raid - return boolean indicating device is raid volume |
| 1540 | * @dev the device struct object |
| 1541 | */ |
| 1542 | static int |
| 1543 | _scsih_is_raid(struct device *dev) |
| 1544 | { |
| 1545 | struct scsi_device *sdev = to_scsi_device(dev); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1546 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1547 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1548 | if (ioc->is_warpdrive) |
| 1549 | return 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1550 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
| 1551 | } |
| 1552 | |
| 1553 | /** |
| 1554 | * _scsih_get_resync - get raid volume resync percent complete |
| 1555 | * @dev the device struct object |
| 1556 | */ |
| 1557 | static void |
| 1558 | _scsih_get_resync(struct device *dev) |
| 1559 | { |
| 1560 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1561 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1562 | static struct _raid_device *raid_device; |
| 1563 | unsigned long flags; |
| 1564 | Mpi2RaidVolPage0_t vol_pg0; |
| 1565 | Mpi2ConfigReply_t mpi_reply; |
| 1566 | u32 volume_status_flags; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1567 | u8 percent_complete; |
| 1568 | u16 handle; |
| 1569 | |
| 1570 | percent_complete = 0; |
| 1571 | handle = 0; |
| 1572 | if (ioc->is_warpdrive) |
| 1573 | goto out; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1574 | |
| 1575 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1576 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1577 | sdev->channel); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1578 | if (raid_device) { |
| 1579 | handle = raid_device->handle; |
| 1580 | percent_complete = raid_device->percent_complete; |
| 1581 | } |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1582 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1583 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1584 | if (!handle) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1585 | goto out; |
| 1586 | |
| 1587 | 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] | 1588 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1589 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1590 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1591 | ioc->name, __FILE__, __LINE__, __func__); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1592 | percent_complete = 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1593 | goto out; |
| 1594 | } |
| 1595 | |
| 1596 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1597 | if (!(volume_status_flags & |
| 1598 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) |
| 1599 | percent_complete = 0; |
| 1600 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1601 | out: |
| 1602 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); |
| 1603 | } |
| 1604 | |
| 1605 | /** |
| 1606 | * _scsih_get_state - get raid volume level |
| 1607 | * @dev the device struct object |
| 1608 | */ |
| 1609 | static void |
| 1610 | _scsih_get_state(struct device *dev) |
| 1611 | { |
| 1612 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1613 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1614 | static struct _raid_device *raid_device; |
| 1615 | unsigned long flags; |
| 1616 | Mpi2RaidVolPage0_t vol_pg0; |
| 1617 | Mpi2ConfigReply_t mpi_reply; |
| 1618 | u32 volstate; |
| 1619 | enum raid_state state = RAID_STATE_UNKNOWN; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1620 | u16 handle = 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1621 | |
| 1622 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1623 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1624 | sdev->channel); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1625 | if (raid_device) |
| 1626 | handle = raid_device->handle; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1627 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1628 | |
| 1629 | if (!raid_device) |
| 1630 | goto out; |
| 1631 | |
| 1632 | 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] | 1633 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1634 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1635 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1636 | ioc->name, __FILE__, __LINE__, __func__); |
| 1637 | goto out; |
| 1638 | } |
| 1639 | |
| 1640 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
| 1641 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { |
| 1642 | state = RAID_STATE_RESYNCING; |
| 1643 | goto out; |
| 1644 | } |
| 1645 | |
| 1646 | switch (vol_pg0.VolumeState) { |
| 1647 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
| 1648 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 1649 | state = RAID_STATE_ACTIVE; |
| 1650 | break; |
| 1651 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 1652 | state = RAID_STATE_DEGRADED; |
| 1653 | break; |
| 1654 | case MPI2_RAID_VOL_STATE_FAILED: |
| 1655 | case MPI2_RAID_VOL_STATE_MISSING: |
| 1656 | state = RAID_STATE_OFFLINE; |
| 1657 | break; |
| 1658 | } |
| 1659 | out: |
| 1660 | raid_set_state(mpt2sas_raid_template, dev, state); |
| 1661 | } |
| 1662 | |
| 1663 | /** |
| 1664 | * _scsih_set_level - set raid level |
| 1665 | * @sdev: scsi device struct |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1666 | * @volume_type: volume type |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1667 | */ |
| 1668 | static void |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1669 | _scsih_set_level(struct scsi_device *sdev, u8 volume_type) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1670 | { |
| 1671 | enum raid_level level = RAID_LEVEL_UNKNOWN; |
| 1672 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1673 | switch (volume_type) { |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1674 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 1675 | level = RAID_LEVEL_0; |
| 1676 | break; |
| 1677 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 1678 | level = RAID_LEVEL_10; |
| 1679 | break; |
| 1680 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 1681 | level = RAID_LEVEL_1E; |
| 1682 | break; |
| 1683 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 1684 | level = RAID_LEVEL_1; |
| 1685 | break; |
| 1686 | } |
| 1687 | |
| 1688 | raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level); |
| 1689 | } |
| 1690 | |
| 1691 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1692 | * _scsih_get_volume_capabilities - volume capabilities |
| 1693 | * @ioc: per adapter object |
| 1694 | * @sas_device: the raid_device object |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1695 | * |
| 1696 | * Returns 0 for success, else 1 |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1697 | */ |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1698 | static int |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1699 | _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc, |
| 1700 | struct _raid_device *raid_device) |
| 1701 | { |
| 1702 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1703 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1704 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1705 | Mpi2ConfigReply_t mpi_reply; |
| 1706 | u16 sz; |
| 1707 | u8 num_pds; |
| 1708 | |
| 1709 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1710 | &num_pds)) || !num_pds) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1711 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1712 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1713 | __func__)); |
| 1714 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | raid_device->num_pds = num_pds; |
| 1718 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1719 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1720 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1721 | if (!vol_pg0) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1722 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1723 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1724 | __func__)); |
| 1725 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1729 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1730 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1731 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1732 | __func__)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1733 | kfree(vol_pg0); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1734 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | raid_device->volume_type = vol_pg0->VolumeType; |
| 1738 | |
| 1739 | /* figure out what the underlying devices are by |
| 1740 | * obtaining the device_info bits for the 1st device |
| 1741 | */ |
| 1742 | if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1743 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1744 | vol_pg0->PhysDisk[0].PhysDiskNum))) { |
| 1745 | if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 1746 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 1747 | le16_to_cpu(pd_pg0.DevHandle)))) { |
| 1748 | raid_device->device_info = |
| 1749 | le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | kfree(vol_pg0); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1754 | return 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1755 | } |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1756 | /** |
| 1757 | * _scsih_disable_ddio - Disable direct I/O for all the volumes |
| 1758 | * @ioc: per adapter object |
| 1759 | */ |
| 1760 | static void |
| 1761 | _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc) |
| 1762 | { |
| 1763 | Mpi2RaidVolPage1_t vol_pg1; |
| 1764 | Mpi2ConfigReply_t mpi_reply; |
| 1765 | struct _raid_device *raid_device; |
| 1766 | u16 handle; |
| 1767 | u16 ioc_status; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1768 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1769 | |
| 1770 | handle = 0xFFFF; |
| 1771 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 1772 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 1773 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1774 | MPI2_IOCSTATUS_MASK; |
| 1775 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 1776 | break; |
| 1777 | handle = le16_to_cpu(vol_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1778 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1779 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 1780 | if (raid_device) |
| 1781 | raid_device->direct_io_enabled = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1782 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1783 | } |
| 1784 | return; |
| 1785 | } |
| 1786 | |
| 1787 | |
| 1788 | /** |
| 1789 | * _scsih_get_num_volumes - Get number of volumes in the ioc |
| 1790 | * @ioc: per adapter object |
| 1791 | */ |
| 1792 | static u8 |
| 1793 | _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc) |
| 1794 | { |
| 1795 | Mpi2RaidVolPage1_t vol_pg1; |
| 1796 | Mpi2ConfigReply_t mpi_reply; |
| 1797 | u16 handle; |
| 1798 | u8 vol_cnt = 0; |
| 1799 | u16 ioc_status; |
| 1800 | |
| 1801 | handle = 0xFFFF; |
| 1802 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 1803 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 1804 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1805 | MPI2_IOCSTATUS_MASK; |
| 1806 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 1807 | break; |
| 1808 | vol_cnt++; |
| 1809 | handle = le16_to_cpu(vol_pg1.DevHandle); |
| 1810 | } |
| 1811 | return vol_cnt; |
| 1812 | } |
| 1813 | |
| 1814 | |
| 1815 | /** |
| 1816 | * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O. |
| 1817 | * @ioc: per adapter object |
| 1818 | * @raid_device: the raid_device object |
| 1819 | */ |
| 1820 | static void |
| 1821 | _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc, |
| 1822 | struct _raid_device *raid_device) |
| 1823 | { |
| 1824 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1825 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1826 | Mpi2ConfigReply_t mpi_reply; |
| 1827 | u16 sz; |
| 1828 | u8 num_pds, count; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1829 | unsigned long stripe_sz, block_sz; |
| 1830 | u8 stripe_exp, block_exp; |
| 1831 | u64 dev_max_lba; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1832 | |
| 1833 | if (!ioc->is_warpdrive) |
| 1834 | return; |
| 1835 | |
| 1836 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) { |
| 1837 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1838 | "globally as drives are exposed\n", ioc->name); |
| 1839 | return; |
| 1840 | } |
| 1841 | if (_scsih_get_num_volumes(ioc) > 1) { |
| 1842 | _scsih_disable_ddio(ioc); |
| 1843 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1844 | "globally as number of drives > 1\n", ioc->name); |
| 1845 | return; |
| 1846 | } |
| 1847 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1848 | &num_pds)) || !num_pds) { |
| 1849 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1850 | "Failure in computing number of drives\n", ioc->name); |
| 1851 | return; |
| 1852 | } |
| 1853 | |
| 1854 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1855 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1856 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1857 | if (!vol_pg0) { |
| 1858 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1859 | "Memory allocation failure for RVPG0\n", ioc->name); |
| 1860 | return; |
| 1861 | } |
| 1862 | |
| 1863 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1864 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
| 1865 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1866 | "Failure in retrieving RVPG0\n", ioc->name); |
| 1867 | kfree(vol_pg0); |
| 1868 | return; |
| 1869 | } |
| 1870 | |
| 1871 | /* |
| 1872 | * WARPDRIVE:If number of physical disks in a volume exceeds the max pds |
| 1873 | * assumed for WARPDRIVE, disable direct I/O |
| 1874 | */ |
| 1875 | if (num_pds > MPT_MAX_WARPDRIVE_PDS) { |
| 1876 | printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled " |
| 1877 | "for the drive with handle(0x%04x): num_mem=%d, " |
| 1878 | "max_mem_allowed=%d\n", ioc->name, raid_device->handle, |
| 1879 | num_pds, MPT_MAX_WARPDRIVE_PDS); |
| 1880 | kfree(vol_pg0); |
| 1881 | return; |
| 1882 | } |
| 1883 | for (count = 0; count < num_pds; count++) { |
| 1884 | if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1885 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1886 | vol_pg0->PhysDisk[count].PhysDiskNum) || |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 1887 | le16_to_cpu(pd_pg0.DevHandle) == |
| 1888 | MPT2SAS_INVALID_DEVICE_HANDLE) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1889 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " |
| 1890 | "disabled for the drive with handle(0x%04x) member" |
| 1891 | "handle retrieval failed for member number=%d\n", |
| 1892 | ioc->name, raid_device->handle, |
| 1893 | vol_pg0->PhysDisk[count].PhysDiskNum); |
| 1894 | goto out_error; |
| 1895 | } |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1896 | /* Disable direct I/O if member drive lba exceeds 4 bytes */ |
| 1897 | dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA); |
| 1898 | if (dev_max_lba >> 32) { |
| 1899 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " |
| 1900 | "disabled for the drive with handle(0x%04x) member" |
| 1901 | "handle (0x%04x) unsupported max lba 0x%016llx\n", |
| 1902 | ioc->name, raid_device->handle, |
| 1903 | le16_to_cpu(pd_pg0.DevHandle), |
| 1904 | (unsigned long long)dev_max_lba); |
| 1905 | goto out_error; |
| 1906 | } |
| 1907 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1908 | raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle); |
| 1909 | } |
| 1910 | |
| 1911 | /* |
| 1912 | * 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] | 1913 | * not RAID0 |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1914 | */ |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1915 | if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1916 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1917 | "for the drive with handle(0x%04x): type=%d, " |
| 1918 | "s_sz=%uK, blk_size=%u\n", ioc->name, |
| 1919 | raid_device->handle, raid_device->volume_type, |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1920 | (le32_to_cpu(vol_pg0->StripeSize) * |
| 1921 | le16_to_cpu(vol_pg0->BlockSize)) / 1024, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1922 | le16_to_cpu(vol_pg0->BlockSize)); |
| 1923 | goto out_error; |
| 1924 | } |
| 1925 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1926 | stripe_sz = le32_to_cpu(vol_pg0->StripeSize); |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1927 | stripe_exp = find_first_bit(&stripe_sz, 32); |
| 1928 | if (stripe_exp == 32) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1929 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1930 | "for the drive with handle(0x%04x) invalid stripe sz %uK\n", |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1931 | ioc->name, raid_device->handle, |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1932 | (le32_to_cpu(vol_pg0->StripeSize) * |
| 1933 | le16_to_cpu(vol_pg0->BlockSize)) / 1024); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1934 | goto out_error; |
| 1935 | } |
| 1936 | raid_device->stripe_exponent = stripe_exp; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1937 | block_sz = le16_to_cpu(vol_pg0->BlockSize); |
| 1938 | block_exp = find_first_bit(&block_sz, 16); |
| 1939 | if (block_exp == 16) { |
| 1940 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1941 | "for the drive with handle(0x%04x) invalid block sz %u\n", |
| 1942 | ioc->name, raid_device->handle, |
| 1943 | le16_to_cpu(vol_pg0->BlockSize)); |
| 1944 | goto out_error; |
| 1945 | } |
| 1946 | raid_device->block_exponent = block_exp; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1947 | raid_device->direct_io_enabled = 1; |
| 1948 | |
| 1949 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive" |
| 1950 | " with handle(0x%04x)\n", ioc->name, raid_device->handle); |
| 1951 | /* |
| 1952 | * WARPDRIVE: Though the following fields are not used for direct IO, |
| 1953 | * stored for future purpose: |
| 1954 | */ |
| 1955 | raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA); |
| 1956 | raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize); |
| 1957 | raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize); |
| 1958 | |
| 1959 | |
| 1960 | kfree(vol_pg0); |
| 1961 | return; |
| 1962 | |
| 1963 | out_error: |
| 1964 | raid_device->direct_io_enabled = 0; |
| 1965 | for (count = 0; count < num_pds; count++) |
| 1966 | raid_device->pd_handle[count] = 0; |
| 1967 | kfree(vol_pg0); |
| 1968 | return; |
| 1969 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1970 | |
| 1971 | /** |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 1972 | * _scsih_enable_tlr - setting TLR flags |
| 1973 | * @ioc: per adapter object |
| 1974 | * @sdev: scsi device struct |
| 1975 | * |
| 1976 | * Enabling Transaction Layer Retries for tape devices when |
| 1977 | * vpd page 0x90 is present |
| 1978 | * |
| 1979 | */ |
| 1980 | static void |
| 1981 | _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev) |
| 1982 | { |
| 1983 | /* only for TAPE */ |
| 1984 | if (sdev->type != TYPE_TAPE) |
| 1985 | return; |
| 1986 | |
| 1987 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) |
| 1988 | return; |
| 1989 | |
| 1990 | sas_enable_tlr(sdev); |
| 1991 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", |
| 1992 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); |
| 1993 | return; |
| 1994 | |
| 1995 | } |
| 1996 | |
| 1997 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1998 | * _scsih_slave_configure - device configure routine. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1999 | * @sdev: scsi device struct |
| 2000 | * |
| 2001 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 2002 | * the device is ignored. |
| 2003 | */ |
| 2004 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2005 | _scsih_slave_configure(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2006 | { |
| 2007 | struct Scsi_Host *shost = sdev->host; |
| 2008 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2009 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2010 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 2011 | struct _sas_device *sas_device; |
| 2012 | struct _raid_device *raid_device; |
| 2013 | unsigned long flags; |
| 2014 | int qdepth; |
| 2015 | u8 ssp_target = 0; |
| 2016 | char *ds = ""; |
| 2017 | char *r_level = ""; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2018 | u16 handle, volume_handle = 0; |
| 2019 | u64 volume_wwid = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2020 | |
| 2021 | qdepth = 1; |
| 2022 | sas_device_priv_data = sdev->hostdata; |
| 2023 | sas_device_priv_data->configured_lun = 1; |
| 2024 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; |
| 2025 | sas_target_priv_data = sas_device_priv_data->sas_target; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2026 | handle = sas_target_priv_data->handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2027 | |
| 2028 | /* raid volume handling */ |
| 2029 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 2030 | |
| 2031 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2032 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2033 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 2034 | if (!raid_device) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2035 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2036 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2037 | __LINE__, __func__)); |
| 2038 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2039 | } |
| 2040 | |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2041 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { |
| 2042 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2043 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2044 | __LINE__, __func__)); |
| 2045 | return 1; |
| 2046 | } |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2047 | /* |
| 2048 | * WARPDRIVE: Initialize the required data for Direct IO |
| 2049 | */ |
| 2050 | _scsih_init_warpdrive_properties(ioc, raid_device); |
| 2051 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2052 | /* RAID Queue Depth Support |
| 2053 | * IS volume = underlying qdepth of drive type, either |
| 2054 | * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH |
| 2055 | * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH) |
| 2056 | */ |
| 2057 | if (raid_device->device_info & |
| 2058 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 2059 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 2060 | ds = "SSP"; |
| 2061 | } else { |
| 2062 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 2063 | if (raid_device->device_info & |
| 2064 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 2065 | ds = "SATA"; |
| 2066 | else |
| 2067 | ds = "STP"; |
| 2068 | } |
| 2069 | |
| 2070 | switch (raid_device->volume_type) { |
| 2071 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 2072 | r_level = "RAID0"; |
| 2073 | break; |
| 2074 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 2075 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 2076 | if (ioc->manu_pg10.OEMIdentifier && |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 2077 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 2078 | MFG10_GF0_R10_DISPLAY) && |
| 2079 | !(raid_device->num_pds % 2)) |
| 2080 | r_level = "RAID10"; |
| 2081 | else |
| 2082 | r_level = "RAID1E"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2083 | break; |
| 2084 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 2085 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2086 | r_level = "RAID1"; |
| 2087 | break; |
| 2088 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 2089 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2090 | r_level = "RAID10"; |
| 2091 | break; |
| 2092 | case MPI2_RAID_VOL_TYPE_UNKNOWN: |
| 2093 | default: |
| 2094 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2095 | r_level = "RAIDX"; |
| 2096 | break; |
| 2097 | } |
| 2098 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2099 | if (!ioc->hide_ir_msg) |
| 2100 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
| 2101 | "wwid(0x%016llx), pd_count(%d), type(%s)\n", |
| 2102 | r_level, raid_device->handle, |
| 2103 | (unsigned long long)raid_device->wwid, |
| 2104 | raid_device->num_pds, ds); |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 2105 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 2106 | /* raid transport support */ |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2107 | if (!ioc->is_warpdrive) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2108 | _scsih_set_level(sdev, raid_device->volume_type); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2109 | return 0; |
| 2110 | } |
| 2111 | |
| 2112 | /* non-raid handling */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2113 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2114 | if (mpt2sas_config_get_volume_handle(ioc, handle, |
| 2115 | &volume_handle)) { |
| 2116 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2117 | "failure at %s:%d/%s()!\n", ioc->name, |
| 2118 | __FILE__, __LINE__, __func__)); |
| 2119 | return 1; |
| 2120 | } |
| 2121 | if (volume_handle && mpt2sas_config_get_volume_wwid(ioc, |
| 2122 | volume_handle, &volume_wwid)) { |
| 2123 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2124 | "failure at %s:%d/%s()!\n", ioc->name, |
| 2125 | __FILE__, __LINE__, __func__)); |
| 2126 | return 1; |
| 2127 | } |
| 2128 | } |
| 2129 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2130 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2131 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2132 | sas_device_priv_data->sas_target->sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2133 | if (!sas_device) { |
| 2134 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2135 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2136 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2137 | __LINE__, __func__)); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2138 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2139 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2140 | sas_device->volume_handle = volume_handle; |
| 2141 | sas_device->volume_wwid = volume_wwid; |
| 2142 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 2143 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 2144 | ssp_target = 1; |
| 2145 | ds = "SSP"; |
| 2146 | } else { |
| 2147 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 2148 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
| 2149 | ds = "STP"; |
| 2150 | else if (sas_device->device_info & |
| 2151 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 2152 | ds = "SATA"; |
| 2153 | } |
| 2154 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
| 2155 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", |
| 2156 | ds, sas_device->handle, |
| 2157 | (unsigned long long)sas_device->sas_address, |
| 2158 | sas_device->phy, |
| 2159 | (unsigned long long)sas_device->device_name); |
| 2160 | sdev_printk(KERN_INFO, sdev, "%s: " |
| 2161 | "enclosure_logical_id(0x%016llx), slot(%d)\n", ds, |
| 2162 | (unsigned long long) sas_device->enclosure_logical_id, |
| 2163 | sas_device->slot); |
| 2164 | |
| 2165 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2166 | if (!ssp_target) |
| 2167 | _scsih_display_sata_capabilities(ioc, handle, sdev); |
| 2168 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2169 | |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 2170 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2171 | |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 2172 | if (ssp_target) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2173 | sas_read_port_mode_page(sdev); |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 2174 | _scsih_enable_tlr(ioc, sdev); |
| 2175 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2176 | return 0; |
| 2177 | } |
| 2178 | |
| 2179 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2180 | * _scsih_bios_param - fetch head, sector, cylinder info for a disk |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2181 | * @sdev: scsi device struct |
| 2182 | * @bdev: pointer to block device context |
| 2183 | * @capacity: device size (in 512 byte sectors) |
| 2184 | * @params: three element array to place output: |
| 2185 | * params[0] number of heads (max 255) |
| 2186 | * params[1] number of sectors (max 63) |
| 2187 | * params[2] number of cylinders |
| 2188 | * |
| 2189 | * Return nothing. |
| 2190 | */ |
| 2191 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2192 | _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2193 | sector_t capacity, int params[]) |
| 2194 | { |
| 2195 | int heads; |
| 2196 | int sectors; |
| 2197 | sector_t cylinders; |
| 2198 | ulong dummy; |
| 2199 | |
| 2200 | heads = 64; |
| 2201 | sectors = 32; |
| 2202 | |
| 2203 | dummy = heads * sectors; |
| 2204 | cylinders = capacity; |
| 2205 | sector_div(cylinders, dummy); |
| 2206 | |
| 2207 | /* |
| 2208 | * Handle extended translation size for logical drives |
| 2209 | * > 1Gb |
| 2210 | */ |
| 2211 | if ((ulong)capacity >= 0x200000) { |
| 2212 | heads = 255; |
| 2213 | sectors = 63; |
| 2214 | dummy = heads * sectors; |
| 2215 | cylinders = capacity; |
| 2216 | sector_div(cylinders, dummy); |
| 2217 | } |
| 2218 | |
| 2219 | /* return result */ |
| 2220 | params[0] = heads; |
| 2221 | params[1] = sectors; |
| 2222 | params[2] = cylinders; |
| 2223 | |
| 2224 | return 0; |
| 2225 | } |
| 2226 | |
| 2227 | /** |
| 2228 | * _scsih_response_code - translation of device response code |
| 2229 | * @ioc: per adapter object |
| 2230 | * @response_code: response code returned by the device |
| 2231 | * |
| 2232 | * Return nothing. |
| 2233 | */ |
| 2234 | static void |
| 2235 | _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code) |
| 2236 | { |
| 2237 | char *desc; |
| 2238 | |
| 2239 | switch (response_code) { |
| 2240 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: |
| 2241 | desc = "task management request completed"; |
| 2242 | break; |
| 2243 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: |
| 2244 | desc = "invalid frame"; |
| 2245 | break; |
| 2246 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: |
| 2247 | desc = "task management request not supported"; |
| 2248 | break; |
| 2249 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: |
| 2250 | desc = "task management request failed"; |
| 2251 | break; |
| 2252 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: |
| 2253 | desc = "task management request succeeded"; |
| 2254 | break; |
| 2255 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: |
| 2256 | desc = "invalid lun"; |
| 2257 | break; |
| 2258 | case 0xA: |
| 2259 | desc = "overlapped tag attempted"; |
| 2260 | break; |
| 2261 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: |
| 2262 | desc = "task queued, however not sent to target"; |
| 2263 | break; |
| 2264 | default: |
| 2265 | desc = "unknown"; |
| 2266 | break; |
| 2267 | } |
| 2268 | printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n", |
| 2269 | ioc->name, response_code, desc); |
| 2270 | } |
| 2271 | |
| 2272 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2273 | * _scsih_tm_done - tm completion routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2274 | * @ioc: per adapter object |
| 2275 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2276 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2277 | * @reply: reply message frame(lower 32bit addr) |
| 2278 | * Context: none. |
| 2279 | * |
| 2280 | * The callback handler when using scsih_issue_tm. |
| 2281 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2282 | * Return 1 meaning mf should be freed from _base_interrupt |
| 2283 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2284 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2285 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2286 | _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] | 2287 | { |
| 2288 | MPI2DefaultReply_t *mpi_reply; |
| 2289 | |
| 2290 | if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2291 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2292 | if (ioc->tm_cmds.smid != smid) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2293 | return 1; |
nagalakshmi.nandigama@lsi.com | 911ae94 | 2011-09-08 06:18:50 +0530 | [diff] [blame] | 2294 | mpt2sas_base_flush_reply_queues(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2295 | ioc->tm_cmds.status |= MPT2_CMD_COMPLETE; |
| 2296 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 2297 | if (mpi_reply) { |
| 2298 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 2299 | ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 2300 | } |
| 2301 | ioc->tm_cmds.status &= ~MPT2_CMD_PENDING; |
| 2302 | complete(&ioc->tm_cmds.done); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2303 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | /** |
| 2307 | * mpt2sas_scsih_set_tm_flag - set per target tm_busy |
| 2308 | * @ioc: per adapter object |
| 2309 | * @handle: device handle |
| 2310 | * |
| 2311 | * During taskmangement request, we need to freeze the device queue. |
| 2312 | */ |
| 2313 | void |
| 2314 | mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2315 | { |
| 2316 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2317 | struct scsi_device *sdev; |
| 2318 | u8 skip = 0; |
| 2319 | |
| 2320 | shost_for_each_device(sdev, ioc->shost) { |
| 2321 | if (skip) |
| 2322 | continue; |
| 2323 | sas_device_priv_data = sdev->hostdata; |
| 2324 | if (!sas_device_priv_data) |
| 2325 | continue; |
| 2326 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2327 | sas_device_priv_data->sas_target->tm_busy = 1; |
| 2328 | skip = 1; |
| 2329 | ioc->ignore_loginfos = 1; |
| 2330 | } |
| 2331 | } |
| 2332 | } |
| 2333 | |
| 2334 | /** |
| 2335 | * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy |
| 2336 | * @ioc: per adapter object |
| 2337 | * @handle: device handle |
| 2338 | * |
| 2339 | * During taskmangement request, we need to freeze the device queue. |
| 2340 | */ |
| 2341 | void |
| 2342 | mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2343 | { |
| 2344 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2345 | struct scsi_device *sdev; |
| 2346 | u8 skip = 0; |
| 2347 | |
| 2348 | shost_for_each_device(sdev, ioc->shost) { |
| 2349 | if (skip) |
| 2350 | continue; |
| 2351 | sas_device_priv_data = sdev->hostdata; |
| 2352 | if (!sas_device_priv_data) |
| 2353 | continue; |
| 2354 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2355 | sas_device_priv_data->sas_target->tm_busy = 0; |
| 2356 | skip = 1; |
| 2357 | ioc->ignore_loginfos = 0; |
| 2358 | } |
| 2359 | } |
| 2360 | } |
| 2361 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2362 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2363 | /** |
| 2364 | * mpt2sas_scsih_issue_tm - main routine for sending tm requests |
| 2365 | * @ioc: per adapter struct |
| 2366 | * @device_handle: device handle |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2367 | * @channel: the channel assigned by the OS |
| 2368 | * @id: the id assigned by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2369 | * @lun: lun number |
| 2370 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) |
| 2371 | * @smid_task: smid assigned to the task |
| 2372 | * @timeout: timeout in seconds |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2373 | * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2374 | * Context: user |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2375 | * |
| 2376 | * A generic API for sending task management requests to firmware. |
| 2377 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2378 | * The callback index is set inside `ioc->tm_cb_idx`. |
| 2379 | * |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2380 | * Return SUCCESS or FAILED. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2381 | */ |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2382 | int |
| 2383 | mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel, |
| 2384 | uint id, uint lun, u8 type, u16 smid_task, ulong timeout, |
Matthew Wilcox | 2e45c8b | 2014-03-27 16:40:32 -0400 | [diff] [blame] | 2385 | enum mutex_type m_type) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2386 | { |
| 2387 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 2388 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
| 2389 | u16 smid = 0; |
| 2390 | u32 ioc_state; |
| 2391 | unsigned long timeleft; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2392 | struct scsiio_tracker *scsi_lookup = NULL; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2393 | int rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2394 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2395 | if (m_type == TM_MUTEX_ON) |
| 2396 | mutex_lock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2397 | if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) { |
| 2398 | printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n", |
| 2399 | __func__, ioc->name); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2400 | rc = FAILED; |
| 2401 | goto err_out; |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2402 | } |
| 2403 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 2404 | if (ioc->shost_recovery || ioc->remove_host || |
| 2405 | ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2406 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 2407 | __func__, ioc->name); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2408 | rc = FAILED; |
| 2409 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2410 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2411 | |
| 2412 | ioc_state = mpt2sas_base_get_iocstate(ioc, 0); |
| 2413 | if (ioc_state & MPI2_DOORBELL_USED) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 2414 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2415 | "active!\n", ioc->name)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2416 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2417 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2418 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2419 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 2423 | mpt2sas_base_fault_info(ioc, ioc_state & |
| 2424 | MPI2_DOORBELL_DATA_MASK); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2425 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2426 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2427 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2428 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2429 | } |
| 2430 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2431 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2432 | if (!smid) { |
| 2433 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 2434 | ioc->name, __func__); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2435 | rc = FAILED; |
| 2436 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2437 | } |
| 2438 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2439 | if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) |
| 2440 | scsi_lookup = &ioc->scsi_lookup[smid_task - 1]; |
| 2441 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2442 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x)," |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2443 | " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type, |
| 2444 | smid_task)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2445 | ioc->tm_cmds.status = MPT2_CMD_PENDING; |
| 2446 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 2447 | ioc->tm_cmds.smid = smid; |
| 2448 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2449 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2450 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 2451 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 2452 | mpi_request->TaskType = type; |
| 2453 | mpi_request->TaskMID = cpu_to_le16(smid_task); |
| 2454 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); |
| 2455 | mpt2sas_scsih_set_tm_flag(ioc, handle); |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 2456 | init_completion(&ioc->tm_cmds.done); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2457 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2458 | timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2459 | if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) { |
| 2460 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 2461 | ioc->name, __func__); |
| 2462 | _debug_dump_mf(mpi_request, |
| 2463 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2464 | if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) { |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2465 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2466 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2467 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2468 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
| 2469 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 2470 | goto err_out; |
| 2471 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 2475 | mpi_reply = ioc->tm_cmds.reply; |
| 2476 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: " |
| 2477 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", |
| 2478 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 2479 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 2480 | le32_to_cpu(mpi_reply->TerminationCount))); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2481 | if (ioc->logging_level & MPT_DEBUG_TM) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2482 | _scsih_response_code(ioc, mpi_reply->ResponseCode); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2483 | if (mpi_reply->IOCStatus) |
| 2484 | _debug_dump_mf(mpi_request, |
| 2485 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
| 2486 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2487 | } |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2488 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2489 | switch (type) { |
| 2490 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2491 | rc = SUCCESS; |
| 2492 | if (scsi_lookup->scmd == NULL) |
| 2493 | break; |
| 2494 | rc = FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2495 | break; |
| 2496 | |
| 2497 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: |
| 2498 | if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) |
| 2499 | rc = FAILED; |
| 2500 | else |
| 2501 | rc = SUCCESS; |
| 2502 | break; |
| 2503 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2504 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2505 | case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: |
| 2506 | if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) |
| 2507 | rc = FAILED; |
| 2508 | else |
| 2509 | rc = SUCCESS; |
| 2510 | break; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2511 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: |
| 2512 | rc = SUCCESS; |
| 2513 | break; |
| 2514 | default: |
| 2515 | rc = FAILED; |
| 2516 | break; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2517 | } |
| 2518 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2519 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 2520 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2521 | if (m_type == TM_MUTEX_ON) |
| 2522 | mutex_unlock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2523 | |
| 2524 | return rc; |
| 2525 | |
| 2526 | err_out: |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2527 | if (m_type == TM_MUTEX_ON) |
| 2528 | mutex_unlock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2529 | return rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | /** |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2533 | * _scsih_tm_display_info - displays info about the device |
| 2534 | * @ioc: per adapter struct |
| 2535 | * @scmd: pointer to scsi command object |
| 2536 | * |
| 2537 | * Called by task management callback handlers. |
| 2538 | */ |
| 2539 | static void |
| 2540 | _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) |
| 2541 | { |
| 2542 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2543 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; |
| 2544 | struct _sas_device *sas_device = NULL; |
| 2545 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2546 | char *device_str = NULL; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2547 | |
| 2548 | if (!priv_target) |
| 2549 | return; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2550 | if (ioc->hide_ir_msg) |
| 2551 | device_str = "WarpDrive"; |
| 2552 | else |
| 2553 | device_str = "volume"; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2554 | |
| 2555 | scsi_print_command(scmd); |
| 2556 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2557 | starget_printk(KERN_INFO, starget, "%s handle(0x%04x), " |
| 2558 | "%s wwid(0x%016llx)\n", device_str, priv_target->handle, |
| 2559 | device_str, (unsigned long long)priv_target->sas_address); |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2560 | } else { |
| 2561 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2562 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2563 | priv_target->sas_address); |
| 2564 | if (sas_device) { |
| 2565 | if (priv_target->flags & |
| 2566 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2567 | starget_printk(KERN_INFO, starget, |
| 2568 | "volume handle(0x%04x), " |
| 2569 | "volume wwid(0x%016llx)\n", |
| 2570 | sas_device->volume_handle, |
| 2571 | (unsigned long long)sas_device->volume_wwid); |
| 2572 | } |
| 2573 | starget_printk(KERN_INFO, starget, |
| 2574 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", |
| 2575 | sas_device->handle, |
| 2576 | (unsigned long long)sas_device->sas_address, |
| 2577 | sas_device->phy); |
| 2578 | starget_printk(KERN_INFO, starget, |
| 2579 | "enclosure_logical_id(0x%016llx), slot(%d)\n", |
| 2580 | (unsigned long long)sas_device->enclosure_logical_id, |
| 2581 | sas_device->slot); |
| 2582 | } |
| 2583 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2588 | * _scsih_abort - eh threads main abort routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2589 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2590 | * |
| 2591 | * Returns SUCCESS if command aborted else FAILED |
| 2592 | */ |
| 2593 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2594 | _scsih_abort(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2595 | { |
| 2596 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2597 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2598 | u16 smid; |
| 2599 | u16 handle; |
| 2600 | int r; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2601 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2602 | sdev_printk(KERN_INFO, scmd->device, "attempting task abort! " |
| 2603 | "scmd(%p)\n", scmd); |
| 2604 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2605 | |
| 2606 | sas_device_priv_data = scmd->device->hostdata; |
| 2607 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2608 | sdev_printk(KERN_INFO, scmd->device, "device been deleted! " |
| 2609 | "scmd(%p)\n", scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2610 | scmd->result = DID_NO_CONNECT << 16; |
| 2611 | scmd->scsi_done(scmd); |
| 2612 | r = SUCCESS; |
| 2613 | goto out; |
| 2614 | } |
| 2615 | |
| 2616 | /* search for the command */ |
| 2617 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); |
| 2618 | if (!smid) { |
| 2619 | scmd->result = DID_RESET << 16; |
| 2620 | r = SUCCESS; |
| 2621 | goto out; |
| 2622 | } |
| 2623 | |
| 2624 | /* for hidden raid components and volumes this is not supported */ |
| 2625 | if (sas_device_priv_data->sas_target->flags & |
| 2626 | MPT_TARGET_FLAGS_RAID_COMPONENT || |
| 2627 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 2628 | scmd->result = DID_RESET << 16; |
| 2629 | r = FAILED; |
| 2630 | goto out; |
| 2631 | } |
| 2632 | |
Kashyap, Desai | fa7f316 | 2009-09-23 17:26:58 +0530 | [diff] [blame] | 2633 | mpt2sas_halt_firmware(ioc); |
| 2634 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2635 | handle = sas_device_priv_data->sas_target->handle; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2636 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2637 | scmd->device->id, scmd->device->lun, |
Matthew Wilcox | 2e45c8b | 2014-03-27 16:40:32 -0400 | [diff] [blame] | 2638 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, 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, |
Matthew Wilcox | 2e45c8b | 2014-03-27 16:40:32 -0400 | [diff] [blame] | 2699 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2700 | |
| 2701 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2702 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", |
| 2703 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2704 | return r; |
| 2705 | } |
| 2706 | |
| 2707 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2708 | * _scsih_target_reset - eh threads main target reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2709 | * @scmd: pointer to scsi command object |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2710 | * |
| 2711 | * Returns SUCCESS if command aborted else FAILED |
| 2712 | */ |
| 2713 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2714 | _scsih_target_reset(struct scsi_cmnd *scmd) |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2715 | { |
| 2716 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2717 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2718 | struct _sas_device *sas_device; |
| 2719 | unsigned long flags; |
| 2720 | u16 handle; |
| 2721 | int r; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2722 | struct scsi_target *starget = scmd->device->sdev_target; |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2723 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2724 | starget_printk(KERN_INFO, starget, "attempting target reset! " |
| 2725 | "scmd(%p)\n", scmd); |
| 2726 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2727 | |
| 2728 | sas_device_priv_data = scmd->device->hostdata; |
| 2729 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2730 | starget_printk(KERN_INFO, starget, "target been deleted! " |
| 2731 | "scmd(%p)\n", scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2732 | scmd->result = DID_NO_CONNECT << 16; |
| 2733 | scmd->scsi_done(scmd); |
| 2734 | r = SUCCESS; |
| 2735 | goto out; |
| 2736 | } |
| 2737 | |
| 2738 | /* for hidden raid components obtain the volume_handle */ |
| 2739 | handle = 0; |
| 2740 | if (sas_device_priv_data->sas_target->flags & |
| 2741 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2742 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2743 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2744 | sas_device_priv_data->sas_target->handle); |
| 2745 | if (sas_device) |
| 2746 | handle = sas_device->volume_handle; |
| 2747 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2748 | } else |
| 2749 | handle = sas_device_priv_data->sas_target->handle; |
| 2750 | |
| 2751 | if (!handle) { |
| 2752 | scmd->result = DID_RESET << 16; |
| 2753 | r = FAILED; |
| 2754 | goto out; |
| 2755 | } |
| 2756 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2757 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2758 | scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, |
Matthew Wilcox | 2e45c8b | 2014-03-27 16:40:32 -0400 | [diff] [blame] | 2759 | 30, TM_MUTEX_ON); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2760 | |
| 2761 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2762 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", |
| 2763 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2764 | return r; |
| 2765 | } |
| 2766 | |
| 2767 | /** |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2768 | * _scsih_host_reset - eh threads main host reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2769 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2770 | * |
| 2771 | * Returns SUCCESS if command aborted else FAILED |
| 2772 | */ |
| 2773 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2774 | _scsih_host_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2775 | { |
| 2776 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2777 | int r, retval; |
| 2778 | |
| 2779 | printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n", |
| 2780 | ioc->name, scmd); |
| 2781 | scsi_print_command(scmd); |
| 2782 | |
| 2783 | retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2784 | FORCE_BIG_HAMMER); |
| 2785 | r = (retval < 0) ? FAILED : SUCCESS; |
| 2786 | printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n", |
| 2787 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 2788 | |
| 2789 | return r; |
| 2790 | } |
| 2791 | |
| 2792 | /** |
| 2793 | * _scsih_fw_event_add - insert and queue up fw_event |
| 2794 | * @ioc: per adapter object |
| 2795 | * @fw_event: object describing the event |
| 2796 | * Context: This function will acquire ioc->fw_event_lock. |
| 2797 | * |
| 2798 | * This adds the firmware event object into link list, then queues it up to |
| 2799 | * be processed from user context. |
| 2800 | * |
| 2801 | * Return nothing. |
| 2802 | */ |
| 2803 | static void |
| 2804 | _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event) |
| 2805 | { |
| 2806 | unsigned long flags; |
| 2807 | |
| 2808 | if (ioc->firmware_event_thread == NULL) |
| 2809 | return; |
| 2810 | |
| 2811 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2812 | list_add_tail(&fw_event->list, &ioc->fw_event_list); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2813 | INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work); |
| 2814 | queue_delayed_work(ioc->firmware_event_thread, |
| 2815 | &fw_event->delayed_work, 0); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2816 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2817 | } |
| 2818 | |
| 2819 | /** |
| 2820 | * _scsih_fw_event_free - delete fw_event |
| 2821 | * @ioc: per adapter object |
| 2822 | * @fw_event: object describing the event |
| 2823 | * Context: This function will acquire ioc->fw_event_lock. |
| 2824 | * |
| 2825 | * This removes firmware event object from link list, frees associated memory. |
| 2826 | * |
| 2827 | * Return nothing. |
| 2828 | */ |
| 2829 | static void |
| 2830 | _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work |
| 2831 | *fw_event) |
| 2832 | { |
| 2833 | unsigned long flags; |
| 2834 | |
| 2835 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2836 | list_del(&fw_event->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2837 | kfree(fw_event); |
| 2838 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2839 | } |
| 2840 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2841 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2842 | /** |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2843 | * _scsih_error_recovery_delete_devices - remove devices not responding |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2844 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2845 | * |
| 2846 | * Return nothing. |
| 2847 | */ |
| 2848 | static void |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2849 | _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2850 | { |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2851 | struct fw_event_work *fw_event; |
| 2852 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2853 | if (ioc->is_driver_loading) |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2854 | return; |
Dan Carpenter | 181a9d7 | 2011-11-04 21:25:01 +0300 | [diff] [blame] | 2855 | |
| 2856 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2857 | if (!fw_event) |
| 2858 | return; |
| 2859 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2860 | fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES; |
| 2861 | fw_event->ioc = ioc; |
| 2862 | _scsih_fw_event_add(ioc, fw_event); |
| 2863 | } |
| 2864 | |
| 2865 | /** |
| 2866 | * mpt2sas_port_enable_complete - port enable completed (fake event) |
| 2867 | * @ioc: per adapter object |
| 2868 | * |
| 2869 | * Return nothing. |
| 2870 | */ |
| 2871 | void |
| 2872 | mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc) |
| 2873 | { |
| 2874 | struct fw_event_work *fw_event; |
| 2875 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2876 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2877 | if (!fw_event) |
| 2878 | return; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2879 | fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2880 | fw_event->ioc = ioc; |
| 2881 | _scsih_fw_event_add(ioc, fw_event); |
| 2882 | } |
| 2883 | |
| 2884 | /** |
| 2885 | * _scsih_fw_event_cleanup_queue - cleanup event queue |
| 2886 | * @ioc: per adapter object |
| 2887 | * |
| 2888 | * Walk the firmware event queue, either killing timers, or waiting |
| 2889 | * for outstanding events to complete |
| 2890 | * |
| 2891 | * Return nothing. |
| 2892 | */ |
| 2893 | static void |
| 2894 | _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc) |
| 2895 | { |
| 2896 | struct fw_event_work *fw_event, *next; |
| 2897 | |
| 2898 | if (list_empty(&ioc->fw_event_list) || |
| 2899 | !ioc->firmware_event_thread || in_interrupt()) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2900 | return; |
| 2901 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2902 | list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) { |
Reddy, Sreekanth | 02b7708 | 2014-07-14 12:00:49 +0530 | [diff] [blame^] | 2903 | if (cancel_delayed_work_sync(&fw_event->delayed_work)) { |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2904 | _scsih_fw_event_free(ioc, fw_event); |
| 2905 | continue; |
| 2906 | } |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2907 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2908 | } |
| 2909 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2910 | /** |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2911 | * _scsih_ublock_io_all_device - unblock every device |
| 2912 | * @ioc: per adapter object |
| 2913 | * |
| 2914 | * change the device state from block to running |
| 2915 | */ |
| 2916 | static void |
| 2917 | _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc) |
| 2918 | { |
| 2919 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2920 | struct scsi_device *sdev; |
| 2921 | |
| 2922 | shost_for_each_device(sdev, ioc->shost) { |
| 2923 | sas_device_priv_data = sdev->hostdata; |
| 2924 | if (!sas_device_priv_data) |
| 2925 | continue; |
| 2926 | if (!sas_device_priv_data->block) |
| 2927 | continue; |
| 2928 | sas_device_priv_data->block = 0; |
| 2929 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, " |
| 2930 | "handle(0x%04x)\n", |
| 2931 | sas_device_priv_data->sas_target->handle)); |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 2932 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2933 | } |
| 2934 | } |
| 2935 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2936 | * _scsih_ublock_io_device - set the device state to SDEV_RUNNING |
| 2937 | * @ioc: per adapter object |
| 2938 | * @handle: device handle |
| 2939 | * |
| 2940 | * During device pull we need to appropiately set the sdev state. |
| 2941 | */ |
| 2942 | static void |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2943 | _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2944 | { |
| 2945 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2946 | struct scsi_device *sdev; |
| 2947 | |
| 2948 | shost_for_each_device(sdev, ioc->shost) { |
| 2949 | sas_device_priv_data = sdev->hostdata; |
| 2950 | if (!sas_device_priv_data) |
| 2951 | continue; |
| 2952 | if (!sas_device_priv_data->block) |
| 2953 | continue; |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2954 | if (sas_device_priv_data->sas_target->sas_address == |
| 2955 | sas_address) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2956 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2957 | MPT2SAS_INFO_FMT "SDEV_RUNNING: " |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2958 | "sas address(0x%016llx)\n", ioc->name, |
| 2959 | (unsigned long long)sas_address)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2960 | sas_device_priv_data->block = 0; |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 2961 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2962 | } |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | /** |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2967 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK |
| 2968 | * @ioc: per adapter object |
| 2969 | * @handle: device handle |
| 2970 | * |
| 2971 | * During device pull we need to appropiately set the sdev state. |
| 2972 | */ |
| 2973 | static void |
| 2974 | _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc) |
| 2975 | { |
| 2976 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2977 | struct scsi_device *sdev; |
| 2978 | |
| 2979 | shost_for_each_device(sdev, ioc->shost) { |
| 2980 | sas_device_priv_data = sdev->hostdata; |
| 2981 | if (!sas_device_priv_data) |
| 2982 | continue; |
| 2983 | if (sas_device_priv_data->block) |
| 2984 | continue; |
| 2985 | sas_device_priv_data->block = 1; |
| 2986 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, " |
| 2987 | "handle(0x%04x)\n", |
| 2988 | sas_device_priv_data->sas_target->handle)); |
| 2989 | scsi_internal_device_block(sdev); |
| 2990 | } |
| 2991 | } |
| 2992 | |
| 2993 | |
| 2994 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2995 | * _scsih_block_io_device - set the device state to SDEV_BLOCK |
| 2996 | * @ioc: per adapter object |
| 2997 | * @handle: device handle |
| 2998 | * |
| 2999 | * During device pull we need to appropiately set the sdev state. |
| 3000 | */ |
| 3001 | static void |
| 3002 | _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3003 | { |
| 3004 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 3005 | struct scsi_device *sdev; |
| 3006 | |
| 3007 | shost_for_each_device(sdev, ioc->shost) { |
| 3008 | sas_device_priv_data = sdev->hostdata; |
| 3009 | if (!sas_device_priv_data) |
| 3010 | continue; |
| 3011 | if (sas_device_priv_data->block) |
| 3012 | continue; |
| 3013 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 3014 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 3015 | MPT2SAS_INFO_FMT "SDEV_BLOCK: " |
| 3016 | "handle(0x%04x)\n", ioc->name, handle)); |
| 3017 | sas_device_priv_data->block = 1; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 3018 | scsi_internal_device_block(sdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3019 | } |
| 3020 | } |
| 3021 | } |
| 3022 | |
| 3023 | /** |
| 3024 | * _scsih_block_io_to_children_attached_to_ex |
| 3025 | * @ioc: per adapter object |
| 3026 | * @sas_expander: the sas_device object |
| 3027 | * |
| 3028 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 3029 | * attached to this expander. This function called when expander is |
| 3030 | * pulled. |
| 3031 | */ |
| 3032 | static void |
| 3033 | _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc, |
| 3034 | struct _sas_node *sas_expander) |
| 3035 | { |
| 3036 | struct _sas_port *mpt2sas_port; |
| 3037 | struct _sas_device *sas_device; |
| 3038 | struct _sas_node *expander_sibling; |
| 3039 | unsigned long flags; |
| 3040 | |
| 3041 | if (!sas_expander) |
| 3042 | return; |
| 3043 | |
| 3044 | list_for_each_entry(mpt2sas_port, |
| 3045 | &sas_expander->sas_port_list, port_list) { |
| 3046 | if (mpt2sas_port->remote_identify.device_type == |
| 3047 | SAS_END_DEVICE) { |
| 3048 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3049 | sas_device = |
| 3050 | mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 3051 | mpt2sas_port->remote_identify.sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 3052 | if (sas_device) |
| 3053 | set_bit(sas_device->handle, |
| 3054 | ioc->blocking_handles); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3055 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3056 | } |
| 3057 | } |
| 3058 | |
| 3059 | list_for_each_entry(mpt2sas_port, |
| 3060 | &sas_expander->sas_port_list, port_list) { |
| 3061 | |
| 3062 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 3063 | SAS_EDGE_EXPANDER_DEVICE || |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3064 | mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 3065 | SAS_FANOUT_EXPANDER_DEVICE) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3066 | expander_sibling = |
| 3067 | mpt2sas_scsih_expander_find_by_sas_address( |
| 3068 | ioc, mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3069 | _scsih_block_io_to_children_attached_to_ex(ioc, |
| 3070 | expander_sibling); |
| 3071 | } |
| 3072 | } |
| 3073 | } |
| 3074 | |
| 3075 | /** |
| 3076 | * _scsih_block_io_to_children_attached_directly |
| 3077 | * @ioc: per adapter object |
| 3078 | * @event_data: topology change event data |
| 3079 | * |
| 3080 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 3081 | * direct attached during device pull. |
| 3082 | */ |
| 3083 | static void |
| 3084 | _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc, |
| 3085 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3086 | { |
| 3087 | int i; |
| 3088 | u16 handle; |
| 3089 | u16 reason_code; |
| 3090 | u8 phy_number; |
| 3091 | |
| 3092 | for (i = 0; i < event_data->NumEntries; i++) { |
| 3093 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3094 | if (!handle) |
| 3095 | continue; |
| 3096 | phy_number = event_data->StartPhyNum + i; |
| 3097 | reason_code = event_data->PHY[i].PhyStatus & |
| 3098 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3099 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) |
| 3100 | _scsih_block_io_device(ioc, handle); |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3105 | * _scsih_tm_tr_send - send task management request |
| 3106 | * @ioc: per adapter object |
| 3107 | * @handle: device handle |
| 3108 | * Context: interrupt time. |
| 3109 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3110 | * This code is to initiate the device removal handshake protocol |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3111 | * with controller firmware. This function will issue target reset |
| 3112 | * using high priority request queue. It will send a sas iounit |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3113 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3114 | * |
| 3115 | * This is designed to send muliple task management request at the same |
| 3116 | * time to the fifo. If the fifo is full, we will append the request, |
| 3117 | * and process it in a future completion. |
| 3118 | */ |
| 3119 | static void |
| 3120 | _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3121 | { |
| 3122 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3123 | u16 smid; |
| 3124 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3125 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; |
| 3126 | u64 sas_address = 0; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3127 | unsigned long flags; |
| 3128 | struct _tr_list *delayed_tr; |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3129 | u32 ioc_state; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3130 | |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3131 | if (ioc->remove_host) { |
| 3132 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been " |
| 3133 | "removed: handle(0x%04x)\n", __func__, ioc->name, handle)); |
| 3134 | return; |
| 3135 | } else if (ioc->pci_error_recovery) { |
| 3136 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci " |
| 3137 | "error recovery: handle(0x%04x)\n", __func__, ioc->name, |
| 3138 | handle)); |
| 3139 | return; |
| 3140 | } |
| 3141 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 3142 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 3143 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not " |
| 3144 | "operational: handle(0x%04x)\n", __func__, ioc->name, |
| 3145 | handle)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3146 | return; |
| 3147 | } |
| 3148 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3149 | /* if PD, then return */ |
| 3150 | if (test_bit(handle, ioc->pd_handles)) |
| 3151 | return; |
| 3152 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3153 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3154 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3155 | if (sas_device && sas_device->starget && |
| 3156 | sas_device->starget->hostdata) { |
| 3157 | sas_target_priv_data = sas_device->starget->hostdata; |
| 3158 | sas_target_priv_data->deleted = 1; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3159 | sas_address = sas_device->sas_address; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3160 | } |
| 3161 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3162 | |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3163 | if (sas_target_priv_data) { |
| 3164 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: " |
| 3165 | "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle, |
| 3166 | (unsigned long long)sas_address)); |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 3167 | _scsih_ublock_io_device(ioc, sas_address); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 3168 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3169 | } |
| 3170 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3171 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); |
| 3172 | if (!smid) { |
| 3173 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3174 | if (!delayed_tr) |
| 3175 | return; |
| 3176 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3177 | delayed_tr->handle = handle; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3178 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 3179 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3180 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 3181 | ioc->name, handle)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3182 | return; |
| 3183 | } |
| 3184 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3185 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " |
| 3186 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, |
| 3187 | ioc->tm_tr_cb_idx)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3188 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3189 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 3190 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3191 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3192 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3193 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
| 3194 | } |
| 3195 | |
| 3196 | |
| 3197 | |
| 3198 | /** |
| 3199 | * _scsih_sas_control_complete - completion routine |
| 3200 | * @ioc: per adapter object |
| 3201 | * @smid: system request message index |
| 3202 | * @msix_index: MSIX table index supplied by the OS |
| 3203 | * @reply: reply message frame(lower 32bit addr) |
| 3204 | * Context: interrupt time. |
| 3205 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3206 | * This is the sas iounit control completion routine. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3207 | * 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] | 3208 | * handshake protocol with controller firmware. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3209 | * |
| 3210 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3211 | * 0 means the mf is freed from this function. |
| 3212 | */ |
| 3213 | static u8 |
| 3214 | _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 3215 | u8 msix_index, u32 reply) |
| 3216 | { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3217 | Mpi2SasIoUnitControlReply_t *mpi_reply = |
| 3218 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3219 | if (likely(mpi_reply)) { |
| 3220 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3221 | "sc_complete:handle(0x%04x), (open) " |
| 3222 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 3223 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, |
| 3224 | le16_to_cpu(mpi_reply->IOCStatus), |
| 3225 | le32_to_cpu(mpi_reply->IOCLogInfo))); |
| 3226 | } else { |
| 3227 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3228 | ioc->name, __FILE__, __LINE__, __func__); |
| 3229 | } |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3230 | return 1; |
| 3231 | } |
| 3232 | |
| 3233 | /** |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3234 | * _scsih_tm_tr_volume_send - send target reset request for volumes |
| 3235 | * @ioc: per adapter object |
| 3236 | * @handle: device handle |
| 3237 | * Context: interrupt time. |
| 3238 | * |
| 3239 | * This is designed to send muliple task management request at the same |
| 3240 | * time to the fifo. If the fifo is full, we will append the request, |
| 3241 | * and process it in a future completion. |
| 3242 | */ |
| 3243 | static void |
| 3244 | _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3245 | { |
| 3246 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 3247 | u16 smid; |
| 3248 | struct _tr_list *delayed_tr; |
| 3249 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3250 | if (ioc->shost_recovery || ioc->remove_host || |
| 3251 | ioc->pci_error_recovery) { |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3252 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3253 | "progress!\n", __func__, ioc->name)); |
| 3254 | return; |
| 3255 | } |
| 3256 | |
| 3257 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); |
| 3258 | if (!smid) { |
| 3259 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3260 | if (!delayed_tr) |
| 3261 | return; |
| 3262 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3263 | delayed_tr->handle = handle; |
| 3264 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); |
| 3265 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3266 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 3267 | ioc->name, handle)); |
| 3268 | return; |
| 3269 | } |
| 3270 | |
| 3271 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " |
| 3272 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, |
| 3273 | ioc->tm_tr_volume_cb_idx)); |
| 3274 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3275 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 3276 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3277 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3278 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
| 3279 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
| 3280 | } |
| 3281 | |
| 3282 | /** |
| 3283 | * _scsih_tm_volume_tr_complete - target reset completion |
| 3284 | * @ioc: per adapter object |
| 3285 | * @smid: system request message index |
| 3286 | * @msix_index: MSIX table index supplied by the OS |
| 3287 | * @reply: reply message frame(lower 32bit addr) |
| 3288 | * Context: interrupt time. |
| 3289 | * |
| 3290 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3291 | * 0 means the mf is freed from this function. |
| 3292 | */ |
| 3293 | static u8 |
| 3294 | _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 3295 | u8 msix_index, u32 reply) |
| 3296 | { |
| 3297 | u16 handle; |
| 3298 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
| 3299 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3300 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 3301 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3302 | if (ioc->shost_recovery || ioc->remove_host || |
| 3303 | ioc->pci_error_recovery) { |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3304 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3305 | "progress!\n", __func__, ioc->name)); |
| 3306 | return 1; |
| 3307 | } |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3308 | if (unlikely(!mpi_reply)) { |
| 3309 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3310 | ioc->name, __FILE__, __LINE__, __func__); |
| 3311 | return 1; |
| 3312 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3313 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3314 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3315 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3316 | dewtprintk(ioc, printk("spurious interrupt: " |
| 3317 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle, |
| 3318 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3319 | return 0; |
| 3320 | } |
| 3321 | |
| 3322 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3323 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3324 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3325 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3326 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3327 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3328 | |
| 3329 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3330 | } |
| 3331 | |
| 3332 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3333 | * _scsih_tm_tr_complete - |
| 3334 | * @ioc: per adapter object |
| 3335 | * @smid: system request message index |
| 3336 | * @msix_index: MSIX table index supplied by the OS |
| 3337 | * @reply: reply message frame(lower 32bit addr) |
| 3338 | * Context: interrupt time. |
| 3339 | * |
| 3340 | * This is the target reset completion routine. |
| 3341 | * 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] | 3342 | * handshake protocol with controller firmware. |
| 3343 | * 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] | 3344 | * |
| 3345 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3346 | * 0 means the mf is freed from this function. |
| 3347 | */ |
| 3348 | static u8 |
| 3349 | _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 3350 | u32 reply) |
| 3351 | { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3352 | u16 handle; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3353 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3354 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3355 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 3356 | Mpi2SasIoUnitControlRequest_t *mpi_request; |
| 3357 | u16 smid_sas_ctrl; |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3358 | u32 ioc_state; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3359 | |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3360 | if (ioc->remove_host) { |
| 3361 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been " |
| 3362 | "removed\n", __func__, ioc->name)); |
| 3363 | return 1; |
| 3364 | } else if (ioc->pci_error_recovery) { |
| 3365 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci " |
| 3366 | "error recovery\n", __func__, ioc->name)); |
| 3367 | return 1; |
| 3368 | } |
| 3369 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 3370 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 3371 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not " |
| 3372 | "operational\n", __func__, ioc->name)); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3373 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3374 | } |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3375 | if (unlikely(!mpi_reply)) { |
| 3376 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3377 | ioc->name, __FILE__, __LINE__, __func__); |
| 3378 | return 1; |
| 3379 | } |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3380 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3381 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3382 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3383 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: " |
| 3384 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle, |
| 3385 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3386 | return 0; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3387 | } |
| 3388 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3389 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3390 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3391 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3392 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3393 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3394 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3395 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3396 | smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); |
| 3397 | if (!smid_sas_ctrl) { |
| 3398 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 3399 | ioc->name, __func__); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3400 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3401 | } |
| 3402 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3403 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), " |
| 3404 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl, |
| 3405 | ioc->tm_sas_control_cb_idx)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3406 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl); |
| 3407 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); |
| 3408 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; |
| 3409 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3410 | mpi_request->DevHandle = mpi_request_tm->DevHandle; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3411 | mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3412 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3413 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3414 | } |
| 3415 | |
| 3416 | /** |
| 3417 | * _scsih_check_for_pending_tm - check for pending task management |
| 3418 | * @ioc: per adapter object |
| 3419 | * @smid: system request message index |
| 3420 | * |
| 3421 | * This will check delayed target reset list, and feed the |
| 3422 | * next reqeust. |
| 3423 | * |
| 3424 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3425 | * 0 means the mf is freed from this function. |
| 3426 | */ |
| 3427 | static u8 |
| 3428 | _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 3429 | { |
| 3430 | struct _tr_list *delayed_tr; |
| 3431 | |
| 3432 | if (!list_empty(&ioc->delayed_tr_volume_list)) { |
| 3433 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, |
| 3434 | struct _tr_list, list); |
| 3435 | mpt2sas_base_free_smid(ioc, smid); |
| 3436 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); |
| 3437 | list_del(&delayed_tr->list); |
| 3438 | kfree(delayed_tr); |
| 3439 | return 0; |
| 3440 | } |
| 3441 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3442 | if (!list_empty(&ioc->delayed_tr_list)) { |
| 3443 | delayed_tr = list_entry(ioc->delayed_tr_list.next, |
| 3444 | struct _tr_list, list); |
| 3445 | mpt2sas_base_free_smid(ioc, smid); |
| 3446 | _scsih_tm_tr_send(ioc, delayed_tr->handle); |
| 3447 | list_del(&delayed_tr->list); |
| 3448 | kfree(delayed_tr); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3449 | return 0; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3450 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3451 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3452 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3456 | * _scsih_check_topo_delete_events - sanity check on topo events |
| 3457 | * @ioc: per adapter object |
| 3458 | * @event_data: the event data payload |
| 3459 | * |
| 3460 | * This routine added to better handle cable breaker. |
| 3461 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3462 | * This handles the case where driver receives multiple expander |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3463 | * add and delete events in a single shot. When there is a delete event |
| 3464 | * the routine will void any pending add events waiting in the event queue. |
| 3465 | * |
| 3466 | * Return nothing. |
| 3467 | */ |
| 3468 | static void |
| 3469 | _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 3470 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3471 | { |
| 3472 | struct fw_event_work *fw_event; |
| 3473 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; |
| 3474 | u16 expander_handle; |
| 3475 | struct _sas_node *sas_expander; |
| 3476 | unsigned long flags; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3477 | int i, reason_code; |
| 3478 | u16 handle; |
| 3479 | |
| 3480 | for (i = 0 ; i < event_data->NumEntries; i++) { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3481 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3482 | if (!handle) |
| 3483 | continue; |
| 3484 | reason_code = event_data->PHY[i].PhyStatus & |
| 3485 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3486 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) |
| 3487 | _scsih_tm_tr_send(ioc, handle); |
| 3488 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3489 | |
| 3490 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 3491 | if (expander_handle < ioc->sas_hba.num_phys) { |
| 3492 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3493 | return; |
| 3494 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 3495 | if (event_data->ExpStatus == |
| 3496 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { |
| 3497 | /* put expander attached devices into blocking state */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3498 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 3499 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 3500 | expander_handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3501 | _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] | 3502 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 3503 | do { |
| 3504 | handle = find_first_bit(ioc->blocking_handles, |
| 3505 | ioc->facts.MaxDevHandle); |
| 3506 | if (handle < ioc->facts.MaxDevHandle) |
| 3507 | _scsih_block_io_device(ioc, handle); |
| 3508 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3509 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) |
| 3510 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3511 | |
| 3512 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) |
| 3513 | return; |
| 3514 | |
| 3515 | /* mark ignore flag for pending events */ |
| 3516 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 3517 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { |
| 3518 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || |
| 3519 | fw_event->ignore) |
| 3520 | continue; |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 3521 | local_event_data = (Mpi2EventDataSasTopologyChangeList_t *) |
| 3522 | fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3523 | if (local_event_data->ExpStatus == |
| 3524 | MPI2_EVENT_SAS_TOPO_ES_ADDED || |
| 3525 | local_event_data->ExpStatus == |
| 3526 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { |
| 3527 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == |
| 3528 | expander_handle) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 3529 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3530 | "setting ignoring flag\n", ioc->name)); |
| 3531 | fw_event->ignore = 1; |
| 3532 | } |
| 3533 | } |
| 3534 | } |
| 3535 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 3536 | } |
| 3537 | |
| 3538 | /** |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3539 | * _scsih_set_volume_delete_flag - setting volume delete flag |
| 3540 | * @ioc: per adapter object |
| 3541 | * @handle: device handle |
| 3542 | * |
| 3543 | * This |
| 3544 | * Return nothing. |
| 3545 | */ |
| 3546 | static void |
| 3547 | _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3548 | { |
| 3549 | struct _raid_device *raid_device; |
| 3550 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 3551 | unsigned long flags; |
| 3552 | |
| 3553 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 3554 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 3555 | if (raid_device && raid_device->starget && |
| 3556 | raid_device->starget->hostdata) { |
| 3557 | sas_target_priv_data = |
| 3558 | raid_device->starget->hostdata; |
| 3559 | sas_target_priv_data->deleted = 1; |
| 3560 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3561 | "setting delete flag: handle(0x%04x), " |
| 3562 | "wwid(0x%016llx)\n", ioc->name, handle, |
| 3563 | (unsigned long long) raid_device->wwid)); |
| 3564 | } |
| 3565 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 3566 | } |
| 3567 | |
| 3568 | /** |
| 3569 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume |
| 3570 | * @handle: input handle |
| 3571 | * @a: handle for volume a |
| 3572 | * @b: handle for volume b |
| 3573 | * |
| 3574 | * IR firmware only supports two raid volumes. The purpose of this |
| 3575 | * routine is to set the volume handle in either a or b. When the given |
| 3576 | * input handle is non-zero, or when a and b have not been set before. |
| 3577 | */ |
| 3578 | static void |
| 3579 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) |
| 3580 | { |
| 3581 | if (!handle || handle == *a || handle == *b) |
| 3582 | return; |
| 3583 | if (!*a) |
| 3584 | *a = handle; |
| 3585 | else if (!*b) |
| 3586 | *b = handle; |
| 3587 | } |
| 3588 | |
| 3589 | /** |
| 3590 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events |
| 3591 | * @ioc: per adapter object |
| 3592 | * @event_data: the event data payload |
| 3593 | * Context: interrupt time. |
| 3594 | * |
| 3595 | * This routine will send target reset to volume, followed by target |
| 3596 | * resets to the PDs. This is called when a PD has been removed, or |
| 3597 | * volume has been deleted or removed. When the target reset is sent |
| 3598 | * to volume, the PD target resets need to be queued to start upon |
| 3599 | * completion of the volume target reset. |
| 3600 | * |
| 3601 | * Return nothing. |
| 3602 | */ |
| 3603 | static void |
| 3604 | _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc, |
| 3605 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 3606 | { |
| 3607 | Mpi2EventIrConfigElement_t *element; |
| 3608 | int i; |
| 3609 | u16 handle, volume_handle, a, b; |
| 3610 | struct _tr_list *delayed_tr; |
| 3611 | |
| 3612 | a = 0; |
| 3613 | b = 0; |
| 3614 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3615 | if (ioc->is_warpdrive) |
| 3616 | return; |
| 3617 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3618 | /* Volume Resets for Deleted or Removed */ |
| 3619 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3620 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3621 | if (element->ReasonCode == |
| 3622 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || |
| 3623 | element->ReasonCode == |
| 3624 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { |
| 3625 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3626 | _scsih_set_volume_delete_flag(ioc, volume_handle); |
| 3627 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3628 | } |
| 3629 | } |
| 3630 | |
| 3631 | /* Volume Resets for UNHIDE events */ |
| 3632 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3633 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3634 | if (le32_to_cpu(event_data->Flags) & |
| 3635 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) |
| 3636 | continue; |
| 3637 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { |
| 3638 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3639 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3640 | } |
| 3641 | } |
| 3642 | |
| 3643 | if (a) |
| 3644 | _scsih_tm_tr_volume_send(ioc, a); |
| 3645 | if (b) |
| 3646 | _scsih_tm_tr_volume_send(ioc, b); |
| 3647 | |
| 3648 | /* PD target resets */ |
| 3649 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3650 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3651 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) |
| 3652 | continue; |
| 3653 | handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 3654 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3655 | clear_bit(handle, ioc->pd_handles); |
| 3656 | if (!volume_handle) |
| 3657 | _scsih_tm_tr_send(ioc, handle); |
| 3658 | else if (volume_handle == a || volume_handle == b) { |
| 3659 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3660 | BUG_ON(!delayed_tr); |
| 3661 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3662 | delayed_tr->handle = handle; |
| 3663 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 3664 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3665 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, |
| 3666 | handle)); |
| 3667 | } else |
| 3668 | _scsih_tm_tr_send(ioc, handle); |
| 3669 | } |
| 3670 | } |
| 3671 | |
| 3672 | |
| 3673 | /** |
| 3674 | * _scsih_check_volume_delete_events - set delete flag for volumes |
| 3675 | * @ioc: per adapter object |
| 3676 | * @event_data: the event data payload |
| 3677 | * Context: interrupt time. |
| 3678 | * |
| 3679 | * This will handle the case when the cable connected to entire volume is |
| 3680 | * pulled. We will take care of setting the deleted flag so normal IO will |
| 3681 | * not be sent. |
| 3682 | * |
| 3683 | * Return nothing. |
| 3684 | */ |
| 3685 | static void |
| 3686 | _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 3687 | Mpi2EventDataIrVolume_t *event_data) |
| 3688 | { |
| 3689 | u32 state; |
| 3690 | |
| 3691 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 3692 | return; |
| 3693 | state = le32_to_cpu(event_data->NewValue); |
| 3694 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == |
| 3695 | MPI2_RAID_VOL_STATE_FAILED) |
| 3696 | _scsih_set_volume_delete_flag(ioc, |
| 3697 | le16_to_cpu(event_data->VolDevHandle)); |
| 3698 | } |
| 3699 | |
| 3700 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3701 | * _scsih_flush_running_cmds - completing outstanding commands. |
| 3702 | * @ioc: per adapter object |
| 3703 | * |
| 3704 | * The flushing out of all pending scmd commands following host reset, |
| 3705 | * where all IO is dropped to the floor. |
| 3706 | * |
| 3707 | * Return nothing. |
| 3708 | */ |
| 3709 | static void |
| 3710 | _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc) |
| 3711 | { |
| 3712 | struct scsi_cmnd *scmd; |
| 3713 | u16 smid; |
| 3714 | u16 count = 0; |
| 3715 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3716 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 3717 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3718 | if (!scmd) |
| 3719 | continue; |
| 3720 | count++; |
| 3721 | mpt2sas_base_free_smid(ioc, smid); |
| 3722 | scsi_dma_unmap(scmd); |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3723 | if (ioc->pci_error_recovery) |
| 3724 | scmd->result = DID_NO_CONNECT << 16; |
| 3725 | else |
| 3726 | scmd->result = DID_RESET << 16; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3727 | scmd->scsi_done(scmd); |
| 3728 | } |
| 3729 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n", |
| 3730 | ioc->name, count)); |
| 3731 | } |
| 3732 | |
| 3733 | /** |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3734 | * _scsih_setup_eedp - setup MPI request for EEDP transfer |
| 3735 | * @scmd: pointer to scsi command object |
| 3736 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3737 | * |
| 3738 | * Supporting protection 1 and 3. |
| 3739 | * |
| 3740 | * Returns nothing |
| 3741 | */ |
| 3742 | static void |
| 3743 | _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request) |
| 3744 | { |
| 3745 | u16 eedp_flags; |
| 3746 | unsigned char prot_op = scsi_get_prot_op(scmd); |
| 3747 | unsigned char prot_type = scsi_get_prot_type(scmd); |
| 3748 | |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3749 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3750 | return; |
| 3751 | |
| 3752 | if (prot_op == SCSI_PROT_READ_STRIP) |
| 3753 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; |
| 3754 | else if (prot_op == SCSI_PROT_WRITE_INSERT) |
| 3755 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; |
| 3756 | else |
| 3757 | return; |
| 3758 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3759 | switch (prot_type) { |
| 3760 | case SCSI_PROT_DIF_TYPE1: |
Martin K. Petersen | 756aca7 | 2011-05-18 00:45:22 -0400 | [diff] [blame] | 3761 | case SCSI_PROT_DIF_TYPE2: |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3762 | |
| 3763 | /* |
| 3764 | * enable ref/guard checking |
| 3765 | * auto increment ref tag |
| 3766 | */ |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3767 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3768 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | |
| 3769 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
| 3770 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = |
| 3771 | cpu_to_be32(scsi_get_lba(scmd)); |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3772 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3773 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3774 | case SCSI_PROT_DIF_TYPE3: |
| 3775 | |
| 3776 | /* |
| 3777 | * enable guard checking |
| 3778 | */ |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3779 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3780 | break; |
| 3781 | } |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3782 | mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size); |
| 3783 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | /** |
| 3787 | * _scsih_eedp_error_handling - return sense code for EEDP errors |
| 3788 | * @scmd: pointer to scsi command object |
| 3789 | * @ioc_status: ioc status |
| 3790 | * |
| 3791 | * Returns nothing |
| 3792 | */ |
| 3793 | static void |
| 3794 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) |
| 3795 | { |
| 3796 | u8 ascq; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3797 | |
| 3798 | switch (ioc_status) { |
| 3799 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 3800 | ascq = 0x01; |
| 3801 | break; |
| 3802 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 3803 | ascq = 0x02; |
| 3804 | break; |
| 3805 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 3806 | ascq = 0x03; |
| 3807 | break; |
| 3808 | default: |
| 3809 | ascq = 0x00; |
| 3810 | break; |
| 3811 | } |
| 3812 | |
Martin K. Petersen | 9b5cd13 | 2012-08-28 14:29:36 -0400 | [diff] [blame] | 3813 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq); |
| 3814 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3815 | SAM_STAT_CHECK_CONDITION; |
| 3816 | } |
| 3817 | |
| 3818 | /** |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3819 | * _scsih_scsi_direct_io_get - returns direct io flag |
| 3820 | * @ioc: per adapter object |
| 3821 | * @smid: system request message index |
| 3822 | * |
| 3823 | * Returns the smid stored scmd pointer. |
| 3824 | */ |
| 3825 | static inline u8 |
| 3826 | _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 3827 | { |
| 3828 | return ioc->scsi_lookup[smid - 1].direct_io; |
| 3829 | } |
| 3830 | |
| 3831 | /** |
| 3832 | * _scsih_scsi_direct_io_set - sets direct io flag |
| 3833 | * @ioc: per adapter object |
| 3834 | * @smid: system request message index |
| 3835 | * @direct_io: Zero or non-zero value to set in the direct_io flag |
| 3836 | * |
| 3837 | * Returns Nothing. |
| 3838 | */ |
| 3839 | static inline void |
| 3840 | _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io) |
| 3841 | { |
| 3842 | ioc->scsi_lookup[smid - 1].direct_io = direct_io; |
| 3843 | } |
| 3844 | |
| 3845 | |
| 3846 | /** |
| 3847 | * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O |
| 3848 | * @ioc: per adapter object |
| 3849 | * @scmd: pointer to scsi command object |
| 3850 | * @raid_device: pointer to raid device data structure |
| 3851 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3852 | * @smid: system request message index |
| 3853 | * |
| 3854 | * Returns nothing |
| 3855 | */ |
| 3856 | static void |
| 3857 | _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 3858 | struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request, |
| 3859 | u16 smid) |
| 3860 | { |
| 3861 | u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size; |
| 3862 | u32 stripe_sz, stripe_exp; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3863 | u8 num_pds, *cdb_ptr, i; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3864 | u8 cdb0 = scmd->cmnd[0]; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3865 | u64 v_llba; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3866 | |
| 3867 | /* |
| 3868 | * Try Direct I/O to RAID memeber disks |
| 3869 | */ |
| 3870 | if (cdb0 == READ_16 || cdb0 == READ_10 || |
| 3871 | cdb0 == WRITE_16 || cdb0 == WRITE_10) { |
| 3872 | cdb_ptr = mpi_request->CDB.CDB32; |
| 3873 | |
| 3874 | if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4] |
| 3875 | | cdb_ptr[5])) { |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3876 | io_size = scsi_bufflen(scmd) >> |
| 3877 | raid_device->block_exponent; |
| 3878 | i = (cdb0 < READ_16) ? 2 : 6; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3879 | /* get virtual lba */ |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3880 | v_lba = be32_to_cpu(*(__be32 *)(&cdb_ptr[i])); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3881 | |
| 3882 | if (((u64)v_lba + (u64)io_size - 1) <= |
| 3883 | (u32)raid_device->max_lba) { |
| 3884 | stripe_sz = raid_device->stripe_sz; |
| 3885 | stripe_exp = raid_device->stripe_exponent; |
| 3886 | stripe_off = v_lba & (stripe_sz - 1); |
| 3887 | |
| 3888 | /* Check whether IO falls within a stripe */ |
| 3889 | if ((stripe_off + io_size) <= stripe_sz) { |
| 3890 | num_pds = raid_device->num_pds; |
| 3891 | p_lba = v_lba >> stripe_exp; |
| 3892 | stripe_unit = p_lba / num_pds; |
| 3893 | column = p_lba % num_pds; |
| 3894 | p_lba = (stripe_unit << stripe_exp) + |
| 3895 | stripe_off; |
| 3896 | mpi_request->DevHandle = |
| 3897 | cpu_to_le16(raid_device-> |
| 3898 | pd_handle[column]); |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3899 | (*(__be32 *)(&cdb_ptr[i])) = |
| 3900 | cpu_to_be32(p_lba); |
| 3901 | /* |
| 3902 | * WD: To indicate this I/O is directI/O |
| 3903 | */ |
| 3904 | _scsih_scsi_direct_io_set(ioc, smid, 1); |
| 3905 | } |
| 3906 | } |
| 3907 | } else { |
| 3908 | io_size = scsi_bufflen(scmd) >> |
| 3909 | raid_device->block_exponent; |
| 3910 | /* get virtual lba */ |
| 3911 | v_llba = be64_to_cpu(*(__be64 *)(&cdb_ptr[2])); |
| 3912 | |
| 3913 | if ((v_llba + (u64)io_size - 1) <= |
| 3914 | raid_device->max_lba) { |
| 3915 | stripe_sz = raid_device->stripe_sz; |
| 3916 | stripe_exp = raid_device->stripe_exponent; |
| 3917 | stripe_off = (u32) (v_llba & (stripe_sz - 1)); |
| 3918 | |
| 3919 | /* Check whether IO falls within a stripe */ |
| 3920 | if ((stripe_off + io_size) <= stripe_sz) { |
| 3921 | num_pds = raid_device->num_pds; |
| 3922 | p_lba = (u32)(v_llba >> stripe_exp); |
| 3923 | stripe_unit = p_lba / num_pds; |
| 3924 | column = p_lba % num_pds; |
| 3925 | p_lba = (stripe_unit << stripe_exp) + |
| 3926 | stripe_off; |
| 3927 | mpi_request->DevHandle = |
| 3928 | cpu_to_le16(raid_device-> |
| 3929 | pd_handle[column]); |
| 3930 | (*(__be64 *)(&cdb_ptr[2])) = |
| 3931 | cpu_to_be64((u64)p_lba); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3932 | /* |
| 3933 | * WD: To indicate this I/O is directI/O |
| 3934 | */ |
| 3935 | _scsih_scsi_direct_io_set(ioc, smid, 1); |
| 3936 | } |
| 3937 | } |
| 3938 | } |
| 3939 | } |
| 3940 | } |
| 3941 | |
| 3942 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 3943 | * _scsih_qcmd - main scsi request entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3944 | * @scmd: pointer to scsi command object |
| 3945 | * @done: function pointer to be invoked on completion |
| 3946 | * |
| 3947 | * The callback index is set inside `ioc->scsi_io_cb_idx`. |
| 3948 | * |
| 3949 | * Returns 0 on success. If there's a failure, return either: |
| 3950 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or |
| 3951 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full |
| 3952 | */ |
| 3953 | static int |
Matthew Wilcox | 90f951e | 2014-03-27 16:40:33 -0400 | [diff] [blame] | 3954 | _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3955 | { |
Matthew Wilcox | 90f951e | 2014-03-27 16:40:33 -0400 | [diff] [blame] | 3956 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3957 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 3958 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3959 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3960 | Mpi2SCSIIORequest_t *mpi_request; |
| 3961 | u32 mpi_control; |
| 3962 | u16 smid; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3963 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3964 | sas_device_priv_data = scmd->device->hostdata; |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3965 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3966 | scmd->result = DID_NO_CONNECT << 16; |
| 3967 | scmd->scsi_done(scmd); |
| 3968 | return 0; |
| 3969 | } |
| 3970 | |
Kashyap, Desai | 7821578 | 2011-06-14 10:57:08 +0530 | [diff] [blame] | 3971 | if (ioc->pci_error_recovery || ioc->remove_host) { |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3972 | scmd->result = DID_NO_CONNECT << 16; |
| 3973 | scmd->scsi_done(scmd); |
| 3974 | return 0; |
| 3975 | } |
| 3976 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3977 | sas_target_priv_data = sas_device_priv_data->sas_target; |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3978 | /* invalid device handle */ |
| 3979 | if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3980 | scmd->result = DID_NO_CONNECT << 16; |
| 3981 | scmd->scsi_done(scmd); |
| 3982 | return 0; |
| 3983 | } |
| 3984 | |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3985 | /* host recovery or link resets sent via IOCTLs */ |
| 3986 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3987 | return SCSI_MLQUEUE_HOST_BUSY; |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 3988 | /* device busy with task management */ |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3989 | else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy) |
| 3990 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 3991 | /* device has been deleted */ |
| 3992 | else if (sas_target_priv_data->deleted) { |
| 3993 | scmd->result = DID_NO_CONNECT << 16; |
| 3994 | scmd->scsi_done(scmd); |
| 3995 | return 0; |
| 3996 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3997 | |
| 3998 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) |
| 3999 | mpi_control = MPI2_SCSIIO_CONTROL_READ; |
| 4000 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 4001 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; |
| 4002 | else |
| 4003 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; |
| 4004 | |
| 4005 | /* set tags */ |
| 4006 | if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) { |
| 4007 | if (scmd->device->tagged_supported) { |
| 4008 | if (scmd->device->ordered_tags) |
| 4009 | mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ; |
| 4010 | else |
| 4011 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
| 4012 | } else |
Sreekanth Reddy | 48ba2ef | 2013-02-02 00:58:20 +0530 | [diff] [blame] | 4013 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4014 | } else |
| 4015 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4016 | /* Make sure Device is not raid volume. |
| 4017 | * We do not expose raid functionality to upper layer for warpdrive. |
| 4018 | */ |
| 4019 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 4020 | sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4021 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
| 4022 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 4023 | 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] | 4024 | if (!smid) { |
| 4025 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 4026 | ioc->name, __func__); |
| 4027 | goto out; |
| 4028 | } |
| 4029 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 4030 | memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t)); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4031 | _scsih_setup_eedp(scmd, mpi_request); |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 4032 | if (scmd->cmd_len == 32) |
| 4033 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4034 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 4035 | if (sas_device_priv_data->sas_target->flags & |
| 4036 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 4037 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; |
| 4038 | else |
Matthew Wilcox | 90f951e | 2014-03-27 16:40:33 -0400 | [diff] [blame] | 4039 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4040 | mpi_request->DevHandle = |
| 4041 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 4042 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
| 4043 | mpi_request->Control = cpu_to_le32(mpi_control); |
| 4044 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); |
| 4045 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; |
| 4046 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; |
| 4047 | mpi_request->SenseBufferLowAddress = |
Kashyap, Desai | ec9472c | 2009-09-23 17:34:13 +0530 | [diff] [blame] | 4048 | mpt2sas_base_get_sense_buffer_dma(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4049 | mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4; |
| 4050 | mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI + |
| 4051 | MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4052 | mpi_request->VF_ID = 0; /* TODO */ |
| 4053 | mpi_request->VP_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4054 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
| 4055 | mpi_request->LUN); |
| 4056 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 4057 | |
| 4058 | if (!mpi_request->DataLength) { |
| 4059 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL); |
| 4060 | } else { |
| 4061 | if (_scsih_build_scatter_gather(ioc, scmd, smid)) { |
| 4062 | mpt2sas_base_free_smid(ioc, smid); |
| 4063 | goto out; |
| 4064 | } |
| 4065 | } |
| 4066 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4067 | raid_device = sas_target_priv_data->raid_device; |
| 4068 | if (raid_device && raid_device->direct_io_enabled) |
| 4069 | _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request, |
| 4070 | smid); |
| 4071 | |
Kashyap, Desai | 58287fd | 2010-03-17 16:27:25 +0530 | [diff] [blame] | 4072 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) |
| 4073 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4074 | le16_to_cpu(mpi_request->DevHandle)); |
Kashyap, Desai | 58287fd | 2010-03-17 16:27:25 +0530 | [diff] [blame] | 4075 | else |
| 4076 | mpt2sas_base_put_smid_default(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4077 | return 0; |
| 4078 | |
| 4079 | out: |
| 4080 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4081 | } |
| 4082 | |
| 4083 | /** |
| 4084 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data |
| 4085 | * @sense_buffer: sense data returned by target |
| 4086 | * @data: normalized skey/asc/ascq |
| 4087 | * |
| 4088 | * Return nothing. |
| 4089 | */ |
| 4090 | static void |
| 4091 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) |
| 4092 | { |
| 4093 | if ((sense_buffer[0] & 0x7F) >= 0x72) { |
| 4094 | /* descriptor format */ |
| 4095 | data->skey = sense_buffer[1] & 0x0F; |
| 4096 | data->asc = sense_buffer[2]; |
| 4097 | data->ascq = sense_buffer[3]; |
| 4098 | } else { |
| 4099 | /* fixed format */ |
| 4100 | data->skey = sense_buffer[2] & 0x0F; |
| 4101 | data->asc = sense_buffer[12]; |
| 4102 | data->ascq = sense_buffer[13]; |
| 4103 | } |
| 4104 | } |
| 4105 | |
| 4106 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4107 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4108 | * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4109 | * @ioc: per adapter object |
| 4110 | * @scmd: pointer to scsi command object |
| 4111 | * @mpi_reply: reply mf payload returned from firmware |
| 4112 | * |
| 4113 | * scsi_status - SCSI Status code returned from target device |
| 4114 | * scsi_state - state info associated with SCSI_IO determined by ioc |
| 4115 | * ioc_status - ioc supplied status info |
| 4116 | * |
| 4117 | * Return nothing. |
| 4118 | */ |
| 4119 | static void |
| 4120 | _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 4121 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) |
| 4122 | { |
| 4123 | u32 response_info; |
| 4124 | u8 *response_bytes; |
| 4125 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & |
| 4126 | MPI2_IOCSTATUS_MASK; |
| 4127 | u8 scsi_state = mpi_reply->SCSIState; |
| 4128 | u8 scsi_status = mpi_reply->SCSIStatus; |
| 4129 | char *desc_ioc_state = NULL; |
| 4130 | char *desc_scsi_status = NULL; |
| 4131 | char *desc_scsi_state = ioc->tmp_string; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4132 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4133 | struct _sas_device *sas_device = NULL; |
| 4134 | unsigned long flags; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4135 | struct scsi_target *starget = scmd->device->sdev_target; |
| 4136 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4137 | char *device_str = NULL; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4138 | |
| 4139 | if (!priv_target) |
| 4140 | return; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4141 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4142 | if (ioc->hide_ir_msg) |
| 4143 | device_str = "WarpDrive"; |
| 4144 | else |
| 4145 | device_str = "volume"; |
| 4146 | |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4147 | if (log_info == 0x31170000) |
| 4148 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4149 | |
| 4150 | switch (ioc_status) { |
| 4151 | case MPI2_IOCSTATUS_SUCCESS: |
| 4152 | desc_ioc_state = "success"; |
| 4153 | break; |
| 4154 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 4155 | desc_ioc_state = "invalid function"; |
| 4156 | break; |
| 4157 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 4158 | desc_ioc_state = "scsi recovered error"; |
| 4159 | break; |
| 4160 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: |
| 4161 | desc_ioc_state = "scsi invalid dev handle"; |
| 4162 | break; |
| 4163 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 4164 | desc_ioc_state = "scsi device not there"; |
| 4165 | break; |
| 4166 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 4167 | desc_ioc_state = "scsi data overrun"; |
| 4168 | break; |
| 4169 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 4170 | desc_ioc_state = "scsi data underrun"; |
| 4171 | break; |
| 4172 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 4173 | desc_ioc_state = "scsi io data error"; |
| 4174 | break; |
| 4175 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 4176 | desc_ioc_state = "scsi protocol error"; |
| 4177 | break; |
| 4178 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 4179 | desc_ioc_state = "scsi task terminated"; |
| 4180 | break; |
| 4181 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 4182 | desc_ioc_state = "scsi residual mismatch"; |
| 4183 | break; |
| 4184 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 4185 | desc_ioc_state = "scsi task mgmt failed"; |
| 4186 | break; |
| 4187 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 4188 | desc_ioc_state = "scsi ioc terminated"; |
| 4189 | break; |
| 4190 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 4191 | desc_ioc_state = "scsi ext terminated"; |
| 4192 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4193 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 4194 | desc_ioc_state = "eedp guard error"; |
| 4195 | break; |
| 4196 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 4197 | desc_ioc_state = "eedp ref tag error"; |
| 4198 | break; |
| 4199 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 4200 | desc_ioc_state = "eedp app tag error"; |
| 4201 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4202 | default: |
| 4203 | desc_ioc_state = "unknown"; |
| 4204 | break; |
| 4205 | } |
| 4206 | |
| 4207 | switch (scsi_status) { |
| 4208 | case MPI2_SCSI_STATUS_GOOD: |
| 4209 | desc_scsi_status = "good"; |
| 4210 | break; |
| 4211 | case MPI2_SCSI_STATUS_CHECK_CONDITION: |
| 4212 | desc_scsi_status = "check condition"; |
| 4213 | break; |
| 4214 | case MPI2_SCSI_STATUS_CONDITION_MET: |
| 4215 | desc_scsi_status = "condition met"; |
| 4216 | break; |
| 4217 | case MPI2_SCSI_STATUS_BUSY: |
| 4218 | desc_scsi_status = "busy"; |
| 4219 | break; |
| 4220 | case MPI2_SCSI_STATUS_INTERMEDIATE: |
| 4221 | desc_scsi_status = "intermediate"; |
| 4222 | break; |
| 4223 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: |
| 4224 | desc_scsi_status = "intermediate condmet"; |
| 4225 | break; |
| 4226 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: |
| 4227 | desc_scsi_status = "reservation conflict"; |
| 4228 | break; |
| 4229 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: |
| 4230 | desc_scsi_status = "command terminated"; |
| 4231 | break; |
| 4232 | case MPI2_SCSI_STATUS_TASK_SET_FULL: |
| 4233 | desc_scsi_status = "task set full"; |
| 4234 | break; |
| 4235 | case MPI2_SCSI_STATUS_ACA_ACTIVE: |
| 4236 | desc_scsi_status = "aca active"; |
| 4237 | break; |
| 4238 | case MPI2_SCSI_STATUS_TASK_ABORTED: |
| 4239 | desc_scsi_status = "task aborted"; |
| 4240 | break; |
| 4241 | default: |
| 4242 | desc_scsi_status = "unknown"; |
| 4243 | break; |
| 4244 | } |
| 4245 | |
| 4246 | desc_scsi_state[0] = '\0'; |
| 4247 | if (!scsi_state) |
| 4248 | desc_scsi_state = " "; |
| 4249 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 4250 | strcat(desc_scsi_state, "response info "); |
| 4251 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4252 | strcat(desc_scsi_state, "state terminated "); |
| 4253 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) |
| 4254 | strcat(desc_scsi_state, "no status "); |
| 4255 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) |
| 4256 | strcat(desc_scsi_state, "autosense failed "); |
| 4257 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) |
| 4258 | strcat(desc_scsi_state, "autosense valid "); |
| 4259 | |
| 4260 | scsi_print_command(scmd); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4261 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4262 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4263 | printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name, |
| 4264 | device_str, (unsigned long long)priv_target->sas_address); |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4265 | } else { |
| 4266 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4267 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 4268 | priv_target->sas_address); |
| 4269 | if (sas_device) { |
| 4270 | printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), " |
| 4271 | "phy(%d)\n", ioc->name, sas_device->sas_address, |
| 4272 | sas_device->phy); |
| 4273 | printk(MPT2SAS_WARN_FMT |
| 4274 | "\tenclosure_logical_id(0x%016llx), slot(%d)\n", |
| 4275 | ioc->name, sas_device->enclosure_logical_id, |
| 4276 | sas_device->slot); |
| 4277 | } |
| 4278 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4279 | } |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4280 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4281 | printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), " |
| 4282 | "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle), |
| 4283 | desc_ioc_state, ioc_status, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4284 | printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), " |
| 4285 | "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow, |
| 4286 | scsi_get_resid(scmd)); |
| 4287 | printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), " |
| 4288 | "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag), |
| 4289 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); |
| 4290 | printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), " |
| 4291 | "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status, |
| 4292 | scsi_status, desc_scsi_state, scsi_state); |
| 4293 | |
| 4294 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4295 | struct sense_info data; |
| 4296 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4297 | printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: " |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 4298 | "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey, |
| 4299 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4300 | } |
| 4301 | |
| 4302 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { |
| 4303 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); |
| 4304 | response_bytes = (u8 *)&response_info; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4305 | _scsih_response_code(ioc, response_bytes[0]); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4306 | } |
| 4307 | } |
| 4308 | #endif |
| 4309 | |
| 4310 | /** |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4311 | * _scsih_turn_on_fault_led - illuminate Fault LED |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4312 | * @ioc: per adapter object |
| 4313 | * @handle: device handle |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4314 | * Context: process |
| 4315 | * |
| 4316 | * Return nothing. |
| 4317 | */ |
| 4318 | static void |
| 4319 | _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4320 | { |
| 4321 | Mpi2SepReply_t mpi_reply; |
| 4322 | Mpi2SepRequest_t mpi_request; |
| 4323 | |
| 4324 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
| 4325 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; |
| 4326 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; |
| 4327 | mpi_request.SlotStatus = |
| 4328 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); |
| 4329 | mpi_request.DevHandle = cpu_to_le16(handle); |
| 4330 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; |
| 4331 | if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply, |
| 4332 | &mpi_request)) != 0) { |
| 4333 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 4334 | __FILE__, __LINE__, __func__); |
| 4335 | return; |
| 4336 | } |
| 4337 | |
| 4338 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { |
| 4339 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: " |
| 4340 | "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name, |
| 4341 | le16_to_cpu(mpi_reply.IOCStatus), |
| 4342 | le32_to_cpu(mpi_reply.IOCLogInfo))); |
| 4343 | return; |
| 4344 | } |
| 4345 | } |
| 4346 | |
| 4347 | /** |
| 4348 | * _scsih_send_event_to_turn_on_fault_led - fire delayed event |
| 4349 | * @ioc: per adapter object |
| 4350 | * @handle: device handle |
| 4351 | * Context: interrupt. |
| 4352 | * |
| 4353 | * Return nothing. |
| 4354 | */ |
| 4355 | static void |
| 4356 | _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4357 | { |
| 4358 | struct fw_event_work *fw_event; |
| 4359 | |
| 4360 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 4361 | if (!fw_event) |
| 4362 | return; |
| 4363 | fw_event->event = MPT2SAS_TURN_ON_FAULT_LED; |
| 4364 | fw_event->device_handle = handle; |
| 4365 | fw_event->ioc = ioc; |
| 4366 | _scsih_fw_event_add(ioc, fw_event); |
| 4367 | } |
| 4368 | |
| 4369 | /** |
| 4370 | * _scsih_smart_predicted_fault - process smart errors |
| 4371 | * @ioc: per adapter object |
| 4372 | * @handle: device handle |
| 4373 | * Context: interrupt. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4374 | * |
| 4375 | * Return nothing. |
| 4376 | */ |
| 4377 | static void |
| 4378 | _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4379 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4380 | struct scsi_target *starget; |
| 4381 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 4382 | Mpi2EventNotificationReply_t *event_reply; |
| 4383 | Mpi2EventDataSasDeviceStatusChange_t *event_data; |
| 4384 | struct _sas_device *sas_device; |
| 4385 | ssize_t sz; |
| 4386 | unsigned long flags; |
| 4387 | |
| 4388 | /* only handle non-raid devices */ |
| 4389 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4390 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 4391 | if (!sas_device) { |
| 4392 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4393 | return; |
| 4394 | } |
| 4395 | starget = sas_device->starget; |
| 4396 | sas_target_priv_data = starget->hostdata; |
| 4397 | |
| 4398 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || |
| 4399 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) { |
| 4400 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4401 | return; |
| 4402 | } |
| 4403 | starget_printk(KERN_WARNING, starget, "predicted fault\n"); |
| 4404 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4405 | |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4406 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) |
| 4407 | _scsih_send_event_to_turn_on_fault_led(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4408 | |
| 4409 | /* insert into event log */ |
| 4410 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + |
| 4411 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); |
Anton Blanchard | f6a290b4 | 2011-11-07 22:05:21 +1100 | [diff] [blame] | 4412 | event_reply = kzalloc(sz, GFP_ATOMIC); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4413 | if (!event_reply) { |
| 4414 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4415 | ioc->name, __FILE__, __LINE__, __func__); |
| 4416 | return; |
| 4417 | } |
| 4418 | |
| 4419 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; |
| 4420 | event_reply->Event = |
| 4421 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); |
| 4422 | event_reply->MsgLength = sz/4; |
| 4423 | event_reply->EventDataLength = |
| 4424 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); |
| 4425 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) |
| 4426 | event_reply->EventData; |
| 4427 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; |
| 4428 | event_data->ASC = 0x5D; |
| 4429 | event_data->DevHandle = cpu_to_le16(handle); |
| 4430 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); |
| 4431 | mpt2sas_ctl_add_to_event_log(ioc, event_reply); |
| 4432 | kfree(event_reply); |
| 4433 | } |
| 4434 | |
| 4435 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 4436 | * _scsih_io_done - scsi request callback |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4437 | * @ioc: per adapter object |
| 4438 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4439 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4440 | * @reply: reply message frame(lower 32bit addr) |
| 4441 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4442 | * Callback handler when using _scsih_qcmd. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4443 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4444 | * Return 1 meaning mf should be freed from _base_interrupt |
| 4445 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4446 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4447 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4448 | _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] | 4449 | { |
| 4450 | Mpi2SCSIIORequest_t *mpi_request; |
| 4451 | Mpi2SCSIIOReply_t *mpi_reply; |
| 4452 | struct scsi_cmnd *scmd; |
| 4453 | u16 ioc_status; |
| 4454 | u32 xfer_cnt; |
| 4455 | u8 scsi_state; |
| 4456 | u8 scsi_status; |
| 4457 | u32 log_info; |
| 4458 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4459 | u32 response_code = 0; |
Kashyap, Desai | 82a4525 | 2011-07-05 12:40:23 +0530 | [diff] [blame] | 4460 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4461 | |
| 4462 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 4463 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4464 | if (scmd == NULL) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4465 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4466 | |
| 4467 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 4468 | |
| 4469 | if (mpi_reply == NULL) { |
| 4470 | scmd->result = DID_OK << 16; |
| 4471 | goto out; |
| 4472 | } |
| 4473 | |
| 4474 | sas_device_priv_data = scmd->device->hostdata; |
| 4475 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
| 4476 | sas_device_priv_data->sas_target->deleted) { |
| 4477 | scmd->result = DID_NO_CONNECT << 16; |
| 4478 | goto out; |
| 4479 | } |
nagalakshmi.nandigama@lsi.com | 4da7af9 | 2011-12-01 07:53:02 +0530 | [diff] [blame] | 4480 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4481 | /* |
| 4482 | * WARPDRIVE: If direct_io is set then it is directIO, |
| 4483 | * the failed direct I/O should be redirected to volume |
| 4484 | */ |
nagalakshmi.nandigama@lsi.com | 4da7af9 | 2011-12-01 07:53:02 +0530 | [diff] [blame] | 4485 | if (_scsih_scsi_direct_io_get(ioc, smid) && |
| 4486 | ((ioc_status & MPI2_IOCSTATUS_MASK) |
| 4487 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { |
Kashyap, Desai | 82a4525 | 2011-07-05 12:40:23 +0530 | [diff] [blame] | 4488 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 4489 | ioc->scsi_lookup[smid - 1].scmd = scmd; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4490 | _scsih_scsi_direct_io_set(ioc, smid, 0); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 4491 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4492 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 4493 | mpi_request->DevHandle = |
| 4494 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 4495 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
| 4496 | sas_device_priv_data->sas_target->handle); |
| 4497 | return 0; |
| 4498 | } |
| 4499 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4500 | |
| 4501 | /* turning off TLR */ |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4502 | scsi_state = mpi_reply->SCSIState; |
| 4503 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 4504 | response_code = |
| 4505 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4506 | if (!sas_device_priv_data->tlr_snoop_check) { |
| 4507 | sas_device_priv_data->tlr_snoop_check++; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4508 | /* Make sure Device is not raid volume. |
| 4509 | * We do not expose raid functionality to upper layer for warpdrive. |
| 4510 | */ |
| 4511 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && |
Kashyap, Desai | 3ed2152 | 2010-02-17 16:08:36 +0530 | [diff] [blame] | 4512 | sas_is_tlr_enabled(scmd->device) && |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 4513 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { |
| 4514 | sas_disable_tlr(scmd->device); |
| 4515 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); |
| 4516 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); |
| 4520 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4521 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) |
| 4522 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
| 4523 | else |
| 4524 | log_info = 0; |
| 4525 | ioc_status &= MPI2_IOCSTATUS_MASK; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4526 | scsi_status = mpi_reply->SCSIStatus; |
| 4527 | |
| 4528 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && |
| 4529 | (scsi_status == MPI2_SCSI_STATUS_BUSY || |
| 4530 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || |
| 4531 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { |
| 4532 | ioc_status = MPI2_IOCSTATUS_SUCCESS; |
| 4533 | } |
| 4534 | |
| 4535 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4536 | struct sense_info data; |
| 4537 | const void *sense_data = mpt2sas_base_get_sense_buffer(ioc, |
| 4538 | smid); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 4539 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4540 | le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 4541 | memcpy(scmd->sense_buffer, sense_data, sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4542 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4543 | /* failure prediction threshold exceeded */ |
| 4544 | if (data.asc == 0x5D) |
| 4545 | _scsih_smart_predicted_fault(ioc, |
| 4546 | le16_to_cpu(mpi_reply->DevHandle)); |
| 4547 | } |
| 4548 | |
| 4549 | switch (ioc_status) { |
| 4550 | case MPI2_IOCSTATUS_BUSY: |
| 4551 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: |
| 4552 | scmd->result = SAM_STAT_BUSY; |
| 4553 | break; |
| 4554 | |
| 4555 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 4556 | scmd->result = DID_NO_CONNECT << 16; |
| 4557 | break; |
| 4558 | |
| 4559 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 4560 | if (sas_device_priv_data->block) { |
Kashyap, Desai | e4e7c7e | 2009-09-23 17:33:14 +0530 | [diff] [blame] | 4561 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; |
| 4562 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4563 | } |
nagalakshmi.nandigama@lsi.com | 3ade1ca | 2011-12-01 07:42:40 +0530 | [diff] [blame] | 4564 | scmd->result = DID_SOFT_ERROR << 16; |
| 4565 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4566 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 4567 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 4568 | scmd->result = DID_RESET << 16; |
| 4569 | break; |
| 4570 | |
| 4571 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 4572 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) |
| 4573 | scmd->result = DID_SOFT_ERROR << 16; |
| 4574 | else |
| 4575 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4576 | break; |
| 4577 | |
| 4578 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 4579 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4580 | |
| 4581 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) |
| 4582 | break; |
| 4583 | |
| 4584 | if (xfer_cnt < scmd->underflow) { |
| 4585 | if (scsi_status == SAM_STAT_BUSY) |
| 4586 | scmd->result = SAM_STAT_BUSY; |
| 4587 | else |
| 4588 | scmd->result = DID_SOFT_ERROR << 16; |
| 4589 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4590 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) |
| 4591 | scmd->result = DID_SOFT_ERROR << 16; |
| 4592 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4593 | scmd->result = DID_RESET << 16; |
| 4594 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { |
| 4595 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; |
| 4596 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; |
| 4597 | scmd->result = (DRIVER_SENSE << 24) | |
| 4598 | SAM_STAT_CHECK_CONDITION; |
| 4599 | scmd->sense_buffer[0] = 0x70; |
| 4600 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; |
| 4601 | scmd->sense_buffer[12] = 0x20; |
| 4602 | scmd->sense_buffer[13] = 0; |
| 4603 | } |
| 4604 | break; |
| 4605 | |
| 4606 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 4607 | scsi_set_resid(scmd, 0); |
| 4608 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 4609 | case MPI2_IOCSTATUS_SUCCESS: |
| 4610 | scmd->result = (DID_OK << 16) | scsi_status; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4611 | if (response_code == |
| 4612 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || |
| 4613 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4614 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4615 | scmd->result = DID_SOFT_ERROR << 16; |
| 4616 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4617 | scmd->result = DID_RESET << 16; |
| 4618 | break; |
| 4619 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4620 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 4621 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 4622 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 4623 | _scsih_eedp_error_handling(scmd, ioc_status); |
| 4624 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4625 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 4626 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 4627 | case MPI2_IOCSTATUS_INVALID_SGL: |
| 4628 | case MPI2_IOCSTATUS_INTERNAL_ERROR: |
| 4629 | case MPI2_IOCSTATUS_INVALID_FIELD: |
| 4630 | case MPI2_IOCSTATUS_INVALID_STATE: |
| 4631 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 4632 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 4633 | default: |
| 4634 | scmd->result = DID_SOFT_ERROR << 16; |
| 4635 | break; |
| 4636 | |
| 4637 | } |
| 4638 | |
| 4639 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4640 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
| 4641 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); |
| 4642 | #endif |
| 4643 | |
| 4644 | out: |
| 4645 | scsi_dma_unmap(scmd); |
| 4646 | scmd->scsi_done(scmd); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4647 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4648 | } |
| 4649 | |
| 4650 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4651 | * _scsih_sas_host_refresh - refreshing sas host object contents |
| 4652 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4653 | * Context: user |
| 4654 | * |
| 4655 | * During port enable, fw will send topology events for every device. Its |
| 4656 | * possible that the handles may change from the previous setting, so this |
| 4657 | * code keeping handles updating if changed. |
| 4658 | * |
| 4659 | * Return nothing. |
| 4660 | */ |
| 4661 | static void |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4662 | _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4663 | { |
| 4664 | u16 sz; |
| 4665 | u16 ioc_status; |
| 4666 | int i; |
| 4667 | Mpi2ConfigReply_t mpi_reply; |
| 4668 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4669 | u16 attached_handle; |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4670 | u8 link_rate; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4671 | |
| 4672 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 4673 | "updating handles for sas_host(0x%016llx)\n", |
| 4674 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); |
| 4675 | |
| 4676 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys |
| 4677 | * sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4678 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4679 | if (!sas_iounit_pg0) { |
| 4680 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4681 | ioc->name, __FILE__, __LINE__, __func__); |
| 4682 | return; |
| 4683 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4684 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4685 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4686 | sas_iounit_pg0, sz)) != 0) |
| 4687 | goto out; |
| 4688 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 4689 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 4690 | goto out; |
| 4691 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4692 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4693 | if (i == 0) |
| 4694 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4695 | PhyData[0].ControllerDevHandle); |
| 4696 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
| 4697 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. |
| 4698 | AttachedDevHandle); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4699 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 4700 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4701 | mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address, |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4702 | attached_handle, i, link_rate); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4703 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4704 | out: |
| 4705 | kfree(sas_iounit_pg0); |
| 4706 | } |
| 4707 | |
| 4708 | /** |
| 4709 | * _scsih_sas_host_add - create sas host object |
| 4710 | * @ioc: per adapter object |
| 4711 | * |
| 4712 | * Creating host side data object, stored in ioc->sas_hba |
| 4713 | * |
| 4714 | * Return nothing. |
| 4715 | */ |
| 4716 | static void |
| 4717 | _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc) |
| 4718 | { |
| 4719 | int i; |
| 4720 | Mpi2ConfigReply_t mpi_reply; |
| 4721 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
| 4722 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; |
| 4723 | Mpi2SasPhyPage0_t phy_pg0; |
| 4724 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4725 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4726 | u16 ioc_status; |
| 4727 | u16 sz; |
| 4728 | u16 device_missing_delay; |
| 4729 | |
| 4730 | mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys); |
| 4731 | if (!ioc->sas_hba.num_phys) { |
| 4732 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4733 | ioc->name, __FILE__, __LINE__, __func__); |
| 4734 | return; |
| 4735 | } |
| 4736 | |
| 4737 | /* sas_iounit page 0 */ |
| 4738 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4739 | sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4740 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4741 | if (!sas_iounit_pg0) { |
| 4742 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4743 | ioc->name, __FILE__, __LINE__, __func__); |
| 4744 | return; |
| 4745 | } |
| 4746 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4747 | sas_iounit_pg0, sz))) { |
| 4748 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4749 | ioc->name, __FILE__, __LINE__, __func__); |
| 4750 | goto out; |
| 4751 | } |
| 4752 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4753 | MPI2_IOCSTATUS_MASK; |
| 4754 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4755 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4756 | ioc->name, __FILE__, __LINE__, __func__); |
| 4757 | goto out; |
| 4758 | } |
| 4759 | |
| 4760 | /* sas_iounit page 1 */ |
| 4761 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4762 | sizeof(Mpi2SasIOUnit1PhyData_t)); |
| 4763 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); |
| 4764 | if (!sas_iounit_pg1) { |
| 4765 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4766 | ioc->name, __FILE__, __LINE__, __func__); |
| 4767 | goto out; |
| 4768 | } |
| 4769 | if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, |
| 4770 | sas_iounit_pg1, sz))) { |
| 4771 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4772 | ioc->name, __FILE__, __LINE__, __func__); |
| 4773 | goto out; |
| 4774 | } |
| 4775 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4776 | MPI2_IOCSTATUS_MASK; |
| 4777 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4778 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4779 | ioc->name, __FILE__, __LINE__, __func__); |
| 4780 | goto out; |
| 4781 | } |
| 4782 | |
| 4783 | ioc->io_missing_delay = |
| 4784 | le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay); |
| 4785 | device_missing_delay = |
| 4786 | le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay); |
| 4787 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) |
| 4788 | ioc->device_missing_delay = (device_missing_delay & |
| 4789 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; |
| 4790 | else |
| 4791 | ioc->device_missing_delay = device_missing_delay & |
| 4792 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 4793 | |
| 4794 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; |
| 4795 | ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys, |
| 4796 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4797 | if (!ioc->sas_hba.phy) { |
| 4798 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4799 | ioc->name, __FILE__, __LINE__, __func__); |
| 4800 | goto out; |
| 4801 | } |
| 4802 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
| 4803 | if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, |
| 4804 | i))) { |
| 4805 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4806 | ioc->name, __FILE__, __LINE__, __func__); |
| 4807 | goto out; |
| 4808 | } |
| 4809 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4810 | MPI2_IOCSTATUS_MASK; |
| 4811 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4812 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4813 | ioc->name, __FILE__, __LINE__, __func__); |
| 4814 | goto out; |
| 4815 | } |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4816 | |
| 4817 | if (i == 0) |
| 4818 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4819 | PhyData[0].ControllerDevHandle); |
| 4820 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4821 | ioc->sas_hba.phy[i].phy_id = i; |
| 4822 | mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], |
| 4823 | phy_pg0, ioc->sas_hba.parent_dev); |
| 4824 | } |
| 4825 | 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] | 4826 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4827 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4828 | ioc->name, __FILE__, __LINE__, __func__); |
| 4829 | goto out; |
| 4830 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4831 | ioc->sas_hba.enclosure_handle = |
| 4832 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 4833 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 4834 | printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), " |
| 4835 | "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle, |
| 4836 | (unsigned long long) ioc->sas_hba.sas_address, |
| 4837 | ioc->sas_hba.num_phys) ; |
| 4838 | |
| 4839 | if (ioc->sas_hba.enclosure_handle) { |
| 4840 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4841 | &enclosure_pg0, |
| 4842 | MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4843 | ioc->sas_hba.enclosure_handle))) { |
| 4844 | ioc->sas_hba.enclosure_logical_id = |
| 4845 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4846 | } |
| 4847 | } |
| 4848 | |
| 4849 | out: |
| 4850 | kfree(sas_iounit_pg1); |
| 4851 | kfree(sas_iounit_pg0); |
| 4852 | } |
| 4853 | |
| 4854 | /** |
| 4855 | * _scsih_expander_add - creating expander object |
| 4856 | * @ioc: per adapter object |
| 4857 | * @handle: expander handle |
| 4858 | * |
| 4859 | * Creating expander object, stored in ioc->sas_expander_list. |
| 4860 | * |
| 4861 | * Return 0 for success, else error. |
| 4862 | */ |
| 4863 | static int |
| 4864 | _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4865 | { |
| 4866 | struct _sas_node *sas_expander; |
| 4867 | Mpi2ConfigReply_t mpi_reply; |
| 4868 | Mpi2ExpanderPage0_t expander_pg0; |
| 4869 | Mpi2ExpanderPage1_t expander_pg1; |
| 4870 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4871 | u32 ioc_status; |
| 4872 | u16 parent_handle; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 4873 | u64 sas_address, sas_address_parent = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4874 | int i; |
| 4875 | unsigned long flags; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4876 | struct _sas_port *mpt2sas_port = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4877 | int rc = 0; |
| 4878 | |
| 4879 | if (!handle) |
| 4880 | return -1; |
| 4881 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 4882 | if (ioc->shost_recovery || ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 4883 | return -1; |
| 4884 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4885 | if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 4886 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { |
| 4887 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4888 | ioc->name, __FILE__, __LINE__, __func__); |
| 4889 | return -1; |
| 4890 | } |
| 4891 | |
| 4892 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4893 | MPI2_IOCSTATUS_MASK; |
| 4894 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4895 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4896 | ioc->name, __FILE__, __LINE__, __func__); |
| 4897 | return -1; |
| 4898 | } |
| 4899 | |
| 4900 | /* handle out of order topology events */ |
| 4901 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4902 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) |
| 4903 | != 0) { |
| 4904 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4905 | ioc->name, __FILE__, __LINE__, __func__); |
| 4906 | return -1; |
| 4907 | } |
| 4908 | if (sas_address_parent != ioc->sas_hba.sas_address) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4909 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4910 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4911 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4912 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4913 | if (!sas_expander) { |
| 4914 | rc = _scsih_expander_add(ioc, parent_handle); |
| 4915 | if (rc != 0) |
| 4916 | return rc; |
| 4917 | } |
| 4918 | } |
| 4919 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4920 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 4921 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4922 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4923 | sas_address); |
| 4924 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4925 | |
| 4926 | if (sas_expander) |
| 4927 | return 0; |
| 4928 | |
| 4929 | sas_expander = kzalloc(sizeof(struct _sas_node), |
| 4930 | GFP_KERNEL); |
| 4931 | if (!sas_expander) { |
| 4932 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4933 | ioc->name, __FILE__, __LINE__, __func__); |
| 4934 | return -1; |
| 4935 | } |
| 4936 | |
| 4937 | sas_expander->handle = handle; |
| 4938 | sas_expander->num_phys = expander_pg0.NumPhys; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4939 | sas_expander->sas_address_parent = sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4940 | sas_expander->sas_address = sas_address; |
| 4941 | |
| 4942 | printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x)," |
| 4943 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4944 | handle, parent_handle, (unsigned long long) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4945 | sas_expander->sas_address, sas_expander->num_phys); |
| 4946 | |
| 4947 | if (!sas_expander->num_phys) |
| 4948 | goto out_fail; |
| 4949 | sas_expander->phy = kcalloc(sas_expander->num_phys, |
| 4950 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4951 | if (!sas_expander->phy) { |
| 4952 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4953 | ioc->name, __FILE__, __LINE__, __func__); |
| 4954 | rc = -1; |
| 4955 | goto out_fail; |
| 4956 | } |
| 4957 | |
| 4958 | INIT_LIST_HEAD(&sas_expander->sas_port_list); |
| 4959 | mpt2sas_port = mpt2sas_transport_port_add(ioc, handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4960 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4961 | if (!mpt2sas_port) { |
| 4962 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4963 | ioc->name, __FILE__, __LINE__, __func__); |
| 4964 | rc = -1; |
| 4965 | goto out_fail; |
| 4966 | } |
| 4967 | sas_expander->parent_dev = &mpt2sas_port->rphy->dev; |
| 4968 | |
| 4969 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 4970 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 4971 | &expander_pg1, i, handle))) { |
| 4972 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4973 | ioc->name, __FILE__, __LINE__, __func__); |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4974 | rc = -1; |
| 4975 | goto out_fail; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4976 | } |
| 4977 | sas_expander->phy[i].handle = handle; |
| 4978 | sas_expander->phy[i].phy_id = i; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4979 | |
| 4980 | if ((mpt2sas_transport_add_expander_phy(ioc, |
| 4981 | &sas_expander->phy[i], expander_pg1, |
| 4982 | sas_expander->parent_dev))) { |
| 4983 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4984 | ioc->name, __FILE__, __LINE__, __func__); |
| 4985 | rc = -1; |
| 4986 | goto out_fail; |
| 4987 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4988 | } |
| 4989 | |
| 4990 | if (sas_expander->enclosure_handle) { |
| 4991 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4992 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4993 | sas_expander->enclosure_handle))) { |
| 4994 | sas_expander->enclosure_logical_id = |
| 4995 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4996 | } |
| 4997 | } |
| 4998 | |
| 4999 | _scsih_expander_node_add(ioc, sas_expander); |
| 5000 | return 0; |
| 5001 | |
| 5002 | out_fail: |
| 5003 | |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 5004 | if (mpt2sas_port) |
| 5005 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5006 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5007 | kfree(sas_expander); |
| 5008 | return rc; |
| 5009 | } |
| 5010 | |
| 5011 | /** |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 5012 | * _scsih_done - scsih callback handler. |
| 5013 | * @ioc: per adapter object |
| 5014 | * @smid: system request message index |
| 5015 | * @msix_index: MSIX table index supplied by the OS |
| 5016 | * @reply: reply message frame(lower 32bit addr) |
| 5017 | * |
| 5018 | * Callback handler when sending internal generated message frames. |
| 5019 | * The callback index passed is `ioc->scsih_cb_idx` |
| 5020 | * |
| 5021 | * Return 1 meaning mf should be freed from _base_interrupt |
| 5022 | * 0 means the mf is freed from this function. |
| 5023 | */ |
| 5024 | static u8 |
| 5025 | _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) |
| 5026 | { |
| 5027 | MPI2DefaultReply_t *mpi_reply; |
| 5028 | |
| 5029 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 5030 | if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED) |
| 5031 | return 1; |
| 5032 | if (ioc->scsih_cmds.smid != smid) |
| 5033 | return 1; |
| 5034 | ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE; |
| 5035 | if (mpi_reply) { |
| 5036 | memcpy(ioc->scsih_cmds.reply, mpi_reply, |
| 5037 | mpi_reply->MsgLength*4); |
| 5038 | ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 5039 | } |
| 5040 | ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING; |
| 5041 | complete(&ioc->scsih_cmds.done); |
| 5042 | return 1; |
| 5043 | } |
| 5044 | |
| 5045 | /** |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5046 | * mpt2sas_expander_remove - removing expander object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5047 | * @ioc: per adapter object |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5048 | * @sas_address: expander sas_address |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5049 | * |
| 5050 | * Return nothing. |
| 5051 | */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5052 | void |
| 5053 | mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5054 | { |
| 5055 | struct _sas_node *sas_expander; |
| 5056 | unsigned long flags; |
| 5057 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 5058 | if (ioc->shost_recovery) |
| 5059 | return; |
| 5060 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5061 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5062 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 5063 | sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5064 | if (sas_expander) |
| 5065 | list_del(&sas_expander->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5066 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5067 | if (sas_expander) |
| 5068 | _scsih_expander_node_remove(ioc, sas_expander); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | /** |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5072 | * _scsih_check_access_status - check access flags |
| 5073 | * @ioc: per adapter object |
| 5074 | * @sas_address: sas address |
| 5075 | * @handle: sas device handle |
| 5076 | * @access_flags: errors returned during discovery of the device |
| 5077 | * |
| 5078 | * Return 0 for success, else failure |
| 5079 | */ |
| 5080 | static u8 |
| 5081 | _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 5082 | u16 handle, u8 access_status) |
| 5083 | { |
| 5084 | u8 rc = 1; |
| 5085 | char *desc = NULL; |
| 5086 | |
| 5087 | switch (access_status) { |
| 5088 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: |
| 5089 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: |
| 5090 | rc = 0; |
| 5091 | break; |
| 5092 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: |
| 5093 | desc = "sata capability failed"; |
| 5094 | break; |
| 5095 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: |
| 5096 | desc = "sata affiliation conflict"; |
| 5097 | break; |
| 5098 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: |
| 5099 | desc = "route not addressable"; |
| 5100 | break; |
| 5101 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: |
| 5102 | desc = "smp error not addressable"; |
| 5103 | break; |
| 5104 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: |
| 5105 | desc = "device blocked"; |
| 5106 | break; |
| 5107 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: |
| 5108 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: |
| 5109 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: |
| 5110 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: |
| 5111 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: |
| 5112 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: |
| 5113 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: |
| 5114 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: |
| 5115 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: |
| 5116 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: |
| 5117 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: |
| 5118 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: |
| 5119 | desc = "sata initialization failed"; |
| 5120 | break; |
| 5121 | default: |
| 5122 | desc = "unknown"; |
| 5123 | break; |
| 5124 | } |
| 5125 | |
| 5126 | if (!rc) |
| 5127 | return 0; |
| 5128 | |
| 5129 | printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), " |
| 5130 | "handle(0x%04x)\n", ioc->name, desc, |
| 5131 | (unsigned long long)sas_address, handle); |
| 5132 | return rc; |
| 5133 | } |
| 5134 | |
| 5135 | static void |
| 5136 | _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 5137 | { |
| 5138 | Mpi2ConfigReply_t mpi_reply; |
| 5139 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 5140 | struct _sas_device *sas_device; |
| 5141 | u32 ioc_status; |
| 5142 | unsigned long flags; |
| 5143 | u64 sas_address; |
| 5144 | struct scsi_target *starget; |
| 5145 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 5146 | u32 device_info; |
| 5147 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5148 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5149 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 5150 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) |
| 5151 | return; |
| 5152 | |
| 5153 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 5154 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 5155 | return; |
| 5156 | |
| 5157 | /* check if this is end device */ |
| 5158 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 5159 | if (!(_scsih_is_end_device(device_info))) |
| 5160 | return; |
| 5161 | |
| 5162 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5163 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 5164 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5165 | sas_address); |
| 5166 | |
| 5167 | if (!sas_device) { |
| 5168 | printk(MPT2SAS_ERR_FMT "device is not present " |
| 5169 | "handle(0x%04x), no sas_device!!!\n", ioc->name, handle); |
| 5170 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5171 | return; |
| 5172 | } |
| 5173 | |
| 5174 | if (unlikely(sas_device->handle != handle)) { |
| 5175 | starget = sas_device->starget; |
| 5176 | sas_target_priv_data = starget->hostdata; |
| 5177 | starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)" |
| 5178 | " to (0x%04x)!!!\n", sas_device->handle, handle); |
| 5179 | sas_target_priv_data->handle = handle; |
| 5180 | sas_device->handle = handle; |
| 5181 | } |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5182 | |
| 5183 | /* check if device is present */ |
| 5184 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 5185 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 5186 | printk(MPT2SAS_ERR_FMT "device is not present " |
| 5187 | "handle(0x%04x), flags!!!\n", ioc->name, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5188 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5189 | return; |
| 5190 | } |
| 5191 | |
| 5192 | /* check if there were any issues with discovery */ |
| 5193 | if (_scsih_check_access_status(ioc, sas_address, handle, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5194 | sas_device_pg0.AccessStatus)) { |
| 5195 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5196 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5197 | } |
| 5198 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 5199 | _scsih_ublock_io_device(ioc, sas_address); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5200 | |
| 5201 | } |
| 5202 | |
| 5203 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5204 | * _scsih_add_device - creating sas device object |
| 5205 | * @ioc: per adapter object |
| 5206 | * @handle: sas device handle |
| 5207 | * @phy_num: phy number end device attached to |
| 5208 | * @is_pd: is this hidden raid component |
| 5209 | * |
| 5210 | * Creating end device object, stored in ioc->sas_device_list. |
| 5211 | * |
| 5212 | * Returns 0 for success, non-zero for failure. |
| 5213 | */ |
| 5214 | static int |
| 5215 | _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd) |
| 5216 | { |
| 5217 | Mpi2ConfigReply_t mpi_reply; |
| 5218 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 5219 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 5220 | struct _sas_device *sas_device; |
| 5221 | u32 ioc_status; |
| 5222 | __le64 sas_address; |
| 5223 | u32 device_info; |
| 5224 | unsigned long flags; |
| 5225 | |
| 5226 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 5227 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 5228 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5229 | ioc->name, __FILE__, __LINE__, __func__); |
| 5230 | return -1; |
| 5231 | } |
| 5232 | |
| 5233 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 5234 | MPI2_IOCSTATUS_MASK; |
| 5235 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5236 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5237 | ioc->name, __FILE__, __LINE__, __func__); |
| 5238 | return -1; |
| 5239 | } |
| 5240 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5241 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 5242 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5243 | /* check if device is present */ |
| 5244 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 5245 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 5246 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5247 | ioc->name, __FILE__, __LINE__, __func__); |
| 5248 | printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n", |
| 5249 | ioc->name, le16_to_cpu(sas_device_pg0.Flags)); |
| 5250 | return -1; |
| 5251 | } |
| 5252 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5253 | /* check if there were any issues with discovery */ |
| 5254 | if (_scsih_check_access_status(ioc, sas_address, handle, |
| 5255 | sas_device_pg0.AccessStatus)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5256 | return -1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5257 | |
| 5258 | /* check if this is end device */ |
| 5259 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 5260 | if (!(_scsih_is_end_device(device_info))) { |
| 5261 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5262 | ioc->name, __FILE__, __LINE__, __func__); |
| 5263 | return -1; |
| 5264 | } |
| 5265 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5266 | |
| 5267 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5268 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5269 | sas_address); |
| 5270 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5271 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5272 | if (sas_device) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5273 | return 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5274 | |
| 5275 | sas_device = kzalloc(sizeof(struct _sas_device), |
| 5276 | GFP_KERNEL); |
| 5277 | if (!sas_device) { |
| 5278 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5279 | ioc->name, __FILE__, __LINE__, __func__); |
| 5280 | return -1; |
| 5281 | } |
| 5282 | |
| 5283 | sas_device->handle = handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5284 | if (_scsih_get_sas_address(ioc, le16_to_cpu |
| 5285 | (sas_device_pg0.ParentDevHandle), |
| 5286 | &sas_device->sas_address_parent) != 0) |
| 5287 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5288 | ioc->name, __FILE__, __LINE__, __func__); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5289 | sas_device->enclosure_handle = |
| 5290 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 5291 | sas_device->slot = |
| 5292 | le16_to_cpu(sas_device_pg0.Slot); |
| 5293 | sas_device->device_info = device_info; |
| 5294 | sas_device->sas_address = sas_address; |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 5295 | sas_device->phy = sas_device_pg0.PhyNum; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5296 | |
| 5297 | /* get enclosure_logical_id */ |
Kashyap, Desai | 15052c9 | 2009-08-07 19:33:17 +0530 | [diff] [blame] | 5298 | if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0( |
| 5299 | ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 5300 | sas_device->enclosure_handle))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5301 | sas_device->enclosure_logical_id = |
| 5302 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5303 | |
| 5304 | /* get device name */ |
| 5305 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); |
| 5306 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5307 | if (ioc->wait_for_discovery_to_complete) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5308 | _scsih_sas_device_init_add(ioc, sas_device); |
| 5309 | else |
| 5310 | _scsih_sas_device_add(ioc, sas_device); |
| 5311 | |
| 5312 | return 0; |
| 5313 | } |
| 5314 | |
| 5315 | /** |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5316 | * _scsih_remove_device - removing sas device object |
| 5317 | * @ioc: per adapter object |
| 5318 | * @sas_device_delete: the sas_device object |
| 5319 | * |
| 5320 | * Return nothing. |
| 5321 | */ |
| 5322 | static void |
| 5323 | _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, |
| 5324 | struct _sas_device *sas_device) |
| 5325 | { |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5326 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 5327 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5328 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: " |
| 5329 | "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] | 5330 | sas_device->handle, (unsigned long long) |
| 5331 | sas_device->sas_address)); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5332 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5333 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 5334 | sas_target_priv_data = sas_device->starget->hostdata; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5335 | sas_target_priv_data->deleted = 1; |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 5336 | _scsih_ublock_io_device(ioc, sas_device->sas_address); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5337 | sas_target_priv_data->handle = |
| 5338 | MPT2SAS_INVALID_DEVICE_HANDLE; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5339 | } |
| 5340 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 5341 | if (!ioc->hide_drives) |
| 5342 | mpt2sas_transport_port_remove(ioc, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5343 | sas_device->sas_address, |
| 5344 | sas_device->sas_address_parent); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5345 | |
| 5346 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr" |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5347 | "(0x%016llx)\n", ioc->name, sas_device->handle, |
| 5348 | (unsigned long long) sas_device->sas_address); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5349 | |
| 5350 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: " |
| 5351 | "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] | 5352 | sas_device->handle, (unsigned long long) |
| 5353 | sas_device->sas_address)); |
| 5354 | kfree(sas_device); |
| 5355 | } |
| 5356 | /** |
| 5357 | * _scsih_device_remove_by_handle - removing device object by handle |
| 5358 | * @ioc: per adapter object |
| 5359 | * @handle: device handle |
| 5360 | * |
| 5361 | * Return nothing. |
| 5362 | */ |
| 5363 | static void |
| 5364 | _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 5365 | { |
| 5366 | struct _sas_device *sas_device; |
| 5367 | unsigned long flags; |
| 5368 | |
| 5369 | if (ioc->shost_recovery) |
| 5370 | return; |
| 5371 | |
| 5372 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5373 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 5374 | if (sas_device) |
| 5375 | list_del(&sas_device->list); |
| 5376 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5377 | if (sas_device) |
| 5378 | _scsih_remove_device(ioc, sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5379 | } |
| 5380 | |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5381 | /** |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5382 | * mpt2sas_device_remove_by_sas_address - removing device object by sas address |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5383 | * @ioc: per adapter object |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5384 | * @sas_address: device sas_address |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5385 | * |
| 5386 | * Return nothing. |
| 5387 | */ |
| 5388 | void |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5389 | mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 5390 | u64 sas_address) |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5391 | { |
| 5392 | struct _sas_device *sas_device; |
| 5393 | unsigned long flags; |
| 5394 | |
| 5395 | if (ioc->shost_recovery) |
| 5396 | return; |
| 5397 | |
| 5398 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5399 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5400 | sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5401 | if (sas_device) |
| 5402 | list_del(&sas_device->list); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5403 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5404 | if (sas_device) |
| 5405 | _scsih_remove_device(ioc, sas_device); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5406 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5407 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5408 | /** |
| 5409 | * _scsih_sas_topology_change_event_debug - debug for topology event |
| 5410 | * @ioc: per adapter object |
| 5411 | * @event_data: event data payload |
| 5412 | * Context: user. |
| 5413 | */ |
| 5414 | static void |
| 5415 | _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5416 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 5417 | { |
| 5418 | int i; |
| 5419 | u16 handle; |
| 5420 | u16 reason_code; |
| 5421 | u8 phy_number; |
| 5422 | char *status_str = NULL; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5423 | u8 link_rate, prev_link_rate; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5424 | |
| 5425 | switch (event_data->ExpStatus) { |
| 5426 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: |
| 5427 | status_str = "add"; |
| 5428 | break; |
| 5429 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: |
| 5430 | status_str = "remove"; |
| 5431 | break; |
| 5432 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5433 | case 0: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5434 | status_str = "responding"; |
| 5435 | break; |
| 5436 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: |
| 5437 | status_str = "remove delay"; |
| 5438 | break; |
| 5439 | default: |
| 5440 | status_str = "unknown status"; |
| 5441 | break; |
| 5442 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5443 | printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5444 | ioc->name, status_str); |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5445 | printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5446 | "start_phy(%02d), count(%d)\n", |
| 5447 | le16_to_cpu(event_data->ExpanderDevHandle), |
| 5448 | le16_to_cpu(event_data->EnclosureHandle), |
| 5449 | event_data->StartPhyNum, event_data->NumEntries); |
| 5450 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5451 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5452 | if (!handle) |
| 5453 | continue; |
| 5454 | phy_number = event_data->StartPhyNum + i; |
| 5455 | reason_code = event_data->PHY[i].PhyStatus & |
| 5456 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5457 | switch (reason_code) { |
| 5458 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5459 | status_str = "target add"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5460 | break; |
| 5461 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5462 | status_str = "target remove"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5463 | break; |
| 5464 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5465 | status_str = "delay target remove"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5466 | break; |
| 5467 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5468 | status_str = "link rate change"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5469 | break; |
| 5470 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5471 | status_str = "target responding"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5472 | break; |
| 5473 | default: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5474 | status_str = "unknown"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5475 | break; |
| 5476 | } |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5477 | link_rate = event_data->PHY[i].LinkRate >> 4; |
| 5478 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5479 | printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:" |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5480 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, |
| 5481 | handle, status_str, link_rate, prev_link_rate); |
| 5482 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5483 | } |
| 5484 | } |
| 5485 | #endif |
| 5486 | |
| 5487 | /** |
| 5488 | * _scsih_sas_topology_change_event - handle topology changes |
| 5489 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5490 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5491 | * Context: user. |
| 5492 | * |
| 5493 | */ |
| 5494 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5495 | _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5496 | struct fw_event_work *fw_event) |
| 5497 | { |
| 5498 | int i; |
| 5499 | u16 parent_handle, handle; |
| 5500 | u16 reason_code; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5501 | u8 phy_number, max_phys; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5502 | struct _sas_node *sas_expander; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5503 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5504 | unsigned long flags; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5505 | u8 link_rate, prev_link_rate; |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 5506 | Mpi2EventDataSasTopologyChangeList_t *event_data = |
| 5507 | (Mpi2EventDataSasTopologyChangeList_t *) |
| 5508 | fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5509 | |
| 5510 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5511 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5512 | _scsih_sas_topology_change_event_debug(ioc, event_data); |
| 5513 | #endif |
| 5514 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5515 | if (ioc->remove_host || ioc->pci_error_recovery) |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5516 | return; |
| 5517 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5518 | if (!ioc->sas_hba.num_phys) |
| 5519 | _scsih_sas_host_add(ioc); |
| 5520 | else |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5521 | _scsih_sas_host_refresh(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5522 | |
| 5523 | if (fw_event->ignore) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5524 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5525 | "event\n", ioc->name)); |
| 5526 | return; |
| 5527 | } |
| 5528 | |
| 5529 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 5530 | |
| 5531 | /* handle expander add */ |
| 5532 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) |
| 5533 | if (_scsih_expander_add(ioc, parent_handle) != 0) |
| 5534 | return; |
| 5535 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5536 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 5537 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 5538 | parent_handle); |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5539 | if (sas_expander) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5540 | sas_address = sas_expander->sas_address; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5541 | max_phys = sas_expander->num_phys; |
| 5542 | } else if (parent_handle < ioc->sas_hba.num_phys) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5543 | sas_address = ioc->sas_hba.sas_address; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5544 | max_phys = ioc->sas_hba.num_phys; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5545 | } else { |
| 5546 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5547 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5548 | } |
| 5549 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5550 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5551 | /* handle siblings events */ |
| 5552 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5553 | if (fw_event->ignore) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5554 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5555 | "expander event\n", ioc->name)); |
| 5556 | return; |
| 5557 | } |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 5558 | if (ioc->shost_recovery || ioc->remove_host || |
| 5559 | ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 5560 | return; |
Kashyap, Desai | 308609c | 2009-09-14 11:07:23 +0530 | [diff] [blame] | 5561 | phy_number = event_data->StartPhyNum + i; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5562 | if (phy_number >= max_phys) |
| 5563 | continue; |
Kashyap, Desai | 308609c | 2009-09-14 11:07:23 +0530 | [diff] [blame] | 5564 | reason_code = event_data->PHY[i].PhyStatus & |
| 5565 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5566 | if ((event_data->PHY[i].PhyStatus & |
| 5567 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != |
| 5568 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5569 | continue; |
| 5570 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5571 | if (!handle) |
| 5572 | continue; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5573 | link_rate = event_data->PHY[i].LinkRate >> 4; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5574 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5575 | switch (reason_code) { |
| 5576 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5577 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5578 | if (ioc->shost_recovery) |
| 5579 | break; |
| 5580 | |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5581 | if (link_rate == prev_link_rate) |
| 5582 | break; |
| 5583 | |
| 5584 | mpt2sas_transport_update_links(ioc, sas_address, |
| 5585 | handle, phy_number, link_rate); |
| 5586 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5587 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 5588 | break; |
| 5589 | |
| 5590 | _scsih_check_device(ioc, handle); |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5591 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5592 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5593 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5594 | if (ioc->shost_recovery) |
| 5595 | break; |
| 5596 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5597 | mpt2sas_transport_update_links(ioc, sas_address, |
| 5598 | handle, phy_number, link_rate); |
| 5599 | |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5600 | _scsih_add_device(ioc, handle, phy_number, 0); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5601 | break; |
| 5602 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5603 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5604 | _scsih_device_remove_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5605 | break; |
| 5606 | } |
| 5607 | } |
| 5608 | |
| 5609 | /* handle expander removal */ |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5610 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && |
| 5611 | sas_expander) |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5612 | mpt2sas_expander_remove(ioc, sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5613 | |
| 5614 | } |
| 5615 | |
| 5616 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5617 | /** |
| 5618 | * _scsih_sas_device_status_change_event_debug - debug for device event |
| 5619 | * @event_data: event data payload |
| 5620 | * Context: user. |
| 5621 | * |
| 5622 | * Return nothing. |
| 5623 | */ |
| 5624 | static void |
| 5625 | _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5626 | Mpi2EventDataSasDeviceStatusChange_t *event_data) |
| 5627 | { |
| 5628 | char *reason_str = NULL; |
| 5629 | |
| 5630 | switch (event_data->ReasonCode) { |
| 5631 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: |
| 5632 | reason_str = "smart data"; |
| 5633 | break; |
| 5634 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: |
| 5635 | reason_str = "unsupported device discovered"; |
| 5636 | break; |
| 5637 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: |
| 5638 | reason_str = "internal device reset"; |
| 5639 | break; |
| 5640 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: |
| 5641 | reason_str = "internal task abort"; |
| 5642 | break; |
| 5643 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: |
| 5644 | reason_str = "internal task abort set"; |
| 5645 | break; |
| 5646 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: |
| 5647 | reason_str = "internal clear task set"; |
| 5648 | break; |
| 5649 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: |
| 5650 | reason_str = "internal query task"; |
| 5651 | break; |
| 5652 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: |
| 5653 | reason_str = "sata init failure"; |
| 5654 | break; |
| 5655 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: |
| 5656 | reason_str = "internal device reset complete"; |
| 5657 | break; |
| 5658 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: |
| 5659 | reason_str = "internal task abort complete"; |
| 5660 | break; |
| 5661 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: |
| 5662 | reason_str = "internal async notification"; |
| 5663 | break; |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 5664 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5665 | reason_str = "expander reduced functionality"; |
| 5666 | break; |
| 5667 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5668 | reason_str = "expander reduced functionality complete"; |
| 5669 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5670 | default: |
| 5671 | reason_str = "unknown reason"; |
| 5672 | break; |
| 5673 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5674 | printk(MPT2SAS_INFO_FMT "device status change: (%s)\n" |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5675 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", |
| 5676 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), |
| 5677 | (unsigned long long)le64_to_cpu(event_data->SASAddress), |
| 5678 | le16_to_cpu(event_data->TaskTag)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5679 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5680 | 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] | 5681 | event_data->ASC, event_data->ASCQ); |
| 5682 | printk(KERN_INFO "\n"); |
| 5683 | } |
| 5684 | #endif |
| 5685 | |
| 5686 | /** |
| 5687 | * _scsih_sas_device_status_change_event - handle device status change |
| 5688 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5689 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5690 | * Context: user. |
| 5691 | * |
| 5692 | * Return nothing. |
| 5693 | */ |
| 5694 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5695 | _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 5696 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5697 | { |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5698 | struct MPT2SAS_TARGET *target_priv_data; |
| 5699 | struct _sas_device *sas_device; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 5700 | u64 sas_address; |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5701 | unsigned long flags; |
| 5702 | Mpi2EventDataSasDeviceStatusChange_t *event_data = |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 5703 | (Mpi2EventDataSasDeviceStatusChange_t *) |
| 5704 | fw_event->event_data; |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5705 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5706 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5707 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5708 | _scsih_sas_device_status_change_event_debug(ioc, |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5709 | event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5710 | #endif |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5711 | |
Kashyap, Desai | efe82a1 | 2011-01-04 11:34:17 +0530 | [diff] [blame] | 5712 | /* In MPI Revision K (0xC), the internal device reset complete was |
| 5713 | * implemented, so avoid setting tm_busy flag for older firmware. |
| 5714 | */ |
| 5715 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) |
| 5716 | return; |
| 5717 | |
Kashyap, Desai | f891dcf | 2010-03-17 16:22:21 +0530 | [diff] [blame] | 5718 | if (event_data->ReasonCode != |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5719 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && |
Kashyap, Desai | f891dcf | 2010-03-17 16:22:21 +0530 | [diff] [blame] | 5720 | event_data->ReasonCode != |
| 5721 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5722 | return; |
| 5723 | |
| 5724 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5725 | sas_address = le64_to_cpu(event_data->SASAddress); |
| 5726 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5727 | sas_address); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5728 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5729 | if (!sas_device || !sas_device->starget) { |
| 5730 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5731 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5732 | } |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5733 | |
| 5734 | target_priv_data = sas_device->starget->hostdata; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5735 | if (!target_priv_data) { |
| 5736 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5737 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5738 | } |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5739 | |
| 5740 | if (event_data->ReasonCode == |
| 5741 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) |
| 5742 | target_priv_data->tm_busy = 1; |
| 5743 | else |
| 5744 | target_priv_data->tm_busy = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5745 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5746 | } |
| 5747 | |
| 5748 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5749 | /** |
| 5750 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event |
| 5751 | * @ioc: per adapter object |
| 5752 | * @event_data: event data payload |
| 5753 | * Context: user. |
| 5754 | * |
| 5755 | * Return nothing. |
| 5756 | */ |
| 5757 | static void |
| 5758 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5759 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) |
| 5760 | { |
| 5761 | char *reason_str = NULL; |
| 5762 | |
| 5763 | switch (event_data->ReasonCode) { |
| 5764 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: |
| 5765 | reason_str = "enclosure add"; |
| 5766 | break; |
| 5767 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: |
| 5768 | reason_str = "enclosure remove"; |
| 5769 | break; |
| 5770 | default: |
| 5771 | reason_str = "unknown reason"; |
| 5772 | break; |
| 5773 | } |
| 5774 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5775 | printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5776 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" |
| 5777 | " number slots(%d)\n", ioc->name, reason_str, |
| 5778 | le16_to_cpu(event_data->EnclosureHandle), |
| 5779 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), |
| 5780 | le16_to_cpu(event_data->StartSlot)); |
| 5781 | } |
| 5782 | #endif |
| 5783 | |
| 5784 | /** |
| 5785 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events |
| 5786 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5787 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5788 | * Context: user. |
| 5789 | * |
| 5790 | * Return nothing. |
| 5791 | */ |
| 5792 | static void |
| 5793 | _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5794 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5795 | { |
| 5796 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5797 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5798 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 5799 | (Mpi2EventDataSasEnclDevStatusChange_t *) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5800 | fw_event->event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5801 | #endif |
| 5802 | } |
| 5803 | |
| 5804 | /** |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 5805 | * _scsih_sas_broadcast_primitive_event - handle broadcast events |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5806 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5807 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5808 | * Context: user. |
| 5809 | * |
| 5810 | * Return nothing. |
| 5811 | */ |
| 5812 | static void |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 5813 | _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5814 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5815 | { |
| 5816 | struct scsi_cmnd *scmd; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5817 | struct scsi_device *sdev; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5818 | u16 smid, handle; |
| 5819 | u32 lun; |
| 5820 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 5821 | u32 termination_count; |
| 5822 | u32 query_count; |
| 5823 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 5824 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = |
| 5825 | (Mpi2EventDataSasBroadcastPrimitive_t *) |
| 5826 | fw_event->event_data; |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 5827 | u16 ioc_status; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5828 | unsigned long flags; |
| 5829 | int r; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5830 | u8 max_retries = 0; |
| 5831 | u8 task_abort_retries; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5832 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5833 | mutex_lock(&ioc->tm_cmds.mutex); |
Reddy, Sreekanth | c3a634b | 2013-02-26 17:36:12 +0530 | [diff] [blame] | 5834 | pr_info(MPT2SAS_FMT |
| 5835 | "%s: enter: phy number(%d), width(%d)\n", |
| 5836 | ioc->name, __func__, event_data->PhyNum, |
| 5837 | event_data->PortWidth); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5838 | |
| 5839 | _scsih_block_io_all_device(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5840 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5841 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5842 | mpi_reply = ioc->tm_cmds.reply; |
| 5843 | broadcast_aen_retry: |
| 5844 | |
| 5845 | /* sanity checks for retrying this loop */ |
| 5846 | if (max_retries++ == 5) { |
| 5847 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n", |
| 5848 | ioc->name, __func__)); |
| 5849 | goto out; |
| 5850 | } else if (max_retries > 1) |
| 5851 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n", |
| 5852 | ioc->name, __func__, max_retries - 1)); |
| 5853 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5854 | termination_count = 0; |
| 5855 | query_count = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 5856 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5857 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5858 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5859 | scmd = _scsih_scsi_lookup_get(ioc, smid); |
| 5860 | if (!scmd) |
| 5861 | continue; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5862 | sdev = scmd->device; |
| 5863 | sas_device_priv_data = sdev->hostdata; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5864 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) |
| 5865 | continue; |
| 5866 | /* skip hidden raid components */ |
| 5867 | if (sas_device_priv_data->sas_target->flags & |
| 5868 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 5869 | continue; |
| 5870 | /* skip volumes */ |
| 5871 | if (sas_device_priv_data->sas_target->flags & |
| 5872 | MPT_TARGET_FLAGS_VOLUME) |
| 5873 | continue; |
| 5874 | |
| 5875 | handle = sas_device_priv_data->sas_target->handle; |
| 5876 | lun = sas_device_priv_data->lun; |
| 5877 | query_count++; |
| 5878 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5879 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5880 | goto out; |
| 5881 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5882 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5883 | r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun, |
Matthew Wilcox | 2e45c8b | 2014-03-27 16:40:32 -0400 | [diff] [blame] | 5884 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5885 | TM_MUTEX_OFF); |
| 5886 | if (r == FAILED) { |
| 5887 | sdev_printk(KERN_WARNING, sdev, |
| 5888 | "mpt2sas_scsih_issue_tm: FAILED when sending " |
| 5889 | "QUERY_TASK: scmd(%p)\n", scmd); |
| 5890 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5891 | goto broadcast_aen_retry; |
| 5892 | } |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 5893 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) |
| 5894 | & MPI2_IOCSTATUS_MASK; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5895 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5896 | sdev_printk(KERN_WARNING, sdev, "query task: FAILED " |
| 5897 | "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status, |
| 5898 | scmd); |
| 5899 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5900 | goto broadcast_aen_retry; |
| 5901 | } |
| 5902 | |
| 5903 | /* see if IO is still owned by IOC and target */ |
| 5904 | if (mpi_reply->ResponseCode == |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5905 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || |
| 5906 | mpi_reply->ResponseCode == |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5907 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5908 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5909 | continue; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5910 | } |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5911 | task_abort_retries = 0; |
| 5912 | tm_retry: |
| 5913 | if (task_abort_retries++ == 60) { |
| 5914 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 5915 | "%s: ABORT_TASK: giving up\n", ioc->name, |
| 5916 | __func__)); |
| 5917 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5918 | goto broadcast_aen_retry; |
| 5919 | } |
| 5920 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5921 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5922 | goto out_no_lock; |
| 5923 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5924 | r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, |
| 5925 | sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, |
Matthew Wilcox | 2e45c8b | 2014-03-27 16:40:32 -0400 | [diff] [blame] | 5926 | TM_MUTEX_OFF); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5927 | if (r == FAILED) { |
| 5928 | sdev_printk(KERN_WARNING, sdev, |
| 5929 | "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : " |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5930 | "scmd(%p)\n", scmd); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5931 | goto tm_retry; |
| 5932 | } |
| 5933 | |
| 5934 | if (task_abort_retries > 1) |
| 5935 | sdev_printk(KERN_WARNING, sdev, |
| 5936 | "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" |
| 5937 | " scmd(%p)\n", |
| 5938 | task_abort_retries - 1, scmd); |
| 5939 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5940 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5941 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5942 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5943 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5944 | if (ioc->broadcast_aen_pending) { |
| 5945 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to" |
| 5946 | " pending AEN\n", ioc->name, __func__)); |
| 5947 | ioc->broadcast_aen_pending = 0; |
| 5948 | goto broadcast_aen_retry; |
| 5949 | } |
| 5950 | |
| 5951 | out: |
| 5952 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 5953 | out_no_lock: |
| 5954 | |
| 5955 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5956 | "%s - exit, query_count = %d termination_count = %d\n", |
| 5957 | ioc->name, __func__, query_count, termination_count)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5958 | |
| 5959 | ioc->broadcast_aen_busy = 0; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5960 | if (!ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5961 | _scsih_ublock_io_all_device(ioc); |
| 5962 | mutex_unlock(&ioc->tm_cmds.mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5963 | } |
| 5964 | |
| 5965 | /** |
| 5966 | * _scsih_sas_discovery_event - handle discovery events |
| 5967 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5968 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5969 | * Context: user. |
| 5970 | * |
| 5971 | * Return nothing. |
| 5972 | */ |
| 5973 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5974 | _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc, |
| 5975 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5976 | { |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 5977 | Mpi2EventDataSasDiscovery_t *event_data = |
| 5978 | (Mpi2EventDataSasDiscovery_t *) |
| 5979 | fw_event->event_data; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5980 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5981 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5982 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5983 | printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5984 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? |
| 5985 | "start" : "stop"); |
| 5986 | if (event_data->DiscoveryStatus) |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 5987 | printk("discovery_status(0x%08x)", |
| 5988 | le32_to_cpu(event_data->DiscoveryStatus)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5989 | printk("\n"); |
| 5990 | } |
| 5991 | #endif |
| 5992 | |
| 5993 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 5994 | !ioc->sas_hba.num_phys) { |
| 5995 | if (disable_discovery > 0 && ioc->shost_recovery) { |
| 5996 | /* Wait for the reset to complete */ |
| 5997 | while (ioc->shost_recovery) |
| 5998 | ssleep(1); |
| 5999 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6000 | _scsih_sas_host_add(ioc); |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 6001 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6002 | } |
| 6003 | |
| 6004 | /** |
| 6005 | * _scsih_reprobe_lun - reprobing lun |
| 6006 | * @sdev: scsi device struct |
| 6007 | * @no_uld_attach: sdev->no_uld_attach flag setting |
| 6008 | * |
| 6009 | **/ |
| 6010 | static void |
| 6011 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) |
| 6012 | { |
| 6013 | int rc; |
| 6014 | |
| 6015 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
| 6016 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", |
| 6017 | sdev->no_uld_attach ? "hidding" : "exposing"); |
| 6018 | rc = scsi_device_reprobe(sdev); |
| 6019 | } |
| 6020 | |
| 6021 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6022 | * _scsih_sas_volume_add - add new volume |
| 6023 | * @ioc: per adapter object |
| 6024 | * @element: IR config element data |
| 6025 | * Context: user. |
| 6026 | * |
| 6027 | * Return nothing. |
| 6028 | */ |
| 6029 | static void |
| 6030 | _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc, |
| 6031 | Mpi2EventIrConfigElement_t *element) |
| 6032 | { |
| 6033 | struct _raid_device *raid_device; |
| 6034 | unsigned long flags; |
| 6035 | u64 wwid; |
| 6036 | u16 handle = le16_to_cpu(element->VolDevHandle); |
| 6037 | int rc; |
| 6038 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6039 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 6040 | if (!wwid) { |
| 6041 | printk(MPT2SAS_ERR_FMT |
| 6042 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6043 | __FILE__, __LINE__, __func__); |
| 6044 | return; |
| 6045 | } |
| 6046 | |
| 6047 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6048 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); |
| 6049 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6050 | |
| 6051 | if (raid_device) |
| 6052 | return; |
| 6053 | |
| 6054 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 6055 | if (!raid_device) { |
| 6056 | printk(MPT2SAS_ERR_FMT |
| 6057 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6058 | __FILE__, __LINE__, __func__); |
| 6059 | return; |
| 6060 | } |
| 6061 | |
| 6062 | raid_device->id = ioc->sas_id++; |
| 6063 | raid_device->channel = RAID_CHANNEL; |
| 6064 | raid_device->handle = handle; |
| 6065 | raid_device->wwid = wwid; |
| 6066 | _scsih_raid_device_add(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6067 | if (!ioc->wait_for_discovery_to_complete) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6068 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 6069 | raid_device->id, 0); |
| 6070 | if (rc) |
| 6071 | _scsih_raid_device_remove(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6072 | } else { |
| 6073 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6074 | _scsih_determine_boot_device(ioc, raid_device, 1); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6075 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6076 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6077 | } |
| 6078 | |
| 6079 | /** |
| 6080 | * _scsih_sas_volume_delete - delete volume |
| 6081 | * @ioc: per adapter object |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6082 | * @handle: volume device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6083 | * Context: user. |
| 6084 | * |
| 6085 | * Return nothing. |
| 6086 | */ |
| 6087 | static void |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6088 | _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6089 | { |
| 6090 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6091 | unsigned long flags; |
| 6092 | struct MPT2SAS_TARGET *sas_target_priv_data; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6093 | struct scsi_target *starget = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6094 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6095 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6096 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6097 | if (raid_device) { |
| 6098 | if (raid_device->starget) { |
| 6099 | starget = raid_device->starget; |
| 6100 | sas_target_priv_data = starget->hostdata; |
| 6101 | sas_target_priv_data->deleted = 1; |
| 6102 | } |
| 6103 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" |
| 6104 | "(0x%016llx)\n", ioc->name, raid_device->handle, |
| 6105 | (unsigned long long) raid_device->wwid); |
| 6106 | list_del(&raid_device->list); |
| 6107 | kfree(raid_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6108 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6109 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6110 | if (starget) |
| 6111 | scsi_remove_target(&starget->dev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6112 | } |
| 6113 | |
| 6114 | /** |
| 6115 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX |
| 6116 | * @ioc: per adapter object |
| 6117 | * @element: IR config element data |
| 6118 | * Context: user. |
| 6119 | * |
| 6120 | * Return nothing. |
| 6121 | */ |
| 6122 | static void |
| 6123 | _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc, |
| 6124 | Mpi2EventIrConfigElement_t *element) |
| 6125 | { |
| 6126 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6127 | struct scsi_target *starget = NULL; |
| 6128 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6129 | unsigned long flags; |
| 6130 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 6131 | |
| 6132 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6133 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6134 | if (sas_device) { |
| 6135 | sas_device->volume_handle = 0; |
| 6136 | sas_device->volume_wwid = 0; |
| 6137 | clear_bit(handle, ioc->pd_handles); |
| 6138 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 6139 | starget = sas_device->starget; |
| 6140 | sas_target_priv_data = starget->hostdata; |
| 6141 | sas_target_priv_data->flags &= |
| 6142 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 6143 | } |
| 6144 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6145 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6146 | if (!sas_device) |
| 6147 | return; |
| 6148 | |
| 6149 | /* exposing raid component */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6150 | if (starget) |
| 6151 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | /** |
| 6155 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX |
| 6156 | * @ioc: per adapter object |
| 6157 | * @element: IR config element data |
| 6158 | * Context: user. |
| 6159 | * |
| 6160 | * Return nothing. |
| 6161 | */ |
| 6162 | static void |
| 6163 | _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc, |
| 6164 | Mpi2EventIrConfigElement_t *element) |
| 6165 | { |
| 6166 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6167 | struct scsi_target *starget = NULL; |
| 6168 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6169 | unsigned long flags; |
| 6170 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6171 | u16 volume_handle = 0; |
| 6172 | u64 volume_wwid = 0; |
| 6173 | |
| 6174 | mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle); |
| 6175 | if (volume_handle) |
| 6176 | mpt2sas_config_get_volume_wwid(ioc, volume_handle, |
| 6177 | &volume_wwid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6178 | |
| 6179 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6180 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6181 | if (sas_device) { |
| 6182 | set_bit(handle, ioc->pd_handles); |
| 6183 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 6184 | starget = sas_device->starget; |
| 6185 | sas_target_priv_data = starget->hostdata; |
| 6186 | sas_target_priv_data->flags |= |
| 6187 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 6188 | sas_device->volume_handle = volume_handle; |
| 6189 | sas_device->volume_wwid = volume_wwid; |
| 6190 | } |
| 6191 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6192 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6193 | if (!sas_device) |
| 6194 | return; |
| 6195 | |
| 6196 | /* hiding raid component */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6197 | if (starget) |
| 6198 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | /** |
| 6202 | * _scsih_sas_pd_delete - delete pd component |
| 6203 | * @ioc: per adapter object |
| 6204 | * @element: IR config element data |
| 6205 | * Context: user. |
| 6206 | * |
| 6207 | * Return nothing. |
| 6208 | */ |
| 6209 | static void |
| 6210 | _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc, |
| 6211 | Mpi2EventIrConfigElement_t *element) |
| 6212 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6213 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 6214 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6215 | _scsih_device_remove_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6216 | } |
| 6217 | |
| 6218 | /** |
| 6219 | * _scsih_sas_pd_add - remove pd component |
| 6220 | * @ioc: per adapter object |
| 6221 | * @element: IR config element data |
| 6222 | * Context: user. |
| 6223 | * |
| 6224 | * Return nothing. |
| 6225 | */ |
| 6226 | static void |
| 6227 | _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc, |
| 6228 | Mpi2EventIrConfigElement_t *element) |
| 6229 | { |
| 6230 | struct _sas_device *sas_device; |
| 6231 | unsigned long flags; |
| 6232 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6233 | Mpi2ConfigReply_t mpi_reply; |
| 6234 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6235 | u32 ioc_status; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6236 | u64 sas_address; |
| 6237 | u16 parent_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6238 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6239 | set_bit(handle, ioc->pd_handles); |
| 6240 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6241 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6242 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6243 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6244 | if (sas_device) |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6245 | return; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6246 | |
| 6247 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 6248 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 6249 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6250 | ioc->name, __FILE__, __LINE__, __func__); |
| 6251 | return; |
| 6252 | } |
| 6253 | |
| 6254 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6255 | MPI2_IOCSTATUS_MASK; |
| 6256 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6257 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6258 | ioc->name, __FILE__, __LINE__, __func__); |
| 6259 | return; |
| 6260 | } |
| 6261 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6262 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6263 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 6264 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 6265 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6266 | |
| 6267 | _scsih_add_device(ioc, handle, 0, 1); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6268 | } |
| 6269 | |
| 6270 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 6271 | /** |
| 6272 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events |
| 6273 | * @ioc: per adapter object |
| 6274 | * @event_data: event data payload |
| 6275 | * Context: user. |
| 6276 | * |
| 6277 | * Return nothing. |
| 6278 | */ |
| 6279 | static void |
| 6280 | _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 6281 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 6282 | { |
| 6283 | Mpi2EventIrConfigElement_t *element; |
| 6284 | u8 element_type; |
| 6285 | int i; |
| 6286 | char *reason_str = NULL, *element_str = NULL; |
| 6287 | |
| 6288 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 6289 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6290 | printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6291 | ioc->name, (le32_to_cpu(event_data->Flags) & |
| 6292 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? |
| 6293 | "foreign" : "native", event_data->NumElements); |
| 6294 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6295 | switch (element->ReasonCode) { |
| 6296 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
| 6297 | reason_str = "add"; |
| 6298 | break; |
| 6299 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
| 6300 | reason_str = "remove"; |
| 6301 | break; |
| 6302 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: |
| 6303 | reason_str = "no change"; |
| 6304 | break; |
| 6305 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
| 6306 | reason_str = "hide"; |
| 6307 | break; |
| 6308 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
| 6309 | reason_str = "unhide"; |
| 6310 | break; |
| 6311 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 6312 | reason_str = "volume_created"; |
| 6313 | break; |
| 6314 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 6315 | reason_str = "volume_deleted"; |
| 6316 | break; |
| 6317 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
| 6318 | reason_str = "pd_created"; |
| 6319 | break; |
| 6320 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
| 6321 | reason_str = "pd_deleted"; |
| 6322 | break; |
| 6323 | default: |
| 6324 | reason_str = "unknown reason"; |
| 6325 | break; |
| 6326 | } |
| 6327 | element_type = le16_to_cpu(element->ElementFlags) & |
| 6328 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; |
| 6329 | switch (element_type) { |
| 6330 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: |
| 6331 | element_str = "volume"; |
| 6332 | break; |
| 6333 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: |
| 6334 | element_str = "phys disk"; |
| 6335 | break; |
| 6336 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: |
| 6337 | element_str = "hot spare"; |
| 6338 | break; |
| 6339 | default: |
| 6340 | element_str = "unknown element"; |
| 6341 | break; |
| 6342 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6343 | printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6344 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, |
| 6345 | reason_str, le16_to_cpu(element->VolDevHandle), |
| 6346 | le16_to_cpu(element->PhysDiskDevHandle), |
| 6347 | element->PhysDiskNum); |
| 6348 | } |
| 6349 | } |
| 6350 | #endif |
| 6351 | |
| 6352 | /** |
| 6353 | * _scsih_sas_ir_config_change_event - handle ir configuration change events |
| 6354 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6355 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6356 | * Context: user. |
| 6357 | * |
| 6358 | * Return nothing. |
| 6359 | */ |
| 6360 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6361 | _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 6362 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6363 | { |
| 6364 | Mpi2EventIrConfigElement_t *element; |
| 6365 | int i; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6366 | u8 foreign_config; |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 6367 | Mpi2EventDataIrConfigChangeList_t *event_data = |
| 6368 | (Mpi2EventDataIrConfigChangeList_t *) |
| 6369 | fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6370 | |
| 6371 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6372 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6373 | && !ioc->hide_ir_msg) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6374 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
| 6375 | |
| 6376 | #endif |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6377 | |
| 6378 | if (ioc->shost_recovery) |
| 6379 | return; |
| 6380 | |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6381 | foreign_config = (le32_to_cpu(event_data->Flags) & |
| 6382 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6383 | |
| 6384 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 6385 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6386 | |
| 6387 | switch (element->ReasonCode) { |
| 6388 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 6389 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6390 | if (!foreign_config) |
| 6391 | _scsih_sas_volume_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6392 | break; |
| 6393 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 6394 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6395 | if (!foreign_config) |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6396 | _scsih_sas_volume_delete(ioc, |
| 6397 | le16_to_cpu(element->VolDevHandle)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6398 | break; |
| 6399 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6400 | if (!ioc->is_warpdrive) |
| 6401 | _scsih_sas_pd_hide(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6402 | break; |
| 6403 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6404 | if (!ioc->is_warpdrive) |
| 6405 | _scsih_sas_pd_expose(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6406 | break; |
| 6407 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6408 | if (!ioc->is_warpdrive) |
| 6409 | _scsih_sas_pd_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6410 | break; |
| 6411 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6412 | if (!ioc->is_warpdrive) |
| 6413 | _scsih_sas_pd_delete(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6414 | break; |
| 6415 | } |
| 6416 | } |
| 6417 | } |
| 6418 | |
| 6419 | /** |
| 6420 | * _scsih_sas_ir_volume_event - IR volume event |
| 6421 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6422 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6423 | * Context: user. |
| 6424 | * |
| 6425 | * Return nothing. |
| 6426 | */ |
| 6427 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6428 | _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc, |
| 6429 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6430 | { |
| 6431 | u64 wwid; |
| 6432 | unsigned long flags; |
| 6433 | struct _raid_device *raid_device; |
| 6434 | u16 handle; |
| 6435 | u32 state; |
| 6436 | int rc; |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 6437 | Mpi2EventDataIrVolume_t *event_data = |
| 6438 | (Mpi2EventDataIrVolume_t *) |
| 6439 | fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6440 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6441 | if (ioc->shost_recovery) |
| 6442 | return; |
| 6443 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6444 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 6445 | return; |
| 6446 | |
| 6447 | handle = le16_to_cpu(event_data->VolDevHandle); |
| 6448 | state = le32_to_cpu(event_data->NewValue); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6449 | if (!ioc->hide_ir_msg) |
| 6450 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " |
| 6451 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 6452 | le32_to_cpu(event_data->PreviousValue), state)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6453 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6454 | switch (state) { |
| 6455 | case MPI2_RAID_VOL_STATE_MISSING: |
| 6456 | case MPI2_RAID_VOL_STATE_FAILED: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6457 | _scsih_sas_volume_delete(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6458 | break; |
| 6459 | |
| 6460 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 6461 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 6462 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6463 | |
| 6464 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6465 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 6466 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6467 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6468 | if (raid_device) |
| 6469 | break; |
| 6470 | |
| 6471 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 6472 | if (!wwid) { |
| 6473 | printk(MPT2SAS_ERR_FMT |
| 6474 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6475 | __FILE__, __LINE__, __func__); |
| 6476 | break; |
| 6477 | } |
| 6478 | |
| 6479 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 6480 | if (!raid_device) { |
| 6481 | printk(MPT2SAS_ERR_FMT |
| 6482 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6483 | __FILE__, __LINE__, __func__); |
| 6484 | break; |
| 6485 | } |
| 6486 | |
| 6487 | raid_device->id = ioc->sas_id++; |
| 6488 | raid_device->channel = RAID_CHANNEL; |
| 6489 | raid_device->handle = handle; |
| 6490 | raid_device->wwid = wwid; |
| 6491 | _scsih_raid_device_add(ioc, raid_device); |
| 6492 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 6493 | raid_device->id, 0); |
| 6494 | if (rc) |
| 6495 | _scsih_raid_device_remove(ioc, raid_device); |
| 6496 | break; |
| 6497 | |
| 6498 | case MPI2_RAID_VOL_STATE_INITIALIZING: |
| 6499 | default: |
| 6500 | break; |
| 6501 | } |
| 6502 | } |
| 6503 | |
| 6504 | /** |
| 6505 | * _scsih_sas_ir_physical_disk_event - PD event |
| 6506 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6507 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6508 | * Context: user. |
| 6509 | * |
| 6510 | * Return nothing. |
| 6511 | */ |
| 6512 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6513 | _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc, |
| 6514 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6515 | { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6516 | u16 handle, parent_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6517 | u32 state; |
| 6518 | struct _sas_device *sas_device; |
| 6519 | unsigned long flags; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6520 | Mpi2ConfigReply_t mpi_reply; |
| 6521 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6522 | u32 ioc_status; |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 6523 | Mpi2EventDataIrPhysicalDisk_t *event_data = |
| 6524 | (Mpi2EventDataIrPhysicalDisk_t *) |
| 6525 | fw_event->event_data; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6526 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6527 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6528 | if (ioc->shost_recovery) |
| 6529 | return; |
| 6530 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6531 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) |
| 6532 | return; |
| 6533 | |
| 6534 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); |
| 6535 | state = le32_to_cpu(event_data->NewValue); |
| 6536 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6537 | if (!ioc->hide_ir_msg) |
| 6538 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " |
| 6539 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 6540 | le32_to_cpu(event_data->PreviousValue), state)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6541 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6542 | switch (state) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6543 | case MPI2_RAID_PD_STATE_ONLINE: |
| 6544 | case MPI2_RAID_PD_STATE_DEGRADED: |
| 6545 | case MPI2_RAID_PD_STATE_REBUILDING: |
| 6546 | case MPI2_RAID_PD_STATE_OPTIMAL: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6547 | case MPI2_RAID_PD_STATE_HOT_SPARE: |
| 6548 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6549 | if (!ioc->is_warpdrive) |
| 6550 | set_bit(handle, ioc->pd_handles); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6551 | |
| 6552 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6553 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6554 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6555 | |
| 6556 | if (sas_device) |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6557 | return; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6558 | |
| 6559 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6560 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 6561 | handle))) { |
| 6562 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6563 | ioc->name, __FILE__, __LINE__, __func__); |
| 6564 | return; |
| 6565 | } |
| 6566 | |
| 6567 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6568 | MPI2_IOCSTATUS_MASK; |
| 6569 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6570 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6571 | ioc->name, __FILE__, __LINE__, __func__); |
| 6572 | return; |
| 6573 | } |
| 6574 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6575 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6576 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 6577 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 6578 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6579 | |
| 6580 | _scsih_add_device(ioc, handle, 0, 1); |
| 6581 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6582 | break; |
| 6583 | |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6584 | case MPI2_RAID_PD_STATE_OFFLINE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6585 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: |
| 6586 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6587 | default: |
| 6588 | break; |
| 6589 | } |
| 6590 | } |
| 6591 | |
| 6592 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 6593 | /** |
| 6594 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event |
| 6595 | * @ioc: per adapter object |
| 6596 | * @event_data: event data payload |
| 6597 | * Context: user. |
| 6598 | * |
| 6599 | * Return nothing. |
| 6600 | */ |
| 6601 | static void |
| 6602 | _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 6603 | Mpi2EventDataIrOperationStatus_t *event_data) |
| 6604 | { |
| 6605 | char *reason_str = NULL; |
| 6606 | |
| 6607 | switch (event_data->RAIDOperation) { |
| 6608 | case MPI2_EVENT_IR_RAIDOP_RESYNC: |
| 6609 | reason_str = "resync"; |
| 6610 | break; |
| 6611 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: |
| 6612 | reason_str = "online capacity expansion"; |
| 6613 | break; |
| 6614 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: |
| 6615 | reason_str = "consistency check"; |
| 6616 | break; |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 6617 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: |
| 6618 | reason_str = "background init"; |
| 6619 | break; |
| 6620 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: |
| 6621 | reason_str = "make data consistent"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6622 | break; |
| 6623 | } |
| 6624 | |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 6625 | if (!reason_str) |
| 6626 | return; |
| 6627 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6628 | printk(MPT2SAS_INFO_FMT "raid operational status: (%s)" |
| 6629 | "\thandle(0x%04x), percent complete(%d)\n", |
| 6630 | ioc->name, reason_str, |
| 6631 | le16_to_cpu(event_data->VolDevHandle), |
| 6632 | event_data->PercentComplete); |
| 6633 | } |
| 6634 | #endif |
| 6635 | |
| 6636 | /** |
| 6637 | * _scsih_sas_ir_operation_status_event - handle RAID operation events |
| 6638 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6639 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6640 | * Context: user. |
| 6641 | * |
| 6642 | * Return nothing. |
| 6643 | */ |
| 6644 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6645 | _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc, |
| 6646 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6647 | { |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 6648 | Mpi2EventDataIrOperationStatus_t *event_data = |
| 6649 | (Mpi2EventDataIrOperationStatus_t *) |
| 6650 | fw_event->event_data; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6651 | static struct _raid_device *raid_device; |
| 6652 | unsigned long flags; |
| 6653 | u16 handle; |
| 6654 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6655 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6656 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6657 | && !ioc->hide_ir_msg) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6658 | _scsih_sas_ir_operation_status_event_debug(ioc, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6659 | event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6660 | #endif |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6661 | |
| 6662 | /* code added for raid transport support */ |
| 6663 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { |
| 6664 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6665 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6666 | handle = le16_to_cpu(event_data->VolDevHandle); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6667 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6668 | if (raid_device) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6669 | raid_device->percent_complete = |
| 6670 | event_data->PercentComplete; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6671 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6672 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6673 | } |
| 6674 | |
| 6675 | /** |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6676 | * _scsih_prep_device_scan - initialize parameters prior to device scan |
| 6677 | * @ioc: per adapter object |
| 6678 | * |
| 6679 | * Set the deleted flag prior to device scan. If the device is found during |
| 6680 | * the scan, then we clear the deleted flag. |
| 6681 | */ |
| 6682 | static void |
| 6683 | _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc) |
| 6684 | { |
| 6685 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 6686 | struct scsi_device *sdev; |
| 6687 | |
| 6688 | shost_for_each_device(sdev, ioc->shost) { |
| 6689 | sas_device_priv_data = sdev->hostdata; |
| 6690 | if (sas_device_priv_data && sas_device_priv_data->sas_target) |
| 6691 | sas_device_priv_data->sas_target->deleted = 1; |
| 6692 | } |
| 6693 | } |
| 6694 | |
| 6695 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6696 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding |
| 6697 | * @ioc: per adapter object |
| 6698 | * @sas_address: sas address |
| 6699 | * @slot: enclosure slot id |
| 6700 | * @handle: device handle |
| 6701 | * |
| 6702 | * After host reset, find out whether devices are still responding. |
| 6703 | * Used in _scsi_remove_unresponsive_sas_devices. |
| 6704 | * |
| 6705 | * Return nothing. |
| 6706 | */ |
| 6707 | static void |
| 6708 | _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 6709 | u16 slot, u16 handle) |
| 6710 | { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6711 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6712 | struct scsi_target *starget; |
| 6713 | struct _sas_device *sas_device; |
| 6714 | unsigned long flags; |
| 6715 | |
| 6716 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6717 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { |
| 6718 | if (sas_device->sas_address == sas_address && |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6719 | sas_device->slot == slot) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6720 | sas_device->responding = 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6721 | starget = sas_device->starget; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6722 | if (starget && starget->hostdata) { |
| 6723 | sas_target_priv_data = starget->hostdata; |
| 6724 | sas_target_priv_data->tm_busy = 0; |
| 6725 | sas_target_priv_data->deleted = 0; |
| 6726 | } else |
| 6727 | sas_target_priv_data = NULL; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6728 | if (starget) |
| 6729 | starget_printk(KERN_INFO, starget, |
| 6730 | "handle(0x%04x), sas_addr(0x%016llx), " |
| 6731 | "enclosure logical id(0x%016llx), " |
| 6732 | "slot(%d)\n", handle, |
| 6733 | (unsigned long long)sas_device->sas_address, |
| 6734 | (unsigned long long) |
| 6735 | sas_device->enclosure_logical_id, |
| 6736 | sas_device->slot); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6737 | if (sas_device->handle == handle) |
| 6738 | goto out; |
| 6739 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 6740 | sas_device->handle); |
| 6741 | sas_device->handle = handle; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6742 | if (sas_target_priv_data) |
| 6743 | sas_target_priv_data->handle = handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6744 | goto out; |
| 6745 | } |
| 6746 | } |
| 6747 | out: |
| 6748 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6749 | } |
| 6750 | |
| 6751 | /** |
| 6752 | * _scsih_search_responding_sas_devices - |
| 6753 | * @ioc: per adapter object |
| 6754 | * |
| 6755 | * After host reset, find out whether devices are still responding. |
| 6756 | * If not remove. |
| 6757 | * |
| 6758 | * Return nothing. |
| 6759 | */ |
| 6760 | static void |
| 6761 | _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6762 | { |
| 6763 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6764 | Mpi2ConfigReply_t mpi_reply; |
| 6765 | u16 ioc_status; |
| 6766 | __le64 sas_address; |
| 6767 | u16 handle; |
| 6768 | u32 device_info; |
| 6769 | u16 slot; |
| 6770 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6771 | printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6772 | |
| 6773 | if (list_empty(&ioc->sas_device_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6774 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6775 | |
| 6776 | handle = 0xFFFF; |
| 6777 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6778 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 6779 | handle))) { |
| 6780 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6781 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 1c50e8d | 2013-07-25 11:29:45 +0530 | [diff] [blame] | 6782 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6783 | break; |
| 6784 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 6785 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 6786 | if (!(_scsih_is_end_device(device_info))) |
| 6787 | continue; |
| 6788 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 6789 | slot = le16_to_cpu(sas_device_pg0.Slot); |
| 6790 | _scsih_mark_responding_sas_device(ioc, sas_address, slot, |
| 6791 | handle); |
| 6792 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6793 | out: |
| 6794 | printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n", |
| 6795 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6796 | } |
| 6797 | |
| 6798 | /** |
| 6799 | * _scsih_mark_responding_raid_device - mark a raid_device as responding |
| 6800 | * @ioc: per adapter object |
| 6801 | * @wwid: world wide identifier for raid volume |
| 6802 | * @handle: device handle |
| 6803 | * |
| 6804 | * After host reset, find out whether devices are still responding. |
| 6805 | * Used in _scsi_remove_unresponsive_raid_devices. |
| 6806 | * |
| 6807 | * Return nothing. |
| 6808 | */ |
| 6809 | static void |
| 6810 | _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid, |
| 6811 | u16 handle) |
| 6812 | { |
| 6813 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 6814 | struct scsi_target *starget; |
| 6815 | struct _raid_device *raid_device; |
| 6816 | unsigned long flags; |
| 6817 | |
| 6818 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6819 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 6820 | if (raid_device->wwid == wwid && raid_device->starget) { |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6821 | starget = raid_device->starget; |
| 6822 | if (starget && starget->hostdata) { |
| 6823 | sas_target_priv_data = starget->hostdata; |
| 6824 | sas_target_priv_data->deleted = 0; |
| 6825 | } else |
| 6826 | sas_target_priv_data = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6827 | raid_device->responding = 1; |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6828 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6829 | starget_printk(KERN_INFO, raid_device->starget, |
| 6830 | "handle(0x%04x), wwid(0x%016llx)\n", handle, |
| 6831 | (unsigned long long)raid_device->wwid); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6832 | /* |
| 6833 | * WARPDRIVE: The handles of the PDs might have changed |
| 6834 | * across the host reset so re-initialize the |
| 6835 | * required data for Direct IO |
| 6836 | */ |
| 6837 | _scsih_init_warpdrive_properties(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6838 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6839 | if (raid_device->handle == handle) { |
| 6840 | spin_unlock_irqrestore(&ioc->raid_device_lock, |
| 6841 | flags); |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6842 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6843 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6844 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 6845 | raid_device->handle); |
| 6846 | raid_device->handle = handle; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6847 | if (sas_target_priv_data) |
| 6848 | sas_target_priv_data->handle = handle; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6849 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6850 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6851 | } |
| 6852 | } |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6853 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6854 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6855 | } |
| 6856 | |
| 6857 | /** |
| 6858 | * _scsih_search_responding_raid_devices - |
| 6859 | * @ioc: per adapter object |
| 6860 | * |
| 6861 | * After host reset, find out whether devices are still responding. |
| 6862 | * If not remove. |
| 6863 | * |
| 6864 | * Return nothing. |
| 6865 | */ |
| 6866 | static void |
| 6867 | _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6868 | { |
| 6869 | Mpi2RaidVolPage1_t volume_pg1; |
Kashyap, Desai | d417d1c | 2010-06-17 13:48:10 +0530 | [diff] [blame] | 6870 | Mpi2RaidVolPage0_t volume_pg0; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6871 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6872 | Mpi2ConfigReply_t mpi_reply; |
| 6873 | u16 ioc_status; |
| 6874 | u16 handle; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6875 | u8 phys_disk_num; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6876 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6877 | if (!ioc->ir_firmware) |
| 6878 | return; |
| 6879 | |
| 6880 | printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n", |
| 6881 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6882 | |
| 6883 | if (list_empty(&ioc->raid_device_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6884 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6885 | |
| 6886 | handle = 0xFFFF; |
| 6887 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 6888 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 6889 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6890 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 1c50e8d | 2013-07-25 11:29:45 +0530 | [diff] [blame] | 6891 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6892 | break; |
| 6893 | handle = le16_to_cpu(volume_pg1.DevHandle); |
Kashyap, Desai | d417d1c | 2010-06-17 13:48:10 +0530 | [diff] [blame] | 6894 | |
| 6895 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 6896 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 6897 | sizeof(Mpi2RaidVolPage0_t))) |
| 6898 | continue; |
| 6899 | |
| 6900 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 6901 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 6902 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) |
| 6903 | _scsih_mark_responding_raid_device(ioc, |
| 6904 | le64_to_cpu(volume_pg1.WWID), handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6905 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6906 | |
| 6907 | /* refresh the pd_handles */ |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6908 | if (!ioc->is_warpdrive) { |
| 6909 | phys_disk_num = 0xFF; |
| 6910 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); |
| 6911 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 6912 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 6913 | phys_disk_num))) { |
| 6914 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6915 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 1c50e8d | 2013-07-25 11:29:45 +0530 | [diff] [blame] | 6916 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6917 | break; |
| 6918 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 6919 | handle = le16_to_cpu(pd_pg0.DevHandle); |
| 6920 | set_bit(handle, ioc->pd_handles); |
| 6921 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6922 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6923 | out: |
| 6924 | printk(MPT2SAS_INFO_FMT "search for responding raid volumes: " |
| 6925 | "complete\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6926 | } |
| 6927 | |
| 6928 | /** |
| 6929 | * _scsih_mark_responding_expander - mark a expander as responding |
| 6930 | * @ioc: per adapter object |
| 6931 | * @sas_address: sas address |
| 6932 | * @handle: |
| 6933 | * |
| 6934 | * After host reset, find out whether devices are still responding. |
| 6935 | * Used in _scsi_remove_unresponsive_expanders. |
| 6936 | * |
| 6937 | * Return nothing. |
| 6938 | */ |
| 6939 | static void |
| 6940 | _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 6941 | u16 handle) |
| 6942 | { |
| 6943 | struct _sas_node *sas_expander; |
| 6944 | unsigned long flags; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6945 | int i; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6946 | |
| 6947 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 6948 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6949 | if (sas_expander->sas_address != sas_address) |
| 6950 | continue; |
| 6951 | sas_expander->responding = 1; |
| 6952 | if (sas_expander->handle == handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6953 | goto out; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6954 | printk(KERN_INFO "\texpander(0x%016llx): handle changed" |
| 6955 | " from(0x%04x) to (0x%04x)!!!\n", |
| 6956 | (unsigned long long)sas_expander->sas_address, |
| 6957 | sas_expander->handle, handle); |
| 6958 | sas_expander->handle = handle; |
| 6959 | for (i = 0 ; i < sas_expander->num_phys ; i++) |
| 6960 | sas_expander->phy[i].handle = handle; |
| 6961 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6962 | } |
| 6963 | out: |
| 6964 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 6965 | } |
| 6966 | |
| 6967 | /** |
| 6968 | * _scsih_search_responding_expanders - |
| 6969 | * @ioc: per adapter object |
| 6970 | * |
| 6971 | * After host reset, find out whether devices are still responding. |
| 6972 | * If not remove. |
| 6973 | * |
| 6974 | * Return nothing. |
| 6975 | */ |
| 6976 | static void |
| 6977 | _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc) |
| 6978 | { |
| 6979 | Mpi2ExpanderPage0_t expander_pg0; |
| 6980 | Mpi2ConfigReply_t mpi_reply; |
| 6981 | u16 ioc_status; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 6982 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6983 | u16 handle; |
| 6984 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6985 | printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6986 | |
| 6987 | if (list_empty(&ioc->sas_expander_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6988 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6989 | |
| 6990 | handle = 0xFFFF; |
| 6991 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 6992 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 6993 | |
| 6994 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6995 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 1c50e8d | 2013-07-25 11:29:45 +0530 | [diff] [blame] | 6996 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6997 | break; |
| 6998 | |
| 6999 | handle = le16_to_cpu(expander_pg0.DevHandle); |
| 7000 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
| 7001 | printk(KERN_INFO "\texpander present: handle(0x%04x), " |
| 7002 | "sas_addr(0x%016llx)\n", handle, |
| 7003 | (unsigned long long)sas_address); |
| 7004 | _scsih_mark_responding_expander(ioc, sas_address, handle); |
| 7005 | } |
| 7006 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7007 | out: |
| 7008 | printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7009 | } |
| 7010 | |
| 7011 | /** |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7012 | * _scsih_remove_unresponding_sas_devices - removing unresponding devices |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7013 | * @ioc: per adapter object |
| 7014 | * |
| 7015 | * Return nothing. |
| 7016 | */ |
| 7017 | static void |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7018 | _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7019 | { |
| 7020 | struct _sas_device *sas_device, *sas_device_next; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7021 | struct _sas_node *sas_expander, *sas_expander_next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7022 | struct _raid_device *raid_device, *raid_device_next; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7023 | struct list_head tmp_list; |
| 7024 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7025 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7026 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n", |
| 7027 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7028 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7029 | /* removing unresponding end devices */ |
| 7030 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n", |
| 7031 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7032 | list_for_each_entry_safe(sas_device, sas_device_next, |
| 7033 | &ioc->sas_device_list, list) { |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7034 | if (!sas_device->responding) |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 7035 | mpt2sas_device_remove_by_sas_address(ioc, |
| 7036 | sas_device->sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7037 | else |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7038 | sas_device->responding = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7039 | } |
| 7040 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7041 | /* removing unresponding volumes */ |
| 7042 | if (ioc->ir_firmware) { |
| 7043 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: " |
| 7044 | "volumes\n", ioc->name); |
| 7045 | list_for_each_entry_safe(raid_device, raid_device_next, |
| 7046 | &ioc->raid_device_list, list) { |
| 7047 | if (!raid_device->responding) |
| 7048 | _scsih_sas_volume_delete(ioc, |
| 7049 | raid_device->handle); |
| 7050 | else |
| 7051 | raid_device->responding = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7052 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7053 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7054 | /* removing unresponding expanders */ |
| 7055 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n", |
| 7056 | ioc->name); |
| 7057 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 7058 | INIT_LIST_HEAD(&tmp_list); |
| 7059 | list_for_each_entry_safe(sas_expander, sas_expander_next, |
| 7060 | &ioc->sas_expander_list, list) { |
| 7061 | if (!sas_expander->responding) |
| 7062 | list_move_tail(&sas_expander->list, &tmp_list); |
| 7063 | else |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7064 | sas_expander->responding = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7065 | } |
| 7066 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 7067 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, |
| 7068 | list) { |
| 7069 | list_del(&sas_expander->list); |
| 7070 | _scsih_expander_node_remove(ioc, sas_expander); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7071 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7072 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n", |
| 7073 | ioc->name); |
| 7074 | /* unblock devices */ |
| 7075 | _scsih_ublock_io_all_device(ioc); |
| 7076 | } |
| 7077 | |
| 7078 | static void |
| 7079 | _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc, |
| 7080 | struct _sas_node *sas_expander, u16 handle) |
| 7081 | { |
| 7082 | Mpi2ExpanderPage1_t expander_pg1; |
| 7083 | Mpi2ConfigReply_t mpi_reply; |
| 7084 | int i; |
| 7085 | |
| 7086 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 7087 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 7088 | &expander_pg1, i, handle))) { |
| 7089 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7090 | ioc->name, __FILE__, __LINE__, __func__); |
| 7091 | return; |
| 7092 | } |
| 7093 | |
| 7094 | mpt2sas_transport_update_links(ioc, sas_expander->sas_address, |
| 7095 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, |
| 7096 | expander_pg1.NegotiatedLinkRate >> 4); |
| 7097 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7098 | } |
| 7099 | |
| 7100 | /** |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7101 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7102 | * @ioc: per adapter object |
| 7103 | * |
| 7104 | * Return nothing. |
| 7105 | */ |
| 7106 | static void |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7107 | _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc) |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7108 | { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7109 | Mpi2ExpanderPage0_t expander_pg0; |
| 7110 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 7111 | Mpi2RaidVolPage1_t volume_pg1; |
| 7112 | Mpi2RaidVolPage0_t volume_pg0; |
| 7113 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 7114 | Mpi2EventIrConfigElement_t element; |
| 7115 | Mpi2ConfigReply_t mpi_reply; |
| 7116 | u8 phys_disk_num; |
| 7117 | u16 ioc_status; |
| 7118 | u16 handle, parent_handle; |
| 7119 | u64 sas_address; |
| 7120 | struct _sas_device *sas_device; |
| 7121 | struct _sas_node *expander_device; |
| 7122 | static struct _raid_device *raid_device; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7123 | u8 retry_count; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7124 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7125 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7126 | printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7127 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7128 | _scsih_sas_host_refresh(ioc); |
| 7129 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7130 | printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n", |
| 7131 | ioc->name); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7132 | /* expanders */ |
| 7133 | handle = 0xFFFF; |
| 7134 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 7135 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 7136 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7137 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7138 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7139 | printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: " |
| 7140 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7141 | ioc->name, ioc_status, |
| 7142 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7143 | break; |
| 7144 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7145 | handle = le16_to_cpu(expander_pg0.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7146 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7147 | expander_device = mpt2sas_scsih_expander_find_by_sas_address( |
| 7148 | ioc, le64_to_cpu(expander_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7149 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7150 | if (expander_device) |
| 7151 | _scsih_refresh_expander_links(ioc, expander_device, |
| 7152 | handle); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7153 | else { |
| 7154 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: " |
| 7155 | "handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7156 | ioc->name, handle, (unsigned long long) |
| 7157 | le64_to_cpu(expander_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7158 | _scsih_expander_add(ioc, handle); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7159 | printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: " |
| 7160 | "handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7161 | ioc->name, handle, (unsigned long long) |
| 7162 | le64_to_cpu(expander_pg0.SASAddress)); |
| 7163 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7164 | } |
| 7165 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7166 | printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n", |
| 7167 | ioc->name); |
| 7168 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7169 | if (!ioc->ir_firmware) |
| 7170 | goto skip_to_sas; |
| 7171 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7172 | 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] | 7173 | /* phys disk */ |
| 7174 | phys_disk_num = 0xFF; |
| 7175 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 7176 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 7177 | phys_disk_num))) { |
| 7178 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7179 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7180 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7181 | printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:" |
| 7182 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7183 | ioc->name, ioc_status, |
| 7184 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7185 | break; |
| 7186 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7187 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 7188 | handle = le16_to_cpu(pd_pg0.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7189 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7190 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7191 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7192 | if (sas_device) |
| 7193 | continue; |
| 7194 | if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 7195 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 7196 | handle) != 0) |
| 7197 | continue; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7198 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7199 | MPI2_IOCSTATUS_MASK; |
| 7200 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7201 | printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan " |
| 7202 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7203 | ioc->name, ioc_status, |
| 7204 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7205 | break; |
| 7206 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7207 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 7208 | if (!_scsih_get_sas_address(ioc, parent_handle, |
| 7209 | &sas_address)) { |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7210 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: " |
| 7211 | " handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7212 | ioc->name, handle, (unsigned long long) |
| 7213 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7214 | mpt2sas_transport_update_links(ioc, sas_address, |
| 7215 | handle, sas_device_pg0.PhyNum, |
| 7216 | MPI2_SAS_NEG_LINK_RATE_1_5); |
| 7217 | set_bit(handle, ioc->pd_handles); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7218 | retry_count = 0; |
| 7219 | /* This will retry adding the end device. |
| 7220 | * _scsih_add_device() will decide on retries and |
| 7221 | * return "1" when it should be retried |
| 7222 | */ |
| 7223 | while (_scsih_add_device(ioc, handle, retry_count++, |
| 7224 | 1)) { |
| 7225 | ssleep(1); |
| 7226 | } |
| 7227 | printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: " |
| 7228 | " handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7229 | ioc->name, handle, (unsigned long long) |
| 7230 | le64_to_cpu(sas_device_pg0.SASAddress)); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7231 | } |
| 7232 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7233 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7234 | printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n", |
| 7235 | ioc->name); |
| 7236 | |
| 7237 | 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] | 7238 | /* volumes */ |
| 7239 | handle = 0xFFFF; |
| 7240 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 7241 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 7242 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7243 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7244 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7245 | printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: " |
| 7246 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7247 | ioc->name, ioc_status, |
| 7248 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7249 | break; |
| 7250 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7251 | handle = le16_to_cpu(volume_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7252 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7253 | raid_device = _scsih_raid_device_find_by_wwid(ioc, |
| 7254 | le64_to_cpu(volume_pg1.WWID)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7255 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7256 | if (raid_device) |
| 7257 | continue; |
| 7258 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 7259 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 7260 | sizeof(Mpi2RaidVolPage0_t))) |
| 7261 | continue; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7262 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7263 | MPI2_IOCSTATUS_MASK; |
| 7264 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7265 | printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: " |
| 7266 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7267 | ioc->name, ioc_status, |
| 7268 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7269 | break; |
| 7270 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7271 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 7272 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 7273 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { |
| 7274 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); |
| 7275 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; |
| 7276 | element.VolDevHandle = volume_pg1.DevHandle; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7277 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: " |
| 7278 | " handle (0x%04x)\n", ioc->name, |
| 7279 | volume_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7280 | _scsih_sas_volume_add(ioc, &element); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7281 | printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: " |
| 7282 | " handle (0x%04x)\n", ioc->name, |
| 7283 | volume_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7284 | } |
| 7285 | } |
| 7286 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7287 | printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n", |
| 7288 | ioc->name); |
| 7289 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7290 | skip_to_sas: |
| 7291 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7292 | printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n", |
| 7293 | ioc->name); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7294 | /* sas devices */ |
| 7295 | handle = 0xFFFF; |
| 7296 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 7297 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 7298 | handle))) { |
| 7299 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7300 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7301 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7302 | printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:" |
| 7303 | " ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7304 | ioc->name, ioc_status, |
| 7305 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7306 | break; |
| 7307 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7308 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 7309 | if (!(_scsih_is_end_device( |
| 7310 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) |
| 7311 | continue; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7312 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7313 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 7314 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7315 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7316 | if (sas_device) |
| 7317 | continue; |
| 7318 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 7319 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7320 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: " |
| 7321 | "handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7322 | ioc->name, handle, (unsigned long long) |
| 7323 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7324 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 7325 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7326 | retry_count = 0; |
| 7327 | /* This will retry adding the end device. |
| 7328 | * _scsih_add_device() will decide on retries and |
| 7329 | * return "1" when it should be retried |
| 7330 | */ |
| 7331 | while (_scsih_add_device(ioc, handle, retry_count++, |
| 7332 | 0)) { |
| 7333 | ssleep(1); |
| 7334 | } |
| 7335 | printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: " |
| 7336 | "handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7337 | ioc->name, handle, (unsigned long long) |
| 7338 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7339 | } |
| 7340 | } |
| 7341 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7342 | printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n", |
| 7343 | ioc->name); |
| 7344 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7345 | printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7346 | } |
| 7347 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7348 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7349 | /** |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7350 | * mpt2sas_scsih_reset_handler - reset callback handler (for scsih) |
| 7351 | * @ioc: per adapter object |
| 7352 | * @reset_phase: phase |
| 7353 | * |
| 7354 | * The handler for doing any required cleanup or initialization. |
| 7355 | * |
| 7356 | * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET, |
| 7357 | * MPT2_IOC_DONE_RESET |
| 7358 | * |
| 7359 | * Return nothing. |
| 7360 | */ |
| 7361 | void |
| 7362 | mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase) |
| 7363 | { |
| 7364 | switch (reset_phase) { |
| 7365 | case MPT2_IOC_PRE_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7366 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7367 | "MPT2_IOC_PRE_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7368 | break; |
| 7369 | case MPT2_IOC_AFTER_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7370 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7371 | "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7372 | if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) { |
| 7373 | ioc->scsih_cmds.status |= MPT2_CMD_RESET; |
| 7374 | mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid); |
| 7375 | complete(&ioc->scsih_cmds.done); |
| 7376 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7377 | if (ioc->tm_cmds.status & MPT2_CMD_PENDING) { |
| 7378 | ioc->tm_cmds.status |= MPT2_CMD_RESET; |
| 7379 | mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid); |
| 7380 | complete(&ioc->tm_cmds.done); |
| 7381 | } |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7382 | _scsih_fw_event_cleanup_queue(ioc); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7383 | _scsih_flush_running_cmds(ioc); |
| 7384 | break; |
| 7385 | case MPT2_IOC_DONE_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7386 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7387 | "MPT2_IOC_DONE_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7388 | _scsih_sas_host_refresh(ioc); |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 7389 | _scsih_prep_device_scan(ioc); |
| 7390 | _scsih_search_responding_sas_devices(ioc); |
| 7391 | _scsih_search_responding_raid_devices(ioc); |
| 7392 | _scsih_search_responding_expanders(ioc); |
sreekanth.reddy@lsi.com | 14aa7f7 | 2012-07-17 15:56:13 +0530 | [diff] [blame] | 7393 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && |
| 7394 | !ioc->sas_hba.num_phys)) { |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7395 | _scsih_prep_device_scan(ioc); |
| 7396 | _scsih_search_responding_sas_devices(ioc); |
| 7397 | _scsih_search_responding_raid_devices(ioc); |
| 7398 | _scsih_search_responding_expanders(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7399 | _scsih_error_recovery_delete_devices(ioc); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7400 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7401 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7402 | } |
| 7403 | } |
| 7404 | |
| 7405 | /** |
| 7406 | * _firmware_event_work - delayed task for processing firmware events |
| 7407 | * @ioc: per adapter object |
| 7408 | * @work: equal to the fw_event_work object |
| 7409 | * Context: user. |
| 7410 | * |
| 7411 | * Return nothing. |
| 7412 | */ |
| 7413 | static void |
| 7414 | _firmware_event_work(struct work_struct *work) |
| 7415 | { |
| 7416 | struct fw_event_work *fw_event = container_of(work, |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7417 | struct fw_event_work, delayed_work.work); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7418 | struct MPT2SAS_ADAPTER *ioc = fw_event->ioc; |
| 7419 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7420 | /* the queue is being flushed so ignore this event */ |
Reddy, Sreekanth | 02b7708 | 2014-07-14 12:00:49 +0530 | [diff] [blame^] | 7421 | if (ioc->remove_host || |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7422 | ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7423 | _scsih_fw_event_free(ioc, fw_event); |
| 7424 | return; |
| 7425 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7426 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7427 | switch (fw_event->event) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7428 | case MPT2SAS_REMOVE_UNRESPONDING_DEVICES: |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7429 | while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7430 | ssleep(1); |
| 7431 | _scsih_remove_unresponding_sas_devices(ioc); |
| 7432 | _scsih_scan_for_devices_after_reset(ioc); |
| 7433 | break; |
| 7434 | case MPT2SAS_PORT_ENABLE_COMPLETE: |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7435 | ioc->start_scan = 0; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7436 | |
Reddy, Sreekanth | b0df96a0 | 2013-02-26 16:59:59 +0530 | [diff] [blame] | 7437 | if (missing_delay[0] != -1 && missing_delay[1] != -1) |
| 7438 | mpt2sas_base_update_missing_delay(ioc, missing_delay[0], |
| 7439 | missing_delay[1]); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7440 | |
| 7441 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete " |
| 7442 | "from worker thread\n", ioc->name)); |
| 7443 | break; |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 7444 | case MPT2SAS_TURN_ON_FAULT_LED: |
| 7445 | _scsih_turn_on_fault_led(ioc, fw_event->device_handle); |
| 7446 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7447 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7448 | _scsih_sas_topology_change_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7449 | break; |
| 7450 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7451 | _scsih_sas_device_status_change_event(ioc, |
| 7452 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7453 | break; |
| 7454 | case MPI2_EVENT_SAS_DISCOVERY: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7455 | _scsih_sas_discovery_event(ioc, |
| 7456 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7457 | break; |
| 7458 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 7459 | _scsih_sas_broadcast_primitive_event(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7460 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7461 | break; |
| 7462 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
| 7463 | _scsih_sas_enclosure_dev_status_change_event(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7464 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7465 | break; |
| 7466 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7467 | _scsih_sas_ir_config_change_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7468 | break; |
| 7469 | case MPI2_EVENT_IR_VOLUME: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7470 | _scsih_sas_ir_volume_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7471 | break; |
| 7472 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7473 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7474 | break; |
| 7475 | case MPI2_EVENT_IR_OPERATION_STATUS: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7476 | _scsih_sas_ir_operation_status_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7477 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7478 | } |
| 7479 | _scsih_fw_event_free(ioc, fw_event); |
| 7480 | } |
| 7481 | |
| 7482 | /** |
| 7483 | * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time) |
| 7484 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7485 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7486 | * @reply: reply message frame(lower 32bit addr) |
| 7487 | * Context: interrupt. |
| 7488 | * |
| 7489 | * This function merely adds a new work task into ioc->firmware_event_thread. |
| 7490 | * The tasks are worked from _firmware_event_work in user context. |
| 7491 | * |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7492 | * Returns void. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7493 | */ |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7494 | void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7495 | mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, |
| 7496 | u32 reply) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7497 | { |
| 7498 | struct fw_event_work *fw_event; |
| 7499 | Mpi2EventNotificationReply_t *mpi_reply; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7500 | u16 event; |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 7501 | u16 sz; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7502 | |
| 7503 | /* events turned off due to host reset or driver unloading */ |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7504 | if (ioc->remove_host || ioc->pci_error_recovery) |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7505 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7506 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7507 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 7508 | |
| 7509 | if (unlikely(!mpi_reply)) { |
| 7510 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 7511 | ioc->name, __FILE__, __LINE__, __func__); |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7512 | return; |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 7513 | } |
| 7514 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7515 | event = le16_to_cpu(mpi_reply->Event); |
| 7516 | |
| 7517 | switch (event) { |
| 7518 | /* handle these */ |
| 7519 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 7520 | { |
| 7521 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = |
| 7522 | (Mpi2EventDataSasBroadcastPrimitive_t *) |
| 7523 | mpi_reply->EventData; |
| 7524 | |
| 7525 | if (baen_data->Primitive != |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7526 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7527 | return; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7528 | |
| 7529 | if (ioc->broadcast_aen_busy) { |
| 7530 | ioc->broadcast_aen_pending++; |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7531 | return; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7532 | } else |
| 7533 | ioc->broadcast_aen_busy = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7534 | break; |
| 7535 | } |
| 7536 | |
| 7537 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
| 7538 | _scsih_check_topo_delete_events(ioc, |
| 7539 | (Mpi2EventDataSasTopologyChangeList_t *) |
| 7540 | mpi_reply->EventData); |
| 7541 | break; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 7542 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
| 7543 | _scsih_check_ir_config_unhide_events(ioc, |
| 7544 | (Mpi2EventDataIrConfigChangeList_t *) |
| 7545 | mpi_reply->EventData); |
| 7546 | break; |
| 7547 | case MPI2_EVENT_IR_VOLUME: |
| 7548 | _scsih_check_volume_delete_events(ioc, |
| 7549 | (Mpi2EventDataIrVolume_t *) |
| 7550 | mpi_reply->EventData); |
| 7551 | break; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7552 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
| 7553 | { |
| 7554 | Mpi2EventDataLogEntryAdded_t *log_entry; |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 7555 | __le32 *log_code; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7556 | |
| 7557 | if (!ioc->is_warpdrive) |
| 7558 | break; |
| 7559 | |
| 7560 | log_entry = (Mpi2EventDataLogEntryAdded_t *) |
| 7561 | mpi_reply->EventData; |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 7562 | log_code = (__le32 *)log_entry->LogData; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7563 | |
| 7564 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
| 7565 | != MPT2_WARPDRIVE_LOGENTRY) |
| 7566 | break; |
| 7567 | |
| 7568 | switch (le32_to_cpu(*log_code)) { |
| 7569 | case MPT2_WARPDRIVE_LC_SSDT: |
| 7570 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " |
| 7571 | "IO Throttling has occurred in the WarpDrive " |
| 7572 | "subsystem. Check WarpDrive documentation for " |
| 7573 | "additional details.\n", ioc->name); |
| 7574 | break; |
| 7575 | case MPT2_WARPDRIVE_LC_SSDLW: |
| 7576 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " |
| 7577 | "Program/Erase Cycles for the WarpDrive subsystem " |
| 7578 | "in degraded range. Check WarpDrive documentation " |
| 7579 | "for additional details.\n", ioc->name); |
| 7580 | break; |
| 7581 | case MPT2_WARPDRIVE_LC_SSDLF: |
| 7582 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " |
| 7583 | "There are no Program/Erase Cycles for the " |
| 7584 | "WarpDrive subsystem. The storage device will be " |
| 7585 | "in read-only mode. Check WarpDrive documentation " |
| 7586 | "for additional details.\n", ioc->name); |
| 7587 | break; |
| 7588 | case MPT2_WARPDRIVE_LC_BRMF: |
| 7589 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " |
| 7590 | "The Backup Rail Monitor has failed on the " |
| 7591 | "WarpDrive subsystem. Check WarpDrive " |
| 7592 | "documentation for additional details.\n", |
| 7593 | ioc->name); |
| 7594 | break; |
| 7595 | } |
| 7596 | |
| 7597 | break; |
| 7598 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7599 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 7600 | case MPI2_EVENT_IR_OPERATION_STATUS: |
| 7601 | case MPI2_EVENT_SAS_DISCOVERY: |
| 7602 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7603 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7604 | break; |
| 7605 | |
| 7606 | default: /* ignore the rest */ |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7607 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7608 | } |
| 7609 | |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 7610 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
| 7611 | fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7612 | if (!fw_event) { |
| 7613 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7614 | ioc->name, __FILE__, __LINE__, __func__); |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7615 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7616 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7617 | |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 7618 | memcpy(fw_event->event_data, mpi_reply->EventData, sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7619 | fw_event->ioc = ioc; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7620 | fw_event->VF_ID = mpi_reply->VF_ID; |
| 7621 | fw_event->VP_ID = mpi_reply->VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7622 | fw_event->event = event; |
| 7623 | _scsih_fw_event_add(ioc, fw_event); |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7624 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7625 | } |
| 7626 | |
| 7627 | /* shost template */ |
| 7628 | static struct scsi_host_template scsih_driver_template = { |
| 7629 | .module = THIS_MODULE, |
| 7630 | .name = "Fusion MPT SAS Host", |
| 7631 | .proc_name = MPT2SAS_DRIVER_NAME, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7632 | .queuecommand = _scsih_qcmd, |
| 7633 | .target_alloc = _scsih_target_alloc, |
| 7634 | .slave_alloc = _scsih_slave_alloc, |
| 7635 | .slave_configure = _scsih_slave_configure, |
| 7636 | .target_destroy = _scsih_target_destroy, |
| 7637 | .slave_destroy = _scsih_slave_destroy, |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7638 | .scan_finished = _scsih_scan_finished, |
| 7639 | .scan_start = _scsih_scan_start, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7640 | .change_queue_depth = _scsih_change_queue_depth, |
| 7641 | .change_queue_type = _scsih_change_queue_type, |
| 7642 | .eh_abort_handler = _scsih_abort, |
| 7643 | .eh_device_reset_handler = _scsih_dev_reset, |
| 7644 | .eh_target_reset_handler = _scsih_target_reset, |
| 7645 | .eh_host_reset_handler = _scsih_host_reset, |
| 7646 | .bios_param = _scsih_bios_param, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7647 | .can_queue = 1, |
| 7648 | .this_id = -1, |
| 7649 | .sg_tablesize = MPT2SAS_SG_DEPTH, |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 7650 | .max_sectors = 32767, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7651 | .cmd_per_lun = 7, |
| 7652 | .use_clustering = ENABLE_CLUSTERING, |
| 7653 | .shost_attrs = mpt2sas_host_attrs, |
| 7654 | .sdev_attrs = mpt2sas_dev_attrs, |
| 7655 | }; |
| 7656 | |
| 7657 | /** |
| 7658 | * _scsih_expander_node_remove - removing expander device from list. |
| 7659 | * @ioc: per adapter object |
| 7660 | * @sas_expander: the sas_device object |
| 7661 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 7662 | * |
| 7663 | * Removing object and freeing associated memory from the |
| 7664 | * ioc->sas_expander_list. |
| 7665 | * |
| 7666 | * Return nothing. |
| 7667 | */ |
| 7668 | static void |
| 7669 | _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc, |
| 7670 | struct _sas_node *sas_expander) |
| 7671 | { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7672 | struct _sas_port *mpt2sas_port, *next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7673 | |
| 7674 | /* remove sibling ports attached to this expander */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7675 | list_for_each_entry_safe(mpt2sas_port, next, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7676 | &sas_expander->sas_port_list, port_list) { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7677 | if (ioc->shost_recovery) |
| 7678 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7679 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7680 | SAS_END_DEVICE) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7681 | mpt2sas_device_remove_by_sas_address(ioc, |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7682 | mpt2sas_port->remote_identify.sas_address); |
| 7683 | else if (mpt2sas_port->remote_identify.device_type == |
| 7684 | SAS_EDGE_EXPANDER_DEVICE || |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7685 | mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7686 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7687 | mpt2sas_expander_remove(ioc, |
| 7688 | mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7689 | } |
| 7690 | |
| 7691 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7692 | sas_expander->sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7693 | |
| 7694 | printk(MPT2SAS_INFO_FMT "expander_remove: handle" |
| 7695 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, |
| 7696 | sas_expander->handle, (unsigned long long) |
| 7697 | sas_expander->sas_address); |
| 7698 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7699 | kfree(sas_expander->phy); |
| 7700 | kfree(sas_expander); |
| 7701 | } |
| 7702 | |
| 7703 | /** |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7704 | * _scsih_ir_shutdown - IR shutdown notification |
| 7705 | * @ioc: per adapter object |
| 7706 | * |
| 7707 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that |
| 7708 | * the host system is shutting down. |
| 7709 | * |
| 7710 | * Return nothing. |
| 7711 | */ |
| 7712 | static void |
| 7713 | _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc) |
| 7714 | { |
| 7715 | Mpi2RaidActionRequest_t *mpi_request; |
| 7716 | Mpi2RaidActionReply_t *mpi_reply; |
| 7717 | u16 smid; |
| 7718 | |
| 7719 | /* is IR firmware build loaded ? */ |
| 7720 | if (!ioc->ir_firmware) |
| 7721 | return; |
| 7722 | |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7723 | mutex_lock(&ioc->scsih_cmds.mutex); |
| 7724 | |
| 7725 | if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) { |
| 7726 | printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n", |
| 7727 | ioc->name, __func__); |
| 7728 | goto out; |
| 7729 | } |
| 7730 | ioc->scsih_cmds.status = MPT2_CMD_PENDING; |
| 7731 | |
| 7732 | smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx); |
| 7733 | if (!smid) { |
| 7734 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 7735 | ioc->name, __func__); |
| 7736 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; |
| 7737 | goto out; |
| 7738 | } |
| 7739 | |
| 7740 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 7741 | ioc->scsih_cmds.smid = smid; |
| 7742 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); |
| 7743 | |
| 7744 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; |
| 7745 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; |
| 7746 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7747 | if (!ioc->hide_ir_msg) |
| 7748 | printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7749 | init_completion(&ioc->scsih_cmds.done); |
| 7750 | mpt2sas_base_put_smid_default(ioc, smid); |
| 7751 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
| 7752 | |
| 7753 | if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) { |
| 7754 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 7755 | ioc->name, __func__); |
| 7756 | goto out; |
| 7757 | } |
| 7758 | |
| 7759 | if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 7760 | mpi_reply = ioc->scsih_cmds.reply; |
| 7761 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7762 | if (!ioc->hide_ir_msg) |
| 7763 | printk(MPT2SAS_INFO_FMT "IR shutdown (complete): " |
| 7764 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7765 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 7766 | le32_to_cpu(mpi_reply->IOCLogInfo)); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7767 | } |
| 7768 | |
| 7769 | out: |
| 7770 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; |
| 7771 | mutex_unlock(&ioc->scsih_cmds.mutex); |
| 7772 | } |
| 7773 | |
| 7774 | /** |
| 7775 | * _scsih_shutdown - routine call during system shutdown |
| 7776 | * @pdev: PCI device struct |
| 7777 | * |
| 7778 | * Return nothing. |
| 7779 | */ |
| 7780 | static void |
| 7781 | _scsih_shutdown(struct pci_dev *pdev) |
| 7782 | { |
| 7783 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7784 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7785 | struct workqueue_struct *wq; |
| 7786 | unsigned long flags; |
| 7787 | |
| 7788 | ioc->remove_host = 1; |
| 7789 | _scsih_fw_event_cleanup_queue(ioc); |
| 7790 | |
| 7791 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7792 | wq = ioc->firmware_event_thread; |
| 7793 | ioc->firmware_event_thread = NULL; |
| 7794 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7795 | if (wq) |
| 7796 | destroy_workqueue(wq); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7797 | |
| 7798 | _scsih_ir_shutdown(ioc); |
| 7799 | mpt2sas_base_detach(ioc); |
| 7800 | } |
| 7801 | |
| 7802 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7803 | * _scsih_remove - detach and remove add host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7804 | * @pdev: PCI device struct |
| 7805 | * |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7806 | * Routine called when unloading the driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7807 | * Return nothing. |
| 7808 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7809 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7810 | _scsih_remove(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7811 | { |
| 7812 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7813 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7814 | struct _sas_port *mpt2sas_port, *next_port; |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7815 | struct _raid_device *raid_device, *next; |
| 7816 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7817 | struct workqueue_struct *wq; |
| 7818 | unsigned long flags; |
| 7819 | |
| 7820 | ioc->remove_host = 1; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7821 | _scsih_fw_event_cleanup_queue(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7822 | |
| 7823 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7824 | wq = ioc->firmware_event_thread; |
| 7825 | ioc->firmware_event_thread = NULL; |
| 7826 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7827 | if (wq) |
| 7828 | destroy_workqueue(wq); |
| 7829 | |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7830 | /* release all the volumes */ |
Kashyap, Desai | 3a9c913 | 2011-01-04 11:40:23 +0530 | [diff] [blame] | 7831 | _scsih_ir_shutdown(ioc); |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7832 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, |
| 7833 | list) { |
| 7834 | if (raid_device->starget) { |
| 7835 | sas_target_priv_data = |
| 7836 | raid_device->starget->hostdata; |
| 7837 | sas_target_priv_data->deleted = 1; |
| 7838 | scsi_remove_target(&raid_device->starget->dev); |
| 7839 | } |
| 7840 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" |
| 7841 | "(0x%016llx)\n", ioc->name, raid_device->handle, |
| 7842 | (unsigned long long) raid_device->wwid); |
| 7843 | _scsih_raid_device_remove(ioc, raid_device); |
| 7844 | } |
| 7845 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7846 | /* free ports attached to the sas_host */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7847 | list_for_each_entry_safe(mpt2sas_port, next_port, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7848 | &ioc->sas_hba.sas_port_list, port_list) { |
| 7849 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7850 | SAS_END_DEVICE) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7851 | mpt2sas_device_remove_by_sas_address(ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7852 | mpt2sas_port->remote_identify.sas_address); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7853 | else if (mpt2sas_port->remote_identify.device_type == |
| 7854 | SAS_EDGE_EXPANDER_DEVICE || |
| 7855 | mpt2sas_port->remote_identify.device_type == |
| 7856 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7857 | mpt2sas_expander_remove(ioc, |
| 7858 | mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7859 | } |
| 7860 | |
| 7861 | /* free phys attached to the sas_host */ |
| 7862 | if (ioc->sas_hba.num_phys) { |
| 7863 | kfree(ioc->sas_hba.phy); |
| 7864 | ioc->sas_hba.phy = NULL; |
| 7865 | ioc->sas_hba.num_phys = 0; |
| 7866 | } |
| 7867 | |
| 7868 | sas_remove_host(shost); |
Reddy, Sreekanth | 02b7708 | 2014-07-14 12:00:49 +0530 | [diff] [blame^] | 7869 | scsi_remove_host(shost); |
kashyap.desai@lsi.com | 9ae89b0 | 2011-08-04 16:47:50 +0530 | [diff] [blame] | 7870 | mpt2sas_base_detach(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7871 | list_del(&ioc->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7872 | scsi_host_put(shost); |
| 7873 | } |
| 7874 | |
| 7875 | /** |
| 7876 | * _scsih_probe_boot_devices - reports 1st device |
| 7877 | * @ioc: per adapter object |
| 7878 | * |
| 7879 | * If specified in bios page 2, this routine reports the 1st |
| 7880 | * device scsi-ml or sas transport for persistent boot device |
| 7881 | * purposes. Please refer to function _scsih_determine_boot_device() |
| 7882 | */ |
| 7883 | static void |
| 7884 | _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc) |
| 7885 | { |
| 7886 | u8 is_raid; |
| 7887 | void *device; |
| 7888 | struct _sas_device *sas_device; |
| 7889 | struct _raid_device *raid_device; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7890 | u16 handle; |
| 7891 | u64 sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7892 | u64 sas_address; |
| 7893 | unsigned long flags; |
| 7894 | int rc; |
| 7895 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7896 | /* no Bios, return immediately */ |
| 7897 | if (!ioc->bios_pg3.BiosVersion) |
| 7898 | return; |
| 7899 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7900 | device = NULL; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7901 | is_raid = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7902 | if (ioc->req_boot_device.device) { |
| 7903 | device = ioc->req_boot_device.device; |
| 7904 | is_raid = ioc->req_boot_device.is_raid; |
| 7905 | } else if (ioc->req_alt_boot_device.device) { |
| 7906 | device = ioc->req_alt_boot_device.device; |
| 7907 | is_raid = ioc->req_alt_boot_device.is_raid; |
| 7908 | } else if (ioc->current_boot_device.device) { |
| 7909 | device = ioc->current_boot_device.device; |
| 7910 | is_raid = ioc->current_boot_device.is_raid; |
| 7911 | } |
| 7912 | |
| 7913 | if (!device) |
| 7914 | return; |
| 7915 | |
| 7916 | if (is_raid) { |
| 7917 | raid_device = device; |
| 7918 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7919 | raid_device->id, 0); |
| 7920 | if (rc) |
| 7921 | _scsih_raid_device_remove(ioc, raid_device); |
| 7922 | } else { |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7923 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7924 | sas_device = device; |
| 7925 | handle = sas_device->handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7926 | sas_address_parent = sas_device->sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7927 | sas_address = sas_device->sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7928 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 7929 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7930 | |
| 7931 | if (ioc->hide_drives) |
| 7932 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7933 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7934 | sas_device->sas_address_parent)) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7935 | _scsih_sas_device_remove(ioc, sas_device); |
| 7936 | } else if (!sas_device->starget) { |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 7937 | if (!ioc->is_driver_loading) { |
| 7938 | mpt2sas_transport_port_remove(ioc, |
| 7939 | sas_address, |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 7940 | sas_address_parent); |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 7941 | _scsih_sas_device_remove(ioc, sas_device); |
| 7942 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7943 | } |
| 7944 | } |
| 7945 | } |
| 7946 | |
| 7947 | /** |
| 7948 | * _scsih_probe_raid - reporting raid volumes to scsi-ml |
| 7949 | * @ioc: per adapter object |
| 7950 | * |
| 7951 | * Called during initial loading of the driver. |
| 7952 | */ |
| 7953 | static void |
| 7954 | _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc) |
| 7955 | { |
| 7956 | struct _raid_device *raid_device, *raid_next; |
| 7957 | int rc; |
| 7958 | |
| 7959 | list_for_each_entry_safe(raid_device, raid_next, |
| 7960 | &ioc->raid_device_list, list) { |
| 7961 | if (raid_device->starget) |
| 7962 | continue; |
| 7963 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7964 | raid_device->id, 0); |
| 7965 | if (rc) |
| 7966 | _scsih_raid_device_remove(ioc, raid_device); |
| 7967 | } |
| 7968 | } |
| 7969 | |
| 7970 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7971 | * _scsih_probe_sas - reporting sas devices to sas transport |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7972 | * @ioc: per adapter object |
| 7973 | * |
| 7974 | * Called during initial loading of the driver. |
| 7975 | */ |
| 7976 | static void |
| 7977 | _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc) |
| 7978 | { |
| 7979 | struct _sas_device *sas_device, *next; |
| 7980 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7981 | |
| 7982 | /* SAS Device List */ |
| 7983 | list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list, |
| 7984 | list) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7985 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7986 | if (ioc->hide_drives) |
| 7987 | continue; |
| 7988 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7989 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
| 7990 | sas_device->sas_address_parent)) { |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 7991 | list_del(&sas_device->list); |
| 7992 | kfree(sas_device); |
| 7993 | continue; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7994 | } else if (!sas_device->starget) { |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 7995 | if (!ioc->is_driver_loading) { |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 7996 | mpt2sas_transport_port_remove(ioc, |
| 7997 | sas_device->sas_address, |
| 7998 | sas_device->sas_address_parent); |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 7999 | list_del(&sas_device->list); |
| 8000 | kfree(sas_device); |
| 8001 | continue; |
| 8002 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8003 | } |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 8004 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 8005 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 8006 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8007 | } |
| 8008 | } |
| 8009 | |
| 8010 | /** |
| 8011 | * _scsih_probe_devices - probing for devices |
| 8012 | * @ioc: per adapter object |
| 8013 | * |
| 8014 | * Called during initial loading of the driver. |
| 8015 | */ |
| 8016 | static void |
| 8017 | _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc) |
| 8018 | { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8019 | u16 volume_mapping_flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8020 | |
| 8021 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) |
| 8022 | return; /* return when IOC doesn't support initiator mode */ |
| 8023 | |
| 8024 | _scsih_probe_boot_devices(ioc); |
| 8025 | |
| 8026 | if (ioc->ir_firmware) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8027 | volume_mapping_flags = |
| 8028 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & |
| 8029 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; |
| 8030 | if (volume_mapping_flags == |
| 8031 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8032 | _scsih_probe_raid(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8033 | _scsih_probe_sas(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8034 | } else { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8035 | _scsih_probe_sas(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8036 | _scsih_probe_raid(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8037 | } |
| 8038 | } else |
| 8039 | _scsih_probe_sas(ioc); |
| 8040 | } |
| 8041 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8042 | |
| 8043 | /** |
| 8044 | * _scsih_scan_start - scsi lld callback for .scan_start |
| 8045 | * @shost: SCSI host pointer |
| 8046 | * |
| 8047 | * The shost has the ability to discover targets on its own instead |
| 8048 | * of scanning the entire bus. In our implemention, we will kick off |
| 8049 | * firmware discovery. |
| 8050 | */ |
| 8051 | static void |
| 8052 | _scsih_scan_start(struct Scsi_Host *shost) |
| 8053 | { |
| 8054 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8055 | int rc; |
| 8056 | |
| 8057 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) |
| 8058 | mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable); |
| 8059 | |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 8060 | if (disable_discovery > 0) |
| 8061 | return; |
| 8062 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8063 | ioc->start_scan = 1; |
| 8064 | rc = mpt2sas_port_enable(ioc); |
| 8065 | |
| 8066 | if (rc != 0) |
| 8067 | printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name); |
| 8068 | } |
| 8069 | |
| 8070 | /** |
| 8071 | * _scsih_scan_finished - scsi lld callback for .scan_finished |
| 8072 | * @shost: SCSI host pointer |
| 8073 | * @time: elapsed time of the scan in jiffies |
| 8074 | * |
| 8075 | * This function will be called periodically until it returns 1 with the |
| 8076 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, |
| 8077 | * we wait for firmware discovery to complete, then return 1. |
| 8078 | */ |
| 8079 | static int |
| 8080 | _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 8081 | { |
| 8082 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8083 | |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 8084 | if (disable_discovery > 0) { |
| 8085 | ioc->is_driver_loading = 0; |
| 8086 | ioc->wait_for_discovery_to_complete = 0; |
| 8087 | return 1; |
| 8088 | } |
| 8089 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8090 | if (time >= (300 * HZ)) { |
| 8091 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 8092 | printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout " |
| 8093 | "(timeout=300s)\n", ioc->name); |
| 8094 | ioc->is_driver_loading = 0; |
| 8095 | return 1; |
| 8096 | } |
| 8097 | |
| 8098 | if (ioc->start_scan) |
| 8099 | return 0; |
| 8100 | |
| 8101 | if (ioc->start_scan_failed) { |
| 8102 | printk(MPT2SAS_INFO_FMT "port enable: FAILED with " |
| 8103 | "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed); |
| 8104 | ioc->is_driver_loading = 0; |
| 8105 | ioc->wait_for_discovery_to_complete = 0; |
| 8106 | ioc->remove_host = 1; |
| 8107 | return 1; |
| 8108 | } |
| 8109 | |
| 8110 | printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name); |
| 8111 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 8112 | |
| 8113 | if (ioc->wait_for_discovery_to_complete) { |
| 8114 | ioc->wait_for_discovery_to_complete = 0; |
| 8115 | _scsih_probe_devices(ioc); |
| 8116 | } |
| 8117 | mpt2sas_base_start_watchdog(ioc); |
| 8118 | ioc->is_driver_loading = 0; |
| 8119 | return 1; |
| 8120 | } |
| 8121 | |
| 8122 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8123 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8124 | * _scsih_probe - attach and add scsi host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8125 | * @pdev: PCI device struct |
| 8126 | * @id: pci device id |
| 8127 | * |
| 8128 | * Returns 0 success, anything else error. |
| 8129 | */ |
| 8130 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8131 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8132 | { |
| 8133 | struct MPT2SAS_ADAPTER *ioc; |
| 8134 | struct Scsi_Host *shost; |
| 8135 | |
| 8136 | shost = scsi_host_alloc(&scsih_driver_template, |
| 8137 | sizeof(struct MPT2SAS_ADAPTER)); |
| 8138 | if (!shost) |
| 8139 | return -ENODEV; |
| 8140 | |
| 8141 | /* init local params */ |
| 8142 | ioc = shost_priv(shost); |
| 8143 | memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER)); |
| 8144 | INIT_LIST_HEAD(&ioc->list); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 8145 | list_add_tail(&ioc->list, &mpt2sas_ioc_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8146 | ioc->shost = shost; |
| 8147 | ioc->id = mpt_ids++; |
| 8148 | sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id); |
| 8149 | ioc->pdev = pdev; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8150 | if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) { |
| 8151 | ioc->is_warpdrive = 1; |
| 8152 | ioc->hide_ir_msg = 1; |
| 8153 | } else |
| 8154 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8155 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; |
| 8156 | ioc->tm_cb_idx = tm_cb_idx; |
| 8157 | ioc->ctl_cb_idx = ctl_cb_idx; |
| 8158 | ioc->base_cb_idx = base_cb_idx; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8159 | ioc->port_enable_cb_idx = port_enable_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8160 | ioc->transport_cb_idx = transport_cb_idx; |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8161 | ioc->scsih_cb_idx = scsih_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8162 | ioc->config_cb_idx = config_cb_idx; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8163 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8164 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8165 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8166 | ioc->logging_level = logging_level; |
nagalakshmi.nandigama@lsi.com | 845a0e4 | 2011-12-01 07:42:04 +0530 | [diff] [blame] | 8167 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8168 | /* misc semaphores and spin locks */ |
Kashyap, Desai | d274213 | 2010-06-17 13:28:55 +0530 | [diff] [blame] | 8169 | mutex_init(&ioc->reset_in_progress_mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8170 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
| 8171 | spin_lock_init(&ioc->scsi_lookup_lock); |
| 8172 | spin_lock_init(&ioc->sas_device_lock); |
| 8173 | spin_lock_init(&ioc->sas_node_lock); |
| 8174 | spin_lock_init(&ioc->fw_event_lock); |
| 8175 | spin_lock_init(&ioc->raid_device_lock); |
| 8176 | |
| 8177 | INIT_LIST_HEAD(&ioc->sas_device_list); |
| 8178 | INIT_LIST_HEAD(&ioc->sas_device_init_list); |
| 8179 | INIT_LIST_HEAD(&ioc->sas_expander_list); |
| 8180 | INIT_LIST_HEAD(&ioc->fw_event_list); |
| 8181 | INIT_LIST_HEAD(&ioc->raid_device_list); |
| 8182 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8183 | INIT_LIST_HEAD(&ioc->delayed_tr_list); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8184 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
Joe Lawrence | 3b3e6f8 | 2013-08-08 16:45:38 -0400 | [diff] [blame] | 8185 | INIT_LIST_HEAD(&ioc->reply_queue_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8186 | |
| 8187 | /* init shost parameters */ |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 8188 | shost->max_cmd_len = 32; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8189 | shost->max_lun = max_lun; |
| 8190 | shost->transportt = mpt2sas_transport_template; |
| 8191 | shost->unique_id = ioc->id; |
| 8192 | |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8193 | if (max_sectors != 0xFFFF) { |
| 8194 | if (max_sectors < 64) { |
| 8195 | shost->max_sectors = 64; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 8196 | printk(MPT2SAS_WARN_FMT "Invalid value %d passed " |
| 8197 | "for max_sectors, range is 64 to 32767. Assigning " |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8198 | "value of 64.\n", ioc->name, max_sectors); |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 8199 | } else if (max_sectors > 32767) { |
| 8200 | shost->max_sectors = 32767; |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8201 | printk(MPT2SAS_WARN_FMT "Invalid value %d passed " |
| 8202 | "for max_sectors, range is 64 to 8192. Assigning " |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 8203 | "default value of 32767.\n", ioc->name, |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8204 | max_sectors); |
| 8205 | } else { |
| 8206 | shost->max_sectors = max_sectors & 0xFFFE; |
| 8207 | printk(MPT2SAS_INFO_FMT "The max_sectors value is " |
| 8208 | "set to %d\n", ioc->name, shost->max_sectors); |
| 8209 | } |
| 8210 | } |
| 8211 | |
Martin K. Petersen | 5e95e73 | 2012-08-28 14:29:37 -0400 | [diff] [blame] | 8212 | /* register EEDP capabilities with SCSI layer */ |
| 8213 | if (prot_mask) |
| 8214 | scsi_host_set_prot(shost, prot_mask); |
| 8215 | else |
| 8216 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION |
| 8217 | | SHOST_DIF_TYPE2_PROTECTION |
| 8218 | | SHOST_DIF_TYPE3_PROTECTION); |
| 8219 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8220 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 8221 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8222 | /* event thread */ |
| 8223 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), |
| 8224 | "fw_event%d", ioc->id); |
| 8225 | ioc->firmware_event_thread = create_singlethread_workqueue( |
| 8226 | ioc->firmware_event_name); |
| 8227 | if (!ioc->firmware_event_thread) { |
| 8228 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8229 | ioc->name, __FILE__, __LINE__, __func__); |
| 8230 | goto out_thread_fail; |
| 8231 | } |
| 8232 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8233 | ioc->is_driver_loading = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8234 | if ((mpt2sas_base_attach(ioc))) { |
| 8235 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8236 | ioc->name, __FILE__, __LINE__, __func__); |
| 8237 | goto out_attach_fail; |
| 8238 | } |
| 8239 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8240 | if (ioc->is_warpdrive) { |
| 8241 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) |
| 8242 | ioc->hide_drives = 0; |
| 8243 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) |
| 8244 | ioc->hide_drives = 1; |
| 8245 | else { |
| 8246 | if (_scsih_get_num_volumes(ioc)) |
| 8247 | ioc->hide_drives = 1; |
| 8248 | else |
| 8249 | ioc->hide_drives = 0; |
| 8250 | } |
| 8251 | } else |
| 8252 | ioc->hide_drives = 0; |
Reddy, Sreekanth | 02b7708 | 2014-07-14 12:00:49 +0530 | [diff] [blame^] | 8253 | |
| 8254 | if ((scsi_add_host(shost, &pdev->dev))) { |
| 8255 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8256 | ioc->name, __FILE__, __LINE__, __func__); |
| 8257 | goto out_add_shost_fail; |
| 8258 | } |
| 8259 | |
nagalakshmi.nandigama@lsi.com | 2cb6fc8 | 2011-12-13 09:29:15 +0530 | [diff] [blame] | 8260 | scsi_scan_host(shost); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8261 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8262 | return 0; |
| 8263 | |
Reddy, Sreekanth | 02b7708 | 2014-07-14 12:00:49 +0530 | [diff] [blame^] | 8264 | out_add_shost_fail: |
| 8265 | mpt2sas_base_detach(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8266 | out_attach_fail: |
| 8267 | destroy_workqueue(ioc->firmware_event_thread); |
| 8268 | out_thread_fail: |
| 8269 | list_del(&ioc->list); |
Tomas Henzl | f555e05 | 2012-04-17 15:24:48 +0200 | [diff] [blame] | 8270 | scsi_host_put(shost); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8271 | return -ENODEV; |
| 8272 | } |
| 8273 | |
| 8274 | #ifdef CONFIG_PM |
| 8275 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8276 | * _scsih_suspend - power management suspend main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8277 | * @pdev: PCI device struct |
| 8278 | * @state: PM state change to (usually PCI_D3) |
| 8279 | * |
| 8280 | * Returns 0 success, anything else error. |
| 8281 | */ |
| 8282 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8283 | _scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8284 | { |
| 8285 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8286 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 8287 | pci_power_t device_state; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8288 | |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 8289 | mpt2sas_base_stop_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8290 | scsi_block_requests(shost); |
Sreekanth Reddy | 3627dba | 2013-07-25 11:25:57 +0530 | [diff] [blame] | 8291 | _scsih_ir_shutdown(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8292 | device_state = pci_choose_state(pdev, state); |
| 8293 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering " |
| 8294 | "operating state [D%d]\n", ioc->name, pdev, |
| 8295 | pci_name(pdev), device_state); |
| 8296 | |
| 8297 | mpt2sas_base_free_resources(ioc); |
| 8298 | pci_save_state(pdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8299 | pci_set_power_state(pdev, device_state); |
| 8300 | return 0; |
| 8301 | } |
| 8302 | |
| 8303 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8304 | * _scsih_resume - power management resume main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8305 | * @pdev: PCI device struct |
| 8306 | * |
| 8307 | * Returns 0 success, anything else error. |
| 8308 | */ |
| 8309 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8310 | _scsih_resume(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8311 | { |
| 8312 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8313 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 8314 | pci_power_t device_state = pdev->current_state; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8315 | int r; |
| 8316 | |
| 8317 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous " |
| 8318 | "operating state [D%d]\n", ioc->name, pdev, |
| 8319 | pci_name(pdev), device_state); |
| 8320 | |
| 8321 | pci_set_power_state(pdev, PCI_D0); |
| 8322 | pci_enable_wake(pdev, PCI_D0, 0); |
| 8323 | pci_restore_state(pdev); |
| 8324 | ioc->pdev = pdev; |
| 8325 | r = mpt2sas_base_map_resources(ioc); |
| 8326 | if (r) |
| 8327 | return r; |
| 8328 | |
| 8329 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET); |
| 8330 | scsi_unblock_requests(shost); |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 8331 | mpt2sas_base_start_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8332 | return 0; |
| 8333 | } |
| 8334 | #endif /* CONFIG_PM */ |
| 8335 | |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8336 | /** |
| 8337 | * _scsih_pci_error_detected - Called when a PCI error is detected. |
| 8338 | * @pdev: PCI device struct |
| 8339 | * @state: PCI channel state |
| 8340 | * |
| 8341 | * Description: Called when a PCI error is detected. |
| 8342 | * |
| 8343 | * Return value: |
| 8344 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT |
| 8345 | */ |
| 8346 | static pci_ers_result_t |
| 8347 | _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 8348 | { |
| 8349 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8350 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8351 | |
| 8352 | printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n", |
| 8353 | ioc->name, state); |
| 8354 | |
| 8355 | switch (state) { |
| 8356 | case pci_channel_io_normal: |
| 8357 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 8358 | case pci_channel_io_frozen: |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8359 | /* Fatal error, prepare for slot reset */ |
| 8360 | ioc->pci_error_recovery = 1; |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8361 | scsi_block_requests(ioc->shost); |
| 8362 | mpt2sas_base_stop_watchdog(ioc); |
| 8363 | mpt2sas_base_free_resources(ioc); |
| 8364 | return PCI_ERS_RESULT_NEED_RESET; |
| 8365 | case pci_channel_io_perm_failure: |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8366 | /* Permanent error, prepare for device removal */ |
| 8367 | ioc->pci_error_recovery = 1; |
| 8368 | mpt2sas_base_stop_watchdog(ioc); |
| 8369 | _scsih_flush_running_cmds(ioc); |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8370 | return PCI_ERS_RESULT_DISCONNECT; |
| 8371 | } |
| 8372 | return PCI_ERS_RESULT_NEED_RESET; |
| 8373 | } |
| 8374 | |
| 8375 | /** |
| 8376 | * _scsih_pci_slot_reset - Called when PCI slot has been reset. |
| 8377 | * @pdev: PCI device struct |
| 8378 | * |
| 8379 | * Description: This routine is called by the pci error recovery |
| 8380 | * code after the PCI slot has been reset, just before we |
| 8381 | * should resume normal operations. |
| 8382 | */ |
| 8383 | static pci_ers_result_t |
| 8384 | _scsih_pci_slot_reset(struct pci_dev *pdev) |
| 8385 | { |
| 8386 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8387 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8388 | int rc; |
| 8389 | |
| 8390 | printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n", |
| 8391 | ioc->name); |
| 8392 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8393 | ioc->pci_error_recovery = 0; |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8394 | ioc->pdev = pdev; |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8395 | pci_restore_state(pdev); |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8396 | rc = mpt2sas_base_map_resources(ioc); |
| 8397 | if (rc) |
| 8398 | return PCI_ERS_RESULT_DISCONNECT; |
| 8399 | |
| 8400 | |
| 8401 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 8402 | FORCE_BIG_HAMMER); |
| 8403 | |
| 8404 | printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name, |
| 8405 | (rc == 0) ? "success" : "failed"); |
| 8406 | |
| 8407 | if (!rc) |
| 8408 | return PCI_ERS_RESULT_RECOVERED; |
| 8409 | else |
| 8410 | return PCI_ERS_RESULT_DISCONNECT; |
| 8411 | } |
| 8412 | |
| 8413 | /** |
| 8414 | * _scsih_pci_resume() - resume normal ops after PCI reset |
| 8415 | * @pdev: pointer to PCI device |
| 8416 | * |
| 8417 | * Called when the error recovery driver tells us that its |
| 8418 | * OK to resume normal operation. Use completion to allow |
| 8419 | * halted scsi ops to resume. |
| 8420 | */ |
| 8421 | static void |
| 8422 | _scsih_pci_resume(struct pci_dev *pdev) |
| 8423 | { |
| 8424 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8425 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8426 | |
| 8427 | printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name); |
| 8428 | |
| 8429 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8430 | mpt2sas_base_start_watchdog(ioc); |
| 8431 | scsi_unblock_requests(ioc->shost); |
| 8432 | } |
| 8433 | |
| 8434 | /** |
| 8435 | * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
| 8436 | * @pdev: pointer to PCI device |
| 8437 | */ |
| 8438 | static pci_ers_result_t |
| 8439 | _scsih_pci_mmio_enabled(struct pci_dev *pdev) |
| 8440 | { |
| 8441 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8442 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8443 | |
| 8444 | printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n", |
| 8445 | ioc->name); |
| 8446 | |
| 8447 | /* TODO - dump whatever for debugging purposes */ |
| 8448 | |
| 8449 | /* Request a slot reset. */ |
| 8450 | return PCI_ERS_RESULT_NEED_RESET; |
| 8451 | } |
| 8452 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 8453 | static const struct pci_error_handlers _scsih_err_handler = { |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8454 | .error_detected = _scsih_pci_error_detected, |
| 8455 | .mmio_enabled = _scsih_pci_mmio_enabled, |
| 8456 | .slot_reset = _scsih_pci_slot_reset, |
| 8457 | .resume = _scsih_pci_resume, |
| 8458 | }; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8459 | |
| 8460 | static struct pci_driver scsih_driver = { |
| 8461 | .name = MPT2SAS_DRIVER_NAME, |
| 8462 | .id_table = scsih_pci_table, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8463 | .probe = _scsih_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8464 | .remove = _scsih_remove, |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8465 | .shutdown = _scsih_shutdown, |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8466 | .err_handler = &_scsih_err_handler, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8467 | #ifdef CONFIG_PM |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8468 | .suspend = _scsih_suspend, |
| 8469 | .resume = _scsih_resume, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8470 | #endif |
| 8471 | }; |
| 8472 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8473 | /* raid transport support */ |
| 8474 | static struct raid_function_template mpt2sas_raid_functions = { |
| 8475 | .cookie = &scsih_driver_template, |
| 8476 | .is_raid = _scsih_is_raid, |
| 8477 | .get_resync = _scsih_get_resync, |
| 8478 | .get_state = _scsih_get_state, |
| 8479 | }; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8480 | |
| 8481 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8482 | * _scsih_init - main entry point for this driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8483 | * |
| 8484 | * Returns 0 success, anything else error. |
| 8485 | */ |
| 8486 | static int __init |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8487 | _scsih_init(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8488 | { |
| 8489 | int error; |
| 8490 | |
| 8491 | mpt_ids = 0; |
| 8492 | printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME, |
| 8493 | MPT2SAS_DRIVER_VERSION); |
| 8494 | |
| 8495 | mpt2sas_transport_template = |
| 8496 | sas_attach_transport(&mpt2sas_transport_functions); |
| 8497 | if (!mpt2sas_transport_template) |
| 8498 | return -ENODEV; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8499 | /* raid transport support */ |
| 8500 | mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions); |
| 8501 | if (!mpt2sas_raid_template) { |
| 8502 | sas_release_transport(mpt2sas_transport_template); |
| 8503 | return -ENODEV; |
| 8504 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8505 | |
| 8506 | mpt2sas_base_initialize_callback_handler(); |
| 8507 | |
| 8508 | /* queuecommand callback hander */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8509 | scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8510 | |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 8511 | /* task management callback handler */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8512 | tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8513 | |
| 8514 | /* base internal commands callback handler */ |
| 8515 | 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] | 8516 | port_enable_cb_idx = mpt2sas_base_register_callback_handler( |
| 8517 | mpt2sas_port_enable_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8518 | |
| 8519 | /* transport internal commands callback handler */ |
| 8520 | transport_cb_idx = mpt2sas_base_register_callback_handler( |
| 8521 | mpt2sas_transport_done); |
| 8522 | |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8523 | /* scsih internal commands callback handler */ |
| 8524 | scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done); |
| 8525 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8526 | /* configuration page API internal commands callback handler */ |
| 8527 | config_cb_idx = mpt2sas_base_register_callback_handler( |
| 8528 | mpt2sas_config_done); |
| 8529 | |
| 8530 | /* ctl module callback handler */ |
| 8531 | ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done); |
| 8532 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8533 | tm_tr_cb_idx = mpt2sas_base_register_callback_handler( |
| 8534 | _scsih_tm_tr_complete); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8535 | |
| 8536 | tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler( |
| 8537 | _scsih_tm_volume_tr_complete); |
| 8538 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8539 | tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler( |
| 8540 | _scsih_sas_control_complete); |
| 8541 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8542 | mpt2sas_ctl_init(); |
| 8543 | |
| 8544 | error = pci_register_driver(&scsih_driver); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8545 | if (error) { |
| 8546 | /* raid transport support */ |
| 8547 | raid_class_release(mpt2sas_raid_template); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8548 | sas_release_transport(mpt2sas_transport_template); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8549 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8550 | |
| 8551 | return error; |
| 8552 | } |
| 8553 | |
| 8554 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8555 | * _scsih_exit - exit point for this driver (when it is a module). |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8556 | * |
| 8557 | * Returns 0 success, anything else error. |
| 8558 | */ |
| 8559 | static void __exit |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8560 | _scsih_exit(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8561 | { |
| 8562 | printk(KERN_INFO "mpt2sas version %s unloading\n", |
| 8563 | MPT2SAS_DRIVER_VERSION); |
| 8564 | |
| 8565 | pci_unregister_driver(&scsih_driver); |
| 8566 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8567 | mpt2sas_ctl_exit(); |
| 8568 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8569 | mpt2sas_base_release_callback_handler(scsi_io_cb_idx); |
| 8570 | mpt2sas_base_release_callback_handler(tm_cb_idx); |
| 8571 | mpt2sas_base_release_callback_handler(base_cb_idx); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8572 | mpt2sas_base_release_callback_handler(port_enable_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8573 | mpt2sas_base_release_callback_handler(transport_cb_idx); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8574 | mpt2sas_base_release_callback_handler(scsih_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8575 | mpt2sas_base_release_callback_handler(config_cb_idx); |
| 8576 | mpt2sas_base_release_callback_handler(ctl_cb_idx); |
| 8577 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8578 | mpt2sas_base_release_callback_handler(tm_tr_cb_idx); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8579 | mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8580 | mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx); |
| 8581 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8582 | /* raid transport support */ |
| 8583 | raid_class_release(mpt2sas_raid_template); |
| 8584 | sas_release_transport(mpt2sas_transport_template); |
| 8585 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8586 | } |
| 8587 | |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8588 | module_init(_scsih_init); |
| 8589 | module_exit(_scsih_exit); |