blob: 42fef914d441f4d85ccf302af12f327cf1d5fd3c [file] [log] [blame]
Eric Moore635374e2009-03-09 01:21:12 -06001/*
2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
3 *
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
Sreekanth Reddye9edbe32014-09-12 15:35:18 +05305 * Copyright (C) 2007-2014 LSI Corporation
Eric Moore635374e2009-03-09 01:21:12 -06006 * (mailto:DL-MPTFusionLinux@lsi.com)
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * NO WARRANTY
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
28
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
37
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
41 * USA.
42 */
43
Eric Moore635374e2009-03-09 01:21:12 -060044#include <linux/module.h>
45#include <linux/kernel.h>
46#include <linux/init.h>
47#include <linux/errno.h>
48#include <linux/blkdev.h>
49#include <linux/sched.h>
50#include <linux/workqueue.h>
51#include <linux/delay.h>
52#include <linux/pci.h>
53#include <linux/interrupt.h>
Kashyap, Desaief7c80c2010-04-05 14:20:07 +053054#include <linux/aer.h>
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +053055#include <linux/raid_class.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090056#include <linux/slab.h>
Eric Moore635374e2009-03-09 01:21:12 -060057
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +053058#include <asm/unaligned.h>
59
Eric Moore635374e2009-03-09 01:21:12 -060060#include "mpt2sas_base.h"
61
62MODULE_AUTHOR(MPT2SAS_AUTHOR);
63MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
64MODULE_LICENSE("GPL");
65MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
66
67#define RAID_CHANNEL 1
68
69/* forward proto's */
70static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
71 struct _sas_node *sas_expander);
72static void _firmware_event_work(struct work_struct *work);
73
Kashyap, Desaif3eedd62010-06-17 13:46:13 +053074static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
75
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +053076static void _scsih_scan_start(struct Scsi_Host *shost);
77static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
78
Eric Moore635374e2009-03-09 01:21:12 -060079/* global parameters */
Eric Mooreba33fad2009-03-15 21:37:18 -060080LIST_HEAD(mpt2sas_ioc_list);
Eric Moore635374e2009-03-09 01:21:12 -060081
82/* local parameters */
Eric Moore635374e2009-03-09 01:21:12 -060083static u8 scsi_io_cb_idx = -1;
84static u8 tm_cb_idx = -1;
85static u8 ctl_cb_idx = -1;
86static u8 base_cb_idx = -1;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +053087static u8 port_enable_cb_idx = -1;
Eric Moore635374e2009-03-09 01:21:12 -060088static u8 transport_cb_idx = -1;
Kashyap, Desai744090d2009-10-05 15:56:56 +053089static u8 scsih_cb_idx = -1;
Eric Moore635374e2009-03-09 01:21:12 -060090static u8 config_cb_idx = -1;
91static int mpt_ids;
92
Kashyap, Desai77e63ed2009-09-14 11:04:23 +053093static u8 tm_tr_cb_idx = -1 ;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +053094static u8 tm_tr_volume_cb_idx = -1 ;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +053095static u8 tm_sas_control_cb_idx = -1;
96
Eric Moore635374e2009-03-09 01:21:12 -060097/* command line options */
Eric Mooreba33fad2009-03-15 21:37:18 -060098static u32 logging_level;
Eric Moore635374e2009-03-09 01:21:12 -060099MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
100 "(default=0)");
101
Kashyap, Desaia3e1e552011-06-14 10:56:12 +0530102static ushort max_sectors = 0xFFFF;
103module_param(max_sectors, ushort, 0);
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +0530104MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
Kashyap, Desaia3e1e552011-06-14 10:56:12 +0530105
Reddy, Sreekanthb0df96a02013-02-26 16:59:59 +0530106static int missing_delay[2] = {-1, -1};
107module_param_array(missing_delay, int, NULL, 0);
108MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
109
Eric Moore635374e2009-03-09 01:21:12 -0600110/* scsi-mid layer global parmeter is max_report_luns, which is 511 */
111#define MPT2SAS_MAX_LUN (16895)
112static int max_lun = MPT2SAS_MAX_LUN;
113module_param(max_lun, int, 0);
114MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
115
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530116/* diag_buffer_enable is bitwise
117 * bit 0 set = TRACE
118 * bit 1 set = SNAPSHOT
119 * bit 2 set = EXTENDED
120 *
121 * Either bit can be set, or both
122 */
123static int diag_buffer_enable = -1;
124module_param(diag_buffer_enable, int, 0);
125MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
126 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
127
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +0530128static int disable_discovery = -1;
129module_param(disable_discovery, int, 0);
130MODULE_PARM_DESC(disable_discovery, " disable discovery ");
131
Martin K. Petersen5e95e732012-08-28 14:29:37 -0400132/* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
133static int prot_mask = 0;
134module_param(prot_mask, int, 0);
135MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
136
Eric Moore635374e2009-03-09 01:21:12 -0600137/**
138 * struct sense_info - common structure for obtaining sense keys
139 * @skey: sense key
140 * @asc: additional sense code
141 * @ascq: additional sense code qualifier
142 */
143struct sense_info {
144 u8 skey;
145 u8 asc;
146 u8 ascq;
147};
148
149
Sreekanth Reddybd58ea32014-09-12 15:35:19 +0530150#define MPT2SAS_TURN_ON_PFA_LED (0xFFFC)
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530151#define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
152#define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
Eric Moore635374e2009-03-09 01:21:12 -0600153/**
154 * struct fw_event_work - firmware event struct
155 * @list: link list framework
156 * @work: work object (ioc->fault_reset_work_q)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +0530157 * @cancel_pending_work: flag set during reset handling
Eric Moore635374e2009-03-09 01:21:12 -0600158 * @ioc: per adapter object
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530159 * @device_handle: device handle
Eric Moore635374e2009-03-09 01:21:12 -0600160 * @VF_ID: virtual function id
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530161 * @VP_ID: virtual port id
Eric Moore635374e2009-03-09 01:21:12 -0600162 * @ignore: flag meaning this event has been marked to ignore
163 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
164 * @event_data: reply event data payload follows
165 *
166 * This object stored on ioc->fw_event_list.
167 */
168struct fw_event_work {
169 struct list_head list;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +0530170 u8 cancel_pending_work;
171 struct delayed_work delayed_work;
Eric Moore635374e2009-03-09 01:21:12 -0600172 struct MPT2SAS_ADAPTER *ioc;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530173 u16 device_handle;
Eric Moore635374e2009-03-09 01:21:12 -0600174 u8 VF_ID;
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530175 u8 VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -0600176 u8 ignore;
177 u16 event;
Joe Lawrence00713ad2014-06-25 17:03:33 -0400178 char event_data[0] __aligned(4);
Eric Moore635374e2009-03-09 01:21:12 -0600179};
180
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +0530181/* raid transport support */
182static struct raid_template *mpt2sas_raid_template;
183
Eric Moore635374e2009-03-09 01:21:12 -0600184/**
185 * struct _scsi_io_transfer - scsi io transfer
186 * @handle: sas device handle (assigned by firmware)
187 * @is_raid: flag set for hidden raid components
188 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
189 * @data_length: data transfer length
190 * @data_dma: dma pointer to data
191 * @sense: sense data
192 * @lun: lun number
193 * @cdb_length: cdb length
194 * @cdb: cdb contents
Eric Moore635374e2009-03-09 01:21:12 -0600195 * @timeout: timeout for this command
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530196 * @VF_ID: virtual function id
197 * @VP_ID: virtual port id
198 * @valid_reply: flag set for reply message
Eric Moore635374e2009-03-09 01:21:12 -0600199 * @sense_length: sense length
200 * @ioc_status: ioc status
201 * @scsi_state: scsi state
202 * @scsi_status: scsi staus
203 * @log_info: log information
204 * @transfer_length: data length transfer when there is a reply message
205 *
206 * Used for sending internal scsi commands to devices within this module.
207 * Refer to _scsi_send_scsi_io().
208 */
209struct _scsi_io_transfer {
210 u16 handle;
211 u8 is_raid;
212 enum dma_data_direction dir;
213 u32 data_length;
214 dma_addr_t data_dma;
215 u8 sense[SCSI_SENSE_BUFFERSIZE];
216 u32 lun;
217 u8 cdb_length;
218 u8 cdb[32];
219 u8 timeout;
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530220 u8 VF_ID;
221 u8 VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -0600222 u8 valid_reply;
223 /* the following bits are only valid when 'valid_reply = 1' */
224 u32 sense_length;
225 u16 ioc_status;
226 u8 scsi_state;
227 u8 scsi_status;
228 u32 log_info;
229 u32 transfer_length;
230};
231
232/*
233 * The pci device ids are defined in mpi/mpi2_cnfg.h.
234 */
235static struct pci_device_id scsih_pci_table[] = {
236 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
237 PCI_ANY_ID, PCI_ANY_ID },
238 /* Falcon ~ 2008*/
239 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
240 PCI_ANY_ID, PCI_ANY_ID },
241 /* Liberator ~ 2108 */
242 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
243 PCI_ANY_ID, PCI_ANY_ID },
244 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
245 PCI_ANY_ID, PCI_ANY_ID },
246 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
247 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desaidb271362009-09-23 17:24:27 +0530248 /* Meteor ~ 2116 */
Eric Moore635374e2009-03-09 01:21:12 -0600249 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
250 PCI_ANY_ID, PCI_ANY_ID },
251 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
252 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desaidb271362009-09-23 17:24:27 +0530253 /* Thunderbolt ~ 2208 */
254 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
255 PCI_ANY_ID, PCI_ANY_ID },
256 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
257 PCI_ANY_ID, PCI_ANY_ID },
258 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
259 PCI_ANY_ID, PCI_ANY_ID },
260 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
261 PCI_ANY_ID, PCI_ANY_ID },
262 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
263 PCI_ANY_ID, PCI_ANY_ID },
264 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
265 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai203d65b2010-06-17 13:37:59 +0530266 /* Mustang ~ 2308 */
267 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
Kashyap, Desaidb271362009-09-23 17:24:27 +0530268 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai203d65b2010-06-17 13:37:59 +0530269 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
270 PCI_ANY_ID, PCI_ANY_ID },
271 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
Kashyap, Desaidb271362009-09-23 17:24:27 +0530272 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +0530273 /* SSS6200 */
274 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
275 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore635374e2009-03-09 01:21:12 -0600276 {0} /* Terminating entry */
277};
278MODULE_DEVICE_TABLE(pci, scsih_pci_table);
279
280/**
Eric Moored5d135b2009-05-18 13:02:08 -0600281 * _scsih_set_debug_level - global setting of ioc->logging_level.
Eric Moore635374e2009-03-09 01:21:12 -0600282 *
283 * Note: The logging levels are defined in mpt2sas_debug.h.
284 */
285static int
Eric Moored5d135b2009-05-18 13:02:08 -0600286_scsih_set_debug_level(const char *val, struct kernel_param *kp)
Eric Moore635374e2009-03-09 01:21:12 -0600287{
288 int ret = param_set_int(val, kp);
289 struct MPT2SAS_ADAPTER *ioc;
290
291 if (ret)
292 return ret;
293
294 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
Eric Mooreba33fad2009-03-15 21:37:18 -0600295 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
Eric Moore635374e2009-03-09 01:21:12 -0600296 ioc->logging_level = logging_level;
297 return 0;
298}
Eric Moored5d135b2009-05-18 13:02:08 -0600299module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
Eric Moore635374e2009-03-09 01:21:12 -0600300 &logging_level, 0644);
301
302/**
303 * _scsih_srch_boot_sas_address - search based on sas_address
304 * @sas_address: sas address
305 * @boot_device: boot device object from bios page 2
306 *
307 * Returns 1 when there's a match, 0 means no match.
308 */
309static inline int
310_scsih_srch_boot_sas_address(u64 sas_address,
311 Mpi2BootDeviceSasWwid_t *boot_device)
312{
313 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
314}
315
316/**
317 * _scsih_srch_boot_device_name - search based on device name
318 * @device_name: device name specified in INDENTIFY fram
319 * @boot_device: boot device object from bios page 2
320 *
321 * Returns 1 when there's a match, 0 means no match.
322 */
323static inline int
324_scsih_srch_boot_device_name(u64 device_name,
325 Mpi2BootDeviceDeviceName_t *boot_device)
326{
327 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
328}
329
330/**
331 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
332 * @enclosure_logical_id: enclosure logical id
333 * @slot_number: slot number
334 * @boot_device: boot device object from bios page 2
335 *
336 * Returns 1 when there's a match, 0 means no match.
337 */
338static inline int
339_scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
340 Mpi2BootDeviceEnclosureSlot_t *boot_device)
341{
342 return (enclosure_logical_id == le64_to_cpu(boot_device->
343 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
344 SlotNumber)) ? 1 : 0;
345}
346
347/**
348 * _scsih_is_boot_device - search for matching boot device.
349 * @sas_address: sas address
350 * @device_name: device name specified in INDENTIFY fram
351 * @enclosure_logical_id: enclosure logical id
352 * @slot_number: slot number
353 * @form: specifies boot device form
354 * @boot_device: boot device object from bios page 2
355 *
356 * Returns 1 when there's a match, 0 means no match.
357 */
358static int
359_scsih_is_boot_device(u64 sas_address, u64 device_name,
360 u64 enclosure_logical_id, u16 slot, u8 form,
361 Mpi2BiosPage2BootDevice_t *boot_device)
362{
363 int rc = 0;
364
365 switch (form) {
366 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
367 if (!sas_address)
368 break;
369 rc = _scsih_srch_boot_sas_address(
370 sas_address, &boot_device->SasWwid);
371 break;
372 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
373 if (!enclosure_logical_id)
374 break;
375 rc = _scsih_srch_boot_encl_slot(
376 enclosure_logical_id,
377 slot, &boot_device->EnclosureSlot);
378 break;
379 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
380 if (!device_name)
381 break;
382 rc = _scsih_srch_boot_device_name(
383 device_name, &boot_device->DeviceName);
384 break;
385 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
386 break;
387 }
388
389 return rc;
390}
391
392/**
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530393 * _scsih_get_sas_address - set the sas_address for given device handle
394 * @handle: device handle
395 * @sas_address: sas address
396 *
397 * Returns 0 success, non-zero when failure
398 */
399static int
400_scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
401 u64 *sas_address)
402{
403 Mpi2SasDevicePage0_t sas_device_pg0;
404 Mpi2ConfigReply_t mpi_reply;
405 u32 ioc_status;
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530406 *sas_address = 0;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530407
408 if (handle <= ioc->sas_hba.num_phys) {
409 *sas_address = ioc->sas_hba.sas_address;
410 return 0;
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530411 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530412
413 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
414 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530415 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
416 __FILE__, __LINE__, __func__);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530417 return -ENXIO;
418 }
419
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530420 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
421 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
422 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
423 return 0;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530424 }
425
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530426 /* we hit this becuase the given parent handle doesn't exist */
427 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
428 return -ENXIO;
429 /* else error case */
430 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
431 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
432 __FILE__, __LINE__, __func__);
433 return -EIO;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530434}
435
436/**
Eric Moore635374e2009-03-09 01:21:12 -0600437 * _scsih_determine_boot_device - determine boot device.
438 * @ioc: per adapter object
439 * @device: either sas_device or raid_device object
440 * @is_raid: [flag] 1 = raid object, 0 = sas object
441 *
442 * Determines whether this device should be first reported device to
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300443 * to scsi-ml or sas transport, this purpose is for persistent boot device.
Eric Moore635374e2009-03-09 01:21:12 -0600444 * There are primary, alternate, and current entries in bios page 2. The order
445 * priority is primary, alternate, then current. This routine saves
446 * the corresponding device object and is_raid flag in the ioc object.
447 * The saved data to be used later in _scsih_probe_boot_devices().
448 */
449static void
450_scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
451 void *device, u8 is_raid)
452{
453 struct _sas_device *sas_device;
454 struct _raid_device *raid_device;
455 u64 sas_address;
456 u64 device_name;
457 u64 enclosure_logical_id;
458 u16 slot;
459
460 /* only process this function when driver loads */
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530461 if (!ioc->is_driver_loading)
462 return;
463
464 /* no Bios, return immediately */
465 if (!ioc->bios_pg3.BiosVersion)
Eric Moore635374e2009-03-09 01:21:12 -0600466 return;
467
468 if (!is_raid) {
469 sas_device = device;
470 sas_address = sas_device->sas_address;
471 device_name = sas_device->device_name;
472 enclosure_logical_id = sas_device->enclosure_logical_id;
473 slot = sas_device->slot;
474 } else {
475 raid_device = device;
476 sas_address = raid_device->wwid;
477 device_name = 0;
478 enclosure_logical_id = 0;
479 slot = 0;
480 }
481
482 if (!ioc->req_boot_device.device) {
483 if (_scsih_is_boot_device(sas_address, device_name,
484 enclosure_logical_id, slot,
485 (ioc->bios_pg2.ReqBootDeviceForm &
486 MPI2_BIOSPAGE2_FORM_MASK),
487 &ioc->bios_pg2.RequestedBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530488 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600489 "%s: req_boot_device(0x%016llx)\n",
490 ioc->name, __func__,
491 (unsigned long long)sas_address));
492 ioc->req_boot_device.device = device;
493 ioc->req_boot_device.is_raid = is_raid;
494 }
495 }
496
497 if (!ioc->req_alt_boot_device.device) {
498 if (_scsih_is_boot_device(sas_address, device_name,
499 enclosure_logical_id, slot,
500 (ioc->bios_pg2.ReqAltBootDeviceForm &
501 MPI2_BIOSPAGE2_FORM_MASK),
502 &ioc->bios_pg2.RequestedAltBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530503 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600504 "%s: req_alt_boot_device(0x%016llx)\n",
505 ioc->name, __func__,
506 (unsigned long long)sas_address));
507 ioc->req_alt_boot_device.device = device;
508 ioc->req_alt_boot_device.is_raid = is_raid;
509 }
510 }
511
512 if (!ioc->current_boot_device.device) {
513 if (_scsih_is_boot_device(sas_address, device_name,
514 enclosure_logical_id, slot,
515 (ioc->bios_pg2.CurrentBootDeviceForm &
516 MPI2_BIOSPAGE2_FORM_MASK),
517 &ioc->bios_pg2.CurrentBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530518 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600519 "%s: current_boot_device(0x%016llx)\n",
520 ioc->name, __func__,
521 (unsigned long long)sas_address));
522 ioc->current_boot_device.device = device;
523 ioc->current_boot_device.is_raid = is_raid;
524 }
525 }
526}
527
528/**
529 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
530 * @ioc: per adapter object
531 * @sas_address: sas address
532 * Context: Calling function should acquire ioc->sas_device_lock
533 *
534 * This searches for sas_device based on sas_address, then return sas_device
535 * object.
536 */
537struct _sas_device *
538mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
539 u64 sas_address)
540{
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530541 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600542
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530543 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
544 if (sas_device->sas_address == sas_address)
545 return sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600546
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530547 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
548 if (sas_device->sas_address == sas_address)
549 return sas_device;
550
551 return NULL;
Eric Moore635374e2009-03-09 01:21:12 -0600552}
553
554/**
555 * _scsih_sas_device_find_by_handle - sas device search
556 * @ioc: per adapter object
557 * @handle: sas device handle (assigned by firmware)
558 * Context: Calling function should acquire ioc->sas_device_lock
559 *
560 * This searches for sas_device based on sas_address, then return sas_device
561 * object.
562 */
563static struct _sas_device *
564_scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
565{
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530566 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600567
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530568 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
569 if (sas_device->handle == handle)
570 return sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600571
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530572 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
573 if (sas_device->handle == handle)
574 return sas_device;
575
576 return NULL;
Eric Moore635374e2009-03-09 01:21:12 -0600577}
578
579/**
580 * _scsih_sas_device_remove - remove sas_device from list.
581 * @ioc: per adapter object
582 * @sas_device: the sas_device object
583 * Context: This function will acquire ioc->sas_device_lock.
584 *
585 * Removing object and freeing associated memory from the ioc->sas_device_list.
586 */
587static void
588_scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
589 struct _sas_device *sas_device)
590{
591 unsigned long flags;
592
Kashyap, Desai980ead32010-04-08 17:55:22 +0530593 if (!sas_device)
594 return;
595
Eric Moore635374e2009-03-09 01:21:12 -0600596 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530597 list_del(&sas_device->list);
598 kfree(sas_device);
Eric Moore635374e2009-03-09 01:21:12 -0600599 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
600}
601
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530602
Eric Moore635374e2009-03-09 01:21:12 -0600603/**
604 * _scsih_sas_device_add - insert sas_device to the list.
605 * @ioc: per adapter object
606 * @sas_device: the sas_device object
607 * Context: This function will acquire ioc->sas_device_lock.
608 *
609 * Adding new object to the ioc->sas_device_list.
610 */
611static void
612_scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
613 struct _sas_device *sas_device)
614{
615 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -0600616
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530617 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600618 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
619 sas_device->handle, (unsigned long long)sas_device->sas_address));
620
621 spin_lock_irqsave(&ioc->sas_device_lock, flags);
622 list_add_tail(&sas_device->list, &ioc->sas_device_list);
623 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
624
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530625 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +0530626 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -0600627 _scsih_sas_device_remove(ioc, sas_device);
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +0530628 } else if (!sas_device->starget) {
629 /* When asyn scanning is enabled, its not possible to remove
630 * devices while scanning is turned on due to an oops in
631 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
632 */
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +0530633 if (!ioc->is_driver_loading) {
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +0530634 mpt2sas_transport_port_remove(ioc,
635 sas_device->sas_address,
636 sas_device->sas_address_parent);
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +0530637 _scsih_sas_device_remove(ioc, sas_device);
638 }
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +0530639 }
Eric Moore635374e2009-03-09 01:21:12 -0600640}
641
642/**
643 * _scsih_sas_device_init_add - insert sas_device to the list.
644 * @ioc: per adapter object
645 * @sas_device: the sas_device object
646 * Context: This function will acquire ioc->sas_device_lock.
647 *
648 * Adding new object at driver load time to the ioc->sas_device_init_list.
649 */
650static void
651_scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
652 struct _sas_device *sas_device)
653{
654 unsigned long flags;
655
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530656 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600657 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
658 sas_device->handle, (unsigned long long)sas_device->sas_address));
659
660 spin_lock_irqsave(&ioc->sas_device_lock, flags);
661 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
Eric Moore635374e2009-03-09 01:21:12 -0600662 _scsih_determine_boot_device(ioc, sas_device, 0);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530663 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -0600664}
665
666/**
Eric Moore635374e2009-03-09 01:21:12 -0600667 * _scsih_raid_device_find_by_id - raid device search
668 * @ioc: per adapter object
669 * @id: sas device target id
670 * @channel: sas device channel
671 * Context: Calling function should acquire ioc->raid_device_lock
672 *
673 * This searches for raid_device based on target id, then return raid_device
674 * object.
675 */
676static struct _raid_device *
677_scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
678{
679 struct _raid_device *raid_device, *r;
680
681 r = NULL;
682 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
683 if (raid_device->id == id && raid_device->channel == channel) {
684 r = raid_device;
685 goto out;
686 }
687 }
688
689 out:
690 return r;
691}
692
693/**
694 * _scsih_raid_device_find_by_handle - raid device search
695 * @ioc: per adapter object
696 * @handle: sas device handle (assigned by firmware)
697 * Context: Calling function should acquire ioc->raid_device_lock
698 *
699 * This searches for raid_device based on handle, then return raid_device
700 * object.
701 */
702static struct _raid_device *
703_scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
704{
705 struct _raid_device *raid_device, *r;
706
707 r = NULL;
708 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
709 if (raid_device->handle != handle)
710 continue;
711 r = raid_device;
712 goto out;
713 }
714
715 out:
716 return r;
717}
718
719/**
720 * _scsih_raid_device_find_by_wwid - raid device search
721 * @ioc: per adapter object
722 * @handle: sas device handle (assigned by firmware)
723 * Context: Calling function should acquire ioc->raid_device_lock
724 *
725 * This searches for raid_device based on wwid, then return raid_device
726 * object.
727 */
728static struct _raid_device *
729_scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
730{
731 struct _raid_device *raid_device, *r;
732
733 r = NULL;
734 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
735 if (raid_device->wwid != wwid)
736 continue;
737 r = raid_device;
738 goto out;
739 }
740
741 out:
742 return r;
743}
744
745/**
746 * _scsih_raid_device_add - add raid_device object
747 * @ioc: per adapter object
748 * @raid_device: raid_device object
749 *
750 * This is added to the raid_device_list link list.
751 */
752static void
753_scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
754 struct _raid_device *raid_device)
755{
756 unsigned long flags;
757
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530758 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600759 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
760 raid_device->handle, (unsigned long long)raid_device->wwid));
761
762 spin_lock_irqsave(&ioc->raid_device_lock, flags);
763 list_add_tail(&raid_device->list, &ioc->raid_device_list);
764 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
765}
766
767/**
768 * _scsih_raid_device_remove - delete raid_device object
769 * @ioc: per adapter object
770 * @raid_device: raid_device object
771 *
Eric Moore635374e2009-03-09 01:21:12 -0600772 */
773static void
774_scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
775 struct _raid_device *raid_device)
776{
777 unsigned long flags;
778
779 spin_lock_irqsave(&ioc->raid_device_lock, flags);
780 list_del(&raid_device->list);
Eric Moore635374e2009-03-09 01:21:12 -0600781 kfree(raid_device);
782 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
783}
784
785/**
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530786 * mpt2sas_scsih_expander_find_by_handle - expander device search
787 * @ioc: per adapter object
788 * @handle: expander handle (assigned by firmware)
789 * Context: Calling function should acquire ioc->sas_device_lock
790 *
791 * This searches for expander device based on handle, then returns the
792 * sas_node object.
793 */
794struct _sas_node *
795mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
796{
797 struct _sas_node *sas_expander, *r;
798
799 r = NULL;
800 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
801 if (sas_expander->handle != handle)
802 continue;
803 r = sas_expander;
804 goto out;
805 }
806 out:
807 return r;
808}
809
810/**
Eric Moore635374e2009-03-09 01:21:12 -0600811 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
812 * @ioc: per adapter object
813 * @sas_address: sas address
814 * Context: Calling function should acquire ioc->sas_node_lock.
815 *
816 * This searches for expander device based on sas_address, then returns the
817 * sas_node object.
818 */
819struct _sas_node *
820mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
821 u64 sas_address)
822{
823 struct _sas_node *sas_expander, *r;
824
825 r = NULL;
826 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
827 if (sas_expander->sas_address != sas_address)
828 continue;
829 r = sas_expander;
830 goto out;
831 }
832 out:
833 return r;
834}
835
836/**
837 * _scsih_expander_node_add - insert expander device to the list.
838 * @ioc: per adapter object
839 * @sas_expander: the sas_device object
840 * Context: This function will acquire ioc->sas_node_lock.
841 *
842 * Adding new object to the ioc->sas_expander_list.
843 *
844 * Return nothing.
845 */
846static void
847_scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
848 struct _sas_node *sas_expander)
849{
850 unsigned long flags;
851
852 spin_lock_irqsave(&ioc->sas_node_lock, flags);
853 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
854 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
855}
856
857/**
858 * _scsih_is_end_device - determines if device is an end device
859 * @device_info: bitfield providing information about the device.
860 * Context: none
861 *
862 * Returns 1 if end device.
863 */
864static int
865_scsih_is_end_device(u32 device_info)
866{
867 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
868 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
869 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
870 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
871 return 1;
872 else
873 return 0;
874}
875
876/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530877 * _scsih_scsi_lookup_get - returns scmd entry
Eric Moore635374e2009-03-09 01:21:12 -0600878 * @ioc: per adapter object
879 * @smid: system request message index
Eric Moore635374e2009-03-09 01:21:12 -0600880 *
881 * Returns the smid stored scmd pointer.
882 */
883static struct scsi_cmnd *
884_scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
885{
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530886 return ioc->scsi_lookup[smid - 1].scmd;
Eric Moore635374e2009-03-09 01:21:12 -0600887}
888
889/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530890 * _scsih_scsi_lookup_get_clear - returns scmd entry
891 * @ioc: per adapter object
892 * @smid: system request message index
893 *
894 * Returns the smid stored scmd pointer.
895 * Then will derefrence the stored scmd pointer.
896 */
897static inline struct scsi_cmnd *
898_scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
899{
900 unsigned long flags;
901 struct scsi_cmnd *scmd;
902
903 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
904 scmd = ioc->scsi_lookup[smid - 1].scmd;
905 ioc->scsi_lookup[smid - 1].scmd = NULL;
906 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
907
908 return scmd;
909}
910
911/**
Eric Moore635374e2009-03-09 01:21:12 -0600912 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
913 * @ioc: per adapter object
914 * @smid: system request message index
915 * @scmd: pointer to scsi command object
916 * Context: This function will acquire ioc->scsi_lookup_lock.
917 *
918 * This will search for a scmd pointer in the scsi_lookup array,
919 * returning the revelent smid. A returned value of zero means invalid.
920 */
921static u16
922_scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
923 *scmd)
924{
925 u16 smid;
926 unsigned long flags;
927 int i;
928
929 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
930 smid = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530931 for (i = 0; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600932 if (ioc->scsi_lookup[i].scmd == scmd) {
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530933 smid = ioc->scsi_lookup[i].smid;
Eric Moore635374e2009-03-09 01:21:12 -0600934 goto out;
935 }
936 }
937 out:
938 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
939 return smid;
940}
941
942/**
943 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
944 * @ioc: per adapter object
945 * @id: target id
946 * @channel: channel
947 * Context: This function will acquire ioc->scsi_lookup_lock.
948 *
949 * This will search for a matching channel:id in the scsi_lookup array,
950 * returning 1 if found.
951 */
952static u8
953_scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
954 int channel)
955{
956 u8 found;
957 unsigned long flags;
958 int i;
959
960 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
961 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530962 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600963 if (ioc->scsi_lookup[i].scmd &&
964 (ioc->scsi_lookup[i].scmd->device->id == id &&
965 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
966 found = 1;
967 goto out;
968 }
969 }
970 out:
971 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
972 return found;
973}
974
975/**
Eric Moore993e0da2009-05-18 13:00:45 -0600976 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
977 * @ioc: per adapter object
978 * @id: target id
979 * @lun: lun number
980 * @channel: channel
981 * Context: This function will acquire ioc->scsi_lookup_lock.
982 *
983 * This will search for a matching channel:id:lun in the scsi_lookup array,
984 * returning 1 if found.
985 */
986static u8
987_scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
988 unsigned int lun, int channel)
989{
990 u8 found;
991 unsigned long flags;
992 int i;
993
994 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
995 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530996 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore993e0da2009-05-18 13:00:45 -0600997 if (ioc->scsi_lookup[i].scmd &&
998 (ioc->scsi_lookup[i].scmd->device->id == id &&
999 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1000 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1001 found = 1;
1002 goto out;
1003 }
1004 }
1005 out:
1006 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1007 return found;
1008}
1009
1010/**
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301011 * _scsih_get_chain_buffer_tracker - obtain chain tracker
Eric Moore635374e2009-03-09 01:21:12 -06001012 * @ioc: per adapter object
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301013 * @smid: smid associated to an IO request
Eric Moore635374e2009-03-09 01:21:12 -06001014 *
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301015 * Returns chain tracker(from ioc->free_chain_list)
Eric Moore635374e2009-03-09 01:21:12 -06001016 */
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301017static struct chain_tracker *
1018_scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
Eric Moore635374e2009-03-09 01:21:12 -06001019{
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301020 struct chain_tracker *chain_req;
1021 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001022
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301023 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1024 if (list_empty(&ioc->free_chain_list)) {
1025 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
nagalakshmi.nandigama@lsi.comaff132d2011-12-01 07:53:08 +05301026 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not "
1027 "available\n", ioc->name));
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301028 return NULL;
1029 }
1030 chain_req = list_entry(ioc->free_chain_list.next,
1031 struct chain_tracker, tracker_list);
1032 list_del_init(&chain_req->tracker_list);
1033 list_add_tail(&chain_req->tracker_list,
1034 &ioc->scsi_lookup[smid - 1].chain_list);
1035 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1036 return chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001037}
1038
1039/**
1040 * _scsih_build_scatter_gather - main sg creation routine
1041 * @ioc: per adapter object
1042 * @scmd: scsi command
1043 * @smid: system request message index
1044 * Context: none.
1045 *
1046 * The main routine that builds scatter gather table from a given
1047 * scsi request sent via the .queuecommand main handler.
1048 *
1049 * Returns 0 success, anything else error
1050 */
1051static int
1052_scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1053 struct scsi_cmnd *scmd, u16 smid)
1054{
1055 Mpi2SCSIIORequest_t *mpi_request;
1056 dma_addr_t chain_dma;
1057 struct scatterlist *sg_scmd;
1058 void *sg_local, *chain;
1059 u32 chain_offset;
1060 u32 chain_length;
1061 u32 chain_flags;
FUJITA Tomonoribb789d02010-03-09 11:09:50 +09001062 int sges_left;
Eric Moore635374e2009-03-09 01:21:12 -06001063 u32 sges_in_segment;
1064 u32 sgl_flags;
1065 u32 sgl_flags_last_element;
1066 u32 sgl_flags_end_buffer;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301067 struct chain_tracker *chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001068
1069 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1070
1071 /* init scatter gather flags */
1072 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1073 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1074 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1075 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1076 << MPI2_SGE_FLAGS_SHIFT;
1077 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1078 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1079 << MPI2_SGE_FLAGS_SHIFT;
1080 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1081
1082 sg_scmd = scsi_sglist(scmd);
1083 sges_left = scsi_dma_map(scmd);
FUJITA Tomonoribb789d02010-03-09 11:09:50 +09001084 if (sges_left < 0) {
Eric Moore635374e2009-03-09 01:21:12 -06001085 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1086 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1087 return -ENOMEM;
1088 }
1089
1090 sg_local = &mpi_request->SGL;
1091 sges_in_segment = ioc->max_sges_in_main_message;
1092 if (sges_left <= sges_in_segment)
1093 goto fill_in_last_segment;
1094
1095 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1096 (sges_in_segment * ioc->sge_size))/4;
1097
1098 /* fill in main message segment when there is a chain following */
1099 while (sges_in_segment) {
1100 if (sges_in_segment == 1)
1101 ioc->base_add_sg_single(sg_local,
1102 sgl_flags_last_element | sg_dma_len(sg_scmd),
1103 sg_dma_address(sg_scmd));
1104 else
1105 ioc->base_add_sg_single(sg_local, sgl_flags |
1106 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1107 sg_scmd = sg_next(sg_scmd);
1108 sg_local += ioc->sge_size;
1109 sges_left--;
1110 sges_in_segment--;
1111 }
1112
1113 /* initializing the chain flags and pointers */
1114 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301115 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1116 if (!chain_req)
1117 return -1;
1118 chain = chain_req->chain_buffer;
1119 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001120 do {
1121 sges_in_segment = (sges_left <=
1122 ioc->max_sges_in_chain_message) ? sges_left :
1123 ioc->max_sges_in_chain_message;
1124 chain_offset = (sges_left == sges_in_segment) ?
1125 0 : (sges_in_segment * ioc->sge_size)/4;
1126 chain_length = sges_in_segment * ioc->sge_size;
1127 if (chain_offset) {
1128 chain_offset = chain_offset <<
1129 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1130 chain_length += ioc->sge_size;
1131 }
1132 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1133 chain_length, chain_dma);
1134 sg_local = chain;
1135 if (!chain_offset)
1136 goto fill_in_last_segment;
1137
1138 /* fill in chain segments */
1139 while (sges_in_segment) {
1140 if (sges_in_segment == 1)
1141 ioc->base_add_sg_single(sg_local,
1142 sgl_flags_last_element |
1143 sg_dma_len(sg_scmd),
1144 sg_dma_address(sg_scmd));
1145 else
1146 ioc->base_add_sg_single(sg_local, sgl_flags |
1147 sg_dma_len(sg_scmd),
1148 sg_dma_address(sg_scmd));
1149 sg_scmd = sg_next(sg_scmd);
1150 sg_local += ioc->sge_size;
1151 sges_left--;
1152 sges_in_segment--;
1153 }
1154
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301155 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1156 if (!chain_req)
1157 return -1;
1158 chain = chain_req->chain_buffer;
1159 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001160 } while (1);
1161
1162
1163 fill_in_last_segment:
1164
1165 /* fill the last segment */
1166 while (sges_left) {
1167 if (sges_left == 1)
1168 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1169 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1170 else
1171 ioc->base_add_sg_single(sg_local, sgl_flags |
1172 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1173 sg_scmd = sg_next(sg_scmd);
1174 sg_local += ioc->sge_size;
1175 sges_left--;
1176 }
1177
1178 return 0;
1179}
1180
1181/**
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301182 * _scsih_adjust_queue_depth - setting device queue depth
Eric Moore635374e2009-03-09 01:21:12 -06001183 * @sdev: scsi device struct
1184 * @qdepth: requested queue depth
1185 *
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301186 *
1187 * Returns nothing
Eric Moore635374e2009-03-09 01:21:12 -06001188 */
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301189static void
1190_scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
Eric Moore635374e2009-03-09 01:21:12 -06001191{
1192 struct Scsi_Host *shost = sdev->host;
1193 int max_depth;
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301194 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1195 struct MPT2SAS_DEVICE *sas_device_priv_data;
1196 struct MPT2SAS_TARGET *sas_target_priv_data;
1197 struct _sas_device *sas_device;
1198 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001199
1200 max_depth = shost->can_queue;
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301201
1202 /* limit max device queue for SATA to 32 */
1203 sas_device_priv_data = sdev->hostdata;
1204 if (!sas_device_priv_data)
1205 goto not_sata;
1206 sas_target_priv_data = sas_device_priv_data->sas_target;
1207 if (!sas_target_priv_data)
1208 goto not_sata;
1209 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1210 goto not_sata;
1211 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1212 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1213 sas_device_priv_data->sas_target->sas_address);
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301214 if (sas_device && sas_device->device_info &
1215 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1216 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301217 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301218
1219 not_sata:
1220
Eric Moore635374e2009-03-09 01:21:12 -06001221 if (!sdev->tagged_supported)
1222 max_depth = 1;
1223 if (qdepth > max_depth)
1224 qdepth = max_depth;
Christoph Hellwigc8b09f62014-11-03 20:15:14 +01001225 scsi_adjust_queue_depth(sdev, qdepth);
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301226}
1227
1228/**
1229 * _scsih_change_queue_depth - setting device queue depth
1230 * @sdev: scsi device struct
1231 * @qdepth: requested queue depth
1232 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1233 * (see include/scsi/scsi_host.h for definition)
1234 *
1235 * Returns queue depth.
1236 */
1237static int
1238_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1239{
1240 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1241 _scsih_adjust_queue_depth(sdev, qdepth);
1242 else if (reason == SCSI_QDEPTH_QFULL)
1243 scsi_track_queue_full(sdev, qdepth);
1244 else
1245 return -EOPNOTSUPP;
Eric Moore635374e2009-03-09 01:21:12 -06001246
1247 if (sdev->inquiry_len > 7)
1248 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
Christoph Hellwig609aa222014-10-30 11:54:58 +01001249 "simple(%d), scsi_level(%d), cmd_que(%d)\n",
Eric Moore635374e2009-03-09 01:21:12 -06001250 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
Christoph Hellwig609aa222014-10-30 11:54:58 +01001251 sdev->scsi_level,
Eric Moore635374e2009-03-09 01:21:12 -06001252 (sdev->inquiry[7] & 2) >> 1);
1253
1254 return sdev->queue_depth;
1255}
1256
1257/**
Eric Moored5d135b2009-05-18 13:02:08 -06001258 * _scsih_target_alloc - target add routine
Eric Moore635374e2009-03-09 01:21:12 -06001259 * @starget: scsi target struct
1260 *
1261 * Returns 0 if ok. Any other return is assumed to be an error and
1262 * the device is ignored.
1263 */
1264static int
Eric Moored5d135b2009-05-18 13:02:08 -06001265_scsih_target_alloc(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001266{
1267 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1268 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1269 struct MPT2SAS_TARGET *sas_target_priv_data;
1270 struct _sas_device *sas_device;
1271 struct _raid_device *raid_device;
1272 unsigned long flags;
1273 struct sas_rphy *rphy;
1274
Joe Lawrencefeafe7c2014-06-25 17:03:14 -04001275 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1276 GFP_KERNEL);
Eric Moore635374e2009-03-09 01:21:12 -06001277 if (!sas_target_priv_data)
1278 return -ENOMEM;
1279
1280 starget->hostdata = sas_target_priv_data;
1281 sas_target_priv_data->starget = starget;
1282 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1283
1284 /* RAID volumes */
1285 if (starget->channel == RAID_CHANNEL) {
1286 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1287 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1288 starget->channel);
1289 if (raid_device) {
1290 sas_target_priv_data->handle = raid_device->handle;
1291 sas_target_priv_data->sas_address = raid_device->wwid;
1292 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301293 if (ioc->is_warpdrive)
1294 sas_target_priv_data->raid_device = raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06001295 raid_device->starget = starget;
1296 }
1297 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1298 return 0;
1299 }
1300
1301 /* sas/sata devices */
1302 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1303 rphy = dev_to_rphy(starget->dev.parent);
1304 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1305 rphy->identify.sas_address);
1306
1307 if (sas_device) {
1308 sas_target_priv_data->handle = sas_device->handle;
1309 sas_target_priv_data->sas_address = sas_device->sas_address;
1310 sas_device->starget = starget;
1311 sas_device->id = starget->id;
1312 sas_device->channel = starget->channel;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05301313 if (test_bit(sas_device->handle, ioc->pd_handles))
Eric Moore635374e2009-03-09 01:21:12 -06001314 sas_target_priv_data->flags |=
1315 MPT_TARGET_FLAGS_RAID_COMPONENT;
1316 }
1317 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1318
1319 return 0;
1320}
1321
1322/**
Eric Moored5d135b2009-05-18 13:02:08 -06001323 * _scsih_target_destroy - target destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001324 * @starget: scsi target struct
1325 *
1326 * Returns nothing.
1327 */
1328static void
Eric Moored5d135b2009-05-18 13:02:08 -06001329_scsih_target_destroy(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001330{
1331 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1332 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1333 struct MPT2SAS_TARGET *sas_target_priv_data;
1334 struct _sas_device *sas_device;
1335 struct _raid_device *raid_device;
1336 unsigned long flags;
1337 struct sas_rphy *rphy;
1338
1339 sas_target_priv_data = starget->hostdata;
1340 if (!sas_target_priv_data)
1341 return;
1342
1343 if (starget->channel == RAID_CHANNEL) {
1344 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1345 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1346 starget->channel);
1347 if (raid_device) {
1348 raid_device->starget = NULL;
1349 raid_device->sdev = NULL;
1350 }
1351 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1352 goto out;
1353 }
1354
1355 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1356 rphy = dev_to_rphy(starget->dev.parent);
1357 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1358 rphy->identify.sas_address);
Eric Moore8901cbb2009-04-21 15:41:32 -06001359 if (sas_device && (sas_device->starget == starget) &&
1360 (sas_device->id == starget->id) &&
1361 (sas_device->channel == starget->channel))
Eric Moore635374e2009-03-09 01:21:12 -06001362 sas_device->starget = NULL;
1363
1364 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1365
1366 out:
1367 kfree(sas_target_priv_data);
1368 starget->hostdata = NULL;
1369}
1370
1371/**
Eric Moored5d135b2009-05-18 13:02:08 -06001372 * _scsih_slave_alloc - device add routine
Eric Moore635374e2009-03-09 01:21:12 -06001373 * @sdev: scsi device struct
1374 *
1375 * Returns 0 if ok. Any other return is assumed to be an error and
1376 * the device is ignored.
1377 */
1378static int
Eric Moored5d135b2009-05-18 13:02:08 -06001379_scsih_slave_alloc(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001380{
1381 struct Scsi_Host *shost;
1382 struct MPT2SAS_ADAPTER *ioc;
1383 struct MPT2SAS_TARGET *sas_target_priv_data;
1384 struct MPT2SAS_DEVICE *sas_device_priv_data;
1385 struct scsi_target *starget;
1386 struct _raid_device *raid_device;
Sreekanth Reddy63e359d2013-07-25 11:32:51 +05301387 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -06001388 unsigned long flags;
1389
Joe Lawrencefeafe7c2014-06-25 17:03:14 -04001390 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1391 GFP_KERNEL);
Eric Moore635374e2009-03-09 01:21:12 -06001392 if (!sas_device_priv_data)
1393 return -ENOMEM;
1394
1395 sas_device_priv_data->lun = sdev->lun;
1396 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1397
1398 starget = scsi_target(sdev);
1399 sas_target_priv_data = starget->hostdata;
1400 sas_target_priv_data->num_luns++;
1401 sas_device_priv_data->sas_target = sas_target_priv_data;
1402 sdev->hostdata = sas_device_priv_data;
1403 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1404 sdev->no_uld_attach = 1;
1405
1406 shost = dev_to_shost(&starget->dev);
1407 ioc = shost_priv(shost);
1408 if (starget->channel == RAID_CHANNEL) {
1409 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1410 raid_device = _scsih_raid_device_find_by_id(ioc,
1411 starget->id, starget->channel);
1412 if (raid_device)
1413 raid_device->sdev = sdev; /* raid is single lun */
1414 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06001415 }
1416
Sreekanth Reddy63e359d2013-07-25 11:32:51 +05301417 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1418 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1419 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1420 sas_target_priv_data->sas_address);
1421 if (sas_device && (sas_device->starget == NULL)) {
1422 sdev_printk(KERN_INFO, sdev,
1423 "%s : sas_device->starget set to starget @ %d\n",
1424 __func__, __LINE__);
1425 sas_device->starget = starget;
1426 }
1427 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1428 }
1429
Eric Moore635374e2009-03-09 01:21:12 -06001430 return 0;
1431}
1432
1433/**
Eric Moored5d135b2009-05-18 13:02:08 -06001434 * _scsih_slave_destroy - device destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001435 * @sdev: scsi device struct
1436 *
1437 * Returns nothing.
1438 */
1439static void
Eric Moored5d135b2009-05-18 13:02:08 -06001440_scsih_slave_destroy(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001441{
1442 struct MPT2SAS_TARGET *sas_target_priv_data;
1443 struct scsi_target *starget;
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301444 struct Scsi_Host *shost;
1445 struct MPT2SAS_ADAPTER *ioc;
1446 struct _sas_device *sas_device;
1447 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001448
1449 if (!sdev->hostdata)
1450 return;
1451
1452 starget = scsi_target(sdev);
1453 sas_target_priv_data = starget->hostdata;
1454 sas_target_priv_data->num_luns--;
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301455
1456 shost = dev_to_shost(&starget->dev);
1457 ioc = shost_priv(shost);
1458
1459 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1460 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1461 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1462 sas_target_priv_data->sas_address);
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +05301463 if (sas_device && !sas_target_priv_data->num_luns)
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301464 sas_device->starget = NULL;
1465 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1466 }
1467
Eric Moore635374e2009-03-09 01:21:12 -06001468 kfree(sdev->hostdata);
1469 sdev->hostdata = NULL;
1470}
1471
1472/**
Eric Moored5d135b2009-05-18 13:02:08 -06001473 * _scsih_display_sata_capabilities - sata capabilities
Eric Moore635374e2009-03-09 01:21:12 -06001474 * @ioc: per adapter object
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301475 * @handle: device handle
Eric Moore635374e2009-03-09 01:21:12 -06001476 * @sdev: scsi device struct
1477 */
1478static void
Eric Moored5d135b2009-05-18 13:02:08 -06001479_scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301480 u16 handle, struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001481{
1482 Mpi2ConfigReply_t mpi_reply;
1483 Mpi2SasDevicePage0_t sas_device_pg0;
1484 u32 ioc_status;
1485 u16 flags;
1486 u32 device_info;
1487
1488 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301489 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06001490 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1491 ioc->name, __FILE__, __LINE__, __func__);
1492 return;
1493 }
1494
1495 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1496 MPI2_IOCSTATUS_MASK;
1497 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1498 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1499 ioc->name, __FILE__, __LINE__, __func__);
1500 return;
1501 }
1502
1503 flags = le16_to_cpu(sas_device_pg0.Flags);
Kashyap, Desaie94f6742010-03-17 16:24:52 +05301504 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
Eric Moore635374e2009-03-09 01:21:12 -06001505
1506 sdev_printk(KERN_INFO, sdev,
1507 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1508 "sw_preserve(%s)\n",
1509 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1510 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1511 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1512 "n",
1513 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1514 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1515 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1516}
1517
1518/**
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301519 * _scsih_is_raid - return boolean indicating device is raid volume
1520 * @dev the device struct object
1521 */
1522static int
1523_scsih_is_raid(struct device *dev)
1524{
1525 struct scsi_device *sdev = to_scsi_device(dev);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301526 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301527
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301528 if (ioc->is_warpdrive)
1529 return 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301530 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1531}
1532
1533/**
1534 * _scsih_get_resync - get raid volume resync percent complete
1535 * @dev the device struct object
1536 */
1537static void
1538_scsih_get_resync(struct device *dev)
1539{
1540 struct scsi_device *sdev = to_scsi_device(dev);
1541 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1542 static struct _raid_device *raid_device;
1543 unsigned long flags;
1544 Mpi2RaidVolPage0_t vol_pg0;
1545 Mpi2ConfigReply_t mpi_reply;
1546 u32 volume_status_flags;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301547 u8 percent_complete;
1548 u16 handle;
1549
1550 percent_complete = 0;
1551 handle = 0;
1552 if (ioc->is_warpdrive)
1553 goto out;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301554
1555 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1556 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1557 sdev->channel);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301558 if (raid_device) {
1559 handle = raid_device->handle;
1560 percent_complete = raid_device->percent_complete;
1561 }
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301562 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1563
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301564 if (!handle)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301565 goto out;
1566
1567 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301568 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301569 sizeof(Mpi2RaidVolPage0_t))) {
1570 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1571 ioc->name, __FILE__, __LINE__, __func__);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301572 percent_complete = 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301573 goto out;
1574 }
1575
1576 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301577 if (!(volume_status_flags &
1578 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1579 percent_complete = 0;
1580
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301581 out:
1582 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1583}
1584
1585/**
1586 * _scsih_get_state - get raid volume level
1587 * @dev the device struct object
1588 */
1589static void
1590_scsih_get_state(struct device *dev)
1591{
1592 struct scsi_device *sdev = to_scsi_device(dev);
1593 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1594 static struct _raid_device *raid_device;
1595 unsigned long flags;
1596 Mpi2RaidVolPage0_t vol_pg0;
1597 Mpi2ConfigReply_t mpi_reply;
1598 u32 volstate;
1599 enum raid_state state = RAID_STATE_UNKNOWN;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301600 u16 handle = 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301601
1602 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1603 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1604 sdev->channel);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301605 if (raid_device)
1606 handle = raid_device->handle;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301607 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1608
1609 if (!raid_device)
1610 goto out;
1611
1612 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301613 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301614 sizeof(Mpi2RaidVolPage0_t))) {
1615 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1616 ioc->name, __FILE__, __LINE__, __func__);
1617 goto out;
1618 }
1619
1620 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1621 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1622 state = RAID_STATE_RESYNCING;
1623 goto out;
1624 }
1625
1626 switch (vol_pg0.VolumeState) {
1627 case MPI2_RAID_VOL_STATE_OPTIMAL:
1628 case MPI2_RAID_VOL_STATE_ONLINE:
1629 state = RAID_STATE_ACTIVE;
1630 break;
1631 case MPI2_RAID_VOL_STATE_DEGRADED:
1632 state = RAID_STATE_DEGRADED;
1633 break;
1634 case MPI2_RAID_VOL_STATE_FAILED:
1635 case MPI2_RAID_VOL_STATE_MISSING:
1636 state = RAID_STATE_OFFLINE;
1637 break;
1638 }
1639 out:
1640 raid_set_state(mpt2sas_raid_template, dev, state);
1641}
1642
1643/**
1644 * _scsih_set_level - set raid level
1645 * @sdev: scsi device struct
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301646 * @volume_type: volume type
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301647 */
1648static void
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301649_scsih_set_level(struct scsi_device *sdev, u8 volume_type)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301650{
1651 enum raid_level level = RAID_LEVEL_UNKNOWN;
1652
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301653 switch (volume_type) {
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301654 case MPI2_RAID_VOL_TYPE_RAID0:
1655 level = RAID_LEVEL_0;
1656 break;
1657 case MPI2_RAID_VOL_TYPE_RAID10:
1658 level = RAID_LEVEL_10;
1659 break;
1660 case MPI2_RAID_VOL_TYPE_RAID1E:
1661 level = RAID_LEVEL_1E;
1662 break;
1663 case MPI2_RAID_VOL_TYPE_RAID1:
1664 level = RAID_LEVEL_1;
1665 break;
1666 }
1667
1668 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1669}
1670
1671/**
Eric Moore635374e2009-03-09 01:21:12 -06001672 * _scsih_get_volume_capabilities - volume capabilities
1673 * @ioc: per adapter object
1674 * @sas_device: the raid_device object
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301675 *
1676 * Returns 0 for success, else 1
Eric Moore635374e2009-03-09 01:21:12 -06001677 */
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301678static int
Eric Moore635374e2009-03-09 01:21:12 -06001679_scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1680 struct _raid_device *raid_device)
1681{
1682 Mpi2RaidVolPage0_t *vol_pg0;
1683 Mpi2RaidPhysDiskPage0_t pd_pg0;
1684 Mpi2SasDevicePage0_t sas_device_pg0;
1685 Mpi2ConfigReply_t mpi_reply;
1686 u16 sz;
1687 u8 num_pds;
1688
1689 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1690 &num_pds)) || !num_pds) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301691 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1692 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1693 __func__));
1694 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001695 }
1696
1697 raid_device->num_pds = num_pds;
1698 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1699 sizeof(Mpi2RaidVol0PhysDisk_t));
1700 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1701 if (!vol_pg0) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301702 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1703 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1704 __func__));
1705 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001706 }
1707
1708 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1709 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301710 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1711 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1712 __func__));
Eric Moore635374e2009-03-09 01:21:12 -06001713 kfree(vol_pg0);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301714 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001715 }
1716
1717 raid_device->volume_type = vol_pg0->VolumeType;
1718
1719 /* figure out what the underlying devices are by
1720 * obtaining the device_info bits for the 1st device
1721 */
1722 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1723 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1724 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1725 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1726 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1727 le16_to_cpu(pd_pg0.DevHandle)))) {
1728 raid_device->device_info =
1729 le32_to_cpu(sas_device_pg0.DeviceInfo);
1730 }
1731 }
1732
1733 kfree(vol_pg0);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301734 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06001735}
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301736/**
1737 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1738 * @ioc: per adapter object
1739 */
1740static void
1741_scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1742{
1743 Mpi2RaidVolPage1_t vol_pg1;
1744 Mpi2ConfigReply_t mpi_reply;
1745 struct _raid_device *raid_device;
1746 u16 handle;
1747 u16 ioc_status;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301748 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301749
1750 handle = 0xFFFF;
1751 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1752 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1753 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1754 MPI2_IOCSTATUS_MASK;
1755 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1756 break;
1757 handle = le16_to_cpu(vol_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301758 spin_lock_irqsave(&ioc->raid_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301759 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1760 if (raid_device)
1761 raid_device->direct_io_enabled = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301762 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301763 }
1764 return;
1765}
1766
1767
1768/**
1769 * _scsih_get_num_volumes - Get number of volumes in the ioc
1770 * @ioc: per adapter object
1771 */
1772static u8
1773_scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1774{
1775 Mpi2RaidVolPage1_t vol_pg1;
1776 Mpi2ConfigReply_t mpi_reply;
1777 u16 handle;
1778 u8 vol_cnt = 0;
1779 u16 ioc_status;
1780
1781 handle = 0xFFFF;
1782 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1783 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1784 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1785 MPI2_IOCSTATUS_MASK;
1786 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1787 break;
1788 vol_cnt++;
1789 handle = le16_to_cpu(vol_pg1.DevHandle);
1790 }
1791 return vol_cnt;
1792}
1793
1794
1795/**
1796 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1797 * @ioc: per adapter object
1798 * @raid_device: the raid_device object
1799 */
1800static void
1801_scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1802 struct _raid_device *raid_device)
1803{
1804 Mpi2RaidVolPage0_t *vol_pg0;
1805 Mpi2RaidPhysDiskPage0_t pd_pg0;
1806 Mpi2ConfigReply_t mpi_reply;
1807 u16 sz;
1808 u8 num_pds, count;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301809 unsigned long stripe_sz, block_sz;
1810 u8 stripe_exp, block_exp;
1811 u64 dev_max_lba;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301812
1813 if (!ioc->is_warpdrive)
1814 return;
1815
1816 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1817 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1818 "globally as drives are exposed\n", ioc->name);
1819 return;
1820 }
1821 if (_scsih_get_num_volumes(ioc) > 1) {
1822 _scsih_disable_ddio(ioc);
1823 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1824 "globally as number of drives > 1\n", ioc->name);
1825 return;
1826 }
1827 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1828 &num_pds)) || !num_pds) {
1829 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1830 "Failure in computing number of drives\n", ioc->name);
1831 return;
1832 }
1833
1834 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1835 sizeof(Mpi2RaidVol0PhysDisk_t));
1836 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1837 if (!vol_pg0) {
1838 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1839 "Memory allocation failure for RVPG0\n", ioc->name);
1840 return;
1841 }
1842
1843 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1844 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1845 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1846 "Failure in retrieving RVPG0\n", ioc->name);
1847 kfree(vol_pg0);
1848 return;
1849 }
1850
1851 /*
1852 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1853 * assumed for WARPDRIVE, disable direct I/O
1854 */
1855 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1856 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1857 "for the drive with handle(0x%04x): num_mem=%d, "
1858 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1859 num_pds, MPT_MAX_WARPDRIVE_PDS);
1860 kfree(vol_pg0);
1861 return;
1862 }
1863 for (count = 0; count < num_pds; count++) {
1864 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1865 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1866 vol_pg0->PhysDisk[count].PhysDiskNum) ||
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05301867 le16_to_cpu(pd_pg0.DevHandle) ==
1868 MPT2SAS_INVALID_DEVICE_HANDLE) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301869 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1870 "disabled for the drive with handle(0x%04x) member"
1871 "handle retrieval failed for member number=%d\n",
1872 ioc->name, raid_device->handle,
1873 vol_pg0->PhysDisk[count].PhysDiskNum);
1874 goto out_error;
1875 }
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301876 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1877 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
1878 if (dev_max_lba >> 32) {
1879 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1880 "disabled for the drive with handle(0x%04x) member"
1881 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1882 ioc->name, raid_device->handle,
1883 le16_to_cpu(pd_pg0.DevHandle),
1884 (unsigned long long)dev_max_lba);
1885 goto out_error;
1886 }
1887
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301888 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1889 }
1890
1891 /*
1892 * Assumption for WD: Direct I/O is not supported if the volume is
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301893 * not RAID0
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301894 */
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301895 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301896 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1897 "for the drive with handle(0x%04x): type=%d, "
1898 "s_sz=%uK, blk_size=%u\n", ioc->name,
1899 raid_device->handle, raid_device->volume_type,
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301900 (le32_to_cpu(vol_pg0->StripeSize) *
1901 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301902 le16_to_cpu(vol_pg0->BlockSize));
1903 goto out_error;
1904 }
1905
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301906 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301907 stripe_exp = find_first_bit(&stripe_sz, 32);
1908 if (stripe_exp == 32) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301909 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301910 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301911 ioc->name, raid_device->handle,
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301912 (le32_to_cpu(vol_pg0->StripeSize) *
1913 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301914 goto out_error;
1915 }
1916 raid_device->stripe_exponent = stripe_exp;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301917 block_sz = le16_to_cpu(vol_pg0->BlockSize);
1918 block_exp = find_first_bit(&block_sz, 16);
1919 if (block_exp == 16) {
1920 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1921 "for the drive with handle(0x%04x) invalid block sz %u\n",
1922 ioc->name, raid_device->handle,
1923 le16_to_cpu(vol_pg0->BlockSize));
1924 goto out_error;
1925 }
1926 raid_device->block_exponent = block_exp;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301927 raid_device->direct_io_enabled = 1;
1928
1929 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1930 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1931 /*
1932 * WARPDRIVE: Though the following fields are not used for direct IO,
1933 * stored for future purpose:
1934 */
1935 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1936 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1937 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1938
1939
1940 kfree(vol_pg0);
1941 return;
1942
1943out_error:
1944 raid_device->direct_io_enabled = 0;
1945 for (count = 0; count < num_pds; count++)
1946 raid_device->pd_handle[count] = 0;
1947 kfree(vol_pg0);
1948 return;
1949}
Eric Moore635374e2009-03-09 01:21:12 -06001950
1951/**
Kashyap, Desai84f0b042009-12-16 18:56:28 +05301952 * _scsih_enable_tlr - setting TLR flags
1953 * @ioc: per adapter object
1954 * @sdev: scsi device struct
1955 *
1956 * Enabling Transaction Layer Retries for tape devices when
1957 * vpd page 0x90 is present
1958 *
1959 */
1960static void
1961_scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1962{
1963 /* only for TAPE */
1964 if (sdev->type != TYPE_TAPE)
1965 return;
1966
1967 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1968 return;
1969
1970 sas_enable_tlr(sdev);
1971 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1972 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1973 return;
1974
1975}
1976
1977/**
Eric Moored5d135b2009-05-18 13:02:08 -06001978 * _scsih_slave_configure - device configure routine.
Eric Moore635374e2009-03-09 01:21:12 -06001979 * @sdev: scsi device struct
1980 *
1981 * Returns 0 if ok. Any other return is assumed to be an error and
1982 * the device is ignored.
1983 */
1984static int
Eric Moored5d135b2009-05-18 13:02:08 -06001985_scsih_slave_configure(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001986{
1987 struct Scsi_Host *shost = sdev->host;
1988 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1989 struct MPT2SAS_DEVICE *sas_device_priv_data;
1990 struct MPT2SAS_TARGET *sas_target_priv_data;
1991 struct _sas_device *sas_device;
1992 struct _raid_device *raid_device;
1993 unsigned long flags;
1994 int qdepth;
1995 u8 ssp_target = 0;
1996 char *ds = "";
1997 char *r_level = "";
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301998 u16 handle, volume_handle = 0;
1999 u64 volume_wwid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06002000
2001 qdepth = 1;
2002 sas_device_priv_data = sdev->hostdata;
2003 sas_device_priv_data->configured_lun = 1;
2004 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
2005 sas_target_priv_data = sas_device_priv_data->sas_target;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302006 handle = sas_target_priv_data->handle;
Eric Moore635374e2009-03-09 01:21:12 -06002007
2008 /* raid volume handling */
2009 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2010
2011 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302012 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06002013 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2014 if (!raid_device) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302015 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2016 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2017 __LINE__, __func__));
2018 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002019 }
2020
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302021 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2022 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2023 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2024 __LINE__, __func__));
2025 return 1;
2026 }
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302027 /*
2028 * WARPDRIVE: Initialize the required data for Direct IO
2029 */
2030 _scsih_init_warpdrive_properties(ioc, raid_device);
2031
Eric Moore635374e2009-03-09 01:21:12 -06002032 /* RAID Queue Depth Support
2033 * IS volume = underlying qdepth of drive type, either
2034 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2035 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2036 */
2037 if (raid_device->device_info &
2038 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2039 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2040 ds = "SSP";
2041 } else {
2042 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2043 if (raid_device->device_info &
2044 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2045 ds = "SATA";
2046 else
2047 ds = "STP";
2048 }
2049
2050 switch (raid_device->volume_type) {
2051 case MPI2_RAID_VOL_TYPE_RAID0:
2052 r_level = "RAID0";
2053 break;
2054 case MPI2_RAID_VOL_TYPE_RAID1E:
2055 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
Kashyap, Desaied79f122009-08-20 13:23:49 +05302056 if (ioc->manu_pg10.OEMIdentifier &&
Kashyap, Desaic97951e2011-06-14 10:54:56 +05302057 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
Kashyap, Desaied79f122009-08-20 13:23:49 +05302058 MFG10_GF0_R10_DISPLAY) &&
2059 !(raid_device->num_pds % 2))
2060 r_level = "RAID10";
2061 else
2062 r_level = "RAID1E";
Eric Moore635374e2009-03-09 01:21:12 -06002063 break;
2064 case MPI2_RAID_VOL_TYPE_RAID1:
2065 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2066 r_level = "RAID1";
2067 break;
2068 case MPI2_RAID_VOL_TYPE_RAID10:
2069 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2070 r_level = "RAID10";
2071 break;
2072 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2073 default:
2074 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2075 r_level = "RAIDX";
2076 break;
2077 }
2078
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302079 if (!ioc->hide_ir_msg)
2080 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2081 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2082 r_level, raid_device->handle,
2083 (unsigned long long)raid_device->wwid,
2084 raid_device->num_pds, ds);
Mike Christiee881a172009-10-15 17:46:39 -07002085 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05302086 /* raid transport support */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302087 if (!ioc->is_warpdrive)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302088 _scsih_set_level(sdev, raid_device->volume_type);
Eric Moore635374e2009-03-09 01:21:12 -06002089 return 0;
2090 }
2091
2092 /* non-raid handling */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302093 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2094 if (mpt2sas_config_get_volume_handle(ioc, handle,
2095 &volume_handle)) {
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 if (volume_handle && mpt2sas_config_get_volume_wwid(ioc,
2102 volume_handle, &volume_wwid)) {
2103 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2104 "failure at %s:%d/%s()!\n", ioc->name,
2105 __FILE__, __LINE__, __func__));
2106 return 1;
2107 }
2108 }
2109
Eric Moore635374e2009-03-09 01:21:12 -06002110 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2111 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2112 sas_device_priv_data->sas_target->sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302113 if (!sas_device) {
2114 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302115 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302116 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2117 __LINE__, __func__));
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302118 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002119 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302120 sas_device->volume_handle = volume_handle;
2121 sas_device->volume_wwid = volume_wwid;
2122 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2123 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2124 ssp_target = 1;
2125 ds = "SSP";
2126 } else {
2127 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2128 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2129 ds = "STP";
2130 else if (sas_device->device_info &
2131 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2132 ds = "SATA";
2133 }
2134 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2135 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2136 ds, sas_device->handle,
2137 (unsigned long long)sas_device->sas_address,
2138 sas_device->phy,
2139 (unsigned long long)sas_device->device_name);
2140 sdev_printk(KERN_INFO, sdev, "%s: "
2141 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2142 (unsigned long long) sas_device->enclosure_logical_id,
2143 sas_device->slot);
2144
2145 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2146 if (!ssp_target)
2147 _scsih_display_sata_capabilities(ioc, handle, sdev);
2148
Eric Moore635374e2009-03-09 01:21:12 -06002149
Mike Christiee881a172009-10-15 17:46:39 -07002150 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
Eric Moore635374e2009-03-09 01:21:12 -06002151
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302152 if (ssp_target) {
Eric Moore635374e2009-03-09 01:21:12 -06002153 sas_read_port_mode_page(sdev);
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302154 _scsih_enable_tlr(ioc, sdev);
2155 }
Eric Moore635374e2009-03-09 01:21:12 -06002156 return 0;
2157}
2158
2159/**
Eric Moored5d135b2009-05-18 13:02:08 -06002160 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
Eric Moore635374e2009-03-09 01:21:12 -06002161 * @sdev: scsi device struct
2162 * @bdev: pointer to block device context
2163 * @capacity: device size (in 512 byte sectors)
2164 * @params: three element array to place output:
2165 * params[0] number of heads (max 255)
2166 * params[1] number of sectors (max 63)
2167 * params[2] number of cylinders
2168 *
2169 * Return nothing.
2170 */
2171static int
Eric Moored5d135b2009-05-18 13:02:08 -06002172_scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
Eric Moore635374e2009-03-09 01:21:12 -06002173 sector_t capacity, int params[])
2174{
2175 int heads;
2176 int sectors;
2177 sector_t cylinders;
2178 ulong dummy;
2179
2180 heads = 64;
2181 sectors = 32;
2182
2183 dummy = heads * sectors;
2184 cylinders = capacity;
2185 sector_div(cylinders, dummy);
2186
2187 /*
2188 * Handle extended translation size for logical drives
2189 * > 1Gb
2190 */
2191 if ((ulong)capacity >= 0x200000) {
2192 heads = 255;
2193 sectors = 63;
2194 dummy = heads * sectors;
2195 cylinders = capacity;
2196 sector_div(cylinders, dummy);
2197 }
2198
2199 /* return result */
2200 params[0] = heads;
2201 params[1] = sectors;
2202 params[2] = cylinders;
2203
2204 return 0;
2205}
2206
2207/**
2208 * _scsih_response_code - translation of device response code
2209 * @ioc: per adapter object
2210 * @response_code: response code returned by the device
2211 *
2212 * Return nothing.
2213 */
2214static void
2215_scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2216{
2217 char *desc;
2218
2219 switch (response_code) {
2220 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2221 desc = "task management request completed";
2222 break;
2223 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2224 desc = "invalid frame";
2225 break;
2226 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2227 desc = "task management request not supported";
2228 break;
2229 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2230 desc = "task management request failed";
2231 break;
2232 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2233 desc = "task management request succeeded";
2234 break;
2235 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2236 desc = "invalid lun";
2237 break;
2238 case 0xA:
2239 desc = "overlapped tag attempted";
2240 break;
2241 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2242 desc = "task queued, however not sent to target";
2243 break;
2244 default:
2245 desc = "unknown";
2246 break;
2247 }
2248 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2249 ioc->name, response_code, desc);
2250}
2251
2252/**
Eric Moored5d135b2009-05-18 13:02:08 -06002253 * _scsih_tm_done - tm completion routine
Eric Moore635374e2009-03-09 01:21:12 -06002254 * @ioc: per adapter object
2255 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302256 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002257 * @reply: reply message frame(lower 32bit addr)
2258 * Context: none.
2259 *
2260 * The callback handler when using scsih_issue_tm.
2261 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302262 * Return 1 meaning mf should be freed from _base_interrupt
2263 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06002264 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302265static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302266_scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06002267{
2268 MPI2DefaultReply_t *mpi_reply;
2269
2270 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302271 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002272 if (ioc->tm_cmds.smid != smid)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302273 return 1;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05302274 mpt2sas_base_flush_reply_queues(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06002275 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2276 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2277 if (mpi_reply) {
2278 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2279 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2280 }
2281 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2282 complete(&ioc->tm_cmds.done);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302283 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002284}
2285
2286/**
2287 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2288 * @ioc: per adapter object
2289 * @handle: device handle
2290 *
2291 * During taskmangement request, we need to freeze the device queue.
2292 */
2293void
2294mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2295{
2296 struct MPT2SAS_DEVICE *sas_device_priv_data;
2297 struct scsi_device *sdev;
2298 u8 skip = 0;
2299
2300 shost_for_each_device(sdev, ioc->shost) {
2301 if (skip)
2302 continue;
2303 sas_device_priv_data = sdev->hostdata;
2304 if (!sas_device_priv_data)
2305 continue;
2306 if (sas_device_priv_data->sas_target->handle == handle) {
2307 sas_device_priv_data->sas_target->tm_busy = 1;
2308 skip = 1;
2309 ioc->ignore_loginfos = 1;
2310 }
2311 }
2312}
2313
2314/**
2315 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2316 * @ioc: per adapter object
2317 * @handle: device handle
2318 *
2319 * During taskmangement request, we need to freeze the device queue.
2320 */
2321void
2322mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2323{
2324 struct MPT2SAS_DEVICE *sas_device_priv_data;
2325 struct scsi_device *sdev;
2326 u8 skip = 0;
2327
2328 shost_for_each_device(sdev, ioc->shost) {
2329 if (skip)
2330 continue;
2331 sas_device_priv_data = sdev->hostdata;
2332 if (!sas_device_priv_data)
2333 continue;
2334 if (sas_device_priv_data->sas_target->handle == handle) {
2335 sas_device_priv_data->sas_target->tm_busy = 0;
2336 skip = 1;
2337 ioc->ignore_loginfos = 0;
2338 }
2339 }
2340}
2341
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302342
Eric Moore635374e2009-03-09 01:21:12 -06002343/**
2344 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2345 * @ioc: per adapter struct
2346 * @device_handle: device handle
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302347 * @channel: the channel assigned by the OS
2348 * @id: the id assigned by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002349 * @lun: lun number
2350 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2351 * @smid_task: smid assigned to the task
2352 * @timeout: timeout in seconds
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302353 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302354 * Context: user
Eric Moore635374e2009-03-09 01:21:12 -06002355 *
2356 * A generic API for sending task management requests to firmware.
2357 *
Eric Moore635374e2009-03-09 01:21:12 -06002358 * The callback index is set inside `ioc->tm_cb_idx`.
2359 *
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302360 * Return SUCCESS or FAILED.
Eric Moore635374e2009-03-09 01:21:12 -06002361 */
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302362int
2363mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2364 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002365 enum mutex_type m_type)
Eric Moore635374e2009-03-09 01:21:12 -06002366{
2367 Mpi2SCSITaskManagementRequest_t *mpi_request;
2368 Mpi2SCSITaskManagementReply_t *mpi_reply;
2369 u16 smid = 0;
2370 u32 ioc_state;
2371 unsigned long timeleft;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302372 struct scsiio_tracker *scsi_lookup = NULL;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302373 int rc;
Eric Moore635374e2009-03-09 01:21:12 -06002374
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302375 if (m_type == TM_MUTEX_ON)
2376 mutex_lock(&ioc->tm_cmds.mutex);
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302377 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2378 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2379 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302380 rc = FAILED;
2381 goto err_out;
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302382 }
2383
Eric Moore3cb54692010-07-08 14:44:34 -06002384 if (ioc->shost_recovery || ioc->remove_host ||
2385 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06002386 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2387 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302388 rc = FAILED;
2389 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002390 }
Eric Moore635374e2009-03-09 01:21:12 -06002391
2392 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2393 if (ioc_state & MPI2_DOORBELL_USED) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302394 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
Eric Moore635374e2009-03-09 01:21:12 -06002395 "active!\n", ioc->name));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302396 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302397 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302398 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302399 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002400 }
2401
2402 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2403 mpt2sas_base_fault_info(ioc, ioc_state &
2404 MPI2_DOORBELL_DATA_MASK);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302405 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302406 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302407 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302408 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002409 }
2410
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302411 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06002412 if (!smid) {
2413 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2414 ioc->name, __func__);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302415 rc = FAILED;
2416 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002417 }
2418
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302419 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2420 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2421
Eric Moore635374e2009-03-09 01:21:12 -06002422 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302423 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2424 smid_task));
Eric Moore635374e2009-03-09 01:21:12 -06002425 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2426 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2427 ioc->tm_cmds.smid = smid;
2428 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302429 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
Eric Moore635374e2009-03-09 01:21:12 -06002430 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2431 mpi_request->DevHandle = cpu_to_le16(handle);
2432 mpi_request->TaskType = type;
2433 mpi_request->TaskMID = cpu_to_le16(smid_task);
2434 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2435 mpt2sas_scsih_set_tm_flag(ioc, handle);
Kashyap, Desai5b768582009-08-20 13:24:31 +05302436 init_completion(&ioc->tm_cmds.done);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302437 mpt2sas_base_put_smid_hi_priority(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06002438 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
Eric Moore635374e2009-03-09 01:21:12 -06002439 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2440 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2441 ioc->name, __func__);
2442 _debug_dump_mf(mpi_request,
2443 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302444 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302445 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302446 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302447 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302448 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2449 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2450 goto err_out;
2451 }
Eric Moore635374e2009-03-09 01:21:12 -06002452 }
2453
2454 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2455 mpi_reply = ioc->tm_cmds.reply;
2456 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2457 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2458 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2459 le32_to_cpu(mpi_reply->IOCLogInfo),
2460 le32_to_cpu(mpi_reply->TerminationCount)));
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302461 if (ioc->logging_level & MPT_DEBUG_TM) {
Eric Moore635374e2009-03-09 01:21:12 -06002462 _scsih_response_code(ioc, mpi_reply->ResponseCode);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302463 if (mpi_reply->IOCStatus)
2464 _debug_dump_mf(mpi_request,
2465 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2466 }
Eric Moore635374e2009-03-09 01:21:12 -06002467 }
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302468
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302469 switch (type) {
2470 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302471 rc = SUCCESS;
2472 if (scsi_lookup->scmd == NULL)
2473 break;
2474 rc = FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302475 break;
2476
2477 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2478 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2479 rc = FAILED;
2480 else
2481 rc = SUCCESS;
2482 break;
2483
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302484 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302485 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2486 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2487 rc = FAILED;
2488 else
2489 rc = SUCCESS;
2490 break;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302491 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2492 rc = SUCCESS;
2493 break;
2494 default:
2495 rc = FAILED;
2496 break;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302497 }
2498
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302499 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2500 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302501 if (m_type == TM_MUTEX_ON)
2502 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302503
2504 return rc;
2505
2506 err_out:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302507 if (m_type == TM_MUTEX_ON)
2508 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302509 return rc;
Eric Moore635374e2009-03-09 01:21:12 -06002510}
2511
2512/**
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302513 * _scsih_tm_display_info - displays info about the device
2514 * @ioc: per adapter struct
2515 * @scmd: pointer to scsi command object
2516 *
2517 * Called by task management callback handlers.
2518 */
2519static void
2520_scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2521{
2522 struct scsi_target *starget = scmd->device->sdev_target;
2523 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2524 struct _sas_device *sas_device = NULL;
2525 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302526 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302527
2528 if (!priv_target)
2529 return;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302530 if (ioc->hide_ir_msg)
2531 device_str = "WarpDrive";
2532 else
2533 device_str = "volume";
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302534
2535 scsi_print_command(scmd);
2536 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302537 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2538 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2539 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302540 } else {
2541 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2542 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2543 priv_target->sas_address);
2544 if (sas_device) {
2545 if (priv_target->flags &
2546 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2547 starget_printk(KERN_INFO, starget,
2548 "volume handle(0x%04x), "
2549 "volume wwid(0x%016llx)\n",
2550 sas_device->volume_handle,
2551 (unsigned long long)sas_device->volume_wwid);
2552 }
2553 starget_printk(KERN_INFO, starget,
2554 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2555 sas_device->handle,
2556 (unsigned long long)sas_device->sas_address,
2557 sas_device->phy);
2558 starget_printk(KERN_INFO, starget,
2559 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2560 (unsigned long long)sas_device->enclosure_logical_id,
2561 sas_device->slot);
2562 }
2563 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2564 }
2565}
2566
2567/**
Eric Moored5d135b2009-05-18 13:02:08 -06002568 * _scsih_abort - eh threads main abort routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302569 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002570 *
2571 * Returns SUCCESS if command aborted else FAILED
2572 */
2573static int
Eric Moored5d135b2009-05-18 13:02:08 -06002574_scsih_abort(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002575{
2576 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2577 struct MPT2SAS_DEVICE *sas_device_priv_data;
2578 u16 smid;
2579 u16 handle;
2580 int r;
Eric Moore635374e2009-03-09 01:21:12 -06002581
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302582 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2583 "scmd(%p)\n", scmd);
2584 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002585
2586 sas_device_priv_data = scmd->device->hostdata;
2587 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302588 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2589 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002590 scmd->result = DID_NO_CONNECT << 16;
2591 scmd->scsi_done(scmd);
2592 r = SUCCESS;
2593 goto out;
2594 }
2595
2596 /* search for the command */
2597 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2598 if (!smid) {
2599 scmd->result = DID_RESET << 16;
2600 r = SUCCESS;
2601 goto out;
2602 }
2603
2604 /* for hidden raid components and volumes this is not supported */
2605 if (sas_device_priv_data->sas_target->flags &
2606 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2607 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2608 scmd->result = DID_RESET << 16;
2609 r = FAILED;
2610 goto out;
2611 }
2612
Kashyap, Desaifa7f3162009-09-23 17:26:58 +05302613 mpt2sas_halt_firmware(ioc);
2614
Eric Moore635374e2009-03-09 01:21:12 -06002615 handle = sas_device_priv_data->sas_target->handle;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302616 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2617 scmd->device->id, scmd->device->lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002618 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002619
2620 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302621 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2622 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002623 return r;
2624}
2625
Eric Moore635374e2009-03-09 01:21:12 -06002626/**
Eric Moored5d135b2009-05-18 13:02:08 -06002627 * _scsih_dev_reset - eh threads main device reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302628 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002629 *
2630 * Returns SUCCESS if command aborted else FAILED
2631 */
2632static int
Eric Moored5d135b2009-05-18 13:02:08 -06002633_scsih_dev_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002634{
2635 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2636 struct MPT2SAS_DEVICE *sas_device_priv_data;
2637 struct _sas_device *sas_device;
2638 unsigned long flags;
2639 u16 handle;
2640 int r;
2641
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302642 struct scsi_target *starget = scmd->device->sdev_target;
2643
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302644 starget_printk(KERN_INFO, starget, "attempting device reset! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302645 "scmd(%p)\n", scmd);
2646 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002647
2648 sas_device_priv_data = scmd->device->hostdata;
2649 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302650 starget_printk(KERN_INFO, starget, "device been deleted! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302651 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002652 scmd->result = DID_NO_CONNECT << 16;
2653 scmd->scsi_done(scmd);
2654 r = SUCCESS;
2655 goto out;
2656 }
2657
2658 /* for hidden raid components obtain the volume_handle */
2659 handle = 0;
2660 if (sas_device_priv_data->sas_target->flags &
2661 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2662 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2663 sas_device = _scsih_sas_device_find_by_handle(ioc,
2664 sas_device_priv_data->sas_target->handle);
2665 if (sas_device)
2666 handle = sas_device->volume_handle;
2667 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2668 } else
2669 handle = sas_device_priv_data->sas_target->handle;
2670
2671 if (!handle) {
2672 scmd->result = DID_RESET << 16;
2673 r = FAILED;
2674 goto out;
2675 }
2676
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302677 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2678 scmd->device->id, scmd->device->lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002679 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
Eric Moore993e0da2009-05-18 13:00:45 -06002680
2681 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302682 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2683 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002684 return r;
2685}
2686
2687/**
Eric Moored5d135b2009-05-18 13:02:08 -06002688 * _scsih_target_reset - eh threads main target reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302689 * @scmd: pointer to scsi command object
Eric Moore993e0da2009-05-18 13:00:45 -06002690 *
2691 * Returns SUCCESS if command aborted else FAILED
2692 */
2693static int
Eric Moored5d135b2009-05-18 13:02:08 -06002694_scsih_target_reset(struct scsi_cmnd *scmd)
Eric Moore993e0da2009-05-18 13:00:45 -06002695{
2696 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2697 struct MPT2SAS_DEVICE *sas_device_priv_data;
2698 struct _sas_device *sas_device;
2699 unsigned long flags;
2700 u16 handle;
2701 int r;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302702 struct scsi_target *starget = scmd->device->sdev_target;
Eric Moore993e0da2009-05-18 13:00:45 -06002703
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302704 starget_printk(KERN_INFO, starget, "attempting target reset! "
2705 "scmd(%p)\n", scmd);
2706 _scsih_tm_display_info(ioc, scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002707
2708 sas_device_priv_data = scmd->device->hostdata;
2709 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302710 starget_printk(KERN_INFO, starget, "target been deleted! "
2711 "scmd(%p)\n", scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002712 scmd->result = DID_NO_CONNECT << 16;
2713 scmd->scsi_done(scmd);
2714 r = SUCCESS;
2715 goto out;
2716 }
2717
2718 /* for hidden raid components obtain the volume_handle */
2719 handle = 0;
2720 if (sas_device_priv_data->sas_target->flags &
2721 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2722 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2723 sas_device = _scsih_sas_device_find_by_handle(ioc,
2724 sas_device_priv_data->sas_target->handle);
2725 if (sas_device)
2726 handle = sas_device->volume_handle;
2727 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2728 } else
2729 handle = sas_device_priv_data->sas_target->handle;
2730
2731 if (!handle) {
2732 scmd->result = DID_RESET << 16;
2733 r = FAILED;
2734 goto out;
2735 }
2736
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302737 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2738 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002739 30, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002740
2741 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302742 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2743 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002744 return r;
2745}
2746
2747/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302748 * _scsih_host_reset - eh threads main host reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302749 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002750 *
2751 * Returns SUCCESS if command aborted else FAILED
2752 */
2753static int
Eric Moored5d135b2009-05-18 13:02:08 -06002754_scsih_host_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002755{
2756 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2757 int r, retval;
2758
2759 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2760 ioc->name, scmd);
2761 scsi_print_command(scmd);
2762
2763 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2764 FORCE_BIG_HAMMER);
2765 r = (retval < 0) ? FAILED : SUCCESS;
2766 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2767 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2768
2769 return r;
2770}
2771
2772/**
2773 * _scsih_fw_event_add - insert and queue up fw_event
2774 * @ioc: per adapter object
2775 * @fw_event: object describing the event
2776 * Context: This function will acquire ioc->fw_event_lock.
2777 *
2778 * This adds the firmware event object into link list, then queues it up to
2779 * be processed from user context.
2780 *
2781 * Return nothing.
2782 */
2783static void
2784_scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2785{
2786 unsigned long flags;
2787
2788 if (ioc->firmware_event_thread == NULL)
2789 return;
2790
2791 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2792 list_add_tail(&fw_event->list, &ioc->fw_event_list);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302793 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2794 queue_delayed_work(ioc->firmware_event_thread,
2795 &fw_event->delayed_work, 0);
Eric Moore635374e2009-03-09 01:21:12 -06002796 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2797}
2798
2799/**
2800 * _scsih_fw_event_free - delete fw_event
2801 * @ioc: per adapter object
2802 * @fw_event: object describing the event
2803 * Context: This function will acquire ioc->fw_event_lock.
2804 *
2805 * This removes firmware event object from link list, frees associated memory.
2806 *
2807 * Return nothing.
2808 */
2809static void
2810_scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2811 *fw_event)
2812{
2813 unsigned long flags;
2814
2815 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2816 list_del(&fw_event->list);
Eric Moore635374e2009-03-09 01:21:12 -06002817 kfree(fw_event);
2818 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2819}
2820
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302821
Eric Moore635374e2009-03-09 01:21:12 -06002822/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302823 * _scsih_error_recovery_delete_devices - remove devices not responding
Eric Moore635374e2009-03-09 01:21:12 -06002824 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06002825 *
2826 * Return nothing.
2827 */
2828static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302829_scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06002830{
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302831 struct fw_event_work *fw_event;
2832
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302833 if (ioc->is_driver_loading)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302834 return;
Dan Carpenter181a9d72011-11-04 21:25:01 +03002835
2836 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2837 if (!fw_event)
2838 return;
2839
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302840 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2841 fw_event->ioc = ioc;
2842 _scsih_fw_event_add(ioc, fw_event);
2843}
2844
2845/**
2846 * mpt2sas_port_enable_complete - port enable completed (fake event)
2847 * @ioc: per adapter object
2848 *
2849 * Return nothing.
2850 */
2851void
2852mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2853{
2854 struct fw_event_work *fw_event;
2855
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302856 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2857 if (!fw_event)
2858 return;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302859 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302860 fw_event->ioc = ioc;
2861 _scsih_fw_event_add(ioc, fw_event);
2862}
2863
2864/**
2865 * _scsih_fw_event_cleanup_queue - cleanup event queue
2866 * @ioc: per adapter object
2867 *
2868 * Walk the firmware event queue, either killing timers, or waiting
2869 * for outstanding events to complete
2870 *
2871 * Return nothing.
2872 */
2873static void
2874_scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2875{
2876 struct fw_event_work *fw_event, *next;
2877
2878 if (list_empty(&ioc->fw_event_list) ||
2879 !ioc->firmware_event_thread || in_interrupt())
Eric Moore635374e2009-03-09 01:21:12 -06002880 return;
2881
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302882 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05302883 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302884 _scsih_fw_event_free(ioc, fw_event);
2885 continue;
2886 }
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302887 }
Eric Moore635374e2009-03-09 01:21:12 -06002888}
2889
Eric Moore635374e2009-03-09 01:21:12 -06002890/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302891 * _scsih_ublock_io_all_device - unblock every device
2892 * @ioc: per adapter object
2893 *
2894 * change the device state from block to running
2895 */
2896static void
2897_scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2898{
2899 struct MPT2SAS_DEVICE *sas_device_priv_data;
2900 struct scsi_device *sdev;
2901
2902 shost_for_each_device(sdev, ioc->shost) {
2903 sas_device_priv_data = sdev->hostdata;
2904 if (!sas_device_priv_data)
2905 continue;
2906 if (!sas_device_priv_data->block)
2907 continue;
2908 sas_device_priv_data->block = 0;
2909 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2910 "handle(0x%04x)\n",
2911 sas_device_priv_data->sas_target->handle));
Mike Christie5d9fb5c2012-05-17 23:56:57 -05002912 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302913 }
2914}
2915/**
Eric Moore635374e2009-03-09 01:21:12 -06002916 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2917 * @ioc: per adapter object
2918 * @handle: device handle
2919 *
2920 * During device pull we need to appropiately set the sdev state.
2921 */
2922static void
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302923_scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06002924{
2925 struct MPT2SAS_DEVICE *sas_device_priv_data;
2926 struct scsi_device *sdev;
2927
2928 shost_for_each_device(sdev, ioc->shost) {
2929 sas_device_priv_data = sdev->hostdata;
2930 if (!sas_device_priv_data)
2931 continue;
2932 if (!sas_device_priv_data->block)
2933 continue;
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302934 if (sas_device_priv_data->sas_target->sas_address ==
2935 sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06002936 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2937 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302938 "sas address(0x%016llx)\n", ioc->name,
2939 (unsigned long long)sas_address));
Eric Moore635374e2009-03-09 01:21:12 -06002940 sas_device_priv_data->block = 0;
Mike Christie5d9fb5c2012-05-17 23:56:57 -05002941 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
Eric Moore635374e2009-03-09 01:21:12 -06002942 }
2943 }
2944}
2945
2946/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302947 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2948 * @ioc: per adapter object
2949 * @handle: device handle
2950 *
2951 * During device pull we need to appropiately set the sdev state.
2952 */
2953static void
2954_scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2955{
2956 struct MPT2SAS_DEVICE *sas_device_priv_data;
2957 struct scsi_device *sdev;
2958
2959 shost_for_each_device(sdev, ioc->shost) {
2960 sas_device_priv_data = sdev->hostdata;
2961 if (!sas_device_priv_data)
2962 continue;
2963 if (sas_device_priv_data->block)
2964 continue;
2965 sas_device_priv_data->block = 1;
2966 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2967 "handle(0x%04x)\n",
2968 sas_device_priv_data->sas_target->handle));
2969 scsi_internal_device_block(sdev);
2970 }
2971}
2972
2973
2974/**
Eric Moore635374e2009-03-09 01:21:12 -06002975 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2976 * @ioc: per adapter object
2977 * @handle: device handle
2978 *
2979 * During device pull we need to appropiately set the sdev state.
2980 */
2981static void
2982_scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2983{
2984 struct MPT2SAS_DEVICE *sas_device_priv_data;
2985 struct scsi_device *sdev;
2986
2987 shost_for_each_device(sdev, ioc->shost) {
2988 sas_device_priv_data = sdev->hostdata;
2989 if (!sas_device_priv_data)
2990 continue;
2991 if (sas_device_priv_data->block)
2992 continue;
2993 if (sas_device_priv_data->sas_target->handle == handle) {
2994 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2995 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2996 "handle(0x%04x)\n", ioc->name, handle));
2997 sas_device_priv_data->block = 1;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05302998 scsi_internal_device_block(sdev);
Eric Moore635374e2009-03-09 01:21:12 -06002999 }
3000 }
3001}
3002
3003/**
3004 * _scsih_block_io_to_children_attached_to_ex
3005 * @ioc: per adapter object
3006 * @sas_expander: the sas_device object
3007 *
3008 * This routine set sdev state to SDEV_BLOCK for all devices
3009 * attached to this expander. This function called when expander is
3010 * pulled.
3011 */
3012static void
3013_scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
3014 struct _sas_node *sas_expander)
3015{
3016 struct _sas_port *mpt2sas_port;
3017 struct _sas_device *sas_device;
3018 struct _sas_node *expander_sibling;
3019 unsigned long flags;
3020
3021 if (!sas_expander)
3022 return;
3023
3024 list_for_each_entry(mpt2sas_port,
3025 &sas_expander->sas_port_list, port_list) {
3026 if (mpt2sas_port->remote_identify.device_type ==
3027 SAS_END_DEVICE) {
3028 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3029 sas_device =
3030 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3031 mpt2sas_port->remote_identify.sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303032 if (sas_device)
3033 set_bit(sas_device->handle,
3034 ioc->blocking_handles);
Eric Moore635374e2009-03-09 01:21:12 -06003035 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06003036 }
3037 }
3038
3039 list_for_each_entry(mpt2sas_port,
3040 &sas_expander->sas_port_list, port_list) {
3041
3042 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05303043 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06003044 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05303045 SAS_FANOUT_EXPANDER_DEVICE) {
Eric Moore635374e2009-03-09 01:21:12 -06003046 expander_sibling =
3047 mpt2sas_scsih_expander_find_by_sas_address(
3048 ioc, mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06003049 _scsih_block_io_to_children_attached_to_ex(ioc,
3050 expander_sibling);
3051 }
3052 }
3053}
3054
3055/**
3056 * _scsih_block_io_to_children_attached_directly
3057 * @ioc: per adapter object
3058 * @event_data: topology change event data
3059 *
3060 * This routine set sdev state to SDEV_BLOCK for all devices
3061 * direct attached during device pull.
3062 */
3063static void
3064_scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3065 Mpi2EventDataSasTopologyChangeList_t *event_data)
3066{
3067 int i;
3068 u16 handle;
3069 u16 reason_code;
3070 u8 phy_number;
3071
3072 for (i = 0; i < event_data->NumEntries; i++) {
3073 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3074 if (!handle)
3075 continue;
3076 phy_number = event_data->StartPhyNum + i;
3077 reason_code = event_data->PHY[i].PhyStatus &
3078 MPI2_EVENT_SAS_TOPO_RC_MASK;
3079 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3080 _scsih_block_io_device(ioc, handle);
3081 }
3082}
3083
3084/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303085 * _scsih_tm_tr_send - send task management request
3086 * @ioc: per adapter object
3087 * @handle: device handle
3088 * Context: interrupt time.
3089 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003090 * This code is to initiate the device removal handshake protocol
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303091 * with controller firmware. This function will issue target reset
3092 * using high priority request queue. It will send a sas iounit
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003093 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303094 *
3095 * This is designed to send muliple task management request at the same
3096 * time to the fifo. If the fifo is full, we will append the request,
3097 * and process it in a future completion.
3098 */
3099static void
3100_scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3101{
3102 Mpi2SCSITaskManagementRequest_t *mpi_request;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303103 u16 smid;
3104 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303105 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3106 u64 sas_address = 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303107 unsigned long flags;
3108 struct _tr_list *delayed_tr;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303109 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303110
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303111 if (ioc->remove_host) {
3112 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3113 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3114 return;
3115 } else if (ioc->pci_error_recovery) {
3116 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3117 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3118 handle));
3119 return;
3120 }
3121 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3122 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3123 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3124 "operational: handle(0x%04x)\n", __func__, ioc->name,
3125 handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303126 return;
3127 }
3128
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303129 /* if PD, then return */
3130 if (test_bit(handle, ioc->pd_handles))
3131 return;
3132
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303133 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3134 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303135 if (sas_device && sas_device->starget &&
3136 sas_device->starget->hostdata) {
3137 sas_target_priv_data = sas_device->starget->hostdata;
3138 sas_target_priv_data->deleted = 1;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303139 sas_address = sas_device->sas_address;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303140 }
3141 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303142
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303143 if (sas_target_priv_data) {
3144 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3145 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3146 (unsigned long long)sas_address));
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05303147 _scsih_ublock_io_device(ioc, sas_address);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05303148 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303149 }
3150
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303151 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3152 if (!smid) {
3153 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3154 if (!delayed_tr)
3155 return;
3156 INIT_LIST_HEAD(&delayed_tr->list);
3157 delayed_tr->handle = handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303158 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3159 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3160 "DELAYED:tr:handle(0x%04x), (open)\n",
3161 ioc->name, handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303162 return;
3163 }
3164
Kashyap, Desai1278b112010-03-09 17:34:13 +05303165 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3166 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3167 ioc->tm_tr_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303168 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3169 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3170 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3171 mpi_request->DevHandle = cpu_to_le16(handle);
3172 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303173 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3174}
3175
3176
3177
3178/**
3179 * _scsih_sas_control_complete - completion routine
3180 * @ioc: per adapter object
3181 * @smid: system request message index
3182 * @msix_index: MSIX table index supplied by the OS
3183 * @reply: reply message frame(lower 32bit addr)
3184 * Context: interrupt time.
3185 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003186 * This is the sas iounit control completion routine.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303187 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003188 * handshake protocol with controller firmware.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303189 *
3190 * Return 1 meaning mf should be freed from _base_interrupt
3191 * 0 means the mf is freed from this function.
3192 */
3193static u8
3194_scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3195 u8 msix_index, u32 reply)
3196{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303197 Mpi2SasIoUnitControlReply_t *mpi_reply =
3198 mpt2sas_base_get_reply_virt_addr(ioc, reply);
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303199 if (likely(mpi_reply)) {
3200 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3201 "sc_complete:handle(0x%04x), (open) "
3202 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3203 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3204 le16_to_cpu(mpi_reply->IOCStatus),
3205 le32_to_cpu(mpi_reply->IOCLogInfo)));
3206 } else {
3207 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3208 ioc->name, __FILE__, __LINE__, __func__);
3209 }
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303210 return 1;
3211}
3212
3213/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303214 * _scsih_tm_tr_volume_send - send target reset request for volumes
3215 * @ioc: per adapter object
3216 * @handle: device handle
3217 * Context: interrupt time.
3218 *
3219 * This is designed to send muliple task management request at the same
3220 * time to the fifo. If the fifo is full, we will append the request,
3221 * and process it in a future completion.
3222 */
3223static void
3224_scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3225{
3226 Mpi2SCSITaskManagementRequest_t *mpi_request;
3227 u16 smid;
3228 struct _tr_list *delayed_tr;
3229
Eric Moore3cb54692010-07-08 14:44:34 -06003230 if (ioc->shost_recovery || ioc->remove_host ||
3231 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303232 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3233 "progress!\n", __func__, ioc->name));
3234 return;
3235 }
3236
3237 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3238 if (!smid) {
3239 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3240 if (!delayed_tr)
3241 return;
3242 INIT_LIST_HEAD(&delayed_tr->list);
3243 delayed_tr->handle = handle;
3244 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3245 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3246 "DELAYED:tr:handle(0x%04x), (open)\n",
3247 ioc->name, handle));
3248 return;
3249 }
3250
3251 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3252 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3253 ioc->tm_tr_volume_cb_idx));
3254 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3255 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3256 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3257 mpi_request->DevHandle = cpu_to_le16(handle);
3258 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3259 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3260}
3261
3262/**
3263 * _scsih_tm_volume_tr_complete - target reset completion
3264 * @ioc: per adapter object
3265 * @smid: system request message index
3266 * @msix_index: MSIX table index supplied by the OS
3267 * @reply: reply message frame(lower 32bit addr)
3268 * Context: interrupt time.
3269 *
3270 * Return 1 meaning mf should be freed from _base_interrupt
3271 * 0 means the mf is freed from this function.
3272 */
3273static u8
3274_scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3275 u8 msix_index, u32 reply)
3276{
3277 u16 handle;
3278 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3279 Mpi2SCSITaskManagementReply_t *mpi_reply =
3280 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3281
Eric Moore3cb54692010-07-08 14:44:34 -06003282 if (ioc->shost_recovery || ioc->remove_host ||
3283 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303284 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3285 "progress!\n", __func__, ioc->name));
3286 return 1;
3287 }
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303288 if (unlikely(!mpi_reply)) {
3289 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3290 ioc->name, __FILE__, __LINE__, __func__);
3291 return 1;
3292 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303293 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3294 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3295 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3296 dewtprintk(ioc, printk("spurious interrupt: "
3297 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3298 le16_to_cpu(mpi_reply->DevHandle), smid));
3299 return 0;
3300 }
3301
3302 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3303 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3304 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3305 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3306 le32_to_cpu(mpi_reply->IOCLogInfo),
3307 le32_to_cpu(mpi_reply->TerminationCount)));
3308
3309 return _scsih_check_for_pending_tm(ioc, smid);
3310}
3311
3312/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303313 * _scsih_tm_tr_complete -
3314 * @ioc: per adapter object
3315 * @smid: system request message index
3316 * @msix_index: MSIX table index supplied by the OS
3317 * @reply: reply message frame(lower 32bit addr)
3318 * Context: interrupt time.
3319 *
3320 * This is the target reset completion routine.
3321 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003322 * handshake protocol with controller firmware.
3323 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303324 *
3325 * Return 1 meaning mf should be freed from _base_interrupt
3326 * 0 means the mf is freed from this function.
3327 */
3328static u8
3329_scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3330 u32 reply)
3331{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303332 u16 handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303333 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303334 Mpi2SCSITaskManagementReply_t *mpi_reply =
3335 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3336 Mpi2SasIoUnitControlRequest_t *mpi_request;
3337 u16 smid_sas_ctrl;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303338 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303339
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303340 if (ioc->remove_host) {
3341 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3342 "removed\n", __func__, ioc->name));
3343 return 1;
3344 } else if (ioc->pci_error_recovery) {
3345 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3346 "error recovery\n", __func__, ioc->name));
3347 return 1;
3348 }
3349 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3350 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3351 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3352 "operational\n", __func__, ioc->name));
Kashyap, Desai1278b112010-03-09 17:34:13 +05303353 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303354 }
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303355 if (unlikely(!mpi_reply)) {
3356 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3357 ioc->name, __FILE__, __LINE__, __func__);
3358 return 1;
3359 }
Kashyap, Desai1278b112010-03-09 17:34:13 +05303360 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3361 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3362 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3363 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3364 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3365 le16_to_cpu(mpi_reply->DevHandle), smid));
3366 return 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303367 }
3368
Kashyap, Desai1278b112010-03-09 17:34:13 +05303369 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3370 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3371 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3372 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3373 le32_to_cpu(mpi_reply->IOCLogInfo),
3374 le32_to_cpu(mpi_reply->TerminationCount)));
3375
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303376 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3377 if (!smid_sas_ctrl) {
3378 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3379 ioc->name, __func__);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303380 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303381 }
3382
Kashyap, Desai1278b112010-03-09 17:34:13 +05303383 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3384 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3385 ioc->tm_sas_control_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303386 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3387 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3388 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3389 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303390 mpi_request->DevHandle = mpi_request_tm->DevHandle;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303391 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303392
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303393 return _scsih_check_for_pending_tm(ioc, smid);
3394}
3395
3396/**
3397 * _scsih_check_for_pending_tm - check for pending task management
3398 * @ioc: per adapter object
3399 * @smid: system request message index
3400 *
3401 * This will check delayed target reset list, and feed the
3402 * next reqeust.
3403 *
3404 * Return 1 meaning mf should be freed from _base_interrupt
3405 * 0 means the mf is freed from this function.
3406 */
3407static u8
3408_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3409{
3410 struct _tr_list *delayed_tr;
3411
3412 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3413 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3414 struct _tr_list, list);
3415 mpt2sas_base_free_smid(ioc, smid);
3416 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3417 list_del(&delayed_tr->list);
3418 kfree(delayed_tr);
3419 return 0;
3420 }
3421
Kashyap, Desai1278b112010-03-09 17:34:13 +05303422 if (!list_empty(&ioc->delayed_tr_list)) {
3423 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3424 struct _tr_list, list);
3425 mpt2sas_base_free_smid(ioc, smid);
3426 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3427 list_del(&delayed_tr->list);
3428 kfree(delayed_tr);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303429 return 0;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303430 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303431
Kashyap, Desai1278b112010-03-09 17:34:13 +05303432 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303433}
3434
3435/**
Eric Moore635374e2009-03-09 01:21:12 -06003436 * _scsih_check_topo_delete_events - sanity check on topo events
3437 * @ioc: per adapter object
3438 * @event_data: the event data payload
3439 *
3440 * This routine added to better handle cable breaker.
3441 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003442 * This handles the case where driver receives multiple expander
Eric Moore635374e2009-03-09 01:21:12 -06003443 * add and delete events in a single shot. When there is a delete event
3444 * the routine will void any pending add events waiting in the event queue.
3445 *
3446 * Return nothing.
3447 */
3448static void
3449_scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3450 Mpi2EventDataSasTopologyChangeList_t *event_data)
3451{
3452 struct fw_event_work *fw_event;
3453 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3454 u16 expander_handle;
3455 struct _sas_node *sas_expander;
3456 unsigned long flags;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303457 int i, reason_code;
3458 u16 handle;
3459
3460 for (i = 0 ; i < event_data->NumEntries; i++) {
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303461 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3462 if (!handle)
3463 continue;
3464 reason_code = event_data->PHY[i].PhyStatus &
3465 MPI2_EVENT_SAS_TOPO_RC_MASK;
3466 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3467 _scsih_tm_tr_send(ioc, handle);
3468 }
Eric Moore635374e2009-03-09 01:21:12 -06003469
3470 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3471 if (expander_handle < ioc->sas_hba.num_phys) {
3472 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3473 return;
3474 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303475 if (event_data->ExpStatus ==
3476 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3477 /* put expander attached devices into blocking state */
Eric Moore635374e2009-03-09 01:21:12 -06003478 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3479 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3480 expander_handle);
Eric Moore635374e2009-03-09 01:21:12 -06003481 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303482 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3483 do {
3484 handle = find_first_bit(ioc->blocking_handles,
3485 ioc->facts.MaxDevHandle);
3486 if (handle < ioc->facts.MaxDevHandle)
3487 _scsih_block_io_device(ioc, handle);
3488 } while (test_and_clear_bit(handle, ioc->blocking_handles));
Eric Moore635374e2009-03-09 01:21:12 -06003489 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3490 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3491
3492 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3493 return;
3494
3495 /* mark ignore flag for pending events */
3496 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3497 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3498 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3499 fw_event->ignore)
3500 continue;
Joe Lawrence00713ad2014-06-25 17:03:33 -04003501 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3502 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06003503 if (local_event_data->ExpStatus ==
3504 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3505 local_event_data->ExpStatus ==
3506 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3507 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3508 expander_handle) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303509 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06003510 "setting ignoring flag\n", ioc->name));
3511 fw_event->ignore = 1;
3512 }
3513 }
3514 }
3515 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3516}
3517
3518/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303519 * _scsih_set_volume_delete_flag - setting volume delete flag
3520 * @ioc: per adapter object
3521 * @handle: device handle
3522 *
3523 * This
3524 * Return nothing.
3525 */
3526static void
3527_scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3528{
3529 struct _raid_device *raid_device;
3530 struct MPT2SAS_TARGET *sas_target_priv_data;
3531 unsigned long flags;
3532
3533 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3534 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3535 if (raid_device && raid_device->starget &&
3536 raid_device->starget->hostdata) {
3537 sas_target_priv_data =
3538 raid_device->starget->hostdata;
3539 sas_target_priv_data->deleted = 1;
3540 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3541 "setting delete flag: handle(0x%04x), "
3542 "wwid(0x%016llx)\n", ioc->name, handle,
3543 (unsigned long long) raid_device->wwid));
3544 }
3545 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3546}
3547
3548/**
3549 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3550 * @handle: input handle
3551 * @a: handle for volume a
3552 * @b: handle for volume b
3553 *
3554 * IR firmware only supports two raid volumes. The purpose of this
3555 * routine is to set the volume handle in either a or b. When the given
3556 * input handle is non-zero, or when a and b have not been set before.
3557 */
3558static void
3559_scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3560{
3561 if (!handle || handle == *a || handle == *b)
3562 return;
3563 if (!*a)
3564 *a = handle;
3565 else if (!*b)
3566 *b = handle;
3567}
3568
3569/**
3570 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3571 * @ioc: per adapter object
3572 * @event_data: the event data payload
3573 * Context: interrupt time.
3574 *
3575 * This routine will send target reset to volume, followed by target
3576 * resets to the PDs. This is called when a PD has been removed, or
3577 * volume has been deleted or removed. When the target reset is sent
3578 * to volume, the PD target resets need to be queued to start upon
3579 * completion of the volume target reset.
3580 *
3581 * Return nothing.
3582 */
3583static void
3584_scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3585 Mpi2EventDataIrConfigChangeList_t *event_data)
3586{
3587 Mpi2EventIrConfigElement_t *element;
3588 int i;
3589 u16 handle, volume_handle, a, b;
3590 struct _tr_list *delayed_tr;
3591
3592 a = 0;
3593 b = 0;
3594
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303595 if (ioc->is_warpdrive)
3596 return;
3597
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303598 /* Volume Resets for Deleted or Removed */
3599 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3600 for (i = 0; i < event_data->NumElements; i++, element++) {
3601 if (element->ReasonCode ==
3602 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3603 element->ReasonCode ==
3604 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3605 volume_handle = le16_to_cpu(element->VolDevHandle);
3606 _scsih_set_volume_delete_flag(ioc, volume_handle);
3607 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3608 }
3609 }
3610
3611 /* Volume Resets for UNHIDE events */
3612 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3613 for (i = 0; i < event_data->NumElements; i++, element++) {
3614 if (le32_to_cpu(event_data->Flags) &
3615 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3616 continue;
3617 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3618 volume_handle = le16_to_cpu(element->VolDevHandle);
3619 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3620 }
3621 }
3622
3623 if (a)
3624 _scsih_tm_tr_volume_send(ioc, a);
3625 if (b)
3626 _scsih_tm_tr_volume_send(ioc, b);
3627
3628 /* PD target resets */
3629 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3630 for (i = 0; i < event_data->NumElements; i++, element++) {
3631 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3632 continue;
3633 handle = le16_to_cpu(element->PhysDiskDevHandle);
3634 volume_handle = le16_to_cpu(element->VolDevHandle);
3635 clear_bit(handle, ioc->pd_handles);
3636 if (!volume_handle)
3637 _scsih_tm_tr_send(ioc, handle);
3638 else if (volume_handle == a || volume_handle == b) {
3639 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3640 BUG_ON(!delayed_tr);
3641 INIT_LIST_HEAD(&delayed_tr->list);
3642 delayed_tr->handle = handle;
3643 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3644 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3645 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3646 handle));
3647 } else
3648 _scsih_tm_tr_send(ioc, handle);
3649 }
3650}
3651
3652
3653/**
3654 * _scsih_check_volume_delete_events - set delete flag for volumes
3655 * @ioc: per adapter object
3656 * @event_data: the event data payload
3657 * Context: interrupt time.
3658 *
3659 * This will handle the case when the cable connected to entire volume is
3660 * pulled. We will take care of setting the deleted flag so normal IO will
3661 * not be sent.
3662 *
3663 * Return nothing.
3664 */
3665static void
3666_scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3667 Mpi2EventDataIrVolume_t *event_data)
3668{
3669 u32 state;
3670
3671 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3672 return;
3673 state = le32_to_cpu(event_data->NewValue);
3674 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3675 MPI2_RAID_VOL_STATE_FAILED)
3676 _scsih_set_volume_delete_flag(ioc,
3677 le16_to_cpu(event_data->VolDevHandle));
3678}
3679
3680/**
Eric Moore635374e2009-03-09 01:21:12 -06003681 * _scsih_flush_running_cmds - completing outstanding commands.
3682 * @ioc: per adapter object
3683 *
3684 * The flushing out of all pending scmd commands following host reset,
3685 * where all IO is dropped to the floor.
3686 *
3687 * Return nothing.
3688 */
3689static void
3690_scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3691{
3692 struct scsi_cmnd *scmd;
3693 u16 smid;
3694 u16 count = 0;
3695
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303696 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05303697 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003698 if (!scmd)
3699 continue;
3700 count++;
3701 mpt2sas_base_free_smid(ioc, smid);
3702 scsi_dma_unmap(scmd);
Eric Moore3cb54692010-07-08 14:44:34 -06003703 if (ioc->pci_error_recovery)
3704 scmd->result = DID_NO_CONNECT << 16;
3705 else
3706 scmd->result = DID_RESET << 16;
Eric Moore635374e2009-03-09 01:21:12 -06003707 scmd->scsi_done(scmd);
3708 }
3709 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3710 ioc->name, count));
3711}
3712
3713/**
Eric Moore3c621b32009-05-18 12:59:41 -06003714 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3715 * @scmd: pointer to scsi command object
3716 * @mpi_request: pointer to the SCSI_IO reqest message frame
3717 *
3718 * Supporting protection 1 and 3.
3719 *
3720 * Returns nothing
3721 */
3722static void
3723_scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3724{
3725 u16 eedp_flags;
3726 unsigned char prot_op = scsi_get_prot_op(scmd);
3727 unsigned char prot_type = scsi_get_prot_type(scmd);
3728
Eric Moored334aa72010-04-22 10:47:40 -06003729 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
Eric Moore3c621b32009-05-18 12:59:41 -06003730 return;
3731
3732 if (prot_op == SCSI_PROT_READ_STRIP)
3733 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3734 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3735 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3736 else
3737 return;
3738
Eric Moore3c621b32009-05-18 12:59:41 -06003739 switch (prot_type) {
3740 case SCSI_PROT_DIF_TYPE1:
Martin K. Petersen756aca72011-05-18 00:45:22 -04003741 case SCSI_PROT_DIF_TYPE2:
Eric Moore3c621b32009-05-18 12:59:41 -06003742
3743 /*
3744 * enable ref/guard checking
3745 * auto increment ref tag
3746 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303747 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
Eric Moore3c621b32009-05-18 12:59:41 -06003748 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3749 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3750 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3751 cpu_to_be32(scsi_get_lba(scmd));
Eric Moored334aa72010-04-22 10:47:40 -06003752 break;
Eric Moore3c621b32009-05-18 12:59:41 -06003753
Eric Moore3c621b32009-05-18 12:59:41 -06003754 case SCSI_PROT_DIF_TYPE3:
3755
3756 /*
3757 * enable guard checking
3758 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303759 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
Eric Moore3c621b32009-05-18 12:59:41 -06003760 break;
3761 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05303762 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3763 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
Eric Moore3c621b32009-05-18 12:59:41 -06003764}
3765
3766/**
3767 * _scsih_eedp_error_handling - return sense code for EEDP errors
3768 * @scmd: pointer to scsi command object
3769 * @ioc_status: ioc status
3770 *
3771 * Returns nothing
3772 */
3773static void
3774_scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3775{
3776 u8 ascq;
Eric Moore3c621b32009-05-18 12:59:41 -06003777
3778 switch (ioc_status) {
3779 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3780 ascq = 0x01;
3781 break;
3782 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3783 ascq = 0x02;
3784 break;
3785 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3786 ascq = 0x03;
3787 break;
3788 default:
3789 ascq = 0x00;
3790 break;
3791 }
3792
Martin K. Petersen9b5cd132012-08-28 14:29:36 -04003793 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq);
3794 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
Eric Moore3c621b32009-05-18 12:59:41 -06003795 SAM_STAT_CHECK_CONDITION;
3796}
3797
3798/**
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303799 * _scsih_scsi_direct_io_get - returns direct io flag
3800 * @ioc: per adapter object
3801 * @smid: system request message index
3802 *
3803 * Returns the smid stored scmd pointer.
3804 */
3805static inline u8
3806_scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3807{
3808 return ioc->scsi_lookup[smid - 1].direct_io;
3809}
3810
3811/**
3812 * _scsih_scsi_direct_io_set - sets direct io flag
3813 * @ioc: per adapter object
3814 * @smid: system request message index
3815 * @direct_io: Zero or non-zero value to set in the direct_io flag
3816 *
3817 * Returns Nothing.
3818 */
3819static inline void
3820_scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3821{
3822 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3823}
3824
3825
3826/**
3827 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3828 * @ioc: per adapter object
3829 * @scmd: pointer to scsi command object
3830 * @raid_device: pointer to raid device data structure
3831 * @mpi_request: pointer to the SCSI_IO reqest message frame
3832 * @smid: system request message index
3833 *
3834 * Returns nothing
3835 */
3836static void
3837_scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3838 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3839 u16 smid)
3840{
Sreekanth Reddyf78f6942014-09-19 12:17:27 +05303841 sector_t v_lba, p_lba, stripe_off, column, io_size;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303842 u32 stripe_sz, stripe_exp;
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303843 u8 num_pds, cmd = scmd->cmnd[0];
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303844
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303845 if (cmd != READ_10 && cmd != WRITE_10 &&
3846 cmd != READ_16 && cmd != WRITE_16)
3847 return;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303848
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303849 if (cmd == READ_10 || cmd == WRITE_10)
3850 v_lba = get_unaligned_be32(&mpi_request->CDB.CDB32[2]);
3851 else
3852 v_lba = get_unaligned_be64(&mpi_request->CDB.CDB32[2]);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303853
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303854 io_size = scsi_bufflen(scmd) >> raid_device->block_exponent;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303855
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303856 if (v_lba + io_size - 1 > raid_device->max_lba)
3857 return;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303858
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303859 stripe_sz = raid_device->stripe_sz;
3860 stripe_exp = raid_device->stripe_exponent;
3861 stripe_off = v_lba & (stripe_sz - 1);
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303862
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303863 /* Return unless IO falls within a stripe */
3864 if (stripe_off + io_size > stripe_sz)
3865 return;
3866
3867 num_pds = raid_device->num_pds;
3868 p_lba = v_lba >> stripe_exp;
Sreekanth Reddyf78f6942014-09-19 12:17:27 +05303869 column = sector_div(p_lba, num_pds);
3870 p_lba = (p_lba << stripe_exp) + stripe_off;
3871
Sreekanth Reddydaeaa9d2014-09-12 15:35:21 +05303872 mpi_request->DevHandle = cpu_to_le16(raid_device->pd_handle[column]);
3873
3874 if (cmd == READ_10 || cmd == WRITE_10)
3875 put_unaligned_be32(lower_32_bits(p_lba),
3876 &mpi_request->CDB.CDB32[2]);
3877 else
3878 put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]);
3879
3880 _scsih_scsi_direct_io_set(ioc, smid, 1);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303881}
3882
3883/**
Eric Moored5d135b2009-05-18 13:02:08 -06003884 * _scsih_qcmd - main scsi request entry point
Eric Moore635374e2009-03-09 01:21:12 -06003885 * @scmd: pointer to scsi command object
3886 * @done: function pointer to be invoked on completion
3887 *
3888 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3889 *
3890 * Returns 0 on success. If there's a failure, return either:
3891 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3892 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3893 */
3894static int
Matthew Wilcox90f951e2014-03-27 16:40:33 -04003895_scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06003896{
Matthew Wilcox90f951e2014-03-27 16:40:33 -04003897 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Eric Moore635374e2009-03-09 01:21:12 -06003898 struct MPT2SAS_DEVICE *sas_device_priv_data;
3899 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303900 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06003901 Mpi2SCSIIORequest_t *mpi_request;
3902 u32 mpi_control;
3903 u16 smid;
Eric Moore635374e2009-03-09 01:21:12 -06003904
Eric Moore635374e2009-03-09 01:21:12 -06003905 sas_device_priv_data = scmd->device->hostdata;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303906 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Eric Moore635374e2009-03-09 01:21:12 -06003907 scmd->result = DID_NO_CONNECT << 16;
3908 scmd->scsi_done(scmd);
3909 return 0;
3910 }
3911
Kashyap, Desai78215782011-06-14 10:57:08 +05303912 if (ioc->pci_error_recovery || ioc->remove_host) {
Eric Moore3cb54692010-07-08 14:44:34 -06003913 scmd->result = DID_NO_CONNECT << 16;
3914 scmd->scsi_done(scmd);
3915 return 0;
3916 }
3917
Eric Moore635374e2009-03-09 01:21:12 -06003918 sas_target_priv_data = sas_device_priv_data->sas_target;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303919 /* invalid device handle */
3920 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
Eric Moore635374e2009-03-09 01:21:12 -06003921 scmd->result = DID_NO_CONNECT << 16;
3922 scmd->scsi_done(scmd);
3923 return 0;
3924 }
3925
Kashyap, Desai130b9582010-04-08 17:54:32 +05303926 /* host recovery or link resets sent via IOCTLs */
3927 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
Eric Moore635374e2009-03-09 01:21:12 -06003928 return SCSI_MLQUEUE_HOST_BUSY;
Uwe Kleine-König65155b32010-06-11 12:17:01 +02003929 /* device busy with task management */
Kashyap, Desai130b9582010-04-08 17:54:32 +05303930 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3931 return SCSI_MLQUEUE_DEVICE_BUSY;
3932 /* device has been deleted */
3933 else if (sas_target_priv_data->deleted) {
3934 scmd->result = DID_NO_CONNECT << 16;
3935 scmd->scsi_done(scmd);
3936 return 0;
3937 }
Eric Moore635374e2009-03-09 01:21:12 -06003938
3939 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3940 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3941 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3942 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3943 else
3944 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3945
3946 /* set tags */
Christoph Hellwig609aa222014-10-30 11:54:58 +01003947 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3948
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303949 /* Make sure Device is not raid volume.
3950 * We do not expose raid functionality to upper layer for warpdrive.
3951 */
3952 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Eric Moored334aa72010-04-22 10:47:40 -06003953 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
Eric Moore635374e2009-03-09 01:21:12 -06003954 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3955
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303956 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06003957 if (!smid) {
3958 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3959 ioc->name, __func__);
3960 goto out;
3961 }
3962 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3963 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
Eric Moore3c621b32009-05-18 12:59:41 -06003964 _scsih_setup_eedp(scmd, mpi_request);
Eric Moored334aa72010-04-22 10:47:40 -06003965 if (scmd->cmd_len == 32)
3966 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
Eric Moore635374e2009-03-09 01:21:12 -06003967 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3968 if (sas_device_priv_data->sas_target->flags &
3969 MPT_TARGET_FLAGS_RAID_COMPONENT)
3970 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3971 else
Matthew Wilcox90f951e2014-03-27 16:40:33 -04003972 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
Eric Moore635374e2009-03-09 01:21:12 -06003973 mpi_request->DevHandle =
3974 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3975 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3976 mpi_request->Control = cpu_to_le32(mpi_control);
3977 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3978 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3979 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3980 mpi_request->SenseBufferLowAddress =
Kashyap, Desaiec9472c2009-09-23 17:34:13 +05303981 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003982 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3983 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3984 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05303985 mpi_request->VF_ID = 0; /* TODO */
3986 mpi_request->VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06003987 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3988 mpi_request->LUN);
3989 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3990
3991 if (!mpi_request->DataLength) {
3992 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
3993 } else {
3994 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
3995 mpt2sas_base_free_smid(ioc, smid);
3996 goto out;
3997 }
3998 }
3999
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304000 raid_device = sas_target_priv_data->raid_device;
4001 if (raid_device && raid_device->direct_io_enabled)
4002 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4003 smid);
4004
Kashyap, Desai58287fd2010-03-17 16:27:25 +05304005 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
4006 mpt2sas_base_put_smid_scsi_io(ioc, smid,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304007 le16_to_cpu(mpi_request->DevHandle));
Kashyap, Desai58287fd2010-03-17 16:27:25 +05304008 else
4009 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004010 return 0;
4011
4012 out:
4013 return SCSI_MLQUEUE_HOST_BUSY;
4014}
4015
4016/**
4017 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4018 * @sense_buffer: sense data returned by target
4019 * @data: normalized skey/asc/ascq
4020 *
4021 * Return nothing.
4022 */
4023static void
4024_scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4025{
4026 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4027 /* descriptor format */
4028 data->skey = sense_buffer[1] & 0x0F;
4029 data->asc = sense_buffer[2];
4030 data->ascq = sense_buffer[3];
4031 } else {
4032 /* fixed format */
4033 data->skey = sense_buffer[2] & 0x0F;
4034 data->asc = sense_buffer[12];
4035 data->ascq = sense_buffer[13];
4036 }
4037}
4038
4039#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4040/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004041 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
Eric Moore635374e2009-03-09 01:21:12 -06004042 * @ioc: per adapter object
4043 * @scmd: pointer to scsi command object
4044 * @mpi_reply: reply mf payload returned from firmware
4045 *
4046 * scsi_status - SCSI Status code returned from target device
4047 * scsi_state - state info associated with SCSI_IO determined by ioc
4048 * ioc_status - ioc supplied status info
4049 *
4050 * Return nothing.
4051 */
4052static void
4053_scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4054 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4055{
4056 u32 response_info;
4057 u8 *response_bytes;
4058 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4059 MPI2_IOCSTATUS_MASK;
4060 u8 scsi_state = mpi_reply->SCSIState;
4061 u8 scsi_status = mpi_reply->SCSIStatus;
4062 char *desc_ioc_state = NULL;
4063 char *desc_scsi_status = NULL;
4064 char *desc_scsi_state = ioc->tmp_string;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304065 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304066 struct _sas_device *sas_device = NULL;
4067 unsigned long flags;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304068 struct scsi_target *starget = scmd->device->sdev_target;
4069 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304070 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304071
4072 if (!priv_target)
4073 return;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304074
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304075 if (ioc->hide_ir_msg)
4076 device_str = "WarpDrive";
4077 else
4078 device_str = "volume";
4079
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304080 if (log_info == 0x31170000)
4081 return;
Eric Moore635374e2009-03-09 01:21:12 -06004082
4083 switch (ioc_status) {
4084 case MPI2_IOCSTATUS_SUCCESS:
4085 desc_ioc_state = "success";
4086 break;
4087 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4088 desc_ioc_state = "invalid function";
4089 break;
4090 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4091 desc_ioc_state = "scsi recovered error";
4092 break;
4093 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4094 desc_ioc_state = "scsi invalid dev handle";
4095 break;
4096 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4097 desc_ioc_state = "scsi device not there";
4098 break;
4099 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4100 desc_ioc_state = "scsi data overrun";
4101 break;
4102 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4103 desc_ioc_state = "scsi data underrun";
4104 break;
4105 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4106 desc_ioc_state = "scsi io data error";
4107 break;
4108 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4109 desc_ioc_state = "scsi protocol error";
4110 break;
4111 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4112 desc_ioc_state = "scsi task terminated";
4113 break;
4114 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4115 desc_ioc_state = "scsi residual mismatch";
4116 break;
4117 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4118 desc_ioc_state = "scsi task mgmt failed";
4119 break;
4120 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4121 desc_ioc_state = "scsi ioc terminated";
4122 break;
4123 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4124 desc_ioc_state = "scsi ext terminated";
4125 break;
Eric Moore3c621b32009-05-18 12:59:41 -06004126 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4127 desc_ioc_state = "eedp guard error";
4128 break;
4129 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4130 desc_ioc_state = "eedp ref tag error";
4131 break;
4132 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4133 desc_ioc_state = "eedp app tag error";
4134 break;
Eric Moore635374e2009-03-09 01:21:12 -06004135 default:
4136 desc_ioc_state = "unknown";
4137 break;
4138 }
4139
4140 switch (scsi_status) {
4141 case MPI2_SCSI_STATUS_GOOD:
4142 desc_scsi_status = "good";
4143 break;
4144 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4145 desc_scsi_status = "check condition";
4146 break;
4147 case MPI2_SCSI_STATUS_CONDITION_MET:
4148 desc_scsi_status = "condition met";
4149 break;
4150 case MPI2_SCSI_STATUS_BUSY:
4151 desc_scsi_status = "busy";
4152 break;
4153 case MPI2_SCSI_STATUS_INTERMEDIATE:
4154 desc_scsi_status = "intermediate";
4155 break;
4156 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4157 desc_scsi_status = "intermediate condmet";
4158 break;
4159 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4160 desc_scsi_status = "reservation conflict";
4161 break;
4162 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4163 desc_scsi_status = "command terminated";
4164 break;
4165 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4166 desc_scsi_status = "task set full";
4167 break;
4168 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4169 desc_scsi_status = "aca active";
4170 break;
4171 case MPI2_SCSI_STATUS_TASK_ABORTED:
4172 desc_scsi_status = "task aborted";
4173 break;
4174 default:
4175 desc_scsi_status = "unknown";
4176 break;
4177 }
4178
4179 desc_scsi_state[0] = '\0';
4180 if (!scsi_state)
4181 desc_scsi_state = " ";
4182 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4183 strcat(desc_scsi_state, "response info ");
4184 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4185 strcat(desc_scsi_state, "state terminated ");
4186 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4187 strcat(desc_scsi_state, "no status ");
4188 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4189 strcat(desc_scsi_state, "autosense failed ");
4190 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4191 strcat(desc_scsi_state, "autosense valid ");
4192
4193 scsi_print_command(scmd);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304194
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304195 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304196 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4197 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304198 } else {
4199 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4200 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4201 priv_target->sas_address);
4202 if (sas_device) {
4203 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4204 "phy(%d)\n", ioc->name, sas_device->sas_address,
4205 sas_device->phy);
4206 printk(MPT2SAS_WARN_FMT
4207 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4208 ioc->name, sas_device->enclosure_logical_id,
4209 sas_device->slot);
4210 }
4211 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304212 }
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304213
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304214 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4215 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4216 desc_ioc_state, ioc_status, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004217 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4218 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4219 scsi_get_resid(scmd));
4220 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4221 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4222 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4223 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4224 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4225 scsi_status, desc_scsi_state, scsi_state);
4226
4227 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4228 struct sense_info data;
4229 _scsih_normalize_sense(scmd->sense_buffer, &data);
4230 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
Kashyap, Desaie94f6742010-03-17 16:24:52 +05304231 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4232 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
Eric Moore635374e2009-03-09 01:21:12 -06004233 }
4234
4235 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4236 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4237 response_bytes = (u8 *)&response_info;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304238 _scsih_response_code(ioc, response_bytes[0]);
Eric Moore635374e2009-03-09 01:21:12 -06004239 }
4240}
4241#endif
4242
4243/**
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304244 * _scsih_turn_on_pfa_led - illuminate PFA LED
Eric Moore635374e2009-03-09 01:21:12 -06004245 * @ioc: per adapter object
4246 * @handle: device handle
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304247 * Context: process
4248 *
4249 * Return nothing.
4250 */
4251static void
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304252_scsih_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304253{
4254 Mpi2SepReply_t mpi_reply;
4255 Mpi2SepRequest_t mpi_request;
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304256 struct _sas_device *sas_device;
4257
4258 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4259 if (!sas_device)
4260 return;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304261
4262 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4263 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4264 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4265 mpi_request.SlotStatus =
4266 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4267 mpi_request.DevHandle = cpu_to_le16(handle);
4268 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4269 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4270 &mpi_request)) != 0) {
4271 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4272 __FILE__, __LINE__, __func__);
4273 return;
4274 }
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304275 sas_device->pfa_led_on = 1;
4276
4277
4278 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4279 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
4280 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4281 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4282 le32_to_cpu(mpi_reply.IOCLogInfo)));
4283 return;
4284 }
4285}
4286
4287/**
4288 * _scsih_turn_off_pfa_led - turn off PFA LED
4289 * @ioc: per adapter object
4290 * @sas_device: sas device whose PFA LED has to turned off
4291 * Context: process
4292 *
4293 * Return nothing.
4294 */
4295static void
4296_scsih_turn_off_pfa_led(struct MPT2SAS_ADAPTER *ioc,
4297 struct _sas_device *sas_device)
4298{
4299 Mpi2SepReply_t mpi_reply;
4300 Mpi2SepRequest_t mpi_request;
4301
4302 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4303 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4304 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4305 mpi_request.SlotStatus = 0;
4306 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4307 mpi_request.DevHandle = 0;
4308 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4309 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4310 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4311 &mpi_request)) != 0) {
4312 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4313 __FILE__, __LINE__, __func__);
4314 return;
4315 }
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304316
4317 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4318 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4319 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4320 le16_to_cpu(mpi_reply.IOCStatus),
4321 le32_to_cpu(mpi_reply.IOCLogInfo)));
4322 return;
4323 }
4324}
4325
4326/**
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304327 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304328 * @ioc: per adapter object
4329 * @handle: device handle
4330 * Context: interrupt.
4331 *
4332 * Return nothing.
4333 */
4334static void
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304335_scsih_send_event_to_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304336{
4337 struct fw_event_work *fw_event;
4338
4339 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4340 if (!fw_event)
4341 return;
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304342 fw_event->event = MPT2SAS_TURN_ON_PFA_LED;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304343 fw_event->device_handle = handle;
4344 fw_event->ioc = ioc;
4345 _scsih_fw_event_add(ioc, fw_event);
4346}
4347
4348/**
4349 * _scsih_smart_predicted_fault - process smart errors
4350 * @ioc: per adapter object
4351 * @handle: device handle
4352 * Context: interrupt.
Eric Moore635374e2009-03-09 01:21:12 -06004353 *
4354 * Return nothing.
4355 */
4356static void
4357_scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4358{
Eric Moore635374e2009-03-09 01:21:12 -06004359 struct scsi_target *starget;
4360 struct MPT2SAS_TARGET *sas_target_priv_data;
4361 Mpi2EventNotificationReply_t *event_reply;
4362 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4363 struct _sas_device *sas_device;
4364 ssize_t sz;
4365 unsigned long flags;
4366
4367 /* only handle non-raid devices */
4368 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4369 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4370 if (!sas_device) {
4371 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4372 return;
4373 }
4374 starget = sas_device->starget;
4375 sas_target_priv_data = starget->hostdata;
4376
4377 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4378 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4379 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4380 return;
4381 }
4382 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4383 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4384
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304385 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05304386 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06004387
4388 /* insert into event log */
4389 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4390 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
Anton Blanchardf6a290b42011-11-07 22:05:21 +11004391 event_reply = kzalloc(sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06004392 if (!event_reply) {
4393 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4394 ioc->name, __FILE__, __LINE__, __func__);
4395 return;
4396 }
4397
4398 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4399 event_reply->Event =
4400 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4401 event_reply->MsgLength = sz/4;
4402 event_reply->EventDataLength =
4403 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4404 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4405 event_reply->EventData;
4406 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4407 event_data->ASC = 0x5D;
4408 event_data->DevHandle = cpu_to_le16(handle);
4409 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4410 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4411 kfree(event_reply);
4412}
4413
4414/**
Eric Moored5d135b2009-05-18 13:02:08 -06004415 * _scsih_io_done - scsi request callback
Eric Moore635374e2009-03-09 01:21:12 -06004416 * @ioc: per adapter object
4417 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304418 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06004419 * @reply: reply message frame(lower 32bit addr)
4420 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304421 * Callback handler when using _scsih_qcmd.
Eric Moore635374e2009-03-09 01:21:12 -06004422 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304423 * Return 1 meaning mf should be freed from _base_interrupt
4424 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06004425 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304426static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304427_scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06004428{
4429 Mpi2SCSIIORequest_t *mpi_request;
4430 Mpi2SCSIIOReply_t *mpi_reply;
4431 struct scsi_cmnd *scmd;
4432 u16 ioc_status;
4433 u32 xfer_cnt;
4434 u8 scsi_state;
4435 u8 scsi_status;
4436 u32 log_info;
4437 struct MPT2SAS_DEVICE *sas_device_priv_data;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304438 u32 response_code = 0;
Kashyap, Desai82a45252011-07-05 12:40:23 +05304439 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06004440
4441 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05304442 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004443 if (scmd == NULL)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304444 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004445
4446 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4447
4448 if (mpi_reply == NULL) {
4449 scmd->result = DID_OK << 16;
4450 goto out;
4451 }
4452
4453 sas_device_priv_data = scmd->device->hostdata;
4454 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4455 sas_device_priv_data->sas_target->deleted) {
4456 scmd->result = DID_NO_CONNECT << 16;
4457 goto out;
4458 }
nagalakshmi.nandigama@lsi.com4da7af92011-12-01 07:53:02 +05304459 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304460 /*
4461 * WARPDRIVE: If direct_io is set then it is directIO,
4462 * the failed direct I/O should be redirected to volume
4463 */
nagalakshmi.nandigama@lsi.com4da7af92011-12-01 07:53:02 +05304464 if (_scsih_scsi_direct_io_get(ioc, smid) &&
4465 ((ioc_status & MPI2_IOCSTATUS_MASK)
4466 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
Kashyap, Desai82a45252011-07-05 12:40:23 +05304467 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4468 ioc->scsi_lookup[smid - 1].scmd = scmd;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304469 _scsih_scsi_direct_io_set(ioc, smid, 0);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05304470 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304471 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4472 mpi_request->DevHandle =
4473 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4474 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4475 sas_device_priv_data->sas_target->handle);
4476 return 0;
4477 }
4478
Eric Moore635374e2009-03-09 01:21:12 -06004479
4480 /* turning off TLR */
Kashyap, Desai9982f592009-09-23 17:23:07 +05304481 scsi_state = mpi_reply->SCSIState;
4482 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4483 response_code =
4484 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
Eric Moore635374e2009-03-09 01:21:12 -06004485 if (!sas_device_priv_data->tlr_snoop_check) {
4486 sas_device_priv_data->tlr_snoop_check++;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304487 /* Make sure Device is not raid volume.
4488 * We do not expose raid functionality to upper layer for warpdrive.
4489 */
4490 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Kashyap, Desai3ed21522010-02-17 16:08:36 +05304491 sas_is_tlr_enabled(scmd->device) &&
Kashyap, Desai84f0b042009-12-16 18:56:28 +05304492 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4493 sas_disable_tlr(scmd->device);
4494 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4495 }
Eric Moore635374e2009-03-09 01:21:12 -06004496 }
4497
4498 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4499 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
Eric Moore635374e2009-03-09 01:21:12 -06004500 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4501 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4502 else
4503 log_info = 0;
4504 ioc_status &= MPI2_IOCSTATUS_MASK;
Eric Moore635374e2009-03-09 01:21:12 -06004505 scsi_status = mpi_reply->SCSIStatus;
4506
4507 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4508 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4509 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4510 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4511 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4512 }
4513
4514 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4515 struct sense_info data;
4516 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4517 smid);
Eric Moore0d04df92009-04-21 15:38:43 -06004518 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
Eric Moore635374e2009-03-09 01:21:12 -06004519 le32_to_cpu(mpi_reply->SenseCount));
Eric Moore0d04df92009-04-21 15:38:43 -06004520 memcpy(scmd->sense_buffer, sense_data, sz);
Eric Moore635374e2009-03-09 01:21:12 -06004521 _scsih_normalize_sense(scmd->sense_buffer, &data);
4522 /* failure prediction threshold exceeded */
4523 if (data.asc == 0x5D)
4524 _scsih_smart_predicted_fault(ioc,
4525 le16_to_cpu(mpi_reply->DevHandle));
4526 }
4527
4528 switch (ioc_status) {
4529 case MPI2_IOCSTATUS_BUSY:
4530 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4531 scmd->result = SAM_STAT_BUSY;
4532 break;
4533
4534 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4535 scmd->result = DID_NO_CONNECT << 16;
4536 break;
4537
4538 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4539 if (sas_device_priv_data->block) {
Kashyap, Desaie4e7c7e2009-09-23 17:33:14 +05304540 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4541 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06004542 }
nagalakshmi.nandigama@lsi.com3ade1ca2011-12-01 07:42:40 +05304543 scmd->result = DID_SOFT_ERROR << 16;
4544 break;
Eric Moore635374e2009-03-09 01:21:12 -06004545 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4546 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4547 scmd->result = DID_RESET << 16;
4548 break;
4549
4550 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4551 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4552 scmd->result = DID_SOFT_ERROR << 16;
4553 else
4554 scmd->result = (DID_OK << 16) | scsi_status;
4555 break;
4556
4557 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4558 scmd->result = (DID_OK << 16) | scsi_status;
4559
4560 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4561 break;
4562
4563 if (xfer_cnt < scmd->underflow) {
4564 if (scsi_status == SAM_STAT_BUSY)
4565 scmd->result = SAM_STAT_BUSY;
4566 else
4567 scmd->result = DID_SOFT_ERROR << 16;
4568 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4569 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4570 scmd->result = DID_SOFT_ERROR << 16;
4571 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4572 scmd->result = DID_RESET << 16;
4573 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4574 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4575 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4576 scmd->result = (DRIVER_SENSE << 24) |
4577 SAM_STAT_CHECK_CONDITION;
4578 scmd->sense_buffer[0] = 0x70;
4579 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4580 scmd->sense_buffer[12] = 0x20;
4581 scmd->sense_buffer[13] = 0;
4582 }
4583 break;
4584
4585 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4586 scsi_set_resid(scmd, 0);
4587 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4588 case MPI2_IOCSTATUS_SUCCESS:
4589 scmd->result = (DID_OK << 16) | scsi_status;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304590 if (response_code ==
4591 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4592 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4593 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
Eric Moore635374e2009-03-09 01:21:12 -06004594 scmd->result = DID_SOFT_ERROR << 16;
4595 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4596 scmd->result = DID_RESET << 16;
4597 break;
4598
Eric Moore3c621b32009-05-18 12:59:41 -06004599 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4600 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4601 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4602 _scsih_eedp_error_handling(scmd, ioc_status);
4603 break;
Eric Moore635374e2009-03-09 01:21:12 -06004604 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4605 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4606 case MPI2_IOCSTATUS_INVALID_SGL:
4607 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4608 case MPI2_IOCSTATUS_INVALID_FIELD:
4609 case MPI2_IOCSTATUS_INVALID_STATE:
4610 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4611 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4612 default:
4613 scmd->result = DID_SOFT_ERROR << 16;
4614 break;
4615
4616 }
4617
4618#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4619 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4620 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4621#endif
4622
4623 out:
4624 scsi_dma_unmap(scmd);
4625 scmd->scsi_done(scmd);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304626 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004627}
4628
4629/**
Eric Moore635374e2009-03-09 01:21:12 -06004630 * _scsih_sas_host_refresh - refreshing sas host object contents
4631 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06004632 * Context: user
4633 *
4634 * During port enable, fw will send topology events for every device. Its
4635 * possible that the handles may change from the previous setting, so this
4636 * code keeping handles updating if changed.
4637 *
4638 * Return nothing.
4639 */
4640static void
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304641_scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06004642{
4643 u16 sz;
4644 u16 ioc_status;
4645 int i;
4646 Mpi2ConfigReply_t mpi_reply;
4647 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304648 u16 attached_handle;
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304649 u8 link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06004650
4651 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4652 "updating handles for sas_host(0x%016llx)\n",
4653 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4654
4655 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4656 * sizeof(Mpi2SasIOUnit0PhyData_t));
4657 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4658 if (!sas_iounit_pg0) {
4659 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4660 ioc->name, __FILE__, __LINE__, __func__);
4661 return;
4662 }
Eric Moore635374e2009-03-09 01:21:12 -06004663
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304664 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4665 sas_iounit_pg0, sz)) != 0)
4666 goto out;
4667 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4668 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4669 goto out;
4670 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304671 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304672 if (i == 0)
4673 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4674 PhyData[0].ControllerDevHandle);
4675 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4676 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4677 AttachedDevHandle);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304678 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4679 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304680 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304681 attached_handle, i, link_rate);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304682 }
Eric Moore635374e2009-03-09 01:21:12 -06004683 out:
4684 kfree(sas_iounit_pg0);
4685}
4686
4687/**
4688 * _scsih_sas_host_add - create sas host object
4689 * @ioc: per adapter object
4690 *
4691 * Creating host side data object, stored in ioc->sas_hba
4692 *
4693 * Return nothing.
4694 */
4695static void
4696_scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4697{
4698 int i;
4699 Mpi2ConfigReply_t mpi_reply;
4700 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4701 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4702 Mpi2SasPhyPage0_t phy_pg0;
4703 Mpi2SasDevicePage0_t sas_device_pg0;
4704 Mpi2SasEnclosurePage0_t enclosure_pg0;
4705 u16 ioc_status;
4706 u16 sz;
4707 u16 device_missing_delay;
4708
4709 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4710 if (!ioc->sas_hba.num_phys) {
4711 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4712 ioc->name, __FILE__, __LINE__, __func__);
4713 return;
4714 }
4715
4716 /* sas_iounit page 0 */
4717 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4718 sizeof(Mpi2SasIOUnit0PhyData_t));
4719 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4720 if (!sas_iounit_pg0) {
4721 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4722 ioc->name, __FILE__, __LINE__, __func__);
4723 return;
4724 }
4725 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4726 sas_iounit_pg0, sz))) {
4727 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4728 ioc->name, __FILE__, __LINE__, __func__);
4729 goto out;
4730 }
4731 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4732 MPI2_IOCSTATUS_MASK;
4733 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4734 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4735 ioc->name, __FILE__, __LINE__, __func__);
4736 goto out;
4737 }
4738
4739 /* sas_iounit page 1 */
4740 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4741 sizeof(Mpi2SasIOUnit1PhyData_t));
4742 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4743 if (!sas_iounit_pg1) {
4744 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4745 ioc->name, __FILE__, __LINE__, __func__);
4746 goto out;
4747 }
4748 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4749 sas_iounit_pg1, sz))) {
4750 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4751 ioc->name, __FILE__, __LINE__, __func__);
4752 goto out;
4753 }
4754 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4755 MPI2_IOCSTATUS_MASK;
4756 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4757 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4758 ioc->name, __FILE__, __LINE__, __func__);
4759 goto out;
4760 }
4761
4762 ioc->io_missing_delay =
4763 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4764 device_missing_delay =
4765 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4766 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4767 ioc->device_missing_delay = (device_missing_delay &
4768 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4769 else
4770 ioc->device_missing_delay = device_missing_delay &
4771 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4772
4773 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4774 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4775 sizeof(struct _sas_phy), GFP_KERNEL);
4776 if (!ioc->sas_hba.phy) {
4777 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4778 ioc->name, __FILE__, __LINE__, __func__);
4779 goto out;
4780 }
4781 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4782 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4783 i))) {
4784 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4785 ioc->name, __FILE__, __LINE__, __func__);
4786 goto out;
4787 }
4788 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4789 MPI2_IOCSTATUS_MASK;
4790 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4791 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4792 ioc->name, __FILE__, __LINE__, __func__);
4793 goto out;
4794 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304795
4796 if (i == 0)
4797 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4798 PhyData[0].ControllerDevHandle);
4799 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
Eric Moore635374e2009-03-09 01:21:12 -06004800 ioc->sas_hba.phy[i].phy_id = i;
4801 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4802 phy_pg0, ioc->sas_hba.parent_dev);
4803 }
4804 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304805 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06004806 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4807 ioc->name, __FILE__, __LINE__, __func__);
4808 goto out;
4809 }
Eric Moore635374e2009-03-09 01:21:12 -06004810 ioc->sas_hba.enclosure_handle =
4811 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4812 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4813 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4814 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4815 (unsigned long long) ioc->sas_hba.sas_address,
4816 ioc->sas_hba.num_phys) ;
4817
4818 if (ioc->sas_hba.enclosure_handle) {
4819 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4820 &enclosure_pg0,
4821 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4822 ioc->sas_hba.enclosure_handle))) {
4823 ioc->sas_hba.enclosure_logical_id =
4824 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4825 }
4826 }
4827
4828 out:
4829 kfree(sas_iounit_pg1);
4830 kfree(sas_iounit_pg0);
4831}
4832
4833/**
4834 * _scsih_expander_add - creating expander object
4835 * @ioc: per adapter object
4836 * @handle: expander handle
4837 *
4838 * Creating expander object, stored in ioc->sas_expander_list.
4839 *
4840 * Return 0 for success, else error.
4841 */
4842static int
4843_scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4844{
4845 struct _sas_node *sas_expander;
4846 Mpi2ConfigReply_t mpi_reply;
4847 Mpi2ExpanderPage0_t expander_pg0;
4848 Mpi2ExpanderPage1_t expander_pg1;
4849 Mpi2SasEnclosurePage0_t enclosure_pg0;
4850 u32 ioc_status;
4851 u16 parent_handle;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05304852 u64 sas_address, sas_address_parent = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004853 int i;
4854 unsigned long flags;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304855 struct _sas_port *mpt2sas_port = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06004856 int rc = 0;
4857
4858 if (!handle)
4859 return -1;
4860
Eric Moore3cb54692010-07-08 14:44:34 -06004861 if (ioc->shost_recovery || ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05304862 return -1;
4863
Eric Moore635374e2009-03-09 01:21:12 -06004864 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4865 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4866 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4867 ioc->name, __FILE__, __LINE__, __func__);
4868 return -1;
4869 }
4870
4871 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4872 MPI2_IOCSTATUS_MASK;
4873 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4874 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4875 ioc->name, __FILE__, __LINE__, __func__);
4876 return -1;
4877 }
4878
4879 /* handle out of order topology events */
4880 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304881 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4882 != 0) {
4883 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4884 ioc->name, __FILE__, __LINE__, __func__);
4885 return -1;
4886 }
4887 if (sas_address_parent != ioc->sas_hba.sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06004888 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304889 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4890 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004891 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4892 if (!sas_expander) {
4893 rc = _scsih_expander_add(ioc, parent_handle);
4894 if (rc != 0)
4895 return rc;
4896 }
4897 }
4898
Eric Moore635374e2009-03-09 01:21:12 -06004899 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304900 sas_address = le64_to_cpu(expander_pg0.SASAddress);
Eric Moore635374e2009-03-09 01:21:12 -06004901 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4902 sas_address);
4903 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4904
4905 if (sas_expander)
4906 return 0;
4907
4908 sas_expander = kzalloc(sizeof(struct _sas_node),
4909 GFP_KERNEL);
4910 if (!sas_expander) {
4911 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4912 ioc->name, __FILE__, __LINE__, __func__);
4913 return -1;
4914 }
4915
4916 sas_expander->handle = handle;
4917 sas_expander->num_phys = expander_pg0.NumPhys;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304918 sas_expander->sas_address_parent = sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06004919 sas_expander->sas_address = sas_address;
4920
4921 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4922 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304923 handle, parent_handle, (unsigned long long)
Eric Moore635374e2009-03-09 01:21:12 -06004924 sas_expander->sas_address, sas_expander->num_phys);
4925
4926 if (!sas_expander->num_phys)
4927 goto out_fail;
4928 sas_expander->phy = kcalloc(sas_expander->num_phys,
4929 sizeof(struct _sas_phy), GFP_KERNEL);
4930 if (!sas_expander->phy) {
4931 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4932 ioc->name, __FILE__, __LINE__, __func__);
4933 rc = -1;
4934 goto out_fail;
4935 }
4936
4937 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4938 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304939 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004940 if (!mpt2sas_port) {
4941 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4942 ioc->name, __FILE__, __LINE__, __func__);
4943 rc = -1;
4944 goto out_fail;
4945 }
4946 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4947
4948 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4949 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4950 &expander_pg1, i, handle))) {
4951 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4952 ioc->name, __FILE__, __LINE__, __func__);
Kashyap, Desai20f58952009-08-07 19:34:26 +05304953 rc = -1;
4954 goto out_fail;
Eric Moore635374e2009-03-09 01:21:12 -06004955 }
4956 sas_expander->phy[i].handle = handle;
4957 sas_expander->phy[i].phy_id = i;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304958
4959 if ((mpt2sas_transport_add_expander_phy(ioc,
4960 &sas_expander->phy[i], expander_pg1,
4961 sas_expander->parent_dev))) {
4962 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4963 ioc->name, __FILE__, __LINE__, __func__);
4964 rc = -1;
4965 goto out_fail;
4966 }
Eric Moore635374e2009-03-09 01:21:12 -06004967 }
4968
4969 if (sas_expander->enclosure_handle) {
4970 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4971 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4972 sas_expander->enclosure_handle))) {
4973 sas_expander->enclosure_logical_id =
4974 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4975 }
4976 }
4977
4978 _scsih_expander_node_add(ioc, sas_expander);
4979 return 0;
4980
4981 out_fail:
4982
Kashyap, Desai20f58952009-08-07 19:34:26 +05304983 if (mpt2sas_port)
4984 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304985 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004986 kfree(sas_expander);
4987 return rc;
4988}
4989
4990/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05304991 * _scsih_done - scsih callback handler.
4992 * @ioc: per adapter object
4993 * @smid: system request message index
4994 * @msix_index: MSIX table index supplied by the OS
4995 * @reply: reply message frame(lower 32bit addr)
4996 *
4997 * Callback handler when sending internal generated message frames.
4998 * The callback index passed is `ioc->scsih_cb_idx`
4999 *
5000 * Return 1 meaning mf should be freed from _base_interrupt
5001 * 0 means the mf is freed from this function.
5002 */
5003static u8
5004_scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5005{
5006 MPI2DefaultReply_t *mpi_reply;
5007
5008 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5009 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
5010 return 1;
5011 if (ioc->scsih_cmds.smid != smid)
5012 return 1;
5013 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
5014 if (mpi_reply) {
5015 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5016 mpi_reply->MsgLength*4);
5017 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
5018 }
5019 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
5020 complete(&ioc->scsih_cmds.done);
5021 return 1;
5022}
5023
5024/**
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305025 * mpt2sas_expander_remove - removing expander object
Eric Moore635374e2009-03-09 01:21:12 -06005026 * @ioc: per adapter object
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305027 * @sas_address: expander sas_address
Eric Moore635374e2009-03-09 01:21:12 -06005028 *
5029 * Return nothing.
5030 */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305031void
5032mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06005033{
5034 struct _sas_node *sas_expander;
5035 unsigned long flags;
5036
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305037 if (ioc->shost_recovery)
5038 return;
5039
Eric Moore635374e2009-03-09 01:21:12 -06005040 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305041 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5042 sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305043 if (sas_expander)
5044 list_del(&sas_expander->list);
Eric Moore635374e2009-03-09 01:21:12 -06005045 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305046 if (sas_expander)
5047 _scsih_expander_node_remove(ioc, sas_expander);
Eric Moore635374e2009-03-09 01:21:12 -06005048}
5049
5050/**
Kashyap, Desaib4344272010-03-17 16:24:14 +05305051 * _scsih_check_access_status - check access flags
5052 * @ioc: per adapter object
5053 * @sas_address: sas address
5054 * @handle: sas device handle
5055 * @access_flags: errors returned during discovery of the device
5056 *
5057 * Return 0 for success, else failure
5058 */
5059static u8
5060_scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5061 u16 handle, u8 access_status)
5062{
5063 u8 rc = 1;
5064 char *desc = NULL;
5065
5066 switch (access_status) {
5067 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5068 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5069 rc = 0;
5070 break;
5071 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5072 desc = "sata capability failed";
5073 break;
5074 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5075 desc = "sata affiliation conflict";
5076 break;
5077 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5078 desc = "route not addressable";
5079 break;
5080 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5081 desc = "smp error not addressable";
5082 break;
5083 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5084 desc = "device blocked";
5085 break;
5086 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5087 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5088 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5089 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5090 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5091 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5092 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5093 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5094 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5095 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5096 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5097 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5098 desc = "sata initialization failed";
5099 break;
5100 default:
5101 desc = "unknown";
5102 break;
5103 }
5104
5105 if (!rc)
5106 return 0;
5107
5108 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5109 "handle(0x%04x)\n", ioc->name, desc,
5110 (unsigned long long)sas_address, handle);
5111 return rc;
5112}
5113
5114static void
5115_scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5116{
5117 Mpi2ConfigReply_t mpi_reply;
5118 Mpi2SasDevicePage0_t sas_device_pg0;
5119 struct _sas_device *sas_device;
5120 u32 ioc_status;
5121 unsigned long flags;
5122 u64 sas_address;
5123 struct scsi_target *starget;
5124 struct MPT2SAS_TARGET *sas_target_priv_data;
5125 u32 device_info;
5126
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305127
Kashyap, Desaib4344272010-03-17 16:24:14 +05305128 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5129 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5130 return;
5131
5132 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5133 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5134 return;
5135
5136 /* check if this is end device */
5137 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5138 if (!(_scsih_is_end_device(device_info)))
5139 return;
5140
5141 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5142 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5143 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5144 sas_address);
5145
5146 if (!sas_device) {
5147 printk(MPT2SAS_ERR_FMT "device is not present "
5148 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5149 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5150 return;
5151 }
5152
5153 if (unlikely(sas_device->handle != handle)) {
5154 starget = sas_device->starget;
5155 sas_target_priv_data = starget->hostdata;
5156 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5157 " to (0x%04x)!!!\n", sas_device->handle, handle);
5158 sas_target_priv_data->handle = handle;
5159 sas_device->handle = handle;
5160 }
Kashyap, Desaib4344272010-03-17 16:24:14 +05305161
5162 /* check if device is present */
5163 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5164 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5165 printk(MPT2SAS_ERR_FMT "device is not present "
5166 "handle(0x%04x), flags!!!\n", ioc->name, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305167 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305168 return;
5169 }
5170
5171 /* check if there were any issues with discovery */
5172 if (_scsih_check_access_status(ioc, sas_address, handle,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305173 sas_device_pg0.AccessStatus)) {
5174 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305175 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305176 }
5177 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05305178 _scsih_ublock_io_device(ioc, sas_address);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305179
5180}
5181
5182/**
Eric Moore635374e2009-03-09 01:21:12 -06005183 * _scsih_add_device - creating sas device object
5184 * @ioc: per adapter object
5185 * @handle: sas device handle
5186 * @phy_num: phy number end device attached to
5187 * @is_pd: is this hidden raid component
5188 *
5189 * Creating end device object, stored in ioc->sas_device_list.
5190 *
5191 * Returns 0 for success, non-zero for failure.
5192 */
5193static int
5194_scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5195{
5196 Mpi2ConfigReply_t mpi_reply;
5197 Mpi2SasDevicePage0_t sas_device_pg0;
5198 Mpi2SasEnclosurePage0_t enclosure_pg0;
5199 struct _sas_device *sas_device;
5200 u32 ioc_status;
5201 __le64 sas_address;
5202 u32 device_info;
5203 unsigned long flags;
5204
5205 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5206 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5207 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5208 ioc->name, __FILE__, __LINE__, __func__);
5209 return -1;
5210 }
5211
5212 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5213 MPI2_IOCSTATUS_MASK;
5214 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5215 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5216 ioc->name, __FILE__, __LINE__, __func__);
5217 return -1;
5218 }
5219
Kashyap, Desaib4344272010-03-17 16:24:14 +05305220 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5221
Eric Moore635374e2009-03-09 01:21:12 -06005222 /* check if device is present */
5223 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5224 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5225 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5226 ioc->name, __FILE__, __LINE__, __func__);
5227 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5228 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5229 return -1;
5230 }
5231
Kashyap, Desaib4344272010-03-17 16:24:14 +05305232 /* check if there were any issues with discovery */
5233 if (_scsih_check_access_status(ioc, sas_address, handle,
5234 sas_device_pg0.AccessStatus))
Eric Moore635374e2009-03-09 01:21:12 -06005235 return -1;
Eric Moore635374e2009-03-09 01:21:12 -06005236
5237 /* check if this is end device */
5238 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5239 if (!(_scsih_is_end_device(device_info))) {
5240 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5241 ioc->name, __FILE__, __LINE__, __func__);
5242 return -1;
5243 }
5244
Eric Moore635374e2009-03-09 01:21:12 -06005245
5246 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5247 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5248 sas_address);
5249 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5250
Kashyap, Desaib4344272010-03-17 16:24:14 +05305251 if (sas_device)
Eric Moore635374e2009-03-09 01:21:12 -06005252 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06005253
5254 sas_device = kzalloc(sizeof(struct _sas_device),
5255 GFP_KERNEL);
5256 if (!sas_device) {
5257 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5258 ioc->name, __FILE__, __LINE__, __func__);
5259 return -1;
5260 }
5261
5262 sas_device->handle = handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305263 if (_scsih_get_sas_address(ioc, le16_to_cpu
5264 (sas_device_pg0.ParentDevHandle),
5265 &sas_device->sas_address_parent) != 0)
5266 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5267 ioc->name, __FILE__, __LINE__, __func__);
Eric Moore635374e2009-03-09 01:21:12 -06005268 sas_device->enclosure_handle =
5269 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5270 sas_device->slot =
5271 le16_to_cpu(sas_device_pg0.Slot);
5272 sas_device->device_info = device_info;
5273 sas_device->sas_address = sas_address;
Kashyap, Desai7fbae672010-06-17 13:45:17 +05305274 sas_device->phy = sas_device_pg0.PhyNum;
Eric Moore635374e2009-03-09 01:21:12 -06005275
5276 /* get enclosure_logical_id */
Kashyap, Desai15052c92009-08-07 19:33:17 +05305277 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5278 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5279 sas_device->enclosure_handle)))
Eric Moore635374e2009-03-09 01:21:12 -06005280 sas_device->enclosure_logical_id =
5281 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
Eric Moore635374e2009-03-09 01:21:12 -06005282
5283 /* get device name */
5284 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5285
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305286 if (ioc->wait_for_discovery_to_complete)
Eric Moore635374e2009-03-09 01:21:12 -06005287 _scsih_sas_device_init_add(ioc, sas_device);
5288 else
5289 _scsih_sas_device_add(ioc, sas_device);
5290
5291 return 0;
5292}
5293
5294/**
Kashyap, Desai1278b112010-03-09 17:34:13 +05305295 * _scsih_remove_device - removing sas device object
5296 * @ioc: per adapter object
5297 * @sas_device_delete: the sas_device object
5298 *
5299 * Return nothing.
5300 */
5301static void
5302_scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5303 struct _sas_device *sas_device)
5304{
Kashyap, Desai1278b112010-03-09 17:34:13 +05305305 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05305306
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05305307 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5308 (sas_device->pfa_led_on)) {
5309 _scsih_turn_off_pfa_led(ioc, sas_device);
5310 sas_device->pfa_led_on = 0;
5311 }
5312
Kashyap, Desai1278b112010-03-09 17:34:13 +05305313 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5314 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305315 sas_device->handle, (unsigned long long)
5316 sas_device->sas_address));
Kashyap, Desai1278b112010-03-09 17:34:13 +05305317
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305318 if (sas_device->starget && sas_device->starget->hostdata) {
5319 sas_target_priv_data = sas_device->starget->hostdata;
Kashyap, Desai1278b112010-03-09 17:34:13 +05305320 sas_target_priv_data->deleted = 1;
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05305321 _scsih_ublock_io_device(ioc, sas_device->sas_address);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305322 sas_target_priv_data->handle =
5323 MPT2SAS_INVALID_DEVICE_HANDLE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05305324 }
5325
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05305326 if (!ioc->hide_drives)
5327 mpt2sas_transport_port_remove(ioc,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305328 sas_device->sas_address,
5329 sas_device->sas_address_parent);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305330
5331 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305332 "(0x%016llx)\n", ioc->name, sas_device->handle,
5333 (unsigned long long) sas_device->sas_address);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305334
5335 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5336 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305337 sas_device->handle, (unsigned long long)
5338 sas_device->sas_address));
5339 kfree(sas_device);
5340}
5341/**
5342 * _scsih_device_remove_by_handle - removing device object by handle
5343 * @ioc: per adapter object
5344 * @handle: device handle
5345 *
5346 * Return nothing.
5347 */
5348static void
5349_scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5350{
5351 struct _sas_device *sas_device;
5352 unsigned long flags;
5353
5354 if (ioc->shost_recovery)
5355 return;
5356
5357 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5358 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5359 if (sas_device)
5360 list_del(&sas_device->list);
5361 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5362 if (sas_device)
5363 _scsih_remove_device(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -06005364}
5365
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305366/**
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305367 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305368 * @ioc: per adapter object
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305369 * @sas_address: device sas_address
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305370 *
5371 * Return nothing.
5372 */
5373void
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305374mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
5375 u64 sas_address)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305376{
5377 struct _sas_device *sas_device;
5378 unsigned long flags;
5379
5380 if (ioc->shost_recovery)
5381 return;
5382
5383 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5384 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5385 sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305386 if (sas_device)
5387 list_del(&sas_device->list);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305388 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305389 if (sas_device)
5390 _scsih_remove_device(ioc, sas_device);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305391}
Eric Moore635374e2009-03-09 01:21:12 -06005392#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5393/**
5394 * _scsih_sas_topology_change_event_debug - debug for topology event
5395 * @ioc: per adapter object
5396 * @event_data: event data payload
5397 * Context: user.
5398 */
5399static void
5400_scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5401 Mpi2EventDataSasTopologyChangeList_t *event_data)
5402{
5403 int i;
5404 u16 handle;
5405 u16 reason_code;
5406 u8 phy_number;
5407 char *status_str = NULL;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305408 u8 link_rate, prev_link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06005409
5410 switch (event_data->ExpStatus) {
5411 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5412 status_str = "add";
5413 break;
5414 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5415 status_str = "remove";
5416 break;
5417 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305418 case 0:
Eric Moore635374e2009-03-09 01:21:12 -06005419 status_str = "responding";
5420 break;
5421 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5422 status_str = "remove delay";
5423 break;
5424 default:
5425 status_str = "unknown status";
5426 break;
5427 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305428 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
Eric Moore635374e2009-03-09 01:21:12 -06005429 ioc->name, status_str);
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305430 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
Eric Moore635374e2009-03-09 01:21:12 -06005431 "start_phy(%02d), count(%d)\n",
5432 le16_to_cpu(event_data->ExpanderDevHandle),
5433 le16_to_cpu(event_data->EnclosureHandle),
5434 event_data->StartPhyNum, event_data->NumEntries);
5435 for (i = 0; i < event_data->NumEntries; i++) {
5436 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5437 if (!handle)
5438 continue;
5439 phy_number = event_data->StartPhyNum + i;
5440 reason_code = event_data->PHY[i].PhyStatus &
5441 MPI2_EVENT_SAS_TOPO_RC_MASK;
5442 switch (reason_code) {
5443 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305444 status_str = "target add";
Eric Moore635374e2009-03-09 01:21:12 -06005445 break;
5446 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305447 status_str = "target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005448 break;
5449 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305450 status_str = "delay target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005451 break;
5452 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305453 status_str = "link rate change";
Eric Moore635374e2009-03-09 01:21:12 -06005454 break;
5455 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305456 status_str = "target responding";
Eric Moore635374e2009-03-09 01:21:12 -06005457 break;
5458 default:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305459 status_str = "unknown";
Eric Moore635374e2009-03-09 01:21:12 -06005460 break;
5461 }
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305462 link_rate = event_data->PHY[i].LinkRate >> 4;
5463 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305464 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305465 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5466 handle, status_str, link_rate, prev_link_rate);
5467
Eric Moore635374e2009-03-09 01:21:12 -06005468 }
5469}
5470#endif
5471
5472/**
5473 * _scsih_sas_topology_change_event - handle topology changes
5474 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305475 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005476 * Context: user.
5477 *
5478 */
5479static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305480_scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
Eric Moore635374e2009-03-09 01:21:12 -06005481 struct fw_event_work *fw_event)
5482{
5483 int i;
5484 u16 parent_handle, handle;
5485 u16 reason_code;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305486 u8 phy_number, max_phys;
Eric Moore635374e2009-03-09 01:21:12 -06005487 struct _sas_node *sas_expander;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305488 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06005489 unsigned long flags;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305490 u8 link_rate, prev_link_rate;
Joe Lawrence00713ad2014-06-25 17:03:33 -04005491 Mpi2EventDataSasTopologyChangeList_t *event_data =
5492 (Mpi2EventDataSasTopologyChangeList_t *)
5493 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06005494
5495#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5496 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5497 _scsih_sas_topology_change_event_debug(ioc, event_data);
5498#endif
5499
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305500 if (ioc->remove_host || ioc->pci_error_recovery)
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305501 return;
5502
Eric Moore635374e2009-03-09 01:21:12 -06005503 if (!ioc->sas_hba.num_phys)
5504 _scsih_sas_host_add(ioc);
5505 else
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305506 _scsih_sas_host_refresh(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005507
5508 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305509 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
Eric Moore635374e2009-03-09 01:21:12 -06005510 "event\n", ioc->name));
5511 return;
5512 }
5513
5514 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5515
5516 /* handle expander add */
5517 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5518 if (_scsih_expander_add(ioc, parent_handle) != 0)
5519 return;
5520
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305521 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5522 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5523 parent_handle);
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305524 if (sas_expander) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305525 sas_address = sas_expander->sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305526 max_phys = sas_expander->num_phys;
5527 } else if (parent_handle < ioc->sas_hba.num_phys) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305528 sas_address = ioc->sas_hba.sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305529 max_phys = ioc->sas_hba.num_phys;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305530 } else {
5531 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305532 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305533 }
5534 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305535
Eric Moore635374e2009-03-09 01:21:12 -06005536 /* handle siblings events */
5537 for (i = 0; i < event_data->NumEntries; i++) {
5538 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305539 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
Eric Moore635374e2009-03-09 01:21:12 -06005540 "expander event\n", ioc->name));
5541 return;
5542 }
Eric Moore3cb54692010-07-08 14:44:34 -06005543 if (ioc->shost_recovery || ioc->remove_host ||
5544 ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305545 return;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305546 phy_number = event_data->StartPhyNum + i;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305547 if (phy_number >= max_phys)
5548 continue;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305549 reason_code = event_data->PHY[i].PhyStatus &
5550 MPI2_EVENT_SAS_TOPO_RC_MASK;
5551 if ((event_data->PHY[i].PhyStatus &
5552 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5553 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
Eric Moore635374e2009-03-09 01:21:12 -06005554 continue;
5555 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5556 if (!handle)
5557 continue;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305558 link_rate = event_data->PHY[i].LinkRate >> 4;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305559 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Eric Moore635374e2009-03-09 01:21:12 -06005560 switch (reason_code) {
5561 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305562
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305563 if (ioc->shost_recovery)
5564 break;
5565
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305566 if (link_rate == prev_link_rate)
5567 break;
5568
5569 mpt2sas_transport_update_links(ioc, sas_address,
5570 handle, phy_number, link_rate);
5571
Kashyap, Desaib4344272010-03-17 16:24:14 +05305572 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5573 break;
5574
5575 _scsih_check_device(ioc, handle);
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305576 break;
Eric Moore635374e2009-03-09 01:21:12 -06005577 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305578
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305579 if (ioc->shost_recovery)
5580 break;
5581
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305582 mpt2sas_transport_update_links(ioc, sas_address,
5583 handle, phy_number, link_rate);
5584
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305585 _scsih_add_device(ioc, handle, phy_number, 0);
Eric Moore635374e2009-03-09 01:21:12 -06005586 break;
5587 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305588
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305589 _scsih_device_remove_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06005590 break;
5591 }
5592 }
5593
5594 /* handle expander removal */
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305595 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5596 sas_expander)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305597 mpt2sas_expander_remove(ioc, sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06005598
5599}
5600
5601#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5602/**
5603 * _scsih_sas_device_status_change_event_debug - debug for device event
5604 * @event_data: event data payload
5605 * Context: user.
5606 *
5607 * Return nothing.
5608 */
5609static void
5610_scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5611 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5612{
5613 char *reason_str = NULL;
5614
5615 switch (event_data->ReasonCode) {
5616 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5617 reason_str = "smart data";
5618 break;
5619 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5620 reason_str = "unsupported device discovered";
5621 break;
5622 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5623 reason_str = "internal device reset";
5624 break;
5625 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5626 reason_str = "internal task abort";
5627 break;
5628 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5629 reason_str = "internal task abort set";
5630 break;
5631 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5632 reason_str = "internal clear task set";
5633 break;
5634 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5635 reason_str = "internal query task";
5636 break;
5637 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5638 reason_str = "sata init failure";
5639 break;
5640 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5641 reason_str = "internal device reset complete";
5642 break;
5643 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5644 reason_str = "internal task abort complete";
5645 break;
5646 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5647 reason_str = "internal async notification";
5648 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05305649 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5650 reason_str = "expander reduced functionality";
5651 break;
5652 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5653 reason_str = "expander reduced functionality complete";
5654 break;
Eric Moore635374e2009-03-09 01:21:12 -06005655 default:
5656 reason_str = "unknown reason";
5657 break;
5658 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305659 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305660 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5661 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5662 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5663 le16_to_cpu(event_data->TaskTag));
Eric Moore635374e2009-03-09 01:21:12 -06005664 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305665 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005666 event_data->ASC, event_data->ASCQ);
5667 printk(KERN_INFO "\n");
5668}
5669#endif
5670
5671/**
5672 * _scsih_sas_device_status_change_event - handle device status change
5673 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305674 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005675 * Context: user.
5676 *
5677 * Return nothing.
5678 */
5679static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305680_scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5681 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005682{
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305683 struct MPT2SAS_TARGET *target_priv_data;
5684 struct _sas_device *sas_device;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05305685 u64 sas_address;
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305686 unsigned long flags;
5687 Mpi2EventDataSasDeviceStatusChange_t *event_data =
Joe Lawrence00713ad2014-06-25 17:03:33 -04005688 (Mpi2EventDataSasDeviceStatusChange_t *)
5689 fw_event->event_data;
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305690
Eric Moore635374e2009-03-09 01:21:12 -06005691#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5692 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305693 _scsih_sas_device_status_change_event_debug(ioc,
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305694 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005695#endif
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305696
Kashyap, Desaiefe82a12011-01-04 11:34:17 +05305697 /* In MPI Revision K (0xC), the internal device reset complete was
5698 * implemented, so avoid setting tm_busy flag for older firmware.
5699 */
5700 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5701 return;
5702
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305703 if (event_data->ReasonCode !=
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305704 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305705 event_data->ReasonCode !=
5706 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305707 return;
5708
5709 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5710 sas_address = le64_to_cpu(event_data->SASAddress);
5711 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5712 sas_address);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305713
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305714 if (!sas_device || !sas_device->starget) {
5715 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305716 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305717 }
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305718
5719 target_priv_data = sas_device->starget->hostdata;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305720 if (!target_priv_data) {
5721 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305722 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305723 }
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305724
5725 if (event_data->ReasonCode ==
5726 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5727 target_priv_data->tm_busy = 1;
5728 else
5729 target_priv_data->tm_busy = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305730 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005731}
5732
5733#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5734/**
5735 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5736 * @ioc: per adapter object
5737 * @event_data: event data payload
5738 * Context: user.
5739 *
5740 * Return nothing.
5741 */
5742static void
5743_scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5744 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5745{
5746 char *reason_str = NULL;
5747
5748 switch (event_data->ReasonCode) {
5749 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5750 reason_str = "enclosure add";
5751 break;
5752 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5753 reason_str = "enclosure remove";
5754 break;
5755 default:
5756 reason_str = "unknown reason";
5757 break;
5758 }
5759
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305760 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
Eric Moore635374e2009-03-09 01:21:12 -06005761 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5762 " number slots(%d)\n", ioc->name, reason_str,
5763 le16_to_cpu(event_data->EnclosureHandle),
5764 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5765 le16_to_cpu(event_data->StartSlot));
5766}
5767#endif
5768
5769/**
5770 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5771 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305772 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005773 * Context: user.
5774 *
5775 * Return nothing.
5776 */
5777static void
5778_scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305779 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005780{
5781#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5782 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5783 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
Joe Lawrence00713ad2014-06-25 17:03:33 -04005784 (Mpi2EventDataSasEnclDevStatusChange_t *)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305785 fw_event->event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005786#endif
5787}
5788
5789/**
Andrew Mortona78e21d2012-02-08 12:52:22 -08005790 * _scsih_sas_broadcast_primitive_event - handle broadcast events
Eric Moore635374e2009-03-09 01:21:12 -06005791 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305792 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005793 * Context: user.
5794 *
5795 * Return nothing.
5796 */
5797static void
Andrew Mortona78e21d2012-02-08 12:52:22 -08005798_scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305799 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005800{
5801 struct scsi_cmnd *scmd;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305802 struct scsi_device *sdev;
Eric Moore635374e2009-03-09 01:21:12 -06005803 u16 smid, handle;
5804 u32 lun;
5805 struct MPT2SAS_DEVICE *sas_device_priv_data;
5806 u32 termination_count;
5807 u32 query_count;
5808 Mpi2SCSITaskManagementReply_t *mpi_reply;
Joe Lawrence00713ad2014-06-25 17:03:33 -04005809 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5810 (Mpi2EventDataSasBroadcastPrimitive_t *)
5811 fw_event->event_data;
Kashyap, Desai463217b2009-10-05 15:53:06 +05305812 u16 ioc_status;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305813 unsigned long flags;
5814 int r;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305815 u8 max_retries = 0;
5816 u8 task_abort_retries;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305817
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305818 mutex_lock(&ioc->tm_cmds.mutex);
Reddy, Sreekanthc3a634b2013-02-26 17:36:12 +05305819 pr_info(MPT2SAS_FMT
5820 "%s: enter: phy number(%d), width(%d)\n",
5821 ioc->name, __func__, event_data->PhyNum,
5822 event_data->PortWidth);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305823
5824 _scsih_block_io_all_device(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005825
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305826 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305827 mpi_reply = ioc->tm_cmds.reply;
5828broadcast_aen_retry:
5829
5830 /* sanity checks for retrying this loop */
5831 if (max_retries++ == 5) {
5832 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5833 ioc->name, __func__));
5834 goto out;
5835 } else if (max_retries > 1)
5836 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5837 ioc->name, __func__, max_retries - 1));
5838
Eric Moore635374e2009-03-09 01:21:12 -06005839 termination_count = 0;
5840 query_count = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305841 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305842 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305843 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06005844 scmd = _scsih_scsi_lookup_get(ioc, smid);
5845 if (!scmd)
5846 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305847 sdev = scmd->device;
5848 sas_device_priv_data = sdev->hostdata;
Eric Moore635374e2009-03-09 01:21:12 -06005849 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5850 continue;
5851 /* skip hidden raid components */
5852 if (sas_device_priv_data->sas_target->flags &
5853 MPT_TARGET_FLAGS_RAID_COMPONENT)
5854 continue;
5855 /* skip volumes */
5856 if (sas_device_priv_data->sas_target->flags &
5857 MPT_TARGET_FLAGS_VOLUME)
5858 continue;
5859
5860 handle = sas_device_priv_data->sas_target->handle;
5861 lun = sas_device_priv_data->lun;
5862 query_count++;
5863
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305864 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305865 goto out;
5866
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305867 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305868 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04005869 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305870 TM_MUTEX_OFF);
5871 if (r == FAILED) {
5872 sdev_printk(KERN_WARNING, sdev,
5873 "mpt2sas_scsih_issue_tm: FAILED when sending "
5874 "QUERY_TASK: scmd(%p)\n", scmd);
5875 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5876 goto broadcast_aen_retry;
5877 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05305878 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5879 & MPI2_IOCSTATUS_MASK;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305880 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5881 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5882 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5883 scmd);
5884 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5885 goto broadcast_aen_retry;
5886 }
5887
5888 /* see if IO is still owned by IOC and target */
5889 if (mpi_reply->ResponseCode ==
Eric Moore635374e2009-03-09 01:21:12 -06005890 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5891 mpi_reply->ResponseCode ==
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305892 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305893 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005894 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305895 }
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305896 task_abort_retries = 0;
5897 tm_retry:
5898 if (task_abort_retries++ == 60) {
5899 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5900 "%s: ABORT_TASK: giving up\n", ioc->name,
5901 __func__));
5902 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5903 goto broadcast_aen_retry;
5904 }
5905
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305906 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305907 goto out_no_lock;
5908
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305909 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5910 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04005911 TM_MUTEX_OFF);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305912 if (r == FAILED) {
5913 sdev_printk(KERN_WARNING, sdev,
5914 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305915 "scmd(%p)\n", scmd);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305916 goto tm_retry;
5917 }
5918
5919 if (task_abort_retries > 1)
5920 sdev_printk(KERN_WARNING, sdev,
5921 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5922 " scmd(%p)\n",
5923 task_abort_retries - 1, scmd);
5924
Eric Moore635374e2009-03-09 01:21:12 -06005925 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305926 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005927 }
Eric Moore635374e2009-03-09 01:21:12 -06005928
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305929 if (ioc->broadcast_aen_pending) {
5930 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5931 " pending AEN\n", ioc->name, __func__));
5932 ioc->broadcast_aen_pending = 0;
5933 goto broadcast_aen_retry;
5934 }
5935
5936 out:
5937 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5938 out_no_lock:
5939
5940 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06005941 "%s - exit, query_count = %d termination_count = %d\n",
5942 ioc->name, __func__, query_count, termination_count));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305943
5944 ioc->broadcast_aen_busy = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305945 if (!ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305946 _scsih_ublock_io_all_device(ioc);
5947 mutex_unlock(&ioc->tm_cmds.mutex);
Eric Moore635374e2009-03-09 01:21:12 -06005948}
5949
5950/**
5951 * _scsih_sas_discovery_event - handle discovery events
5952 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305953 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005954 * Context: user.
5955 *
5956 * Return nothing.
5957 */
5958static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305959_scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5960 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005961{
Joe Lawrence00713ad2014-06-25 17:03:33 -04005962 Mpi2EventDataSasDiscovery_t *event_data =
5963 (Mpi2EventDataSasDiscovery_t *)
5964 fw_event->event_data;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305965
Eric Moore635374e2009-03-09 01:21:12 -06005966#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5967 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305968 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005969 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5970 "start" : "stop");
5971 if (event_data->DiscoveryStatus)
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305972 printk("discovery_status(0x%08x)",
5973 le32_to_cpu(event_data->DiscoveryStatus));
Eric Moore635374e2009-03-09 01:21:12 -06005974 printk("\n");
5975 }
5976#endif
5977
5978 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05305979 !ioc->sas_hba.num_phys) {
5980 if (disable_discovery > 0 && ioc->shost_recovery) {
5981 /* Wait for the reset to complete */
5982 while (ioc->shost_recovery)
5983 ssleep(1);
5984 }
Eric Moore635374e2009-03-09 01:21:12 -06005985 _scsih_sas_host_add(ioc);
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05305986 }
Eric Moore635374e2009-03-09 01:21:12 -06005987}
5988
5989/**
5990 * _scsih_reprobe_lun - reprobing lun
5991 * @sdev: scsi device struct
5992 * @no_uld_attach: sdev->no_uld_attach flag setting
5993 *
5994 **/
5995static void
5996_scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5997{
5998 int rc;
5999
6000 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6001 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6002 sdev->no_uld_attach ? "hidding" : "exposing");
6003 rc = scsi_device_reprobe(sdev);
6004}
6005
6006/**
Eric Moore635374e2009-03-09 01:21:12 -06006007 * _scsih_sas_volume_add - add new volume
6008 * @ioc: per adapter object
6009 * @element: IR config element data
6010 * Context: user.
6011 *
6012 * Return nothing.
6013 */
6014static void
6015_scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
6016 Mpi2EventIrConfigElement_t *element)
6017{
6018 struct _raid_device *raid_device;
6019 unsigned long flags;
6020 u64 wwid;
6021 u16 handle = le16_to_cpu(element->VolDevHandle);
6022 int rc;
6023
Eric Moore635374e2009-03-09 01:21:12 -06006024 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6025 if (!wwid) {
6026 printk(MPT2SAS_ERR_FMT
6027 "failure at %s:%d/%s()!\n", ioc->name,
6028 __FILE__, __LINE__, __func__);
6029 return;
6030 }
6031
6032 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6033 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6034 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6035
6036 if (raid_device)
6037 return;
6038
6039 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6040 if (!raid_device) {
6041 printk(MPT2SAS_ERR_FMT
6042 "failure at %s:%d/%s()!\n", ioc->name,
6043 __FILE__, __LINE__, __func__);
6044 return;
6045 }
6046
6047 raid_device->id = ioc->sas_id++;
6048 raid_device->channel = RAID_CHANNEL;
6049 raid_device->handle = handle;
6050 raid_device->wwid = wwid;
6051 _scsih_raid_device_add(ioc, raid_device);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306052 if (!ioc->wait_for_discovery_to_complete) {
Eric Moore635374e2009-03-09 01:21:12 -06006053 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6054 raid_device->id, 0);
6055 if (rc)
6056 _scsih_raid_device_remove(ioc, raid_device);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306057 } else {
6058 spin_lock_irqsave(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06006059 _scsih_determine_boot_device(ioc, raid_device, 1);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306060 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6061 }
Eric Moore635374e2009-03-09 01:21:12 -06006062}
6063
6064/**
6065 * _scsih_sas_volume_delete - delete volume
6066 * @ioc: per adapter object
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306067 * @handle: volume device handle
Eric Moore635374e2009-03-09 01:21:12 -06006068 * Context: user.
6069 *
6070 * Return nothing.
6071 */
6072static void
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306073_scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Eric Moore635374e2009-03-09 01:21:12 -06006074{
6075 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06006076 unsigned long flags;
6077 struct MPT2SAS_TARGET *sas_target_priv_data;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306078 struct scsi_target *starget = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006079
Eric Moore635374e2009-03-09 01:21:12 -06006080 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6081 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306082 if (raid_device) {
6083 if (raid_device->starget) {
6084 starget = raid_device->starget;
6085 sas_target_priv_data = starget->hostdata;
6086 sas_target_priv_data->deleted = 1;
6087 }
6088 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6089 "(0x%016llx)\n", ioc->name, raid_device->handle,
6090 (unsigned long long) raid_device->wwid);
6091 list_del(&raid_device->list);
6092 kfree(raid_device);
Eric Moore635374e2009-03-09 01:21:12 -06006093 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306094 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6095 if (starget)
6096 scsi_remove_target(&starget->dev);
Eric Moore635374e2009-03-09 01:21:12 -06006097}
6098
6099/**
6100 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6101 * @ioc: per adapter object
6102 * @element: IR config element data
6103 * Context: user.
6104 *
6105 * Return nothing.
6106 */
6107static void
6108_scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6109 Mpi2EventIrConfigElement_t *element)
6110{
6111 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306112 struct scsi_target *starget = NULL;
6113 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06006114 unsigned long flags;
6115 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6116
6117 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6118 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306119 if (sas_device) {
6120 sas_device->volume_handle = 0;
6121 sas_device->volume_wwid = 0;
6122 clear_bit(handle, ioc->pd_handles);
6123 if (sas_device->starget && sas_device->starget->hostdata) {
6124 starget = sas_device->starget;
6125 sas_target_priv_data = starget->hostdata;
6126 sas_target_priv_data->flags &=
6127 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6128 }
6129 }
Eric Moore635374e2009-03-09 01:21:12 -06006130 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6131 if (!sas_device)
6132 return;
6133
6134 /* exposing raid component */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306135 if (starget)
6136 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
Eric Moore635374e2009-03-09 01:21:12 -06006137}
6138
6139/**
6140 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6141 * @ioc: per adapter object
6142 * @element: IR config element data
6143 * Context: user.
6144 *
6145 * Return nothing.
6146 */
6147static void
6148_scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6149 Mpi2EventIrConfigElement_t *element)
6150{
6151 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306152 struct scsi_target *starget = NULL;
6153 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06006154 unsigned long flags;
6155 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306156 u16 volume_handle = 0;
6157 u64 volume_wwid = 0;
6158
6159 mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle);
6160 if (volume_handle)
6161 mpt2sas_config_get_volume_wwid(ioc, volume_handle,
6162 &volume_wwid);
Eric Moore635374e2009-03-09 01:21:12 -06006163
6164 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6165 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306166 if (sas_device) {
6167 set_bit(handle, ioc->pd_handles);
6168 if (sas_device->starget && sas_device->starget->hostdata) {
6169 starget = sas_device->starget;
6170 sas_target_priv_data = starget->hostdata;
6171 sas_target_priv_data->flags |=
6172 MPT_TARGET_FLAGS_RAID_COMPONENT;
6173 sas_device->volume_handle = volume_handle;
6174 sas_device->volume_wwid = volume_wwid;
6175 }
6176 }
Eric Moore635374e2009-03-09 01:21:12 -06006177 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6178 if (!sas_device)
6179 return;
6180
6181 /* hiding raid component */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306182 if (starget)
6183 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
Eric Moore635374e2009-03-09 01:21:12 -06006184}
6185
6186/**
6187 * _scsih_sas_pd_delete - delete pd component
6188 * @ioc: per adapter object
6189 * @element: IR config element data
6190 * Context: user.
6191 *
6192 * Return nothing.
6193 */
6194static void
6195_scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6196 Mpi2EventIrConfigElement_t *element)
6197{
Eric Moore635374e2009-03-09 01:21:12 -06006198 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6199
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306200 _scsih_device_remove_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006201}
6202
6203/**
6204 * _scsih_sas_pd_add - remove pd component
6205 * @ioc: per adapter object
6206 * @element: IR config element data
6207 * Context: user.
6208 *
6209 * Return nothing.
6210 */
6211static void
6212_scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6213 Mpi2EventIrConfigElement_t *element)
6214{
6215 struct _sas_device *sas_device;
6216 unsigned long flags;
6217 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306218 Mpi2ConfigReply_t mpi_reply;
6219 Mpi2SasDevicePage0_t sas_device_pg0;
6220 u32 ioc_status;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306221 u64 sas_address;
6222 u16 parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006223
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306224 set_bit(handle, ioc->pd_handles);
6225
Eric Moore635374e2009-03-09 01:21:12 -06006226 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6227 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6228 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306229 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306230 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306231
6232 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6233 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6234 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6235 ioc->name, __FILE__, __LINE__, __func__);
6236 return;
6237 }
6238
6239 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6240 MPI2_IOCSTATUS_MASK;
6241 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6242 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6243 ioc->name, __FILE__, __LINE__, __func__);
6244 return;
6245 }
6246
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306247 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6248 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6249 mpt2sas_transport_update_links(ioc, sas_address, handle,
6250 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306251
6252 _scsih_add_device(ioc, handle, 0, 1);
Eric Moore635374e2009-03-09 01:21:12 -06006253}
6254
6255#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6256/**
6257 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6258 * @ioc: per adapter object
6259 * @event_data: event data payload
6260 * Context: user.
6261 *
6262 * Return nothing.
6263 */
6264static void
6265_scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6266 Mpi2EventDataIrConfigChangeList_t *event_data)
6267{
6268 Mpi2EventIrConfigElement_t *element;
6269 u8 element_type;
6270 int i;
6271 char *reason_str = NULL, *element_str = NULL;
6272
6273 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6274
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306275 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
Eric Moore635374e2009-03-09 01:21:12 -06006276 ioc->name, (le32_to_cpu(event_data->Flags) &
6277 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6278 "foreign" : "native", event_data->NumElements);
6279 for (i = 0; i < event_data->NumElements; i++, element++) {
6280 switch (element->ReasonCode) {
6281 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6282 reason_str = "add";
6283 break;
6284 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6285 reason_str = "remove";
6286 break;
6287 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6288 reason_str = "no change";
6289 break;
6290 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6291 reason_str = "hide";
6292 break;
6293 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6294 reason_str = "unhide";
6295 break;
6296 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6297 reason_str = "volume_created";
6298 break;
6299 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6300 reason_str = "volume_deleted";
6301 break;
6302 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6303 reason_str = "pd_created";
6304 break;
6305 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6306 reason_str = "pd_deleted";
6307 break;
6308 default:
6309 reason_str = "unknown reason";
6310 break;
6311 }
6312 element_type = le16_to_cpu(element->ElementFlags) &
6313 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6314 switch (element_type) {
6315 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6316 element_str = "volume";
6317 break;
6318 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6319 element_str = "phys disk";
6320 break;
6321 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6322 element_str = "hot spare";
6323 break;
6324 default:
6325 element_str = "unknown element";
6326 break;
6327 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306328 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
Eric Moore635374e2009-03-09 01:21:12 -06006329 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6330 reason_str, le16_to_cpu(element->VolDevHandle),
6331 le16_to_cpu(element->PhysDiskDevHandle),
6332 element->PhysDiskNum);
6333 }
6334}
6335#endif
6336
6337/**
6338 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6339 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306340 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006341 * Context: user.
6342 *
6343 * Return nothing.
6344 */
6345static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306346_scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6347 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006348{
6349 Mpi2EventIrConfigElement_t *element;
6350 int i;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306351 u8 foreign_config;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006352 Mpi2EventDataIrConfigChangeList_t *event_data =
6353 (Mpi2EventDataIrConfigChangeList_t *)
6354 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006355
6356#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306357 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6358 && !ioc->hide_ir_msg)
Eric Moore635374e2009-03-09 01:21:12 -06006359 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6360
6361#endif
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306362
6363 if (ioc->shost_recovery)
6364 return;
6365
Kashyap, Desai62727a72009-08-07 19:35:18 +05306366 foreign_config = (le32_to_cpu(event_data->Flags) &
6367 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
Eric Moore635374e2009-03-09 01:21:12 -06006368
6369 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6370 for (i = 0; i < event_data->NumElements; i++, element++) {
6371
6372 switch (element->ReasonCode) {
6373 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6374 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306375 if (!foreign_config)
6376 _scsih_sas_volume_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006377 break;
6378 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6379 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306380 if (!foreign_config)
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306381 _scsih_sas_volume_delete(ioc,
6382 le16_to_cpu(element->VolDevHandle));
Eric Moore635374e2009-03-09 01:21:12 -06006383 break;
6384 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306385 if (!ioc->is_warpdrive)
6386 _scsih_sas_pd_hide(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006387 break;
6388 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306389 if (!ioc->is_warpdrive)
6390 _scsih_sas_pd_expose(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006391 break;
6392 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306393 if (!ioc->is_warpdrive)
6394 _scsih_sas_pd_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006395 break;
6396 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306397 if (!ioc->is_warpdrive)
6398 _scsih_sas_pd_delete(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006399 break;
6400 }
6401 }
6402}
6403
6404/**
6405 * _scsih_sas_ir_volume_event - IR volume event
6406 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306407 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006408 * Context: user.
6409 *
6410 * Return nothing.
6411 */
6412static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306413_scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6414 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006415{
6416 u64 wwid;
6417 unsigned long flags;
6418 struct _raid_device *raid_device;
6419 u16 handle;
6420 u32 state;
6421 int rc;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006422 Mpi2EventDataIrVolume_t *event_data =
6423 (Mpi2EventDataIrVolume_t *)
6424 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006425
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306426 if (ioc->shost_recovery)
6427 return;
6428
Eric Moore635374e2009-03-09 01:21:12 -06006429 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6430 return;
6431
6432 handle = le16_to_cpu(event_data->VolDevHandle);
6433 state = le32_to_cpu(event_data->NewValue);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306434 if (!ioc->hide_ir_msg)
6435 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6436 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6437 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006438
Eric Moore635374e2009-03-09 01:21:12 -06006439 switch (state) {
6440 case MPI2_RAID_VOL_STATE_MISSING:
6441 case MPI2_RAID_VOL_STATE_FAILED:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306442 _scsih_sas_volume_delete(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006443 break;
6444
6445 case MPI2_RAID_VOL_STATE_ONLINE:
6446 case MPI2_RAID_VOL_STATE_DEGRADED:
6447 case MPI2_RAID_VOL_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306448
6449 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6450 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6451 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6452
Eric Moore635374e2009-03-09 01:21:12 -06006453 if (raid_device)
6454 break;
6455
6456 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6457 if (!wwid) {
6458 printk(MPT2SAS_ERR_FMT
6459 "failure at %s:%d/%s()!\n", ioc->name,
6460 __FILE__, __LINE__, __func__);
6461 break;
6462 }
6463
6464 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6465 if (!raid_device) {
6466 printk(MPT2SAS_ERR_FMT
6467 "failure at %s:%d/%s()!\n", ioc->name,
6468 __FILE__, __LINE__, __func__);
6469 break;
6470 }
6471
6472 raid_device->id = ioc->sas_id++;
6473 raid_device->channel = RAID_CHANNEL;
6474 raid_device->handle = handle;
6475 raid_device->wwid = wwid;
6476 _scsih_raid_device_add(ioc, raid_device);
6477 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6478 raid_device->id, 0);
6479 if (rc)
6480 _scsih_raid_device_remove(ioc, raid_device);
6481 break;
6482
6483 case MPI2_RAID_VOL_STATE_INITIALIZING:
6484 default:
6485 break;
6486 }
6487}
6488
6489/**
6490 * _scsih_sas_ir_physical_disk_event - PD event
6491 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306492 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006493 * Context: user.
6494 *
6495 * Return nothing.
6496 */
6497static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306498_scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6499 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006500{
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306501 u16 handle, parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006502 u32 state;
6503 struct _sas_device *sas_device;
6504 unsigned long flags;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306505 Mpi2ConfigReply_t mpi_reply;
6506 Mpi2SasDevicePage0_t sas_device_pg0;
6507 u32 ioc_status;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006508 Mpi2EventDataIrPhysicalDisk_t *event_data =
6509 (Mpi2EventDataIrPhysicalDisk_t *)
6510 fw_event->event_data;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306511 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006512
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306513 if (ioc->shost_recovery)
6514 return;
6515
Eric Moore635374e2009-03-09 01:21:12 -06006516 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6517 return;
6518
6519 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6520 state = le32_to_cpu(event_data->NewValue);
6521
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306522 if (!ioc->hide_ir_msg)
6523 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6524 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6525 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006526
Eric Moore635374e2009-03-09 01:21:12 -06006527 switch (state) {
Eric Moore635374e2009-03-09 01:21:12 -06006528 case MPI2_RAID_PD_STATE_ONLINE:
6529 case MPI2_RAID_PD_STATE_DEGRADED:
6530 case MPI2_RAID_PD_STATE_REBUILDING:
6531 case MPI2_RAID_PD_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306532 case MPI2_RAID_PD_STATE_HOT_SPARE:
6533
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306534 if (!ioc->is_warpdrive)
6535 set_bit(handle, ioc->pd_handles);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306536
6537 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6538 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6539 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6540
6541 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306542 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306543
6544 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6545 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6546 handle))) {
6547 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6548 ioc->name, __FILE__, __LINE__, __func__);
6549 return;
6550 }
6551
6552 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6553 MPI2_IOCSTATUS_MASK;
6554 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6555 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6556 ioc->name, __FILE__, __LINE__, __func__);
6557 return;
6558 }
6559
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306560 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6561 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6562 mpt2sas_transport_update_links(ioc, sas_address, handle,
6563 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306564
6565 _scsih_add_device(ioc, handle, 0, 1);
6566
Eric Moore635374e2009-03-09 01:21:12 -06006567 break;
6568
Kashyap, Desai62727a72009-08-07 19:35:18 +05306569 case MPI2_RAID_PD_STATE_OFFLINE:
Eric Moore635374e2009-03-09 01:21:12 -06006570 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6571 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
Eric Moore635374e2009-03-09 01:21:12 -06006572 default:
6573 break;
6574 }
6575}
6576
6577#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6578/**
6579 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6580 * @ioc: per adapter object
6581 * @event_data: event data payload
6582 * Context: user.
6583 *
6584 * Return nothing.
6585 */
6586static void
6587_scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6588 Mpi2EventDataIrOperationStatus_t *event_data)
6589{
6590 char *reason_str = NULL;
6591
6592 switch (event_data->RAIDOperation) {
6593 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6594 reason_str = "resync";
6595 break;
6596 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6597 reason_str = "online capacity expansion";
6598 break;
6599 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6600 reason_str = "consistency check";
6601 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306602 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6603 reason_str = "background init";
6604 break;
6605 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6606 reason_str = "make data consistent";
Eric Moore635374e2009-03-09 01:21:12 -06006607 break;
6608 }
6609
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306610 if (!reason_str)
6611 return;
6612
Eric Moore635374e2009-03-09 01:21:12 -06006613 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6614 "\thandle(0x%04x), percent complete(%d)\n",
6615 ioc->name, reason_str,
6616 le16_to_cpu(event_data->VolDevHandle),
6617 event_data->PercentComplete);
6618}
6619#endif
6620
6621/**
6622 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6623 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306624 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006625 * Context: user.
6626 *
6627 * Return nothing.
6628 */
6629static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306630_scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6631 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006632{
Joe Lawrence00713ad2014-06-25 17:03:33 -04006633 Mpi2EventDataIrOperationStatus_t *event_data =
6634 (Mpi2EventDataIrOperationStatus_t *)
6635 fw_event->event_data;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306636 static struct _raid_device *raid_device;
6637 unsigned long flags;
6638 u16 handle;
6639
Eric Moore635374e2009-03-09 01:21:12 -06006640#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306641 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6642 && !ioc->hide_ir_msg)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306643 _scsih_sas_ir_operation_status_event_debug(ioc,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306644 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06006645#endif
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306646
6647 /* code added for raid transport support */
6648 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6649
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306650 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306651 handle = le16_to_cpu(event_data->VolDevHandle);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306652 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306653 if (raid_device)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306654 raid_device->percent_complete =
6655 event_data->PercentComplete;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306656 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306657 }
Eric Moore635374e2009-03-09 01:21:12 -06006658}
6659
6660/**
Kashyap, Desai14695852010-03-30 10:52:44 +05306661 * _scsih_prep_device_scan - initialize parameters prior to device scan
6662 * @ioc: per adapter object
6663 *
6664 * Set the deleted flag prior to device scan. If the device is found during
6665 * the scan, then we clear the deleted flag.
6666 */
6667static void
6668_scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6669{
6670 struct MPT2SAS_DEVICE *sas_device_priv_data;
6671 struct scsi_device *sdev;
6672
6673 shost_for_each_device(sdev, ioc->shost) {
6674 sas_device_priv_data = sdev->hostdata;
6675 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6676 sas_device_priv_data->sas_target->deleted = 1;
6677 }
6678}
6679
6680/**
Eric Moore635374e2009-03-09 01:21:12 -06006681 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6682 * @ioc: per adapter object
6683 * @sas_address: sas address
6684 * @slot: enclosure slot id
6685 * @handle: device handle
6686 *
6687 * After host reset, find out whether devices are still responding.
6688 * Used in _scsi_remove_unresponsive_sas_devices.
6689 *
6690 * Return nothing.
6691 */
6692static void
6693_scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6694 u16 slot, u16 handle)
6695{
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306696 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006697 struct scsi_target *starget;
6698 struct _sas_device *sas_device;
6699 unsigned long flags;
6700
6701 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6702 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6703 if (sas_device->sas_address == sas_address &&
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306704 sas_device->slot == slot) {
Eric Moore635374e2009-03-09 01:21:12 -06006705 sas_device->responding = 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05306706 starget = sas_device->starget;
Kashyap, Desai14695852010-03-30 10:52:44 +05306707 if (starget && starget->hostdata) {
6708 sas_target_priv_data = starget->hostdata;
6709 sas_target_priv_data->tm_busy = 0;
6710 sas_target_priv_data->deleted = 0;
6711 } else
6712 sas_target_priv_data = NULL;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306713 if (starget)
6714 starget_printk(KERN_INFO, starget,
6715 "handle(0x%04x), sas_addr(0x%016llx), "
6716 "enclosure logical id(0x%016llx), "
6717 "slot(%d)\n", handle,
6718 (unsigned long long)sas_device->sas_address,
6719 (unsigned long long)
6720 sas_device->enclosure_logical_id,
6721 sas_device->slot);
Eric Moore635374e2009-03-09 01:21:12 -06006722 if (sas_device->handle == handle)
6723 goto out;
6724 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6725 sas_device->handle);
6726 sas_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306727 if (sas_target_priv_data)
6728 sas_target_priv_data->handle = handle;
Eric Moore635374e2009-03-09 01:21:12 -06006729 goto out;
6730 }
6731 }
6732 out:
6733 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6734}
6735
6736/**
6737 * _scsih_search_responding_sas_devices -
6738 * @ioc: per adapter object
6739 *
6740 * After host reset, find out whether devices are still responding.
6741 * If not remove.
6742 *
6743 * Return nothing.
6744 */
6745static void
6746_scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6747{
6748 Mpi2SasDevicePage0_t sas_device_pg0;
6749 Mpi2ConfigReply_t mpi_reply;
6750 u16 ioc_status;
6751 __le64 sas_address;
6752 u16 handle;
6753 u32 device_info;
6754 u16 slot;
6755
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306756 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006757
6758 if (list_empty(&ioc->sas_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306759 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006760
6761 handle = 0xFFFF;
6762 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6763 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6764 handle))) {
6765 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6766 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306767 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006768 break;
6769 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6770 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6771 if (!(_scsih_is_end_device(device_info)))
6772 continue;
6773 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6774 slot = le16_to_cpu(sas_device_pg0.Slot);
6775 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6776 handle);
6777 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306778out:
6779 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6780 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006781}
6782
6783/**
6784 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6785 * @ioc: per adapter object
6786 * @wwid: world wide identifier for raid volume
6787 * @handle: device handle
6788 *
6789 * After host reset, find out whether devices are still responding.
6790 * Used in _scsi_remove_unresponsive_raid_devices.
6791 *
6792 * Return nothing.
6793 */
6794static void
6795_scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6796 u16 handle)
6797{
6798 struct MPT2SAS_TARGET *sas_target_priv_data;
6799 struct scsi_target *starget;
6800 struct _raid_device *raid_device;
6801 unsigned long flags;
6802
6803 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6804 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6805 if (raid_device->wwid == wwid && raid_device->starget) {
Kashyap, Desai14695852010-03-30 10:52:44 +05306806 starget = raid_device->starget;
6807 if (starget && starget->hostdata) {
6808 sas_target_priv_data = starget->hostdata;
6809 sas_target_priv_data->deleted = 0;
6810 } else
6811 sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006812 raid_device->responding = 1;
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306813 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06006814 starget_printk(KERN_INFO, raid_device->starget,
6815 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6816 (unsigned long long)raid_device->wwid);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306817 /*
6818 * WARPDRIVE: The handles of the PDs might have changed
6819 * across the host reset so re-initialize the
6820 * required data for Direct IO
6821 */
6822 _scsih_init_warpdrive_properties(ioc, raid_device);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306823 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6824 if (raid_device->handle == handle) {
6825 spin_unlock_irqrestore(&ioc->raid_device_lock,
6826 flags);
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306827 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306828 }
Eric Moore635374e2009-03-09 01:21:12 -06006829 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6830 raid_device->handle);
6831 raid_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306832 if (sas_target_priv_data)
6833 sas_target_priv_data->handle = handle;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306834 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306835 return;
Eric Moore635374e2009-03-09 01:21:12 -06006836 }
6837 }
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306838
Eric Moore635374e2009-03-09 01:21:12 -06006839 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6840}
6841
6842/**
6843 * _scsih_search_responding_raid_devices -
6844 * @ioc: per adapter object
6845 *
6846 * After host reset, find out whether devices are still responding.
6847 * If not remove.
6848 *
6849 * Return nothing.
6850 */
6851static void
6852_scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6853{
6854 Mpi2RaidVolPage1_t volume_pg1;
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306855 Mpi2RaidVolPage0_t volume_pg0;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306856 Mpi2RaidPhysDiskPage0_t pd_pg0;
Eric Moore635374e2009-03-09 01:21:12 -06006857 Mpi2ConfigReply_t mpi_reply;
6858 u16 ioc_status;
6859 u16 handle;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306860 u8 phys_disk_num;
Eric Moore635374e2009-03-09 01:21:12 -06006861
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306862 if (!ioc->ir_firmware)
6863 return;
6864
6865 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6866 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006867
6868 if (list_empty(&ioc->raid_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306869 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006870
6871 handle = 0xFFFF;
6872 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6873 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6874 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6875 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306876 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006877 break;
6878 handle = le16_to_cpu(volume_pg1.DevHandle);
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306879
6880 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6881 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6882 sizeof(Mpi2RaidVolPage0_t)))
6883 continue;
6884
6885 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6886 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6887 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6888 _scsih_mark_responding_raid_device(ioc,
6889 le64_to_cpu(volume_pg1.WWID), handle);
Eric Moore635374e2009-03-09 01:21:12 -06006890 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306891
6892 /* refresh the pd_handles */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306893 if (!ioc->is_warpdrive) {
6894 phys_disk_num = 0xFF;
6895 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6896 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6897 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6898 phys_disk_num))) {
6899 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6900 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306901 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306902 break;
6903 phys_disk_num = pd_pg0.PhysDiskNum;
6904 handle = le16_to_cpu(pd_pg0.DevHandle);
6905 set_bit(handle, ioc->pd_handles);
6906 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306907 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306908out:
6909 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6910 "complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006911}
6912
6913/**
6914 * _scsih_mark_responding_expander - mark a expander as responding
6915 * @ioc: per adapter object
6916 * @sas_address: sas address
6917 * @handle:
6918 *
6919 * After host reset, find out whether devices are still responding.
6920 * Used in _scsi_remove_unresponsive_expanders.
6921 *
6922 * Return nothing.
6923 */
6924static void
6925_scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6926 u16 handle)
6927{
6928 struct _sas_node *sas_expander;
6929 unsigned long flags;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306930 int i;
Eric Moore635374e2009-03-09 01:21:12 -06006931
6932 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6933 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306934 if (sas_expander->sas_address != sas_address)
6935 continue;
6936 sas_expander->responding = 1;
6937 if (sas_expander->handle == handle)
Eric Moore635374e2009-03-09 01:21:12 -06006938 goto out;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306939 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6940 " from(0x%04x) to (0x%04x)!!!\n",
6941 (unsigned long long)sas_expander->sas_address,
6942 sas_expander->handle, handle);
6943 sas_expander->handle = handle;
6944 for (i = 0 ; i < sas_expander->num_phys ; i++)
6945 sas_expander->phy[i].handle = handle;
6946 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006947 }
6948 out:
6949 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6950}
6951
6952/**
6953 * _scsih_search_responding_expanders -
6954 * @ioc: per adapter object
6955 *
6956 * After host reset, find out whether devices are still responding.
6957 * If not remove.
6958 *
6959 * Return nothing.
6960 */
6961static void
6962_scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6963{
6964 Mpi2ExpanderPage0_t expander_pg0;
6965 Mpi2ConfigReply_t mpi_reply;
6966 u16 ioc_status;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05306967 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006968 u16 handle;
6969
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306970 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006971
6972 if (list_empty(&ioc->sas_expander_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306973 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006974
6975 handle = 0xFFFF;
6976 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6977 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6978
6979 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6980 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306981 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006982 break;
6983
6984 handle = le16_to_cpu(expander_pg0.DevHandle);
6985 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6986 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6987 "sas_addr(0x%016llx)\n", handle,
6988 (unsigned long long)sas_address);
6989 _scsih_mark_responding_expander(ioc, sas_address, handle);
6990 }
6991
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306992 out:
6993 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006994}
6995
6996/**
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05306997 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
Eric Moore635374e2009-03-09 01:21:12 -06006998 * @ioc: per adapter object
6999 *
7000 * Return nothing.
7001 */
7002static void
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307003_scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06007004{
7005 struct _sas_device *sas_device, *sas_device_next;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307006 struct _sas_node *sas_expander, *sas_expander_next;
Eric Moore635374e2009-03-09 01:21:12 -06007007 struct _raid_device *raid_device, *raid_device_next;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307008 struct list_head tmp_list;
7009 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06007010
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307011 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
7012 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06007013
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307014 /* removing unresponding end devices */
7015 printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n",
7016 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06007017 list_for_each_entry_safe(sas_device, sas_device_next,
7018 &ioc->sas_device_list, list) {
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307019 if (!sas_device->responding)
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05307020 mpt2sas_device_remove_by_sas_address(ioc,
7021 sas_device->sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307022 else
Eric Moore635374e2009-03-09 01:21:12 -06007023 sas_device->responding = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007024 }
7025
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307026 /* removing unresponding volumes */
7027 if (ioc->ir_firmware) {
7028 printk(MPT2SAS_INFO_FMT "removing unresponding devices: "
7029 "volumes\n", ioc->name);
7030 list_for_each_entry_safe(raid_device, raid_device_next,
7031 &ioc->raid_device_list, list) {
7032 if (!raid_device->responding)
7033 _scsih_sas_volume_delete(ioc,
7034 raid_device->handle);
7035 else
7036 raid_device->responding = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007037 }
Eric Moore635374e2009-03-09 01:21:12 -06007038 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307039 /* removing unresponding expanders */
7040 printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n",
7041 ioc->name);
7042 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7043 INIT_LIST_HEAD(&tmp_list);
7044 list_for_each_entry_safe(sas_expander, sas_expander_next,
7045 &ioc->sas_expander_list, list) {
7046 if (!sas_expander->responding)
7047 list_move_tail(&sas_expander->list, &tmp_list);
7048 else
Eric Moore635374e2009-03-09 01:21:12 -06007049 sas_expander->responding = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307050 }
7051 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7052 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7053 list) {
7054 list_del(&sas_expander->list);
7055 _scsih_expander_node_remove(ioc, sas_expander);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307056 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307057 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
7058 ioc->name);
7059 /* unblock devices */
7060 _scsih_ublock_io_all_device(ioc);
7061}
7062
7063static void
7064_scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
7065 struct _sas_node *sas_expander, u16 handle)
7066{
7067 Mpi2ExpanderPage1_t expander_pg1;
7068 Mpi2ConfigReply_t mpi_reply;
7069 int i;
7070
7071 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7072 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
7073 &expander_pg1, i, handle))) {
7074 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7075 ioc->name, __FILE__, __LINE__, __func__);
7076 return;
7077 }
7078
7079 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
7080 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7081 expander_pg1.NegotiatedLinkRate >> 4);
7082 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307083}
7084
7085/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307086 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307087 * @ioc: per adapter object
7088 *
7089 * Return nothing.
7090 */
7091static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307092_scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307093{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307094 Mpi2ExpanderPage0_t expander_pg0;
7095 Mpi2SasDevicePage0_t sas_device_pg0;
7096 Mpi2RaidVolPage1_t volume_pg1;
7097 Mpi2RaidVolPage0_t volume_pg0;
7098 Mpi2RaidPhysDiskPage0_t pd_pg0;
7099 Mpi2EventIrConfigElement_t element;
7100 Mpi2ConfigReply_t mpi_reply;
7101 u8 phys_disk_num;
7102 u16 ioc_status;
7103 u16 handle, parent_handle;
7104 u64 sas_address;
7105 struct _sas_device *sas_device;
7106 struct _sas_node *expander_device;
7107 static struct _raid_device *raid_device;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307108 u8 retry_count;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307109 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307110
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307111 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307112
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307113 _scsih_sas_host_refresh(ioc);
7114
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307115 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n",
7116 ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307117 /* expanders */
7118 handle = 0xFFFF;
7119 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7120 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7121 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7122 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307123 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7124 printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: "
7125 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7126 ioc->name, ioc_status,
7127 le32_to_cpu(mpi_reply.IOCLogInfo));
7128 break;
7129 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307130 handle = le16_to_cpu(expander_pg0.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307131 spin_lock_irqsave(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307132 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7133 ioc, le64_to_cpu(expander_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307134 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307135 if (expander_device)
7136 _scsih_refresh_expander_links(ioc, expander_device,
7137 handle);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307138 else {
7139 printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: "
7140 "handle (0x%04x), sas_addr(0x%016llx)\n",
7141 ioc->name, handle, (unsigned long long)
7142 le64_to_cpu(expander_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307143 _scsih_expander_add(ioc, handle);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307144 printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: "
7145 "handle (0x%04x), sas_addr(0x%016llx)\n",
7146 ioc->name, handle, (unsigned long long)
7147 le64_to_cpu(expander_pg0.SASAddress));
7148 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307149 }
7150
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307151 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n",
7152 ioc->name);
7153
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307154 if (!ioc->ir_firmware)
7155 goto skip_to_sas;
7156
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307157 printk(MPT2SAS_INFO_FMT "\tscan devices phys disk start\n", ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307158 /* phys disk */
7159 phys_disk_num = 0xFF;
7160 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7161 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7162 phys_disk_num))) {
7163 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7164 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307165 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7166 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:"
7167 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7168 ioc->name, ioc_status,
7169 le32_to_cpu(mpi_reply.IOCLogInfo));
7170 break;
7171 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307172 phys_disk_num = pd_pg0.PhysDiskNum;
7173 handle = le16_to_cpu(pd_pg0.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307174 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307175 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307176 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307177 if (sas_device)
7178 continue;
7179 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7180 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7181 handle) != 0)
7182 continue;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307183 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7184 MPI2_IOCSTATUS_MASK;
7185 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7186 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan "
7187 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7188 ioc->name, ioc_status,
7189 le32_to_cpu(mpi_reply.IOCLogInfo));
7190 break;
7191 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307192 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7193 if (!_scsih_get_sas_address(ioc, parent_handle,
7194 &sas_address)) {
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307195 printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: "
7196 " handle (0x%04x), sas_addr(0x%016llx)\n",
7197 ioc->name, handle, (unsigned long long)
7198 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307199 mpt2sas_transport_update_links(ioc, sas_address,
7200 handle, sas_device_pg0.PhyNum,
7201 MPI2_SAS_NEG_LINK_RATE_1_5);
7202 set_bit(handle, ioc->pd_handles);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307203 retry_count = 0;
7204 /* This will retry adding the end device.
7205 * _scsih_add_device() will decide on retries and
7206 * return "1" when it should be retried
7207 */
7208 while (_scsih_add_device(ioc, handle, retry_count++,
7209 1)) {
7210 ssleep(1);
7211 }
7212 printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: "
7213 " handle (0x%04x), sas_addr(0x%016llx)\n",
7214 ioc->name, handle, (unsigned long long)
7215 le64_to_cpu(sas_device_pg0.SASAddress));
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307216 }
7217 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307218
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307219 printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n",
7220 ioc->name);
7221
7222 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes start\n", ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307223 /* volumes */
7224 handle = 0xFFFF;
7225 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7226 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7227 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7228 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307229 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7230 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7231 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7232 ioc->name, ioc_status,
7233 le32_to_cpu(mpi_reply.IOCLogInfo));
7234 break;
7235 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307236 handle = le16_to_cpu(volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307237 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307238 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7239 le64_to_cpu(volume_pg1.WWID));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307240 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307241 if (raid_device)
7242 continue;
7243 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7244 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7245 sizeof(Mpi2RaidVolPage0_t)))
7246 continue;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307247 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7248 MPI2_IOCSTATUS_MASK;
7249 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7250 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7251 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7252 ioc->name, ioc_status,
7253 le32_to_cpu(mpi_reply.IOCLogInfo));
7254 break;
7255 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307256 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7257 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7258 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7259 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7260 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7261 element.VolDevHandle = volume_pg1.DevHandle;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307262 printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: "
7263 " handle (0x%04x)\n", ioc->name,
7264 volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307265 _scsih_sas_volume_add(ioc, &element);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307266 printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: "
7267 " handle (0x%04x)\n", ioc->name,
7268 volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307269 }
7270 }
7271
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307272 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n",
7273 ioc->name);
7274
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307275 skip_to_sas:
7276
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307277 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n",
7278 ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307279 /* sas devices */
7280 handle = 0xFFFF;
7281 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7282 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7283 handle))) {
7284 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7285 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307286 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7287 printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:"
7288 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7289 ioc->name, ioc_status,
7290 le32_to_cpu(mpi_reply.IOCLogInfo));
7291 break;
7292 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307293 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7294 if (!(_scsih_is_end_device(
7295 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7296 continue;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307297 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307298 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7299 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307300 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307301 if (sas_device)
7302 continue;
7303 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7304 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307305 printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: "
7306 "handle (0x%04x), sas_addr(0x%016llx)\n",
7307 ioc->name, handle, (unsigned long long)
7308 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307309 mpt2sas_transport_update_links(ioc, sas_address, handle,
7310 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307311 retry_count = 0;
7312 /* This will retry adding the end device.
7313 * _scsih_add_device() will decide on retries and
7314 * return "1" when it should be retried
7315 */
7316 while (_scsih_add_device(ioc, handle, retry_count++,
7317 0)) {
7318 ssleep(1);
7319 }
7320 printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: "
7321 "handle (0x%04x), sas_addr(0x%016llx)\n",
7322 ioc->name, handle, (unsigned long long)
7323 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307324 }
7325 }
7326
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307327 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n",
7328 ioc->name);
7329
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307330 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307331}
7332
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307333
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307334/**
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307335 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7336 * @ioc: per adapter object
7337 * @reset_phase: phase
7338 *
7339 * The handler for doing any required cleanup or initialization.
7340 *
7341 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7342 * MPT2_IOC_DONE_RESET
7343 *
7344 * Return nothing.
7345 */
7346void
7347mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7348{
7349 switch (reset_phase) {
7350 case MPT2_IOC_PRE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307351 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307352 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307353 break;
7354 case MPT2_IOC_AFTER_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307355 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307356 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307357 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7358 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7359 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7360 complete(&ioc->scsih_cmds.done);
7361 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307362 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7363 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7364 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7365 complete(&ioc->tm_cmds.done);
7366 }
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307367 _scsih_fw_event_cleanup_queue(ioc);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307368 _scsih_flush_running_cmds(ioc);
7369 break;
7370 case MPT2_IOC_DONE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307371 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307372 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307373 _scsih_sas_host_refresh(ioc);
Kashyap, Desai14695852010-03-30 10:52:44 +05307374 _scsih_prep_device_scan(ioc);
7375 _scsih_search_responding_sas_devices(ioc);
7376 _scsih_search_responding_raid_devices(ioc);
7377 _scsih_search_responding_expanders(ioc);
sreekanth.reddy@lsi.com14aa7f72012-07-17 15:56:13 +05307378 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7379 !ioc->sas_hba.num_phys)) {
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307380 _scsih_prep_device_scan(ioc);
7381 _scsih_search_responding_sas_devices(ioc);
7382 _scsih_search_responding_raid_devices(ioc);
7383 _scsih_search_responding_expanders(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307384 _scsih_error_recovery_delete_devices(ioc);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307385 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307386 break;
Eric Moore635374e2009-03-09 01:21:12 -06007387 }
7388}
7389
7390/**
7391 * _firmware_event_work - delayed task for processing firmware events
7392 * @ioc: per adapter object
7393 * @work: equal to the fw_event_work object
7394 * Context: user.
7395 *
7396 * Return nothing.
7397 */
7398static void
7399_firmware_event_work(struct work_struct *work)
7400{
7401 struct fw_event_work *fw_event = container_of(work,
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307402 struct fw_event_work, delayed_work.work);
Eric Moore635374e2009-03-09 01:21:12 -06007403 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7404
Eric Moore635374e2009-03-09 01:21:12 -06007405 /* the queue is being flushed so ignore this event */
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05307406 if (ioc->remove_host ||
Eric Moore3cb54692010-07-08 14:44:34 -06007407 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06007408 _scsih_fw_event_free(ioc, fw_event);
7409 return;
7410 }
Eric Moore635374e2009-03-09 01:21:12 -06007411
Eric Moore635374e2009-03-09 01:21:12 -06007412 switch (fw_event->event) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307413 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307414 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307415 ssleep(1);
7416 _scsih_remove_unresponding_sas_devices(ioc);
7417 _scsih_scan_for_devices_after_reset(ioc);
7418 break;
7419 case MPT2SAS_PORT_ENABLE_COMPLETE:
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307420 ioc->start_scan = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307421
Reddy, Sreekanthb0df96a02013-02-26 16:59:59 +05307422 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7423 mpt2sas_base_update_missing_delay(ioc, missing_delay[0],
7424 missing_delay[1]);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307425
7426 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7427 "from worker thread\n", ioc->name));
7428 break;
Sreekanth Reddybd58ea32014-09-12 15:35:19 +05307429 case MPT2SAS_TURN_ON_PFA_LED:
7430 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05307431 break;
Eric Moore635374e2009-03-09 01:21:12 -06007432 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307433 _scsih_sas_topology_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007434 break;
7435 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307436 _scsih_sas_device_status_change_event(ioc,
7437 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007438 break;
7439 case MPI2_EVENT_SAS_DISCOVERY:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307440 _scsih_sas_discovery_event(ioc,
7441 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007442 break;
7443 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
Andrew Mortona78e21d2012-02-08 12:52:22 -08007444 _scsih_sas_broadcast_primitive_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307445 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007446 break;
7447 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7448 _scsih_sas_enclosure_dev_status_change_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307449 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007450 break;
7451 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307452 _scsih_sas_ir_config_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007453 break;
7454 case MPI2_EVENT_IR_VOLUME:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307455 _scsih_sas_ir_volume_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007456 break;
7457 case MPI2_EVENT_IR_PHYSICAL_DISK:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307458 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007459 break;
7460 case MPI2_EVENT_IR_OPERATION_STATUS:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307461 _scsih_sas_ir_operation_status_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007462 break;
Eric Moore635374e2009-03-09 01:21:12 -06007463 }
7464 _scsih_fw_event_free(ioc, fw_event);
7465}
7466
7467/**
7468 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7469 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307470 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06007471 * @reply: reply message frame(lower 32bit addr)
7472 * Context: interrupt.
7473 *
7474 * This function merely adds a new work task into ioc->firmware_event_thread.
7475 * The tasks are worked from _firmware_event_work in user context.
7476 *
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307477 * Returns void.
Eric Moore635374e2009-03-09 01:21:12 -06007478 */
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307479void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307480mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7481 u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06007482{
7483 struct fw_event_work *fw_event;
7484 Mpi2EventNotificationReply_t *mpi_reply;
Eric Moore635374e2009-03-09 01:21:12 -06007485 u16 event;
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307486 u16 sz;
Eric Moore635374e2009-03-09 01:21:12 -06007487
7488 /* events turned off due to host reset or driver unloading */
Eric Moore3cb54692010-07-08 14:44:34 -06007489 if (ioc->remove_host || ioc->pci_error_recovery)
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307490 return;
Eric Moore635374e2009-03-09 01:21:12 -06007491
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307492 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05307493
7494 if (unlikely(!mpi_reply)) {
7495 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7496 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307497 return;
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05307498 }
7499
Eric Moore635374e2009-03-09 01:21:12 -06007500 event = le16_to_cpu(mpi_reply->Event);
7501
7502 switch (event) {
7503 /* handle these */
7504 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7505 {
7506 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7507 (Mpi2EventDataSasBroadcastPrimitive_t *)
7508 mpi_reply->EventData;
7509
7510 if (baen_data->Primitive !=
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307511 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307512 return;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307513
7514 if (ioc->broadcast_aen_busy) {
7515 ioc->broadcast_aen_pending++;
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307516 return;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307517 } else
7518 ioc->broadcast_aen_busy = 1;
Eric Moore635374e2009-03-09 01:21:12 -06007519 break;
7520 }
7521
7522 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7523 _scsih_check_topo_delete_events(ioc,
7524 (Mpi2EventDataSasTopologyChangeList_t *)
7525 mpi_reply->EventData);
7526 break;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05307527 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7528 _scsih_check_ir_config_unhide_events(ioc,
7529 (Mpi2EventDataIrConfigChangeList_t *)
7530 mpi_reply->EventData);
7531 break;
7532 case MPI2_EVENT_IR_VOLUME:
7533 _scsih_check_volume_delete_events(ioc,
7534 (Mpi2EventDataIrVolume_t *)
7535 mpi_reply->EventData);
7536 break;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307537 case MPI2_EVENT_LOG_ENTRY_ADDED:
7538 {
7539 Mpi2EventDataLogEntryAdded_t *log_entry;
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05307540 __le32 *log_code;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307541
7542 if (!ioc->is_warpdrive)
7543 break;
7544
7545 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7546 mpi_reply->EventData;
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05307547 log_code = (__le32 *)log_entry->LogData;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307548
7549 if (le16_to_cpu(log_entry->LogEntryQualifier)
7550 != MPT2_WARPDRIVE_LOGENTRY)
7551 break;
7552
7553 switch (le32_to_cpu(*log_code)) {
7554 case MPT2_WARPDRIVE_LC_SSDT:
7555 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7556 "IO Throttling has occurred in the WarpDrive "
7557 "subsystem. Check WarpDrive documentation for "
7558 "additional details.\n", ioc->name);
7559 break;
7560 case MPT2_WARPDRIVE_LC_SSDLW:
7561 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7562 "Program/Erase Cycles for the WarpDrive subsystem "
7563 "in degraded range. Check WarpDrive documentation "
7564 "for additional details.\n", ioc->name);
7565 break;
7566 case MPT2_WARPDRIVE_LC_SSDLF:
7567 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7568 "There are no Program/Erase Cycles for the "
7569 "WarpDrive subsystem. The storage device will be "
7570 "in read-only mode. Check WarpDrive documentation "
7571 "for additional details.\n", ioc->name);
7572 break;
7573 case MPT2_WARPDRIVE_LC_BRMF:
7574 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7575 "The Backup Rail Monitor has failed on the "
7576 "WarpDrive subsystem. Check WarpDrive "
7577 "documentation for additional details.\n",
7578 ioc->name);
7579 break;
7580 }
7581
7582 break;
7583 }
Eric Moore635374e2009-03-09 01:21:12 -06007584 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7585 case MPI2_EVENT_IR_OPERATION_STATUS:
7586 case MPI2_EVENT_SAS_DISCOVERY:
7587 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
Eric Moore635374e2009-03-09 01:21:12 -06007588 case MPI2_EVENT_IR_PHYSICAL_DISK:
Eric Moore635374e2009-03-09 01:21:12 -06007589 break;
7590
7591 default: /* ignore the rest */
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307592 return;
Eric Moore635374e2009-03-09 01:21:12 -06007593 }
7594
Joe Lawrence00713ad2014-06-25 17:03:33 -04007595 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7596 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06007597 if (!fw_event) {
7598 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7599 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307600 return;
Eric Moore635374e2009-03-09 01:21:12 -06007601 }
Eric Moore635374e2009-03-09 01:21:12 -06007602
Joe Lawrence00713ad2014-06-25 17:03:33 -04007603 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
Eric Moore635374e2009-03-09 01:21:12 -06007604 fw_event->ioc = ioc;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307605 fw_event->VF_ID = mpi_reply->VF_ID;
7606 fw_event->VP_ID = mpi_reply->VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -06007607 fw_event->event = event;
7608 _scsih_fw_event_add(ioc, fw_event);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307609 return;
Eric Moore635374e2009-03-09 01:21:12 -06007610}
7611
7612/* shost template */
7613static struct scsi_host_template scsih_driver_template = {
7614 .module = THIS_MODULE,
7615 .name = "Fusion MPT SAS Host",
7616 .proc_name = MPT2SAS_DRIVER_NAME,
Eric Moored5d135b2009-05-18 13:02:08 -06007617 .queuecommand = _scsih_qcmd,
7618 .target_alloc = _scsih_target_alloc,
7619 .slave_alloc = _scsih_slave_alloc,
7620 .slave_configure = _scsih_slave_configure,
7621 .target_destroy = _scsih_target_destroy,
7622 .slave_destroy = _scsih_slave_destroy,
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307623 .scan_finished = _scsih_scan_finished,
7624 .scan_start = _scsih_scan_start,
Eric Moored5d135b2009-05-18 13:02:08 -06007625 .change_queue_depth = _scsih_change_queue_depth,
Christoph Hellwiga62182f2014-10-02 14:39:55 +02007626 .change_queue_type = scsi_change_queue_type,
Eric Moored5d135b2009-05-18 13:02:08 -06007627 .eh_abort_handler = _scsih_abort,
7628 .eh_device_reset_handler = _scsih_dev_reset,
7629 .eh_target_reset_handler = _scsih_target_reset,
7630 .eh_host_reset_handler = _scsih_host_reset,
7631 .bios_param = _scsih_bios_param,
Eric Moore635374e2009-03-09 01:21:12 -06007632 .can_queue = 1,
7633 .this_id = -1,
7634 .sg_tablesize = MPT2SAS_SG_DEPTH,
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05307635 .max_sectors = 32767,
Eric Moore635374e2009-03-09 01:21:12 -06007636 .cmd_per_lun = 7,
7637 .use_clustering = ENABLE_CLUSTERING,
7638 .shost_attrs = mpt2sas_host_attrs,
7639 .sdev_attrs = mpt2sas_dev_attrs,
7640};
7641
7642/**
7643 * _scsih_expander_node_remove - removing expander device from list.
7644 * @ioc: per adapter object
7645 * @sas_expander: the sas_device object
7646 * Context: Calling function should acquire ioc->sas_node_lock.
7647 *
7648 * Removing object and freeing associated memory from the
7649 * ioc->sas_expander_list.
7650 *
7651 * Return nothing.
7652 */
7653static void
7654_scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7655 struct _sas_node *sas_expander)
7656{
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307657 struct _sas_port *mpt2sas_port, *next;
Eric Moore635374e2009-03-09 01:21:12 -06007658
7659 /* remove sibling ports attached to this expander */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307660 list_for_each_entry_safe(mpt2sas_port, next,
Eric Moore635374e2009-03-09 01:21:12 -06007661 &sas_expander->sas_port_list, port_list) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307662 if (ioc->shost_recovery)
7663 return;
Eric Moore635374e2009-03-09 01:21:12 -06007664 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307665 SAS_END_DEVICE)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307666 mpt2sas_device_remove_by_sas_address(ioc,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307667 mpt2sas_port->remote_identify.sas_address);
7668 else if (mpt2sas_port->remote_identify.device_type ==
7669 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06007670 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307671 SAS_FANOUT_EXPANDER_DEVICE)
7672 mpt2sas_expander_remove(ioc,
7673 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007674 }
7675
7676 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307677 sas_expander->sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06007678
7679 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7680 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7681 sas_expander->handle, (unsigned long long)
7682 sas_expander->sas_address);
7683
Eric Moore635374e2009-03-09 01:21:12 -06007684 kfree(sas_expander->phy);
7685 kfree(sas_expander);
7686}
7687
7688/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05307689 * _scsih_ir_shutdown - IR shutdown notification
7690 * @ioc: per adapter object
7691 *
7692 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7693 * the host system is shutting down.
7694 *
7695 * Return nothing.
7696 */
7697static void
7698_scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7699{
7700 Mpi2RaidActionRequest_t *mpi_request;
7701 Mpi2RaidActionReply_t *mpi_reply;
7702 u16 smid;
7703
7704 /* is IR firmware build loaded ? */
7705 if (!ioc->ir_firmware)
7706 return;
7707
Kashyap, Desai744090d2009-10-05 15:56:56 +05307708 mutex_lock(&ioc->scsih_cmds.mutex);
7709
7710 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7711 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7712 ioc->name, __func__);
7713 goto out;
7714 }
7715 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7716
7717 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7718 if (!smid) {
7719 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7720 ioc->name, __func__);
7721 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7722 goto out;
7723 }
7724
7725 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7726 ioc->scsih_cmds.smid = smid;
7727 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7728
7729 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7730 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7731
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307732 if (!ioc->hide_ir_msg)
7733 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307734 init_completion(&ioc->scsih_cmds.done);
7735 mpt2sas_base_put_smid_default(ioc, smid);
7736 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7737
7738 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7739 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7740 ioc->name, __func__);
7741 goto out;
7742 }
7743
7744 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7745 mpi_reply = ioc->scsih_cmds.reply;
7746
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307747 if (!ioc->hide_ir_msg)
7748 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7749 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7750 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7751 le32_to_cpu(mpi_reply->IOCLogInfo));
Kashyap, Desai744090d2009-10-05 15:56:56 +05307752 }
7753
7754 out:
7755 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7756 mutex_unlock(&ioc->scsih_cmds.mutex);
7757}
7758
7759/**
7760 * _scsih_shutdown - routine call during system shutdown
7761 * @pdev: PCI device struct
7762 *
7763 * Return nothing.
7764 */
7765static void
7766_scsih_shutdown(struct pci_dev *pdev)
7767{
7768 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7769 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307770 struct workqueue_struct *wq;
7771 unsigned long flags;
7772
7773 ioc->remove_host = 1;
7774 _scsih_fw_event_cleanup_queue(ioc);
7775
7776 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7777 wq = ioc->firmware_event_thread;
7778 ioc->firmware_event_thread = NULL;
7779 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7780 if (wq)
7781 destroy_workqueue(wq);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307782
7783 _scsih_ir_shutdown(ioc);
7784 mpt2sas_base_detach(ioc);
7785}
7786
7787/**
Eric Moored5d135b2009-05-18 13:02:08 -06007788 * _scsih_remove - detach and remove add host
Eric Moore635374e2009-03-09 01:21:12 -06007789 * @pdev: PCI device struct
7790 *
Kashyap, Desai744090d2009-10-05 15:56:56 +05307791 * Routine called when unloading the driver.
Eric Moore635374e2009-03-09 01:21:12 -06007792 * Return nothing.
7793 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08007794static void
Eric Moored5d135b2009-05-18 13:02:08 -06007795_scsih_remove(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06007796{
7797 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7798 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307799 struct _sas_port *mpt2sas_port, *next_port;
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307800 struct _raid_device *raid_device, *next;
7801 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06007802 struct workqueue_struct *wq;
7803 unsigned long flags;
7804
7805 ioc->remove_host = 1;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307806 _scsih_fw_event_cleanup_queue(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007807
7808 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7809 wq = ioc->firmware_event_thread;
7810 ioc->firmware_event_thread = NULL;
7811 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7812 if (wq)
7813 destroy_workqueue(wq);
7814
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307815 /* release all the volumes */
Kashyap, Desai3a9c9132011-01-04 11:40:23 +05307816 _scsih_ir_shutdown(ioc);
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307817 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7818 list) {
7819 if (raid_device->starget) {
7820 sas_target_priv_data =
7821 raid_device->starget->hostdata;
7822 sas_target_priv_data->deleted = 1;
7823 scsi_remove_target(&raid_device->starget->dev);
7824 }
7825 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7826 "(0x%016llx)\n", ioc->name, raid_device->handle,
7827 (unsigned long long) raid_device->wwid);
7828 _scsih_raid_device_remove(ioc, raid_device);
7829 }
7830
Eric Moore635374e2009-03-09 01:21:12 -06007831 /* free ports attached to the sas_host */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307832 list_for_each_entry_safe(mpt2sas_port, next_port,
Eric Moore635374e2009-03-09 01:21:12 -06007833 &ioc->sas_hba.sas_port_list, port_list) {
7834 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307835 SAS_END_DEVICE)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307836 mpt2sas_device_remove_by_sas_address(ioc,
Eric Moore635374e2009-03-09 01:21:12 -06007837 mpt2sas_port->remote_identify.sas_address);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307838 else if (mpt2sas_port->remote_identify.device_type ==
7839 SAS_EDGE_EXPANDER_DEVICE ||
7840 mpt2sas_port->remote_identify.device_type ==
7841 SAS_FANOUT_EXPANDER_DEVICE)
7842 mpt2sas_expander_remove(ioc,
7843 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007844 }
7845
7846 /* free phys attached to the sas_host */
7847 if (ioc->sas_hba.num_phys) {
7848 kfree(ioc->sas_hba.phy);
7849 ioc->sas_hba.phy = NULL;
7850 ioc->sas_hba.num_phys = 0;
7851 }
7852
7853 sas_remove_host(shost);
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05307854 scsi_remove_host(shost);
kashyap.desai@lsi.com9ae89b02011-08-04 16:47:50 +05307855 mpt2sas_base_detach(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007856 list_del(&ioc->list);
Eric Moore635374e2009-03-09 01:21:12 -06007857 scsi_host_put(shost);
7858}
7859
7860/**
7861 * _scsih_probe_boot_devices - reports 1st device
7862 * @ioc: per adapter object
7863 *
7864 * If specified in bios page 2, this routine reports the 1st
7865 * device scsi-ml or sas transport for persistent boot device
7866 * purposes. Please refer to function _scsih_determine_boot_device()
7867 */
7868static void
7869_scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7870{
7871 u8 is_raid;
7872 void *device;
7873 struct _sas_device *sas_device;
7874 struct _raid_device *raid_device;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307875 u16 handle;
7876 u64 sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007877 u64 sas_address;
7878 unsigned long flags;
7879 int rc;
7880
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307881 /* no Bios, return immediately */
7882 if (!ioc->bios_pg3.BiosVersion)
7883 return;
7884
Eric Moore635374e2009-03-09 01:21:12 -06007885 device = NULL;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307886 is_raid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007887 if (ioc->req_boot_device.device) {
7888 device = ioc->req_boot_device.device;
7889 is_raid = ioc->req_boot_device.is_raid;
7890 } else if (ioc->req_alt_boot_device.device) {
7891 device = ioc->req_alt_boot_device.device;
7892 is_raid = ioc->req_alt_boot_device.is_raid;
7893 } else if (ioc->current_boot_device.device) {
7894 device = ioc->current_boot_device.device;
7895 is_raid = ioc->current_boot_device.is_raid;
7896 }
7897
7898 if (!device)
7899 return;
7900
7901 if (is_raid) {
7902 raid_device = device;
7903 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7904 raid_device->id, 0);
7905 if (rc)
7906 _scsih_raid_device_remove(ioc, raid_device);
7907 } else {
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307908 spin_lock_irqsave(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06007909 sas_device = device;
7910 handle = sas_device->handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307911 sas_address_parent = sas_device->sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007912 sas_address = sas_device->sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06007913 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7914 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307915
7916 if (ioc->hide_drives)
7917 return;
Eric Moore635374e2009-03-09 01:21:12 -06007918 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307919 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -06007920 _scsih_sas_device_remove(ioc, sas_device);
7921 } else if (!sas_device->starget) {
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307922 if (!ioc->is_driver_loading) {
7923 mpt2sas_transport_port_remove(ioc,
7924 sas_address,
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05307925 sas_address_parent);
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307926 _scsih_sas_device_remove(ioc, sas_device);
7927 }
Eric Moore635374e2009-03-09 01:21:12 -06007928 }
7929 }
7930}
7931
7932/**
7933 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7934 * @ioc: per adapter object
7935 *
7936 * Called during initial loading of the driver.
7937 */
7938static void
7939_scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7940{
7941 struct _raid_device *raid_device, *raid_next;
7942 int rc;
7943
7944 list_for_each_entry_safe(raid_device, raid_next,
7945 &ioc->raid_device_list, list) {
7946 if (raid_device->starget)
7947 continue;
7948 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7949 raid_device->id, 0);
7950 if (rc)
7951 _scsih_raid_device_remove(ioc, raid_device);
7952 }
7953}
7954
7955/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307956 * _scsih_probe_sas - reporting sas devices to sas transport
Eric Moore635374e2009-03-09 01:21:12 -06007957 * @ioc: per adapter object
7958 *
7959 * Called during initial loading of the driver.
7960 */
7961static void
7962_scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7963{
7964 struct _sas_device *sas_device, *next;
7965 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06007966
7967 /* SAS Device List */
7968 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7969 list) {
Eric Moore635374e2009-03-09 01:21:12 -06007970
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307971 if (ioc->hide_drives)
7972 continue;
7973
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307974 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7975 sas_device->sas_address_parent)) {
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307976 list_del(&sas_device->list);
7977 kfree(sas_device);
7978 continue;
Eric Moore635374e2009-03-09 01:21:12 -06007979 } else if (!sas_device->starget) {
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307980 if (!ioc->is_driver_loading) {
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05307981 mpt2sas_transport_port_remove(ioc,
7982 sas_device->sas_address,
7983 sas_device->sas_address_parent);
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307984 list_del(&sas_device->list);
7985 kfree(sas_device);
7986 continue;
7987 }
Eric Moore635374e2009-03-09 01:21:12 -06007988 }
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307989 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7990 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7991 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06007992 }
7993}
7994
7995/**
7996 * _scsih_probe_devices - probing for devices
7997 * @ioc: per adapter object
7998 *
7999 * Called during initial loading of the driver.
8000 */
8001static void
8002_scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
8003{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308004 u16 volume_mapping_flags;
Eric Moore635374e2009-03-09 01:21:12 -06008005
8006 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8007 return; /* return when IOC doesn't support initiator mode */
8008
8009 _scsih_probe_boot_devices(ioc);
8010
8011 if (ioc->ir_firmware) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308012 volume_mapping_flags =
8013 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8014 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8015 if (volume_mapping_flags ==
8016 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
Eric Moore635374e2009-03-09 01:21:12 -06008017 _scsih_probe_raid(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308018 _scsih_probe_sas(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008019 } else {
Eric Moore635374e2009-03-09 01:21:12 -06008020 _scsih_probe_sas(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308021 _scsih_probe_raid(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008022 }
8023 } else
8024 _scsih_probe_sas(ioc);
8025}
8026
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308027
8028/**
8029 * _scsih_scan_start - scsi lld callback for .scan_start
8030 * @shost: SCSI host pointer
8031 *
8032 * The shost has the ability to discover targets on its own instead
8033 * of scanning the entire bus. In our implemention, we will kick off
8034 * firmware discovery.
8035 */
8036static void
8037_scsih_scan_start(struct Scsi_Host *shost)
8038{
8039 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8040 int rc;
8041
8042 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8043 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
8044
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05308045 if (disable_discovery > 0)
8046 return;
8047
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308048 ioc->start_scan = 1;
8049 rc = mpt2sas_port_enable(ioc);
8050
8051 if (rc != 0)
8052 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
8053}
8054
8055/**
8056 * _scsih_scan_finished - scsi lld callback for .scan_finished
8057 * @shost: SCSI host pointer
8058 * @time: elapsed time of the scan in jiffies
8059 *
8060 * This function will be called periodically until it returns 1 with the
8061 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8062 * we wait for firmware discovery to complete, then return 1.
8063 */
8064static int
8065_scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8066{
8067 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8068
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05308069 if (disable_discovery > 0) {
8070 ioc->is_driver_loading = 0;
8071 ioc->wait_for_discovery_to_complete = 0;
8072 return 1;
8073 }
8074
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308075 if (time >= (300 * HZ)) {
8076 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8077 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
8078 "(timeout=300s)\n", ioc->name);
8079 ioc->is_driver_loading = 0;
8080 return 1;
8081 }
8082
8083 if (ioc->start_scan)
8084 return 0;
8085
8086 if (ioc->start_scan_failed) {
8087 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
8088 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
8089 ioc->is_driver_loading = 0;
8090 ioc->wait_for_discovery_to_complete = 0;
8091 ioc->remove_host = 1;
8092 return 1;
8093 }
8094
8095 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
8096 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8097
8098 if (ioc->wait_for_discovery_to_complete) {
8099 ioc->wait_for_discovery_to_complete = 0;
8100 _scsih_probe_devices(ioc);
8101 }
8102 mpt2sas_base_start_watchdog(ioc);
8103 ioc->is_driver_loading = 0;
8104 return 1;
8105}
8106
8107
Eric Moore635374e2009-03-09 01:21:12 -06008108/**
Eric Moored5d135b2009-05-18 13:02:08 -06008109 * _scsih_probe - attach and add scsi host
Eric Moore635374e2009-03-09 01:21:12 -06008110 * @pdev: PCI device struct
8111 * @id: pci device id
8112 *
8113 * Returns 0 success, anything else error.
8114 */
8115static int
Eric Moored5d135b2009-05-18 13:02:08 -06008116_scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
Eric Moore635374e2009-03-09 01:21:12 -06008117{
8118 struct MPT2SAS_ADAPTER *ioc;
8119 struct Scsi_Host *shost;
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308120 int rv;
Eric Moore635374e2009-03-09 01:21:12 -06008121
8122 shost = scsi_host_alloc(&scsih_driver_template,
8123 sizeof(struct MPT2SAS_ADAPTER));
8124 if (!shost)
8125 return -ENODEV;
8126
8127 /* init local params */
8128 ioc = shost_priv(shost);
8129 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
8130 INIT_LIST_HEAD(&ioc->list);
Eric Mooreba33fad2009-03-15 21:37:18 -06008131 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
Eric Moore635374e2009-03-09 01:21:12 -06008132 ioc->shost = shost;
8133 ioc->id = mpt_ids++;
8134 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
8135 ioc->pdev = pdev;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308136 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8137 ioc->is_warpdrive = 1;
8138 ioc->hide_ir_msg = 1;
8139 } else
8140 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
Eric Moore635374e2009-03-09 01:21:12 -06008141 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8142 ioc->tm_cb_idx = tm_cb_idx;
8143 ioc->ctl_cb_idx = ctl_cb_idx;
8144 ioc->base_cb_idx = base_cb_idx;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308145 ioc->port_enable_cb_idx = port_enable_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008146 ioc->transport_cb_idx = transport_cb_idx;
Kashyap, Desai744090d2009-10-05 15:56:56 +05308147 ioc->scsih_cb_idx = scsih_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008148 ioc->config_cb_idx = config_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308149 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308150 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308151 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008152 ioc->logging_level = logging_level;
nagalakshmi.nandigama@lsi.com845a0e42011-12-01 07:42:04 +05308153 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
Eric Moore635374e2009-03-09 01:21:12 -06008154 /* misc semaphores and spin locks */
Kashyap, Desaid2742132010-06-17 13:28:55 +05308155 mutex_init(&ioc->reset_in_progress_mutex);
Eric Moore635374e2009-03-09 01:21:12 -06008156 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8157 spin_lock_init(&ioc->scsi_lookup_lock);
8158 spin_lock_init(&ioc->sas_device_lock);
8159 spin_lock_init(&ioc->sas_node_lock);
8160 spin_lock_init(&ioc->fw_event_lock);
8161 spin_lock_init(&ioc->raid_device_lock);
8162
8163 INIT_LIST_HEAD(&ioc->sas_device_list);
8164 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8165 INIT_LIST_HEAD(&ioc->sas_expander_list);
8166 INIT_LIST_HEAD(&ioc->fw_event_list);
8167 INIT_LIST_HEAD(&ioc->raid_device_list);
8168 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308169 INIT_LIST_HEAD(&ioc->delayed_tr_list);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308170 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
Joe Lawrence3b3e6f82013-08-08 16:45:38 -04008171 INIT_LIST_HEAD(&ioc->reply_queue_list);
Eric Moore635374e2009-03-09 01:21:12 -06008172
8173 /* init shost parameters */
Eric Moored334aa72010-04-22 10:47:40 -06008174 shost->max_cmd_len = 32;
Eric Moore635374e2009-03-09 01:21:12 -06008175 shost->max_lun = max_lun;
8176 shost->transportt = mpt2sas_transport_template;
8177 shost->unique_id = ioc->id;
8178
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308179 if (max_sectors != 0xFFFF) {
8180 if (max_sectors < 64) {
8181 shost->max_sectors = 64;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05308182 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8183 "for max_sectors, range is 64 to 32767. Assigning "
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308184 "value of 64.\n", ioc->name, max_sectors);
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05308185 } else if (max_sectors > 32767) {
8186 shost->max_sectors = 32767;
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308187 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8188 "for max_sectors, range is 64 to 8192. Assigning "
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05308189 "default value of 32767.\n", ioc->name,
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308190 max_sectors);
8191 } else {
8192 shost->max_sectors = max_sectors & 0xFFFE;
8193 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
8194 "set to %d\n", ioc->name, shost->max_sectors);
8195 }
8196 }
8197
Martin K. Petersen5e95e732012-08-28 14:29:37 -04008198 /* register EEDP capabilities with SCSI layer */
8199 if (prot_mask)
8200 scsi_host_set_prot(shost, prot_mask);
8201 else
8202 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8203 | SHOST_DIF_TYPE2_PROTECTION
8204 | SHOST_DIF_TYPE3_PROTECTION);
8205
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308206 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
Eric Moore3c621b32009-05-18 12:59:41 -06008207
Eric Moore635374e2009-03-09 01:21:12 -06008208 /* event thread */
8209 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8210 "fw_event%d", ioc->id);
8211 ioc->firmware_event_thread = create_singlethread_workqueue(
8212 ioc->firmware_event_name);
8213 if (!ioc->firmware_event_thread) {
8214 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8215 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308216 rv = -ENODEV;
Eric Moore635374e2009-03-09 01:21:12 -06008217 goto out_thread_fail;
8218 }
8219
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308220 ioc->is_driver_loading = 1;
Eric Moore635374e2009-03-09 01:21:12 -06008221 if ((mpt2sas_base_attach(ioc))) {
8222 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8223 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308224 rv = -ENODEV;
Eric Moore635374e2009-03-09 01:21:12 -06008225 goto out_attach_fail;
8226 }
8227
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308228 if (ioc->is_warpdrive) {
8229 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8230 ioc->hide_drives = 0;
8231 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8232 ioc->hide_drives = 1;
8233 else {
8234 if (_scsih_get_num_volumes(ioc))
8235 ioc->hide_drives = 1;
8236 else
8237 ioc->hide_drives = 0;
8238 }
8239 } else
8240 ioc->hide_drives = 0;
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05308241
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308242 rv = scsi_add_host(shost, &pdev->dev);
8243 if (rv) {
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05308244 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8245 ioc->name, __FILE__, __LINE__, __func__);
8246 goto out_add_shost_fail;
8247 }
8248
nagalakshmi.nandigama@lsi.com2cb6fc82011-12-13 09:29:15 +05308249 scsi_scan_host(shost);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308250
Eric Moore635374e2009-03-09 01:21:12 -06008251 return 0;
8252
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05308253 out_add_shost_fail:
8254 mpt2sas_base_detach(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008255 out_attach_fail:
8256 destroy_workqueue(ioc->firmware_event_thread);
8257 out_thread_fail:
8258 list_del(&ioc->list);
Tomas Henzlf555e052012-04-17 15:24:48 +02008259 scsi_host_put(shost);
Sreekanth Reddyb65f1d42014-09-12 15:35:33 +05308260 return rv;
Eric Moore635374e2009-03-09 01:21:12 -06008261}
8262
8263#ifdef CONFIG_PM
8264/**
Eric Moored5d135b2009-05-18 13:02:08 -06008265 * _scsih_suspend - power management suspend main entry point
Eric Moore635374e2009-03-09 01:21:12 -06008266 * @pdev: PCI device struct
8267 * @state: PM state change to (usually PCI_D3)
8268 *
8269 * Returns 0 success, anything else error.
8270 */
8271static int
Eric Moored5d135b2009-05-18 13:02:08 -06008272_scsih_suspend(struct pci_dev *pdev, pm_message_t state)
Eric Moore635374e2009-03-09 01:21:12 -06008273{
8274 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8275 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05308276 pci_power_t device_state;
Eric Moore635374e2009-03-09 01:21:12 -06008277
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308278 mpt2sas_base_stop_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008279 scsi_block_requests(shost);
Sreekanth Reddy3627dba2013-07-25 11:25:57 +05308280 _scsih_ir_shutdown(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008281 device_state = pci_choose_state(pdev, state);
8282 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8283 "operating state [D%d]\n", ioc->name, pdev,
8284 pci_name(pdev), device_state);
8285
8286 mpt2sas_base_free_resources(ioc);
8287 pci_save_state(pdev);
Eric Moore635374e2009-03-09 01:21:12 -06008288 pci_set_power_state(pdev, device_state);
8289 return 0;
8290}
8291
8292/**
Eric Moored5d135b2009-05-18 13:02:08 -06008293 * _scsih_resume - power management resume main entry point
Eric Moore635374e2009-03-09 01:21:12 -06008294 * @pdev: PCI device struct
8295 *
8296 * Returns 0 success, anything else error.
8297 */
8298static int
Eric Moored5d135b2009-05-18 13:02:08 -06008299_scsih_resume(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06008300{
8301 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8302 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05308303 pci_power_t device_state = pdev->current_state;
Eric Moore635374e2009-03-09 01:21:12 -06008304 int r;
8305
8306 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8307 "operating state [D%d]\n", ioc->name, pdev,
8308 pci_name(pdev), device_state);
8309
8310 pci_set_power_state(pdev, PCI_D0);
8311 pci_enable_wake(pdev, PCI_D0, 0);
8312 pci_restore_state(pdev);
8313 ioc->pdev = pdev;
8314 r = mpt2sas_base_map_resources(ioc);
8315 if (r)
8316 return r;
8317
8318 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8319 scsi_unblock_requests(shost);
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308320 mpt2sas_base_start_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008321 return 0;
8322}
8323#endif /* CONFIG_PM */
8324
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308325/**
8326 * _scsih_pci_error_detected - Called when a PCI error is detected.
8327 * @pdev: PCI device struct
8328 * @state: PCI channel state
8329 *
8330 * Description: Called when a PCI error is detected.
8331 *
8332 * Return value:
8333 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8334 */
8335static pci_ers_result_t
8336_scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8337{
8338 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8339 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8340
8341 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8342 ioc->name, state);
8343
8344 switch (state) {
8345 case pci_channel_io_normal:
8346 return PCI_ERS_RESULT_CAN_RECOVER;
8347 case pci_channel_io_frozen:
Eric Moore3cb54692010-07-08 14:44:34 -06008348 /* Fatal error, prepare for slot reset */
8349 ioc->pci_error_recovery = 1;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308350 scsi_block_requests(ioc->shost);
8351 mpt2sas_base_stop_watchdog(ioc);
8352 mpt2sas_base_free_resources(ioc);
8353 return PCI_ERS_RESULT_NEED_RESET;
8354 case pci_channel_io_perm_failure:
Eric Moore3cb54692010-07-08 14:44:34 -06008355 /* Permanent error, prepare for device removal */
8356 ioc->pci_error_recovery = 1;
8357 mpt2sas_base_stop_watchdog(ioc);
8358 _scsih_flush_running_cmds(ioc);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308359 return PCI_ERS_RESULT_DISCONNECT;
8360 }
8361 return PCI_ERS_RESULT_NEED_RESET;
8362}
8363
8364/**
8365 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8366 * @pdev: PCI device struct
8367 *
8368 * Description: This routine is called by the pci error recovery
8369 * code after the PCI slot has been reset, just before we
8370 * should resume normal operations.
8371 */
8372static pci_ers_result_t
8373_scsih_pci_slot_reset(struct pci_dev *pdev)
8374{
8375 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8376 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8377 int rc;
8378
8379 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8380 ioc->name);
8381
Eric Moore3cb54692010-07-08 14:44:34 -06008382 ioc->pci_error_recovery = 0;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308383 ioc->pdev = pdev;
Eric Moore3cb54692010-07-08 14:44:34 -06008384 pci_restore_state(pdev);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308385 rc = mpt2sas_base_map_resources(ioc);
8386 if (rc)
8387 return PCI_ERS_RESULT_DISCONNECT;
8388
8389
8390 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8391 FORCE_BIG_HAMMER);
8392
8393 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8394 (rc == 0) ? "success" : "failed");
8395
8396 if (!rc)
8397 return PCI_ERS_RESULT_RECOVERED;
8398 else
8399 return PCI_ERS_RESULT_DISCONNECT;
8400}
8401
8402/**
8403 * _scsih_pci_resume() - resume normal ops after PCI reset
8404 * @pdev: pointer to PCI device
8405 *
8406 * Called when the error recovery driver tells us that its
8407 * OK to resume normal operation. Use completion to allow
8408 * halted scsi ops to resume.
8409 */
8410static void
8411_scsih_pci_resume(struct pci_dev *pdev)
8412{
8413 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8414 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8415
8416 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8417
8418 pci_cleanup_aer_uncorrect_error_status(pdev);
8419 mpt2sas_base_start_watchdog(ioc);
8420 scsi_unblock_requests(ioc->shost);
8421}
8422
8423/**
8424 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8425 * @pdev: pointer to PCI device
8426 */
8427static pci_ers_result_t
8428_scsih_pci_mmio_enabled(struct pci_dev *pdev)
8429{
8430 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8431 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8432
8433 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8434 ioc->name);
8435
8436 /* TODO - dump whatever for debugging purposes */
8437
8438 /* Request a slot reset. */
8439 return PCI_ERS_RESULT_NEED_RESET;
8440}
8441
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07008442static const struct pci_error_handlers _scsih_err_handler = {
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308443 .error_detected = _scsih_pci_error_detected,
8444 .mmio_enabled = _scsih_pci_mmio_enabled,
8445 .slot_reset = _scsih_pci_slot_reset,
8446 .resume = _scsih_pci_resume,
8447};
Eric Moore635374e2009-03-09 01:21:12 -06008448
8449static struct pci_driver scsih_driver = {
8450 .name = MPT2SAS_DRIVER_NAME,
8451 .id_table = scsih_pci_table,
Eric Moored5d135b2009-05-18 13:02:08 -06008452 .probe = _scsih_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008453 .remove = _scsih_remove,
Kashyap, Desai744090d2009-10-05 15:56:56 +05308454 .shutdown = _scsih_shutdown,
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308455 .err_handler = &_scsih_err_handler,
Eric Moore635374e2009-03-09 01:21:12 -06008456#ifdef CONFIG_PM
Eric Moored5d135b2009-05-18 13:02:08 -06008457 .suspend = _scsih_suspend,
8458 .resume = _scsih_resume,
Eric Moore635374e2009-03-09 01:21:12 -06008459#endif
8460};
8461
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308462/* raid transport support */
8463static struct raid_function_template mpt2sas_raid_functions = {
8464 .cookie = &scsih_driver_template,
8465 .is_raid = _scsih_is_raid,
8466 .get_resync = _scsih_get_resync,
8467 .get_state = _scsih_get_state,
8468};
Eric Moore635374e2009-03-09 01:21:12 -06008469
8470/**
Eric Moored5d135b2009-05-18 13:02:08 -06008471 * _scsih_init - main entry point for this driver.
Eric Moore635374e2009-03-09 01:21:12 -06008472 *
8473 * Returns 0 success, anything else error.
8474 */
8475static int __init
Eric Moored5d135b2009-05-18 13:02:08 -06008476_scsih_init(void)
Eric Moore635374e2009-03-09 01:21:12 -06008477{
8478 int error;
8479
8480 mpt_ids = 0;
8481 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8482 MPT2SAS_DRIVER_VERSION);
8483
8484 mpt2sas_transport_template =
8485 sas_attach_transport(&mpt2sas_transport_functions);
8486 if (!mpt2sas_transport_template)
8487 return -ENODEV;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308488 /* raid transport support */
8489 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8490 if (!mpt2sas_raid_template) {
8491 sas_release_transport(mpt2sas_transport_template);
8492 return -ENODEV;
8493 }
Eric Moore635374e2009-03-09 01:21:12 -06008494
8495 mpt2sas_base_initialize_callback_handler();
8496
8497 /* queuecommand callback hander */
Eric Moored5d135b2009-05-18 13:02:08 -06008498 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
Eric Moore635374e2009-03-09 01:21:12 -06008499
Uwe Kleine-König65155b32010-06-11 12:17:01 +02008500 /* task management callback handler */
Eric Moored5d135b2009-05-18 13:02:08 -06008501 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
Eric Moore635374e2009-03-09 01:21:12 -06008502
8503 /* base internal commands callback handler */
8504 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308505 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8506 mpt2sas_port_enable_done);
Eric Moore635374e2009-03-09 01:21:12 -06008507
8508 /* transport internal commands callback handler */
8509 transport_cb_idx = mpt2sas_base_register_callback_handler(
8510 mpt2sas_transport_done);
8511
Kashyap, Desai744090d2009-10-05 15:56:56 +05308512 /* scsih internal commands callback handler */
8513 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8514
Eric Moore635374e2009-03-09 01:21:12 -06008515 /* configuration page API internal commands callback handler */
8516 config_cb_idx = mpt2sas_base_register_callback_handler(
8517 mpt2sas_config_done);
8518
8519 /* ctl module callback handler */
8520 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8521
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308522 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8523 _scsih_tm_tr_complete);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308524
8525 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8526 _scsih_tm_volume_tr_complete);
8527
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308528 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8529 _scsih_sas_control_complete);
8530
Eric Moore635374e2009-03-09 01:21:12 -06008531 mpt2sas_ctl_init();
8532
8533 error = pci_register_driver(&scsih_driver);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308534 if (error) {
8535 /* raid transport support */
8536 raid_class_release(mpt2sas_raid_template);
Eric Moore635374e2009-03-09 01:21:12 -06008537 sas_release_transport(mpt2sas_transport_template);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308538 }
Eric Moore635374e2009-03-09 01:21:12 -06008539
8540 return error;
8541}
8542
8543/**
Eric Moored5d135b2009-05-18 13:02:08 -06008544 * _scsih_exit - exit point for this driver (when it is a module).
Eric Moore635374e2009-03-09 01:21:12 -06008545 *
8546 * Returns 0 success, anything else error.
8547 */
8548static void __exit
Eric Moored5d135b2009-05-18 13:02:08 -06008549_scsih_exit(void)
Eric Moore635374e2009-03-09 01:21:12 -06008550{
8551 printk(KERN_INFO "mpt2sas version %s unloading\n",
8552 MPT2SAS_DRIVER_VERSION);
8553
8554 pci_unregister_driver(&scsih_driver);
8555
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308556 mpt2sas_ctl_exit();
8557
Eric Moore635374e2009-03-09 01:21:12 -06008558 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8559 mpt2sas_base_release_callback_handler(tm_cb_idx);
8560 mpt2sas_base_release_callback_handler(base_cb_idx);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308561 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008562 mpt2sas_base_release_callback_handler(transport_cb_idx);
Kashyap, Desai744090d2009-10-05 15:56:56 +05308563 mpt2sas_base_release_callback_handler(scsih_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008564 mpt2sas_base_release_callback_handler(config_cb_idx);
8565 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8566
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308567 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308568 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308569 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8570
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308571 /* raid transport support */
8572 raid_class_release(mpt2sas_raid_template);
8573 sas_release_transport(mpt2sas_transport_template);
8574
Eric Moore635374e2009-03-09 01:21:12 -06008575}
8576
Eric Moored5d135b2009-05-18 13:02:08 -06008577module_init(_scsih_init);
8578module_exit(_scsih_exit);