blob: 3f26147bbc646535c643adf961001855a1797f96 [file] [log] [blame]
Eric Moore635374e2009-03-09 01:21:12 -06001/*
2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
3 *
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
Sreekanth Reddye9edbe32014-09-12 15:35:18 +05305 * Copyright (C) 2007-2014 LSI Corporation
Sreekanth Reddya03bd152015-01-12 11:39:02 +05306 * Copyright (C) 20013-2014 Avago Technologies
7 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
Eric Moore635374e2009-03-09 01:21:12 -06008 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * NO WARRANTY
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
29
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
42 * USA.
43 */
44
Eric Moore635374e2009-03-09 01:21:12 -060045#include <linux/module.h>
46#include <linux/kernel.h>
47#include <linux/init.h>
48#include <linux/errno.h>
49#include <linux/blkdev.h>
50#include <linux/sched.h>
51#include <linux/workqueue.h>
52#include <linux/delay.h>
53#include <linux/pci.h>
54#include <linux/interrupt.h>
Kashyap, Desaief7c80c2010-04-05 14:20:07 +053055#include <linux/aer.h>
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +053056#include <linux/raid_class.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090057#include <linux/slab.h>
Eric Moore635374e2009-03-09 01:21:12 -060058
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +053059#include <asm/unaligned.h>
60
Eric Moore635374e2009-03-09 01:21:12 -060061#include "mpt2sas_base.h"
62
63MODULE_AUTHOR(MPT2SAS_AUTHOR);
64MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
65MODULE_LICENSE("GPL");
66MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
67
68#define RAID_CHANNEL 1
69
70/* forward proto's */
71static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
72 struct _sas_node *sas_expander);
73static void _firmware_event_work(struct work_struct *work);
74
Kashyap, Desaif3eedd62010-06-17 13:46:13 +053075static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
76
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +053077static void _scsih_scan_start(struct Scsi_Host *shost);
78static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
79
Eric Moore635374e2009-03-09 01:21:12 -060080/* global parameters */
Eric Mooreba33fad2009-03-15 21:37:18 -060081LIST_HEAD(mpt2sas_ioc_list);
Eric Moore635374e2009-03-09 01:21:12 -060082
83/* local parameters */
Eric Moore635374e2009-03-09 01:21:12 -060084static u8 scsi_io_cb_idx = -1;
85static u8 tm_cb_idx = -1;
86static u8 ctl_cb_idx = -1;
87static u8 base_cb_idx = -1;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +053088static u8 port_enable_cb_idx = -1;
Eric Moore635374e2009-03-09 01:21:12 -060089static u8 transport_cb_idx = -1;
Kashyap, Desai744090d2009-10-05 15:56:56 +053090static u8 scsih_cb_idx = -1;
Eric Moore635374e2009-03-09 01:21:12 -060091static u8 config_cb_idx = -1;
92static int mpt_ids;
93
Kashyap, Desai77e63ed2009-09-14 11:04:23 +053094static u8 tm_tr_cb_idx = -1 ;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +053095static u8 tm_tr_volume_cb_idx = -1 ;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +053096static u8 tm_sas_control_cb_idx = -1;
97
Eric Moore635374e2009-03-09 01:21:12 -060098/* command line options */
Eric Mooreba33fad2009-03-15 21:37:18 -060099static u32 logging_level;
Eric Moore635374e2009-03-09 01:21:12 -0600100MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
101 "(default=0)");
102
Kashyap, Desaia3e1e552011-06-14 10:56:12 +0530103static ushort max_sectors = 0xFFFF;
104module_param(max_sectors, ushort, 0);
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +0530105MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
Kashyap, Desaia3e1e552011-06-14 10:56:12 +0530106
Reddy, Sreekanthb0df96a02013-02-26 16:59:59 +0530107static int missing_delay[2] = {-1, -1};
108module_param_array(missing_delay, int, NULL, 0);
109MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
110
Eric Moore635374e2009-03-09 01:21:12 -0600111/* scsi-mid layer global parmeter is max_report_luns, which is 511 */
112#define MPT2SAS_MAX_LUN (16895)
113static int max_lun = MPT2SAS_MAX_LUN;
114module_param(max_lun, int, 0);
115MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
116
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530117/* diag_buffer_enable is bitwise
118 * bit 0 set = TRACE
119 * bit 1 set = SNAPSHOT
120 * bit 2 set = EXTENDED
121 *
122 * Either bit can be set, or both
123 */
124static int diag_buffer_enable = -1;
125module_param(diag_buffer_enable, int, 0);
126MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
127 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
128
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +0530129static int disable_discovery = -1;
130module_param(disable_discovery, int, 0);
131MODULE_PARM_DESC(disable_discovery, " disable discovery ");
132
Martin K. Petersen5e95e732012-08-28 14:29:37 -0400133/* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
134static int prot_mask = 0;
135module_param(prot_mask, int, 0);
136MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
137
Eric Moore635374e2009-03-09 01:21:12 -0600138/**
139 * struct sense_info - common structure for obtaining sense keys
140 * @skey: sense key
141 * @asc: additional sense code
142 * @ascq: additional sense code qualifier
143 */
144struct sense_info {
145 u8 skey;
146 u8 asc;
147 u8 ascq;
148};
149
150
Sreekanth Reddybd58ea32014-09-12 15:35:19 +0530151#define MPT2SAS_TURN_ON_PFA_LED (0xFFFC)
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530152#define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
153#define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
Eric Moore635374e2009-03-09 01:21:12 -0600154/**
155 * struct fw_event_work - firmware event struct
156 * @list: link list framework
157 * @work: work object (ioc->fault_reset_work_q)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +0530158 * @cancel_pending_work: flag set during reset handling
Eric Moore635374e2009-03-09 01:21:12 -0600159 * @ioc: per adapter object
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530160 * @device_handle: device handle
Eric Moore635374e2009-03-09 01:21:12 -0600161 * @VF_ID: virtual function id
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530162 * @VP_ID: virtual port id
Eric Moore635374e2009-03-09 01:21:12 -0600163 * @ignore: flag meaning this event has been marked to ignore
164 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
165 * @event_data: reply event data payload follows
166 *
167 * This object stored on ioc->fw_event_list.
168 */
169struct fw_event_work {
170 struct list_head list;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +0530171 u8 cancel_pending_work;
172 struct delayed_work delayed_work;
Eric Moore635374e2009-03-09 01:21:12 -0600173 struct MPT2SAS_ADAPTER *ioc;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530174 u16 device_handle;
Eric Moore635374e2009-03-09 01:21:12 -0600175 u8 VF_ID;
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530176 u8 VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -0600177 u8 ignore;
178 u16 event;
Joe Lawrence00713ad2014-06-25 17:03:33 -0400179 char event_data[0] __aligned(4);
Eric Moore635374e2009-03-09 01:21:12 -0600180};
181
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +0530182/* raid transport support */
183static struct raid_template *mpt2sas_raid_template;
184
Eric Moore635374e2009-03-09 01:21:12 -0600185/**
186 * struct _scsi_io_transfer - scsi io transfer
187 * @handle: sas device handle (assigned by firmware)
188 * @is_raid: flag set for hidden raid components
189 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
190 * @data_length: data transfer length
191 * @data_dma: dma pointer to data
192 * @sense: sense data
193 * @lun: lun number
194 * @cdb_length: cdb length
195 * @cdb: cdb contents
Eric Moore635374e2009-03-09 01:21:12 -0600196 * @timeout: timeout for this command
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530197 * @VF_ID: virtual function id
198 * @VP_ID: virtual port id
199 * @valid_reply: flag set for reply message
Eric Moore635374e2009-03-09 01:21:12 -0600200 * @sense_length: sense length
201 * @ioc_status: ioc status
202 * @scsi_state: scsi state
203 * @scsi_status: scsi staus
204 * @log_info: log information
205 * @transfer_length: data length transfer when there is a reply message
206 *
207 * Used for sending internal scsi commands to devices within this module.
208 * Refer to _scsi_send_scsi_io().
209 */
210struct _scsi_io_transfer {
211 u16 handle;
212 u8 is_raid;
213 enum dma_data_direction dir;
214 u32 data_length;
215 dma_addr_t data_dma;
216 u8 sense[SCSI_SENSE_BUFFERSIZE];
217 u32 lun;
218 u8 cdb_length;
219 u8 cdb[32];
220 u8 timeout;
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530221 u8 VF_ID;
222 u8 VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -0600223 u8 valid_reply;
224 /* the following bits are only valid when 'valid_reply = 1' */
225 u32 sense_length;
226 u16 ioc_status;
227 u8 scsi_state;
228 u8 scsi_status;
229 u32 log_info;
230 u32 transfer_length;
231};
232
233/*
234 * The pci device ids are defined in mpi/mpi2_cnfg.h.
235 */
236static struct pci_device_id scsih_pci_table[] = {
237 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
238 PCI_ANY_ID, PCI_ANY_ID },
239 /* Falcon ~ 2008*/
240 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
241 PCI_ANY_ID, PCI_ANY_ID },
242 /* Liberator ~ 2108 */
243 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
244 PCI_ANY_ID, PCI_ANY_ID },
245 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
246 PCI_ANY_ID, PCI_ANY_ID },
247 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
248 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desaidb271362009-09-23 17:24:27 +0530249 /* Meteor ~ 2116 */
Eric Moore635374e2009-03-09 01:21:12 -0600250 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
251 PCI_ANY_ID, PCI_ANY_ID },
252 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
253 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desaidb271362009-09-23 17:24:27 +0530254 /* Thunderbolt ~ 2208 */
255 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
256 PCI_ANY_ID, PCI_ANY_ID },
257 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
258 PCI_ANY_ID, PCI_ANY_ID },
259 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
260 PCI_ANY_ID, PCI_ANY_ID },
261 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
262 PCI_ANY_ID, PCI_ANY_ID },
263 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
264 PCI_ANY_ID, PCI_ANY_ID },
265 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
266 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai203d65b2010-06-17 13:37:59 +0530267 /* Mustang ~ 2308 */
268 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
Kashyap, Desaidb271362009-09-23 17:24:27 +0530269 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai203d65b2010-06-17 13:37:59 +0530270 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
271 PCI_ANY_ID, PCI_ANY_ID },
272 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
Kashyap, Desaidb271362009-09-23 17:24:27 +0530273 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +0530274 /* SSS6200 */
275 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
276 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore635374e2009-03-09 01:21:12 -0600277 {0} /* Terminating entry */
278};
279MODULE_DEVICE_TABLE(pci, scsih_pci_table);
280
281/**
Eric Moored5d135b2009-05-18 13:02:08 -0600282 * _scsih_set_debug_level - global setting of ioc->logging_level.
Eric Moore635374e2009-03-09 01:21:12 -0600283 *
284 * Note: The logging levels are defined in mpt2sas_debug.h.
285 */
286static int
Eric Moored5d135b2009-05-18 13:02:08 -0600287_scsih_set_debug_level(const char *val, struct kernel_param *kp)
Eric Moore635374e2009-03-09 01:21:12 -0600288{
289 int ret = param_set_int(val, kp);
290 struct MPT2SAS_ADAPTER *ioc;
291
292 if (ret)
293 return ret;
294
295 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
Eric Mooreba33fad2009-03-15 21:37:18 -0600296 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
Eric Moore635374e2009-03-09 01:21:12 -0600297 ioc->logging_level = logging_level;
298 return 0;
299}
Eric Moored5d135b2009-05-18 13:02:08 -0600300module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
Eric Moore635374e2009-03-09 01:21:12 -0600301 &logging_level, 0644);
302
303/**
304 * _scsih_srch_boot_sas_address - search based on sas_address
305 * @sas_address: sas address
306 * @boot_device: boot device object from bios page 2
307 *
308 * Returns 1 when there's a match, 0 means no match.
309 */
310static inline int
311_scsih_srch_boot_sas_address(u64 sas_address,
312 Mpi2BootDeviceSasWwid_t *boot_device)
313{
314 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
315}
316
317/**
318 * _scsih_srch_boot_device_name - search based on device name
319 * @device_name: device name specified in INDENTIFY fram
320 * @boot_device: boot device object from bios page 2
321 *
322 * Returns 1 when there's a match, 0 means no match.
323 */
324static inline int
325_scsih_srch_boot_device_name(u64 device_name,
326 Mpi2BootDeviceDeviceName_t *boot_device)
327{
328 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
329}
330
331/**
332 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
333 * @enclosure_logical_id: enclosure logical id
334 * @slot_number: slot number
335 * @boot_device: boot device object from bios page 2
336 *
337 * Returns 1 when there's a match, 0 means no match.
338 */
339static inline int
340_scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
341 Mpi2BootDeviceEnclosureSlot_t *boot_device)
342{
343 return (enclosure_logical_id == le64_to_cpu(boot_device->
344 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
345 SlotNumber)) ? 1 : 0;
346}
347
348/**
349 * _scsih_is_boot_device - search for matching boot device.
350 * @sas_address: sas address
351 * @device_name: device name specified in INDENTIFY fram
352 * @enclosure_logical_id: enclosure logical id
353 * @slot_number: slot number
354 * @form: specifies boot device form
355 * @boot_device: boot device object from bios page 2
356 *
357 * Returns 1 when there's a match, 0 means no match.
358 */
359static int
360_scsih_is_boot_device(u64 sas_address, u64 device_name,
361 u64 enclosure_logical_id, u16 slot, u8 form,
362 Mpi2BiosPage2BootDevice_t *boot_device)
363{
364 int rc = 0;
365
366 switch (form) {
367 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
368 if (!sas_address)
369 break;
370 rc = _scsih_srch_boot_sas_address(
371 sas_address, &boot_device->SasWwid);
372 break;
373 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
374 if (!enclosure_logical_id)
375 break;
376 rc = _scsih_srch_boot_encl_slot(
377 enclosure_logical_id,
378 slot, &boot_device->EnclosureSlot);
379 break;
380 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
381 if (!device_name)
382 break;
383 rc = _scsih_srch_boot_device_name(
384 device_name, &boot_device->DeviceName);
385 break;
386 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
387 break;
388 }
389
390 return rc;
391}
392
393/**
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530394 * _scsih_get_sas_address - set the sas_address for given device handle
395 * @handle: device handle
396 * @sas_address: sas address
397 *
398 * Returns 0 success, non-zero when failure
399 */
400static int
401_scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
402 u64 *sas_address)
403{
404 Mpi2SasDevicePage0_t sas_device_pg0;
405 Mpi2ConfigReply_t mpi_reply;
406 u32 ioc_status;
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530407 *sas_address = 0;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530408
409 if (handle <= ioc->sas_hba.num_phys) {
410 *sas_address = ioc->sas_hba.sas_address;
411 return 0;
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530412 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530413
414 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
415 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530416 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
417 __FILE__, __LINE__, __func__);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530418 return -ENXIO;
419 }
420
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530421 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
422 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
423 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
424 return 0;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530425 }
426
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530427 /* we hit this becuase the given parent handle doesn't exist */
428 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
429 return -ENXIO;
430 /* else error case */
431 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
432 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
433 __FILE__, __LINE__, __func__);
434 return -EIO;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530435}
436
437/**
Eric Moore635374e2009-03-09 01:21:12 -0600438 * _scsih_determine_boot_device - determine boot device.
439 * @ioc: per adapter object
440 * @device: either sas_device or raid_device object
441 * @is_raid: [flag] 1 = raid object, 0 = sas object
442 *
443 * Determines whether this device should be first reported device to
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300444 * to scsi-ml or sas transport, this purpose is for persistent boot device.
Eric Moore635374e2009-03-09 01:21:12 -0600445 * There are primary, alternate, and current entries in bios page 2. The order
446 * priority is primary, alternate, then current. This routine saves
447 * the corresponding device object and is_raid flag in the ioc object.
448 * The saved data to be used later in _scsih_probe_boot_devices().
449 */
450static void
451_scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
452 void *device, u8 is_raid)
453{
454 struct _sas_device *sas_device;
455 struct _raid_device *raid_device;
456 u64 sas_address;
457 u64 device_name;
458 u64 enclosure_logical_id;
459 u16 slot;
460
461 /* only process this function when driver loads */
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530462 if (!ioc->is_driver_loading)
463 return;
464
465 /* no Bios, return immediately */
466 if (!ioc->bios_pg3.BiosVersion)
Eric Moore635374e2009-03-09 01:21:12 -0600467 return;
468
469 if (!is_raid) {
470 sas_device = device;
471 sas_address = sas_device->sas_address;
472 device_name = sas_device->device_name;
473 enclosure_logical_id = sas_device->enclosure_logical_id;
474 slot = sas_device->slot;
475 } else {
476 raid_device = device;
477 sas_address = raid_device->wwid;
478 device_name = 0;
479 enclosure_logical_id = 0;
480 slot = 0;
481 }
482
483 if (!ioc->req_boot_device.device) {
484 if (_scsih_is_boot_device(sas_address, device_name,
485 enclosure_logical_id, slot,
486 (ioc->bios_pg2.ReqBootDeviceForm &
487 MPI2_BIOSPAGE2_FORM_MASK),
488 &ioc->bios_pg2.RequestedBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530489 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600490 "%s: req_boot_device(0x%016llx)\n",
491 ioc->name, __func__,
492 (unsigned long long)sas_address));
493 ioc->req_boot_device.device = device;
494 ioc->req_boot_device.is_raid = is_raid;
495 }
496 }
497
498 if (!ioc->req_alt_boot_device.device) {
499 if (_scsih_is_boot_device(sas_address, device_name,
500 enclosure_logical_id, slot,
501 (ioc->bios_pg2.ReqAltBootDeviceForm &
502 MPI2_BIOSPAGE2_FORM_MASK),
503 &ioc->bios_pg2.RequestedAltBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530504 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600505 "%s: req_alt_boot_device(0x%016llx)\n",
506 ioc->name, __func__,
507 (unsigned long long)sas_address));
508 ioc->req_alt_boot_device.device = device;
509 ioc->req_alt_boot_device.is_raid = is_raid;
510 }
511 }
512
513 if (!ioc->current_boot_device.device) {
514 if (_scsih_is_boot_device(sas_address, device_name,
515 enclosure_logical_id, slot,
516 (ioc->bios_pg2.CurrentBootDeviceForm &
517 MPI2_BIOSPAGE2_FORM_MASK),
518 &ioc->bios_pg2.CurrentBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530519 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600520 "%s: current_boot_device(0x%016llx)\n",
521 ioc->name, __func__,
522 (unsigned long long)sas_address));
523 ioc->current_boot_device.device = device;
524 ioc->current_boot_device.is_raid = is_raid;
525 }
526 }
527}
528
529/**
530 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
531 * @ioc: per adapter object
532 * @sas_address: sas address
533 * Context: Calling function should acquire ioc->sas_device_lock
534 *
535 * This searches for sas_device based on sas_address, then return sas_device
536 * object.
537 */
538struct _sas_device *
539mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
540 u64 sas_address)
541{
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530542 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600543
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530544 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
545 if (sas_device->sas_address == sas_address)
546 return sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600547
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530548 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
549 if (sas_device->sas_address == sas_address)
550 return sas_device;
551
552 return NULL;
Eric Moore635374e2009-03-09 01:21:12 -0600553}
554
555/**
556 * _scsih_sas_device_find_by_handle - sas device search
557 * @ioc: per adapter object
558 * @handle: sas device handle (assigned by firmware)
559 * Context: Calling function should acquire ioc->sas_device_lock
560 *
561 * This searches for sas_device based on sas_address, then return sas_device
562 * object.
563 */
564static struct _sas_device *
565_scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
566{
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530567 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600568
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530569 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
570 if (sas_device->handle == handle)
571 return sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600572
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530573 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
574 if (sas_device->handle == handle)
575 return sas_device;
576
577 return NULL;
Eric Moore635374e2009-03-09 01:21:12 -0600578}
579
580/**
581 * _scsih_sas_device_remove - remove sas_device from list.
582 * @ioc: per adapter object
583 * @sas_device: the sas_device object
584 * Context: This function will acquire ioc->sas_device_lock.
585 *
586 * Removing object and freeing associated memory from the ioc->sas_device_list.
587 */
588static void
589_scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
590 struct _sas_device *sas_device)
591{
592 unsigned long flags;
593
Kashyap, Desai980ead32010-04-08 17:55:22 +0530594 if (!sas_device)
595 return;
596
Eric Moore635374e2009-03-09 01:21:12 -0600597 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530598 list_del(&sas_device->list);
599 kfree(sas_device);
Eric Moore635374e2009-03-09 01:21:12 -0600600 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
601}
602
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530603
Eric Moore635374e2009-03-09 01:21:12 -0600604/**
605 * _scsih_sas_device_add - insert sas_device to the list.
606 * @ioc: per adapter object
607 * @sas_device: the sas_device object
608 * Context: This function will acquire ioc->sas_device_lock.
609 *
610 * Adding new object to the ioc->sas_device_list.
611 */
612static void
613_scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
614 struct _sas_device *sas_device)
615{
616 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -0600617
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530618 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600619 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
620 sas_device->handle, (unsigned long long)sas_device->sas_address));
621
622 spin_lock_irqsave(&ioc->sas_device_lock, flags);
623 list_add_tail(&sas_device->list, &ioc->sas_device_list);
624 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
625
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530626 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +0530627 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -0600628 _scsih_sas_device_remove(ioc, sas_device);
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +0530629 } else if (!sas_device->starget) {
630 /* When asyn scanning is enabled, its not possible to remove
631 * devices while scanning is turned on due to an oops in
632 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
633 */
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +0530634 if (!ioc->is_driver_loading) {
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +0530635 mpt2sas_transport_port_remove(ioc,
636 sas_device->sas_address,
637 sas_device->sas_address_parent);
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +0530638 _scsih_sas_device_remove(ioc, sas_device);
639 }
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +0530640 }
Eric Moore635374e2009-03-09 01:21:12 -0600641}
642
643/**
644 * _scsih_sas_device_init_add - insert sas_device to the list.
645 * @ioc: per adapter object
646 * @sas_device: the sas_device object
647 * Context: This function will acquire ioc->sas_device_lock.
648 *
649 * Adding new object at driver load time to the ioc->sas_device_init_list.
650 */
651static void
652_scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
653 struct _sas_device *sas_device)
654{
655 unsigned long flags;
656
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530657 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600658 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
659 sas_device->handle, (unsigned long long)sas_device->sas_address));
660
661 spin_lock_irqsave(&ioc->sas_device_lock, flags);
662 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
Eric Moore635374e2009-03-09 01:21:12 -0600663 _scsih_determine_boot_device(ioc, sas_device, 0);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530664 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -0600665}
666
667/**
Eric Moore635374e2009-03-09 01:21:12 -0600668 * _scsih_raid_device_find_by_id - raid device search
669 * @ioc: per adapter object
670 * @id: sas device target id
671 * @channel: sas device channel
672 * Context: Calling function should acquire ioc->raid_device_lock
673 *
674 * This searches for raid_device based on target id, then return raid_device
675 * object.
676 */
677static struct _raid_device *
678_scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
679{
680 struct _raid_device *raid_device, *r;
681
682 r = NULL;
683 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
684 if (raid_device->id == id && raid_device->channel == channel) {
685 r = raid_device;
686 goto out;
687 }
688 }
689
690 out:
691 return r;
692}
693
694/**
695 * _scsih_raid_device_find_by_handle - raid device search
696 * @ioc: per adapter object
697 * @handle: sas device handle (assigned by firmware)
698 * Context: Calling function should acquire ioc->raid_device_lock
699 *
700 * This searches for raid_device based on handle, then return raid_device
701 * object.
702 */
703static struct _raid_device *
704_scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
705{
706 struct _raid_device *raid_device, *r;
707
708 r = NULL;
709 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
710 if (raid_device->handle != handle)
711 continue;
712 r = raid_device;
713 goto out;
714 }
715
716 out:
717 return r;
718}
719
720/**
721 * _scsih_raid_device_find_by_wwid - raid device search
722 * @ioc: per adapter object
723 * @handle: sas device handle (assigned by firmware)
724 * Context: Calling function should acquire ioc->raid_device_lock
725 *
726 * This searches for raid_device based on wwid, then return raid_device
727 * object.
728 */
729static struct _raid_device *
730_scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
731{
732 struct _raid_device *raid_device, *r;
733
734 r = NULL;
735 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
736 if (raid_device->wwid != wwid)
737 continue;
738 r = raid_device;
739 goto out;
740 }
741
742 out:
743 return r;
744}
745
746/**
747 * _scsih_raid_device_add - add raid_device object
748 * @ioc: per adapter object
749 * @raid_device: raid_device object
750 *
751 * This is added to the raid_device_list link list.
752 */
753static void
754_scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
755 struct _raid_device *raid_device)
756{
757 unsigned long flags;
758
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530759 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600760 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
761 raid_device->handle, (unsigned long long)raid_device->wwid));
762
763 spin_lock_irqsave(&ioc->raid_device_lock, flags);
764 list_add_tail(&raid_device->list, &ioc->raid_device_list);
765 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
766}
767
768/**
769 * _scsih_raid_device_remove - delete raid_device object
770 * @ioc: per adapter object
771 * @raid_device: raid_device object
772 *
Eric Moore635374e2009-03-09 01:21:12 -0600773 */
774static void
775_scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
776 struct _raid_device *raid_device)
777{
778 unsigned long flags;
779
780 spin_lock_irqsave(&ioc->raid_device_lock, flags);
781 list_del(&raid_device->list);
Eric Moore635374e2009-03-09 01:21:12 -0600782 kfree(raid_device);
783 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
784}
785
786/**
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530787 * mpt2sas_scsih_expander_find_by_handle - expander device search
788 * @ioc: per adapter object
789 * @handle: expander handle (assigned by firmware)
790 * Context: Calling function should acquire ioc->sas_device_lock
791 *
792 * This searches for expander device based on handle, then returns the
793 * sas_node object.
794 */
795struct _sas_node *
796mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
797{
798 struct _sas_node *sas_expander, *r;
799
800 r = NULL;
801 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
802 if (sas_expander->handle != handle)
803 continue;
804 r = sas_expander;
805 goto out;
806 }
807 out:
808 return r;
809}
810
811/**
Eric Moore635374e2009-03-09 01:21:12 -0600812 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
813 * @ioc: per adapter object
814 * @sas_address: sas address
815 * Context: Calling function should acquire ioc->sas_node_lock.
816 *
817 * This searches for expander device based on sas_address, then returns the
818 * sas_node object.
819 */
820struct _sas_node *
821mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
822 u64 sas_address)
823{
824 struct _sas_node *sas_expander, *r;
825
826 r = NULL;
827 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
828 if (sas_expander->sas_address != sas_address)
829 continue;
830 r = sas_expander;
831 goto out;
832 }
833 out:
834 return r;
835}
836
837/**
838 * _scsih_expander_node_add - insert expander device to the list.
839 * @ioc: per adapter object
840 * @sas_expander: the sas_device object
841 * Context: This function will acquire ioc->sas_node_lock.
842 *
843 * Adding new object to the ioc->sas_expander_list.
844 *
845 * Return nothing.
846 */
847static void
848_scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
849 struct _sas_node *sas_expander)
850{
851 unsigned long flags;
852
853 spin_lock_irqsave(&ioc->sas_node_lock, flags);
854 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
855 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
856}
857
858/**
859 * _scsih_is_end_device - determines if device is an end device
860 * @device_info: bitfield providing information about the device.
861 * Context: none
862 *
863 * Returns 1 if end device.
864 */
865static int
866_scsih_is_end_device(u32 device_info)
867{
868 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
869 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
870 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
871 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
872 return 1;
873 else
874 return 0;
875}
876
877/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530878 * _scsih_scsi_lookup_get - returns scmd entry
Eric Moore635374e2009-03-09 01:21:12 -0600879 * @ioc: per adapter object
880 * @smid: system request message index
Eric Moore635374e2009-03-09 01:21:12 -0600881 *
882 * Returns the smid stored scmd pointer.
883 */
884static struct scsi_cmnd *
885_scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
886{
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530887 return ioc->scsi_lookup[smid - 1].scmd;
Eric Moore635374e2009-03-09 01:21:12 -0600888}
889
890/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530891 * _scsih_scsi_lookup_get_clear - returns scmd entry
892 * @ioc: per adapter object
893 * @smid: system request message index
894 *
895 * Returns the smid stored scmd pointer.
896 * Then will derefrence the stored scmd pointer.
897 */
898static inline struct scsi_cmnd *
899_scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
900{
901 unsigned long flags;
902 struct scsi_cmnd *scmd;
903
904 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
905 scmd = ioc->scsi_lookup[smid - 1].scmd;
906 ioc->scsi_lookup[smid - 1].scmd = NULL;
907 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
908
909 return scmd;
910}
911
912/**
Eric Moore635374e2009-03-09 01:21:12 -0600913 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
914 * @ioc: per adapter object
915 * @smid: system request message index
916 * @scmd: pointer to scsi command object
917 * Context: This function will acquire ioc->scsi_lookup_lock.
918 *
919 * This will search for a scmd pointer in the scsi_lookup array,
920 * returning the revelent smid. A returned value of zero means invalid.
921 */
922static u16
923_scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
924 *scmd)
925{
926 u16 smid;
927 unsigned long flags;
928 int i;
929
930 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
931 smid = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530932 for (i = 0; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600933 if (ioc->scsi_lookup[i].scmd == scmd) {
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530934 smid = ioc->scsi_lookup[i].smid;
Eric Moore635374e2009-03-09 01:21:12 -0600935 goto out;
936 }
937 }
938 out:
939 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
940 return smid;
941}
942
943/**
944 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
945 * @ioc: per adapter object
946 * @id: target id
947 * @channel: channel
948 * Context: This function will acquire ioc->scsi_lookup_lock.
949 *
950 * This will search for a matching channel:id in the scsi_lookup array,
951 * returning 1 if found.
952 */
953static u8
954_scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
955 int channel)
956{
957 u8 found;
958 unsigned long flags;
959 int i;
960
961 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
962 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530963 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600964 if (ioc->scsi_lookup[i].scmd &&
965 (ioc->scsi_lookup[i].scmd->device->id == id &&
966 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
967 found = 1;
968 goto out;
969 }
970 }
971 out:
972 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
973 return found;
974}
975
976/**
Eric Moore993e0da2009-05-18 13:00:45 -0600977 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
978 * @ioc: per adapter object
979 * @id: target id
980 * @lun: lun number
981 * @channel: channel
982 * Context: This function will acquire ioc->scsi_lookup_lock.
983 *
984 * This will search for a matching channel:id:lun in the scsi_lookup array,
985 * returning 1 if found.
986 */
987static u8
988_scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
989 unsigned int lun, int channel)
990{
991 u8 found;
992 unsigned long flags;
993 int i;
994
995 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
996 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530997 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore993e0da2009-05-18 13:00:45 -0600998 if (ioc->scsi_lookup[i].scmd &&
999 (ioc->scsi_lookup[i].scmd->device->id == id &&
1000 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1001 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1002 found = 1;
1003 goto out;
1004 }
1005 }
1006 out:
1007 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1008 return found;
1009}
1010
1011/**
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301012 * _scsih_get_chain_buffer_tracker - obtain chain tracker
Eric Moore635374e2009-03-09 01:21:12 -06001013 * @ioc: per adapter object
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301014 * @smid: smid associated to an IO request
Eric Moore635374e2009-03-09 01:21:12 -06001015 *
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301016 * Returns chain tracker(from ioc->free_chain_list)
Eric Moore635374e2009-03-09 01:21:12 -06001017 */
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301018static struct chain_tracker *
1019_scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
Eric Moore635374e2009-03-09 01:21:12 -06001020{
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301021 struct chain_tracker *chain_req;
1022 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001023
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301024 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1025 if (list_empty(&ioc->free_chain_list)) {
1026 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
nagalakshmi.nandigama@lsi.comaff132d2011-12-01 07:53:08 +05301027 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not "
1028 "available\n", ioc->name));
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301029 return NULL;
1030 }
1031 chain_req = list_entry(ioc->free_chain_list.next,
1032 struct chain_tracker, tracker_list);
1033 list_del_init(&chain_req->tracker_list);
1034 list_add_tail(&chain_req->tracker_list,
1035 &ioc->scsi_lookup[smid - 1].chain_list);
1036 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1037 return chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001038}
1039
1040/**
1041 * _scsih_build_scatter_gather - main sg creation routine
1042 * @ioc: per adapter object
1043 * @scmd: scsi command
1044 * @smid: system request message index
1045 * Context: none.
1046 *
1047 * The main routine that builds scatter gather table from a given
1048 * scsi request sent via the .queuecommand main handler.
1049 *
1050 * Returns 0 success, anything else error
1051 */
1052static int
1053_scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1054 struct scsi_cmnd *scmd, u16 smid)
1055{
1056 Mpi2SCSIIORequest_t *mpi_request;
1057 dma_addr_t chain_dma;
1058 struct scatterlist *sg_scmd;
1059 void *sg_local, *chain;
1060 u32 chain_offset;
1061 u32 chain_length;
1062 u32 chain_flags;
FUJITA Tomonoribb789d02010-03-09 11:09:50 +09001063 int sges_left;
Eric Moore635374e2009-03-09 01:21:12 -06001064 u32 sges_in_segment;
1065 u32 sgl_flags;
1066 u32 sgl_flags_last_element;
1067 u32 sgl_flags_end_buffer;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301068 struct chain_tracker *chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001069
1070 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1071
1072 /* init scatter gather flags */
1073 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1074 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1075 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1076 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1077 << MPI2_SGE_FLAGS_SHIFT;
1078 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1079 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1080 << MPI2_SGE_FLAGS_SHIFT;
1081 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1082
1083 sg_scmd = scsi_sglist(scmd);
1084 sges_left = scsi_dma_map(scmd);
FUJITA Tomonoribb789d02010-03-09 11:09:50 +09001085 if (sges_left < 0) {
Eric Moore635374e2009-03-09 01:21:12 -06001086 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1087 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1088 return -ENOMEM;
1089 }
1090
1091 sg_local = &mpi_request->SGL;
1092 sges_in_segment = ioc->max_sges_in_main_message;
1093 if (sges_left <= sges_in_segment)
1094 goto fill_in_last_segment;
1095
1096 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1097 (sges_in_segment * ioc->sge_size))/4;
1098
1099 /* fill in main message segment when there is a chain following */
1100 while (sges_in_segment) {
1101 if (sges_in_segment == 1)
1102 ioc->base_add_sg_single(sg_local,
1103 sgl_flags_last_element | sg_dma_len(sg_scmd),
1104 sg_dma_address(sg_scmd));
1105 else
1106 ioc->base_add_sg_single(sg_local, sgl_flags |
1107 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1108 sg_scmd = sg_next(sg_scmd);
1109 sg_local += ioc->sge_size;
1110 sges_left--;
1111 sges_in_segment--;
1112 }
1113
1114 /* initializing the chain flags and pointers */
1115 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301116 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1117 if (!chain_req)
1118 return -1;
1119 chain = chain_req->chain_buffer;
1120 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001121 do {
1122 sges_in_segment = (sges_left <=
1123 ioc->max_sges_in_chain_message) ? sges_left :
1124 ioc->max_sges_in_chain_message;
1125 chain_offset = (sges_left == sges_in_segment) ?
1126 0 : (sges_in_segment * ioc->sge_size)/4;
1127 chain_length = sges_in_segment * ioc->sge_size;
1128 if (chain_offset) {
1129 chain_offset = chain_offset <<
1130 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1131 chain_length += ioc->sge_size;
1132 }
1133 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1134 chain_length, chain_dma);
1135 sg_local = chain;
1136 if (!chain_offset)
1137 goto fill_in_last_segment;
1138
1139 /* fill in chain segments */
1140 while (sges_in_segment) {
1141 if (sges_in_segment == 1)
1142 ioc->base_add_sg_single(sg_local,
1143 sgl_flags_last_element |
1144 sg_dma_len(sg_scmd),
1145 sg_dma_address(sg_scmd));
1146 else
1147 ioc->base_add_sg_single(sg_local, sgl_flags |
1148 sg_dma_len(sg_scmd),
1149 sg_dma_address(sg_scmd));
1150 sg_scmd = sg_next(sg_scmd);
1151 sg_local += ioc->sge_size;
1152 sges_left--;
1153 sges_in_segment--;
1154 }
1155
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301156 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1157 if (!chain_req)
1158 return -1;
1159 chain = chain_req->chain_buffer;
1160 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001161 } while (1);
1162
1163
1164 fill_in_last_segment:
1165
1166 /* fill the last segment */
1167 while (sges_left) {
1168 if (sges_left == 1)
1169 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1170 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1171 else
1172 ioc->base_add_sg_single(sg_local, sgl_flags |
1173 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1174 sg_scmd = sg_next(sg_scmd);
1175 sg_local += ioc->sge_size;
1176 sges_left--;
1177 }
1178
1179 return 0;
1180}
1181
1182/**
Christoph Hellwig286c9402014-11-13 15:11:59 +01001183 * _scsih_change_queue_depth - setting device queue depth
Eric Moore635374e2009-03-09 01:21:12 -06001184 * @sdev: scsi device struct
1185 * @qdepth: requested queue depth
1186 *
Christoph Hellwig286c9402014-11-13 15:11:59 +01001187 * Returns queue depth.
Eric Moore635374e2009-03-09 01:21:12 -06001188 */
Christoph Hellwig286c9402014-11-13 15:11:59 +01001189static int
1190_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
Eric Moore635374e2009-03-09 01:21:12 -06001191{
1192 struct Scsi_Host *shost = sdev->host;
1193 int max_depth;
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301194 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1195 struct MPT2SAS_DEVICE *sas_device_priv_data;
1196 struct MPT2SAS_TARGET *sas_target_priv_data;
1197 struct _sas_device *sas_device;
1198 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001199
1200 max_depth = shost->can_queue;
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301201
1202 /* limit max device queue for SATA to 32 */
1203 sas_device_priv_data = sdev->hostdata;
1204 if (!sas_device_priv_data)
1205 goto not_sata;
1206 sas_target_priv_data = sas_device_priv_data->sas_target;
1207 if (!sas_target_priv_data)
1208 goto not_sata;
1209 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1210 goto not_sata;
1211 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1212 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1213 sas_device_priv_data->sas_target->sas_address);
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301214 if (sas_device && sas_device->device_info &
1215 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1216 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301217 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301218
1219 not_sata:
Eric Moore635374e2009-03-09 01:21:12 -06001220 if (!sdev->tagged_supported)
1221 max_depth = 1;
1222 if (qdepth > max_depth)
1223 qdepth = max_depth;
Christoph Hellwig286c9402014-11-13 15:11:59 +01001224 return scsi_change_queue_depth(sdev, qdepth);
Eric Moore635374e2009-03-09 01:21:12 -06001225}
1226
1227/**
Eric Moored5d135b2009-05-18 13:02:08 -06001228 * _scsih_target_alloc - target add routine
Eric Moore635374e2009-03-09 01:21:12 -06001229 * @starget: scsi target struct
1230 *
1231 * Returns 0 if ok. Any other return is assumed to be an error and
1232 * the device is ignored.
1233 */
1234static int
Eric Moored5d135b2009-05-18 13:02:08 -06001235_scsih_target_alloc(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001236{
1237 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1238 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1239 struct MPT2SAS_TARGET *sas_target_priv_data;
1240 struct _sas_device *sas_device;
1241 struct _raid_device *raid_device;
1242 unsigned long flags;
1243 struct sas_rphy *rphy;
1244
Joe Lawrencefeafe7c2014-06-25 17:03:14 -04001245 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1246 GFP_KERNEL);
Eric Moore635374e2009-03-09 01:21:12 -06001247 if (!sas_target_priv_data)
1248 return -ENOMEM;
1249
1250 starget->hostdata = sas_target_priv_data;
1251 sas_target_priv_data->starget = starget;
1252 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1253
1254 /* RAID volumes */
1255 if (starget->channel == RAID_CHANNEL) {
1256 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1257 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1258 starget->channel);
1259 if (raid_device) {
1260 sas_target_priv_data->handle = raid_device->handle;
1261 sas_target_priv_data->sas_address = raid_device->wwid;
1262 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301263 if (ioc->is_warpdrive)
1264 sas_target_priv_data->raid_device = raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06001265 raid_device->starget = starget;
1266 }
1267 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1268 return 0;
1269 }
1270
1271 /* sas/sata devices */
1272 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1273 rphy = dev_to_rphy(starget->dev.parent);
1274 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1275 rphy->identify.sas_address);
1276
1277 if (sas_device) {
1278 sas_target_priv_data->handle = sas_device->handle;
1279 sas_target_priv_data->sas_address = sas_device->sas_address;
1280 sas_device->starget = starget;
1281 sas_device->id = starget->id;
1282 sas_device->channel = starget->channel;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05301283 if (test_bit(sas_device->handle, ioc->pd_handles))
Eric Moore635374e2009-03-09 01:21:12 -06001284 sas_target_priv_data->flags |=
1285 MPT_TARGET_FLAGS_RAID_COMPONENT;
1286 }
1287 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1288
1289 return 0;
1290}
1291
1292/**
Eric Moored5d135b2009-05-18 13:02:08 -06001293 * _scsih_target_destroy - target destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001294 * @starget: scsi target struct
1295 *
1296 * Returns nothing.
1297 */
1298static void
Eric Moored5d135b2009-05-18 13:02:08 -06001299_scsih_target_destroy(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001300{
1301 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1302 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1303 struct MPT2SAS_TARGET *sas_target_priv_data;
1304 struct _sas_device *sas_device;
1305 struct _raid_device *raid_device;
1306 unsigned long flags;
1307 struct sas_rphy *rphy;
1308
1309 sas_target_priv_data = starget->hostdata;
1310 if (!sas_target_priv_data)
1311 return;
1312
1313 if (starget->channel == RAID_CHANNEL) {
1314 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1315 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1316 starget->channel);
1317 if (raid_device) {
1318 raid_device->starget = NULL;
1319 raid_device->sdev = NULL;
1320 }
1321 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1322 goto out;
1323 }
1324
1325 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1326 rphy = dev_to_rphy(starget->dev.parent);
1327 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1328 rphy->identify.sas_address);
Eric Moore8901cbb2009-04-21 15:41:32 -06001329 if (sas_device && (sas_device->starget == starget) &&
1330 (sas_device->id == starget->id) &&
1331 (sas_device->channel == starget->channel))
Eric Moore635374e2009-03-09 01:21:12 -06001332 sas_device->starget = NULL;
1333
1334 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1335
1336 out:
1337 kfree(sas_target_priv_data);
1338 starget->hostdata = NULL;
1339}
1340
1341/**
Eric Moored5d135b2009-05-18 13:02:08 -06001342 * _scsih_slave_alloc - device add routine
Eric Moore635374e2009-03-09 01:21:12 -06001343 * @sdev: scsi device struct
1344 *
1345 * Returns 0 if ok. Any other return is assumed to be an error and
1346 * the device is ignored.
1347 */
1348static int
Eric Moored5d135b2009-05-18 13:02:08 -06001349_scsih_slave_alloc(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001350{
1351 struct Scsi_Host *shost;
1352 struct MPT2SAS_ADAPTER *ioc;
1353 struct MPT2SAS_TARGET *sas_target_priv_data;
1354 struct MPT2SAS_DEVICE *sas_device_priv_data;
1355 struct scsi_target *starget;
1356 struct _raid_device *raid_device;
Sreekanth Reddy63e359d2013-07-25 11:32:51 +05301357 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -06001358 unsigned long flags;
1359
Joe Lawrencefeafe7c2014-06-25 17:03:14 -04001360 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1361 GFP_KERNEL);
Eric Moore635374e2009-03-09 01:21:12 -06001362 if (!sas_device_priv_data)
1363 return -ENOMEM;
1364
1365 sas_device_priv_data->lun = sdev->lun;
1366 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1367
1368 starget = scsi_target(sdev);
1369 sas_target_priv_data = starget->hostdata;
1370 sas_target_priv_data->num_luns++;
1371 sas_device_priv_data->sas_target = sas_target_priv_data;
1372 sdev->hostdata = sas_device_priv_data;
1373 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1374 sdev->no_uld_attach = 1;
1375
1376 shost = dev_to_shost(&starget->dev);
1377 ioc = shost_priv(shost);
1378 if (starget->channel == RAID_CHANNEL) {
1379 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1380 raid_device = _scsih_raid_device_find_by_id(ioc,
1381 starget->id, starget->channel);
1382 if (raid_device)
1383 raid_device->sdev = sdev; /* raid is single lun */
1384 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06001385 }
1386
Sreekanth Reddy63e359d2013-07-25 11:32:51 +05301387 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1388 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1389 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1390 sas_target_priv_data->sas_address);
1391 if (sas_device && (sas_device->starget == NULL)) {
1392 sdev_printk(KERN_INFO, sdev,
1393 "%s : sas_device->starget set to starget @ %d\n",
1394 __func__, __LINE__);
1395 sas_device->starget = starget;
1396 }
1397 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1398 }
1399
Eric Moore635374e2009-03-09 01:21:12 -06001400 return 0;
1401}
1402
1403/**
Eric Moored5d135b2009-05-18 13:02:08 -06001404 * _scsih_slave_destroy - device destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001405 * @sdev: scsi device struct
1406 *
1407 * Returns nothing.
1408 */
1409static void
Eric Moored5d135b2009-05-18 13:02:08 -06001410_scsih_slave_destroy(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001411{
1412 struct MPT2SAS_TARGET *sas_target_priv_data;
1413 struct scsi_target *starget;
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301414 struct Scsi_Host *shost;
1415 struct MPT2SAS_ADAPTER *ioc;
1416 struct _sas_device *sas_device;
1417 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001418
1419 if (!sdev->hostdata)
1420 return;
1421
1422 starget = scsi_target(sdev);
1423 sas_target_priv_data = starget->hostdata;
1424 sas_target_priv_data->num_luns--;
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301425
1426 shost = dev_to_shost(&starget->dev);
1427 ioc = shost_priv(shost);
1428
1429 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1430 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1431 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1432 sas_target_priv_data->sas_address);
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +05301433 if (sas_device && !sas_target_priv_data->num_luns)
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301434 sas_device->starget = NULL;
1435 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1436 }
1437
Eric Moore635374e2009-03-09 01:21:12 -06001438 kfree(sdev->hostdata);
1439 sdev->hostdata = NULL;
1440}
1441
1442/**
Eric Moored5d135b2009-05-18 13:02:08 -06001443 * _scsih_display_sata_capabilities - sata capabilities
Eric Moore635374e2009-03-09 01:21:12 -06001444 * @ioc: per adapter object
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301445 * @handle: device handle
Eric Moore635374e2009-03-09 01:21:12 -06001446 * @sdev: scsi device struct
1447 */
1448static void
Eric Moored5d135b2009-05-18 13:02:08 -06001449_scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301450 u16 handle, struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001451{
1452 Mpi2ConfigReply_t mpi_reply;
1453 Mpi2SasDevicePage0_t sas_device_pg0;
1454 u32 ioc_status;
1455 u16 flags;
1456 u32 device_info;
1457
1458 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301459 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06001460 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1461 ioc->name, __FILE__, __LINE__, __func__);
1462 return;
1463 }
1464
1465 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1466 MPI2_IOCSTATUS_MASK;
1467 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1468 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1469 ioc->name, __FILE__, __LINE__, __func__);
1470 return;
1471 }
1472
1473 flags = le16_to_cpu(sas_device_pg0.Flags);
Kashyap, Desaie94f6742010-03-17 16:24:52 +05301474 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
Eric Moore635374e2009-03-09 01:21:12 -06001475
1476 sdev_printk(KERN_INFO, sdev,
1477 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1478 "sw_preserve(%s)\n",
1479 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1480 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1481 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1482 "n",
1483 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1484 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1485 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1486}
1487
1488/**
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301489 * _scsih_is_raid - return boolean indicating device is raid volume
1490 * @dev the device struct object
1491 */
1492static int
1493_scsih_is_raid(struct device *dev)
1494{
1495 struct scsi_device *sdev = to_scsi_device(dev);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301496 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301497
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301498 if (ioc->is_warpdrive)
1499 return 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301500 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1501}
1502
1503/**
1504 * _scsih_get_resync - get raid volume resync percent complete
1505 * @dev the device struct object
1506 */
1507static void
1508_scsih_get_resync(struct device *dev)
1509{
1510 struct scsi_device *sdev = to_scsi_device(dev);
1511 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1512 static struct _raid_device *raid_device;
1513 unsigned long flags;
1514 Mpi2RaidVolPage0_t vol_pg0;
1515 Mpi2ConfigReply_t mpi_reply;
1516 u32 volume_status_flags;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301517 u8 percent_complete;
1518 u16 handle;
1519
1520 percent_complete = 0;
1521 handle = 0;
1522 if (ioc->is_warpdrive)
1523 goto out;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301524
1525 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1526 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1527 sdev->channel);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301528 if (raid_device) {
1529 handle = raid_device->handle;
1530 percent_complete = raid_device->percent_complete;
1531 }
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301532 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1533
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301534 if (!handle)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301535 goto out;
1536
1537 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301538 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301539 sizeof(Mpi2RaidVolPage0_t))) {
1540 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1541 ioc->name, __FILE__, __LINE__, __func__);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301542 percent_complete = 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301543 goto out;
1544 }
1545
1546 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301547 if (!(volume_status_flags &
1548 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1549 percent_complete = 0;
1550
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301551 out:
1552 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1553}
1554
1555/**
1556 * _scsih_get_state - get raid volume level
1557 * @dev the device struct object
1558 */
1559static void
1560_scsih_get_state(struct device *dev)
1561{
1562 struct scsi_device *sdev = to_scsi_device(dev);
1563 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1564 static struct _raid_device *raid_device;
1565 unsigned long flags;
1566 Mpi2RaidVolPage0_t vol_pg0;
1567 Mpi2ConfigReply_t mpi_reply;
1568 u32 volstate;
1569 enum raid_state state = RAID_STATE_UNKNOWN;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301570 u16 handle = 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301571
1572 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1573 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1574 sdev->channel);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301575 if (raid_device)
1576 handle = raid_device->handle;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301577 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1578
1579 if (!raid_device)
1580 goto out;
1581
1582 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301583 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301584 sizeof(Mpi2RaidVolPage0_t))) {
1585 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1586 ioc->name, __FILE__, __LINE__, __func__);
1587 goto out;
1588 }
1589
1590 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1591 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1592 state = RAID_STATE_RESYNCING;
1593 goto out;
1594 }
1595
1596 switch (vol_pg0.VolumeState) {
1597 case MPI2_RAID_VOL_STATE_OPTIMAL:
1598 case MPI2_RAID_VOL_STATE_ONLINE:
1599 state = RAID_STATE_ACTIVE;
1600 break;
1601 case MPI2_RAID_VOL_STATE_DEGRADED:
1602 state = RAID_STATE_DEGRADED;
1603 break;
1604 case MPI2_RAID_VOL_STATE_FAILED:
1605 case MPI2_RAID_VOL_STATE_MISSING:
1606 state = RAID_STATE_OFFLINE;
1607 break;
1608 }
1609 out:
1610 raid_set_state(mpt2sas_raid_template, dev, state);
1611}
1612
1613/**
1614 * _scsih_set_level - set raid level
1615 * @sdev: scsi device struct
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301616 * @volume_type: volume type
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301617 */
1618static void
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301619_scsih_set_level(struct scsi_device *sdev, u8 volume_type)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301620{
1621 enum raid_level level = RAID_LEVEL_UNKNOWN;
1622
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301623 switch (volume_type) {
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301624 case MPI2_RAID_VOL_TYPE_RAID0:
1625 level = RAID_LEVEL_0;
1626 break;
1627 case MPI2_RAID_VOL_TYPE_RAID10:
1628 level = RAID_LEVEL_10;
1629 break;
1630 case MPI2_RAID_VOL_TYPE_RAID1E:
1631 level = RAID_LEVEL_1E;
1632 break;
1633 case MPI2_RAID_VOL_TYPE_RAID1:
1634 level = RAID_LEVEL_1;
1635 break;
1636 }
1637
1638 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1639}
1640
1641/**
Eric Moore635374e2009-03-09 01:21:12 -06001642 * _scsih_get_volume_capabilities - volume capabilities
1643 * @ioc: per adapter object
1644 * @sas_device: the raid_device object
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301645 *
1646 * Returns 0 for success, else 1
Eric Moore635374e2009-03-09 01:21:12 -06001647 */
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301648static int
Eric Moore635374e2009-03-09 01:21:12 -06001649_scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1650 struct _raid_device *raid_device)
1651{
1652 Mpi2RaidVolPage0_t *vol_pg0;
1653 Mpi2RaidPhysDiskPage0_t pd_pg0;
1654 Mpi2SasDevicePage0_t sas_device_pg0;
1655 Mpi2ConfigReply_t mpi_reply;
1656 u16 sz;
1657 u8 num_pds;
1658
1659 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1660 &num_pds)) || !num_pds) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301661 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1662 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1663 __func__));
1664 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001665 }
1666
1667 raid_device->num_pds = num_pds;
1668 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1669 sizeof(Mpi2RaidVol0PhysDisk_t));
1670 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1671 if (!vol_pg0) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301672 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1673 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1674 __func__));
1675 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001676 }
1677
1678 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1679 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301680 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1681 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1682 __func__));
Eric Moore635374e2009-03-09 01:21:12 -06001683 kfree(vol_pg0);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301684 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001685 }
1686
1687 raid_device->volume_type = vol_pg0->VolumeType;
1688
1689 /* figure out what the underlying devices are by
1690 * obtaining the device_info bits for the 1st device
1691 */
1692 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1693 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1694 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1695 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1696 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1697 le16_to_cpu(pd_pg0.DevHandle)))) {
1698 raid_device->device_info =
1699 le32_to_cpu(sas_device_pg0.DeviceInfo);
1700 }
1701 }
1702
1703 kfree(vol_pg0);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301704 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06001705}
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301706/**
1707 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1708 * @ioc: per adapter object
1709 */
1710static void
1711_scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1712{
1713 Mpi2RaidVolPage1_t vol_pg1;
1714 Mpi2ConfigReply_t mpi_reply;
1715 struct _raid_device *raid_device;
1716 u16 handle;
1717 u16 ioc_status;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301718 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301719
1720 handle = 0xFFFF;
1721 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1722 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1723 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1724 MPI2_IOCSTATUS_MASK;
1725 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1726 break;
1727 handle = le16_to_cpu(vol_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301728 spin_lock_irqsave(&ioc->raid_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301729 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1730 if (raid_device)
1731 raid_device->direct_io_enabled = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301732 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301733 }
1734 return;
1735}
1736
1737
1738/**
1739 * _scsih_get_num_volumes - Get number of volumes in the ioc
1740 * @ioc: per adapter object
1741 */
1742static u8
1743_scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1744{
1745 Mpi2RaidVolPage1_t vol_pg1;
1746 Mpi2ConfigReply_t mpi_reply;
1747 u16 handle;
1748 u8 vol_cnt = 0;
1749 u16 ioc_status;
1750
1751 handle = 0xFFFF;
1752 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1753 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1754 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1755 MPI2_IOCSTATUS_MASK;
1756 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1757 break;
1758 vol_cnt++;
1759 handle = le16_to_cpu(vol_pg1.DevHandle);
1760 }
1761 return vol_cnt;
1762}
1763
1764
1765/**
1766 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1767 * @ioc: per adapter object
1768 * @raid_device: the raid_device object
1769 */
1770static void
1771_scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1772 struct _raid_device *raid_device)
1773{
1774 Mpi2RaidVolPage0_t *vol_pg0;
1775 Mpi2RaidPhysDiskPage0_t pd_pg0;
1776 Mpi2ConfigReply_t mpi_reply;
1777 u16 sz;
1778 u8 num_pds, count;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301779 unsigned long stripe_sz, block_sz;
1780 u8 stripe_exp, block_exp;
1781 u64 dev_max_lba;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301782
1783 if (!ioc->is_warpdrive)
1784 return;
1785
1786 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1787 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1788 "globally as drives are exposed\n", ioc->name);
1789 return;
1790 }
1791 if (_scsih_get_num_volumes(ioc) > 1) {
1792 _scsih_disable_ddio(ioc);
1793 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1794 "globally as number of drives > 1\n", ioc->name);
1795 return;
1796 }
1797 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1798 &num_pds)) || !num_pds) {
1799 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1800 "Failure in computing number of drives\n", ioc->name);
1801 return;
1802 }
1803
1804 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1805 sizeof(Mpi2RaidVol0PhysDisk_t));
1806 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1807 if (!vol_pg0) {
1808 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1809 "Memory allocation failure for RVPG0\n", ioc->name);
1810 return;
1811 }
1812
1813 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1814 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1815 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1816 "Failure in retrieving RVPG0\n", ioc->name);
1817 kfree(vol_pg0);
1818 return;
1819 }
1820
1821 /*
1822 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1823 * assumed for WARPDRIVE, disable direct I/O
1824 */
1825 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1826 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1827 "for the drive with handle(0x%04x): num_mem=%d, "
1828 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1829 num_pds, MPT_MAX_WARPDRIVE_PDS);
1830 kfree(vol_pg0);
1831 return;
1832 }
1833 for (count = 0; count < num_pds; count++) {
1834 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1835 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1836 vol_pg0->PhysDisk[count].PhysDiskNum) ||
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05301837 le16_to_cpu(pd_pg0.DevHandle) ==
1838 MPT2SAS_INVALID_DEVICE_HANDLE) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301839 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1840 "disabled for the drive with handle(0x%04x) member"
1841 "handle retrieval failed for member number=%d\n",
1842 ioc->name, raid_device->handle,
1843 vol_pg0->PhysDisk[count].PhysDiskNum);
1844 goto out_error;
1845 }
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301846 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1847 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
1848 if (dev_max_lba >> 32) {
1849 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1850 "disabled for the drive with handle(0x%04x) member"
1851 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1852 ioc->name, raid_device->handle,
1853 le16_to_cpu(pd_pg0.DevHandle),
1854 (unsigned long long)dev_max_lba);
1855 goto out_error;
1856 }
1857
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301858 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1859 }
1860
1861 /*
1862 * Assumption for WD: Direct I/O is not supported if the volume is
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301863 * not RAID0
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301864 */
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301865 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301866 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1867 "for the drive with handle(0x%04x): type=%d, "
1868 "s_sz=%uK, blk_size=%u\n", ioc->name,
1869 raid_device->handle, raid_device->volume_type,
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301870 (le32_to_cpu(vol_pg0->StripeSize) *
1871 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301872 le16_to_cpu(vol_pg0->BlockSize));
1873 goto out_error;
1874 }
1875
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301876 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301877 stripe_exp = find_first_bit(&stripe_sz, 32);
1878 if (stripe_exp == 32) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301879 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301880 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301881 ioc->name, raid_device->handle,
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301882 (le32_to_cpu(vol_pg0->StripeSize) *
1883 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301884 goto out_error;
1885 }
1886 raid_device->stripe_exponent = stripe_exp;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301887 block_sz = le16_to_cpu(vol_pg0->BlockSize);
1888 block_exp = find_first_bit(&block_sz, 16);
1889 if (block_exp == 16) {
1890 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1891 "for the drive with handle(0x%04x) invalid block sz %u\n",
1892 ioc->name, raid_device->handle,
1893 le16_to_cpu(vol_pg0->BlockSize));
1894 goto out_error;
1895 }
1896 raid_device->block_exponent = block_exp;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301897 raid_device->direct_io_enabled = 1;
1898
1899 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1900 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1901 /*
1902 * WARPDRIVE: Though the following fields are not used for direct IO,
1903 * stored for future purpose:
1904 */
1905 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1906 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1907 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1908
1909
1910 kfree(vol_pg0);
1911 return;
1912
1913out_error:
1914 raid_device->direct_io_enabled = 0;
1915 for (count = 0; count < num_pds; count++)
1916 raid_device->pd_handle[count] = 0;
1917 kfree(vol_pg0);
1918 return;
1919}
Eric Moore635374e2009-03-09 01:21:12 -06001920
1921/**
Kashyap, Desai84f0b042009-12-16 18:56:28 +05301922 * _scsih_enable_tlr - setting TLR flags
1923 * @ioc: per adapter object
1924 * @sdev: scsi device struct
1925 *
1926 * Enabling Transaction Layer Retries for tape devices when
1927 * vpd page 0x90 is present
1928 *
1929 */
1930static void
1931_scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1932{
1933 /* only for TAPE */
1934 if (sdev->type != TYPE_TAPE)
1935 return;
1936
1937 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1938 return;
1939
1940 sas_enable_tlr(sdev);
1941 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1942 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1943 return;
1944
1945}
1946
1947/**
Eric Moored5d135b2009-05-18 13:02:08 -06001948 * _scsih_slave_configure - device configure routine.
Eric Moore635374e2009-03-09 01:21:12 -06001949 * @sdev: scsi device struct
1950 *
1951 * Returns 0 if ok. Any other return is assumed to be an error and
1952 * the device is ignored.
1953 */
1954static int
Eric Moored5d135b2009-05-18 13:02:08 -06001955_scsih_slave_configure(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001956{
1957 struct Scsi_Host *shost = sdev->host;
1958 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1959 struct MPT2SAS_DEVICE *sas_device_priv_data;
1960 struct MPT2SAS_TARGET *sas_target_priv_data;
1961 struct _sas_device *sas_device;
1962 struct _raid_device *raid_device;
1963 unsigned long flags;
1964 int qdepth;
1965 u8 ssp_target = 0;
1966 char *ds = "";
1967 char *r_level = "";
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301968 u16 handle, volume_handle = 0;
1969 u64 volume_wwid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06001970
1971 qdepth = 1;
1972 sas_device_priv_data = sdev->hostdata;
1973 sas_device_priv_data->configured_lun = 1;
1974 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1975 sas_target_priv_data = sas_device_priv_data->sas_target;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301976 handle = sas_target_priv_data->handle;
Eric Moore635374e2009-03-09 01:21:12 -06001977
1978 /* raid volume handling */
1979 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1980
1981 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301982 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06001983 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1984 if (!raid_device) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301985 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1986 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1987 __LINE__, __func__));
1988 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001989 }
1990
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301991 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1992 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1993 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1994 __LINE__, __func__));
1995 return 1;
1996 }
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301997 /*
1998 * WARPDRIVE: Initialize the required data for Direct IO
1999 */
2000 _scsih_init_warpdrive_properties(ioc, raid_device);
2001
Eric Moore635374e2009-03-09 01:21:12 -06002002 /* RAID Queue Depth Support
2003 * IS volume = underlying qdepth of drive type, either
2004 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2005 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2006 */
2007 if (raid_device->device_info &
2008 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2009 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2010 ds = "SSP";
2011 } else {
2012 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2013 if (raid_device->device_info &
2014 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2015 ds = "SATA";
2016 else
2017 ds = "STP";
2018 }
2019
2020 switch (raid_device->volume_type) {
2021 case MPI2_RAID_VOL_TYPE_RAID0:
2022 r_level = "RAID0";
2023 break;
2024 case MPI2_RAID_VOL_TYPE_RAID1E:
2025 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
Kashyap, Desaied79f122009-08-20 13:23:49 +05302026 if (ioc->manu_pg10.OEMIdentifier &&
Kashyap, Desaic97951e2011-06-14 10:54:56 +05302027 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
Kashyap, Desaied79f122009-08-20 13:23:49 +05302028 MFG10_GF0_R10_DISPLAY) &&
2029 !(raid_device->num_pds % 2))
2030 r_level = "RAID10";
2031 else
2032 r_level = "RAID1E";
Eric Moore635374e2009-03-09 01:21:12 -06002033 break;
2034 case MPI2_RAID_VOL_TYPE_RAID1:
2035 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2036 r_level = "RAID1";
2037 break;
2038 case MPI2_RAID_VOL_TYPE_RAID10:
2039 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2040 r_level = "RAID10";
2041 break;
2042 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2043 default:
2044 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2045 r_level = "RAIDX";
2046 break;
2047 }
2048
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302049 if (!ioc->hide_ir_msg)
2050 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2051 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2052 r_level, raid_device->handle,
2053 (unsigned long long)raid_device->wwid,
2054 raid_device->num_pds, ds);
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01002055 _scsih_change_queue_depth(sdev, qdepth);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05302056 /* raid transport support */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302057 if (!ioc->is_warpdrive)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302058 _scsih_set_level(sdev, raid_device->volume_type);
Eric Moore635374e2009-03-09 01:21:12 -06002059 return 0;
2060 }
2061
2062 /* non-raid handling */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302063 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2064 if (mpt2sas_config_get_volume_handle(ioc, handle,
2065 &volume_handle)) {
2066 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2067 "failure at %s:%d/%s()!\n", ioc->name,
2068 __FILE__, __LINE__, __func__));
2069 return 1;
2070 }
2071 if (volume_handle && mpt2sas_config_get_volume_wwid(ioc,
2072 volume_handle, &volume_wwid)) {
2073 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2074 "failure at %s:%d/%s()!\n", ioc->name,
2075 __FILE__, __LINE__, __func__));
2076 return 1;
2077 }
2078 }
2079
Eric Moore635374e2009-03-09 01:21:12 -06002080 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2081 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2082 sas_device_priv_data->sas_target->sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302083 if (!sas_device) {
2084 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302085 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302086 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2087 __LINE__, __func__));
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302088 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002089 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302090 sas_device->volume_handle = volume_handle;
2091 sas_device->volume_wwid = volume_wwid;
2092 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2093 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2094 ssp_target = 1;
2095 ds = "SSP";
2096 } else {
2097 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2098 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2099 ds = "STP";
2100 else if (sas_device->device_info &
2101 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2102 ds = "SATA";
2103 }
2104 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2105 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2106 ds, sas_device->handle,
2107 (unsigned long long)sas_device->sas_address,
2108 sas_device->phy,
2109 (unsigned long long)sas_device->device_name);
2110 sdev_printk(KERN_INFO, sdev, "%s: "
2111 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2112 (unsigned long long) sas_device->enclosure_logical_id,
2113 sas_device->slot);
2114
2115 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2116 if (!ssp_target)
2117 _scsih_display_sata_capabilities(ioc, handle, sdev);
2118
Eric Moore635374e2009-03-09 01:21:12 -06002119
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01002120 _scsih_change_queue_depth(sdev, qdepth);
Eric Moore635374e2009-03-09 01:21:12 -06002121
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302122 if (ssp_target) {
Eric Moore635374e2009-03-09 01:21:12 -06002123 sas_read_port_mode_page(sdev);
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302124 _scsih_enable_tlr(ioc, sdev);
2125 }
Eric Moore635374e2009-03-09 01:21:12 -06002126 return 0;
2127}
2128
2129/**
Eric Moored5d135b2009-05-18 13:02:08 -06002130 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
Eric Moore635374e2009-03-09 01:21:12 -06002131 * @sdev: scsi device struct
2132 * @bdev: pointer to block device context
2133 * @capacity: device size (in 512 byte sectors)
2134 * @params: three element array to place output:
2135 * params[0] number of heads (max 255)
2136 * params[1] number of sectors (max 63)
2137 * params[2] number of cylinders
2138 *
2139 * Return nothing.
2140 */
2141static int
Eric Moored5d135b2009-05-18 13:02:08 -06002142_scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
Eric Moore635374e2009-03-09 01:21:12 -06002143 sector_t capacity, int params[])
2144{
2145 int heads;
2146 int sectors;
2147 sector_t cylinders;
2148 ulong dummy;
2149
2150 heads = 64;
2151 sectors = 32;
2152
2153 dummy = heads * sectors;
2154 cylinders = capacity;
2155 sector_div(cylinders, dummy);
2156
2157 /*
2158 * Handle extended translation size for logical drives
2159 * > 1Gb
2160 */
2161 if ((ulong)capacity >= 0x200000) {
2162 heads = 255;
2163 sectors = 63;
2164 dummy = heads * sectors;
2165 cylinders = capacity;
2166 sector_div(cylinders, dummy);
2167 }
2168
2169 /* return result */
2170 params[0] = heads;
2171 params[1] = sectors;
2172 params[2] = cylinders;
2173
2174 return 0;
2175}
2176
2177/**
2178 * _scsih_response_code - translation of device response code
2179 * @ioc: per adapter object
2180 * @response_code: response code returned by the device
2181 *
2182 * Return nothing.
2183 */
2184static void
2185_scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2186{
2187 char *desc;
2188
2189 switch (response_code) {
2190 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2191 desc = "task management request completed";
2192 break;
2193 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2194 desc = "invalid frame";
2195 break;
2196 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2197 desc = "task management request not supported";
2198 break;
2199 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2200 desc = "task management request failed";
2201 break;
2202 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2203 desc = "task management request succeeded";
2204 break;
2205 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2206 desc = "invalid lun";
2207 break;
2208 case 0xA:
2209 desc = "overlapped tag attempted";
2210 break;
2211 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2212 desc = "task queued, however not sent to target";
2213 break;
2214 default:
2215 desc = "unknown";
2216 break;
2217 }
2218 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2219 ioc->name, response_code, desc);
2220}
2221
2222/**
Eric Moored5d135b2009-05-18 13:02:08 -06002223 * _scsih_tm_done - tm completion routine
Eric Moore635374e2009-03-09 01:21:12 -06002224 * @ioc: per adapter object
2225 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302226 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002227 * @reply: reply message frame(lower 32bit addr)
2228 * Context: none.
2229 *
2230 * The callback handler when using scsih_issue_tm.
2231 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302232 * Return 1 meaning mf should be freed from _base_interrupt
2233 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06002234 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302235static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302236_scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06002237{
2238 MPI2DefaultReply_t *mpi_reply;
2239
2240 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302241 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002242 if (ioc->tm_cmds.smid != smid)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302243 return 1;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05302244 mpt2sas_base_flush_reply_queues(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06002245 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2246 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2247 if (mpi_reply) {
2248 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2249 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2250 }
2251 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2252 complete(&ioc->tm_cmds.done);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302253 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002254}
2255
2256/**
2257 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2258 * @ioc: per adapter object
2259 * @handle: device handle
2260 *
2261 * During taskmangement request, we need to freeze the device queue.
2262 */
2263void
2264mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2265{
2266 struct MPT2SAS_DEVICE *sas_device_priv_data;
2267 struct scsi_device *sdev;
2268 u8 skip = 0;
2269
2270 shost_for_each_device(sdev, ioc->shost) {
2271 if (skip)
2272 continue;
2273 sas_device_priv_data = sdev->hostdata;
2274 if (!sas_device_priv_data)
2275 continue;
2276 if (sas_device_priv_data->sas_target->handle == handle) {
2277 sas_device_priv_data->sas_target->tm_busy = 1;
2278 skip = 1;
2279 ioc->ignore_loginfos = 1;
2280 }
2281 }
2282}
2283
2284/**
2285 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2286 * @ioc: per adapter object
2287 * @handle: device handle
2288 *
2289 * During taskmangement request, we need to freeze the device queue.
2290 */
2291void
2292mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2293{
2294 struct MPT2SAS_DEVICE *sas_device_priv_data;
2295 struct scsi_device *sdev;
2296 u8 skip = 0;
2297
2298 shost_for_each_device(sdev, ioc->shost) {
2299 if (skip)
2300 continue;
2301 sas_device_priv_data = sdev->hostdata;
2302 if (!sas_device_priv_data)
2303 continue;
2304 if (sas_device_priv_data->sas_target->handle == handle) {
2305 sas_device_priv_data->sas_target->tm_busy = 0;
2306 skip = 1;
2307 ioc->ignore_loginfos = 0;
2308 }
2309 }
2310}
2311
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302312
Eric Moore635374e2009-03-09 01:21:12 -06002313/**
2314 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2315 * @ioc: per adapter struct
2316 * @device_handle: device handle
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302317 * @channel: the channel assigned by the OS
2318 * @id: the id assigned by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002319 * @lun: lun number
2320 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2321 * @smid_task: smid assigned to the task
2322 * @timeout: timeout in seconds
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302323 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302324 * Context: user
Eric Moore635374e2009-03-09 01:21:12 -06002325 *
2326 * A generic API for sending task management requests to firmware.
2327 *
Eric Moore635374e2009-03-09 01:21:12 -06002328 * The callback index is set inside `ioc->tm_cb_idx`.
2329 *
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302330 * Return SUCCESS or FAILED.
Eric Moore635374e2009-03-09 01:21:12 -06002331 */
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302332int
2333mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2334 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002335 enum mutex_type m_type)
Eric Moore635374e2009-03-09 01:21:12 -06002336{
2337 Mpi2SCSITaskManagementRequest_t *mpi_request;
2338 Mpi2SCSITaskManagementReply_t *mpi_reply;
2339 u16 smid = 0;
2340 u32 ioc_state;
2341 unsigned long timeleft;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302342 struct scsiio_tracker *scsi_lookup = NULL;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302343 int rc;
Eric Moore635374e2009-03-09 01:21:12 -06002344
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302345 if (m_type == TM_MUTEX_ON)
2346 mutex_lock(&ioc->tm_cmds.mutex);
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302347 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2348 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2349 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302350 rc = FAILED;
2351 goto err_out;
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302352 }
2353
Eric Moore3cb54692010-07-08 14:44:34 -06002354 if (ioc->shost_recovery || ioc->remove_host ||
2355 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06002356 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2357 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302358 rc = FAILED;
2359 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002360 }
Eric Moore635374e2009-03-09 01:21:12 -06002361
2362 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2363 if (ioc_state & MPI2_DOORBELL_USED) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302364 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
Eric Moore635374e2009-03-09 01:21:12 -06002365 "active!\n", ioc->name));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302366 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302367 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302368 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302369 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002370 }
2371
2372 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2373 mpt2sas_base_fault_info(ioc, ioc_state &
2374 MPI2_DOORBELL_DATA_MASK);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302375 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302376 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302377 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302378 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002379 }
2380
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302381 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06002382 if (!smid) {
2383 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2384 ioc->name, __func__);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302385 rc = FAILED;
2386 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002387 }
2388
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302389 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2390 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2391
Eric Moore635374e2009-03-09 01:21:12 -06002392 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302393 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2394 smid_task));
Eric Moore635374e2009-03-09 01:21:12 -06002395 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2396 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2397 ioc->tm_cmds.smid = smid;
2398 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302399 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
Eric Moore635374e2009-03-09 01:21:12 -06002400 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2401 mpi_request->DevHandle = cpu_to_le16(handle);
2402 mpi_request->TaskType = type;
2403 mpi_request->TaskMID = cpu_to_le16(smid_task);
2404 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2405 mpt2sas_scsih_set_tm_flag(ioc, handle);
Kashyap, Desai5b768582009-08-20 13:24:31 +05302406 init_completion(&ioc->tm_cmds.done);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302407 mpt2sas_base_put_smid_hi_priority(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06002408 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
Eric Moore635374e2009-03-09 01:21:12 -06002409 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2410 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2411 ioc->name, __func__);
2412 _debug_dump_mf(mpi_request,
2413 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302414 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302415 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302416 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302417 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302418 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2419 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2420 goto err_out;
2421 }
Eric Moore635374e2009-03-09 01:21:12 -06002422 }
2423
2424 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2425 mpi_reply = ioc->tm_cmds.reply;
2426 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2427 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2428 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2429 le32_to_cpu(mpi_reply->IOCLogInfo),
2430 le32_to_cpu(mpi_reply->TerminationCount)));
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302431 if (ioc->logging_level & MPT_DEBUG_TM) {
Eric Moore635374e2009-03-09 01:21:12 -06002432 _scsih_response_code(ioc, mpi_reply->ResponseCode);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302433 if (mpi_reply->IOCStatus)
2434 _debug_dump_mf(mpi_request,
2435 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2436 }
Eric Moore635374e2009-03-09 01:21:12 -06002437 }
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302438
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302439 switch (type) {
2440 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302441 rc = SUCCESS;
2442 if (scsi_lookup->scmd == NULL)
2443 break;
2444 rc = FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302445 break;
2446
2447 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2448 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2449 rc = FAILED;
2450 else
2451 rc = SUCCESS;
2452 break;
2453
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302454 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302455 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2456 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2457 rc = FAILED;
2458 else
2459 rc = SUCCESS;
2460 break;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302461 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2462 rc = SUCCESS;
2463 break;
2464 default:
2465 rc = FAILED;
2466 break;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302467 }
2468
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302469 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2470 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302471 if (m_type == TM_MUTEX_ON)
2472 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302473
2474 return rc;
2475
2476 err_out:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302477 if (m_type == TM_MUTEX_ON)
2478 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302479 return rc;
Eric Moore635374e2009-03-09 01:21:12 -06002480}
2481
2482/**
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302483 * _scsih_tm_display_info - displays info about the device
2484 * @ioc: per adapter struct
2485 * @scmd: pointer to scsi command object
2486 *
2487 * Called by task management callback handlers.
2488 */
2489static void
2490_scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2491{
2492 struct scsi_target *starget = scmd->device->sdev_target;
2493 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2494 struct _sas_device *sas_device = NULL;
2495 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302496 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302497
2498 if (!priv_target)
2499 return;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302500 if (ioc->hide_ir_msg)
2501 device_str = "WarpDrive";
2502 else
2503 device_str = "volume";
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302504
2505 scsi_print_command(scmd);
2506 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302507 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2508 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2509 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302510 } else {
2511 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2512 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2513 priv_target->sas_address);
2514 if (sas_device) {
2515 if (priv_target->flags &
2516 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2517 starget_printk(KERN_INFO, starget,
2518 "volume handle(0x%04x), "
2519 "volume wwid(0x%016llx)\n",
2520 sas_device->volume_handle,
2521 (unsigned long long)sas_device->volume_wwid);
2522 }
2523 starget_printk(KERN_INFO, starget,
2524 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2525 sas_device->handle,
2526 (unsigned long long)sas_device->sas_address,
2527 sas_device->phy);
2528 starget_printk(KERN_INFO, starget,
2529 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2530 (unsigned long long)sas_device->enclosure_logical_id,
2531 sas_device->slot);
2532 }
2533 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2534 }
2535}
2536
2537/**
Eric Moored5d135b2009-05-18 13:02:08 -06002538 * _scsih_abort - eh threads main abort routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302539 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002540 *
2541 * Returns SUCCESS if command aborted else FAILED
2542 */
2543static int
Eric Moored5d135b2009-05-18 13:02:08 -06002544_scsih_abort(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002545{
2546 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2547 struct MPT2SAS_DEVICE *sas_device_priv_data;
2548 u16 smid;
2549 u16 handle;
2550 int r;
Eric Moore635374e2009-03-09 01:21:12 -06002551
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302552 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2553 "scmd(%p)\n", scmd);
2554 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002555
2556 sas_device_priv_data = scmd->device->hostdata;
2557 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302558 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2559 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002560 scmd->result = DID_NO_CONNECT << 16;
2561 scmd->scsi_done(scmd);
2562 r = SUCCESS;
2563 goto out;
2564 }
2565
2566 /* search for the command */
2567 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2568 if (!smid) {
2569 scmd->result = DID_RESET << 16;
2570 r = SUCCESS;
2571 goto out;
2572 }
2573
2574 /* for hidden raid components and volumes this is not supported */
2575 if (sas_device_priv_data->sas_target->flags &
2576 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2577 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2578 scmd->result = DID_RESET << 16;
2579 r = FAILED;
2580 goto out;
2581 }
2582
Kashyap, Desaifa7f3162009-09-23 17:26:58 +05302583 mpt2sas_halt_firmware(ioc);
2584
Eric Moore635374e2009-03-09 01:21:12 -06002585 handle = sas_device_priv_data->sas_target->handle;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302586 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2587 scmd->device->id, scmd->device->lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002588 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002589
2590 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302591 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2592 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002593 return r;
2594}
2595
Eric Moore635374e2009-03-09 01:21:12 -06002596/**
Eric Moored5d135b2009-05-18 13:02:08 -06002597 * _scsih_dev_reset - eh threads main device reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302598 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002599 *
2600 * Returns SUCCESS if command aborted else FAILED
2601 */
2602static int
Eric Moored5d135b2009-05-18 13:02:08 -06002603_scsih_dev_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002604{
2605 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2606 struct MPT2SAS_DEVICE *sas_device_priv_data;
2607 struct _sas_device *sas_device;
2608 unsigned long flags;
2609 u16 handle;
2610 int r;
2611
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302612 struct scsi_target *starget = scmd->device->sdev_target;
2613
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302614 starget_printk(KERN_INFO, starget, "attempting device reset! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302615 "scmd(%p)\n", scmd);
2616 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002617
2618 sas_device_priv_data = scmd->device->hostdata;
2619 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302620 starget_printk(KERN_INFO, starget, "device been deleted! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302621 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002622 scmd->result = DID_NO_CONNECT << 16;
2623 scmd->scsi_done(scmd);
2624 r = SUCCESS;
2625 goto out;
2626 }
2627
2628 /* for hidden raid components obtain the volume_handle */
2629 handle = 0;
2630 if (sas_device_priv_data->sas_target->flags &
2631 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2632 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2633 sas_device = _scsih_sas_device_find_by_handle(ioc,
2634 sas_device_priv_data->sas_target->handle);
2635 if (sas_device)
2636 handle = sas_device->volume_handle;
2637 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2638 } else
2639 handle = sas_device_priv_data->sas_target->handle;
2640
2641 if (!handle) {
2642 scmd->result = DID_RESET << 16;
2643 r = FAILED;
2644 goto out;
2645 }
2646
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302647 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2648 scmd->device->id, scmd->device->lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002649 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
Eric Moore993e0da2009-05-18 13:00:45 -06002650
2651 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302652 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2653 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002654 return r;
2655}
2656
2657/**
Eric Moored5d135b2009-05-18 13:02:08 -06002658 * _scsih_target_reset - eh threads main target reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302659 * @scmd: pointer to scsi command object
Eric Moore993e0da2009-05-18 13:00:45 -06002660 *
2661 * Returns SUCCESS if command aborted else FAILED
2662 */
2663static int
Eric Moored5d135b2009-05-18 13:02:08 -06002664_scsih_target_reset(struct scsi_cmnd *scmd)
Eric Moore993e0da2009-05-18 13:00:45 -06002665{
2666 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2667 struct MPT2SAS_DEVICE *sas_device_priv_data;
2668 struct _sas_device *sas_device;
2669 unsigned long flags;
2670 u16 handle;
2671 int r;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302672 struct scsi_target *starget = scmd->device->sdev_target;
Eric Moore993e0da2009-05-18 13:00:45 -06002673
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302674 starget_printk(KERN_INFO, starget, "attempting target reset! "
2675 "scmd(%p)\n", scmd);
2676 _scsih_tm_display_info(ioc, scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002677
2678 sas_device_priv_data = scmd->device->hostdata;
2679 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302680 starget_printk(KERN_INFO, starget, "target been deleted! "
2681 "scmd(%p)\n", scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002682 scmd->result = DID_NO_CONNECT << 16;
2683 scmd->scsi_done(scmd);
2684 r = SUCCESS;
2685 goto out;
2686 }
2687
2688 /* for hidden raid components obtain the volume_handle */
2689 handle = 0;
2690 if (sas_device_priv_data->sas_target->flags &
2691 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2692 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2693 sas_device = _scsih_sas_device_find_by_handle(ioc,
2694 sas_device_priv_data->sas_target->handle);
2695 if (sas_device)
2696 handle = sas_device->volume_handle;
2697 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2698 } else
2699 handle = sas_device_priv_data->sas_target->handle;
2700
2701 if (!handle) {
2702 scmd->result = DID_RESET << 16;
2703 r = FAILED;
2704 goto out;
2705 }
2706
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302707 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2708 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002709 30, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002710
2711 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302712 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2713 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002714 return r;
2715}
2716
2717/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302718 * _scsih_host_reset - eh threads main host reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302719 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002720 *
2721 * Returns SUCCESS if command aborted else FAILED
2722 */
2723static int
Eric Moored5d135b2009-05-18 13:02:08 -06002724_scsih_host_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002725{
2726 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2727 int r, retval;
2728
2729 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2730 ioc->name, scmd);
2731 scsi_print_command(scmd);
2732
Sreekanth Reddyddb588b2015-01-12 11:38:57 +05302733 if (ioc->is_driver_loading) {
2734 printk(MPT2SAS_INFO_FMT "Blocking the host reset\n",
2735 ioc->name);
2736 r = FAILED;
2737 goto out;
2738 }
2739
Eric Moore635374e2009-03-09 01:21:12 -06002740 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2741 FORCE_BIG_HAMMER);
2742 r = (retval < 0) ? FAILED : SUCCESS;
Sreekanth Reddyddb588b2015-01-12 11:38:57 +05302743
2744 out:
Eric Moore635374e2009-03-09 01:21:12 -06002745 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2746 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2747
2748 return r;
2749}
2750
2751/**
2752 * _scsih_fw_event_add - insert and queue up fw_event
2753 * @ioc: per adapter object
2754 * @fw_event: object describing the event
2755 * Context: This function will acquire ioc->fw_event_lock.
2756 *
2757 * This adds the firmware event object into link list, then queues it up to
2758 * be processed from user context.
2759 *
2760 * Return nothing.
2761 */
2762static void
2763_scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2764{
2765 unsigned long flags;
2766
2767 if (ioc->firmware_event_thread == NULL)
2768 return;
2769
2770 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2771 list_add_tail(&fw_event->list, &ioc->fw_event_list);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302772 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2773 queue_delayed_work(ioc->firmware_event_thread,
2774 &fw_event->delayed_work, 0);
Eric Moore635374e2009-03-09 01:21:12 -06002775 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2776}
2777
2778/**
2779 * _scsih_fw_event_free - delete fw_event
2780 * @ioc: per adapter object
2781 * @fw_event: object describing the event
2782 * Context: This function will acquire ioc->fw_event_lock.
2783 *
2784 * This removes firmware event object from link list, frees associated memory.
2785 *
2786 * Return nothing.
2787 */
2788static void
2789_scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2790 *fw_event)
2791{
2792 unsigned long flags;
2793
2794 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2795 list_del(&fw_event->list);
Eric Moore635374e2009-03-09 01:21:12 -06002796 kfree(fw_event);
2797 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2798}
2799
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302800
Eric Moore635374e2009-03-09 01:21:12 -06002801/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302802 * _scsih_error_recovery_delete_devices - remove devices not responding
Eric Moore635374e2009-03-09 01:21:12 -06002803 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06002804 *
2805 * Return nothing.
2806 */
2807static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302808_scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06002809{
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302810 struct fw_event_work *fw_event;
2811
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302812 if (ioc->is_driver_loading)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302813 return;
Dan Carpenter181a9d72011-11-04 21:25:01 +03002814
2815 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2816 if (!fw_event)
2817 return;
2818
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302819 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2820 fw_event->ioc = ioc;
2821 _scsih_fw_event_add(ioc, fw_event);
2822}
2823
2824/**
2825 * mpt2sas_port_enable_complete - port enable completed (fake event)
2826 * @ioc: per adapter object
2827 *
2828 * Return nothing.
2829 */
2830void
2831mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2832{
2833 struct fw_event_work *fw_event;
2834
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302835 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2836 if (!fw_event)
2837 return;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302838 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302839 fw_event->ioc = ioc;
2840 _scsih_fw_event_add(ioc, fw_event);
2841}
2842
2843/**
2844 * _scsih_fw_event_cleanup_queue - cleanup event queue
2845 * @ioc: per adapter object
2846 *
2847 * Walk the firmware event queue, either killing timers, or waiting
2848 * for outstanding events to complete
2849 *
2850 * Return nothing.
2851 */
2852static void
2853_scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2854{
2855 struct fw_event_work *fw_event, *next;
2856
2857 if (list_empty(&ioc->fw_event_list) ||
2858 !ioc->firmware_event_thread || in_interrupt())
Eric Moore635374e2009-03-09 01:21:12 -06002859 return;
2860
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302861 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05302862 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302863 _scsih_fw_event_free(ioc, fw_event);
2864 continue;
2865 }
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302866 }
Eric Moore635374e2009-03-09 01:21:12 -06002867}
2868
Eric Moore635374e2009-03-09 01:21:12 -06002869/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302870 * _scsih_ublock_io_all_device - unblock every device
2871 * @ioc: per adapter object
2872 *
2873 * change the device state from block to running
2874 */
2875static void
2876_scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2877{
2878 struct MPT2SAS_DEVICE *sas_device_priv_data;
2879 struct scsi_device *sdev;
2880
2881 shost_for_each_device(sdev, ioc->shost) {
2882 sas_device_priv_data = sdev->hostdata;
2883 if (!sas_device_priv_data)
2884 continue;
2885 if (!sas_device_priv_data->block)
2886 continue;
2887 sas_device_priv_data->block = 0;
2888 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2889 "handle(0x%04x)\n",
2890 sas_device_priv_data->sas_target->handle));
Mike Christie5d9fb5c2012-05-17 23:56:57 -05002891 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302892 }
2893}
2894/**
Eric Moore635374e2009-03-09 01:21:12 -06002895 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2896 * @ioc: per adapter object
2897 * @handle: device handle
2898 *
2899 * During device pull we need to appropiately set the sdev state.
2900 */
2901static void
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302902_scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06002903{
2904 struct MPT2SAS_DEVICE *sas_device_priv_data;
2905 struct scsi_device *sdev;
2906
2907 shost_for_each_device(sdev, ioc->shost) {
2908 sas_device_priv_data = sdev->hostdata;
2909 if (!sas_device_priv_data)
2910 continue;
2911 if (!sas_device_priv_data->block)
2912 continue;
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302913 if (sas_device_priv_data->sas_target->sas_address ==
2914 sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06002915 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2916 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302917 "sas address(0x%016llx)\n", ioc->name,
2918 (unsigned long long)sas_address));
Eric Moore635374e2009-03-09 01:21:12 -06002919 sas_device_priv_data->block = 0;
Mike Christie5d9fb5c2012-05-17 23:56:57 -05002920 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
Eric Moore635374e2009-03-09 01:21:12 -06002921 }
2922 }
2923}
2924
2925/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302926 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2927 * @ioc: per adapter object
2928 * @handle: device handle
2929 *
2930 * During device pull we need to appropiately set the sdev state.
2931 */
2932static void
2933_scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2934{
2935 struct MPT2SAS_DEVICE *sas_device_priv_data;
2936 struct scsi_device *sdev;
2937
2938 shost_for_each_device(sdev, ioc->shost) {
2939 sas_device_priv_data = sdev->hostdata;
2940 if (!sas_device_priv_data)
2941 continue;
2942 if (sas_device_priv_data->block)
2943 continue;
2944 sas_device_priv_data->block = 1;
2945 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2946 "handle(0x%04x)\n",
2947 sas_device_priv_data->sas_target->handle));
2948 scsi_internal_device_block(sdev);
2949 }
2950}
2951
2952
2953/**
Eric Moore635374e2009-03-09 01:21:12 -06002954 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2955 * @ioc: per adapter object
2956 * @handle: device handle
2957 *
2958 * During device pull we need to appropiately set the sdev state.
2959 */
2960static void
2961_scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2962{
2963 struct MPT2SAS_DEVICE *sas_device_priv_data;
2964 struct scsi_device *sdev;
2965
2966 shost_for_each_device(sdev, ioc->shost) {
2967 sas_device_priv_data = sdev->hostdata;
2968 if (!sas_device_priv_data)
2969 continue;
2970 if (sas_device_priv_data->block)
2971 continue;
2972 if (sas_device_priv_data->sas_target->handle == handle) {
2973 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2974 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2975 "handle(0x%04x)\n", ioc->name, handle));
2976 sas_device_priv_data->block = 1;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05302977 scsi_internal_device_block(sdev);
Eric Moore635374e2009-03-09 01:21:12 -06002978 }
2979 }
2980}
2981
2982/**
2983 * _scsih_block_io_to_children_attached_to_ex
2984 * @ioc: per adapter object
2985 * @sas_expander: the sas_device object
2986 *
2987 * This routine set sdev state to SDEV_BLOCK for all devices
2988 * attached to this expander. This function called when expander is
2989 * pulled.
2990 */
2991static void
2992_scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
2993 struct _sas_node *sas_expander)
2994{
2995 struct _sas_port *mpt2sas_port;
2996 struct _sas_device *sas_device;
2997 struct _sas_node *expander_sibling;
2998 unsigned long flags;
2999
3000 if (!sas_expander)
3001 return;
3002
3003 list_for_each_entry(mpt2sas_port,
3004 &sas_expander->sas_port_list, port_list) {
3005 if (mpt2sas_port->remote_identify.device_type ==
3006 SAS_END_DEVICE) {
3007 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3008 sas_device =
3009 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3010 mpt2sas_port->remote_identify.sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303011 if (sas_device)
3012 set_bit(sas_device->handle,
3013 ioc->blocking_handles);
Eric Moore635374e2009-03-09 01:21:12 -06003014 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06003015 }
3016 }
3017
3018 list_for_each_entry(mpt2sas_port,
3019 &sas_expander->sas_port_list, port_list) {
3020
3021 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05303022 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06003023 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05303024 SAS_FANOUT_EXPANDER_DEVICE) {
Eric Moore635374e2009-03-09 01:21:12 -06003025 expander_sibling =
3026 mpt2sas_scsih_expander_find_by_sas_address(
3027 ioc, mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06003028 _scsih_block_io_to_children_attached_to_ex(ioc,
3029 expander_sibling);
3030 }
3031 }
3032}
3033
3034/**
3035 * _scsih_block_io_to_children_attached_directly
3036 * @ioc: per adapter object
3037 * @event_data: topology change event data
3038 *
3039 * This routine set sdev state to SDEV_BLOCK for all devices
3040 * direct attached during device pull.
3041 */
3042static void
3043_scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3044 Mpi2EventDataSasTopologyChangeList_t *event_data)
3045{
3046 int i;
3047 u16 handle;
3048 u16 reason_code;
3049 u8 phy_number;
3050
3051 for (i = 0; i < event_data->NumEntries; i++) {
3052 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3053 if (!handle)
3054 continue;
3055 phy_number = event_data->StartPhyNum + i;
3056 reason_code = event_data->PHY[i].PhyStatus &
3057 MPI2_EVENT_SAS_TOPO_RC_MASK;
3058 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3059 _scsih_block_io_device(ioc, handle);
3060 }
3061}
3062
3063/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303064 * _scsih_tm_tr_send - send task management request
3065 * @ioc: per adapter object
3066 * @handle: device handle
3067 * Context: interrupt time.
3068 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003069 * This code is to initiate the device removal handshake protocol
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303070 * with controller firmware. This function will issue target reset
3071 * using high priority request queue. It will send a sas iounit
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003072 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303073 *
3074 * This is designed to send muliple task management request at the same
3075 * time to the fifo. If the fifo is full, we will append the request,
3076 * and process it in a future completion.
3077 */
3078static void
3079_scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3080{
3081 Mpi2SCSITaskManagementRequest_t *mpi_request;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303082 u16 smid;
3083 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303084 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3085 u64 sas_address = 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303086 unsigned long flags;
3087 struct _tr_list *delayed_tr;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303088 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303089
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303090 if (ioc->remove_host) {
3091 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3092 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3093 return;
3094 } else if (ioc->pci_error_recovery) {
3095 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3096 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3097 handle));
3098 return;
3099 }
3100 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3101 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3102 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3103 "operational: handle(0x%04x)\n", __func__, ioc->name,
3104 handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303105 return;
3106 }
3107
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303108 /* if PD, then return */
3109 if (test_bit(handle, ioc->pd_handles))
3110 return;
3111
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303112 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3113 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303114 if (sas_device && sas_device->starget &&
3115 sas_device->starget->hostdata) {
3116 sas_target_priv_data = sas_device->starget->hostdata;
3117 sas_target_priv_data->deleted = 1;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303118 sas_address = sas_device->sas_address;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303119 }
3120 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303121
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303122 if (sas_target_priv_data) {
3123 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3124 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3125 (unsigned long long)sas_address));
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05303126 _scsih_ublock_io_device(ioc, sas_address);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05303127 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303128 }
3129
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303130 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3131 if (!smid) {
3132 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3133 if (!delayed_tr)
3134 return;
3135 INIT_LIST_HEAD(&delayed_tr->list);
3136 delayed_tr->handle = handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303137 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3138 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3139 "DELAYED:tr:handle(0x%04x), (open)\n",
3140 ioc->name, handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303141 return;
3142 }
3143
Kashyap, Desai1278b112010-03-09 17:34:13 +05303144 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3145 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3146 ioc->tm_tr_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303147 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3148 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3149 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3150 mpi_request->DevHandle = cpu_to_le16(handle);
3151 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303152 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3153}
3154
3155
3156
3157/**
3158 * _scsih_sas_control_complete - completion routine
3159 * @ioc: per adapter object
3160 * @smid: system request message index
3161 * @msix_index: MSIX table index supplied by the OS
3162 * @reply: reply message frame(lower 32bit addr)
3163 * Context: interrupt time.
3164 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003165 * This is the sas iounit control completion routine.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303166 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003167 * handshake protocol with controller firmware.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303168 *
3169 * Return 1 meaning mf should be freed from _base_interrupt
3170 * 0 means the mf is freed from this function.
3171 */
3172static u8
3173_scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3174 u8 msix_index, u32 reply)
3175{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303176 Mpi2SasIoUnitControlReply_t *mpi_reply =
3177 mpt2sas_base_get_reply_virt_addr(ioc, reply);
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303178 if (likely(mpi_reply)) {
3179 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3180 "sc_complete:handle(0x%04x), (open) "
3181 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3182 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3183 le16_to_cpu(mpi_reply->IOCStatus),
3184 le32_to_cpu(mpi_reply->IOCLogInfo)));
3185 } else {
3186 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3187 ioc->name, __FILE__, __LINE__, __func__);
3188 }
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303189 return 1;
3190}
3191
3192/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303193 * _scsih_tm_tr_volume_send - send target reset request for volumes
3194 * @ioc: per adapter object
3195 * @handle: device handle
3196 * Context: interrupt time.
3197 *
3198 * This is designed to send muliple task management request at the same
3199 * time to the fifo. If the fifo is full, we will append the request,
3200 * and process it in a future completion.
3201 */
3202static void
3203_scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3204{
3205 Mpi2SCSITaskManagementRequest_t *mpi_request;
3206 u16 smid;
3207 struct _tr_list *delayed_tr;
3208
Eric Moore3cb54692010-07-08 14:44:34 -06003209 if (ioc->shost_recovery || ioc->remove_host ||
3210 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303211 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3212 "progress!\n", __func__, ioc->name));
3213 return;
3214 }
3215
3216 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3217 if (!smid) {
3218 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3219 if (!delayed_tr)
3220 return;
3221 INIT_LIST_HEAD(&delayed_tr->list);
3222 delayed_tr->handle = handle;
3223 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3224 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3225 "DELAYED:tr:handle(0x%04x), (open)\n",
3226 ioc->name, handle));
3227 return;
3228 }
3229
3230 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3231 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3232 ioc->tm_tr_volume_cb_idx));
3233 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3234 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3235 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3236 mpi_request->DevHandle = cpu_to_le16(handle);
3237 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3238 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3239}
3240
3241/**
3242 * _scsih_tm_volume_tr_complete - target reset completion
3243 * @ioc: per adapter object
3244 * @smid: system request message index
3245 * @msix_index: MSIX table index supplied by the OS
3246 * @reply: reply message frame(lower 32bit addr)
3247 * Context: interrupt time.
3248 *
3249 * Return 1 meaning mf should be freed from _base_interrupt
3250 * 0 means the mf is freed from this function.
3251 */
3252static u8
3253_scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3254 u8 msix_index, u32 reply)
3255{
3256 u16 handle;
3257 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3258 Mpi2SCSITaskManagementReply_t *mpi_reply =
3259 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3260
Eric Moore3cb54692010-07-08 14:44:34 -06003261 if (ioc->shost_recovery || ioc->remove_host ||
3262 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303263 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3264 "progress!\n", __func__, ioc->name));
3265 return 1;
3266 }
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303267 if (unlikely(!mpi_reply)) {
3268 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3269 ioc->name, __FILE__, __LINE__, __func__);
3270 return 1;
3271 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303272 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3273 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3274 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3275 dewtprintk(ioc, printk("spurious interrupt: "
3276 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3277 le16_to_cpu(mpi_reply->DevHandle), smid));
3278 return 0;
3279 }
3280
3281 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3282 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3283 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3284 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3285 le32_to_cpu(mpi_reply->IOCLogInfo),
3286 le32_to_cpu(mpi_reply->TerminationCount)));
3287
3288 return _scsih_check_for_pending_tm(ioc, smid);
3289}
3290
3291/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303292 * _scsih_tm_tr_complete -
3293 * @ioc: per adapter object
3294 * @smid: system request message index
3295 * @msix_index: MSIX table index supplied by the OS
3296 * @reply: reply message frame(lower 32bit addr)
3297 * Context: interrupt time.
3298 *
3299 * This is the target reset completion routine.
3300 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003301 * handshake protocol with controller firmware.
3302 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303303 *
3304 * Return 1 meaning mf should be freed from _base_interrupt
3305 * 0 means the mf is freed from this function.
3306 */
3307static u8
3308_scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3309 u32 reply)
3310{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303311 u16 handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303312 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303313 Mpi2SCSITaskManagementReply_t *mpi_reply =
3314 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3315 Mpi2SasIoUnitControlRequest_t *mpi_request;
3316 u16 smid_sas_ctrl;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303317 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303318
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303319 if (ioc->remove_host) {
3320 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3321 "removed\n", __func__, ioc->name));
3322 return 1;
3323 } else if (ioc->pci_error_recovery) {
3324 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3325 "error recovery\n", __func__, ioc->name));
3326 return 1;
3327 }
3328 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3329 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3330 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3331 "operational\n", __func__, ioc->name));
Kashyap, Desai1278b112010-03-09 17:34:13 +05303332 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303333 }
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303334 if (unlikely(!mpi_reply)) {
3335 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3336 ioc->name, __FILE__, __LINE__, __func__);
3337 return 1;
3338 }
Kashyap, Desai1278b112010-03-09 17:34:13 +05303339 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3340 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3341 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3342 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3343 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3344 le16_to_cpu(mpi_reply->DevHandle), smid));
3345 return 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303346 }
3347
Kashyap, Desai1278b112010-03-09 17:34:13 +05303348 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3349 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3350 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3351 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3352 le32_to_cpu(mpi_reply->IOCLogInfo),
3353 le32_to_cpu(mpi_reply->TerminationCount)));
3354
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303355 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3356 if (!smid_sas_ctrl) {
3357 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3358 ioc->name, __func__);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303359 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303360 }
3361
Kashyap, Desai1278b112010-03-09 17:34:13 +05303362 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3363 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3364 ioc->tm_sas_control_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303365 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3366 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3367 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3368 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303369 mpi_request->DevHandle = mpi_request_tm->DevHandle;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303370 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303371
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303372 return _scsih_check_for_pending_tm(ioc, smid);
3373}
3374
3375/**
3376 * _scsih_check_for_pending_tm - check for pending task management
3377 * @ioc: per adapter object
3378 * @smid: system request message index
3379 *
3380 * This will check delayed target reset list, and feed the
3381 * next reqeust.
3382 *
3383 * Return 1 meaning mf should be freed from _base_interrupt
3384 * 0 means the mf is freed from this function.
3385 */
3386static u8
3387_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3388{
3389 struct _tr_list *delayed_tr;
3390
3391 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3392 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3393 struct _tr_list, list);
3394 mpt2sas_base_free_smid(ioc, smid);
3395 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3396 list_del(&delayed_tr->list);
3397 kfree(delayed_tr);
3398 return 0;
3399 }
3400
Kashyap, Desai1278b112010-03-09 17:34:13 +05303401 if (!list_empty(&ioc->delayed_tr_list)) {
3402 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3403 struct _tr_list, list);
3404 mpt2sas_base_free_smid(ioc, smid);
3405 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3406 list_del(&delayed_tr->list);
3407 kfree(delayed_tr);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303408 return 0;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303409 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303410
Kashyap, Desai1278b112010-03-09 17:34:13 +05303411 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303412}
3413
3414/**
Eric Moore635374e2009-03-09 01:21:12 -06003415 * _scsih_check_topo_delete_events - sanity check on topo events
3416 * @ioc: per adapter object
3417 * @event_data: the event data payload
3418 *
3419 * This routine added to better handle cable breaker.
3420 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003421 * This handles the case where driver receives multiple expander
Eric Moore635374e2009-03-09 01:21:12 -06003422 * add and delete events in a single shot. When there is a delete event
3423 * the routine will void any pending add events waiting in the event queue.
3424 *
3425 * Return nothing.
3426 */
3427static void
3428_scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3429 Mpi2EventDataSasTopologyChangeList_t *event_data)
3430{
3431 struct fw_event_work *fw_event;
3432 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3433 u16 expander_handle;
3434 struct _sas_node *sas_expander;
3435 unsigned long flags;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303436 int i, reason_code;
3437 u16 handle;
3438
3439 for (i = 0 ; i < event_data->NumEntries; i++) {
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303440 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3441 if (!handle)
3442 continue;
3443 reason_code = event_data->PHY[i].PhyStatus &
3444 MPI2_EVENT_SAS_TOPO_RC_MASK;
3445 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3446 _scsih_tm_tr_send(ioc, handle);
3447 }
Eric Moore635374e2009-03-09 01:21:12 -06003448
3449 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3450 if (expander_handle < ioc->sas_hba.num_phys) {
3451 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3452 return;
3453 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303454 if (event_data->ExpStatus ==
3455 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3456 /* put expander attached devices into blocking state */
Eric Moore635374e2009-03-09 01:21:12 -06003457 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3458 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3459 expander_handle);
Eric Moore635374e2009-03-09 01:21:12 -06003460 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303461 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3462 do {
3463 handle = find_first_bit(ioc->blocking_handles,
3464 ioc->facts.MaxDevHandle);
3465 if (handle < ioc->facts.MaxDevHandle)
3466 _scsih_block_io_device(ioc, handle);
3467 } while (test_and_clear_bit(handle, ioc->blocking_handles));
Eric Moore635374e2009-03-09 01:21:12 -06003468 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3469 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3470
3471 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3472 return;
3473
3474 /* mark ignore flag for pending events */
3475 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3476 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3477 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3478 fw_event->ignore)
3479 continue;
Joe Lawrence00713ad2014-06-25 17:03:33 -04003480 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3481 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06003482 if (local_event_data->ExpStatus ==
3483 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3484 local_event_data->ExpStatus ==
3485 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3486 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3487 expander_handle) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303488 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06003489 "setting ignoring flag\n", ioc->name));
3490 fw_event->ignore = 1;
3491 }
3492 }
3493 }
3494 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3495}
3496
3497/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303498 * _scsih_set_volume_delete_flag - setting volume delete flag
3499 * @ioc: per adapter object
3500 * @handle: device handle
3501 *
3502 * This
3503 * Return nothing.
3504 */
3505static void
3506_scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3507{
3508 struct _raid_device *raid_device;
3509 struct MPT2SAS_TARGET *sas_target_priv_data;
3510 unsigned long flags;
3511
3512 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3513 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3514 if (raid_device && raid_device->starget &&
3515 raid_device->starget->hostdata) {
3516 sas_target_priv_data =
3517 raid_device->starget->hostdata;
3518 sas_target_priv_data->deleted = 1;
3519 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3520 "setting delete flag: handle(0x%04x), "
3521 "wwid(0x%016llx)\n", ioc->name, handle,
3522 (unsigned long long) raid_device->wwid));
3523 }
3524 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3525}
3526
3527/**
3528 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3529 * @handle: input handle
3530 * @a: handle for volume a
3531 * @b: handle for volume b
3532 *
3533 * IR firmware only supports two raid volumes. The purpose of this
3534 * routine is to set the volume handle in either a or b. When the given
3535 * input handle is non-zero, or when a and b have not been set before.
3536 */
3537static void
3538_scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3539{
3540 if (!handle || handle == *a || handle == *b)
3541 return;
3542 if (!*a)
3543 *a = handle;
3544 else if (!*b)
3545 *b = handle;
3546}
3547
3548/**
3549 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3550 * @ioc: per adapter object
3551 * @event_data: the event data payload
3552 * Context: interrupt time.
3553 *
3554 * This routine will send target reset to volume, followed by target
3555 * resets to the PDs. This is called when a PD has been removed, or
3556 * volume has been deleted or removed. When the target reset is sent
3557 * to volume, the PD target resets need to be queued to start upon
3558 * completion of the volume target reset.
3559 *
3560 * Return nothing.
3561 */
3562static void
3563_scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3564 Mpi2EventDataIrConfigChangeList_t *event_data)
3565{
3566 Mpi2EventIrConfigElement_t *element;
3567 int i;
3568 u16 handle, volume_handle, a, b;
3569 struct _tr_list *delayed_tr;
3570
3571 a = 0;
3572 b = 0;
3573
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303574 if (ioc->is_warpdrive)
3575 return;
3576
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303577 /* Volume Resets for Deleted or Removed */
3578 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3579 for (i = 0; i < event_data->NumElements; i++, element++) {
3580 if (element->ReasonCode ==
3581 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3582 element->ReasonCode ==
3583 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3584 volume_handle = le16_to_cpu(element->VolDevHandle);
3585 _scsih_set_volume_delete_flag(ioc, volume_handle);
3586 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3587 }
3588 }
3589
3590 /* Volume Resets for UNHIDE events */
3591 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3592 for (i = 0; i < event_data->NumElements; i++, element++) {
3593 if (le32_to_cpu(event_data->Flags) &
3594 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3595 continue;
3596 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3597 volume_handle = le16_to_cpu(element->VolDevHandle);
3598 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3599 }
3600 }
3601
3602 if (a)
3603 _scsih_tm_tr_volume_send(ioc, a);
3604 if (b)
3605 _scsih_tm_tr_volume_send(ioc, b);
3606
3607 /* PD target resets */
3608 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3609 for (i = 0; i < event_data->NumElements; i++, element++) {
3610 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3611 continue;
3612 handle = le16_to_cpu(element->PhysDiskDevHandle);
3613 volume_handle = le16_to_cpu(element->VolDevHandle);
3614 clear_bit(handle, ioc->pd_handles);
3615 if (!volume_handle)
3616 _scsih_tm_tr_send(ioc, handle);
3617 else if (volume_handle == a || volume_handle == b) {
3618 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3619 BUG_ON(!delayed_tr);
3620 INIT_LIST_HEAD(&delayed_tr->list);
3621 delayed_tr->handle = handle;
3622 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3623 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3624 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3625 handle));
3626 } else
3627 _scsih_tm_tr_send(ioc, handle);
3628 }
3629}
3630
3631
3632/**
3633 * _scsih_check_volume_delete_events - set delete flag for volumes
3634 * @ioc: per adapter object
3635 * @event_data: the event data payload
3636 * Context: interrupt time.
3637 *
3638 * This will handle the case when the cable connected to entire volume is
3639 * pulled. We will take care of setting the deleted flag so normal IO will
3640 * not be sent.
3641 *
3642 * Return nothing.
3643 */
3644static void
3645_scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3646 Mpi2EventDataIrVolume_t *event_data)
3647{
3648 u32 state;
3649
3650 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3651 return;
3652 state = le32_to_cpu(event_data->NewValue);
3653 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3654 MPI2_RAID_VOL_STATE_FAILED)
3655 _scsih_set_volume_delete_flag(ioc,
3656 le16_to_cpu(event_data->VolDevHandle));
3657}
3658
3659/**
Sreekanth Reddy2d8ce8c2015-01-12 11:38:56 +05303660 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3661 * @ioc: per adapter object
3662 * @event_data: the temp threshold event data
3663 * Context: interrupt time.
3664 *
3665 * Return nothing.
3666 */
3667static void
3668_scsih_temp_threshold_events(struct MPT2SAS_ADAPTER *ioc,
3669 Mpi2EventDataTemperature_t *event_data)
3670{
3671 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3672 printk(MPT2SAS_ERR_FMT "Temperature Threshold flags %s%s%s%s"
3673 " exceeded for Sensor: %d !!!\n", ioc->name,
3674 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3675 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3676 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3677 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3678 event_data->SensorNum);
3679 printk(MPT2SAS_ERR_FMT "Current Temp In Celsius: %d\n",
3680 ioc->name, event_data->CurrentTemperature);
3681 }
3682}
3683
3684/**
Eric Moore635374e2009-03-09 01:21:12 -06003685 * _scsih_flush_running_cmds - completing outstanding commands.
3686 * @ioc: per adapter object
3687 *
3688 * The flushing out of all pending scmd commands following host reset,
3689 * where all IO is dropped to the floor.
3690 *
3691 * Return nothing.
3692 */
3693static void
3694_scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3695{
3696 struct scsi_cmnd *scmd;
3697 u16 smid;
3698 u16 count = 0;
3699
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303700 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05303701 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003702 if (!scmd)
3703 continue;
3704 count++;
3705 mpt2sas_base_free_smid(ioc, smid);
3706 scsi_dma_unmap(scmd);
Eric Moore3cb54692010-07-08 14:44:34 -06003707 if (ioc->pci_error_recovery)
3708 scmd->result = DID_NO_CONNECT << 16;
3709 else
3710 scmd->result = DID_RESET << 16;
Eric Moore635374e2009-03-09 01:21:12 -06003711 scmd->scsi_done(scmd);
3712 }
3713 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3714 ioc->name, count));
3715}
3716
3717/**
Eric Moore3c621b32009-05-18 12:59:41 -06003718 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3719 * @scmd: pointer to scsi command object
3720 * @mpi_request: pointer to the SCSI_IO reqest message frame
3721 *
3722 * Supporting protection 1 and 3.
3723 *
3724 * Returns nothing
3725 */
3726static void
3727_scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3728{
3729 u16 eedp_flags;
3730 unsigned char prot_op = scsi_get_prot_op(scmd);
3731 unsigned char prot_type = scsi_get_prot_type(scmd);
3732
Eric Moored334aa72010-04-22 10:47:40 -06003733 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
Eric Moore3c621b32009-05-18 12:59:41 -06003734 return;
3735
3736 if (prot_op == SCSI_PROT_READ_STRIP)
3737 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3738 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3739 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3740 else
3741 return;
3742
Eric Moore3c621b32009-05-18 12:59:41 -06003743 switch (prot_type) {
3744 case SCSI_PROT_DIF_TYPE1:
Martin K. Petersen756aca72011-05-18 00:45:22 -04003745 case SCSI_PROT_DIF_TYPE2:
Eric Moore3c621b32009-05-18 12:59:41 -06003746
3747 /*
3748 * enable ref/guard checking
3749 * auto increment ref tag
3750 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303751 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
Eric Moore3c621b32009-05-18 12:59:41 -06003752 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3753 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3754 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3755 cpu_to_be32(scsi_get_lba(scmd));
Eric Moored334aa72010-04-22 10:47:40 -06003756 break;
Eric Moore3c621b32009-05-18 12:59:41 -06003757
Eric Moore3c621b32009-05-18 12:59:41 -06003758 case SCSI_PROT_DIF_TYPE3:
3759
3760 /*
3761 * enable guard checking
3762 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303763 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
Eric Moore3c621b32009-05-18 12:59:41 -06003764 break;
3765 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05303766 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3767 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
Eric Moore3c621b32009-05-18 12:59:41 -06003768}
3769
3770/**
3771 * _scsih_eedp_error_handling - return sense code for EEDP errors
3772 * @scmd: pointer to scsi command object
3773 * @ioc_status: ioc status
3774 *
3775 * Returns nothing
3776 */
3777static void
3778_scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3779{
3780 u8 ascq;
Eric Moore3c621b32009-05-18 12:59:41 -06003781
3782 switch (ioc_status) {
3783 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3784 ascq = 0x01;
3785 break;
3786 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3787 ascq = 0x02;
3788 break;
3789 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3790 ascq = 0x03;
3791 break;
3792 default:
3793 ascq = 0x00;
3794 break;
3795 }
3796
Martin K. Petersen9b5cd132012-08-28 14:29:36 -04003797 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq);
3798 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
Eric Moore3c621b32009-05-18 12:59:41 -06003799 SAM_STAT_CHECK_CONDITION;
3800}
3801
3802/**
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303803 * _scsih_scsi_direct_io_get - returns direct io flag
3804 * @ioc: per adapter object
3805 * @smid: system request message index
3806 *
3807 * Returns the smid stored scmd pointer.
3808 */
3809static inline u8
3810_scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3811{
3812 return ioc->scsi_lookup[smid - 1].direct_io;
3813}
3814
3815/**
3816 * _scsih_scsi_direct_io_set - sets direct io flag
3817 * @ioc: per adapter object
3818 * @smid: system request message index
3819 * @direct_io: Zero or non-zero value to set in the direct_io flag
3820 *
3821 * Returns Nothing.
3822 */
3823static inline void
3824_scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3825{
3826 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3827}
3828
3829
3830/**
3831 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3832 * @ioc: per adapter object
3833 * @scmd: pointer to scsi command object
3834 * @raid_device: pointer to raid device data structure
3835 * @mpi_request: pointer to the SCSI_IO reqest message frame
3836 * @smid: system request message index
3837 *
3838 * Returns nothing
3839 */
3840static void
3841_scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3842 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3843 u16 smid)
3844{
Sreekanth Reddyf78f6942014-09-19 12:17:27 +05303845 sector_t v_lba, p_lba, stripe_off, column, io_size;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303846 u32 stripe_sz, stripe_exp;
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303847 u8 num_pds, cmd = scmd->cmnd[0];
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303848
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303849 if (cmd != READ_10 && cmd != WRITE_10 &&
3850 cmd != READ_16 && cmd != WRITE_16)
3851 return;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303852
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303853 if (cmd == READ_10 || cmd == WRITE_10)
3854 v_lba = get_unaligned_be32(&mpi_request->CDB.CDB32[2]);
3855 else
3856 v_lba = get_unaligned_be64(&mpi_request->CDB.CDB32[2]);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303857
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303858 io_size = scsi_bufflen(scmd) >> raid_device->block_exponent;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303859
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303860 if (v_lba + io_size - 1 > raid_device->max_lba)
3861 return;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303862
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303863 stripe_sz = raid_device->stripe_sz;
3864 stripe_exp = raid_device->stripe_exponent;
3865 stripe_off = v_lba & (stripe_sz - 1);
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303866
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303867 /* Return unless IO falls within a stripe */
3868 if (stripe_off + io_size > stripe_sz)
3869 return;
3870
3871 num_pds = raid_device->num_pds;
3872 p_lba = v_lba >> stripe_exp;
Sreekanth Reddyf78f6942014-09-19 12:17:27 +05303873 column = sector_div(p_lba, num_pds);
3874 p_lba = (p_lba << stripe_exp) + stripe_off;
3875
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303876 mpi_request->DevHandle = cpu_to_le16(raid_device->pd_handle[column]);
3877
3878 if (cmd == READ_10 || cmd == WRITE_10)
3879 put_unaligned_be32(lower_32_bits(p_lba),
3880 &mpi_request->CDB.CDB32[2]);
3881 else
3882 put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]);
3883
3884 _scsih_scsi_direct_io_set(ioc, smid, 1);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303885}
3886
3887/**
Eric Moored5d135b2009-05-18 13:02:08 -06003888 * _scsih_qcmd - main scsi request entry point
Eric Moore635374e2009-03-09 01:21:12 -06003889 * @scmd: pointer to scsi command object
3890 * @done: function pointer to be invoked on completion
3891 *
3892 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3893 *
3894 * Returns 0 on success. If there's a failure, return either:
3895 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3896 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3897 */
3898static int
Matthew Wilcox90f951e2014-03-27 16:40:33 -04003899_scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06003900{
Matthew Wilcox90f951e2014-03-27 16:40:33 -04003901 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Eric Moore635374e2009-03-09 01:21:12 -06003902 struct MPT2SAS_DEVICE *sas_device_priv_data;
3903 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303904 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06003905 Mpi2SCSIIORequest_t *mpi_request;
3906 u32 mpi_control;
3907 u16 smid;
Eric Moore635374e2009-03-09 01:21:12 -06003908
Eric Moore635374e2009-03-09 01:21:12 -06003909 sas_device_priv_data = scmd->device->hostdata;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303910 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Eric Moore635374e2009-03-09 01:21:12 -06003911 scmd->result = DID_NO_CONNECT << 16;
3912 scmd->scsi_done(scmd);
3913 return 0;
3914 }
3915
Kashyap, Desai78215782011-06-14 10:57:08 +05303916 if (ioc->pci_error_recovery || ioc->remove_host) {
Eric Moore3cb54692010-07-08 14:44:34 -06003917 scmd->result = DID_NO_CONNECT << 16;
3918 scmd->scsi_done(scmd);
3919 return 0;
3920 }
3921
Eric Moore635374e2009-03-09 01:21:12 -06003922 sas_target_priv_data = sas_device_priv_data->sas_target;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303923 /* invalid device handle */
3924 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
Eric Moore635374e2009-03-09 01:21:12 -06003925 scmd->result = DID_NO_CONNECT << 16;
3926 scmd->scsi_done(scmd);
3927 return 0;
3928 }
3929
Kashyap, Desai130b9582010-04-08 17:54:32 +05303930 /* host recovery or link resets sent via IOCTLs */
3931 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
Eric Moore635374e2009-03-09 01:21:12 -06003932 return SCSI_MLQUEUE_HOST_BUSY;
Uwe Kleine-König65155b32010-06-11 12:17:01 +02003933 /* device busy with task management */
Kashyap, Desai130b9582010-04-08 17:54:32 +05303934 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3935 return SCSI_MLQUEUE_DEVICE_BUSY;
3936 /* device has been deleted */
3937 else if (sas_target_priv_data->deleted) {
3938 scmd->result = DID_NO_CONNECT << 16;
3939 scmd->scsi_done(scmd);
3940 return 0;
3941 }
Eric Moore635374e2009-03-09 01:21:12 -06003942
3943 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3944 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3945 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3946 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3947 else
3948 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3949
3950 /* set tags */
Christoph Hellwig609aa222014-10-30 11:54:58 +01003951 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3952
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303953 /* Make sure Device is not raid volume.
3954 * We do not expose raid functionality to upper layer for warpdrive.
3955 */
3956 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Eric Moored334aa72010-04-22 10:47:40 -06003957 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
Eric Moore635374e2009-03-09 01:21:12 -06003958 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3959
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303960 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06003961 if (!smid) {
3962 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3963 ioc->name, __func__);
3964 goto out;
3965 }
3966 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3967 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
Eric Moore3c621b32009-05-18 12:59:41 -06003968 _scsih_setup_eedp(scmd, mpi_request);
Eric Moored334aa72010-04-22 10:47:40 -06003969 if (scmd->cmd_len == 32)
3970 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
Eric Moore635374e2009-03-09 01:21:12 -06003971 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3972 if (sas_device_priv_data->sas_target->flags &
3973 MPT_TARGET_FLAGS_RAID_COMPONENT)
3974 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3975 else
Matthew Wilcox90f951e2014-03-27 16:40:33 -04003976 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
Eric Moore635374e2009-03-09 01:21:12 -06003977 mpi_request->DevHandle =
3978 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3979 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3980 mpi_request->Control = cpu_to_le32(mpi_control);
3981 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3982 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3983 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3984 mpi_request->SenseBufferLowAddress =
Kashyap, Desaiec9472c2009-09-23 17:34:13 +05303985 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003986 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3987 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3988 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05303989 mpi_request->VF_ID = 0; /* TODO */
3990 mpi_request->VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06003991 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3992 mpi_request->LUN);
3993 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3994
3995 if (!mpi_request->DataLength) {
3996 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
3997 } else {
3998 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
3999 mpt2sas_base_free_smid(ioc, smid);
4000 goto out;
4001 }
4002 }
4003
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304004 raid_device = sas_target_priv_data->raid_device;
4005 if (raid_device && raid_device->direct_io_enabled)
4006 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4007 smid);
4008
Kashyap, Desai58287fd2010-03-17 16:27:25 +05304009 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
4010 mpt2sas_base_put_smid_scsi_io(ioc, smid,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304011 le16_to_cpu(mpi_request->DevHandle));
Kashyap, Desai58287fd2010-03-17 16:27:25 +05304012 else
4013 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004014 return 0;
4015
4016 out:
4017 return SCSI_MLQUEUE_HOST_BUSY;
4018}
4019
4020/**
4021 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4022 * @sense_buffer: sense data returned by target
4023 * @data: normalized skey/asc/ascq
4024 *
4025 * Return nothing.
4026 */
4027static void
4028_scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4029{
4030 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4031 /* descriptor format */
4032 data->skey = sense_buffer[1] & 0x0F;
4033 data->asc = sense_buffer[2];
4034 data->ascq = sense_buffer[3];
4035 } else {
4036 /* fixed format */
4037 data->skey = sense_buffer[2] & 0x0F;
4038 data->asc = sense_buffer[12];
4039 data->ascq = sense_buffer[13];
4040 }
4041}
4042
4043#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4044/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004045 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
Eric Moore635374e2009-03-09 01:21:12 -06004046 * @ioc: per adapter object
4047 * @scmd: pointer to scsi command object
4048 * @mpi_reply: reply mf payload returned from firmware
4049 *
4050 * scsi_status - SCSI Status code returned from target device
4051 * scsi_state - state info associated with SCSI_IO determined by ioc
4052 * ioc_status - ioc supplied status info
4053 *
4054 * Return nothing.
4055 */
4056static void
4057_scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4058 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4059{
4060 u32 response_info;
4061 u8 *response_bytes;
4062 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4063 MPI2_IOCSTATUS_MASK;
4064 u8 scsi_state = mpi_reply->SCSIState;
4065 u8 scsi_status = mpi_reply->SCSIStatus;
4066 char *desc_ioc_state = NULL;
4067 char *desc_scsi_status = NULL;
4068 char *desc_scsi_state = ioc->tmp_string;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304069 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304070 struct _sas_device *sas_device = NULL;
4071 unsigned long flags;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304072 struct scsi_target *starget = scmd->device->sdev_target;
4073 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304074 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304075
4076 if (!priv_target)
4077 return;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304078
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304079 if (ioc->hide_ir_msg)
4080 device_str = "WarpDrive";
4081 else
4082 device_str = "volume";
4083
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304084 if (log_info == 0x31170000)
4085 return;
Eric Moore635374e2009-03-09 01:21:12 -06004086
4087 switch (ioc_status) {
4088 case MPI2_IOCSTATUS_SUCCESS:
4089 desc_ioc_state = "success";
4090 break;
4091 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4092 desc_ioc_state = "invalid function";
4093 break;
4094 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4095 desc_ioc_state = "scsi recovered error";
4096 break;
4097 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4098 desc_ioc_state = "scsi invalid dev handle";
4099 break;
4100 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4101 desc_ioc_state = "scsi device not there";
4102 break;
4103 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4104 desc_ioc_state = "scsi data overrun";
4105 break;
4106 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4107 desc_ioc_state = "scsi data underrun";
4108 break;
4109 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4110 desc_ioc_state = "scsi io data error";
4111 break;
4112 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4113 desc_ioc_state = "scsi protocol error";
4114 break;
4115 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4116 desc_ioc_state = "scsi task terminated";
4117 break;
4118 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4119 desc_ioc_state = "scsi residual mismatch";
4120 break;
4121 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4122 desc_ioc_state = "scsi task mgmt failed";
4123 break;
4124 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4125 desc_ioc_state = "scsi ioc terminated";
4126 break;
4127 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4128 desc_ioc_state = "scsi ext terminated";
4129 break;
Eric Moore3c621b32009-05-18 12:59:41 -06004130 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4131 desc_ioc_state = "eedp guard error";
4132 break;
4133 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4134 desc_ioc_state = "eedp ref tag error";
4135 break;
4136 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4137 desc_ioc_state = "eedp app tag error";
4138 break;
Eric Moore635374e2009-03-09 01:21:12 -06004139 default:
4140 desc_ioc_state = "unknown";
4141 break;
4142 }
4143
4144 switch (scsi_status) {
4145 case MPI2_SCSI_STATUS_GOOD:
4146 desc_scsi_status = "good";
4147 break;
4148 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4149 desc_scsi_status = "check condition";
4150 break;
4151 case MPI2_SCSI_STATUS_CONDITION_MET:
4152 desc_scsi_status = "condition met";
4153 break;
4154 case MPI2_SCSI_STATUS_BUSY:
4155 desc_scsi_status = "busy";
4156 break;
4157 case MPI2_SCSI_STATUS_INTERMEDIATE:
4158 desc_scsi_status = "intermediate";
4159 break;
4160 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4161 desc_scsi_status = "intermediate condmet";
4162 break;
4163 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4164 desc_scsi_status = "reservation conflict";
4165 break;
4166 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4167 desc_scsi_status = "command terminated";
4168 break;
4169 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4170 desc_scsi_status = "task set full";
4171 break;
4172 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4173 desc_scsi_status = "aca active";
4174 break;
4175 case MPI2_SCSI_STATUS_TASK_ABORTED:
4176 desc_scsi_status = "task aborted";
4177 break;
4178 default:
4179 desc_scsi_status = "unknown";
4180 break;
4181 }
4182
4183 desc_scsi_state[0] = '\0';
4184 if (!scsi_state)
4185 desc_scsi_state = " ";
4186 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4187 strcat(desc_scsi_state, "response info ");
4188 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4189 strcat(desc_scsi_state, "state terminated ");
4190 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4191 strcat(desc_scsi_state, "no status ");
4192 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4193 strcat(desc_scsi_state, "autosense failed ");
4194 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4195 strcat(desc_scsi_state, "autosense valid ");
4196
4197 scsi_print_command(scmd);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304198
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304199 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304200 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4201 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304202 } else {
4203 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4204 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4205 priv_target->sas_address);
4206 if (sas_device) {
4207 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4208 "phy(%d)\n", ioc->name, sas_device->sas_address,
4209 sas_device->phy);
4210 printk(MPT2SAS_WARN_FMT
4211 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4212 ioc->name, sas_device->enclosure_logical_id,
4213 sas_device->slot);
4214 }
4215 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304216 }
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304217
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304218 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4219 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4220 desc_ioc_state, ioc_status, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004221 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4222 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4223 scsi_get_resid(scmd));
4224 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4225 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4226 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4227 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4228 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4229 scsi_status, desc_scsi_state, scsi_state);
4230
4231 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4232 struct sense_info data;
4233 _scsih_normalize_sense(scmd->sense_buffer, &data);
4234 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
Kashyap, Desaie94f6742010-03-17 16:24:52 +05304235 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4236 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
Eric Moore635374e2009-03-09 01:21:12 -06004237 }
4238
4239 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4240 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4241 response_bytes = (u8 *)&response_info;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304242 _scsih_response_code(ioc, response_bytes[0]);
Eric Moore635374e2009-03-09 01:21:12 -06004243 }
4244}
4245#endif
4246
4247/**
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304248 * _scsih_turn_on_pfa_led - illuminate PFA LED
Eric Moore635374e2009-03-09 01:21:12 -06004249 * @ioc: per adapter object
4250 * @handle: device handle
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304251 * Context: process
4252 *
4253 * Return nothing.
4254 */
4255static void
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304256_scsih_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304257{
4258 Mpi2SepReply_t mpi_reply;
4259 Mpi2SepRequest_t mpi_request;
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304260 struct _sas_device *sas_device;
4261
4262 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4263 if (!sas_device)
4264 return;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304265
4266 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4267 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4268 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4269 mpi_request.SlotStatus =
4270 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4271 mpi_request.DevHandle = cpu_to_le16(handle);
4272 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4273 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4274 &mpi_request)) != 0) {
4275 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4276 __FILE__, __LINE__, __func__);
4277 return;
4278 }
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304279 sas_device->pfa_led_on = 1;
4280
4281
4282 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4283 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
4284 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4285 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4286 le32_to_cpu(mpi_reply.IOCLogInfo)));
4287 return;
4288 }
4289}
4290
4291/**
4292 * _scsih_turn_off_pfa_led - turn off PFA LED
4293 * @ioc: per adapter object
4294 * @sas_device: sas device whose PFA LED has to turned off
4295 * Context: process
4296 *
4297 * Return nothing.
4298 */
4299static void
4300_scsih_turn_off_pfa_led(struct MPT2SAS_ADAPTER *ioc,
4301 struct _sas_device *sas_device)
4302{
4303 Mpi2SepReply_t mpi_reply;
4304 Mpi2SepRequest_t mpi_request;
4305
4306 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4307 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4308 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4309 mpi_request.SlotStatus = 0;
4310 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4311 mpi_request.DevHandle = 0;
4312 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4313 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4314 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4315 &mpi_request)) != 0) {
4316 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4317 __FILE__, __LINE__, __func__);
4318 return;
4319 }
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304320
4321 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4322 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4323 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4324 le16_to_cpu(mpi_reply.IOCStatus),
4325 le32_to_cpu(mpi_reply.IOCLogInfo)));
4326 return;
4327 }
4328}
4329
4330/**
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304331 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304332 * @ioc: per adapter object
4333 * @handle: device handle
4334 * Context: interrupt.
4335 *
4336 * Return nothing.
4337 */
4338static void
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304339_scsih_send_event_to_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304340{
4341 struct fw_event_work *fw_event;
4342
4343 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4344 if (!fw_event)
4345 return;
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304346 fw_event->event = MPT2SAS_TURN_ON_PFA_LED;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304347 fw_event->device_handle = handle;
4348 fw_event->ioc = ioc;
4349 _scsih_fw_event_add(ioc, fw_event);
4350}
4351
4352/**
4353 * _scsih_smart_predicted_fault - process smart errors
4354 * @ioc: per adapter object
4355 * @handle: device handle
4356 * Context: interrupt.
Eric Moore635374e2009-03-09 01:21:12 -06004357 *
4358 * Return nothing.
4359 */
4360static void
4361_scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4362{
Eric Moore635374e2009-03-09 01:21:12 -06004363 struct scsi_target *starget;
4364 struct MPT2SAS_TARGET *sas_target_priv_data;
4365 Mpi2EventNotificationReply_t *event_reply;
4366 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4367 struct _sas_device *sas_device;
4368 ssize_t sz;
4369 unsigned long flags;
4370
4371 /* only handle non-raid devices */
4372 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4373 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4374 if (!sas_device) {
4375 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4376 return;
4377 }
4378 starget = sas_device->starget;
4379 sas_target_priv_data = starget->hostdata;
4380
4381 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4382 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4383 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4384 return;
4385 }
4386 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4387 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4388
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304389 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304390 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06004391
4392 /* insert into event log */
4393 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4394 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
Anton Blanchardf6a290b42011-11-07 22:05:21 +11004395 event_reply = kzalloc(sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06004396 if (!event_reply) {
4397 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4398 ioc->name, __FILE__, __LINE__, __func__);
4399 return;
4400 }
4401
4402 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4403 event_reply->Event =
4404 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4405 event_reply->MsgLength = sz/4;
4406 event_reply->EventDataLength =
4407 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4408 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4409 event_reply->EventData;
4410 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4411 event_data->ASC = 0x5D;
4412 event_data->DevHandle = cpu_to_le16(handle);
4413 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4414 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4415 kfree(event_reply);
4416}
4417
4418/**
Eric Moored5d135b2009-05-18 13:02:08 -06004419 * _scsih_io_done - scsi request callback
Eric Moore635374e2009-03-09 01:21:12 -06004420 * @ioc: per adapter object
4421 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304422 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06004423 * @reply: reply message frame(lower 32bit addr)
4424 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304425 * Callback handler when using _scsih_qcmd.
Eric Moore635374e2009-03-09 01:21:12 -06004426 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304427 * Return 1 meaning mf should be freed from _base_interrupt
4428 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06004429 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304430static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304431_scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06004432{
4433 Mpi2SCSIIORequest_t *mpi_request;
4434 Mpi2SCSIIOReply_t *mpi_reply;
4435 struct scsi_cmnd *scmd;
4436 u16 ioc_status;
4437 u32 xfer_cnt;
4438 u8 scsi_state;
4439 u8 scsi_status;
4440 u32 log_info;
4441 struct MPT2SAS_DEVICE *sas_device_priv_data;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304442 u32 response_code = 0;
Kashyap, Desai82a45252011-07-05 12:40:23 +05304443 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06004444
4445 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05304446 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004447 if (scmd == NULL)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304448 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004449
4450 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4451
4452 if (mpi_reply == NULL) {
4453 scmd->result = DID_OK << 16;
4454 goto out;
4455 }
4456
4457 sas_device_priv_data = scmd->device->hostdata;
4458 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4459 sas_device_priv_data->sas_target->deleted) {
4460 scmd->result = DID_NO_CONNECT << 16;
4461 goto out;
4462 }
nagalakshmi.nandigama@lsi.com4da7af92011-12-01 07:53:02 +05304463 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304464 /*
4465 * WARPDRIVE: If direct_io is set then it is directIO,
4466 * the failed direct I/O should be redirected to volume
4467 */
nagalakshmi.nandigama@lsi.com4da7af92011-12-01 07:53:02 +05304468 if (_scsih_scsi_direct_io_get(ioc, smid) &&
4469 ((ioc_status & MPI2_IOCSTATUS_MASK)
4470 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
Kashyap, Desai82a45252011-07-05 12:40:23 +05304471 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4472 ioc->scsi_lookup[smid - 1].scmd = scmd;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304473 _scsih_scsi_direct_io_set(ioc, smid, 0);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05304474 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304475 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4476 mpi_request->DevHandle =
4477 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4478 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4479 sas_device_priv_data->sas_target->handle);
4480 return 0;
4481 }
4482
Eric Moore635374e2009-03-09 01:21:12 -06004483
4484 /* turning off TLR */
Kashyap, Desai9982f592009-09-23 17:23:07 +05304485 scsi_state = mpi_reply->SCSIState;
4486 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4487 response_code =
4488 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
Eric Moore635374e2009-03-09 01:21:12 -06004489 if (!sas_device_priv_data->tlr_snoop_check) {
4490 sas_device_priv_data->tlr_snoop_check++;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304491 /* Make sure Device is not raid volume.
4492 * We do not expose raid functionality to upper layer for warpdrive.
4493 */
4494 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Kashyap, Desai3ed21522010-02-17 16:08:36 +05304495 sas_is_tlr_enabled(scmd->device) &&
Kashyap, Desai84f0b042009-12-16 18:56:28 +05304496 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4497 sas_disable_tlr(scmd->device);
4498 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4499 }
Eric Moore635374e2009-03-09 01:21:12 -06004500 }
4501
4502 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4503 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
Eric Moore635374e2009-03-09 01:21:12 -06004504 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4505 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4506 else
4507 log_info = 0;
4508 ioc_status &= MPI2_IOCSTATUS_MASK;
Eric Moore635374e2009-03-09 01:21:12 -06004509 scsi_status = mpi_reply->SCSIStatus;
4510
4511 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4512 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4513 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4514 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4515 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4516 }
4517
4518 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4519 struct sense_info data;
4520 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4521 smid);
Eric Moore0d04df92009-04-21 15:38:43 -06004522 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
Eric Moore635374e2009-03-09 01:21:12 -06004523 le32_to_cpu(mpi_reply->SenseCount));
Eric Moore0d04df92009-04-21 15:38:43 -06004524 memcpy(scmd->sense_buffer, sense_data, sz);
Eric Moore635374e2009-03-09 01:21:12 -06004525 _scsih_normalize_sense(scmd->sense_buffer, &data);
4526 /* failure prediction threshold exceeded */
4527 if (data.asc == 0x5D)
4528 _scsih_smart_predicted_fault(ioc,
4529 le16_to_cpu(mpi_reply->DevHandle));
4530 }
4531
4532 switch (ioc_status) {
4533 case MPI2_IOCSTATUS_BUSY:
4534 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4535 scmd->result = SAM_STAT_BUSY;
4536 break;
4537
4538 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4539 scmd->result = DID_NO_CONNECT << 16;
4540 break;
4541
4542 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4543 if (sas_device_priv_data->block) {
Kashyap, Desaie4e7c7e2009-09-23 17:33:14 +05304544 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4545 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06004546 }
Sreekanth Reddyd2227f72015-01-12 11:39:01 +05304547 if (log_info == 0x32010081) {
4548 scmd->result = DID_RESET << 16;
4549 break;
4550 }
nagalakshmi.nandigama@lsi.com3ade1ca2011-12-01 07:42:40 +05304551 scmd->result = DID_SOFT_ERROR << 16;
4552 break;
Eric Moore635374e2009-03-09 01:21:12 -06004553 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4554 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4555 scmd->result = DID_RESET << 16;
4556 break;
4557
4558 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4559 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4560 scmd->result = DID_SOFT_ERROR << 16;
4561 else
4562 scmd->result = (DID_OK << 16) | scsi_status;
4563 break;
4564
4565 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4566 scmd->result = (DID_OK << 16) | scsi_status;
4567
4568 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4569 break;
4570
4571 if (xfer_cnt < scmd->underflow) {
4572 if (scsi_status == SAM_STAT_BUSY)
4573 scmd->result = SAM_STAT_BUSY;
4574 else
4575 scmd->result = DID_SOFT_ERROR << 16;
4576 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4577 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4578 scmd->result = DID_SOFT_ERROR << 16;
4579 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4580 scmd->result = DID_RESET << 16;
4581 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4582 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4583 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4584 scmd->result = (DRIVER_SENSE << 24) |
4585 SAM_STAT_CHECK_CONDITION;
4586 scmd->sense_buffer[0] = 0x70;
4587 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4588 scmd->sense_buffer[12] = 0x20;
4589 scmd->sense_buffer[13] = 0;
4590 }
4591 break;
4592
4593 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4594 scsi_set_resid(scmd, 0);
4595 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4596 case MPI2_IOCSTATUS_SUCCESS:
4597 scmd->result = (DID_OK << 16) | scsi_status;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304598 if (response_code ==
4599 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4600 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4601 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
Eric Moore635374e2009-03-09 01:21:12 -06004602 scmd->result = DID_SOFT_ERROR << 16;
4603 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4604 scmd->result = DID_RESET << 16;
4605 break;
4606
Eric Moore3c621b32009-05-18 12:59:41 -06004607 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4608 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4609 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4610 _scsih_eedp_error_handling(scmd, ioc_status);
4611 break;
Eric Moore635374e2009-03-09 01:21:12 -06004612 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4613 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4614 case MPI2_IOCSTATUS_INVALID_SGL:
4615 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4616 case MPI2_IOCSTATUS_INVALID_FIELD:
4617 case MPI2_IOCSTATUS_INVALID_STATE:
4618 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4619 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4620 default:
4621 scmd->result = DID_SOFT_ERROR << 16;
4622 break;
4623
4624 }
4625
4626#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4627 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4628 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4629#endif
4630
4631 out:
4632 scsi_dma_unmap(scmd);
4633 scmd->scsi_done(scmd);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304634 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004635}
4636
4637/**
Eric Moore635374e2009-03-09 01:21:12 -06004638 * _scsih_sas_host_refresh - refreshing sas host object contents
4639 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06004640 * Context: user
4641 *
4642 * During port enable, fw will send topology events for every device. Its
4643 * possible that the handles may change from the previous setting, so this
4644 * code keeping handles updating if changed.
4645 *
4646 * Return nothing.
4647 */
4648static void
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304649_scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06004650{
4651 u16 sz;
4652 u16 ioc_status;
4653 int i;
4654 Mpi2ConfigReply_t mpi_reply;
4655 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304656 u16 attached_handle;
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304657 u8 link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06004658
4659 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4660 "updating handles for sas_host(0x%016llx)\n",
4661 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4662
4663 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4664 * sizeof(Mpi2SasIOUnit0PhyData_t));
4665 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4666 if (!sas_iounit_pg0) {
4667 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4668 ioc->name, __FILE__, __LINE__, __func__);
4669 return;
4670 }
Eric Moore635374e2009-03-09 01:21:12 -06004671
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304672 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4673 sas_iounit_pg0, sz)) != 0)
4674 goto out;
4675 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4676 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4677 goto out;
4678 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304679 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304680 if (i == 0)
4681 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4682 PhyData[0].ControllerDevHandle);
4683 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4684 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4685 AttachedDevHandle);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304686 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4687 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304688 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304689 attached_handle, i, link_rate);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304690 }
Eric Moore635374e2009-03-09 01:21:12 -06004691 out:
4692 kfree(sas_iounit_pg0);
4693}
4694
4695/**
4696 * _scsih_sas_host_add - create sas host object
4697 * @ioc: per adapter object
4698 *
4699 * Creating host side data object, stored in ioc->sas_hba
4700 *
4701 * Return nothing.
4702 */
4703static void
4704_scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4705{
4706 int i;
4707 Mpi2ConfigReply_t mpi_reply;
4708 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4709 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4710 Mpi2SasPhyPage0_t phy_pg0;
4711 Mpi2SasDevicePage0_t sas_device_pg0;
4712 Mpi2SasEnclosurePage0_t enclosure_pg0;
4713 u16 ioc_status;
4714 u16 sz;
4715 u16 device_missing_delay;
4716
4717 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4718 if (!ioc->sas_hba.num_phys) {
4719 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4720 ioc->name, __FILE__, __LINE__, __func__);
4721 return;
4722 }
4723
4724 /* sas_iounit page 0 */
4725 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4726 sizeof(Mpi2SasIOUnit0PhyData_t));
4727 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4728 if (!sas_iounit_pg0) {
4729 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4730 ioc->name, __FILE__, __LINE__, __func__);
4731 return;
4732 }
4733 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4734 sas_iounit_pg0, sz))) {
4735 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4736 ioc->name, __FILE__, __LINE__, __func__);
4737 goto out;
4738 }
4739 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4740 MPI2_IOCSTATUS_MASK;
4741 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4742 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4743 ioc->name, __FILE__, __LINE__, __func__);
4744 goto out;
4745 }
4746
4747 /* sas_iounit page 1 */
4748 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4749 sizeof(Mpi2SasIOUnit1PhyData_t));
4750 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4751 if (!sas_iounit_pg1) {
4752 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4753 ioc->name, __FILE__, __LINE__, __func__);
4754 goto out;
4755 }
4756 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4757 sas_iounit_pg1, sz))) {
4758 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4759 ioc->name, __FILE__, __LINE__, __func__);
4760 goto out;
4761 }
4762 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4763 MPI2_IOCSTATUS_MASK;
4764 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4765 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4766 ioc->name, __FILE__, __LINE__, __func__);
4767 goto out;
4768 }
4769
4770 ioc->io_missing_delay =
4771 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4772 device_missing_delay =
4773 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4774 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4775 ioc->device_missing_delay = (device_missing_delay &
4776 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4777 else
4778 ioc->device_missing_delay = device_missing_delay &
4779 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4780
4781 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4782 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4783 sizeof(struct _sas_phy), GFP_KERNEL);
4784 if (!ioc->sas_hba.phy) {
4785 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4786 ioc->name, __FILE__, __LINE__, __func__);
4787 goto out;
4788 }
4789 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4790 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4791 i))) {
4792 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4793 ioc->name, __FILE__, __LINE__, __func__);
4794 goto out;
4795 }
4796 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4797 MPI2_IOCSTATUS_MASK;
4798 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4799 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4800 ioc->name, __FILE__, __LINE__, __func__);
4801 goto out;
4802 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304803
4804 if (i == 0)
4805 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4806 PhyData[0].ControllerDevHandle);
4807 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
Eric Moore635374e2009-03-09 01:21:12 -06004808 ioc->sas_hba.phy[i].phy_id = i;
4809 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4810 phy_pg0, ioc->sas_hba.parent_dev);
4811 }
4812 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304813 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06004814 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4815 ioc->name, __FILE__, __LINE__, __func__);
4816 goto out;
4817 }
Eric Moore635374e2009-03-09 01:21:12 -06004818 ioc->sas_hba.enclosure_handle =
4819 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4820 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4821 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4822 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4823 (unsigned long long) ioc->sas_hba.sas_address,
4824 ioc->sas_hba.num_phys) ;
4825
4826 if (ioc->sas_hba.enclosure_handle) {
4827 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4828 &enclosure_pg0,
4829 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4830 ioc->sas_hba.enclosure_handle))) {
4831 ioc->sas_hba.enclosure_logical_id =
4832 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4833 }
4834 }
4835
4836 out:
4837 kfree(sas_iounit_pg1);
4838 kfree(sas_iounit_pg0);
4839}
4840
4841/**
4842 * _scsih_expander_add - creating expander object
4843 * @ioc: per adapter object
4844 * @handle: expander handle
4845 *
4846 * Creating expander object, stored in ioc->sas_expander_list.
4847 *
4848 * Return 0 for success, else error.
4849 */
4850static int
4851_scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4852{
4853 struct _sas_node *sas_expander;
4854 Mpi2ConfigReply_t mpi_reply;
4855 Mpi2ExpanderPage0_t expander_pg0;
4856 Mpi2ExpanderPage1_t expander_pg1;
4857 Mpi2SasEnclosurePage0_t enclosure_pg0;
4858 u32 ioc_status;
4859 u16 parent_handle;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05304860 u64 sas_address, sas_address_parent = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004861 int i;
4862 unsigned long flags;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304863 struct _sas_port *mpt2sas_port = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06004864 int rc = 0;
4865
4866 if (!handle)
4867 return -1;
4868
Eric Moore3cb54692010-07-08 14:44:34 -06004869 if (ioc->shost_recovery || ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05304870 return -1;
4871
Eric Moore635374e2009-03-09 01:21:12 -06004872 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4873 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4874 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4875 ioc->name, __FILE__, __LINE__, __func__);
4876 return -1;
4877 }
4878
4879 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4880 MPI2_IOCSTATUS_MASK;
4881 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4882 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4883 ioc->name, __FILE__, __LINE__, __func__);
4884 return -1;
4885 }
4886
4887 /* handle out of order topology events */
4888 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304889 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4890 != 0) {
4891 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4892 ioc->name, __FILE__, __LINE__, __func__);
4893 return -1;
4894 }
4895 if (sas_address_parent != ioc->sas_hba.sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06004896 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304897 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4898 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004899 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4900 if (!sas_expander) {
4901 rc = _scsih_expander_add(ioc, parent_handle);
4902 if (rc != 0)
4903 return rc;
4904 }
4905 }
4906
Eric Moore635374e2009-03-09 01:21:12 -06004907 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304908 sas_address = le64_to_cpu(expander_pg0.SASAddress);
Eric Moore635374e2009-03-09 01:21:12 -06004909 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4910 sas_address);
4911 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4912
4913 if (sas_expander)
4914 return 0;
4915
4916 sas_expander = kzalloc(sizeof(struct _sas_node),
4917 GFP_KERNEL);
4918 if (!sas_expander) {
4919 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4920 ioc->name, __FILE__, __LINE__, __func__);
4921 return -1;
4922 }
4923
4924 sas_expander->handle = handle;
4925 sas_expander->num_phys = expander_pg0.NumPhys;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304926 sas_expander->sas_address_parent = sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06004927 sas_expander->sas_address = sas_address;
4928
4929 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4930 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304931 handle, parent_handle, (unsigned long long)
Eric Moore635374e2009-03-09 01:21:12 -06004932 sas_expander->sas_address, sas_expander->num_phys);
4933
4934 if (!sas_expander->num_phys)
4935 goto out_fail;
4936 sas_expander->phy = kcalloc(sas_expander->num_phys,
4937 sizeof(struct _sas_phy), GFP_KERNEL);
4938 if (!sas_expander->phy) {
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
4945 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4946 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304947 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004948 if (!mpt2sas_port) {
4949 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4950 ioc->name, __FILE__, __LINE__, __func__);
4951 rc = -1;
4952 goto out_fail;
4953 }
4954 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4955
4956 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4957 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4958 &expander_pg1, i, handle))) {
4959 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4960 ioc->name, __FILE__, __LINE__, __func__);
Kashyap, Desai20f58952009-08-07 19:34:26 +05304961 rc = -1;
4962 goto out_fail;
Eric Moore635374e2009-03-09 01:21:12 -06004963 }
4964 sas_expander->phy[i].handle = handle;
4965 sas_expander->phy[i].phy_id = i;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304966
4967 if ((mpt2sas_transport_add_expander_phy(ioc,
4968 &sas_expander->phy[i], expander_pg1,
4969 sas_expander->parent_dev))) {
4970 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4971 ioc->name, __FILE__, __LINE__, __func__);
4972 rc = -1;
4973 goto out_fail;
4974 }
Eric Moore635374e2009-03-09 01:21:12 -06004975 }
4976
4977 if (sas_expander->enclosure_handle) {
4978 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4979 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4980 sas_expander->enclosure_handle))) {
4981 sas_expander->enclosure_logical_id =
4982 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4983 }
4984 }
4985
4986 _scsih_expander_node_add(ioc, sas_expander);
4987 return 0;
4988
4989 out_fail:
4990
Kashyap, Desai20f58952009-08-07 19:34:26 +05304991 if (mpt2sas_port)
4992 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304993 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004994 kfree(sas_expander);
4995 return rc;
4996}
4997
4998/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05304999 * _scsih_done - scsih callback handler.
5000 * @ioc: per adapter object
5001 * @smid: system request message index
5002 * @msix_index: MSIX table index supplied by the OS
5003 * @reply: reply message frame(lower 32bit addr)
5004 *
5005 * Callback handler when sending internal generated message frames.
5006 * The callback index passed is `ioc->scsih_cb_idx`
5007 *
5008 * Return 1 meaning mf should be freed from _base_interrupt
5009 * 0 means the mf is freed from this function.
5010 */
5011static u8
5012_scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5013{
5014 MPI2DefaultReply_t *mpi_reply;
5015
5016 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5017 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
5018 return 1;
5019 if (ioc->scsih_cmds.smid != smid)
5020 return 1;
5021 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
5022 if (mpi_reply) {
5023 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5024 mpi_reply->MsgLength*4);
5025 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
5026 }
5027 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
5028 complete(&ioc->scsih_cmds.done);
5029 return 1;
5030}
5031
5032/**
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305033 * mpt2sas_expander_remove - removing expander object
Eric Moore635374e2009-03-09 01:21:12 -06005034 * @ioc: per adapter object
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305035 * @sas_address: expander sas_address
Eric Moore635374e2009-03-09 01:21:12 -06005036 *
5037 * Return nothing.
5038 */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305039void
5040mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06005041{
5042 struct _sas_node *sas_expander;
5043 unsigned long flags;
5044
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305045 if (ioc->shost_recovery)
5046 return;
5047
Eric Moore635374e2009-03-09 01:21:12 -06005048 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305049 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5050 sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305051 if (sas_expander)
5052 list_del(&sas_expander->list);
Eric Moore635374e2009-03-09 01:21:12 -06005053 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305054 if (sas_expander)
5055 _scsih_expander_node_remove(ioc, sas_expander);
Eric Moore635374e2009-03-09 01:21:12 -06005056}
5057
5058/**
Kashyap, Desaib4344272010-03-17 16:24:14 +05305059 * _scsih_check_access_status - check access flags
5060 * @ioc: per adapter object
5061 * @sas_address: sas address
5062 * @handle: sas device handle
5063 * @access_flags: errors returned during discovery of the device
5064 *
5065 * Return 0 for success, else failure
5066 */
5067static u8
5068_scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5069 u16 handle, u8 access_status)
5070{
5071 u8 rc = 1;
5072 char *desc = NULL;
5073
5074 switch (access_status) {
5075 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5076 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5077 rc = 0;
5078 break;
5079 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5080 desc = "sata capability failed";
5081 break;
5082 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5083 desc = "sata affiliation conflict";
5084 break;
5085 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5086 desc = "route not addressable";
5087 break;
5088 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5089 desc = "smp error not addressable";
5090 break;
5091 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5092 desc = "device blocked";
5093 break;
5094 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5095 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5096 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5097 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5098 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5099 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5100 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5101 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5102 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5103 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5104 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5105 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5106 desc = "sata initialization failed";
5107 break;
5108 default:
5109 desc = "unknown";
5110 break;
5111 }
5112
5113 if (!rc)
5114 return 0;
5115
5116 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5117 "handle(0x%04x)\n", ioc->name, desc,
5118 (unsigned long long)sas_address, handle);
5119 return rc;
5120}
5121
5122static void
5123_scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5124{
5125 Mpi2ConfigReply_t mpi_reply;
5126 Mpi2SasDevicePage0_t sas_device_pg0;
5127 struct _sas_device *sas_device;
5128 u32 ioc_status;
5129 unsigned long flags;
5130 u64 sas_address;
5131 struct scsi_target *starget;
5132 struct MPT2SAS_TARGET *sas_target_priv_data;
5133 u32 device_info;
5134
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305135
Kashyap, Desaib4344272010-03-17 16:24:14 +05305136 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5137 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5138 return;
5139
5140 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5141 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5142 return;
5143
5144 /* check if this is end device */
5145 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5146 if (!(_scsih_is_end_device(device_info)))
5147 return;
5148
5149 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5150 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5151 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5152 sas_address);
5153
5154 if (!sas_device) {
5155 printk(MPT2SAS_ERR_FMT "device is not present "
5156 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5157 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5158 return;
5159 }
5160
5161 if (unlikely(sas_device->handle != handle)) {
5162 starget = sas_device->starget;
5163 sas_target_priv_data = starget->hostdata;
5164 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5165 " to (0x%04x)!!!\n", sas_device->handle, handle);
5166 sas_target_priv_data->handle = handle;
5167 sas_device->handle = handle;
5168 }
Kashyap, Desaib4344272010-03-17 16:24:14 +05305169
5170 /* check if device is present */
5171 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5172 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5173 printk(MPT2SAS_ERR_FMT "device is not present "
5174 "handle(0x%04x), flags!!!\n", ioc->name, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305175 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305176 return;
5177 }
5178
5179 /* check if there were any issues with discovery */
5180 if (_scsih_check_access_status(ioc, sas_address, handle,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305181 sas_device_pg0.AccessStatus)) {
5182 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305183 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305184 }
5185 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05305186 _scsih_ublock_io_device(ioc, sas_address);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305187
5188}
5189
5190/**
Eric Moore635374e2009-03-09 01:21:12 -06005191 * _scsih_add_device - creating sas device object
5192 * @ioc: per adapter object
5193 * @handle: sas device handle
5194 * @phy_num: phy number end device attached to
5195 * @is_pd: is this hidden raid component
5196 *
5197 * Creating end device object, stored in ioc->sas_device_list.
5198 *
5199 * Returns 0 for success, non-zero for failure.
5200 */
5201static int
5202_scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5203{
5204 Mpi2ConfigReply_t mpi_reply;
5205 Mpi2SasDevicePage0_t sas_device_pg0;
5206 Mpi2SasEnclosurePage0_t enclosure_pg0;
5207 struct _sas_device *sas_device;
5208 u32 ioc_status;
5209 __le64 sas_address;
5210 u32 device_info;
5211 unsigned long flags;
5212
5213 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5214 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5215 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5216 ioc->name, __FILE__, __LINE__, __func__);
5217 return -1;
5218 }
5219
5220 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5221 MPI2_IOCSTATUS_MASK;
5222 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5223 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5224 ioc->name, __FILE__, __LINE__, __func__);
5225 return -1;
5226 }
5227
Kashyap, Desaib4344272010-03-17 16:24:14 +05305228 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5229
Eric Moore635374e2009-03-09 01:21:12 -06005230 /* check if device is present */
5231 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5232 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5233 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5234 ioc->name, __FILE__, __LINE__, __func__);
5235 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5236 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5237 return -1;
5238 }
5239
Kashyap, Desaib4344272010-03-17 16:24:14 +05305240 /* check if there were any issues with discovery */
5241 if (_scsih_check_access_status(ioc, sas_address, handle,
5242 sas_device_pg0.AccessStatus))
Eric Moore635374e2009-03-09 01:21:12 -06005243 return -1;
Eric Moore635374e2009-03-09 01:21:12 -06005244
5245 /* check if this is end device */
5246 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5247 if (!(_scsih_is_end_device(device_info))) {
5248 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5249 ioc->name, __FILE__, __LINE__, __func__);
5250 return -1;
5251 }
5252
Eric Moore635374e2009-03-09 01:21:12 -06005253
5254 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5255 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5256 sas_address);
5257 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5258
Kashyap, Desaib4344272010-03-17 16:24:14 +05305259 if (sas_device)
Eric Moore635374e2009-03-09 01:21:12 -06005260 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06005261
5262 sas_device = kzalloc(sizeof(struct _sas_device),
5263 GFP_KERNEL);
5264 if (!sas_device) {
5265 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5266 ioc->name, __FILE__, __LINE__, __func__);
5267 return -1;
5268 }
5269
5270 sas_device->handle = handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305271 if (_scsih_get_sas_address(ioc, le16_to_cpu
5272 (sas_device_pg0.ParentDevHandle),
5273 &sas_device->sas_address_parent) != 0)
5274 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5275 ioc->name, __FILE__, __LINE__, __func__);
Eric Moore635374e2009-03-09 01:21:12 -06005276 sas_device->enclosure_handle =
5277 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5278 sas_device->slot =
5279 le16_to_cpu(sas_device_pg0.Slot);
5280 sas_device->device_info = device_info;
5281 sas_device->sas_address = sas_address;
Kashyap, Desai7fbae672010-06-17 13:45:17 +05305282 sas_device->phy = sas_device_pg0.PhyNum;
Eric Moore635374e2009-03-09 01:21:12 -06005283
5284 /* get enclosure_logical_id */
Kashyap, Desai15052c92009-08-07 19:33:17 +05305285 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5286 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5287 sas_device->enclosure_handle)))
Eric Moore635374e2009-03-09 01:21:12 -06005288 sas_device->enclosure_logical_id =
5289 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
Eric Moore635374e2009-03-09 01:21:12 -06005290
5291 /* get device name */
5292 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5293
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305294 if (ioc->wait_for_discovery_to_complete)
Eric Moore635374e2009-03-09 01:21:12 -06005295 _scsih_sas_device_init_add(ioc, sas_device);
5296 else
5297 _scsih_sas_device_add(ioc, sas_device);
5298
5299 return 0;
5300}
5301
5302/**
Kashyap, Desai1278b112010-03-09 17:34:13 +05305303 * _scsih_remove_device - removing sas device object
5304 * @ioc: per adapter object
5305 * @sas_device_delete: the sas_device object
5306 *
5307 * Return nothing.
5308 */
5309static void
5310_scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5311 struct _sas_device *sas_device)
5312{
Kashyap, Desai1278b112010-03-09 17:34:13 +05305313 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05305314
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05305315 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5316 (sas_device->pfa_led_on)) {
5317 _scsih_turn_off_pfa_led(ioc, sas_device);
5318 sas_device->pfa_led_on = 0;
5319 }
5320
Kashyap, Desai1278b112010-03-09 17:34:13 +05305321 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5322 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305323 sas_device->handle, (unsigned long long)
5324 sas_device->sas_address));
Kashyap, Desai1278b112010-03-09 17:34:13 +05305325
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305326 if (sas_device->starget && sas_device->starget->hostdata) {
5327 sas_target_priv_data = sas_device->starget->hostdata;
Kashyap, Desai1278b112010-03-09 17:34:13 +05305328 sas_target_priv_data->deleted = 1;
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05305329 _scsih_ublock_io_device(ioc, sas_device->sas_address);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305330 sas_target_priv_data->handle =
5331 MPT2SAS_INVALID_DEVICE_HANDLE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05305332 }
5333
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05305334 if (!ioc->hide_drives)
5335 mpt2sas_transport_port_remove(ioc,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305336 sas_device->sas_address,
5337 sas_device->sas_address_parent);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305338
5339 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305340 "(0x%016llx)\n", ioc->name, sas_device->handle,
5341 (unsigned long long) sas_device->sas_address);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305342
5343 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5344 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305345 sas_device->handle, (unsigned long long)
5346 sas_device->sas_address));
5347 kfree(sas_device);
5348}
5349/**
5350 * _scsih_device_remove_by_handle - removing device object by handle
5351 * @ioc: per adapter object
5352 * @handle: device handle
5353 *
5354 * Return nothing.
5355 */
5356static void
5357_scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5358{
5359 struct _sas_device *sas_device;
5360 unsigned long flags;
5361
5362 if (ioc->shost_recovery)
5363 return;
5364
5365 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5366 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5367 if (sas_device)
5368 list_del(&sas_device->list);
5369 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5370 if (sas_device)
5371 _scsih_remove_device(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -06005372}
5373
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305374/**
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305375 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305376 * @ioc: per adapter object
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305377 * @sas_address: device sas_address
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305378 *
5379 * Return nothing.
5380 */
5381void
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305382mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
5383 u64 sas_address)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305384{
5385 struct _sas_device *sas_device;
5386 unsigned long flags;
5387
5388 if (ioc->shost_recovery)
5389 return;
5390
5391 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5392 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5393 sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305394 if (sas_device)
5395 list_del(&sas_device->list);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305396 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305397 if (sas_device)
5398 _scsih_remove_device(ioc, sas_device);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305399}
Eric Moore635374e2009-03-09 01:21:12 -06005400#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5401/**
5402 * _scsih_sas_topology_change_event_debug - debug for topology event
5403 * @ioc: per adapter object
5404 * @event_data: event data payload
5405 * Context: user.
5406 */
5407static void
5408_scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5409 Mpi2EventDataSasTopologyChangeList_t *event_data)
5410{
5411 int i;
5412 u16 handle;
5413 u16 reason_code;
5414 u8 phy_number;
5415 char *status_str = NULL;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305416 u8 link_rate, prev_link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06005417
5418 switch (event_data->ExpStatus) {
5419 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5420 status_str = "add";
5421 break;
5422 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5423 status_str = "remove";
5424 break;
5425 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305426 case 0:
Eric Moore635374e2009-03-09 01:21:12 -06005427 status_str = "responding";
5428 break;
5429 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5430 status_str = "remove delay";
5431 break;
5432 default:
5433 status_str = "unknown status";
5434 break;
5435 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305436 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
Eric Moore635374e2009-03-09 01:21:12 -06005437 ioc->name, status_str);
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305438 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
Eric Moore635374e2009-03-09 01:21:12 -06005439 "start_phy(%02d), count(%d)\n",
5440 le16_to_cpu(event_data->ExpanderDevHandle),
5441 le16_to_cpu(event_data->EnclosureHandle),
5442 event_data->StartPhyNum, event_data->NumEntries);
5443 for (i = 0; i < event_data->NumEntries; i++) {
5444 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5445 if (!handle)
5446 continue;
5447 phy_number = event_data->StartPhyNum + i;
5448 reason_code = event_data->PHY[i].PhyStatus &
5449 MPI2_EVENT_SAS_TOPO_RC_MASK;
5450 switch (reason_code) {
5451 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305452 status_str = "target add";
Eric Moore635374e2009-03-09 01:21:12 -06005453 break;
5454 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305455 status_str = "target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005456 break;
5457 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305458 status_str = "delay target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005459 break;
5460 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305461 status_str = "link rate change";
Eric Moore635374e2009-03-09 01:21:12 -06005462 break;
5463 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305464 status_str = "target responding";
Eric Moore635374e2009-03-09 01:21:12 -06005465 break;
5466 default:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305467 status_str = "unknown";
Eric Moore635374e2009-03-09 01:21:12 -06005468 break;
5469 }
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305470 link_rate = event_data->PHY[i].LinkRate >> 4;
5471 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305472 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305473 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5474 handle, status_str, link_rate, prev_link_rate);
5475
Eric Moore635374e2009-03-09 01:21:12 -06005476 }
5477}
5478#endif
5479
5480/**
5481 * _scsih_sas_topology_change_event - handle topology changes
5482 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305483 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005484 * Context: user.
5485 *
5486 */
5487static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305488_scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
Eric Moore635374e2009-03-09 01:21:12 -06005489 struct fw_event_work *fw_event)
5490{
5491 int i;
5492 u16 parent_handle, handle;
5493 u16 reason_code;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305494 u8 phy_number, max_phys;
Eric Moore635374e2009-03-09 01:21:12 -06005495 struct _sas_node *sas_expander;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305496 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06005497 unsigned long flags;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305498 u8 link_rate, prev_link_rate;
Joe Lawrence00713ad2014-06-25 17:03:33 -04005499 Mpi2EventDataSasTopologyChangeList_t *event_data =
5500 (Mpi2EventDataSasTopologyChangeList_t *)
5501 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06005502
5503#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5504 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5505 _scsih_sas_topology_change_event_debug(ioc, event_data);
5506#endif
5507
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305508 if (ioc->remove_host || ioc->pci_error_recovery)
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305509 return;
5510
Eric Moore635374e2009-03-09 01:21:12 -06005511 if (!ioc->sas_hba.num_phys)
5512 _scsih_sas_host_add(ioc);
5513 else
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305514 _scsih_sas_host_refresh(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005515
5516 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305517 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
Eric Moore635374e2009-03-09 01:21:12 -06005518 "event\n", ioc->name));
5519 return;
5520 }
5521
5522 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5523
5524 /* handle expander add */
5525 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5526 if (_scsih_expander_add(ioc, parent_handle) != 0)
5527 return;
5528
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305529 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5530 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5531 parent_handle);
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305532 if (sas_expander) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305533 sas_address = sas_expander->sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305534 max_phys = sas_expander->num_phys;
5535 } else if (parent_handle < ioc->sas_hba.num_phys) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305536 sas_address = ioc->sas_hba.sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305537 max_phys = ioc->sas_hba.num_phys;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305538 } else {
5539 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305540 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305541 }
5542 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305543
Eric Moore635374e2009-03-09 01:21:12 -06005544 /* handle siblings events */
5545 for (i = 0; i < event_data->NumEntries; i++) {
5546 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305547 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
Eric Moore635374e2009-03-09 01:21:12 -06005548 "expander event\n", ioc->name));
5549 return;
5550 }
Eric Moore3cb54692010-07-08 14:44:34 -06005551 if (ioc->shost_recovery || ioc->remove_host ||
5552 ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305553 return;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305554 phy_number = event_data->StartPhyNum + i;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305555 if (phy_number >= max_phys)
5556 continue;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305557 reason_code = event_data->PHY[i].PhyStatus &
5558 MPI2_EVENT_SAS_TOPO_RC_MASK;
5559 if ((event_data->PHY[i].PhyStatus &
5560 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5561 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
Eric Moore635374e2009-03-09 01:21:12 -06005562 continue;
5563 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5564 if (!handle)
5565 continue;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305566 link_rate = event_data->PHY[i].LinkRate >> 4;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305567 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Eric Moore635374e2009-03-09 01:21:12 -06005568 switch (reason_code) {
5569 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305570
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305571 if (ioc->shost_recovery)
5572 break;
5573
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305574 if (link_rate == prev_link_rate)
5575 break;
5576
5577 mpt2sas_transport_update_links(ioc, sas_address,
5578 handle, phy_number, link_rate);
5579
Kashyap, Desaib4344272010-03-17 16:24:14 +05305580 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5581 break;
5582
5583 _scsih_check_device(ioc, handle);
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305584 break;
Eric Moore635374e2009-03-09 01:21:12 -06005585 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305586
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305587 if (ioc->shost_recovery)
5588 break;
5589
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305590 mpt2sas_transport_update_links(ioc, sas_address,
5591 handle, phy_number, link_rate);
5592
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305593 _scsih_add_device(ioc, handle, phy_number, 0);
Eric Moore635374e2009-03-09 01:21:12 -06005594 break;
5595 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305596
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305597 _scsih_device_remove_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06005598 break;
5599 }
5600 }
5601
5602 /* handle expander removal */
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305603 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5604 sas_expander)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305605 mpt2sas_expander_remove(ioc, sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06005606
5607}
5608
5609#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5610/**
5611 * _scsih_sas_device_status_change_event_debug - debug for device event
5612 * @event_data: event data payload
5613 * Context: user.
5614 *
5615 * Return nothing.
5616 */
5617static void
5618_scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5619 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5620{
5621 char *reason_str = NULL;
5622
5623 switch (event_data->ReasonCode) {
5624 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5625 reason_str = "smart data";
5626 break;
5627 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5628 reason_str = "unsupported device discovered";
5629 break;
5630 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5631 reason_str = "internal device reset";
5632 break;
5633 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5634 reason_str = "internal task abort";
5635 break;
5636 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5637 reason_str = "internal task abort set";
5638 break;
5639 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5640 reason_str = "internal clear task set";
5641 break;
5642 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5643 reason_str = "internal query task";
5644 break;
5645 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5646 reason_str = "sata init failure";
5647 break;
5648 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5649 reason_str = "internal device reset complete";
5650 break;
5651 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5652 reason_str = "internal task abort complete";
5653 break;
5654 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5655 reason_str = "internal async notification";
5656 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05305657 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5658 reason_str = "expander reduced functionality";
5659 break;
5660 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5661 reason_str = "expander reduced functionality complete";
5662 break;
Eric Moore635374e2009-03-09 01:21:12 -06005663 default:
5664 reason_str = "unknown reason";
5665 break;
5666 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305667 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305668 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5669 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5670 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5671 le16_to_cpu(event_data->TaskTag));
Eric Moore635374e2009-03-09 01:21:12 -06005672 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305673 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005674 event_data->ASC, event_data->ASCQ);
5675 printk(KERN_INFO "\n");
5676}
5677#endif
5678
5679/**
5680 * _scsih_sas_device_status_change_event - handle device status change
5681 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305682 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005683 * Context: user.
5684 *
5685 * Return nothing.
5686 */
5687static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305688_scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5689 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005690{
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305691 struct MPT2SAS_TARGET *target_priv_data;
5692 struct _sas_device *sas_device;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05305693 u64 sas_address;
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305694 unsigned long flags;
5695 Mpi2EventDataSasDeviceStatusChange_t *event_data =
Joe Lawrence00713ad2014-06-25 17:03:33 -04005696 (Mpi2EventDataSasDeviceStatusChange_t *)
5697 fw_event->event_data;
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305698
Eric Moore635374e2009-03-09 01:21:12 -06005699#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5700 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305701 _scsih_sas_device_status_change_event_debug(ioc,
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305702 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005703#endif
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305704
Kashyap, Desaiefe82a12011-01-04 11:34:17 +05305705 /* In MPI Revision K (0xC), the internal device reset complete was
5706 * implemented, so avoid setting tm_busy flag for older firmware.
5707 */
5708 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5709 return;
5710
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305711 if (event_data->ReasonCode !=
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305712 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305713 event_data->ReasonCode !=
5714 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305715 return;
5716
5717 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5718 sas_address = le64_to_cpu(event_data->SASAddress);
5719 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5720 sas_address);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305721
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305722 if (!sas_device || !sas_device->starget) {
5723 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305724 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305725 }
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305726
5727 target_priv_data = sas_device->starget->hostdata;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305728 if (!target_priv_data) {
5729 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305730 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305731 }
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305732
5733 if (event_data->ReasonCode ==
5734 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5735 target_priv_data->tm_busy = 1;
5736 else
5737 target_priv_data->tm_busy = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305738 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005739}
5740
5741#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5742/**
5743 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5744 * @ioc: per adapter object
5745 * @event_data: event data payload
5746 * Context: user.
5747 *
5748 * Return nothing.
5749 */
5750static void
5751_scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5752 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5753{
5754 char *reason_str = NULL;
5755
5756 switch (event_data->ReasonCode) {
5757 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5758 reason_str = "enclosure add";
5759 break;
5760 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5761 reason_str = "enclosure remove";
5762 break;
5763 default:
5764 reason_str = "unknown reason";
5765 break;
5766 }
5767
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305768 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
Eric Moore635374e2009-03-09 01:21:12 -06005769 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5770 " number slots(%d)\n", ioc->name, reason_str,
5771 le16_to_cpu(event_data->EnclosureHandle),
5772 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5773 le16_to_cpu(event_data->StartSlot));
5774}
5775#endif
5776
5777/**
5778 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5779 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305780 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005781 * Context: user.
5782 *
5783 * Return nothing.
5784 */
5785static void
5786_scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305787 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005788{
5789#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5790 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5791 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
Joe Lawrence00713ad2014-06-25 17:03:33 -04005792 (Mpi2EventDataSasEnclDevStatusChange_t *)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305793 fw_event->event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005794#endif
5795}
5796
5797/**
Andrew Mortona78e21d2012-02-08 12:52:22 -08005798 * _scsih_sas_broadcast_primitive_event - handle broadcast events
Eric Moore635374e2009-03-09 01:21:12 -06005799 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305800 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005801 * Context: user.
5802 *
5803 * Return nothing.
5804 */
5805static void
Andrew Mortona78e21d2012-02-08 12:52:22 -08005806_scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305807 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005808{
5809 struct scsi_cmnd *scmd;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305810 struct scsi_device *sdev;
Eric Moore635374e2009-03-09 01:21:12 -06005811 u16 smid, handle;
5812 u32 lun;
5813 struct MPT2SAS_DEVICE *sas_device_priv_data;
5814 u32 termination_count;
5815 u32 query_count;
5816 Mpi2SCSITaskManagementReply_t *mpi_reply;
Joe Lawrence00713ad2014-06-25 17:03:33 -04005817 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5818 (Mpi2EventDataSasBroadcastPrimitive_t *)
5819 fw_event->event_data;
Kashyap, Desai463217b2009-10-05 15:53:06 +05305820 u16 ioc_status;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305821 unsigned long flags;
5822 int r;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305823 u8 max_retries = 0;
5824 u8 task_abort_retries;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305825
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305826 mutex_lock(&ioc->tm_cmds.mutex);
Reddy, Sreekanthc3a634b2013-02-26 17:36:12 +05305827 pr_info(MPT2SAS_FMT
5828 "%s: enter: phy number(%d), width(%d)\n",
5829 ioc->name, __func__, event_data->PhyNum,
5830 event_data->PortWidth);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305831
5832 _scsih_block_io_all_device(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005833
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305834 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305835 mpi_reply = ioc->tm_cmds.reply;
5836broadcast_aen_retry:
5837
5838 /* sanity checks for retrying this loop */
5839 if (max_retries++ == 5) {
5840 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5841 ioc->name, __func__));
5842 goto out;
5843 } else if (max_retries > 1)
5844 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5845 ioc->name, __func__, max_retries - 1));
5846
Eric Moore635374e2009-03-09 01:21:12 -06005847 termination_count = 0;
5848 query_count = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305849 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305850 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305851 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06005852 scmd = _scsih_scsi_lookup_get(ioc, smid);
5853 if (!scmd)
5854 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305855 sdev = scmd->device;
5856 sas_device_priv_data = sdev->hostdata;
Eric Moore635374e2009-03-09 01:21:12 -06005857 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5858 continue;
5859 /* skip hidden raid components */
5860 if (sas_device_priv_data->sas_target->flags &
5861 MPT_TARGET_FLAGS_RAID_COMPONENT)
5862 continue;
5863 /* skip volumes */
5864 if (sas_device_priv_data->sas_target->flags &
5865 MPT_TARGET_FLAGS_VOLUME)
5866 continue;
5867
5868 handle = sas_device_priv_data->sas_target->handle;
5869 lun = sas_device_priv_data->lun;
5870 query_count++;
5871
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305872 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305873 goto out;
5874
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305875 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305876 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04005877 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305878 TM_MUTEX_OFF);
5879 if (r == FAILED) {
5880 sdev_printk(KERN_WARNING, sdev,
5881 "mpt2sas_scsih_issue_tm: FAILED when sending "
5882 "QUERY_TASK: scmd(%p)\n", scmd);
5883 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5884 goto broadcast_aen_retry;
5885 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05305886 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5887 & MPI2_IOCSTATUS_MASK;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305888 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5889 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5890 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5891 scmd);
5892 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5893 goto broadcast_aen_retry;
5894 }
5895
5896 /* see if IO is still owned by IOC and target */
5897 if (mpi_reply->ResponseCode ==
Eric Moore635374e2009-03-09 01:21:12 -06005898 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5899 mpi_reply->ResponseCode ==
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305900 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305901 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005902 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305903 }
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305904 task_abort_retries = 0;
5905 tm_retry:
5906 if (task_abort_retries++ == 60) {
5907 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5908 "%s: ABORT_TASK: giving up\n", ioc->name,
5909 __func__));
5910 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5911 goto broadcast_aen_retry;
5912 }
5913
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305914 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305915 goto out_no_lock;
5916
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305917 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5918 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04005919 TM_MUTEX_OFF);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305920 if (r == FAILED) {
5921 sdev_printk(KERN_WARNING, sdev,
5922 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305923 "scmd(%p)\n", scmd);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305924 goto tm_retry;
5925 }
5926
5927 if (task_abort_retries > 1)
5928 sdev_printk(KERN_WARNING, sdev,
5929 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5930 " scmd(%p)\n",
5931 task_abort_retries - 1, scmd);
5932
Eric Moore635374e2009-03-09 01:21:12 -06005933 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305934 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005935 }
Eric Moore635374e2009-03-09 01:21:12 -06005936
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305937 if (ioc->broadcast_aen_pending) {
5938 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5939 " pending AEN\n", ioc->name, __func__));
5940 ioc->broadcast_aen_pending = 0;
5941 goto broadcast_aen_retry;
5942 }
5943
5944 out:
5945 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5946 out_no_lock:
5947
5948 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06005949 "%s - exit, query_count = %d termination_count = %d\n",
5950 ioc->name, __func__, query_count, termination_count));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305951
5952 ioc->broadcast_aen_busy = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305953 if (!ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305954 _scsih_ublock_io_all_device(ioc);
5955 mutex_unlock(&ioc->tm_cmds.mutex);
Eric Moore635374e2009-03-09 01:21:12 -06005956}
5957
5958/**
5959 * _scsih_sas_discovery_event - handle discovery events
5960 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305961 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005962 * Context: user.
5963 *
5964 * Return nothing.
5965 */
5966static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305967_scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5968 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005969{
Joe Lawrence00713ad2014-06-25 17:03:33 -04005970 Mpi2EventDataSasDiscovery_t *event_data =
5971 (Mpi2EventDataSasDiscovery_t *)
5972 fw_event->event_data;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305973
Eric Moore635374e2009-03-09 01:21:12 -06005974#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5975 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305976 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005977 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5978 "start" : "stop");
5979 if (event_data->DiscoveryStatus)
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305980 printk("discovery_status(0x%08x)",
5981 le32_to_cpu(event_data->DiscoveryStatus));
Eric Moore635374e2009-03-09 01:21:12 -06005982 printk("\n");
5983 }
5984#endif
5985
5986 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05305987 !ioc->sas_hba.num_phys) {
5988 if (disable_discovery > 0 && ioc->shost_recovery) {
5989 /* Wait for the reset to complete */
5990 while (ioc->shost_recovery)
5991 ssleep(1);
5992 }
Eric Moore635374e2009-03-09 01:21:12 -06005993 _scsih_sas_host_add(ioc);
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05305994 }
Eric Moore635374e2009-03-09 01:21:12 -06005995}
5996
5997/**
5998 * _scsih_reprobe_lun - reprobing lun
5999 * @sdev: scsi device struct
6000 * @no_uld_attach: sdev->no_uld_attach flag setting
6001 *
6002 **/
6003static void
6004_scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
6005{
6006 int rc;
6007
6008 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6009 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6010 sdev->no_uld_attach ? "hidding" : "exposing");
6011 rc = scsi_device_reprobe(sdev);
6012}
6013
6014/**
Eric Moore635374e2009-03-09 01:21:12 -06006015 * _scsih_sas_volume_add - add new volume
6016 * @ioc: per adapter object
6017 * @element: IR config element data
6018 * Context: user.
6019 *
6020 * Return nothing.
6021 */
6022static void
6023_scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
6024 Mpi2EventIrConfigElement_t *element)
6025{
6026 struct _raid_device *raid_device;
6027 unsigned long flags;
6028 u64 wwid;
6029 u16 handle = le16_to_cpu(element->VolDevHandle);
6030 int rc;
6031
Eric Moore635374e2009-03-09 01:21:12 -06006032 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6033 if (!wwid) {
6034 printk(MPT2SAS_ERR_FMT
6035 "failure at %s:%d/%s()!\n", ioc->name,
6036 __FILE__, __LINE__, __func__);
6037 return;
6038 }
6039
6040 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6041 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6042 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6043
6044 if (raid_device)
6045 return;
6046
6047 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6048 if (!raid_device) {
6049 printk(MPT2SAS_ERR_FMT
6050 "failure at %s:%d/%s()!\n", ioc->name,
6051 __FILE__, __LINE__, __func__);
6052 return;
6053 }
6054
6055 raid_device->id = ioc->sas_id++;
6056 raid_device->channel = RAID_CHANNEL;
6057 raid_device->handle = handle;
6058 raid_device->wwid = wwid;
6059 _scsih_raid_device_add(ioc, raid_device);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306060 if (!ioc->wait_for_discovery_to_complete) {
Eric Moore635374e2009-03-09 01:21:12 -06006061 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6062 raid_device->id, 0);
6063 if (rc)
6064 _scsih_raid_device_remove(ioc, raid_device);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306065 } else {
6066 spin_lock_irqsave(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06006067 _scsih_determine_boot_device(ioc, raid_device, 1);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306068 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6069 }
Eric Moore635374e2009-03-09 01:21:12 -06006070}
6071
6072/**
6073 * _scsih_sas_volume_delete - delete volume
6074 * @ioc: per adapter object
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306075 * @handle: volume device handle
Eric Moore635374e2009-03-09 01:21:12 -06006076 * Context: user.
6077 *
6078 * Return nothing.
6079 */
6080static void
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306081_scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Eric Moore635374e2009-03-09 01:21:12 -06006082{
6083 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06006084 unsigned long flags;
6085 struct MPT2SAS_TARGET *sas_target_priv_data;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306086 struct scsi_target *starget = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006087
Eric Moore635374e2009-03-09 01:21:12 -06006088 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6089 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306090 if (raid_device) {
6091 if (raid_device->starget) {
6092 starget = raid_device->starget;
6093 sas_target_priv_data = starget->hostdata;
6094 sas_target_priv_data->deleted = 1;
6095 }
6096 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6097 "(0x%016llx)\n", ioc->name, raid_device->handle,
6098 (unsigned long long) raid_device->wwid);
6099 list_del(&raid_device->list);
6100 kfree(raid_device);
Eric Moore635374e2009-03-09 01:21:12 -06006101 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306102 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6103 if (starget)
6104 scsi_remove_target(&starget->dev);
Eric Moore635374e2009-03-09 01:21:12 -06006105}
6106
6107/**
6108 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6109 * @ioc: per adapter object
6110 * @element: IR config element data
6111 * Context: user.
6112 *
6113 * Return nothing.
6114 */
6115static void
6116_scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6117 Mpi2EventIrConfigElement_t *element)
6118{
6119 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306120 struct scsi_target *starget = NULL;
6121 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06006122 unsigned long flags;
6123 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6124
6125 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6126 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306127 if (sas_device) {
6128 sas_device->volume_handle = 0;
6129 sas_device->volume_wwid = 0;
6130 clear_bit(handle, ioc->pd_handles);
6131 if (sas_device->starget && sas_device->starget->hostdata) {
6132 starget = sas_device->starget;
6133 sas_target_priv_data = starget->hostdata;
6134 sas_target_priv_data->flags &=
6135 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6136 }
6137 }
Eric Moore635374e2009-03-09 01:21:12 -06006138 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6139 if (!sas_device)
6140 return;
6141
6142 /* exposing raid component */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306143 if (starget)
6144 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
Eric Moore635374e2009-03-09 01:21:12 -06006145}
6146
6147/**
6148 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6149 * @ioc: per adapter object
6150 * @element: IR config element data
6151 * Context: user.
6152 *
6153 * Return nothing.
6154 */
6155static void
6156_scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6157 Mpi2EventIrConfigElement_t *element)
6158{
6159 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306160 struct scsi_target *starget = NULL;
6161 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06006162 unsigned long flags;
6163 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306164 u16 volume_handle = 0;
6165 u64 volume_wwid = 0;
6166
6167 mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle);
6168 if (volume_handle)
6169 mpt2sas_config_get_volume_wwid(ioc, volume_handle,
6170 &volume_wwid);
Eric Moore635374e2009-03-09 01:21:12 -06006171
6172 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6173 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306174 if (sas_device) {
6175 set_bit(handle, ioc->pd_handles);
6176 if (sas_device->starget && sas_device->starget->hostdata) {
6177 starget = sas_device->starget;
6178 sas_target_priv_data = starget->hostdata;
6179 sas_target_priv_data->flags |=
6180 MPT_TARGET_FLAGS_RAID_COMPONENT;
6181 sas_device->volume_handle = volume_handle;
6182 sas_device->volume_wwid = volume_wwid;
6183 }
6184 }
Eric Moore635374e2009-03-09 01:21:12 -06006185 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6186 if (!sas_device)
6187 return;
6188
6189 /* hiding raid component */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306190 if (starget)
6191 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
Eric Moore635374e2009-03-09 01:21:12 -06006192}
6193
6194/**
6195 * _scsih_sas_pd_delete - delete pd component
6196 * @ioc: per adapter object
6197 * @element: IR config element data
6198 * Context: user.
6199 *
6200 * Return nothing.
6201 */
6202static void
6203_scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6204 Mpi2EventIrConfigElement_t *element)
6205{
Eric Moore635374e2009-03-09 01:21:12 -06006206 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6207
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306208 _scsih_device_remove_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006209}
6210
6211/**
6212 * _scsih_sas_pd_add - remove pd component
6213 * @ioc: per adapter object
6214 * @element: IR config element data
6215 * Context: user.
6216 *
6217 * Return nothing.
6218 */
6219static void
6220_scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6221 Mpi2EventIrConfigElement_t *element)
6222{
6223 struct _sas_device *sas_device;
6224 unsigned long flags;
6225 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306226 Mpi2ConfigReply_t mpi_reply;
6227 Mpi2SasDevicePage0_t sas_device_pg0;
6228 u32 ioc_status;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306229 u64 sas_address;
6230 u16 parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006231
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306232 set_bit(handle, ioc->pd_handles);
6233
Eric Moore635374e2009-03-09 01:21:12 -06006234 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6235 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6236 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306237 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306238 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306239
6240 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6241 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6242 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6243 ioc->name, __FILE__, __LINE__, __func__);
6244 return;
6245 }
6246
6247 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6248 MPI2_IOCSTATUS_MASK;
6249 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6250 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6251 ioc->name, __FILE__, __LINE__, __func__);
6252 return;
6253 }
6254
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306255 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6256 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6257 mpt2sas_transport_update_links(ioc, sas_address, handle,
6258 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306259
6260 _scsih_add_device(ioc, handle, 0, 1);
Eric Moore635374e2009-03-09 01:21:12 -06006261}
6262
6263#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6264/**
6265 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6266 * @ioc: per adapter object
6267 * @event_data: event data payload
6268 * Context: user.
6269 *
6270 * Return nothing.
6271 */
6272static void
6273_scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6274 Mpi2EventDataIrConfigChangeList_t *event_data)
6275{
6276 Mpi2EventIrConfigElement_t *element;
6277 u8 element_type;
6278 int i;
6279 char *reason_str = NULL, *element_str = NULL;
6280
6281 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6282
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306283 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
Eric Moore635374e2009-03-09 01:21:12 -06006284 ioc->name, (le32_to_cpu(event_data->Flags) &
6285 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6286 "foreign" : "native", event_data->NumElements);
6287 for (i = 0; i < event_data->NumElements; i++, element++) {
6288 switch (element->ReasonCode) {
6289 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6290 reason_str = "add";
6291 break;
6292 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6293 reason_str = "remove";
6294 break;
6295 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6296 reason_str = "no change";
6297 break;
6298 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6299 reason_str = "hide";
6300 break;
6301 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6302 reason_str = "unhide";
6303 break;
6304 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6305 reason_str = "volume_created";
6306 break;
6307 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6308 reason_str = "volume_deleted";
6309 break;
6310 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6311 reason_str = "pd_created";
6312 break;
6313 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6314 reason_str = "pd_deleted";
6315 break;
6316 default:
6317 reason_str = "unknown reason";
6318 break;
6319 }
6320 element_type = le16_to_cpu(element->ElementFlags) &
6321 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6322 switch (element_type) {
6323 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6324 element_str = "volume";
6325 break;
6326 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6327 element_str = "phys disk";
6328 break;
6329 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6330 element_str = "hot spare";
6331 break;
6332 default:
6333 element_str = "unknown element";
6334 break;
6335 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306336 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
Eric Moore635374e2009-03-09 01:21:12 -06006337 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6338 reason_str, le16_to_cpu(element->VolDevHandle),
6339 le16_to_cpu(element->PhysDiskDevHandle),
6340 element->PhysDiskNum);
6341 }
6342}
6343#endif
6344
6345/**
6346 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6347 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306348 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006349 * Context: user.
6350 *
6351 * Return nothing.
6352 */
6353static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306354_scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6355 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006356{
6357 Mpi2EventIrConfigElement_t *element;
6358 int i;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306359 u8 foreign_config;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006360 Mpi2EventDataIrConfigChangeList_t *event_data =
6361 (Mpi2EventDataIrConfigChangeList_t *)
6362 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006363
6364#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306365 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6366 && !ioc->hide_ir_msg)
Eric Moore635374e2009-03-09 01:21:12 -06006367 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6368
6369#endif
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306370
6371 if (ioc->shost_recovery)
6372 return;
6373
Kashyap, Desai62727a72009-08-07 19:35:18 +05306374 foreign_config = (le32_to_cpu(event_data->Flags) &
6375 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
Eric Moore635374e2009-03-09 01:21:12 -06006376
6377 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6378 for (i = 0; i < event_data->NumElements; i++, element++) {
6379
6380 switch (element->ReasonCode) {
6381 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6382 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306383 if (!foreign_config)
6384 _scsih_sas_volume_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006385 break;
6386 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6387 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306388 if (!foreign_config)
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306389 _scsih_sas_volume_delete(ioc,
6390 le16_to_cpu(element->VolDevHandle));
Eric Moore635374e2009-03-09 01:21:12 -06006391 break;
6392 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306393 if (!ioc->is_warpdrive)
6394 _scsih_sas_pd_hide(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006395 break;
6396 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306397 if (!ioc->is_warpdrive)
6398 _scsih_sas_pd_expose(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006399 break;
6400 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306401 if (!ioc->is_warpdrive)
6402 _scsih_sas_pd_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006403 break;
6404 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306405 if (!ioc->is_warpdrive)
6406 _scsih_sas_pd_delete(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006407 break;
6408 }
6409 }
6410}
6411
6412/**
6413 * _scsih_sas_ir_volume_event - IR volume event
6414 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306415 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006416 * Context: user.
6417 *
6418 * Return nothing.
6419 */
6420static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306421_scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6422 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006423{
6424 u64 wwid;
6425 unsigned long flags;
6426 struct _raid_device *raid_device;
6427 u16 handle;
6428 u32 state;
6429 int rc;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006430 Mpi2EventDataIrVolume_t *event_data =
6431 (Mpi2EventDataIrVolume_t *)
6432 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006433
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306434 if (ioc->shost_recovery)
6435 return;
6436
Eric Moore635374e2009-03-09 01:21:12 -06006437 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6438 return;
6439
6440 handle = le16_to_cpu(event_data->VolDevHandle);
6441 state = le32_to_cpu(event_data->NewValue);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306442 if (!ioc->hide_ir_msg)
6443 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6444 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6445 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006446
Eric Moore635374e2009-03-09 01:21:12 -06006447 switch (state) {
6448 case MPI2_RAID_VOL_STATE_MISSING:
6449 case MPI2_RAID_VOL_STATE_FAILED:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306450 _scsih_sas_volume_delete(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006451 break;
6452
6453 case MPI2_RAID_VOL_STATE_ONLINE:
6454 case MPI2_RAID_VOL_STATE_DEGRADED:
6455 case MPI2_RAID_VOL_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306456
6457 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6458 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6459 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6460
Eric Moore635374e2009-03-09 01:21:12 -06006461 if (raid_device)
6462 break;
6463
6464 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6465 if (!wwid) {
6466 printk(MPT2SAS_ERR_FMT
6467 "failure at %s:%d/%s()!\n", ioc->name,
6468 __FILE__, __LINE__, __func__);
6469 break;
6470 }
6471
6472 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6473 if (!raid_device) {
6474 printk(MPT2SAS_ERR_FMT
6475 "failure at %s:%d/%s()!\n", ioc->name,
6476 __FILE__, __LINE__, __func__);
6477 break;
6478 }
6479
6480 raid_device->id = ioc->sas_id++;
6481 raid_device->channel = RAID_CHANNEL;
6482 raid_device->handle = handle;
6483 raid_device->wwid = wwid;
6484 _scsih_raid_device_add(ioc, raid_device);
6485 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6486 raid_device->id, 0);
6487 if (rc)
6488 _scsih_raid_device_remove(ioc, raid_device);
6489 break;
6490
6491 case MPI2_RAID_VOL_STATE_INITIALIZING:
6492 default:
6493 break;
6494 }
6495}
6496
6497/**
6498 * _scsih_sas_ir_physical_disk_event - PD event
6499 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306500 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006501 * Context: user.
6502 *
6503 * Return nothing.
6504 */
6505static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306506_scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6507 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006508{
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306509 u16 handle, parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006510 u32 state;
6511 struct _sas_device *sas_device;
6512 unsigned long flags;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306513 Mpi2ConfigReply_t mpi_reply;
6514 Mpi2SasDevicePage0_t sas_device_pg0;
6515 u32 ioc_status;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006516 Mpi2EventDataIrPhysicalDisk_t *event_data =
6517 (Mpi2EventDataIrPhysicalDisk_t *)
6518 fw_event->event_data;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306519 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006520
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306521 if (ioc->shost_recovery)
6522 return;
6523
Eric Moore635374e2009-03-09 01:21:12 -06006524 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6525 return;
6526
6527 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6528 state = le32_to_cpu(event_data->NewValue);
6529
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306530 if (!ioc->hide_ir_msg)
6531 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6532 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6533 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006534
Eric Moore635374e2009-03-09 01:21:12 -06006535 switch (state) {
Eric Moore635374e2009-03-09 01:21:12 -06006536 case MPI2_RAID_PD_STATE_ONLINE:
6537 case MPI2_RAID_PD_STATE_DEGRADED:
6538 case MPI2_RAID_PD_STATE_REBUILDING:
6539 case MPI2_RAID_PD_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306540 case MPI2_RAID_PD_STATE_HOT_SPARE:
6541
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306542 if (!ioc->is_warpdrive)
6543 set_bit(handle, ioc->pd_handles);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306544
6545 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6546 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6547 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6548
6549 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306550 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306551
6552 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6553 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6554 handle))) {
6555 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6556 ioc->name, __FILE__, __LINE__, __func__);
6557 return;
6558 }
6559
6560 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6561 MPI2_IOCSTATUS_MASK;
6562 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6563 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6564 ioc->name, __FILE__, __LINE__, __func__);
6565 return;
6566 }
6567
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306568 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6569 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6570 mpt2sas_transport_update_links(ioc, sas_address, handle,
6571 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306572
6573 _scsih_add_device(ioc, handle, 0, 1);
6574
Eric Moore635374e2009-03-09 01:21:12 -06006575 break;
6576
Kashyap, Desai62727a72009-08-07 19:35:18 +05306577 case MPI2_RAID_PD_STATE_OFFLINE:
Eric Moore635374e2009-03-09 01:21:12 -06006578 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6579 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
Eric Moore635374e2009-03-09 01:21:12 -06006580 default:
6581 break;
6582 }
6583}
6584
6585#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6586/**
6587 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6588 * @ioc: per adapter object
6589 * @event_data: event data payload
6590 * Context: user.
6591 *
6592 * Return nothing.
6593 */
6594static void
6595_scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6596 Mpi2EventDataIrOperationStatus_t *event_data)
6597{
6598 char *reason_str = NULL;
6599
6600 switch (event_data->RAIDOperation) {
6601 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6602 reason_str = "resync";
6603 break;
6604 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6605 reason_str = "online capacity expansion";
6606 break;
6607 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6608 reason_str = "consistency check";
6609 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306610 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6611 reason_str = "background init";
6612 break;
6613 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6614 reason_str = "make data consistent";
Eric Moore635374e2009-03-09 01:21:12 -06006615 break;
6616 }
6617
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306618 if (!reason_str)
6619 return;
6620
Eric Moore635374e2009-03-09 01:21:12 -06006621 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6622 "\thandle(0x%04x), percent complete(%d)\n",
6623 ioc->name, reason_str,
6624 le16_to_cpu(event_data->VolDevHandle),
6625 event_data->PercentComplete);
6626}
6627#endif
6628
6629/**
6630 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6631 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306632 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006633 * Context: user.
6634 *
6635 * Return nothing.
6636 */
6637static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306638_scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6639 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006640{
Joe Lawrence00713ad2014-06-25 17:03:33 -04006641 Mpi2EventDataIrOperationStatus_t *event_data =
6642 (Mpi2EventDataIrOperationStatus_t *)
6643 fw_event->event_data;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306644 static struct _raid_device *raid_device;
6645 unsigned long flags;
6646 u16 handle;
6647
Eric Moore635374e2009-03-09 01:21:12 -06006648#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306649 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6650 && !ioc->hide_ir_msg)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306651 _scsih_sas_ir_operation_status_event_debug(ioc,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306652 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06006653#endif
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306654
6655 /* code added for raid transport support */
6656 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6657
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306658 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306659 handle = le16_to_cpu(event_data->VolDevHandle);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306660 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306661 if (raid_device)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306662 raid_device->percent_complete =
6663 event_data->PercentComplete;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306664 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306665 }
Eric Moore635374e2009-03-09 01:21:12 -06006666}
6667
6668/**
Kashyap, Desai14695852010-03-30 10:52:44 +05306669 * _scsih_prep_device_scan - initialize parameters prior to device scan
6670 * @ioc: per adapter object
6671 *
6672 * Set the deleted flag prior to device scan. If the device is found during
6673 * the scan, then we clear the deleted flag.
6674 */
6675static void
6676_scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6677{
6678 struct MPT2SAS_DEVICE *sas_device_priv_data;
6679 struct scsi_device *sdev;
6680
6681 shost_for_each_device(sdev, ioc->shost) {
6682 sas_device_priv_data = sdev->hostdata;
6683 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6684 sas_device_priv_data->sas_target->deleted = 1;
6685 }
6686}
6687
6688/**
Eric Moore635374e2009-03-09 01:21:12 -06006689 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6690 * @ioc: per adapter object
6691 * @sas_address: sas address
6692 * @slot: enclosure slot id
6693 * @handle: device handle
6694 *
6695 * After host reset, find out whether devices are still responding.
6696 * Used in _scsi_remove_unresponsive_sas_devices.
6697 *
6698 * Return nothing.
6699 */
6700static void
6701_scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6702 u16 slot, u16 handle)
6703{
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306704 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006705 struct scsi_target *starget;
6706 struct _sas_device *sas_device;
6707 unsigned long flags;
6708
6709 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6710 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6711 if (sas_device->sas_address == sas_address &&
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306712 sas_device->slot == slot) {
Eric Moore635374e2009-03-09 01:21:12 -06006713 sas_device->responding = 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05306714 starget = sas_device->starget;
Kashyap, Desai14695852010-03-30 10:52:44 +05306715 if (starget && starget->hostdata) {
6716 sas_target_priv_data = starget->hostdata;
6717 sas_target_priv_data->tm_busy = 0;
6718 sas_target_priv_data->deleted = 0;
6719 } else
6720 sas_target_priv_data = NULL;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306721 if (starget)
6722 starget_printk(KERN_INFO, starget,
6723 "handle(0x%04x), sas_addr(0x%016llx), "
6724 "enclosure logical id(0x%016llx), "
6725 "slot(%d)\n", handle,
6726 (unsigned long long)sas_device->sas_address,
6727 (unsigned long long)
6728 sas_device->enclosure_logical_id,
6729 sas_device->slot);
Eric Moore635374e2009-03-09 01:21:12 -06006730 if (sas_device->handle == handle)
6731 goto out;
6732 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6733 sas_device->handle);
6734 sas_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306735 if (sas_target_priv_data)
6736 sas_target_priv_data->handle = handle;
Eric Moore635374e2009-03-09 01:21:12 -06006737 goto out;
6738 }
6739 }
6740 out:
6741 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6742}
6743
6744/**
6745 * _scsih_search_responding_sas_devices -
6746 * @ioc: per adapter object
6747 *
6748 * After host reset, find out whether devices are still responding.
6749 * If not remove.
6750 *
6751 * Return nothing.
6752 */
6753static void
6754_scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6755{
6756 Mpi2SasDevicePage0_t sas_device_pg0;
6757 Mpi2ConfigReply_t mpi_reply;
6758 u16 ioc_status;
6759 __le64 sas_address;
6760 u16 handle;
6761 u32 device_info;
6762 u16 slot;
6763
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306764 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006765
6766 if (list_empty(&ioc->sas_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306767 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006768
6769 handle = 0xFFFF;
6770 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6771 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6772 handle))) {
6773 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6774 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306775 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006776 break;
6777 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6778 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6779 if (!(_scsih_is_end_device(device_info)))
6780 continue;
6781 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6782 slot = le16_to_cpu(sas_device_pg0.Slot);
6783 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6784 handle);
6785 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306786out:
6787 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6788 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006789}
6790
6791/**
6792 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6793 * @ioc: per adapter object
6794 * @wwid: world wide identifier for raid volume
6795 * @handle: device handle
6796 *
6797 * After host reset, find out whether devices are still responding.
6798 * Used in _scsi_remove_unresponsive_raid_devices.
6799 *
6800 * Return nothing.
6801 */
6802static void
6803_scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6804 u16 handle)
6805{
6806 struct MPT2SAS_TARGET *sas_target_priv_data;
6807 struct scsi_target *starget;
6808 struct _raid_device *raid_device;
6809 unsigned long flags;
6810
6811 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6812 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6813 if (raid_device->wwid == wwid && raid_device->starget) {
Kashyap, Desai14695852010-03-30 10:52:44 +05306814 starget = raid_device->starget;
6815 if (starget && starget->hostdata) {
6816 sas_target_priv_data = starget->hostdata;
6817 sas_target_priv_data->deleted = 0;
6818 } else
6819 sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006820 raid_device->responding = 1;
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306821 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06006822 starget_printk(KERN_INFO, raid_device->starget,
6823 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6824 (unsigned long long)raid_device->wwid);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306825 /*
6826 * WARPDRIVE: The handles of the PDs might have changed
6827 * across the host reset so re-initialize the
6828 * required data for Direct IO
6829 */
6830 _scsih_init_warpdrive_properties(ioc, raid_device);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306831 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6832 if (raid_device->handle == handle) {
6833 spin_unlock_irqrestore(&ioc->raid_device_lock,
6834 flags);
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306835 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306836 }
Eric Moore635374e2009-03-09 01:21:12 -06006837 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6838 raid_device->handle);
6839 raid_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306840 if (sas_target_priv_data)
6841 sas_target_priv_data->handle = handle;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306842 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306843 return;
Eric Moore635374e2009-03-09 01:21:12 -06006844 }
6845 }
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306846
Eric Moore635374e2009-03-09 01:21:12 -06006847 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6848}
6849
6850/**
6851 * _scsih_search_responding_raid_devices -
6852 * @ioc: per adapter object
6853 *
6854 * After host reset, find out whether devices are still responding.
6855 * If not remove.
6856 *
6857 * Return nothing.
6858 */
6859static void
6860_scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6861{
6862 Mpi2RaidVolPage1_t volume_pg1;
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306863 Mpi2RaidVolPage0_t volume_pg0;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306864 Mpi2RaidPhysDiskPage0_t pd_pg0;
Eric Moore635374e2009-03-09 01:21:12 -06006865 Mpi2ConfigReply_t mpi_reply;
6866 u16 ioc_status;
6867 u16 handle;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306868 u8 phys_disk_num;
Eric Moore635374e2009-03-09 01:21:12 -06006869
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306870 if (!ioc->ir_firmware)
6871 return;
6872
6873 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6874 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006875
6876 if (list_empty(&ioc->raid_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306877 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006878
6879 handle = 0xFFFF;
6880 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6881 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6882 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6883 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306884 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006885 break;
6886 handle = le16_to_cpu(volume_pg1.DevHandle);
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306887
6888 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6889 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6890 sizeof(Mpi2RaidVolPage0_t)))
6891 continue;
6892
6893 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6894 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6895 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6896 _scsih_mark_responding_raid_device(ioc,
6897 le64_to_cpu(volume_pg1.WWID), handle);
Eric Moore635374e2009-03-09 01:21:12 -06006898 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306899
6900 /* refresh the pd_handles */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306901 if (!ioc->is_warpdrive) {
6902 phys_disk_num = 0xFF;
6903 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6904 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6905 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6906 phys_disk_num))) {
6907 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6908 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306909 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306910 break;
6911 phys_disk_num = pd_pg0.PhysDiskNum;
6912 handle = le16_to_cpu(pd_pg0.DevHandle);
6913 set_bit(handle, ioc->pd_handles);
6914 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306915 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306916out:
6917 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6918 "complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006919}
6920
6921/**
6922 * _scsih_mark_responding_expander - mark a expander as responding
6923 * @ioc: per adapter object
6924 * @sas_address: sas address
6925 * @handle:
6926 *
6927 * After host reset, find out whether devices are still responding.
6928 * Used in _scsi_remove_unresponsive_expanders.
6929 *
6930 * Return nothing.
6931 */
6932static void
6933_scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6934 u16 handle)
6935{
6936 struct _sas_node *sas_expander;
6937 unsigned long flags;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306938 int i;
Eric Moore635374e2009-03-09 01:21:12 -06006939
6940 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6941 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306942 if (sas_expander->sas_address != sas_address)
6943 continue;
6944 sas_expander->responding = 1;
6945 if (sas_expander->handle == handle)
Eric Moore635374e2009-03-09 01:21:12 -06006946 goto out;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306947 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6948 " from(0x%04x) to (0x%04x)!!!\n",
6949 (unsigned long long)sas_expander->sas_address,
6950 sas_expander->handle, handle);
6951 sas_expander->handle = handle;
6952 for (i = 0 ; i < sas_expander->num_phys ; i++)
6953 sas_expander->phy[i].handle = handle;
6954 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006955 }
6956 out:
6957 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6958}
6959
6960/**
6961 * _scsih_search_responding_expanders -
6962 * @ioc: per adapter object
6963 *
6964 * After host reset, find out whether devices are still responding.
6965 * If not remove.
6966 *
6967 * Return nothing.
6968 */
6969static void
6970_scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6971{
6972 Mpi2ExpanderPage0_t expander_pg0;
6973 Mpi2ConfigReply_t mpi_reply;
6974 u16 ioc_status;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05306975 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006976 u16 handle;
6977
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306978 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006979
6980 if (list_empty(&ioc->sas_expander_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306981 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006982
6983 handle = 0xFFFF;
6984 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6985 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6986
6987 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6988 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306989 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006990 break;
6991
6992 handle = le16_to_cpu(expander_pg0.DevHandle);
6993 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6994 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6995 "sas_addr(0x%016llx)\n", handle,
6996 (unsigned long long)sas_address);
6997 _scsih_mark_responding_expander(ioc, sas_address, handle);
6998 }
6999
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307000 out:
7001 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06007002}
7003
7004/**
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307005 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
Eric Moore635374e2009-03-09 01:21:12 -06007006 * @ioc: per adapter object
7007 *
7008 * Return nothing.
7009 */
7010static void
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307011_scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06007012{
7013 struct _sas_device *sas_device, *sas_device_next;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307014 struct _sas_node *sas_expander, *sas_expander_next;
Eric Moore635374e2009-03-09 01:21:12 -06007015 struct _raid_device *raid_device, *raid_device_next;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307016 struct list_head tmp_list;
7017 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06007018
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307019 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
7020 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06007021
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307022 /* removing unresponding end devices */
7023 printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n",
7024 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06007025 list_for_each_entry_safe(sas_device, sas_device_next,
7026 &ioc->sas_device_list, list) {
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307027 if (!sas_device->responding)
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05307028 mpt2sas_device_remove_by_sas_address(ioc,
7029 sas_device->sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307030 else
Eric Moore635374e2009-03-09 01:21:12 -06007031 sas_device->responding = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007032 }
7033
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307034 /* removing unresponding volumes */
7035 if (ioc->ir_firmware) {
7036 printk(MPT2SAS_INFO_FMT "removing unresponding devices: "
7037 "volumes\n", ioc->name);
7038 list_for_each_entry_safe(raid_device, raid_device_next,
7039 &ioc->raid_device_list, list) {
7040 if (!raid_device->responding)
7041 _scsih_sas_volume_delete(ioc,
7042 raid_device->handle);
7043 else
7044 raid_device->responding = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007045 }
Eric Moore635374e2009-03-09 01:21:12 -06007046 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307047 /* removing unresponding expanders */
7048 printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n",
7049 ioc->name);
7050 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7051 INIT_LIST_HEAD(&tmp_list);
7052 list_for_each_entry_safe(sas_expander, sas_expander_next,
7053 &ioc->sas_expander_list, list) {
7054 if (!sas_expander->responding)
7055 list_move_tail(&sas_expander->list, &tmp_list);
7056 else
Eric Moore635374e2009-03-09 01:21:12 -06007057 sas_expander->responding = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307058 }
7059 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7060 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7061 list) {
7062 list_del(&sas_expander->list);
7063 _scsih_expander_node_remove(ioc, sas_expander);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307064 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307065 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
7066 ioc->name);
7067 /* unblock devices */
7068 _scsih_ublock_io_all_device(ioc);
7069}
7070
7071static void
7072_scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
7073 struct _sas_node *sas_expander, u16 handle)
7074{
7075 Mpi2ExpanderPage1_t expander_pg1;
7076 Mpi2ConfigReply_t mpi_reply;
7077 int i;
7078
7079 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7080 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
7081 &expander_pg1, i, handle))) {
7082 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7083 ioc->name, __FILE__, __LINE__, __func__);
7084 return;
7085 }
7086
7087 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
7088 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7089 expander_pg1.NegotiatedLinkRate >> 4);
7090 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307091}
7092
7093/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307094 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307095 * @ioc: per adapter object
7096 *
7097 * Return nothing.
7098 */
7099static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307100_scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307101{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307102 Mpi2ExpanderPage0_t expander_pg0;
7103 Mpi2SasDevicePage0_t sas_device_pg0;
7104 Mpi2RaidVolPage1_t volume_pg1;
7105 Mpi2RaidVolPage0_t volume_pg0;
7106 Mpi2RaidPhysDiskPage0_t pd_pg0;
7107 Mpi2EventIrConfigElement_t element;
7108 Mpi2ConfigReply_t mpi_reply;
7109 u8 phys_disk_num;
7110 u16 ioc_status;
7111 u16 handle, parent_handle;
7112 u64 sas_address;
7113 struct _sas_device *sas_device;
7114 struct _sas_node *expander_device;
7115 static struct _raid_device *raid_device;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307116 u8 retry_count;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307117 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307118
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307119 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307120
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307121 _scsih_sas_host_refresh(ioc);
7122
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307123 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n",
7124 ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307125 /* expanders */
7126 handle = 0xFFFF;
7127 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7128 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7129 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7130 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307131 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7132 printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: "
7133 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7134 ioc->name, ioc_status,
7135 le32_to_cpu(mpi_reply.IOCLogInfo));
7136 break;
7137 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307138 handle = le16_to_cpu(expander_pg0.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307139 spin_lock_irqsave(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307140 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7141 ioc, le64_to_cpu(expander_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307142 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307143 if (expander_device)
7144 _scsih_refresh_expander_links(ioc, expander_device,
7145 handle);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307146 else {
7147 printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: "
7148 "handle (0x%04x), sas_addr(0x%016llx)\n",
7149 ioc->name, handle, (unsigned long long)
7150 le64_to_cpu(expander_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307151 _scsih_expander_add(ioc, handle);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307152 printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: "
7153 "handle (0x%04x), sas_addr(0x%016llx)\n",
7154 ioc->name, handle, (unsigned long long)
7155 le64_to_cpu(expander_pg0.SASAddress));
7156 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307157 }
7158
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307159 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n",
7160 ioc->name);
7161
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307162 if (!ioc->ir_firmware)
7163 goto skip_to_sas;
7164
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307165 printk(MPT2SAS_INFO_FMT "\tscan devices phys disk start\n", ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307166 /* phys disk */
7167 phys_disk_num = 0xFF;
7168 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7169 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7170 phys_disk_num))) {
7171 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7172 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307173 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7174 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:"
7175 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7176 ioc->name, ioc_status,
7177 le32_to_cpu(mpi_reply.IOCLogInfo));
7178 break;
7179 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307180 phys_disk_num = pd_pg0.PhysDiskNum;
7181 handle = le16_to_cpu(pd_pg0.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307182 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307183 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307184 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307185 if (sas_device)
7186 continue;
7187 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7188 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7189 handle) != 0)
7190 continue;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307191 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7192 MPI2_IOCSTATUS_MASK;
7193 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7194 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan "
7195 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7196 ioc->name, ioc_status,
7197 le32_to_cpu(mpi_reply.IOCLogInfo));
7198 break;
7199 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307200 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7201 if (!_scsih_get_sas_address(ioc, parent_handle,
7202 &sas_address)) {
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307203 printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: "
7204 " handle (0x%04x), sas_addr(0x%016llx)\n",
7205 ioc->name, handle, (unsigned long long)
7206 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307207 mpt2sas_transport_update_links(ioc, sas_address,
7208 handle, sas_device_pg0.PhyNum,
7209 MPI2_SAS_NEG_LINK_RATE_1_5);
7210 set_bit(handle, ioc->pd_handles);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307211 retry_count = 0;
7212 /* This will retry adding the end device.
7213 * _scsih_add_device() will decide on retries and
7214 * return "1" when it should be retried
7215 */
7216 while (_scsih_add_device(ioc, handle, retry_count++,
7217 1)) {
7218 ssleep(1);
7219 }
7220 printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: "
7221 " handle (0x%04x), sas_addr(0x%016llx)\n",
7222 ioc->name, handle, (unsigned long long)
7223 le64_to_cpu(sas_device_pg0.SASAddress));
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307224 }
7225 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307226
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307227 printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n",
7228 ioc->name);
7229
7230 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes start\n", ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307231 /* volumes */
7232 handle = 0xFFFF;
7233 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7234 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7235 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7236 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307237 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7238 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7239 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7240 ioc->name, ioc_status,
7241 le32_to_cpu(mpi_reply.IOCLogInfo));
7242 break;
7243 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307244 handle = le16_to_cpu(volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307245 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307246 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7247 le64_to_cpu(volume_pg1.WWID));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307248 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307249 if (raid_device)
7250 continue;
7251 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7252 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7253 sizeof(Mpi2RaidVolPage0_t)))
7254 continue;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307255 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7256 MPI2_IOCSTATUS_MASK;
7257 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7258 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7259 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7260 ioc->name, ioc_status,
7261 le32_to_cpu(mpi_reply.IOCLogInfo));
7262 break;
7263 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307264 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7265 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7266 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7267 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7268 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7269 element.VolDevHandle = volume_pg1.DevHandle;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307270 printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: "
7271 " handle (0x%04x)\n", ioc->name,
7272 volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307273 _scsih_sas_volume_add(ioc, &element);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307274 printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: "
7275 " handle (0x%04x)\n", ioc->name,
7276 volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307277 }
7278 }
7279
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307280 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n",
7281 ioc->name);
7282
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307283 skip_to_sas:
7284
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307285 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n",
7286 ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307287 /* sas devices */
7288 handle = 0xFFFF;
7289 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7290 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7291 handle))) {
7292 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7293 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307294 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7295 printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:"
7296 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7297 ioc->name, ioc_status,
7298 le32_to_cpu(mpi_reply.IOCLogInfo));
7299 break;
7300 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307301 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7302 if (!(_scsih_is_end_device(
7303 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7304 continue;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307305 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307306 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7307 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307308 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307309 if (sas_device)
7310 continue;
7311 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7312 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307313 printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: "
7314 "handle (0x%04x), sas_addr(0x%016llx)\n",
7315 ioc->name, handle, (unsigned long long)
7316 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307317 mpt2sas_transport_update_links(ioc, sas_address, handle,
7318 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307319 retry_count = 0;
7320 /* This will retry adding the end device.
7321 * _scsih_add_device() will decide on retries and
7322 * return "1" when it should be retried
7323 */
7324 while (_scsih_add_device(ioc, handle, retry_count++,
7325 0)) {
7326 ssleep(1);
7327 }
7328 printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: "
7329 "handle (0x%04x), sas_addr(0x%016llx)\n",
7330 ioc->name, handle, (unsigned long long)
7331 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307332 }
7333 }
7334
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307335 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n",
7336 ioc->name);
7337
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307338 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307339}
7340
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307341
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307342/**
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307343 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7344 * @ioc: per adapter object
7345 * @reset_phase: phase
7346 *
7347 * The handler for doing any required cleanup or initialization.
7348 *
7349 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7350 * MPT2_IOC_DONE_RESET
7351 *
7352 * Return nothing.
7353 */
7354void
7355mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7356{
7357 switch (reset_phase) {
7358 case MPT2_IOC_PRE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307359 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307360 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307361 break;
7362 case MPT2_IOC_AFTER_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307363 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307364 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307365 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7366 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7367 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7368 complete(&ioc->scsih_cmds.done);
7369 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307370 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7371 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7372 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7373 complete(&ioc->tm_cmds.done);
7374 }
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307375 _scsih_fw_event_cleanup_queue(ioc);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307376 _scsih_flush_running_cmds(ioc);
7377 break;
7378 case MPT2_IOC_DONE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307379 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307380 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307381 _scsih_sas_host_refresh(ioc);
Kashyap, Desai14695852010-03-30 10:52:44 +05307382 _scsih_prep_device_scan(ioc);
7383 _scsih_search_responding_sas_devices(ioc);
7384 _scsih_search_responding_raid_devices(ioc);
7385 _scsih_search_responding_expanders(ioc);
sreekanth.reddy@lsi.com14aa7f72012-07-17 15:56:13 +05307386 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7387 !ioc->sas_hba.num_phys)) {
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307388 _scsih_prep_device_scan(ioc);
7389 _scsih_search_responding_sas_devices(ioc);
7390 _scsih_search_responding_raid_devices(ioc);
7391 _scsih_search_responding_expanders(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307392 _scsih_error_recovery_delete_devices(ioc);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307393 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307394 break;
Eric Moore635374e2009-03-09 01:21:12 -06007395 }
7396}
7397
7398/**
7399 * _firmware_event_work - delayed task for processing firmware events
7400 * @ioc: per adapter object
7401 * @work: equal to the fw_event_work object
7402 * Context: user.
7403 *
7404 * Return nothing.
7405 */
7406static void
7407_firmware_event_work(struct work_struct *work)
7408{
7409 struct fw_event_work *fw_event = container_of(work,
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307410 struct fw_event_work, delayed_work.work);
Eric Moore635374e2009-03-09 01:21:12 -06007411 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7412
Eric Moore635374e2009-03-09 01:21:12 -06007413 /* the queue is being flushed so ignore this event */
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05307414 if (ioc->remove_host ||
Eric Moore3cb54692010-07-08 14:44:34 -06007415 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06007416 _scsih_fw_event_free(ioc, fw_event);
7417 return;
7418 }
Eric Moore635374e2009-03-09 01:21:12 -06007419
Eric Moore635374e2009-03-09 01:21:12 -06007420 switch (fw_event->event) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307421 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307422 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307423 ssleep(1);
7424 _scsih_remove_unresponding_sas_devices(ioc);
7425 _scsih_scan_for_devices_after_reset(ioc);
7426 break;
7427 case MPT2SAS_PORT_ENABLE_COMPLETE:
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307428 ioc->start_scan = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307429
Reddy, Sreekanthb0df96a02013-02-26 16:59:59 +05307430 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7431 mpt2sas_base_update_missing_delay(ioc, missing_delay[0],
7432 missing_delay[1]);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307433
7434 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7435 "from worker thread\n", ioc->name));
7436 break;
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05307437 case MPT2SAS_TURN_ON_PFA_LED:
7438 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05307439 break;
Eric Moore635374e2009-03-09 01:21:12 -06007440 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307441 _scsih_sas_topology_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007442 break;
7443 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307444 _scsih_sas_device_status_change_event(ioc,
7445 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007446 break;
7447 case MPI2_EVENT_SAS_DISCOVERY:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307448 _scsih_sas_discovery_event(ioc,
7449 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007450 break;
7451 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
Andrew Mortona78e21d2012-02-08 12:52:22 -08007452 _scsih_sas_broadcast_primitive_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307453 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007454 break;
7455 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7456 _scsih_sas_enclosure_dev_status_change_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307457 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007458 break;
7459 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307460 _scsih_sas_ir_config_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007461 break;
7462 case MPI2_EVENT_IR_VOLUME:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307463 _scsih_sas_ir_volume_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007464 break;
7465 case MPI2_EVENT_IR_PHYSICAL_DISK:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307466 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007467 break;
7468 case MPI2_EVENT_IR_OPERATION_STATUS:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307469 _scsih_sas_ir_operation_status_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007470 break;
Eric Moore635374e2009-03-09 01:21:12 -06007471 }
7472 _scsih_fw_event_free(ioc, fw_event);
7473}
7474
7475/**
7476 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7477 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307478 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06007479 * @reply: reply message frame(lower 32bit addr)
7480 * Context: interrupt.
7481 *
7482 * This function merely adds a new work task into ioc->firmware_event_thread.
7483 * The tasks are worked from _firmware_event_work in user context.
7484 *
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307485 * Returns void.
Eric Moore635374e2009-03-09 01:21:12 -06007486 */
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307487void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307488mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7489 u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06007490{
7491 struct fw_event_work *fw_event;
7492 Mpi2EventNotificationReply_t *mpi_reply;
Eric Moore635374e2009-03-09 01:21:12 -06007493 u16 event;
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307494 u16 sz;
Eric Moore635374e2009-03-09 01:21:12 -06007495
7496 /* events turned off due to host reset or driver unloading */
Eric Moore3cb54692010-07-08 14:44:34 -06007497 if (ioc->remove_host || ioc->pci_error_recovery)
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307498 return;
Eric Moore635374e2009-03-09 01:21:12 -06007499
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307500 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05307501
7502 if (unlikely(!mpi_reply)) {
7503 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7504 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307505 return;
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05307506 }
7507
Eric Moore635374e2009-03-09 01:21:12 -06007508 event = le16_to_cpu(mpi_reply->Event);
7509
7510 switch (event) {
7511 /* handle these */
7512 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7513 {
7514 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7515 (Mpi2EventDataSasBroadcastPrimitive_t *)
7516 mpi_reply->EventData;
7517
7518 if (baen_data->Primitive !=
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307519 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307520 return;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307521
7522 if (ioc->broadcast_aen_busy) {
7523 ioc->broadcast_aen_pending++;
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307524 return;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307525 } else
7526 ioc->broadcast_aen_busy = 1;
Eric Moore635374e2009-03-09 01:21:12 -06007527 break;
7528 }
7529
7530 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7531 _scsih_check_topo_delete_events(ioc,
7532 (Mpi2EventDataSasTopologyChangeList_t *)
7533 mpi_reply->EventData);
7534 break;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05307535 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7536 _scsih_check_ir_config_unhide_events(ioc,
7537 (Mpi2EventDataIrConfigChangeList_t *)
7538 mpi_reply->EventData);
7539 break;
7540 case MPI2_EVENT_IR_VOLUME:
7541 _scsih_check_volume_delete_events(ioc,
7542 (Mpi2EventDataIrVolume_t *)
7543 mpi_reply->EventData);
7544 break;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307545 case MPI2_EVENT_LOG_ENTRY_ADDED:
7546 {
7547 Mpi2EventDataLogEntryAdded_t *log_entry;
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05307548 __le32 *log_code;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307549
7550 if (!ioc->is_warpdrive)
7551 break;
7552
7553 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7554 mpi_reply->EventData;
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05307555 log_code = (__le32 *)log_entry->LogData;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307556
7557 if (le16_to_cpu(log_entry->LogEntryQualifier)
7558 != MPT2_WARPDRIVE_LOGENTRY)
7559 break;
7560
7561 switch (le32_to_cpu(*log_code)) {
7562 case MPT2_WARPDRIVE_LC_SSDT:
7563 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7564 "IO Throttling has occurred in the WarpDrive "
7565 "subsystem. Check WarpDrive documentation for "
7566 "additional details.\n", ioc->name);
7567 break;
7568 case MPT2_WARPDRIVE_LC_SSDLW:
7569 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7570 "Program/Erase Cycles for the WarpDrive subsystem "
7571 "in degraded range. Check WarpDrive documentation "
7572 "for additional details.\n", ioc->name);
7573 break;
7574 case MPT2_WARPDRIVE_LC_SSDLF:
7575 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7576 "There are no Program/Erase Cycles for the "
7577 "WarpDrive subsystem. The storage device will be "
7578 "in read-only mode. Check WarpDrive documentation "
7579 "for additional details.\n", ioc->name);
7580 break;
7581 case MPT2_WARPDRIVE_LC_BRMF:
7582 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7583 "The Backup Rail Monitor has failed on the "
7584 "WarpDrive subsystem. Check WarpDrive "
7585 "documentation for additional details.\n",
7586 ioc->name);
7587 break;
7588 }
7589
7590 break;
7591 }
Eric Moore635374e2009-03-09 01:21:12 -06007592 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7593 case MPI2_EVENT_IR_OPERATION_STATUS:
7594 case MPI2_EVENT_SAS_DISCOVERY:
7595 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
Eric Moore635374e2009-03-09 01:21:12 -06007596 case MPI2_EVENT_IR_PHYSICAL_DISK:
Eric Moore635374e2009-03-09 01:21:12 -06007597 break;
7598
Sreekanth Reddy2d8ce8c2015-01-12 11:38:56 +05307599 case MPI2_EVENT_TEMP_THRESHOLD:
7600 _scsih_temp_threshold_events(ioc,
7601 (Mpi2EventDataTemperature_t *)
7602 mpi_reply->EventData);
7603 break;
7604
Eric Moore635374e2009-03-09 01:21:12 -06007605 default: /* ignore the rest */
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307606 return;
Eric Moore635374e2009-03-09 01:21:12 -06007607 }
7608
Joe Lawrence00713ad2014-06-25 17:03:33 -04007609 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7610 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06007611 if (!fw_event) {
7612 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7613 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307614 return;
Eric Moore635374e2009-03-09 01:21:12 -06007615 }
Eric Moore635374e2009-03-09 01:21:12 -06007616
Joe Lawrence00713ad2014-06-25 17:03:33 -04007617 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
Eric Moore635374e2009-03-09 01:21:12 -06007618 fw_event->ioc = ioc;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307619 fw_event->VF_ID = mpi_reply->VF_ID;
7620 fw_event->VP_ID = mpi_reply->VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -06007621 fw_event->event = event;
7622 _scsih_fw_event_add(ioc, fw_event);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307623 return;
Eric Moore635374e2009-03-09 01:21:12 -06007624}
7625
7626/* shost template */
7627static struct scsi_host_template scsih_driver_template = {
7628 .module = THIS_MODULE,
7629 .name = "Fusion MPT SAS Host",
7630 .proc_name = MPT2SAS_DRIVER_NAME,
Eric Moored5d135b2009-05-18 13:02:08 -06007631 .queuecommand = _scsih_qcmd,
7632 .target_alloc = _scsih_target_alloc,
7633 .slave_alloc = _scsih_slave_alloc,
7634 .slave_configure = _scsih_slave_configure,
7635 .target_destroy = _scsih_target_destroy,
7636 .slave_destroy = _scsih_slave_destroy,
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307637 .scan_finished = _scsih_scan_finished,
7638 .scan_start = _scsih_scan_start,
Eric Moored5d135b2009-05-18 13:02:08 -06007639 .change_queue_depth = _scsih_change_queue_depth,
Eric Moored5d135b2009-05-18 13:02:08 -06007640 .eh_abort_handler = _scsih_abort,
7641 .eh_device_reset_handler = _scsih_dev_reset,
7642 .eh_target_reset_handler = _scsih_target_reset,
7643 .eh_host_reset_handler = _scsih_host_reset,
7644 .bios_param = _scsih_bios_param,
Eric Moore635374e2009-03-09 01:21:12 -06007645 .can_queue = 1,
7646 .this_id = -1,
7647 .sg_tablesize = MPT2SAS_SG_DEPTH,
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05307648 .max_sectors = 32767,
Eric Moore635374e2009-03-09 01:21:12 -06007649 .cmd_per_lun = 7,
7650 .use_clustering = ENABLE_CLUSTERING,
7651 .shost_attrs = mpt2sas_host_attrs,
7652 .sdev_attrs = mpt2sas_dev_attrs,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +01007653 .track_queue_depth = 1,
Eric Moore635374e2009-03-09 01:21:12 -06007654};
7655
7656/**
7657 * _scsih_expander_node_remove - removing expander device from list.
7658 * @ioc: per adapter object
7659 * @sas_expander: the sas_device object
7660 * Context: Calling function should acquire ioc->sas_node_lock.
7661 *
7662 * Removing object and freeing associated memory from the
7663 * ioc->sas_expander_list.
7664 *
7665 * Return nothing.
7666 */
7667static void
7668_scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7669 struct _sas_node *sas_expander)
7670{
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307671 struct _sas_port *mpt2sas_port, *next;
Eric Moore635374e2009-03-09 01:21:12 -06007672
7673 /* remove sibling ports attached to this expander */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307674 list_for_each_entry_safe(mpt2sas_port, next,
Eric Moore635374e2009-03-09 01:21:12 -06007675 &sas_expander->sas_port_list, port_list) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307676 if (ioc->shost_recovery)
7677 return;
Eric Moore635374e2009-03-09 01:21:12 -06007678 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307679 SAS_END_DEVICE)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307680 mpt2sas_device_remove_by_sas_address(ioc,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307681 mpt2sas_port->remote_identify.sas_address);
7682 else if (mpt2sas_port->remote_identify.device_type ==
7683 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06007684 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307685 SAS_FANOUT_EXPANDER_DEVICE)
7686 mpt2sas_expander_remove(ioc,
7687 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007688 }
7689
7690 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307691 sas_expander->sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06007692
7693 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7694 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7695 sas_expander->handle, (unsigned long long)
7696 sas_expander->sas_address);
7697
Eric Moore635374e2009-03-09 01:21:12 -06007698 kfree(sas_expander->phy);
7699 kfree(sas_expander);
7700}
7701
7702/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05307703 * _scsih_ir_shutdown - IR shutdown notification
7704 * @ioc: per adapter object
7705 *
7706 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7707 * the host system is shutting down.
7708 *
7709 * Return nothing.
7710 */
7711static void
7712_scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7713{
7714 Mpi2RaidActionRequest_t *mpi_request;
7715 Mpi2RaidActionReply_t *mpi_reply;
7716 u16 smid;
7717
7718 /* is IR firmware build loaded ? */
7719 if (!ioc->ir_firmware)
7720 return;
7721
Kashyap, Desai744090d2009-10-05 15:56:56 +05307722 mutex_lock(&ioc->scsih_cmds.mutex);
7723
7724 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7725 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7726 ioc->name, __func__);
7727 goto out;
7728 }
7729 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7730
7731 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7732 if (!smid) {
7733 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7734 ioc->name, __func__);
7735 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7736 goto out;
7737 }
7738
7739 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7740 ioc->scsih_cmds.smid = smid;
7741 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7742
7743 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7744 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7745
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307746 if (!ioc->hide_ir_msg)
7747 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307748 init_completion(&ioc->scsih_cmds.done);
7749 mpt2sas_base_put_smid_default(ioc, smid);
7750 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7751
7752 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7753 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7754 ioc->name, __func__);
7755 goto out;
7756 }
7757
7758 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7759 mpi_reply = ioc->scsih_cmds.reply;
7760
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307761 if (!ioc->hide_ir_msg)
7762 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7763 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7764 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7765 le32_to_cpu(mpi_reply->IOCLogInfo));
Kashyap, Desai744090d2009-10-05 15:56:56 +05307766 }
7767
7768 out:
7769 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7770 mutex_unlock(&ioc->scsih_cmds.mutex);
7771}
7772
7773/**
7774 * _scsih_shutdown - routine call during system shutdown
7775 * @pdev: PCI device struct
7776 *
7777 * Return nothing.
7778 */
7779static void
7780_scsih_shutdown(struct pci_dev *pdev)
7781{
7782 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7783 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307784 struct workqueue_struct *wq;
7785 unsigned long flags;
7786
7787 ioc->remove_host = 1;
7788 _scsih_fw_event_cleanup_queue(ioc);
7789
7790 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7791 wq = ioc->firmware_event_thread;
7792 ioc->firmware_event_thread = NULL;
7793 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7794 if (wq)
7795 destroy_workqueue(wq);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307796
7797 _scsih_ir_shutdown(ioc);
7798 mpt2sas_base_detach(ioc);
7799}
7800
7801/**
Eric Moored5d135b2009-05-18 13:02:08 -06007802 * _scsih_remove - detach and remove add host
Eric Moore635374e2009-03-09 01:21:12 -06007803 * @pdev: PCI device struct
7804 *
Kashyap, Desai744090d2009-10-05 15:56:56 +05307805 * Routine called when unloading the driver.
Eric Moore635374e2009-03-09 01:21:12 -06007806 * Return nothing.
7807 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08007808static void
Eric Moored5d135b2009-05-18 13:02:08 -06007809_scsih_remove(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06007810{
7811 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7812 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307813 struct _sas_port *mpt2sas_port, *next_port;
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307814 struct _raid_device *raid_device, *next;
7815 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06007816 struct workqueue_struct *wq;
7817 unsigned long flags;
7818
7819 ioc->remove_host = 1;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307820 _scsih_fw_event_cleanup_queue(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007821
7822 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7823 wq = ioc->firmware_event_thread;
7824 ioc->firmware_event_thread = NULL;
7825 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7826 if (wq)
7827 destroy_workqueue(wq);
7828
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307829 /* release all the volumes */
Kashyap, Desai3a9c9132011-01-04 11:40:23 +05307830 _scsih_ir_shutdown(ioc);
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307831 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7832 list) {
7833 if (raid_device->starget) {
7834 sas_target_priv_data =
7835 raid_device->starget->hostdata;
7836 sas_target_priv_data->deleted = 1;
7837 scsi_remove_target(&raid_device->starget->dev);
7838 }
7839 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7840 "(0x%016llx)\n", ioc->name, raid_device->handle,
7841 (unsigned long long) raid_device->wwid);
7842 _scsih_raid_device_remove(ioc, raid_device);
7843 }
7844
Eric Moore635374e2009-03-09 01:21:12 -06007845 /* free ports attached to the sas_host */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307846 list_for_each_entry_safe(mpt2sas_port, next_port,
Eric Moore635374e2009-03-09 01:21:12 -06007847 &ioc->sas_hba.sas_port_list, port_list) {
7848 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307849 SAS_END_DEVICE)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307850 mpt2sas_device_remove_by_sas_address(ioc,
Eric Moore635374e2009-03-09 01:21:12 -06007851 mpt2sas_port->remote_identify.sas_address);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307852 else if (mpt2sas_port->remote_identify.device_type ==
7853 SAS_EDGE_EXPANDER_DEVICE ||
7854 mpt2sas_port->remote_identify.device_type ==
7855 SAS_FANOUT_EXPANDER_DEVICE)
7856 mpt2sas_expander_remove(ioc,
7857 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007858 }
7859
7860 /* free phys attached to the sas_host */
7861 if (ioc->sas_hba.num_phys) {
7862 kfree(ioc->sas_hba.phy);
7863 ioc->sas_hba.phy = NULL;
7864 ioc->sas_hba.num_phys = 0;
7865 }
7866
7867 sas_remove_host(shost);
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05307868 scsi_remove_host(shost);
kashyap.desai@lsi.com9ae89b02011-08-04 16:47:50 +05307869 mpt2sas_base_detach(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007870 list_del(&ioc->list);
Eric Moore635374e2009-03-09 01:21:12 -06007871 scsi_host_put(shost);
7872}
7873
7874/**
7875 * _scsih_probe_boot_devices - reports 1st device
7876 * @ioc: per adapter object
7877 *
7878 * If specified in bios page 2, this routine reports the 1st
7879 * device scsi-ml or sas transport for persistent boot device
7880 * purposes. Please refer to function _scsih_determine_boot_device()
7881 */
7882static void
7883_scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7884{
7885 u8 is_raid;
7886 void *device;
7887 struct _sas_device *sas_device;
7888 struct _raid_device *raid_device;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307889 u16 handle;
7890 u64 sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007891 u64 sas_address;
7892 unsigned long flags;
7893 int rc;
7894
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307895 /* no Bios, return immediately */
7896 if (!ioc->bios_pg3.BiosVersion)
7897 return;
7898
Eric Moore635374e2009-03-09 01:21:12 -06007899 device = NULL;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307900 is_raid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007901 if (ioc->req_boot_device.device) {
7902 device = ioc->req_boot_device.device;
7903 is_raid = ioc->req_boot_device.is_raid;
7904 } else if (ioc->req_alt_boot_device.device) {
7905 device = ioc->req_alt_boot_device.device;
7906 is_raid = ioc->req_alt_boot_device.is_raid;
7907 } else if (ioc->current_boot_device.device) {
7908 device = ioc->current_boot_device.device;
7909 is_raid = ioc->current_boot_device.is_raid;
7910 }
7911
7912 if (!device)
7913 return;
7914
7915 if (is_raid) {
7916 raid_device = device;
7917 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7918 raid_device->id, 0);
7919 if (rc)
7920 _scsih_raid_device_remove(ioc, raid_device);
7921 } else {
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307922 spin_lock_irqsave(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06007923 sas_device = device;
7924 handle = sas_device->handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307925 sas_address_parent = sas_device->sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007926 sas_address = sas_device->sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06007927 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7928 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307929
7930 if (ioc->hide_drives)
7931 return;
Eric Moore635374e2009-03-09 01:21:12 -06007932 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307933 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -06007934 _scsih_sas_device_remove(ioc, sas_device);
7935 } else if (!sas_device->starget) {
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307936 if (!ioc->is_driver_loading) {
7937 mpt2sas_transport_port_remove(ioc,
7938 sas_address,
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05307939 sas_address_parent);
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307940 _scsih_sas_device_remove(ioc, sas_device);
7941 }
Eric Moore635374e2009-03-09 01:21:12 -06007942 }
7943 }
7944}
7945
7946/**
7947 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7948 * @ioc: per adapter object
7949 *
7950 * Called during initial loading of the driver.
7951 */
7952static void
7953_scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7954{
7955 struct _raid_device *raid_device, *raid_next;
7956 int rc;
7957
7958 list_for_each_entry_safe(raid_device, raid_next,
7959 &ioc->raid_device_list, list) {
7960 if (raid_device->starget)
7961 continue;
7962 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7963 raid_device->id, 0);
7964 if (rc)
7965 _scsih_raid_device_remove(ioc, raid_device);
7966 }
7967}
7968
7969/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307970 * _scsih_probe_sas - reporting sas devices to sas transport
Eric Moore635374e2009-03-09 01:21:12 -06007971 * @ioc: per adapter object
7972 *
7973 * Called during initial loading of the driver.
7974 */
7975static void
7976_scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7977{
7978 struct _sas_device *sas_device, *next;
7979 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06007980
7981 /* SAS Device List */
7982 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7983 list) {
Eric Moore635374e2009-03-09 01:21:12 -06007984
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307985 if (ioc->hide_drives)
7986 continue;
7987
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307988 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7989 sas_device->sas_address_parent)) {
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307990 list_del(&sas_device->list);
7991 kfree(sas_device);
7992 continue;
Eric Moore635374e2009-03-09 01:21:12 -06007993 } else if (!sas_device->starget) {
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307994 if (!ioc->is_driver_loading) {
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05307995 mpt2sas_transport_port_remove(ioc,
7996 sas_device->sas_address,
7997 sas_device->sas_address_parent);
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307998 list_del(&sas_device->list);
7999 kfree(sas_device);
8000 continue;
8001 }
Eric Moore635374e2009-03-09 01:21:12 -06008002 }
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05308003 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8004 list_move_tail(&sas_device->list, &ioc->sas_device_list);
8005 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06008006 }
8007}
8008
8009/**
8010 * _scsih_probe_devices - probing for devices
8011 * @ioc: per adapter object
8012 *
8013 * Called during initial loading of the driver.
8014 */
8015static void
8016_scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
8017{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308018 u16 volume_mapping_flags;
Eric Moore635374e2009-03-09 01:21:12 -06008019
8020 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8021 return; /* return when IOC doesn't support initiator mode */
8022
8023 _scsih_probe_boot_devices(ioc);
8024
8025 if (ioc->ir_firmware) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308026 volume_mapping_flags =
8027 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8028 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8029 if (volume_mapping_flags ==
8030 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
Eric Moore635374e2009-03-09 01:21:12 -06008031 _scsih_probe_raid(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308032 _scsih_probe_sas(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008033 } else {
Eric Moore635374e2009-03-09 01:21:12 -06008034 _scsih_probe_sas(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308035 _scsih_probe_raid(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008036 }
8037 } else
8038 _scsih_probe_sas(ioc);
8039}
8040
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308041
8042/**
8043 * _scsih_scan_start - scsi lld callback for .scan_start
8044 * @shost: SCSI host pointer
8045 *
8046 * The shost has the ability to discover targets on its own instead
8047 * of scanning the entire bus. In our implemention, we will kick off
8048 * firmware discovery.
8049 */
8050static void
8051_scsih_scan_start(struct Scsi_Host *shost)
8052{
8053 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8054 int rc;
8055
8056 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8057 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
8058
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05308059 if (disable_discovery > 0)
8060 return;
8061
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308062 ioc->start_scan = 1;
8063 rc = mpt2sas_port_enable(ioc);
8064
8065 if (rc != 0)
8066 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
8067}
8068
8069/**
8070 * _scsih_scan_finished - scsi lld callback for .scan_finished
8071 * @shost: SCSI host pointer
8072 * @time: elapsed time of the scan in jiffies
8073 *
8074 * This function will be called periodically until it returns 1 with the
8075 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8076 * we wait for firmware discovery to complete, then return 1.
8077 */
8078static int
8079_scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8080{
8081 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8082
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05308083 if (disable_discovery > 0) {
8084 ioc->is_driver_loading = 0;
8085 ioc->wait_for_discovery_to_complete = 0;
8086 return 1;
8087 }
8088
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308089 if (time >= (300 * HZ)) {
8090 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8091 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
8092 "(timeout=300s)\n", ioc->name);
8093 ioc->is_driver_loading = 0;
8094 return 1;
8095 }
8096
8097 if (ioc->start_scan)
8098 return 0;
8099
8100 if (ioc->start_scan_failed) {
8101 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
8102 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
8103 ioc->is_driver_loading = 0;
8104 ioc->wait_for_discovery_to_complete = 0;
8105 ioc->remove_host = 1;
8106 return 1;
8107 }
8108
8109 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
8110 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8111
8112 if (ioc->wait_for_discovery_to_complete) {
8113 ioc->wait_for_discovery_to_complete = 0;
8114 _scsih_probe_devices(ioc);
8115 }
8116 mpt2sas_base_start_watchdog(ioc);
8117 ioc->is_driver_loading = 0;
8118 return 1;
8119}
8120
8121
Eric Moore635374e2009-03-09 01:21:12 -06008122/**
Eric Moored5d135b2009-05-18 13:02:08 -06008123 * _scsih_probe - attach and add scsi host
Eric Moore635374e2009-03-09 01:21:12 -06008124 * @pdev: PCI device struct
8125 * @id: pci device id
8126 *
8127 * Returns 0 success, anything else error.
8128 */
8129static int
Eric Moored5d135b2009-05-18 13:02:08 -06008130_scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
Eric Moore635374e2009-03-09 01:21:12 -06008131{
8132 struct MPT2SAS_ADAPTER *ioc;
8133 struct Scsi_Host *shost;
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308134 int rv;
Eric Moore635374e2009-03-09 01:21:12 -06008135
8136 shost = scsi_host_alloc(&scsih_driver_template,
8137 sizeof(struct MPT2SAS_ADAPTER));
8138 if (!shost)
8139 return -ENODEV;
8140
8141 /* init local params */
8142 ioc = shost_priv(shost);
8143 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
8144 INIT_LIST_HEAD(&ioc->list);
Eric Mooreba33fad2009-03-15 21:37:18 -06008145 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
Eric Moore635374e2009-03-09 01:21:12 -06008146 ioc->shost = shost;
8147 ioc->id = mpt_ids++;
8148 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
8149 ioc->pdev = pdev;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308150 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8151 ioc->is_warpdrive = 1;
8152 ioc->hide_ir_msg = 1;
8153 } else
8154 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
Eric Moore635374e2009-03-09 01:21:12 -06008155 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8156 ioc->tm_cb_idx = tm_cb_idx;
8157 ioc->ctl_cb_idx = ctl_cb_idx;
8158 ioc->base_cb_idx = base_cb_idx;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308159 ioc->port_enable_cb_idx = port_enable_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008160 ioc->transport_cb_idx = transport_cb_idx;
Kashyap, Desai744090d2009-10-05 15:56:56 +05308161 ioc->scsih_cb_idx = scsih_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008162 ioc->config_cb_idx = config_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308163 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308164 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308165 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008166 ioc->logging_level = logging_level;
nagalakshmi.nandigama@lsi.com845a0e42011-12-01 07:42:04 +05308167 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
Eric Moore635374e2009-03-09 01:21:12 -06008168 /* misc semaphores and spin locks */
Kashyap, Desaid2742132010-06-17 13:28:55 +05308169 mutex_init(&ioc->reset_in_progress_mutex);
Eric Moore635374e2009-03-09 01:21:12 -06008170 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8171 spin_lock_init(&ioc->scsi_lookup_lock);
8172 spin_lock_init(&ioc->sas_device_lock);
8173 spin_lock_init(&ioc->sas_node_lock);
8174 spin_lock_init(&ioc->fw_event_lock);
8175 spin_lock_init(&ioc->raid_device_lock);
8176
8177 INIT_LIST_HEAD(&ioc->sas_device_list);
8178 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8179 INIT_LIST_HEAD(&ioc->sas_expander_list);
8180 INIT_LIST_HEAD(&ioc->fw_event_list);
8181 INIT_LIST_HEAD(&ioc->raid_device_list);
8182 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308183 INIT_LIST_HEAD(&ioc->delayed_tr_list);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308184 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
Joe Lawrence3b3e6f82013-08-08 16:45:38 -04008185 INIT_LIST_HEAD(&ioc->reply_queue_list);
Eric Moore635374e2009-03-09 01:21:12 -06008186
8187 /* init shost parameters */
Eric Moored334aa72010-04-22 10:47:40 -06008188 shost->max_cmd_len = 32;
Eric Moore635374e2009-03-09 01:21:12 -06008189 shost->max_lun = max_lun;
8190 shost->transportt = mpt2sas_transport_template;
8191 shost->unique_id = ioc->id;
8192
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308193 if (max_sectors != 0xFFFF) {
8194 if (max_sectors < 64) {
8195 shost->max_sectors = 64;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05308196 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8197 "for max_sectors, range is 64 to 32767. Assigning "
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308198 "value of 64.\n", ioc->name, max_sectors);
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05308199 } else if (max_sectors > 32767) {
8200 shost->max_sectors = 32767;
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308201 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8202 "for max_sectors, range is 64 to 8192. Assigning "
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05308203 "default value of 32767.\n", ioc->name,
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308204 max_sectors);
8205 } else {
8206 shost->max_sectors = max_sectors & 0xFFFE;
8207 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
8208 "set to %d\n", ioc->name, shost->max_sectors);
8209 }
8210 }
8211
Martin K. Petersen5e95e732012-08-28 14:29:37 -04008212 /* register EEDP capabilities with SCSI layer */
8213 if (prot_mask)
8214 scsi_host_set_prot(shost, prot_mask);
8215 else
8216 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8217 | SHOST_DIF_TYPE2_PROTECTION
8218 | SHOST_DIF_TYPE3_PROTECTION);
8219
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308220 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
Eric Moore3c621b32009-05-18 12:59:41 -06008221
Eric Moore635374e2009-03-09 01:21:12 -06008222 /* event thread */
8223 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8224 "fw_event%d", ioc->id);
8225 ioc->firmware_event_thread = create_singlethread_workqueue(
8226 ioc->firmware_event_name);
8227 if (!ioc->firmware_event_thread) {
8228 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8229 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308230 rv = -ENODEV;
Eric Moore635374e2009-03-09 01:21:12 -06008231 goto out_thread_fail;
8232 }
8233
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308234 ioc->is_driver_loading = 1;
Eric Moore635374e2009-03-09 01:21:12 -06008235 if ((mpt2sas_base_attach(ioc))) {
8236 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8237 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308238 rv = -ENODEV;
Eric Moore635374e2009-03-09 01:21:12 -06008239 goto out_attach_fail;
8240 }
8241
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308242 if (ioc->is_warpdrive) {
8243 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8244 ioc->hide_drives = 0;
8245 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8246 ioc->hide_drives = 1;
8247 else {
8248 if (_scsih_get_num_volumes(ioc))
8249 ioc->hide_drives = 1;
8250 else
8251 ioc->hide_drives = 0;
8252 }
8253 } else
8254 ioc->hide_drives = 0;
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05308255
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308256 rv = scsi_add_host(shost, &pdev->dev);
8257 if (rv) {
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05308258 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8259 ioc->name, __FILE__, __LINE__, __func__);
8260 goto out_add_shost_fail;
8261 }
8262
nagalakshmi.nandigama@lsi.com2cb6fc82011-12-13 09:29:15 +05308263 scsi_scan_host(shost);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308264
Eric Moore635374e2009-03-09 01:21:12 -06008265 return 0;
8266
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05308267 out_add_shost_fail:
8268 mpt2sas_base_detach(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008269 out_attach_fail:
8270 destroy_workqueue(ioc->firmware_event_thread);
8271 out_thread_fail:
8272 list_del(&ioc->list);
Tomas Henzlf555e052012-04-17 15:24:48 +02008273 scsi_host_put(shost);
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308274 return rv;
Eric Moore635374e2009-03-09 01:21:12 -06008275}
8276
8277#ifdef CONFIG_PM
8278/**
Eric Moored5d135b2009-05-18 13:02:08 -06008279 * _scsih_suspend - power management suspend main entry point
Eric Moore635374e2009-03-09 01:21:12 -06008280 * @pdev: PCI device struct
8281 * @state: PM state change to (usually PCI_D3)
8282 *
8283 * Returns 0 success, anything else error.
8284 */
8285static int
Eric Moored5d135b2009-05-18 13:02:08 -06008286_scsih_suspend(struct pci_dev *pdev, pm_message_t state)
Eric Moore635374e2009-03-09 01:21:12 -06008287{
8288 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8289 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05308290 pci_power_t device_state;
Eric Moore635374e2009-03-09 01:21:12 -06008291
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308292 mpt2sas_base_stop_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008293 scsi_block_requests(shost);
Sreekanth Reddy3627dba2013-07-25 11:25:57 +05308294 _scsih_ir_shutdown(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008295 device_state = pci_choose_state(pdev, state);
8296 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8297 "operating state [D%d]\n", ioc->name, pdev,
8298 pci_name(pdev), device_state);
8299
8300 mpt2sas_base_free_resources(ioc);
8301 pci_save_state(pdev);
Eric Moore635374e2009-03-09 01:21:12 -06008302 pci_set_power_state(pdev, device_state);
8303 return 0;
8304}
8305
8306/**
Eric Moored5d135b2009-05-18 13:02:08 -06008307 * _scsih_resume - power management resume main entry point
Eric Moore635374e2009-03-09 01:21:12 -06008308 * @pdev: PCI device struct
8309 *
8310 * Returns 0 success, anything else error.
8311 */
8312static int
Eric Moored5d135b2009-05-18 13:02:08 -06008313_scsih_resume(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06008314{
8315 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8316 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05308317 pci_power_t device_state = pdev->current_state;
Eric Moore635374e2009-03-09 01:21:12 -06008318 int r;
8319
8320 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8321 "operating state [D%d]\n", ioc->name, pdev,
8322 pci_name(pdev), device_state);
8323
8324 pci_set_power_state(pdev, PCI_D0);
8325 pci_enable_wake(pdev, PCI_D0, 0);
8326 pci_restore_state(pdev);
8327 ioc->pdev = pdev;
8328 r = mpt2sas_base_map_resources(ioc);
8329 if (r)
8330 return r;
8331
8332 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8333 scsi_unblock_requests(shost);
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308334 mpt2sas_base_start_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008335 return 0;
8336}
8337#endif /* CONFIG_PM */
8338
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308339/**
8340 * _scsih_pci_error_detected - Called when a PCI error is detected.
8341 * @pdev: PCI device struct
8342 * @state: PCI channel state
8343 *
8344 * Description: Called when a PCI error is detected.
8345 *
8346 * Return value:
8347 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8348 */
8349static pci_ers_result_t
8350_scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8351{
8352 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8353 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8354
8355 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8356 ioc->name, state);
8357
8358 switch (state) {
8359 case pci_channel_io_normal:
8360 return PCI_ERS_RESULT_CAN_RECOVER;
8361 case pci_channel_io_frozen:
Eric Moore3cb54692010-07-08 14:44:34 -06008362 /* Fatal error, prepare for slot reset */
8363 ioc->pci_error_recovery = 1;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308364 scsi_block_requests(ioc->shost);
8365 mpt2sas_base_stop_watchdog(ioc);
8366 mpt2sas_base_free_resources(ioc);
8367 return PCI_ERS_RESULT_NEED_RESET;
8368 case pci_channel_io_perm_failure:
Eric Moore3cb54692010-07-08 14:44:34 -06008369 /* Permanent error, prepare for device removal */
8370 ioc->pci_error_recovery = 1;
8371 mpt2sas_base_stop_watchdog(ioc);
8372 _scsih_flush_running_cmds(ioc);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308373 return PCI_ERS_RESULT_DISCONNECT;
8374 }
8375 return PCI_ERS_RESULT_NEED_RESET;
8376}
8377
8378/**
8379 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8380 * @pdev: PCI device struct
8381 *
8382 * Description: This routine is called by the pci error recovery
8383 * code after the PCI slot has been reset, just before we
8384 * should resume normal operations.
8385 */
8386static pci_ers_result_t
8387_scsih_pci_slot_reset(struct pci_dev *pdev)
8388{
8389 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8390 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8391 int rc;
8392
8393 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8394 ioc->name);
8395
Eric Moore3cb54692010-07-08 14:44:34 -06008396 ioc->pci_error_recovery = 0;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308397 ioc->pdev = pdev;
Eric Moore3cb54692010-07-08 14:44:34 -06008398 pci_restore_state(pdev);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308399 rc = mpt2sas_base_map_resources(ioc);
8400 if (rc)
8401 return PCI_ERS_RESULT_DISCONNECT;
8402
8403
8404 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8405 FORCE_BIG_HAMMER);
8406
8407 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8408 (rc == 0) ? "success" : "failed");
8409
8410 if (!rc)
8411 return PCI_ERS_RESULT_RECOVERED;
8412 else
8413 return PCI_ERS_RESULT_DISCONNECT;
8414}
8415
8416/**
8417 * _scsih_pci_resume() - resume normal ops after PCI reset
8418 * @pdev: pointer to PCI device
8419 *
8420 * Called when the error recovery driver tells us that its
8421 * OK to resume normal operation. Use completion to allow
8422 * halted scsi ops to resume.
8423 */
8424static void
8425_scsih_pci_resume(struct pci_dev *pdev)
8426{
8427 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8428 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8429
8430 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8431
8432 pci_cleanup_aer_uncorrect_error_status(pdev);
8433 mpt2sas_base_start_watchdog(ioc);
8434 scsi_unblock_requests(ioc->shost);
8435}
8436
8437/**
8438 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8439 * @pdev: pointer to PCI device
8440 */
8441static pci_ers_result_t
8442_scsih_pci_mmio_enabled(struct pci_dev *pdev)
8443{
8444 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8445 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8446
8447 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8448 ioc->name);
8449
8450 /* TODO - dump whatever for debugging purposes */
8451
8452 /* Request a slot reset. */
8453 return PCI_ERS_RESULT_NEED_RESET;
8454}
8455
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07008456static const struct pci_error_handlers _scsih_err_handler = {
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308457 .error_detected = _scsih_pci_error_detected,
8458 .mmio_enabled = _scsih_pci_mmio_enabled,
8459 .slot_reset = _scsih_pci_slot_reset,
8460 .resume = _scsih_pci_resume,
8461};
Eric Moore635374e2009-03-09 01:21:12 -06008462
8463static struct pci_driver scsih_driver = {
8464 .name = MPT2SAS_DRIVER_NAME,
8465 .id_table = scsih_pci_table,
Eric Moored5d135b2009-05-18 13:02:08 -06008466 .probe = _scsih_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008467 .remove = _scsih_remove,
Kashyap, Desai744090d2009-10-05 15:56:56 +05308468 .shutdown = _scsih_shutdown,
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308469 .err_handler = &_scsih_err_handler,
Eric Moore635374e2009-03-09 01:21:12 -06008470#ifdef CONFIG_PM
Eric Moored5d135b2009-05-18 13:02:08 -06008471 .suspend = _scsih_suspend,
8472 .resume = _scsih_resume,
Eric Moore635374e2009-03-09 01:21:12 -06008473#endif
8474};
8475
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308476/* raid transport support */
8477static struct raid_function_template mpt2sas_raid_functions = {
8478 .cookie = &scsih_driver_template,
8479 .is_raid = _scsih_is_raid,
8480 .get_resync = _scsih_get_resync,
8481 .get_state = _scsih_get_state,
8482};
Eric Moore635374e2009-03-09 01:21:12 -06008483
8484/**
Eric Moored5d135b2009-05-18 13:02:08 -06008485 * _scsih_init - main entry point for this driver.
Eric Moore635374e2009-03-09 01:21:12 -06008486 *
8487 * Returns 0 success, anything else error.
8488 */
8489static int __init
Eric Moored5d135b2009-05-18 13:02:08 -06008490_scsih_init(void)
Eric Moore635374e2009-03-09 01:21:12 -06008491{
8492 int error;
8493
8494 mpt_ids = 0;
8495 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8496 MPT2SAS_DRIVER_VERSION);
8497
8498 mpt2sas_transport_template =
8499 sas_attach_transport(&mpt2sas_transport_functions);
8500 if (!mpt2sas_transport_template)
8501 return -ENODEV;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308502 /* raid transport support */
8503 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8504 if (!mpt2sas_raid_template) {
8505 sas_release_transport(mpt2sas_transport_template);
8506 return -ENODEV;
8507 }
Eric Moore635374e2009-03-09 01:21:12 -06008508
8509 mpt2sas_base_initialize_callback_handler();
8510
8511 /* queuecommand callback hander */
Eric Moored5d135b2009-05-18 13:02:08 -06008512 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
Eric Moore635374e2009-03-09 01:21:12 -06008513
Uwe Kleine-König65155b32010-06-11 12:17:01 +02008514 /* task management callback handler */
Eric Moored5d135b2009-05-18 13:02:08 -06008515 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
Eric Moore635374e2009-03-09 01:21:12 -06008516
8517 /* base internal commands callback handler */
8518 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308519 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8520 mpt2sas_port_enable_done);
Eric Moore635374e2009-03-09 01:21:12 -06008521
8522 /* transport internal commands callback handler */
8523 transport_cb_idx = mpt2sas_base_register_callback_handler(
8524 mpt2sas_transport_done);
8525
Kashyap, Desai744090d2009-10-05 15:56:56 +05308526 /* scsih internal commands callback handler */
8527 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8528
Eric Moore635374e2009-03-09 01:21:12 -06008529 /* configuration page API internal commands callback handler */
8530 config_cb_idx = mpt2sas_base_register_callback_handler(
8531 mpt2sas_config_done);
8532
8533 /* ctl module callback handler */
8534 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8535
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308536 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8537 _scsih_tm_tr_complete);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308538
8539 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8540 _scsih_tm_volume_tr_complete);
8541
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308542 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8543 _scsih_sas_control_complete);
8544
Eric Moore635374e2009-03-09 01:21:12 -06008545 mpt2sas_ctl_init();
8546
8547 error = pci_register_driver(&scsih_driver);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308548 if (error) {
8549 /* raid transport support */
8550 raid_class_release(mpt2sas_raid_template);
Eric Moore635374e2009-03-09 01:21:12 -06008551 sas_release_transport(mpt2sas_transport_template);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308552 }
Eric Moore635374e2009-03-09 01:21:12 -06008553
8554 return error;
8555}
8556
8557/**
Eric Moored5d135b2009-05-18 13:02:08 -06008558 * _scsih_exit - exit point for this driver (when it is a module).
Eric Moore635374e2009-03-09 01:21:12 -06008559 *
8560 * Returns 0 success, anything else error.
8561 */
8562static void __exit
Eric Moored5d135b2009-05-18 13:02:08 -06008563_scsih_exit(void)
Eric Moore635374e2009-03-09 01:21:12 -06008564{
8565 printk(KERN_INFO "mpt2sas version %s unloading\n",
8566 MPT2SAS_DRIVER_VERSION);
8567
8568 pci_unregister_driver(&scsih_driver);
8569
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308570 mpt2sas_ctl_exit();
8571
Eric Moore635374e2009-03-09 01:21:12 -06008572 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8573 mpt2sas_base_release_callback_handler(tm_cb_idx);
8574 mpt2sas_base_release_callback_handler(base_cb_idx);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308575 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008576 mpt2sas_base_release_callback_handler(transport_cb_idx);
Kashyap, Desai744090d2009-10-05 15:56:56 +05308577 mpt2sas_base_release_callback_handler(scsih_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008578 mpt2sas_base_release_callback_handler(config_cb_idx);
8579 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8580
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308581 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308582 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308583 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8584
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308585 /* raid transport support */
8586 raid_class_release(mpt2sas_raid_template);
8587 sas_release_transport(mpt2sas_transport_template);
8588
Eric Moore635374e2009-03-09 01:21:12 -06008589}
8590
Eric Moored5d135b2009-05-18 13:02:08 -06008591module_init(_scsih_init);
8592module_exit(_scsih_exit);