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 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 126 | /** |
| 127 | * struct sense_info - common structure for obtaining sense keys |
| 128 | * @skey: sense key |
| 129 | * @asc: additional sense code |
| 130 | * @ascq: additional sense code qualifier |
| 131 | */ |
| 132 | struct sense_info { |
| 133 | u8 skey; |
| 134 | u8 asc; |
| 135 | u8 ascq; |
| 136 | }; |
| 137 | |
| 138 | |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 139 | #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 140 | #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD) |
| 141 | #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 142 | /** |
| 143 | * struct fw_event_work - firmware event struct |
| 144 | * @list: link list framework |
| 145 | * @work: work object (ioc->fault_reset_work_q) |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 146 | * @cancel_pending_work: flag set during reset handling |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 147 | * @ioc: per adapter object |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 148 | * @device_handle: device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 149 | * @VF_ID: virtual function id |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 150 | * @VP_ID: virtual port id |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 151 | * @ignore: flag meaning this event has been marked to ignore |
| 152 | * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h |
| 153 | * @event_data: reply event data payload follows |
| 154 | * |
| 155 | * This object stored on ioc->fw_event_list. |
| 156 | */ |
| 157 | struct fw_event_work { |
| 158 | struct list_head list; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 159 | u8 cancel_pending_work; |
| 160 | struct delayed_work delayed_work; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 161 | struct MPT2SAS_ADAPTER *ioc; |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 162 | u16 device_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 163 | u8 VF_ID; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 164 | u8 VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 165 | u8 ignore; |
| 166 | u16 event; |
| 167 | void *event_data; |
| 168 | }; |
| 169 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 170 | /* raid transport support */ |
| 171 | static struct raid_template *mpt2sas_raid_template; |
| 172 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 173 | /** |
| 174 | * struct _scsi_io_transfer - scsi io transfer |
| 175 | * @handle: sas device handle (assigned by firmware) |
| 176 | * @is_raid: flag set for hidden raid components |
| 177 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, |
| 178 | * @data_length: data transfer length |
| 179 | * @data_dma: dma pointer to data |
| 180 | * @sense: sense data |
| 181 | * @lun: lun number |
| 182 | * @cdb_length: cdb length |
| 183 | * @cdb: cdb contents |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 184 | * @timeout: timeout for this command |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 185 | * @VF_ID: virtual function id |
| 186 | * @VP_ID: virtual port id |
| 187 | * @valid_reply: flag set for reply message |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 188 | * @sense_length: sense length |
| 189 | * @ioc_status: ioc status |
| 190 | * @scsi_state: scsi state |
| 191 | * @scsi_status: scsi staus |
| 192 | * @log_info: log information |
| 193 | * @transfer_length: data length transfer when there is a reply message |
| 194 | * |
| 195 | * Used for sending internal scsi commands to devices within this module. |
| 196 | * Refer to _scsi_send_scsi_io(). |
| 197 | */ |
| 198 | struct _scsi_io_transfer { |
| 199 | u16 handle; |
| 200 | u8 is_raid; |
| 201 | enum dma_data_direction dir; |
| 202 | u32 data_length; |
| 203 | dma_addr_t data_dma; |
| 204 | u8 sense[SCSI_SENSE_BUFFERSIZE]; |
| 205 | u32 lun; |
| 206 | u8 cdb_length; |
| 207 | u8 cdb[32]; |
| 208 | u8 timeout; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 209 | u8 VF_ID; |
| 210 | u8 VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 211 | u8 valid_reply; |
| 212 | /* the following bits are only valid when 'valid_reply = 1' */ |
| 213 | u32 sense_length; |
| 214 | u16 ioc_status; |
| 215 | u8 scsi_state; |
| 216 | u8 scsi_status; |
| 217 | u32 log_info; |
| 218 | u32 transfer_length; |
| 219 | }; |
| 220 | |
| 221 | /* |
| 222 | * The pci device ids are defined in mpi/mpi2_cnfg.h. |
| 223 | */ |
| 224 | static struct pci_device_id scsih_pci_table[] = { |
| 225 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, |
| 226 | PCI_ANY_ID, PCI_ANY_ID }, |
| 227 | /* Falcon ~ 2008*/ |
| 228 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, |
| 229 | PCI_ANY_ID, PCI_ANY_ID }, |
| 230 | /* Liberator ~ 2108 */ |
| 231 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, |
| 232 | PCI_ANY_ID, PCI_ANY_ID }, |
| 233 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, |
| 234 | PCI_ANY_ID, PCI_ANY_ID }, |
| 235 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, |
| 236 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 237 | /* Meteor ~ 2116 */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 238 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, |
| 239 | PCI_ANY_ID, PCI_ANY_ID }, |
| 240 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, |
| 241 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 242 | /* Thunderbolt ~ 2208 */ |
| 243 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, |
| 244 | PCI_ANY_ID, PCI_ANY_ID }, |
| 245 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, |
| 246 | PCI_ANY_ID, PCI_ANY_ID }, |
| 247 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, |
| 248 | PCI_ANY_ID, PCI_ANY_ID }, |
| 249 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, |
| 250 | PCI_ANY_ID, PCI_ANY_ID }, |
| 251 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, |
| 252 | PCI_ANY_ID, PCI_ANY_ID }, |
| 253 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, |
| 254 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 203d65b | 2010-06-17 13:37:59 +0530 | [diff] [blame] | 255 | /* Mustang ~ 2308 */ |
| 256 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 257 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 203d65b | 2010-06-17 13:37:59 +0530 | [diff] [blame] | 258 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, |
| 259 | PCI_ANY_ID, PCI_ANY_ID }, |
| 260 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 261 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 262 | /* SSS6200 */ |
| 263 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, |
| 264 | PCI_ANY_ID, PCI_ANY_ID }, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 265 | {0} /* Terminating entry */ |
| 266 | }; |
| 267 | MODULE_DEVICE_TABLE(pci, scsih_pci_table); |
| 268 | |
| 269 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 270 | * _scsih_set_debug_level - global setting of ioc->logging_level. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 271 | * |
| 272 | * Note: The logging levels are defined in mpt2sas_debug.h. |
| 273 | */ |
| 274 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 275 | _scsih_set_debug_level(const char *val, struct kernel_param *kp) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 276 | { |
| 277 | int ret = param_set_int(val, kp); |
| 278 | struct MPT2SAS_ADAPTER *ioc; |
| 279 | |
| 280 | if (ret) |
| 281 | return ret; |
| 282 | |
| 283 | printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 284 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 285 | ioc->logging_level = logging_level; |
| 286 | return 0; |
| 287 | } |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 288 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 289 | &logging_level, 0644); |
| 290 | |
| 291 | /** |
| 292 | * _scsih_srch_boot_sas_address - search based on sas_address |
| 293 | * @sas_address: sas address |
| 294 | * @boot_device: boot device object from bios page 2 |
| 295 | * |
| 296 | * Returns 1 when there's a match, 0 means no match. |
| 297 | */ |
| 298 | static inline int |
| 299 | _scsih_srch_boot_sas_address(u64 sas_address, |
| 300 | Mpi2BootDeviceSasWwid_t *boot_device) |
| 301 | { |
| 302 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * _scsih_srch_boot_device_name - search based on device name |
| 307 | * @device_name: device name specified in INDENTIFY fram |
| 308 | * @boot_device: boot device object from bios page 2 |
| 309 | * |
| 310 | * Returns 1 when there's a match, 0 means no match. |
| 311 | */ |
| 312 | static inline int |
| 313 | _scsih_srch_boot_device_name(u64 device_name, |
| 314 | Mpi2BootDeviceDeviceName_t *boot_device) |
| 315 | { |
| 316 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot |
| 321 | * @enclosure_logical_id: enclosure logical id |
| 322 | * @slot_number: slot number |
| 323 | * @boot_device: boot device object from bios page 2 |
| 324 | * |
| 325 | * Returns 1 when there's a match, 0 means no match. |
| 326 | */ |
| 327 | static inline int |
| 328 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, |
| 329 | Mpi2BootDeviceEnclosureSlot_t *boot_device) |
| 330 | { |
| 331 | return (enclosure_logical_id == le64_to_cpu(boot_device-> |
| 332 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> |
| 333 | SlotNumber)) ? 1 : 0; |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * _scsih_is_boot_device - search for matching boot device. |
| 338 | * @sas_address: sas address |
| 339 | * @device_name: device name specified in INDENTIFY fram |
| 340 | * @enclosure_logical_id: enclosure logical id |
| 341 | * @slot_number: slot number |
| 342 | * @form: specifies boot device form |
| 343 | * @boot_device: boot device object from bios page 2 |
| 344 | * |
| 345 | * Returns 1 when there's a match, 0 means no match. |
| 346 | */ |
| 347 | static int |
| 348 | _scsih_is_boot_device(u64 sas_address, u64 device_name, |
| 349 | u64 enclosure_logical_id, u16 slot, u8 form, |
| 350 | Mpi2BiosPage2BootDevice_t *boot_device) |
| 351 | { |
| 352 | int rc = 0; |
| 353 | |
| 354 | switch (form) { |
| 355 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: |
| 356 | if (!sas_address) |
| 357 | break; |
| 358 | rc = _scsih_srch_boot_sas_address( |
| 359 | sas_address, &boot_device->SasWwid); |
| 360 | break; |
| 361 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: |
| 362 | if (!enclosure_logical_id) |
| 363 | break; |
| 364 | rc = _scsih_srch_boot_encl_slot( |
| 365 | enclosure_logical_id, |
| 366 | slot, &boot_device->EnclosureSlot); |
| 367 | break; |
| 368 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: |
| 369 | if (!device_name) |
| 370 | break; |
| 371 | rc = _scsih_srch_boot_device_name( |
| 372 | device_name, &boot_device->DeviceName); |
| 373 | break; |
| 374 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: |
| 375 | break; |
| 376 | } |
| 377 | |
| 378 | return rc; |
| 379 | } |
| 380 | |
| 381 | /** |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 382 | * _scsih_get_sas_address - set the sas_address for given device handle |
| 383 | * @handle: device handle |
| 384 | * @sas_address: sas address |
| 385 | * |
| 386 | * Returns 0 success, non-zero when failure |
| 387 | */ |
| 388 | static int |
| 389 | _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle, |
| 390 | u64 *sas_address) |
| 391 | { |
| 392 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 393 | Mpi2ConfigReply_t mpi_reply; |
| 394 | u32 ioc_status; |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 395 | *sas_address = 0; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 396 | |
| 397 | if (handle <= ioc->sas_hba.num_phys) { |
| 398 | *sas_address = ioc->sas_hba.sas_address; |
| 399 | return 0; |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 400 | } |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 401 | |
| 402 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 403 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 404 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 405 | __FILE__, __LINE__, __func__); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 406 | return -ENXIO; |
| 407 | } |
| 408 | |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 409 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 410 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { |
| 411 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 412 | return 0; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 413 | } |
| 414 | |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 415 | /* we hit this becuase the given parent handle doesn't exist */ |
| 416 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 417 | return -ENXIO; |
| 418 | /* else error case */ |
| 419 | printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), " |
| 420 | "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status, |
| 421 | __FILE__, __LINE__, __func__); |
| 422 | return -EIO; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 426 | * _scsih_determine_boot_device - determine boot device. |
| 427 | * @ioc: per adapter object |
| 428 | * @device: either sas_device or raid_device object |
| 429 | * @is_raid: [flag] 1 = raid object, 0 = sas object |
| 430 | * |
| 431 | * Determines whether this device should be first reported device to |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 432 | * 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] | 433 | * There are primary, alternate, and current entries in bios page 2. The order |
| 434 | * priority is primary, alternate, then current. This routine saves |
| 435 | * the corresponding device object and is_raid flag in the ioc object. |
| 436 | * The saved data to be used later in _scsih_probe_boot_devices(). |
| 437 | */ |
| 438 | static void |
| 439 | _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc, |
| 440 | void *device, u8 is_raid) |
| 441 | { |
| 442 | struct _sas_device *sas_device; |
| 443 | struct _raid_device *raid_device; |
| 444 | u64 sas_address; |
| 445 | u64 device_name; |
| 446 | u64 enclosure_logical_id; |
| 447 | u16 slot; |
| 448 | |
| 449 | /* only process this function when driver loads */ |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 450 | if (!ioc->is_driver_loading) |
| 451 | return; |
| 452 | |
| 453 | /* no Bios, return immediately */ |
| 454 | if (!ioc->bios_pg3.BiosVersion) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 455 | return; |
| 456 | |
| 457 | if (!is_raid) { |
| 458 | sas_device = device; |
| 459 | sas_address = sas_device->sas_address; |
| 460 | device_name = sas_device->device_name; |
| 461 | enclosure_logical_id = sas_device->enclosure_logical_id; |
| 462 | slot = sas_device->slot; |
| 463 | } else { |
| 464 | raid_device = device; |
| 465 | sas_address = raid_device->wwid; |
| 466 | device_name = 0; |
| 467 | enclosure_logical_id = 0; |
| 468 | slot = 0; |
| 469 | } |
| 470 | |
| 471 | if (!ioc->req_boot_device.device) { |
| 472 | if (_scsih_is_boot_device(sas_address, device_name, |
| 473 | enclosure_logical_id, slot, |
| 474 | (ioc->bios_pg2.ReqBootDeviceForm & |
| 475 | MPI2_BIOSPAGE2_FORM_MASK), |
| 476 | &ioc->bios_pg2.RequestedBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 477 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 478 | "%s: req_boot_device(0x%016llx)\n", |
| 479 | ioc->name, __func__, |
| 480 | (unsigned long long)sas_address)); |
| 481 | ioc->req_boot_device.device = device; |
| 482 | ioc->req_boot_device.is_raid = is_raid; |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | if (!ioc->req_alt_boot_device.device) { |
| 487 | if (_scsih_is_boot_device(sas_address, device_name, |
| 488 | enclosure_logical_id, slot, |
| 489 | (ioc->bios_pg2.ReqAltBootDeviceForm & |
| 490 | MPI2_BIOSPAGE2_FORM_MASK), |
| 491 | &ioc->bios_pg2.RequestedAltBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 492 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 493 | "%s: req_alt_boot_device(0x%016llx)\n", |
| 494 | ioc->name, __func__, |
| 495 | (unsigned long long)sas_address)); |
| 496 | ioc->req_alt_boot_device.device = device; |
| 497 | ioc->req_alt_boot_device.is_raid = is_raid; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | if (!ioc->current_boot_device.device) { |
| 502 | if (_scsih_is_boot_device(sas_address, device_name, |
| 503 | enclosure_logical_id, slot, |
| 504 | (ioc->bios_pg2.CurrentBootDeviceForm & |
| 505 | MPI2_BIOSPAGE2_FORM_MASK), |
| 506 | &ioc->bios_pg2.CurrentBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 507 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 508 | "%s: current_boot_device(0x%016llx)\n", |
| 509 | ioc->name, __func__, |
| 510 | (unsigned long long)sas_address)); |
| 511 | ioc->current_boot_device.device = device; |
| 512 | ioc->current_boot_device.is_raid = is_raid; |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search |
| 519 | * @ioc: per adapter object |
| 520 | * @sas_address: sas address |
| 521 | * Context: Calling function should acquire ioc->sas_device_lock |
| 522 | * |
| 523 | * This searches for sas_device based on sas_address, then return sas_device |
| 524 | * object. |
| 525 | */ |
| 526 | struct _sas_device * |
| 527 | mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 528 | u64 sas_address) |
| 529 | { |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 530 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 531 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 532 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) |
| 533 | if (sas_device->sas_address == sas_address) |
| 534 | return sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 535 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 536 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) |
| 537 | if (sas_device->sas_address == sas_address) |
| 538 | return sas_device; |
| 539 | |
| 540 | return NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /** |
| 544 | * _scsih_sas_device_find_by_handle - sas device search |
| 545 | * @ioc: per adapter object |
| 546 | * @handle: sas device handle (assigned by firmware) |
| 547 | * Context: Calling function should acquire ioc->sas_device_lock |
| 548 | * |
| 549 | * This searches for sas_device based on sas_address, then return sas_device |
| 550 | * object. |
| 551 | */ |
| 552 | static struct _sas_device * |
| 553 | _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 554 | { |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 555 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 556 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 557 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) |
| 558 | if (sas_device->handle == handle) |
| 559 | return sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 560 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 561 | list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) |
| 562 | if (sas_device->handle == handle) |
| 563 | return sas_device; |
| 564 | |
| 565 | return NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /** |
| 569 | * _scsih_sas_device_remove - remove sas_device from list. |
| 570 | * @ioc: per adapter object |
| 571 | * @sas_device: the sas_device object |
| 572 | * Context: This function will acquire ioc->sas_device_lock. |
| 573 | * |
| 574 | * Removing object and freeing associated memory from the ioc->sas_device_list. |
| 575 | */ |
| 576 | static void |
| 577 | _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc, |
| 578 | struct _sas_device *sas_device) |
| 579 | { |
| 580 | unsigned long flags; |
| 581 | |
Kashyap, Desai | 980ead3 | 2010-04-08 17:55:22 +0530 | [diff] [blame] | 582 | if (!sas_device) |
| 583 | return; |
| 584 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 585 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 586 | list_del(&sas_device->list); |
| 587 | kfree(sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 588 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 589 | } |
| 590 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 591 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 592 | /** |
| 593 | * _scsih_sas_device_add - insert sas_device to the list. |
| 594 | * @ioc: per adapter object |
| 595 | * @sas_device: the sas_device object |
| 596 | * Context: This function will acquire ioc->sas_device_lock. |
| 597 | * |
| 598 | * Adding new object to the ioc->sas_device_list. |
| 599 | */ |
| 600 | static void |
| 601 | _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc, |
| 602 | struct _sas_device *sas_device) |
| 603 | { |
| 604 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 605 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 606 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 607 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 608 | sas_device->handle, (unsigned long long)sas_device->sas_address)); |
| 609 | |
| 610 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 611 | list_add_tail(&sas_device->list, &ioc->sas_device_list); |
| 612 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 613 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 614 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 615 | sas_device->sas_address_parent)) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 616 | _scsih_sas_device_remove(ioc, sas_device); |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 617 | } else if (!sas_device->starget) { |
| 618 | /* When asyn scanning is enabled, its not possible to remove |
| 619 | * devices while scanning is turned on due to an oops in |
| 620 | * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start() |
| 621 | */ |
| 622 | if (!ioc->is_driver_loading) |
| 623 | mpt2sas_transport_port_remove(ioc, |
| 624 | sas_device->sas_address, |
| 625 | sas_device->sas_address_parent); |
| 626 | _scsih_sas_device_remove(ioc, sas_device); |
| 627 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /** |
| 631 | * _scsih_sas_device_init_add - insert sas_device to the list. |
| 632 | * @ioc: per adapter object |
| 633 | * @sas_device: the sas_device object |
| 634 | * Context: This function will acquire ioc->sas_device_lock. |
| 635 | * |
| 636 | * Adding new object at driver load time to the ioc->sas_device_init_list. |
| 637 | */ |
| 638 | static void |
| 639 | _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc, |
| 640 | struct _sas_device *sas_device) |
| 641 | { |
| 642 | unsigned long flags; |
| 643 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 644 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 645 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 646 | sas_device->handle, (unsigned long long)sas_device->sas_address)); |
| 647 | |
| 648 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 649 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 650 | _scsih_determine_boot_device(ioc, sas_device, 0); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 651 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 655 | * _scsih_raid_device_find_by_id - raid device search |
| 656 | * @ioc: per adapter object |
| 657 | * @id: sas device target id |
| 658 | * @channel: sas device channel |
| 659 | * Context: Calling function should acquire ioc->raid_device_lock |
| 660 | * |
| 661 | * This searches for raid_device based on target id, then return raid_device |
| 662 | * object. |
| 663 | */ |
| 664 | static struct _raid_device * |
| 665 | _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel) |
| 666 | { |
| 667 | struct _raid_device *raid_device, *r; |
| 668 | |
| 669 | r = NULL; |
| 670 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 671 | if (raid_device->id == id && raid_device->channel == channel) { |
| 672 | r = raid_device; |
| 673 | goto out; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | out: |
| 678 | return r; |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * _scsih_raid_device_find_by_handle - raid device search |
| 683 | * @ioc: per adapter object |
| 684 | * @handle: sas device handle (assigned by firmware) |
| 685 | * Context: Calling function should acquire ioc->raid_device_lock |
| 686 | * |
| 687 | * This searches for raid_device based on handle, then return raid_device |
| 688 | * object. |
| 689 | */ |
| 690 | static struct _raid_device * |
| 691 | _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 692 | { |
| 693 | struct _raid_device *raid_device, *r; |
| 694 | |
| 695 | r = NULL; |
| 696 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 697 | if (raid_device->handle != handle) |
| 698 | continue; |
| 699 | r = raid_device; |
| 700 | goto out; |
| 701 | } |
| 702 | |
| 703 | out: |
| 704 | return r; |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * _scsih_raid_device_find_by_wwid - raid device search |
| 709 | * @ioc: per adapter object |
| 710 | * @handle: sas device handle (assigned by firmware) |
| 711 | * Context: Calling function should acquire ioc->raid_device_lock |
| 712 | * |
| 713 | * This searches for raid_device based on wwid, then return raid_device |
| 714 | * object. |
| 715 | */ |
| 716 | static struct _raid_device * |
| 717 | _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid) |
| 718 | { |
| 719 | struct _raid_device *raid_device, *r; |
| 720 | |
| 721 | r = NULL; |
| 722 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 723 | if (raid_device->wwid != wwid) |
| 724 | continue; |
| 725 | r = raid_device; |
| 726 | goto out; |
| 727 | } |
| 728 | |
| 729 | out: |
| 730 | return r; |
| 731 | } |
| 732 | |
| 733 | /** |
| 734 | * _scsih_raid_device_add - add raid_device object |
| 735 | * @ioc: per adapter object |
| 736 | * @raid_device: raid_device object |
| 737 | * |
| 738 | * This is added to the raid_device_list link list. |
| 739 | */ |
| 740 | static void |
| 741 | _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc, |
| 742 | struct _raid_device *raid_device) |
| 743 | { |
| 744 | unsigned long flags; |
| 745 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 746 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 747 | "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, |
| 748 | raid_device->handle, (unsigned long long)raid_device->wwid)); |
| 749 | |
| 750 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 751 | list_add_tail(&raid_device->list, &ioc->raid_device_list); |
| 752 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 753 | } |
| 754 | |
| 755 | /** |
| 756 | * _scsih_raid_device_remove - delete raid_device object |
| 757 | * @ioc: per adapter object |
| 758 | * @raid_device: raid_device object |
| 759 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 760 | */ |
| 761 | static void |
| 762 | _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc, |
| 763 | struct _raid_device *raid_device) |
| 764 | { |
| 765 | unsigned long flags; |
| 766 | |
| 767 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 768 | list_del(&raid_device->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 769 | kfree(raid_device); |
| 770 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 771 | } |
| 772 | |
| 773 | /** |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 774 | * mpt2sas_scsih_expander_find_by_handle - expander device search |
| 775 | * @ioc: per adapter object |
| 776 | * @handle: expander handle (assigned by firmware) |
| 777 | * Context: Calling function should acquire ioc->sas_device_lock |
| 778 | * |
| 779 | * This searches for expander device based on handle, then returns the |
| 780 | * sas_node object. |
| 781 | */ |
| 782 | struct _sas_node * |
| 783 | mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 784 | { |
| 785 | struct _sas_node *sas_expander, *r; |
| 786 | |
| 787 | r = NULL; |
| 788 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 789 | if (sas_expander->handle != handle) |
| 790 | continue; |
| 791 | r = sas_expander; |
| 792 | goto out; |
| 793 | } |
| 794 | out: |
| 795 | return r; |
| 796 | } |
| 797 | |
| 798 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 799 | * mpt2sas_scsih_expander_find_by_sas_address - expander device search |
| 800 | * @ioc: per adapter object |
| 801 | * @sas_address: sas address |
| 802 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 803 | * |
| 804 | * This searches for expander device based on sas_address, then returns the |
| 805 | * sas_node object. |
| 806 | */ |
| 807 | struct _sas_node * |
| 808 | mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 809 | u64 sas_address) |
| 810 | { |
| 811 | struct _sas_node *sas_expander, *r; |
| 812 | |
| 813 | r = NULL; |
| 814 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 815 | if (sas_expander->sas_address != sas_address) |
| 816 | continue; |
| 817 | r = sas_expander; |
| 818 | goto out; |
| 819 | } |
| 820 | out: |
| 821 | return r; |
| 822 | } |
| 823 | |
| 824 | /** |
| 825 | * _scsih_expander_node_add - insert expander device to the list. |
| 826 | * @ioc: per adapter object |
| 827 | * @sas_expander: the sas_device object |
| 828 | * Context: This function will acquire ioc->sas_node_lock. |
| 829 | * |
| 830 | * Adding new object to the ioc->sas_expander_list. |
| 831 | * |
| 832 | * Return nothing. |
| 833 | */ |
| 834 | static void |
| 835 | _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc, |
| 836 | struct _sas_node *sas_expander) |
| 837 | { |
| 838 | unsigned long flags; |
| 839 | |
| 840 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 841 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); |
| 842 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 843 | } |
| 844 | |
| 845 | /** |
| 846 | * _scsih_is_end_device - determines if device is an end device |
| 847 | * @device_info: bitfield providing information about the device. |
| 848 | * Context: none |
| 849 | * |
| 850 | * Returns 1 if end device. |
| 851 | */ |
| 852 | static int |
| 853 | _scsih_is_end_device(u32 device_info) |
| 854 | { |
| 855 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && |
| 856 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | |
| 857 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
| 858 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) |
| 859 | return 1; |
| 860 | else |
| 861 | return 0; |
| 862 | } |
| 863 | |
| 864 | /** |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 865 | * _scsih_scsi_lookup_get - returns scmd entry |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 866 | * @ioc: per adapter object |
| 867 | * @smid: system request message index |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 868 | * |
| 869 | * Returns the smid stored scmd pointer. |
| 870 | */ |
| 871 | static struct scsi_cmnd * |
| 872 | _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 873 | { |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 874 | return ioc->scsi_lookup[smid - 1].scmd; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | /** |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 878 | * _scsih_scsi_lookup_get_clear - returns scmd entry |
| 879 | * @ioc: per adapter object |
| 880 | * @smid: system request message index |
| 881 | * |
| 882 | * Returns the smid stored scmd pointer. |
| 883 | * Then will derefrence the stored scmd pointer. |
| 884 | */ |
| 885 | static inline struct scsi_cmnd * |
| 886 | _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 887 | { |
| 888 | unsigned long flags; |
| 889 | struct scsi_cmnd *scmd; |
| 890 | |
| 891 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 892 | scmd = ioc->scsi_lookup[smid - 1].scmd; |
| 893 | ioc->scsi_lookup[smid - 1].scmd = NULL; |
| 894 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 895 | |
| 896 | return scmd; |
| 897 | } |
| 898 | |
| 899 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 900 | * _scsih_scsi_lookup_find_by_scmd - scmd lookup |
| 901 | * @ioc: per adapter object |
| 902 | * @smid: system request message index |
| 903 | * @scmd: pointer to scsi command object |
| 904 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 905 | * |
| 906 | * This will search for a scmd pointer in the scsi_lookup array, |
| 907 | * returning the revelent smid. A returned value of zero means invalid. |
| 908 | */ |
| 909 | static u16 |
| 910 | _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd |
| 911 | *scmd) |
| 912 | { |
| 913 | u16 smid; |
| 914 | unsigned long flags; |
| 915 | int i; |
| 916 | |
| 917 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 918 | smid = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 919 | for (i = 0; i < ioc->scsiio_depth; i++) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 920 | if (ioc->scsi_lookup[i].scmd == scmd) { |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 921 | smid = ioc->scsi_lookup[i].smid; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 922 | goto out; |
| 923 | } |
| 924 | } |
| 925 | out: |
| 926 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 927 | return smid; |
| 928 | } |
| 929 | |
| 930 | /** |
| 931 | * _scsih_scsi_lookup_find_by_target - search for matching channel:id |
| 932 | * @ioc: per adapter object |
| 933 | * @id: target id |
| 934 | * @channel: channel |
| 935 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 936 | * |
| 937 | * This will search for a matching channel:id in the scsi_lookup array, |
| 938 | * returning 1 if found. |
| 939 | */ |
| 940 | static u8 |
| 941 | _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id, |
| 942 | int channel) |
| 943 | { |
| 944 | u8 found; |
| 945 | unsigned long flags; |
| 946 | int i; |
| 947 | |
| 948 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 949 | found = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 950 | for (i = 0 ; i < ioc->scsiio_depth; i++) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 951 | if (ioc->scsi_lookup[i].scmd && |
| 952 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 953 | ioc->scsi_lookup[i].scmd->device->channel == channel)) { |
| 954 | found = 1; |
| 955 | goto out; |
| 956 | } |
| 957 | } |
| 958 | out: |
| 959 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 960 | return found; |
| 961 | } |
| 962 | |
| 963 | /** |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 964 | * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun |
| 965 | * @ioc: per adapter object |
| 966 | * @id: target id |
| 967 | * @lun: lun number |
| 968 | * @channel: channel |
| 969 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 970 | * |
| 971 | * This will search for a matching channel:id:lun in the scsi_lookup array, |
| 972 | * returning 1 if found. |
| 973 | */ |
| 974 | static u8 |
| 975 | _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id, |
| 976 | unsigned int lun, int channel) |
| 977 | { |
| 978 | u8 found; |
| 979 | unsigned long flags; |
| 980 | int i; |
| 981 | |
| 982 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 983 | found = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 984 | for (i = 0 ; i < ioc->scsiio_depth; i++) { |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 985 | if (ioc->scsi_lookup[i].scmd && |
| 986 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 987 | ioc->scsi_lookup[i].scmd->device->channel == channel && |
| 988 | ioc->scsi_lookup[i].scmd->device->lun == lun)) { |
| 989 | found = 1; |
| 990 | goto out; |
| 991 | } |
| 992 | } |
| 993 | out: |
| 994 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 995 | return found; |
| 996 | } |
| 997 | |
| 998 | /** |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 999 | * _scsih_get_chain_buffer_tracker - obtain chain tracker |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1000 | * @ioc: per adapter object |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1001 | * @smid: smid associated to an IO request |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1002 | * |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1003 | * Returns chain tracker(from ioc->free_chain_list) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1004 | */ |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1005 | static struct chain_tracker * |
| 1006 | _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
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 | struct chain_tracker *chain_req; |
| 1009 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1010 | |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1011 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 1012 | if (list_empty(&ioc->free_chain_list)) { |
| 1013 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
nagalakshmi.nandigama@lsi.com | aff132d | 2011-12-01 07:53:08 +0530 | [diff] [blame] | 1014 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not " |
| 1015 | "available\n", ioc->name)); |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1016 | return NULL; |
| 1017 | } |
| 1018 | chain_req = list_entry(ioc->free_chain_list.next, |
| 1019 | struct chain_tracker, tracker_list); |
| 1020 | list_del_init(&chain_req->tracker_list); |
| 1021 | list_add_tail(&chain_req->tracker_list, |
| 1022 | &ioc->scsi_lookup[smid - 1].chain_list); |
| 1023 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1024 | return chain_req; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | /** |
| 1028 | * _scsih_build_scatter_gather - main sg creation routine |
| 1029 | * @ioc: per adapter object |
| 1030 | * @scmd: scsi command |
| 1031 | * @smid: system request message index |
| 1032 | * Context: none. |
| 1033 | * |
| 1034 | * The main routine that builds scatter gather table from a given |
| 1035 | * scsi request sent via the .queuecommand main handler. |
| 1036 | * |
| 1037 | * Returns 0 success, anything else error |
| 1038 | */ |
| 1039 | static int |
| 1040 | _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc, |
| 1041 | struct scsi_cmnd *scmd, u16 smid) |
| 1042 | { |
| 1043 | Mpi2SCSIIORequest_t *mpi_request; |
| 1044 | dma_addr_t chain_dma; |
| 1045 | struct scatterlist *sg_scmd; |
| 1046 | void *sg_local, *chain; |
| 1047 | u32 chain_offset; |
| 1048 | u32 chain_length; |
| 1049 | u32 chain_flags; |
FUJITA Tomonori | bb789d0 | 2010-03-09 11:09:50 +0900 | [diff] [blame] | 1050 | int sges_left; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1051 | u32 sges_in_segment; |
| 1052 | u32 sgl_flags; |
| 1053 | u32 sgl_flags_last_element; |
| 1054 | u32 sgl_flags_end_buffer; |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1055 | struct chain_tracker *chain_req; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1056 | |
| 1057 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 1058 | |
| 1059 | /* init scatter gather flags */ |
| 1060 | sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT; |
| 1061 | if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 1062 | sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC; |
| 1063 | sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT) |
| 1064 | << MPI2_SGE_FLAGS_SHIFT; |
| 1065 | sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT | |
| 1066 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST) |
| 1067 | << MPI2_SGE_FLAGS_SHIFT; |
| 1068 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1069 | |
| 1070 | sg_scmd = scsi_sglist(scmd); |
| 1071 | sges_left = scsi_dma_map(scmd); |
FUJITA Tomonori | bb789d0 | 2010-03-09 11:09:50 +0900 | [diff] [blame] | 1072 | if (sges_left < 0) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1073 | sdev_printk(KERN_ERR, scmd->device, "pci_map_sg" |
| 1074 | " failed: request for %d bytes!\n", scsi_bufflen(scmd)); |
| 1075 | return -ENOMEM; |
| 1076 | } |
| 1077 | |
| 1078 | sg_local = &mpi_request->SGL; |
| 1079 | sges_in_segment = ioc->max_sges_in_main_message; |
| 1080 | if (sges_left <= sges_in_segment) |
| 1081 | goto fill_in_last_segment; |
| 1082 | |
| 1083 | mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) + |
| 1084 | (sges_in_segment * ioc->sge_size))/4; |
| 1085 | |
| 1086 | /* fill in main message segment when there is a chain following */ |
| 1087 | while (sges_in_segment) { |
| 1088 | if (sges_in_segment == 1) |
| 1089 | ioc->base_add_sg_single(sg_local, |
| 1090 | sgl_flags_last_element | sg_dma_len(sg_scmd), |
| 1091 | sg_dma_address(sg_scmd)); |
| 1092 | else |
| 1093 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1094 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1095 | sg_scmd = sg_next(sg_scmd); |
| 1096 | sg_local += ioc->sge_size; |
| 1097 | sges_left--; |
| 1098 | sges_in_segment--; |
| 1099 | } |
| 1100 | |
| 1101 | /* initializing the chain flags and pointers */ |
| 1102 | chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT; |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1103 | chain_req = _scsih_get_chain_buffer_tracker(ioc, smid); |
| 1104 | if (!chain_req) |
| 1105 | return -1; |
| 1106 | chain = chain_req->chain_buffer; |
| 1107 | chain_dma = chain_req->chain_buffer_dma; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1108 | do { |
| 1109 | sges_in_segment = (sges_left <= |
| 1110 | ioc->max_sges_in_chain_message) ? sges_left : |
| 1111 | ioc->max_sges_in_chain_message; |
| 1112 | chain_offset = (sges_left == sges_in_segment) ? |
| 1113 | 0 : (sges_in_segment * ioc->sge_size)/4; |
| 1114 | chain_length = sges_in_segment * ioc->sge_size; |
| 1115 | if (chain_offset) { |
| 1116 | chain_offset = chain_offset << |
| 1117 | MPI2_SGE_CHAIN_OFFSET_SHIFT; |
| 1118 | chain_length += ioc->sge_size; |
| 1119 | } |
| 1120 | ioc->base_add_sg_single(sg_local, chain_flags | chain_offset | |
| 1121 | chain_length, chain_dma); |
| 1122 | sg_local = chain; |
| 1123 | if (!chain_offset) |
| 1124 | goto fill_in_last_segment; |
| 1125 | |
| 1126 | /* fill in chain segments */ |
| 1127 | while (sges_in_segment) { |
| 1128 | if (sges_in_segment == 1) |
| 1129 | ioc->base_add_sg_single(sg_local, |
| 1130 | sgl_flags_last_element | |
| 1131 | sg_dma_len(sg_scmd), |
| 1132 | sg_dma_address(sg_scmd)); |
| 1133 | else |
| 1134 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1135 | sg_dma_len(sg_scmd), |
| 1136 | sg_dma_address(sg_scmd)); |
| 1137 | sg_scmd = sg_next(sg_scmd); |
| 1138 | sg_local += ioc->sge_size; |
| 1139 | sges_left--; |
| 1140 | sges_in_segment--; |
| 1141 | } |
| 1142 | |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1143 | chain_req = _scsih_get_chain_buffer_tracker(ioc, smid); |
| 1144 | if (!chain_req) |
| 1145 | return -1; |
| 1146 | chain = chain_req->chain_buffer; |
| 1147 | chain_dma = chain_req->chain_buffer_dma; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1148 | } while (1); |
| 1149 | |
| 1150 | |
| 1151 | fill_in_last_segment: |
| 1152 | |
| 1153 | /* fill the last segment */ |
| 1154 | while (sges_left) { |
| 1155 | if (sges_left == 1) |
| 1156 | ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer | |
| 1157 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1158 | else |
| 1159 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1160 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1161 | sg_scmd = sg_next(sg_scmd); |
| 1162 | sg_local += ioc->sge_size; |
| 1163 | sges_left--; |
| 1164 | } |
| 1165 | |
| 1166 | return 0; |
| 1167 | } |
| 1168 | |
| 1169 | /** |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1170 | * _scsih_adjust_queue_depth - setting device queue depth |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1171 | * @sdev: scsi device struct |
| 1172 | * @qdepth: requested queue depth |
| 1173 | * |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1174 | * |
| 1175 | * Returns nothing |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1176 | */ |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1177 | static void |
| 1178 | _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1179 | { |
| 1180 | struct Scsi_Host *shost = sdev->host; |
| 1181 | int max_depth; |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1182 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1183 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1184 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1185 | struct _sas_device *sas_device; |
| 1186 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1187 | |
| 1188 | max_depth = shost->can_queue; |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1189 | |
| 1190 | /* limit max device queue for SATA to 32 */ |
| 1191 | sas_device_priv_data = sdev->hostdata; |
| 1192 | if (!sas_device_priv_data) |
| 1193 | goto not_sata; |
| 1194 | sas_target_priv_data = sas_device_priv_data->sas_target; |
| 1195 | if (!sas_target_priv_data) |
| 1196 | goto not_sata; |
| 1197 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) |
| 1198 | goto not_sata; |
| 1199 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1200 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1201 | sas_device_priv_data->sas_target->sas_address); |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1202 | if (sas_device && sas_device->device_info & |
| 1203 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1204 | max_depth = MPT2SAS_SATA_QUEUE_DEPTH; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1205 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1206 | |
| 1207 | not_sata: |
| 1208 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1209 | if (!sdev->tagged_supported) |
| 1210 | max_depth = 1; |
| 1211 | if (qdepth > max_depth) |
| 1212 | qdepth = max_depth; |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1213 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); |
| 1214 | } |
| 1215 | |
| 1216 | /** |
| 1217 | * _scsih_change_queue_depth - setting device queue depth |
| 1218 | * @sdev: scsi device struct |
| 1219 | * @qdepth: requested queue depth |
| 1220 | * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP |
| 1221 | * (see include/scsi/scsi_host.h for definition) |
| 1222 | * |
| 1223 | * Returns queue depth. |
| 1224 | */ |
| 1225 | static int |
| 1226 | _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) |
| 1227 | { |
| 1228 | if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP) |
| 1229 | _scsih_adjust_queue_depth(sdev, qdepth); |
| 1230 | else if (reason == SCSI_QDEPTH_QFULL) |
| 1231 | scsi_track_queue_full(sdev, qdepth); |
| 1232 | else |
| 1233 | return -EOPNOTSUPP; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1234 | |
| 1235 | if (sdev->inquiry_len > 7) |
| 1236 | sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " |
| 1237 | "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n", |
| 1238 | sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags, |
| 1239 | sdev->ordered_tags, sdev->scsi_level, |
| 1240 | (sdev->inquiry[7] & 2) >> 1); |
| 1241 | |
| 1242 | return sdev->queue_depth; |
| 1243 | } |
| 1244 | |
| 1245 | /** |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 1246 | * _scsih_change_queue_type - changing device queue tag type |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1247 | * @sdev: scsi device struct |
| 1248 | * @tag_type: requested tag type |
| 1249 | * |
| 1250 | * Returns queue tag type. |
| 1251 | */ |
| 1252 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1253 | _scsih_change_queue_type(struct scsi_device *sdev, int tag_type) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1254 | { |
| 1255 | if (sdev->tagged_supported) { |
| 1256 | scsi_set_tag_type(sdev, tag_type); |
| 1257 | if (tag_type) |
| 1258 | scsi_activate_tcq(sdev, sdev->queue_depth); |
| 1259 | else |
| 1260 | scsi_deactivate_tcq(sdev, sdev->queue_depth); |
| 1261 | } else |
| 1262 | tag_type = 0; |
| 1263 | |
| 1264 | return tag_type; |
| 1265 | } |
| 1266 | |
| 1267 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1268 | * _scsih_target_alloc - target add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1269 | * @starget: scsi target struct |
| 1270 | * |
| 1271 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1272 | * the device is ignored. |
| 1273 | */ |
| 1274 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1275 | _scsih_target_alloc(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1276 | { |
| 1277 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1278 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1279 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1280 | struct _sas_device *sas_device; |
| 1281 | struct _raid_device *raid_device; |
| 1282 | unsigned long flags; |
| 1283 | struct sas_rphy *rphy; |
| 1284 | |
| 1285 | sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL); |
| 1286 | if (!sas_target_priv_data) |
| 1287 | return -ENOMEM; |
| 1288 | |
| 1289 | starget->hostdata = sas_target_priv_data; |
| 1290 | sas_target_priv_data->starget = starget; |
| 1291 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; |
| 1292 | |
| 1293 | /* RAID volumes */ |
| 1294 | if (starget->channel == RAID_CHANNEL) { |
| 1295 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1296 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1297 | starget->channel); |
| 1298 | if (raid_device) { |
| 1299 | sas_target_priv_data->handle = raid_device->handle; |
| 1300 | sas_target_priv_data->sas_address = raid_device->wwid; |
| 1301 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1302 | if (ioc->is_warpdrive) |
| 1303 | sas_target_priv_data->raid_device = raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1304 | raid_device->starget = starget; |
| 1305 | } |
| 1306 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1307 | return 0; |
| 1308 | } |
| 1309 | |
| 1310 | /* sas/sata devices */ |
| 1311 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1312 | rphy = dev_to_rphy(starget->dev.parent); |
| 1313 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1314 | rphy->identify.sas_address); |
| 1315 | |
| 1316 | if (sas_device) { |
| 1317 | sas_target_priv_data->handle = sas_device->handle; |
| 1318 | sas_target_priv_data->sas_address = sas_device->sas_address; |
| 1319 | sas_device->starget = starget; |
| 1320 | sas_device->id = starget->id; |
| 1321 | sas_device->channel = starget->channel; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 1322 | if (test_bit(sas_device->handle, ioc->pd_handles)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1323 | sas_target_priv_data->flags |= |
| 1324 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 1325 | } |
| 1326 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1327 | |
| 1328 | return 0; |
| 1329 | } |
| 1330 | |
| 1331 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1332 | * _scsih_target_destroy - target destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1333 | * @starget: scsi target struct |
| 1334 | * |
| 1335 | * Returns nothing. |
| 1336 | */ |
| 1337 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1338 | _scsih_target_destroy(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1339 | { |
| 1340 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1341 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1342 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1343 | struct _sas_device *sas_device; |
| 1344 | struct _raid_device *raid_device; |
| 1345 | unsigned long flags; |
| 1346 | struct sas_rphy *rphy; |
| 1347 | |
| 1348 | sas_target_priv_data = starget->hostdata; |
| 1349 | if (!sas_target_priv_data) |
| 1350 | return; |
| 1351 | |
| 1352 | if (starget->channel == RAID_CHANNEL) { |
| 1353 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1354 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1355 | starget->channel); |
| 1356 | if (raid_device) { |
| 1357 | raid_device->starget = NULL; |
| 1358 | raid_device->sdev = NULL; |
| 1359 | } |
| 1360 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1361 | goto out; |
| 1362 | } |
| 1363 | |
| 1364 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1365 | rphy = dev_to_rphy(starget->dev.parent); |
| 1366 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1367 | rphy->identify.sas_address); |
Eric Moore | 8901cbb | 2009-04-21 15:41:32 -0600 | [diff] [blame] | 1368 | if (sas_device && (sas_device->starget == starget) && |
| 1369 | (sas_device->id == starget->id) && |
| 1370 | (sas_device->channel == starget->channel)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1371 | sas_device->starget = NULL; |
| 1372 | |
| 1373 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1374 | |
| 1375 | out: |
| 1376 | kfree(sas_target_priv_data); |
| 1377 | starget->hostdata = NULL; |
| 1378 | } |
| 1379 | |
| 1380 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1381 | * _scsih_slave_alloc - device add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1382 | * @sdev: scsi device struct |
| 1383 | * |
| 1384 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1385 | * the device is ignored. |
| 1386 | */ |
| 1387 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1388 | _scsih_slave_alloc(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1389 | { |
| 1390 | struct Scsi_Host *shost; |
| 1391 | struct MPT2SAS_ADAPTER *ioc; |
| 1392 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1393 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1394 | struct scsi_target *starget; |
| 1395 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1396 | unsigned long flags; |
| 1397 | |
| 1398 | sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL); |
| 1399 | if (!sas_device_priv_data) |
| 1400 | return -ENOMEM; |
| 1401 | |
| 1402 | sas_device_priv_data->lun = sdev->lun; |
| 1403 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; |
| 1404 | |
| 1405 | starget = scsi_target(sdev); |
| 1406 | sas_target_priv_data = starget->hostdata; |
| 1407 | sas_target_priv_data->num_luns++; |
| 1408 | sas_device_priv_data->sas_target = sas_target_priv_data; |
| 1409 | sdev->hostdata = sas_device_priv_data; |
| 1410 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) |
| 1411 | sdev->no_uld_attach = 1; |
| 1412 | |
| 1413 | shost = dev_to_shost(&starget->dev); |
| 1414 | ioc = shost_priv(shost); |
| 1415 | if (starget->channel == RAID_CHANNEL) { |
| 1416 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1417 | raid_device = _scsih_raid_device_find_by_id(ioc, |
| 1418 | starget->id, starget->channel); |
| 1419 | if (raid_device) |
| 1420 | raid_device->sdev = sdev; /* raid is single lun */ |
| 1421 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1422 | } |
| 1423 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1424 | return 0; |
| 1425 | } |
| 1426 | |
| 1427 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1428 | * _scsih_slave_destroy - device destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1429 | * @sdev: scsi device struct |
| 1430 | * |
| 1431 | * Returns nothing. |
| 1432 | */ |
| 1433 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1434 | _scsih_slave_destroy(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1435 | { |
| 1436 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1437 | struct scsi_target *starget; |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1438 | struct Scsi_Host *shost; |
| 1439 | struct MPT2SAS_ADAPTER *ioc; |
| 1440 | struct _sas_device *sas_device; |
| 1441 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1442 | |
| 1443 | if (!sdev->hostdata) |
| 1444 | return; |
| 1445 | |
| 1446 | starget = scsi_target(sdev); |
| 1447 | sas_target_priv_data = starget->hostdata; |
| 1448 | sas_target_priv_data->num_luns--; |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1449 | |
| 1450 | shost = dev_to_shost(&starget->dev); |
| 1451 | ioc = shost_priv(shost); |
| 1452 | |
| 1453 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
| 1454 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1455 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1456 | sas_target_priv_data->sas_address); |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 1457 | if (sas_device && !sas_target_priv_data->num_luns) |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1458 | sas_device->starget = NULL; |
| 1459 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1460 | } |
| 1461 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1462 | kfree(sdev->hostdata); |
| 1463 | sdev->hostdata = NULL; |
| 1464 | } |
| 1465 | |
| 1466 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1467 | * _scsih_display_sata_capabilities - sata capabilities |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1468 | * @ioc: per adapter object |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1469 | * @handle: device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1470 | * @sdev: scsi device struct |
| 1471 | */ |
| 1472 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1473 | _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1474 | u16 handle, struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1475 | { |
| 1476 | Mpi2ConfigReply_t mpi_reply; |
| 1477 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1478 | u32 ioc_status; |
| 1479 | u16 flags; |
| 1480 | u32 device_info; |
| 1481 | |
| 1482 | 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] | 1483 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1484 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1485 | ioc->name, __FILE__, __LINE__, __func__); |
| 1486 | return; |
| 1487 | } |
| 1488 | |
| 1489 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1490 | MPI2_IOCSTATUS_MASK; |
| 1491 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 1492 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1493 | ioc->name, __FILE__, __LINE__, __func__); |
| 1494 | return; |
| 1495 | } |
| 1496 | |
| 1497 | flags = le16_to_cpu(sas_device_pg0.Flags); |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 1498 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1499 | |
| 1500 | sdev_printk(KERN_INFO, sdev, |
| 1501 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " |
| 1502 | "sw_preserve(%s)\n", |
| 1503 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", |
| 1504 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", |
| 1505 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : |
| 1506 | "n", |
| 1507 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", |
| 1508 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", |
| 1509 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); |
| 1510 | } |
| 1511 | |
| 1512 | /** |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1513 | * _scsih_is_raid - return boolean indicating device is raid volume |
| 1514 | * @dev the device struct object |
| 1515 | */ |
| 1516 | static int |
| 1517 | _scsih_is_raid(struct device *dev) |
| 1518 | { |
| 1519 | struct scsi_device *sdev = to_scsi_device(dev); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1520 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1521 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1522 | if (ioc->is_warpdrive) |
| 1523 | return 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1524 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
| 1525 | } |
| 1526 | |
| 1527 | /** |
| 1528 | * _scsih_get_resync - get raid volume resync percent complete |
| 1529 | * @dev the device struct object |
| 1530 | */ |
| 1531 | static void |
| 1532 | _scsih_get_resync(struct device *dev) |
| 1533 | { |
| 1534 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1535 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1536 | static struct _raid_device *raid_device; |
| 1537 | unsigned long flags; |
| 1538 | Mpi2RaidVolPage0_t vol_pg0; |
| 1539 | Mpi2ConfigReply_t mpi_reply; |
| 1540 | u32 volume_status_flags; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1541 | u8 percent_complete; |
| 1542 | u16 handle; |
| 1543 | |
| 1544 | percent_complete = 0; |
| 1545 | handle = 0; |
| 1546 | if (ioc->is_warpdrive) |
| 1547 | goto out; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1548 | |
| 1549 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1550 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1551 | sdev->channel); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1552 | if (raid_device) { |
| 1553 | handle = raid_device->handle; |
| 1554 | percent_complete = raid_device->percent_complete; |
| 1555 | } |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1556 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1557 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1558 | if (!handle) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1559 | goto out; |
| 1560 | |
| 1561 | 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] | 1562 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1563 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1564 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1565 | ioc->name, __FILE__, __LINE__, __func__); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1566 | percent_complete = 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1567 | goto out; |
| 1568 | } |
| 1569 | |
| 1570 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1571 | if (!(volume_status_flags & |
| 1572 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) |
| 1573 | percent_complete = 0; |
| 1574 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1575 | out: |
| 1576 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); |
| 1577 | } |
| 1578 | |
| 1579 | /** |
| 1580 | * _scsih_get_state - get raid volume level |
| 1581 | * @dev the device struct object |
| 1582 | */ |
| 1583 | static void |
| 1584 | _scsih_get_state(struct device *dev) |
| 1585 | { |
| 1586 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1587 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1588 | static struct _raid_device *raid_device; |
| 1589 | unsigned long flags; |
| 1590 | Mpi2RaidVolPage0_t vol_pg0; |
| 1591 | Mpi2ConfigReply_t mpi_reply; |
| 1592 | u32 volstate; |
| 1593 | enum raid_state state = RAID_STATE_UNKNOWN; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1594 | u16 handle = 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1595 | |
| 1596 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1597 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1598 | sdev->channel); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1599 | if (raid_device) |
| 1600 | handle = raid_device->handle; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1601 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1602 | |
| 1603 | if (!raid_device) |
| 1604 | goto out; |
| 1605 | |
| 1606 | 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] | 1607 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1608 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1609 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1610 | ioc->name, __FILE__, __LINE__, __func__); |
| 1611 | goto out; |
| 1612 | } |
| 1613 | |
| 1614 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
| 1615 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { |
| 1616 | state = RAID_STATE_RESYNCING; |
| 1617 | goto out; |
| 1618 | } |
| 1619 | |
| 1620 | switch (vol_pg0.VolumeState) { |
| 1621 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
| 1622 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 1623 | state = RAID_STATE_ACTIVE; |
| 1624 | break; |
| 1625 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 1626 | state = RAID_STATE_DEGRADED; |
| 1627 | break; |
| 1628 | case MPI2_RAID_VOL_STATE_FAILED: |
| 1629 | case MPI2_RAID_VOL_STATE_MISSING: |
| 1630 | state = RAID_STATE_OFFLINE; |
| 1631 | break; |
| 1632 | } |
| 1633 | out: |
| 1634 | raid_set_state(mpt2sas_raid_template, dev, state); |
| 1635 | } |
| 1636 | |
| 1637 | /** |
| 1638 | * _scsih_set_level - set raid level |
| 1639 | * @sdev: scsi device struct |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1640 | * @volume_type: volume type |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1641 | */ |
| 1642 | static void |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1643 | _scsih_set_level(struct scsi_device *sdev, u8 volume_type) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1644 | { |
| 1645 | enum raid_level level = RAID_LEVEL_UNKNOWN; |
| 1646 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1647 | switch (volume_type) { |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1648 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 1649 | level = RAID_LEVEL_0; |
| 1650 | break; |
| 1651 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 1652 | level = RAID_LEVEL_10; |
| 1653 | break; |
| 1654 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 1655 | level = RAID_LEVEL_1E; |
| 1656 | break; |
| 1657 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 1658 | level = RAID_LEVEL_1; |
| 1659 | break; |
| 1660 | } |
| 1661 | |
| 1662 | raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level); |
| 1663 | } |
| 1664 | |
| 1665 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1666 | * _scsih_get_volume_capabilities - volume capabilities |
| 1667 | * @ioc: per adapter object |
| 1668 | * @sas_device: the raid_device object |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1669 | * |
| 1670 | * Returns 0 for success, else 1 |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1671 | */ |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1672 | static int |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1673 | _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc, |
| 1674 | struct _raid_device *raid_device) |
| 1675 | { |
| 1676 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1677 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1678 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1679 | Mpi2ConfigReply_t mpi_reply; |
| 1680 | u16 sz; |
| 1681 | u8 num_pds; |
| 1682 | |
| 1683 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1684 | &num_pds)) || !num_pds) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1685 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1686 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1687 | __func__)); |
| 1688 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | raid_device->num_pds = num_pds; |
| 1692 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1693 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1694 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1695 | if (!vol_pg0) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1696 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1697 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1698 | __func__)); |
| 1699 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1703 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1704 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1705 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1706 | __func__)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1707 | kfree(vol_pg0); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1708 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | raid_device->volume_type = vol_pg0->VolumeType; |
| 1712 | |
| 1713 | /* figure out what the underlying devices are by |
| 1714 | * obtaining the device_info bits for the 1st device |
| 1715 | */ |
| 1716 | if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1717 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1718 | vol_pg0->PhysDisk[0].PhysDiskNum))) { |
| 1719 | if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 1720 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 1721 | le16_to_cpu(pd_pg0.DevHandle)))) { |
| 1722 | raid_device->device_info = |
| 1723 | le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | kfree(vol_pg0); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1728 | return 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1729 | } |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1730 | /** |
| 1731 | * _scsih_disable_ddio - Disable direct I/O for all the volumes |
| 1732 | * @ioc: per adapter object |
| 1733 | */ |
| 1734 | static void |
| 1735 | _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc) |
| 1736 | { |
| 1737 | Mpi2RaidVolPage1_t vol_pg1; |
| 1738 | Mpi2ConfigReply_t mpi_reply; |
| 1739 | struct _raid_device *raid_device; |
| 1740 | u16 handle; |
| 1741 | u16 ioc_status; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1742 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1743 | |
| 1744 | handle = 0xFFFF; |
| 1745 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 1746 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 1747 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1748 | MPI2_IOCSTATUS_MASK; |
| 1749 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 1750 | break; |
| 1751 | handle = le16_to_cpu(vol_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1752 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1753 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 1754 | if (raid_device) |
| 1755 | raid_device->direct_io_enabled = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1756 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1757 | } |
| 1758 | return; |
| 1759 | } |
| 1760 | |
| 1761 | |
| 1762 | /** |
| 1763 | * _scsih_get_num_volumes - Get number of volumes in the ioc |
| 1764 | * @ioc: per adapter object |
| 1765 | */ |
| 1766 | static u8 |
| 1767 | _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc) |
| 1768 | { |
| 1769 | Mpi2RaidVolPage1_t vol_pg1; |
| 1770 | Mpi2ConfigReply_t mpi_reply; |
| 1771 | u16 handle; |
| 1772 | u8 vol_cnt = 0; |
| 1773 | u16 ioc_status; |
| 1774 | |
| 1775 | handle = 0xFFFF; |
| 1776 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 1777 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 1778 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1779 | MPI2_IOCSTATUS_MASK; |
| 1780 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 1781 | break; |
| 1782 | vol_cnt++; |
| 1783 | handle = le16_to_cpu(vol_pg1.DevHandle); |
| 1784 | } |
| 1785 | return vol_cnt; |
| 1786 | } |
| 1787 | |
| 1788 | |
| 1789 | /** |
| 1790 | * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O. |
| 1791 | * @ioc: per adapter object |
| 1792 | * @raid_device: the raid_device object |
| 1793 | */ |
| 1794 | static void |
| 1795 | _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc, |
| 1796 | struct _raid_device *raid_device) |
| 1797 | { |
| 1798 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1799 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1800 | Mpi2ConfigReply_t mpi_reply; |
| 1801 | u16 sz; |
| 1802 | u8 num_pds, count; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1803 | unsigned long stripe_sz, block_sz; |
| 1804 | u8 stripe_exp, block_exp; |
| 1805 | u64 dev_max_lba; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1806 | |
| 1807 | if (!ioc->is_warpdrive) |
| 1808 | return; |
| 1809 | |
| 1810 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) { |
| 1811 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1812 | "globally as drives are exposed\n", ioc->name); |
| 1813 | return; |
| 1814 | } |
| 1815 | if (_scsih_get_num_volumes(ioc) > 1) { |
| 1816 | _scsih_disable_ddio(ioc); |
| 1817 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1818 | "globally as number of drives > 1\n", ioc->name); |
| 1819 | return; |
| 1820 | } |
| 1821 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1822 | &num_pds)) || !num_pds) { |
| 1823 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1824 | "Failure in computing number of drives\n", ioc->name); |
| 1825 | return; |
| 1826 | } |
| 1827 | |
| 1828 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1829 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1830 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1831 | if (!vol_pg0) { |
| 1832 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1833 | "Memory allocation failure for RVPG0\n", ioc->name); |
| 1834 | return; |
| 1835 | } |
| 1836 | |
| 1837 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1838 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
| 1839 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1840 | "Failure in retrieving RVPG0\n", ioc->name); |
| 1841 | kfree(vol_pg0); |
| 1842 | return; |
| 1843 | } |
| 1844 | |
| 1845 | /* |
| 1846 | * WARPDRIVE:If number of physical disks in a volume exceeds the max pds |
| 1847 | * assumed for WARPDRIVE, disable direct I/O |
| 1848 | */ |
| 1849 | if (num_pds > MPT_MAX_WARPDRIVE_PDS) { |
| 1850 | printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled " |
| 1851 | "for the drive with handle(0x%04x): num_mem=%d, " |
| 1852 | "max_mem_allowed=%d\n", ioc->name, raid_device->handle, |
| 1853 | num_pds, MPT_MAX_WARPDRIVE_PDS); |
| 1854 | kfree(vol_pg0); |
| 1855 | return; |
| 1856 | } |
| 1857 | for (count = 0; count < num_pds; count++) { |
| 1858 | if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1859 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1860 | vol_pg0->PhysDisk[count].PhysDiskNum) || |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 1861 | le16_to_cpu(pd_pg0.DevHandle) == |
| 1862 | MPT2SAS_INVALID_DEVICE_HANDLE) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1863 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " |
| 1864 | "disabled for the drive with handle(0x%04x) member" |
| 1865 | "handle retrieval failed for member number=%d\n", |
| 1866 | ioc->name, raid_device->handle, |
| 1867 | vol_pg0->PhysDisk[count].PhysDiskNum); |
| 1868 | goto out_error; |
| 1869 | } |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1870 | /* Disable direct I/O if member drive lba exceeds 4 bytes */ |
| 1871 | dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA); |
| 1872 | if (dev_max_lba >> 32) { |
| 1873 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " |
| 1874 | "disabled for the drive with handle(0x%04x) member" |
| 1875 | "handle (0x%04x) unsupported max lba 0x%016llx\n", |
| 1876 | ioc->name, raid_device->handle, |
| 1877 | le16_to_cpu(pd_pg0.DevHandle), |
| 1878 | (unsigned long long)dev_max_lba); |
| 1879 | goto out_error; |
| 1880 | } |
| 1881 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1882 | raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle); |
| 1883 | } |
| 1884 | |
| 1885 | /* |
| 1886 | * 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] | 1887 | * not RAID0 |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1888 | */ |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1889 | if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1890 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1891 | "for the drive with handle(0x%04x): type=%d, " |
| 1892 | "s_sz=%uK, blk_size=%u\n", ioc->name, |
| 1893 | raid_device->handle, raid_device->volume_type, |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1894 | (le32_to_cpu(vol_pg0->StripeSize) * |
| 1895 | le16_to_cpu(vol_pg0->BlockSize)) / 1024, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1896 | le16_to_cpu(vol_pg0->BlockSize)); |
| 1897 | goto out_error; |
| 1898 | } |
| 1899 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1900 | stripe_sz = le32_to_cpu(vol_pg0->StripeSize); |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1901 | stripe_exp = find_first_bit(&stripe_sz, 32); |
| 1902 | if (stripe_exp == 32) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1903 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1904 | "for the drive with handle(0x%04x) invalid stripe sz %uK\n", |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1905 | ioc->name, raid_device->handle, |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1906 | (le32_to_cpu(vol_pg0->StripeSize) * |
| 1907 | le16_to_cpu(vol_pg0->BlockSize)) / 1024); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1908 | goto out_error; |
| 1909 | } |
| 1910 | raid_device->stripe_exponent = stripe_exp; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1911 | block_sz = le16_to_cpu(vol_pg0->BlockSize); |
| 1912 | block_exp = find_first_bit(&block_sz, 16); |
| 1913 | if (block_exp == 16) { |
| 1914 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1915 | "for the drive with handle(0x%04x) invalid block sz %u\n", |
| 1916 | ioc->name, raid_device->handle, |
| 1917 | le16_to_cpu(vol_pg0->BlockSize)); |
| 1918 | goto out_error; |
| 1919 | } |
| 1920 | raid_device->block_exponent = block_exp; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1921 | raid_device->direct_io_enabled = 1; |
| 1922 | |
| 1923 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive" |
| 1924 | " with handle(0x%04x)\n", ioc->name, raid_device->handle); |
| 1925 | /* |
| 1926 | * WARPDRIVE: Though the following fields are not used for direct IO, |
| 1927 | * stored for future purpose: |
| 1928 | */ |
| 1929 | raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA); |
| 1930 | raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize); |
| 1931 | raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize); |
| 1932 | |
| 1933 | |
| 1934 | kfree(vol_pg0); |
| 1935 | return; |
| 1936 | |
| 1937 | out_error: |
| 1938 | raid_device->direct_io_enabled = 0; |
| 1939 | for (count = 0; count < num_pds; count++) |
| 1940 | raid_device->pd_handle[count] = 0; |
| 1941 | kfree(vol_pg0); |
| 1942 | return; |
| 1943 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1944 | |
| 1945 | /** |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 1946 | * _scsih_enable_tlr - setting TLR flags |
| 1947 | * @ioc: per adapter object |
| 1948 | * @sdev: scsi device struct |
| 1949 | * |
| 1950 | * Enabling Transaction Layer Retries for tape devices when |
| 1951 | * vpd page 0x90 is present |
| 1952 | * |
| 1953 | */ |
| 1954 | static void |
| 1955 | _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev) |
| 1956 | { |
| 1957 | /* only for TAPE */ |
| 1958 | if (sdev->type != TYPE_TAPE) |
| 1959 | return; |
| 1960 | |
| 1961 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) |
| 1962 | return; |
| 1963 | |
| 1964 | sas_enable_tlr(sdev); |
| 1965 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", |
| 1966 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); |
| 1967 | return; |
| 1968 | |
| 1969 | } |
| 1970 | |
| 1971 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1972 | * _scsih_slave_configure - device configure routine. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1973 | * @sdev: scsi device struct |
| 1974 | * |
| 1975 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1976 | * the device is ignored. |
| 1977 | */ |
| 1978 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1979 | _scsih_slave_configure(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1980 | { |
| 1981 | struct Scsi_Host *shost = sdev->host; |
| 1982 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1983 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1984 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1985 | struct _sas_device *sas_device; |
| 1986 | struct _raid_device *raid_device; |
| 1987 | unsigned long flags; |
| 1988 | int qdepth; |
| 1989 | u8 ssp_target = 0; |
| 1990 | char *ds = ""; |
| 1991 | char *r_level = ""; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 1992 | u16 handle, volume_handle = 0; |
| 1993 | u64 volume_wwid = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1994 | |
| 1995 | qdepth = 1; |
| 1996 | sas_device_priv_data = sdev->hostdata; |
| 1997 | sas_device_priv_data->configured_lun = 1; |
| 1998 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; |
| 1999 | sas_target_priv_data = sas_device_priv_data->sas_target; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2000 | handle = sas_target_priv_data->handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2001 | |
| 2002 | /* raid volume handling */ |
| 2003 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 2004 | |
| 2005 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2006 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2007 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 2008 | if (!raid_device) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2009 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2010 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2011 | __LINE__, __func__)); |
| 2012 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2013 | } |
| 2014 | |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2015 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { |
| 2016 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2017 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2018 | __LINE__, __func__)); |
| 2019 | return 1; |
| 2020 | } |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2021 | /* |
| 2022 | * WARPDRIVE: Initialize the required data for Direct IO |
| 2023 | */ |
| 2024 | _scsih_init_warpdrive_properties(ioc, raid_device); |
| 2025 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2026 | /* RAID Queue Depth Support |
| 2027 | * IS volume = underlying qdepth of drive type, either |
| 2028 | * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH |
| 2029 | * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH) |
| 2030 | */ |
| 2031 | if (raid_device->device_info & |
| 2032 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 2033 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 2034 | ds = "SSP"; |
| 2035 | } else { |
| 2036 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 2037 | if (raid_device->device_info & |
| 2038 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 2039 | ds = "SATA"; |
| 2040 | else |
| 2041 | ds = "STP"; |
| 2042 | } |
| 2043 | |
| 2044 | switch (raid_device->volume_type) { |
| 2045 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 2046 | r_level = "RAID0"; |
| 2047 | break; |
| 2048 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 2049 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 2050 | if (ioc->manu_pg10.OEMIdentifier && |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 2051 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 2052 | MFG10_GF0_R10_DISPLAY) && |
| 2053 | !(raid_device->num_pds % 2)) |
| 2054 | r_level = "RAID10"; |
| 2055 | else |
| 2056 | r_level = "RAID1E"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2057 | break; |
| 2058 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 2059 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2060 | r_level = "RAID1"; |
| 2061 | break; |
| 2062 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 2063 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2064 | r_level = "RAID10"; |
| 2065 | break; |
| 2066 | case MPI2_RAID_VOL_TYPE_UNKNOWN: |
| 2067 | default: |
| 2068 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2069 | r_level = "RAIDX"; |
| 2070 | break; |
| 2071 | } |
| 2072 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2073 | if (!ioc->hide_ir_msg) |
| 2074 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
| 2075 | "wwid(0x%016llx), pd_count(%d), type(%s)\n", |
| 2076 | r_level, raid_device->handle, |
| 2077 | (unsigned long long)raid_device->wwid, |
| 2078 | raid_device->num_pds, ds); |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 2079 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 2080 | /* raid transport support */ |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2081 | if (!ioc->is_warpdrive) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2082 | _scsih_set_level(sdev, raid_device->volume_type); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2083 | return 0; |
| 2084 | } |
| 2085 | |
| 2086 | /* non-raid handling */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2087 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2088 | if (mpt2sas_config_get_volume_handle(ioc, handle, |
| 2089 | &volume_handle)) { |
| 2090 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2091 | "failure at %s:%d/%s()!\n", ioc->name, |
| 2092 | __FILE__, __LINE__, __func__)); |
| 2093 | return 1; |
| 2094 | } |
| 2095 | if (volume_handle && mpt2sas_config_get_volume_wwid(ioc, |
| 2096 | volume_handle, &volume_wwid)) { |
| 2097 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2098 | "failure at %s:%d/%s()!\n", ioc->name, |
| 2099 | __FILE__, __LINE__, __func__)); |
| 2100 | return 1; |
| 2101 | } |
| 2102 | } |
| 2103 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2104 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2105 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2106 | sas_device_priv_data->sas_target->sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2107 | if (!sas_device) { |
| 2108 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2109 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2110 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2111 | __LINE__, __func__)); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2112 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2113 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 2114 | sas_device->volume_handle = volume_handle; |
| 2115 | sas_device->volume_wwid = volume_wwid; |
| 2116 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 2117 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 2118 | ssp_target = 1; |
| 2119 | ds = "SSP"; |
| 2120 | } else { |
| 2121 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 2122 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
| 2123 | ds = "STP"; |
| 2124 | else if (sas_device->device_info & |
| 2125 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 2126 | ds = "SATA"; |
| 2127 | } |
| 2128 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
| 2129 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", |
| 2130 | ds, sas_device->handle, |
| 2131 | (unsigned long long)sas_device->sas_address, |
| 2132 | sas_device->phy, |
| 2133 | (unsigned long long)sas_device->device_name); |
| 2134 | sdev_printk(KERN_INFO, sdev, "%s: " |
| 2135 | "enclosure_logical_id(0x%016llx), slot(%d)\n", ds, |
| 2136 | (unsigned long long) sas_device->enclosure_logical_id, |
| 2137 | sas_device->slot); |
| 2138 | |
| 2139 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2140 | if (!ssp_target) |
| 2141 | _scsih_display_sata_capabilities(ioc, handle, sdev); |
| 2142 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2143 | |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 2144 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2145 | |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 2146 | if (ssp_target) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2147 | sas_read_port_mode_page(sdev); |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 2148 | _scsih_enable_tlr(ioc, sdev); |
| 2149 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2150 | return 0; |
| 2151 | } |
| 2152 | |
| 2153 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2154 | * _scsih_bios_param - fetch head, sector, cylinder info for a disk |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2155 | * @sdev: scsi device struct |
| 2156 | * @bdev: pointer to block device context |
| 2157 | * @capacity: device size (in 512 byte sectors) |
| 2158 | * @params: three element array to place output: |
| 2159 | * params[0] number of heads (max 255) |
| 2160 | * params[1] number of sectors (max 63) |
| 2161 | * params[2] number of cylinders |
| 2162 | * |
| 2163 | * Return nothing. |
| 2164 | */ |
| 2165 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2166 | _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2167 | sector_t capacity, int params[]) |
| 2168 | { |
| 2169 | int heads; |
| 2170 | int sectors; |
| 2171 | sector_t cylinders; |
| 2172 | ulong dummy; |
| 2173 | |
| 2174 | heads = 64; |
| 2175 | sectors = 32; |
| 2176 | |
| 2177 | dummy = heads * sectors; |
| 2178 | cylinders = capacity; |
| 2179 | sector_div(cylinders, dummy); |
| 2180 | |
| 2181 | /* |
| 2182 | * Handle extended translation size for logical drives |
| 2183 | * > 1Gb |
| 2184 | */ |
| 2185 | if ((ulong)capacity >= 0x200000) { |
| 2186 | heads = 255; |
| 2187 | sectors = 63; |
| 2188 | dummy = heads * sectors; |
| 2189 | cylinders = capacity; |
| 2190 | sector_div(cylinders, dummy); |
| 2191 | } |
| 2192 | |
| 2193 | /* return result */ |
| 2194 | params[0] = heads; |
| 2195 | params[1] = sectors; |
| 2196 | params[2] = cylinders; |
| 2197 | |
| 2198 | return 0; |
| 2199 | } |
| 2200 | |
| 2201 | /** |
| 2202 | * _scsih_response_code - translation of device response code |
| 2203 | * @ioc: per adapter object |
| 2204 | * @response_code: response code returned by the device |
| 2205 | * |
| 2206 | * Return nothing. |
| 2207 | */ |
| 2208 | static void |
| 2209 | _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code) |
| 2210 | { |
| 2211 | char *desc; |
| 2212 | |
| 2213 | switch (response_code) { |
| 2214 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: |
| 2215 | desc = "task management request completed"; |
| 2216 | break; |
| 2217 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: |
| 2218 | desc = "invalid frame"; |
| 2219 | break; |
| 2220 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: |
| 2221 | desc = "task management request not supported"; |
| 2222 | break; |
| 2223 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: |
| 2224 | desc = "task management request failed"; |
| 2225 | break; |
| 2226 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: |
| 2227 | desc = "task management request succeeded"; |
| 2228 | break; |
| 2229 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: |
| 2230 | desc = "invalid lun"; |
| 2231 | break; |
| 2232 | case 0xA: |
| 2233 | desc = "overlapped tag attempted"; |
| 2234 | break; |
| 2235 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: |
| 2236 | desc = "task queued, however not sent to target"; |
| 2237 | break; |
| 2238 | default: |
| 2239 | desc = "unknown"; |
| 2240 | break; |
| 2241 | } |
| 2242 | printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n", |
| 2243 | ioc->name, response_code, desc); |
| 2244 | } |
| 2245 | |
| 2246 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2247 | * _scsih_tm_done - tm completion routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2248 | * @ioc: per adapter object |
| 2249 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2250 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2251 | * @reply: reply message frame(lower 32bit addr) |
| 2252 | * Context: none. |
| 2253 | * |
| 2254 | * The callback handler when using scsih_issue_tm. |
| 2255 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2256 | * Return 1 meaning mf should be freed from _base_interrupt |
| 2257 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2258 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2259 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2260 | _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] | 2261 | { |
| 2262 | MPI2DefaultReply_t *mpi_reply; |
| 2263 | |
| 2264 | if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2265 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2266 | if (ioc->tm_cmds.smid != smid) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2267 | return 1; |
nagalakshmi.nandigama@lsi.com | 911ae94 | 2011-09-08 06:18:50 +0530 | [diff] [blame] | 2268 | mpt2sas_base_flush_reply_queues(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2269 | ioc->tm_cmds.status |= MPT2_CMD_COMPLETE; |
| 2270 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 2271 | if (mpi_reply) { |
| 2272 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 2273 | ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 2274 | } |
| 2275 | ioc->tm_cmds.status &= ~MPT2_CMD_PENDING; |
| 2276 | complete(&ioc->tm_cmds.done); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2277 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | /** |
| 2281 | * mpt2sas_scsih_set_tm_flag - set per target tm_busy |
| 2282 | * @ioc: per adapter object |
| 2283 | * @handle: device handle |
| 2284 | * |
| 2285 | * During taskmangement request, we need to freeze the device queue. |
| 2286 | */ |
| 2287 | void |
| 2288 | mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2289 | { |
| 2290 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2291 | struct scsi_device *sdev; |
| 2292 | u8 skip = 0; |
| 2293 | |
| 2294 | shost_for_each_device(sdev, ioc->shost) { |
| 2295 | if (skip) |
| 2296 | continue; |
| 2297 | sas_device_priv_data = sdev->hostdata; |
| 2298 | if (!sas_device_priv_data) |
| 2299 | continue; |
| 2300 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2301 | sas_device_priv_data->sas_target->tm_busy = 1; |
| 2302 | skip = 1; |
| 2303 | ioc->ignore_loginfos = 1; |
| 2304 | } |
| 2305 | } |
| 2306 | } |
| 2307 | |
| 2308 | /** |
| 2309 | * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy |
| 2310 | * @ioc: per adapter object |
| 2311 | * @handle: device handle |
| 2312 | * |
| 2313 | * During taskmangement request, we need to freeze the device queue. |
| 2314 | */ |
| 2315 | void |
| 2316 | mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2317 | { |
| 2318 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2319 | struct scsi_device *sdev; |
| 2320 | u8 skip = 0; |
| 2321 | |
| 2322 | shost_for_each_device(sdev, ioc->shost) { |
| 2323 | if (skip) |
| 2324 | continue; |
| 2325 | sas_device_priv_data = sdev->hostdata; |
| 2326 | if (!sas_device_priv_data) |
| 2327 | continue; |
| 2328 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2329 | sas_device_priv_data->sas_target->tm_busy = 0; |
| 2330 | skip = 1; |
| 2331 | ioc->ignore_loginfos = 0; |
| 2332 | } |
| 2333 | } |
| 2334 | } |
| 2335 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2336 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2337 | /** |
| 2338 | * mpt2sas_scsih_issue_tm - main routine for sending tm requests |
| 2339 | * @ioc: per adapter struct |
| 2340 | * @device_handle: device handle |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2341 | * @channel: the channel assigned by the OS |
| 2342 | * @id: the id assigned by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2343 | * @lun: lun number |
| 2344 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) |
| 2345 | * @smid_task: smid assigned to the task |
| 2346 | * @timeout: timeout in seconds |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2347 | * @serial_number: the serial_number from scmd |
| 2348 | * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2349 | * Context: user |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2350 | * |
| 2351 | * A generic API for sending task management requests to firmware. |
| 2352 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2353 | * The callback index is set inside `ioc->tm_cb_idx`. |
| 2354 | * |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2355 | * Return SUCCESS or FAILED. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2356 | */ |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2357 | int |
| 2358 | mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel, |
| 2359 | uint id, uint lun, u8 type, u16 smid_task, ulong timeout, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2360 | unsigned long serial_number, enum mutex_type m_type) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2361 | { |
| 2362 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 2363 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
| 2364 | u16 smid = 0; |
| 2365 | u32 ioc_state; |
| 2366 | unsigned long timeleft; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2367 | struct scsiio_tracker *scsi_lookup = NULL; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2368 | int rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2369 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2370 | if (m_type == TM_MUTEX_ON) |
| 2371 | mutex_lock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2372 | if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) { |
| 2373 | printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n", |
| 2374 | __func__, ioc->name); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2375 | rc = FAILED; |
| 2376 | goto err_out; |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2377 | } |
| 2378 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 2379 | if (ioc->shost_recovery || ioc->remove_host || |
| 2380 | ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2381 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 2382 | __func__, ioc->name); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2383 | rc = FAILED; |
| 2384 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2385 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2386 | |
| 2387 | ioc_state = mpt2sas_base_get_iocstate(ioc, 0); |
| 2388 | if (ioc_state & MPI2_DOORBELL_USED) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 2389 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2390 | "active!\n", ioc->name)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2391 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2392 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2393 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2394 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 2398 | mpt2sas_base_fault_info(ioc, ioc_state & |
| 2399 | MPI2_DOORBELL_DATA_MASK); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2400 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2401 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2402 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2403 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2404 | } |
| 2405 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2406 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2407 | if (!smid) { |
| 2408 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 2409 | ioc->name, __func__); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2410 | rc = FAILED; |
| 2411 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2412 | } |
| 2413 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2414 | if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) |
| 2415 | scsi_lookup = &ioc->scsi_lookup[smid_task - 1]; |
| 2416 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2417 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x)," |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2418 | " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type, |
| 2419 | smid_task)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2420 | ioc->tm_cmds.status = MPT2_CMD_PENDING; |
| 2421 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 2422 | ioc->tm_cmds.smid = smid; |
| 2423 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2424 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2425 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 2426 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 2427 | mpi_request->TaskType = type; |
| 2428 | mpi_request->TaskMID = cpu_to_le16(smid_task); |
| 2429 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); |
| 2430 | mpt2sas_scsih_set_tm_flag(ioc, handle); |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 2431 | init_completion(&ioc->tm_cmds.done); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2432 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2433 | timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2434 | if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) { |
| 2435 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 2436 | ioc->name, __func__); |
| 2437 | _debug_dump_mf(mpi_request, |
| 2438 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2439 | if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) { |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2440 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2441 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2442 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2443 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
| 2444 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 2445 | goto err_out; |
| 2446 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 2450 | mpi_reply = ioc->tm_cmds.reply; |
| 2451 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: " |
| 2452 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", |
| 2453 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 2454 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 2455 | le32_to_cpu(mpi_reply->TerminationCount))); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2456 | if (ioc->logging_level & MPT_DEBUG_TM) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2457 | _scsih_response_code(ioc, mpi_reply->ResponseCode); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2458 | if (mpi_reply->IOCStatus) |
| 2459 | _debug_dump_mf(mpi_request, |
| 2460 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
| 2461 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2462 | } |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2463 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2464 | switch (type) { |
| 2465 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2466 | rc = SUCCESS; |
| 2467 | if (scsi_lookup->scmd == NULL) |
| 2468 | break; |
| 2469 | rc = FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2470 | break; |
| 2471 | |
| 2472 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: |
| 2473 | if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) |
| 2474 | rc = FAILED; |
| 2475 | else |
| 2476 | rc = SUCCESS; |
| 2477 | break; |
| 2478 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2479 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2480 | case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: |
| 2481 | if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) |
| 2482 | rc = FAILED; |
| 2483 | else |
| 2484 | rc = SUCCESS; |
| 2485 | break; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2486 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: |
| 2487 | rc = SUCCESS; |
| 2488 | break; |
| 2489 | default: |
| 2490 | rc = FAILED; |
| 2491 | break; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2492 | } |
| 2493 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2494 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 2495 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2496 | if (m_type == TM_MUTEX_ON) |
| 2497 | mutex_unlock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2498 | |
| 2499 | return rc; |
| 2500 | |
| 2501 | err_out: |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2502 | if (m_type == TM_MUTEX_ON) |
| 2503 | mutex_unlock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2504 | return rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2505 | } |
| 2506 | |
| 2507 | /** |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2508 | * _scsih_tm_display_info - displays info about the device |
| 2509 | * @ioc: per adapter struct |
| 2510 | * @scmd: pointer to scsi command object |
| 2511 | * |
| 2512 | * Called by task management callback handlers. |
| 2513 | */ |
| 2514 | static void |
| 2515 | _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) |
| 2516 | { |
| 2517 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2518 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; |
| 2519 | struct _sas_device *sas_device = NULL; |
| 2520 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2521 | char *device_str = NULL; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2522 | |
| 2523 | if (!priv_target) |
| 2524 | return; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2525 | if (ioc->hide_ir_msg) |
| 2526 | device_str = "WarpDrive"; |
| 2527 | else |
| 2528 | device_str = "volume"; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2529 | |
| 2530 | scsi_print_command(scmd); |
| 2531 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2532 | starget_printk(KERN_INFO, starget, "%s handle(0x%04x), " |
| 2533 | "%s wwid(0x%016llx)\n", device_str, priv_target->handle, |
| 2534 | device_str, (unsigned long long)priv_target->sas_address); |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2535 | } else { |
| 2536 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2537 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2538 | priv_target->sas_address); |
| 2539 | if (sas_device) { |
| 2540 | if (priv_target->flags & |
| 2541 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2542 | starget_printk(KERN_INFO, starget, |
| 2543 | "volume handle(0x%04x), " |
| 2544 | "volume wwid(0x%016llx)\n", |
| 2545 | sas_device->volume_handle, |
| 2546 | (unsigned long long)sas_device->volume_wwid); |
| 2547 | } |
| 2548 | starget_printk(KERN_INFO, starget, |
| 2549 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", |
| 2550 | sas_device->handle, |
| 2551 | (unsigned long long)sas_device->sas_address, |
| 2552 | sas_device->phy); |
| 2553 | starget_printk(KERN_INFO, starget, |
| 2554 | "enclosure_logical_id(0x%016llx), slot(%d)\n", |
| 2555 | (unsigned long long)sas_device->enclosure_logical_id, |
| 2556 | sas_device->slot); |
| 2557 | } |
| 2558 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2559 | } |
| 2560 | } |
| 2561 | |
| 2562 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2563 | * _scsih_abort - eh threads main abort routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2564 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2565 | * |
| 2566 | * Returns SUCCESS if command aborted else FAILED |
| 2567 | */ |
| 2568 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2569 | _scsih_abort(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2570 | { |
| 2571 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2572 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2573 | u16 smid; |
| 2574 | u16 handle; |
| 2575 | int r; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2576 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2577 | sdev_printk(KERN_INFO, scmd->device, "attempting task abort! " |
| 2578 | "scmd(%p)\n", scmd); |
| 2579 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2580 | |
| 2581 | sas_device_priv_data = scmd->device->hostdata; |
| 2582 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2583 | sdev_printk(KERN_INFO, scmd->device, "device been deleted! " |
| 2584 | "scmd(%p)\n", scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2585 | scmd->result = DID_NO_CONNECT << 16; |
| 2586 | scmd->scsi_done(scmd); |
| 2587 | r = SUCCESS; |
| 2588 | goto out; |
| 2589 | } |
| 2590 | |
| 2591 | /* search for the command */ |
| 2592 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); |
| 2593 | if (!smid) { |
| 2594 | scmd->result = DID_RESET << 16; |
| 2595 | r = SUCCESS; |
| 2596 | goto out; |
| 2597 | } |
| 2598 | |
| 2599 | /* for hidden raid components and volumes this is not supported */ |
| 2600 | if (sas_device_priv_data->sas_target->flags & |
| 2601 | MPT_TARGET_FLAGS_RAID_COMPONENT || |
| 2602 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 2603 | scmd->result = DID_RESET << 16; |
| 2604 | r = FAILED; |
| 2605 | goto out; |
| 2606 | } |
| 2607 | |
Kashyap, Desai | fa7f316 | 2009-09-23 17:26:58 +0530 | [diff] [blame] | 2608 | mpt2sas_halt_firmware(ioc); |
| 2609 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2610 | handle = sas_device_priv_data->sas_target->handle; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2611 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2612 | scmd->device->id, scmd->device->lun, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2613 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, |
| 2614 | scmd->serial_number, TM_MUTEX_ON); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2615 | |
| 2616 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2617 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", |
| 2618 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2619 | return r; |
| 2620 | } |
| 2621 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2622 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2623 | * _scsih_dev_reset - eh threads main device reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2624 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2625 | * |
| 2626 | * Returns SUCCESS if command aborted else FAILED |
| 2627 | */ |
| 2628 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2629 | _scsih_dev_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2630 | { |
| 2631 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2632 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2633 | struct _sas_device *sas_device; |
| 2634 | unsigned long flags; |
| 2635 | u16 handle; |
| 2636 | int r; |
| 2637 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2638 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2639 | |
Kashyap, Desai | 37aaa78 | 2010-11-13 04:41:32 +0530 | [diff] [blame] | 2640 | starget_printk(KERN_INFO, starget, "attempting device reset! " |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2641 | "scmd(%p)\n", scmd); |
| 2642 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2643 | |
| 2644 | sas_device_priv_data = scmd->device->hostdata; |
| 2645 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 37aaa78 | 2010-11-13 04:41:32 +0530 | [diff] [blame] | 2646 | starget_printk(KERN_INFO, starget, "device been deleted! " |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2647 | "scmd(%p)\n", scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2648 | scmd->result = DID_NO_CONNECT << 16; |
| 2649 | scmd->scsi_done(scmd); |
| 2650 | r = SUCCESS; |
| 2651 | goto out; |
| 2652 | } |
| 2653 | |
| 2654 | /* for hidden raid components obtain the volume_handle */ |
| 2655 | handle = 0; |
| 2656 | if (sas_device_priv_data->sas_target->flags & |
| 2657 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2658 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2659 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2660 | sas_device_priv_data->sas_target->handle); |
| 2661 | if (sas_device) |
| 2662 | handle = sas_device->volume_handle; |
| 2663 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2664 | } else |
| 2665 | handle = sas_device_priv_data->sas_target->handle; |
| 2666 | |
| 2667 | if (!handle) { |
| 2668 | scmd->result = DID_RESET << 16; |
| 2669 | r = FAILED; |
| 2670 | goto out; |
| 2671 | } |
| 2672 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2673 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2674 | scmd->device->id, scmd->device->lun, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2675 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, 0, |
| 2676 | TM_MUTEX_ON); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2677 | |
| 2678 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2679 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", |
| 2680 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2681 | return r; |
| 2682 | } |
| 2683 | |
| 2684 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2685 | * _scsih_target_reset - eh threads main target reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2686 | * @scmd: pointer to scsi command object |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2687 | * |
| 2688 | * Returns SUCCESS if command aborted else FAILED |
| 2689 | */ |
| 2690 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2691 | _scsih_target_reset(struct scsi_cmnd *scmd) |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2692 | { |
| 2693 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2694 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2695 | struct _sas_device *sas_device; |
| 2696 | unsigned long flags; |
| 2697 | u16 handle; |
| 2698 | int r; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2699 | struct scsi_target *starget = scmd->device->sdev_target; |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2700 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2701 | starget_printk(KERN_INFO, starget, "attempting target reset! " |
| 2702 | "scmd(%p)\n", scmd); |
| 2703 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2704 | |
| 2705 | sas_device_priv_data = scmd->device->hostdata; |
| 2706 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2707 | starget_printk(KERN_INFO, starget, "target been deleted! " |
| 2708 | "scmd(%p)\n", scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2709 | scmd->result = DID_NO_CONNECT << 16; |
| 2710 | scmd->scsi_done(scmd); |
| 2711 | r = SUCCESS; |
| 2712 | goto out; |
| 2713 | } |
| 2714 | |
| 2715 | /* for hidden raid components obtain the volume_handle */ |
| 2716 | handle = 0; |
| 2717 | if (sas_device_priv_data->sas_target->flags & |
| 2718 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2719 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2720 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2721 | sas_device_priv_data->sas_target->handle); |
| 2722 | if (sas_device) |
| 2723 | handle = sas_device->volume_handle; |
| 2724 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2725 | } else |
| 2726 | handle = sas_device_priv_data->sas_target->handle; |
| 2727 | |
| 2728 | if (!handle) { |
| 2729 | scmd->result = DID_RESET << 16; |
| 2730 | r = FAILED; |
| 2731 | goto out; |
| 2732 | } |
| 2733 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2734 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2735 | scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2736 | 30, 0, TM_MUTEX_ON); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2737 | |
| 2738 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2739 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", |
| 2740 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2741 | return r; |
| 2742 | } |
| 2743 | |
| 2744 | /** |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2745 | * _scsih_host_reset - eh threads main host reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2746 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2747 | * |
| 2748 | * Returns SUCCESS if command aborted else FAILED |
| 2749 | */ |
| 2750 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2751 | _scsih_host_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2752 | { |
| 2753 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2754 | int r, retval; |
| 2755 | |
| 2756 | printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n", |
| 2757 | ioc->name, scmd); |
| 2758 | scsi_print_command(scmd); |
| 2759 | |
| 2760 | retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2761 | FORCE_BIG_HAMMER); |
| 2762 | r = (retval < 0) ? FAILED : SUCCESS; |
| 2763 | printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n", |
| 2764 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 2765 | |
| 2766 | return r; |
| 2767 | } |
| 2768 | |
| 2769 | /** |
| 2770 | * _scsih_fw_event_add - insert and queue up fw_event |
| 2771 | * @ioc: per adapter object |
| 2772 | * @fw_event: object describing the event |
| 2773 | * Context: This function will acquire ioc->fw_event_lock. |
| 2774 | * |
| 2775 | * This adds the firmware event object into link list, then queues it up to |
| 2776 | * be processed from user context. |
| 2777 | * |
| 2778 | * Return nothing. |
| 2779 | */ |
| 2780 | static void |
| 2781 | _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event) |
| 2782 | { |
| 2783 | unsigned long flags; |
| 2784 | |
| 2785 | if (ioc->firmware_event_thread == NULL) |
| 2786 | return; |
| 2787 | |
| 2788 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2789 | list_add_tail(&fw_event->list, &ioc->fw_event_list); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2790 | INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work); |
| 2791 | queue_delayed_work(ioc->firmware_event_thread, |
| 2792 | &fw_event->delayed_work, 0); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2793 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2794 | } |
| 2795 | |
| 2796 | /** |
| 2797 | * _scsih_fw_event_free - delete fw_event |
| 2798 | * @ioc: per adapter object |
| 2799 | * @fw_event: object describing the event |
| 2800 | * Context: This function will acquire ioc->fw_event_lock. |
| 2801 | * |
| 2802 | * This removes firmware event object from link list, frees associated memory. |
| 2803 | * |
| 2804 | * Return nothing. |
| 2805 | */ |
| 2806 | static void |
| 2807 | _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work |
| 2808 | *fw_event) |
| 2809 | { |
| 2810 | unsigned long flags; |
| 2811 | |
| 2812 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2813 | list_del(&fw_event->list); |
| 2814 | kfree(fw_event->event_data); |
| 2815 | kfree(fw_event); |
| 2816 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2817 | } |
| 2818 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2819 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2820 | /** |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2821 | * _scsih_error_recovery_delete_devices - remove devices not responding |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2822 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2823 | * |
| 2824 | * Return nothing. |
| 2825 | */ |
| 2826 | static void |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2827 | _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2828 | { |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2829 | struct fw_event_work *fw_event; |
| 2830 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2831 | if (ioc->is_driver_loading) |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2832 | return; |
Dan Carpenter | 181a9d7 | 2011-11-04 21:25:01 +0300 | [diff] [blame] | 2833 | |
| 2834 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2835 | if (!fw_event) |
| 2836 | return; |
| 2837 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2838 | fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES; |
| 2839 | fw_event->ioc = ioc; |
| 2840 | _scsih_fw_event_add(ioc, fw_event); |
| 2841 | } |
| 2842 | |
| 2843 | /** |
| 2844 | * mpt2sas_port_enable_complete - port enable completed (fake event) |
| 2845 | * @ioc: per adapter object |
| 2846 | * |
| 2847 | * Return nothing. |
| 2848 | */ |
| 2849 | void |
| 2850 | mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc) |
| 2851 | { |
| 2852 | struct fw_event_work *fw_event; |
| 2853 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2854 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2855 | if (!fw_event) |
| 2856 | return; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2857 | fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2858 | fw_event->ioc = ioc; |
| 2859 | _scsih_fw_event_add(ioc, fw_event); |
| 2860 | } |
| 2861 | |
| 2862 | /** |
| 2863 | * _scsih_fw_event_cleanup_queue - cleanup event queue |
| 2864 | * @ioc: per adapter object |
| 2865 | * |
| 2866 | * Walk the firmware event queue, either killing timers, or waiting |
| 2867 | * for outstanding events to complete |
| 2868 | * |
| 2869 | * Return nothing. |
| 2870 | */ |
| 2871 | static void |
| 2872 | _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc) |
| 2873 | { |
| 2874 | struct fw_event_work *fw_event, *next; |
| 2875 | |
| 2876 | if (list_empty(&ioc->fw_event_list) || |
| 2877 | !ioc->firmware_event_thread || in_interrupt()) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2878 | return; |
| 2879 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2880 | list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) { |
| 2881 | if (cancel_delayed_work(&fw_event->delayed_work)) { |
| 2882 | _scsih_fw_event_free(ioc, fw_event); |
| 2883 | continue; |
| 2884 | } |
| 2885 | fw_event->cancel_pending_work = 1; |
| 2886 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2887 | } |
| 2888 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2889 | /** |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2890 | * _scsih_ublock_io_all_device - unblock every device |
| 2891 | * @ioc: per adapter object |
| 2892 | * |
| 2893 | * change the device state from block to running |
| 2894 | */ |
| 2895 | static void |
| 2896 | _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc) |
| 2897 | { |
| 2898 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2899 | struct scsi_device *sdev; |
| 2900 | |
| 2901 | shost_for_each_device(sdev, ioc->shost) { |
| 2902 | sas_device_priv_data = sdev->hostdata; |
| 2903 | if (!sas_device_priv_data) |
| 2904 | continue; |
| 2905 | if (!sas_device_priv_data->block) |
| 2906 | continue; |
| 2907 | sas_device_priv_data->block = 0; |
| 2908 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, " |
| 2909 | "handle(0x%04x)\n", |
| 2910 | sas_device_priv_data->sas_target->handle)); |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 2911 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2912 | } |
| 2913 | } |
| 2914 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2915 | * _scsih_ublock_io_device - set the device state to SDEV_RUNNING |
| 2916 | * @ioc: per adapter object |
| 2917 | * @handle: device handle |
| 2918 | * |
| 2919 | * During device pull we need to appropiately set the sdev state. |
| 2920 | */ |
| 2921 | static void |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2922 | _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2923 | { |
| 2924 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2925 | struct scsi_device *sdev; |
| 2926 | |
| 2927 | shost_for_each_device(sdev, ioc->shost) { |
| 2928 | sas_device_priv_data = sdev->hostdata; |
| 2929 | if (!sas_device_priv_data) |
| 2930 | continue; |
| 2931 | if (!sas_device_priv_data->block) |
| 2932 | continue; |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2933 | if (sas_device_priv_data->sas_target->sas_address == |
| 2934 | sas_address) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2935 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2936 | MPT2SAS_INFO_FMT "SDEV_RUNNING: " |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 2937 | "sas address(0x%016llx)\n", ioc->name, |
| 2938 | (unsigned long long)sas_address)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2939 | sas_device_priv_data->block = 0; |
Mike Christie | 5d9fb5c | 2012-05-17 23:56:57 -0500 | [diff] [blame] | 2940 | scsi_internal_device_unblock(sdev, SDEV_RUNNING); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2941 | } |
| 2942 | } |
| 2943 | } |
| 2944 | |
| 2945 | /** |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2946 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK |
| 2947 | * @ioc: per adapter object |
| 2948 | * @handle: device handle |
| 2949 | * |
| 2950 | * During device pull we need to appropiately set the sdev state. |
| 2951 | */ |
| 2952 | static void |
| 2953 | _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc) |
| 2954 | { |
| 2955 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2956 | struct scsi_device *sdev; |
| 2957 | |
| 2958 | shost_for_each_device(sdev, ioc->shost) { |
| 2959 | sas_device_priv_data = sdev->hostdata; |
| 2960 | if (!sas_device_priv_data) |
| 2961 | continue; |
| 2962 | if (sas_device_priv_data->block) |
| 2963 | continue; |
| 2964 | sas_device_priv_data->block = 1; |
| 2965 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, " |
| 2966 | "handle(0x%04x)\n", |
| 2967 | sas_device_priv_data->sas_target->handle)); |
| 2968 | scsi_internal_device_block(sdev); |
| 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | |
| 2973 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2974 | * _scsih_block_io_device - set the device state to SDEV_BLOCK |
| 2975 | * @ioc: per adapter object |
| 2976 | * @handle: device handle |
| 2977 | * |
| 2978 | * During device pull we need to appropiately set the sdev state. |
| 2979 | */ |
| 2980 | static void |
| 2981 | _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2982 | { |
| 2983 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2984 | struct scsi_device *sdev; |
| 2985 | |
| 2986 | shost_for_each_device(sdev, ioc->shost) { |
| 2987 | sas_device_priv_data = sdev->hostdata; |
| 2988 | if (!sas_device_priv_data) |
| 2989 | continue; |
| 2990 | if (sas_device_priv_data->block) |
| 2991 | continue; |
| 2992 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2993 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2994 | MPT2SAS_INFO_FMT "SDEV_BLOCK: " |
| 2995 | "handle(0x%04x)\n", ioc->name, handle)); |
| 2996 | sas_device_priv_data->block = 1; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 2997 | scsi_internal_device_block(sdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2998 | } |
| 2999 | } |
| 3000 | } |
| 3001 | |
| 3002 | /** |
| 3003 | * _scsih_block_io_to_children_attached_to_ex |
| 3004 | * @ioc: per adapter object |
| 3005 | * @sas_expander: the sas_device object |
| 3006 | * |
| 3007 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 3008 | * attached to this expander. This function called when expander is |
| 3009 | * pulled. |
| 3010 | */ |
| 3011 | static void |
| 3012 | _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc, |
| 3013 | struct _sas_node *sas_expander) |
| 3014 | { |
| 3015 | struct _sas_port *mpt2sas_port; |
| 3016 | struct _sas_device *sas_device; |
| 3017 | struct _sas_node *expander_sibling; |
| 3018 | unsigned long flags; |
| 3019 | |
| 3020 | if (!sas_expander) |
| 3021 | return; |
| 3022 | |
| 3023 | list_for_each_entry(mpt2sas_port, |
| 3024 | &sas_expander->sas_port_list, port_list) { |
| 3025 | if (mpt2sas_port->remote_identify.device_type == |
| 3026 | SAS_END_DEVICE) { |
| 3027 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3028 | sas_device = |
| 3029 | mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 3030 | mpt2sas_port->remote_identify.sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 3031 | if (sas_device) |
| 3032 | set_bit(sas_device->handle, |
| 3033 | ioc->blocking_handles); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3034 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | list_for_each_entry(mpt2sas_port, |
| 3039 | &sas_expander->sas_port_list, port_list) { |
| 3040 | |
| 3041 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 3042 | SAS_EDGE_EXPANDER_DEVICE || |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3043 | mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 3044 | SAS_FANOUT_EXPANDER_DEVICE) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3045 | expander_sibling = |
| 3046 | mpt2sas_scsih_expander_find_by_sas_address( |
| 3047 | ioc, mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3048 | _scsih_block_io_to_children_attached_to_ex(ioc, |
| 3049 | expander_sibling); |
| 3050 | } |
| 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | /** |
| 3055 | * _scsih_block_io_to_children_attached_directly |
| 3056 | * @ioc: per adapter object |
| 3057 | * @event_data: topology change event data |
| 3058 | * |
| 3059 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 3060 | * direct attached during device pull. |
| 3061 | */ |
| 3062 | static void |
| 3063 | _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc, |
| 3064 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3065 | { |
| 3066 | int i; |
| 3067 | u16 handle; |
| 3068 | u16 reason_code; |
| 3069 | u8 phy_number; |
| 3070 | |
| 3071 | for (i = 0; i < event_data->NumEntries; i++) { |
| 3072 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3073 | if (!handle) |
| 3074 | continue; |
| 3075 | phy_number = event_data->StartPhyNum + i; |
| 3076 | reason_code = event_data->PHY[i].PhyStatus & |
| 3077 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3078 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) |
| 3079 | _scsih_block_io_device(ioc, handle); |
| 3080 | } |
| 3081 | } |
| 3082 | |
| 3083 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3084 | * _scsih_tm_tr_send - send task management request |
| 3085 | * @ioc: per adapter object |
| 3086 | * @handle: device handle |
| 3087 | * Context: interrupt time. |
| 3088 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3089 | * This code is to initiate the device removal handshake protocol |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3090 | * with controller firmware. This function will issue target reset |
| 3091 | * using high priority request queue. It will send a sas iounit |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3092 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3093 | * |
| 3094 | * This is designed to send muliple task management request at the same |
| 3095 | * time to the fifo. If the fifo is full, we will append the request, |
| 3096 | * and process it in a future completion. |
| 3097 | */ |
| 3098 | static void |
| 3099 | _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3100 | { |
| 3101 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3102 | u16 smid; |
| 3103 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3104 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; |
| 3105 | u64 sas_address = 0; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3106 | unsigned long flags; |
| 3107 | struct _tr_list *delayed_tr; |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3108 | u32 ioc_state; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3109 | |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3110 | if (ioc->remove_host) { |
| 3111 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been " |
| 3112 | "removed: handle(0x%04x)\n", __func__, ioc->name, handle)); |
| 3113 | return; |
| 3114 | } else if (ioc->pci_error_recovery) { |
| 3115 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci " |
| 3116 | "error recovery: handle(0x%04x)\n", __func__, ioc->name, |
| 3117 | handle)); |
| 3118 | return; |
| 3119 | } |
| 3120 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 3121 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 3122 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not " |
| 3123 | "operational: handle(0x%04x)\n", __func__, ioc->name, |
| 3124 | handle)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3125 | return; |
| 3126 | } |
| 3127 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3128 | /* if PD, then return */ |
| 3129 | if (test_bit(handle, ioc->pd_handles)) |
| 3130 | return; |
| 3131 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3132 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3133 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3134 | if (sas_device && sas_device->starget && |
| 3135 | sas_device->starget->hostdata) { |
| 3136 | sas_target_priv_data = sas_device->starget->hostdata; |
| 3137 | sas_target_priv_data->deleted = 1; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3138 | sas_address = sas_device->sas_address; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3139 | } |
| 3140 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3141 | |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3142 | if (sas_target_priv_data) { |
| 3143 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: " |
| 3144 | "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle, |
| 3145 | (unsigned long long)sas_address)); |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 3146 | _scsih_ublock_io_device(ioc, sas_address); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 3147 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3148 | } |
| 3149 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3150 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); |
| 3151 | if (!smid) { |
| 3152 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3153 | if (!delayed_tr) |
| 3154 | return; |
| 3155 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3156 | delayed_tr->handle = handle; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3157 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 3158 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3159 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 3160 | ioc->name, handle)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3161 | return; |
| 3162 | } |
| 3163 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3164 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " |
| 3165 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, |
| 3166 | ioc->tm_tr_cb_idx)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3167 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3168 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 3169 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3170 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3171 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3172 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
| 3173 | } |
| 3174 | |
| 3175 | |
| 3176 | |
| 3177 | /** |
| 3178 | * _scsih_sas_control_complete - completion routine |
| 3179 | * @ioc: per adapter object |
| 3180 | * @smid: system request message index |
| 3181 | * @msix_index: MSIX table index supplied by the OS |
| 3182 | * @reply: reply message frame(lower 32bit addr) |
| 3183 | * Context: interrupt time. |
| 3184 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3185 | * This is the sas iounit control completion routine. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3186 | * 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] | 3187 | * handshake protocol with controller firmware. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3188 | * |
| 3189 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3190 | * 0 means the mf is freed from this function. |
| 3191 | */ |
| 3192 | static u8 |
| 3193 | _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 3194 | u8 msix_index, u32 reply) |
| 3195 | { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3196 | Mpi2SasIoUnitControlReply_t *mpi_reply = |
| 3197 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3198 | if (likely(mpi_reply)) { |
| 3199 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3200 | "sc_complete:handle(0x%04x), (open) " |
| 3201 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 3202 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, |
| 3203 | le16_to_cpu(mpi_reply->IOCStatus), |
| 3204 | le32_to_cpu(mpi_reply->IOCLogInfo))); |
| 3205 | } else { |
| 3206 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3207 | ioc->name, __FILE__, __LINE__, __func__); |
| 3208 | } |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3209 | return 1; |
| 3210 | } |
| 3211 | |
| 3212 | /** |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3213 | * _scsih_tm_tr_volume_send - send target reset request for volumes |
| 3214 | * @ioc: per adapter object |
| 3215 | * @handle: device handle |
| 3216 | * Context: interrupt time. |
| 3217 | * |
| 3218 | * This is designed to send muliple task management request at the same |
| 3219 | * time to the fifo. If the fifo is full, we will append the request, |
| 3220 | * and process it in a future completion. |
| 3221 | */ |
| 3222 | static void |
| 3223 | _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3224 | { |
| 3225 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 3226 | u16 smid; |
| 3227 | struct _tr_list *delayed_tr; |
| 3228 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3229 | if (ioc->shost_recovery || ioc->remove_host || |
| 3230 | ioc->pci_error_recovery) { |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3231 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3232 | "progress!\n", __func__, ioc->name)); |
| 3233 | return; |
| 3234 | } |
| 3235 | |
| 3236 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); |
| 3237 | if (!smid) { |
| 3238 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3239 | if (!delayed_tr) |
| 3240 | return; |
| 3241 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3242 | delayed_tr->handle = handle; |
| 3243 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); |
| 3244 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3245 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 3246 | ioc->name, handle)); |
| 3247 | return; |
| 3248 | } |
| 3249 | |
| 3250 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " |
| 3251 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, |
| 3252 | ioc->tm_tr_volume_cb_idx)); |
| 3253 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3254 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 3255 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3256 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3257 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
| 3258 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
| 3259 | } |
| 3260 | |
| 3261 | /** |
| 3262 | * _scsih_tm_volume_tr_complete - target reset completion |
| 3263 | * @ioc: per adapter object |
| 3264 | * @smid: system request message index |
| 3265 | * @msix_index: MSIX table index supplied by the OS |
| 3266 | * @reply: reply message frame(lower 32bit addr) |
| 3267 | * Context: interrupt time. |
| 3268 | * |
| 3269 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3270 | * 0 means the mf is freed from this function. |
| 3271 | */ |
| 3272 | static u8 |
| 3273 | _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 3274 | u8 msix_index, u32 reply) |
| 3275 | { |
| 3276 | u16 handle; |
| 3277 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
| 3278 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3279 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 3280 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3281 | if (ioc->shost_recovery || ioc->remove_host || |
| 3282 | ioc->pci_error_recovery) { |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3283 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3284 | "progress!\n", __func__, ioc->name)); |
| 3285 | return 1; |
| 3286 | } |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3287 | if (unlikely(!mpi_reply)) { |
| 3288 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3289 | ioc->name, __FILE__, __LINE__, __func__); |
| 3290 | return 1; |
| 3291 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3292 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3293 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3294 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3295 | dewtprintk(ioc, printk("spurious interrupt: " |
| 3296 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle, |
| 3297 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3298 | return 0; |
| 3299 | } |
| 3300 | |
| 3301 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3302 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3303 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3304 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3305 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3306 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3307 | |
| 3308 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3309 | } |
| 3310 | |
| 3311 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3312 | * _scsih_tm_tr_complete - |
| 3313 | * @ioc: per adapter object |
| 3314 | * @smid: system request message index |
| 3315 | * @msix_index: MSIX table index supplied by the OS |
| 3316 | * @reply: reply message frame(lower 32bit addr) |
| 3317 | * Context: interrupt time. |
| 3318 | * |
| 3319 | * This is the target reset completion routine. |
| 3320 | * 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] | 3321 | * handshake protocol with controller firmware. |
| 3322 | * 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] | 3323 | * |
| 3324 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3325 | * 0 means the mf is freed from this function. |
| 3326 | */ |
| 3327 | static u8 |
| 3328 | _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 3329 | u32 reply) |
| 3330 | { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3331 | u16 handle; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3332 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3333 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3334 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 3335 | Mpi2SasIoUnitControlRequest_t *mpi_request; |
| 3336 | u16 smid_sas_ctrl; |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3337 | u32 ioc_state; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3338 | |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3339 | if (ioc->remove_host) { |
| 3340 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been " |
| 3341 | "removed\n", __func__, ioc->name)); |
| 3342 | return 1; |
| 3343 | } else if (ioc->pci_error_recovery) { |
| 3344 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci " |
| 3345 | "error recovery\n", __func__, ioc->name)); |
| 3346 | return 1; |
| 3347 | } |
| 3348 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 3349 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 3350 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not " |
| 3351 | "operational\n", __func__, ioc->name)); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3352 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3353 | } |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 3354 | if (unlikely(!mpi_reply)) { |
| 3355 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 3356 | ioc->name, __FILE__, __LINE__, __func__); |
| 3357 | return 1; |
| 3358 | } |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3359 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3360 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3361 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3362 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: " |
| 3363 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle, |
| 3364 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3365 | return 0; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3366 | } |
| 3367 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3368 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3369 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3370 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3371 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3372 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3373 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3374 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3375 | smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); |
| 3376 | if (!smid_sas_ctrl) { |
| 3377 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 3378 | ioc->name, __func__); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3379 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3380 | } |
| 3381 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3382 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), " |
| 3383 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl, |
| 3384 | ioc->tm_sas_control_cb_idx)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3385 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl); |
| 3386 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); |
| 3387 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; |
| 3388 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3389 | mpi_request->DevHandle = mpi_request_tm->DevHandle; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3390 | mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3391 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3392 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3393 | } |
| 3394 | |
| 3395 | /** |
| 3396 | * _scsih_check_for_pending_tm - check for pending task management |
| 3397 | * @ioc: per adapter object |
| 3398 | * @smid: system request message index |
| 3399 | * |
| 3400 | * This will check delayed target reset list, and feed the |
| 3401 | * next reqeust. |
| 3402 | * |
| 3403 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3404 | * 0 means the mf is freed from this function. |
| 3405 | */ |
| 3406 | static u8 |
| 3407 | _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 3408 | { |
| 3409 | struct _tr_list *delayed_tr; |
| 3410 | |
| 3411 | if (!list_empty(&ioc->delayed_tr_volume_list)) { |
| 3412 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, |
| 3413 | struct _tr_list, list); |
| 3414 | mpt2sas_base_free_smid(ioc, smid); |
| 3415 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); |
| 3416 | list_del(&delayed_tr->list); |
| 3417 | kfree(delayed_tr); |
| 3418 | return 0; |
| 3419 | } |
| 3420 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3421 | if (!list_empty(&ioc->delayed_tr_list)) { |
| 3422 | delayed_tr = list_entry(ioc->delayed_tr_list.next, |
| 3423 | struct _tr_list, list); |
| 3424 | mpt2sas_base_free_smid(ioc, smid); |
| 3425 | _scsih_tm_tr_send(ioc, delayed_tr->handle); |
| 3426 | list_del(&delayed_tr->list); |
| 3427 | kfree(delayed_tr); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3428 | return 0; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3429 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3430 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3431 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3432 | } |
| 3433 | |
| 3434 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3435 | * _scsih_check_topo_delete_events - sanity check on topo events |
| 3436 | * @ioc: per adapter object |
| 3437 | * @event_data: the event data payload |
| 3438 | * |
| 3439 | * This routine added to better handle cable breaker. |
| 3440 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3441 | * This handles the case where driver receives multiple expander |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3442 | * add and delete events in a single shot. When there is a delete event |
| 3443 | * the routine will void any pending add events waiting in the event queue. |
| 3444 | * |
| 3445 | * Return nothing. |
| 3446 | */ |
| 3447 | static void |
| 3448 | _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 3449 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3450 | { |
| 3451 | struct fw_event_work *fw_event; |
| 3452 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; |
| 3453 | u16 expander_handle; |
| 3454 | struct _sas_node *sas_expander; |
| 3455 | unsigned long flags; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3456 | int i, reason_code; |
| 3457 | u16 handle; |
| 3458 | |
| 3459 | for (i = 0 ; i < event_data->NumEntries; i++) { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3460 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3461 | if (!handle) |
| 3462 | continue; |
| 3463 | reason_code = event_data->PHY[i].PhyStatus & |
| 3464 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3465 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) |
| 3466 | _scsih_tm_tr_send(ioc, handle); |
| 3467 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3468 | |
| 3469 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 3470 | if (expander_handle < ioc->sas_hba.num_phys) { |
| 3471 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3472 | return; |
| 3473 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 3474 | if (event_data->ExpStatus == |
| 3475 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { |
| 3476 | /* put expander attached devices into blocking state */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3477 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 3478 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 3479 | expander_handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3480 | _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] | 3481 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 3482 | do { |
| 3483 | handle = find_first_bit(ioc->blocking_handles, |
| 3484 | ioc->facts.MaxDevHandle); |
| 3485 | if (handle < ioc->facts.MaxDevHandle) |
| 3486 | _scsih_block_io_device(ioc, handle); |
| 3487 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3488 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) |
| 3489 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3490 | |
| 3491 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) |
| 3492 | return; |
| 3493 | |
| 3494 | /* mark ignore flag for pending events */ |
| 3495 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 3496 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { |
| 3497 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || |
| 3498 | fw_event->ignore) |
| 3499 | continue; |
| 3500 | local_event_data = fw_event->event_data; |
| 3501 | if (local_event_data->ExpStatus == |
| 3502 | MPI2_EVENT_SAS_TOPO_ES_ADDED || |
| 3503 | local_event_data->ExpStatus == |
| 3504 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { |
| 3505 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == |
| 3506 | expander_handle) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 3507 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3508 | "setting ignoring flag\n", ioc->name)); |
| 3509 | fw_event->ignore = 1; |
| 3510 | } |
| 3511 | } |
| 3512 | } |
| 3513 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 3514 | } |
| 3515 | |
| 3516 | /** |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3517 | * _scsih_set_volume_delete_flag - setting volume delete flag |
| 3518 | * @ioc: per adapter object |
| 3519 | * @handle: device handle |
| 3520 | * |
| 3521 | * This |
| 3522 | * Return nothing. |
| 3523 | */ |
| 3524 | static void |
| 3525 | _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3526 | { |
| 3527 | struct _raid_device *raid_device; |
| 3528 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 3529 | unsigned long flags; |
| 3530 | |
| 3531 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 3532 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 3533 | if (raid_device && raid_device->starget && |
| 3534 | raid_device->starget->hostdata) { |
| 3535 | sas_target_priv_data = |
| 3536 | raid_device->starget->hostdata; |
| 3537 | sas_target_priv_data->deleted = 1; |
| 3538 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3539 | "setting delete flag: handle(0x%04x), " |
| 3540 | "wwid(0x%016llx)\n", ioc->name, handle, |
| 3541 | (unsigned long long) raid_device->wwid)); |
| 3542 | } |
| 3543 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 3544 | } |
| 3545 | |
| 3546 | /** |
| 3547 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume |
| 3548 | * @handle: input handle |
| 3549 | * @a: handle for volume a |
| 3550 | * @b: handle for volume b |
| 3551 | * |
| 3552 | * IR firmware only supports two raid volumes. The purpose of this |
| 3553 | * routine is to set the volume handle in either a or b. When the given |
| 3554 | * input handle is non-zero, or when a and b have not been set before. |
| 3555 | */ |
| 3556 | static void |
| 3557 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) |
| 3558 | { |
| 3559 | if (!handle || handle == *a || handle == *b) |
| 3560 | return; |
| 3561 | if (!*a) |
| 3562 | *a = handle; |
| 3563 | else if (!*b) |
| 3564 | *b = handle; |
| 3565 | } |
| 3566 | |
| 3567 | /** |
| 3568 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events |
| 3569 | * @ioc: per adapter object |
| 3570 | * @event_data: the event data payload |
| 3571 | * Context: interrupt time. |
| 3572 | * |
| 3573 | * This routine will send target reset to volume, followed by target |
| 3574 | * resets to the PDs. This is called when a PD has been removed, or |
| 3575 | * volume has been deleted or removed. When the target reset is sent |
| 3576 | * to volume, the PD target resets need to be queued to start upon |
| 3577 | * completion of the volume target reset. |
| 3578 | * |
| 3579 | * Return nothing. |
| 3580 | */ |
| 3581 | static void |
| 3582 | _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc, |
| 3583 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 3584 | { |
| 3585 | Mpi2EventIrConfigElement_t *element; |
| 3586 | int i; |
| 3587 | u16 handle, volume_handle, a, b; |
| 3588 | struct _tr_list *delayed_tr; |
| 3589 | |
| 3590 | a = 0; |
| 3591 | b = 0; |
| 3592 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3593 | if (ioc->is_warpdrive) |
| 3594 | return; |
| 3595 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3596 | /* Volume Resets for Deleted or Removed */ |
| 3597 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3598 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3599 | if (element->ReasonCode == |
| 3600 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || |
| 3601 | element->ReasonCode == |
| 3602 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { |
| 3603 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3604 | _scsih_set_volume_delete_flag(ioc, volume_handle); |
| 3605 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3606 | } |
| 3607 | } |
| 3608 | |
| 3609 | /* Volume Resets for UNHIDE events */ |
| 3610 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3611 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3612 | if (le32_to_cpu(event_data->Flags) & |
| 3613 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) |
| 3614 | continue; |
| 3615 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { |
| 3616 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3617 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3618 | } |
| 3619 | } |
| 3620 | |
| 3621 | if (a) |
| 3622 | _scsih_tm_tr_volume_send(ioc, a); |
| 3623 | if (b) |
| 3624 | _scsih_tm_tr_volume_send(ioc, b); |
| 3625 | |
| 3626 | /* PD target resets */ |
| 3627 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3628 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3629 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) |
| 3630 | continue; |
| 3631 | handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 3632 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3633 | clear_bit(handle, ioc->pd_handles); |
| 3634 | if (!volume_handle) |
| 3635 | _scsih_tm_tr_send(ioc, handle); |
| 3636 | else if (volume_handle == a || volume_handle == b) { |
| 3637 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3638 | BUG_ON(!delayed_tr); |
| 3639 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3640 | delayed_tr->handle = handle; |
| 3641 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 3642 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3643 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, |
| 3644 | handle)); |
| 3645 | } else |
| 3646 | _scsih_tm_tr_send(ioc, handle); |
| 3647 | } |
| 3648 | } |
| 3649 | |
| 3650 | |
| 3651 | /** |
| 3652 | * _scsih_check_volume_delete_events - set delete flag for volumes |
| 3653 | * @ioc: per adapter object |
| 3654 | * @event_data: the event data payload |
| 3655 | * Context: interrupt time. |
| 3656 | * |
| 3657 | * This will handle the case when the cable connected to entire volume is |
| 3658 | * pulled. We will take care of setting the deleted flag so normal IO will |
| 3659 | * not be sent. |
| 3660 | * |
| 3661 | * Return nothing. |
| 3662 | */ |
| 3663 | static void |
| 3664 | _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 3665 | Mpi2EventDataIrVolume_t *event_data) |
| 3666 | { |
| 3667 | u32 state; |
| 3668 | |
| 3669 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 3670 | return; |
| 3671 | state = le32_to_cpu(event_data->NewValue); |
| 3672 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == |
| 3673 | MPI2_RAID_VOL_STATE_FAILED) |
| 3674 | _scsih_set_volume_delete_flag(ioc, |
| 3675 | le16_to_cpu(event_data->VolDevHandle)); |
| 3676 | } |
| 3677 | |
| 3678 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3679 | * _scsih_flush_running_cmds - completing outstanding commands. |
| 3680 | * @ioc: per adapter object |
| 3681 | * |
| 3682 | * The flushing out of all pending scmd commands following host reset, |
| 3683 | * where all IO is dropped to the floor. |
| 3684 | * |
| 3685 | * Return nothing. |
| 3686 | */ |
| 3687 | static void |
| 3688 | _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc) |
| 3689 | { |
| 3690 | struct scsi_cmnd *scmd; |
| 3691 | u16 smid; |
| 3692 | u16 count = 0; |
| 3693 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3694 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 3695 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3696 | if (!scmd) |
| 3697 | continue; |
| 3698 | count++; |
| 3699 | mpt2sas_base_free_smid(ioc, smid); |
| 3700 | scsi_dma_unmap(scmd); |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3701 | if (ioc->pci_error_recovery) |
| 3702 | scmd->result = DID_NO_CONNECT << 16; |
| 3703 | else |
| 3704 | scmd->result = DID_RESET << 16; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3705 | scmd->scsi_done(scmd); |
| 3706 | } |
| 3707 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n", |
| 3708 | ioc->name, count)); |
| 3709 | } |
| 3710 | |
| 3711 | /** |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3712 | * _scsih_setup_eedp - setup MPI request for EEDP transfer |
| 3713 | * @scmd: pointer to scsi command object |
| 3714 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3715 | * |
| 3716 | * Supporting protection 1 and 3. |
| 3717 | * |
| 3718 | * Returns nothing |
| 3719 | */ |
| 3720 | static void |
| 3721 | _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request) |
| 3722 | { |
| 3723 | u16 eedp_flags; |
| 3724 | unsigned char prot_op = scsi_get_prot_op(scmd); |
| 3725 | unsigned char prot_type = scsi_get_prot_type(scmd); |
| 3726 | |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3727 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3728 | return; |
| 3729 | |
| 3730 | if (prot_op == SCSI_PROT_READ_STRIP) |
| 3731 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; |
| 3732 | else if (prot_op == SCSI_PROT_WRITE_INSERT) |
| 3733 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; |
| 3734 | else |
| 3735 | return; |
| 3736 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3737 | switch (prot_type) { |
| 3738 | case SCSI_PROT_DIF_TYPE1: |
Martin K. Petersen | 756aca7 | 2011-05-18 00:45:22 -0400 | [diff] [blame] | 3739 | case SCSI_PROT_DIF_TYPE2: |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3740 | |
| 3741 | /* |
| 3742 | * enable ref/guard checking |
| 3743 | * auto increment ref tag |
| 3744 | */ |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3745 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3746 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | |
| 3747 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
| 3748 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = |
| 3749 | cpu_to_be32(scsi_get_lba(scmd)); |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3750 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3751 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3752 | case SCSI_PROT_DIF_TYPE3: |
| 3753 | |
| 3754 | /* |
| 3755 | * enable guard checking |
| 3756 | */ |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3757 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3758 | break; |
| 3759 | } |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3760 | mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size); |
| 3761 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3762 | } |
| 3763 | |
| 3764 | /** |
| 3765 | * _scsih_eedp_error_handling - return sense code for EEDP errors |
| 3766 | * @scmd: pointer to scsi command object |
| 3767 | * @ioc_status: ioc status |
| 3768 | * |
| 3769 | * Returns nothing |
| 3770 | */ |
| 3771 | static void |
| 3772 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) |
| 3773 | { |
| 3774 | u8 ascq; |
| 3775 | u8 sk; |
| 3776 | u8 host_byte; |
| 3777 | |
| 3778 | switch (ioc_status) { |
| 3779 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 3780 | ascq = 0x01; |
| 3781 | break; |
| 3782 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 3783 | ascq = 0x02; |
| 3784 | break; |
| 3785 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 3786 | ascq = 0x03; |
| 3787 | break; |
| 3788 | default: |
| 3789 | ascq = 0x00; |
| 3790 | break; |
| 3791 | } |
| 3792 | |
| 3793 | if (scmd->sc_data_direction == DMA_TO_DEVICE) { |
| 3794 | sk = ILLEGAL_REQUEST; |
| 3795 | host_byte = DID_ABORT; |
| 3796 | } else { |
| 3797 | sk = ABORTED_COMMAND; |
| 3798 | host_byte = DID_OK; |
| 3799 | } |
| 3800 | |
| 3801 | scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq); |
| 3802 | scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) | |
| 3803 | SAM_STAT_CHECK_CONDITION; |
| 3804 | } |
| 3805 | |
| 3806 | /** |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3807 | * _scsih_scsi_direct_io_get - returns direct io flag |
| 3808 | * @ioc: per adapter object |
| 3809 | * @smid: system request message index |
| 3810 | * |
| 3811 | * Returns the smid stored scmd pointer. |
| 3812 | */ |
| 3813 | static inline u8 |
| 3814 | _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 3815 | { |
| 3816 | return ioc->scsi_lookup[smid - 1].direct_io; |
| 3817 | } |
| 3818 | |
| 3819 | /** |
| 3820 | * _scsih_scsi_direct_io_set - sets direct io flag |
| 3821 | * @ioc: per adapter object |
| 3822 | * @smid: system request message index |
| 3823 | * @direct_io: Zero or non-zero value to set in the direct_io flag |
| 3824 | * |
| 3825 | * Returns Nothing. |
| 3826 | */ |
| 3827 | static inline void |
| 3828 | _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io) |
| 3829 | { |
| 3830 | ioc->scsi_lookup[smid - 1].direct_io = direct_io; |
| 3831 | } |
| 3832 | |
| 3833 | |
| 3834 | /** |
| 3835 | * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O |
| 3836 | * @ioc: per adapter object |
| 3837 | * @scmd: pointer to scsi command object |
| 3838 | * @raid_device: pointer to raid device data structure |
| 3839 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3840 | * @smid: system request message index |
| 3841 | * |
| 3842 | * Returns nothing |
| 3843 | */ |
| 3844 | static void |
| 3845 | _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 3846 | struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request, |
| 3847 | u16 smid) |
| 3848 | { |
| 3849 | u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size; |
| 3850 | u32 stripe_sz, stripe_exp; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3851 | u8 num_pds, *cdb_ptr, i; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3852 | u8 cdb0 = scmd->cmnd[0]; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3853 | u64 v_llba; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3854 | |
| 3855 | /* |
| 3856 | * Try Direct I/O to RAID memeber disks |
| 3857 | */ |
| 3858 | if (cdb0 == READ_16 || cdb0 == READ_10 || |
| 3859 | cdb0 == WRITE_16 || cdb0 == WRITE_10) { |
| 3860 | cdb_ptr = mpi_request->CDB.CDB32; |
| 3861 | |
| 3862 | if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4] |
| 3863 | | cdb_ptr[5])) { |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3864 | io_size = scsi_bufflen(scmd) >> |
| 3865 | raid_device->block_exponent; |
| 3866 | i = (cdb0 < READ_16) ? 2 : 6; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3867 | /* get virtual lba */ |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3868 | v_lba = be32_to_cpu(*(__be32 *)(&cdb_ptr[i])); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3869 | |
| 3870 | if (((u64)v_lba + (u64)io_size - 1) <= |
| 3871 | (u32)raid_device->max_lba) { |
| 3872 | stripe_sz = raid_device->stripe_sz; |
| 3873 | stripe_exp = raid_device->stripe_exponent; |
| 3874 | stripe_off = v_lba & (stripe_sz - 1); |
| 3875 | |
| 3876 | /* Check whether IO falls within a stripe */ |
| 3877 | if ((stripe_off + io_size) <= stripe_sz) { |
| 3878 | num_pds = raid_device->num_pds; |
| 3879 | p_lba = v_lba >> stripe_exp; |
| 3880 | stripe_unit = p_lba / num_pds; |
| 3881 | column = p_lba % num_pds; |
| 3882 | p_lba = (stripe_unit << stripe_exp) + |
| 3883 | stripe_off; |
| 3884 | mpi_request->DevHandle = |
| 3885 | cpu_to_le16(raid_device-> |
| 3886 | pd_handle[column]); |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3887 | (*(__be32 *)(&cdb_ptr[i])) = |
| 3888 | cpu_to_be32(p_lba); |
| 3889 | /* |
| 3890 | * WD: To indicate this I/O is directI/O |
| 3891 | */ |
| 3892 | _scsih_scsi_direct_io_set(ioc, smid, 1); |
| 3893 | } |
| 3894 | } |
| 3895 | } else { |
| 3896 | io_size = scsi_bufflen(scmd) >> |
| 3897 | raid_device->block_exponent; |
| 3898 | /* get virtual lba */ |
| 3899 | v_llba = be64_to_cpu(*(__be64 *)(&cdb_ptr[2])); |
| 3900 | |
| 3901 | if ((v_llba + (u64)io_size - 1) <= |
| 3902 | raid_device->max_lba) { |
| 3903 | stripe_sz = raid_device->stripe_sz; |
| 3904 | stripe_exp = raid_device->stripe_exponent; |
| 3905 | stripe_off = (u32) (v_llba & (stripe_sz - 1)); |
| 3906 | |
| 3907 | /* Check whether IO falls within a stripe */ |
| 3908 | if ((stripe_off + io_size) <= stripe_sz) { |
| 3909 | num_pds = raid_device->num_pds; |
| 3910 | p_lba = (u32)(v_llba >> stripe_exp); |
| 3911 | stripe_unit = p_lba / num_pds; |
| 3912 | column = p_lba % num_pds; |
| 3913 | p_lba = (stripe_unit << stripe_exp) + |
| 3914 | stripe_off; |
| 3915 | mpi_request->DevHandle = |
| 3916 | cpu_to_le16(raid_device-> |
| 3917 | pd_handle[column]); |
| 3918 | (*(__be64 *)(&cdb_ptr[2])) = |
| 3919 | cpu_to_be64((u64)p_lba); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3920 | /* |
| 3921 | * WD: To indicate this I/O is directI/O |
| 3922 | */ |
| 3923 | _scsih_scsi_direct_io_set(ioc, smid, 1); |
| 3924 | } |
| 3925 | } |
| 3926 | } |
| 3927 | } |
| 3928 | } |
| 3929 | |
| 3930 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 3931 | * _scsih_qcmd - main scsi request entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3932 | * @scmd: pointer to scsi command object |
| 3933 | * @done: function pointer to be invoked on completion |
| 3934 | * |
| 3935 | * The callback index is set inside `ioc->scsi_io_cb_idx`. |
| 3936 | * |
| 3937 | * Returns 0 on success. If there's a failure, return either: |
| 3938 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or |
| 3939 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full |
| 3940 | */ |
| 3941 | static int |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 3942 | _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3943 | { |
| 3944 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 3945 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 3946 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3947 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3948 | Mpi2SCSIIORequest_t *mpi_request; |
| 3949 | u32 mpi_control; |
| 3950 | u16 smid; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3951 | |
| 3952 | scmd->scsi_done = done; |
| 3953 | sas_device_priv_data = scmd->device->hostdata; |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3954 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3955 | scmd->result = DID_NO_CONNECT << 16; |
| 3956 | scmd->scsi_done(scmd); |
| 3957 | return 0; |
| 3958 | } |
| 3959 | |
Kashyap, Desai | 7821578 | 2011-06-14 10:57:08 +0530 | [diff] [blame] | 3960 | if (ioc->pci_error_recovery || ioc->remove_host) { |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3961 | scmd->result = DID_NO_CONNECT << 16; |
| 3962 | scmd->scsi_done(scmd); |
| 3963 | return 0; |
| 3964 | } |
| 3965 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3966 | sas_target_priv_data = sas_device_priv_data->sas_target; |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3967 | /* invalid device handle */ |
| 3968 | if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3969 | scmd->result = DID_NO_CONNECT << 16; |
| 3970 | scmd->scsi_done(scmd); |
| 3971 | return 0; |
| 3972 | } |
| 3973 | |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3974 | /* host recovery or link resets sent via IOCTLs */ |
| 3975 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3976 | return SCSI_MLQUEUE_HOST_BUSY; |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 3977 | /* device busy with task management */ |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3978 | else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy) |
| 3979 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 3980 | /* device has been deleted */ |
| 3981 | else if (sas_target_priv_data->deleted) { |
| 3982 | scmd->result = DID_NO_CONNECT << 16; |
| 3983 | scmd->scsi_done(scmd); |
| 3984 | return 0; |
| 3985 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3986 | |
| 3987 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) |
| 3988 | mpi_control = MPI2_SCSIIO_CONTROL_READ; |
| 3989 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 3990 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; |
| 3991 | else |
| 3992 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; |
| 3993 | |
| 3994 | /* set tags */ |
| 3995 | if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) { |
| 3996 | if (scmd->device->tagged_supported) { |
| 3997 | if (scmd->device->ordered_tags) |
| 3998 | mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ; |
| 3999 | else |
| 4000 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
| 4001 | } else |
| 4002 | /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */ |
| 4003 | /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED; |
| 4004 | */ |
| 4005 | mpi_control |= (0x500); |
| 4006 | |
| 4007 | } else |
| 4008 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4009 | /* Make sure Device is not raid volume. |
| 4010 | * We do not expose raid functionality to upper layer for warpdrive. |
| 4011 | */ |
| 4012 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 4013 | sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4014 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
| 4015 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 4016 | 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] | 4017 | if (!smid) { |
| 4018 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 4019 | ioc->name, __func__); |
| 4020 | goto out; |
| 4021 | } |
| 4022 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 4023 | memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t)); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4024 | _scsih_setup_eedp(scmd, mpi_request); |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 4025 | if (scmd->cmd_len == 32) |
| 4026 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4027 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 4028 | if (sas_device_priv_data->sas_target->flags & |
| 4029 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 4030 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; |
| 4031 | else |
| 4032 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 4033 | mpi_request->DevHandle = |
| 4034 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 4035 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
| 4036 | mpi_request->Control = cpu_to_le32(mpi_control); |
| 4037 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); |
| 4038 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; |
| 4039 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; |
| 4040 | mpi_request->SenseBufferLowAddress = |
Kashyap, Desai | ec9472c | 2009-09-23 17:34:13 +0530 | [diff] [blame] | 4041 | mpt2sas_base_get_sense_buffer_dma(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4042 | mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4; |
| 4043 | mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI + |
| 4044 | MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4045 | mpi_request->VF_ID = 0; /* TODO */ |
| 4046 | mpi_request->VP_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4047 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
| 4048 | mpi_request->LUN); |
| 4049 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 4050 | |
| 4051 | if (!mpi_request->DataLength) { |
| 4052 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL); |
| 4053 | } else { |
| 4054 | if (_scsih_build_scatter_gather(ioc, scmd, smid)) { |
| 4055 | mpt2sas_base_free_smid(ioc, smid); |
| 4056 | goto out; |
| 4057 | } |
| 4058 | } |
| 4059 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4060 | raid_device = sas_target_priv_data->raid_device; |
| 4061 | if (raid_device && raid_device->direct_io_enabled) |
| 4062 | _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request, |
| 4063 | smid); |
| 4064 | |
Kashyap, Desai | 58287fd | 2010-03-17 16:27:25 +0530 | [diff] [blame] | 4065 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) |
| 4066 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4067 | le16_to_cpu(mpi_request->DevHandle)); |
Kashyap, Desai | 58287fd | 2010-03-17 16:27:25 +0530 | [diff] [blame] | 4068 | else |
| 4069 | mpt2sas_base_put_smid_default(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4070 | return 0; |
| 4071 | |
| 4072 | out: |
| 4073 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4074 | } |
| 4075 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 4076 | static DEF_SCSI_QCMD(_scsih_qcmd) |
| 4077 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4078 | /** |
| 4079 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data |
| 4080 | * @sense_buffer: sense data returned by target |
| 4081 | * @data: normalized skey/asc/ascq |
| 4082 | * |
| 4083 | * Return nothing. |
| 4084 | */ |
| 4085 | static void |
| 4086 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) |
| 4087 | { |
| 4088 | if ((sense_buffer[0] & 0x7F) >= 0x72) { |
| 4089 | /* descriptor format */ |
| 4090 | data->skey = sense_buffer[1] & 0x0F; |
| 4091 | data->asc = sense_buffer[2]; |
| 4092 | data->ascq = sense_buffer[3]; |
| 4093 | } else { |
| 4094 | /* fixed format */ |
| 4095 | data->skey = sense_buffer[2] & 0x0F; |
| 4096 | data->asc = sense_buffer[12]; |
| 4097 | data->ascq = sense_buffer[13]; |
| 4098 | } |
| 4099 | } |
| 4100 | |
| 4101 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4102 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4103 | * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4104 | * @ioc: per adapter object |
| 4105 | * @scmd: pointer to scsi command object |
| 4106 | * @mpi_reply: reply mf payload returned from firmware |
| 4107 | * |
| 4108 | * scsi_status - SCSI Status code returned from target device |
| 4109 | * scsi_state - state info associated with SCSI_IO determined by ioc |
| 4110 | * ioc_status - ioc supplied status info |
| 4111 | * |
| 4112 | * Return nothing. |
| 4113 | */ |
| 4114 | static void |
| 4115 | _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 4116 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) |
| 4117 | { |
| 4118 | u32 response_info; |
| 4119 | u8 *response_bytes; |
| 4120 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & |
| 4121 | MPI2_IOCSTATUS_MASK; |
| 4122 | u8 scsi_state = mpi_reply->SCSIState; |
| 4123 | u8 scsi_status = mpi_reply->SCSIStatus; |
| 4124 | char *desc_ioc_state = NULL; |
| 4125 | char *desc_scsi_status = NULL; |
| 4126 | char *desc_scsi_state = ioc->tmp_string; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4127 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4128 | struct _sas_device *sas_device = NULL; |
| 4129 | unsigned long flags; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4130 | struct scsi_target *starget = scmd->device->sdev_target; |
| 4131 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4132 | char *device_str = NULL; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4133 | |
| 4134 | if (!priv_target) |
| 4135 | return; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4136 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4137 | if (ioc->hide_ir_msg) |
| 4138 | device_str = "WarpDrive"; |
| 4139 | else |
| 4140 | device_str = "volume"; |
| 4141 | |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4142 | if (log_info == 0x31170000) |
| 4143 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4144 | |
| 4145 | switch (ioc_status) { |
| 4146 | case MPI2_IOCSTATUS_SUCCESS: |
| 4147 | desc_ioc_state = "success"; |
| 4148 | break; |
| 4149 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 4150 | desc_ioc_state = "invalid function"; |
| 4151 | break; |
| 4152 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 4153 | desc_ioc_state = "scsi recovered error"; |
| 4154 | break; |
| 4155 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: |
| 4156 | desc_ioc_state = "scsi invalid dev handle"; |
| 4157 | break; |
| 4158 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 4159 | desc_ioc_state = "scsi device not there"; |
| 4160 | break; |
| 4161 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 4162 | desc_ioc_state = "scsi data overrun"; |
| 4163 | break; |
| 4164 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 4165 | desc_ioc_state = "scsi data underrun"; |
| 4166 | break; |
| 4167 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 4168 | desc_ioc_state = "scsi io data error"; |
| 4169 | break; |
| 4170 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 4171 | desc_ioc_state = "scsi protocol error"; |
| 4172 | break; |
| 4173 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 4174 | desc_ioc_state = "scsi task terminated"; |
| 4175 | break; |
| 4176 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 4177 | desc_ioc_state = "scsi residual mismatch"; |
| 4178 | break; |
| 4179 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 4180 | desc_ioc_state = "scsi task mgmt failed"; |
| 4181 | break; |
| 4182 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 4183 | desc_ioc_state = "scsi ioc terminated"; |
| 4184 | break; |
| 4185 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 4186 | desc_ioc_state = "scsi ext terminated"; |
| 4187 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4188 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 4189 | desc_ioc_state = "eedp guard error"; |
| 4190 | break; |
| 4191 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 4192 | desc_ioc_state = "eedp ref tag error"; |
| 4193 | break; |
| 4194 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 4195 | desc_ioc_state = "eedp app tag error"; |
| 4196 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4197 | default: |
| 4198 | desc_ioc_state = "unknown"; |
| 4199 | break; |
| 4200 | } |
| 4201 | |
| 4202 | switch (scsi_status) { |
| 4203 | case MPI2_SCSI_STATUS_GOOD: |
| 4204 | desc_scsi_status = "good"; |
| 4205 | break; |
| 4206 | case MPI2_SCSI_STATUS_CHECK_CONDITION: |
| 4207 | desc_scsi_status = "check condition"; |
| 4208 | break; |
| 4209 | case MPI2_SCSI_STATUS_CONDITION_MET: |
| 4210 | desc_scsi_status = "condition met"; |
| 4211 | break; |
| 4212 | case MPI2_SCSI_STATUS_BUSY: |
| 4213 | desc_scsi_status = "busy"; |
| 4214 | break; |
| 4215 | case MPI2_SCSI_STATUS_INTERMEDIATE: |
| 4216 | desc_scsi_status = "intermediate"; |
| 4217 | break; |
| 4218 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: |
| 4219 | desc_scsi_status = "intermediate condmet"; |
| 4220 | break; |
| 4221 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: |
| 4222 | desc_scsi_status = "reservation conflict"; |
| 4223 | break; |
| 4224 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: |
| 4225 | desc_scsi_status = "command terminated"; |
| 4226 | break; |
| 4227 | case MPI2_SCSI_STATUS_TASK_SET_FULL: |
| 4228 | desc_scsi_status = "task set full"; |
| 4229 | break; |
| 4230 | case MPI2_SCSI_STATUS_ACA_ACTIVE: |
| 4231 | desc_scsi_status = "aca active"; |
| 4232 | break; |
| 4233 | case MPI2_SCSI_STATUS_TASK_ABORTED: |
| 4234 | desc_scsi_status = "task aborted"; |
| 4235 | break; |
| 4236 | default: |
| 4237 | desc_scsi_status = "unknown"; |
| 4238 | break; |
| 4239 | } |
| 4240 | |
| 4241 | desc_scsi_state[0] = '\0'; |
| 4242 | if (!scsi_state) |
| 4243 | desc_scsi_state = " "; |
| 4244 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 4245 | strcat(desc_scsi_state, "response info "); |
| 4246 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4247 | strcat(desc_scsi_state, "state terminated "); |
| 4248 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) |
| 4249 | strcat(desc_scsi_state, "no status "); |
| 4250 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) |
| 4251 | strcat(desc_scsi_state, "autosense failed "); |
| 4252 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) |
| 4253 | strcat(desc_scsi_state, "autosense valid "); |
| 4254 | |
| 4255 | scsi_print_command(scmd); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4256 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4257 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4258 | printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name, |
| 4259 | device_str, (unsigned long long)priv_target->sas_address); |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4260 | } else { |
| 4261 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4262 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 4263 | priv_target->sas_address); |
| 4264 | if (sas_device) { |
| 4265 | printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), " |
| 4266 | "phy(%d)\n", ioc->name, sas_device->sas_address, |
| 4267 | sas_device->phy); |
| 4268 | printk(MPT2SAS_WARN_FMT |
| 4269 | "\tenclosure_logical_id(0x%016llx), slot(%d)\n", |
| 4270 | ioc->name, sas_device->enclosure_logical_id, |
| 4271 | sas_device->slot); |
| 4272 | } |
| 4273 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4274 | } |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4275 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4276 | printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), " |
| 4277 | "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle), |
| 4278 | desc_ioc_state, ioc_status, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4279 | printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), " |
| 4280 | "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow, |
| 4281 | scsi_get_resid(scmd)); |
| 4282 | printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), " |
| 4283 | "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag), |
| 4284 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); |
| 4285 | printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), " |
| 4286 | "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status, |
| 4287 | scsi_status, desc_scsi_state, scsi_state); |
| 4288 | |
| 4289 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4290 | struct sense_info data; |
| 4291 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4292 | printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: " |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 4293 | "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey, |
| 4294 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4295 | } |
| 4296 | |
| 4297 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { |
| 4298 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); |
| 4299 | response_bytes = (u8 *)&response_info; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4300 | _scsih_response_code(ioc, response_bytes[0]); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4301 | } |
| 4302 | } |
| 4303 | #endif |
| 4304 | |
| 4305 | /** |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4306 | * _scsih_turn_on_fault_led - illuminate Fault LED |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4307 | * @ioc: per adapter object |
| 4308 | * @handle: device handle |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4309 | * Context: process |
| 4310 | * |
| 4311 | * Return nothing. |
| 4312 | */ |
| 4313 | static void |
| 4314 | _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4315 | { |
| 4316 | Mpi2SepReply_t mpi_reply; |
| 4317 | Mpi2SepRequest_t mpi_request; |
| 4318 | |
| 4319 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
| 4320 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; |
| 4321 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; |
| 4322 | mpi_request.SlotStatus = |
| 4323 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); |
| 4324 | mpi_request.DevHandle = cpu_to_le16(handle); |
| 4325 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; |
| 4326 | if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply, |
| 4327 | &mpi_request)) != 0) { |
| 4328 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 4329 | __FILE__, __LINE__, __func__); |
| 4330 | return; |
| 4331 | } |
| 4332 | |
| 4333 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { |
| 4334 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: " |
| 4335 | "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name, |
| 4336 | le16_to_cpu(mpi_reply.IOCStatus), |
| 4337 | le32_to_cpu(mpi_reply.IOCLogInfo))); |
| 4338 | return; |
| 4339 | } |
| 4340 | } |
| 4341 | |
| 4342 | /** |
| 4343 | * _scsih_send_event_to_turn_on_fault_led - fire delayed event |
| 4344 | * @ioc: per adapter object |
| 4345 | * @handle: device handle |
| 4346 | * Context: interrupt. |
| 4347 | * |
| 4348 | * Return nothing. |
| 4349 | */ |
| 4350 | static void |
| 4351 | _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4352 | { |
| 4353 | struct fw_event_work *fw_event; |
| 4354 | |
| 4355 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 4356 | if (!fw_event) |
| 4357 | return; |
| 4358 | fw_event->event = MPT2SAS_TURN_ON_FAULT_LED; |
| 4359 | fw_event->device_handle = handle; |
| 4360 | fw_event->ioc = ioc; |
| 4361 | _scsih_fw_event_add(ioc, fw_event); |
| 4362 | } |
| 4363 | |
| 4364 | /** |
| 4365 | * _scsih_smart_predicted_fault - process smart errors |
| 4366 | * @ioc: per adapter object |
| 4367 | * @handle: device handle |
| 4368 | * Context: interrupt. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4369 | * |
| 4370 | * Return nothing. |
| 4371 | */ |
| 4372 | static void |
| 4373 | _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4374 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4375 | struct scsi_target *starget; |
| 4376 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 4377 | Mpi2EventNotificationReply_t *event_reply; |
| 4378 | Mpi2EventDataSasDeviceStatusChange_t *event_data; |
| 4379 | struct _sas_device *sas_device; |
| 4380 | ssize_t sz; |
| 4381 | unsigned long flags; |
| 4382 | |
| 4383 | /* only handle non-raid devices */ |
| 4384 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4385 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 4386 | if (!sas_device) { |
| 4387 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4388 | return; |
| 4389 | } |
| 4390 | starget = sas_device->starget; |
| 4391 | sas_target_priv_data = starget->hostdata; |
| 4392 | |
| 4393 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || |
| 4394 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) { |
| 4395 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4396 | return; |
| 4397 | } |
| 4398 | starget_printk(KERN_WARNING, starget, "predicted fault\n"); |
| 4399 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4400 | |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4401 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) |
| 4402 | _scsih_send_event_to_turn_on_fault_led(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4403 | |
| 4404 | /* insert into event log */ |
| 4405 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + |
| 4406 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); |
Anton Blanchard | f6a290b4 | 2011-11-07 22:05:21 +1100 | [diff] [blame] | 4407 | event_reply = kzalloc(sz, GFP_ATOMIC); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4408 | if (!event_reply) { |
| 4409 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4410 | ioc->name, __FILE__, __LINE__, __func__); |
| 4411 | return; |
| 4412 | } |
| 4413 | |
| 4414 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; |
| 4415 | event_reply->Event = |
| 4416 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); |
| 4417 | event_reply->MsgLength = sz/4; |
| 4418 | event_reply->EventDataLength = |
| 4419 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); |
| 4420 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) |
| 4421 | event_reply->EventData; |
| 4422 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; |
| 4423 | event_data->ASC = 0x5D; |
| 4424 | event_data->DevHandle = cpu_to_le16(handle); |
| 4425 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); |
| 4426 | mpt2sas_ctl_add_to_event_log(ioc, event_reply); |
| 4427 | kfree(event_reply); |
| 4428 | } |
| 4429 | |
| 4430 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 4431 | * _scsih_io_done - scsi request callback |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4432 | * @ioc: per adapter object |
| 4433 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4434 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4435 | * @reply: reply message frame(lower 32bit addr) |
| 4436 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4437 | * Callback handler when using _scsih_qcmd. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4438 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4439 | * Return 1 meaning mf should be freed from _base_interrupt |
| 4440 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4441 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4442 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4443 | _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] | 4444 | { |
| 4445 | Mpi2SCSIIORequest_t *mpi_request; |
| 4446 | Mpi2SCSIIOReply_t *mpi_reply; |
| 4447 | struct scsi_cmnd *scmd; |
| 4448 | u16 ioc_status; |
| 4449 | u32 xfer_cnt; |
| 4450 | u8 scsi_state; |
| 4451 | u8 scsi_status; |
| 4452 | u32 log_info; |
| 4453 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4454 | u32 response_code = 0; |
Kashyap, Desai | 82a4525 | 2011-07-05 12:40:23 +0530 | [diff] [blame] | 4455 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4456 | |
| 4457 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 4458 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4459 | if (scmd == NULL) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4460 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4461 | |
| 4462 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 4463 | |
| 4464 | if (mpi_reply == NULL) { |
| 4465 | scmd->result = DID_OK << 16; |
| 4466 | goto out; |
| 4467 | } |
| 4468 | |
| 4469 | sas_device_priv_data = scmd->device->hostdata; |
| 4470 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
| 4471 | sas_device_priv_data->sas_target->deleted) { |
| 4472 | scmd->result = DID_NO_CONNECT << 16; |
| 4473 | goto out; |
| 4474 | } |
nagalakshmi.nandigama@lsi.com | 4da7af9 | 2011-12-01 07:53:02 +0530 | [diff] [blame] | 4475 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4476 | /* |
| 4477 | * WARPDRIVE: If direct_io is set then it is directIO, |
| 4478 | * the failed direct I/O should be redirected to volume |
| 4479 | */ |
nagalakshmi.nandigama@lsi.com | 4da7af9 | 2011-12-01 07:53:02 +0530 | [diff] [blame] | 4480 | if (_scsih_scsi_direct_io_get(ioc, smid) && |
| 4481 | ((ioc_status & MPI2_IOCSTATUS_MASK) |
| 4482 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { |
Kashyap, Desai | 82a4525 | 2011-07-05 12:40:23 +0530 | [diff] [blame] | 4483 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 4484 | ioc->scsi_lookup[smid - 1].scmd = scmd; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4485 | _scsih_scsi_direct_io_set(ioc, smid, 0); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 4486 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4487 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 4488 | mpi_request->DevHandle = |
| 4489 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 4490 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
| 4491 | sas_device_priv_data->sas_target->handle); |
| 4492 | return 0; |
| 4493 | } |
| 4494 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4495 | |
| 4496 | /* turning off TLR */ |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4497 | scsi_state = mpi_reply->SCSIState; |
| 4498 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 4499 | response_code = |
| 4500 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4501 | if (!sas_device_priv_data->tlr_snoop_check) { |
| 4502 | sas_device_priv_data->tlr_snoop_check++; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4503 | /* Make sure Device is not raid volume. |
| 4504 | * We do not expose raid functionality to upper layer for warpdrive. |
| 4505 | */ |
| 4506 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && |
Kashyap, Desai | 3ed2152 | 2010-02-17 16:08:36 +0530 | [diff] [blame] | 4507 | sas_is_tlr_enabled(scmd->device) && |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 4508 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { |
| 4509 | sas_disable_tlr(scmd->device); |
| 4510 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); |
| 4511 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4512 | } |
| 4513 | |
| 4514 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); |
| 4515 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4516 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) |
| 4517 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
| 4518 | else |
| 4519 | log_info = 0; |
| 4520 | ioc_status &= MPI2_IOCSTATUS_MASK; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4521 | scsi_status = mpi_reply->SCSIStatus; |
| 4522 | |
| 4523 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && |
| 4524 | (scsi_status == MPI2_SCSI_STATUS_BUSY || |
| 4525 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || |
| 4526 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { |
| 4527 | ioc_status = MPI2_IOCSTATUS_SUCCESS; |
| 4528 | } |
| 4529 | |
| 4530 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4531 | struct sense_info data; |
| 4532 | const void *sense_data = mpt2sas_base_get_sense_buffer(ioc, |
| 4533 | smid); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 4534 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4535 | le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 4536 | memcpy(scmd->sense_buffer, sense_data, sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4537 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4538 | /* failure prediction threshold exceeded */ |
| 4539 | if (data.asc == 0x5D) |
| 4540 | _scsih_smart_predicted_fault(ioc, |
| 4541 | le16_to_cpu(mpi_reply->DevHandle)); |
| 4542 | } |
| 4543 | |
| 4544 | switch (ioc_status) { |
| 4545 | case MPI2_IOCSTATUS_BUSY: |
| 4546 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: |
| 4547 | scmd->result = SAM_STAT_BUSY; |
| 4548 | break; |
| 4549 | |
| 4550 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 4551 | scmd->result = DID_NO_CONNECT << 16; |
| 4552 | break; |
| 4553 | |
| 4554 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 4555 | if (sas_device_priv_data->block) { |
Kashyap, Desai | e4e7c7e | 2009-09-23 17:33:14 +0530 | [diff] [blame] | 4556 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; |
| 4557 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4558 | } |
nagalakshmi.nandigama@lsi.com | 3ade1ca | 2011-12-01 07:42:40 +0530 | [diff] [blame] | 4559 | scmd->result = DID_SOFT_ERROR << 16; |
| 4560 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4561 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 4562 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 4563 | scmd->result = DID_RESET << 16; |
| 4564 | break; |
| 4565 | |
| 4566 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 4567 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) |
| 4568 | scmd->result = DID_SOFT_ERROR << 16; |
| 4569 | else |
| 4570 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4571 | break; |
| 4572 | |
| 4573 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 4574 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4575 | |
| 4576 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) |
| 4577 | break; |
| 4578 | |
| 4579 | if (xfer_cnt < scmd->underflow) { |
| 4580 | if (scsi_status == SAM_STAT_BUSY) |
| 4581 | scmd->result = SAM_STAT_BUSY; |
| 4582 | else |
| 4583 | scmd->result = DID_SOFT_ERROR << 16; |
| 4584 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4585 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) |
| 4586 | scmd->result = DID_SOFT_ERROR << 16; |
| 4587 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4588 | scmd->result = DID_RESET << 16; |
| 4589 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { |
| 4590 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; |
| 4591 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; |
| 4592 | scmd->result = (DRIVER_SENSE << 24) | |
| 4593 | SAM_STAT_CHECK_CONDITION; |
| 4594 | scmd->sense_buffer[0] = 0x70; |
| 4595 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; |
| 4596 | scmd->sense_buffer[12] = 0x20; |
| 4597 | scmd->sense_buffer[13] = 0; |
| 4598 | } |
| 4599 | break; |
| 4600 | |
| 4601 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 4602 | scsi_set_resid(scmd, 0); |
| 4603 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 4604 | case MPI2_IOCSTATUS_SUCCESS: |
| 4605 | scmd->result = (DID_OK << 16) | scsi_status; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4606 | if (response_code == |
| 4607 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || |
| 4608 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4609 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4610 | scmd->result = DID_SOFT_ERROR << 16; |
| 4611 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4612 | scmd->result = DID_RESET << 16; |
| 4613 | break; |
| 4614 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4615 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 4616 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 4617 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 4618 | _scsih_eedp_error_handling(scmd, ioc_status); |
| 4619 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4620 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 4621 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 4622 | case MPI2_IOCSTATUS_INVALID_SGL: |
| 4623 | case MPI2_IOCSTATUS_INTERNAL_ERROR: |
| 4624 | case MPI2_IOCSTATUS_INVALID_FIELD: |
| 4625 | case MPI2_IOCSTATUS_INVALID_STATE: |
| 4626 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 4627 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 4628 | default: |
| 4629 | scmd->result = DID_SOFT_ERROR << 16; |
| 4630 | break; |
| 4631 | |
| 4632 | } |
| 4633 | |
| 4634 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4635 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
| 4636 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); |
| 4637 | #endif |
| 4638 | |
| 4639 | out: |
| 4640 | scsi_dma_unmap(scmd); |
| 4641 | scmd->scsi_done(scmd); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4642 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4643 | } |
| 4644 | |
| 4645 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4646 | * _scsih_sas_host_refresh - refreshing sas host object contents |
| 4647 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4648 | * Context: user |
| 4649 | * |
| 4650 | * During port enable, fw will send topology events for every device. Its |
| 4651 | * possible that the handles may change from the previous setting, so this |
| 4652 | * code keeping handles updating if changed. |
| 4653 | * |
| 4654 | * Return nothing. |
| 4655 | */ |
| 4656 | static void |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4657 | _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4658 | { |
| 4659 | u16 sz; |
| 4660 | u16 ioc_status; |
| 4661 | int i; |
| 4662 | Mpi2ConfigReply_t mpi_reply; |
| 4663 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4664 | u16 attached_handle; |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4665 | u8 link_rate; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4666 | |
| 4667 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 4668 | "updating handles for sas_host(0x%016llx)\n", |
| 4669 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); |
| 4670 | |
| 4671 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys |
| 4672 | * sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4673 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4674 | if (!sas_iounit_pg0) { |
| 4675 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4676 | ioc->name, __FILE__, __LINE__, __func__); |
| 4677 | return; |
| 4678 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4679 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4680 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4681 | sas_iounit_pg0, sz)) != 0) |
| 4682 | goto out; |
| 4683 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 4684 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 4685 | goto out; |
| 4686 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4687 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4688 | if (i == 0) |
| 4689 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4690 | PhyData[0].ControllerDevHandle); |
| 4691 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
| 4692 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. |
| 4693 | AttachedDevHandle); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4694 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 4695 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4696 | mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address, |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4697 | attached_handle, i, link_rate); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4698 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4699 | out: |
| 4700 | kfree(sas_iounit_pg0); |
| 4701 | } |
| 4702 | |
| 4703 | /** |
| 4704 | * _scsih_sas_host_add - create sas host object |
| 4705 | * @ioc: per adapter object |
| 4706 | * |
| 4707 | * Creating host side data object, stored in ioc->sas_hba |
| 4708 | * |
| 4709 | * Return nothing. |
| 4710 | */ |
| 4711 | static void |
| 4712 | _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc) |
| 4713 | { |
| 4714 | int i; |
| 4715 | Mpi2ConfigReply_t mpi_reply; |
| 4716 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
| 4717 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; |
| 4718 | Mpi2SasPhyPage0_t phy_pg0; |
| 4719 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4720 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4721 | u16 ioc_status; |
| 4722 | u16 sz; |
| 4723 | u16 device_missing_delay; |
| 4724 | |
| 4725 | mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys); |
| 4726 | if (!ioc->sas_hba.num_phys) { |
| 4727 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4728 | ioc->name, __FILE__, __LINE__, __func__); |
| 4729 | return; |
| 4730 | } |
| 4731 | |
| 4732 | /* sas_iounit page 0 */ |
| 4733 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4734 | sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4735 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4736 | if (!sas_iounit_pg0) { |
| 4737 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4738 | ioc->name, __FILE__, __LINE__, __func__); |
| 4739 | return; |
| 4740 | } |
| 4741 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4742 | sas_iounit_pg0, sz))) { |
| 4743 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4744 | ioc->name, __FILE__, __LINE__, __func__); |
| 4745 | goto out; |
| 4746 | } |
| 4747 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4748 | MPI2_IOCSTATUS_MASK; |
| 4749 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4750 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4751 | ioc->name, __FILE__, __LINE__, __func__); |
| 4752 | goto out; |
| 4753 | } |
| 4754 | |
| 4755 | /* sas_iounit page 1 */ |
| 4756 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4757 | sizeof(Mpi2SasIOUnit1PhyData_t)); |
| 4758 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); |
| 4759 | if (!sas_iounit_pg1) { |
| 4760 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4761 | ioc->name, __FILE__, __LINE__, __func__); |
| 4762 | goto out; |
| 4763 | } |
| 4764 | if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, |
| 4765 | sas_iounit_pg1, sz))) { |
| 4766 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4767 | ioc->name, __FILE__, __LINE__, __func__); |
| 4768 | goto out; |
| 4769 | } |
| 4770 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4771 | MPI2_IOCSTATUS_MASK; |
| 4772 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4773 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4774 | ioc->name, __FILE__, __LINE__, __func__); |
| 4775 | goto out; |
| 4776 | } |
| 4777 | |
| 4778 | ioc->io_missing_delay = |
| 4779 | le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay); |
| 4780 | device_missing_delay = |
| 4781 | le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay); |
| 4782 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) |
| 4783 | ioc->device_missing_delay = (device_missing_delay & |
| 4784 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; |
| 4785 | else |
| 4786 | ioc->device_missing_delay = device_missing_delay & |
| 4787 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 4788 | |
| 4789 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; |
| 4790 | ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys, |
| 4791 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4792 | if (!ioc->sas_hba.phy) { |
| 4793 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4794 | ioc->name, __FILE__, __LINE__, __func__); |
| 4795 | goto out; |
| 4796 | } |
| 4797 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
| 4798 | if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, |
| 4799 | i))) { |
| 4800 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4801 | ioc->name, __FILE__, __LINE__, __func__); |
| 4802 | goto out; |
| 4803 | } |
| 4804 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4805 | MPI2_IOCSTATUS_MASK; |
| 4806 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4807 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4808 | ioc->name, __FILE__, __LINE__, __func__); |
| 4809 | goto out; |
| 4810 | } |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4811 | |
| 4812 | if (i == 0) |
| 4813 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4814 | PhyData[0].ControllerDevHandle); |
| 4815 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4816 | ioc->sas_hba.phy[i].phy_id = i; |
| 4817 | mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], |
| 4818 | phy_pg0, ioc->sas_hba.parent_dev); |
| 4819 | } |
| 4820 | 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] | 4821 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4822 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4823 | ioc->name, __FILE__, __LINE__, __func__); |
| 4824 | goto out; |
| 4825 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4826 | ioc->sas_hba.enclosure_handle = |
| 4827 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 4828 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 4829 | printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), " |
| 4830 | "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle, |
| 4831 | (unsigned long long) ioc->sas_hba.sas_address, |
| 4832 | ioc->sas_hba.num_phys) ; |
| 4833 | |
| 4834 | if (ioc->sas_hba.enclosure_handle) { |
| 4835 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4836 | &enclosure_pg0, |
| 4837 | MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4838 | ioc->sas_hba.enclosure_handle))) { |
| 4839 | ioc->sas_hba.enclosure_logical_id = |
| 4840 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4841 | } |
| 4842 | } |
| 4843 | |
| 4844 | out: |
| 4845 | kfree(sas_iounit_pg1); |
| 4846 | kfree(sas_iounit_pg0); |
| 4847 | } |
| 4848 | |
| 4849 | /** |
| 4850 | * _scsih_expander_add - creating expander object |
| 4851 | * @ioc: per adapter object |
| 4852 | * @handle: expander handle |
| 4853 | * |
| 4854 | * Creating expander object, stored in ioc->sas_expander_list. |
| 4855 | * |
| 4856 | * Return 0 for success, else error. |
| 4857 | */ |
| 4858 | static int |
| 4859 | _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4860 | { |
| 4861 | struct _sas_node *sas_expander; |
| 4862 | Mpi2ConfigReply_t mpi_reply; |
| 4863 | Mpi2ExpanderPage0_t expander_pg0; |
| 4864 | Mpi2ExpanderPage1_t expander_pg1; |
| 4865 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4866 | u32 ioc_status; |
| 4867 | u16 parent_handle; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 4868 | u64 sas_address, sas_address_parent = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4869 | int i; |
| 4870 | unsigned long flags; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4871 | struct _sas_port *mpt2sas_port = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4872 | int rc = 0; |
| 4873 | |
| 4874 | if (!handle) |
| 4875 | return -1; |
| 4876 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 4877 | if (ioc->shost_recovery || ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 4878 | return -1; |
| 4879 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4880 | if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 4881 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { |
| 4882 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4883 | ioc->name, __FILE__, __LINE__, __func__); |
| 4884 | return -1; |
| 4885 | } |
| 4886 | |
| 4887 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4888 | MPI2_IOCSTATUS_MASK; |
| 4889 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4890 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4891 | ioc->name, __FILE__, __LINE__, __func__); |
| 4892 | return -1; |
| 4893 | } |
| 4894 | |
| 4895 | /* handle out of order topology events */ |
| 4896 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4897 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) |
| 4898 | != 0) { |
| 4899 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4900 | ioc->name, __FILE__, __LINE__, __func__); |
| 4901 | return -1; |
| 4902 | } |
| 4903 | if (sas_address_parent != ioc->sas_hba.sas_address) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4904 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4905 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4906 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4907 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4908 | if (!sas_expander) { |
| 4909 | rc = _scsih_expander_add(ioc, parent_handle); |
| 4910 | if (rc != 0) |
| 4911 | return rc; |
| 4912 | } |
| 4913 | } |
| 4914 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4915 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 4916 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4917 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4918 | sas_address); |
| 4919 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4920 | |
| 4921 | if (sas_expander) |
| 4922 | return 0; |
| 4923 | |
| 4924 | sas_expander = kzalloc(sizeof(struct _sas_node), |
| 4925 | GFP_KERNEL); |
| 4926 | if (!sas_expander) { |
| 4927 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4928 | ioc->name, __FILE__, __LINE__, __func__); |
| 4929 | return -1; |
| 4930 | } |
| 4931 | |
| 4932 | sas_expander->handle = handle; |
| 4933 | sas_expander->num_phys = expander_pg0.NumPhys; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4934 | sas_expander->sas_address_parent = sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4935 | sas_expander->sas_address = sas_address; |
| 4936 | |
| 4937 | printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x)," |
| 4938 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4939 | handle, parent_handle, (unsigned long long) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4940 | sas_expander->sas_address, sas_expander->num_phys); |
| 4941 | |
| 4942 | if (!sas_expander->num_phys) |
| 4943 | goto out_fail; |
| 4944 | sas_expander->phy = kcalloc(sas_expander->num_phys, |
| 4945 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4946 | if (!sas_expander->phy) { |
| 4947 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4948 | ioc->name, __FILE__, __LINE__, __func__); |
| 4949 | rc = -1; |
| 4950 | goto out_fail; |
| 4951 | } |
| 4952 | |
| 4953 | INIT_LIST_HEAD(&sas_expander->sas_port_list); |
| 4954 | mpt2sas_port = mpt2sas_transport_port_add(ioc, handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4955 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4956 | if (!mpt2sas_port) { |
| 4957 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4958 | ioc->name, __FILE__, __LINE__, __func__); |
| 4959 | rc = -1; |
| 4960 | goto out_fail; |
| 4961 | } |
| 4962 | sas_expander->parent_dev = &mpt2sas_port->rphy->dev; |
| 4963 | |
| 4964 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 4965 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 4966 | &expander_pg1, i, handle))) { |
| 4967 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4968 | ioc->name, __FILE__, __LINE__, __func__); |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4969 | rc = -1; |
| 4970 | goto out_fail; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4971 | } |
| 4972 | sas_expander->phy[i].handle = handle; |
| 4973 | sas_expander->phy[i].phy_id = i; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4974 | |
| 4975 | if ((mpt2sas_transport_add_expander_phy(ioc, |
| 4976 | &sas_expander->phy[i], expander_pg1, |
| 4977 | sas_expander->parent_dev))) { |
| 4978 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4979 | ioc->name, __FILE__, __LINE__, __func__); |
| 4980 | rc = -1; |
| 4981 | goto out_fail; |
| 4982 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4983 | } |
| 4984 | |
| 4985 | if (sas_expander->enclosure_handle) { |
| 4986 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4987 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4988 | sas_expander->enclosure_handle))) { |
| 4989 | sas_expander->enclosure_logical_id = |
| 4990 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4991 | } |
| 4992 | } |
| 4993 | |
| 4994 | _scsih_expander_node_add(ioc, sas_expander); |
| 4995 | return 0; |
| 4996 | |
| 4997 | out_fail: |
| 4998 | |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4999 | if (mpt2sas_port) |
| 5000 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5001 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5002 | kfree(sas_expander); |
| 5003 | return rc; |
| 5004 | } |
| 5005 | |
| 5006 | /** |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 5007 | * _scsih_done - scsih callback handler. |
| 5008 | * @ioc: per adapter object |
| 5009 | * @smid: system request message index |
| 5010 | * @msix_index: MSIX table index supplied by the OS |
| 5011 | * @reply: reply message frame(lower 32bit addr) |
| 5012 | * |
| 5013 | * Callback handler when sending internal generated message frames. |
| 5014 | * The callback index passed is `ioc->scsih_cb_idx` |
| 5015 | * |
| 5016 | * Return 1 meaning mf should be freed from _base_interrupt |
| 5017 | * 0 means the mf is freed from this function. |
| 5018 | */ |
| 5019 | static u8 |
| 5020 | _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) |
| 5021 | { |
| 5022 | MPI2DefaultReply_t *mpi_reply; |
| 5023 | |
| 5024 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 5025 | if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED) |
| 5026 | return 1; |
| 5027 | if (ioc->scsih_cmds.smid != smid) |
| 5028 | return 1; |
| 5029 | ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE; |
| 5030 | if (mpi_reply) { |
| 5031 | memcpy(ioc->scsih_cmds.reply, mpi_reply, |
| 5032 | mpi_reply->MsgLength*4); |
| 5033 | ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 5034 | } |
| 5035 | ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING; |
| 5036 | complete(&ioc->scsih_cmds.done); |
| 5037 | return 1; |
| 5038 | } |
| 5039 | |
| 5040 | /** |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5041 | * mpt2sas_expander_remove - removing expander object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5042 | * @ioc: per adapter object |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5043 | * @sas_address: expander sas_address |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5044 | * |
| 5045 | * Return nothing. |
| 5046 | */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5047 | void |
| 5048 | mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5049 | { |
| 5050 | struct _sas_node *sas_expander; |
| 5051 | unsigned long flags; |
| 5052 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 5053 | if (ioc->shost_recovery) |
| 5054 | return; |
| 5055 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5056 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5057 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 5058 | sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5059 | if (sas_expander) |
| 5060 | list_del(&sas_expander->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5061 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5062 | if (sas_expander) |
| 5063 | _scsih_expander_node_remove(ioc, sas_expander); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5064 | } |
| 5065 | |
| 5066 | /** |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5067 | * _scsih_check_access_status - check access flags |
| 5068 | * @ioc: per adapter object |
| 5069 | * @sas_address: sas address |
| 5070 | * @handle: sas device handle |
| 5071 | * @access_flags: errors returned during discovery of the device |
| 5072 | * |
| 5073 | * Return 0 for success, else failure |
| 5074 | */ |
| 5075 | static u8 |
| 5076 | _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 5077 | u16 handle, u8 access_status) |
| 5078 | { |
| 5079 | u8 rc = 1; |
| 5080 | char *desc = NULL; |
| 5081 | |
| 5082 | switch (access_status) { |
| 5083 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: |
| 5084 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: |
| 5085 | rc = 0; |
| 5086 | break; |
| 5087 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: |
| 5088 | desc = "sata capability failed"; |
| 5089 | break; |
| 5090 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: |
| 5091 | desc = "sata affiliation conflict"; |
| 5092 | break; |
| 5093 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: |
| 5094 | desc = "route not addressable"; |
| 5095 | break; |
| 5096 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: |
| 5097 | desc = "smp error not addressable"; |
| 5098 | break; |
| 5099 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: |
| 5100 | desc = "device blocked"; |
| 5101 | break; |
| 5102 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: |
| 5103 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: |
| 5104 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: |
| 5105 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: |
| 5106 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: |
| 5107 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: |
| 5108 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: |
| 5109 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: |
| 5110 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: |
| 5111 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: |
| 5112 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: |
| 5113 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: |
| 5114 | desc = "sata initialization failed"; |
| 5115 | break; |
| 5116 | default: |
| 5117 | desc = "unknown"; |
| 5118 | break; |
| 5119 | } |
| 5120 | |
| 5121 | if (!rc) |
| 5122 | return 0; |
| 5123 | |
| 5124 | printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), " |
| 5125 | "handle(0x%04x)\n", ioc->name, desc, |
| 5126 | (unsigned long long)sas_address, handle); |
| 5127 | return rc; |
| 5128 | } |
| 5129 | |
| 5130 | static void |
| 5131 | _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 5132 | { |
| 5133 | Mpi2ConfigReply_t mpi_reply; |
| 5134 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 5135 | struct _sas_device *sas_device; |
| 5136 | u32 ioc_status; |
| 5137 | unsigned long flags; |
| 5138 | u64 sas_address; |
| 5139 | struct scsi_target *starget; |
| 5140 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 5141 | u32 device_info; |
| 5142 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5143 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5144 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 5145 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) |
| 5146 | return; |
| 5147 | |
| 5148 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 5149 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 5150 | return; |
| 5151 | |
| 5152 | /* check if this is end device */ |
| 5153 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 5154 | if (!(_scsih_is_end_device(device_info))) |
| 5155 | return; |
| 5156 | |
| 5157 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5158 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 5159 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5160 | sas_address); |
| 5161 | |
| 5162 | if (!sas_device) { |
| 5163 | printk(MPT2SAS_ERR_FMT "device is not present " |
| 5164 | "handle(0x%04x), no sas_device!!!\n", ioc->name, handle); |
| 5165 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5166 | return; |
| 5167 | } |
| 5168 | |
| 5169 | if (unlikely(sas_device->handle != handle)) { |
| 5170 | starget = sas_device->starget; |
| 5171 | sas_target_priv_data = starget->hostdata; |
| 5172 | starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)" |
| 5173 | " to (0x%04x)!!!\n", sas_device->handle, handle); |
| 5174 | sas_target_priv_data->handle = handle; |
| 5175 | sas_device->handle = handle; |
| 5176 | } |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5177 | |
| 5178 | /* check if device is present */ |
| 5179 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 5180 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 5181 | printk(MPT2SAS_ERR_FMT "device is not present " |
| 5182 | "handle(0x%04x), flags!!!\n", ioc->name, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5183 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5184 | return; |
| 5185 | } |
| 5186 | |
| 5187 | /* check if there were any issues with discovery */ |
| 5188 | if (_scsih_check_access_status(ioc, sas_address, handle, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5189 | sas_device_pg0.AccessStatus)) { |
| 5190 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5191 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5192 | } |
| 5193 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 5194 | _scsih_ublock_io_device(ioc, sas_address); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5195 | |
| 5196 | } |
| 5197 | |
| 5198 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5199 | * _scsih_add_device - creating sas device object |
| 5200 | * @ioc: per adapter object |
| 5201 | * @handle: sas device handle |
| 5202 | * @phy_num: phy number end device attached to |
| 5203 | * @is_pd: is this hidden raid component |
| 5204 | * |
| 5205 | * Creating end device object, stored in ioc->sas_device_list. |
| 5206 | * |
| 5207 | * Returns 0 for success, non-zero for failure. |
| 5208 | */ |
| 5209 | static int |
| 5210 | _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd) |
| 5211 | { |
| 5212 | Mpi2ConfigReply_t mpi_reply; |
| 5213 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 5214 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 5215 | struct _sas_device *sas_device; |
| 5216 | u32 ioc_status; |
| 5217 | __le64 sas_address; |
| 5218 | u32 device_info; |
| 5219 | unsigned long flags; |
| 5220 | |
| 5221 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 5222 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 5223 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5224 | ioc->name, __FILE__, __LINE__, __func__); |
| 5225 | return -1; |
| 5226 | } |
| 5227 | |
| 5228 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 5229 | MPI2_IOCSTATUS_MASK; |
| 5230 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5231 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5232 | ioc->name, __FILE__, __LINE__, __func__); |
| 5233 | return -1; |
| 5234 | } |
| 5235 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5236 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 5237 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5238 | /* check if device is present */ |
| 5239 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 5240 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 5241 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5242 | ioc->name, __FILE__, __LINE__, __func__); |
| 5243 | printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n", |
| 5244 | ioc->name, le16_to_cpu(sas_device_pg0.Flags)); |
| 5245 | return -1; |
| 5246 | } |
| 5247 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5248 | /* check if there were any issues with discovery */ |
| 5249 | if (_scsih_check_access_status(ioc, sas_address, handle, |
| 5250 | sas_device_pg0.AccessStatus)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5251 | return -1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5252 | |
| 5253 | /* check if this is end device */ |
| 5254 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 5255 | if (!(_scsih_is_end_device(device_info))) { |
| 5256 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5257 | ioc->name, __FILE__, __LINE__, __func__); |
| 5258 | return -1; |
| 5259 | } |
| 5260 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5261 | |
| 5262 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5263 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5264 | sas_address); |
| 5265 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5266 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5267 | if (sas_device) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5268 | return 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5269 | |
| 5270 | sas_device = kzalloc(sizeof(struct _sas_device), |
| 5271 | GFP_KERNEL); |
| 5272 | if (!sas_device) { |
| 5273 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5274 | ioc->name, __FILE__, __LINE__, __func__); |
| 5275 | return -1; |
| 5276 | } |
| 5277 | |
| 5278 | sas_device->handle = handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5279 | if (_scsih_get_sas_address(ioc, le16_to_cpu |
| 5280 | (sas_device_pg0.ParentDevHandle), |
| 5281 | &sas_device->sas_address_parent) != 0) |
| 5282 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5283 | ioc->name, __FILE__, __LINE__, __func__); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5284 | sas_device->enclosure_handle = |
| 5285 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 5286 | sas_device->slot = |
| 5287 | le16_to_cpu(sas_device_pg0.Slot); |
| 5288 | sas_device->device_info = device_info; |
| 5289 | sas_device->sas_address = sas_address; |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 5290 | sas_device->phy = sas_device_pg0.PhyNum; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5291 | |
| 5292 | /* get enclosure_logical_id */ |
Kashyap, Desai | 15052c9 | 2009-08-07 19:33:17 +0530 | [diff] [blame] | 5293 | if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0( |
| 5294 | ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 5295 | sas_device->enclosure_handle))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5296 | sas_device->enclosure_logical_id = |
| 5297 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5298 | |
| 5299 | /* get device name */ |
| 5300 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); |
| 5301 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5302 | if (ioc->wait_for_discovery_to_complete) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5303 | _scsih_sas_device_init_add(ioc, sas_device); |
| 5304 | else |
| 5305 | _scsih_sas_device_add(ioc, sas_device); |
| 5306 | |
| 5307 | return 0; |
| 5308 | } |
| 5309 | |
| 5310 | /** |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5311 | * _scsih_remove_device - removing sas device object |
| 5312 | * @ioc: per adapter object |
| 5313 | * @sas_device_delete: the sas_device object |
| 5314 | * |
| 5315 | * Return nothing. |
| 5316 | */ |
| 5317 | static void |
| 5318 | _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, |
| 5319 | struct _sas_device *sas_device) |
| 5320 | { |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5321 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 5322 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5323 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: " |
| 5324 | "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] | 5325 | sas_device->handle, (unsigned long long) |
| 5326 | sas_device->sas_address)); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5327 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5328 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 5329 | sas_target_priv_data = sas_device->starget->hostdata; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5330 | sas_target_priv_data->deleted = 1; |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 5331 | _scsih_ublock_io_device(ioc, sas_device->sas_address); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5332 | sas_target_priv_data->handle = |
| 5333 | MPT2SAS_INVALID_DEVICE_HANDLE; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5334 | } |
| 5335 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 5336 | if (!ioc->hide_drives) |
| 5337 | mpt2sas_transport_port_remove(ioc, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5338 | sas_device->sas_address, |
| 5339 | sas_device->sas_address_parent); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5340 | |
| 5341 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr" |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5342 | "(0x%016llx)\n", ioc->name, sas_device->handle, |
| 5343 | (unsigned long long) sas_device->sas_address); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5344 | |
| 5345 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: " |
| 5346 | "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] | 5347 | sas_device->handle, (unsigned long long) |
| 5348 | sas_device->sas_address)); |
| 5349 | kfree(sas_device); |
| 5350 | } |
| 5351 | /** |
| 5352 | * _scsih_device_remove_by_handle - removing device object by handle |
| 5353 | * @ioc: per adapter object |
| 5354 | * @handle: device handle |
| 5355 | * |
| 5356 | * Return nothing. |
| 5357 | */ |
| 5358 | static void |
| 5359 | _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 5360 | { |
| 5361 | struct _sas_device *sas_device; |
| 5362 | unsigned long flags; |
| 5363 | |
| 5364 | if (ioc->shost_recovery) |
| 5365 | return; |
| 5366 | |
| 5367 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5368 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 5369 | if (sas_device) |
| 5370 | list_del(&sas_device->list); |
| 5371 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5372 | if (sas_device) |
| 5373 | _scsih_remove_device(ioc, sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5374 | } |
| 5375 | |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5376 | /** |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5377 | * mpt2sas_device_remove_by_sas_address - removing device object by sas address |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5378 | * @ioc: per adapter object |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5379 | * @sas_address: device sas_address |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5380 | * |
| 5381 | * Return nothing. |
| 5382 | */ |
| 5383 | void |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5384 | mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 5385 | u64 sas_address) |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5386 | { |
| 5387 | struct _sas_device *sas_device; |
| 5388 | unsigned long flags; |
| 5389 | |
| 5390 | if (ioc->shost_recovery) |
| 5391 | return; |
| 5392 | |
| 5393 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5394 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5395 | sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5396 | if (sas_device) |
| 5397 | list_del(&sas_device->list); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5398 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5399 | if (sas_device) |
| 5400 | _scsih_remove_device(ioc, sas_device); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5401 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5402 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5403 | /** |
| 5404 | * _scsih_sas_topology_change_event_debug - debug for topology event |
| 5405 | * @ioc: per adapter object |
| 5406 | * @event_data: event data payload |
| 5407 | * Context: user. |
| 5408 | */ |
| 5409 | static void |
| 5410 | _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5411 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 5412 | { |
| 5413 | int i; |
| 5414 | u16 handle; |
| 5415 | u16 reason_code; |
| 5416 | u8 phy_number; |
| 5417 | char *status_str = NULL; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5418 | u8 link_rate, prev_link_rate; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5419 | |
| 5420 | switch (event_data->ExpStatus) { |
| 5421 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: |
| 5422 | status_str = "add"; |
| 5423 | break; |
| 5424 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: |
| 5425 | status_str = "remove"; |
| 5426 | break; |
| 5427 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5428 | case 0: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5429 | status_str = "responding"; |
| 5430 | break; |
| 5431 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: |
| 5432 | status_str = "remove delay"; |
| 5433 | break; |
| 5434 | default: |
| 5435 | status_str = "unknown status"; |
| 5436 | break; |
| 5437 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5438 | printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5439 | ioc->name, status_str); |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5440 | printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5441 | "start_phy(%02d), count(%d)\n", |
| 5442 | le16_to_cpu(event_data->ExpanderDevHandle), |
| 5443 | le16_to_cpu(event_data->EnclosureHandle), |
| 5444 | event_data->StartPhyNum, event_data->NumEntries); |
| 5445 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5446 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5447 | if (!handle) |
| 5448 | continue; |
| 5449 | phy_number = event_data->StartPhyNum + i; |
| 5450 | reason_code = event_data->PHY[i].PhyStatus & |
| 5451 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5452 | switch (reason_code) { |
| 5453 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5454 | status_str = "target add"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5455 | break; |
| 5456 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5457 | status_str = "target remove"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5458 | break; |
| 5459 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5460 | status_str = "delay target remove"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5461 | break; |
| 5462 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5463 | status_str = "link rate change"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5464 | break; |
| 5465 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5466 | status_str = "target responding"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5467 | break; |
| 5468 | default: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5469 | status_str = "unknown"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5470 | break; |
| 5471 | } |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5472 | link_rate = event_data->PHY[i].LinkRate >> 4; |
| 5473 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5474 | printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:" |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5475 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, |
| 5476 | handle, status_str, link_rate, prev_link_rate); |
| 5477 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5478 | } |
| 5479 | } |
| 5480 | #endif |
| 5481 | |
| 5482 | /** |
| 5483 | * _scsih_sas_topology_change_event - handle topology changes |
| 5484 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5485 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5486 | * Context: user. |
| 5487 | * |
| 5488 | */ |
| 5489 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5490 | _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5491 | struct fw_event_work *fw_event) |
| 5492 | { |
| 5493 | int i; |
| 5494 | u16 parent_handle, handle; |
| 5495 | u16 reason_code; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5496 | u8 phy_number, max_phys; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5497 | struct _sas_node *sas_expander; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5498 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5499 | unsigned long flags; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5500 | u8 link_rate, prev_link_rate; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5501 | Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5502 | |
| 5503 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5504 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5505 | _scsih_sas_topology_change_event_debug(ioc, event_data); |
| 5506 | #endif |
| 5507 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5508 | if (ioc->remove_host || ioc->pci_error_recovery) |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5509 | return; |
| 5510 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5511 | if (!ioc->sas_hba.num_phys) |
| 5512 | _scsih_sas_host_add(ioc); |
| 5513 | else |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5514 | _scsih_sas_host_refresh(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5515 | |
| 5516 | if (fw_event->ignore) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5517 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5518 | "event\n", ioc->name)); |
| 5519 | return; |
| 5520 | } |
| 5521 | |
| 5522 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 5523 | |
| 5524 | /* handle expander add */ |
| 5525 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) |
| 5526 | if (_scsih_expander_add(ioc, parent_handle) != 0) |
| 5527 | return; |
| 5528 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5529 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 5530 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 5531 | parent_handle); |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5532 | if (sas_expander) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5533 | sas_address = sas_expander->sas_address; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5534 | max_phys = sas_expander->num_phys; |
| 5535 | } else if (parent_handle < ioc->sas_hba.num_phys) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5536 | sas_address = ioc->sas_hba.sas_address; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5537 | max_phys = ioc->sas_hba.num_phys; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5538 | } else { |
| 5539 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5540 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5541 | } |
| 5542 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5543 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5544 | /* handle siblings events */ |
| 5545 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5546 | if (fw_event->ignore) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5547 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5548 | "expander event\n", ioc->name)); |
| 5549 | return; |
| 5550 | } |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 5551 | if (ioc->shost_recovery || ioc->remove_host || |
| 5552 | ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 5553 | return; |
Kashyap, Desai | 308609c | 2009-09-14 11:07:23 +0530 | [diff] [blame] | 5554 | phy_number = event_data->StartPhyNum + i; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5555 | if (phy_number >= max_phys) |
| 5556 | continue; |
Kashyap, Desai | 308609c | 2009-09-14 11:07:23 +0530 | [diff] [blame] | 5557 | reason_code = event_data->PHY[i].PhyStatus & |
| 5558 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5559 | if ((event_data->PHY[i].PhyStatus & |
| 5560 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != |
| 5561 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5562 | continue; |
| 5563 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5564 | if (!handle) |
| 5565 | continue; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5566 | link_rate = event_data->PHY[i].LinkRate >> 4; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5567 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5568 | switch (reason_code) { |
| 5569 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5570 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5571 | if (ioc->shost_recovery) |
| 5572 | break; |
| 5573 | |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5574 | if (link_rate == prev_link_rate) |
| 5575 | break; |
| 5576 | |
| 5577 | mpt2sas_transport_update_links(ioc, sas_address, |
| 5578 | handle, phy_number, link_rate); |
| 5579 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5580 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 5581 | break; |
| 5582 | |
| 5583 | _scsih_check_device(ioc, handle); |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5584 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5585 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5586 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5587 | if (ioc->shost_recovery) |
| 5588 | break; |
| 5589 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5590 | mpt2sas_transport_update_links(ioc, sas_address, |
| 5591 | handle, phy_number, link_rate); |
| 5592 | |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5593 | _scsih_add_device(ioc, handle, phy_number, 0); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5594 | break; |
| 5595 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5596 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5597 | _scsih_device_remove_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5598 | break; |
| 5599 | } |
| 5600 | } |
| 5601 | |
| 5602 | /* handle expander removal */ |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5603 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && |
| 5604 | sas_expander) |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5605 | mpt2sas_expander_remove(ioc, sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5606 | |
| 5607 | } |
| 5608 | |
| 5609 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5610 | /** |
| 5611 | * _scsih_sas_device_status_change_event_debug - debug for device event |
| 5612 | * @event_data: event data payload |
| 5613 | * Context: user. |
| 5614 | * |
| 5615 | * Return nothing. |
| 5616 | */ |
| 5617 | static void |
| 5618 | _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5619 | Mpi2EventDataSasDeviceStatusChange_t *event_data) |
| 5620 | { |
| 5621 | char *reason_str = NULL; |
| 5622 | |
| 5623 | switch (event_data->ReasonCode) { |
| 5624 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: |
| 5625 | reason_str = "smart data"; |
| 5626 | break; |
| 5627 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: |
| 5628 | reason_str = "unsupported device discovered"; |
| 5629 | break; |
| 5630 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: |
| 5631 | reason_str = "internal device reset"; |
| 5632 | break; |
| 5633 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: |
| 5634 | reason_str = "internal task abort"; |
| 5635 | break; |
| 5636 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: |
| 5637 | reason_str = "internal task abort set"; |
| 5638 | break; |
| 5639 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: |
| 5640 | reason_str = "internal clear task set"; |
| 5641 | break; |
| 5642 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: |
| 5643 | reason_str = "internal query task"; |
| 5644 | break; |
| 5645 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: |
| 5646 | reason_str = "sata init failure"; |
| 5647 | break; |
| 5648 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: |
| 5649 | reason_str = "internal device reset complete"; |
| 5650 | break; |
| 5651 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: |
| 5652 | reason_str = "internal task abort complete"; |
| 5653 | break; |
| 5654 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: |
| 5655 | reason_str = "internal async notification"; |
| 5656 | break; |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 5657 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5658 | reason_str = "expander reduced functionality"; |
| 5659 | break; |
| 5660 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5661 | reason_str = "expander reduced functionality complete"; |
| 5662 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5663 | default: |
| 5664 | reason_str = "unknown reason"; |
| 5665 | break; |
| 5666 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5667 | printk(MPT2SAS_INFO_FMT "device status change: (%s)\n" |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5668 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", |
| 5669 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), |
| 5670 | (unsigned long long)le64_to_cpu(event_data->SASAddress), |
| 5671 | le16_to_cpu(event_data->TaskTag)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5672 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5673 | 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] | 5674 | event_data->ASC, event_data->ASCQ); |
| 5675 | printk(KERN_INFO "\n"); |
| 5676 | } |
| 5677 | #endif |
| 5678 | |
| 5679 | /** |
| 5680 | * _scsih_sas_device_status_change_event - handle device status change |
| 5681 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5682 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5683 | * Context: user. |
| 5684 | * |
| 5685 | * Return nothing. |
| 5686 | */ |
| 5687 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5688 | _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 5689 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5690 | { |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5691 | struct MPT2SAS_TARGET *target_priv_data; |
| 5692 | struct _sas_device *sas_device; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 5693 | u64 sas_address; |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5694 | unsigned long flags; |
| 5695 | Mpi2EventDataSasDeviceStatusChange_t *event_data = |
| 5696 | fw_event->event_data; |
| 5697 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5698 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5699 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5700 | _scsih_sas_device_status_change_event_debug(ioc, |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5701 | event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5702 | #endif |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5703 | |
Kashyap, Desai | efe82a1 | 2011-01-04 11:34:17 +0530 | [diff] [blame] | 5704 | /* In MPI Revision K (0xC), the internal device reset complete was |
| 5705 | * implemented, so avoid setting tm_busy flag for older firmware. |
| 5706 | */ |
| 5707 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) |
| 5708 | return; |
| 5709 | |
Kashyap, Desai | f891dcf | 2010-03-17 16:22:21 +0530 | [diff] [blame] | 5710 | if (event_data->ReasonCode != |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5711 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && |
Kashyap, Desai | f891dcf | 2010-03-17 16:22:21 +0530 | [diff] [blame] | 5712 | event_data->ReasonCode != |
| 5713 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5714 | return; |
| 5715 | |
| 5716 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5717 | sas_address = le64_to_cpu(event_data->SASAddress); |
| 5718 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5719 | sas_address); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5720 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5721 | if (!sas_device || !sas_device->starget) { |
| 5722 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5723 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5724 | } |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5725 | |
| 5726 | target_priv_data = sas_device->starget->hostdata; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5727 | if (!target_priv_data) { |
| 5728 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5729 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5730 | } |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5731 | |
| 5732 | if (event_data->ReasonCode == |
| 5733 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) |
| 5734 | target_priv_data->tm_busy = 1; |
| 5735 | else |
| 5736 | target_priv_data->tm_busy = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 5737 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5738 | } |
| 5739 | |
| 5740 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5741 | /** |
| 5742 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event |
| 5743 | * @ioc: per adapter object |
| 5744 | * @event_data: event data payload |
| 5745 | * Context: user. |
| 5746 | * |
| 5747 | * Return nothing. |
| 5748 | */ |
| 5749 | static void |
| 5750 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5751 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) |
| 5752 | { |
| 5753 | char *reason_str = NULL; |
| 5754 | |
| 5755 | switch (event_data->ReasonCode) { |
| 5756 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: |
| 5757 | reason_str = "enclosure add"; |
| 5758 | break; |
| 5759 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: |
| 5760 | reason_str = "enclosure remove"; |
| 5761 | break; |
| 5762 | default: |
| 5763 | reason_str = "unknown reason"; |
| 5764 | break; |
| 5765 | } |
| 5766 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5767 | printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5768 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" |
| 5769 | " number slots(%d)\n", ioc->name, reason_str, |
| 5770 | le16_to_cpu(event_data->EnclosureHandle), |
| 5771 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), |
| 5772 | le16_to_cpu(event_data->StartSlot)); |
| 5773 | } |
| 5774 | #endif |
| 5775 | |
| 5776 | /** |
| 5777 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events |
| 5778 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5779 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5780 | * Context: user. |
| 5781 | * |
| 5782 | * Return nothing. |
| 5783 | */ |
| 5784 | static void |
| 5785 | _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5786 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5787 | { |
| 5788 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5789 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5790 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5791 | fw_event->event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5792 | #endif |
| 5793 | } |
| 5794 | |
| 5795 | /** |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 5796 | * _scsih_sas_broadcast_primitive_event - handle broadcast events |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5797 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5798 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5799 | * Context: user. |
| 5800 | * |
| 5801 | * Return nothing. |
| 5802 | */ |
| 5803 | static void |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 5804 | _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5805 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5806 | { |
| 5807 | struct scsi_cmnd *scmd; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5808 | struct scsi_device *sdev; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5809 | u16 smid, handle; |
| 5810 | u32 lun; |
| 5811 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 5812 | u32 termination_count; |
| 5813 | u32 query_count; |
| 5814 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5815 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data; |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 5816 | u16 ioc_status; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5817 | unsigned long flags; |
| 5818 | int r; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5819 | u8 max_retries = 0; |
| 5820 | u8 task_abort_retries; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5821 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5822 | mutex_lock(&ioc->tm_cmds.mutex); |
| 5823 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: phy number(%d), " |
| 5824 | "width(%d)\n", ioc->name, __func__, event_data->PhyNum, |
| 5825 | event_data->PortWidth)); |
| 5826 | |
| 5827 | _scsih_block_io_all_device(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5828 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5829 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5830 | mpi_reply = ioc->tm_cmds.reply; |
| 5831 | broadcast_aen_retry: |
| 5832 | |
| 5833 | /* sanity checks for retrying this loop */ |
| 5834 | if (max_retries++ == 5) { |
| 5835 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n", |
| 5836 | ioc->name, __func__)); |
| 5837 | goto out; |
| 5838 | } else if (max_retries > 1) |
| 5839 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n", |
| 5840 | ioc->name, __func__, max_retries - 1)); |
| 5841 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5842 | termination_count = 0; |
| 5843 | query_count = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 5844 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5845 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5846 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5847 | scmd = _scsih_scsi_lookup_get(ioc, smid); |
| 5848 | if (!scmd) |
| 5849 | continue; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5850 | sdev = scmd->device; |
| 5851 | sas_device_priv_data = sdev->hostdata; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5852 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) |
| 5853 | continue; |
| 5854 | /* skip hidden raid components */ |
| 5855 | if (sas_device_priv_data->sas_target->flags & |
| 5856 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 5857 | continue; |
| 5858 | /* skip volumes */ |
| 5859 | if (sas_device_priv_data->sas_target->flags & |
| 5860 | MPT_TARGET_FLAGS_VOLUME) |
| 5861 | continue; |
| 5862 | |
| 5863 | handle = sas_device_priv_data->sas_target->handle; |
| 5864 | lun = sas_device_priv_data->lun; |
| 5865 | query_count++; |
| 5866 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5867 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5868 | goto out; |
| 5869 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5870 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5871 | r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun, |
| 5872 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0, |
| 5873 | TM_MUTEX_OFF); |
| 5874 | if (r == FAILED) { |
| 5875 | sdev_printk(KERN_WARNING, sdev, |
| 5876 | "mpt2sas_scsih_issue_tm: FAILED when sending " |
| 5877 | "QUERY_TASK: scmd(%p)\n", scmd); |
| 5878 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5879 | goto broadcast_aen_retry; |
| 5880 | } |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 5881 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) |
| 5882 | & MPI2_IOCSTATUS_MASK; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5883 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5884 | sdev_printk(KERN_WARNING, sdev, "query task: FAILED " |
| 5885 | "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status, |
| 5886 | scmd); |
| 5887 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5888 | goto broadcast_aen_retry; |
| 5889 | } |
| 5890 | |
| 5891 | /* see if IO is still owned by IOC and target */ |
| 5892 | if (mpi_reply->ResponseCode == |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5893 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || |
| 5894 | mpi_reply->ResponseCode == |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5895 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5896 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5897 | continue; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5898 | } |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5899 | task_abort_retries = 0; |
| 5900 | tm_retry: |
| 5901 | if (task_abort_retries++ == 60) { |
| 5902 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 5903 | "%s: ABORT_TASK: giving up\n", ioc->name, |
| 5904 | __func__)); |
| 5905 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5906 | goto broadcast_aen_retry; |
| 5907 | } |
| 5908 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5909 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5910 | goto out_no_lock; |
| 5911 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5912 | r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, |
| 5913 | sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5914 | scmd->serial_number, TM_MUTEX_OFF); |
| 5915 | if (r == FAILED) { |
| 5916 | sdev_printk(KERN_WARNING, sdev, |
| 5917 | "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : " |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5918 | "scmd(%p)\n", scmd); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5919 | goto tm_retry; |
| 5920 | } |
| 5921 | |
| 5922 | if (task_abort_retries > 1) |
| 5923 | sdev_printk(KERN_WARNING, sdev, |
| 5924 | "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" |
| 5925 | " scmd(%p)\n", |
| 5926 | task_abort_retries - 1, scmd); |
| 5927 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5928 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5929 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5930 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5931 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5932 | if (ioc->broadcast_aen_pending) { |
| 5933 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to" |
| 5934 | " pending AEN\n", ioc->name, __func__)); |
| 5935 | ioc->broadcast_aen_pending = 0; |
| 5936 | goto broadcast_aen_retry; |
| 5937 | } |
| 5938 | |
| 5939 | out: |
| 5940 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 5941 | out_no_lock: |
| 5942 | |
| 5943 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5944 | "%s - exit, query_count = %d termination_count = %d\n", |
| 5945 | ioc->name, __func__, query_count, termination_count)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5946 | |
| 5947 | ioc->broadcast_aen_busy = 0; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5948 | if (!ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5949 | _scsih_ublock_io_all_device(ioc); |
| 5950 | mutex_unlock(&ioc->tm_cmds.mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5951 | } |
| 5952 | |
| 5953 | /** |
| 5954 | * _scsih_sas_discovery_event - handle discovery events |
| 5955 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5956 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5957 | * Context: user. |
| 5958 | * |
| 5959 | * Return nothing. |
| 5960 | */ |
| 5961 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5962 | _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc, |
| 5963 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5964 | { |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5965 | Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data; |
| 5966 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5967 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5968 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5969 | printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5970 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? |
| 5971 | "start" : "stop"); |
| 5972 | if (event_data->DiscoveryStatus) |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 5973 | printk("discovery_status(0x%08x)", |
| 5974 | le32_to_cpu(event_data->DiscoveryStatus)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5975 | printk("\n"); |
| 5976 | } |
| 5977 | #endif |
| 5978 | |
| 5979 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 5980 | !ioc->sas_hba.num_phys) { |
| 5981 | if (disable_discovery > 0 && ioc->shost_recovery) { |
| 5982 | /* Wait for the reset to complete */ |
| 5983 | while (ioc->shost_recovery) |
| 5984 | ssleep(1); |
| 5985 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5986 | _scsih_sas_host_add(ioc); |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 5987 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5988 | } |
| 5989 | |
| 5990 | /** |
| 5991 | * _scsih_reprobe_lun - reprobing lun |
| 5992 | * @sdev: scsi device struct |
| 5993 | * @no_uld_attach: sdev->no_uld_attach flag setting |
| 5994 | * |
| 5995 | **/ |
| 5996 | static void |
| 5997 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) |
| 5998 | { |
| 5999 | int rc; |
| 6000 | |
| 6001 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
| 6002 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", |
| 6003 | sdev->no_uld_attach ? "hidding" : "exposing"); |
| 6004 | rc = scsi_device_reprobe(sdev); |
| 6005 | } |
| 6006 | |
| 6007 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6008 | * _scsih_sas_volume_add - add new volume |
| 6009 | * @ioc: per adapter object |
| 6010 | * @element: IR config element data |
| 6011 | * Context: user. |
| 6012 | * |
| 6013 | * Return nothing. |
| 6014 | */ |
| 6015 | static void |
| 6016 | _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc, |
| 6017 | Mpi2EventIrConfigElement_t *element) |
| 6018 | { |
| 6019 | struct _raid_device *raid_device; |
| 6020 | unsigned long flags; |
| 6021 | u64 wwid; |
| 6022 | u16 handle = le16_to_cpu(element->VolDevHandle); |
| 6023 | int rc; |
| 6024 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6025 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 6026 | if (!wwid) { |
| 6027 | printk(MPT2SAS_ERR_FMT |
| 6028 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6029 | __FILE__, __LINE__, __func__); |
| 6030 | return; |
| 6031 | } |
| 6032 | |
| 6033 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6034 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); |
| 6035 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6036 | |
| 6037 | if (raid_device) |
| 6038 | return; |
| 6039 | |
| 6040 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 6041 | if (!raid_device) { |
| 6042 | printk(MPT2SAS_ERR_FMT |
| 6043 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6044 | __FILE__, __LINE__, __func__); |
| 6045 | return; |
| 6046 | } |
| 6047 | |
| 6048 | raid_device->id = ioc->sas_id++; |
| 6049 | raid_device->channel = RAID_CHANNEL; |
| 6050 | raid_device->handle = handle; |
| 6051 | raid_device->wwid = wwid; |
| 6052 | _scsih_raid_device_add(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6053 | if (!ioc->wait_for_discovery_to_complete) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6054 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 6055 | raid_device->id, 0); |
| 6056 | if (rc) |
| 6057 | _scsih_raid_device_remove(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6058 | } else { |
| 6059 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6060 | _scsih_determine_boot_device(ioc, raid_device, 1); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6061 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6062 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6063 | } |
| 6064 | |
| 6065 | /** |
| 6066 | * _scsih_sas_volume_delete - delete volume |
| 6067 | * @ioc: per adapter object |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6068 | * @handle: volume device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6069 | * Context: user. |
| 6070 | * |
| 6071 | * Return nothing. |
| 6072 | */ |
| 6073 | static void |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6074 | _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6075 | { |
| 6076 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6077 | unsigned long flags; |
| 6078 | struct MPT2SAS_TARGET *sas_target_priv_data; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6079 | struct scsi_target *starget = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6080 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6081 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6082 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6083 | if (raid_device) { |
| 6084 | if (raid_device->starget) { |
| 6085 | starget = raid_device->starget; |
| 6086 | sas_target_priv_data = starget->hostdata; |
| 6087 | sas_target_priv_data->deleted = 1; |
| 6088 | } |
| 6089 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" |
| 6090 | "(0x%016llx)\n", ioc->name, raid_device->handle, |
| 6091 | (unsigned long long) raid_device->wwid); |
| 6092 | list_del(&raid_device->list); |
| 6093 | kfree(raid_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6094 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6095 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6096 | if (starget) |
| 6097 | scsi_remove_target(&starget->dev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6098 | } |
| 6099 | |
| 6100 | /** |
| 6101 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX |
| 6102 | * @ioc: per adapter object |
| 6103 | * @element: IR config element data |
| 6104 | * Context: user. |
| 6105 | * |
| 6106 | * Return nothing. |
| 6107 | */ |
| 6108 | static void |
| 6109 | _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc, |
| 6110 | Mpi2EventIrConfigElement_t *element) |
| 6111 | { |
| 6112 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6113 | struct scsi_target *starget = NULL; |
| 6114 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6115 | unsigned long flags; |
| 6116 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 6117 | |
| 6118 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6119 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6120 | if (sas_device) { |
| 6121 | sas_device->volume_handle = 0; |
| 6122 | sas_device->volume_wwid = 0; |
| 6123 | clear_bit(handle, ioc->pd_handles); |
| 6124 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 6125 | starget = sas_device->starget; |
| 6126 | sas_target_priv_data = starget->hostdata; |
| 6127 | sas_target_priv_data->flags &= |
| 6128 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 6129 | } |
| 6130 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6131 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6132 | if (!sas_device) |
| 6133 | return; |
| 6134 | |
| 6135 | /* exposing raid component */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6136 | if (starget) |
| 6137 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6138 | } |
| 6139 | |
| 6140 | /** |
| 6141 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX |
| 6142 | * @ioc: per adapter object |
| 6143 | * @element: IR config element data |
| 6144 | * Context: user. |
| 6145 | * |
| 6146 | * Return nothing. |
| 6147 | */ |
| 6148 | static void |
| 6149 | _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc, |
| 6150 | Mpi2EventIrConfigElement_t *element) |
| 6151 | { |
| 6152 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6153 | struct scsi_target *starget = NULL; |
| 6154 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6155 | unsigned long flags; |
| 6156 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6157 | u16 volume_handle = 0; |
| 6158 | u64 volume_wwid = 0; |
| 6159 | |
| 6160 | mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle); |
| 6161 | if (volume_handle) |
| 6162 | mpt2sas_config_get_volume_wwid(ioc, volume_handle, |
| 6163 | &volume_wwid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6164 | |
| 6165 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6166 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6167 | if (sas_device) { |
| 6168 | set_bit(handle, ioc->pd_handles); |
| 6169 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 6170 | starget = sas_device->starget; |
| 6171 | sas_target_priv_data = starget->hostdata; |
| 6172 | sas_target_priv_data->flags |= |
| 6173 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 6174 | sas_device->volume_handle = volume_handle; |
| 6175 | sas_device->volume_wwid = volume_wwid; |
| 6176 | } |
| 6177 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6178 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6179 | if (!sas_device) |
| 6180 | return; |
| 6181 | |
| 6182 | /* hiding raid component */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6183 | if (starget) |
| 6184 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6185 | } |
| 6186 | |
| 6187 | /** |
| 6188 | * _scsih_sas_pd_delete - delete pd component |
| 6189 | * @ioc: per adapter object |
| 6190 | * @element: IR config element data |
| 6191 | * Context: user. |
| 6192 | * |
| 6193 | * Return nothing. |
| 6194 | */ |
| 6195 | static void |
| 6196 | _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc, |
| 6197 | Mpi2EventIrConfigElement_t *element) |
| 6198 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6199 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 6200 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6201 | _scsih_device_remove_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6202 | } |
| 6203 | |
| 6204 | /** |
| 6205 | * _scsih_sas_pd_add - remove pd component |
| 6206 | * @ioc: per adapter object |
| 6207 | * @element: IR config element data |
| 6208 | * Context: user. |
| 6209 | * |
| 6210 | * Return nothing. |
| 6211 | */ |
| 6212 | static void |
| 6213 | _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc, |
| 6214 | Mpi2EventIrConfigElement_t *element) |
| 6215 | { |
| 6216 | struct _sas_device *sas_device; |
| 6217 | unsigned long flags; |
| 6218 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6219 | Mpi2ConfigReply_t mpi_reply; |
| 6220 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6221 | u32 ioc_status; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6222 | u64 sas_address; |
| 6223 | u16 parent_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6224 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6225 | set_bit(handle, ioc->pd_handles); |
| 6226 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6227 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6228 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6229 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6230 | if (sas_device) |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6231 | return; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6232 | |
| 6233 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 6234 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 6235 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6236 | ioc->name, __FILE__, __LINE__, __func__); |
| 6237 | return; |
| 6238 | } |
| 6239 | |
| 6240 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6241 | MPI2_IOCSTATUS_MASK; |
| 6242 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6243 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6244 | ioc->name, __FILE__, __LINE__, __func__); |
| 6245 | return; |
| 6246 | } |
| 6247 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6248 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6249 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 6250 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 6251 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6252 | |
| 6253 | _scsih_add_device(ioc, handle, 0, 1); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6254 | } |
| 6255 | |
| 6256 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 6257 | /** |
| 6258 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events |
| 6259 | * @ioc: per adapter object |
| 6260 | * @event_data: event data payload |
| 6261 | * Context: user. |
| 6262 | * |
| 6263 | * Return nothing. |
| 6264 | */ |
| 6265 | static void |
| 6266 | _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 6267 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 6268 | { |
| 6269 | Mpi2EventIrConfigElement_t *element; |
| 6270 | u8 element_type; |
| 6271 | int i; |
| 6272 | char *reason_str = NULL, *element_str = NULL; |
| 6273 | |
| 6274 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 6275 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6276 | printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6277 | ioc->name, (le32_to_cpu(event_data->Flags) & |
| 6278 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? |
| 6279 | "foreign" : "native", event_data->NumElements); |
| 6280 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6281 | switch (element->ReasonCode) { |
| 6282 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
| 6283 | reason_str = "add"; |
| 6284 | break; |
| 6285 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
| 6286 | reason_str = "remove"; |
| 6287 | break; |
| 6288 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: |
| 6289 | reason_str = "no change"; |
| 6290 | break; |
| 6291 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
| 6292 | reason_str = "hide"; |
| 6293 | break; |
| 6294 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
| 6295 | reason_str = "unhide"; |
| 6296 | break; |
| 6297 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 6298 | reason_str = "volume_created"; |
| 6299 | break; |
| 6300 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 6301 | reason_str = "volume_deleted"; |
| 6302 | break; |
| 6303 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
| 6304 | reason_str = "pd_created"; |
| 6305 | break; |
| 6306 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
| 6307 | reason_str = "pd_deleted"; |
| 6308 | break; |
| 6309 | default: |
| 6310 | reason_str = "unknown reason"; |
| 6311 | break; |
| 6312 | } |
| 6313 | element_type = le16_to_cpu(element->ElementFlags) & |
| 6314 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; |
| 6315 | switch (element_type) { |
| 6316 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: |
| 6317 | element_str = "volume"; |
| 6318 | break; |
| 6319 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: |
| 6320 | element_str = "phys disk"; |
| 6321 | break; |
| 6322 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: |
| 6323 | element_str = "hot spare"; |
| 6324 | break; |
| 6325 | default: |
| 6326 | element_str = "unknown element"; |
| 6327 | break; |
| 6328 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6329 | printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6330 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, |
| 6331 | reason_str, le16_to_cpu(element->VolDevHandle), |
| 6332 | le16_to_cpu(element->PhysDiskDevHandle), |
| 6333 | element->PhysDiskNum); |
| 6334 | } |
| 6335 | } |
| 6336 | #endif |
| 6337 | |
| 6338 | /** |
| 6339 | * _scsih_sas_ir_config_change_event - handle ir configuration change events |
| 6340 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6341 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6342 | * Context: user. |
| 6343 | * |
| 6344 | * Return nothing. |
| 6345 | */ |
| 6346 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6347 | _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 6348 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6349 | { |
| 6350 | Mpi2EventIrConfigElement_t *element; |
| 6351 | int i; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6352 | u8 foreign_config; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6353 | Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6354 | |
| 6355 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6356 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6357 | && !ioc->hide_ir_msg) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6358 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
| 6359 | |
| 6360 | #endif |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6361 | |
| 6362 | if (ioc->shost_recovery) |
| 6363 | return; |
| 6364 | |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6365 | foreign_config = (le32_to_cpu(event_data->Flags) & |
| 6366 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6367 | |
| 6368 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 6369 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6370 | |
| 6371 | switch (element->ReasonCode) { |
| 6372 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 6373 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6374 | if (!foreign_config) |
| 6375 | _scsih_sas_volume_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6376 | break; |
| 6377 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 6378 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6379 | if (!foreign_config) |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6380 | _scsih_sas_volume_delete(ioc, |
| 6381 | le16_to_cpu(element->VolDevHandle)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6382 | break; |
| 6383 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6384 | if (!ioc->is_warpdrive) |
| 6385 | _scsih_sas_pd_hide(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6386 | break; |
| 6387 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6388 | if (!ioc->is_warpdrive) |
| 6389 | _scsih_sas_pd_expose(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6390 | break; |
| 6391 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6392 | if (!ioc->is_warpdrive) |
| 6393 | _scsih_sas_pd_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6394 | break; |
| 6395 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6396 | if (!ioc->is_warpdrive) |
| 6397 | _scsih_sas_pd_delete(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6398 | break; |
| 6399 | } |
| 6400 | } |
| 6401 | } |
| 6402 | |
| 6403 | /** |
| 6404 | * _scsih_sas_ir_volume_event - IR volume event |
| 6405 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6406 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6407 | * Context: user. |
| 6408 | * |
| 6409 | * Return nothing. |
| 6410 | */ |
| 6411 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6412 | _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc, |
| 6413 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6414 | { |
| 6415 | u64 wwid; |
| 6416 | unsigned long flags; |
| 6417 | struct _raid_device *raid_device; |
| 6418 | u16 handle; |
| 6419 | u32 state; |
| 6420 | int rc; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6421 | Mpi2EventDataIrVolume_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6422 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6423 | if (ioc->shost_recovery) |
| 6424 | return; |
| 6425 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6426 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 6427 | return; |
| 6428 | |
| 6429 | handle = le16_to_cpu(event_data->VolDevHandle); |
| 6430 | state = le32_to_cpu(event_data->NewValue); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6431 | if (!ioc->hide_ir_msg) |
| 6432 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " |
| 6433 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 6434 | le32_to_cpu(event_data->PreviousValue), state)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6435 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6436 | switch (state) { |
| 6437 | case MPI2_RAID_VOL_STATE_MISSING: |
| 6438 | case MPI2_RAID_VOL_STATE_FAILED: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6439 | _scsih_sas_volume_delete(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6440 | break; |
| 6441 | |
| 6442 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 6443 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 6444 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6445 | |
| 6446 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6447 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 6448 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6449 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6450 | if (raid_device) |
| 6451 | break; |
| 6452 | |
| 6453 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 6454 | if (!wwid) { |
| 6455 | printk(MPT2SAS_ERR_FMT |
| 6456 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6457 | __FILE__, __LINE__, __func__); |
| 6458 | break; |
| 6459 | } |
| 6460 | |
| 6461 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 6462 | if (!raid_device) { |
| 6463 | printk(MPT2SAS_ERR_FMT |
| 6464 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6465 | __FILE__, __LINE__, __func__); |
| 6466 | break; |
| 6467 | } |
| 6468 | |
| 6469 | raid_device->id = ioc->sas_id++; |
| 6470 | raid_device->channel = RAID_CHANNEL; |
| 6471 | raid_device->handle = handle; |
| 6472 | raid_device->wwid = wwid; |
| 6473 | _scsih_raid_device_add(ioc, raid_device); |
| 6474 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 6475 | raid_device->id, 0); |
| 6476 | if (rc) |
| 6477 | _scsih_raid_device_remove(ioc, raid_device); |
| 6478 | break; |
| 6479 | |
| 6480 | case MPI2_RAID_VOL_STATE_INITIALIZING: |
| 6481 | default: |
| 6482 | break; |
| 6483 | } |
| 6484 | } |
| 6485 | |
| 6486 | /** |
| 6487 | * _scsih_sas_ir_physical_disk_event - PD event |
| 6488 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6489 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6490 | * Context: user. |
| 6491 | * |
| 6492 | * Return nothing. |
| 6493 | */ |
| 6494 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6495 | _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc, |
| 6496 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6497 | { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6498 | u16 handle, parent_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6499 | u32 state; |
| 6500 | struct _sas_device *sas_device; |
| 6501 | unsigned long flags; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6502 | Mpi2ConfigReply_t mpi_reply; |
| 6503 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6504 | u32 ioc_status; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6505 | Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6506 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6507 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6508 | if (ioc->shost_recovery) |
| 6509 | return; |
| 6510 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6511 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) |
| 6512 | return; |
| 6513 | |
| 6514 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); |
| 6515 | state = le32_to_cpu(event_data->NewValue); |
| 6516 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6517 | if (!ioc->hide_ir_msg) |
| 6518 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " |
| 6519 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 6520 | le32_to_cpu(event_data->PreviousValue), state)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6521 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6522 | switch (state) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6523 | case MPI2_RAID_PD_STATE_ONLINE: |
| 6524 | case MPI2_RAID_PD_STATE_DEGRADED: |
| 6525 | case MPI2_RAID_PD_STATE_REBUILDING: |
| 6526 | case MPI2_RAID_PD_STATE_OPTIMAL: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6527 | case MPI2_RAID_PD_STATE_HOT_SPARE: |
| 6528 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6529 | if (!ioc->is_warpdrive) |
| 6530 | set_bit(handle, ioc->pd_handles); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6531 | |
| 6532 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6533 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6534 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6535 | |
| 6536 | if (sas_device) |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6537 | return; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6538 | |
| 6539 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6540 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 6541 | handle))) { |
| 6542 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6543 | ioc->name, __FILE__, __LINE__, __func__); |
| 6544 | return; |
| 6545 | } |
| 6546 | |
| 6547 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6548 | MPI2_IOCSTATUS_MASK; |
| 6549 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6550 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6551 | ioc->name, __FILE__, __LINE__, __func__); |
| 6552 | return; |
| 6553 | } |
| 6554 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6555 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6556 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 6557 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 6558 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6559 | |
| 6560 | _scsih_add_device(ioc, handle, 0, 1); |
| 6561 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6562 | break; |
| 6563 | |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6564 | case MPI2_RAID_PD_STATE_OFFLINE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6565 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: |
| 6566 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6567 | default: |
| 6568 | break; |
| 6569 | } |
| 6570 | } |
| 6571 | |
| 6572 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 6573 | /** |
| 6574 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event |
| 6575 | * @ioc: per adapter object |
| 6576 | * @event_data: event data payload |
| 6577 | * Context: user. |
| 6578 | * |
| 6579 | * Return nothing. |
| 6580 | */ |
| 6581 | static void |
| 6582 | _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 6583 | Mpi2EventDataIrOperationStatus_t *event_data) |
| 6584 | { |
| 6585 | char *reason_str = NULL; |
| 6586 | |
| 6587 | switch (event_data->RAIDOperation) { |
| 6588 | case MPI2_EVENT_IR_RAIDOP_RESYNC: |
| 6589 | reason_str = "resync"; |
| 6590 | break; |
| 6591 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: |
| 6592 | reason_str = "online capacity expansion"; |
| 6593 | break; |
| 6594 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: |
| 6595 | reason_str = "consistency check"; |
| 6596 | break; |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 6597 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: |
| 6598 | reason_str = "background init"; |
| 6599 | break; |
| 6600 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: |
| 6601 | reason_str = "make data consistent"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6602 | break; |
| 6603 | } |
| 6604 | |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 6605 | if (!reason_str) |
| 6606 | return; |
| 6607 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6608 | printk(MPT2SAS_INFO_FMT "raid operational status: (%s)" |
| 6609 | "\thandle(0x%04x), percent complete(%d)\n", |
| 6610 | ioc->name, reason_str, |
| 6611 | le16_to_cpu(event_data->VolDevHandle), |
| 6612 | event_data->PercentComplete); |
| 6613 | } |
| 6614 | #endif |
| 6615 | |
| 6616 | /** |
| 6617 | * _scsih_sas_ir_operation_status_event - handle RAID operation events |
| 6618 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6619 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6620 | * Context: user. |
| 6621 | * |
| 6622 | * Return nothing. |
| 6623 | */ |
| 6624 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6625 | _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc, |
| 6626 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6627 | { |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6628 | Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data; |
| 6629 | static struct _raid_device *raid_device; |
| 6630 | unsigned long flags; |
| 6631 | u16 handle; |
| 6632 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6633 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6634 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6635 | && !ioc->hide_ir_msg) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6636 | _scsih_sas_ir_operation_status_event_debug(ioc, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6637 | event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6638 | #endif |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6639 | |
| 6640 | /* code added for raid transport support */ |
| 6641 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { |
| 6642 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6643 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6644 | handle = le16_to_cpu(event_data->VolDevHandle); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6645 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6646 | if (raid_device) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6647 | raid_device->percent_complete = |
| 6648 | event_data->PercentComplete; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6649 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6650 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6651 | } |
| 6652 | |
| 6653 | /** |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6654 | * _scsih_prep_device_scan - initialize parameters prior to device scan |
| 6655 | * @ioc: per adapter object |
| 6656 | * |
| 6657 | * Set the deleted flag prior to device scan. If the device is found during |
| 6658 | * the scan, then we clear the deleted flag. |
| 6659 | */ |
| 6660 | static void |
| 6661 | _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc) |
| 6662 | { |
| 6663 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 6664 | struct scsi_device *sdev; |
| 6665 | |
| 6666 | shost_for_each_device(sdev, ioc->shost) { |
| 6667 | sas_device_priv_data = sdev->hostdata; |
| 6668 | if (sas_device_priv_data && sas_device_priv_data->sas_target) |
| 6669 | sas_device_priv_data->sas_target->deleted = 1; |
| 6670 | } |
| 6671 | } |
| 6672 | |
| 6673 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6674 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding |
| 6675 | * @ioc: per adapter object |
| 6676 | * @sas_address: sas address |
| 6677 | * @slot: enclosure slot id |
| 6678 | * @handle: device handle |
| 6679 | * |
| 6680 | * After host reset, find out whether devices are still responding. |
| 6681 | * Used in _scsi_remove_unresponsive_sas_devices. |
| 6682 | * |
| 6683 | * Return nothing. |
| 6684 | */ |
| 6685 | static void |
| 6686 | _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 6687 | u16 slot, u16 handle) |
| 6688 | { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6689 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6690 | struct scsi_target *starget; |
| 6691 | struct _sas_device *sas_device; |
| 6692 | unsigned long flags; |
| 6693 | |
| 6694 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6695 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { |
| 6696 | if (sas_device->sas_address == sas_address && |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6697 | sas_device->slot == slot) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6698 | sas_device->responding = 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6699 | starget = sas_device->starget; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6700 | if (starget && starget->hostdata) { |
| 6701 | sas_target_priv_data = starget->hostdata; |
| 6702 | sas_target_priv_data->tm_busy = 0; |
| 6703 | sas_target_priv_data->deleted = 0; |
| 6704 | } else |
| 6705 | sas_target_priv_data = NULL; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6706 | if (starget) |
| 6707 | starget_printk(KERN_INFO, starget, |
| 6708 | "handle(0x%04x), sas_addr(0x%016llx), " |
| 6709 | "enclosure logical id(0x%016llx), " |
| 6710 | "slot(%d)\n", handle, |
| 6711 | (unsigned long long)sas_device->sas_address, |
| 6712 | (unsigned long long) |
| 6713 | sas_device->enclosure_logical_id, |
| 6714 | sas_device->slot); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6715 | if (sas_device->handle == handle) |
| 6716 | goto out; |
| 6717 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 6718 | sas_device->handle); |
| 6719 | sas_device->handle = handle; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6720 | if (sas_target_priv_data) |
| 6721 | sas_target_priv_data->handle = handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6722 | goto out; |
| 6723 | } |
| 6724 | } |
| 6725 | out: |
| 6726 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6727 | } |
| 6728 | |
| 6729 | /** |
| 6730 | * _scsih_search_responding_sas_devices - |
| 6731 | * @ioc: per adapter object |
| 6732 | * |
| 6733 | * After host reset, find out whether devices are still responding. |
| 6734 | * If not remove. |
| 6735 | * |
| 6736 | * Return nothing. |
| 6737 | */ |
| 6738 | static void |
| 6739 | _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6740 | { |
| 6741 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6742 | Mpi2ConfigReply_t mpi_reply; |
| 6743 | u16 ioc_status; |
| 6744 | __le64 sas_address; |
| 6745 | u16 handle; |
| 6746 | u32 device_info; |
| 6747 | u16 slot; |
| 6748 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6749 | printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6750 | |
| 6751 | if (list_empty(&ioc->sas_device_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6752 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6753 | |
| 6754 | handle = 0xFFFF; |
| 6755 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6756 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 6757 | handle))) { |
| 6758 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6759 | MPI2_IOCSTATUS_MASK; |
| 6760 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6761 | break; |
| 6762 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 6763 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 6764 | if (!(_scsih_is_end_device(device_info))) |
| 6765 | continue; |
| 6766 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 6767 | slot = le16_to_cpu(sas_device_pg0.Slot); |
| 6768 | _scsih_mark_responding_sas_device(ioc, sas_address, slot, |
| 6769 | handle); |
| 6770 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6771 | out: |
| 6772 | printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n", |
| 6773 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6774 | } |
| 6775 | |
| 6776 | /** |
| 6777 | * _scsih_mark_responding_raid_device - mark a raid_device as responding |
| 6778 | * @ioc: per adapter object |
| 6779 | * @wwid: world wide identifier for raid volume |
| 6780 | * @handle: device handle |
| 6781 | * |
| 6782 | * After host reset, find out whether devices are still responding. |
| 6783 | * Used in _scsi_remove_unresponsive_raid_devices. |
| 6784 | * |
| 6785 | * Return nothing. |
| 6786 | */ |
| 6787 | static void |
| 6788 | _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid, |
| 6789 | u16 handle) |
| 6790 | { |
| 6791 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 6792 | struct scsi_target *starget; |
| 6793 | struct _raid_device *raid_device; |
| 6794 | unsigned long flags; |
| 6795 | |
| 6796 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6797 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 6798 | if (raid_device->wwid == wwid && raid_device->starget) { |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6799 | starget = raid_device->starget; |
| 6800 | if (starget && starget->hostdata) { |
| 6801 | sas_target_priv_data = starget->hostdata; |
| 6802 | sas_target_priv_data->deleted = 0; |
| 6803 | } else |
| 6804 | sas_target_priv_data = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6805 | raid_device->responding = 1; |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6806 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6807 | starget_printk(KERN_INFO, raid_device->starget, |
| 6808 | "handle(0x%04x), wwid(0x%016llx)\n", handle, |
| 6809 | (unsigned long long)raid_device->wwid); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6810 | /* |
| 6811 | * WARPDRIVE: The handles of the PDs might have changed |
| 6812 | * across the host reset so re-initialize the |
| 6813 | * required data for Direct IO |
| 6814 | */ |
| 6815 | _scsih_init_warpdrive_properties(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6816 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6817 | if (raid_device->handle == handle) { |
| 6818 | spin_unlock_irqrestore(&ioc->raid_device_lock, |
| 6819 | flags); |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6820 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6821 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6822 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 6823 | raid_device->handle); |
| 6824 | raid_device->handle = handle; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6825 | if (sas_target_priv_data) |
| 6826 | sas_target_priv_data->handle = handle; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6827 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6828 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6829 | } |
| 6830 | } |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6831 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6832 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6833 | } |
| 6834 | |
| 6835 | /** |
| 6836 | * _scsih_search_responding_raid_devices - |
| 6837 | * @ioc: per adapter object |
| 6838 | * |
| 6839 | * After host reset, find out whether devices are still responding. |
| 6840 | * If not remove. |
| 6841 | * |
| 6842 | * Return nothing. |
| 6843 | */ |
| 6844 | static void |
| 6845 | _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6846 | { |
| 6847 | Mpi2RaidVolPage1_t volume_pg1; |
Kashyap, Desai | d417d1c | 2010-06-17 13:48:10 +0530 | [diff] [blame] | 6848 | Mpi2RaidVolPage0_t volume_pg0; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6849 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6850 | Mpi2ConfigReply_t mpi_reply; |
| 6851 | u16 ioc_status; |
| 6852 | u16 handle; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6853 | u8 phys_disk_num; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6854 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6855 | if (!ioc->ir_firmware) |
| 6856 | return; |
| 6857 | |
| 6858 | printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n", |
| 6859 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6860 | |
| 6861 | if (list_empty(&ioc->raid_device_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6862 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6863 | |
| 6864 | handle = 0xFFFF; |
| 6865 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 6866 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 6867 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6868 | MPI2_IOCSTATUS_MASK; |
| 6869 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6870 | break; |
| 6871 | handle = le16_to_cpu(volume_pg1.DevHandle); |
Kashyap, Desai | d417d1c | 2010-06-17 13:48:10 +0530 | [diff] [blame] | 6872 | |
| 6873 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 6874 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 6875 | sizeof(Mpi2RaidVolPage0_t))) |
| 6876 | continue; |
| 6877 | |
| 6878 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 6879 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 6880 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) |
| 6881 | _scsih_mark_responding_raid_device(ioc, |
| 6882 | le64_to_cpu(volume_pg1.WWID), handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6883 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6884 | |
| 6885 | /* refresh the pd_handles */ |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6886 | if (!ioc->is_warpdrive) { |
| 6887 | phys_disk_num = 0xFF; |
| 6888 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); |
| 6889 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 6890 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 6891 | phys_disk_num))) { |
| 6892 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6893 | MPI2_IOCSTATUS_MASK; |
| 6894 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6895 | break; |
| 6896 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 6897 | handle = le16_to_cpu(pd_pg0.DevHandle); |
| 6898 | set_bit(handle, ioc->pd_handles); |
| 6899 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6900 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6901 | out: |
| 6902 | printk(MPT2SAS_INFO_FMT "search for responding raid volumes: " |
| 6903 | "complete\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6904 | } |
| 6905 | |
| 6906 | /** |
| 6907 | * _scsih_mark_responding_expander - mark a expander as responding |
| 6908 | * @ioc: per adapter object |
| 6909 | * @sas_address: sas address |
| 6910 | * @handle: |
| 6911 | * |
| 6912 | * After host reset, find out whether devices are still responding. |
| 6913 | * Used in _scsi_remove_unresponsive_expanders. |
| 6914 | * |
| 6915 | * Return nothing. |
| 6916 | */ |
| 6917 | static void |
| 6918 | _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 6919 | u16 handle) |
| 6920 | { |
| 6921 | struct _sas_node *sas_expander; |
| 6922 | unsigned long flags; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6923 | int i; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6924 | |
| 6925 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 6926 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6927 | if (sas_expander->sas_address != sas_address) |
| 6928 | continue; |
| 6929 | sas_expander->responding = 1; |
| 6930 | if (sas_expander->handle == handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6931 | goto out; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6932 | printk(KERN_INFO "\texpander(0x%016llx): handle changed" |
| 6933 | " from(0x%04x) to (0x%04x)!!!\n", |
| 6934 | (unsigned long long)sas_expander->sas_address, |
| 6935 | sas_expander->handle, handle); |
| 6936 | sas_expander->handle = handle; |
| 6937 | for (i = 0 ; i < sas_expander->num_phys ; i++) |
| 6938 | sas_expander->phy[i].handle = handle; |
| 6939 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6940 | } |
| 6941 | out: |
| 6942 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 6943 | } |
| 6944 | |
| 6945 | /** |
| 6946 | * _scsih_search_responding_expanders - |
| 6947 | * @ioc: per adapter object |
| 6948 | * |
| 6949 | * After host reset, find out whether devices are still responding. |
| 6950 | * If not remove. |
| 6951 | * |
| 6952 | * Return nothing. |
| 6953 | */ |
| 6954 | static void |
| 6955 | _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc) |
| 6956 | { |
| 6957 | Mpi2ExpanderPage0_t expander_pg0; |
| 6958 | Mpi2ConfigReply_t mpi_reply; |
| 6959 | u16 ioc_status; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 6960 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6961 | u16 handle; |
| 6962 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6963 | printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6964 | |
| 6965 | if (list_empty(&ioc->sas_expander_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6966 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6967 | |
| 6968 | handle = 0xFFFF; |
| 6969 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 6970 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 6971 | |
| 6972 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6973 | MPI2_IOCSTATUS_MASK; |
| 6974 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6975 | break; |
| 6976 | |
| 6977 | handle = le16_to_cpu(expander_pg0.DevHandle); |
| 6978 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
| 6979 | printk(KERN_INFO "\texpander present: handle(0x%04x), " |
| 6980 | "sas_addr(0x%016llx)\n", handle, |
| 6981 | (unsigned long long)sas_address); |
| 6982 | _scsih_mark_responding_expander(ioc, sas_address, handle); |
| 6983 | } |
| 6984 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6985 | out: |
| 6986 | printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6987 | } |
| 6988 | |
| 6989 | /** |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6990 | * _scsih_remove_unresponding_sas_devices - removing unresponding devices |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6991 | * @ioc: per adapter object |
| 6992 | * |
| 6993 | * Return nothing. |
| 6994 | */ |
| 6995 | static void |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6996 | _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6997 | { |
| 6998 | struct _sas_device *sas_device, *sas_device_next; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 6999 | struct _sas_node *sas_expander, *sas_expander_next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7000 | struct _raid_device *raid_device, *raid_device_next; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7001 | struct list_head tmp_list; |
| 7002 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7003 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7004 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n", |
| 7005 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7006 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7007 | /* removing unresponding end devices */ |
| 7008 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n", |
| 7009 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7010 | list_for_each_entry_safe(sas_device, sas_device_next, |
| 7011 | &ioc->sas_device_list, list) { |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7012 | if (!sas_device->responding) |
nagalakshmi.nandigama@lsi.com | 39af7a9 | 2012-03-20 12:09:26 +0530 | [diff] [blame] | 7013 | mpt2sas_device_remove_by_sas_address(ioc, |
| 7014 | sas_device->sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7015 | else |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7016 | sas_device->responding = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7017 | } |
| 7018 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7019 | /* removing unresponding volumes */ |
| 7020 | if (ioc->ir_firmware) { |
| 7021 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: " |
| 7022 | "volumes\n", ioc->name); |
| 7023 | list_for_each_entry_safe(raid_device, raid_device_next, |
| 7024 | &ioc->raid_device_list, list) { |
| 7025 | if (!raid_device->responding) |
| 7026 | _scsih_sas_volume_delete(ioc, |
| 7027 | raid_device->handle); |
| 7028 | else |
| 7029 | raid_device->responding = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7030 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7031 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7032 | /* removing unresponding expanders */ |
| 7033 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n", |
| 7034 | ioc->name); |
| 7035 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 7036 | INIT_LIST_HEAD(&tmp_list); |
| 7037 | list_for_each_entry_safe(sas_expander, sas_expander_next, |
| 7038 | &ioc->sas_expander_list, list) { |
| 7039 | if (!sas_expander->responding) |
| 7040 | list_move_tail(&sas_expander->list, &tmp_list); |
| 7041 | else |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7042 | sas_expander->responding = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7043 | } |
| 7044 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 7045 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, |
| 7046 | list) { |
| 7047 | list_del(&sas_expander->list); |
| 7048 | _scsih_expander_node_remove(ioc, sas_expander); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7049 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7050 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n", |
| 7051 | ioc->name); |
| 7052 | /* unblock devices */ |
| 7053 | _scsih_ublock_io_all_device(ioc); |
| 7054 | } |
| 7055 | |
| 7056 | static void |
| 7057 | _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc, |
| 7058 | struct _sas_node *sas_expander, u16 handle) |
| 7059 | { |
| 7060 | Mpi2ExpanderPage1_t expander_pg1; |
| 7061 | Mpi2ConfigReply_t mpi_reply; |
| 7062 | int i; |
| 7063 | |
| 7064 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 7065 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 7066 | &expander_pg1, i, handle))) { |
| 7067 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7068 | ioc->name, __FILE__, __LINE__, __func__); |
| 7069 | return; |
| 7070 | } |
| 7071 | |
| 7072 | mpt2sas_transport_update_links(ioc, sas_expander->sas_address, |
| 7073 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, |
| 7074 | expander_pg1.NegotiatedLinkRate >> 4); |
| 7075 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7076 | } |
| 7077 | |
| 7078 | /** |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7079 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7080 | * @ioc: per adapter object |
| 7081 | * |
| 7082 | * Return nothing. |
| 7083 | */ |
| 7084 | static void |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7085 | _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc) |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7086 | { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7087 | Mpi2ExpanderPage0_t expander_pg0; |
| 7088 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 7089 | Mpi2RaidVolPage1_t volume_pg1; |
| 7090 | Mpi2RaidVolPage0_t volume_pg0; |
| 7091 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 7092 | Mpi2EventIrConfigElement_t element; |
| 7093 | Mpi2ConfigReply_t mpi_reply; |
| 7094 | u8 phys_disk_num; |
| 7095 | u16 ioc_status; |
| 7096 | u16 handle, parent_handle; |
| 7097 | u64 sas_address; |
| 7098 | struct _sas_device *sas_device; |
| 7099 | struct _sas_node *expander_device; |
| 7100 | static struct _raid_device *raid_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7101 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7102 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7103 | printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7104 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7105 | _scsih_sas_host_refresh(ioc); |
| 7106 | |
| 7107 | /* expanders */ |
| 7108 | handle = 0xFFFF; |
| 7109 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 7110 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 7111 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7112 | MPI2_IOCSTATUS_MASK; |
| 7113 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 7114 | break; |
| 7115 | handle = le16_to_cpu(expander_pg0.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7116 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7117 | expander_device = mpt2sas_scsih_expander_find_by_sas_address( |
| 7118 | ioc, le64_to_cpu(expander_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7119 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7120 | if (expander_device) |
| 7121 | _scsih_refresh_expander_links(ioc, expander_device, |
| 7122 | handle); |
| 7123 | else |
| 7124 | _scsih_expander_add(ioc, handle); |
| 7125 | } |
| 7126 | |
| 7127 | if (!ioc->ir_firmware) |
| 7128 | goto skip_to_sas; |
| 7129 | |
| 7130 | /* phys disk */ |
| 7131 | phys_disk_num = 0xFF; |
| 7132 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 7133 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 7134 | phys_disk_num))) { |
| 7135 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7136 | MPI2_IOCSTATUS_MASK; |
| 7137 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 7138 | break; |
| 7139 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 7140 | handle = le16_to_cpu(pd_pg0.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7141 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7142 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7143 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7144 | if (sas_device) |
| 7145 | continue; |
| 7146 | if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 7147 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 7148 | handle) != 0) |
| 7149 | continue; |
| 7150 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 7151 | if (!_scsih_get_sas_address(ioc, parent_handle, |
| 7152 | &sas_address)) { |
| 7153 | mpt2sas_transport_update_links(ioc, sas_address, |
| 7154 | handle, sas_device_pg0.PhyNum, |
| 7155 | MPI2_SAS_NEG_LINK_RATE_1_5); |
| 7156 | set_bit(handle, ioc->pd_handles); |
| 7157 | _scsih_add_device(ioc, handle, 0, 1); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7158 | } |
| 7159 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7160 | |
| 7161 | /* volumes */ |
| 7162 | handle = 0xFFFF; |
| 7163 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 7164 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 7165 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7166 | MPI2_IOCSTATUS_MASK; |
| 7167 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 7168 | break; |
| 7169 | handle = le16_to_cpu(volume_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7170 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7171 | raid_device = _scsih_raid_device_find_by_wwid(ioc, |
| 7172 | le64_to_cpu(volume_pg1.WWID)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7173 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7174 | if (raid_device) |
| 7175 | continue; |
| 7176 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 7177 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 7178 | sizeof(Mpi2RaidVolPage0_t))) |
| 7179 | continue; |
| 7180 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 7181 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 7182 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { |
| 7183 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); |
| 7184 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; |
| 7185 | element.VolDevHandle = volume_pg1.DevHandle; |
| 7186 | _scsih_sas_volume_add(ioc, &element); |
| 7187 | } |
| 7188 | } |
| 7189 | |
| 7190 | skip_to_sas: |
| 7191 | |
| 7192 | /* sas devices */ |
| 7193 | handle = 0xFFFF; |
| 7194 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 7195 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 7196 | handle))) { |
| 7197 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7198 | MPI2_IOCSTATUS_MASK; |
| 7199 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 7200 | break; |
| 7201 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 7202 | if (!(_scsih_is_end_device( |
| 7203 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) |
| 7204 | continue; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7205 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7206 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 7207 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7208 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7209 | if (sas_device) |
| 7210 | continue; |
| 7211 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 7212 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { |
| 7213 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 7214 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
| 7215 | _scsih_add_device(ioc, handle, 0, 0); |
| 7216 | } |
| 7217 | } |
| 7218 | |
| 7219 | printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7220 | } |
| 7221 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7222 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7223 | /** |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7224 | * mpt2sas_scsih_reset_handler - reset callback handler (for scsih) |
| 7225 | * @ioc: per adapter object |
| 7226 | * @reset_phase: phase |
| 7227 | * |
| 7228 | * The handler for doing any required cleanup or initialization. |
| 7229 | * |
| 7230 | * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET, |
| 7231 | * MPT2_IOC_DONE_RESET |
| 7232 | * |
| 7233 | * Return nothing. |
| 7234 | */ |
| 7235 | void |
| 7236 | mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase) |
| 7237 | { |
| 7238 | switch (reset_phase) { |
| 7239 | case MPT2_IOC_PRE_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7240 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7241 | "MPT2_IOC_PRE_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7242 | break; |
| 7243 | case MPT2_IOC_AFTER_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7244 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7245 | "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7246 | if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) { |
| 7247 | ioc->scsih_cmds.status |= MPT2_CMD_RESET; |
| 7248 | mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid); |
| 7249 | complete(&ioc->scsih_cmds.done); |
| 7250 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7251 | if (ioc->tm_cmds.status & MPT2_CMD_PENDING) { |
| 7252 | ioc->tm_cmds.status |= MPT2_CMD_RESET; |
| 7253 | mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid); |
| 7254 | complete(&ioc->tm_cmds.done); |
| 7255 | } |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7256 | _scsih_fw_event_cleanup_queue(ioc); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7257 | _scsih_flush_running_cmds(ioc); |
| 7258 | break; |
| 7259 | case MPT2_IOC_DONE_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7260 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7261 | "MPT2_IOC_DONE_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7262 | _scsih_sas_host_refresh(ioc); |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 7263 | _scsih_prep_device_scan(ioc); |
| 7264 | _scsih_search_responding_sas_devices(ioc); |
| 7265 | _scsih_search_responding_raid_devices(ioc); |
| 7266 | _scsih_search_responding_expanders(ioc); |
sreekanth.reddy@lsi.com | 14aa7f7 | 2012-07-17 15:56:13 +0530 | [diff] [blame^] | 7267 | if ((!ioc->is_driver_loading) && !(disable_discovery > 0 && |
| 7268 | !ioc->sas_hba.num_phys)) { |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7269 | _scsih_prep_device_scan(ioc); |
| 7270 | _scsih_search_responding_sas_devices(ioc); |
| 7271 | _scsih_search_responding_raid_devices(ioc); |
| 7272 | _scsih_search_responding_expanders(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7273 | _scsih_error_recovery_delete_devices(ioc); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7274 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7275 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7276 | } |
| 7277 | } |
| 7278 | |
| 7279 | /** |
| 7280 | * _firmware_event_work - delayed task for processing firmware events |
| 7281 | * @ioc: per adapter object |
| 7282 | * @work: equal to the fw_event_work object |
| 7283 | * Context: user. |
| 7284 | * |
| 7285 | * Return nothing. |
| 7286 | */ |
| 7287 | static void |
| 7288 | _firmware_event_work(struct work_struct *work) |
| 7289 | { |
| 7290 | struct fw_event_work *fw_event = container_of(work, |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7291 | struct fw_event_work, delayed_work.work); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7292 | struct MPT2SAS_ADAPTER *ioc = fw_event->ioc; |
| 7293 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7294 | /* the queue is being flushed so ignore this event */ |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7295 | if (ioc->remove_host || fw_event->cancel_pending_work || |
| 7296 | ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7297 | _scsih_fw_event_free(ioc, fw_event); |
| 7298 | return; |
| 7299 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7300 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7301 | switch (fw_event->event) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7302 | case MPT2SAS_REMOVE_UNRESPONDING_DEVICES: |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7303 | while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7304 | ssleep(1); |
| 7305 | _scsih_remove_unresponding_sas_devices(ioc); |
| 7306 | _scsih_scan_for_devices_after_reset(ioc); |
| 7307 | break; |
| 7308 | case MPT2SAS_PORT_ENABLE_COMPLETE: |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7309 | ioc->start_scan = 0; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7310 | |
| 7311 | |
| 7312 | |
| 7313 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete " |
| 7314 | "from worker thread\n", ioc->name)); |
| 7315 | break; |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 7316 | case MPT2SAS_TURN_ON_FAULT_LED: |
| 7317 | _scsih_turn_on_fault_led(ioc, fw_event->device_handle); |
| 7318 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7319 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7320 | _scsih_sas_topology_change_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7321 | break; |
| 7322 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7323 | _scsih_sas_device_status_change_event(ioc, |
| 7324 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7325 | break; |
| 7326 | case MPI2_EVENT_SAS_DISCOVERY: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7327 | _scsih_sas_discovery_event(ioc, |
| 7328 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7329 | break; |
| 7330 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 7331 | _scsih_sas_broadcast_primitive_event(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7332 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7333 | break; |
| 7334 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
| 7335 | _scsih_sas_enclosure_dev_status_change_event(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7336 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7337 | break; |
| 7338 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7339 | _scsih_sas_ir_config_change_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7340 | break; |
| 7341 | case MPI2_EVENT_IR_VOLUME: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7342 | _scsih_sas_ir_volume_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7343 | break; |
| 7344 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7345 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7346 | break; |
| 7347 | case MPI2_EVENT_IR_OPERATION_STATUS: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7348 | _scsih_sas_ir_operation_status_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7349 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7350 | } |
| 7351 | _scsih_fw_event_free(ioc, fw_event); |
| 7352 | } |
| 7353 | |
| 7354 | /** |
| 7355 | * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time) |
| 7356 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7357 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7358 | * @reply: reply message frame(lower 32bit addr) |
| 7359 | * Context: interrupt. |
| 7360 | * |
| 7361 | * This function merely adds a new work task into ioc->firmware_event_thread. |
| 7362 | * The tasks are worked from _firmware_event_work in user context. |
| 7363 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7364 | * Return 1 meaning mf should be freed from _base_interrupt |
| 7365 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7366 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7367 | u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7368 | mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, |
| 7369 | u32 reply) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7370 | { |
| 7371 | struct fw_event_work *fw_event; |
| 7372 | Mpi2EventNotificationReply_t *mpi_reply; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7373 | u16 event; |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 7374 | u16 sz; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7375 | |
| 7376 | /* events turned off due to host reset or driver unloading */ |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7377 | if (ioc->remove_host || ioc->pci_error_recovery) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7378 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7379 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7380 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
nagalakshmi.nandigama@lsi.com | 298c794 | 2012-03-20 12:07:17 +0530 | [diff] [blame] | 7381 | |
| 7382 | if (unlikely(!mpi_reply)) { |
| 7383 | printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 7384 | ioc->name, __FILE__, __LINE__, __func__); |
| 7385 | return 1; |
| 7386 | } |
| 7387 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7388 | event = le16_to_cpu(mpi_reply->Event); |
| 7389 | |
| 7390 | switch (event) { |
| 7391 | /* handle these */ |
| 7392 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 7393 | { |
| 7394 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = |
| 7395 | (Mpi2EventDataSasBroadcastPrimitive_t *) |
| 7396 | mpi_reply->EventData; |
| 7397 | |
| 7398 | if (baen_data->Primitive != |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7399 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7400 | return 1; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7401 | |
| 7402 | if (ioc->broadcast_aen_busy) { |
| 7403 | ioc->broadcast_aen_pending++; |
| 7404 | return 1; |
| 7405 | } else |
| 7406 | ioc->broadcast_aen_busy = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7407 | break; |
| 7408 | } |
| 7409 | |
| 7410 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
| 7411 | _scsih_check_topo_delete_events(ioc, |
| 7412 | (Mpi2EventDataSasTopologyChangeList_t *) |
| 7413 | mpi_reply->EventData); |
| 7414 | break; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 7415 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
| 7416 | _scsih_check_ir_config_unhide_events(ioc, |
| 7417 | (Mpi2EventDataIrConfigChangeList_t *) |
| 7418 | mpi_reply->EventData); |
| 7419 | break; |
| 7420 | case MPI2_EVENT_IR_VOLUME: |
| 7421 | _scsih_check_volume_delete_events(ioc, |
| 7422 | (Mpi2EventDataIrVolume_t *) |
| 7423 | mpi_reply->EventData); |
| 7424 | break; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7425 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
| 7426 | { |
| 7427 | Mpi2EventDataLogEntryAdded_t *log_entry; |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 7428 | __le32 *log_code; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7429 | |
| 7430 | if (!ioc->is_warpdrive) |
| 7431 | break; |
| 7432 | |
| 7433 | log_entry = (Mpi2EventDataLogEntryAdded_t *) |
| 7434 | mpi_reply->EventData; |
nagalakshmi.nandigama@lsi.com | d838c36 | 2012-03-20 12:07:48 +0530 | [diff] [blame] | 7435 | log_code = (__le32 *)log_entry->LogData; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7436 | |
| 7437 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
| 7438 | != MPT2_WARPDRIVE_LOGENTRY) |
| 7439 | break; |
| 7440 | |
| 7441 | switch (le32_to_cpu(*log_code)) { |
| 7442 | case MPT2_WARPDRIVE_LC_SSDT: |
| 7443 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " |
| 7444 | "IO Throttling has occurred in the WarpDrive " |
| 7445 | "subsystem. Check WarpDrive documentation for " |
| 7446 | "additional details.\n", ioc->name); |
| 7447 | break; |
| 7448 | case MPT2_WARPDRIVE_LC_SSDLW: |
| 7449 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " |
| 7450 | "Program/Erase Cycles for the WarpDrive subsystem " |
| 7451 | "in degraded range. Check WarpDrive documentation " |
| 7452 | "for additional details.\n", ioc->name); |
| 7453 | break; |
| 7454 | case MPT2_WARPDRIVE_LC_SSDLF: |
| 7455 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " |
| 7456 | "There are no Program/Erase Cycles for the " |
| 7457 | "WarpDrive subsystem. The storage device will be " |
| 7458 | "in read-only mode. Check WarpDrive documentation " |
| 7459 | "for additional details.\n", ioc->name); |
| 7460 | break; |
| 7461 | case MPT2_WARPDRIVE_LC_BRMF: |
| 7462 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " |
| 7463 | "The Backup Rail Monitor has failed on the " |
| 7464 | "WarpDrive subsystem. Check WarpDrive " |
| 7465 | "documentation for additional details.\n", |
| 7466 | ioc->name); |
| 7467 | break; |
| 7468 | } |
| 7469 | |
| 7470 | break; |
| 7471 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7472 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 7473 | case MPI2_EVENT_IR_OPERATION_STATUS: |
| 7474 | case MPI2_EVENT_SAS_DISCOVERY: |
| 7475 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7476 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7477 | break; |
| 7478 | |
| 7479 | default: /* ignore the rest */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7480 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7481 | } |
| 7482 | |
| 7483 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 7484 | if (!fw_event) { |
| 7485 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7486 | ioc->name, __FILE__, __LINE__, __func__); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7487 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7488 | } |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 7489 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
| 7490 | fw_event->event_data = kzalloc(sz, GFP_ATOMIC); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7491 | if (!fw_event->event_data) { |
| 7492 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7493 | ioc->name, __FILE__, __LINE__, __func__); |
| 7494 | kfree(fw_event); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7495 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7496 | } |
| 7497 | |
| 7498 | memcpy(fw_event->event_data, mpi_reply->EventData, |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 7499 | sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7500 | fw_event->ioc = ioc; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7501 | fw_event->VF_ID = mpi_reply->VF_ID; |
| 7502 | fw_event->VP_ID = mpi_reply->VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7503 | fw_event->event = event; |
| 7504 | _scsih_fw_event_add(ioc, fw_event); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7505 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7506 | } |
| 7507 | |
| 7508 | /* shost template */ |
| 7509 | static struct scsi_host_template scsih_driver_template = { |
| 7510 | .module = THIS_MODULE, |
| 7511 | .name = "Fusion MPT SAS Host", |
| 7512 | .proc_name = MPT2SAS_DRIVER_NAME, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7513 | .queuecommand = _scsih_qcmd, |
| 7514 | .target_alloc = _scsih_target_alloc, |
| 7515 | .slave_alloc = _scsih_slave_alloc, |
| 7516 | .slave_configure = _scsih_slave_configure, |
| 7517 | .target_destroy = _scsih_target_destroy, |
| 7518 | .slave_destroy = _scsih_slave_destroy, |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7519 | .scan_finished = _scsih_scan_finished, |
| 7520 | .scan_start = _scsih_scan_start, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7521 | .change_queue_depth = _scsih_change_queue_depth, |
| 7522 | .change_queue_type = _scsih_change_queue_type, |
| 7523 | .eh_abort_handler = _scsih_abort, |
| 7524 | .eh_device_reset_handler = _scsih_dev_reset, |
| 7525 | .eh_target_reset_handler = _scsih_target_reset, |
| 7526 | .eh_host_reset_handler = _scsih_host_reset, |
| 7527 | .bios_param = _scsih_bios_param, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7528 | .can_queue = 1, |
| 7529 | .this_id = -1, |
| 7530 | .sg_tablesize = MPT2SAS_SG_DEPTH, |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 7531 | .max_sectors = 32767, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7532 | .cmd_per_lun = 7, |
| 7533 | .use_clustering = ENABLE_CLUSTERING, |
| 7534 | .shost_attrs = mpt2sas_host_attrs, |
| 7535 | .sdev_attrs = mpt2sas_dev_attrs, |
| 7536 | }; |
| 7537 | |
| 7538 | /** |
| 7539 | * _scsih_expander_node_remove - removing expander device from list. |
| 7540 | * @ioc: per adapter object |
| 7541 | * @sas_expander: the sas_device object |
| 7542 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 7543 | * |
| 7544 | * Removing object and freeing associated memory from the |
| 7545 | * ioc->sas_expander_list. |
| 7546 | * |
| 7547 | * Return nothing. |
| 7548 | */ |
| 7549 | static void |
| 7550 | _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc, |
| 7551 | struct _sas_node *sas_expander) |
| 7552 | { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7553 | struct _sas_port *mpt2sas_port, *next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7554 | |
| 7555 | /* remove sibling ports attached to this expander */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7556 | list_for_each_entry_safe(mpt2sas_port, next, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7557 | &sas_expander->sas_port_list, port_list) { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7558 | if (ioc->shost_recovery) |
| 7559 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7560 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7561 | SAS_END_DEVICE) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7562 | mpt2sas_device_remove_by_sas_address(ioc, |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7563 | mpt2sas_port->remote_identify.sas_address); |
| 7564 | else if (mpt2sas_port->remote_identify.device_type == |
| 7565 | SAS_EDGE_EXPANDER_DEVICE || |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7566 | mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7567 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7568 | mpt2sas_expander_remove(ioc, |
| 7569 | mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7570 | } |
| 7571 | |
| 7572 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7573 | sas_expander->sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7574 | |
| 7575 | printk(MPT2SAS_INFO_FMT "expander_remove: handle" |
| 7576 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, |
| 7577 | sas_expander->handle, (unsigned long long) |
| 7578 | sas_expander->sas_address); |
| 7579 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7580 | kfree(sas_expander->phy); |
| 7581 | kfree(sas_expander); |
| 7582 | } |
| 7583 | |
| 7584 | /** |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7585 | * _scsih_ir_shutdown - IR shutdown notification |
| 7586 | * @ioc: per adapter object |
| 7587 | * |
| 7588 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that |
| 7589 | * the host system is shutting down. |
| 7590 | * |
| 7591 | * Return nothing. |
| 7592 | */ |
| 7593 | static void |
| 7594 | _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc) |
| 7595 | { |
| 7596 | Mpi2RaidActionRequest_t *mpi_request; |
| 7597 | Mpi2RaidActionReply_t *mpi_reply; |
| 7598 | u16 smid; |
| 7599 | |
| 7600 | /* is IR firmware build loaded ? */ |
| 7601 | if (!ioc->ir_firmware) |
| 7602 | return; |
| 7603 | |
| 7604 | /* are there any volumes ? */ |
| 7605 | if (list_empty(&ioc->raid_device_list)) |
| 7606 | return; |
| 7607 | |
| 7608 | mutex_lock(&ioc->scsih_cmds.mutex); |
| 7609 | |
| 7610 | if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) { |
| 7611 | printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n", |
| 7612 | ioc->name, __func__); |
| 7613 | goto out; |
| 7614 | } |
| 7615 | ioc->scsih_cmds.status = MPT2_CMD_PENDING; |
| 7616 | |
| 7617 | smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx); |
| 7618 | if (!smid) { |
| 7619 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 7620 | ioc->name, __func__); |
| 7621 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; |
| 7622 | goto out; |
| 7623 | } |
| 7624 | |
| 7625 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 7626 | ioc->scsih_cmds.smid = smid; |
| 7627 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); |
| 7628 | |
| 7629 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; |
| 7630 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; |
| 7631 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7632 | if (!ioc->hide_ir_msg) |
| 7633 | printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7634 | init_completion(&ioc->scsih_cmds.done); |
| 7635 | mpt2sas_base_put_smid_default(ioc, smid); |
| 7636 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
| 7637 | |
| 7638 | if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) { |
| 7639 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 7640 | ioc->name, __func__); |
| 7641 | goto out; |
| 7642 | } |
| 7643 | |
| 7644 | if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 7645 | mpi_reply = ioc->scsih_cmds.reply; |
| 7646 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7647 | if (!ioc->hide_ir_msg) |
| 7648 | printk(MPT2SAS_INFO_FMT "IR shutdown (complete): " |
| 7649 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7650 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 7651 | le32_to_cpu(mpi_reply->IOCLogInfo)); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7652 | } |
| 7653 | |
| 7654 | out: |
| 7655 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; |
| 7656 | mutex_unlock(&ioc->scsih_cmds.mutex); |
| 7657 | } |
| 7658 | |
| 7659 | /** |
| 7660 | * _scsih_shutdown - routine call during system shutdown |
| 7661 | * @pdev: PCI device struct |
| 7662 | * |
| 7663 | * Return nothing. |
| 7664 | */ |
| 7665 | static void |
| 7666 | _scsih_shutdown(struct pci_dev *pdev) |
| 7667 | { |
| 7668 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7669 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7670 | struct workqueue_struct *wq; |
| 7671 | unsigned long flags; |
| 7672 | |
| 7673 | ioc->remove_host = 1; |
| 7674 | _scsih_fw_event_cleanup_queue(ioc); |
| 7675 | |
| 7676 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7677 | wq = ioc->firmware_event_thread; |
| 7678 | ioc->firmware_event_thread = NULL; |
| 7679 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7680 | if (wq) |
| 7681 | destroy_workqueue(wq); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7682 | |
| 7683 | _scsih_ir_shutdown(ioc); |
| 7684 | mpt2sas_base_detach(ioc); |
| 7685 | } |
| 7686 | |
| 7687 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7688 | * _scsih_remove - detach and remove add host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7689 | * @pdev: PCI device struct |
| 7690 | * |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7691 | * Routine called when unloading the driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7692 | * Return nothing. |
| 7693 | */ |
| 7694 | static void __devexit |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7695 | _scsih_remove(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7696 | { |
| 7697 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7698 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7699 | struct _sas_port *mpt2sas_port, *next_port; |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7700 | struct _raid_device *raid_device, *next; |
| 7701 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7702 | struct workqueue_struct *wq; |
| 7703 | unsigned long flags; |
| 7704 | |
| 7705 | ioc->remove_host = 1; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7706 | _scsih_fw_event_cleanup_queue(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7707 | |
| 7708 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7709 | wq = ioc->firmware_event_thread; |
| 7710 | ioc->firmware_event_thread = NULL; |
| 7711 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7712 | if (wq) |
| 7713 | destroy_workqueue(wq); |
| 7714 | |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7715 | /* release all the volumes */ |
Kashyap, Desai | 3a9c913 | 2011-01-04 11:40:23 +0530 | [diff] [blame] | 7716 | _scsih_ir_shutdown(ioc); |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7717 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, |
| 7718 | list) { |
| 7719 | if (raid_device->starget) { |
| 7720 | sas_target_priv_data = |
| 7721 | raid_device->starget->hostdata; |
| 7722 | sas_target_priv_data->deleted = 1; |
| 7723 | scsi_remove_target(&raid_device->starget->dev); |
| 7724 | } |
| 7725 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" |
| 7726 | "(0x%016llx)\n", ioc->name, raid_device->handle, |
| 7727 | (unsigned long long) raid_device->wwid); |
| 7728 | _scsih_raid_device_remove(ioc, raid_device); |
| 7729 | } |
| 7730 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7731 | /* free ports attached to the sas_host */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7732 | list_for_each_entry_safe(mpt2sas_port, next_port, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7733 | &ioc->sas_hba.sas_port_list, port_list) { |
| 7734 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7735 | SAS_END_DEVICE) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7736 | mpt2sas_device_remove_by_sas_address(ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7737 | mpt2sas_port->remote_identify.sas_address); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7738 | else if (mpt2sas_port->remote_identify.device_type == |
| 7739 | SAS_EDGE_EXPANDER_DEVICE || |
| 7740 | mpt2sas_port->remote_identify.device_type == |
| 7741 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7742 | mpt2sas_expander_remove(ioc, |
| 7743 | mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7744 | } |
| 7745 | |
| 7746 | /* free phys attached to the sas_host */ |
| 7747 | if (ioc->sas_hba.num_phys) { |
| 7748 | kfree(ioc->sas_hba.phy); |
| 7749 | ioc->sas_hba.phy = NULL; |
| 7750 | ioc->sas_hba.num_phys = 0; |
| 7751 | } |
| 7752 | |
| 7753 | sas_remove_host(shost); |
kashyap.desai@lsi.com | 9ae89b0 | 2011-08-04 16:47:50 +0530 | [diff] [blame] | 7754 | mpt2sas_base_detach(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7755 | list_del(&ioc->list); |
| 7756 | scsi_remove_host(shost); |
| 7757 | scsi_host_put(shost); |
| 7758 | } |
| 7759 | |
| 7760 | /** |
| 7761 | * _scsih_probe_boot_devices - reports 1st device |
| 7762 | * @ioc: per adapter object |
| 7763 | * |
| 7764 | * If specified in bios page 2, this routine reports the 1st |
| 7765 | * device scsi-ml or sas transport for persistent boot device |
| 7766 | * purposes. Please refer to function _scsih_determine_boot_device() |
| 7767 | */ |
| 7768 | static void |
| 7769 | _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc) |
| 7770 | { |
| 7771 | u8 is_raid; |
| 7772 | void *device; |
| 7773 | struct _sas_device *sas_device; |
| 7774 | struct _raid_device *raid_device; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7775 | u16 handle; |
| 7776 | u64 sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7777 | u64 sas_address; |
| 7778 | unsigned long flags; |
| 7779 | int rc; |
| 7780 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7781 | /* no Bios, return immediately */ |
| 7782 | if (!ioc->bios_pg3.BiosVersion) |
| 7783 | return; |
| 7784 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7785 | device = NULL; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7786 | is_raid = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7787 | if (ioc->req_boot_device.device) { |
| 7788 | device = ioc->req_boot_device.device; |
| 7789 | is_raid = ioc->req_boot_device.is_raid; |
| 7790 | } else if (ioc->req_alt_boot_device.device) { |
| 7791 | device = ioc->req_alt_boot_device.device; |
| 7792 | is_raid = ioc->req_alt_boot_device.is_raid; |
| 7793 | } else if (ioc->current_boot_device.device) { |
| 7794 | device = ioc->current_boot_device.device; |
| 7795 | is_raid = ioc->current_boot_device.is_raid; |
| 7796 | } |
| 7797 | |
| 7798 | if (!device) |
| 7799 | return; |
| 7800 | |
| 7801 | if (is_raid) { |
| 7802 | raid_device = device; |
| 7803 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7804 | raid_device->id, 0); |
| 7805 | if (rc) |
| 7806 | _scsih_raid_device_remove(ioc, raid_device); |
| 7807 | } else { |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame] | 7808 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7809 | sas_device = device; |
| 7810 | handle = sas_device->handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7811 | sas_address_parent = sas_device->sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7812 | sas_address = sas_device->sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7813 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 7814 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7815 | |
| 7816 | if (ioc->hide_drives) |
| 7817 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7818 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7819 | sas_device->sas_address_parent)) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7820 | _scsih_sas_device_remove(ioc, sas_device); |
| 7821 | } else if (!sas_device->starget) { |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 7822 | if (!ioc->is_driver_loading) |
| 7823 | mpt2sas_transport_port_remove(ioc, sas_address, |
| 7824 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7825 | _scsih_sas_device_remove(ioc, sas_device); |
| 7826 | } |
| 7827 | } |
| 7828 | } |
| 7829 | |
| 7830 | /** |
| 7831 | * _scsih_probe_raid - reporting raid volumes to scsi-ml |
| 7832 | * @ioc: per adapter object |
| 7833 | * |
| 7834 | * Called during initial loading of the driver. |
| 7835 | */ |
| 7836 | static void |
| 7837 | _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc) |
| 7838 | { |
| 7839 | struct _raid_device *raid_device, *raid_next; |
| 7840 | int rc; |
| 7841 | |
| 7842 | list_for_each_entry_safe(raid_device, raid_next, |
| 7843 | &ioc->raid_device_list, list) { |
| 7844 | if (raid_device->starget) |
| 7845 | continue; |
| 7846 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7847 | raid_device->id, 0); |
| 7848 | if (rc) |
| 7849 | _scsih_raid_device_remove(ioc, raid_device); |
| 7850 | } |
| 7851 | } |
| 7852 | |
| 7853 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7854 | * _scsih_probe_sas - reporting sas devices to sas transport |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7855 | * @ioc: per adapter object |
| 7856 | * |
| 7857 | * Called during initial loading of the driver. |
| 7858 | */ |
| 7859 | static void |
| 7860 | _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc) |
| 7861 | { |
| 7862 | struct _sas_device *sas_device, *next; |
| 7863 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7864 | |
| 7865 | /* SAS Device List */ |
| 7866 | list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list, |
| 7867 | list) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7868 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7869 | if (ioc->hide_drives) |
| 7870 | continue; |
| 7871 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7872 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
| 7873 | sas_device->sas_address_parent)) { |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 7874 | list_del(&sas_device->list); |
| 7875 | kfree(sas_device); |
| 7876 | continue; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7877 | } else if (!sas_device->starget) { |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 7878 | if (!ioc->is_driver_loading) |
| 7879 | mpt2sas_transport_port_remove(ioc, |
| 7880 | sas_device->sas_address, |
| 7881 | sas_device->sas_address_parent); |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 7882 | list_del(&sas_device->list); |
| 7883 | kfree(sas_device); |
| 7884 | continue; |
| 7885 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7886 | } |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 7887 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 7888 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 7889 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7890 | } |
| 7891 | } |
| 7892 | |
| 7893 | /** |
| 7894 | * _scsih_probe_devices - probing for devices |
| 7895 | * @ioc: per adapter object |
| 7896 | * |
| 7897 | * Called during initial loading of the driver. |
| 7898 | */ |
| 7899 | static void |
| 7900 | _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc) |
| 7901 | { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7902 | u16 volume_mapping_flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7903 | |
| 7904 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) |
| 7905 | return; /* return when IOC doesn't support initiator mode */ |
| 7906 | |
| 7907 | _scsih_probe_boot_devices(ioc); |
| 7908 | |
| 7909 | if (ioc->ir_firmware) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7910 | volume_mapping_flags = |
| 7911 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & |
| 7912 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; |
| 7913 | if (volume_mapping_flags == |
| 7914 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7915 | _scsih_probe_raid(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7916 | _scsih_probe_sas(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7917 | } else { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7918 | _scsih_probe_sas(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7919 | _scsih_probe_raid(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7920 | } |
| 7921 | } else |
| 7922 | _scsih_probe_sas(ioc); |
| 7923 | } |
| 7924 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7925 | |
| 7926 | /** |
| 7927 | * _scsih_scan_start - scsi lld callback for .scan_start |
| 7928 | * @shost: SCSI host pointer |
| 7929 | * |
| 7930 | * The shost has the ability to discover targets on its own instead |
| 7931 | * of scanning the entire bus. In our implemention, we will kick off |
| 7932 | * firmware discovery. |
| 7933 | */ |
| 7934 | static void |
| 7935 | _scsih_scan_start(struct Scsi_Host *shost) |
| 7936 | { |
| 7937 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 7938 | int rc; |
| 7939 | |
| 7940 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) |
| 7941 | mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable); |
| 7942 | |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 7943 | if (disable_discovery > 0) |
| 7944 | return; |
| 7945 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7946 | ioc->start_scan = 1; |
| 7947 | rc = mpt2sas_port_enable(ioc); |
| 7948 | |
| 7949 | if (rc != 0) |
| 7950 | printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name); |
| 7951 | } |
| 7952 | |
| 7953 | /** |
| 7954 | * _scsih_scan_finished - scsi lld callback for .scan_finished |
| 7955 | * @shost: SCSI host pointer |
| 7956 | * @time: elapsed time of the scan in jiffies |
| 7957 | * |
| 7958 | * This function will be called periodically until it returns 1 with the |
| 7959 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, |
| 7960 | * we wait for firmware discovery to complete, then return 1. |
| 7961 | */ |
| 7962 | static int |
| 7963 | _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 7964 | { |
| 7965 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 7966 | |
sreekanth.reddy@lsi.com | 4b19317 | 2012-07-17 15:56:12 +0530 | [diff] [blame] | 7967 | if (disable_discovery > 0) { |
| 7968 | ioc->is_driver_loading = 0; |
| 7969 | ioc->wait_for_discovery_to_complete = 0; |
| 7970 | return 1; |
| 7971 | } |
| 7972 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7973 | if (time >= (300 * HZ)) { |
| 7974 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 7975 | printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout " |
| 7976 | "(timeout=300s)\n", ioc->name); |
| 7977 | ioc->is_driver_loading = 0; |
| 7978 | return 1; |
| 7979 | } |
| 7980 | |
| 7981 | if (ioc->start_scan) |
| 7982 | return 0; |
| 7983 | |
| 7984 | if (ioc->start_scan_failed) { |
| 7985 | printk(MPT2SAS_INFO_FMT "port enable: FAILED with " |
| 7986 | "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed); |
| 7987 | ioc->is_driver_loading = 0; |
| 7988 | ioc->wait_for_discovery_to_complete = 0; |
| 7989 | ioc->remove_host = 1; |
| 7990 | return 1; |
| 7991 | } |
| 7992 | |
| 7993 | printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name); |
| 7994 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 7995 | |
| 7996 | if (ioc->wait_for_discovery_to_complete) { |
| 7997 | ioc->wait_for_discovery_to_complete = 0; |
| 7998 | _scsih_probe_devices(ioc); |
| 7999 | } |
| 8000 | mpt2sas_base_start_watchdog(ioc); |
| 8001 | ioc->is_driver_loading = 0; |
| 8002 | return 1; |
| 8003 | } |
| 8004 | |
| 8005 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8006 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8007 | * _scsih_probe - attach and add scsi host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8008 | * @pdev: PCI device struct |
| 8009 | * @id: pci device id |
| 8010 | * |
| 8011 | * Returns 0 success, anything else error. |
| 8012 | */ |
| 8013 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8014 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8015 | { |
| 8016 | struct MPT2SAS_ADAPTER *ioc; |
| 8017 | struct Scsi_Host *shost; |
| 8018 | |
| 8019 | shost = scsi_host_alloc(&scsih_driver_template, |
| 8020 | sizeof(struct MPT2SAS_ADAPTER)); |
| 8021 | if (!shost) |
| 8022 | return -ENODEV; |
| 8023 | |
| 8024 | /* init local params */ |
| 8025 | ioc = shost_priv(shost); |
| 8026 | memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER)); |
| 8027 | INIT_LIST_HEAD(&ioc->list); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 8028 | list_add_tail(&ioc->list, &mpt2sas_ioc_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8029 | ioc->shost = shost; |
| 8030 | ioc->id = mpt_ids++; |
| 8031 | sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id); |
| 8032 | ioc->pdev = pdev; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8033 | if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) { |
| 8034 | ioc->is_warpdrive = 1; |
| 8035 | ioc->hide_ir_msg = 1; |
| 8036 | } else |
| 8037 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8038 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; |
| 8039 | ioc->tm_cb_idx = tm_cb_idx; |
| 8040 | ioc->ctl_cb_idx = ctl_cb_idx; |
| 8041 | ioc->base_cb_idx = base_cb_idx; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8042 | ioc->port_enable_cb_idx = port_enable_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8043 | ioc->transport_cb_idx = transport_cb_idx; |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8044 | ioc->scsih_cb_idx = scsih_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8045 | ioc->config_cb_idx = config_cb_idx; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8046 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8047 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8048 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8049 | ioc->logging_level = logging_level; |
nagalakshmi.nandigama@lsi.com | 845a0e4 | 2011-12-01 07:42:04 +0530 | [diff] [blame] | 8050 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8051 | /* misc semaphores and spin locks */ |
Kashyap, Desai | d274213 | 2010-06-17 13:28:55 +0530 | [diff] [blame] | 8052 | mutex_init(&ioc->reset_in_progress_mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8053 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
| 8054 | spin_lock_init(&ioc->scsi_lookup_lock); |
| 8055 | spin_lock_init(&ioc->sas_device_lock); |
| 8056 | spin_lock_init(&ioc->sas_node_lock); |
| 8057 | spin_lock_init(&ioc->fw_event_lock); |
| 8058 | spin_lock_init(&ioc->raid_device_lock); |
| 8059 | |
| 8060 | INIT_LIST_HEAD(&ioc->sas_device_list); |
| 8061 | INIT_LIST_HEAD(&ioc->sas_device_init_list); |
| 8062 | INIT_LIST_HEAD(&ioc->sas_expander_list); |
| 8063 | INIT_LIST_HEAD(&ioc->fw_event_list); |
| 8064 | INIT_LIST_HEAD(&ioc->raid_device_list); |
| 8065 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8066 | INIT_LIST_HEAD(&ioc->delayed_tr_list); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8067 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8068 | |
| 8069 | /* init shost parameters */ |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 8070 | shost->max_cmd_len = 32; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8071 | shost->max_lun = max_lun; |
| 8072 | shost->transportt = mpt2sas_transport_template; |
| 8073 | shost->unique_id = ioc->id; |
| 8074 | |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8075 | if (max_sectors != 0xFFFF) { |
| 8076 | if (max_sectors < 64) { |
| 8077 | shost->max_sectors = 64; |
sreekanth.reddy@lsi.com | eece5de | 2012-07-17 15:56:09 +0530 | [diff] [blame] | 8078 | printk(MPT2SAS_WARN_FMT "Invalid value %d passed "\ |
| 8079 | "for max_sectors, range is 64 to 32767. Assigning "\ |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8080 | "value of 64.\n", ioc->name, max_sectors); |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 8081 | } else if (max_sectors > 32767) { |
| 8082 | shost->max_sectors = 32767; |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8083 | printk(MPT2SAS_WARN_FMT "Invalid value %d passed " |
| 8084 | "for max_sectors, range is 64 to 8192. Assigning " |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 8085 | "default value of 32767.\n", ioc->name, |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8086 | max_sectors); |
| 8087 | } else { |
| 8088 | shost->max_sectors = max_sectors & 0xFFFE; |
| 8089 | printk(MPT2SAS_INFO_FMT "The max_sectors value is " |
| 8090 | "set to %d\n", ioc->name, shost->max_sectors); |
| 8091 | } |
| 8092 | } |
| 8093 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8094 | if ((scsi_add_host(shost, &pdev->dev))) { |
| 8095 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8096 | ioc->name, __FILE__, __LINE__, __func__); |
| 8097 | list_del(&ioc->list); |
| 8098 | goto out_add_shost_fail; |
| 8099 | } |
| 8100 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 8101 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 8102 | | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8103 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 8104 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8105 | /* event thread */ |
| 8106 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), |
| 8107 | "fw_event%d", ioc->id); |
| 8108 | ioc->firmware_event_thread = create_singlethread_workqueue( |
| 8109 | ioc->firmware_event_name); |
| 8110 | if (!ioc->firmware_event_thread) { |
| 8111 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8112 | ioc->name, __FILE__, __LINE__, __func__); |
| 8113 | goto out_thread_fail; |
| 8114 | } |
| 8115 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8116 | ioc->is_driver_loading = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8117 | if ((mpt2sas_base_attach(ioc))) { |
| 8118 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8119 | ioc->name, __FILE__, __LINE__, __func__); |
| 8120 | goto out_attach_fail; |
| 8121 | } |
| 8122 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8123 | if (ioc->is_warpdrive) { |
| 8124 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) |
| 8125 | ioc->hide_drives = 0; |
| 8126 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) |
| 8127 | ioc->hide_drives = 1; |
| 8128 | else { |
| 8129 | if (_scsih_get_num_volumes(ioc)) |
| 8130 | ioc->hide_drives = 1; |
| 8131 | else |
| 8132 | ioc->hide_drives = 0; |
| 8133 | } |
| 8134 | } else |
| 8135 | ioc->hide_drives = 0; |
nagalakshmi.nandigama@lsi.com | 2cb6fc8 | 2011-12-13 09:29:15 +0530 | [diff] [blame] | 8136 | scsi_scan_host(shost); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8137 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8138 | return 0; |
| 8139 | |
| 8140 | out_attach_fail: |
| 8141 | destroy_workqueue(ioc->firmware_event_thread); |
| 8142 | out_thread_fail: |
| 8143 | list_del(&ioc->list); |
| 8144 | scsi_remove_host(shost); |
| 8145 | out_add_shost_fail: |
Tomas Henzl | f555e05 | 2012-04-17 15:24:48 +0200 | [diff] [blame] | 8146 | scsi_host_put(shost); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8147 | return -ENODEV; |
| 8148 | } |
| 8149 | |
| 8150 | #ifdef CONFIG_PM |
| 8151 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8152 | * _scsih_suspend - power management suspend main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8153 | * @pdev: PCI device struct |
| 8154 | * @state: PM state change to (usually PCI_D3) |
| 8155 | * |
| 8156 | * Returns 0 success, anything else error. |
| 8157 | */ |
| 8158 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8159 | _scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8160 | { |
| 8161 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8162 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 8163 | pci_power_t device_state; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8164 | |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 8165 | mpt2sas_base_stop_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8166 | scsi_block_requests(shost); |
| 8167 | device_state = pci_choose_state(pdev, state); |
| 8168 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering " |
| 8169 | "operating state [D%d]\n", ioc->name, pdev, |
| 8170 | pci_name(pdev), device_state); |
| 8171 | |
| 8172 | mpt2sas_base_free_resources(ioc); |
| 8173 | pci_save_state(pdev); |
| 8174 | pci_disable_device(pdev); |
| 8175 | pci_set_power_state(pdev, device_state); |
| 8176 | return 0; |
| 8177 | } |
| 8178 | |
| 8179 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8180 | * _scsih_resume - power management resume main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8181 | * @pdev: PCI device struct |
| 8182 | * |
| 8183 | * Returns 0 success, anything else error. |
| 8184 | */ |
| 8185 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8186 | _scsih_resume(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8187 | { |
| 8188 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8189 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 8190 | pci_power_t device_state = pdev->current_state; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8191 | int r; |
| 8192 | |
| 8193 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous " |
| 8194 | "operating state [D%d]\n", ioc->name, pdev, |
| 8195 | pci_name(pdev), device_state); |
| 8196 | |
| 8197 | pci_set_power_state(pdev, PCI_D0); |
| 8198 | pci_enable_wake(pdev, PCI_D0, 0); |
| 8199 | pci_restore_state(pdev); |
| 8200 | ioc->pdev = pdev; |
| 8201 | r = mpt2sas_base_map_resources(ioc); |
| 8202 | if (r) |
| 8203 | return r; |
| 8204 | |
| 8205 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET); |
| 8206 | scsi_unblock_requests(shost); |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 8207 | mpt2sas_base_start_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8208 | return 0; |
| 8209 | } |
| 8210 | #endif /* CONFIG_PM */ |
| 8211 | |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8212 | /** |
| 8213 | * _scsih_pci_error_detected - Called when a PCI error is detected. |
| 8214 | * @pdev: PCI device struct |
| 8215 | * @state: PCI channel state |
| 8216 | * |
| 8217 | * Description: Called when a PCI error is detected. |
| 8218 | * |
| 8219 | * Return value: |
| 8220 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT |
| 8221 | */ |
| 8222 | static pci_ers_result_t |
| 8223 | _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 8224 | { |
| 8225 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8226 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8227 | |
| 8228 | printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n", |
| 8229 | ioc->name, state); |
| 8230 | |
| 8231 | switch (state) { |
| 8232 | case pci_channel_io_normal: |
| 8233 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 8234 | case pci_channel_io_frozen: |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8235 | /* Fatal error, prepare for slot reset */ |
| 8236 | ioc->pci_error_recovery = 1; |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8237 | scsi_block_requests(ioc->shost); |
| 8238 | mpt2sas_base_stop_watchdog(ioc); |
| 8239 | mpt2sas_base_free_resources(ioc); |
| 8240 | return PCI_ERS_RESULT_NEED_RESET; |
| 8241 | case pci_channel_io_perm_failure: |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8242 | /* Permanent error, prepare for device removal */ |
| 8243 | ioc->pci_error_recovery = 1; |
| 8244 | mpt2sas_base_stop_watchdog(ioc); |
| 8245 | _scsih_flush_running_cmds(ioc); |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8246 | return PCI_ERS_RESULT_DISCONNECT; |
| 8247 | } |
| 8248 | return PCI_ERS_RESULT_NEED_RESET; |
| 8249 | } |
| 8250 | |
| 8251 | /** |
| 8252 | * _scsih_pci_slot_reset - Called when PCI slot has been reset. |
| 8253 | * @pdev: PCI device struct |
| 8254 | * |
| 8255 | * Description: This routine is called by the pci error recovery |
| 8256 | * code after the PCI slot has been reset, just before we |
| 8257 | * should resume normal operations. |
| 8258 | */ |
| 8259 | static pci_ers_result_t |
| 8260 | _scsih_pci_slot_reset(struct pci_dev *pdev) |
| 8261 | { |
| 8262 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8263 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8264 | int rc; |
| 8265 | |
| 8266 | printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n", |
| 8267 | ioc->name); |
| 8268 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8269 | ioc->pci_error_recovery = 0; |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8270 | ioc->pdev = pdev; |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8271 | pci_restore_state(pdev); |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8272 | rc = mpt2sas_base_map_resources(ioc); |
| 8273 | if (rc) |
| 8274 | return PCI_ERS_RESULT_DISCONNECT; |
| 8275 | |
| 8276 | |
| 8277 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 8278 | FORCE_BIG_HAMMER); |
| 8279 | |
| 8280 | printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name, |
| 8281 | (rc == 0) ? "success" : "failed"); |
| 8282 | |
| 8283 | if (!rc) |
| 8284 | return PCI_ERS_RESULT_RECOVERED; |
| 8285 | else |
| 8286 | return PCI_ERS_RESULT_DISCONNECT; |
| 8287 | } |
| 8288 | |
| 8289 | /** |
| 8290 | * _scsih_pci_resume() - resume normal ops after PCI reset |
| 8291 | * @pdev: pointer to PCI device |
| 8292 | * |
| 8293 | * Called when the error recovery driver tells us that its |
| 8294 | * OK to resume normal operation. Use completion to allow |
| 8295 | * halted scsi ops to resume. |
| 8296 | */ |
| 8297 | static void |
| 8298 | _scsih_pci_resume(struct pci_dev *pdev) |
| 8299 | { |
| 8300 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8301 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8302 | |
| 8303 | printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name); |
| 8304 | |
| 8305 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8306 | mpt2sas_base_start_watchdog(ioc); |
| 8307 | scsi_unblock_requests(ioc->shost); |
| 8308 | } |
| 8309 | |
| 8310 | /** |
| 8311 | * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
| 8312 | * @pdev: pointer to PCI device |
| 8313 | */ |
| 8314 | static pci_ers_result_t |
| 8315 | _scsih_pci_mmio_enabled(struct pci_dev *pdev) |
| 8316 | { |
| 8317 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8318 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8319 | |
| 8320 | printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n", |
| 8321 | ioc->name); |
| 8322 | |
| 8323 | /* TODO - dump whatever for debugging purposes */ |
| 8324 | |
| 8325 | /* Request a slot reset. */ |
| 8326 | return PCI_ERS_RESULT_NEED_RESET; |
| 8327 | } |
| 8328 | |
| 8329 | static struct pci_error_handlers _scsih_err_handler = { |
| 8330 | .error_detected = _scsih_pci_error_detected, |
| 8331 | .mmio_enabled = _scsih_pci_mmio_enabled, |
| 8332 | .slot_reset = _scsih_pci_slot_reset, |
| 8333 | .resume = _scsih_pci_resume, |
| 8334 | }; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8335 | |
| 8336 | static struct pci_driver scsih_driver = { |
| 8337 | .name = MPT2SAS_DRIVER_NAME, |
| 8338 | .id_table = scsih_pci_table, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8339 | .probe = _scsih_probe, |
| 8340 | .remove = __devexit_p(_scsih_remove), |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8341 | .shutdown = _scsih_shutdown, |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8342 | .err_handler = &_scsih_err_handler, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8343 | #ifdef CONFIG_PM |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8344 | .suspend = _scsih_suspend, |
| 8345 | .resume = _scsih_resume, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8346 | #endif |
| 8347 | }; |
| 8348 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8349 | /* raid transport support */ |
| 8350 | static struct raid_function_template mpt2sas_raid_functions = { |
| 8351 | .cookie = &scsih_driver_template, |
| 8352 | .is_raid = _scsih_is_raid, |
| 8353 | .get_resync = _scsih_get_resync, |
| 8354 | .get_state = _scsih_get_state, |
| 8355 | }; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8356 | |
| 8357 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8358 | * _scsih_init - main entry point for this driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8359 | * |
| 8360 | * Returns 0 success, anything else error. |
| 8361 | */ |
| 8362 | static int __init |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8363 | _scsih_init(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8364 | { |
| 8365 | int error; |
| 8366 | |
| 8367 | mpt_ids = 0; |
| 8368 | printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME, |
| 8369 | MPT2SAS_DRIVER_VERSION); |
| 8370 | |
| 8371 | mpt2sas_transport_template = |
| 8372 | sas_attach_transport(&mpt2sas_transport_functions); |
| 8373 | if (!mpt2sas_transport_template) |
| 8374 | return -ENODEV; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8375 | /* raid transport support */ |
| 8376 | mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions); |
| 8377 | if (!mpt2sas_raid_template) { |
| 8378 | sas_release_transport(mpt2sas_transport_template); |
| 8379 | return -ENODEV; |
| 8380 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8381 | |
| 8382 | mpt2sas_base_initialize_callback_handler(); |
| 8383 | |
| 8384 | /* queuecommand callback hander */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8385 | scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8386 | |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 8387 | /* task management callback handler */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8388 | tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8389 | |
| 8390 | /* base internal commands callback handler */ |
| 8391 | 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] | 8392 | port_enable_cb_idx = mpt2sas_base_register_callback_handler( |
| 8393 | mpt2sas_port_enable_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8394 | |
| 8395 | /* transport internal commands callback handler */ |
| 8396 | transport_cb_idx = mpt2sas_base_register_callback_handler( |
| 8397 | mpt2sas_transport_done); |
| 8398 | |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8399 | /* scsih internal commands callback handler */ |
| 8400 | scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done); |
| 8401 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8402 | /* configuration page API internal commands callback handler */ |
| 8403 | config_cb_idx = mpt2sas_base_register_callback_handler( |
| 8404 | mpt2sas_config_done); |
| 8405 | |
| 8406 | /* ctl module callback handler */ |
| 8407 | ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done); |
| 8408 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8409 | tm_tr_cb_idx = mpt2sas_base_register_callback_handler( |
| 8410 | _scsih_tm_tr_complete); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8411 | |
| 8412 | tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler( |
| 8413 | _scsih_tm_volume_tr_complete); |
| 8414 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8415 | tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler( |
| 8416 | _scsih_sas_control_complete); |
| 8417 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8418 | mpt2sas_ctl_init(); |
| 8419 | |
| 8420 | error = pci_register_driver(&scsih_driver); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8421 | if (error) { |
| 8422 | /* raid transport support */ |
| 8423 | raid_class_release(mpt2sas_raid_template); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8424 | sas_release_transport(mpt2sas_transport_template); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8425 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8426 | |
| 8427 | return error; |
| 8428 | } |
| 8429 | |
| 8430 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8431 | * _scsih_exit - exit point for this driver (when it is a module). |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8432 | * |
| 8433 | * Returns 0 success, anything else error. |
| 8434 | */ |
| 8435 | static void __exit |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8436 | _scsih_exit(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8437 | { |
| 8438 | printk(KERN_INFO "mpt2sas version %s unloading\n", |
| 8439 | MPT2SAS_DRIVER_VERSION); |
| 8440 | |
| 8441 | pci_unregister_driver(&scsih_driver); |
| 8442 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8443 | mpt2sas_ctl_exit(); |
| 8444 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8445 | mpt2sas_base_release_callback_handler(scsi_io_cb_idx); |
| 8446 | mpt2sas_base_release_callback_handler(tm_cb_idx); |
| 8447 | mpt2sas_base_release_callback_handler(base_cb_idx); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8448 | mpt2sas_base_release_callback_handler(port_enable_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8449 | mpt2sas_base_release_callback_handler(transport_cb_idx); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8450 | mpt2sas_base_release_callback_handler(scsih_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8451 | mpt2sas_base_release_callback_handler(config_cb_idx); |
| 8452 | mpt2sas_base_release_callback_handler(ctl_cb_idx); |
| 8453 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8454 | mpt2sas_base_release_callback_handler(tm_tr_cb_idx); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8455 | mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8456 | mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx); |
| 8457 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8458 | /* raid transport support */ |
| 8459 | raid_class_release(mpt2sas_raid_template); |
| 8460 | sas_release_transport(mpt2sas_transport_template); |
| 8461 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8462 | } |
| 8463 | |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8464 | module_init(_scsih_init); |
| 8465 | module_exit(_scsih_exit); |