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 |
Kashyap, Desai | 31b7f2e | 2010-03-17 16:28:04 +0530 | [diff] [blame] | 5 | * Copyright (C) 2007-2010 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 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 122 | /** |
| 123 | * struct sense_info - common structure for obtaining sense keys |
| 124 | * @skey: sense key |
| 125 | * @asc: additional sense code |
| 126 | * @ascq: additional sense code qualifier |
| 127 | */ |
| 128 | struct sense_info { |
| 129 | u8 skey; |
| 130 | u8 asc; |
| 131 | u8 ascq; |
| 132 | }; |
| 133 | |
| 134 | |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 135 | #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 136 | #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD) |
| 137 | #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 138 | /** |
| 139 | * struct fw_event_work - firmware event struct |
| 140 | * @list: link list framework |
| 141 | * @work: work object (ioc->fault_reset_work_q) |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 142 | * @cancel_pending_work: flag set during reset handling |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 143 | * @ioc: per adapter object |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 144 | * @device_handle: device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 145 | * @VF_ID: virtual function id |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 146 | * @VP_ID: virtual port id |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 147 | * @ignore: flag meaning this event has been marked to ignore |
| 148 | * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h |
| 149 | * @event_data: reply event data payload follows |
| 150 | * |
| 151 | * This object stored on ioc->fw_event_list. |
| 152 | */ |
| 153 | struct fw_event_work { |
| 154 | struct list_head list; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 155 | u8 cancel_pending_work; |
| 156 | struct delayed_work delayed_work; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 157 | struct MPT2SAS_ADAPTER *ioc; |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 158 | u16 device_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 159 | u8 VF_ID; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 160 | u8 VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 161 | u8 ignore; |
| 162 | u16 event; |
| 163 | void *event_data; |
| 164 | }; |
| 165 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 166 | /* raid transport support */ |
| 167 | static struct raid_template *mpt2sas_raid_template; |
| 168 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 169 | /** |
| 170 | * struct _scsi_io_transfer - scsi io transfer |
| 171 | * @handle: sas device handle (assigned by firmware) |
| 172 | * @is_raid: flag set for hidden raid components |
| 173 | * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE, |
| 174 | * @data_length: data transfer length |
| 175 | * @data_dma: dma pointer to data |
| 176 | * @sense: sense data |
| 177 | * @lun: lun number |
| 178 | * @cdb_length: cdb length |
| 179 | * @cdb: cdb contents |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 180 | * @timeout: timeout for this command |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 181 | * @VF_ID: virtual function id |
| 182 | * @VP_ID: virtual port id |
| 183 | * @valid_reply: flag set for reply message |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 184 | * @sense_length: sense length |
| 185 | * @ioc_status: ioc status |
| 186 | * @scsi_state: scsi state |
| 187 | * @scsi_status: scsi staus |
| 188 | * @log_info: log information |
| 189 | * @transfer_length: data length transfer when there is a reply message |
| 190 | * |
| 191 | * Used for sending internal scsi commands to devices within this module. |
| 192 | * Refer to _scsi_send_scsi_io(). |
| 193 | */ |
| 194 | struct _scsi_io_transfer { |
| 195 | u16 handle; |
| 196 | u8 is_raid; |
| 197 | enum dma_data_direction dir; |
| 198 | u32 data_length; |
| 199 | dma_addr_t data_dma; |
| 200 | u8 sense[SCSI_SENSE_BUFFERSIZE]; |
| 201 | u32 lun; |
| 202 | u8 cdb_length; |
| 203 | u8 cdb[32]; |
| 204 | u8 timeout; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 205 | u8 VF_ID; |
| 206 | u8 VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 207 | u8 valid_reply; |
| 208 | /* the following bits are only valid when 'valid_reply = 1' */ |
| 209 | u32 sense_length; |
| 210 | u16 ioc_status; |
| 211 | u8 scsi_state; |
| 212 | u8 scsi_status; |
| 213 | u32 log_info; |
| 214 | u32 transfer_length; |
| 215 | }; |
| 216 | |
| 217 | /* |
| 218 | * The pci device ids are defined in mpi/mpi2_cnfg.h. |
| 219 | */ |
| 220 | static struct pci_device_id scsih_pci_table[] = { |
| 221 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, |
| 222 | PCI_ANY_ID, PCI_ANY_ID }, |
| 223 | /* Falcon ~ 2008*/ |
| 224 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, |
| 225 | PCI_ANY_ID, PCI_ANY_ID }, |
| 226 | /* Liberator ~ 2108 */ |
| 227 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, |
| 228 | PCI_ANY_ID, PCI_ANY_ID }, |
| 229 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, |
| 230 | PCI_ANY_ID, PCI_ANY_ID }, |
| 231 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, |
| 232 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 233 | /* Meteor ~ 2116 */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 234 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, |
| 235 | PCI_ANY_ID, PCI_ANY_ID }, |
| 236 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, |
| 237 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 238 | /* Thunderbolt ~ 2208 */ |
| 239 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, |
| 240 | PCI_ANY_ID, PCI_ANY_ID }, |
| 241 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, |
| 242 | PCI_ANY_ID, PCI_ANY_ID }, |
| 243 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, |
| 244 | PCI_ANY_ID, PCI_ANY_ID }, |
| 245 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, |
| 246 | PCI_ANY_ID, PCI_ANY_ID }, |
| 247 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, |
| 248 | PCI_ANY_ID, PCI_ANY_ID }, |
| 249 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, |
| 250 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 203d65b | 2010-06-17 13:37:59 +0530 | [diff] [blame] | 251 | /* Mustang ~ 2308 */ |
| 252 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 253 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 203d65b | 2010-06-17 13:37:59 +0530 | [diff] [blame] | 254 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, |
| 255 | PCI_ANY_ID, PCI_ANY_ID }, |
| 256 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, |
Kashyap, Desai | db27136 | 2009-09-23 17:24:27 +0530 | [diff] [blame] | 257 | PCI_ANY_ID, PCI_ANY_ID }, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 258 | /* SSS6200 */ |
| 259 | { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, |
| 260 | PCI_ANY_ID, PCI_ANY_ID }, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 261 | {0} /* Terminating entry */ |
| 262 | }; |
| 263 | MODULE_DEVICE_TABLE(pci, scsih_pci_table); |
| 264 | |
| 265 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 266 | * _scsih_set_debug_level - global setting of ioc->logging_level. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 267 | * |
| 268 | * Note: The logging levels are defined in mpt2sas_debug.h. |
| 269 | */ |
| 270 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 271 | _scsih_set_debug_level(const char *val, struct kernel_param *kp) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 272 | { |
| 273 | int ret = param_set_int(val, kp); |
| 274 | struct MPT2SAS_ADAPTER *ioc; |
| 275 | |
| 276 | if (ret) |
| 277 | return ret; |
| 278 | |
| 279 | printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 280 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 281 | ioc->logging_level = logging_level; |
| 282 | return 0; |
| 283 | } |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 284 | module_param_call(logging_level, _scsih_set_debug_level, param_get_int, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 285 | &logging_level, 0644); |
| 286 | |
| 287 | /** |
| 288 | * _scsih_srch_boot_sas_address - search based on sas_address |
| 289 | * @sas_address: sas address |
| 290 | * @boot_device: boot device object from bios page 2 |
| 291 | * |
| 292 | * Returns 1 when there's a match, 0 means no match. |
| 293 | */ |
| 294 | static inline int |
| 295 | _scsih_srch_boot_sas_address(u64 sas_address, |
| 296 | Mpi2BootDeviceSasWwid_t *boot_device) |
| 297 | { |
| 298 | return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * _scsih_srch_boot_device_name - search based on device name |
| 303 | * @device_name: device name specified in INDENTIFY fram |
| 304 | * @boot_device: boot device object from bios page 2 |
| 305 | * |
| 306 | * Returns 1 when there's a match, 0 means no match. |
| 307 | */ |
| 308 | static inline int |
| 309 | _scsih_srch_boot_device_name(u64 device_name, |
| 310 | Mpi2BootDeviceDeviceName_t *boot_device) |
| 311 | { |
| 312 | return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot |
| 317 | * @enclosure_logical_id: enclosure logical id |
| 318 | * @slot_number: slot number |
| 319 | * @boot_device: boot device object from bios page 2 |
| 320 | * |
| 321 | * Returns 1 when there's a match, 0 means no match. |
| 322 | */ |
| 323 | static inline int |
| 324 | _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number, |
| 325 | Mpi2BootDeviceEnclosureSlot_t *boot_device) |
| 326 | { |
| 327 | return (enclosure_logical_id == le64_to_cpu(boot_device-> |
| 328 | EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device-> |
| 329 | SlotNumber)) ? 1 : 0; |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * _scsih_is_boot_device - search for matching boot device. |
| 334 | * @sas_address: sas address |
| 335 | * @device_name: device name specified in INDENTIFY fram |
| 336 | * @enclosure_logical_id: enclosure logical id |
| 337 | * @slot_number: slot number |
| 338 | * @form: specifies boot device form |
| 339 | * @boot_device: boot device object from bios page 2 |
| 340 | * |
| 341 | * Returns 1 when there's a match, 0 means no match. |
| 342 | */ |
| 343 | static int |
| 344 | _scsih_is_boot_device(u64 sas_address, u64 device_name, |
| 345 | u64 enclosure_logical_id, u16 slot, u8 form, |
| 346 | Mpi2BiosPage2BootDevice_t *boot_device) |
| 347 | { |
| 348 | int rc = 0; |
| 349 | |
| 350 | switch (form) { |
| 351 | case MPI2_BIOSPAGE2_FORM_SAS_WWID: |
| 352 | if (!sas_address) |
| 353 | break; |
| 354 | rc = _scsih_srch_boot_sas_address( |
| 355 | sas_address, &boot_device->SasWwid); |
| 356 | break; |
| 357 | case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT: |
| 358 | if (!enclosure_logical_id) |
| 359 | break; |
| 360 | rc = _scsih_srch_boot_encl_slot( |
| 361 | enclosure_logical_id, |
| 362 | slot, &boot_device->EnclosureSlot); |
| 363 | break; |
| 364 | case MPI2_BIOSPAGE2_FORM_DEVICE_NAME: |
| 365 | if (!device_name) |
| 366 | break; |
| 367 | rc = _scsih_srch_boot_device_name( |
| 368 | device_name, &boot_device->DeviceName); |
| 369 | break; |
| 370 | case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED: |
| 371 | break; |
| 372 | } |
| 373 | |
| 374 | return rc; |
| 375 | } |
| 376 | |
| 377 | /** |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 378 | * _scsih_get_sas_address - set the sas_address for given device handle |
| 379 | * @handle: device handle |
| 380 | * @sas_address: sas address |
| 381 | * |
| 382 | * Returns 0 success, non-zero when failure |
| 383 | */ |
| 384 | static int |
| 385 | _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle, |
| 386 | u64 *sas_address) |
| 387 | { |
| 388 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 389 | Mpi2ConfigReply_t mpi_reply; |
| 390 | u32 ioc_status; |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 391 | *sas_address = 0; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 392 | |
| 393 | if (handle <= ioc->sas_hba.num_phys) { |
| 394 | *sas_address = ioc->sas_hba.sas_address; |
| 395 | return 0; |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 396 | } |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 397 | |
| 398 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 399 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 400 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 401 | __FILE__, __LINE__, __func__); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 402 | return -ENXIO; |
| 403 | } |
| 404 | |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 405 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 406 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { |
| 407 | *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 408 | return 0; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 409 | } |
| 410 | |
nagalakshmi.nandigama@lsi.com | 24f09b5 | 2011-10-19 15:36:47 +0530 | [diff] [blame] | 411 | /* we hit this becuase the given parent handle doesn't exist */ |
| 412 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 413 | return -ENXIO; |
| 414 | /* else error case */ |
| 415 | printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), " |
| 416 | "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status, |
| 417 | __FILE__, __LINE__, __func__); |
| 418 | return -EIO; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 422 | * _scsih_determine_boot_device - determine boot device. |
| 423 | * @ioc: per adapter object |
| 424 | * @device: either sas_device or raid_device object |
| 425 | * @is_raid: [flag] 1 = raid object, 0 = sas object |
| 426 | * |
| 427 | * Determines whether this device should be first reported device to |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 428 | * 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] | 429 | * There are primary, alternate, and current entries in bios page 2. The order |
| 430 | * priority is primary, alternate, then current. This routine saves |
| 431 | * the corresponding device object and is_raid flag in the ioc object. |
| 432 | * The saved data to be used later in _scsih_probe_boot_devices(). |
| 433 | */ |
| 434 | static void |
| 435 | _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc, |
| 436 | void *device, u8 is_raid) |
| 437 | { |
| 438 | struct _sas_device *sas_device; |
| 439 | struct _raid_device *raid_device; |
| 440 | u64 sas_address; |
| 441 | u64 device_name; |
| 442 | u64 enclosure_logical_id; |
| 443 | u16 slot; |
| 444 | |
| 445 | /* only process this function when driver loads */ |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 446 | if (!ioc->is_driver_loading) |
| 447 | return; |
| 448 | |
| 449 | /* no Bios, return immediately */ |
| 450 | if (!ioc->bios_pg3.BiosVersion) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 451 | return; |
| 452 | |
| 453 | if (!is_raid) { |
| 454 | sas_device = device; |
| 455 | sas_address = sas_device->sas_address; |
| 456 | device_name = sas_device->device_name; |
| 457 | enclosure_logical_id = sas_device->enclosure_logical_id; |
| 458 | slot = sas_device->slot; |
| 459 | } else { |
| 460 | raid_device = device; |
| 461 | sas_address = raid_device->wwid; |
| 462 | device_name = 0; |
| 463 | enclosure_logical_id = 0; |
| 464 | slot = 0; |
| 465 | } |
| 466 | |
| 467 | if (!ioc->req_boot_device.device) { |
| 468 | if (_scsih_is_boot_device(sas_address, device_name, |
| 469 | enclosure_logical_id, slot, |
| 470 | (ioc->bios_pg2.ReqBootDeviceForm & |
| 471 | MPI2_BIOSPAGE2_FORM_MASK), |
| 472 | &ioc->bios_pg2.RequestedBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 473 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 474 | "%s: req_boot_device(0x%016llx)\n", |
| 475 | ioc->name, __func__, |
| 476 | (unsigned long long)sas_address)); |
| 477 | ioc->req_boot_device.device = device; |
| 478 | ioc->req_boot_device.is_raid = is_raid; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | if (!ioc->req_alt_boot_device.device) { |
| 483 | if (_scsih_is_boot_device(sas_address, device_name, |
| 484 | enclosure_logical_id, slot, |
| 485 | (ioc->bios_pg2.ReqAltBootDeviceForm & |
| 486 | MPI2_BIOSPAGE2_FORM_MASK), |
| 487 | &ioc->bios_pg2.RequestedAltBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 488 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 489 | "%s: req_alt_boot_device(0x%016llx)\n", |
| 490 | ioc->name, __func__, |
| 491 | (unsigned long long)sas_address)); |
| 492 | ioc->req_alt_boot_device.device = device; |
| 493 | ioc->req_alt_boot_device.is_raid = is_raid; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | if (!ioc->current_boot_device.device) { |
| 498 | if (_scsih_is_boot_device(sas_address, device_name, |
| 499 | enclosure_logical_id, slot, |
| 500 | (ioc->bios_pg2.CurrentBootDeviceForm & |
| 501 | MPI2_BIOSPAGE2_FORM_MASK), |
| 502 | &ioc->bios_pg2.CurrentBootDevice)) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 503 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 504 | "%s: current_boot_device(0x%016llx)\n", |
| 505 | ioc->name, __func__, |
| 506 | (unsigned long long)sas_address)); |
| 507 | ioc->current_boot_device.device = device; |
| 508 | ioc->current_boot_device.is_raid = is_raid; |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | /** |
| 514 | * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search |
| 515 | * @ioc: per adapter object |
| 516 | * @sas_address: sas address |
| 517 | * Context: Calling function should acquire ioc->sas_device_lock |
| 518 | * |
| 519 | * This searches for sas_device based on sas_address, then return sas_device |
| 520 | * object. |
| 521 | */ |
| 522 | struct _sas_device * |
| 523 | mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 524 | u64 sas_address) |
| 525 | { |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 526 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 527 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 528 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) |
| 529 | if (sas_device->sas_address == sas_address) |
| 530 | return 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_init_list, list) |
| 533 | if (sas_device->sas_address == sas_address) |
| 534 | return sas_device; |
| 535 | |
| 536 | return NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /** |
| 540 | * _scsih_sas_device_find_by_handle - sas device search |
| 541 | * @ioc: per adapter object |
| 542 | * @handle: sas device handle (assigned by firmware) |
| 543 | * Context: Calling function should acquire ioc->sas_device_lock |
| 544 | * |
| 545 | * This searches for sas_device based on sas_address, then return sas_device |
| 546 | * object. |
| 547 | */ |
| 548 | static struct _sas_device * |
| 549 | _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 550 | { |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 551 | struct _sas_device *sas_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 552 | |
Kashyap, Desai | cd9843f | 2010-03-09 16:32:17 +0530 | [diff] [blame] | 553 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) |
| 554 | if (sas_device->handle == handle) |
| 555 | return 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_init_list, list) |
| 558 | if (sas_device->handle == handle) |
| 559 | return sas_device; |
| 560 | |
| 561 | return NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | /** |
| 565 | * _scsih_sas_device_remove - remove sas_device from list. |
| 566 | * @ioc: per adapter object |
| 567 | * @sas_device: the sas_device object |
| 568 | * Context: This function will acquire ioc->sas_device_lock. |
| 569 | * |
| 570 | * Removing object and freeing associated memory from the ioc->sas_device_list. |
| 571 | */ |
| 572 | static void |
| 573 | _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc, |
| 574 | struct _sas_device *sas_device) |
| 575 | { |
| 576 | unsigned long flags; |
| 577 | |
Kashyap, Desai | 980ead3 | 2010-04-08 17:55:22 +0530 | [diff] [blame] | 578 | if (!sas_device) |
| 579 | return; |
| 580 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 581 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 582 | list_del(&sas_device->list); |
| 583 | kfree(sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 584 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 585 | } |
| 586 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 587 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 588 | /** |
| 589 | * _scsih_sas_device_add - insert sas_device to the list. |
| 590 | * @ioc: per adapter object |
| 591 | * @sas_device: the sas_device object |
| 592 | * Context: This function will acquire ioc->sas_device_lock. |
| 593 | * |
| 594 | * Adding new object to the ioc->sas_device_list. |
| 595 | */ |
| 596 | static void |
| 597 | _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc, |
| 598 | struct _sas_device *sas_device) |
| 599 | { |
| 600 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 601 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 602 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 603 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 604 | sas_device->handle, (unsigned long long)sas_device->sas_address)); |
| 605 | |
| 606 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 607 | list_add_tail(&sas_device->list, &ioc->sas_device_list); |
| 608 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 609 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 610 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 611 | sas_device->sas_address_parent)) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 612 | _scsih_sas_device_remove(ioc, sas_device); |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 613 | } else if (!sas_device->starget) { |
| 614 | /* When asyn scanning is enabled, its not possible to remove |
| 615 | * devices while scanning is turned on due to an oops in |
| 616 | * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start() |
| 617 | */ |
| 618 | if (!ioc->is_driver_loading) |
| 619 | mpt2sas_transport_port_remove(ioc, |
| 620 | sas_device->sas_address, |
| 621 | sas_device->sas_address_parent); |
| 622 | _scsih_sas_device_remove(ioc, sas_device); |
| 623 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | /** |
| 627 | * _scsih_sas_device_init_add - insert sas_device to the list. |
| 628 | * @ioc: per adapter object |
| 629 | * @sas_device: the sas_device object |
| 630 | * Context: This function will acquire ioc->sas_device_lock. |
| 631 | * |
| 632 | * Adding new object at driver load time to the ioc->sas_device_init_list. |
| 633 | */ |
| 634 | static void |
| 635 | _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc, |
| 636 | struct _sas_device *sas_device) |
| 637 | { |
| 638 | unsigned long flags; |
| 639 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 640 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 641 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__, |
| 642 | sas_device->handle, (unsigned long long)sas_device->sas_address)); |
| 643 | |
| 644 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 645 | list_add_tail(&sas_device->list, &ioc->sas_device_init_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 646 | _scsih_determine_boot_device(ioc, sas_device, 0); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 647 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 651 | * _scsih_raid_device_find_by_id - raid device search |
| 652 | * @ioc: per adapter object |
| 653 | * @id: sas device target id |
| 654 | * @channel: sas device channel |
| 655 | * Context: Calling function should acquire ioc->raid_device_lock |
| 656 | * |
| 657 | * This searches for raid_device based on target id, then return raid_device |
| 658 | * object. |
| 659 | */ |
| 660 | static struct _raid_device * |
| 661 | _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel) |
| 662 | { |
| 663 | struct _raid_device *raid_device, *r; |
| 664 | |
| 665 | r = NULL; |
| 666 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 667 | if (raid_device->id == id && raid_device->channel == channel) { |
| 668 | r = raid_device; |
| 669 | goto out; |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | out: |
| 674 | return r; |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | * _scsih_raid_device_find_by_handle - raid device search |
| 679 | * @ioc: per adapter object |
| 680 | * @handle: sas device handle (assigned by firmware) |
| 681 | * Context: Calling function should acquire ioc->raid_device_lock |
| 682 | * |
| 683 | * This searches for raid_device based on handle, then return raid_device |
| 684 | * object. |
| 685 | */ |
| 686 | static struct _raid_device * |
| 687 | _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 688 | { |
| 689 | struct _raid_device *raid_device, *r; |
| 690 | |
| 691 | r = NULL; |
| 692 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 693 | if (raid_device->handle != handle) |
| 694 | continue; |
| 695 | r = raid_device; |
| 696 | goto out; |
| 697 | } |
| 698 | |
| 699 | out: |
| 700 | return r; |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * _scsih_raid_device_find_by_wwid - raid device search |
| 705 | * @ioc: per adapter object |
| 706 | * @handle: sas device handle (assigned by firmware) |
| 707 | * Context: Calling function should acquire ioc->raid_device_lock |
| 708 | * |
| 709 | * This searches for raid_device based on wwid, then return raid_device |
| 710 | * object. |
| 711 | */ |
| 712 | static struct _raid_device * |
| 713 | _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid) |
| 714 | { |
| 715 | struct _raid_device *raid_device, *r; |
| 716 | |
| 717 | r = NULL; |
| 718 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 719 | if (raid_device->wwid != wwid) |
| 720 | continue; |
| 721 | r = raid_device; |
| 722 | goto out; |
| 723 | } |
| 724 | |
| 725 | out: |
| 726 | return r; |
| 727 | } |
| 728 | |
| 729 | /** |
| 730 | * _scsih_raid_device_add - add raid_device object |
| 731 | * @ioc: per adapter object |
| 732 | * @raid_device: raid_device object |
| 733 | * |
| 734 | * This is added to the raid_device_list link list. |
| 735 | */ |
| 736 | static void |
| 737 | _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc, |
| 738 | struct _raid_device *raid_device) |
| 739 | { |
| 740 | unsigned long flags; |
| 741 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 742 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 743 | "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__, |
| 744 | raid_device->handle, (unsigned long long)raid_device->wwid)); |
| 745 | |
| 746 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 747 | list_add_tail(&raid_device->list, &ioc->raid_device_list); |
| 748 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 749 | } |
| 750 | |
| 751 | /** |
| 752 | * _scsih_raid_device_remove - delete raid_device object |
| 753 | * @ioc: per adapter object |
| 754 | * @raid_device: raid_device object |
| 755 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 756 | */ |
| 757 | static void |
| 758 | _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc, |
| 759 | struct _raid_device *raid_device) |
| 760 | { |
| 761 | unsigned long flags; |
| 762 | |
| 763 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 764 | list_del(&raid_device->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 765 | kfree(raid_device); |
| 766 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 767 | } |
| 768 | |
| 769 | /** |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 770 | * mpt2sas_scsih_expander_find_by_handle - expander device search |
| 771 | * @ioc: per adapter object |
| 772 | * @handle: expander handle (assigned by firmware) |
| 773 | * Context: Calling function should acquire ioc->sas_device_lock |
| 774 | * |
| 775 | * This searches for expander device based on handle, then returns the |
| 776 | * sas_node object. |
| 777 | */ |
| 778 | struct _sas_node * |
| 779 | mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 780 | { |
| 781 | struct _sas_node *sas_expander, *r; |
| 782 | |
| 783 | r = NULL; |
| 784 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 785 | if (sas_expander->handle != handle) |
| 786 | continue; |
| 787 | r = sas_expander; |
| 788 | goto out; |
| 789 | } |
| 790 | out: |
| 791 | return r; |
| 792 | } |
| 793 | |
| 794 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 795 | * mpt2sas_scsih_expander_find_by_sas_address - expander device search |
| 796 | * @ioc: per adapter object |
| 797 | * @sas_address: sas address |
| 798 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 799 | * |
| 800 | * This searches for expander device based on sas_address, then returns the |
| 801 | * sas_node object. |
| 802 | */ |
| 803 | struct _sas_node * |
| 804 | mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 805 | u64 sas_address) |
| 806 | { |
| 807 | struct _sas_node *sas_expander, *r; |
| 808 | |
| 809 | r = NULL; |
| 810 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
| 811 | if (sas_expander->sas_address != sas_address) |
| 812 | continue; |
| 813 | r = sas_expander; |
| 814 | goto out; |
| 815 | } |
| 816 | out: |
| 817 | return r; |
| 818 | } |
| 819 | |
| 820 | /** |
| 821 | * _scsih_expander_node_add - insert expander device to the list. |
| 822 | * @ioc: per adapter object |
| 823 | * @sas_expander: the sas_device object |
| 824 | * Context: This function will acquire ioc->sas_node_lock. |
| 825 | * |
| 826 | * Adding new object to the ioc->sas_expander_list. |
| 827 | * |
| 828 | * Return nothing. |
| 829 | */ |
| 830 | static void |
| 831 | _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc, |
| 832 | struct _sas_node *sas_expander) |
| 833 | { |
| 834 | unsigned long flags; |
| 835 | |
| 836 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 837 | list_add_tail(&sas_expander->list, &ioc->sas_expander_list); |
| 838 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 839 | } |
| 840 | |
| 841 | /** |
| 842 | * _scsih_is_end_device - determines if device is an end device |
| 843 | * @device_info: bitfield providing information about the device. |
| 844 | * Context: none |
| 845 | * |
| 846 | * Returns 1 if end device. |
| 847 | */ |
| 848 | static int |
| 849 | _scsih_is_end_device(u32 device_info) |
| 850 | { |
| 851 | if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE && |
| 852 | ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) | |
| 853 | (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) | |
| 854 | (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE))) |
| 855 | return 1; |
| 856 | else |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | /** |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 861 | * _scsih_scsi_lookup_get - returns scmd entry |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 862 | * @ioc: per adapter object |
| 863 | * @smid: system request message index |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 864 | * |
| 865 | * Returns the smid stored scmd pointer. |
| 866 | */ |
| 867 | static struct scsi_cmnd * |
| 868 | _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 869 | { |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 870 | return ioc->scsi_lookup[smid - 1].scmd; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | /** |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 874 | * _scsih_scsi_lookup_get_clear - returns scmd entry |
| 875 | * @ioc: per adapter object |
| 876 | * @smid: system request message index |
| 877 | * |
| 878 | * Returns the smid stored scmd pointer. |
| 879 | * Then will derefrence the stored scmd pointer. |
| 880 | */ |
| 881 | static inline struct scsi_cmnd * |
| 882 | _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 883 | { |
| 884 | unsigned long flags; |
| 885 | struct scsi_cmnd *scmd; |
| 886 | |
| 887 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 888 | scmd = ioc->scsi_lookup[smid - 1].scmd; |
| 889 | ioc->scsi_lookup[smid - 1].scmd = NULL; |
| 890 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 891 | |
| 892 | return scmd; |
| 893 | } |
| 894 | |
| 895 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 896 | * _scsih_scsi_lookup_find_by_scmd - scmd lookup |
| 897 | * @ioc: per adapter object |
| 898 | * @smid: system request message index |
| 899 | * @scmd: pointer to scsi command object |
| 900 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 901 | * |
| 902 | * This will search for a scmd pointer in the scsi_lookup array, |
| 903 | * returning the revelent smid. A returned value of zero means invalid. |
| 904 | */ |
| 905 | static u16 |
| 906 | _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd |
| 907 | *scmd) |
| 908 | { |
| 909 | u16 smid; |
| 910 | unsigned long flags; |
| 911 | int i; |
| 912 | |
| 913 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 914 | smid = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 915 | for (i = 0; i < ioc->scsiio_depth; i++) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 916 | if (ioc->scsi_lookup[i].scmd == scmd) { |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 917 | smid = ioc->scsi_lookup[i].smid; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 918 | goto out; |
| 919 | } |
| 920 | } |
| 921 | out: |
| 922 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 923 | return smid; |
| 924 | } |
| 925 | |
| 926 | /** |
| 927 | * _scsih_scsi_lookup_find_by_target - search for matching channel:id |
| 928 | * @ioc: per adapter object |
| 929 | * @id: target id |
| 930 | * @channel: channel |
| 931 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 932 | * |
| 933 | * This will search for a matching channel:id in the scsi_lookup array, |
| 934 | * returning 1 if found. |
| 935 | */ |
| 936 | static u8 |
| 937 | _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id, |
| 938 | int channel) |
| 939 | { |
| 940 | u8 found; |
| 941 | unsigned long flags; |
| 942 | int i; |
| 943 | |
| 944 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 945 | found = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 946 | for (i = 0 ; i < ioc->scsiio_depth; i++) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 947 | if (ioc->scsi_lookup[i].scmd && |
| 948 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 949 | ioc->scsi_lookup[i].scmd->device->channel == channel)) { |
| 950 | found = 1; |
| 951 | goto out; |
| 952 | } |
| 953 | } |
| 954 | out: |
| 955 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 956 | return found; |
| 957 | } |
| 958 | |
| 959 | /** |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 960 | * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun |
| 961 | * @ioc: per adapter object |
| 962 | * @id: target id |
| 963 | * @lun: lun number |
| 964 | * @channel: channel |
| 965 | * Context: This function will acquire ioc->scsi_lookup_lock. |
| 966 | * |
| 967 | * This will search for a matching channel:id:lun in the scsi_lookup array, |
| 968 | * returning 1 if found. |
| 969 | */ |
| 970 | static u8 |
| 971 | _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id, |
| 972 | unsigned int lun, int channel) |
| 973 | { |
| 974 | u8 found; |
| 975 | unsigned long flags; |
| 976 | int i; |
| 977 | |
| 978 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 979 | found = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 980 | for (i = 0 ; i < ioc->scsiio_depth; i++) { |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 981 | if (ioc->scsi_lookup[i].scmd && |
| 982 | (ioc->scsi_lookup[i].scmd->device->id == id && |
| 983 | ioc->scsi_lookup[i].scmd->device->channel == channel && |
| 984 | ioc->scsi_lookup[i].scmd->device->lun == lun)) { |
| 985 | found = 1; |
| 986 | goto out; |
| 987 | } |
| 988 | } |
| 989 | out: |
| 990 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 991 | return found; |
| 992 | } |
| 993 | |
| 994 | /** |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 995 | * _scsih_get_chain_buffer_tracker - obtain chain tracker |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 996 | * @ioc: per adapter object |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 997 | * @smid: smid associated to an IO request |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 998 | * |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 999 | * Returns chain tracker(from ioc->free_chain_list) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1000 | */ |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1001 | static struct chain_tracker * |
| 1002 | _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1003 | { |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1004 | struct chain_tracker *chain_req; |
| 1005 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1006 | |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1007 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 1008 | if (list_empty(&ioc->free_chain_list)) { |
| 1009 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
nagalakshmi.nandigama@lsi.com | aff132d | 2011-12-01 07:53:08 +0530 | [diff] [blame] | 1010 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not " |
| 1011 | "available\n", ioc->name)); |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1012 | return NULL; |
| 1013 | } |
| 1014 | chain_req = list_entry(ioc->free_chain_list.next, |
| 1015 | struct chain_tracker, tracker_list); |
| 1016 | list_del_init(&chain_req->tracker_list); |
| 1017 | list_add_tail(&chain_req->tracker_list, |
| 1018 | &ioc->scsi_lookup[smid - 1].chain_list); |
| 1019 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1020 | return chain_req; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | /** |
| 1024 | * _scsih_build_scatter_gather - main sg creation routine |
| 1025 | * @ioc: per adapter object |
| 1026 | * @scmd: scsi command |
| 1027 | * @smid: system request message index |
| 1028 | * Context: none. |
| 1029 | * |
| 1030 | * The main routine that builds scatter gather table from a given |
| 1031 | * scsi request sent via the .queuecommand main handler. |
| 1032 | * |
| 1033 | * Returns 0 success, anything else error |
| 1034 | */ |
| 1035 | static int |
| 1036 | _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc, |
| 1037 | struct scsi_cmnd *scmd, u16 smid) |
| 1038 | { |
| 1039 | Mpi2SCSIIORequest_t *mpi_request; |
| 1040 | dma_addr_t chain_dma; |
| 1041 | struct scatterlist *sg_scmd; |
| 1042 | void *sg_local, *chain; |
| 1043 | u32 chain_offset; |
| 1044 | u32 chain_length; |
| 1045 | u32 chain_flags; |
FUJITA Tomonori | bb789d0 | 2010-03-09 11:09:50 +0900 | [diff] [blame] | 1046 | int sges_left; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1047 | u32 sges_in_segment; |
| 1048 | u32 sgl_flags; |
| 1049 | u32 sgl_flags_last_element; |
| 1050 | u32 sgl_flags_end_buffer; |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1051 | struct chain_tracker *chain_req; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1052 | |
| 1053 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 1054 | |
| 1055 | /* init scatter gather flags */ |
| 1056 | sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT; |
| 1057 | if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 1058 | sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC; |
| 1059 | sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT) |
| 1060 | << MPI2_SGE_FLAGS_SHIFT; |
| 1061 | sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT | |
| 1062 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST) |
| 1063 | << MPI2_SGE_FLAGS_SHIFT; |
| 1064 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1065 | |
| 1066 | sg_scmd = scsi_sglist(scmd); |
| 1067 | sges_left = scsi_dma_map(scmd); |
FUJITA Tomonori | bb789d0 | 2010-03-09 11:09:50 +0900 | [diff] [blame] | 1068 | if (sges_left < 0) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1069 | sdev_printk(KERN_ERR, scmd->device, "pci_map_sg" |
| 1070 | " failed: request for %d bytes!\n", scsi_bufflen(scmd)); |
| 1071 | return -ENOMEM; |
| 1072 | } |
| 1073 | |
| 1074 | sg_local = &mpi_request->SGL; |
| 1075 | sges_in_segment = ioc->max_sges_in_main_message; |
| 1076 | if (sges_left <= sges_in_segment) |
| 1077 | goto fill_in_last_segment; |
| 1078 | |
| 1079 | mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) + |
| 1080 | (sges_in_segment * ioc->sge_size))/4; |
| 1081 | |
| 1082 | /* fill in main message segment when there is a chain following */ |
| 1083 | while (sges_in_segment) { |
| 1084 | if (sges_in_segment == 1) |
| 1085 | ioc->base_add_sg_single(sg_local, |
| 1086 | sgl_flags_last_element | sg_dma_len(sg_scmd), |
| 1087 | sg_dma_address(sg_scmd)); |
| 1088 | else |
| 1089 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1090 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1091 | sg_scmd = sg_next(sg_scmd); |
| 1092 | sg_local += ioc->sge_size; |
| 1093 | sges_left--; |
| 1094 | sges_in_segment--; |
| 1095 | } |
| 1096 | |
| 1097 | /* initializing the chain flags and pointers */ |
| 1098 | chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT; |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1099 | chain_req = _scsih_get_chain_buffer_tracker(ioc, smid); |
| 1100 | if (!chain_req) |
| 1101 | return -1; |
| 1102 | chain = chain_req->chain_buffer; |
| 1103 | chain_dma = chain_req->chain_buffer_dma; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1104 | do { |
| 1105 | sges_in_segment = (sges_left <= |
| 1106 | ioc->max_sges_in_chain_message) ? sges_left : |
| 1107 | ioc->max_sges_in_chain_message; |
| 1108 | chain_offset = (sges_left == sges_in_segment) ? |
| 1109 | 0 : (sges_in_segment * ioc->sge_size)/4; |
| 1110 | chain_length = sges_in_segment * ioc->sge_size; |
| 1111 | if (chain_offset) { |
| 1112 | chain_offset = chain_offset << |
| 1113 | MPI2_SGE_CHAIN_OFFSET_SHIFT; |
| 1114 | chain_length += ioc->sge_size; |
| 1115 | } |
| 1116 | ioc->base_add_sg_single(sg_local, chain_flags | chain_offset | |
| 1117 | chain_length, chain_dma); |
| 1118 | sg_local = chain; |
| 1119 | if (!chain_offset) |
| 1120 | goto fill_in_last_segment; |
| 1121 | |
| 1122 | /* fill in chain segments */ |
| 1123 | while (sges_in_segment) { |
| 1124 | if (sges_in_segment == 1) |
| 1125 | ioc->base_add_sg_single(sg_local, |
| 1126 | sgl_flags_last_element | |
| 1127 | sg_dma_len(sg_scmd), |
| 1128 | sg_dma_address(sg_scmd)); |
| 1129 | else |
| 1130 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1131 | sg_dma_len(sg_scmd), |
| 1132 | sg_dma_address(sg_scmd)); |
| 1133 | sg_scmd = sg_next(sg_scmd); |
| 1134 | sg_local += ioc->sge_size; |
| 1135 | sges_left--; |
| 1136 | sges_in_segment--; |
| 1137 | } |
| 1138 | |
Kashyap, Desai | 35f805b | 2010-11-13 04:34:06 +0530 | [diff] [blame] | 1139 | chain_req = _scsih_get_chain_buffer_tracker(ioc, smid); |
| 1140 | if (!chain_req) |
| 1141 | return -1; |
| 1142 | chain = chain_req->chain_buffer; |
| 1143 | chain_dma = chain_req->chain_buffer_dma; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1144 | } while (1); |
| 1145 | |
| 1146 | |
| 1147 | fill_in_last_segment: |
| 1148 | |
| 1149 | /* fill the last segment */ |
| 1150 | while (sges_left) { |
| 1151 | if (sges_left == 1) |
| 1152 | ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer | |
| 1153 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1154 | else |
| 1155 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1156 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1157 | sg_scmd = sg_next(sg_scmd); |
| 1158 | sg_local += ioc->sge_size; |
| 1159 | sges_left--; |
| 1160 | } |
| 1161 | |
| 1162 | return 0; |
| 1163 | } |
| 1164 | |
| 1165 | /** |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1166 | * _scsih_adjust_queue_depth - setting device queue depth |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1167 | * @sdev: scsi device struct |
| 1168 | * @qdepth: requested queue depth |
| 1169 | * |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1170 | * |
| 1171 | * Returns nothing |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1172 | */ |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1173 | static void |
| 1174 | _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1175 | { |
| 1176 | struct Scsi_Host *shost = sdev->host; |
| 1177 | int max_depth; |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1178 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1179 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1180 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1181 | struct _sas_device *sas_device; |
| 1182 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1183 | |
| 1184 | max_depth = shost->can_queue; |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1185 | |
| 1186 | /* limit max device queue for SATA to 32 */ |
| 1187 | sas_device_priv_data = sdev->hostdata; |
| 1188 | if (!sas_device_priv_data) |
| 1189 | goto not_sata; |
| 1190 | sas_target_priv_data = sas_device_priv_data->sas_target; |
| 1191 | if (!sas_target_priv_data) |
| 1192 | goto not_sata; |
| 1193 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) |
| 1194 | goto not_sata; |
| 1195 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1196 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1197 | sas_device_priv_data->sas_target->sas_address); |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1198 | if (sas_device && sas_device->device_info & |
| 1199 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1200 | max_depth = MPT2SAS_SATA_QUEUE_DEPTH; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1201 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | e0077d6 | 2009-09-23 17:30:22 +0530 | [diff] [blame] | 1202 | |
| 1203 | not_sata: |
| 1204 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1205 | if (!sdev->tagged_supported) |
| 1206 | max_depth = 1; |
| 1207 | if (qdepth > max_depth) |
| 1208 | qdepth = max_depth; |
Kashyap, Desai | a93c6b4 | 2010-11-13 04:39:11 +0530 | [diff] [blame] | 1209 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); |
| 1210 | } |
| 1211 | |
| 1212 | /** |
| 1213 | * _scsih_change_queue_depth - setting device queue depth |
| 1214 | * @sdev: scsi device struct |
| 1215 | * @qdepth: requested queue depth |
| 1216 | * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP |
| 1217 | * (see include/scsi/scsi_host.h for definition) |
| 1218 | * |
| 1219 | * Returns queue depth. |
| 1220 | */ |
| 1221 | static int |
| 1222 | _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) |
| 1223 | { |
| 1224 | if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP) |
| 1225 | _scsih_adjust_queue_depth(sdev, qdepth); |
| 1226 | else if (reason == SCSI_QDEPTH_QFULL) |
| 1227 | scsi_track_queue_full(sdev, qdepth); |
| 1228 | else |
| 1229 | return -EOPNOTSUPP; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1230 | |
| 1231 | if (sdev->inquiry_len > 7) |
| 1232 | sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " |
| 1233 | "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n", |
| 1234 | sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags, |
| 1235 | sdev->ordered_tags, sdev->scsi_level, |
| 1236 | (sdev->inquiry[7] & 2) >> 1); |
| 1237 | |
| 1238 | return sdev->queue_depth; |
| 1239 | } |
| 1240 | |
| 1241 | /** |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 1242 | * _scsih_change_queue_type - changing device queue tag type |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1243 | * @sdev: scsi device struct |
| 1244 | * @tag_type: requested tag type |
| 1245 | * |
| 1246 | * Returns queue tag type. |
| 1247 | */ |
| 1248 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1249 | _scsih_change_queue_type(struct scsi_device *sdev, int tag_type) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1250 | { |
| 1251 | if (sdev->tagged_supported) { |
| 1252 | scsi_set_tag_type(sdev, tag_type); |
| 1253 | if (tag_type) |
| 1254 | scsi_activate_tcq(sdev, sdev->queue_depth); |
| 1255 | else |
| 1256 | scsi_deactivate_tcq(sdev, sdev->queue_depth); |
| 1257 | } else |
| 1258 | tag_type = 0; |
| 1259 | |
| 1260 | return tag_type; |
| 1261 | } |
| 1262 | |
| 1263 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1264 | * _scsih_target_alloc - target add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1265 | * @starget: scsi target struct |
| 1266 | * |
| 1267 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1268 | * the device is ignored. |
| 1269 | */ |
| 1270 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1271 | _scsih_target_alloc(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1272 | { |
| 1273 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1274 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1275 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1276 | struct _sas_device *sas_device; |
| 1277 | struct _raid_device *raid_device; |
| 1278 | unsigned long flags; |
| 1279 | struct sas_rphy *rphy; |
| 1280 | |
| 1281 | sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL); |
| 1282 | if (!sas_target_priv_data) |
| 1283 | return -ENOMEM; |
| 1284 | |
| 1285 | starget->hostdata = sas_target_priv_data; |
| 1286 | sas_target_priv_data->starget = starget; |
| 1287 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; |
| 1288 | |
| 1289 | /* RAID volumes */ |
| 1290 | if (starget->channel == RAID_CHANNEL) { |
| 1291 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1292 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1293 | starget->channel); |
| 1294 | if (raid_device) { |
| 1295 | sas_target_priv_data->handle = raid_device->handle; |
| 1296 | sas_target_priv_data->sas_address = raid_device->wwid; |
| 1297 | sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1298 | if (ioc->is_warpdrive) |
| 1299 | sas_target_priv_data->raid_device = raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1300 | raid_device->starget = starget; |
| 1301 | } |
| 1302 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1303 | return 0; |
| 1304 | } |
| 1305 | |
| 1306 | /* sas/sata devices */ |
| 1307 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1308 | rphy = dev_to_rphy(starget->dev.parent); |
| 1309 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1310 | rphy->identify.sas_address); |
| 1311 | |
| 1312 | if (sas_device) { |
| 1313 | sas_target_priv_data->handle = sas_device->handle; |
| 1314 | sas_target_priv_data->sas_address = sas_device->sas_address; |
| 1315 | sas_device->starget = starget; |
| 1316 | sas_device->id = starget->id; |
| 1317 | sas_device->channel = starget->channel; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 1318 | if (test_bit(sas_device->handle, ioc->pd_handles)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1319 | sas_target_priv_data->flags |= |
| 1320 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 1321 | } |
| 1322 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1323 | |
| 1324 | return 0; |
| 1325 | } |
| 1326 | |
| 1327 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1328 | * _scsih_target_destroy - target destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1329 | * @starget: scsi target struct |
| 1330 | * |
| 1331 | * Returns nothing. |
| 1332 | */ |
| 1333 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1334 | _scsih_target_destroy(struct scsi_target *starget) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1335 | { |
| 1336 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 1337 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1338 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1339 | struct _sas_device *sas_device; |
| 1340 | struct _raid_device *raid_device; |
| 1341 | unsigned long flags; |
| 1342 | struct sas_rphy *rphy; |
| 1343 | |
| 1344 | sas_target_priv_data = starget->hostdata; |
| 1345 | if (!sas_target_priv_data) |
| 1346 | return; |
| 1347 | |
| 1348 | if (starget->channel == RAID_CHANNEL) { |
| 1349 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1350 | raid_device = _scsih_raid_device_find_by_id(ioc, starget->id, |
| 1351 | starget->channel); |
| 1352 | if (raid_device) { |
| 1353 | raid_device->starget = NULL; |
| 1354 | raid_device->sdev = NULL; |
| 1355 | } |
| 1356 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1357 | goto out; |
| 1358 | } |
| 1359 | |
| 1360 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1361 | rphy = dev_to_rphy(starget->dev.parent); |
| 1362 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1363 | rphy->identify.sas_address); |
Eric Moore | 8901cbb | 2009-04-21 15:41:32 -0600 | [diff] [blame] | 1364 | if (sas_device && (sas_device->starget == starget) && |
| 1365 | (sas_device->id == starget->id) && |
| 1366 | (sas_device->channel == starget->channel)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1367 | sas_device->starget = NULL; |
| 1368 | |
| 1369 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1370 | |
| 1371 | out: |
| 1372 | kfree(sas_target_priv_data); |
| 1373 | starget->hostdata = NULL; |
| 1374 | } |
| 1375 | |
| 1376 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1377 | * _scsih_slave_alloc - device add routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1378 | * @sdev: scsi device struct |
| 1379 | * |
| 1380 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1381 | * the device is ignored. |
| 1382 | */ |
| 1383 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1384 | _scsih_slave_alloc(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1385 | { |
| 1386 | struct Scsi_Host *shost; |
| 1387 | struct MPT2SAS_ADAPTER *ioc; |
| 1388 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1389 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1390 | struct scsi_target *starget; |
| 1391 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1392 | unsigned long flags; |
| 1393 | |
| 1394 | sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL); |
| 1395 | if (!sas_device_priv_data) |
| 1396 | return -ENOMEM; |
| 1397 | |
| 1398 | sas_device_priv_data->lun = sdev->lun; |
| 1399 | sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT; |
| 1400 | |
| 1401 | starget = scsi_target(sdev); |
| 1402 | sas_target_priv_data = starget->hostdata; |
| 1403 | sas_target_priv_data->num_luns++; |
| 1404 | sas_device_priv_data->sas_target = sas_target_priv_data; |
| 1405 | sdev->hostdata = sas_device_priv_data; |
| 1406 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT)) |
| 1407 | sdev->no_uld_attach = 1; |
| 1408 | |
| 1409 | shost = dev_to_shost(&starget->dev); |
| 1410 | ioc = shost_priv(shost); |
| 1411 | if (starget->channel == RAID_CHANNEL) { |
| 1412 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1413 | raid_device = _scsih_raid_device_find_by_id(ioc, |
| 1414 | starget->id, starget->channel); |
| 1415 | if (raid_device) |
| 1416 | raid_device->sdev = sdev; /* raid is single lun */ |
| 1417 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1418 | } |
| 1419 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1420 | return 0; |
| 1421 | } |
| 1422 | |
| 1423 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1424 | * _scsih_slave_destroy - device destroy routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1425 | * @sdev: scsi device struct |
| 1426 | * |
| 1427 | * Returns nothing. |
| 1428 | */ |
| 1429 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1430 | _scsih_slave_destroy(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1431 | { |
| 1432 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1433 | struct scsi_target *starget; |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1434 | struct Scsi_Host *shost; |
| 1435 | struct MPT2SAS_ADAPTER *ioc; |
| 1436 | struct _sas_device *sas_device; |
| 1437 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1438 | |
| 1439 | if (!sdev->hostdata) |
| 1440 | return; |
| 1441 | |
| 1442 | starget = scsi_target(sdev); |
| 1443 | sas_target_priv_data = starget->hostdata; |
| 1444 | sas_target_priv_data->num_luns--; |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1445 | |
| 1446 | shost = dev_to_shost(&starget->dev); |
| 1447 | ioc = shost_priv(shost); |
| 1448 | |
| 1449 | if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) { |
| 1450 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1451 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 1452 | sas_target_priv_data->sas_address); |
nagalakshmi.nandigama@lsi.com | 23edb6e | 2011-12-01 07:43:50 +0530 | [diff] [blame] | 1453 | if (sas_device && !sas_target_priv_data->num_luns) |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 1454 | sas_device->starget = NULL; |
| 1455 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1456 | } |
| 1457 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1458 | kfree(sdev->hostdata); |
| 1459 | sdev->hostdata = NULL; |
| 1460 | } |
| 1461 | |
| 1462 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1463 | * _scsih_display_sata_capabilities - sata capabilities |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1464 | * @ioc: per adapter object |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1465 | * @handle: device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1466 | * @sdev: scsi device struct |
| 1467 | */ |
| 1468 | static void |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1469 | _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1470 | u16 handle, struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1471 | { |
| 1472 | Mpi2ConfigReply_t mpi_reply; |
| 1473 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1474 | u32 ioc_status; |
| 1475 | u16 flags; |
| 1476 | u32 device_info; |
| 1477 | |
| 1478 | 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^] | 1479 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1480 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1481 | ioc->name, __FILE__, __LINE__, __func__); |
| 1482 | return; |
| 1483 | } |
| 1484 | |
| 1485 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1486 | MPI2_IOCSTATUS_MASK; |
| 1487 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 1488 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1489 | ioc->name, __FILE__, __LINE__, __func__); |
| 1490 | return; |
| 1491 | } |
| 1492 | |
| 1493 | flags = le16_to_cpu(sas_device_pg0.Flags); |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 1494 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1495 | |
| 1496 | sdev_printk(KERN_INFO, sdev, |
| 1497 | "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), " |
| 1498 | "sw_preserve(%s)\n", |
| 1499 | (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n", |
| 1500 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n", |
| 1501 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" : |
| 1502 | "n", |
| 1503 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n", |
| 1504 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n", |
| 1505 | (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n"); |
| 1506 | } |
| 1507 | |
| 1508 | /** |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1509 | * _scsih_is_raid - return boolean indicating device is raid volume |
| 1510 | * @dev the device struct object |
| 1511 | */ |
| 1512 | static int |
| 1513 | _scsih_is_raid(struct device *dev) |
| 1514 | { |
| 1515 | struct scsi_device *sdev = to_scsi_device(dev); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1516 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1517 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1518 | if (ioc->is_warpdrive) |
| 1519 | return 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1520 | return (sdev->channel == RAID_CHANNEL) ? 1 : 0; |
| 1521 | } |
| 1522 | |
| 1523 | /** |
| 1524 | * _scsih_get_resync - get raid volume resync percent complete |
| 1525 | * @dev the device struct object |
| 1526 | */ |
| 1527 | static void |
| 1528 | _scsih_get_resync(struct device *dev) |
| 1529 | { |
| 1530 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1531 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1532 | static struct _raid_device *raid_device; |
| 1533 | unsigned long flags; |
| 1534 | Mpi2RaidVolPage0_t vol_pg0; |
| 1535 | Mpi2ConfigReply_t mpi_reply; |
| 1536 | u32 volume_status_flags; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1537 | u8 percent_complete; |
| 1538 | u16 handle; |
| 1539 | |
| 1540 | percent_complete = 0; |
| 1541 | handle = 0; |
| 1542 | if (ioc->is_warpdrive) |
| 1543 | goto out; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1544 | |
| 1545 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1546 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1547 | sdev->channel); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1548 | if (raid_device) { |
| 1549 | handle = raid_device->handle; |
| 1550 | percent_complete = raid_device->percent_complete; |
| 1551 | } |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1552 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1553 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1554 | if (!handle) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1555 | goto out; |
| 1556 | |
| 1557 | 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^] | 1558 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1559 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1560 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1561 | ioc->name, __FILE__, __LINE__, __func__); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1562 | percent_complete = 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1563 | goto out; |
| 1564 | } |
| 1565 | |
| 1566 | volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1567 | if (!(volume_status_flags & |
| 1568 | MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)) |
| 1569 | percent_complete = 0; |
| 1570 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1571 | out: |
| 1572 | raid_set_resync(mpt2sas_raid_template, dev, percent_complete); |
| 1573 | } |
| 1574 | |
| 1575 | /** |
| 1576 | * _scsih_get_state - get raid volume level |
| 1577 | * @dev the device struct object |
| 1578 | */ |
| 1579 | static void |
| 1580 | _scsih_get_state(struct device *dev) |
| 1581 | { |
| 1582 | struct scsi_device *sdev = to_scsi_device(dev); |
| 1583 | struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host); |
| 1584 | static struct _raid_device *raid_device; |
| 1585 | unsigned long flags; |
| 1586 | Mpi2RaidVolPage0_t vol_pg0; |
| 1587 | Mpi2ConfigReply_t mpi_reply; |
| 1588 | u32 volstate; |
| 1589 | enum raid_state state = RAID_STATE_UNKNOWN; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1590 | u16 handle = 0; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1591 | |
| 1592 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1593 | raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id, |
| 1594 | sdev->channel); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1595 | if (raid_device) |
| 1596 | handle = raid_device->handle; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1597 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1598 | |
| 1599 | if (!raid_device) |
| 1600 | goto out; |
| 1601 | |
| 1602 | 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^] | 1603 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1604 | sizeof(Mpi2RaidVolPage0_t))) { |
| 1605 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 1606 | ioc->name, __FILE__, __LINE__, __func__); |
| 1607 | goto out; |
| 1608 | } |
| 1609 | |
| 1610 | volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags); |
| 1611 | if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { |
| 1612 | state = RAID_STATE_RESYNCING; |
| 1613 | goto out; |
| 1614 | } |
| 1615 | |
| 1616 | switch (vol_pg0.VolumeState) { |
| 1617 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
| 1618 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 1619 | state = RAID_STATE_ACTIVE; |
| 1620 | break; |
| 1621 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 1622 | state = RAID_STATE_DEGRADED; |
| 1623 | break; |
| 1624 | case MPI2_RAID_VOL_STATE_FAILED: |
| 1625 | case MPI2_RAID_VOL_STATE_MISSING: |
| 1626 | state = RAID_STATE_OFFLINE; |
| 1627 | break; |
| 1628 | } |
| 1629 | out: |
| 1630 | raid_set_state(mpt2sas_raid_template, dev, state); |
| 1631 | } |
| 1632 | |
| 1633 | /** |
| 1634 | * _scsih_set_level - set raid level |
| 1635 | * @sdev: scsi device struct |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1636 | * @volume_type: volume type |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1637 | */ |
| 1638 | static void |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1639 | _scsih_set_level(struct scsi_device *sdev, u8 volume_type) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1640 | { |
| 1641 | enum raid_level level = RAID_LEVEL_UNKNOWN; |
| 1642 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1643 | switch (volume_type) { |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 1644 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 1645 | level = RAID_LEVEL_0; |
| 1646 | break; |
| 1647 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 1648 | level = RAID_LEVEL_10; |
| 1649 | break; |
| 1650 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 1651 | level = RAID_LEVEL_1E; |
| 1652 | break; |
| 1653 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 1654 | level = RAID_LEVEL_1; |
| 1655 | break; |
| 1656 | } |
| 1657 | |
| 1658 | raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level); |
| 1659 | } |
| 1660 | |
| 1661 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1662 | * _scsih_get_volume_capabilities - volume capabilities |
| 1663 | * @ioc: per adapter object |
| 1664 | * @sas_device: the raid_device object |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1665 | * |
| 1666 | * Returns 0 for success, else 1 |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1667 | */ |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1668 | static int |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1669 | _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc, |
| 1670 | struct _raid_device *raid_device) |
| 1671 | { |
| 1672 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1673 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1674 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 1675 | Mpi2ConfigReply_t mpi_reply; |
| 1676 | u16 sz; |
| 1677 | u8 num_pds; |
| 1678 | |
| 1679 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1680 | &num_pds)) || !num_pds) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1681 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1682 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1683 | __func__)); |
| 1684 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | raid_device->num_pds = num_pds; |
| 1688 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1689 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1690 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1691 | if (!vol_pg0) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1692 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1693 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1694 | __func__)); |
| 1695 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1699 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1700 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 1701 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__, |
| 1702 | __func__)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1703 | kfree(vol_pg0); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1704 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | raid_device->volume_type = vol_pg0->VolumeType; |
| 1708 | |
| 1709 | /* figure out what the underlying devices are by |
| 1710 | * obtaining the device_info bits for the 1st device |
| 1711 | */ |
| 1712 | if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1713 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1714 | vol_pg0->PhysDisk[0].PhysDiskNum))) { |
| 1715 | if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 1716 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 1717 | le16_to_cpu(pd_pg0.DevHandle)))) { |
| 1718 | raid_device->device_info = |
| 1719 | le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | kfree(vol_pg0); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 1724 | return 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1725 | } |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1726 | /** |
| 1727 | * _scsih_disable_ddio - Disable direct I/O for all the volumes |
| 1728 | * @ioc: per adapter object |
| 1729 | */ |
| 1730 | static void |
| 1731 | _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc) |
| 1732 | { |
| 1733 | Mpi2RaidVolPage1_t vol_pg1; |
| 1734 | Mpi2ConfigReply_t mpi_reply; |
| 1735 | struct _raid_device *raid_device; |
| 1736 | u16 handle; |
| 1737 | u16 ioc_status; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1738 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1739 | |
| 1740 | handle = 0xFFFF; |
| 1741 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 1742 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 1743 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1744 | MPI2_IOCSTATUS_MASK; |
| 1745 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 1746 | break; |
| 1747 | handle = le16_to_cpu(vol_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1748 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1749 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 1750 | if (raid_device) |
| 1751 | raid_device->direct_io_enabled = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1752 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1753 | } |
| 1754 | return; |
| 1755 | } |
| 1756 | |
| 1757 | |
| 1758 | /** |
| 1759 | * _scsih_get_num_volumes - Get number of volumes in the ioc |
| 1760 | * @ioc: per adapter object |
| 1761 | */ |
| 1762 | static u8 |
| 1763 | _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc) |
| 1764 | { |
| 1765 | Mpi2RaidVolPage1_t vol_pg1; |
| 1766 | Mpi2ConfigReply_t mpi_reply; |
| 1767 | u16 handle; |
| 1768 | u8 vol_cnt = 0; |
| 1769 | u16 ioc_status; |
| 1770 | |
| 1771 | handle = 0xFFFF; |
| 1772 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 1773 | &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 1774 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 1775 | MPI2_IOCSTATUS_MASK; |
| 1776 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 1777 | break; |
| 1778 | vol_cnt++; |
| 1779 | handle = le16_to_cpu(vol_pg1.DevHandle); |
| 1780 | } |
| 1781 | return vol_cnt; |
| 1782 | } |
| 1783 | |
| 1784 | |
| 1785 | /** |
| 1786 | * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O. |
| 1787 | * @ioc: per adapter object |
| 1788 | * @raid_device: the raid_device object |
| 1789 | */ |
| 1790 | static void |
| 1791 | _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc, |
| 1792 | struct _raid_device *raid_device) |
| 1793 | { |
| 1794 | Mpi2RaidVolPage0_t *vol_pg0; |
| 1795 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 1796 | Mpi2ConfigReply_t mpi_reply; |
| 1797 | u16 sz; |
| 1798 | u8 num_pds, count; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1799 | unsigned long stripe_sz, block_sz; |
| 1800 | u8 stripe_exp, block_exp; |
| 1801 | u64 dev_max_lba; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1802 | |
| 1803 | if (!ioc->is_warpdrive) |
| 1804 | return; |
| 1805 | |
| 1806 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) { |
| 1807 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1808 | "globally as drives are exposed\n", ioc->name); |
| 1809 | return; |
| 1810 | } |
| 1811 | if (_scsih_get_num_volumes(ioc) > 1) { |
| 1812 | _scsih_disable_ddio(ioc); |
| 1813 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1814 | "globally as number of drives > 1\n", ioc->name); |
| 1815 | return; |
| 1816 | } |
| 1817 | if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, |
| 1818 | &num_pds)) || !num_pds) { |
| 1819 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1820 | "Failure in computing number of drives\n", ioc->name); |
| 1821 | return; |
| 1822 | } |
| 1823 | |
| 1824 | sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds * |
| 1825 | sizeof(Mpi2RaidVol0PhysDisk_t)); |
| 1826 | vol_pg0 = kzalloc(sz, GFP_KERNEL); |
| 1827 | if (!vol_pg0) { |
| 1828 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1829 | "Memory allocation failure for RVPG0\n", ioc->name); |
| 1830 | return; |
| 1831 | } |
| 1832 | |
| 1833 | if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, |
| 1834 | MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { |
| 1835 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1836 | "Failure in retrieving RVPG0\n", ioc->name); |
| 1837 | kfree(vol_pg0); |
| 1838 | return; |
| 1839 | } |
| 1840 | |
| 1841 | /* |
| 1842 | * WARPDRIVE:If number of physical disks in a volume exceeds the max pds |
| 1843 | * assumed for WARPDRIVE, disable direct I/O |
| 1844 | */ |
| 1845 | if (num_pds > MPT_MAX_WARPDRIVE_PDS) { |
| 1846 | printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled " |
| 1847 | "for the drive with handle(0x%04x): num_mem=%d, " |
| 1848 | "max_mem_allowed=%d\n", ioc->name, raid_device->handle, |
| 1849 | num_pds, MPT_MAX_WARPDRIVE_PDS); |
| 1850 | kfree(vol_pg0); |
| 1851 | return; |
| 1852 | } |
| 1853 | for (count = 0; count < num_pds; count++) { |
| 1854 | if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 1855 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM, |
| 1856 | vol_pg0->PhysDisk[count].PhysDiskNum) || |
| 1857 | pd_pg0.DevHandle == MPT2SAS_INVALID_DEVICE_HANDLE) { |
| 1858 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " |
| 1859 | "disabled for the drive with handle(0x%04x) member" |
| 1860 | "handle retrieval failed for member number=%d\n", |
| 1861 | ioc->name, raid_device->handle, |
| 1862 | vol_pg0->PhysDisk[count].PhysDiskNum); |
| 1863 | goto out_error; |
| 1864 | } |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1865 | /* Disable direct I/O if member drive lba exceeds 4 bytes */ |
| 1866 | dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA); |
| 1867 | if (dev_max_lba >> 32) { |
| 1868 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is " |
| 1869 | "disabled for the drive with handle(0x%04x) member" |
| 1870 | "handle (0x%04x) unsupported max lba 0x%016llx\n", |
| 1871 | ioc->name, raid_device->handle, |
| 1872 | le16_to_cpu(pd_pg0.DevHandle), |
| 1873 | (unsigned long long)dev_max_lba); |
| 1874 | goto out_error; |
| 1875 | } |
| 1876 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1877 | raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle); |
| 1878 | } |
| 1879 | |
| 1880 | /* |
| 1881 | * 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] | 1882 | * not RAID0 |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1883 | */ |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1884 | if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1885 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1886 | "for the drive with handle(0x%04x): type=%d, " |
| 1887 | "s_sz=%uK, blk_size=%u\n", ioc->name, |
| 1888 | raid_device->handle, raid_device->volume_type, |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1889 | (le32_to_cpu(vol_pg0->StripeSize) * |
| 1890 | le16_to_cpu(vol_pg0->BlockSize)) / 1024, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1891 | le16_to_cpu(vol_pg0->BlockSize)); |
| 1892 | goto out_error; |
| 1893 | } |
| 1894 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1895 | stripe_sz = le32_to_cpu(vol_pg0->StripeSize); |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1896 | stripe_exp = find_first_bit(&stripe_sz, 32); |
| 1897 | if (stripe_exp == 32) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1898 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1899 | "for the drive with handle(0x%04x) invalid stripe sz %uK\n", |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1900 | ioc->name, raid_device->handle, |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1901 | (le32_to_cpu(vol_pg0->StripeSize) * |
| 1902 | le16_to_cpu(vol_pg0->BlockSize)) / 1024); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1903 | goto out_error; |
| 1904 | } |
| 1905 | raid_device->stripe_exponent = stripe_exp; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 1906 | block_sz = le16_to_cpu(vol_pg0->BlockSize); |
| 1907 | block_exp = find_first_bit(&block_sz, 16); |
| 1908 | if (block_exp == 16) { |
| 1909 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled " |
| 1910 | "for the drive with handle(0x%04x) invalid block sz %u\n", |
| 1911 | ioc->name, raid_device->handle, |
| 1912 | le16_to_cpu(vol_pg0->BlockSize)); |
| 1913 | goto out_error; |
| 1914 | } |
| 1915 | raid_device->block_exponent = block_exp; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 1916 | raid_device->direct_io_enabled = 1; |
| 1917 | |
| 1918 | printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive" |
| 1919 | " with handle(0x%04x)\n", ioc->name, raid_device->handle); |
| 1920 | /* |
| 1921 | * WARPDRIVE: Though the following fields are not used for direct IO, |
| 1922 | * stored for future purpose: |
| 1923 | */ |
| 1924 | raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA); |
| 1925 | raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize); |
| 1926 | raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize); |
| 1927 | |
| 1928 | |
| 1929 | kfree(vol_pg0); |
| 1930 | return; |
| 1931 | |
| 1932 | out_error: |
| 1933 | raid_device->direct_io_enabled = 0; |
| 1934 | for (count = 0; count < num_pds; count++) |
| 1935 | raid_device->pd_handle[count] = 0; |
| 1936 | kfree(vol_pg0); |
| 1937 | return; |
| 1938 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1939 | |
| 1940 | /** |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 1941 | * _scsih_enable_tlr - setting TLR flags |
| 1942 | * @ioc: per adapter object |
| 1943 | * @sdev: scsi device struct |
| 1944 | * |
| 1945 | * Enabling Transaction Layer Retries for tape devices when |
| 1946 | * vpd page 0x90 is present |
| 1947 | * |
| 1948 | */ |
| 1949 | static void |
| 1950 | _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev) |
| 1951 | { |
| 1952 | /* only for TAPE */ |
| 1953 | if (sdev->type != TYPE_TAPE) |
| 1954 | return; |
| 1955 | |
| 1956 | if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR)) |
| 1957 | return; |
| 1958 | |
| 1959 | sas_enable_tlr(sdev); |
| 1960 | sdev_printk(KERN_INFO, sdev, "TLR %s\n", |
| 1961 | sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled"); |
| 1962 | return; |
| 1963 | |
| 1964 | } |
| 1965 | |
| 1966 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1967 | * _scsih_slave_configure - device configure routine. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1968 | * @sdev: scsi device struct |
| 1969 | * |
| 1970 | * Returns 0 if ok. Any other return is assumed to be an error and |
| 1971 | * the device is ignored. |
| 1972 | */ |
| 1973 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 1974 | _scsih_slave_configure(struct scsi_device *sdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1975 | { |
| 1976 | struct Scsi_Host *shost = sdev->host; |
| 1977 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 1978 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 1979 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 1980 | struct _sas_device *sas_device; |
| 1981 | struct _raid_device *raid_device; |
| 1982 | unsigned long flags; |
| 1983 | int qdepth; |
| 1984 | u8 ssp_target = 0; |
| 1985 | char *ds = ""; |
| 1986 | char *r_level = ""; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1987 | u16 handle, volume_handle = 0; |
| 1988 | u64 volume_wwid = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1989 | |
| 1990 | qdepth = 1; |
| 1991 | sas_device_priv_data = sdev->hostdata; |
| 1992 | sas_device_priv_data->configured_lun = 1; |
| 1993 | sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT; |
| 1994 | sas_target_priv_data = sas_device_priv_data->sas_target; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 1995 | handle = sas_target_priv_data->handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1996 | |
| 1997 | /* raid volume handling */ |
| 1998 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 1999 | |
| 2000 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 2001 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2002 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 2003 | if (!raid_device) { |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2004 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2005 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2006 | __LINE__, __func__)); |
| 2007 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2008 | } |
| 2009 | |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2010 | if (_scsih_get_volume_capabilities(ioc, raid_device)) { |
| 2011 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2012 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2013 | __LINE__, __func__)); |
| 2014 | return 1; |
| 2015 | } |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2016 | /* |
| 2017 | * WARPDRIVE: Initialize the required data for Direct IO |
| 2018 | */ |
| 2019 | _scsih_init_warpdrive_properties(ioc, raid_device); |
| 2020 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2021 | /* RAID Queue Depth Support |
| 2022 | * IS volume = underlying qdepth of drive type, either |
| 2023 | * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH |
| 2024 | * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH) |
| 2025 | */ |
| 2026 | if (raid_device->device_info & |
| 2027 | MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 2028 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 2029 | ds = "SSP"; |
| 2030 | } else { |
| 2031 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 2032 | if (raid_device->device_info & |
| 2033 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 2034 | ds = "SATA"; |
| 2035 | else |
| 2036 | ds = "STP"; |
| 2037 | } |
| 2038 | |
| 2039 | switch (raid_device->volume_type) { |
| 2040 | case MPI2_RAID_VOL_TYPE_RAID0: |
| 2041 | r_level = "RAID0"; |
| 2042 | break; |
| 2043 | case MPI2_RAID_VOL_TYPE_RAID1E: |
| 2044 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 2045 | if (ioc->manu_pg10.OEMIdentifier && |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 2046 | (le32_to_cpu(ioc->manu_pg10.GenericFlags0) & |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 2047 | MFG10_GF0_R10_DISPLAY) && |
| 2048 | !(raid_device->num_pds % 2)) |
| 2049 | r_level = "RAID10"; |
| 2050 | else |
| 2051 | r_level = "RAID1E"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2052 | break; |
| 2053 | case MPI2_RAID_VOL_TYPE_RAID1: |
| 2054 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2055 | r_level = "RAID1"; |
| 2056 | break; |
| 2057 | case MPI2_RAID_VOL_TYPE_RAID10: |
| 2058 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2059 | r_level = "RAID10"; |
| 2060 | break; |
| 2061 | case MPI2_RAID_VOL_TYPE_UNKNOWN: |
| 2062 | default: |
| 2063 | qdepth = MPT2SAS_RAID_QUEUE_DEPTH; |
| 2064 | r_level = "RAIDX"; |
| 2065 | break; |
| 2066 | } |
| 2067 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2068 | if (!ioc->hide_ir_msg) |
| 2069 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
| 2070 | "wwid(0x%016llx), pd_count(%d), type(%s)\n", |
| 2071 | r_level, raid_device->handle, |
| 2072 | (unsigned long long)raid_device->wwid, |
| 2073 | raid_device->num_pds, ds); |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 2074 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 2075 | /* raid transport support */ |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2076 | if (!ioc->is_warpdrive) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 2077 | _scsih_set_level(sdev, raid_device->volume_type); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2078 | return 0; |
| 2079 | } |
| 2080 | |
| 2081 | /* non-raid handling */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 2082 | if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2083 | if (mpt2sas_config_get_volume_handle(ioc, handle, |
| 2084 | &volume_handle)) { |
| 2085 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2086 | "failure at %s:%d/%s()!\n", ioc->name, |
| 2087 | __FILE__, __LINE__, __func__)); |
| 2088 | return 1; |
| 2089 | } |
| 2090 | if (volume_handle && mpt2sas_config_get_volume_wwid(ioc, |
| 2091 | volume_handle, &volume_wwid)) { |
| 2092 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
| 2093 | "failure at %s:%d/%s()!\n", ioc->name, |
| 2094 | __FILE__, __LINE__, __func__)); |
| 2095 | return 1; |
| 2096 | } |
| 2097 | } |
| 2098 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2099 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2100 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2101 | sas_device_priv_data->sas_target->sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 2102 | if (!sas_device) { |
| 2103 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2104 | dfailprintk(ioc, printk(MPT2SAS_WARN_FMT |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 2105 | "failure at %s:%d/%s()!\n", ioc->name, __FILE__, |
| 2106 | __LINE__, __func__)); |
nagalakshmi.nandigama@lsi.com | 6faace2 | 2011-10-19 15:37:37 +0530 | [diff] [blame] | 2107 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2108 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 2109 | sas_device->volume_handle = volume_handle; |
| 2110 | sas_device->volume_wwid = volume_wwid; |
| 2111 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { |
| 2112 | qdepth = MPT2SAS_SAS_QUEUE_DEPTH; |
| 2113 | ssp_target = 1; |
| 2114 | ds = "SSP"; |
| 2115 | } else { |
| 2116 | qdepth = MPT2SAS_SATA_QUEUE_DEPTH; |
| 2117 | if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
| 2118 | ds = "STP"; |
| 2119 | else if (sas_device->device_info & |
| 2120 | MPI2_SAS_DEVICE_INFO_SATA_DEVICE) |
| 2121 | ds = "SATA"; |
| 2122 | } |
| 2123 | sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " |
| 2124 | "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n", |
| 2125 | ds, sas_device->handle, |
| 2126 | (unsigned long long)sas_device->sas_address, |
| 2127 | sas_device->phy, |
| 2128 | (unsigned long long)sas_device->device_name); |
| 2129 | sdev_printk(KERN_INFO, sdev, "%s: " |
| 2130 | "enclosure_logical_id(0x%016llx), slot(%d)\n", ds, |
| 2131 | (unsigned long long) sas_device->enclosure_logical_id, |
| 2132 | sas_device->slot); |
| 2133 | |
| 2134 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2135 | if (!ssp_target) |
| 2136 | _scsih_display_sata_capabilities(ioc, handle, sdev); |
| 2137 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2138 | |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 2139 | _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2140 | |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 2141 | if (ssp_target) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2142 | sas_read_port_mode_page(sdev); |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 2143 | _scsih_enable_tlr(ioc, sdev); |
| 2144 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2145 | return 0; |
| 2146 | } |
| 2147 | |
| 2148 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2149 | * _scsih_bios_param - fetch head, sector, cylinder info for a disk |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2150 | * @sdev: scsi device struct |
| 2151 | * @bdev: pointer to block device context |
| 2152 | * @capacity: device size (in 512 byte sectors) |
| 2153 | * @params: three element array to place output: |
| 2154 | * params[0] number of heads (max 255) |
| 2155 | * params[1] number of sectors (max 63) |
| 2156 | * params[2] number of cylinders |
| 2157 | * |
| 2158 | * Return nothing. |
| 2159 | */ |
| 2160 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2161 | _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2162 | sector_t capacity, int params[]) |
| 2163 | { |
| 2164 | int heads; |
| 2165 | int sectors; |
| 2166 | sector_t cylinders; |
| 2167 | ulong dummy; |
| 2168 | |
| 2169 | heads = 64; |
| 2170 | sectors = 32; |
| 2171 | |
| 2172 | dummy = heads * sectors; |
| 2173 | cylinders = capacity; |
| 2174 | sector_div(cylinders, dummy); |
| 2175 | |
| 2176 | /* |
| 2177 | * Handle extended translation size for logical drives |
| 2178 | * > 1Gb |
| 2179 | */ |
| 2180 | if ((ulong)capacity >= 0x200000) { |
| 2181 | heads = 255; |
| 2182 | sectors = 63; |
| 2183 | dummy = heads * sectors; |
| 2184 | cylinders = capacity; |
| 2185 | sector_div(cylinders, dummy); |
| 2186 | } |
| 2187 | |
| 2188 | /* return result */ |
| 2189 | params[0] = heads; |
| 2190 | params[1] = sectors; |
| 2191 | params[2] = cylinders; |
| 2192 | |
| 2193 | return 0; |
| 2194 | } |
| 2195 | |
| 2196 | /** |
| 2197 | * _scsih_response_code - translation of device response code |
| 2198 | * @ioc: per adapter object |
| 2199 | * @response_code: response code returned by the device |
| 2200 | * |
| 2201 | * Return nothing. |
| 2202 | */ |
| 2203 | static void |
| 2204 | _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code) |
| 2205 | { |
| 2206 | char *desc; |
| 2207 | |
| 2208 | switch (response_code) { |
| 2209 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: |
| 2210 | desc = "task management request completed"; |
| 2211 | break; |
| 2212 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: |
| 2213 | desc = "invalid frame"; |
| 2214 | break; |
| 2215 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: |
| 2216 | desc = "task management request not supported"; |
| 2217 | break; |
| 2218 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: |
| 2219 | desc = "task management request failed"; |
| 2220 | break; |
| 2221 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: |
| 2222 | desc = "task management request succeeded"; |
| 2223 | break; |
| 2224 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: |
| 2225 | desc = "invalid lun"; |
| 2226 | break; |
| 2227 | case 0xA: |
| 2228 | desc = "overlapped tag attempted"; |
| 2229 | break; |
| 2230 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: |
| 2231 | desc = "task queued, however not sent to target"; |
| 2232 | break; |
| 2233 | default: |
| 2234 | desc = "unknown"; |
| 2235 | break; |
| 2236 | } |
| 2237 | printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n", |
| 2238 | ioc->name, response_code, desc); |
| 2239 | } |
| 2240 | |
| 2241 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2242 | * _scsih_tm_done - tm completion routine |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2243 | * @ioc: per adapter object |
| 2244 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2245 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2246 | * @reply: reply message frame(lower 32bit addr) |
| 2247 | * Context: none. |
| 2248 | * |
| 2249 | * The callback handler when using scsih_issue_tm. |
| 2250 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2251 | * Return 1 meaning mf should be freed from _base_interrupt |
| 2252 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2253 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2254 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2255 | _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] | 2256 | { |
| 2257 | MPI2DefaultReply_t *mpi_reply; |
| 2258 | |
| 2259 | if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2260 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2261 | if (ioc->tm_cmds.smid != smid) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2262 | return 1; |
nagalakshmi.nandigama@lsi.com | 911ae94 | 2011-09-08 06:18:50 +0530 | [diff] [blame] | 2263 | mpt2sas_base_flush_reply_queues(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2264 | ioc->tm_cmds.status |= MPT2_CMD_COMPLETE; |
| 2265 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 2266 | if (mpi_reply) { |
| 2267 | memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 2268 | ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 2269 | } |
| 2270 | ioc->tm_cmds.status &= ~MPT2_CMD_PENDING; |
| 2271 | complete(&ioc->tm_cmds.done); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 2272 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | /** |
| 2276 | * mpt2sas_scsih_set_tm_flag - set per target tm_busy |
| 2277 | * @ioc: per adapter object |
| 2278 | * @handle: device handle |
| 2279 | * |
| 2280 | * During taskmangement request, we need to freeze the device queue. |
| 2281 | */ |
| 2282 | void |
| 2283 | mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2284 | { |
| 2285 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2286 | struct scsi_device *sdev; |
| 2287 | u8 skip = 0; |
| 2288 | |
| 2289 | shost_for_each_device(sdev, ioc->shost) { |
| 2290 | if (skip) |
| 2291 | continue; |
| 2292 | sas_device_priv_data = sdev->hostdata; |
| 2293 | if (!sas_device_priv_data) |
| 2294 | continue; |
| 2295 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2296 | sas_device_priv_data->sas_target->tm_busy = 1; |
| 2297 | skip = 1; |
| 2298 | ioc->ignore_loginfos = 1; |
| 2299 | } |
| 2300 | } |
| 2301 | } |
| 2302 | |
| 2303 | /** |
| 2304 | * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy |
| 2305 | * @ioc: per adapter object |
| 2306 | * @handle: device handle |
| 2307 | * |
| 2308 | * During taskmangement request, we need to freeze the device queue. |
| 2309 | */ |
| 2310 | void |
| 2311 | mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2312 | { |
| 2313 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2314 | struct scsi_device *sdev; |
| 2315 | u8 skip = 0; |
| 2316 | |
| 2317 | shost_for_each_device(sdev, ioc->shost) { |
| 2318 | if (skip) |
| 2319 | continue; |
| 2320 | sas_device_priv_data = sdev->hostdata; |
| 2321 | if (!sas_device_priv_data) |
| 2322 | continue; |
| 2323 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2324 | sas_device_priv_data->sas_target->tm_busy = 0; |
| 2325 | skip = 1; |
| 2326 | ioc->ignore_loginfos = 0; |
| 2327 | } |
| 2328 | } |
| 2329 | } |
| 2330 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2331 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2332 | /** |
| 2333 | * mpt2sas_scsih_issue_tm - main routine for sending tm requests |
| 2334 | * @ioc: per adapter struct |
| 2335 | * @device_handle: device handle |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2336 | * @channel: the channel assigned by the OS |
| 2337 | * @id: the id assigned by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2338 | * @lun: lun number |
| 2339 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h) |
| 2340 | * @smid_task: smid assigned to the task |
| 2341 | * @timeout: timeout in seconds |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2342 | * @serial_number: the serial_number from scmd |
| 2343 | * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2344 | * Context: user |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2345 | * |
| 2346 | * A generic API for sending task management requests to firmware. |
| 2347 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2348 | * The callback index is set inside `ioc->tm_cb_idx`. |
| 2349 | * |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2350 | * Return SUCCESS or FAILED. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2351 | */ |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2352 | int |
| 2353 | mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel, |
| 2354 | uint id, uint lun, u8 type, u16 smid_task, ulong timeout, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2355 | unsigned long serial_number, enum mutex_type m_type) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2356 | { |
| 2357 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 2358 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
| 2359 | u16 smid = 0; |
| 2360 | u32 ioc_state; |
| 2361 | unsigned long timeleft; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2362 | struct scsiio_tracker *scsi_lookup = NULL; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2363 | int rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2364 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2365 | if (m_type == TM_MUTEX_ON) |
| 2366 | mutex_lock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2367 | if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) { |
| 2368 | printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n", |
| 2369 | __func__, ioc->name); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2370 | rc = FAILED; |
| 2371 | goto err_out; |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2372 | } |
| 2373 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 2374 | if (ioc->shost_recovery || ioc->remove_host || |
| 2375 | ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2376 | printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n", |
| 2377 | __func__, ioc->name); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2378 | rc = FAILED; |
| 2379 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2380 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2381 | |
| 2382 | ioc_state = mpt2sas_base_get_iocstate(ioc, 0); |
| 2383 | if (ioc_state & MPI2_DOORBELL_USED) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 2384 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2385 | "active!\n", ioc->name)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2386 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2387 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2388 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2389 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 2393 | mpt2sas_base_fault_info(ioc, ioc_state & |
| 2394 | MPI2_DOORBELL_DATA_MASK); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2395 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2396 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2397 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2398 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2399 | } |
| 2400 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2401 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2402 | if (!smid) { |
| 2403 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 2404 | ioc->name, __func__); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2405 | rc = FAILED; |
| 2406 | goto err_out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2407 | } |
| 2408 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2409 | if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) |
| 2410 | scsi_lookup = &ioc->scsi_lookup[smid_task - 1]; |
| 2411 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2412 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x)," |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2413 | " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type, |
| 2414 | smid_task)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2415 | ioc->tm_cmds.status = MPT2_CMD_PENDING; |
| 2416 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 2417 | ioc->tm_cmds.smid = smid; |
| 2418 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2419 | memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2420 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 2421 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 2422 | mpi_request->TaskType = type; |
| 2423 | mpi_request->TaskMID = cpu_to_le16(smid_task); |
| 2424 | int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN); |
| 2425 | mpt2sas_scsih_set_tm_flag(ioc, handle); |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 2426 | init_completion(&ioc->tm_cmds.done); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2427 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2428 | timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2429 | if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) { |
| 2430 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 2431 | ioc->name, __func__); |
| 2432 | _debug_dump_mf(mpi_request, |
| 2433 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2434 | if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) { |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2435 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2436 | FORCE_BIG_HAMMER); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2437 | rc = (!rc) ? SUCCESS : FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2438 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
| 2439 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 2440 | goto err_out; |
| 2441 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 2445 | mpi_reply = ioc->tm_cmds.reply; |
| 2446 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: " |
| 2447 | "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n", |
| 2448 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 2449 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 2450 | le32_to_cpu(mpi_reply->TerminationCount))); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2451 | if (ioc->logging_level & MPT_DEBUG_TM) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2452 | _scsih_response_code(ioc, mpi_reply->ResponseCode); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2453 | if (mpi_reply->IOCStatus) |
| 2454 | _debug_dump_mf(mpi_request, |
| 2455 | sizeof(Mpi2SCSITaskManagementRequest_t)/4); |
| 2456 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2457 | } |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2458 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2459 | switch (type) { |
| 2460 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2461 | rc = SUCCESS; |
| 2462 | if (scsi_lookup->scmd == NULL) |
| 2463 | break; |
| 2464 | rc = FAILED; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2465 | break; |
| 2466 | |
| 2467 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: |
| 2468 | if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) |
| 2469 | rc = FAILED; |
| 2470 | else |
| 2471 | rc = SUCCESS; |
| 2472 | break; |
| 2473 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2474 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2475 | case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: |
| 2476 | if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) |
| 2477 | rc = FAILED; |
| 2478 | else |
| 2479 | rc = SUCCESS; |
| 2480 | break; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2481 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: |
| 2482 | rc = SUCCESS; |
| 2483 | break; |
| 2484 | default: |
| 2485 | rc = FAILED; |
| 2486 | break; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2487 | } |
| 2488 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2489 | mpt2sas_scsih_clear_tm_flag(ioc, handle); |
| 2490 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2491 | if (m_type == TM_MUTEX_ON) |
| 2492 | mutex_unlock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2493 | |
| 2494 | return rc; |
| 2495 | |
| 2496 | err_out: |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2497 | if (m_type == TM_MUTEX_ON) |
| 2498 | mutex_unlock(&ioc->tm_cmds.mutex); |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2499 | return rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | /** |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2503 | * _scsih_tm_display_info - displays info about the device |
| 2504 | * @ioc: per adapter struct |
| 2505 | * @scmd: pointer to scsi command object |
| 2506 | * |
| 2507 | * Called by task management callback handlers. |
| 2508 | */ |
| 2509 | static void |
| 2510 | _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd) |
| 2511 | { |
| 2512 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2513 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; |
| 2514 | struct _sas_device *sas_device = NULL; |
| 2515 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2516 | char *device_str = NULL; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2517 | |
| 2518 | if (!priv_target) |
| 2519 | return; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2520 | if (ioc->hide_ir_msg) |
| 2521 | device_str = "WarpDrive"; |
| 2522 | else |
| 2523 | device_str = "volume"; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2524 | |
| 2525 | scsi_print_command(scmd); |
| 2526 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 2527 | starget_printk(KERN_INFO, starget, "%s handle(0x%04x), " |
| 2528 | "%s wwid(0x%016llx)\n", device_str, priv_target->handle, |
| 2529 | device_str, (unsigned long long)priv_target->sas_address); |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2530 | } else { |
| 2531 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2532 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 2533 | priv_target->sas_address); |
| 2534 | if (sas_device) { |
| 2535 | if (priv_target->flags & |
| 2536 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2537 | starget_printk(KERN_INFO, starget, |
| 2538 | "volume handle(0x%04x), " |
| 2539 | "volume wwid(0x%016llx)\n", |
| 2540 | sas_device->volume_handle, |
| 2541 | (unsigned long long)sas_device->volume_wwid); |
| 2542 | } |
| 2543 | starget_printk(KERN_INFO, starget, |
| 2544 | "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n", |
| 2545 | sas_device->handle, |
| 2546 | (unsigned long long)sas_device->sas_address, |
| 2547 | sas_device->phy); |
| 2548 | starget_printk(KERN_INFO, starget, |
| 2549 | "enclosure_logical_id(0x%016llx), slot(%d)\n", |
| 2550 | (unsigned long long)sas_device->enclosure_logical_id, |
| 2551 | sas_device->slot); |
| 2552 | } |
| 2553 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2554 | } |
| 2555 | } |
| 2556 | |
| 2557 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2558 | * _scsih_abort - eh threads main abort routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2559 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2560 | * |
| 2561 | * Returns SUCCESS if command aborted else FAILED |
| 2562 | */ |
| 2563 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2564 | _scsih_abort(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2565 | { |
| 2566 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2567 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2568 | u16 smid; |
| 2569 | u16 handle; |
| 2570 | int r; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2571 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2572 | sdev_printk(KERN_INFO, scmd->device, "attempting task abort! " |
| 2573 | "scmd(%p)\n", scmd); |
| 2574 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2575 | |
| 2576 | sas_device_priv_data = scmd->device->hostdata; |
| 2577 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2578 | sdev_printk(KERN_INFO, scmd->device, "device been deleted! " |
| 2579 | "scmd(%p)\n", scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2580 | scmd->result = DID_NO_CONNECT << 16; |
| 2581 | scmd->scsi_done(scmd); |
| 2582 | r = SUCCESS; |
| 2583 | goto out; |
| 2584 | } |
| 2585 | |
| 2586 | /* search for the command */ |
| 2587 | smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd); |
| 2588 | if (!smid) { |
| 2589 | scmd->result = DID_RESET << 16; |
| 2590 | r = SUCCESS; |
| 2591 | goto out; |
| 2592 | } |
| 2593 | |
| 2594 | /* for hidden raid components and volumes this is not supported */ |
| 2595 | if (sas_device_priv_data->sas_target->flags & |
| 2596 | MPT_TARGET_FLAGS_RAID_COMPONENT || |
| 2597 | sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
| 2598 | scmd->result = DID_RESET << 16; |
| 2599 | r = FAILED; |
| 2600 | goto out; |
| 2601 | } |
| 2602 | |
Kashyap, Desai | fa7f316 | 2009-09-23 17:26:58 +0530 | [diff] [blame] | 2603 | mpt2sas_halt_firmware(ioc); |
| 2604 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2605 | handle = sas_device_priv_data->sas_target->handle; |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2606 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2607 | scmd->device->id, scmd->device->lun, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2608 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, |
| 2609 | scmd->serial_number, TM_MUTEX_ON); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2610 | |
| 2611 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2612 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", |
| 2613 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2614 | return r; |
| 2615 | } |
| 2616 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2617 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2618 | * _scsih_dev_reset - eh threads main device reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2619 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2620 | * |
| 2621 | * Returns SUCCESS if command aborted else FAILED |
| 2622 | */ |
| 2623 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2624 | _scsih_dev_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2625 | { |
| 2626 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2627 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2628 | struct _sas_device *sas_device; |
| 2629 | unsigned long flags; |
| 2630 | u16 handle; |
| 2631 | int r; |
| 2632 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2633 | struct scsi_target *starget = scmd->device->sdev_target; |
| 2634 | |
Kashyap, Desai | 37aaa78 | 2010-11-13 04:41:32 +0530 | [diff] [blame] | 2635 | starget_printk(KERN_INFO, starget, "attempting device reset! " |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2636 | "scmd(%p)\n", scmd); |
| 2637 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2638 | |
| 2639 | sas_device_priv_data = scmd->device->hostdata; |
| 2640 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 37aaa78 | 2010-11-13 04:41:32 +0530 | [diff] [blame] | 2641 | starget_printk(KERN_INFO, starget, "device been deleted! " |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2642 | "scmd(%p)\n", scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2643 | scmd->result = DID_NO_CONNECT << 16; |
| 2644 | scmd->scsi_done(scmd); |
| 2645 | r = SUCCESS; |
| 2646 | goto out; |
| 2647 | } |
| 2648 | |
| 2649 | /* for hidden raid components obtain the volume_handle */ |
| 2650 | handle = 0; |
| 2651 | if (sas_device_priv_data->sas_target->flags & |
| 2652 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2653 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2654 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2655 | sas_device_priv_data->sas_target->handle); |
| 2656 | if (sas_device) |
| 2657 | handle = sas_device->volume_handle; |
| 2658 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2659 | } else |
| 2660 | handle = sas_device_priv_data->sas_target->handle; |
| 2661 | |
| 2662 | if (!handle) { |
| 2663 | scmd->result = DID_RESET << 16; |
| 2664 | r = FAILED; |
| 2665 | goto out; |
| 2666 | } |
| 2667 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2668 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2669 | scmd->device->id, scmd->device->lun, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2670 | MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, 0, |
| 2671 | TM_MUTEX_ON); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2672 | |
| 2673 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2674 | sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", |
| 2675 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2676 | return r; |
| 2677 | } |
| 2678 | |
| 2679 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2680 | * _scsih_target_reset - eh threads main target reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2681 | * @scmd: pointer to scsi command object |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2682 | * |
| 2683 | * Returns SUCCESS if command aborted else FAILED |
| 2684 | */ |
| 2685 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2686 | _scsih_target_reset(struct scsi_cmnd *scmd) |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2687 | { |
| 2688 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2689 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2690 | struct _sas_device *sas_device; |
| 2691 | unsigned long flags; |
| 2692 | u16 handle; |
| 2693 | int r; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2694 | struct scsi_target *starget = scmd->device->sdev_target; |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2695 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2696 | starget_printk(KERN_INFO, starget, "attempting target reset! " |
| 2697 | "scmd(%p)\n", scmd); |
| 2698 | _scsih_tm_display_info(ioc, scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2699 | |
| 2700 | sas_device_priv_data = scmd->device->hostdata; |
| 2701 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2702 | starget_printk(KERN_INFO, starget, "target been deleted! " |
| 2703 | "scmd(%p)\n", scmd); |
Eric Moore | 993e0da | 2009-05-18 13:00:45 -0600 | [diff] [blame] | 2704 | scmd->result = DID_NO_CONNECT << 16; |
| 2705 | scmd->scsi_done(scmd); |
| 2706 | r = SUCCESS; |
| 2707 | goto out; |
| 2708 | } |
| 2709 | |
| 2710 | /* for hidden raid components obtain the volume_handle */ |
| 2711 | handle = 0; |
| 2712 | if (sas_device_priv_data->sas_target->flags & |
| 2713 | MPT_TARGET_FLAGS_RAID_COMPONENT) { |
| 2714 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 2715 | sas_device = _scsih_sas_device_find_by_handle(ioc, |
| 2716 | sas_device_priv_data->sas_target->handle); |
| 2717 | if (sas_device) |
| 2718 | handle = sas_device->volume_handle; |
| 2719 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 2720 | } else |
| 2721 | handle = sas_device_priv_data->sas_target->handle; |
| 2722 | |
| 2723 | if (!handle) { |
| 2724 | scmd->result = DID_RESET << 16; |
| 2725 | r = FAILED; |
| 2726 | goto out; |
| 2727 | } |
| 2728 | |
Kashyap, Desai | 8ed9a03 | 2010-03-17 16:25:59 +0530 | [diff] [blame] | 2729 | r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel, |
| 2730 | scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2731 | 30, 0, TM_MUTEX_ON); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2732 | |
| 2733 | out: |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2734 | starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", |
| 2735 | ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2736 | return r; |
| 2737 | } |
| 2738 | |
| 2739 | /** |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2740 | * _scsih_host_reset - eh threads main host reset routine |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 2741 | * @scmd: pointer to scsi command object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2742 | * |
| 2743 | * Returns SUCCESS if command aborted else FAILED |
| 2744 | */ |
| 2745 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 2746 | _scsih_host_reset(struct scsi_cmnd *scmd) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2747 | { |
| 2748 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 2749 | int r, retval; |
| 2750 | |
| 2751 | printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n", |
| 2752 | ioc->name, scmd); |
| 2753 | scsi_print_command(scmd); |
| 2754 | |
| 2755 | retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2756 | FORCE_BIG_HAMMER); |
| 2757 | r = (retval < 0) ? FAILED : SUCCESS; |
| 2758 | printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n", |
| 2759 | ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 2760 | |
| 2761 | return r; |
| 2762 | } |
| 2763 | |
| 2764 | /** |
| 2765 | * _scsih_fw_event_add - insert and queue up fw_event |
| 2766 | * @ioc: per adapter object |
| 2767 | * @fw_event: object describing the event |
| 2768 | * Context: This function will acquire ioc->fw_event_lock. |
| 2769 | * |
| 2770 | * This adds the firmware event object into link list, then queues it up to |
| 2771 | * be processed from user context. |
| 2772 | * |
| 2773 | * Return nothing. |
| 2774 | */ |
| 2775 | static void |
| 2776 | _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event) |
| 2777 | { |
| 2778 | unsigned long flags; |
| 2779 | |
| 2780 | if (ioc->firmware_event_thread == NULL) |
| 2781 | return; |
| 2782 | |
| 2783 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2784 | list_add_tail(&fw_event->list, &ioc->fw_event_list); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2785 | INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work); |
| 2786 | queue_delayed_work(ioc->firmware_event_thread, |
| 2787 | &fw_event->delayed_work, 0); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2788 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2789 | } |
| 2790 | |
| 2791 | /** |
| 2792 | * _scsih_fw_event_free - delete fw_event |
| 2793 | * @ioc: per adapter object |
| 2794 | * @fw_event: object describing the event |
| 2795 | * Context: This function will acquire ioc->fw_event_lock. |
| 2796 | * |
| 2797 | * This removes firmware event object from link list, frees associated memory. |
| 2798 | * |
| 2799 | * Return nothing. |
| 2800 | */ |
| 2801 | static void |
| 2802 | _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work |
| 2803 | *fw_event) |
| 2804 | { |
| 2805 | unsigned long flags; |
| 2806 | |
| 2807 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 2808 | list_del(&fw_event->list); |
| 2809 | kfree(fw_event->event_data); |
| 2810 | kfree(fw_event); |
| 2811 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 2812 | } |
| 2813 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2814 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2815 | /** |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2816 | * _scsih_error_recovery_delete_devices - remove devices not responding |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2817 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2818 | * |
| 2819 | * Return nothing. |
| 2820 | */ |
| 2821 | static void |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2822 | _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2823 | { |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2824 | struct fw_event_work *fw_event; |
| 2825 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2826 | if (ioc->is_driver_loading) |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2827 | return; |
Dan Carpenter | 181a9d7 | 2011-11-04 21:25:01 +0300 | [diff] [blame] | 2828 | |
| 2829 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2830 | if (!fw_event) |
| 2831 | return; |
| 2832 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2833 | fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES; |
| 2834 | fw_event->ioc = ioc; |
| 2835 | _scsih_fw_event_add(ioc, fw_event); |
| 2836 | } |
| 2837 | |
| 2838 | /** |
| 2839 | * mpt2sas_port_enable_complete - port enable completed (fake event) |
| 2840 | * @ioc: per adapter object |
| 2841 | * |
| 2842 | * Return nothing. |
| 2843 | */ |
| 2844 | void |
| 2845 | mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc) |
| 2846 | { |
| 2847 | struct fw_event_work *fw_event; |
| 2848 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2849 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 2850 | if (!fw_event) |
| 2851 | return; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 2852 | fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2853 | fw_event->ioc = ioc; |
| 2854 | _scsih_fw_event_add(ioc, fw_event); |
| 2855 | } |
| 2856 | |
| 2857 | /** |
| 2858 | * _scsih_fw_event_cleanup_queue - cleanup event queue |
| 2859 | * @ioc: per adapter object |
| 2860 | * |
| 2861 | * Walk the firmware event queue, either killing timers, or waiting |
| 2862 | * for outstanding events to complete |
| 2863 | * |
| 2864 | * Return nothing. |
| 2865 | */ |
| 2866 | static void |
| 2867 | _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc) |
| 2868 | { |
| 2869 | struct fw_event_work *fw_event, *next; |
| 2870 | |
| 2871 | if (list_empty(&ioc->fw_event_list) || |
| 2872 | !ioc->firmware_event_thread || in_interrupt()) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2873 | return; |
| 2874 | |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 2875 | list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) { |
| 2876 | if (cancel_delayed_work(&fw_event->delayed_work)) { |
| 2877 | _scsih_fw_event_free(ioc, fw_event); |
| 2878 | continue; |
| 2879 | } |
| 2880 | fw_event->cancel_pending_work = 1; |
| 2881 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2882 | } |
| 2883 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2884 | /** |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2885 | * _scsih_ublock_io_all_device - unblock every device |
| 2886 | * @ioc: per adapter object |
| 2887 | * |
| 2888 | * change the device state from block to running |
| 2889 | */ |
| 2890 | static void |
| 2891 | _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc) |
| 2892 | { |
| 2893 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2894 | struct scsi_device *sdev; |
| 2895 | |
| 2896 | shost_for_each_device(sdev, ioc->shost) { |
| 2897 | sas_device_priv_data = sdev->hostdata; |
| 2898 | if (!sas_device_priv_data) |
| 2899 | continue; |
| 2900 | if (!sas_device_priv_data->block) |
| 2901 | continue; |
| 2902 | sas_device_priv_data->block = 0; |
| 2903 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, " |
| 2904 | "handle(0x%04x)\n", |
| 2905 | sas_device_priv_data->sas_target->handle)); |
| 2906 | scsi_internal_device_unblock(sdev); |
| 2907 | } |
| 2908 | } |
| 2909 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2910 | * _scsih_ublock_io_device - set the device state to SDEV_RUNNING |
| 2911 | * @ioc: per adapter object |
| 2912 | * @handle: device handle |
| 2913 | * |
| 2914 | * During device pull we need to appropiately set the sdev state. |
| 2915 | */ |
| 2916 | static void |
| 2917 | _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2918 | { |
| 2919 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2920 | struct scsi_device *sdev; |
| 2921 | |
| 2922 | shost_for_each_device(sdev, ioc->shost) { |
| 2923 | sas_device_priv_data = sdev->hostdata; |
| 2924 | if (!sas_device_priv_data) |
| 2925 | continue; |
| 2926 | if (!sas_device_priv_data->block) |
| 2927 | continue; |
| 2928 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2929 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2930 | MPT2SAS_INFO_FMT "SDEV_RUNNING: " |
| 2931 | "handle(0x%04x)\n", ioc->name, handle)); |
| 2932 | sas_device_priv_data->block = 0; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 2933 | scsi_internal_device_unblock(sdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2934 | } |
| 2935 | } |
| 2936 | } |
| 2937 | |
| 2938 | /** |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 2939 | * _scsih_block_io_all_device - set the device state to SDEV_BLOCK |
| 2940 | * @ioc: per adapter object |
| 2941 | * @handle: device handle |
| 2942 | * |
| 2943 | * During device pull we need to appropiately set the sdev state. |
| 2944 | */ |
| 2945 | static void |
| 2946 | _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc) |
| 2947 | { |
| 2948 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2949 | struct scsi_device *sdev; |
| 2950 | |
| 2951 | shost_for_each_device(sdev, ioc->shost) { |
| 2952 | sas_device_priv_data = sdev->hostdata; |
| 2953 | if (!sas_device_priv_data) |
| 2954 | continue; |
| 2955 | if (sas_device_priv_data->block) |
| 2956 | continue; |
| 2957 | sas_device_priv_data->block = 1; |
| 2958 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, " |
| 2959 | "handle(0x%04x)\n", |
| 2960 | sas_device_priv_data->sas_target->handle)); |
| 2961 | scsi_internal_device_block(sdev); |
| 2962 | } |
| 2963 | } |
| 2964 | |
| 2965 | |
| 2966 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2967 | * _scsih_block_io_device - set the device state to SDEV_BLOCK |
| 2968 | * @ioc: per adapter object |
| 2969 | * @handle: device handle |
| 2970 | * |
| 2971 | * During device pull we need to appropiately set the sdev state. |
| 2972 | */ |
| 2973 | static void |
| 2974 | _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 2975 | { |
| 2976 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 2977 | struct scsi_device *sdev; |
| 2978 | |
| 2979 | shost_for_each_device(sdev, ioc->shost) { |
| 2980 | sas_device_priv_data = sdev->hostdata; |
| 2981 | if (!sas_device_priv_data) |
| 2982 | continue; |
| 2983 | if (sas_device_priv_data->block) |
| 2984 | continue; |
| 2985 | if (sas_device_priv_data->sas_target->handle == handle) { |
| 2986 | dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, |
| 2987 | MPT2SAS_INFO_FMT "SDEV_BLOCK: " |
| 2988 | "handle(0x%04x)\n", ioc->name, handle)); |
| 2989 | sas_device_priv_data->block = 1; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 2990 | scsi_internal_device_block(sdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2991 | } |
| 2992 | } |
| 2993 | } |
| 2994 | |
| 2995 | /** |
| 2996 | * _scsih_block_io_to_children_attached_to_ex |
| 2997 | * @ioc: per adapter object |
| 2998 | * @sas_expander: the sas_device object |
| 2999 | * |
| 3000 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 3001 | * attached to this expander. This function called when expander is |
| 3002 | * pulled. |
| 3003 | */ |
| 3004 | static void |
| 3005 | _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc, |
| 3006 | struct _sas_node *sas_expander) |
| 3007 | { |
| 3008 | struct _sas_port *mpt2sas_port; |
| 3009 | struct _sas_device *sas_device; |
| 3010 | struct _sas_node *expander_sibling; |
| 3011 | unsigned long flags; |
| 3012 | |
| 3013 | if (!sas_expander) |
| 3014 | return; |
| 3015 | |
| 3016 | list_for_each_entry(mpt2sas_port, |
| 3017 | &sas_expander->sas_port_list, port_list) { |
| 3018 | if (mpt2sas_port->remote_identify.device_type == |
| 3019 | SAS_END_DEVICE) { |
| 3020 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3021 | sas_device = |
| 3022 | mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 3023 | mpt2sas_port->remote_identify.sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 3024 | if (sas_device) |
| 3025 | set_bit(sas_device->handle, |
| 3026 | ioc->blocking_handles); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3027 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3028 | } |
| 3029 | } |
| 3030 | |
| 3031 | list_for_each_entry(mpt2sas_port, |
| 3032 | &sas_expander->sas_port_list, port_list) { |
| 3033 | |
| 3034 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 3035 | SAS_EDGE_EXPANDER_DEVICE || |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3036 | mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 3037 | SAS_FANOUT_EXPANDER_DEVICE) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3038 | expander_sibling = |
| 3039 | mpt2sas_scsih_expander_find_by_sas_address( |
| 3040 | ioc, mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3041 | _scsih_block_io_to_children_attached_to_ex(ioc, |
| 3042 | expander_sibling); |
| 3043 | } |
| 3044 | } |
| 3045 | } |
| 3046 | |
| 3047 | /** |
| 3048 | * _scsih_block_io_to_children_attached_directly |
| 3049 | * @ioc: per adapter object |
| 3050 | * @event_data: topology change event data |
| 3051 | * |
| 3052 | * This routine set sdev state to SDEV_BLOCK for all devices |
| 3053 | * direct attached during device pull. |
| 3054 | */ |
| 3055 | static void |
| 3056 | _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc, |
| 3057 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3058 | { |
| 3059 | int i; |
| 3060 | u16 handle; |
| 3061 | u16 reason_code; |
| 3062 | u8 phy_number; |
| 3063 | |
| 3064 | for (i = 0; i < event_data->NumEntries; i++) { |
| 3065 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3066 | if (!handle) |
| 3067 | continue; |
| 3068 | phy_number = event_data->StartPhyNum + i; |
| 3069 | reason_code = event_data->PHY[i].PhyStatus & |
| 3070 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3071 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING) |
| 3072 | _scsih_block_io_device(ioc, handle); |
| 3073 | } |
| 3074 | } |
| 3075 | |
| 3076 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3077 | * _scsih_tm_tr_send - send task management request |
| 3078 | * @ioc: per adapter object |
| 3079 | * @handle: device handle |
| 3080 | * Context: interrupt time. |
| 3081 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3082 | * This code is to initiate the device removal handshake protocol |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3083 | * with controller firmware. This function will issue target reset |
| 3084 | * using high priority request queue. It will send a sas iounit |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3085 | * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3086 | * |
| 3087 | * This is designed to send muliple task management request at the same |
| 3088 | * time to the fifo. If the fifo is full, we will append the request, |
| 3089 | * and process it in a future completion. |
| 3090 | */ |
| 3091 | static void |
| 3092 | _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3093 | { |
| 3094 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3095 | u16 smid; |
| 3096 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3097 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; |
| 3098 | u64 sas_address = 0; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3099 | unsigned long flags; |
| 3100 | struct _tr_list *delayed_tr; |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3101 | u32 ioc_state; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3102 | |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3103 | if (ioc->remove_host) { |
| 3104 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been " |
| 3105 | "removed: handle(0x%04x)\n", __func__, ioc->name, handle)); |
| 3106 | return; |
| 3107 | } else if (ioc->pci_error_recovery) { |
| 3108 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci " |
| 3109 | "error recovery: handle(0x%04x)\n", __func__, ioc->name, |
| 3110 | handle)); |
| 3111 | return; |
| 3112 | } |
| 3113 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 3114 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 3115 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not " |
| 3116 | "operational: handle(0x%04x)\n", __func__, ioc->name, |
| 3117 | handle)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3118 | return; |
| 3119 | } |
| 3120 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3121 | /* if PD, then return */ |
| 3122 | if (test_bit(handle, ioc->pd_handles)) |
| 3123 | return; |
| 3124 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3125 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 3126 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3127 | if (sas_device && sas_device->starget && |
| 3128 | sas_device->starget->hostdata) { |
| 3129 | sas_target_priv_data = sas_device->starget->hostdata; |
| 3130 | sas_target_priv_data->deleted = 1; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3131 | sas_address = sas_device->sas_address; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3132 | } |
| 3133 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3134 | |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3135 | if (sas_target_priv_data) { |
| 3136 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: " |
| 3137 | "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle, |
| 3138 | (unsigned long long)sas_address)); |
| 3139 | _scsih_ublock_io_device(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 3140 | sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE; |
nagalakshmi.nandigama@lsi.com | f3db032 | 2011-10-19 15:37:14 +0530 | [diff] [blame] | 3141 | } |
| 3142 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3143 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); |
| 3144 | if (!smid) { |
| 3145 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3146 | if (!delayed_tr) |
| 3147 | return; |
| 3148 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3149 | delayed_tr->handle = handle; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3150 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 3151 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3152 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 3153 | ioc->name, handle)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3154 | return; |
| 3155 | } |
| 3156 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3157 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " |
| 3158 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, |
| 3159 | ioc->tm_tr_cb_idx)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3160 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3161 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 3162 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3163 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3164 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3165 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
| 3166 | } |
| 3167 | |
| 3168 | |
| 3169 | |
| 3170 | /** |
| 3171 | * _scsih_sas_control_complete - completion routine |
| 3172 | * @ioc: per adapter object |
| 3173 | * @smid: system request message index |
| 3174 | * @msix_index: MSIX table index supplied by the OS |
| 3175 | * @reply: reply message frame(lower 32bit addr) |
| 3176 | * Context: interrupt time. |
| 3177 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3178 | * This is the sas iounit control completion routine. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3179 | * 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] | 3180 | * handshake protocol with controller firmware. |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3181 | * |
| 3182 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3183 | * 0 means the mf is freed from this function. |
| 3184 | */ |
| 3185 | static u8 |
| 3186 | _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 3187 | u8 msix_index, u32 reply) |
| 3188 | { |
Kashyap, Desai | 363fa50f | 2010-11-13 04:29:20 +0530 | [diff] [blame] | 3189 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3190 | Mpi2SasIoUnitControlReply_t *mpi_reply = |
| 3191 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
Kashyap, Desai | 363fa50f | 2010-11-13 04:29:20 +0530 | [diff] [blame] | 3192 | #endif |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3193 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3194 | "sc_complete:handle(0x%04x), (open) " |
| 3195 | "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 3196 | ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid, |
| 3197 | le16_to_cpu(mpi_reply->IOCStatus), |
| 3198 | le32_to_cpu(mpi_reply->IOCLogInfo))); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3199 | return 1; |
| 3200 | } |
| 3201 | |
| 3202 | /** |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3203 | * _scsih_tm_tr_volume_send - send target reset request for volumes |
| 3204 | * @ioc: per adapter object |
| 3205 | * @handle: device handle |
| 3206 | * Context: interrupt time. |
| 3207 | * |
| 3208 | * This is designed to send muliple task management request at the same |
| 3209 | * time to the fifo. If the fifo is full, we will append the request, |
| 3210 | * and process it in a future completion. |
| 3211 | */ |
| 3212 | static void |
| 3213 | _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3214 | { |
| 3215 | Mpi2SCSITaskManagementRequest_t *mpi_request; |
| 3216 | u16 smid; |
| 3217 | struct _tr_list *delayed_tr; |
| 3218 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3219 | if (ioc->shost_recovery || ioc->remove_host || |
| 3220 | ioc->pci_error_recovery) { |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3221 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3222 | "progress!\n", __func__, ioc->name)); |
| 3223 | return; |
| 3224 | } |
| 3225 | |
| 3226 | smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx); |
| 3227 | if (!smid) { |
| 3228 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3229 | if (!delayed_tr) |
| 3230 | return; |
| 3231 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3232 | delayed_tr->handle = handle; |
| 3233 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list); |
| 3234 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3235 | "DELAYED:tr:handle(0x%04x), (open)\n", |
| 3236 | ioc->name, handle)); |
| 3237 | return; |
| 3238 | } |
| 3239 | |
| 3240 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), " |
| 3241 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid, |
| 3242 | ioc->tm_tr_volume_cb_idx)); |
| 3243 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3244 | memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t)); |
| 3245 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3246 | mpi_request->DevHandle = cpu_to_le16(handle); |
| 3247 | mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
| 3248 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
| 3249 | } |
| 3250 | |
| 3251 | /** |
| 3252 | * _scsih_tm_volume_tr_complete - target reset completion |
| 3253 | * @ioc: per adapter object |
| 3254 | * @smid: system request message index |
| 3255 | * @msix_index: MSIX table index supplied by the OS |
| 3256 | * @reply: reply message frame(lower 32bit addr) |
| 3257 | * Context: interrupt time. |
| 3258 | * |
| 3259 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3260 | * 0 means the mf is freed from this function. |
| 3261 | */ |
| 3262 | static u8 |
| 3263 | _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 3264 | u8 msix_index, u32 reply) |
| 3265 | { |
| 3266 | u16 handle; |
| 3267 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
| 3268 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3269 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 3270 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3271 | if (ioc->shost_recovery || ioc->remove_host || |
| 3272 | ioc->pci_error_recovery) { |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3273 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " |
| 3274 | "progress!\n", __func__, ioc->name)); |
| 3275 | return 1; |
| 3276 | } |
| 3277 | |
| 3278 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3279 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3280 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3281 | dewtprintk(ioc, printk("spurious interrupt: " |
| 3282 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle, |
| 3283 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3284 | return 0; |
| 3285 | } |
| 3286 | |
| 3287 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3288 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3289 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3290 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3291 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3292 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3293 | |
| 3294 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3295 | } |
| 3296 | |
| 3297 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3298 | * _scsih_tm_tr_complete - |
| 3299 | * @ioc: per adapter object |
| 3300 | * @smid: system request message index |
| 3301 | * @msix_index: MSIX table index supplied by the OS |
| 3302 | * @reply: reply message frame(lower 32bit addr) |
| 3303 | * Context: interrupt time. |
| 3304 | * |
| 3305 | * This is the target reset completion routine. |
| 3306 | * 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] | 3307 | * handshake protocol with controller firmware. |
| 3308 | * 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] | 3309 | * |
| 3310 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3311 | * 0 means the mf is freed from this function. |
| 3312 | */ |
| 3313 | static u8 |
| 3314 | _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 3315 | u32 reply) |
| 3316 | { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3317 | u16 handle; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3318 | Mpi2SCSITaskManagementRequest_t *mpi_request_tm; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3319 | Mpi2SCSITaskManagementReply_t *mpi_reply = |
| 3320 | mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 3321 | Mpi2SasIoUnitControlRequest_t *mpi_request; |
| 3322 | u16 smid_sas_ctrl; |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3323 | u32 ioc_state; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3324 | |
nagalakshmi.nandigama@lsi.com | f881cea | 2011-10-19 15:37:00 +0530 | [diff] [blame] | 3325 | if (ioc->remove_host) { |
| 3326 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been " |
| 3327 | "removed\n", __func__, ioc->name)); |
| 3328 | return 1; |
| 3329 | } else if (ioc->pci_error_recovery) { |
| 3330 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci " |
| 3331 | "error recovery\n", __func__, ioc->name)); |
| 3332 | return 1; |
| 3333 | } |
| 3334 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 3335 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 3336 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not " |
| 3337 | "operational\n", __func__, ioc->name)); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3338 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3339 | } |
| 3340 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3341 | mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3342 | handle = le16_to_cpu(mpi_request_tm->DevHandle); |
| 3343 | if (handle != le16_to_cpu(mpi_reply->DevHandle)) { |
| 3344 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: " |
| 3345 | "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle, |
| 3346 | le16_to_cpu(mpi_reply->DevHandle), smid)); |
| 3347 | return 0; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3348 | } |
| 3349 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3350 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3351 | "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), " |
| 3352 | "loginfo(0x%08x), completed(%d)\n", ioc->name, |
| 3353 | handle, smid, le16_to_cpu(mpi_reply->IOCStatus), |
| 3354 | le32_to_cpu(mpi_reply->IOCLogInfo), |
| 3355 | le32_to_cpu(mpi_reply->TerminationCount))); |
| 3356 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3357 | smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx); |
| 3358 | if (!smid_sas_ctrl) { |
| 3359 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 3360 | ioc->name, __func__); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3361 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3362 | } |
| 3363 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3364 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), " |
| 3365 | "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl, |
| 3366 | ioc->tm_sas_control_cb_idx)); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3367 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl); |
| 3368 | memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t)); |
| 3369 | mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL; |
| 3370 | mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3371 | mpi_request->DevHandle = mpi_request_tm->DevHandle; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3372 | mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3373 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3374 | return _scsih_check_for_pending_tm(ioc, smid); |
| 3375 | } |
| 3376 | |
| 3377 | /** |
| 3378 | * _scsih_check_for_pending_tm - check for pending task management |
| 3379 | * @ioc: per adapter object |
| 3380 | * @smid: system request message index |
| 3381 | * |
| 3382 | * This will check delayed target reset list, and feed the |
| 3383 | * next reqeust. |
| 3384 | * |
| 3385 | * Return 1 meaning mf should be freed from _base_interrupt |
| 3386 | * 0 means the mf is freed from this function. |
| 3387 | */ |
| 3388 | static u8 |
| 3389 | _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 3390 | { |
| 3391 | struct _tr_list *delayed_tr; |
| 3392 | |
| 3393 | if (!list_empty(&ioc->delayed_tr_volume_list)) { |
| 3394 | delayed_tr = list_entry(ioc->delayed_tr_volume_list.next, |
| 3395 | struct _tr_list, list); |
| 3396 | mpt2sas_base_free_smid(ioc, smid); |
| 3397 | _scsih_tm_tr_volume_send(ioc, delayed_tr->handle); |
| 3398 | list_del(&delayed_tr->list); |
| 3399 | kfree(delayed_tr); |
| 3400 | return 0; |
| 3401 | } |
| 3402 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3403 | if (!list_empty(&ioc->delayed_tr_list)) { |
| 3404 | delayed_tr = list_entry(ioc->delayed_tr_list.next, |
| 3405 | struct _tr_list, list); |
| 3406 | mpt2sas_base_free_smid(ioc, smid); |
| 3407 | _scsih_tm_tr_send(ioc, delayed_tr->handle); |
| 3408 | list_del(&delayed_tr->list); |
| 3409 | kfree(delayed_tr); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3410 | return 0; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3411 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3412 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 3413 | return 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3414 | } |
| 3415 | |
| 3416 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3417 | * _scsih_check_topo_delete_events - sanity check on topo events |
| 3418 | * @ioc: per adapter object |
| 3419 | * @event_data: the event data payload |
| 3420 | * |
| 3421 | * This routine added to better handle cable breaker. |
| 3422 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3423 | * This handles the case where driver receives multiple expander |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3424 | * add and delete events in a single shot. When there is a delete event |
| 3425 | * the routine will void any pending add events waiting in the event queue. |
| 3426 | * |
| 3427 | * Return nothing. |
| 3428 | */ |
| 3429 | static void |
| 3430 | _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 3431 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 3432 | { |
| 3433 | struct fw_event_work *fw_event; |
| 3434 | Mpi2EventDataSasTopologyChangeList_t *local_event_data; |
| 3435 | u16 expander_handle; |
| 3436 | struct _sas_node *sas_expander; |
| 3437 | unsigned long flags; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3438 | int i, reason_code; |
| 3439 | u16 handle; |
| 3440 | |
| 3441 | for (i = 0 ; i < event_data->NumEntries; i++) { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3442 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 3443 | if (!handle) |
| 3444 | continue; |
| 3445 | reason_code = event_data->PHY[i].PhyStatus & |
| 3446 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 3447 | if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING) |
| 3448 | _scsih_tm_tr_send(ioc, handle); |
| 3449 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3450 | |
| 3451 | expander_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 3452 | if (expander_handle < ioc->sas_hba.num_phys) { |
| 3453 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3454 | return; |
| 3455 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 3456 | if (event_data->ExpStatus == |
| 3457 | MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) { |
| 3458 | /* put expander attached devices into blocking state */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3459 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 3460 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 3461 | expander_handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3462 | _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^] | 3463 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 3464 | do { |
| 3465 | handle = find_first_bit(ioc->blocking_handles, |
| 3466 | ioc->facts.MaxDevHandle); |
| 3467 | if (handle < ioc->facts.MaxDevHandle) |
| 3468 | _scsih_block_io_device(ioc, handle); |
| 3469 | } while (test_and_clear_bit(handle, ioc->blocking_handles)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3470 | } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING) |
| 3471 | _scsih_block_io_to_children_attached_directly(ioc, event_data); |
| 3472 | |
| 3473 | if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) |
| 3474 | return; |
| 3475 | |
| 3476 | /* mark ignore flag for pending events */ |
| 3477 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 3478 | list_for_each_entry(fw_event, &ioc->fw_event_list, list) { |
| 3479 | if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST || |
| 3480 | fw_event->ignore) |
| 3481 | continue; |
| 3482 | local_event_data = fw_event->event_data; |
| 3483 | if (local_event_data->ExpStatus == |
| 3484 | MPI2_EVENT_SAS_TOPO_ES_ADDED || |
| 3485 | local_event_data->ExpStatus == |
| 3486 | MPI2_EVENT_SAS_TOPO_ES_RESPONDING) { |
| 3487 | if (le16_to_cpu(local_event_data->ExpanderDevHandle) == |
| 3488 | expander_handle) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 3489 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3490 | "setting ignoring flag\n", ioc->name)); |
| 3491 | fw_event->ignore = 1; |
| 3492 | } |
| 3493 | } |
| 3494 | } |
| 3495 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 3496 | } |
| 3497 | |
| 3498 | /** |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3499 | * _scsih_set_volume_delete_flag - setting volume delete flag |
| 3500 | * @ioc: per adapter object |
| 3501 | * @handle: device handle |
| 3502 | * |
| 3503 | * This |
| 3504 | * Return nothing. |
| 3505 | */ |
| 3506 | static void |
| 3507 | _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 3508 | { |
| 3509 | struct _raid_device *raid_device; |
| 3510 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 3511 | unsigned long flags; |
| 3512 | |
| 3513 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 3514 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 3515 | if (raid_device && raid_device->starget && |
| 3516 | raid_device->starget->hostdata) { |
| 3517 | sas_target_priv_data = |
| 3518 | raid_device->starget->hostdata; |
| 3519 | sas_target_priv_data->deleted = 1; |
| 3520 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3521 | "setting delete flag: handle(0x%04x), " |
| 3522 | "wwid(0x%016llx)\n", ioc->name, handle, |
| 3523 | (unsigned long long) raid_device->wwid)); |
| 3524 | } |
| 3525 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 3526 | } |
| 3527 | |
| 3528 | /** |
| 3529 | * _scsih_set_volume_handle_for_tr - set handle for target reset to volume |
| 3530 | * @handle: input handle |
| 3531 | * @a: handle for volume a |
| 3532 | * @b: handle for volume b |
| 3533 | * |
| 3534 | * IR firmware only supports two raid volumes. The purpose of this |
| 3535 | * routine is to set the volume handle in either a or b. When the given |
| 3536 | * input handle is non-zero, or when a and b have not been set before. |
| 3537 | */ |
| 3538 | static void |
| 3539 | _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b) |
| 3540 | { |
| 3541 | if (!handle || handle == *a || handle == *b) |
| 3542 | return; |
| 3543 | if (!*a) |
| 3544 | *a = handle; |
| 3545 | else if (!*b) |
| 3546 | *b = handle; |
| 3547 | } |
| 3548 | |
| 3549 | /** |
| 3550 | * _scsih_check_ir_config_unhide_events - check for UNHIDE events |
| 3551 | * @ioc: per adapter object |
| 3552 | * @event_data: the event data payload |
| 3553 | * Context: interrupt time. |
| 3554 | * |
| 3555 | * This routine will send target reset to volume, followed by target |
| 3556 | * resets to the PDs. This is called when a PD has been removed, or |
| 3557 | * volume has been deleted or removed. When the target reset is sent |
| 3558 | * to volume, the PD target resets need to be queued to start upon |
| 3559 | * completion of the volume target reset. |
| 3560 | * |
| 3561 | * Return nothing. |
| 3562 | */ |
| 3563 | static void |
| 3564 | _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc, |
| 3565 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 3566 | { |
| 3567 | Mpi2EventIrConfigElement_t *element; |
| 3568 | int i; |
| 3569 | u16 handle, volume_handle, a, b; |
| 3570 | struct _tr_list *delayed_tr; |
| 3571 | |
| 3572 | a = 0; |
| 3573 | b = 0; |
| 3574 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3575 | if (ioc->is_warpdrive) |
| 3576 | return; |
| 3577 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 3578 | /* Volume Resets for Deleted or Removed */ |
| 3579 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3580 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3581 | if (element->ReasonCode == |
| 3582 | MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED || |
| 3583 | element->ReasonCode == |
| 3584 | MPI2_EVENT_IR_CHANGE_RC_REMOVED) { |
| 3585 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3586 | _scsih_set_volume_delete_flag(ioc, volume_handle); |
| 3587 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3588 | } |
| 3589 | } |
| 3590 | |
| 3591 | /* Volume Resets for UNHIDE events */ |
| 3592 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3593 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3594 | if (le32_to_cpu(event_data->Flags) & |
| 3595 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) |
| 3596 | continue; |
| 3597 | if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) { |
| 3598 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3599 | _scsih_set_volume_handle_for_tr(volume_handle, &a, &b); |
| 3600 | } |
| 3601 | } |
| 3602 | |
| 3603 | if (a) |
| 3604 | _scsih_tm_tr_volume_send(ioc, a); |
| 3605 | if (b) |
| 3606 | _scsih_tm_tr_volume_send(ioc, b); |
| 3607 | |
| 3608 | /* PD target resets */ |
| 3609 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 3610 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 3611 | if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE) |
| 3612 | continue; |
| 3613 | handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 3614 | volume_handle = le16_to_cpu(element->VolDevHandle); |
| 3615 | clear_bit(handle, ioc->pd_handles); |
| 3616 | if (!volume_handle) |
| 3617 | _scsih_tm_tr_send(ioc, handle); |
| 3618 | else if (volume_handle == a || volume_handle == b) { |
| 3619 | delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); |
| 3620 | BUG_ON(!delayed_tr); |
| 3621 | INIT_LIST_HEAD(&delayed_tr->list); |
| 3622 | delayed_tr->handle = handle; |
| 3623 | list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list); |
| 3624 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 3625 | "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name, |
| 3626 | handle)); |
| 3627 | } else |
| 3628 | _scsih_tm_tr_send(ioc, handle); |
| 3629 | } |
| 3630 | } |
| 3631 | |
| 3632 | |
| 3633 | /** |
| 3634 | * _scsih_check_volume_delete_events - set delete flag for volumes |
| 3635 | * @ioc: per adapter object |
| 3636 | * @event_data: the event data payload |
| 3637 | * Context: interrupt time. |
| 3638 | * |
| 3639 | * This will handle the case when the cable connected to entire volume is |
| 3640 | * pulled. We will take care of setting the deleted flag so normal IO will |
| 3641 | * not be sent. |
| 3642 | * |
| 3643 | * Return nothing. |
| 3644 | */ |
| 3645 | static void |
| 3646 | _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc, |
| 3647 | Mpi2EventDataIrVolume_t *event_data) |
| 3648 | { |
| 3649 | u32 state; |
| 3650 | |
| 3651 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 3652 | return; |
| 3653 | state = le32_to_cpu(event_data->NewValue); |
| 3654 | if (state == MPI2_RAID_VOL_STATE_MISSING || state == |
| 3655 | MPI2_RAID_VOL_STATE_FAILED) |
| 3656 | _scsih_set_volume_delete_flag(ioc, |
| 3657 | le16_to_cpu(event_data->VolDevHandle)); |
| 3658 | } |
| 3659 | |
| 3660 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3661 | * _scsih_flush_running_cmds - completing outstanding commands. |
| 3662 | * @ioc: per adapter object |
| 3663 | * |
| 3664 | * The flushing out of all pending scmd commands following host reset, |
| 3665 | * where all IO is dropped to the floor. |
| 3666 | * |
| 3667 | * Return nothing. |
| 3668 | */ |
| 3669 | static void |
| 3670 | _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc) |
| 3671 | { |
| 3672 | struct scsi_cmnd *scmd; |
| 3673 | u16 smid; |
| 3674 | u16 count = 0; |
| 3675 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3676 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 3677 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3678 | if (!scmd) |
| 3679 | continue; |
| 3680 | count++; |
| 3681 | mpt2sas_base_free_smid(ioc, smid); |
| 3682 | scsi_dma_unmap(scmd); |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3683 | if (ioc->pci_error_recovery) |
| 3684 | scmd->result = DID_NO_CONNECT << 16; |
| 3685 | else |
| 3686 | scmd->result = DID_RESET << 16; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3687 | scmd->scsi_done(scmd); |
| 3688 | } |
| 3689 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n", |
| 3690 | ioc->name, count)); |
| 3691 | } |
| 3692 | |
| 3693 | /** |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3694 | * _scsih_setup_eedp - setup MPI request for EEDP transfer |
| 3695 | * @scmd: pointer to scsi command object |
| 3696 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3697 | * |
| 3698 | * Supporting protection 1 and 3. |
| 3699 | * |
| 3700 | * Returns nothing |
| 3701 | */ |
| 3702 | static void |
| 3703 | _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request) |
| 3704 | { |
| 3705 | u16 eedp_flags; |
| 3706 | unsigned char prot_op = scsi_get_prot_op(scmd); |
| 3707 | unsigned char prot_type = scsi_get_prot_type(scmd); |
| 3708 | |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3709 | if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL) |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3710 | return; |
| 3711 | |
| 3712 | if (prot_op == SCSI_PROT_READ_STRIP) |
| 3713 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP; |
| 3714 | else if (prot_op == SCSI_PROT_WRITE_INSERT) |
| 3715 | eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP; |
| 3716 | else |
| 3717 | return; |
| 3718 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3719 | switch (prot_type) { |
| 3720 | case SCSI_PROT_DIF_TYPE1: |
Martin K. Petersen | 756aca7 | 2011-05-18 00:45:22 -0400 | [diff] [blame] | 3721 | case SCSI_PROT_DIF_TYPE2: |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3722 | |
| 3723 | /* |
| 3724 | * enable ref/guard checking |
| 3725 | * auto increment ref tag |
| 3726 | */ |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3727 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3728 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | |
| 3729 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
| 3730 | mpi_request->CDB.EEDP32.PrimaryReferenceTag = |
| 3731 | cpu_to_be32(scsi_get_lba(scmd)); |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3732 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3733 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3734 | case SCSI_PROT_DIF_TYPE3: |
| 3735 | |
| 3736 | /* |
| 3737 | * enable guard checking |
| 3738 | */ |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3739 | eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3740 | break; |
| 3741 | } |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 3742 | mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size); |
| 3743 | mpi_request->EEDPFlags = cpu_to_le16(eedp_flags); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 3744 | } |
| 3745 | |
| 3746 | /** |
| 3747 | * _scsih_eedp_error_handling - return sense code for EEDP errors |
| 3748 | * @scmd: pointer to scsi command object |
| 3749 | * @ioc_status: ioc status |
| 3750 | * |
| 3751 | * Returns nothing |
| 3752 | */ |
| 3753 | static void |
| 3754 | _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status) |
| 3755 | { |
| 3756 | u8 ascq; |
| 3757 | u8 sk; |
| 3758 | u8 host_byte; |
| 3759 | |
| 3760 | switch (ioc_status) { |
| 3761 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 3762 | ascq = 0x01; |
| 3763 | break; |
| 3764 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 3765 | ascq = 0x02; |
| 3766 | break; |
| 3767 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 3768 | ascq = 0x03; |
| 3769 | break; |
| 3770 | default: |
| 3771 | ascq = 0x00; |
| 3772 | break; |
| 3773 | } |
| 3774 | |
| 3775 | if (scmd->sc_data_direction == DMA_TO_DEVICE) { |
| 3776 | sk = ILLEGAL_REQUEST; |
| 3777 | host_byte = DID_ABORT; |
| 3778 | } else { |
| 3779 | sk = ABORTED_COMMAND; |
| 3780 | host_byte = DID_OK; |
| 3781 | } |
| 3782 | |
| 3783 | scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq); |
| 3784 | scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) | |
| 3785 | SAM_STAT_CHECK_CONDITION; |
| 3786 | } |
| 3787 | |
| 3788 | /** |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3789 | * _scsih_scsi_direct_io_get - returns direct io flag |
| 3790 | * @ioc: per adapter object |
| 3791 | * @smid: system request message index |
| 3792 | * |
| 3793 | * Returns the smid stored scmd pointer. |
| 3794 | */ |
| 3795 | static inline u8 |
| 3796 | _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 3797 | { |
| 3798 | return ioc->scsi_lookup[smid - 1].direct_io; |
| 3799 | } |
| 3800 | |
| 3801 | /** |
| 3802 | * _scsih_scsi_direct_io_set - sets direct io flag |
| 3803 | * @ioc: per adapter object |
| 3804 | * @smid: system request message index |
| 3805 | * @direct_io: Zero or non-zero value to set in the direct_io flag |
| 3806 | * |
| 3807 | * Returns Nothing. |
| 3808 | */ |
| 3809 | static inline void |
| 3810 | _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io) |
| 3811 | { |
| 3812 | ioc->scsi_lookup[smid - 1].direct_io = direct_io; |
| 3813 | } |
| 3814 | |
| 3815 | |
| 3816 | /** |
| 3817 | * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O |
| 3818 | * @ioc: per adapter object |
| 3819 | * @scmd: pointer to scsi command object |
| 3820 | * @raid_device: pointer to raid device data structure |
| 3821 | * @mpi_request: pointer to the SCSI_IO reqest message frame |
| 3822 | * @smid: system request message index |
| 3823 | * |
| 3824 | * Returns nothing |
| 3825 | */ |
| 3826 | static void |
| 3827 | _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 3828 | struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request, |
| 3829 | u16 smid) |
| 3830 | { |
| 3831 | u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size; |
| 3832 | u32 stripe_sz, stripe_exp; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3833 | u8 num_pds, *cdb_ptr, i; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3834 | u8 cdb0 = scmd->cmnd[0]; |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3835 | u64 v_llba; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3836 | |
| 3837 | /* |
| 3838 | * Try Direct I/O to RAID memeber disks |
| 3839 | */ |
| 3840 | if (cdb0 == READ_16 || cdb0 == READ_10 || |
| 3841 | cdb0 == WRITE_16 || cdb0 == WRITE_10) { |
| 3842 | cdb_ptr = mpi_request->CDB.CDB32; |
| 3843 | |
| 3844 | if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4] |
| 3845 | | cdb_ptr[5])) { |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3846 | io_size = scsi_bufflen(scmd) >> |
| 3847 | raid_device->block_exponent; |
| 3848 | i = (cdb0 < READ_16) ? 2 : 6; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3849 | /* get virtual lba */ |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3850 | v_lba = be32_to_cpu(*(__be32 *)(&cdb_ptr[i])); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3851 | |
| 3852 | if (((u64)v_lba + (u64)io_size - 1) <= |
| 3853 | (u32)raid_device->max_lba) { |
| 3854 | stripe_sz = raid_device->stripe_sz; |
| 3855 | stripe_exp = raid_device->stripe_exponent; |
| 3856 | stripe_off = v_lba & (stripe_sz - 1); |
| 3857 | |
| 3858 | /* Check whether IO falls within a stripe */ |
| 3859 | if ((stripe_off + io_size) <= stripe_sz) { |
| 3860 | num_pds = raid_device->num_pds; |
| 3861 | p_lba = v_lba >> stripe_exp; |
| 3862 | stripe_unit = p_lba / num_pds; |
| 3863 | column = p_lba % num_pds; |
| 3864 | p_lba = (stripe_unit << stripe_exp) + |
| 3865 | stripe_off; |
| 3866 | mpi_request->DevHandle = |
| 3867 | cpu_to_le16(raid_device-> |
| 3868 | pd_handle[column]); |
nagalakshmi.nandigama@lsi.com | ba96bd0 | 2011-12-01 07:51:55 +0530 | [diff] [blame] | 3869 | (*(__be32 *)(&cdb_ptr[i])) = |
| 3870 | cpu_to_be32(p_lba); |
| 3871 | /* |
| 3872 | * WD: To indicate this I/O is directI/O |
| 3873 | */ |
| 3874 | _scsih_scsi_direct_io_set(ioc, smid, 1); |
| 3875 | } |
| 3876 | } |
| 3877 | } else { |
| 3878 | io_size = scsi_bufflen(scmd) >> |
| 3879 | raid_device->block_exponent; |
| 3880 | /* get virtual lba */ |
| 3881 | v_llba = be64_to_cpu(*(__be64 *)(&cdb_ptr[2])); |
| 3882 | |
| 3883 | if ((v_llba + (u64)io_size - 1) <= |
| 3884 | raid_device->max_lba) { |
| 3885 | stripe_sz = raid_device->stripe_sz; |
| 3886 | stripe_exp = raid_device->stripe_exponent; |
| 3887 | stripe_off = (u32) (v_llba & (stripe_sz - 1)); |
| 3888 | |
| 3889 | /* Check whether IO falls within a stripe */ |
| 3890 | if ((stripe_off + io_size) <= stripe_sz) { |
| 3891 | num_pds = raid_device->num_pds; |
| 3892 | p_lba = (u32)(v_llba >> stripe_exp); |
| 3893 | stripe_unit = p_lba / num_pds; |
| 3894 | column = p_lba % num_pds; |
| 3895 | p_lba = (stripe_unit << stripe_exp) + |
| 3896 | stripe_off; |
| 3897 | mpi_request->DevHandle = |
| 3898 | cpu_to_le16(raid_device-> |
| 3899 | pd_handle[column]); |
| 3900 | (*(__be64 *)(&cdb_ptr[2])) = |
| 3901 | cpu_to_be64((u64)p_lba); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3902 | /* |
| 3903 | * WD: To indicate this I/O is directI/O |
| 3904 | */ |
| 3905 | _scsih_scsi_direct_io_set(ioc, smid, 1); |
| 3906 | } |
| 3907 | } |
| 3908 | } |
| 3909 | } |
| 3910 | } |
| 3911 | |
| 3912 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 3913 | * _scsih_qcmd - main scsi request entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3914 | * @scmd: pointer to scsi command object |
| 3915 | * @done: function pointer to be invoked on completion |
| 3916 | * |
| 3917 | * The callback index is set inside `ioc->scsi_io_cb_idx`. |
| 3918 | * |
| 3919 | * Returns 0 on success. If there's a failure, return either: |
| 3920 | * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or |
| 3921 | * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full |
| 3922 | */ |
| 3923 | static int |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 3924 | _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3925 | { |
| 3926 | struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host); |
| 3927 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 3928 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3929 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3930 | Mpi2SCSIIORequest_t *mpi_request; |
| 3931 | u32 mpi_control; |
| 3932 | u16 smid; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3933 | |
| 3934 | scmd->scsi_done = done; |
| 3935 | sas_device_priv_data = scmd->device->hostdata; |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3936 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3937 | scmd->result = DID_NO_CONNECT << 16; |
| 3938 | scmd->scsi_done(scmd); |
| 3939 | return 0; |
| 3940 | } |
| 3941 | |
Kashyap, Desai | 7821578 | 2011-06-14 10:57:08 +0530 | [diff] [blame] | 3942 | if (ioc->pci_error_recovery || ioc->remove_host) { |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 3943 | scmd->result = DID_NO_CONNECT << 16; |
| 3944 | scmd->scsi_done(scmd); |
| 3945 | return 0; |
| 3946 | } |
| 3947 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3948 | sas_target_priv_data = sas_device_priv_data->sas_target; |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3949 | /* invalid device handle */ |
| 3950 | if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3951 | scmd->result = DID_NO_CONNECT << 16; |
| 3952 | scmd->scsi_done(scmd); |
| 3953 | return 0; |
| 3954 | } |
| 3955 | |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3956 | /* host recovery or link resets sent via IOCTLs */ |
| 3957 | if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3958 | return SCSI_MLQUEUE_HOST_BUSY; |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 3959 | /* device busy with task management */ |
Kashyap, Desai | 130b958 | 2010-04-08 17:54:32 +0530 | [diff] [blame] | 3960 | else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy) |
| 3961 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 3962 | /* device has been deleted */ |
| 3963 | else if (sas_target_priv_data->deleted) { |
| 3964 | scmd->result = DID_NO_CONNECT << 16; |
| 3965 | scmd->scsi_done(scmd); |
| 3966 | return 0; |
| 3967 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3968 | |
| 3969 | if (scmd->sc_data_direction == DMA_FROM_DEVICE) |
| 3970 | mpi_control = MPI2_SCSIIO_CONTROL_READ; |
| 3971 | else if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 3972 | mpi_control = MPI2_SCSIIO_CONTROL_WRITE; |
| 3973 | else |
| 3974 | mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; |
| 3975 | |
| 3976 | /* set tags */ |
| 3977 | if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) { |
| 3978 | if (scmd->device->tagged_supported) { |
| 3979 | if (scmd->device->ordered_tags) |
| 3980 | mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ; |
| 3981 | else |
| 3982 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
| 3983 | } else |
| 3984 | /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */ |
| 3985 | /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED; |
| 3986 | */ |
| 3987 | mpi_control |= (0x500); |
| 3988 | |
| 3989 | } else |
| 3990 | mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 3991 | /* Make sure Device is not raid volume. |
| 3992 | * We do not expose raid functionality to upper layer for warpdrive. |
| 3993 | */ |
| 3994 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 3995 | sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3996 | mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; |
| 3997 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3998 | 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] | 3999 | if (!smid) { |
| 4000 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 4001 | ioc->name, __func__); |
| 4002 | goto out; |
| 4003 | } |
| 4004 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 4005 | memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t)); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4006 | _scsih_setup_eedp(scmd, mpi_request); |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 4007 | if (scmd->cmd_len == 32) |
| 4008 | mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4009 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 4010 | if (sas_device_priv_data->sas_target->flags & |
| 4011 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 4012 | mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; |
| 4013 | else |
| 4014 | mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 4015 | mpi_request->DevHandle = |
| 4016 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 4017 | mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
| 4018 | mpi_request->Control = cpu_to_le32(mpi_control); |
| 4019 | mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len); |
| 4020 | mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR; |
| 4021 | mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; |
| 4022 | mpi_request->SenseBufferLowAddress = |
Kashyap, Desai | ec9472c | 2009-09-23 17:34:13 +0530 | [diff] [blame] | 4023 | mpt2sas_base_get_sense_buffer_dma(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4024 | mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4; |
| 4025 | mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI + |
| 4026 | MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4027 | mpi_request->VF_ID = 0; /* TODO */ |
| 4028 | mpi_request->VP_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4029 | int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *) |
| 4030 | mpi_request->LUN); |
| 4031 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 4032 | |
| 4033 | if (!mpi_request->DataLength) { |
| 4034 | mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL); |
| 4035 | } else { |
| 4036 | if (_scsih_build_scatter_gather(ioc, scmd, smid)) { |
| 4037 | mpt2sas_base_free_smid(ioc, smid); |
| 4038 | goto out; |
| 4039 | } |
| 4040 | } |
| 4041 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4042 | raid_device = sas_target_priv_data->raid_device; |
| 4043 | if (raid_device && raid_device->direct_io_enabled) |
| 4044 | _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request, |
| 4045 | smid); |
| 4046 | |
Kashyap, Desai | 58287fd | 2010-03-17 16:27:25 +0530 | [diff] [blame] | 4047 | if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) |
| 4048 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4049 | le16_to_cpu(mpi_request->DevHandle)); |
Kashyap, Desai | 58287fd | 2010-03-17 16:27:25 +0530 | [diff] [blame] | 4050 | else |
| 4051 | mpt2sas_base_put_smid_default(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4052 | return 0; |
| 4053 | |
| 4054 | out: |
| 4055 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4056 | } |
| 4057 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 4058 | static DEF_SCSI_QCMD(_scsih_qcmd) |
| 4059 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4060 | /** |
| 4061 | * _scsih_normalize_sense - normalize descriptor and fixed format sense data |
| 4062 | * @sense_buffer: sense data returned by target |
| 4063 | * @data: normalized skey/asc/ascq |
| 4064 | * |
| 4065 | * Return nothing. |
| 4066 | */ |
| 4067 | static void |
| 4068 | _scsih_normalize_sense(char *sense_buffer, struct sense_info *data) |
| 4069 | { |
| 4070 | if ((sense_buffer[0] & 0x7F) >= 0x72) { |
| 4071 | /* descriptor format */ |
| 4072 | data->skey = sense_buffer[1] & 0x0F; |
| 4073 | data->asc = sense_buffer[2]; |
| 4074 | data->ascq = sense_buffer[3]; |
| 4075 | } else { |
| 4076 | /* fixed format */ |
| 4077 | data->skey = sense_buffer[2] & 0x0F; |
| 4078 | data->asc = sense_buffer[12]; |
| 4079 | data->ascq = sense_buffer[13]; |
| 4080 | } |
| 4081 | } |
| 4082 | |
| 4083 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4084 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4085 | * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4086 | * @ioc: per adapter object |
| 4087 | * @scmd: pointer to scsi command object |
| 4088 | * @mpi_reply: reply mf payload returned from firmware |
| 4089 | * |
| 4090 | * scsi_status - SCSI Status code returned from target device |
| 4091 | * scsi_state - state info associated with SCSI_IO determined by ioc |
| 4092 | * ioc_status - ioc supplied status info |
| 4093 | * |
| 4094 | * Return nothing. |
| 4095 | */ |
| 4096 | static void |
| 4097 | _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd, |
| 4098 | Mpi2SCSIIOReply_t *mpi_reply, u16 smid) |
| 4099 | { |
| 4100 | u32 response_info; |
| 4101 | u8 *response_bytes; |
| 4102 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & |
| 4103 | MPI2_IOCSTATUS_MASK; |
| 4104 | u8 scsi_state = mpi_reply->SCSIState; |
| 4105 | u8 scsi_status = mpi_reply->SCSIStatus; |
| 4106 | char *desc_ioc_state = NULL; |
| 4107 | char *desc_scsi_status = NULL; |
| 4108 | char *desc_scsi_state = ioc->tmp_string; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4109 | u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4110 | struct _sas_device *sas_device = NULL; |
| 4111 | unsigned long flags; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4112 | struct scsi_target *starget = scmd->device->sdev_target; |
| 4113 | struct MPT2SAS_TARGET *priv_target = starget->hostdata; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4114 | char *device_str = NULL; |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4115 | |
| 4116 | if (!priv_target) |
| 4117 | return; |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4118 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4119 | if (ioc->hide_ir_msg) |
| 4120 | device_str = "WarpDrive"; |
| 4121 | else |
| 4122 | device_str = "volume"; |
| 4123 | |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 4124 | if (log_info == 0x31170000) |
| 4125 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4126 | |
| 4127 | switch (ioc_status) { |
| 4128 | case MPI2_IOCSTATUS_SUCCESS: |
| 4129 | desc_ioc_state = "success"; |
| 4130 | break; |
| 4131 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 4132 | desc_ioc_state = "invalid function"; |
| 4133 | break; |
| 4134 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 4135 | desc_ioc_state = "scsi recovered error"; |
| 4136 | break; |
| 4137 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: |
| 4138 | desc_ioc_state = "scsi invalid dev handle"; |
| 4139 | break; |
| 4140 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 4141 | desc_ioc_state = "scsi device not there"; |
| 4142 | break; |
| 4143 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 4144 | desc_ioc_state = "scsi data overrun"; |
| 4145 | break; |
| 4146 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 4147 | desc_ioc_state = "scsi data underrun"; |
| 4148 | break; |
| 4149 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 4150 | desc_ioc_state = "scsi io data error"; |
| 4151 | break; |
| 4152 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 4153 | desc_ioc_state = "scsi protocol error"; |
| 4154 | break; |
| 4155 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 4156 | desc_ioc_state = "scsi task terminated"; |
| 4157 | break; |
| 4158 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 4159 | desc_ioc_state = "scsi residual mismatch"; |
| 4160 | break; |
| 4161 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 4162 | desc_ioc_state = "scsi task mgmt failed"; |
| 4163 | break; |
| 4164 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 4165 | desc_ioc_state = "scsi ioc terminated"; |
| 4166 | break; |
| 4167 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 4168 | desc_ioc_state = "scsi ext terminated"; |
| 4169 | break; |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4170 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 4171 | desc_ioc_state = "eedp guard error"; |
| 4172 | break; |
| 4173 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 4174 | desc_ioc_state = "eedp ref tag error"; |
| 4175 | break; |
| 4176 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 4177 | desc_ioc_state = "eedp app tag error"; |
| 4178 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4179 | default: |
| 4180 | desc_ioc_state = "unknown"; |
| 4181 | break; |
| 4182 | } |
| 4183 | |
| 4184 | switch (scsi_status) { |
| 4185 | case MPI2_SCSI_STATUS_GOOD: |
| 4186 | desc_scsi_status = "good"; |
| 4187 | break; |
| 4188 | case MPI2_SCSI_STATUS_CHECK_CONDITION: |
| 4189 | desc_scsi_status = "check condition"; |
| 4190 | break; |
| 4191 | case MPI2_SCSI_STATUS_CONDITION_MET: |
| 4192 | desc_scsi_status = "condition met"; |
| 4193 | break; |
| 4194 | case MPI2_SCSI_STATUS_BUSY: |
| 4195 | desc_scsi_status = "busy"; |
| 4196 | break; |
| 4197 | case MPI2_SCSI_STATUS_INTERMEDIATE: |
| 4198 | desc_scsi_status = "intermediate"; |
| 4199 | break; |
| 4200 | case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET: |
| 4201 | desc_scsi_status = "intermediate condmet"; |
| 4202 | break; |
| 4203 | case MPI2_SCSI_STATUS_RESERVATION_CONFLICT: |
| 4204 | desc_scsi_status = "reservation conflict"; |
| 4205 | break; |
| 4206 | case MPI2_SCSI_STATUS_COMMAND_TERMINATED: |
| 4207 | desc_scsi_status = "command terminated"; |
| 4208 | break; |
| 4209 | case MPI2_SCSI_STATUS_TASK_SET_FULL: |
| 4210 | desc_scsi_status = "task set full"; |
| 4211 | break; |
| 4212 | case MPI2_SCSI_STATUS_ACA_ACTIVE: |
| 4213 | desc_scsi_status = "aca active"; |
| 4214 | break; |
| 4215 | case MPI2_SCSI_STATUS_TASK_ABORTED: |
| 4216 | desc_scsi_status = "task aborted"; |
| 4217 | break; |
| 4218 | default: |
| 4219 | desc_scsi_status = "unknown"; |
| 4220 | break; |
| 4221 | } |
| 4222 | |
| 4223 | desc_scsi_state[0] = '\0'; |
| 4224 | if (!scsi_state) |
| 4225 | desc_scsi_state = " "; |
| 4226 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 4227 | strcat(desc_scsi_state, "response info "); |
| 4228 | if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4229 | strcat(desc_scsi_state, "state terminated "); |
| 4230 | if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS) |
| 4231 | strcat(desc_scsi_state, "no status "); |
| 4232 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED) |
| 4233 | strcat(desc_scsi_state, "autosense failed "); |
| 4234 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) |
| 4235 | strcat(desc_scsi_state, "autosense valid "); |
| 4236 | |
| 4237 | scsi_print_command(scmd); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4238 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4239 | if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4240 | printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name, |
| 4241 | device_str, (unsigned long long)priv_target->sas_address); |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4242 | } else { |
| 4243 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4244 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 4245 | priv_target->sas_address); |
| 4246 | if (sas_device) { |
| 4247 | printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), " |
| 4248 | "phy(%d)\n", ioc->name, sas_device->sas_address, |
| 4249 | sas_device->phy); |
| 4250 | printk(MPT2SAS_WARN_FMT |
| 4251 | "\tenclosure_logical_id(0x%016llx), slot(%d)\n", |
| 4252 | ioc->name, sas_device->enclosure_logical_id, |
| 4253 | sas_device->slot); |
| 4254 | } |
| 4255 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4256 | } |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 4257 | |
Kashyap, Desai | 8e864a8 | 2010-06-17 13:48:46 +0530 | [diff] [blame] | 4258 | printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), " |
| 4259 | "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle), |
| 4260 | desc_ioc_state, ioc_status, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4261 | printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), " |
| 4262 | "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow, |
| 4263 | scsi_get_resid(scmd)); |
| 4264 | printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), " |
| 4265 | "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag), |
| 4266 | le32_to_cpu(mpi_reply->TransferCount), scmd->result); |
| 4267 | printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), " |
| 4268 | "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status, |
| 4269 | scsi_status, desc_scsi_state, scsi_state); |
| 4270 | |
| 4271 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4272 | struct sense_info data; |
| 4273 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4274 | printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: " |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 4275 | "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey, |
| 4276 | data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4277 | } |
| 4278 | |
| 4279 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) { |
| 4280 | response_info = le32_to_cpu(mpi_reply->ResponseInfo); |
| 4281 | response_bytes = (u8 *)&response_info; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4282 | _scsih_response_code(ioc, response_bytes[0]); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4283 | } |
| 4284 | } |
| 4285 | #endif |
| 4286 | |
| 4287 | /** |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4288 | * _scsih_turn_on_fault_led - illuminate Fault LED |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4289 | * @ioc: per adapter object |
| 4290 | * @handle: device handle |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4291 | * Context: process |
| 4292 | * |
| 4293 | * Return nothing. |
| 4294 | */ |
| 4295 | static void |
| 4296 | _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4297 | { |
| 4298 | Mpi2SepReply_t mpi_reply; |
| 4299 | Mpi2SepRequest_t mpi_request; |
| 4300 | |
| 4301 | memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t)); |
| 4302 | mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; |
| 4303 | mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; |
| 4304 | mpi_request.SlotStatus = |
| 4305 | cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); |
| 4306 | mpi_request.DevHandle = cpu_to_le16(handle); |
| 4307 | mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS; |
| 4308 | if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply, |
| 4309 | &mpi_request)) != 0) { |
| 4310 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name, |
| 4311 | __FILE__, __LINE__, __func__); |
| 4312 | return; |
| 4313 | } |
| 4314 | |
| 4315 | if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) { |
| 4316 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: " |
| 4317 | "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name, |
| 4318 | le16_to_cpu(mpi_reply.IOCStatus), |
| 4319 | le32_to_cpu(mpi_reply.IOCLogInfo))); |
| 4320 | return; |
| 4321 | } |
| 4322 | } |
| 4323 | |
| 4324 | /** |
| 4325 | * _scsih_send_event_to_turn_on_fault_led - fire delayed event |
| 4326 | * @ioc: per adapter object |
| 4327 | * @handle: device handle |
| 4328 | * Context: interrupt. |
| 4329 | * |
| 4330 | * Return nothing. |
| 4331 | */ |
| 4332 | static void |
| 4333 | _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4334 | { |
| 4335 | struct fw_event_work *fw_event; |
| 4336 | |
| 4337 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 4338 | if (!fw_event) |
| 4339 | return; |
| 4340 | fw_event->event = MPT2SAS_TURN_ON_FAULT_LED; |
| 4341 | fw_event->device_handle = handle; |
| 4342 | fw_event->ioc = ioc; |
| 4343 | _scsih_fw_event_add(ioc, fw_event); |
| 4344 | } |
| 4345 | |
| 4346 | /** |
| 4347 | * _scsih_smart_predicted_fault - process smart errors |
| 4348 | * @ioc: per adapter object |
| 4349 | * @handle: device handle |
| 4350 | * Context: interrupt. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4351 | * |
| 4352 | * Return nothing. |
| 4353 | */ |
| 4354 | static void |
| 4355 | _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4356 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4357 | struct scsi_target *starget; |
| 4358 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 4359 | Mpi2EventNotificationReply_t *event_reply; |
| 4360 | Mpi2EventDataSasDeviceStatusChange_t *event_data; |
| 4361 | struct _sas_device *sas_device; |
| 4362 | ssize_t sz; |
| 4363 | unsigned long flags; |
| 4364 | |
| 4365 | /* only handle non-raid devices */ |
| 4366 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 4367 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 4368 | if (!sas_device) { |
| 4369 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4370 | return; |
| 4371 | } |
| 4372 | starget = sas_device->starget; |
| 4373 | sas_target_priv_data = starget->hostdata; |
| 4374 | |
| 4375 | if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) || |
| 4376 | ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) { |
| 4377 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4378 | return; |
| 4379 | } |
| 4380 | starget_printk(KERN_WARNING, starget, "predicted fault\n"); |
| 4381 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 4382 | |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 4383 | if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) |
| 4384 | _scsih_send_event_to_turn_on_fault_led(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4385 | |
| 4386 | /* insert into event log */ |
| 4387 | sz = offsetof(Mpi2EventNotificationReply_t, EventData) + |
| 4388 | sizeof(Mpi2EventDataSasDeviceStatusChange_t); |
Anton Blanchard | f6a290b4 | 2011-11-07 22:05:21 +1100 | [diff] [blame] | 4389 | event_reply = kzalloc(sz, GFP_ATOMIC); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4390 | if (!event_reply) { |
| 4391 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4392 | ioc->name, __FILE__, __LINE__, __func__); |
| 4393 | return; |
| 4394 | } |
| 4395 | |
| 4396 | event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; |
| 4397 | event_reply->Event = |
| 4398 | cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); |
| 4399 | event_reply->MsgLength = sz/4; |
| 4400 | event_reply->EventDataLength = |
| 4401 | cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4); |
| 4402 | event_data = (Mpi2EventDataSasDeviceStatusChange_t *) |
| 4403 | event_reply->EventData; |
| 4404 | event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA; |
| 4405 | event_data->ASC = 0x5D; |
| 4406 | event_data->DevHandle = cpu_to_le16(handle); |
| 4407 | event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address); |
| 4408 | mpt2sas_ctl_add_to_event_log(ioc, event_reply); |
| 4409 | kfree(event_reply); |
| 4410 | } |
| 4411 | |
| 4412 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 4413 | * _scsih_io_done - scsi request callback |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4414 | * @ioc: per adapter object |
| 4415 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4416 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4417 | * @reply: reply message frame(lower 32bit addr) |
| 4418 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4419 | * Callback handler when using _scsih_qcmd. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4420 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4421 | * Return 1 meaning mf should be freed from _base_interrupt |
| 4422 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4423 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4424 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 4425 | _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] | 4426 | { |
| 4427 | Mpi2SCSIIORequest_t *mpi_request; |
| 4428 | Mpi2SCSIIOReply_t *mpi_reply; |
| 4429 | struct scsi_cmnd *scmd; |
| 4430 | u16 ioc_status; |
| 4431 | u32 xfer_cnt; |
| 4432 | u8 scsi_state; |
| 4433 | u8 scsi_status; |
| 4434 | u32 log_info; |
| 4435 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4436 | u32 response_code = 0; |
Kashyap, Desai | 82a4525 | 2011-07-05 12:40:23 +0530 | [diff] [blame] | 4437 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4438 | |
| 4439 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 4440 | scmd = _scsih_scsi_lookup_get_clear(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4441 | if (scmd == NULL) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4442 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4443 | |
| 4444 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 4445 | |
| 4446 | if (mpi_reply == NULL) { |
| 4447 | scmd->result = DID_OK << 16; |
| 4448 | goto out; |
| 4449 | } |
| 4450 | |
| 4451 | sas_device_priv_data = scmd->device->hostdata; |
| 4452 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target || |
| 4453 | sas_device_priv_data->sas_target->deleted) { |
| 4454 | scmd->result = DID_NO_CONNECT << 16; |
| 4455 | goto out; |
| 4456 | } |
nagalakshmi.nandigama@lsi.com | 4da7af9 | 2011-12-01 07:53:02 +0530 | [diff] [blame] | 4457 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4458 | /* |
| 4459 | * WARPDRIVE: If direct_io is set then it is directIO, |
| 4460 | * the failed direct I/O should be redirected to volume |
| 4461 | */ |
nagalakshmi.nandigama@lsi.com | 4da7af9 | 2011-12-01 07:53:02 +0530 | [diff] [blame] | 4462 | if (_scsih_scsi_direct_io_get(ioc, smid) && |
| 4463 | ((ioc_status & MPI2_IOCSTATUS_MASK) |
| 4464 | != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) { |
Kashyap, Desai | 82a4525 | 2011-07-05 12:40:23 +0530 | [diff] [blame] | 4465 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 4466 | ioc->scsi_lookup[smid - 1].scmd = scmd; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4467 | _scsih_scsi_direct_io_set(ioc, smid, 0); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 4468 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4469 | memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len); |
| 4470 | mpi_request->DevHandle = |
| 4471 | cpu_to_le16(sas_device_priv_data->sas_target->handle); |
| 4472 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
| 4473 | sas_device_priv_data->sas_target->handle); |
| 4474 | return 0; |
| 4475 | } |
| 4476 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4477 | |
| 4478 | /* turning off TLR */ |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4479 | scsi_state = mpi_reply->SCSIState; |
| 4480 | if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) |
| 4481 | response_code = |
| 4482 | le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4483 | if (!sas_device_priv_data->tlr_snoop_check) { |
| 4484 | sas_device_priv_data->tlr_snoop_check++; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 4485 | /* Make sure Device is not raid volume. |
| 4486 | * We do not expose raid functionality to upper layer for warpdrive. |
| 4487 | */ |
| 4488 | if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) && |
Kashyap, Desai | 3ed2152 | 2010-02-17 16:08:36 +0530 | [diff] [blame] | 4489 | sas_is_tlr_enabled(scmd->device) && |
Kashyap, Desai | 84f0b04 | 2009-12-16 18:56:28 +0530 | [diff] [blame] | 4490 | response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) { |
| 4491 | sas_disable_tlr(scmd->device); |
| 4492 | sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n"); |
| 4493 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4494 | } |
| 4495 | |
| 4496 | xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); |
| 4497 | scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4498 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) |
| 4499 | log_info = le32_to_cpu(mpi_reply->IOCLogInfo); |
| 4500 | else |
| 4501 | log_info = 0; |
| 4502 | ioc_status &= MPI2_IOCSTATUS_MASK; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4503 | scsi_status = mpi_reply->SCSIStatus; |
| 4504 | |
| 4505 | if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && |
| 4506 | (scsi_status == MPI2_SCSI_STATUS_BUSY || |
| 4507 | scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT || |
| 4508 | scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) { |
| 4509 | ioc_status = MPI2_IOCSTATUS_SUCCESS; |
| 4510 | } |
| 4511 | |
| 4512 | if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 4513 | struct sense_info data; |
| 4514 | const void *sense_data = mpt2sas_base_get_sense_buffer(ioc, |
| 4515 | smid); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 4516 | u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4517 | le32_to_cpu(mpi_reply->SenseCount)); |
Eric Moore | 0d04df9 | 2009-04-21 15:38:43 -0600 | [diff] [blame] | 4518 | memcpy(scmd->sense_buffer, sense_data, sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4519 | _scsih_normalize_sense(scmd->sense_buffer, &data); |
| 4520 | /* failure prediction threshold exceeded */ |
| 4521 | if (data.asc == 0x5D) |
| 4522 | _scsih_smart_predicted_fault(ioc, |
| 4523 | le16_to_cpu(mpi_reply->DevHandle)); |
| 4524 | } |
| 4525 | |
| 4526 | switch (ioc_status) { |
| 4527 | case MPI2_IOCSTATUS_BUSY: |
| 4528 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: |
| 4529 | scmd->result = SAM_STAT_BUSY; |
| 4530 | break; |
| 4531 | |
| 4532 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 4533 | scmd->result = DID_NO_CONNECT << 16; |
| 4534 | break; |
| 4535 | |
| 4536 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 4537 | if (sas_device_priv_data->block) { |
Kashyap, Desai | e4e7c7e | 2009-09-23 17:33:14 +0530 | [diff] [blame] | 4538 | scmd->result = DID_TRANSPORT_DISRUPTED << 16; |
| 4539 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4540 | } |
nagalakshmi.nandigama@lsi.com | 3ade1ca | 2011-12-01 07:42:40 +0530 | [diff] [blame] | 4541 | scmd->result = DID_SOFT_ERROR << 16; |
| 4542 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4543 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 4544 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 4545 | scmd->result = DID_RESET << 16; |
| 4546 | break; |
| 4547 | |
| 4548 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 4549 | if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt)) |
| 4550 | scmd->result = DID_SOFT_ERROR << 16; |
| 4551 | else |
| 4552 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4553 | break; |
| 4554 | |
| 4555 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 4556 | scmd->result = (DID_OK << 16) | scsi_status; |
| 4557 | |
| 4558 | if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)) |
| 4559 | break; |
| 4560 | |
| 4561 | if (xfer_cnt < scmd->underflow) { |
| 4562 | if (scsi_status == SAM_STAT_BUSY) |
| 4563 | scmd->result = SAM_STAT_BUSY; |
| 4564 | else |
| 4565 | scmd->result = DID_SOFT_ERROR << 16; |
| 4566 | } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4567 | MPI2_SCSI_STATE_NO_SCSI_STATUS)) |
| 4568 | scmd->result = DID_SOFT_ERROR << 16; |
| 4569 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4570 | scmd->result = DID_RESET << 16; |
| 4571 | else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { |
| 4572 | mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; |
| 4573 | mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; |
| 4574 | scmd->result = (DRIVER_SENSE << 24) | |
| 4575 | SAM_STAT_CHECK_CONDITION; |
| 4576 | scmd->sense_buffer[0] = 0x70; |
| 4577 | scmd->sense_buffer[2] = ILLEGAL_REQUEST; |
| 4578 | scmd->sense_buffer[12] = 0x20; |
| 4579 | scmd->sense_buffer[13] = 0; |
| 4580 | } |
| 4581 | break; |
| 4582 | |
| 4583 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 4584 | scsi_set_resid(scmd, 0); |
| 4585 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 4586 | case MPI2_IOCSTATUS_SUCCESS: |
| 4587 | scmd->result = (DID_OK << 16) | scsi_status; |
Kashyap, Desai | 9982f59 | 2009-09-23 17:23:07 +0530 | [diff] [blame] | 4588 | if (response_code == |
| 4589 | MPI2_SCSITASKMGMT_RSP_INVALID_FRAME || |
| 4590 | (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED | |
| 4591 | MPI2_SCSI_STATE_NO_SCSI_STATUS))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4592 | scmd->result = DID_SOFT_ERROR << 16; |
| 4593 | else if (scsi_state & MPI2_SCSI_STATE_TERMINATED) |
| 4594 | scmd->result = DID_RESET << 16; |
| 4595 | break; |
| 4596 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 4597 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 4598 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 4599 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 4600 | _scsih_eedp_error_handling(scmd, ioc_status); |
| 4601 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4602 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 4603 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 4604 | case MPI2_IOCSTATUS_INVALID_SGL: |
| 4605 | case MPI2_IOCSTATUS_INTERNAL_ERROR: |
| 4606 | case MPI2_IOCSTATUS_INVALID_FIELD: |
| 4607 | case MPI2_IOCSTATUS_INVALID_STATE: |
| 4608 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 4609 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 4610 | default: |
| 4611 | scmd->result = DID_SOFT_ERROR << 16; |
| 4612 | break; |
| 4613 | |
| 4614 | } |
| 4615 | |
| 4616 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 4617 | if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY)) |
| 4618 | _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid); |
| 4619 | #endif |
| 4620 | |
| 4621 | out: |
| 4622 | scsi_dma_unmap(scmd); |
| 4623 | scmd->scsi_done(scmd); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 4624 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4628 | * _scsih_sas_host_refresh - refreshing sas host object contents |
| 4629 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4630 | * Context: user |
| 4631 | * |
| 4632 | * During port enable, fw will send topology events for every device. Its |
| 4633 | * possible that the handles may change from the previous setting, so this |
| 4634 | * code keeping handles updating if changed. |
| 4635 | * |
| 4636 | * Return nothing. |
| 4637 | */ |
| 4638 | static void |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4639 | _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4640 | { |
| 4641 | u16 sz; |
| 4642 | u16 ioc_status; |
| 4643 | int i; |
| 4644 | Mpi2ConfigReply_t mpi_reply; |
| 4645 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4646 | u16 attached_handle; |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4647 | u8 link_rate; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4648 | |
| 4649 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 4650 | "updating handles for sas_host(0x%016llx)\n", |
| 4651 | ioc->name, (unsigned long long)ioc->sas_hba.sas_address)); |
| 4652 | |
| 4653 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys |
| 4654 | * sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4655 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4656 | if (!sas_iounit_pg0) { |
| 4657 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4658 | ioc->name, __FILE__, __LINE__, __func__); |
| 4659 | return; |
| 4660 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4661 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4662 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4663 | sas_iounit_pg0, sz)) != 0) |
| 4664 | goto out; |
| 4665 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 4666 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 4667 | goto out; |
| 4668 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4669 | link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4670 | if (i == 0) |
| 4671 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4672 | PhyData[0].ControllerDevHandle); |
| 4673 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
| 4674 | attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. |
| 4675 | AttachedDevHandle); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4676 | if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 4677 | link_rate = MPI2_SAS_NEG_LINK_RATE_1_5; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4678 | mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address, |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 4679 | attached_handle, i, link_rate); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4680 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4681 | out: |
| 4682 | kfree(sas_iounit_pg0); |
| 4683 | } |
| 4684 | |
| 4685 | /** |
| 4686 | * _scsih_sas_host_add - create sas host object |
| 4687 | * @ioc: per adapter object |
| 4688 | * |
| 4689 | * Creating host side data object, stored in ioc->sas_hba |
| 4690 | * |
| 4691 | * Return nothing. |
| 4692 | */ |
| 4693 | static void |
| 4694 | _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc) |
| 4695 | { |
| 4696 | int i; |
| 4697 | Mpi2ConfigReply_t mpi_reply; |
| 4698 | Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL; |
| 4699 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; |
| 4700 | Mpi2SasPhyPage0_t phy_pg0; |
| 4701 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 4702 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4703 | u16 ioc_status; |
| 4704 | u16 sz; |
| 4705 | u16 device_missing_delay; |
| 4706 | |
| 4707 | mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys); |
| 4708 | if (!ioc->sas_hba.num_phys) { |
| 4709 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4710 | ioc->name, __FILE__, __LINE__, __func__); |
| 4711 | return; |
| 4712 | } |
| 4713 | |
| 4714 | /* sas_iounit page 0 */ |
| 4715 | sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4716 | sizeof(Mpi2SasIOUnit0PhyData_t)); |
| 4717 | sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL); |
| 4718 | if (!sas_iounit_pg0) { |
| 4719 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4720 | ioc->name, __FILE__, __LINE__, __func__); |
| 4721 | return; |
| 4722 | } |
| 4723 | if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply, |
| 4724 | sas_iounit_pg0, sz))) { |
| 4725 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4726 | ioc->name, __FILE__, __LINE__, __func__); |
| 4727 | goto out; |
| 4728 | } |
| 4729 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4730 | MPI2_IOCSTATUS_MASK; |
| 4731 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4732 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4733 | ioc->name, __FILE__, __LINE__, __func__); |
| 4734 | goto out; |
| 4735 | } |
| 4736 | |
| 4737 | /* sas_iounit page 1 */ |
| 4738 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys * |
| 4739 | sizeof(Mpi2SasIOUnit1PhyData_t)); |
| 4740 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); |
| 4741 | if (!sas_iounit_pg1) { |
| 4742 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4743 | ioc->name, __FILE__, __LINE__, __func__); |
| 4744 | goto out; |
| 4745 | } |
| 4746 | if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, |
| 4747 | sas_iounit_pg1, sz))) { |
| 4748 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4749 | ioc->name, __FILE__, __LINE__, __func__); |
| 4750 | goto out; |
| 4751 | } |
| 4752 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4753 | MPI2_IOCSTATUS_MASK; |
| 4754 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4755 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4756 | ioc->name, __FILE__, __LINE__, __func__); |
| 4757 | goto out; |
| 4758 | } |
| 4759 | |
| 4760 | ioc->io_missing_delay = |
| 4761 | le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay); |
| 4762 | device_missing_delay = |
| 4763 | le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay); |
| 4764 | if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) |
| 4765 | ioc->device_missing_delay = (device_missing_delay & |
| 4766 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; |
| 4767 | else |
| 4768 | ioc->device_missing_delay = device_missing_delay & |
| 4769 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 4770 | |
| 4771 | ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev; |
| 4772 | ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys, |
| 4773 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4774 | if (!ioc->sas_hba.phy) { |
| 4775 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4776 | ioc->name, __FILE__, __LINE__, __func__); |
| 4777 | goto out; |
| 4778 | } |
| 4779 | for (i = 0; i < ioc->sas_hba.num_phys ; i++) { |
| 4780 | if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0, |
| 4781 | i))) { |
| 4782 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4783 | ioc->name, __FILE__, __LINE__, __func__); |
| 4784 | goto out; |
| 4785 | } |
| 4786 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4787 | MPI2_IOCSTATUS_MASK; |
| 4788 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4789 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4790 | ioc->name, __FILE__, __LINE__, __func__); |
| 4791 | goto out; |
| 4792 | } |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4793 | |
| 4794 | if (i == 0) |
| 4795 | ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0-> |
| 4796 | PhyData[0].ControllerDevHandle); |
| 4797 | ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4798 | ioc->sas_hba.phy[i].phy_id = i; |
| 4799 | mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i], |
| 4800 | phy_pg0, ioc->sas_hba.parent_dev); |
| 4801 | } |
| 4802 | 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] | 4803 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4804 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4805 | ioc->name, __FILE__, __LINE__, __func__); |
| 4806 | goto out; |
| 4807 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4808 | ioc->sas_hba.enclosure_handle = |
| 4809 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 4810 | ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 4811 | printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), " |
| 4812 | "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle, |
| 4813 | (unsigned long long) ioc->sas_hba.sas_address, |
| 4814 | ioc->sas_hba.num_phys) ; |
| 4815 | |
| 4816 | if (ioc->sas_hba.enclosure_handle) { |
| 4817 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4818 | &enclosure_pg0, |
| 4819 | MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4820 | ioc->sas_hba.enclosure_handle))) { |
| 4821 | ioc->sas_hba.enclosure_logical_id = |
| 4822 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4823 | } |
| 4824 | } |
| 4825 | |
| 4826 | out: |
| 4827 | kfree(sas_iounit_pg1); |
| 4828 | kfree(sas_iounit_pg0); |
| 4829 | } |
| 4830 | |
| 4831 | /** |
| 4832 | * _scsih_expander_add - creating expander object |
| 4833 | * @ioc: per adapter object |
| 4834 | * @handle: expander handle |
| 4835 | * |
| 4836 | * Creating expander object, stored in ioc->sas_expander_list. |
| 4837 | * |
| 4838 | * Return 0 for success, else error. |
| 4839 | */ |
| 4840 | static int |
| 4841 | _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 4842 | { |
| 4843 | struct _sas_node *sas_expander; |
| 4844 | Mpi2ConfigReply_t mpi_reply; |
| 4845 | Mpi2ExpanderPage0_t expander_pg0; |
| 4846 | Mpi2ExpanderPage1_t expander_pg1; |
| 4847 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 4848 | u32 ioc_status; |
| 4849 | u16 parent_handle; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 4850 | u64 sas_address, sas_address_parent = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4851 | int i; |
| 4852 | unsigned long flags; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4853 | struct _sas_port *mpt2sas_port = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4854 | int rc = 0; |
| 4855 | |
| 4856 | if (!handle) |
| 4857 | return -1; |
| 4858 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 4859 | if (ioc->shost_recovery || ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 4860 | return -1; |
| 4861 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4862 | if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 4863 | MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) { |
| 4864 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4865 | ioc->name, __FILE__, __LINE__, __func__); |
| 4866 | return -1; |
| 4867 | } |
| 4868 | |
| 4869 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 4870 | MPI2_IOCSTATUS_MASK; |
| 4871 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4872 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4873 | ioc->name, __FILE__, __LINE__, __func__); |
| 4874 | return -1; |
| 4875 | } |
| 4876 | |
| 4877 | /* handle out of order topology events */ |
| 4878 | parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4879 | if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent) |
| 4880 | != 0) { |
| 4881 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4882 | ioc->name, __FILE__, __LINE__, __func__); |
| 4883 | return -1; |
| 4884 | } |
| 4885 | if (sas_address_parent != ioc->sas_hba.sas_address) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4886 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4887 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4888 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4889 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4890 | if (!sas_expander) { |
| 4891 | rc = _scsih_expander_add(ioc, parent_handle); |
| 4892 | if (rc != 0) |
| 4893 | return rc; |
| 4894 | } |
| 4895 | } |
| 4896 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4897 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 4898 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4899 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 4900 | sas_address); |
| 4901 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 4902 | |
| 4903 | if (sas_expander) |
| 4904 | return 0; |
| 4905 | |
| 4906 | sas_expander = kzalloc(sizeof(struct _sas_node), |
| 4907 | GFP_KERNEL); |
| 4908 | if (!sas_expander) { |
| 4909 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4910 | ioc->name, __FILE__, __LINE__, __func__); |
| 4911 | return -1; |
| 4912 | } |
| 4913 | |
| 4914 | sas_expander->handle = handle; |
| 4915 | sas_expander->num_phys = expander_pg0.NumPhys; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4916 | sas_expander->sas_address_parent = sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4917 | sas_expander->sas_address = sas_address; |
| 4918 | |
| 4919 | printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x)," |
| 4920 | " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4921 | handle, parent_handle, (unsigned long long) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4922 | sas_expander->sas_address, sas_expander->num_phys); |
| 4923 | |
| 4924 | if (!sas_expander->num_phys) |
| 4925 | goto out_fail; |
| 4926 | sas_expander->phy = kcalloc(sas_expander->num_phys, |
| 4927 | sizeof(struct _sas_phy), GFP_KERNEL); |
| 4928 | if (!sas_expander->phy) { |
| 4929 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4930 | ioc->name, __FILE__, __LINE__, __func__); |
| 4931 | rc = -1; |
| 4932 | goto out_fail; |
| 4933 | } |
| 4934 | |
| 4935 | INIT_LIST_HEAD(&sas_expander->sas_port_list); |
| 4936 | mpt2sas_port = mpt2sas_transport_port_add(ioc, handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4937 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4938 | if (!mpt2sas_port) { |
| 4939 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4940 | ioc->name, __FILE__, __LINE__, __func__); |
| 4941 | rc = -1; |
| 4942 | goto out_fail; |
| 4943 | } |
| 4944 | sas_expander->parent_dev = &mpt2sas_port->rphy->dev; |
| 4945 | |
| 4946 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 4947 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 4948 | &expander_pg1, i, handle))) { |
| 4949 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4950 | ioc->name, __FILE__, __LINE__, __func__); |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4951 | rc = -1; |
| 4952 | goto out_fail; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4953 | } |
| 4954 | sas_expander->phy[i].handle = handle; |
| 4955 | sas_expander->phy[i].phy_id = i; |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4956 | |
| 4957 | if ((mpt2sas_transport_add_expander_phy(ioc, |
| 4958 | &sas_expander->phy[i], expander_pg1, |
| 4959 | sas_expander->parent_dev))) { |
| 4960 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 4961 | ioc->name, __FILE__, __LINE__, __func__); |
| 4962 | rc = -1; |
| 4963 | goto out_fail; |
| 4964 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4965 | } |
| 4966 | |
| 4967 | if (sas_expander->enclosure_handle) { |
| 4968 | if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply, |
| 4969 | &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 4970 | sas_expander->enclosure_handle))) { |
| 4971 | sas_expander->enclosure_logical_id = |
| 4972 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
| 4973 | } |
| 4974 | } |
| 4975 | |
| 4976 | _scsih_expander_node_add(ioc, sas_expander); |
| 4977 | return 0; |
| 4978 | |
| 4979 | out_fail: |
| 4980 | |
Kashyap, Desai | 20f5895 | 2009-08-07 19:34:26 +0530 | [diff] [blame] | 4981 | if (mpt2sas_port) |
| 4982 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 4983 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 4984 | kfree(sas_expander); |
| 4985 | return rc; |
| 4986 | } |
| 4987 | |
| 4988 | /** |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 4989 | * _scsih_done - scsih callback handler. |
| 4990 | * @ioc: per adapter object |
| 4991 | * @smid: system request message index |
| 4992 | * @msix_index: MSIX table index supplied by the OS |
| 4993 | * @reply: reply message frame(lower 32bit addr) |
| 4994 | * |
| 4995 | * Callback handler when sending internal generated message frames. |
| 4996 | * The callback index passed is `ioc->scsih_cb_idx` |
| 4997 | * |
| 4998 | * Return 1 meaning mf should be freed from _base_interrupt |
| 4999 | * 0 means the mf is freed from this function. |
| 5000 | */ |
| 5001 | static u8 |
| 5002 | _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) |
| 5003 | { |
| 5004 | MPI2DefaultReply_t *mpi_reply; |
| 5005 | |
| 5006 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 5007 | if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED) |
| 5008 | return 1; |
| 5009 | if (ioc->scsih_cmds.smid != smid) |
| 5010 | return 1; |
| 5011 | ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE; |
| 5012 | if (mpi_reply) { |
| 5013 | memcpy(ioc->scsih_cmds.reply, mpi_reply, |
| 5014 | mpi_reply->MsgLength*4); |
| 5015 | ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 5016 | } |
| 5017 | ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING; |
| 5018 | complete(&ioc->scsih_cmds.done); |
| 5019 | return 1; |
| 5020 | } |
| 5021 | |
| 5022 | /** |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5023 | * mpt2sas_expander_remove - removing expander object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5024 | * @ioc: per adapter object |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5025 | * @sas_address: expander sas_address |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5026 | * |
| 5027 | * Return nothing. |
| 5028 | */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5029 | void |
| 5030 | mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5031 | { |
| 5032 | struct _sas_node *sas_expander; |
| 5033 | unsigned long flags; |
| 5034 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 5035 | if (ioc->shost_recovery) |
| 5036 | return; |
| 5037 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5038 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5039 | sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc, |
| 5040 | sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5041 | if (sas_expander) |
| 5042 | list_del(&sas_expander->list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5043 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5044 | if (sas_expander) |
| 5045 | _scsih_expander_node_remove(ioc, sas_expander); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5046 | } |
| 5047 | |
| 5048 | /** |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5049 | * _scsih_check_access_status - check access flags |
| 5050 | * @ioc: per adapter object |
| 5051 | * @sas_address: sas address |
| 5052 | * @handle: sas device handle |
| 5053 | * @access_flags: errors returned during discovery of the device |
| 5054 | * |
| 5055 | * Return 0 for success, else failure |
| 5056 | */ |
| 5057 | static u8 |
| 5058 | _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 5059 | u16 handle, u8 access_status) |
| 5060 | { |
| 5061 | u8 rc = 1; |
| 5062 | char *desc = NULL; |
| 5063 | |
| 5064 | switch (access_status) { |
| 5065 | case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS: |
| 5066 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION: |
| 5067 | rc = 0; |
| 5068 | break; |
| 5069 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED: |
| 5070 | desc = "sata capability failed"; |
| 5071 | break; |
| 5072 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT: |
| 5073 | desc = "sata affiliation conflict"; |
| 5074 | break; |
| 5075 | case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE: |
| 5076 | desc = "route not addressable"; |
| 5077 | break; |
| 5078 | case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE: |
| 5079 | desc = "smp error not addressable"; |
| 5080 | break; |
| 5081 | case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED: |
| 5082 | desc = "device blocked"; |
| 5083 | break; |
| 5084 | case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED: |
| 5085 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN: |
| 5086 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT: |
| 5087 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG: |
| 5088 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION: |
| 5089 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER: |
| 5090 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN: |
| 5091 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN: |
| 5092 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN: |
| 5093 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION: |
| 5094 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE: |
| 5095 | case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX: |
| 5096 | desc = "sata initialization failed"; |
| 5097 | break; |
| 5098 | default: |
| 5099 | desc = "unknown"; |
| 5100 | break; |
| 5101 | } |
| 5102 | |
| 5103 | if (!rc) |
| 5104 | return 0; |
| 5105 | |
| 5106 | printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), " |
| 5107 | "handle(0x%04x)\n", ioc->name, desc, |
| 5108 | (unsigned long long)sas_address, handle); |
| 5109 | return rc; |
| 5110 | } |
| 5111 | |
| 5112 | static void |
| 5113 | _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 5114 | { |
| 5115 | Mpi2ConfigReply_t mpi_reply; |
| 5116 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 5117 | struct _sas_device *sas_device; |
| 5118 | u32 ioc_status; |
| 5119 | unsigned long flags; |
| 5120 | u64 sas_address; |
| 5121 | struct scsi_target *starget; |
| 5122 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 5123 | u32 device_info; |
| 5124 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5125 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5126 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 5127 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) |
| 5128 | return; |
| 5129 | |
| 5130 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 5131 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 5132 | return; |
| 5133 | |
| 5134 | /* check if this is end device */ |
| 5135 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 5136 | if (!(_scsih_is_end_device(device_info))) |
| 5137 | return; |
| 5138 | |
| 5139 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5140 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 5141 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5142 | sas_address); |
| 5143 | |
| 5144 | if (!sas_device) { |
| 5145 | printk(MPT2SAS_ERR_FMT "device is not present " |
| 5146 | "handle(0x%04x), no sas_device!!!\n", ioc->name, handle); |
| 5147 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5148 | return; |
| 5149 | } |
| 5150 | |
| 5151 | if (unlikely(sas_device->handle != handle)) { |
| 5152 | starget = sas_device->starget; |
| 5153 | sas_target_priv_data = starget->hostdata; |
| 5154 | starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)" |
| 5155 | " to (0x%04x)!!!\n", sas_device->handle, handle); |
| 5156 | sas_target_priv_data->handle = handle; |
| 5157 | sas_device->handle = handle; |
| 5158 | } |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5159 | |
| 5160 | /* check if device is present */ |
| 5161 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 5162 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 5163 | printk(MPT2SAS_ERR_FMT "device is not present " |
| 5164 | "handle(0x%04x), flags!!!\n", ioc->name, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5165 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5166 | return; |
| 5167 | } |
| 5168 | |
| 5169 | /* check if there were any issues with discovery */ |
| 5170 | if (_scsih_check_access_status(ioc, sas_address, handle, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5171 | sas_device_pg0.AccessStatus)) { |
| 5172 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5173 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5174 | } |
| 5175 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5176 | _scsih_ublock_io_device(ioc, handle); |
| 5177 | |
| 5178 | } |
| 5179 | |
| 5180 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5181 | * _scsih_add_device - creating sas device object |
| 5182 | * @ioc: per adapter object |
| 5183 | * @handle: sas device handle |
| 5184 | * @phy_num: phy number end device attached to |
| 5185 | * @is_pd: is this hidden raid component |
| 5186 | * |
| 5187 | * Creating end device object, stored in ioc->sas_device_list. |
| 5188 | * |
| 5189 | * Returns 0 for success, non-zero for failure. |
| 5190 | */ |
| 5191 | static int |
| 5192 | _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd) |
| 5193 | { |
| 5194 | Mpi2ConfigReply_t mpi_reply; |
| 5195 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 5196 | Mpi2SasEnclosurePage0_t enclosure_pg0; |
| 5197 | struct _sas_device *sas_device; |
| 5198 | u32 ioc_status; |
| 5199 | __le64 sas_address; |
| 5200 | u32 device_info; |
| 5201 | unsigned long flags; |
| 5202 | |
| 5203 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 5204 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 5205 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5206 | ioc->name, __FILE__, __LINE__, __func__); |
| 5207 | return -1; |
| 5208 | } |
| 5209 | |
| 5210 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 5211 | MPI2_IOCSTATUS_MASK; |
| 5212 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5213 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5214 | ioc->name, __FILE__, __LINE__, __func__); |
| 5215 | return -1; |
| 5216 | } |
| 5217 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5218 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 5219 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5220 | /* check if device is present */ |
| 5221 | if (!(le16_to_cpu(sas_device_pg0.Flags) & |
| 5222 | MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) { |
| 5223 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5224 | ioc->name, __FILE__, __LINE__, __func__); |
| 5225 | printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n", |
| 5226 | ioc->name, le16_to_cpu(sas_device_pg0.Flags)); |
| 5227 | return -1; |
| 5228 | } |
| 5229 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5230 | /* check if there were any issues with discovery */ |
| 5231 | if (_scsih_check_access_status(ioc, sas_address, handle, |
| 5232 | sas_device_pg0.AccessStatus)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5233 | return -1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5234 | |
| 5235 | /* check if this is end device */ |
| 5236 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 5237 | if (!(_scsih_is_end_device(device_info))) { |
| 5238 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5239 | ioc->name, __FILE__, __LINE__, __func__); |
| 5240 | return -1; |
| 5241 | } |
| 5242 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5243 | |
| 5244 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5245 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5246 | sas_address); |
| 5247 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5248 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5249 | if (sas_device) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5250 | return 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5251 | |
| 5252 | sas_device = kzalloc(sizeof(struct _sas_device), |
| 5253 | GFP_KERNEL); |
| 5254 | if (!sas_device) { |
| 5255 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5256 | ioc->name, __FILE__, __LINE__, __func__); |
| 5257 | return -1; |
| 5258 | } |
| 5259 | |
| 5260 | sas_device->handle = handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5261 | if (_scsih_get_sas_address(ioc, le16_to_cpu |
| 5262 | (sas_device_pg0.ParentDevHandle), |
| 5263 | &sas_device->sas_address_parent) != 0) |
| 5264 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 5265 | ioc->name, __FILE__, __LINE__, __func__); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5266 | sas_device->enclosure_handle = |
| 5267 | le16_to_cpu(sas_device_pg0.EnclosureHandle); |
| 5268 | sas_device->slot = |
| 5269 | le16_to_cpu(sas_device_pg0.Slot); |
| 5270 | sas_device->device_info = device_info; |
| 5271 | sas_device->sas_address = sas_address; |
Kashyap, Desai | 7fbae67 | 2010-06-17 13:45:17 +0530 | [diff] [blame] | 5272 | sas_device->phy = sas_device_pg0.PhyNum; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5273 | |
| 5274 | /* get enclosure_logical_id */ |
Kashyap, Desai | 15052c9 | 2009-08-07 19:33:17 +0530 | [diff] [blame] | 5275 | if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0( |
| 5276 | ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, |
| 5277 | sas_device->enclosure_handle))) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5278 | sas_device->enclosure_logical_id = |
| 5279 | le64_to_cpu(enclosure_pg0.EnclosureLogicalID); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5280 | |
| 5281 | /* get device name */ |
| 5282 | sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); |
| 5283 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5284 | if (ioc->wait_for_discovery_to_complete) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5285 | _scsih_sas_device_init_add(ioc, sas_device); |
| 5286 | else |
| 5287 | _scsih_sas_device_add(ioc, sas_device); |
| 5288 | |
| 5289 | return 0; |
| 5290 | } |
| 5291 | |
| 5292 | /** |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5293 | * _scsih_remove_device - removing sas device object |
| 5294 | * @ioc: per adapter object |
| 5295 | * @sas_device_delete: the sas_device object |
| 5296 | * |
| 5297 | * Return nothing. |
| 5298 | */ |
| 5299 | static void |
| 5300 | _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, |
| 5301 | struct _sas_device *sas_device) |
| 5302 | { |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5303 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Kashyap, Desai | 34a03be | 2009-08-20 13:23:19 +0530 | [diff] [blame] | 5304 | |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5305 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: " |
| 5306 | "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^] | 5307 | sas_device->handle, (unsigned long long) |
| 5308 | sas_device->sas_address)); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5309 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5310 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 5311 | sas_target_priv_data = sas_device->starget->hostdata; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5312 | sas_target_priv_data->deleted = 1; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5313 | _scsih_ublock_io_device(ioc, sas_device->handle); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5314 | sas_target_priv_data->handle = |
| 5315 | MPT2SAS_INVALID_DEVICE_HANDLE; |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5316 | } |
| 5317 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 5318 | if (!ioc->hide_drives) |
| 5319 | mpt2sas_transport_port_remove(ioc, |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5320 | sas_device->sas_address, |
| 5321 | sas_device->sas_address_parent); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5322 | |
| 5323 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr" |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5324 | "(0x%016llx)\n", ioc->name, sas_device->handle, |
| 5325 | (unsigned long long) sas_device->sas_address); |
Kashyap, Desai | 1278b11 | 2010-03-09 17:34:13 +0530 | [diff] [blame] | 5326 | |
| 5327 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: " |
| 5328 | "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^] | 5329 | sas_device->handle, (unsigned long long) |
| 5330 | sas_device->sas_address)); |
| 5331 | kfree(sas_device); |
| 5332 | } |
| 5333 | /** |
| 5334 | * _scsih_device_remove_by_handle - removing device object by handle |
| 5335 | * @ioc: per adapter object |
| 5336 | * @handle: device handle |
| 5337 | * |
| 5338 | * Return nothing. |
| 5339 | */ |
| 5340 | static void |
| 5341 | _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
| 5342 | { |
| 5343 | struct _sas_device *sas_device; |
| 5344 | unsigned long flags; |
| 5345 | |
| 5346 | if (ioc->shost_recovery) |
| 5347 | return; |
| 5348 | |
| 5349 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5350 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 5351 | if (sas_device) |
| 5352 | list_del(&sas_device->list); |
| 5353 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 5354 | if (sas_device) |
| 5355 | _scsih_remove_device(ioc, sas_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5356 | } |
| 5357 | |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5358 | /** |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5359 | * mpt2sas_device_remove_by_sas_address - removing device object by sas address |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5360 | * @ioc: per adapter object |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5361 | * @sas_address: device sas_address |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5362 | * |
| 5363 | * Return nothing. |
| 5364 | */ |
| 5365 | void |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5366 | mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc, |
| 5367 | u64 sas_address) |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5368 | { |
| 5369 | struct _sas_device *sas_device; |
| 5370 | unsigned long flags; |
| 5371 | |
| 5372 | if (ioc->shost_recovery) |
| 5373 | return; |
| 5374 | |
| 5375 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5376 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5377 | sas_address); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5378 | if (sas_device) |
| 5379 | list_del(&sas_device->list); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5380 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5381 | if (sas_device) |
| 5382 | _scsih_remove_device(ioc, sas_device); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5383 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5384 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5385 | /** |
| 5386 | * _scsih_sas_topology_change_event_debug - debug for topology event |
| 5387 | * @ioc: per adapter object |
| 5388 | * @event_data: event data payload |
| 5389 | * Context: user. |
| 5390 | */ |
| 5391 | static void |
| 5392 | _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5393 | Mpi2EventDataSasTopologyChangeList_t *event_data) |
| 5394 | { |
| 5395 | int i; |
| 5396 | u16 handle; |
| 5397 | u16 reason_code; |
| 5398 | u8 phy_number; |
| 5399 | char *status_str = NULL; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5400 | u8 link_rate, prev_link_rate; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5401 | |
| 5402 | switch (event_data->ExpStatus) { |
| 5403 | case MPI2_EVENT_SAS_TOPO_ES_ADDED: |
| 5404 | status_str = "add"; |
| 5405 | break; |
| 5406 | case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING: |
| 5407 | status_str = "remove"; |
| 5408 | break; |
| 5409 | case MPI2_EVENT_SAS_TOPO_ES_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5410 | case 0: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5411 | status_str = "responding"; |
| 5412 | break; |
| 5413 | case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING: |
| 5414 | status_str = "remove delay"; |
| 5415 | break; |
| 5416 | default: |
| 5417 | status_str = "unknown status"; |
| 5418 | break; |
| 5419 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5420 | printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5421 | ioc->name, status_str); |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5422 | printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5423 | "start_phy(%02d), count(%d)\n", |
| 5424 | le16_to_cpu(event_data->ExpanderDevHandle), |
| 5425 | le16_to_cpu(event_data->EnclosureHandle), |
| 5426 | event_data->StartPhyNum, event_data->NumEntries); |
| 5427 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5428 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5429 | if (!handle) |
| 5430 | continue; |
| 5431 | phy_number = event_data->StartPhyNum + i; |
| 5432 | reason_code = event_data->PHY[i].PhyStatus & |
| 5433 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5434 | switch (reason_code) { |
| 5435 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5436 | status_str = "target add"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5437 | break; |
| 5438 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5439 | status_str = "target remove"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5440 | break; |
| 5441 | case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5442 | status_str = "delay target remove"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5443 | break; |
| 5444 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5445 | status_str = "link rate change"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5446 | break; |
| 5447 | case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5448 | status_str = "target responding"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5449 | break; |
| 5450 | default: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5451 | status_str = "unknown"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5452 | break; |
| 5453 | } |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5454 | link_rate = event_data->PHY[i].LinkRate >> 4; |
| 5455 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5456 | printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:" |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5457 | " link rate: new(0x%02x), old(0x%02x)\n", phy_number, |
| 5458 | handle, status_str, link_rate, prev_link_rate); |
| 5459 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5460 | } |
| 5461 | } |
| 5462 | #endif |
| 5463 | |
| 5464 | /** |
| 5465 | * _scsih_sas_topology_change_event - handle topology changes |
| 5466 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5467 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5468 | * Context: user. |
| 5469 | * |
| 5470 | */ |
| 5471 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5472 | _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5473 | struct fw_event_work *fw_event) |
| 5474 | { |
| 5475 | int i; |
| 5476 | u16 parent_handle, handle; |
| 5477 | u16 reason_code; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5478 | u8 phy_number, max_phys; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5479 | struct _sas_node *sas_expander; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5480 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5481 | unsigned long flags; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5482 | u8 link_rate, prev_link_rate; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5483 | Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5484 | |
| 5485 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5486 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5487 | _scsih_sas_topology_change_event_debug(ioc, event_data); |
| 5488 | #endif |
| 5489 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5490 | if (ioc->remove_host || ioc->pci_error_recovery) |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5491 | return; |
| 5492 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5493 | if (!ioc->sas_hba.num_phys) |
| 5494 | _scsih_sas_host_add(ioc); |
| 5495 | else |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5496 | _scsih_sas_host_refresh(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5497 | |
| 5498 | if (fw_event->ignore) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5499 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5500 | "event\n", ioc->name)); |
| 5501 | return; |
| 5502 | } |
| 5503 | |
| 5504 | parent_handle = le16_to_cpu(event_data->ExpanderDevHandle); |
| 5505 | |
| 5506 | /* handle expander add */ |
| 5507 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED) |
| 5508 | if (_scsih_expander_add(ioc, parent_handle) != 0) |
| 5509 | return; |
| 5510 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5511 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 5512 | sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, |
| 5513 | parent_handle); |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5514 | if (sas_expander) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5515 | sas_address = sas_expander->sas_address; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5516 | max_phys = sas_expander->num_phys; |
| 5517 | } else if (parent_handle < ioc->sas_hba.num_phys) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5518 | sas_address = ioc->sas_hba.sas_address; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5519 | max_phys = ioc->sas_hba.num_phys; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5520 | } else { |
| 5521 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5522 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5523 | } |
| 5524 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5525 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5526 | /* handle siblings events */ |
| 5527 | for (i = 0; i < event_data->NumEntries; i++) { |
| 5528 | if (fw_event->ignore) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5529 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5530 | "expander event\n", ioc->name)); |
| 5531 | return; |
| 5532 | } |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 5533 | if (ioc->shost_recovery || ioc->remove_host || |
| 5534 | ioc->pci_error_recovery) |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 5535 | return; |
Kashyap, Desai | 308609c | 2009-09-14 11:07:23 +0530 | [diff] [blame] | 5536 | phy_number = event_data->StartPhyNum + i; |
Kashyap, Desai | b41c09d | 2010-11-13 04:40:51 +0530 | [diff] [blame] | 5537 | if (phy_number >= max_phys) |
| 5538 | continue; |
Kashyap, Desai | 308609c | 2009-09-14 11:07:23 +0530 | [diff] [blame] | 5539 | reason_code = event_data->PHY[i].PhyStatus & |
| 5540 | MPI2_EVENT_SAS_TOPO_RC_MASK; |
| 5541 | if ((event_data->PHY[i].PhyStatus & |
| 5542 | MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code != |
| 5543 | MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5544 | continue; |
| 5545 | handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle); |
| 5546 | if (!handle) |
| 5547 | continue; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5548 | link_rate = event_data->PHY[i].LinkRate >> 4; |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5549 | prev_link_rate = event_data->PHY[i].LinkRate & 0xF; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5550 | switch (reason_code) { |
| 5551 | case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5552 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5553 | if (ioc->shost_recovery) |
| 5554 | break; |
| 5555 | |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5556 | if (link_rate == prev_link_rate) |
| 5557 | break; |
| 5558 | |
| 5559 | mpt2sas_transport_update_links(ioc, sas_address, |
| 5560 | handle, phy_number, link_rate); |
| 5561 | |
Kashyap, Desai | b434427 | 2010-03-17 16:24:14 +0530 | [diff] [blame] | 5562 | if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5) |
| 5563 | break; |
| 5564 | |
| 5565 | _scsih_check_device(ioc, handle); |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5566 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5567 | case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5568 | |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 5569 | if (ioc->shost_recovery) |
| 5570 | break; |
| 5571 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5572 | mpt2sas_transport_update_links(ioc, sas_address, |
| 5573 | handle, phy_number, link_rate); |
| 5574 | |
Kashyap, Desai | e7d59c1 | 2009-09-23 17:36:52 +0530 | [diff] [blame] | 5575 | _scsih_add_device(ioc, handle, phy_number, 0); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5576 | break; |
| 5577 | case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING: |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5578 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5579 | _scsih_device_remove_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5580 | break; |
| 5581 | } |
| 5582 | } |
| 5583 | |
| 5584 | /* handle expander removal */ |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 5585 | if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING && |
| 5586 | sas_expander) |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 5587 | mpt2sas_expander_remove(ioc, sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5588 | |
| 5589 | } |
| 5590 | |
| 5591 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5592 | /** |
| 5593 | * _scsih_sas_device_status_change_event_debug - debug for device event |
| 5594 | * @event_data: event data payload |
| 5595 | * Context: user. |
| 5596 | * |
| 5597 | * Return nothing. |
| 5598 | */ |
| 5599 | static void |
| 5600 | _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5601 | Mpi2EventDataSasDeviceStatusChange_t *event_data) |
| 5602 | { |
| 5603 | char *reason_str = NULL; |
| 5604 | |
| 5605 | switch (event_data->ReasonCode) { |
| 5606 | case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA: |
| 5607 | reason_str = "smart data"; |
| 5608 | break; |
| 5609 | case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: |
| 5610 | reason_str = "unsupported device discovered"; |
| 5611 | break; |
| 5612 | case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: |
| 5613 | reason_str = "internal device reset"; |
| 5614 | break; |
| 5615 | case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: |
| 5616 | reason_str = "internal task abort"; |
| 5617 | break; |
| 5618 | case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: |
| 5619 | reason_str = "internal task abort set"; |
| 5620 | break; |
| 5621 | case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: |
| 5622 | reason_str = "internal clear task set"; |
| 5623 | break; |
| 5624 | case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: |
| 5625 | reason_str = "internal query task"; |
| 5626 | break; |
| 5627 | case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE: |
| 5628 | reason_str = "sata init failure"; |
| 5629 | break; |
| 5630 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET: |
| 5631 | reason_str = "internal device reset complete"; |
| 5632 | break; |
| 5633 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL: |
| 5634 | reason_str = "internal task abort complete"; |
| 5635 | break; |
| 5636 | case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION: |
| 5637 | reason_str = "internal async notification"; |
| 5638 | break; |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 5639 | case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5640 | reason_str = "expander reduced functionality"; |
| 5641 | break; |
| 5642 | case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY: |
| 5643 | reason_str = "expander reduced functionality complete"; |
| 5644 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5645 | default: |
| 5646 | reason_str = "unknown reason"; |
| 5647 | break; |
| 5648 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5649 | printk(MPT2SAS_INFO_FMT "device status change: (%s)\n" |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5650 | "\thandle(0x%04x), sas address(0x%016llx), tag(%d)", |
| 5651 | ioc->name, reason_str, le16_to_cpu(event_data->DevHandle), |
| 5652 | (unsigned long long)le64_to_cpu(event_data->SASAddress), |
| 5653 | le16_to_cpu(event_data->TaskTag)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5654 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA) |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5655 | 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] | 5656 | event_data->ASC, event_data->ASCQ); |
| 5657 | printk(KERN_INFO "\n"); |
| 5658 | } |
| 5659 | #endif |
| 5660 | |
| 5661 | /** |
| 5662 | * _scsih_sas_device_status_change_event - handle device status change |
| 5663 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5664 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5665 | * Context: user. |
| 5666 | * |
| 5667 | * Return nothing. |
| 5668 | */ |
| 5669 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5670 | _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 5671 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5672 | { |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5673 | struct MPT2SAS_TARGET *target_priv_data; |
| 5674 | struct _sas_device *sas_device; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 5675 | u64 sas_address; |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5676 | unsigned long flags; |
| 5677 | Mpi2EventDataSasDeviceStatusChange_t *event_data = |
| 5678 | fw_event->event_data; |
| 5679 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5680 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5681 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5682 | _scsih_sas_device_status_change_event_debug(ioc, |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5683 | event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5684 | #endif |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5685 | |
Kashyap, Desai | efe82a1 | 2011-01-04 11:34:17 +0530 | [diff] [blame] | 5686 | /* In MPI Revision K (0xC), the internal device reset complete was |
| 5687 | * implemented, so avoid setting tm_busy flag for older firmware. |
| 5688 | */ |
| 5689 | if ((ioc->facts.HeaderVersion >> 8) < 0xC) |
| 5690 | return; |
| 5691 | |
Kashyap, Desai | f891dcf | 2010-03-17 16:22:21 +0530 | [diff] [blame] | 5692 | if (event_data->ReasonCode != |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5693 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && |
Kashyap, Desai | f891dcf | 2010-03-17 16:22:21 +0530 | [diff] [blame] | 5694 | event_data->ReasonCode != |
| 5695 | MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET) |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5696 | return; |
| 5697 | |
| 5698 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 5699 | sas_address = le64_to_cpu(event_data->SASAddress); |
| 5700 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 5701 | sas_address); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5702 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5703 | if (!sas_device || !sas_device->starget) { |
| 5704 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5705 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5706 | } |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5707 | |
| 5708 | target_priv_data = sas_device->starget->hostdata; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5709 | if (!target_priv_data) { |
| 5710 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5711 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5712 | } |
Kashyap, Desai | 8ffc457 | 2009-09-23 17:35:41 +0530 | [diff] [blame] | 5713 | |
| 5714 | if (event_data->ReasonCode == |
| 5715 | MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET) |
| 5716 | target_priv_data->tm_busy = 1; |
| 5717 | else |
| 5718 | target_priv_data->tm_busy = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 5719 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5720 | } |
| 5721 | |
| 5722 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5723 | /** |
| 5724 | * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event |
| 5725 | * @ioc: per adapter object |
| 5726 | * @event_data: event data payload |
| 5727 | * Context: user. |
| 5728 | * |
| 5729 | * Return nothing. |
| 5730 | */ |
| 5731 | static void |
| 5732 | _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 5733 | Mpi2EventDataSasEnclDevStatusChange_t *event_data) |
| 5734 | { |
| 5735 | char *reason_str = NULL; |
| 5736 | |
| 5737 | switch (event_data->ReasonCode) { |
| 5738 | case MPI2_EVENT_SAS_ENCL_RC_ADDED: |
| 5739 | reason_str = "enclosure add"; |
| 5740 | break; |
| 5741 | case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING: |
| 5742 | reason_str = "enclosure remove"; |
| 5743 | break; |
| 5744 | default: |
| 5745 | reason_str = "unknown reason"; |
| 5746 | break; |
| 5747 | } |
| 5748 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5749 | printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n" |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5750 | "\thandle(0x%04x), enclosure logical id(0x%016llx)" |
| 5751 | " number slots(%d)\n", ioc->name, reason_str, |
| 5752 | le16_to_cpu(event_data->EnclosureHandle), |
| 5753 | (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID), |
| 5754 | le16_to_cpu(event_data->StartSlot)); |
| 5755 | } |
| 5756 | #endif |
| 5757 | |
| 5758 | /** |
| 5759 | * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events |
| 5760 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5761 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5762 | * Context: user. |
| 5763 | * |
| 5764 | * Return nothing. |
| 5765 | */ |
| 5766 | static void |
| 5767 | _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5768 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5769 | { |
| 5770 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5771 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 5772 | _scsih_sas_enclosure_dev_status_change_event_debug(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5773 | fw_event->event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5774 | #endif |
| 5775 | } |
| 5776 | |
| 5777 | /** |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 5778 | * _scsih_sas_broadcast_primitive_event - handle broadcast events |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5779 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5780 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5781 | * Context: user. |
| 5782 | * |
| 5783 | * Return nothing. |
| 5784 | */ |
| 5785 | static void |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 5786 | _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5787 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5788 | { |
| 5789 | struct scsi_cmnd *scmd; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5790 | struct scsi_device *sdev; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5791 | u16 smid, handle; |
| 5792 | u32 lun; |
| 5793 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 5794 | u32 termination_count; |
| 5795 | u32 query_count; |
| 5796 | Mpi2SCSITaskManagementReply_t *mpi_reply; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5797 | Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data; |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 5798 | u16 ioc_status; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5799 | unsigned long flags; |
| 5800 | int r; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5801 | u8 max_retries = 0; |
| 5802 | u8 task_abort_retries; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5803 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5804 | mutex_lock(&ioc->tm_cmds.mutex); |
| 5805 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: phy number(%d), " |
| 5806 | "width(%d)\n", ioc->name, __func__, event_data->PhyNum, |
| 5807 | event_data->PortWidth)); |
| 5808 | |
| 5809 | _scsih_block_io_all_device(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5810 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5811 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5812 | mpi_reply = ioc->tm_cmds.reply; |
| 5813 | broadcast_aen_retry: |
| 5814 | |
| 5815 | /* sanity checks for retrying this loop */ |
| 5816 | if (max_retries++ == 5) { |
| 5817 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n", |
| 5818 | ioc->name, __func__)); |
| 5819 | goto out; |
| 5820 | } else if (max_retries > 1) |
| 5821 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n", |
| 5822 | ioc->name, __func__, max_retries - 1)); |
| 5823 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5824 | termination_count = 0; |
| 5825 | query_count = 0; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 5826 | for (smid = 1; smid <= ioc->scsiio_depth; smid++) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5827 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5828 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5829 | scmd = _scsih_scsi_lookup_get(ioc, smid); |
| 5830 | if (!scmd) |
| 5831 | continue; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5832 | sdev = scmd->device; |
| 5833 | sas_device_priv_data = sdev->hostdata; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5834 | if (!sas_device_priv_data || !sas_device_priv_data->sas_target) |
| 5835 | continue; |
| 5836 | /* skip hidden raid components */ |
| 5837 | if (sas_device_priv_data->sas_target->flags & |
| 5838 | MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 5839 | continue; |
| 5840 | /* skip volumes */ |
| 5841 | if (sas_device_priv_data->sas_target->flags & |
| 5842 | MPT_TARGET_FLAGS_VOLUME) |
| 5843 | continue; |
| 5844 | |
| 5845 | handle = sas_device_priv_data->sas_target->handle; |
| 5846 | lun = sas_device_priv_data->lun; |
| 5847 | query_count++; |
| 5848 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5849 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5850 | goto out; |
| 5851 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5852 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5853 | r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun, |
| 5854 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0, |
| 5855 | TM_MUTEX_OFF); |
| 5856 | if (r == FAILED) { |
| 5857 | sdev_printk(KERN_WARNING, sdev, |
| 5858 | "mpt2sas_scsih_issue_tm: FAILED when sending " |
| 5859 | "QUERY_TASK: scmd(%p)\n", scmd); |
| 5860 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5861 | goto broadcast_aen_retry; |
| 5862 | } |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 5863 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) |
| 5864 | & MPI2_IOCSTATUS_MASK; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5865 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5866 | sdev_printk(KERN_WARNING, sdev, "query task: FAILED " |
| 5867 | "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status, |
| 5868 | scmd); |
| 5869 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5870 | goto broadcast_aen_retry; |
| 5871 | } |
| 5872 | |
| 5873 | /* see if IO is still owned by IOC and target */ |
| 5874 | if (mpi_reply->ResponseCode == |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5875 | MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED || |
| 5876 | mpi_reply->ResponseCode == |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5877 | MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) { |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5878 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5879 | continue; |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5880 | } |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5881 | task_abort_retries = 0; |
| 5882 | tm_retry: |
| 5883 | if (task_abort_retries++ == 60) { |
| 5884 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 5885 | "%s: ABORT_TASK: giving up\n", ioc->name, |
| 5886 | __func__)); |
| 5887 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5888 | goto broadcast_aen_retry; |
| 5889 | } |
| 5890 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5891 | if (ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5892 | goto out_no_lock; |
| 5893 | |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5894 | r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, |
| 5895 | sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5896 | scmd->serial_number, TM_MUTEX_OFF); |
| 5897 | if (r == FAILED) { |
| 5898 | sdev_printk(KERN_WARNING, sdev, |
| 5899 | "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : " |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5900 | "scmd(%p)\n", scmd); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5901 | goto tm_retry; |
| 5902 | } |
| 5903 | |
| 5904 | if (task_abort_retries > 1) |
| 5905 | sdev_printk(KERN_WARNING, sdev, |
| 5906 | "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):" |
| 5907 | " scmd(%p)\n", |
| 5908 | task_abort_retries - 1, scmd); |
| 5909 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5910 | termination_count += le32_to_cpu(mpi_reply->TerminationCount); |
Kashyap, Desai | ec07a05 | 2011-01-05 17:54:32 +0530 | [diff] [blame] | 5911 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5912 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5913 | |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5914 | if (ioc->broadcast_aen_pending) { |
| 5915 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to" |
| 5916 | " pending AEN\n", ioc->name, __func__)); |
| 5917 | ioc->broadcast_aen_pending = 0; |
| 5918 | goto broadcast_aen_retry; |
| 5919 | } |
| 5920 | |
| 5921 | out: |
| 5922 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 5923 | out_no_lock: |
| 5924 | |
| 5925 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5926 | "%s - exit, query_count = %d termination_count = %d\n", |
| 5927 | ioc->name, __func__, query_count, termination_count)); |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5928 | |
| 5929 | ioc->broadcast_aen_busy = 0; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 5930 | if (!ioc->shost_recovery) |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 5931 | _scsih_ublock_io_all_device(ioc); |
| 5932 | mutex_unlock(&ioc->tm_cmds.mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5933 | } |
| 5934 | |
| 5935 | /** |
| 5936 | * _scsih_sas_discovery_event - handle discovery events |
| 5937 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5938 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5939 | * Context: user. |
| 5940 | * |
| 5941 | * Return nothing. |
| 5942 | */ |
| 5943 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5944 | _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc, |
| 5945 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5946 | { |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 5947 | Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data; |
| 5948 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5949 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 5950 | if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) { |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 5951 | printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5952 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? |
| 5953 | "start" : "stop"); |
| 5954 | if (event_data->DiscoveryStatus) |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 5955 | printk("discovery_status(0x%08x)", |
| 5956 | le32_to_cpu(event_data->DiscoveryStatus)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5957 | printk("\n"); |
| 5958 | } |
| 5959 | #endif |
| 5960 | |
| 5961 | if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED && |
| 5962 | !ioc->sas_hba.num_phys) |
| 5963 | _scsih_sas_host_add(ioc); |
| 5964 | } |
| 5965 | |
| 5966 | /** |
| 5967 | * _scsih_reprobe_lun - reprobing lun |
| 5968 | * @sdev: scsi device struct |
| 5969 | * @no_uld_attach: sdev->no_uld_attach flag setting |
| 5970 | * |
| 5971 | **/ |
| 5972 | static void |
| 5973 | _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach) |
| 5974 | { |
| 5975 | int rc; |
| 5976 | |
| 5977 | sdev->no_uld_attach = no_uld_attach ? 1 : 0; |
| 5978 | sdev_printk(KERN_INFO, sdev, "%s raid component\n", |
| 5979 | sdev->no_uld_attach ? "hidding" : "exposing"); |
| 5980 | rc = scsi_device_reprobe(sdev); |
| 5981 | } |
| 5982 | |
| 5983 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 5984 | * _scsih_sas_volume_add - add new volume |
| 5985 | * @ioc: per adapter object |
| 5986 | * @element: IR config element data |
| 5987 | * Context: user. |
| 5988 | * |
| 5989 | * Return nothing. |
| 5990 | */ |
| 5991 | static void |
| 5992 | _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc, |
| 5993 | Mpi2EventIrConfigElement_t *element) |
| 5994 | { |
| 5995 | struct _raid_device *raid_device; |
| 5996 | unsigned long flags; |
| 5997 | u64 wwid; |
| 5998 | u16 handle = le16_to_cpu(element->VolDevHandle); |
| 5999 | int rc; |
| 6000 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6001 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 6002 | if (!wwid) { |
| 6003 | printk(MPT2SAS_ERR_FMT |
| 6004 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6005 | __FILE__, __LINE__, __func__); |
| 6006 | return; |
| 6007 | } |
| 6008 | |
| 6009 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6010 | raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid); |
| 6011 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6012 | |
| 6013 | if (raid_device) |
| 6014 | return; |
| 6015 | |
| 6016 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 6017 | if (!raid_device) { |
| 6018 | printk(MPT2SAS_ERR_FMT |
| 6019 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6020 | __FILE__, __LINE__, __func__); |
| 6021 | return; |
| 6022 | } |
| 6023 | |
| 6024 | raid_device->id = ioc->sas_id++; |
| 6025 | raid_device->channel = RAID_CHANNEL; |
| 6026 | raid_device->handle = handle; |
| 6027 | raid_device->wwid = wwid; |
| 6028 | _scsih_raid_device_add(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6029 | if (!ioc->wait_for_discovery_to_complete) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6030 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 6031 | raid_device->id, 0); |
| 6032 | if (rc) |
| 6033 | _scsih_raid_device_remove(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6034 | } else { |
| 6035 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6036 | _scsih_determine_boot_device(ioc, raid_device, 1); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6037 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6038 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6039 | } |
| 6040 | |
| 6041 | /** |
| 6042 | * _scsih_sas_volume_delete - delete volume |
| 6043 | * @ioc: per adapter object |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6044 | * @handle: volume device handle |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6045 | * Context: user. |
| 6046 | * |
| 6047 | * Return nothing. |
| 6048 | */ |
| 6049 | static void |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6050 | _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6051 | { |
| 6052 | struct _raid_device *raid_device; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6053 | unsigned long flags; |
| 6054 | struct MPT2SAS_TARGET *sas_target_priv_data; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6055 | struct scsi_target *starget = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6056 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6057 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6058 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6059 | if (raid_device) { |
| 6060 | if (raid_device->starget) { |
| 6061 | starget = raid_device->starget; |
| 6062 | sas_target_priv_data = starget->hostdata; |
| 6063 | sas_target_priv_data->deleted = 1; |
| 6064 | } |
| 6065 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" |
| 6066 | "(0x%016llx)\n", ioc->name, raid_device->handle, |
| 6067 | (unsigned long long) raid_device->wwid); |
| 6068 | list_del(&raid_device->list); |
| 6069 | kfree(raid_device); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6070 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6071 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6072 | if (starget) |
| 6073 | scsi_remove_target(&starget->dev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6074 | } |
| 6075 | |
| 6076 | /** |
| 6077 | * _scsih_sas_pd_expose - expose pd component to /dev/sdX |
| 6078 | * @ioc: per adapter object |
| 6079 | * @element: IR config element data |
| 6080 | * Context: user. |
| 6081 | * |
| 6082 | * Return nothing. |
| 6083 | */ |
| 6084 | static void |
| 6085 | _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc, |
| 6086 | Mpi2EventIrConfigElement_t *element) |
| 6087 | { |
| 6088 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6089 | struct scsi_target *starget = NULL; |
| 6090 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6091 | unsigned long flags; |
| 6092 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 6093 | |
| 6094 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6095 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6096 | if (sas_device) { |
| 6097 | sas_device->volume_handle = 0; |
| 6098 | sas_device->volume_wwid = 0; |
| 6099 | clear_bit(handle, ioc->pd_handles); |
| 6100 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 6101 | starget = sas_device->starget; |
| 6102 | sas_target_priv_data = starget->hostdata; |
| 6103 | sas_target_priv_data->flags &= |
| 6104 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 6105 | } |
| 6106 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6107 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6108 | if (!sas_device) |
| 6109 | return; |
| 6110 | |
| 6111 | /* exposing raid component */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6112 | if (starget) |
| 6113 | starget_for_each_device(starget, NULL, _scsih_reprobe_lun); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6114 | } |
| 6115 | |
| 6116 | /** |
| 6117 | * _scsih_sas_pd_hide - hide pd component from /dev/sdX |
| 6118 | * @ioc: per adapter object |
| 6119 | * @element: IR config element data |
| 6120 | * Context: user. |
| 6121 | * |
| 6122 | * Return nothing. |
| 6123 | */ |
| 6124 | static void |
| 6125 | _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc, |
| 6126 | Mpi2EventIrConfigElement_t *element) |
| 6127 | { |
| 6128 | struct _sas_device *sas_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6129 | struct scsi_target *starget = NULL; |
| 6130 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6131 | unsigned long flags; |
| 6132 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6133 | u16 volume_handle = 0; |
| 6134 | u64 volume_wwid = 0; |
| 6135 | |
| 6136 | mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle); |
| 6137 | if (volume_handle) |
| 6138 | mpt2sas_config_get_volume_wwid(ioc, volume_handle, |
| 6139 | &volume_wwid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6140 | |
| 6141 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6142 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6143 | if (sas_device) { |
| 6144 | set_bit(handle, ioc->pd_handles); |
| 6145 | if (sas_device->starget && sas_device->starget->hostdata) { |
| 6146 | starget = sas_device->starget; |
| 6147 | sas_target_priv_data = starget->hostdata; |
| 6148 | sas_target_priv_data->flags |= |
| 6149 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 6150 | sas_device->volume_handle = volume_handle; |
| 6151 | sas_device->volume_wwid = volume_wwid; |
| 6152 | } |
| 6153 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6154 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6155 | if (!sas_device) |
| 6156 | return; |
| 6157 | |
| 6158 | /* hiding raid component */ |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6159 | if (starget) |
| 6160 | starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6161 | } |
| 6162 | |
| 6163 | /** |
| 6164 | * _scsih_sas_pd_delete - delete pd component |
| 6165 | * @ioc: per adapter object |
| 6166 | * @element: IR config element data |
| 6167 | * Context: user. |
| 6168 | * |
| 6169 | * Return nothing. |
| 6170 | */ |
| 6171 | static void |
| 6172 | _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc, |
| 6173 | Mpi2EventIrConfigElement_t *element) |
| 6174 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6175 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
| 6176 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6177 | _scsih_device_remove_by_handle(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6178 | } |
| 6179 | |
| 6180 | /** |
| 6181 | * _scsih_sas_pd_add - remove pd component |
| 6182 | * @ioc: per adapter object |
| 6183 | * @element: IR config element data |
| 6184 | * Context: user. |
| 6185 | * |
| 6186 | * Return nothing. |
| 6187 | */ |
| 6188 | static void |
| 6189 | _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc, |
| 6190 | Mpi2EventIrConfigElement_t *element) |
| 6191 | { |
| 6192 | struct _sas_device *sas_device; |
| 6193 | unsigned long flags; |
| 6194 | u16 handle = le16_to_cpu(element->PhysDiskDevHandle); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6195 | Mpi2ConfigReply_t mpi_reply; |
| 6196 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6197 | u32 ioc_status; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6198 | u64 sas_address; |
| 6199 | u16 parent_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6200 | |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6201 | set_bit(handle, ioc->pd_handles); |
| 6202 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6203 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6204 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6205 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6206 | if (sas_device) |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6207 | return; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6208 | |
| 6209 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, |
| 6210 | MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { |
| 6211 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6212 | ioc->name, __FILE__, __LINE__, __func__); |
| 6213 | return; |
| 6214 | } |
| 6215 | |
| 6216 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6217 | MPI2_IOCSTATUS_MASK; |
| 6218 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6219 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6220 | ioc->name, __FILE__, __LINE__, __func__); |
| 6221 | return; |
| 6222 | } |
| 6223 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6224 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6225 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 6226 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 6227 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6228 | |
| 6229 | _scsih_add_device(ioc, handle, 0, 1); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6230 | } |
| 6231 | |
| 6232 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 6233 | /** |
| 6234 | * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events |
| 6235 | * @ioc: per adapter object |
| 6236 | * @event_data: event data payload |
| 6237 | * Context: user. |
| 6238 | * |
| 6239 | * Return nothing. |
| 6240 | */ |
| 6241 | static void |
| 6242 | _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 6243 | Mpi2EventDataIrConfigChangeList_t *event_data) |
| 6244 | { |
| 6245 | Mpi2EventIrConfigElement_t *element; |
| 6246 | u8 element_type; |
| 6247 | int i; |
| 6248 | char *reason_str = NULL, *element_str = NULL; |
| 6249 | |
| 6250 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 6251 | |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6252 | printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n", |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6253 | ioc->name, (le32_to_cpu(event_data->Flags) & |
| 6254 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? |
| 6255 | "foreign" : "native", event_data->NumElements); |
| 6256 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6257 | switch (element->ReasonCode) { |
| 6258 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
| 6259 | reason_str = "add"; |
| 6260 | break; |
| 6261 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
| 6262 | reason_str = "remove"; |
| 6263 | break; |
| 6264 | case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE: |
| 6265 | reason_str = "no change"; |
| 6266 | break; |
| 6267 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
| 6268 | reason_str = "hide"; |
| 6269 | break; |
| 6270 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
| 6271 | reason_str = "unhide"; |
| 6272 | break; |
| 6273 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 6274 | reason_str = "volume_created"; |
| 6275 | break; |
| 6276 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 6277 | reason_str = "volume_deleted"; |
| 6278 | break; |
| 6279 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
| 6280 | reason_str = "pd_created"; |
| 6281 | break; |
| 6282 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
| 6283 | reason_str = "pd_deleted"; |
| 6284 | break; |
| 6285 | default: |
| 6286 | reason_str = "unknown reason"; |
| 6287 | break; |
| 6288 | } |
| 6289 | element_type = le16_to_cpu(element->ElementFlags) & |
| 6290 | MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK; |
| 6291 | switch (element_type) { |
| 6292 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT: |
| 6293 | element_str = "volume"; |
| 6294 | break; |
| 6295 | case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT: |
| 6296 | element_str = "phys disk"; |
| 6297 | break; |
| 6298 | case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT: |
| 6299 | element_str = "hot spare"; |
| 6300 | break; |
| 6301 | default: |
| 6302 | element_str = "unknown element"; |
| 6303 | break; |
| 6304 | } |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 6305 | printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), " |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6306 | "pd handle(0x%04x), pd num(0x%02x)\n", element_str, |
| 6307 | reason_str, le16_to_cpu(element->VolDevHandle), |
| 6308 | le16_to_cpu(element->PhysDiskDevHandle), |
| 6309 | element->PhysDiskNum); |
| 6310 | } |
| 6311 | } |
| 6312 | #endif |
| 6313 | |
| 6314 | /** |
| 6315 | * _scsih_sas_ir_config_change_event - handle ir configuration change events |
| 6316 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6317 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6318 | * Context: user. |
| 6319 | * |
| 6320 | * Return nothing. |
| 6321 | */ |
| 6322 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6323 | _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc, |
| 6324 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6325 | { |
| 6326 | Mpi2EventIrConfigElement_t *element; |
| 6327 | int i; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6328 | u8 foreign_config; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6329 | Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6330 | |
| 6331 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6332 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6333 | && !ioc->hide_ir_msg) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6334 | _scsih_sas_ir_config_change_event_debug(ioc, event_data); |
| 6335 | |
| 6336 | #endif |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6337 | |
| 6338 | if (ioc->shost_recovery) |
| 6339 | return; |
| 6340 | |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6341 | foreign_config = (le32_to_cpu(event_data->Flags) & |
| 6342 | MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6343 | |
| 6344 | element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0]; |
| 6345 | for (i = 0; i < event_data->NumElements; i++, element++) { |
| 6346 | |
| 6347 | switch (element->ReasonCode) { |
| 6348 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED: |
| 6349 | case MPI2_EVENT_IR_CHANGE_RC_ADDED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6350 | if (!foreign_config) |
| 6351 | _scsih_sas_volume_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6352 | break; |
| 6353 | case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED: |
| 6354 | case MPI2_EVENT_IR_CHANGE_RC_REMOVED: |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6355 | if (!foreign_config) |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6356 | _scsih_sas_volume_delete(ioc, |
| 6357 | le16_to_cpu(element->VolDevHandle)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6358 | break; |
| 6359 | case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6360 | if (!ioc->is_warpdrive) |
| 6361 | _scsih_sas_pd_hide(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6362 | break; |
| 6363 | case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6364 | if (!ioc->is_warpdrive) |
| 6365 | _scsih_sas_pd_expose(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6366 | break; |
| 6367 | case MPI2_EVENT_IR_CHANGE_RC_HIDE: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6368 | if (!ioc->is_warpdrive) |
| 6369 | _scsih_sas_pd_add(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6370 | break; |
| 6371 | case MPI2_EVENT_IR_CHANGE_RC_UNHIDE: |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6372 | if (!ioc->is_warpdrive) |
| 6373 | _scsih_sas_pd_delete(ioc, element); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6374 | break; |
| 6375 | } |
| 6376 | } |
| 6377 | } |
| 6378 | |
| 6379 | /** |
| 6380 | * _scsih_sas_ir_volume_event - IR volume event |
| 6381 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6382 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6383 | * Context: user. |
| 6384 | * |
| 6385 | * Return nothing. |
| 6386 | */ |
| 6387 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6388 | _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc, |
| 6389 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6390 | { |
| 6391 | u64 wwid; |
| 6392 | unsigned long flags; |
| 6393 | struct _raid_device *raid_device; |
| 6394 | u16 handle; |
| 6395 | u32 state; |
| 6396 | int rc; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6397 | Mpi2EventDataIrVolume_t *event_data = fw_event->event_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6398 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6399 | if (ioc->shost_recovery) |
| 6400 | return; |
| 6401 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6402 | if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) |
| 6403 | return; |
| 6404 | |
| 6405 | handle = le16_to_cpu(event_data->VolDevHandle); |
| 6406 | state = le32_to_cpu(event_data->NewValue); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6407 | if (!ioc->hide_ir_msg) |
| 6408 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " |
| 6409 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 6410 | le32_to_cpu(event_data->PreviousValue), state)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6411 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6412 | switch (state) { |
| 6413 | case MPI2_RAID_VOL_STATE_MISSING: |
| 6414 | case MPI2_RAID_VOL_STATE_FAILED: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6415 | _scsih_sas_volume_delete(ioc, handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6416 | break; |
| 6417 | |
| 6418 | case MPI2_RAID_VOL_STATE_ONLINE: |
| 6419 | case MPI2_RAID_VOL_STATE_DEGRADED: |
| 6420 | case MPI2_RAID_VOL_STATE_OPTIMAL: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6421 | |
| 6422 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6423 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
| 6424 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6425 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6426 | if (raid_device) |
| 6427 | break; |
| 6428 | |
| 6429 | mpt2sas_config_get_volume_wwid(ioc, handle, &wwid); |
| 6430 | if (!wwid) { |
| 6431 | printk(MPT2SAS_ERR_FMT |
| 6432 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6433 | __FILE__, __LINE__, __func__); |
| 6434 | break; |
| 6435 | } |
| 6436 | |
| 6437 | raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL); |
| 6438 | if (!raid_device) { |
| 6439 | printk(MPT2SAS_ERR_FMT |
| 6440 | "failure at %s:%d/%s()!\n", ioc->name, |
| 6441 | __FILE__, __LINE__, __func__); |
| 6442 | break; |
| 6443 | } |
| 6444 | |
| 6445 | raid_device->id = ioc->sas_id++; |
| 6446 | raid_device->channel = RAID_CHANNEL; |
| 6447 | raid_device->handle = handle; |
| 6448 | raid_device->wwid = wwid; |
| 6449 | _scsih_raid_device_add(ioc, raid_device); |
| 6450 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 6451 | raid_device->id, 0); |
| 6452 | if (rc) |
| 6453 | _scsih_raid_device_remove(ioc, raid_device); |
| 6454 | break; |
| 6455 | |
| 6456 | case MPI2_RAID_VOL_STATE_INITIALIZING: |
| 6457 | default: |
| 6458 | break; |
| 6459 | } |
| 6460 | } |
| 6461 | |
| 6462 | /** |
| 6463 | * _scsih_sas_ir_physical_disk_event - PD event |
| 6464 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6465 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6466 | * Context: user. |
| 6467 | * |
| 6468 | * Return nothing. |
| 6469 | */ |
| 6470 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6471 | _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc, |
| 6472 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6473 | { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6474 | u16 handle, parent_handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6475 | u32 state; |
| 6476 | struct _sas_device *sas_device; |
| 6477 | unsigned long flags; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6478 | Mpi2ConfigReply_t mpi_reply; |
| 6479 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6480 | u32 ioc_status; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6481 | Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6482 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6483 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6484 | if (ioc->shost_recovery) |
| 6485 | return; |
| 6486 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6487 | if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) |
| 6488 | return; |
| 6489 | |
| 6490 | handle = le16_to_cpu(event_data->PhysDiskDevHandle); |
| 6491 | state = le32_to_cpu(event_data->NewValue); |
| 6492 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6493 | if (!ioc->hide_ir_msg) |
| 6494 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), " |
| 6495 | "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle, |
| 6496 | le32_to_cpu(event_data->PreviousValue), state)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6497 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6498 | switch (state) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6499 | case MPI2_RAID_PD_STATE_ONLINE: |
| 6500 | case MPI2_RAID_PD_STATE_DEGRADED: |
| 6501 | case MPI2_RAID_PD_STATE_REBUILDING: |
| 6502 | case MPI2_RAID_PD_STATE_OPTIMAL: |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6503 | case MPI2_RAID_PD_STATE_HOT_SPARE: |
| 6504 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6505 | if (!ioc->is_warpdrive) |
| 6506 | set_bit(handle, ioc->pd_handles); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6507 | |
| 6508 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6509 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
| 6510 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6511 | |
| 6512 | if (sas_device) |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6513 | return; |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6514 | |
| 6515 | if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6516 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 6517 | handle))) { |
| 6518 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6519 | ioc->name, __FILE__, __LINE__, __func__); |
| 6520 | return; |
| 6521 | } |
| 6522 | |
| 6523 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6524 | MPI2_IOCSTATUS_MASK; |
| 6525 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 6526 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 6527 | ioc->name, __FILE__, __LINE__, __func__); |
| 6528 | return; |
| 6529 | } |
| 6530 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6531 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 6532 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) |
| 6533 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 6534 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6535 | |
| 6536 | _scsih_add_device(ioc, handle, 0, 1); |
| 6537 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6538 | break; |
| 6539 | |
Kashyap, Desai | 62727a7 | 2009-08-07 19:35:18 +0530 | [diff] [blame] | 6540 | case MPI2_RAID_PD_STATE_OFFLINE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6541 | case MPI2_RAID_PD_STATE_NOT_CONFIGURED: |
| 6542 | case MPI2_RAID_PD_STATE_NOT_COMPATIBLE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6543 | default: |
| 6544 | break; |
| 6545 | } |
| 6546 | } |
| 6547 | |
| 6548 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 6549 | /** |
| 6550 | * _scsih_sas_ir_operation_status_event_debug - debug for IR op event |
| 6551 | * @ioc: per adapter object |
| 6552 | * @event_data: event data payload |
| 6553 | * Context: user. |
| 6554 | * |
| 6555 | * Return nothing. |
| 6556 | */ |
| 6557 | static void |
| 6558 | _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc, |
| 6559 | Mpi2EventDataIrOperationStatus_t *event_data) |
| 6560 | { |
| 6561 | char *reason_str = NULL; |
| 6562 | |
| 6563 | switch (event_data->RAIDOperation) { |
| 6564 | case MPI2_EVENT_IR_RAIDOP_RESYNC: |
| 6565 | reason_str = "resync"; |
| 6566 | break; |
| 6567 | case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION: |
| 6568 | reason_str = "online capacity expansion"; |
| 6569 | break; |
| 6570 | case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK: |
| 6571 | reason_str = "consistency check"; |
| 6572 | break; |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 6573 | case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT: |
| 6574 | reason_str = "background init"; |
| 6575 | break; |
| 6576 | case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT: |
| 6577 | reason_str = "make data consistent"; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6578 | break; |
| 6579 | } |
| 6580 | |
Kashyap, Desai | ec6c2b4 | 2009-09-23 17:31:01 +0530 | [diff] [blame] | 6581 | if (!reason_str) |
| 6582 | return; |
| 6583 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6584 | printk(MPT2SAS_INFO_FMT "raid operational status: (%s)" |
| 6585 | "\thandle(0x%04x), percent complete(%d)\n", |
| 6586 | ioc->name, reason_str, |
| 6587 | le16_to_cpu(event_data->VolDevHandle), |
| 6588 | event_data->PercentComplete); |
| 6589 | } |
| 6590 | #endif |
| 6591 | |
| 6592 | /** |
| 6593 | * _scsih_sas_ir_operation_status_event - handle RAID operation events |
| 6594 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6595 | * @fw_event: The fw_event_work object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6596 | * Context: user. |
| 6597 | * |
| 6598 | * Return nothing. |
| 6599 | */ |
| 6600 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6601 | _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc, |
| 6602 | struct fw_event_work *fw_event) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6603 | { |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6604 | Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data; |
| 6605 | static struct _raid_device *raid_device; |
| 6606 | unsigned long flags; |
| 6607 | u16 handle; |
| 6608 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6609 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6610 | if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) |
| 6611 | && !ioc->hide_ir_msg) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 6612 | _scsih_sas_ir_operation_status_event_debug(ioc, |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6613 | event_data); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6614 | #endif |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6615 | |
| 6616 | /* code added for raid transport support */ |
| 6617 | if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) { |
| 6618 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6619 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6620 | handle = le16_to_cpu(event_data->VolDevHandle); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6621 | raid_device = _scsih_raid_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6622 | if (raid_device) |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6623 | raid_device->percent_complete = |
| 6624 | event_data->PercentComplete; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6625 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 6626 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6627 | } |
| 6628 | |
| 6629 | /** |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6630 | * _scsih_prep_device_scan - initialize parameters prior to device scan |
| 6631 | * @ioc: per adapter object |
| 6632 | * |
| 6633 | * Set the deleted flag prior to device scan. If the device is found during |
| 6634 | * the scan, then we clear the deleted flag. |
| 6635 | */ |
| 6636 | static void |
| 6637 | _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc) |
| 6638 | { |
| 6639 | struct MPT2SAS_DEVICE *sas_device_priv_data; |
| 6640 | struct scsi_device *sdev; |
| 6641 | |
| 6642 | shost_for_each_device(sdev, ioc->shost) { |
| 6643 | sas_device_priv_data = sdev->hostdata; |
| 6644 | if (sas_device_priv_data && sas_device_priv_data->sas_target) |
| 6645 | sas_device_priv_data->sas_target->deleted = 1; |
| 6646 | } |
| 6647 | } |
| 6648 | |
| 6649 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6650 | * _scsih_mark_responding_sas_device - mark a sas_devices as responding |
| 6651 | * @ioc: per adapter object |
| 6652 | * @sas_address: sas address |
| 6653 | * @slot: enclosure slot id |
| 6654 | * @handle: device handle |
| 6655 | * |
| 6656 | * After host reset, find out whether devices are still responding. |
| 6657 | * Used in _scsi_remove_unresponsive_sas_devices. |
| 6658 | * |
| 6659 | * Return nothing. |
| 6660 | */ |
| 6661 | static void |
| 6662 | _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 6663 | u16 slot, u16 handle) |
| 6664 | { |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6665 | struct MPT2SAS_TARGET *sas_target_priv_data = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6666 | struct scsi_target *starget; |
| 6667 | struct _sas_device *sas_device; |
| 6668 | unsigned long flags; |
| 6669 | |
| 6670 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 6671 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { |
| 6672 | if (sas_device->sas_address == sas_address && |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6673 | sas_device->slot == slot) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6674 | sas_device->responding = 1; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 6675 | starget = sas_device->starget; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6676 | if (starget && starget->hostdata) { |
| 6677 | sas_target_priv_data = starget->hostdata; |
| 6678 | sas_target_priv_data->tm_busy = 0; |
| 6679 | sas_target_priv_data->deleted = 0; |
| 6680 | } else |
| 6681 | sas_target_priv_data = NULL; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6682 | if (starget) |
| 6683 | starget_printk(KERN_INFO, starget, |
| 6684 | "handle(0x%04x), sas_addr(0x%016llx), " |
| 6685 | "enclosure logical id(0x%016llx), " |
| 6686 | "slot(%d)\n", handle, |
| 6687 | (unsigned long long)sas_device->sas_address, |
| 6688 | (unsigned long long) |
| 6689 | sas_device->enclosure_logical_id, |
| 6690 | sas_device->slot); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6691 | if (sas_device->handle == handle) |
| 6692 | goto out; |
| 6693 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 6694 | sas_device->handle); |
| 6695 | sas_device->handle = handle; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6696 | if (sas_target_priv_data) |
| 6697 | sas_target_priv_data->handle = handle; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6698 | goto out; |
| 6699 | } |
| 6700 | } |
| 6701 | out: |
| 6702 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 6703 | } |
| 6704 | |
| 6705 | /** |
| 6706 | * _scsih_search_responding_sas_devices - |
| 6707 | * @ioc: per adapter object |
| 6708 | * |
| 6709 | * After host reset, find out whether devices are still responding. |
| 6710 | * If not remove. |
| 6711 | * |
| 6712 | * Return nothing. |
| 6713 | */ |
| 6714 | static void |
| 6715 | _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6716 | { |
| 6717 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 6718 | Mpi2ConfigReply_t mpi_reply; |
| 6719 | u16 ioc_status; |
| 6720 | __le64 sas_address; |
| 6721 | u16 handle; |
| 6722 | u32 device_info; |
| 6723 | u16 slot; |
| 6724 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6725 | printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6726 | |
| 6727 | if (list_empty(&ioc->sas_device_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6728 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6729 | |
| 6730 | handle = 0xFFFF; |
| 6731 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 6732 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 6733 | handle))) { |
| 6734 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6735 | MPI2_IOCSTATUS_MASK; |
| 6736 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6737 | break; |
| 6738 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 6739 | device_info = le32_to_cpu(sas_device_pg0.DeviceInfo); |
| 6740 | if (!(_scsih_is_end_device(device_info))) |
| 6741 | continue; |
| 6742 | sas_address = le64_to_cpu(sas_device_pg0.SASAddress); |
| 6743 | slot = le16_to_cpu(sas_device_pg0.Slot); |
| 6744 | _scsih_mark_responding_sas_device(ioc, sas_address, slot, |
| 6745 | handle); |
| 6746 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6747 | out: |
| 6748 | printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n", |
| 6749 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6750 | } |
| 6751 | |
| 6752 | /** |
| 6753 | * _scsih_mark_responding_raid_device - mark a raid_device as responding |
| 6754 | * @ioc: per adapter object |
| 6755 | * @wwid: world wide identifier for raid volume |
| 6756 | * @handle: device handle |
| 6757 | * |
| 6758 | * After host reset, find out whether devices are still responding. |
| 6759 | * Used in _scsi_remove_unresponsive_raid_devices. |
| 6760 | * |
| 6761 | * Return nothing. |
| 6762 | */ |
| 6763 | static void |
| 6764 | _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid, |
| 6765 | u16 handle) |
| 6766 | { |
| 6767 | struct MPT2SAS_TARGET *sas_target_priv_data; |
| 6768 | struct scsi_target *starget; |
| 6769 | struct _raid_device *raid_device; |
| 6770 | unsigned long flags; |
| 6771 | |
| 6772 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6773 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 6774 | if (raid_device->wwid == wwid && raid_device->starget) { |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6775 | starget = raid_device->starget; |
| 6776 | if (starget && starget->hostdata) { |
| 6777 | sas_target_priv_data = starget->hostdata; |
| 6778 | sas_target_priv_data->deleted = 0; |
| 6779 | } else |
| 6780 | sas_target_priv_data = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6781 | raid_device->responding = 1; |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6782 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6783 | starget_printk(KERN_INFO, raid_device->starget, |
| 6784 | "handle(0x%04x), wwid(0x%016llx)\n", handle, |
| 6785 | (unsigned long long)raid_device->wwid); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6786 | /* |
| 6787 | * WARPDRIVE: The handles of the PDs might have changed |
| 6788 | * across the host reset so re-initialize the |
| 6789 | * required data for Direct IO |
| 6790 | */ |
| 6791 | _scsih_init_warpdrive_properties(ioc, raid_device); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6792 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 6793 | if (raid_device->handle == handle) { |
| 6794 | spin_unlock_irqrestore(&ioc->raid_device_lock, |
| 6795 | flags); |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6796 | return; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6797 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6798 | printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n", |
| 6799 | raid_device->handle); |
| 6800 | raid_device->handle = handle; |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 6801 | if (sas_target_priv_data) |
| 6802 | sas_target_priv_data->handle = handle; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6803 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6804 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6805 | } |
| 6806 | } |
nagalakshmi.nandigama@lsi.com | 30c4328 | 2011-12-01 07:52:56 +0530 | [diff] [blame] | 6807 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6808 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 6809 | } |
| 6810 | |
| 6811 | /** |
| 6812 | * _scsih_search_responding_raid_devices - |
| 6813 | * @ioc: per adapter object |
| 6814 | * |
| 6815 | * After host reset, find out whether devices are still responding. |
| 6816 | * If not remove. |
| 6817 | * |
| 6818 | * Return nothing. |
| 6819 | */ |
| 6820 | static void |
| 6821 | _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc) |
| 6822 | { |
| 6823 | Mpi2RaidVolPage1_t volume_pg1; |
Kashyap, Desai | d417d1c | 2010-06-17 13:48:10 +0530 | [diff] [blame] | 6824 | Mpi2RaidVolPage0_t volume_pg0; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6825 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6826 | Mpi2ConfigReply_t mpi_reply; |
| 6827 | u16 ioc_status; |
| 6828 | u16 handle; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6829 | u8 phys_disk_num; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6830 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6831 | if (!ioc->ir_firmware) |
| 6832 | return; |
| 6833 | |
| 6834 | printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n", |
| 6835 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6836 | |
| 6837 | if (list_empty(&ioc->raid_device_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6838 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6839 | |
| 6840 | handle = 0xFFFF; |
| 6841 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 6842 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 6843 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6844 | MPI2_IOCSTATUS_MASK; |
| 6845 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6846 | break; |
| 6847 | handle = le16_to_cpu(volume_pg1.DevHandle); |
Kashyap, Desai | d417d1c | 2010-06-17 13:48:10 +0530 | [diff] [blame] | 6848 | |
| 6849 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 6850 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 6851 | sizeof(Mpi2RaidVolPage0_t))) |
| 6852 | continue; |
| 6853 | |
| 6854 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 6855 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 6856 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) |
| 6857 | _scsih_mark_responding_raid_device(ioc, |
| 6858 | le64_to_cpu(volume_pg1.WWID), handle); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6859 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6860 | |
| 6861 | /* refresh the pd_handles */ |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 6862 | if (!ioc->is_warpdrive) { |
| 6863 | phys_disk_num = 0xFF; |
| 6864 | memset(ioc->pd_handles, 0, ioc->pd_handles_sz); |
| 6865 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 6866 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 6867 | phys_disk_num))) { |
| 6868 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6869 | MPI2_IOCSTATUS_MASK; |
| 6870 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6871 | break; |
| 6872 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 6873 | handle = le16_to_cpu(pd_pg0.DevHandle); |
| 6874 | set_bit(handle, ioc->pd_handles); |
| 6875 | } |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 6876 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6877 | out: |
| 6878 | printk(MPT2SAS_INFO_FMT "search for responding raid volumes: " |
| 6879 | "complete\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6880 | } |
| 6881 | |
| 6882 | /** |
| 6883 | * _scsih_mark_responding_expander - mark a expander as responding |
| 6884 | * @ioc: per adapter object |
| 6885 | * @sas_address: sas address |
| 6886 | * @handle: |
| 6887 | * |
| 6888 | * After host reset, find out whether devices are still responding. |
| 6889 | * Used in _scsi_remove_unresponsive_expanders. |
| 6890 | * |
| 6891 | * Return nothing. |
| 6892 | */ |
| 6893 | static void |
| 6894 | _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address, |
| 6895 | u16 handle) |
| 6896 | { |
| 6897 | struct _sas_node *sas_expander; |
| 6898 | unsigned long flags; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6899 | int i; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6900 | |
| 6901 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 6902 | list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6903 | if (sas_expander->sas_address != sas_address) |
| 6904 | continue; |
| 6905 | sas_expander->responding = 1; |
| 6906 | if (sas_expander->handle == handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6907 | goto out; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 6908 | printk(KERN_INFO "\texpander(0x%016llx): handle changed" |
| 6909 | " from(0x%04x) to (0x%04x)!!!\n", |
| 6910 | (unsigned long long)sas_expander->sas_address, |
| 6911 | sas_expander->handle, handle); |
| 6912 | sas_expander->handle = handle; |
| 6913 | for (i = 0 ; i < sas_expander->num_phys ; i++) |
| 6914 | sas_expander->phy[i].handle = handle; |
| 6915 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6916 | } |
| 6917 | out: |
| 6918 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 6919 | } |
| 6920 | |
| 6921 | /** |
| 6922 | * _scsih_search_responding_expanders - |
| 6923 | * @ioc: per adapter object |
| 6924 | * |
| 6925 | * After host reset, find out whether devices are still responding. |
| 6926 | * If not remove. |
| 6927 | * |
| 6928 | * Return nothing. |
| 6929 | */ |
| 6930 | static void |
| 6931 | _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc) |
| 6932 | { |
| 6933 | Mpi2ExpanderPage0_t expander_pg0; |
| 6934 | Mpi2ConfigReply_t mpi_reply; |
| 6935 | u16 ioc_status; |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 6936 | u64 sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6937 | u16 handle; |
| 6938 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6939 | printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6940 | |
| 6941 | if (list_empty(&ioc->sas_expander_list)) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6942 | goto out; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6943 | |
| 6944 | handle = 0xFFFF; |
| 6945 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 6946 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 6947 | |
| 6948 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 6949 | MPI2_IOCSTATUS_MASK; |
| 6950 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 6951 | break; |
| 6952 | |
| 6953 | handle = le16_to_cpu(expander_pg0.DevHandle); |
| 6954 | sas_address = le64_to_cpu(expander_pg0.SASAddress); |
| 6955 | printk(KERN_INFO "\texpander present: handle(0x%04x), " |
| 6956 | "sas_addr(0x%016llx)\n", handle, |
| 6957 | (unsigned long long)sas_address); |
| 6958 | _scsih_mark_responding_expander(ioc, sas_address, handle); |
| 6959 | } |
| 6960 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6961 | out: |
| 6962 | printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6963 | } |
| 6964 | |
| 6965 | /** |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6966 | * _scsih_remove_unresponding_sas_devices - removing unresponding devices |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6967 | * @ioc: per adapter object |
| 6968 | * |
| 6969 | * Return nothing. |
| 6970 | */ |
| 6971 | static void |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 6972 | _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6973 | { |
| 6974 | struct _sas_device *sas_device, *sas_device_next; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6975 | struct _sas_node *sas_expander, *sas_expander_next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6976 | struct _raid_device *raid_device, *raid_device_next; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6977 | struct list_head tmp_list; |
| 6978 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6979 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 6980 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n", |
| 6981 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6982 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6983 | /* removing unresponding end devices */ |
| 6984 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n", |
| 6985 | ioc->name); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6986 | list_for_each_entry_safe(sas_device, sas_device_next, |
| 6987 | &ioc->sas_device_list, list) { |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6988 | if (!sas_device->responding) |
| 6989 | _scsih_device_remove_by_handle(ioc, |
| 6990 | sas_device->handle); |
| 6991 | else |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6992 | sas_device->responding = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 6993 | } |
| 6994 | |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 6995 | /* removing unresponding volumes */ |
| 6996 | if (ioc->ir_firmware) { |
| 6997 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: " |
| 6998 | "volumes\n", ioc->name); |
| 6999 | list_for_each_entry_safe(raid_device, raid_device_next, |
| 7000 | &ioc->raid_device_list, list) { |
| 7001 | if (!raid_device->responding) |
| 7002 | _scsih_sas_volume_delete(ioc, |
| 7003 | raid_device->handle); |
| 7004 | else |
| 7005 | raid_device->responding = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7006 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7007 | } |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7008 | /* removing unresponding expanders */ |
| 7009 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n", |
| 7010 | ioc->name); |
| 7011 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
| 7012 | INIT_LIST_HEAD(&tmp_list); |
| 7013 | list_for_each_entry_safe(sas_expander, sas_expander_next, |
| 7014 | &ioc->sas_expander_list, list) { |
| 7015 | if (!sas_expander->responding) |
| 7016 | list_move_tail(&sas_expander->list, &tmp_list); |
| 7017 | else |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7018 | sas_expander->responding = 0; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7019 | } |
| 7020 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
| 7021 | list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list, |
| 7022 | list) { |
| 7023 | list_del(&sas_expander->list); |
| 7024 | _scsih_expander_node_remove(ioc, sas_expander); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7025 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7026 | printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n", |
| 7027 | ioc->name); |
| 7028 | /* unblock devices */ |
| 7029 | _scsih_ublock_io_all_device(ioc); |
| 7030 | } |
| 7031 | |
| 7032 | static void |
| 7033 | _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc, |
| 7034 | struct _sas_node *sas_expander, u16 handle) |
| 7035 | { |
| 7036 | Mpi2ExpanderPage1_t expander_pg1; |
| 7037 | Mpi2ConfigReply_t mpi_reply; |
| 7038 | int i; |
| 7039 | |
| 7040 | for (i = 0 ; i < sas_expander->num_phys ; i++) { |
| 7041 | if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply, |
| 7042 | &expander_pg1, i, handle))) { |
| 7043 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7044 | ioc->name, __FILE__, __LINE__, __func__); |
| 7045 | return; |
| 7046 | } |
| 7047 | |
| 7048 | mpt2sas_transport_update_links(ioc, sas_expander->sas_address, |
| 7049 | le16_to_cpu(expander_pg1.AttachedDevHandle), i, |
| 7050 | expander_pg1.NegotiatedLinkRate >> 4); |
| 7051 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7052 | } |
| 7053 | |
| 7054 | /** |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7055 | * _scsih_scan_for_devices_after_reset - scan for devices after host reset |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7056 | * @ioc: per adapter object |
| 7057 | * |
| 7058 | * Return nothing. |
| 7059 | */ |
| 7060 | static void |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7061 | _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc) |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7062 | { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7063 | Mpi2ExpanderPage0_t expander_pg0; |
| 7064 | Mpi2SasDevicePage0_t sas_device_pg0; |
| 7065 | Mpi2RaidVolPage1_t volume_pg1; |
| 7066 | Mpi2RaidVolPage0_t volume_pg0; |
| 7067 | Mpi2RaidPhysDiskPage0_t pd_pg0; |
| 7068 | Mpi2EventIrConfigElement_t element; |
| 7069 | Mpi2ConfigReply_t mpi_reply; |
| 7070 | u8 phys_disk_num; |
| 7071 | u16 ioc_status; |
| 7072 | u16 handle, parent_handle; |
| 7073 | u64 sas_address; |
| 7074 | struct _sas_device *sas_device; |
| 7075 | struct _sas_node *expander_device; |
| 7076 | static struct _raid_device *raid_device; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7077 | unsigned long flags; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7078 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7079 | printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7080 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7081 | _scsih_sas_host_refresh(ioc); |
| 7082 | |
| 7083 | /* expanders */ |
| 7084 | handle = 0xFFFF; |
| 7085 | while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, |
| 7086 | MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) { |
| 7087 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7088 | MPI2_IOCSTATUS_MASK; |
| 7089 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 7090 | break; |
| 7091 | handle = le16_to_cpu(expander_pg0.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7092 | spin_lock_irqsave(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7093 | expander_device = mpt2sas_scsih_expander_find_by_sas_address( |
| 7094 | ioc, le64_to_cpu(expander_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7095 | spin_unlock_irqrestore(&ioc->sas_node_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7096 | if (expander_device) |
| 7097 | _scsih_refresh_expander_links(ioc, expander_device, |
| 7098 | handle); |
| 7099 | else |
| 7100 | _scsih_expander_add(ioc, handle); |
| 7101 | } |
| 7102 | |
| 7103 | if (!ioc->ir_firmware) |
| 7104 | goto skip_to_sas; |
| 7105 | |
| 7106 | /* phys disk */ |
| 7107 | phys_disk_num = 0xFF; |
| 7108 | while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply, |
| 7109 | &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM, |
| 7110 | phys_disk_num))) { |
| 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 | phys_disk_num = pd_pg0.PhysDiskNum; |
| 7116 | handle = le16_to_cpu(pd_pg0.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7117 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7118 | sas_device = _scsih_sas_device_find_by_handle(ioc, handle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7119 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7120 | if (sas_device) |
| 7121 | continue; |
| 7122 | if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 7123 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, |
| 7124 | handle) != 0) |
| 7125 | continue; |
| 7126 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 7127 | if (!_scsih_get_sas_address(ioc, parent_handle, |
| 7128 | &sas_address)) { |
| 7129 | mpt2sas_transport_update_links(ioc, sas_address, |
| 7130 | handle, sas_device_pg0.PhyNum, |
| 7131 | MPI2_SAS_NEG_LINK_RATE_1_5); |
| 7132 | set_bit(handle, ioc->pd_handles); |
| 7133 | _scsih_add_device(ioc, handle, 0, 1); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7134 | } |
| 7135 | } |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7136 | |
| 7137 | /* volumes */ |
| 7138 | handle = 0xFFFF; |
| 7139 | while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, |
| 7140 | &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 7141 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7142 | MPI2_IOCSTATUS_MASK; |
| 7143 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 7144 | break; |
| 7145 | handle = le16_to_cpu(volume_pg1.DevHandle); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7146 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7147 | raid_device = _scsih_raid_device_find_by_wwid(ioc, |
| 7148 | le64_to_cpu(volume_pg1.WWID)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7149 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7150 | if (raid_device) |
| 7151 | continue; |
| 7152 | if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, |
| 7153 | &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle, |
| 7154 | sizeof(Mpi2RaidVolPage0_t))) |
| 7155 | continue; |
| 7156 | if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL || |
| 7157 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE || |
| 7158 | volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) { |
| 7159 | memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t)); |
| 7160 | element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED; |
| 7161 | element.VolDevHandle = volume_pg1.DevHandle; |
| 7162 | _scsih_sas_volume_add(ioc, &element); |
| 7163 | } |
| 7164 | } |
| 7165 | |
| 7166 | skip_to_sas: |
| 7167 | |
| 7168 | /* sas devices */ |
| 7169 | handle = 0xFFFF; |
| 7170 | while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, |
| 7171 | &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, |
| 7172 | handle))) { |
| 7173 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 7174 | MPI2_IOCSTATUS_MASK; |
| 7175 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 7176 | break; |
| 7177 | handle = le16_to_cpu(sas_device_pg0.DevHandle); |
| 7178 | if (!(_scsih_is_end_device( |
| 7179 | le32_to_cpu(sas_device_pg0.DeviceInfo)))) |
| 7180 | continue; |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7181 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7182 | sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc, |
| 7183 | le64_to_cpu(sas_device_pg0.SASAddress)); |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7184 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7185 | if (sas_device) |
| 7186 | continue; |
| 7187 | parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle); |
| 7188 | if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) { |
| 7189 | mpt2sas_transport_update_links(ioc, sas_address, handle, |
| 7190 | sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5); |
| 7191 | _scsih_add_device(ioc, handle, 0, 0); |
| 7192 | } |
| 7193 | } |
| 7194 | |
| 7195 | printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7196 | } |
| 7197 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7198 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7199 | /** |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7200 | * mpt2sas_scsih_reset_handler - reset callback handler (for scsih) |
| 7201 | * @ioc: per adapter object |
| 7202 | * @reset_phase: phase |
| 7203 | * |
| 7204 | * The handler for doing any required cleanup or initialization. |
| 7205 | * |
| 7206 | * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET, |
| 7207 | * MPT2_IOC_DONE_RESET |
| 7208 | * |
| 7209 | * Return nothing. |
| 7210 | */ |
| 7211 | void |
| 7212 | mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase) |
| 7213 | { |
| 7214 | switch (reset_phase) { |
| 7215 | case MPT2_IOC_PRE_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7216 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7217 | "MPT2_IOC_PRE_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7218 | break; |
| 7219 | case MPT2_IOC_AFTER_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7220 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7221 | "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7222 | if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) { |
| 7223 | ioc->scsih_cmds.status |= MPT2_CMD_RESET; |
| 7224 | mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid); |
| 7225 | complete(&ioc->scsih_cmds.done); |
| 7226 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7227 | if (ioc->tm_cmds.status & MPT2_CMD_PENDING) { |
| 7228 | ioc->tm_cmds.status |= MPT2_CMD_RESET; |
| 7229 | mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid); |
| 7230 | complete(&ioc->tm_cmds.done); |
| 7231 | } |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7232 | _scsih_fw_event_cleanup_queue(ioc); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7233 | _scsih_flush_running_cmds(ioc); |
| 7234 | break; |
| 7235 | case MPT2_IOC_DONE_RESET: |
Kashyap, Desai | eabb08a | 2010-06-17 13:43:57 +0530 | [diff] [blame] | 7236 | dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7237 | "MPT2_IOC_DONE_RESET\n", ioc->name, __func__)); |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7238 | _scsih_sas_host_refresh(ioc); |
Kashyap, Desai | 1469585 | 2010-03-30 10:52:44 +0530 | [diff] [blame] | 7239 | _scsih_prep_device_scan(ioc); |
| 7240 | _scsih_search_responding_sas_devices(ioc); |
| 7241 | _scsih_search_responding_raid_devices(ioc); |
| 7242 | _scsih_search_responding_expanders(ioc); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7243 | if (!ioc->is_driver_loading) { |
| 7244 | _scsih_prep_device_scan(ioc); |
| 7245 | _scsih_search_responding_sas_devices(ioc); |
| 7246 | _scsih_search_responding_raid_devices(ioc); |
| 7247 | _scsih_search_responding_expanders(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7248 | _scsih_error_recovery_delete_devices(ioc); |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7249 | } |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 7250 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7251 | } |
| 7252 | } |
| 7253 | |
| 7254 | /** |
| 7255 | * _firmware_event_work - delayed task for processing firmware events |
| 7256 | * @ioc: per adapter object |
| 7257 | * @work: equal to the fw_event_work object |
| 7258 | * Context: user. |
| 7259 | * |
| 7260 | * Return nothing. |
| 7261 | */ |
| 7262 | static void |
| 7263 | _firmware_event_work(struct work_struct *work) |
| 7264 | { |
| 7265 | struct fw_event_work *fw_event = container_of(work, |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7266 | struct fw_event_work, delayed_work.work); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7267 | struct MPT2SAS_ADAPTER *ioc = fw_event->ioc; |
| 7268 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7269 | /* the queue is being flushed so ignore this event */ |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7270 | if (ioc->remove_host || fw_event->cancel_pending_work || |
| 7271 | ioc->pci_error_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7272 | _scsih_fw_event_free(ioc, fw_event); |
| 7273 | return; |
| 7274 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7275 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7276 | switch (fw_event->event) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7277 | case MPT2SAS_REMOVE_UNRESPONDING_DEVICES: |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7278 | while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery) |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7279 | ssleep(1); |
| 7280 | _scsih_remove_unresponding_sas_devices(ioc); |
| 7281 | _scsih_scan_for_devices_after_reset(ioc); |
| 7282 | break; |
| 7283 | case MPT2SAS_PORT_ENABLE_COMPLETE: |
nagalakshmi.nandigama@lsi.com | 918134e | 2011-10-19 15:37:24 +0530 | [diff] [blame] | 7284 | ioc->start_scan = 0; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7285 | |
| 7286 | |
| 7287 | |
| 7288 | dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete " |
| 7289 | "from worker thread\n", ioc->name)); |
| 7290 | break; |
Kashyap, Desai | 3ace8e0 | 2011-05-04 16:35:58 +0530 | [diff] [blame] | 7291 | case MPT2SAS_TURN_ON_FAULT_LED: |
| 7292 | _scsih_turn_on_fault_led(ioc, fw_event->device_handle); |
| 7293 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7294 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7295 | _scsih_sas_topology_change_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7296 | break; |
| 7297 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7298 | _scsih_sas_device_status_change_event(ioc, |
| 7299 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7300 | break; |
| 7301 | case MPI2_EVENT_SAS_DISCOVERY: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7302 | _scsih_sas_discovery_event(ioc, |
| 7303 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7304 | break; |
| 7305 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
Andrew Morton | a78e21d | 2012-02-08 12:52:22 -0800 | [diff] [blame] | 7306 | _scsih_sas_broadcast_primitive_event(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7307 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7308 | break; |
| 7309 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
| 7310 | _scsih_sas_enclosure_dev_status_change_event(ioc, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7311 | fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7312 | break; |
| 7313 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7314 | _scsih_sas_ir_config_change_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7315 | break; |
| 7316 | case MPI2_EVENT_IR_VOLUME: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7317 | _scsih_sas_ir_volume_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7318 | break; |
| 7319 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7320 | _scsih_sas_ir_physical_disk_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7321 | break; |
| 7322 | case MPI2_EVENT_IR_OPERATION_STATUS: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7323 | _scsih_sas_ir_operation_status_event(ioc, fw_event); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7324 | break; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7325 | } |
| 7326 | _scsih_fw_event_free(ioc, fw_event); |
| 7327 | } |
| 7328 | |
| 7329 | /** |
| 7330 | * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time) |
| 7331 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7332 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7333 | * @reply: reply message frame(lower 32bit addr) |
| 7334 | * Context: interrupt. |
| 7335 | * |
| 7336 | * This function merely adds a new work task into ioc->firmware_event_thread. |
| 7337 | * The tasks are worked from _firmware_event_work in user context. |
| 7338 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7339 | * Return 1 meaning mf should be freed from _base_interrupt |
| 7340 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7341 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7342 | u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7343 | mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, |
| 7344 | u32 reply) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7345 | { |
| 7346 | struct fw_event_work *fw_event; |
| 7347 | Mpi2EventNotificationReply_t *mpi_reply; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7348 | u16 event; |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 7349 | u16 sz; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7350 | |
| 7351 | /* events turned off due to host reset or driver unloading */ |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 7352 | if (ioc->remove_host || ioc->pci_error_recovery) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7353 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7354 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7355 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7356 | event = le16_to_cpu(mpi_reply->Event); |
| 7357 | |
| 7358 | switch (event) { |
| 7359 | /* handle these */ |
| 7360 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 7361 | { |
| 7362 | Mpi2EventDataSasBroadcastPrimitive_t *baen_data = |
| 7363 | (Mpi2EventDataSasBroadcastPrimitive_t *) |
| 7364 | mpi_reply->EventData; |
| 7365 | |
| 7366 | if (baen_data->Primitive != |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7367 | MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7368 | return 1; |
Kashyap, Desai | f93213d | 2011-06-14 10:56:43 +0530 | [diff] [blame] | 7369 | |
| 7370 | if (ioc->broadcast_aen_busy) { |
| 7371 | ioc->broadcast_aen_pending++; |
| 7372 | return 1; |
| 7373 | } else |
| 7374 | ioc->broadcast_aen_busy = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7375 | break; |
| 7376 | } |
| 7377 | |
| 7378 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
| 7379 | _scsih_check_topo_delete_events(ioc, |
| 7380 | (Mpi2EventDataSasTopologyChangeList_t *) |
| 7381 | mpi_reply->EventData); |
| 7382 | break; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 7383 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
| 7384 | _scsih_check_ir_config_unhide_events(ioc, |
| 7385 | (Mpi2EventDataIrConfigChangeList_t *) |
| 7386 | mpi_reply->EventData); |
| 7387 | break; |
| 7388 | case MPI2_EVENT_IR_VOLUME: |
| 7389 | _scsih_check_volume_delete_events(ioc, |
| 7390 | (Mpi2EventDataIrVolume_t *) |
| 7391 | mpi_reply->EventData); |
| 7392 | break; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7393 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
| 7394 | { |
| 7395 | Mpi2EventDataLogEntryAdded_t *log_entry; |
| 7396 | u32 *log_code; |
| 7397 | |
| 7398 | if (!ioc->is_warpdrive) |
| 7399 | break; |
| 7400 | |
| 7401 | log_entry = (Mpi2EventDataLogEntryAdded_t *) |
| 7402 | mpi_reply->EventData; |
| 7403 | log_code = (u32 *)log_entry->LogData; |
| 7404 | |
| 7405 | if (le16_to_cpu(log_entry->LogEntryQualifier) |
| 7406 | != MPT2_WARPDRIVE_LOGENTRY) |
| 7407 | break; |
| 7408 | |
| 7409 | switch (le32_to_cpu(*log_code)) { |
| 7410 | case MPT2_WARPDRIVE_LC_SSDT: |
| 7411 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " |
| 7412 | "IO Throttling has occurred in the WarpDrive " |
| 7413 | "subsystem. Check WarpDrive documentation for " |
| 7414 | "additional details.\n", ioc->name); |
| 7415 | break; |
| 7416 | case MPT2_WARPDRIVE_LC_SSDLW: |
| 7417 | printk(MPT2SAS_WARN_FMT "WarpDrive Warning: " |
| 7418 | "Program/Erase Cycles for the WarpDrive subsystem " |
| 7419 | "in degraded range. Check WarpDrive documentation " |
| 7420 | "for additional details.\n", ioc->name); |
| 7421 | break; |
| 7422 | case MPT2_WARPDRIVE_LC_SSDLF: |
| 7423 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " |
| 7424 | "There are no Program/Erase Cycles for the " |
| 7425 | "WarpDrive subsystem. The storage device will be " |
| 7426 | "in read-only mode. Check WarpDrive documentation " |
| 7427 | "for additional details.\n", ioc->name); |
| 7428 | break; |
| 7429 | case MPT2_WARPDRIVE_LC_BRMF: |
| 7430 | printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: " |
| 7431 | "The Backup Rail Monitor has failed on the " |
| 7432 | "WarpDrive subsystem. Check WarpDrive " |
| 7433 | "documentation for additional details.\n", |
| 7434 | ioc->name); |
| 7435 | break; |
| 7436 | } |
| 7437 | |
| 7438 | break; |
| 7439 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7440 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 7441 | case MPI2_EVENT_IR_OPERATION_STATUS: |
| 7442 | case MPI2_EVENT_SAS_DISCOVERY: |
| 7443 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7444 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7445 | break; |
| 7446 | |
| 7447 | default: /* ignore the rest */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7448 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7449 | } |
| 7450 | |
| 7451 | fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); |
| 7452 | if (!fw_event) { |
| 7453 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7454 | ioc->name, __FILE__, __LINE__, __func__); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7455 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7456 | } |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 7457 | sz = le16_to_cpu(mpi_reply->EventDataLength) * 4; |
| 7458 | fw_event->event_data = kzalloc(sz, GFP_ATOMIC); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7459 | if (!fw_event->event_data) { |
| 7460 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 7461 | ioc->name, __FILE__, __LINE__, __func__); |
| 7462 | kfree(fw_event); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7463 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7464 | } |
| 7465 | |
| 7466 | memcpy(fw_event->event_data, mpi_reply->EventData, |
Kashyap, Desai | e94f674 | 2010-03-17 16:24:52 +0530 | [diff] [blame] | 7467 | sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7468 | fw_event->ioc = ioc; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 7469 | fw_event->VF_ID = mpi_reply->VF_ID; |
| 7470 | fw_event->VP_ID = mpi_reply->VP_ID; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7471 | fw_event->event = event; |
| 7472 | _scsih_fw_event_add(ioc, fw_event); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7473 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7474 | } |
| 7475 | |
| 7476 | /* shost template */ |
| 7477 | static struct scsi_host_template scsih_driver_template = { |
| 7478 | .module = THIS_MODULE, |
| 7479 | .name = "Fusion MPT SAS Host", |
| 7480 | .proc_name = MPT2SAS_DRIVER_NAME, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7481 | .queuecommand = _scsih_qcmd, |
| 7482 | .target_alloc = _scsih_target_alloc, |
| 7483 | .slave_alloc = _scsih_slave_alloc, |
| 7484 | .slave_configure = _scsih_slave_configure, |
| 7485 | .target_destroy = _scsih_target_destroy, |
| 7486 | .slave_destroy = _scsih_slave_destroy, |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7487 | .scan_finished = _scsih_scan_finished, |
| 7488 | .scan_start = _scsih_scan_start, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7489 | .change_queue_depth = _scsih_change_queue_depth, |
| 7490 | .change_queue_type = _scsih_change_queue_type, |
| 7491 | .eh_abort_handler = _scsih_abort, |
| 7492 | .eh_device_reset_handler = _scsih_dev_reset, |
| 7493 | .eh_target_reset_handler = _scsih_target_reset, |
| 7494 | .eh_host_reset_handler = _scsih_host_reset, |
| 7495 | .bios_param = _scsih_bios_param, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7496 | .can_queue = 1, |
| 7497 | .this_id = -1, |
| 7498 | .sg_tablesize = MPT2SAS_SG_DEPTH, |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 7499 | .max_sectors = 32767, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7500 | .cmd_per_lun = 7, |
| 7501 | .use_clustering = ENABLE_CLUSTERING, |
| 7502 | .shost_attrs = mpt2sas_host_attrs, |
| 7503 | .sdev_attrs = mpt2sas_dev_attrs, |
| 7504 | }; |
| 7505 | |
| 7506 | /** |
| 7507 | * _scsih_expander_node_remove - removing expander device from list. |
| 7508 | * @ioc: per adapter object |
| 7509 | * @sas_expander: the sas_device object |
| 7510 | * Context: Calling function should acquire ioc->sas_node_lock. |
| 7511 | * |
| 7512 | * Removing object and freeing associated memory from the |
| 7513 | * ioc->sas_expander_list. |
| 7514 | * |
| 7515 | * Return nothing. |
| 7516 | */ |
| 7517 | static void |
| 7518 | _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc, |
| 7519 | struct _sas_node *sas_expander) |
| 7520 | { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7521 | struct _sas_port *mpt2sas_port, *next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7522 | |
| 7523 | /* remove sibling ports attached to this expander */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7524 | list_for_each_entry_safe(mpt2sas_port, next, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7525 | &sas_expander->sas_port_list, port_list) { |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7526 | if (ioc->shost_recovery) |
| 7527 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7528 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7529 | SAS_END_DEVICE) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7530 | mpt2sas_device_remove_by_sas_address(ioc, |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7531 | mpt2sas_port->remote_identify.sas_address); |
| 7532 | else if (mpt2sas_port->remote_identify.device_type == |
| 7533 | SAS_EDGE_EXPANDER_DEVICE || |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7534 | mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7535 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7536 | mpt2sas_expander_remove(ioc, |
| 7537 | mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7538 | } |
| 7539 | |
| 7540 | mpt2sas_transport_port_remove(ioc, sas_expander->sas_address, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7541 | sas_expander->sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7542 | |
| 7543 | printk(MPT2SAS_INFO_FMT "expander_remove: handle" |
| 7544 | "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, |
| 7545 | sas_expander->handle, (unsigned long long) |
| 7546 | sas_expander->sas_address); |
| 7547 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7548 | kfree(sas_expander->phy); |
| 7549 | kfree(sas_expander); |
| 7550 | } |
| 7551 | |
| 7552 | /** |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7553 | * _scsih_ir_shutdown - IR shutdown notification |
| 7554 | * @ioc: per adapter object |
| 7555 | * |
| 7556 | * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that |
| 7557 | * the host system is shutting down. |
| 7558 | * |
| 7559 | * Return nothing. |
| 7560 | */ |
| 7561 | static void |
| 7562 | _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc) |
| 7563 | { |
| 7564 | Mpi2RaidActionRequest_t *mpi_request; |
| 7565 | Mpi2RaidActionReply_t *mpi_reply; |
| 7566 | u16 smid; |
| 7567 | |
| 7568 | /* is IR firmware build loaded ? */ |
| 7569 | if (!ioc->ir_firmware) |
| 7570 | return; |
| 7571 | |
| 7572 | /* are there any volumes ? */ |
| 7573 | if (list_empty(&ioc->raid_device_list)) |
| 7574 | return; |
| 7575 | |
| 7576 | mutex_lock(&ioc->scsih_cmds.mutex); |
| 7577 | |
| 7578 | if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) { |
| 7579 | printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n", |
| 7580 | ioc->name, __func__); |
| 7581 | goto out; |
| 7582 | } |
| 7583 | ioc->scsih_cmds.status = MPT2_CMD_PENDING; |
| 7584 | |
| 7585 | smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx); |
| 7586 | if (!smid) { |
| 7587 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 7588 | ioc->name, __func__); |
| 7589 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; |
| 7590 | goto out; |
| 7591 | } |
| 7592 | |
| 7593 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 7594 | ioc->scsih_cmds.smid = smid; |
| 7595 | memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t)); |
| 7596 | |
| 7597 | mpi_request->Function = MPI2_FUNCTION_RAID_ACTION; |
| 7598 | mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED; |
| 7599 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7600 | if (!ioc->hide_ir_msg) |
| 7601 | printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7602 | init_completion(&ioc->scsih_cmds.done); |
| 7603 | mpt2sas_base_put_smid_default(ioc, smid); |
| 7604 | wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ); |
| 7605 | |
| 7606 | if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) { |
| 7607 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 7608 | ioc->name, __func__); |
| 7609 | goto out; |
| 7610 | } |
| 7611 | |
| 7612 | if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) { |
| 7613 | mpi_reply = ioc->scsih_cmds.reply; |
| 7614 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7615 | if (!ioc->hide_ir_msg) |
| 7616 | printk(MPT2SAS_INFO_FMT "IR shutdown (complete): " |
| 7617 | "ioc_status(0x%04x), loginfo(0x%08x)\n", |
| 7618 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 7619 | le32_to_cpu(mpi_reply->IOCLogInfo)); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7620 | } |
| 7621 | |
| 7622 | out: |
| 7623 | ioc->scsih_cmds.status = MPT2_CMD_NOT_USED; |
| 7624 | mutex_unlock(&ioc->scsih_cmds.mutex); |
| 7625 | } |
| 7626 | |
| 7627 | /** |
| 7628 | * _scsih_shutdown - routine call during system shutdown |
| 7629 | * @pdev: PCI device struct |
| 7630 | * |
| 7631 | * Return nothing. |
| 7632 | */ |
| 7633 | static void |
| 7634 | _scsih_shutdown(struct pci_dev *pdev) |
| 7635 | { |
| 7636 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7637 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7638 | struct workqueue_struct *wq; |
| 7639 | unsigned long flags; |
| 7640 | |
| 7641 | ioc->remove_host = 1; |
| 7642 | _scsih_fw_event_cleanup_queue(ioc); |
| 7643 | |
| 7644 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 7645 | wq = ioc->firmware_event_thread; |
| 7646 | ioc->firmware_event_thread = NULL; |
| 7647 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 7648 | if (wq) |
| 7649 | destroy_workqueue(wq); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7650 | |
| 7651 | _scsih_ir_shutdown(ioc); |
| 7652 | mpt2sas_base_detach(ioc); |
| 7653 | } |
| 7654 | |
| 7655 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7656 | * _scsih_remove - detach and remove add host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7657 | * @pdev: PCI device struct |
| 7658 | * |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 7659 | * Routine called when unloading the driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7660 | * Return nothing. |
| 7661 | */ |
| 7662 | static void __devexit |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7663 | _scsih_remove(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7664 | { |
| 7665 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 7666 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7667 | struct _sas_port *mpt2sas_port, *next_port; |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7668 | struct _raid_device *raid_device, *next; |
| 7669 | struct MPT2SAS_TARGET *sas_target_priv_data; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7670 | struct workqueue_struct *wq; |
| 7671 | unsigned long flags; |
| 7672 | |
| 7673 | ioc->remove_host = 1; |
Kashyap, Desai | f1c35e6 | 2010-03-09 16:31:43 +0530 | [diff] [blame] | 7674 | _scsih_fw_event_cleanup_queue(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 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); |
| 7682 | |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7683 | /* release all the volumes */ |
Kashyap, Desai | 3a9c913 | 2011-01-04 11:40:23 +0530 | [diff] [blame] | 7684 | _scsih_ir_shutdown(ioc); |
Kashyap, Desai | d7384b2 | 2009-12-16 18:50:06 +0530 | [diff] [blame] | 7685 | list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, |
| 7686 | list) { |
| 7687 | if (raid_device->starget) { |
| 7688 | sas_target_priv_data = |
| 7689 | raid_device->starget->hostdata; |
| 7690 | sas_target_priv_data->deleted = 1; |
| 7691 | scsi_remove_target(&raid_device->starget->dev); |
| 7692 | } |
| 7693 | printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid" |
| 7694 | "(0x%016llx)\n", ioc->name, raid_device->handle, |
| 7695 | (unsigned long long) raid_device->wwid); |
| 7696 | _scsih_raid_device_remove(ioc, raid_device); |
| 7697 | } |
| 7698 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7699 | /* free ports attached to the sas_host */ |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7700 | list_for_each_entry_safe(mpt2sas_port, next_port, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7701 | &ioc->sas_hba.sas_port_list, port_list) { |
| 7702 | if (mpt2sas_port->remote_identify.device_type == |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7703 | SAS_END_DEVICE) |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7704 | mpt2sas_device_remove_by_sas_address(ioc, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7705 | mpt2sas_port->remote_identify.sas_address); |
Kashyap, Desai | 7f6f794 | 2010-11-13 04:35:30 +0530 | [diff] [blame] | 7706 | else if (mpt2sas_port->remote_identify.device_type == |
| 7707 | SAS_EDGE_EXPANDER_DEVICE || |
| 7708 | mpt2sas_port->remote_identify.device_type == |
| 7709 | SAS_FANOUT_EXPANDER_DEVICE) |
| 7710 | mpt2sas_expander_remove(ioc, |
| 7711 | mpt2sas_port->remote_identify.sas_address); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7712 | } |
| 7713 | |
| 7714 | /* free phys attached to the sas_host */ |
| 7715 | if (ioc->sas_hba.num_phys) { |
| 7716 | kfree(ioc->sas_hba.phy); |
| 7717 | ioc->sas_hba.phy = NULL; |
| 7718 | ioc->sas_hba.num_phys = 0; |
| 7719 | } |
| 7720 | |
| 7721 | sas_remove_host(shost); |
kashyap.desai@lsi.com | 9ae89b0 | 2011-08-04 16:47:50 +0530 | [diff] [blame] | 7722 | mpt2sas_base_detach(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7723 | list_del(&ioc->list); |
| 7724 | scsi_remove_host(shost); |
| 7725 | scsi_host_put(shost); |
| 7726 | } |
| 7727 | |
| 7728 | /** |
| 7729 | * _scsih_probe_boot_devices - reports 1st device |
| 7730 | * @ioc: per adapter object |
| 7731 | * |
| 7732 | * If specified in bios page 2, this routine reports the 1st |
| 7733 | * device scsi-ml or sas transport for persistent boot device |
| 7734 | * purposes. Please refer to function _scsih_determine_boot_device() |
| 7735 | */ |
| 7736 | static void |
| 7737 | _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc) |
| 7738 | { |
| 7739 | u8 is_raid; |
| 7740 | void *device; |
| 7741 | struct _sas_device *sas_device; |
| 7742 | struct _raid_device *raid_device; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7743 | u16 handle; |
| 7744 | u64 sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7745 | u64 sas_address; |
| 7746 | unsigned long flags; |
| 7747 | int rc; |
| 7748 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7749 | /* no Bios, return immediately */ |
| 7750 | if (!ioc->bios_pg3.BiosVersion) |
| 7751 | return; |
| 7752 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7753 | device = NULL; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7754 | is_raid = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7755 | if (ioc->req_boot_device.device) { |
| 7756 | device = ioc->req_boot_device.device; |
| 7757 | is_raid = ioc->req_boot_device.is_raid; |
| 7758 | } else if (ioc->req_alt_boot_device.device) { |
| 7759 | device = ioc->req_alt_boot_device.device; |
| 7760 | is_raid = ioc->req_alt_boot_device.is_raid; |
| 7761 | } else if (ioc->current_boot_device.device) { |
| 7762 | device = ioc->current_boot_device.device; |
| 7763 | is_raid = ioc->current_boot_device.is_raid; |
| 7764 | } |
| 7765 | |
| 7766 | if (!device) |
| 7767 | return; |
| 7768 | |
| 7769 | if (is_raid) { |
| 7770 | raid_device = device; |
| 7771 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7772 | raid_device->id, 0); |
| 7773 | if (rc) |
| 7774 | _scsih_raid_device_remove(ioc, raid_device); |
| 7775 | } else { |
nagalakshmi.nandigama@lsi.com | 09da0b3 | 2012-03-20 12:06:50 +0530 | [diff] [blame^] | 7776 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7777 | sas_device = device; |
| 7778 | handle = sas_device->handle; |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7779 | sas_address_parent = sas_device->sas_address_parent; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7780 | sas_address = sas_device->sas_address; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7781 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 7782 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7783 | |
| 7784 | if (ioc->hide_drives) |
| 7785 | return; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7786 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7787 | sas_device->sas_address_parent)) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7788 | _scsih_sas_device_remove(ioc, sas_device); |
| 7789 | } else if (!sas_device->starget) { |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 7790 | if (!ioc->is_driver_loading) |
| 7791 | mpt2sas_transport_port_remove(ioc, sas_address, |
| 7792 | sas_address_parent); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7793 | _scsih_sas_device_remove(ioc, sas_device); |
| 7794 | } |
| 7795 | } |
| 7796 | } |
| 7797 | |
| 7798 | /** |
| 7799 | * _scsih_probe_raid - reporting raid volumes to scsi-ml |
| 7800 | * @ioc: per adapter object |
| 7801 | * |
| 7802 | * Called during initial loading of the driver. |
| 7803 | */ |
| 7804 | static void |
| 7805 | _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc) |
| 7806 | { |
| 7807 | struct _raid_device *raid_device, *raid_next; |
| 7808 | int rc; |
| 7809 | |
| 7810 | list_for_each_entry_safe(raid_device, raid_next, |
| 7811 | &ioc->raid_device_list, list) { |
| 7812 | if (raid_device->starget) |
| 7813 | continue; |
| 7814 | rc = scsi_add_device(ioc->shost, RAID_CHANNEL, |
| 7815 | raid_device->id, 0); |
| 7816 | if (rc) |
| 7817 | _scsih_raid_device_remove(ioc, raid_device); |
| 7818 | } |
| 7819 | } |
| 7820 | |
| 7821 | /** |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 7822 | * _scsih_probe_sas - reporting sas devices to sas transport |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7823 | * @ioc: per adapter object |
| 7824 | * |
| 7825 | * Called during initial loading of the driver. |
| 7826 | */ |
| 7827 | static void |
| 7828 | _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc) |
| 7829 | { |
| 7830 | struct _sas_device *sas_device, *next; |
| 7831 | unsigned long flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7832 | |
| 7833 | /* SAS Device List */ |
| 7834 | list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list, |
| 7835 | list) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7836 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7837 | if (ioc->hide_drives) |
| 7838 | continue; |
| 7839 | |
Kashyap, Desai | c5e039b | 2009-09-23 17:21:29 +0530 | [diff] [blame] | 7840 | if (!mpt2sas_transport_port_add(ioc, sas_device->handle, |
| 7841 | sas_device->sas_address_parent)) { |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 7842 | list_del(&sas_device->list); |
| 7843 | kfree(sas_device); |
| 7844 | continue; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7845 | } else if (!sas_device->starget) { |
nagalakshmi.nandigama@lsi.com | 35116db | 2011-10-21 10:08:07 +0530 | [diff] [blame] | 7846 | if (!ioc->is_driver_loading) |
| 7847 | mpt2sas_transport_port_remove(ioc, |
| 7848 | sas_device->sas_address, |
| 7849 | sas_device->sas_address_parent); |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 7850 | list_del(&sas_device->list); |
| 7851 | kfree(sas_device); |
| 7852 | continue; |
| 7853 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7854 | } |
nagalakshmi.nandigama@lsi.com | 0167ac6 | 2011-10-21 10:06:33 +0530 | [diff] [blame] | 7855 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 7856 | list_move_tail(&sas_device->list, &ioc->sas_device_list); |
| 7857 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7858 | } |
| 7859 | } |
| 7860 | |
| 7861 | /** |
| 7862 | * _scsih_probe_devices - probing for devices |
| 7863 | * @ioc: per adapter object |
| 7864 | * |
| 7865 | * Called during initial loading of the driver. |
| 7866 | */ |
| 7867 | static void |
| 7868 | _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc) |
| 7869 | { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7870 | u16 volume_mapping_flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7871 | |
| 7872 | if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) |
| 7873 | return; /* return when IOC doesn't support initiator mode */ |
| 7874 | |
| 7875 | _scsih_probe_boot_devices(ioc); |
| 7876 | |
| 7877 | if (ioc->ir_firmware) { |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7878 | volume_mapping_flags = |
| 7879 | le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) & |
| 7880 | MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE; |
| 7881 | if (volume_mapping_flags == |
| 7882 | MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7883 | _scsih_probe_raid(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7884 | _scsih_probe_sas(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7885 | } else { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7886 | _scsih_probe_sas(ioc); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7887 | _scsih_probe_raid(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7888 | } |
| 7889 | } else |
| 7890 | _scsih_probe_sas(ioc); |
| 7891 | } |
| 7892 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 7893 | |
| 7894 | /** |
| 7895 | * _scsih_scan_start - scsi lld callback for .scan_start |
| 7896 | * @shost: SCSI host pointer |
| 7897 | * |
| 7898 | * The shost has the ability to discover targets on its own instead |
| 7899 | * of scanning the entire bus. In our implemention, we will kick off |
| 7900 | * firmware discovery. |
| 7901 | */ |
| 7902 | static void |
| 7903 | _scsih_scan_start(struct Scsi_Host *shost) |
| 7904 | { |
| 7905 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 7906 | int rc; |
| 7907 | |
| 7908 | if (diag_buffer_enable != -1 && diag_buffer_enable != 0) |
| 7909 | mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable); |
| 7910 | |
| 7911 | ioc->start_scan = 1; |
| 7912 | rc = mpt2sas_port_enable(ioc); |
| 7913 | |
| 7914 | if (rc != 0) |
| 7915 | printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name); |
| 7916 | } |
| 7917 | |
| 7918 | /** |
| 7919 | * _scsih_scan_finished - scsi lld callback for .scan_finished |
| 7920 | * @shost: SCSI host pointer |
| 7921 | * @time: elapsed time of the scan in jiffies |
| 7922 | * |
| 7923 | * This function will be called periodically until it returns 1 with the |
| 7924 | * scsi_host and the elapsed time of the scan in jiffies. In our implemention, |
| 7925 | * we wait for firmware discovery to complete, then return 1. |
| 7926 | */ |
| 7927 | static int |
| 7928 | _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 7929 | { |
| 7930 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 7931 | |
| 7932 | if (time >= (300 * HZ)) { |
| 7933 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 7934 | printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout " |
| 7935 | "(timeout=300s)\n", ioc->name); |
| 7936 | ioc->is_driver_loading = 0; |
| 7937 | return 1; |
| 7938 | } |
| 7939 | |
| 7940 | if (ioc->start_scan) |
| 7941 | return 0; |
| 7942 | |
| 7943 | if (ioc->start_scan_failed) { |
| 7944 | printk(MPT2SAS_INFO_FMT "port enable: FAILED with " |
| 7945 | "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed); |
| 7946 | ioc->is_driver_loading = 0; |
| 7947 | ioc->wait_for_discovery_to_complete = 0; |
| 7948 | ioc->remove_host = 1; |
| 7949 | return 1; |
| 7950 | } |
| 7951 | |
| 7952 | printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name); |
| 7953 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 7954 | |
| 7955 | if (ioc->wait_for_discovery_to_complete) { |
| 7956 | ioc->wait_for_discovery_to_complete = 0; |
| 7957 | _scsih_probe_devices(ioc); |
| 7958 | } |
| 7959 | mpt2sas_base_start_watchdog(ioc); |
| 7960 | ioc->is_driver_loading = 0; |
| 7961 | return 1; |
| 7962 | } |
| 7963 | |
| 7964 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7965 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7966 | * _scsih_probe - attach and add scsi host |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7967 | * @pdev: PCI device struct |
| 7968 | * @id: pci device id |
| 7969 | * |
| 7970 | * Returns 0 success, anything else error. |
| 7971 | */ |
| 7972 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 7973 | _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7974 | { |
| 7975 | struct MPT2SAS_ADAPTER *ioc; |
| 7976 | struct Scsi_Host *shost; |
| 7977 | |
| 7978 | shost = scsi_host_alloc(&scsih_driver_template, |
| 7979 | sizeof(struct MPT2SAS_ADAPTER)); |
| 7980 | if (!shost) |
| 7981 | return -ENODEV; |
| 7982 | |
| 7983 | /* init local params */ |
| 7984 | ioc = shost_priv(shost); |
| 7985 | memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER)); |
| 7986 | INIT_LIST_HEAD(&ioc->list); |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 7987 | list_add_tail(&ioc->list, &mpt2sas_ioc_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7988 | ioc->shost = shost; |
| 7989 | ioc->id = mpt_ids++; |
| 7990 | sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id); |
| 7991 | ioc->pdev = pdev; |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 7992 | if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) { |
| 7993 | ioc->is_warpdrive = 1; |
| 7994 | ioc->hide_ir_msg = 1; |
| 7995 | } else |
| 7996 | ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7997 | ioc->scsi_io_cb_idx = scsi_io_cb_idx; |
| 7998 | ioc->tm_cb_idx = tm_cb_idx; |
| 7999 | ioc->ctl_cb_idx = ctl_cb_idx; |
| 8000 | ioc->base_cb_idx = base_cb_idx; |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8001 | ioc->port_enable_cb_idx = port_enable_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8002 | ioc->transport_cb_idx = transport_cb_idx; |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8003 | ioc->scsih_cb_idx = scsih_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8004 | ioc->config_cb_idx = config_cb_idx; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8005 | ioc->tm_tr_cb_idx = tm_tr_cb_idx; |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8006 | ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8007 | ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8008 | ioc->logging_level = logging_level; |
nagalakshmi.nandigama@lsi.com | 845a0e4 | 2011-12-01 07:42:04 +0530 | [diff] [blame] | 8009 | ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8010 | /* misc semaphores and spin locks */ |
Kashyap, Desai | d274213 | 2010-06-17 13:28:55 +0530 | [diff] [blame] | 8011 | mutex_init(&ioc->reset_in_progress_mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8012 | spin_lock_init(&ioc->ioc_reset_in_progress_lock); |
| 8013 | spin_lock_init(&ioc->scsi_lookup_lock); |
| 8014 | spin_lock_init(&ioc->sas_device_lock); |
| 8015 | spin_lock_init(&ioc->sas_node_lock); |
| 8016 | spin_lock_init(&ioc->fw_event_lock); |
| 8017 | spin_lock_init(&ioc->raid_device_lock); |
| 8018 | |
| 8019 | INIT_LIST_HEAD(&ioc->sas_device_list); |
| 8020 | INIT_LIST_HEAD(&ioc->sas_device_init_list); |
| 8021 | INIT_LIST_HEAD(&ioc->sas_expander_list); |
| 8022 | INIT_LIST_HEAD(&ioc->fw_event_list); |
| 8023 | INIT_LIST_HEAD(&ioc->raid_device_list); |
| 8024 | INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8025 | INIT_LIST_HEAD(&ioc->delayed_tr_list); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8026 | INIT_LIST_HEAD(&ioc->delayed_tr_volume_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8027 | |
| 8028 | /* init shost parameters */ |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 8029 | shost->max_cmd_len = 32; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8030 | shost->max_lun = max_lun; |
| 8031 | shost->transportt = mpt2sas_transport_template; |
| 8032 | shost->unique_id = ioc->id; |
| 8033 | |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8034 | if (max_sectors != 0xFFFF) { |
| 8035 | if (max_sectors < 64) { |
| 8036 | shost->max_sectors = 64; |
| 8037 | printk(MPT2SAS_WARN_FMT "Invalid value %d passed " |
| 8038 | "for max_sectors, range is 64 to 8192. Assigning " |
| 8039 | "value of 64.\n", ioc->name, max_sectors); |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 8040 | } else if (max_sectors > 32767) { |
| 8041 | shost->max_sectors = 32767; |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8042 | printk(MPT2SAS_WARN_FMT "Invalid value %d passed " |
| 8043 | "for max_sectors, range is 64 to 8192. Assigning " |
nagalakshmi.nandigama@lsi.com | 9ac49d3 | 2011-12-01 07:52:08 +0530 | [diff] [blame] | 8044 | "default value of 32767.\n", ioc->name, |
Kashyap, Desai | a3e1e55 | 2011-06-14 10:56:12 +0530 | [diff] [blame] | 8045 | max_sectors); |
| 8046 | } else { |
| 8047 | shost->max_sectors = max_sectors & 0xFFFE; |
| 8048 | printk(MPT2SAS_INFO_FMT "The max_sectors value is " |
| 8049 | "set to %d\n", ioc->name, shost->max_sectors); |
| 8050 | } |
| 8051 | } |
| 8052 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8053 | if ((scsi_add_host(shost, &pdev->dev))) { |
| 8054 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8055 | ioc->name, __FILE__, __LINE__, __func__); |
| 8056 | list_del(&ioc->list); |
| 8057 | goto out_add_shost_fail; |
| 8058 | } |
| 8059 | |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 8060 | scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION |
Eric Moore | d334aa7 | 2010-04-22 10:47:40 -0600 | [diff] [blame] | 8061 | | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8062 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC); |
Eric Moore | 3c621b3 | 2009-05-18 12:59:41 -0600 | [diff] [blame] | 8063 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8064 | /* event thread */ |
| 8065 | snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name), |
| 8066 | "fw_event%d", ioc->id); |
| 8067 | ioc->firmware_event_thread = create_singlethread_workqueue( |
| 8068 | ioc->firmware_event_name); |
| 8069 | if (!ioc->firmware_event_thread) { |
| 8070 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8071 | ioc->name, __FILE__, __LINE__, __func__); |
| 8072 | goto out_thread_fail; |
| 8073 | } |
| 8074 | |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8075 | ioc->is_driver_loading = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8076 | if ((mpt2sas_base_attach(ioc))) { |
| 8077 | printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", |
| 8078 | ioc->name, __FILE__, __LINE__, __func__); |
| 8079 | goto out_attach_fail; |
| 8080 | } |
| 8081 | |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8082 | if (ioc->is_warpdrive) { |
| 8083 | if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) |
| 8084 | ioc->hide_drives = 0; |
| 8085 | else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS) |
| 8086 | ioc->hide_drives = 1; |
| 8087 | else { |
| 8088 | if (_scsih_get_num_volumes(ioc)) |
| 8089 | ioc->hide_drives = 1; |
| 8090 | else |
| 8091 | ioc->hide_drives = 0; |
| 8092 | } |
| 8093 | } else |
| 8094 | ioc->hide_drives = 0; |
nagalakshmi.nandigama@lsi.com | 2cb6fc8 | 2011-12-13 09:29:15 +0530 | [diff] [blame] | 8095 | scsi_scan_host(shost); |
Kashyap, Desai | 0bdccdb | 2011-04-07 12:32:49 +0530 | [diff] [blame] | 8096 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8097 | return 0; |
| 8098 | |
| 8099 | out_attach_fail: |
| 8100 | destroy_workqueue(ioc->firmware_event_thread); |
| 8101 | out_thread_fail: |
| 8102 | list_del(&ioc->list); |
| 8103 | scsi_remove_host(shost); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8104 | scsi_host_put(shost); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8105 | out_add_shost_fail: |
| 8106 | return -ENODEV; |
| 8107 | } |
| 8108 | |
| 8109 | #ifdef CONFIG_PM |
| 8110 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8111 | * _scsih_suspend - power management suspend main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8112 | * @pdev: PCI device struct |
| 8113 | * @state: PM state change to (usually PCI_D3) |
| 8114 | * |
| 8115 | * Returns 0 success, anything else error. |
| 8116 | */ |
| 8117 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8118 | _scsih_suspend(struct pci_dev *pdev, pm_message_t state) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8119 | { |
| 8120 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8121 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 8122 | pci_power_t device_state; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8123 | |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 8124 | mpt2sas_base_stop_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8125 | scsi_block_requests(shost); |
| 8126 | device_state = pci_choose_state(pdev, state); |
| 8127 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering " |
| 8128 | "operating state [D%d]\n", ioc->name, pdev, |
| 8129 | pci_name(pdev), device_state); |
| 8130 | |
| 8131 | mpt2sas_base_free_resources(ioc); |
| 8132 | pci_save_state(pdev); |
| 8133 | pci_disable_device(pdev); |
| 8134 | pci_set_power_state(pdev, device_state); |
| 8135 | return 0; |
| 8136 | } |
| 8137 | |
| 8138 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8139 | * _scsih_resume - power management resume main entry point |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8140 | * @pdev: PCI device struct |
| 8141 | * |
| 8142 | * Returns 0 success, anything else error. |
| 8143 | */ |
| 8144 | static int |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8145 | _scsih_resume(struct pci_dev *pdev) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8146 | { |
| 8147 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8148 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
Kashyap, Desai | c97951e | 2011-06-14 10:54:56 +0530 | [diff] [blame] | 8149 | pci_power_t device_state = pdev->current_state; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8150 | int r; |
| 8151 | |
| 8152 | printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous " |
| 8153 | "operating state [D%d]\n", ioc->name, pdev, |
| 8154 | pci_name(pdev), device_state); |
| 8155 | |
| 8156 | pci_set_power_state(pdev, PCI_D0); |
| 8157 | pci_enable_wake(pdev, PCI_D0, 0); |
| 8158 | pci_restore_state(pdev); |
| 8159 | ioc->pdev = pdev; |
| 8160 | r = mpt2sas_base_map_resources(ioc); |
| 8161 | if (r) |
| 8162 | return r; |
| 8163 | |
| 8164 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET); |
| 8165 | scsi_unblock_requests(shost); |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 8166 | mpt2sas_base_start_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8167 | return 0; |
| 8168 | } |
| 8169 | #endif /* CONFIG_PM */ |
| 8170 | |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8171 | /** |
| 8172 | * _scsih_pci_error_detected - Called when a PCI error is detected. |
| 8173 | * @pdev: PCI device struct |
| 8174 | * @state: PCI channel state |
| 8175 | * |
| 8176 | * Description: Called when a PCI error is detected. |
| 8177 | * |
| 8178 | * Return value: |
| 8179 | * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT |
| 8180 | */ |
| 8181 | static pci_ers_result_t |
| 8182 | _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 8183 | { |
| 8184 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8185 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8186 | |
| 8187 | printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n", |
| 8188 | ioc->name, state); |
| 8189 | |
| 8190 | switch (state) { |
| 8191 | case pci_channel_io_normal: |
| 8192 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 8193 | case pci_channel_io_frozen: |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8194 | /* Fatal error, prepare for slot reset */ |
| 8195 | ioc->pci_error_recovery = 1; |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8196 | scsi_block_requests(ioc->shost); |
| 8197 | mpt2sas_base_stop_watchdog(ioc); |
| 8198 | mpt2sas_base_free_resources(ioc); |
| 8199 | return PCI_ERS_RESULT_NEED_RESET; |
| 8200 | case pci_channel_io_perm_failure: |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8201 | /* Permanent error, prepare for device removal */ |
| 8202 | ioc->pci_error_recovery = 1; |
| 8203 | mpt2sas_base_stop_watchdog(ioc); |
| 8204 | _scsih_flush_running_cmds(ioc); |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8205 | return PCI_ERS_RESULT_DISCONNECT; |
| 8206 | } |
| 8207 | return PCI_ERS_RESULT_NEED_RESET; |
| 8208 | } |
| 8209 | |
| 8210 | /** |
| 8211 | * _scsih_pci_slot_reset - Called when PCI slot has been reset. |
| 8212 | * @pdev: PCI device struct |
| 8213 | * |
| 8214 | * Description: This routine is called by the pci error recovery |
| 8215 | * code after the PCI slot has been reset, just before we |
| 8216 | * should resume normal operations. |
| 8217 | */ |
| 8218 | static pci_ers_result_t |
| 8219 | _scsih_pci_slot_reset(struct pci_dev *pdev) |
| 8220 | { |
| 8221 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8222 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8223 | int rc; |
| 8224 | |
| 8225 | printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n", |
| 8226 | ioc->name); |
| 8227 | |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8228 | ioc->pci_error_recovery = 0; |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8229 | ioc->pdev = pdev; |
Eric Moore | 3cb5469 | 2010-07-08 14:44:34 -0600 | [diff] [blame] | 8230 | pci_restore_state(pdev); |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8231 | rc = mpt2sas_base_map_resources(ioc); |
| 8232 | if (rc) |
| 8233 | return PCI_ERS_RESULT_DISCONNECT; |
| 8234 | |
| 8235 | |
| 8236 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 8237 | FORCE_BIG_HAMMER); |
| 8238 | |
| 8239 | printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name, |
| 8240 | (rc == 0) ? "success" : "failed"); |
| 8241 | |
| 8242 | if (!rc) |
| 8243 | return PCI_ERS_RESULT_RECOVERED; |
| 8244 | else |
| 8245 | return PCI_ERS_RESULT_DISCONNECT; |
| 8246 | } |
| 8247 | |
| 8248 | /** |
| 8249 | * _scsih_pci_resume() - resume normal ops after PCI reset |
| 8250 | * @pdev: pointer to PCI device |
| 8251 | * |
| 8252 | * Called when the error recovery driver tells us that its |
| 8253 | * OK to resume normal operation. Use completion to allow |
| 8254 | * halted scsi ops to resume. |
| 8255 | */ |
| 8256 | static void |
| 8257 | _scsih_pci_resume(struct pci_dev *pdev) |
| 8258 | { |
| 8259 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8260 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8261 | |
| 8262 | printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name); |
| 8263 | |
| 8264 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8265 | mpt2sas_base_start_watchdog(ioc); |
| 8266 | scsi_unblock_requests(ioc->shost); |
| 8267 | } |
| 8268 | |
| 8269 | /** |
| 8270 | * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers |
| 8271 | * @pdev: pointer to PCI device |
| 8272 | */ |
| 8273 | static pci_ers_result_t |
| 8274 | _scsih_pci_mmio_enabled(struct pci_dev *pdev) |
| 8275 | { |
| 8276 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 8277 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 8278 | |
| 8279 | printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n", |
| 8280 | ioc->name); |
| 8281 | |
| 8282 | /* TODO - dump whatever for debugging purposes */ |
| 8283 | |
| 8284 | /* Request a slot reset. */ |
| 8285 | return PCI_ERS_RESULT_NEED_RESET; |
| 8286 | } |
| 8287 | |
| 8288 | static struct pci_error_handlers _scsih_err_handler = { |
| 8289 | .error_detected = _scsih_pci_error_detected, |
| 8290 | .mmio_enabled = _scsih_pci_mmio_enabled, |
| 8291 | .slot_reset = _scsih_pci_slot_reset, |
| 8292 | .resume = _scsih_pci_resume, |
| 8293 | }; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8294 | |
| 8295 | static struct pci_driver scsih_driver = { |
| 8296 | .name = MPT2SAS_DRIVER_NAME, |
| 8297 | .id_table = scsih_pci_table, |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8298 | .probe = _scsih_probe, |
| 8299 | .remove = __devexit_p(_scsih_remove), |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8300 | .shutdown = _scsih_shutdown, |
Kashyap, Desai | ef7c80c | 2010-04-05 14:20:07 +0530 | [diff] [blame] | 8301 | .err_handler = &_scsih_err_handler, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8302 | #ifdef CONFIG_PM |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8303 | .suspend = _scsih_suspend, |
| 8304 | .resume = _scsih_resume, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8305 | #endif |
| 8306 | }; |
| 8307 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8308 | /* raid transport support */ |
| 8309 | static struct raid_function_template mpt2sas_raid_functions = { |
| 8310 | .cookie = &scsih_driver_template, |
| 8311 | .is_raid = _scsih_is_raid, |
| 8312 | .get_resync = _scsih_get_resync, |
| 8313 | .get_state = _scsih_get_state, |
| 8314 | }; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8315 | |
| 8316 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8317 | * _scsih_init - main entry point for this driver. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8318 | * |
| 8319 | * Returns 0 success, anything else error. |
| 8320 | */ |
| 8321 | static int __init |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8322 | _scsih_init(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8323 | { |
| 8324 | int error; |
| 8325 | |
| 8326 | mpt_ids = 0; |
| 8327 | printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME, |
| 8328 | MPT2SAS_DRIVER_VERSION); |
| 8329 | |
| 8330 | mpt2sas_transport_template = |
| 8331 | sas_attach_transport(&mpt2sas_transport_functions); |
| 8332 | if (!mpt2sas_transport_template) |
| 8333 | return -ENODEV; |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8334 | /* raid transport support */ |
| 8335 | mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions); |
| 8336 | if (!mpt2sas_raid_template) { |
| 8337 | sas_release_transport(mpt2sas_transport_template); |
| 8338 | return -ENODEV; |
| 8339 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8340 | |
| 8341 | mpt2sas_base_initialize_callback_handler(); |
| 8342 | |
| 8343 | /* queuecommand callback hander */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8344 | scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8345 | |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 8346 | /* task management callback handler */ |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8347 | tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8348 | |
| 8349 | /* base internal commands callback handler */ |
| 8350 | 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] | 8351 | port_enable_cb_idx = mpt2sas_base_register_callback_handler( |
| 8352 | mpt2sas_port_enable_done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8353 | |
| 8354 | /* transport internal commands callback handler */ |
| 8355 | transport_cb_idx = mpt2sas_base_register_callback_handler( |
| 8356 | mpt2sas_transport_done); |
| 8357 | |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8358 | /* scsih internal commands callback handler */ |
| 8359 | scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done); |
| 8360 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8361 | /* configuration page API internal commands callback handler */ |
| 8362 | config_cb_idx = mpt2sas_base_register_callback_handler( |
| 8363 | mpt2sas_config_done); |
| 8364 | |
| 8365 | /* ctl module callback handler */ |
| 8366 | ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done); |
| 8367 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8368 | tm_tr_cb_idx = mpt2sas_base_register_callback_handler( |
| 8369 | _scsih_tm_tr_complete); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8370 | |
| 8371 | tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler( |
| 8372 | _scsih_tm_volume_tr_complete); |
| 8373 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8374 | tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler( |
| 8375 | _scsih_sas_control_complete); |
| 8376 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8377 | mpt2sas_ctl_init(); |
| 8378 | |
| 8379 | error = pci_register_driver(&scsih_driver); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8380 | if (error) { |
| 8381 | /* raid transport support */ |
| 8382 | raid_class_release(mpt2sas_raid_template); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8383 | sas_release_transport(mpt2sas_transport_template); |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8384 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8385 | |
| 8386 | return error; |
| 8387 | } |
| 8388 | |
| 8389 | /** |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8390 | * _scsih_exit - exit point for this driver (when it is a module). |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8391 | * |
| 8392 | * Returns 0 success, anything else error. |
| 8393 | */ |
| 8394 | static void __exit |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8395 | _scsih_exit(void) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8396 | { |
| 8397 | printk(KERN_INFO "mpt2sas version %s unloading\n", |
| 8398 | MPT2SAS_DRIVER_VERSION); |
| 8399 | |
| 8400 | pci_unregister_driver(&scsih_driver); |
| 8401 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8402 | mpt2sas_ctl_exit(); |
| 8403 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8404 | mpt2sas_base_release_callback_handler(scsi_io_cb_idx); |
| 8405 | mpt2sas_base_release_callback_handler(tm_cb_idx); |
| 8406 | mpt2sas_base_release_callback_handler(base_cb_idx); |
nagalakshmi.nandigama@lsi.com | 921cd80 | 2011-10-19 15:36:26 +0530 | [diff] [blame] | 8407 | mpt2sas_base_release_callback_handler(port_enable_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8408 | mpt2sas_base_release_callback_handler(transport_cb_idx); |
Kashyap, Desai | 744090d | 2009-10-05 15:56:56 +0530 | [diff] [blame] | 8409 | mpt2sas_base_release_callback_handler(scsih_cb_idx); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8410 | mpt2sas_base_release_callback_handler(config_cb_idx); |
| 8411 | mpt2sas_base_release_callback_handler(ctl_cb_idx); |
| 8412 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8413 | mpt2sas_base_release_callback_handler(tm_tr_cb_idx); |
Kashyap, Desai | f3eedd6 | 2010-06-17 13:46:13 +0530 | [diff] [blame] | 8414 | mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 8415 | mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx); |
| 8416 | |
Kashyap, Desai | f7c95ef | 2009-12-16 18:54:42 +0530 | [diff] [blame] | 8417 | /* raid transport support */ |
| 8418 | raid_class_release(mpt2sas_raid_template); |
| 8419 | sas_release_transport(mpt2sas_transport_template); |
| 8420 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 8421 | } |
| 8422 | |
Eric Moore | d5d135b | 2009-05-18 13:02:08 -0600 | [diff] [blame] | 8423 | module_init(_scsih_init); |
| 8424 | module_exit(_scsih_exit); |