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 | e9edbe3 | 2014-09-12 15:35:18 +0530 | [diff] [blame] | 5 | * Copyright (C) 2007-2014 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 | |
Sreekanth Reddy | daeaa9d | 2014-09-12 15:35:21 +0530 | [diff] [blame] | 58 | #include <asm/unaligned.h> |
| 59 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 60 | #include "mpt2sas_base.h" |
| 61 | |
| 62 | MODULE_AUTHOR(MPT2SAS_AUTHOR); |
| 63 | MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION); |
| 64 | MODULE_LICENSE("GPL"); |
| 65 | MODULE_VERSION(MPT2SAS_DRIVER_VERSION); |
| 66 | |
| 67 | #define RAID_CHANNEL 1 |
| 68 | |
| 69 | /* forward proto's */ |
| 70 | static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc, |
| 71 | struct _sas_node *sas_expander); |
| 72 | static void _firmware_event_work(struct work_struct *work); |
| 73 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 74 | static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid); |
| 75 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 76 | static void _scsih_scan_start(struct Scsi_Host *shost); |
| 77 | static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time); |
| 78 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 79 | /* global parameters */ |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 80 | LIST_HEAD(mpt2sas_ioc_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 81 | |
| 82 | /* local parameters */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 83 | static u8 scsi_io_cb_idx = -1; |
| 84 | static u8 tm_cb_idx = -1; |
| 85 | static u8 ctl_cb_idx = -1; |
| 86 | static u8 base_cb_idx = -1; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 87 | static u8 port_enable_cb_idx = -1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 88 | static u8 transport_cb_idx = -1; |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 89 | static u8 scsih_cb_idx = -1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 90 | static u8 config_cb_idx = -1; |
| 91 | static int mpt_ids; |
| 92 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 93 | static u8 tm_tr_cb_idx = -1 ; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 94 | static u8 tm_tr_volume_cb_idx = -1 ; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 95 | static u8 tm_sas_control_cb_idx = -1; |
| 96 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 97 | /* command line options */ |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 98 | static u32 logging_level; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 99 | MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info " |
| 100 | "(default=0)"); |
| 101 | |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 102 | static ushort max_sectors = 0xFFFF; |
| 103 | module_param(max_sectors, ushort, 0); |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 104 | 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] | 105 | |
Reddy, Sreekanth | b0df96a0 | 2013-02-26 16:59:59 +0530 | [diff] [blame] | 106 | static int missing_delay[2] = {-1, -1}; |
| 107 | module_param_array(missing_delay, int, NULL, 0); |
| 108 | MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay"); |
| 109 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 110 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ |
| 111 | #define MPT2SAS_MAX_LUN (16895) |
| 112 | static int max_lun = MPT2SAS_MAX_LUN; |
| 113 | module_param(max_lun, int, 0); |
| 114 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); |
| 115 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 116 | /* diag_buffer_enable is bitwise |
| 117 | * bit 0 set = TRACE |
| 118 | * bit 1 set = SNAPSHOT |
| 119 | * bit 2 set = EXTENDED |
| 120 | * |
| 121 | * Either bit can be set, or both |
| 122 | */ |
| 123 | static int diag_buffer_enable = -1; |
| 124 | module_param(diag_buffer_enable, int, 0); |
| 125 | MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers " |
| 126 | "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); |
| 127 | |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 128 | static int disable_discovery = -1; |
| 129 | module_param(disable_discovery, int, 0); |
| 130 | MODULE_PARM_DESC(disable_discovery, " disable discovery "); |
| 131 | |
Martin K. Petersen | 5e95e73 | 2012-08-28 14:29:37 -0400 | [diff] [blame] | 132 | /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */ |
| 133 | static int prot_mask = 0; |
| 134 | module_param(prot_mask, int, 0); |
| 135 | MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 "); |
| 136 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 137 | /** |
| 138 | * struct sense_info - common structure for obtaining sense keys |
| 139 | * @skey: sense key |
| 140 | * @asc: additional sense code |
| 141 | * @ascq: additional sense code qualifier |
| 142 | */ |
| 143 | struct sense_info { |
| 144 | u8 skey; |
| 145 | u8 asc; |
| 146 | u8 ascq; |
| 147 | }; |
| 148 | |
| 149 | |
Sreekanth Reddy | bd58ea3 | 2014-09-12 15:35:19 +0530 | [diff] [blame] | 150 | #define MPT2SAS_TURN_ON_PFA_LED (0xFFFC) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 151 | #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD) |
| 152 | #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 153 | /** |
| 154 | * struct fw_event_work - firmware event struct |
| 155 | * @list: link list framework |
| 156 | * @work: work object (ioc->fault_reset_work_q) |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 157 | * @cancel_pending_work: flag set during reset handling |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 158 | * @ioc: per adapter object |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 159 | * @device_handle: device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 160 | * @VF_ID: virtual function id |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 161 | * @VP_ID: virtual port id |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 162 | * @ignore: flag meaning this event has been marked to ignore |
| 163 | * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h |
| 164 | * @event_data: reply event data payload follows |
| 165 | * |
| 166 | * This object stored on ioc->fw_event_list. |
| 167 | */ |
| 168 | struct fw_event_work { |
| 169 | struct list_head list; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 170 | u8 cancel_pending_work; |
| 171 | struct delayed_work delayed_work; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 172 | struct MPT2SAS_ADAPTER *ioc; |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 173 | u16 device_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 174 | u8 VF_ID; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 175 | u8 VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 176 | u8 ignore; |
| 177 | u16 event; |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 178 | char event_data[0] __aligned(4); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 179 | }; |
| 180 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 181 | /* raid transport support */ |
| 182 | static struct raid_template *mpt2sas_raid_template; |
| 183 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 184 | /** |
| 185 | * struct _scsi_io_transfer - scsi io transfer |
| 186 | * @handle: sas device handle (assigned by firmware) |
| 187 | * @is_raid: flag set for hidden raid components |
| 188 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, |
| 189 | * @data_length: data transfer length |
| 190 | * @data_dma: dma pointer to data |
| 191 | * @sense: sense data |
| 192 | * @lun: lun number |
| 193 | * @cdb_length: cdb length |
| 194 | * @cdb: cdb contents |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 195 | * @timeout: timeout for this command |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 196 | * @VF_ID: virtual function id |
| 197 | * @VP_ID: virtual port id |
| 198 | * @valid_reply: flag set for reply message |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 199 | * @sense_length: sense length |
| 200 | * @ioc_status: ioc status |
| 201 | * @scsi_state: scsi state |
| 202 | * @scsi_status: scsi staus |
| 203 | * @log_info: log information |
| 204 | * @transfer_length: data length transfer when there is a reply message |
| 205 | * |
| 206 | * Used for sending internal scsi commands to devices within this module. |
| 207 | * Refer to _scsi_send_scsi_io(). |
| 208 | */ |
| 209 | struct _scsi_io_transfer { |
| 210 | u16 handle; |
| 211 | u8 is_raid; |
| 212 | enum dma_data_direction dir; |
| 213 | u32 data_length; |
| 214 | dma_addr_t data_dma; |
| 215 | u8 sense[SCSI_SENSE_BUFFERSIZE]; |
| 216 | u32 lun; |
| 217 | u8 cdb_length; |
| 218 | u8 cdb[32]; |
| 219 | u8 timeout; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 220 | u8 VF_ID; |
| 221 | u8 VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 222 | u8 valid_reply; |
| 223 | /* the following bits are only valid when 'valid_reply = 1' */ |
| 224 | u32 sense_length; |
| 225 | u16 ioc_status; |
| 226 | u8 scsi_state; |
| 227 | u8 scsi_status; |
| 228 | u32 log_info; |
| 229 | u32 transfer_length; |
| 230 | }; |
| 231 | |
| 232 | /* |
| 233 | * The pci device ids are defined in mpi/mpi2_cnfg.h. |
| 234 | */ |
| 235 | static struct pci_device_id scsih_pci_table[] = { |
| 236 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, |
| 237 | PCI_ANY_ID, PCI_ANY_ID }, |
| 238 | /* Falcon ~ 2008*/ |
| 239 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, |
| 240 | PCI_ANY_ID, PCI_ANY_ID }, |
| 241 | /* Liberator ~ 2108 */ |
| 242 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, |
| 243 | PCI_ANY_ID, PCI_ANY_ID }, |
| 244 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, |
| 245 | PCI_ANY_ID, PCI_ANY_ID }, |
| 246 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, |
| 247 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 248 | /* Meteor ~ 2116 */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 249 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, |
| 250 | PCI_ANY_ID, PCI_ANY_ID }, |
| 251 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, |
| 252 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 253 | /* Thunderbolt ~ 2208 */ |
| 254 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, |
| 255 | PCI_ANY_ID, PCI_ANY_ID }, |
| 256 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, |
| 257 | PCI_ANY_ID, PCI_ANY_ID }, |
| 258 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, |
| 259 | PCI_ANY_ID, PCI_ANY_ID }, |
| 260 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, |
| 261 | PCI_ANY_ID, PCI_ANY_ID }, |
| 262 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, |
| 263 | PCI_ANY_ID, PCI_ANY_ID }, |
| 264 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, |
| 265 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 203d65b | 2010-06-17 13:37:59 +0530 | [diff] [blame] | 266 | /* Mustang ~ 2308 */ |
| 267 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 268 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 203d65b | 2010-06-17 13:37:59 +0530 | [diff] [blame] | 269 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, |
| 270 | PCI_ANY_ID, PCI_ANY_ID }, |
| 271 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 272 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 273 | /* SSS6200 */ |
| 274 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, |
| 275 | PCI_ANY_ID, PCI_ANY_ID }, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 276 | {0} /* Terminating entry */ |
| 277 | }; |
| 278 | MODULE_DEVICE_TABLE(pci, scsih_pci_table); |
| 279 | |
| 280 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 281 | * _scsih_set_debug_level - global setting of ioc->logging_level. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 282 | * |
| 283 | * Note: The logging levels are defined in mpt2sas_debug.h. |
| 284 | */ |
| 285 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 286 | _scsih_set_debug_level(const char *val, struct kernel_param *kp) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 287 | { |
| 288 | int ret = param_set_int(val, kp); |
| 289 | struct MPT2SAS_ADAPTER *ioc; |
| 290 | |
| 291 | if (ret) |
| 292 | return ret; |
| 293 | |
| 294 | printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 295 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 296 | ioc->logging_level = logging_level; |
| 297 | return 0; |
| 298 | } |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 299 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 300 | &logging_level, 0644); |
| 301 | |
| 302 | /** |
| 303 | * _scsih_srch_boot_sas_address - search based on sas_address |
| 304 | * @sas_address: sas address |
| 305 | * @boot_device: boot device object from bios page 2 |
| 306 | * |
| 307 | * Returns 1 when there's a match, 0 means no match. |
| 308 | */ |
| 309 | static inline int |
| 310 | _scsih_srch_boot_sas_address(u64 sas_address, |
| 311 | Mpi2BootDeviceSasWwid_t *boot_device) |
| 312 | { |
| 313 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * _scsih_srch_boot_device_name - search based on device name |
| 318 | * @device_name: device name specified in INDENTIFY fram |
| 319 | * @boot_device: boot device object from bios page 2 |
| 320 | * |
| 321 | * Returns 1 when there's a match, 0 means no match. |
| 322 | */ |
| 323 | static inline int |
| 324 | _scsih_srch_boot_device_name(u64 device_name, |
| 325 | Mpi2BootDeviceDeviceName_t *boot_device) |
| 326 | { |
| 327 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot |
| 332 | * @enclosure_logical_id: enclosure logical id |
| 333 | * @slot_number: slot number |
| 334 | * @boot_device: boot device object from bios page 2 |
| 335 | * |
| 336 | * Returns 1 when there's a match, 0 means no match. |
| 337 | */ |
| 338 | static inline int |
| 339 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, |
| 340 | Mpi2BootDeviceEnclosureSlot_t *boot_device) |
| 341 | { |
| 342 | return (enclosure_logical_id == le64_to_cpu(boot_device-> |
| 343 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> |
| 344 | SlotNumber)) ? 1 : 0; |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * _scsih_is_boot_device - search for matching boot device. |
| 349 | * @sas_address: sas address |
| 350 | * @device_name: device name specified in INDENTIFY fram |
| 351 | * @enclosure_logical_id: enclosure logical id |
| 352 | * @slot_number: slot number |
| 353 | * @form: specifies boot device form |
| 354 | * @boot_device: boot device object from bios page 2 |
| 355 | * |
| 356 | * Returns 1 when there's a match, 0 means no match. |
| 357 | */ |
| 358 | static int |
| 359 | _scsih_is_boot_device(u64 sas_address, u64 device_name, |
| 360 | u64 enclosure_logical_id, u16 slot, u8 form, |
| 361 | Mpi2BiosPage2BootDevice_t *boot_device) |
| 362 | { |
| 363 | int rc = 0; |
| 364 | |
| 365 | switch (form) { |
| 366 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: |
| 367 | if (!sas_address) |
| 368 | break; |
| 369 | rc = _scsih_srch_boot_sas_address( |
| 370 | sas_address, &boot_device->SasWwid); |
| 371 | break; |
| 372 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: |
| 373 | if (!enclosure_logical_id) |
| 374 | break; |
| 375 | rc = _scsih_srch_boot_encl_slot( |
| 376 | enclosure_logical_id, |
| 377 | slot, &boot_device->EnclosureSlot); |
| 378 | break; |
| 379 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: |
| 380 | if (!device_name) |
| 381 | break; |
| 382 | rc = _scsih_srch_boot_device_name( |
| 383 | device_name, &boot_device->DeviceName); |
| 384 | break; |
| 385 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: |
| 386 | break; |
| 387 | } |
| 388 | |
| 389 | return rc; |
| 390 | } |
| 391 | |
| 392 | /** |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 393 | * _scsih_get_sas_address - set the sas_address for given device handle |
| 394 | * @handle: device handle |
| 395 | * @sas_address: sas address |
| 396 | * |
| 397 | * Returns 0 success, non-zero when failure |
| 398 | */ |
| 399 | static int |
| 400 | _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle, |
| 401 | u64 *sas_address) |
| 402 | { |
| 403 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 404 | Mpi2ConfigReply_t mpi_reply; |
| 405 | u32 ioc_status; |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 406 | *sas_address = 0; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 407 | |
| 408 | if (handle <= ioc->sas_hba.num_phys) { |
| 409 | *sas_address = ioc->sas_hba.sas_address; |
| 410 | return 0; |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 411 | } |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 412 | |
| 413 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 414 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 415 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 416 | __FILE__, __LINE__, __func__); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 417 | return -ENXIO; |
| 418 | } |
| 419 | |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 420 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 421 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { |
| 422 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 423 | return 0; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 424 | } |
| 425 | |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 426 | /* we hit this becuase the given parent handle doesn't exist */ |
| 427 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 428 | return -ENXIO; |
| 429 | /* else error case */ |
| 430 | printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), " |
| 431 | "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status, |
| 432 | __FILE__, __LINE__, __func__); |
| 433 | return -EIO; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 437 | * _scsih_determine_boot_device - determine boot device. |
| 438 | * @ioc: per adapter object |
| 439 | * @device: either sas_device or raid_device object |
| 440 | * @is_raid: [flag] 1 = raid object, 0 = sas object |
| 441 | * |
| 442 | * Determines whether this device should be first reported device to |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 443 | * 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] | 444 | * There are primary, alternate, and current entries in bios page 2. The order |
| 445 | * priority is primary, alternate, then current. This routine saves |
| 446 | * the corresponding device object and is_raid flag in the ioc object. |
| 447 | * The saved data to be used later in _scsih_probe_boot_devices(). |
| 448 | */ |
| 449 | static void |
| 450 | _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc, |
| 451 | void *device, u8 is_raid) |
| 452 | { |
| 453 | struct _sas_device *sas_device; |
| 454 | struct _raid_device *raid_device; |
| 455 | u64 sas_address; |
| 456 | u64 device_name; |
| 457 | u64 enclosure_logical_id; |
| 458 | u16 slot; |
| 459 | |
| 460 | /* only process this function when driver loads */ |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 461 | if (!ioc->is_driver_loading) |
| 462 | return; |
| 463 | |
| 464 | /* no Bios, return immediately */ |
| 465 | if (!ioc->bios_pg3.BiosVersion) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 466 | return; |
| 467 | |
| 468 | if (!is_raid) { |
| 469 | sas_device = device; |
| 470 | sas_address = sas_device->sas_address; |
| 471 | device_name = sas_device->device_name; |
| 472 | enclosure_logical_id = sas_device->enclosure_logical_id; |
| 473 | slot = sas_device->slot; |
| 474 | } else { |
| 475 | raid_device = device; |
| 476 | sas_address = raid_device->wwid; |
| 477 | device_name = 0; |
| 478 | enclosure_logical_id = 0; |
| 479 | slot = 0; |
| 480 | } |
| 481 | |
| 482 | if (!ioc->req_boot_device.device) { |
| 483 | if (_scsih_is_boot_device(sas_address, device_name, |
| 484 | enclosure_logical_id, slot, |
| 485 | (ioc->bios_pg2.ReqBootDeviceForm & |
| 486 | MPI2_BIOSPAGE2_FORM_MASK), |
| 487 | &ioc->bios_pg2.RequestedBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 488 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 489 | "%s: req_boot_device(0x%016llx)\n", |
| 490 | ioc->name, __func__, |
| 491 | (unsigned long long)sas_address)); |
| 492 | ioc->req_boot_device.device = device; |
| 493 | ioc->req_boot_device.is_raid = is_raid; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | if (!ioc->req_alt_boot_device.device) { |
| 498 | if (_scsih_is_boot_device(sas_address, device_name, |
| 499 | enclosure_logical_id, slot, |
| 500 | (ioc->bios_pg2.ReqAltBootDeviceForm & |
| 501 | MPI2_BIOSPAGE2_FORM_MASK), |
| 502 | &ioc->bios_pg2.RequestedAltBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 503 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 504 | "%s: req_alt_boot_device(0x%016llx)\n", |
| 505 | ioc->name, __func__, |
| 506 | (unsigned long long)sas_address)); |
| 507 | ioc->req_alt_boot_device.device = device; |
| 508 | ioc->req_alt_boot_device.is_raid = is_raid; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | if (!ioc->current_boot_device.device) { |
| 513 | if (_scsih_is_boot_device(sas_address, device_name, |
| 514 | enclosure_logical_id, slot, |
| 515 | (ioc->bios_pg2.CurrentBootDeviceForm & |
| 516 | MPI2_BIOSPAGE2_FORM_MASK), |
| 517 | &ioc->bios_pg2.CurrentBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 518 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 519 | "%s: current_boot_device(0x%016llx)\n", |
| 520 | ioc->name, __func__, |
| 521 | (unsigned long long)sas_address)); |
| 522 | ioc->current_boot_device.device = device; |
| 523 | ioc->current_boot_device.is_raid = is_raid; |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | /** |
| 529 | * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search |
| 530 | * @ioc: per adapter object |
| 531 | * @sas_address: sas address |
| 532 | * Context: Calling function should acquire ioc->sas_device_lock |
| 533 | * |
| 534 | * This searches for sas_device based on sas_address, then return sas_device |
| 535 | * object. |
| 536 | */ |
| 537 | struct _sas_device * |
| 538 | mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 539 | u64 sas_address) |
| 540 | { |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 541 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 542 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 543 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) |
| 544 | if (sas_device->sas_address == sas_address) |
| 545 | return sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 546 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 547 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) |
| 548 | if (sas_device->sas_address == sas_address) |
| 549 | return sas_device; |
| 550 | |
| 551 | return NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /** |
| 555 | * _scsih_sas_device_find_by_handle - sas device search |
| 556 | * @ioc: per adapter object |
| 557 | * @handle: sas device handle (assigned by firmware) |
| 558 | * Context: Calling function should acquire ioc->sas_device_lock |
| 559 | * |
| 560 | * This searches for sas_device based on sas_address, then return sas_device |
| 561 | * object. |
| 562 | */ |
| 563 | static struct _sas_device * |
| 564 | _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 565 | { |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 566 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 567 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 568 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) |
| 569 | if (sas_device->handle == handle) |
| 570 | return sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 571 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 572 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) |
| 573 | if (sas_device->handle == handle) |
| 574 | return sas_device; |
| 575 | |
| 576 | return NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /** |
| 580 | * _scsih_sas_device_remove - remove sas_device from list. |
| 581 | * @ioc: per adapter object |
| 582 | * @sas_device: the sas_device object |
| 583 | * Context: This function will acquire ioc->sas_device_lock. |
| 584 | * |
| 585 | * Removing object and freeing associated memory from the ioc->sas_device_list. |
| 586 | */ |
| 587 | static void |
| 588 | _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc, |
| 589 | struct _sas_device *sas_device) |
| 590 | { |
| 591 | unsigned long flags; |
| 592 | |
Kashyap, Desai | 980ead3 | 2010-04-08 17:55:22 +0530 | [diff] [blame] | 593 | if (!sas_device) |
| 594 | return; |
| 595 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 596 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 597 | list_del(&sas_device->list); |
| 598 | kfree(sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 599 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 600 | } |
| 601 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 602 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 603 | /** |
| 604 | * _scsih_sas_device_add - insert sas_device to the list. |
| 605 | * @ioc: per adapter object |
| 606 | * @sas_device: the sas_device object |
| 607 | * Context: This function will acquire ioc->sas_device_lock. |
| 608 | * |
| 609 | * Adding new object to the ioc->sas_device_list. |
| 610 | */ |
| 611 | static void |
| 612 | _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc, |
| 613 | struct _sas_device *sas_device) |
| 614 | { |
| 615 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 616 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 617 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 618 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 619 | sas_device->handle, (unsigned long long)sas_device->sas_address)); |
| 620 | |
| 621 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 622 | list_add_tail(&sas_device->list, &ioc->sas_device_list); |
| 623 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 624 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 625 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 626 | sas_device->sas_address_parent)) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 627 | _scsih_sas_device_remove(ioc, sas_device); |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 628 | } else if (!sas_device->starget) { |
| 629 | /* When asyn scanning is enabled, its not possible to remove |
| 630 | * devices while scanning is turned on due to an oops in |
| 631 | * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start() |
| 632 | */ |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 633 | if (!ioc->is_driver_loading) { |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 634 | mpt2sas_transport_port_remove(ioc, |
| 635 | sas_device->sas_address, |
| 636 | sas_device->sas_address_parent); |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 637 | _scsih_sas_device_remove(ioc, sas_device); |
| 638 | } |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 639 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | /** |
| 643 | * _scsih_sas_device_init_add - insert sas_device to the list. |
| 644 | * @ioc: per adapter object |
| 645 | * @sas_device: the sas_device object |
| 646 | * Context: This function will acquire ioc->sas_device_lock. |
| 647 | * |
| 648 | * Adding new object at driver load time to the ioc->sas_device_init_list. |
| 649 | */ |
| 650 | static void |
| 651 | _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc, |
| 652 | struct _sas_device *sas_device) |
| 653 | { |
| 654 | unsigned long flags; |
| 655 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 656 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 657 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 658 | sas_device->handle, (unsigned long long)sas_device->sas_address)); |
| 659 | |
| 660 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 661 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 662 | _scsih_determine_boot_device(ioc, sas_device, 0); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 663 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 667 | * _scsih_raid_device_find_by_id - raid device search |
| 668 | * @ioc: per adapter object |
| 669 | * @id: sas device target id |
| 670 | * @channel: sas device channel |
| 671 | * Context: Calling function should acquire ioc->raid_device_lock |
| 672 | * |
| 673 | * This searches for raid_device based on target id, then return raid_device |
| 674 | * object. |
| 675 | */ |
| 676 | static struct _raid_device * |
| 677 | _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel) |
| 678 | { |
| 679 | struct _raid_device *raid_device, *r; |
| 680 | |
| 681 | r = NULL; |
| 682 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 683 | if (raid_device->id == id && raid_device->channel == channel) { |
| 684 | r = raid_device; |
| 685 | goto out; |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | out: |
| 690 | return r; |
| 691 | } |
| 692 | |
| 693 | /** |
| 694 | * _scsih_raid_device_find_by_handle - raid device search |
| 695 | * @ioc: per adapter object |
| 696 | * @handle: sas device handle (assigned by firmware) |
| 697 | * Context: Calling function should acquire ioc->raid_device_lock |
| 698 | * |
| 699 | * This searches for raid_device based on handle, then return raid_device |
| 700 | * object. |
| 701 | */ |
| 702 | static struct _raid_device * |
| 703 | _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 704 | { |
| 705 | struct _raid_device *raid_device, *r; |
| 706 | |
| 707 | r = NULL; |
| 708 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 709 | if (raid_device->handle != handle) |
| 710 | continue; |
| 711 | r = raid_device; |
| 712 | goto out; |
| 713 | } |
| 714 | |
| 715 | out: |
| 716 | return r; |
| 717 | } |
| 718 | |
| 719 | /** |
| 720 | * _scsih_raid_device_find_by_wwid - raid device search |
| 721 | * @ioc: per adapter object |
| 722 | * @handle: sas device handle (assigned by firmware) |
| 723 | * Context: Calling function should acquire ioc->raid_device_lock |
| 724 | * |
| 725 | * This searches for raid_device based on wwid, then return raid_device |
| 726 | * object. |
| 727 | */ |
| 728 | static struct _raid_device * |
| 729 | _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid) |
| 730 | { |
| 731 | struct _raid_device *raid_device, *r; |
| 732 | |
| 733 | r = NULL; |
| 734 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 735 | if (raid_device->wwid != wwid) |
| 736 | continue; |
| 737 | r = raid_device; |
| 738 | goto out; |
| 739 | } |
| 740 | |
| 741 | out: |
| 742 | return r; |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * _scsih_raid_device_add - add raid_device object |
| 747 | * @ioc: per adapter object |
| 748 | * @raid_device: raid_device object |
| 749 | * |
| 750 | * This is added to the raid_device_list link list. |
| 751 | */ |
| 752 | static void |
| 753 | _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc, |
| 754 | struct _raid_device *raid_device) |
| 755 | { |
| 756 | unsigned long flags; |
| 757 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 758 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 759 | "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, |
| 760 | raid_device->handle, (unsigned long long)raid_device->wwid)); |
| 761 | |
| 762 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 763 | list_add_tail(&raid_device->list, &ioc->raid_device_list); |
| 764 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 765 | } |
| 766 | |
| 767 | /** |
| 768 | * _scsih_raid_device_remove - delete raid_device object |
| 769 | * @ioc: per adapter object |
| 770 | * @raid_device: raid_device object |
| 771 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 772 | */ |
| 773 | static void |
| 774 | _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc, |
| 775 | struct _raid_device *raid_device) |
| 776 | { |
| 777 | unsigned long flags; |
| 778 | |
| 779 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 780 | list_del(&raid_device->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 781 | kfree(raid_device); |
| 782 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 783 | } |
| 784 | |
| 785 | /** |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 786 | * mpt2sas_scsih_expander_find_by_handle - expander device search |
| 787 | * @ioc: per adapter object |
| 788 | * @handle: expander handle (assigned by firmware) |
| 789 | * Context: Calling function should acquire ioc->sas_device_lock |
| 790 | * |
| 791 | * This searches for expander device based on handle, then returns the |
| 792 | * sas_node object. |
| 793 | */ |
| 794 | struct _sas_node * |
| 795 | mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 796 | { |
| 797 | struct _sas_node *sas_expander, *r; |
| 798 | |
| 799 | r = NULL; |
| 800 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 801 | if (sas_expander->handle != handle) |
| 802 | continue; |
| 803 | r = sas_expander; |
| 804 | goto out; |
| 805 | } |
| 806 | out: |
| 807 | return r; |
| 808 | } |
| 809 | |
| 810 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 811 | * mpt2sas_scsih_expander_find_by_sas_address - expander device search |
| 812 | * @ioc: per adapter object |
| 813 | * @sas_address: sas address |
| 814 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 815 | * |
| 816 | * This searches for expander device based on sas_address, then returns the |
| 817 | * sas_node object. |
| 818 | */ |
| 819 | struct _sas_node * |
| 820 | mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 821 | u64 sas_address) |
| 822 | { |
| 823 | struct _sas_node *sas_expander, *r; |
| 824 | |
| 825 | r = NULL; |
| 826 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 827 | if (sas_expander->sas_address != sas_address) |
| 828 | continue; |
| 829 | r = sas_expander; |
| 830 | goto out; |
| 831 | } |
| 832 | out: |
| 833 | return r; |
| 834 | } |
| 835 | |
| 836 | /** |
| 837 | * _scsih_expander_node_add - insert expander device to the list. |
| 838 | * @ioc: per adapter object |
| 839 | * @sas_expander: the sas_device object |
| 840 | * Context: This function will acquire ioc->sas_node_lock. |
| 841 | * |
| 842 | * Adding new object to the ioc->sas_expander_list. |
| 843 | * |
| 844 | * Return nothing. |
| 845 | */ |
| 846 | static void |
| 847 | _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc, |
| 848 | struct _sas_node *sas_expander) |
| 849 | { |
| 850 | unsigned long flags; |
| 851 | |
| 852 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 853 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); |
| 854 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 855 | } |
| 856 | |
| 857 | /** |
| 858 | * _scsih_is_end_device - determines if device is an end device |
| 859 | * @device_info: bitfield providing information about the device. |
| 860 | * Context: none |
| 861 | * |
| 862 | * Returns 1 if end device. |
| 863 | */ |
| 864 | static int |
| 865 | _scsih_is_end_device(u32 device_info) |
| 866 | { |
| 867 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && |
| 868 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | |
| 869 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
| 870 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) |
| 871 | return 1; |
| 872 | else |
| 873 | return 0; |
| 874 | } |
| 875 | |
| 876 | /** |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 877 | * _scsih_scsi_lookup_get - returns scmd entry |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 878 | * @ioc: per adapter object |
| 879 | * @smid: system request message index |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 880 | * |
| 881 | * Returns the smid stored scmd pointer. |
| 882 | */ |
| 883 | static struct scsi_cmnd * |
| 884 | _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 885 | { |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 886 | return ioc->scsi_lookup[smid - 1].scmd; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | /** |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 890 | * _scsih_scsi_lookup_get_clear - returns scmd entry |
| 891 | * @ioc: per adapter object |
| 892 | * @smid: system request message index |
| 893 | * |
| 894 | * Returns the smid stored scmd pointer. |
| 895 | * Then will derefrence the stored scmd pointer. |
| 896 | */ |
| 897 | static inline struct scsi_cmnd * |
| 898 | _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 899 | { |
| 900 | unsigned long flags; |
| 901 | struct scsi_cmnd *scmd; |
| 902 | |
| 903 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 904 | scmd = ioc->scsi_lookup[smid - 1].scmd; |
| 905 | ioc->scsi_lookup[smid - 1].scmd = NULL; |
| 906 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 907 | |
| 908 | return scmd; |
| 909 | } |
| 910 | |
| 911 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 912 | * _scsih_scsi_lookup_find_by_scmd - scmd lookup |
| 913 | * @ioc: per adapter object |
| 914 | * @smid: system request message index |
| 915 | * @scmd: pointer to scsi command object |
| 916 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 917 | * |
| 918 | * This will search for a scmd pointer in the scsi_lookup array, |
| 919 | * returning the revelent smid. A returned value of zero means invalid. |
| 920 | */ |
| 921 | static u16 |
| 922 | _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd |
| 923 | *scmd) |
| 924 | { |
| 925 | u16 smid; |
| 926 | unsigned long flags; |
| 927 | int i; |
| 928 | |
| 929 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 930 | smid = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 931 | for (i = 0; i < ioc->scsiio_depth; i++) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 932 | if (ioc->scsi_lookup[i].scmd == scmd) { |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 933 | smid = ioc->scsi_lookup[i].smid; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 934 | goto out; |
| 935 | } |
| 936 | } |
| 937 | out: |
| 938 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 939 | return smid; |
| 940 | } |
| 941 | |
| 942 | /** |
| 943 | * _scsih_scsi_lookup_find_by_target - search for matching channel:id |
| 944 | * @ioc: per adapter object |
| 945 | * @id: target id |
| 946 | * @channel: channel |
| 947 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 948 | * |
| 949 | * This will search for a matching channel:id in the scsi_lookup array, |
| 950 | * returning 1 if found. |
| 951 | */ |
| 952 | static u8 |
| 953 | _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id, |
| 954 | int channel) |
| 955 | { |
| 956 | u8 found; |
| 957 | unsigned long flags; |
| 958 | int i; |
| 959 | |
| 960 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 961 | found = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 962 | for (i = 0 ; i < ioc->scsiio_depth; i++) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 963 | if (ioc->scsi_lookup[i].scmd && |
| 964 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 965 | ioc->scsi_lookup[i].scmd->device->channel == channel)) { |
| 966 | found = 1; |
| 967 | goto out; |
| 968 | } |
| 969 | } |
| 970 | out: |
| 971 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 972 | return found; |
| 973 | } |
| 974 | |
| 975 | /** |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 976 | * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun |
| 977 | * @ioc: per adapter object |
| 978 | * @id: target id |
| 979 | * @lun: lun number |
| 980 | * @channel: channel |
| 981 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 982 | * |
| 983 | * This will search for a matching channel:id:lun in the scsi_lookup array, |
| 984 | * returning 1 if found. |
| 985 | */ |
| 986 | static u8 |
| 987 | _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id, |
| 988 | unsigned int lun, int channel) |
| 989 | { |
| 990 | u8 found; |
| 991 | unsigned long flags; |
| 992 | int i; |
| 993 | |
| 994 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 995 | found = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 996 | for (i = 0 ; i < ioc->scsiio_depth; i++) { |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 997 | if (ioc->scsi_lookup[i].scmd && |
| 998 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 999 | ioc->scsi_lookup[i].scmd->device->channel == channel && |
| 1000 | ioc->scsi_lookup[i].scmd->device->lun == lun)) { |
| 1001 | found = 1; |
| 1002 | goto out; |
| 1003 | } |
| 1004 | } |
| 1005 | out: |
| 1006 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1007 | return found; |
| 1008 | } |
| 1009 | |
| 1010 | /** |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1011 | * _scsih_get_chain_buffer_tracker - obtain chain tracker |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1012 | * @ioc: per adapter object |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1013 | * @smid: smid associated to an IO request |
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 | * Returns chain tracker(from ioc->free_chain_list) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1016 | */ |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1017 | static struct chain_tracker * |
| 1018 | _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1019 | { |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1020 | struct chain_tracker *chain_req; |
| 1021 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1022 | |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1023 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 1024 | if (list_empty(&ioc->free_chain_list)) { |
| 1025 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
nagalakshmi.nandigama@lsi.com | aff132d | 2011-12-01 07:53:08 +0530 | [diff] [blame] | 1026 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not " |
| 1027 | "available\n", ioc->name)); |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1028 | return NULL; |
| 1029 | } |
| 1030 | chain_req = list_entry(ioc->free_chain_list.next, |
| 1031 | struct chain_tracker, tracker_list); |
| 1032 | list_del_init(&chain_req->tracker_list); |
| 1033 | list_add_tail(&chain_req->tracker_list, |
| 1034 | &ioc->scsi_lookup[smid - 1].chain_list); |
| 1035 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1036 | return chain_req; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | /** |
| 1040 | * _scsih_build_scatter_gather - main sg creation routine |
| 1041 | * @ioc: per adapter object |
| 1042 | * @scmd: scsi command |
| 1043 | * @smid: system request message index |
| 1044 | * Context: none. |
| 1045 | * |
| 1046 | * The main routine that builds scatter gather table from a given |
| 1047 | * scsi request sent via the .queuecommand main handler. |
| 1048 | * |
| 1049 | * Returns 0 success, anything else error |
| 1050 | */ |
| 1051 | static int |
| 1052 | _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc, |
| 1053 | struct scsi_cmnd *scmd, u16 smid) |
| 1054 | { |
| 1055 | Mpi2SCSIIORequest_t *mpi_request; |
| 1056 | dma_addr_t chain_dma; |
| 1057 | struct scatterlist *sg_scmd; |
| 1058 | void *sg_local, *chain; |
| 1059 | u32 chain_offset; |
| 1060 | u32 chain_length; |
| 1061 | u32 chain_flags; |
FUJITA Tomonori | bb789d0 | 2010-03-09 11:09:50 +0900 | [diff] [blame] | 1062 | int sges_left; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1063 | u32 sges_in_segment; |
| 1064 | u32 sgl_flags; |
| 1065 | u32 sgl_flags_last_element; |
| 1066 | u32 sgl_flags_end_buffer; |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1067 | struct chain_tracker *chain_req; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1068 | |
| 1069 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 1070 | |
| 1071 | /* init scatter gather flags */ |
| 1072 | sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT; |
| 1073 | if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 1074 | sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC; |
| 1075 | sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT) |
| 1076 | << MPI2_SGE_FLAGS_SHIFT; |
| 1077 | sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT | |
| 1078 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST) |
| 1079 | << MPI2_SGE_FLAGS_SHIFT; |
| 1080 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1081 | |
| 1082 | sg_scmd = scsi_sglist(scmd); |
| 1083 | sges_left = scsi_dma_map(scmd); |
FUJITA Tomonori | bb789d0 | 2010-03-09 11:09:50 +0900 | [diff] [blame] | 1084 | if (sges_left < 0) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1085 | sdev_printk(KERN_ERR, scmd->device, "pci_map_sg" |
| 1086 | " failed: request for %d bytes!\n", scsi_bufflen(scmd)); |
| 1087 | return -ENOMEM; |
| 1088 | } |
| 1089 | |
| 1090 | sg_local = &mpi_request->SGL; |
| 1091 | sges_in_segment = ioc->max_sges_in_main_message; |
| 1092 | if (sges_left <= sges_in_segment) |
| 1093 | goto fill_in_last_segment; |
| 1094 | |
| 1095 | mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) + |
| 1096 | (sges_in_segment * ioc->sge_size))/4; |
| 1097 | |
| 1098 | /* fill in main message segment when there is a chain following */ |
| 1099 | while (sges_in_segment) { |
| 1100 | if (sges_in_segment == 1) |
| 1101 | ioc->base_add_sg_single(sg_local, |
| 1102 | sgl_flags_last_element | sg_dma_len(sg_scmd), |
| 1103 | sg_dma_address(sg_scmd)); |
| 1104 | else |
| 1105 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1106 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1107 | sg_scmd = sg_next(sg_scmd); |
| 1108 | sg_local += ioc->sge_size; |
| 1109 | sges_left--; |
| 1110 | sges_in_segment--; |
| 1111 | } |
| 1112 | |
| 1113 | /* initializing the chain flags and pointers */ |
| 1114 | chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT; |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1115 | chain_req = _scsih_get_chain_buffer_tracker(ioc, smid); |
| 1116 | if (!chain_req) |
| 1117 | return -1; |
| 1118 | chain = chain_req->chain_buffer; |
| 1119 | chain_dma = chain_req->chain_buffer_dma; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1120 | do { |
| 1121 | sges_in_segment = (sges_left <= |
| 1122 | ioc->max_sges_in_chain_message) ? sges_left : |
| 1123 | ioc->max_sges_in_chain_message; |
| 1124 | chain_offset = (sges_left == sges_in_segment) ? |
| 1125 | 0 : (sges_in_segment * ioc->sge_size)/4; |
| 1126 | chain_length = sges_in_segment * ioc->sge_size; |
| 1127 | if (chain_offset) { |
| 1128 | chain_offset = chain_offset << |
| 1129 | MPI2_SGE_CHAIN_OFFSET_SHIFT; |
| 1130 | chain_length += ioc->sge_size; |
| 1131 | } |
| 1132 | ioc->base_add_sg_single(sg_local, chain_flags | chain_offset | |
| 1133 | chain_length, chain_dma); |
| 1134 | sg_local = chain; |
| 1135 | if (!chain_offset) |
| 1136 | goto fill_in_last_segment; |
| 1137 | |
| 1138 | /* fill in chain segments */ |
| 1139 | while (sges_in_segment) { |
| 1140 | if (sges_in_segment == 1) |
| 1141 | ioc->base_add_sg_single(sg_local, |
| 1142 | sgl_flags_last_element | |
| 1143 | sg_dma_len(sg_scmd), |
| 1144 | sg_dma_address(sg_scmd)); |
| 1145 | else |
| 1146 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1147 | sg_dma_len(sg_scmd), |
| 1148 | sg_dma_address(sg_scmd)); |
| 1149 | sg_scmd = sg_next(sg_scmd); |
| 1150 | sg_local += ioc->sge_size; |
| 1151 | sges_left--; |
| 1152 | sges_in_segment--; |
| 1153 | } |
| 1154 | |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1155 | chain_req = _scsih_get_chain_buffer_tracker(ioc, smid); |
| 1156 | if (!chain_req) |
| 1157 | return -1; |
| 1158 | chain = chain_req->chain_buffer; |
| 1159 | chain_dma = chain_req->chain_buffer_dma; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1160 | } while (1); |
| 1161 | |
| 1162 | |
| 1163 | fill_in_last_segment: |
| 1164 | |
| 1165 | /* fill the last segment */ |
| 1166 | while (sges_left) { |
| 1167 | if (sges_left == 1) |
| 1168 | ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer | |
| 1169 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1170 | else |
| 1171 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1172 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1173 | sg_scmd = sg_next(sg_scmd); |
| 1174 | sg_local += ioc->sge_size; |
| 1175 | sges_left--; |
| 1176 | } |
| 1177 | |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
| 1181 | /** |
Christoph Hellwig | 286c940 | 2014-11-13 15:11:59 +0100 | [diff] [blame] | 1182 | * _scsih_change_queue_depth - setting device queue depth |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1183 | * @sdev: scsi device struct |
| 1184 | * @qdepth: requested queue depth |
| 1185 | * |
Christoph Hellwig | 286c940 | 2014-11-13 15:11:59 +0100 | [diff] [blame] | 1186 | * Returns queue depth. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1187 | */ |
Christoph Hellwig | 286c940 | 2014-11-13 15:11:59 +0100 | [diff] [blame] | 1188 | static int |
| 1189 | _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1190 | { |
| 1191 | struct Scsi_Host *shost = sdev->host; |
| 1192 | int max_depth; |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1193 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1194 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1195 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1196 | struct _sas_device *sas_device; |
| 1197 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1198 | |
| 1199 | max_depth = shost->can_queue; |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1200 | |
| 1201 | /* limit max device queue for SATA to 32 */ |
| 1202 | sas_device_priv_data = sdev->hostdata; |
| 1203 | if (!sas_device_priv_data) |
| 1204 | goto not_sata; |
| 1205 | sas_target_priv_data = sas_device_priv_data->sas_target; |
| 1206 | if (!sas_target_priv_data) |
| 1207 | goto not_sata; |
| 1208 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) |
| 1209 | goto not_sata; |
| 1210 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1211 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1212 | sas_device_priv_data->sas_target->sas_address); |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1213 | if (sas_device && sas_device->device_info & |
| 1214 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1215 | max_depth = MPT2SAS_SATA_QUEUE_DEPTH; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1216 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1217 | |
| 1218 | not_sata: |
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; |
Christoph Hellwig | 286c940 | 2014-11-13 15:11:59 +0100 | [diff] [blame] | 1223 | return scsi_change_queue_depth(sdev, qdepth); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1227 | * _scsih_target_alloc - target add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1228 | * @starget: scsi target struct |
| 1229 | * |
| 1230 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1231 | * the device is ignored. |
| 1232 | */ |
| 1233 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1234 | _scsih_target_alloc(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1235 | { |
| 1236 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1237 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1238 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1239 | struct _sas_device *sas_device; |
| 1240 | struct _raid_device *raid_device; |
| 1241 | unsigned long flags; |
| 1242 | struct sas_rphy *rphy; |
| 1243 | |
Joe Lawrence | feafe7c | 2014-06-25 17:03:14 -0400 | [diff] [blame] | 1244 | sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data), |
| 1245 | GFP_KERNEL); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1246 | if (!sas_target_priv_data) |
| 1247 | return -ENOMEM; |
| 1248 | |
| 1249 | starget->hostdata = sas_target_priv_data; |
| 1250 | sas_target_priv_data->starget = starget; |
| 1251 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; |
| 1252 | |
| 1253 | /* RAID volumes */ |
| 1254 | if (starget->channel == RAID_CHANNEL) { |
| 1255 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1256 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1257 | starget->channel); |
| 1258 | if (raid_device) { |
| 1259 | sas_target_priv_data->handle = raid_device->handle; |
| 1260 | sas_target_priv_data->sas_address = raid_device->wwid; |
| 1261 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1262 | if (ioc->is_warpdrive) |
| 1263 | sas_target_priv_data->raid_device = raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1264 | raid_device->starget = starget; |
| 1265 | } |
| 1266 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1267 | return 0; |
| 1268 | } |
| 1269 | |
| 1270 | /* sas/sata devices */ |
| 1271 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1272 | rphy = dev_to_rphy(starget->dev.parent); |
| 1273 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1274 | rphy->identify.sas_address); |
| 1275 | |
| 1276 | if (sas_device) { |
| 1277 | sas_target_priv_data->handle = sas_device->handle; |
| 1278 | sas_target_priv_data->sas_address = sas_device->sas_address; |
| 1279 | sas_device->starget = starget; |
| 1280 | sas_device->id = starget->id; |
| 1281 | sas_device->channel = starget->channel; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 1282 | if (test_bit(sas_device->handle, ioc->pd_handles)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1283 | sas_target_priv_data->flags |= |
| 1284 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 1285 | } |
| 1286 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1287 | |
| 1288 | return 0; |
| 1289 | } |
| 1290 | |
| 1291 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1292 | * _scsih_target_destroy - target destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1293 | * @starget: scsi target struct |
| 1294 | * |
| 1295 | * Returns nothing. |
| 1296 | */ |
| 1297 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1298 | _scsih_target_destroy(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1299 | { |
| 1300 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1301 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1302 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1303 | struct _sas_device *sas_device; |
| 1304 | struct _raid_device *raid_device; |
| 1305 | unsigned long flags; |
| 1306 | struct sas_rphy *rphy; |
| 1307 | |
| 1308 | sas_target_priv_data = starget->hostdata; |
| 1309 | if (!sas_target_priv_data) |
| 1310 | return; |
| 1311 | |
| 1312 | if (starget->channel == RAID_CHANNEL) { |
| 1313 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1314 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1315 | starget->channel); |
| 1316 | if (raid_device) { |
| 1317 | raid_device->starget = NULL; |
| 1318 | raid_device->sdev = NULL; |
| 1319 | } |
| 1320 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1321 | goto out; |
| 1322 | } |
| 1323 | |
| 1324 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1325 | rphy = dev_to_rphy(starget->dev.parent); |
| 1326 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1327 | rphy->identify.sas_address); |
Eric Moore | 8901cbb | 2009-04-21 15:41:32 -0600 | [diff] [blame] | 1328 | if (sas_device && (sas_device->starget == starget) && |
| 1329 | (sas_device->id == starget->id) && |
| 1330 | (sas_device->channel == starget->channel)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1331 | sas_device->starget = NULL; |
| 1332 | |
| 1333 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1334 | |
| 1335 | out: |
| 1336 | kfree(sas_target_priv_data); |
| 1337 | starget->hostdata = NULL; |
| 1338 | } |
| 1339 | |
| 1340 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1341 | * _scsih_slave_alloc - device add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1342 | * @sdev: scsi device struct |
| 1343 | * |
| 1344 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1345 | * the device is ignored. |
| 1346 | */ |
| 1347 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1348 | _scsih_slave_alloc(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1349 | { |
| 1350 | struct Scsi_Host *shost; |
| 1351 | struct MPT2SAS_ADAPTER *ioc; |
| 1352 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1353 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1354 | struct scsi_target *starget; |
| 1355 | struct _raid_device *raid_device; |
Sreekanth Reddy | 63e359d | 2013-07-25 11:32:51 +0530 | [diff] [blame] | 1356 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1357 | unsigned long flags; |
| 1358 | |
Joe Lawrence | feafe7c | 2014-06-25 17:03:14 -0400 | [diff] [blame] | 1359 | sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data), |
| 1360 | GFP_KERNEL); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1361 | if (!sas_device_priv_data) |
| 1362 | return -ENOMEM; |
| 1363 | |
| 1364 | sas_device_priv_data->lun = sdev->lun; |
| 1365 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; |
| 1366 | |
| 1367 | starget = scsi_target(sdev); |
| 1368 | sas_target_priv_data = starget->hostdata; |
| 1369 | sas_target_priv_data->num_luns++; |
| 1370 | sas_device_priv_data->sas_target = sas_target_priv_data; |
| 1371 | sdev->hostdata = sas_device_priv_data; |
| 1372 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) |
| 1373 | sdev->no_uld_attach = 1; |
| 1374 | |
| 1375 | shost = dev_to_shost(&starget->dev); |
| 1376 | ioc = shost_priv(shost); |
| 1377 | if (starget->channel == RAID_CHANNEL) { |
| 1378 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1379 | raid_device = _scsih_raid_device_find_by_id(ioc, |
| 1380 | starget->id, starget->channel); |
| 1381 | if (raid_device) |
| 1382 | raid_device->sdev = sdev; /* raid is single lun */ |
| 1383 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1384 | } |
| 1385 | |
Sreekanth Reddy | 63e359d | 2013-07-25 11:32:51 +0530 | [diff] [blame] | 1386 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
| 1387 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1388 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1389 | sas_target_priv_data->sas_address); |
| 1390 | if (sas_device && (sas_device->starget == NULL)) { |
| 1391 | sdev_printk(KERN_INFO, sdev, |
| 1392 | "%s : sas_device->starget set to starget @ %d\n", |
| 1393 | __func__, __LINE__); |
| 1394 | sas_device->starget = starget; |
| 1395 | } |
| 1396 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1397 | } |
| 1398 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1399 | return 0; |
| 1400 | } |
| 1401 | |
| 1402 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1403 | * _scsih_slave_destroy - device destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1404 | * @sdev: scsi device struct |
| 1405 | * |
| 1406 | * Returns nothing. |
| 1407 | */ |
| 1408 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1409 | _scsih_slave_destroy(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1410 | { |
| 1411 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1412 | struct scsi_target *starget; |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1413 | struct Scsi_Host *shost; |
| 1414 | struct MPT2SAS_ADAPTER *ioc; |
| 1415 | struct _sas_device *sas_device; |
| 1416 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1417 | |
| 1418 | if (!sdev->hostdata) |
| 1419 | return; |
| 1420 | |
| 1421 | starget = scsi_target(sdev); |
| 1422 | sas_target_priv_data = starget->hostdata; |
| 1423 | sas_target_priv_data->num_luns--; |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1424 | |
| 1425 | shost = dev_to_shost(&starget->dev); |
| 1426 | ioc = shost_priv(shost); |
| 1427 | |
| 1428 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
| 1429 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1430 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1431 | sas_target_priv_data->sas_address); |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 1432 | if (sas_device && !sas_target_priv_data->num_luns) |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1433 | sas_device->starget = NULL; |
| 1434 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1435 | } |
| 1436 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1437 | kfree(sdev->hostdata); |
| 1438 | sdev->hostdata = NULL; |
| 1439 | } |
| 1440 | |
| 1441 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1442 | * _scsih_display_sata_capabilities - sata capabilities |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1443 | * @ioc: per adapter object |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1444 | * @handle: device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1445 | * @sdev: scsi device struct |
| 1446 | */ |
| 1447 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1448 | _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1449 | u16 handle, struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1450 | { |
| 1451 | Mpi2ConfigReply_t mpi_reply; |
| 1452 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1453 | u32 ioc_status; |
| 1454 | u16 flags; |
| 1455 | u32 device_info; |
| 1456 | |
| 1457 | 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] | 1458 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1459 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1460 | ioc->name, __FILE__, __LINE__, __func__); |
| 1461 | return; |
| 1462 | } |
| 1463 | |
| 1464 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1465 | MPI2_IOCSTATUS_MASK; |
| 1466 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 1467 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1468 | ioc->name, __FILE__, __LINE__, __func__); |
| 1469 | return; |
| 1470 | } |
| 1471 | |
| 1472 | flags = le16_to_cpu(sas_device_pg0.Flags); |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 1473 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1474 | |
| 1475 | sdev_printk(KERN_INFO, sdev, |
| 1476 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " |
| 1477 | "sw_preserve(%s)\n", |
| 1478 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", |
| 1479 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", |
| 1480 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : |
| 1481 | "n", |
| 1482 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", |
| 1483 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", |
| 1484 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); |
| 1485 | } |
| 1486 | |
| 1487 | /** |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1488 | * _scsih_is_raid - return boolean indicating device is raid volume |
| 1489 | * @dev the device struct object |
| 1490 | */ |
| 1491 | static int |
| 1492 | _scsih_is_raid(struct device *dev) |
| 1493 | { |
| 1494 | struct scsi_device *sdev = to_scsi_device(dev); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1495 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1496 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1497 | if (ioc->is_warpdrive) |
| 1498 | return 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1499 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
| 1500 | } |
| 1501 | |
| 1502 | /** |
| 1503 | * _scsih_get_resync - get raid volume resync percent complete |
| 1504 | * @dev the device struct object |
| 1505 | */ |
| 1506 | static void |
| 1507 | _scsih_get_resync(struct device *dev) |
| 1508 | { |
| 1509 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1510 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1511 | static struct _raid_device *raid_device; |
| 1512 | unsigned long flags; |
| 1513 | Mpi2RaidVolPage0_t vol_pg0; |
| 1514 | Mpi2ConfigReply_t mpi_reply; |
| 1515 | u32 volume_status_flags; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1516 | u8 percent_complete; |
| 1517 | u16 handle; |
| 1518 | |
| 1519 | percent_complete = 0; |
| 1520 | handle = 0; |
| 1521 | if (ioc->is_warpdrive) |
| 1522 | goto out; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1523 | |
| 1524 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1525 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1526 | sdev->channel); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1527 | if (raid_device) { |
| 1528 | handle = raid_device->handle; |
| 1529 | percent_complete = raid_device->percent_complete; |
| 1530 | } |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1531 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1532 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1533 | if (!handle) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1534 | goto out; |
| 1535 | |
| 1536 | 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] | 1537 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1538 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1539 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1540 | ioc->name, __FILE__, __LINE__, __func__); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1541 | percent_complete = 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1542 | goto out; |
| 1543 | } |
| 1544 | |
| 1545 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1546 | if (!(volume_status_flags & |
| 1547 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) |
| 1548 | percent_complete = 0; |
| 1549 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1550 | out: |
| 1551 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); |
| 1552 | } |
| 1553 | |
| 1554 | /** |
| 1555 | * _scsih_get_state - get raid volume level |
| 1556 | * @dev the device struct object |
| 1557 | */ |
| 1558 | static void |
| 1559 | _scsih_get_state(struct device *dev) |
| 1560 | { |
| 1561 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1562 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1563 | static struct _raid_device *raid_device; |
| 1564 | unsigned long flags; |
| 1565 | Mpi2RaidVolPage0_t vol_pg0; |
| 1566 | Mpi2ConfigReply_t mpi_reply; |
| 1567 | u32 volstate; |
| 1568 | enum raid_state state = RAID_STATE_UNKNOWN; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1569 | u16 handle = 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1570 | |
| 1571 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1572 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1573 | sdev->channel); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1574 | if (raid_device) |
| 1575 | handle = raid_device->handle; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1576 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1577 | |
| 1578 | if (!raid_device) |
| 1579 | goto out; |
| 1580 | |
| 1581 | 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] | 1582 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1583 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1584 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1585 | ioc->name, __FILE__, __LINE__, __func__); |
| 1586 | goto out; |
| 1587 | } |
| 1588 | |
| 1589 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
| 1590 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { |
| 1591 | state = RAID_STATE_RESYNCING; |
| 1592 | goto out; |
| 1593 | } |
| 1594 | |
| 1595 | switch (vol_pg0.VolumeState) { |
| 1596 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
| 1597 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 1598 | state = RAID_STATE_ACTIVE; |
| 1599 | break; |
| 1600 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 1601 | state = RAID_STATE_DEGRADED; |
| 1602 | break; |
| 1603 | case MPI2_RAID_VOL_STATE_FAILED: |
| 1604 | case MPI2_RAID_VOL_STATE_MISSING: |
| 1605 | state = RAID_STATE_OFFLINE; |
| 1606 | break; |
| 1607 | } |
| 1608 | out: |
| 1609 | raid_set_state(mpt2sas_raid_template, dev, state); |
| 1610 | } |
| 1611 | |
| 1612 | /** |
| 1613 | * _scsih_set_level - set raid level |
| 1614 | * @sdev: scsi device struct |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1615 | * @volume_type: volume type |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1616 | */ |
| 1617 | static void |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1618 | _scsih_set_level(struct scsi_device *sdev, u8 volume_type) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1619 | { |
| 1620 | enum raid_level level = RAID_LEVEL_UNKNOWN; |
| 1621 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1622 | switch (volume_type) { |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1623 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 1624 | level = RAID_LEVEL_0; |
| 1625 | break; |
| 1626 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 1627 | level = RAID_LEVEL_10; |
| 1628 | break; |
| 1629 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 1630 | level = RAID_LEVEL_1E; |
| 1631 | break; |
| 1632 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 1633 | level = RAID_LEVEL_1; |
| 1634 | break; |
| 1635 | } |
| 1636 | |
| 1637 | raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level); |
| 1638 | } |
| 1639 | |
| 1640 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1641 | * _scsih_get_volume_capabilities - volume capabilities |
| 1642 | * @ioc: per adapter object |
| 1643 | * @sas_device: the raid_device object |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1644 | * |
| 1645 | * Returns 0 for success, else 1 |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1646 | */ |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1647 | static int |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1648 | _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc, |
| 1649 | struct _raid_device *raid_device) |
| 1650 | { |
| 1651 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1652 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1653 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1654 | Mpi2ConfigReply_t mpi_reply; |
| 1655 | u16 sz; |
| 1656 | u8 num_pds; |
| 1657 | |
| 1658 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1659 | &num_pds)) || !num_pds) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1660 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1661 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1662 | __func__)); |
| 1663 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | raid_device->num_pds = num_pds; |
| 1667 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1668 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1669 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1670 | if (!vol_pg0) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1671 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1672 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1673 | __func__)); |
| 1674 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1678 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1679 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1680 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1681 | __func__)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1682 | kfree(vol_pg0); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1683 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | raid_device->volume_type = vol_pg0->VolumeType; |
| 1687 | |
| 1688 | /* figure out what the underlying devices are by |
| 1689 | * obtaining the device_info bits for the 1st device |
| 1690 | */ |
| 1691 | if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1692 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1693 | vol_pg0->PhysDisk[0].PhysDiskNum))) { |
| 1694 | if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 1695 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 1696 | le16_to_cpu(pd_pg0.DevHandle)))) { |
| 1697 | raid_device->device_info = |
| 1698 | le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | kfree(vol_pg0); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1703 | return 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1704 | } |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1705 | /** |
| 1706 | * _scsih_disable_ddio - Disable direct I/O for all the volumes |
| 1707 | * @ioc: per adapter object |
| 1708 | */ |
| 1709 | static void |
| 1710 | _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc) |
| 1711 | { |
| 1712 | Mpi2RaidVolPage1_t vol_pg1; |
| 1713 | Mpi2ConfigReply_t mpi_reply; |
| 1714 | struct _raid_device *raid_device; |
| 1715 | u16 handle; |
| 1716 | u16 ioc_status; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1717 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1718 | |
| 1719 | handle = 0xFFFF; |
| 1720 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 1721 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 1722 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1723 | MPI2_IOCSTATUS_MASK; |
| 1724 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 1725 | break; |
| 1726 | handle = le16_to_cpu(vol_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1727 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1728 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 1729 | if (raid_device) |
| 1730 | raid_device->direct_io_enabled = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1731 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1732 | } |
| 1733 | return; |
| 1734 | } |
| 1735 | |
| 1736 | |
| 1737 | /** |
| 1738 | * _scsih_get_num_volumes - Get number of volumes in the ioc |
| 1739 | * @ioc: per adapter object |
| 1740 | */ |
| 1741 | static u8 |
| 1742 | _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc) |
| 1743 | { |
| 1744 | Mpi2RaidVolPage1_t vol_pg1; |
| 1745 | Mpi2ConfigReply_t mpi_reply; |
| 1746 | u16 handle; |
| 1747 | u8 vol_cnt = 0; |
| 1748 | u16 ioc_status; |
| 1749 | |
| 1750 | handle = 0xFFFF; |
| 1751 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 1752 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 1753 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1754 | MPI2_IOCSTATUS_MASK; |
| 1755 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 1756 | break; |
| 1757 | vol_cnt++; |
| 1758 | handle = le16_to_cpu(vol_pg1.DevHandle); |
| 1759 | } |
| 1760 | return vol_cnt; |
| 1761 | } |
| 1762 | |
| 1763 | |
| 1764 | /** |
| 1765 | * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O. |
| 1766 | * @ioc: per adapter object |
| 1767 | * @raid_device: the raid_device object |
| 1768 | */ |
| 1769 | static void |
| 1770 | _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc, |
| 1771 | struct _raid_device *raid_device) |
| 1772 | { |
| 1773 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1774 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1775 | Mpi2ConfigReply_t mpi_reply; |
| 1776 | u16 sz; |
| 1777 | u8 num_pds, count; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1778 | unsigned long stripe_sz, block_sz; |
| 1779 | u8 stripe_exp, block_exp; |
| 1780 | u64 dev_max_lba; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1781 | |
| 1782 | if (!ioc->is_warpdrive) |
| 1783 | return; |
| 1784 | |
| 1785 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) { |
| 1786 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1787 | "globally as drives are exposed\n", ioc->name); |
| 1788 | return; |
| 1789 | } |
| 1790 | if (_scsih_get_num_volumes(ioc) > 1) { |
| 1791 | _scsih_disable_ddio(ioc); |
| 1792 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1793 | "globally as number of drives > 1\n", ioc->name); |
| 1794 | return; |
| 1795 | } |
| 1796 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1797 | &num_pds)) || !num_pds) { |
| 1798 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1799 | "Failure in computing number of drives\n", ioc->name); |
| 1800 | return; |
| 1801 | } |
| 1802 | |
| 1803 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1804 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1805 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1806 | if (!vol_pg0) { |
| 1807 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1808 | "Memory allocation failure for RVPG0\n", ioc->name); |
| 1809 | return; |
| 1810 | } |
| 1811 | |
| 1812 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1813 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
| 1814 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1815 | "Failure in retrieving RVPG0\n", ioc->name); |
| 1816 | kfree(vol_pg0); |
| 1817 | return; |
| 1818 | } |
| 1819 | |
| 1820 | /* |
| 1821 | * WARPDRIVE:If number of physical disks in a volume exceeds the max pds |
| 1822 | * assumed for WARPDRIVE, disable direct I/O |
| 1823 | */ |
| 1824 | if (num_pds > MPT_MAX_WARPDRIVE_PDS) { |
| 1825 | printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled " |
| 1826 | "for the drive with handle(0x%04x): num_mem=%d, " |
| 1827 | "max_mem_allowed=%d\n", ioc->name, raid_device->handle, |
| 1828 | num_pds, MPT_MAX_WARPDRIVE_PDS); |
| 1829 | kfree(vol_pg0); |
| 1830 | return; |
| 1831 | } |
| 1832 | for (count = 0; count < num_pds; count++) { |
| 1833 | if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1834 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1835 | vol_pg0->PhysDisk[count].PhysDiskNum) || |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 1836 | le16_to_cpu(pd_pg0.DevHandle) == |
| 1837 | MPT2SAS_INVALID_DEVICE_HANDLE) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1838 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " |
| 1839 | "disabled for the drive with handle(0x%04x) member" |
| 1840 | "handle retrieval failed for member number=%d\n", |
| 1841 | ioc->name, raid_device->handle, |
| 1842 | vol_pg0->PhysDisk[count].PhysDiskNum); |
| 1843 | goto out_error; |
| 1844 | } |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1845 | /* Disable direct I/O if member drive lba exceeds 4 bytes */ |
| 1846 | dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA); |
| 1847 | if (dev_max_lba >> 32) { |
| 1848 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " |
| 1849 | "disabled for the drive with handle(0x%04x) member" |
| 1850 | "handle (0x%04x) unsupported max lba 0x%016llx\n", |
| 1851 | ioc->name, raid_device->handle, |
| 1852 | le16_to_cpu(pd_pg0.DevHandle), |
| 1853 | (unsigned long long)dev_max_lba); |
| 1854 | goto out_error; |
| 1855 | } |
| 1856 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1857 | raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle); |
| 1858 | } |
| 1859 | |
| 1860 | /* |
| 1861 | * 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] | 1862 | * not RAID0 |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1863 | */ |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1864 | if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1865 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1866 | "for the drive with handle(0x%04x): type=%d, " |
| 1867 | "s_sz=%uK, blk_size=%u\n", ioc->name, |
| 1868 | raid_device->handle, raid_device->volume_type, |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1869 | (le32_to_cpu(vol_pg0->StripeSize) * |
| 1870 | le16_to_cpu(vol_pg0->BlockSize)) / 1024, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1871 | le16_to_cpu(vol_pg0->BlockSize)); |
| 1872 | goto out_error; |
| 1873 | } |
| 1874 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1875 | stripe_sz = le32_to_cpu(vol_pg0->StripeSize); |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1876 | stripe_exp = find_first_bit(&stripe_sz, 32); |
| 1877 | if (stripe_exp == 32) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1878 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1879 | "for the drive with handle(0x%04x) invalid stripe sz %uK\n", |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1880 | ioc->name, raid_device->handle, |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1881 | (le32_to_cpu(vol_pg0->StripeSize) * |
| 1882 | le16_to_cpu(vol_pg0->BlockSize)) / 1024); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1883 | goto out_error; |
| 1884 | } |
| 1885 | raid_device->stripe_exponent = stripe_exp; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1886 | block_sz = le16_to_cpu(vol_pg0->BlockSize); |
| 1887 | block_exp = find_first_bit(&block_sz, 16); |
| 1888 | if (block_exp == 16) { |
| 1889 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1890 | "for the drive with handle(0x%04x) invalid block sz %u\n", |
| 1891 | ioc->name, raid_device->handle, |
| 1892 | le16_to_cpu(vol_pg0->BlockSize)); |
| 1893 | goto out_error; |
| 1894 | } |
| 1895 | raid_device->block_exponent = block_exp; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1896 | raid_device->direct_io_enabled = 1; |
| 1897 | |
| 1898 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive" |
| 1899 | " with handle(0x%04x)\n", ioc->name, raid_device->handle); |
| 1900 | /* |
| 1901 | * WARPDRIVE: Though the following fields are not used for direct IO, |
| 1902 | * stored for future purpose: |
| 1903 | */ |
| 1904 | raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA); |
| 1905 | raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize); |
| 1906 | raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize); |
| 1907 | |
| 1908 | |
| 1909 | kfree(vol_pg0); |
| 1910 | return; |
| 1911 | |
| 1912 | out_error: |
| 1913 | raid_device->direct_io_enabled = 0; |
| 1914 | for (count = 0; count < num_pds; count++) |
| 1915 | raid_device->pd_handle[count] = 0; |
| 1916 | kfree(vol_pg0); |
| 1917 | return; |
| 1918 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1919 | |
| 1920 | /** |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 1921 | * _scsih_enable_tlr - setting TLR flags |
| 1922 | * @ioc: per adapter object |
| 1923 | * @sdev: scsi device struct |
| 1924 | * |
| 1925 | * Enabling Transaction Layer Retries for tape devices when |
| 1926 | * vpd page 0x90 is present |
| 1927 | * |
| 1928 | */ |
| 1929 | static void |
| 1930 | _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev) |
| 1931 | { |
| 1932 | /* only for TAPE */ |
| 1933 | if (sdev->type != TYPE_TAPE) |
| 1934 | return; |
| 1935 | |
| 1936 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) |
| 1937 | return; |
| 1938 | |
| 1939 | sas_enable_tlr(sdev); |
| 1940 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", |
| 1941 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); |
| 1942 | return; |
| 1943 | |
| 1944 | } |
| 1945 | |
| 1946 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1947 | * _scsih_slave_configure - device configure routine. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1948 | * @sdev: scsi device struct |
| 1949 | * |
| 1950 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1951 | * the device is ignored. |
| 1952 | */ |
| 1953 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1954 | _scsih_slave_configure(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1955 | { |
| 1956 | struct Scsi_Host *shost = sdev->host; |
| 1957 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1958 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1959 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1960 | struct _sas_device *sas_device; |
| 1961 | struct _raid_device *raid_device; |
| 1962 | unsigned long flags; |
| 1963 | int qdepth; |
| 1964 | u8 ssp_target = 0; |
| 1965 | char *ds = ""; |
| 1966 | char *r_level = ""; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1967 | u16 handle, volume_handle = 0; |
| 1968 | u64 volume_wwid = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1969 | |
| 1970 | qdepth = 1; |
| 1971 | sas_device_priv_data = sdev->hostdata; |
| 1972 | sas_device_priv_data->configured_lun = 1; |
| 1973 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; |
| 1974 | sas_target_priv_data = sas_device_priv_data->sas_target; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1975 | handle = sas_target_priv_data->handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1976 | |
| 1977 | /* raid volume handling */ |
| 1978 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 1979 | |
| 1980 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1981 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1982 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1983 | if (!raid_device) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1984 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1985 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 1986 | __LINE__, __func__)); |
| 1987 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1988 | } |
| 1989 | |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1990 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { |
| 1991 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1992 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 1993 | __LINE__, __func__)); |
| 1994 | return 1; |
| 1995 | } |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1996 | /* |
| 1997 | * WARPDRIVE: Initialize the required data for Direct IO |
| 1998 | */ |
| 1999 | _scsih_init_warpdrive_properties(ioc, raid_device); |
| 2000 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2001 | /* RAID Queue Depth Support |
| 2002 | * IS volume = underlying qdepth of drive type, either |
| 2003 | * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH |
| 2004 | * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH) |
| 2005 | */ |
| 2006 | if (raid_device->device_info & |
| 2007 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 2008 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 2009 | ds = "SSP"; |
| 2010 | } else { |
| 2011 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 2012 | if (raid_device->device_info & |
| 2013 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 2014 | ds = "SATA"; |
| 2015 | else |
| 2016 | ds = "STP"; |
| 2017 | } |
| 2018 | |
| 2019 | switch (raid_device->volume_type) { |
| 2020 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 2021 | r_level = "RAID0"; |
| 2022 | break; |
| 2023 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 2024 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 2025 | if (ioc->manu_pg10.OEMIdentifier && |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 2026 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 2027 | MFG10_GF0_R10_DISPLAY) && |
| 2028 | !(raid_device->num_pds % 2)) |
| 2029 | r_level = "RAID10"; |
| 2030 | else |
| 2031 | r_level = "RAID1E"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2032 | break; |
| 2033 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 2034 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2035 | r_level = "RAID1"; |
| 2036 | break; |
| 2037 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 2038 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2039 | r_level = "RAID10"; |
| 2040 | break; |
| 2041 | case MPI2_RAID_VOL_TYPE_UNKNOWN: |
| 2042 | default: |
| 2043 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2044 | r_level = "RAIDX"; |
| 2045 | break; |
| 2046 | } |
| 2047 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2048 | if (!ioc->hide_ir_msg) |
| 2049 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
| 2050 | "wwid(0x%016llx), pd_count(%d), type(%s)\n", |
| 2051 | r_level, raid_device->handle, |
| 2052 | (unsigned long long)raid_device->wwid, |
| 2053 | raid_device->num_pds, ds); |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 2054 | _scsih_change_queue_depth(sdev, qdepth); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 2055 | /* raid transport support */ |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2056 | if (!ioc->is_warpdrive) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2057 | _scsih_set_level(sdev, raid_device->volume_type); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2058 | return 0; |
| 2059 | } |
| 2060 | |
| 2061 | /* non-raid handling */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2062 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2063 | if (mpt2sas_config_get_volume_handle(ioc, handle, |
| 2064 | &volume_handle)) { |
| 2065 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2066 | "failure at %s:%d/%s()!\n", ioc->name, |
| 2067 | __FILE__, __LINE__, __func__)); |
| 2068 | return 1; |
| 2069 | } |
| 2070 | if (volume_handle && mpt2sas_config_get_volume_wwid(ioc, |
| 2071 | volume_handle, &volume_wwid)) { |
| 2072 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2073 | "failure at %s:%d/%s()!\n", ioc->name, |
| 2074 | __FILE__, __LINE__, __func__)); |
| 2075 | return 1; |
| 2076 | } |
| 2077 | } |
| 2078 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2079 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2080 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2081 | sas_device_priv_data->sas_target->sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2082 | if (!sas_device) { |
| 2083 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2084 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2085 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2086 | __LINE__, __func__)); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2087 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2088 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2089 | sas_device->volume_handle = volume_handle; |
| 2090 | sas_device->volume_wwid = volume_wwid; |
| 2091 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 2092 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 2093 | ssp_target = 1; |
| 2094 | ds = "SSP"; |
| 2095 | } else { |
| 2096 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 2097 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
| 2098 | ds = "STP"; |
| 2099 | else if (sas_device->device_info & |
| 2100 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 2101 | ds = "SATA"; |
| 2102 | } |
| 2103 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
| 2104 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", |
| 2105 | ds, sas_device->handle, |
| 2106 | (unsigned long long)sas_device->sas_address, |
| 2107 | sas_device->phy, |
| 2108 | (unsigned long long)sas_device->device_name); |
| 2109 | sdev_printk(KERN_INFO, sdev, "%s: " |
| 2110 | "enclosure_logical_id(0x%016llx), slot(%d)\n", ds, |
| 2111 | (unsigned long long) sas_device->enclosure_logical_id, |
| 2112 | sas_device->slot); |
| 2113 | |
| 2114 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2115 | if (!ssp_target) |
| 2116 | _scsih_display_sata_capabilities(ioc, handle, sdev); |
| 2117 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2118 | |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 2119 | _scsih_change_queue_depth(sdev, qdepth); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2120 | |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 2121 | if (ssp_target) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2122 | sas_read_port_mode_page(sdev); |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 2123 | _scsih_enable_tlr(ioc, sdev); |
| 2124 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2125 | return 0; |
| 2126 | } |
| 2127 | |
| 2128 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2129 | * _scsih_bios_param - fetch head, sector, cylinder info for a disk |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2130 | * @sdev: scsi device struct |
| 2131 | * @bdev: pointer to block device context |
| 2132 | * @capacity: device size (in 512 byte sectors) |
| 2133 | * @params: three element array to place output: |
| 2134 | * params[0] number of heads (max 255) |
| 2135 | * params[1] number of sectors (max 63) |
| 2136 | * params[2] number of cylinders |
| 2137 | * |
| 2138 | * Return nothing. |
| 2139 | */ |
| 2140 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2141 | _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2142 | sector_t capacity, int params[]) |
| 2143 | { |
| 2144 | int heads; |
| 2145 | int sectors; |
| 2146 | sector_t cylinders; |
| 2147 | ulong dummy; |
| 2148 | |
| 2149 | heads = 64; |
| 2150 | sectors = 32; |
| 2151 | |
| 2152 | dummy = heads * sectors; |
| 2153 | cylinders = capacity; |
| 2154 | sector_div(cylinders, dummy); |
| 2155 | |
| 2156 | /* |
| 2157 | * Handle extended translation size for logical drives |
| 2158 | * > 1Gb |
| 2159 | */ |
| 2160 | if ((ulong)capacity >= 0x200000) { |
| 2161 | heads = 255; |
| 2162 | sectors = 63; |
| 2163 | dummy = heads * sectors; |
| 2164 | cylinders = capacity; |
| 2165 | sector_div(cylinders, dummy); |
| 2166 | } |
| 2167 | |
| 2168 | /* return result */ |
| 2169 | params[0] = heads; |
| 2170 | params[1] = sectors; |
| 2171 | params[2] = cylinders; |
| 2172 | |
| 2173 | return 0; |
| 2174 | } |
| 2175 | |
| 2176 | /** |
| 2177 | * _scsih_response_code - translation of device response code |
| 2178 | * @ioc: per adapter object |
| 2179 | * @response_code: response code returned by the device |
| 2180 | * |
| 2181 | * Return nothing. |
| 2182 | */ |
| 2183 | static void |
| 2184 | _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code) |
| 2185 | { |
| 2186 | char *desc; |
| 2187 | |
| 2188 | switch (response_code) { |
| 2189 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: |
| 2190 | desc = "task management request completed"; |
| 2191 | break; |
| 2192 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: |
| 2193 | desc = "invalid frame"; |
| 2194 | break; |
| 2195 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: |
| 2196 | desc = "task management request not supported"; |
| 2197 | break; |
| 2198 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: |
| 2199 | desc = "task management request failed"; |
| 2200 | break; |
| 2201 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: |
| 2202 | desc = "task management request succeeded"; |
| 2203 | break; |
| 2204 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: |
| 2205 | desc = "invalid lun"; |
| 2206 | break; |
| 2207 | case 0xA: |
| 2208 | desc = "overlapped tag attempted"; |
| 2209 | break; |
| 2210 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: |
| 2211 | desc = "task queued, however not sent to target"; |
| 2212 | break; |
| 2213 | default: |
| 2214 | desc = "unknown"; |
| 2215 | break; |
| 2216 | } |
| 2217 | printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n", |
| 2218 | ioc->name, response_code, desc); |
| 2219 | } |
| 2220 | |
| 2221 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2222 | * _scsih_tm_done - tm completion routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2223 | * @ioc: per adapter object |
| 2224 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2225 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2226 | * @reply: reply message frame(lower 32bit addr) |
| 2227 | * Context: none. |
| 2228 | * |
| 2229 | * The callback handler when using scsih_issue_tm. |
| 2230 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2231 | * Return 1 meaning mf should be freed from _base_interrupt |
| 2232 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2233 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2234 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2235 | _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] | 2236 | { |
| 2237 | MPI2DefaultReply_t *mpi_reply; |
| 2238 | |
| 2239 | if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2240 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2241 | if (ioc->tm_cmds.smid != smid) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2242 | return 1; |
nagalakshmi.nandigama@lsi.com | 911ae94 | 2011-09-08 06:18:50 +0530 | [diff] [blame] | 2243 | mpt2sas_base_flush_reply_queues(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2244 | ioc->tm_cmds.status |= MPT2_CMD_COMPLETE; |
| 2245 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 2246 | if (mpi_reply) { |
| 2247 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 2248 | ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 2249 | } |
| 2250 | ioc->tm_cmds.status &= ~MPT2_CMD_PENDING; |
| 2251 | complete(&ioc->tm_cmds.done); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2252 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | /** |
| 2256 | * mpt2sas_scsih_set_tm_flag - set per target tm_busy |
| 2257 | * @ioc: per adapter object |
| 2258 | * @handle: device handle |
| 2259 | * |
| 2260 | * During taskmangement request, we need to freeze the device queue. |
| 2261 | */ |
| 2262 | void |
| 2263 | mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2264 | { |
| 2265 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2266 | struct scsi_device *sdev; |
| 2267 | u8 skip = 0; |
| 2268 | |
| 2269 | shost_for_each_device(sdev, ioc->shost) { |
| 2270 | if (skip) |
| 2271 | continue; |
| 2272 | sas_device_priv_data = sdev->hostdata; |
| 2273 | if (!sas_device_priv_data) |
| 2274 | continue; |
| 2275 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2276 | sas_device_priv_data->sas_target->tm_busy = 1; |
| 2277 | skip = 1; |
| 2278 | ioc->ignore_loginfos = 1; |
| 2279 | } |
| 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | /** |
| 2284 | * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy |
| 2285 | * @ioc: per adapter object |
| 2286 | * @handle: device handle |
| 2287 | * |
| 2288 | * During taskmangement request, we need to freeze the device queue. |
| 2289 | */ |
| 2290 | void |
| 2291 | mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2292 | { |
| 2293 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2294 | struct scsi_device *sdev; |
| 2295 | u8 skip = 0; |
| 2296 | |
| 2297 | shost_for_each_device(sdev, ioc->shost) { |
| 2298 | if (skip) |
| 2299 | continue; |
| 2300 | sas_device_priv_data = sdev->hostdata; |
| 2301 | if (!sas_device_priv_data) |
| 2302 | continue; |
| 2303 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2304 | sas_device_priv_data->sas_target->tm_busy = 0; |
| 2305 | skip = 1; |
| 2306 | ioc->ignore_loginfos = 0; |
| 2307 | } |
| 2308 | } |
| 2309 | } |
| 2310 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2311 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2312 | /** |
| 2313 | * mpt2sas_scsih_issue_tm - main routine for sending tm requests |
| 2314 | * @ioc: per adapter struct |
| 2315 | * @device_handle: device handle |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2316 | * @channel: the channel assigned by the OS |
| 2317 | * @id: the id assigned by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2318 | * @lun: lun number |
| 2319 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) |
| 2320 | * @smid_task: smid assigned to the task |
| 2321 | * @timeout: timeout in seconds |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2322 | * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2323 | * Context: user |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2324 | * |
| 2325 | * A generic API for sending task management requests to firmware. |
| 2326 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2327 | * The callback index is set inside `ioc->tm_cb_idx`. |
| 2328 | * |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2329 | * Return SUCCESS or FAILED. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2330 | */ |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2331 | int |
| 2332 | mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel, |
| 2333 | uint id, uint lun, u8 type, u16 smid_task, ulong timeout, |
Matthew Wilcox | 2e45c8b | 2014-03-27 16:40:32 -0400 | [diff] [blame] | 2334 | enum mutex_type m_type) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2335 | { |
| 2336 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 2337 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
| 2338 | u16 smid = 0; |
| 2339 | u32 ioc_state; |
| 2340 | unsigned long timeleft; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2341 | struct scsiio_tracker *scsi_lookup = NULL; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2342 | int rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2343 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2344 | if (m_type == TM_MUTEX_ON) |
| 2345 | mutex_lock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2346 | if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) { |
| 2347 | printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n", |
| 2348 | __func__, ioc->name); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2349 | rc = FAILED; |
| 2350 | goto err_out; |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2351 | } |
| 2352 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 2353 | if (ioc->shost_recovery || ioc->remove_host || |
| 2354 | ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2355 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 2356 | __func__, ioc->name); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2357 | rc = FAILED; |
| 2358 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2359 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2360 | |
| 2361 | ioc_state = mpt2sas_base_get_iocstate(ioc, 0); |
| 2362 | if (ioc_state & MPI2_DOORBELL_USED) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 2363 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2364 | "active!\n", ioc->name)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2365 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2366 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2367 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2368 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 2372 | mpt2sas_base_fault_info(ioc, ioc_state & |
| 2373 | MPI2_DOORBELL_DATA_MASK); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2374 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2375 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2376 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2377 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2378 | } |
| 2379 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2380 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2381 | if (!smid) { |
| 2382 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 2383 | ioc->name, __func__); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2384 | rc = FAILED; |
| 2385 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2386 | } |
| 2387 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2388 | if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) |
| 2389 | scsi_lookup = &ioc->scsi_lookup[smid_task - 1]; |
| 2390 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2391 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x)," |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2392 | " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type, |
| 2393 | smid_task)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2394 | ioc->tm_cmds.status = MPT2_CMD_PENDING; |
| 2395 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 2396 | ioc->tm_cmds.smid = smid; |
| 2397 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2398 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2399 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 2400 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 2401 | mpi_request->TaskType = type; |
| 2402 | mpi_request->TaskMID = cpu_to_le16(smid_task); |
| 2403 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); |
| 2404 | mpt2sas_scsih_set_tm_flag(ioc, handle); |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 2405 | init_completion(&ioc->tm_cmds.done); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2406 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2407 | timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2408 | if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) { |
| 2409 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 2410 | ioc->name, __func__); |
| 2411 | _debug_dump_mf(mpi_request, |
| 2412 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2413 | if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) { |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2414 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2415 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2416 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2417 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
| 2418 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 2419 | goto err_out; |
| 2420 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 2424 | mpi_reply = ioc->tm_cmds.reply; |
| 2425 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: " |
| 2426 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", |
| 2427 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 2428 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 2429 | le32_to_cpu(mpi_reply->TerminationCount))); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2430 | if (ioc->logging_level & MPT_DEBUG_TM) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2431 | _scsih_response_code(ioc, mpi_reply->ResponseCode); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2432 | if (mpi_reply->IOCStatus) |
| 2433 | _debug_dump_mf(mpi_request, |
| 2434 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
| 2435 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2436 | } |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2437 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2438 | switch (type) { |
| 2439 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2440 | rc = SUCCESS; |
| 2441 | if (scsi_lookup->scmd == NULL) |
| 2442 | break; |
| 2443 | rc = FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2444 | break; |
| 2445 | |
| 2446 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: |
| 2447 | if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) |
| 2448 | rc = FAILED; |
| 2449 | else |
| 2450 | rc = SUCCESS; |
| 2451 | break; |
| 2452 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2453 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2454 | case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: |
| 2455 | if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) |
| 2456 | rc = FAILED; |
| 2457 | else |
| 2458 | rc = SUCCESS; |
| 2459 | break; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2460 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: |
| 2461 | rc = SUCCESS; |
| 2462 | break; |
| 2463 | default: |
| 2464 | rc = FAILED; |
| 2465 | break; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2466 | } |
| 2467 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2468 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 2469 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2470 | if (m_type == TM_MUTEX_ON) |
| 2471 | mutex_unlock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2472 | |
| 2473 | return rc; |
| 2474 | |
| 2475 | err_out: |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2476 | if (m_type == TM_MUTEX_ON) |
| 2477 | mutex_unlock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2478 | return rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | /** |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2482 | * _scsih_tm_display_info - displays info about the device |
| 2483 | * @ioc: per adapter struct |
| 2484 | * @scmd: pointer to scsi command object |
| 2485 | * |
| 2486 | * Called by task management callback handlers. |
| 2487 | */ |
| 2488 | static void |
| 2489 | _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) |
| 2490 | { |
| 2491 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2492 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; |
| 2493 | struct _sas_device *sas_device = NULL; |
| 2494 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2495 | char *device_str = NULL; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2496 | |
| 2497 | if (!priv_target) |
| 2498 | return; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2499 | if (ioc->hide_ir_msg) |
| 2500 | device_str = "WarpDrive"; |
| 2501 | else |
| 2502 | device_str = "volume"; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2503 | |
| 2504 | scsi_print_command(scmd); |
| 2505 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2506 | starget_printk(KERN_INFO, starget, "%s handle(0x%04x), " |
| 2507 | "%s wwid(0x%016llx)\n", device_str, priv_target->handle, |
| 2508 | device_str, (unsigned long long)priv_target->sas_address); |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2509 | } else { |
| 2510 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2511 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2512 | priv_target->sas_address); |
| 2513 | if (sas_device) { |
| 2514 | if (priv_target->flags & |
| 2515 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2516 | starget_printk(KERN_INFO, starget, |
| 2517 | "volume handle(0x%04x), " |
| 2518 | "volume wwid(0x%016llx)\n", |
| 2519 | sas_device->volume_handle, |
| 2520 | (unsigned long long)sas_device->volume_wwid); |
| 2521 | } |
| 2522 | starget_printk(KERN_INFO, starget, |
| 2523 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", |
| 2524 | sas_device->handle, |
| 2525 | (unsigned long long)sas_device->sas_address, |
| 2526 | sas_device->phy); |
| 2527 | starget_printk(KERN_INFO, starget, |
| 2528 | "enclosure_logical_id(0x%016llx), slot(%d)\n", |
| 2529 | (unsigned long long)sas_device->enclosure_logical_id, |
| 2530 | sas_device->slot); |
| 2531 | } |
| 2532 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2533 | } |
| 2534 | } |
| 2535 | |
| 2536 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2537 | * _scsih_abort - eh threads main abort routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2538 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2539 | * |
| 2540 | * Returns SUCCESS if command aborted else FAILED |
| 2541 | */ |
| 2542 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2543 | _scsih_abort(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2544 | { |
| 2545 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2546 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2547 | u16 smid; |
| 2548 | u16 handle; |
| 2549 | int r; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2550 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2551 | sdev_printk(KERN_INFO, scmd->device, "attempting task abort! " |
| 2552 | "scmd(%p)\n", scmd); |
| 2553 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2554 | |
| 2555 | sas_device_priv_data = scmd->device->hostdata; |
| 2556 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2557 | sdev_printk(KERN_INFO, scmd->device, "device been deleted! " |
| 2558 | "scmd(%p)\n", scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2559 | scmd->result = DID_NO_CONNECT << 16; |
| 2560 | scmd->scsi_done(scmd); |
| 2561 | r = SUCCESS; |
| 2562 | goto out; |
| 2563 | } |
| 2564 | |
| 2565 | /* search for the command */ |
| 2566 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); |
| 2567 | if (!smid) { |
| 2568 | scmd->result = DID_RESET << 16; |
| 2569 | r = SUCCESS; |
| 2570 | goto out; |
| 2571 | } |
| 2572 | |
| 2573 | /* for hidden raid components and volumes this is not supported */ |
| 2574 | if (sas_device_priv_data->sas_target->flags & |
| 2575 | MPT_TARGET_FLAGS_RAID_COMPONENT || |
| 2576 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 2577 | scmd->result = DID_RESET << 16; |
| 2578 | r = FAILED; |
| 2579 | goto out; |
| 2580 | } |
| 2581 | |
Kashyap, Desai | fa7f316 | 2009-09-23 17:26:58 +0530 | [diff] [blame] | 2582 | mpt2sas_halt_firmware(ioc); |
| 2583 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2584 | handle = sas_device_priv_data->sas_target->handle; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2585 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2586 | scmd->device->id, scmd->device->lun, |
Matthew Wilcox | 2e45c8b | 2014-03-27 16:40:32 -0400 | [diff] [blame] | 2587 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2588 | |
| 2589 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2590 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", |
| 2591 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2592 | return r; |
| 2593 | } |
| 2594 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2595 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2596 | * _scsih_dev_reset - eh threads main device reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2597 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2598 | * |
| 2599 | * Returns SUCCESS if command aborted else FAILED |
| 2600 | */ |
| 2601 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2602 | _scsih_dev_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2603 | { |
| 2604 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2605 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2606 | struct _sas_device *sas_device; |
| 2607 | unsigned long flags; |
| 2608 | u16 handle; |
| 2609 | int r; |
| 2610 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2611 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2612 | |
Kashyap, Desai | 37aaa78 | 2010-11-13 04:41:32 +0530 | [diff] [blame] | 2613 | starget_printk(KERN_INFO, starget, "attempting device reset! " |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2614 | "scmd(%p)\n", scmd); |
| 2615 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2616 | |
| 2617 | sas_device_priv_data = scmd->device->hostdata; |
| 2618 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 37aaa78 | 2010-11-13 04:41:32 +0530 | [diff] [blame] | 2619 | starget_printk(KERN_INFO, starget, "device been deleted! " |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2620 | "scmd(%p)\n", scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2621 | scmd->result = DID_NO_CONNECT << 16; |
| 2622 | scmd->scsi_done(scmd); |
| 2623 | r = SUCCESS; |
| 2624 | goto out; |
| 2625 | } |
| 2626 | |
| 2627 | /* for hidden raid components obtain the volume_handle */ |
| 2628 | handle = 0; |
| 2629 | if (sas_device_priv_data->sas_target->flags & |
| 2630 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2631 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2632 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2633 | sas_device_priv_data->sas_target->handle); |
| 2634 | if (sas_device) |
| 2635 | handle = sas_device->volume_handle; |
| 2636 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2637 | } else |
| 2638 | handle = sas_device_priv_data->sas_target->handle; |
| 2639 | |
| 2640 | if (!handle) { |
| 2641 | scmd->result = DID_RESET << 16; |
| 2642 | r = FAILED; |
| 2643 | goto out; |
| 2644 | } |
| 2645 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2646 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2647 | scmd->device->id, scmd->device->lun, |
Matthew Wilcox | 2e45c8b | 2014-03-27 16:40:32 -0400 | [diff] [blame] | 2648 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2649 | |
| 2650 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2651 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", |
| 2652 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2653 | return r; |
| 2654 | } |
| 2655 | |
| 2656 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2657 | * _scsih_target_reset - eh threads main target reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2658 | * @scmd: pointer to scsi command object |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2659 | * |
| 2660 | * Returns SUCCESS if command aborted else FAILED |
| 2661 | */ |
| 2662 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2663 | _scsih_target_reset(struct scsi_cmnd *scmd) |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2664 | { |
| 2665 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2666 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2667 | struct _sas_device *sas_device; |
| 2668 | unsigned long flags; |
| 2669 | u16 handle; |
| 2670 | int r; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2671 | struct scsi_target *starget = scmd->device->sdev_target; |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2672 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2673 | starget_printk(KERN_INFO, starget, "attempting target reset! " |
| 2674 | "scmd(%p)\n", scmd); |
| 2675 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2676 | |
| 2677 | sas_device_priv_data = scmd->device->hostdata; |
| 2678 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2679 | starget_printk(KERN_INFO, starget, "target been deleted! " |
| 2680 | "scmd(%p)\n", scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2681 | scmd->result = DID_NO_CONNECT << 16; |
| 2682 | scmd->scsi_done(scmd); |
| 2683 | r = SUCCESS; |
| 2684 | goto out; |
| 2685 | } |
| 2686 | |
| 2687 | /* for hidden raid components obtain the volume_handle */ |
| 2688 | handle = 0; |
| 2689 | if (sas_device_priv_data->sas_target->flags & |
| 2690 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2691 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2692 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2693 | sas_device_priv_data->sas_target->handle); |
| 2694 | if (sas_device) |
| 2695 | handle = sas_device->volume_handle; |
| 2696 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2697 | } else |
| 2698 | handle = sas_device_priv_data->sas_target->handle; |
| 2699 | |
| 2700 | if (!handle) { |
| 2701 | scmd->result = DID_RESET << 16; |
| 2702 | r = FAILED; |
| 2703 | goto out; |
| 2704 | } |
| 2705 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2706 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2707 | scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, |
Matthew Wilcox | 2e45c8b | 2014-03-27 16:40:32 -0400 | [diff] [blame] | 2708 | 30, TM_MUTEX_ON); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2709 | |
| 2710 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2711 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", |
| 2712 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2713 | return r; |
| 2714 | } |
| 2715 | |
| 2716 | /** |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2717 | * _scsih_host_reset - eh threads main host reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2718 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2719 | * |
| 2720 | * Returns SUCCESS if command aborted else FAILED |
| 2721 | */ |
| 2722 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2723 | _scsih_host_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2724 | { |
| 2725 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2726 | int r, retval; |
| 2727 | |
| 2728 | printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n", |
| 2729 | ioc->name, scmd); |
| 2730 | scsi_print_command(scmd); |
| 2731 | |
| 2732 | retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2733 | FORCE_BIG_HAMMER); |
| 2734 | r = (retval < 0) ? FAILED : SUCCESS; |
| 2735 | printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n", |
| 2736 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 2737 | |
| 2738 | return r; |
| 2739 | } |
| 2740 | |
| 2741 | /** |
| 2742 | * _scsih_fw_event_add - insert and queue up fw_event |
| 2743 | * @ioc: per adapter object |
| 2744 | * @fw_event: object describing the event |
| 2745 | * Context: This function will acquire ioc->fw_event_lock. |
| 2746 | * |
| 2747 | * This adds the firmware event object into link list, then queues it up to |
| 2748 | * be processed from user context. |
| 2749 | * |
| 2750 | * Return nothing. |
| 2751 | */ |
| 2752 | static void |
| 2753 | _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event) |
| 2754 | { |
| 2755 | unsigned long flags; |
| 2756 | |
| 2757 | if (ioc->firmware_event_thread == NULL) |
| 2758 | return; |
| 2759 | |
| 2760 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2761 | list_add_tail(&fw_event->list, &ioc->fw_event_list); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2762 | INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work); |
| 2763 | queue_delayed_work(ioc->firmware_event_thread, |
| 2764 | &fw_event->delayed_work, 0); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2765 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2766 | } |
| 2767 | |
| 2768 | /** |
| 2769 | * _scsih_fw_event_free - delete fw_event |
| 2770 | * @ioc: per adapter object |
| 2771 | * @fw_event: object describing the event |
| 2772 | * Context: This function will acquire ioc->fw_event_lock. |
| 2773 | * |
| 2774 | * This removes firmware event object from link list, frees associated memory. |
| 2775 | * |
| 2776 | * Return nothing. |
| 2777 | */ |
| 2778 | static void |
| 2779 | _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work |
| 2780 | *fw_event) |
| 2781 | { |
| 2782 | unsigned long flags; |
| 2783 | |
| 2784 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2785 | list_del(&fw_event->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2786 | kfree(fw_event); |
| 2787 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2788 | } |
| 2789 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2790 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2791 | /** |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2792 | * _scsih_error_recovery_delete_devices - remove devices not responding |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2793 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2794 | * |
| 2795 | * Return nothing. |
| 2796 | */ |
| 2797 | static void |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2798 | _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2799 | { |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2800 | struct fw_event_work *fw_event; |
| 2801 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2802 | if (ioc->is_driver_loading) |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2803 | return; |
Dan Carpenter | 181a9d7 | 2011-11-04 21:25:01 +0300 | [diff] [blame] | 2804 | |
| 2805 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2806 | if (!fw_event) |
| 2807 | return; |
| 2808 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2809 | fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES; |
| 2810 | fw_event->ioc = ioc; |
| 2811 | _scsih_fw_event_add(ioc, fw_event); |
| 2812 | } |
| 2813 | |
| 2814 | /** |
| 2815 | * mpt2sas_port_enable_complete - port enable completed (fake event) |
| 2816 | * @ioc: per adapter object |
| 2817 | * |
| 2818 | * Return nothing. |
| 2819 | */ |
| 2820 | void |
| 2821 | mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc) |
| 2822 | { |
| 2823 | struct fw_event_work *fw_event; |
| 2824 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2825 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2826 | if (!fw_event) |
| 2827 | return; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2828 | fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2829 | fw_event->ioc = ioc; |
| 2830 | _scsih_fw_event_add(ioc, fw_event); |
| 2831 | } |
| 2832 | |
| 2833 | /** |
| 2834 | * _scsih_fw_event_cleanup_queue - cleanup event queue |
| 2835 | * @ioc: per adapter object |
| 2836 | * |
| 2837 | * Walk the firmware event queue, either killing timers, or waiting |
| 2838 | * for outstanding events to complete |
| 2839 | * |
| 2840 | * Return nothing. |
| 2841 | */ |
| 2842 | static void |
| 2843 | _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc) |
| 2844 | { |
| 2845 | struct fw_event_work *fw_event, *next; |
| 2846 | |
| 2847 | if (list_empty(&ioc->fw_event_list) || |
| 2848 | !ioc->firmware_event_thread || in_interrupt()) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2849 | return; |
| 2850 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2851 | 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] | 2852 | if (cancel_delayed_work_sync(&fw_event->delayed_work)) { |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2853 | _scsih_fw_event_free(ioc, fw_event); |
| 2854 | continue; |
| 2855 | } |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2856 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2857 | } |
| 2858 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2859 | /** |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2860 | * _scsih_ublock_io_all_device - unblock every device |
| 2861 | * @ioc: per adapter object |
| 2862 | * |
| 2863 | * change the device state from block to running |
| 2864 | */ |
| 2865 | static void |
| 2866 | _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc) |
| 2867 | { |
| 2868 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2869 | struct scsi_device *sdev; |
| 2870 | |
| 2871 | shost_for_each_device(sdev, ioc->shost) { |
| 2872 | sas_device_priv_data = sdev->hostdata; |
| 2873 | if (!sas_device_priv_data) |
| 2874 | continue; |
| 2875 | if (!sas_device_priv_data->block) |
| 2876 | continue; |
| 2877 | sas_device_priv_data->block = 0; |
| 2878 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, " |
| 2879 | "handle(0x%04x)\n", |
| 2880 | sas_device_priv_data->sas_target->handle)); |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 2881 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2882 | } |
| 2883 | } |
| 2884 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2885 | * _scsih_ublock_io_device - set the device state to SDEV_RUNNING |
| 2886 | * @ioc: per adapter object |
| 2887 | * @handle: device handle |
| 2888 | * |
| 2889 | * During device pull we need to appropiately set the sdev state. |
| 2890 | */ |
| 2891 | static void |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2892 | _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2893 | { |
| 2894 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2895 | struct scsi_device *sdev; |
| 2896 | |
| 2897 | shost_for_each_device(sdev, ioc->shost) { |
| 2898 | sas_device_priv_data = sdev->hostdata; |
| 2899 | if (!sas_device_priv_data) |
| 2900 | continue; |
| 2901 | if (!sas_device_priv_data->block) |
| 2902 | continue; |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2903 | if (sas_device_priv_data->sas_target->sas_address == |
| 2904 | sas_address) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2905 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2906 | MPT2SAS_INFO_FMT "SDEV_RUNNING: " |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2907 | "sas address(0x%016llx)\n", ioc->name, |
| 2908 | (unsigned long long)sas_address)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2909 | sas_device_priv_data->block = 0; |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 2910 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2911 | } |
| 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | /** |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2916 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK |
| 2917 | * @ioc: per adapter object |
| 2918 | * @handle: device handle |
| 2919 | * |
| 2920 | * During device pull we need to appropiately set the sdev state. |
| 2921 | */ |
| 2922 | static void |
| 2923 | _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc) |
| 2924 | { |
| 2925 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2926 | struct scsi_device *sdev; |
| 2927 | |
| 2928 | shost_for_each_device(sdev, ioc->shost) { |
| 2929 | sas_device_priv_data = sdev->hostdata; |
| 2930 | if (!sas_device_priv_data) |
| 2931 | continue; |
| 2932 | if (sas_device_priv_data->block) |
| 2933 | continue; |
| 2934 | sas_device_priv_data->block = 1; |
| 2935 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, " |
| 2936 | "handle(0x%04x)\n", |
| 2937 | sas_device_priv_data->sas_target->handle)); |
| 2938 | scsi_internal_device_block(sdev); |
| 2939 | } |
| 2940 | } |
| 2941 | |
| 2942 | |
| 2943 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2944 | * _scsih_block_io_device - set the device state to SDEV_BLOCK |
| 2945 | * @ioc: per adapter object |
| 2946 | * @handle: device handle |
| 2947 | * |
| 2948 | * During device pull we need to appropiately set the sdev state. |
| 2949 | */ |
| 2950 | static void |
| 2951 | _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2952 | { |
| 2953 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2954 | struct scsi_device *sdev; |
| 2955 | |
| 2956 | shost_for_each_device(sdev, ioc->shost) { |
| 2957 | sas_device_priv_data = sdev->hostdata; |
| 2958 | if (!sas_device_priv_data) |
| 2959 | continue; |
| 2960 | if (sas_device_priv_data->block) |
| 2961 | continue; |
| 2962 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2963 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2964 | MPT2SAS_INFO_FMT "SDEV_BLOCK: " |
| 2965 | "handle(0x%04x)\n", ioc->name, handle)); |
| 2966 | sas_device_priv_data->block = 1; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 2967 | scsi_internal_device_block(sdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2968 | } |
| 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | /** |
| 2973 | * _scsih_block_io_to_children_attached_to_ex |
| 2974 | * @ioc: per adapter object |
| 2975 | * @sas_expander: the sas_device object |
| 2976 | * |
| 2977 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 2978 | * attached to this expander. This function called when expander is |
| 2979 | * pulled. |
| 2980 | */ |
| 2981 | static void |
| 2982 | _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc, |
| 2983 | struct _sas_node *sas_expander) |
| 2984 | { |
| 2985 | struct _sas_port *mpt2sas_port; |
| 2986 | struct _sas_device *sas_device; |
| 2987 | struct _sas_node *expander_sibling; |
| 2988 | unsigned long flags; |
| 2989 | |
| 2990 | if (!sas_expander) |
| 2991 | return; |
| 2992 | |
| 2993 | list_for_each_entry(mpt2sas_port, |
| 2994 | &sas_expander->sas_port_list, port_list) { |
| 2995 | if (mpt2sas_port->remote_identify.device_type == |
| 2996 | SAS_END_DEVICE) { |
| 2997 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2998 | sas_device = |
| 2999 | mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 3000 | mpt2sas_port->remote_identify.sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 3001 | if (sas_device) |
| 3002 | set_bit(sas_device->handle, |
| 3003 | ioc->blocking_handles); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3004 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3005 | } |
| 3006 | } |
| 3007 | |
| 3008 | list_for_each_entry(mpt2sas_port, |
| 3009 | &sas_expander->sas_port_list, port_list) { |
| 3010 | |
| 3011 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 3012 | SAS_EDGE_EXPANDER_DEVICE || |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3013 | mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 3014 | SAS_FANOUT_EXPANDER_DEVICE) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3015 | expander_sibling = |
| 3016 | mpt2sas_scsih_expander_find_by_sas_address( |
| 3017 | ioc, mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3018 | _scsih_block_io_to_children_attached_to_ex(ioc, |
| 3019 | expander_sibling); |
| 3020 | } |
| 3021 | } |
| 3022 | } |
| 3023 | |
| 3024 | /** |
| 3025 | * _scsih_block_io_to_children_attached_directly |
| 3026 | * @ioc: per adapter object |
| 3027 | * @event_data: topology change event data |
| 3028 | * |
| 3029 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 3030 | * direct attached during device pull. |
| 3031 | */ |
| 3032 | static void |
| 3033 | _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc, |
| 3034 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3035 | { |
| 3036 | int i; |
| 3037 | u16 handle; |
| 3038 | u16 reason_code; |
| 3039 | u8 phy_number; |
| 3040 | |
| 3041 | for (i = 0; i < event_data->NumEntries; i++) { |
| 3042 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3043 | if (!handle) |
| 3044 | continue; |
| 3045 | phy_number = event_data->StartPhyNum + i; |
| 3046 | reason_code = event_data->PHY[i].PhyStatus & |
| 3047 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3048 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) |
| 3049 | _scsih_block_io_device(ioc, handle); |
| 3050 | } |
| 3051 | } |
| 3052 | |
| 3053 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3054 | * _scsih_tm_tr_send - send task management request |
| 3055 | * @ioc: per adapter object |
| 3056 | * @handle: device handle |
| 3057 | * Context: interrupt time. |
| 3058 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3059 | * This code is to initiate the device removal handshake protocol |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3060 | * with controller firmware. This function will issue target reset |
| 3061 | * using high priority request queue. It will send a sas iounit |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3062 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3063 | * |
| 3064 | * This is designed to send muliple task management request at the same |
| 3065 | * time to the fifo. If the fifo is full, we will append the request, |
| 3066 | * and process it in a future completion. |
| 3067 | */ |
| 3068 | static void |
| 3069 | _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3070 | { |
| 3071 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3072 | u16 smid; |
| 3073 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3074 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; |
| 3075 | u64 sas_address = 0; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3076 | unsigned long flags; |
| 3077 | struct _tr_list *delayed_tr; |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3078 | u32 ioc_state; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3079 | |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3080 | if (ioc->remove_host) { |
| 3081 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been " |
| 3082 | "removed: handle(0x%04x)\n", __func__, ioc->name, handle)); |
| 3083 | return; |
| 3084 | } else if (ioc->pci_error_recovery) { |
| 3085 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci " |
| 3086 | "error recovery: handle(0x%04x)\n", __func__, ioc->name, |
| 3087 | handle)); |
| 3088 | return; |
| 3089 | } |
| 3090 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 3091 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 3092 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not " |
| 3093 | "operational: handle(0x%04x)\n", __func__, ioc->name, |
| 3094 | handle)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3095 | return; |
| 3096 | } |
| 3097 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3098 | /* if PD, then return */ |
| 3099 | if (test_bit(handle, ioc->pd_handles)) |
| 3100 | return; |
| 3101 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3102 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3103 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3104 | if (sas_device && sas_device->starget && |
| 3105 | sas_device->starget->hostdata) { |
| 3106 | sas_target_priv_data = sas_device->starget->hostdata; |
| 3107 | sas_target_priv_data->deleted = 1; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3108 | sas_address = sas_device->sas_address; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3109 | } |
| 3110 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3111 | |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3112 | if (sas_target_priv_data) { |
| 3113 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: " |
| 3114 | "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle, |
| 3115 | (unsigned long long)sas_address)); |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 3116 | _scsih_ublock_io_device(ioc, sas_address); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 3117 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3118 | } |
| 3119 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3120 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); |
| 3121 | if (!smid) { |
| 3122 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3123 | if (!delayed_tr) |
| 3124 | return; |
| 3125 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3126 | delayed_tr->handle = handle; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3127 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 3128 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3129 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 3130 | ioc->name, handle)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3131 | return; |
| 3132 | } |
| 3133 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3134 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " |
| 3135 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, |
| 3136 | ioc->tm_tr_cb_idx)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3137 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3138 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 3139 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3140 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3141 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3142 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
| 3143 | } |
| 3144 | |
| 3145 | |
| 3146 | |
| 3147 | /** |
| 3148 | * _scsih_sas_control_complete - completion routine |
| 3149 | * @ioc: per adapter object |
| 3150 | * @smid: system request message index |
| 3151 | * @msix_index: MSIX table index supplied by the OS |
| 3152 | * @reply: reply message frame(lower 32bit addr) |
| 3153 | * Context: interrupt time. |
| 3154 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3155 | * This is the sas iounit control completion routine. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3156 | * 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] | 3157 | * handshake protocol with controller firmware. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3158 | * |
| 3159 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3160 | * 0 means the mf is freed from this function. |
| 3161 | */ |
| 3162 | static u8 |
| 3163 | _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 3164 | u8 msix_index, u32 reply) |
| 3165 | { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3166 | Mpi2SasIoUnitControlReply_t *mpi_reply = |
| 3167 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3168 | if (likely(mpi_reply)) { |
| 3169 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3170 | "sc_complete:handle(0x%04x), (open) " |
| 3171 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 3172 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, |
| 3173 | le16_to_cpu(mpi_reply->IOCStatus), |
| 3174 | le32_to_cpu(mpi_reply->IOCLogInfo))); |
| 3175 | } else { |
| 3176 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3177 | ioc->name, __FILE__, __LINE__, __func__); |
| 3178 | } |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3179 | return 1; |
| 3180 | } |
| 3181 | |
| 3182 | /** |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3183 | * _scsih_tm_tr_volume_send - send target reset request for volumes |
| 3184 | * @ioc: per adapter object |
| 3185 | * @handle: device handle |
| 3186 | * Context: interrupt time. |
| 3187 | * |
| 3188 | * This is designed to send muliple task management request at the same |
| 3189 | * time to the fifo. If the fifo is full, we will append the request, |
| 3190 | * and process it in a future completion. |
| 3191 | */ |
| 3192 | static void |
| 3193 | _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3194 | { |
| 3195 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 3196 | u16 smid; |
| 3197 | struct _tr_list *delayed_tr; |
| 3198 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3199 | if (ioc->shost_recovery || ioc->remove_host || |
| 3200 | ioc->pci_error_recovery) { |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3201 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3202 | "progress!\n", __func__, ioc->name)); |
| 3203 | return; |
| 3204 | } |
| 3205 | |
| 3206 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); |
| 3207 | if (!smid) { |
| 3208 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3209 | if (!delayed_tr) |
| 3210 | return; |
| 3211 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3212 | delayed_tr->handle = handle; |
| 3213 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); |
| 3214 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3215 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 3216 | ioc->name, handle)); |
| 3217 | return; |
| 3218 | } |
| 3219 | |
| 3220 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " |
| 3221 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, |
| 3222 | ioc->tm_tr_volume_cb_idx)); |
| 3223 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3224 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 3225 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3226 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3227 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
| 3228 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
| 3229 | } |
| 3230 | |
| 3231 | /** |
| 3232 | * _scsih_tm_volume_tr_complete - target reset completion |
| 3233 | * @ioc: per adapter object |
| 3234 | * @smid: system request message index |
| 3235 | * @msix_index: MSIX table index supplied by the OS |
| 3236 | * @reply: reply message frame(lower 32bit addr) |
| 3237 | * Context: interrupt time. |
| 3238 | * |
| 3239 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3240 | * 0 means the mf is freed from this function. |
| 3241 | */ |
| 3242 | static u8 |
| 3243 | _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 3244 | u8 msix_index, u32 reply) |
| 3245 | { |
| 3246 | u16 handle; |
| 3247 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
| 3248 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3249 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 3250 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3251 | if (ioc->shost_recovery || ioc->remove_host || |
| 3252 | ioc->pci_error_recovery) { |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3253 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3254 | "progress!\n", __func__, ioc->name)); |
| 3255 | return 1; |
| 3256 | } |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3257 | if (unlikely(!mpi_reply)) { |
| 3258 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3259 | ioc->name, __FILE__, __LINE__, __func__); |
| 3260 | return 1; |
| 3261 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3262 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3263 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3264 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3265 | dewtprintk(ioc, printk("spurious interrupt: " |
| 3266 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle, |
| 3267 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3268 | return 0; |
| 3269 | } |
| 3270 | |
| 3271 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3272 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3273 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3274 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3275 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3276 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3277 | |
| 3278 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3279 | } |
| 3280 | |
| 3281 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3282 | * _scsih_tm_tr_complete - |
| 3283 | * @ioc: per adapter object |
| 3284 | * @smid: system request message index |
| 3285 | * @msix_index: MSIX table index supplied by the OS |
| 3286 | * @reply: reply message frame(lower 32bit addr) |
| 3287 | * Context: interrupt time. |
| 3288 | * |
| 3289 | * This is the target reset completion routine. |
| 3290 | * 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] | 3291 | * handshake protocol with controller firmware. |
| 3292 | * 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] | 3293 | * |
| 3294 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3295 | * 0 means the mf is freed from this function. |
| 3296 | */ |
| 3297 | static u8 |
| 3298 | _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 3299 | u32 reply) |
| 3300 | { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3301 | u16 handle; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3302 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3303 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3304 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 3305 | Mpi2SasIoUnitControlRequest_t *mpi_request; |
| 3306 | u16 smid_sas_ctrl; |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3307 | u32 ioc_state; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3308 | |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3309 | if (ioc->remove_host) { |
| 3310 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been " |
| 3311 | "removed\n", __func__, ioc->name)); |
| 3312 | return 1; |
| 3313 | } else if (ioc->pci_error_recovery) { |
| 3314 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci " |
| 3315 | "error recovery\n", __func__, ioc->name)); |
| 3316 | return 1; |
| 3317 | } |
| 3318 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 3319 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 3320 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not " |
| 3321 | "operational\n", __func__, ioc->name)); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3322 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3323 | } |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3324 | if (unlikely(!mpi_reply)) { |
| 3325 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3326 | ioc->name, __FILE__, __LINE__, __func__); |
| 3327 | return 1; |
| 3328 | } |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3329 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3330 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3331 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3332 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: " |
| 3333 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle, |
| 3334 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3335 | return 0; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3336 | } |
| 3337 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3338 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3339 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3340 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3341 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3342 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3343 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3344 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3345 | smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); |
| 3346 | if (!smid_sas_ctrl) { |
| 3347 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 3348 | ioc->name, __func__); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3349 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3350 | } |
| 3351 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3352 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), " |
| 3353 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl, |
| 3354 | ioc->tm_sas_control_cb_idx)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3355 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl); |
| 3356 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); |
| 3357 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; |
| 3358 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3359 | mpi_request->DevHandle = mpi_request_tm->DevHandle; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3360 | mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3361 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3362 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3363 | } |
| 3364 | |
| 3365 | /** |
| 3366 | * _scsih_check_for_pending_tm - check for pending task management |
| 3367 | * @ioc: per adapter object |
| 3368 | * @smid: system request message index |
| 3369 | * |
| 3370 | * This will check delayed target reset list, and feed the |
| 3371 | * next reqeust. |
| 3372 | * |
| 3373 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3374 | * 0 means the mf is freed from this function. |
| 3375 | */ |
| 3376 | static u8 |
| 3377 | _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 3378 | { |
| 3379 | struct _tr_list *delayed_tr; |
| 3380 | |
| 3381 | if (!list_empty(&ioc->delayed_tr_volume_list)) { |
| 3382 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, |
| 3383 | struct _tr_list, list); |
| 3384 | mpt2sas_base_free_smid(ioc, smid); |
| 3385 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); |
| 3386 | list_del(&delayed_tr->list); |
| 3387 | kfree(delayed_tr); |
| 3388 | return 0; |
| 3389 | } |
| 3390 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3391 | if (!list_empty(&ioc->delayed_tr_list)) { |
| 3392 | delayed_tr = list_entry(ioc->delayed_tr_list.next, |
| 3393 | struct _tr_list, list); |
| 3394 | mpt2sas_base_free_smid(ioc, smid); |
| 3395 | _scsih_tm_tr_send(ioc, delayed_tr->handle); |
| 3396 | list_del(&delayed_tr->list); |
| 3397 | kfree(delayed_tr); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3398 | return 0; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3399 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3400 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3401 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3405 | * _scsih_check_topo_delete_events - sanity check on topo events |
| 3406 | * @ioc: per adapter object |
| 3407 | * @event_data: the event data payload |
| 3408 | * |
| 3409 | * This routine added to better handle cable breaker. |
| 3410 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3411 | * This handles the case where driver receives multiple expander |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3412 | * add and delete events in a single shot. When there is a delete event |
| 3413 | * the routine will void any pending add events waiting in the event queue. |
| 3414 | * |
| 3415 | * Return nothing. |
| 3416 | */ |
| 3417 | static void |
| 3418 | _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 3419 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3420 | { |
| 3421 | struct fw_event_work *fw_event; |
| 3422 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; |
| 3423 | u16 expander_handle; |
| 3424 | struct _sas_node *sas_expander; |
| 3425 | unsigned long flags; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3426 | int i, reason_code; |
| 3427 | u16 handle; |
| 3428 | |
| 3429 | for (i = 0 ; i < event_data->NumEntries; i++) { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3430 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3431 | if (!handle) |
| 3432 | continue; |
| 3433 | reason_code = event_data->PHY[i].PhyStatus & |
| 3434 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3435 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) |
| 3436 | _scsih_tm_tr_send(ioc, handle); |
| 3437 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3438 | |
| 3439 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 3440 | if (expander_handle < ioc->sas_hba.num_phys) { |
| 3441 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3442 | return; |
| 3443 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 3444 | if (event_data->ExpStatus == |
| 3445 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { |
| 3446 | /* put expander attached devices into blocking state */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3447 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 3448 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 3449 | expander_handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3450 | _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] | 3451 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 3452 | do { |
| 3453 | handle = find_first_bit(ioc->blocking_handles, |
| 3454 | ioc->facts.MaxDevHandle); |
| 3455 | if (handle < ioc->facts.MaxDevHandle) |
| 3456 | _scsih_block_io_device(ioc, handle); |
| 3457 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3458 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) |
| 3459 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3460 | |
| 3461 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) |
| 3462 | return; |
| 3463 | |
| 3464 | /* mark ignore flag for pending events */ |
| 3465 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 3466 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { |
| 3467 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || |
| 3468 | fw_event->ignore) |
| 3469 | continue; |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 3470 | local_event_data = (Mpi2EventDataSasTopologyChangeList_t *) |
| 3471 | fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3472 | if (local_event_data->ExpStatus == |
| 3473 | MPI2_EVENT_SAS_TOPO_ES_ADDED || |
| 3474 | local_event_data->ExpStatus == |
| 3475 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { |
| 3476 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == |
| 3477 | expander_handle) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 3478 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3479 | "setting ignoring flag\n", ioc->name)); |
| 3480 | fw_event->ignore = 1; |
| 3481 | } |
| 3482 | } |
| 3483 | } |
| 3484 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 3485 | } |
| 3486 | |
| 3487 | /** |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3488 | * _scsih_set_volume_delete_flag - setting volume delete flag |
| 3489 | * @ioc: per adapter object |
| 3490 | * @handle: device handle |
| 3491 | * |
| 3492 | * This |
| 3493 | * Return nothing. |
| 3494 | */ |
| 3495 | static void |
| 3496 | _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3497 | { |
| 3498 | struct _raid_device *raid_device; |
| 3499 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 3500 | unsigned long flags; |
| 3501 | |
| 3502 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 3503 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 3504 | if (raid_device && raid_device->starget && |
| 3505 | raid_device->starget->hostdata) { |
| 3506 | sas_target_priv_data = |
| 3507 | raid_device->starget->hostdata; |
| 3508 | sas_target_priv_data->deleted = 1; |
| 3509 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3510 | "setting delete flag: handle(0x%04x), " |
| 3511 | "wwid(0x%016llx)\n", ioc->name, handle, |
| 3512 | (unsigned long long) raid_device->wwid)); |
| 3513 | } |
| 3514 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 3515 | } |
| 3516 | |
| 3517 | /** |
| 3518 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume |
| 3519 | * @handle: input handle |
| 3520 | * @a: handle for volume a |
| 3521 | * @b: handle for volume b |
| 3522 | * |
| 3523 | * IR firmware only supports two raid volumes. The purpose of this |
| 3524 | * routine is to set the volume handle in either a or b. When the given |
| 3525 | * input handle is non-zero, or when a and b have not been set before. |
| 3526 | */ |
| 3527 | static void |
| 3528 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) |
| 3529 | { |
| 3530 | if (!handle || handle == *a || handle == *b) |
| 3531 | return; |
| 3532 | if (!*a) |
| 3533 | *a = handle; |
| 3534 | else if (!*b) |
| 3535 | *b = handle; |
| 3536 | } |
| 3537 | |
| 3538 | /** |
| 3539 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events |
| 3540 | * @ioc: per adapter object |
| 3541 | * @event_data: the event data payload |
| 3542 | * Context: interrupt time. |
| 3543 | * |
| 3544 | * This routine will send target reset to volume, followed by target |
| 3545 | * resets to the PDs. This is called when a PD has been removed, or |
| 3546 | * volume has been deleted or removed. When the target reset is sent |
| 3547 | * to volume, the PD target resets need to be queued to start upon |
| 3548 | * completion of the volume target reset. |
| 3549 | * |
| 3550 | * Return nothing. |
| 3551 | */ |
| 3552 | static void |
| 3553 | _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc, |
| 3554 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 3555 | { |
| 3556 | Mpi2EventIrConfigElement_t *element; |
| 3557 | int i; |
| 3558 | u16 handle, volume_handle, a, b; |
| 3559 | struct _tr_list *delayed_tr; |
| 3560 | |
| 3561 | a = 0; |
| 3562 | b = 0; |
| 3563 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3564 | if (ioc->is_warpdrive) |
| 3565 | return; |
| 3566 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3567 | /* Volume Resets for Deleted or Removed */ |
| 3568 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3569 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3570 | if (element->ReasonCode == |
| 3571 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || |
| 3572 | element->ReasonCode == |
| 3573 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { |
| 3574 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3575 | _scsih_set_volume_delete_flag(ioc, volume_handle); |
| 3576 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3577 | } |
| 3578 | } |
| 3579 | |
| 3580 | /* Volume Resets for UNHIDE events */ |
| 3581 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3582 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3583 | if (le32_to_cpu(event_data->Flags) & |
| 3584 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) |
| 3585 | continue; |
| 3586 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { |
| 3587 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3588 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3589 | } |
| 3590 | } |
| 3591 | |
| 3592 | if (a) |
| 3593 | _scsih_tm_tr_volume_send(ioc, a); |
| 3594 | if (b) |
| 3595 | _scsih_tm_tr_volume_send(ioc, b); |
| 3596 | |
| 3597 | /* PD target resets */ |
| 3598 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3599 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3600 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) |
| 3601 | continue; |
| 3602 | handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 3603 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3604 | clear_bit(handle, ioc->pd_handles); |
| 3605 | if (!volume_handle) |
| 3606 | _scsih_tm_tr_send(ioc, handle); |
| 3607 | else if (volume_handle == a || volume_handle == b) { |
| 3608 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3609 | BUG_ON(!delayed_tr); |
| 3610 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3611 | delayed_tr->handle = handle; |
| 3612 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 3613 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3614 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, |
| 3615 | handle)); |
| 3616 | } else |
| 3617 | _scsih_tm_tr_send(ioc, handle); |
| 3618 | } |
| 3619 | } |
| 3620 | |
| 3621 | |
| 3622 | /** |
| 3623 | * _scsih_check_volume_delete_events - set delete flag for volumes |
| 3624 | * @ioc: per adapter object |
| 3625 | * @event_data: the event data payload |
| 3626 | * Context: interrupt time. |
| 3627 | * |
| 3628 | * This will handle the case when the cable connected to entire volume is |
| 3629 | * pulled. We will take care of setting the deleted flag so normal IO will |
| 3630 | * not be sent. |
| 3631 | * |
| 3632 | * Return nothing. |
| 3633 | */ |
| 3634 | static void |
| 3635 | _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 3636 | Mpi2EventDataIrVolume_t *event_data) |
| 3637 | { |
| 3638 | u32 state; |
| 3639 | |
| 3640 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 3641 | return; |
| 3642 | state = le32_to_cpu(event_data->NewValue); |
| 3643 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == |
| 3644 | MPI2_RAID_VOL_STATE_FAILED) |
| 3645 | _scsih_set_volume_delete_flag(ioc, |
| 3646 | le16_to_cpu(event_data->VolDevHandle)); |
| 3647 | } |
| 3648 | |
| 3649 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3650 | * _scsih_flush_running_cmds - completing outstanding commands. |
| 3651 | * @ioc: per adapter object |
| 3652 | * |
| 3653 | * The flushing out of all pending scmd commands following host reset, |
| 3654 | * where all IO is dropped to the floor. |
| 3655 | * |
| 3656 | * Return nothing. |
| 3657 | */ |
| 3658 | static void |
| 3659 | _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc) |
| 3660 | { |
| 3661 | struct scsi_cmnd *scmd; |
| 3662 | u16 smid; |
| 3663 | u16 count = 0; |
| 3664 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3665 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 3666 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3667 | if (!scmd) |
| 3668 | continue; |
| 3669 | count++; |
| 3670 | mpt2sas_base_free_smid(ioc, smid); |
| 3671 | scsi_dma_unmap(scmd); |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3672 | if (ioc->pci_error_recovery) |
| 3673 | scmd->result = DID_NO_CONNECT << 16; |
| 3674 | else |
| 3675 | scmd->result = DID_RESET << 16; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3676 | scmd->scsi_done(scmd); |
| 3677 | } |
| 3678 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n", |
| 3679 | ioc->name, count)); |
| 3680 | } |
| 3681 | |
| 3682 | /** |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3683 | * _scsih_setup_eedp - setup MPI request for EEDP transfer |
| 3684 | * @scmd: pointer to scsi command object |
| 3685 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3686 | * |
| 3687 | * Supporting protection 1 and 3. |
| 3688 | * |
| 3689 | * Returns nothing |
| 3690 | */ |
| 3691 | static void |
| 3692 | _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request) |
| 3693 | { |
| 3694 | u16 eedp_flags; |
| 3695 | unsigned char prot_op = scsi_get_prot_op(scmd); |
| 3696 | unsigned char prot_type = scsi_get_prot_type(scmd); |
| 3697 | |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3698 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3699 | return; |
| 3700 | |
| 3701 | if (prot_op == SCSI_PROT_READ_STRIP) |
| 3702 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; |
| 3703 | else if (prot_op == SCSI_PROT_WRITE_INSERT) |
| 3704 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; |
| 3705 | else |
| 3706 | return; |
| 3707 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3708 | switch (prot_type) { |
| 3709 | case SCSI_PROT_DIF_TYPE1: |
Martin K. Petersen | 756aca7 | 2011-05-18 00:45:22 -0400 | [diff] [blame] | 3710 | case SCSI_PROT_DIF_TYPE2: |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3711 | |
| 3712 | /* |
| 3713 | * enable ref/guard checking |
| 3714 | * auto increment ref tag |
| 3715 | */ |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3716 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3717 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | |
| 3718 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
| 3719 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = |
| 3720 | cpu_to_be32(scsi_get_lba(scmd)); |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3721 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3722 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3723 | case SCSI_PROT_DIF_TYPE3: |
| 3724 | |
| 3725 | /* |
| 3726 | * enable guard checking |
| 3727 | */ |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3728 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3729 | break; |
| 3730 | } |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3731 | mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size); |
| 3732 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | /** |
| 3736 | * _scsih_eedp_error_handling - return sense code for EEDP errors |
| 3737 | * @scmd: pointer to scsi command object |
| 3738 | * @ioc_status: ioc status |
| 3739 | * |
| 3740 | * Returns nothing |
| 3741 | */ |
| 3742 | static void |
| 3743 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) |
| 3744 | { |
| 3745 | u8 ascq; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3746 | |
| 3747 | switch (ioc_status) { |
| 3748 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 3749 | ascq = 0x01; |
| 3750 | break; |
| 3751 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 3752 | ascq = 0x02; |
| 3753 | break; |
| 3754 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 3755 | ascq = 0x03; |
| 3756 | break; |
| 3757 | default: |
| 3758 | ascq = 0x00; |
| 3759 | break; |
| 3760 | } |
| 3761 | |
Martin K. Petersen | 9b5cd13 | 2012-08-28 14:29:36 -0400 | [diff] [blame] | 3762 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq); |
| 3763 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3764 | SAM_STAT_CHECK_CONDITION; |
| 3765 | } |
| 3766 | |
| 3767 | /** |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3768 | * _scsih_scsi_direct_io_get - returns direct io flag |
| 3769 | * @ioc: per adapter object |
| 3770 | * @smid: system request message index |
| 3771 | * |
| 3772 | * Returns the smid stored scmd pointer. |
| 3773 | */ |
| 3774 | static inline u8 |
| 3775 | _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 3776 | { |
| 3777 | return ioc->scsi_lookup[smid - 1].direct_io; |
| 3778 | } |
| 3779 | |
| 3780 | /** |
| 3781 | * _scsih_scsi_direct_io_set - sets direct io flag |
| 3782 | * @ioc: per adapter object |
| 3783 | * @smid: system request message index |
| 3784 | * @direct_io: Zero or non-zero value to set in the direct_io flag |
| 3785 | * |
| 3786 | * Returns Nothing. |
| 3787 | */ |
| 3788 | static inline void |
| 3789 | _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io) |
| 3790 | { |
| 3791 | ioc->scsi_lookup[smid - 1].direct_io = direct_io; |
| 3792 | } |
| 3793 | |
| 3794 | |
| 3795 | /** |
| 3796 | * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O |
| 3797 | * @ioc: per adapter object |
| 3798 | * @scmd: pointer to scsi command object |
| 3799 | * @raid_device: pointer to raid device data structure |
| 3800 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3801 | * @smid: system request message index |
| 3802 | * |
| 3803 | * Returns nothing |
| 3804 | */ |
| 3805 | static void |
| 3806 | _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 3807 | struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request, |
| 3808 | u16 smid) |
| 3809 | { |
Sreekanth Reddy | f78f694 | 2014-09-19 12:17:27 +0530 | [diff] [blame] | 3810 | sector_t v_lba, p_lba, stripe_off, column, io_size; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3811 | u32 stripe_sz, stripe_exp; |
Sreekanth Reddy | daeaa9d | 2014-09-12 15:35:21 +0530 | [diff] [blame] | 3812 | u8 num_pds, cmd = scmd->cmnd[0]; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3813 | |
Sreekanth Reddy | daeaa9d | 2014-09-12 15:35:21 +0530 | [diff] [blame] | 3814 | if (cmd != READ_10 && cmd != WRITE_10 && |
| 3815 | cmd != READ_16 && cmd != WRITE_16) |
| 3816 | return; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3817 | |
Sreekanth Reddy | daeaa9d | 2014-09-12 15:35:21 +0530 | [diff] [blame] | 3818 | if (cmd == READ_10 || cmd == WRITE_10) |
| 3819 | v_lba = get_unaligned_be32(&mpi_request->CDB.CDB32[2]); |
| 3820 | else |
| 3821 | v_lba = get_unaligned_be64(&mpi_request->CDB.CDB32[2]); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3822 | |
Sreekanth Reddy | daeaa9d | 2014-09-12 15:35:21 +0530 | [diff] [blame] | 3823 | io_size = scsi_bufflen(scmd) >> raid_device->block_exponent; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3824 | |
Sreekanth Reddy | daeaa9d | 2014-09-12 15:35:21 +0530 | [diff] [blame] | 3825 | if (v_lba + io_size - 1 > raid_device->max_lba) |
| 3826 | return; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3827 | |
Sreekanth Reddy | daeaa9d | 2014-09-12 15:35:21 +0530 | [diff] [blame] | 3828 | stripe_sz = raid_device->stripe_sz; |
| 3829 | stripe_exp = raid_device->stripe_exponent; |
| 3830 | stripe_off = v_lba & (stripe_sz - 1); |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3831 | |
Sreekanth Reddy | daeaa9d | 2014-09-12 15:35:21 +0530 | [diff] [blame] | 3832 | /* Return unless IO falls within a stripe */ |
| 3833 | if (stripe_off + io_size > stripe_sz) |
| 3834 | return; |
| 3835 | |
| 3836 | num_pds = raid_device->num_pds; |
| 3837 | p_lba = v_lba >> stripe_exp; |
Sreekanth Reddy | f78f694 | 2014-09-19 12:17:27 +0530 | [diff] [blame] | 3838 | column = sector_div(p_lba, num_pds); |
| 3839 | p_lba = (p_lba << stripe_exp) + stripe_off; |
| 3840 | |
Sreekanth Reddy | daeaa9d | 2014-09-12 15:35:21 +0530 | [diff] [blame] | 3841 | mpi_request->DevHandle = cpu_to_le16(raid_device->pd_handle[column]); |
| 3842 | |
| 3843 | if (cmd == READ_10 || cmd == WRITE_10) |
| 3844 | put_unaligned_be32(lower_32_bits(p_lba), |
| 3845 | &mpi_request->CDB.CDB32[2]); |
| 3846 | else |
| 3847 | put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]); |
| 3848 | |
| 3849 | _scsih_scsi_direct_io_set(ioc, smid, 1); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3850 | } |
| 3851 | |
| 3852 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 3853 | * _scsih_qcmd - main scsi request entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3854 | * @scmd: pointer to scsi command object |
| 3855 | * @done: function pointer to be invoked on completion |
| 3856 | * |
| 3857 | * The callback index is set inside `ioc->scsi_io_cb_idx`. |
| 3858 | * |
| 3859 | * Returns 0 on success. If there's a failure, return either: |
| 3860 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or |
| 3861 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full |
| 3862 | */ |
| 3863 | static int |
Matthew Wilcox | 90f951e | 2014-03-27 16:40:33 -0400 | [diff] [blame] | 3864 | _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3865 | { |
Matthew Wilcox | 90f951e | 2014-03-27 16:40:33 -0400 | [diff] [blame] | 3866 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3867 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 3868 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3869 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3870 | Mpi2SCSIIORequest_t *mpi_request; |
| 3871 | u32 mpi_control; |
| 3872 | u16 smid; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3873 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3874 | sas_device_priv_data = scmd->device->hostdata; |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3875 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3876 | scmd->result = DID_NO_CONNECT << 16; |
| 3877 | scmd->scsi_done(scmd); |
| 3878 | return 0; |
| 3879 | } |
| 3880 | |
Kashyap, Desai | 7821578 | 2011-06-14 10:57:08 +0530 | [diff] [blame] | 3881 | if (ioc->pci_error_recovery || ioc->remove_host) { |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3882 | scmd->result = DID_NO_CONNECT << 16; |
| 3883 | scmd->scsi_done(scmd); |
| 3884 | return 0; |
| 3885 | } |
| 3886 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3887 | sas_target_priv_data = sas_device_priv_data->sas_target; |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3888 | /* invalid device handle */ |
| 3889 | if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3890 | scmd->result = DID_NO_CONNECT << 16; |
| 3891 | scmd->scsi_done(scmd); |
| 3892 | return 0; |
| 3893 | } |
| 3894 | |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3895 | /* host recovery or link resets sent via IOCTLs */ |
| 3896 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3897 | return SCSI_MLQUEUE_HOST_BUSY; |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 3898 | /* device busy with task management */ |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3899 | else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy) |
| 3900 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 3901 | /* device has been deleted */ |
| 3902 | else if (sas_target_priv_data->deleted) { |
| 3903 | scmd->result = DID_NO_CONNECT << 16; |
| 3904 | scmd->scsi_done(scmd); |
| 3905 | return 0; |
| 3906 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3907 | |
| 3908 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) |
| 3909 | mpi_control = MPI2_SCSIIO_CONTROL_READ; |
| 3910 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 3911 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; |
| 3912 | else |
| 3913 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; |
| 3914 | |
| 3915 | /* set tags */ |
Christoph Hellwig | 609aa22 | 2014-10-30 11:54:58 +0100 | [diff] [blame] | 3916 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
| 3917 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3918 | /* Make sure Device is not raid volume. |
| 3919 | * We do not expose raid functionality to upper layer for warpdrive. |
| 3920 | */ |
| 3921 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3922 | sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3923 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
| 3924 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3925 | 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] | 3926 | if (!smid) { |
| 3927 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 3928 | ioc->name, __func__); |
| 3929 | goto out; |
| 3930 | } |
| 3931 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3932 | memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t)); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3933 | _scsih_setup_eedp(scmd, mpi_request); |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3934 | if (scmd->cmd_len == 32) |
| 3935 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3936 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 3937 | if (sas_device_priv_data->sas_target->flags & |
| 3938 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 3939 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; |
| 3940 | else |
Matthew Wilcox | 90f951e | 2014-03-27 16:40:33 -0400 | [diff] [blame] | 3941 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3942 | mpi_request->DevHandle = |
| 3943 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 3944 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
| 3945 | mpi_request->Control = cpu_to_le32(mpi_control); |
| 3946 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); |
| 3947 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; |
| 3948 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; |
| 3949 | mpi_request->SenseBufferLowAddress = |
Kashyap, Desai | ec9472c | 2009-09-23 17:34:13 +0530 | [diff] [blame] | 3950 | mpt2sas_base_get_sense_buffer_dma(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3951 | mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4; |
| 3952 | mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI + |
| 3953 | MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3954 | mpi_request->VF_ID = 0; /* TODO */ |
| 3955 | mpi_request->VP_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3956 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
| 3957 | mpi_request->LUN); |
| 3958 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 3959 | |
| 3960 | if (!mpi_request->DataLength) { |
| 3961 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL); |
| 3962 | } else { |
| 3963 | if (_scsih_build_scatter_gather(ioc, scmd, smid)) { |
| 3964 | mpt2sas_base_free_smid(ioc, smid); |
| 3965 | goto out; |
| 3966 | } |
| 3967 | } |
| 3968 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3969 | raid_device = sas_target_priv_data->raid_device; |
| 3970 | if (raid_device && raid_device->direct_io_enabled) |
| 3971 | _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request, |
| 3972 | smid); |
| 3973 | |
Kashyap, Desai | 58287fd | 2010-03-17 16:27:25 +0530 | [diff] [blame] | 3974 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) |
| 3975 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3976 | le16_to_cpu(mpi_request->DevHandle)); |
Kashyap, Desai | 58287fd | 2010-03-17 16:27:25 +0530 | [diff] [blame] | 3977 | else |
| 3978 | mpt2sas_base_put_smid_default(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3979 | return 0; |
| 3980 | |
| 3981 | out: |
| 3982 | return SCSI_MLQUEUE_HOST_BUSY; |
| 3983 | } |
| 3984 | |
| 3985 | /** |
| 3986 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data |
| 3987 | * @sense_buffer: sense data returned by target |
| 3988 | * @data: normalized skey/asc/ascq |
| 3989 | * |
| 3990 | * Return nothing. |
| 3991 | */ |
| 3992 | static void |
| 3993 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) |
| 3994 | { |
| 3995 | if ((sense_buffer[0] & 0x7F) >= 0x72) { |
| 3996 | /* descriptor format */ |
| 3997 | data->skey = sense_buffer[1] & 0x0F; |
| 3998 | data->asc = sense_buffer[2]; |
| 3999 | data->ascq = sense_buffer[3]; |
| 4000 | } else { |
| 4001 | /* fixed format */ |
| 4002 | data->skey = sense_buffer[2] & 0x0F; |
| 4003 | data->asc = sense_buffer[12]; |
| 4004 | data->ascq = sense_buffer[13]; |
| 4005 | } |
| 4006 | } |
| 4007 | |
| 4008 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4009 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4010 | * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4011 | * @ioc: per adapter object |
| 4012 | * @scmd: pointer to scsi command object |
| 4013 | * @mpi_reply: reply mf payload returned from firmware |
| 4014 | * |
| 4015 | * scsi_status - SCSI Status code returned from target device |
| 4016 | * scsi_state - state info associated with SCSI_IO determined by ioc |
| 4017 | * ioc_status - ioc supplied status info |
| 4018 | * |
| 4019 | * Return nothing. |
| 4020 | */ |
| 4021 | static void |
| 4022 | _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 4023 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) |
| 4024 | { |
| 4025 | u32 response_info; |
| 4026 | u8 *response_bytes; |
| 4027 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & |
| 4028 | MPI2_IOCSTATUS_MASK; |
| 4029 | u8 scsi_state = mpi_reply->SCSIState; |
| 4030 | u8 scsi_status = mpi_reply->SCSIStatus; |
| 4031 | char *desc_ioc_state = NULL; |
| 4032 | char *desc_scsi_status = NULL; |
| 4033 | char *desc_scsi_state = ioc->tmp_string; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4034 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4035 | struct _sas_device *sas_device = NULL; |
| 4036 | unsigned long flags; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4037 | struct scsi_target *starget = scmd->device->sdev_target; |
| 4038 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4039 | char *device_str = NULL; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4040 | |
| 4041 | if (!priv_target) |
| 4042 | return; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4043 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4044 | if (ioc->hide_ir_msg) |
| 4045 | device_str = "WarpDrive"; |
| 4046 | else |
| 4047 | device_str = "volume"; |
| 4048 | |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4049 | if (log_info == 0x31170000) |
| 4050 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4051 | |
| 4052 | switch (ioc_status) { |
| 4053 | case MPI2_IOCSTATUS_SUCCESS: |
| 4054 | desc_ioc_state = "success"; |
| 4055 | break; |
| 4056 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 4057 | desc_ioc_state = "invalid function"; |
| 4058 | break; |
| 4059 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 4060 | desc_ioc_state = "scsi recovered error"; |
| 4061 | break; |
| 4062 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: |
| 4063 | desc_ioc_state = "scsi invalid dev handle"; |
| 4064 | break; |
| 4065 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 4066 | desc_ioc_state = "scsi device not there"; |
| 4067 | break; |
| 4068 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 4069 | desc_ioc_state = "scsi data overrun"; |
| 4070 | break; |
| 4071 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 4072 | desc_ioc_state = "scsi data underrun"; |
| 4073 | break; |
| 4074 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 4075 | desc_ioc_state = "scsi io data error"; |
| 4076 | break; |
| 4077 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 4078 | desc_ioc_state = "scsi protocol error"; |
| 4079 | break; |
| 4080 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 4081 | desc_ioc_state = "scsi task terminated"; |
| 4082 | break; |
| 4083 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 4084 | desc_ioc_state = "scsi residual mismatch"; |
| 4085 | break; |
| 4086 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 4087 | desc_ioc_state = "scsi task mgmt failed"; |
| 4088 | break; |
| 4089 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 4090 | desc_ioc_state = "scsi ioc terminated"; |
| 4091 | break; |
| 4092 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 4093 | desc_ioc_state = "scsi ext terminated"; |
| 4094 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4095 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 4096 | desc_ioc_state = "eedp guard error"; |
| 4097 | break; |
| 4098 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 4099 | desc_ioc_state = "eedp ref tag error"; |
| 4100 | break; |
| 4101 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 4102 | desc_ioc_state = "eedp app tag error"; |
| 4103 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4104 | default: |
| 4105 | desc_ioc_state = "unknown"; |
| 4106 | break; |
| 4107 | } |
| 4108 | |
| 4109 | switch (scsi_status) { |
| 4110 | case MPI2_SCSI_STATUS_GOOD: |
| 4111 | desc_scsi_status = "good"; |
| 4112 | break; |
| 4113 | case MPI2_SCSI_STATUS_CHECK_CONDITION: |
| 4114 | desc_scsi_status = "check condition"; |
| 4115 | break; |
| 4116 | case MPI2_SCSI_STATUS_CONDITION_MET: |
| 4117 | desc_scsi_status = "condition met"; |
| 4118 | break; |
| 4119 | case MPI2_SCSI_STATUS_BUSY: |
| 4120 | desc_scsi_status = "busy"; |
| 4121 | break; |
| 4122 | case MPI2_SCSI_STATUS_INTERMEDIATE: |
| 4123 | desc_scsi_status = "intermediate"; |
| 4124 | break; |
| 4125 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: |
| 4126 | desc_scsi_status = "intermediate condmet"; |
| 4127 | break; |
| 4128 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: |
| 4129 | desc_scsi_status = "reservation conflict"; |
| 4130 | break; |
| 4131 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: |
| 4132 | desc_scsi_status = "command terminated"; |
| 4133 | break; |
| 4134 | case MPI2_SCSI_STATUS_TASK_SET_FULL: |
| 4135 | desc_scsi_status = "task set full"; |
| 4136 | break; |
| 4137 | case MPI2_SCSI_STATUS_ACA_ACTIVE: |
| 4138 | desc_scsi_status = "aca active"; |
| 4139 | break; |
| 4140 | case MPI2_SCSI_STATUS_TASK_ABORTED: |
| 4141 | desc_scsi_status = "task aborted"; |
| 4142 | break; |
| 4143 | default: |
| 4144 | desc_scsi_status = "unknown"; |
| 4145 | break; |
| 4146 | } |
| 4147 | |
| 4148 | desc_scsi_state[0] = '\0'; |
| 4149 | if (!scsi_state) |
| 4150 | desc_scsi_state = " "; |
| 4151 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 4152 | strcat(desc_scsi_state, "response info "); |
| 4153 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4154 | strcat(desc_scsi_state, "state terminated "); |
| 4155 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) |
| 4156 | strcat(desc_scsi_state, "no status "); |
| 4157 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) |
| 4158 | strcat(desc_scsi_state, "autosense failed "); |
| 4159 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) |
| 4160 | strcat(desc_scsi_state, "autosense valid "); |
| 4161 | |
| 4162 | scsi_print_command(scmd); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4163 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4164 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4165 | printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name, |
| 4166 | device_str, (unsigned long long)priv_target->sas_address); |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4167 | } else { |
| 4168 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4169 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 4170 | priv_target->sas_address); |
| 4171 | if (sas_device) { |
| 4172 | printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), " |
| 4173 | "phy(%d)\n", ioc->name, sas_device->sas_address, |
| 4174 | sas_device->phy); |
| 4175 | printk(MPT2SAS_WARN_FMT |
| 4176 | "\tenclosure_logical_id(0x%016llx), slot(%d)\n", |
| 4177 | ioc->name, sas_device->enclosure_logical_id, |
| 4178 | sas_device->slot); |
| 4179 | } |
| 4180 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4181 | } |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4182 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4183 | printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), " |
| 4184 | "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle), |
| 4185 | desc_ioc_state, ioc_status, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4186 | printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), " |
| 4187 | "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow, |
| 4188 | scsi_get_resid(scmd)); |
| 4189 | printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), " |
| 4190 | "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag), |
| 4191 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); |
| 4192 | printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), " |
| 4193 | "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status, |
| 4194 | scsi_status, desc_scsi_state, scsi_state); |
| 4195 | |
| 4196 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4197 | struct sense_info data; |
| 4198 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4199 | printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: " |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 4200 | "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey, |
| 4201 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { |
| 4205 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); |
| 4206 | response_bytes = (u8 *)&response_info; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4207 | _scsih_response_code(ioc, response_bytes[0]); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4208 | } |
| 4209 | } |
| 4210 | #endif |
| 4211 | |
| 4212 | /** |
Sreekanth Reddy | bd58ea3 | 2014-09-12 15:35:19 +0530 | [diff] [blame] | 4213 | * _scsih_turn_on_pfa_led - illuminate PFA LED |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4214 | * @ioc: per adapter object |
| 4215 | * @handle: device handle |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4216 | * Context: process |
| 4217 | * |
| 4218 | * Return nothing. |
| 4219 | */ |
| 4220 | static void |
Sreekanth Reddy | bd58ea3 | 2014-09-12 15:35:19 +0530 | [diff] [blame] | 4221 | _scsih_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4222 | { |
| 4223 | Mpi2SepReply_t mpi_reply; |
| 4224 | Mpi2SepRequest_t mpi_request; |
Sreekanth Reddy | bd58ea3 | 2014-09-12 15:35:19 +0530 | [diff] [blame] | 4225 | struct _sas_device *sas_device; |
| 4226 | |
| 4227 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 4228 | if (!sas_device) |
| 4229 | return; |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4230 | |
| 4231 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
| 4232 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; |
| 4233 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; |
| 4234 | mpi_request.SlotStatus = |
| 4235 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); |
| 4236 | mpi_request.DevHandle = cpu_to_le16(handle); |
| 4237 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; |
| 4238 | if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply, |
| 4239 | &mpi_request)) != 0) { |
| 4240 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 4241 | __FILE__, __LINE__, __func__); |
| 4242 | return; |
| 4243 | } |
Sreekanth Reddy | bd58ea3 | 2014-09-12 15:35:19 +0530 | [diff] [blame] | 4244 | sas_device->pfa_led_on = 1; |
| 4245 | |
| 4246 | |
| 4247 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { |
| 4248 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 4249 | "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n", |
| 4250 | ioc->name, le16_to_cpu(mpi_reply.IOCStatus), |
| 4251 | le32_to_cpu(mpi_reply.IOCLogInfo))); |
| 4252 | return; |
| 4253 | } |
| 4254 | } |
| 4255 | |
| 4256 | /** |
| 4257 | * _scsih_turn_off_pfa_led - turn off PFA LED |
| 4258 | * @ioc: per adapter object |
| 4259 | * @sas_device: sas device whose PFA LED has to turned off |
| 4260 | * Context: process |
| 4261 | * |
| 4262 | * Return nothing. |
| 4263 | */ |
| 4264 | static void |
| 4265 | _scsih_turn_off_pfa_led(struct MPT2SAS_ADAPTER *ioc, |
| 4266 | struct _sas_device *sas_device) |
| 4267 | { |
| 4268 | Mpi2SepReply_t mpi_reply; |
| 4269 | Mpi2SepRequest_t mpi_request; |
| 4270 | |
| 4271 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
| 4272 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; |
| 4273 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; |
| 4274 | mpi_request.SlotStatus = 0; |
| 4275 | mpi_request.Slot = cpu_to_le16(sas_device->slot); |
| 4276 | mpi_request.DevHandle = 0; |
| 4277 | mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle); |
| 4278 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS; |
| 4279 | if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply, |
| 4280 | &mpi_request)) != 0) { |
| 4281 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 4282 | __FILE__, __LINE__, __func__); |
| 4283 | return; |
| 4284 | } |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4285 | |
| 4286 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { |
| 4287 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: " |
| 4288 | "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name, |
| 4289 | le16_to_cpu(mpi_reply.IOCStatus), |
| 4290 | le32_to_cpu(mpi_reply.IOCLogInfo))); |
| 4291 | return; |
| 4292 | } |
| 4293 | } |
| 4294 | |
| 4295 | /** |
Sreekanth Reddy | bd58ea3 | 2014-09-12 15:35:19 +0530 | [diff] [blame] | 4296 | * _scsih_send_event_to_turn_on_pfa_led - fire delayed event |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4297 | * @ioc: per adapter object |
| 4298 | * @handle: device handle |
| 4299 | * Context: interrupt. |
| 4300 | * |
| 4301 | * Return nothing. |
| 4302 | */ |
| 4303 | static void |
Sreekanth Reddy | bd58ea3 | 2014-09-12 15:35:19 +0530 | [diff] [blame] | 4304 | _scsih_send_event_to_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4305 | { |
| 4306 | struct fw_event_work *fw_event; |
| 4307 | |
| 4308 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 4309 | if (!fw_event) |
| 4310 | return; |
Sreekanth Reddy | bd58ea3 | 2014-09-12 15:35:19 +0530 | [diff] [blame] | 4311 | fw_event->event = MPT2SAS_TURN_ON_PFA_LED; |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4312 | fw_event->device_handle = handle; |
| 4313 | fw_event->ioc = ioc; |
| 4314 | _scsih_fw_event_add(ioc, fw_event); |
| 4315 | } |
| 4316 | |
| 4317 | /** |
| 4318 | * _scsih_smart_predicted_fault - process smart errors |
| 4319 | * @ioc: per adapter object |
| 4320 | * @handle: device handle |
| 4321 | * Context: interrupt. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4322 | * |
| 4323 | * Return nothing. |
| 4324 | */ |
| 4325 | static void |
| 4326 | _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4327 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4328 | struct scsi_target *starget; |
| 4329 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 4330 | Mpi2EventNotificationReply_t *event_reply; |
| 4331 | Mpi2EventDataSasDeviceStatusChange_t *event_data; |
| 4332 | struct _sas_device *sas_device; |
| 4333 | ssize_t sz; |
| 4334 | unsigned long flags; |
| 4335 | |
| 4336 | /* only handle non-raid devices */ |
| 4337 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4338 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 4339 | if (!sas_device) { |
| 4340 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4341 | return; |
| 4342 | } |
| 4343 | starget = sas_device->starget; |
| 4344 | sas_target_priv_data = starget->hostdata; |
| 4345 | |
| 4346 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || |
| 4347 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) { |
| 4348 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4349 | return; |
| 4350 | } |
| 4351 | starget_printk(KERN_WARNING, starget, "predicted fault\n"); |
| 4352 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4353 | |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4354 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) |
Sreekanth Reddy | bd58ea3 | 2014-09-12 15:35:19 +0530 | [diff] [blame] | 4355 | _scsih_send_event_to_turn_on_pfa_led(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4356 | |
| 4357 | /* insert into event log */ |
| 4358 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + |
| 4359 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); |
Anton Blanchard | f6a290b4 | 2011-11-07 22:05:21 +1100 | [diff] [blame] | 4360 | event_reply = kzalloc(sz, GFP_ATOMIC); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4361 | if (!event_reply) { |
| 4362 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4363 | ioc->name, __FILE__, __LINE__, __func__); |
| 4364 | return; |
| 4365 | } |
| 4366 | |
| 4367 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; |
| 4368 | event_reply->Event = |
| 4369 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); |
| 4370 | event_reply->MsgLength = sz/4; |
| 4371 | event_reply->EventDataLength = |
| 4372 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); |
| 4373 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) |
| 4374 | event_reply->EventData; |
| 4375 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; |
| 4376 | event_data->ASC = 0x5D; |
| 4377 | event_data->DevHandle = cpu_to_le16(handle); |
| 4378 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); |
| 4379 | mpt2sas_ctl_add_to_event_log(ioc, event_reply); |
| 4380 | kfree(event_reply); |
| 4381 | } |
| 4382 | |
| 4383 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 4384 | * _scsih_io_done - scsi request callback |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4385 | * @ioc: per adapter object |
| 4386 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4387 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4388 | * @reply: reply message frame(lower 32bit addr) |
| 4389 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4390 | * Callback handler when using _scsih_qcmd. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4391 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4392 | * Return 1 meaning mf should be freed from _base_interrupt |
| 4393 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4394 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4395 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4396 | _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] | 4397 | { |
| 4398 | Mpi2SCSIIORequest_t *mpi_request; |
| 4399 | Mpi2SCSIIOReply_t *mpi_reply; |
| 4400 | struct scsi_cmnd *scmd; |
| 4401 | u16 ioc_status; |
| 4402 | u32 xfer_cnt; |
| 4403 | u8 scsi_state; |
| 4404 | u8 scsi_status; |
| 4405 | u32 log_info; |
| 4406 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4407 | u32 response_code = 0; |
Kashyap, Desai | 82a4525 | 2011-07-05 12:40:23 +0530 | [diff] [blame] | 4408 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4409 | |
| 4410 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 4411 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4412 | if (scmd == NULL) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4413 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4414 | |
| 4415 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 4416 | |
| 4417 | if (mpi_reply == NULL) { |
| 4418 | scmd->result = DID_OK << 16; |
| 4419 | goto out; |
| 4420 | } |
| 4421 | |
| 4422 | sas_device_priv_data = scmd->device->hostdata; |
| 4423 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
| 4424 | sas_device_priv_data->sas_target->deleted) { |
| 4425 | scmd->result = DID_NO_CONNECT << 16; |
| 4426 | goto out; |
| 4427 | } |
nagalakshmi.nandigama@lsi.com | 4da7af9 | 2011-12-01 07:53:02 +0530 | [diff] [blame] | 4428 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4429 | /* |
| 4430 | * WARPDRIVE: If direct_io is set then it is directIO, |
| 4431 | * the failed direct I/O should be redirected to volume |
| 4432 | */ |
nagalakshmi.nandigama@lsi.com | 4da7af9 | 2011-12-01 07:53:02 +0530 | [diff] [blame] | 4433 | if (_scsih_scsi_direct_io_get(ioc, smid) && |
| 4434 | ((ioc_status & MPI2_IOCSTATUS_MASK) |
| 4435 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { |
Kashyap, Desai | 82a4525 | 2011-07-05 12:40:23 +0530 | [diff] [blame] | 4436 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 4437 | ioc->scsi_lookup[smid - 1].scmd = scmd; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4438 | _scsih_scsi_direct_io_set(ioc, smid, 0); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 4439 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4440 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 4441 | mpi_request->DevHandle = |
| 4442 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 4443 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
| 4444 | sas_device_priv_data->sas_target->handle); |
| 4445 | return 0; |
| 4446 | } |
| 4447 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4448 | |
| 4449 | /* turning off TLR */ |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4450 | scsi_state = mpi_reply->SCSIState; |
| 4451 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 4452 | response_code = |
| 4453 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4454 | if (!sas_device_priv_data->tlr_snoop_check) { |
| 4455 | sas_device_priv_data->tlr_snoop_check++; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4456 | /* Make sure Device is not raid volume. |
| 4457 | * We do not expose raid functionality to upper layer for warpdrive. |
| 4458 | */ |
| 4459 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && |
Kashyap, Desai | 3ed2152 | 2010-02-17 16:08:36 +0530 | [diff] [blame] | 4460 | sas_is_tlr_enabled(scmd->device) && |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 4461 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { |
| 4462 | sas_disable_tlr(scmd->device); |
| 4463 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); |
| 4464 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); |
| 4468 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4469 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) |
| 4470 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
| 4471 | else |
| 4472 | log_info = 0; |
| 4473 | ioc_status &= MPI2_IOCSTATUS_MASK; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4474 | scsi_status = mpi_reply->SCSIStatus; |
| 4475 | |
| 4476 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && |
| 4477 | (scsi_status == MPI2_SCSI_STATUS_BUSY || |
| 4478 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || |
| 4479 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { |
| 4480 | ioc_status = MPI2_IOCSTATUS_SUCCESS; |
| 4481 | } |
| 4482 | |
| 4483 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4484 | struct sense_info data; |
| 4485 | const void *sense_data = mpt2sas_base_get_sense_buffer(ioc, |
| 4486 | smid); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 4487 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4488 | le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 4489 | memcpy(scmd->sense_buffer, sense_data, sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4490 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4491 | /* failure prediction threshold exceeded */ |
| 4492 | if (data.asc == 0x5D) |
| 4493 | _scsih_smart_predicted_fault(ioc, |
| 4494 | le16_to_cpu(mpi_reply->DevHandle)); |
| 4495 | } |
| 4496 | |
| 4497 | switch (ioc_status) { |
| 4498 | case MPI2_IOCSTATUS_BUSY: |
| 4499 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: |
| 4500 | scmd->result = SAM_STAT_BUSY; |
| 4501 | break; |
| 4502 | |
| 4503 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 4504 | scmd->result = DID_NO_CONNECT << 16; |
| 4505 | break; |
| 4506 | |
| 4507 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 4508 | if (sas_device_priv_data->block) { |
Kashyap, Desai | e4e7c7e | 2009-09-23 17:33:14 +0530 | [diff] [blame] | 4509 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; |
| 4510 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4511 | } |
nagalakshmi.nandigama@lsi.com | 3ade1ca | 2011-12-01 07:42:40 +0530 | [diff] [blame] | 4512 | scmd->result = DID_SOFT_ERROR << 16; |
| 4513 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4514 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 4515 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 4516 | scmd->result = DID_RESET << 16; |
| 4517 | break; |
| 4518 | |
| 4519 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 4520 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) |
| 4521 | scmd->result = DID_SOFT_ERROR << 16; |
| 4522 | else |
| 4523 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4524 | break; |
| 4525 | |
| 4526 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 4527 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4528 | |
| 4529 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) |
| 4530 | break; |
| 4531 | |
| 4532 | if (xfer_cnt < scmd->underflow) { |
| 4533 | if (scsi_status == SAM_STAT_BUSY) |
| 4534 | scmd->result = SAM_STAT_BUSY; |
| 4535 | else |
| 4536 | scmd->result = DID_SOFT_ERROR << 16; |
| 4537 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4538 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) |
| 4539 | scmd->result = DID_SOFT_ERROR << 16; |
| 4540 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4541 | scmd->result = DID_RESET << 16; |
| 4542 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { |
| 4543 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; |
| 4544 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; |
| 4545 | scmd->result = (DRIVER_SENSE << 24) | |
| 4546 | SAM_STAT_CHECK_CONDITION; |
| 4547 | scmd->sense_buffer[0] = 0x70; |
| 4548 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; |
| 4549 | scmd->sense_buffer[12] = 0x20; |
| 4550 | scmd->sense_buffer[13] = 0; |
| 4551 | } |
| 4552 | break; |
| 4553 | |
| 4554 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 4555 | scsi_set_resid(scmd, 0); |
| 4556 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 4557 | case MPI2_IOCSTATUS_SUCCESS: |
| 4558 | scmd->result = (DID_OK << 16) | scsi_status; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4559 | if (response_code == |
| 4560 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || |
| 4561 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4562 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4563 | scmd->result = DID_SOFT_ERROR << 16; |
| 4564 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4565 | scmd->result = DID_RESET << 16; |
| 4566 | break; |
| 4567 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4568 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 4569 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 4570 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 4571 | _scsih_eedp_error_handling(scmd, ioc_status); |
| 4572 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4573 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 4574 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 4575 | case MPI2_IOCSTATUS_INVALID_SGL: |
| 4576 | case MPI2_IOCSTATUS_INTERNAL_ERROR: |
| 4577 | case MPI2_IOCSTATUS_INVALID_FIELD: |
| 4578 | case MPI2_IOCSTATUS_INVALID_STATE: |
| 4579 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 4580 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 4581 | default: |
| 4582 | scmd->result = DID_SOFT_ERROR << 16; |
| 4583 | break; |
| 4584 | |
| 4585 | } |
| 4586 | |
| 4587 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4588 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
| 4589 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); |
| 4590 | #endif |
| 4591 | |
| 4592 | out: |
| 4593 | scsi_dma_unmap(scmd); |
| 4594 | scmd->scsi_done(scmd); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4595 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4596 | } |
| 4597 | |
| 4598 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4599 | * _scsih_sas_host_refresh - refreshing sas host object contents |
| 4600 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4601 | * Context: user |
| 4602 | * |
| 4603 | * During port enable, fw will send topology events for every device. Its |
| 4604 | * possible that the handles may change from the previous setting, so this |
| 4605 | * code keeping handles updating if changed. |
| 4606 | * |
| 4607 | * Return nothing. |
| 4608 | */ |
| 4609 | static void |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4610 | _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4611 | { |
| 4612 | u16 sz; |
| 4613 | u16 ioc_status; |
| 4614 | int i; |
| 4615 | Mpi2ConfigReply_t mpi_reply; |
| 4616 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4617 | u16 attached_handle; |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4618 | u8 link_rate; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4619 | |
| 4620 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 4621 | "updating handles for sas_host(0x%016llx)\n", |
| 4622 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); |
| 4623 | |
| 4624 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys |
| 4625 | * sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4626 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4627 | if (!sas_iounit_pg0) { |
| 4628 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4629 | ioc->name, __FILE__, __LINE__, __func__); |
| 4630 | return; |
| 4631 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4632 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4633 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4634 | sas_iounit_pg0, sz)) != 0) |
| 4635 | goto out; |
| 4636 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 4637 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 4638 | goto out; |
| 4639 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4640 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4641 | if (i == 0) |
| 4642 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4643 | PhyData[0].ControllerDevHandle); |
| 4644 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
| 4645 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. |
| 4646 | AttachedDevHandle); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4647 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 4648 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4649 | mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address, |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4650 | attached_handle, i, link_rate); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4651 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4652 | out: |
| 4653 | kfree(sas_iounit_pg0); |
| 4654 | } |
| 4655 | |
| 4656 | /** |
| 4657 | * _scsih_sas_host_add - create sas host object |
| 4658 | * @ioc: per adapter object |
| 4659 | * |
| 4660 | * Creating host side data object, stored in ioc->sas_hba |
| 4661 | * |
| 4662 | * Return nothing. |
| 4663 | */ |
| 4664 | static void |
| 4665 | _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc) |
| 4666 | { |
| 4667 | int i; |
| 4668 | Mpi2ConfigReply_t mpi_reply; |
| 4669 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
| 4670 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; |
| 4671 | Mpi2SasPhyPage0_t phy_pg0; |
| 4672 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4673 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4674 | u16 ioc_status; |
| 4675 | u16 sz; |
| 4676 | u16 device_missing_delay; |
| 4677 | |
| 4678 | mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys); |
| 4679 | if (!ioc->sas_hba.num_phys) { |
| 4680 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4681 | ioc->name, __FILE__, __LINE__, __func__); |
| 4682 | return; |
| 4683 | } |
| 4684 | |
| 4685 | /* sas_iounit page 0 */ |
| 4686 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4687 | sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4688 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4689 | if (!sas_iounit_pg0) { |
| 4690 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4691 | ioc->name, __FILE__, __LINE__, __func__); |
| 4692 | return; |
| 4693 | } |
| 4694 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4695 | sas_iounit_pg0, sz))) { |
| 4696 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4697 | ioc->name, __FILE__, __LINE__, __func__); |
| 4698 | goto out; |
| 4699 | } |
| 4700 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4701 | MPI2_IOCSTATUS_MASK; |
| 4702 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4703 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4704 | ioc->name, __FILE__, __LINE__, __func__); |
| 4705 | goto out; |
| 4706 | } |
| 4707 | |
| 4708 | /* sas_iounit page 1 */ |
| 4709 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4710 | sizeof(Mpi2SasIOUnit1PhyData_t)); |
| 4711 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); |
| 4712 | if (!sas_iounit_pg1) { |
| 4713 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4714 | ioc->name, __FILE__, __LINE__, __func__); |
| 4715 | goto out; |
| 4716 | } |
| 4717 | if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, |
| 4718 | sas_iounit_pg1, sz))) { |
| 4719 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4720 | ioc->name, __FILE__, __LINE__, __func__); |
| 4721 | goto out; |
| 4722 | } |
| 4723 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4724 | MPI2_IOCSTATUS_MASK; |
| 4725 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4726 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4727 | ioc->name, __FILE__, __LINE__, __func__); |
| 4728 | goto out; |
| 4729 | } |
| 4730 | |
| 4731 | ioc->io_missing_delay = |
| 4732 | le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay); |
| 4733 | device_missing_delay = |
| 4734 | le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay); |
| 4735 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) |
| 4736 | ioc->device_missing_delay = (device_missing_delay & |
| 4737 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; |
| 4738 | else |
| 4739 | ioc->device_missing_delay = device_missing_delay & |
| 4740 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 4741 | |
| 4742 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; |
| 4743 | ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys, |
| 4744 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4745 | if (!ioc->sas_hba.phy) { |
| 4746 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4747 | ioc->name, __FILE__, __LINE__, __func__); |
| 4748 | goto out; |
| 4749 | } |
| 4750 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
| 4751 | if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, |
| 4752 | i))) { |
| 4753 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4754 | ioc->name, __FILE__, __LINE__, __func__); |
| 4755 | goto out; |
| 4756 | } |
| 4757 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4758 | MPI2_IOCSTATUS_MASK; |
| 4759 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4760 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4761 | ioc->name, __FILE__, __LINE__, __func__); |
| 4762 | goto out; |
| 4763 | } |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4764 | |
| 4765 | if (i == 0) |
| 4766 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4767 | PhyData[0].ControllerDevHandle); |
| 4768 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4769 | ioc->sas_hba.phy[i].phy_id = i; |
| 4770 | mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], |
| 4771 | phy_pg0, ioc->sas_hba.parent_dev); |
| 4772 | } |
| 4773 | 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] | 4774 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4775 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4776 | ioc->name, __FILE__, __LINE__, __func__); |
| 4777 | goto out; |
| 4778 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4779 | ioc->sas_hba.enclosure_handle = |
| 4780 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 4781 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 4782 | printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), " |
| 4783 | "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle, |
| 4784 | (unsigned long long) ioc->sas_hba.sas_address, |
| 4785 | ioc->sas_hba.num_phys) ; |
| 4786 | |
| 4787 | if (ioc->sas_hba.enclosure_handle) { |
| 4788 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4789 | &enclosure_pg0, |
| 4790 | MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4791 | ioc->sas_hba.enclosure_handle))) { |
| 4792 | ioc->sas_hba.enclosure_logical_id = |
| 4793 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4794 | } |
| 4795 | } |
| 4796 | |
| 4797 | out: |
| 4798 | kfree(sas_iounit_pg1); |
| 4799 | kfree(sas_iounit_pg0); |
| 4800 | } |
| 4801 | |
| 4802 | /** |
| 4803 | * _scsih_expander_add - creating expander object |
| 4804 | * @ioc: per adapter object |
| 4805 | * @handle: expander handle |
| 4806 | * |
| 4807 | * Creating expander object, stored in ioc->sas_expander_list. |
| 4808 | * |
| 4809 | * Return 0 for success, else error. |
| 4810 | */ |
| 4811 | static int |
| 4812 | _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4813 | { |
| 4814 | struct _sas_node *sas_expander; |
| 4815 | Mpi2ConfigReply_t mpi_reply; |
| 4816 | Mpi2ExpanderPage0_t expander_pg0; |
| 4817 | Mpi2ExpanderPage1_t expander_pg1; |
| 4818 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4819 | u32 ioc_status; |
| 4820 | u16 parent_handle; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 4821 | u64 sas_address, sas_address_parent = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4822 | int i; |
| 4823 | unsigned long flags; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4824 | struct _sas_port *mpt2sas_port = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4825 | int rc = 0; |
| 4826 | |
| 4827 | if (!handle) |
| 4828 | return -1; |
| 4829 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 4830 | if (ioc->shost_recovery || ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 4831 | return -1; |
| 4832 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4833 | if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 4834 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { |
| 4835 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4836 | ioc->name, __FILE__, __LINE__, __func__); |
| 4837 | return -1; |
| 4838 | } |
| 4839 | |
| 4840 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4841 | MPI2_IOCSTATUS_MASK; |
| 4842 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4843 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4844 | ioc->name, __FILE__, __LINE__, __func__); |
| 4845 | return -1; |
| 4846 | } |
| 4847 | |
| 4848 | /* handle out of order topology events */ |
| 4849 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4850 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) |
| 4851 | != 0) { |
| 4852 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4853 | ioc->name, __FILE__, __LINE__, __func__); |
| 4854 | return -1; |
| 4855 | } |
| 4856 | if (sas_address_parent != ioc->sas_hba.sas_address) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4857 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4858 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4859 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4860 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4861 | if (!sas_expander) { |
| 4862 | rc = _scsih_expander_add(ioc, parent_handle); |
| 4863 | if (rc != 0) |
| 4864 | return rc; |
| 4865 | } |
| 4866 | } |
| 4867 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4868 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 4869 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4870 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4871 | sas_address); |
| 4872 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4873 | |
| 4874 | if (sas_expander) |
| 4875 | return 0; |
| 4876 | |
| 4877 | sas_expander = kzalloc(sizeof(struct _sas_node), |
| 4878 | GFP_KERNEL); |
| 4879 | if (!sas_expander) { |
| 4880 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4881 | ioc->name, __FILE__, __LINE__, __func__); |
| 4882 | return -1; |
| 4883 | } |
| 4884 | |
| 4885 | sas_expander->handle = handle; |
| 4886 | sas_expander->num_phys = expander_pg0.NumPhys; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4887 | sas_expander->sas_address_parent = sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4888 | sas_expander->sas_address = sas_address; |
| 4889 | |
| 4890 | printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x)," |
| 4891 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4892 | handle, parent_handle, (unsigned long long) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4893 | sas_expander->sas_address, sas_expander->num_phys); |
| 4894 | |
| 4895 | if (!sas_expander->num_phys) |
| 4896 | goto out_fail; |
| 4897 | sas_expander->phy = kcalloc(sas_expander->num_phys, |
| 4898 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4899 | if (!sas_expander->phy) { |
| 4900 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4901 | ioc->name, __FILE__, __LINE__, __func__); |
| 4902 | rc = -1; |
| 4903 | goto out_fail; |
| 4904 | } |
| 4905 | |
| 4906 | INIT_LIST_HEAD(&sas_expander->sas_port_list); |
| 4907 | mpt2sas_port = mpt2sas_transport_port_add(ioc, handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4908 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4909 | if (!mpt2sas_port) { |
| 4910 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4911 | ioc->name, __FILE__, __LINE__, __func__); |
| 4912 | rc = -1; |
| 4913 | goto out_fail; |
| 4914 | } |
| 4915 | sas_expander->parent_dev = &mpt2sas_port->rphy->dev; |
| 4916 | |
| 4917 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 4918 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 4919 | &expander_pg1, i, handle))) { |
| 4920 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4921 | ioc->name, __FILE__, __LINE__, __func__); |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4922 | rc = -1; |
| 4923 | goto out_fail; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4924 | } |
| 4925 | sas_expander->phy[i].handle = handle; |
| 4926 | sas_expander->phy[i].phy_id = i; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4927 | |
| 4928 | if ((mpt2sas_transport_add_expander_phy(ioc, |
| 4929 | &sas_expander->phy[i], expander_pg1, |
| 4930 | sas_expander->parent_dev))) { |
| 4931 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4932 | ioc->name, __FILE__, __LINE__, __func__); |
| 4933 | rc = -1; |
| 4934 | goto out_fail; |
| 4935 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4936 | } |
| 4937 | |
| 4938 | if (sas_expander->enclosure_handle) { |
| 4939 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4940 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4941 | sas_expander->enclosure_handle))) { |
| 4942 | sas_expander->enclosure_logical_id = |
| 4943 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4944 | } |
| 4945 | } |
| 4946 | |
| 4947 | _scsih_expander_node_add(ioc, sas_expander); |
| 4948 | return 0; |
| 4949 | |
| 4950 | out_fail: |
| 4951 | |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4952 | if (mpt2sas_port) |
| 4953 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4954 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4955 | kfree(sas_expander); |
| 4956 | return rc; |
| 4957 | } |
| 4958 | |
| 4959 | /** |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 4960 | * _scsih_done - scsih callback handler. |
| 4961 | * @ioc: per adapter object |
| 4962 | * @smid: system request message index |
| 4963 | * @msix_index: MSIX table index supplied by the OS |
| 4964 | * @reply: reply message frame(lower 32bit addr) |
| 4965 | * |
| 4966 | * Callback handler when sending internal generated message frames. |
| 4967 | * The callback index passed is `ioc->scsih_cb_idx` |
| 4968 | * |
| 4969 | * Return 1 meaning mf should be freed from _base_interrupt |
| 4970 | * 0 means the mf is freed from this function. |
| 4971 | */ |
| 4972 | static u8 |
| 4973 | _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) |
| 4974 | { |
| 4975 | MPI2DefaultReply_t *mpi_reply; |
| 4976 | |
| 4977 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 4978 | if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED) |
| 4979 | return 1; |
| 4980 | if (ioc->scsih_cmds.smid != smid) |
| 4981 | return 1; |
| 4982 | ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE; |
| 4983 | if (mpi_reply) { |
| 4984 | memcpy(ioc->scsih_cmds.reply, mpi_reply, |
| 4985 | mpi_reply->MsgLength*4); |
| 4986 | ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 4987 | } |
| 4988 | ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING; |
| 4989 | complete(&ioc->scsih_cmds.done); |
| 4990 | return 1; |
| 4991 | } |
| 4992 | |
| 4993 | /** |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4994 | * mpt2sas_expander_remove - removing expander object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4995 | * @ioc: per adapter object |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4996 | * @sas_address: expander sas_address |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4997 | * |
| 4998 | * Return nothing. |
| 4999 | */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5000 | void |
| 5001 | mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5002 | { |
| 5003 | struct _sas_node *sas_expander; |
| 5004 | unsigned long flags; |
| 5005 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 5006 | if (ioc->shost_recovery) |
| 5007 | return; |
| 5008 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5009 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5010 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 5011 | sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5012 | if (sas_expander) |
| 5013 | list_del(&sas_expander->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5014 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5015 | if (sas_expander) |
| 5016 | _scsih_expander_node_remove(ioc, sas_expander); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5017 | } |
| 5018 | |
| 5019 | /** |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5020 | * _scsih_check_access_status - check access flags |
| 5021 | * @ioc: per adapter object |
| 5022 | * @sas_address: sas address |
| 5023 | * @handle: sas device handle |
| 5024 | * @access_flags: errors returned during discovery of the device |
| 5025 | * |
| 5026 | * Return 0 for success, else failure |
| 5027 | */ |
| 5028 | static u8 |
| 5029 | _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 5030 | u16 handle, u8 access_status) |
| 5031 | { |
| 5032 | u8 rc = 1; |
| 5033 | char *desc = NULL; |
| 5034 | |
| 5035 | switch (access_status) { |
| 5036 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: |
| 5037 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: |
| 5038 | rc = 0; |
| 5039 | break; |
| 5040 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: |
| 5041 | desc = "sata capability failed"; |
| 5042 | break; |
| 5043 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: |
| 5044 | desc = "sata affiliation conflict"; |
| 5045 | break; |
| 5046 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: |
| 5047 | desc = "route not addressable"; |
| 5048 | break; |
| 5049 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: |
| 5050 | desc = "smp error not addressable"; |
| 5051 | break; |
| 5052 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: |
| 5053 | desc = "device blocked"; |
| 5054 | break; |
| 5055 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: |
| 5056 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: |
| 5057 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: |
| 5058 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: |
| 5059 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: |
| 5060 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: |
| 5061 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: |
| 5062 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: |
| 5063 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: |
| 5064 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: |
| 5065 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: |
| 5066 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: |
| 5067 | desc = "sata initialization failed"; |
| 5068 | break; |
| 5069 | default: |
| 5070 | desc = "unknown"; |
| 5071 | break; |
| 5072 | } |
| 5073 | |
| 5074 | if (!rc) |
| 5075 | return 0; |
| 5076 | |
| 5077 | printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), " |
| 5078 | "handle(0x%04x)\n", ioc->name, desc, |
| 5079 | (unsigned long long)sas_address, handle); |
| 5080 | return rc; |
| 5081 | } |
| 5082 | |
| 5083 | static void |
| 5084 | _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 5085 | { |
| 5086 | Mpi2ConfigReply_t mpi_reply; |
| 5087 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 5088 | struct _sas_device *sas_device; |
| 5089 | u32 ioc_status; |
| 5090 | unsigned long flags; |
| 5091 | u64 sas_address; |
| 5092 | struct scsi_target *starget; |
| 5093 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 5094 | u32 device_info; |
| 5095 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5096 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5097 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 5098 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) |
| 5099 | return; |
| 5100 | |
| 5101 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 5102 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 5103 | return; |
| 5104 | |
| 5105 | /* check if this is end device */ |
| 5106 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 5107 | if (!(_scsih_is_end_device(device_info))) |
| 5108 | return; |
| 5109 | |
| 5110 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5111 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 5112 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5113 | sas_address); |
| 5114 | |
| 5115 | if (!sas_device) { |
| 5116 | printk(MPT2SAS_ERR_FMT "device is not present " |
| 5117 | "handle(0x%04x), no sas_device!!!\n", ioc->name, handle); |
| 5118 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5119 | return; |
| 5120 | } |
| 5121 | |
| 5122 | if (unlikely(sas_device->handle != handle)) { |
| 5123 | starget = sas_device->starget; |
| 5124 | sas_target_priv_data = starget->hostdata; |
| 5125 | starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)" |
| 5126 | " to (0x%04x)!!!\n", sas_device->handle, handle); |
| 5127 | sas_target_priv_data->handle = handle; |
| 5128 | sas_device->handle = handle; |
| 5129 | } |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5130 | |
| 5131 | /* check if device is present */ |
| 5132 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 5133 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 5134 | printk(MPT2SAS_ERR_FMT "device is not present " |
| 5135 | "handle(0x%04x), flags!!!\n", ioc->name, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5136 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5137 | return; |
| 5138 | } |
| 5139 | |
| 5140 | /* check if there were any issues with discovery */ |
| 5141 | if (_scsih_check_access_status(ioc, sas_address, handle, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5142 | sas_device_pg0.AccessStatus)) { |
| 5143 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5144 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5145 | } |
| 5146 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 5147 | _scsih_ublock_io_device(ioc, sas_address); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5148 | |
| 5149 | } |
| 5150 | |
| 5151 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5152 | * _scsih_add_device - creating sas device object |
| 5153 | * @ioc: per adapter object |
| 5154 | * @handle: sas device handle |
| 5155 | * @phy_num: phy number end device attached to |
| 5156 | * @is_pd: is this hidden raid component |
| 5157 | * |
| 5158 | * Creating end device object, stored in ioc->sas_device_list. |
| 5159 | * |
| 5160 | * Returns 0 for success, non-zero for failure. |
| 5161 | */ |
| 5162 | static int |
| 5163 | _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd) |
| 5164 | { |
| 5165 | Mpi2ConfigReply_t mpi_reply; |
| 5166 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 5167 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 5168 | struct _sas_device *sas_device; |
| 5169 | u32 ioc_status; |
| 5170 | __le64 sas_address; |
| 5171 | u32 device_info; |
| 5172 | unsigned long flags; |
| 5173 | |
| 5174 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 5175 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 5176 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5177 | ioc->name, __FILE__, __LINE__, __func__); |
| 5178 | return -1; |
| 5179 | } |
| 5180 | |
| 5181 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 5182 | MPI2_IOCSTATUS_MASK; |
| 5183 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5184 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5185 | ioc->name, __FILE__, __LINE__, __func__); |
| 5186 | return -1; |
| 5187 | } |
| 5188 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5189 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 5190 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5191 | /* check if device is present */ |
| 5192 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 5193 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 5194 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5195 | ioc->name, __FILE__, __LINE__, __func__); |
| 5196 | printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n", |
| 5197 | ioc->name, le16_to_cpu(sas_device_pg0.Flags)); |
| 5198 | return -1; |
| 5199 | } |
| 5200 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5201 | /* check if there were any issues with discovery */ |
| 5202 | if (_scsih_check_access_status(ioc, sas_address, handle, |
| 5203 | sas_device_pg0.AccessStatus)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5204 | return -1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5205 | |
| 5206 | /* check if this is end device */ |
| 5207 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 5208 | if (!(_scsih_is_end_device(device_info))) { |
| 5209 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5210 | ioc->name, __FILE__, __LINE__, __func__); |
| 5211 | return -1; |
| 5212 | } |
| 5213 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5214 | |
| 5215 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5216 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5217 | sas_address); |
| 5218 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5219 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5220 | if (sas_device) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5221 | return 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5222 | |
| 5223 | sas_device = kzalloc(sizeof(struct _sas_device), |
| 5224 | GFP_KERNEL); |
| 5225 | if (!sas_device) { |
| 5226 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5227 | ioc->name, __FILE__, __LINE__, __func__); |
| 5228 | return -1; |
| 5229 | } |
| 5230 | |
| 5231 | sas_device->handle = handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5232 | if (_scsih_get_sas_address(ioc, le16_to_cpu |
| 5233 | (sas_device_pg0.ParentDevHandle), |
| 5234 | &sas_device->sas_address_parent) != 0) |
| 5235 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5236 | ioc->name, __FILE__, __LINE__, __func__); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5237 | sas_device->enclosure_handle = |
| 5238 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 5239 | sas_device->slot = |
| 5240 | le16_to_cpu(sas_device_pg0.Slot); |
| 5241 | sas_device->device_info = device_info; |
| 5242 | sas_device->sas_address = sas_address; |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 5243 | sas_device->phy = sas_device_pg0.PhyNum; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5244 | |
| 5245 | /* get enclosure_logical_id */ |
Kashyap, Desai | 15052c9 | 2009-08-07 19:33:17 +0530 | [diff] [blame] | 5246 | if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0( |
| 5247 | ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 5248 | sas_device->enclosure_handle))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5249 | sas_device->enclosure_logical_id = |
| 5250 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5251 | |
| 5252 | /* get device name */ |
| 5253 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); |
| 5254 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5255 | if (ioc->wait_for_discovery_to_complete) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5256 | _scsih_sas_device_init_add(ioc, sas_device); |
| 5257 | else |
| 5258 | _scsih_sas_device_add(ioc, sas_device); |
| 5259 | |
| 5260 | return 0; |
| 5261 | } |
| 5262 | |
| 5263 | /** |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5264 | * _scsih_remove_device - removing sas device object |
| 5265 | * @ioc: per adapter object |
| 5266 | * @sas_device_delete: the sas_device object |
| 5267 | * |
| 5268 | * Return nothing. |
| 5269 | */ |
| 5270 | static void |
| 5271 | _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, |
| 5272 | struct _sas_device *sas_device) |
| 5273 | { |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5274 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 5275 | |
Sreekanth Reddy | bd58ea3 | 2014-09-12 15:35:19 +0530 | [diff] [blame] | 5276 | if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) && |
| 5277 | (sas_device->pfa_led_on)) { |
| 5278 | _scsih_turn_off_pfa_led(ioc, sas_device); |
| 5279 | sas_device->pfa_led_on = 0; |
| 5280 | } |
| 5281 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5282 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: " |
| 5283 | "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] | 5284 | sas_device->handle, (unsigned long long) |
| 5285 | sas_device->sas_address)); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5286 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5287 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 5288 | sas_target_priv_data = sas_device->starget->hostdata; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5289 | sas_target_priv_data->deleted = 1; |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 5290 | _scsih_ublock_io_device(ioc, sas_device->sas_address); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5291 | sas_target_priv_data->handle = |
| 5292 | MPT2SAS_INVALID_DEVICE_HANDLE; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5293 | } |
| 5294 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 5295 | if (!ioc->hide_drives) |
| 5296 | mpt2sas_transport_port_remove(ioc, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5297 | sas_device->sas_address, |
| 5298 | sas_device->sas_address_parent); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5299 | |
| 5300 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr" |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5301 | "(0x%016llx)\n", ioc->name, sas_device->handle, |
| 5302 | (unsigned long long) sas_device->sas_address); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5303 | |
| 5304 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: " |
| 5305 | "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] | 5306 | sas_device->handle, (unsigned long long) |
| 5307 | sas_device->sas_address)); |
| 5308 | kfree(sas_device); |
| 5309 | } |
| 5310 | /** |
| 5311 | * _scsih_device_remove_by_handle - removing device object by handle |
| 5312 | * @ioc: per adapter object |
| 5313 | * @handle: device handle |
| 5314 | * |
| 5315 | * Return nothing. |
| 5316 | */ |
| 5317 | static void |
| 5318 | _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 5319 | { |
| 5320 | struct _sas_device *sas_device; |
| 5321 | unsigned long flags; |
| 5322 | |
| 5323 | if (ioc->shost_recovery) |
| 5324 | return; |
| 5325 | |
| 5326 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5327 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 5328 | if (sas_device) |
| 5329 | list_del(&sas_device->list); |
| 5330 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5331 | if (sas_device) |
| 5332 | _scsih_remove_device(ioc, sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5333 | } |
| 5334 | |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5335 | /** |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5336 | * mpt2sas_device_remove_by_sas_address - removing device object by sas address |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5337 | * @ioc: per adapter object |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5338 | * @sas_address: device sas_address |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5339 | * |
| 5340 | * Return nothing. |
| 5341 | */ |
| 5342 | void |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5343 | mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 5344 | u64 sas_address) |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5345 | { |
| 5346 | struct _sas_device *sas_device; |
| 5347 | unsigned long flags; |
| 5348 | |
| 5349 | if (ioc->shost_recovery) |
| 5350 | return; |
| 5351 | |
| 5352 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5353 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5354 | sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5355 | if (sas_device) |
| 5356 | list_del(&sas_device->list); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5357 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5358 | if (sas_device) |
| 5359 | _scsih_remove_device(ioc, sas_device); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5360 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5361 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5362 | /** |
| 5363 | * _scsih_sas_topology_change_event_debug - debug for topology event |
| 5364 | * @ioc: per adapter object |
| 5365 | * @event_data: event data payload |
| 5366 | * Context: user. |
| 5367 | */ |
| 5368 | static void |
| 5369 | _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5370 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 5371 | { |
| 5372 | int i; |
| 5373 | u16 handle; |
| 5374 | u16 reason_code; |
| 5375 | u8 phy_number; |
| 5376 | char *status_str = NULL; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5377 | u8 link_rate, prev_link_rate; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5378 | |
| 5379 | switch (event_data->ExpStatus) { |
| 5380 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: |
| 5381 | status_str = "add"; |
| 5382 | break; |
| 5383 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: |
| 5384 | status_str = "remove"; |
| 5385 | break; |
| 5386 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5387 | case 0: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5388 | status_str = "responding"; |
| 5389 | break; |
| 5390 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: |
| 5391 | status_str = "remove delay"; |
| 5392 | break; |
| 5393 | default: |
| 5394 | status_str = "unknown status"; |
| 5395 | break; |
| 5396 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5397 | printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5398 | ioc->name, status_str); |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5399 | printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5400 | "start_phy(%02d), count(%d)\n", |
| 5401 | le16_to_cpu(event_data->ExpanderDevHandle), |
| 5402 | le16_to_cpu(event_data->EnclosureHandle), |
| 5403 | event_data->StartPhyNum, event_data->NumEntries); |
| 5404 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5405 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5406 | if (!handle) |
| 5407 | continue; |
| 5408 | phy_number = event_data->StartPhyNum + i; |
| 5409 | reason_code = event_data->PHY[i].PhyStatus & |
| 5410 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5411 | switch (reason_code) { |
| 5412 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5413 | status_str = "target add"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5414 | break; |
| 5415 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5416 | status_str = "target remove"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5417 | break; |
| 5418 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5419 | status_str = "delay target remove"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5420 | break; |
| 5421 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5422 | status_str = "link rate change"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5423 | break; |
| 5424 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5425 | status_str = "target responding"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5426 | break; |
| 5427 | default: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5428 | status_str = "unknown"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5429 | break; |
| 5430 | } |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5431 | link_rate = event_data->PHY[i].LinkRate >> 4; |
| 5432 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5433 | printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:" |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5434 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, |
| 5435 | handle, status_str, link_rate, prev_link_rate); |
| 5436 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5437 | } |
| 5438 | } |
| 5439 | #endif |
| 5440 | |
| 5441 | /** |
| 5442 | * _scsih_sas_topology_change_event - handle topology changes |
| 5443 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5444 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5445 | * Context: user. |
| 5446 | * |
| 5447 | */ |
| 5448 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5449 | _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5450 | struct fw_event_work *fw_event) |
| 5451 | { |
| 5452 | int i; |
| 5453 | u16 parent_handle, handle; |
| 5454 | u16 reason_code; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5455 | u8 phy_number, max_phys; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5456 | struct _sas_node *sas_expander; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5457 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5458 | unsigned long flags; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5459 | u8 link_rate, prev_link_rate; |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 5460 | Mpi2EventDataSasTopologyChangeList_t *event_data = |
| 5461 | (Mpi2EventDataSasTopologyChangeList_t *) |
| 5462 | fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5463 | |
| 5464 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5465 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5466 | _scsih_sas_topology_change_event_debug(ioc, event_data); |
| 5467 | #endif |
| 5468 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5469 | if (ioc->remove_host || ioc->pci_error_recovery) |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5470 | return; |
| 5471 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5472 | if (!ioc->sas_hba.num_phys) |
| 5473 | _scsih_sas_host_add(ioc); |
| 5474 | else |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5475 | _scsih_sas_host_refresh(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5476 | |
| 5477 | if (fw_event->ignore) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5478 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5479 | "event\n", ioc->name)); |
| 5480 | return; |
| 5481 | } |
| 5482 | |
| 5483 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 5484 | |
| 5485 | /* handle expander add */ |
| 5486 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) |
| 5487 | if (_scsih_expander_add(ioc, parent_handle) != 0) |
| 5488 | return; |
| 5489 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5490 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 5491 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 5492 | parent_handle); |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5493 | if (sas_expander) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5494 | sas_address = sas_expander->sas_address; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5495 | max_phys = sas_expander->num_phys; |
| 5496 | } else if (parent_handle < ioc->sas_hba.num_phys) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5497 | sas_address = ioc->sas_hba.sas_address; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5498 | max_phys = ioc->sas_hba.num_phys; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5499 | } else { |
| 5500 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5501 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5502 | } |
| 5503 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5504 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5505 | /* handle siblings events */ |
| 5506 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5507 | if (fw_event->ignore) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5508 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5509 | "expander event\n", ioc->name)); |
| 5510 | return; |
| 5511 | } |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 5512 | if (ioc->shost_recovery || ioc->remove_host || |
| 5513 | ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 5514 | return; |
Kashyap, Desai | 308609c | 2009-09-14 11:07:23 +0530 | [diff] [blame] | 5515 | phy_number = event_data->StartPhyNum + i; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5516 | if (phy_number >= max_phys) |
| 5517 | continue; |
Kashyap, Desai | 308609c | 2009-09-14 11:07:23 +0530 | [diff] [blame] | 5518 | reason_code = event_data->PHY[i].PhyStatus & |
| 5519 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5520 | if ((event_data->PHY[i].PhyStatus & |
| 5521 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != |
| 5522 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5523 | continue; |
| 5524 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5525 | if (!handle) |
| 5526 | continue; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5527 | link_rate = event_data->PHY[i].LinkRate >> 4; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5528 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5529 | switch (reason_code) { |
| 5530 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5531 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5532 | if (ioc->shost_recovery) |
| 5533 | break; |
| 5534 | |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5535 | if (link_rate == prev_link_rate) |
| 5536 | break; |
| 5537 | |
| 5538 | mpt2sas_transport_update_links(ioc, sas_address, |
| 5539 | handle, phy_number, link_rate); |
| 5540 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5541 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 5542 | break; |
| 5543 | |
| 5544 | _scsih_check_device(ioc, handle); |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5545 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5546 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5547 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5548 | if (ioc->shost_recovery) |
| 5549 | break; |
| 5550 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5551 | mpt2sas_transport_update_links(ioc, sas_address, |
| 5552 | handle, phy_number, link_rate); |
| 5553 | |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5554 | _scsih_add_device(ioc, handle, phy_number, 0); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5555 | break; |
| 5556 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5557 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5558 | _scsih_device_remove_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5559 | break; |
| 5560 | } |
| 5561 | } |
| 5562 | |
| 5563 | /* handle expander removal */ |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5564 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && |
| 5565 | sas_expander) |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5566 | mpt2sas_expander_remove(ioc, sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5567 | |
| 5568 | } |
| 5569 | |
| 5570 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5571 | /** |
| 5572 | * _scsih_sas_device_status_change_event_debug - debug for device event |
| 5573 | * @event_data: event data payload |
| 5574 | * Context: user. |
| 5575 | * |
| 5576 | * Return nothing. |
| 5577 | */ |
| 5578 | static void |
| 5579 | _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5580 | Mpi2EventDataSasDeviceStatusChange_t *event_data) |
| 5581 | { |
| 5582 | char *reason_str = NULL; |
| 5583 | |
| 5584 | switch (event_data->ReasonCode) { |
| 5585 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: |
| 5586 | reason_str = "smart data"; |
| 5587 | break; |
| 5588 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: |
| 5589 | reason_str = "unsupported device discovered"; |
| 5590 | break; |
| 5591 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: |
| 5592 | reason_str = "internal device reset"; |
| 5593 | break; |
| 5594 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: |
| 5595 | reason_str = "internal task abort"; |
| 5596 | break; |
| 5597 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: |
| 5598 | reason_str = "internal task abort set"; |
| 5599 | break; |
| 5600 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: |
| 5601 | reason_str = "internal clear task set"; |
| 5602 | break; |
| 5603 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: |
| 5604 | reason_str = "internal query task"; |
| 5605 | break; |
| 5606 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: |
| 5607 | reason_str = "sata init failure"; |
| 5608 | break; |
| 5609 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: |
| 5610 | reason_str = "internal device reset complete"; |
| 5611 | break; |
| 5612 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: |
| 5613 | reason_str = "internal task abort complete"; |
| 5614 | break; |
| 5615 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: |
| 5616 | reason_str = "internal async notification"; |
| 5617 | break; |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 5618 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5619 | reason_str = "expander reduced functionality"; |
| 5620 | break; |
| 5621 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5622 | reason_str = "expander reduced functionality complete"; |
| 5623 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5624 | default: |
| 5625 | reason_str = "unknown reason"; |
| 5626 | break; |
| 5627 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5628 | printk(MPT2SAS_INFO_FMT "device status change: (%s)\n" |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5629 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", |
| 5630 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), |
| 5631 | (unsigned long long)le64_to_cpu(event_data->SASAddress), |
| 5632 | le16_to_cpu(event_data->TaskTag)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5633 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5634 | 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] | 5635 | event_data->ASC, event_data->ASCQ); |
| 5636 | printk(KERN_INFO "\n"); |
| 5637 | } |
| 5638 | #endif |
| 5639 | |
| 5640 | /** |
| 5641 | * _scsih_sas_device_status_change_event - handle device status change |
| 5642 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5643 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5644 | * Context: user. |
| 5645 | * |
| 5646 | * Return nothing. |
| 5647 | */ |
| 5648 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5649 | _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 5650 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5651 | { |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5652 | struct MPT2SAS_TARGET *target_priv_data; |
| 5653 | struct _sas_device *sas_device; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 5654 | u64 sas_address; |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5655 | unsigned long flags; |
| 5656 | Mpi2EventDataSasDeviceStatusChange_t *event_data = |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 5657 | (Mpi2EventDataSasDeviceStatusChange_t *) |
| 5658 | fw_event->event_data; |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5659 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5660 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5661 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5662 | _scsih_sas_device_status_change_event_debug(ioc, |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5663 | event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5664 | #endif |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5665 | |
Kashyap, Desai | efe82a1 | 2011-01-04 11:34:17 +0530 | [diff] [blame] | 5666 | /* In MPI Revision K (0xC), the internal device reset complete was |
| 5667 | * implemented, so avoid setting tm_busy flag for older firmware. |
| 5668 | */ |
| 5669 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) |
| 5670 | return; |
| 5671 | |
Kashyap, Desai | f891dcf | 2010-03-17 16:22:21 +0530 | [diff] [blame] | 5672 | if (event_data->ReasonCode != |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5673 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && |
Kashyap, Desai | f891dcf | 2010-03-17 16:22:21 +0530 | [diff] [blame] | 5674 | event_data->ReasonCode != |
| 5675 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5676 | return; |
| 5677 | |
| 5678 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5679 | sas_address = le64_to_cpu(event_data->SASAddress); |
| 5680 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5681 | sas_address); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5682 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5683 | if (!sas_device || !sas_device->starget) { |
| 5684 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5685 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5686 | } |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5687 | |
| 5688 | target_priv_data = sas_device->starget->hostdata; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5689 | if (!target_priv_data) { |
| 5690 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5691 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5692 | } |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5693 | |
| 5694 | if (event_data->ReasonCode == |
| 5695 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) |
| 5696 | target_priv_data->tm_busy = 1; |
| 5697 | else |
| 5698 | target_priv_data->tm_busy = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5699 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5700 | } |
| 5701 | |
| 5702 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5703 | /** |
| 5704 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event |
| 5705 | * @ioc: per adapter object |
| 5706 | * @event_data: event data payload |
| 5707 | * Context: user. |
| 5708 | * |
| 5709 | * Return nothing. |
| 5710 | */ |
| 5711 | static void |
| 5712 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5713 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) |
| 5714 | { |
| 5715 | char *reason_str = NULL; |
| 5716 | |
| 5717 | switch (event_data->ReasonCode) { |
| 5718 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: |
| 5719 | reason_str = "enclosure add"; |
| 5720 | break; |
| 5721 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: |
| 5722 | reason_str = "enclosure remove"; |
| 5723 | break; |
| 5724 | default: |
| 5725 | reason_str = "unknown reason"; |
| 5726 | break; |
| 5727 | } |
| 5728 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5729 | printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5730 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" |
| 5731 | " number slots(%d)\n", ioc->name, reason_str, |
| 5732 | le16_to_cpu(event_data->EnclosureHandle), |
| 5733 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), |
| 5734 | le16_to_cpu(event_data->StartSlot)); |
| 5735 | } |
| 5736 | #endif |
| 5737 | |
| 5738 | /** |
| 5739 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events |
| 5740 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5741 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5742 | * Context: user. |
| 5743 | * |
| 5744 | * Return nothing. |
| 5745 | */ |
| 5746 | static void |
| 5747 | _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5748 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5749 | { |
| 5750 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5751 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5752 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 5753 | (Mpi2EventDataSasEnclDevStatusChange_t *) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5754 | fw_event->event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5755 | #endif |
| 5756 | } |
| 5757 | |
| 5758 | /** |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 5759 | * _scsih_sas_broadcast_primitive_event - handle broadcast events |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5760 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5761 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5762 | * Context: user. |
| 5763 | * |
| 5764 | * Return nothing. |
| 5765 | */ |
| 5766 | static void |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 5767 | _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5768 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5769 | { |
| 5770 | struct scsi_cmnd *scmd; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5771 | struct scsi_device *sdev; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5772 | u16 smid, handle; |
| 5773 | u32 lun; |
| 5774 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 5775 | u32 termination_count; |
| 5776 | u32 query_count; |
| 5777 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 5778 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = |
| 5779 | (Mpi2EventDataSasBroadcastPrimitive_t *) |
| 5780 | fw_event->event_data; |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 5781 | u16 ioc_status; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5782 | unsigned long flags; |
| 5783 | int r; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5784 | u8 max_retries = 0; |
| 5785 | u8 task_abort_retries; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5786 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5787 | mutex_lock(&ioc->tm_cmds.mutex); |
Reddy, Sreekanth | c3a634b | 2013-02-26 17:36:12 +0530 | [diff] [blame] | 5788 | pr_info(MPT2SAS_FMT |
| 5789 | "%s: enter: phy number(%d), width(%d)\n", |
| 5790 | ioc->name, __func__, event_data->PhyNum, |
| 5791 | event_data->PortWidth); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5792 | |
| 5793 | _scsih_block_io_all_device(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5794 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5795 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5796 | mpi_reply = ioc->tm_cmds.reply; |
| 5797 | broadcast_aen_retry: |
| 5798 | |
| 5799 | /* sanity checks for retrying this loop */ |
| 5800 | if (max_retries++ == 5) { |
| 5801 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n", |
| 5802 | ioc->name, __func__)); |
| 5803 | goto out; |
| 5804 | } else if (max_retries > 1) |
| 5805 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n", |
| 5806 | ioc->name, __func__, max_retries - 1)); |
| 5807 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5808 | termination_count = 0; |
| 5809 | query_count = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 5810 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5811 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5812 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5813 | scmd = _scsih_scsi_lookup_get(ioc, smid); |
| 5814 | if (!scmd) |
| 5815 | continue; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5816 | sdev = scmd->device; |
| 5817 | sas_device_priv_data = sdev->hostdata; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5818 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) |
| 5819 | continue; |
| 5820 | /* skip hidden raid components */ |
| 5821 | if (sas_device_priv_data->sas_target->flags & |
| 5822 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 5823 | continue; |
| 5824 | /* skip volumes */ |
| 5825 | if (sas_device_priv_data->sas_target->flags & |
| 5826 | MPT_TARGET_FLAGS_VOLUME) |
| 5827 | continue; |
| 5828 | |
| 5829 | handle = sas_device_priv_data->sas_target->handle; |
| 5830 | lun = sas_device_priv_data->lun; |
| 5831 | query_count++; |
| 5832 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5833 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5834 | goto out; |
| 5835 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5836 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5837 | r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun, |
Matthew Wilcox | 2e45c8b | 2014-03-27 16:40:32 -0400 | [diff] [blame] | 5838 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5839 | TM_MUTEX_OFF); |
| 5840 | if (r == FAILED) { |
| 5841 | sdev_printk(KERN_WARNING, sdev, |
| 5842 | "mpt2sas_scsih_issue_tm: FAILED when sending " |
| 5843 | "QUERY_TASK: scmd(%p)\n", scmd); |
| 5844 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5845 | goto broadcast_aen_retry; |
| 5846 | } |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 5847 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) |
| 5848 | & MPI2_IOCSTATUS_MASK; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5849 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5850 | sdev_printk(KERN_WARNING, sdev, "query task: FAILED " |
| 5851 | "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status, |
| 5852 | scmd); |
| 5853 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5854 | goto broadcast_aen_retry; |
| 5855 | } |
| 5856 | |
| 5857 | /* see if IO is still owned by IOC and target */ |
| 5858 | if (mpi_reply->ResponseCode == |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5859 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || |
| 5860 | mpi_reply->ResponseCode == |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5861 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5862 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5863 | continue; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5864 | } |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5865 | task_abort_retries = 0; |
| 5866 | tm_retry: |
| 5867 | if (task_abort_retries++ == 60) { |
| 5868 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 5869 | "%s: ABORT_TASK: giving up\n", ioc->name, |
| 5870 | __func__)); |
| 5871 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5872 | goto broadcast_aen_retry; |
| 5873 | } |
| 5874 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5875 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5876 | goto out_no_lock; |
| 5877 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5878 | r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, |
| 5879 | sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, |
Matthew Wilcox | 2e45c8b | 2014-03-27 16:40:32 -0400 | [diff] [blame] | 5880 | TM_MUTEX_OFF); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5881 | if (r == FAILED) { |
| 5882 | sdev_printk(KERN_WARNING, sdev, |
| 5883 | "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : " |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5884 | "scmd(%p)\n", scmd); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5885 | goto tm_retry; |
| 5886 | } |
| 5887 | |
| 5888 | if (task_abort_retries > 1) |
| 5889 | sdev_printk(KERN_WARNING, sdev, |
| 5890 | "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" |
| 5891 | " scmd(%p)\n", |
| 5892 | task_abort_retries - 1, scmd); |
| 5893 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5894 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5895 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5896 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5897 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5898 | if (ioc->broadcast_aen_pending) { |
| 5899 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to" |
| 5900 | " pending AEN\n", ioc->name, __func__)); |
| 5901 | ioc->broadcast_aen_pending = 0; |
| 5902 | goto broadcast_aen_retry; |
| 5903 | } |
| 5904 | |
| 5905 | out: |
| 5906 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 5907 | out_no_lock: |
| 5908 | |
| 5909 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5910 | "%s - exit, query_count = %d termination_count = %d\n", |
| 5911 | ioc->name, __func__, query_count, termination_count)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5912 | |
| 5913 | ioc->broadcast_aen_busy = 0; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5914 | if (!ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5915 | _scsih_ublock_io_all_device(ioc); |
| 5916 | mutex_unlock(&ioc->tm_cmds.mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5917 | } |
| 5918 | |
| 5919 | /** |
| 5920 | * _scsih_sas_discovery_event - handle discovery events |
| 5921 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5922 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5923 | * Context: user. |
| 5924 | * |
| 5925 | * Return nothing. |
| 5926 | */ |
| 5927 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5928 | _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc, |
| 5929 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5930 | { |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 5931 | Mpi2EventDataSasDiscovery_t *event_data = |
| 5932 | (Mpi2EventDataSasDiscovery_t *) |
| 5933 | fw_event->event_data; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5934 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5935 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5936 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5937 | printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5938 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? |
| 5939 | "start" : "stop"); |
| 5940 | if (event_data->DiscoveryStatus) |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 5941 | printk("discovery_status(0x%08x)", |
| 5942 | le32_to_cpu(event_data->DiscoveryStatus)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5943 | printk("\n"); |
| 5944 | } |
| 5945 | #endif |
| 5946 | |
| 5947 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 5948 | !ioc->sas_hba.num_phys) { |
| 5949 | if (disable_discovery > 0 && ioc->shost_recovery) { |
| 5950 | /* Wait for the reset to complete */ |
| 5951 | while (ioc->shost_recovery) |
| 5952 | ssleep(1); |
| 5953 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5954 | _scsih_sas_host_add(ioc); |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 5955 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5956 | } |
| 5957 | |
| 5958 | /** |
| 5959 | * _scsih_reprobe_lun - reprobing lun |
| 5960 | * @sdev: scsi device struct |
| 5961 | * @no_uld_attach: sdev->no_uld_attach flag setting |
| 5962 | * |
| 5963 | **/ |
| 5964 | static void |
| 5965 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) |
| 5966 | { |
| 5967 | int rc; |
| 5968 | |
| 5969 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
| 5970 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", |
| 5971 | sdev->no_uld_attach ? "hidding" : "exposing"); |
| 5972 | rc = scsi_device_reprobe(sdev); |
| 5973 | } |
| 5974 | |
| 5975 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5976 | * _scsih_sas_volume_add - add new volume |
| 5977 | * @ioc: per adapter object |
| 5978 | * @element: IR config element data |
| 5979 | * Context: user. |
| 5980 | * |
| 5981 | * Return nothing. |
| 5982 | */ |
| 5983 | static void |
| 5984 | _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc, |
| 5985 | Mpi2EventIrConfigElement_t *element) |
| 5986 | { |
| 5987 | struct _raid_device *raid_device; |
| 5988 | unsigned long flags; |
| 5989 | u64 wwid; |
| 5990 | u16 handle = le16_to_cpu(element->VolDevHandle); |
| 5991 | int rc; |
| 5992 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5993 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 5994 | if (!wwid) { |
| 5995 | printk(MPT2SAS_ERR_FMT |
| 5996 | "failure at %s:%d/%s()!\n", ioc->name, |
| 5997 | __FILE__, __LINE__, __func__); |
| 5998 | return; |
| 5999 | } |
| 6000 | |
| 6001 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6002 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); |
| 6003 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6004 | |
| 6005 | if (raid_device) |
| 6006 | return; |
| 6007 | |
| 6008 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 6009 | if (!raid_device) { |
| 6010 | printk(MPT2SAS_ERR_FMT |
| 6011 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6012 | __FILE__, __LINE__, __func__); |
| 6013 | return; |
| 6014 | } |
| 6015 | |
| 6016 | raid_device->id = ioc->sas_id++; |
| 6017 | raid_device->channel = RAID_CHANNEL; |
| 6018 | raid_device->handle = handle; |
| 6019 | raid_device->wwid = wwid; |
| 6020 | _scsih_raid_device_add(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6021 | if (!ioc->wait_for_discovery_to_complete) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6022 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 6023 | raid_device->id, 0); |
| 6024 | if (rc) |
| 6025 | _scsih_raid_device_remove(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6026 | } else { |
| 6027 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6028 | _scsih_determine_boot_device(ioc, raid_device, 1); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6029 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6030 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6031 | } |
| 6032 | |
| 6033 | /** |
| 6034 | * _scsih_sas_volume_delete - delete volume |
| 6035 | * @ioc: per adapter object |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6036 | * @handle: volume device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6037 | * Context: user. |
| 6038 | * |
| 6039 | * Return nothing. |
| 6040 | */ |
| 6041 | static void |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6042 | _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6043 | { |
| 6044 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6045 | unsigned long flags; |
| 6046 | struct MPT2SAS_TARGET *sas_target_priv_data; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6047 | struct scsi_target *starget = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6048 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6049 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6050 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6051 | if (raid_device) { |
| 6052 | if (raid_device->starget) { |
| 6053 | starget = raid_device->starget; |
| 6054 | sas_target_priv_data = starget->hostdata; |
| 6055 | sas_target_priv_data->deleted = 1; |
| 6056 | } |
| 6057 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" |
| 6058 | "(0x%016llx)\n", ioc->name, raid_device->handle, |
| 6059 | (unsigned long long) raid_device->wwid); |
| 6060 | list_del(&raid_device->list); |
| 6061 | kfree(raid_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6062 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6063 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6064 | if (starget) |
| 6065 | scsi_remove_target(&starget->dev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6066 | } |
| 6067 | |
| 6068 | /** |
| 6069 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX |
| 6070 | * @ioc: per adapter object |
| 6071 | * @element: IR config element data |
| 6072 | * Context: user. |
| 6073 | * |
| 6074 | * Return nothing. |
| 6075 | */ |
| 6076 | static void |
| 6077 | _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc, |
| 6078 | Mpi2EventIrConfigElement_t *element) |
| 6079 | { |
| 6080 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6081 | struct scsi_target *starget = NULL; |
| 6082 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6083 | unsigned long flags; |
| 6084 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 6085 | |
| 6086 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6087 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6088 | if (sas_device) { |
| 6089 | sas_device->volume_handle = 0; |
| 6090 | sas_device->volume_wwid = 0; |
| 6091 | clear_bit(handle, ioc->pd_handles); |
| 6092 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 6093 | starget = sas_device->starget; |
| 6094 | sas_target_priv_data = starget->hostdata; |
| 6095 | sas_target_priv_data->flags &= |
| 6096 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 6097 | } |
| 6098 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6099 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6100 | if (!sas_device) |
| 6101 | return; |
| 6102 | |
| 6103 | /* exposing raid component */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6104 | if (starget) |
| 6105 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6106 | } |
| 6107 | |
| 6108 | /** |
| 6109 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX |
| 6110 | * @ioc: per adapter object |
| 6111 | * @element: IR config element data |
| 6112 | * Context: user. |
| 6113 | * |
| 6114 | * Return nothing. |
| 6115 | */ |
| 6116 | static void |
| 6117 | _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc, |
| 6118 | Mpi2EventIrConfigElement_t *element) |
| 6119 | { |
| 6120 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6121 | struct scsi_target *starget = NULL; |
| 6122 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6123 | unsigned long flags; |
| 6124 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6125 | u16 volume_handle = 0; |
| 6126 | u64 volume_wwid = 0; |
| 6127 | |
| 6128 | mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle); |
| 6129 | if (volume_handle) |
| 6130 | mpt2sas_config_get_volume_wwid(ioc, volume_handle, |
| 6131 | &volume_wwid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6132 | |
| 6133 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6134 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6135 | if (sas_device) { |
| 6136 | set_bit(handle, ioc->pd_handles); |
| 6137 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 6138 | starget = sas_device->starget; |
| 6139 | sas_target_priv_data = starget->hostdata; |
| 6140 | sas_target_priv_data->flags |= |
| 6141 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 6142 | sas_device->volume_handle = volume_handle; |
| 6143 | sas_device->volume_wwid = volume_wwid; |
| 6144 | } |
| 6145 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6146 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6147 | if (!sas_device) |
| 6148 | return; |
| 6149 | |
| 6150 | /* hiding raid component */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6151 | if (starget) |
| 6152 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6153 | } |
| 6154 | |
| 6155 | /** |
| 6156 | * _scsih_sas_pd_delete - delete pd component |
| 6157 | * @ioc: per adapter object |
| 6158 | * @element: IR config element data |
| 6159 | * Context: user. |
| 6160 | * |
| 6161 | * Return nothing. |
| 6162 | */ |
| 6163 | static void |
| 6164 | _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc, |
| 6165 | Mpi2EventIrConfigElement_t *element) |
| 6166 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6167 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 6168 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6169 | _scsih_device_remove_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6170 | } |
| 6171 | |
| 6172 | /** |
| 6173 | * _scsih_sas_pd_add - remove pd component |
| 6174 | * @ioc: per adapter object |
| 6175 | * @element: IR config element data |
| 6176 | * Context: user. |
| 6177 | * |
| 6178 | * Return nothing. |
| 6179 | */ |
| 6180 | static void |
| 6181 | _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc, |
| 6182 | Mpi2EventIrConfigElement_t *element) |
| 6183 | { |
| 6184 | struct _sas_device *sas_device; |
| 6185 | unsigned long flags; |
| 6186 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6187 | Mpi2ConfigReply_t mpi_reply; |
| 6188 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6189 | u32 ioc_status; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6190 | u64 sas_address; |
| 6191 | u16 parent_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6192 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6193 | set_bit(handle, ioc->pd_handles); |
| 6194 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6195 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6196 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6197 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6198 | if (sas_device) |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6199 | return; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6200 | |
| 6201 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 6202 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 6203 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6204 | ioc->name, __FILE__, __LINE__, __func__); |
| 6205 | return; |
| 6206 | } |
| 6207 | |
| 6208 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6209 | MPI2_IOCSTATUS_MASK; |
| 6210 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6211 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6212 | ioc->name, __FILE__, __LINE__, __func__); |
| 6213 | return; |
| 6214 | } |
| 6215 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6216 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6217 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 6218 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 6219 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6220 | |
| 6221 | _scsih_add_device(ioc, handle, 0, 1); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6222 | } |
| 6223 | |
| 6224 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 6225 | /** |
| 6226 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events |
| 6227 | * @ioc: per adapter object |
| 6228 | * @event_data: event data payload |
| 6229 | * Context: user. |
| 6230 | * |
| 6231 | * Return nothing. |
| 6232 | */ |
| 6233 | static void |
| 6234 | _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 6235 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 6236 | { |
| 6237 | Mpi2EventIrConfigElement_t *element; |
| 6238 | u8 element_type; |
| 6239 | int i; |
| 6240 | char *reason_str = NULL, *element_str = NULL; |
| 6241 | |
| 6242 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 6243 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6244 | printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6245 | ioc->name, (le32_to_cpu(event_data->Flags) & |
| 6246 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? |
| 6247 | "foreign" : "native", event_data->NumElements); |
| 6248 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6249 | switch (element->ReasonCode) { |
| 6250 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
| 6251 | reason_str = "add"; |
| 6252 | break; |
| 6253 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
| 6254 | reason_str = "remove"; |
| 6255 | break; |
| 6256 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: |
| 6257 | reason_str = "no change"; |
| 6258 | break; |
| 6259 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
| 6260 | reason_str = "hide"; |
| 6261 | break; |
| 6262 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
| 6263 | reason_str = "unhide"; |
| 6264 | break; |
| 6265 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 6266 | reason_str = "volume_created"; |
| 6267 | break; |
| 6268 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 6269 | reason_str = "volume_deleted"; |
| 6270 | break; |
| 6271 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
| 6272 | reason_str = "pd_created"; |
| 6273 | break; |
| 6274 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
| 6275 | reason_str = "pd_deleted"; |
| 6276 | break; |
| 6277 | default: |
| 6278 | reason_str = "unknown reason"; |
| 6279 | break; |
| 6280 | } |
| 6281 | element_type = le16_to_cpu(element->ElementFlags) & |
| 6282 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; |
| 6283 | switch (element_type) { |
| 6284 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: |
| 6285 | element_str = "volume"; |
| 6286 | break; |
| 6287 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: |
| 6288 | element_str = "phys disk"; |
| 6289 | break; |
| 6290 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: |
| 6291 | element_str = "hot spare"; |
| 6292 | break; |
| 6293 | default: |
| 6294 | element_str = "unknown element"; |
| 6295 | break; |
| 6296 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6297 | printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6298 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, |
| 6299 | reason_str, le16_to_cpu(element->VolDevHandle), |
| 6300 | le16_to_cpu(element->PhysDiskDevHandle), |
| 6301 | element->PhysDiskNum); |
| 6302 | } |
| 6303 | } |
| 6304 | #endif |
| 6305 | |
| 6306 | /** |
| 6307 | * _scsih_sas_ir_config_change_event - handle ir configuration change events |
| 6308 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6309 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6310 | * Context: user. |
| 6311 | * |
| 6312 | * Return nothing. |
| 6313 | */ |
| 6314 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6315 | _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 6316 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6317 | { |
| 6318 | Mpi2EventIrConfigElement_t *element; |
| 6319 | int i; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6320 | u8 foreign_config; |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 6321 | Mpi2EventDataIrConfigChangeList_t *event_data = |
| 6322 | (Mpi2EventDataIrConfigChangeList_t *) |
| 6323 | fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6324 | |
| 6325 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6326 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6327 | && !ioc->hide_ir_msg) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6328 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
| 6329 | |
| 6330 | #endif |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6331 | |
| 6332 | if (ioc->shost_recovery) |
| 6333 | return; |
| 6334 | |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6335 | foreign_config = (le32_to_cpu(event_data->Flags) & |
| 6336 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6337 | |
| 6338 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 6339 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6340 | |
| 6341 | switch (element->ReasonCode) { |
| 6342 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 6343 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6344 | if (!foreign_config) |
| 6345 | _scsih_sas_volume_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6346 | break; |
| 6347 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 6348 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6349 | if (!foreign_config) |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6350 | _scsih_sas_volume_delete(ioc, |
| 6351 | le16_to_cpu(element->VolDevHandle)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6352 | break; |
| 6353 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6354 | if (!ioc->is_warpdrive) |
| 6355 | _scsih_sas_pd_hide(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6356 | break; |
| 6357 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6358 | if (!ioc->is_warpdrive) |
| 6359 | _scsih_sas_pd_expose(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6360 | break; |
| 6361 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6362 | if (!ioc->is_warpdrive) |
| 6363 | _scsih_sas_pd_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6364 | break; |
| 6365 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6366 | if (!ioc->is_warpdrive) |
| 6367 | _scsih_sas_pd_delete(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6368 | break; |
| 6369 | } |
| 6370 | } |
| 6371 | } |
| 6372 | |
| 6373 | /** |
| 6374 | * _scsih_sas_ir_volume_event - IR volume event |
| 6375 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6376 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6377 | * Context: user. |
| 6378 | * |
| 6379 | * Return nothing. |
| 6380 | */ |
| 6381 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6382 | _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc, |
| 6383 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6384 | { |
| 6385 | u64 wwid; |
| 6386 | unsigned long flags; |
| 6387 | struct _raid_device *raid_device; |
| 6388 | u16 handle; |
| 6389 | u32 state; |
| 6390 | int rc; |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 6391 | Mpi2EventDataIrVolume_t *event_data = |
| 6392 | (Mpi2EventDataIrVolume_t *) |
| 6393 | fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6394 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6395 | if (ioc->shost_recovery) |
| 6396 | return; |
| 6397 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6398 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 6399 | return; |
| 6400 | |
| 6401 | handle = le16_to_cpu(event_data->VolDevHandle); |
| 6402 | state = le32_to_cpu(event_data->NewValue); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6403 | if (!ioc->hide_ir_msg) |
| 6404 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " |
| 6405 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 6406 | le32_to_cpu(event_data->PreviousValue), state)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6407 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6408 | switch (state) { |
| 6409 | case MPI2_RAID_VOL_STATE_MISSING: |
| 6410 | case MPI2_RAID_VOL_STATE_FAILED: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6411 | _scsih_sas_volume_delete(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6412 | break; |
| 6413 | |
| 6414 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 6415 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 6416 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6417 | |
| 6418 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6419 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 6420 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6421 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6422 | if (raid_device) |
| 6423 | break; |
| 6424 | |
| 6425 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 6426 | if (!wwid) { |
| 6427 | printk(MPT2SAS_ERR_FMT |
| 6428 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6429 | __FILE__, __LINE__, __func__); |
| 6430 | break; |
| 6431 | } |
| 6432 | |
| 6433 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 6434 | if (!raid_device) { |
| 6435 | printk(MPT2SAS_ERR_FMT |
| 6436 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6437 | __FILE__, __LINE__, __func__); |
| 6438 | break; |
| 6439 | } |
| 6440 | |
| 6441 | raid_device->id = ioc->sas_id++; |
| 6442 | raid_device->channel = RAID_CHANNEL; |
| 6443 | raid_device->handle = handle; |
| 6444 | raid_device->wwid = wwid; |
| 6445 | _scsih_raid_device_add(ioc, raid_device); |
| 6446 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 6447 | raid_device->id, 0); |
| 6448 | if (rc) |
| 6449 | _scsih_raid_device_remove(ioc, raid_device); |
| 6450 | break; |
| 6451 | |
| 6452 | case MPI2_RAID_VOL_STATE_INITIALIZING: |
| 6453 | default: |
| 6454 | break; |
| 6455 | } |
| 6456 | } |
| 6457 | |
| 6458 | /** |
| 6459 | * _scsih_sas_ir_physical_disk_event - PD event |
| 6460 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6461 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6462 | * Context: user. |
| 6463 | * |
| 6464 | * Return nothing. |
| 6465 | */ |
| 6466 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6467 | _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc, |
| 6468 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6469 | { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6470 | u16 handle, parent_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6471 | u32 state; |
| 6472 | struct _sas_device *sas_device; |
| 6473 | unsigned long flags; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6474 | Mpi2ConfigReply_t mpi_reply; |
| 6475 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6476 | u32 ioc_status; |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 6477 | Mpi2EventDataIrPhysicalDisk_t *event_data = |
| 6478 | (Mpi2EventDataIrPhysicalDisk_t *) |
| 6479 | fw_event->event_data; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6480 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6481 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6482 | if (ioc->shost_recovery) |
| 6483 | return; |
| 6484 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6485 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) |
| 6486 | return; |
| 6487 | |
| 6488 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); |
| 6489 | state = le32_to_cpu(event_data->NewValue); |
| 6490 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6491 | if (!ioc->hide_ir_msg) |
| 6492 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " |
| 6493 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 6494 | le32_to_cpu(event_data->PreviousValue), state)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6495 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6496 | switch (state) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6497 | case MPI2_RAID_PD_STATE_ONLINE: |
| 6498 | case MPI2_RAID_PD_STATE_DEGRADED: |
| 6499 | case MPI2_RAID_PD_STATE_REBUILDING: |
| 6500 | case MPI2_RAID_PD_STATE_OPTIMAL: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6501 | case MPI2_RAID_PD_STATE_HOT_SPARE: |
| 6502 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6503 | if (!ioc->is_warpdrive) |
| 6504 | set_bit(handle, ioc->pd_handles); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6505 | |
| 6506 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6507 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6508 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6509 | |
| 6510 | if (sas_device) |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6511 | return; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6512 | |
| 6513 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6514 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 6515 | handle))) { |
| 6516 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6517 | ioc->name, __FILE__, __LINE__, __func__); |
| 6518 | return; |
| 6519 | } |
| 6520 | |
| 6521 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6522 | MPI2_IOCSTATUS_MASK; |
| 6523 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6524 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6525 | ioc->name, __FILE__, __LINE__, __func__); |
| 6526 | return; |
| 6527 | } |
| 6528 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6529 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6530 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 6531 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 6532 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6533 | |
| 6534 | _scsih_add_device(ioc, handle, 0, 1); |
| 6535 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6536 | break; |
| 6537 | |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6538 | case MPI2_RAID_PD_STATE_OFFLINE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6539 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: |
| 6540 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6541 | default: |
| 6542 | break; |
| 6543 | } |
| 6544 | } |
| 6545 | |
| 6546 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 6547 | /** |
| 6548 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event |
| 6549 | * @ioc: per adapter object |
| 6550 | * @event_data: event data payload |
| 6551 | * Context: user. |
| 6552 | * |
| 6553 | * Return nothing. |
| 6554 | */ |
| 6555 | static void |
| 6556 | _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 6557 | Mpi2EventDataIrOperationStatus_t *event_data) |
| 6558 | { |
| 6559 | char *reason_str = NULL; |
| 6560 | |
| 6561 | switch (event_data->RAIDOperation) { |
| 6562 | case MPI2_EVENT_IR_RAIDOP_RESYNC: |
| 6563 | reason_str = "resync"; |
| 6564 | break; |
| 6565 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: |
| 6566 | reason_str = "online capacity expansion"; |
| 6567 | break; |
| 6568 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: |
| 6569 | reason_str = "consistency check"; |
| 6570 | break; |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 6571 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: |
| 6572 | reason_str = "background init"; |
| 6573 | break; |
| 6574 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: |
| 6575 | reason_str = "make data consistent"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6576 | break; |
| 6577 | } |
| 6578 | |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 6579 | if (!reason_str) |
| 6580 | return; |
| 6581 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6582 | printk(MPT2SAS_INFO_FMT "raid operational status: (%s)" |
| 6583 | "\thandle(0x%04x), percent complete(%d)\n", |
| 6584 | ioc->name, reason_str, |
| 6585 | le16_to_cpu(event_data->VolDevHandle), |
| 6586 | event_data->PercentComplete); |
| 6587 | } |
| 6588 | #endif |
| 6589 | |
| 6590 | /** |
| 6591 | * _scsih_sas_ir_operation_status_event - handle RAID operation events |
| 6592 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6593 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6594 | * Context: user. |
| 6595 | * |
| 6596 | * Return nothing. |
| 6597 | */ |
| 6598 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6599 | _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc, |
| 6600 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6601 | { |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 6602 | Mpi2EventDataIrOperationStatus_t *event_data = |
| 6603 | (Mpi2EventDataIrOperationStatus_t *) |
| 6604 | fw_event->event_data; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6605 | static struct _raid_device *raid_device; |
| 6606 | unsigned long flags; |
| 6607 | u16 handle; |
| 6608 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6609 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6610 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6611 | && !ioc->hide_ir_msg) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6612 | _scsih_sas_ir_operation_status_event_debug(ioc, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6613 | event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6614 | #endif |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6615 | |
| 6616 | /* code added for raid transport support */ |
| 6617 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { |
| 6618 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6619 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6620 | handle = le16_to_cpu(event_data->VolDevHandle); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6621 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6622 | if (raid_device) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6623 | raid_device->percent_complete = |
| 6624 | event_data->PercentComplete; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6625 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6626 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6627 | } |
| 6628 | |
| 6629 | /** |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6630 | * _scsih_prep_device_scan - initialize parameters prior to device scan |
| 6631 | * @ioc: per adapter object |
| 6632 | * |
| 6633 | * Set the deleted flag prior to device scan. If the device is found during |
| 6634 | * the scan, then we clear the deleted flag. |
| 6635 | */ |
| 6636 | static void |
| 6637 | _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc) |
| 6638 | { |
| 6639 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 6640 | struct scsi_device *sdev; |
| 6641 | |
| 6642 | shost_for_each_device(sdev, ioc->shost) { |
| 6643 | sas_device_priv_data = sdev->hostdata; |
| 6644 | if (sas_device_priv_data && sas_device_priv_data->sas_target) |
| 6645 | sas_device_priv_data->sas_target->deleted = 1; |
| 6646 | } |
| 6647 | } |
| 6648 | |
| 6649 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6650 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding |
| 6651 | * @ioc: per adapter object |
| 6652 | * @sas_address: sas address |
| 6653 | * @slot: enclosure slot id |
| 6654 | * @handle: device handle |
| 6655 | * |
| 6656 | * After host reset, find out whether devices are still responding. |
| 6657 | * Used in _scsi_remove_unresponsive_sas_devices. |
| 6658 | * |
| 6659 | * Return nothing. |
| 6660 | */ |
| 6661 | static void |
| 6662 | _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 6663 | u16 slot, u16 handle) |
| 6664 | { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6665 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6666 | struct scsi_target *starget; |
| 6667 | struct _sas_device *sas_device; |
| 6668 | unsigned long flags; |
| 6669 | |
| 6670 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6671 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { |
| 6672 | if (sas_device->sas_address == sas_address && |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6673 | sas_device->slot == slot) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6674 | sas_device->responding = 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6675 | starget = sas_device->starget; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6676 | if (starget && starget->hostdata) { |
| 6677 | sas_target_priv_data = starget->hostdata; |
| 6678 | sas_target_priv_data->tm_busy = 0; |
| 6679 | sas_target_priv_data->deleted = 0; |
| 6680 | } else |
| 6681 | sas_target_priv_data = NULL; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6682 | if (starget) |
| 6683 | starget_printk(KERN_INFO, starget, |
| 6684 | "handle(0x%04x), sas_addr(0x%016llx), " |
| 6685 | "enclosure logical id(0x%016llx), " |
| 6686 | "slot(%d)\n", handle, |
| 6687 | (unsigned long long)sas_device->sas_address, |
| 6688 | (unsigned long long) |
| 6689 | sas_device->enclosure_logical_id, |
| 6690 | sas_device->slot); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6691 | if (sas_device->handle == handle) |
| 6692 | goto out; |
| 6693 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 6694 | sas_device->handle); |
| 6695 | sas_device->handle = handle; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6696 | if (sas_target_priv_data) |
| 6697 | sas_target_priv_data->handle = handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6698 | goto out; |
| 6699 | } |
| 6700 | } |
| 6701 | out: |
| 6702 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6703 | } |
| 6704 | |
| 6705 | /** |
| 6706 | * _scsih_search_responding_sas_devices - |
| 6707 | * @ioc: per adapter object |
| 6708 | * |
| 6709 | * After host reset, find out whether devices are still responding. |
| 6710 | * If not remove. |
| 6711 | * |
| 6712 | * Return nothing. |
| 6713 | */ |
| 6714 | static void |
| 6715 | _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6716 | { |
| 6717 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6718 | Mpi2ConfigReply_t mpi_reply; |
| 6719 | u16 ioc_status; |
| 6720 | __le64 sas_address; |
| 6721 | u16 handle; |
| 6722 | u32 device_info; |
| 6723 | u16 slot; |
| 6724 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6725 | printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6726 | |
| 6727 | if (list_empty(&ioc->sas_device_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6728 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6729 | |
| 6730 | handle = 0xFFFF; |
| 6731 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6732 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 6733 | handle))) { |
| 6734 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6735 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 1c50e8d | 2013-07-25 11:29:45 +0530 | [diff] [blame] | 6736 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6737 | break; |
| 6738 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 6739 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 6740 | if (!(_scsih_is_end_device(device_info))) |
| 6741 | continue; |
| 6742 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 6743 | slot = le16_to_cpu(sas_device_pg0.Slot); |
| 6744 | _scsih_mark_responding_sas_device(ioc, sas_address, slot, |
| 6745 | handle); |
| 6746 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6747 | out: |
| 6748 | printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n", |
| 6749 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6750 | } |
| 6751 | |
| 6752 | /** |
| 6753 | * _scsih_mark_responding_raid_device - mark a raid_device as responding |
| 6754 | * @ioc: per adapter object |
| 6755 | * @wwid: world wide identifier for raid volume |
| 6756 | * @handle: device handle |
| 6757 | * |
| 6758 | * After host reset, find out whether devices are still responding. |
| 6759 | * Used in _scsi_remove_unresponsive_raid_devices. |
| 6760 | * |
| 6761 | * Return nothing. |
| 6762 | */ |
| 6763 | static void |
| 6764 | _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid, |
| 6765 | u16 handle) |
| 6766 | { |
| 6767 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 6768 | struct scsi_target *starget; |
| 6769 | struct _raid_device *raid_device; |
| 6770 | unsigned long flags; |
| 6771 | |
| 6772 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6773 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 6774 | if (raid_device->wwid == wwid && raid_device->starget) { |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6775 | starget = raid_device->starget; |
| 6776 | if (starget && starget->hostdata) { |
| 6777 | sas_target_priv_data = starget->hostdata; |
| 6778 | sas_target_priv_data->deleted = 0; |
| 6779 | } else |
| 6780 | sas_target_priv_data = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6781 | raid_device->responding = 1; |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6782 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6783 | starget_printk(KERN_INFO, raid_device->starget, |
| 6784 | "handle(0x%04x), wwid(0x%016llx)\n", handle, |
| 6785 | (unsigned long long)raid_device->wwid); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6786 | /* |
| 6787 | * WARPDRIVE: The handles of the PDs might have changed |
| 6788 | * across the host reset so re-initialize the |
| 6789 | * required data for Direct IO |
| 6790 | */ |
| 6791 | _scsih_init_warpdrive_properties(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6792 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6793 | if (raid_device->handle == handle) { |
| 6794 | spin_unlock_irqrestore(&ioc->raid_device_lock, |
| 6795 | flags); |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6796 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6797 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6798 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 6799 | raid_device->handle); |
| 6800 | raid_device->handle = handle; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6801 | if (sas_target_priv_data) |
| 6802 | sas_target_priv_data->handle = handle; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6803 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6804 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6805 | } |
| 6806 | } |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6807 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6808 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6809 | } |
| 6810 | |
| 6811 | /** |
| 6812 | * _scsih_search_responding_raid_devices - |
| 6813 | * @ioc: per adapter object |
| 6814 | * |
| 6815 | * After host reset, find out whether devices are still responding. |
| 6816 | * If not remove. |
| 6817 | * |
| 6818 | * Return nothing. |
| 6819 | */ |
| 6820 | static void |
| 6821 | _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6822 | { |
| 6823 | Mpi2RaidVolPage1_t volume_pg1; |
Kashyap, Desai | d417d1c | 2010-06-17 13:48:10 +0530 | [diff] [blame] | 6824 | Mpi2RaidVolPage0_t volume_pg0; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6825 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6826 | Mpi2ConfigReply_t mpi_reply; |
| 6827 | u16 ioc_status; |
| 6828 | u16 handle; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6829 | u8 phys_disk_num; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6830 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6831 | if (!ioc->ir_firmware) |
| 6832 | return; |
| 6833 | |
| 6834 | printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n", |
| 6835 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6836 | |
| 6837 | if (list_empty(&ioc->raid_device_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6838 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6839 | |
| 6840 | handle = 0xFFFF; |
| 6841 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 6842 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 6843 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6844 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 1c50e8d | 2013-07-25 11:29:45 +0530 | [diff] [blame] | 6845 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6846 | break; |
| 6847 | handle = le16_to_cpu(volume_pg1.DevHandle); |
Kashyap, Desai | d417d1c | 2010-06-17 13:48:10 +0530 | [diff] [blame] | 6848 | |
| 6849 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 6850 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 6851 | sizeof(Mpi2RaidVolPage0_t))) |
| 6852 | continue; |
| 6853 | |
| 6854 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 6855 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 6856 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) |
| 6857 | _scsih_mark_responding_raid_device(ioc, |
| 6858 | le64_to_cpu(volume_pg1.WWID), handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6859 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6860 | |
| 6861 | /* refresh the pd_handles */ |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6862 | if (!ioc->is_warpdrive) { |
| 6863 | phys_disk_num = 0xFF; |
| 6864 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); |
| 6865 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 6866 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 6867 | phys_disk_num))) { |
| 6868 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6869 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 1c50e8d | 2013-07-25 11:29:45 +0530 | [diff] [blame] | 6870 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6871 | break; |
| 6872 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 6873 | handle = le16_to_cpu(pd_pg0.DevHandle); |
| 6874 | set_bit(handle, ioc->pd_handles); |
| 6875 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6876 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6877 | out: |
| 6878 | printk(MPT2SAS_INFO_FMT "search for responding raid volumes: " |
| 6879 | "complete\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6880 | } |
| 6881 | |
| 6882 | /** |
| 6883 | * _scsih_mark_responding_expander - mark a expander as responding |
| 6884 | * @ioc: per adapter object |
| 6885 | * @sas_address: sas address |
| 6886 | * @handle: |
| 6887 | * |
| 6888 | * After host reset, find out whether devices are still responding. |
| 6889 | * Used in _scsi_remove_unresponsive_expanders. |
| 6890 | * |
| 6891 | * Return nothing. |
| 6892 | */ |
| 6893 | static void |
| 6894 | _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 6895 | u16 handle) |
| 6896 | { |
| 6897 | struct _sas_node *sas_expander; |
| 6898 | unsigned long flags; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6899 | int i; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6900 | |
| 6901 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 6902 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6903 | if (sas_expander->sas_address != sas_address) |
| 6904 | continue; |
| 6905 | sas_expander->responding = 1; |
| 6906 | if (sas_expander->handle == handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6907 | goto out; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6908 | printk(KERN_INFO "\texpander(0x%016llx): handle changed" |
| 6909 | " from(0x%04x) to (0x%04x)!!!\n", |
| 6910 | (unsigned long long)sas_expander->sas_address, |
| 6911 | sas_expander->handle, handle); |
| 6912 | sas_expander->handle = handle; |
| 6913 | for (i = 0 ; i < sas_expander->num_phys ; i++) |
| 6914 | sas_expander->phy[i].handle = handle; |
| 6915 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6916 | } |
| 6917 | out: |
| 6918 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 6919 | } |
| 6920 | |
| 6921 | /** |
| 6922 | * _scsih_search_responding_expanders - |
| 6923 | * @ioc: per adapter object |
| 6924 | * |
| 6925 | * After host reset, find out whether devices are still responding. |
| 6926 | * If not remove. |
| 6927 | * |
| 6928 | * Return nothing. |
| 6929 | */ |
| 6930 | static void |
| 6931 | _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc) |
| 6932 | { |
| 6933 | Mpi2ExpanderPage0_t expander_pg0; |
| 6934 | Mpi2ConfigReply_t mpi_reply; |
| 6935 | u16 ioc_status; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 6936 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6937 | u16 handle; |
| 6938 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6939 | printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6940 | |
| 6941 | if (list_empty(&ioc->sas_expander_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6942 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6943 | |
| 6944 | handle = 0xFFFF; |
| 6945 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 6946 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 6947 | |
| 6948 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6949 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 1c50e8d | 2013-07-25 11:29:45 +0530 | [diff] [blame] | 6950 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6951 | break; |
| 6952 | |
| 6953 | handle = le16_to_cpu(expander_pg0.DevHandle); |
| 6954 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
| 6955 | printk(KERN_INFO "\texpander present: handle(0x%04x), " |
| 6956 | "sas_addr(0x%016llx)\n", handle, |
| 6957 | (unsigned long long)sas_address); |
| 6958 | _scsih_mark_responding_expander(ioc, sas_address, handle); |
| 6959 | } |
| 6960 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6961 | out: |
| 6962 | printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6963 | } |
| 6964 | |
| 6965 | /** |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6966 | * _scsih_remove_unresponding_sas_devices - removing unresponding devices |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6967 | * @ioc: per adapter object |
| 6968 | * |
| 6969 | * Return nothing. |
| 6970 | */ |
| 6971 | static void |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6972 | _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6973 | { |
| 6974 | struct _sas_device *sas_device, *sas_device_next; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6975 | struct _sas_node *sas_expander, *sas_expander_next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6976 | struct _raid_device *raid_device, *raid_device_next; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6977 | struct list_head tmp_list; |
| 6978 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6979 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6980 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n", |
| 6981 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6982 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6983 | /* removing unresponding end devices */ |
| 6984 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n", |
| 6985 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6986 | list_for_each_entry_safe(sas_device, sas_device_next, |
| 6987 | &ioc->sas_device_list, list) { |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6988 | if (!sas_device->responding) |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 6989 | mpt2sas_device_remove_by_sas_address(ioc, |
| 6990 | sas_device->sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6991 | else |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6992 | sas_device->responding = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6993 | } |
| 6994 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6995 | /* removing unresponding volumes */ |
| 6996 | if (ioc->ir_firmware) { |
| 6997 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: " |
| 6998 | "volumes\n", ioc->name); |
| 6999 | list_for_each_entry_safe(raid_device, raid_device_next, |
| 7000 | &ioc->raid_device_list, list) { |
| 7001 | if (!raid_device->responding) |
| 7002 | _scsih_sas_volume_delete(ioc, |
| 7003 | raid_device->handle); |
| 7004 | else |
| 7005 | raid_device->responding = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7006 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7007 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7008 | /* removing unresponding expanders */ |
| 7009 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n", |
| 7010 | ioc->name); |
| 7011 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 7012 | INIT_LIST_HEAD(&tmp_list); |
| 7013 | list_for_each_entry_safe(sas_expander, sas_expander_next, |
| 7014 | &ioc->sas_expander_list, list) { |
| 7015 | if (!sas_expander->responding) |
| 7016 | list_move_tail(&sas_expander->list, &tmp_list); |
| 7017 | else |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7018 | sas_expander->responding = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7019 | } |
| 7020 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 7021 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, |
| 7022 | list) { |
| 7023 | list_del(&sas_expander->list); |
| 7024 | _scsih_expander_node_remove(ioc, sas_expander); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [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: complete\n", |
| 7027 | ioc->name); |
| 7028 | /* unblock devices */ |
| 7029 | _scsih_ublock_io_all_device(ioc); |
| 7030 | } |
| 7031 | |
| 7032 | static void |
| 7033 | _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc, |
| 7034 | struct _sas_node *sas_expander, u16 handle) |
| 7035 | { |
| 7036 | Mpi2ExpanderPage1_t expander_pg1; |
| 7037 | Mpi2ConfigReply_t mpi_reply; |
| 7038 | int i; |
| 7039 | |
| 7040 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 7041 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 7042 | &expander_pg1, i, handle))) { |
| 7043 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7044 | ioc->name, __FILE__, __LINE__, __func__); |
| 7045 | return; |
| 7046 | } |
| 7047 | |
| 7048 | mpt2sas_transport_update_links(ioc, sas_expander->sas_address, |
| 7049 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, |
| 7050 | expander_pg1.NegotiatedLinkRate >> 4); |
| 7051 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7052 | } |
| 7053 | |
| 7054 | /** |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7055 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7056 | * @ioc: per adapter object |
| 7057 | * |
| 7058 | * Return nothing. |
| 7059 | */ |
| 7060 | static void |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7061 | _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc) |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7062 | { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7063 | Mpi2ExpanderPage0_t expander_pg0; |
| 7064 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 7065 | Mpi2RaidVolPage1_t volume_pg1; |
| 7066 | Mpi2RaidVolPage0_t volume_pg0; |
| 7067 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 7068 | Mpi2EventIrConfigElement_t element; |
| 7069 | Mpi2ConfigReply_t mpi_reply; |
| 7070 | u8 phys_disk_num; |
| 7071 | u16 ioc_status; |
| 7072 | u16 handle, parent_handle; |
| 7073 | u64 sas_address; |
| 7074 | struct _sas_device *sas_device; |
| 7075 | struct _sas_node *expander_device; |
| 7076 | static struct _raid_device *raid_device; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7077 | u8 retry_count; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7078 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7079 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7080 | printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7081 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7082 | _scsih_sas_host_refresh(ioc); |
| 7083 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7084 | printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n", |
| 7085 | ioc->name); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7086 | /* expanders */ |
| 7087 | handle = 0xFFFF; |
| 7088 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 7089 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 7090 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7091 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7092 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7093 | printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: " |
| 7094 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7095 | ioc->name, ioc_status, |
| 7096 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7097 | break; |
| 7098 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7099 | handle = le16_to_cpu(expander_pg0.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7100 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7101 | expander_device = mpt2sas_scsih_expander_find_by_sas_address( |
| 7102 | ioc, le64_to_cpu(expander_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7103 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7104 | if (expander_device) |
| 7105 | _scsih_refresh_expander_links(ioc, expander_device, |
| 7106 | handle); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7107 | else { |
| 7108 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: " |
| 7109 | "handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7110 | ioc->name, handle, (unsigned long long) |
| 7111 | le64_to_cpu(expander_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7112 | _scsih_expander_add(ioc, handle); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7113 | printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: " |
| 7114 | "handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7115 | ioc->name, handle, (unsigned long long) |
| 7116 | le64_to_cpu(expander_pg0.SASAddress)); |
| 7117 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7118 | } |
| 7119 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7120 | printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n", |
| 7121 | ioc->name); |
| 7122 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7123 | if (!ioc->ir_firmware) |
| 7124 | goto skip_to_sas; |
| 7125 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7126 | 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] | 7127 | /* phys disk */ |
| 7128 | phys_disk_num = 0xFF; |
| 7129 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 7130 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 7131 | phys_disk_num))) { |
| 7132 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7133 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7134 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7135 | printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:" |
| 7136 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7137 | ioc->name, ioc_status, |
| 7138 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7139 | break; |
| 7140 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7141 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 7142 | handle = le16_to_cpu(pd_pg0.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7143 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7144 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7145 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7146 | if (sas_device) |
| 7147 | continue; |
| 7148 | if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 7149 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 7150 | handle) != 0) |
| 7151 | continue; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7152 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7153 | MPI2_IOCSTATUS_MASK; |
| 7154 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7155 | printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan " |
| 7156 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7157 | ioc->name, ioc_status, |
| 7158 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7159 | break; |
| 7160 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7161 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 7162 | if (!_scsih_get_sas_address(ioc, parent_handle, |
| 7163 | &sas_address)) { |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7164 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: " |
| 7165 | " handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7166 | ioc->name, handle, (unsigned long long) |
| 7167 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7168 | mpt2sas_transport_update_links(ioc, sas_address, |
| 7169 | handle, sas_device_pg0.PhyNum, |
| 7170 | MPI2_SAS_NEG_LINK_RATE_1_5); |
| 7171 | set_bit(handle, ioc->pd_handles); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7172 | retry_count = 0; |
| 7173 | /* This will retry adding the end device. |
| 7174 | * _scsih_add_device() will decide on retries and |
| 7175 | * return "1" when it should be retried |
| 7176 | */ |
| 7177 | while (_scsih_add_device(ioc, handle, retry_count++, |
| 7178 | 1)) { |
| 7179 | ssleep(1); |
| 7180 | } |
| 7181 | printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: " |
| 7182 | " handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7183 | ioc->name, handle, (unsigned long long) |
| 7184 | le64_to_cpu(sas_device_pg0.SASAddress)); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7185 | } |
| 7186 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7187 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7188 | printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n", |
| 7189 | ioc->name); |
| 7190 | |
| 7191 | 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] | 7192 | /* volumes */ |
| 7193 | handle = 0xFFFF; |
| 7194 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 7195 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 7196 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7197 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7198 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7199 | printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: " |
| 7200 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7201 | ioc->name, ioc_status, |
| 7202 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7203 | break; |
| 7204 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7205 | handle = le16_to_cpu(volume_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7206 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7207 | raid_device = _scsih_raid_device_find_by_wwid(ioc, |
| 7208 | le64_to_cpu(volume_pg1.WWID)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7209 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7210 | if (raid_device) |
| 7211 | continue; |
| 7212 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 7213 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 7214 | sizeof(Mpi2RaidVolPage0_t))) |
| 7215 | continue; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7216 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7217 | MPI2_IOCSTATUS_MASK; |
| 7218 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7219 | printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: " |
| 7220 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7221 | ioc->name, ioc_status, |
| 7222 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7223 | break; |
| 7224 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7225 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 7226 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 7227 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { |
| 7228 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); |
| 7229 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; |
| 7230 | element.VolDevHandle = volume_pg1.DevHandle; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7231 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: " |
| 7232 | " handle (0x%04x)\n", ioc->name, |
| 7233 | volume_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7234 | _scsih_sas_volume_add(ioc, &element); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7235 | printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: " |
| 7236 | " handle (0x%04x)\n", ioc->name, |
| 7237 | volume_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7238 | } |
| 7239 | } |
| 7240 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7241 | printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n", |
| 7242 | ioc->name); |
| 7243 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7244 | skip_to_sas: |
| 7245 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7246 | printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n", |
| 7247 | ioc->name); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7248 | /* sas devices */ |
| 7249 | handle = 0xFFFF; |
| 7250 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 7251 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 7252 | handle))) { |
| 7253 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7254 | MPI2_IOCSTATUS_MASK; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7255 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 7256 | printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:" |
| 7257 | " ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7258 | ioc->name, ioc_status, |
| 7259 | le32_to_cpu(mpi_reply.IOCLogInfo)); |
| 7260 | break; |
| 7261 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7262 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 7263 | if (!(_scsih_is_end_device( |
| 7264 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) |
| 7265 | continue; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7266 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7267 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 7268 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7269 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7270 | if (sas_device) |
| 7271 | continue; |
| 7272 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 7273 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7274 | printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: " |
| 7275 | "handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7276 | ioc->name, handle, (unsigned long long) |
| 7277 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7278 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 7279 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7280 | retry_count = 0; |
| 7281 | /* This will retry adding the end device. |
| 7282 | * _scsih_add_device() will decide on retries and |
| 7283 | * return "1" when it should be retried |
| 7284 | */ |
| 7285 | while (_scsih_add_device(ioc, handle, retry_count++, |
| 7286 | 0)) { |
| 7287 | ssleep(1); |
| 7288 | } |
| 7289 | printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: " |
| 7290 | "handle (0x%04x), sas_addr(0x%016llx)\n", |
| 7291 | ioc->name, handle, (unsigned long long) |
| 7292 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7293 | } |
| 7294 | } |
| 7295 | |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 7296 | printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n", |
| 7297 | ioc->name); |
| 7298 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7299 | printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7300 | } |
| 7301 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7302 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7303 | /** |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7304 | * mpt2sas_scsih_reset_handler - reset callback handler (for scsih) |
| 7305 | * @ioc: per adapter object |
| 7306 | * @reset_phase: phase |
| 7307 | * |
| 7308 | * The handler for doing any required cleanup or initialization. |
| 7309 | * |
| 7310 | * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET, |
| 7311 | * MPT2_IOC_DONE_RESET |
| 7312 | * |
| 7313 | * Return nothing. |
| 7314 | */ |
| 7315 | void |
| 7316 | mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase) |
| 7317 | { |
| 7318 | switch (reset_phase) { |
| 7319 | case MPT2_IOC_PRE_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7320 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7321 | "MPT2_IOC_PRE_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7322 | break; |
| 7323 | case MPT2_IOC_AFTER_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7324 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7325 | "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7326 | if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) { |
| 7327 | ioc->scsih_cmds.status |= MPT2_CMD_RESET; |
| 7328 | mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid); |
| 7329 | complete(&ioc->scsih_cmds.done); |
| 7330 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7331 | if (ioc->tm_cmds.status & MPT2_CMD_PENDING) { |
| 7332 | ioc->tm_cmds.status |= MPT2_CMD_RESET; |
| 7333 | mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid); |
| 7334 | complete(&ioc->tm_cmds.done); |
| 7335 | } |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7336 | _scsih_fw_event_cleanup_queue(ioc); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7337 | _scsih_flush_running_cmds(ioc); |
| 7338 | break; |
| 7339 | case MPT2_IOC_DONE_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7340 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7341 | "MPT2_IOC_DONE_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7342 | _scsih_sas_host_refresh(ioc); |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 7343 | _scsih_prep_device_scan(ioc); |
| 7344 | _scsih_search_responding_sas_devices(ioc); |
| 7345 | _scsih_search_responding_raid_devices(ioc); |
| 7346 | _scsih_search_responding_expanders(ioc); |
sreekanth.reddy@lsi.com | 14aa7f7 | 2012-07-17 15:56:13 +0530 | [diff] [blame] | 7347 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && |
| 7348 | !ioc->sas_hba.num_phys)) { |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7349 | _scsih_prep_device_scan(ioc); |
| 7350 | _scsih_search_responding_sas_devices(ioc); |
| 7351 | _scsih_search_responding_raid_devices(ioc); |
| 7352 | _scsih_search_responding_expanders(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7353 | _scsih_error_recovery_delete_devices(ioc); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7354 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7355 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7356 | } |
| 7357 | } |
| 7358 | |
| 7359 | /** |
| 7360 | * _firmware_event_work - delayed task for processing firmware events |
| 7361 | * @ioc: per adapter object |
| 7362 | * @work: equal to the fw_event_work object |
| 7363 | * Context: user. |
| 7364 | * |
| 7365 | * Return nothing. |
| 7366 | */ |
| 7367 | static void |
| 7368 | _firmware_event_work(struct work_struct *work) |
| 7369 | { |
| 7370 | struct fw_event_work *fw_event = container_of(work, |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7371 | struct fw_event_work, delayed_work.work); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7372 | struct MPT2SAS_ADAPTER *ioc = fw_event->ioc; |
| 7373 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7374 | /* the queue is being flushed so ignore this event */ |
Reddy, Sreekanth | 02b7708 | 2014-07-14 12:00:49 +0530 | [diff] [blame] | 7375 | if (ioc->remove_host || |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7376 | ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7377 | _scsih_fw_event_free(ioc, fw_event); |
| 7378 | return; |
| 7379 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7380 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7381 | switch (fw_event->event) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7382 | case MPT2SAS_REMOVE_UNRESPONDING_DEVICES: |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7383 | while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7384 | ssleep(1); |
| 7385 | _scsih_remove_unresponding_sas_devices(ioc); |
| 7386 | _scsih_scan_for_devices_after_reset(ioc); |
| 7387 | break; |
| 7388 | case MPT2SAS_PORT_ENABLE_COMPLETE: |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7389 | ioc->start_scan = 0; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7390 | |
Reddy, Sreekanth | b0df96a0 | 2013-02-26 16:59:59 +0530 | [diff] [blame] | 7391 | if (missing_delay[0] != -1 && missing_delay[1] != -1) |
| 7392 | mpt2sas_base_update_missing_delay(ioc, missing_delay[0], |
| 7393 | missing_delay[1]); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7394 | |
| 7395 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete " |
| 7396 | "from worker thread\n", ioc->name)); |
| 7397 | break; |
Sreekanth Reddy | bd58ea3 | 2014-09-12 15:35:19 +0530 | [diff] [blame] | 7398 | case MPT2SAS_TURN_ON_PFA_LED: |
| 7399 | _scsih_turn_on_pfa_led(ioc, fw_event->device_handle); |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 7400 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7401 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7402 | _scsih_sas_topology_change_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7403 | break; |
| 7404 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7405 | _scsih_sas_device_status_change_event(ioc, |
| 7406 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7407 | break; |
| 7408 | case MPI2_EVENT_SAS_DISCOVERY: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7409 | _scsih_sas_discovery_event(ioc, |
| 7410 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7411 | break; |
| 7412 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 7413 | _scsih_sas_broadcast_primitive_event(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7414 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7415 | break; |
| 7416 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
| 7417 | _scsih_sas_enclosure_dev_status_change_event(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7418 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7419 | break; |
| 7420 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7421 | _scsih_sas_ir_config_change_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7422 | break; |
| 7423 | case MPI2_EVENT_IR_VOLUME: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7424 | _scsih_sas_ir_volume_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7425 | break; |
| 7426 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7427 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7428 | break; |
| 7429 | case MPI2_EVENT_IR_OPERATION_STATUS: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7430 | _scsih_sas_ir_operation_status_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7431 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7432 | } |
| 7433 | _scsih_fw_event_free(ioc, fw_event); |
| 7434 | } |
| 7435 | |
| 7436 | /** |
| 7437 | * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time) |
| 7438 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7439 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7440 | * @reply: reply message frame(lower 32bit addr) |
| 7441 | * Context: interrupt. |
| 7442 | * |
| 7443 | * This function merely adds a new work task into ioc->firmware_event_thread. |
| 7444 | * The tasks are worked from _firmware_event_work in user context. |
| 7445 | * |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7446 | * Returns void. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7447 | */ |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7448 | void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7449 | mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, |
| 7450 | u32 reply) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7451 | { |
| 7452 | struct fw_event_work *fw_event; |
| 7453 | Mpi2EventNotificationReply_t *mpi_reply; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7454 | u16 event; |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 7455 | u16 sz; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7456 | |
| 7457 | /* events turned off due to host reset or driver unloading */ |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7458 | if (ioc->remove_host || ioc->pci_error_recovery) |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7459 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7460 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7461 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 7462 | |
| 7463 | if (unlikely(!mpi_reply)) { |
| 7464 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 7465 | ioc->name, __FILE__, __LINE__, __func__); |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7466 | return; |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 7467 | } |
| 7468 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7469 | event = le16_to_cpu(mpi_reply->Event); |
| 7470 | |
| 7471 | switch (event) { |
| 7472 | /* handle these */ |
| 7473 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 7474 | { |
| 7475 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = |
| 7476 | (Mpi2EventDataSasBroadcastPrimitive_t *) |
| 7477 | mpi_reply->EventData; |
| 7478 | |
| 7479 | if (baen_data->Primitive != |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7480 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7481 | return; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7482 | |
| 7483 | if (ioc->broadcast_aen_busy) { |
| 7484 | ioc->broadcast_aen_pending++; |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7485 | return; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7486 | } else |
| 7487 | ioc->broadcast_aen_busy = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7488 | break; |
| 7489 | } |
| 7490 | |
| 7491 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
| 7492 | _scsih_check_topo_delete_events(ioc, |
| 7493 | (Mpi2EventDataSasTopologyChangeList_t *) |
| 7494 | mpi_reply->EventData); |
| 7495 | break; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 7496 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
| 7497 | _scsih_check_ir_config_unhide_events(ioc, |
| 7498 | (Mpi2EventDataIrConfigChangeList_t *) |
| 7499 | mpi_reply->EventData); |
| 7500 | break; |
| 7501 | case MPI2_EVENT_IR_VOLUME: |
| 7502 | _scsih_check_volume_delete_events(ioc, |
| 7503 | (Mpi2EventDataIrVolume_t *) |
| 7504 | mpi_reply->EventData); |
| 7505 | break; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7506 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
| 7507 | { |
| 7508 | Mpi2EventDataLogEntryAdded_t *log_entry; |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 7509 | __le32 *log_code; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7510 | |
| 7511 | if (!ioc->is_warpdrive) |
| 7512 | break; |
| 7513 | |
| 7514 | log_entry = (Mpi2EventDataLogEntryAdded_t *) |
| 7515 | mpi_reply->EventData; |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 7516 | log_code = (__le32 *)log_entry->LogData; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7517 | |
| 7518 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
| 7519 | != MPT2_WARPDRIVE_LOGENTRY) |
| 7520 | break; |
| 7521 | |
| 7522 | switch (le32_to_cpu(*log_code)) { |
| 7523 | case MPT2_WARPDRIVE_LC_SSDT: |
| 7524 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " |
| 7525 | "IO Throttling has occurred in the WarpDrive " |
| 7526 | "subsystem. Check WarpDrive documentation for " |
| 7527 | "additional details.\n", ioc->name); |
| 7528 | break; |
| 7529 | case MPT2_WARPDRIVE_LC_SSDLW: |
| 7530 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " |
| 7531 | "Program/Erase Cycles for the WarpDrive subsystem " |
| 7532 | "in degraded range. Check WarpDrive documentation " |
| 7533 | "for additional details.\n", ioc->name); |
| 7534 | break; |
| 7535 | case MPT2_WARPDRIVE_LC_SSDLF: |
| 7536 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " |
| 7537 | "There are no Program/Erase Cycles for the " |
| 7538 | "WarpDrive subsystem. The storage device will be " |
| 7539 | "in read-only mode. Check WarpDrive documentation " |
| 7540 | "for additional details.\n", ioc->name); |
| 7541 | break; |
| 7542 | case MPT2_WARPDRIVE_LC_BRMF: |
| 7543 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " |
| 7544 | "The Backup Rail Monitor has failed on the " |
| 7545 | "WarpDrive subsystem. Check WarpDrive " |
| 7546 | "documentation for additional details.\n", |
| 7547 | ioc->name); |
| 7548 | break; |
| 7549 | } |
| 7550 | |
| 7551 | break; |
| 7552 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7553 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 7554 | case MPI2_EVENT_IR_OPERATION_STATUS: |
| 7555 | case MPI2_EVENT_SAS_DISCOVERY: |
| 7556 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7557 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7558 | break; |
| 7559 | |
| 7560 | default: /* ignore the rest */ |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7561 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7562 | } |
| 7563 | |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 7564 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
| 7565 | fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7566 | if (!fw_event) { |
| 7567 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7568 | ioc->name, __FILE__, __LINE__, __func__); |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7569 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7570 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7571 | |
Joe Lawrence | 00713ad | 2014-06-25 17:03:33 -0400 | [diff] [blame] | 7572 | memcpy(fw_event->event_data, mpi_reply->EventData, sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7573 | fw_event->ioc = ioc; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7574 | fw_event->VF_ID = mpi_reply->VF_ID; |
| 7575 | fw_event->VP_ID = mpi_reply->VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7576 | fw_event->event = event; |
| 7577 | _scsih_fw_event_add(ioc, fw_event); |
Sreekanth Reddy | 6409a7d | 2013-07-25 11:24:35 +0530 | [diff] [blame] | 7578 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7579 | } |
| 7580 | |
| 7581 | /* shost template */ |
| 7582 | static struct scsi_host_template scsih_driver_template = { |
| 7583 | .module = THIS_MODULE, |
| 7584 | .name = "Fusion MPT SAS Host", |
| 7585 | .proc_name = MPT2SAS_DRIVER_NAME, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7586 | .queuecommand = _scsih_qcmd, |
| 7587 | .target_alloc = _scsih_target_alloc, |
| 7588 | .slave_alloc = _scsih_slave_alloc, |
| 7589 | .slave_configure = _scsih_slave_configure, |
| 7590 | .target_destroy = _scsih_target_destroy, |
| 7591 | .slave_destroy = _scsih_slave_destroy, |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7592 | .scan_finished = _scsih_scan_finished, |
| 7593 | .scan_start = _scsih_scan_start, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7594 | .change_queue_depth = _scsih_change_queue_depth, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7595 | .eh_abort_handler = _scsih_abort, |
| 7596 | .eh_device_reset_handler = _scsih_dev_reset, |
| 7597 | .eh_target_reset_handler = _scsih_target_reset, |
| 7598 | .eh_host_reset_handler = _scsih_host_reset, |
| 7599 | .bios_param = _scsih_bios_param, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7600 | .can_queue = 1, |
| 7601 | .this_id = -1, |
| 7602 | .sg_tablesize = MPT2SAS_SG_DEPTH, |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 7603 | .max_sectors = 32767, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7604 | .cmd_per_lun = 7, |
| 7605 | .use_clustering = ENABLE_CLUSTERING, |
| 7606 | .shost_attrs = mpt2sas_host_attrs, |
| 7607 | .sdev_attrs = mpt2sas_dev_attrs, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 7608 | .track_queue_depth = 1, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7609 | }; |
| 7610 | |
| 7611 | /** |
| 7612 | * _scsih_expander_node_remove - removing expander device from list. |
| 7613 | * @ioc: per adapter object |
| 7614 | * @sas_expander: the sas_device object |
| 7615 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 7616 | * |
| 7617 | * Removing object and freeing associated memory from the |
| 7618 | * ioc->sas_expander_list. |
| 7619 | * |
| 7620 | * Return nothing. |
| 7621 | */ |
| 7622 | static void |
| 7623 | _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc, |
| 7624 | struct _sas_node *sas_expander) |
| 7625 | { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7626 | struct _sas_port *mpt2sas_port, *next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7627 | |
| 7628 | /* remove sibling ports attached to this expander */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7629 | list_for_each_entry_safe(mpt2sas_port, next, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7630 | &sas_expander->sas_port_list, port_list) { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7631 | if (ioc->shost_recovery) |
| 7632 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7633 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7634 | SAS_END_DEVICE) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7635 | mpt2sas_device_remove_by_sas_address(ioc, |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7636 | mpt2sas_port->remote_identify.sas_address); |
| 7637 | else if (mpt2sas_port->remote_identify.device_type == |
| 7638 | SAS_EDGE_EXPANDER_DEVICE || |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7639 | mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7640 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7641 | mpt2sas_expander_remove(ioc, |
| 7642 | mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7643 | } |
| 7644 | |
| 7645 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7646 | sas_expander->sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7647 | |
| 7648 | printk(MPT2SAS_INFO_FMT "expander_remove: handle" |
| 7649 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, |
| 7650 | sas_expander->handle, (unsigned long long) |
| 7651 | sas_expander->sas_address); |
| 7652 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7653 | kfree(sas_expander->phy); |
| 7654 | kfree(sas_expander); |
| 7655 | } |
| 7656 | |
| 7657 | /** |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7658 | * _scsih_ir_shutdown - IR shutdown notification |
| 7659 | * @ioc: per adapter object |
| 7660 | * |
| 7661 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that |
| 7662 | * the host system is shutting down. |
| 7663 | * |
| 7664 | * Return nothing. |
| 7665 | */ |
| 7666 | static void |
| 7667 | _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc) |
| 7668 | { |
| 7669 | Mpi2RaidActionRequest_t *mpi_request; |
| 7670 | Mpi2RaidActionReply_t *mpi_reply; |
| 7671 | u16 smid; |
| 7672 | |
| 7673 | /* is IR firmware build loaded ? */ |
| 7674 | if (!ioc->ir_firmware) |
| 7675 | return; |
| 7676 | |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7677 | mutex_lock(&ioc->scsih_cmds.mutex); |
| 7678 | |
| 7679 | if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) { |
| 7680 | printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n", |
| 7681 | ioc->name, __func__); |
| 7682 | goto out; |
| 7683 | } |
| 7684 | ioc->scsih_cmds.status = MPT2_CMD_PENDING; |
| 7685 | |
| 7686 | smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx); |
| 7687 | if (!smid) { |
| 7688 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 7689 | ioc->name, __func__); |
| 7690 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; |
| 7691 | goto out; |
| 7692 | } |
| 7693 | |
| 7694 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 7695 | ioc->scsih_cmds.smid = smid; |
| 7696 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); |
| 7697 | |
| 7698 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; |
| 7699 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; |
| 7700 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7701 | if (!ioc->hide_ir_msg) |
| 7702 | printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7703 | init_completion(&ioc->scsih_cmds.done); |
| 7704 | mpt2sas_base_put_smid_default(ioc, smid); |
| 7705 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
| 7706 | |
| 7707 | if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) { |
| 7708 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 7709 | ioc->name, __func__); |
| 7710 | goto out; |
| 7711 | } |
| 7712 | |
| 7713 | if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 7714 | mpi_reply = ioc->scsih_cmds.reply; |
| 7715 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7716 | if (!ioc->hide_ir_msg) |
| 7717 | printk(MPT2SAS_INFO_FMT "IR shutdown (complete): " |
| 7718 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7719 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 7720 | le32_to_cpu(mpi_reply->IOCLogInfo)); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7721 | } |
| 7722 | |
| 7723 | out: |
| 7724 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; |
| 7725 | mutex_unlock(&ioc->scsih_cmds.mutex); |
| 7726 | } |
| 7727 | |
| 7728 | /** |
| 7729 | * _scsih_shutdown - routine call during system shutdown |
| 7730 | * @pdev: PCI device struct |
| 7731 | * |
| 7732 | * Return nothing. |
| 7733 | */ |
| 7734 | static void |
| 7735 | _scsih_shutdown(struct pci_dev *pdev) |
| 7736 | { |
| 7737 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7738 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7739 | struct workqueue_struct *wq; |
| 7740 | unsigned long flags; |
| 7741 | |
| 7742 | ioc->remove_host = 1; |
| 7743 | _scsih_fw_event_cleanup_queue(ioc); |
| 7744 | |
| 7745 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7746 | wq = ioc->firmware_event_thread; |
| 7747 | ioc->firmware_event_thread = NULL; |
| 7748 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7749 | if (wq) |
| 7750 | destroy_workqueue(wq); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7751 | |
| 7752 | _scsih_ir_shutdown(ioc); |
| 7753 | mpt2sas_base_detach(ioc); |
| 7754 | } |
| 7755 | |
| 7756 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7757 | * _scsih_remove - detach and remove add host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7758 | * @pdev: PCI device struct |
| 7759 | * |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7760 | * Routine called when unloading the driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7761 | * Return nothing. |
| 7762 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7763 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7764 | _scsih_remove(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7765 | { |
| 7766 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7767 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7768 | struct _sas_port *mpt2sas_port, *next_port; |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7769 | struct _raid_device *raid_device, *next; |
| 7770 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7771 | struct workqueue_struct *wq; |
| 7772 | unsigned long flags; |
| 7773 | |
| 7774 | ioc->remove_host = 1; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7775 | _scsih_fw_event_cleanup_queue(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7776 | |
| 7777 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7778 | wq = ioc->firmware_event_thread; |
| 7779 | ioc->firmware_event_thread = NULL; |
| 7780 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7781 | if (wq) |
| 7782 | destroy_workqueue(wq); |
| 7783 | |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7784 | /* release all the volumes */ |
Kashyap, Desai | 3a9c913 | 2011-01-04 11:40:23 +0530 | [diff] [blame] | 7785 | _scsih_ir_shutdown(ioc); |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7786 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, |
| 7787 | list) { |
| 7788 | if (raid_device->starget) { |
| 7789 | sas_target_priv_data = |
| 7790 | raid_device->starget->hostdata; |
| 7791 | sas_target_priv_data->deleted = 1; |
| 7792 | scsi_remove_target(&raid_device->starget->dev); |
| 7793 | } |
| 7794 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" |
| 7795 | "(0x%016llx)\n", ioc->name, raid_device->handle, |
| 7796 | (unsigned long long) raid_device->wwid); |
| 7797 | _scsih_raid_device_remove(ioc, raid_device); |
| 7798 | } |
| 7799 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7800 | /* free ports attached to the sas_host */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7801 | list_for_each_entry_safe(mpt2sas_port, next_port, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7802 | &ioc->sas_hba.sas_port_list, port_list) { |
| 7803 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7804 | SAS_END_DEVICE) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7805 | mpt2sas_device_remove_by_sas_address(ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7806 | mpt2sas_port->remote_identify.sas_address); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7807 | else if (mpt2sas_port->remote_identify.device_type == |
| 7808 | SAS_EDGE_EXPANDER_DEVICE || |
| 7809 | mpt2sas_port->remote_identify.device_type == |
| 7810 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7811 | mpt2sas_expander_remove(ioc, |
| 7812 | mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7813 | } |
| 7814 | |
| 7815 | /* free phys attached to the sas_host */ |
| 7816 | if (ioc->sas_hba.num_phys) { |
| 7817 | kfree(ioc->sas_hba.phy); |
| 7818 | ioc->sas_hba.phy = NULL; |
| 7819 | ioc->sas_hba.num_phys = 0; |
| 7820 | } |
| 7821 | |
| 7822 | sas_remove_host(shost); |
Reddy, Sreekanth | 02b7708 | 2014-07-14 12:00:49 +0530 | [diff] [blame] | 7823 | scsi_remove_host(shost); |
kashyap.desai@lsi.com | 9ae89b0 | 2011-08-04 16:47:50 +0530 | [diff] [blame] | 7824 | mpt2sas_base_detach(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7825 | list_del(&ioc->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7826 | scsi_host_put(shost); |
| 7827 | } |
| 7828 | |
| 7829 | /** |
| 7830 | * _scsih_probe_boot_devices - reports 1st device |
| 7831 | * @ioc: per adapter object |
| 7832 | * |
| 7833 | * If specified in bios page 2, this routine reports the 1st |
| 7834 | * device scsi-ml or sas transport for persistent boot device |
| 7835 | * purposes. Please refer to function _scsih_determine_boot_device() |
| 7836 | */ |
| 7837 | static void |
| 7838 | _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc) |
| 7839 | { |
| 7840 | u8 is_raid; |
| 7841 | void *device; |
| 7842 | struct _sas_device *sas_device; |
| 7843 | struct _raid_device *raid_device; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7844 | u16 handle; |
| 7845 | u64 sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7846 | u64 sas_address; |
| 7847 | unsigned long flags; |
| 7848 | int rc; |
| 7849 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7850 | /* no Bios, return immediately */ |
| 7851 | if (!ioc->bios_pg3.BiosVersion) |
| 7852 | return; |
| 7853 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7854 | device = NULL; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7855 | is_raid = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7856 | if (ioc->req_boot_device.device) { |
| 7857 | device = ioc->req_boot_device.device; |
| 7858 | is_raid = ioc->req_boot_device.is_raid; |
| 7859 | } else if (ioc->req_alt_boot_device.device) { |
| 7860 | device = ioc->req_alt_boot_device.device; |
| 7861 | is_raid = ioc->req_alt_boot_device.is_raid; |
| 7862 | } else if (ioc->current_boot_device.device) { |
| 7863 | device = ioc->current_boot_device.device; |
| 7864 | is_raid = ioc->current_boot_device.is_raid; |
| 7865 | } |
| 7866 | |
| 7867 | if (!device) |
| 7868 | return; |
| 7869 | |
| 7870 | if (is_raid) { |
| 7871 | raid_device = device; |
| 7872 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7873 | raid_device->id, 0); |
| 7874 | if (rc) |
| 7875 | _scsih_raid_device_remove(ioc, raid_device); |
| 7876 | } else { |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7877 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7878 | sas_device = device; |
| 7879 | handle = sas_device->handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7880 | sas_address_parent = sas_device->sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7881 | sas_address = sas_device->sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7882 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 7883 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7884 | |
| 7885 | if (ioc->hide_drives) |
| 7886 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7887 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7888 | sas_device->sas_address_parent)) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7889 | _scsih_sas_device_remove(ioc, sas_device); |
| 7890 | } else if (!sas_device->starget) { |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 7891 | if (!ioc->is_driver_loading) { |
| 7892 | mpt2sas_transport_port_remove(ioc, |
| 7893 | sas_address, |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 7894 | sas_address_parent); |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 7895 | _scsih_sas_device_remove(ioc, sas_device); |
| 7896 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7897 | } |
| 7898 | } |
| 7899 | } |
| 7900 | |
| 7901 | /** |
| 7902 | * _scsih_probe_raid - reporting raid volumes to scsi-ml |
| 7903 | * @ioc: per adapter object |
| 7904 | * |
| 7905 | * Called during initial loading of the driver. |
| 7906 | */ |
| 7907 | static void |
| 7908 | _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc) |
| 7909 | { |
| 7910 | struct _raid_device *raid_device, *raid_next; |
| 7911 | int rc; |
| 7912 | |
| 7913 | list_for_each_entry_safe(raid_device, raid_next, |
| 7914 | &ioc->raid_device_list, list) { |
| 7915 | if (raid_device->starget) |
| 7916 | continue; |
| 7917 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7918 | raid_device->id, 0); |
| 7919 | if (rc) |
| 7920 | _scsih_raid_device_remove(ioc, raid_device); |
| 7921 | } |
| 7922 | } |
| 7923 | |
| 7924 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7925 | * _scsih_probe_sas - reporting sas devices to sas transport |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7926 | * @ioc: per adapter object |
| 7927 | * |
| 7928 | * Called during initial loading of the driver. |
| 7929 | */ |
| 7930 | static void |
| 7931 | _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc) |
| 7932 | { |
| 7933 | struct _sas_device *sas_device, *next; |
| 7934 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7935 | |
| 7936 | /* SAS Device List */ |
| 7937 | list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list, |
| 7938 | list) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7939 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7940 | if (ioc->hide_drives) |
| 7941 | continue; |
| 7942 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7943 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
| 7944 | sas_device->sas_address_parent)) { |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 7945 | list_del(&sas_device->list); |
| 7946 | kfree(sas_device); |
| 7947 | continue; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7948 | } else if (!sas_device->starget) { |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 7949 | if (!ioc->is_driver_loading) { |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 7950 | mpt2sas_transport_port_remove(ioc, |
| 7951 | sas_device->sas_address, |
| 7952 | sas_device->sas_address_parent); |
Sreekanth Reddy | bc6d4c3 | 2013-07-25 11:31:12 +0530 | [diff] [blame] | 7953 | list_del(&sas_device->list); |
| 7954 | kfree(sas_device); |
| 7955 | continue; |
| 7956 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7957 | } |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 7958 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 7959 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 7960 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7961 | } |
| 7962 | } |
| 7963 | |
| 7964 | /** |
| 7965 | * _scsih_probe_devices - probing for devices |
| 7966 | * @ioc: per adapter object |
| 7967 | * |
| 7968 | * Called during initial loading of the driver. |
| 7969 | */ |
| 7970 | static void |
| 7971 | _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc) |
| 7972 | { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7973 | u16 volume_mapping_flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7974 | |
| 7975 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) |
| 7976 | return; /* return when IOC doesn't support initiator mode */ |
| 7977 | |
| 7978 | _scsih_probe_boot_devices(ioc); |
| 7979 | |
| 7980 | if (ioc->ir_firmware) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7981 | volume_mapping_flags = |
| 7982 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & |
| 7983 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; |
| 7984 | if (volume_mapping_flags == |
| 7985 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7986 | _scsih_probe_raid(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7987 | _scsih_probe_sas(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7988 | } else { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7989 | _scsih_probe_sas(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7990 | _scsih_probe_raid(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7991 | } |
| 7992 | } else |
| 7993 | _scsih_probe_sas(ioc); |
| 7994 | } |
| 7995 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7996 | |
| 7997 | /** |
| 7998 | * _scsih_scan_start - scsi lld callback for .scan_start |
| 7999 | * @shost: SCSI host pointer |
| 8000 | * |
| 8001 | * The shost has the ability to discover targets on its own instead |
| 8002 | * of scanning the entire bus. In our implemention, we will kick off |
| 8003 | * firmware discovery. |
| 8004 | */ |
| 8005 | static void |
| 8006 | _scsih_scan_start(struct Scsi_Host *shost) |
| 8007 | { |
| 8008 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8009 | int rc; |
| 8010 | |
| 8011 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) |
| 8012 | mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable); |
| 8013 | |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 8014 | if (disable_discovery > 0) |
| 8015 | return; |
| 8016 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8017 | ioc->start_scan = 1; |
| 8018 | rc = mpt2sas_port_enable(ioc); |
| 8019 | |
| 8020 | if (rc != 0) |
| 8021 | printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name); |
| 8022 | } |
| 8023 | |
| 8024 | /** |
| 8025 | * _scsih_scan_finished - scsi lld callback for .scan_finished |
| 8026 | * @shost: SCSI host pointer |
| 8027 | * @time: elapsed time of the scan in jiffies |
| 8028 | * |
| 8029 | * This function will be called periodically until it returns 1 with the |
| 8030 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, |
| 8031 | * we wait for firmware discovery to complete, then return 1. |
| 8032 | */ |
| 8033 | static int |
| 8034 | _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 8035 | { |
| 8036 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8037 | |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 8038 | if (disable_discovery > 0) { |
| 8039 | ioc->is_driver_loading = 0; |
| 8040 | ioc->wait_for_discovery_to_complete = 0; |
| 8041 | return 1; |
| 8042 | } |
| 8043 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8044 | if (time >= (300 * HZ)) { |
| 8045 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 8046 | printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout " |
| 8047 | "(timeout=300s)\n", ioc->name); |
| 8048 | ioc->is_driver_loading = 0; |
| 8049 | return 1; |
| 8050 | } |
| 8051 | |
| 8052 | if (ioc->start_scan) |
| 8053 | return 0; |
| 8054 | |
| 8055 | if (ioc->start_scan_failed) { |
| 8056 | printk(MPT2SAS_INFO_FMT "port enable: FAILED with " |
| 8057 | "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed); |
| 8058 | ioc->is_driver_loading = 0; |
| 8059 | ioc->wait_for_discovery_to_complete = 0; |
| 8060 | ioc->remove_host = 1; |
| 8061 | return 1; |
| 8062 | } |
| 8063 | |
| 8064 | printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name); |
| 8065 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 8066 | |
| 8067 | if (ioc->wait_for_discovery_to_complete) { |
| 8068 | ioc->wait_for_discovery_to_complete = 0; |
| 8069 | _scsih_probe_devices(ioc); |
| 8070 | } |
| 8071 | mpt2sas_base_start_watchdog(ioc); |
| 8072 | ioc->is_driver_loading = 0; |
| 8073 | return 1; |
| 8074 | } |
| 8075 | |
| 8076 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8077 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8078 | * _scsih_probe - attach and add scsi host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8079 | * @pdev: PCI device struct |
| 8080 | * @id: pci device id |
| 8081 | * |
| 8082 | * Returns 0 success, anything else error. |
| 8083 | */ |
| 8084 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8085 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8086 | { |
| 8087 | struct MPT2SAS_ADAPTER *ioc; |
| 8088 | struct Scsi_Host *shost; |
Sreekanth Reddy | b65f1d4 | 2014-09-12 15:35:33 +0530 | [diff] [blame] | 8089 | int rv; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8090 | |
| 8091 | shost = scsi_host_alloc(&scsih_driver_template, |
| 8092 | sizeof(struct MPT2SAS_ADAPTER)); |
| 8093 | if (!shost) |
| 8094 | return -ENODEV; |
| 8095 | |
| 8096 | /* init local params */ |
| 8097 | ioc = shost_priv(shost); |
| 8098 | memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER)); |
| 8099 | INIT_LIST_HEAD(&ioc->list); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 8100 | list_add_tail(&ioc->list, &mpt2sas_ioc_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8101 | ioc->shost = shost; |
| 8102 | ioc->id = mpt_ids++; |
| 8103 | sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id); |
| 8104 | ioc->pdev = pdev; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8105 | if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) { |
| 8106 | ioc->is_warpdrive = 1; |
| 8107 | ioc->hide_ir_msg = 1; |
| 8108 | } else |
| 8109 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8110 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; |
| 8111 | ioc->tm_cb_idx = tm_cb_idx; |
| 8112 | ioc->ctl_cb_idx = ctl_cb_idx; |
| 8113 | ioc->base_cb_idx = base_cb_idx; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8114 | ioc->port_enable_cb_idx = port_enable_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8115 | ioc->transport_cb_idx = transport_cb_idx; |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8116 | ioc->scsih_cb_idx = scsih_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8117 | ioc->config_cb_idx = config_cb_idx; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8118 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8119 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8120 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8121 | ioc->logging_level = logging_level; |
nagalakshmi.nandigama@lsi.com | 845a0e4 | 2011-12-01 07:42:04 +0530 | [diff] [blame] | 8122 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8123 | /* misc semaphores and spin locks */ |
Kashyap, Desai | d274213 | 2010-06-17 13:28:55 +0530 | [diff] [blame] | 8124 | mutex_init(&ioc->reset_in_progress_mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8125 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
| 8126 | spin_lock_init(&ioc->scsi_lookup_lock); |
| 8127 | spin_lock_init(&ioc->sas_device_lock); |
| 8128 | spin_lock_init(&ioc->sas_node_lock); |
| 8129 | spin_lock_init(&ioc->fw_event_lock); |
| 8130 | spin_lock_init(&ioc->raid_device_lock); |
| 8131 | |
| 8132 | INIT_LIST_HEAD(&ioc->sas_device_list); |
| 8133 | INIT_LIST_HEAD(&ioc->sas_device_init_list); |
| 8134 | INIT_LIST_HEAD(&ioc->sas_expander_list); |
| 8135 | INIT_LIST_HEAD(&ioc->fw_event_list); |
| 8136 | INIT_LIST_HEAD(&ioc->raid_device_list); |
| 8137 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8138 | INIT_LIST_HEAD(&ioc->delayed_tr_list); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8139 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
Joe Lawrence | 3b3e6f8 | 2013-08-08 16:45:38 -0400 | [diff] [blame] | 8140 | INIT_LIST_HEAD(&ioc->reply_queue_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8141 | |
| 8142 | /* init shost parameters */ |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 8143 | shost->max_cmd_len = 32; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8144 | shost->max_lun = max_lun; |
| 8145 | shost->transportt = mpt2sas_transport_template; |
| 8146 | shost->unique_id = ioc->id; |
| 8147 | |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8148 | if (max_sectors != 0xFFFF) { |
| 8149 | if (max_sectors < 64) { |
| 8150 | shost->max_sectors = 64; |
Sreekanth Reddy | 6241f22 | 2013-02-02 00:56:18 +0530 | [diff] [blame] | 8151 | printk(MPT2SAS_WARN_FMT "Invalid value %d passed " |
| 8152 | "for max_sectors, range is 64 to 32767. Assigning " |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8153 | "value of 64.\n", ioc->name, max_sectors); |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 8154 | } else if (max_sectors > 32767) { |
| 8155 | shost->max_sectors = 32767; |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8156 | printk(MPT2SAS_WARN_FMT "Invalid value %d passed " |
| 8157 | "for max_sectors, range is 64 to 8192. Assigning " |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 8158 | "default value of 32767.\n", ioc->name, |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8159 | max_sectors); |
| 8160 | } else { |
| 8161 | shost->max_sectors = max_sectors & 0xFFFE; |
| 8162 | printk(MPT2SAS_INFO_FMT "The max_sectors value is " |
| 8163 | "set to %d\n", ioc->name, shost->max_sectors); |
| 8164 | } |
| 8165 | } |
| 8166 | |
Martin K. Petersen | 5e95e73 | 2012-08-28 14:29:37 -0400 | [diff] [blame] | 8167 | /* register EEDP capabilities with SCSI layer */ |
| 8168 | if (prot_mask) |
| 8169 | scsi_host_set_prot(shost, prot_mask); |
| 8170 | else |
| 8171 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION |
| 8172 | | SHOST_DIF_TYPE2_PROTECTION |
| 8173 | | SHOST_DIF_TYPE3_PROTECTION); |
| 8174 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8175 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 8176 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8177 | /* event thread */ |
| 8178 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), |
| 8179 | "fw_event%d", ioc->id); |
| 8180 | ioc->firmware_event_thread = create_singlethread_workqueue( |
| 8181 | ioc->firmware_event_name); |
| 8182 | if (!ioc->firmware_event_thread) { |
| 8183 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8184 | ioc->name, __FILE__, __LINE__, __func__); |
Sreekanth Reddy | b65f1d4 | 2014-09-12 15:35:33 +0530 | [diff] [blame] | 8185 | rv = -ENODEV; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8186 | goto out_thread_fail; |
| 8187 | } |
| 8188 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8189 | ioc->is_driver_loading = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8190 | if ((mpt2sas_base_attach(ioc))) { |
| 8191 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8192 | ioc->name, __FILE__, __LINE__, __func__); |
Sreekanth Reddy | b65f1d4 | 2014-09-12 15:35:33 +0530 | [diff] [blame] | 8193 | rv = -ENODEV; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8194 | goto out_attach_fail; |
| 8195 | } |
| 8196 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8197 | if (ioc->is_warpdrive) { |
| 8198 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) |
| 8199 | ioc->hide_drives = 0; |
| 8200 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) |
| 8201 | ioc->hide_drives = 1; |
| 8202 | else { |
| 8203 | if (_scsih_get_num_volumes(ioc)) |
| 8204 | ioc->hide_drives = 1; |
| 8205 | else |
| 8206 | ioc->hide_drives = 0; |
| 8207 | } |
| 8208 | } else |
| 8209 | ioc->hide_drives = 0; |
Reddy, Sreekanth | 02b7708 | 2014-07-14 12:00:49 +0530 | [diff] [blame] | 8210 | |
Sreekanth Reddy | b65f1d4 | 2014-09-12 15:35:33 +0530 | [diff] [blame] | 8211 | rv = scsi_add_host(shost, &pdev->dev); |
| 8212 | if (rv) { |
Reddy, Sreekanth | 02b7708 | 2014-07-14 12:00:49 +0530 | [diff] [blame] | 8213 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8214 | ioc->name, __FILE__, __LINE__, __func__); |
| 8215 | goto out_add_shost_fail; |
| 8216 | } |
| 8217 | |
nagalakshmi.nandigama@lsi.com | 2cb6fc8 | 2011-12-13 09:29:15 +0530 | [diff] [blame] | 8218 | scsi_scan_host(shost); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8219 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8220 | return 0; |
| 8221 | |
Reddy, Sreekanth | 02b7708 | 2014-07-14 12:00:49 +0530 | [diff] [blame] | 8222 | out_add_shost_fail: |
| 8223 | mpt2sas_base_detach(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8224 | out_attach_fail: |
| 8225 | destroy_workqueue(ioc->firmware_event_thread); |
| 8226 | out_thread_fail: |
| 8227 | list_del(&ioc->list); |
Tomas Henzl | f555e05 | 2012-04-17 15:24:48 +0200 | [diff] [blame] | 8228 | scsi_host_put(shost); |
Sreekanth Reddy | b65f1d4 | 2014-09-12 15:35:33 +0530 | [diff] [blame] | 8229 | return rv; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8230 | } |
| 8231 | |
| 8232 | #ifdef CONFIG_PM |
| 8233 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8234 | * _scsih_suspend - power management suspend main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8235 | * @pdev: PCI device struct |
| 8236 | * @state: PM state change to (usually PCI_D3) |
| 8237 | * |
| 8238 | * Returns 0 success, anything else error. |
| 8239 | */ |
| 8240 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8241 | _scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8242 | { |
| 8243 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8244 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 8245 | pci_power_t device_state; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8246 | |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 8247 | mpt2sas_base_stop_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8248 | scsi_block_requests(shost); |
Sreekanth Reddy | 3627dba | 2013-07-25 11:25:57 +0530 | [diff] [blame] | 8249 | _scsih_ir_shutdown(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8250 | device_state = pci_choose_state(pdev, state); |
| 8251 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering " |
| 8252 | "operating state [D%d]\n", ioc->name, pdev, |
| 8253 | pci_name(pdev), device_state); |
| 8254 | |
| 8255 | mpt2sas_base_free_resources(ioc); |
| 8256 | pci_save_state(pdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8257 | pci_set_power_state(pdev, device_state); |
| 8258 | return 0; |
| 8259 | } |
| 8260 | |
| 8261 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8262 | * _scsih_resume - power management resume main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8263 | * @pdev: PCI device struct |
| 8264 | * |
| 8265 | * Returns 0 success, anything else error. |
| 8266 | */ |
| 8267 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8268 | _scsih_resume(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8269 | { |
| 8270 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8271 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 8272 | pci_power_t device_state = pdev->current_state; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8273 | int r; |
| 8274 | |
| 8275 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous " |
| 8276 | "operating state [D%d]\n", ioc->name, pdev, |
| 8277 | pci_name(pdev), device_state); |
| 8278 | |
| 8279 | pci_set_power_state(pdev, PCI_D0); |
| 8280 | pci_enable_wake(pdev, PCI_D0, 0); |
| 8281 | pci_restore_state(pdev); |
| 8282 | ioc->pdev = pdev; |
| 8283 | r = mpt2sas_base_map_resources(ioc); |
| 8284 | if (r) |
| 8285 | return r; |
| 8286 | |
| 8287 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET); |
| 8288 | scsi_unblock_requests(shost); |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 8289 | mpt2sas_base_start_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8290 | return 0; |
| 8291 | } |
| 8292 | #endif /* CONFIG_PM */ |
| 8293 | |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8294 | /** |
| 8295 | * _scsih_pci_error_detected - Called when a PCI error is detected. |
| 8296 | * @pdev: PCI device struct |
| 8297 | * @state: PCI channel state |
| 8298 | * |
| 8299 | * Description: Called when a PCI error is detected. |
| 8300 | * |
| 8301 | * Return value: |
| 8302 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT |
| 8303 | */ |
| 8304 | static pci_ers_result_t |
| 8305 | _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 8306 | { |
| 8307 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8308 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8309 | |
| 8310 | printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n", |
| 8311 | ioc->name, state); |
| 8312 | |
| 8313 | switch (state) { |
| 8314 | case pci_channel_io_normal: |
| 8315 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 8316 | case pci_channel_io_frozen: |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8317 | /* Fatal error, prepare for slot reset */ |
| 8318 | ioc->pci_error_recovery = 1; |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8319 | scsi_block_requests(ioc->shost); |
| 8320 | mpt2sas_base_stop_watchdog(ioc); |
| 8321 | mpt2sas_base_free_resources(ioc); |
| 8322 | return PCI_ERS_RESULT_NEED_RESET; |
| 8323 | case pci_channel_io_perm_failure: |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8324 | /* Permanent error, prepare for device removal */ |
| 8325 | ioc->pci_error_recovery = 1; |
| 8326 | mpt2sas_base_stop_watchdog(ioc); |
| 8327 | _scsih_flush_running_cmds(ioc); |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8328 | return PCI_ERS_RESULT_DISCONNECT; |
| 8329 | } |
| 8330 | return PCI_ERS_RESULT_NEED_RESET; |
| 8331 | } |
| 8332 | |
| 8333 | /** |
| 8334 | * _scsih_pci_slot_reset - Called when PCI slot has been reset. |
| 8335 | * @pdev: PCI device struct |
| 8336 | * |
| 8337 | * Description: This routine is called by the pci error recovery |
| 8338 | * code after the PCI slot has been reset, just before we |
| 8339 | * should resume normal operations. |
| 8340 | */ |
| 8341 | static pci_ers_result_t |
| 8342 | _scsih_pci_slot_reset(struct pci_dev *pdev) |
| 8343 | { |
| 8344 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8345 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8346 | int rc; |
| 8347 | |
| 8348 | printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n", |
| 8349 | ioc->name); |
| 8350 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8351 | ioc->pci_error_recovery = 0; |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8352 | ioc->pdev = pdev; |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8353 | pci_restore_state(pdev); |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8354 | rc = mpt2sas_base_map_resources(ioc); |
| 8355 | if (rc) |
| 8356 | return PCI_ERS_RESULT_DISCONNECT; |
| 8357 | |
| 8358 | |
| 8359 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 8360 | FORCE_BIG_HAMMER); |
| 8361 | |
| 8362 | printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name, |
| 8363 | (rc == 0) ? "success" : "failed"); |
| 8364 | |
| 8365 | if (!rc) |
| 8366 | return PCI_ERS_RESULT_RECOVERED; |
| 8367 | else |
| 8368 | return PCI_ERS_RESULT_DISCONNECT; |
| 8369 | } |
| 8370 | |
| 8371 | /** |
| 8372 | * _scsih_pci_resume() - resume normal ops after PCI reset |
| 8373 | * @pdev: pointer to PCI device |
| 8374 | * |
| 8375 | * Called when the error recovery driver tells us that its |
| 8376 | * OK to resume normal operation. Use completion to allow |
| 8377 | * halted scsi ops to resume. |
| 8378 | */ |
| 8379 | static void |
| 8380 | _scsih_pci_resume(struct pci_dev *pdev) |
| 8381 | { |
| 8382 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8383 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8384 | |
| 8385 | printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name); |
| 8386 | |
| 8387 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8388 | mpt2sas_base_start_watchdog(ioc); |
| 8389 | scsi_unblock_requests(ioc->shost); |
| 8390 | } |
| 8391 | |
| 8392 | /** |
| 8393 | * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
| 8394 | * @pdev: pointer to PCI device |
| 8395 | */ |
| 8396 | static pci_ers_result_t |
| 8397 | _scsih_pci_mmio_enabled(struct pci_dev *pdev) |
| 8398 | { |
| 8399 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8400 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8401 | |
| 8402 | printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n", |
| 8403 | ioc->name); |
| 8404 | |
| 8405 | /* TODO - dump whatever for debugging purposes */ |
| 8406 | |
| 8407 | /* Request a slot reset. */ |
| 8408 | return PCI_ERS_RESULT_NEED_RESET; |
| 8409 | } |
| 8410 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 8411 | static const struct pci_error_handlers _scsih_err_handler = { |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8412 | .error_detected = _scsih_pci_error_detected, |
| 8413 | .mmio_enabled = _scsih_pci_mmio_enabled, |
| 8414 | .slot_reset = _scsih_pci_slot_reset, |
| 8415 | .resume = _scsih_pci_resume, |
| 8416 | }; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8417 | |
| 8418 | static struct pci_driver scsih_driver = { |
| 8419 | .name = MPT2SAS_DRIVER_NAME, |
| 8420 | .id_table = scsih_pci_table, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8421 | .probe = _scsih_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8422 | .remove = _scsih_remove, |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8423 | .shutdown = _scsih_shutdown, |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8424 | .err_handler = &_scsih_err_handler, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8425 | #ifdef CONFIG_PM |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8426 | .suspend = _scsih_suspend, |
| 8427 | .resume = _scsih_resume, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8428 | #endif |
| 8429 | }; |
| 8430 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8431 | /* raid transport support */ |
| 8432 | static struct raid_function_template mpt2sas_raid_functions = { |
| 8433 | .cookie = &scsih_driver_template, |
| 8434 | .is_raid = _scsih_is_raid, |
| 8435 | .get_resync = _scsih_get_resync, |
| 8436 | .get_state = _scsih_get_state, |
| 8437 | }; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8438 | |
| 8439 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8440 | * _scsih_init - main entry point for this driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8441 | * |
| 8442 | * Returns 0 success, anything else error. |
| 8443 | */ |
| 8444 | static int __init |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8445 | _scsih_init(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8446 | { |
| 8447 | int error; |
| 8448 | |
| 8449 | mpt_ids = 0; |
| 8450 | printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME, |
| 8451 | MPT2SAS_DRIVER_VERSION); |
| 8452 | |
| 8453 | mpt2sas_transport_template = |
| 8454 | sas_attach_transport(&mpt2sas_transport_functions); |
| 8455 | if (!mpt2sas_transport_template) |
| 8456 | return -ENODEV; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8457 | /* raid transport support */ |
| 8458 | mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions); |
| 8459 | if (!mpt2sas_raid_template) { |
| 8460 | sas_release_transport(mpt2sas_transport_template); |
| 8461 | return -ENODEV; |
| 8462 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8463 | |
| 8464 | mpt2sas_base_initialize_callback_handler(); |
| 8465 | |
| 8466 | /* queuecommand callback hander */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8467 | scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8468 | |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 8469 | /* task management callback handler */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8470 | tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8471 | |
| 8472 | /* base internal commands callback handler */ |
| 8473 | 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] | 8474 | port_enable_cb_idx = mpt2sas_base_register_callback_handler( |
| 8475 | mpt2sas_port_enable_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8476 | |
| 8477 | /* transport internal commands callback handler */ |
| 8478 | transport_cb_idx = mpt2sas_base_register_callback_handler( |
| 8479 | mpt2sas_transport_done); |
| 8480 | |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8481 | /* scsih internal commands callback handler */ |
| 8482 | scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done); |
| 8483 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8484 | /* configuration page API internal commands callback handler */ |
| 8485 | config_cb_idx = mpt2sas_base_register_callback_handler( |
| 8486 | mpt2sas_config_done); |
| 8487 | |
| 8488 | /* ctl module callback handler */ |
| 8489 | ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done); |
| 8490 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8491 | tm_tr_cb_idx = mpt2sas_base_register_callback_handler( |
| 8492 | _scsih_tm_tr_complete); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8493 | |
| 8494 | tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler( |
| 8495 | _scsih_tm_volume_tr_complete); |
| 8496 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8497 | tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler( |
| 8498 | _scsih_sas_control_complete); |
| 8499 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8500 | mpt2sas_ctl_init(); |
| 8501 | |
| 8502 | error = pci_register_driver(&scsih_driver); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8503 | if (error) { |
| 8504 | /* raid transport support */ |
| 8505 | raid_class_release(mpt2sas_raid_template); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8506 | sas_release_transport(mpt2sas_transport_template); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8507 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8508 | |
| 8509 | return error; |
| 8510 | } |
| 8511 | |
| 8512 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8513 | * _scsih_exit - exit point for this driver (when it is a module). |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8514 | * |
| 8515 | * Returns 0 success, anything else error. |
| 8516 | */ |
| 8517 | static void __exit |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8518 | _scsih_exit(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8519 | { |
| 8520 | printk(KERN_INFO "mpt2sas version %s unloading\n", |
| 8521 | MPT2SAS_DRIVER_VERSION); |
| 8522 | |
| 8523 | pci_unregister_driver(&scsih_driver); |
| 8524 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8525 | mpt2sas_ctl_exit(); |
| 8526 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8527 | mpt2sas_base_release_callback_handler(scsi_io_cb_idx); |
| 8528 | mpt2sas_base_release_callback_handler(tm_cb_idx); |
| 8529 | mpt2sas_base_release_callback_handler(base_cb_idx); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8530 | mpt2sas_base_release_callback_handler(port_enable_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8531 | mpt2sas_base_release_callback_handler(transport_cb_idx); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8532 | mpt2sas_base_release_callback_handler(scsih_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8533 | mpt2sas_base_release_callback_handler(config_cb_idx); |
| 8534 | mpt2sas_base_release_callback_handler(ctl_cb_idx); |
| 8535 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8536 | mpt2sas_base_release_callback_handler(tm_tr_cb_idx); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8537 | mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8538 | mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx); |
| 8539 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8540 | /* raid transport support */ |
| 8541 | raid_class_release(mpt2sas_raid_template); |
| 8542 | sas_release_transport(mpt2sas_transport_template); |
| 8543 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8544 | } |
| 8545 | |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8546 | module_init(_scsih_init); |
| 8547 | module_exit(_scsih_exit); |