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@lsi.com | 433d717 | 2012-07-17 15:56:03 +0530 | [diff] [blame] | 5 | * Copyright (C) 2007-2012 LSI Corporation |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6 | * (mailto:DL-MPTFusionLinux@lsi.com) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * as published by the Free Software Foundation; either version 2 |
| 11 | * of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * NO WARRANTY |
| 19 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 20 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT |
| 21 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, |
| 22 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is |
| 23 | * solely responsible for determining the appropriateness of using and |
| 24 | * distributing the Program and assumes all risks associated with its |
| 25 | * exercise of rights under this Agreement, including but not limited to |
| 26 | * the risks and costs of program errors, damage to or loss of data, |
| 27 | * programs or equipment, and unavailability or interruption of operations. |
| 28 | |
| 29 | * DISCLAIMER OF LIABILITY |
| 30 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY |
| 31 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 32 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND |
| 33 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 34 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 35 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED |
| 36 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES |
| 37 | |
| 38 | * You should have received a copy of the GNU General Public License |
| 39 | * along with this program; if not, write to the Free Software |
| 40 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 41 | * USA. |
| 42 | */ |
| 43 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 44 | #include <linux/module.h> |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/init.h> |
| 47 | #include <linux/errno.h> |
| 48 | #include <linux/blkdev.h> |
| 49 | #include <linux/sched.h> |
| 50 | #include <linux/workqueue.h> |
| 51 | #include <linux/delay.h> |
| 52 | #include <linux/pci.h> |
| 53 | #include <linux/interrupt.h> |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 54 | #include <linux/aer.h> |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 55 | #include <linux/raid_class.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 56 | #include <linux/slab.h> |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 57 | |
| 58 | #include "mpt2sas_base.h" |
| 59 | |
| 60 | MODULE_AUTHOR(MPT2SAS_AUTHOR); |
| 61 | MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION); |
| 62 | MODULE_LICENSE("GPL"); |
| 63 | MODULE_VERSION(MPT2SAS_DRIVER_VERSION); |
| 64 | |
| 65 | #define RAID_CHANNEL 1 |
| 66 | |
| 67 | /* forward proto's */ |
| 68 | static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc, |
| 69 | struct _sas_node *sas_expander); |
| 70 | static void _firmware_event_work(struct work_struct *work); |
| 71 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 72 | static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid); |
| 73 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 74 | static void _scsih_scan_start(struct Scsi_Host *shost); |
| 75 | static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time); |
| 76 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 77 | /* global parameters */ |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 78 | LIST_HEAD(mpt2sas_ioc_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 79 | |
| 80 | /* local parameters */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 81 | static u8 scsi_io_cb_idx = -1; |
| 82 | static u8 tm_cb_idx = -1; |
| 83 | static u8 ctl_cb_idx = -1; |
| 84 | static u8 base_cb_idx = -1; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 85 | static u8 port_enable_cb_idx = -1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 86 | static u8 transport_cb_idx = -1; |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 87 | static u8 scsih_cb_idx = -1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 88 | static u8 config_cb_idx = -1; |
| 89 | static int mpt_ids; |
| 90 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 91 | static u8 tm_tr_cb_idx = -1 ; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 92 | static u8 tm_tr_volume_cb_idx = -1 ; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 93 | static u8 tm_sas_control_cb_idx = -1; |
| 94 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 95 | /* command line options */ |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 96 | static u32 logging_level; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 97 | MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info " |
| 98 | "(default=0)"); |
| 99 | |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 100 | static ushort max_sectors = 0xFFFF; |
| 101 | module_param(max_sectors, ushort, 0); |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 102 | MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767"); |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 103 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 104 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ |
| 105 | #define MPT2SAS_MAX_LUN (16895) |
| 106 | static int max_lun = MPT2SAS_MAX_LUN; |
| 107 | module_param(max_lun, int, 0); |
| 108 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); |
| 109 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 110 | /* diag_buffer_enable is bitwise |
| 111 | * bit 0 set = TRACE |
| 112 | * bit 1 set = SNAPSHOT |
| 113 | * bit 2 set = EXTENDED |
| 114 | * |
| 115 | * Either bit can be set, or both |
| 116 | */ |
| 117 | static int diag_buffer_enable = -1; |
| 118 | module_param(diag_buffer_enable, int, 0); |
| 119 | MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers " |
| 120 | "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); |
| 121 | |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 122 | static int disable_discovery = -1; |
| 123 | module_param(disable_discovery, int, 0); |
| 124 | MODULE_PARM_DESC(disable_discovery, " disable discovery "); |
| 125 | |
Martin K. Petersen | 5e95e73 | 2012-08-28 14:29:37 -0400 | [diff] [blame] | 126 | /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */ |
| 127 | static int prot_mask = 0; |
| 128 | module_param(prot_mask, int, 0); |
| 129 | MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 "); |
| 130 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 131 | /** |
| 132 | * struct sense_info - common structure for obtaining sense keys |
| 133 | * @skey: sense key |
| 134 | * @asc: additional sense code |
| 135 | * @ascq: additional sense code qualifier |
| 136 | */ |
| 137 | struct sense_info { |
| 138 | u8 skey; |
| 139 | u8 asc; |
| 140 | u8 ascq; |
| 141 | }; |
| 142 | |
| 143 | |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 144 | #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 145 | #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD) |
| 146 | #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 147 | /** |
| 148 | * struct fw_event_work - firmware event struct |
| 149 | * @list: link list framework |
| 150 | * @work: work object (ioc->fault_reset_work_q) |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 151 | * @cancel_pending_work: flag set during reset handling |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 152 | * @ioc: per adapter object |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 153 | * @device_handle: device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 154 | * @VF_ID: virtual function id |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 155 | * @VP_ID: virtual port id |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 156 | * @ignore: flag meaning this event has been marked to ignore |
| 157 | * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h |
| 158 | * @event_data: reply event data payload follows |
| 159 | * |
| 160 | * This object stored on ioc->fw_event_list. |
| 161 | */ |
| 162 | struct fw_event_work { |
| 163 | struct list_head list; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 164 | u8 cancel_pending_work; |
| 165 | struct delayed_work delayed_work; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 166 | struct MPT2SAS_ADAPTER *ioc; |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 167 | u16 device_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 168 | u8 VF_ID; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 169 | u8 VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 170 | u8 ignore; |
| 171 | u16 event; |
| 172 | void *event_data; |
| 173 | }; |
| 174 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 175 | /* raid transport support */ |
| 176 | static struct raid_template *mpt2sas_raid_template; |
| 177 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 178 | /** |
| 179 | * struct _scsi_io_transfer - scsi io transfer |
| 180 | * @handle: sas device handle (assigned by firmware) |
| 181 | * @is_raid: flag set for hidden raid components |
| 182 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, |
| 183 | * @data_length: data transfer length |
| 184 | * @data_dma: dma pointer to data |
| 185 | * @sense: sense data |
| 186 | * @lun: lun number |
| 187 | * @cdb_length: cdb length |
| 188 | * @cdb: cdb contents |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 189 | * @timeout: timeout for this command |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 190 | * @VF_ID: virtual function id |
| 191 | * @VP_ID: virtual port id |
| 192 | * @valid_reply: flag set for reply message |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 193 | * @sense_length: sense length |
| 194 | * @ioc_status: ioc status |
| 195 | * @scsi_state: scsi state |
| 196 | * @scsi_status: scsi staus |
| 197 | * @log_info: log information |
| 198 | * @transfer_length: data length transfer when there is a reply message |
| 199 | * |
| 200 | * Used for sending internal scsi commands to devices within this module. |
| 201 | * Refer to _scsi_send_scsi_io(). |
| 202 | */ |
| 203 | struct _scsi_io_transfer { |
| 204 | u16 handle; |
| 205 | u8 is_raid; |
| 206 | enum dma_data_direction dir; |
| 207 | u32 data_length; |
| 208 | dma_addr_t data_dma; |
| 209 | u8 sense[SCSI_SENSE_BUFFERSIZE]; |
| 210 | u32 lun; |
| 211 | u8 cdb_length; |
| 212 | u8 cdb[32]; |
| 213 | u8 timeout; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 214 | u8 VF_ID; |
| 215 | u8 VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 216 | u8 valid_reply; |
| 217 | /* the following bits are only valid when 'valid_reply = 1' */ |
| 218 | u32 sense_length; |
| 219 | u16 ioc_status; |
| 220 | u8 scsi_state; |
| 221 | u8 scsi_status; |
| 222 | u32 log_info; |
| 223 | u32 transfer_length; |
| 224 | }; |
| 225 | |
| 226 | /* |
| 227 | * The pci device ids are defined in mpi/mpi2_cnfg.h. |
| 228 | */ |
| 229 | static struct pci_device_id scsih_pci_table[] = { |
| 230 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, |
| 231 | PCI_ANY_ID, PCI_ANY_ID }, |
| 232 | /* Falcon ~ 2008*/ |
| 233 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, |
| 234 | PCI_ANY_ID, PCI_ANY_ID }, |
| 235 | /* Liberator ~ 2108 */ |
| 236 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, |
| 237 | PCI_ANY_ID, PCI_ANY_ID }, |
| 238 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, |
| 239 | PCI_ANY_ID, PCI_ANY_ID }, |
| 240 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, |
| 241 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 242 | /* Meteor ~ 2116 */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 243 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, |
| 244 | PCI_ANY_ID, PCI_ANY_ID }, |
| 245 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, |
| 246 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 247 | /* Thunderbolt ~ 2208 */ |
| 248 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, |
| 249 | PCI_ANY_ID, PCI_ANY_ID }, |
| 250 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, |
| 251 | PCI_ANY_ID, PCI_ANY_ID }, |
| 252 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, |
| 253 | PCI_ANY_ID, PCI_ANY_ID }, |
| 254 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, |
| 255 | PCI_ANY_ID, PCI_ANY_ID }, |
| 256 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, |
| 257 | PCI_ANY_ID, PCI_ANY_ID }, |
| 258 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, |
| 259 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 203d65b | 2010-06-17 13:37:59 +0530 | [diff] [blame] | 260 | /* Mustang ~ 2308 */ |
| 261 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 262 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 203d65b | 2010-06-17 13:37:59 +0530 | [diff] [blame] | 263 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, |
| 264 | PCI_ANY_ID, PCI_ANY_ID }, |
| 265 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 266 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 267 | /* SSS6200 */ |
| 268 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, |
| 269 | PCI_ANY_ID, PCI_ANY_ID }, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 270 | {0} /* Terminating entry */ |
| 271 | }; |
| 272 | MODULE_DEVICE_TABLE(pci, scsih_pci_table); |
| 273 | |
| 274 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 275 | * _scsih_set_debug_level - global setting of ioc->logging_level. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 276 | * |
| 277 | * Note: The logging levels are defined in mpt2sas_debug.h. |
| 278 | */ |
| 279 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 280 | _scsih_set_debug_level(const char *val, struct kernel_param *kp) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 281 | { |
| 282 | int ret = param_set_int(val, kp); |
| 283 | struct MPT2SAS_ADAPTER *ioc; |
| 284 | |
| 285 | if (ret) |
| 286 | return ret; |
| 287 | |
| 288 | printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 289 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 290 | ioc->logging_level = logging_level; |
| 291 | return 0; |
| 292 | } |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 293 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 294 | &logging_level, 0644); |
| 295 | |
| 296 | /** |
| 297 | * _scsih_srch_boot_sas_address - search based on sas_address |
| 298 | * @sas_address: sas address |
| 299 | * @boot_device: boot device object from bios page 2 |
| 300 | * |
| 301 | * Returns 1 when there's a match, 0 means no match. |
| 302 | */ |
| 303 | static inline int |
| 304 | _scsih_srch_boot_sas_address(u64 sas_address, |
| 305 | Mpi2BootDeviceSasWwid_t *boot_device) |
| 306 | { |
| 307 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * _scsih_srch_boot_device_name - search based on device name |
| 312 | * @device_name: device name specified in INDENTIFY fram |
| 313 | * @boot_device: boot device object from bios page 2 |
| 314 | * |
| 315 | * Returns 1 when there's a match, 0 means no match. |
| 316 | */ |
| 317 | static inline int |
| 318 | _scsih_srch_boot_device_name(u64 device_name, |
| 319 | Mpi2BootDeviceDeviceName_t *boot_device) |
| 320 | { |
| 321 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot |
| 326 | * @enclosure_logical_id: enclosure logical id |
| 327 | * @slot_number: slot number |
| 328 | * @boot_device: boot device object from bios page 2 |
| 329 | * |
| 330 | * Returns 1 when there's a match, 0 means no match. |
| 331 | */ |
| 332 | static inline int |
| 333 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, |
| 334 | Mpi2BootDeviceEnclosureSlot_t *boot_device) |
| 335 | { |
| 336 | return (enclosure_logical_id == le64_to_cpu(boot_device-> |
| 337 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> |
| 338 | SlotNumber)) ? 1 : 0; |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * _scsih_is_boot_device - search for matching boot device. |
| 343 | * @sas_address: sas address |
| 344 | * @device_name: device name specified in INDENTIFY fram |
| 345 | * @enclosure_logical_id: enclosure logical id |
| 346 | * @slot_number: slot number |
| 347 | * @form: specifies boot device form |
| 348 | * @boot_device: boot device object from bios page 2 |
| 349 | * |
| 350 | * Returns 1 when there's a match, 0 means no match. |
| 351 | */ |
| 352 | static int |
| 353 | _scsih_is_boot_device(u64 sas_address, u64 device_name, |
| 354 | u64 enclosure_logical_id, u16 slot, u8 form, |
| 355 | Mpi2BiosPage2BootDevice_t *boot_device) |
| 356 | { |
| 357 | int rc = 0; |
| 358 | |
| 359 | switch (form) { |
| 360 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: |
| 361 | if (!sas_address) |
| 362 | break; |
| 363 | rc = _scsih_srch_boot_sas_address( |
| 364 | sas_address, &boot_device->SasWwid); |
| 365 | break; |
| 366 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: |
| 367 | if (!enclosure_logical_id) |
| 368 | break; |
| 369 | rc = _scsih_srch_boot_encl_slot( |
| 370 | enclosure_logical_id, |
| 371 | slot, &boot_device->EnclosureSlot); |
| 372 | break; |
| 373 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: |
| 374 | if (!device_name) |
| 375 | break; |
| 376 | rc = _scsih_srch_boot_device_name( |
| 377 | device_name, &boot_device->DeviceName); |
| 378 | break; |
| 379 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: |
| 380 | break; |
| 381 | } |
| 382 | |
| 383 | return rc; |
| 384 | } |
| 385 | |
| 386 | /** |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 387 | * _scsih_get_sas_address - set the sas_address for given device handle |
| 388 | * @handle: device handle |
| 389 | * @sas_address: sas address |
| 390 | * |
| 391 | * Returns 0 success, non-zero when failure |
| 392 | */ |
| 393 | static int |
| 394 | _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle, |
| 395 | u64 *sas_address) |
| 396 | { |
| 397 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 398 | Mpi2ConfigReply_t mpi_reply; |
| 399 | u32 ioc_status; |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 400 | *sas_address = 0; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 401 | |
| 402 | if (handle <= ioc->sas_hba.num_phys) { |
| 403 | *sas_address = ioc->sas_hba.sas_address; |
| 404 | return 0; |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 405 | } |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 406 | |
| 407 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 408 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 409 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 410 | __FILE__, __LINE__, __func__); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 411 | return -ENXIO; |
| 412 | } |
| 413 | |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 414 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 415 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { |
| 416 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 417 | return 0; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 418 | } |
| 419 | |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 420 | /* we hit this becuase the given parent handle doesn't exist */ |
| 421 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 422 | return -ENXIO; |
| 423 | /* else error case */ |
| 424 | printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), " |
| 425 | "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status, |
| 426 | __FILE__, __LINE__, __func__); |
| 427 | return -EIO; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 431 | * _scsih_determine_boot_device - determine boot device. |
| 432 | * @ioc: per adapter object |
| 433 | * @device: either sas_device or raid_device object |
| 434 | * @is_raid: [flag] 1 = raid object, 0 = sas object |
| 435 | * |
| 436 | * Determines whether this device should be first reported device to |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 437 | * 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] | 438 | * There are primary, alternate, and current entries in bios page 2. The order |
| 439 | * priority is primary, alternate, then current. This routine saves |
| 440 | * the corresponding device object and is_raid flag in the ioc object. |
| 441 | * The saved data to be used later in _scsih_probe_boot_devices(). |
| 442 | */ |
| 443 | static void |
| 444 | _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc, |
| 445 | void *device, u8 is_raid) |
| 446 | { |
| 447 | struct _sas_device *sas_device; |
| 448 | struct _raid_device *raid_device; |
| 449 | u64 sas_address; |
| 450 | u64 device_name; |
| 451 | u64 enclosure_logical_id; |
| 452 | u16 slot; |
| 453 | |
| 454 | /* only process this function when driver loads */ |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 455 | if (!ioc->is_driver_loading) |
| 456 | return; |
| 457 | |
| 458 | /* no Bios, return immediately */ |
| 459 | if (!ioc->bios_pg3.BiosVersion) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 460 | return; |
| 461 | |
| 462 | if (!is_raid) { |
| 463 | sas_device = device; |
| 464 | sas_address = sas_device->sas_address; |
| 465 | device_name = sas_device->device_name; |
| 466 | enclosure_logical_id = sas_device->enclosure_logical_id; |
| 467 | slot = sas_device->slot; |
| 468 | } else { |
| 469 | raid_device = device; |
| 470 | sas_address = raid_device->wwid; |
| 471 | device_name = 0; |
| 472 | enclosure_logical_id = 0; |
| 473 | slot = 0; |
| 474 | } |
| 475 | |
| 476 | if (!ioc->req_boot_device.device) { |
| 477 | if (_scsih_is_boot_device(sas_address, device_name, |
| 478 | enclosure_logical_id, slot, |
| 479 | (ioc->bios_pg2.ReqBootDeviceForm & |
| 480 | MPI2_BIOSPAGE2_FORM_MASK), |
| 481 | &ioc->bios_pg2.RequestedBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 482 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 483 | "%s: req_boot_device(0x%016llx)\n", |
| 484 | ioc->name, __func__, |
| 485 | (unsigned long long)sas_address)); |
| 486 | ioc->req_boot_device.device = device; |
| 487 | ioc->req_boot_device.is_raid = is_raid; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | if (!ioc->req_alt_boot_device.device) { |
| 492 | if (_scsih_is_boot_device(sas_address, device_name, |
| 493 | enclosure_logical_id, slot, |
| 494 | (ioc->bios_pg2.ReqAltBootDeviceForm & |
| 495 | MPI2_BIOSPAGE2_FORM_MASK), |
| 496 | &ioc->bios_pg2.RequestedAltBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 497 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 498 | "%s: req_alt_boot_device(0x%016llx)\n", |
| 499 | ioc->name, __func__, |
| 500 | (unsigned long long)sas_address)); |
| 501 | ioc->req_alt_boot_device.device = device; |
| 502 | ioc->req_alt_boot_device.is_raid = is_raid; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | if (!ioc->current_boot_device.device) { |
| 507 | if (_scsih_is_boot_device(sas_address, device_name, |
| 508 | enclosure_logical_id, slot, |
| 509 | (ioc->bios_pg2.CurrentBootDeviceForm & |
| 510 | MPI2_BIOSPAGE2_FORM_MASK), |
| 511 | &ioc->bios_pg2.CurrentBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 512 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 513 | "%s: current_boot_device(0x%016llx)\n", |
| 514 | ioc->name, __func__, |
| 515 | (unsigned long long)sas_address)); |
| 516 | ioc->current_boot_device.device = device; |
| 517 | ioc->current_boot_device.is_raid = is_raid; |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | /** |
| 523 | * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search |
| 524 | * @ioc: per adapter object |
| 525 | * @sas_address: sas address |
| 526 | * Context: Calling function should acquire ioc->sas_device_lock |
| 527 | * |
| 528 | * This searches for sas_device based on sas_address, then return sas_device |
| 529 | * object. |
| 530 | */ |
| 531 | struct _sas_device * |
| 532 | mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 533 | u64 sas_address) |
| 534 | { |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 535 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 536 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 537 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) |
| 538 | if (sas_device->sas_address == sas_address) |
| 539 | return sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 540 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 541 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) |
| 542 | if (sas_device->sas_address == sas_address) |
| 543 | return sas_device; |
| 544 | |
| 545 | return NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | /** |
| 549 | * _scsih_sas_device_find_by_handle - sas device search |
| 550 | * @ioc: per adapter object |
| 551 | * @handle: sas device handle (assigned by firmware) |
| 552 | * Context: Calling function should acquire ioc->sas_device_lock |
| 553 | * |
| 554 | * This searches for sas_device based on sas_address, then return sas_device |
| 555 | * object. |
| 556 | */ |
| 557 | static struct _sas_device * |
| 558 | _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 559 | { |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 560 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 561 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 562 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) |
| 563 | if (sas_device->handle == handle) |
| 564 | return sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 565 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 566 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) |
| 567 | if (sas_device->handle == handle) |
| 568 | return sas_device; |
| 569 | |
| 570 | return NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /** |
| 574 | * _scsih_sas_device_remove - remove sas_device from list. |
| 575 | * @ioc: per adapter object |
| 576 | * @sas_device: the sas_device object |
| 577 | * Context: This function will acquire ioc->sas_device_lock. |
| 578 | * |
| 579 | * Removing object and freeing associated memory from the ioc->sas_device_list. |
| 580 | */ |
| 581 | static void |
| 582 | _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc, |
| 583 | struct _sas_device *sas_device) |
| 584 | { |
| 585 | unsigned long flags; |
| 586 | |
Kashyap, Desai | 980ead3 | 2010-04-08 17:55:22 +0530 | [diff] [blame] | 587 | if (!sas_device) |
| 588 | return; |
| 589 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 590 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 591 | list_del(&sas_device->list); |
| 592 | kfree(sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 593 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 594 | } |
| 595 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 596 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 597 | /** |
| 598 | * _scsih_sas_device_add - insert sas_device to the list. |
| 599 | * @ioc: per adapter object |
| 600 | * @sas_device: the sas_device object |
| 601 | * Context: This function will acquire ioc->sas_device_lock. |
| 602 | * |
| 603 | * Adding new object to the ioc->sas_device_list. |
| 604 | */ |
| 605 | static void |
| 606 | _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc, |
| 607 | struct _sas_device *sas_device) |
| 608 | { |
| 609 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 610 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 611 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 612 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 613 | sas_device->handle, (unsigned long long)sas_device->sas_address)); |
| 614 | |
| 615 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 616 | list_add_tail(&sas_device->list, &ioc->sas_device_list); |
| 617 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 618 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 619 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 620 | sas_device->sas_address_parent)) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 621 | _scsih_sas_device_remove(ioc, sas_device); |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 622 | } else if (!sas_device->starget) { |
| 623 | /* When asyn scanning is enabled, its not possible to remove |
| 624 | * devices while scanning is turned on due to an oops in |
| 625 | * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start() |
| 626 | */ |
| 627 | if (!ioc->is_driver_loading) |
| 628 | mpt2sas_transport_port_remove(ioc, |
| 629 | sas_device->sas_address, |
| 630 | sas_device->sas_address_parent); |
| 631 | _scsih_sas_device_remove(ioc, sas_device); |
| 632 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /** |
| 636 | * _scsih_sas_device_init_add - insert sas_device to the list. |
| 637 | * @ioc: per adapter object |
| 638 | * @sas_device: the sas_device object |
| 639 | * Context: This function will acquire ioc->sas_device_lock. |
| 640 | * |
| 641 | * Adding new object at driver load time to the ioc->sas_device_init_list. |
| 642 | */ |
| 643 | static void |
| 644 | _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc, |
| 645 | struct _sas_device *sas_device) |
| 646 | { |
| 647 | unsigned long flags; |
| 648 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 649 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 650 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 651 | sas_device->handle, (unsigned long long)sas_device->sas_address)); |
| 652 | |
| 653 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 654 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 655 | _scsih_determine_boot_device(ioc, sas_device, 0); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 656 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 660 | * _scsih_raid_device_find_by_id - raid device search |
| 661 | * @ioc: per adapter object |
| 662 | * @id: sas device target id |
| 663 | * @channel: sas device channel |
| 664 | * Context: Calling function should acquire ioc->raid_device_lock |
| 665 | * |
| 666 | * This searches for raid_device based on target id, then return raid_device |
| 667 | * object. |
| 668 | */ |
| 669 | static struct _raid_device * |
| 670 | _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel) |
| 671 | { |
| 672 | struct _raid_device *raid_device, *r; |
| 673 | |
| 674 | r = NULL; |
| 675 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 676 | if (raid_device->id == id && raid_device->channel == channel) { |
| 677 | r = raid_device; |
| 678 | goto out; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | out: |
| 683 | return r; |
| 684 | } |
| 685 | |
| 686 | /** |
| 687 | * _scsih_raid_device_find_by_handle - raid device search |
| 688 | * @ioc: per adapter object |
| 689 | * @handle: sas device handle (assigned by firmware) |
| 690 | * Context: Calling function should acquire ioc->raid_device_lock |
| 691 | * |
| 692 | * This searches for raid_device based on handle, then return raid_device |
| 693 | * object. |
| 694 | */ |
| 695 | static struct _raid_device * |
| 696 | _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 697 | { |
| 698 | struct _raid_device *raid_device, *r; |
| 699 | |
| 700 | r = NULL; |
| 701 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 702 | if (raid_device->handle != handle) |
| 703 | continue; |
| 704 | r = raid_device; |
| 705 | goto out; |
| 706 | } |
| 707 | |
| 708 | out: |
| 709 | return r; |
| 710 | } |
| 711 | |
| 712 | /** |
| 713 | * _scsih_raid_device_find_by_wwid - raid device search |
| 714 | * @ioc: per adapter object |
| 715 | * @handle: sas device handle (assigned by firmware) |
| 716 | * Context: Calling function should acquire ioc->raid_device_lock |
| 717 | * |
| 718 | * This searches for raid_device based on wwid, then return raid_device |
| 719 | * object. |
| 720 | */ |
| 721 | static struct _raid_device * |
| 722 | _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid) |
| 723 | { |
| 724 | struct _raid_device *raid_device, *r; |
| 725 | |
| 726 | r = NULL; |
| 727 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 728 | if (raid_device->wwid != wwid) |
| 729 | continue; |
| 730 | r = raid_device; |
| 731 | goto out; |
| 732 | } |
| 733 | |
| 734 | out: |
| 735 | return r; |
| 736 | } |
| 737 | |
| 738 | /** |
| 739 | * _scsih_raid_device_add - add raid_device object |
| 740 | * @ioc: per adapter object |
| 741 | * @raid_device: raid_device object |
| 742 | * |
| 743 | * This is added to the raid_device_list link list. |
| 744 | */ |
| 745 | static void |
| 746 | _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc, |
| 747 | struct _raid_device *raid_device) |
| 748 | { |
| 749 | unsigned long flags; |
| 750 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 751 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 752 | "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, |
| 753 | raid_device->handle, (unsigned long long)raid_device->wwid)); |
| 754 | |
| 755 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 756 | list_add_tail(&raid_device->list, &ioc->raid_device_list); |
| 757 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 758 | } |
| 759 | |
| 760 | /** |
| 761 | * _scsih_raid_device_remove - delete raid_device object |
| 762 | * @ioc: per adapter object |
| 763 | * @raid_device: raid_device object |
| 764 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 765 | */ |
| 766 | static void |
| 767 | _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc, |
| 768 | struct _raid_device *raid_device) |
| 769 | { |
| 770 | unsigned long flags; |
| 771 | |
| 772 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 773 | list_del(&raid_device->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 774 | kfree(raid_device); |
| 775 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 776 | } |
| 777 | |
| 778 | /** |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 779 | * mpt2sas_scsih_expander_find_by_handle - expander device search |
| 780 | * @ioc: per adapter object |
| 781 | * @handle: expander handle (assigned by firmware) |
| 782 | * Context: Calling function should acquire ioc->sas_device_lock |
| 783 | * |
| 784 | * This searches for expander device based on handle, then returns the |
| 785 | * sas_node object. |
| 786 | */ |
| 787 | struct _sas_node * |
| 788 | mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 789 | { |
| 790 | struct _sas_node *sas_expander, *r; |
| 791 | |
| 792 | r = NULL; |
| 793 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 794 | if (sas_expander->handle != handle) |
| 795 | continue; |
| 796 | r = sas_expander; |
| 797 | goto out; |
| 798 | } |
| 799 | out: |
| 800 | return r; |
| 801 | } |
| 802 | |
| 803 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 804 | * mpt2sas_scsih_expander_find_by_sas_address - expander device search |
| 805 | * @ioc: per adapter object |
| 806 | * @sas_address: sas address |
| 807 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 808 | * |
| 809 | * This searches for expander device based on sas_address, then returns the |
| 810 | * sas_node object. |
| 811 | */ |
| 812 | struct _sas_node * |
| 813 | mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 814 | u64 sas_address) |
| 815 | { |
| 816 | struct _sas_node *sas_expander, *r; |
| 817 | |
| 818 | r = NULL; |
| 819 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 820 | if (sas_expander->sas_address != sas_address) |
| 821 | continue; |
| 822 | r = sas_expander; |
| 823 | goto out; |
| 824 | } |
| 825 | out: |
| 826 | return r; |
| 827 | } |
| 828 | |
| 829 | /** |
| 830 | * _scsih_expander_node_add - insert expander device to the list. |
| 831 | * @ioc: per adapter object |
| 832 | * @sas_expander: the sas_device object |
| 833 | * Context: This function will acquire ioc->sas_node_lock. |
| 834 | * |
| 835 | * Adding new object to the ioc->sas_expander_list. |
| 836 | * |
| 837 | * Return nothing. |
| 838 | */ |
| 839 | static void |
| 840 | _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc, |
| 841 | struct _sas_node *sas_expander) |
| 842 | { |
| 843 | unsigned long flags; |
| 844 | |
| 845 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 846 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); |
| 847 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 848 | } |
| 849 | |
| 850 | /** |
| 851 | * _scsih_is_end_device - determines if device is an end device |
| 852 | * @device_info: bitfield providing information about the device. |
| 853 | * Context: none |
| 854 | * |
| 855 | * Returns 1 if end device. |
| 856 | */ |
| 857 | static int |
| 858 | _scsih_is_end_device(u32 device_info) |
| 859 | { |
| 860 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && |
| 861 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | |
| 862 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
| 863 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) |
| 864 | return 1; |
| 865 | else |
| 866 | return 0; |
| 867 | } |
| 868 | |
| 869 | /** |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 870 | * _scsih_scsi_lookup_get - returns scmd entry |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 871 | * @ioc: per adapter object |
| 872 | * @smid: system request message index |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 873 | * |
| 874 | * Returns the smid stored scmd pointer. |
| 875 | */ |
| 876 | static struct scsi_cmnd * |
| 877 | _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 878 | { |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 879 | return ioc->scsi_lookup[smid - 1].scmd; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | /** |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 883 | * _scsih_scsi_lookup_get_clear - returns scmd entry |
| 884 | * @ioc: per adapter object |
| 885 | * @smid: system request message index |
| 886 | * |
| 887 | * Returns the smid stored scmd pointer. |
| 888 | * Then will derefrence the stored scmd pointer. |
| 889 | */ |
| 890 | static inline struct scsi_cmnd * |
| 891 | _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 892 | { |
| 893 | unsigned long flags; |
| 894 | struct scsi_cmnd *scmd; |
| 895 | |
| 896 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 897 | scmd = ioc->scsi_lookup[smid - 1].scmd; |
| 898 | ioc->scsi_lookup[smid - 1].scmd = NULL; |
| 899 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 900 | |
| 901 | return scmd; |
| 902 | } |
| 903 | |
| 904 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 905 | * _scsih_scsi_lookup_find_by_scmd - scmd lookup |
| 906 | * @ioc: per adapter object |
| 907 | * @smid: system request message index |
| 908 | * @scmd: pointer to scsi command object |
| 909 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 910 | * |
| 911 | * This will search for a scmd pointer in the scsi_lookup array, |
| 912 | * returning the revelent smid. A returned value of zero means invalid. |
| 913 | */ |
| 914 | static u16 |
| 915 | _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd |
| 916 | *scmd) |
| 917 | { |
| 918 | u16 smid; |
| 919 | unsigned long flags; |
| 920 | int i; |
| 921 | |
| 922 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 923 | smid = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 924 | for (i = 0; i < ioc->scsiio_depth; i++) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 925 | if (ioc->scsi_lookup[i].scmd == scmd) { |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 926 | smid = ioc->scsi_lookup[i].smid; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 927 | goto out; |
| 928 | } |
| 929 | } |
| 930 | out: |
| 931 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 932 | return smid; |
| 933 | } |
| 934 | |
| 935 | /** |
| 936 | * _scsih_scsi_lookup_find_by_target - search for matching channel:id |
| 937 | * @ioc: per adapter object |
| 938 | * @id: target id |
| 939 | * @channel: channel |
| 940 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 941 | * |
| 942 | * This will search for a matching channel:id in the scsi_lookup array, |
| 943 | * returning 1 if found. |
| 944 | */ |
| 945 | static u8 |
| 946 | _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id, |
| 947 | int channel) |
| 948 | { |
| 949 | u8 found; |
| 950 | unsigned long flags; |
| 951 | int i; |
| 952 | |
| 953 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 954 | found = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 955 | for (i = 0 ; i < ioc->scsiio_depth; i++) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 956 | if (ioc->scsi_lookup[i].scmd && |
| 957 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 958 | ioc->scsi_lookup[i].scmd->device->channel == channel)) { |
| 959 | found = 1; |
| 960 | goto out; |
| 961 | } |
| 962 | } |
| 963 | out: |
| 964 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 965 | return found; |
| 966 | } |
| 967 | |
| 968 | /** |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 969 | * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun |
| 970 | * @ioc: per adapter object |
| 971 | * @id: target id |
| 972 | * @lun: lun number |
| 973 | * @channel: channel |
| 974 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 975 | * |
| 976 | * This will search for a matching channel:id:lun in the scsi_lookup array, |
| 977 | * returning 1 if found. |
| 978 | */ |
| 979 | static u8 |
| 980 | _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id, |
| 981 | unsigned int lun, int channel) |
| 982 | { |
| 983 | u8 found; |
| 984 | unsigned long flags; |
| 985 | int i; |
| 986 | |
| 987 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 988 | found = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 989 | for (i = 0 ; i < ioc->scsiio_depth; i++) { |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 990 | if (ioc->scsi_lookup[i].scmd && |
| 991 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 992 | ioc->scsi_lookup[i].scmd->device->channel == channel && |
| 993 | ioc->scsi_lookup[i].scmd->device->lun == lun)) { |
| 994 | found = 1; |
| 995 | goto out; |
| 996 | } |
| 997 | } |
| 998 | out: |
| 999 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1000 | return found; |
| 1001 | } |
| 1002 | |
| 1003 | /** |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1004 | * _scsih_get_chain_buffer_tracker - obtain chain tracker |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1005 | * @ioc: per adapter object |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1006 | * @smid: smid associated to an IO request |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1007 | * |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1008 | * Returns chain tracker(from ioc->free_chain_list) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1009 | */ |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1010 | static struct chain_tracker * |
| 1011 | _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1012 | { |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1013 | struct chain_tracker *chain_req; |
| 1014 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1015 | |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1016 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 1017 | if (list_empty(&ioc->free_chain_list)) { |
| 1018 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
nagalakshmi.nandigama@lsi.com | aff132d | 2011-12-01 07:53:08 +0530 | [diff] [blame] | 1019 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not " |
| 1020 | "available\n", ioc->name)); |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1021 | return NULL; |
| 1022 | } |
| 1023 | chain_req = list_entry(ioc->free_chain_list.next, |
| 1024 | struct chain_tracker, tracker_list); |
| 1025 | list_del_init(&chain_req->tracker_list); |
| 1026 | list_add_tail(&chain_req->tracker_list, |
| 1027 | &ioc->scsi_lookup[smid - 1].chain_list); |
| 1028 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1029 | return chain_req; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | /** |
| 1033 | * _scsih_build_scatter_gather - main sg creation routine |
| 1034 | * @ioc: per adapter object |
| 1035 | * @scmd: scsi command |
| 1036 | * @smid: system request message index |
| 1037 | * Context: none. |
| 1038 | * |
| 1039 | * The main routine that builds scatter gather table from a given |
| 1040 | * scsi request sent via the .queuecommand main handler. |
| 1041 | * |
| 1042 | * Returns 0 success, anything else error |
| 1043 | */ |
| 1044 | static int |
| 1045 | _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc, |
| 1046 | struct scsi_cmnd *scmd, u16 smid) |
| 1047 | { |
| 1048 | Mpi2SCSIIORequest_t *mpi_request; |
| 1049 | dma_addr_t chain_dma; |
| 1050 | struct scatterlist *sg_scmd; |
| 1051 | void *sg_local, *chain; |
| 1052 | u32 chain_offset; |
| 1053 | u32 chain_length; |
| 1054 | u32 chain_flags; |
FUJITA Tomonori | bb789d0 | 2010-03-09 11:09:50 +0900 | [diff] [blame] | 1055 | int sges_left; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1056 | u32 sges_in_segment; |
| 1057 | u32 sgl_flags; |
| 1058 | u32 sgl_flags_last_element; |
| 1059 | u32 sgl_flags_end_buffer; |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1060 | struct chain_tracker *chain_req; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1061 | |
| 1062 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 1063 | |
| 1064 | /* init scatter gather flags */ |
| 1065 | sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT; |
| 1066 | if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 1067 | sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC; |
| 1068 | sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT) |
| 1069 | << MPI2_SGE_FLAGS_SHIFT; |
| 1070 | sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT | |
| 1071 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST) |
| 1072 | << MPI2_SGE_FLAGS_SHIFT; |
| 1073 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1074 | |
| 1075 | sg_scmd = scsi_sglist(scmd); |
| 1076 | sges_left = scsi_dma_map(scmd); |
FUJITA Tomonori | bb789d0 | 2010-03-09 11:09:50 +0900 | [diff] [blame] | 1077 | if (sges_left < 0) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1078 | sdev_printk(KERN_ERR, scmd->device, "pci_map_sg" |
| 1079 | " failed: request for %d bytes!\n", scsi_bufflen(scmd)); |
| 1080 | return -ENOMEM; |
| 1081 | } |
| 1082 | |
| 1083 | sg_local = &mpi_request->SGL; |
| 1084 | sges_in_segment = ioc->max_sges_in_main_message; |
| 1085 | if (sges_left <= sges_in_segment) |
| 1086 | goto fill_in_last_segment; |
| 1087 | |
| 1088 | mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) + |
| 1089 | (sges_in_segment * ioc->sge_size))/4; |
| 1090 | |
| 1091 | /* fill in main message segment when there is a chain following */ |
| 1092 | while (sges_in_segment) { |
| 1093 | if (sges_in_segment == 1) |
| 1094 | ioc->base_add_sg_single(sg_local, |
| 1095 | sgl_flags_last_element | sg_dma_len(sg_scmd), |
| 1096 | sg_dma_address(sg_scmd)); |
| 1097 | else |
| 1098 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1099 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1100 | sg_scmd = sg_next(sg_scmd); |
| 1101 | sg_local += ioc->sge_size; |
| 1102 | sges_left--; |
| 1103 | sges_in_segment--; |
| 1104 | } |
| 1105 | |
| 1106 | /* initializing the chain flags and pointers */ |
| 1107 | chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT; |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1108 | chain_req = _scsih_get_chain_buffer_tracker(ioc, smid); |
| 1109 | if (!chain_req) |
| 1110 | return -1; |
| 1111 | chain = chain_req->chain_buffer; |
| 1112 | chain_dma = chain_req->chain_buffer_dma; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1113 | do { |
| 1114 | sges_in_segment = (sges_left <= |
| 1115 | ioc->max_sges_in_chain_message) ? sges_left : |
| 1116 | ioc->max_sges_in_chain_message; |
| 1117 | chain_offset = (sges_left == sges_in_segment) ? |
| 1118 | 0 : (sges_in_segment * ioc->sge_size)/4; |
| 1119 | chain_length = sges_in_segment * ioc->sge_size; |
| 1120 | if (chain_offset) { |
| 1121 | chain_offset = chain_offset << |
| 1122 | MPI2_SGE_CHAIN_OFFSET_SHIFT; |
| 1123 | chain_length += ioc->sge_size; |
| 1124 | } |
| 1125 | ioc->base_add_sg_single(sg_local, chain_flags | chain_offset | |
| 1126 | chain_length, chain_dma); |
| 1127 | sg_local = chain; |
| 1128 | if (!chain_offset) |
| 1129 | goto fill_in_last_segment; |
| 1130 | |
| 1131 | /* fill in chain segments */ |
| 1132 | while (sges_in_segment) { |
| 1133 | if (sges_in_segment == 1) |
| 1134 | ioc->base_add_sg_single(sg_local, |
| 1135 | sgl_flags_last_element | |
| 1136 | sg_dma_len(sg_scmd), |
| 1137 | sg_dma_address(sg_scmd)); |
| 1138 | else |
| 1139 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1140 | sg_dma_len(sg_scmd), |
| 1141 | sg_dma_address(sg_scmd)); |
| 1142 | sg_scmd = sg_next(sg_scmd); |
| 1143 | sg_local += ioc->sge_size; |
| 1144 | sges_left--; |
| 1145 | sges_in_segment--; |
| 1146 | } |
| 1147 | |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1148 | chain_req = _scsih_get_chain_buffer_tracker(ioc, smid); |
| 1149 | if (!chain_req) |
| 1150 | return -1; |
| 1151 | chain = chain_req->chain_buffer; |
| 1152 | chain_dma = chain_req->chain_buffer_dma; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1153 | } while (1); |
| 1154 | |
| 1155 | |
| 1156 | fill_in_last_segment: |
| 1157 | |
| 1158 | /* fill the last segment */ |
| 1159 | while (sges_left) { |
| 1160 | if (sges_left == 1) |
| 1161 | ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer | |
| 1162 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1163 | else |
| 1164 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1165 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1166 | sg_scmd = sg_next(sg_scmd); |
| 1167 | sg_local += ioc->sge_size; |
| 1168 | sges_left--; |
| 1169 | } |
| 1170 | |
| 1171 | return 0; |
| 1172 | } |
| 1173 | |
| 1174 | /** |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1175 | * _scsih_adjust_queue_depth - setting device queue depth |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1176 | * @sdev: scsi device struct |
| 1177 | * @qdepth: requested queue depth |
| 1178 | * |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1179 | * |
| 1180 | * Returns nothing |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1181 | */ |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1182 | static void |
| 1183 | _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1184 | { |
| 1185 | struct Scsi_Host *shost = sdev->host; |
| 1186 | int max_depth; |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1187 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1188 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1189 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1190 | struct _sas_device *sas_device; |
| 1191 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1192 | |
| 1193 | max_depth = shost->can_queue; |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1194 | |
| 1195 | /* limit max device queue for SATA to 32 */ |
| 1196 | sas_device_priv_data = sdev->hostdata; |
| 1197 | if (!sas_device_priv_data) |
| 1198 | goto not_sata; |
| 1199 | sas_target_priv_data = sas_device_priv_data->sas_target; |
| 1200 | if (!sas_target_priv_data) |
| 1201 | goto not_sata; |
| 1202 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) |
| 1203 | goto not_sata; |
| 1204 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1205 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1206 | sas_device_priv_data->sas_target->sas_address); |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1207 | if (sas_device && sas_device->device_info & |
| 1208 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1209 | max_depth = MPT2SAS_SATA_QUEUE_DEPTH; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1210 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1211 | |
| 1212 | not_sata: |
| 1213 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1214 | if (!sdev->tagged_supported) |
| 1215 | max_depth = 1; |
| 1216 | if (qdepth > max_depth) |
| 1217 | qdepth = max_depth; |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1218 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); |
| 1219 | } |
| 1220 | |
| 1221 | /** |
| 1222 | * _scsih_change_queue_depth - setting device queue depth |
| 1223 | * @sdev: scsi device struct |
| 1224 | * @qdepth: requested queue depth |
| 1225 | * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP |
| 1226 | * (see include/scsi/scsi_host.h for definition) |
| 1227 | * |
| 1228 | * Returns queue depth. |
| 1229 | */ |
| 1230 | static int |
| 1231 | _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) |
| 1232 | { |
| 1233 | if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP) |
| 1234 | _scsih_adjust_queue_depth(sdev, qdepth); |
| 1235 | else if (reason == SCSI_QDEPTH_QFULL) |
| 1236 | scsi_track_queue_full(sdev, qdepth); |
| 1237 | else |
| 1238 | return -EOPNOTSUPP; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1239 | |
| 1240 | if (sdev->inquiry_len > 7) |
| 1241 | sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " |
| 1242 | "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n", |
| 1243 | sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags, |
| 1244 | sdev->ordered_tags, sdev->scsi_level, |
| 1245 | (sdev->inquiry[7] & 2) >> 1); |
| 1246 | |
| 1247 | return sdev->queue_depth; |
| 1248 | } |
| 1249 | |
| 1250 | /** |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 1251 | * _scsih_change_queue_type - changing device queue tag type |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1252 | * @sdev: scsi device struct |
| 1253 | * @tag_type: requested tag type |
| 1254 | * |
| 1255 | * Returns queue tag type. |
| 1256 | */ |
| 1257 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1258 | _scsih_change_queue_type(struct scsi_device *sdev, int tag_type) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1259 | { |
| 1260 | if (sdev->tagged_supported) { |
| 1261 | scsi_set_tag_type(sdev, tag_type); |
| 1262 | if (tag_type) |
| 1263 | scsi_activate_tcq(sdev, sdev->queue_depth); |
| 1264 | else |
| 1265 | scsi_deactivate_tcq(sdev, sdev->queue_depth); |
| 1266 | } else |
| 1267 | tag_type = 0; |
| 1268 | |
| 1269 | return tag_type; |
| 1270 | } |
| 1271 | |
| 1272 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1273 | * _scsih_target_alloc - target add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1274 | * @starget: scsi target struct |
| 1275 | * |
| 1276 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1277 | * the device is ignored. |
| 1278 | */ |
| 1279 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1280 | _scsih_target_alloc(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1281 | { |
| 1282 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1283 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1284 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1285 | struct _sas_device *sas_device; |
| 1286 | struct _raid_device *raid_device; |
| 1287 | unsigned long flags; |
| 1288 | struct sas_rphy *rphy; |
| 1289 | |
| 1290 | sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL); |
| 1291 | if (!sas_target_priv_data) |
| 1292 | return -ENOMEM; |
| 1293 | |
| 1294 | starget->hostdata = sas_target_priv_data; |
| 1295 | sas_target_priv_data->starget = starget; |
| 1296 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; |
| 1297 | |
| 1298 | /* RAID volumes */ |
| 1299 | if (starget->channel == RAID_CHANNEL) { |
| 1300 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1301 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1302 | starget->channel); |
| 1303 | if (raid_device) { |
| 1304 | sas_target_priv_data->handle = raid_device->handle; |
| 1305 | sas_target_priv_data->sas_address = raid_device->wwid; |
| 1306 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1307 | if (ioc->is_warpdrive) |
| 1308 | sas_target_priv_data->raid_device = raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1309 | raid_device->starget = starget; |
| 1310 | } |
| 1311 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1312 | return 0; |
| 1313 | } |
| 1314 | |
| 1315 | /* sas/sata devices */ |
| 1316 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1317 | rphy = dev_to_rphy(starget->dev.parent); |
| 1318 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1319 | rphy->identify.sas_address); |
| 1320 | |
| 1321 | if (sas_device) { |
| 1322 | sas_target_priv_data->handle = sas_device->handle; |
| 1323 | sas_target_priv_data->sas_address = sas_device->sas_address; |
| 1324 | sas_device->starget = starget; |
| 1325 | sas_device->id = starget->id; |
| 1326 | sas_device->channel = starget->channel; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 1327 | if (test_bit(sas_device->handle, ioc->pd_handles)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1328 | sas_target_priv_data->flags |= |
| 1329 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 1330 | } |
| 1331 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1332 | |
| 1333 | return 0; |
| 1334 | } |
| 1335 | |
| 1336 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1337 | * _scsih_target_destroy - target destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1338 | * @starget: scsi target struct |
| 1339 | * |
| 1340 | * Returns nothing. |
| 1341 | */ |
| 1342 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1343 | _scsih_target_destroy(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1344 | { |
| 1345 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1346 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1347 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1348 | struct _sas_device *sas_device; |
| 1349 | struct _raid_device *raid_device; |
| 1350 | unsigned long flags; |
| 1351 | struct sas_rphy *rphy; |
| 1352 | |
| 1353 | sas_target_priv_data = starget->hostdata; |
| 1354 | if (!sas_target_priv_data) |
| 1355 | return; |
| 1356 | |
| 1357 | if (starget->channel == RAID_CHANNEL) { |
| 1358 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1359 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1360 | starget->channel); |
| 1361 | if (raid_device) { |
| 1362 | raid_device->starget = NULL; |
| 1363 | raid_device->sdev = NULL; |
| 1364 | } |
| 1365 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1366 | goto out; |
| 1367 | } |
| 1368 | |
| 1369 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1370 | rphy = dev_to_rphy(starget->dev.parent); |
| 1371 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1372 | rphy->identify.sas_address); |
Eric Moore | 8901cbb | 2009-04-21 15:41:32 -0600 | [diff] [blame] | 1373 | if (sas_device && (sas_device->starget == starget) && |
| 1374 | (sas_device->id == starget->id) && |
| 1375 | (sas_device->channel == starget->channel)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1376 | sas_device->starget = NULL; |
| 1377 | |
| 1378 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1379 | |
| 1380 | out: |
| 1381 | kfree(sas_target_priv_data); |
| 1382 | starget->hostdata = NULL; |
| 1383 | } |
| 1384 | |
| 1385 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1386 | * _scsih_slave_alloc - device add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1387 | * @sdev: scsi device struct |
| 1388 | * |
| 1389 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1390 | * the device is ignored. |
| 1391 | */ |
| 1392 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1393 | _scsih_slave_alloc(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1394 | { |
| 1395 | struct Scsi_Host *shost; |
| 1396 | struct MPT2SAS_ADAPTER *ioc; |
| 1397 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1398 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1399 | struct scsi_target *starget; |
| 1400 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1401 | unsigned long flags; |
| 1402 | |
| 1403 | sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL); |
| 1404 | if (!sas_device_priv_data) |
| 1405 | return -ENOMEM; |
| 1406 | |
| 1407 | sas_device_priv_data->lun = sdev->lun; |
| 1408 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; |
| 1409 | |
| 1410 | starget = scsi_target(sdev); |
| 1411 | sas_target_priv_data = starget->hostdata; |
| 1412 | sas_target_priv_data->num_luns++; |
| 1413 | sas_device_priv_data->sas_target = sas_target_priv_data; |
| 1414 | sdev->hostdata = sas_device_priv_data; |
| 1415 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) |
| 1416 | sdev->no_uld_attach = 1; |
| 1417 | |
| 1418 | shost = dev_to_shost(&starget->dev); |
| 1419 | ioc = shost_priv(shost); |
| 1420 | if (starget->channel == RAID_CHANNEL) { |
| 1421 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1422 | raid_device = _scsih_raid_device_find_by_id(ioc, |
| 1423 | starget->id, starget->channel); |
| 1424 | if (raid_device) |
| 1425 | raid_device->sdev = sdev; /* raid is single lun */ |
| 1426 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1427 | } |
| 1428 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1429 | return 0; |
| 1430 | } |
| 1431 | |
| 1432 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1433 | * _scsih_slave_destroy - device destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1434 | * @sdev: scsi device struct |
| 1435 | * |
| 1436 | * Returns nothing. |
| 1437 | */ |
| 1438 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1439 | _scsih_slave_destroy(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1440 | { |
| 1441 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1442 | struct scsi_target *starget; |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1443 | struct Scsi_Host *shost; |
| 1444 | struct MPT2SAS_ADAPTER *ioc; |
| 1445 | struct _sas_device *sas_device; |
| 1446 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1447 | |
| 1448 | if (!sdev->hostdata) |
| 1449 | return; |
| 1450 | |
| 1451 | starget = scsi_target(sdev); |
| 1452 | sas_target_priv_data = starget->hostdata; |
| 1453 | sas_target_priv_data->num_luns--; |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1454 | |
| 1455 | shost = dev_to_shost(&starget->dev); |
| 1456 | ioc = shost_priv(shost); |
| 1457 | |
| 1458 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
| 1459 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1460 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1461 | sas_target_priv_data->sas_address); |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 1462 | if (sas_device && !sas_target_priv_data->num_luns) |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1463 | sas_device->starget = NULL; |
| 1464 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1465 | } |
| 1466 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1467 | kfree(sdev->hostdata); |
| 1468 | sdev->hostdata = NULL; |
| 1469 | } |
| 1470 | |
| 1471 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1472 | * _scsih_display_sata_capabilities - sata capabilities |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1473 | * @ioc: per adapter object |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1474 | * @handle: device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1475 | * @sdev: scsi device struct |
| 1476 | */ |
| 1477 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1478 | _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1479 | u16 handle, struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1480 | { |
| 1481 | Mpi2ConfigReply_t mpi_reply; |
| 1482 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1483 | u32 ioc_status; |
| 1484 | u16 flags; |
| 1485 | u32 device_info; |
| 1486 | |
| 1487 | 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] | 1488 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1489 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1490 | ioc->name, __FILE__, __LINE__, __func__); |
| 1491 | return; |
| 1492 | } |
| 1493 | |
| 1494 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1495 | MPI2_IOCSTATUS_MASK; |
| 1496 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 1497 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1498 | ioc->name, __FILE__, __LINE__, __func__); |
| 1499 | return; |
| 1500 | } |
| 1501 | |
| 1502 | flags = le16_to_cpu(sas_device_pg0.Flags); |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 1503 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1504 | |
| 1505 | sdev_printk(KERN_INFO, sdev, |
| 1506 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " |
| 1507 | "sw_preserve(%s)\n", |
| 1508 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", |
| 1509 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", |
| 1510 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : |
| 1511 | "n", |
| 1512 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", |
| 1513 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", |
| 1514 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); |
| 1515 | } |
| 1516 | |
| 1517 | /** |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1518 | * _scsih_is_raid - return boolean indicating device is raid volume |
| 1519 | * @dev the device struct object |
| 1520 | */ |
| 1521 | static int |
| 1522 | _scsih_is_raid(struct device *dev) |
| 1523 | { |
| 1524 | struct scsi_device *sdev = to_scsi_device(dev); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1525 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1526 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1527 | if (ioc->is_warpdrive) |
| 1528 | return 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1529 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
| 1530 | } |
| 1531 | |
| 1532 | /** |
| 1533 | * _scsih_get_resync - get raid volume resync percent complete |
| 1534 | * @dev the device struct object |
| 1535 | */ |
| 1536 | static void |
| 1537 | _scsih_get_resync(struct device *dev) |
| 1538 | { |
| 1539 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1540 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1541 | static struct _raid_device *raid_device; |
| 1542 | unsigned long flags; |
| 1543 | Mpi2RaidVolPage0_t vol_pg0; |
| 1544 | Mpi2ConfigReply_t mpi_reply; |
| 1545 | u32 volume_status_flags; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1546 | u8 percent_complete; |
| 1547 | u16 handle; |
| 1548 | |
| 1549 | percent_complete = 0; |
| 1550 | handle = 0; |
| 1551 | if (ioc->is_warpdrive) |
| 1552 | goto out; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1553 | |
| 1554 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1555 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1556 | sdev->channel); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1557 | if (raid_device) { |
| 1558 | handle = raid_device->handle; |
| 1559 | percent_complete = raid_device->percent_complete; |
| 1560 | } |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1561 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1562 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1563 | if (!handle) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1564 | goto out; |
| 1565 | |
| 1566 | 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] | 1567 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1568 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1569 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1570 | ioc->name, __FILE__, __LINE__, __func__); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1571 | percent_complete = 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1572 | goto out; |
| 1573 | } |
| 1574 | |
| 1575 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1576 | if (!(volume_status_flags & |
| 1577 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) |
| 1578 | percent_complete = 0; |
| 1579 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1580 | out: |
| 1581 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); |
| 1582 | } |
| 1583 | |
| 1584 | /** |
| 1585 | * _scsih_get_state - get raid volume level |
| 1586 | * @dev the device struct object |
| 1587 | */ |
| 1588 | static void |
| 1589 | _scsih_get_state(struct device *dev) |
| 1590 | { |
| 1591 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1592 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1593 | static struct _raid_device *raid_device; |
| 1594 | unsigned long flags; |
| 1595 | Mpi2RaidVolPage0_t vol_pg0; |
| 1596 | Mpi2ConfigReply_t mpi_reply; |
| 1597 | u32 volstate; |
| 1598 | enum raid_state state = RAID_STATE_UNKNOWN; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1599 | u16 handle = 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1600 | |
| 1601 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1602 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1603 | sdev->channel); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1604 | if (raid_device) |
| 1605 | handle = raid_device->handle; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1606 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1607 | |
| 1608 | if (!raid_device) |
| 1609 | goto out; |
| 1610 | |
| 1611 | 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] | 1612 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1613 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1614 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1615 | ioc->name, __FILE__, __LINE__, __func__); |
| 1616 | goto out; |
| 1617 | } |
| 1618 | |
| 1619 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
| 1620 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { |
| 1621 | state = RAID_STATE_RESYNCING; |
| 1622 | goto out; |
| 1623 | } |
| 1624 | |
| 1625 | switch (vol_pg0.VolumeState) { |
| 1626 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
| 1627 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 1628 | state = RAID_STATE_ACTIVE; |
| 1629 | break; |
| 1630 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 1631 | state = RAID_STATE_DEGRADED; |
| 1632 | break; |
| 1633 | case MPI2_RAID_VOL_STATE_FAILED: |
| 1634 | case MPI2_RAID_VOL_STATE_MISSING: |
| 1635 | state = RAID_STATE_OFFLINE; |
| 1636 | break; |
| 1637 | } |
| 1638 | out: |
| 1639 | raid_set_state(mpt2sas_raid_template, dev, state); |
| 1640 | } |
| 1641 | |
| 1642 | /** |
| 1643 | * _scsih_set_level - set raid level |
| 1644 | * @sdev: scsi device struct |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1645 | * @volume_type: volume type |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1646 | */ |
| 1647 | static void |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1648 | _scsih_set_level(struct scsi_device *sdev, u8 volume_type) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1649 | { |
| 1650 | enum raid_level level = RAID_LEVEL_UNKNOWN; |
| 1651 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1652 | switch (volume_type) { |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1653 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 1654 | level = RAID_LEVEL_0; |
| 1655 | break; |
| 1656 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 1657 | level = RAID_LEVEL_10; |
| 1658 | break; |
| 1659 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 1660 | level = RAID_LEVEL_1E; |
| 1661 | break; |
| 1662 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 1663 | level = RAID_LEVEL_1; |
| 1664 | break; |
| 1665 | } |
| 1666 | |
| 1667 | raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level); |
| 1668 | } |
| 1669 | |
| 1670 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1671 | * _scsih_get_volume_capabilities - volume capabilities |
| 1672 | * @ioc: per adapter object |
| 1673 | * @sas_device: the raid_device object |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1674 | * |
| 1675 | * Returns 0 for success, else 1 |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1676 | */ |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1677 | static int |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1678 | _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc, |
| 1679 | struct _raid_device *raid_device) |
| 1680 | { |
| 1681 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1682 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1683 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1684 | Mpi2ConfigReply_t mpi_reply; |
| 1685 | u16 sz; |
| 1686 | u8 num_pds; |
| 1687 | |
| 1688 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1689 | &num_pds)) || !num_pds) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1690 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1691 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1692 | __func__)); |
| 1693 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | raid_device->num_pds = num_pds; |
| 1697 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1698 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1699 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1700 | if (!vol_pg0) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1701 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1702 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1703 | __func__)); |
| 1704 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1708 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1709 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1710 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1711 | __func__)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1712 | kfree(vol_pg0); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1713 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | raid_device->volume_type = vol_pg0->VolumeType; |
| 1717 | |
| 1718 | /* figure out what the underlying devices are by |
| 1719 | * obtaining the device_info bits for the 1st device |
| 1720 | */ |
| 1721 | if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1722 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1723 | vol_pg0->PhysDisk[0].PhysDiskNum))) { |
| 1724 | if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 1725 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 1726 | le16_to_cpu(pd_pg0.DevHandle)))) { |
| 1727 | raid_device->device_info = |
| 1728 | le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | kfree(vol_pg0); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1733 | return 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1734 | } |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1735 | /** |
| 1736 | * _scsih_disable_ddio - Disable direct I/O for all the volumes |
| 1737 | * @ioc: per adapter object |
| 1738 | */ |
| 1739 | static void |
| 1740 | _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc) |
| 1741 | { |
| 1742 | Mpi2RaidVolPage1_t vol_pg1; |
| 1743 | Mpi2ConfigReply_t mpi_reply; |
| 1744 | struct _raid_device *raid_device; |
| 1745 | u16 handle; |
| 1746 | u16 ioc_status; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1747 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1748 | |
| 1749 | handle = 0xFFFF; |
| 1750 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 1751 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 1752 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1753 | MPI2_IOCSTATUS_MASK; |
| 1754 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 1755 | break; |
| 1756 | handle = le16_to_cpu(vol_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1757 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1758 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 1759 | if (raid_device) |
| 1760 | raid_device->direct_io_enabled = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1761 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1762 | } |
| 1763 | return; |
| 1764 | } |
| 1765 | |
| 1766 | |
| 1767 | /** |
| 1768 | * _scsih_get_num_volumes - Get number of volumes in the ioc |
| 1769 | * @ioc: per adapter object |
| 1770 | */ |
| 1771 | static u8 |
| 1772 | _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc) |
| 1773 | { |
| 1774 | Mpi2RaidVolPage1_t vol_pg1; |
| 1775 | Mpi2ConfigReply_t mpi_reply; |
| 1776 | u16 handle; |
| 1777 | u8 vol_cnt = 0; |
| 1778 | u16 ioc_status; |
| 1779 | |
| 1780 | handle = 0xFFFF; |
| 1781 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 1782 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 1783 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1784 | MPI2_IOCSTATUS_MASK; |
| 1785 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 1786 | break; |
| 1787 | vol_cnt++; |
| 1788 | handle = le16_to_cpu(vol_pg1.DevHandle); |
| 1789 | } |
| 1790 | return vol_cnt; |
| 1791 | } |
| 1792 | |
| 1793 | |
| 1794 | /** |
| 1795 | * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O. |
| 1796 | * @ioc: per adapter object |
| 1797 | * @raid_device: the raid_device object |
| 1798 | */ |
| 1799 | static void |
| 1800 | _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc, |
| 1801 | struct _raid_device *raid_device) |
| 1802 | { |
| 1803 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1804 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1805 | Mpi2ConfigReply_t mpi_reply; |
| 1806 | u16 sz; |
| 1807 | u8 num_pds, count; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1808 | unsigned long stripe_sz, block_sz; |
| 1809 | u8 stripe_exp, block_exp; |
| 1810 | u64 dev_max_lba; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1811 | |
| 1812 | if (!ioc->is_warpdrive) |
| 1813 | return; |
| 1814 | |
| 1815 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) { |
| 1816 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1817 | "globally as drives are exposed\n", ioc->name); |
| 1818 | return; |
| 1819 | } |
| 1820 | if (_scsih_get_num_volumes(ioc) > 1) { |
| 1821 | _scsih_disable_ddio(ioc); |
| 1822 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1823 | "globally as number of drives > 1\n", ioc->name); |
| 1824 | return; |
| 1825 | } |
| 1826 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1827 | &num_pds)) || !num_pds) { |
| 1828 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1829 | "Failure in computing number of drives\n", ioc->name); |
| 1830 | return; |
| 1831 | } |
| 1832 | |
| 1833 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1834 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1835 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1836 | if (!vol_pg0) { |
| 1837 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1838 | "Memory allocation failure for RVPG0\n", ioc->name); |
| 1839 | return; |
| 1840 | } |
| 1841 | |
| 1842 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1843 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
| 1844 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1845 | "Failure in retrieving RVPG0\n", ioc->name); |
| 1846 | kfree(vol_pg0); |
| 1847 | return; |
| 1848 | } |
| 1849 | |
| 1850 | /* |
| 1851 | * WARPDRIVE:If number of physical disks in a volume exceeds the max pds |
| 1852 | * assumed for WARPDRIVE, disable direct I/O |
| 1853 | */ |
| 1854 | if (num_pds > MPT_MAX_WARPDRIVE_PDS) { |
| 1855 | printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled " |
| 1856 | "for the drive with handle(0x%04x): num_mem=%d, " |
| 1857 | "max_mem_allowed=%d\n", ioc->name, raid_device->handle, |
| 1858 | num_pds, MPT_MAX_WARPDRIVE_PDS); |
| 1859 | kfree(vol_pg0); |
| 1860 | return; |
| 1861 | } |
| 1862 | for (count = 0; count < num_pds; count++) { |
| 1863 | if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1864 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1865 | vol_pg0->PhysDisk[count].PhysDiskNum) || |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 1866 | le16_to_cpu(pd_pg0.DevHandle) == |
| 1867 | MPT2SAS_INVALID_DEVICE_HANDLE) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1868 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " |
| 1869 | "disabled for the drive with handle(0x%04x) member" |
| 1870 | "handle retrieval failed for member number=%d\n", |
| 1871 | ioc->name, raid_device->handle, |
| 1872 | vol_pg0->PhysDisk[count].PhysDiskNum); |
| 1873 | goto out_error; |
| 1874 | } |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1875 | /* Disable direct I/O if member drive lba exceeds 4 bytes */ |
| 1876 | dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA); |
| 1877 | if (dev_max_lba >> 32) { |
| 1878 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " |
| 1879 | "disabled for the drive with handle(0x%04x) member" |
| 1880 | "handle (0x%04x) unsupported max lba 0x%016llx\n", |
| 1881 | ioc->name, raid_device->handle, |
| 1882 | le16_to_cpu(pd_pg0.DevHandle), |
| 1883 | (unsigned long long)dev_max_lba); |
| 1884 | goto out_error; |
| 1885 | } |
| 1886 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1887 | raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle); |
| 1888 | } |
| 1889 | |
| 1890 | /* |
| 1891 | * 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] | 1892 | * not RAID0 |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1893 | */ |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1894 | if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1895 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1896 | "for the drive with handle(0x%04x): type=%d, " |
| 1897 | "s_sz=%uK, blk_size=%u\n", ioc->name, |
| 1898 | raid_device->handle, raid_device->volume_type, |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1899 | (le32_to_cpu(vol_pg0->StripeSize) * |
| 1900 | le16_to_cpu(vol_pg0->BlockSize)) / 1024, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1901 | le16_to_cpu(vol_pg0->BlockSize)); |
| 1902 | goto out_error; |
| 1903 | } |
| 1904 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1905 | stripe_sz = le32_to_cpu(vol_pg0->StripeSize); |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1906 | stripe_exp = find_first_bit(&stripe_sz, 32); |
| 1907 | if (stripe_exp == 32) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1908 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1909 | "for the drive with handle(0x%04x) invalid stripe sz %uK\n", |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1910 | ioc->name, raid_device->handle, |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1911 | (le32_to_cpu(vol_pg0->StripeSize) * |
| 1912 | le16_to_cpu(vol_pg0->BlockSize)) / 1024); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1913 | goto out_error; |
| 1914 | } |
| 1915 | raid_device->stripe_exponent = stripe_exp; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1916 | block_sz = le16_to_cpu(vol_pg0->BlockSize); |
| 1917 | block_exp = find_first_bit(&block_sz, 16); |
| 1918 | if (block_exp == 16) { |
| 1919 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1920 | "for the drive with handle(0x%04x) invalid block sz %u\n", |
| 1921 | ioc->name, raid_device->handle, |
| 1922 | le16_to_cpu(vol_pg0->BlockSize)); |
| 1923 | goto out_error; |
| 1924 | } |
| 1925 | raid_device->block_exponent = block_exp; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1926 | raid_device->direct_io_enabled = 1; |
| 1927 | |
| 1928 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive" |
| 1929 | " with handle(0x%04x)\n", ioc->name, raid_device->handle); |
| 1930 | /* |
| 1931 | * WARPDRIVE: Though the following fields are not used for direct IO, |
| 1932 | * stored for future purpose: |
| 1933 | */ |
| 1934 | raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA); |
| 1935 | raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize); |
| 1936 | raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize); |
| 1937 | |
| 1938 | |
| 1939 | kfree(vol_pg0); |
| 1940 | return; |
| 1941 | |
| 1942 | out_error: |
| 1943 | raid_device->direct_io_enabled = 0; |
| 1944 | for (count = 0; count < num_pds; count++) |
| 1945 | raid_device->pd_handle[count] = 0; |
| 1946 | kfree(vol_pg0); |
| 1947 | return; |
| 1948 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1949 | |
| 1950 | /** |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 1951 | * _scsih_enable_tlr - setting TLR flags |
| 1952 | * @ioc: per adapter object |
| 1953 | * @sdev: scsi device struct |
| 1954 | * |
| 1955 | * Enabling Transaction Layer Retries for tape devices when |
| 1956 | * vpd page 0x90 is present |
| 1957 | * |
| 1958 | */ |
| 1959 | static void |
| 1960 | _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev) |
| 1961 | { |
| 1962 | /* only for TAPE */ |
| 1963 | if (sdev->type != TYPE_TAPE) |
| 1964 | return; |
| 1965 | |
| 1966 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) |
| 1967 | return; |
| 1968 | |
| 1969 | sas_enable_tlr(sdev); |
| 1970 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", |
| 1971 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); |
| 1972 | return; |
| 1973 | |
| 1974 | } |
| 1975 | |
| 1976 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1977 | * _scsih_slave_configure - device configure routine. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1978 | * @sdev: scsi device struct |
| 1979 | * |
| 1980 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1981 | * the device is ignored. |
| 1982 | */ |
| 1983 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1984 | _scsih_slave_configure(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1985 | { |
| 1986 | struct Scsi_Host *shost = sdev->host; |
| 1987 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1988 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1989 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1990 | struct _sas_device *sas_device; |
| 1991 | struct _raid_device *raid_device; |
| 1992 | unsigned long flags; |
| 1993 | int qdepth; |
| 1994 | u8 ssp_target = 0; |
| 1995 | char *ds = ""; |
| 1996 | char *r_level = ""; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1997 | u16 handle, volume_handle = 0; |
| 1998 | u64 volume_wwid = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1999 | |
| 2000 | qdepth = 1; |
| 2001 | sas_device_priv_data = sdev->hostdata; |
| 2002 | sas_device_priv_data->configured_lun = 1; |
| 2003 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; |
| 2004 | sas_target_priv_data = sas_device_priv_data->sas_target; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2005 | handle = sas_target_priv_data->handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2006 | |
| 2007 | /* raid volume handling */ |
| 2008 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 2009 | |
| 2010 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2011 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2012 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 2013 | if (!raid_device) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2014 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2015 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2016 | __LINE__, __func__)); |
| 2017 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2018 | } |
| 2019 | |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2020 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { |
| 2021 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2022 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2023 | __LINE__, __func__)); |
| 2024 | return 1; |
| 2025 | } |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2026 | /* |
| 2027 | * WARPDRIVE: Initialize the required data for Direct IO |
| 2028 | */ |
| 2029 | _scsih_init_warpdrive_properties(ioc, raid_device); |
| 2030 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2031 | /* RAID Queue Depth Support |
| 2032 | * IS volume = underlying qdepth of drive type, either |
| 2033 | * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH |
| 2034 | * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH) |
| 2035 | */ |
| 2036 | if (raid_device->device_info & |
| 2037 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 2038 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 2039 | ds = "SSP"; |
| 2040 | } else { |
| 2041 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 2042 | if (raid_device->device_info & |
| 2043 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 2044 | ds = "SATA"; |
| 2045 | else |
| 2046 | ds = "STP"; |
| 2047 | } |
| 2048 | |
| 2049 | switch (raid_device->volume_type) { |
| 2050 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 2051 | r_level = "RAID0"; |
| 2052 | break; |
| 2053 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 2054 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 2055 | if (ioc->manu_pg10.OEMIdentifier && |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 2056 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 2057 | MFG10_GF0_R10_DISPLAY) && |
| 2058 | !(raid_device->num_pds % 2)) |
| 2059 | r_level = "RAID10"; |
| 2060 | else |
| 2061 | r_level = "RAID1E"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2062 | break; |
| 2063 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 2064 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2065 | r_level = "RAID1"; |
| 2066 | break; |
| 2067 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 2068 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2069 | r_level = "RAID10"; |
| 2070 | break; |
| 2071 | case MPI2_RAID_VOL_TYPE_UNKNOWN: |
| 2072 | default: |
| 2073 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2074 | r_level = "RAIDX"; |
| 2075 | break; |
| 2076 | } |
| 2077 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2078 | if (!ioc->hide_ir_msg) |
| 2079 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
| 2080 | "wwid(0x%016llx), pd_count(%d), type(%s)\n", |
| 2081 | r_level, raid_device->handle, |
| 2082 | (unsigned long long)raid_device->wwid, |
| 2083 | raid_device->num_pds, ds); |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 2084 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 2085 | /* raid transport support */ |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2086 | if (!ioc->is_warpdrive) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2087 | _scsih_set_level(sdev, raid_device->volume_type); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2088 | return 0; |
| 2089 | } |
| 2090 | |
| 2091 | /* non-raid handling */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2092 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2093 | if (mpt2sas_config_get_volume_handle(ioc, handle, |
| 2094 | &volume_handle)) { |
| 2095 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2096 | "failure at %s:%d/%s()!\n", ioc->name, |
| 2097 | __FILE__, __LINE__, __func__)); |
| 2098 | return 1; |
| 2099 | } |
| 2100 | if (volume_handle && mpt2sas_config_get_volume_wwid(ioc, |
| 2101 | volume_handle, &volume_wwid)) { |
| 2102 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2103 | "failure at %s:%d/%s()!\n", ioc->name, |
| 2104 | __FILE__, __LINE__, __func__)); |
| 2105 | return 1; |
| 2106 | } |
| 2107 | } |
| 2108 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2109 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2110 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2111 | sas_device_priv_data->sas_target->sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2112 | if (!sas_device) { |
| 2113 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2114 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2115 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2116 | __LINE__, __func__)); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2117 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2118 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2119 | sas_device->volume_handle = volume_handle; |
| 2120 | sas_device->volume_wwid = volume_wwid; |
| 2121 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 2122 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 2123 | ssp_target = 1; |
| 2124 | ds = "SSP"; |
| 2125 | } else { |
| 2126 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 2127 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
| 2128 | ds = "STP"; |
| 2129 | else if (sas_device->device_info & |
| 2130 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 2131 | ds = "SATA"; |
| 2132 | } |
| 2133 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
| 2134 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", |
| 2135 | ds, sas_device->handle, |
| 2136 | (unsigned long long)sas_device->sas_address, |
| 2137 | sas_device->phy, |
| 2138 | (unsigned long long)sas_device->device_name); |
| 2139 | sdev_printk(KERN_INFO, sdev, "%s: " |
| 2140 | "enclosure_logical_id(0x%016llx), slot(%d)\n", ds, |
| 2141 | (unsigned long long) sas_device->enclosure_logical_id, |
| 2142 | sas_device->slot); |
| 2143 | |
| 2144 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2145 | if (!ssp_target) |
| 2146 | _scsih_display_sata_capabilities(ioc, handle, sdev); |
| 2147 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2148 | |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 2149 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2150 | |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 2151 | if (ssp_target) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2152 | sas_read_port_mode_page(sdev); |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 2153 | _scsih_enable_tlr(ioc, sdev); |
| 2154 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2155 | return 0; |
| 2156 | } |
| 2157 | |
| 2158 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2159 | * _scsih_bios_param - fetch head, sector, cylinder info for a disk |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2160 | * @sdev: scsi device struct |
| 2161 | * @bdev: pointer to block device context |
| 2162 | * @capacity: device size (in 512 byte sectors) |
| 2163 | * @params: three element array to place output: |
| 2164 | * params[0] number of heads (max 255) |
| 2165 | * params[1] number of sectors (max 63) |
| 2166 | * params[2] number of cylinders |
| 2167 | * |
| 2168 | * Return nothing. |
| 2169 | */ |
| 2170 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2171 | _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2172 | sector_t capacity, int params[]) |
| 2173 | { |
| 2174 | int heads; |
| 2175 | int sectors; |
| 2176 | sector_t cylinders; |
| 2177 | ulong dummy; |
| 2178 | |
| 2179 | heads = 64; |
| 2180 | sectors = 32; |
| 2181 | |
| 2182 | dummy = heads * sectors; |
| 2183 | cylinders = capacity; |
| 2184 | sector_div(cylinders, dummy); |
| 2185 | |
| 2186 | /* |
| 2187 | * Handle extended translation size for logical drives |
| 2188 | * > 1Gb |
| 2189 | */ |
| 2190 | if ((ulong)capacity >= 0x200000) { |
| 2191 | heads = 255; |
| 2192 | sectors = 63; |
| 2193 | dummy = heads * sectors; |
| 2194 | cylinders = capacity; |
| 2195 | sector_div(cylinders, dummy); |
| 2196 | } |
| 2197 | |
| 2198 | /* return result */ |
| 2199 | params[0] = heads; |
| 2200 | params[1] = sectors; |
| 2201 | params[2] = cylinders; |
| 2202 | |
| 2203 | return 0; |
| 2204 | } |
| 2205 | |
| 2206 | /** |
| 2207 | * _scsih_response_code - translation of device response code |
| 2208 | * @ioc: per adapter object |
| 2209 | * @response_code: response code returned by the device |
| 2210 | * |
| 2211 | * Return nothing. |
| 2212 | */ |
| 2213 | static void |
| 2214 | _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code) |
| 2215 | { |
| 2216 | char *desc; |
| 2217 | |
| 2218 | switch (response_code) { |
| 2219 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: |
| 2220 | desc = "task management request completed"; |
| 2221 | break; |
| 2222 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: |
| 2223 | desc = "invalid frame"; |
| 2224 | break; |
| 2225 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: |
| 2226 | desc = "task management request not supported"; |
| 2227 | break; |
| 2228 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: |
| 2229 | desc = "task management request failed"; |
| 2230 | break; |
| 2231 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: |
| 2232 | desc = "task management request succeeded"; |
| 2233 | break; |
| 2234 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: |
| 2235 | desc = "invalid lun"; |
| 2236 | break; |
| 2237 | case 0xA: |
| 2238 | desc = "overlapped tag attempted"; |
| 2239 | break; |
| 2240 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: |
| 2241 | desc = "task queued, however not sent to target"; |
| 2242 | break; |
| 2243 | default: |
| 2244 | desc = "unknown"; |
| 2245 | break; |
| 2246 | } |
| 2247 | printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n", |
| 2248 | ioc->name, response_code, desc); |
| 2249 | } |
| 2250 | |
| 2251 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2252 | * _scsih_tm_done - tm completion routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2253 | * @ioc: per adapter object |
| 2254 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2255 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2256 | * @reply: reply message frame(lower 32bit addr) |
| 2257 | * Context: none. |
| 2258 | * |
| 2259 | * The callback handler when using scsih_issue_tm. |
| 2260 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2261 | * Return 1 meaning mf should be freed from _base_interrupt |
| 2262 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2263 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2264 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2265 | _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] | 2266 | { |
| 2267 | MPI2DefaultReply_t *mpi_reply; |
| 2268 | |
| 2269 | if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2270 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2271 | if (ioc->tm_cmds.smid != smid) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2272 | return 1; |
nagalakshmi.nandigama@lsi.com | 911ae94 | 2011-09-08 06:18:50 +0530 | [diff] [blame] | 2273 | mpt2sas_base_flush_reply_queues(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2274 | ioc->tm_cmds.status |= MPT2_CMD_COMPLETE; |
| 2275 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 2276 | if (mpi_reply) { |
| 2277 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 2278 | ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 2279 | } |
| 2280 | ioc->tm_cmds.status &= ~MPT2_CMD_PENDING; |
| 2281 | complete(&ioc->tm_cmds.done); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2282 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | /** |
| 2286 | * mpt2sas_scsih_set_tm_flag - set per target tm_busy |
| 2287 | * @ioc: per adapter object |
| 2288 | * @handle: device handle |
| 2289 | * |
| 2290 | * During taskmangement request, we need to freeze the device queue. |
| 2291 | */ |
| 2292 | void |
| 2293 | mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2294 | { |
| 2295 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2296 | struct scsi_device *sdev; |
| 2297 | u8 skip = 0; |
| 2298 | |
| 2299 | shost_for_each_device(sdev, ioc->shost) { |
| 2300 | if (skip) |
| 2301 | continue; |
| 2302 | sas_device_priv_data = sdev->hostdata; |
| 2303 | if (!sas_device_priv_data) |
| 2304 | continue; |
| 2305 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2306 | sas_device_priv_data->sas_target->tm_busy = 1; |
| 2307 | skip = 1; |
| 2308 | ioc->ignore_loginfos = 1; |
| 2309 | } |
| 2310 | } |
| 2311 | } |
| 2312 | |
| 2313 | /** |
| 2314 | * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy |
| 2315 | * @ioc: per adapter object |
| 2316 | * @handle: device handle |
| 2317 | * |
| 2318 | * During taskmangement request, we need to freeze the device queue. |
| 2319 | */ |
| 2320 | void |
| 2321 | mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2322 | { |
| 2323 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2324 | struct scsi_device *sdev; |
| 2325 | u8 skip = 0; |
| 2326 | |
| 2327 | shost_for_each_device(sdev, ioc->shost) { |
| 2328 | if (skip) |
| 2329 | continue; |
| 2330 | sas_device_priv_data = sdev->hostdata; |
| 2331 | if (!sas_device_priv_data) |
| 2332 | continue; |
| 2333 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2334 | sas_device_priv_data->sas_target->tm_busy = 0; |
| 2335 | skip = 1; |
| 2336 | ioc->ignore_loginfos = 0; |
| 2337 | } |
| 2338 | } |
| 2339 | } |
| 2340 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2341 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2342 | /** |
| 2343 | * mpt2sas_scsih_issue_tm - main routine for sending tm requests |
| 2344 | * @ioc: per adapter struct |
| 2345 | * @device_handle: device handle |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2346 | * @channel: the channel assigned by the OS |
| 2347 | * @id: the id assigned by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2348 | * @lun: lun number |
| 2349 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) |
| 2350 | * @smid_task: smid assigned to the task |
| 2351 | * @timeout: timeout in seconds |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2352 | * @serial_number: the serial_number from scmd |
| 2353 | * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2354 | * Context: user |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2355 | * |
| 2356 | * A generic API for sending task management requests to firmware. |
| 2357 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2358 | * The callback index is set inside `ioc->tm_cb_idx`. |
| 2359 | * |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2360 | * Return SUCCESS or FAILED. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2361 | */ |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2362 | int |
| 2363 | mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel, |
| 2364 | uint id, uint lun, u8 type, u16 smid_task, ulong timeout, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2365 | unsigned long serial_number, enum mutex_type m_type) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2366 | { |
| 2367 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 2368 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
| 2369 | u16 smid = 0; |
| 2370 | u32 ioc_state; |
| 2371 | unsigned long timeleft; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2372 | struct scsiio_tracker *scsi_lookup = NULL; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2373 | int rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2374 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2375 | if (m_type == TM_MUTEX_ON) |
| 2376 | mutex_lock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2377 | if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) { |
| 2378 | printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n", |
| 2379 | __func__, ioc->name); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2380 | rc = FAILED; |
| 2381 | goto err_out; |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2382 | } |
| 2383 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 2384 | if (ioc->shost_recovery || ioc->remove_host || |
| 2385 | ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2386 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 2387 | __func__, ioc->name); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2388 | rc = FAILED; |
| 2389 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2390 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2391 | |
| 2392 | ioc_state = mpt2sas_base_get_iocstate(ioc, 0); |
| 2393 | if (ioc_state & MPI2_DOORBELL_USED) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 2394 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2395 | "active!\n", ioc->name)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2396 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2397 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2398 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2399 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 2403 | mpt2sas_base_fault_info(ioc, ioc_state & |
| 2404 | MPI2_DOORBELL_DATA_MASK); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2405 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2406 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2407 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2408 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2409 | } |
| 2410 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2411 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2412 | if (!smid) { |
| 2413 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 2414 | ioc->name, __func__); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2415 | rc = FAILED; |
| 2416 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2417 | } |
| 2418 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2419 | if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) |
| 2420 | scsi_lookup = &ioc->scsi_lookup[smid_task - 1]; |
| 2421 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2422 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x)," |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2423 | " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type, |
| 2424 | smid_task)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2425 | ioc->tm_cmds.status = MPT2_CMD_PENDING; |
| 2426 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 2427 | ioc->tm_cmds.smid = smid; |
| 2428 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2429 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2430 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 2431 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 2432 | mpi_request->TaskType = type; |
| 2433 | mpi_request->TaskMID = cpu_to_le16(smid_task); |
| 2434 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); |
| 2435 | mpt2sas_scsih_set_tm_flag(ioc, handle); |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 2436 | init_completion(&ioc->tm_cmds.done); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2437 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2438 | timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2439 | if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) { |
| 2440 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 2441 | ioc->name, __func__); |
| 2442 | _debug_dump_mf(mpi_request, |
| 2443 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2444 | if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) { |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2445 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2446 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2447 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2448 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
| 2449 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 2450 | goto err_out; |
| 2451 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 2455 | mpi_reply = ioc->tm_cmds.reply; |
| 2456 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: " |
| 2457 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", |
| 2458 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 2459 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 2460 | le32_to_cpu(mpi_reply->TerminationCount))); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2461 | if (ioc->logging_level & MPT_DEBUG_TM) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2462 | _scsih_response_code(ioc, mpi_reply->ResponseCode); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2463 | if (mpi_reply->IOCStatus) |
| 2464 | _debug_dump_mf(mpi_request, |
| 2465 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
| 2466 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2467 | } |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2468 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2469 | switch (type) { |
| 2470 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2471 | rc = SUCCESS; |
| 2472 | if (scsi_lookup->scmd == NULL) |
| 2473 | break; |
| 2474 | rc = FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2475 | break; |
| 2476 | |
| 2477 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: |
| 2478 | if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) |
| 2479 | rc = FAILED; |
| 2480 | else |
| 2481 | rc = SUCCESS; |
| 2482 | break; |
| 2483 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2484 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2485 | case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: |
| 2486 | if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) |
| 2487 | rc = FAILED; |
| 2488 | else |
| 2489 | rc = SUCCESS; |
| 2490 | break; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2491 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: |
| 2492 | rc = SUCCESS; |
| 2493 | break; |
| 2494 | default: |
| 2495 | rc = FAILED; |
| 2496 | break; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2497 | } |
| 2498 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2499 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 2500 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2501 | if (m_type == TM_MUTEX_ON) |
| 2502 | mutex_unlock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2503 | |
| 2504 | return rc; |
| 2505 | |
| 2506 | err_out: |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2507 | if (m_type == TM_MUTEX_ON) |
| 2508 | mutex_unlock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2509 | return rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | /** |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2513 | * _scsih_tm_display_info - displays info about the device |
| 2514 | * @ioc: per adapter struct |
| 2515 | * @scmd: pointer to scsi command object |
| 2516 | * |
| 2517 | * Called by task management callback handlers. |
| 2518 | */ |
| 2519 | static void |
| 2520 | _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) |
| 2521 | { |
| 2522 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2523 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; |
| 2524 | struct _sas_device *sas_device = NULL; |
| 2525 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2526 | char *device_str = NULL; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2527 | |
| 2528 | if (!priv_target) |
| 2529 | return; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2530 | if (ioc->hide_ir_msg) |
| 2531 | device_str = "WarpDrive"; |
| 2532 | else |
| 2533 | device_str = "volume"; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2534 | |
| 2535 | scsi_print_command(scmd); |
| 2536 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2537 | starget_printk(KERN_INFO, starget, "%s handle(0x%04x), " |
| 2538 | "%s wwid(0x%016llx)\n", device_str, priv_target->handle, |
| 2539 | device_str, (unsigned long long)priv_target->sas_address); |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2540 | } else { |
| 2541 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2542 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2543 | priv_target->sas_address); |
| 2544 | if (sas_device) { |
| 2545 | if (priv_target->flags & |
| 2546 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2547 | starget_printk(KERN_INFO, starget, |
| 2548 | "volume handle(0x%04x), " |
| 2549 | "volume wwid(0x%016llx)\n", |
| 2550 | sas_device->volume_handle, |
| 2551 | (unsigned long long)sas_device->volume_wwid); |
| 2552 | } |
| 2553 | starget_printk(KERN_INFO, starget, |
| 2554 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", |
| 2555 | sas_device->handle, |
| 2556 | (unsigned long long)sas_device->sas_address, |
| 2557 | sas_device->phy); |
| 2558 | starget_printk(KERN_INFO, starget, |
| 2559 | "enclosure_logical_id(0x%016llx), slot(%d)\n", |
| 2560 | (unsigned long long)sas_device->enclosure_logical_id, |
| 2561 | sas_device->slot); |
| 2562 | } |
| 2563 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2564 | } |
| 2565 | } |
| 2566 | |
| 2567 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2568 | * _scsih_abort - eh threads main abort routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2569 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2570 | * |
| 2571 | * Returns SUCCESS if command aborted else FAILED |
| 2572 | */ |
| 2573 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2574 | _scsih_abort(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2575 | { |
| 2576 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2577 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2578 | u16 smid; |
| 2579 | u16 handle; |
| 2580 | int r; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2581 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2582 | sdev_printk(KERN_INFO, scmd->device, "attempting task abort! " |
| 2583 | "scmd(%p)\n", scmd); |
| 2584 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2585 | |
| 2586 | sas_device_priv_data = scmd->device->hostdata; |
| 2587 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2588 | sdev_printk(KERN_INFO, scmd->device, "device been deleted! " |
| 2589 | "scmd(%p)\n", scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2590 | scmd->result = DID_NO_CONNECT << 16; |
| 2591 | scmd->scsi_done(scmd); |
| 2592 | r = SUCCESS; |
| 2593 | goto out; |
| 2594 | } |
| 2595 | |
| 2596 | /* search for the command */ |
| 2597 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); |
| 2598 | if (!smid) { |
| 2599 | scmd->result = DID_RESET << 16; |
| 2600 | r = SUCCESS; |
| 2601 | goto out; |
| 2602 | } |
| 2603 | |
| 2604 | /* for hidden raid components and volumes this is not supported */ |
| 2605 | if (sas_device_priv_data->sas_target->flags & |
| 2606 | MPT_TARGET_FLAGS_RAID_COMPONENT || |
| 2607 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 2608 | scmd->result = DID_RESET << 16; |
| 2609 | r = FAILED; |
| 2610 | goto out; |
| 2611 | } |
| 2612 | |
Kashyap, Desai | fa7f316 | 2009-09-23 17:26:58 +0530 | [diff] [blame] | 2613 | mpt2sas_halt_firmware(ioc); |
| 2614 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2615 | handle = sas_device_priv_data->sas_target->handle; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2616 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2617 | scmd->device->id, scmd->device->lun, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2618 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, |
| 2619 | scmd->serial_number, TM_MUTEX_ON); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2620 | |
| 2621 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2622 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", |
| 2623 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2624 | return r; |
| 2625 | } |
| 2626 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2627 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2628 | * _scsih_dev_reset - eh threads main device reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2629 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2630 | * |
| 2631 | * Returns SUCCESS if command aborted else FAILED |
| 2632 | */ |
| 2633 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2634 | _scsih_dev_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2635 | { |
| 2636 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2637 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2638 | struct _sas_device *sas_device; |
| 2639 | unsigned long flags; |
| 2640 | u16 handle; |
| 2641 | int r; |
| 2642 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2643 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2644 | |
Kashyap, Desai | 37aaa78 | 2010-11-13 04:41:32 +0530 | [diff] [blame] | 2645 | starget_printk(KERN_INFO, starget, "attempting device reset! " |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2646 | "scmd(%p)\n", scmd); |
| 2647 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2648 | |
| 2649 | sas_device_priv_data = scmd->device->hostdata; |
| 2650 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 37aaa78 | 2010-11-13 04:41:32 +0530 | [diff] [blame] | 2651 | starget_printk(KERN_INFO, starget, "device been deleted! " |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2652 | "scmd(%p)\n", scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2653 | scmd->result = DID_NO_CONNECT << 16; |
| 2654 | scmd->scsi_done(scmd); |
| 2655 | r = SUCCESS; |
| 2656 | goto out; |
| 2657 | } |
| 2658 | |
| 2659 | /* for hidden raid components obtain the volume_handle */ |
| 2660 | handle = 0; |
| 2661 | if (sas_device_priv_data->sas_target->flags & |
| 2662 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2663 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2664 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2665 | sas_device_priv_data->sas_target->handle); |
| 2666 | if (sas_device) |
| 2667 | handle = sas_device->volume_handle; |
| 2668 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2669 | } else |
| 2670 | handle = sas_device_priv_data->sas_target->handle; |
| 2671 | |
| 2672 | if (!handle) { |
| 2673 | scmd->result = DID_RESET << 16; |
| 2674 | r = FAILED; |
| 2675 | goto out; |
| 2676 | } |
| 2677 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2678 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2679 | scmd->device->id, scmd->device->lun, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2680 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, 0, |
| 2681 | TM_MUTEX_ON); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2682 | |
| 2683 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2684 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", |
| 2685 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2686 | return r; |
| 2687 | } |
| 2688 | |
| 2689 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2690 | * _scsih_target_reset - eh threads main target reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2691 | * @scmd: pointer to scsi command object |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2692 | * |
| 2693 | * Returns SUCCESS if command aborted else FAILED |
| 2694 | */ |
| 2695 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2696 | _scsih_target_reset(struct scsi_cmnd *scmd) |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2697 | { |
| 2698 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2699 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2700 | struct _sas_device *sas_device; |
| 2701 | unsigned long flags; |
| 2702 | u16 handle; |
| 2703 | int r; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2704 | struct scsi_target *starget = scmd->device->sdev_target; |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2705 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2706 | starget_printk(KERN_INFO, starget, "attempting target reset! " |
| 2707 | "scmd(%p)\n", scmd); |
| 2708 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2709 | |
| 2710 | sas_device_priv_data = scmd->device->hostdata; |
| 2711 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2712 | starget_printk(KERN_INFO, starget, "target been deleted! " |
| 2713 | "scmd(%p)\n", scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2714 | scmd->result = DID_NO_CONNECT << 16; |
| 2715 | scmd->scsi_done(scmd); |
| 2716 | r = SUCCESS; |
| 2717 | goto out; |
| 2718 | } |
| 2719 | |
| 2720 | /* for hidden raid components obtain the volume_handle */ |
| 2721 | handle = 0; |
| 2722 | if (sas_device_priv_data->sas_target->flags & |
| 2723 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2724 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2725 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2726 | sas_device_priv_data->sas_target->handle); |
| 2727 | if (sas_device) |
| 2728 | handle = sas_device->volume_handle; |
| 2729 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2730 | } else |
| 2731 | handle = sas_device_priv_data->sas_target->handle; |
| 2732 | |
| 2733 | if (!handle) { |
| 2734 | scmd->result = DID_RESET << 16; |
| 2735 | r = FAILED; |
| 2736 | goto out; |
| 2737 | } |
| 2738 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2739 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2740 | scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2741 | 30, 0, TM_MUTEX_ON); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2742 | |
| 2743 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2744 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", |
| 2745 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2746 | return r; |
| 2747 | } |
| 2748 | |
| 2749 | /** |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2750 | * _scsih_host_reset - eh threads main host reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2751 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2752 | * |
| 2753 | * Returns SUCCESS if command aborted else FAILED |
| 2754 | */ |
| 2755 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2756 | _scsih_host_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2757 | { |
| 2758 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2759 | int r, retval; |
| 2760 | |
| 2761 | printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n", |
| 2762 | ioc->name, scmd); |
| 2763 | scsi_print_command(scmd); |
| 2764 | |
| 2765 | retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2766 | FORCE_BIG_HAMMER); |
| 2767 | r = (retval < 0) ? FAILED : SUCCESS; |
| 2768 | printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n", |
| 2769 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 2770 | |
| 2771 | return r; |
| 2772 | } |
| 2773 | |
| 2774 | /** |
| 2775 | * _scsih_fw_event_add - insert and queue up fw_event |
| 2776 | * @ioc: per adapter object |
| 2777 | * @fw_event: object describing the event |
| 2778 | * Context: This function will acquire ioc->fw_event_lock. |
| 2779 | * |
| 2780 | * This adds the firmware event object into link list, then queues it up to |
| 2781 | * be processed from user context. |
| 2782 | * |
| 2783 | * Return nothing. |
| 2784 | */ |
| 2785 | static void |
| 2786 | _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event) |
| 2787 | { |
| 2788 | unsigned long flags; |
| 2789 | |
| 2790 | if (ioc->firmware_event_thread == NULL) |
| 2791 | return; |
| 2792 | |
| 2793 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2794 | list_add_tail(&fw_event->list, &ioc->fw_event_list); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2795 | INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work); |
| 2796 | queue_delayed_work(ioc->firmware_event_thread, |
| 2797 | &fw_event->delayed_work, 0); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2798 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2799 | } |
| 2800 | |
| 2801 | /** |
| 2802 | * _scsih_fw_event_free - delete fw_event |
| 2803 | * @ioc: per adapter object |
| 2804 | * @fw_event: object describing the event |
| 2805 | * Context: This function will acquire ioc->fw_event_lock. |
| 2806 | * |
| 2807 | * This removes firmware event object from link list, frees associated memory. |
| 2808 | * |
| 2809 | * Return nothing. |
| 2810 | */ |
| 2811 | static void |
| 2812 | _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work |
| 2813 | *fw_event) |
| 2814 | { |
| 2815 | unsigned long flags; |
| 2816 | |
| 2817 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2818 | list_del(&fw_event->list); |
| 2819 | kfree(fw_event->event_data); |
| 2820 | kfree(fw_event); |
| 2821 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2822 | } |
| 2823 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2824 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2825 | /** |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2826 | * _scsih_error_recovery_delete_devices - remove devices not responding |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2827 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2828 | * |
| 2829 | * Return nothing. |
| 2830 | */ |
| 2831 | static void |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2832 | _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2833 | { |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2834 | struct fw_event_work *fw_event; |
| 2835 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2836 | if (ioc->is_driver_loading) |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2837 | return; |
Dan Carpenter | 181a9d7 | 2011-11-04 21:25:01 +0300 | [diff] [blame] | 2838 | |
| 2839 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2840 | if (!fw_event) |
| 2841 | return; |
| 2842 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2843 | fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES; |
| 2844 | fw_event->ioc = ioc; |
| 2845 | _scsih_fw_event_add(ioc, fw_event); |
| 2846 | } |
| 2847 | |
| 2848 | /** |
| 2849 | * mpt2sas_port_enable_complete - port enable completed (fake event) |
| 2850 | * @ioc: per adapter object |
| 2851 | * |
| 2852 | * Return nothing. |
| 2853 | */ |
| 2854 | void |
| 2855 | mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc) |
| 2856 | { |
| 2857 | struct fw_event_work *fw_event; |
| 2858 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2859 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2860 | if (!fw_event) |
| 2861 | return; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2862 | fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2863 | fw_event->ioc = ioc; |
| 2864 | _scsih_fw_event_add(ioc, fw_event); |
| 2865 | } |
| 2866 | |
| 2867 | /** |
| 2868 | * _scsih_fw_event_cleanup_queue - cleanup event queue |
| 2869 | * @ioc: per adapter object |
| 2870 | * |
| 2871 | * Walk the firmware event queue, either killing timers, or waiting |
| 2872 | * for outstanding events to complete |
| 2873 | * |
| 2874 | * Return nothing. |
| 2875 | */ |
| 2876 | static void |
| 2877 | _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc) |
| 2878 | { |
| 2879 | struct fw_event_work *fw_event, *next; |
| 2880 | |
| 2881 | if (list_empty(&ioc->fw_event_list) || |
| 2882 | !ioc->firmware_event_thread || in_interrupt()) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2883 | return; |
| 2884 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2885 | list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) { |
| 2886 | if (cancel_delayed_work(&fw_event->delayed_work)) { |
| 2887 | _scsih_fw_event_free(ioc, fw_event); |
| 2888 | continue; |
| 2889 | } |
| 2890 | fw_event->cancel_pending_work = 1; |
| 2891 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2892 | } |
| 2893 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2894 | /** |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2895 | * _scsih_ublock_io_all_device - unblock every device |
| 2896 | * @ioc: per adapter object |
| 2897 | * |
| 2898 | * change the device state from block to running |
| 2899 | */ |
| 2900 | static void |
| 2901 | _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc) |
| 2902 | { |
| 2903 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2904 | struct scsi_device *sdev; |
| 2905 | |
| 2906 | shost_for_each_device(sdev, ioc->shost) { |
| 2907 | sas_device_priv_data = sdev->hostdata; |
| 2908 | if (!sas_device_priv_data) |
| 2909 | continue; |
| 2910 | if (!sas_device_priv_data->block) |
| 2911 | continue; |
| 2912 | sas_device_priv_data->block = 0; |
| 2913 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, " |
| 2914 | "handle(0x%04x)\n", |
| 2915 | sas_device_priv_data->sas_target->handle)); |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 2916 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2917 | } |
| 2918 | } |
| 2919 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2920 | * _scsih_ublock_io_device - set the device state to SDEV_RUNNING |
| 2921 | * @ioc: per adapter object |
| 2922 | * @handle: device handle |
| 2923 | * |
| 2924 | * During device pull we need to appropiately set the sdev state. |
| 2925 | */ |
| 2926 | static void |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2927 | _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2928 | { |
| 2929 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2930 | struct scsi_device *sdev; |
| 2931 | |
| 2932 | shost_for_each_device(sdev, ioc->shost) { |
| 2933 | sas_device_priv_data = sdev->hostdata; |
| 2934 | if (!sas_device_priv_data) |
| 2935 | continue; |
| 2936 | if (!sas_device_priv_data->block) |
| 2937 | continue; |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2938 | if (sas_device_priv_data->sas_target->sas_address == |
| 2939 | sas_address) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2940 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2941 | MPT2SAS_INFO_FMT "SDEV_RUNNING: " |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2942 | "sas address(0x%016llx)\n", ioc->name, |
| 2943 | (unsigned long long)sas_address)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2944 | sas_device_priv_data->block = 0; |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 2945 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2946 | } |
| 2947 | } |
| 2948 | } |
| 2949 | |
| 2950 | /** |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2951 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK |
| 2952 | * @ioc: per adapter object |
| 2953 | * @handle: device handle |
| 2954 | * |
| 2955 | * During device pull we need to appropiately set the sdev state. |
| 2956 | */ |
| 2957 | static void |
| 2958 | _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc) |
| 2959 | { |
| 2960 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2961 | struct scsi_device *sdev; |
| 2962 | |
| 2963 | shost_for_each_device(sdev, ioc->shost) { |
| 2964 | sas_device_priv_data = sdev->hostdata; |
| 2965 | if (!sas_device_priv_data) |
| 2966 | continue; |
| 2967 | if (sas_device_priv_data->block) |
| 2968 | continue; |
| 2969 | sas_device_priv_data->block = 1; |
| 2970 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, " |
| 2971 | "handle(0x%04x)\n", |
| 2972 | sas_device_priv_data->sas_target->handle)); |
| 2973 | scsi_internal_device_block(sdev); |
| 2974 | } |
| 2975 | } |
| 2976 | |
| 2977 | |
| 2978 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2979 | * _scsih_block_io_device - set the device state to SDEV_BLOCK |
| 2980 | * @ioc: per adapter object |
| 2981 | * @handle: device handle |
| 2982 | * |
| 2983 | * During device pull we need to appropiately set the sdev state. |
| 2984 | */ |
| 2985 | static void |
| 2986 | _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2987 | { |
| 2988 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2989 | struct scsi_device *sdev; |
| 2990 | |
| 2991 | shost_for_each_device(sdev, ioc->shost) { |
| 2992 | sas_device_priv_data = sdev->hostdata; |
| 2993 | if (!sas_device_priv_data) |
| 2994 | continue; |
| 2995 | if (sas_device_priv_data->block) |
| 2996 | continue; |
| 2997 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2998 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2999 | MPT2SAS_INFO_FMT "SDEV_BLOCK: " |
| 3000 | "handle(0x%04x)\n", ioc->name, handle)); |
| 3001 | sas_device_priv_data->block = 1; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 3002 | scsi_internal_device_block(sdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3003 | } |
| 3004 | } |
| 3005 | } |
| 3006 | |
| 3007 | /** |
| 3008 | * _scsih_block_io_to_children_attached_to_ex |
| 3009 | * @ioc: per adapter object |
| 3010 | * @sas_expander: the sas_device object |
| 3011 | * |
| 3012 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 3013 | * attached to this expander. This function called when expander is |
| 3014 | * pulled. |
| 3015 | */ |
| 3016 | static void |
| 3017 | _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc, |
| 3018 | struct _sas_node *sas_expander) |
| 3019 | { |
| 3020 | struct _sas_port *mpt2sas_port; |
| 3021 | struct _sas_device *sas_device; |
| 3022 | struct _sas_node *expander_sibling; |
| 3023 | unsigned long flags; |
| 3024 | |
| 3025 | if (!sas_expander) |
| 3026 | return; |
| 3027 | |
| 3028 | list_for_each_entry(mpt2sas_port, |
| 3029 | &sas_expander->sas_port_list, port_list) { |
| 3030 | if (mpt2sas_port->remote_identify.device_type == |
| 3031 | SAS_END_DEVICE) { |
| 3032 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3033 | sas_device = |
| 3034 | mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 3035 | mpt2sas_port->remote_identify.sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 3036 | if (sas_device) |
| 3037 | set_bit(sas_device->handle, |
| 3038 | ioc->blocking_handles); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3039 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3040 | } |
| 3041 | } |
| 3042 | |
| 3043 | list_for_each_entry(mpt2sas_port, |
| 3044 | &sas_expander->sas_port_list, port_list) { |
| 3045 | |
| 3046 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 3047 | SAS_EDGE_EXPANDER_DEVICE || |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3048 | mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 3049 | SAS_FANOUT_EXPANDER_DEVICE) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3050 | expander_sibling = |
| 3051 | mpt2sas_scsih_expander_find_by_sas_address( |
| 3052 | ioc, mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3053 | _scsih_block_io_to_children_attached_to_ex(ioc, |
| 3054 | expander_sibling); |
| 3055 | } |
| 3056 | } |
| 3057 | } |
| 3058 | |
| 3059 | /** |
| 3060 | * _scsih_block_io_to_children_attached_directly |
| 3061 | * @ioc: per adapter object |
| 3062 | * @event_data: topology change event data |
| 3063 | * |
| 3064 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 3065 | * direct attached during device pull. |
| 3066 | */ |
| 3067 | static void |
| 3068 | _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc, |
| 3069 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3070 | { |
| 3071 | int i; |
| 3072 | u16 handle; |
| 3073 | u16 reason_code; |
| 3074 | u8 phy_number; |
| 3075 | |
| 3076 | for (i = 0; i < event_data->NumEntries; i++) { |
| 3077 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3078 | if (!handle) |
| 3079 | continue; |
| 3080 | phy_number = event_data->StartPhyNum + i; |
| 3081 | reason_code = event_data->PHY[i].PhyStatus & |
| 3082 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3083 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) |
| 3084 | _scsih_block_io_device(ioc, handle); |
| 3085 | } |
| 3086 | } |
| 3087 | |
| 3088 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3089 | * _scsih_tm_tr_send - send task management request |
| 3090 | * @ioc: per adapter object |
| 3091 | * @handle: device handle |
| 3092 | * Context: interrupt time. |
| 3093 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3094 | * This code is to initiate the device removal handshake protocol |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3095 | * with controller firmware. This function will issue target reset |
| 3096 | * using high priority request queue. It will send a sas iounit |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3097 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3098 | * |
| 3099 | * This is designed to send muliple task management request at the same |
| 3100 | * time to the fifo. If the fifo is full, we will append the request, |
| 3101 | * and process it in a future completion. |
| 3102 | */ |
| 3103 | static void |
| 3104 | _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3105 | { |
| 3106 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3107 | u16 smid; |
| 3108 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3109 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; |
| 3110 | u64 sas_address = 0; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3111 | unsigned long flags; |
| 3112 | struct _tr_list *delayed_tr; |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3113 | u32 ioc_state; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3114 | |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3115 | if (ioc->remove_host) { |
| 3116 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been " |
| 3117 | "removed: handle(0x%04x)\n", __func__, ioc->name, handle)); |
| 3118 | return; |
| 3119 | } else if (ioc->pci_error_recovery) { |
| 3120 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci " |
| 3121 | "error recovery: handle(0x%04x)\n", __func__, ioc->name, |
| 3122 | handle)); |
| 3123 | return; |
| 3124 | } |
| 3125 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 3126 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 3127 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not " |
| 3128 | "operational: handle(0x%04x)\n", __func__, ioc->name, |
| 3129 | handle)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3130 | return; |
| 3131 | } |
| 3132 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3133 | /* if PD, then return */ |
| 3134 | if (test_bit(handle, ioc->pd_handles)) |
| 3135 | return; |
| 3136 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3137 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3138 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3139 | if (sas_device && sas_device->starget && |
| 3140 | sas_device->starget->hostdata) { |
| 3141 | sas_target_priv_data = sas_device->starget->hostdata; |
| 3142 | sas_target_priv_data->deleted = 1; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3143 | sas_address = sas_device->sas_address; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3144 | } |
| 3145 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3146 | |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3147 | if (sas_target_priv_data) { |
| 3148 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: " |
| 3149 | "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle, |
| 3150 | (unsigned long long)sas_address)); |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 3151 | _scsih_ublock_io_device(ioc, sas_address); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 3152 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3153 | } |
| 3154 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3155 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); |
| 3156 | if (!smid) { |
| 3157 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3158 | if (!delayed_tr) |
| 3159 | return; |
| 3160 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3161 | delayed_tr->handle = handle; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3162 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 3163 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3164 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 3165 | ioc->name, handle)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3166 | return; |
| 3167 | } |
| 3168 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3169 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " |
| 3170 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, |
| 3171 | ioc->tm_tr_cb_idx)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3172 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3173 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 3174 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3175 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3176 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3177 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
| 3178 | } |
| 3179 | |
| 3180 | |
| 3181 | |
| 3182 | /** |
| 3183 | * _scsih_sas_control_complete - completion routine |
| 3184 | * @ioc: per adapter object |
| 3185 | * @smid: system request message index |
| 3186 | * @msix_index: MSIX table index supplied by the OS |
| 3187 | * @reply: reply message frame(lower 32bit addr) |
| 3188 | * Context: interrupt time. |
| 3189 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3190 | * This is the sas iounit control completion routine. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3191 | * 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] | 3192 | * handshake protocol with controller firmware. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3193 | * |
| 3194 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3195 | * 0 means the mf is freed from this function. |
| 3196 | */ |
| 3197 | static u8 |
| 3198 | _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 3199 | u8 msix_index, u32 reply) |
| 3200 | { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3201 | Mpi2SasIoUnitControlReply_t *mpi_reply = |
| 3202 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3203 | if (likely(mpi_reply)) { |
| 3204 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3205 | "sc_complete:handle(0x%04x), (open) " |
| 3206 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 3207 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, |
| 3208 | le16_to_cpu(mpi_reply->IOCStatus), |
| 3209 | le32_to_cpu(mpi_reply->IOCLogInfo))); |
| 3210 | } else { |
| 3211 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3212 | ioc->name, __FILE__, __LINE__, __func__); |
| 3213 | } |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3214 | return 1; |
| 3215 | } |
| 3216 | |
| 3217 | /** |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3218 | * _scsih_tm_tr_volume_send - send target reset request for volumes |
| 3219 | * @ioc: per adapter object |
| 3220 | * @handle: device handle |
| 3221 | * Context: interrupt time. |
| 3222 | * |
| 3223 | * This is designed to send muliple task management request at the same |
| 3224 | * time to the fifo. If the fifo is full, we will append the request, |
| 3225 | * and process it in a future completion. |
| 3226 | */ |
| 3227 | static void |
| 3228 | _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3229 | { |
| 3230 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 3231 | u16 smid; |
| 3232 | struct _tr_list *delayed_tr; |
| 3233 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3234 | if (ioc->shost_recovery || ioc->remove_host || |
| 3235 | ioc->pci_error_recovery) { |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3236 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3237 | "progress!\n", __func__, ioc->name)); |
| 3238 | return; |
| 3239 | } |
| 3240 | |
| 3241 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); |
| 3242 | if (!smid) { |
| 3243 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3244 | if (!delayed_tr) |
| 3245 | return; |
| 3246 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3247 | delayed_tr->handle = handle; |
| 3248 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); |
| 3249 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3250 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 3251 | ioc->name, handle)); |
| 3252 | return; |
| 3253 | } |
| 3254 | |
| 3255 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " |
| 3256 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, |
| 3257 | ioc->tm_tr_volume_cb_idx)); |
| 3258 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3259 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 3260 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3261 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3262 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
| 3263 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
| 3264 | } |
| 3265 | |
| 3266 | /** |
| 3267 | * _scsih_tm_volume_tr_complete - target reset completion |
| 3268 | * @ioc: per adapter object |
| 3269 | * @smid: system request message index |
| 3270 | * @msix_index: MSIX table index supplied by the OS |
| 3271 | * @reply: reply message frame(lower 32bit addr) |
| 3272 | * Context: interrupt time. |
| 3273 | * |
| 3274 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3275 | * 0 means the mf is freed from this function. |
| 3276 | */ |
| 3277 | static u8 |
| 3278 | _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 3279 | u8 msix_index, u32 reply) |
| 3280 | { |
| 3281 | u16 handle; |
| 3282 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
| 3283 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3284 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 3285 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3286 | if (ioc->shost_recovery || ioc->remove_host || |
| 3287 | ioc->pci_error_recovery) { |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3288 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3289 | "progress!\n", __func__, ioc->name)); |
| 3290 | return 1; |
| 3291 | } |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3292 | if (unlikely(!mpi_reply)) { |
| 3293 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3294 | ioc->name, __FILE__, __LINE__, __func__); |
| 3295 | return 1; |
| 3296 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3297 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3298 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3299 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3300 | dewtprintk(ioc, printk("spurious interrupt: " |
| 3301 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle, |
| 3302 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3303 | return 0; |
| 3304 | } |
| 3305 | |
| 3306 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3307 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3308 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3309 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3310 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3311 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3312 | |
| 3313 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3314 | } |
| 3315 | |
| 3316 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3317 | * _scsih_tm_tr_complete - |
| 3318 | * @ioc: per adapter object |
| 3319 | * @smid: system request message index |
| 3320 | * @msix_index: MSIX table index supplied by the OS |
| 3321 | * @reply: reply message frame(lower 32bit addr) |
| 3322 | * Context: interrupt time. |
| 3323 | * |
| 3324 | * This is the target reset completion routine. |
| 3325 | * 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] | 3326 | * handshake protocol with controller firmware. |
| 3327 | * 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] | 3328 | * |
| 3329 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3330 | * 0 means the mf is freed from this function. |
| 3331 | */ |
| 3332 | static u8 |
| 3333 | _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 3334 | u32 reply) |
| 3335 | { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3336 | u16 handle; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3337 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3338 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3339 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 3340 | Mpi2SasIoUnitControlRequest_t *mpi_request; |
| 3341 | u16 smid_sas_ctrl; |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3342 | u32 ioc_state; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3343 | |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3344 | if (ioc->remove_host) { |
| 3345 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been " |
| 3346 | "removed\n", __func__, ioc->name)); |
| 3347 | return 1; |
| 3348 | } else if (ioc->pci_error_recovery) { |
| 3349 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci " |
| 3350 | "error recovery\n", __func__, ioc->name)); |
| 3351 | return 1; |
| 3352 | } |
| 3353 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 3354 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 3355 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not " |
| 3356 | "operational\n", __func__, ioc->name)); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3357 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3358 | } |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3359 | if (unlikely(!mpi_reply)) { |
| 3360 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3361 | ioc->name, __FILE__, __LINE__, __func__); |
| 3362 | return 1; |
| 3363 | } |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3364 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3365 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3366 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3367 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: " |
| 3368 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle, |
| 3369 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3370 | return 0; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3371 | } |
| 3372 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3373 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3374 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3375 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3376 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3377 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3378 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3379 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3380 | smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); |
| 3381 | if (!smid_sas_ctrl) { |
| 3382 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 3383 | ioc->name, __func__); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3384 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3385 | } |
| 3386 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3387 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), " |
| 3388 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl, |
| 3389 | ioc->tm_sas_control_cb_idx)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3390 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl); |
| 3391 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); |
| 3392 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; |
| 3393 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3394 | mpi_request->DevHandle = mpi_request_tm->DevHandle; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3395 | mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3396 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3397 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3398 | } |
| 3399 | |
| 3400 | /** |
| 3401 | * _scsih_check_for_pending_tm - check for pending task management |
| 3402 | * @ioc: per adapter object |
| 3403 | * @smid: system request message index |
| 3404 | * |
| 3405 | * This will check delayed target reset list, and feed the |
| 3406 | * next reqeust. |
| 3407 | * |
| 3408 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3409 | * 0 means the mf is freed from this function. |
| 3410 | */ |
| 3411 | static u8 |
| 3412 | _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 3413 | { |
| 3414 | struct _tr_list *delayed_tr; |
| 3415 | |
| 3416 | if (!list_empty(&ioc->delayed_tr_volume_list)) { |
| 3417 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, |
| 3418 | struct _tr_list, list); |
| 3419 | mpt2sas_base_free_smid(ioc, smid); |
| 3420 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); |
| 3421 | list_del(&delayed_tr->list); |
| 3422 | kfree(delayed_tr); |
| 3423 | return 0; |
| 3424 | } |
| 3425 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3426 | if (!list_empty(&ioc->delayed_tr_list)) { |
| 3427 | delayed_tr = list_entry(ioc->delayed_tr_list.next, |
| 3428 | struct _tr_list, list); |
| 3429 | mpt2sas_base_free_smid(ioc, smid); |
| 3430 | _scsih_tm_tr_send(ioc, delayed_tr->handle); |
| 3431 | list_del(&delayed_tr->list); |
| 3432 | kfree(delayed_tr); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3433 | return 0; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3434 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3435 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3436 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3440 | * _scsih_check_topo_delete_events - sanity check on topo events |
| 3441 | * @ioc: per adapter object |
| 3442 | * @event_data: the event data payload |
| 3443 | * |
| 3444 | * This routine added to better handle cable breaker. |
| 3445 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3446 | * This handles the case where driver receives multiple expander |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3447 | * add and delete events in a single shot. When there is a delete event |
| 3448 | * the routine will void any pending add events waiting in the event queue. |
| 3449 | * |
| 3450 | * Return nothing. |
| 3451 | */ |
| 3452 | static void |
| 3453 | _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 3454 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3455 | { |
| 3456 | struct fw_event_work *fw_event; |
| 3457 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; |
| 3458 | u16 expander_handle; |
| 3459 | struct _sas_node *sas_expander; |
| 3460 | unsigned long flags; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3461 | int i, reason_code; |
| 3462 | u16 handle; |
| 3463 | |
| 3464 | for (i = 0 ; i < event_data->NumEntries; i++) { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3465 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3466 | if (!handle) |
| 3467 | continue; |
| 3468 | reason_code = event_data->PHY[i].PhyStatus & |
| 3469 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3470 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) |
| 3471 | _scsih_tm_tr_send(ioc, handle); |
| 3472 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3473 | |
| 3474 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 3475 | if (expander_handle < ioc->sas_hba.num_phys) { |
| 3476 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3477 | return; |
| 3478 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 3479 | if (event_data->ExpStatus == |
| 3480 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { |
| 3481 | /* put expander attached devices into blocking state */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3482 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 3483 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 3484 | expander_handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3485 | _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] | 3486 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 3487 | do { |
| 3488 | handle = find_first_bit(ioc->blocking_handles, |
| 3489 | ioc->facts.MaxDevHandle); |
| 3490 | if (handle < ioc->facts.MaxDevHandle) |
| 3491 | _scsih_block_io_device(ioc, handle); |
| 3492 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3493 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) |
| 3494 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3495 | |
| 3496 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) |
| 3497 | return; |
| 3498 | |
| 3499 | /* mark ignore flag for pending events */ |
| 3500 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 3501 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { |
| 3502 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || |
| 3503 | fw_event->ignore) |
| 3504 | continue; |
| 3505 | local_event_data = fw_event->event_data; |
| 3506 | if (local_event_data->ExpStatus == |
| 3507 | MPI2_EVENT_SAS_TOPO_ES_ADDED || |
| 3508 | local_event_data->ExpStatus == |
| 3509 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { |
| 3510 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == |
| 3511 | expander_handle) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 3512 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3513 | "setting ignoring flag\n", ioc->name)); |
| 3514 | fw_event->ignore = 1; |
| 3515 | } |
| 3516 | } |
| 3517 | } |
| 3518 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 3519 | } |
| 3520 | |
| 3521 | /** |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3522 | * _scsih_set_volume_delete_flag - setting volume delete flag |
| 3523 | * @ioc: per adapter object |
| 3524 | * @handle: device handle |
| 3525 | * |
| 3526 | * This |
| 3527 | * Return nothing. |
| 3528 | */ |
| 3529 | static void |
| 3530 | _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3531 | { |
| 3532 | struct _raid_device *raid_device; |
| 3533 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 3534 | unsigned long flags; |
| 3535 | |
| 3536 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 3537 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 3538 | if (raid_device && raid_device->starget && |
| 3539 | raid_device->starget->hostdata) { |
| 3540 | sas_target_priv_data = |
| 3541 | raid_device->starget->hostdata; |
| 3542 | sas_target_priv_data->deleted = 1; |
| 3543 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3544 | "setting delete flag: handle(0x%04x), " |
| 3545 | "wwid(0x%016llx)\n", ioc->name, handle, |
| 3546 | (unsigned long long) raid_device->wwid)); |
| 3547 | } |
| 3548 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 3549 | } |
| 3550 | |
| 3551 | /** |
| 3552 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume |
| 3553 | * @handle: input handle |
| 3554 | * @a: handle for volume a |
| 3555 | * @b: handle for volume b |
| 3556 | * |
| 3557 | * IR firmware only supports two raid volumes. The purpose of this |
| 3558 | * routine is to set the volume handle in either a or b. When the given |
| 3559 | * input handle is non-zero, or when a and b have not been set before. |
| 3560 | */ |
| 3561 | static void |
| 3562 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) |
| 3563 | { |
| 3564 | if (!handle || handle == *a || handle == *b) |
| 3565 | return; |
| 3566 | if (!*a) |
| 3567 | *a = handle; |
| 3568 | else if (!*b) |
| 3569 | *b = handle; |
| 3570 | } |
| 3571 | |
| 3572 | /** |
| 3573 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events |
| 3574 | * @ioc: per adapter object |
| 3575 | * @event_data: the event data payload |
| 3576 | * Context: interrupt time. |
| 3577 | * |
| 3578 | * This routine will send target reset to volume, followed by target |
| 3579 | * resets to the PDs. This is called when a PD has been removed, or |
| 3580 | * volume has been deleted or removed. When the target reset is sent |
| 3581 | * to volume, the PD target resets need to be queued to start upon |
| 3582 | * completion of the volume target reset. |
| 3583 | * |
| 3584 | * Return nothing. |
| 3585 | */ |
| 3586 | static void |
| 3587 | _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc, |
| 3588 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 3589 | { |
| 3590 | Mpi2EventIrConfigElement_t *element; |
| 3591 | int i; |
| 3592 | u16 handle, volume_handle, a, b; |
| 3593 | struct _tr_list *delayed_tr; |
| 3594 | |
| 3595 | a = 0; |
| 3596 | b = 0; |
| 3597 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3598 | if (ioc->is_warpdrive) |
| 3599 | return; |
| 3600 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3601 | /* Volume Resets for Deleted or Removed */ |
| 3602 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3603 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3604 | if (element->ReasonCode == |
| 3605 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || |
| 3606 | element->ReasonCode == |
| 3607 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { |
| 3608 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3609 | _scsih_set_volume_delete_flag(ioc, volume_handle); |
| 3610 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3611 | } |
| 3612 | } |
| 3613 | |
| 3614 | /* Volume Resets for UNHIDE events */ |
| 3615 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3616 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3617 | if (le32_to_cpu(event_data->Flags) & |
| 3618 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) |
| 3619 | continue; |
| 3620 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { |
| 3621 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3622 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3623 | } |
| 3624 | } |
| 3625 | |
| 3626 | if (a) |
| 3627 | _scsih_tm_tr_volume_send(ioc, a); |
| 3628 | if (b) |
| 3629 | _scsih_tm_tr_volume_send(ioc, b); |
| 3630 | |
| 3631 | /* PD target resets */ |
| 3632 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3633 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3634 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) |
| 3635 | continue; |
| 3636 | handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 3637 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3638 | clear_bit(handle, ioc->pd_handles); |
| 3639 | if (!volume_handle) |
| 3640 | _scsih_tm_tr_send(ioc, handle); |
| 3641 | else if (volume_handle == a || volume_handle == b) { |
| 3642 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3643 | BUG_ON(!delayed_tr); |
| 3644 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3645 | delayed_tr->handle = handle; |
| 3646 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 3647 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3648 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, |
| 3649 | handle)); |
| 3650 | } else |
| 3651 | _scsih_tm_tr_send(ioc, handle); |
| 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | |
| 3656 | /** |
| 3657 | * _scsih_check_volume_delete_events - set delete flag for volumes |
| 3658 | * @ioc: per adapter object |
| 3659 | * @event_data: the event data payload |
| 3660 | * Context: interrupt time. |
| 3661 | * |
| 3662 | * This will handle the case when the cable connected to entire volume is |
| 3663 | * pulled. We will take care of setting the deleted flag so normal IO will |
| 3664 | * not be sent. |
| 3665 | * |
| 3666 | * Return nothing. |
| 3667 | */ |
| 3668 | static void |
| 3669 | _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 3670 | Mpi2EventDataIrVolume_t *event_data) |
| 3671 | { |
| 3672 | u32 state; |
| 3673 | |
| 3674 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 3675 | return; |
| 3676 | state = le32_to_cpu(event_data->NewValue); |
| 3677 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == |
| 3678 | MPI2_RAID_VOL_STATE_FAILED) |
| 3679 | _scsih_set_volume_delete_flag(ioc, |
| 3680 | le16_to_cpu(event_data->VolDevHandle)); |
| 3681 | } |
| 3682 | |
| 3683 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3684 | * _scsih_flush_running_cmds - completing outstanding commands. |
| 3685 | * @ioc: per adapter object |
| 3686 | * |
| 3687 | * The flushing out of all pending scmd commands following host reset, |
| 3688 | * where all IO is dropped to the floor. |
| 3689 | * |
| 3690 | * Return nothing. |
| 3691 | */ |
| 3692 | static void |
| 3693 | _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc) |
| 3694 | { |
| 3695 | struct scsi_cmnd *scmd; |
| 3696 | u16 smid; |
| 3697 | u16 count = 0; |
| 3698 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3699 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 3700 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3701 | if (!scmd) |
| 3702 | continue; |
| 3703 | count++; |
| 3704 | mpt2sas_base_free_smid(ioc, smid); |
| 3705 | scsi_dma_unmap(scmd); |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3706 | if (ioc->pci_error_recovery) |
| 3707 | scmd->result = DID_NO_CONNECT << 16; |
| 3708 | else |
| 3709 | scmd->result = DID_RESET << 16; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3710 | scmd->scsi_done(scmd); |
| 3711 | } |
| 3712 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n", |
| 3713 | ioc->name, count)); |
| 3714 | } |
| 3715 | |
| 3716 | /** |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3717 | * _scsih_setup_eedp - setup MPI request for EEDP transfer |
| 3718 | * @scmd: pointer to scsi command object |
| 3719 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3720 | * |
| 3721 | * Supporting protection 1 and 3. |
| 3722 | * |
| 3723 | * Returns nothing |
| 3724 | */ |
| 3725 | static void |
| 3726 | _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request) |
| 3727 | { |
| 3728 | u16 eedp_flags; |
| 3729 | unsigned char prot_op = scsi_get_prot_op(scmd); |
| 3730 | unsigned char prot_type = scsi_get_prot_type(scmd); |
| 3731 | |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3732 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3733 | return; |
| 3734 | |
| 3735 | if (prot_op == SCSI_PROT_READ_STRIP) |
| 3736 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; |
| 3737 | else if (prot_op == SCSI_PROT_WRITE_INSERT) |
| 3738 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; |
| 3739 | else |
| 3740 | return; |
| 3741 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3742 | switch (prot_type) { |
| 3743 | case SCSI_PROT_DIF_TYPE1: |
Martin K. Petersen | 756aca7 | 2011-05-18 00:45:22 -0400 | [diff] [blame] | 3744 | case SCSI_PROT_DIF_TYPE2: |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3745 | |
| 3746 | /* |
| 3747 | * enable ref/guard checking |
| 3748 | * auto increment ref tag |
| 3749 | */ |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3750 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3751 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | |
| 3752 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
| 3753 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = |
| 3754 | cpu_to_be32(scsi_get_lba(scmd)); |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3755 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3756 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3757 | case SCSI_PROT_DIF_TYPE3: |
| 3758 | |
| 3759 | /* |
| 3760 | * enable guard checking |
| 3761 | */ |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3762 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3763 | break; |
| 3764 | } |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3765 | mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size); |
| 3766 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | /** |
| 3770 | * _scsih_eedp_error_handling - return sense code for EEDP errors |
| 3771 | * @scmd: pointer to scsi command object |
| 3772 | * @ioc_status: ioc status |
| 3773 | * |
| 3774 | * Returns nothing |
| 3775 | */ |
| 3776 | static void |
| 3777 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) |
| 3778 | { |
| 3779 | u8 ascq; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3780 | |
| 3781 | switch (ioc_status) { |
| 3782 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 3783 | ascq = 0x01; |
| 3784 | break; |
| 3785 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 3786 | ascq = 0x02; |
| 3787 | break; |
| 3788 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 3789 | ascq = 0x03; |
| 3790 | break; |
| 3791 | default: |
| 3792 | ascq = 0x00; |
| 3793 | break; |
| 3794 | } |
| 3795 | |
Martin K. Petersen | 9b5cd13 | 2012-08-28 14:29:36 -0400 | [diff] [blame] | 3796 | scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq); |
| 3797 | scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3798 | SAM_STAT_CHECK_CONDITION; |
| 3799 | } |
| 3800 | |
| 3801 | /** |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3802 | * _scsih_scsi_direct_io_get - returns direct io flag |
| 3803 | * @ioc: per adapter object |
| 3804 | * @smid: system request message index |
| 3805 | * |
| 3806 | * Returns the smid stored scmd pointer. |
| 3807 | */ |
| 3808 | static inline u8 |
| 3809 | _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 3810 | { |
| 3811 | return ioc->scsi_lookup[smid - 1].direct_io; |
| 3812 | } |
| 3813 | |
| 3814 | /** |
| 3815 | * _scsih_scsi_direct_io_set - sets direct io flag |
| 3816 | * @ioc: per adapter object |
| 3817 | * @smid: system request message index |
| 3818 | * @direct_io: Zero or non-zero value to set in the direct_io flag |
| 3819 | * |
| 3820 | * Returns Nothing. |
| 3821 | */ |
| 3822 | static inline void |
| 3823 | _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io) |
| 3824 | { |
| 3825 | ioc->scsi_lookup[smid - 1].direct_io = direct_io; |
| 3826 | } |
| 3827 | |
| 3828 | |
| 3829 | /** |
| 3830 | * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O |
| 3831 | * @ioc: per adapter object |
| 3832 | * @scmd: pointer to scsi command object |
| 3833 | * @raid_device: pointer to raid device data structure |
| 3834 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3835 | * @smid: system request message index |
| 3836 | * |
| 3837 | * Returns nothing |
| 3838 | */ |
| 3839 | static void |
| 3840 | _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 3841 | struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request, |
| 3842 | u16 smid) |
| 3843 | { |
| 3844 | u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size; |
| 3845 | u32 stripe_sz, stripe_exp; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3846 | u8 num_pds, *cdb_ptr, i; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3847 | u8 cdb0 = scmd->cmnd[0]; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3848 | u64 v_llba; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3849 | |
| 3850 | /* |
| 3851 | * Try Direct I/O to RAID memeber disks |
| 3852 | */ |
| 3853 | if (cdb0 == READ_16 || cdb0 == READ_10 || |
| 3854 | cdb0 == WRITE_16 || cdb0 == WRITE_10) { |
| 3855 | cdb_ptr = mpi_request->CDB.CDB32; |
| 3856 | |
| 3857 | if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4] |
| 3858 | | cdb_ptr[5])) { |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3859 | io_size = scsi_bufflen(scmd) >> |
| 3860 | raid_device->block_exponent; |
| 3861 | i = (cdb0 < READ_16) ? 2 : 6; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3862 | /* get virtual lba */ |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3863 | v_lba = be32_to_cpu(*(__be32 *)(&cdb_ptr[i])); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3864 | |
| 3865 | if (((u64)v_lba + (u64)io_size - 1) <= |
| 3866 | (u32)raid_device->max_lba) { |
| 3867 | stripe_sz = raid_device->stripe_sz; |
| 3868 | stripe_exp = raid_device->stripe_exponent; |
| 3869 | stripe_off = v_lba & (stripe_sz - 1); |
| 3870 | |
| 3871 | /* Check whether IO falls within a stripe */ |
| 3872 | if ((stripe_off + io_size) <= stripe_sz) { |
| 3873 | num_pds = raid_device->num_pds; |
| 3874 | p_lba = v_lba >> stripe_exp; |
| 3875 | stripe_unit = p_lba / num_pds; |
| 3876 | column = p_lba % num_pds; |
| 3877 | p_lba = (stripe_unit << stripe_exp) + |
| 3878 | stripe_off; |
| 3879 | mpi_request->DevHandle = |
| 3880 | cpu_to_le16(raid_device-> |
| 3881 | pd_handle[column]); |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3882 | (*(__be32 *)(&cdb_ptr[i])) = |
| 3883 | cpu_to_be32(p_lba); |
| 3884 | /* |
| 3885 | * WD: To indicate this I/O is directI/O |
| 3886 | */ |
| 3887 | _scsih_scsi_direct_io_set(ioc, smid, 1); |
| 3888 | } |
| 3889 | } |
| 3890 | } else { |
| 3891 | io_size = scsi_bufflen(scmd) >> |
| 3892 | raid_device->block_exponent; |
| 3893 | /* get virtual lba */ |
| 3894 | v_llba = be64_to_cpu(*(__be64 *)(&cdb_ptr[2])); |
| 3895 | |
| 3896 | if ((v_llba + (u64)io_size - 1) <= |
| 3897 | raid_device->max_lba) { |
| 3898 | stripe_sz = raid_device->stripe_sz; |
| 3899 | stripe_exp = raid_device->stripe_exponent; |
| 3900 | stripe_off = (u32) (v_llba & (stripe_sz - 1)); |
| 3901 | |
| 3902 | /* Check whether IO falls within a stripe */ |
| 3903 | if ((stripe_off + io_size) <= stripe_sz) { |
| 3904 | num_pds = raid_device->num_pds; |
| 3905 | p_lba = (u32)(v_llba >> stripe_exp); |
| 3906 | stripe_unit = p_lba / num_pds; |
| 3907 | column = p_lba % num_pds; |
| 3908 | p_lba = (stripe_unit << stripe_exp) + |
| 3909 | stripe_off; |
| 3910 | mpi_request->DevHandle = |
| 3911 | cpu_to_le16(raid_device-> |
| 3912 | pd_handle[column]); |
| 3913 | (*(__be64 *)(&cdb_ptr[2])) = |
| 3914 | cpu_to_be64((u64)p_lba); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3915 | /* |
| 3916 | * WD: To indicate this I/O is directI/O |
| 3917 | */ |
| 3918 | _scsih_scsi_direct_io_set(ioc, smid, 1); |
| 3919 | } |
| 3920 | } |
| 3921 | } |
| 3922 | } |
| 3923 | } |
| 3924 | |
| 3925 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 3926 | * _scsih_qcmd - main scsi request entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3927 | * @scmd: pointer to scsi command object |
| 3928 | * @done: function pointer to be invoked on completion |
| 3929 | * |
| 3930 | * The callback index is set inside `ioc->scsi_io_cb_idx`. |
| 3931 | * |
| 3932 | * Returns 0 on success. If there's a failure, return either: |
| 3933 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or |
| 3934 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full |
| 3935 | */ |
| 3936 | static int |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 3937 | _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3938 | { |
| 3939 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 3940 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 3941 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3942 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3943 | Mpi2SCSIIORequest_t *mpi_request; |
| 3944 | u32 mpi_control; |
| 3945 | u16 smid; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3946 | |
| 3947 | scmd->scsi_done = done; |
| 3948 | sas_device_priv_data = scmd->device->hostdata; |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3949 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3950 | scmd->result = DID_NO_CONNECT << 16; |
| 3951 | scmd->scsi_done(scmd); |
| 3952 | return 0; |
| 3953 | } |
| 3954 | |
Kashyap, Desai | 7821578 | 2011-06-14 10:57:08 +0530 | [diff] [blame] | 3955 | if (ioc->pci_error_recovery || ioc->remove_host) { |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3956 | scmd->result = DID_NO_CONNECT << 16; |
| 3957 | scmd->scsi_done(scmd); |
| 3958 | return 0; |
| 3959 | } |
| 3960 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3961 | sas_target_priv_data = sas_device_priv_data->sas_target; |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3962 | /* invalid device handle */ |
| 3963 | if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3964 | scmd->result = DID_NO_CONNECT << 16; |
| 3965 | scmd->scsi_done(scmd); |
| 3966 | return 0; |
| 3967 | } |
| 3968 | |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3969 | /* host recovery or link resets sent via IOCTLs */ |
| 3970 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3971 | return SCSI_MLQUEUE_HOST_BUSY; |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 3972 | /* device busy with task management */ |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3973 | else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy) |
| 3974 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 3975 | /* device has been deleted */ |
| 3976 | else if (sas_target_priv_data->deleted) { |
| 3977 | scmd->result = DID_NO_CONNECT << 16; |
| 3978 | scmd->scsi_done(scmd); |
| 3979 | return 0; |
| 3980 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3981 | |
| 3982 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) |
| 3983 | mpi_control = MPI2_SCSIIO_CONTROL_READ; |
| 3984 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 3985 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; |
| 3986 | else |
| 3987 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; |
| 3988 | |
| 3989 | /* set tags */ |
| 3990 | if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) { |
| 3991 | if (scmd->device->tagged_supported) { |
| 3992 | if (scmd->device->ordered_tags) |
| 3993 | mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ; |
| 3994 | else |
| 3995 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
| 3996 | } else |
| 3997 | /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */ |
| 3998 | /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED; |
| 3999 | */ |
| 4000 | mpi_control |= (0x500); |
| 4001 | |
| 4002 | } else |
| 4003 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4004 | /* Make sure Device is not raid volume. |
| 4005 | * We do not expose raid functionality to upper layer for warpdrive. |
| 4006 | */ |
| 4007 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 4008 | sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4009 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
| 4010 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 4011 | 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] | 4012 | if (!smid) { |
| 4013 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 4014 | ioc->name, __func__); |
| 4015 | goto out; |
| 4016 | } |
| 4017 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 4018 | memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t)); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4019 | _scsih_setup_eedp(scmd, mpi_request); |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 4020 | if (scmd->cmd_len == 32) |
| 4021 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4022 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 4023 | if (sas_device_priv_data->sas_target->flags & |
| 4024 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 4025 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; |
| 4026 | else |
| 4027 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 4028 | mpi_request->DevHandle = |
| 4029 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 4030 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
| 4031 | mpi_request->Control = cpu_to_le32(mpi_control); |
| 4032 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); |
| 4033 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; |
| 4034 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; |
| 4035 | mpi_request->SenseBufferLowAddress = |
Kashyap, Desai | ec9472c | 2009-09-23 17:34:13 +0530 | [diff] [blame] | 4036 | mpt2sas_base_get_sense_buffer_dma(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4037 | mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4; |
| 4038 | mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI + |
| 4039 | MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4040 | mpi_request->VF_ID = 0; /* TODO */ |
| 4041 | mpi_request->VP_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4042 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
| 4043 | mpi_request->LUN); |
| 4044 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 4045 | |
| 4046 | if (!mpi_request->DataLength) { |
| 4047 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL); |
| 4048 | } else { |
| 4049 | if (_scsih_build_scatter_gather(ioc, scmd, smid)) { |
| 4050 | mpt2sas_base_free_smid(ioc, smid); |
| 4051 | goto out; |
| 4052 | } |
| 4053 | } |
| 4054 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4055 | raid_device = sas_target_priv_data->raid_device; |
| 4056 | if (raid_device && raid_device->direct_io_enabled) |
| 4057 | _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request, |
| 4058 | smid); |
| 4059 | |
Kashyap, Desai | 58287fd | 2010-03-17 16:27:25 +0530 | [diff] [blame] | 4060 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) |
| 4061 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4062 | le16_to_cpu(mpi_request->DevHandle)); |
Kashyap, Desai | 58287fd | 2010-03-17 16:27:25 +0530 | [diff] [blame] | 4063 | else |
| 4064 | mpt2sas_base_put_smid_default(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4065 | return 0; |
| 4066 | |
| 4067 | out: |
| 4068 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4069 | } |
| 4070 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 4071 | static DEF_SCSI_QCMD(_scsih_qcmd) |
| 4072 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4073 | /** |
| 4074 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data |
| 4075 | * @sense_buffer: sense data returned by target |
| 4076 | * @data: normalized skey/asc/ascq |
| 4077 | * |
| 4078 | * Return nothing. |
| 4079 | */ |
| 4080 | static void |
| 4081 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) |
| 4082 | { |
| 4083 | if ((sense_buffer[0] & 0x7F) >= 0x72) { |
| 4084 | /* descriptor format */ |
| 4085 | data->skey = sense_buffer[1] & 0x0F; |
| 4086 | data->asc = sense_buffer[2]; |
| 4087 | data->ascq = sense_buffer[3]; |
| 4088 | } else { |
| 4089 | /* fixed format */ |
| 4090 | data->skey = sense_buffer[2] & 0x0F; |
| 4091 | data->asc = sense_buffer[12]; |
| 4092 | data->ascq = sense_buffer[13]; |
| 4093 | } |
| 4094 | } |
| 4095 | |
| 4096 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4097 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4098 | * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4099 | * @ioc: per adapter object |
| 4100 | * @scmd: pointer to scsi command object |
| 4101 | * @mpi_reply: reply mf payload returned from firmware |
| 4102 | * |
| 4103 | * scsi_status - SCSI Status code returned from target device |
| 4104 | * scsi_state - state info associated with SCSI_IO determined by ioc |
| 4105 | * ioc_status - ioc supplied status info |
| 4106 | * |
| 4107 | * Return nothing. |
| 4108 | */ |
| 4109 | static void |
| 4110 | _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 4111 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) |
| 4112 | { |
| 4113 | u32 response_info; |
| 4114 | u8 *response_bytes; |
| 4115 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & |
| 4116 | MPI2_IOCSTATUS_MASK; |
| 4117 | u8 scsi_state = mpi_reply->SCSIState; |
| 4118 | u8 scsi_status = mpi_reply->SCSIStatus; |
| 4119 | char *desc_ioc_state = NULL; |
| 4120 | char *desc_scsi_status = NULL; |
| 4121 | char *desc_scsi_state = ioc->tmp_string; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4122 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4123 | struct _sas_device *sas_device = NULL; |
| 4124 | unsigned long flags; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4125 | struct scsi_target *starget = scmd->device->sdev_target; |
| 4126 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4127 | char *device_str = NULL; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4128 | |
| 4129 | if (!priv_target) |
| 4130 | return; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4131 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4132 | if (ioc->hide_ir_msg) |
| 4133 | device_str = "WarpDrive"; |
| 4134 | else |
| 4135 | device_str = "volume"; |
| 4136 | |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4137 | if (log_info == 0x31170000) |
| 4138 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4139 | |
| 4140 | switch (ioc_status) { |
| 4141 | case MPI2_IOCSTATUS_SUCCESS: |
| 4142 | desc_ioc_state = "success"; |
| 4143 | break; |
| 4144 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 4145 | desc_ioc_state = "invalid function"; |
| 4146 | break; |
| 4147 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 4148 | desc_ioc_state = "scsi recovered error"; |
| 4149 | break; |
| 4150 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: |
| 4151 | desc_ioc_state = "scsi invalid dev handle"; |
| 4152 | break; |
| 4153 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 4154 | desc_ioc_state = "scsi device not there"; |
| 4155 | break; |
| 4156 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 4157 | desc_ioc_state = "scsi data overrun"; |
| 4158 | break; |
| 4159 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 4160 | desc_ioc_state = "scsi data underrun"; |
| 4161 | break; |
| 4162 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 4163 | desc_ioc_state = "scsi io data error"; |
| 4164 | break; |
| 4165 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 4166 | desc_ioc_state = "scsi protocol error"; |
| 4167 | break; |
| 4168 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 4169 | desc_ioc_state = "scsi task terminated"; |
| 4170 | break; |
| 4171 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 4172 | desc_ioc_state = "scsi residual mismatch"; |
| 4173 | break; |
| 4174 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 4175 | desc_ioc_state = "scsi task mgmt failed"; |
| 4176 | break; |
| 4177 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 4178 | desc_ioc_state = "scsi ioc terminated"; |
| 4179 | break; |
| 4180 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 4181 | desc_ioc_state = "scsi ext terminated"; |
| 4182 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4183 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 4184 | desc_ioc_state = "eedp guard error"; |
| 4185 | break; |
| 4186 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 4187 | desc_ioc_state = "eedp ref tag error"; |
| 4188 | break; |
| 4189 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 4190 | desc_ioc_state = "eedp app tag error"; |
| 4191 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4192 | default: |
| 4193 | desc_ioc_state = "unknown"; |
| 4194 | break; |
| 4195 | } |
| 4196 | |
| 4197 | switch (scsi_status) { |
| 4198 | case MPI2_SCSI_STATUS_GOOD: |
| 4199 | desc_scsi_status = "good"; |
| 4200 | break; |
| 4201 | case MPI2_SCSI_STATUS_CHECK_CONDITION: |
| 4202 | desc_scsi_status = "check condition"; |
| 4203 | break; |
| 4204 | case MPI2_SCSI_STATUS_CONDITION_MET: |
| 4205 | desc_scsi_status = "condition met"; |
| 4206 | break; |
| 4207 | case MPI2_SCSI_STATUS_BUSY: |
| 4208 | desc_scsi_status = "busy"; |
| 4209 | break; |
| 4210 | case MPI2_SCSI_STATUS_INTERMEDIATE: |
| 4211 | desc_scsi_status = "intermediate"; |
| 4212 | break; |
| 4213 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: |
| 4214 | desc_scsi_status = "intermediate condmet"; |
| 4215 | break; |
| 4216 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: |
| 4217 | desc_scsi_status = "reservation conflict"; |
| 4218 | break; |
| 4219 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: |
| 4220 | desc_scsi_status = "command terminated"; |
| 4221 | break; |
| 4222 | case MPI2_SCSI_STATUS_TASK_SET_FULL: |
| 4223 | desc_scsi_status = "task set full"; |
| 4224 | break; |
| 4225 | case MPI2_SCSI_STATUS_ACA_ACTIVE: |
| 4226 | desc_scsi_status = "aca active"; |
| 4227 | break; |
| 4228 | case MPI2_SCSI_STATUS_TASK_ABORTED: |
| 4229 | desc_scsi_status = "task aborted"; |
| 4230 | break; |
| 4231 | default: |
| 4232 | desc_scsi_status = "unknown"; |
| 4233 | break; |
| 4234 | } |
| 4235 | |
| 4236 | desc_scsi_state[0] = '\0'; |
| 4237 | if (!scsi_state) |
| 4238 | desc_scsi_state = " "; |
| 4239 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 4240 | strcat(desc_scsi_state, "response info "); |
| 4241 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4242 | strcat(desc_scsi_state, "state terminated "); |
| 4243 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) |
| 4244 | strcat(desc_scsi_state, "no status "); |
| 4245 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) |
| 4246 | strcat(desc_scsi_state, "autosense failed "); |
| 4247 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) |
| 4248 | strcat(desc_scsi_state, "autosense valid "); |
| 4249 | |
| 4250 | scsi_print_command(scmd); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4251 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4252 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4253 | printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name, |
| 4254 | device_str, (unsigned long long)priv_target->sas_address); |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4255 | } else { |
| 4256 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4257 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 4258 | priv_target->sas_address); |
| 4259 | if (sas_device) { |
| 4260 | printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), " |
| 4261 | "phy(%d)\n", ioc->name, sas_device->sas_address, |
| 4262 | sas_device->phy); |
| 4263 | printk(MPT2SAS_WARN_FMT |
| 4264 | "\tenclosure_logical_id(0x%016llx), slot(%d)\n", |
| 4265 | ioc->name, sas_device->enclosure_logical_id, |
| 4266 | sas_device->slot); |
| 4267 | } |
| 4268 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4269 | } |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4270 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4271 | printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), " |
| 4272 | "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle), |
| 4273 | desc_ioc_state, ioc_status, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4274 | printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), " |
| 4275 | "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow, |
| 4276 | scsi_get_resid(scmd)); |
| 4277 | printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), " |
| 4278 | "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag), |
| 4279 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); |
| 4280 | printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), " |
| 4281 | "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status, |
| 4282 | scsi_status, desc_scsi_state, scsi_state); |
| 4283 | |
| 4284 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4285 | struct sense_info data; |
| 4286 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4287 | printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: " |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 4288 | "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey, |
| 4289 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { |
| 4293 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); |
| 4294 | response_bytes = (u8 *)&response_info; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4295 | _scsih_response_code(ioc, response_bytes[0]); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4296 | } |
| 4297 | } |
| 4298 | #endif |
| 4299 | |
| 4300 | /** |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4301 | * _scsih_turn_on_fault_led - illuminate Fault LED |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4302 | * @ioc: per adapter object |
| 4303 | * @handle: device handle |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4304 | * Context: process |
| 4305 | * |
| 4306 | * Return nothing. |
| 4307 | */ |
| 4308 | static void |
| 4309 | _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4310 | { |
| 4311 | Mpi2SepReply_t mpi_reply; |
| 4312 | Mpi2SepRequest_t mpi_request; |
| 4313 | |
| 4314 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
| 4315 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; |
| 4316 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; |
| 4317 | mpi_request.SlotStatus = |
| 4318 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); |
| 4319 | mpi_request.DevHandle = cpu_to_le16(handle); |
| 4320 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; |
| 4321 | if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply, |
| 4322 | &mpi_request)) != 0) { |
| 4323 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 4324 | __FILE__, __LINE__, __func__); |
| 4325 | return; |
| 4326 | } |
| 4327 | |
| 4328 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { |
| 4329 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: " |
| 4330 | "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name, |
| 4331 | le16_to_cpu(mpi_reply.IOCStatus), |
| 4332 | le32_to_cpu(mpi_reply.IOCLogInfo))); |
| 4333 | return; |
| 4334 | } |
| 4335 | } |
| 4336 | |
| 4337 | /** |
| 4338 | * _scsih_send_event_to_turn_on_fault_led - fire delayed event |
| 4339 | * @ioc: per adapter object |
| 4340 | * @handle: device handle |
| 4341 | * Context: interrupt. |
| 4342 | * |
| 4343 | * Return nothing. |
| 4344 | */ |
| 4345 | static void |
| 4346 | _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4347 | { |
| 4348 | struct fw_event_work *fw_event; |
| 4349 | |
| 4350 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 4351 | if (!fw_event) |
| 4352 | return; |
| 4353 | fw_event->event = MPT2SAS_TURN_ON_FAULT_LED; |
| 4354 | fw_event->device_handle = handle; |
| 4355 | fw_event->ioc = ioc; |
| 4356 | _scsih_fw_event_add(ioc, fw_event); |
| 4357 | } |
| 4358 | |
| 4359 | /** |
| 4360 | * _scsih_smart_predicted_fault - process smart errors |
| 4361 | * @ioc: per adapter object |
| 4362 | * @handle: device handle |
| 4363 | * Context: interrupt. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4364 | * |
| 4365 | * Return nothing. |
| 4366 | */ |
| 4367 | static void |
| 4368 | _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4369 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4370 | struct scsi_target *starget; |
| 4371 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 4372 | Mpi2EventNotificationReply_t *event_reply; |
| 4373 | Mpi2EventDataSasDeviceStatusChange_t *event_data; |
| 4374 | struct _sas_device *sas_device; |
| 4375 | ssize_t sz; |
| 4376 | unsigned long flags; |
| 4377 | |
| 4378 | /* only handle non-raid devices */ |
| 4379 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4380 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 4381 | if (!sas_device) { |
| 4382 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4383 | return; |
| 4384 | } |
| 4385 | starget = sas_device->starget; |
| 4386 | sas_target_priv_data = starget->hostdata; |
| 4387 | |
| 4388 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || |
| 4389 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) { |
| 4390 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4391 | return; |
| 4392 | } |
| 4393 | starget_printk(KERN_WARNING, starget, "predicted fault\n"); |
| 4394 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4395 | |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4396 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) |
| 4397 | _scsih_send_event_to_turn_on_fault_led(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4398 | |
| 4399 | /* insert into event log */ |
| 4400 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + |
| 4401 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); |
Anton Blanchard | f6a290b4 | 2011-11-07 22:05:21 +1100 | [diff] [blame] | 4402 | event_reply = kzalloc(sz, GFP_ATOMIC); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4403 | if (!event_reply) { |
| 4404 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4405 | ioc->name, __FILE__, __LINE__, __func__); |
| 4406 | return; |
| 4407 | } |
| 4408 | |
| 4409 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; |
| 4410 | event_reply->Event = |
| 4411 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); |
| 4412 | event_reply->MsgLength = sz/4; |
| 4413 | event_reply->EventDataLength = |
| 4414 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); |
| 4415 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) |
| 4416 | event_reply->EventData; |
| 4417 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; |
| 4418 | event_data->ASC = 0x5D; |
| 4419 | event_data->DevHandle = cpu_to_le16(handle); |
| 4420 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); |
| 4421 | mpt2sas_ctl_add_to_event_log(ioc, event_reply); |
| 4422 | kfree(event_reply); |
| 4423 | } |
| 4424 | |
| 4425 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 4426 | * _scsih_io_done - scsi request callback |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4427 | * @ioc: per adapter object |
| 4428 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4429 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4430 | * @reply: reply message frame(lower 32bit addr) |
| 4431 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4432 | * Callback handler when using _scsih_qcmd. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4433 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4434 | * Return 1 meaning mf should be freed from _base_interrupt |
| 4435 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4436 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4437 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4438 | _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] | 4439 | { |
| 4440 | Mpi2SCSIIORequest_t *mpi_request; |
| 4441 | Mpi2SCSIIOReply_t *mpi_reply; |
| 4442 | struct scsi_cmnd *scmd; |
| 4443 | u16 ioc_status; |
| 4444 | u32 xfer_cnt; |
| 4445 | u8 scsi_state; |
| 4446 | u8 scsi_status; |
| 4447 | u32 log_info; |
| 4448 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4449 | u32 response_code = 0; |
Kashyap, Desai | 82a4525 | 2011-07-05 12:40:23 +0530 | [diff] [blame] | 4450 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4451 | |
| 4452 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 4453 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4454 | if (scmd == NULL) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4455 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4456 | |
| 4457 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 4458 | |
| 4459 | if (mpi_reply == NULL) { |
| 4460 | scmd->result = DID_OK << 16; |
| 4461 | goto out; |
| 4462 | } |
| 4463 | |
| 4464 | sas_device_priv_data = scmd->device->hostdata; |
| 4465 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
| 4466 | sas_device_priv_data->sas_target->deleted) { |
| 4467 | scmd->result = DID_NO_CONNECT << 16; |
| 4468 | goto out; |
| 4469 | } |
nagalakshmi.nandigama@lsi.com | 4da7af9 | 2011-12-01 07:53:02 +0530 | [diff] [blame] | 4470 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4471 | /* |
| 4472 | * WARPDRIVE: If direct_io is set then it is directIO, |
| 4473 | * the failed direct I/O should be redirected to volume |
| 4474 | */ |
nagalakshmi.nandigama@lsi.com | 4da7af9 | 2011-12-01 07:53:02 +0530 | [diff] [blame] | 4475 | if (_scsih_scsi_direct_io_get(ioc, smid) && |
| 4476 | ((ioc_status & MPI2_IOCSTATUS_MASK) |
| 4477 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { |
Kashyap, Desai | 82a4525 | 2011-07-05 12:40:23 +0530 | [diff] [blame] | 4478 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 4479 | ioc->scsi_lookup[smid - 1].scmd = scmd; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4480 | _scsih_scsi_direct_io_set(ioc, smid, 0); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 4481 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4482 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 4483 | mpi_request->DevHandle = |
| 4484 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 4485 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
| 4486 | sas_device_priv_data->sas_target->handle); |
| 4487 | return 0; |
| 4488 | } |
| 4489 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4490 | |
| 4491 | /* turning off TLR */ |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4492 | scsi_state = mpi_reply->SCSIState; |
| 4493 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 4494 | response_code = |
| 4495 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4496 | if (!sas_device_priv_data->tlr_snoop_check) { |
| 4497 | sas_device_priv_data->tlr_snoop_check++; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4498 | /* Make sure Device is not raid volume. |
| 4499 | * We do not expose raid functionality to upper layer for warpdrive. |
| 4500 | */ |
| 4501 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && |
Kashyap, Desai | 3ed2152 | 2010-02-17 16:08:36 +0530 | [diff] [blame] | 4502 | sas_is_tlr_enabled(scmd->device) && |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 4503 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { |
| 4504 | sas_disable_tlr(scmd->device); |
| 4505 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); |
| 4506 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4507 | } |
| 4508 | |
| 4509 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); |
| 4510 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4511 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) |
| 4512 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
| 4513 | else |
| 4514 | log_info = 0; |
| 4515 | ioc_status &= MPI2_IOCSTATUS_MASK; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4516 | scsi_status = mpi_reply->SCSIStatus; |
| 4517 | |
| 4518 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && |
| 4519 | (scsi_status == MPI2_SCSI_STATUS_BUSY || |
| 4520 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || |
| 4521 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { |
| 4522 | ioc_status = MPI2_IOCSTATUS_SUCCESS; |
| 4523 | } |
| 4524 | |
| 4525 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4526 | struct sense_info data; |
| 4527 | const void *sense_data = mpt2sas_base_get_sense_buffer(ioc, |
| 4528 | smid); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 4529 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4530 | le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 4531 | memcpy(scmd->sense_buffer, sense_data, sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4532 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4533 | /* failure prediction threshold exceeded */ |
| 4534 | if (data.asc == 0x5D) |
| 4535 | _scsih_smart_predicted_fault(ioc, |
| 4536 | le16_to_cpu(mpi_reply->DevHandle)); |
| 4537 | } |
| 4538 | |
| 4539 | switch (ioc_status) { |
| 4540 | case MPI2_IOCSTATUS_BUSY: |
| 4541 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: |
| 4542 | scmd->result = SAM_STAT_BUSY; |
| 4543 | break; |
| 4544 | |
| 4545 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 4546 | scmd->result = DID_NO_CONNECT << 16; |
| 4547 | break; |
| 4548 | |
| 4549 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 4550 | if (sas_device_priv_data->block) { |
Kashyap, Desai | e4e7c7e | 2009-09-23 17:33:14 +0530 | [diff] [blame] | 4551 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; |
| 4552 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4553 | } |
nagalakshmi.nandigama@lsi.com | 3ade1ca | 2011-12-01 07:42:40 +0530 | [diff] [blame] | 4554 | scmd->result = DID_SOFT_ERROR << 16; |
| 4555 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4556 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 4557 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 4558 | scmd->result = DID_RESET << 16; |
| 4559 | break; |
| 4560 | |
| 4561 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 4562 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) |
| 4563 | scmd->result = DID_SOFT_ERROR << 16; |
| 4564 | else |
| 4565 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4566 | break; |
| 4567 | |
| 4568 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 4569 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4570 | |
| 4571 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) |
| 4572 | break; |
| 4573 | |
| 4574 | if (xfer_cnt < scmd->underflow) { |
| 4575 | if (scsi_status == SAM_STAT_BUSY) |
| 4576 | scmd->result = SAM_STAT_BUSY; |
| 4577 | else |
| 4578 | scmd->result = DID_SOFT_ERROR << 16; |
| 4579 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4580 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) |
| 4581 | scmd->result = DID_SOFT_ERROR << 16; |
| 4582 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4583 | scmd->result = DID_RESET << 16; |
| 4584 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { |
| 4585 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; |
| 4586 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; |
| 4587 | scmd->result = (DRIVER_SENSE << 24) | |
| 4588 | SAM_STAT_CHECK_CONDITION; |
| 4589 | scmd->sense_buffer[0] = 0x70; |
| 4590 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; |
| 4591 | scmd->sense_buffer[12] = 0x20; |
| 4592 | scmd->sense_buffer[13] = 0; |
| 4593 | } |
| 4594 | break; |
| 4595 | |
| 4596 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 4597 | scsi_set_resid(scmd, 0); |
| 4598 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 4599 | case MPI2_IOCSTATUS_SUCCESS: |
| 4600 | scmd->result = (DID_OK << 16) | scsi_status; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4601 | if (response_code == |
| 4602 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || |
| 4603 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4604 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4605 | scmd->result = DID_SOFT_ERROR << 16; |
| 4606 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4607 | scmd->result = DID_RESET << 16; |
| 4608 | break; |
| 4609 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4610 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 4611 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 4612 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 4613 | _scsih_eedp_error_handling(scmd, ioc_status); |
| 4614 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4615 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 4616 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 4617 | case MPI2_IOCSTATUS_INVALID_SGL: |
| 4618 | case MPI2_IOCSTATUS_INTERNAL_ERROR: |
| 4619 | case MPI2_IOCSTATUS_INVALID_FIELD: |
| 4620 | case MPI2_IOCSTATUS_INVALID_STATE: |
| 4621 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 4622 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 4623 | default: |
| 4624 | scmd->result = DID_SOFT_ERROR << 16; |
| 4625 | break; |
| 4626 | |
| 4627 | } |
| 4628 | |
| 4629 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4630 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
| 4631 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); |
| 4632 | #endif |
| 4633 | |
| 4634 | out: |
| 4635 | scsi_dma_unmap(scmd); |
| 4636 | scmd->scsi_done(scmd); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4637 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4638 | } |
| 4639 | |
| 4640 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4641 | * _scsih_sas_host_refresh - refreshing sas host object contents |
| 4642 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4643 | * Context: user |
| 4644 | * |
| 4645 | * During port enable, fw will send topology events for every device. Its |
| 4646 | * possible that the handles may change from the previous setting, so this |
| 4647 | * code keeping handles updating if changed. |
| 4648 | * |
| 4649 | * Return nothing. |
| 4650 | */ |
| 4651 | static void |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4652 | _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4653 | { |
| 4654 | u16 sz; |
| 4655 | u16 ioc_status; |
| 4656 | int i; |
| 4657 | Mpi2ConfigReply_t mpi_reply; |
| 4658 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4659 | u16 attached_handle; |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4660 | u8 link_rate; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4661 | |
| 4662 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 4663 | "updating handles for sas_host(0x%016llx)\n", |
| 4664 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); |
| 4665 | |
| 4666 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys |
| 4667 | * sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4668 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4669 | if (!sas_iounit_pg0) { |
| 4670 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4671 | ioc->name, __FILE__, __LINE__, __func__); |
| 4672 | return; |
| 4673 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4674 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4675 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4676 | sas_iounit_pg0, sz)) != 0) |
| 4677 | goto out; |
| 4678 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 4679 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 4680 | goto out; |
| 4681 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4682 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4683 | if (i == 0) |
| 4684 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4685 | PhyData[0].ControllerDevHandle); |
| 4686 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
| 4687 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. |
| 4688 | AttachedDevHandle); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4689 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 4690 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4691 | mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address, |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4692 | attached_handle, i, link_rate); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4693 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4694 | out: |
| 4695 | kfree(sas_iounit_pg0); |
| 4696 | } |
| 4697 | |
| 4698 | /** |
| 4699 | * _scsih_sas_host_add - create sas host object |
| 4700 | * @ioc: per adapter object |
| 4701 | * |
| 4702 | * Creating host side data object, stored in ioc->sas_hba |
| 4703 | * |
| 4704 | * Return nothing. |
| 4705 | */ |
| 4706 | static void |
| 4707 | _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc) |
| 4708 | { |
| 4709 | int i; |
| 4710 | Mpi2ConfigReply_t mpi_reply; |
| 4711 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
| 4712 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; |
| 4713 | Mpi2SasPhyPage0_t phy_pg0; |
| 4714 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4715 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4716 | u16 ioc_status; |
| 4717 | u16 sz; |
| 4718 | u16 device_missing_delay; |
| 4719 | |
| 4720 | mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys); |
| 4721 | if (!ioc->sas_hba.num_phys) { |
| 4722 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4723 | ioc->name, __FILE__, __LINE__, __func__); |
| 4724 | return; |
| 4725 | } |
| 4726 | |
| 4727 | /* sas_iounit page 0 */ |
| 4728 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4729 | sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4730 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4731 | if (!sas_iounit_pg0) { |
| 4732 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4733 | ioc->name, __FILE__, __LINE__, __func__); |
| 4734 | return; |
| 4735 | } |
| 4736 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4737 | sas_iounit_pg0, sz))) { |
| 4738 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4739 | ioc->name, __FILE__, __LINE__, __func__); |
| 4740 | goto out; |
| 4741 | } |
| 4742 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4743 | MPI2_IOCSTATUS_MASK; |
| 4744 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4745 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4746 | ioc->name, __FILE__, __LINE__, __func__); |
| 4747 | goto out; |
| 4748 | } |
| 4749 | |
| 4750 | /* sas_iounit page 1 */ |
| 4751 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4752 | sizeof(Mpi2SasIOUnit1PhyData_t)); |
| 4753 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); |
| 4754 | if (!sas_iounit_pg1) { |
| 4755 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4756 | ioc->name, __FILE__, __LINE__, __func__); |
| 4757 | goto out; |
| 4758 | } |
| 4759 | if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, |
| 4760 | sas_iounit_pg1, sz))) { |
| 4761 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4762 | ioc->name, __FILE__, __LINE__, __func__); |
| 4763 | goto out; |
| 4764 | } |
| 4765 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4766 | MPI2_IOCSTATUS_MASK; |
| 4767 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4768 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4769 | ioc->name, __FILE__, __LINE__, __func__); |
| 4770 | goto out; |
| 4771 | } |
| 4772 | |
| 4773 | ioc->io_missing_delay = |
| 4774 | le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay); |
| 4775 | device_missing_delay = |
| 4776 | le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay); |
| 4777 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) |
| 4778 | ioc->device_missing_delay = (device_missing_delay & |
| 4779 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; |
| 4780 | else |
| 4781 | ioc->device_missing_delay = device_missing_delay & |
| 4782 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 4783 | |
| 4784 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; |
| 4785 | ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys, |
| 4786 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4787 | if (!ioc->sas_hba.phy) { |
| 4788 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4789 | ioc->name, __FILE__, __LINE__, __func__); |
| 4790 | goto out; |
| 4791 | } |
| 4792 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
| 4793 | if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, |
| 4794 | i))) { |
| 4795 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4796 | ioc->name, __FILE__, __LINE__, __func__); |
| 4797 | goto out; |
| 4798 | } |
| 4799 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4800 | MPI2_IOCSTATUS_MASK; |
| 4801 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4802 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4803 | ioc->name, __FILE__, __LINE__, __func__); |
| 4804 | goto out; |
| 4805 | } |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4806 | |
| 4807 | if (i == 0) |
| 4808 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4809 | PhyData[0].ControllerDevHandle); |
| 4810 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4811 | ioc->sas_hba.phy[i].phy_id = i; |
| 4812 | mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], |
| 4813 | phy_pg0, ioc->sas_hba.parent_dev); |
| 4814 | } |
| 4815 | 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] | 4816 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4817 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4818 | ioc->name, __FILE__, __LINE__, __func__); |
| 4819 | goto out; |
| 4820 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4821 | ioc->sas_hba.enclosure_handle = |
| 4822 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 4823 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 4824 | printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), " |
| 4825 | "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle, |
| 4826 | (unsigned long long) ioc->sas_hba.sas_address, |
| 4827 | ioc->sas_hba.num_phys) ; |
| 4828 | |
| 4829 | if (ioc->sas_hba.enclosure_handle) { |
| 4830 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4831 | &enclosure_pg0, |
| 4832 | MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4833 | ioc->sas_hba.enclosure_handle))) { |
| 4834 | ioc->sas_hba.enclosure_logical_id = |
| 4835 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4836 | } |
| 4837 | } |
| 4838 | |
| 4839 | out: |
| 4840 | kfree(sas_iounit_pg1); |
| 4841 | kfree(sas_iounit_pg0); |
| 4842 | } |
| 4843 | |
| 4844 | /** |
| 4845 | * _scsih_expander_add - creating expander object |
| 4846 | * @ioc: per adapter object |
| 4847 | * @handle: expander handle |
| 4848 | * |
| 4849 | * Creating expander object, stored in ioc->sas_expander_list. |
| 4850 | * |
| 4851 | * Return 0 for success, else error. |
| 4852 | */ |
| 4853 | static int |
| 4854 | _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4855 | { |
| 4856 | struct _sas_node *sas_expander; |
| 4857 | Mpi2ConfigReply_t mpi_reply; |
| 4858 | Mpi2ExpanderPage0_t expander_pg0; |
| 4859 | Mpi2ExpanderPage1_t expander_pg1; |
| 4860 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4861 | u32 ioc_status; |
| 4862 | u16 parent_handle; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 4863 | u64 sas_address, sas_address_parent = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4864 | int i; |
| 4865 | unsigned long flags; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4866 | struct _sas_port *mpt2sas_port = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4867 | int rc = 0; |
| 4868 | |
| 4869 | if (!handle) |
| 4870 | return -1; |
| 4871 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 4872 | if (ioc->shost_recovery || ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 4873 | return -1; |
| 4874 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4875 | if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 4876 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { |
| 4877 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4878 | ioc->name, __FILE__, __LINE__, __func__); |
| 4879 | return -1; |
| 4880 | } |
| 4881 | |
| 4882 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4883 | MPI2_IOCSTATUS_MASK; |
| 4884 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4885 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4886 | ioc->name, __FILE__, __LINE__, __func__); |
| 4887 | return -1; |
| 4888 | } |
| 4889 | |
| 4890 | /* handle out of order topology events */ |
| 4891 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4892 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) |
| 4893 | != 0) { |
| 4894 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4895 | ioc->name, __FILE__, __LINE__, __func__); |
| 4896 | return -1; |
| 4897 | } |
| 4898 | if (sas_address_parent != ioc->sas_hba.sas_address) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4899 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4900 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4901 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4902 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4903 | if (!sas_expander) { |
| 4904 | rc = _scsih_expander_add(ioc, parent_handle); |
| 4905 | if (rc != 0) |
| 4906 | return rc; |
| 4907 | } |
| 4908 | } |
| 4909 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4910 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 4911 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4912 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4913 | sas_address); |
| 4914 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4915 | |
| 4916 | if (sas_expander) |
| 4917 | return 0; |
| 4918 | |
| 4919 | sas_expander = kzalloc(sizeof(struct _sas_node), |
| 4920 | GFP_KERNEL); |
| 4921 | if (!sas_expander) { |
| 4922 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4923 | ioc->name, __FILE__, __LINE__, __func__); |
| 4924 | return -1; |
| 4925 | } |
| 4926 | |
| 4927 | sas_expander->handle = handle; |
| 4928 | sas_expander->num_phys = expander_pg0.NumPhys; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4929 | sas_expander->sas_address_parent = sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4930 | sas_expander->sas_address = sas_address; |
| 4931 | |
| 4932 | printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x)," |
| 4933 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4934 | handle, parent_handle, (unsigned long long) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4935 | sas_expander->sas_address, sas_expander->num_phys); |
| 4936 | |
| 4937 | if (!sas_expander->num_phys) |
| 4938 | goto out_fail; |
| 4939 | sas_expander->phy = kcalloc(sas_expander->num_phys, |
| 4940 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4941 | if (!sas_expander->phy) { |
| 4942 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4943 | ioc->name, __FILE__, __LINE__, __func__); |
| 4944 | rc = -1; |
| 4945 | goto out_fail; |
| 4946 | } |
| 4947 | |
| 4948 | INIT_LIST_HEAD(&sas_expander->sas_port_list); |
| 4949 | mpt2sas_port = mpt2sas_transport_port_add(ioc, handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4950 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4951 | if (!mpt2sas_port) { |
| 4952 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4953 | ioc->name, __FILE__, __LINE__, __func__); |
| 4954 | rc = -1; |
| 4955 | goto out_fail; |
| 4956 | } |
| 4957 | sas_expander->parent_dev = &mpt2sas_port->rphy->dev; |
| 4958 | |
| 4959 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 4960 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 4961 | &expander_pg1, i, handle))) { |
| 4962 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4963 | ioc->name, __FILE__, __LINE__, __func__); |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4964 | rc = -1; |
| 4965 | goto out_fail; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4966 | } |
| 4967 | sas_expander->phy[i].handle = handle; |
| 4968 | sas_expander->phy[i].phy_id = i; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4969 | |
| 4970 | if ((mpt2sas_transport_add_expander_phy(ioc, |
| 4971 | &sas_expander->phy[i], expander_pg1, |
| 4972 | sas_expander->parent_dev))) { |
| 4973 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4974 | ioc->name, __FILE__, __LINE__, __func__); |
| 4975 | rc = -1; |
| 4976 | goto out_fail; |
| 4977 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | if (sas_expander->enclosure_handle) { |
| 4981 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4982 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4983 | sas_expander->enclosure_handle))) { |
| 4984 | sas_expander->enclosure_logical_id = |
| 4985 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4986 | } |
| 4987 | } |
| 4988 | |
| 4989 | _scsih_expander_node_add(ioc, sas_expander); |
| 4990 | return 0; |
| 4991 | |
| 4992 | out_fail: |
| 4993 | |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4994 | if (mpt2sas_port) |
| 4995 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4996 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4997 | kfree(sas_expander); |
| 4998 | return rc; |
| 4999 | } |
| 5000 | |
| 5001 | /** |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 5002 | * _scsih_done - scsih callback handler. |
| 5003 | * @ioc: per adapter object |
| 5004 | * @smid: system request message index |
| 5005 | * @msix_index: MSIX table index supplied by the OS |
| 5006 | * @reply: reply message frame(lower 32bit addr) |
| 5007 | * |
| 5008 | * Callback handler when sending internal generated message frames. |
| 5009 | * The callback index passed is `ioc->scsih_cb_idx` |
| 5010 | * |
| 5011 | * Return 1 meaning mf should be freed from _base_interrupt |
| 5012 | * 0 means the mf is freed from this function. |
| 5013 | */ |
| 5014 | static u8 |
| 5015 | _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) |
| 5016 | { |
| 5017 | MPI2DefaultReply_t *mpi_reply; |
| 5018 | |
| 5019 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 5020 | if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED) |
| 5021 | return 1; |
| 5022 | if (ioc->scsih_cmds.smid != smid) |
| 5023 | return 1; |
| 5024 | ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE; |
| 5025 | if (mpi_reply) { |
| 5026 | memcpy(ioc->scsih_cmds.reply, mpi_reply, |
| 5027 | mpi_reply->MsgLength*4); |
| 5028 | ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 5029 | } |
| 5030 | ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING; |
| 5031 | complete(&ioc->scsih_cmds.done); |
| 5032 | return 1; |
| 5033 | } |
| 5034 | |
| 5035 | /** |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5036 | * mpt2sas_expander_remove - removing expander object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5037 | * @ioc: per adapter object |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5038 | * @sas_address: expander sas_address |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5039 | * |
| 5040 | * Return nothing. |
| 5041 | */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5042 | void |
| 5043 | mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5044 | { |
| 5045 | struct _sas_node *sas_expander; |
| 5046 | unsigned long flags; |
| 5047 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 5048 | if (ioc->shost_recovery) |
| 5049 | return; |
| 5050 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5051 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5052 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 5053 | sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5054 | if (sas_expander) |
| 5055 | list_del(&sas_expander->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5056 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5057 | if (sas_expander) |
| 5058 | _scsih_expander_node_remove(ioc, sas_expander); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5059 | } |
| 5060 | |
| 5061 | /** |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5062 | * _scsih_check_access_status - check access flags |
| 5063 | * @ioc: per adapter object |
| 5064 | * @sas_address: sas address |
| 5065 | * @handle: sas device handle |
| 5066 | * @access_flags: errors returned during discovery of the device |
| 5067 | * |
| 5068 | * Return 0 for success, else failure |
| 5069 | */ |
| 5070 | static u8 |
| 5071 | _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 5072 | u16 handle, u8 access_status) |
| 5073 | { |
| 5074 | u8 rc = 1; |
| 5075 | char *desc = NULL; |
| 5076 | |
| 5077 | switch (access_status) { |
| 5078 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: |
| 5079 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: |
| 5080 | rc = 0; |
| 5081 | break; |
| 5082 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: |
| 5083 | desc = "sata capability failed"; |
| 5084 | break; |
| 5085 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: |
| 5086 | desc = "sata affiliation conflict"; |
| 5087 | break; |
| 5088 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: |
| 5089 | desc = "route not addressable"; |
| 5090 | break; |
| 5091 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: |
| 5092 | desc = "smp error not addressable"; |
| 5093 | break; |
| 5094 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: |
| 5095 | desc = "device blocked"; |
| 5096 | break; |
| 5097 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: |
| 5098 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: |
| 5099 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: |
| 5100 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: |
| 5101 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: |
| 5102 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: |
| 5103 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: |
| 5104 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: |
| 5105 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: |
| 5106 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: |
| 5107 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: |
| 5108 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: |
| 5109 | desc = "sata initialization failed"; |
| 5110 | break; |
| 5111 | default: |
| 5112 | desc = "unknown"; |
| 5113 | break; |
| 5114 | } |
| 5115 | |
| 5116 | if (!rc) |
| 5117 | return 0; |
| 5118 | |
| 5119 | printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), " |
| 5120 | "handle(0x%04x)\n", ioc->name, desc, |
| 5121 | (unsigned long long)sas_address, handle); |
| 5122 | return rc; |
| 5123 | } |
| 5124 | |
| 5125 | static void |
| 5126 | _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 5127 | { |
| 5128 | Mpi2ConfigReply_t mpi_reply; |
| 5129 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 5130 | struct _sas_device *sas_device; |
| 5131 | u32 ioc_status; |
| 5132 | unsigned long flags; |
| 5133 | u64 sas_address; |
| 5134 | struct scsi_target *starget; |
| 5135 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 5136 | u32 device_info; |
| 5137 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5138 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5139 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 5140 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) |
| 5141 | return; |
| 5142 | |
| 5143 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 5144 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 5145 | return; |
| 5146 | |
| 5147 | /* check if this is end device */ |
| 5148 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 5149 | if (!(_scsih_is_end_device(device_info))) |
| 5150 | return; |
| 5151 | |
| 5152 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5153 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 5154 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5155 | sas_address); |
| 5156 | |
| 5157 | if (!sas_device) { |
| 5158 | printk(MPT2SAS_ERR_FMT "device is not present " |
| 5159 | "handle(0x%04x), no sas_device!!!\n", ioc->name, handle); |
| 5160 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5161 | return; |
| 5162 | } |
| 5163 | |
| 5164 | if (unlikely(sas_device->handle != handle)) { |
| 5165 | starget = sas_device->starget; |
| 5166 | sas_target_priv_data = starget->hostdata; |
| 5167 | starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)" |
| 5168 | " to (0x%04x)!!!\n", sas_device->handle, handle); |
| 5169 | sas_target_priv_data->handle = handle; |
| 5170 | sas_device->handle = handle; |
| 5171 | } |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5172 | |
| 5173 | /* check if device is present */ |
| 5174 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 5175 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 5176 | printk(MPT2SAS_ERR_FMT "device is not present " |
| 5177 | "handle(0x%04x), flags!!!\n", ioc->name, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5178 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5179 | return; |
| 5180 | } |
| 5181 | |
| 5182 | /* check if there were any issues with discovery */ |
| 5183 | if (_scsih_check_access_status(ioc, sas_address, handle, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5184 | sas_device_pg0.AccessStatus)) { |
| 5185 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5186 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5187 | } |
| 5188 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 5189 | _scsih_ublock_io_device(ioc, sas_address); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5190 | |
| 5191 | } |
| 5192 | |
| 5193 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5194 | * _scsih_add_device - creating sas device object |
| 5195 | * @ioc: per adapter object |
| 5196 | * @handle: sas device handle |
| 5197 | * @phy_num: phy number end device attached to |
| 5198 | * @is_pd: is this hidden raid component |
| 5199 | * |
| 5200 | * Creating end device object, stored in ioc->sas_device_list. |
| 5201 | * |
| 5202 | * Returns 0 for success, non-zero for failure. |
| 5203 | */ |
| 5204 | static int |
| 5205 | _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd) |
| 5206 | { |
| 5207 | Mpi2ConfigReply_t mpi_reply; |
| 5208 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 5209 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 5210 | struct _sas_device *sas_device; |
| 5211 | u32 ioc_status; |
| 5212 | __le64 sas_address; |
| 5213 | u32 device_info; |
| 5214 | unsigned long flags; |
| 5215 | |
| 5216 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 5217 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 5218 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5219 | ioc->name, __FILE__, __LINE__, __func__); |
| 5220 | return -1; |
| 5221 | } |
| 5222 | |
| 5223 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 5224 | MPI2_IOCSTATUS_MASK; |
| 5225 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5226 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5227 | ioc->name, __FILE__, __LINE__, __func__); |
| 5228 | return -1; |
| 5229 | } |
| 5230 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5231 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 5232 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5233 | /* check if device is present */ |
| 5234 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 5235 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 5236 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5237 | ioc->name, __FILE__, __LINE__, __func__); |
| 5238 | printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n", |
| 5239 | ioc->name, le16_to_cpu(sas_device_pg0.Flags)); |
| 5240 | return -1; |
| 5241 | } |
| 5242 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5243 | /* check if there were any issues with discovery */ |
| 5244 | if (_scsih_check_access_status(ioc, sas_address, handle, |
| 5245 | sas_device_pg0.AccessStatus)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5246 | return -1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5247 | |
| 5248 | /* check if this is end device */ |
| 5249 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 5250 | if (!(_scsih_is_end_device(device_info))) { |
| 5251 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5252 | ioc->name, __FILE__, __LINE__, __func__); |
| 5253 | return -1; |
| 5254 | } |
| 5255 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5256 | |
| 5257 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5258 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5259 | sas_address); |
| 5260 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5261 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5262 | if (sas_device) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5263 | return 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5264 | |
| 5265 | sas_device = kzalloc(sizeof(struct _sas_device), |
| 5266 | GFP_KERNEL); |
| 5267 | if (!sas_device) { |
| 5268 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5269 | ioc->name, __FILE__, __LINE__, __func__); |
| 5270 | return -1; |
| 5271 | } |
| 5272 | |
| 5273 | sas_device->handle = handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5274 | if (_scsih_get_sas_address(ioc, le16_to_cpu |
| 5275 | (sas_device_pg0.ParentDevHandle), |
| 5276 | &sas_device->sas_address_parent) != 0) |
| 5277 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5278 | ioc->name, __FILE__, __LINE__, __func__); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5279 | sas_device->enclosure_handle = |
| 5280 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 5281 | sas_device->slot = |
| 5282 | le16_to_cpu(sas_device_pg0.Slot); |
| 5283 | sas_device->device_info = device_info; |
| 5284 | sas_device->sas_address = sas_address; |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 5285 | sas_device->phy = sas_device_pg0.PhyNum; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5286 | |
| 5287 | /* get enclosure_logical_id */ |
Kashyap, Desai | 15052c9 | 2009-08-07 19:33:17 +0530 | [diff] [blame] | 5288 | if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0( |
| 5289 | ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 5290 | sas_device->enclosure_handle))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5291 | sas_device->enclosure_logical_id = |
| 5292 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5293 | |
| 5294 | /* get device name */ |
| 5295 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); |
| 5296 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5297 | if (ioc->wait_for_discovery_to_complete) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5298 | _scsih_sas_device_init_add(ioc, sas_device); |
| 5299 | else |
| 5300 | _scsih_sas_device_add(ioc, sas_device); |
| 5301 | |
| 5302 | return 0; |
| 5303 | } |
| 5304 | |
| 5305 | /** |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5306 | * _scsih_remove_device - removing sas device object |
| 5307 | * @ioc: per adapter object |
| 5308 | * @sas_device_delete: the sas_device object |
| 5309 | * |
| 5310 | * Return nothing. |
| 5311 | */ |
| 5312 | static void |
| 5313 | _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, |
| 5314 | struct _sas_device *sas_device) |
| 5315 | { |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5316 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 5317 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5318 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: " |
| 5319 | "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] | 5320 | sas_device->handle, (unsigned long long) |
| 5321 | sas_device->sas_address)); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5322 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5323 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 5324 | sas_target_priv_data = sas_device->starget->hostdata; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5325 | sas_target_priv_data->deleted = 1; |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 5326 | _scsih_ublock_io_device(ioc, sas_device->sas_address); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5327 | sas_target_priv_data->handle = |
| 5328 | MPT2SAS_INVALID_DEVICE_HANDLE; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5329 | } |
| 5330 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 5331 | if (!ioc->hide_drives) |
| 5332 | mpt2sas_transport_port_remove(ioc, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5333 | sas_device->sas_address, |
| 5334 | sas_device->sas_address_parent); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5335 | |
| 5336 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr" |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5337 | "(0x%016llx)\n", ioc->name, sas_device->handle, |
| 5338 | (unsigned long long) sas_device->sas_address); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5339 | |
| 5340 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: " |
| 5341 | "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] | 5342 | sas_device->handle, (unsigned long long) |
| 5343 | sas_device->sas_address)); |
| 5344 | kfree(sas_device); |
| 5345 | } |
| 5346 | /** |
| 5347 | * _scsih_device_remove_by_handle - removing device object by handle |
| 5348 | * @ioc: per adapter object |
| 5349 | * @handle: device handle |
| 5350 | * |
| 5351 | * Return nothing. |
| 5352 | */ |
| 5353 | static void |
| 5354 | _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 5355 | { |
| 5356 | struct _sas_device *sas_device; |
| 5357 | unsigned long flags; |
| 5358 | |
| 5359 | if (ioc->shost_recovery) |
| 5360 | return; |
| 5361 | |
| 5362 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5363 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 5364 | if (sas_device) |
| 5365 | list_del(&sas_device->list); |
| 5366 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5367 | if (sas_device) |
| 5368 | _scsih_remove_device(ioc, sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5369 | } |
| 5370 | |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5371 | /** |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5372 | * mpt2sas_device_remove_by_sas_address - removing device object by sas address |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5373 | * @ioc: per adapter object |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5374 | * @sas_address: device sas_address |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5375 | * |
| 5376 | * Return nothing. |
| 5377 | */ |
| 5378 | void |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5379 | mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 5380 | u64 sas_address) |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5381 | { |
| 5382 | struct _sas_device *sas_device; |
| 5383 | unsigned long flags; |
| 5384 | |
| 5385 | if (ioc->shost_recovery) |
| 5386 | return; |
| 5387 | |
| 5388 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5389 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5390 | sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5391 | if (sas_device) |
| 5392 | list_del(&sas_device->list); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5393 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5394 | if (sas_device) |
| 5395 | _scsih_remove_device(ioc, sas_device); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5396 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5397 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5398 | /** |
| 5399 | * _scsih_sas_topology_change_event_debug - debug for topology event |
| 5400 | * @ioc: per adapter object |
| 5401 | * @event_data: event data payload |
| 5402 | * Context: user. |
| 5403 | */ |
| 5404 | static void |
| 5405 | _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5406 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 5407 | { |
| 5408 | int i; |
| 5409 | u16 handle; |
| 5410 | u16 reason_code; |
| 5411 | u8 phy_number; |
| 5412 | char *status_str = NULL; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5413 | u8 link_rate, prev_link_rate; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5414 | |
| 5415 | switch (event_data->ExpStatus) { |
| 5416 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: |
| 5417 | status_str = "add"; |
| 5418 | break; |
| 5419 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: |
| 5420 | status_str = "remove"; |
| 5421 | break; |
| 5422 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5423 | case 0: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5424 | status_str = "responding"; |
| 5425 | break; |
| 5426 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: |
| 5427 | status_str = "remove delay"; |
| 5428 | break; |
| 5429 | default: |
| 5430 | status_str = "unknown status"; |
| 5431 | break; |
| 5432 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5433 | printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5434 | ioc->name, status_str); |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5435 | printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5436 | "start_phy(%02d), count(%d)\n", |
| 5437 | le16_to_cpu(event_data->ExpanderDevHandle), |
| 5438 | le16_to_cpu(event_data->EnclosureHandle), |
| 5439 | event_data->StartPhyNum, event_data->NumEntries); |
| 5440 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5441 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5442 | if (!handle) |
| 5443 | continue; |
| 5444 | phy_number = event_data->StartPhyNum + i; |
| 5445 | reason_code = event_data->PHY[i].PhyStatus & |
| 5446 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5447 | switch (reason_code) { |
| 5448 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5449 | status_str = "target add"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5450 | break; |
| 5451 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5452 | status_str = "target remove"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5453 | break; |
| 5454 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5455 | status_str = "delay target remove"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5456 | break; |
| 5457 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5458 | status_str = "link rate change"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5459 | break; |
| 5460 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5461 | status_str = "target responding"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5462 | break; |
| 5463 | default: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5464 | status_str = "unknown"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5465 | break; |
| 5466 | } |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5467 | link_rate = event_data->PHY[i].LinkRate >> 4; |
| 5468 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5469 | printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:" |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5470 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, |
| 5471 | handle, status_str, link_rate, prev_link_rate); |
| 5472 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5473 | } |
| 5474 | } |
| 5475 | #endif |
| 5476 | |
| 5477 | /** |
| 5478 | * _scsih_sas_topology_change_event - handle topology changes |
| 5479 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5480 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5481 | * Context: user. |
| 5482 | * |
| 5483 | */ |
| 5484 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5485 | _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5486 | struct fw_event_work *fw_event) |
| 5487 | { |
| 5488 | int i; |
| 5489 | u16 parent_handle, handle; |
| 5490 | u16 reason_code; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5491 | u8 phy_number, max_phys; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5492 | struct _sas_node *sas_expander; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5493 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5494 | unsigned long flags; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5495 | u8 link_rate, prev_link_rate; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5496 | Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5497 | |
| 5498 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5499 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5500 | _scsih_sas_topology_change_event_debug(ioc, event_data); |
| 5501 | #endif |
| 5502 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5503 | if (ioc->remove_host || ioc->pci_error_recovery) |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5504 | return; |
| 5505 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5506 | if (!ioc->sas_hba.num_phys) |
| 5507 | _scsih_sas_host_add(ioc); |
| 5508 | else |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5509 | _scsih_sas_host_refresh(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5510 | |
| 5511 | if (fw_event->ignore) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5512 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5513 | "event\n", ioc->name)); |
| 5514 | return; |
| 5515 | } |
| 5516 | |
| 5517 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 5518 | |
| 5519 | /* handle expander add */ |
| 5520 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) |
| 5521 | if (_scsih_expander_add(ioc, parent_handle) != 0) |
| 5522 | return; |
| 5523 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5524 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 5525 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 5526 | parent_handle); |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5527 | if (sas_expander) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5528 | sas_address = sas_expander->sas_address; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5529 | max_phys = sas_expander->num_phys; |
| 5530 | } else if (parent_handle < ioc->sas_hba.num_phys) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5531 | sas_address = ioc->sas_hba.sas_address; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5532 | max_phys = ioc->sas_hba.num_phys; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5533 | } else { |
| 5534 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5535 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5536 | } |
| 5537 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5538 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5539 | /* handle siblings events */ |
| 5540 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5541 | if (fw_event->ignore) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5542 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5543 | "expander event\n", ioc->name)); |
| 5544 | return; |
| 5545 | } |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 5546 | if (ioc->shost_recovery || ioc->remove_host || |
| 5547 | ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 5548 | return; |
Kashyap, Desai | 308609c | 2009-09-14 11:07:23 +0530 | [diff] [blame] | 5549 | phy_number = event_data->StartPhyNum + i; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5550 | if (phy_number >= max_phys) |
| 5551 | continue; |
Kashyap, Desai | 308609c | 2009-09-14 11:07:23 +0530 | [diff] [blame] | 5552 | reason_code = event_data->PHY[i].PhyStatus & |
| 5553 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5554 | if ((event_data->PHY[i].PhyStatus & |
| 5555 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != |
| 5556 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5557 | continue; |
| 5558 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5559 | if (!handle) |
| 5560 | continue; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5561 | link_rate = event_data->PHY[i].LinkRate >> 4; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5562 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5563 | switch (reason_code) { |
| 5564 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5565 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5566 | if (ioc->shost_recovery) |
| 5567 | break; |
| 5568 | |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5569 | if (link_rate == prev_link_rate) |
| 5570 | break; |
| 5571 | |
| 5572 | mpt2sas_transport_update_links(ioc, sas_address, |
| 5573 | handle, phy_number, link_rate); |
| 5574 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5575 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 5576 | break; |
| 5577 | |
| 5578 | _scsih_check_device(ioc, handle); |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5579 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5580 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5581 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5582 | if (ioc->shost_recovery) |
| 5583 | break; |
| 5584 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5585 | mpt2sas_transport_update_links(ioc, sas_address, |
| 5586 | handle, phy_number, link_rate); |
| 5587 | |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5588 | _scsih_add_device(ioc, handle, phy_number, 0); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5589 | break; |
| 5590 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5591 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5592 | _scsih_device_remove_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5593 | break; |
| 5594 | } |
| 5595 | } |
| 5596 | |
| 5597 | /* handle expander removal */ |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5598 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && |
| 5599 | sas_expander) |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5600 | mpt2sas_expander_remove(ioc, sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5601 | |
| 5602 | } |
| 5603 | |
| 5604 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5605 | /** |
| 5606 | * _scsih_sas_device_status_change_event_debug - debug for device event |
| 5607 | * @event_data: event data payload |
| 5608 | * Context: user. |
| 5609 | * |
| 5610 | * Return nothing. |
| 5611 | */ |
| 5612 | static void |
| 5613 | _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5614 | Mpi2EventDataSasDeviceStatusChange_t *event_data) |
| 5615 | { |
| 5616 | char *reason_str = NULL; |
| 5617 | |
| 5618 | switch (event_data->ReasonCode) { |
| 5619 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: |
| 5620 | reason_str = "smart data"; |
| 5621 | break; |
| 5622 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: |
| 5623 | reason_str = "unsupported device discovered"; |
| 5624 | break; |
| 5625 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: |
| 5626 | reason_str = "internal device reset"; |
| 5627 | break; |
| 5628 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: |
| 5629 | reason_str = "internal task abort"; |
| 5630 | break; |
| 5631 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: |
| 5632 | reason_str = "internal task abort set"; |
| 5633 | break; |
| 5634 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: |
| 5635 | reason_str = "internal clear task set"; |
| 5636 | break; |
| 5637 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: |
| 5638 | reason_str = "internal query task"; |
| 5639 | break; |
| 5640 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: |
| 5641 | reason_str = "sata init failure"; |
| 5642 | break; |
| 5643 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: |
| 5644 | reason_str = "internal device reset complete"; |
| 5645 | break; |
| 5646 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: |
| 5647 | reason_str = "internal task abort complete"; |
| 5648 | break; |
| 5649 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: |
| 5650 | reason_str = "internal async notification"; |
| 5651 | break; |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 5652 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5653 | reason_str = "expander reduced functionality"; |
| 5654 | break; |
| 5655 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5656 | reason_str = "expander reduced functionality complete"; |
| 5657 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5658 | default: |
| 5659 | reason_str = "unknown reason"; |
| 5660 | break; |
| 5661 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5662 | printk(MPT2SAS_INFO_FMT "device status change: (%s)\n" |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5663 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", |
| 5664 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), |
| 5665 | (unsigned long long)le64_to_cpu(event_data->SASAddress), |
| 5666 | le16_to_cpu(event_data->TaskTag)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5667 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5668 | 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] | 5669 | event_data->ASC, event_data->ASCQ); |
| 5670 | printk(KERN_INFO "\n"); |
| 5671 | } |
| 5672 | #endif |
| 5673 | |
| 5674 | /** |
| 5675 | * _scsih_sas_device_status_change_event - handle device status change |
| 5676 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5677 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5678 | * Context: user. |
| 5679 | * |
| 5680 | * Return nothing. |
| 5681 | */ |
| 5682 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5683 | _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 5684 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5685 | { |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5686 | struct MPT2SAS_TARGET *target_priv_data; |
| 5687 | struct _sas_device *sas_device; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 5688 | u64 sas_address; |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5689 | unsigned long flags; |
| 5690 | Mpi2EventDataSasDeviceStatusChange_t *event_data = |
| 5691 | fw_event->event_data; |
| 5692 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5693 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5694 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5695 | _scsih_sas_device_status_change_event_debug(ioc, |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5696 | event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5697 | #endif |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5698 | |
Kashyap, Desai | efe82a1 | 2011-01-04 11:34:17 +0530 | [diff] [blame] | 5699 | /* In MPI Revision K (0xC), the internal device reset complete was |
| 5700 | * implemented, so avoid setting tm_busy flag for older firmware. |
| 5701 | */ |
| 5702 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) |
| 5703 | return; |
| 5704 | |
Kashyap, Desai | f891dcf | 2010-03-17 16:22:21 +0530 | [diff] [blame] | 5705 | if (event_data->ReasonCode != |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5706 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && |
Kashyap, Desai | f891dcf | 2010-03-17 16:22:21 +0530 | [diff] [blame] | 5707 | event_data->ReasonCode != |
| 5708 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5709 | return; |
| 5710 | |
| 5711 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5712 | sas_address = le64_to_cpu(event_data->SASAddress); |
| 5713 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5714 | sas_address); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5715 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5716 | if (!sas_device || !sas_device->starget) { |
| 5717 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5718 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5719 | } |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5720 | |
| 5721 | target_priv_data = sas_device->starget->hostdata; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5722 | if (!target_priv_data) { |
| 5723 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5724 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5725 | } |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5726 | |
| 5727 | if (event_data->ReasonCode == |
| 5728 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) |
| 5729 | target_priv_data->tm_busy = 1; |
| 5730 | else |
| 5731 | target_priv_data->tm_busy = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5732 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5733 | } |
| 5734 | |
| 5735 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5736 | /** |
| 5737 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event |
| 5738 | * @ioc: per adapter object |
| 5739 | * @event_data: event data payload |
| 5740 | * Context: user. |
| 5741 | * |
| 5742 | * Return nothing. |
| 5743 | */ |
| 5744 | static void |
| 5745 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5746 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) |
| 5747 | { |
| 5748 | char *reason_str = NULL; |
| 5749 | |
| 5750 | switch (event_data->ReasonCode) { |
| 5751 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: |
| 5752 | reason_str = "enclosure add"; |
| 5753 | break; |
| 5754 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: |
| 5755 | reason_str = "enclosure remove"; |
| 5756 | break; |
| 5757 | default: |
| 5758 | reason_str = "unknown reason"; |
| 5759 | break; |
| 5760 | } |
| 5761 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5762 | printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5763 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" |
| 5764 | " number slots(%d)\n", ioc->name, reason_str, |
| 5765 | le16_to_cpu(event_data->EnclosureHandle), |
| 5766 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), |
| 5767 | le16_to_cpu(event_data->StartSlot)); |
| 5768 | } |
| 5769 | #endif |
| 5770 | |
| 5771 | /** |
| 5772 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events |
| 5773 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5774 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5775 | * Context: user. |
| 5776 | * |
| 5777 | * Return nothing. |
| 5778 | */ |
| 5779 | static void |
| 5780 | _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5781 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5782 | { |
| 5783 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5784 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5785 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5786 | fw_event->event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5787 | #endif |
| 5788 | } |
| 5789 | |
| 5790 | /** |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 5791 | * _scsih_sas_broadcast_primitive_event - handle broadcast events |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5792 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5793 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5794 | * Context: user. |
| 5795 | * |
| 5796 | * Return nothing. |
| 5797 | */ |
| 5798 | static void |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 5799 | _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5800 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5801 | { |
| 5802 | struct scsi_cmnd *scmd; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5803 | struct scsi_device *sdev; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5804 | u16 smid, handle; |
| 5805 | u32 lun; |
| 5806 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 5807 | u32 termination_count; |
| 5808 | u32 query_count; |
| 5809 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5810 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data; |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 5811 | u16 ioc_status; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5812 | unsigned long flags; |
| 5813 | int r; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5814 | u8 max_retries = 0; |
| 5815 | u8 task_abort_retries; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5816 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5817 | mutex_lock(&ioc->tm_cmds.mutex); |
| 5818 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: phy number(%d), " |
| 5819 | "width(%d)\n", ioc->name, __func__, event_data->PhyNum, |
| 5820 | event_data->PortWidth)); |
| 5821 | |
| 5822 | _scsih_block_io_all_device(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5823 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5824 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5825 | mpi_reply = ioc->tm_cmds.reply; |
| 5826 | broadcast_aen_retry: |
| 5827 | |
| 5828 | /* sanity checks for retrying this loop */ |
| 5829 | if (max_retries++ == 5) { |
| 5830 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n", |
| 5831 | ioc->name, __func__)); |
| 5832 | goto out; |
| 5833 | } else if (max_retries > 1) |
| 5834 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n", |
| 5835 | ioc->name, __func__, max_retries - 1)); |
| 5836 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5837 | termination_count = 0; |
| 5838 | query_count = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 5839 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5840 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5841 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5842 | scmd = _scsih_scsi_lookup_get(ioc, smid); |
| 5843 | if (!scmd) |
| 5844 | continue; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5845 | sdev = scmd->device; |
| 5846 | sas_device_priv_data = sdev->hostdata; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5847 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) |
| 5848 | continue; |
| 5849 | /* skip hidden raid components */ |
| 5850 | if (sas_device_priv_data->sas_target->flags & |
| 5851 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 5852 | continue; |
| 5853 | /* skip volumes */ |
| 5854 | if (sas_device_priv_data->sas_target->flags & |
| 5855 | MPT_TARGET_FLAGS_VOLUME) |
| 5856 | continue; |
| 5857 | |
| 5858 | handle = sas_device_priv_data->sas_target->handle; |
| 5859 | lun = sas_device_priv_data->lun; |
| 5860 | query_count++; |
| 5861 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5862 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5863 | goto out; |
| 5864 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5865 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5866 | r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun, |
| 5867 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0, |
| 5868 | TM_MUTEX_OFF); |
| 5869 | if (r == FAILED) { |
| 5870 | sdev_printk(KERN_WARNING, sdev, |
| 5871 | "mpt2sas_scsih_issue_tm: FAILED when sending " |
| 5872 | "QUERY_TASK: scmd(%p)\n", scmd); |
| 5873 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5874 | goto broadcast_aen_retry; |
| 5875 | } |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 5876 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) |
| 5877 | & MPI2_IOCSTATUS_MASK; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5878 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5879 | sdev_printk(KERN_WARNING, sdev, "query task: FAILED " |
| 5880 | "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status, |
| 5881 | scmd); |
| 5882 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5883 | goto broadcast_aen_retry; |
| 5884 | } |
| 5885 | |
| 5886 | /* see if IO is still owned by IOC and target */ |
| 5887 | if (mpi_reply->ResponseCode == |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5888 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || |
| 5889 | mpi_reply->ResponseCode == |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5890 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5891 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5892 | continue; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5893 | } |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5894 | task_abort_retries = 0; |
| 5895 | tm_retry: |
| 5896 | if (task_abort_retries++ == 60) { |
| 5897 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 5898 | "%s: ABORT_TASK: giving up\n", ioc->name, |
| 5899 | __func__)); |
| 5900 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5901 | goto broadcast_aen_retry; |
| 5902 | } |
| 5903 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5904 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5905 | goto out_no_lock; |
| 5906 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5907 | r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, |
| 5908 | sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5909 | scmd->serial_number, TM_MUTEX_OFF); |
| 5910 | if (r == FAILED) { |
| 5911 | sdev_printk(KERN_WARNING, sdev, |
| 5912 | "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : " |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5913 | "scmd(%p)\n", scmd); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5914 | goto tm_retry; |
| 5915 | } |
| 5916 | |
| 5917 | if (task_abort_retries > 1) |
| 5918 | sdev_printk(KERN_WARNING, sdev, |
| 5919 | "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" |
| 5920 | " scmd(%p)\n", |
| 5921 | task_abort_retries - 1, scmd); |
| 5922 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5923 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5924 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5925 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5926 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5927 | if (ioc->broadcast_aen_pending) { |
| 5928 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to" |
| 5929 | " pending AEN\n", ioc->name, __func__)); |
| 5930 | ioc->broadcast_aen_pending = 0; |
| 5931 | goto broadcast_aen_retry; |
| 5932 | } |
| 5933 | |
| 5934 | out: |
| 5935 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 5936 | out_no_lock: |
| 5937 | |
| 5938 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5939 | "%s - exit, query_count = %d termination_count = %d\n", |
| 5940 | ioc->name, __func__, query_count, termination_count)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5941 | |
| 5942 | ioc->broadcast_aen_busy = 0; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5943 | if (!ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5944 | _scsih_ublock_io_all_device(ioc); |
| 5945 | mutex_unlock(&ioc->tm_cmds.mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5946 | } |
| 5947 | |
| 5948 | /** |
| 5949 | * _scsih_sas_discovery_event - handle discovery events |
| 5950 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5951 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5952 | * Context: user. |
| 5953 | * |
| 5954 | * Return nothing. |
| 5955 | */ |
| 5956 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5957 | _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc, |
| 5958 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5959 | { |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5960 | Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data; |
| 5961 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5962 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5963 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5964 | printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5965 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? |
| 5966 | "start" : "stop"); |
| 5967 | if (event_data->DiscoveryStatus) |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 5968 | printk("discovery_status(0x%08x)", |
| 5969 | le32_to_cpu(event_data->DiscoveryStatus)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5970 | printk("\n"); |
| 5971 | } |
| 5972 | #endif |
| 5973 | |
| 5974 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 5975 | !ioc->sas_hba.num_phys) { |
| 5976 | if (disable_discovery > 0 && ioc->shost_recovery) { |
| 5977 | /* Wait for the reset to complete */ |
| 5978 | while (ioc->shost_recovery) |
| 5979 | ssleep(1); |
| 5980 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5981 | _scsih_sas_host_add(ioc); |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 5982 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5983 | } |
| 5984 | |
| 5985 | /** |
| 5986 | * _scsih_reprobe_lun - reprobing lun |
| 5987 | * @sdev: scsi device struct |
| 5988 | * @no_uld_attach: sdev->no_uld_attach flag setting |
| 5989 | * |
| 5990 | **/ |
| 5991 | static void |
| 5992 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) |
| 5993 | { |
| 5994 | int rc; |
| 5995 | |
| 5996 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
| 5997 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", |
| 5998 | sdev->no_uld_attach ? "hidding" : "exposing"); |
| 5999 | rc = scsi_device_reprobe(sdev); |
| 6000 | } |
| 6001 | |
| 6002 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6003 | * _scsih_sas_volume_add - add new volume |
| 6004 | * @ioc: per adapter object |
| 6005 | * @element: IR config element data |
| 6006 | * Context: user. |
| 6007 | * |
| 6008 | * Return nothing. |
| 6009 | */ |
| 6010 | static void |
| 6011 | _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc, |
| 6012 | Mpi2EventIrConfigElement_t *element) |
| 6013 | { |
| 6014 | struct _raid_device *raid_device; |
| 6015 | unsigned long flags; |
| 6016 | u64 wwid; |
| 6017 | u16 handle = le16_to_cpu(element->VolDevHandle); |
| 6018 | int rc; |
| 6019 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6020 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 6021 | if (!wwid) { |
| 6022 | printk(MPT2SAS_ERR_FMT |
| 6023 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6024 | __FILE__, __LINE__, __func__); |
| 6025 | return; |
| 6026 | } |
| 6027 | |
| 6028 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6029 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); |
| 6030 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6031 | |
| 6032 | if (raid_device) |
| 6033 | return; |
| 6034 | |
| 6035 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 6036 | if (!raid_device) { |
| 6037 | printk(MPT2SAS_ERR_FMT |
| 6038 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6039 | __FILE__, __LINE__, __func__); |
| 6040 | return; |
| 6041 | } |
| 6042 | |
| 6043 | raid_device->id = ioc->sas_id++; |
| 6044 | raid_device->channel = RAID_CHANNEL; |
| 6045 | raid_device->handle = handle; |
| 6046 | raid_device->wwid = wwid; |
| 6047 | _scsih_raid_device_add(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6048 | if (!ioc->wait_for_discovery_to_complete) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6049 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 6050 | raid_device->id, 0); |
| 6051 | if (rc) |
| 6052 | _scsih_raid_device_remove(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6053 | } else { |
| 6054 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6055 | _scsih_determine_boot_device(ioc, raid_device, 1); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6056 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6057 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6058 | } |
| 6059 | |
| 6060 | /** |
| 6061 | * _scsih_sas_volume_delete - delete volume |
| 6062 | * @ioc: per adapter object |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6063 | * @handle: volume device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6064 | * Context: user. |
| 6065 | * |
| 6066 | * Return nothing. |
| 6067 | */ |
| 6068 | static void |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6069 | _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6070 | { |
| 6071 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6072 | unsigned long flags; |
| 6073 | struct MPT2SAS_TARGET *sas_target_priv_data; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6074 | struct scsi_target *starget = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6075 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6076 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6077 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6078 | if (raid_device) { |
| 6079 | if (raid_device->starget) { |
| 6080 | starget = raid_device->starget; |
| 6081 | sas_target_priv_data = starget->hostdata; |
| 6082 | sas_target_priv_data->deleted = 1; |
| 6083 | } |
| 6084 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" |
| 6085 | "(0x%016llx)\n", ioc->name, raid_device->handle, |
| 6086 | (unsigned long long) raid_device->wwid); |
| 6087 | list_del(&raid_device->list); |
| 6088 | kfree(raid_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6089 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6090 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6091 | if (starget) |
| 6092 | scsi_remove_target(&starget->dev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6093 | } |
| 6094 | |
| 6095 | /** |
| 6096 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX |
| 6097 | * @ioc: per adapter object |
| 6098 | * @element: IR config element data |
| 6099 | * Context: user. |
| 6100 | * |
| 6101 | * Return nothing. |
| 6102 | */ |
| 6103 | static void |
| 6104 | _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc, |
| 6105 | Mpi2EventIrConfigElement_t *element) |
| 6106 | { |
| 6107 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6108 | struct scsi_target *starget = NULL; |
| 6109 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6110 | unsigned long flags; |
| 6111 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 6112 | |
| 6113 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6114 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6115 | if (sas_device) { |
| 6116 | sas_device->volume_handle = 0; |
| 6117 | sas_device->volume_wwid = 0; |
| 6118 | clear_bit(handle, ioc->pd_handles); |
| 6119 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 6120 | starget = sas_device->starget; |
| 6121 | sas_target_priv_data = starget->hostdata; |
| 6122 | sas_target_priv_data->flags &= |
| 6123 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 6124 | } |
| 6125 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6126 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6127 | if (!sas_device) |
| 6128 | return; |
| 6129 | |
| 6130 | /* exposing raid component */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6131 | if (starget) |
| 6132 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6133 | } |
| 6134 | |
| 6135 | /** |
| 6136 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX |
| 6137 | * @ioc: per adapter object |
| 6138 | * @element: IR config element data |
| 6139 | * Context: user. |
| 6140 | * |
| 6141 | * Return nothing. |
| 6142 | */ |
| 6143 | static void |
| 6144 | _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc, |
| 6145 | Mpi2EventIrConfigElement_t *element) |
| 6146 | { |
| 6147 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6148 | struct scsi_target *starget = NULL; |
| 6149 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6150 | unsigned long flags; |
| 6151 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6152 | u16 volume_handle = 0; |
| 6153 | u64 volume_wwid = 0; |
| 6154 | |
| 6155 | mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle); |
| 6156 | if (volume_handle) |
| 6157 | mpt2sas_config_get_volume_wwid(ioc, volume_handle, |
| 6158 | &volume_wwid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6159 | |
| 6160 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6161 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6162 | if (sas_device) { |
| 6163 | set_bit(handle, ioc->pd_handles); |
| 6164 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 6165 | starget = sas_device->starget; |
| 6166 | sas_target_priv_data = starget->hostdata; |
| 6167 | sas_target_priv_data->flags |= |
| 6168 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 6169 | sas_device->volume_handle = volume_handle; |
| 6170 | sas_device->volume_wwid = volume_wwid; |
| 6171 | } |
| 6172 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6173 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6174 | if (!sas_device) |
| 6175 | return; |
| 6176 | |
| 6177 | /* hiding raid component */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6178 | if (starget) |
| 6179 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6180 | } |
| 6181 | |
| 6182 | /** |
| 6183 | * _scsih_sas_pd_delete - delete pd component |
| 6184 | * @ioc: per adapter object |
| 6185 | * @element: IR config element data |
| 6186 | * Context: user. |
| 6187 | * |
| 6188 | * Return nothing. |
| 6189 | */ |
| 6190 | static void |
| 6191 | _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc, |
| 6192 | Mpi2EventIrConfigElement_t *element) |
| 6193 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6194 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 6195 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6196 | _scsih_device_remove_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | /** |
| 6200 | * _scsih_sas_pd_add - remove pd component |
| 6201 | * @ioc: per adapter object |
| 6202 | * @element: IR config element data |
| 6203 | * Context: user. |
| 6204 | * |
| 6205 | * Return nothing. |
| 6206 | */ |
| 6207 | static void |
| 6208 | _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc, |
| 6209 | Mpi2EventIrConfigElement_t *element) |
| 6210 | { |
| 6211 | struct _sas_device *sas_device; |
| 6212 | unsigned long flags; |
| 6213 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6214 | Mpi2ConfigReply_t mpi_reply; |
| 6215 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6216 | u32 ioc_status; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6217 | u64 sas_address; |
| 6218 | u16 parent_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6219 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6220 | set_bit(handle, ioc->pd_handles); |
| 6221 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6222 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6223 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6224 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6225 | if (sas_device) |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6226 | return; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6227 | |
| 6228 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 6229 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 6230 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6231 | ioc->name, __FILE__, __LINE__, __func__); |
| 6232 | return; |
| 6233 | } |
| 6234 | |
| 6235 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6236 | MPI2_IOCSTATUS_MASK; |
| 6237 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6238 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6239 | ioc->name, __FILE__, __LINE__, __func__); |
| 6240 | return; |
| 6241 | } |
| 6242 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6243 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6244 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 6245 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 6246 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6247 | |
| 6248 | _scsih_add_device(ioc, handle, 0, 1); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6249 | } |
| 6250 | |
| 6251 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 6252 | /** |
| 6253 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events |
| 6254 | * @ioc: per adapter object |
| 6255 | * @event_data: event data payload |
| 6256 | * Context: user. |
| 6257 | * |
| 6258 | * Return nothing. |
| 6259 | */ |
| 6260 | static void |
| 6261 | _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 6262 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 6263 | { |
| 6264 | Mpi2EventIrConfigElement_t *element; |
| 6265 | u8 element_type; |
| 6266 | int i; |
| 6267 | char *reason_str = NULL, *element_str = NULL; |
| 6268 | |
| 6269 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 6270 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6271 | printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6272 | ioc->name, (le32_to_cpu(event_data->Flags) & |
| 6273 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? |
| 6274 | "foreign" : "native", event_data->NumElements); |
| 6275 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6276 | switch (element->ReasonCode) { |
| 6277 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
| 6278 | reason_str = "add"; |
| 6279 | break; |
| 6280 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
| 6281 | reason_str = "remove"; |
| 6282 | break; |
| 6283 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: |
| 6284 | reason_str = "no change"; |
| 6285 | break; |
| 6286 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
| 6287 | reason_str = "hide"; |
| 6288 | break; |
| 6289 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
| 6290 | reason_str = "unhide"; |
| 6291 | break; |
| 6292 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 6293 | reason_str = "volume_created"; |
| 6294 | break; |
| 6295 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 6296 | reason_str = "volume_deleted"; |
| 6297 | break; |
| 6298 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
| 6299 | reason_str = "pd_created"; |
| 6300 | break; |
| 6301 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
| 6302 | reason_str = "pd_deleted"; |
| 6303 | break; |
| 6304 | default: |
| 6305 | reason_str = "unknown reason"; |
| 6306 | break; |
| 6307 | } |
| 6308 | element_type = le16_to_cpu(element->ElementFlags) & |
| 6309 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; |
| 6310 | switch (element_type) { |
| 6311 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: |
| 6312 | element_str = "volume"; |
| 6313 | break; |
| 6314 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: |
| 6315 | element_str = "phys disk"; |
| 6316 | break; |
| 6317 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: |
| 6318 | element_str = "hot spare"; |
| 6319 | break; |
| 6320 | default: |
| 6321 | element_str = "unknown element"; |
| 6322 | break; |
| 6323 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6324 | printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6325 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, |
| 6326 | reason_str, le16_to_cpu(element->VolDevHandle), |
| 6327 | le16_to_cpu(element->PhysDiskDevHandle), |
| 6328 | element->PhysDiskNum); |
| 6329 | } |
| 6330 | } |
| 6331 | #endif |
| 6332 | |
| 6333 | /** |
| 6334 | * _scsih_sas_ir_config_change_event - handle ir configuration change events |
| 6335 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6336 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6337 | * Context: user. |
| 6338 | * |
| 6339 | * Return nothing. |
| 6340 | */ |
| 6341 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6342 | _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 6343 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6344 | { |
| 6345 | Mpi2EventIrConfigElement_t *element; |
| 6346 | int i; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6347 | u8 foreign_config; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6348 | Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6349 | |
| 6350 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6351 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6352 | && !ioc->hide_ir_msg) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6353 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
| 6354 | |
| 6355 | #endif |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6356 | |
| 6357 | if (ioc->shost_recovery) |
| 6358 | return; |
| 6359 | |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6360 | foreign_config = (le32_to_cpu(event_data->Flags) & |
| 6361 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6362 | |
| 6363 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 6364 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6365 | |
| 6366 | switch (element->ReasonCode) { |
| 6367 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 6368 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6369 | if (!foreign_config) |
| 6370 | _scsih_sas_volume_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6371 | break; |
| 6372 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 6373 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6374 | if (!foreign_config) |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6375 | _scsih_sas_volume_delete(ioc, |
| 6376 | le16_to_cpu(element->VolDevHandle)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6377 | break; |
| 6378 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6379 | if (!ioc->is_warpdrive) |
| 6380 | _scsih_sas_pd_hide(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6381 | break; |
| 6382 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6383 | if (!ioc->is_warpdrive) |
| 6384 | _scsih_sas_pd_expose(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6385 | break; |
| 6386 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6387 | if (!ioc->is_warpdrive) |
| 6388 | _scsih_sas_pd_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6389 | break; |
| 6390 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6391 | if (!ioc->is_warpdrive) |
| 6392 | _scsih_sas_pd_delete(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6393 | break; |
| 6394 | } |
| 6395 | } |
| 6396 | } |
| 6397 | |
| 6398 | /** |
| 6399 | * _scsih_sas_ir_volume_event - IR volume event |
| 6400 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6401 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6402 | * Context: user. |
| 6403 | * |
| 6404 | * Return nothing. |
| 6405 | */ |
| 6406 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6407 | _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc, |
| 6408 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6409 | { |
| 6410 | u64 wwid; |
| 6411 | unsigned long flags; |
| 6412 | struct _raid_device *raid_device; |
| 6413 | u16 handle; |
| 6414 | u32 state; |
| 6415 | int rc; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6416 | Mpi2EventDataIrVolume_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6417 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6418 | if (ioc->shost_recovery) |
| 6419 | return; |
| 6420 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6421 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 6422 | return; |
| 6423 | |
| 6424 | handle = le16_to_cpu(event_data->VolDevHandle); |
| 6425 | state = le32_to_cpu(event_data->NewValue); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6426 | if (!ioc->hide_ir_msg) |
| 6427 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " |
| 6428 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 6429 | le32_to_cpu(event_data->PreviousValue), state)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6430 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6431 | switch (state) { |
| 6432 | case MPI2_RAID_VOL_STATE_MISSING: |
| 6433 | case MPI2_RAID_VOL_STATE_FAILED: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6434 | _scsih_sas_volume_delete(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6435 | break; |
| 6436 | |
| 6437 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 6438 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 6439 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6440 | |
| 6441 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6442 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 6443 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6444 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6445 | if (raid_device) |
| 6446 | break; |
| 6447 | |
| 6448 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 6449 | if (!wwid) { |
| 6450 | printk(MPT2SAS_ERR_FMT |
| 6451 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6452 | __FILE__, __LINE__, __func__); |
| 6453 | break; |
| 6454 | } |
| 6455 | |
| 6456 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 6457 | if (!raid_device) { |
| 6458 | printk(MPT2SAS_ERR_FMT |
| 6459 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6460 | __FILE__, __LINE__, __func__); |
| 6461 | break; |
| 6462 | } |
| 6463 | |
| 6464 | raid_device->id = ioc->sas_id++; |
| 6465 | raid_device->channel = RAID_CHANNEL; |
| 6466 | raid_device->handle = handle; |
| 6467 | raid_device->wwid = wwid; |
| 6468 | _scsih_raid_device_add(ioc, raid_device); |
| 6469 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 6470 | raid_device->id, 0); |
| 6471 | if (rc) |
| 6472 | _scsih_raid_device_remove(ioc, raid_device); |
| 6473 | break; |
| 6474 | |
| 6475 | case MPI2_RAID_VOL_STATE_INITIALIZING: |
| 6476 | default: |
| 6477 | break; |
| 6478 | } |
| 6479 | } |
| 6480 | |
| 6481 | /** |
| 6482 | * _scsih_sas_ir_physical_disk_event - PD event |
| 6483 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6484 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6485 | * Context: user. |
| 6486 | * |
| 6487 | * Return nothing. |
| 6488 | */ |
| 6489 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6490 | _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc, |
| 6491 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6492 | { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6493 | u16 handle, parent_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6494 | u32 state; |
| 6495 | struct _sas_device *sas_device; |
| 6496 | unsigned long flags; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6497 | Mpi2ConfigReply_t mpi_reply; |
| 6498 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6499 | u32 ioc_status; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6500 | Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6501 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6502 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6503 | if (ioc->shost_recovery) |
| 6504 | return; |
| 6505 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6506 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) |
| 6507 | return; |
| 6508 | |
| 6509 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); |
| 6510 | state = le32_to_cpu(event_data->NewValue); |
| 6511 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6512 | if (!ioc->hide_ir_msg) |
| 6513 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " |
| 6514 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 6515 | le32_to_cpu(event_data->PreviousValue), state)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6516 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6517 | switch (state) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6518 | case MPI2_RAID_PD_STATE_ONLINE: |
| 6519 | case MPI2_RAID_PD_STATE_DEGRADED: |
| 6520 | case MPI2_RAID_PD_STATE_REBUILDING: |
| 6521 | case MPI2_RAID_PD_STATE_OPTIMAL: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6522 | case MPI2_RAID_PD_STATE_HOT_SPARE: |
| 6523 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6524 | if (!ioc->is_warpdrive) |
| 6525 | set_bit(handle, ioc->pd_handles); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6526 | |
| 6527 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6528 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6529 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6530 | |
| 6531 | if (sas_device) |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6532 | return; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6533 | |
| 6534 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6535 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 6536 | handle))) { |
| 6537 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6538 | ioc->name, __FILE__, __LINE__, __func__); |
| 6539 | return; |
| 6540 | } |
| 6541 | |
| 6542 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6543 | MPI2_IOCSTATUS_MASK; |
| 6544 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6545 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6546 | ioc->name, __FILE__, __LINE__, __func__); |
| 6547 | return; |
| 6548 | } |
| 6549 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6550 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6551 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 6552 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 6553 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6554 | |
| 6555 | _scsih_add_device(ioc, handle, 0, 1); |
| 6556 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6557 | break; |
| 6558 | |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6559 | case MPI2_RAID_PD_STATE_OFFLINE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6560 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: |
| 6561 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6562 | default: |
| 6563 | break; |
| 6564 | } |
| 6565 | } |
| 6566 | |
| 6567 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 6568 | /** |
| 6569 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event |
| 6570 | * @ioc: per adapter object |
| 6571 | * @event_data: event data payload |
| 6572 | * Context: user. |
| 6573 | * |
| 6574 | * Return nothing. |
| 6575 | */ |
| 6576 | static void |
| 6577 | _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 6578 | Mpi2EventDataIrOperationStatus_t *event_data) |
| 6579 | { |
| 6580 | char *reason_str = NULL; |
| 6581 | |
| 6582 | switch (event_data->RAIDOperation) { |
| 6583 | case MPI2_EVENT_IR_RAIDOP_RESYNC: |
| 6584 | reason_str = "resync"; |
| 6585 | break; |
| 6586 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: |
| 6587 | reason_str = "online capacity expansion"; |
| 6588 | break; |
| 6589 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: |
| 6590 | reason_str = "consistency check"; |
| 6591 | break; |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 6592 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: |
| 6593 | reason_str = "background init"; |
| 6594 | break; |
| 6595 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: |
| 6596 | reason_str = "make data consistent"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6597 | break; |
| 6598 | } |
| 6599 | |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 6600 | if (!reason_str) |
| 6601 | return; |
| 6602 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6603 | printk(MPT2SAS_INFO_FMT "raid operational status: (%s)" |
| 6604 | "\thandle(0x%04x), percent complete(%d)\n", |
| 6605 | ioc->name, reason_str, |
| 6606 | le16_to_cpu(event_data->VolDevHandle), |
| 6607 | event_data->PercentComplete); |
| 6608 | } |
| 6609 | #endif |
| 6610 | |
| 6611 | /** |
| 6612 | * _scsih_sas_ir_operation_status_event - handle RAID operation events |
| 6613 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6614 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6615 | * Context: user. |
| 6616 | * |
| 6617 | * Return nothing. |
| 6618 | */ |
| 6619 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6620 | _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc, |
| 6621 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6622 | { |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6623 | Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data; |
| 6624 | static struct _raid_device *raid_device; |
| 6625 | unsigned long flags; |
| 6626 | u16 handle; |
| 6627 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6628 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6629 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6630 | && !ioc->hide_ir_msg) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6631 | _scsih_sas_ir_operation_status_event_debug(ioc, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6632 | event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6633 | #endif |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6634 | |
| 6635 | /* code added for raid transport support */ |
| 6636 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { |
| 6637 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6638 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6639 | handle = le16_to_cpu(event_data->VolDevHandle); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6640 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6641 | if (raid_device) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6642 | raid_device->percent_complete = |
| 6643 | event_data->PercentComplete; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6644 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6645 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6646 | } |
| 6647 | |
| 6648 | /** |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6649 | * _scsih_prep_device_scan - initialize parameters prior to device scan |
| 6650 | * @ioc: per adapter object |
| 6651 | * |
| 6652 | * Set the deleted flag prior to device scan. If the device is found during |
| 6653 | * the scan, then we clear the deleted flag. |
| 6654 | */ |
| 6655 | static void |
| 6656 | _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc) |
| 6657 | { |
| 6658 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 6659 | struct scsi_device *sdev; |
| 6660 | |
| 6661 | shost_for_each_device(sdev, ioc->shost) { |
| 6662 | sas_device_priv_data = sdev->hostdata; |
| 6663 | if (sas_device_priv_data && sas_device_priv_data->sas_target) |
| 6664 | sas_device_priv_data->sas_target->deleted = 1; |
| 6665 | } |
| 6666 | } |
| 6667 | |
| 6668 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6669 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding |
| 6670 | * @ioc: per adapter object |
| 6671 | * @sas_address: sas address |
| 6672 | * @slot: enclosure slot id |
| 6673 | * @handle: device handle |
| 6674 | * |
| 6675 | * After host reset, find out whether devices are still responding. |
| 6676 | * Used in _scsi_remove_unresponsive_sas_devices. |
| 6677 | * |
| 6678 | * Return nothing. |
| 6679 | */ |
| 6680 | static void |
| 6681 | _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 6682 | u16 slot, u16 handle) |
| 6683 | { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6684 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6685 | struct scsi_target *starget; |
| 6686 | struct _sas_device *sas_device; |
| 6687 | unsigned long flags; |
| 6688 | |
| 6689 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6690 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { |
| 6691 | if (sas_device->sas_address == sas_address && |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6692 | sas_device->slot == slot) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6693 | sas_device->responding = 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6694 | starget = sas_device->starget; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6695 | if (starget && starget->hostdata) { |
| 6696 | sas_target_priv_data = starget->hostdata; |
| 6697 | sas_target_priv_data->tm_busy = 0; |
| 6698 | sas_target_priv_data->deleted = 0; |
| 6699 | } else |
| 6700 | sas_target_priv_data = NULL; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6701 | if (starget) |
| 6702 | starget_printk(KERN_INFO, starget, |
| 6703 | "handle(0x%04x), sas_addr(0x%016llx), " |
| 6704 | "enclosure logical id(0x%016llx), " |
| 6705 | "slot(%d)\n", handle, |
| 6706 | (unsigned long long)sas_device->sas_address, |
| 6707 | (unsigned long long) |
| 6708 | sas_device->enclosure_logical_id, |
| 6709 | sas_device->slot); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6710 | if (sas_device->handle == handle) |
| 6711 | goto out; |
| 6712 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 6713 | sas_device->handle); |
| 6714 | sas_device->handle = handle; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6715 | if (sas_target_priv_data) |
| 6716 | sas_target_priv_data->handle = handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6717 | goto out; |
| 6718 | } |
| 6719 | } |
| 6720 | out: |
| 6721 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6722 | } |
| 6723 | |
| 6724 | /** |
| 6725 | * _scsih_search_responding_sas_devices - |
| 6726 | * @ioc: per adapter object |
| 6727 | * |
| 6728 | * After host reset, find out whether devices are still responding. |
| 6729 | * If not remove. |
| 6730 | * |
| 6731 | * Return nothing. |
| 6732 | */ |
| 6733 | static void |
| 6734 | _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6735 | { |
| 6736 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6737 | Mpi2ConfigReply_t mpi_reply; |
| 6738 | u16 ioc_status; |
| 6739 | __le64 sas_address; |
| 6740 | u16 handle; |
| 6741 | u32 device_info; |
| 6742 | u16 slot; |
| 6743 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6744 | printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6745 | |
| 6746 | if (list_empty(&ioc->sas_device_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6747 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6748 | |
| 6749 | handle = 0xFFFF; |
| 6750 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6751 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 6752 | handle))) { |
| 6753 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6754 | MPI2_IOCSTATUS_MASK; |
| 6755 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6756 | break; |
| 6757 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 6758 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 6759 | if (!(_scsih_is_end_device(device_info))) |
| 6760 | continue; |
| 6761 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 6762 | slot = le16_to_cpu(sas_device_pg0.Slot); |
| 6763 | _scsih_mark_responding_sas_device(ioc, sas_address, slot, |
| 6764 | handle); |
| 6765 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6766 | out: |
| 6767 | printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n", |
| 6768 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6769 | } |
| 6770 | |
| 6771 | /** |
| 6772 | * _scsih_mark_responding_raid_device - mark a raid_device as responding |
| 6773 | * @ioc: per adapter object |
| 6774 | * @wwid: world wide identifier for raid volume |
| 6775 | * @handle: device handle |
| 6776 | * |
| 6777 | * After host reset, find out whether devices are still responding. |
| 6778 | * Used in _scsi_remove_unresponsive_raid_devices. |
| 6779 | * |
| 6780 | * Return nothing. |
| 6781 | */ |
| 6782 | static void |
| 6783 | _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid, |
| 6784 | u16 handle) |
| 6785 | { |
| 6786 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 6787 | struct scsi_target *starget; |
| 6788 | struct _raid_device *raid_device; |
| 6789 | unsigned long flags; |
| 6790 | |
| 6791 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6792 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 6793 | if (raid_device->wwid == wwid && raid_device->starget) { |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6794 | starget = raid_device->starget; |
| 6795 | if (starget && starget->hostdata) { |
| 6796 | sas_target_priv_data = starget->hostdata; |
| 6797 | sas_target_priv_data->deleted = 0; |
| 6798 | } else |
| 6799 | sas_target_priv_data = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6800 | raid_device->responding = 1; |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6801 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6802 | starget_printk(KERN_INFO, raid_device->starget, |
| 6803 | "handle(0x%04x), wwid(0x%016llx)\n", handle, |
| 6804 | (unsigned long long)raid_device->wwid); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6805 | /* |
| 6806 | * WARPDRIVE: The handles of the PDs might have changed |
| 6807 | * across the host reset so re-initialize the |
| 6808 | * required data for Direct IO |
| 6809 | */ |
| 6810 | _scsih_init_warpdrive_properties(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6811 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6812 | if (raid_device->handle == handle) { |
| 6813 | spin_unlock_irqrestore(&ioc->raid_device_lock, |
| 6814 | flags); |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6815 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6816 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6817 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 6818 | raid_device->handle); |
| 6819 | raid_device->handle = handle; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6820 | if (sas_target_priv_data) |
| 6821 | sas_target_priv_data->handle = handle; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6822 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6823 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6824 | } |
| 6825 | } |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6826 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6827 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6828 | } |
| 6829 | |
| 6830 | /** |
| 6831 | * _scsih_search_responding_raid_devices - |
| 6832 | * @ioc: per adapter object |
| 6833 | * |
| 6834 | * After host reset, find out whether devices are still responding. |
| 6835 | * If not remove. |
| 6836 | * |
| 6837 | * Return nothing. |
| 6838 | */ |
| 6839 | static void |
| 6840 | _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6841 | { |
| 6842 | Mpi2RaidVolPage1_t volume_pg1; |
Kashyap, Desai | d417d1c | 2010-06-17 13:48:10 +0530 | [diff] [blame] | 6843 | Mpi2RaidVolPage0_t volume_pg0; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6844 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6845 | Mpi2ConfigReply_t mpi_reply; |
| 6846 | u16 ioc_status; |
| 6847 | u16 handle; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6848 | u8 phys_disk_num; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6849 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6850 | if (!ioc->ir_firmware) |
| 6851 | return; |
| 6852 | |
| 6853 | printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n", |
| 6854 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6855 | |
| 6856 | if (list_empty(&ioc->raid_device_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6857 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6858 | |
| 6859 | handle = 0xFFFF; |
| 6860 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 6861 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 6862 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6863 | MPI2_IOCSTATUS_MASK; |
| 6864 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6865 | break; |
| 6866 | handle = le16_to_cpu(volume_pg1.DevHandle); |
Kashyap, Desai | d417d1c | 2010-06-17 13:48:10 +0530 | [diff] [blame] | 6867 | |
| 6868 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 6869 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 6870 | sizeof(Mpi2RaidVolPage0_t))) |
| 6871 | continue; |
| 6872 | |
| 6873 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 6874 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 6875 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) |
| 6876 | _scsih_mark_responding_raid_device(ioc, |
| 6877 | le64_to_cpu(volume_pg1.WWID), handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6878 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6879 | |
| 6880 | /* refresh the pd_handles */ |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6881 | if (!ioc->is_warpdrive) { |
| 6882 | phys_disk_num = 0xFF; |
| 6883 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); |
| 6884 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 6885 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 6886 | phys_disk_num))) { |
| 6887 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6888 | MPI2_IOCSTATUS_MASK; |
| 6889 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6890 | break; |
| 6891 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 6892 | handle = le16_to_cpu(pd_pg0.DevHandle); |
| 6893 | set_bit(handle, ioc->pd_handles); |
| 6894 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6895 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6896 | out: |
| 6897 | printk(MPT2SAS_INFO_FMT "search for responding raid volumes: " |
| 6898 | "complete\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6899 | } |
| 6900 | |
| 6901 | /** |
| 6902 | * _scsih_mark_responding_expander - mark a expander as responding |
| 6903 | * @ioc: per adapter object |
| 6904 | * @sas_address: sas address |
| 6905 | * @handle: |
| 6906 | * |
| 6907 | * After host reset, find out whether devices are still responding. |
| 6908 | * Used in _scsi_remove_unresponsive_expanders. |
| 6909 | * |
| 6910 | * Return nothing. |
| 6911 | */ |
| 6912 | static void |
| 6913 | _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 6914 | u16 handle) |
| 6915 | { |
| 6916 | struct _sas_node *sas_expander; |
| 6917 | unsigned long flags; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6918 | int i; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6919 | |
| 6920 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 6921 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6922 | if (sas_expander->sas_address != sas_address) |
| 6923 | continue; |
| 6924 | sas_expander->responding = 1; |
| 6925 | if (sas_expander->handle == handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6926 | goto out; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6927 | printk(KERN_INFO "\texpander(0x%016llx): handle changed" |
| 6928 | " from(0x%04x) to (0x%04x)!!!\n", |
| 6929 | (unsigned long long)sas_expander->sas_address, |
| 6930 | sas_expander->handle, handle); |
| 6931 | sas_expander->handle = handle; |
| 6932 | for (i = 0 ; i < sas_expander->num_phys ; i++) |
| 6933 | sas_expander->phy[i].handle = handle; |
| 6934 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6935 | } |
| 6936 | out: |
| 6937 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 6938 | } |
| 6939 | |
| 6940 | /** |
| 6941 | * _scsih_search_responding_expanders - |
| 6942 | * @ioc: per adapter object |
| 6943 | * |
| 6944 | * After host reset, find out whether devices are still responding. |
| 6945 | * If not remove. |
| 6946 | * |
| 6947 | * Return nothing. |
| 6948 | */ |
| 6949 | static void |
| 6950 | _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc) |
| 6951 | { |
| 6952 | Mpi2ExpanderPage0_t expander_pg0; |
| 6953 | Mpi2ConfigReply_t mpi_reply; |
| 6954 | u16 ioc_status; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 6955 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6956 | u16 handle; |
| 6957 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6958 | printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6959 | |
| 6960 | if (list_empty(&ioc->sas_expander_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6961 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6962 | |
| 6963 | handle = 0xFFFF; |
| 6964 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 6965 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 6966 | |
| 6967 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6968 | MPI2_IOCSTATUS_MASK; |
| 6969 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6970 | break; |
| 6971 | |
| 6972 | handle = le16_to_cpu(expander_pg0.DevHandle); |
| 6973 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
| 6974 | printk(KERN_INFO "\texpander present: handle(0x%04x), " |
| 6975 | "sas_addr(0x%016llx)\n", handle, |
| 6976 | (unsigned long long)sas_address); |
| 6977 | _scsih_mark_responding_expander(ioc, sas_address, handle); |
| 6978 | } |
| 6979 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6980 | out: |
| 6981 | printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6982 | } |
| 6983 | |
| 6984 | /** |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6985 | * _scsih_remove_unresponding_sas_devices - removing unresponding devices |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6986 | * @ioc: per adapter object |
| 6987 | * |
| 6988 | * Return nothing. |
| 6989 | */ |
| 6990 | static void |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6991 | _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6992 | { |
| 6993 | struct _sas_device *sas_device, *sas_device_next; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6994 | struct _sas_node *sas_expander, *sas_expander_next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6995 | struct _raid_device *raid_device, *raid_device_next; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6996 | struct list_head tmp_list; |
| 6997 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6998 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6999 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n", |
| 7000 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7001 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7002 | /* removing unresponding end devices */ |
| 7003 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n", |
| 7004 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7005 | list_for_each_entry_safe(sas_device, sas_device_next, |
| 7006 | &ioc->sas_device_list, list) { |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7007 | if (!sas_device->responding) |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 7008 | mpt2sas_device_remove_by_sas_address(ioc, |
| 7009 | sas_device->sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7010 | else |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7011 | sas_device->responding = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7012 | } |
| 7013 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7014 | /* removing unresponding volumes */ |
| 7015 | if (ioc->ir_firmware) { |
| 7016 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: " |
| 7017 | "volumes\n", ioc->name); |
| 7018 | list_for_each_entry_safe(raid_device, raid_device_next, |
| 7019 | &ioc->raid_device_list, list) { |
| 7020 | if (!raid_device->responding) |
| 7021 | _scsih_sas_volume_delete(ioc, |
| 7022 | raid_device->handle); |
| 7023 | else |
| 7024 | raid_device->responding = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7025 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7026 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7027 | /* removing unresponding expanders */ |
| 7028 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n", |
| 7029 | ioc->name); |
| 7030 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 7031 | INIT_LIST_HEAD(&tmp_list); |
| 7032 | list_for_each_entry_safe(sas_expander, sas_expander_next, |
| 7033 | &ioc->sas_expander_list, list) { |
| 7034 | if (!sas_expander->responding) |
| 7035 | list_move_tail(&sas_expander->list, &tmp_list); |
| 7036 | else |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7037 | sas_expander->responding = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7038 | } |
| 7039 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 7040 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, |
| 7041 | list) { |
| 7042 | list_del(&sas_expander->list); |
| 7043 | _scsih_expander_node_remove(ioc, sas_expander); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7044 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7045 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n", |
| 7046 | ioc->name); |
| 7047 | /* unblock devices */ |
| 7048 | _scsih_ublock_io_all_device(ioc); |
| 7049 | } |
| 7050 | |
| 7051 | static void |
| 7052 | _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc, |
| 7053 | struct _sas_node *sas_expander, u16 handle) |
| 7054 | { |
| 7055 | Mpi2ExpanderPage1_t expander_pg1; |
| 7056 | Mpi2ConfigReply_t mpi_reply; |
| 7057 | int i; |
| 7058 | |
| 7059 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 7060 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 7061 | &expander_pg1, i, handle))) { |
| 7062 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7063 | ioc->name, __FILE__, __LINE__, __func__); |
| 7064 | return; |
| 7065 | } |
| 7066 | |
| 7067 | mpt2sas_transport_update_links(ioc, sas_expander->sas_address, |
| 7068 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, |
| 7069 | expander_pg1.NegotiatedLinkRate >> 4); |
| 7070 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7071 | } |
| 7072 | |
| 7073 | /** |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7074 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7075 | * @ioc: per adapter object |
| 7076 | * |
| 7077 | * Return nothing. |
| 7078 | */ |
| 7079 | static void |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7080 | _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc) |
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 | Mpi2ExpanderPage0_t expander_pg0; |
| 7083 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 7084 | Mpi2RaidVolPage1_t volume_pg1; |
| 7085 | Mpi2RaidVolPage0_t volume_pg0; |
| 7086 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 7087 | Mpi2EventIrConfigElement_t element; |
| 7088 | Mpi2ConfigReply_t mpi_reply; |
| 7089 | u8 phys_disk_num; |
| 7090 | u16 ioc_status; |
| 7091 | u16 handle, parent_handle; |
| 7092 | u64 sas_address; |
| 7093 | struct _sas_device *sas_device; |
| 7094 | struct _sas_node *expander_device; |
| 7095 | static struct _raid_device *raid_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7096 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7097 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7098 | printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7099 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7100 | _scsih_sas_host_refresh(ioc); |
| 7101 | |
| 7102 | /* expanders */ |
| 7103 | handle = 0xFFFF; |
| 7104 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 7105 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 7106 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7107 | MPI2_IOCSTATUS_MASK; |
| 7108 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 7109 | break; |
| 7110 | handle = le16_to_cpu(expander_pg0.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7111 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7112 | expander_device = mpt2sas_scsih_expander_find_by_sas_address( |
| 7113 | ioc, le64_to_cpu(expander_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7114 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7115 | if (expander_device) |
| 7116 | _scsih_refresh_expander_links(ioc, expander_device, |
| 7117 | handle); |
| 7118 | else |
| 7119 | _scsih_expander_add(ioc, handle); |
| 7120 | } |
| 7121 | |
| 7122 | if (!ioc->ir_firmware) |
| 7123 | goto skip_to_sas; |
| 7124 | |
| 7125 | /* phys disk */ |
| 7126 | phys_disk_num = 0xFF; |
| 7127 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 7128 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 7129 | phys_disk_num))) { |
| 7130 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7131 | MPI2_IOCSTATUS_MASK; |
| 7132 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 7133 | break; |
| 7134 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 7135 | handle = le16_to_cpu(pd_pg0.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7136 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7137 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7138 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7139 | if (sas_device) |
| 7140 | continue; |
| 7141 | if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 7142 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 7143 | handle) != 0) |
| 7144 | continue; |
| 7145 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 7146 | if (!_scsih_get_sas_address(ioc, parent_handle, |
| 7147 | &sas_address)) { |
| 7148 | mpt2sas_transport_update_links(ioc, sas_address, |
| 7149 | handle, sas_device_pg0.PhyNum, |
| 7150 | MPI2_SAS_NEG_LINK_RATE_1_5); |
| 7151 | set_bit(handle, ioc->pd_handles); |
| 7152 | _scsih_add_device(ioc, handle, 0, 1); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7153 | } |
| 7154 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7155 | |
| 7156 | /* volumes */ |
| 7157 | handle = 0xFFFF; |
| 7158 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 7159 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 7160 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7161 | MPI2_IOCSTATUS_MASK; |
| 7162 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 7163 | break; |
| 7164 | handle = le16_to_cpu(volume_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7165 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7166 | raid_device = _scsih_raid_device_find_by_wwid(ioc, |
| 7167 | le64_to_cpu(volume_pg1.WWID)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7168 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7169 | if (raid_device) |
| 7170 | continue; |
| 7171 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 7172 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 7173 | sizeof(Mpi2RaidVolPage0_t))) |
| 7174 | continue; |
| 7175 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 7176 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 7177 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { |
| 7178 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); |
| 7179 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; |
| 7180 | element.VolDevHandle = volume_pg1.DevHandle; |
| 7181 | _scsih_sas_volume_add(ioc, &element); |
| 7182 | } |
| 7183 | } |
| 7184 | |
| 7185 | skip_to_sas: |
| 7186 | |
| 7187 | /* sas devices */ |
| 7188 | handle = 0xFFFF; |
| 7189 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 7190 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 7191 | handle))) { |
| 7192 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7193 | MPI2_IOCSTATUS_MASK; |
| 7194 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 7195 | break; |
| 7196 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 7197 | if (!(_scsih_is_end_device( |
| 7198 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) |
| 7199 | continue; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7200 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7201 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 7202 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7203 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7204 | if (sas_device) |
| 7205 | continue; |
| 7206 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 7207 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { |
| 7208 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 7209 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
| 7210 | _scsih_add_device(ioc, handle, 0, 0); |
| 7211 | } |
| 7212 | } |
| 7213 | |
| 7214 | printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7215 | } |
| 7216 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7217 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7218 | /** |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7219 | * mpt2sas_scsih_reset_handler - reset callback handler (for scsih) |
| 7220 | * @ioc: per adapter object |
| 7221 | * @reset_phase: phase |
| 7222 | * |
| 7223 | * The handler for doing any required cleanup or initialization. |
| 7224 | * |
| 7225 | * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET, |
| 7226 | * MPT2_IOC_DONE_RESET |
| 7227 | * |
| 7228 | * Return nothing. |
| 7229 | */ |
| 7230 | void |
| 7231 | mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase) |
| 7232 | { |
| 7233 | switch (reset_phase) { |
| 7234 | case MPT2_IOC_PRE_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7235 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7236 | "MPT2_IOC_PRE_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7237 | break; |
| 7238 | case MPT2_IOC_AFTER_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7239 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7240 | "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7241 | if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) { |
| 7242 | ioc->scsih_cmds.status |= MPT2_CMD_RESET; |
| 7243 | mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid); |
| 7244 | complete(&ioc->scsih_cmds.done); |
| 7245 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7246 | if (ioc->tm_cmds.status & MPT2_CMD_PENDING) { |
| 7247 | ioc->tm_cmds.status |= MPT2_CMD_RESET; |
| 7248 | mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid); |
| 7249 | complete(&ioc->tm_cmds.done); |
| 7250 | } |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7251 | _scsih_fw_event_cleanup_queue(ioc); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7252 | _scsih_flush_running_cmds(ioc); |
| 7253 | break; |
| 7254 | case MPT2_IOC_DONE_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7255 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7256 | "MPT2_IOC_DONE_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7257 | _scsih_sas_host_refresh(ioc); |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 7258 | _scsih_prep_device_scan(ioc); |
| 7259 | _scsih_search_responding_sas_devices(ioc); |
| 7260 | _scsih_search_responding_raid_devices(ioc); |
| 7261 | _scsih_search_responding_expanders(ioc); |
sreekanth.reddy@lsi.com | 14aa7f7 | 2012-07-17 15:56:13 +0530 | [diff] [blame] | 7262 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && |
| 7263 | !ioc->sas_hba.num_phys)) { |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7264 | _scsih_prep_device_scan(ioc); |
| 7265 | _scsih_search_responding_sas_devices(ioc); |
| 7266 | _scsih_search_responding_raid_devices(ioc); |
| 7267 | _scsih_search_responding_expanders(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7268 | _scsih_error_recovery_delete_devices(ioc); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7269 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7270 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7271 | } |
| 7272 | } |
| 7273 | |
| 7274 | /** |
| 7275 | * _firmware_event_work - delayed task for processing firmware events |
| 7276 | * @ioc: per adapter object |
| 7277 | * @work: equal to the fw_event_work object |
| 7278 | * Context: user. |
| 7279 | * |
| 7280 | * Return nothing. |
| 7281 | */ |
| 7282 | static void |
| 7283 | _firmware_event_work(struct work_struct *work) |
| 7284 | { |
| 7285 | struct fw_event_work *fw_event = container_of(work, |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7286 | struct fw_event_work, delayed_work.work); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7287 | struct MPT2SAS_ADAPTER *ioc = fw_event->ioc; |
| 7288 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7289 | /* the queue is being flushed so ignore this event */ |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7290 | if (ioc->remove_host || fw_event->cancel_pending_work || |
| 7291 | ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7292 | _scsih_fw_event_free(ioc, fw_event); |
| 7293 | return; |
| 7294 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7295 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7296 | switch (fw_event->event) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7297 | case MPT2SAS_REMOVE_UNRESPONDING_DEVICES: |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7298 | while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7299 | ssleep(1); |
| 7300 | _scsih_remove_unresponding_sas_devices(ioc); |
| 7301 | _scsih_scan_for_devices_after_reset(ioc); |
| 7302 | break; |
| 7303 | case MPT2SAS_PORT_ENABLE_COMPLETE: |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7304 | ioc->start_scan = 0; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7305 | |
| 7306 | |
| 7307 | |
| 7308 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete " |
| 7309 | "from worker thread\n", ioc->name)); |
| 7310 | break; |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 7311 | case MPT2SAS_TURN_ON_FAULT_LED: |
| 7312 | _scsih_turn_on_fault_led(ioc, fw_event->device_handle); |
| 7313 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7314 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7315 | _scsih_sas_topology_change_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7316 | break; |
| 7317 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7318 | _scsih_sas_device_status_change_event(ioc, |
| 7319 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7320 | break; |
| 7321 | case MPI2_EVENT_SAS_DISCOVERY: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7322 | _scsih_sas_discovery_event(ioc, |
| 7323 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7324 | break; |
| 7325 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 7326 | _scsih_sas_broadcast_primitive_event(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7327 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7328 | break; |
| 7329 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
| 7330 | _scsih_sas_enclosure_dev_status_change_event(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7331 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7332 | break; |
| 7333 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7334 | _scsih_sas_ir_config_change_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7335 | break; |
| 7336 | case MPI2_EVENT_IR_VOLUME: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7337 | _scsih_sas_ir_volume_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7338 | break; |
| 7339 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7340 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7341 | break; |
| 7342 | case MPI2_EVENT_IR_OPERATION_STATUS: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7343 | _scsih_sas_ir_operation_status_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7344 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7345 | } |
| 7346 | _scsih_fw_event_free(ioc, fw_event); |
| 7347 | } |
| 7348 | |
| 7349 | /** |
| 7350 | * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time) |
| 7351 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7352 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7353 | * @reply: reply message frame(lower 32bit addr) |
| 7354 | * Context: interrupt. |
| 7355 | * |
| 7356 | * This function merely adds a new work task into ioc->firmware_event_thread. |
| 7357 | * The tasks are worked from _firmware_event_work in user context. |
| 7358 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7359 | * Return 1 meaning mf should be freed from _base_interrupt |
| 7360 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7361 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7362 | u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7363 | mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, |
| 7364 | u32 reply) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7365 | { |
| 7366 | struct fw_event_work *fw_event; |
| 7367 | Mpi2EventNotificationReply_t *mpi_reply; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7368 | u16 event; |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 7369 | u16 sz; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7370 | |
| 7371 | /* events turned off due to host reset or driver unloading */ |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7372 | if (ioc->remove_host || ioc->pci_error_recovery) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7373 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7374 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7375 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 7376 | |
| 7377 | if (unlikely(!mpi_reply)) { |
| 7378 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 7379 | ioc->name, __FILE__, __LINE__, __func__); |
| 7380 | return 1; |
| 7381 | } |
| 7382 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7383 | event = le16_to_cpu(mpi_reply->Event); |
| 7384 | |
| 7385 | switch (event) { |
| 7386 | /* handle these */ |
| 7387 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 7388 | { |
| 7389 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = |
| 7390 | (Mpi2EventDataSasBroadcastPrimitive_t *) |
| 7391 | mpi_reply->EventData; |
| 7392 | |
| 7393 | if (baen_data->Primitive != |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7394 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7395 | return 1; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7396 | |
| 7397 | if (ioc->broadcast_aen_busy) { |
| 7398 | ioc->broadcast_aen_pending++; |
| 7399 | return 1; |
| 7400 | } else |
| 7401 | ioc->broadcast_aen_busy = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7402 | break; |
| 7403 | } |
| 7404 | |
| 7405 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
| 7406 | _scsih_check_topo_delete_events(ioc, |
| 7407 | (Mpi2EventDataSasTopologyChangeList_t *) |
| 7408 | mpi_reply->EventData); |
| 7409 | break; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 7410 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
| 7411 | _scsih_check_ir_config_unhide_events(ioc, |
| 7412 | (Mpi2EventDataIrConfigChangeList_t *) |
| 7413 | mpi_reply->EventData); |
| 7414 | break; |
| 7415 | case MPI2_EVENT_IR_VOLUME: |
| 7416 | _scsih_check_volume_delete_events(ioc, |
| 7417 | (Mpi2EventDataIrVolume_t *) |
| 7418 | mpi_reply->EventData); |
| 7419 | break; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7420 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
| 7421 | { |
| 7422 | Mpi2EventDataLogEntryAdded_t *log_entry; |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 7423 | __le32 *log_code; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7424 | |
| 7425 | if (!ioc->is_warpdrive) |
| 7426 | break; |
| 7427 | |
| 7428 | log_entry = (Mpi2EventDataLogEntryAdded_t *) |
| 7429 | mpi_reply->EventData; |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 7430 | log_code = (__le32 *)log_entry->LogData; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7431 | |
| 7432 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
| 7433 | != MPT2_WARPDRIVE_LOGENTRY) |
| 7434 | break; |
| 7435 | |
| 7436 | switch (le32_to_cpu(*log_code)) { |
| 7437 | case MPT2_WARPDRIVE_LC_SSDT: |
| 7438 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " |
| 7439 | "IO Throttling has occurred in the WarpDrive " |
| 7440 | "subsystem. Check WarpDrive documentation for " |
| 7441 | "additional details.\n", ioc->name); |
| 7442 | break; |
| 7443 | case MPT2_WARPDRIVE_LC_SSDLW: |
| 7444 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " |
| 7445 | "Program/Erase Cycles for the WarpDrive subsystem " |
| 7446 | "in degraded range. Check WarpDrive documentation " |
| 7447 | "for additional details.\n", ioc->name); |
| 7448 | break; |
| 7449 | case MPT2_WARPDRIVE_LC_SSDLF: |
| 7450 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " |
| 7451 | "There are no Program/Erase Cycles for the " |
| 7452 | "WarpDrive subsystem. The storage device will be " |
| 7453 | "in read-only mode. Check WarpDrive documentation " |
| 7454 | "for additional details.\n", ioc->name); |
| 7455 | break; |
| 7456 | case MPT2_WARPDRIVE_LC_BRMF: |
| 7457 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " |
| 7458 | "The Backup Rail Monitor has failed on the " |
| 7459 | "WarpDrive subsystem. Check WarpDrive " |
| 7460 | "documentation for additional details.\n", |
| 7461 | ioc->name); |
| 7462 | break; |
| 7463 | } |
| 7464 | |
| 7465 | break; |
| 7466 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7467 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 7468 | case MPI2_EVENT_IR_OPERATION_STATUS: |
| 7469 | case MPI2_EVENT_SAS_DISCOVERY: |
| 7470 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7471 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7472 | break; |
| 7473 | |
| 7474 | default: /* ignore the rest */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7475 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7476 | } |
| 7477 | |
| 7478 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 7479 | if (!fw_event) { |
| 7480 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7481 | ioc->name, __FILE__, __LINE__, __func__); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7482 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7483 | } |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 7484 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
| 7485 | fw_event->event_data = kzalloc(sz, GFP_ATOMIC); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7486 | if (!fw_event->event_data) { |
| 7487 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7488 | ioc->name, __FILE__, __LINE__, __func__); |
| 7489 | kfree(fw_event); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7490 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7491 | } |
| 7492 | |
| 7493 | memcpy(fw_event->event_data, mpi_reply->EventData, |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 7494 | sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7495 | fw_event->ioc = ioc; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7496 | fw_event->VF_ID = mpi_reply->VF_ID; |
| 7497 | fw_event->VP_ID = mpi_reply->VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7498 | fw_event->event = event; |
| 7499 | _scsih_fw_event_add(ioc, fw_event); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7500 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7501 | } |
| 7502 | |
| 7503 | /* shost template */ |
| 7504 | static struct scsi_host_template scsih_driver_template = { |
| 7505 | .module = THIS_MODULE, |
| 7506 | .name = "Fusion MPT SAS Host", |
| 7507 | .proc_name = MPT2SAS_DRIVER_NAME, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7508 | .queuecommand = _scsih_qcmd, |
| 7509 | .target_alloc = _scsih_target_alloc, |
| 7510 | .slave_alloc = _scsih_slave_alloc, |
| 7511 | .slave_configure = _scsih_slave_configure, |
| 7512 | .target_destroy = _scsih_target_destroy, |
| 7513 | .slave_destroy = _scsih_slave_destroy, |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7514 | .scan_finished = _scsih_scan_finished, |
| 7515 | .scan_start = _scsih_scan_start, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7516 | .change_queue_depth = _scsih_change_queue_depth, |
| 7517 | .change_queue_type = _scsih_change_queue_type, |
| 7518 | .eh_abort_handler = _scsih_abort, |
| 7519 | .eh_device_reset_handler = _scsih_dev_reset, |
| 7520 | .eh_target_reset_handler = _scsih_target_reset, |
| 7521 | .eh_host_reset_handler = _scsih_host_reset, |
| 7522 | .bios_param = _scsih_bios_param, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7523 | .can_queue = 1, |
| 7524 | .this_id = -1, |
| 7525 | .sg_tablesize = MPT2SAS_SG_DEPTH, |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 7526 | .max_sectors = 32767, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7527 | .cmd_per_lun = 7, |
| 7528 | .use_clustering = ENABLE_CLUSTERING, |
| 7529 | .shost_attrs = mpt2sas_host_attrs, |
| 7530 | .sdev_attrs = mpt2sas_dev_attrs, |
| 7531 | }; |
| 7532 | |
| 7533 | /** |
| 7534 | * _scsih_expander_node_remove - removing expander device from list. |
| 7535 | * @ioc: per adapter object |
| 7536 | * @sas_expander: the sas_device object |
| 7537 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 7538 | * |
| 7539 | * Removing object and freeing associated memory from the |
| 7540 | * ioc->sas_expander_list. |
| 7541 | * |
| 7542 | * Return nothing. |
| 7543 | */ |
| 7544 | static void |
| 7545 | _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc, |
| 7546 | struct _sas_node *sas_expander) |
| 7547 | { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7548 | struct _sas_port *mpt2sas_port, *next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7549 | |
| 7550 | /* remove sibling ports attached to this expander */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7551 | list_for_each_entry_safe(mpt2sas_port, next, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7552 | &sas_expander->sas_port_list, port_list) { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7553 | if (ioc->shost_recovery) |
| 7554 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7555 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7556 | SAS_END_DEVICE) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7557 | mpt2sas_device_remove_by_sas_address(ioc, |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7558 | mpt2sas_port->remote_identify.sas_address); |
| 7559 | else if (mpt2sas_port->remote_identify.device_type == |
| 7560 | SAS_EDGE_EXPANDER_DEVICE || |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7561 | mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7562 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7563 | mpt2sas_expander_remove(ioc, |
| 7564 | mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7565 | } |
| 7566 | |
| 7567 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7568 | sas_expander->sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7569 | |
| 7570 | printk(MPT2SAS_INFO_FMT "expander_remove: handle" |
| 7571 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, |
| 7572 | sas_expander->handle, (unsigned long long) |
| 7573 | sas_expander->sas_address); |
| 7574 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7575 | kfree(sas_expander->phy); |
| 7576 | kfree(sas_expander); |
| 7577 | } |
| 7578 | |
| 7579 | /** |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7580 | * _scsih_ir_shutdown - IR shutdown notification |
| 7581 | * @ioc: per adapter object |
| 7582 | * |
| 7583 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that |
| 7584 | * the host system is shutting down. |
| 7585 | * |
| 7586 | * Return nothing. |
| 7587 | */ |
| 7588 | static void |
| 7589 | _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc) |
| 7590 | { |
| 7591 | Mpi2RaidActionRequest_t *mpi_request; |
| 7592 | Mpi2RaidActionReply_t *mpi_reply; |
| 7593 | u16 smid; |
| 7594 | |
| 7595 | /* is IR firmware build loaded ? */ |
| 7596 | if (!ioc->ir_firmware) |
| 7597 | return; |
| 7598 | |
| 7599 | /* are there any volumes ? */ |
| 7600 | if (list_empty(&ioc->raid_device_list)) |
| 7601 | return; |
| 7602 | |
| 7603 | mutex_lock(&ioc->scsih_cmds.mutex); |
| 7604 | |
| 7605 | if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) { |
| 7606 | printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n", |
| 7607 | ioc->name, __func__); |
| 7608 | goto out; |
| 7609 | } |
| 7610 | ioc->scsih_cmds.status = MPT2_CMD_PENDING; |
| 7611 | |
| 7612 | smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx); |
| 7613 | if (!smid) { |
| 7614 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 7615 | ioc->name, __func__); |
| 7616 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; |
| 7617 | goto out; |
| 7618 | } |
| 7619 | |
| 7620 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 7621 | ioc->scsih_cmds.smid = smid; |
| 7622 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); |
| 7623 | |
| 7624 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; |
| 7625 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; |
| 7626 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7627 | if (!ioc->hide_ir_msg) |
| 7628 | printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7629 | init_completion(&ioc->scsih_cmds.done); |
| 7630 | mpt2sas_base_put_smid_default(ioc, smid); |
| 7631 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
| 7632 | |
| 7633 | if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) { |
| 7634 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 7635 | ioc->name, __func__); |
| 7636 | goto out; |
| 7637 | } |
| 7638 | |
| 7639 | if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 7640 | mpi_reply = ioc->scsih_cmds.reply; |
| 7641 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7642 | if (!ioc->hide_ir_msg) |
| 7643 | printk(MPT2SAS_INFO_FMT "IR shutdown (complete): " |
| 7644 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7645 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 7646 | le32_to_cpu(mpi_reply->IOCLogInfo)); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7647 | } |
| 7648 | |
| 7649 | out: |
| 7650 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; |
| 7651 | mutex_unlock(&ioc->scsih_cmds.mutex); |
| 7652 | } |
| 7653 | |
| 7654 | /** |
| 7655 | * _scsih_shutdown - routine call during system shutdown |
| 7656 | * @pdev: PCI device struct |
| 7657 | * |
| 7658 | * Return nothing. |
| 7659 | */ |
| 7660 | static void |
| 7661 | _scsih_shutdown(struct pci_dev *pdev) |
| 7662 | { |
| 7663 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7664 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7665 | struct workqueue_struct *wq; |
| 7666 | unsigned long flags; |
| 7667 | |
| 7668 | ioc->remove_host = 1; |
| 7669 | _scsih_fw_event_cleanup_queue(ioc); |
| 7670 | |
| 7671 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7672 | wq = ioc->firmware_event_thread; |
| 7673 | ioc->firmware_event_thread = NULL; |
| 7674 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7675 | if (wq) |
| 7676 | destroy_workqueue(wq); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7677 | |
| 7678 | _scsih_ir_shutdown(ioc); |
| 7679 | mpt2sas_base_detach(ioc); |
| 7680 | } |
| 7681 | |
| 7682 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7683 | * _scsih_remove - detach and remove add host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7684 | * @pdev: PCI device struct |
| 7685 | * |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7686 | * Routine called when unloading the driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7687 | * Return nothing. |
| 7688 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame^] | 7689 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7690 | _scsih_remove(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7691 | { |
| 7692 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7693 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7694 | struct _sas_port *mpt2sas_port, *next_port; |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7695 | struct _raid_device *raid_device, *next; |
| 7696 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7697 | struct workqueue_struct *wq; |
| 7698 | unsigned long flags; |
| 7699 | |
| 7700 | ioc->remove_host = 1; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7701 | _scsih_fw_event_cleanup_queue(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7702 | |
| 7703 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7704 | wq = ioc->firmware_event_thread; |
| 7705 | ioc->firmware_event_thread = NULL; |
| 7706 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7707 | if (wq) |
| 7708 | destroy_workqueue(wq); |
| 7709 | |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7710 | /* release all the volumes */ |
Kashyap, Desai | 3a9c913 | 2011-01-04 11:40:23 +0530 | [diff] [blame] | 7711 | _scsih_ir_shutdown(ioc); |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7712 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, |
| 7713 | list) { |
| 7714 | if (raid_device->starget) { |
| 7715 | sas_target_priv_data = |
| 7716 | raid_device->starget->hostdata; |
| 7717 | sas_target_priv_data->deleted = 1; |
| 7718 | scsi_remove_target(&raid_device->starget->dev); |
| 7719 | } |
| 7720 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" |
| 7721 | "(0x%016llx)\n", ioc->name, raid_device->handle, |
| 7722 | (unsigned long long) raid_device->wwid); |
| 7723 | _scsih_raid_device_remove(ioc, raid_device); |
| 7724 | } |
| 7725 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7726 | /* free ports attached to the sas_host */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7727 | list_for_each_entry_safe(mpt2sas_port, next_port, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7728 | &ioc->sas_hba.sas_port_list, port_list) { |
| 7729 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7730 | SAS_END_DEVICE) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7731 | mpt2sas_device_remove_by_sas_address(ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7732 | mpt2sas_port->remote_identify.sas_address); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7733 | else if (mpt2sas_port->remote_identify.device_type == |
| 7734 | SAS_EDGE_EXPANDER_DEVICE || |
| 7735 | mpt2sas_port->remote_identify.device_type == |
| 7736 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7737 | mpt2sas_expander_remove(ioc, |
| 7738 | mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7739 | } |
| 7740 | |
| 7741 | /* free phys attached to the sas_host */ |
| 7742 | if (ioc->sas_hba.num_phys) { |
| 7743 | kfree(ioc->sas_hba.phy); |
| 7744 | ioc->sas_hba.phy = NULL; |
| 7745 | ioc->sas_hba.num_phys = 0; |
| 7746 | } |
| 7747 | |
| 7748 | sas_remove_host(shost); |
kashyap.desai@lsi.com | 9ae89b0 | 2011-08-04 16:47:50 +0530 | [diff] [blame] | 7749 | mpt2sas_base_detach(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7750 | list_del(&ioc->list); |
| 7751 | scsi_remove_host(shost); |
| 7752 | scsi_host_put(shost); |
| 7753 | } |
| 7754 | |
| 7755 | /** |
| 7756 | * _scsih_probe_boot_devices - reports 1st device |
| 7757 | * @ioc: per adapter object |
| 7758 | * |
| 7759 | * If specified in bios page 2, this routine reports the 1st |
| 7760 | * device scsi-ml or sas transport for persistent boot device |
| 7761 | * purposes. Please refer to function _scsih_determine_boot_device() |
| 7762 | */ |
| 7763 | static void |
| 7764 | _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc) |
| 7765 | { |
| 7766 | u8 is_raid; |
| 7767 | void *device; |
| 7768 | struct _sas_device *sas_device; |
| 7769 | struct _raid_device *raid_device; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7770 | u16 handle; |
| 7771 | u64 sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7772 | u64 sas_address; |
| 7773 | unsigned long flags; |
| 7774 | int rc; |
| 7775 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7776 | /* no Bios, return immediately */ |
| 7777 | if (!ioc->bios_pg3.BiosVersion) |
| 7778 | return; |
| 7779 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7780 | device = NULL; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7781 | is_raid = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7782 | if (ioc->req_boot_device.device) { |
| 7783 | device = ioc->req_boot_device.device; |
| 7784 | is_raid = ioc->req_boot_device.is_raid; |
| 7785 | } else if (ioc->req_alt_boot_device.device) { |
| 7786 | device = ioc->req_alt_boot_device.device; |
| 7787 | is_raid = ioc->req_alt_boot_device.is_raid; |
| 7788 | } else if (ioc->current_boot_device.device) { |
| 7789 | device = ioc->current_boot_device.device; |
| 7790 | is_raid = ioc->current_boot_device.is_raid; |
| 7791 | } |
| 7792 | |
| 7793 | if (!device) |
| 7794 | return; |
| 7795 | |
| 7796 | if (is_raid) { |
| 7797 | raid_device = device; |
| 7798 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7799 | raid_device->id, 0); |
| 7800 | if (rc) |
| 7801 | _scsih_raid_device_remove(ioc, raid_device); |
| 7802 | } else { |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7803 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7804 | sas_device = device; |
| 7805 | handle = sas_device->handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7806 | sas_address_parent = sas_device->sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7807 | sas_address = sas_device->sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7808 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 7809 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7810 | |
| 7811 | if (ioc->hide_drives) |
| 7812 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7813 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7814 | sas_device->sas_address_parent)) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7815 | _scsih_sas_device_remove(ioc, sas_device); |
| 7816 | } else if (!sas_device->starget) { |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 7817 | if (!ioc->is_driver_loading) |
| 7818 | mpt2sas_transport_port_remove(ioc, sas_address, |
| 7819 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7820 | _scsih_sas_device_remove(ioc, sas_device); |
| 7821 | } |
| 7822 | } |
| 7823 | } |
| 7824 | |
| 7825 | /** |
| 7826 | * _scsih_probe_raid - reporting raid volumes to scsi-ml |
| 7827 | * @ioc: per adapter object |
| 7828 | * |
| 7829 | * Called during initial loading of the driver. |
| 7830 | */ |
| 7831 | static void |
| 7832 | _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc) |
| 7833 | { |
| 7834 | struct _raid_device *raid_device, *raid_next; |
| 7835 | int rc; |
| 7836 | |
| 7837 | list_for_each_entry_safe(raid_device, raid_next, |
| 7838 | &ioc->raid_device_list, list) { |
| 7839 | if (raid_device->starget) |
| 7840 | continue; |
| 7841 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7842 | raid_device->id, 0); |
| 7843 | if (rc) |
| 7844 | _scsih_raid_device_remove(ioc, raid_device); |
| 7845 | } |
| 7846 | } |
| 7847 | |
| 7848 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7849 | * _scsih_probe_sas - reporting sas devices to sas transport |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7850 | * @ioc: per adapter object |
| 7851 | * |
| 7852 | * Called during initial loading of the driver. |
| 7853 | */ |
| 7854 | static void |
| 7855 | _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc) |
| 7856 | { |
| 7857 | struct _sas_device *sas_device, *next; |
| 7858 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7859 | |
| 7860 | /* SAS Device List */ |
| 7861 | list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list, |
| 7862 | list) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7863 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7864 | if (ioc->hide_drives) |
| 7865 | continue; |
| 7866 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7867 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
| 7868 | sas_device->sas_address_parent)) { |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 7869 | list_del(&sas_device->list); |
| 7870 | kfree(sas_device); |
| 7871 | continue; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7872 | } else if (!sas_device->starget) { |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 7873 | if (!ioc->is_driver_loading) |
| 7874 | mpt2sas_transport_port_remove(ioc, |
| 7875 | sas_device->sas_address, |
| 7876 | sas_device->sas_address_parent); |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 7877 | list_del(&sas_device->list); |
| 7878 | kfree(sas_device); |
| 7879 | continue; |
| 7880 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7881 | } |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 7882 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 7883 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 7884 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7885 | } |
| 7886 | } |
| 7887 | |
| 7888 | /** |
| 7889 | * _scsih_probe_devices - probing for devices |
| 7890 | * @ioc: per adapter object |
| 7891 | * |
| 7892 | * Called during initial loading of the driver. |
| 7893 | */ |
| 7894 | static void |
| 7895 | _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc) |
| 7896 | { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7897 | u16 volume_mapping_flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7898 | |
| 7899 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) |
| 7900 | return; /* return when IOC doesn't support initiator mode */ |
| 7901 | |
| 7902 | _scsih_probe_boot_devices(ioc); |
| 7903 | |
| 7904 | if (ioc->ir_firmware) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7905 | volume_mapping_flags = |
| 7906 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & |
| 7907 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; |
| 7908 | if (volume_mapping_flags == |
| 7909 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7910 | _scsih_probe_raid(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7911 | _scsih_probe_sas(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7912 | } else { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7913 | _scsih_probe_sas(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7914 | _scsih_probe_raid(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7915 | } |
| 7916 | } else |
| 7917 | _scsih_probe_sas(ioc); |
| 7918 | } |
| 7919 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7920 | |
| 7921 | /** |
| 7922 | * _scsih_scan_start - scsi lld callback for .scan_start |
| 7923 | * @shost: SCSI host pointer |
| 7924 | * |
| 7925 | * The shost has the ability to discover targets on its own instead |
| 7926 | * of scanning the entire bus. In our implemention, we will kick off |
| 7927 | * firmware discovery. |
| 7928 | */ |
| 7929 | static void |
| 7930 | _scsih_scan_start(struct Scsi_Host *shost) |
| 7931 | { |
| 7932 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 7933 | int rc; |
| 7934 | |
| 7935 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) |
| 7936 | mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable); |
| 7937 | |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 7938 | if (disable_discovery > 0) |
| 7939 | return; |
| 7940 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7941 | ioc->start_scan = 1; |
| 7942 | rc = mpt2sas_port_enable(ioc); |
| 7943 | |
| 7944 | if (rc != 0) |
| 7945 | printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name); |
| 7946 | } |
| 7947 | |
| 7948 | /** |
| 7949 | * _scsih_scan_finished - scsi lld callback for .scan_finished |
| 7950 | * @shost: SCSI host pointer |
| 7951 | * @time: elapsed time of the scan in jiffies |
| 7952 | * |
| 7953 | * This function will be called periodically until it returns 1 with the |
| 7954 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, |
| 7955 | * we wait for firmware discovery to complete, then return 1. |
| 7956 | */ |
| 7957 | static int |
| 7958 | _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 7959 | { |
| 7960 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 7961 | |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 7962 | if (disable_discovery > 0) { |
| 7963 | ioc->is_driver_loading = 0; |
| 7964 | ioc->wait_for_discovery_to_complete = 0; |
| 7965 | return 1; |
| 7966 | } |
| 7967 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7968 | if (time >= (300 * HZ)) { |
| 7969 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 7970 | printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout " |
| 7971 | "(timeout=300s)\n", ioc->name); |
| 7972 | ioc->is_driver_loading = 0; |
| 7973 | return 1; |
| 7974 | } |
| 7975 | |
| 7976 | if (ioc->start_scan) |
| 7977 | return 0; |
| 7978 | |
| 7979 | if (ioc->start_scan_failed) { |
| 7980 | printk(MPT2SAS_INFO_FMT "port enable: FAILED with " |
| 7981 | "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed); |
| 7982 | ioc->is_driver_loading = 0; |
| 7983 | ioc->wait_for_discovery_to_complete = 0; |
| 7984 | ioc->remove_host = 1; |
| 7985 | return 1; |
| 7986 | } |
| 7987 | |
| 7988 | printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name); |
| 7989 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 7990 | |
| 7991 | if (ioc->wait_for_discovery_to_complete) { |
| 7992 | ioc->wait_for_discovery_to_complete = 0; |
| 7993 | _scsih_probe_devices(ioc); |
| 7994 | } |
| 7995 | mpt2sas_base_start_watchdog(ioc); |
| 7996 | ioc->is_driver_loading = 0; |
| 7997 | return 1; |
| 7998 | } |
| 7999 | |
| 8000 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8001 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8002 | * _scsih_probe - attach and add scsi host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8003 | * @pdev: PCI device struct |
| 8004 | * @id: pci device id |
| 8005 | * |
| 8006 | * Returns 0 success, anything else error. |
| 8007 | */ |
| 8008 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8009 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8010 | { |
| 8011 | struct MPT2SAS_ADAPTER *ioc; |
| 8012 | struct Scsi_Host *shost; |
| 8013 | |
| 8014 | shost = scsi_host_alloc(&scsih_driver_template, |
| 8015 | sizeof(struct MPT2SAS_ADAPTER)); |
| 8016 | if (!shost) |
| 8017 | return -ENODEV; |
| 8018 | |
| 8019 | /* init local params */ |
| 8020 | ioc = shost_priv(shost); |
| 8021 | memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER)); |
| 8022 | INIT_LIST_HEAD(&ioc->list); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 8023 | list_add_tail(&ioc->list, &mpt2sas_ioc_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8024 | ioc->shost = shost; |
| 8025 | ioc->id = mpt_ids++; |
| 8026 | sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id); |
| 8027 | ioc->pdev = pdev; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8028 | if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) { |
| 8029 | ioc->is_warpdrive = 1; |
| 8030 | ioc->hide_ir_msg = 1; |
| 8031 | } else |
| 8032 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8033 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; |
| 8034 | ioc->tm_cb_idx = tm_cb_idx; |
| 8035 | ioc->ctl_cb_idx = ctl_cb_idx; |
| 8036 | ioc->base_cb_idx = base_cb_idx; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8037 | ioc->port_enable_cb_idx = port_enable_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8038 | ioc->transport_cb_idx = transport_cb_idx; |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8039 | ioc->scsih_cb_idx = scsih_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8040 | ioc->config_cb_idx = config_cb_idx; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8041 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8042 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8043 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8044 | ioc->logging_level = logging_level; |
nagalakshmi.nandigama@lsi.com | 845a0e4 | 2011-12-01 07:42:04 +0530 | [diff] [blame] | 8045 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8046 | /* misc semaphores and spin locks */ |
Kashyap, Desai | d274213 | 2010-06-17 13:28:55 +0530 | [diff] [blame] | 8047 | mutex_init(&ioc->reset_in_progress_mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8048 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
| 8049 | spin_lock_init(&ioc->scsi_lookup_lock); |
| 8050 | spin_lock_init(&ioc->sas_device_lock); |
| 8051 | spin_lock_init(&ioc->sas_node_lock); |
| 8052 | spin_lock_init(&ioc->fw_event_lock); |
| 8053 | spin_lock_init(&ioc->raid_device_lock); |
| 8054 | |
| 8055 | INIT_LIST_HEAD(&ioc->sas_device_list); |
| 8056 | INIT_LIST_HEAD(&ioc->sas_device_init_list); |
| 8057 | INIT_LIST_HEAD(&ioc->sas_expander_list); |
| 8058 | INIT_LIST_HEAD(&ioc->fw_event_list); |
| 8059 | INIT_LIST_HEAD(&ioc->raid_device_list); |
| 8060 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8061 | INIT_LIST_HEAD(&ioc->delayed_tr_list); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8062 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8063 | |
| 8064 | /* init shost parameters */ |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 8065 | shost->max_cmd_len = 32; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8066 | shost->max_lun = max_lun; |
| 8067 | shost->transportt = mpt2sas_transport_template; |
| 8068 | shost->unique_id = ioc->id; |
| 8069 | |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8070 | if (max_sectors != 0xFFFF) { |
| 8071 | if (max_sectors < 64) { |
| 8072 | shost->max_sectors = 64; |
sreekanth.reddy@lsi.com | eece5de | 2012-07-17 15:56:09 +0530 | [diff] [blame] | 8073 | printk(MPT2SAS_WARN_FMT "Invalid value %d passed "\ |
| 8074 | "for max_sectors, range is 64 to 32767. Assigning "\ |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8075 | "value of 64.\n", ioc->name, max_sectors); |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 8076 | } else if (max_sectors > 32767) { |
| 8077 | shost->max_sectors = 32767; |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8078 | printk(MPT2SAS_WARN_FMT "Invalid value %d passed " |
| 8079 | "for max_sectors, range is 64 to 8192. Assigning " |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 8080 | "default value of 32767.\n", ioc->name, |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8081 | max_sectors); |
| 8082 | } else { |
| 8083 | shost->max_sectors = max_sectors & 0xFFFE; |
| 8084 | printk(MPT2SAS_INFO_FMT "The max_sectors value is " |
| 8085 | "set to %d\n", ioc->name, shost->max_sectors); |
| 8086 | } |
| 8087 | } |
| 8088 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8089 | if ((scsi_add_host(shost, &pdev->dev))) { |
| 8090 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8091 | ioc->name, __FILE__, __LINE__, __func__); |
| 8092 | list_del(&ioc->list); |
| 8093 | goto out_add_shost_fail; |
| 8094 | } |
| 8095 | |
Martin K. Petersen | 5e95e73 | 2012-08-28 14:29:37 -0400 | [diff] [blame] | 8096 | /* register EEDP capabilities with SCSI layer */ |
| 8097 | if (prot_mask) |
| 8098 | scsi_host_set_prot(shost, prot_mask); |
| 8099 | else |
| 8100 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION |
| 8101 | | SHOST_DIF_TYPE2_PROTECTION |
| 8102 | | SHOST_DIF_TYPE3_PROTECTION); |
| 8103 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8104 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 8105 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8106 | /* event thread */ |
| 8107 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), |
| 8108 | "fw_event%d", ioc->id); |
| 8109 | ioc->firmware_event_thread = create_singlethread_workqueue( |
| 8110 | ioc->firmware_event_name); |
| 8111 | if (!ioc->firmware_event_thread) { |
| 8112 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8113 | ioc->name, __FILE__, __LINE__, __func__); |
| 8114 | goto out_thread_fail; |
| 8115 | } |
| 8116 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8117 | ioc->is_driver_loading = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8118 | if ((mpt2sas_base_attach(ioc))) { |
| 8119 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8120 | ioc->name, __FILE__, __LINE__, __func__); |
| 8121 | goto out_attach_fail; |
| 8122 | } |
| 8123 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8124 | if (ioc->is_warpdrive) { |
| 8125 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) |
| 8126 | ioc->hide_drives = 0; |
| 8127 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) |
| 8128 | ioc->hide_drives = 1; |
| 8129 | else { |
| 8130 | if (_scsih_get_num_volumes(ioc)) |
| 8131 | ioc->hide_drives = 1; |
| 8132 | else |
| 8133 | ioc->hide_drives = 0; |
| 8134 | } |
| 8135 | } else |
| 8136 | ioc->hide_drives = 0; |
nagalakshmi.nandigama@lsi.com | 2cb6fc8 | 2011-12-13 09:29:15 +0530 | [diff] [blame] | 8137 | scsi_scan_host(shost); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8138 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8139 | return 0; |
| 8140 | |
| 8141 | out_attach_fail: |
| 8142 | destroy_workqueue(ioc->firmware_event_thread); |
| 8143 | out_thread_fail: |
| 8144 | list_del(&ioc->list); |
| 8145 | scsi_remove_host(shost); |
| 8146 | out_add_shost_fail: |
Tomas Henzl | f555e05 | 2012-04-17 15:24:48 +0200 | [diff] [blame] | 8147 | scsi_host_put(shost); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8148 | return -ENODEV; |
| 8149 | } |
| 8150 | |
| 8151 | #ifdef CONFIG_PM |
| 8152 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8153 | * _scsih_suspend - power management suspend main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8154 | * @pdev: PCI device struct |
| 8155 | * @state: PM state change to (usually PCI_D3) |
| 8156 | * |
| 8157 | * Returns 0 success, anything else error. |
| 8158 | */ |
| 8159 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8160 | _scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8161 | { |
| 8162 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8163 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 8164 | pci_power_t device_state; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8165 | |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 8166 | mpt2sas_base_stop_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8167 | scsi_block_requests(shost); |
| 8168 | device_state = pci_choose_state(pdev, state); |
| 8169 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering " |
| 8170 | "operating state [D%d]\n", ioc->name, pdev, |
| 8171 | pci_name(pdev), device_state); |
| 8172 | |
| 8173 | mpt2sas_base_free_resources(ioc); |
| 8174 | pci_save_state(pdev); |
| 8175 | pci_disable_device(pdev); |
| 8176 | pci_set_power_state(pdev, device_state); |
| 8177 | return 0; |
| 8178 | } |
| 8179 | |
| 8180 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8181 | * _scsih_resume - power management resume main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8182 | * @pdev: PCI device struct |
| 8183 | * |
| 8184 | * Returns 0 success, anything else error. |
| 8185 | */ |
| 8186 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8187 | _scsih_resume(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8188 | { |
| 8189 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8190 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 8191 | pci_power_t device_state = pdev->current_state; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8192 | int r; |
| 8193 | |
| 8194 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous " |
| 8195 | "operating state [D%d]\n", ioc->name, pdev, |
| 8196 | pci_name(pdev), device_state); |
| 8197 | |
| 8198 | pci_set_power_state(pdev, PCI_D0); |
| 8199 | pci_enable_wake(pdev, PCI_D0, 0); |
| 8200 | pci_restore_state(pdev); |
| 8201 | ioc->pdev = pdev; |
| 8202 | r = mpt2sas_base_map_resources(ioc); |
| 8203 | if (r) |
| 8204 | return r; |
| 8205 | |
| 8206 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET); |
| 8207 | scsi_unblock_requests(shost); |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 8208 | mpt2sas_base_start_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8209 | return 0; |
| 8210 | } |
| 8211 | #endif /* CONFIG_PM */ |
| 8212 | |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8213 | /** |
| 8214 | * _scsih_pci_error_detected - Called when a PCI error is detected. |
| 8215 | * @pdev: PCI device struct |
| 8216 | * @state: PCI channel state |
| 8217 | * |
| 8218 | * Description: Called when a PCI error is detected. |
| 8219 | * |
| 8220 | * Return value: |
| 8221 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT |
| 8222 | */ |
| 8223 | static pci_ers_result_t |
| 8224 | _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 8225 | { |
| 8226 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8227 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8228 | |
| 8229 | printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n", |
| 8230 | ioc->name, state); |
| 8231 | |
| 8232 | switch (state) { |
| 8233 | case pci_channel_io_normal: |
| 8234 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 8235 | case pci_channel_io_frozen: |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8236 | /* Fatal error, prepare for slot reset */ |
| 8237 | ioc->pci_error_recovery = 1; |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8238 | scsi_block_requests(ioc->shost); |
| 8239 | mpt2sas_base_stop_watchdog(ioc); |
| 8240 | mpt2sas_base_free_resources(ioc); |
| 8241 | return PCI_ERS_RESULT_NEED_RESET; |
| 8242 | case pci_channel_io_perm_failure: |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8243 | /* Permanent error, prepare for device removal */ |
| 8244 | ioc->pci_error_recovery = 1; |
| 8245 | mpt2sas_base_stop_watchdog(ioc); |
| 8246 | _scsih_flush_running_cmds(ioc); |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8247 | return PCI_ERS_RESULT_DISCONNECT; |
| 8248 | } |
| 8249 | return PCI_ERS_RESULT_NEED_RESET; |
| 8250 | } |
| 8251 | |
| 8252 | /** |
| 8253 | * _scsih_pci_slot_reset - Called when PCI slot has been reset. |
| 8254 | * @pdev: PCI device struct |
| 8255 | * |
| 8256 | * Description: This routine is called by the pci error recovery |
| 8257 | * code after the PCI slot has been reset, just before we |
| 8258 | * should resume normal operations. |
| 8259 | */ |
| 8260 | static pci_ers_result_t |
| 8261 | _scsih_pci_slot_reset(struct pci_dev *pdev) |
| 8262 | { |
| 8263 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8264 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8265 | int rc; |
| 8266 | |
| 8267 | printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n", |
| 8268 | ioc->name); |
| 8269 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8270 | ioc->pci_error_recovery = 0; |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8271 | ioc->pdev = pdev; |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8272 | pci_restore_state(pdev); |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8273 | rc = mpt2sas_base_map_resources(ioc); |
| 8274 | if (rc) |
| 8275 | return PCI_ERS_RESULT_DISCONNECT; |
| 8276 | |
| 8277 | |
| 8278 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 8279 | FORCE_BIG_HAMMER); |
| 8280 | |
| 8281 | printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name, |
| 8282 | (rc == 0) ? "success" : "failed"); |
| 8283 | |
| 8284 | if (!rc) |
| 8285 | return PCI_ERS_RESULT_RECOVERED; |
| 8286 | else |
| 8287 | return PCI_ERS_RESULT_DISCONNECT; |
| 8288 | } |
| 8289 | |
| 8290 | /** |
| 8291 | * _scsih_pci_resume() - resume normal ops after PCI reset |
| 8292 | * @pdev: pointer to PCI device |
| 8293 | * |
| 8294 | * Called when the error recovery driver tells us that its |
| 8295 | * OK to resume normal operation. Use completion to allow |
| 8296 | * halted scsi ops to resume. |
| 8297 | */ |
| 8298 | static void |
| 8299 | _scsih_pci_resume(struct pci_dev *pdev) |
| 8300 | { |
| 8301 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8302 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8303 | |
| 8304 | printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name); |
| 8305 | |
| 8306 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8307 | mpt2sas_base_start_watchdog(ioc); |
| 8308 | scsi_unblock_requests(ioc->shost); |
| 8309 | } |
| 8310 | |
| 8311 | /** |
| 8312 | * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
| 8313 | * @pdev: pointer to PCI device |
| 8314 | */ |
| 8315 | static pci_ers_result_t |
| 8316 | _scsih_pci_mmio_enabled(struct pci_dev *pdev) |
| 8317 | { |
| 8318 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8319 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8320 | |
| 8321 | printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n", |
| 8322 | ioc->name); |
| 8323 | |
| 8324 | /* TODO - dump whatever for debugging purposes */ |
| 8325 | |
| 8326 | /* Request a slot reset. */ |
| 8327 | return PCI_ERS_RESULT_NEED_RESET; |
| 8328 | } |
| 8329 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 8330 | static const struct pci_error_handlers _scsih_err_handler = { |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8331 | .error_detected = _scsih_pci_error_detected, |
| 8332 | .mmio_enabled = _scsih_pci_mmio_enabled, |
| 8333 | .slot_reset = _scsih_pci_slot_reset, |
| 8334 | .resume = _scsih_pci_resume, |
| 8335 | }; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8336 | |
| 8337 | static struct pci_driver scsih_driver = { |
| 8338 | .name = MPT2SAS_DRIVER_NAME, |
| 8339 | .id_table = scsih_pci_table, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8340 | .probe = _scsih_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame^] | 8341 | .remove = _scsih_remove, |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8342 | .shutdown = _scsih_shutdown, |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8343 | .err_handler = &_scsih_err_handler, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8344 | #ifdef CONFIG_PM |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8345 | .suspend = _scsih_suspend, |
| 8346 | .resume = _scsih_resume, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8347 | #endif |
| 8348 | }; |
| 8349 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8350 | /* raid transport support */ |
| 8351 | static struct raid_function_template mpt2sas_raid_functions = { |
| 8352 | .cookie = &scsih_driver_template, |
| 8353 | .is_raid = _scsih_is_raid, |
| 8354 | .get_resync = _scsih_get_resync, |
| 8355 | .get_state = _scsih_get_state, |
| 8356 | }; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8357 | |
| 8358 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8359 | * _scsih_init - main entry point for this driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8360 | * |
| 8361 | * Returns 0 success, anything else error. |
| 8362 | */ |
| 8363 | static int __init |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8364 | _scsih_init(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8365 | { |
| 8366 | int error; |
| 8367 | |
| 8368 | mpt_ids = 0; |
| 8369 | printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME, |
| 8370 | MPT2SAS_DRIVER_VERSION); |
| 8371 | |
| 8372 | mpt2sas_transport_template = |
| 8373 | sas_attach_transport(&mpt2sas_transport_functions); |
| 8374 | if (!mpt2sas_transport_template) |
| 8375 | return -ENODEV; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8376 | /* raid transport support */ |
| 8377 | mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions); |
| 8378 | if (!mpt2sas_raid_template) { |
| 8379 | sas_release_transport(mpt2sas_transport_template); |
| 8380 | return -ENODEV; |
| 8381 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8382 | |
| 8383 | mpt2sas_base_initialize_callback_handler(); |
| 8384 | |
| 8385 | /* queuecommand callback hander */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8386 | scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8387 | |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 8388 | /* task management callback handler */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8389 | tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8390 | |
| 8391 | /* base internal commands callback handler */ |
| 8392 | 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] | 8393 | port_enable_cb_idx = mpt2sas_base_register_callback_handler( |
| 8394 | mpt2sas_port_enable_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8395 | |
| 8396 | /* transport internal commands callback handler */ |
| 8397 | transport_cb_idx = mpt2sas_base_register_callback_handler( |
| 8398 | mpt2sas_transport_done); |
| 8399 | |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8400 | /* scsih internal commands callback handler */ |
| 8401 | scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done); |
| 8402 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8403 | /* configuration page API internal commands callback handler */ |
| 8404 | config_cb_idx = mpt2sas_base_register_callback_handler( |
| 8405 | mpt2sas_config_done); |
| 8406 | |
| 8407 | /* ctl module callback handler */ |
| 8408 | ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done); |
| 8409 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8410 | tm_tr_cb_idx = mpt2sas_base_register_callback_handler( |
| 8411 | _scsih_tm_tr_complete); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8412 | |
| 8413 | tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler( |
| 8414 | _scsih_tm_volume_tr_complete); |
| 8415 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8416 | tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler( |
| 8417 | _scsih_sas_control_complete); |
| 8418 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8419 | mpt2sas_ctl_init(); |
| 8420 | |
| 8421 | error = pci_register_driver(&scsih_driver); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8422 | if (error) { |
| 8423 | /* raid transport support */ |
| 8424 | raid_class_release(mpt2sas_raid_template); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8425 | sas_release_transport(mpt2sas_transport_template); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8426 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8427 | |
| 8428 | return error; |
| 8429 | } |
| 8430 | |
| 8431 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8432 | * _scsih_exit - exit point for this driver (when it is a module). |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8433 | * |
| 8434 | * Returns 0 success, anything else error. |
| 8435 | */ |
| 8436 | static void __exit |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8437 | _scsih_exit(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8438 | { |
| 8439 | printk(KERN_INFO "mpt2sas version %s unloading\n", |
| 8440 | MPT2SAS_DRIVER_VERSION); |
| 8441 | |
| 8442 | pci_unregister_driver(&scsih_driver); |
| 8443 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8444 | mpt2sas_ctl_exit(); |
| 8445 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8446 | mpt2sas_base_release_callback_handler(scsi_io_cb_idx); |
| 8447 | mpt2sas_base_release_callback_handler(tm_cb_idx); |
| 8448 | mpt2sas_base_release_callback_handler(base_cb_idx); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8449 | mpt2sas_base_release_callback_handler(port_enable_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8450 | mpt2sas_base_release_callback_handler(transport_cb_idx); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8451 | mpt2sas_base_release_callback_handler(scsih_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8452 | mpt2sas_base_release_callback_handler(config_cb_idx); |
| 8453 | mpt2sas_base_release_callback_handler(ctl_cb_idx); |
| 8454 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8455 | mpt2sas_base_release_callback_handler(tm_tr_cb_idx); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8456 | mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8457 | mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx); |
| 8458 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8459 | /* raid transport support */ |
| 8460 | raid_class_release(mpt2sas_raid_template); |
| 8461 | sas_release_transport(mpt2sas_transport_template); |
| 8462 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8463 | } |
| 8464 | |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8465 | module_init(_scsih_init); |
| 8466 | module_exit(_scsih_exit); |