blob: dd461015813f8450bc53a2c2d9581548ec7cef00 [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 Reddyd648d5a2013-07-25 11:28:01 +05305 * Copyright (C) 2007-2013 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
58#include "mpt2sas_base.h"
59
60MODULE_AUTHOR(MPT2SAS_AUTHOR);
61MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
62MODULE_LICENSE("GPL");
63MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
64
65#define RAID_CHANNEL 1
66
67/* forward proto's */
68static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
69 struct _sas_node *sas_expander);
70static void _firmware_event_work(struct work_struct *work);
71
Kashyap, Desaif3eedd62010-06-17 13:46:13 +053072static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
73
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +053074static void _scsih_scan_start(struct Scsi_Host *shost);
75static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
76
Eric Moore635374e2009-03-09 01:21:12 -060077/* global parameters */
Eric Mooreba33fad2009-03-15 21:37:18 -060078LIST_HEAD(mpt2sas_ioc_list);
Eric Moore635374e2009-03-09 01:21:12 -060079
80/* local parameters */
Eric Moore635374e2009-03-09 01:21:12 -060081static u8 scsi_io_cb_idx = -1;
82static u8 tm_cb_idx = -1;
83static u8 ctl_cb_idx = -1;
84static u8 base_cb_idx = -1;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +053085static u8 port_enable_cb_idx = -1;
Eric Moore635374e2009-03-09 01:21:12 -060086static u8 transport_cb_idx = -1;
Kashyap, Desai744090d2009-10-05 15:56:56 +053087static u8 scsih_cb_idx = -1;
Eric Moore635374e2009-03-09 01:21:12 -060088static u8 config_cb_idx = -1;
89static int mpt_ids;
90
Kashyap, Desai77e63ed2009-09-14 11:04:23 +053091static u8 tm_tr_cb_idx = -1 ;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +053092static u8 tm_tr_volume_cb_idx = -1 ;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +053093static u8 tm_sas_control_cb_idx = -1;
94
Eric Moore635374e2009-03-09 01:21:12 -060095/* command line options */
Eric Mooreba33fad2009-03-15 21:37:18 -060096static u32 logging_level;
Eric Moore635374e2009-03-09 01:21:12 -060097MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
98 "(default=0)");
99
Kashyap, Desaia3e1e552011-06-14 10:56:12 +0530100static ushort max_sectors = 0xFFFF;
101module_param(max_sectors, ushort, 0);
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +0530102MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
Kashyap, Desaia3e1e552011-06-14 10:56:12 +0530103
Reddy, Sreekanthb0df96a02013-02-26 16:59:59 +0530104static int missing_delay[2] = {-1, -1};
105module_param_array(missing_delay, int, NULL, 0);
106MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
107
Eric Moore635374e2009-03-09 01:21:12 -0600108/* scsi-mid layer global parmeter is max_report_luns, which is 511 */
109#define MPT2SAS_MAX_LUN (16895)
110static int max_lun = MPT2SAS_MAX_LUN;
111module_param(max_lun, int, 0);
112MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
113
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530114/* diag_buffer_enable is bitwise
115 * bit 0 set = TRACE
116 * bit 1 set = SNAPSHOT
117 * bit 2 set = EXTENDED
118 *
119 * Either bit can be set, or both
120 */
121static int diag_buffer_enable = -1;
122module_param(diag_buffer_enable, int, 0);
123MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
124 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
125
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +0530126static int disable_discovery = -1;
127module_param(disable_discovery, int, 0);
128MODULE_PARM_DESC(disable_discovery, " disable discovery ");
129
Martin K. Petersen5e95e732012-08-28 14:29:37 -0400130/* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
131static int prot_mask = 0;
132module_param(prot_mask, int, 0);
133MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
134
Eric Moore635374e2009-03-09 01:21:12 -0600135/**
136 * struct sense_info - common structure for obtaining sense keys
137 * @skey: sense key
138 * @asc: additional sense code
139 * @ascq: additional sense code qualifier
140 */
141struct sense_info {
142 u8 skey;
143 u8 asc;
144 u8 ascq;
145};
146
147
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530148#define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC)
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530149#define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
150#define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
Eric Moore635374e2009-03-09 01:21:12 -0600151/**
152 * struct fw_event_work - firmware event struct
153 * @list: link list framework
154 * @work: work object (ioc->fault_reset_work_q)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +0530155 * @cancel_pending_work: flag set during reset handling
Eric Moore635374e2009-03-09 01:21:12 -0600156 * @ioc: per adapter object
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530157 * @device_handle: device handle
Eric Moore635374e2009-03-09 01:21:12 -0600158 * @VF_ID: virtual function id
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530159 * @VP_ID: virtual port id
Eric Moore635374e2009-03-09 01:21:12 -0600160 * @ignore: flag meaning this event has been marked to ignore
161 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
162 * @event_data: reply event data payload follows
163 *
164 * This object stored on ioc->fw_event_list.
165 */
166struct fw_event_work {
167 struct list_head list;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +0530168 u8 cancel_pending_work;
169 struct delayed_work delayed_work;
Eric Moore635374e2009-03-09 01:21:12 -0600170 struct MPT2SAS_ADAPTER *ioc;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530171 u16 device_handle;
Eric Moore635374e2009-03-09 01:21:12 -0600172 u8 VF_ID;
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530173 u8 VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -0600174 u8 ignore;
175 u16 event;
Joe Lawrence00713ad2014-06-25 17:03:33 -0400176 char event_data[0] __aligned(4);
Eric Moore635374e2009-03-09 01:21:12 -0600177};
178
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +0530179/* raid transport support */
180static struct raid_template *mpt2sas_raid_template;
181
Eric Moore635374e2009-03-09 01:21:12 -0600182/**
183 * struct _scsi_io_transfer - scsi io transfer
184 * @handle: sas device handle (assigned by firmware)
185 * @is_raid: flag set for hidden raid components
186 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
187 * @data_length: data transfer length
188 * @data_dma: dma pointer to data
189 * @sense: sense data
190 * @lun: lun number
191 * @cdb_length: cdb length
192 * @cdb: cdb contents
Eric Moore635374e2009-03-09 01:21:12 -0600193 * @timeout: timeout for this command
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530194 * @VF_ID: virtual function id
195 * @VP_ID: virtual port id
196 * @valid_reply: flag set for reply message
Eric Moore635374e2009-03-09 01:21:12 -0600197 * @sense_length: sense length
198 * @ioc_status: ioc status
199 * @scsi_state: scsi state
200 * @scsi_status: scsi staus
201 * @log_info: log information
202 * @transfer_length: data length transfer when there is a reply message
203 *
204 * Used for sending internal scsi commands to devices within this module.
205 * Refer to _scsi_send_scsi_io().
206 */
207struct _scsi_io_transfer {
208 u16 handle;
209 u8 is_raid;
210 enum dma_data_direction dir;
211 u32 data_length;
212 dma_addr_t data_dma;
213 u8 sense[SCSI_SENSE_BUFFERSIZE];
214 u32 lun;
215 u8 cdb_length;
216 u8 cdb[32];
217 u8 timeout;
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530218 u8 VF_ID;
219 u8 VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -0600220 u8 valid_reply;
221 /* the following bits are only valid when 'valid_reply = 1' */
222 u32 sense_length;
223 u16 ioc_status;
224 u8 scsi_state;
225 u8 scsi_status;
226 u32 log_info;
227 u32 transfer_length;
228};
229
230/*
231 * The pci device ids are defined in mpi/mpi2_cnfg.h.
232 */
233static struct pci_device_id scsih_pci_table[] = {
234 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
235 PCI_ANY_ID, PCI_ANY_ID },
236 /* Falcon ~ 2008*/
237 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
238 PCI_ANY_ID, PCI_ANY_ID },
239 /* Liberator ~ 2108 */
240 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
241 PCI_ANY_ID, PCI_ANY_ID },
242 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
243 PCI_ANY_ID, PCI_ANY_ID },
244 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
245 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desaidb271362009-09-23 17:24:27 +0530246 /* Meteor ~ 2116 */
Eric Moore635374e2009-03-09 01:21:12 -0600247 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
248 PCI_ANY_ID, PCI_ANY_ID },
249 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
250 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desaidb271362009-09-23 17:24:27 +0530251 /* Thunderbolt ~ 2208 */
252 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
253 PCI_ANY_ID, PCI_ANY_ID },
254 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
255 PCI_ANY_ID, PCI_ANY_ID },
256 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
257 PCI_ANY_ID, PCI_ANY_ID },
258 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
259 PCI_ANY_ID, PCI_ANY_ID },
260 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
261 PCI_ANY_ID, PCI_ANY_ID },
262 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
263 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai203d65b2010-06-17 13:37:59 +0530264 /* Mustang ~ 2308 */
265 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
Kashyap, Desaidb271362009-09-23 17:24:27 +0530266 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai203d65b2010-06-17 13:37:59 +0530267 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
268 PCI_ANY_ID, PCI_ANY_ID },
269 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
Kashyap, Desaidb271362009-09-23 17:24:27 +0530270 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +0530271 /* SSS6200 */
272 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
273 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore635374e2009-03-09 01:21:12 -0600274 {0} /* Terminating entry */
275};
276MODULE_DEVICE_TABLE(pci, scsih_pci_table);
277
278/**
Eric Moored5d135b2009-05-18 13:02:08 -0600279 * _scsih_set_debug_level - global setting of ioc->logging_level.
Eric Moore635374e2009-03-09 01:21:12 -0600280 *
281 * Note: The logging levels are defined in mpt2sas_debug.h.
282 */
283static int
Eric Moored5d135b2009-05-18 13:02:08 -0600284_scsih_set_debug_level(const char *val, struct kernel_param *kp)
Eric Moore635374e2009-03-09 01:21:12 -0600285{
286 int ret = param_set_int(val, kp);
287 struct MPT2SAS_ADAPTER *ioc;
288
289 if (ret)
290 return ret;
291
292 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
Eric Mooreba33fad2009-03-15 21:37:18 -0600293 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
Eric Moore635374e2009-03-09 01:21:12 -0600294 ioc->logging_level = logging_level;
295 return 0;
296}
Eric Moored5d135b2009-05-18 13:02:08 -0600297module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
Eric Moore635374e2009-03-09 01:21:12 -0600298 &logging_level, 0644);
299
300/**
301 * _scsih_srch_boot_sas_address - search based on sas_address
302 * @sas_address: sas address
303 * @boot_device: boot device object from bios page 2
304 *
305 * Returns 1 when there's a match, 0 means no match.
306 */
307static inline int
308_scsih_srch_boot_sas_address(u64 sas_address,
309 Mpi2BootDeviceSasWwid_t *boot_device)
310{
311 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
312}
313
314/**
315 * _scsih_srch_boot_device_name - search based on device name
316 * @device_name: device name specified in INDENTIFY fram
317 * @boot_device: boot device object from bios page 2
318 *
319 * Returns 1 when there's a match, 0 means no match.
320 */
321static inline int
322_scsih_srch_boot_device_name(u64 device_name,
323 Mpi2BootDeviceDeviceName_t *boot_device)
324{
325 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
326}
327
328/**
329 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
330 * @enclosure_logical_id: enclosure logical id
331 * @slot_number: slot number
332 * @boot_device: boot device object from bios page 2
333 *
334 * Returns 1 when there's a match, 0 means no match.
335 */
336static inline int
337_scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
338 Mpi2BootDeviceEnclosureSlot_t *boot_device)
339{
340 return (enclosure_logical_id == le64_to_cpu(boot_device->
341 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
342 SlotNumber)) ? 1 : 0;
343}
344
345/**
346 * _scsih_is_boot_device - search for matching boot device.
347 * @sas_address: sas address
348 * @device_name: device name specified in INDENTIFY fram
349 * @enclosure_logical_id: enclosure logical id
350 * @slot_number: slot number
351 * @form: specifies boot device form
352 * @boot_device: boot device object from bios page 2
353 *
354 * Returns 1 when there's a match, 0 means no match.
355 */
356static int
357_scsih_is_boot_device(u64 sas_address, u64 device_name,
358 u64 enclosure_logical_id, u16 slot, u8 form,
359 Mpi2BiosPage2BootDevice_t *boot_device)
360{
361 int rc = 0;
362
363 switch (form) {
364 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
365 if (!sas_address)
366 break;
367 rc = _scsih_srch_boot_sas_address(
368 sas_address, &boot_device->SasWwid);
369 break;
370 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
371 if (!enclosure_logical_id)
372 break;
373 rc = _scsih_srch_boot_encl_slot(
374 enclosure_logical_id,
375 slot, &boot_device->EnclosureSlot);
376 break;
377 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
378 if (!device_name)
379 break;
380 rc = _scsih_srch_boot_device_name(
381 device_name, &boot_device->DeviceName);
382 break;
383 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
384 break;
385 }
386
387 return rc;
388}
389
390/**
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530391 * _scsih_get_sas_address - set the sas_address for given device handle
392 * @handle: device handle
393 * @sas_address: sas address
394 *
395 * Returns 0 success, non-zero when failure
396 */
397static int
398_scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
399 u64 *sas_address)
400{
401 Mpi2SasDevicePage0_t sas_device_pg0;
402 Mpi2ConfigReply_t mpi_reply;
403 u32 ioc_status;
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530404 *sas_address = 0;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530405
406 if (handle <= ioc->sas_hba.num_phys) {
407 *sas_address = ioc->sas_hba.sas_address;
408 return 0;
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530409 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530410
411 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
412 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530413 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
414 __FILE__, __LINE__, __func__);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530415 return -ENXIO;
416 }
417
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530418 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
419 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
420 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
421 return 0;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530422 }
423
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530424 /* we hit this becuase the given parent handle doesn't exist */
425 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
426 return -ENXIO;
427 /* else error case */
428 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
429 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
430 __FILE__, __LINE__, __func__);
431 return -EIO;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530432}
433
434/**
Eric Moore635374e2009-03-09 01:21:12 -0600435 * _scsih_determine_boot_device - determine boot device.
436 * @ioc: per adapter object
437 * @device: either sas_device or raid_device object
438 * @is_raid: [flag] 1 = raid object, 0 = sas object
439 *
440 * Determines whether this device should be first reported device to
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300441 * to scsi-ml or sas transport, this purpose is for persistent boot device.
Eric Moore635374e2009-03-09 01:21:12 -0600442 * There are primary, alternate, and current entries in bios page 2. The order
443 * priority is primary, alternate, then current. This routine saves
444 * the corresponding device object and is_raid flag in the ioc object.
445 * The saved data to be used later in _scsih_probe_boot_devices().
446 */
447static void
448_scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
449 void *device, u8 is_raid)
450{
451 struct _sas_device *sas_device;
452 struct _raid_device *raid_device;
453 u64 sas_address;
454 u64 device_name;
455 u64 enclosure_logical_id;
456 u16 slot;
457
458 /* only process this function when driver loads */
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530459 if (!ioc->is_driver_loading)
460 return;
461
462 /* no Bios, return immediately */
463 if (!ioc->bios_pg3.BiosVersion)
Eric Moore635374e2009-03-09 01:21:12 -0600464 return;
465
466 if (!is_raid) {
467 sas_device = device;
468 sas_address = sas_device->sas_address;
469 device_name = sas_device->device_name;
470 enclosure_logical_id = sas_device->enclosure_logical_id;
471 slot = sas_device->slot;
472 } else {
473 raid_device = device;
474 sas_address = raid_device->wwid;
475 device_name = 0;
476 enclosure_logical_id = 0;
477 slot = 0;
478 }
479
480 if (!ioc->req_boot_device.device) {
481 if (_scsih_is_boot_device(sas_address, device_name,
482 enclosure_logical_id, slot,
483 (ioc->bios_pg2.ReqBootDeviceForm &
484 MPI2_BIOSPAGE2_FORM_MASK),
485 &ioc->bios_pg2.RequestedBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530486 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600487 "%s: req_boot_device(0x%016llx)\n",
488 ioc->name, __func__,
489 (unsigned long long)sas_address));
490 ioc->req_boot_device.device = device;
491 ioc->req_boot_device.is_raid = is_raid;
492 }
493 }
494
495 if (!ioc->req_alt_boot_device.device) {
496 if (_scsih_is_boot_device(sas_address, device_name,
497 enclosure_logical_id, slot,
498 (ioc->bios_pg2.ReqAltBootDeviceForm &
499 MPI2_BIOSPAGE2_FORM_MASK),
500 &ioc->bios_pg2.RequestedAltBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530501 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600502 "%s: req_alt_boot_device(0x%016llx)\n",
503 ioc->name, __func__,
504 (unsigned long long)sas_address));
505 ioc->req_alt_boot_device.device = device;
506 ioc->req_alt_boot_device.is_raid = is_raid;
507 }
508 }
509
510 if (!ioc->current_boot_device.device) {
511 if (_scsih_is_boot_device(sas_address, device_name,
512 enclosure_logical_id, slot,
513 (ioc->bios_pg2.CurrentBootDeviceForm &
514 MPI2_BIOSPAGE2_FORM_MASK),
515 &ioc->bios_pg2.CurrentBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530516 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600517 "%s: current_boot_device(0x%016llx)\n",
518 ioc->name, __func__,
519 (unsigned long long)sas_address));
520 ioc->current_boot_device.device = device;
521 ioc->current_boot_device.is_raid = is_raid;
522 }
523 }
524}
525
526/**
527 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
528 * @ioc: per adapter object
529 * @sas_address: sas address
530 * Context: Calling function should acquire ioc->sas_device_lock
531 *
532 * This searches for sas_device based on sas_address, then return sas_device
533 * object.
534 */
535struct _sas_device *
536mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
537 u64 sas_address)
538{
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530539 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600540
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530541 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
542 if (sas_device->sas_address == sas_address)
543 return sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600544
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530545 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
546 if (sas_device->sas_address == sas_address)
547 return sas_device;
548
549 return NULL;
Eric Moore635374e2009-03-09 01:21:12 -0600550}
551
552/**
553 * _scsih_sas_device_find_by_handle - sas device search
554 * @ioc: per adapter object
555 * @handle: sas device handle (assigned by firmware)
556 * Context: Calling function should acquire ioc->sas_device_lock
557 *
558 * This searches for sas_device based on sas_address, then return sas_device
559 * object.
560 */
561static struct _sas_device *
562_scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
563{
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530564 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600565
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530566 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
567 if (sas_device->handle == handle)
568 return sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600569
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530570 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
571 if (sas_device->handle == handle)
572 return sas_device;
573
574 return NULL;
Eric Moore635374e2009-03-09 01:21:12 -0600575}
576
577/**
578 * _scsih_sas_device_remove - remove sas_device from list.
579 * @ioc: per adapter object
580 * @sas_device: the sas_device object
581 * Context: This function will acquire ioc->sas_device_lock.
582 *
583 * Removing object and freeing associated memory from the ioc->sas_device_list.
584 */
585static void
586_scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
587 struct _sas_device *sas_device)
588{
589 unsigned long flags;
590
Kashyap, Desai980ead32010-04-08 17:55:22 +0530591 if (!sas_device)
592 return;
593
Eric Moore635374e2009-03-09 01:21:12 -0600594 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530595 list_del(&sas_device->list);
596 kfree(sas_device);
Eric Moore635374e2009-03-09 01:21:12 -0600597 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
598}
599
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530600
Eric Moore635374e2009-03-09 01:21:12 -0600601/**
602 * _scsih_sas_device_add - insert sas_device to the list.
603 * @ioc: per adapter object
604 * @sas_device: the sas_device object
605 * Context: This function will acquire ioc->sas_device_lock.
606 *
607 * Adding new object to the ioc->sas_device_list.
608 */
609static void
610_scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
611 struct _sas_device *sas_device)
612{
613 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -0600614
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530615 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600616 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
617 sas_device->handle, (unsigned long long)sas_device->sas_address));
618
619 spin_lock_irqsave(&ioc->sas_device_lock, flags);
620 list_add_tail(&sas_device->list, &ioc->sas_device_list);
621 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
622
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530623 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +0530624 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -0600625 _scsih_sas_device_remove(ioc, sas_device);
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +0530626 } else if (!sas_device->starget) {
627 /* When asyn scanning is enabled, its not possible to remove
628 * devices while scanning is turned on due to an oops in
629 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
630 */
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +0530631 if (!ioc->is_driver_loading) {
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +0530632 mpt2sas_transport_port_remove(ioc,
633 sas_device->sas_address,
634 sas_device->sas_address_parent);
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +0530635 _scsih_sas_device_remove(ioc, sas_device);
636 }
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +0530637 }
Eric Moore635374e2009-03-09 01:21:12 -0600638}
639
640/**
641 * _scsih_sas_device_init_add - insert sas_device to the list.
642 * @ioc: per adapter object
643 * @sas_device: the sas_device object
644 * Context: This function will acquire ioc->sas_device_lock.
645 *
646 * Adding new object at driver load time to the ioc->sas_device_init_list.
647 */
648static void
649_scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
650 struct _sas_device *sas_device)
651{
652 unsigned long flags;
653
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530654 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600655 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
656 sas_device->handle, (unsigned long long)sas_device->sas_address));
657
658 spin_lock_irqsave(&ioc->sas_device_lock, flags);
659 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
Eric Moore635374e2009-03-09 01:21:12 -0600660 _scsih_determine_boot_device(ioc, sas_device, 0);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530661 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -0600662}
663
664/**
Eric Moore635374e2009-03-09 01:21:12 -0600665 * _scsih_raid_device_find_by_id - raid device search
666 * @ioc: per adapter object
667 * @id: sas device target id
668 * @channel: sas device channel
669 * Context: Calling function should acquire ioc->raid_device_lock
670 *
671 * This searches for raid_device based on target id, then return raid_device
672 * object.
673 */
674static struct _raid_device *
675_scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
676{
677 struct _raid_device *raid_device, *r;
678
679 r = NULL;
680 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
681 if (raid_device->id == id && raid_device->channel == channel) {
682 r = raid_device;
683 goto out;
684 }
685 }
686
687 out:
688 return r;
689}
690
691/**
692 * _scsih_raid_device_find_by_handle - raid device search
693 * @ioc: per adapter object
694 * @handle: sas device handle (assigned by firmware)
695 * Context: Calling function should acquire ioc->raid_device_lock
696 *
697 * This searches for raid_device based on handle, then return raid_device
698 * object.
699 */
700static struct _raid_device *
701_scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
702{
703 struct _raid_device *raid_device, *r;
704
705 r = NULL;
706 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
707 if (raid_device->handle != handle)
708 continue;
709 r = raid_device;
710 goto out;
711 }
712
713 out:
714 return r;
715}
716
717/**
718 * _scsih_raid_device_find_by_wwid - raid device search
719 * @ioc: per adapter object
720 * @handle: sas device handle (assigned by firmware)
721 * Context: Calling function should acquire ioc->raid_device_lock
722 *
723 * This searches for raid_device based on wwid, then return raid_device
724 * object.
725 */
726static struct _raid_device *
727_scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
728{
729 struct _raid_device *raid_device, *r;
730
731 r = NULL;
732 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
733 if (raid_device->wwid != wwid)
734 continue;
735 r = raid_device;
736 goto out;
737 }
738
739 out:
740 return r;
741}
742
743/**
744 * _scsih_raid_device_add - add raid_device object
745 * @ioc: per adapter object
746 * @raid_device: raid_device object
747 *
748 * This is added to the raid_device_list link list.
749 */
750static void
751_scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
752 struct _raid_device *raid_device)
753{
754 unsigned long flags;
755
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530756 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600757 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
758 raid_device->handle, (unsigned long long)raid_device->wwid));
759
760 spin_lock_irqsave(&ioc->raid_device_lock, flags);
761 list_add_tail(&raid_device->list, &ioc->raid_device_list);
762 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
763}
764
765/**
766 * _scsih_raid_device_remove - delete raid_device object
767 * @ioc: per adapter object
768 * @raid_device: raid_device object
769 *
Eric Moore635374e2009-03-09 01:21:12 -0600770 */
771static void
772_scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
773 struct _raid_device *raid_device)
774{
775 unsigned long flags;
776
777 spin_lock_irqsave(&ioc->raid_device_lock, flags);
778 list_del(&raid_device->list);
Eric Moore635374e2009-03-09 01:21:12 -0600779 kfree(raid_device);
780 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
781}
782
783/**
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530784 * mpt2sas_scsih_expander_find_by_handle - expander device search
785 * @ioc: per adapter object
786 * @handle: expander handle (assigned by firmware)
787 * Context: Calling function should acquire ioc->sas_device_lock
788 *
789 * This searches for expander device based on handle, then returns the
790 * sas_node object.
791 */
792struct _sas_node *
793mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
794{
795 struct _sas_node *sas_expander, *r;
796
797 r = NULL;
798 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
799 if (sas_expander->handle != handle)
800 continue;
801 r = sas_expander;
802 goto out;
803 }
804 out:
805 return r;
806}
807
808/**
Eric Moore635374e2009-03-09 01:21:12 -0600809 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
810 * @ioc: per adapter object
811 * @sas_address: sas address
812 * Context: Calling function should acquire ioc->sas_node_lock.
813 *
814 * This searches for expander device based on sas_address, then returns the
815 * sas_node object.
816 */
817struct _sas_node *
818mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
819 u64 sas_address)
820{
821 struct _sas_node *sas_expander, *r;
822
823 r = NULL;
824 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
825 if (sas_expander->sas_address != sas_address)
826 continue;
827 r = sas_expander;
828 goto out;
829 }
830 out:
831 return r;
832}
833
834/**
835 * _scsih_expander_node_add - insert expander device to the list.
836 * @ioc: per adapter object
837 * @sas_expander: the sas_device object
838 * Context: This function will acquire ioc->sas_node_lock.
839 *
840 * Adding new object to the ioc->sas_expander_list.
841 *
842 * Return nothing.
843 */
844static void
845_scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
846 struct _sas_node *sas_expander)
847{
848 unsigned long flags;
849
850 spin_lock_irqsave(&ioc->sas_node_lock, flags);
851 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
852 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
853}
854
855/**
856 * _scsih_is_end_device - determines if device is an end device
857 * @device_info: bitfield providing information about the device.
858 * Context: none
859 *
860 * Returns 1 if end device.
861 */
862static int
863_scsih_is_end_device(u32 device_info)
864{
865 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
866 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
867 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
868 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
869 return 1;
870 else
871 return 0;
872}
873
874/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530875 * _scsih_scsi_lookup_get - returns scmd entry
Eric Moore635374e2009-03-09 01:21:12 -0600876 * @ioc: per adapter object
877 * @smid: system request message index
Eric Moore635374e2009-03-09 01:21:12 -0600878 *
879 * Returns the smid stored scmd pointer.
880 */
881static struct scsi_cmnd *
882_scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
883{
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530884 return ioc->scsi_lookup[smid - 1].scmd;
Eric Moore635374e2009-03-09 01:21:12 -0600885}
886
887/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530888 * _scsih_scsi_lookup_get_clear - returns scmd entry
889 * @ioc: per adapter object
890 * @smid: system request message index
891 *
892 * Returns the smid stored scmd pointer.
893 * Then will derefrence the stored scmd pointer.
894 */
895static inline struct scsi_cmnd *
896_scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
897{
898 unsigned long flags;
899 struct scsi_cmnd *scmd;
900
901 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
902 scmd = ioc->scsi_lookup[smid - 1].scmd;
903 ioc->scsi_lookup[smid - 1].scmd = NULL;
904 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
905
906 return scmd;
907}
908
909/**
Eric Moore635374e2009-03-09 01:21:12 -0600910 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
911 * @ioc: per adapter object
912 * @smid: system request message index
913 * @scmd: pointer to scsi command object
914 * Context: This function will acquire ioc->scsi_lookup_lock.
915 *
916 * This will search for a scmd pointer in the scsi_lookup array,
917 * returning the revelent smid. A returned value of zero means invalid.
918 */
919static u16
920_scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
921 *scmd)
922{
923 u16 smid;
924 unsigned long flags;
925 int i;
926
927 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
928 smid = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530929 for (i = 0; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600930 if (ioc->scsi_lookup[i].scmd == scmd) {
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530931 smid = ioc->scsi_lookup[i].smid;
Eric Moore635374e2009-03-09 01:21:12 -0600932 goto out;
933 }
934 }
935 out:
936 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
937 return smid;
938}
939
940/**
941 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
942 * @ioc: per adapter object
943 * @id: target id
944 * @channel: channel
945 * Context: This function will acquire ioc->scsi_lookup_lock.
946 *
947 * This will search for a matching channel:id in the scsi_lookup array,
948 * returning 1 if found.
949 */
950static u8
951_scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
952 int channel)
953{
954 u8 found;
955 unsigned long flags;
956 int i;
957
958 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
959 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530960 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600961 if (ioc->scsi_lookup[i].scmd &&
962 (ioc->scsi_lookup[i].scmd->device->id == id &&
963 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
964 found = 1;
965 goto out;
966 }
967 }
968 out:
969 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
970 return found;
971}
972
973/**
Eric Moore993e0da2009-05-18 13:00:45 -0600974 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
975 * @ioc: per adapter object
976 * @id: target id
977 * @lun: lun number
978 * @channel: channel
979 * Context: This function will acquire ioc->scsi_lookup_lock.
980 *
981 * This will search for a matching channel:id:lun in the scsi_lookup array,
982 * returning 1 if found.
983 */
984static u8
985_scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
986 unsigned int lun, int channel)
987{
988 u8 found;
989 unsigned long flags;
990 int i;
991
992 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
993 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530994 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore993e0da2009-05-18 13:00:45 -0600995 if (ioc->scsi_lookup[i].scmd &&
996 (ioc->scsi_lookup[i].scmd->device->id == id &&
997 ioc->scsi_lookup[i].scmd->device->channel == channel &&
998 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
999 found = 1;
1000 goto out;
1001 }
1002 }
1003 out:
1004 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1005 return found;
1006}
1007
1008/**
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301009 * _scsih_get_chain_buffer_tracker - obtain chain tracker
Eric Moore635374e2009-03-09 01:21:12 -06001010 * @ioc: per adapter object
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301011 * @smid: smid associated to an IO request
Eric Moore635374e2009-03-09 01:21:12 -06001012 *
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301013 * Returns chain tracker(from ioc->free_chain_list)
Eric Moore635374e2009-03-09 01:21:12 -06001014 */
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301015static struct chain_tracker *
1016_scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
Eric Moore635374e2009-03-09 01:21:12 -06001017{
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301018 struct chain_tracker *chain_req;
1019 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001020
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301021 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1022 if (list_empty(&ioc->free_chain_list)) {
1023 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
nagalakshmi.nandigama@lsi.comaff132d2011-12-01 07:53:08 +05301024 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not "
1025 "available\n", ioc->name));
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301026 return NULL;
1027 }
1028 chain_req = list_entry(ioc->free_chain_list.next,
1029 struct chain_tracker, tracker_list);
1030 list_del_init(&chain_req->tracker_list);
1031 list_add_tail(&chain_req->tracker_list,
1032 &ioc->scsi_lookup[smid - 1].chain_list);
1033 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1034 return chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001035}
1036
1037/**
1038 * _scsih_build_scatter_gather - main sg creation routine
1039 * @ioc: per adapter object
1040 * @scmd: scsi command
1041 * @smid: system request message index
1042 * Context: none.
1043 *
1044 * The main routine that builds scatter gather table from a given
1045 * scsi request sent via the .queuecommand main handler.
1046 *
1047 * Returns 0 success, anything else error
1048 */
1049static int
1050_scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1051 struct scsi_cmnd *scmd, u16 smid)
1052{
1053 Mpi2SCSIIORequest_t *mpi_request;
1054 dma_addr_t chain_dma;
1055 struct scatterlist *sg_scmd;
1056 void *sg_local, *chain;
1057 u32 chain_offset;
1058 u32 chain_length;
1059 u32 chain_flags;
FUJITA Tomonoribb789d02010-03-09 11:09:50 +09001060 int sges_left;
Eric Moore635374e2009-03-09 01:21:12 -06001061 u32 sges_in_segment;
1062 u32 sgl_flags;
1063 u32 sgl_flags_last_element;
1064 u32 sgl_flags_end_buffer;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301065 struct chain_tracker *chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001066
1067 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1068
1069 /* init scatter gather flags */
1070 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1071 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1072 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1073 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1074 << MPI2_SGE_FLAGS_SHIFT;
1075 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1076 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1077 << MPI2_SGE_FLAGS_SHIFT;
1078 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1079
1080 sg_scmd = scsi_sglist(scmd);
1081 sges_left = scsi_dma_map(scmd);
FUJITA Tomonoribb789d02010-03-09 11:09:50 +09001082 if (sges_left < 0) {
Eric Moore635374e2009-03-09 01:21:12 -06001083 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1084 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1085 return -ENOMEM;
1086 }
1087
1088 sg_local = &mpi_request->SGL;
1089 sges_in_segment = ioc->max_sges_in_main_message;
1090 if (sges_left <= sges_in_segment)
1091 goto fill_in_last_segment;
1092
1093 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1094 (sges_in_segment * ioc->sge_size))/4;
1095
1096 /* fill in main message segment when there is a chain following */
1097 while (sges_in_segment) {
1098 if (sges_in_segment == 1)
1099 ioc->base_add_sg_single(sg_local,
1100 sgl_flags_last_element | sg_dma_len(sg_scmd),
1101 sg_dma_address(sg_scmd));
1102 else
1103 ioc->base_add_sg_single(sg_local, sgl_flags |
1104 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1105 sg_scmd = sg_next(sg_scmd);
1106 sg_local += ioc->sge_size;
1107 sges_left--;
1108 sges_in_segment--;
1109 }
1110
1111 /* initializing the chain flags and pointers */
1112 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301113 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1114 if (!chain_req)
1115 return -1;
1116 chain = chain_req->chain_buffer;
1117 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001118 do {
1119 sges_in_segment = (sges_left <=
1120 ioc->max_sges_in_chain_message) ? sges_left :
1121 ioc->max_sges_in_chain_message;
1122 chain_offset = (sges_left == sges_in_segment) ?
1123 0 : (sges_in_segment * ioc->sge_size)/4;
1124 chain_length = sges_in_segment * ioc->sge_size;
1125 if (chain_offset) {
1126 chain_offset = chain_offset <<
1127 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1128 chain_length += ioc->sge_size;
1129 }
1130 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1131 chain_length, chain_dma);
1132 sg_local = chain;
1133 if (!chain_offset)
1134 goto fill_in_last_segment;
1135
1136 /* fill in chain segments */
1137 while (sges_in_segment) {
1138 if (sges_in_segment == 1)
1139 ioc->base_add_sg_single(sg_local,
1140 sgl_flags_last_element |
1141 sg_dma_len(sg_scmd),
1142 sg_dma_address(sg_scmd));
1143 else
1144 ioc->base_add_sg_single(sg_local, sgl_flags |
1145 sg_dma_len(sg_scmd),
1146 sg_dma_address(sg_scmd));
1147 sg_scmd = sg_next(sg_scmd);
1148 sg_local += ioc->sge_size;
1149 sges_left--;
1150 sges_in_segment--;
1151 }
1152
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301153 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1154 if (!chain_req)
1155 return -1;
1156 chain = chain_req->chain_buffer;
1157 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001158 } while (1);
1159
1160
1161 fill_in_last_segment:
1162
1163 /* fill the last segment */
1164 while (sges_left) {
1165 if (sges_left == 1)
1166 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1167 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1168 else
1169 ioc->base_add_sg_single(sg_local, sgl_flags |
1170 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1171 sg_scmd = sg_next(sg_scmd);
1172 sg_local += ioc->sge_size;
1173 sges_left--;
1174 }
1175
1176 return 0;
1177}
1178
1179/**
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301180 * _scsih_adjust_queue_depth - setting device queue depth
Eric Moore635374e2009-03-09 01:21:12 -06001181 * @sdev: scsi device struct
1182 * @qdepth: requested queue depth
1183 *
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301184 *
1185 * Returns nothing
Eric Moore635374e2009-03-09 01:21:12 -06001186 */
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301187static void
1188_scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
Eric Moore635374e2009-03-09 01:21:12 -06001189{
1190 struct Scsi_Host *shost = sdev->host;
1191 int max_depth;
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301192 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1193 struct MPT2SAS_DEVICE *sas_device_priv_data;
1194 struct MPT2SAS_TARGET *sas_target_priv_data;
1195 struct _sas_device *sas_device;
1196 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001197
1198 max_depth = shost->can_queue;
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301199
1200 /* limit max device queue for SATA to 32 */
1201 sas_device_priv_data = sdev->hostdata;
1202 if (!sas_device_priv_data)
1203 goto not_sata;
1204 sas_target_priv_data = sas_device_priv_data->sas_target;
1205 if (!sas_target_priv_data)
1206 goto not_sata;
1207 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1208 goto not_sata;
1209 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1210 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1211 sas_device_priv_data->sas_target->sas_address);
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301212 if (sas_device && sas_device->device_info &
1213 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1214 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301215 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301216
1217 not_sata:
1218
Eric Moore635374e2009-03-09 01:21:12 -06001219 if (!sdev->tagged_supported)
1220 max_depth = 1;
1221 if (qdepth > max_depth)
1222 qdepth = max_depth;
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301223 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1224}
1225
1226/**
1227 * _scsih_change_queue_depth - setting device queue depth
1228 * @sdev: scsi device struct
1229 * @qdepth: requested queue depth
1230 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1231 * (see include/scsi/scsi_host.h for definition)
1232 *
1233 * Returns queue depth.
1234 */
1235static int
1236_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1237{
1238 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1239 _scsih_adjust_queue_depth(sdev, qdepth);
1240 else if (reason == SCSI_QDEPTH_QFULL)
1241 scsi_track_queue_full(sdev, qdepth);
1242 else
1243 return -EOPNOTSUPP;
Eric Moore635374e2009-03-09 01:21:12 -06001244
1245 if (sdev->inquiry_len > 7)
1246 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1247 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1248 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1249 sdev->ordered_tags, sdev->scsi_level,
1250 (sdev->inquiry[7] & 2) >> 1);
1251
1252 return sdev->queue_depth;
1253}
1254
1255/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05301256 * _scsih_change_queue_type - changing device queue tag type
Eric Moore635374e2009-03-09 01:21:12 -06001257 * @sdev: scsi device struct
1258 * @tag_type: requested tag type
1259 *
1260 * Returns queue tag type.
1261 */
1262static int
Eric Moored5d135b2009-05-18 13:02:08 -06001263_scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
Eric Moore635374e2009-03-09 01:21:12 -06001264{
1265 if (sdev->tagged_supported) {
1266 scsi_set_tag_type(sdev, tag_type);
1267 if (tag_type)
1268 scsi_activate_tcq(sdev, sdev->queue_depth);
1269 else
1270 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1271 } else
1272 tag_type = 0;
1273
1274 return tag_type;
1275}
1276
1277/**
Eric Moored5d135b2009-05-18 13:02:08 -06001278 * _scsih_target_alloc - target add routine
Eric Moore635374e2009-03-09 01:21:12 -06001279 * @starget: scsi target struct
1280 *
1281 * Returns 0 if ok. Any other return is assumed to be an error and
1282 * the device is ignored.
1283 */
1284static int
Eric Moored5d135b2009-05-18 13:02:08 -06001285_scsih_target_alloc(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001286{
1287 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1288 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1289 struct MPT2SAS_TARGET *sas_target_priv_data;
1290 struct _sas_device *sas_device;
1291 struct _raid_device *raid_device;
1292 unsigned long flags;
1293 struct sas_rphy *rphy;
1294
Joe Lawrencefeafe7c2014-06-25 17:03:14 -04001295 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1296 GFP_KERNEL);
Eric Moore635374e2009-03-09 01:21:12 -06001297 if (!sas_target_priv_data)
1298 return -ENOMEM;
1299
1300 starget->hostdata = sas_target_priv_data;
1301 sas_target_priv_data->starget = starget;
1302 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1303
1304 /* RAID volumes */
1305 if (starget->channel == RAID_CHANNEL) {
1306 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1307 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1308 starget->channel);
1309 if (raid_device) {
1310 sas_target_priv_data->handle = raid_device->handle;
1311 sas_target_priv_data->sas_address = raid_device->wwid;
1312 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301313 if (ioc->is_warpdrive)
1314 sas_target_priv_data->raid_device = raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06001315 raid_device->starget = starget;
1316 }
1317 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1318 return 0;
1319 }
1320
1321 /* sas/sata devices */
1322 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1323 rphy = dev_to_rphy(starget->dev.parent);
1324 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1325 rphy->identify.sas_address);
1326
1327 if (sas_device) {
1328 sas_target_priv_data->handle = sas_device->handle;
1329 sas_target_priv_data->sas_address = sas_device->sas_address;
1330 sas_device->starget = starget;
1331 sas_device->id = starget->id;
1332 sas_device->channel = starget->channel;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05301333 if (test_bit(sas_device->handle, ioc->pd_handles))
Eric Moore635374e2009-03-09 01:21:12 -06001334 sas_target_priv_data->flags |=
1335 MPT_TARGET_FLAGS_RAID_COMPONENT;
1336 }
1337 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1338
1339 return 0;
1340}
1341
1342/**
Eric Moored5d135b2009-05-18 13:02:08 -06001343 * _scsih_target_destroy - target destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001344 * @starget: scsi target struct
1345 *
1346 * Returns nothing.
1347 */
1348static void
Eric Moored5d135b2009-05-18 13:02:08 -06001349_scsih_target_destroy(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001350{
1351 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1352 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1353 struct MPT2SAS_TARGET *sas_target_priv_data;
1354 struct _sas_device *sas_device;
1355 struct _raid_device *raid_device;
1356 unsigned long flags;
1357 struct sas_rphy *rphy;
1358
1359 sas_target_priv_data = starget->hostdata;
1360 if (!sas_target_priv_data)
1361 return;
1362
1363 if (starget->channel == RAID_CHANNEL) {
1364 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1365 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1366 starget->channel);
1367 if (raid_device) {
1368 raid_device->starget = NULL;
1369 raid_device->sdev = NULL;
1370 }
1371 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1372 goto out;
1373 }
1374
1375 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1376 rphy = dev_to_rphy(starget->dev.parent);
1377 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1378 rphy->identify.sas_address);
Eric Moore8901cbb2009-04-21 15:41:32 -06001379 if (sas_device && (sas_device->starget == starget) &&
1380 (sas_device->id == starget->id) &&
1381 (sas_device->channel == starget->channel))
Eric Moore635374e2009-03-09 01:21:12 -06001382 sas_device->starget = NULL;
1383
1384 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1385
1386 out:
1387 kfree(sas_target_priv_data);
1388 starget->hostdata = NULL;
1389}
1390
1391/**
Eric Moored5d135b2009-05-18 13:02:08 -06001392 * _scsih_slave_alloc - device add routine
Eric Moore635374e2009-03-09 01:21:12 -06001393 * @sdev: scsi device struct
1394 *
1395 * Returns 0 if ok. Any other return is assumed to be an error and
1396 * the device is ignored.
1397 */
1398static int
Eric Moored5d135b2009-05-18 13:02:08 -06001399_scsih_slave_alloc(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001400{
1401 struct Scsi_Host *shost;
1402 struct MPT2SAS_ADAPTER *ioc;
1403 struct MPT2SAS_TARGET *sas_target_priv_data;
1404 struct MPT2SAS_DEVICE *sas_device_priv_data;
1405 struct scsi_target *starget;
1406 struct _raid_device *raid_device;
Sreekanth Reddy63e359d2013-07-25 11:32:51 +05301407 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -06001408 unsigned long flags;
1409
Joe Lawrencefeafe7c2014-06-25 17:03:14 -04001410 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1411 GFP_KERNEL);
Eric Moore635374e2009-03-09 01:21:12 -06001412 if (!sas_device_priv_data)
1413 return -ENOMEM;
1414
1415 sas_device_priv_data->lun = sdev->lun;
1416 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1417
1418 starget = scsi_target(sdev);
1419 sas_target_priv_data = starget->hostdata;
1420 sas_target_priv_data->num_luns++;
1421 sas_device_priv_data->sas_target = sas_target_priv_data;
1422 sdev->hostdata = sas_device_priv_data;
1423 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1424 sdev->no_uld_attach = 1;
1425
1426 shost = dev_to_shost(&starget->dev);
1427 ioc = shost_priv(shost);
1428 if (starget->channel == RAID_CHANNEL) {
1429 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1430 raid_device = _scsih_raid_device_find_by_id(ioc,
1431 starget->id, starget->channel);
1432 if (raid_device)
1433 raid_device->sdev = sdev; /* raid is single lun */
1434 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06001435 }
1436
Sreekanth Reddy63e359d2013-07-25 11:32:51 +05301437 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1438 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1439 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1440 sas_target_priv_data->sas_address);
1441 if (sas_device && (sas_device->starget == NULL)) {
1442 sdev_printk(KERN_INFO, sdev,
1443 "%s : sas_device->starget set to starget @ %d\n",
1444 __func__, __LINE__);
1445 sas_device->starget = starget;
1446 }
1447 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1448 }
1449
Eric Moore635374e2009-03-09 01:21:12 -06001450 return 0;
1451}
1452
1453/**
Eric Moored5d135b2009-05-18 13:02:08 -06001454 * _scsih_slave_destroy - device destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001455 * @sdev: scsi device struct
1456 *
1457 * Returns nothing.
1458 */
1459static void
Eric Moored5d135b2009-05-18 13:02:08 -06001460_scsih_slave_destroy(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001461{
1462 struct MPT2SAS_TARGET *sas_target_priv_data;
1463 struct scsi_target *starget;
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301464 struct Scsi_Host *shost;
1465 struct MPT2SAS_ADAPTER *ioc;
1466 struct _sas_device *sas_device;
1467 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001468
1469 if (!sdev->hostdata)
1470 return;
1471
1472 starget = scsi_target(sdev);
1473 sas_target_priv_data = starget->hostdata;
1474 sas_target_priv_data->num_luns--;
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301475
1476 shost = dev_to_shost(&starget->dev);
1477 ioc = shost_priv(shost);
1478
1479 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1480 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1481 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1482 sas_target_priv_data->sas_address);
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +05301483 if (sas_device && !sas_target_priv_data->num_luns)
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301484 sas_device->starget = NULL;
1485 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1486 }
1487
Eric Moore635374e2009-03-09 01:21:12 -06001488 kfree(sdev->hostdata);
1489 sdev->hostdata = NULL;
1490}
1491
1492/**
Eric Moored5d135b2009-05-18 13:02:08 -06001493 * _scsih_display_sata_capabilities - sata capabilities
Eric Moore635374e2009-03-09 01:21:12 -06001494 * @ioc: per adapter object
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301495 * @handle: device handle
Eric Moore635374e2009-03-09 01:21:12 -06001496 * @sdev: scsi device struct
1497 */
1498static void
Eric Moored5d135b2009-05-18 13:02:08 -06001499_scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301500 u16 handle, struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001501{
1502 Mpi2ConfigReply_t mpi_reply;
1503 Mpi2SasDevicePage0_t sas_device_pg0;
1504 u32 ioc_status;
1505 u16 flags;
1506 u32 device_info;
1507
1508 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301509 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06001510 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1511 ioc->name, __FILE__, __LINE__, __func__);
1512 return;
1513 }
1514
1515 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1516 MPI2_IOCSTATUS_MASK;
1517 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1518 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1519 ioc->name, __FILE__, __LINE__, __func__);
1520 return;
1521 }
1522
1523 flags = le16_to_cpu(sas_device_pg0.Flags);
Kashyap, Desaie94f6742010-03-17 16:24:52 +05301524 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
Eric Moore635374e2009-03-09 01:21:12 -06001525
1526 sdev_printk(KERN_INFO, sdev,
1527 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1528 "sw_preserve(%s)\n",
1529 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1530 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1531 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1532 "n",
1533 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1534 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1535 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1536}
1537
1538/**
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301539 * _scsih_is_raid - return boolean indicating device is raid volume
1540 * @dev the device struct object
1541 */
1542static int
1543_scsih_is_raid(struct device *dev)
1544{
1545 struct scsi_device *sdev = to_scsi_device(dev);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301546 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301547
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301548 if (ioc->is_warpdrive)
1549 return 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301550 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1551}
1552
1553/**
1554 * _scsih_get_resync - get raid volume resync percent complete
1555 * @dev the device struct object
1556 */
1557static void
1558_scsih_get_resync(struct device *dev)
1559{
1560 struct scsi_device *sdev = to_scsi_device(dev);
1561 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1562 static struct _raid_device *raid_device;
1563 unsigned long flags;
1564 Mpi2RaidVolPage0_t vol_pg0;
1565 Mpi2ConfigReply_t mpi_reply;
1566 u32 volume_status_flags;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301567 u8 percent_complete;
1568 u16 handle;
1569
1570 percent_complete = 0;
1571 handle = 0;
1572 if (ioc->is_warpdrive)
1573 goto out;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301574
1575 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1576 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1577 sdev->channel);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301578 if (raid_device) {
1579 handle = raid_device->handle;
1580 percent_complete = raid_device->percent_complete;
1581 }
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301582 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1583
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301584 if (!handle)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301585 goto out;
1586
1587 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301588 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301589 sizeof(Mpi2RaidVolPage0_t))) {
1590 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1591 ioc->name, __FILE__, __LINE__, __func__);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301592 percent_complete = 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301593 goto out;
1594 }
1595
1596 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301597 if (!(volume_status_flags &
1598 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1599 percent_complete = 0;
1600
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301601 out:
1602 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1603}
1604
1605/**
1606 * _scsih_get_state - get raid volume level
1607 * @dev the device struct object
1608 */
1609static void
1610_scsih_get_state(struct device *dev)
1611{
1612 struct scsi_device *sdev = to_scsi_device(dev);
1613 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1614 static struct _raid_device *raid_device;
1615 unsigned long flags;
1616 Mpi2RaidVolPage0_t vol_pg0;
1617 Mpi2ConfigReply_t mpi_reply;
1618 u32 volstate;
1619 enum raid_state state = RAID_STATE_UNKNOWN;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301620 u16 handle = 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301621
1622 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1623 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1624 sdev->channel);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301625 if (raid_device)
1626 handle = raid_device->handle;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301627 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1628
1629 if (!raid_device)
1630 goto out;
1631
1632 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301633 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301634 sizeof(Mpi2RaidVolPage0_t))) {
1635 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1636 ioc->name, __FILE__, __LINE__, __func__);
1637 goto out;
1638 }
1639
1640 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1641 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1642 state = RAID_STATE_RESYNCING;
1643 goto out;
1644 }
1645
1646 switch (vol_pg0.VolumeState) {
1647 case MPI2_RAID_VOL_STATE_OPTIMAL:
1648 case MPI2_RAID_VOL_STATE_ONLINE:
1649 state = RAID_STATE_ACTIVE;
1650 break;
1651 case MPI2_RAID_VOL_STATE_DEGRADED:
1652 state = RAID_STATE_DEGRADED;
1653 break;
1654 case MPI2_RAID_VOL_STATE_FAILED:
1655 case MPI2_RAID_VOL_STATE_MISSING:
1656 state = RAID_STATE_OFFLINE;
1657 break;
1658 }
1659 out:
1660 raid_set_state(mpt2sas_raid_template, dev, state);
1661}
1662
1663/**
1664 * _scsih_set_level - set raid level
1665 * @sdev: scsi device struct
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301666 * @volume_type: volume type
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301667 */
1668static void
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301669_scsih_set_level(struct scsi_device *sdev, u8 volume_type)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301670{
1671 enum raid_level level = RAID_LEVEL_UNKNOWN;
1672
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301673 switch (volume_type) {
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301674 case MPI2_RAID_VOL_TYPE_RAID0:
1675 level = RAID_LEVEL_0;
1676 break;
1677 case MPI2_RAID_VOL_TYPE_RAID10:
1678 level = RAID_LEVEL_10;
1679 break;
1680 case MPI2_RAID_VOL_TYPE_RAID1E:
1681 level = RAID_LEVEL_1E;
1682 break;
1683 case MPI2_RAID_VOL_TYPE_RAID1:
1684 level = RAID_LEVEL_1;
1685 break;
1686 }
1687
1688 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1689}
1690
1691/**
Eric Moore635374e2009-03-09 01:21:12 -06001692 * _scsih_get_volume_capabilities - volume capabilities
1693 * @ioc: per adapter object
1694 * @sas_device: the raid_device object
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301695 *
1696 * Returns 0 for success, else 1
Eric Moore635374e2009-03-09 01:21:12 -06001697 */
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301698static int
Eric Moore635374e2009-03-09 01:21:12 -06001699_scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1700 struct _raid_device *raid_device)
1701{
1702 Mpi2RaidVolPage0_t *vol_pg0;
1703 Mpi2RaidPhysDiskPage0_t pd_pg0;
1704 Mpi2SasDevicePage0_t sas_device_pg0;
1705 Mpi2ConfigReply_t mpi_reply;
1706 u16 sz;
1707 u8 num_pds;
1708
1709 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1710 &num_pds)) || !num_pds) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301711 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1712 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1713 __func__));
1714 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001715 }
1716
1717 raid_device->num_pds = num_pds;
1718 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1719 sizeof(Mpi2RaidVol0PhysDisk_t));
1720 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1721 if (!vol_pg0) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301722 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1723 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1724 __func__));
1725 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001726 }
1727
1728 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1729 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301730 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1731 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1732 __func__));
Eric Moore635374e2009-03-09 01:21:12 -06001733 kfree(vol_pg0);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301734 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001735 }
1736
1737 raid_device->volume_type = vol_pg0->VolumeType;
1738
1739 /* figure out what the underlying devices are by
1740 * obtaining the device_info bits for the 1st device
1741 */
1742 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1743 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1744 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1745 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1746 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1747 le16_to_cpu(pd_pg0.DevHandle)))) {
1748 raid_device->device_info =
1749 le32_to_cpu(sas_device_pg0.DeviceInfo);
1750 }
1751 }
1752
1753 kfree(vol_pg0);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301754 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06001755}
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301756/**
1757 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1758 * @ioc: per adapter object
1759 */
1760static void
1761_scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1762{
1763 Mpi2RaidVolPage1_t vol_pg1;
1764 Mpi2ConfigReply_t mpi_reply;
1765 struct _raid_device *raid_device;
1766 u16 handle;
1767 u16 ioc_status;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301768 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301769
1770 handle = 0xFFFF;
1771 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1772 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1773 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1774 MPI2_IOCSTATUS_MASK;
1775 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1776 break;
1777 handle = le16_to_cpu(vol_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301778 spin_lock_irqsave(&ioc->raid_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301779 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1780 if (raid_device)
1781 raid_device->direct_io_enabled = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301782 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301783 }
1784 return;
1785}
1786
1787
1788/**
1789 * _scsih_get_num_volumes - Get number of volumes in the ioc
1790 * @ioc: per adapter object
1791 */
1792static u8
1793_scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1794{
1795 Mpi2RaidVolPage1_t vol_pg1;
1796 Mpi2ConfigReply_t mpi_reply;
1797 u16 handle;
1798 u8 vol_cnt = 0;
1799 u16 ioc_status;
1800
1801 handle = 0xFFFF;
1802 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1803 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1804 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1805 MPI2_IOCSTATUS_MASK;
1806 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1807 break;
1808 vol_cnt++;
1809 handle = le16_to_cpu(vol_pg1.DevHandle);
1810 }
1811 return vol_cnt;
1812}
1813
1814
1815/**
1816 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1817 * @ioc: per adapter object
1818 * @raid_device: the raid_device object
1819 */
1820static void
1821_scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1822 struct _raid_device *raid_device)
1823{
1824 Mpi2RaidVolPage0_t *vol_pg0;
1825 Mpi2RaidPhysDiskPage0_t pd_pg0;
1826 Mpi2ConfigReply_t mpi_reply;
1827 u16 sz;
1828 u8 num_pds, count;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301829 unsigned long stripe_sz, block_sz;
1830 u8 stripe_exp, block_exp;
1831 u64 dev_max_lba;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301832
1833 if (!ioc->is_warpdrive)
1834 return;
1835
1836 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1837 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1838 "globally as drives are exposed\n", ioc->name);
1839 return;
1840 }
1841 if (_scsih_get_num_volumes(ioc) > 1) {
1842 _scsih_disable_ddio(ioc);
1843 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1844 "globally as number of drives > 1\n", ioc->name);
1845 return;
1846 }
1847 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1848 &num_pds)) || !num_pds) {
1849 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1850 "Failure in computing number of drives\n", ioc->name);
1851 return;
1852 }
1853
1854 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1855 sizeof(Mpi2RaidVol0PhysDisk_t));
1856 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1857 if (!vol_pg0) {
1858 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1859 "Memory allocation failure for RVPG0\n", ioc->name);
1860 return;
1861 }
1862
1863 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1864 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1865 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1866 "Failure in retrieving RVPG0\n", ioc->name);
1867 kfree(vol_pg0);
1868 return;
1869 }
1870
1871 /*
1872 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1873 * assumed for WARPDRIVE, disable direct I/O
1874 */
1875 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1876 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1877 "for the drive with handle(0x%04x): num_mem=%d, "
1878 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1879 num_pds, MPT_MAX_WARPDRIVE_PDS);
1880 kfree(vol_pg0);
1881 return;
1882 }
1883 for (count = 0; count < num_pds; count++) {
1884 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1885 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1886 vol_pg0->PhysDisk[count].PhysDiskNum) ||
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05301887 le16_to_cpu(pd_pg0.DevHandle) ==
1888 MPT2SAS_INVALID_DEVICE_HANDLE) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301889 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1890 "disabled for the drive with handle(0x%04x) member"
1891 "handle retrieval failed for member number=%d\n",
1892 ioc->name, raid_device->handle,
1893 vol_pg0->PhysDisk[count].PhysDiskNum);
1894 goto out_error;
1895 }
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301896 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1897 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
1898 if (dev_max_lba >> 32) {
1899 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1900 "disabled for the drive with handle(0x%04x) member"
1901 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1902 ioc->name, raid_device->handle,
1903 le16_to_cpu(pd_pg0.DevHandle),
1904 (unsigned long long)dev_max_lba);
1905 goto out_error;
1906 }
1907
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301908 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1909 }
1910
1911 /*
1912 * Assumption for WD: Direct I/O is not supported if the volume is
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301913 * not RAID0
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301914 */
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301915 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301916 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1917 "for the drive with handle(0x%04x): type=%d, "
1918 "s_sz=%uK, blk_size=%u\n", ioc->name,
1919 raid_device->handle, raid_device->volume_type,
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301920 (le32_to_cpu(vol_pg0->StripeSize) *
1921 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301922 le16_to_cpu(vol_pg0->BlockSize));
1923 goto out_error;
1924 }
1925
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301926 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301927 stripe_exp = find_first_bit(&stripe_sz, 32);
1928 if (stripe_exp == 32) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301929 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301930 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301931 ioc->name, raid_device->handle,
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301932 (le32_to_cpu(vol_pg0->StripeSize) *
1933 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301934 goto out_error;
1935 }
1936 raid_device->stripe_exponent = stripe_exp;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301937 block_sz = le16_to_cpu(vol_pg0->BlockSize);
1938 block_exp = find_first_bit(&block_sz, 16);
1939 if (block_exp == 16) {
1940 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1941 "for the drive with handle(0x%04x) invalid block sz %u\n",
1942 ioc->name, raid_device->handle,
1943 le16_to_cpu(vol_pg0->BlockSize));
1944 goto out_error;
1945 }
1946 raid_device->block_exponent = block_exp;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301947 raid_device->direct_io_enabled = 1;
1948
1949 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1950 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1951 /*
1952 * WARPDRIVE: Though the following fields are not used for direct IO,
1953 * stored for future purpose:
1954 */
1955 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1956 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1957 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1958
1959
1960 kfree(vol_pg0);
1961 return;
1962
1963out_error:
1964 raid_device->direct_io_enabled = 0;
1965 for (count = 0; count < num_pds; count++)
1966 raid_device->pd_handle[count] = 0;
1967 kfree(vol_pg0);
1968 return;
1969}
Eric Moore635374e2009-03-09 01:21:12 -06001970
1971/**
Kashyap, Desai84f0b042009-12-16 18:56:28 +05301972 * _scsih_enable_tlr - setting TLR flags
1973 * @ioc: per adapter object
1974 * @sdev: scsi device struct
1975 *
1976 * Enabling Transaction Layer Retries for tape devices when
1977 * vpd page 0x90 is present
1978 *
1979 */
1980static void
1981_scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1982{
1983 /* only for TAPE */
1984 if (sdev->type != TYPE_TAPE)
1985 return;
1986
1987 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1988 return;
1989
1990 sas_enable_tlr(sdev);
1991 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1992 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1993 return;
1994
1995}
1996
1997/**
Eric Moored5d135b2009-05-18 13:02:08 -06001998 * _scsih_slave_configure - device configure routine.
Eric Moore635374e2009-03-09 01:21:12 -06001999 * @sdev: scsi device struct
2000 *
2001 * Returns 0 if ok. Any other return is assumed to be an error and
2002 * the device is ignored.
2003 */
2004static int
Eric Moored5d135b2009-05-18 13:02:08 -06002005_scsih_slave_configure(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06002006{
2007 struct Scsi_Host *shost = sdev->host;
2008 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2009 struct MPT2SAS_DEVICE *sas_device_priv_data;
2010 struct MPT2SAS_TARGET *sas_target_priv_data;
2011 struct _sas_device *sas_device;
2012 struct _raid_device *raid_device;
2013 unsigned long flags;
2014 int qdepth;
2015 u8 ssp_target = 0;
2016 char *ds = "";
2017 char *r_level = "";
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302018 u16 handle, volume_handle = 0;
2019 u64 volume_wwid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06002020
2021 qdepth = 1;
2022 sas_device_priv_data = sdev->hostdata;
2023 sas_device_priv_data->configured_lun = 1;
2024 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
2025 sas_target_priv_data = sas_device_priv_data->sas_target;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302026 handle = sas_target_priv_data->handle;
Eric Moore635374e2009-03-09 01:21:12 -06002027
2028 /* raid volume handling */
2029 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2030
2031 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302032 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06002033 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2034 if (!raid_device) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302035 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2036 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2037 __LINE__, __func__));
2038 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002039 }
2040
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302041 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2042 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2043 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2044 __LINE__, __func__));
2045 return 1;
2046 }
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302047 /*
2048 * WARPDRIVE: Initialize the required data for Direct IO
2049 */
2050 _scsih_init_warpdrive_properties(ioc, raid_device);
2051
Eric Moore635374e2009-03-09 01:21:12 -06002052 /* RAID Queue Depth Support
2053 * IS volume = underlying qdepth of drive type, either
2054 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2055 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2056 */
2057 if (raid_device->device_info &
2058 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2059 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2060 ds = "SSP";
2061 } else {
2062 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2063 if (raid_device->device_info &
2064 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2065 ds = "SATA";
2066 else
2067 ds = "STP";
2068 }
2069
2070 switch (raid_device->volume_type) {
2071 case MPI2_RAID_VOL_TYPE_RAID0:
2072 r_level = "RAID0";
2073 break;
2074 case MPI2_RAID_VOL_TYPE_RAID1E:
2075 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
Kashyap, Desaied79f122009-08-20 13:23:49 +05302076 if (ioc->manu_pg10.OEMIdentifier &&
Kashyap, Desaic97951e2011-06-14 10:54:56 +05302077 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
Kashyap, Desaied79f122009-08-20 13:23:49 +05302078 MFG10_GF0_R10_DISPLAY) &&
2079 !(raid_device->num_pds % 2))
2080 r_level = "RAID10";
2081 else
2082 r_level = "RAID1E";
Eric Moore635374e2009-03-09 01:21:12 -06002083 break;
2084 case MPI2_RAID_VOL_TYPE_RAID1:
2085 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2086 r_level = "RAID1";
2087 break;
2088 case MPI2_RAID_VOL_TYPE_RAID10:
2089 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2090 r_level = "RAID10";
2091 break;
2092 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2093 default:
2094 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2095 r_level = "RAIDX";
2096 break;
2097 }
2098
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302099 if (!ioc->hide_ir_msg)
2100 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2101 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2102 r_level, raid_device->handle,
2103 (unsigned long long)raid_device->wwid,
2104 raid_device->num_pds, ds);
Mike Christiee881a172009-10-15 17:46:39 -07002105 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05302106 /* raid transport support */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302107 if (!ioc->is_warpdrive)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302108 _scsih_set_level(sdev, raid_device->volume_type);
Eric Moore635374e2009-03-09 01:21:12 -06002109 return 0;
2110 }
2111
2112 /* non-raid handling */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302113 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2114 if (mpt2sas_config_get_volume_handle(ioc, handle,
2115 &volume_handle)) {
2116 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2117 "failure at %s:%d/%s()!\n", ioc->name,
2118 __FILE__, __LINE__, __func__));
2119 return 1;
2120 }
2121 if (volume_handle && mpt2sas_config_get_volume_wwid(ioc,
2122 volume_handle, &volume_wwid)) {
2123 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2124 "failure at %s:%d/%s()!\n", ioc->name,
2125 __FILE__, __LINE__, __func__));
2126 return 1;
2127 }
2128 }
2129
Eric Moore635374e2009-03-09 01:21:12 -06002130 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2131 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2132 sas_device_priv_data->sas_target->sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302133 if (!sas_device) {
2134 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302135 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302136 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2137 __LINE__, __func__));
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302138 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002139 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302140 sas_device->volume_handle = volume_handle;
2141 sas_device->volume_wwid = volume_wwid;
2142 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2143 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2144 ssp_target = 1;
2145 ds = "SSP";
2146 } else {
2147 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2148 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2149 ds = "STP";
2150 else if (sas_device->device_info &
2151 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2152 ds = "SATA";
2153 }
2154 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2155 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2156 ds, sas_device->handle,
2157 (unsigned long long)sas_device->sas_address,
2158 sas_device->phy,
2159 (unsigned long long)sas_device->device_name);
2160 sdev_printk(KERN_INFO, sdev, "%s: "
2161 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2162 (unsigned long long) sas_device->enclosure_logical_id,
2163 sas_device->slot);
2164
2165 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2166 if (!ssp_target)
2167 _scsih_display_sata_capabilities(ioc, handle, sdev);
2168
Eric Moore635374e2009-03-09 01:21:12 -06002169
Mike Christiee881a172009-10-15 17:46:39 -07002170 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
Eric Moore635374e2009-03-09 01:21:12 -06002171
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302172 if (ssp_target) {
Eric Moore635374e2009-03-09 01:21:12 -06002173 sas_read_port_mode_page(sdev);
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302174 _scsih_enable_tlr(ioc, sdev);
2175 }
Eric Moore635374e2009-03-09 01:21:12 -06002176 return 0;
2177}
2178
2179/**
Eric Moored5d135b2009-05-18 13:02:08 -06002180 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
Eric Moore635374e2009-03-09 01:21:12 -06002181 * @sdev: scsi device struct
2182 * @bdev: pointer to block device context
2183 * @capacity: device size (in 512 byte sectors)
2184 * @params: three element array to place output:
2185 * params[0] number of heads (max 255)
2186 * params[1] number of sectors (max 63)
2187 * params[2] number of cylinders
2188 *
2189 * Return nothing.
2190 */
2191static int
Eric Moored5d135b2009-05-18 13:02:08 -06002192_scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
Eric Moore635374e2009-03-09 01:21:12 -06002193 sector_t capacity, int params[])
2194{
2195 int heads;
2196 int sectors;
2197 sector_t cylinders;
2198 ulong dummy;
2199
2200 heads = 64;
2201 sectors = 32;
2202
2203 dummy = heads * sectors;
2204 cylinders = capacity;
2205 sector_div(cylinders, dummy);
2206
2207 /*
2208 * Handle extended translation size for logical drives
2209 * > 1Gb
2210 */
2211 if ((ulong)capacity >= 0x200000) {
2212 heads = 255;
2213 sectors = 63;
2214 dummy = heads * sectors;
2215 cylinders = capacity;
2216 sector_div(cylinders, dummy);
2217 }
2218
2219 /* return result */
2220 params[0] = heads;
2221 params[1] = sectors;
2222 params[2] = cylinders;
2223
2224 return 0;
2225}
2226
2227/**
2228 * _scsih_response_code - translation of device response code
2229 * @ioc: per adapter object
2230 * @response_code: response code returned by the device
2231 *
2232 * Return nothing.
2233 */
2234static void
2235_scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2236{
2237 char *desc;
2238
2239 switch (response_code) {
2240 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2241 desc = "task management request completed";
2242 break;
2243 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2244 desc = "invalid frame";
2245 break;
2246 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2247 desc = "task management request not supported";
2248 break;
2249 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2250 desc = "task management request failed";
2251 break;
2252 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2253 desc = "task management request succeeded";
2254 break;
2255 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2256 desc = "invalid lun";
2257 break;
2258 case 0xA:
2259 desc = "overlapped tag attempted";
2260 break;
2261 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2262 desc = "task queued, however not sent to target";
2263 break;
2264 default:
2265 desc = "unknown";
2266 break;
2267 }
2268 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2269 ioc->name, response_code, desc);
2270}
2271
2272/**
Eric Moored5d135b2009-05-18 13:02:08 -06002273 * _scsih_tm_done - tm completion routine
Eric Moore635374e2009-03-09 01:21:12 -06002274 * @ioc: per adapter object
2275 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302276 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002277 * @reply: reply message frame(lower 32bit addr)
2278 * Context: none.
2279 *
2280 * The callback handler when using scsih_issue_tm.
2281 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302282 * Return 1 meaning mf should be freed from _base_interrupt
2283 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06002284 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302285static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302286_scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06002287{
2288 MPI2DefaultReply_t *mpi_reply;
2289
2290 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302291 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002292 if (ioc->tm_cmds.smid != smid)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302293 return 1;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05302294 mpt2sas_base_flush_reply_queues(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06002295 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2296 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2297 if (mpi_reply) {
2298 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2299 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2300 }
2301 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2302 complete(&ioc->tm_cmds.done);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302303 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002304}
2305
2306/**
2307 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2308 * @ioc: per adapter object
2309 * @handle: device handle
2310 *
2311 * During taskmangement request, we need to freeze the device queue.
2312 */
2313void
2314mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2315{
2316 struct MPT2SAS_DEVICE *sas_device_priv_data;
2317 struct scsi_device *sdev;
2318 u8 skip = 0;
2319
2320 shost_for_each_device(sdev, ioc->shost) {
2321 if (skip)
2322 continue;
2323 sas_device_priv_data = sdev->hostdata;
2324 if (!sas_device_priv_data)
2325 continue;
2326 if (sas_device_priv_data->sas_target->handle == handle) {
2327 sas_device_priv_data->sas_target->tm_busy = 1;
2328 skip = 1;
2329 ioc->ignore_loginfos = 1;
2330 }
2331 }
2332}
2333
2334/**
2335 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2336 * @ioc: per adapter object
2337 * @handle: device handle
2338 *
2339 * During taskmangement request, we need to freeze the device queue.
2340 */
2341void
2342mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2343{
2344 struct MPT2SAS_DEVICE *sas_device_priv_data;
2345 struct scsi_device *sdev;
2346 u8 skip = 0;
2347
2348 shost_for_each_device(sdev, ioc->shost) {
2349 if (skip)
2350 continue;
2351 sas_device_priv_data = sdev->hostdata;
2352 if (!sas_device_priv_data)
2353 continue;
2354 if (sas_device_priv_data->sas_target->handle == handle) {
2355 sas_device_priv_data->sas_target->tm_busy = 0;
2356 skip = 1;
2357 ioc->ignore_loginfos = 0;
2358 }
2359 }
2360}
2361
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302362
Eric Moore635374e2009-03-09 01:21:12 -06002363/**
2364 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2365 * @ioc: per adapter struct
2366 * @device_handle: device handle
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302367 * @channel: the channel assigned by the OS
2368 * @id: the id assigned by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002369 * @lun: lun number
2370 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2371 * @smid_task: smid assigned to the task
2372 * @timeout: timeout in seconds
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302373 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302374 * Context: user
Eric Moore635374e2009-03-09 01:21:12 -06002375 *
2376 * A generic API for sending task management requests to firmware.
2377 *
Eric Moore635374e2009-03-09 01:21:12 -06002378 * The callback index is set inside `ioc->tm_cb_idx`.
2379 *
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302380 * Return SUCCESS or FAILED.
Eric Moore635374e2009-03-09 01:21:12 -06002381 */
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302382int
2383mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2384 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002385 enum mutex_type m_type)
Eric Moore635374e2009-03-09 01:21:12 -06002386{
2387 Mpi2SCSITaskManagementRequest_t *mpi_request;
2388 Mpi2SCSITaskManagementReply_t *mpi_reply;
2389 u16 smid = 0;
2390 u32 ioc_state;
2391 unsigned long timeleft;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302392 struct scsiio_tracker *scsi_lookup = NULL;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302393 int rc;
Eric Moore635374e2009-03-09 01:21:12 -06002394
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302395 if (m_type == TM_MUTEX_ON)
2396 mutex_lock(&ioc->tm_cmds.mutex);
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302397 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2398 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2399 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302400 rc = FAILED;
2401 goto err_out;
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302402 }
2403
Eric Moore3cb54692010-07-08 14:44:34 -06002404 if (ioc->shost_recovery || ioc->remove_host ||
2405 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06002406 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2407 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302408 rc = FAILED;
2409 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002410 }
Eric Moore635374e2009-03-09 01:21:12 -06002411
2412 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2413 if (ioc_state & MPI2_DOORBELL_USED) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302414 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
Eric Moore635374e2009-03-09 01:21:12 -06002415 "active!\n", ioc->name));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302416 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302417 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302418 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302419 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002420 }
2421
2422 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2423 mpt2sas_base_fault_info(ioc, ioc_state &
2424 MPI2_DOORBELL_DATA_MASK);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302425 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302426 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302427 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302428 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002429 }
2430
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302431 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06002432 if (!smid) {
2433 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2434 ioc->name, __func__);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302435 rc = FAILED;
2436 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002437 }
2438
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302439 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2440 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2441
Eric Moore635374e2009-03-09 01:21:12 -06002442 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302443 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2444 smid_task));
Eric Moore635374e2009-03-09 01:21:12 -06002445 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2446 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2447 ioc->tm_cmds.smid = smid;
2448 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302449 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
Eric Moore635374e2009-03-09 01:21:12 -06002450 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2451 mpi_request->DevHandle = cpu_to_le16(handle);
2452 mpi_request->TaskType = type;
2453 mpi_request->TaskMID = cpu_to_le16(smid_task);
2454 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2455 mpt2sas_scsih_set_tm_flag(ioc, handle);
Kashyap, Desai5b768582009-08-20 13:24:31 +05302456 init_completion(&ioc->tm_cmds.done);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302457 mpt2sas_base_put_smid_hi_priority(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06002458 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
Eric Moore635374e2009-03-09 01:21:12 -06002459 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2460 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2461 ioc->name, __func__);
2462 _debug_dump_mf(mpi_request,
2463 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302464 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302465 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302466 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302467 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302468 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2469 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2470 goto err_out;
2471 }
Eric Moore635374e2009-03-09 01:21:12 -06002472 }
2473
2474 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2475 mpi_reply = ioc->tm_cmds.reply;
2476 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2477 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2478 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2479 le32_to_cpu(mpi_reply->IOCLogInfo),
2480 le32_to_cpu(mpi_reply->TerminationCount)));
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302481 if (ioc->logging_level & MPT_DEBUG_TM) {
Eric Moore635374e2009-03-09 01:21:12 -06002482 _scsih_response_code(ioc, mpi_reply->ResponseCode);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302483 if (mpi_reply->IOCStatus)
2484 _debug_dump_mf(mpi_request,
2485 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2486 }
Eric Moore635374e2009-03-09 01:21:12 -06002487 }
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302488
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302489 switch (type) {
2490 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302491 rc = SUCCESS;
2492 if (scsi_lookup->scmd == NULL)
2493 break;
2494 rc = FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302495 break;
2496
2497 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2498 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2499 rc = FAILED;
2500 else
2501 rc = SUCCESS;
2502 break;
2503
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302504 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302505 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2506 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2507 rc = FAILED;
2508 else
2509 rc = SUCCESS;
2510 break;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302511 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2512 rc = SUCCESS;
2513 break;
2514 default:
2515 rc = FAILED;
2516 break;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302517 }
2518
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302519 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2520 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302521 if (m_type == TM_MUTEX_ON)
2522 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302523
2524 return rc;
2525
2526 err_out:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302527 if (m_type == TM_MUTEX_ON)
2528 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302529 return rc;
Eric Moore635374e2009-03-09 01:21:12 -06002530}
2531
2532/**
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302533 * _scsih_tm_display_info - displays info about the device
2534 * @ioc: per adapter struct
2535 * @scmd: pointer to scsi command object
2536 *
2537 * Called by task management callback handlers.
2538 */
2539static void
2540_scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2541{
2542 struct scsi_target *starget = scmd->device->sdev_target;
2543 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2544 struct _sas_device *sas_device = NULL;
2545 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302546 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302547
2548 if (!priv_target)
2549 return;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302550 if (ioc->hide_ir_msg)
2551 device_str = "WarpDrive";
2552 else
2553 device_str = "volume";
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302554
2555 scsi_print_command(scmd);
2556 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302557 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2558 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2559 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302560 } else {
2561 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2562 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2563 priv_target->sas_address);
2564 if (sas_device) {
2565 if (priv_target->flags &
2566 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2567 starget_printk(KERN_INFO, starget,
2568 "volume handle(0x%04x), "
2569 "volume wwid(0x%016llx)\n",
2570 sas_device->volume_handle,
2571 (unsigned long long)sas_device->volume_wwid);
2572 }
2573 starget_printk(KERN_INFO, starget,
2574 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2575 sas_device->handle,
2576 (unsigned long long)sas_device->sas_address,
2577 sas_device->phy);
2578 starget_printk(KERN_INFO, starget,
2579 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2580 (unsigned long long)sas_device->enclosure_logical_id,
2581 sas_device->slot);
2582 }
2583 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2584 }
2585}
2586
2587/**
Eric Moored5d135b2009-05-18 13:02:08 -06002588 * _scsih_abort - eh threads main abort routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302589 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002590 *
2591 * Returns SUCCESS if command aborted else FAILED
2592 */
2593static int
Eric Moored5d135b2009-05-18 13:02:08 -06002594_scsih_abort(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002595{
2596 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2597 struct MPT2SAS_DEVICE *sas_device_priv_data;
2598 u16 smid;
2599 u16 handle;
2600 int r;
Eric Moore635374e2009-03-09 01:21:12 -06002601
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302602 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2603 "scmd(%p)\n", scmd);
2604 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002605
2606 sas_device_priv_data = scmd->device->hostdata;
2607 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302608 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2609 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002610 scmd->result = DID_NO_CONNECT << 16;
2611 scmd->scsi_done(scmd);
2612 r = SUCCESS;
2613 goto out;
2614 }
2615
2616 /* search for the command */
2617 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2618 if (!smid) {
2619 scmd->result = DID_RESET << 16;
2620 r = SUCCESS;
2621 goto out;
2622 }
2623
2624 /* for hidden raid components and volumes this is not supported */
2625 if (sas_device_priv_data->sas_target->flags &
2626 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2627 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2628 scmd->result = DID_RESET << 16;
2629 r = FAILED;
2630 goto out;
2631 }
2632
Kashyap, Desaifa7f3162009-09-23 17:26:58 +05302633 mpt2sas_halt_firmware(ioc);
2634
Eric Moore635374e2009-03-09 01:21:12 -06002635 handle = sas_device_priv_data->sas_target->handle;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302636 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2637 scmd->device->id, scmd->device->lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002638 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002639
2640 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302641 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2642 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002643 return r;
2644}
2645
Eric Moore635374e2009-03-09 01:21:12 -06002646/**
Eric Moored5d135b2009-05-18 13:02:08 -06002647 * _scsih_dev_reset - eh threads main device reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302648 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002649 *
2650 * Returns SUCCESS if command aborted else FAILED
2651 */
2652static int
Eric Moored5d135b2009-05-18 13:02:08 -06002653_scsih_dev_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002654{
2655 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2656 struct MPT2SAS_DEVICE *sas_device_priv_data;
2657 struct _sas_device *sas_device;
2658 unsigned long flags;
2659 u16 handle;
2660 int r;
2661
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302662 struct scsi_target *starget = scmd->device->sdev_target;
2663
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302664 starget_printk(KERN_INFO, starget, "attempting device reset! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302665 "scmd(%p)\n", scmd);
2666 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002667
2668 sas_device_priv_data = scmd->device->hostdata;
2669 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302670 starget_printk(KERN_INFO, starget, "device been deleted! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302671 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002672 scmd->result = DID_NO_CONNECT << 16;
2673 scmd->scsi_done(scmd);
2674 r = SUCCESS;
2675 goto out;
2676 }
2677
2678 /* for hidden raid components obtain the volume_handle */
2679 handle = 0;
2680 if (sas_device_priv_data->sas_target->flags &
2681 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2682 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2683 sas_device = _scsih_sas_device_find_by_handle(ioc,
2684 sas_device_priv_data->sas_target->handle);
2685 if (sas_device)
2686 handle = sas_device->volume_handle;
2687 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2688 } else
2689 handle = sas_device_priv_data->sas_target->handle;
2690
2691 if (!handle) {
2692 scmd->result = DID_RESET << 16;
2693 r = FAILED;
2694 goto out;
2695 }
2696
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302697 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2698 scmd->device->id, scmd->device->lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002699 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
Eric Moore993e0da2009-05-18 13:00:45 -06002700
2701 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302702 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2703 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002704 return r;
2705}
2706
2707/**
Eric Moored5d135b2009-05-18 13:02:08 -06002708 * _scsih_target_reset - eh threads main target reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302709 * @scmd: pointer to scsi command object
Eric Moore993e0da2009-05-18 13:00:45 -06002710 *
2711 * Returns SUCCESS if command aborted else FAILED
2712 */
2713static int
Eric Moored5d135b2009-05-18 13:02:08 -06002714_scsih_target_reset(struct scsi_cmnd *scmd)
Eric Moore993e0da2009-05-18 13:00:45 -06002715{
2716 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2717 struct MPT2SAS_DEVICE *sas_device_priv_data;
2718 struct _sas_device *sas_device;
2719 unsigned long flags;
2720 u16 handle;
2721 int r;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302722 struct scsi_target *starget = scmd->device->sdev_target;
Eric Moore993e0da2009-05-18 13:00:45 -06002723
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302724 starget_printk(KERN_INFO, starget, "attempting target reset! "
2725 "scmd(%p)\n", scmd);
2726 _scsih_tm_display_info(ioc, scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002727
2728 sas_device_priv_data = scmd->device->hostdata;
2729 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302730 starget_printk(KERN_INFO, starget, "target been deleted! "
2731 "scmd(%p)\n", scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002732 scmd->result = DID_NO_CONNECT << 16;
2733 scmd->scsi_done(scmd);
2734 r = SUCCESS;
2735 goto out;
2736 }
2737
2738 /* for hidden raid components obtain the volume_handle */
2739 handle = 0;
2740 if (sas_device_priv_data->sas_target->flags &
2741 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2742 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2743 sas_device = _scsih_sas_device_find_by_handle(ioc,
2744 sas_device_priv_data->sas_target->handle);
2745 if (sas_device)
2746 handle = sas_device->volume_handle;
2747 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2748 } else
2749 handle = sas_device_priv_data->sas_target->handle;
2750
2751 if (!handle) {
2752 scmd->result = DID_RESET << 16;
2753 r = FAILED;
2754 goto out;
2755 }
2756
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302757 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2758 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04002759 30, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002760
2761 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302762 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2763 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002764 return r;
2765}
2766
2767/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302768 * _scsih_host_reset - eh threads main host reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302769 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002770 *
2771 * Returns SUCCESS if command aborted else FAILED
2772 */
2773static int
Eric Moored5d135b2009-05-18 13:02:08 -06002774_scsih_host_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002775{
2776 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2777 int r, retval;
2778
2779 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2780 ioc->name, scmd);
2781 scsi_print_command(scmd);
2782
2783 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2784 FORCE_BIG_HAMMER);
2785 r = (retval < 0) ? FAILED : SUCCESS;
2786 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2787 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2788
2789 return r;
2790}
2791
2792/**
2793 * _scsih_fw_event_add - insert and queue up fw_event
2794 * @ioc: per adapter object
2795 * @fw_event: object describing the event
2796 * Context: This function will acquire ioc->fw_event_lock.
2797 *
2798 * This adds the firmware event object into link list, then queues it up to
2799 * be processed from user context.
2800 *
2801 * Return nothing.
2802 */
2803static void
2804_scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2805{
2806 unsigned long flags;
2807
2808 if (ioc->firmware_event_thread == NULL)
2809 return;
2810
2811 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2812 list_add_tail(&fw_event->list, &ioc->fw_event_list);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302813 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2814 queue_delayed_work(ioc->firmware_event_thread,
2815 &fw_event->delayed_work, 0);
Eric Moore635374e2009-03-09 01:21:12 -06002816 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2817}
2818
2819/**
2820 * _scsih_fw_event_free - delete fw_event
2821 * @ioc: per adapter object
2822 * @fw_event: object describing the event
2823 * Context: This function will acquire ioc->fw_event_lock.
2824 *
2825 * This removes firmware event object from link list, frees associated memory.
2826 *
2827 * Return nothing.
2828 */
2829static void
2830_scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2831 *fw_event)
2832{
2833 unsigned long flags;
2834
2835 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2836 list_del(&fw_event->list);
Eric Moore635374e2009-03-09 01:21:12 -06002837 kfree(fw_event);
2838 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2839}
2840
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302841
Eric Moore635374e2009-03-09 01:21:12 -06002842/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302843 * _scsih_error_recovery_delete_devices - remove devices not responding
Eric Moore635374e2009-03-09 01:21:12 -06002844 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06002845 *
2846 * Return nothing.
2847 */
2848static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302849_scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06002850{
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302851 struct fw_event_work *fw_event;
2852
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302853 if (ioc->is_driver_loading)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302854 return;
Dan Carpenter181a9d72011-11-04 21:25:01 +03002855
2856 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2857 if (!fw_event)
2858 return;
2859
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302860 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2861 fw_event->ioc = ioc;
2862 _scsih_fw_event_add(ioc, fw_event);
2863}
2864
2865/**
2866 * mpt2sas_port_enable_complete - port enable completed (fake event)
2867 * @ioc: per adapter object
2868 *
2869 * Return nothing.
2870 */
2871void
2872mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2873{
2874 struct fw_event_work *fw_event;
2875
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302876 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2877 if (!fw_event)
2878 return;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302879 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302880 fw_event->ioc = ioc;
2881 _scsih_fw_event_add(ioc, fw_event);
2882}
2883
2884/**
2885 * _scsih_fw_event_cleanup_queue - cleanup event queue
2886 * @ioc: per adapter object
2887 *
2888 * Walk the firmware event queue, either killing timers, or waiting
2889 * for outstanding events to complete
2890 *
2891 * Return nothing.
2892 */
2893static void
2894_scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2895{
2896 struct fw_event_work *fw_event, *next;
2897
2898 if (list_empty(&ioc->fw_event_list) ||
2899 !ioc->firmware_event_thread || in_interrupt())
Eric Moore635374e2009-03-09 01:21:12 -06002900 return;
2901
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302902 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05302903 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302904 _scsih_fw_event_free(ioc, fw_event);
2905 continue;
2906 }
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302907 }
Eric Moore635374e2009-03-09 01:21:12 -06002908}
2909
Eric Moore635374e2009-03-09 01:21:12 -06002910/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302911 * _scsih_ublock_io_all_device - unblock every device
2912 * @ioc: per adapter object
2913 *
2914 * change the device state from block to running
2915 */
2916static void
2917_scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2918{
2919 struct MPT2SAS_DEVICE *sas_device_priv_data;
2920 struct scsi_device *sdev;
2921
2922 shost_for_each_device(sdev, ioc->shost) {
2923 sas_device_priv_data = sdev->hostdata;
2924 if (!sas_device_priv_data)
2925 continue;
2926 if (!sas_device_priv_data->block)
2927 continue;
2928 sas_device_priv_data->block = 0;
2929 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2930 "handle(0x%04x)\n",
2931 sas_device_priv_data->sas_target->handle));
Mike Christie5d9fb5c2012-05-17 23:56:57 -05002932 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302933 }
2934}
2935/**
Eric Moore635374e2009-03-09 01:21:12 -06002936 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2937 * @ioc: per adapter object
2938 * @handle: device handle
2939 *
2940 * During device pull we need to appropiately set the sdev state.
2941 */
2942static void
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302943_scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06002944{
2945 struct MPT2SAS_DEVICE *sas_device_priv_data;
2946 struct scsi_device *sdev;
2947
2948 shost_for_each_device(sdev, ioc->shost) {
2949 sas_device_priv_data = sdev->hostdata;
2950 if (!sas_device_priv_data)
2951 continue;
2952 if (!sas_device_priv_data->block)
2953 continue;
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302954 if (sas_device_priv_data->sas_target->sas_address ==
2955 sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06002956 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2957 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302958 "sas address(0x%016llx)\n", ioc->name,
2959 (unsigned long long)sas_address));
Eric Moore635374e2009-03-09 01:21:12 -06002960 sas_device_priv_data->block = 0;
Mike Christie5d9fb5c2012-05-17 23:56:57 -05002961 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
Eric Moore635374e2009-03-09 01:21:12 -06002962 }
2963 }
2964}
2965
2966/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302967 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2968 * @ioc: per adapter object
2969 * @handle: device handle
2970 *
2971 * During device pull we need to appropiately set the sdev state.
2972 */
2973static void
2974_scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2975{
2976 struct MPT2SAS_DEVICE *sas_device_priv_data;
2977 struct scsi_device *sdev;
2978
2979 shost_for_each_device(sdev, ioc->shost) {
2980 sas_device_priv_data = sdev->hostdata;
2981 if (!sas_device_priv_data)
2982 continue;
2983 if (sas_device_priv_data->block)
2984 continue;
2985 sas_device_priv_data->block = 1;
2986 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2987 "handle(0x%04x)\n",
2988 sas_device_priv_data->sas_target->handle));
2989 scsi_internal_device_block(sdev);
2990 }
2991}
2992
2993
2994/**
Eric Moore635374e2009-03-09 01:21:12 -06002995 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2996 * @ioc: per adapter object
2997 * @handle: device handle
2998 *
2999 * During device pull we need to appropiately set the sdev state.
3000 */
3001static void
3002_scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3003{
3004 struct MPT2SAS_DEVICE *sas_device_priv_data;
3005 struct scsi_device *sdev;
3006
3007 shost_for_each_device(sdev, ioc->shost) {
3008 sas_device_priv_data = sdev->hostdata;
3009 if (!sas_device_priv_data)
3010 continue;
3011 if (sas_device_priv_data->block)
3012 continue;
3013 if (sas_device_priv_data->sas_target->handle == handle) {
3014 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
3015 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
3016 "handle(0x%04x)\n", ioc->name, handle));
3017 sas_device_priv_data->block = 1;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05303018 scsi_internal_device_block(sdev);
Eric Moore635374e2009-03-09 01:21:12 -06003019 }
3020 }
3021}
3022
3023/**
3024 * _scsih_block_io_to_children_attached_to_ex
3025 * @ioc: per adapter object
3026 * @sas_expander: the sas_device object
3027 *
3028 * This routine set sdev state to SDEV_BLOCK for all devices
3029 * attached to this expander. This function called when expander is
3030 * pulled.
3031 */
3032static void
3033_scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
3034 struct _sas_node *sas_expander)
3035{
3036 struct _sas_port *mpt2sas_port;
3037 struct _sas_device *sas_device;
3038 struct _sas_node *expander_sibling;
3039 unsigned long flags;
3040
3041 if (!sas_expander)
3042 return;
3043
3044 list_for_each_entry(mpt2sas_port,
3045 &sas_expander->sas_port_list, port_list) {
3046 if (mpt2sas_port->remote_identify.device_type ==
3047 SAS_END_DEVICE) {
3048 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3049 sas_device =
3050 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3051 mpt2sas_port->remote_identify.sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303052 if (sas_device)
3053 set_bit(sas_device->handle,
3054 ioc->blocking_handles);
Eric Moore635374e2009-03-09 01:21:12 -06003055 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06003056 }
3057 }
3058
3059 list_for_each_entry(mpt2sas_port,
3060 &sas_expander->sas_port_list, port_list) {
3061
3062 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05303063 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06003064 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05303065 SAS_FANOUT_EXPANDER_DEVICE) {
Eric Moore635374e2009-03-09 01:21:12 -06003066 expander_sibling =
3067 mpt2sas_scsih_expander_find_by_sas_address(
3068 ioc, mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06003069 _scsih_block_io_to_children_attached_to_ex(ioc,
3070 expander_sibling);
3071 }
3072 }
3073}
3074
3075/**
3076 * _scsih_block_io_to_children_attached_directly
3077 * @ioc: per adapter object
3078 * @event_data: topology change event data
3079 *
3080 * This routine set sdev state to SDEV_BLOCK for all devices
3081 * direct attached during device pull.
3082 */
3083static void
3084_scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3085 Mpi2EventDataSasTopologyChangeList_t *event_data)
3086{
3087 int i;
3088 u16 handle;
3089 u16 reason_code;
3090 u8 phy_number;
3091
3092 for (i = 0; i < event_data->NumEntries; i++) {
3093 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3094 if (!handle)
3095 continue;
3096 phy_number = event_data->StartPhyNum + i;
3097 reason_code = event_data->PHY[i].PhyStatus &
3098 MPI2_EVENT_SAS_TOPO_RC_MASK;
3099 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3100 _scsih_block_io_device(ioc, handle);
3101 }
3102}
3103
3104/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303105 * _scsih_tm_tr_send - send task management request
3106 * @ioc: per adapter object
3107 * @handle: device handle
3108 * Context: interrupt time.
3109 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003110 * This code is to initiate the device removal handshake protocol
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303111 * with controller firmware. This function will issue target reset
3112 * using high priority request queue. It will send a sas iounit
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003113 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303114 *
3115 * This is designed to send muliple task management request at the same
3116 * time to the fifo. If the fifo is full, we will append the request,
3117 * and process it in a future completion.
3118 */
3119static void
3120_scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3121{
3122 Mpi2SCSITaskManagementRequest_t *mpi_request;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303123 u16 smid;
3124 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303125 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3126 u64 sas_address = 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303127 unsigned long flags;
3128 struct _tr_list *delayed_tr;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303129 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303130
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303131 if (ioc->remove_host) {
3132 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3133 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3134 return;
3135 } else if (ioc->pci_error_recovery) {
3136 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3137 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3138 handle));
3139 return;
3140 }
3141 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3142 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3143 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3144 "operational: handle(0x%04x)\n", __func__, ioc->name,
3145 handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303146 return;
3147 }
3148
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303149 /* if PD, then return */
3150 if (test_bit(handle, ioc->pd_handles))
3151 return;
3152
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303153 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3154 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303155 if (sas_device && sas_device->starget &&
3156 sas_device->starget->hostdata) {
3157 sas_target_priv_data = sas_device->starget->hostdata;
3158 sas_target_priv_data->deleted = 1;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303159 sas_address = sas_device->sas_address;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303160 }
3161 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303162
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303163 if (sas_target_priv_data) {
3164 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3165 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3166 (unsigned long long)sas_address));
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05303167 _scsih_ublock_io_device(ioc, sas_address);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05303168 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303169 }
3170
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303171 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3172 if (!smid) {
3173 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3174 if (!delayed_tr)
3175 return;
3176 INIT_LIST_HEAD(&delayed_tr->list);
3177 delayed_tr->handle = handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303178 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3179 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3180 "DELAYED:tr:handle(0x%04x), (open)\n",
3181 ioc->name, handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303182 return;
3183 }
3184
Kashyap, Desai1278b112010-03-09 17:34:13 +05303185 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3186 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3187 ioc->tm_tr_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303188 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3189 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3190 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3191 mpi_request->DevHandle = cpu_to_le16(handle);
3192 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303193 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3194}
3195
3196
3197
3198/**
3199 * _scsih_sas_control_complete - completion routine
3200 * @ioc: per adapter object
3201 * @smid: system request message index
3202 * @msix_index: MSIX table index supplied by the OS
3203 * @reply: reply message frame(lower 32bit addr)
3204 * Context: interrupt time.
3205 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003206 * This is the sas iounit control completion routine.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303207 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003208 * handshake protocol with controller firmware.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303209 *
3210 * Return 1 meaning mf should be freed from _base_interrupt
3211 * 0 means the mf is freed from this function.
3212 */
3213static u8
3214_scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3215 u8 msix_index, u32 reply)
3216{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303217 Mpi2SasIoUnitControlReply_t *mpi_reply =
3218 mpt2sas_base_get_reply_virt_addr(ioc, reply);
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303219 if (likely(mpi_reply)) {
3220 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3221 "sc_complete:handle(0x%04x), (open) "
3222 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3223 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3224 le16_to_cpu(mpi_reply->IOCStatus),
3225 le32_to_cpu(mpi_reply->IOCLogInfo)));
3226 } else {
3227 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3228 ioc->name, __FILE__, __LINE__, __func__);
3229 }
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303230 return 1;
3231}
3232
3233/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303234 * _scsih_tm_tr_volume_send - send target reset request for volumes
3235 * @ioc: per adapter object
3236 * @handle: device handle
3237 * Context: interrupt time.
3238 *
3239 * This is designed to send muliple task management request at the same
3240 * time to the fifo. If the fifo is full, we will append the request,
3241 * and process it in a future completion.
3242 */
3243static void
3244_scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3245{
3246 Mpi2SCSITaskManagementRequest_t *mpi_request;
3247 u16 smid;
3248 struct _tr_list *delayed_tr;
3249
Eric Moore3cb54692010-07-08 14:44:34 -06003250 if (ioc->shost_recovery || ioc->remove_host ||
3251 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303252 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3253 "progress!\n", __func__, ioc->name));
3254 return;
3255 }
3256
3257 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3258 if (!smid) {
3259 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3260 if (!delayed_tr)
3261 return;
3262 INIT_LIST_HEAD(&delayed_tr->list);
3263 delayed_tr->handle = handle;
3264 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3265 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3266 "DELAYED:tr:handle(0x%04x), (open)\n",
3267 ioc->name, handle));
3268 return;
3269 }
3270
3271 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3272 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3273 ioc->tm_tr_volume_cb_idx));
3274 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3275 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3276 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3277 mpi_request->DevHandle = cpu_to_le16(handle);
3278 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3279 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3280}
3281
3282/**
3283 * _scsih_tm_volume_tr_complete - target reset completion
3284 * @ioc: per adapter object
3285 * @smid: system request message index
3286 * @msix_index: MSIX table index supplied by the OS
3287 * @reply: reply message frame(lower 32bit addr)
3288 * Context: interrupt time.
3289 *
3290 * Return 1 meaning mf should be freed from _base_interrupt
3291 * 0 means the mf is freed from this function.
3292 */
3293static u8
3294_scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3295 u8 msix_index, u32 reply)
3296{
3297 u16 handle;
3298 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3299 Mpi2SCSITaskManagementReply_t *mpi_reply =
3300 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3301
Eric Moore3cb54692010-07-08 14:44:34 -06003302 if (ioc->shost_recovery || ioc->remove_host ||
3303 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303304 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3305 "progress!\n", __func__, ioc->name));
3306 return 1;
3307 }
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303308 if (unlikely(!mpi_reply)) {
3309 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3310 ioc->name, __FILE__, __LINE__, __func__);
3311 return 1;
3312 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303313 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3314 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3315 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3316 dewtprintk(ioc, printk("spurious interrupt: "
3317 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3318 le16_to_cpu(mpi_reply->DevHandle), smid));
3319 return 0;
3320 }
3321
3322 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3323 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3324 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3325 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3326 le32_to_cpu(mpi_reply->IOCLogInfo),
3327 le32_to_cpu(mpi_reply->TerminationCount)));
3328
3329 return _scsih_check_for_pending_tm(ioc, smid);
3330}
3331
3332/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303333 * _scsih_tm_tr_complete -
3334 * @ioc: per adapter object
3335 * @smid: system request message index
3336 * @msix_index: MSIX table index supplied by the OS
3337 * @reply: reply message frame(lower 32bit addr)
3338 * Context: interrupt time.
3339 *
3340 * This is the target reset completion routine.
3341 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003342 * handshake protocol with controller firmware.
3343 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303344 *
3345 * Return 1 meaning mf should be freed from _base_interrupt
3346 * 0 means the mf is freed from this function.
3347 */
3348static u8
3349_scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3350 u32 reply)
3351{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303352 u16 handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303353 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303354 Mpi2SCSITaskManagementReply_t *mpi_reply =
3355 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3356 Mpi2SasIoUnitControlRequest_t *mpi_request;
3357 u16 smid_sas_ctrl;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303358 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303359
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303360 if (ioc->remove_host) {
3361 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3362 "removed\n", __func__, ioc->name));
3363 return 1;
3364 } else if (ioc->pci_error_recovery) {
3365 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3366 "error recovery\n", __func__, ioc->name));
3367 return 1;
3368 }
3369 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3370 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3371 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3372 "operational\n", __func__, ioc->name));
Kashyap, Desai1278b112010-03-09 17:34:13 +05303373 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303374 }
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05303375 if (unlikely(!mpi_reply)) {
3376 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3377 ioc->name, __FILE__, __LINE__, __func__);
3378 return 1;
3379 }
Kashyap, Desai1278b112010-03-09 17:34:13 +05303380 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3381 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3382 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3383 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3384 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3385 le16_to_cpu(mpi_reply->DevHandle), smid));
3386 return 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303387 }
3388
Kashyap, Desai1278b112010-03-09 17:34:13 +05303389 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3390 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3391 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3392 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3393 le32_to_cpu(mpi_reply->IOCLogInfo),
3394 le32_to_cpu(mpi_reply->TerminationCount)));
3395
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303396 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3397 if (!smid_sas_ctrl) {
3398 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3399 ioc->name, __func__);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303400 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303401 }
3402
Kashyap, Desai1278b112010-03-09 17:34:13 +05303403 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3404 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3405 ioc->tm_sas_control_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303406 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3407 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3408 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3409 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303410 mpi_request->DevHandle = mpi_request_tm->DevHandle;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303411 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303412
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303413 return _scsih_check_for_pending_tm(ioc, smid);
3414}
3415
3416/**
3417 * _scsih_check_for_pending_tm - check for pending task management
3418 * @ioc: per adapter object
3419 * @smid: system request message index
3420 *
3421 * This will check delayed target reset list, and feed the
3422 * next reqeust.
3423 *
3424 * Return 1 meaning mf should be freed from _base_interrupt
3425 * 0 means the mf is freed from this function.
3426 */
3427static u8
3428_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3429{
3430 struct _tr_list *delayed_tr;
3431
3432 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3433 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3434 struct _tr_list, list);
3435 mpt2sas_base_free_smid(ioc, smid);
3436 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3437 list_del(&delayed_tr->list);
3438 kfree(delayed_tr);
3439 return 0;
3440 }
3441
Kashyap, Desai1278b112010-03-09 17:34:13 +05303442 if (!list_empty(&ioc->delayed_tr_list)) {
3443 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3444 struct _tr_list, list);
3445 mpt2sas_base_free_smid(ioc, smid);
3446 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3447 list_del(&delayed_tr->list);
3448 kfree(delayed_tr);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303449 return 0;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303450 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303451
Kashyap, Desai1278b112010-03-09 17:34:13 +05303452 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303453}
3454
3455/**
Eric Moore635374e2009-03-09 01:21:12 -06003456 * _scsih_check_topo_delete_events - sanity check on topo events
3457 * @ioc: per adapter object
3458 * @event_data: the event data payload
3459 *
3460 * This routine added to better handle cable breaker.
3461 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003462 * This handles the case where driver receives multiple expander
Eric Moore635374e2009-03-09 01:21:12 -06003463 * add and delete events in a single shot. When there is a delete event
3464 * the routine will void any pending add events waiting in the event queue.
3465 *
3466 * Return nothing.
3467 */
3468static void
3469_scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3470 Mpi2EventDataSasTopologyChangeList_t *event_data)
3471{
3472 struct fw_event_work *fw_event;
3473 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3474 u16 expander_handle;
3475 struct _sas_node *sas_expander;
3476 unsigned long flags;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303477 int i, reason_code;
3478 u16 handle;
3479
3480 for (i = 0 ; i < event_data->NumEntries; i++) {
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303481 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3482 if (!handle)
3483 continue;
3484 reason_code = event_data->PHY[i].PhyStatus &
3485 MPI2_EVENT_SAS_TOPO_RC_MASK;
3486 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3487 _scsih_tm_tr_send(ioc, handle);
3488 }
Eric Moore635374e2009-03-09 01:21:12 -06003489
3490 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3491 if (expander_handle < ioc->sas_hba.num_phys) {
3492 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3493 return;
3494 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303495 if (event_data->ExpStatus ==
3496 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3497 /* put expander attached devices into blocking state */
Eric Moore635374e2009-03-09 01:21:12 -06003498 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3499 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3500 expander_handle);
Eric Moore635374e2009-03-09 01:21:12 -06003501 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303502 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3503 do {
3504 handle = find_first_bit(ioc->blocking_handles,
3505 ioc->facts.MaxDevHandle);
3506 if (handle < ioc->facts.MaxDevHandle)
3507 _scsih_block_io_device(ioc, handle);
3508 } while (test_and_clear_bit(handle, ioc->blocking_handles));
Eric Moore635374e2009-03-09 01:21:12 -06003509 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3510 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3511
3512 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3513 return;
3514
3515 /* mark ignore flag for pending events */
3516 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3517 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3518 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3519 fw_event->ignore)
3520 continue;
Joe Lawrence00713ad2014-06-25 17:03:33 -04003521 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3522 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06003523 if (local_event_data->ExpStatus ==
3524 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3525 local_event_data->ExpStatus ==
3526 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3527 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3528 expander_handle) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303529 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06003530 "setting ignoring flag\n", ioc->name));
3531 fw_event->ignore = 1;
3532 }
3533 }
3534 }
3535 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3536}
3537
3538/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303539 * _scsih_set_volume_delete_flag - setting volume delete flag
3540 * @ioc: per adapter object
3541 * @handle: device handle
3542 *
3543 * This
3544 * Return nothing.
3545 */
3546static void
3547_scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3548{
3549 struct _raid_device *raid_device;
3550 struct MPT2SAS_TARGET *sas_target_priv_data;
3551 unsigned long flags;
3552
3553 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3554 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3555 if (raid_device && raid_device->starget &&
3556 raid_device->starget->hostdata) {
3557 sas_target_priv_data =
3558 raid_device->starget->hostdata;
3559 sas_target_priv_data->deleted = 1;
3560 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3561 "setting delete flag: handle(0x%04x), "
3562 "wwid(0x%016llx)\n", ioc->name, handle,
3563 (unsigned long long) raid_device->wwid));
3564 }
3565 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3566}
3567
3568/**
3569 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3570 * @handle: input handle
3571 * @a: handle for volume a
3572 * @b: handle for volume b
3573 *
3574 * IR firmware only supports two raid volumes. The purpose of this
3575 * routine is to set the volume handle in either a or b. When the given
3576 * input handle is non-zero, or when a and b have not been set before.
3577 */
3578static void
3579_scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3580{
3581 if (!handle || handle == *a || handle == *b)
3582 return;
3583 if (!*a)
3584 *a = handle;
3585 else if (!*b)
3586 *b = handle;
3587}
3588
3589/**
3590 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3591 * @ioc: per adapter object
3592 * @event_data: the event data payload
3593 * Context: interrupt time.
3594 *
3595 * This routine will send target reset to volume, followed by target
3596 * resets to the PDs. This is called when a PD has been removed, or
3597 * volume has been deleted or removed. When the target reset is sent
3598 * to volume, the PD target resets need to be queued to start upon
3599 * completion of the volume target reset.
3600 *
3601 * Return nothing.
3602 */
3603static void
3604_scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3605 Mpi2EventDataIrConfigChangeList_t *event_data)
3606{
3607 Mpi2EventIrConfigElement_t *element;
3608 int i;
3609 u16 handle, volume_handle, a, b;
3610 struct _tr_list *delayed_tr;
3611
3612 a = 0;
3613 b = 0;
3614
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303615 if (ioc->is_warpdrive)
3616 return;
3617
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303618 /* Volume Resets for Deleted or Removed */
3619 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3620 for (i = 0; i < event_data->NumElements; i++, element++) {
3621 if (element->ReasonCode ==
3622 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3623 element->ReasonCode ==
3624 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3625 volume_handle = le16_to_cpu(element->VolDevHandle);
3626 _scsih_set_volume_delete_flag(ioc, volume_handle);
3627 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3628 }
3629 }
3630
3631 /* Volume Resets for UNHIDE events */
3632 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3633 for (i = 0; i < event_data->NumElements; i++, element++) {
3634 if (le32_to_cpu(event_data->Flags) &
3635 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3636 continue;
3637 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3638 volume_handle = le16_to_cpu(element->VolDevHandle);
3639 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3640 }
3641 }
3642
3643 if (a)
3644 _scsih_tm_tr_volume_send(ioc, a);
3645 if (b)
3646 _scsih_tm_tr_volume_send(ioc, b);
3647
3648 /* PD target resets */
3649 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3650 for (i = 0; i < event_data->NumElements; i++, element++) {
3651 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3652 continue;
3653 handle = le16_to_cpu(element->PhysDiskDevHandle);
3654 volume_handle = le16_to_cpu(element->VolDevHandle);
3655 clear_bit(handle, ioc->pd_handles);
3656 if (!volume_handle)
3657 _scsih_tm_tr_send(ioc, handle);
3658 else if (volume_handle == a || volume_handle == b) {
3659 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3660 BUG_ON(!delayed_tr);
3661 INIT_LIST_HEAD(&delayed_tr->list);
3662 delayed_tr->handle = handle;
3663 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3664 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3665 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3666 handle));
3667 } else
3668 _scsih_tm_tr_send(ioc, handle);
3669 }
3670}
3671
3672
3673/**
3674 * _scsih_check_volume_delete_events - set delete flag for volumes
3675 * @ioc: per adapter object
3676 * @event_data: the event data payload
3677 * Context: interrupt time.
3678 *
3679 * This will handle the case when the cable connected to entire volume is
3680 * pulled. We will take care of setting the deleted flag so normal IO will
3681 * not be sent.
3682 *
3683 * Return nothing.
3684 */
3685static void
3686_scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3687 Mpi2EventDataIrVolume_t *event_data)
3688{
3689 u32 state;
3690
3691 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3692 return;
3693 state = le32_to_cpu(event_data->NewValue);
3694 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3695 MPI2_RAID_VOL_STATE_FAILED)
3696 _scsih_set_volume_delete_flag(ioc,
3697 le16_to_cpu(event_data->VolDevHandle));
3698}
3699
3700/**
Eric Moore635374e2009-03-09 01:21:12 -06003701 * _scsih_flush_running_cmds - completing outstanding commands.
3702 * @ioc: per adapter object
3703 *
3704 * The flushing out of all pending scmd commands following host reset,
3705 * where all IO is dropped to the floor.
3706 *
3707 * Return nothing.
3708 */
3709static void
3710_scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3711{
3712 struct scsi_cmnd *scmd;
3713 u16 smid;
3714 u16 count = 0;
3715
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303716 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05303717 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003718 if (!scmd)
3719 continue;
3720 count++;
3721 mpt2sas_base_free_smid(ioc, smid);
3722 scsi_dma_unmap(scmd);
Eric Moore3cb54692010-07-08 14:44:34 -06003723 if (ioc->pci_error_recovery)
3724 scmd->result = DID_NO_CONNECT << 16;
3725 else
3726 scmd->result = DID_RESET << 16;
Eric Moore635374e2009-03-09 01:21:12 -06003727 scmd->scsi_done(scmd);
3728 }
3729 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3730 ioc->name, count));
3731}
3732
3733/**
Eric Moore3c621b32009-05-18 12:59:41 -06003734 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3735 * @scmd: pointer to scsi command object
3736 * @mpi_request: pointer to the SCSI_IO reqest message frame
3737 *
3738 * Supporting protection 1 and 3.
3739 *
3740 * Returns nothing
3741 */
3742static void
3743_scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3744{
3745 u16 eedp_flags;
3746 unsigned char prot_op = scsi_get_prot_op(scmd);
3747 unsigned char prot_type = scsi_get_prot_type(scmd);
3748
Eric Moored334aa72010-04-22 10:47:40 -06003749 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
Eric Moore3c621b32009-05-18 12:59:41 -06003750 return;
3751
3752 if (prot_op == SCSI_PROT_READ_STRIP)
3753 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3754 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3755 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3756 else
3757 return;
3758
Eric Moore3c621b32009-05-18 12:59:41 -06003759 switch (prot_type) {
3760 case SCSI_PROT_DIF_TYPE1:
Martin K. Petersen756aca72011-05-18 00:45:22 -04003761 case SCSI_PROT_DIF_TYPE2:
Eric Moore3c621b32009-05-18 12:59:41 -06003762
3763 /*
3764 * enable ref/guard checking
3765 * auto increment ref tag
3766 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303767 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
Eric Moore3c621b32009-05-18 12:59:41 -06003768 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3769 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3770 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3771 cpu_to_be32(scsi_get_lba(scmd));
Eric Moored334aa72010-04-22 10:47:40 -06003772 break;
Eric Moore3c621b32009-05-18 12:59:41 -06003773
Eric Moore3c621b32009-05-18 12:59:41 -06003774 case SCSI_PROT_DIF_TYPE3:
3775
3776 /*
3777 * enable guard checking
3778 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303779 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
Eric Moore3c621b32009-05-18 12:59:41 -06003780 break;
3781 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05303782 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3783 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
Eric Moore3c621b32009-05-18 12:59:41 -06003784}
3785
3786/**
3787 * _scsih_eedp_error_handling - return sense code for EEDP errors
3788 * @scmd: pointer to scsi command object
3789 * @ioc_status: ioc status
3790 *
3791 * Returns nothing
3792 */
3793static void
3794_scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3795{
3796 u8 ascq;
Eric Moore3c621b32009-05-18 12:59:41 -06003797
3798 switch (ioc_status) {
3799 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3800 ascq = 0x01;
3801 break;
3802 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3803 ascq = 0x02;
3804 break;
3805 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3806 ascq = 0x03;
3807 break;
3808 default:
3809 ascq = 0x00;
3810 break;
3811 }
3812
Martin K. Petersen9b5cd132012-08-28 14:29:36 -04003813 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq);
3814 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
Eric Moore3c621b32009-05-18 12:59:41 -06003815 SAM_STAT_CHECK_CONDITION;
3816}
3817
3818/**
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303819 * _scsih_scsi_direct_io_get - returns direct io flag
3820 * @ioc: per adapter object
3821 * @smid: system request message index
3822 *
3823 * Returns the smid stored scmd pointer.
3824 */
3825static inline u8
3826_scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3827{
3828 return ioc->scsi_lookup[smid - 1].direct_io;
3829}
3830
3831/**
3832 * _scsih_scsi_direct_io_set - sets direct io flag
3833 * @ioc: per adapter object
3834 * @smid: system request message index
3835 * @direct_io: Zero or non-zero value to set in the direct_io flag
3836 *
3837 * Returns Nothing.
3838 */
3839static inline void
3840_scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3841{
3842 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3843}
3844
3845
3846/**
3847 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3848 * @ioc: per adapter object
3849 * @scmd: pointer to scsi command object
3850 * @raid_device: pointer to raid device data structure
3851 * @mpi_request: pointer to the SCSI_IO reqest message frame
3852 * @smid: system request message index
3853 *
3854 * Returns nothing
3855 */
3856static void
3857_scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3858 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3859 u16 smid)
3860{
3861 u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size;
3862 u32 stripe_sz, stripe_exp;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303863 u8 num_pds, *cdb_ptr, i;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303864 u8 cdb0 = scmd->cmnd[0];
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303865 u64 v_llba;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303866
3867 /*
3868 * Try Direct I/O to RAID memeber disks
3869 */
3870 if (cdb0 == READ_16 || cdb0 == READ_10 ||
3871 cdb0 == WRITE_16 || cdb0 == WRITE_10) {
3872 cdb_ptr = mpi_request->CDB.CDB32;
3873
3874 if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4]
3875 | cdb_ptr[5])) {
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303876 io_size = scsi_bufflen(scmd) >>
3877 raid_device->block_exponent;
3878 i = (cdb0 < READ_16) ? 2 : 6;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303879 /* get virtual lba */
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303880 v_lba = be32_to_cpu(*(__be32 *)(&cdb_ptr[i]));
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303881
3882 if (((u64)v_lba + (u64)io_size - 1) <=
3883 (u32)raid_device->max_lba) {
3884 stripe_sz = raid_device->stripe_sz;
3885 stripe_exp = raid_device->stripe_exponent;
3886 stripe_off = v_lba & (stripe_sz - 1);
3887
3888 /* Check whether IO falls within a stripe */
3889 if ((stripe_off + io_size) <= stripe_sz) {
3890 num_pds = raid_device->num_pds;
3891 p_lba = v_lba >> stripe_exp;
3892 stripe_unit = p_lba / num_pds;
3893 column = p_lba % num_pds;
3894 p_lba = (stripe_unit << stripe_exp) +
3895 stripe_off;
3896 mpi_request->DevHandle =
3897 cpu_to_le16(raid_device->
3898 pd_handle[column]);
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303899 (*(__be32 *)(&cdb_ptr[i])) =
3900 cpu_to_be32(p_lba);
3901 /*
3902 * WD: To indicate this I/O is directI/O
3903 */
3904 _scsih_scsi_direct_io_set(ioc, smid, 1);
3905 }
3906 }
3907 } else {
3908 io_size = scsi_bufflen(scmd) >>
3909 raid_device->block_exponent;
3910 /* get virtual lba */
3911 v_llba = be64_to_cpu(*(__be64 *)(&cdb_ptr[2]));
3912
3913 if ((v_llba + (u64)io_size - 1) <=
3914 raid_device->max_lba) {
3915 stripe_sz = raid_device->stripe_sz;
3916 stripe_exp = raid_device->stripe_exponent;
3917 stripe_off = (u32) (v_llba & (stripe_sz - 1));
3918
3919 /* Check whether IO falls within a stripe */
3920 if ((stripe_off + io_size) <= stripe_sz) {
3921 num_pds = raid_device->num_pds;
3922 p_lba = (u32)(v_llba >> stripe_exp);
3923 stripe_unit = p_lba / num_pds;
3924 column = p_lba % num_pds;
3925 p_lba = (stripe_unit << stripe_exp) +
3926 stripe_off;
3927 mpi_request->DevHandle =
3928 cpu_to_le16(raid_device->
3929 pd_handle[column]);
3930 (*(__be64 *)(&cdb_ptr[2])) =
3931 cpu_to_be64((u64)p_lba);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303932 /*
3933 * WD: To indicate this I/O is directI/O
3934 */
3935 _scsih_scsi_direct_io_set(ioc, smid, 1);
3936 }
3937 }
3938 }
3939 }
3940}
3941
3942/**
Eric Moored5d135b2009-05-18 13:02:08 -06003943 * _scsih_qcmd - main scsi request entry point
Eric Moore635374e2009-03-09 01:21:12 -06003944 * @scmd: pointer to scsi command object
3945 * @done: function pointer to be invoked on completion
3946 *
3947 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3948 *
3949 * Returns 0 on success. If there's a failure, return either:
3950 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3951 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3952 */
3953static int
Matthew Wilcox90f951e2014-03-27 16:40:33 -04003954_scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06003955{
Matthew Wilcox90f951e2014-03-27 16:40:33 -04003956 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Eric Moore635374e2009-03-09 01:21:12 -06003957 struct MPT2SAS_DEVICE *sas_device_priv_data;
3958 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303959 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06003960 Mpi2SCSIIORequest_t *mpi_request;
3961 u32 mpi_control;
3962 u16 smid;
Eric Moore635374e2009-03-09 01:21:12 -06003963
Eric Moore635374e2009-03-09 01:21:12 -06003964 sas_device_priv_data = scmd->device->hostdata;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303965 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Eric Moore635374e2009-03-09 01:21:12 -06003966 scmd->result = DID_NO_CONNECT << 16;
3967 scmd->scsi_done(scmd);
3968 return 0;
3969 }
3970
Kashyap, Desai78215782011-06-14 10:57:08 +05303971 if (ioc->pci_error_recovery || ioc->remove_host) {
Eric Moore3cb54692010-07-08 14:44:34 -06003972 scmd->result = DID_NO_CONNECT << 16;
3973 scmd->scsi_done(scmd);
3974 return 0;
3975 }
3976
Eric Moore635374e2009-03-09 01:21:12 -06003977 sas_target_priv_data = sas_device_priv_data->sas_target;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303978 /* invalid device handle */
3979 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
Eric Moore635374e2009-03-09 01:21:12 -06003980 scmd->result = DID_NO_CONNECT << 16;
3981 scmd->scsi_done(scmd);
3982 return 0;
3983 }
3984
Kashyap, Desai130b9582010-04-08 17:54:32 +05303985 /* host recovery or link resets sent via IOCTLs */
3986 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
Eric Moore635374e2009-03-09 01:21:12 -06003987 return SCSI_MLQUEUE_HOST_BUSY;
Uwe Kleine-König65155b32010-06-11 12:17:01 +02003988 /* device busy with task management */
Kashyap, Desai130b9582010-04-08 17:54:32 +05303989 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3990 return SCSI_MLQUEUE_DEVICE_BUSY;
3991 /* device has been deleted */
3992 else if (sas_target_priv_data->deleted) {
3993 scmd->result = DID_NO_CONNECT << 16;
3994 scmd->scsi_done(scmd);
3995 return 0;
3996 }
Eric Moore635374e2009-03-09 01:21:12 -06003997
3998 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3999 mpi_control = MPI2_SCSIIO_CONTROL_READ;
4000 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
4001 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
4002 else
4003 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
4004
4005 /* set tags */
4006 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
4007 if (scmd->device->tagged_supported) {
4008 if (scmd->device->ordered_tags)
4009 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
4010 else
4011 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
4012 } else
Sreekanth Reddy48ba2ef2013-02-02 00:58:20 +05304013 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
Eric Moore635374e2009-03-09 01:21:12 -06004014 } else
4015 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304016 /* Make sure Device is not raid volume.
4017 * We do not expose raid functionality to upper layer for warpdrive.
4018 */
4019 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Eric Moored334aa72010-04-22 10:47:40 -06004020 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
Eric Moore635374e2009-03-09 01:21:12 -06004021 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
4022
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304023 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06004024 if (!smid) {
4025 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
4026 ioc->name, __func__);
4027 goto out;
4028 }
4029 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4030 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
Eric Moore3c621b32009-05-18 12:59:41 -06004031 _scsih_setup_eedp(scmd, mpi_request);
Eric Moored334aa72010-04-22 10:47:40 -06004032 if (scmd->cmd_len == 32)
4033 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
Eric Moore635374e2009-03-09 01:21:12 -06004034 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4035 if (sas_device_priv_data->sas_target->flags &
4036 MPT_TARGET_FLAGS_RAID_COMPONENT)
4037 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4038 else
Matthew Wilcox90f951e2014-03-27 16:40:33 -04004039 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
Eric Moore635374e2009-03-09 01:21:12 -06004040 mpi_request->DevHandle =
4041 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4042 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
4043 mpi_request->Control = cpu_to_le32(mpi_control);
4044 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4045 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4046 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4047 mpi_request->SenseBufferLowAddress =
Kashyap, Desaiec9472c2009-09-23 17:34:13 +05304048 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004049 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
4050 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
4051 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304052 mpi_request->VF_ID = 0; /* TODO */
4053 mpi_request->VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004054 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4055 mpi_request->LUN);
4056 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4057
4058 if (!mpi_request->DataLength) {
4059 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
4060 } else {
4061 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
4062 mpt2sas_base_free_smid(ioc, smid);
4063 goto out;
4064 }
4065 }
4066
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304067 raid_device = sas_target_priv_data->raid_device;
4068 if (raid_device && raid_device->direct_io_enabled)
4069 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4070 smid);
4071
Kashyap, Desai58287fd2010-03-17 16:27:25 +05304072 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
4073 mpt2sas_base_put_smid_scsi_io(ioc, smid,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304074 le16_to_cpu(mpi_request->DevHandle));
Kashyap, Desai58287fd2010-03-17 16:27:25 +05304075 else
4076 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004077 return 0;
4078
4079 out:
4080 return SCSI_MLQUEUE_HOST_BUSY;
4081}
4082
4083/**
4084 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4085 * @sense_buffer: sense data returned by target
4086 * @data: normalized skey/asc/ascq
4087 *
4088 * Return nothing.
4089 */
4090static void
4091_scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4092{
4093 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4094 /* descriptor format */
4095 data->skey = sense_buffer[1] & 0x0F;
4096 data->asc = sense_buffer[2];
4097 data->ascq = sense_buffer[3];
4098 } else {
4099 /* fixed format */
4100 data->skey = sense_buffer[2] & 0x0F;
4101 data->asc = sense_buffer[12];
4102 data->ascq = sense_buffer[13];
4103 }
4104}
4105
4106#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4107/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004108 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
Eric Moore635374e2009-03-09 01:21:12 -06004109 * @ioc: per adapter object
4110 * @scmd: pointer to scsi command object
4111 * @mpi_reply: reply mf payload returned from firmware
4112 *
4113 * scsi_status - SCSI Status code returned from target device
4114 * scsi_state - state info associated with SCSI_IO determined by ioc
4115 * ioc_status - ioc supplied status info
4116 *
4117 * Return nothing.
4118 */
4119static void
4120_scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4121 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4122{
4123 u32 response_info;
4124 u8 *response_bytes;
4125 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4126 MPI2_IOCSTATUS_MASK;
4127 u8 scsi_state = mpi_reply->SCSIState;
4128 u8 scsi_status = mpi_reply->SCSIStatus;
4129 char *desc_ioc_state = NULL;
4130 char *desc_scsi_status = NULL;
4131 char *desc_scsi_state = ioc->tmp_string;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304132 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304133 struct _sas_device *sas_device = NULL;
4134 unsigned long flags;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304135 struct scsi_target *starget = scmd->device->sdev_target;
4136 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304137 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304138
4139 if (!priv_target)
4140 return;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304141
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304142 if (ioc->hide_ir_msg)
4143 device_str = "WarpDrive";
4144 else
4145 device_str = "volume";
4146
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304147 if (log_info == 0x31170000)
4148 return;
Eric Moore635374e2009-03-09 01:21:12 -06004149
4150 switch (ioc_status) {
4151 case MPI2_IOCSTATUS_SUCCESS:
4152 desc_ioc_state = "success";
4153 break;
4154 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4155 desc_ioc_state = "invalid function";
4156 break;
4157 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4158 desc_ioc_state = "scsi recovered error";
4159 break;
4160 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4161 desc_ioc_state = "scsi invalid dev handle";
4162 break;
4163 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4164 desc_ioc_state = "scsi device not there";
4165 break;
4166 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4167 desc_ioc_state = "scsi data overrun";
4168 break;
4169 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4170 desc_ioc_state = "scsi data underrun";
4171 break;
4172 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4173 desc_ioc_state = "scsi io data error";
4174 break;
4175 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4176 desc_ioc_state = "scsi protocol error";
4177 break;
4178 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4179 desc_ioc_state = "scsi task terminated";
4180 break;
4181 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4182 desc_ioc_state = "scsi residual mismatch";
4183 break;
4184 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4185 desc_ioc_state = "scsi task mgmt failed";
4186 break;
4187 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4188 desc_ioc_state = "scsi ioc terminated";
4189 break;
4190 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4191 desc_ioc_state = "scsi ext terminated";
4192 break;
Eric Moore3c621b32009-05-18 12:59:41 -06004193 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4194 desc_ioc_state = "eedp guard error";
4195 break;
4196 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4197 desc_ioc_state = "eedp ref tag error";
4198 break;
4199 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4200 desc_ioc_state = "eedp app tag error";
4201 break;
Eric Moore635374e2009-03-09 01:21:12 -06004202 default:
4203 desc_ioc_state = "unknown";
4204 break;
4205 }
4206
4207 switch (scsi_status) {
4208 case MPI2_SCSI_STATUS_GOOD:
4209 desc_scsi_status = "good";
4210 break;
4211 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4212 desc_scsi_status = "check condition";
4213 break;
4214 case MPI2_SCSI_STATUS_CONDITION_MET:
4215 desc_scsi_status = "condition met";
4216 break;
4217 case MPI2_SCSI_STATUS_BUSY:
4218 desc_scsi_status = "busy";
4219 break;
4220 case MPI2_SCSI_STATUS_INTERMEDIATE:
4221 desc_scsi_status = "intermediate";
4222 break;
4223 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4224 desc_scsi_status = "intermediate condmet";
4225 break;
4226 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4227 desc_scsi_status = "reservation conflict";
4228 break;
4229 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4230 desc_scsi_status = "command terminated";
4231 break;
4232 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4233 desc_scsi_status = "task set full";
4234 break;
4235 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4236 desc_scsi_status = "aca active";
4237 break;
4238 case MPI2_SCSI_STATUS_TASK_ABORTED:
4239 desc_scsi_status = "task aborted";
4240 break;
4241 default:
4242 desc_scsi_status = "unknown";
4243 break;
4244 }
4245
4246 desc_scsi_state[0] = '\0';
4247 if (!scsi_state)
4248 desc_scsi_state = " ";
4249 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4250 strcat(desc_scsi_state, "response info ");
4251 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4252 strcat(desc_scsi_state, "state terminated ");
4253 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4254 strcat(desc_scsi_state, "no status ");
4255 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4256 strcat(desc_scsi_state, "autosense failed ");
4257 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4258 strcat(desc_scsi_state, "autosense valid ");
4259
4260 scsi_print_command(scmd);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304261
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304262 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304263 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4264 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304265 } else {
4266 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4267 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4268 priv_target->sas_address);
4269 if (sas_device) {
4270 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4271 "phy(%d)\n", ioc->name, sas_device->sas_address,
4272 sas_device->phy);
4273 printk(MPT2SAS_WARN_FMT
4274 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4275 ioc->name, sas_device->enclosure_logical_id,
4276 sas_device->slot);
4277 }
4278 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304279 }
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304280
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304281 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4282 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4283 desc_ioc_state, ioc_status, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004284 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4285 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4286 scsi_get_resid(scmd));
4287 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4288 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4289 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4290 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4291 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4292 scsi_status, desc_scsi_state, scsi_state);
4293
4294 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4295 struct sense_info data;
4296 _scsih_normalize_sense(scmd->sense_buffer, &data);
4297 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
Kashyap, Desaie94f6742010-03-17 16:24:52 +05304298 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4299 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
Eric Moore635374e2009-03-09 01:21:12 -06004300 }
4301
4302 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4303 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4304 response_bytes = (u8 *)&response_info;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304305 _scsih_response_code(ioc, response_bytes[0]);
Eric Moore635374e2009-03-09 01:21:12 -06004306 }
4307}
4308#endif
4309
4310/**
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304311 * _scsih_turn_on_fault_led - illuminate Fault LED
Eric Moore635374e2009-03-09 01:21:12 -06004312 * @ioc: per adapter object
4313 * @handle: device handle
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304314 * Context: process
4315 *
4316 * Return nothing.
4317 */
4318static void
4319_scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4320{
4321 Mpi2SepReply_t mpi_reply;
4322 Mpi2SepRequest_t mpi_request;
4323
4324 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4325 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4326 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4327 mpi_request.SlotStatus =
4328 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4329 mpi_request.DevHandle = cpu_to_le16(handle);
4330 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4331 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4332 &mpi_request)) != 0) {
4333 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4334 __FILE__, __LINE__, __func__);
4335 return;
4336 }
4337
4338 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4339 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4340 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4341 le16_to_cpu(mpi_reply.IOCStatus),
4342 le32_to_cpu(mpi_reply.IOCLogInfo)));
4343 return;
4344 }
4345}
4346
4347/**
4348 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4349 * @ioc: per adapter object
4350 * @handle: device handle
4351 * Context: interrupt.
4352 *
4353 * Return nothing.
4354 */
4355static void
4356_scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4357{
4358 struct fw_event_work *fw_event;
4359
4360 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4361 if (!fw_event)
4362 return;
4363 fw_event->event = MPT2SAS_TURN_ON_FAULT_LED;
4364 fw_event->device_handle = handle;
4365 fw_event->ioc = ioc;
4366 _scsih_fw_event_add(ioc, fw_event);
4367}
4368
4369/**
4370 * _scsih_smart_predicted_fault - process smart errors
4371 * @ioc: per adapter object
4372 * @handle: device handle
4373 * Context: interrupt.
Eric Moore635374e2009-03-09 01:21:12 -06004374 *
4375 * Return nothing.
4376 */
4377static void
4378_scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4379{
Eric Moore635374e2009-03-09 01:21:12 -06004380 struct scsi_target *starget;
4381 struct MPT2SAS_TARGET *sas_target_priv_data;
4382 Mpi2EventNotificationReply_t *event_reply;
4383 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4384 struct _sas_device *sas_device;
4385 ssize_t sz;
4386 unsigned long flags;
4387
4388 /* only handle non-raid devices */
4389 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4390 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4391 if (!sas_device) {
4392 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4393 return;
4394 }
4395 starget = sas_device->starget;
4396 sas_target_priv_data = starget->hostdata;
4397
4398 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4399 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4400 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4401 return;
4402 }
4403 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4404 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4405
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304406 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4407 _scsih_send_event_to_turn_on_fault_led(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06004408
4409 /* insert into event log */
4410 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4411 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
Anton Blanchardf6a290b42011-11-07 22:05:21 +11004412 event_reply = kzalloc(sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06004413 if (!event_reply) {
4414 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4415 ioc->name, __FILE__, __LINE__, __func__);
4416 return;
4417 }
4418
4419 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4420 event_reply->Event =
4421 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4422 event_reply->MsgLength = sz/4;
4423 event_reply->EventDataLength =
4424 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4425 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4426 event_reply->EventData;
4427 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4428 event_data->ASC = 0x5D;
4429 event_data->DevHandle = cpu_to_le16(handle);
4430 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4431 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4432 kfree(event_reply);
4433}
4434
4435/**
Eric Moored5d135b2009-05-18 13:02:08 -06004436 * _scsih_io_done - scsi request callback
Eric Moore635374e2009-03-09 01:21:12 -06004437 * @ioc: per adapter object
4438 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304439 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06004440 * @reply: reply message frame(lower 32bit addr)
4441 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304442 * Callback handler when using _scsih_qcmd.
Eric Moore635374e2009-03-09 01:21:12 -06004443 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304444 * Return 1 meaning mf should be freed from _base_interrupt
4445 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06004446 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304447static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304448_scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06004449{
4450 Mpi2SCSIIORequest_t *mpi_request;
4451 Mpi2SCSIIOReply_t *mpi_reply;
4452 struct scsi_cmnd *scmd;
4453 u16 ioc_status;
4454 u32 xfer_cnt;
4455 u8 scsi_state;
4456 u8 scsi_status;
4457 u32 log_info;
4458 struct MPT2SAS_DEVICE *sas_device_priv_data;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304459 u32 response_code = 0;
Kashyap, Desai82a45252011-07-05 12:40:23 +05304460 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06004461
4462 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05304463 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004464 if (scmd == NULL)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304465 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004466
4467 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4468
4469 if (mpi_reply == NULL) {
4470 scmd->result = DID_OK << 16;
4471 goto out;
4472 }
4473
4474 sas_device_priv_data = scmd->device->hostdata;
4475 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4476 sas_device_priv_data->sas_target->deleted) {
4477 scmd->result = DID_NO_CONNECT << 16;
4478 goto out;
4479 }
nagalakshmi.nandigama@lsi.com4da7af92011-12-01 07:53:02 +05304480 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304481 /*
4482 * WARPDRIVE: If direct_io is set then it is directIO,
4483 * the failed direct I/O should be redirected to volume
4484 */
nagalakshmi.nandigama@lsi.com4da7af92011-12-01 07:53:02 +05304485 if (_scsih_scsi_direct_io_get(ioc, smid) &&
4486 ((ioc_status & MPI2_IOCSTATUS_MASK)
4487 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
Kashyap, Desai82a45252011-07-05 12:40:23 +05304488 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4489 ioc->scsi_lookup[smid - 1].scmd = scmd;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304490 _scsih_scsi_direct_io_set(ioc, smid, 0);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05304491 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304492 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4493 mpi_request->DevHandle =
4494 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4495 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4496 sas_device_priv_data->sas_target->handle);
4497 return 0;
4498 }
4499
Eric Moore635374e2009-03-09 01:21:12 -06004500
4501 /* turning off TLR */
Kashyap, Desai9982f592009-09-23 17:23:07 +05304502 scsi_state = mpi_reply->SCSIState;
4503 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4504 response_code =
4505 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
Eric Moore635374e2009-03-09 01:21:12 -06004506 if (!sas_device_priv_data->tlr_snoop_check) {
4507 sas_device_priv_data->tlr_snoop_check++;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304508 /* Make sure Device is not raid volume.
4509 * We do not expose raid functionality to upper layer for warpdrive.
4510 */
4511 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Kashyap, Desai3ed21522010-02-17 16:08:36 +05304512 sas_is_tlr_enabled(scmd->device) &&
Kashyap, Desai84f0b042009-12-16 18:56:28 +05304513 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4514 sas_disable_tlr(scmd->device);
4515 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4516 }
Eric Moore635374e2009-03-09 01:21:12 -06004517 }
4518
4519 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4520 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
Eric Moore635374e2009-03-09 01:21:12 -06004521 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4522 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4523 else
4524 log_info = 0;
4525 ioc_status &= MPI2_IOCSTATUS_MASK;
Eric Moore635374e2009-03-09 01:21:12 -06004526 scsi_status = mpi_reply->SCSIStatus;
4527
4528 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4529 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4530 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4531 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4532 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4533 }
4534
4535 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4536 struct sense_info data;
4537 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4538 smid);
Eric Moore0d04df92009-04-21 15:38:43 -06004539 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
Eric Moore635374e2009-03-09 01:21:12 -06004540 le32_to_cpu(mpi_reply->SenseCount));
Eric Moore0d04df92009-04-21 15:38:43 -06004541 memcpy(scmd->sense_buffer, sense_data, sz);
Eric Moore635374e2009-03-09 01:21:12 -06004542 _scsih_normalize_sense(scmd->sense_buffer, &data);
4543 /* failure prediction threshold exceeded */
4544 if (data.asc == 0x5D)
4545 _scsih_smart_predicted_fault(ioc,
4546 le16_to_cpu(mpi_reply->DevHandle));
4547 }
4548
4549 switch (ioc_status) {
4550 case MPI2_IOCSTATUS_BUSY:
4551 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4552 scmd->result = SAM_STAT_BUSY;
4553 break;
4554
4555 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4556 scmd->result = DID_NO_CONNECT << 16;
4557 break;
4558
4559 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4560 if (sas_device_priv_data->block) {
Kashyap, Desaie4e7c7e2009-09-23 17:33:14 +05304561 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4562 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06004563 }
nagalakshmi.nandigama@lsi.com3ade1ca2011-12-01 07:42:40 +05304564 scmd->result = DID_SOFT_ERROR << 16;
4565 break;
Eric Moore635374e2009-03-09 01:21:12 -06004566 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4567 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4568 scmd->result = DID_RESET << 16;
4569 break;
4570
4571 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4572 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4573 scmd->result = DID_SOFT_ERROR << 16;
4574 else
4575 scmd->result = (DID_OK << 16) | scsi_status;
4576 break;
4577
4578 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4579 scmd->result = (DID_OK << 16) | scsi_status;
4580
4581 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4582 break;
4583
4584 if (xfer_cnt < scmd->underflow) {
4585 if (scsi_status == SAM_STAT_BUSY)
4586 scmd->result = SAM_STAT_BUSY;
4587 else
4588 scmd->result = DID_SOFT_ERROR << 16;
4589 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4590 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4591 scmd->result = DID_SOFT_ERROR << 16;
4592 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4593 scmd->result = DID_RESET << 16;
4594 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4595 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4596 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4597 scmd->result = (DRIVER_SENSE << 24) |
4598 SAM_STAT_CHECK_CONDITION;
4599 scmd->sense_buffer[0] = 0x70;
4600 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4601 scmd->sense_buffer[12] = 0x20;
4602 scmd->sense_buffer[13] = 0;
4603 }
4604 break;
4605
4606 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4607 scsi_set_resid(scmd, 0);
4608 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4609 case MPI2_IOCSTATUS_SUCCESS:
4610 scmd->result = (DID_OK << 16) | scsi_status;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304611 if (response_code ==
4612 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4613 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4614 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
Eric Moore635374e2009-03-09 01:21:12 -06004615 scmd->result = DID_SOFT_ERROR << 16;
4616 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4617 scmd->result = DID_RESET << 16;
4618 break;
4619
Eric Moore3c621b32009-05-18 12:59:41 -06004620 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4621 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4622 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4623 _scsih_eedp_error_handling(scmd, ioc_status);
4624 break;
Eric Moore635374e2009-03-09 01:21:12 -06004625 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4626 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4627 case MPI2_IOCSTATUS_INVALID_SGL:
4628 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4629 case MPI2_IOCSTATUS_INVALID_FIELD:
4630 case MPI2_IOCSTATUS_INVALID_STATE:
4631 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4632 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4633 default:
4634 scmd->result = DID_SOFT_ERROR << 16;
4635 break;
4636
4637 }
4638
4639#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4640 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4641 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4642#endif
4643
4644 out:
4645 scsi_dma_unmap(scmd);
4646 scmd->scsi_done(scmd);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304647 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004648}
4649
4650/**
Eric Moore635374e2009-03-09 01:21:12 -06004651 * _scsih_sas_host_refresh - refreshing sas host object contents
4652 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06004653 * Context: user
4654 *
4655 * During port enable, fw will send topology events for every device. Its
4656 * possible that the handles may change from the previous setting, so this
4657 * code keeping handles updating if changed.
4658 *
4659 * Return nothing.
4660 */
4661static void
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304662_scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06004663{
4664 u16 sz;
4665 u16 ioc_status;
4666 int i;
4667 Mpi2ConfigReply_t mpi_reply;
4668 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304669 u16 attached_handle;
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304670 u8 link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06004671
4672 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4673 "updating handles for sas_host(0x%016llx)\n",
4674 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4675
4676 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4677 * sizeof(Mpi2SasIOUnit0PhyData_t));
4678 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4679 if (!sas_iounit_pg0) {
4680 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4681 ioc->name, __FILE__, __LINE__, __func__);
4682 return;
4683 }
Eric Moore635374e2009-03-09 01:21:12 -06004684
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304685 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4686 sas_iounit_pg0, sz)) != 0)
4687 goto out;
4688 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4689 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4690 goto out;
4691 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304692 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304693 if (i == 0)
4694 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4695 PhyData[0].ControllerDevHandle);
4696 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4697 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4698 AttachedDevHandle);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304699 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4700 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304701 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304702 attached_handle, i, link_rate);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304703 }
Eric Moore635374e2009-03-09 01:21:12 -06004704 out:
4705 kfree(sas_iounit_pg0);
4706}
4707
4708/**
4709 * _scsih_sas_host_add - create sas host object
4710 * @ioc: per adapter object
4711 *
4712 * Creating host side data object, stored in ioc->sas_hba
4713 *
4714 * Return nothing.
4715 */
4716static void
4717_scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4718{
4719 int i;
4720 Mpi2ConfigReply_t mpi_reply;
4721 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4722 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4723 Mpi2SasPhyPage0_t phy_pg0;
4724 Mpi2SasDevicePage0_t sas_device_pg0;
4725 Mpi2SasEnclosurePage0_t enclosure_pg0;
4726 u16 ioc_status;
4727 u16 sz;
4728 u16 device_missing_delay;
4729
4730 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4731 if (!ioc->sas_hba.num_phys) {
4732 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4733 ioc->name, __FILE__, __LINE__, __func__);
4734 return;
4735 }
4736
4737 /* sas_iounit page 0 */
4738 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4739 sizeof(Mpi2SasIOUnit0PhyData_t));
4740 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4741 if (!sas_iounit_pg0) {
4742 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4743 ioc->name, __FILE__, __LINE__, __func__);
4744 return;
4745 }
4746 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4747 sas_iounit_pg0, sz))) {
4748 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4749 ioc->name, __FILE__, __LINE__, __func__);
4750 goto out;
4751 }
4752 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4753 MPI2_IOCSTATUS_MASK;
4754 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4755 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4756 ioc->name, __FILE__, __LINE__, __func__);
4757 goto out;
4758 }
4759
4760 /* sas_iounit page 1 */
4761 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4762 sizeof(Mpi2SasIOUnit1PhyData_t));
4763 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4764 if (!sas_iounit_pg1) {
4765 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4766 ioc->name, __FILE__, __LINE__, __func__);
4767 goto out;
4768 }
4769 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4770 sas_iounit_pg1, sz))) {
4771 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4772 ioc->name, __FILE__, __LINE__, __func__);
4773 goto out;
4774 }
4775 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4776 MPI2_IOCSTATUS_MASK;
4777 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4778 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4779 ioc->name, __FILE__, __LINE__, __func__);
4780 goto out;
4781 }
4782
4783 ioc->io_missing_delay =
4784 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4785 device_missing_delay =
4786 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4787 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4788 ioc->device_missing_delay = (device_missing_delay &
4789 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4790 else
4791 ioc->device_missing_delay = device_missing_delay &
4792 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4793
4794 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4795 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4796 sizeof(struct _sas_phy), GFP_KERNEL);
4797 if (!ioc->sas_hba.phy) {
4798 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4799 ioc->name, __FILE__, __LINE__, __func__);
4800 goto out;
4801 }
4802 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4803 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4804 i))) {
4805 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4806 ioc->name, __FILE__, __LINE__, __func__);
4807 goto out;
4808 }
4809 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4810 MPI2_IOCSTATUS_MASK;
4811 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4812 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4813 ioc->name, __FILE__, __LINE__, __func__);
4814 goto out;
4815 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304816
4817 if (i == 0)
4818 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4819 PhyData[0].ControllerDevHandle);
4820 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
Eric Moore635374e2009-03-09 01:21:12 -06004821 ioc->sas_hba.phy[i].phy_id = i;
4822 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4823 phy_pg0, ioc->sas_hba.parent_dev);
4824 }
4825 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304826 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06004827 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4828 ioc->name, __FILE__, __LINE__, __func__);
4829 goto out;
4830 }
Eric Moore635374e2009-03-09 01:21:12 -06004831 ioc->sas_hba.enclosure_handle =
4832 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4833 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4834 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4835 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4836 (unsigned long long) ioc->sas_hba.sas_address,
4837 ioc->sas_hba.num_phys) ;
4838
4839 if (ioc->sas_hba.enclosure_handle) {
4840 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4841 &enclosure_pg0,
4842 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4843 ioc->sas_hba.enclosure_handle))) {
4844 ioc->sas_hba.enclosure_logical_id =
4845 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4846 }
4847 }
4848
4849 out:
4850 kfree(sas_iounit_pg1);
4851 kfree(sas_iounit_pg0);
4852}
4853
4854/**
4855 * _scsih_expander_add - creating expander object
4856 * @ioc: per adapter object
4857 * @handle: expander handle
4858 *
4859 * Creating expander object, stored in ioc->sas_expander_list.
4860 *
4861 * Return 0 for success, else error.
4862 */
4863static int
4864_scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4865{
4866 struct _sas_node *sas_expander;
4867 Mpi2ConfigReply_t mpi_reply;
4868 Mpi2ExpanderPage0_t expander_pg0;
4869 Mpi2ExpanderPage1_t expander_pg1;
4870 Mpi2SasEnclosurePage0_t enclosure_pg0;
4871 u32 ioc_status;
4872 u16 parent_handle;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05304873 u64 sas_address, sas_address_parent = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004874 int i;
4875 unsigned long flags;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304876 struct _sas_port *mpt2sas_port = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06004877 int rc = 0;
4878
4879 if (!handle)
4880 return -1;
4881
Eric Moore3cb54692010-07-08 14:44:34 -06004882 if (ioc->shost_recovery || ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05304883 return -1;
4884
Eric Moore635374e2009-03-09 01:21:12 -06004885 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4886 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4887 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4888 ioc->name, __FILE__, __LINE__, __func__);
4889 return -1;
4890 }
4891
4892 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4893 MPI2_IOCSTATUS_MASK;
4894 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4895 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4896 ioc->name, __FILE__, __LINE__, __func__);
4897 return -1;
4898 }
4899
4900 /* handle out of order topology events */
4901 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304902 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4903 != 0) {
4904 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4905 ioc->name, __FILE__, __LINE__, __func__);
4906 return -1;
4907 }
4908 if (sas_address_parent != ioc->sas_hba.sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06004909 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304910 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4911 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004912 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4913 if (!sas_expander) {
4914 rc = _scsih_expander_add(ioc, parent_handle);
4915 if (rc != 0)
4916 return rc;
4917 }
4918 }
4919
Eric Moore635374e2009-03-09 01:21:12 -06004920 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304921 sas_address = le64_to_cpu(expander_pg0.SASAddress);
Eric Moore635374e2009-03-09 01:21:12 -06004922 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4923 sas_address);
4924 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4925
4926 if (sas_expander)
4927 return 0;
4928
4929 sas_expander = kzalloc(sizeof(struct _sas_node),
4930 GFP_KERNEL);
4931 if (!sas_expander) {
4932 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4933 ioc->name, __FILE__, __LINE__, __func__);
4934 return -1;
4935 }
4936
4937 sas_expander->handle = handle;
4938 sas_expander->num_phys = expander_pg0.NumPhys;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304939 sas_expander->sas_address_parent = sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06004940 sas_expander->sas_address = sas_address;
4941
4942 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4943 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304944 handle, parent_handle, (unsigned long long)
Eric Moore635374e2009-03-09 01:21:12 -06004945 sas_expander->sas_address, sas_expander->num_phys);
4946
4947 if (!sas_expander->num_phys)
4948 goto out_fail;
4949 sas_expander->phy = kcalloc(sas_expander->num_phys,
4950 sizeof(struct _sas_phy), GFP_KERNEL);
4951 if (!sas_expander->phy) {
4952 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4953 ioc->name, __FILE__, __LINE__, __func__);
4954 rc = -1;
4955 goto out_fail;
4956 }
4957
4958 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4959 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304960 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004961 if (!mpt2sas_port) {
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 }
4967 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4968
4969 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4970 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4971 &expander_pg1, i, handle))) {
4972 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4973 ioc->name, __FILE__, __LINE__, __func__);
Kashyap, Desai20f58952009-08-07 19:34:26 +05304974 rc = -1;
4975 goto out_fail;
Eric Moore635374e2009-03-09 01:21:12 -06004976 }
4977 sas_expander->phy[i].handle = handle;
4978 sas_expander->phy[i].phy_id = i;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304979
4980 if ((mpt2sas_transport_add_expander_phy(ioc,
4981 &sas_expander->phy[i], expander_pg1,
4982 sas_expander->parent_dev))) {
4983 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4984 ioc->name, __FILE__, __LINE__, __func__);
4985 rc = -1;
4986 goto out_fail;
4987 }
Eric Moore635374e2009-03-09 01:21:12 -06004988 }
4989
4990 if (sas_expander->enclosure_handle) {
4991 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4992 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4993 sas_expander->enclosure_handle))) {
4994 sas_expander->enclosure_logical_id =
4995 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4996 }
4997 }
4998
4999 _scsih_expander_node_add(ioc, sas_expander);
5000 return 0;
5001
5002 out_fail:
5003
Kashyap, Desai20f58952009-08-07 19:34:26 +05305004 if (mpt2sas_port)
5005 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305006 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06005007 kfree(sas_expander);
5008 return rc;
5009}
5010
5011/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05305012 * _scsih_done - scsih callback handler.
5013 * @ioc: per adapter object
5014 * @smid: system request message index
5015 * @msix_index: MSIX table index supplied by the OS
5016 * @reply: reply message frame(lower 32bit addr)
5017 *
5018 * Callback handler when sending internal generated message frames.
5019 * The callback index passed is `ioc->scsih_cb_idx`
5020 *
5021 * Return 1 meaning mf should be freed from _base_interrupt
5022 * 0 means the mf is freed from this function.
5023 */
5024static u8
5025_scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5026{
5027 MPI2DefaultReply_t *mpi_reply;
5028
5029 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5030 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
5031 return 1;
5032 if (ioc->scsih_cmds.smid != smid)
5033 return 1;
5034 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
5035 if (mpi_reply) {
5036 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5037 mpi_reply->MsgLength*4);
5038 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
5039 }
5040 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
5041 complete(&ioc->scsih_cmds.done);
5042 return 1;
5043}
5044
5045/**
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305046 * mpt2sas_expander_remove - removing expander object
Eric Moore635374e2009-03-09 01:21:12 -06005047 * @ioc: per adapter object
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305048 * @sas_address: expander sas_address
Eric Moore635374e2009-03-09 01:21:12 -06005049 *
5050 * Return nothing.
5051 */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305052void
5053mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06005054{
5055 struct _sas_node *sas_expander;
5056 unsigned long flags;
5057
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305058 if (ioc->shost_recovery)
5059 return;
5060
Eric Moore635374e2009-03-09 01:21:12 -06005061 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305062 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5063 sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305064 if (sas_expander)
5065 list_del(&sas_expander->list);
Eric Moore635374e2009-03-09 01:21:12 -06005066 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305067 if (sas_expander)
5068 _scsih_expander_node_remove(ioc, sas_expander);
Eric Moore635374e2009-03-09 01:21:12 -06005069}
5070
5071/**
Kashyap, Desaib4344272010-03-17 16:24:14 +05305072 * _scsih_check_access_status - check access flags
5073 * @ioc: per adapter object
5074 * @sas_address: sas address
5075 * @handle: sas device handle
5076 * @access_flags: errors returned during discovery of the device
5077 *
5078 * Return 0 for success, else failure
5079 */
5080static u8
5081_scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5082 u16 handle, u8 access_status)
5083{
5084 u8 rc = 1;
5085 char *desc = NULL;
5086
5087 switch (access_status) {
5088 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5089 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5090 rc = 0;
5091 break;
5092 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5093 desc = "sata capability failed";
5094 break;
5095 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5096 desc = "sata affiliation conflict";
5097 break;
5098 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5099 desc = "route not addressable";
5100 break;
5101 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5102 desc = "smp error not addressable";
5103 break;
5104 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5105 desc = "device blocked";
5106 break;
5107 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5108 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5109 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5110 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5111 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5112 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5113 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5114 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5115 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5116 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5117 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5118 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5119 desc = "sata initialization failed";
5120 break;
5121 default:
5122 desc = "unknown";
5123 break;
5124 }
5125
5126 if (!rc)
5127 return 0;
5128
5129 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5130 "handle(0x%04x)\n", ioc->name, desc,
5131 (unsigned long long)sas_address, handle);
5132 return rc;
5133}
5134
5135static void
5136_scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5137{
5138 Mpi2ConfigReply_t mpi_reply;
5139 Mpi2SasDevicePage0_t sas_device_pg0;
5140 struct _sas_device *sas_device;
5141 u32 ioc_status;
5142 unsigned long flags;
5143 u64 sas_address;
5144 struct scsi_target *starget;
5145 struct MPT2SAS_TARGET *sas_target_priv_data;
5146 u32 device_info;
5147
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305148
Kashyap, Desaib4344272010-03-17 16:24:14 +05305149 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5150 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5151 return;
5152
5153 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5154 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5155 return;
5156
5157 /* check if this is end device */
5158 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5159 if (!(_scsih_is_end_device(device_info)))
5160 return;
5161
5162 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5163 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5164 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5165 sas_address);
5166
5167 if (!sas_device) {
5168 printk(MPT2SAS_ERR_FMT "device is not present "
5169 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5170 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5171 return;
5172 }
5173
5174 if (unlikely(sas_device->handle != handle)) {
5175 starget = sas_device->starget;
5176 sas_target_priv_data = starget->hostdata;
5177 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5178 " to (0x%04x)!!!\n", sas_device->handle, handle);
5179 sas_target_priv_data->handle = handle;
5180 sas_device->handle = handle;
5181 }
Kashyap, Desaib4344272010-03-17 16:24:14 +05305182
5183 /* check if device is present */
5184 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5185 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5186 printk(MPT2SAS_ERR_FMT "device is not present "
5187 "handle(0x%04x), flags!!!\n", ioc->name, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305188 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305189 return;
5190 }
5191
5192 /* check if there were any issues with discovery */
5193 if (_scsih_check_access_status(ioc, sas_address, handle,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305194 sas_device_pg0.AccessStatus)) {
5195 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305196 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305197 }
5198 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05305199 _scsih_ublock_io_device(ioc, sas_address);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305200
5201}
5202
5203/**
Eric Moore635374e2009-03-09 01:21:12 -06005204 * _scsih_add_device - creating sas device object
5205 * @ioc: per adapter object
5206 * @handle: sas device handle
5207 * @phy_num: phy number end device attached to
5208 * @is_pd: is this hidden raid component
5209 *
5210 * Creating end device object, stored in ioc->sas_device_list.
5211 *
5212 * Returns 0 for success, non-zero for failure.
5213 */
5214static int
5215_scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5216{
5217 Mpi2ConfigReply_t mpi_reply;
5218 Mpi2SasDevicePage0_t sas_device_pg0;
5219 Mpi2SasEnclosurePage0_t enclosure_pg0;
5220 struct _sas_device *sas_device;
5221 u32 ioc_status;
5222 __le64 sas_address;
5223 u32 device_info;
5224 unsigned long flags;
5225
5226 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5227 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5228 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5229 ioc->name, __FILE__, __LINE__, __func__);
5230 return -1;
5231 }
5232
5233 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5234 MPI2_IOCSTATUS_MASK;
5235 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5236 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5237 ioc->name, __FILE__, __LINE__, __func__);
5238 return -1;
5239 }
5240
Kashyap, Desaib4344272010-03-17 16:24:14 +05305241 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5242
Eric Moore635374e2009-03-09 01:21:12 -06005243 /* check if device is present */
5244 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5245 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5246 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5247 ioc->name, __FILE__, __LINE__, __func__);
5248 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5249 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5250 return -1;
5251 }
5252
Kashyap, Desaib4344272010-03-17 16:24:14 +05305253 /* check if there were any issues with discovery */
5254 if (_scsih_check_access_status(ioc, sas_address, handle,
5255 sas_device_pg0.AccessStatus))
Eric Moore635374e2009-03-09 01:21:12 -06005256 return -1;
Eric Moore635374e2009-03-09 01:21:12 -06005257
5258 /* check if this is end device */
5259 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5260 if (!(_scsih_is_end_device(device_info))) {
5261 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5262 ioc->name, __FILE__, __LINE__, __func__);
5263 return -1;
5264 }
5265
Eric Moore635374e2009-03-09 01:21:12 -06005266
5267 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5268 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5269 sas_address);
5270 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5271
Kashyap, Desaib4344272010-03-17 16:24:14 +05305272 if (sas_device)
Eric Moore635374e2009-03-09 01:21:12 -06005273 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06005274
5275 sas_device = kzalloc(sizeof(struct _sas_device),
5276 GFP_KERNEL);
5277 if (!sas_device) {
5278 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5279 ioc->name, __FILE__, __LINE__, __func__);
5280 return -1;
5281 }
5282
5283 sas_device->handle = handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305284 if (_scsih_get_sas_address(ioc, le16_to_cpu
5285 (sas_device_pg0.ParentDevHandle),
5286 &sas_device->sas_address_parent) != 0)
5287 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5288 ioc->name, __FILE__, __LINE__, __func__);
Eric Moore635374e2009-03-09 01:21:12 -06005289 sas_device->enclosure_handle =
5290 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5291 sas_device->slot =
5292 le16_to_cpu(sas_device_pg0.Slot);
5293 sas_device->device_info = device_info;
5294 sas_device->sas_address = sas_address;
Kashyap, Desai7fbae672010-06-17 13:45:17 +05305295 sas_device->phy = sas_device_pg0.PhyNum;
Eric Moore635374e2009-03-09 01:21:12 -06005296
5297 /* get enclosure_logical_id */
Kashyap, Desai15052c92009-08-07 19:33:17 +05305298 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5299 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5300 sas_device->enclosure_handle)))
Eric Moore635374e2009-03-09 01:21:12 -06005301 sas_device->enclosure_logical_id =
5302 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
Eric Moore635374e2009-03-09 01:21:12 -06005303
5304 /* get device name */
5305 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5306
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305307 if (ioc->wait_for_discovery_to_complete)
Eric Moore635374e2009-03-09 01:21:12 -06005308 _scsih_sas_device_init_add(ioc, sas_device);
5309 else
5310 _scsih_sas_device_add(ioc, sas_device);
5311
5312 return 0;
5313}
5314
5315/**
Kashyap, Desai1278b112010-03-09 17:34:13 +05305316 * _scsih_remove_device - removing sas device object
5317 * @ioc: per adapter object
5318 * @sas_device_delete: the sas_device object
5319 *
5320 * Return nothing.
5321 */
5322static void
5323_scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5324 struct _sas_device *sas_device)
5325{
Kashyap, Desai1278b112010-03-09 17:34:13 +05305326 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05305327
Kashyap, Desai1278b112010-03-09 17:34:13 +05305328 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5329 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305330 sas_device->handle, (unsigned long long)
5331 sas_device->sas_address));
Kashyap, Desai1278b112010-03-09 17:34:13 +05305332
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305333 if (sas_device->starget && sas_device->starget->hostdata) {
5334 sas_target_priv_data = sas_device->starget->hostdata;
Kashyap, Desai1278b112010-03-09 17:34:13 +05305335 sas_target_priv_data->deleted = 1;
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05305336 _scsih_ublock_io_device(ioc, sas_device->sas_address);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305337 sas_target_priv_data->handle =
5338 MPT2SAS_INVALID_DEVICE_HANDLE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05305339 }
5340
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05305341 if (!ioc->hide_drives)
5342 mpt2sas_transport_port_remove(ioc,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305343 sas_device->sas_address,
5344 sas_device->sas_address_parent);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305345
5346 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305347 "(0x%016llx)\n", ioc->name, sas_device->handle,
5348 (unsigned long long) sas_device->sas_address);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305349
5350 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5351 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305352 sas_device->handle, (unsigned long long)
5353 sas_device->sas_address));
5354 kfree(sas_device);
5355}
5356/**
5357 * _scsih_device_remove_by_handle - removing device object by handle
5358 * @ioc: per adapter object
5359 * @handle: device handle
5360 *
5361 * Return nothing.
5362 */
5363static void
5364_scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5365{
5366 struct _sas_device *sas_device;
5367 unsigned long flags;
5368
5369 if (ioc->shost_recovery)
5370 return;
5371
5372 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5373 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5374 if (sas_device)
5375 list_del(&sas_device->list);
5376 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5377 if (sas_device)
5378 _scsih_remove_device(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -06005379}
5380
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305381/**
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305382 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305383 * @ioc: per adapter object
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305384 * @sas_address: device sas_address
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305385 *
5386 * Return nothing.
5387 */
5388void
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305389mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
5390 u64 sas_address)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305391{
5392 struct _sas_device *sas_device;
5393 unsigned long flags;
5394
5395 if (ioc->shost_recovery)
5396 return;
5397
5398 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5399 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5400 sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305401 if (sas_device)
5402 list_del(&sas_device->list);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305403 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305404 if (sas_device)
5405 _scsih_remove_device(ioc, sas_device);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305406}
Eric Moore635374e2009-03-09 01:21:12 -06005407#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5408/**
5409 * _scsih_sas_topology_change_event_debug - debug for topology event
5410 * @ioc: per adapter object
5411 * @event_data: event data payload
5412 * Context: user.
5413 */
5414static void
5415_scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5416 Mpi2EventDataSasTopologyChangeList_t *event_data)
5417{
5418 int i;
5419 u16 handle;
5420 u16 reason_code;
5421 u8 phy_number;
5422 char *status_str = NULL;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305423 u8 link_rate, prev_link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06005424
5425 switch (event_data->ExpStatus) {
5426 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5427 status_str = "add";
5428 break;
5429 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5430 status_str = "remove";
5431 break;
5432 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305433 case 0:
Eric Moore635374e2009-03-09 01:21:12 -06005434 status_str = "responding";
5435 break;
5436 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5437 status_str = "remove delay";
5438 break;
5439 default:
5440 status_str = "unknown status";
5441 break;
5442 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305443 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
Eric Moore635374e2009-03-09 01:21:12 -06005444 ioc->name, status_str);
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305445 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
Eric Moore635374e2009-03-09 01:21:12 -06005446 "start_phy(%02d), count(%d)\n",
5447 le16_to_cpu(event_data->ExpanderDevHandle),
5448 le16_to_cpu(event_data->EnclosureHandle),
5449 event_data->StartPhyNum, event_data->NumEntries);
5450 for (i = 0; i < event_data->NumEntries; i++) {
5451 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5452 if (!handle)
5453 continue;
5454 phy_number = event_data->StartPhyNum + i;
5455 reason_code = event_data->PHY[i].PhyStatus &
5456 MPI2_EVENT_SAS_TOPO_RC_MASK;
5457 switch (reason_code) {
5458 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305459 status_str = "target add";
Eric Moore635374e2009-03-09 01:21:12 -06005460 break;
5461 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305462 status_str = "target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005463 break;
5464 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305465 status_str = "delay target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005466 break;
5467 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305468 status_str = "link rate change";
Eric Moore635374e2009-03-09 01:21:12 -06005469 break;
5470 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305471 status_str = "target responding";
Eric Moore635374e2009-03-09 01:21:12 -06005472 break;
5473 default:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305474 status_str = "unknown";
Eric Moore635374e2009-03-09 01:21:12 -06005475 break;
5476 }
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305477 link_rate = event_data->PHY[i].LinkRate >> 4;
5478 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305479 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305480 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5481 handle, status_str, link_rate, prev_link_rate);
5482
Eric Moore635374e2009-03-09 01:21:12 -06005483 }
5484}
5485#endif
5486
5487/**
5488 * _scsih_sas_topology_change_event - handle topology changes
5489 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305490 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005491 * Context: user.
5492 *
5493 */
5494static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305495_scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
Eric Moore635374e2009-03-09 01:21:12 -06005496 struct fw_event_work *fw_event)
5497{
5498 int i;
5499 u16 parent_handle, handle;
5500 u16 reason_code;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305501 u8 phy_number, max_phys;
Eric Moore635374e2009-03-09 01:21:12 -06005502 struct _sas_node *sas_expander;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305503 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06005504 unsigned long flags;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305505 u8 link_rate, prev_link_rate;
Joe Lawrence00713ad2014-06-25 17:03:33 -04005506 Mpi2EventDataSasTopologyChangeList_t *event_data =
5507 (Mpi2EventDataSasTopologyChangeList_t *)
5508 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06005509
5510#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5511 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5512 _scsih_sas_topology_change_event_debug(ioc, event_data);
5513#endif
5514
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305515 if (ioc->remove_host || ioc->pci_error_recovery)
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305516 return;
5517
Eric Moore635374e2009-03-09 01:21:12 -06005518 if (!ioc->sas_hba.num_phys)
5519 _scsih_sas_host_add(ioc);
5520 else
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305521 _scsih_sas_host_refresh(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005522
5523 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305524 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
Eric Moore635374e2009-03-09 01:21:12 -06005525 "event\n", ioc->name));
5526 return;
5527 }
5528
5529 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5530
5531 /* handle expander add */
5532 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5533 if (_scsih_expander_add(ioc, parent_handle) != 0)
5534 return;
5535
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305536 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5537 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5538 parent_handle);
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305539 if (sas_expander) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305540 sas_address = sas_expander->sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305541 max_phys = sas_expander->num_phys;
5542 } else if (parent_handle < ioc->sas_hba.num_phys) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305543 sas_address = ioc->sas_hba.sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305544 max_phys = ioc->sas_hba.num_phys;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305545 } else {
5546 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305547 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305548 }
5549 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305550
Eric Moore635374e2009-03-09 01:21:12 -06005551 /* handle siblings events */
5552 for (i = 0; i < event_data->NumEntries; i++) {
5553 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305554 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
Eric Moore635374e2009-03-09 01:21:12 -06005555 "expander event\n", ioc->name));
5556 return;
5557 }
Eric Moore3cb54692010-07-08 14:44:34 -06005558 if (ioc->shost_recovery || ioc->remove_host ||
5559 ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305560 return;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305561 phy_number = event_data->StartPhyNum + i;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305562 if (phy_number >= max_phys)
5563 continue;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305564 reason_code = event_data->PHY[i].PhyStatus &
5565 MPI2_EVENT_SAS_TOPO_RC_MASK;
5566 if ((event_data->PHY[i].PhyStatus &
5567 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5568 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
Eric Moore635374e2009-03-09 01:21:12 -06005569 continue;
5570 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5571 if (!handle)
5572 continue;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305573 link_rate = event_data->PHY[i].LinkRate >> 4;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305574 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Eric Moore635374e2009-03-09 01:21:12 -06005575 switch (reason_code) {
5576 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305577
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305578 if (ioc->shost_recovery)
5579 break;
5580
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305581 if (link_rate == prev_link_rate)
5582 break;
5583
5584 mpt2sas_transport_update_links(ioc, sas_address,
5585 handle, phy_number, link_rate);
5586
Kashyap, Desaib4344272010-03-17 16:24:14 +05305587 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5588 break;
5589
5590 _scsih_check_device(ioc, handle);
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305591 break;
Eric Moore635374e2009-03-09 01:21:12 -06005592 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305593
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305594 if (ioc->shost_recovery)
5595 break;
5596
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305597 mpt2sas_transport_update_links(ioc, sas_address,
5598 handle, phy_number, link_rate);
5599
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305600 _scsih_add_device(ioc, handle, phy_number, 0);
Eric Moore635374e2009-03-09 01:21:12 -06005601 break;
5602 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305603
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305604 _scsih_device_remove_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06005605 break;
5606 }
5607 }
5608
5609 /* handle expander removal */
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305610 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5611 sas_expander)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305612 mpt2sas_expander_remove(ioc, sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06005613
5614}
5615
5616#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5617/**
5618 * _scsih_sas_device_status_change_event_debug - debug for device event
5619 * @event_data: event data payload
5620 * Context: user.
5621 *
5622 * Return nothing.
5623 */
5624static void
5625_scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5626 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5627{
5628 char *reason_str = NULL;
5629
5630 switch (event_data->ReasonCode) {
5631 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5632 reason_str = "smart data";
5633 break;
5634 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5635 reason_str = "unsupported device discovered";
5636 break;
5637 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5638 reason_str = "internal device reset";
5639 break;
5640 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5641 reason_str = "internal task abort";
5642 break;
5643 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5644 reason_str = "internal task abort set";
5645 break;
5646 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5647 reason_str = "internal clear task set";
5648 break;
5649 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5650 reason_str = "internal query task";
5651 break;
5652 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5653 reason_str = "sata init failure";
5654 break;
5655 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5656 reason_str = "internal device reset complete";
5657 break;
5658 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5659 reason_str = "internal task abort complete";
5660 break;
5661 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5662 reason_str = "internal async notification";
5663 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05305664 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5665 reason_str = "expander reduced functionality";
5666 break;
5667 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5668 reason_str = "expander reduced functionality complete";
5669 break;
Eric Moore635374e2009-03-09 01:21:12 -06005670 default:
5671 reason_str = "unknown reason";
5672 break;
5673 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305674 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305675 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5676 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5677 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5678 le16_to_cpu(event_data->TaskTag));
Eric Moore635374e2009-03-09 01:21:12 -06005679 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305680 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005681 event_data->ASC, event_data->ASCQ);
5682 printk(KERN_INFO "\n");
5683}
5684#endif
5685
5686/**
5687 * _scsih_sas_device_status_change_event - handle device status change
5688 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305689 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005690 * Context: user.
5691 *
5692 * Return nothing.
5693 */
5694static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305695_scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5696 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005697{
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305698 struct MPT2SAS_TARGET *target_priv_data;
5699 struct _sas_device *sas_device;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05305700 u64 sas_address;
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305701 unsigned long flags;
5702 Mpi2EventDataSasDeviceStatusChange_t *event_data =
Joe Lawrence00713ad2014-06-25 17:03:33 -04005703 (Mpi2EventDataSasDeviceStatusChange_t *)
5704 fw_event->event_data;
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305705
Eric Moore635374e2009-03-09 01:21:12 -06005706#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5707 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305708 _scsih_sas_device_status_change_event_debug(ioc,
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305709 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005710#endif
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305711
Kashyap, Desaiefe82a12011-01-04 11:34:17 +05305712 /* In MPI Revision K (0xC), the internal device reset complete was
5713 * implemented, so avoid setting tm_busy flag for older firmware.
5714 */
5715 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5716 return;
5717
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305718 if (event_data->ReasonCode !=
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305719 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305720 event_data->ReasonCode !=
5721 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305722 return;
5723
5724 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5725 sas_address = le64_to_cpu(event_data->SASAddress);
5726 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5727 sas_address);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305728
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305729 if (!sas_device || !sas_device->starget) {
5730 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305731 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305732 }
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305733
5734 target_priv_data = sas_device->starget->hostdata;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305735 if (!target_priv_data) {
5736 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305737 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305738 }
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305739
5740 if (event_data->ReasonCode ==
5741 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5742 target_priv_data->tm_busy = 1;
5743 else
5744 target_priv_data->tm_busy = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305745 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005746}
5747
5748#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5749/**
5750 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5751 * @ioc: per adapter object
5752 * @event_data: event data payload
5753 * Context: user.
5754 *
5755 * Return nothing.
5756 */
5757static void
5758_scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5759 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5760{
5761 char *reason_str = NULL;
5762
5763 switch (event_data->ReasonCode) {
5764 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5765 reason_str = "enclosure add";
5766 break;
5767 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5768 reason_str = "enclosure remove";
5769 break;
5770 default:
5771 reason_str = "unknown reason";
5772 break;
5773 }
5774
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305775 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
Eric Moore635374e2009-03-09 01:21:12 -06005776 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5777 " number slots(%d)\n", ioc->name, reason_str,
5778 le16_to_cpu(event_data->EnclosureHandle),
5779 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5780 le16_to_cpu(event_data->StartSlot));
5781}
5782#endif
5783
5784/**
5785 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5786 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305787 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005788 * Context: user.
5789 *
5790 * Return nothing.
5791 */
5792static void
5793_scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305794 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005795{
5796#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5797 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5798 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
Joe Lawrence00713ad2014-06-25 17:03:33 -04005799 (Mpi2EventDataSasEnclDevStatusChange_t *)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305800 fw_event->event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005801#endif
5802}
5803
5804/**
Andrew Mortona78e21d2012-02-08 12:52:22 -08005805 * _scsih_sas_broadcast_primitive_event - handle broadcast events
Eric Moore635374e2009-03-09 01:21:12 -06005806 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305807 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005808 * Context: user.
5809 *
5810 * Return nothing.
5811 */
5812static void
Andrew Mortona78e21d2012-02-08 12:52:22 -08005813_scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305814 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005815{
5816 struct scsi_cmnd *scmd;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305817 struct scsi_device *sdev;
Eric Moore635374e2009-03-09 01:21:12 -06005818 u16 smid, handle;
5819 u32 lun;
5820 struct MPT2SAS_DEVICE *sas_device_priv_data;
5821 u32 termination_count;
5822 u32 query_count;
5823 Mpi2SCSITaskManagementReply_t *mpi_reply;
Joe Lawrence00713ad2014-06-25 17:03:33 -04005824 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5825 (Mpi2EventDataSasBroadcastPrimitive_t *)
5826 fw_event->event_data;
Kashyap, Desai463217b2009-10-05 15:53:06 +05305827 u16 ioc_status;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305828 unsigned long flags;
5829 int r;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305830 u8 max_retries = 0;
5831 u8 task_abort_retries;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305832
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305833 mutex_lock(&ioc->tm_cmds.mutex);
Reddy, Sreekanthc3a634b2013-02-26 17:36:12 +05305834 pr_info(MPT2SAS_FMT
5835 "%s: enter: phy number(%d), width(%d)\n",
5836 ioc->name, __func__, event_data->PhyNum,
5837 event_data->PortWidth);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305838
5839 _scsih_block_io_all_device(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005840
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305841 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305842 mpi_reply = ioc->tm_cmds.reply;
5843broadcast_aen_retry:
5844
5845 /* sanity checks for retrying this loop */
5846 if (max_retries++ == 5) {
5847 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5848 ioc->name, __func__));
5849 goto out;
5850 } else if (max_retries > 1)
5851 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5852 ioc->name, __func__, max_retries - 1));
5853
Eric Moore635374e2009-03-09 01:21:12 -06005854 termination_count = 0;
5855 query_count = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305856 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305857 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305858 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06005859 scmd = _scsih_scsi_lookup_get(ioc, smid);
5860 if (!scmd)
5861 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305862 sdev = scmd->device;
5863 sas_device_priv_data = sdev->hostdata;
Eric Moore635374e2009-03-09 01:21:12 -06005864 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5865 continue;
5866 /* skip hidden raid components */
5867 if (sas_device_priv_data->sas_target->flags &
5868 MPT_TARGET_FLAGS_RAID_COMPONENT)
5869 continue;
5870 /* skip volumes */
5871 if (sas_device_priv_data->sas_target->flags &
5872 MPT_TARGET_FLAGS_VOLUME)
5873 continue;
5874
5875 handle = sas_device_priv_data->sas_target->handle;
5876 lun = sas_device_priv_data->lun;
5877 query_count++;
5878
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305879 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305880 goto out;
5881
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305882 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305883 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04005884 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305885 TM_MUTEX_OFF);
5886 if (r == FAILED) {
5887 sdev_printk(KERN_WARNING, sdev,
5888 "mpt2sas_scsih_issue_tm: FAILED when sending "
5889 "QUERY_TASK: scmd(%p)\n", scmd);
5890 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5891 goto broadcast_aen_retry;
5892 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05305893 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5894 & MPI2_IOCSTATUS_MASK;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305895 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5896 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5897 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5898 scmd);
5899 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5900 goto broadcast_aen_retry;
5901 }
5902
5903 /* see if IO is still owned by IOC and target */
5904 if (mpi_reply->ResponseCode ==
Eric Moore635374e2009-03-09 01:21:12 -06005905 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5906 mpi_reply->ResponseCode ==
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305907 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305908 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005909 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305910 }
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305911 task_abort_retries = 0;
5912 tm_retry:
5913 if (task_abort_retries++ == 60) {
5914 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5915 "%s: ABORT_TASK: giving up\n", ioc->name,
5916 __func__));
5917 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5918 goto broadcast_aen_retry;
5919 }
5920
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305921 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305922 goto out_no_lock;
5923
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305924 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5925 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
Matthew Wilcox2e45c8b2014-03-27 16:40:32 -04005926 TM_MUTEX_OFF);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305927 if (r == FAILED) {
5928 sdev_printk(KERN_WARNING, sdev,
5929 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305930 "scmd(%p)\n", scmd);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305931 goto tm_retry;
5932 }
5933
5934 if (task_abort_retries > 1)
5935 sdev_printk(KERN_WARNING, sdev,
5936 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5937 " scmd(%p)\n",
5938 task_abort_retries - 1, scmd);
5939
Eric Moore635374e2009-03-09 01:21:12 -06005940 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305941 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005942 }
Eric Moore635374e2009-03-09 01:21:12 -06005943
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305944 if (ioc->broadcast_aen_pending) {
5945 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5946 " pending AEN\n", ioc->name, __func__));
5947 ioc->broadcast_aen_pending = 0;
5948 goto broadcast_aen_retry;
5949 }
5950
5951 out:
5952 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5953 out_no_lock:
5954
5955 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06005956 "%s - exit, query_count = %d termination_count = %d\n",
5957 ioc->name, __func__, query_count, termination_count));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305958
5959 ioc->broadcast_aen_busy = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305960 if (!ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305961 _scsih_ublock_io_all_device(ioc);
5962 mutex_unlock(&ioc->tm_cmds.mutex);
Eric Moore635374e2009-03-09 01:21:12 -06005963}
5964
5965/**
5966 * _scsih_sas_discovery_event - handle discovery events
5967 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305968 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005969 * Context: user.
5970 *
5971 * Return nothing.
5972 */
5973static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305974_scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5975 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005976{
Joe Lawrence00713ad2014-06-25 17:03:33 -04005977 Mpi2EventDataSasDiscovery_t *event_data =
5978 (Mpi2EventDataSasDiscovery_t *)
5979 fw_event->event_data;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305980
Eric Moore635374e2009-03-09 01:21:12 -06005981#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5982 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305983 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005984 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5985 "start" : "stop");
5986 if (event_data->DiscoveryStatus)
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305987 printk("discovery_status(0x%08x)",
5988 le32_to_cpu(event_data->DiscoveryStatus));
Eric Moore635374e2009-03-09 01:21:12 -06005989 printk("\n");
5990 }
5991#endif
5992
5993 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05305994 !ioc->sas_hba.num_phys) {
5995 if (disable_discovery > 0 && ioc->shost_recovery) {
5996 /* Wait for the reset to complete */
5997 while (ioc->shost_recovery)
5998 ssleep(1);
5999 }
Eric Moore635374e2009-03-09 01:21:12 -06006000 _scsih_sas_host_add(ioc);
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05306001 }
Eric Moore635374e2009-03-09 01:21:12 -06006002}
6003
6004/**
6005 * _scsih_reprobe_lun - reprobing lun
6006 * @sdev: scsi device struct
6007 * @no_uld_attach: sdev->no_uld_attach flag setting
6008 *
6009 **/
6010static void
6011_scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
6012{
6013 int rc;
6014
6015 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6016 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6017 sdev->no_uld_attach ? "hidding" : "exposing");
6018 rc = scsi_device_reprobe(sdev);
6019}
6020
6021/**
Eric Moore635374e2009-03-09 01:21:12 -06006022 * _scsih_sas_volume_add - add new volume
6023 * @ioc: per adapter object
6024 * @element: IR config element data
6025 * Context: user.
6026 *
6027 * Return nothing.
6028 */
6029static void
6030_scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
6031 Mpi2EventIrConfigElement_t *element)
6032{
6033 struct _raid_device *raid_device;
6034 unsigned long flags;
6035 u64 wwid;
6036 u16 handle = le16_to_cpu(element->VolDevHandle);
6037 int rc;
6038
Eric Moore635374e2009-03-09 01:21:12 -06006039 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6040 if (!wwid) {
6041 printk(MPT2SAS_ERR_FMT
6042 "failure at %s:%d/%s()!\n", ioc->name,
6043 __FILE__, __LINE__, __func__);
6044 return;
6045 }
6046
6047 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6048 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6049 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6050
6051 if (raid_device)
6052 return;
6053
6054 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6055 if (!raid_device) {
6056 printk(MPT2SAS_ERR_FMT
6057 "failure at %s:%d/%s()!\n", ioc->name,
6058 __FILE__, __LINE__, __func__);
6059 return;
6060 }
6061
6062 raid_device->id = ioc->sas_id++;
6063 raid_device->channel = RAID_CHANNEL;
6064 raid_device->handle = handle;
6065 raid_device->wwid = wwid;
6066 _scsih_raid_device_add(ioc, raid_device);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306067 if (!ioc->wait_for_discovery_to_complete) {
Eric Moore635374e2009-03-09 01:21:12 -06006068 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6069 raid_device->id, 0);
6070 if (rc)
6071 _scsih_raid_device_remove(ioc, raid_device);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306072 } else {
6073 spin_lock_irqsave(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06006074 _scsih_determine_boot_device(ioc, raid_device, 1);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306075 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6076 }
Eric Moore635374e2009-03-09 01:21:12 -06006077}
6078
6079/**
6080 * _scsih_sas_volume_delete - delete volume
6081 * @ioc: per adapter object
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306082 * @handle: volume device handle
Eric Moore635374e2009-03-09 01:21:12 -06006083 * Context: user.
6084 *
6085 * Return nothing.
6086 */
6087static void
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306088_scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Eric Moore635374e2009-03-09 01:21:12 -06006089{
6090 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06006091 unsigned long flags;
6092 struct MPT2SAS_TARGET *sas_target_priv_data;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306093 struct scsi_target *starget = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006094
Eric Moore635374e2009-03-09 01:21:12 -06006095 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6096 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306097 if (raid_device) {
6098 if (raid_device->starget) {
6099 starget = raid_device->starget;
6100 sas_target_priv_data = starget->hostdata;
6101 sas_target_priv_data->deleted = 1;
6102 }
6103 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6104 "(0x%016llx)\n", ioc->name, raid_device->handle,
6105 (unsigned long long) raid_device->wwid);
6106 list_del(&raid_device->list);
6107 kfree(raid_device);
Eric Moore635374e2009-03-09 01:21:12 -06006108 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306109 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6110 if (starget)
6111 scsi_remove_target(&starget->dev);
Eric Moore635374e2009-03-09 01:21:12 -06006112}
6113
6114/**
6115 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6116 * @ioc: per adapter object
6117 * @element: IR config element data
6118 * Context: user.
6119 *
6120 * Return nothing.
6121 */
6122static void
6123_scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6124 Mpi2EventIrConfigElement_t *element)
6125{
6126 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306127 struct scsi_target *starget = NULL;
6128 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06006129 unsigned long flags;
6130 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6131
6132 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6133 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306134 if (sas_device) {
6135 sas_device->volume_handle = 0;
6136 sas_device->volume_wwid = 0;
6137 clear_bit(handle, ioc->pd_handles);
6138 if (sas_device->starget && sas_device->starget->hostdata) {
6139 starget = sas_device->starget;
6140 sas_target_priv_data = starget->hostdata;
6141 sas_target_priv_data->flags &=
6142 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6143 }
6144 }
Eric Moore635374e2009-03-09 01:21:12 -06006145 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6146 if (!sas_device)
6147 return;
6148
6149 /* exposing raid component */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306150 if (starget)
6151 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
Eric Moore635374e2009-03-09 01:21:12 -06006152}
6153
6154/**
6155 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6156 * @ioc: per adapter object
6157 * @element: IR config element data
6158 * Context: user.
6159 *
6160 * Return nothing.
6161 */
6162static void
6163_scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6164 Mpi2EventIrConfigElement_t *element)
6165{
6166 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306167 struct scsi_target *starget = NULL;
6168 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06006169 unsigned long flags;
6170 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306171 u16 volume_handle = 0;
6172 u64 volume_wwid = 0;
6173
6174 mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle);
6175 if (volume_handle)
6176 mpt2sas_config_get_volume_wwid(ioc, volume_handle,
6177 &volume_wwid);
Eric Moore635374e2009-03-09 01:21:12 -06006178
6179 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6180 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306181 if (sas_device) {
6182 set_bit(handle, ioc->pd_handles);
6183 if (sas_device->starget && sas_device->starget->hostdata) {
6184 starget = sas_device->starget;
6185 sas_target_priv_data = starget->hostdata;
6186 sas_target_priv_data->flags |=
6187 MPT_TARGET_FLAGS_RAID_COMPONENT;
6188 sas_device->volume_handle = volume_handle;
6189 sas_device->volume_wwid = volume_wwid;
6190 }
6191 }
Eric Moore635374e2009-03-09 01:21:12 -06006192 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6193 if (!sas_device)
6194 return;
6195
6196 /* hiding raid component */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306197 if (starget)
6198 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
Eric Moore635374e2009-03-09 01:21:12 -06006199}
6200
6201/**
6202 * _scsih_sas_pd_delete - delete pd component
6203 * @ioc: per adapter object
6204 * @element: IR config element data
6205 * Context: user.
6206 *
6207 * Return nothing.
6208 */
6209static void
6210_scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6211 Mpi2EventIrConfigElement_t *element)
6212{
Eric Moore635374e2009-03-09 01:21:12 -06006213 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6214
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306215 _scsih_device_remove_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006216}
6217
6218/**
6219 * _scsih_sas_pd_add - remove pd component
6220 * @ioc: per adapter object
6221 * @element: IR config element data
6222 * Context: user.
6223 *
6224 * Return nothing.
6225 */
6226static void
6227_scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6228 Mpi2EventIrConfigElement_t *element)
6229{
6230 struct _sas_device *sas_device;
6231 unsigned long flags;
6232 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306233 Mpi2ConfigReply_t mpi_reply;
6234 Mpi2SasDevicePage0_t sas_device_pg0;
6235 u32 ioc_status;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306236 u64 sas_address;
6237 u16 parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006238
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306239 set_bit(handle, ioc->pd_handles);
6240
Eric Moore635374e2009-03-09 01:21:12 -06006241 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6242 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6243 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306244 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306245 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306246
6247 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6248 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6249 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6250 ioc->name, __FILE__, __LINE__, __func__);
6251 return;
6252 }
6253
6254 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6255 MPI2_IOCSTATUS_MASK;
6256 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6257 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6258 ioc->name, __FILE__, __LINE__, __func__);
6259 return;
6260 }
6261
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306262 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6263 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6264 mpt2sas_transport_update_links(ioc, sas_address, handle,
6265 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306266
6267 _scsih_add_device(ioc, handle, 0, 1);
Eric Moore635374e2009-03-09 01:21:12 -06006268}
6269
6270#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6271/**
6272 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6273 * @ioc: per adapter object
6274 * @event_data: event data payload
6275 * Context: user.
6276 *
6277 * Return nothing.
6278 */
6279static void
6280_scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6281 Mpi2EventDataIrConfigChangeList_t *event_data)
6282{
6283 Mpi2EventIrConfigElement_t *element;
6284 u8 element_type;
6285 int i;
6286 char *reason_str = NULL, *element_str = NULL;
6287
6288 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6289
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306290 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
Eric Moore635374e2009-03-09 01:21:12 -06006291 ioc->name, (le32_to_cpu(event_data->Flags) &
6292 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6293 "foreign" : "native", event_data->NumElements);
6294 for (i = 0; i < event_data->NumElements; i++, element++) {
6295 switch (element->ReasonCode) {
6296 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6297 reason_str = "add";
6298 break;
6299 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6300 reason_str = "remove";
6301 break;
6302 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6303 reason_str = "no change";
6304 break;
6305 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6306 reason_str = "hide";
6307 break;
6308 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6309 reason_str = "unhide";
6310 break;
6311 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6312 reason_str = "volume_created";
6313 break;
6314 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6315 reason_str = "volume_deleted";
6316 break;
6317 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6318 reason_str = "pd_created";
6319 break;
6320 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6321 reason_str = "pd_deleted";
6322 break;
6323 default:
6324 reason_str = "unknown reason";
6325 break;
6326 }
6327 element_type = le16_to_cpu(element->ElementFlags) &
6328 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6329 switch (element_type) {
6330 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6331 element_str = "volume";
6332 break;
6333 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6334 element_str = "phys disk";
6335 break;
6336 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6337 element_str = "hot spare";
6338 break;
6339 default:
6340 element_str = "unknown element";
6341 break;
6342 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306343 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
Eric Moore635374e2009-03-09 01:21:12 -06006344 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6345 reason_str, le16_to_cpu(element->VolDevHandle),
6346 le16_to_cpu(element->PhysDiskDevHandle),
6347 element->PhysDiskNum);
6348 }
6349}
6350#endif
6351
6352/**
6353 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6354 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306355 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006356 * Context: user.
6357 *
6358 * Return nothing.
6359 */
6360static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306361_scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6362 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006363{
6364 Mpi2EventIrConfigElement_t *element;
6365 int i;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306366 u8 foreign_config;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006367 Mpi2EventDataIrConfigChangeList_t *event_data =
6368 (Mpi2EventDataIrConfigChangeList_t *)
6369 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006370
6371#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306372 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6373 && !ioc->hide_ir_msg)
Eric Moore635374e2009-03-09 01:21:12 -06006374 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6375
6376#endif
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306377
6378 if (ioc->shost_recovery)
6379 return;
6380
Kashyap, Desai62727a72009-08-07 19:35:18 +05306381 foreign_config = (le32_to_cpu(event_data->Flags) &
6382 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
Eric Moore635374e2009-03-09 01:21:12 -06006383
6384 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6385 for (i = 0; i < event_data->NumElements; i++, element++) {
6386
6387 switch (element->ReasonCode) {
6388 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6389 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306390 if (!foreign_config)
6391 _scsih_sas_volume_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006392 break;
6393 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6394 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306395 if (!foreign_config)
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306396 _scsih_sas_volume_delete(ioc,
6397 le16_to_cpu(element->VolDevHandle));
Eric Moore635374e2009-03-09 01:21:12 -06006398 break;
6399 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306400 if (!ioc->is_warpdrive)
6401 _scsih_sas_pd_hide(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006402 break;
6403 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306404 if (!ioc->is_warpdrive)
6405 _scsih_sas_pd_expose(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006406 break;
6407 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306408 if (!ioc->is_warpdrive)
6409 _scsih_sas_pd_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006410 break;
6411 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306412 if (!ioc->is_warpdrive)
6413 _scsih_sas_pd_delete(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006414 break;
6415 }
6416 }
6417}
6418
6419/**
6420 * _scsih_sas_ir_volume_event - IR volume event
6421 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306422 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006423 * Context: user.
6424 *
6425 * Return nothing.
6426 */
6427static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306428_scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6429 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006430{
6431 u64 wwid;
6432 unsigned long flags;
6433 struct _raid_device *raid_device;
6434 u16 handle;
6435 u32 state;
6436 int rc;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006437 Mpi2EventDataIrVolume_t *event_data =
6438 (Mpi2EventDataIrVolume_t *)
6439 fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006440
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306441 if (ioc->shost_recovery)
6442 return;
6443
Eric Moore635374e2009-03-09 01:21:12 -06006444 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6445 return;
6446
6447 handle = le16_to_cpu(event_data->VolDevHandle);
6448 state = le32_to_cpu(event_data->NewValue);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306449 if (!ioc->hide_ir_msg)
6450 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6451 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6452 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006453
Eric Moore635374e2009-03-09 01:21:12 -06006454 switch (state) {
6455 case MPI2_RAID_VOL_STATE_MISSING:
6456 case MPI2_RAID_VOL_STATE_FAILED:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306457 _scsih_sas_volume_delete(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006458 break;
6459
6460 case MPI2_RAID_VOL_STATE_ONLINE:
6461 case MPI2_RAID_VOL_STATE_DEGRADED:
6462 case MPI2_RAID_VOL_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306463
6464 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6465 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6466 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6467
Eric Moore635374e2009-03-09 01:21:12 -06006468 if (raid_device)
6469 break;
6470
6471 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6472 if (!wwid) {
6473 printk(MPT2SAS_ERR_FMT
6474 "failure at %s:%d/%s()!\n", ioc->name,
6475 __FILE__, __LINE__, __func__);
6476 break;
6477 }
6478
6479 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6480 if (!raid_device) {
6481 printk(MPT2SAS_ERR_FMT
6482 "failure at %s:%d/%s()!\n", ioc->name,
6483 __FILE__, __LINE__, __func__);
6484 break;
6485 }
6486
6487 raid_device->id = ioc->sas_id++;
6488 raid_device->channel = RAID_CHANNEL;
6489 raid_device->handle = handle;
6490 raid_device->wwid = wwid;
6491 _scsih_raid_device_add(ioc, raid_device);
6492 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6493 raid_device->id, 0);
6494 if (rc)
6495 _scsih_raid_device_remove(ioc, raid_device);
6496 break;
6497
6498 case MPI2_RAID_VOL_STATE_INITIALIZING:
6499 default:
6500 break;
6501 }
6502}
6503
6504/**
6505 * _scsih_sas_ir_physical_disk_event - PD event
6506 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306507 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006508 * Context: user.
6509 *
6510 * Return nothing.
6511 */
6512static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306513_scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6514 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006515{
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306516 u16 handle, parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006517 u32 state;
6518 struct _sas_device *sas_device;
6519 unsigned long flags;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306520 Mpi2ConfigReply_t mpi_reply;
6521 Mpi2SasDevicePage0_t sas_device_pg0;
6522 u32 ioc_status;
Joe Lawrence00713ad2014-06-25 17:03:33 -04006523 Mpi2EventDataIrPhysicalDisk_t *event_data =
6524 (Mpi2EventDataIrPhysicalDisk_t *)
6525 fw_event->event_data;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306526 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006527
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306528 if (ioc->shost_recovery)
6529 return;
6530
Eric Moore635374e2009-03-09 01:21:12 -06006531 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6532 return;
6533
6534 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6535 state = le32_to_cpu(event_data->NewValue);
6536
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306537 if (!ioc->hide_ir_msg)
6538 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6539 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6540 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006541
Eric Moore635374e2009-03-09 01:21:12 -06006542 switch (state) {
Eric Moore635374e2009-03-09 01:21:12 -06006543 case MPI2_RAID_PD_STATE_ONLINE:
6544 case MPI2_RAID_PD_STATE_DEGRADED:
6545 case MPI2_RAID_PD_STATE_REBUILDING:
6546 case MPI2_RAID_PD_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306547 case MPI2_RAID_PD_STATE_HOT_SPARE:
6548
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306549 if (!ioc->is_warpdrive)
6550 set_bit(handle, ioc->pd_handles);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306551
6552 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6553 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6554 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6555
6556 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306557 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306558
6559 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6560 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6561 handle))) {
6562 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6563 ioc->name, __FILE__, __LINE__, __func__);
6564 return;
6565 }
6566
6567 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6568 MPI2_IOCSTATUS_MASK;
6569 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6570 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6571 ioc->name, __FILE__, __LINE__, __func__);
6572 return;
6573 }
6574
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306575 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6576 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6577 mpt2sas_transport_update_links(ioc, sas_address, handle,
6578 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306579
6580 _scsih_add_device(ioc, handle, 0, 1);
6581
Eric Moore635374e2009-03-09 01:21:12 -06006582 break;
6583
Kashyap, Desai62727a72009-08-07 19:35:18 +05306584 case MPI2_RAID_PD_STATE_OFFLINE:
Eric Moore635374e2009-03-09 01:21:12 -06006585 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6586 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
Eric Moore635374e2009-03-09 01:21:12 -06006587 default:
6588 break;
6589 }
6590}
6591
6592#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6593/**
6594 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6595 * @ioc: per adapter object
6596 * @event_data: event data payload
6597 * Context: user.
6598 *
6599 * Return nothing.
6600 */
6601static void
6602_scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6603 Mpi2EventDataIrOperationStatus_t *event_data)
6604{
6605 char *reason_str = NULL;
6606
6607 switch (event_data->RAIDOperation) {
6608 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6609 reason_str = "resync";
6610 break;
6611 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6612 reason_str = "online capacity expansion";
6613 break;
6614 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6615 reason_str = "consistency check";
6616 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306617 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6618 reason_str = "background init";
6619 break;
6620 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6621 reason_str = "make data consistent";
Eric Moore635374e2009-03-09 01:21:12 -06006622 break;
6623 }
6624
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306625 if (!reason_str)
6626 return;
6627
Eric Moore635374e2009-03-09 01:21:12 -06006628 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6629 "\thandle(0x%04x), percent complete(%d)\n",
6630 ioc->name, reason_str,
6631 le16_to_cpu(event_data->VolDevHandle),
6632 event_data->PercentComplete);
6633}
6634#endif
6635
6636/**
6637 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6638 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306639 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006640 * Context: user.
6641 *
6642 * Return nothing.
6643 */
6644static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306645_scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6646 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006647{
Joe Lawrence00713ad2014-06-25 17:03:33 -04006648 Mpi2EventDataIrOperationStatus_t *event_data =
6649 (Mpi2EventDataIrOperationStatus_t *)
6650 fw_event->event_data;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306651 static struct _raid_device *raid_device;
6652 unsigned long flags;
6653 u16 handle;
6654
Eric Moore635374e2009-03-09 01:21:12 -06006655#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306656 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6657 && !ioc->hide_ir_msg)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306658 _scsih_sas_ir_operation_status_event_debug(ioc,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306659 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06006660#endif
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306661
6662 /* code added for raid transport support */
6663 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6664
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306665 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306666 handle = le16_to_cpu(event_data->VolDevHandle);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306667 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306668 if (raid_device)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306669 raid_device->percent_complete =
6670 event_data->PercentComplete;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306671 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306672 }
Eric Moore635374e2009-03-09 01:21:12 -06006673}
6674
6675/**
Kashyap, Desai14695852010-03-30 10:52:44 +05306676 * _scsih_prep_device_scan - initialize parameters prior to device scan
6677 * @ioc: per adapter object
6678 *
6679 * Set the deleted flag prior to device scan. If the device is found during
6680 * the scan, then we clear the deleted flag.
6681 */
6682static void
6683_scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6684{
6685 struct MPT2SAS_DEVICE *sas_device_priv_data;
6686 struct scsi_device *sdev;
6687
6688 shost_for_each_device(sdev, ioc->shost) {
6689 sas_device_priv_data = sdev->hostdata;
6690 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6691 sas_device_priv_data->sas_target->deleted = 1;
6692 }
6693}
6694
6695/**
Eric Moore635374e2009-03-09 01:21:12 -06006696 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6697 * @ioc: per adapter object
6698 * @sas_address: sas address
6699 * @slot: enclosure slot id
6700 * @handle: device handle
6701 *
6702 * After host reset, find out whether devices are still responding.
6703 * Used in _scsi_remove_unresponsive_sas_devices.
6704 *
6705 * Return nothing.
6706 */
6707static void
6708_scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6709 u16 slot, u16 handle)
6710{
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306711 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006712 struct scsi_target *starget;
6713 struct _sas_device *sas_device;
6714 unsigned long flags;
6715
6716 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6717 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6718 if (sas_device->sas_address == sas_address &&
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306719 sas_device->slot == slot) {
Eric Moore635374e2009-03-09 01:21:12 -06006720 sas_device->responding = 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05306721 starget = sas_device->starget;
Kashyap, Desai14695852010-03-30 10:52:44 +05306722 if (starget && starget->hostdata) {
6723 sas_target_priv_data = starget->hostdata;
6724 sas_target_priv_data->tm_busy = 0;
6725 sas_target_priv_data->deleted = 0;
6726 } else
6727 sas_target_priv_data = NULL;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306728 if (starget)
6729 starget_printk(KERN_INFO, starget,
6730 "handle(0x%04x), sas_addr(0x%016llx), "
6731 "enclosure logical id(0x%016llx), "
6732 "slot(%d)\n", handle,
6733 (unsigned long long)sas_device->sas_address,
6734 (unsigned long long)
6735 sas_device->enclosure_logical_id,
6736 sas_device->slot);
Eric Moore635374e2009-03-09 01:21:12 -06006737 if (sas_device->handle == handle)
6738 goto out;
6739 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6740 sas_device->handle);
6741 sas_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306742 if (sas_target_priv_data)
6743 sas_target_priv_data->handle = handle;
Eric Moore635374e2009-03-09 01:21:12 -06006744 goto out;
6745 }
6746 }
6747 out:
6748 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6749}
6750
6751/**
6752 * _scsih_search_responding_sas_devices -
6753 * @ioc: per adapter object
6754 *
6755 * After host reset, find out whether devices are still responding.
6756 * If not remove.
6757 *
6758 * Return nothing.
6759 */
6760static void
6761_scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6762{
6763 Mpi2SasDevicePage0_t sas_device_pg0;
6764 Mpi2ConfigReply_t mpi_reply;
6765 u16 ioc_status;
6766 __le64 sas_address;
6767 u16 handle;
6768 u32 device_info;
6769 u16 slot;
6770
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306771 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006772
6773 if (list_empty(&ioc->sas_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306774 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006775
6776 handle = 0xFFFF;
6777 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6778 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6779 handle))) {
6780 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6781 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306782 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006783 break;
6784 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6785 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6786 if (!(_scsih_is_end_device(device_info)))
6787 continue;
6788 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6789 slot = le16_to_cpu(sas_device_pg0.Slot);
6790 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6791 handle);
6792 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306793out:
6794 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6795 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006796}
6797
6798/**
6799 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6800 * @ioc: per adapter object
6801 * @wwid: world wide identifier for raid volume
6802 * @handle: device handle
6803 *
6804 * After host reset, find out whether devices are still responding.
6805 * Used in _scsi_remove_unresponsive_raid_devices.
6806 *
6807 * Return nothing.
6808 */
6809static void
6810_scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6811 u16 handle)
6812{
6813 struct MPT2SAS_TARGET *sas_target_priv_data;
6814 struct scsi_target *starget;
6815 struct _raid_device *raid_device;
6816 unsigned long flags;
6817
6818 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6819 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6820 if (raid_device->wwid == wwid && raid_device->starget) {
Kashyap, Desai14695852010-03-30 10:52:44 +05306821 starget = raid_device->starget;
6822 if (starget && starget->hostdata) {
6823 sas_target_priv_data = starget->hostdata;
6824 sas_target_priv_data->deleted = 0;
6825 } else
6826 sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006827 raid_device->responding = 1;
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306828 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06006829 starget_printk(KERN_INFO, raid_device->starget,
6830 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6831 (unsigned long long)raid_device->wwid);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306832 /*
6833 * WARPDRIVE: The handles of the PDs might have changed
6834 * across the host reset so re-initialize the
6835 * required data for Direct IO
6836 */
6837 _scsih_init_warpdrive_properties(ioc, raid_device);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306838 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6839 if (raid_device->handle == handle) {
6840 spin_unlock_irqrestore(&ioc->raid_device_lock,
6841 flags);
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306842 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306843 }
Eric Moore635374e2009-03-09 01:21:12 -06006844 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6845 raid_device->handle);
6846 raid_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306847 if (sas_target_priv_data)
6848 sas_target_priv_data->handle = handle;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306849 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306850 return;
Eric Moore635374e2009-03-09 01:21:12 -06006851 }
6852 }
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306853
Eric Moore635374e2009-03-09 01:21:12 -06006854 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6855}
6856
6857/**
6858 * _scsih_search_responding_raid_devices -
6859 * @ioc: per adapter object
6860 *
6861 * After host reset, find out whether devices are still responding.
6862 * If not remove.
6863 *
6864 * Return nothing.
6865 */
6866static void
6867_scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6868{
6869 Mpi2RaidVolPage1_t volume_pg1;
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306870 Mpi2RaidVolPage0_t volume_pg0;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306871 Mpi2RaidPhysDiskPage0_t pd_pg0;
Eric Moore635374e2009-03-09 01:21:12 -06006872 Mpi2ConfigReply_t mpi_reply;
6873 u16 ioc_status;
6874 u16 handle;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306875 u8 phys_disk_num;
Eric Moore635374e2009-03-09 01:21:12 -06006876
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306877 if (!ioc->ir_firmware)
6878 return;
6879
6880 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6881 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006882
6883 if (list_empty(&ioc->raid_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306884 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006885
6886 handle = 0xFFFF;
6887 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6888 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6889 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6890 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306891 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006892 break;
6893 handle = le16_to_cpu(volume_pg1.DevHandle);
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306894
6895 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6896 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6897 sizeof(Mpi2RaidVolPage0_t)))
6898 continue;
6899
6900 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6901 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6902 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6903 _scsih_mark_responding_raid_device(ioc,
6904 le64_to_cpu(volume_pg1.WWID), handle);
Eric Moore635374e2009-03-09 01:21:12 -06006905 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306906
6907 /* refresh the pd_handles */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306908 if (!ioc->is_warpdrive) {
6909 phys_disk_num = 0xFF;
6910 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6911 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6912 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6913 phys_disk_num))) {
6914 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6915 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306916 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306917 break;
6918 phys_disk_num = pd_pg0.PhysDiskNum;
6919 handle = le16_to_cpu(pd_pg0.DevHandle);
6920 set_bit(handle, ioc->pd_handles);
6921 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306922 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306923out:
6924 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6925 "complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006926}
6927
6928/**
6929 * _scsih_mark_responding_expander - mark a expander as responding
6930 * @ioc: per adapter object
6931 * @sas_address: sas address
6932 * @handle:
6933 *
6934 * After host reset, find out whether devices are still responding.
6935 * Used in _scsi_remove_unresponsive_expanders.
6936 *
6937 * Return nothing.
6938 */
6939static void
6940_scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6941 u16 handle)
6942{
6943 struct _sas_node *sas_expander;
6944 unsigned long flags;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306945 int i;
Eric Moore635374e2009-03-09 01:21:12 -06006946
6947 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6948 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306949 if (sas_expander->sas_address != sas_address)
6950 continue;
6951 sas_expander->responding = 1;
6952 if (sas_expander->handle == handle)
Eric Moore635374e2009-03-09 01:21:12 -06006953 goto out;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306954 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6955 " from(0x%04x) to (0x%04x)!!!\n",
6956 (unsigned long long)sas_expander->sas_address,
6957 sas_expander->handle, handle);
6958 sas_expander->handle = handle;
6959 for (i = 0 ; i < sas_expander->num_phys ; i++)
6960 sas_expander->phy[i].handle = handle;
6961 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006962 }
6963 out:
6964 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6965}
6966
6967/**
6968 * _scsih_search_responding_expanders -
6969 * @ioc: per adapter object
6970 *
6971 * After host reset, find out whether devices are still responding.
6972 * If not remove.
6973 *
6974 * Return nothing.
6975 */
6976static void
6977_scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6978{
6979 Mpi2ExpanderPage0_t expander_pg0;
6980 Mpi2ConfigReply_t mpi_reply;
6981 u16 ioc_status;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05306982 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006983 u16 handle;
6984
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306985 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006986
6987 if (list_empty(&ioc->sas_expander_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306988 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006989
6990 handle = 0xFFFF;
6991 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6992 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6993
6994 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6995 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy1c50e8d2013-07-25 11:29:45 +05306996 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
Eric Moore635374e2009-03-09 01:21:12 -06006997 break;
6998
6999 handle = le16_to_cpu(expander_pg0.DevHandle);
7000 sas_address = le64_to_cpu(expander_pg0.SASAddress);
7001 printk(KERN_INFO "\texpander present: handle(0x%04x), "
7002 "sas_addr(0x%016llx)\n", handle,
7003 (unsigned long long)sas_address);
7004 _scsih_mark_responding_expander(ioc, sas_address, handle);
7005 }
7006
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307007 out:
7008 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06007009}
7010
7011/**
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307012 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
Eric Moore635374e2009-03-09 01:21:12 -06007013 * @ioc: per adapter object
7014 *
7015 * Return nothing.
7016 */
7017static void
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307018_scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06007019{
7020 struct _sas_device *sas_device, *sas_device_next;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307021 struct _sas_node *sas_expander, *sas_expander_next;
Eric Moore635374e2009-03-09 01:21:12 -06007022 struct _raid_device *raid_device, *raid_device_next;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307023 struct list_head tmp_list;
7024 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06007025
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307026 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
7027 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06007028
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307029 /* removing unresponding end devices */
7030 printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n",
7031 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06007032 list_for_each_entry_safe(sas_device, sas_device_next,
7033 &ioc->sas_device_list, list) {
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307034 if (!sas_device->responding)
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05307035 mpt2sas_device_remove_by_sas_address(ioc,
7036 sas_device->sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307037 else
Eric Moore635374e2009-03-09 01:21:12 -06007038 sas_device->responding = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007039 }
7040
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307041 /* removing unresponding volumes */
7042 if (ioc->ir_firmware) {
7043 printk(MPT2SAS_INFO_FMT "removing unresponding devices: "
7044 "volumes\n", ioc->name);
7045 list_for_each_entry_safe(raid_device, raid_device_next,
7046 &ioc->raid_device_list, list) {
7047 if (!raid_device->responding)
7048 _scsih_sas_volume_delete(ioc,
7049 raid_device->handle);
7050 else
7051 raid_device->responding = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007052 }
Eric Moore635374e2009-03-09 01:21:12 -06007053 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307054 /* removing unresponding expanders */
7055 printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n",
7056 ioc->name);
7057 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7058 INIT_LIST_HEAD(&tmp_list);
7059 list_for_each_entry_safe(sas_expander, sas_expander_next,
7060 &ioc->sas_expander_list, list) {
7061 if (!sas_expander->responding)
7062 list_move_tail(&sas_expander->list, &tmp_list);
7063 else
Eric Moore635374e2009-03-09 01:21:12 -06007064 sas_expander->responding = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307065 }
7066 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7067 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7068 list) {
7069 list_del(&sas_expander->list);
7070 _scsih_expander_node_remove(ioc, sas_expander);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307071 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307072 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
7073 ioc->name);
7074 /* unblock devices */
7075 _scsih_ublock_io_all_device(ioc);
7076}
7077
7078static void
7079_scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
7080 struct _sas_node *sas_expander, u16 handle)
7081{
7082 Mpi2ExpanderPage1_t expander_pg1;
7083 Mpi2ConfigReply_t mpi_reply;
7084 int i;
7085
7086 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7087 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
7088 &expander_pg1, i, handle))) {
7089 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7090 ioc->name, __FILE__, __LINE__, __func__);
7091 return;
7092 }
7093
7094 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
7095 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7096 expander_pg1.NegotiatedLinkRate >> 4);
7097 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307098}
7099
7100/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307101 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307102 * @ioc: per adapter object
7103 *
7104 * Return nothing.
7105 */
7106static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307107_scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307108{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307109 Mpi2ExpanderPage0_t expander_pg0;
7110 Mpi2SasDevicePage0_t sas_device_pg0;
7111 Mpi2RaidVolPage1_t volume_pg1;
7112 Mpi2RaidVolPage0_t volume_pg0;
7113 Mpi2RaidPhysDiskPage0_t pd_pg0;
7114 Mpi2EventIrConfigElement_t element;
7115 Mpi2ConfigReply_t mpi_reply;
7116 u8 phys_disk_num;
7117 u16 ioc_status;
7118 u16 handle, parent_handle;
7119 u64 sas_address;
7120 struct _sas_device *sas_device;
7121 struct _sas_node *expander_device;
7122 static struct _raid_device *raid_device;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307123 u8 retry_count;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307124 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307125
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307126 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307127
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307128 _scsih_sas_host_refresh(ioc);
7129
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307130 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n",
7131 ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307132 /* expanders */
7133 handle = 0xFFFF;
7134 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7135 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7136 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7137 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307138 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7139 printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: "
7140 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7141 ioc->name, ioc_status,
7142 le32_to_cpu(mpi_reply.IOCLogInfo));
7143 break;
7144 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307145 handle = le16_to_cpu(expander_pg0.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307146 spin_lock_irqsave(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307147 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7148 ioc, le64_to_cpu(expander_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307149 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307150 if (expander_device)
7151 _scsih_refresh_expander_links(ioc, expander_device,
7152 handle);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307153 else {
7154 printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: "
7155 "handle (0x%04x), sas_addr(0x%016llx)\n",
7156 ioc->name, handle, (unsigned long long)
7157 le64_to_cpu(expander_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307158 _scsih_expander_add(ioc, handle);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307159 printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: "
7160 "handle (0x%04x), sas_addr(0x%016llx)\n",
7161 ioc->name, handle, (unsigned long long)
7162 le64_to_cpu(expander_pg0.SASAddress));
7163 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307164 }
7165
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307166 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n",
7167 ioc->name);
7168
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307169 if (!ioc->ir_firmware)
7170 goto skip_to_sas;
7171
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307172 printk(MPT2SAS_INFO_FMT "\tscan devices phys disk start\n", ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307173 /* phys disk */
7174 phys_disk_num = 0xFF;
7175 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7176 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7177 phys_disk_num))) {
7178 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7179 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307180 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7181 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:"
7182 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7183 ioc->name, ioc_status,
7184 le32_to_cpu(mpi_reply.IOCLogInfo));
7185 break;
7186 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307187 phys_disk_num = pd_pg0.PhysDiskNum;
7188 handle = le16_to_cpu(pd_pg0.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307189 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307190 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307191 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307192 if (sas_device)
7193 continue;
7194 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7195 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7196 handle) != 0)
7197 continue;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307198 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7199 MPI2_IOCSTATUS_MASK;
7200 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7201 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan "
7202 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7203 ioc->name, ioc_status,
7204 le32_to_cpu(mpi_reply.IOCLogInfo));
7205 break;
7206 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307207 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7208 if (!_scsih_get_sas_address(ioc, parent_handle,
7209 &sas_address)) {
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307210 printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: "
7211 " handle (0x%04x), sas_addr(0x%016llx)\n",
7212 ioc->name, handle, (unsigned long long)
7213 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307214 mpt2sas_transport_update_links(ioc, sas_address,
7215 handle, sas_device_pg0.PhyNum,
7216 MPI2_SAS_NEG_LINK_RATE_1_5);
7217 set_bit(handle, ioc->pd_handles);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307218 retry_count = 0;
7219 /* This will retry adding the end device.
7220 * _scsih_add_device() will decide on retries and
7221 * return "1" when it should be retried
7222 */
7223 while (_scsih_add_device(ioc, handle, retry_count++,
7224 1)) {
7225 ssleep(1);
7226 }
7227 printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: "
7228 " handle (0x%04x), sas_addr(0x%016llx)\n",
7229 ioc->name, handle, (unsigned long long)
7230 le64_to_cpu(sas_device_pg0.SASAddress));
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307231 }
7232 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307233
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307234 printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n",
7235 ioc->name);
7236
7237 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes start\n", ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307238 /* volumes */
7239 handle = 0xFFFF;
7240 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7241 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7242 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7243 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307244 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7245 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7246 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7247 ioc->name, ioc_status,
7248 le32_to_cpu(mpi_reply.IOCLogInfo));
7249 break;
7250 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307251 handle = le16_to_cpu(volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307252 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307253 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7254 le64_to_cpu(volume_pg1.WWID));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307255 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307256 if (raid_device)
7257 continue;
7258 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7259 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7260 sizeof(Mpi2RaidVolPage0_t)))
7261 continue;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307262 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7263 MPI2_IOCSTATUS_MASK;
7264 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7265 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7266 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7267 ioc->name, ioc_status,
7268 le32_to_cpu(mpi_reply.IOCLogInfo));
7269 break;
7270 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307271 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7272 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7273 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7274 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7275 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7276 element.VolDevHandle = volume_pg1.DevHandle;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307277 printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: "
7278 " handle (0x%04x)\n", ioc->name,
7279 volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307280 _scsih_sas_volume_add(ioc, &element);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307281 printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: "
7282 " handle (0x%04x)\n", ioc->name,
7283 volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307284 }
7285 }
7286
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307287 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n",
7288 ioc->name);
7289
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307290 skip_to_sas:
7291
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307292 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n",
7293 ioc->name);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307294 /* sas devices */
7295 handle = 0xFFFF;
7296 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7297 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7298 handle))) {
7299 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7300 MPI2_IOCSTATUS_MASK;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307301 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7302 printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:"
7303 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7304 ioc->name, ioc_status,
7305 le32_to_cpu(mpi_reply.IOCLogInfo));
7306 break;
7307 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307308 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7309 if (!(_scsih_is_end_device(
7310 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7311 continue;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307312 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307313 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7314 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307315 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307316 if (sas_device)
7317 continue;
7318 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7319 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307320 printk(MPT2SAS_INFO_FMT "\tBEFORE 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 mpt2sas_transport_update_links(ioc, sas_address, handle,
7325 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307326 retry_count = 0;
7327 /* This will retry adding the end device.
7328 * _scsih_add_device() will decide on retries and
7329 * return "1" when it should be retried
7330 */
7331 while (_scsih_add_device(ioc, handle, retry_count++,
7332 0)) {
7333 ssleep(1);
7334 }
7335 printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: "
7336 "handle (0x%04x), sas_addr(0x%016llx)\n",
7337 ioc->name, handle, (unsigned long long)
7338 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307339 }
7340 }
7341
Sreekanth Reddy6241f222013-02-02 00:56:18 +05307342 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n",
7343 ioc->name);
7344
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307345 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307346}
7347
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307348
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307349/**
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307350 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7351 * @ioc: per adapter object
7352 * @reset_phase: phase
7353 *
7354 * The handler for doing any required cleanup or initialization.
7355 *
7356 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7357 * MPT2_IOC_DONE_RESET
7358 *
7359 * Return nothing.
7360 */
7361void
7362mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7363{
7364 switch (reset_phase) {
7365 case MPT2_IOC_PRE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307366 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307367 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307368 break;
7369 case MPT2_IOC_AFTER_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307370 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307371 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307372 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7373 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7374 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7375 complete(&ioc->scsih_cmds.done);
7376 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307377 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7378 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7379 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7380 complete(&ioc->tm_cmds.done);
7381 }
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307382 _scsih_fw_event_cleanup_queue(ioc);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307383 _scsih_flush_running_cmds(ioc);
7384 break;
7385 case MPT2_IOC_DONE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307386 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307387 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307388 _scsih_sas_host_refresh(ioc);
Kashyap, Desai14695852010-03-30 10:52:44 +05307389 _scsih_prep_device_scan(ioc);
7390 _scsih_search_responding_sas_devices(ioc);
7391 _scsih_search_responding_raid_devices(ioc);
7392 _scsih_search_responding_expanders(ioc);
sreekanth.reddy@lsi.com14aa7f72012-07-17 15:56:13 +05307393 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7394 !ioc->sas_hba.num_phys)) {
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307395 _scsih_prep_device_scan(ioc);
7396 _scsih_search_responding_sas_devices(ioc);
7397 _scsih_search_responding_raid_devices(ioc);
7398 _scsih_search_responding_expanders(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307399 _scsih_error_recovery_delete_devices(ioc);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307400 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307401 break;
Eric Moore635374e2009-03-09 01:21:12 -06007402 }
7403}
7404
7405/**
7406 * _firmware_event_work - delayed task for processing firmware events
7407 * @ioc: per adapter object
7408 * @work: equal to the fw_event_work object
7409 * Context: user.
7410 *
7411 * Return nothing.
7412 */
7413static void
7414_firmware_event_work(struct work_struct *work)
7415{
7416 struct fw_event_work *fw_event = container_of(work,
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307417 struct fw_event_work, delayed_work.work);
Eric Moore635374e2009-03-09 01:21:12 -06007418 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7419
Eric Moore635374e2009-03-09 01:21:12 -06007420 /* the queue is being flushed so ignore this event */
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05307421 if (ioc->remove_host ||
Eric Moore3cb54692010-07-08 14:44:34 -06007422 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06007423 _scsih_fw_event_free(ioc, fw_event);
7424 return;
7425 }
Eric Moore635374e2009-03-09 01:21:12 -06007426
Eric Moore635374e2009-03-09 01:21:12 -06007427 switch (fw_event->event) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307428 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307429 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307430 ssleep(1);
7431 _scsih_remove_unresponding_sas_devices(ioc);
7432 _scsih_scan_for_devices_after_reset(ioc);
7433 break;
7434 case MPT2SAS_PORT_ENABLE_COMPLETE:
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307435 ioc->start_scan = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307436
Reddy, Sreekanthb0df96a02013-02-26 16:59:59 +05307437 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7438 mpt2sas_base_update_missing_delay(ioc, missing_delay[0],
7439 missing_delay[1]);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307440
7441 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7442 "from worker thread\n", ioc->name));
7443 break;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05307444 case MPT2SAS_TURN_ON_FAULT_LED:
7445 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
7446 break;
Eric Moore635374e2009-03-09 01:21:12 -06007447 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307448 _scsih_sas_topology_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007449 break;
7450 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307451 _scsih_sas_device_status_change_event(ioc,
7452 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007453 break;
7454 case MPI2_EVENT_SAS_DISCOVERY:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307455 _scsih_sas_discovery_event(ioc,
7456 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007457 break;
7458 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
Andrew Mortona78e21d2012-02-08 12:52:22 -08007459 _scsih_sas_broadcast_primitive_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307460 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007461 break;
7462 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7463 _scsih_sas_enclosure_dev_status_change_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307464 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007465 break;
7466 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307467 _scsih_sas_ir_config_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007468 break;
7469 case MPI2_EVENT_IR_VOLUME:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307470 _scsih_sas_ir_volume_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007471 break;
7472 case MPI2_EVENT_IR_PHYSICAL_DISK:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307473 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007474 break;
7475 case MPI2_EVENT_IR_OPERATION_STATUS:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307476 _scsih_sas_ir_operation_status_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007477 break;
Eric Moore635374e2009-03-09 01:21:12 -06007478 }
7479 _scsih_fw_event_free(ioc, fw_event);
7480}
7481
7482/**
7483 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7484 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307485 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06007486 * @reply: reply message frame(lower 32bit addr)
7487 * Context: interrupt.
7488 *
7489 * This function merely adds a new work task into ioc->firmware_event_thread.
7490 * The tasks are worked from _firmware_event_work in user context.
7491 *
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307492 * Returns void.
Eric Moore635374e2009-03-09 01:21:12 -06007493 */
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307494void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307495mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7496 u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06007497{
7498 struct fw_event_work *fw_event;
7499 Mpi2EventNotificationReply_t *mpi_reply;
Eric Moore635374e2009-03-09 01:21:12 -06007500 u16 event;
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307501 u16 sz;
Eric Moore635374e2009-03-09 01:21:12 -06007502
7503 /* events turned off due to host reset or driver unloading */
Eric Moore3cb54692010-07-08 14:44:34 -06007504 if (ioc->remove_host || ioc->pci_error_recovery)
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307505 return;
Eric Moore635374e2009-03-09 01:21:12 -06007506
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307507 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05307508
7509 if (unlikely(!mpi_reply)) {
7510 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7511 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307512 return;
nagalakshmi.nandigama@lsi.com298c7942012-03-20 12:07:17 +05307513 }
7514
Eric Moore635374e2009-03-09 01:21:12 -06007515 event = le16_to_cpu(mpi_reply->Event);
7516
7517 switch (event) {
7518 /* handle these */
7519 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7520 {
7521 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7522 (Mpi2EventDataSasBroadcastPrimitive_t *)
7523 mpi_reply->EventData;
7524
7525 if (baen_data->Primitive !=
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307526 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307527 return;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307528
7529 if (ioc->broadcast_aen_busy) {
7530 ioc->broadcast_aen_pending++;
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307531 return;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307532 } else
7533 ioc->broadcast_aen_busy = 1;
Eric Moore635374e2009-03-09 01:21:12 -06007534 break;
7535 }
7536
7537 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7538 _scsih_check_topo_delete_events(ioc,
7539 (Mpi2EventDataSasTopologyChangeList_t *)
7540 mpi_reply->EventData);
7541 break;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05307542 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7543 _scsih_check_ir_config_unhide_events(ioc,
7544 (Mpi2EventDataIrConfigChangeList_t *)
7545 mpi_reply->EventData);
7546 break;
7547 case MPI2_EVENT_IR_VOLUME:
7548 _scsih_check_volume_delete_events(ioc,
7549 (Mpi2EventDataIrVolume_t *)
7550 mpi_reply->EventData);
7551 break;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307552 case MPI2_EVENT_LOG_ENTRY_ADDED:
7553 {
7554 Mpi2EventDataLogEntryAdded_t *log_entry;
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05307555 __le32 *log_code;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307556
7557 if (!ioc->is_warpdrive)
7558 break;
7559
7560 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7561 mpi_reply->EventData;
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05307562 log_code = (__le32 *)log_entry->LogData;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307563
7564 if (le16_to_cpu(log_entry->LogEntryQualifier)
7565 != MPT2_WARPDRIVE_LOGENTRY)
7566 break;
7567
7568 switch (le32_to_cpu(*log_code)) {
7569 case MPT2_WARPDRIVE_LC_SSDT:
7570 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7571 "IO Throttling has occurred in the WarpDrive "
7572 "subsystem. Check WarpDrive documentation for "
7573 "additional details.\n", ioc->name);
7574 break;
7575 case MPT2_WARPDRIVE_LC_SSDLW:
7576 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7577 "Program/Erase Cycles for the WarpDrive subsystem "
7578 "in degraded range. Check WarpDrive documentation "
7579 "for additional details.\n", ioc->name);
7580 break;
7581 case MPT2_WARPDRIVE_LC_SSDLF:
7582 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7583 "There are no Program/Erase Cycles for the "
7584 "WarpDrive subsystem. The storage device will be "
7585 "in read-only mode. Check WarpDrive documentation "
7586 "for additional details.\n", ioc->name);
7587 break;
7588 case MPT2_WARPDRIVE_LC_BRMF:
7589 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7590 "The Backup Rail Monitor has failed on the "
7591 "WarpDrive subsystem. Check WarpDrive "
7592 "documentation for additional details.\n",
7593 ioc->name);
7594 break;
7595 }
7596
7597 break;
7598 }
Eric Moore635374e2009-03-09 01:21:12 -06007599 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7600 case MPI2_EVENT_IR_OPERATION_STATUS:
7601 case MPI2_EVENT_SAS_DISCOVERY:
7602 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
Eric Moore635374e2009-03-09 01:21:12 -06007603 case MPI2_EVENT_IR_PHYSICAL_DISK:
Eric Moore635374e2009-03-09 01:21:12 -06007604 break;
7605
7606 default: /* ignore the rest */
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307607 return;
Eric Moore635374e2009-03-09 01:21:12 -06007608 }
7609
Joe Lawrence00713ad2014-06-25 17:03:33 -04007610 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7611 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06007612 if (!fw_event) {
7613 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7614 ioc->name, __FILE__, __LINE__, __func__);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307615 return;
Eric Moore635374e2009-03-09 01:21:12 -06007616 }
Eric Moore635374e2009-03-09 01:21:12 -06007617
Joe Lawrence00713ad2014-06-25 17:03:33 -04007618 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
Eric Moore635374e2009-03-09 01:21:12 -06007619 fw_event->ioc = ioc;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307620 fw_event->VF_ID = mpi_reply->VF_ID;
7621 fw_event->VP_ID = mpi_reply->VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -06007622 fw_event->event = event;
7623 _scsih_fw_event_add(ioc, fw_event);
Sreekanth Reddy6409a7d2013-07-25 11:24:35 +05307624 return;
Eric Moore635374e2009-03-09 01:21:12 -06007625}
7626
7627/* shost template */
7628static struct scsi_host_template scsih_driver_template = {
7629 .module = THIS_MODULE,
7630 .name = "Fusion MPT SAS Host",
7631 .proc_name = MPT2SAS_DRIVER_NAME,
Eric Moored5d135b2009-05-18 13:02:08 -06007632 .queuecommand = _scsih_qcmd,
7633 .target_alloc = _scsih_target_alloc,
7634 .slave_alloc = _scsih_slave_alloc,
7635 .slave_configure = _scsih_slave_configure,
7636 .target_destroy = _scsih_target_destroy,
7637 .slave_destroy = _scsih_slave_destroy,
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307638 .scan_finished = _scsih_scan_finished,
7639 .scan_start = _scsih_scan_start,
Eric Moored5d135b2009-05-18 13:02:08 -06007640 .change_queue_depth = _scsih_change_queue_depth,
7641 .change_queue_type = _scsih_change_queue_type,
7642 .eh_abort_handler = _scsih_abort,
7643 .eh_device_reset_handler = _scsih_dev_reset,
7644 .eh_target_reset_handler = _scsih_target_reset,
7645 .eh_host_reset_handler = _scsih_host_reset,
7646 .bios_param = _scsih_bios_param,
Eric Moore635374e2009-03-09 01:21:12 -06007647 .can_queue = 1,
7648 .this_id = -1,
7649 .sg_tablesize = MPT2SAS_SG_DEPTH,
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05307650 .max_sectors = 32767,
Eric Moore635374e2009-03-09 01:21:12 -06007651 .cmd_per_lun = 7,
7652 .use_clustering = ENABLE_CLUSTERING,
7653 .shost_attrs = mpt2sas_host_attrs,
7654 .sdev_attrs = mpt2sas_dev_attrs,
7655};
7656
7657/**
7658 * _scsih_expander_node_remove - removing expander device from list.
7659 * @ioc: per adapter object
7660 * @sas_expander: the sas_device object
7661 * Context: Calling function should acquire ioc->sas_node_lock.
7662 *
7663 * Removing object and freeing associated memory from the
7664 * ioc->sas_expander_list.
7665 *
7666 * Return nothing.
7667 */
7668static void
7669_scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7670 struct _sas_node *sas_expander)
7671{
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307672 struct _sas_port *mpt2sas_port, *next;
Eric Moore635374e2009-03-09 01:21:12 -06007673
7674 /* remove sibling ports attached to this expander */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307675 list_for_each_entry_safe(mpt2sas_port, next,
Eric Moore635374e2009-03-09 01:21:12 -06007676 &sas_expander->sas_port_list, port_list) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307677 if (ioc->shost_recovery)
7678 return;
Eric Moore635374e2009-03-09 01:21:12 -06007679 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307680 SAS_END_DEVICE)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307681 mpt2sas_device_remove_by_sas_address(ioc,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307682 mpt2sas_port->remote_identify.sas_address);
7683 else if (mpt2sas_port->remote_identify.device_type ==
7684 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06007685 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307686 SAS_FANOUT_EXPANDER_DEVICE)
7687 mpt2sas_expander_remove(ioc,
7688 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007689 }
7690
7691 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307692 sas_expander->sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06007693
7694 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7695 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7696 sas_expander->handle, (unsigned long long)
7697 sas_expander->sas_address);
7698
Eric Moore635374e2009-03-09 01:21:12 -06007699 kfree(sas_expander->phy);
7700 kfree(sas_expander);
7701}
7702
7703/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05307704 * _scsih_ir_shutdown - IR shutdown notification
7705 * @ioc: per adapter object
7706 *
7707 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7708 * the host system is shutting down.
7709 *
7710 * Return nothing.
7711 */
7712static void
7713_scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7714{
7715 Mpi2RaidActionRequest_t *mpi_request;
7716 Mpi2RaidActionReply_t *mpi_reply;
7717 u16 smid;
7718
7719 /* is IR firmware build loaded ? */
7720 if (!ioc->ir_firmware)
7721 return;
7722
Kashyap, Desai744090d2009-10-05 15:56:56 +05307723 mutex_lock(&ioc->scsih_cmds.mutex);
7724
7725 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7726 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7727 ioc->name, __func__);
7728 goto out;
7729 }
7730 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7731
7732 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7733 if (!smid) {
7734 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7735 ioc->name, __func__);
7736 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7737 goto out;
7738 }
7739
7740 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7741 ioc->scsih_cmds.smid = smid;
7742 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7743
7744 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7745 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7746
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307747 if (!ioc->hide_ir_msg)
7748 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307749 init_completion(&ioc->scsih_cmds.done);
7750 mpt2sas_base_put_smid_default(ioc, smid);
7751 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7752
7753 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7754 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7755 ioc->name, __func__);
7756 goto out;
7757 }
7758
7759 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7760 mpi_reply = ioc->scsih_cmds.reply;
7761
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307762 if (!ioc->hide_ir_msg)
7763 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7764 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7765 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7766 le32_to_cpu(mpi_reply->IOCLogInfo));
Kashyap, Desai744090d2009-10-05 15:56:56 +05307767 }
7768
7769 out:
7770 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7771 mutex_unlock(&ioc->scsih_cmds.mutex);
7772}
7773
7774/**
7775 * _scsih_shutdown - routine call during system shutdown
7776 * @pdev: PCI device struct
7777 *
7778 * Return nothing.
7779 */
7780static void
7781_scsih_shutdown(struct pci_dev *pdev)
7782{
7783 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7784 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307785 struct workqueue_struct *wq;
7786 unsigned long flags;
7787
7788 ioc->remove_host = 1;
7789 _scsih_fw_event_cleanup_queue(ioc);
7790
7791 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7792 wq = ioc->firmware_event_thread;
7793 ioc->firmware_event_thread = NULL;
7794 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7795 if (wq)
7796 destroy_workqueue(wq);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307797
7798 _scsih_ir_shutdown(ioc);
7799 mpt2sas_base_detach(ioc);
7800}
7801
7802/**
Eric Moored5d135b2009-05-18 13:02:08 -06007803 * _scsih_remove - detach and remove add host
Eric Moore635374e2009-03-09 01:21:12 -06007804 * @pdev: PCI device struct
7805 *
Kashyap, Desai744090d2009-10-05 15:56:56 +05307806 * Routine called when unloading the driver.
Eric Moore635374e2009-03-09 01:21:12 -06007807 * Return nothing.
7808 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08007809static void
Eric Moored5d135b2009-05-18 13:02:08 -06007810_scsih_remove(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06007811{
7812 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7813 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307814 struct _sas_port *mpt2sas_port, *next_port;
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307815 struct _raid_device *raid_device, *next;
7816 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06007817 struct workqueue_struct *wq;
7818 unsigned long flags;
7819
7820 ioc->remove_host = 1;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307821 _scsih_fw_event_cleanup_queue(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007822
7823 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7824 wq = ioc->firmware_event_thread;
7825 ioc->firmware_event_thread = NULL;
7826 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7827 if (wq)
7828 destroy_workqueue(wq);
7829
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307830 /* release all the volumes */
Kashyap, Desai3a9c9132011-01-04 11:40:23 +05307831 _scsih_ir_shutdown(ioc);
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307832 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7833 list) {
7834 if (raid_device->starget) {
7835 sas_target_priv_data =
7836 raid_device->starget->hostdata;
7837 sas_target_priv_data->deleted = 1;
7838 scsi_remove_target(&raid_device->starget->dev);
7839 }
7840 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7841 "(0x%016llx)\n", ioc->name, raid_device->handle,
7842 (unsigned long long) raid_device->wwid);
7843 _scsih_raid_device_remove(ioc, raid_device);
7844 }
7845
Eric Moore635374e2009-03-09 01:21:12 -06007846 /* free ports attached to the sas_host */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307847 list_for_each_entry_safe(mpt2sas_port, next_port,
Eric Moore635374e2009-03-09 01:21:12 -06007848 &ioc->sas_hba.sas_port_list, port_list) {
7849 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307850 SAS_END_DEVICE)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307851 mpt2sas_device_remove_by_sas_address(ioc,
Eric Moore635374e2009-03-09 01:21:12 -06007852 mpt2sas_port->remote_identify.sas_address);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307853 else if (mpt2sas_port->remote_identify.device_type ==
7854 SAS_EDGE_EXPANDER_DEVICE ||
7855 mpt2sas_port->remote_identify.device_type ==
7856 SAS_FANOUT_EXPANDER_DEVICE)
7857 mpt2sas_expander_remove(ioc,
7858 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007859 }
7860
7861 /* free phys attached to the sas_host */
7862 if (ioc->sas_hba.num_phys) {
7863 kfree(ioc->sas_hba.phy);
7864 ioc->sas_hba.phy = NULL;
7865 ioc->sas_hba.num_phys = 0;
7866 }
7867
7868 sas_remove_host(shost);
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05307869 scsi_remove_host(shost);
kashyap.desai@lsi.com9ae89b02011-08-04 16:47:50 +05307870 mpt2sas_base_detach(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007871 list_del(&ioc->list);
Eric Moore635374e2009-03-09 01:21:12 -06007872 scsi_host_put(shost);
7873}
7874
7875/**
7876 * _scsih_probe_boot_devices - reports 1st device
7877 * @ioc: per adapter object
7878 *
7879 * If specified in bios page 2, this routine reports the 1st
7880 * device scsi-ml or sas transport for persistent boot device
7881 * purposes. Please refer to function _scsih_determine_boot_device()
7882 */
7883static void
7884_scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7885{
7886 u8 is_raid;
7887 void *device;
7888 struct _sas_device *sas_device;
7889 struct _raid_device *raid_device;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307890 u16 handle;
7891 u64 sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007892 u64 sas_address;
7893 unsigned long flags;
7894 int rc;
7895
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307896 /* no Bios, return immediately */
7897 if (!ioc->bios_pg3.BiosVersion)
7898 return;
7899
Eric Moore635374e2009-03-09 01:21:12 -06007900 device = NULL;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307901 is_raid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007902 if (ioc->req_boot_device.device) {
7903 device = ioc->req_boot_device.device;
7904 is_raid = ioc->req_boot_device.is_raid;
7905 } else if (ioc->req_alt_boot_device.device) {
7906 device = ioc->req_alt_boot_device.device;
7907 is_raid = ioc->req_alt_boot_device.is_raid;
7908 } else if (ioc->current_boot_device.device) {
7909 device = ioc->current_boot_device.device;
7910 is_raid = ioc->current_boot_device.is_raid;
7911 }
7912
7913 if (!device)
7914 return;
7915
7916 if (is_raid) {
7917 raid_device = device;
7918 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7919 raid_device->id, 0);
7920 if (rc)
7921 _scsih_raid_device_remove(ioc, raid_device);
7922 } else {
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307923 spin_lock_irqsave(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06007924 sas_device = device;
7925 handle = sas_device->handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307926 sas_address_parent = sas_device->sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007927 sas_address = sas_device->sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06007928 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7929 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307930
7931 if (ioc->hide_drives)
7932 return;
Eric Moore635374e2009-03-09 01:21:12 -06007933 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307934 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -06007935 _scsih_sas_device_remove(ioc, sas_device);
7936 } else if (!sas_device->starget) {
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307937 if (!ioc->is_driver_loading) {
7938 mpt2sas_transport_port_remove(ioc,
7939 sas_address,
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05307940 sas_address_parent);
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307941 _scsih_sas_device_remove(ioc, sas_device);
7942 }
Eric Moore635374e2009-03-09 01:21:12 -06007943 }
7944 }
7945}
7946
7947/**
7948 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7949 * @ioc: per adapter object
7950 *
7951 * Called during initial loading of the driver.
7952 */
7953static void
7954_scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7955{
7956 struct _raid_device *raid_device, *raid_next;
7957 int rc;
7958
7959 list_for_each_entry_safe(raid_device, raid_next,
7960 &ioc->raid_device_list, list) {
7961 if (raid_device->starget)
7962 continue;
7963 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7964 raid_device->id, 0);
7965 if (rc)
7966 _scsih_raid_device_remove(ioc, raid_device);
7967 }
7968}
7969
7970/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307971 * _scsih_probe_sas - reporting sas devices to sas transport
Eric Moore635374e2009-03-09 01:21:12 -06007972 * @ioc: per adapter object
7973 *
7974 * Called during initial loading of the driver.
7975 */
7976static void
7977_scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7978{
7979 struct _sas_device *sas_device, *next;
7980 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06007981
7982 /* SAS Device List */
7983 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7984 list) {
Eric Moore635374e2009-03-09 01:21:12 -06007985
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307986 if (ioc->hide_drives)
7987 continue;
7988
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307989 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7990 sas_device->sas_address_parent)) {
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307991 list_del(&sas_device->list);
7992 kfree(sas_device);
7993 continue;
Eric Moore635374e2009-03-09 01:21:12 -06007994 } else if (!sas_device->starget) {
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307995 if (!ioc->is_driver_loading) {
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05307996 mpt2sas_transport_port_remove(ioc,
7997 sas_device->sas_address,
7998 sas_device->sas_address_parent);
Sreekanth Reddybc6d4c32013-07-25 11:31:12 +05307999 list_del(&sas_device->list);
8000 kfree(sas_device);
8001 continue;
8002 }
Eric Moore635374e2009-03-09 01:21:12 -06008003 }
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05308004 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8005 list_move_tail(&sas_device->list, &ioc->sas_device_list);
8006 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06008007 }
8008}
8009
8010/**
8011 * _scsih_probe_devices - probing for devices
8012 * @ioc: per adapter object
8013 *
8014 * Called during initial loading of the driver.
8015 */
8016static void
8017_scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
8018{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308019 u16 volume_mapping_flags;
Eric Moore635374e2009-03-09 01:21:12 -06008020
8021 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8022 return; /* return when IOC doesn't support initiator mode */
8023
8024 _scsih_probe_boot_devices(ioc);
8025
8026 if (ioc->ir_firmware) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308027 volume_mapping_flags =
8028 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8029 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8030 if (volume_mapping_flags ==
8031 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
Eric Moore635374e2009-03-09 01:21:12 -06008032 _scsih_probe_raid(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308033 _scsih_probe_sas(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008034 } else {
Eric Moore635374e2009-03-09 01:21:12 -06008035 _scsih_probe_sas(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308036 _scsih_probe_raid(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008037 }
8038 } else
8039 _scsih_probe_sas(ioc);
8040}
8041
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308042
8043/**
8044 * _scsih_scan_start - scsi lld callback for .scan_start
8045 * @shost: SCSI host pointer
8046 *
8047 * The shost has the ability to discover targets on its own instead
8048 * of scanning the entire bus. In our implemention, we will kick off
8049 * firmware discovery.
8050 */
8051static void
8052_scsih_scan_start(struct Scsi_Host *shost)
8053{
8054 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8055 int rc;
8056
8057 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8058 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
8059
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05308060 if (disable_discovery > 0)
8061 return;
8062
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308063 ioc->start_scan = 1;
8064 rc = mpt2sas_port_enable(ioc);
8065
8066 if (rc != 0)
8067 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
8068}
8069
8070/**
8071 * _scsih_scan_finished - scsi lld callback for .scan_finished
8072 * @shost: SCSI host pointer
8073 * @time: elapsed time of the scan in jiffies
8074 *
8075 * This function will be called periodically until it returns 1 with the
8076 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8077 * we wait for firmware discovery to complete, then return 1.
8078 */
8079static int
8080_scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8081{
8082 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8083
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05308084 if (disable_discovery > 0) {
8085 ioc->is_driver_loading = 0;
8086 ioc->wait_for_discovery_to_complete = 0;
8087 return 1;
8088 }
8089
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308090 if (time >= (300 * HZ)) {
8091 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8092 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
8093 "(timeout=300s)\n", ioc->name);
8094 ioc->is_driver_loading = 0;
8095 return 1;
8096 }
8097
8098 if (ioc->start_scan)
8099 return 0;
8100
8101 if (ioc->start_scan_failed) {
8102 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
8103 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
8104 ioc->is_driver_loading = 0;
8105 ioc->wait_for_discovery_to_complete = 0;
8106 ioc->remove_host = 1;
8107 return 1;
8108 }
8109
8110 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
8111 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8112
8113 if (ioc->wait_for_discovery_to_complete) {
8114 ioc->wait_for_discovery_to_complete = 0;
8115 _scsih_probe_devices(ioc);
8116 }
8117 mpt2sas_base_start_watchdog(ioc);
8118 ioc->is_driver_loading = 0;
8119 return 1;
8120}
8121
8122
Eric Moore635374e2009-03-09 01:21:12 -06008123/**
Eric Moored5d135b2009-05-18 13:02:08 -06008124 * _scsih_probe - attach and add scsi host
Eric Moore635374e2009-03-09 01:21:12 -06008125 * @pdev: PCI device struct
8126 * @id: pci device id
8127 *
8128 * Returns 0 success, anything else error.
8129 */
8130static int
Eric Moored5d135b2009-05-18 13:02:08 -06008131_scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
Eric Moore635374e2009-03-09 01:21:12 -06008132{
8133 struct MPT2SAS_ADAPTER *ioc;
8134 struct Scsi_Host *shost;
8135
8136 shost = scsi_host_alloc(&scsih_driver_template,
8137 sizeof(struct MPT2SAS_ADAPTER));
8138 if (!shost)
8139 return -ENODEV;
8140
8141 /* init local params */
8142 ioc = shost_priv(shost);
8143 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
8144 INIT_LIST_HEAD(&ioc->list);
Eric Mooreba33fad2009-03-15 21:37:18 -06008145 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
Eric Moore635374e2009-03-09 01:21:12 -06008146 ioc->shost = shost;
8147 ioc->id = mpt_ids++;
8148 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
8149 ioc->pdev = pdev;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308150 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8151 ioc->is_warpdrive = 1;
8152 ioc->hide_ir_msg = 1;
8153 } else
8154 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
Eric Moore635374e2009-03-09 01:21:12 -06008155 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8156 ioc->tm_cb_idx = tm_cb_idx;
8157 ioc->ctl_cb_idx = ctl_cb_idx;
8158 ioc->base_cb_idx = base_cb_idx;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308159 ioc->port_enable_cb_idx = port_enable_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008160 ioc->transport_cb_idx = transport_cb_idx;
Kashyap, Desai744090d2009-10-05 15:56:56 +05308161 ioc->scsih_cb_idx = scsih_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008162 ioc->config_cb_idx = config_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308163 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308164 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308165 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008166 ioc->logging_level = logging_level;
nagalakshmi.nandigama@lsi.com845a0e42011-12-01 07:42:04 +05308167 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
Eric Moore635374e2009-03-09 01:21:12 -06008168 /* misc semaphores and spin locks */
Kashyap, Desaid2742132010-06-17 13:28:55 +05308169 mutex_init(&ioc->reset_in_progress_mutex);
Eric Moore635374e2009-03-09 01:21:12 -06008170 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8171 spin_lock_init(&ioc->scsi_lookup_lock);
8172 spin_lock_init(&ioc->sas_device_lock);
8173 spin_lock_init(&ioc->sas_node_lock);
8174 spin_lock_init(&ioc->fw_event_lock);
8175 spin_lock_init(&ioc->raid_device_lock);
8176
8177 INIT_LIST_HEAD(&ioc->sas_device_list);
8178 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8179 INIT_LIST_HEAD(&ioc->sas_expander_list);
8180 INIT_LIST_HEAD(&ioc->fw_event_list);
8181 INIT_LIST_HEAD(&ioc->raid_device_list);
8182 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308183 INIT_LIST_HEAD(&ioc->delayed_tr_list);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308184 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
Joe Lawrence3b3e6f82013-08-08 16:45:38 -04008185 INIT_LIST_HEAD(&ioc->reply_queue_list);
Eric Moore635374e2009-03-09 01:21:12 -06008186
8187 /* init shost parameters */
Eric Moored334aa72010-04-22 10:47:40 -06008188 shost->max_cmd_len = 32;
Eric Moore635374e2009-03-09 01:21:12 -06008189 shost->max_lun = max_lun;
8190 shost->transportt = mpt2sas_transport_template;
8191 shost->unique_id = ioc->id;
8192
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308193 if (max_sectors != 0xFFFF) {
8194 if (max_sectors < 64) {
8195 shost->max_sectors = 64;
Sreekanth Reddy6241f222013-02-02 00:56:18 +05308196 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8197 "for max_sectors, range is 64 to 32767. Assigning "
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308198 "value of 64.\n", ioc->name, max_sectors);
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05308199 } else if (max_sectors > 32767) {
8200 shost->max_sectors = 32767;
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308201 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8202 "for max_sectors, range is 64 to 8192. Assigning "
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05308203 "default value of 32767.\n", ioc->name,
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308204 max_sectors);
8205 } else {
8206 shost->max_sectors = max_sectors & 0xFFFE;
8207 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
8208 "set to %d\n", ioc->name, shost->max_sectors);
8209 }
8210 }
8211
Martin K. Petersen5e95e732012-08-28 14:29:37 -04008212 /* register EEDP capabilities with SCSI layer */
8213 if (prot_mask)
8214 scsi_host_set_prot(shost, prot_mask);
8215 else
8216 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8217 | SHOST_DIF_TYPE2_PROTECTION
8218 | SHOST_DIF_TYPE3_PROTECTION);
8219
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308220 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
Eric Moore3c621b32009-05-18 12:59:41 -06008221
Eric Moore635374e2009-03-09 01:21:12 -06008222 /* event thread */
8223 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8224 "fw_event%d", ioc->id);
8225 ioc->firmware_event_thread = create_singlethread_workqueue(
8226 ioc->firmware_event_name);
8227 if (!ioc->firmware_event_thread) {
8228 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8229 ioc->name, __FILE__, __LINE__, __func__);
8230 goto out_thread_fail;
8231 }
8232
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308233 ioc->is_driver_loading = 1;
Eric Moore635374e2009-03-09 01:21:12 -06008234 if ((mpt2sas_base_attach(ioc))) {
8235 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8236 ioc->name, __FILE__, __LINE__, __func__);
8237 goto out_attach_fail;
8238 }
8239
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308240 if (ioc->is_warpdrive) {
8241 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8242 ioc->hide_drives = 0;
8243 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8244 ioc->hide_drives = 1;
8245 else {
8246 if (_scsih_get_num_volumes(ioc))
8247 ioc->hide_drives = 1;
8248 else
8249 ioc->hide_drives = 0;
8250 }
8251 } else
8252 ioc->hide_drives = 0;
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05308253
8254 if ((scsi_add_host(shost, &pdev->dev))) {
8255 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8256 ioc->name, __FILE__, __LINE__, __func__);
8257 goto out_add_shost_fail;
8258 }
8259
nagalakshmi.nandigama@lsi.com2cb6fc82011-12-13 09:29:15 +05308260 scsi_scan_host(shost);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308261
Eric Moore635374e2009-03-09 01:21:12 -06008262 return 0;
8263
Reddy, Sreekanth02b77082014-07-14 12:00:49 +05308264 out_add_shost_fail:
8265 mpt2sas_base_detach(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008266 out_attach_fail:
8267 destroy_workqueue(ioc->firmware_event_thread);
8268 out_thread_fail:
8269 list_del(&ioc->list);
Tomas Henzlf555e052012-04-17 15:24:48 +02008270 scsi_host_put(shost);
Eric Moore635374e2009-03-09 01:21:12 -06008271 return -ENODEV;
8272}
8273
8274#ifdef CONFIG_PM
8275/**
Eric Moored5d135b2009-05-18 13:02:08 -06008276 * _scsih_suspend - power management suspend main entry point
Eric Moore635374e2009-03-09 01:21:12 -06008277 * @pdev: PCI device struct
8278 * @state: PM state change to (usually PCI_D3)
8279 *
8280 * Returns 0 success, anything else error.
8281 */
8282static int
Eric Moored5d135b2009-05-18 13:02:08 -06008283_scsih_suspend(struct pci_dev *pdev, pm_message_t state)
Eric Moore635374e2009-03-09 01:21:12 -06008284{
8285 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8286 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05308287 pci_power_t device_state;
Eric Moore635374e2009-03-09 01:21:12 -06008288
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308289 mpt2sas_base_stop_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008290 scsi_block_requests(shost);
Sreekanth Reddy3627dba2013-07-25 11:25:57 +05308291 _scsih_ir_shutdown(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008292 device_state = pci_choose_state(pdev, state);
8293 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8294 "operating state [D%d]\n", ioc->name, pdev,
8295 pci_name(pdev), device_state);
8296
8297 mpt2sas_base_free_resources(ioc);
8298 pci_save_state(pdev);
Eric Moore635374e2009-03-09 01:21:12 -06008299 pci_set_power_state(pdev, device_state);
8300 return 0;
8301}
8302
8303/**
Eric Moored5d135b2009-05-18 13:02:08 -06008304 * _scsih_resume - power management resume main entry point
Eric Moore635374e2009-03-09 01:21:12 -06008305 * @pdev: PCI device struct
8306 *
8307 * Returns 0 success, anything else error.
8308 */
8309static int
Eric Moored5d135b2009-05-18 13:02:08 -06008310_scsih_resume(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06008311{
8312 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8313 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05308314 pci_power_t device_state = pdev->current_state;
Eric Moore635374e2009-03-09 01:21:12 -06008315 int r;
8316
8317 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8318 "operating state [D%d]\n", ioc->name, pdev,
8319 pci_name(pdev), device_state);
8320
8321 pci_set_power_state(pdev, PCI_D0);
8322 pci_enable_wake(pdev, PCI_D0, 0);
8323 pci_restore_state(pdev);
8324 ioc->pdev = pdev;
8325 r = mpt2sas_base_map_resources(ioc);
8326 if (r)
8327 return r;
8328
8329 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8330 scsi_unblock_requests(shost);
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308331 mpt2sas_base_start_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008332 return 0;
8333}
8334#endif /* CONFIG_PM */
8335
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308336/**
8337 * _scsih_pci_error_detected - Called when a PCI error is detected.
8338 * @pdev: PCI device struct
8339 * @state: PCI channel state
8340 *
8341 * Description: Called when a PCI error is detected.
8342 *
8343 * Return value:
8344 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8345 */
8346static pci_ers_result_t
8347_scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8348{
8349 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8350 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8351
8352 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8353 ioc->name, state);
8354
8355 switch (state) {
8356 case pci_channel_io_normal:
8357 return PCI_ERS_RESULT_CAN_RECOVER;
8358 case pci_channel_io_frozen:
Eric Moore3cb54692010-07-08 14:44:34 -06008359 /* Fatal error, prepare for slot reset */
8360 ioc->pci_error_recovery = 1;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308361 scsi_block_requests(ioc->shost);
8362 mpt2sas_base_stop_watchdog(ioc);
8363 mpt2sas_base_free_resources(ioc);
8364 return PCI_ERS_RESULT_NEED_RESET;
8365 case pci_channel_io_perm_failure:
Eric Moore3cb54692010-07-08 14:44:34 -06008366 /* Permanent error, prepare for device removal */
8367 ioc->pci_error_recovery = 1;
8368 mpt2sas_base_stop_watchdog(ioc);
8369 _scsih_flush_running_cmds(ioc);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308370 return PCI_ERS_RESULT_DISCONNECT;
8371 }
8372 return PCI_ERS_RESULT_NEED_RESET;
8373}
8374
8375/**
8376 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8377 * @pdev: PCI device struct
8378 *
8379 * Description: This routine is called by the pci error recovery
8380 * code after the PCI slot has been reset, just before we
8381 * should resume normal operations.
8382 */
8383static pci_ers_result_t
8384_scsih_pci_slot_reset(struct pci_dev *pdev)
8385{
8386 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8387 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8388 int rc;
8389
8390 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8391 ioc->name);
8392
Eric Moore3cb54692010-07-08 14:44:34 -06008393 ioc->pci_error_recovery = 0;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308394 ioc->pdev = pdev;
Eric Moore3cb54692010-07-08 14:44:34 -06008395 pci_restore_state(pdev);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308396 rc = mpt2sas_base_map_resources(ioc);
8397 if (rc)
8398 return PCI_ERS_RESULT_DISCONNECT;
8399
8400
8401 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8402 FORCE_BIG_HAMMER);
8403
8404 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8405 (rc == 0) ? "success" : "failed");
8406
8407 if (!rc)
8408 return PCI_ERS_RESULT_RECOVERED;
8409 else
8410 return PCI_ERS_RESULT_DISCONNECT;
8411}
8412
8413/**
8414 * _scsih_pci_resume() - resume normal ops after PCI reset
8415 * @pdev: pointer to PCI device
8416 *
8417 * Called when the error recovery driver tells us that its
8418 * OK to resume normal operation. Use completion to allow
8419 * halted scsi ops to resume.
8420 */
8421static void
8422_scsih_pci_resume(struct pci_dev *pdev)
8423{
8424 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8425 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8426
8427 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8428
8429 pci_cleanup_aer_uncorrect_error_status(pdev);
8430 mpt2sas_base_start_watchdog(ioc);
8431 scsi_unblock_requests(ioc->shost);
8432}
8433
8434/**
8435 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8436 * @pdev: pointer to PCI device
8437 */
8438static pci_ers_result_t
8439_scsih_pci_mmio_enabled(struct pci_dev *pdev)
8440{
8441 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8442 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8443
8444 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8445 ioc->name);
8446
8447 /* TODO - dump whatever for debugging purposes */
8448
8449 /* Request a slot reset. */
8450 return PCI_ERS_RESULT_NEED_RESET;
8451}
8452
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07008453static const struct pci_error_handlers _scsih_err_handler = {
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308454 .error_detected = _scsih_pci_error_detected,
8455 .mmio_enabled = _scsih_pci_mmio_enabled,
8456 .slot_reset = _scsih_pci_slot_reset,
8457 .resume = _scsih_pci_resume,
8458};
Eric Moore635374e2009-03-09 01:21:12 -06008459
8460static struct pci_driver scsih_driver = {
8461 .name = MPT2SAS_DRIVER_NAME,
8462 .id_table = scsih_pci_table,
Eric Moored5d135b2009-05-18 13:02:08 -06008463 .probe = _scsih_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008464 .remove = _scsih_remove,
Kashyap, Desai744090d2009-10-05 15:56:56 +05308465 .shutdown = _scsih_shutdown,
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308466 .err_handler = &_scsih_err_handler,
Eric Moore635374e2009-03-09 01:21:12 -06008467#ifdef CONFIG_PM
Eric Moored5d135b2009-05-18 13:02:08 -06008468 .suspend = _scsih_suspend,
8469 .resume = _scsih_resume,
Eric Moore635374e2009-03-09 01:21:12 -06008470#endif
8471};
8472
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308473/* raid transport support */
8474static struct raid_function_template mpt2sas_raid_functions = {
8475 .cookie = &scsih_driver_template,
8476 .is_raid = _scsih_is_raid,
8477 .get_resync = _scsih_get_resync,
8478 .get_state = _scsih_get_state,
8479};
Eric Moore635374e2009-03-09 01:21:12 -06008480
8481/**
Eric Moored5d135b2009-05-18 13:02:08 -06008482 * _scsih_init - main entry point for this driver.
Eric Moore635374e2009-03-09 01:21:12 -06008483 *
8484 * Returns 0 success, anything else error.
8485 */
8486static int __init
Eric Moored5d135b2009-05-18 13:02:08 -06008487_scsih_init(void)
Eric Moore635374e2009-03-09 01:21:12 -06008488{
8489 int error;
8490
8491 mpt_ids = 0;
8492 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8493 MPT2SAS_DRIVER_VERSION);
8494
8495 mpt2sas_transport_template =
8496 sas_attach_transport(&mpt2sas_transport_functions);
8497 if (!mpt2sas_transport_template)
8498 return -ENODEV;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308499 /* raid transport support */
8500 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8501 if (!mpt2sas_raid_template) {
8502 sas_release_transport(mpt2sas_transport_template);
8503 return -ENODEV;
8504 }
Eric Moore635374e2009-03-09 01:21:12 -06008505
8506 mpt2sas_base_initialize_callback_handler();
8507
8508 /* queuecommand callback hander */
Eric Moored5d135b2009-05-18 13:02:08 -06008509 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
Eric Moore635374e2009-03-09 01:21:12 -06008510
Uwe Kleine-König65155b32010-06-11 12:17:01 +02008511 /* task management callback handler */
Eric Moored5d135b2009-05-18 13:02:08 -06008512 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
Eric Moore635374e2009-03-09 01:21:12 -06008513
8514 /* base internal commands callback handler */
8515 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308516 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8517 mpt2sas_port_enable_done);
Eric Moore635374e2009-03-09 01:21:12 -06008518
8519 /* transport internal commands callback handler */
8520 transport_cb_idx = mpt2sas_base_register_callback_handler(
8521 mpt2sas_transport_done);
8522
Kashyap, Desai744090d2009-10-05 15:56:56 +05308523 /* scsih internal commands callback handler */
8524 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8525
Eric Moore635374e2009-03-09 01:21:12 -06008526 /* configuration page API internal commands callback handler */
8527 config_cb_idx = mpt2sas_base_register_callback_handler(
8528 mpt2sas_config_done);
8529
8530 /* ctl module callback handler */
8531 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8532
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308533 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8534 _scsih_tm_tr_complete);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308535
8536 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8537 _scsih_tm_volume_tr_complete);
8538
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308539 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8540 _scsih_sas_control_complete);
8541
Eric Moore635374e2009-03-09 01:21:12 -06008542 mpt2sas_ctl_init();
8543
8544 error = pci_register_driver(&scsih_driver);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308545 if (error) {
8546 /* raid transport support */
8547 raid_class_release(mpt2sas_raid_template);
Eric Moore635374e2009-03-09 01:21:12 -06008548 sas_release_transport(mpt2sas_transport_template);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308549 }
Eric Moore635374e2009-03-09 01:21:12 -06008550
8551 return error;
8552}
8553
8554/**
Eric Moored5d135b2009-05-18 13:02:08 -06008555 * _scsih_exit - exit point for this driver (when it is a module).
Eric Moore635374e2009-03-09 01:21:12 -06008556 *
8557 * Returns 0 success, anything else error.
8558 */
8559static void __exit
Eric Moored5d135b2009-05-18 13:02:08 -06008560_scsih_exit(void)
Eric Moore635374e2009-03-09 01:21:12 -06008561{
8562 printk(KERN_INFO "mpt2sas version %s unloading\n",
8563 MPT2SAS_DRIVER_VERSION);
8564
8565 pci_unregister_driver(&scsih_driver);
8566
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308567 mpt2sas_ctl_exit();
8568
Eric Moore635374e2009-03-09 01:21:12 -06008569 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8570 mpt2sas_base_release_callback_handler(tm_cb_idx);
8571 mpt2sas_base_release_callback_handler(base_cb_idx);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308572 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008573 mpt2sas_base_release_callback_handler(transport_cb_idx);
Kashyap, Desai744090d2009-10-05 15:56:56 +05308574 mpt2sas_base_release_callback_handler(scsih_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008575 mpt2sas_base_release_callback_handler(config_cb_idx);
8576 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8577
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308578 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308579 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308580 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8581
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308582 /* raid transport support */
8583 raid_class_release(mpt2sas_raid_template);
8584 sas_release_transport(mpt2sas_transport_template);
8585
Eric Moore635374e2009-03-09 01:21:12 -06008586}
8587
Eric Moored5d135b2009-05-18 13:02:08 -06008588module_init(_scsih_init);
8589module_exit(_scsih_exit);