blob: 12229de433bfa2999c3d1b35bd0eebf656780793 [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 Hellwigdb5ed4d2014-11-13 15:08:42 +01001225 scsi_change_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
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301232 *
1233 * Returns queue depth.
1234 */
1235static int
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001236_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301237{
Christoph Hellwigc40ecc12014-11-13 14:25:11 +01001238 _scsih_adjust_queue_depth(sdev, qdepth);
Eric Moore635374e2009-03-09 01:21:12 -06001239
1240 if (sdev->inquiry_len > 7)
1241 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
Christoph Hellwig609aa222014-10-30 11:54:58 +01001242 "simple(%d), scsi_level(%d), cmd_que(%d)\n",
Eric Moore635374e2009-03-09 01:21:12 -06001243 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
Christoph Hellwig609aa222014-10-30 11:54:58 +01001244 sdev->scsi_level,
Eric Moore635374e2009-03-09 01:21:12 -06001245 (sdev->inquiry[7] & 2) >> 1);
1246
1247 return sdev->queue_depth;
1248}
1249
1250/**
Eric Moored5d135b2009-05-18 13:02:08 -06001251 * _scsih_target_alloc - target add routine
Eric Moore635374e2009-03-09 01:21:12 -06001252 * @starget: scsi target struct
1253 *
1254 * Returns 0 if ok. Any other return is assumed to be an error and
1255 * the device is ignored.
1256 */
1257static int
Eric Moored5d135b2009-05-18 13:02:08 -06001258_scsih_target_alloc(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001259{
1260 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1261 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1262 struct MPT2SAS_TARGET *sas_target_priv_data;
1263 struct _sas_device *sas_device;
1264 struct _raid_device *raid_device;
1265 unsigned long flags;
1266 struct sas_rphy *rphy;
1267
Joe Lawrencefeafe7c2014-06-25 17:03:14 -04001268 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1269 GFP_KERNEL);
Eric Moore635374e2009-03-09 01:21:12 -06001270 if (!sas_target_priv_data)
1271 return -ENOMEM;
1272
1273 starget->hostdata = sas_target_priv_data;
1274 sas_target_priv_data->starget = starget;
1275 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1276
1277 /* RAID volumes */
1278 if (starget->channel == RAID_CHANNEL) {
1279 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1280 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1281 starget->channel);
1282 if (raid_device) {
1283 sas_target_priv_data->handle = raid_device->handle;
1284 sas_target_priv_data->sas_address = raid_device->wwid;
1285 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301286 if (ioc->is_warpdrive)
1287 sas_target_priv_data->raid_device = raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06001288 raid_device->starget = starget;
1289 }
1290 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1291 return 0;
1292 }
1293
1294 /* sas/sata devices */
1295 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1296 rphy = dev_to_rphy(starget->dev.parent);
1297 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1298 rphy->identify.sas_address);
1299
1300 if (sas_device) {
1301 sas_target_priv_data->handle = sas_device->handle;
1302 sas_target_priv_data->sas_address = sas_device->sas_address;
1303 sas_device->starget = starget;
1304 sas_device->id = starget->id;
1305 sas_device->channel = starget->channel;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05301306 if (test_bit(sas_device->handle, ioc->pd_handles))
Eric Moore635374e2009-03-09 01:21:12 -06001307 sas_target_priv_data->flags |=
1308 MPT_TARGET_FLAGS_RAID_COMPONENT;
1309 }
1310 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1311
1312 return 0;
1313}
1314
1315/**
Eric Moored5d135b2009-05-18 13:02:08 -06001316 * _scsih_target_destroy - target destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001317 * @starget: scsi target struct
1318 *
1319 * Returns nothing.
1320 */
1321static void
Eric Moored5d135b2009-05-18 13:02:08 -06001322_scsih_target_destroy(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001323{
1324 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1325 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1326 struct MPT2SAS_TARGET *sas_target_priv_data;
1327 struct _sas_device *sas_device;
1328 struct _raid_device *raid_device;
1329 unsigned long flags;
1330 struct sas_rphy *rphy;
1331
1332 sas_target_priv_data = starget->hostdata;
1333 if (!sas_target_priv_data)
1334 return;
1335
1336 if (starget->channel == RAID_CHANNEL) {
1337 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1338 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1339 starget->channel);
1340 if (raid_device) {
1341 raid_device->starget = NULL;
1342 raid_device->sdev = NULL;
1343 }
1344 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1345 goto out;
1346 }
1347
1348 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1349 rphy = dev_to_rphy(starget->dev.parent);
1350 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1351 rphy->identify.sas_address);
Eric Moore8901cbb2009-04-21 15:41:32 -06001352 if (sas_device && (sas_device->starget == starget) &&
1353 (sas_device->id == starget->id) &&
1354 (sas_device->channel == starget->channel))
Eric Moore635374e2009-03-09 01:21:12 -06001355 sas_device->starget = NULL;
1356
1357 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1358
1359 out:
1360 kfree(sas_target_priv_data);
1361 starget->hostdata = NULL;
1362}
1363
1364/**
Eric Moored5d135b2009-05-18 13:02:08 -06001365 * _scsih_slave_alloc - device add routine
Eric Moore635374e2009-03-09 01:21:12 -06001366 * @sdev: scsi device struct
1367 *
1368 * Returns 0 if ok. Any other return is assumed to be an error and
1369 * the device is ignored.
1370 */
1371static int
Eric Moored5d135b2009-05-18 13:02:08 -06001372_scsih_slave_alloc(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001373{
1374 struct Scsi_Host *shost;
1375 struct MPT2SAS_ADAPTER *ioc;
1376 struct MPT2SAS_TARGET *sas_target_priv_data;
1377 struct MPT2SAS_DEVICE *sas_device_priv_data;
1378 struct scsi_target *starget;
1379 struct _raid_device *raid_device;
Sreekanth Reddy63e359d2013-07-25 11:32:51 +05301380 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -06001381 unsigned long flags;
1382
Joe Lawrencefeafe7c2014-06-25 17:03:14 -04001383 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1384 GFP_KERNEL);
Eric Moore635374e2009-03-09 01:21:12 -06001385 if (!sas_device_priv_data)
1386 return -ENOMEM;
1387
1388 sas_device_priv_data->lun = sdev->lun;
1389 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1390
1391 starget = scsi_target(sdev);
1392 sas_target_priv_data = starget->hostdata;
1393 sas_target_priv_data->num_luns++;
1394 sas_device_priv_data->sas_target = sas_target_priv_data;
1395 sdev->hostdata = sas_device_priv_data;
1396 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1397 sdev->no_uld_attach = 1;
1398
1399 shost = dev_to_shost(&starget->dev);
1400 ioc = shost_priv(shost);
1401 if (starget->channel == RAID_CHANNEL) {
1402 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1403 raid_device = _scsih_raid_device_find_by_id(ioc,
1404 starget->id, starget->channel);
1405 if (raid_device)
1406 raid_device->sdev = sdev; /* raid is single lun */
1407 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06001408 }
1409
Sreekanth Reddy63e359d2013-07-25 11:32:51 +05301410 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1411 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1412 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1413 sas_target_priv_data->sas_address);
1414 if (sas_device && (sas_device->starget == NULL)) {
1415 sdev_printk(KERN_INFO, sdev,
1416 "%s : sas_device->starget set to starget @ %d\n",
1417 __func__, __LINE__);
1418 sas_device->starget = starget;
1419 }
1420 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1421 }
1422
Eric Moore635374e2009-03-09 01:21:12 -06001423 return 0;
1424}
1425
1426/**
Eric Moored5d135b2009-05-18 13:02:08 -06001427 * _scsih_slave_destroy - device destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001428 * @sdev: scsi device struct
1429 *
1430 * Returns nothing.
1431 */
1432static void
Eric Moored5d135b2009-05-18 13:02:08 -06001433_scsih_slave_destroy(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001434{
1435 struct MPT2SAS_TARGET *sas_target_priv_data;
1436 struct scsi_target *starget;
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301437 struct Scsi_Host *shost;
1438 struct MPT2SAS_ADAPTER *ioc;
1439 struct _sas_device *sas_device;
1440 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001441
1442 if (!sdev->hostdata)
1443 return;
1444
1445 starget = scsi_target(sdev);
1446 sas_target_priv_data = starget->hostdata;
1447 sas_target_priv_data->num_luns--;
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301448
1449 shost = dev_to_shost(&starget->dev);
1450 ioc = shost_priv(shost);
1451
1452 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1453 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1454 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1455 sas_target_priv_data->sas_address);
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +05301456 if (sas_device && !sas_target_priv_data->num_luns)
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301457 sas_device->starget = NULL;
1458 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1459 }
1460
Eric Moore635374e2009-03-09 01:21:12 -06001461 kfree(sdev->hostdata);
1462 sdev->hostdata = NULL;
1463}
1464
1465/**
Eric Moored5d135b2009-05-18 13:02:08 -06001466 * _scsih_display_sata_capabilities - sata capabilities
Eric Moore635374e2009-03-09 01:21:12 -06001467 * @ioc: per adapter object
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301468 * @handle: device handle
Eric Moore635374e2009-03-09 01:21:12 -06001469 * @sdev: scsi device struct
1470 */
1471static void
Eric Moored5d135b2009-05-18 13:02:08 -06001472_scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301473 u16 handle, struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001474{
1475 Mpi2ConfigReply_t mpi_reply;
1476 Mpi2SasDevicePage0_t sas_device_pg0;
1477 u32 ioc_status;
1478 u16 flags;
1479 u32 device_info;
1480
1481 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301482 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06001483 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1484 ioc->name, __FILE__, __LINE__, __func__);
1485 return;
1486 }
1487
1488 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1489 MPI2_IOCSTATUS_MASK;
1490 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1491 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1492 ioc->name, __FILE__, __LINE__, __func__);
1493 return;
1494 }
1495
1496 flags = le16_to_cpu(sas_device_pg0.Flags);
Kashyap, Desaie94f6742010-03-17 16:24:52 +05301497 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
Eric Moore635374e2009-03-09 01:21:12 -06001498
1499 sdev_printk(KERN_INFO, sdev,
1500 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1501 "sw_preserve(%s)\n",
1502 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1503 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1504 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1505 "n",
1506 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1507 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1508 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1509}
1510
1511/**
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301512 * _scsih_is_raid - return boolean indicating device is raid volume
1513 * @dev the device struct object
1514 */
1515static int
1516_scsih_is_raid(struct device *dev)
1517{
1518 struct scsi_device *sdev = to_scsi_device(dev);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301519 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301520
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301521 if (ioc->is_warpdrive)
1522 return 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301523 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1524}
1525
1526/**
1527 * _scsih_get_resync - get raid volume resync percent complete
1528 * @dev the device struct object
1529 */
1530static void
1531_scsih_get_resync(struct device *dev)
1532{
1533 struct scsi_device *sdev = to_scsi_device(dev);
1534 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1535 static struct _raid_device *raid_device;
1536 unsigned long flags;
1537 Mpi2RaidVolPage0_t vol_pg0;
1538 Mpi2ConfigReply_t mpi_reply;
1539 u32 volume_status_flags;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301540 u8 percent_complete;
1541 u16 handle;
1542
1543 percent_complete = 0;
1544 handle = 0;
1545 if (ioc->is_warpdrive)
1546 goto out;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301547
1548 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1549 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1550 sdev->channel);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301551 if (raid_device) {
1552 handle = raid_device->handle;
1553 percent_complete = raid_device->percent_complete;
1554 }
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301555 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1556
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301557 if (!handle)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301558 goto out;
1559
1560 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301561 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301562 sizeof(Mpi2RaidVolPage0_t))) {
1563 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1564 ioc->name, __FILE__, __LINE__, __func__);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301565 percent_complete = 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301566 goto out;
1567 }
1568
1569 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301570 if (!(volume_status_flags &
1571 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1572 percent_complete = 0;
1573
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301574 out:
1575 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1576}
1577
1578/**
1579 * _scsih_get_state - get raid volume level
1580 * @dev the device struct object
1581 */
1582static void
1583_scsih_get_state(struct device *dev)
1584{
1585 struct scsi_device *sdev = to_scsi_device(dev);
1586 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1587 static struct _raid_device *raid_device;
1588 unsigned long flags;
1589 Mpi2RaidVolPage0_t vol_pg0;
1590 Mpi2ConfigReply_t mpi_reply;
1591 u32 volstate;
1592 enum raid_state state = RAID_STATE_UNKNOWN;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301593 u16 handle = 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301594
1595 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1596 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1597 sdev->channel);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301598 if (raid_device)
1599 handle = raid_device->handle;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301600 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1601
1602 if (!raid_device)
1603 goto out;
1604
1605 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301606 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301607 sizeof(Mpi2RaidVolPage0_t))) {
1608 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1609 ioc->name, __FILE__, __LINE__, __func__);
1610 goto out;
1611 }
1612
1613 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1614 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1615 state = RAID_STATE_RESYNCING;
1616 goto out;
1617 }
1618
1619 switch (vol_pg0.VolumeState) {
1620 case MPI2_RAID_VOL_STATE_OPTIMAL:
1621 case MPI2_RAID_VOL_STATE_ONLINE:
1622 state = RAID_STATE_ACTIVE;
1623 break;
1624 case MPI2_RAID_VOL_STATE_DEGRADED:
1625 state = RAID_STATE_DEGRADED;
1626 break;
1627 case MPI2_RAID_VOL_STATE_FAILED:
1628 case MPI2_RAID_VOL_STATE_MISSING:
1629 state = RAID_STATE_OFFLINE;
1630 break;
1631 }
1632 out:
1633 raid_set_state(mpt2sas_raid_template, dev, state);
1634}
1635
1636/**
1637 * _scsih_set_level - set raid level
1638 * @sdev: scsi device struct
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301639 * @volume_type: volume type
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301640 */
1641static void
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301642_scsih_set_level(struct scsi_device *sdev, u8 volume_type)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301643{
1644 enum raid_level level = RAID_LEVEL_UNKNOWN;
1645
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301646 switch (volume_type) {
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301647 case MPI2_RAID_VOL_TYPE_RAID0:
1648 level = RAID_LEVEL_0;
1649 break;
1650 case MPI2_RAID_VOL_TYPE_RAID10:
1651 level = RAID_LEVEL_10;
1652 break;
1653 case MPI2_RAID_VOL_TYPE_RAID1E:
1654 level = RAID_LEVEL_1E;
1655 break;
1656 case MPI2_RAID_VOL_TYPE_RAID1:
1657 level = RAID_LEVEL_1;
1658 break;
1659 }
1660
1661 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1662}
1663
1664/**
Eric Moore635374e2009-03-09 01:21:12 -06001665 * _scsih_get_volume_capabilities - volume capabilities
1666 * @ioc: per adapter object
1667 * @sas_device: the raid_device object
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301668 *
1669 * Returns 0 for success, else 1
Eric Moore635374e2009-03-09 01:21:12 -06001670 */
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301671static int
Eric Moore635374e2009-03-09 01:21:12 -06001672_scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1673 struct _raid_device *raid_device)
1674{
1675 Mpi2RaidVolPage0_t *vol_pg0;
1676 Mpi2RaidPhysDiskPage0_t pd_pg0;
1677 Mpi2SasDevicePage0_t sas_device_pg0;
1678 Mpi2ConfigReply_t mpi_reply;
1679 u16 sz;
1680 u8 num_pds;
1681
1682 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1683 &num_pds)) || !num_pds) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301684 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1685 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1686 __func__));
1687 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001688 }
1689
1690 raid_device->num_pds = num_pds;
1691 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1692 sizeof(Mpi2RaidVol0PhysDisk_t));
1693 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1694 if (!vol_pg0) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301695 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1696 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1697 __func__));
1698 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001699 }
1700
1701 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1702 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301703 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1704 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1705 __func__));
Eric Moore635374e2009-03-09 01:21:12 -06001706 kfree(vol_pg0);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301707 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001708 }
1709
1710 raid_device->volume_type = vol_pg0->VolumeType;
1711
1712 /* figure out what the underlying devices are by
1713 * obtaining the device_info bits for the 1st device
1714 */
1715 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1716 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1717 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1718 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1719 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1720 le16_to_cpu(pd_pg0.DevHandle)))) {
1721 raid_device->device_info =
1722 le32_to_cpu(sas_device_pg0.DeviceInfo);
1723 }
1724 }
1725
1726 kfree(vol_pg0);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301727 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06001728}
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301729/**
1730 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1731 * @ioc: per adapter object
1732 */
1733static void
1734_scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1735{
1736 Mpi2RaidVolPage1_t vol_pg1;
1737 Mpi2ConfigReply_t mpi_reply;
1738 struct _raid_device *raid_device;
1739 u16 handle;
1740 u16 ioc_status;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301741 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301742
1743 handle = 0xFFFF;
1744 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1745 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1746 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1747 MPI2_IOCSTATUS_MASK;
1748 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1749 break;
1750 handle = le16_to_cpu(vol_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301751 spin_lock_irqsave(&ioc->raid_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301752 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1753 if (raid_device)
1754 raid_device->direct_io_enabled = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301755 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301756 }
1757 return;
1758}
1759
1760
1761/**
1762 * _scsih_get_num_volumes - Get number of volumes in the ioc
1763 * @ioc: per adapter object
1764 */
1765static u8
1766_scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1767{
1768 Mpi2RaidVolPage1_t vol_pg1;
1769 Mpi2ConfigReply_t mpi_reply;
1770 u16 handle;
1771 u8 vol_cnt = 0;
1772 u16 ioc_status;
1773
1774 handle = 0xFFFF;
1775 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1776 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1777 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1778 MPI2_IOCSTATUS_MASK;
1779 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1780 break;
1781 vol_cnt++;
1782 handle = le16_to_cpu(vol_pg1.DevHandle);
1783 }
1784 return vol_cnt;
1785}
1786
1787
1788/**
1789 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1790 * @ioc: per adapter object
1791 * @raid_device: the raid_device object
1792 */
1793static void
1794_scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1795 struct _raid_device *raid_device)
1796{
1797 Mpi2RaidVolPage0_t *vol_pg0;
1798 Mpi2RaidPhysDiskPage0_t pd_pg0;
1799 Mpi2ConfigReply_t mpi_reply;
1800 u16 sz;
1801 u8 num_pds, count;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301802 unsigned long stripe_sz, block_sz;
1803 u8 stripe_exp, block_exp;
1804 u64 dev_max_lba;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301805
1806 if (!ioc->is_warpdrive)
1807 return;
1808
1809 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1810 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1811 "globally as drives are exposed\n", ioc->name);
1812 return;
1813 }
1814 if (_scsih_get_num_volumes(ioc) > 1) {
1815 _scsih_disable_ddio(ioc);
1816 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1817 "globally as number of drives > 1\n", ioc->name);
1818 return;
1819 }
1820 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1821 &num_pds)) || !num_pds) {
1822 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1823 "Failure in computing number of drives\n", ioc->name);
1824 return;
1825 }
1826
1827 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1828 sizeof(Mpi2RaidVol0PhysDisk_t));
1829 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1830 if (!vol_pg0) {
1831 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1832 "Memory allocation failure for RVPG0\n", ioc->name);
1833 return;
1834 }
1835
1836 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1837 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1838 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1839 "Failure in retrieving RVPG0\n", ioc->name);
1840 kfree(vol_pg0);
1841 return;
1842 }
1843
1844 /*
1845 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1846 * assumed for WARPDRIVE, disable direct I/O
1847 */
1848 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1849 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1850 "for the drive with handle(0x%04x): num_mem=%d, "
1851 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1852 num_pds, MPT_MAX_WARPDRIVE_PDS);
1853 kfree(vol_pg0);
1854 return;
1855 }
1856 for (count = 0; count < num_pds; count++) {
1857 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1858 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1859 vol_pg0->PhysDisk[count].PhysDiskNum) ||
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05301860 le16_to_cpu(pd_pg0.DevHandle) ==
1861 MPT2SAS_INVALID_DEVICE_HANDLE) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301862 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1863 "disabled for the drive with handle(0x%04x) member"
1864 "handle retrieval failed for member number=%d\n",
1865 ioc->name, raid_device->handle,
1866 vol_pg0->PhysDisk[count].PhysDiskNum);
1867 goto out_error;
1868 }
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301869 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1870 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
1871 if (dev_max_lba >> 32) {
1872 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1873 "disabled for the drive with handle(0x%04x) member"
1874 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1875 ioc->name, raid_device->handle,
1876 le16_to_cpu(pd_pg0.DevHandle),
1877 (unsigned long long)dev_max_lba);
1878 goto out_error;
1879 }
1880
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301881 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1882 }
1883
1884 /*
1885 * Assumption for WD: Direct I/O is not supported if the volume is
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301886 * not RAID0
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301887 */
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301888 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301889 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1890 "for the drive with handle(0x%04x): type=%d, "
1891 "s_sz=%uK, blk_size=%u\n", ioc->name,
1892 raid_device->handle, raid_device->volume_type,
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301893 (le32_to_cpu(vol_pg0->StripeSize) *
1894 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301895 le16_to_cpu(vol_pg0->BlockSize));
1896 goto out_error;
1897 }
1898
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301899 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301900 stripe_exp = find_first_bit(&stripe_sz, 32);
1901 if (stripe_exp == 32) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301902 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301903 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301904 ioc->name, raid_device->handle,
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301905 (le32_to_cpu(vol_pg0->StripeSize) *
1906 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301907 goto out_error;
1908 }
1909 raid_device->stripe_exponent = stripe_exp;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301910 block_sz = le16_to_cpu(vol_pg0->BlockSize);
1911 block_exp = find_first_bit(&block_sz, 16);
1912 if (block_exp == 16) {
1913 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1914 "for the drive with handle(0x%04x) invalid block sz %u\n",
1915 ioc->name, raid_device->handle,
1916 le16_to_cpu(vol_pg0->BlockSize));
1917 goto out_error;
1918 }
1919 raid_device->block_exponent = block_exp;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301920 raid_device->direct_io_enabled = 1;
1921
1922 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1923 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1924 /*
1925 * WARPDRIVE: Though the following fields are not used for direct IO,
1926 * stored for future purpose:
1927 */
1928 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1929 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1930 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1931
1932
1933 kfree(vol_pg0);
1934 return;
1935
1936out_error:
1937 raid_device->direct_io_enabled = 0;
1938 for (count = 0; count < num_pds; count++)
1939 raid_device->pd_handle[count] = 0;
1940 kfree(vol_pg0);
1941 return;
1942}
Eric Moore635374e2009-03-09 01:21:12 -06001943
1944/**
Kashyap, Desai84f0b042009-12-16 18:56:28 +05301945 * _scsih_enable_tlr - setting TLR flags
1946 * @ioc: per adapter object
1947 * @sdev: scsi device struct
1948 *
1949 * Enabling Transaction Layer Retries for tape devices when
1950 * vpd page 0x90 is present
1951 *
1952 */
1953static void
1954_scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1955{
1956 /* only for TAPE */
1957 if (sdev->type != TYPE_TAPE)
1958 return;
1959
1960 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1961 return;
1962
1963 sas_enable_tlr(sdev);
1964 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1965 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1966 return;
1967
1968}
1969
1970/**
Eric Moored5d135b2009-05-18 13:02:08 -06001971 * _scsih_slave_configure - device configure routine.
Eric Moore635374e2009-03-09 01:21:12 -06001972 * @sdev: scsi device struct
1973 *
1974 * Returns 0 if ok. Any other return is assumed to be an error and
1975 * the device is ignored.
1976 */
1977static int
Eric Moored5d135b2009-05-18 13:02:08 -06001978_scsih_slave_configure(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001979{
1980 struct Scsi_Host *shost = sdev->host;
1981 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1982 struct MPT2SAS_DEVICE *sas_device_priv_data;
1983 struct MPT2SAS_TARGET *sas_target_priv_data;
1984 struct _sas_device *sas_device;
1985 struct _raid_device *raid_device;
1986 unsigned long flags;
1987 int qdepth;
1988 u8 ssp_target = 0;
1989 char *ds = "";
1990 char *r_level = "";
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301991 u16 handle, volume_handle = 0;
1992 u64 volume_wwid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06001993
1994 qdepth = 1;
1995 sas_device_priv_data = sdev->hostdata;
1996 sas_device_priv_data->configured_lun = 1;
1997 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1998 sas_target_priv_data = sas_device_priv_data->sas_target;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301999 handle = sas_target_priv_data->handle;
Eric Moore635374e2009-03-09 01:21:12 -06002000
2001 /* raid volume handling */
2002 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2003
2004 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302005 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06002006 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2007 if (!raid_device) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302008 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2009 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2010 __LINE__, __func__));
2011 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002012 }
2013
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302014 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2015 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2016 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2017 __LINE__, __func__));
2018 return 1;
2019 }
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302020 /*
2021 * WARPDRIVE: Initialize the required data for Direct IO
2022 */
2023 _scsih_init_warpdrive_properties(ioc, raid_device);
2024
Eric Moore635374e2009-03-09 01:21:12 -06002025 /* RAID Queue Depth Support
2026 * IS volume = underlying qdepth of drive type, either
2027 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2028 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2029 */
2030 if (raid_device->device_info &
2031 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2032 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2033 ds = "SSP";
2034 } else {
2035 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2036 if (raid_device->device_info &
2037 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2038 ds = "SATA";
2039 else
2040 ds = "STP";
2041 }
2042
2043 switch (raid_device->volume_type) {
2044 case MPI2_RAID_VOL_TYPE_RAID0:
2045 r_level = "RAID0";
2046 break;
2047 case MPI2_RAID_VOL_TYPE_RAID1E:
2048 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
Kashyap, Desaied79f122009-08-20 13:23:49 +05302049 if (ioc->manu_pg10.OEMIdentifier &&
Kashyap, Desaic97951e2011-06-14 10:54:56 +05302050 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
Kashyap, Desaied79f122009-08-20 13:23:49 +05302051 MFG10_GF0_R10_DISPLAY) &&
2052 !(raid_device->num_pds % 2))
2053 r_level = "RAID10";
2054 else
2055 r_level = "RAID1E";
Eric Moore635374e2009-03-09 01:21:12 -06002056 break;
2057 case MPI2_RAID_VOL_TYPE_RAID1:
2058 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2059 r_level = "RAID1";
2060 break;
2061 case MPI2_RAID_VOL_TYPE_RAID10:
2062 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2063 r_level = "RAID10";
2064 break;
2065 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2066 default:
2067 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2068 r_level = "RAIDX";
2069 break;
2070 }
2071
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302072 if (!ioc->hide_ir_msg)
2073 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2074 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2075 r_level, raid_device->handle,
2076 (unsigned long long)raid_device->wwid,
2077 raid_device->num_pds, ds);
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01002078 _scsih_change_queue_depth(sdev, qdepth);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05302079 /* raid transport support */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302080 if (!ioc->is_warpdrive)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302081 _scsih_set_level(sdev, raid_device->volume_type);
Eric Moore635374e2009-03-09 01:21:12 -06002082 return 0;
2083 }
2084
2085 /* non-raid handling */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302086 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2087 if (mpt2sas_config_get_volume_handle(ioc, handle,
2088 &volume_handle)) {
2089 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2090 "failure at %s:%d/%s()!\n", ioc->name,
2091 __FILE__, __LINE__, __func__));
2092 return 1;
2093 }
2094 if (volume_handle && mpt2sas_config_get_volume_wwid(ioc,
2095 volume_handle, &volume_wwid)) {
2096 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2097 "failure at %s:%d/%s()!\n", ioc->name,
2098 __FILE__, __LINE__, __func__));
2099 return 1;
2100 }
2101 }
2102
Eric Moore635374e2009-03-09 01:21:12 -06002103 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2104 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2105 sas_device_priv_data->sas_target->sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302106 if (!sas_device) {
2107 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302108 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302109 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2110 __LINE__, __func__));
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302111 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002112 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302113 sas_device->volume_handle = volume_handle;
2114 sas_device->volume_wwid = volume_wwid;
2115 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2116 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2117 ssp_target = 1;
2118 ds = "SSP";
2119 } else {
2120 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2121 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2122 ds = "STP";
2123 else if (sas_device->device_info &
2124 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2125 ds = "SATA";
2126 }
2127 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2128 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2129 ds, sas_device->handle,
2130 (unsigned long long)sas_device->sas_address,
2131 sas_device->phy,
2132 (unsigned long long)sas_device->device_name);
2133 sdev_printk(KERN_INFO, sdev, "%s: "
2134 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2135 (unsigned long long) sas_device->enclosure_logical_id,
2136 sas_device->slot);
2137
2138 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2139 if (!ssp_target)
2140 _scsih_display_sata_capabilities(ioc, handle, sdev);
2141
Eric Moore635374e2009-03-09 01:21:12 -06002142
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01002143 _scsih_change_queue_depth(sdev, qdepth);
Eric Moore635374e2009-03-09 01:21:12 -06002144
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302145 if (ssp_target) {
Eric Moore635374e2009-03-09 01:21:12 -06002146 sas_read_port_mode_page(sdev);
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302147 _scsih_enable_tlr(ioc, sdev);
2148 }
Eric Moore635374e2009-03-09 01:21:12 -06002149 return 0;
2150}
2151
2152/**
Eric Moored5d135b2009-05-18 13:02:08 -06002153 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
Eric Moore635374e2009-03-09 01:21:12 -06002154 * @sdev: scsi device struct
2155 * @bdev: pointer to block device context
2156 * @capacity: device size (in 512 byte sectors)
2157 * @params: three element array to place output:
2158 * params[0] number of heads (max 255)
2159 * params[1] number of sectors (max 63)
2160 * params[2] number of cylinders
2161 *
2162 * Return nothing.
2163 */
2164static int
Eric Moored5d135b2009-05-18 13:02:08 -06002165_scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
Eric Moore635374e2009-03-09 01:21:12 -06002166 sector_t capacity, int params[])
2167{
2168 int heads;
2169 int sectors;
2170 sector_t cylinders;
2171 ulong dummy;
2172
2173 heads = 64;
2174 sectors = 32;
2175
2176 dummy = heads * sectors;
2177 cylinders = capacity;
2178 sector_div(cylinders, dummy);
2179
2180 /*
2181 * Handle extended translation size for logical drives
2182 * > 1Gb
2183 */
2184 if ((ulong)capacity >= 0x200000) {
2185 heads = 255;
2186 sectors = 63;
2187 dummy = heads * sectors;
2188 cylinders = capacity;
2189 sector_div(cylinders, dummy);
2190 }
2191
2192 /* return result */
2193 params[0] = heads;
2194 params[1] = sectors;
2195 params[2] = cylinders;
2196
2197 return 0;
2198}
2199
2200/**
2201 * _scsih_response_code - translation of device response code
2202 * @ioc: per adapter object
2203 * @response_code: response code returned by the device
2204 *
2205 * Return nothing.
2206 */
2207static void
2208_scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2209{
2210 char *desc;
2211
2212 switch (response_code) {
2213 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2214 desc = "task management request completed";
2215 break;
2216 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2217 desc = "invalid frame";
2218 break;
2219 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2220 desc = "task management request not supported";
2221 break;
2222 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2223 desc = "task management request failed";
2224 break;
2225 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2226 desc = "task management request succeeded";
2227 break;
2228 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2229 desc = "invalid lun";
2230 break;
2231 case 0xA:
2232 desc = "overlapped tag attempted";
2233 break;
2234 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2235 desc = "task queued, however not sent to target";
2236 break;
2237 default:
2238 desc = "unknown";
2239 break;
2240 }
2241 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2242 ioc->name, response_code, desc);
2243}
2244
2245/**
Eric Moored5d135b2009-05-18 13:02:08 -06002246 * _scsih_tm_done - tm completion routine
Eric Moore635374e2009-03-09 01:21:12 -06002247 * @ioc: per adapter object
2248 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302249 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002250 * @reply: reply message frame(lower 32bit addr)
2251 * Context: none.
2252 *
2253 * The callback handler when using scsih_issue_tm.
2254 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302255 * Return 1 meaning mf should be freed from _base_interrupt
2256 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06002257 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302258static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302259_scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06002260{
2261 MPI2DefaultReply_t *mpi_reply;
2262
2263 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302264 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002265 if (ioc->tm_cmds.smid != smid)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302266 return 1;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05302267 mpt2sas_base_flush_reply_queues(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06002268 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2269 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2270 if (mpi_reply) {
2271 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2272 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2273 }
2274 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2275 complete(&ioc->tm_cmds.done);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302276 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002277}
2278
2279/**
2280 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2281 * @ioc: per adapter object
2282 * @handle: device handle
2283 *
2284 * During taskmangement request, we need to freeze the device queue.
2285 */
2286void
2287mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2288{
2289 struct MPT2SAS_DEVICE *sas_device_priv_data;
2290 struct scsi_device *sdev;
2291 u8 skip = 0;
2292
2293 shost_for_each_device(sdev, ioc->shost) {
2294 if (skip)
2295 continue;
2296 sas_device_priv_data = sdev->hostdata;
2297 if (!sas_device_priv_data)
2298 continue;
2299 if (sas_device_priv_data->sas_target->handle == handle) {
2300 sas_device_priv_data->sas_target->tm_busy = 1;
2301 skip = 1;
2302 ioc->ignore_loginfos = 1;
2303 }
2304 }
2305}
2306
2307/**
2308 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2309 * @ioc: per adapter object
2310 * @handle: device handle
2311 *
2312 * During taskmangement request, we need to freeze the device queue.
2313 */
2314void
2315mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2316{
2317 struct MPT2SAS_DEVICE *sas_device_priv_data;
2318 struct scsi_device *sdev;
2319 u8 skip = 0;
2320
2321 shost_for_each_device(sdev, ioc->shost) {
2322 if (skip)
2323 continue;
2324 sas_device_priv_data = sdev->hostdata;
2325 if (!sas_device_priv_data)
2326 continue;
2327 if (sas_device_priv_data->sas_target->handle == handle) {
2328 sas_device_priv_data->sas_target->tm_busy = 0;
2329 skip = 1;
2330 ioc->ignore_loginfos = 0;
2331 }
2332 }
2333}
2334
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302335
Eric Moore635374e2009-03-09 01:21:12 -06002336/**
2337 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2338 * @ioc: per adapter struct
2339 * @device_handle: device handle
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302340 * @channel: the channel assigned by the OS
2341 * @id: the id assigned by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002342 * @lun: lun number
2343 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2344 * @smid_task: smid assigned to the task
2345 * @timeout: timeout in seconds
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302346 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302347 * Context: user
Eric Moore635374e2009-03-09 01:21:12 -06002348 *
2349 * A generic API for sending task management requests to firmware.
2350 *
Eric Moore635374e2009-03-09 01:21:12 -06002351 * The callback index is set inside `ioc->tm_cb_idx`.
2352 *
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302353 * Return SUCCESS or FAILED.
Eric Moore635374e2009-03-09 01:21:12 -06002354 */
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302355int
2356mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2357 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002358 enum mutex_type m_type)
Eric Moore635374e2009-03-09 01:21:12 -06002359{
2360 Mpi2SCSITaskManagementRequest_t *mpi_request;
2361 Mpi2SCSITaskManagementReply_t *mpi_reply;
2362 u16 smid = 0;
2363 u32 ioc_state;
2364 unsigned long timeleft;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302365 struct scsiio_tracker *scsi_lookup = NULL;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302366 int rc;
Eric Moore635374e2009-03-09 01:21:12 -06002367
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302368 if (m_type == TM_MUTEX_ON)
2369 mutex_lock(&ioc->tm_cmds.mutex);
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302370 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2371 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2372 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302373 rc = FAILED;
2374 goto err_out;
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302375 }
2376
Eric Moore3cb54692010-07-08 14:44:34 -06002377 if (ioc->shost_recovery || ioc->remove_host ||
2378 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06002379 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2380 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302381 rc = FAILED;
2382 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002383 }
Eric Moore635374e2009-03-09 01:21:12 -06002384
2385 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2386 if (ioc_state & MPI2_DOORBELL_USED) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302387 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
Eric Moore635374e2009-03-09 01:21:12 -06002388 "active!\n", ioc->name));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302389 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302390 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302391 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302392 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002393 }
2394
2395 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2396 mpt2sas_base_fault_info(ioc, ioc_state &
2397 MPI2_DOORBELL_DATA_MASK);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302398 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302399 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302400 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302401 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002402 }
2403
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302404 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06002405 if (!smid) {
2406 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2407 ioc->name, __func__);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302408 rc = FAILED;
2409 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002410 }
2411
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302412 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2413 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2414
Eric Moore635374e2009-03-09 01:21:12 -06002415 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302416 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2417 smid_task));
Eric Moore635374e2009-03-09 01:21:12 -06002418 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2419 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2420 ioc->tm_cmds.smid = smid;
2421 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302422 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
Eric Moore635374e2009-03-09 01:21:12 -06002423 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2424 mpi_request->DevHandle = cpu_to_le16(handle);
2425 mpi_request->TaskType = type;
2426 mpi_request->TaskMID = cpu_to_le16(smid_task);
2427 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2428 mpt2sas_scsih_set_tm_flag(ioc, handle);
Kashyap, Desai5b768582009-08-20 13:24:31 +05302429 init_completion(&ioc->tm_cmds.done);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302430 mpt2sas_base_put_smid_hi_priority(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06002431 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
Eric Moore635374e2009-03-09 01:21:12 -06002432 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2433 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2434 ioc->name, __func__);
2435 _debug_dump_mf(mpi_request,
2436 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302437 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302438 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302439 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302440 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302441 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2442 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2443 goto err_out;
2444 }
Eric Moore635374e2009-03-09 01:21:12 -06002445 }
2446
2447 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2448 mpi_reply = ioc->tm_cmds.reply;
2449 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2450 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2451 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2452 le32_to_cpu(mpi_reply->IOCLogInfo),
2453 le32_to_cpu(mpi_reply->TerminationCount)));
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302454 if (ioc->logging_level & MPT_DEBUG_TM) {
Eric Moore635374e2009-03-09 01:21:12 -06002455 _scsih_response_code(ioc, mpi_reply->ResponseCode);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302456 if (mpi_reply->IOCStatus)
2457 _debug_dump_mf(mpi_request,
2458 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2459 }
Eric Moore635374e2009-03-09 01:21:12 -06002460 }
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302461
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302462 switch (type) {
2463 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302464 rc = SUCCESS;
2465 if (scsi_lookup->scmd == NULL)
2466 break;
2467 rc = FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302468 break;
2469
2470 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2471 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2472 rc = FAILED;
2473 else
2474 rc = SUCCESS;
2475 break;
2476
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302477 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302478 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2479 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2480 rc = FAILED;
2481 else
2482 rc = SUCCESS;
2483 break;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302484 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2485 rc = SUCCESS;
2486 break;
2487 default:
2488 rc = FAILED;
2489 break;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302490 }
2491
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302492 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2493 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302494 if (m_type == TM_MUTEX_ON)
2495 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302496
2497 return rc;
2498
2499 err_out:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302500 if (m_type == TM_MUTEX_ON)
2501 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302502 return rc;
Eric Moore635374e2009-03-09 01:21:12 -06002503}
2504
2505/**
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302506 * _scsih_tm_display_info - displays info about the device
2507 * @ioc: per adapter struct
2508 * @scmd: pointer to scsi command object
2509 *
2510 * Called by task management callback handlers.
2511 */
2512static void
2513_scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2514{
2515 struct scsi_target *starget = scmd->device->sdev_target;
2516 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2517 struct _sas_device *sas_device = NULL;
2518 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302519 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302520
2521 if (!priv_target)
2522 return;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302523 if (ioc->hide_ir_msg)
2524 device_str = "WarpDrive";
2525 else
2526 device_str = "volume";
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302527
2528 scsi_print_command(scmd);
2529 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302530 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2531 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2532 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302533 } else {
2534 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2535 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2536 priv_target->sas_address);
2537 if (sas_device) {
2538 if (priv_target->flags &
2539 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2540 starget_printk(KERN_INFO, starget,
2541 "volume handle(0x%04x), "
2542 "volume wwid(0x%016llx)\n",
2543 sas_device->volume_handle,
2544 (unsigned long long)sas_device->volume_wwid);
2545 }
2546 starget_printk(KERN_INFO, starget,
2547 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2548 sas_device->handle,
2549 (unsigned long long)sas_device->sas_address,
2550 sas_device->phy);
2551 starget_printk(KERN_INFO, starget,
2552 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2553 (unsigned long long)sas_device->enclosure_logical_id,
2554 sas_device->slot);
2555 }
2556 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2557 }
2558}
2559
2560/**
Eric Moored5d135b2009-05-18 13:02:08 -06002561 * _scsih_abort - eh threads main abort routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302562 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002563 *
2564 * Returns SUCCESS if command aborted else FAILED
2565 */
2566static int
Eric Moored5d135b2009-05-18 13:02:08 -06002567_scsih_abort(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002568{
2569 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2570 struct MPT2SAS_DEVICE *sas_device_priv_data;
2571 u16 smid;
2572 u16 handle;
2573 int r;
Eric Moore635374e2009-03-09 01:21:12 -06002574
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302575 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2576 "scmd(%p)\n", scmd);
2577 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002578
2579 sas_device_priv_data = scmd->device->hostdata;
2580 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302581 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2582 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002583 scmd->result = DID_NO_CONNECT << 16;
2584 scmd->scsi_done(scmd);
2585 r = SUCCESS;
2586 goto out;
2587 }
2588
2589 /* search for the command */
2590 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2591 if (!smid) {
2592 scmd->result = DID_RESET << 16;
2593 r = SUCCESS;
2594 goto out;
2595 }
2596
2597 /* for hidden raid components and volumes this is not supported */
2598 if (sas_device_priv_data->sas_target->flags &
2599 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2600 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2601 scmd->result = DID_RESET << 16;
2602 r = FAILED;
2603 goto out;
2604 }
2605
Kashyap, Desaifa7f3162009-09-23 17:26:58 +05302606 mpt2sas_halt_firmware(ioc);
2607
Eric Moore635374e2009-03-09 01:21:12 -06002608 handle = sas_device_priv_data->sas_target->handle;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302609 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2610 scmd->device->id, scmd->device->lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002611 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002612
2613 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302614 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2615 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002616 return r;
2617}
2618
Eric Moore635374e2009-03-09 01:21:12 -06002619/**
Eric Moored5d135b2009-05-18 13:02:08 -06002620 * _scsih_dev_reset - eh threads main device reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302621 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002622 *
2623 * Returns SUCCESS if command aborted else FAILED
2624 */
2625static int
Eric Moored5d135b2009-05-18 13:02:08 -06002626_scsih_dev_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002627{
2628 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2629 struct MPT2SAS_DEVICE *sas_device_priv_data;
2630 struct _sas_device *sas_device;
2631 unsigned long flags;
2632 u16 handle;
2633 int r;
2634
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302635 struct scsi_target *starget = scmd->device->sdev_target;
2636
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302637 starget_printk(KERN_INFO, starget, "attempting device reset! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302638 "scmd(%p)\n", scmd);
2639 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002640
2641 sas_device_priv_data = scmd->device->hostdata;
2642 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302643 starget_printk(KERN_INFO, starget, "device been deleted! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302644 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002645 scmd->result = DID_NO_CONNECT << 16;
2646 scmd->scsi_done(scmd);
2647 r = SUCCESS;
2648 goto out;
2649 }
2650
2651 /* for hidden raid components obtain the volume_handle */
2652 handle = 0;
2653 if (sas_device_priv_data->sas_target->flags &
2654 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2655 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2656 sas_device = _scsih_sas_device_find_by_handle(ioc,
2657 sas_device_priv_data->sas_target->handle);
2658 if (sas_device)
2659 handle = sas_device->volume_handle;
2660 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2661 } else
2662 handle = sas_device_priv_data->sas_target->handle;
2663
2664 if (!handle) {
2665 scmd->result = DID_RESET << 16;
2666 r = FAILED;
2667 goto out;
2668 }
2669
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302670 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2671 scmd->device->id, scmd->device->lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002672 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
Eric Moore993e0da2009-05-18 13:00:45 -06002673
2674 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302675 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2676 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002677 return r;
2678}
2679
2680/**
Eric Moored5d135b2009-05-18 13:02:08 -06002681 * _scsih_target_reset - eh threads main target reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302682 * @scmd: pointer to scsi command object
Eric Moore993e0da2009-05-18 13:00:45 -06002683 *
2684 * Returns SUCCESS if command aborted else FAILED
2685 */
2686static int
Eric Moored5d135b2009-05-18 13:02:08 -06002687_scsih_target_reset(struct scsi_cmnd *scmd)
Eric Moore993e0da2009-05-18 13:00:45 -06002688{
2689 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2690 struct MPT2SAS_DEVICE *sas_device_priv_data;
2691 struct _sas_device *sas_device;
2692 unsigned long flags;
2693 u16 handle;
2694 int r;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302695 struct scsi_target *starget = scmd->device->sdev_target;
Eric Moore993e0da2009-05-18 13:00:45 -06002696
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302697 starget_printk(KERN_INFO, starget, "attempting target reset! "
2698 "scmd(%p)\n", scmd);
2699 _scsih_tm_display_info(ioc, scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002700
2701 sas_device_priv_data = scmd->device->hostdata;
2702 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302703 starget_printk(KERN_INFO, starget, "target been deleted! "
2704 "scmd(%p)\n", scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002705 scmd->result = DID_NO_CONNECT << 16;
2706 scmd->scsi_done(scmd);
2707 r = SUCCESS;
2708 goto out;
2709 }
2710
2711 /* for hidden raid components obtain the volume_handle */
2712 handle = 0;
2713 if (sas_device_priv_data->sas_target->flags &
2714 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2715 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2716 sas_device = _scsih_sas_device_find_by_handle(ioc,
2717 sas_device_priv_data->sas_target->handle);
2718 if (sas_device)
2719 handle = sas_device->volume_handle;
2720 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2721 } else
2722 handle = sas_device_priv_data->sas_target->handle;
2723
2724 if (!handle) {
2725 scmd->result = DID_RESET << 16;
2726 r = FAILED;
2727 goto out;
2728 }
2729
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302730 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2731 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002732 30, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002733
2734 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302735 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2736 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002737 return r;
2738}
2739
2740/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302741 * _scsih_host_reset - eh threads main host reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302742 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002743 *
2744 * Returns SUCCESS if command aborted else FAILED
2745 */
2746static int
Eric Moored5d135b2009-05-18 13:02:08 -06002747_scsih_host_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002748{
2749 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2750 int r, retval;
2751
2752 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2753 ioc->name, scmd);
2754 scsi_print_command(scmd);
2755
2756 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2757 FORCE_BIG_HAMMER);
2758 r = (retval < 0) ? FAILED : SUCCESS;
2759 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2760 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2761
2762 return r;
2763}
2764
2765/**
2766 * _scsih_fw_event_add - insert and queue up fw_event
2767 * @ioc: per adapter object
2768 * @fw_event: object describing the event
2769 * Context: This function will acquire ioc->fw_event_lock.
2770 *
2771 * This adds the firmware event object into link list, then queues it up to
2772 * be processed from user context.
2773 *
2774 * Return nothing.
2775 */
2776static void
2777_scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2778{
2779 unsigned long flags;
2780
2781 if (ioc->firmware_event_thread == NULL)
2782 return;
2783
2784 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2785 list_add_tail(&fw_event->list, &ioc->fw_event_list);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302786 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2787 queue_delayed_work(ioc->firmware_event_thread,
2788 &fw_event->delayed_work, 0);
Eric Moore635374e2009-03-09 01:21:12 -06002789 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2790}
2791
2792/**
2793 * _scsih_fw_event_free - delete fw_event
2794 * @ioc: per adapter object
2795 * @fw_event: object describing the event
2796 * Context: This function will acquire ioc->fw_event_lock.
2797 *
2798 * This removes firmware event object from link list, frees associated memory.
2799 *
2800 * Return nothing.
2801 */
2802static void
2803_scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2804 *fw_event)
2805{
2806 unsigned long flags;
2807
2808 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2809 list_del(&fw_event->list);
Eric Moore635374e2009-03-09 01:21:12 -06002810 kfree(fw_event);
2811 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2812}
2813
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302814
Eric Moore635374e2009-03-09 01:21:12 -06002815/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302816 * _scsih_error_recovery_delete_devices - remove devices not responding
Eric Moore635374e2009-03-09 01:21:12 -06002817 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06002818 *
2819 * Return nothing.
2820 */
2821static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302822_scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06002823{
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302824 struct fw_event_work *fw_event;
2825
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302826 if (ioc->is_driver_loading)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302827 return;
Dan Carpenter181a9d72011-11-04 21:25:01 +03002828
2829 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2830 if (!fw_event)
2831 return;
2832
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302833 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2834 fw_event->ioc = ioc;
2835 _scsih_fw_event_add(ioc, fw_event);
2836}
2837
2838/**
2839 * mpt2sas_port_enable_complete - port enable completed (fake event)
2840 * @ioc: per adapter object
2841 *
2842 * Return nothing.
2843 */
2844void
2845mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2846{
2847 struct fw_event_work *fw_event;
2848
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302849 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2850 if (!fw_event)
2851 return;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302852 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302853 fw_event->ioc = ioc;
2854 _scsih_fw_event_add(ioc, fw_event);
2855}
2856
2857/**
2858 * _scsih_fw_event_cleanup_queue - cleanup event queue
2859 * @ioc: per adapter object
2860 *
2861 * Walk the firmware event queue, either killing timers, or waiting
2862 * for outstanding events to complete
2863 *
2864 * Return nothing.
2865 */
2866static void
2867_scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2868{
2869 struct fw_event_work *fw_event, *next;
2870
2871 if (list_empty(&ioc->fw_event_list) ||
2872 !ioc->firmware_event_thread || in_interrupt())
Eric Moore635374e2009-03-09 01:21:12 -06002873 return;
2874
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302875 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05302876 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302877 _scsih_fw_event_free(ioc, fw_event);
2878 continue;
2879 }
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302880 }
Eric Moore635374e2009-03-09 01:21:12 -06002881}
2882
Eric Moore635374e2009-03-09 01:21:12 -06002883/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302884 * _scsih_ublock_io_all_device - unblock every device
2885 * @ioc: per adapter object
2886 *
2887 * change the device state from block to running
2888 */
2889static void
2890_scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2891{
2892 struct MPT2SAS_DEVICE *sas_device_priv_data;
2893 struct scsi_device *sdev;
2894
2895 shost_for_each_device(sdev, ioc->shost) {
2896 sas_device_priv_data = sdev->hostdata;
2897 if (!sas_device_priv_data)
2898 continue;
2899 if (!sas_device_priv_data->block)
2900 continue;
2901 sas_device_priv_data->block = 0;
2902 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2903 "handle(0x%04x)\n",
2904 sas_device_priv_data->sas_target->handle));
Mike Christie5d9fb5c2012-05-17 23:56:57 -05002905 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302906 }
2907}
2908/**
Eric Moore635374e2009-03-09 01:21:12 -06002909 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2910 * @ioc: per adapter object
2911 * @handle: device handle
2912 *
2913 * During device pull we need to appropiately set the sdev state.
2914 */
2915static void
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302916_scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06002917{
2918 struct MPT2SAS_DEVICE *sas_device_priv_data;
2919 struct scsi_device *sdev;
2920
2921 shost_for_each_device(sdev, ioc->shost) {
2922 sas_device_priv_data = sdev->hostdata;
2923 if (!sas_device_priv_data)
2924 continue;
2925 if (!sas_device_priv_data->block)
2926 continue;
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302927 if (sas_device_priv_data->sas_target->sas_address ==
2928 sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06002929 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2930 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302931 "sas address(0x%016llx)\n", ioc->name,
2932 (unsigned long long)sas_address));
Eric Moore635374e2009-03-09 01:21:12 -06002933 sas_device_priv_data->block = 0;
Mike Christie5d9fb5c2012-05-17 23:56:57 -05002934 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
Eric Moore635374e2009-03-09 01:21:12 -06002935 }
2936 }
2937}
2938
2939/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302940 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2941 * @ioc: per adapter object
2942 * @handle: device handle
2943 *
2944 * During device pull we need to appropiately set the sdev state.
2945 */
2946static void
2947_scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2948{
2949 struct MPT2SAS_DEVICE *sas_device_priv_data;
2950 struct scsi_device *sdev;
2951
2952 shost_for_each_device(sdev, ioc->shost) {
2953 sas_device_priv_data = sdev->hostdata;
2954 if (!sas_device_priv_data)
2955 continue;
2956 if (sas_device_priv_data->block)
2957 continue;
2958 sas_device_priv_data->block = 1;
2959 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2960 "handle(0x%04x)\n",
2961 sas_device_priv_data->sas_target->handle));
2962 scsi_internal_device_block(sdev);
2963 }
2964}
2965
2966
2967/**
Eric Moore635374e2009-03-09 01:21:12 -06002968 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2969 * @ioc: per adapter object
2970 * @handle: device handle
2971 *
2972 * During device pull we need to appropiately set the sdev state.
2973 */
2974static void
2975_scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2976{
2977 struct MPT2SAS_DEVICE *sas_device_priv_data;
2978 struct scsi_device *sdev;
2979
2980 shost_for_each_device(sdev, ioc->shost) {
2981 sas_device_priv_data = sdev->hostdata;
2982 if (!sas_device_priv_data)
2983 continue;
2984 if (sas_device_priv_data->block)
2985 continue;
2986 if (sas_device_priv_data->sas_target->handle == handle) {
2987 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2988 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2989 "handle(0x%04x)\n", ioc->name, handle));
2990 sas_device_priv_data->block = 1;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05302991 scsi_internal_device_block(sdev);
Eric Moore635374e2009-03-09 01:21:12 -06002992 }
2993 }
2994}
2995
2996/**
2997 * _scsih_block_io_to_children_attached_to_ex
2998 * @ioc: per adapter object
2999 * @sas_expander: the sas_device object
3000 *
3001 * This routine set sdev state to SDEV_BLOCK for all devices
3002 * attached to this expander. This function called when expander is
3003 * pulled.
3004 */
3005static void
3006_scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
3007 struct _sas_node *sas_expander)
3008{
3009 struct _sas_port *mpt2sas_port;
3010 struct _sas_device *sas_device;
3011 struct _sas_node *expander_sibling;
3012 unsigned long flags;
3013
3014 if (!sas_expander)
3015 return;
3016
3017 list_for_each_entry(mpt2sas_port,
3018 &sas_expander->sas_port_list, port_list) {
3019 if (mpt2sas_port->remote_identify.device_type ==
3020 SAS_END_DEVICE) {
3021 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3022 sas_device =
3023 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3024 mpt2sas_port->remote_identify.sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303025 if (sas_device)
3026 set_bit(sas_device->handle,
3027 ioc->blocking_handles);
Eric Moore635374e2009-03-09 01:21:12 -06003028 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06003029 }
3030 }
3031
3032 list_for_each_entry(mpt2sas_port,
3033 &sas_expander->sas_port_list, port_list) {
3034
3035 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05303036 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06003037 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05303038 SAS_FANOUT_EXPANDER_DEVICE) {
Eric Moore635374e2009-03-09 01:21:12 -06003039 expander_sibling =
3040 mpt2sas_scsih_expander_find_by_sas_address(
3041 ioc, mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06003042 _scsih_block_io_to_children_attached_to_ex(ioc,
3043 expander_sibling);
3044 }
3045 }
3046}
3047
3048/**
3049 * _scsih_block_io_to_children_attached_directly
3050 * @ioc: per adapter object
3051 * @event_data: topology change event data
3052 *
3053 * This routine set sdev state to SDEV_BLOCK for all devices
3054 * direct attached during device pull.
3055 */
3056static void
3057_scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3058 Mpi2EventDataSasTopologyChangeList_t *event_data)
3059{
3060 int i;
3061 u16 handle;
3062 u16 reason_code;
3063 u8 phy_number;
3064
3065 for (i = 0; i < event_data->NumEntries; i++) {
3066 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3067 if (!handle)
3068 continue;
3069 phy_number = event_data->StartPhyNum + i;
3070 reason_code = event_data->PHY[i].PhyStatus &
3071 MPI2_EVENT_SAS_TOPO_RC_MASK;
3072 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3073 _scsih_block_io_device(ioc, handle);
3074 }
3075}
3076
3077/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303078 * _scsih_tm_tr_send - send task management request
3079 * @ioc: per adapter object
3080 * @handle: device handle
3081 * Context: interrupt time.
3082 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003083 * This code is to initiate the device removal handshake protocol
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303084 * with controller firmware. This function will issue target reset
3085 * using high priority request queue. It will send a sas iounit
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003086 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303087 *
3088 * This is designed to send muliple task management request at the same
3089 * time to the fifo. If the fifo is full, we will append the request,
3090 * and process it in a future completion.
3091 */
3092static void
3093_scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3094{
3095 Mpi2SCSITaskManagementRequest_t *mpi_request;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303096 u16 smid;
3097 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303098 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3099 u64 sas_address = 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303100 unsigned long flags;
3101 struct _tr_list *delayed_tr;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303102 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303103
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303104 if (ioc->remove_host) {
3105 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3106 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3107 return;
3108 } else if (ioc->pci_error_recovery) {
3109 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3110 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3111 handle));
3112 return;
3113 }
3114 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3115 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3116 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3117 "operational: handle(0x%04x)\n", __func__, ioc->name,
3118 handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303119 return;
3120 }
3121
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303122 /* if PD, then return */
3123 if (test_bit(handle, ioc->pd_handles))
3124 return;
3125
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303126 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3127 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303128 if (sas_device && sas_device->starget &&
3129 sas_device->starget->hostdata) {
3130 sas_target_priv_data = sas_device->starget->hostdata;
3131 sas_target_priv_data->deleted = 1;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303132 sas_address = sas_device->sas_address;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303133 }
3134 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303135
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303136 if (sas_target_priv_data) {
3137 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3138 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3139 (unsigned long long)sas_address));
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05303140 _scsih_ublock_io_device(ioc, sas_address);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05303141 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303142 }
3143
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303144 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3145 if (!smid) {
3146 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3147 if (!delayed_tr)
3148 return;
3149 INIT_LIST_HEAD(&delayed_tr->list);
3150 delayed_tr->handle = handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303151 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3152 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3153 "DELAYED:tr:handle(0x%04x), (open)\n",
3154 ioc->name, handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303155 return;
3156 }
3157
Kashyap, Desai1278b112010-03-09 17:34:13 +05303158 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3159 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3160 ioc->tm_tr_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303161 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3162 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3163 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3164 mpi_request->DevHandle = cpu_to_le16(handle);
3165 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303166 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3167}
3168
3169
3170
3171/**
3172 * _scsih_sas_control_complete - completion routine
3173 * @ioc: per adapter object
3174 * @smid: system request message index
3175 * @msix_index: MSIX table index supplied by the OS
3176 * @reply: reply message frame(lower 32bit addr)
3177 * Context: interrupt time.
3178 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003179 * This is the sas iounit control completion routine.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303180 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003181 * handshake protocol with controller firmware.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303182 *
3183 * Return 1 meaning mf should be freed from _base_interrupt
3184 * 0 means the mf is freed from this function.
3185 */
3186static u8
3187_scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3188 u8 msix_index, u32 reply)
3189{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303190 Mpi2SasIoUnitControlReply_t *mpi_reply =
3191 mpt2sas_base_get_reply_virt_addr(ioc, reply);
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303192 if (likely(mpi_reply)) {
3193 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3194 "sc_complete:handle(0x%04x), (open) "
3195 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3196 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3197 le16_to_cpu(mpi_reply->IOCStatus),
3198 le32_to_cpu(mpi_reply->IOCLogInfo)));
3199 } else {
3200 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3201 ioc->name, __FILE__, __LINE__, __func__);
3202 }
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303203 return 1;
3204}
3205
3206/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303207 * _scsih_tm_tr_volume_send - send target reset request for volumes
3208 * @ioc: per adapter object
3209 * @handle: device handle
3210 * Context: interrupt time.
3211 *
3212 * This is designed to send muliple task management request at the same
3213 * time to the fifo. If the fifo is full, we will append the request,
3214 * and process it in a future completion.
3215 */
3216static void
3217_scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3218{
3219 Mpi2SCSITaskManagementRequest_t *mpi_request;
3220 u16 smid;
3221 struct _tr_list *delayed_tr;
3222
Eric Moore3cb54692010-07-08 14:44:34 -06003223 if (ioc->shost_recovery || ioc->remove_host ||
3224 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303225 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3226 "progress!\n", __func__, ioc->name));
3227 return;
3228 }
3229
3230 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3231 if (!smid) {
3232 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3233 if (!delayed_tr)
3234 return;
3235 INIT_LIST_HEAD(&delayed_tr->list);
3236 delayed_tr->handle = handle;
3237 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3238 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3239 "DELAYED:tr:handle(0x%04x), (open)\n",
3240 ioc->name, handle));
3241 return;
3242 }
3243
3244 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3245 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3246 ioc->tm_tr_volume_cb_idx));
3247 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3248 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3249 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3250 mpi_request->DevHandle = cpu_to_le16(handle);
3251 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3252 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3253}
3254
3255/**
3256 * _scsih_tm_volume_tr_complete - target reset completion
3257 * @ioc: per adapter object
3258 * @smid: system request message index
3259 * @msix_index: MSIX table index supplied by the OS
3260 * @reply: reply message frame(lower 32bit addr)
3261 * Context: interrupt time.
3262 *
3263 * Return 1 meaning mf should be freed from _base_interrupt
3264 * 0 means the mf is freed from this function.
3265 */
3266static u8
3267_scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3268 u8 msix_index, u32 reply)
3269{
3270 u16 handle;
3271 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3272 Mpi2SCSITaskManagementReply_t *mpi_reply =
3273 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3274
Eric Moore3cb54692010-07-08 14:44:34 -06003275 if (ioc->shost_recovery || ioc->remove_host ||
3276 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303277 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3278 "progress!\n", __func__, ioc->name));
3279 return 1;
3280 }
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303281 if (unlikely(!mpi_reply)) {
3282 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3283 ioc->name, __FILE__, __LINE__, __func__);
3284 return 1;
3285 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303286 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3287 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3288 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3289 dewtprintk(ioc, printk("spurious interrupt: "
3290 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3291 le16_to_cpu(mpi_reply->DevHandle), smid));
3292 return 0;
3293 }
3294
3295 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3296 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3297 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3298 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3299 le32_to_cpu(mpi_reply->IOCLogInfo),
3300 le32_to_cpu(mpi_reply->TerminationCount)));
3301
3302 return _scsih_check_for_pending_tm(ioc, smid);
3303}
3304
3305/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303306 * _scsih_tm_tr_complete -
3307 * @ioc: per adapter object
3308 * @smid: system request message index
3309 * @msix_index: MSIX table index supplied by the OS
3310 * @reply: reply message frame(lower 32bit addr)
3311 * Context: interrupt time.
3312 *
3313 * This is the target reset completion routine.
3314 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003315 * handshake protocol with controller firmware.
3316 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303317 *
3318 * Return 1 meaning mf should be freed from _base_interrupt
3319 * 0 means the mf is freed from this function.
3320 */
3321static u8
3322_scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3323 u32 reply)
3324{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303325 u16 handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303326 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303327 Mpi2SCSITaskManagementReply_t *mpi_reply =
3328 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3329 Mpi2SasIoUnitControlRequest_t *mpi_request;
3330 u16 smid_sas_ctrl;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303331 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303332
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303333 if (ioc->remove_host) {
3334 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3335 "removed\n", __func__, ioc->name));
3336 return 1;
3337 } else if (ioc->pci_error_recovery) {
3338 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3339 "error recovery\n", __func__, ioc->name));
3340 return 1;
3341 }
3342 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3343 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3344 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3345 "operational\n", __func__, ioc->name));
Kashyap, Desai1278b112010-03-09 17:34:13 +05303346 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303347 }
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303348 if (unlikely(!mpi_reply)) {
3349 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3350 ioc->name, __FILE__, __LINE__, __func__);
3351 return 1;
3352 }
Kashyap, Desai1278b112010-03-09 17:34:13 +05303353 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3354 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3355 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3356 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3357 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3358 le16_to_cpu(mpi_reply->DevHandle), smid));
3359 return 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303360 }
3361
Kashyap, Desai1278b112010-03-09 17:34:13 +05303362 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3363 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3364 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3365 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3366 le32_to_cpu(mpi_reply->IOCLogInfo),
3367 le32_to_cpu(mpi_reply->TerminationCount)));
3368
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303369 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3370 if (!smid_sas_ctrl) {
3371 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3372 ioc->name, __func__);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303373 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303374 }
3375
Kashyap, Desai1278b112010-03-09 17:34:13 +05303376 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3377 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3378 ioc->tm_sas_control_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303379 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3380 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3381 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3382 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303383 mpi_request->DevHandle = mpi_request_tm->DevHandle;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303384 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303385
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303386 return _scsih_check_for_pending_tm(ioc, smid);
3387}
3388
3389/**
3390 * _scsih_check_for_pending_tm - check for pending task management
3391 * @ioc: per adapter object
3392 * @smid: system request message index
3393 *
3394 * This will check delayed target reset list, and feed the
3395 * next reqeust.
3396 *
3397 * Return 1 meaning mf should be freed from _base_interrupt
3398 * 0 means the mf is freed from this function.
3399 */
3400static u8
3401_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3402{
3403 struct _tr_list *delayed_tr;
3404
3405 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3406 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3407 struct _tr_list, list);
3408 mpt2sas_base_free_smid(ioc, smid);
3409 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3410 list_del(&delayed_tr->list);
3411 kfree(delayed_tr);
3412 return 0;
3413 }
3414
Kashyap, Desai1278b112010-03-09 17:34:13 +05303415 if (!list_empty(&ioc->delayed_tr_list)) {
3416 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3417 struct _tr_list, list);
3418 mpt2sas_base_free_smid(ioc, smid);
3419 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3420 list_del(&delayed_tr->list);
3421 kfree(delayed_tr);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303422 return 0;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303423 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303424
Kashyap, Desai1278b112010-03-09 17:34:13 +05303425 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303426}
3427
3428/**
Eric Moore635374e2009-03-09 01:21:12 -06003429 * _scsih_check_topo_delete_events - sanity check on topo events
3430 * @ioc: per adapter object
3431 * @event_data: the event data payload
3432 *
3433 * This routine added to better handle cable breaker.
3434 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003435 * This handles the case where driver receives multiple expander
Eric Moore635374e2009-03-09 01:21:12 -06003436 * add and delete events in a single shot. When there is a delete event
3437 * the routine will void any pending add events waiting in the event queue.
3438 *
3439 * Return nothing.
3440 */
3441static void
3442_scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3443 Mpi2EventDataSasTopologyChangeList_t *event_data)
3444{
3445 struct fw_event_work *fw_event;
3446 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3447 u16 expander_handle;
3448 struct _sas_node *sas_expander;
3449 unsigned long flags;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303450 int i, reason_code;
3451 u16 handle;
3452
3453 for (i = 0 ; i < event_data->NumEntries; i++) {
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303454 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3455 if (!handle)
3456 continue;
3457 reason_code = event_data->PHY[i].PhyStatus &
3458 MPI2_EVENT_SAS_TOPO_RC_MASK;
3459 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3460 _scsih_tm_tr_send(ioc, handle);
3461 }
Eric Moore635374e2009-03-09 01:21:12 -06003462
3463 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3464 if (expander_handle < ioc->sas_hba.num_phys) {
3465 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3466 return;
3467 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303468 if (event_data->ExpStatus ==
3469 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3470 /* put expander attached devices into blocking state */
Eric Moore635374e2009-03-09 01:21:12 -06003471 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3472 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3473 expander_handle);
Eric Moore635374e2009-03-09 01:21:12 -06003474 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303475 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3476 do {
3477 handle = find_first_bit(ioc->blocking_handles,
3478 ioc->facts.MaxDevHandle);
3479 if (handle < ioc->facts.MaxDevHandle)
3480 _scsih_block_io_device(ioc, handle);
3481 } while (test_and_clear_bit(handle, ioc->blocking_handles));
Eric Moore635374e2009-03-09 01:21:12 -06003482 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3483 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3484
3485 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3486 return;
3487
3488 /* mark ignore flag for pending events */
3489 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3490 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3491 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3492 fw_event->ignore)
3493 continue;
Joe Lawrence00713ad2014-06-25 17:03:33 -04003494 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3495 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06003496 if (local_event_data->ExpStatus ==
3497 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3498 local_event_data->ExpStatus ==
3499 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3500 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3501 expander_handle) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303502 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06003503 "setting ignoring flag\n", ioc->name));
3504 fw_event->ignore = 1;
3505 }
3506 }
3507 }
3508 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3509}
3510
3511/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303512 * _scsih_set_volume_delete_flag - setting volume delete flag
3513 * @ioc: per adapter object
3514 * @handle: device handle
3515 *
3516 * This
3517 * Return nothing.
3518 */
3519static void
3520_scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3521{
3522 struct _raid_device *raid_device;
3523 struct MPT2SAS_TARGET *sas_target_priv_data;
3524 unsigned long flags;
3525
3526 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3527 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3528 if (raid_device && raid_device->starget &&
3529 raid_device->starget->hostdata) {
3530 sas_target_priv_data =
3531 raid_device->starget->hostdata;
3532 sas_target_priv_data->deleted = 1;
3533 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3534 "setting delete flag: handle(0x%04x), "
3535 "wwid(0x%016llx)\n", ioc->name, handle,
3536 (unsigned long long) raid_device->wwid));
3537 }
3538 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3539}
3540
3541/**
3542 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3543 * @handle: input handle
3544 * @a: handle for volume a
3545 * @b: handle for volume b
3546 *
3547 * IR firmware only supports two raid volumes. The purpose of this
3548 * routine is to set the volume handle in either a or b. When the given
3549 * input handle is non-zero, or when a and b have not been set before.
3550 */
3551static void
3552_scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3553{
3554 if (!handle || handle == *a || handle == *b)
3555 return;
3556 if (!*a)
3557 *a = handle;
3558 else if (!*b)
3559 *b = handle;
3560}
3561
3562/**
3563 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3564 * @ioc: per adapter object
3565 * @event_data: the event data payload
3566 * Context: interrupt time.
3567 *
3568 * This routine will send target reset to volume, followed by target
3569 * resets to the PDs. This is called when a PD has been removed, or
3570 * volume has been deleted or removed. When the target reset is sent
3571 * to volume, the PD target resets need to be queued to start upon
3572 * completion of the volume target reset.
3573 *
3574 * Return nothing.
3575 */
3576static void
3577_scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3578 Mpi2EventDataIrConfigChangeList_t *event_data)
3579{
3580 Mpi2EventIrConfigElement_t *element;
3581 int i;
3582 u16 handle, volume_handle, a, b;
3583 struct _tr_list *delayed_tr;
3584
3585 a = 0;
3586 b = 0;
3587
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303588 if (ioc->is_warpdrive)
3589 return;
3590
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303591 /* Volume Resets for Deleted or Removed */
3592 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3593 for (i = 0; i < event_data->NumElements; i++, element++) {
3594 if (element->ReasonCode ==
3595 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3596 element->ReasonCode ==
3597 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3598 volume_handle = le16_to_cpu(element->VolDevHandle);
3599 _scsih_set_volume_delete_flag(ioc, volume_handle);
3600 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3601 }
3602 }
3603
3604 /* Volume Resets for UNHIDE events */
3605 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3606 for (i = 0; i < event_data->NumElements; i++, element++) {
3607 if (le32_to_cpu(event_data->Flags) &
3608 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3609 continue;
3610 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3611 volume_handle = le16_to_cpu(element->VolDevHandle);
3612 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3613 }
3614 }
3615
3616 if (a)
3617 _scsih_tm_tr_volume_send(ioc, a);
3618 if (b)
3619 _scsih_tm_tr_volume_send(ioc, b);
3620
3621 /* PD target resets */
3622 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3623 for (i = 0; i < event_data->NumElements; i++, element++) {
3624 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3625 continue;
3626 handle = le16_to_cpu(element->PhysDiskDevHandle);
3627 volume_handle = le16_to_cpu(element->VolDevHandle);
3628 clear_bit(handle, ioc->pd_handles);
3629 if (!volume_handle)
3630 _scsih_tm_tr_send(ioc, handle);
3631 else if (volume_handle == a || volume_handle == b) {
3632 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3633 BUG_ON(!delayed_tr);
3634 INIT_LIST_HEAD(&delayed_tr->list);
3635 delayed_tr->handle = handle;
3636 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3637 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3638 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3639 handle));
3640 } else
3641 _scsih_tm_tr_send(ioc, handle);
3642 }
3643}
3644
3645
3646/**
3647 * _scsih_check_volume_delete_events - set delete flag for volumes
3648 * @ioc: per adapter object
3649 * @event_data: the event data payload
3650 * Context: interrupt time.
3651 *
3652 * This will handle the case when the cable connected to entire volume is
3653 * pulled. We will take care of setting the deleted flag so normal IO will
3654 * not be sent.
3655 *
3656 * Return nothing.
3657 */
3658static void
3659_scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3660 Mpi2EventDataIrVolume_t *event_data)
3661{
3662 u32 state;
3663
3664 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3665 return;
3666 state = le32_to_cpu(event_data->NewValue);
3667 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3668 MPI2_RAID_VOL_STATE_FAILED)
3669 _scsih_set_volume_delete_flag(ioc,
3670 le16_to_cpu(event_data->VolDevHandle));
3671}
3672
3673/**
Eric Moore635374e2009-03-09 01:21:12 -06003674 * _scsih_flush_running_cmds - completing outstanding commands.
3675 * @ioc: per adapter object
3676 *
3677 * The flushing out of all pending scmd commands following host reset,
3678 * where all IO is dropped to the floor.
3679 *
3680 * Return nothing.
3681 */
3682static void
3683_scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3684{
3685 struct scsi_cmnd *scmd;
3686 u16 smid;
3687 u16 count = 0;
3688
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303689 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05303690 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003691 if (!scmd)
3692 continue;
3693 count++;
3694 mpt2sas_base_free_smid(ioc, smid);
3695 scsi_dma_unmap(scmd);
Eric Moore3cb54692010-07-08 14:44:34 -06003696 if (ioc->pci_error_recovery)
3697 scmd->result = DID_NO_CONNECT << 16;
3698 else
3699 scmd->result = DID_RESET << 16;
Eric Moore635374e2009-03-09 01:21:12 -06003700 scmd->scsi_done(scmd);
3701 }
3702 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3703 ioc->name, count));
3704}
3705
3706/**
Eric Moore3c621b32009-05-18 12:59:41 -06003707 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3708 * @scmd: pointer to scsi command object
3709 * @mpi_request: pointer to the SCSI_IO reqest message frame
3710 *
3711 * Supporting protection 1 and 3.
3712 *
3713 * Returns nothing
3714 */
3715static void
3716_scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3717{
3718 u16 eedp_flags;
3719 unsigned char prot_op = scsi_get_prot_op(scmd);
3720 unsigned char prot_type = scsi_get_prot_type(scmd);
3721
Eric Moored334aa72010-04-22 10:47:40 -06003722 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
Eric Moore3c621b32009-05-18 12:59:41 -06003723 return;
3724
3725 if (prot_op == SCSI_PROT_READ_STRIP)
3726 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3727 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3728 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3729 else
3730 return;
3731
Eric Moore3c621b32009-05-18 12:59:41 -06003732 switch (prot_type) {
3733 case SCSI_PROT_DIF_TYPE1:
Martin K. Petersen756aca72011-05-18 00:45:22 -04003734 case SCSI_PROT_DIF_TYPE2:
Eric Moore3c621b32009-05-18 12:59:41 -06003735
3736 /*
3737 * enable ref/guard checking
3738 * auto increment ref tag
3739 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303740 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
Eric Moore3c621b32009-05-18 12:59:41 -06003741 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3742 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3743 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3744 cpu_to_be32(scsi_get_lba(scmd));
Eric Moored334aa72010-04-22 10:47:40 -06003745 break;
Eric Moore3c621b32009-05-18 12:59:41 -06003746
Eric Moore3c621b32009-05-18 12:59:41 -06003747 case SCSI_PROT_DIF_TYPE3:
3748
3749 /*
3750 * enable guard checking
3751 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303752 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
Eric Moore3c621b32009-05-18 12:59:41 -06003753 break;
3754 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05303755 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3756 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
Eric Moore3c621b32009-05-18 12:59:41 -06003757}
3758
3759/**
3760 * _scsih_eedp_error_handling - return sense code for EEDP errors
3761 * @scmd: pointer to scsi command object
3762 * @ioc_status: ioc status
3763 *
3764 * Returns nothing
3765 */
3766static void
3767_scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3768{
3769 u8 ascq;
Eric Moore3c621b32009-05-18 12:59:41 -06003770
3771 switch (ioc_status) {
3772 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3773 ascq = 0x01;
3774 break;
3775 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3776 ascq = 0x02;
3777 break;
3778 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3779 ascq = 0x03;
3780 break;
3781 default:
3782 ascq = 0x00;
3783 break;
3784 }
3785
Martin K. Petersen9b5cd132012-08-28 14:29:36 -04003786 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq);
3787 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
Eric Moore3c621b32009-05-18 12:59:41 -06003788 SAM_STAT_CHECK_CONDITION;
3789}
3790
3791/**
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303792 * _scsih_scsi_direct_io_get - returns direct io flag
3793 * @ioc: per adapter object
3794 * @smid: system request message index
3795 *
3796 * Returns the smid stored scmd pointer.
3797 */
3798static inline u8
3799_scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3800{
3801 return ioc->scsi_lookup[smid - 1].direct_io;
3802}
3803
3804/**
3805 * _scsih_scsi_direct_io_set - sets direct io flag
3806 * @ioc: per adapter object
3807 * @smid: system request message index
3808 * @direct_io: Zero or non-zero value to set in the direct_io flag
3809 *
3810 * Returns Nothing.
3811 */
3812static inline void
3813_scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3814{
3815 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3816}
3817
3818
3819/**
3820 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3821 * @ioc: per adapter object
3822 * @scmd: pointer to scsi command object
3823 * @raid_device: pointer to raid device data structure
3824 * @mpi_request: pointer to the SCSI_IO reqest message frame
3825 * @smid: system request message index
3826 *
3827 * Returns nothing
3828 */
3829static void
3830_scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3831 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3832 u16 smid)
3833{
Sreekanth Reddyf78f6942014-09-19 12:17:27 +05303834 sector_t v_lba, p_lba, stripe_off, column, io_size;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303835 u32 stripe_sz, stripe_exp;
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303836 u8 num_pds, cmd = scmd->cmnd[0];
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303837
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303838 if (cmd != READ_10 && cmd != WRITE_10 &&
3839 cmd != READ_16 && cmd != WRITE_16)
3840 return;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303841
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303842 if (cmd == READ_10 || cmd == WRITE_10)
3843 v_lba = get_unaligned_be32(&mpi_request->CDB.CDB32[2]);
3844 else
3845 v_lba = get_unaligned_be64(&mpi_request->CDB.CDB32[2]);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303846
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303847 io_size = scsi_bufflen(scmd) >> raid_device->block_exponent;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303848
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303849 if (v_lba + io_size - 1 > raid_device->max_lba)
3850 return;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303851
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303852 stripe_sz = raid_device->stripe_sz;
3853 stripe_exp = raid_device->stripe_exponent;
3854 stripe_off = v_lba & (stripe_sz - 1);
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303855
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303856 /* Return unless IO falls within a stripe */
3857 if (stripe_off + io_size > stripe_sz)
3858 return;
3859
3860 num_pds = raid_device->num_pds;
3861 p_lba = v_lba >> stripe_exp;
Sreekanth Reddyf78f6942014-09-19 12:17:27 +05303862 column = sector_div(p_lba, num_pds);
3863 p_lba = (p_lba << stripe_exp) + stripe_off;
3864
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303865 mpi_request->DevHandle = cpu_to_le16(raid_device->pd_handle[column]);
3866
3867 if (cmd == READ_10 || cmd == WRITE_10)
3868 put_unaligned_be32(lower_32_bits(p_lba),
3869 &mpi_request->CDB.CDB32[2]);
3870 else
3871 put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]);
3872
3873 _scsih_scsi_direct_io_set(ioc, smid, 1);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303874}
3875
3876/**
Eric Moored5d135b2009-05-18 13:02:08 -06003877 * _scsih_qcmd - main scsi request entry point
Eric Moore635374e2009-03-09 01:21:12 -06003878 * @scmd: pointer to scsi command object
3879 * @done: function pointer to be invoked on completion
3880 *
3881 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3882 *
3883 * Returns 0 on success. If there's a failure, return either:
3884 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3885 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3886 */
3887static int
Matthew Wilcox90f951e2014-03-27 16:40:33 -04003888_scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06003889{
Matthew Wilcox90f951e2014-03-27 16:40:33 -04003890 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Eric Moore635374e2009-03-09 01:21:12 -06003891 struct MPT2SAS_DEVICE *sas_device_priv_data;
3892 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303893 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06003894 Mpi2SCSIIORequest_t *mpi_request;
3895 u32 mpi_control;
3896 u16 smid;
Eric Moore635374e2009-03-09 01:21:12 -06003897
Eric Moore635374e2009-03-09 01:21:12 -06003898 sas_device_priv_data = scmd->device->hostdata;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303899 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Eric Moore635374e2009-03-09 01:21:12 -06003900 scmd->result = DID_NO_CONNECT << 16;
3901 scmd->scsi_done(scmd);
3902 return 0;
3903 }
3904
Kashyap, Desai78215782011-06-14 10:57:08 +05303905 if (ioc->pci_error_recovery || ioc->remove_host) {
Eric Moore3cb54692010-07-08 14:44:34 -06003906 scmd->result = DID_NO_CONNECT << 16;
3907 scmd->scsi_done(scmd);
3908 return 0;
3909 }
3910
Eric Moore635374e2009-03-09 01:21:12 -06003911 sas_target_priv_data = sas_device_priv_data->sas_target;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303912 /* invalid device handle */
3913 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
Eric Moore635374e2009-03-09 01:21:12 -06003914 scmd->result = DID_NO_CONNECT << 16;
3915 scmd->scsi_done(scmd);
3916 return 0;
3917 }
3918
Kashyap, Desai130b9582010-04-08 17:54:32 +05303919 /* host recovery or link resets sent via IOCTLs */
3920 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
Eric Moore635374e2009-03-09 01:21:12 -06003921 return SCSI_MLQUEUE_HOST_BUSY;
Uwe Kleine-König65155b32010-06-11 12:17:01 +02003922 /* device busy with task management */
Kashyap, Desai130b9582010-04-08 17:54:32 +05303923 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3924 return SCSI_MLQUEUE_DEVICE_BUSY;
3925 /* device has been deleted */
3926 else if (sas_target_priv_data->deleted) {
3927 scmd->result = DID_NO_CONNECT << 16;
3928 scmd->scsi_done(scmd);
3929 return 0;
3930 }
Eric Moore635374e2009-03-09 01:21:12 -06003931
3932 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3933 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3934 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3935 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3936 else
3937 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3938
3939 /* set tags */
Christoph Hellwig609aa222014-10-30 11:54:58 +01003940 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3941
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303942 /* Make sure Device is not raid volume.
3943 * We do not expose raid functionality to upper layer for warpdrive.
3944 */
3945 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Eric Moored334aa72010-04-22 10:47:40 -06003946 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
Eric Moore635374e2009-03-09 01:21:12 -06003947 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3948
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303949 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06003950 if (!smid) {
3951 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3952 ioc->name, __func__);
3953 goto out;
3954 }
3955 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3956 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
Eric Moore3c621b32009-05-18 12:59:41 -06003957 _scsih_setup_eedp(scmd, mpi_request);
Eric Moored334aa72010-04-22 10:47:40 -06003958 if (scmd->cmd_len == 32)
3959 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
Eric Moore635374e2009-03-09 01:21:12 -06003960 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3961 if (sas_device_priv_data->sas_target->flags &
3962 MPT_TARGET_FLAGS_RAID_COMPONENT)
3963 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3964 else
Matthew Wilcox90f951e2014-03-27 16:40:33 -04003965 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
Eric Moore635374e2009-03-09 01:21:12 -06003966 mpi_request->DevHandle =
3967 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3968 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3969 mpi_request->Control = cpu_to_le32(mpi_control);
3970 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3971 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3972 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3973 mpi_request->SenseBufferLowAddress =
Kashyap, Desaiec9472c2009-09-23 17:34:13 +05303974 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003975 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3976 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3977 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05303978 mpi_request->VF_ID = 0; /* TODO */
3979 mpi_request->VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06003980 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3981 mpi_request->LUN);
3982 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3983
3984 if (!mpi_request->DataLength) {
3985 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
3986 } else {
3987 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
3988 mpt2sas_base_free_smid(ioc, smid);
3989 goto out;
3990 }
3991 }
3992
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303993 raid_device = sas_target_priv_data->raid_device;
3994 if (raid_device && raid_device->direct_io_enabled)
3995 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
3996 smid);
3997
Kashyap, Desai58287fd2010-03-17 16:27:25 +05303998 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
3999 mpt2sas_base_put_smid_scsi_io(ioc, smid,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304000 le16_to_cpu(mpi_request->DevHandle));
Kashyap, Desai58287fd2010-03-17 16:27:25 +05304001 else
4002 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004003 return 0;
4004
4005 out:
4006 return SCSI_MLQUEUE_HOST_BUSY;
4007}
4008
4009/**
4010 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4011 * @sense_buffer: sense data returned by target
4012 * @data: normalized skey/asc/ascq
4013 *
4014 * Return nothing.
4015 */
4016static void
4017_scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4018{
4019 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4020 /* descriptor format */
4021 data->skey = sense_buffer[1] & 0x0F;
4022 data->asc = sense_buffer[2];
4023 data->ascq = sense_buffer[3];
4024 } else {
4025 /* fixed format */
4026 data->skey = sense_buffer[2] & 0x0F;
4027 data->asc = sense_buffer[12];
4028 data->ascq = sense_buffer[13];
4029 }
4030}
4031
4032#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4033/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004034 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
Eric Moore635374e2009-03-09 01:21:12 -06004035 * @ioc: per adapter object
4036 * @scmd: pointer to scsi command object
4037 * @mpi_reply: reply mf payload returned from firmware
4038 *
4039 * scsi_status - SCSI Status code returned from target device
4040 * scsi_state - state info associated with SCSI_IO determined by ioc
4041 * ioc_status - ioc supplied status info
4042 *
4043 * Return nothing.
4044 */
4045static void
4046_scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4047 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4048{
4049 u32 response_info;
4050 u8 *response_bytes;
4051 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4052 MPI2_IOCSTATUS_MASK;
4053 u8 scsi_state = mpi_reply->SCSIState;
4054 u8 scsi_status = mpi_reply->SCSIStatus;
4055 char *desc_ioc_state = NULL;
4056 char *desc_scsi_status = NULL;
4057 char *desc_scsi_state = ioc->tmp_string;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304058 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304059 struct _sas_device *sas_device = NULL;
4060 unsigned long flags;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304061 struct scsi_target *starget = scmd->device->sdev_target;
4062 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304063 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304064
4065 if (!priv_target)
4066 return;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304067
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304068 if (ioc->hide_ir_msg)
4069 device_str = "WarpDrive";
4070 else
4071 device_str = "volume";
4072
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304073 if (log_info == 0x31170000)
4074 return;
Eric Moore635374e2009-03-09 01:21:12 -06004075
4076 switch (ioc_status) {
4077 case MPI2_IOCSTATUS_SUCCESS:
4078 desc_ioc_state = "success";
4079 break;
4080 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4081 desc_ioc_state = "invalid function";
4082 break;
4083 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4084 desc_ioc_state = "scsi recovered error";
4085 break;
4086 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4087 desc_ioc_state = "scsi invalid dev handle";
4088 break;
4089 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4090 desc_ioc_state = "scsi device not there";
4091 break;
4092 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4093 desc_ioc_state = "scsi data overrun";
4094 break;
4095 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4096 desc_ioc_state = "scsi data underrun";
4097 break;
4098 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4099 desc_ioc_state = "scsi io data error";
4100 break;
4101 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4102 desc_ioc_state = "scsi protocol error";
4103 break;
4104 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4105 desc_ioc_state = "scsi task terminated";
4106 break;
4107 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4108 desc_ioc_state = "scsi residual mismatch";
4109 break;
4110 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4111 desc_ioc_state = "scsi task mgmt failed";
4112 break;
4113 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4114 desc_ioc_state = "scsi ioc terminated";
4115 break;
4116 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4117 desc_ioc_state = "scsi ext terminated";
4118 break;
Eric Moore3c621b32009-05-18 12:59:41 -06004119 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4120 desc_ioc_state = "eedp guard error";
4121 break;
4122 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4123 desc_ioc_state = "eedp ref tag error";
4124 break;
4125 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4126 desc_ioc_state = "eedp app tag error";
4127 break;
Eric Moore635374e2009-03-09 01:21:12 -06004128 default:
4129 desc_ioc_state = "unknown";
4130 break;
4131 }
4132
4133 switch (scsi_status) {
4134 case MPI2_SCSI_STATUS_GOOD:
4135 desc_scsi_status = "good";
4136 break;
4137 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4138 desc_scsi_status = "check condition";
4139 break;
4140 case MPI2_SCSI_STATUS_CONDITION_MET:
4141 desc_scsi_status = "condition met";
4142 break;
4143 case MPI2_SCSI_STATUS_BUSY:
4144 desc_scsi_status = "busy";
4145 break;
4146 case MPI2_SCSI_STATUS_INTERMEDIATE:
4147 desc_scsi_status = "intermediate";
4148 break;
4149 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4150 desc_scsi_status = "intermediate condmet";
4151 break;
4152 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4153 desc_scsi_status = "reservation conflict";
4154 break;
4155 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4156 desc_scsi_status = "command terminated";
4157 break;
4158 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4159 desc_scsi_status = "task set full";
4160 break;
4161 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4162 desc_scsi_status = "aca active";
4163 break;
4164 case MPI2_SCSI_STATUS_TASK_ABORTED:
4165 desc_scsi_status = "task aborted";
4166 break;
4167 default:
4168 desc_scsi_status = "unknown";
4169 break;
4170 }
4171
4172 desc_scsi_state[0] = '\0';
4173 if (!scsi_state)
4174 desc_scsi_state = " ";
4175 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4176 strcat(desc_scsi_state, "response info ");
4177 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4178 strcat(desc_scsi_state, "state terminated ");
4179 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4180 strcat(desc_scsi_state, "no status ");
4181 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4182 strcat(desc_scsi_state, "autosense failed ");
4183 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4184 strcat(desc_scsi_state, "autosense valid ");
4185
4186 scsi_print_command(scmd);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304187
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304188 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304189 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4190 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304191 } else {
4192 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4193 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4194 priv_target->sas_address);
4195 if (sas_device) {
4196 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4197 "phy(%d)\n", ioc->name, sas_device->sas_address,
4198 sas_device->phy);
4199 printk(MPT2SAS_WARN_FMT
4200 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4201 ioc->name, sas_device->enclosure_logical_id,
4202 sas_device->slot);
4203 }
4204 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304205 }
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304206
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304207 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4208 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4209 desc_ioc_state, ioc_status, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004210 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4211 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4212 scsi_get_resid(scmd));
4213 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4214 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4215 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4216 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4217 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4218 scsi_status, desc_scsi_state, scsi_state);
4219
4220 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4221 struct sense_info data;
4222 _scsih_normalize_sense(scmd->sense_buffer, &data);
4223 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
Kashyap, Desaie94f6742010-03-17 16:24:52 +05304224 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4225 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
Eric Moore635374e2009-03-09 01:21:12 -06004226 }
4227
4228 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4229 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4230 response_bytes = (u8 *)&response_info;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304231 _scsih_response_code(ioc, response_bytes[0]);
Eric Moore635374e2009-03-09 01:21:12 -06004232 }
4233}
4234#endif
4235
4236/**
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304237 * _scsih_turn_on_pfa_led - illuminate PFA LED
Eric Moore635374e2009-03-09 01:21:12 -06004238 * @ioc: per adapter object
4239 * @handle: device handle
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304240 * Context: process
4241 *
4242 * Return nothing.
4243 */
4244static void
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304245_scsih_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304246{
4247 Mpi2SepReply_t mpi_reply;
4248 Mpi2SepRequest_t mpi_request;
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304249 struct _sas_device *sas_device;
4250
4251 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4252 if (!sas_device)
4253 return;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304254
4255 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4256 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4257 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4258 mpi_request.SlotStatus =
4259 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4260 mpi_request.DevHandle = cpu_to_le16(handle);
4261 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4262 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4263 &mpi_request)) != 0) {
4264 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4265 __FILE__, __LINE__, __func__);
4266 return;
4267 }
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304268 sas_device->pfa_led_on = 1;
4269
4270
4271 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4272 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
4273 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4274 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4275 le32_to_cpu(mpi_reply.IOCLogInfo)));
4276 return;
4277 }
4278}
4279
4280/**
4281 * _scsih_turn_off_pfa_led - turn off PFA LED
4282 * @ioc: per adapter object
4283 * @sas_device: sas device whose PFA LED has to turned off
4284 * Context: process
4285 *
4286 * Return nothing.
4287 */
4288static void
4289_scsih_turn_off_pfa_led(struct MPT2SAS_ADAPTER *ioc,
4290 struct _sas_device *sas_device)
4291{
4292 Mpi2SepReply_t mpi_reply;
4293 Mpi2SepRequest_t mpi_request;
4294
4295 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4296 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4297 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4298 mpi_request.SlotStatus = 0;
4299 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4300 mpi_request.DevHandle = 0;
4301 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4302 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4303 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4304 &mpi_request)) != 0) {
4305 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4306 __FILE__, __LINE__, __func__);
4307 return;
4308 }
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304309
4310 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4311 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4312 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4313 le16_to_cpu(mpi_reply.IOCStatus),
4314 le32_to_cpu(mpi_reply.IOCLogInfo)));
4315 return;
4316 }
4317}
4318
4319/**
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304320 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304321 * @ioc: per adapter object
4322 * @handle: device handle
4323 * Context: interrupt.
4324 *
4325 * Return nothing.
4326 */
4327static void
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304328_scsih_send_event_to_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304329{
4330 struct fw_event_work *fw_event;
4331
4332 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4333 if (!fw_event)
4334 return;
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304335 fw_event->event = MPT2SAS_TURN_ON_PFA_LED;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304336 fw_event->device_handle = handle;
4337 fw_event->ioc = ioc;
4338 _scsih_fw_event_add(ioc, fw_event);
4339}
4340
4341/**
4342 * _scsih_smart_predicted_fault - process smart errors
4343 * @ioc: per adapter object
4344 * @handle: device handle
4345 * Context: interrupt.
Eric Moore635374e2009-03-09 01:21:12 -06004346 *
4347 * Return nothing.
4348 */
4349static void
4350_scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4351{
Eric Moore635374e2009-03-09 01:21:12 -06004352 struct scsi_target *starget;
4353 struct MPT2SAS_TARGET *sas_target_priv_data;
4354 Mpi2EventNotificationReply_t *event_reply;
4355 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4356 struct _sas_device *sas_device;
4357 ssize_t sz;
4358 unsigned long flags;
4359
4360 /* only handle non-raid devices */
4361 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4362 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4363 if (!sas_device) {
4364 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4365 return;
4366 }
4367 starget = sas_device->starget;
4368 sas_target_priv_data = starget->hostdata;
4369
4370 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4371 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4372 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4373 return;
4374 }
4375 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4376 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4377
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304378 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304379 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06004380
4381 /* insert into event log */
4382 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4383 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
Anton Blanchardf6a290b42011-11-07 22:05:21 +11004384 event_reply = kzalloc(sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06004385 if (!event_reply) {
4386 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4387 ioc->name, __FILE__, __LINE__, __func__);
4388 return;
4389 }
4390
4391 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4392 event_reply->Event =
4393 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4394 event_reply->MsgLength = sz/4;
4395 event_reply->EventDataLength =
4396 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4397 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4398 event_reply->EventData;
4399 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4400 event_data->ASC = 0x5D;
4401 event_data->DevHandle = cpu_to_le16(handle);
4402 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4403 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4404 kfree(event_reply);
4405}
4406
4407/**
Eric Moored5d135b2009-05-18 13:02:08 -06004408 * _scsih_io_done - scsi request callback
Eric Moore635374e2009-03-09 01:21:12 -06004409 * @ioc: per adapter object
4410 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304411 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06004412 * @reply: reply message frame(lower 32bit addr)
4413 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304414 * Callback handler when using _scsih_qcmd.
Eric Moore635374e2009-03-09 01:21:12 -06004415 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304416 * Return 1 meaning mf should be freed from _base_interrupt
4417 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06004418 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304419static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304420_scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06004421{
4422 Mpi2SCSIIORequest_t *mpi_request;
4423 Mpi2SCSIIOReply_t *mpi_reply;
4424 struct scsi_cmnd *scmd;
4425 u16 ioc_status;
4426 u32 xfer_cnt;
4427 u8 scsi_state;
4428 u8 scsi_status;
4429 u32 log_info;
4430 struct MPT2SAS_DEVICE *sas_device_priv_data;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304431 u32 response_code = 0;
Kashyap, Desai82a45252011-07-05 12:40:23 +05304432 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06004433
4434 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05304435 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004436 if (scmd == NULL)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304437 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004438
4439 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4440
4441 if (mpi_reply == NULL) {
4442 scmd->result = DID_OK << 16;
4443 goto out;
4444 }
4445
4446 sas_device_priv_data = scmd->device->hostdata;
4447 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4448 sas_device_priv_data->sas_target->deleted) {
4449 scmd->result = DID_NO_CONNECT << 16;
4450 goto out;
4451 }
nagalakshmi.nandigama@lsi.com4da7af92011-12-01 07:53:02 +05304452 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304453 /*
4454 * WARPDRIVE: If direct_io is set then it is directIO,
4455 * the failed direct I/O should be redirected to volume
4456 */
nagalakshmi.nandigama@lsi.com4da7af92011-12-01 07:53:02 +05304457 if (_scsih_scsi_direct_io_get(ioc, smid) &&
4458 ((ioc_status & MPI2_IOCSTATUS_MASK)
4459 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
Kashyap, Desai82a45252011-07-05 12:40:23 +05304460 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4461 ioc->scsi_lookup[smid - 1].scmd = scmd;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304462 _scsih_scsi_direct_io_set(ioc, smid, 0);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05304463 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304464 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4465 mpi_request->DevHandle =
4466 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4467 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4468 sas_device_priv_data->sas_target->handle);
4469 return 0;
4470 }
4471
Eric Moore635374e2009-03-09 01:21:12 -06004472
4473 /* turning off TLR */
Kashyap, Desai9982f592009-09-23 17:23:07 +05304474 scsi_state = mpi_reply->SCSIState;
4475 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4476 response_code =
4477 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
Eric Moore635374e2009-03-09 01:21:12 -06004478 if (!sas_device_priv_data->tlr_snoop_check) {
4479 sas_device_priv_data->tlr_snoop_check++;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304480 /* Make sure Device is not raid volume.
4481 * We do not expose raid functionality to upper layer for warpdrive.
4482 */
4483 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Kashyap, Desai3ed21522010-02-17 16:08:36 +05304484 sas_is_tlr_enabled(scmd->device) &&
Kashyap, Desai84f0b042009-12-16 18:56:28 +05304485 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4486 sas_disable_tlr(scmd->device);
4487 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4488 }
Eric Moore635374e2009-03-09 01:21:12 -06004489 }
4490
4491 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4492 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
Eric Moore635374e2009-03-09 01:21:12 -06004493 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4494 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4495 else
4496 log_info = 0;
4497 ioc_status &= MPI2_IOCSTATUS_MASK;
Eric Moore635374e2009-03-09 01:21:12 -06004498 scsi_status = mpi_reply->SCSIStatus;
4499
4500 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4501 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4502 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4503 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4504 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4505 }
4506
4507 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4508 struct sense_info data;
4509 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4510 smid);
Eric Moore0d04df92009-04-21 15:38:43 -06004511 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
Eric Moore635374e2009-03-09 01:21:12 -06004512 le32_to_cpu(mpi_reply->SenseCount));
Eric Moore0d04df92009-04-21 15:38:43 -06004513 memcpy(scmd->sense_buffer, sense_data, sz);
Eric Moore635374e2009-03-09 01:21:12 -06004514 _scsih_normalize_sense(scmd->sense_buffer, &data);
4515 /* failure prediction threshold exceeded */
4516 if (data.asc == 0x5D)
4517 _scsih_smart_predicted_fault(ioc,
4518 le16_to_cpu(mpi_reply->DevHandle));
4519 }
4520
4521 switch (ioc_status) {
4522 case MPI2_IOCSTATUS_BUSY:
4523 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4524 scmd->result = SAM_STAT_BUSY;
4525 break;
4526
4527 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4528 scmd->result = DID_NO_CONNECT << 16;
4529 break;
4530
4531 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4532 if (sas_device_priv_data->block) {
Kashyap, Desaie4e7c7e2009-09-23 17:33:14 +05304533 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4534 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06004535 }
nagalakshmi.nandigama@lsi.com3ade1ca2011-12-01 07:42:40 +05304536 scmd->result = DID_SOFT_ERROR << 16;
4537 break;
Eric Moore635374e2009-03-09 01:21:12 -06004538 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4539 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4540 scmd->result = DID_RESET << 16;
4541 break;
4542
4543 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4544 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4545 scmd->result = DID_SOFT_ERROR << 16;
4546 else
4547 scmd->result = (DID_OK << 16) | scsi_status;
4548 break;
4549
4550 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4551 scmd->result = (DID_OK << 16) | scsi_status;
4552
4553 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4554 break;
4555
4556 if (xfer_cnt < scmd->underflow) {
4557 if (scsi_status == SAM_STAT_BUSY)
4558 scmd->result = SAM_STAT_BUSY;
4559 else
4560 scmd->result = DID_SOFT_ERROR << 16;
4561 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4562 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4563 scmd->result = DID_SOFT_ERROR << 16;
4564 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4565 scmd->result = DID_RESET << 16;
4566 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4567 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4568 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4569 scmd->result = (DRIVER_SENSE << 24) |
4570 SAM_STAT_CHECK_CONDITION;
4571 scmd->sense_buffer[0] = 0x70;
4572 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4573 scmd->sense_buffer[12] = 0x20;
4574 scmd->sense_buffer[13] = 0;
4575 }
4576 break;
4577
4578 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4579 scsi_set_resid(scmd, 0);
4580 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4581 case MPI2_IOCSTATUS_SUCCESS:
4582 scmd->result = (DID_OK << 16) | scsi_status;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304583 if (response_code ==
4584 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4585 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4586 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
Eric Moore635374e2009-03-09 01:21:12 -06004587 scmd->result = DID_SOFT_ERROR << 16;
4588 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4589 scmd->result = DID_RESET << 16;
4590 break;
4591
Eric Moore3c621b32009-05-18 12:59:41 -06004592 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4593 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4594 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4595 _scsih_eedp_error_handling(scmd, ioc_status);
4596 break;
Eric Moore635374e2009-03-09 01:21:12 -06004597 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4598 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4599 case MPI2_IOCSTATUS_INVALID_SGL:
4600 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4601 case MPI2_IOCSTATUS_INVALID_FIELD:
4602 case MPI2_IOCSTATUS_INVALID_STATE:
4603 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4604 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4605 default:
4606 scmd->result = DID_SOFT_ERROR << 16;
4607 break;
4608
4609 }
4610
4611#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4612 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4613 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4614#endif
4615
4616 out:
4617 scsi_dma_unmap(scmd);
4618 scmd->scsi_done(scmd);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304619 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004620}
4621
4622/**
Eric Moore635374e2009-03-09 01:21:12 -06004623 * _scsih_sas_host_refresh - refreshing sas host object contents
4624 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06004625 * Context: user
4626 *
4627 * During port enable, fw will send topology events for every device. Its
4628 * possible that the handles may change from the previous setting, so this
4629 * code keeping handles updating if changed.
4630 *
4631 * Return nothing.
4632 */
4633static void
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304634_scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06004635{
4636 u16 sz;
4637 u16 ioc_status;
4638 int i;
4639 Mpi2ConfigReply_t mpi_reply;
4640 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304641 u16 attached_handle;
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304642 u8 link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06004643
4644 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4645 "updating handles for sas_host(0x%016llx)\n",
4646 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4647
4648 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4649 * sizeof(Mpi2SasIOUnit0PhyData_t));
4650 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4651 if (!sas_iounit_pg0) {
4652 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4653 ioc->name, __FILE__, __LINE__, __func__);
4654 return;
4655 }
Eric Moore635374e2009-03-09 01:21:12 -06004656
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304657 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4658 sas_iounit_pg0, sz)) != 0)
4659 goto out;
4660 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4661 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4662 goto out;
4663 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304664 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304665 if (i == 0)
4666 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4667 PhyData[0].ControllerDevHandle);
4668 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4669 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4670 AttachedDevHandle);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304671 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4672 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304673 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304674 attached_handle, i, link_rate);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304675 }
Eric Moore635374e2009-03-09 01:21:12 -06004676 out:
4677 kfree(sas_iounit_pg0);
4678}
4679
4680/**
4681 * _scsih_sas_host_add - create sas host object
4682 * @ioc: per adapter object
4683 *
4684 * Creating host side data object, stored in ioc->sas_hba
4685 *
4686 * Return nothing.
4687 */
4688static void
4689_scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4690{
4691 int i;
4692 Mpi2ConfigReply_t mpi_reply;
4693 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4694 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4695 Mpi2SasPhyPage0_t phy_pg0;
4696 Mpi2SasDevicePage0_t sas_device_pg0;
4697 Mpi2SasEnclosurePage0_t enclosure_pg0;
4698 u16 ioc_status;
4699 u16 sz;
4700 u16 device_missing_delay;
4701
4702 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4703 if (!ioc->sas_hba.num_phys) {
4704 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4705 ioc->name, __FILE__, __LINE__, __func__);
4706 return;
4707 }
4708
4709 /* sas_iounit page 0 */
4710 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4711 sizeof(Mpi2SasIOUnit0PhyData_t));
4712 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4713 if (!sas_iounit_pg0) {
4714 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4715 ioc->name, __FILE__, __LINE__, __func__);
4716 return;
4717 }
4718 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4719 sas_iounit_pg0, sz))) {
4720 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4721 ioc->name, __FILE__, __LINE__, __func__);
4722 goto out;
4723 }
4724 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4725 MPI2_IOCSTATUS_MASK;
4726 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4727 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4728 ioc->name, __FILE__, __LINE__, __func__);
4729 goto out;
4730 }
4731
4732 /* sas_iounit page 1 */
4733 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4734 sizeof(Mpi2SasIOUnit1PhyData_t));
4735 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4736 if (!sas_iounit_pg1) {
4737 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4738 ioc->name, __FILE__, __LINE__, __func__);
4739 goto out;
4740 }
4741 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4742 sas_iounit_pg1, sz))) {
4743 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4744 ioc->name, __FILE__, __LINE__, __func__);
4745 goto out;
4746 }
4747 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4748 MPI2_IOCSTATUS_MASK;
4749 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4750 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4751 ioc->name, __FILE__, __LINE__, __func__);
4752 goto out;
4753 }
4754
4755 ioc->io_missing_delay =
4756 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4757 device_missing_delay =
4758 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4759 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4760 ioc->device_missing_delay = (device_missing_delay &
4761 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4762 else
4763 ioc->device_missing_delay = device_missing_delay &
4764 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4765
4766 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4767 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4768 sizeof(struct _sas_phy), GFP_KERNEL);
4769 if (!ioc->sas_hba.phy) {
4770 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4771 ioc->name, __FILE__, __LINE__, __func__);
4772 goto out;
4773 }
4774 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4775 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4776 i))) {
4777 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4778 ioc->name, __FILE__, __LINE__, __func__);
4779 goto out;
4780 }
4781 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4782 MPI2_IOCSTATUS_MASK;
4783 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4784 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4785 ioc->name, __FILE__, __LINE__, __func__);
4786 goto out;
4787 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304788
4789 if (i == 0)
4790 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4791 PhyData[0].ControllerDevHandle);
4792 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
Eric Moore635374e2009-03-09 01:21:12 -06004793 ioc->sas_hba.phy[i].phy_id = i;
4794 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4795 phy_pg0, ioc->sas_hba.parent_dev);
4796 }
4797 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304798 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06004799 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4800 ioc->name, __FILE__, __LINE__, __func__);
4801 goto out;
4802 }
Eric Moore635374e2009-03-09 01:21:12 -06004803 ioc->sas_hba.enclosure_handle =
4804 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4805 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4806 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4807 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4808 (unsigned long long) ioc->sas_hba.sas_address,
4809 ioc->sas_hba.num_phys) ;
4810
4811 if (ioc->sas_hba.enclosure_handle) {
4812 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4813 &enclosure_pg0,
4814 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4815 ioc->sas_hba.enclosure_handle))) {
4816 ioc->sas_hba.enclosure_logical_id =
4817 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4818 }
4819 }
4820
4821 out:
4822 kfree(sas_iounit_pg1);
4823 kfree(sas_iounit_pg0);
4824}
4825
4826/**
4827 * _scsih_expander_add - creating expander object
4828 * @ioc: per adapter object
4829 * @handle: expander handle
4830 *
4831 * Creating expander object, stored in ioc->sas_expander_list.
4832 *
4833 * Return 0 for success, else error.
4834 */
4835static int
4836_scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4837{
4838 struct _sas_node *sas_expander;
4839 Mpi2ConfigReply_t mpi_reply;
4840 Mpi2ExpanderPage0_t expander_pg0;
4841 Mpi2ExpanderPage1_t expander_pg1;
4842 Mpi2SasEnclosurePage0_t enclosure_pg0;
4843 u32 ioc_status;
4844 u16 parent_handle;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05304845 u64 sas_address, sas_address_parent = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004846 int i;
4847 unsigned long flags;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304848 struct _sas_port *mpt2sas_port = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06004849 int rc = 0;
4850
4851 if (!handle)
4852 return -1;
4853
Eric Moore3cb54692010-07-08 14:44:34 -06004854 if (ioc->shost_recovery || ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05304855 return -1;
4856
Eric Moore635374e2009-03-09 01:21:12 -06004857 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4858 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4859 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4860 ioc->name, __FILE__, __LINE__, __func__);
4861 return -1;
4862 }
4863
4864 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4865 MPI2_IOCSTATUS_MASK;
4866 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4867 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4868 ioc->name, __FILE__, __LINE__, __func__);
4869 return -1;
4870 }
4871
4872 /* handle out of order topology events */
4873 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304874 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4875 != 0) {
4876 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4877 ioc->name, __FILE__, __LINE__, __func__);
4878 return -1;
4879 }
4880 if (sas_address_parent != ioc->sas_hba.sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06004881 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304882 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4883 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004884 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4885 if (!sas_expander) {
4886 rc = _scsih_expander_add(ioc, parent_handle);
4887 if (rc != 0)
4888 return rc;
4889 }
4890 }
4891
Eric Moore635374e2009-03-09 01:21:12 -06004892 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304893 sas_address = le64_to_cpu(expander_pg0.SASAddress);
Eric Moore635374e2009-03-09 01:21:12 -06004894 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4895 sas_address);
4896 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4897
4898 if (sas_expander)
4899 return 0;
4900
4901 sas_expander = kzalloc(sizeof(struct _sas_node),
4902 GFP_KERNEL);
4903 if (!sas_expander) {
4904 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4905 ioc->name, __FILE__, __LINE__, __func__);
4906 return -1;
4907 }
4908
4909 sas_expander->handle = handle;
4910 sas_expander->num_phys = expander_pg0.NumPhys;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304911 sas_expander->sas_address_parent = sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06004912 sas_expander->sas_address = sas_address;
4913
4914 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4915 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304916 handle, parent_handle, (unsigned long long)
Eric Moore635374e2009-03-09 01:21:12 -06004917 sas_expander->sas_address, sas_expander->num_phys);
4918
4919 if (!sas_expander->num_phys)
4920 goto out_fail;
4921 sas_expander->phy = kcalloc(sas_expander->num_phys,
4922 sizeof(struct _sas_phy), GFP_KERNEL);
4923 if (!sas_expander->phy) {
4924 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4925 ioc->name, __FILE__, __LINE__, __func__);
4926 rc = -1;
4927 goto out_fail;
4928 }
4929
4930 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4931 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304932 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004933 if (!mpt2sas_port) {
4934 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4935 ioc->name, __FILE__, __LINE__, __func__);
4936 rc = -1;
4937 goto out_fail;
4938 }
4939 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4940
4941 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4942 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4943 &expander_pg1, i, handle))) {
4944 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4945 ioc->name, __FILE__, __LINE__, __func__);
Kashyap, Desai20f58952009-08-07 19:34:26 +05304946 rc = -1;
4947 goto out_fail;
Eric Moore635374e2009-03-09 01:21:12 -06004948 }
4949 sas_expander->phy[i].handle = handle;
4950 sas_expander->phy[i].phy_id = i;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304951
4952 if ((mpt2sas_transport_add_expander_phy(ioc,
4953 &sas_expander->phy[i], expander_pg1,
4954 sas_expander->parent_dev))) {
4955 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4956 ioc->name, __FILE__, __LINE__, __func__);
4957 rc = -1;
4958 goto out_fail;
4959 }
Eric Moore635374e2009-03-09 01:21:12 -06004960 }
4961
4962 if (sas_expander->enclosure_handle) {
4963 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4964 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4965 sas_expander->enclosure_handle))) {
4966 sas_expander->enclosure_logical_id =
4967 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4968 }
4969 }
4970
4971 _scsih_expander_node_add(ioc, sas_expander);
4972 return 0;
4973
4974 out_fail:
4975
Kashyap, Desai20f58952009-08-07 19:34:26 +05304976 if (mpt2sas_port)
4977 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304978 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004979 kfree(sas_expander);
4980 return rc;
4981}
4982
4983/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05304984 * _scsih_done - scsih callback handler.
4985 * @ioc: per adapter object
4986 * @smid: system request message index
4987 * @msix_index: MSIX table index supplied by the OS
4988 * @reply: reply message frame(lower 32bit addr)
4989 *
4990 * Callback handler when sending internal generated message frames.
4991 * The callback index passed is `ioc->scsih_cb_idx`
4992 *
4993 * Return 1 meaning mf should be freed from _base_interrupt
4994 * 0 means the mf is freed from this function.
4995 */
4996static u8
4997_scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4998{
4999 MPI2DefaultReply_t *mpi_reply;
5000
5001 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5002 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
5003 return 1;
5004 if (ioc->scsih_cmds.smid != smid)
5005 return 1;
5006 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
5007 if (mpi_reply) {
5008 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5009 mpi_reply->MsgLength*4);
5010 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
5011 }
5012 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
5013 complete(&ioc->scsih_cmds.done);
5014 return 1;
5015}
5016
5017/**
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305018 * mpt2sas_expander_remove - removing expander object
Eric Moore635374e2009-03-09 01:21:12 -06005019 * @ioc: per adapter object
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305020 * @sas_address: expander sas_address
Eric Moore635374e2009-03-09 01:21:12 -06005021 *
5022 * Return nothing.
5023 */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305024void
5025mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06005026{
5027 struct _sas_node *sas_expander;
5028 unsigned long flags;
5029
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305030 if (ioc->shost_recovery)
5031 return;
5032
Eric Moore635374e2009-03-09 01:21:12 -06005033 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305034 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5035 sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305036 if (sas_expander)
5037 list_del(&sas_expander->list);
Eric Moore635374e2009-03-09 01:21:12 -06005038 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305039 if (sas_expander)
5040 _scsih_expander_node_remove(ioc, sas_expander);
Eric Moore635374e2009-03-09 01:21:12 -06005041}
5042
5043/**
Kashyap, Desaib4344272010-03-17 16:24:14 +05305044 * _scsih_check_access_status - check access flags
5045 * @ioc: per adapter object
5046 * @sas_address: sas address
5047 * @handle: sas device handle
5048 * @access_flags: errors returned during discovery of the device
5049 *
5050 * Return 0 for success, else failure
5051 */
5052static u8
5053_scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5054 u16 handle, u8 access_status)
5055{
5056 u8 rc = 1;
5057 char *desc = NULL;
5058
5059 switch (access_status) {
5060 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5061 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5062 rc = 0;
5063 break;
5064 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5065 desc = "sata capability failed";
5066 break;
5067 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5068 desc = "sata affiliation conflict";
5069 break;
5070 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5071 desc = "route not addressable";
5072 break;
5073 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5074 desc = "smp error not addressable";
5075 break;
5076 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5077 desc = "device blocked";
5078 break;
5079 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5080 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5081 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5082 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5083 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5084 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5085 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5086 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5087 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5088 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5089 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5090 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5091 desc = "sata initialization failed";
5092 break;
5093 default:
5094 desc = "unknown";
5095 break;
5096 }
5097
5098 if (!rc)
5099 return 0;
5100
5101 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5102 "handle(0x%04x)\n", ioc->name, desc,
5103 (unsigned long long)sas_address, handle);
5104 return rc;
5105}
5106
5107static void
5108_scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5109{
5110 Mpi2ConfigReply_t mpi_reply;
5111 Mpi2SasDevicePage0_t sas_device_pg0;
5112 struct _sas_device *sas_device;
5113 u32 ioc_status;
5114 unsigned long flags;
5115 u64 sas_address;
5116 struct scsi_target *starget;
5117 struct MPT2SAS_TARGET *sas_target_priv_data;
5118 u32 device_info;
5119
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305120
Kashyap, Desaib4344272010-03-17 16:24:14 +05305121 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5122 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5123 return;
5124
5125 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5126 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5127 return;
5128
5129 /* check if this is end device */
5130 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5131 if (!(_scsih_is_end_device(device_info)))
5132 return;
5133
5134 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5135 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5136 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5137 sas_address);
5138
5139 if (!sas_device) {
5140 printk(MPT2SAS_ERR_FMT "device is not present "
5141 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5142 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5143 return;
5144 }
5145
5146 if (unlikely(sas_device->handle != handle)) {
5147 starget = sas_device->starget;
5148 sas_target_priv_data = starget->hostdata;
5149 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5150 " to (0x%04x)!!!\n", sas_device->handle, handle);
5151 sas_target_priv_data->handle = handle;
5152 sas_device->handle = handle;
5153 }
Kashyap, Desaib4344272010-03-17 16:24:14 +05305154
5155 /* check if device is present */
5156 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5157 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5158 printk(MPT2SAS_ERR_FMT "device is not present "
5159 "handle(0x%04x), flags!!!\n", ioc->name, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305160 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305161 return;
5162 }
5163
5164 /* check if there were any issues with discovery */
5165 if (_scsih_check_access_status(ioc, sas_address, handle,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305166 sas_device_pg0.AccessStatus)) {
5167 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305168 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305169 }
5170 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05305171 _scsih_ublock_io_device(ioc, sas_address);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305172
5173}
5174
5175/**
Eric Moore635374e2009-03-09 01:21:12 -06005176 * _scsih_add_device - creating sas device object
5177 * @ioc: per adapter object
5178 * @handle: sas device handle
5179 * @phy_num: phy number end device attached to
5180 * @is_pd: is this hidden raid component
5181 *
5182 * Creating end device object, stored in ioc->sas_device_list.
5183 *
5184 * Returns 0 for success, non-zero for failure.
5185 */
5186static int
5187_scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5188{
5189 Mpi2ConfigReply_t mpi_reply;
5190 Mpi2SasDevicePage0_t sas_device_pg0;
5191 Mpi2SasEnclosurePage0_t enclosure_pg0;
5192 struct _sas_device *sas_device;
5193 u32 ioc_status;
5194 __le64 sas_address;
5195 u32 device_info;
5196 unsigned long flags;
5197
5198 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5199 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5200 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5201 ioc->name, __FILE__, __LINE__, __func__);
5202 return -1;
5203 }
5204
5205 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5206 MPI2_IOCSTATUS_MASK;
5207 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5208 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5209 ioc->name, __FILE__, __LINE__, __func__);
5210 return -1;
5211 }
5212
Kashyap, Desaib4344272010-03-17 16:24:14 +05305213 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5214
Eric Moore635374e2009-03-09 01:21:12 -06005215 /* check if device is present */
5216 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5217 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5218 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5219 ioc->name, __FILE__, __LINE__, __func__);
5220 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5221 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5222 return -1;
5223 }
5224
Kashyap, Desaib4344272010-03-17 16:24:14 +05305225 /* check if there were any issues with discovery */
5226 if (_scsih_check_access_status(ioc, sas_address, handle,
5227 sas_device_pg0.AccessStatus))
Eric Moore635374e2009-03-09 01:21:12 -06005228 return -1;
Eric Moore635374e2009-03-09 01:21:12 -06005229
5230 /* check if this is end device */
5231 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5232 if (!(_scsih_is_end_device(device_info))) {
5233 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5234 ioc->name, __FILE__, __LINE__, __func__);
5235 return -1;
5236 }
5237
Eric Moore635374e2009-03-09 01:21:12 -06005238
5239 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5240 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5241 sas_address);
5242 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5243
Kashyap, Desaib4344272010-03-17 16:24:14 +05305244 if (sas_device)
Eric Moore635374e2009-03-09 01:21:12 -06005245 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06005246
5247 sas_device = kzalloc(sizeof(struct _sas_device),
5248 GFP_KERNEL);
5249 if (!sas_device) {
5250 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5251 ioc->name, __FILE__, __LINE__, __func__);
5252 return -1;
5253 }
5254
5255 sas_device->handle = handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305256 if (_scsih_get_sas_address(ioc, le16_to_cpu
5257 (sas_device_pg0.ParentDevHandle),
5258 &sas_device->sas_address_parent) != 0)
5259 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5260 ioc->name, __FILE__, __LINE__, __func__);
Eric Moore635374e2009-03-09 01:21:12 -06005261 sas_device->enclosure_handle =
5262 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5263 sas_device->slot =
5264 le16_to_cpu(sas_device_pg0.Slot);
5265 sas_device->device_info = device_info;
5266 sas_device->sas_address = sas_address;
Kashyap, Desai7fbae672010-06-17 13:45:17 +05305267 sas_device->phy = sas_device_pg0.PhyNum;
Eric Moore635374e2009-03-09 01:21:12 -06005268
5269 /* get enclosure_logical_id */
Kashyap, Desai15052c92009-08-07 19:33:17 +05305270 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5271 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5272 sas_device->enclosure_handle)))
Eric Moore635374e2009-03-09 01:21:12 -06005273 sas_device->enclosure_logical_id =
5274 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
Eric Moore635374e2009-03-09 01:21:12 -06005275
5276 /* get device name */
5277 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5278
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305279 if (ioc->wait_for_discovery_to_complete)
Eric Moore635374e2009-03-09 01:21:12 -06005280 _scsih_sas_device_init_add(ioc, sas_device);
5281 else
5282 _scsih_sas_device_add(ioc, sas_device);
5283
5284 return 0;
5285}
5286
5287/**
Kashyap, Desai1278b112010-03-09 17:34:13 +05305288 * _scsih_remove_device - removing sas device object
5289 * @ioc: per adapter object
5290 * @sas_device_delete: the sas_device object
5291 *
5292 * Return nothing.
5293 */
5294static void
5295_scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5296 struct _sas_device *sas_device)
5297{
Kashyap, Desai1278b112010-03-09 17:34:13 +05305298 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05305299
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05305300 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5301 (sas_device->pfa_led_on)) {
5302 _scsih_turn_off_pfa_led(ioc, sas_device);
5303 sas_device->pfa_led_on = 0;
5304 }
5305
Kashyap, Desai1278b112010-03-09 17:34:13 +05305306 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5307 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305308 sas_device->handle, (unsigned long long)
5309 sas_device->sas_address));
Kashyap, Desai1278b112010-03-09 17:34:13 +05305310
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305311 if (sas_device->starget && sas_device->starget->hostdata) {
5312 sas_target_priv_data = sas_device->starget->hostdata;
Kashyap, Desai1278b112010-03-09 17:34:13 +05305313 sas_target_priv_data->deleted = 1;
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05305314 _scsih_ublock_io_device(ioc, sas_device->sas_address);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305315 sas_target_priv_data->handle =
5316 MPT2SAS_INVALID_DEVICE_HANDLE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05305317 }
5318
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05305319 if (!ioc->hide_drives)
5320 mpt2sas_transport_port_remove(ioc,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305321 sas_device->sas_address,
5322 sas_device->sas_address_parent);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305323
5324 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305325 "(0x%016llx)\n", ioc->name, sas_device->handle,
5326 (unsigned long long) sas_device->sas_address);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305327
5328 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5329 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305330 sas_device->handle, (unsigned long long)
5331 sas_device->sas_address));
5332 kfree(sas_device);
5333}
5334/**
5335 * _scsih_device_remove_by_handle - removing device object by handle
5336 * @ioc: per adapter object
5337 * @handle: device handle
5338 *
5339 * Return nothing.
5340 */
5341static void
5342_scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5343{
5344 struct _sas_device *sas_device;
5345 unsigned long flags;
5346
5347 if (ioc->shost_recovery)
5348 return;
5349
5350 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5351 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5352 if (sas_device)
5353 list_del(&sas_device->list);
5354 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5355 if (sas_device)
5356 _scsih_remove_device(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -06005357}
5358
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305359/**
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305360 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305361 * @ioc: per adapter object
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305362 * @sas_address: device sas_address
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305363 *
5364 * Return nothing.
5365 */
5366void
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305367mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
5368 u64 sas_address)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305369{
5370 struct _sas_device *sas_device;
5371 unsigned long flags;
5372
5373 if (ioc->shost_recovery)
5374 return;
5375
5376 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5377 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5378 sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305379 if (sas_device)
5380 list_del(&sas_device->list);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305381 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305382 if (sas_device)
5383 _scsih_remove_device(ioc, sas_device);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305384}
Eric Moore635374e2009-03-09 01:21:12 -06005385#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5386/**
5387 * _scsih_sas_topology_change_event_debug - debug for topology event
5388 * @ioc: per adapter object
5389 * @event_data: event data payload
5390 * Context: user.
5391 */
5392static void
5393_scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5394 Mpi2EventDataSasTopologyChangeList_t *event_data)
5395{
5396 int i;
5397 u16 handle;
5398 u16 reason_code;
5399 u8 phy_number;
5400 char *status_str = NULL;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305401 u8 link_rate, prev_link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06005402
5403 switch (event_data->ExpStatus) {
5404 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5405 status_str = "add";
5406 break;
5407 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5408 status_str = "remove";
5409 break;
5410 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305411 case 0:
Eric Moore635374e2009-03-09 01:21:12 -06005412 status_str = "responding";
5413 break;
5414 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5415 status_str = "remove delay";
5416 break;
5417 default:
5418 status_str = "unknown status";
5419 break;
5420 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305421 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
Eric Moore635374e2009-03-09 01:21:12 -06005422 ioc->name, status_str);
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305423 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
Eric Moore635374e2009-03-09 01:21:12 -06005424 "start_phy(%02d), count(%d)\n",
5425 le16_to_cpu(event_data->ExpanderDevHandle),
5426 le16_to_cpu(event_data->EnclosureHandle),
5427 event_data->StartPhyNum, event_data->NumEntries);
5428 for (i = 0; i < event_data->NumEntries; i++) {
5429 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5430 if (!handle)
5431 continue;
5432 phy_number = event_data->StartPhyNum + i;
5433 reason_code = event_data->PHY[i].PhyStatus &
5434 MPI2_EVENT_SAS_TOPO_RC_MASK;
5435 switch (reason_code) {
5436 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305437 status_str = "target add";
Eric Moore635374e2009-03-09 01:21:12 -06005438 break;
5439 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305440 status_str = "target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005441 break;
5442 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305443 status_str = "delay target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005444 break;
5445 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305446 status_str = "link rate change";
Eric Moore635374e2009-03-09 01:21:12 -06005447 break;
5448 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305449 status_str = "target responding";
Eric Moore635374e2009-03-09 01:21:12 -06005450 break;
5451 default:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305452 status_str = "unknown";
Eric Moore635374e2009-03-09 01:21:12 -06005453 break;
5454 }
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305455 link_rate = event_data->PHY[i].LinkRate >> 4;
5456 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305457 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305458 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5459 handle, status_str, link_rate, prev_link_rate);
5460
Eric Moore635374e2009-03-09 01:21:12 -06005461 }
5462}
5463#endif
5464
5465/**
5466 * _scsih_sas_topology_change_event - handle topology changes
5467 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305468 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005469 * Context: user.
5470 *
5471 */
5472static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305473_scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
Eric Moore635374e2009-03-09 01:21:12 -06005474 struct fw_event_work *fw_event)
5475{
5476 int i;
5477 u16 parent_handle, handle;
5478 u16 reason_code;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305479 u8 phy_number, max_phys;
Eric Moore635374e2009-03-09 01:21:12 -06005480 struct _sas_node *sas_expander;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305481 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06005482 unsigned long flags;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305483 u8 link_rate, prev_link_rate;
Joe Lawrence00713ad2014-06-25 17:03:33 -04005484 Mpi2EventDataSasTopologyChangeList_t *event_data =
5485 (Mpi2EventDataSasTopologyChangeList_t *)
5486 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06005487
5488#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5489 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5490 _scsih_sas_topology_change_event_debug(ioc, event_data);
5491#endif
5492
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305493 if (ioc->remove_host || ioc->pci_error_recovery)
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305494 return;
5495
Eric Moore635374e2009-03-09 01:21:12 -06005496 if (!ioc->sas_hba.num_phys)
5497 _scsih_sas_host_add(ioc);
5498 else
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305499 _scsih_sas_host_refresh(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005500
5501 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305502 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
Eric Moore635374e2009-03-09 01:21:12 -06005503 "event\n", ioc->name));
5504 return;
5505 }
5506
5507 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5508
5509 /* handle expander add */
5510 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5511 if (_scsih_expander_add(ioc, parent_handle) != 0)
5512 return;
5513
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305514 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5515 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5516 parent_handle);
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305517 if (sas_expander) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305518 sas_address = sas_expander->sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305519 max_phys = sas_expander->num_phys;
5520 } else if (parent_handle < ioc->sas_hba.num_phys) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305521 sas_address = ioc->sas_hba.sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305522 max_phys = ioc->sas_hba.num_phys;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305523 } else {
5524 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305525 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305526 }
5527 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305528
Eric Moore635374e2009-03-09 01:21:12 -06005529 /* handle siblings events */
5530 for (i = 0; i < event_data->NumEntries; i++) {
5531 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305532 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
Eric Moore635374e2009-03-09 01:21:12 -06005533 "expander event\n", ioc->name));
5534 return;
5535 }
Eric Moore3cb54692010-07-08 14:44:34 -06005536 if (ioc->shost_recovery || ioc->remove_host ||
5537 ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305538 return;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305539 phy_number = event_data->StartPhyNum + i;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305540 if (phy_number >= max_phys)
5541 continue;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305542 reason_code = event_data->PHY[i].PhyStatus &
5543 MPI2_EVENT_SAS_TOPO_RC_MASK;
5544 if ((event_data->PHY[i].PhyStatus &
5545 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5546 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
Eric Moore635374e2009-03-09 01:21:12 -06005547 continue;
5548 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5549 if (!handle)
5550 continue;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305551 link_rate = event_data->PHY[i].LinkRate >> 4;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305552 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Eric Moore635374e2009-03-09 01:21:12 -06005553 switch (reason_code) {
5554 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305555
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305556 if (ioc->shost_recovery)
5557 break;
5558
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305559 if (link_rate == prev_link_rate)
5560 break;
5561
5562 mpt2sas_transport_update_links(ioc, sas_address,
5563 handle, phy_number, link_rate);
5564
Kashyap, Desaib4344272010-03-17 16:24:14 +05305565 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5566 break;
5567
5568 _scsih_check_device(ioc, handle);
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305569 break;
Eric Moore635374e2009-03-09 01:21:12 -06005570 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305571
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305572 if (ioc->shost_recovery)
5573 break;
5574
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305575 mpt2sas_transport_update_links(ioc, sas_address,
5576 handle, phy_number, link_rate);
5577
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305578 _scsih_add_device(ioc, handle, phy_number, 0);
Eric Moore635374e2009-03-09 01:21:12 -06005579 break;
5580 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305581
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305582 _scsih_device_remove_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06005583 break;
5584 }
5585 }
5586
5587 /* handle expander removal */
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305588 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5589 sas_expander)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305590 mpt2sas_expander_remove(ioc, sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06005591
5592}
5593
5594#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5595/**
5596 * _scsih_sas_device_status_change_event_debug - debug for device event
5597 * @event_data: event data payload
5598 * Context: user.
5599 *
5600 * Return nothing.
5601 */
5602static void
5603_scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5604 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5605{
5606 char *reason_str = NULL;
5607
5608 switch (event_data->ReasonCode) {
5609 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5610 reason_str = "smart data";
5611 break;
5612 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5613 reason_str = "unsupported device discovered";
5614 break;
5615 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5616 reason_str = "internal device reset";
5617 break;
5618 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5619 reason_str = "internal task abort";
5620 break;
5621 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5622 reason_str = "internal task abort set";
5623 break;
5624 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5625 reason_str = "internal clear task set";
5626 break;
5627 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5628 reason_str = "internal query task";
5629 break;
5630 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5631 reason_str = "sata init failure";
5632 break;
5633 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5634 reason_str = "internal device reset complete";
5635 break;
5636 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5637 reason_str = "internal task abort complete";
5638 break;
5639 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5640 reason_str = "internal async notification";
5641 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05305642 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5643 reason_str = "expander reduced functionality";
5644 break;
5645 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5646 reason_str = "expander reduced functionality complete";
5647 break;
Eric Moore635374e2009-03-09 01:21:12 -06005648 default:
5649 reason_str = "unknown reason";
5650 break;
5651 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305652 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305653 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5654 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5655 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5656 le16_to_cpu(event_data->TaskTag));
Eric Moore635374e2009-03-09 01:21:12 -06005657 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305658 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005659 event_data->ASC, event_data->ASCQ);
5660 printk(KERN_INFO "\n");
5661}
5662#endif
5663
5664/**
5665 * _scsih_sas_device_status_change_event - handle device status change
5666 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305667 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005668 * Context: user.
5669 *
5670 * Return nothing.
5671 */
5672static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305673_scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5674 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005675{
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305676 struct MPT2SAS_TARGET *target_priv_data;
5677 struct _sas_device *sas_device;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05305678 u64 sas_address;
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305679 unsigned long flags;
5680 Mpi2EventDataSasDeviceStatusChange_t *event_data =
Joe Lawrence00713ad2014-06-25 17:03:33 -04005681 (Mpi2EventDataSasDeviceStatusChange_t *)
5682 fw_event->event_data;
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305683
Eric Moore635374e2009-03-09 01:21:12 -06005684#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5685 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305686 _scsih_sas_device_status_change_event_debug(ioc,
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305687 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005688#endif
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305689
Kashyap, Desaiefe82a12011-01-04 11:34:17 +05305690 /* In MPI Revision K (0xC), the internal device reset complete was
5691 * implemented, so avoid setting tm_busy flag for older firmware.
5692 */
5693 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5694 return;
5695
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305696 if (event_data->ReasonCode !=
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305697 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305698 event_data->ReasonCode !=
5699 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305700 return;
5701
5702 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5703 sas_address = le64_to_cpu(event_data->SASAddress);
5704 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5705 sas_address);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305706
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305707 if (!sas_device || !sas_device->starget) {
5708 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305709 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305710 }
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305711
5712 target_priv_data = sas_device->starget->hostdata;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305713 if (!target_priv_data) {
5714 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305715 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305716 }
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305717
5718 if (event_data->ReasonCode ==
5719 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5720 target_priv_data->tm_busy = 1;
5721 else
5722 target_priv_data->tm_busy = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305723 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005724}
5725
5726#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5727/**
5728 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5729 * @ioc: per adapter object
5730 * @event_data: event data payload
5731 * Context: user.
5732 *
5733 * Return nothing.
5734 */
5735static void
5736_scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5737 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5738{
5739 char *reason_str = NULL;
5740
5741 switch (event_data->ReasonCode) {
5742 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5743 reason_str = "enclosure add";
5744 break;
5745 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5746 reason_str = "enclosure remove";
5747 break;
5748 default:
5749 reason_str = "unknown reason";
5750 break;
5751 }
5752
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305753 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
Eric Moore635374e2009-03-09 01:21:12 -06005754 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5755 " number slots(%d)\n", ioc->name, reason_str,
5756 le16_to_cpu(event_data->EnclosureHandle),
5757 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5758 le16_to_cpu(event_data->StartSlot));
5759}
5760#endif
5761
5762/**
5763 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5764 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305765 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005766 * Context: user.
5767 *
5768 * Return nothing.
5769 */
5770static void
5771_scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305772 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005773{
5774#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5775 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5776 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
Joe Lawrence00713ad2014-06-25 17:03:33 -04005777 (Mpi2EventDataSasEnclDevStatusChange_t *)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305778 fw_event->event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005779#endif
5780}
5781
5782/**
Andrew Mortona78e21d2012-02-08 12:52:22 -08005783 * _scsih_sas_broadcast_primitive_event - handle broadcast events
Eric Moore635374e2009-03-09 01:21:12 -06005784 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305785 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005786 * Context: user.
5787 *
5788 * Return nothing.
5789 */
5790static void
Andrew Mortona78e21d2012-02-08 12:52:22 -08005791_scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305792 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005793{
5794 struct scsi_cmnd *scmd;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305795 struct scsi_device *sdev;
Eric Moore635374e2009-03-09 01:21:12 -06005796 u16 smid, handle;
5797 u32 lun;
5798 struct MPT2SAS_DEVICE *sas_device_priv_data;
5799 u32 termination_count;
5800 u32 query_count;
5801 Mpi2SCSITaskManagementReply_t *mpi_reply;
Joe Lawrence00713ad2014-06-25 17:03:33 -04005802 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5803 (Mpi2EventDataSasBroadcastPrimitive_t *)
5804 fw_event->event_data;
Kashyap, Desai463217b2009-10-05 15:53:06 +05305805 u16 ioc_status;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305806 unsigned long flags;
5807 int r;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305808 u8 max_retries = 0;
5809 u8 task_abort_retries;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305810
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305811 mutex_lock(&ioc->tm_cmds.mutex);
Reddy, Sreekanthc3a634b2013-02-26 17:36:12 +05305812 pr_info(MPT2SAS_FMT
5813 "%s: enter: phy number(%d), width(%d)\n",
5814 ioc->name, __func__, event_data->PhyNum,
5815 event_data->PortWidth);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305816
5817 _scsih_block_io_all_device(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005818
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305819 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305820 mpi_reply = ioc->tm_cmds.reply;
5821broadcast_aen_retry:
5822
5823 /* sanity checks for retrying this loop */
5824 if (max_retries++ == 5) {
5825 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5826 ioc->name, __func__));
5827 goto out;
5828 } else if (max_retries > 1)
5829 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5830 ioc->name, __func__, max_retries - 1));
5831
Eric Moore635374e2009-03-09 01:21:12 -06005832 termination_count = 0;
5833 query_count = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305834 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305835 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305836 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06005837 scmd = _scsih_scsi_lookup_get(ioc, smid);
5838 if (!scmd)
5839 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305840 sdev = scmd->device;
5841 sas_device_priv_data = sdev->hostdata;
Eric Moore635374e2009-03-09 01:21:12 -06005842 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5843 continue;
5844 /* skip hidden raid components */
5845 if (sas_device_priv_data->sas_target->flags &
5846 MPT_TARGET_FLAGS_RAID_COMPONENT)
5847 continue;
5848 /* skip volumes */
5849 if (sas_device_priv_data->sas_target->flags &
5850 MPT_TARGET_FLAGS_VOLUME)
5851 continue;
5852
5853 handle = sas_device_priv_data->sas_target->handle;
5854 lun = sas_device_priv_data->lun;
5855 query_count++;
5856
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305857 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305858 goto out;
5859
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305860 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305861 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04005862 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305863 TM_MUTEX_OFF);
5864 if (r == FAILED) {
5865 sdev_printk(KERN_WARNING, sdev,
5866 "mpt2sas_scsih_issue_tm: FAILED when sending "
5867 "QUERY_TASK: scmd(%p)\n", scmd);
5868 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5869 goto broadcast_aen_retry;
5870 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05305871 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5872 & MPI2_IOCSTATUS_MASK;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305873 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5874 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5875 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5876 scmd);
5877 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5878 goto broadcast_aen_retry;
5879 }
5880
5881 /* see if IO is still owned by IOC and target */
5882 if (mpi_reply->ResponseCode ==
Eric Moore635374e2009-03-09 01:21:12 -06005883 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5884 mpi_reply->ResponseCode ==
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305885 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305886 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005887 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305888 }
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305889 task_abort_retries = 0;
5890 tm_retry:
5891 if (task_abort_retries++ == 60) {
5892 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5893 "%s: ABORT_TASK: giving up\n", ioc->name,
5894 __func__));
5895 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5896 goto broadcast_aen_retry;
5897 }
5898
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305899 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305900 goto out_no_lock;
5901
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305902 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5903 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04005904 TM_MUTEX_OFF);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305905 if (r == FAILED) {
5906 sdev_printk(KERN_WARNING, sdev,
5907 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305908 "scmd(%p)\n", scmd);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305909 goto tm_retry;
5910 }
5911
5912 if (task_abort_retries > 1)
5913 sdev_printk(KERN_WARNING, sdev,
5914 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5915 " scmd(%p)\n",
5916 task_abort_retries - 1, scmd);
5917
Eric Moore635374e2009-03-09 01:21:12 -06005918 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305919 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005920 }
Eric Moore635374e2009-03-09 01:21:12 -06005921
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305922 if (ioc->broadcast_aen_pending) {
5923 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5924 " pending AEN\n", ioc->name, __func__));
5925 ioc->broadcast_aen_pending = 0;
5926 goto broadcast_aen_retry;
5927 }
5928
5929 out:
5930 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5931 out_no_lock:
5932
5933 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06005934 "%s - exit, query_count = %d termination_count = %d\n",
5935 ioc->name, __func__, query_count, termination_count));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305936
5937 ioc->broadcast_aen_busy = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305938 if (!ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305939 _scsih_ublock_io_all_device(ioc);
5940 mutex_unlock(&ioc->tm_cmds.mutex);
Eric Moore635374e2009-03-09 01:21:12 -06005941}
5942
5943/**
5944 * _scsih_sas_discovery_event - handle discovery events
5945 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305946 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005947 * Context: user.
5948 *
5949 * Return nothing.
5950 */
5951static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305952_scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5953 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005954{
Joe Lawrence00713ad2014-06-25 17:03:33 -04005955 Mpi2EventDataSasDiscovery_t *event_data =
5956 (Mpi2EventDataSasDiscovery_t *)
5957 fw_event->event_data;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305958
Eric Moore635374e2009-03-09 01:21:12 -06005959#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5960 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305961 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005962 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5963 "start" : "stop");
5964 if (event_data->DiscoveryStatus)
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305965 printk("discovery_status(0x%08x)",
5966 le32_to_cpu(event_data->DiscoveryStatus));
Eric Moore635374e2009-03-09 01:21:12 -06005967 printk("\n");
5968 }
5969#endif
5970
5971 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05305972 !ioc->sas_hba.num_phys) {
5973 if (disable_discovery > 0 && ioc->shost_recovery) {
5974 /* Wait for the reset to complete */
5975 while (ioc->shost_recovery)
5976 ssleep(1);
5977 }
Eric Moore635374e2009-03-09 01:21:12 -06005978 _scsih_sas_host_add(ioc);
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05305979 }
Eric Moore635374e2009-03-09 01:21:12 -06005980}
5981
5982/**
5983 * _scsih_reprobe_lun - reprobing lun
5984 * @sdev: scsi device struct
5985 * @no_uld_attach: sdev->no_uld_attach flag setting
5986 *
5987 **/
5988static void
5989_scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5990{
5991 int rc;
5992
5993 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5994 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5995 sdev->no_uld_attach ? "hidding" : "exposing");
5996 rc = scsi_device_reprobe(sdev);
5997}
5998
5999/**
Eric Moore635374e2009-03-09 01:21:12 -06006000 * _scsih_sas_volume_add - add new volume
6001 * @ioc: per adapter object
6002 * @element: IR config element data
6003 * Context: user.
6004 *
6005 * Return nothing.
6006 */
6007static void
6008_scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
6009 Mpi2EventIrConfigElement_t *element)
6010{
6011 struct _raid_device *raid_device;
6012 unsigned long flags;
6013 u64 wwid;
6014 u16 handle = le16_to_cpu(element->VolDevHandle);
6015 int rc;
6016
Eric Moore635374e2009-03-09 01:21:12 -06006017 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6018 if (!wwid) {
6019 printk(MPT2SAS_ERR_FMT
6020 "failure at %s:%d/%s()!\n", ioc->name,
6021 __FILE__, __LINE__, __func__);
6022 return;
6023 }
6024
6025 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6026 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6027 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6028
6029 if (raid_device)
6030 return;
6031
6032 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6033 if (!raid_device) {
6034 printk(MPT2SAS_ERR_FMT
6035 "failure at %s:%d/%s()!\n", ioc->name,
6036 __FILE__, __LINE__, __func__);
6037 return;
6038 }
6039
6040 raid_device->id = ioc->sas_id++;
6041 raid_device->channel = RAID_CHANNEL;
6042 raid_device->handle = handle;
6043 raid_device->wwid = wwid;
6044 _scsih_raid_device_add(ioc, raid_device);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306045 if (!ioc->wait_for_discovery_to_complete) {
Eric Moore635374e2009-03-09 01:21:12 -06006046 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6047 raid_device->id, 0);
6048 if (rc)
6049 _scsih_raid_device_remove(ioc, raid_device);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306050 } else {
6051 spin_lock_irqsave(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06006052 _scsih_determine_boot_device(ioc, raid_device, 1);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306053 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6054 }
Eric Moore635374e2009-03-09 01:21:12 -06006055}
6056
6057/**
6058 * _scsih_sas_volume_delete - delete volume
6059 * @ioc: per adapter object
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306060 * @handle: volume device handle
Eric Moore635374e2009-03-09 01:21:12 -06006061 * Context: user.
6062 *
6063 * Return nothing.
6064 */
6065static void
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306066_scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Eric Moore635374e2009-03-09 01:21:12 -06006067{
6068 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06006069 unsigned long flags;
6070 struct MPT2SAS_TARGET *sas_target_priv_data;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306071 struct scsi_target *starget = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006072
Eric Moore635374e2009-03-09 01:21:12 -06006073 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6074 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306075 if (raid_device) {
6076 if (raid_device->starget) {
6077 starget = raid_device->starget;
6078 sas_target_priv_data = starget->hostdata;
6079 sas_target_priv_data->deleted = 1;
6080 }
6081 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6082 "(0x%016llx)\n", ioc->name, raid_device->handle,
6083 (unsigned long long) raid_device->wwid);
6084 list_del(&raid_device->list);
6085 kfree(raid_device);
Eric Moore635374e2009-03-09 01:21:12 -06006086 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306087 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6088 if (starget)
6089 scsi_remove_target(&starget->dev);
Eric Moore635374e2009-03-09 01:21:12 -06006090}
6091
6092/**
6093 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6094 * @ioc: per adapter object
6095 * @element: IR config element data
6096 * Context: user.
6097 *
6098 * Return nothing.
6099 */
6100static void
6101_scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6102 Mpi2EventIrConfigElement_t *element)
6103{
6104 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306105 struct scsi_target *starget = NULL;
6106 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06006107 unsigned long flags;
6108 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6109
6110 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6111 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306112 if (sas_device) {
6113 sas_device->volume_handle = 0;
6114 sas_device->volume_wwid = 0;
6115 clear_bit(handle, ioc->pd_handles);
6116 if (sas_device->starget && sas_device->starget->hostdata) {
6117 starget = sas_device->starget;
6118 sas_target_priv_data = starget->hostdata;
6119 sas_target_priv_data->flags &=
6120 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6121 }
6122 }
Eric Moore635374e2009-03-09 01:21:12 -06006123 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6124 if (!sas_device)
6125 return;
6126
6127 /* exposing raid component */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306128 if (starget)
6129 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
Eric Moore635374e2009-03-09 01:21:12 -06006130}
6131
6132/**
6133 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6134 * @ioc: per adapter object
6135 * @element: IR config element data
6136 * Context: user.
6137 *
6138 * Return nothing.
6139 */
6140static void
6141_scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6142 Mpi2EventIrConfigElement_t *element)
6143{
6144 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306145 struct scsi_target *starget = NULL;
6146 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06006147 unsigned long flags;
6148 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306149 u16 volume_handle = 0;
6150 u64 volume_wwid = 0;
6151
6152 mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle);
6153 if (volume_handle)
6154 mpt2sas_config_get_volume_wwid(ioc, volume_handle,
6155 &volume_wwid);
Eric Moore635374e2009-03-09 01:21:12 -06006156
6157 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6158 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306159 if (sas_device) {
6160 set_bit(handle, ioc->pd_handles);
6161 if (sas_device->starget && sas_device->starget->hostdata) {
6162 starget = sas_device->starget;
6163 sas_target_priv_data = starget->hostdata;
6164 sas_target_priv_data->flags |=
6165 MPT_TARGET_FLAGS_RAID_COMPONENT;
6166 sas_device->volume_handle = volume_handle;
6167 sas_device->volume_wwid = volume_wwid;
6168 }
6169 }
Eric Moore635374e2009-03-09 01:21:12 -06006170 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6171 if (!sas_device)
6172 return;
6173
6174 /* hiding raid component */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306175 if (starget)
6176 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
Eric Moore635374e2009-03-09 01:21:12 -06006177}
6178
6179/**
6180 * _scsih_sas_pd_delete - delete pd component
6181 * @ioc: per adapter object
6182 * @element: IR config element data
6183 * Context: user.
6184 *
6185 * Return nothing.
6186 */
6187static void
6188_scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6189 Mpi2EventIrConfigElement_t *element)
6190{
Eric Moore635374e2009-03-09 01:21:12 -06006191 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6192
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306193 _scsih_device_remove_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006194}
6195
6196/**
6197 * _scsih_sas_pd_add - remove pd component
6198 * @ioc: per adapter object
6199 * @element: IR config element data
6200 * Context: user.
6201 *
6202 * Return nothing.
6203 */
6204static void
6205_scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6206 Mpi2EventIrConfigElement_t *element)
6207{
6208 struct _sas_device *sas_device;
6209 unsigned long flags;
6210 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306211 Mpi2ConfigReply_t mpi_reply;
6212 Mpi2SasDevicePage0_t sas_device_pg0;
6213 u32 ioc_status;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306214 u64 sas_address;
6215 u16 parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006216
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306217 set_bit(handle, ioc->pd_handles);
6218
Eric Moore635374e2009-03-09 01:21:12 -06006219 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6220 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6221 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306222 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306223 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306224
6225 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6226 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6227 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6228 ioc->name, __FILE__, __LINE__, __func__);
6229 return;
6230 }
6231
6232 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6233 MPI2_IOCSTATUS_MASK;
6234 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6235 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6236 ioc->name, __FILE__, __LINE__, __func__);
6237 return;
6238 }
6239
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306240 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6241 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6242 mpt2sas_transport_update_links(ioc, sas_address, handle,
6243 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306244
6245 _scsih_add_device(ioc, handle, 0, 1);
Eric Moore635374e2009-03-09 01:21:12 -06006246}
6247
6248#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6249/**
6250 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6251 * @ioc: per adapter object
6252 * @event_data: event data payload
6253 * Context: user.
6254 *
6255 * Return nothing.
6256 */
6257static void
6258_scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6259 Mpi2EventDataIrConfigChangeList_t *event_data)
6260{
6261 Mpi2EventIrConfigElement_t *element;
6262 u8 element_type;
6263 int i;
6264 char *reason_str = NULL, *element_str = NULL;
6265
6266 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6267
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306268 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
Eric Moore635374e2009-03-09 01:21:12 -06006269 ioc->name, (le32_to_cpu(event_data->Flags) &
6270 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6271 "foreign" : "native", event_data->NumElements);
6272 for (i = 0; i < event_data->NumElements; i++, element++) {
6273 switch (element->ReasonCode) {
6274 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6275 reason_str = "add";
6276 break;
6277 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6278 reason_str = "remove";
6279 break;
6280 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6281 reason_str = "no change";
6282 break;
6283 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6284 reason_str = "hide";
6285 break;
6286 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6287 reason_str = "unhide";
6288 break;
6289 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6290 reason_str = "volume_created";
6291 break;
6292 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6293 reason_str = "volume_deleted";
6294 break;
6295 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6296 reason_str = "pd_created";
6297 break;
6298 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6299 reason_str = "pd_deleted";
6300 break;
6301 default:
6302 reason_str = "unknown reason";
6303 break;
6304 }
6305 element_type = le16_to_cpu(element->ElementFlags) &
6306 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6307 switch (element_type) {
6308 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6309 element_str = "volume";
6310 break;
6311 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6312 element_str = "phys disk";
6313 break;
6314 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6315 element_str = "hot spare";
6316 break;
6317 default:
6318 element_str = "unknown element";
6319 break;
6320 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306321 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
Eric Moore635374e2009-03-09 01:21:12 -06006322 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6323 reason_str, le16_to_cpu(element->VolDevHandle),
6324 le16_to_cpu(element->PhysDiskDevHandle),
6325 element->PhysDiskNum);
6326 }
6327}
6328#endif
6329
6330/**
6331 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6332 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306333 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006334 * Context: user.
6335 *
6336 * Return nothing.
6337 */
6338static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306339_scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6340 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006341{
6342 Mpi2EventIrConfigElement_t *element;
6343 int i;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306344 u8 foreign_config;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006345 Mpi2EventDataIrConfigChangeList_t *event_data =
6346 (Mpi2EventDataIrConfigChangeList_t *)
6347 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006348
6349#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306350 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6351 && !ioc->hide_ir_msg)
Eric Moore635374e2009-03-09 01:21:12 -06006352 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6353
6354#endif
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306355
6356 if (ioc->shost_recovery)
6357 return;
6358
Kashyap, Desai62727a72009-08-07 19:35:18 +05306359 foreign_config = (le32_to_cpu(event_data->Flags) &
6360 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
Eric Moore635374e2009-03-09 01:21:12 -06006361
6362 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6363 for (i = 0; i < event_data->NumElements; i++, element++) {
6364
6365 switch (element->ReasonCode) {
6366 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6367 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306368 if (!foreign_config)
6369 _scsih_sas_volume_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006370 break;
6371 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6372 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306373 if (!foreign_config)
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306374 _scsih_sas_volume_delete(ioc,
6375 le16_to_cpu(element->VolDevHandle));
Eric Moore635374e2009-03-09 01:21:12 -06006376 break;
6377 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306378 if (!ioc->is_warpdrive)
6379 _scsih_sas_pd_hide(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006380 break;
6381 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306382 if (!ioc->is_warpdrive)
6383 _scsih_sas_pd_expose(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006384 break;
6385 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306386 if (!ioc->is_warpdrive)
6387 _scsih_sas_pd_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006388 break;
6389 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306390 if (!ioc->is_warpdrive)
6391 _scsih_sas_pd_delete(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006392 break;
6393 }
6394 }
6395}
6396
6397/**
6398 * _scsih_sas_ir_volume_event - IR volume event
6399 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306400 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006401 * Context: user.
6402 *
6403 * Return nothing.
6404 */
6405static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306406_scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6407 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006408{
6409 u64 wwid;
6410 unsigned long flags;
6411 struct _raid_device *raid_device;
6412 u16 handle;
6413 u32 state;
6414 int rc;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006415 Mpi2EventDataIrVolume_t *event_data =
6416 (Mpi2EventDataIrVolume_t *)
6417 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006418
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306419 if (ioc->shost_recovery)
6420 return;
6421
Eric Moore635374e2009-03-09 01:21:12 -06006422 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6423 return;
6424
6425 handle = le16_to_cpu(event_data->VolDevHandle);
6426 state = le32_to_cpu(event_data->NewValue);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306427 if (!ioc->hide_ir_msg)
6428 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6429 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6430 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006431
Eric Moore635374e2009-03-09 01:21:12 -06006432 switch (state) {
6433 case MPI2_RAID_VOL_STATE_MISSING:
6434 case MPI2_RAID_VOL_STATE_FAILED:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306435 _scsih_sas_volume_delete(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006436 break;
6437
6438 case MPI2_RAID_VOL_STATE_ONLINE:
6439 case MPI2_RAID_VOL_STATE_DEGRADED:
6440 case MPI2_RAID_VOL_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306441
6442 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6443 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6444 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6445
Eric Moore635374e2009-03-09 01:21:12 -06006446 if (raid_device)
6447 break;
6448
6449 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6450 if (!wwid) {
6451 printk(MPT2SAS_ERR_FMT
6452 "failure at %s:%d/%s()!\n", ioc->name,
6453 __FILE__, __LINE__, __func__);
6454 break;
6455 }
6456
6457 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6458 if (!raid_device) {
6459 printk(MPT2SAS_ERR_FMT
6460 "failure at %s:%d/%s()!\n", ioc->name,
6461 __FILE__, __LINE__, __func__);
6462 break;
6463 }
6464
6465 raid_device->id = ioc->sas_id++;
6466 raid_device->channel = RAID_CHANNEL;
6467 raid_device->handle = handle;
6468 raid_device->wwid = wwid;
6469 _scsih_raid_device_add(ioc, raid_device);
6470 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6471 raid_device->id, 0);
6472 if (rc)
6473 _scsih_raid_device_remove(ioc, raid_device);
6474 break;
6475
6476 case MPI2_RAID_VOL_STATE_INITIALIZING:
6477 default:
6478 break;
6479 }
6480}
6481
6482/**
6483 * _scsih_sas_ir_physical_disk_event - PD event
6484 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306485 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006486 * Context: user.
6487 *
6488 * Return nothing.
6489 */
6490static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306491_scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6492 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006493{
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306494 u16 handle, parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006495 u32 state;
6496 struct _sas_device *sas_device;
6497 unsigned long flags;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306498 Mpi2ConfigReply_t mpi_reply;
6499 Mpi2SasDevicePage0_t sas_device_pg0;
6500 u32 ioc_status;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006501 Mpi2EventDataIrPhysicalDisk_t *event_data =
6502 (Mpi2EventDataIrPhysicalDisk_t *)
6503 fw_event->event_data;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306504 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006505
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306506 if (ioc->shost_recovery)
6507 return;
6508
Eric Moore635374e2009-03-09 01:21:12 -06006509 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6510 return;
6511
6512 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6513 state = le32_to_cpu(event_data->NewValue);
6514
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306515 if (!ioc->hide_ir_msg)
6516 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6517 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6518 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006519
Eric Moore635374e2009-03-09 01:21:12 -06006520 switch (state) {
Eric Moore635374e2009-03-09 01:21:12 -06006521 case MPI2_RAID_PD_STATE_ONLINE:
6522 case MPI2_RAID_PD_STATE_DEGRADED:
6523 case MPI2_RAID_PD_STATE_REBUILDING:
6524 case MPI2_RAID_PD_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306525 case MPI2_RAID_PD_STATE_HOT_SPARE:
6526
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306527 if (!ioc->is_warpdrive)
6528 set_bit(handle, ioc->pd_handles);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306529
6530 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6531 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6532 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6533
6534 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306535 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306536
6537 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6538 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6539 handle))) {
6540 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6541 ioc->name, __FILE__, __LINE__, __func__);
6542 return;
6543 }
6544
6545 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6546 MPI2_IOCSTATUS_MASK;
6547 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6548 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6549 ioc->name, __FILE__, __LINE__, __func__);
6550 return;
6551 }
6552
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306553 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6554 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6555 mpt2sas_transport_update_links(ioc, sas_address, handle,
6556 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306557
6558 _scsih_add_device(ioc, handle, 0, 1);
6559
Eric Moore635374e2009-03-09 01:21:12 -06006560 break;
6561
Kashyap, Desai62727a72009-08-07 19:35:18 +05306562 case MPI2_RAID_PD_STATE_OFFLINE:
Eric Moore635374e2009-03-09 01:21:12 -06006563 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6564 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
Eric Moore635374e2009-03-09 01:21:12 -06006565 default:
6566 break;
6567 }
6568}
6569
6570#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6571/**
6572 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6573 * @ioc: per adapter object
6574 * @event_data: event data payload
6575 * Context: user.
6576 *
6577 * Return nothing.
6578 */
6579static void
6580_scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6581 Mpi2EventDataIrOperationStatus_t *event_data)
6582{
6583 char *reason_str = NULL;
6584
6585 switch (event_data->RAIDOperation) {
6586 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6587 reason_str = "resync";
6588 break;
6589 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6590 reason_str = "online capacity expansion";
6591 break;
6592 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6593 reason_str = "consistency check";
6594 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306595 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6596 reason_str = "background init";
6597 break;
6598 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6599 reason_str = "make data consistent";
Eric Moore635374e2009-03-09 01:21:12 -06006600 break;
6601 }
6602
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306603 if (!reason_str)
6604 return;
6605
Eric Moore635374e2009-03-09 01:21:12 -06006606 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6607 "\thandle(0x%04x), percent complete(%d)\n",
6608 ioc->name, reason_str,
6609 le16_to_cpu(event_data->VolDevHandle),
6610 event_data->PercentComplete);
6611}
6612#endif
6613
6614/**
6615 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6616 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306617 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006618 * Context: user.
6619 *
6620 * Return nothing.
6621 */
6622static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306623_scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6624 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006625{
Joe Lawrence00713ad2014-06-25 17:03:33 -04006626 Mpi2EventDataIrOperationStatus_t *event_data =
6627 (Mpi2EventDataIrOperationStatus_t *)
6628 fw_event->event_data;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306629 static struct _raid_device *raid_device;
6630 unsigned long flags;
6631 u16 handle;
6632
Eric Moore635374e2009-03-09 01:21:12 -06006633#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306634 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6635 && !ioc->hide_ir_msg)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306636 _scsih_sas_ir_operation_status_event_debug(ioc,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306637 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06006638#endif
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306639
6640 /* code added for raid transport support */
6641 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6642
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306643 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306644 handle = le16_to_cpu(event_data->VolDevHandle);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306645 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306646 if (raid_device)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306647 raid_device->percent_complete =
6648 event_data->PercentComplete;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306649 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306650 }
Eric Moore635374e2009-03-09 01:21:12 -06006651}
6652
6653/**
Kashyap, Desai14695852010-03-30 10:52:44 +05306654 * _scsih_prep_device_scan - initialize parameters prior to device scan
6655 * @ioc: per adapter object
6656 *
6657 * Set the deleted flag prior to device scan. If the device is found during
6658 * the scan, then we clear the deleted flag.
6659 */
6660static void
6661_scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6662{
6663 struct MPT2SAS_DEVICE *sas_device_priv_data;
6664 struct scsi_device *sdev;
6665
6666 shost_for_each_device(sdev, ioc->shost) {
6667 sas_device_priv_data = sdev->hostdata;
6668 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6669 sas_device_priv_data->sas_target->deleted = 1;
6670 }
6671}
6672
6673/**
Eric Moore635374e2009-03-09 01:21:12 -06006674 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6675 * @ioc: per adapter object
6676 * @sas_address: sas address
6677 * @slot: enclosure slot id
6678 * @handle: device handle
6679 *
6680 * After host reset, find out whether devices are still responding.
6681 * Used in _scsi_remove_unresponsive_sas_devices.
6682 *
6683 * Return nothing.
6684 */
6685static void
6686_scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6687 u16 slot, u16 handle)
6688{
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306689 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006690 struct scsi_target *starget;
6691 struct _sas_device *sas_device;
6692 unsigned long flags;
6693
6694 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6695 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6696 if (sas_device->sas_address == sas_address &&
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306697 sas_device->slot == slot) {
Eric Moore635374e2009-03-09 01:21:12 -06006698 sas_device->responding = 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05306699 starget = sas_device->starget;
Kashyap, Desai14695852010-03-30 10:52:44 +05306700 if (starget && starget->hostdata) {
6701 sas_target_priv_data = starget->hostdata;
6702 sas_target_priv_data->tm_busy = 0;
6703 sas_target_priv_data->deleted = 0;
6704 } else
6705 sas_target_priv_data = NULL;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306706 if (starget)
6707 starget_printk(KERN_INFO, starget,
6708 "handle(0x%04x), sas_addr(0x%016llx), "
6709 "enclosure logical id(0x%016llx), "
6710 "slot(%d)\n", handle,
6711 (unsigned long long)sas_device->sas_address,
6712 (unsigned long long)
6713 sas_device->enclosure_logical_id,
6714 sas_device->slot);
Eric Moore635374e2009-03-09 01:21:12 -06006715 if (sas_device->handle == handle)
6716 goto out;
6717 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6718 sas_device->handle);
6719 sas_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306720 if (sas_target_priv_data)
6721 sas_target_priv_data->handle = handle;
Eric Moore635374e2009-03-09 01:21:12 -06006722 goto out;
6723 }
6724 }
6725 out:
6726 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6727}
6728
6729/**
6730 * _scsih_search_responding_sas_devices -
6731 * @ioc: per adapter object
6732 *
6733 * After host reset, find out whether devices are still responding.
6734 * If not remove.
6735 *
6736 * Return nothing.
6737 */
6738static void
6739_scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6740{
6741 Mpi2SasDevicePage0_t sas_device_pg0;
6742 Mpi2ConfigReply_t mpi_reply;
6743 u16 ioc_status;
6744 __le64 sas_address;
6745 u16 handle;
6746 u32 device_info;
6747 u16 slot;
6748
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306749 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006750
6751 if (list_empty(&ioc->sas_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306752 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006753
6754 handle = 0xFFFF;
6755 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6756 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6757 handle))) {
6758 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6759 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306760 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006761 break;
6762 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6763 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6764 if (!(_scsih_is_end_device(device_info)))
6765 continue;
6766 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6767 slot = le16_to_cpu(sas_device_pg0.Slot);
6768 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6769 handle);
6770 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306771out:
6772 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6773 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006774}
6775
6776/**
6777 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6778 * @ioc: per adapter object
6779 * @wwid: world wide identifier for raid volume
6780 * @handle: device handle
6781 *
6782 * After host reset, find out whether devices are still responding.
6783 * Used in _scsi_remove_unresponsive_raid_devices.
6784 *
6785 * Return nothing.
6786 */
6787static void
6788_scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6789 u16 handle)
6790{
6791 struct MPT2SAS_TARGET *sas_target_priv_data;
6792 struct scsi_target *starget;
6793 struct _raid_device *raid_device;
6794 unsigned long flags;
6795
6796 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6797 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6798 if (raid_device->wwid == wwid && raid_device->starget) {
Kashyap, Desai14695852010-03-30 10:52:44 +05306799 starget = raid_device->starget;
6800 if (starget && starget->hostdata) {
6801 sas_target_priv_data = starget->hostdata;
6802 sas_target_priv_data->deleted = 0;
6803 } else
6804 sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006805 raid_device->responding = 1;
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306806 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06006807 starget_printk(KERN_INFO, raid_device->starget,
6808 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6809 (unsigned long long)raid_device->wwid);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306810 /*
6811 * WARPDRIVE: The handles of the PDs might have changed
6812 * across the host reset so re-initialize the
6813 * required data for Direct IO
6814 */
6815 _scsih_init_warpdrive_properties(ioc, raid_device);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306816 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6817 if (raid_device->handle == handle) {
6818 spin_unlock_irqrestore(&ioc->raid_device_lock,
6819 flags);
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306820 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306821 }
Eric Moore635374e2009-03-09 01:21:12 -06006822 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6823 raid_device->handle);
6824 raid_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306825 if (sas_target_priv_data)
6826 sas_target_priv_data->handle = handle;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306827 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306828 return;
Eric Moore635374e2009-03-09 01:21:12 -06006829 }
6830 }
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306831
Eric Moore635374e2009-03-09 01:21:12 -06006832 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6833}
6834
6835/**
6836 * _scsih_search_responding_raid_devices -
6837 * @ioc: per adapter object
6838 *
6839 * After host reset, find out whether devices are still responding.
6840 * If not remove.
6841 *
6842 * Return nothing.
6843 */
6844static void
6845_scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6846{
6847 Mpi2RaidVolPage1_t volume_pg1;
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306848 Mpi2RaidVolPage0_t volume_pg0;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306849 Mpi2RaidPhysDiskPage0_t pd_pg0;
Eric Moore635374e2009-03-09 01:21:12 -06006850 Mpi2ConfigReply_t mpi_reply;
6851 u16 ioc_status;
6852 u16 handle;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306853 u8 phys_disk_num;
Eric Moore635374e2009-03-09 01:21:12 -06006854
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306855 if (!ioc->ir_firmware)
6856 return;
6857
6858 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6859 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006860
6861 if (list_empty(&ioc->raid_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306862 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006863
6864 handle = 0xFFFF;
6865 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6866 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6867 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6868 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306869 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006870 break;
6871 handle = le16_to_cpu(volume_pg1.DevHandle);
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306872
6873 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6874 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6875 sizeof(Mpi2RaidVolPage0_t)))
6876 continue;
6877
6878 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6879 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6880 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6881 _scsih_mark_responding_raid_device(ioc,
6882 le64_to_cpu(volume_pg1.WWID), handle);
Eric Moore635374e2009-03-09 01:21:12 -06006883 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306884
6885 /* refresh the pd_handles */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306886 if (!ioc->is_warpdrive) {
6887 phys_disk_num = 0xFF;
6888 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6889 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6890 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6891 phys_disk_num))) {
6892 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6893 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306894 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306895 break;
6896 phys_disk_num = pd_pg0.PhysDiskNum;
6897 handle = le16_to_cpu(pd_pg0.DevHandle);
6898 set_bit(handle, ioc->pd_handles);
6899 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306900 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306901out:
6902 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6903 "complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006904}
6905
6906/**
6907 * _scsih_mark_responding_expander - mark a expander as responding
6908 * @ioc: per adapter object
6909 * @sas_address: sas address
6910 * @handle:
6911 *
6912 * After host reset, find out whether devices are still responding.
6913 * Used in _scsi_remove_unresponsive_expanders.
6914 *
6915 * Return nothing.
6916 */
6917static void
6918_scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6919 u16 handle)
6920{
6921 struct _sas_node *sas_expander;
6922 unsigned long flags;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306923 int i;
Eric Moore635374e2009-03-09 01:21:12 -06006924
6925 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6926 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306927 if (sas_expander->sas_address != sas_address)
6928 continue;
6929 sas_expander->responding = 1;
6930 if (sas_expander->handle == handle)
Eric Moore635374e2009-03-09 01:21:12 -06006931 goto out;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306932 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6933 " from(0x%04x) to (0x%04x)!!!\n",
6934 (unsigned long long)sas_expander->sas_address,
6935 sas_expander->handle, handle);
6936 sas_expander->handle = handle;
6937 for (i = 0 ; i < sas_expander->num_phys ; i++)
6938 sas_expander->phy[i].handle = handle;
6939 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006940 }
6941 out:
6942 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6943}
6944
6945/**
6946 * _scsih_search_responding_expanders -
6947 * @ioc: per adapter object
6948 *
6949 * After host reset, find out whether devices are still responding.
6950 * If not remove.
6951 *
6952 * Return nothing.
6953 */
6954static void
6955_scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6956{
6957 Mpi2ExpanderPage0_t expander_pg0;
6958 Mpi2ConfigReply_t mpi_reply;
6959 u16 ioc_status;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05306960 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006961 u16 handle;
6962
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306963 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006964
6965 if (list_empty(&ioc->sas_expander_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306966 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006967
6968 handle = 0xFFFF;
6969 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6970 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6971
6972 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6973 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306974 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006975 break;
6976
6977 handle = le16_to_cpu(expander_pg0.DevHandle);
6978 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6979 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6980 "sas_addr(0x%016llx)\n", handle,
6981 (unsigned long long)sas_address);
6982 _scsih_mark_responding_expander(ioc, sas_address, handle);
6983 }
6984
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306985 out:
6986 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006987}
6988
6989/**
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05306990 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
Eric Moore635374e2009-03-09 01:21:12 -06006991 * @ioc: per adapter object
6992 *
6993 * Return nothing.
6994 */
6995static void
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05306996_scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06006997{
6998 struct _sas_device *sas_device, *sas_device_next;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306999 struct _sas_node *sas_expander, *sas_expander_next;
Eric Moore635374e2009-03-09 01:21:12 -06007000 struct _raid_device *raid_device, *raid_device_next;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307001 struct list_head tmp_list;
7002 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06007003
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307004 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
7005 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06007006
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307007 /* removing unresponding end devices */
7008 printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n",
7009 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06007010 list_for_each_entry_safe(sas_device, sas_device_next,
7011 &ioc->sas_device_list, list) {
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307012 if (!sas_device->responding)
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05307013 mpt2sas_device_remove_by_sas_address(ioc,
7014 sas_device->sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307015 else
Eric Moore635374e2009-03-09 01:21:12 -06007016 sas_device->responding = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007017 }
7018
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307019 /* removing unresponding volumes */
7020 if (ioc->ir_firmware) {
7021 printk(MPT2SAS_INFO_FMT "removing unresponding devices: "
7022 "volumes\n", ioc->name);
7023 list_for_each_entry_safe(raid_device, raid_device_next,
7024 &ioc->raid_device_list, list) {
7025 if (!raid_device->responding)
7026 _scsih_sas_volume_delete(ioc,
7027 raid_device->handle);
7028 else
7029 raid_device->responding = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007030 }
Eric Moore635374e2009-03-09 01:21:12 -06007031 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307032 /* removing unresponding expanders */
7033 printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n",
7034 ioc->name);
7035 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7036 INIT_LIST_HEAD(&tmp_list);
7037 list_for_each_entry_safe(sas_expander, sas_expander_next,
7038 &ioc->sas_expander_list, list) {
7039 if (!sas_expander->responding)
7040 list_move_tail(&sas_expander->list, &tmp_list);
7041 else
Eric Moore635374e2009-03-09 01:21:12 -06007042 sas_expander->responding = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307043 }
7044 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7045 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7046 list) {
7047 list_del(&sas_expander->list);
7048 _scsih_expander_node_remove(ioc, sas_expander);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307049 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307050 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
7051 ioc->name);
7052 /* unblock devices */
7053 _scsih_ublock_io_all_device(ioc);
7054}
7055
7056static void
7057_scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
7058 struct _sas_node *sas_expander, u16 handle)
7059{
7060 Mpi2ExpanderPage1_t expander_pg1;
7061 Mpi2ConfigReply_t mpi_reply;
7062 int i;
7063
7064 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7065 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
7066 &expander_pg1, i, handle))) {
7067 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7068 ioc->name, __FILE__, __LINE__, __func__);
7069 return;
7070 }
7071
7072 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
7073 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7074 expander_pg1.NegotiatedLinkRate >> 4);
7075 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307076}
7077
7078/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307079 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307080 * @ioc: per adapter object
7081 *
7082 * Return nothing.
7083 */
7084static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307085_scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307086{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307087 Mpi2ExpanderPage0_t expander_pg0;
7088 Mpi2SasDevicePage0_t sas_device_pg0;
7089 Mpi2RaidVolPage1_t volume_pg1;
7090 Mpi2RaidVolPage0_t volume_pg0;
7091 Mpi2RaidPhysDiskPage0_t pd_pg0;
7092 Mpi2EventIrConfigElement_t element;
7093 Mpi2ConfigReply_t mpi_reply;
7094 u8 phys_disk_num;
7095 u16 ioc_status;
7096 u16 handle, parent_handle;
7097 u64 sas_address;
7098 struct _sas_device *sas_device;
7099 struct _sas_node *expander_device;
7100 static struct _raid_device *raid_device;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307101 u8 retry_count;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307102 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307103
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307104 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307105
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307106 _scsih_sas_host_refresh(ioc);
7107
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307108 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n",
7109 ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307110 /* expanders */
7111 handle = 0xFFFF;
7112 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7113 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7114 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7115 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307116 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7117 printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: "
7118 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7119 ioc->name, ioc_status,
7120 le32_to_cpu(mpi_reply.IOCLogInfo));
7121 break;
7122 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307123 handle = le16_to_cpu(expander_pg0.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307124 spin_lock_irqsave(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307125 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7126 ioc, le64_to_cpu(expander_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307127 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307128 if (expander_device)
7129 _scsih_refresh_expander_links(ioc, expander_device,
7130 handle);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307131 else {
7132 printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: "
7133 "handle (0x%04x), sas_addr(0x%016llx)\n",
7134 ioc->name, handle, (unsigned long long)
7135 le64_to_cpu(expander_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307136 _scsih_expander_add(ioc, handle);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307137 printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: "
7138 "handle (0x%04x), sas_addr(0x%016llx)\n",
7139 ioc->name, handle, (unsigned long long)
7140 le64_to_cpu(expander_pg0.SASAddress));
7141 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307142 }
7143
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307144 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n",
7145 ioc->name);
7146
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307147 if (!ioc->ir_firmware)
7148 goto skip_to_sas;
7149
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307150 printk(MPT2SAS_INFO_FMT "\tscan devices phys disk start\n", ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307151 /* phys disk */
7152 phys_disk_num = 0xFF;
7153 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7154 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7155 phys_disk_num))) {
7156 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7157 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307158 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7159 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:"
7160 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7161 ioc->name, ioc_status,
7162 le32_to_cpu(mpi_reply.IOCLogInfo));
7163 break;
7164 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307165 phys_disk_num = pd_pg0.PhysDiskNum;
7166 handle = le16_to_cpu(pd_pg0.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307167 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307168 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307169 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307170 if (sas_device)
7171 continue;
7172 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7173 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7174 handle) != 0)
7175 continue;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307176 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7177 MPI2_IOCSTATUS_MASK;
7178 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7179 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan "
7180 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7181 ioc->name, ioc_status,
7182 le32_to_cpu(mpi_reply.IOCLogInfo));
7183 break;
7184 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307185 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7186 if (!_scsih_get_sas_address(ioc, parent_handle,
7187 &sas_address)) {
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307188 printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: "
7189 " handle (0x%04x), sas_addr(0x%016llx)\n",
7190 ioc->name, handle, (unsigned long long)
7191 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307192 mpt2sas_transport_update_links(ioc, sas_address,
7193 handle, sas_device_pg0.PhyNum,
7194 MPI2_SAS_NEG_LINK_RATE_1_5);
7195 set_bit(handle, ioc->pd_handles);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307196 retry_count = 0;
7197 /* This will retry adding the end device.
7198 * _scsih_add_device() will decide on retries and
7199 * return "1" when it should be retried
7200 */
7201 while (_scsih_add_device(ioc, handle, retry_count++,
7202 1)) {
7203 ssleep(1);
7204 }
7205 printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: "
7206 " handle (0x%04x), sas_addr(0x%016llx)\n",
7207 ioc->name, handle, (unsigned long long)
7208 le64_to_cpu(sas_device_pg0.SASAddress));
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307209 }
7210 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307211
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307212 printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n",
7213 ioc->name);
7214
7215 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes start\n", ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307216 /* volumes */
7217 handle = 0xFFFF;
7218 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7219 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7220 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7221 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307222 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7223 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7224 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7225 ioc->name, ioc_status,
7226 le32_to_cpu(mpi_reply.IOCLogInfo));
7227 break;
7228 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307229 handle = le16_to_cpu(volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307230 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307231 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7232 le64_to_cpu(volume_pg1.WWID));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307233 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307234 if (raid_device)
7235 continue;
7236 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7237 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7238 sizeof(Mpi2RaidVolPage0_t)))
7239 continue;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307240 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7241 MPI2_IOCSTATUS_MASK;
7242 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7243 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7244 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7245 ioc->name, ioc_status,
7246 le32_to_cpu(mpi_reply.IOCLogInfo));
7247 break;
7248 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307249 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7250 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7251 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7252 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7253 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7254 element.VolDevHandle = volume_pg1.DevHandle;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307255 printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: "
7256 " handle (0x%04x)\n", ioc->name,
7257 volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307258 _scsih_sas_volume_add(ioc, &element);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307259 printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: "
7260 " handle (0x%04x)\n", ioc->name,
7261 volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307262 }
7263 }
7264
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307265 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n",
7266 ioc->name);
7267
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307268 skip_to_sas:
7269
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307270 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n",
7271 ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307272 /* sas devices */
7273 handle = 0xFFFF;
7274 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7275 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7276 handle))) {
7277 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7278 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307279 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7280 printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:"
7281 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7282 ioc->name, ioc_status,
7283 le32_to_cpu(mpi_reply.IOCLogInfo));
7284 break;
7285 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307286 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7287 if (!(_scsih_is_end_device(
7288 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7289 continue;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307290 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307291 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7292 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307293 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307294 if (sas_device)
7295 continue;
7296 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7297 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307298 printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: "
7299 "handle (0x%04x), sas_addr(0x%016llx)\n",
7300 ioc->name, handle, (unsigned long long)
7301 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307302 mpt2sas_transport_update_links(ioc, sas_address, handle,
7303 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307304 retry_count = 0;
7305 /* This will retry adding the end device.
7306 * _scsih_add_device() will decide on retries and
7307 * return "1" when it should be retried
7308 */
7309 while (_scsih_add_device(ioc, handle, retry_count++,
7310 0)) {
7311 ssleep(1);
7312 }
7313 printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: "
7314 "handle (0x%04x), sas_addr(0x%016llx)\n",
7315 ioc->name, handle, (unsigned long long)
7316 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307317 }
7318 }
7319
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307320 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n",
7321 ioc->name);
7322
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307323 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307324}
7325
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307326
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307327/**
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307328 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7329 * @ioc: per adapter object
7330 * @reset_phase: phase
7331 *
7332 * The handler for doing any required cleanup or initialization.
7333 *
7334 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7335 * MPT2_IOC_DONE_RESET
7336 *
7337 * Return nothing.
7338 */
7339void
7340mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7341{
7342 switch (reset_phase) {
7343 case MPT2_IOC_PRE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307344 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307345 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307346 break;
7347 case MPT2_IOC_AFTER_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307348 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307349 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307350 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7351 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7352 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7353 complete(&ioc->scsih_cmds.done);
7354 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307355 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7356 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7357 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7358 complete(&ioc->tm_cmds.done);
7359 }
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307360 _scsih_fw_event_cleanup_queue(ioc);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307361 _scsih_flush_running_cmds(ioc);
7362 break;
7363 case MPT2_IOC_DONE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307364 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307365 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307366 _scsih_sas_host_refresh(ioc);
Kashyap, Desai14695852010-03-30 10:52:44 +05307367 _scsih_prep_device_scan(ioc);
7368 _scsih_search_responding_sas_devices(ioc);
7369 _scsih_search_responding_raid_devices(ioc);
7370 _scsih_search_responding_expanders(ioc);
sreekanth.reddy@lsi.com14aa7f72012-07-17 15:56:13 +05307371 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7372 !ioc->sas_hba.num_phys)) {
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307373 _scsih_prep_device_scan(ioc);
7374 _scsih_search_responding_sas_devices(ioc);
7375 _scsih_search_responding_raid_devices(ioc);
7376 _scsih_search_responding_expanders(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307377 _scsih_error_recovery_delete_devices(ioc);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307378 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307379 break;
Eric Moore635374e2009-03-09 01:21:12 -06007380 }
7381}
7382
7383/**
7384 * _firmware_event_work - delayed task for processing firmware events
7385 * @ioc: per adapter object
7386 * @work: equal to the fw_event_work object
7387 * Context: user.
7388 *
7389 * Return nothing.
7390 */
7391static void
7392_firmware_event_work(struct work_struct *work)
7393{
7394 struct fw_event_work *fw_event = container_of(work,
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307395 struct fw_event_work, delayed_work.work);
Eric Moore635374e2009-03-09 01:21:12 -06007396 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7397
Eric Moore635374e2009-03-09 01:21:12 -06007398 /* the queue is being flushed so ignore this event */
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05307399 if (ioc->remove_host ||
Eric Moore3cb54692010-07-08 14:44:34 -06007400 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06007401 _scsih_fw_event_free(ioc, fw_event);
7402 return;
7403 }
Eric Moore635374e2009-03-09 01:21:12 -06007404
Eric Moore635374e2009-03-09 01:21:12 -06007405 switch (fw_event->event) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307406 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307407 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307408 ssleep(1);
7409 _scsih_remove_unresponding_sas_devices(ioc);
7410 _scsih_scan_for_devices_after_reset(ioc);
7411 break;
7412 case MPT2SAS_PORT_ENABLE_COMPLETE:
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307413 ioc->start_scan = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307414
Reddy, Sreekanthb0df96a02013-02-26 16:59:59 +05307415 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7416 mpt2sas_base_update_missing_delay(ioc, missing_delay[0],
7417 missing_delay[1]);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307418
7419 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7420 "from worker thread\n", ioc->name));
7421 break;
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05307422 case MPT2SAS_TURN_ON_PFA_LED:
7423 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05307424 break;
Eric Moore635374e2009-03-09 01:21:12 -06007425 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307426 _scsih_sas_topology_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007427 break;
7428 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307429 _scsih_sas_device_status_change_event(ioc,
7430 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007431 break;
7432 case MPI2_EVENT_SAS_DISCOVERY:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307433 _scsih_sas_discovery_event(ioc,
7434 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007435 break;
7436 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
Andrew Mortona78e21d2012-02-08 12:52:22 -08007437 _scsih_sas_broadcast_primitive_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307438 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007439 break;
7440 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7441 _scsih_sas_enclosure_dev_status_change_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307442 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007443 break;
7444 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307445 _scsih_sas_ir_config_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007446 break;
7447 case MPI2_EVENT_IR_VOLUME:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307448 _scsih_sas_ir_volume_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007449 break;
7450 case MPI2_EVENT_IR_PHYSICAL_DISK:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307451 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007452 break;
7453 case MPI2_EVENT_IR_OPERATION_STATUS:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307454 _scsih_sas_ir_operation_status_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007455 break;
Eric Moore635374e2009-03-09 01:21:12 -06007456 }
7457 _scsih_fw_event_free(ioc, fw_event);
7458}
7459
7460/**
7461 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7462 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307463 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06007464 * @reply: reply message frame(lower 32bit addr)
7465 * Context: interrupt.
7466 *
7467 * This function merely adds a new work task into ioc->firmware_event_thread.
7468 * The tasks are worked from _firmware_event_work in user context.
7469 *
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307470 * Returns void.
Eric Moore635374e2009-03-09 01:21:12 -06007471 */
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307472void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307473mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7474 u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06007475{
7476 struct fw_event_work *fw_event;
7477 Mpi2EventNotificationReply_t *mpi_reply;
Eric Moore635374e2009-03-09 01:21:12 -06007478 u16 event;
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307479 u16 sz;
Eric Moore635374e2009-03-09 01:21:12 -06007480
7481 /* events turned off due to host reset or driver unloading */
Eric Moore3cb54692010-07-08 14:44:34 -06007482 if (ioc->remove_host || ioc->pci_error_recovery)
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307483 return;
Eric Moore635374e2009-03-09 01:21:12 -06007484
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307485 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05307486
7487 if (unlikely(!mpi_reply)) {
7488 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7489 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307490 return;
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05307491 }
7492
Eric Moore635374e2009-03-09 01:21:12 -06007493 event = le16_to_cpu(mpi_reply->Event);
7494
7495 switch (event) {
7496 /* handle these */
7497 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7498 {
7499 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7500 (Mpi2EventDataSasBroadcastPrimitive_t *)
7501 mpi_reply->EventData;
7502
7503 if (baen_data->Primitive !=
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307504 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307505 return;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307506
7507 if (ioc->broadcast_aen_busy) {
7508 ioc->broadcast_aen_pending++;
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307509 return;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307510 } else
7511 ioc->broadcast_aen_busy = 1;
Eric Moore635374e2009-03-09 01:21:12 -06007512 break;
7513 }
7514
7515 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7516 _scsih_check_topo_delete_events(ioc,
7517 (Mpi2EventDataSasTopologyChangeList_t *)
7518 mpi_reply->EventData);
7519 break;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05307520 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7521 _scsih_check_ir_config_unhide_events(ioc,
7522 (Mpi2EventDataIrConfigChangeList_t *)
7523 mpi_reply->EventData);
7524 break;
7525 case MPI2_EVENT_IR_VOLUME:
7526 _scsih_check_volume_delete_events(ioc,
7527 (Mpi2EventDataIrVolume_t *)
7528 mpi_reply->EventData);
7529 break;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307530 case MPI2_EVENT_LOG_ENTRY_ADDED:
7531 {
7532 Mpi2EventDataLogEntryAdded_t *log_entry;
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05307533 __le32 *log_code;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307534
7535 if (!ioc->is_warpdrive)
7536 break;
7537
7538 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7539 mpi_reply->EventData;
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05307540 log_code = (__le32 *)log_entry->LogData;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307541
7542 if (le16_to_cpu(log_entry->LogEntryQualifier)
7543 != MPT2_WARPDRIVE_LOGENTRY)
7544 break;
7545
7546 switch (le32_to_cpu(*log_code)) {
7547 case MPT2_WARPDRIVE_LC_SSDT:
7548 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7549 "IO Throttling has occurred in the WarpDrive "
7550 "subsystem. Check WarpDrive documentation for "
7551 "additional details.\n", ioc->name);
7552 break;
7553 case MPT2_WARPDRIVE_LC_SSDLW:
7554 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7555 "Program/Erase Cycles for the WarpDrive subsystem "
7556 "in degraded range. Check WarpDrive documentation "
7557 "for additional details.\n", ioc->name);
7558 break;
7559 case MPT2_WARPDRIVE_LC_SSDLF:
7560 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7561 "There are no Program/Erase Cycles for the "
7562 "WarpDrive subsystem. The storage device will be "
7563 "in read-only mode. Check WarpDrive documentation "
7564 "for additional details.\n", ioc->name);
7565 break;
7566 case MPT2_WARPDRIVE_LC_BRMF:
7567 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7568 "The Backup Rail Monitor has failed on the "
7569 "WarpDrive subsystem. Check WarpDrive "
7570 "documentation for additional details.\n",
7571 ioc->name);
7572 break;
7573 }
7574
7575 break;
7576 }
Eric Moore635374e2009-03-09 01:21:12 -06007577 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7578 case MPI2_EVENT_IR_OPERATION_STATUS:
7579 case MPI2_EVENT_SAS_DISCOVERY:
7580 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
Eric Moore635374e2009-03-09 01:21:12 -06007581 case MPI2_EVENT_IR_PHYSICAL_DISK:
Eric Moore635374e2009-03-09 01:21:12 -06007582 break;
7583
7584 default: /* ignore the rest */
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307585 return;
Eric Moore635374e2009-03-09 01:21:12 -06007586 }
7587
Joe Lawrence00713ad2014-06-25 17:03:33 -04007588 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7589 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06007590 if (!fw_event) {
7591 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7592 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307593 return;
Eric Moore635374e2009-03-09 01:21:12 -06007594 }
Eric Moore635374e2009-03-09 01:21:12 -06007595
Joe Lawrence00713ad2014-06-25 17:03:33 -04007596 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
Eric Moore635374e2009-03-09 01:21:12 -06007597 fw_event->ioc = ioc;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307598 fw_event->VF_ID = mpi_reply->VF_ID;
7599 fw_event->VP_ID = mpi_reply->VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -06007600 fw_event->event = event;
7601 _scsih_fw_event_add(ioc, fw_event);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307602 return;
Eric Moore635374e2009-03-09 01:21:12 -06007603}
7604
7605/* shost template */
7606static struct scsi_host_template scsih_driver_template = {
7607 .module = THIS_MODULE,
7608 .name = "Fusion MPT SAS Host",
7609 .proc_name = MPT2SAS_DRIVER_NAME,
Eric Moored5d135b2009-05-18 13:02:08 -06007610 .queuecommand = _scsih_qcmd,
7611 .target_alloc = _scsih_target_alloc,
7612 .slave_alloc = _scsih_slave_alloc,
7613 .slave_configure = _scsih_slave_configure,
7614 .target_destroy = _scsih_target_destroy,
7615 .slave_destroy = _scsih_slave_destroy,
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307616 .scan_finished = _scsih_scan_finished,
7617 .scan_start = _scsih_scan_start,
Eric Moored5d135b2009-05-18 13:02:08 -06007618 .change_queue_depth = _scsih_change_queue_depth,
Christoph Hellwiga62182f2014-10-02 14:39:55 +02007619 .change_queue_type = scsi_change_queue_type,
Eric Moored5d135b2009-05-18 13:02:08 -06007620 .eh_abort_handler = _scsih_abort,
7621 .eh_device_reset_handler = _scsih_dev_reset,
7622 .eh_target_reset_handler = _scsih_target_reset,
7623 .eh_host_reset_handler = _scsih_host_reset,
7624 .bios_param = _scsih_bios_param,
Eric Moore635374e2009-03-09 01:21:12 -06007625 .can_queue = 1,
7626 .this_id = -1,
7627 .sg_tablesize = MPT2SAS_SG_DEPTH,
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05307628 .max_sectors = 32767,
Eric Moore635374e2009-03-09 01:21:12 -06007629 .cmd_per_lun = 7,
7630 .use_clustering = ENABLE_CLUSTERING,
7631 .shost_attrs = mpt2sas_host_attrs,
7632 .sdev_attrs = mpt2sas_dev_attrs,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +01007633 .track_queue_depth = 1,
Eric Moore635374e2009-03-09 01:21:12 -06007634};
7635
7636/**
7637 * _scsih_expander_node_remove - removing expander device from list.
7638 * @ioc: per adapter object
7639 * @sas_expander: the sas_device object
7640 * Context: Calling function should acquire ioc->sas_node_lock.
7641 *
7642 * Removing object and freeing associated memory from the
7643 * ioc->sas_expander_list.
7644 *
7645 * Return nothing.
7646 */
7647static void
7648_scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7649 struct _sas_node *sas_expander)
7650{
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307651 struct _sas_port *mpt2sas_port, *next;
Eric Moore635374e2009-03-09 01:21:12 -06007652
7653 /* remove sibling ports attached to this expander */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307654 list_for_each_entry_safe(mpt2sas_port, next,
Eric Moore635374e2009-03-09 01:21:12 -06007655 &sas_expander->sas_port_list, port_list) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307656 if (ioc->shost_recovery)
7657 return;
Eric Moore635374e2009-03-09 01:21:12 -06007658 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307659 SAS_END_DEVICE)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307660 mpt2sas_device_remove_by_sas_address(ioc,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307661 mpt2sas_port->remote_identify.sas_address);
7662 else if (mpt2sas_port->remote_identify.device_type ==
7663 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06007664 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307665 SAS_FANOUT_EXPANDER_DEVICE)
7666 mpt2sas_expander_remove(ioc,
7667 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007668 }
7669
7670 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307671 sas_expander->sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06007672
7673 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7674 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7675 sas_expander->handle, (unsigned long long)
7676 sas_expander->sas_address);
7677
Eric Moore635374e2009-03-09 01:21:12 -06007678 kfree(sas_expander->phy);
7679 kfree(sas_expander);
7680}
7681
7682/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05307683 * _scsih_ir_shutdown - IR shutdown notification
7684 * @ioc: per adapter object
7685 *
7686 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7687 * the host system is shutting down.
7688 *
7689 * Return nothing.
7690 */
7691static void
7692_scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7693{
7694 Mpi2RaidActionRequest_t *mpi_request;
7695 Mpi2RaidActionReply_t *mpi_reply;
7696 u16 smid;
7697
7698 /* is IR firmware build loaded ? */
7699 if (!ioc->ir_firmware)
7700 return;
7701
Kashyap, Desai744090d2009-10-05 15:56:56 +05307702 mutex_lock(&ioc->scsih_cmds.mutex);
7703
7704 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7705 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7706 ioc->name, __func__);
7707 goto out;
7708 }
7709 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7710
7711 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7712 if (!smid) {
7713 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7714 ioc->name, __func__);
7715 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7716 goto out;
7717 }
7718
7719 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7720 ioc->scsih_cmds.smid = smid;
7721 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7722
7723 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7724 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7725
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307726 if (!ioc->hide_ir_msg)
7727 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307728 init_completion(&ioc->scsih_cmds.done);
7729 mpt2sas_base_put_smid_default(ioc, smid);
7730 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7731
7732 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7733 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7734 ioc->name, __func__);
7735 goto out;
7736 }
7737
7738 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7739 mpi_reply = ioc->scsih_cmds.reply;
7740
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307741 if (!ioc->hide_ir_msg)
7742 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7743 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7744 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7745 le32_to_cpu(mpi_reply->IOCLogInfo));
Kashyap, Desai744090d2009-10-05 15:56:56 +05307746 }
7747
7748 out:
7749 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7750 mutex_unlock(&ioc->scsih_cmds.mutex);
7751}
7752
7753/**
7754 * _scsih_shutdown - routine call during system shutdown
7755 * @pdev: PCI device struct
7756 *
7757 * Return nothing.
7758 */
7759static void
7760_scsih_shutdown(struct pci_dev *pdev)
7761{
7762 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7763 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307764 struct workqueue_struct *wq;
7765 unsigned long flags;
7766
7767 ioc->remove_host = 1;
7768 _scsih_fw_event_cleanup_queue(ioc);
7769
7770 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7771 wq = ioc->firmware_event_thread;
7772 ioc->firmware_event_thread = NULL;
7773 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7774 if (wq)
7775 destroy_workqueue(wq);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307776
7777 _scsih_ir_shutdown(ioc);
7778 mpt2sas_base_detach(ioc);
7779}
7780
7781/**
Eric Moored5d135b2009-05-18 13:02:08 -06007782 * _scsih_remove - detach and remove add host
Eric Moore635374e2009-03-09 01:21:12 -06007783 * @pdev: PCI device struct
7784 *
Kashyap, Desai744090d2009-10-05 15:56:56 +05307785 * Routine called when unloading the driver.
Eric Moore635374e2009-03-09 01:21:12 -06007786 * Return nothing.
7787 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08007788static void
Eric Moored5d135b2009-05-18 13:02:08 -06007789_scsih_remove(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06007790{
7791 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7792 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307793 struct _sas_port *mpt2sas_port, *next_port;
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307794 struct _raid_device *raid_device, *next;
7795 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06007796 struct workqueue_struct *wq;
7797 unsigned long flags;
7798
7799 ioc->remove_host = 1;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307800 _scsih_fw_event_cleanup_queue(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007801
7802 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7803 wq = ioc->firmware_event_thread;
7804 ioc->firmware_event_thread = NULL;
7805 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7806 if (wq)
7807 destroy_workqueue(wq);
7808
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307809 /* release all the volumes */
Kashyap, Desai3a9c9132011-01-04 11:40:23 +05307810 _scsih_ir_shutdown(ioc);
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307811 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7812 list) {
7813 if (raid_device->starget) {
7814 sas_target_priv_data =
7815 raid_device->starget->hostdata;
7816 sas_target_priv_data->deleted = 1;
7817 scsi_remove_target(&raid_device->starget->dev);
7818 }
7819 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7820 "(0x%016llx)\n", ioc->name, raid_device->handle,
7821 (unsigned long long) raid_device->wwid);
7822 _scsih_raid_device_remove(ioc, raid_device);
7823 }
7824
Eric Moore635374e2009-03-09 01:21:12 -06007825 /* free ports attached to the sas_host */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307826 list_for_each_entry_safe(mpt2sas_port, next_port,
Eric Moore635374e2009-03-09 01:21:12 -06007827 &ioc->sas_hba.sas_port_list, port_list) {
7828 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307829 SAS_END_DEVICE)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307830 mpt2sas_device_remove_by_sas_address(ioc,
Eric Moore635374e2009-03-09 01:21:12 -06007831 mpt2sas_port->remote_identify.sas_address);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307832 else if (mpt2sas_port->remote_identify.device_type ==
7833 SAS_EDGE_EXPANDER_DEVICE ||
7834 mpt2sas_port->remote_identify.device_type ==
7835 SAS_FANOUT_EXPANDER_DEVICE)
7836 mpt2sas_expander_remove(ioc,
7837 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007838 }
7839
7840 /* free phys attached to the sas_host */
7841 if (ioc->sas_hba.num_phys) {
7842 kfree(ioc->sas_hba.phy);
7843 ioc->sas_hba.phy = NULL;
7844 ioc->sas_hba.num_phys = 0;
7845 }
7846
7847 sas_remove_host(shost);
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05307848 scsi_remove_host(shost);
kashyap.desai@lsi.com9ae89b02011-08-04 16:47:50 +05307849 mpt2sas_base_detach(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007850 list_del(&ioc->list);
Eric Moore635374e2009-03-09 01:21:12 -06007851 scsi_host_put(shost);
7852}
7853
7854/**
7855 * _scsih_probe_boot_devices - reports 1st device
7856 * @ioc: per adapter object
7857 *
7858 * If specified in bios page 2, this routine reports the 1st
7859 * device scsi-ml or sas transport for persistent boot device
7860 * purposes. Please refer to function _scsih_determine_boot_device()
7861 */
7862static void
7863_scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7864{
7865 u8 is_raid;
7866 void *device;
7867 struct _sas_device *sas_device;
7868 struct _raid_device *raid_device;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307869 u16 handle;
7870 u64 sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007871 u64 sas_address;
7872 unsigned long flags;
7873 int rc;
7874
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307875 /* no Bios, return immediately */
7876 if (!ioc->bios_pg3.BiosVersion)
7877 return;
7878
Eric Moore635374e2009-03-09 01:21:12 -06007879 device = NULL;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307880 is_raid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007881 if (ioc->req_boot_device.device) {
7882 device = ioc->req_boot_device.device;
7883 is_raid = ioc->req_boot_device.is_raid;
7884 } else if (ioc->req_alt_boot_device.device) {
7885 device = ioc->req_alt_boot_device.device;
7886 is_raid = ioc->req_alt_boot_device.is_raid;
7887 } else if (ioc->current_boot_device.device) {
7888 device = ioc->current_boot_device.device;
7889 is_raid = ioc->current_boot_device.is_raid;
7890 }
7891
7892 if (!device)
7893 return;
7894
7895 if (is_raid) {
7896 raid_device = device;
7897 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7898 raid_device->id, 0);
7899 if (rc)
7900 _scsih_raid_device_remove(ioc, raid_device);
7901 } else {
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307902 spin_lock_irqsave(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06007903 sas_device = device;
7904 handle = sas_device->handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307905 sas_address_parent = sas_device->sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007906 sas_address = sas_device->sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06007907 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7908 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307909
7910 if (ioc->hide_drives)
7911 return;
Eric Moore635374e2009-03-09 01:21:12 -06007912 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307913 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -06007914 _scsih_sas_device_remove(ioc, sas_device);
7915 } else if (!sas_device->starget) {
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307916 if (!ioc->is_driver_loading) {
7917 mpt2sas_transport_port_remove(ioc,
7918 sas_address,
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05307919 sas_address_parent);
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307920 _scsih_sas_device_remove(ioc, sas_device);
7921 }
Eric Moore635374e2009-03-09 01:21:12 -06007922 }
7923 }
7924}
7925
7926/**
7927 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7928 * @ioc: per adapter object
7929 *
7930 * Called during initial loading of the driver.
7931 */
7932static void
7933_scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7934{
7935 struct _raid_device *raid_device, *raid_next;
7936 int rc;
7937
7938 list_for_each_entry_safe(raid_device, raid_next,
7939 &ioc->raid_device_list, list) {
7940 if (raid_device->starget)
7941 continue;
7942 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7943 raid_device->id, 0);
7944 if (rc)
7945 _scsih_raid_device_remove(ioc, raid_device);
7946 }
7947}
7948
7949/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307950 * _scsih_probe_sas - reporting sas devices to sas transport
Eric Moore635374e2009-03-09 01:21:12 -06007951 * @ioc: per adapter object
7952 *
7953 * Called during initial loading of the driver.
7954 */
7955static void
7956_scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7957{
7958 struct _sas_device *sas_device, *next;
7959 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06007960
7961 /* SAS Device List */
7962 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7963 list) {
Eric Moore635374e2009-03-09 01:21:12 -06007964
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307965 if (ioc->hide_drives)
7966 continue;
7967
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307968 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7969 sas_device->sas_address_parent)) {
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307970 list_del(&sas_device->list);
7971 kfree(sas_device);
7972 continue;
Eric Moore635374e2009-03-09 01:21:12 -06007973 } else if (!sas_device->starget) {
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307974 if (!ioc->is_driver_loading) {
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05307975 mpt2sas_transport_port_remove(ioc,
7976 sas_device->sas_address,
7977 sas_device->sas_address_parent);
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307978 list_del(&sas_device->list);
7979 kfree(sas_device);
7980 continue;
7981 }
Eric Moore635374e2009-03-09 01:21:12 -06007982 }
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307983 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7984 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7985 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06007986 }
7987}
7988
7989/**
7990 * _scsih_probe_devices - probing for devices
7991 * @ioc: per adapter object
7992 *
7993 * Called during initial loading of the driver.
7994 */
7995static void
7996_scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7997{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307998 u16 volume_mapping_flags;
Eric Moore635374e2009-03-09 01:21:12 -06007999
8000 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8001 return; /* return when IOC doesn't support initiator mode */
8002
8003 _scsih_probe_boot_devices(ioc);
8004
8005 if (ioc->ir_firmware) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308006 volume_mapping_flags =
8007 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8008 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8009 if (volume_mapping_flags ==
8010 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
Eric Moore635374e2009-03-09 01:21:12 -06008011 _scsih_probe_raid(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308012 _scsih_probe_sas(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008013 } else {
Eric Moore635374e2009-03-09 01:21:12 -06008014 _scsih_probe_sas(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308015 _scsih_probe_raid(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008016 }
8017 } else
8018 _scsih_probe_sas(ioc);
8019}
8020
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308021
8022/**
8023 * _scsih_scan_start - scsi lld callback for .scan_start
8024 * @shost: SCSI host pointer
8025 *
8026 * The shost has the ability to discover targets on its own instead
8027 * of scanning the entire bus. In our implemention, we will kick off
8028 * firmware discovery.
8029 */
8030static void
8031_scsih_scan_start(struct Scsi_Host *shost)
8032{
8033 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8034 int rc;
8035
8036 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8037 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
8038
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05308039 if (disable_discovery > 0)
8040 return;
8041
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308042 ioc->start_scan = 1;
8043 rc = mpt2sas_port_enable(ioc);
8044
8045 if (rc != 0)
8046 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
8047}
8048
8049/**
8050 * _scsih_scan_finished - scsi lld callback for .scan_finished
8051 * @shost: SCSI host pointer
8052 * @time: elapsed time of the scan in jiffies
8053 *
8054 * This function will be called periodically until it returns 1 with the
8055 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8056 * we wait for firmware discovery to complete, then return 1.
8057 */
8058static int
8059_scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8060{
8061 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8062
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05308063 if (disable_discovery > 0) {
8064 ioc->is_driver_loading = 0;
8065 ioc->wait_for_discovery_to_complete = 0;
8066 return 1;
8067 }
8068
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308069 if (time >= (300 * HZ)) {
8070 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8071 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
8072 "(timeout=300s)\n", ioc->name);
8073 ioc->is_driver_loading = 0;
8074 return 1;
8075 }
8076
8077 if (ioc->start_scan)
8078 return 0;
8079
8080 if (ioc->start_scan_failed) {
8081 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
8082 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
8083 ioc->is_driver_loading = 0;
8084 ioc->wait_for_discovery_to_complete = 0;
8085 ioc->remove_host = 1;
8086 return 1;
8087 }
8088
8089 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
8090 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8091
8092 if (ioc->wait_for_discovery_to_complete) {
8093 ioc->wait_for_discovery_to_complete = 0;
8094 _scsih_probe_devices(ioc);
8095 }
8096 mpt2sas_base_start_watchdog(ioc);
8097 ioc->is_driver_loading = 0;
8098 return 1;
8099}
8100
8101
Eric Moore635374e2009-03-09 01:21:12 -06008102/**
Eric Moored5d135b2009-05-18 13:02:08 -06008103 * _scsih_probe - attach and add scsi host
Eric Moore635374e2009-03-09 01:21:12 -06008104 * @pdev: PCI device struct
8105 * @id: pci device id
8106 *
8107 * Returns 0 success, anything else error.
8108 */
8109static int
Eric Moored5d135b2009-05-18 13:02:08 -06008110_scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
Eric Moore635374e2009-03-09 01:21:12 -06008111{
8112 struct MPT2SAS_ADAPTER *ioc;
8113 struct Scsi_Host *shost;
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308114 int rv;
Eric Moore635374e2009-03-09 01:21:12 -06008115
8116 shost = scsi_host_alloc(&scsih_driver_template,
8117 sizeof(struct MPT2SAS_ADAPTER));
8118 if (!shost)
8119 return -ENODEV;
8120
8121 /* init local params */
8122 ioc = shost_priv(shost);
8123 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
8124 INIT_LIST_HEAD(&ioc->list);
Eric Mooreba33fad2009-03-15 21:37:18 -06008125 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
Eric Moore635374e2009-03-09 01:21:12 -06008126 ioc->shost = shost;
8127 ioc->id = mpt_ids++;
8128 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
8129 ioc->pdev = pdev;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308130 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8131 ioc->is_warpdrive = 1;
8132 ioc->hide_ir_msg = 1;
8133 } else
8134 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
Eric Moore635374e2009-03-09 01:21:12 -06008135 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8136 ioc->tm_cb_idx = tm_cb_idx;
8137 ioc->ctl_cb_idx = ctl_cb_idx;
8138 ioc->base_cb_idx = base_cb_idx;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308139 ioc->port_enable_cb_idx = port_enable_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008140 ioc->transport_cb_idx = transport_cb_idx;
Kashyap, Desai744090d2009-10-05 15:56:56 +05308141 ioc->scsih_cb_idx = scsih_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008142 ioc->config_cb_idx = config_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308143 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308144 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308145 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008146 ioc->logging_level = logging_level;
nagalakshmi.nandigama@lsi.com845a0e42011-12-01 07:42:04 +05308147 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
Eric Moore635374e2009-03-09 01:21:12 -06008148 /* misc semaphores and spin locks */
Kashyap, Desaid2742132010-06-17 13:28:55 +05308149 mutex_init(&ioc->reset_in_progress_mutex);
Eric Moore635374e2009-03-09 01:21:12 -06008150 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8151 spin_lock_init(&ioc->scsi_lookup_lock);
8152 spin_lock_init(&ioc->sas_device_lock);
8153 spin_lock_init(&ioc->sas_node_lock);
8154 spin_lock_init(&ioc->fw_event_lock);
8155 spin_lock_init(&ioc->raid_device_lock);
8156
8157 INIT_LIST_HEAD(&ioc->sas_device_list);
8158 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8159 INIT_LIST_HEAD(&ioc->sas_expander_list);
8160 INIT_LIST_HEAD(&ioc->fw_event_list);
8161 INIT_LIST_HEAD(&ioc->raid_device_list);
8162 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308163 INIT_LIST_HEAD(&ioc->delayed_tr_list);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308164 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
Joe Lawrence3b3e6f82013-08-08 16:45:38 -04008165 INIT_LIST_HEAD(&ioc->reply_queue_list);
Eric Moore635374e2009-03-09 01:21:12 -06008166
8167 /* init shost parameters */
Eric Moored334aa72010-04-22 10:47:40 -06008168 shost->max_cmd_len = 32;
Eric Moore635374e2009-03-09 01:21:12 -06008169 shost->max_lun = max_lun;
8170 shost->transportt = mpt2sas_transport_template;
8171 shost->unique_id = ioc->id;
8172
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308173 if (max_sectors != 0xFFFF) {
8174 if (max_sectors < 64) {
8175 shost->max_sectors = 64;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05308176 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8177 "for max_sectors, range is 64 to 32767. Assigning "
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308178 "value of 64.\n", ioc->name, max_sectors);
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05308179 } else if (max_sectors > 32767) {
8180 shost->max_sectors = 32767;
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308181 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8182 "for max_sectors, range is 64 to 8192. Assigning "
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05308183 "default value of 32767.\n", ioc->name,
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308184 max_sectors);
8185 } else {
8186 shost->max_sectors = max_sectors & 0xFFFE;
8187 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
8188 "set to %d\n", ioc->name, shost->max_sectors);
8189 }
8190 }
8191
Martin K. Petersen5e95e732012-08-28 14:29:37 -04008192 /* register EEDP capabilities with SCSI layer */
8193 if (prot_mask)
8194 scsi_host_set_prot(shost, prot_mask);
8195 else
8196 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8197 | SHOST_DIF_TYPE2_PROTECTION
8198 | SHOST_DIF_TYPE3_PROTECTION);
8199
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308200 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
Eric Moore3c621b32009-05-18 12:59:41 -06008201
Eric Moore635374e2009-03-09 01:21:12 -06008202 /* event thread */
8203 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8204 "fw_event%d", ioc->id);
8205 ioc->firmware_event_thread = create_singlethread_workqueue(
8206 ioc->firmware_event_name);
8207 if (!ioc->firmware_event_thread) {
8208 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8209 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308210 rv = -ENODEV;
Eric Moore635374e2009-03-09 01:21:12 -06008211 goto out_thread_fail;
8212 }
8213
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308214 ioc->is_driver_loading = 1;
Eric Moore635374e2009-03-09 01:21:12 -06008215 if ((mpt2sas_base_attach(ioc))) {
8216 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8217 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308218 rv = -ENODEV;
Eric Moore635374e2009-03-09 01:21:12 -06008219 goto out_attach_fail;
8220 }
8221
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308222 if (ioc->is_warpdrive) {
8223 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8224 ioc->hide_drives = 0;
8225 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8226 ioc->hide_drives = 1;
8227 else {
8228 if (_scsih_get_num_volumes(ioc))
8229 ioc->hide_drives = 1;
8230 else
8231 ioc->hide_drives = 0;
8232 }
8233 } else
8234 ioc->hide_drives = 0;
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05308235
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308236 rv = scsi_add_host(shost, &pdev->dev);
8237 if (rv) {
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05308238 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8239 ioc->name, __FILE__, __LINE__, __func__);
8240 goto out_add_shost_fail;
8241 }
8242
nagalakshmi.nandigama@lsi.com2cb6fc82011-12-13 09:29:15 +05308243 scsi_scan_host(shost);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308244
Eric Moore635374e2009-03-09 01:21:12 -06008245 return 0;
8246
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05308247 out_add_shost_fail:
8248 mpt2sas_base_detach(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008249 out_attach_fail:
8250 destroy_workqueue(ioc->firmware_event_thread);
8251 out_thread_fail:
8252 list_del(&ioc->list);
Tomas Henzlf555e052012-04-17 15:24:48 +02008253 scsi_host_put(shost);
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308254 return rv;
Eric Moore635374e2009-03-09 01:21:12 -06008255}
8256
8257#ifdef CONFIG_PM
8258/**
Eric Moored5d135b2009-05-18 13:02:08 -06008259 * _scsih_suspend - power management suspend main entry point
Eric Moore635374e2009-03-09 01:21:12 -06008260 * @pdev: PCI device struct
8261 * @state: PM state change to (usually PCI_D3)
8262 *
8263 * Returns 0 success, anything else error.
8264 */
8265static int
Eric Moored5d135b2009-05-18 13:02:08 -06008266_scsih_suspend(struct pci_dev *pdev, pm_message_t state)
Eric Moore635374e2009-03-09 01:21:12 -06008267{
8268 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8269 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05308270 pci_power_t device_state;
Eric Moore635374e2009-03-09 01:21:12 -06008271
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308272 mpt2sas_base_stop_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008273 scsi_block_requests(shost);
Sreekanth Reddy3627dba2013-07-25 11:25:57 +05308274 _scsih_ir_shutdown(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008275 device_state = pci_choose_state(pdev, state);
8276 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8277 "operating state [D%d]\n", ioc->name, pdev,
8278 pci_name(pdev), device_state);
8279
8280 mpt2sas_base_free_resources(ioc);
8281 pci_save_state(pdev);
Eric Moore635374e2009-03-09 01:21:12 -06008282 pci_set_power_state(pdev, device_state);
8283 return 0;
8284}
8285
8286/**
Eric Moored5d135b2009-05-18 13:02:08 -06008287 * _scsih_resume - power management resume main entry point
Eric Moore635374e2009-03-09 01:21:12 -06008288 * @pdev: PCI device struct
8289 *
8290 * Returns 0 success, anything else error.
8291 */
8292static int
Eric Moored5d135b2009-05-18 13:02:08 -06008293_scsih_resume(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06008294{
8295 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8296 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05308297 pci_power_t device_state = pdev->current_state;
Eric Moore635374e2009-03-09 01:21:12 -06008298 int r;
8299
8300 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8301 "operating state [D%d]\n", ioc->name, pdev,
8302 pci_name(pdev), device_state);
8303
8304 pci_set_power_state(pdev, PCI_D0);
8305 pci_enable_wake(pdev, PCI_D0, 0);
8306 pci_restore_state(pdev);
8307 ioc->pdev = pdev;
8308 r = mpt2sas_base_map_resources(ioc);
8309 if (r)
8310 return r;
8311
8312 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8313 scsi_unblock_requests(shost);
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308314 mpt2sas_base_start_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008315 return 0;
8316}
8317#endif /* CONFIG_PM */
8318
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308319/**
8320 * _scsih_pci_error_detected - Called when a PCI error is detected.
8321 * @pdev: PCI device struct
8322 * @state: PCI channel state
8323 *
8324 * Description: Called when a PCI error is detected.
8325 *
8326 * Return value:
8327 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8328 */
8329static pci_ers_result_t
8330_scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8331{
8332 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8333 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8334
8335 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8336 ioc->name, state);
8337
8338 switch (state) {
8339 case pci_channel_io_normal:
8340 return PCI_ERS_RESULT_CAN_RECOVER;
8341 case pci_channel_io_frozen:
Eric Moore3cb54692010-07-08 14:44:34 -06008342 /* Fatal error, prepare for slot reset */
8343 ioc->pci_error_recovery = 1;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308344 scsi_block_requests(ioc->shost);
8345 mpt2sas_base_stop_watchdog(ioc);
8346 mpt2sas_base_free_resources(ioc);
8347 return PCI_ERS_RESULT_NEED_RESET;
8348 case pci_channel_io_perm_failure:
Eric Moore3cb54692010-07-08 14:44:34 -06008349 /* Permanent error, prepare for device removal */
8350 ioc->pci_error_recovery = 1;
8351 mpt2sas_base_stop_watchdog(ioc);
8352 _scsih_flush_running_cmds(ioc);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308353 return PCI_ERS_RESULT_DISCONNECT;
8354 }
8355 return PCI_ERS_RESULT_NEED_RESET;
8356}
8357
8358/**
8359 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8360 * @pdev: PCI device struct
8361 *
8362 * Description: This routine is called by the pci error recovery
8363 * code after the PCI slot has been reset, just before we
8364 * should resume normal operations.
8365 */
8366static pci_ers_result_t
8367_scsih_pci_slot_reset(struct pci_dev *pdev)
8368{
8369 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8370 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8371 int rc;
8372
8373 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8374 ioc->name);
8375
Eric Moore3cb54692010-07-08 14:44:34 -06008376 ioc->pci_error_recovery = 0;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308377 ioc->pdev = pdev;
Eric Moore3cb54692010-07-08 14:44:34 -06008378 pci_restore_state(pdev);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308379 rc = mpt2sas_base_map_resources(ioc);
8380 if (rc)
8381 return PCI_ERS_RESULT_DISCONNECT;
8382
8383
8384 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8385 FORCE_BIG_HAMMER);
8386
8387 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8388 (rc == 0) ? "success" : "failed");
8389
8390 if (!rc)
8391 return PCI_ERS_RESULT_RECOVERED;
8392 else
8393 return PCI_ERS_RESULT_DISCONNECT;
8394}
8395
8396/**
8397 * _scsih_pci_resume() - resume normal ops after PCI reset
8398 * @pdev: pointer to PCI device
8399 *
8400 * Called when the error recovery driver tells us that its
8401 * OK to resume normal operation. Use completion to allow
8402 * halted scsi ops to resume.
8403 */
8404static void
8405_scsih_pci_resume(struct pci_dev *pdev)
8406{
8407 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8408 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8409
8410 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8411
8412 pci_cleanup_aer_uncorrect_error_status(pdev);
8413 mpt2sas_base_start_watchdog(ioc);
8414 scsi_unblock_requests(ioc->shost);
8415}
8416
8417/**
8418 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8419 * @pdev: pointer to PCI device
8420 */
8421static pci_ers_result_t
8422_scsih_pci_mmio_enabled(struct pci_dev *pdev)
8423{
8424 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8425 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8426
8427 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8428 ioc->name);
8429
8430 /* TODO - dump whatever for debugging purposes */
8431
8432 /* Request a slot reset. */
8433 return PCI_ERS_RESULT_NEED_RESET;
8434}
8435
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07008436static const struct pci_error_handlers _scsih_err_handler = {
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308437 .error_detected = _scsih_pci_error_detected,
8438 .mmio_enabled = _scsih_pci_mmio_enabled,
8439 .slot_reset = _scsih_pci_slot_reset,
8440 .resume = _scsih_pci_resume,
8441};
Eric Moore635374e2009-03-09 01:21:12 -06008442
8443static struct pci_driver scsih_driver = {
8444 .name = MPT2SAS_DRIVER_NAME,
8445 .id_table = scsih_pci_table,
Eric Moored5d135b2009-05-18 13:02:08 -06008446 .probe = _scsih_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008447 .remove = _scsih_remove,
Kashyap, Desai744090d2009-10-05 15:56:56 +05308448 .shutdown = _scsih_shutdown,
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308449 .err_handler = &_scsih_err_handler,
Eric Moore635374e2009-03-09 01:21:12 -06008450#ifdef CONFIG_PM
Eric Moored5d135b2009-05-18 13:02:08 -06008451 .suspend = _scsih_suspend,
8452 .resume = _scsih_resume,
Eric Moore635374e2009-03-09 01:21:12 -06008453#endif
8454};
8455
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308456/* raid transport support */
8457static struct raid_function_template mpt2sas_raid_functions = {
8458 .cookie = &scsih_driver_template,
8459 .is_raid = _scsih_is_raid,
8460 .get_resync = _scsih_get_resync,
8461 .get_state = _scsih_get_state,
8462};
Eric Moore635374e2009-03-09 01:21:12 -06008463
8464/**
Eric Moored5d135b2009-05-18 13:02:08 -06008465 * _scsih_init - main entry point for this driver.
Eric Moore635374e2009-03-09 01:21:12 -06008466 *
8467 * Returns 0 success, anything else error.
8468 */
8469static int __init
Eric Moored5d135b2009-05-18 13:02:08 -06008470_scsih_init(void)
Eric Moore635374e2009-03-09 01:21:12 -06008471{
8472 int error;
8473
8474 mpt_ids = 0;
8475 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8476 MPT2SAS_DRIVER_VERSION);
8477
8478 mpt2sas_transport_template =
8479 sas_attach_transport(&mpt2sas_transport_functions);
8480 if (!mpt2sas_transport_template)
8481 return -ENODEV;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308482 /* raid transport support */
8483 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8484 if (!mpt2sas_raid_template) {
8485 sas_release_transport(mpt2sas_transport_template);
8486 return -ENODEV;
8487 }
Eric Moore635374e2009-03-09 01:21:12 -06008488
8489 mpt2sas_base_initialize_callback_handler();
8490
8491 /* queuecommand callback hander */
Eric Moored5d135b2009-05-18 13:02:08 -06008492 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
Eric Moore635374e2009-03-09 01:21:12 -06008493
Uwe Kleine-König65155b32010-06-11 12:17:01 +02008494 /* task management callback handler */
Eric Moored5d135b2009-05-18 13:02:08 -06008495 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
Eric Moore635374e2009-03-09 01:21:12 -06008496
8497 /* base internal commands callback handler */
8498 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308499 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8500 mpt2sas_port_enable_done);
Eric Moore635374e2009-03-09 01:21:12 -06008501
8502 /* transport internal commands callback handler */
8503 transport_cb_idx = mpt2sas_base_register_callback_handler(
8504 mpt2sas_transport_done);
8505
Kashyap, Desai744090d2009-10-05 15:56:56 +05308506 /* scsih internal commands callback handler */
8507 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8508
Eric Moore635374e2009-03-09 01:21:12 -06008509 /* configuration page API internal commands callback handler */
8510 config_cb_idx = mpt2sas_base_register_callback_handler(
8511 mpt2sas_config_done);
8512
8513 /* ctl module callback handler */
8514 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8515
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308516 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8517 _scsih_tm_tr_complete);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308518
8519 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8520 _scsih_tm_volume_tr_complete);
8521
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308522 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8523 _scsih_sas_control_complete);
8524
Eric Moore635374e2009-03-09 01:21:12 -06008525 mpt2sas_ctl_init();
8526
8527 error = pci_register_driver(&scsih_driver);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308528 if (error) {
8529 /* raid transport support */
8530 raid_class_release(mpt2sas_raid_template);
Eric Moore635374e2009-03-09 01:21:12 -06008531 sas_release_transport(mpt2sas_transport_template);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308532 }
Eric Moore635374e2009-03-09 01:21:12 -06008533
8534 return error;
8535}
8536
8537/**
Eric Moored5d135b2009-05-18 13:02:08 -06008538 * _scsih_exit - exit point for this driver (when it is a module).
Eric Moore635374e2009-03-09 01:21:12 -06008539 *
8540 * Returns 0 success, anything else error.
8541 */
8542static void __exit
Eric Moored5d135b2009-05-18 13:02:08 -06008543_scsih_exit(void)
Eric Moore635374e2009-03-09 01:21:12 -06008544{
8545 printk(KERN_INFO "mpt2sas version %s unloading\n",
8546 MPT2SAS_DRIVER_VERSION);
8547
8548 pci_unregister_driver(&scsih_driver);
8549
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308550 mpt2sas_ctl_exit();
8551
Eric Moore635374e2009-03-09 01:21:12 -06008552 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8553 mpt2sas_base_release_callback_handler(tm_cb_idx);
8554 mpt2sas_base_release_callback_handler(base_cb_idx);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308555 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008556 mpt2sas_base_release_callback_handler(transport_cb_idx);
Kashyap, Desai744090d2009-10-05 15:56:56 +05308557 mpt2sas_base_release_callback_handler(scsih_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008558 mpt2sas_base_release_callback_handler(config_cb_idx);
8559 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8560
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308561 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308562 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308563 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8564
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308565 /* raid transport support */
8566 raid_class_release(mpt2sas_raid_template);
8567 sas_release_transport(mpt2sas_transport_template);
8568
Eric Moore635374e2009-03-09 01:21:12 -06008569}
8570
Eric Moored5d135b2009-05-18 13:02:08 -06008571module_init(_scsih_init);
8572module_exit(_scsih_exit);