blob: b006e1e9fcb8c0a94f83e4be9473b96a182e294a [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
Eric Moore635374e2009-03-09 01:21:12 -06006 * (mailto:DL-MPTFusionLinux@lsi.com)
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * NO WARRANTY
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
28
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
37
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
41 * USA.
42 */
43
Eric Moore635374e2009-03-09 01:21:12 -060044#include <linux/module.h>
45#include <linux/kernel.h>
46#include <linux/init.h>
47#include <linux/errno.h>
48#include <linux/blkdev.h>
49#include <linux/sched.h>
50#include <linux/workqueue.h>
51#include <linux/delay.h>
52#include <linux/pci.h>
53#include <linux/interrupt.h>
Kashyap, Desaief7c80c2010-04-05 14:20:07 +053054#include <linux/aer.h>
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +053055#include <linux/raid_class.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090056#include <linux/slab.h>
Eric Moore635374e2009-03-09 01:21:12 -060057
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +053058#include <asm/unaligned.h>
59
Eric Moore635374e2009-03-09 01:21:12 -060060#include "mpt2sas_base.h"
61
62MODULE_AUTHOR(MPT2SAS_AUTHOR);
63MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
64MODULE_LICENSE("GPL");
65MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
66
67#define RAID_CHANNEL 1
68
69/* forward proto's */
70static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
71 struct _sas_node *sas_expander);
72static void _firmware_event_work(struct work_struct *work);
73
Kashyap, Desaif3eedd62010-06-17 13:46:13 +053074static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
75
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +053076static void _scsih_scan_start(struct Scsi_Host *shost);
77static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
78
Eric Moore635374e2009-03-09 01:21:12 -060079/* global parameters */
Eric Mooreba33fad2009-03-15 21:37:18 -060080LIST_HEAD(mpt2sas_ioc_list);
Eric Moore635374e2009-03-09 01:21:12 -060081
82/* local parameters */
Eric Moore635374e2009-03-09 01:21:12 -060083static u8 scsi_io_cb_idx = -1;
84static u8 tm_cb_idx = -1;
85static u8 ctl_cb_idx = -1;
86static u8 base_cb_idx = -1;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +053087static u8 port_enable_cb_idx = -1;
Eric Moore635374e2009-03-09 01:21:12 -060088static u8 transport_cb_idx = -1;
Kashyap, Desai744090d2009-10-05 15:56:56 +053089static u8 scsih_cb_idx = -1;
Eric Moore635374e2009-03-09 01:21:12 -060090static u8 config_cb_idx = -1;
91static int mpt_ids;
92
Kashyap, Desai77e63ed2009-09-14 11:04:23 +053093static u8 tm_tr_cb_idx = -1 ;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +053094static u8 tm_tr_volume_cb_idx = -1 ;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +053095static u8 tm_sas_control_cb_idx = -1;
96
Eric Moore635374e2009-03-09 01:21:12 -060097/* command line options */
Eric Mooreba33fad2009-03-15 21:37:18 -060098static u32 logging_level;
Eric Moore635374e2009-03-09 01:21:12 -060099MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
100 "(default=0)");
101
Kashyap, Desaia3e1e552011-06-14 10:56:12 +0530102static ushort max_sectors = 0xFFFF;
103module_param(max_sectors, ushort, 0);
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +0530104MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
Kashyap, Desaia3e1e552011-06-14 10:56:12 +0530105
Reddy, Sreekanthb0df96a02013-02-26 16:59:59 +0530106static int missing_delay[2] = {-1, -1};
107module_param_array(missing_delay, int, NULL, 0);
108MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
109
Eric Moore635374e2009-03-09 01:21:12 -0600110/* scsi-mid layer global parmeter is max_report_luns, which is 511 */
111#define MPT2SAS_MAX_LUN (16895)
112static int max_lun = MPT2SAS_MAX_LUN;
113module_param(max_lun, int, 0);
114MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
115
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530116/* diag_buffer_enable is bitwise
117 * bit 0 set = TRACE
118 * bit 1 set = SNAPSHOT
119 * bit 2 set = EXTENDED
120 *
121 * Either bit can be set, or both
122 */
123static int diag_buffer_enable = -1;
124module_param(diag_buffer_enable, int, 0);
125MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
126 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
127
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +0530128static int disable_discovery = -1;
129module_param(disable_discovery, int, 0);
130MODULE_PARM_DESC(disable_discovery, " disable discovery ");
131
Martin K. Petersen5e95e732012-08-28 14:29:37 -0400132/* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
133static int prot_mask = 0;
134module_param(prot_mask, int, 0);
135MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
136
Eric Moore635374e2009-03-09 01:21:12 -0600137/**
138 * struct sense_info - common structure for obtaining sense keys
139 * @skey: sense key
140 * @asc: additional sense code
141 * @ascq: additional sense code qualifier
142 */
143struct sense_info {
144 u8 skey;
145 u8 asc;
146 u8 ascq;
147};
148
149
Sreekanth Reddybd58ea32014-09-12 15:35:19 +0530150#define MPT2SAS_TURN_ON_PFA_LED (0xFFFC)
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530151#define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
152#define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
Eric Moore635374e2009-03-09 01:21:12 -0600153/**
154 * struct fw_event_work - firmware event struct
155 * @list: link list framework
156 * @work: work object (ioc->fault_reset_work_q)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +0530157 * @cancel_pending_work: flag set during reset handling
Eric Moore635374e2009-03-09 01:21:12 -0600158 * @ioc: per adapter object
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530159 * @device_handle: device handle
Eric Moore635374e2009-03-09 01:21:12 -0600160 * @VF_ID: virtual function id
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530161 * @VP_ID: virtual port id
Eric Moore635374e2009-03-09 01:21:12 -0600162 * @ignore: flag meaning this event has been marked to ignore
163 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
164 * @event_data: reply event data payload follows
165 *
166 * This object stored on ioc->fw_event_list.
167 */
168struct fw_event_work {
169 struct list_head list;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +0530170 u8 cancel_pending_work;
171 struct delayed_work delayed_work;
Eric Moore635374e2009-03-09 01:21:12 -0600172 struct MPT2SAS_ADAPTER *ioc;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530173 u16 device_handle;
Eric Moore635374e2009-03-09 01:21:12 -0600174 u8 VF_ID;
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530175 u8 VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -0600176 u8 ignore;
177 u16 event;
Joe Lawrence00713ad2014-06-25 17:03:33 -0400178 char event_data[0] __aligned(4);
Eric Moore635374e2009-03-09 01:21:12 -0600179};
180
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +0530181/* raid transport support */
182static struct raid_template *mpt2sas_raid_template;
183
Eric Moore635374e2009-03-09 01:21:12 -0600184/**
185 * struct _scsi_io_transfer - scsi io transfer
186 * @handle: sas device handle (assigned by firmware)
187 * @is_raid: flag set for hidden raid components
188 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
189 * @data_length: data transfer length
190 * @data_dma: dma pointer to data
191 * @sense: sense data
192 * @lun: lun number
193 * @cdb_length: cdb length
194 * @cdb: cdb contents
Eric Moore635374e2009-03-09 01:21:12 -0600195 * @timeout: timeout for this command
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530196 * @VF_ID: virtual function id
197 * @VP_ID: virtual port id
198 * @valid_reply: flag set for reply message
Eric Moore635374e2009-03-09 01:21:12 -0600199 * @sense_length: sense length
200 * @ioc_status: ioc status
201 * @scsi_state: scsi state
202 * @scsi_status: scsi staus
203 * @log_info: log information
204 * @transfer_length: data length transfer when there is a reply message
205 *
206 * Used for sending internal scsi commands to devices within this module.
207 * Refer to _scsi_send_scsi_io().
208 */
209struct _scsi_io_transfer {
210 u16 handle;
211 u8 is_raid;
212 enum dma_data_direction dir;
213 u32 data_length;
214 dma_addr_t data_dma;
215 u8 sense[SCSI_SENSE_BUFFERSIZE];
216 u32 lun;
217 u8 cdb_length;
218 u8 cdb[32];
219 u8 timeout;
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530220 u8 VF_ID;
221 u8 VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -0600222 u8 valid_reply;
223 /* the following bits are only valid when 'valid_reply = 1' */
224 u32 sense_length;
225 u16 ioc_status;
226 u8 scsi_state;
227 u8 scsi_status;
228 u32 log_info;
229 u32 transfer_length;
230};
231
232/*
233 * The pci device ids are defined in mpi/mpi2_cnfg.h.
234 */
235static struct pci_device_id scsih_pci_table[] = {
236 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
237 PCI_ANY_ID, PCI_ANY_ID },
238 /* Falcon ~ 2008*/
239 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
240 PCI_ANY_ID, PCI_ANY_ID },
241 /* Liberator ~ 2108 */
242 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
243 PCI_ANY_ID, PCI_ANY_ID },
244 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
245 PCI_ANY_ID, PCI_ANY_ID },
246 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
247 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desaidb271362009-09-23 17:24:27 +0530248 /* Meteor ~ 2116 */
Eric Moore635374e2009-03-09 01:21:12 -0600249 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
250 PCI_ANY_ID, PCI_ANY_ID },
251 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
252 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desaidb271362009-09-23 17:24:27 +0530253 /* Thunderbolt ~ 2208 */
254 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
255 PCI_ANY_ID, PCI_ANY_ID },
256 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
257 PCI_ANY_ID, PCI_ANY_ID },
258 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
259 PCI_ANY_ID, PCI_ANY_ID },
260 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
261 PCI_ANY_ID, PCI_ANY_ID },
262 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
263 PCI_ANY_ID, PCI_ANY_ID },
264 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
265 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai203d65b2010-06-17 13:37:59 +0530266 /* Mustang ~ 2308 */
267 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
Kashyap, Desaidb271362009-09-23 17:24:27 +0530268 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai203d65b2010-06-17 13:37:59 +0530269 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
270 PCI_ANY_ID, PCI_ANY_ID },
271 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
Kashyap, Desaidb271362009-09-23 17:24:27 +0530272 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +0530273 /* SSS6200 */
274 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
275 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore635374e2009-03-09 01:21:12 -0600276 {0} /* Terminating entry */
277};
278MODULE_DEVICE_TABLE(pci, scsih_pci_table);
279
280/**
Eric Moored5d135b2009-05-18 13:02:08 -0600281 * _scsih_set_debug_level - global setting of ioc->logging_level.
Eric Moore635374e2009-03-09 01:21:12 -0600282 *
283 * Note: The logging levels are defined in mpt2sas_debug.h.
284 */
285static int
Eric Moored5d135b2009-05-18 13:02:08 -0600286_scsih_set_debug_level(const char *val, struct kernel_param *kp)
Eric Moore635374e2009-03-09 01:21:12 -0600287{
288 int ret = param_set_int(val, kp);
289 struct MPT2SAS_ADAPTER *ioc;
290
291 if (ret)
292 return ret;
293
294 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
Eric Mooreba33fad2009-03-15 21:37:18 -0600295 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
Eric Moore635374e2009-03-09 01:21:12 -0600296 ioc->logging_level = logging_level;
297 return 0;
298}
Eric Moored5d135b2009-05-18 13:02:08 -0600299module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
Eric Moore635374e2009-03-09 01:21:12 -0600300 &logging_level, 0644);
301
302/**
303 * _scsih_srch_boot_sas_address - search based on sas_address
304 * @sas_address: sas address
305 * @boot_device: boot device object from bios page 2
306 *
307 * Returns 1 when there's a match, 0 means no match.
308 */
309static inline int
310_scsih_srch_boot_sas_address(u64 sas_address,
311 Mpi2BootDeviceSasWwid_t *boot_device)
312{
313 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
314}
315
316/**
317 * _scsih_srch_boot_device_name - search based on device name
318 * @device_name: device name specified in INDENTIFY fram
319 * @boot_device: boot device object from bios page 2
320 *
321 * Returns 1 when there's a match, 0 means no match.
322 */
323static inline int
324_scsih_srch_boot_device_name(u64 device_name,
325 Mpi2BootDeviceDeviceName_t *boot_device)
326{
327 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
328}
329
330/**
331 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
332 * @enclosure_logical_id: enclosure logical id
333 * @slot_number: slot number
334 * @boot_device: boot device object from bios page 2
335 *
336 * Returns 1 when there's a match, 0 means no match.
337 */
338static inline int
339_scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
340 Mpi2BootDeviceEnclosureSlot_t *boot_device)
341{
342 return (enclosure_logical_id == le64_to_cpu(boot_device->
343 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
344 SlotNumber)) ? 1 : 0;
345}
346
347/**
348 * _scsih_is_boot_device - search for matching boot device.
349 * @sas_address: sas address
350 * @device_name: device name specified in INDENTIFY fram
351 * @enclosure_logical_id: enclosure logical id
352 * @slot_number: slot number
353 * @form: specifies boot device form
354 * @boot_device: boot device object from bios page 2
355 *
356 * Returns 1 when there's a match, 0 means no match.
357 */
358static int
359_scsih_is_boot_device(u64 sas_address, u64 device_name,
360 u64 enclosure_logical_id, u16 slot, u8 form,
361 Mpi2BiosPage2BootDevice_t *boot_device)
362{
363 int rc = 0;
364
365 switch (form) {
366 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
367 if (!sas_address)
368 break;
369 rc = _scsih_srch_boot_sas_address(
370 sas_address, &boot_device->SasWwid);
371 break;
372 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
373 if (!enclosure_logical_id)
374 break;
375 rc = _scsih_srch_boot_encl_slot(
376 enclosure_logical_id,
377 slot, &boot_device->EnclosureSlot);
378 break;
379 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
380 if (!device_name)
381 break;
382 rc = _scsih_srch_boot_device_name(
383 device_name, &boot_device->DeviceName);
384 break;
385 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
386 break;
387 }
388
389 return rc;
390}
391
392/**
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530393 * _scsih_get_sas_address - set the sas_address for given device handle
394 * @handle: device handle
395 * @sas_address: sas address
396 *
397 * Returns 0 success, non-zero when failure
398 */
399static int
400_scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
401 u64 *sas_address)
402{
403 Mpi2SasDevicePage0_t sas_device_pg0;
404 Mpi2ConfigReply_t mpi_reply;
405 u32 ioc_status;
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530406 *sas_address = 0;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530407
408 if (handle <= ioc->sas_hba.num_phys) {
409 *sas_address = ioc->sas_hba.sas_address;
410 return 0;
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530411 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530412
413 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
414 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530415 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
416 __FILE__, __LINE__, __func__);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530417 return -ENXIO;
418 }
419
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530420 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
421 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
422 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
423 return 0;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530424 }
425
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530426 /* we hit this becuase the given parent handle doesn't exist */
427 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
428 return -ENXIO;
429 /* else error case */
430 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
431 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
432 __FILE__, __LINE__, __func__);
433 return -EIO;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530434}
435
436/**
Eric Moore635374e2009-03-09 01:21:12 -0600437 * _scsih_determine_boot_device - determine boot device.
438 * @ioc: per adapter object
439 * @device: either sas_device or raid_device object
440 * @is_raid: [flag] 1 = raid object, 0 = sas object
441 *
442 * Determines whether this device should be first reported device to
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300443 * to scsi-ml or sas transport, this purpose is for persistent boot device.
Eric Moore635374e2009-03-09 01:21:12 -0600444 * There are primary, alternate, and current entries in bios page 2. The order
445 * priority is primary, alternate, then current. This routine saves
446 * the corresponding device object and is_raid flag in the ioc object.
447 * The saved data to be used later in _scsih_probe_boot_devices().
448 */
449static void
450_scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
451 void *device, u8 is_raid)
452{
453 struct _sas_device *sas_device;
454 struct _raid_device *raid_device;
455 u64 sas_address;
456 u64 device_name;
457 u64 enclosure_logical_id;
458 u16 slot;
459
460 /* only process this function when driver loads */
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530461 if (!ioc->is_driver_loading)
462 return;
463
464 /* no Bios, return immediately */
465 if (!ioc->bios_pg3.BiosVersion)
Eric Moore635374e2009-03-09 01:21:12 -0600466 return;
467
468 if (!is_raid) {
469 sas_device = device;
470 sas_address = sas_device->sas_address;
471 device_name = sas_device->device_name;
472 enclosure_logical_id = sas_device->enclosure_logical_id;
473 slot = sas_device->slot;
474 } else {
475 raid_device = device;
476 sas_address = raid_device->wwid;
477 device_name = 0;
478 enclosure_logical_id = 0;
479 slot = 0;
480 }
481
482 if (!ioc->req_boot_device.device) {
483 if (_scsih_is_boot_device(sas_address, device_name,
484 enclosure_logical_id, slot,
485 (ioc->bios_pg2.ReqBootDeviceForm &
486 MPI2_BIOSPAGE2_FORM_MASK),
487 &ioc->bios_pg2.RequestedBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530488 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600489 "%s: req_boot_device(0x%016llx)\n",
490 ioc->name, __func__,
491 (unsigned long long)sas_address));
492 ioc->req_boot_device.device = device;
493 ioc->req_boot_device.is_raid = is_raid;
494 }
495 }
496
497 if (!ioc->req_alt_boot_device.device) {
498 if (_scsih_is_boot_device(sas_address, device_name,
499 enclosure_logical_id, slot,
500 (ioc->bios_pg2.ReqAltBootDeviceForm &
501 MPI2_BIOSPAGE2_FORM_MASK),
502 &ioc->bios_pg2.RequestedAltBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530503 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600504 "%s: req_alt_boot_device(0x%016llx)\n",
505 ioc->name, __func__,
506 (unsigned long long)sas_address));
507 ioc->req_alt_boot_device.device = device;
508 ioc->req_alt_boot_device.is_raid = is_raid;
509 }
510 }
511
512 if (!ioc->current_boot_device.device) {
513 if (_scsih_is_boot_device(sas_address, device_name,
514 enclosure_logical_id, slot,
515 (ioc->bios_pg2.CurrentBootDeviceForm &
516 MPI2_BIOSPAGE2_FORM_MASK),
517 &ioc->bios_pg2.CurrentBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530518 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600519 "%s: current_boot_device(0x%016llx)\n",
520 ioc->name, __func__,
521 (unsigned long long)sas_address));
522 ioc->current_boot_device.device = device;
523 ioc->current_boot_device.is_raid = is_raid;
524 }
525 }
526}
527
528/**
529 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
530 * @ioc: per adapter object
531 * @sas_address: sas address
532 * Context: Calling function should acquire ioc->sas_device_lock
533 *
534 * This searches for sas_device based on sas_address, then return sas_device
535 * object.
536 */
537struct _sas_device *
538mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
539 u64 sas_address)
540{
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530541 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600542
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530543 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
544 if (sas_device->sas_address == sas_address)
545 return sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600546
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530547 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
548 if (sas_device->sas_address == sas_address)
549 return sas_device;
550
551 return NULL;
Eric Moore635374e2009-03-09 01:21:12 -0600552}
553
554/**
555 * _scsih_sas_device_find_by_handle - sas device search
556 * @ioc: per adapter object
557 * @handle: sas device handle (assigned by firmware)
558 * Context: Calling function should acquire ioc->sas_device_lock
559 *
560 * This searches for sas_device based on sas_address, then return sas_device
561 * object.
562 */
563static struct _sas_device *
564_scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
565{
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530566 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600567
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530568 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
569 if (sas_device->handle == handle)
570 return sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600571
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530572 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
573 if (sas_device->handle == handle)
574 return sas_device;
575
576 return NULL;
Eric Moore635374e2009-03-09 01:21:12 -0600577}
578
579/**
580 * _scsih_sas_device_remove - remove sas_device from list.
581 * @ioc: per adapter object
582 * @sas_device: the sas_device object
583 * Context: This function will acquire ioc->sas_device_lock.
584 *
585 * Removing object and freeing associated memory from the ioc->sas_device_list.
586 */
587static void
588_scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
589 struct _sas_device *sas_device)
590{
591 unsigned long flags;
592
Kashyap, Desai980ead32010-04-08 17:55:22 +0530593 if (!sas_device)
594 return;
595
Eric Moore635374e2009-03-09 01:21:12 -0600596 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530597 list_del(&sas_device->list);
598 kfree(sas_device);
Eric Moore635374e2009-03-09 01:21:12 -0600599 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
600}
601
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530602
Eric Moore635374e2009-03-09 01:21:12 -0600603/**
604 * _scsih_sas_device_add - insert sas_device to the list.
605 * @ioc: per adapter object
606 * @sas_device: the sas_device object
607 * Context: This function will acquire ioc->sas_device_lock.
608 *
609 * Adding new object to the ioc->sas_device_list.
610 */
611static void
612_scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
613 struct _sas_device *sas_device)
614{
615 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -0600616
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530617 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600618 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
619 sas_device->handle, (unsigned long long)sas_device->sas_address));
620
621 spin_lock_irqsave(&ioc->sas_device_lock, flags);
622 list_add_tail(&sas_device->list, &ioc->sas_device_list);
623 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
624
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530625 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +0530626 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -0600627 _scsih_sas_device_remove(ioc, sas_device);
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +0530628 } else if (!sas_device->starget) {
629 /* When asyn scanning is enabled, its not possible to remove
630 * devices while scanning is turned on due to an oops in
631 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
632 */
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +0530633 if (!ioc->is_driver_loading) {
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +0530634 mpt2sas_transport_port_remove(ioc,
635 sas_device->sas_address,
636 sas_device->sas_address_parent);
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +0530637 _scsih_sas_device_remove(ioc, sas_device);
638 }
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +0530639 }
Eric Moore635374e2009-03-09 01:21:12 -0600640}
641
642/**
643 * _scsih_sas_device_init_add - insert sas_device to the list.
644 * @ioc: per adapter object
645 * @sas_device: the sas_device object
646 * Context: This function will acquire ioc->sas_device_lock.
647 *
648 * Adding new object at driver load time to the ioc->sas_device_init_list.
649 */
650static void
651_scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
652 struct _sas_device *sas_device)
653{
654 unsigned long flags;
655
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530656 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600657 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
658 sas_device->handle, (unsigned long long)sas_device->sas_address));
659
660 spin_lock_irqsave(&ioc->sas_device_lock, flags);
661 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
Eric Moore635374e2009-03-09 01:21:12 -0600662 _scsih_determine_boot_device(ioc, sas_device, 0);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530663 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -0600664}
665
666/**
Eric Moore635374e2009-03-09 01:21:12 -0600667 * _scsih_raid_device_find_by_id - raid device search
668 * @ioc: per adapter object
669 * @id: sas device target id
670 * @channel: sas device channel
671 * Context: Calling function should acquire ioc->raid_device_lock
672 *
673 * This searches for raid_device based on target id, then return raid_device
674 * object.
675 */
676static struct _raid_device *
677_scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
678{
679 struct _raid_device *raid_device, *r;
680
681 r = NULL;
682 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
683 if (raid_device->id == id && raid_device->channel == channel) {
684 r = raid_device;
685 goto out;
686 }
687 }
688
689 out:
690 return r;
691}
692
693/**
694 * _scsih_raid_device_find_by_handle - raid device search
695 * @ioc: per adapter object
696 * @handle: sas device handle (assigned by firmware)
697 * Context: Calling function should acquire ioc->raid_device_lock
698 *
699 * This searches for raid_device based on handle, then return raid_device
700 * object.
701 */
702static struct _raid_device *
703_scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
704{
705 struct _raid_device *raid_device, *r;
706
707 r = NULL;
708 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
709 if (raid_device->handle != handle)
710 continue;
711 r = raid_device;
712 goto out;
713 }
714
715 out:
716 return r;
717}
718
719/**
720 * _scsih_raid_device_find_by_wwid - raid device search
721 * @ioc: per adapter object
722 * @handle: sas device handle (assigned by firmware)
723 * Context: Calling function should acquire ioc->raid_device_lock
724 *
725 * This searches for raid_device based on wwid, then return raid_device
726 * object.
727 */
728static struct _raid_device *
729_scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
730{
731 struct _raid_device *raid_device, *r;
732
733 r = NULL;
734 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
735 if (raid_device->wwid != wwid)
736 continue;
737 r = raid_device;
738 goto out;
739 }
740
741 out:
742 return r;
743}
744
745/**
746 * _scsih_raid_device_add - add raid_device object
747 * @ioc: per adapter object
748 * @raid_device: raid_device object
749 *
750 * This is added to the raid_device_list link list.
751 */
752static void
753_scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
754 struct _raid_device *raid_device)
755{
756 unsigned long flags;
757
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530758 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600759 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
760 raid_device->handle, (unsigned long long)raid_device->wwid));
761
762 spin_lock_irqsave(&ioc->raid_device_lock, flags);
763 list_add_tail(&raid_device->list, &ioc->raid_device_list);
764 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
765}
766
767/**
768 * _scsih_raid_device_remove - delete raid_device object
769 * @ioc: per adapter object
770 * @raid_device: raid_device object
771 *
Eric Moore635374e2009-03-09 01:21:12 -0600772 */
773static void
774_scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
775 struct _raid_device *raid_device)
776{
777 unsigned long flags;
778
779 spin_lock_irqsave(&ioc->raid_device_lock, flags);
780 list_del(&raid_device->list);
Eric Moore635374e2009-03-09 01:21:12 -0600781 kfree(raid_device);
782 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
783}
784
785/**
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530786 * mpt2sas_scsih_expander_find_by_handle - expander device search
787 * @ioc: per adapter object
788 * @handle: expander handle (assigned by firmware)
789 * Context: Calling function should acquire ioc->sas_device_lock
790 *
791 * This searches for expander device based on handle, then returns the
792 * sas_node object.
793 */
794struct _sas_node *
795mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
796{
797 struct _sas_node *sas_expander, *r;
798
799 r = NULL;
800 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
801 if (sas_expander->handle != handle)
802 continue;
803 r = sas_expander;
804 goto out;
805 }
806 out:
807 return r;
808}
809
810/**
Eric Moore635374e2009-03-09 01:21:12 -0600811 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
812 * @ioc: per adapter object
813 * @sas_address: sas address
814 * Context: Calling function should acquire ioc->sas_node_lock.
815 *
816 * This searches for expander device based on sas_address, then returns the
817 * sas_node object.
818 */
819struct _sas_node *
820mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
821 u64 sas_address)
822{
823 struct _sas_node *sas_expander, *r;
824
825 r = NULL;
826 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
827 if (sas_expander->sas_address != sas_address)
828 continue;
829 r = sas_expander;
830 goto out;
831 }
832 out:
833 return r;
834}
835
836/**
837 * _scsih_expander_node_add - insert expander device to the list.
838 * @ioc: per adapter object
839 * @sas_expander: the sas_device object
840 * Context: This function will acquire ioc->sas_node_lock.
841 *
842 * Adding new object to the ioc->sas_expander_list.
843 *
844 * Return nothing.
845 */
846static void
847_scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
848 struct _sas_node *sas_expander)
849{
850 unsigned long flags;
851
852 spin_lock_irqsave(&ioc->sas_node_lock, flags);
853 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
854 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
855}
856
857/**
858 * _scsih_is_end_device - determines if device is an end device
859 * @device_info: bitfield providing information about the device.
860 * Context: none
861 *
862 * Returns 1 if end device.
863 */
864static int
865_scsih_is_end_device(u32 device_info)
866{
867 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
868 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
869 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
870 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
871 return 1;
872 else
873 return 0;
874}
875
876/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530877 * _scsih_scsi_lookup_get - returns scmd entry
Eric Moore635374e2009-03-09 01:21:12 -0600878 * @ioc: per adapter object
879 * @smid: system request message index
Eric Moore635374e2009-03-09 01:21:12 -0600880 *
881 * Returns the smid stored scmd pointer.
882 */
883static struct scsi_cmnd *
884_scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
885{
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530886 return ioc->scsi_lookup[smid - 1].scmd;
Eric Moore635374e2009-03-09 01:21:12 -0600887}
888
889/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530890 * _scsih_scsi_lookup_get_clear - returns scmd entry
891 * @ioc: per adapter object
892 * @smid: system request message index
893 *
894 * Returns the smid stored scmd pointer.
895 * Then will derefrence the stored scmd pointer.
896 */
897static inline struct scsi_cmnd *
898_scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
899{
900 unsigned long flags;
901 struct scsi_cmnd *scmd;
902
903 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
904 scmd = ioc->scsi_lookup[smid - 1].scmd;
905 ioc->scsi_lookup[smid - 1].scmd = NULL;
906 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
907
908 return scmd;
909}
910
911/**
Eric Moore635374e2009-03-09 01:21:12 -0600912 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
913 * @ioc: per adapter object
914 * @smid: system request message index
915 * @scmd: pointer to scsi command object
916 * Context: This function will acquire ioc->scsi_lookup_lock.
917 *
918 * This will search for a scmd pointer in the scsi_lookup array,
919 * returning the revelent smid. A returned value of zero means invalid.
920 */
921static u16
922_scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
923 *scmd)
924{
925 u16 smid;
926 unsigned long flags;
927 int i;
928
929 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
930 smid = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530931 for (i = 0; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600932 if (ioc->scsi_lookup[i].scmd == scmd) {
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530933 smid = ioc->scsi_lookup[i].smid;
Eric Moore635374e2009-03-09 01:21:12 -0600934 goto out;
935 }
936 }
937 out:
938 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
939 return smid;
940}
941
942/**
943 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
944 * @ioc: per adapter object
945 * @id: target id
946 * @channel: channel
947 * Context: This function will acquire ioc->scsi_lookup_lock.
948 *
949 * This will search for a matching channel:id in the scsi_lookup array,
950 * returning 1 if found.
951 */
952static u8
953_scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
954 int channel)
955{
956 u8 found;
957 unsigned long flags;
958 int i;
959
960 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
961 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530962 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600963 if (ioc->scsi_lookup[i].scmd &&
964 (ioc->scsi_lookup[i].scmd->device->id == id &&
965 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
966 found = 1;
967 goto out;
968 }
969 }
970 out:
971 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
972 return found;
973}
974
975/**
Eric Moore993e0da2009-05-18 13:00:45 -0600976 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
977 * @ioc: per adapter object
978 * @id: target id
979 * @lun: lun number
980 * @channel: channel
981 * Context: This function will acquire ioc->scsi_lookup_lock.
982 *
983 * This will search for a matching channel:id:lun in the scsi_lookup array,
984 * returning 1 if found.
985 */
986static u8
987_scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
988 unsigned int lun, int channel)
989{
990 u8 found;
991 unsigned long flags;
992 int i;
993
994 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
995 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530996 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore993e0da2009-05-18 13:00:45 -0600997 if (ioc->scsi_lookup[i].scmd &&
998 (ioc->scsi_lookup[i].scmd->device->id == id &&
999 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1000 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1001 found = 1;
1002 goto out;
1003 }
1004 }
1005 out:
1006 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1007 return found;
1008}
1009
1010/**
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301011 * _scsih_get_chain_buffer_tracker - obtain chain tracker
Eric Moore635374e2009-03-09 01:21:12 -06001012 * @ioc: per adapter object
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301013 * @smid: smid associated to an IO request
Eric Moore635374e2009-03-09 01:21:12 -06001014 *
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301015 * Returns chain tracker(from ioc->free_chain_list)
Eric Moore635374e2009-03-09 01:21:12 -06001016 */
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301017static struct chain_tracker *
1018_scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
Eric Moore635374e2009-03-09 01:21:12 -06001019{
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301020 struct chain_tracker *chain_req;
1021 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001022
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301023 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1024 if (list_empty(&ioc->free_chain_list)) {
1025 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
nagalakshmi.nandigama@lsi.comaff132d2011-12-01 07:53:08 +05301026 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not "
1027 "available\n", ioc->name));
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301028 return NULL;
1029 }
1030 chain_req = list_entry(ioc->free_chain_list.next,
1031 struct chain_tracker, tracker_list);
1032 list_del_init(&chain_req->tracker_list);
1033 list_add_tail(&chain_req->tracker_list,
1034 &ioc->scsi_lookup[smid - 1].chain_list);
1035 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1036 return chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001037}
1038
1039/**
1040 * _scsih_build_scatter_gather - main sg creation routine
1041 * @ioc: per adapter object
1042 * @scmd: scsi command
1043 * @smid: system request message index
1044 * Context: none.
1045 *
1046 * The main routine that builds scatter gather table from a given
1047 * scsi request sent via the .queuecommand main handler.
1048 *
1049 * Returns 0 success, anything else error
1050 */
1051static int
1052_scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1053 struct scsi_cmnd *scmd, u16 smid)
1054{
1055 Mpi2SCSIIORequest_t *mpi_request;
1056 dma_addr_t chain_dma;
1057 struct scatterlist *sg_scmd;
1058 void *sg_local, *chain;
1059 u32 chain_offset;
1060 u32 chain_length;
1061 u32 chain_flags;
FUJITA Tomonoribb789d02010-03-09 11:09:50 +09001062 int sges_left;
Eric Moore635374e2009-03-09 01:21:12 -06001063 u32 sges_in_segment;
1064 u32 sgl_flags;
1065 u32 sgl_flags_last_element;
1066 u32 sgl_flags_end_buffer;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301067 struct chain_tracker *chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001068
1069 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1070
1071 /* init scatter gather flags */
1072 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1073 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1074 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1075 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1076 << MPI2_SGE_FLAGS_SHIFT;
1077 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1078 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1079 << MPI2_SGE_FLAGS_SHIFT;
1080 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1081
1082 sg_scmd = scsi_sglist(scmd);
1083 sges_left = scsi_dma_map(scmd);
FUJITA Tomonoribb789d02010-03-09 11:09:50 +09001084 if (sges_left < 0) {
Eric Moore635374e2009-03-09 01:21:12 -06001085 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1086 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1087 return -ENOMEM;
1088 }
1089
1090 sg_local = &mpi_request->SGL;
1091 sges_in_segment = ioc->max_sges_in_main_message;
1092 if (sges_left <= sges_in_segment)
1093 goto fill_in_last_segment;
1094
1095 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1096 (sges_in_segment * ioc->sge_size))/4;
1097
1098 /* fill in main message segment when there is a chain following */
1099 while (sges_in_segment) {
1100 if (sges_in_segment == 1)
1101 ioc->base_add_sg_single(sg_local,
1102 sgl_flags_last_element | sg_dma_len(sg_scmd),
1103 sg_dma_address(sg_scmd));
1104 else
1105 ioc->base_add_sg_single(sg_local, sgl_flags |
1106 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1107 sg_scmd = sg_next(sg_scmd);
1108 sg_local += ioc->sge_size;
1109 sges_left--;
1110 sges_in_segment--;
1111 }
1112
1113 /* initializing the chain flags and pointers */
1114 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301115 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1116 if (!chain_req)
1117 return -1;
1118 chain = chain_req->chain_buffer;
1119 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001120 do {
1121 sges_in_segment = (sges_left <=
1122 ioc->max_sges_in_chain_message) ? sges_left :
1123 ioc->max_sges_in_chain_message;
1124 chain_offset = (sges_left == sges_in_segment) ?
1125 0 : (sges_in_segment * ioc->sge_size)/4;
1126 chain_length = sges_in_segment * ioc->sge_size;
1127 if (chain_offset) {
1128 chain_offset = chain_offset <<
1129 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1130 chain_length += ioc->sge_size;
1131 }
1132 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1133 chain_length, chain_dma);
1134 sg_local = chain;
1135 if (!chain_offset)
1136 goto fill_in_last_segment;
1137
1138 /* fill in chain segments */
1139 while (sges_in_segment) {
1140 if (sges_in_segment == 1)
1141 ioc->base_add_sg_single(sg_local,
1142 sgl_flags_last_element |
1143 sg_dma_len(sg_scmd),
1144 sg_dma_address(sg_scmd));
1145 else
1146 ioc->base_add_sg_single(sg_local, sgl_flags |
1147 sg_dma_len(sg_scmd),
1148 sg_dma_address(sg_scmd));
1149 sg_scmd = sg_next(sg_scmd);
1150 sg_local += ioc->sge_size;
1151 sges_left--;
1152 sges_in_segment--;
1153 }
1154
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301155 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1156 if (!chain_req)
1157 return -1;
1158 chain = chain_req->chain_buffer;
1159 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001160 } while (1);
1161
1162
1163 fill_in_last_segment:
1164
1165 /* fill the last segment */
1166 while (sges_left) {
1167 if (sges_left == 1)
1168 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1169 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1170 else
1171 ioc->base_add_sg_single(sg_local, sgl_flags |
1172 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1173 sg_scmd = sg_next(sg_scmd);
1174 sg_local += ioc->sge_size;
1175 sges_left--;
1176 }
1177
1178 return 0;
1179}
1180
1181/**
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301182 * _scsih_adjust_queue_depth - setting device queue depth
Eric Moore635374e2009-03-09 01:21:12 -06001183 * @sdev: scsi device struct
1184 * @qdepth: requested queue depth
1185 *
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301186 *
1187 * Returns nothing
Eric Moore635374e2009-03-09 01:21:12 -06001188 */
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301189static void
1190_scsih_adjust_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:
1220
Eric Moore635374e2009-03-09 01:21:12 -06001221 if (!sdev->tagged_supported)
1222 max_depth = 1;
1223 if (qdepth > max_depth)
1224 qdepth = max_depth;
Christoph Hellwigc8b09f62014-11-03 20:15:14 +01001225 scsi_adjust_queue_depth(sdev, qdepth);
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301226}
1227
1228/**
1229 * _scsih_change_queue_depth - setting device queue depth
1230 * @sdev: scsi device struct
1231 * @qdepth: requested queue depth
Christoph Hellwigc40ecc12014-11-13 14:25:11 +01001232 * @reason: SCSI_QDEPTH_DEFAULT
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301233 * (see include/scsi/scsi_host.h for definition)
1234 *
1235 * Returns queue depth.
1236 */
1237static int
1238_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1239{
Christoph Hellwigc40ecc12014-11-13 14:25:11 +01001240 _scsih_adjust_queue_depth(sdev, qdepth);
Eric Moore635374e2009-03-09 01:21:12 -06001241
1242 if (sdev->inquiry_len > 7)
1243 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
Christoph Hellwig609aa222014-10-30 11:54:58 +01001244 "simple(%d), scsi_level(%d), cmd_que(%d)\n",
Eric Moore635374e2009-03-09 01:21:12 -06001245 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
Christoph Hellwig609aa222014-10-30 11:54:58 +01001246 sdev->scsi_level,
Eric Moore635374e2009-03-09 01:21:12 -06001247 (sdev->inquiry[7] & 2) >> 1);
1248
1249 return sdev->queue_depth;
1250}
1251
1252/**
Eric Moored5d135b2009-05-18 13:02:08 -06001253 * _scsih_target_alloc - target add routine
Eric Moore635374e2009-03-09 01:21:12 -06001254 * @starget: scsi target struct
1255 *
1256 * Returns 0 if ok. Any other return is assumed to be an error and
1257 * the device is ignored.
1258 */
1259static int
Eric Moored5d135b2009-05-18 13:02:08 -06001260_scsih_target_alloc(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001261{
1262 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1263 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1264 struct MPT2SAS_TARGET *sas_target_priv_data;
1265 struct _sas_device *sas_device;
1266 struct _raid_device *raid_device;
1267 unsigned long flags;
1268 struct sas_rphy *rphy;
1269
Joe Lawrencefeafe7c2014-06-25 17:03:14 -04001270 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1271 GFP_KERNEL);
Eric Moore635374e2009-03-09 01:21:12 -06001272 if (!sas_target_priv_data)
1273 return -ENOMEM;
1274
1275 starget->hostdata = sas_target_priv_data;
1276 sas_target_priv_data->starget = starget;
1277 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1278
1279 /* RAID volumes */
1280 if (starget->channel == RAID_CHANNEL) {
1281 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1282 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1283 starget->channel);
1284 if (raid_device) {
1285 sas_target_priv_data->handle = raid_device->handle;
1286 sas_target_priv_data->sas_address = raid_device->wwid;
1287 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301288 if (ioc->is_warpdrive)
1289 sas_target_priv_data->raid_device = raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06001290 raid_device->starget = starget;
1291 }
1292 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1293 return 0;
1294 }
1295
1296 /* sas/sata devices */
1297 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1298 rphy = dev_to_rphy(starget->dev.parent);
1299 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1300 rphy->identify.sas_address);
1301
1302 if (sas_device) {
1303 sas_target_priv_data->handle = sas_device->handle;
1304 sas_target_priv_data->sas_address = sas_device->sas_address;
1305 sas_device->starget = starget;
1306 sas_device->id = starget->id;
1307 sas_device->channel = starget->channel;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05301308 if (test_bit(sas_device->handle, ioc->pd_handles))
Eric Moore635374e2009-03-09 01:21:12 -06001309 sas_target_priv_data->flags |=
1310 MPT_TARGET_FLAGS_RAID_COMPONENT;
1311 }
1312 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1313
1314 return 0;
1315}
1316
1317/**
Eric Moored5d135b2009-05-18 13:02:08 -06001318 * _scsih_target_destroy - target destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001319 * @starget: scsi target struct
1320 *
1321 * Returns nothing.
1322 */
1323static void
Eric Moored5d135b2009-05-18 13:02:08 -06001324_scsih_target_destroy(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001325{
1326 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1327 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1328 struct MPT2SAS_TARGET *sas_target_priv_data;
1329 struct _sas_device *sas_device;
1330 struct _raid_device *raid_device;
1331 unsigned long flags;
1332 struct sas_rphy *rphy;
1333
1334 sas_target_priv_data = starget->hostdata;
1335 if (!sas_target_priv_data)
1336 return;
1337
1338 if (starget->channel == RAID_CHANNEL) {
1339 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1340 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1341 starget->channel);
1342 if (raid_device) {
1343 raid_device->starget = NULL;
1344 raid_device->sdev = NULL;
1345 }
1346 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1347 goto out;
1348 }
1349
1350 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1351 rphy = dev_to_rphy(starget->dev.parent);
1352 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1353 rphy->identify.sas_address);
Eric Moore8901cbb2009-04-21 15:41:32 -06001354 if (sas_device && (sas_device->starget == starget) &&
1355 (sas_device->id == starget->id) &&
1356 (sas_device->channel == starget->channel))
Eric Moore635374e2009-03-09 01:21:12 -06001357 sas_device->starget = NULL;
1358
1359 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1360
1361 out:
1362 kfree(sas_target_priv_data);
1363 starget->hostdata = NULL;
1364}
1365
1366/**
Eric Moored5d135b2009-05-18 13:02:08 -06001367 * _scsih_slave_alloc - device add routine
Eric Moore635374e2009-03-09 01:21:12 -06001368 * @sdev: scsi device struct
1369 *
1370 * Returns 0 if ok. Any other return is assumed to be an error and
1371 * the device is ignored.
1372 */
1373static int
Eric Moored5d135b2009-05-18 13:02:08 -06001374_scsih_slave_alloc(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001375{
1376 struct Scsi_Host *shost;
1377 struct MPT2SAS_ADAPTER *ioc;
1378 struct MPT2SAS_TARGET *sas_target_priv_data;
1379 struct MPT2SAS_DEVICE *sas_device_priv_data;
1380 struct scsi_target *starget;
1381 struct _raid_device *raid_device;
Sreekanth Reddy63e359d2013-07-25 11:32:51 +05301382 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -06001383 unsigned long flags;
1384
Joe Lawrencefeafe7c2014-06-25 17:03:14 -04001385 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1386 GFP_KERNEL);
Eric Moore635374e2009-03-09 01:21:12 -06001387 if (!sas_device_priv_data)
1388 return -ENOMEM;
1389
1390 sas_device_priv_data->lun = sdev->lun;
1391 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1392
1393 starget = scsi_target(sdev);
1394 sas_target_priv_data = starget->hostdata;
1395 sas_target_priv_data->num_luns++;
1396 sas_device_priv_data->sas_target = sas_target_priv_data;
1397 sdev->hostdata = sas_device_priv_data;
1398 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1399 sdev->no_uld_attach = 1;
1400
1401 shost = dev_to_shost(&starget->dev);
1402 ioc = shost_priv(shost);
1403 if (starget->channel == RAID_CHANNEL) {
1404 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1405 raid_device = _scsih_raid_device_find_by_id(ioc,
1406 starget->id, starget->channel);
1407 if (raid_device)
1408 raid_device->sdev = sdev; /* raid is single lun */
1409 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06001410 }
1411
Sreekanth Reddy63e359d2013-07-25 11:32:51 +05301412 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1413 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1414 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1415 sas_target_priv_data->sas_address);
1416 if (sas_device && (sas_device->starget == NULL)) {
1417 sdev_printk(KERN_INFO, sdev,
1418 "%s : sas_device->starget set to starget @ %d\n",
1419 __func__, __LINE__);
1420 sas_device->starget = starget;
1421 }
1422 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1423 }
1424
Eric Moore635374e2009-03-09 01:21:12 -06001425 return 0;
1426}
1427
1428/**
Eric Moored5d135b2009-05-18 13:02:08 -06001429 * _scsih_slave_destroy - device destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001430 * @sdev: scsi device struct
1431 *
1432 * Returns nothing.
1433 */
1434static void
Eric Moored5d135b2009-05-18 13:02:08 -06001435_scsih_slave_destroy(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001436{
1437 struct MPT2SAS_TARGET *sas_target_priv_data;
1438 struct scsi_target *starget;
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301439 struct Scsi_Host *shost;
1440 struct MPT2SAS_ADAPTER *ioc;
1441 struct _sas_device *sas_device;
1442 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001443
1444 if (!sdev->hostdata)
1445 return;
1446
1447 starget = scsi_target(sdev);
1448 sas_target_priv_data = starget->hostdata;
1449 sas_target_priv_data->num_luns--;
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301450
1451 shost = dev_to_shost(&starget->dev);
1452 ioc = shost_priv(shost);
1453
1454 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1455 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1456 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1457 sas_target_priv_data->sas_address);
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +05301458 if (sas_device && !sas_target_priv_data->num_luns)
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301459 sas_device->starget = NULL;
1460 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1461 }
1462
Eric Moore635374e2009-03-09 01:21:12 -06001463 kfree(sdev->hostdata);
1464 sdev->hostdata = NULL;
1465}
1466
1467/**
Eric Moored5d135b2009-05-18 13:02:08 -06001468 * _scsih_display_sata_capabilities - sata capabilities
Eric Moore635374e2009-03-09 01:21:12 -06001469 * @ioc: per adapter object
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301470 * @handle: device handle
Eric Moore635374e2009-03-09 01:21:12 -06001471 * @sdev: scsi device struct
1472 */
1473static void
Eric Moored5d135b2009-05-18 13:02:08 -06001474_scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301475 u16 handle, struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001476{
1477 Mpi2ConfigReply_t mpi_reply;
1478 Mpi2SasDevicePage0_t sas_device_pg0;
1479 u32 ioc_status;
1480 u16 flags;
1481 u32 device_info;
1482
1483 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301484 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06001485 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1486 ioc->name, __FILE__, __LINE__, __func__);
1487 return;
1488 }
1489
1490 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1491 MPI2_IOCSTATUS_MASK;
1492 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1493 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1494 ioc->name, __FILE__, __LINE__, __func__);
1495 return;
1496 }
1497
1498 flags = le16_to_cpu(sas_device_pg0.Flags);
Kashyap, Desaie94f6742010-03-17 16:24:52 +05301499 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
Eric Moore635374e2009-03-09 01:21:12 -06001500
1501 sdev_printk(KERN_INFO, sdev,
1502 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1503 "sw_preserve(%s)\n",
1504 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1505 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1506 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1507 "n",
1508 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1509 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1510 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1511}
1512
1513/**
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301514 * _scsih_is_raid - return boolean indicating device is raid volume
1515 * @dev the device struct object
1516 */
1517static int
1518_scsih_is_raid(struct device *dev)
1519{
1520 struct scsi_device *sdev = to_scsi_device(dev);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301521 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301522
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301523 if (ioc->is_warpdrive)
1524 return 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301525 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1526}
1527
1528/**
1529 * _scsih_get_resync - get raid volume resync percent complete
1530 * @dev the device struct object
1531 */
1532static void
1533_scsih_get_resync(struct device *dev)
1534{
1535 struct scsi_device *sdev = to_scsi_device(dev);
1536 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1537 static struct _raid_device *raid_device;
1538 unsigned long flags;
1539 Mpi2RaidVolPage0_t vol_pg0;
1540 Mpi2ConfigReply_t mpi_reply;
1541 u32 volume_status_flags;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301542 u8 percent_complete;
1543 u16 handle;
1544
1545 percent_complete = 0;
1546 handle = 0;
1547 if (ioc->is_warpdrive)
1548 goto out;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301549
1550 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1551 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1552 sdev->channel);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301553 if (raid_device) {
1554 handle = raid_device->handle;
1555 percent_complete = raid_device->percent_complete;
1556 }
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301557 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1558
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301559 if (!handle)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301560 goto out;
1561
1562 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301563 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301564 sizeof(Mpi2RaidVolPage0_t))) {
1565 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1566 ioc->name, __FILE__, __LINE__, __func__);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301567 percent_complete = 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301568 goto out;
1569 }
1570
1571 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301572 if (!(volume_status_flags &
1573 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1574 percent_complete = 0;
1575
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301576 out:
1577 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1578}
1579
1580/**
1581 * _scsih_get_state - get raid volume level
1582 * @dev the device struct object
1583 */
1584static void
1585_scsih_get_state(struct device *dev)
1586{
1587 struct scsi_device *sdev = to_scsi_device(dev);
1588 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1589 static struct _raid_device *raid_device;
1590 unsigned long flags;
1591 Mpi2RaidVolPage0_t vol_pg0;
1592 Mpi2ConfigReply_t mpi_reply;
1593 u32 volstate;
1594 enum raid_state state = RAID_STATE_UNKNOWN;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301595 u16 handle = 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301596
1597 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1598 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1599 sdev->channel);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301600 if (raid_device)
1601 handle = raid_device->handle;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301602 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1603
1604 if (!raid_device)
1605 goto out;
1606
1607 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301608 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301609 sizeof(Mpi2RaidVolPage0_t))) {
1610 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1611 ioc->name, __FILE__, __LINE__, __func__);
1612 goto out;
1613 }
1614
1615 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1616 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1617 state = RAID_STATE_RESYNCING;
1618 goto out;
1619 }
1620
1621 switch (vol_pg0.VolumeState) {
1622 case MPI2_RAID_VOL_STATE_OPTIMAL:
1623 case MPI2_RAID_VOL_STATE_ONLINE:
1624 state = RAID_STATE_ACTIVE;
1625 break;
1626 case MPI2_RAID_VOL_STATE_DEGRADED:
1627 state = RAID_STATE_DEGRADED;
1628 break;
1629 case MPI2_RAID_VOL_STATE_FAILED:
1630 case MPI2_RAID_VOL_STATE_MISSING:
1631 state = RAID_STATE_OFFLINE;
1632 break;
1633 }
1634 out:
1635 raid_set_state(mpt2sas_raid_template, dev, state);
1636}
1637
1638/**
1639 * _scsih_set_level - set raid level
1640 * @sdev: scsi device struct
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301641 * @volume_type: volume type
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301642 */
1643static void
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301644_scsih_set_level(struct scsi_device *sdev, u8 volume_type)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301645{
1646 enum raid_level level = RAID_LEVEL_UNKNOWN;
1647
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301648 switch (volume_type) {
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301649 case MPI2_RAID_VOL_TYPE_RAID0:
1650 level = RAID_LEVEL_0;
1651 break;
1652 case MPI2_RAID_VOL_TYPE_RAID10:
1653 level = RAID_LEVEL_10;
1654 break;
1655 case MPI2_RAID_VOL_TYPE_RAID1E:
1656 level = RAID_LEVEL_1E;
1657 break;
1658 case MPI2_RAID_VOL_TYPE_RAID1:
1659 level = RAID_LEVEL_1;
1660 break;
1661 }
1662
1663 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1664}
1665
1666/**
Eric Moore635374e2009-03-09 01:21:12 -06001667 * _scsih_get_volume_capabilities - volume capabilities
1668 * @ioc: per adapter object
1669 * @sas_device: the raid_device object
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301670 *
1671 * Returns 0 for success, else 1
Eric Moore635374e2009-03-09 01:21:12 -06001672 */
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301673static int
Eric Moore635374e2009-03-09 01:21:12 -06001674_scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1675 struct _raid_device *raid_device)
1676{
1677 Mpi2RaidVolPage0_t *vol_pg0;
1678 Mpi2RaidPhysDiskPage0_t pd_pg0;
1679 Mpi2SasDevicePage0_t sas_device_pg0;
1680 Mpi2ConfigReply_t mpi_reply;
1681 u16 sz;
1682 u8 num_pds;
1683
1684 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1685 &num_pds)) || !num_pds) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301686 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1687 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1688 __func__));
1689 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001690 }
1691
1692 raid_device->num_pds = num_pds;
1693 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1694 sizeof(Mpi2RaidVol0PhysDisk_t));
1695 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1696 if (!vol_pg0) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301697 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1698 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1699 __func__));
1700 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001701 }
1702
1703 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1704 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301705 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1706 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1707 __func__));
Eric Moore635374e2009-03-09 01:21:12 -06001708 kfree(vol_pg0);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301709 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001710 }
1711
1712 raid_device->volume_type = vol_pg0->VolumeType;
1713
1714 /* figure out what the underlying devices are by
1715 * obtaining the device_info bits for the 1st device
1716 */
1717 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1718 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1719 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1720 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1721 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1722 le16_to_cpu(pd_pg0.DevHandle)))) {
1723 raid_device->device_info =
1724 le32_to_cpu(sas_device_pg0.DeviceInfo);
1725 }
1726 }
1727
1728 kfree(vol_pg0);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301729 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06001730}
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301731/**
1732 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1733 * @ioc: per adapter object
1734 */
1735static void
1736_scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1737{
1738 Mpi2RaidVolPage1_t vol_pg1;
1739 Mpi2ConfigReply_t mpi_reply;
1740 struct _raid_device *raid_device;
1741 u16 handle;
1742 u16 ioc_status;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301743 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301744
1745 handle = 0xFFFF;
1746 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1747 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1748 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1749 MPI2_IOCSTATUS_MASK;
1750 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1751 break;
1752 handle = le16_to_cpu(vol_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301753 spin_lock_irqsave(&ioc->raid_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301754 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1755 if (raid_device)
1756 raid_device->direct_io_enabled = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301757 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301758 }
1759 return;
1760}
1761
1762
1763/**
1764 * _scsih_get_num_volumes - Get number of volumes in the ioc
1765 * @ioc: per adapter object
1766 */
1767static u8
1768_scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1769{
1770 Mpi2RaidVolPage1_t vol_pg1;
1771 Mpi2ConfigReply_t mpi_reply;
1772 u16 handle;
1773 u8 vol_cnt = 0;
1774 u16 ioc_status;
1775
1776 handle = 0xFFFF;
1777 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1778 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1779 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1780 MPI2_IOCSTATUS_MASK;
1781 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1782 break;
1783 vol_cnt++;
1784 handle = le16_to_cpu(vol_pg1.DevHandle);
1785 }
1786 return vol_cnt;
1787}
1788
1789
1790/**
1791 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1792 * @ioc: per adapter object
1793 * @raid_device: the raid_device object
1794 */
1795static void
1796_scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1797 struct _raid_device *raid_device)
1798{
1799 Mpi2RaidVolPage0_t *vol_pg0;
1800 Mpi2RaidPhysDiskPage0_t pd_pg0;
1801 Mpi2ConfigReply_t mpi_reply;
1802 u16 sz;
1803 u8 num_pds, count;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301804 unsigned long stripe_sz, block_sz;
1805 u8 stripe_exp, block_exp;
1806 u64 dev_max_lba;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301807
1808 if (!ioc->is_warpdrive)
1809 return;
1810
1811 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1812 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1813 "globally as drives are exposed\n", ioc->name);
1814 return;
1815 }
1816 if (_scsih_get_num_volumes(ioc) > 1) {
1817 _scsih_disable_ddio(ioc);
1818 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1819 "globally as number of drives > 1\n", ioc->name);
1820 return;
1821 }
1822 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1823 &num_pds)) || !num_pds) {
1824 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1825 "Failure in computing number of drives\n", ioc->name);
1826 return;
1827 }
1828
1829 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1830 sizeof(Mpi2RaidVol0PhysDisk_t));
1831 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1832 if (!vol_pg0) {
1833 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1834 "Memory allocation failure for RVPG0\n", ioc->name);
1835 return;
1836 }
1837
1838 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1839 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1840 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1841 "Failure in retrieving RVPG0\n", ioc->name);
1842 kfree(vol_pg0);
1843 return;
1844 }
1845
1846 /*
1847 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1848 * assumed for WARPDRIVE, disable direct I/O
1849 */
1850 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1851 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1852 "for the drive with handle(0x%04x): num_mem=%d, "
1853 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1854 num_pds, MPT_MAX_WARPDRIVE_PDS);
1855 kfree(vol_pg0);
1856 return;
1857 }
1858 for (count = 0; count < num_pds; count++) {
1859 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1860 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1861 vol_pg0->PhysDisk[count].PhysDiskNum) ||
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05301862 le16_to_cpu(pd_pg0.DevHandle) ==
1863 MPT2SAS_INVALID_DEVICE_HANDLE) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301864 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1865 "disabled for the drive with handle(0x%04x) member"
1866 "handle retrieval failed for member number=%d\n",
1867 ioc->name, raid_device->handle,
1868 vol_pg0->PhysDisk[count].PhysDiskNum);
1869 goto out_error;
1870 }
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301871 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1872 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
1873 if (dev_max_lba >> 32) {
1874 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1875 "disabled for the drive with handle(0x%04x) member"
1876 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1877 ioc->name, raid_device->handle,
1878 le16_to_cpu(pd_pg0.DevHandle),
1879 (unsigned long long)dev_max_lba);
1880 goto out_error;
1881 }
1882
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301883 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1884 }
1885
1886 /*
1887 * Assumption for WD: Direct I/O is not supported if the volume is
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301888 * not RAID0
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301889 */
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301890 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301891 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1892 "for the drive with handle(0x%04x): type=%d, "
1893 "s_sz=%uK, blk_size=%u\n", ioc->name,
1894 raid_device->handle, raid_device->volume_type,
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301895 (le32_to_cpu(vol_pg0->StripeSize) *
1896 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301897 le16_to_cpu(vol_pg0->BlockSize));
1898 goto out_error;
1899 }
1900
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301901 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301902 stripe_exp = find_first_bit(&stripe_sz, 32);
1903 if (stripe_exp == 32) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301904 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301905 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301906 ioc->name, raid_device->handle,
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301907 (le32_to_cpu(vol_pg0->StripeSize) *
1908 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301909 goto out_error;
1910 }
1911 raid_device->stripe_exponent = stripe_exp;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301912 block_sz = le16_to_cpu(vol_pg0->BlockSize);
1913 block_exp = find_first_bit(&block_sz, 16);
1914 if (block_exp == 16) {
1915 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1916 "for the drive with handle(0x%04x) invalid block sz %u\n",
1917 ioc->name, raid_device->handle,
1918 le16_to_cpu(vol_pg0->BlockSize));
1919 goto out_error;
1920 }
1921 raid_device->block_exponent = block_exp;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301922 raid_device->direct_io_enabled = 1;
1923
1924 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1925 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1926 /*
1927 * WARPDRIVE: Though the following fields are not used for direct IO,
1928 * stored for future purpose:
1929 */
1930 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1931 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1932 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1933
1934
1935 kfree(vol_pg0);
1936 return;
1937
1938out_error:
1939 raid_device->direct_io_enabled = 0;
1940 for (count = 0; count < num_pds; count++)
1941 raid_device->pd_handle[count] = 0;
1942 kfree(vol_pg0);
1943 return;
1944}
Eric Moore635374e2009-03-09 01:21:12 -06001945
1946/**
Kashyap, Desai84f0b042009-12-16 18:56:28 +05301947 * _scsih_enable_tlr - setting TLR flags
1948 * @ioc: per adapter object
1949 * @sdev: scsi device struct
1950 *
1951 * Enabling Transaction Layer Retries for tape devices when
1952 * vpd page 0x90 is present
1953 *
1954 */
1955static void
1956_scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1957{
1958 /* only for TAPE */
1959 if (sdev->type != TYPE_TAPE)
1960 return;
1961
1962 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1963 return;
1964
1965 sas_enable_tlr(sdev);
1966 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1967 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1968 return;
1969
1970}
1971
1972/**
Eric Moored5d135b2009-05-18 13:02:08 -06001973 * _scsih_slave_configure - device configure routine.
Eric Moore635374e2009-03-09 01:21:12 -06001974 * @sdev: scsi device struct
1975 *
1976 * Returns 0 if ok. Any other return is assumed to be an error and
1977 * the device is ignored.
1978 */
1979static int
Eric Moored5d135b2009-05-18 13:02:08 -06001980_scsih_slave_configure(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001981{
1982 struct Scsi_Host *shost = sdev->host;
1983 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1984 struct MPT2SAS_DEVICE *sas_device_priv_data;
1985 struct MPT2SAS_TARGET *sas_target_priv_data;
1986 struct _sas_device *sas_device;
1987 struct _raid_device *raid_device;
1988 unsigned long flags;
1989 int qdepth;
1990 u8 ssp_target = 0;
1991 char *ds = "";
1992 char *r_level = "";
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301993 u16 handle, volume_handle = 0;
1994 u64 volume_wwid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06001995
1996 qdepth = 1;
1997 sas_device_priv_data = sdev->hostdata;
1998 sas_device_priv_data->configured_lun = 1;
1999 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
2000 sas_target_priv_data = sas_device_priv_data->sas_target;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302001 handle = sas_target_priv_data->handle;
Eric Moore635374e2009-03-09 01:21:12 -06002002
2003 /* raid volume handling */
2004 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2005
2006 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302007 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06002008 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2009 if (!raid_device) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302010 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2011 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2012 __LINE__, __func__));
2013 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002014 }
2015
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302016 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2017 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2018 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2019 __LINE__, __func__));
2020 return 1;
2021 }
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302022 /*
2023 * WARPDRIVE: Initialize the required data for Direct IO
2024 */
2025 _scsih_init_warpdrive_properties(ioc, raid_device);
2026
Eric Moore635374e2009-03-09 01:21:12 -06002027 /* RAID Queue Depth Support
2028 * IS volume = underlying qdepth of drive type, either
2029 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2030 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2031 */
2032 if (raid_device->device_info &
2033 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2034 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2035 ds = "SSP";
2036 } else {
2037 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2038 if (raid_device->device_info &
2039 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2040 ds = "SATA";
2041 else
2042 ds = "STP";
2043 }
2044
2045 switch (raid_device->volume_type) {
2046 case MPI2_RAID_VOL_TYPE_RAID0:
2047 r_level = "RAID0";
2048 break;
2049 case MPI2_RAID_VOL_TYPE_RAID1E:
2050 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
Kashyap, Desaied79f122009-08-20 13:23:49 +05302051 if (ioc->manu_pg10.OEMIdentifier &&
Kashyap, Desaic97951e2011-06-14 10:54:56 +05302052 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
Kashyap, Desaied79f122009-08-20 13:23:49 +05302053 MFG10_GF0_R10_DISPLAY) &&
2054 !(raid_device->num_pds % 2))
2055 r_level = "RAID10";
2056 else
2057 r_level = "RAID1E";
Eric Moore635374e2009-03-09 01:21:12 -06002058 break;
2059 case MPI2_RAID_VOL_TYPE_RAID1:
2060 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2061 r_level = "RAID1";
2062 break;
2063 case MPI2_RAID_VOL_TYPE_RAID10:
2064 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2065 r_level = "RAID10";
2066 break;
2067 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2068 default:
2069 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2070 r_level = "RAIDX";
2071 break;
2072 }
2073
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302074 if (!ioc->hide_ir_msg)
2075 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2076 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2077 r_level, raid_device->handle,
2078 (unsigned long long)raid_device->wwid,
2079 raid_device->num_pds, ds);
Mike Christiee881a172009-10-15 17:46:39 -07002080 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05302081 /* raid transport support */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302082 if (!ioc->is_warpdrive)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302083 _scsih_set_level(sdev, raid_device->volume_type);
Eric Moore635374e2009-03-09 01:21:12 -06002084 return 0;
2085 }
2086
2087 /* non-raid handling */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302088 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2089 if (mpt2sas_config_get_volume_handle(ioc, handle,
2090 &volume_handle)) {
2091 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2092 "failure at %s:%d/%s()!\n", ioc->name,
2093 __FILE__, __LINE__, __func__));
2094 return 1;
2095 }
2096 if (volume_handle && mpt2sas_config_get_volume_wwid(ioc,
2097 volume_handle, &volume_wwid)) {
2098 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2099 "failure at %s:%d/%s()!\n", ioc->name,
2100 __FILE__, __LINE__, __func__));
2101 return 1;
2102 }
2103 }
2104
Eric Moore635374e2009-03-09 01:21:12 -06002105 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2106 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2107 sas_device_priv_data->sas_target->sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302108 if (!sas_device) {
2109 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302110 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302111 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2112 __LINE__, __func__));
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302113 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002114 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302115 sas_device->volume_handle = volume_handle;
2116 sas_device->volume_wwid = volume_wwid;
2117 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2118 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2119 ssp_target = 1;
2120 ds = "SSP";
2121 } else {
2122 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2123 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2124 ds = "STP";
2125 else if (sas_device->device_info &
2126 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2127 ds = "SATA";
2128 }
2129 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2130 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2131 ds, sas_device->handle,
2132 (unsigned long long)sas_device->sas_address,
2133 sas_device->phy,
2134 (unsigned long long)sas_device->device_name);
2135 sdev_printk(KERN_INFO, sdev, "%s: "
2136 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2137 (unsigned long long) sas_device->enclosure_logical_id,
2138 sas_device->slot);
2139
2140 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2141 if (!ssp_target)
2142 _scsih_display_sata_capabilities(ioc, handle, sdev);
2143
Eric Moore635374e2009-03-09 01:21:12 -06002144
Mike Christiee881a172009-10-15 17:46:39 -07002145 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
Eric Moore635374e2009-03-09 01:21:12 -06002146
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302147 if (ssp_target) {
Eric Moore635374e2009-03-09 01:21:12 -06002148 sas_read_port_mode_page(sdev);
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302149 _scsih_enable_tlr(ioc, sdev);
2150 }
Eric Moore635374e2009-03-09 01:21:12 -06002151 return 0;
2152}
2153
2154/**
Eric Moored5d135b2009-05-18 13:02:08 -06002155 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
Eric Moore635374e2009-03-09 01:21:12 -06002156 * @sdev: scsi device struct
2157 * @bdev: pointer to block device context
2158 * @capacity: device size (in 512 byte sectors)
2159 * @params: three element array to place output:
2160 * params[0] number of heads (max 255)
2161 * params[1] number of sectors (max 63)
2162 * params[2] number of cylinders
2163 *
2164 * Return nothing.
2165 */
2166static int
Eric Moored5d135b2009-05-18 13:02:08 -06002167_scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
Eric Moore635374e2009-03-09 01:21:12 -06002168 sector_t capacity, int params[])
2169{
2170 int heads;
2171 int sectors;
2172 sector_t cylinders;
2173 ulong dummy;
2174
2175 heads = 64;
2176 sectors = 32;
2177
2178 dummy = heads * sectors;
2179 cylinders = capacity;
2180 sector_div(cylinders, dummy);
2181
2182 /*
2183 * Handle extended translation size for logical drives
2184 * > 1Gb
2185 */
2186 if ((ulong)capacity >= 0x200000) {
2187 heads = 255;
2188 sectors = 63;
2189 dummy = heads * sectors;
2190 cylinders = capacity;
2191 sector_div(cylinders, dummy);
2192 }
2193
2194 /* return result */
2195 params[0] = heads;
2196 params[1] = sectors;
2197 params[2] = cylinders;
2198
2199 return 0;
2200}
2201
2202/**
2203 * _scsih_response_code - translation of device response code
2204 * @ioc: per adapter object
2205 * @response_code: response code returned by the device
2206 *
2207 * Return nothing.
2208 */
2209static void
2210_scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2211{
2212 char *desc;
2213
2214 switch (response_code) {
2215 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2216 desc = "task management request completed";
2217 break;
2218 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2219 desc = "invalid frame";
2220 break;
2221 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2222 desc = "task management request not supported";
2223 break;
2224 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2225 desc = "task management request failed";
2226 break;
2227 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2228 desc = "task management request succeeded";
2229 break;
2230 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2231 desc = "invalid lun";
2232 break;
2233 case 0xA:
2234 desc = "overlapped tag attempted";
2235 break;
2236 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2237 desc = "task queued, however not sent to target";
2238 break;
2239 default:
2240 desc = "unknown";
2241 break;
2242 }
2243 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2244 ioc->name, response_code, desc);
2245}
2246
2247/**
Eric Moored5d135b2009-05-18 13:02:08 -06002248 * _scsih_tm_done - tm completion routine
Eric Moore635374e2009-03-09 01:21:12 -06002249 * @ioc: per adapter object
2250 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302251 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002252 * @reply: reply message frame(lower 32bit addr)
2253 * Context: none.
2254 *
2255 * The callback handler when using scsih_issue_tm.
2256 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302257 * Return 1 meaning mf should be freed from _base_interrupt
2258 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06002259 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302260static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302261_scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06002262{
2263 MPI2DefaultReply_t *mpi_reply;
2264
2265 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302266 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002267 if (ioc->tm_cmds.smid != smid)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302268 return 1;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05302269 mpt2sas_base_flush_reply_queues(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06002270 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2271 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2272 if (mpi_reply) {
2273 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2274 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2275 }
2276 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2277 complete(&ioc->tm_cmds.done);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302278 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002279}
2280
2281/**
2282 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2283 * @ioc: per adapter object
2284 * @handle: device handle
2285 *
2286 * During taskmangement request, we need to freeze the device queue.
2287 */
2288void
2289mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2290{
2291 struct MPT2SAS_DEVICE *sas_device_priv_data;
2292 struct scsi_device *sdev;
2293 u8 skip = 0;
2294
2295 shost_for_each_device(sdev, ioc->shost) {
2296 if (skip)
2297 continue;
2298 sas_device_priv_data = sdev->hostdata;
2299 if (!sas_device_priv_data)
2300 continue;
2301 if (sas_device_priv_data->sas_target->handle == handle) {
2302 sas_device_priv_data->sas_target->tm_busy = 1;
2303 skip = 1;
2304 ioc->ignore_loginfos = 1;
2305 }
2306 }
2307}
2308
2309/**
2310 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2311 * @ioc: per adapter object
2312 * @handle: device handle
2313 *
2314 * During taskmangement request, we need to freeze the device queue.
2315 */
2316void
2317mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2318{
2319 struct MPT2SAS_DEVICE *sas_device_priv_data;
2320 struct scsi_device *sdev;
2321 u8 skip = 0;
2322
2323 shost_for_each_device(sdev, ioc->shost) {
2324 if (skip)
2325 continue;
2326 sas_device_priv_data = sdev->hostdata;
2327 if (!sas_device_priv_data)
2328 continue;
2329 if (sas_device_priv_data->sas_target->handle == handle) {
2330 sas_device_priv_data->sas_target->tm_busy = 0;
2331 skip = 1;
2332 ioc->ignore_loginfos = 0;
2333 }
2334 }
2335}
2336
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302337
Eric Moore635374e2009-03-09 01:21:12 -06002338/**
2339 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2340 * @ioc: per adapter struct
2341 * @device_handle: device handle
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302342 * @channel: the channel assigned by the OS
2343 * @id: the id assigned by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002344 * @lun: lun number
2345 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2346 * @smid_task: smid assigned to the task
2347 * @timeout: timeout in seconds
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302348 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302349 * Context: user
Eric Moore635374e2009-03-09 01:21:12 -06002350 *
2351 * A generic API for sending task management requests to firmware.
2352 *
Eric Moore635374e2009-03-09 01:21:12 -06002353 * The callback index is set inside `ioc->tm_cb_idx`.
2354 *
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302355 * Return SUCCESS or FAILED.
Eric Moore635374e2009-03-09 01:21:12 -06002356 */
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302357int
2358mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2359 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002360 enum mutex_type m_type)
Eric Moore635374e2009-03-09 01:21:12 -06002361{
2362 Mpi2SCSITaskManagementRequest_t *mpi_request;
2363 Mpi2SCSITaskManagementReply_t *mpi_reply;
2364 u16 smid = 0;
2365 u32 ioc_state;
2366 unsigned long timeleft;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302367 struct scsiio_tracker *scsi_lookup = NULL;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302368 int rc;
Eric Moore635374e2009-03-09 01:21:12 -06002369
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302370 if (m_type == TM_MUTEX_ON)
2371 mutex_lock(&ioc->tm_cmds.mutex);
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302372 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2373 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2374 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302375 rc = FAILED;
2376 goto err_out;
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302377 }
2378
Eric Moore3cb54692010-07-08 14:44:34 -06002379 if (ioc->shost_recovery || ioc->remove_host ||
2380 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06002381 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2382 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302383 rc = FAILED;
2384 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002385 }
Eric Moore635374e2009-03-09 01:21:12 -06002386
2387 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2388 if (ioc_state & MPI2_DOORBELL_USED) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302389 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
Eric Moore635374e2009-03-09 01:21:12 -06002390 "active!\n", ioc->name));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302391 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302392 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302393 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302394 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002395 }
2396
2397 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2398 mpt2sas_base_fault_info(ioc, ioc_state &
2399 MPI2_DOORBELL_DATA_MASK);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302400 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302401 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302402 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302403 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002404 }
2405
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302406 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06002407 if (!smid) {
2408 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2409 ioc->name, __func__);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302410 rc = FAILED;
2411 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002412 }
2413
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302414 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2415 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2416
Eric Moore635374e2009-03-09 01:21:12 -06002417 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302418 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2419 smid_task));
Eric Moore635374e2009-03-09 01:21:12 -06002420 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2421 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2422 ioc->tm_cmds.smid = smid;
2423 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302424 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
Eric Moore635374e2009-03-09 01:21:12 -06002425 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2426 mpi_request->DevHandle = cpu_to_le16(handle);
2427 mpi_request->TaskType = type;
2428 mpi_request->TaskMID = cpu_to_le16(smid_task);
2429 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2430 mpt2sas_scsih_set_tm_flag(ioc, handle);
Kashyap, Desai5b768582009-08-20 13:24:31 +05302431 init_completion(&ioc->tm_cmds.done);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302432 mpt2sas_base_put_smid_hi_priority(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06002433 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
Eric Moore635374e2009-03-09 01:21:12 -06002434 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2435 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2436 ioc->name, __func__);
2437 _debug_dump_mf(mpi_request,
2438 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302439 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302440 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302441 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302442 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302443 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2444 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2445 goto err_out;
2446 }
Eric Moore635374e2009-03-09 01:21:12 -06002447 }
2448
2449 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2450 mpi_reply = ioc->tm_cmds.reply;
2451 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2452 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2453 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2454 le32_to_cpu(mpi_reply->IOCLogInfo),
2455 le32_to_cpu(mpi_reply->TerminationCount)));
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302456 if (ioc->logging_level & MPT_DEBUG_TM) {
Eric Moore635374e2009-03-09 01:21:12 -06002457 _scsih_response_code(ioc, mpi_reply->ResponseCode);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302458 if (mpi_reply->IOCStatus)
2459 _debug_dump_mf(mpi_request,
2460 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2461 }
Eric Moore635374e2009-03-09 01:21:12 -06002462 }
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302463
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302464 switch (type) {
2465 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302466 rc = SUCCESS;
2467 if (scsi_lookup->scmd == NULL)
2468 break;
2469 rc = FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302470 break;
2471
2472 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2473 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2474 rc = FAILED;
2475 else
2476 rc = SUCCESS;
2477 break;
2478
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302479 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302480 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2481 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2482 rc = FAILED;
2483 else
2484 rc = SUCCESS;
2485 break;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302486 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2487 rc = SUCCESS;
2488 break;
2489 default:
2490 rc = FAILED;
2491 break;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302492 }
2493
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302494 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2495 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302496 if (m_type == TM_MUTEX_ON)
2497 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302498
2499 return rc;
2500
2501 err_out:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302502 if (m_type == TM_MUTEX_ON)
2503 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302504 return rc;
Eric Moore635374e2009-03-09 01:21:12 -06002505}
2506
2507/**
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302508 * _scsih_tm_display_info - displays info about the device
2509 * @ioc: per adapter struct
2510 * @scmd: pointer to scsi command object
2511 *
2512 * Called by task management callback handlers.
2513 */
2514static void
2515_scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2516{
2517 struct scsi_target *starget = scmd->device->sdev_target;
2518 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2519 struct _sas_device *sas_device = NULL;
2520 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302521 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302522
2523 if (!priv_target)
2524 return;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302525 if (ioc->hide_ir_msg)
2526 device_str = "WarpDrive";
2527 else
2528 device_str = "volume";
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302529
2530 scsi_print_command(scmd);
2531 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302532 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2533 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2534 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302535 } else {
2536 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2537 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2538 priv_target->sas_address);
2539 if (sas_device) {
2540 if (priv_target->flags &
2541 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2542 starget_printk(KERN_INFO, starget,
2543 "volume handle(0x%04x), "
2544 "volume wwid(0x%016llx)\n",
2545 sas_device->volume_handle,
2546 (unsigned long long)sas_device->volume_wwid);
2547 }
2548 starget_printk(KERN_INFO, starget,
2549 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2550 sas_device->handle,
2551 (unsigned long long)sas_device->sas_address,
2552 sas_device->phy);
2553 starget_printk(KERN_INFO, starget,
2554 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2555 (unsigned long long)sas_device->enclosure_logical_id,
2556 sas_device->slot);
2557 }
2558 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2559 }
2560}
2561
2562/**
Eric Moored5d135b2009-05-18 13:02:08 -06002563 * _scsih_abort - eh threads main abort routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302564 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002565 *
2566 * Returns SUCCESS if command aborted else FAILED
2567 */
2568static int
Eric Moored5d135b2009-05-18 13:02:08 -06002569_scsih_abort(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002570{
2571 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2572 struct MPT2SAS_DEVICE *sas_device_priv_data;
2573 u16 smid;
2574 u16 handle;
2575 int r;
Eric Moore635374e2009-03-09 01:21:12 -06002576
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302577 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2578 "scmd(%p)\n", scmd);
2579 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002580
2581 sas_device_priv_data = scmd->device->hostdata;
2582 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302583 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2584 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002585 scmd->result = DID_NO_CONNECT << 16;
2586 scmd->scsi_done(scmd);
2587 r = SUCCESS;
2588 goto out;
2589 }
2590
2591 /* search for the command */
2592 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2593 if (!smid) {
2594 scmd->result = DID_RESET << 16;
2595 r = SUCCESS;
2596 goto out;
2597 }
2598
2599 /* for hidden raid components and volumes this is not supported */
2600 if (sas_device_priv_data->sas_target->flags &
2601 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2602 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2603 scmd->result = DID_RESET << 16;
2604 r = FAILED;
2605 goto out;
2606 }
2607
Kashyap, Desaifa7f3162009-09-23 17:26:58 +05302608 mpt2sas_halt_firmware(ioc);
2609
Eric Moore635374e2009-03-09 01:21:12 -06002610 handle = sas_device_priv_data->sas_target->handle;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302611 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2612 scmd->device->id, scmd->device->lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002613 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002614
2615 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302616 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2617 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002618 return r;
2619}
2620
Eric Moore635374e2009-03-09 01:21:12 -06002621/**
Eric Moored5d135b2009-05-18 13:02:08 -06002622 * _scsih_dev_reset - eh threads main device reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302623 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002624 *
2625 * Returns SUCCESS if command aborted else FAILED
2626 */
2627static int
Eric Moored5d135b2009-05-18 13:02:08 -06002628_scsih_dev_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002629{
2630 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2631 struct MPT2SAS_DEVICE *sas_device_priv_data;
2632 struct _sas_device *sas_device;
2633 unsigned long flags;
2634 u16 handle;
2635 int r;
2636
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302637 struct scsi_target *starget = scmd->device->sdev_target;
2638
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302639 starget_printk(KERN_INFO, starget, "attempting device reset! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302640 "scmd(%p)\n", scmd);
2641 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002642
2643 sas_device_priv_data = scmd->device->hostdata;
2644 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302645 starget_printk(KERN_INFO, starget, "device been deleted! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302646 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002647 scmd->result = DID_NO_CONNECT << 16;
2648 scmd->scsi_done(scmd);
2649 r = SUCCESS;
2650 goto out;
2651 }
2652
2653 /* for hidden raid components obtain the volume_handle */
2654 handle = 0;
2655 if (sas_device_priv_data->sas_target->flags &
2656 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2657 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2658 sas_device = _scsih_sas_device_find_by_handle(ioc,
2659 sas_device_priv_data->sas_target->handle);
2660 if (sas_device)
2661 handle = sas_device->volume_handle;
2662 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2663 } else
2664 handle = sas_device_priv_data->sas_target->handle;
2665
2666 if (!handle) {
2667 scmd->result = DID_RESET << 16;
2668 r = FAILED;
2669 goto out;
2670 }
2671
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302672 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2673 scmd->device->id, scmd->device->lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002674 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
Eric Moore993e0da2009-05-18 13:00:45 -06002675
2676 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302677 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2678 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002679 return r;
2680}
2681
2682/**
Eric Moored5d135b2009-05-18 13:02:08 -06002683 * _scsih_target_reset - eh threads main target reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302684 * @scmd: pointer to scsi command object
Eric Moore993e0da2009-05-18 13:00:45 -06002685 *
2686 * Returns SUCCESS if command aborted else FAILED
2687 */
2688static int
Eric Moored5d135b2009-05-18 13:02:08 -06002689_scsih_target_reset(struct scsi_cmnd *scmd)
Eric Moore993e0da2009-05-18 13:00:45 -06002690{
2691 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2692 struct MPT2SAS_DEVICE *sas_device_priv_data;
2693 struct _sas_device *sas_device;
2694 unsigned long flags;
2695 u16 handle;
2696 int r;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302697 struct scsi_target *starget = scmd->device->sdev_target;
Eric Moore993e0da2009-05-18 13:00:45 -06002698
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302699 starget_printk(KERN_INFO, starget, "attempting target reset! "
2700 "scmd(%p)\n", scmd);
2701 _scsih_tm_display_info(ioc, scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002702
2703 sas_device_priv_data = scmd->device->hostdata;
2704 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302705 starget_printk(KERN_INFO, starget, "target been deleted! "
2706 "scmd(%p)\n", scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002707 scmd->result = DID_NO_CONNECT << 16;
2708 scmd->scsi_done(scmd);
2709 r = SUCCESS;
2710 goto out;
2711 }
2712
2713 /* for hidden raid components obtain the volume_handle */
2714 handle = 0;
2715 if (sas_device_priv_data->sas_target->flags &
2716 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2717 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2718 sas_device = _scsih_sas_device_find_by_handle(ioc,
2719 sas_device_priv_data->sas_target->handle);
2720 if (sas_device)
2721 handle = sas_device->volume_handle;
2722 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2723 } else
2724 handle = sas_device_priv_data->sas_target->handle;
2725
2726 if (!handle) {
2727 scmd->result = DID_RESET << 16;
2728 r = FAILED;
2729 goto out;
2730 }
2731
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302732 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2733 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002734 30, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002735
2736 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302737 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2738 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002739 return r;
2740}
2741
2742/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302743 * _scsih_host_reset - eh threads main host reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302744 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002745 *
2746 * Returns SUCCESS if command aborted else FAILED
2747 */
2748static int
Eric Moored5d135b2009-05-18 13:02:08 -06002749_scsih_host_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002750{
2751 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2752 int r, retval;
2753
2754 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2755 ioc->name, scmd);
2756 scsi_print_command(scmd);
2757
2758 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2759 FORCE_BIG_HAMMER);
2760 r = (retval < 0) ? FAILED : SUCCESS;
2761 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2762 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2763
2764 return r;
2765}
2766
2767/**
2768 * _scsih_fw_event_add - insert and queue up fw_event
2769 * @ioc: per adapter object
2770 * @fw_event: object describing the event
2771 * Context: This function will acquire ioc->fw_event_lock.
2772 *
2773 * This adds the firmware event object into link list, then queues it up to
2774 * be processed from user context.
2775 *
2776 * Return nothing.
2777 */
2778static void
2779_scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2780{
2781 unsigned long flags;
2782
2783 if (ioc->firmware_event_thread == NULL)
2784 return;
2785
2786 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2787 list_add_tail(&fw_event->list, &ioc->fw_event_list);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302788 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2789 queue_delayed_work(ioc->firmware_event_thread,
2790 &fw_event->delayed_work, 0);
Eric Moore635374e2009-03-09 01:21:12 -06002791 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2792}
2793
2794/**
2795 * _scsih_fw_event_free - delete fw_event
2796 * @ioc: per adapter object
2797 * @fw_event: object describing the event
2798 * Context: This function will acquire ioc->fw_event_lock.
2799 *
2800 * This removes firmware event object from link list, frees associated memory.
2801 *
2802 * Return nothing.
2803 */
2804static void
2805_scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2806 *fw_event)
2807{
2808 unsigned long flags;
2809
2810 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2811 list_del(&fw_event->list);
Eric Moore635374e2009-03-09 01:21:12 -06002812 kfree(fw_event);
2813 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2814}
2815
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302816
Eric Moore635374e2009-03-09 01:21:12 -06002817/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302818 * _scsih_error_recovery_delete_devices - remove devices not responding
Eric Moore635374e2009-03-09 01:21:12 -06002819 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06002820 *
2821 * Return nothing.
2822 */
2823static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302824_scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06002825{
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302826 struct fw_event_work *fw_event;
2827
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302828 if (ioc->is_driver_loading)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302829 return;
Dan Carpenter181a9d72011-11-04 21:25:01 +03002830
2831 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2832 if (!fw_event)
2833 return;
2834
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302835 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2836 fw_event->ioc = ioc;
2837 _scsih_fw_event_add(ioc, fw_event);
2838}
2839
2840/**
2841 * mpt2sas_port_enable_complete - port enable completed (fake event)
2842 * @ioc: per adapter object
2843 *
2844 * Return nothing.
2845 */
2846void
2847mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2848{
2849 struct fw_event_work *fw_event;
2850
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302851 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2852 if (!fw_event)
2853 return;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302854 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302855 fw_event->ioc = ioc;
2856 _scsih_fw_event_add(ioc, fw_event);
2857}
2858
2859/**
2860 * _scsih_fw_event_cleanup_queue - cleanup event queue
2861 * @ioc: per adapter object
2862 *
2863 * Walk the firmware event queue, either killing timers, or waiting
2864 * for outstanding events to complete
2865 *
2866 * Return nothing.
2867 */
2868static void
2869_scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2870{
2871 struct fw_event_work *fw_event, *next;
2872
2873 if (list_empty(&ioc->fw_event_list) ||
2874 !ioc->firmware_event_thread || in_interrupt())
Eric Moore635374e2009-03-09 01:21:12 -06002875 return;
2876
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302877 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05302878 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302879 _scsih_fw_event_free(ioc, fw_event);
2880 continue;
2881 }
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302882 }
Eric Moore635374e2009-03-09 01:21:12 -06002883}
2884
Eric Moore635374e2009-03-09 01:21:12 -06002885/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302886 * _scsih_ublock_io_all_device - unblock every device
2887 * @ioc: per adapter object
2888 *
2889 * change the device state from block to running
2890 */
2891static void
2892_scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2893{
2894 struct MPT2SAS_DEVICE *sas_device_priv_data;
2895 struct scsi_device *sdev;
2896
2897 shost_for_each_device(sdev, ioc->shost) {
2898 sas_device_priv_data = sdev->hostdata;
2899 if (!sas_device_priv_data)
2900 continue;
2901 if (!sas_device_priv_data->block)
2902 continue;
2903 sas_device_priv_data->block = 0;
2904 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2905 "handle(0x%04x)\n",
2906 sas_device_priv_data->sas_target->handle));
Mike Christie5d9fb5c2012-05-17 23:56:57 -05002907 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302908 }
2909}
2910/**
Eric Moore635374e2009-03-09 01:21:12 -06002911 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2912 * @ioc: per adapter object
2913 * @handle: device handle
2914 *
2915 * During device pull we need to appropiately set the sdev state.
2916 */
2917static void
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302918_scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06002919{
2920 struct MPT2SAS_DEVICE *sas_device_priv_data;
2921 struct scsi_device *sdev;
2922
2923 shost_for_each_device(sdev, ioc->shost) {
2924 sas_device_priv_data = sdev->hostdata;
2925 if (!sas_device_priv_data)
2926 continue;
2927 if (!sas_device_priv_data->block)
2928 continue;
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302929 if (sas_device_priv_data->sas_target->sas_address ==
2930 sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06002931 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2932 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302933 "sas address(0x%016llx)\n", ioc->name,
2934 (unsigned long long)sas_address));
Eric Moore635374e2009-03-09 01:21:12 -06002935 sas_device_priv_data->block = 0;
Mike Christie5d9fb5c2012-05-17 23:56:57 -05002936 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
Eric Moore635374e2009-03-09 01:21:12 -06002937 }
2938 }
2939}
2940
2941/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302942 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2943 * @ioc: per adapter object
2944 * @handle: device handle
2945 *
2946 * During device pull we need to appropiately set the sdev state.
2947 */
2948static void
2949_scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2950{
2951 struct MPT2SAS_DEVICE *sas_device_priv_data;
2952 struct scsi_device *sdev;
2953
2954 shost_for_each_device(sdev, ioc->shost) {
2955 sas_device_priv_data = sdev->hostdata;
2956 if (!sas_device_priv_data)
2957 continue;
2958 if (sas_device_priv_data->block)
2959 continue;
2960 sas_device_priv_data->block = 1;
2961 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2962 "handle(0x%04x)\n",
2963 sas_device_priv_data->sas_target->handle));
2964 scsi_internal_device_block(sdev);
2965 }
2966}
2967
2968
2969/**
Eric Moore635374e2009-03-09 01:21:12 -06002970 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2971 * @ioc: per adapter object
2972 * @handle: device handle
2973 *
2974 * During device pull we need to appropiately set the sdev state.
2975 */
2976static void
2977_scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2978{
2979 struct MPT2SAS_DEVICE *sas_device_priv_data;
2980 struct scsi_device *sdev;
2981
2982 shost_for_each_device(sdev, ioc->shost) {
2983 sas_device_priv_data = sdev->hostdata;
2984 if (!sas_device_priv_data)
2985 continue;
2986 if (sas_device_priv_data->block)
2987 continue;
2988 if (sas_device_priv_data->sas_target->handle == handle) {
2989 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2990 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2991 "handle(0x%04x)\n", ioc->name, handle));
2992 sas_device_priv_data->block = 1;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05302993 scsi_internal_device_block(sdev);
Eric Moore635374e2009-03-09 01:21:12 -06002994 }
2995 }
2996}
2997
2998/**
2999 * _scsih_block_io_to_children_attached_to_ex
3000 * @ioc: per adapter object
3001 * @sas_expander: the sas_device object
3002 *
3003 * This routine set sdev state to SDEV_BLOCK for all devices
3004 * attached to this expander. This function called when expander is
3005 * pulled.
3006 */
3007static void
3008_scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
3009 struct _sas_node *sas_expander)
3010{
3011 struct _sas_port *mpt2sas_port;
3012 struct _sas_device *sas_device;
3013 struct _sas_node *expander_sibling;
3014 unsigned long flags;
3015
3016 if (!sas_expander)
3017 return;
3018
3019 list_for_each_entry(mpt2sas_port,
3020 &sas_expander->sas_port_list, port_list) {
3021 if (mpt2sas_port->remote_identify.device_type ==
3022 SAS_END_DEVICE) {
3023 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3024 sas_device =
3025 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3026 mpt2sas_port->remote_identify.sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303027 if (sas_device)
3028 set_bit(sas_device->handle,
3029 ioc->blocking_handles);
Eric Moore635374e2009-03-09 01:21:12 -06003030 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06003031 }
3032 }
3033
3034 list_for_each_entry(mpt2sas_port,
3035 &sas_expander->sas_port_list, port_list) {
3036
3037 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05303038 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06003039 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05303040 SAS_FANOUT_EXPANDER_DEVICE) {
Eric Moore635374e2009-03-09 01:21:12 -06003041 expander_sibling =
3042 mpt2sas_scsih_expander_find_by_sas_address(
3043 ioc, mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06003044 _scsih_block_io_to_children_attached_to_ex(ioc,
3045 expander_sibling);
3046 }
3047 }
3048}
3049
3050/**
3051 * _scsih_block_io_to_children_attached_directly
3052 * @ioc: per adapter object
3053 * @event_data: topology change event data
3054 *
3055 * This routine set sdev state to SDEV_BLOCK for all devices
3056 * direct attached during device pull.
3057 */
3058static void
3059_scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3060 Mpi2EventDataSasTopologyChangeList_t *event_data)
3061{
3062 int i;
3063 u16 handle;
3064 u16 reason_code;
3065 u8 phy_number;
3066
3067 for (i = 0; i < event_data->NumEntries; i++) {
3068 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3069 if (!handle)
3070 continue;
3071 phy_number = event_data->StartPhyNum + i;
3072 reason_code = event_data->PHY[i].PhyStatus &
3073 MPI2_EVENT_SAS_TOPO_RC_MASK;
3074 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3075 _scsih_block_io_device(ioc, handle);
3076 }
3077}
3078
3079/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303080 * _scsih_tm_tr_send - send task management request
3081 * @ioc: per adapter object
3082 * @handle: device handle
3083 * Context: interrupt time.
3084 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003085 * This code is to initiate the device removal handshake protocol
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303086 * with controller firmware. This function will issue target reset
3087 * using high priority request queue. It will send a sas iounit
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003088 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303089 *
3090 * This is designed to send muliple task management request at the same
3091 * time to the fifo. If the fifo is full, we will append the request,
3092 * and process it in a future completion.
3093 */
3094static void
3095_scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3096{
3097 Mpi2SCSITaskManagementRequest_t *mpi_request;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303098 u16 smid;
3099 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303100 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3101 u64 sas_address = 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303102 unsigned long flags;
3103 struct _tr_list *delayed_tr;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303104 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303105
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303106 if (ioc->remove_host) {
3107 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3108 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3109 return;
3110 } else if (ioc->pci_error_recovery) {
3111 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3112 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3113 handle));
3114 return;
3115 }
3116 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3117 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3118 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3119 "operational: handle(0x%04x)\n", __func__, ioc->name,
3120 handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303121 return;
3122 }
3123
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303124 /* if PD, then return */
3125 if (test_bit(handle, ioc->pd_handles))
3126 return;
3127
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303128 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3129 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303130 if (sas_device && sas_device->starget &&
3131 sas_device->starget->hostdata) {
3132 sas_target_priv_data = sas_device->starget->hostdata;
3133 sas_target_priv_data->deleted = 1;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303134 sas_address = sas_device->sas_address;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303135 }
3136 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303137
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303138 if (sas_target_priv_data) {
3139 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3140 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3141 (unsigned long long)sas_address));
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05303142 _scsih_ublock_io_device(ioc, sas_address);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05303143 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303144 }
3145
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303146 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3147 if (!smid) {
3148 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3149 if (!delayed_tr)
3150 return;
3151 INIT_LIST_HEAD(&delayed_tr->list);
3152 delayed_tr->handle = handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303153 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3154 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3155 "DELAYED:tr:handle(0x%04x), (open)\n",
3156 ioc->name, handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303157 return;
3158 }
3159
Kashyap, Desai1278b112010-03-09 17:34:13 +05303160 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3161 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3162 ioc->tm_tr_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303163 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3164 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3165 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3166 mpi_request->DevHandle = cpu_to_le16(handle);
3167 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303168 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3169}
3170
3171
3172
3173/**
3174 * _scsih_sas_control_complete - completion routine
3175 * @ioc: per adapter object
3176 * @smid: system request message index
3177 * @msix_index: MSIX table index supplied by the OS
3178 * @reply: reply message frame(lower 32bit addr)
3179 * Context: interrupt time.
3180 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003181 * This is the sas iounit control completion routine.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303182 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003183 * handshake protocol with controller firmware.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303184 *
3185 * Return 1 meaning mf should be freed from _base_interrupt
3186 * 0 means the mf is freed from this function.
3187 */
3188static u8
3189_scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3190 u8 msix_index, u32 reply)
3191{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303192 Mpi2SasIoUnitControlReply_t *mpi_reply =
3193 mpt2sas_base_get_reply_virt_addr(ioc, reply);
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303194 if (likely(mpi_reply)) {
3195 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3196 "sc_complete:handle(0x%04x), (open) "
3197 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3198 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3199 le16_to_cpu(mpi_reply->IOCStatus),
3200 le32_to_cpu(mpi_reply->IOCLogInfo)));
3201 } else {
3202 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3203 ioc->name, __FILE__, __LINE__, __func__);
3204 }
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303205 return 1;
3206}
3207
3208/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303209 * _scsih_tm_tr_volume_send - send target reset request for volumes
3210 * @ioc: per adapter object
3211 * @handle: device handle
3212 * Context: interrupt time.
3213 *
3214 * This is designed to send muliple task management request at the same
3215 * time to the fifo. If the fifo is full, we will append the request,
3216 * and process it in a future completion.
3217 */
3218static void
3219_scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3220{
3221 Mpi2SCSITaskManagementRequest_t *mpi_request;
3222 u16 smid;
3223 struct _tr_list *delayed_tr;
3224
Eric Moore3cb54692010-07-08 14:44:34 -06003225 if (ioc->shost_recovery || ioc->remove_host ||
3226 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303227 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3228 "progress!\n", __func__, ioc->name));
3229 return;
3230 }
3231
3232 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3233 if (!smid) {
3234 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3235 if (!delayed_tr)
3236 return;
3237 INIT_LIST_HEAD(&delayed_tr->list);
3238 delayed_tr->handle = handle;
3239 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3240 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3241 "DELAYED:tr:handle(0x%04x), (open)\n",
3242 ioc->name, handle));
3243 return;
3244 }
3245
3246 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3247 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3248 ioc->tm_tr_volume_cb_idx));
3249 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3250 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3251 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3252 mpi_request->DevHandle = cpu_to_le16(handle);
3253 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3254 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3255}
3256
3257/**
3258 * _scsih_tm_volume_tr_complete - target reset completion
3259 * @ioc: per adapter object
3260 * @smid: system request message index
3261 * @msix_index: MSIX table index supplied by the OS
3262 * @reply: reply message frame(lower 32bit addr)
3263 * Context: interrupt time.
3264 *
3265 * Return 1 meaning mf should be freed from _base_interrupt
3266 * 0 means the mf is freed from this function.
3267 */
3268static u8
3269_scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3270 u8 msix_index, u32 reply)
3271{
3272 u16 handle;
3273 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3274 Mpi2SCSITaskManagementReply_t *mpi_reply =
3275 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3276
Eric Moore3cb54692010-07-08 14:44:34 -06003277 if (ioc->shost_recovery || ioc->remove_host ||
3278 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303279 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3280 "progress!\n", __func__, ioc->name));
3281 return 1;
3282 }
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303283 if (unlikely(!mpi_reply)) {
3284 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3285 ioc->name, __FILE__, __LINE__, __func__);
3286 return 1;
3287 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303288 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3289 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3290 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3291 dewtprintk(ioc, printk("spurious interrupt: "
3292 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3293 le16_to_cpu(mpi_reply->DevHandle), smid));
3294 return 0;
3295 }
3296
3297 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3298 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3299 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3300 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3301 le32_to_cpu(mpi_reply->IOCLogInfo),
3302 le32_to_cpu(mpi_reply->TerminationCount)));
3303
3304 return _scsih_check_for_pending_tm(ioc, smid);
3305}
3306
3307/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303308 * _scsih_tm_tr_complete -
3309 * @ioc: per adapter object
3310 * @smid: system request message index
3311 * @msix_index: MSIX table index supplied by the OS
3312 * @reply: reply message frame(lower 32bit addr)
3313 * Context: interrupt time.
3314 *
3315 * This is the target reset completion routine.
3316 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003317 * handshake protocol with controller firmware.
3318 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303319 *
3320 * Return 1 meaning mf should be freed from _base_interrupt
3321 * 0 means the mf is freed from this function.
3322 */
3323static u8
3324_scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3325 u32 reply)
3326{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303327 u16 handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303328 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303329 Mpi2SCSITaskManagementReply_t *mpi_reply =
3330 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3331 Mpi2SasIoUnitControlRequest_t *mpi_request;
3332 u16 smid_sas_ctrl;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303333 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303334
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303335 if (ioc->remove_host) {
3336 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3337 "removed\n", __func__, ioc->name));
3338 return 1;
3339 } else if (ioc->pci_error_recovery) {
3340 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3341 "error recovery\n", __func__, ioc->name));
3342 return 1;
3343 }
3344 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3345 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3346 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3347 "operational\n", __func__, ioc->name));
Kashyap, Desai1278b112010-03-09 17:34:13 +05303348 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303349 }
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303350 if (unlikely(!mpi_reply)) {
3351 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3352 ioc->name, __FILE__, __LINE__, __func__);
3353 return 1;
3354 }
Kashyap, Desai1278b112010-03-09 17:34:13 +05303355 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3356 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3357 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3358 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3359 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3360 le16_to_cpu(mpi_reply->DevHandle), smid));
3361 return 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303362 }
3363
Kashyap, Desai1278b112010-03-09 17:34:13 +05303364 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3365 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3366 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3367 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3368 le32_to_cpu(mpi_reply->IOCLogInfo),
3369 le32_to_cpu(mpi_reply->TerminationCount)));
3370
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303371 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3372 if (!smid_sas_ctrl) {
3373 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3374 ioc->name, __func__);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303375 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303376 }
3377
Kashyap, Desai1278b112010-03-09 17:34:13 +05303378 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3379 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3380 ioc->tm_sas_control_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303381 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3382 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3383 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3384 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303385 mpi_request->DevHandle = mpi_request_tm->DevHandle;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303386 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303387
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303388 return _scsih_check_for_pending_tm(ioc, smid);
3389}
3390
3391/**
3392 * _scsih_check_for_pending_tm - check for pending task management
3393 * @ioc: per adapter object
3394 * @smid: system request message index
3395 *
3396 * This will check delayed target reset list, and feed the
3397 * next reqeust.
3398 *
3399 * Return 1 meaning mf should be freed from _base_interrupt
3400 * 0 means the mf is freed from this function.
3401 */
3402static u8
3403_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3404{
3405 struct _tr_list *delayed_tr;
3406
3407 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3408 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3409 struct _tr_list, list);
3410 mpt2sas_base_free_smid(ioc, smid);
3411 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3412 list_del(&delayed_tr->list);
3413 kfree(delayed_tr);
3414 return 0;
3415 }
3416
Kashyap, Desai1278b112010-03-09 17:34:13 +05303417 if (!list_empty(&ioc->delayed_tr_list)) {
3418 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3419 struct _tr_list, list);
3420 mpt2sas_base_free_smid(ioc, smid);
3421 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3422 list_del(&delayed_tr->list);
3423 kfree(delayed_tr);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303424 return 0;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303425 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303426
Kashyap, Desai1278b112010-03-09 17:34:13 +05303427 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303428}
3429
3430/**
Eric Moore635374e2009-03-09 01:21:12 -06003431 * _scsih_check_topo_delete_events - sanity check on topo events
3432 * @ioc: per adapter object
3433 * @event_data: the event data payload
3434 *
3435 * This routine added to better handle cable breaker.
3436 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003437 * This handles the case where driver receives multiple expander
Eric Moore635374e2009-03-09 01:21:12 -06003438 * add and delete events in a single shot. When there is a delete event
3439 * the routine will void any pending add events waiting in the event queue.
3440 *
3441 * Return nothing.
3442 */
3443static void
3444_scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3445 Mpi2EventDataSasTopologyChangeList_t *event_data)
3446{
3447 struct fw_event_work *fw_event;
3448 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3449 u16 expander_handle;
3450 struct _sas_node *sas_expander;
3451 unsigned long flags;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303452 int i, reason_code;
3453 u16 handle;
3454
3455 for (i = 0 ; i < event_data->NumEntries; i++) {
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303456 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3457 if (!handle)
3458 continue;
3459 reason_code = event_data->PHY[i].PhyStatus &
3460 MPI2_EVENT_SAS_TOPO_RC_MASK;
3461 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3462 _scsih_tm_tr_send(ioc, handle);
3463 }
Eric Moore635374e2009-03-09 01:21:12 -06003464
3465 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3466 if (expander_handle < ioc->sas_hba.num_phys) {
3467 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3468 return;
3469 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303470 if (event_data->ExpStatus ==
3471 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3472 /* put expander attached devices into blocking state */
Eric Moore635374e2009-03-09 01:21:12 -06003473 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3474 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3475 expander_handle);
Eric Moore635374e2009-03-09 01:21:12 -06003476 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303477 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3478 do {
3479 handle = find_first_bit(ioc->blocking_handles,
3480 ioc->facts.MaxDevHandle);
3481 if (handle < ioc->facts.MaxDevHandle)
3482 _scsih_block_io_device(ioc, handle);
3483 } while (test_and_clear_bit(handle, ioc->blocking_handles));
Eric Moore635374e2009-03-09 01:21:12 -06003484 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3485 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3486
3487 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3488 return;
3489
3490 /* mark ignore flag for pending events */
3491 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3492 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3493 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3494 fw_event->ignore)
3495 continue;
Joe Lawrence00713ad2014-06-25 17:03:33 -04003496 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3497 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06003498 if (local_event_data->ExpStatus ==
3499 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3500 local_event_data->ExpStatus ==
3501 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3502 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3503 expander_handle) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303504 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06003505 "setting ignoring flag\n", ioc->name));
3506 fw_event->ignore = 1;
3507 }
3508 }
3509 }
3510 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3511}
3512
3513/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303514 * _scsih_set_volume_delete_flag - setting volume delete flag
3515 * @ioc: per adapter object
3516 * @handle: device handle
3517 *
3518 * This
3519 * Return nothing.
3520 */
3521static void
3522_scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3523{
3524 struct _raid_device *raid_device;
3525 struct MPT2SAS_TARGET *sas_target_priv_data;
3526 unsigned long flags;
3527
3528 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3529 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3530 if (raid_device && raid_device->starget &&
3531 raid_device->starget->hostdata) {
3532 sas_target_priv_data =
3533 raid_device->starget->hostdata;
3534 sas_target_priv_data->deleted = 1;
3535 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3536 "setting delete flag: handle(0x%04x), "
3537 "wwid(0x%016llx)\n", ioc->name, handle,
3538 (unsigned long long) raid_device->wwid));
3539 }
3540 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3541}
3542
3543/**
3544 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3545 * @handle: input handle
3546 * @a: handle for volume a
3547 * @b: handle for volume b
3548 *
3549 * IR firmware only supports two raid volumes. The purpose of this
3550 * routine is to set the volume handle in either a or b. When the given
3551 * input handle is non-zero, or when a and b have not been set before.
3552 */
3553static void
3554_scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3555{
3556 if (!handle || handle == *a || handle == *b)
3557 return;
3558 if (!*a)
3559 *a = handle;
3560 else if (!*b)
3561 *b = handle;
3562}
3563
3564/**
3565 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3566 * @ioc: per adapter object
3567 * @event_data: the event data payload
3568 * Context: interrupt time.
3569 *
3570 * This routine will send target reset to volume, followed by target
3571 * resets to the PDs. This is called when a PD has been removed, or
3572 * volume has been deleted or removed. When the target reset is sent
3573 * to volume, the PD target resets need to be queued to start upon
3574 * completion of the volume target reset.
3575 *
3576 * Return nothing.
3577 */
3578static void
3579_scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3580 Mpi2EventDataIrConfigChangeList_t *event_data)
3581{
3582 Mpi2EventIrConfigElement_t *element;
3583 int i;
3584 u16 handle, volume_handle, a, b;
3585 struct _tr_list *delayed_tr;
3586
3587 a = 0;
3588 b = 0;
3589
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303590 if (ioc->is_warpdrive)
3591 return;
3592
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303593 /* Volume Resets for Deleted or Removed */
3594 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3595 for (i = 0; i < event_data->NumElements; i++, element++) {
3596 if (element->ReasonCode ==
3597 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3598 element->ReasonCode ==
3599 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3600 volume_handle = le16_to_cpu(element->VolDevHandle);
3601 _scsih_set_volume_delete_flag(ioc, volume_handle);
3602 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3603 }
3604 }
3605
3606 /* Volume Resets for UNHIDE events */
3607 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3608 for (i = 0; i < event_data->NumElements; i++, element++) {
3609 if (le32_to_cpu(event_data->Flags) &
3610 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3611 continue;
3612 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3613 volume_handle = le16_to_cpu(element->VolDevHandle);
3614 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3615 }
3616 }
3617
3618 if (a)
3619 _scsih_tm_tr_volume_send(ioc, a);
3620 if (b)
3621 _scsih_tm_tr_volume_send(ioc, b);
3622
3623 /* PD target resets */
3624 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3625 for (i = 0; i < event_data->NumElements; i++, element++) {
3626 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3627 continue;
3628 handle = le16_to_cpu(element->PhysDiskDevHandle);
3629 volume_handle = le16_to_cpu(element->VolDevHandle);
3630 clear_bit(handle, ioc->pd_handles);
3631 if (!volume_handle)
3632 _scsih_tm_tr_send(ioc, handle);
3633 else if (volume_handle == a || volume_handle == b) {
3634 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3635 BUG_ON(!delayed_tr);
3636 INIT_LIST_HEAD(&delayed_tr->list);
3637 delayed_tr->handle = handle;
3638 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3639 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3640 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3641 handle));
3642 } else
3643 _scsih_tm_tr_send(ioc, handle);
3644 }
3645}
3646
3647
3648/**
3649 * _scsih_check_volume_delete_events - set delete flag for volumes
3650 * @ioc: per adapter object
3651 * @event_data: the event data payload
3652 * Context: interrupt time.
3653 *
3654 * This will handle the case when the cable connected to entire volume is
3655 * pulled. We will take care of setting the deleted flag so normal IO will
3656 * not be sent.
3657 *
3658 * Return nothing.
3659 */
3660static void
3661_scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3662 Mpi2EventDataIrVolume_t *event_data)
3663{
3664 u32 state;
3665
3666 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3667 return;
3668 state = le32_to_cpu(event_data->NewValue);
3669 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3670 MPI2_RAID_VOL_STATE_FAILED)
3671 _scsih_set_volume_delete_flag(ioc,
3672 le16_to_cpu(event_data->VolDevHandle));
3673}
3674
3675/**
Eric Moore635374e2009-03-09 01:21:12 -06003676 * _scsih_flush_running_cmds - completing outstanding commands.
3677 * @ioc: per adapter object
3678 *
3679 * The flushing out of all pending scmd commands following host reset,
3680 * where all IO is dropped to the floor.
3681 *
3682 * Return nothing.
3683 */
3684static void
3685_scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3686{
3687 struct scsi_cmnd *scmd;
3688 u16 smid;
3689 u16 count = 0;
3690
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303691 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05303692 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003693 if (!scmd)
3694 continue;
3695 count++;
3696 mpt2sas_base_free_smid(ioc, smid);
3697 scsi_dma_unmap(scmd);
Eric Moore3cb54692010-07-08 14:44:34 -06003698 if (ioc->pci_error_recovery)
3699 scmd->result = DID_NO_CONNECT << 16;
3700 else
3701 scmd->result = DID_RESET << 16;
Eric Moore635374e2009-03-09 01:21:12 -06003702 scmd->scsi_done(scmd);
3703 }
3704 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3705 ioc->name, count));
3706}
3707
3708/**
Eric Moore3c621b32009-05-18 12:59:41 -06003709 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3710 * @scmd: pointer to scsi command object
3711 * @mpi_request: pointer to the SCSI_IO reqest message frame
3712 *
3713 * Supporting protection 1 and 3.
3714 *
3715 * Returns nothing
3716 */
3717static void
3718_scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3719{
3720 u16 eedp_flags;
3721 unsigned char prot_op = scsi_get_prot_op(scmd);
3722 unsigned char prot_type = scsi_get_prot_type(scmd);
3723
Eric Moored334aa72010-04-22 10:47:40 -06003724 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
Eric Moore3c621b32009-05-18 12:59:41 -06003725 return;
3726
3727 if (prot_op == SCSI_PROT_READ_STRIP)
3728 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3729 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3730 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3731 else
3732 return;
3733
Eric Moore3c621b32009-05-18 12:59:41 -06003734 switch (prot_type) {
3735 case SCSI_PROT_DIF_TYPE1:
Martin K. Petersen756aca72011-05-18 00:45:22 -04003736 case SCSI_PROT_DIF_TYPE2:
Eric Moore3c621b32009-05-18 12:59:41 -06003737
3738 /*
3739 * enable ref/guard checking
3740 * auto increment ref tag
3741 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303742 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
Eric Moore3c621b32009-05-18 12:59:41 -06003743 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3744 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3745 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3746 cpu_to_be32(scsi_get_lba(scmd));
Eric Moored334aa72010-04-22 10:47:40 -06003747 break;
Eric Moore3c621b32009-05-18 12:59:41 -06003748
Eric Moore3c621b32009-05-18 12:59:41 -06003749 case SCSI_PROT_DIF_TYPE3:
3750
3751 /*
3752 * enable guard checking
3753 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303754 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
Eric Moore3c621b32009-05-18 12:59:41 -06003755 break;
3756 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05303757 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3758 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
Eric Moore3c621b32009-05-18 12:59:41 -06003759}
3760
3761/**
3762 * _scsih_eedp_error_handling - return sense code for EEDP errors
3763 * @scmd: pointer to scsi command object
3764 * @ioc_status: ioc status
3765 *
3766 * Returns nothing
3767 */
3768static void
3769_scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3770{
3771 u8 ascq;
Eric Moore3c621b32009-05-18 12:59:41 -06003772
3773 switch (ioc_status) {
3774 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3775 ascq = 0x01;
3776 break;
3777 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3778 ascq = 0x02;
3779 break;
3780 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3781 ascq = 0x03;
3782 break;
3783 default:
3784 ascq = 0x00;
3785 break;
3786 }
3787
Martin K. Petersen9b5cd132012-08-28 14:29:36 -04003788 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq);
3789 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
Eric Moore3c621b32009-05-18 12:59:41 -06003790 SAM_STAT_CHECK_CONDITION;
3791}
3792
3793/**
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303794 * _scsih_scsi_direct_io_get - returns direct io flag
3795 * @ioc: per adapter object
3796 * @smid: system request message index
3797 *
3798 * Returns the smid stored scmd pointer.
3799 */
3800static inline u8
3801_scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3802{
3803 return ioc->scsi_lookup[smid - 1].direct_io;
3804}
3805
3806/**
3807 * _scsih_scsi_direct_io_set - sets direct io flag
3808 * @ioc: per adapter object
3809 * @smid: system request message index
3810 * @direct_io: Zero or non-zero value to set in the direct_io flag
3811 *
3812 * Returns Nothing.
3813 */
3814static inline void
3815_scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3816{
3817 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3818}
3819
3820
3821/**
3822 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3823 * @ioc: per adapter object
3824 * @scmd: pointer to scsi command object
3825 * @raid_device: pointer to raid device data structure
3826 * @mpi_request: pointer to the SCSI_IO reqest message frame
3827 * @smid: system request message index
3828 *
3829 * Returns nothing
3830 */
3831static void
3832_scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3833 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3834 u16 smid)
3835{
Sreekanth Reddyf78f6942014-09-19 12:17:27 +05303836 sector_t v_lba, p_lba, stripe_off, column, io_size;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303837 u32 stripe_sz, stripe_exp;
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303838 u8 num_pds, cmd = scmd->cmnd[0];
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303839
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303840 if (cmd != READ_10 && cmd != WRITE_10 &&
3841 cmd != READ_16 && cmd != WRITE_16)
3842 return;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303843
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303844 if (cmd == READ_10 || cmd == WRITE_10)
3845 v_lba = get_unaligned_be32(&mpi_request->CDB.CDB32[2]);
3846 else
3847 v_lba = get_unaligned_be64(&mpi_request->CDB.CDB32[2]);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303848
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303849 io_size = scsi_bufflen(scmd) >> raid_device->block_exponent;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303850
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303851 if (v_lba + io_size - 1 > raid_device->max_lba)
3852 return;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303853
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303854 stripe_sz = raid_device->stripe_sz;
3855 stripe_exp = raid_device->stripe_exponent;
3856 stripe_off = v_lba & (stripe_sz - 1);
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303857
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303858 /* Return unless IO falls within a stripe */
3859 if (stripe_off + io_size > stripe_sz)
3860 return;
3861
3862 num_pds = raid_device->num_pds;
3863 p_lba = v_lba >> stripe_exp;
Sreekanth Reddyf78f6942014-09-19 12:17:27 +05303864 column = sector_div(p_lba, num_pds);
3865 p_lba = (p_lba << stripe_exp) + stripe_off;
3866
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303867 mpi_request->DevHandle = cpu_to_le16(raid_device->pd_handle[column]);
3868
3869 if (cmd == READ_10 || cmd == WRITE_10)
3870 put_unaligned_be32(lower_32_bits(p_lba),
3871 &mpi_request->CDB.CDB32[2]);
3872 else
3873 put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]);
3874
3875 _scsih_scsi_direct_io_set(ioc, smid, 1);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303876}
3877
3878/**
Eric Moored5d135b2009-05-18 13:02:08 -06003879 * _scsih_qcmd - main scsi request entry point
Eric Moore635374e2009-03-09 01:21:12 -06003880 * @scmd: pointer to scsi command object
3881 * @done: function pointer to be invoked on completion
3882 *
3883 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3884 *
3885 * Returns 0 on success. If there's a failure, return either:
3886 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3887 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3888 */
3889static int
Matthew Wilcox90f951e2014-03-27 16:40:33 -04003890_scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06003891{
Matthew Wilcox90f951e2014-03-27 16:40:33 -04003892 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Eric Moore635374e2009-03-09 01:21:12 -06003893 struct MPT2SAS_DEVICE *sas_device_priv_data;
3894 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303895 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06003896 Mpi2SCSIIORequest_t *mpi_request;
3897 u32 mpi_control;
3898 u16 smid;
Eric Moore635374e2009-03-09 01:21:12 -06003899
Eric Moore635374e2009-03-09 01:21:12 -06003900 sas_device_priv_data = scmd->device->hostdata;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303901 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Eric Moore635374e2009-03-09 01:21:12 -06003902 scmd->result = DID_NO_CONNECT << 16;
3903 scmd->scsi_done(scmd);
3904 return 0;
3905 }
3906
Kashyap, Desai78215782011-06-14 10:57:08 +05303907 if (ioc->pci_error_recovery || ioc->remove_host) {
Eric Moore3cb54692010-07-08 14:44:34 -06003908 scmd->result = DID_NO_CONNECT << 16;
3909 scmd->scsi_done(scmd);
3910 return 0;
3911 }
3912
Eric Moore635374e2009-03-09 01:21:12 -06003913 sas_target_priv_data = sas_device_priv_data->sas_target;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303914 /* invalid device handle */
3915 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
Eric Moore635374e2009-03-09 01:21:12 -06003916 scmd->result = DID_NO_CONNECT << 16;
3917 scmd->scsi_done(scmd);
3918 return 0;
3919 }
3920
Kashyap, Desai130b9582010-04-08 17:54:32 +05303921 /* host recovery or link resets sent via IOCTLs */
3922 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
Eric Moore635374e2009-03-09 01:21:12 -06003923 return SCSI_MLQUEUE_HOST_BUSY;
Uwe Kleine-König65155b32010-06-11 12:17:01 +02003924 /* device busy with task management */
Kashyap, Desai130b9582010-04-08 17:54:32 +05303925 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3926 return SCSI_MLQUEUE_DEVICE_BUSY;
3927 /* device has been deleted */
3928 else if (sas_target_priv_data->deleted) {
3929 scmd->result = DID_NO_CONNECT << 16;
3930 scmd->scsi_done(scmd);
3931 return 0;
3932 }
Eric Moore635374e2009-03-09 01:21:12 -06003933
3934 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3935 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3936 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3937 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3938 else
3939 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3940
3941 /* set tags */
Christoph Hellwig609aa222014-10-30 11:54:58 +01003942 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3943
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303944 /* Make sure Device is not raid volume.
3945 * We do not expose raid functionality to upper layer for warpdrive.
3946 */
3947 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Eric Moored334aa72010-04-22 10:47:40 -06003948 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
Eric Moore635374e2009-03-09 01:21:12 -06003949 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3950
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303951 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06003952 if (!smid) {
3953 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3954 ioc->name, __func__);
3955 goto out;
3956 }
3957 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3958 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
Eric Moore3c621b32009-05-18 12:59:41 -06003959 _scsih_setup_eedp(scmd, mpi_request);
Eric Moored334aa72010-04-22 10:47:40 -06003960 if (scmd->cmd_len == 32)
3961 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
Eric Moore635374e2009-03-09 01:21:12 -06003962 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3963 if (sas_device_priv_data->sas_target->flags &
3964 MPT_TARGET_FLAGS_RAID_COMPONENT)
3965 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3966 else
Matthew Wilcox90f951e2014-03-27 16:40:33 -04003967 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
Eric Moore635374e2009-03-09 01:21:12 -06003968 mpi_request->DevHandle =
3969 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3970 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3971 mpi_request->Control = cpu_to_le32(mpi_control);
3972 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3973 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3974 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3975 mpi_request->SenseBufferLowAddress =
Kashyap, Desaiec9472c2009-09-23 17:34:13 +05303976 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003977 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3978 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3979 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05303980 mpi_request->VF_ID = 0; /* TODO */
3981 mpi_request->VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06003982 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3983 mpi_request->LUN);
3984 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3985
3986 if (!mpi_request->DataLength) {
3987 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
3988 } else {
3989 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
3990 mpt2sas_base_free_smid(ioc, smid);
3991 goto out;
3992 }
3993 }
3994
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303995 raid_device = sas_target_priv_data->raid_device;
3996 if (raid_device && raid_device->direct_io_enabled)
3997 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
3998 smid);
3999
Kashyap, Desai58287fd2010-03-17 16:27:25 +05304000 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
4001 mpt2sas_base_put_smid_scsi_io(ioc, smid,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304002 le16_to_cpu(mpi_request->DevHandle));
Kashyap, Desai58287fd2010-03-17 16:27:25 +05304003 else
4004 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004005 return 0;
4006
4007 out:
4008 return SCSI_MLQUEUE_HOST_BUSY;
4009}
4010
4011/**
4012 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4013 * @sense_buffer: sense data returned by target
4014 * @data: normalized skey/asc/ascq
4015 *
4016 * Return nothing.
4017 */
4018static void
4019_scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4020{
4021 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4022 /* descriptor format */
4023 data->skey = sense_buffer[1] & 0x0F;
4024 data->asc = sense_buffer[2];
4025 data->ascq = sense_buffer[3];
4026 } else {
4027 /* fixed format */
4028 data->skey = sense_buffer[2] & 0x0F;
4029 data->asc = sense_buffer[12];
4030 data->ascq = sense_buffer[13];
4031 }
4032}
4033
4034#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4035/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004036 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
Eric Moore635374e2009-03-09 01:21:12 -06004037 * @ioc: per adapter object
4038 * @scmd: pointer to scsi command object
4039 * @mpi_reply: reply mf payload returned from firmware
4040 *
4041 * scsi_status - SCSI Status code returned from target device
4042 * scsi_state - state info associated with SCSI_IO determined by ioc
4043 * ioc_status - ioc supplied status info
4044 *
4045 * Return nothing.
4046 */
4047static void
4048_scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4049 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4050{
4051 u32 response_info;
4052 u8 *response_bytes;
4053 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4054 MPI2_IOCSTATUS_MASK;
4055 u8 scsi_state = mpi_reply->SCSIState;
4056 u8 scsi_status = mpi_reply->SCSIStatus;
4057 char *desc_ioc_state = NULL;
4058 char *desc_scsi_status = NULL;
4059 char *desc_scsi_state = ioc->tmp_string;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304060 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304061 struct _sas_device *sas_device = NULL;
4062 unsigned long flags;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304063 struct scsi_target *starget = scmd->device->sdev_target;
4064 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304065 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304066
4067 if (!priv_target)
4068 return;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304069
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304070 if (ioc->hide_ir_msg)
4071 device_str = "WarpDrive";
4072 else
4073 device_str = "volume";
4074
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304075 if (log_info == 0x31170000)
4076 return;
Eric Moore635374e2009-03-09 01:21:12 -06004077
4078 switch (ioc_status) {
4079 case MPI2_IOCSTATUS_SUCCESS:
4080 desc_ioc_state = "success";
4081 break;
4082 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4083 desc_ioc_state = "invalid function";
4084 break;
4085 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4086 desc_ioc_state = "scsi recovered error";
4087 break;
4088 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4089 desc_ioc_state = "scsi invalid dev handle";
4090 break;
4091 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4092 desc_ioc_state = "scsi device not there";
4093 break;
4094 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4095 desc_ioc_state = "scsi data overrun";
4096 break;
4097 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4098 desc_ioc_state = "scsi data underrun";
4099 break;
4100 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4101 desc_ioc_state = "scsi io data error";
4102 break;
4103 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4104 desc_ioc_state = "scsi protocol error";
4105 break;
4106 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4107 desc_ioc_state = "scsi task terminated";
4108 break;
4109 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4110 desc_ioc_state = "scsi residual mismatch";
4111 break;
4112 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4113 desc_ioc_state = "scsi task mgmt failed";
4114 break;
4115 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4116 desc_ioc_state = "scsi ioc terminated";
4117 break;
4118 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4119 desc_ioc_state = "scsi ext terminated";
4120 break;
Eric Moore3c621b32009-05-18 12:59:41 -06004121 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4122 desc_ioc_state = "eedp guard error";
4123 break;
4124 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4125 desc_ioc_state = "eedp ref tag error";
4126 break;
4127 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4128 desc_ioc_state = "eedp app tag error";
4129 break;
Eric Moore635374e2009-03-09 01:21:12 -06004130 default:
4131 desc_ioc_state = "unknown";
4132 break;
4133 }
4134
4135 switch (scsi_status) {
4136 case MPI2_SCSI_STATUS_GOOD:
4137 desc_scsi_status = "good";
4138 break;
4139 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4140 desc_scsi_status = "check condition";
4141 break;
4142 case MPI2_SCSI_STATUS_CONDITION_MET:
4143 desc_scsi_status = "condition met";
4144 break;
4145 case MPI2_SCSI_STATUS_BUSY:
4146 desc_scsi_status = "busy";
4147 break;
4148 case MPI2_SCSI_STATUS_INTERMEDIATE:
4149 desc_scsi_status = "intermediate";
4150 break;
4151 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4152 desc_scsi_status = "intermediate condmet";
4153 break;
4154 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4155 desc_scsi_status = "reservation conflict";
4156 break;
4157 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4158 desc_scsi_status = "command terminated";
4159 break;
4160 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4161 desc_scsi_status = "task set full";
4162 break;
4163 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4164 desc_scsi_status = "aca active";
4165 break;
4166 case MPI2_SCSI_STATUS_TASK_ABORTED:
4167 desc_scsi_status = "task aborted";
4168 break;
4169 default:
4170 desc_scsi_status = "unknown";
4171 break;
4172 }
4173
4174 desc_scsi_state[0] = '\0';
4175 if (!scsi_state)
4176 desc_scsi_state = " ";
4177 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4178 strcat(desc_scsi_state, "response info ");
4179 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4180 strcat(desc_scsi_state, "state terminated ");
4181 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4182 strcat(desc_scsi_state, "no status ");
4183 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4184 strcat(desc_scsi_state, "autosense failed ");
4185 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4186 strcat(desc_scsi_state, "autosense valid ");
4187
4188 scsi_print_command(scmd);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304189
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304190 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304191 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4192 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304193 } else {
4194 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4195 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4196 priv_target->sas_address);
4197 if (sas_device) {
4198 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4199 "phy(%d)\n", ioc->name, sas_device->sas_address,
4200 sas_device->phy);
4201 printk(MPT2SAS_WARN_FMT
4202 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4203 ioc->name, sas_device->enclosure_logical_id,
4204 sas_device->slot);
4205 }
4206 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304207 }
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304208
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304209 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4210 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4211 desc_ioc_state, ioc_status, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004212 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4213 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4214 scsi_get_resid(scmd));
4215 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4216 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4217 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4218 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4219 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4220 scsi_status, desc_scsi_state, scsi_state);
4221
4222 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4223 struct sense_info data;
4224 _scsih_normalize_sense(scmd->sense_buffer, &data);
4225 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
Kashyap, Desaie94f6742010-03-17 16:24:52 +05304226 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4227 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
Eric Moore635374e2009-03-09 01:21:12 -06004228 }
4229
4230 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4231 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4232 response_bytes = (u8 *)&response_info;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304233 _scsih_response_code(ioc, response_bytes[0]);
Eric Moore635374e2009-03-09 01:21:12 -06004234 }
4235}
4236#endif
4237
4238/**
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304239 * _scsih_turn_on_pfa_led - illuminate PFA LED
Eric Moore635374e2009-03-09 01:21:12 -06004240 * @ioc: per adapter object
4241 * @handle: device handle
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304242 * Context: process
4243 *
4244 * Return nothing.
4245 */
4246static void
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304247_scsih_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304248{
4249 Mpi2SepReply_t mpi_reply;
4250 Mpi2SepRequest_t mpi_request;
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304251 struct _sas_device *sas_device;
4252
4253 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4254 if (!sas_device)
4255 return;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304256
4257 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4258 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4259 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4260 mpi_request.SlotStatus =
4261 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4262 mpi_request.DevHandle = cpu_to_le16(handle);
4263 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4264 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4265 &mpi_request)) != 0) {
4266 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4267 __FILE__, __LINE__, __func__);
4268 return;
4269 }
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304270 sas_device->pfa_led_on = 1;
4271
4272
4273 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4274 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
4275 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4276 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4277 le32_to_cpu(mpi_reply.IOCLogInfo)));
4278 return;
4279 }
4280}
4281
4282/**
4283 * _scsih_turn_off_pfa_led - turn off PFA LED
4284 * @ioc: per adapter object
4285 * @sas_device: sas device whose PFA LED has to turned off
4286 * Context: process
4287 *
4288 * Return nothing.
4289 */
4290static void
4291_scsih_turn_off_pfa_led(struct MPT2SAS_ADAPTER *ioc,
4292 struct _sas_device *sas_device)
4293{
4294 Mpi2SepReply_t mpi_reply;
4295 Mpi2SepRequest_t mpi_request;
4296
4297 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4298 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4299 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4300 mpi_request.SlotStatus = 0;
4301 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4302 mpi_request.DevHandle = 0;
4303 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4304 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4305 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4306 &mpi_request)) != 0) {
4307 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4308 __FILE__, __LINE__, __func__);
4309 return;
4310 }
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304311
4312 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4313 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4314 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4315 le16_to_cpu(mpi_reply.IOCStatus),
4316 le32_to_cpu(mpi_reply.IOCLogInfo)));
4317 return;
4318 }
4319}
4320
4321/**
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304322 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304323 * @ioc: per adapter object
4324 * @handle: device handle
4325 * Context: interrupt.
4326 *
4327 * Return nothing.
4328 */
4329static void
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304330_scsih_send_event_to_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304331{
4332 struct fw_event_work *fw_event;
4333
4334 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4335 if (!fw_event)
4336 return;
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304337 fw_event->event = MPT2SAS_TURN_ON_PFA_LED;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304338 fw_event->device_handle = handle;
4339 fw_event->ioc = ioc;
4340 _scsih_fw_event_add(ioc, fw_event);
4341}
4342
4343/**
4344 * _scsih_smart_predicted_fault - process smart errors
4345 * @ioc: per adapter object
4346 * @handle: device handle
4347 * Context: interrupt.
Eric Moore635374e2009-03-09 01:21:12 -06004348 *
4349 * Return nothing.
4350 */
4351static void
4352_scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4353{
Eric Moore635374e2009-03-09 01:21:12 -06004354 struct scsi_target *starget;
4355 struct MPT2SAS_TARGET *sas_target_priv_data;
4356 Mpi2EventNotificationReply_t *event_reply;
4357 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4358 struct _sas_device *sas_device;
4359 ssize_t sz;
4360 unsigned long flags;
4361
4362 /* only handle non-raid devices */
4363 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4364 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4365 if (!sas_device) {
4366 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4367 return;
4368 }
4369 starget = sas_device->starget;
4370 sas_target_priv_data = starget->hostdata;
4371
4372 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4373 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4374 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4375 return;
4376 }
4377 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4378 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4379
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304380 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304381 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06004382
4383 /* insert into event log */
4384 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4385 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
Anton Blanchardf6a290b42011-11-07 22:05:21 +11004386 event_reply = kzalloc(sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06004387 if (!event_reply) {
4388 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4389 ioc->name, __FILE__, __LINE__, __func__);
4390 return;
4391 }
4392
4393 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4394 event_reply->Event =
4395 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4396 event_reply->MsgLength = sz/4;
4397 event_reply->EventDataLength =
4398 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4399 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4400 event_reply->EventData;
4401 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4402 event_data->ASC = 0x5D;
4403 event_data->DevHandle = cpu_to_le16(handle);
4404 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4405 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4406 kfree(event_reply);
4407}
4408
4409/**
Eric Moored5d135b2009-05-18 13:02:08 -06004410 * _scsih_io_done - scsi request callback
Eric Moore635374e2009-03-09 01:21:12 -06004411 * @ioc: per adapter object
4412 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304413 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06004414 * @reply: reply message frame(lower 32bit addr)
4415 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304416 * Callback handler when using _scsih_qcmd.
Eric Moore635374e2009-03-09 01:21:12 -06004417 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304418 * Return 1 meaning mf should be freed from _base_interrupt
4419 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06004420 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304421static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304422_scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06004423{
4424 Mpi2SCSIIORequest_t *mpi_request;
4425 Mpi2SCSIIOReply_t *mpi_reply;
4426 struct scsi_cmnd *scmd;
4427 u16 ioc_status;
4428 u32 xfer_cnt;
4429 u8 scsi_state;
4430 u8 scsi_status;
4431 u32 log_info;
4432 struct MPT2SAS_DEVICE *sas_device_priv_data;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304433 u32 response_code = 0;
Kashyap, Desai82a45252011-07-05 12:40:23 +05304434 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06004435
4436 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05304437 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004438 if (scmd == NULL)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304439 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004440
4441 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4442
4443 if (mpi_reply == NULL) {
4444 scmd->result = DID_OK << 16;
4445 goto out;
4446 }
4447
4448 sas_device_priv_data = scmd->device->hostdata;
4449 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4450 sas_device_priv_data->sas_target->deleted) {
4451 scmd->result = DID_NO_CONNECT << 16;
4452 goto out;
4453 }
nagalakshmi.nandigama@lsi.com4da7af92011-12-01 07:53:02 +05304454 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304455 /*
4456 * WARPDRIVE: If direct_io is set then it is directIO,
4457 * the failed direct I/O should be redirected to volume
4458 */
nagalakshmi.nandigama@lsi.com4da7af92011-12-01 07:53:02 +05304459 if (_scsih_scsi_direct_io_get(ioc, smid) &&
4460 ((ioc_status & MPI2_IOCSTATUS_MASK)
4461 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
Kashyap, Desai82a45252011-07-05 12:40:23 +05304462 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4463 ioc->scsi_lookup[smid - 1].scmd = scmd;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304464 _scsih_scsi_direct_io_set(ioc, smid, 0);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05304465 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304466 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4467 mpi_request->DevHandle =
4468 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4469 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4470 sas_device_priv_data->sas_target->handle);
4471 return 0;
4472 }
4473
Eric Moore635374e2009-03-09 01:21:12 -06004474
4475 /* turning off TLR */
Kashyap, Desai9982f592009-09-23 17:23:07 +05304476 scsi_state = mpi_reply->SCSIState;
4477 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4478 response_code =
4479 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
Eric Moore635374e2009-03-09 01:21:12 -06004480 if (!sas_device_priv_data->tlr_snoop_check) {
4481 sas_device_priv_data->tlr_snoop_check++;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304482 /* Make sure Device is not raid volume.
4483 * We do not expose raid functionality to upper layer for warpdrive.
4484 */
4485 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Kashyap, Desai3ed21522010-02-17 16:08:36 +05304486 sas_is_tlr_enabled(scmd->device) &&
Kashyap, Desai84f0b042009-12-16 18:56:28 +05304487 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4488 sas_disable_tlr(scmd->device);
4489 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4490 }
Eric Moore635374e2009-03-09 01:21:12 -06004491 }
4492
4493 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4494 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
Eric Moore635374e2009-03-09 01:21:12 -06004495 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4496 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4497 else
4498 log_info = 0;
4499 ioc_status &= MPI2_IOCSTATUS_MASK;
Eric Moore635374e2009-03-09 01:21:12 -06004500 scsi_status = mpi_reply->SCSIStatus;
4501
4502 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4503 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4504 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4505 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4506 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4507 }
4508
4509 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4510 struct sense_info data;
4511 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4512 smid);
Eric Moore0d04df92009-04-21 15:38:43 -06004513 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
Eric Moore635374e2009-03-09 01:21:12 -06004514 le32_to_cpu(mpi_reply->SenseCount));
Eric Moore0d04df92009-04-21 15:38:43 -06004515 memcpy(scmd->sense_buffer, sense_data, sz);
Eric Moore635374e2009-03-09 01:21:12 -06004516 _scsih_normalize_sense(scmd->sense_buffer, &data);
4517 /* failure prediction threshold exceeded */
4518 if (data.asc == 0x5D)
4519 _scsih_smart_predicted_fault(ioc,
4520 le16_to_cpu(mpi_reply->DevHandle));
4521 }
4522
4523 switch (ioc_status) {
4524 case MPI2_IOCSTATUS_BUSY:
4525 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4526 scmd->result = SAM_STAT_BUSY;
4527 break;
4528
4529 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4530 scmd->result = DID_NO_CONNECT << 16;
4531 break;
4532
4533 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4534 if (sas_device_priv_data->block) {
Kashyap, Desaie4e7c7e2009-09-23 17:33:14 +05304535 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4536 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06004537 }
nagalakshmi.nandigama@lsi.com3ade1ca2011-12-01 07:42:40 +05304538 scmd->result = DID_SOFT_ERROR << 16;
4539 break;
Eric Moore635374e2009-03-09 01:21:12 -06004540 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4541 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4542 scmd->result = DID_RESET << 16;
4543 break;
4544
4545 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4546 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4547 scmd->result = DID_SOFT_ERROR << 16;
4548 else
4549 scmd->result = (DID_OK << 16) | scsi_status;
4550 break;
4551
4552 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4553 scmd->result = (DID_OK << 16) | scsi_status;
4554
4555 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4556 break;
4557
4558 if (xfer_cnt < scmd->underflow) {
4559 if (scsi_status == SAM_STAT_BUSY)
4560 scmd->result = SAM_STAT_BUSY;
4561 else
4562 scmd->result = DID_SOFT_ERROR << 16;
4563 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4564 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4565 scmd->result = DID_SOFT_ERROR << 16;
4566 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4567 scmd->result = DID_RESET << 16;
4568 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4569 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4570 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4571 scmd->result = (DRIVER_SENSE << 24) |
4572 SAM_STAT_CHECK_CONDITION;
4573 scmd->sense_buffer[0] = 0x70;
4574 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4575 scmd->sense_buffer[12] = 0x20;
4576 scmd->sense_buffer[13] = 0;
4577 }
4578 break;
4579
4580 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4581 scsi_set_resid(scmd, 0);
4582 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4583 case MPI2_IOCSTATUS_SUCCESS:
4584 scmd->result = (DID_OK << 16) | scsi_status;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304585 if (response_code ==
4586 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4587 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4588 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
Eric Moore635374e2009-03-09 01:21:12 -06004589 scmd->result = DID_SOFT_ERROR << 16;
4590 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4591 scmd->result = DID_RESET << 16;
4592 break;
4593
Eric Moore3c621b32009-05-18 12:59:41 -06004594 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4595 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4596 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4597 _scsih_eedp_error_handling(scmd, ioc_status);
4598 break;
Eric Moore635374e2009-03-09 01:21:12 -06004599 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4600 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4601 case MPI2_IOCSTATUS_INVALID_SGL:
4602 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4603 case MPI2_IOCSTATUS_INVALID_FIELD:
4604 case MPI2_IOCSTATUS_INVALID_STATE:
4605 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4606 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4607 default:
4608 scmd->result = DID_SOFT_ERROR << 16;
4609 break;
4610
4611 }
4612
4613#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4614 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4615 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4616#endif
4617
4618 out:
4619 scsi_dma_unmap(scmd);
4620 scmd->scsi_done(scmd);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304621 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004622}
4623
4624/**
Eric Moore635374e2009-03-09 01:21:12 -06004625 * _scsih_sas_host_refresh - refreshing sas host object contents
4626 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06004627 * Context: user
4628 *
4629 * During port enable, fw will send topology events for every device. Its
4630 * possible that the handles may change from the previous setting, so this
4631 * code keeping handles updating if changed.
4632 *
4633 * Return nothing.
4634 */
4635static void
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304636_scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06004637{
4638 u16 sz;
4639 u16 ioc_status;
4640 int i;
4641 Mpi2ConfigReply_t mpi_reply;
4642 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304643 u16 attached_handle;
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304644 u8 link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06004645
4646 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4647 "updating handles for sas_host(0x%016llx)\n",
4648 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4649
4650 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4651 * sizeof(Mpi2SasIOUnit0PhyData_t));
4652 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4653 if (!sas_iounit_pg0) {
4654 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4655 ioc->name, __FILE__, __LINE__, __func__);
4656 return;
4657 }
Eric Moore635374e2009-03-09 01:21:12 -06004658
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304659 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4660 sas_iounit_pg0, sz)) != 0)
4661 goto out;
4662 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4663 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4664 goto out;
4665 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304666 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304667 if (i == 0)
4668 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4669 PhyData[0].ControllerDevHandle);
4670 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4671 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4672 AttachedDevHandle);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304673 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4674 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304675 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304676 attached_handle, i, link_rate);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304677 }
Eric Moore635374e2009-03-09 01:21:12 -06004678 out:
4679 kfree(sas_iounit_pg0);
4680}
4681
4682/**
4683 * _scsih_sas_host_add - create sas host object
4684 * @ioc: per adapter object
4685 *
4686 * Creating host side data object, stored in ioc->sas_hba
4687 *
4688 * Return nothing.
4689 */
4690static void
4691_scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4692{
4693 int i;
4694 Mpi2ConfigReply_t mpi_reply;
4695 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4696 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4697 Mpi2SasPhyPage0_t phy_pg0;
4698 Mpi2SasDevicePage0_t sas_device_pg0;
4699 Mpi2SasEnclosurePage0_t enclosure_pg0;
4700 u16 ioc_status;
4701 u16 sz;
4702 u16 device_missing_delay;
4703
4704 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4705 if (!ioc->sas_hba.num_phys) {
4706 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4707 ioc->name, __FILE__, __LINE__, __func__);
4708 return;
4709 }
4710
4711 /* sas_iounit page 0 */
4712 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4713 sizeof(Mpi2SasIOUnit0PhyData_t));
4714 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4715 if (!sas_iounit_pg0) {
4716 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4717 ioc->name, __FILE__, __LINE__, __func__);
4718 return;
4719 }
4720 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4721 sas_iounit_pg0, sz))) {
4722 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4723 ioc->name, __FILE__, __LINE__, __func__);
4724 goto out;
4725 }
4726 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4727 MPI2_IOCSTATUS_MASK;
4728 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4729 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4730 ioc->name, __FILE__, __LINE__, __func__);
4731 goto out;
4732 }
4733
4734 /* sas_iounit page 1 */
4735 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4736 sizeof(Mpi2SasIOUnit1PhyData_t));
4737 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4738 if (!sas_iounit_pg1) {
4739 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4740 ioc->name, __FILE__, __LINE__, __func__);
4741 goto out;
4742 }
4743 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4744 sas_iounit_pg1, sz))) {
4745 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4746 ioc->name, __FILE__, __LINE__, __func__);
4747 goto out;
4748 }
4749 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4750 MPI2_IOCSTATUS_MASK;
4751 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4752 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4753 ioc->name, __FILE__, __LINE__, __func__);
4754 goto out;
4755 }
4756
4757 ioc->io_missing_delay =
4758 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4759 device_missing_delay =
4760 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4761 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4762 ioc->device_missing_delay = (device_missing_delay &
4763 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4764 else
4765 ioc->device_missing_delay = device_missing_delay &
4766 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4767
4768 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4769 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4770 sizeof(struct _sas_phy), GFP_KERNEL);
4771 if (!ioc->sas_hba.phy) {
4772 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4773 ioc->name, __FILE__, __LINE__, __func__);
4774 goto out;
4775 }
4776 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4777 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4778 i))) {
4779 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4780 ioc->name, __FILE__, __LINE__, __func__);
4781 goto out;
4782 }
4783 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4784 MPI2_IOCSTATUS_MASK;
4785 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4786 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4787 ioc->name, __FILE__, __LINE__, __func__);
4788 goto out;
4789 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304790
4791 if (i == 0)
4792 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4793 PhyData[0].ControllerDevHandle);
4794 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
Eric Moore635374e2009-03-09 01:21:12 -06004795 ioc->sas_hba.phy[i].phy_id = i;
4796 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4797 phy_pg0, ioc->sas_hba.parent_dev);
4798 }
4799 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304800 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06004801 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4802 ioc->name, __FILE__, __LINE__, __func__);
4803 goto out;
4804 }
Eric Moore635374e2009-03-09 01:21:12 -06004805 ioc->sas_hba.enclosure_handle =
4806 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4807 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4808 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4809 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4810 (unsigned long long) ioc->sas_hba.sas_address,
4811 ioc->sas_hba.num_phys) ;
4812
4813 if (ioc->sas_hba.enclosure_handle) {
4814 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4815 &enclosure_pg0,
4816 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4817 ioc->sas_hba.enclosure_handle))) {
4818 ioc->sas_hba.enclosure_logical_id =
4819 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4820 }
4821 }
4822
4823 out:
4824 kfree(sas_iounit_pg1);
4825 kfree(sas_iounit_pg0);
4826}
4827
4828/**
4829 * _scsih_expander_add - creating expander object
4830 * @ioc: per adapter object
4831 * @handle: expander handle
4832 *
4833 * Creating expander object, stored in ioc->sas_expander_list.
4834 *
4835 * Return 0 for success, else error.
4836 */
4837static int
4838_scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4839{
4840 struct _sas_node *sas_expander;
4841 Mpi2ConfigReply_t mpi_reply;
4842 Mpi2ExpanderPage0_t expander_pg0;
4843 Mpi2ExpanderPage1_t expander_pg1;
4844 Mpi2SasEnclosurePage0_t enclosure_pg0;
4845 u32 ioc_status;
4846 u16 parent_handle;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05304847 u64 sas_address, sas_address_parent = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004848 int i;
4849 unsigned long flags;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304850 struct _sas_port *mpt2sas_port = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06004851 int rc = 0;
4852
4853 if (!handle)
4854 return -1;
4855
Eric Moore3cb54692010-07-08 14:44:34 -06004856 if (ioc->shost_recovery || ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05304857 return -1;
4858
Eric Moore635374e2009-03-09 01:21:12 -06004859 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4860 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4861 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4862 ioc->name, __FILE__, __LINE__, __func__);
4863 return -1;
4864 }
4865
4866 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4867 MPI2_IOCSTATUS_MASK;
4868 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4869 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4870 ioc->name, __FILE__, __LINE__, __func__);
4871 return -1;
4872 }
4873
4874 /* handle out of order topology events */
4875 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304876 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4877 != 0) {
4878 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4879 ioc->name, __FILE__, __LINE__, __func__);
4880 return -1;
4881 }
4882 if (sas_address_parent != ioc->sas_hba.sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06004883 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304884 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4885 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004886 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4887 if (!sas_expander) {
4888 rc = _scsih_expander_add(ioc, parent_handle);
4889 if (rc != 0)
4890 return rc;
4891 }
4892 }
4893
Eric Moore635374e2009-03-09 01:21:12 -06004894 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304895 sas_address = le64_to_cpu(expander_pg0.SASAddress);
Eric Moore635374e2009-03-09 01:21:12 -06004896 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4897 sas_address);
4898 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4899
4900 if (sas_expander)
4901 return 0;
4902
4903 sas_expander = kzalloc(sizeof(struct _sas_node),
4904 GFP_KERNEL);
4905 if (!sas_expander) {
4906 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4907 ioc->name, __FILE__, __LINE__, __func__);
4908 return -1;
4909 }
4910
4911 sas_expander->handle = handle;
4912 sas_expander->num_phys = expander_pg0.NumPhys;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304913 sas_expander->sas_address_parent = sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06004914 sas_expander->sas_address = sas_address;
4915
4916 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4917 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304918 handle, parent_handle, (unsigned long long)
Eric Moore635374e2009-03-09 01:21:12 -06004919 sas_expander->sas_address, sas_expander->num_phys);
4920
4921 if (!sas_expander->num_phys)
4922 goto out_fail;
4923 sas_expander->phy = kcalloc(sas_expander->num_phys,
4924 sizeof(struct _sas_phy), GFP_KERNEL);
4925 if (!sas_expander->phy) {
4926 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4927 ioc->name, __FILE__, __LINE__, __func__);
4928 rc = -1;
4929 goto out_fail;
4930 }
4931
4932 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4933 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304934 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004935 if (!mpt2sas_port) {
4936 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4937 ioc->name, __FILE__, __LINE__, __func__);
4938 rc = -1;
4939 goto out_fail;
4940 }
4941 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4942
4943 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4944 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4945 &expander_pg1, i, handle))) {
4946 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4947 ioc->name, __FILE__, __LINE__, __func__);
Kashyap, Desai20f58952009-08-07 19:34:26 +05304948 rc = -1;
4949 goto out_fail;
Eric Moore635374e2009-03-09 01:21:12 -06004950 }
4951 sas_expander->phy[i].handle = handle;
4952 sas_expander->phy[i].phy_id = i;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304953
4954 if ((mpt2sas_transport_add_expander_phy(ioc,
4955 &sas_expander->phy[i], expander_pg1,
4956 sas_expander->parent_dev))) {
4957 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4958 ioc->name, __FILE__, __LINE__, __func__);
4959 rc = -1;
4960 goto out_fail;
4961 }
Eric Moore635374e2009-03-09 01:21:12 -06004962 }
4963
4964 if (sas_expander->enclosure_handle) {
4965 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4966 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4967 sas_expander->enclosure_handle))) {
4968 sas_expander->enclosure_logical_id =
4969 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4970 }
4971 }
4972
4973 _scsih_expander_node_add(ioc, sas_expander);
4974 return 0;
4975
4976 out_fail:
4977
Kashyap, Desai20f58952009-08-07 19:34:26 +05304978 if (mpt2sas_port)
4979 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304980 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004981 kfree(sas_expander);
4982 return rc;
4983}
4984
4985/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05304986 * _scsih_done - scsih callback handler.
4987 * @ioc: per adapter object
4988 * @smid: system request message index
4989 * @msix_index: MSIX table index supplied by the OS
4990 * @reply: reply message frame(lower 32bit addr)
4991 *
4992 * Callback handler when sending internal generated message frames.
4993 * The callback index passed is `ioc->scsih_cb_idx`
4994 *
4995 * Return 1 meaning mf should be freed from _base_interrupt
4996 * 0 means the mf is freed from this function.
4997 */
4998static u8
4999_scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5000{
5001 MPI2DefaultReply_t *mpi_reply;
5002
5003 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5004 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
5005 return 1;
5006 if (ioc->scsih_cmds.smid != smid)
5007 return 1;
5008 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
5009 if (mpi_reply) {
5010 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5011 mpi_reply->MsgLength*4);
5012 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
5013 }
5014 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
5015 complete(&ioc->scsih_cmds.done);
5016 return 1;
5017}
5018
5019/**
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305020 * mpt2sas_expander_remove - removing expander object
Eric Moore635374e2009-03-09 01:21:12 -06005021 * @ioc: per adapter object
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305022 * @sas_address: expander sas_address
Eric Moore635374e2009-03-09 01:21:12 -06005023 *
5024 * Return nothing.
5025 */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305026void
5027mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06005028{
5029 struct _sas_node *sas_expander;
5030 unsigned long flags;
5031
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305032 if (ioc->shost_recovery)
5033 return;
5034
Eric Moore635374e2009-03-09 01:21:12 -06005035 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305036 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5037 sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305038 if (sas_expander)
5039 list_del(&sas_expander->list);
Eric Moore635374e2009-03-09 01:21:12 -06005040 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305041 if (sas_expander)
5042 _scsih_expander_node_remove(ioc, sas_expander);
Eric Moore635374e2009-03-09 01:21:12 -06005043}
5044
5045/**
Kashyap, Desaib4344272010-03-17 16:24:14 +05305046 * _scsih_check_access_status - check access flags
5047 * @ioc: per adapter object
5048 * @sas_address: sas address
5049 * @handle: sas device handle
5050 * @access_flags: errors returned during discovery of the device
5051 *
5052 * Return 0 for success, else failure
5053 */
5054static u8
5055_scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5056 u16 handle, u8 access_status)
5057{
5058 u8 rc = 1;
5059 char *desc = NULL;
5060
5061 switch (access_status) {
5062 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5063 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5064 rc = 0;
5065 break;
5066 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5067 desc = "sata capability failed";
5068 break;
5069 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5070 desc = "sata affiliation conflict";
5071 break;
5072 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5073 desc = "route not addressable";
5074 break;
5075 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5076 desc = "smp error not addressable";
5077 break;
5078 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5079 desc = "device blocked";
5080 break;
5081 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5082 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5083 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5084 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5085 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5086 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5087 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5088 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5089 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5090 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5091 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5092 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5093 desc = "sata initialization failed";
5094 break;
5095 default:
5096 desc = "unknown";
5097 break;
5098 }
5099
5100 if (!rc)
5101 return 0;
5102
5103 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5104 "handle(0x%04x)\n", ioc->name, desc,
5105 (unsigned long long)sas_address, handle);
5106 return rc;
5107}
5108
5109static void
5110_scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5111{
5112 Mpi2ConfigReply_t mpi_reply;
5113 Mpi2SasDevicePage0_t sas_device_pg0;
5114 struct _sas_device *sas_device;
5115 u32 ioc_status;
5116 unsigned long flags;
5117 u64 sas_address;
5118 struct scsi_target *starget;
5119 struct MPT2SAS_TARGET *sas_target_priv_data;
5120 u32 device_info;
5121
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305122
Kashyap, Desaib4344272010-03-17 16:24:14 +05305123 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5124 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5125 return;
5126
5127 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5128 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5129 return;
5130
5131 /* check if this is end device */
5132 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5133 if (!(_scsih_is_end_device(device_info)))
5134 return;
5135
5136 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5137 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5138 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5139 sas_address);
5140
5141 if (!sas_device) {
5142 printk(MPT2SAS_ERR_FMT "device is not present "
5143 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5144 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5145 return;
5146 }
5147
5148 if (unlikely(sas_device->handle != handle)) {
5149 starget = sas_device->starget;
5150 sas_target_priv_data = starget->hostdata;
5151 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5152 " to (0x%04x)!!!\n", sas_device->handle, handle);
5153 sas_target_priv_data->handle = handle;
5154 sas_device->handle = handle;
5155 }
Kashyap, Desaib4344272010-03-17 16:24:14 +05305156
5157 /* check if device is present */
5158 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5159 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5160 printk(MPT2SAS_ERR_FMT "device is not present "
5161 "handle(0x%04x), flags!!!\n", ioc->name, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305162 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305163 return;
5164 }
5165
5166 /* check if there were any issues with discovery */
5167 if (_scsih_check_access_status(ioc, sas_address, handle,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305168 sas_device_pg0.AccessStatus)) {
5169 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305170 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305171 }
5172 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05305173 _scsih_ublock_io_device(ioc, sas_address);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305174
5175}
5176
5177/**
Eric Moore635374e2009-03-09 01:21:12 -06005178 * _scsih_add_device - creating sas device object
5179 * @ioc: per adapter object
5180 * @handle: sas device handle
5181 * @phy_num: phy number end device attached to
5182 * @is_pd: is this hidden raid component
5183 *
5184 * Creating end device object, stored in ioc->sas_device_list.
5185 *
5186 * Returns 0 for success, non-zero for failure.
5187 */
5188static int
5189_scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5190{
5191 Mpi2ConfigReply_t mpi_reply;
5192 Mpi2SasDevicePage0_t sas_device_pg0;
5193 Mpi2SasEnclosurePage0_t enclosure_pg0;
5194 struct _sas_device *sas_device;
5195 u32 ioc_status;
5196 __le64 sas_address;
5197 u32 device_info;
5198 unsigned long flags;
5199
5200 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5201 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5202 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5203 ioc->name, __FILE__, __LINE__, __func__);
5204 return -1;
5205 }
5206
5207 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5208 MPI2_IOCSTATUS_MASK;
5209 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5210 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5211 ioc->name, __FILE__, __LINE__, __func__);
5212 return -1;
5213 }
5214
Kashyap, Desaib4344272010-03-17 16:24:14 +05305215 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5216
Eric Moore635374e2009-03-09 01:21:12 -06005217 /* check if device is present */
5218 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5219 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5220 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5221 ioc->name, __FILE__, __LINE__, __func__);
5222 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5223 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5224 return -1;
5225 }
5226
Kashyap, Desaib4344272010-03-17 16:24:14 +05305227 /* check if there were any issues with discovery */
5228 if (_scsih_check_access_status(ioc, sas_address, handle,
5229 sas_device_pg0.AccessStatus))
Eric Moore635374e2009-03-09 01:21:12 -06005230 return -1;
Eric Moore635374e2009-03-09 01:21:12 -06005231
5232 /* check if this is end device */
5233 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5234 if (!(_scsih_is_end_device(device_info))) {
5235 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5236 ioc->name, __FILE__, __LINE__, __func__);
5237 return -1;
5238 }
5239
Eric Moore635374e2009-03-09 01:21:12 -06005240
5241 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5242 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5243 sas_address);
5244 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5245
Kashyap, Desaib4344272010-03-17 16:24:14 +05305246 if (sas_device)
Eric Moore635374e2009-03-09 01:21:12 -06005247 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06005248
5249 sas_device = kzalloc(sizeof(struct _sas_device),
5250 GFP_KERNEL);
5251 if (!sas_device) {
5252 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5253 ioc->name, __FILE__, __LINE__, __func__);
5254 return -1;
5255 }
5256
5257 sas_device->handle = handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305258 if (_scsih_get_sas_address(ioc, le16_to_cpu
5259 (sas_device_pg0.ParentDevHandle),
5260 &sas_device->sas_address_parent) != 0)
5261 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5262 ioc->name, __FILE__, __LINE__, __func__);
Eric Moore635374e2009-03-09 01:21:12 -06005263 sas_device->enclosure_handle =
5264 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5265 sas_device->slot =
5266 le16_to_cpu(sas_device_pg0.Slot);
5267 sas_device->device_info = device_info;
5268 sas_device->sas_address = sas_address;
Kashyap, Desai7fbae672010-06-17 13:45:17 +05305269 sas_device->phy = sas_device_pg0.PhyNum;
Eric Moore635374e2009-03-09 01:21:12 -06005270
5271 /* get enclosure_logical_id */
Kashyap, Desai15052c92009-08-07 19:33:17 +05305272 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5273 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5274 sas_device->enclosure_handle)))
Eric Moore635374e2009-03-09 01:21:12 -06005275 sas_device->enclosure_logical_id =
5276 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
Eric Moore635374e2009-03-09 01:21:12 -06005277
5278 /* get device name */
5279 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5280
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305281 if (ioc->wait_for_discovery_to_complete)
Eric Moore635374e2009-03-09 01:21:12 -06005282 _scsih_sas_device_init_add(ioc, sas_device);
5283 else
5284 _scsih_sas_device_add(ioc, sas_device);
5285
5286 return 0;
5287}
5288
5289/**
Kashyap, Desai1278b112010-03-09 17:34:13 +05305290 * _scsih_remove_device - removing sas device object
5291 * @ioc: per adapter object
5292 * @sas_device_delete: the sas_device object
5293 *
5294 * Return nothing.
5295 */
5296static void
5297_scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5298 struct _sas_device *sas_device)
5299{
Kashyap, Desai1278b112010-03-09 17:34:13 +05305300 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05305301
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05305302 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5303 (sas_device->pfa_led_on)) {
5304 _scsih_turn_off_pfa_led(ioc, sas_device);
5305 sas_device->pfa_led_on = 0;
5306 }
5307
Kashyap, Desai1278b112010-03-09 17:34:13 +05305308 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5309 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305310 sas_device->handle, (unsigned long long)
5311 sas_device->sas_address));
Kashyap, Desai1278b112010-03-09 17:34:13 +05305312
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305313 if (sas_device->starget && sas_device->starget->hostdata) {
5314 sas_target_priv_data = sas_device->starget->hostdata;
Kashyap, Desai1278b112010-03-09 17:34:13 +05305315 sas_target_priv_data->deleted = 1;
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05305316 _scsih_ublock_io_device(ioc, sas_device->sas_address);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305317 sas_target_priv_data->handle =
5318 MPT2SAS_INVALID_DEVICE_HANDLE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05305319 }
5320
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05305321 if (!ioc->hide_drives)
5322 mpt2sas_transport_port_remove(ioc,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305323 sas_device->sas_address,
5324 sas_device->sas_address_parent);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305325
5326 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305327 "(0x%016llx)\n", ioc->name, sas_device->handle,
5328 (unsigned long long) sas_device->sas_address);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305329
5330 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5331 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305332 sas_device->handle, (unsigned long long)
5333 sas_device->sas_address));
5334 kfree(sas_device);
5335}
5336/**
5337 * _scsih_device_remove_by_handle - removing device object by handle
5338 * @ioc: per adapter object
5339 * @handle: device handle
5340 *
5341 * Return nothing.
5342 */
5343static void
5344_scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5345{
5346 struct _sas_device *sas_device;
5347 unsigned long flags;
5348
5349 if (ioc->shost_recovery)
5350 return;
5351
5352 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5353 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5354 if (sas_device)
5355 list_del(&sas_device->list);
5356 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5357 if (sas_device)
5358 _scsih_remove_device(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -06005359}
5360
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305361/**
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305362 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305363 * @ioc: per adapter object
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305364 * @sas_address: device sas_address
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305365 *
5366 * Return nothing.
5367 */
5368void
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305369mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
5370 u64 sas_address)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305371{
5372 struct _sas_device *sas_device;
5373 unsigned long flags;
5374
5375 if (ioc->shost_recovery)
5376 return;
5377
5378 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5379 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5380 sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305381 if (sas_device)
5382 list_del(&sas_device->list);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305383 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305384 if (sas_device)
5385 _scsih_remove_device(ioc, sas_device);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305386}
Eric Moore635374e2009-03-09 01:21:12 -06005387#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5388/**
5389 * _scsih_sas_topology_change_event_debug - debug for topology event
5390 * @ioc: per adapter object
5391 * @event_data: event data payload
5392 * Context: user.
5393 */
5394static void
5395_scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5396 Mpi2EventDataSasTopologyChangeList_t *event_data)
5397{
5398 int i;
5399 u16 handle;
5400 u16 reason_code;
5401 u8 phy_number;
5402 char *status_str = NULL;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305403 u8 link_rate, prev_link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06005404
5405 switch (event_data->ExpStatus) {
5406 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5407 status_str = "add";
5408 break;
5409 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5410 status_str = "remove";
5411 break;
5412 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305413 case 0:
Eric Moore635374e2009-03-09 01:21:12 -06005414 status_str = "responding";
5415 break;
5416 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5417 status_str = "remove delay";
5418 break;
5419 default:
5420 status_str = "unknown status";
5421 break;
5422 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305423 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
Eric Moore635374e2009-03-09 01:21:12 -06005424 ioc->name, status_str);
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305425 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
Eric Moore635374e2009-03-09 01:21:12 -06005426 "start_phy(%02d), count(%d)\n",
5427 le16_to_cpu(event_data->ExpanderDevHandle),
5428 le16_to_cpu(event_data->EnclosureHandle),
5429 event_data->StartPhyNum, event_data->NumEntries);
5430 for (i = 0; i < event_data->NumEntries; i++) {
5431 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5432 if (!handle)
5433 continue;
5434 phy_number = event_data->StartPhyNum + i;
5435 reason_code = event_data->PHY[i].PhyStatus &
5436 MPI2_EVENT_SAS_TOPO_RC_MASK;
5437 switch (reason_code) {
5438 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305439 status_str = "target add";
Eric Moore635374e2009-03-09 01:21:12 -06005440 break;
5441 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305442 status_str = "target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005443 break;
5444 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305445 status_str = "delay target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005446 break;
5447 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305448 status_str = "link rate change";
Eric Moore635374e2009-03-09 01:21:12 -06005449 break;
5450 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305451 status_str = "target responding";
Eric Moore635374e2009-03-09 01:21:12 -06005452 break;
5453 default:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305454 status_str = "unknown";
Eric Moore635374e2009-03-09 01:21:12 -06005455 break;
5456 }
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305457 link_rate = event_data->PHY[i].LinkRate >> 4;
5458 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305459 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305460 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5461 handle, status_str, link_rate, prev_link_rate);
5462
Eric Moore635374e2009-03-09 01:21:12 -06005463 }
5464}
5465#endif
5466
5467/**
5468 * _scsih_sas_topology_change_event - handle topology changes
5469 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305470 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005471 * Context: user.
5472 *
5473 */
5474static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305475_scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
Eric Moore635374e2009-03-09 01:21:12 -06005476 struct fw_event_work *fw_event)
5477{
5478 int i;
5479 u16 parent_handle, handle;
5480 u16 reason_code;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305481 u8 phy_number, max_phys;
Eric Moore635374e2009-03-09 01:21:12 -06005482 struct _sas_node *sas_expander;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305483 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06005484 unsigned long flags;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305485 u8 link_rate, prev_link_rate;
Joe Lawrence00713ad2014-06-25 17:03:33 -04005486 Mpi2EventDataSasTopologyChangeList_t *event_data =
5487 (Mpi2EventDataSasTopologyChangeList_t *)
5488 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06005489
5490#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5491 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5492 _scsih_sas_topology_change_event_debug(ioc, event_data);
5493#endif
5494
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305495 if (ioc->remove_host || ioc->pci_error_recovery)
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305496 return;
5497
Eric Moore635374e2009-03-09 01:21:12 -06005498 if (!ioc->sas_hba.num_phys)
5499 _scsih_sas_host_add(ioc);
5500 else
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305501 _scsih_sas_host_refresh(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005502
5503 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305504 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
Eric Moore635374e2009-03-09 01:21:12 -06005505 "event\n", ioc->name));
5506 return;
5507 }
5508
5509 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5510
5511 /* handle expander add */
5512 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5513 if (_scsih_expander_add(ioc, parent_handle) != 0)
5514 return;
5515
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305516 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5517 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5518 parent_handle);
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305519 if (sas_expander) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305520 sas_address = sas_expander->sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305521 max_phys = sas_expander->num_phys;
5522 } else if (parent_handle < ioc->sas_hba.num_phys) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305523 sas_address = ioc->sas_hba.sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305524 max_phys = ioc->sas_hba.num_phys;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305525 } else {
5526 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305527 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305528 }
5529 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305530
Eric Moore635374e2009-03-09 01:21:12 -06005531 /* handle siblings events */
5532 for (i = 0; i < event_data->NumEntries; i++) {
5533 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305534 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
Eric Moore635374e2009-03-09 01:21:12 -06005535 "expander event\n", ioc->name));
5536 return;
5537 }
Eric Moore3cb54692010-07-08 14:44:34 -06005538 if (ioc->shost_recovery || ioc->remove_host ||
5539 ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305540 return;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305541 phy_number = event_data->StartPhyNum + i;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305542 if (phy_number >= max_phys)
5543 continue;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305544 reason_code = event_data->PHY[i].PhyStatus &
5545 MPI2_EVENT_SAS_TOPO_RC_MASK;
5546 if ((event_data->PHY[i].PhyStatus &
5547 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5548 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
Eric Moore635374e2009-03-09 01:21:12 -06005549 continue;
5550 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5551 if (!handle)
5552 continue;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305553 link_rate = event_data->PHY[i].LinkRate >> 4;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305554 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Eric Moore635374e2009-03-09 01:21:12 -06005555 switch (reason_code) {
5556 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305557
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305558 if (ioc->shost_recovery)
5559 break;
5560
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305561 if (link_rate == prev_link_rate)
5562 break;
5563
5564 mpt2sas_transport_update_links(ioc, sas_address,
5565 handle, phy_number, link_rate);
5566
Kashyap, Desaib4344272010-03-17 16:24:14 +05305567 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5568 break;
5569
5570 _scsih_check_device(ioc, handle);
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305571 break;
Eric Moore635374e2009-03-09 01:21:12 -06005572 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305573
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305574 if (ioc->shost_recovery)
5575 break;
5576
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305577 mpt2sas_transport_update_links(ioc, sas_address,
5578 handle, phy_number, link_rate);
5579
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305580 _scsih_add_device(ioc, handle, phy_number, 0);
Eric Moore635374e2009-03-09 01:21:12 -06005581 break;
5582 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305583
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305584 _scsih_device_remove_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06005585 break;
5586 }
5587 }
5588
5589 /* handle expander removal */
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305590 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5591 sas_expander)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305592 mpt2sas_expander_remove(ioc, sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06005593
5594}
5595
5596#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5597/**
5598 * _scsih_sas_device_status_change_event_debug - debug for device event
5599 * @event_data: event data payload
5600 * Context: user.
5601 *
5602 * Return nothing.
5603 */
5604static void
5605_scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5606 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5607{
5608 char *reason_str = NULL;
5609
5610 switch (event_data->ReasonCode) {
5611 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5612 reason_str = "smart data";
5613 break;
5614 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5615 reason_str = "unsupported device discovered";
5616 break;
5617 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5618 reason_str = "internal device reset";
5619 break;
5620 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5621 reason_str = "internal task abort";
5622 break;
5623 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5624 reason_str = "internal task abort set";
5625 break;
5626 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5627 reason_str = "internal clear task set";
5628 break;
5629 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5630 reason_str = "internal query task";
5631 break;
5632 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5633 reason_str = "sata init failure";
5634 break;
5635 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5636 reason_str = "internal device reset complete";
5637 break;
5638 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5639 reason_str = "internal task abort complete";
5640 break;
5641 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5642 reason_str = "internal async notification";
5643 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05305644 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5645 reason_str = "expander reduced functionality";
5646 break;
5647 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5648 reason_str = "expander reduced functionality complete";
5649 break;
Eric Moore635374e2009-03-09 01:21:12 -06005650 default:
5651 reason_str = "unknown reason";
5652 break;
5653 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305654 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305655 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5656 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5657 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5658 le16_to_cpu(event_data->TaskTag));
Eric Moore635374e2009-03-09 01:21:12 -06005659 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305660 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005661 event_data->ASC, event_data->ASCQ);
5662 printk(KERN_INFO "\n");
5663}
5664#endif
5665
5666/**
5667 * _scsih_sas_device_status_change_event - handle device status change
5668 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305669 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005670 * Context: user.
5671 *
5672 * Return nothing.
5673 */
5674static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305675_scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5676 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005677{
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305678 struct MPT2SAS_TARGET *target_priv_data;
5679 struct _sas_device *sas_device;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05305680 u64 sas_address;
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305681 unsigned long flags;
5682 Mpi2EventDataSasDeviceStatusChange_t *event_data =
Joe Lawrence00713ad2014-06-25 17:03:33 -04005683 (Mpi2EventDataSasDeviceStatusChange_t *)
5684 fw_event->event_data;
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305685
Eric Moore635374e2009-03-09 01:21:12 -06005686#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5687 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305688 _scsih_sas_device_status_change_event_debug(ioc,
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305689 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005690#endif
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305691
Kashyap, Desaiefe82a12011-01-04 11:34:17 +05305692 /* In MPI Revision K (0xC), the internal device reset complete was
5693 * implemented, so avoid setting tm_busy flag for older firmware.
5694 */
5695 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5696 return;
5697
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305698 if (event_data->ReasonCode !=
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305699 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305700 event_data->ReasonCode !=
5701 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305702 return;
5703
5704 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5705 sas_address = le64_to_cpu(event_data->SASAddress);
5706 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5707 sas_address);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305708
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305709 if (!sas_device || !sas_device->starget) {
5710 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305711 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305712 }
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305713
5714 target_priv_data = sas_device->starget->hostdata;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305715 if (!target_priv_data) {
5716 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305717 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305718 }
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305719
5720 if (event_data->ReasonCode ==
5721 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5722 target_priv_data->tm_busy = 1;
5723 else
5724 target_priv_data->tm_busy = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305725 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005726}
5727
5728#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5729/**
5730 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5731 * @ioc: per adapter object
5732 * @event_data: event data payload
5733 * Context: user.
5734 *
5735 * Return nothing.
5736 */
5737static void
5738_scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5739 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5740{
5741 char *reason_str = NULL;
5742
5743 switch (event_data->ReasonCode) {
5744 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5745 reason_str = "enclosure add";
5746 break;
5747 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5748 reason_str = "enclosure remove";
5749 break;
5750 default:
5751 reason_str = "unknown reason";
5752 break;
5753 }
5754
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305755 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
Eric Moore635374e2009-03-09 01:21:12 -06005756 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5757 " number slots(%d)\n", ioc->name, reason_str,
5758 le16_to_cpu(event_data->EnclosureHandle),
5759 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5760 le16_to_cpu(event_data->StartSlot));
5761}
5762#endif
5763
5764/**
5765 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5766 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305767 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005768 * Context: user.
5769 *
5770 * Return nothing.
5771 */
5772static void
5773_scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305774 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005775{
5776#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5777 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5778 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
Joe Lawrence00713ad2014-06-25 17:03:33 -04005779 (Mpi2EventDataSasEnclDevStatusChange_t *)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305780 fw_event->event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005781#endif
5782}
5783
5784/**
Andrew Mortona78e21d2012-02-08 12:52:22 -08005785 * _scsih_sas_broadcast_primitive_event - handle broadcast events
Eric Moore635374e2009-03-09 01:21:12 -06005786 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305787 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005788 * Context: user.
5789 *
5790 * Return nothing.
5791 */
5792static void
Andrew Mortona78e21d2012-02-08 12:52:22 -08005793_scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305794 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005795{
5796 struct scsi_cmnd *scmd;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305797 struct scsi_device *sdev;
Eric Moore635374e2009-03-09 01:21:12 -06005798 u16 smid, handle;
5799 u32 lun;
5800 struct MPT2SAS_DEVICE *sas_device_priv_data;
5801 u32 termination_count;
5802 u32 query_count;
5803 Mpi2SCSITaskManagementReply_t *mpi_reply;
Joe Lawrence00713ad2014-06-25 17:03:33 -04005804 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5805 (Mpi2EventDataSasBroadcastPrimitive_t *)
5806 fw_event->event_data;
Kashyap, Desai463217b2009-10-05 15:53:06 +05305807 u16 ioc_status;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305808 unsigned long flags;
5809 int r;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305810 u8 max_retries = 0;
5811 u8 task_abort_retries;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305812
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305813 mutex_lock(&ioc->tm_cmds.mutex);
Reddy, Sreekanthc3a634b2013-02-26 17:36:12 +05305814 pr_info(MPT2SAS_FMT
5815 "%s: enter: phy number(%d), width(%d)\n",
5816 ioc->name, __func__, event_data->PhyNum,
5817 event_data->PortWidth);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305818
5819 _scsih_block_io_all_device(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005820
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305821 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305822 mpi_reply = ioc->tm_cmds.reply;
5823broadcast_aen_retry:
5824
5825 /* sanity checks for retrying this loop */
5826 if (max_retries++ == 5) {
5827 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5828 ioc->name, __func__));
5829 goto out;
5830 } else if (max_retries > 1)
5831 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5832 ioc->name, __func__, max_retries - 1));
5833
Eric Moore635374e2009-03-09 01:21:12 -06005834 termination_count = 0;
5835 query_count = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305836 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305837 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305838 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06005839 scmd = _scsih_scsi_lookup_get(ioc, smid);
5840 if (!scmd)
5841 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305842 sdev = scmd->device;
5843 sas_device_priv_data = sdev->hostdata;
Eric Moore635374e2009-03-09 01:21:12 -06005844 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5845 continue;
5846 /* skip hidden raid components */
5847 if (sas_device_priv_data->sas_target->flags &
5848 MPT_TARGET_FLAGS_RAID_COMPONENT)
5849 continue;
5850 /* skip volumes */
5851 if (sas_device_priv_data->sas_target->flags &
5852 MPT_TARGET_FLAGS_VOLUME)
5853 continue;
5854
5855 handle = sas_device_priv_data->sas_target->handle;
5856 lun = sas_device_priv_data->lun;
5857 query_count++;
5858
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305859 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305860 goto out;
5861
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305862 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305863 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04005864 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305865 TM_MUTEX_OFF);
5866 if (r == FAILED) {
5867 sdev_printk(KERN_WARNING, sdev,
5868 "mpt2sas_scsih_issue_tm: FAILED when sending "
5869 "QUERY_TASK: scmd(%p)\n", scmd);
5870 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5871 goto broadcast_aen_retry;
5872 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05305873 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5874 & MPI2_IOCSTATUS_MASK;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305875 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5876 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5877 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5878 scmd);
5879 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5880 goto broadcast_aen_retry;
5881 }
5882
5883 /* see if IO is still owned by IOC and target */
5884 if (mpi_reply->ResponseCode ==
Eric Moore635374e2009-03-09 01:21:12 -06005885 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5886 mpi_reply->ResponseCode ==
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305887 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305888 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005889 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305890 }
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305891 task_abort_retries = 0;
5892 tm_retry:
5893 if (task_abort_retries++ == 60) {
5894 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5895 "%s: ABORT_TASK: giving up\n", ioc->name,
5896 __func__));
5897 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5898 goto broadcast_aen_retry;
5899 }
5900
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305901 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305902 goto out_no_lock;
5903
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305904 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5905 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04005906 TM_MUTEX_OFF);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305907 if (r == FAILED) {
5908 sdev_printk(KERN_WARNING, sdev,
5909 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305910 "scmd(%p)\n", scmd);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305911 goto tm_retry;
5912 }
5913
5914 if (task_abort_retries > 1)
5915 sdev_printk(KERN_WARNING, sdev,
5916 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5917 " scmd(%p)\n",
5918 task_abort_retries - 1, scmd);
5919
Eric Moore635374e2009-03-09 01:21:12 -06005920 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305921 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005922 }
Eric Moore635374e2009-03-09 01:21:12 -06005923
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305924 if (ioc->broadcast_aen_pending) {
5925 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5926 " pending AEN\n", ioc->name, __func__));
5927 ioc->broadcast_aen_pending = 0;
5928 goto broadcast_aen_retry;
5929 }
5930
5931 out:
5932 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5933 out_no_lock:
5934
5935 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06005936 "%s - exit, query_count = %d termination_count = %d\n",
5937 ioc->name, __func__, query_count, termination_count));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305938
5939 ioc->broadcast_aen_busy = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305940 if (!ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305941 _scsih_ublock_io_all_device(ioc);
5942 mutex_unlock(&ioc->tm_cmds.mutex);
Eric Moore635374e2009-03-09 01:21:12 -06005943}
5944
5945/**
5946 * _scsih_sas_discovery_event - handle discovery events
5947 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305948 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005949 * Context: user.
5950 *
5951 * Return nothing.
5952 */
5953static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305954_scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5955 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005956{
Joe Lawrence00713ad2014-06-25 17:03:33 -04005957 Mpi2EventDataSasDiscovery_t *event_data =
5958 (Mpi2EventDataSasDiscovery_t *)
5959 fw_event->event_data;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305960
Eric Moore635374e2009-03-09 01:21:12 -06005961#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5962 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305963 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005964 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5965 "start" : "stop");
5966 if (event_data->DiscoveryStatus)
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305967 printk("discovery_status(0x%08x)",
5968 le32_to_cpu(event_data->DiscoveryStatus));
Eric Moore635374e2009-03-09 01:21:12 -06005969 printk("\n");
5970 }
5971#endif
5972
5973 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05305974 !ioc->sas_hba.num_phys) {
5975 if (disable_discovery > 0 && ioc->shost_recovery) {
5976 /* Wait for the reset to complete */
5977 while (ioc->shost_recovery)
5978 ssleep(1);
5979 }
Eric Moore635374e2009-03-09 01:21:12 -06005980 _scsih_sas_host_add(ioc);
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05305981 }
Eric Moore635374e2009-03-09 01:21:12 -06005982}
5983
5984/**
5985 * _scsih_reprobe_lun - reprobing lun
5986 * @sdev: scsi device struct
5987 * @no_uld_attach: sdev->no_uld_attach flag setting
5988 *
5989 **/
5990static void
5991_scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5992{
5993 int rc;
5994
5995 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5996 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5997 sdev->no_uld_attach ? "hidding" : "exposing");
5998 rc = scsi_device_reprobe(sdev);
5999}
6000
6001/**
Eric Moore635374e2009-03-09 01:21:12 -06006002 * _scsih_sas_volume_add - add new volume
6003 * @ioc: per adapter object
6004 * @element: IR config element data
6005 * Context: user.
6006 *
6007 * Return nothing.
6008 */
6009static void
6010_scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
6011 Mpi2EventIrConfigElement_t *element)
6012{
6013 struct _raid_device *raid_device;
6014 unsigned long flags;
6015 u64 wwid;
6016 u16 handle = le16_to_cpu(element->VolDevHandle);
6017 int rc;
6018
Eric Moore635374e2009-03-09 01:21:12 -06006019 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6020 if (!wwid) {
6021 printk(MPT2SAS_ERR_FMT
6022 "failure at %s:%d/%s()!\n", ioc->name,
6023 __FILE__, __LINE__, __func__);
6024 return;
6025 }
6026
6027 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6028 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6029 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6030
6031 if (raid_device)
6032 return;
6033
6034 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6035 if (!raid_device) {
6036 printk(MPT2SAS_ERR_FMT
6037 "failure at %s:%d/%s()!\n", ioc->name,
6038 __FILE__, __LINE__, __func__);
6039 return;
6040 }
6041
6042 raid_device->id = ioc->sas_id++;
6043 raid_device->channel = RAID_CHANNEL;
6044 raid_device->handle = handle;
6045 raid_device->wwid = wwid;
6046 _scsih_raid_device_add(ioc, raid_device);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306047 if (!ioc->wait_for_discovery_to_complete) {
Eric Moore635374e2009-03-09 01:21:12 -06006048 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6049 raid_device->id, 0);
6050 if (rc)
6051 _scsih_raid_device_remove(ioc, raid_device);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306052 } else {
6053 spin_lock_irqsave(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06006054 _scsih_determine_boot_device(ioc, raid_device, 1);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306055 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6056 }
Eric Moore635374e2009-03-09 01:21:12 -06006057}
6058
6059/**
6060 * _scsih_sas_volume_delete - delete volume
6061 * @ioc: per adapter object
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306062 * @handle: volume device handle
Eric Moore635374e2009-03-09 01:21:12 -06006063 * Context: user.
6064 *
6065 * Return nothing.
6066 */
6067static void
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306068_scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Eric Moore635374e2009-03-09 01:21:12 -06006069{
6070 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06006071 unsigned long flags;
6072 struct MPT2SAS_TARGET *sas_target_priv_data;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306073 struct scsi_target *starget = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006074
Eric Moore635374e2009-03-09 01:21:12 -06006075 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6076 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306077 if (raid_device) {
6078 if (raid_device->starget) {
6079 starget = raid_device->starget;
6080 sas_target_priv_data = starget->hostdata;
6081 sas_target_priv_data->deleted = 1;
6082 }
6083 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6084 "(0x%016llx)\n", ioc->name, raid_device->handle,
6085 (unsigned long long) raid_device->wwid);
6086 list_del(&raid_device->list);
6087 kfree(raid_device);
Eric Moore635374e2009-03-09 01:21:12 -06006088 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306089 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6090 if (starget)
6091 scsi_remove_target(&starget->dev);
Eric Moore635374e2009-03-09 01:21:12 -06006092}
6093
6094/**
6095 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6096 * @ioc: per adapter object
6097 * @element: IR config element data
6098 * Context: user.
6099 *
6100 * Return nothing.
6101 */
6102static void
6103_scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6104 Mpi2EventIrConfigElement_t *element)
6105{
6106 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306107 struct scsi_target *starget = NULL;
6108 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06006109 unsigned long flags;
6110 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6111
6112 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6113 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306114 if (sas_device) {
6115 sas_device->volume_handle = 0;
6116 sas_device->volume_wwid = 0;
6117 clear_bit(handle, ioc->pd_handles);
6118 if (sas_device->starget && sas_device->starget->hostdata) {
6119 starget = sas_device->starget;
6120 sas_target_priv_data = starget->hostdata;
6121 sas_target_priv_data->flags &=
6122 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6123 }
6124 }
Eric Moore635374e2009-03-09 01:21:12 -06006125 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6126 if (!sas_device)
6127 return;
6128
6129 /* exposing raid component */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306130 if (starget)
6131 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
Eric Moore635374e2009-03-09 01:21:12 -06006132}
6133
6134/**
6135 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6136 * @ioc: per adapter object
6137 * @element: IR config element data
6138 * Context: user.
6139 *
6140 * Return nothing.
6141 */
6142static void
6143_scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6144 Mpi2EventIrConfigElement_t *element)
6145{
6146 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306147 struct scsi_target *starget = NULL;
6148 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06006149 unsigned long flags;
6150 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306151 u16 volume_handle = 0;
6152 u64 volume_wwid = 0;
6153
6154 mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle);
6155 if (volume_handle)
6156 mpt2sas_config_get_volume_wwid(ioc, volume_handle,
6157 &volume_wwid);
Eric Moore635374e2009-03-09 01:21:12 -06006158
6159 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6160 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306161 if (sas_device) {
6162 set_bit(handle, ioc->pd_handles);
6163 if (sas_device->starget && sas_device->starget->hostdata) {
6164 starget = sas_device->starget;
6165 sas_target_priv_data = starget->hostdata;
6166 sas_target_priv_data->flags |=
6167 MPT_TARGET_FLAGS_RAID_COMPONENT;
6168 sas_device->volume_handle = volume_handle;
6169 sas_device->volume_wwid = volume_wwid;
6170 }
6171 }
Eric Moore635374e2009-03-09 01:21:12 -06006172 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6173 if (!sas_device)
6174 return;
6175
6176 /* hiding raid component */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306177 if (starget)
6178 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
Eric Moore635374e2009-03-09 01:21:12 -06006179}
6180
6181/**
6182 * _scsih_sas_pd_delete - delete pd component
6183 * @ioc: per adapter object
6184 * @element: IR config element data
6185 * Context: user.
6186 *
6187 * Return nothing.
6188 */
6189static void
6190_scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6191 Mpi2EventIrConfigElement_t *element)
6192{
Eric Moore635374e2009-03-09 01:21:12 -06006193 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6194
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306195 _scsih_device_remove_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006196}
6197
6198/**
6199 * _scsih_sas_pd_add - remove pd component
6200 * @ioc: per adapter object
6201 * @element: IR config element data
6202 * Context: user.
6203 *
6204 * Return nothing.
6205 */
6206static void
6207_scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6208 Mpi2EventIrConfigElement_t *element)
6209{
6210 struct _sas_device *sas_device;
6211 unsigned long flags;
6212 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306213 Mpi2ConfigReply_t mpi_reply;
6214 Mpi2SasDevicePage0_t sas_device_pg0;
6215 u32 ioc_status;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306216 u64 sas_address;
6217 u16 parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006218
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306219 set_bit(handle, ioc->pd_handles);
6220
Eric Moore635374e2009-03-09 01:21:12 -06006221 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6222 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6223 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306224 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306225 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306226
6227 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6228 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6229 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6230 ioc->name, __FILE__, __LINE__, __func__);
6231 return;
6232 }
6233
6234 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6235 MPI2_IOCSTATUS_MASK;
6236 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6237 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6238 ioc->name, __FILE__, __LINE__, __func__);
6239 return;
6240 }
6241
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306242 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6243 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6244 mpt2sas_transport_update_links(ioc, sas_address, handle,
6245 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306246
6247 _scsih_add_device(ioc, handle, 0, 1);
Eric Moore635374e2009-03-09 01:21:12 -06006248}
6249
6250#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6251/**
6252 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6253 * @ioc: per adapter object
6254 * @event_data: event data payload
6255 * Context: user.
6256 *
6257 * Return nothing.
6258 */
6259static void
6260_scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6261 Mpi2EventDataIrConfigChangeList_t *event_data)
6262{
6263 Mpi2EventIrConfigElement_t *element;
6264 u8 element_type;
6265 int i;
6266 char *reason_str = NULL, *element_str = NULL;
6267
6268 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6269
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306270 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
Eric Moore635374e2009-03-09 01:21:12 -06006271 ioc->name, (le32_to_cpu(event_data->Flags) &
6272 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6273 "foreign" : "native", event_data->NumElements);
6274 for (i = 0; i < event_data->NumElements; i++, element++) {
6275 switch (element->ReasonCode) {
6276 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6277 reason_str = "add";
6278 break;
6279 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6280 reason_str = "remove";
6281 break;
6282 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6283 reason_str = "no change";
6284 break;
6285 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6286 reason_str = "hide";
6287 break;
6288 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6289 reason_str = "unhide";
6290 break;
6291 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6292 reason_str = "volume_created";
6293 break;
6294 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6295 reason_str = "volume_deleted";
6296 break;
6297 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6298 reason_str = "pd_created";
6299 break;
6300 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6301 reason_str = "pd_deleted";
6302 break;
6303 default:
6304 reason_str = "unknown reason";
6305 break;
6306 }
6307 element_type = le16_to_cpu(element->ElementFlags) &
6308 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6309 switch (element_type) {
6310 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6311 element_str = "volume";
6312 break;
6313 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6314 element_str = "phys disk";
6315 break;
6316 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6317 element_str = "hot spare";
6318 break;
6319 default:
6320 element_str = "unknown element";
6321 break;
6322 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306323 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
Eric Moore635374e2009-03-09 01:21:12 -06006324 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6325 reason_str, le16_to_cpu(element->VolDevHandle),
6326 le16_to_cpu(element->PhysDiskDevHandle),
6327 element->PhysDiskNum);
6328 }
6329}
6330#endif
6331
6332/**
6333 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6334 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306335 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006336 * Context: user.
6337 *
6338 * Return nothing.
6339 */
6340static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306341_scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6342 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006343{
6344 Mpi2EventIrConfigElement_t *element;
6345 int i;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306346 u8 foreign_config;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006347 Mpi2EventDataIrConfigChangeList_t *event_data =
6348 (Mpi2EventDataIrConfigChangeList_t *)
6349 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006350
6351#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306352 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6353 && !ioc->hide_ir_msg)
Eric Moore635374e2009-03-09 01:21:12 -06006354 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6355
6356#endif
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306357
6358 if (ioc->shost_recovery)
6359 return;
6360
Kashyap, Desai62727a72009-08-07 19:35:18 +05306361 foreign_config = (le32_to_cpu(event_data->Flags) &
6362 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
Eric Moore635374e2009-03-09 01:21:12 -06006363
6364 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6365 for (i = 0; i < event_data->NumElements; i++, element++) {
6366
6367 switch (element->ReasonCode) {
6368 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6369 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306370 if (!foreign_config)
6371 _scsih_sas_volume_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006372 break;
6373 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6374 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306375 if (!foreign_config)
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306376 _scsih_sas_volume_delete(ioc,
6377 le16_to_cpu(element->VolDevHandle));
Eric Moore635374e2009-03-09 01:21:12 -06006378 break;
6379 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306380 if (!ioc->is_warpdrive)
6381 _scsih_sas_pd_hide(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006382 break;
6383 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306384 if (!ioc->is_warpdrive)
6385 _scsih_sas_pd_expose(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006386 break;
6387 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306388 if (!ioc->is_warpdrive)
6389 _scsih_sas_pd_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006390 break;
6391 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306392 if (!ioc->is_warpdrive)
6393 _scsih_sas_pd_delete(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006394 break;
6395 }
6396 }
6397}
6398
6399/**
6400 * _scsih_sas_ir_volume_event - IR volume event
6401 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306402 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006403 * Context: user.
6404 *
6405 * Return nothing.
6406 */
6407static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306408_scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6409 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006410{
6411 u64 wwid;
6412 unsigned long flags;
6413 struct _raid_device *raid_device;
6414 u16 handle;
6415 u32 state;
6416 int rc;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006417 Mpi2EventDataIrVolume_t *event_data =
6418 (Mpi2EventDataIrVolume_t *)
6419 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006420
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306421 if (ioc->shost_recovery)
6422 return;
6423
Eric Moore635374e2009-03-09 01:21:12 -06006424 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6425 return;
6426
6427 handle = le16_to_cpu(event_data->VolDevHandle);
6428 state = le32_to_cpu(event_data->NewValue);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306429 if (!ioc->hide_ir_msg)
6430 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6431 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6432 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006433
Eric Moore635374e2009-03-09 01:21:12 -06006434 switch (state) {
6435 case MPI2_RAID_VOL_STATE_MISSING:
6436 case MPI2_RAID_VOL_STATE_FAILED:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306437 _scsih_sas_volume_delete(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006438 break;
6439
6440 case MPI2_RAID_VOL_STATE_ONLINE:
6441 case MPI2_RAID_VOL_STATE_DEGRADED:
6442 case MPI2_RAID_VOL_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306443
6444 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6445 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6446 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6447
Eric Moore635374e2009-03-09 01:21:12 -06006448 if (raid_device)
6449 break;
6450
6451 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6452 if (!wwid) {
6453 printk(MPT2SAS_ERR_FMT
6454 "failure at %s:%d/%s()!\n", ioc->name,
6455 __FILE__, __LINE__, __func__);
6456 break;
6457 }
6458
6459 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6460 if (!raid_device) {
6461 printk(MPT2SAS_ERR_FMT
6462 "failure at %s:%d/%s()!\n", ioc->name,
6463 __FILE__, __LINE__, __func__);
6464 break;
6465 }
6466
6467 raid_device->id = ioc->sas_id++;
6468 raid_device->channel = RAID_CHANNEL;
6469 raid_device->handle = handle;
6470 raid_device->wwid = wwid;
6471 _scsih_raid_device_add(ioc, raid_device);
6472 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6473 raid_device->id, 0);
6474 if (rc)
6475 _scsih_raid_device_remove(ioc, raid_device);
6476 break;
6477
6478 case MPI2_RAID_VOL_STATE_INITIALIZING:
6479 default:
6480 break;
6481 }
6482}
6483
6484/**
6485 * _scsih_sas_ir_physical_disk_event - PD event
6486 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306487 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006488 * Context: user.
6489 *
6490 * Return nothing.
6491 */
6492static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306493_scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6494 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006495{
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306496 u16 handle, parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006497 u32 state;
6498 struct _sas_device *sas_device;
6499 unsigned long flags;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306500 Mpi2ConfigReply_t mpi_reply;
6501 Mpi2SasDevicePage0_t sas_device_pg0;
6502 u32 ioc_status;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006503 Mpi2EventDataIrPhysicalDisk_t *event_data =
6504 (Mpi2EventDataIrPhysicalDisk_t *)
6505 fw_event->event_data;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306506 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006507
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306508 if (ioc->shost_recovery)
6509 return;
6510
Eric Moore635374e2009-03-09 01:21:12 -06006511 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6512 return;
6513
6514 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6515 state = le32_to_cpu(event_data->NewValue);
6516
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306517 if (!ioc->hide_ir_msg)
6518 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6519 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6520 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006521
Eric Moore635374e2009-03-09 01:21:12 -06006522 switch (state) {
Eric Moore635374e2009-03-09 01:21:12 -06006523 case MPI2_RAID_PD_STATE_ONLINE:
6524 case MPI2_RAID_PD_STATE_DEGRADED:
6525 case MPI2_RAID_PD_STATE_REBUILDING:
6526 case MPI2_RAID_PD_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306527 case MPI2_RAID_PD_STATE_HOT_SPARE:
6528
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306529 if (!ioc->is_warpdrive)
6530 set_bit(handle, ioc->pd_handles);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306531
6532 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6533 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6534 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6535
6536 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306537 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306538
6539 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6540 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6541 handle))) {
6542 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6543 ioc->name, __FILE__, __LINE__, __func__);
6544 return;
6545 }
6546
6547 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6548 MPI2_IOCSTATUS_MASK;
6549 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6550 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6551 ioc->name, __FILE__, __LINE__, __func__);
6552 return;
6553 }
6554
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306555 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6556 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6557 mpt2sas_transport_update_links(ioc, sas_address, handle,
6558 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306559
6560 _scsih_add_device(ioc, handle, 0, 1);
6561
Eric Moore635374e2009-03-09 01:21:12 -06006562 break;
6563
Kashyap, Desai62727a72009-08-07 19:35:18 +05306564 case MPI2_RAID_PD_STATE_OFFLINE:
Eric Moore635374e2009-03-09 01:21:12 -06006565 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6566 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
Eric Moore635374e2009-03-09 01:21:12 -06006567 default:
6568 break;
6569 }
6570}
6571
6572#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6573/**
6574 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6575 * @ioc: per adapter object
6576 * @event_data: event data payload
6577 * Context: user.
6578 *
6579 * Return nothing.
6580 */
6581static void
6582_scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6583 Mpi2EventDataIrOperationStatus_t *event_data)
6584{
6585 char *reason_str = NULL;
6586
6587 switch (event_data->RAIDOperation) {
6588 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6589 reason_str = "resync";
6590 break;
6591 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6592 reason_str = "online capacity expansion";
6593 break;
6594 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6595 reason_str = "consistency check";
6596 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306597 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6598 reason_str = "background init";
6599 break;
6600 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6601 reason_str = "make data consistent";
Eric Moore635374e2009-03-09 01:21:12 -06006602 break;
6603 }
6604
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306605 if (!reason_str)
6606 return;
6607
Eric Moore635374e2009-03-09 01:21:12 -06006608 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6609 "\thandle(0x%04x), percent complete(%d)\n",
6610 ioc->name, reason_str,
6611 le16_to_cpu(event_data->VolDevHandle),
6612 event_data->PercentComplete);
6613}
6614#endif
6615
6616/**
6617 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6618 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306619 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006620 * Context: user.
6621 *
6622 * Return nothing.
6623 */
6624static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306625_scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6626 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006627{
Joe Lawrence00713ad2014-06-25 17:03:33 -04006628 Mpi2EventDataIrOperationStatus_t *event_data =
6629 (Mpi2EventDataIrOperationStatus_t *)
6630 fw_event->event_data;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306631 static struct _raid_device *raid_device;
6632 unsigned long flags;
6633 u16 handle;
6634
Eric Moore635374e2009-03-09 01:21:12 -06006635#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306636 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6637 && !ioc->hide_ir_msg)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306638 _scsih_sas_ir_operation_status_event_debug(ioc,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306639 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06006640#endif
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306641
6642 /* code added for raid transport support */
6643 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6644
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306645 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306646 handle = le16_to_cpu(event_data->VolDevHandle);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306647 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306648 if (raid_device)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306649 raid_device->percent_complete =
6650 event_data->PercentComplete;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306651 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306652 }
Eric Moore635374e2009-03-09 01:21:12 -06006653}
6654
6655/**
Kashyap, Desai14695852010-03-30 10:52:44 +05306656 * _scsih_prep_device_scan - initialize parameters prior to device scan
6657 * @ioc: per adapter object
6658 *
6659 * Set the deleted flag prior to device scan. If the device is found during
6660 * the scan, then we clear the deleted flag.
6661 */
6662static void
6663_scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6664{
6665 struct MPT2SAS_DEVICE *sas_device_priv_data;
6666 struct scsi_device *sdev;
6667
6668 shost_for_each_device(sdev, ioc->shost) {
6669 sas_device_priv_data = sdev->hostdata;
6670 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6671 sas_device_priv_data->sas_target->deleted = 1;
6672 }
6673}
6674
6675/**
Eric Moore635374e2009-03-09 01:21:12 -06006676 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6677 * @ioc: per adapter object
6678 * @sas_address: sas address
6679 * @slot: enclosure slot id
6680 * @handle: device handle
6681 *
6682 * After host reset, find out whether devices are still responding.
6683 * Used in _scsi_remove_unresponsive_sas_devices.
6684 *
6685 * Return nothing.
6686 */
6687static void
6688_scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6689 u16 slot, u16 handle)
6690{
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306691 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006692 struct scsi_target *starget;
6693 struct _sas_device *sas_device;
6694 unsigned long flags;
6695
6696 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6697 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6698 if (sas_device->sas_address == sas_address &&
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306699 sas_device->slot == slot) {
Eric Moore635374e2009-03-09 01:21:12 -06006700 sas_device->responding = 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05306701 starget = sas_device->starget;
Kashyap, Desai14695852010-03-30 10:52:44 +05306702 if (starget && starget->hostdata) {
6703 sas_target_priv_data = starget->hostdata;
6704 sas_target_priv_data->tm_busy = 0;
6705 sas_target_priv_data->deleted = 0;
6706 } else
6707 sas_target_priv_data = NULL;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306708 if (starget)
6709 starget_printk(KERN_INFO, starget,
6710 "handle(0x%04x), sas_addr(0x%016llx), "
6711 "enclosure logical id(0x%016llx), "
6712 "slot(%d)\n", handle,
6713 (unsigned long long)sas_device->sas_address,
6714 (unsigned long long)
6715 sas_device->enclosure_logical_id,
6716 sas_device->slot);
Eric Moore635374e2009-03-09 01:21:12 -06006717 if (sas_device->handle == handle)
6718 goto out;
6719 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6720 sas_device->handle);
6721 sas_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306722 if (sas_target_priv_data)
6723 sas_target_priv_data->handle = handle;
Eric Moore635374e2009-03-09 01:21:12 -06006724 goto out;
6725 }
6726 }
6727 out:
6728 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6729}
6730
6731/**
6732 * _scsih_search_responding_sas_devices -
6733 * @ioc: per adapter object
6734 *
6735 * After host reset, find out whether devices are still responding.
6736 * If not remove.
6737 *
6738 * Return nothing.
6739 */
6740static void
6741_scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6742{
6743 Mpi2SasDevicePage0_t sas_device_pg0;
6744 Mpi2ConfigReply_t mpi_reply;
6745 u16 ioc_status;
6746 __le64 sas_address;
6747 u16 handle;
6748 u32 device_info;
6749 u16 slot;
6750
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306751 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006752
6753 if (list_empty(&ioc->sas_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306754 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006755
6756 handle = 0xFFFF;
6757 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6758 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6759 handle))) {
6760 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6761 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306762 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006763 break;
6764 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6765 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6766 if (!(_scsih_is_end_device(device_info)))
6767 continue;
6768 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6769 slot = le16_to_cpu(sas_device_pg0.Slot);
6770 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6771 handle);
6772 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306773out:
6774 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6775 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006776}
6777
6778/**
6779 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6780 * @ioc: per adapter object
6781 * @wwid: world wide identifier for raid volume
6782 * @handle: device handle
6783 *
6784 * After host reset, find out whether devices are still responding.
6785 * Used in _scsi_remove_unresponsive_raid_devices.
6786 *
6787 * Return nothing.
6788 */
6789static void
6790_scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6791 u16 handle)
6792{
6793 struct MPT2SAS_TARGET *sas_target_priv_data;
6794 struct scsi_target *starget;
6795 struct _raid_device *raid_device;
6796 unsigned long flags;
6797
6798 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6799 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6800 if (raid_device->wwid == wwid && raid_device->starget) {
Kashyap, Desai14695852010-03-30 10:52:44 +05306801 starget = raid_device->starget;
6802 if (starget && starget->hostdata) {
6803 sas_target_priv_data = starget->hostdata;
6804 sas_target_priv_data->deleted = 0;
6805 } else
6806 sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006807 raid_device->responding = 1;
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306808 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06006809 starget_printk(KERN_INFO, raid_device->starget,
6810 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6811 (unsigned long long)raid_device->wwid);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306812 /*
6813 * WARPDRIVE: The handles of the PDs might have changed
6814 * across the host reset so re-initialize the
6815 * required data for Direct IO
6816 */
6817 _scsih_init_warpdrive_properties(ioc, raid_device);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306818 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6819 if (raid_device->handle == handle) {
6820 spin_unlock_irqrestore(&ioc->raid_device_lock,
6821 flags);
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306822 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306823 }
Eric Moore635374e2009-03-09 01:21:12 -06006824 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6825 raid_device->handle);
6826 raid_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306827 if (sas_target_priv_data)
6828 sas_target_priv_data->handle = handle;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306829 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306830 return;
Eric Moore635374e2009-03-09 01:21:12 -06006831 }
6832 }
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306833
Eric Moore635374e2009-03-09 01:21:12 -06006834 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6835}
6836
6837/**
6838 * _scsih_search_responding_raid_devices -
6839 * @ioc: per adapter object
6840 *
6841 * After host reset, find out whether devices are still responding.
6842 * If not remove.
6843 *
6844 * Return nothing.
6845 */
6846static void
6847_scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6848{
6849 Mpi2RaidVolPage1_t volume_pg1;
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306850 Mpi2RaidVolPage0_t volume_pg0;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306851 Mpi2RaidPhysDiskPage0_t pd_pg0;
Eric Moore635374e2009-03-09 01:21:12 -06006852 Mpi2ConfigReply_t mpi_reply;
6853 u16 ioc_status;
6854 u16 handle;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306855 u8 phys_disk_num;
Eric Moore635374e2009-03-09 01:21:12 -06006856
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306857 if (!ioc->ir_firmware)
6858 return;
6859
6860 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6861 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006862
6863 if (list_empty(&ioc->raid_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306864 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006865
6866 handle = 0xFFFF;
6867 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6868 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6869 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6870 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306871 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006872 break;
6873 handle = le16_to_cpu(volume_pg1.DevHandle);
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306874
6875 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6876 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6877 sizeof(Mpi2RaidVolPage0_t)))
6878 continue;
6879
6880 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6881 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6882 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6883 _scsih_mark_responding_raid_device(ioc,
6884 le64_to_cpu(volume_pg1.WWID), handle);
Eric Moore635374e2009-03-09 01:21:12 -06006885 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306886
6887 /* refresh the pd_handles */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306888 if (!ioc->is_warpdrive) {
6889 phys_disk_num = 0xFF;
6890 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6891 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6892 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6893 phys_disk_num))) {
6894 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6895 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306896 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306897 break;
6898 phys_disk_num = pd_pg0.PhysDiskNum;
6899 handle = le16_to_cpu(pd_pg0.DevHandle);
6900 set_bit(handle, ioc->pd_handles);
6901 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306902 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306903out:
6904 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6905 "complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006906}
6907
6908/**
6909 * _scsih_mark_responding_expander - mark a expander as responding
6910 * @ioc: per adapter object
6911 * @sas_address: sas address
6912 * @handle:
6913 *
6914 * After host reset, find out whether devices are still responding.
6915 * Used in _scsi_remove_unresponsive_expanders.
6916 *
6917 * Return nothing.
6918 */
6919static void
6920_scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6921 u16 handle)
6922{
6923 struct _sas_node *sas_expander;
6924 unsigned long flags;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306925 int i;
Eric Moore635374e2009-03-09 01:21:12 -06006926
6927 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6928 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306929 if (sas_expander->sas_address != sas_address)
6930 continue;
6931 sas_expander->responding = 1;
6932 if (sas_expander->handle == handle)
Eric Moore635374e2009-03-09 01:21:12 -06006933 goto out;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306934 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6935 " from(0x%04x) to (0x%04x)!!!\n",
6936 (unsigned long long)sas_expander->sas_address,
6937 sas_expander->handle, handle);
6938 sas_expander->handle = handle;
6939 for (i = 0 ; i < sas_expander->num_phys ; i++)
6940 sas_expander->phy[i].handle = handle;
6941 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006942 }
6943 out:
6944 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6945}
6946
6947/**
6948 * _scsih_search_responding_expanders -
6949 * @ioc: per adapter object
6950 *
6951 * After host reset, find out whether devices are still responding.
6952 * If not remove.
6953 *
6954 * Return nothing.
6955 */
6956static void
6957_scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6958{
6959 Mpi2ExpanderPage0_t expander_pg0;
6960 Mpi2ConfigReply_t mpi_reply;
6961 u16 ioc_status;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05306962 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006963 u16 handle;
6964
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306965 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006966
6967 if (list_empty(&ioc->sas_expander_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306968 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006969
6970 handle = 0xFFFF;
6971 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6972 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6973
6974 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6975 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306976 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006977 break;
6978
6979 handle = le16_to_cpu(expander_pg0.DevHandle);
6980 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6981 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6982 "sas_addr(0x%016llx)\n", handle,
6983 (unsigned long long)sas_address);
6984 _scsih_mark_responding_expander(ioc, sas_address, handle);
6985 }
6986
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306987 out:
6988 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006989}
6990
6991/**
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05306992 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
Eric Moore635374e2009-03-09 01:21:12 -06006993 * @ioc: per adapter object
6994 *
6995 * Return nothing.
6996 */
6997static void
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05306998_scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06006999{
7000 struct _sas_device *sas_device, *sas_device_next;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307001 struct _sas_node *sas_expander, *sas_expander_next;
Eric Moore635374e2009-03-09 01:21:12 -06007002 struct _raid_device *raid_device, *raid_device_next;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307003 struct list_head tmp_list;
7004 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06007005
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307006 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
7007 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06007008
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307009 /* removing unresponding end devices */
7010 printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n",
7011 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06007012 list_for_each_entry_safe(sas_device, sas_device_next,
7013 &ioc->sas_device_list, list) {
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307014 if (!sas_device->responding)
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05307015 mpt2sas_device_remove_by_sas_address(ioc,
7016 sas_device->sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307017 else
Eric Moore635374e2009-03-09 01:21:12 -06007018 sas_device->responding = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007019 }
7020
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307021 /* removing unresponding volumes */
7022 if (ioc->ir_firmware) {
7023 printk(MPT2SAS_INFO_FMT "removing unresponding devices: "
7024 "volumes\n", ioc->name);
7025 list_for_each_entry_safe(raid_device, raid_device_next,
7026 &ioc->raid_device_list, list) {
7027 if (!raid_device->responding)
7028 _scsih_sas_volume_delete(ioc,
7029 raid_device->handle);
7030 else
7031 raid_device->responding = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007032 }
Eric Moore635374e2009-03-09 01:21:12 -06007033 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307034 /* removing unresponding expanders */
7035 printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n",
7036 ioc->name);
7037 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7038 INIT_LIST_HEAD(&tmp_list);
7039 list_for_each_entry_safe(sas_expander, sas_expander_next,
7040 &ioc->sas_expander_list, list) {
7041 if (!sas_expander->responding)
7042 list_move_tail(&sas_expander->list, &tmp_list);
7043 else
Eric Moore635374e2009-03-09 01:21:12 -06007044 sas_expander->responding = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307045 }
7046 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7047 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7048 list) {
7049 list_del(&sas_expander->list);
7050 _scsih_expander_node_remove(ioc, sas_expander);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307051 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307052 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
7053 ioc->name);
7054 /* unblock devices */
7055 _scsih_ublock_io_all_device(ioc);
7056}
7057
7058static void
7059_scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
7060 struct _sas_node *sas_expander, u16 handle)
7061{
7062 Mpi2ExpanderPage1_t expander_pg1;
7063 Mpi2ConfigReply_t mpi_reply;
7064 int i;
7065
7066 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7067 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
7068 &expander_pg1, i, handle))) {
7069 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7070 ioc->name, __FILE__, __LINE__, __func__);
7071 return;
7072 }
7073
7074 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
7075 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7076 expander_pg1.NegotiatedLinkRate >> 4);
7077 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307078}
7079
7080/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307081 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307082 * @ioc: per adapter object
7083 *
7084 * Return nothing.
7085 */
7086static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307087_scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307088{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307089 Mpi2ExpanderPage0_t expander_pg0;
7090 Mpi2SasDevicePage0_t sas_device_pg0;
7091 Mpi2RaidVolPage1_t volume_pg1;
7092 Mpi2RaidVolPage0_t volume_pg0;
7093 Mpi2RaidPhysDiskPage0_t pd_pg0;
7094 Mpi2EventIrConfigElement_t element;
7095 Mpi2ConfigReply_t mpi_reply;
7096 u8 phys_disk_num;
7097 u16 ioc_status;
7098 u16 handle, parent_handle;
7099 u64 sas_address;
7100 struct _sas_device *sas_device;
7101 struct _sas_node *expander_device;
7102 static struct _raid_device *raid_device;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307103 u8 retry_count;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307104 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307105
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307106 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307107
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307108 _scsih_sas_host_refresh(ioc);
7109
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307110 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n",
7111 ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307112 /* expanders */
7113 handle = 0xFFFF;
7114 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7115 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7116 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7117 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307118 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7119 printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: "
7120 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7121 ioc->name, ioc_status,
7122 le32_to_cpu(mpi_reply.IOCLogInfo));
7123 break;
7124 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307125 handle = le16_to_cpu(expander_pg0.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307126 spin_lock_irqsave(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307127 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7128 ioc, le64_to_cpu(expander_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307129 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307130 if (expander_device)
7131 _scsih_refresh_expander_links(ioc, expander_device,
7132 handle);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307133 else {
7134 printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: "
7135 "handle (0x%04x), sas_addr(0x%016llx)\n",
7136 ioc->name, handle, (unsigned long long)
7137 le64_to_cpu(expander_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307138 _scsih_expander_add(ioc, handle);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307139 printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: "
7140 "handle (0x%04x), sas_addr(0x%016llx)\n",
7141 ioc->name, handle, (unsigned long long)
7142 le64_to_cpu(expander_pg0.SASAddress));
7143 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307144 }
7145
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307146 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n",
7147 ioc->name);
7148
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307149 if (!ioc->ir_firmware)
7150 goto skip_to_sas;
7151
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307152 printk(MPT2SAS_INFO_FMT "\tscan devices phys disk start\n", ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307153 /* phys disk */
7154 phys_disk_num = 0xFF;
7155 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7156 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7157 phys_disk_num))) {
7158 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7159 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307160 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7161 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:"
7162 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7163 ioc->name, ioc_status,
7164 le32_to_cpu(mpi_reply.IOCLogInfo));
7165 break;
7166 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307167 phys_disk_num = pd_pg0.PhysDiskNum;
7168 handle = le16_to_cpu(pd_pg0.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307169 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307170 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307171 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307172 if (sas_device)
7173 continue;
7174 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7175 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7176 handle) != 0)
7177 continue;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307178 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7179 MPI2_IOCSTATUS_MASK;
7180 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7181 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan "
7182 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7183 ioc->name, ioc_status,
7184 le32_to_cpu(mpi_reply.IOCLogInfo));
7185 break;
7186 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307187 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7188 if (!_scsih_get_sas_address(ioc, parent_handle,
7189 &sas_address)) {
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307190 printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: "
7191 " handle (0x%04x), sas_addr(0x%016llx)\n",
7192 ioc->name, handle, (unsigned long long)
7193 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307194 mpt2sas_transport_update_links(ioc, sas_address,
7195 handle, sas_device_pg0.PhyNum,
7196 MPI2_SAS_NEG_LINK_RATE_1_5);
7197 set_bit(handle, ioc->pd_handles);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307198 retry_count = 0;
7199 /* This will retry adding the end device.
7200 * _scsih_add_device() will decide on retries and
7201 * return "1" when it should be retried
7202 */
7203 while (_scsih_add_device(ioc, handle, retry_count++,
7204 1)) {
7205 ssleep(1);
7206 }
7207 printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: "
7208 " handle (0x%04x), sas_addr(0x%016llx)\n",
7209 ioc->name, handle, (unsigned long long)
7210 le64_to_cpu(sas_device_pg0.SASAddress));
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307211 }
7212 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307213
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307214 printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n",
7215 ioc->name);
7216
7217 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes start\n", ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307218 /* volumes */
7219 handle = 0xFFFF;
7220 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7221 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7222 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7223 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307224 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7225 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7226 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7227 ioc->name, ioc_status,
7228 le32_to_cpu(mpi_reply.IOCLogInfo));
7229 break;
7230 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307231 handle = le16_to_cpu(volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307232 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307233 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7234 le64_to_cpu(volume_pg1.WWID));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307235 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307236 if (raid_device)
7237 continue;
7238 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7239 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7240 sizeof(Mpi2RaidVolPage0_t)))
7241 continue;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307242 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7243 MPI2_IOCSTATUS_MASK;
7244 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7245 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7246 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7247 ioc->name, ioc_status,
7248 le32_to_cpu(mpi_reply.IOCLogInfo));
7249 break;
7250 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307251 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7252 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7253 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7254 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7255 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7256 element.VolDevHandle = volume_pg1.DevHandle;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307257 printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: "
7258 " handle (0x%04x)\n", ioc->name,
7259 volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307260 _scsih_sas_volume_add(ioc, &element);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307261 printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: "
7262 " handle (0x%04x)\n", ioc->name,
7263 volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307264 }
7265 }
7266
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307267 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n",
7268 ioc->name);
7269
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307270 skip_to_sas:
7271
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307272 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n",
7273 ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307274 /* sas devices */
7275 handle = 0xFFFF;
7276 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7277 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7278 handle))) {
7279 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7280 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307281 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7282 printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:"
7283 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7284 ioc->name, ioc_status,
7285 le32_to_cpu(mpi_reply.IOCLogInfo));
7286 break;
7287 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307288 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7289 if (!(_scsih_is_end_device(
7290 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7291 continue;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307292 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307293 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7294 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307295 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307296 if (sas_device)
7297 continue;
7298 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7299 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307300 printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: "
7301 "handle (0x%04x), sas_addr(0x%016llx)\n",
7302 ioc->name, handle, (unsigned long long)
7303 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307304 mpt2sas_transport_update_links(ioc, sas_address, handle,
7305 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307306 retry_count = 0;
7307 /* This will retry adding the end device.
7308 * _scsih_add_device() will decide on retries and
7309 * return "1" when it should be retried
7310 */
7311 while (_scsih_add_device(ioc, handle, retry_count++,
7312 0)) {
7313 ssleep(1);
7314 }
7315 printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: "
7316 "handle (0x%04x), sas_addr(0x%016llx)\n",
7317 ioc->name, handle, (unsigned long long)
7318 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307319 }
7320 }
7321
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307322 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n",
7323 ioc->name);
7324
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307325 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307326}
7327
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307328
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307329/**
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307330 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7331 * @ioc: per adapter object
7332 * @reset_phase: phase
7333 *
7334 * The handler for doing any required cleanup or initialization.
7335 *
7336 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7337 * MPT2_IOC_DONE_RESET
7338 *
7339 * Return nothing.
7340 */
7341void
7342mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7343{
7344 switch (reset_phase) {
7345 case MPT2_IOC_PRE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307346 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307347 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307348 break;
7349 case MPT2_IOC_AFTER_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307350 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307351 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307352 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7353 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7354 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7355 complete(&ioc->scsih_cmds.done);
7356 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307357 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7358 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7359 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7360 complete(&ioc->tm_cmds.done);
7361 }
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307362 _scsih_fw_event_cleanup_queue(ioc);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307363 _scsih_flush_running_cmds(ioc);
7364 break;
7365 case MPT2_IOC_DONE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307366 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307367 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307368 _scsih_sas_host_refresh(ioc);
Kashyap, Desai14695852010-03-30 10:52:44 +05307369 _scsih_prep_device_scan(ioc);
7370 _scsih_search_responding_sas_devices(ioc);
7371 _scsih_search_responding_raid_devices(ioc);
7372 _scsih_search_responding_expanders(ioc);
sreekanth.reddy@lsi.com14aa7f72012-07-17 15:56:13 +05307373 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7374 !ioc->sas_hba.num_phys)) {
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307375 _scsih_prep_device_scan(ioc);
7376 _scsih_search_responding_sas_devices(ioc);
7377 _scsih_search_responding_raid_devices(ioc);
7378 _scsih_search_responding_expanders(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307379 _scsih_error_recovery_delete_devices(ioc);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307380 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307381 break;
Eric Moore635374e2009-03-09 01:21:12 -06007382 }
7383}
7384
7385/**
7386 * _firmware_event_work - delayed task for processing firmware events
7387 * @ioc: per adapter object
7388 * @work: equal to the fw_event_work object
7389 * Context: user.
7390 *
7391 * Return nothing.
7392 */
7393static void
7394_firmware_event_work(struct work_struct *work)
7395{
7396 struct fw_event_work *fw_event = container_of(work,
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307397 struct fw_event_work, delayed_work.work);
Eric Moore635374e2009-03-09 01:21:12 -06007398 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7399
Eric Moore635374e2009-03-09 01:21:12 -06007400 /* the queue is being flushed so ignore this event */
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05307401 if (ioc->remove_host ||
Eric Moore3cb54692010-07-08 14:44:34 -06007402 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06007403 _scsih_fw_event_free(ioc, fw_event);
7404 return;
7405 }
Eric Moore635374e2009-03-09 01:21:12 -06007406
Eric Moore635374e2009-03-09 01:21:12 -06007407 switch (fw_event->event) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307408 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307409 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307410 ssleep(1);
7411 _scsih_remove_unresponding_sas_devices(ioc);
7412 _scsih_scan_for_devices_after_reset(ioc);
7413 break;
7414 case MPT2SAS_PORT_ENABLE_COMPLETE:
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307415 ioc->start_scan = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307416
Reddy, Sreekanthb0df96a02013-02-26 16:59:59 +05307417 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7418 mpt2sas_base_update_missing_delay(ioc, missing_delay[0],
7419 missing_delay[1]);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307420
7421 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7422 "from worker thread\n", ioc->name));
7423 break;
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05307424 case MPT2SAS_TURN_ON_PFA_LED:
7425 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05307426 break;
Eric Moore635374e2009-03-09 01:21:12 -06007427 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307428 _scsih_sas_topology_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007429 break;
7430 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307431 _scsih_sas_device_status_change_event(ioc,
7432 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007433 break;
7434 case MPI2_EVENT_SAS_DISCOVERY:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307435 _scsih_sas_discovery_event(ioc,
7436 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007437 break;
7438 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
Andrew Mortona78e21d2012-02-08 12:52:22 -08007439 _scsih_sas_broadcast_primitive_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307440 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007441 break;
7442 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7443 _scsih_sas_enclosure_dev_status_change_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307444 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007445 break;
7446 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307447 _scsih_sas_ir_config_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007448 break;
7449 case MPI2_EVENT_IR_VOLUME:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307450 _scsih_sas_ir_volume_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007451 break;
7452 case MPI2_EVENT_IR_PHYSICAL_DISK:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307453 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007454 break;
7455 case MPI2_EVENT_IR_OPERATION_STATUS:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307456 _scsih_sas_ir_operation_status_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007457 break;
Eric Moore635374e2009-03-09 01:21:12 -06007458 }
7459 _scsih_fw_event_free(ioc, fw_event);
7460}
7461
7462/**
7463 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7464 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307465 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06007466 * @reply: reply message frame(lower 32bit addr)
7467 * Context: interrupt.
7468 *
7469 * This function merely adds a new work task into ioc->firmware_event_thread.
7470 * The tasks are worked from _firmware_event_work in user context.
7471 *
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307472 * Returns void.
Eric Moore635374e2009-03-09 01:21:12 -06007473 */
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307474void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307475mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7476 u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06007477{
7478 struct fw_event_work *fw_event;
7479 Mpi2EventNotificationReply_t *mpi_reply;
Eric Moore635374e2009-03-09 01:21:12 -06007480 u16 event;
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307481 u16 sz;
Eric Moore635374e2009-03-09 01:21:12 -06007482
7483 /* events turned off due to host reset or driver unloading */
Eric Moore3cb54692010-07-08 14:44:34 -06007484 if (ioc->remove_host || ioc->pci_error_recovery)
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307485 return;
Eric Moore635374e2009-03-09 01:21:12 -06007486
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307487 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05307488
7489 if (unlikely(!mpi_reply)) {
7490 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7491 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307492 return;
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05307493 }
7494
Eric Moore635374e2009-03-09 01:21:12 -06007495 event = le16_to_cpu(mpi_reply->Event);
7496
7497 switch (event) {
7498 /* handle these */
7499 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7500 {
7501 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7502 (Mpi2EventDataSasBroadcastPrimitive_t *)
7503 mpi_reply->EventData;
7504
7505 if (baen_data->Primitive !=
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307506 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307507 return;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307508
7509 if (ioc->broadcast_aen_busy) {
7510 ioc->broadcast_aen_pending++;
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307511 return;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307512 } else
7513 ioc->broadcast_aen_busy = 1;
Eric Moore635374e2009-03-09 01:21:12 -06007514 break;
7515 }
7516
7517 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7518 _scsih_check_topo_delete_events(ioc,
7519 (Mpi2EventDataSasTopologyChangeList_t *)
7520 mpi_reply->EventData);
7521 break;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05307522 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7523 _scsih_check_ir_config_unhide_events(ioc,
7524 (Mpi2EventDataIrConfigChangeList_t *)
7525 mpi_reply->EventData);
7526 break;
7527 case MPI2_EVENT_IR_VOLUME:
7528 _scsih_check_volume_delete_events(ioc,
7529 (Mpi2EventDataIrVolume_t *)
7530 mpi_reply->EventData);
7531 break;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307532 case MPI2_EVENT_LOG_ENTRY_ADDED:
7533 {
7534 Mpi2EventDataLogEntryAdded_t *log_entry;
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05307535 __le32 *log_code;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307536
7537 if (!ioc->is_warpdrive)
7538 break;
7539
7540 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7541 mpi_reply->EventData;
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05307542 log_code = (__le32 *)log_entry->LogData;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307543
7544 if (le16_to_cpu(log_entry->LogEntryQualifier)
7545 != MPT2_WARPDRIVE_LOGENTRY)
7546 break;
7547
7548 switch (le32_to_cpu(*log_code)) {
7549 case MPT2_WARPDRIVE_LC_SSDT:
7550 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7551 "IO Throttling has occurred in the WarpDrive "
7552 "subsystem. Check WarpDrive documentation for "
7553 "additional details.\n", ioc->name);
7554 break;
7555 case MPT2_WARPDRIVE_LC_SSDLW:
7556 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7557 "Program/Erase Cycles for the WarpDrive subsystem "
7558 "in degraded range. Check WarpDrive documentation "
7559 "for additional details.\n", ioc->name);
7560 break;
7561 case MPT2_WARPDRIVE_LC_SSDLF:
7562 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7563 "There are no Program/Erase Cycles for the "
7564 "WarpDrive subsystem. The storage device will be "
7565 "in read-only mode. Check WarpDrive documentation "
7566 "for additional details.\n", ioc->name);
7567 break;
7568 case MPT2_WARPDRIVE_LC_BRMF:
7569 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7570 "The Backup Rail Monitor has failed on the "
7571 "WarpDrive subsystem. Check WarpDrive "
7572 "documentation for additional details.\n",
7573 ioc->name);
7574 break;
7575 }
7576
7577 break;
7578 }
Eric Moore635374e2009-03-09 01:21:12 -06007579 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7580 case MPI2_EVENT_IR_OPERATION_STATUS:
7581 case MPI2_EVENT_SAS_DISCOVERY:
7582 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
Eric Moore635374e2009-03-09 01:21:12 -06007583 case MPI2_EVENT_IR_PHYSICAL_DISK:
Eric Moore635374e2009-03-09 01:21:12 -06007584 break;
7585
7586 default: /* ignore the rest */
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307587 return;
Eric Moore635374e2009-03-09 01:21:12 -06007588 }
7589
Joe Lawrence00713ad2014-06-25 17:03:33 -04007590 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7591 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06007592 if (!fw_event) {
7593 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7594 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307595 return;
Eric Moore635374e2009-03-09 01:21:12 -06007596 }
Eric Moore635374e2009-03-09 01:21:12 -06007597
Joe Lawrence00713ad2014-06-25 17:03:33 -04007598 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
Eric Moore635374e2009-03-09 01:21:12 -06007599 fw_event->ioc = ioc;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307600 fw_event->VF_ID = mpi_reply->VF_ID;
7601 fw_event->VP_ID = mpi_reply->VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -06007602 fw_event->event = event;
7603 _scsih_fw_event_add(ioc, fw_event);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307604 return;
Eric Moore635374e2009-03-09 01:21:12 -06007605}
7606
7607/* shost template */
7608static struct scsi_host_template scsih_driver_template = {
7609 .module = THIS_MODULE,
7610 .name = "Fusion MPT SAS Host",
7611 .proc_name = MPT2SAS_DRIVER_NAME,
Eric Moored5d135b2009-05-18 13:02:08 -06007612 .queuecommand = _scsih_qcmd,
7613 .target_alloc = _scsih_target_alloc,
7614 .slave_alloc = _scsih_slave_alloc,
7615 .slave_configure = _scsih_slave_configure,
7616 .target_destroy = _scsih_target_destroy,
7617 .slave_destroy = _scsih_slave_destroy,
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307618 .scan_finished = _scsih_scan_finished,
7619 .scan_start = _scsih_scan_start,
Eric Moored5d135b2009-05-18 13:02:08 -06007620 .change_queue_depth = _scsih_change_queue_depth,
Christoph Hellwiga62182f2014-10-02 14:39:55 +02007621 .change_queue_type = scsi_change_queue_type,
Eric Moored5d135b2009-05-18 13:02:08 -06007622 .eh_abort_handler = _scsih_abort,
7623 .eh_device_reset_handler = _scsih_dev_reset,
7624 .eh_target_reset_handler = _scsih_target_reset,
7625 .eh_host_reset_handler = _scsih_host_reset,
7626 .bios_param = _scsih_bios_param,
Eric Moore635374e2009-03-09 01:21:12 -06007627 .can_queue = 1,
7628 .this_id = -1,
7629 .sg_tablesize = MPT2SAS_SG_DEPTH,
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05307630 .max_sectors = 32767,
Eric Moore635374e2009-03-09 01:21:12 -06007631 .cmd_per_lun = 7,
7632 .use_clustering = ENABLE_CLUSTERING,
7633 .shost_attrs = mpt2sas_host_attrs,
7634 .sdev_attrs = mpt2sas_dev_attrs,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +01007635 .track_queue_depth = 1,
Eric Moore635374e2009-03-09 01:21:12 -06007636};
7637
7638/**
7639 * _scsih_expander_node_remove - removing expander device from list.
7640 * @ioc: per adapter object
7641 * @sas_expander: the sas_device object
7642 * Context: Calling function should acquire ioc->sas_node_lock.
7643 *
7644 * Removing object and freeing associated memory from the
7645 * ioc->sas_expander_list.
7646 *
7647 * Return nothing.
7648 */
7649static void
7650_scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7651 struct _sas_node *sas_expander)
7652{
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307653 struct _sas_port *mpt2sas_port, *next;
Eric Moore635374e2009-03-09 01:21:12 -06007654
7655 /* remove sibling ports attached to this expander */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307656 list_for_each_entry_safe(mpt2sas_port, next,
Eric Moore635374e2009-03-09 01:21:12 -06007657 &sas_expander->sas_port_list, port_list) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307658 if (ioc->shost_recovery)
7659 return;
Eric Moore635374e2009-03-09 01:21:12 -06007660 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307661 SAS_END_DEVICE)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307662 mpt2sas_device_remove_by_sas_address(ioc,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307663 mpt2sas_port->remote_identify.sas_address);
7664 else if (mpt2sas_port->remote_identify.device_type ==
7665 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06007666 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307667 SAS_FANOUT_EXPANDER_DEVICE)
7668 mpt2sas_expander_remove(ioc,
7669 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007670 }
7671
7672 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307673 sas_expander->sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06007674
7675 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7676 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7677 sas_expander->handle, (unsigned long long)
7678 sas_expander->sas_address);
7679
Eric Moore635374e2009-03-09 01:21:12 -06007680 kfree(sas_expander->phy);
7681 kfree(sas_expander);
7682}
7683
7684/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05307685 * _scsih_ir_shutdown - IR shutdown notification
7686 * @ioc: per adapter object
7687 *
7688 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7689 * the host system is shutting down.
7690 *
7691 * Return nothing.
7692 */
7693static void
7694_scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7695{
7696 Mpi2RaidActionRequest_t *mpi_request;
7697 Mpi2RaidActionReply_t *mpi_reply;
7698 u16 smid;
7699
7700 /* is IR firmware build loaded ? */
7701 if (!ioc->ir_firmware)
7702 return;
7703
Kashyap, Desai744090d2009-10-05 15:56:56 +05307704 mutex_lock(&ioc->scsih_cmds.mutex);
7705
7706 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7707 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7708 ioc->name, __func__);
7709 goto out;
7710 }
7711 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7712
7713 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7714 if (!smid) {
7715 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7716 ioc->name, __func__);
7717 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7718 goto out;
7719 }
7720
7721 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7722 ioc->scsih_cmds.smid = smid;
7723 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7724
7725 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7726 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7727
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307728 if (!ioc->hide_ir_msg)
7729 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307730 init_completion(&ioc->scsih_cmds.done);
7731 mpt2sas_base_put_smid_default(ioc, smid);
7732 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7733
7734 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7735 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7736 ioc->name, __func__);
7737 goto out;
7738 }
7739
7740 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7741 mpi_reply = ioc->scsih_cmds.reply;
7742
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307743 if (!ioc->hide_ir_msg)
7744 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7745 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7746 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7747 le32_to_cpu(mpi_reply->IOCLogInfo));
Kashyap, Desai744090d2009-10-05 15:56:56 +05307748 }
7749
7750 out:
7751 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7752 mutex_unlock(&ioc->scsih_cmds.mutex);
7753}
7754
7755/**
7756 * _scsih_shutdown - routine call during system shutdown
7757 * @pdev: PCI device struct
7758 *
7759 * Return nothing.
7760 */
7761static void
7762_scsih_shutdown(struct pci_dev *pdev)
7763{
7764 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7765 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307766 struct workqueue_struct *wq;
7767 unsigned long flags;
7768
7769 ioc->remove_host = 1;
7770 _scsih_fw_event_cleanup_queue(ioc);
7771
7772 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7773 wq = ioc->firmware_event_thread;
7774 ioc->firmware_event_thread = NULL;
7775 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7776 if (wq)
7777 destroy_workqueue(wq);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307778
7779 _scsih_ir_shutdown(ioc);
7780 mpt2sas_base_detach(ioc);
7781}
7782
7783/**
Eric Moored5d135b2009-05-18 13:02:08 -06007784 * _scsih_remove - detach and remove add host
Eric Moore635374e2009-03-09 01:21:12 -06007785 * @pdev: PCI device struct
7786 *
Kashyap, Desai744090d2009-10-05 15:56:56 +05307787 * Routine called when unloading the driver.
Eric Moore635374e2009-03-09 01:21:12 -06007788 * Return nothing.
7789 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08007790static void
Eric Moored5d135b2009-05-18 13:02:08 -06007791_scsih_remove(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06007792{
7793 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7794 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307795 struct _sas_port *mpt2sas_port, *next_port;
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307796 struct _raid_device *raid_device, *next;
7797 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06007798 struct workqueue_struct *wq;
7799 unsigned long flags;
7800
7801 ioc->remove_host = 1;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307802 _scsih_fw_event_cleanup_queue(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007803
7804 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7805 wq = ioc->firmware_event_thread;
7806 ioc->firmware_event_thread = NULL;
7807 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7808 if (wq)
7809 destroy_workqueue(wq);
7810
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307811 /* release all the volumes */
Kashyap, Desai3a9c9132011-01-04 11:40:23 +05307812 _scsih_ir_shutdown(ioc);
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307813 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7814 list) {
7815 if (raid_device->starget) {
7816 sas_target_priv_data =
7817 raid_device->starget->hostdata;
7818 sas_target_priv_data->deleted = 1;
7819 scsi_remove_target(&raid_device->starget->dev);
7820 }
7821 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7822 "(0x%016llx)\n", ioc->name, raid_device->handle,
7823 (unsigned long long) raid_device->wwid);
7824 _scsih_raid_device_remove(ioc, raid_device);
7825 }
7826
Eric Moore635374e2009-03-09 01:21:12 -06007827 /* free ports attached to the sas_host */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307828 list_for_each_entry_safe(mpt2sas_port, next_port,
Eric Moore635374e2009-03-09 01:21:12 -06007829 &ioc->sas_hba.sas_port_list, port_list) {
7830 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307831 SAS_END_DEVICE)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307832 mpt2sas_device_remove_by_sas_address(ioc,
Eric Moore635374e2009-03-09 01:21:12 -06007833 mpt2sas_port->remote_identify.sas_address);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307834 else if (mpt2sas_port->remote_identify.device_type ==
7835 SAS_EDGE_EXPANDER_DEVICE ||
7836 mpt2sas_port->remote_identify.device_type ==
7837 SAS_FANOUT_EXPANDER_DEVICE)
7838 mpt2sas_expander_remove(ioc,
7839 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007840 }
7841
7842 /* free phys attached to the sas_host */
7843 if (ioc->sas_hba.num_phys) {
7844 kfree(ioc->sas_hba.phy);
7845 ioc->sas_hba.phy = NULL;
7846 ioc->sas_hba.num_phys = 0;
7847 }
7848
7849 sas_remove_host(shost);
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05307850 scsi_remove_host(shost);
kashyap.desai@lsi.com9ae89b02011-08-04 16:47:50 +05307851 mpt2sas_base_detach(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007852 list_del(&ioc->list);
Eric Moore635374e2009-03-09 01:21:12 -06007853 scsi_host_put(shost);
7854}
7855
7856/**
7857 * _scsih_probe_boot_devices - reports 1st device
7858 * @ioc: per adapter object
7859 *
7860 * If specified in bios page 2, this routine reports the 1st
7861 * device scsi-ml or sas transport for persistent boot device
7862 * purposes. Please refer to function _scsih_determine_boot_device()
7863 */
7864static void
7865_scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7866{
7867 u8 is_raid;
7868 void *device;
7869 struct _sas_device *sas_device;
7870 struct _raid_device *raid_device;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307871 u16 handle;
7872 u64 sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007873 u64 sas_address;
7874 unsigned long flags;
7875 int rc;
7876
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307877 /* no Bios, return immediately */
7878 if (!ioc->bios_pg3.BiosVersion)
7879 return;
7880
Eric Moore635374e2009-03-09 01:21:12 -06007881 device = NULL;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307882 is_raid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007883 if (ioc->req_boot_device.device) {
7884 device = ioc->req_boot_device.device;
7885 is_raid = ioc->req_boot_device.is_raid;
7886 } else if (ioc->req_alt_boot_device.device) {
7887 device = ioc->req_alt_boot_device.device;
7888 is_raid = ioc->req_alt_boot_device.is_raid;
7889 } else if (ioc->current_boot_device.device) {
7890 device = ioc->current_boot_device.device;
7891 is_raid = ioc->current_boot_device.is_raid;
7892 }
7893
7894 if (!device)
7895 return;
7896
7897 if (is_raid) {
7898 raid_device = device;
7899 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7900 raid_device->id, 0);
7901 if (rc)
7902 _scsih_raid_device_remove(ioc, raid_device);
7903 } else {
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307904 spin_lock_irqsave(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06007905 sas_device = device;
7906 handle = sas_device->handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307907 sas_address_parent = sas_device->sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007908 sas_address = sas_device->sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06007909 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7910 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307911
7912 if (ioc->hide_drives)
7913 return;
Eric Moore635374e2009-03-09 01:21:12 -06007914 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307915 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -06007916 _scsih_sas_device_remove(ioc, sas_device);
7917 } else if (!sas_device->starget) {
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307918 if (!ioc->is_driver_loading) {
7919 mpt2sas_transport_port_remove(ioc,
7920 sas_address,
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05307921 sas_address_parent);
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307922 _scsih_sas_device_remove(ioc, sas_device);
7923 }
Eric Moore635374e2009-03-09 01:21:12 -06007924 }
7925 }
7926}
7927
7928/**
7929 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7930 * @ioc: per adapter object
7931 *
7932 * Called during initial loading of the driver.
7933 */
7934static void
7935_scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7936{
7937 struct _raid_device *raid_device, *raid_next;
7938 int rc;
7939
7940 list_for_each_entry_safe(raid_device, raid_next,
7941 &ioc->raid_device_list, list) {
7942 if (raid_device->starget)
7943 continue;
7944 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7945 raid_device->id, 0);
7946 if (rc)
7947 _scsih_raid_device_remove(ioc, raid_device);
7948 }
7949}
7950
7951/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307952 * _scsih_probe_sas - reporting sas devices to sas transport
Eric Moore635374e2009-03-09 01:21:12 -06007953 * @ioc: per adapter object
7954 *
7955 * Called during initial loading of the driver.
7956 */
7957static void
7958_scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7959{
7960 struct _sas_device *sas_device, *next;
7961 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06007962
7963 /* SAS Device List */
7964 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7965 list) {
Eric Moore635374e2009-03-09 01:21:12 -06007966
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307967 if (ioc->hide_drives)
7968 continue;
7969
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307970 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7971 sas_device->sas_address_parent)) {
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307972 list_del(&sas_device->list);
7973 kfree(sas_device);
7974 continue;
Eric Moore635374e2009-03-09 01:21:12 -06007975 } else if (!sas_device->starget) {
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307976 if (!ioc->is_driver_loading) {
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05307977 mpt2sas_transport_port_remove(ioc,
7978 sas_device->sas_address,
7979 sas_device->sas_address_parent);
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307980 list_del(&sas_device->list);
7981 kfree(sas_device);
7982 continue;
7983 }
Eric Moore635374e2009-03-09 01:21:12 -06007984 }
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307985 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7986 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7987 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06007988 }
7989}
7990
7991/**
7992 * _scsih_probe_devices - probing for devices
7993 * @ioc: per adapter object
7994 *
7995 * Called during initial loading of the driver.
7996 */
7997static void
7998_scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7999{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308000 u16 volume_mapping_flags;
Eric Moore635374e2009-03-09 01:21:12 -06008001
8002 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8003 return; /* return when IOC doesn't support initiator mode */
8004
8005 _scsih_probe_boot_devices(ioc);
8006
8007 if (ioc->ir_firmware) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308008 volume_mapping_flags =
8009 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8010 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8011 if (volume_mapping_flags ==
8012 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
Eric Moore635374e2009-03-09 01:21:12 -06008013 _scsih_probe_raid(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308014 _scsih_probe_sas(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008015 } else {
Eric Moore635374e2009-03-09 01:21:12 -06008016 _scsih_probe_sas(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308017 _scsih_probe_raid(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008018 }
8019 } else
8020 _scsih_probe_sas(ioc);
8021}
8022
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308023
8024/**
8025 * _scsih_scan_start - scsi lld callback for .scan_start
8026 * @shost: SCSI host pointer
8027 *
8028 * The shost has the ability to discover targets on its own instead
8029 * of scanning the entire bus. In our implemention, we will kick off
8030 * firmware discovery.
8031 */
8032static void
8033_scsih_scan_start(struct Scsi_Host *shost)
8034{
8035 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8036 int rc;
8037
8038 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8039 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
8040
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05308041 if (disable_discovery > 0)
8042 return;
8043
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308044 ioc->start_scan = 1;
8045 rc = mpt2sas_port_enable(ioc);
8046
8047 if (rc != 0)
8048 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
8049}
8050
8051/**
8052 * _scsih_scan_finished - scsi lld callback for .scan_finished
8053 * @shost: SCSI host pointer
8054 * @time: elapsed time of the scan in jiffies
8055 *
8056 * This function will be called periodically until it returns 1 with the
8057 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8058 * we wait for firmware discovery to complete, then return 1.
8059 */
8060static int
8061_scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8062{
8063 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8064
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05308065 if (disable_discovery > 0) {
8066 ioc->is_driver_loading = 0;
8067 ioc->wait_for_discovery_to_complete = 0;
8068 return 1;
8069 }
8070
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308071 if (time >= (300 * HZ)) {
8072 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8073 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
8074 "(timeout=300s)\n", ioc->name);
8075 ioc->is_driver_loading = 0;
8076 return 1;
8077 }
8078
8079 if (ioc->start_scan)
8080 return 0;
8081
8082 if (ioc->start_scan_failed) {
8083 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
8084 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
8085 ioc->is_driver_loading = 0;
8086 ioc->wait_for_discovery_to_complete = 0;
8087 ioc->remove_host = 1;
8088 return 1;
8089 }
8090
8091 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
8092 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8093
8094 if (ioc->wait_for_discovery_to_complete) {
8095 ioc->wait_for_discovery_to_complete = 0;
8096 _scsih_probe_devices(ioc);
8097 }
8098 mpt2sas_base_start_watchdog(ioc);
8099 ioc->is_driver_loading = 0;
8100 return 1;
8101}
8102
8103
Eric Moore635374e2009-03-09 01:21:12 -06008104/**
Eric Moored5d135b2009-05-18 13:02:08 -06008105 * _scsih_probe - attach and add scsi host
Eric Moore635374e2009-03-09 01:21:12 -06008106 * @pdev: PCI device struct
8107 * @id: pci device id
8108 *
8109 * Returns 0 success, anything else error.
8110 */
8111static int
Eric Moored5d135b2009-05-18 13:02:08 -06008112_scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
Eric Moore635374e2009-03-09 01:21:12 -06008113{
8114 struct MPT2SAS_ADAPTER *ioc;
8115 struct Scsi_Host *shost;
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308116 int rv;
Eric Moore635374e2009-03-09 01:21:12 -06008117
8118 shost = scsi_host_alloc(&scsih_driver_template,
8119 sizeof(struct MPT2SAS_ADAPTER));
8120 if (!shost)
8121 return -ENODEV;
8122
8123 /* init local params */
8124 ioc = shost_priv(shost);
8125 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
8126 INIT_LIST_HEAD(&ioc->list);
Eric Mooreba33fad2009-03-15 21:37:18 -06008127 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
Eric Moore635374e2009-03-09 01:21:12 -06008128 ioc->shost = shost;
8129 ioc->id = mpt_ids++;
8130 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
8131 ioc->pdev = pdev;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308132 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8133 ioc->is_warpdrive = 1;
8134 ioc->hide_ir_msg = 1;
8135 } else
8136 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
Eric Moore635374e2009-03-09 01:21:12 -06008137 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8138 ioc->tm_cb_idx = tm_cb_idx;
8139 ioc->ctl_cb_idx = ctl_cb_idx;
8140 ioc->base_cb_idx = base_cb_idx;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308141 ioc->port_enable_cb_idx = port_enable_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008142 ioc->transport_cb_idx = transport_cb_idx;
Kashyap, Desai744090d2009-10-05 15:56:56 +05308143 ioc->scsih_cb_idx = scsih_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008144 ioc->config_cb_idx = config_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308145 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308146 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308147 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008148 ioc->logging_level = logging_level;
nagalakshmi.nandigama@lsi.com845a0e42011-12-01 07:42:04 +05308149 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
Eric Moore635374e2009-03-09 01:21:12 -06008150 /* misc semaphores and spin locks */
Kashyap, Desaid2742132010-06-17 13:28:55 +05308151 mutex_init(&ioc->reset_in_progress_mutex);
Eric Moore635374e2009-03-09 01:21:12 -06008152 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8153 spin_lock_init(&ioc->scsi_lookup_lock);
8154 spin_lock_init(&ioc->sas_device_lock);
8155 spin_lock_init(&ioc->sas_node_lock);
8156 spin_lock_init(&ioc->fw_event_lock);
8157 spin_lock_init(&ioc->raid_device_lock);
8158
8159 INIT_LIST_HEAD(&ioc->sas_device_list);
8160 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8161 INIT_LIST_HEAD(&ioc->sas_expander_list);
8162 INIT_LIST_HEAD(&ioc->fw_event_list);
8163 INIT_LIST_HEAD(&ioc->raid_device_list);
8164 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308165 INIT_LIST_HEAD(&ioc->delayed_tr_list);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308166 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
Joe Lawrence3b3e6f82013-08-08 16:45:38 -04008167 INIT_LIST_HEAD(&ioc->reply_queue_list);
Eric Moore635374e2009-03-09 01:21:12 -06008168
8169 /* init shost parameters */
Eric Moored334aa72010-04-22 10:47:40 -06008170 shost->max_cmd_len = 32;
Eric Moore635374e2009-03-09 01:21:12 -06008171 shost->max_lun = max_lun;
8172 shost->transportt = mpt2sas_transport_template;
8173 shost->unique_id = ioc->id;
8174
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308175 if (max_sectors != 0xFFFF) {
8176 if (max_sectors < 64) {
8177 shost->max_sectors = 64;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05308178 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8179 "for max_sectors, range is 64 to 32767. Assigning "
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308180 "value of 64.\n", ioc->name, max_sectors);
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05308181 } else if (max_sectors > 32767) {
8182 shost->max_sectors = 32767;
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308183 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8184 "for max_sectors, range is 64 to 8192. Assigning "
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05308185 "default value of 32767.\n", ioc->name,
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308186 max_sectors);
8187 } else {
8188 shost->max_sectors = max_sectors & 0xFFFE;
8189 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
8190 "set to %d\n", ioc->name, shost->max_sectors);
8191 }
8192 }
8193
Martin K. Petersen5e95e732012-08-28 14:29:37 -04008194 /* register EEDP capabilities with SCSI layer */
8195 if (prot_mask)
8196 scsi_host_set_prot(shost, prot_mask);
8197 else
8198 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8199 | SHOST_DIF_TYPE2_PROTECTION
8200 | SHOST_DIF_TYPE3_PROTECTION);
8201
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308202 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
Eric Moore3c621b32009-05-18 12:59:41 -06008203
Eric Moore635374e2009-03-09 01:21:12 -06008204 /* event thread */
8205 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8206 "fw_event%d", ioc->id);
8207 ioc->firmware_event_thread = create_singlethread_workqueue(
8208 ioc->firmware_event_name);
8209 if (!ioc->firmware_event_thread) {
8210 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8211 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308212 rv = -ENODEV;
Eric Moore635374e2009-03-09 01:21:12 -06008213 goto out_thread_fail;
8214 }
8215
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308216 ioc->is_driver_loading = 1;
Eric Moore635374e2009-03-09 01:21:12 -06008217 if ((mpt2sas_base_attach(ioc))) {
8218 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8219 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308220 rv = -ENODEV;
Eric Moore635374e2009-03-09 01:21:12 -06008221 goto out_attach_fail;
8222 }
8223
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308224 if (ioc->is_warpdrive) {
8225 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8226 ioc->hide_drives = 0;
8227 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8228 ioc->hide_drives = 1;
8229 else {
8230 if (_scsih_get_num_volumes(ioc))
8231 ioc->hide_drives = 1;
8232 else
8233 ioc->hide_drives = 0;
8234 }
8235 } else
8236 ioc->hide_drives = 0;
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05308237
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308238 rv = scsi_add_host(shost, &pdev->dev);
8239 if (rv) {
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05308240 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8241 ioc->name, __FILE__, __LINE__, __func__);
8242 goto out_add_shost_fail;
8243 }
8244
nagalakshmi.nandigama@lsi.com2cb6fc82011-12-13 09:29:15 +05308245 scsi_scan_host(shost);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308246
Eric Moore635374e2009-03-09 01:21:12 -06008247 return 0;
8248
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05308249 out_add_shost_fail:
8250 mpt2sas_base_detach(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008251 out_attach_fail:
8252 destroy_workqueue(ioc->firmware_event_thread);
8253 out_thread_fail:
8254 list_del(&ioc->list);
Tomas Henzlf555e052012-04-17 15:24:48 +02008255 scsi_host_put(shost);
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308256 return rv;
Eric Moore635374e2009-03-09 01:21:12 -06008257}
8258
8259#ifdef CONFIG_PM
8260/**
Eric Moored5d135b2009-05-18 13:02:08 -06008261 * _scsih_suspend - power management suspend main entry point
Eric Moore635374e2009-03-09 01:21:12 -06008262 * @pdev: PCI device struct
8263 * @state: PM state change to (usually PCI_D3)
8264 *
8265 * Returns 0 success, anything else error.
8266 */
8267static int
Eric Moored5d135b2009-05-18 13:02:08 -06008268_scsih_suspend(struct pci_dev *pdev, pm_message_t state)
Eric Moore635374e2009-03-09 01:21:12 -06008269{
8270 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8271 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05308272 pci_power_t device_state;
Eric Moore635374e2009-03-09 01:21:12 -06008273
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308274 mpt2sas_base_stop_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008275 scsi_block_requests(shost);
Sreekanth Reddy3627dba2013-07-25 11:25:57 +05308276 _scsih_ir_shutdown(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008277 device_state = pci_choose_state(pdev, state);
8278 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8279 "operating state [D%d]\n", ioc->name, pdev,
8280 pci_name(pdev), device_state);
8281
8282 mpt2sas_base_free_resources(ioc);
8283 pci_save_state(pdev);
Eric Moore635374e2009-03-09 01:21:12 -06008284 pci_set_power_state(pdev, device_state);
8285 return 0;
8286}
8287
8288/**
Eric Moored5d135b2009-05-18 13:02:08 -06008289 * _scsih_resume - power management resume main entry point
Eric Moore635374e2009-03-09 01:21:12 -06008290 * @pdev: PCI device struct
8291 *
8292 * Returns 0 success, anything else error.
8293 */
8294static int
Eric Moored5d135b2009-05-18 13:02:08 -06008295_scsih_resume(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06008296{
8297 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8298 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05308299 pci_power_t device_state = pdev->current_state;
Eric Moore635374e2009-03-09 01:21:12 -06008300 int r;
8301
8302 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8303 "operating state [D%d]\n", ioc->name, pdev,
8304 pci_name(pdev), device_state);
8305
8306 pci_set_power_state(pdev, PCI_D0);
8307 pci_enable_wake(pdev, PCI_D0, 0);
8308 pci_restore_state(pdev);
8309 ioc->pdev = pdev;
8310 r = mpt2sas_base_map_resources(ioc);
8311 if (r)
8312 return r;
8313
8314 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8315 scsi_unblock_requests(shost);
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308316 mpt2sas_base_start_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008317 return 0;
8318}
8319#endif /* CONFIG_PM */
8320
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308321/**
8322 * _scsih_pci_error_detected - Called when a PCI error is detected.
8323 * @pdev: PCI device struct
8324 * @state: PCI channel state
8325 *
8326 * Description: Called when a PCI error is detected.
8327 *
8328 * Return value:
8329 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8330 */
8331static pci_ers_result_t
8332_scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8333{
8334 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8335 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8336
8337 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8338 ioc->name, state);
8339
8340 switch (state) {
8341 case pci_channel_io_normal:
8342 return PCI_ERS_RESULT_CAN_RECOVER;
8343 case pci_channel_io_frozen:
Eric Moore3cb54692010-07-08 14:44:34 -06008344 /* Fatal error, prepare for slot reset */
8345 ioc->pci_error_recovery = 1;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308346 scsi_block_requests(ioc->shost);
8347 mpt2sas_base_stop_watchdog(ioc);
8348 mpt2sas_base_free_resources(ioc);
8349 return PCI_ERS_RESULT_NEED_RESET;
8350 case pci_channel_io_perm_failure:
Eric Moore3cb54692010-07-08 14:44:34 -06008351 /* Permanent error, prepare for device removal */
8352 ioc->pci_error_recovery = 1;
8353 mpt2sas_base_stop_watchdog(ioc);
8354 _scsih_flush_running_cmds(ioc);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308355 return PCI_ERS_RESULT_DISCONNECT;
8356 }
8357 return PCI_ERS_RESULT_NEED_RESET;
8358}
8359
8360/**
8361 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8362 * @pdev: PCI device struct
8363 *
8364 * Description: This routine is called by the pci error recovery
8365 * code after the PCI slot has been reset, just before we
8366 * should resume normal operations.
8367 */
8368static pci_ers_result_t
8369_scsih_pci_slot_reset(struct pci_dev *pdev)
8370{
8371 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8372 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8373 int rc;
8374
8375 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8376 ioc->name);
8377
Eric Moore3cb54692010-07-08 14:44:34 -06008378 ioc->pci_error_recovery = 0;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308379 ioc->pdev = pdev;
Eric Moore3cb54692010-07-08 14:44:34 -06008380 pci_restore_state(pdev);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308381 rc = mpt2sas_base_map_resources(ioc);
8382 if (rc)
8383 return PCI_ERS_RESULT_DISCONNECT;
8384
8385
8386 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8387 FORCE_BIG_HAMMER);
8388
8389 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8390 (rc == 0) ? "success" : "failed");
8391
8392 if (!rc)
8393 return PCI_ERS_RESULT_RECOVERED;
8394 else
8395 return PCI_ERS_RESULT_DISCONNECT;
8396}
8397
8398/**
8399 * _scsih_pci_resume() - resume normal ops after PCI reset
8400 * @pdev: pointer to PCI device
8401 *
8402 * Called when the error recovery driver tells us that its
8403 * OK to resume normal operation. Use completion to allow
8404 * halted scsi ops to resume.
8405 */
8406static void
8407_scsih_pci_resume(struct pci_dev *pdev)
8408{
8409 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8410 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8411
8412 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8413
8414 pci_cleanup_aer_uncorrect_error_status(pdev);
8415 mpt2sas_base_start_watchdog(ioc);
8416 scsi_unblock_requests(ioc->shost);
8417}
8418
8419/**
8420 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8421 * @pdev: pointer to PCI device
8422 */
8423static pci_ers_result_t
8424_scsih_pci_mmio_enabled(struct pci_dev *pdev)
8425{
8426 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8427 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8428
8429 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8430 ioc->name);
8431
8432 /* TODO - dump whatever for debugging purposes */
8433
8434 /* Request a slot reset. */
8435 return PCI_ERS_RESULT_NEED_RESET;
8436}
8437
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07008438static const struct pci_error_handlers _scsih_err_handler = {
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308439 .error_detected = _scsih_pci_error_detected,
8440 .mmio_enabled = _scsih_pci_mmio_enabled,
8441 .slot_reset = _scsih_pci_slot_reset,
8442 .resume = _scsih_pci_resume,
8443};
Eric Moore635374e2009-03-09 01:21:12 -06008444
8445static struct pci_driver scsih_driver = {
8446 .name = MPT2SAS_DRIVER_NAME,
8447 .id_table = scsih_pci_table,
Eric Moored5d135b2009-05-18 13:02:08 -06008448 .probe = _scsih_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008449 .remove = _scsih_remove,
Kashyap, Desai744090d2009-10-05 15:56:56 +05308450 .shutdown = _scsih_shutdown,
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308451 .err_handler = &_scsih_err_handler,
Eric Moore635374e2009-03-09 01:21:12 -06008452#ifdef CONFIG_PM
Eric Moored5d135b2009-05-18 13:02:08 -06008453 .suspend = _scsih_suspend,
8454 .resume = _scsih_resume,
Eric Moore635374e2009-03-09 01:21:12 -06008455#endif
8456};
8457
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308458/* raid transport support */
8459static struct raid_function_template mpt2sas_raid_functions = {
8460 .cookie = &scsih_driver_template,
8461 .is_raid = _scsih_is_raid,
8462 .get_resync = _scsih_get_resync,
8463 .get_state = _scsih_get_state,
8464};
Eric Moore635374e2009-03-09 01:21:12 -06008465
8466/**
Eric Moored5d135b2009-05-18 13:02:08 -06008467 * _scsih_init - main entry point for this driver.
Eric Moore635374e2009-03-09 01:21:12 -06008468 *
8469 * Returns 0 success, anything else error.
8470 */
8471static int __init
Eric Moored5d135b2009-05-18 13:02:08 -06008472_scsih_init(void)
Eric Moore635374e2009-03-09 01:21:12 -06008473{
8474 int error;
8475
8476 mpt_ids = 0;
8477 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8478 MPT2SAS_DRIVER_VERSION);
8479
8480 mpt2sas_transport_template =
8481 sas_attach_transport(&mpt2sas_transport_functions);
8482 if (!mpt2sas_transport_template)
8483 return -ENODEV;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308484 /* raid transport support */
8485 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8486 if (!mpt2sas_raid_template) {
8487 sas_release_transport(mpt2sas_transport_template);
8488 return -ENODEV;
8489 }
Eric Moore635374e2009-03-09 01:21:12 -06008490
8491 mpt2sas_base_initialize_callback_handler();
8492
8493 /* queuecommand callback hander */
Eric Moored5d135b2009-05-18 13:02:08 -06008494 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
Eric Moore635374e2009-03-09 01:21:12 -06008495
Uwe Kleine-König65155b32010-06-11 12:17:01 +02008496 /* task management callback handler */
Eric Moored5d135b2009-05-18 13:02:08 -06008497 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
Eric Moore635374e2009-03-09 01:21:12 -06008498
8499 /* base internal commands callback handler */
8500 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308501 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8502 mpt2sas_port_enable_done);
Eric Moore635374e2009-03-09 01:21:12 -06008503
8504 /* transport internal commands callback handler */
8505 transport_cb_idx = mpt2sas_base_register_callback_handler(
8506 mpt2sas_transport_done);
8507
Kashyap, Desai744090d2009-10-05 15:56:56 +05308508 /* scsih internal commands callback handler */
8509 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8510
Eric Moore635374e2009-03-09 01:21:12 -06008511 /* configuration page API internal commands callback handler */
8512 config_cb_idx = mpt2sas_base_register_callback_handler(
8513 mpt2sas_config_done);
8514
8515 /* ctl module callback handler */
8516 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8517
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308518 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8519 _scsih_tm_tr_complete);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308520
8521 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8522 _scsih_tm_volume_tr_complete);
8523
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308524 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8525 _scsih_sas_control_complete);
8526
Eric Moore635374e2009-03-09 01:21:12 -06008527 mpt2sas_ctl_init();
8528
8529 error = pci_register_driver(&scsih_driver);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308530 if (error) {
8531 /* raid transport support */
8532 raid_class_release(mpt2sas_raid_template);
Eric Moore635374e2009-03-09 01:21:12 -06008533 sas_release_transport(mpt2sas_transport_template);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308534 }
Eric Moore635374e2009-03-09 01:21:12 -06008535
8536 return error;
8537}
8538
8539/**
Eric Moored5d135b2009-05-18 13:02:08 -06008540 * _scsih_exit - exit point for this driver (when it is a module).
Eric Moore635374e2009-03-09 01:21:12 -06008541 *
8542 * Returns 0 success, anything else error.
8543 */
8544static void __exit
Eric Moored5d135b2009-05-18 13:02:08 -06008545_scsih_exit(void)
Eric Moore635374e2009-03-09 01:21:12 -06008546{
8547 printk(KERN_INFO "mpt2sas version %s unloading\n",
8548 MPT2SAS_DRIVER_VERSION);
8549
8550 pci_unregister_driver(&scsih_driver);
8551
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308552 mpt2sas_ctl_exit();
8553
Eric Moore635374e2009-03-09 01:21:12 -06008554 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8555 mpt2sas_base_release_callback_handler(tm_cb_idx);
8556 mpt2sas_base_release_callback_handler(base_cb_idx);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308557 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008558 mpt2sas_base_release_callback_handler(transport_cb_idx);
Kashyap, Desai744090d2009-10-05 15:56:56 +05308559 mpt2sas_base_release_callback_handler(scsih_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008560 mpt2sas_base_release_callback_handler(config_cb_idx);
8561 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8562
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308563 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308564 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308565 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8566
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308567 /* raid transport support */
8568 raid_class_release(mpt2sas_raid_template);
8569 sas_release_transport(mpt2sas_transport_template);
8570
Eric Moore635374e2009-03-09 01:21:12 -06008571}
8572
Eric Moored5d135b2009-05-18 13:02:08 -06008573module_init(_scsih_init);
8574module_exit(_scsih_exit);