blob: bfda0ecd960dc230de8ed281db5e19b8a8aecbc2 [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.reddy@lsi.com433d7172012-07-17 15:56:03 +05305 * Copyright (C) 2007-2012 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
Eric Moore635374e2009-03-09 01:21:12 -0600104/* scsi-mid layer global parmeter is max_report_luns, which is 511 */
105#define MPT2SAS_MAX_LUN (16895)
106static int max_lun = MPT2SAS_MAX_LUN;
107module_param(max_lun, int, 0);
108MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
109
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530110/* diag_buffer_enable is bitwise
111 * bit 0 set = TRACE
112 * bit 1 set = SNAPSHOT
113 * bit 2 set = EXTENDED
114 *
115 * Either bit can be set, or both
116 */
117static int diag_buffer_enable = -1;
118module_param(diag_buffer_enable, int, 0);
119MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
120 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
121
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +0530122static int disable_discovery = -1;
123module_param(disable_discovery, int, 0);
124MODULE_PARM_DESC(disable_discovery, " disable discovery ");
125
Eric Moore635374e2009-03-09 01:21:12 -0600126/**
127 * struct sense_info - common structure for obtaining sense keys
128 * @skey: sense key
129 * @asc: additional sense code
130 * @ascq: additional sense code qualifier
131 */
132struct sense_info {
133 u8 skey;
134 u8 asc;
135 u8 ascq;
136};
137
138
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530139#define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC)
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530140#define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
141#define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
Eric Moore635374e2009-03-09 01:21:12 -0600142/**
143 * struct fw_event_work - firmware event struct
144 * @list: link list framework
145 * @work: work object (ioc->fault_reset_work_q)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +0530146 * @cancel_pending_work: flag set during reset handling
Eric Moore635374e2009-03-09 01:21:12 -0600147 * @ioc: per adapter object
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530148 * @device_handle: device handle
Eric Moore635374e2009-03-09 01:21:12 -0600149 * @VF_ID: virtual function id
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530150 * @VP_ID: virtual port id
Eric Moore635374e2009-03-09 01:21:12 -0600151 * @ignore: flag meaning this event has been marked to ignore
152 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
153 * @event_data: reply event data payload follows
154 *
155 * This object stored on ioc->fw_event_list.
156 */
157struct fw_event_work {
158 struct list_head list;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +0530159 u8 cancel_pending_work;
160 struct delayed_work delayed_work;
Eric Moore635374e2009-03-09 01:21:12 -0600161 struct MPT2SAS_ADAPTER *ioc;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530162 u16 device_handle;
Eric Moore635374e2009-03-09 01:21:12 -0600163 u8 VF_ID;
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530164 u8 VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -0600165 u8 ignore;
166 u16 event;
167 void *event_data;
168};
169
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +0530170/* raid transport support */
171static struct raid_template *mpt2sas_raid_template;
172
Eric Moore635374e2009-03-09 01:21:12 -0600173/**
174 * struct _scsi_io_transfer - scsi io transfer
175 * @handle: sas device handle (assigned by firmware)
176 * @is_raid: flag set for hidden raid components
177 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
178 * @data_length: data transfer length
179 * @data_dma: dma pointer to data
180 * @sense: sense data
181 * @lun: lun number
182 * @cdb_length: cdb length
183 * @cdb: cdb contents
Eric Moore635374e2009-03-09 01:21:12 -0600184 * @timeout: timeout for this command
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530185 * @VF_ID: virtual function id
186 * @VP_ID: virtual port id
187 * @valid_reply: flag set for reply message
Eric Moore635374e2009-03-09 01:21:12 -0600188 * @sense_length: sense length
189 * @ioc_status: ioc status
190 * @scsi_state: scsi state
191 * @scsi_status: scsi staus
192 * @log_info: log information
193 * @transfer_length: data length transfer when there is a reply message
194 *
195 * Used for sending internal scsi commands to devices within this module.
196 * Refer to _scsi_send_scsi_io().
197 */
198struct _scsi_io_transfer {
199 u16 handle;
200 u8 is_raid;
201 enum dma_data_direction dir;
202 u32 data_length;
203 dma_addr_t data_dma;
204 u8 sense[SCSI_SENSE_BUFFERSIZE];
205 u32 lun;
206 u8 cdb_length;
207 u8 cdb[32];
208 u8 timeout;
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530209 u8 VF_ID;
210 u8 VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -0600211 u8 valid_reply;
212 /* the following bits are only valid when 'valid_reply = 1' */
213 u32 sense_length;
214 u16 ioc_status;
215 u8 scsi_state;
216 u8 scsi_status;
217 u32 log_info;
218 u32 transfer_length;
219};
220
221/*
222 * The pci device ids are defined in mpi/mpi2_cnfg.h.
223 */
224static struct pci_device_id scsih_pci_table[] = {
225 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
226 PCI_ANY_ID, PCI_ANY_ID },
227 /* Falcon ~ 2008*/
228 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
229 PCI_ANY_ID, PCI_ANY_ID },
230 /* Liberator ~ 2108 */
231 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
232 PCI_ANY_ID, PCI_ANY_ID },
233 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
234 PCI_ANY_ID, PCI_ANY_ID },
235 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
236 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desaidb271362009-09-23 17:24:27 +0530237 /* Meteor ~ 2116 */
Eric Moore635374e2009-03-09 01:21:12 -0600238 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
239 PCI_ANY_ID, PCI_ANY_ID },
240 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
241 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desaidb271362009-09-23 17:24:27 +0530242 /* Thunderbolt ~ 2208 */
243 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
244 PCI_ANY_ID, PCI_ANY_ID },
245 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
246 PCI_ANY_ID, PCI_ANY_ID },
247 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
248 PCI_ANY_ID, PCI_ANY_ID },
249 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
250 PCI_ANY_ID, PCI_ANY_ID },
251 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
252 PCI_ANY_ID, PCI_ANY_ID },
253 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
254 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai203d65b2010-06-17 13:37:59 +0530255 /* Mustang ~ 2308 */
256 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
Kashyap, Desaidb271362009-09-23 17:24:27 +0530257 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai203d65b2010-06-17 13:37:59 +0530258 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
259 PCI_ANY_ID, PCI_ANY_ID },
260 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
Kashyap, Desaidb271362009-09-23 17:24:27 +0530261 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +0530262 /* SSS6200 */
263 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
264 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore635374e2009-03-09 01:21:12 -0600265 {0} /* Terminating entry */
266};
267MODULE_DEVICE_TABLE(pci, scsih_pci_table);
268
269/**
Eric Moored5d135b2009-05-18 13:02:08 -0600270 * _scsih_set_debug_level - global setting of ioc->logging_level.
Eric Moore635374e2009-03-09 01:21:12 -0600271 *
272 * Note: The logging levels are defined in mpt2sas_debug.h.
273 */
274static int
Eric Moored5d135b2009-05-18 13:02:08 -0600275_scsih_set_debug_level(const char *val, struct kernel_param *kp)
Eric Moore635374e2009-03-09 01:21:12 -0600276{
277 int ret = param_set_int(val, kp);
278 struct MPT2SAS_ADAPTER *ioc;
279
280 if (ret)
281 return ret;
282
283 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
Eric Mooreba33fad2009-03-15 21:37:18 -0600284 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
Eric Moore635374e2009-03-09 01:21:12 -0600285 ioc->logging_level = logging_level;
286 return 0;
287}
Eric Moored5d135b2009-05-18 13:02:08 -0600288module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
Eric Moore635374e2009-03-09 01:21:12 -0600289 &logging_level, 0644);
290
291/**
292 * _scsih_srch_boot_sas_address - search based on sas_address
293 * @sas_address: sas address
294 * @boot_device: boot device object from bios page 2
295 *
296 * Returns 1 when there's a match, 0 means no match.
297 */
298static inline int
299_scsih_srch_boot_sas_address(u64 sas_address,
300 Mpi2BootDeviceSasWwid_t *boot_device)
301{
302 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
303}
304
305/**
306 * _scsih_srch_boot_device_name - search based on device name
307 * @device_name: device name specified in INDENTIFY fram
308 * @boot_device: boot device object from bios page 2
309 *
310 * Returns 1 when there's a match, 0 means no match.
311 */
312static inline int
313_scsih_srch_boot_device_name(u64 device_name,
314 Mpi2BootDeviceDeviceName_t *boot_device)
315{
316 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
317}
318
319/**
320 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
321 * @enclosure_logical_id: enclosure logical id
322 * @slot_number: slot number
323 * @boot_device: boot device object from bios page 2
324 *
325 * Returns 1 when there's a match, 0 means no match.
326 */
327static inline int
328_scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
329 Mpi2BootDeviceEnclosureSlot_t *boot_device)
330{
331 return (enclosure_logical_id == le64_to_cpu(boot_device->
332 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
333 SlotNumber)) ? 1 : 0;
334}
335
336/**
337 * _scsih_is_boot_device - search for matching boot device.
338 * @sas_address: sas address
339 * @device_name: device name specified in INDENTIFY fram
340 * @enclosure_logical_id: enclosure logical id
341 * @slot_number: slot number
342 * @form: specifies boot device form
343 * @boot_device: boot device object from bios page 2
344 *
345 * Returns 1 when there's a match, 0 means no match.
346 */
347static int
348_scsih_is_boot_device(u64 sas_address, u64 device_name,
349 u64 enclosure_logical_id, u16 slot, u8 form,
350 Mpi2BiosPage2BootDevice_t *boot_device)
351{
352 int rc = 0;
353
354 switch (form) {
355 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
356 if (!sas_address)
357 break;
358 rc = _scsih_srch_boot_sas_address(
359 sas_address, &boot_device->SasWwid);
360 break;
361 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
362 if (!enclosure_logical_id)
363 break;
364 rc = _scsih_srch_boot_encl_slot(
365 enclosure_logical_id,
366 slot, &boot_device->EnclosureSlot);
367 break;
368 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
369 if (!device_name)
370 break;
371 rc = _scsih_srch_boot_device_name(
372 device_name, &boot_device->DeviceName);
373 break;
374 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
375 break;
376 }
377
378 return rc;
379}
380
381/**
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530382 * _scsih_get_sas_address - set the sas_address for given device handle
383 * @handle: device handle
384 * @sas_address: sas address
385 *
386 * Returns 0 success, non-zero when failure
387 */
388static int
389_scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
390 u64 *sas_address)
391{
392 Mpi2SasDevicePage0_t sas_device_pg0;
393 Mpi2ConfigReply_t mpi_reply;
394 u32 ioc_status;
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530395 *sas_address = 0;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530396
397 if (handle <= ioc->sas_hba.num_phys) {
398 *sas_address = ioc->sas_hba.sas_address;
399 return 0;
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530400 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530401
402 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
403 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530404 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
405 __FILE__, __LINE__, __func__);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530406 return -ENXIO;
407 }
408
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530409 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
410 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
411 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
412 return 0;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530413 }
414
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530415 /* we hit this becuase the given parent handle doesn't exist */
416 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
417 return -ENXIO;
418 /* else error case */
419 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
420 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
421 __FILE__, __LINE__, __func__);
422 return -EIO;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530423}
424
425/**
Eric Moore635374e2009-03-09 01:21:12 -0600426 * _scsih_determine_boot_device - determine boot device.
427 * @ioc: per adapter object
428 * @device: either sas_device or raid_device object
429 * @is_raid: [flag] 1 = raid object, 0 = sas object
430 *
431 * Determines whether this device should be first reported device to
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300432 * to scsi-ml or sas transport, this purpose is for persistent boot device.
Eric Moore635374e2009-03-09 01:21:12 -0600433 * There are primary, alternate, and current entries in bios page 2. The order
434 * priority is primary, alternate, then current. This routine saves
435 * the corresponding device object and is_raid flag in the ioc object.
436 * The saved data to be used later in _scsih_probe_boot_devices().
437 */
438static void
439_scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
440 void *device, u8 is_raid)
441{
442 struct _sas_device *sas_device;
443 struct _raid_device *raid_device;
444 u64 sas_address;
445 u64 device_name;
446 u64 enclosure_logical_id;
447 u16 slot;
448
449 /* only process this function when driver loads */
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530450 if (!ioc->is_driver_loading)
451 return;
452
453 /* no Bios, return immediately */
454 if (!ioc->bios_pg3.BiosVersion)
Eric Moore635374e2009-03-09 01:21:12 -0600455 return;
456
457 if (!is_raid) {
458 sas_device = device;
459 sas_address = sas_device->sas_address;
460 device_name = sas_device->device_name;
461 enclosure_logical_id = sas_device->enclosure_logical_id;
462 slot = sas_device->slot;
463 } else {
464 raid_device = device;
465 sas_address = raid_device->wwid;
466 device_name = 0;
467 enclosure_logical_id = 0;
468 slot = 0;
469 }
470
471 if (!ioc->req_boot_device.device) {
472 if (_scsih_is_boot_device(sas_address, device_name,
473 enclosure_logical_id, slot,
474 (ioc->bios_pg2.ReqBootDeviceForm &
475 MPI2_BIOSPAGE2_FORM_MASK),
476 &ioc->bios_pg2.RequestedBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530477 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600478 "%s: req_boot_device(0x%016llx)\n",
479 ioc->name, __func__,
480 (unsigned long long)sas_address));
481 ioc->req_boot_device.device = device;
482 ioc->req_boot_device.is_raid = is_raid;
483 }
484 }
485
486 if (!ioc->req_alt_boot_device.device) {
487 if (_scsih_is_boot_device(sas_address, device_name,
488 enclosure_logical_id, slot,
489 (ioc->bios_pg2.ReqAltBootDeviceForm &
490 MPI2_BIOSPAGE2_FORM_MASK),
491 &ioc->bios_pg2.RequestedAltBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530492 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600493 "%s: req_alt_boot_device(0x%016llx)\n",
494 ioc->name, __func__,
495 (unsigned long long)sas_address));
496 ioc->req_alt_boot_device.device = device;
497 ioc->req_alt_boot_device.is_raid = is_raid;
498 }
499 }
500
501 if (!ioc->current_boot_device.device) {
502 if (_scsih_is_boot_device(sas_address, device_name,
503 enclosure_logical_id, slot,
504 (ioc->bios_pg2.CurrentBootDeviceForm &
505 MPI2_BIOSPAGE2_FORM_MASK),
506 &ioc->bios_pg2.CurrentBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530507 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600508 "%s: current_boot_device(0x%016llx)\n",
509 ioc->name, __func__,
510 (unsigned long long)sas_address));
511 ioc->current_boot_device.device = device;
512 ioc->current_boot_device.is_raid = is_raid;
513 }
514 }
515}
516
517/**
518 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
519 * @ioc: per adapter object
520 * @sas_address: sas address
521 * Context: Calling function should acquire ioc->sas_device_lock
522 *
523 * This searches for sas_device based on sas_address, then return sas_device
524 * object.
525 */
526struct _sas_device *
527mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
528 u64 sas_address)
529{
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530530 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600531
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530532 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
533 if (sas_device->sas_address == sas_address)
534 return sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600535
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530536 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
537 if (sas_device->sas_address == sas_address)
538 return sas_device;
539
540 return NULL;
Eric Moore635374e2009-03-09 01:21:12 -0600541}
542
543/**
544 * _scsih_sas_device_find_by_handle - sas device search
545 * @ioc: per adapter object
546 * @handle: sas device handle (assigned by firmware)
547 * Context: Calling function should acquire ioc->sas_device_lock
548 *
549 * This searches for sas_device based on sas_address, then return sas_device
550 * object.
551 */
552static struct _sas_device *
553_scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
554{
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530555 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600556
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530557 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
558 if (sas_device->handle == handle)
559 return sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600560
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530561 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
562 if (sas_device->handle == handle)
563 return sas_device;
564
565 return NULL;
Eric Moore635374e2009-03-09 01:21:12 -0600566}
567
568/**
569 * _scsih_sas_device_remove - remove sas_device from list.
570 * @ioc: per adapter object
571 * @sas_device: the sas_device object
572 * Context: This function will acquire ioc->sas_device_lock.
573 *
574 * Removing object and freeing associated memory from the ioc->sas_device_list.
575 */
576static void
577_scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
578 struct _sas_device *sas_device)
579{
580 unsigned long flags;
581
Kashyap, Desai980ead32010-04-08 17:55:22 +0530582 if (!sas_device)
583 return;
584
Eric Moore635374e2009-03-09 01:21:12 -0600585 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530586 list_del(&sas_device->list);
587 kfree(sas_device);
Eric Moore635374e2009-03-09 01:21:12 -0600588 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
589}
590
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530591
Eric Moore635374e2009-03-09 01:21:12 -0600592/**
593 * _scsih_sas_device_add - insert sas_device to the list.
594 * @ioc: per adapter object
595 * @sas_device: the sas_device object
596 * Context: This function will acquire ioc->sas_device_lock.
597 *
598 * Adding new object to the ioc->sas_device_list.
599 */
600static void
601_scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
602 struct _sas_device *sas_device)
603{
604 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -0600605
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530606 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600607 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
608 sas_device->handle, (unsigned long long)sas_device->sas_address));
609
610 spin_lock_irqsave(&ioc->sas_device_lock, flags);
611 list_add_tail(&sas_device->list, &ioc->sas_device_list);
612 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
613
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530614 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +0530615 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -0600616 _scsih_sas_device_remove(ioc, sas_device);
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +0530617 } else if (!sas_device->starget) {
618 /* When asyn scanning is enabled, its not possible to remove
619 * devices while scanning is turned on due to an oops in
620 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
621 */
622 if (!ioc->is_driver_loading)
623 mpt2sas_transport_port_remove(ioc,
624 sas_device->sas_address,
625 sas_device->sas_address_parent);
626 _scsih_sas_device_remove(ioc, sas_device);
627 }
Eric Moore635374e2009-03-09 01:21:12 -0600628}
629
630/**
631 * _scsih_sas_device_init_add - insert sas_device to the list.
632 * @ioc: per adapter object
633 * @sas_device: the sas_device object
634 * Context: This function will acquire ioc->sas_device_lock.
635 *
636 * Adding new object at driver load time to the ioc->sas_device_init_list.
637 */
638static void
639_scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
640 struct _sas_device *sas_device)
641{
642 unsigned long flags;
643
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530644 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600645 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
646 sas_device->handle, (unsigned long long)sas_device->sas_address));
647
648 spin_lock_irqsave(&ioc->sas_device_lock, flags);
649 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
Eric Moore635374e2009-03-09 01:21:12 -0600650 _scsih_determine_boot_device(ioc, sas_device, 0);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530651 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -0600652}
653
654/**
Eric Moore635374e2009-03-09 01:21:12 -0600655 * _scsih_raid_device_find_by_id - raid device search
656 * @ioc: per adapter object
657 * @id: sas device target id
658 * @channel: sas device channel
659 * Context: Calling function should acquire ioc->raid_device_lock
660 *
661 * This searches for raid_device based on target id, then return raid_device
662 * object.
663 */
664static struct _raid_device *
665_scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
666{
667 struct _raid_device *raid_device, *r;
668
669 r = NULL;
670 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
671 if (raid_device->id == id && raid_device->channel == channel) {
672 r = raid_device;
673 goto out;
674 }
675 }
676
677 out:
678 return r;
679}
680
681/**
682 * _scsih_raid_device_find_by_handle - raid device search
683 * @ioc: per adapter object
684 * @handle: sas device handle (assigned by firmware)
685 * Context: Calling function should acquire ioc->raid_device_lock
686 *
687 * This searches for raid_device based on handle, then return raid_device
688 * object.
689 */
690static struct _raid_device *
691_scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
692{
693 struct _raid_device *raid_device, *r;
694
695 r = NULL;
696 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
697 if (raid_device->handle != handle)
698 continue;
699 r = raid_device;
700 goto out;
701 }
702
703 out:
704 return r;
705}
706
707/**
708 * _scsih_raid_device_find_by_wwid - raid device search
709 * @ioc: per adapter object
710 * @handle: sas device handle (assigned by firmware)
711 * Context: Calling function should acquire ioc->raid_device_lock
712 *
713 * This searches for raid_device based on wwid, then return raid_device
714 * object.
715 */
716static struct _raid_device *
717_scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
718{
719 struct _raid_device *raid_device, *r;
720
721 r = NULL;
722 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
723 if (raid_device->wwid != wwid)
724 continue;
725 r = raid_device;
726 goto out;
727 }
728
729 out:
730 return r;
731}
732
733/**
734 * _scsih_raid_device_add - add raid_device object
735 * @ioc: per adapter object
736 * @raid_device: raid_device object
737 *
738 * This is added to the raid_device_list link list.
739 */
740static void
741_scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
742 struct _raid_device *raid_device)
743{
744 unsigned long flags;
745
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530746 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600747 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
748 raid_device->handle, (unsigned long long)raid_device->wwid));
749
750 spin_lock_irqsave(&ioc->raid_device_lock, flags);
751 list_add_tail(&raid_device->list, &ioc->raid_device_list);
752 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
753}
754
755/**
756 * _scsih_raid_device_remove - delete raid_device object
757 * @ioc: per adapter object
758 * @raid_device: raid_device object
759 *
Eric Moore635374e2009-03-09 01:21:12 -0600760 */
761static void
762_scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
763 struct _raid_device *raid_device)
764{
765 unsigned long flags;
766
767 spin_lock_irqsave(&ioc->raid_device_lock, flags);
768 list_del(&raid_device->list);
Eric Moore635374e2009-03-09 01:21:12 -0600769 kfree(raid_device);
770 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
771}
772
773/**
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530774 * mpt2sas_scsih_expander_find_by_handle - expander device search
775 * @ioc: per adapter object
776 * @handle: expander handle (assigned by firmware)
777 * Context: Calling function should acquire ioc->sas_device_lock
778 *
779 * This searches for expander device based on handle, then returns the
780 * sas_node object.
781 */
782struct _sas_node *
783mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
784{
785 struct _sas_node *sas_expander, *r;
786
787 r = NULL;
788 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
789 if (sas_expander->handle != handle)
790 continue;
791 r = sas_expander;
792 goto out;
793 }
794 out:
795 return r;
796}
797
798/**
Eric Moore635374e2009-03-09 01:21:12 -0600799 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
800 * @ioc: per adapter object
801 * @sas_address: sas address
802 * Context: Calling function should acquire ioc->sas_node_lock.
803 *
804 * This searches for expander device based on sas_address, then returns the
805 * sas_node object.
806 */
807struct _sas_node *
808mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
809 u64 sas_address)
810{
811 struct _sas_node *sas_expander, *r;
812
813 r = NULL;
814 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
815 if (sas_expander->sas_address != sas_address)
816 continue;
817 r = sas_expander;
818 goto out;
819 }
820 out:
821 return r;
822}
823
824/**
825 * _scsih_expander_node_add - insert expander device to the list.
826 * @ioc: per adapter object
827 * @sas_expander: the sas_device object
828 * Context: This function will acquire ioc->sas_node_lock.
829 *
830 * Adding new object to the ioc->sas_expander_list.
831 *
832 * Return nothing.
833 */
834static void
835_scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
836 struct _sas_node *sas_expander)
837{
838 unsigned long flags;
839
840 spin_lock_irqsave(&ioc->sas_node_lock, flags);
841 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
842 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
843}
844
845/**
846 * _scsih_is_end_device - determines if device is an end device
847 * @device_info: bitfield providing information about the device.
848 * Context: none
849 *
850 * Returns 1 if end device.
851 */
852static int
853_scsih_is_end_device(u32 device_info)
854{
855 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
856 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
857 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
858 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
859 return 1;
860 else
861 return 0;
862}
863
864/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530865 * _scsih_scsi_lookup_get - returns scmd entry
Eric Moore635374e2009-03-09 01:21:12 -0600866 * @ioc: per adapter object
867 * @smid: system request message index
Eric Moore635374e2009-03-09 01:21:12 -0600868 *
869 * Returns the smid stored scmd pointer.
870 */
871static struct scsi_cmnd *
872_scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
873{
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530874 return ioc->scsi_lookup[smid - 1].scmd;
Eric Moore635374e2009-03-09 01:21:12 -0600875}
876
877/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530878 * _scsih_scsi_lookup_get_clear - returns scmd entry
879 * @ioc: per adapter object
880 * @smid: system request message index
881 *
882 * Returns the smid stored scmd pointer.
883 * Then will derefrence the stored scmd pointer.
884 */
885static inline struct scsi_cmnd *
886_scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
887{
888 unsigned long flags;
889 struct scsi_cmnd *scmd;
890
891 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
892 scmd = ioc->scsi_lookup[smid - 1].scmd;
893 ioc->scsi_lookup[smid - 1].scmd = NULL;
894 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
895
896 return scmd;
897}
898
899/**
Eric Moore635374e2009-03-09 01:21:12 -0600900 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
901 * @ioc: per adapter object
902 * @smid: system request message index
903 * @scmd: pointer to scsi command object
904 * Context: This function will acquire ioc->scsi_lookup_lock.
905 *
906 * This will search for a scmd pointer in the scsi_lookup array,
907 * returning the revelent smid. A returned value of zero means invalid.
908 */
909static u16
910_scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
911 *scmd)
912{
913 u16 smid;
914 unsigned long flags;
915 int i;
916
917 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
918 smid = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530919 for (i = 0; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600920 if (ioc->scsi_lookup[i].scmd == scmd) {
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530921 smid = ioc->scsi_lookup[i].smid;
Eric Moore635374e2009-03-09 01:21:12 -0600922 goto out;
923 }
924 }
925 out:
926 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
927 return smid;
928}
929
930/**
931 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
932 * @ioc: per adapter object
933 * @id: target id
934 * @channel: channel
935 * Context: This function will acquire ioc->scsi_lookup_lock.
936 *
937 * This will search for a matching channel:id in the scsi_lookup array,
938 * returning 1 if found.
939 */
940static u8
941_scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
942 int channel)
943{
944 u8 found;
945 unsigned long flags;
946 int i;
947
948 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
949 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530950 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600951 if (ioc->scsi_lookup[i].scmd &&
952 (ioc->scsi_lookup[i].scmd->device->id == id &&
953 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
954 found = 1;
955 goto out;
956 }
957 }
958 out:
959 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
960 return found;
961}
962
963/**
Eric Moore993e0da2009-05-18 13:00:45 -0600964 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
965 * @ioc: per adapter object
966 * @id: target id
967 * @lun: lun number
968 * @channel: channel
969 * Context: This function will acquire ioc->scsi_lookup_lock.
970 *
971 * This will search for a matching channel:id:lun in the scsi_lookup array,
972 * returning 1 if found.
973 */
974static u8
975_scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
976 unsigned int lun, int channel)
977{
978 u8 found;
979 unsigned long flags;
980 int i;
981
982 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
983 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530984 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore993e0da2009-05-18 13:00:45 -0600985 if (ioc->scsi_lookup[i].scmd &&
986 (ioc->scsi_lookup[i].scmd->device->id == id &&
987 ioc->scsi_lookup[i].scmd->device->channel == channel &&
988 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
989 found = 1;
990 goto out;
991 }
992 }
993 out:
994 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
995 return found;
996}
997
998/**
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530999 * _scsih_get_chain_buffer_tracker - obtain chain tracker
Eric Moore635374e2009-03-09 01:21:12 -06001000 * @ioc: per adapter object
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301001 * @smid: smid associated to an IO request
Eric Moore635374e2009-03-09 01:21:12 -06001002 *
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301003 * Returns chain tracker(from ioc->free_chain_list)
Eric Moore635374e2009-03-09 01:21:12 -06001004 */
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301005static struct chain_tracker *
1006_scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
Eric Moore635374e2009-03-09 01:21:12 -06001007{
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301008 struct chain_tracker *chain_req;
1009 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001010
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301011 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1012 if (list_empty(&ioc->free_chain_list)) {
1013 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
nagalakshmi.nandigama@lsi.comaff132d2011-12-01 07:53:08 +05301014 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not "
1015 "available\n", ioc->name));
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301016 return NULL;
1017 }
1018 chain_req = list_entry(ioc->free_chain_list.next,
1019 struct chain_tracker, tracker_list);
1020 list_del_init(&chain_req->tracker_list);
1021 list_add_tail(&chain_req->tracker_list,
1022 &ioc->scsi_lookup[smid - 1].chain_list);
1023 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1024 return chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001025}
1026
1027/**
1028 * _scsih_build_scatter_gather - main sg creation routine
1029 * @ioc: per adapter object
1030 * @scmd: scsi command
1031 * @smid: system request message index
1032 * Context: none.
1033 *
1034 * The main routine that builds scatter gather table from a given
1035 * scsi request sent via the .queuecommand main handler.
1036 *
1037 * Returns 0 success, anything else error
1038 */
1039static int
1040_scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1041 struct scsi_cmnd *scmd, u16 smid)
1042{
1043 Mpi2SCSIIORequest_t *mpi_request;
1044 dma_addr_t chain_dma;
1045 struct scatterlist *sg_scmd;
1046 void *sg_local, *chain;
1047 u32 chain_offset;
1048 u32 chain_length;
1049 u32 chain_flags;
FUJITA Tomonoribb789d012010-03-09 11:09:50 +09001050 int sges_left;
Eric Moore635374e2009-03-09 01:21:12 -06001051 u32 sges_in_segment;
1052 u32 sgl_flags;
1053 u32 sgl_flags_last_element;
1054 u32 sgl_flags_end_buffer;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301055 struct chain_tracker *chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001056
1057 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1058
1059 /* init scatter gather flags */
1060 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1061 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1062 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1063 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1064 << MPI2_SGE_FLAGS_SHIFT;
1065 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1066 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1067 << MPI2_SGE_FLAGS_SHIFT;
1068 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1069
1070 sg_scmd = scsi_sglist(scmd);
1071 sges_left = scsi_dma_map(scmd);
FUJITA Tomonoribb789d012010-03-09 11:09:50 +09001072 if (sges_left < 0) {
Eric Moore635374e2009-03-09 01:21:12 -06001073 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1074 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1075 return -ENOMEM;
1076 }
1077
1078 sg_local = &mpi_request->SGL;
1079 sges_in_segment = ioc->max_sges_in_main_message;
1080 if (sges_left <= sges_in_segment)
1081 goto fill_in_last_segment;
1082
1083 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1084 (sges_in_segment * ioc->sge_size))/4;
1085
1086 /* fill in main message segment when there is a chain following */
1087 while (sges_in_segment) {
1088 if (sges_in_segment == 1)
1089 ioc->base_add_sg_single(sg_local,
1090 sgl_flags_last_element | sg_dma_len(sg_scmd),
1091 sg_dma_address(sg_scmd));
1092 else
1093 ioc->base_add_sg_single(sg_local, sgl_flags |
1094 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1095 sg_scmd = sg_next(sg_scmd);
1096 sg_local += ioc->sge_size;
1097 sges_left--;
1098 sges_in_segment--;
1099 }
1100
1101 /* initializing the chain flags and pointers */
1102 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301103 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1104 if (!chain_req)
1105 return -1;
1106 chain = chain_req->chain_buffer;
1107 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001108 do {
1109 sges_in_segment = (sges_left <=
1110 ioc->max_sges_in_chain_message) ? sges_left :
1111 ioc->max_sges_in_chain_message;
1112 chain_offset = (sges_left == sges_in_segment) ?
1113 0 : (sges_in_segment * ioc->sge_size)/4;
1114 chain_length = sges_in_segment * ioc->sge_size;
1115 if (chain_offset) {
1116 chain_offset = chain_offset <<
1117 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1118 chain_length += ioc->sge_size;
1119 }
1120 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1121 chain_length, chain_dma);
1122 sg_local = chain;
1123 if (!chain_offset)
1124 goto fill_in_last_segment;
1125
1126 /* fill in chain segments */
1127 while (sges_in_segment) {
1128 if (sges_in_segment == 1)
1129 ioc->base_add_sg_single(sg_local,
1130 sgl_flags_last_element |
1131 sg_dma_len(sg_scmd),
1132 sg_dma_address(sg_scmd));
1133 else
1134 ioc->base_add_sg_single(sg_local, sgl_flags |
1135 sg_dma_len(sg_scmd),
1136 sg_dma_address(sg_scmd));
1137 sg_scmd = sg_next(sg_scmd);
1138 sg_local += ioc->sge_size;
1139 sges_left--;
1140 sges_in_segment--;
1141 }
1142
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301143 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1144 if (!chain_req)
1145 return -1;
1146 chain = chain_req->chain_buffer;
1147 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001148 } while (1);
1149
1150
1151 fill_in_last_segment:
1152
1153 /* fill the last segment */
1154 while (sges_left) {
1155 if (sges_left == 1)
1156 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1157 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1158 else
1159 ioc->base_add_sg_single(sg_local, sgl_flags |
1160 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1161 sg_scmd = sg_next(sg_scmd);
1162 sg_local += ioc->sge_size;
1163 sges_left--;
1164 }
1165
1166 return 0;
1167}
1168
1169/**
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301170 * _scsih_adjust_queue_depth - setting device queue depth
Eric Moore635374e2009-03-09 01:21:12 -06001171 * @sdev: scsi device struct
1172 * @qdepth: requested queue depth
1173 *
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301174 *
1175 * Returns nothing
Eric Moore635374e2009-03-09 01:21:12 -06001176 */
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301177static void
1178_scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
Eric Moore635374e2009-03-09 01:21:12 -06001179{
1180 struct Scsi_Host *shost = sdev->host;
1181 int max_depth;
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301182 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1183 struct MPT2SAS_DEVICE *sas_device_priv_data;
1184 struct MPT2SAS_TARGET *sas_target_priv_data;
1185 struct _sas_device *sas_device;
1186 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001187
1188 max_depth = shost->can_queue;
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301189
1190 /* limit max device queue for SATA to 32 */
1191 sas_device_priv_data = sdev->hostdata;
1192 if (!sas_device_priv_data)
1193 goto not_sata;
1194 sas_target_priv_data = sas_device_priv_data->sas_target;
1195 if (!sas_target_priv_data)
1196 goto not_sata;
1197 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1198 goto not_sata;
1199 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1200 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1201 sas_device_priv_data->sas_target->sas_address);
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301202 if (sas_device && sas_device->device_info &
1203 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1204 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301205 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301206
1207 not_sata:
1208
Eric Moore635374e2009-03-09 01:21:12 -06001209 if (!sdev->tagged_supported)
1210 max_depth = 1;
1211 if (qdepth > max_depth)
1212 qdepth = max_depth;
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301213 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1214}
1215
1216/**
1217 * _scsih_change_queue_depth - setting device queue depth
1218 * @sdev: scsi device struct
1219 * @qdepth: requested queue depth
1220 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1221 * (see include/scsi/scsi_host.h for definition)
1222 *
1223 * Returns queue depth.
1224 */
1225static int
1226_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1227{
1228 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1229 _scsih_adjust_queue_depth(sdev, qdepth);
1230 else if (reason == SCSI_QDEPTH_QFULL)
1231 scsi_track_queue_full(sdev, qdepth);
1232 else
1233 return -EOPNOTSUPP;
Eric Moore635374e2009-03-09 01:21:12 -06001234
1235 if (sdev->inquiry_len > 7)
1236 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1237 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1238 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1239 sdev->ordered_tags, sdev->scsi_level,
1240 (sdev->inquiry[7] & 2) >> 1);
1241
1242 return sdev->queue_depth;
1243}
1244
1245/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05301246 * _scsih_change_queue_type - changing device queue tag type
Eric Moore635374e2009-03-09 01:21:12 -06001247 * @sdev: scsi device struct
1248 * @tag_type: requested tag type
1249 *
1250 * Returns queue tag type.
1251 */
1252static int
Eric Moored5d135b2009-05-18 13:02:08 -06001253_scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
Eric Moore635374e2009-03-09 01:21:12 -06001254{
1255 if (sdev->tagged_supported) {
1256 scsi_set_tag_type(sdev, tag_type);
1257 if (tag_type)
1258 scsi_activate_tcq(sdev, sdev->queue_depth);
1259 else
1260 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1261 } else
1262 tag_type = 0;
1263
1264 return tag_type;
1265}
1266
1267/**
Eric Moored5d135b2009-05-18 13:02:08 -06001268 * _scsih_target_alloc - target add routine
Eric Moore635374e2009-03-09 01:21:12 -06001269 * @starget: scsi target struct
1270 *
1271 * Returns 0 if ok. Any other return is assumed to be an error and
1272 * the device is ignored.
1273 */
1274static int
Eric Moored5d135b2009-05-18 13:02:08 -06001275_scsih_target_alloc(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001276{
1277 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1278 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1279 struct MPT2SAS_TARGET *sas_target_priv_data;
1280 struct _sas_device *sas_device;
1281 struct _raid_device *raid_device;
1282 unsigned long flags;
1283 struct sas_rphy *rphy;
1284
1285 sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
1286 if (!sas_target_priv_data)
1287 return -ENOMEM;
1288
1289 starget->hostdata = sas_target_priv_data;
1290 sas_target_priv_data->starget = starget;
1291 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1292
1293 /* RAID volumes */
1294 if (starget->channel == RAID_CHANNEL) {
1295 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1296 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1297 starget->channel);
1298 if (raid_device) {
1299 sas_target_priv_data->handle = raid_device->handle;
1300 sas_target_priv_data->sas_address = raid_device->wwid;
1301 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301302 if (ioc->is_warpdrive)
1303 sas_target_priv_data->raid_device = raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06001304 raid_device->starget = starget;
1305 }
1306 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1307 return 0;
1308 }
1309
1310 /* sas/sata devices */
1311 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1312 rphy = dev_to_rphy(starget->dev.parent);
1313 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1314 rphy->identify.sas_address);
1315
1316 if (sas_device) {
1317 sas_target_priv_data->handle = sas_device->handle;
1318 sas_target_priv_data->sas_address = sas_device->sas_address;
1319 sas_device->starget = starget;
1320 sas_device->id = starget->id;
1321 sas_device->channel = starget->channel;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05301322 if (test_bit(sas_device->handle, ioc->pd_handles))
Eric Moore635374e2009-03-09 01:21:12 -06001323 sas_target_priv_data->flags |=
1324 MPT_TARGET_FLAGS_RAID_COMPONENT;
1325 }
1326 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1327
1328 return 0;
1329}
1330
1331/**
Eric Moored5d135b2009-05-18 13:02:08 -06001332 * _scsih_target_destroy - target destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001333 * @starget: scsi target struct
1334 *
1335 * Returns nothing.
1336 */
1337static void
Eric Moored5d135b2009-05-18 13:02:08 -06001338_scsih_target_destroy(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001339{
1340 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1341 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1342 struct MPT2SAS_TARGET *sas_target_priv_data;
1343 struct _sas_device *sas_device;
1344 struct _raid_device *raid_device;
1345 unsigned long flags;
1346 struct sas_rphy *rphy;
1347
1348 sas_target_priv_data = starget->hostdata;
1349 if (!sas_target_priv_data)
1350 return;
1351
1352 if (starget->channel == RAID_CHANNEL) {
1353 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1354 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1355 starget->channel);
1356 if (raid_device) {
1357 raid_device->starget = NULL;
1358 raid_device->sdev = NULL;
1359 }
1360 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1361 goto out;
1362 }
1363
1364 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1365 rphy = dev_to_rphy(starget->dev.parent);
1366 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1367 rphy->identify.sas_address);
Eric Moore8901cbb2009-04-21 15:41:32 -06001368 if (sas_device && (sas_device->starget == starget) &&
1369 (sas_device->id == starget->id) &&
1370 (sas_device->channel == starget->channel))
Eric Moore635374e2009-03-09 01:21:12 -06001371 sas_device->starget = NULL;
1372
1373 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1374
1375 out:
1376 kfree(sas_target_priv_data);
1377 starget->hostdata = NULL;
1378}
1379
1380/**
Eric Moored5d135b2009-05-18 13:02:08 -06001381 * _scsih_slave_alloc - device add routine
Eric Moore635374e2009-03-09 01:21:12 -06001382 * @sdev: scsi device struct
1383 *
1384 * Returns 0 if ok. Any other return is assumed to be an error and
1385 * the device is ignored.
1386 */
1387static int
Eric Moored5d135b2009-05-18 13:02:08 -06001388_scsih_slave_alloc(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001389{
1390 struct Scsi_Host *shost;
1391 struct MPT2SAS_ADAPTER *ioc;
1392 struct MPT2SAS_TARGET *sas_target_priv_data;
1393 struct MPT2SAS_DEVICE *sas_device_priv_data;
1394 struct scsi_target *starget;
1395 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06001396 unsigned long flags;
1397
1398 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
1399 if (!sas_device_priv_data)
1400 return -ENOMEM;
1401
1402 sas_device_priv_data->lun = sdev->lun;
1403 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1404
1405 starget = scsi_target(sdev);
1406 sas_target_priv_data = starget->hostdata;
1407 sas_target_priv_data->num_luns++;
1408 sas_device_priv_data->sas_target = sas_target_priv_data;
1409 sdev->hostdata = sas_device_priv_data;
1410 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1411 sdev->no_uld_attach = 1;
1412
1413 shost = dev_to_shost(&starget->dev);
1414 ioc = shost_priv(shost);
1415 if (starget->channel == RAID_CHANNEL) {
1416 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1417 raid_device = _scsih_raid_device_find_by_id(ioc,
1418 starget->id, starget->channel);
1419 if (raid_device)
1420 raid_device->sdev = sdev; /* raid is single lun */
1421 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06001422 }
1423
Eric Moore635374e2009-03-09 01:21:12 -06001424 return 0;
1425}
1426
1427/**
Eric Moored5d135b2009-05-18 13:02:08 -06001428 * _scsih_slave_destroy - device destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001429 * @sdev: scsi device struct
1430 *
1431 * Returns nothing.
1432 */
1433static void
Eric Moored5d135b2009-05-18 13:02:08 -06001434_scsih_slave_destroy(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001435{
1436 struct MPT2SAS_TARGET *sas_target_priv_data;
1437 struct scsi_target *starget;
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301438 struct Scsi_Host *shost;
1439 struct MPT2SAS_ADAPTER *ioc;
1440 struct _sas_device *sas_device;
1441 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001442
1443 if (!sdev->hostdata)
1444 return;
1445
1446 starget = scsi_target(sdev);
1447 sas_target_priv_data = starget->hostdata;
1448 sas_target_priv_data->num_luns--;
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301449
1450 shost = dev_to_shost(&starget->dev);
1451 ioc = shost_priv(shost);
1452
1453 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1454 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1455 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1456 sas_target_priv_data->sas_address);
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +05301457 if (sas_device && !sas_target_priv_data->num_luns)
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301458 sas_device->starget = NULL;
1459 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1460 }
1461
Eric Moore635374e2009-03-09 01:21:12 -06001462 kfree(sdev->hostdata);
1463 sdev->hostdata = NULL;
1464}
1465
1466/**
Eric Moored5d135b2009-05-18 13:02:08 -06001467 * _scsih_display_sata_capabilities - sata capabilities
Eric Moore635374e2009-03-09 01:21:12 -06001468 * @ioc: per adapter object
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301469 * @handle: device handle
Eric Moore635374e2009-03-09 01:21:12 -06001470 * @sdev: scsi device struct
1471 */
1472static void
Eric Moored5d135b2009-05-18 13:02:08 -06001473_scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301474 u16 handle, struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001475{
1476 Mpi2ConfigReply_t mpi_reply;
1477 Mpi2SasDevicePage0_t sas_device_pg0;
1478 u32 ioc_status;
1479 u16 flags;
1480 u32 device_info;
1481
1482 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301483 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06001484 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1485 ioc->name, __FILE__, __LINE__, __func__);
1486 return;
1487 }
1488
1489 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1490 MPI2_IOCSTATUS_MASK;
1491 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1492 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1493 ioc->name, __FILE__, __LINE__, __func__);
1494 return;
1495 }
1496
1497 flags = le16_to_cpu(sas_device_pg0.Flags);
Kashyap, Desaie94f6742010-03-17 16:24:52 +05301498 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
Eric Moore635374e2009-03-09 01:21:12 -06001499
1500 sdev_printk(KERN_INFO, sdev,
1501 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1502 "sw_preserve(%s)\n",
1503 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1504 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1505 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1506 "n",
1507 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1508 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1509 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1510}
1511
1512/**
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301513 * _scsih_is_raid - return boolean indicating device is raid volume
1514 * @dev the device struct object
1515 */
1516static int
1517_scsih_is_raid(struct device *dev)
1518{
1519 struct scsi_device *sdev = to_scsi_device(dev);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301520 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301521
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301522 if (ioc->is_warpdrive)
1523 return 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301524 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1525}
1526
1527/**
1528 * _scsih_get_resync - get raid volume resync percent complete
1529 * @dev the device struct object
1530 */
1531static void
1532_scsih_get_resync(struct device *dev)
1533{
1534 struct scsi_device *sdev = to_scsi_device(dev);
1535 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1536 static struct _raid_device *raid_device;
1537 unsigned long flags;
1538 Mpi2RaidVolPage0_t vol_pg0;
1539 Mpi2ConfigReply_t mpi_reply;
1540 u32 volume_status_flags;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301541 u8 percent_complete;
1542 u16 handle;
1543
1544 percent_complete = 0;
1545 handle = 0;
1546 if (ioc->is_warpdrive)
1547 goto out;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301548
1549 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1550 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1551 sdev->channel);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301552 if (raid_device) {
1553 handle = raid_device->handle;
1554 percent_complete = raid_device->percent_complete;
1555 }
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301556 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1557
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301558 if (!handle)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301559 goto out;
1560
1561 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301562 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301563 sizeof(Mpi2RaidVolPage0_t))) {
1564 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1565 ioc->name, __FILE__, __LINE__, __func__);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301566 percent_complete = 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301567 goto out;
1568 }
1569
1570 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301571 if (!(volume_status_flags &
1572 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1573 percent_complete = 0;
1574
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301575 out:
1576 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1577}
1578
1579/**
1580 * _scsih_get_state - get raid volume level
1581 * @dev the device struct object
1582 */
1583static void
1584_scsih_get_state(struct device *dev)
1585{
1586 struct scsi_device *sdev = to_scsi_device(dev);
1587 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1588 static struct _raid_device *raid_device;
1589 unsigned long flags;
1590 Mpi2RaidVolPage0_t vol_pg0;
1591 Mpi2ConfigReply_t mpi_reply;
1592 u32 volstate;
1593 enum raid_state state = RAID_STATE_UNKNOWN;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301594 u16 handle = 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301595
1596 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1597 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1598 sdev->channel);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301599 if (raid_device)
1600 handle = raid_device->handle;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301601 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1602
1603 if (!raid_device)
1604 goto out;
1605
1606 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301607 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301608 sizeof(Mpi2RaidVolPage0_t))) {
1609 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1610 ioc->name, __FILE__, __LINE__, __func__);
1611 goto out;
1612 }
1613
1614 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1615 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1616 state = RAID_STATE_RESYNCING;
1617 goto out;
1618 }
1619
1620 switch (vol_pg0.VolumeState) {
1621 case MPI2_RAID_VOL_STATE_OPTIMAL:
1622 case MPI2_RAID_VOL_STATE_ONLINE:
1623 state = RAID_STATE_ACTIVE;
1624 break;
1625 case MPI2_RAID_VOL_STATE_DEGRADED:
1626 state = RAID_STATE_DEGRADED;
1627 break;
1628 case MPI2_RAID_VOL_STATE_FAILED:
1629 case MPI2_RAID_VOL_STATE_MISSING:
1630 state = RAID_STATE_OFFLINE;
1631 break;
1632 }
1633 out:
1634 raid_set_state(mpt2sas_raid_template, dev, state);
1635}
1636
1637/**
1638 * _scsih_set_level - set raid level
1639 * @sdev: scsi device struct
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301640 * @volume_type: volume type
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301641 */
1642static void
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301643_scsih_set_level(struct scsi_device *sdev, u8 volume_type)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301644{
1645 enum raid_level level = RAID_LEVEL_UNKNOWN;
1646
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301647 switch (volume_type) {
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301648 case MPI2_RAID_VOL_TYPE_RAID0:
1649 level = RAID_LEVEL_0;
1650 break;
1651 case MPI2_RAID_VOL_TYPE_RAID10:
1652 level = RAID_LEVEL_10;
1653 break;
1654 case MPI2_RAID_VOL_TYPE_RAID1E:
1655 level = RAID_LEVEL_1E;
1656 break;
1657 case MPI2_RAID_VOL_TYPE_RAID1:
1658 level = RAID_LEVEL_1;
1659 break;
1660 }
1661
1662 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1663}
1664
1665/**
Eric Moore635374e2009-03-09 01:21:12 -06001666 * _scsih_get_volume_capabilities - volume capabilities
1667 * @ioc: per adapter object
1668 * @sas_device: the raid_device object
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301669 *
1670 * Returns 0 for success, else 1
Eric Moore635374e2009-03-09 01:21:12 -06001671 */
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301672static int
Eric Moore635374e2009-03-09 01:21:12 -06001673_scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1674 struct _raid_device *raid_device)
1675{
1676 Mpi2RaidVolPage0_t *vol_pg0;
1677 Mpi2RaidPhysDiskPage0_t pd_pg0;
1678 Mpi2SasDevicePage0_t sas_device_pg0;
1679 Mpi2ConfigReply_t mpi_reply;
1680 u16 sz;
1681 u8 num_pds;
1682
1683 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1684 &num_pds)) || !num_pds) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301685 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1686 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1687 __func__));
1688 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001689 }
1690
1691 raid_device->num_pds = num_pds;
1692 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1693 sizeof(Mpi2RaidVol0PhysDisk_t));
1694 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1695 if (!vol_pg0) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301696 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1697 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1698 __func__));
1699 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001700 }
1701
1702 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1703 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301704 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1705 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1706 __func__));
Eric Moore635374e2009-03-09 01:21:12 -06001707 kfree(vol_pg0);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301708 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001709 }
1710
1711 raid_device->volume_type = vol_pg0->VolumeType;
1712
1713 /* figure out what the underlying devices are by
1714 * obtaining the device_info bits for the 1st device
1715 */
1716 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1717 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1718 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1719 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1720 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1721 le16_to_cpu(pd_pg0.DevHandle)))) {
1722 raid_device->device_info =
1723 le32_to_cpu(sas_device_pg0.DeviceInfo);
1724 }
1725 }
1726
1727 kfree(vol_pg0);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301728 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06001729}
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301730/**
1731 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1732 * @ioc: per adapter object
1733 */
1734static void
1735_scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1736{
1737 Mpi2RaidVolPage1_t vol_pg1;
1738 Mpi2ConfigReply_t mpi_reply;
1739 struct _raid_device *raid_device;
1740 u16 handle;
1741 u16 ioc_status;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301742 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301743
1744 handle = 0xFFFF;
1745 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1746 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1747 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1748 MPI2_IOCSTATUS_MASK;
1749 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1750 break;
1751 handle = le16_to_cpu(vol_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301752 spin_lock_irqsave(&ioc->raid_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301753 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1754 if (raid_device)
1755 raid_device->direct_io_enabled = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301756 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301757 }
1758 return;
1759}
1760
1761
1762/**
1763 * _scsih_get_num_volumes - Get number of volumes in the ioc
1764 * @ioc: per adapter object
1765 */
1766static u8
1767_scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1768{
1769 Mpi2RaidVolPage1_t vol_pg1;
1770 Mpi2ConfigReply_t mpi_reply;
1771 u16 handle;
1772 u8 vol_cnt = 0;
1773 u16 ioc_status;
1774
1775 handle = 0xFFFF;
1776 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1777 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1778 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1779 MPI2_IOCSTATUS_MASK;
1780 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1781 break;
1782 vol_cnt++;
1783 handle = le16_to_cpu(vol_pg1.DevHandle);
1784 }
1785 return vol_cnt;
1786}
1787
1788
1789/**
1790 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1791 * @ioc: per adapter object
1792 * @raid_device: the raid_device object
1793 */
1794static void
1795_scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1796 struct _raid_device *raid_device)
1797{
1798 Mpi2RaidVolPage0_t *vol_pg0;
1799 Mpi2RaidPhysDiskPage0_t pd_pg0;
1800 Mpi2ConfigReply_t mpi_reply;
1801 u16 sz;
1802 u8 num_pds, count;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301803 unsigned long stripe_sz, block_sz;
1804 u8 stripe_exp, block_exp;
1805 u64 dev_max_lba;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301806
1807 if (!ioc->is_warpdrive)
1808 return;
1809
1810 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1811 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1812 "globally as drives are exposed\n", ioc->name);
1813 return;
1814 }
1815 if (_scsih_get_num_volumes(ioc) > 1) {
1816 _scsih_disable_ddio(ioc);
1817 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1818 "globally as number of drives > 1\n", ioc->name);
1819 return;
1820 }
1821 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1822 &num_pds)) || !num_pds) {
1823 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1824 "Failure in computing number of drives\n", ioc->name);
1825 return;
1826 }
1827
1828 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1829 sizeof(Mpi2RaidVol0PhysDisk_t));
1830 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1831 if (!vol_pg0) {
1832 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1833 "Memory allocation failure for RVPG0\n", ioc->name);
1834 return;
1835 }
1836
1837 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1838 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1839 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1840 "Failure in retrieving RVPG0\n", ioc->name);
1841 kfree(vol_pg0);
1842 return;
1843 }
1844
1845 /*
1846 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1847 * assumed for WARPDRIVE, disable direct I/O
1848 */
1849 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1850 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1851 "for the drive with handle(0x%04x): num_mem=%d, "
1852 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1853 num_pds, MPT_MAX_WARPDRIVE_PDS);
1854 kfree(vol_pg0);
1855 return;
1856 }
1857 for (count = 0; count < num_pds; count++) {
1858 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1859 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1860 vol_pg0->PhysDisk[count].PhysDiskNum) ||
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05301861 le16_to_cpu(pd_pg0.DevHandle) ==
1862 MPT2SAS_INVALID_DEVICE_HANDLE) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301863 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1864 "disabled for the drive with handle(0x%04x) member"
1865 "handle retrieval failed for member number=%d\n",
1866 ioc->name, raid_device->handle,
1867 vol_pg0->PhysDisk[count].PhysDiskNum);
1868 goto out_error;
1869 }
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301870 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1871 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
1872 if (dev_max_lba >> 32) {
1873 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1874 "disabled for the drive with handle(0x%04x) member"
1875 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1876 ioc->name, raid_device->handle,
1877 le16_to_cpu(pd_pg0.DevHandle),
1878 (unsigned long long)dev_max_lba);
1879 goto out_error;
1880 }
1881
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301882 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1883 }
1884
1885 /*
1886 * Assumption for WD: Direct I/O is not supported if the volume is
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301887 * not RAID0
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301888 */
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301889 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301890 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1891 "for the drive with handle(0x%04x): type=%d, "
1892 "s_sz=%uK, blk_size=%u\n", ioc->name,
1893 raid_device->handle, raid_device->volume_type,
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301894 (le32_to_cpu(vol_pg0->StripeSize) *
1895 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301896 le16_to_cpu(vol_pg0->BlockSize));
1897 goto out_error;
1898 }
1899
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301900 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301901 stripe_exp = find_first_bit(&stripe_sz, 32);
1902 if (stripe_exp == 32) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301903 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301904 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301905 ioc->name, raid_device->handle,
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301906 (le32_to_cpu(vol_pg0->StripeSize) *
1907 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301908 goto out_error;
1909 }
1910 raid_device->stripe_exponent = stripe_exp;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301911 block_sz = le16_to_cpu(vol_pg0->BlockSize);
1912 block_exp = find_first_bit(&block_sz, 16);
1913 if (block_exp == 16) {
1914 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1915 "for the drive with handle(0x%04x) invalid block sz %u\n",
1916 ioc->name, raid_device->handle,
1917 le16_to_cpu(vol_pg0->BlockSize));
1918 goto out_error;
1919 }
1920 raid_device->block_exponent = block_exp;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301921 raid_device->direct_io_enabled = 1;
1922
1923 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1924 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1925 /*
1926 * WARPDRIVE: Though the following fields are not used for direct IO,
1927 * stored for future purpose:
1928 */
1929 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1930 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1931 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1932
1933
1934 kfree(vol_pg0);
1935 return;
1936
1937out_error:
1938 raid_device->direct_io_enabled = 0;
1939 for (count = 0; count < num_pds; count++)
1940 raid_device->pd_handle[count] = 0;
1941 kfree(vol_pg0);
1942 return;
1943}
Eric Moore635374e2009-03-09 01:21:12 -06001944
1945/**
Kashyap, Desai84f0b042009-12-16 18:56:28 +05301946 * _scsih_enable_tlr - setting TLR flags
1947 * @ioc: per adapter object
1948 * @sdev: scsi device struct
1949 *
1950 * Enabling Transaction Layer Retries for tape devices when
1951 * vpd page 0x90 is present
1952 *
1953 */
1954static void
1955_scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1956{
1957 /* only for TAPE */
1958 if (sdev->type != TYPE_TAPE)
1959 return;
1960
1961 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1962 return;
1963
1964 sas_enable_tlr(sdev);
1965 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1966 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1967 return;
1968
1969}
1970
1971/**
Eric Moored5d135b2009-05-18 13:02:08 -06001972 * _scsih_slave_configure - device configure routine.
Eric Moore635374e2009-03-09 01:21:12 -06001973 * @sdev: scsi device struct
1974 *
1975 * Returns 0 if ok. Any other return is assumed to be an error and
1976 * the device is ignored.
1977 */
1978static int
Eric Moored5d135b2009-05-18 13:02:08 -06001979_scsih_slave_configure(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001980{
1981 struct Scsi_Host *shost = sdev->host;
1982 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1983 struct MPT2SAS_DEVICE *sas_device_priv_data;
1984 struct MPT2SAS_TARGET *sas_target_priv_data;
1985 struct _sas_device *sas_device;
1986 struct _raid_device *raid_device;
1987 unsigned long flags;
1988 int qdepth;
1989 u8 ssp_target = 0;
1990 char *ds = "";
1991 char *r_level = "";
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301992 u16 handle, volume_handle = 0;
1993 u64 volume_wwid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06001994
1995 qdepth = 1;
1996 sas_device_priv_data = sdev->hostdata;
1997 sas_device_priv_data->configured_lun = 1;
1998 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1999 sas_target_priv_data = sas_device_priv_data->sas_target;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302000 handle = sas_target_priv_data->handle;
Eric Moore635374e2009-03-09 01:21:12 -06002001
2002 /* raid volume handling */
2003 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2004
2005 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302006 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06002007 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2008 if (!raid_device) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302009 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2010 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2011 __LINE__, __func__));
2012 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002013 }
2014
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302015 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2016 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2017 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2018 __LINE__, __func__));
2019 return 1;
2020 }
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302021 /*
2022 * WARPDRIVE: Initialize the required data for Direct IO
2023 */
2024 _scsih_init_warpdrive_properties(ioc, raid_device);
2025
Eric Moore635374e2009-03-09 01:21:12 -06002026 /* RAID Queue Depth Support
2027 * IS volume = underlying qdepth of drive type, either
2028 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2029 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2030 */
2031 if (raid_device->device_info &
2032 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2033 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2034 ds = "SSP";
2035 } else {
2036 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2037 if (raid_device->device_info &
2038 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2039 ds = "SATA";
2040 else
2041 ds = "STP";
2042 }
2043
2044 switch (raid_device->volume_type) {
2045 case MPI2_RAID_VOL_TYPE_RAID0:
2046 r_level = "RAID0";
2047 break;
2048 case MPI2_RAID_VOL_TYPE_RAID1E:
2049 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
Kashyap, Desaied79f122009-08-20 13:23:49 +05302050 if (ioc->manu_pg10.OEMIdentifier &&
Kashyap, Desaic97951e2011-06-14 10:54:56 +05302051 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
Kashyap, Desaied79f122009-08-20 13:23:49 +05302052 MFG10_GF0_R10_DISPLAY) &&
2053 !(raid_device->num_pds % 2))
2054 r_level = "RAID10";
2055 else
2056 r_level = "RAID1E";
Eric Moore635374e2009-03-09 01:21:12 -06002057 break;
2058 case MPI2_RAID_VOL_TYPE_RAID1:
2059 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2060 r_level = "RAID1";
2061 break;
2062 case MPI2_RAID_VOL_TYPE_RAID10:
2063 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2064 r_level = "RAID10";
2065 break;
2066 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2067 default:
2068 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2069 r_level = "RAIDX";
2070 break;
2071 }
2072
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302073 if (!ioc->hide_ir_msg)
2074 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2075 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2076 r_level, raid_device->handle,
2077 (unsigned long long)raid_device->wwid,
2078 raid_device->num_pds, ds);
Mike Christiee881a172009-10-15 17:46:39 -07002079 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05302080 /* raid transport support */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302081 if (!ioc->is_warpdrive)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302082 _scsih_set_level(sdev, raid_device->volume_type);
Eric Moore635374e2009-03-09 01:21:12 -06002083 return 0;
2084 }
2085
2086 /* non-raid handling */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302087 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2088 if (mpt2sas_config_get_volume_handle(ioc, handle,
2089 &volume_handle)) {
2090 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2091 "failure at %s:%d/%s()!\n", ioc->name,
2092 __FILE__, __LINE__, __func__));
2093 return 1;
2094 }
2095 if (volume_handle && mpt2sas_config_get_volume_wwid(ioc,
2096 volume_handle, &volume_wwid)) {
2097 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2098 "failure at %s:%d/%s()!\n", ioc->name,
2099 __FILE__, __LINE__, __func__));
2100 return 1;
2101 }
2102 }
2103
Eric Moore635374e2009-03-09 01:21:12 -06002104 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2105 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2106 sas_device_priv_data->sas_target->sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302107 if (!sas_device) {
2108 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302109 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302110 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2111 __LINE__, __func__));
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302112 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002113 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302114 sas_device->volume_handle = volume_handle;
2115 sas_device->volume_wwid = volume_wwid;
2116 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2117 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2118 ssp_target = 1;
2119 ds = "SSP";
2120 } else {
2121 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2122 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2123 ds = "STP";
2124 else if (sas_device->device_info &
2125 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2126 ds = "SATA";
2127 }
2128 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2129 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2130 ds, sas_device->handle,
2131 (unsigned long long)sas_device->sas_address,
2132 sas_device->phy,
2133 (unsigned long long)sas_device->device_name);
2134 sdev_printk(KERN_INFO, sdev, "%s: "
2135 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2136 (unsigned long long) sas_device->enclosure_logical_id,
2137 sas_device->slot);
2138
2139 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2140 if (!ssp_target)
2141 _scsih_display_sata_capabilities(ioc, handle, sdev);
2142
Eric Moore635374e2009-03-09 01:21:12 -06002143
Mike Christiee881a172009-10-15 17:46:39 -07002144 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
Eric Moore635374e2009-03-09 01:21:12 -06002145
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302146 if (ssp_target) {
Eric Moore635374e2009-03-09 01:21:12 -06002147 sas_read_port_mode_page(sdev);
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302148 _scsih_enable_tlr(ioc, sdev);
2149 }
Eric Moore635374e2009-03-09 01:21:12 -06002150 return 0;
2151}
2152
2153/**
Eric Moored5d135b2009-05-18 13:02:08 -06002154 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
Eric Moore635374e2009-03-09 01:21:12 -06002155 * @sdev: scsi device struct
2156 * @bdev: pointer to block device context
2157 * @capacity: device size (in 512 byte sectors)
2158 * @params: three element array to place output:
2159 * params[0] number of heads (max 255)
2160 * params[1] number of sectors (max 63)
2161 * params[2] number of cylinders
2162 *
2163 * Return nothing.
2164 */
2165static int
Eric Moored5d135b2009-05-18 13:02:08 -06002166_scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
Eric Moore635374e2009-03-09 01:21:12 -06002167 sector_t capacity, int params[])
2168{
2169 int heads;
2170 int sectors;
2171 sector_t cylinders;
2172 ulong dummy;
2173
2174 heads = 64;
2175 sectors = 32;
2176
2177 dummy = heads * sectors;
2178 cylinders = capacity;
2179 sector_div(cylinders, dummy);
2180
2181 /*
2182 * Handle extended translation size for logical drives
2183 * > 1Gb
2184 */
2185 if ((ulong)capacity >= 0x200000) {
2186 heads = 255;
2187 sectors = 63;
2188 dummy = heads * sectors;
2189 cylinders = capacity;
2190 sector_div(cylinders, dummy);
2191 }
2192
2193 /* return result */
2194 params[0] = heads;
2195 params[1] = sectors;
2196 params[2] = cylinders;
2197
2198 return 0;
2199}
2200
2201/**
2202 * _scsih_response_code - translation of device response code
2203 * @ioc: per adapter object
2204 * @response_code: response code returned by the device
2205 *
2206 * Return nothing.
2207 */
2208static void
2209_scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2210{
2211 char *desc;
2212
2213 switch (response_code) {
2214 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2215 desc = "task management request completed";
2216 break;
2217 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2218 desc = "invalid frame";
2219 break;
2220 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2221 desc = "task management request not supported";
2222 break;
2223 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2224 desc = "task management request failed";
2225 break;
2226 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2227 desc = "task management request succeeded";
2228 break;
2229 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2230 desc = "invalid lun";
2231 break;
2232 case 0xA:
2233 desc = "overlapped tag attempted";
2234 break;
2235 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2236 desc = "task queued, however not sent to target";
2237 break;
2238 default:
2239 desc = "unknown";
2240 break;
2241 }
2242 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2243 ioc->name, response_code, desc);
2244}
2245
2246/**
Eric Moored5d135b2009-05-18 13:02:08 -06002247 * _scsih_tm_done - tm completion routine
Eric Moore635374e2009-03-09 01:21:12 -06002248 * @ioc: per adapter object
2249 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302250 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002251 * @reply: reply message frame(lower 32bit addr)
2252 * Context: none.
2253 *
2254 * The callback handler when using scsih_issue_tm.
2255 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302256 * Return 1 meaning mf should be freed from _base_interrupt
2257 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06002258 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302259static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302260_scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06002261{
2262 MPI2DefaultReply_t *mpi_reply;
2263
2264 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302265 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002266 if (ioc->tm_cmds.smid != smid)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302267 return 1;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05302268 mpt2sas_base_flush_reply_queues(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06002269 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2270 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2271 if (mpi_reply) {
2272 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2273 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2274 }
2275 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2276 complete(&ioc->tm_cmds.done);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302277 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002278}
2279
2280/**
2281 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2282 * @ioc: per adapter object
2283 * @handle: device handle
2284 *
2285 * During taskmangement request, we need to freeze the device queue.
2286 */
2287void
2288mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2289{
2290 struct MPT2SAS_DEVICE *sas_device_priv_data;
2291 struct scsi_device *sdev;
2292 u8 skip = 0;
2293
2294 shost_for_each_device(sdev, ioc->shost) {
2295 if (skip)
2296 continue;
2297 sas_device_priv_data = sdev->hostdata;
2298 if (!sas_device_priv_data)
2299 continue;
2300 if (sas_device_priv_data->sas_target->handle == handle) {
2301 sas_device_priv_data->sas_target->tm_busy = 1;
2302 skip = 1;
2303 ioc->ignore_loginfos = 1;
2304 }
2305 }
2306}
2307
2308/**
2309 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2310 * @ioc: per adapter object
2311 * @handle: device handle
2312 *
2313 * During taskmangement request, we need to freeze the device queue.
2314 */
2315void
2316mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2317{
2318 struct MPT2SAS_DEVICE *sas_device_priv_data;
2319 struct scsi_device *sdev;
2320 u8 skip = 0;
2321
2322 shost_for_each_device(sdev, ioc->shost) {
2323 if (skip)
2324 continue;
2325 sas_device_priv_data = sdev->hostdata;
2326 if (!sas_device_priv_data)
2327 continue;
2328 if (sas_device_priv_data->sas_target->handle == handle) {
2329 sas_device_priv_data->sas_target->tm_busy = 0;
2330 skip = 1;
2331 ioc->ignore_loginfos = 0;
2332 }
2333 }
2334}
2335
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302336
Eric Moore635374e2009-03-09 01:21:12 -06002337/**
2338 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2339 * @ioc: per adapter struct
2340 * @device_handle: device handle
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302341 * @channel: the channel assigned by the OS
2342 * @id: the id assigned by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002343 * @lun: lun number
2344 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2345 * @smid_task: smid assigned to the task
2346 * @timeout: timeout in seconds
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302347 * @serial_number: the serial_number from scmd
2348 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302349 * Context: user
Eric Moore635374e2009-03-09 01:21:12 -06002350 *
2351 * A generic API for sending task management requests to firmware.
2352 *
Eric Moore635374e2009-03-09 01:21:12 -06002353 * The callback index is set inside `ioc->tm_cb_idx`.
2354 *
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302355 * Return SUCCESS or FAILED.
Eric Moore635374e2009-03-09 01:21:12 -06002356 */
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302357int
2358mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2359 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302360 unsigned long serial_number, enum mutex_type m_type)
Eric Moore635374e2009-03-09 01:21:12 -06002361{
2362 Mpi2SCSITaskManagementRequest_t *mpi_request;
2363 Mpi2SCSITaskManagementReply_t *mpi_reply;
2364 u16 smid = 0;
2365 u32 ioc_state;
2366 unsigned long timeleft;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302367 struct scsiio_tracker *scsi_lookup = NULL;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302368 int rc;
Eric Moore635374e2009-03-09 01:21:12 -06002369
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302370 if (m_type == TM_MUTEX_ON)
2371 mutex_lock(&ioc->tm_cmds.mutex);
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302372 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2373 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2374 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302375 rc = FAILED;
2376 goto err_out;
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302377 }
2378
Eric Moore3cb54692010-07-08 14:44:34 -06002379 if (ioc->shost_recovery || ioc->remove_host ||
2380 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06002381 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2382 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302383 rc = FAILED;
2384 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002385 }
Eric Moore635374e2009-03-09 01:21:12 -06002386
2387 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2388 if (ioc_state & MPI2_DOORBELL_USED) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302389 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
Eric Moore635374e2009-03-09 01:21:12 -06002390 "active!\n", ioc->name));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302391 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302392 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302393 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302394 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002395 }
2396
2397 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2398 mpt2sas_base_fault_info(ioc, ioc_state &
2399 MPI2_DOORBELL_DATA_MASK);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302400 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302401 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302402 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302403 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002404 }
2405
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302406 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06002407 if (!smid) {
2408 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2409 ioc->name, __func__);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302410 rc = FAILED;
2411 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002412 }
2413
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302414 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2415 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2416
Eric Moore635374e2009-03-09 01:21:12 -06002417 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302418 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2419 smid_task));
Eric Moore635374e2009-03-09 01:21:12 -06002420 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2421 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2422 ioc->tm_cmds.smid = smid;
2423 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302424 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
Eric Moore635374e2009-03-09 01:21:12 -06002425 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2426 mpi_request->DevHandle = cpu_to_le16(handle);
2427 mpi_request->TaskType = type;
2428 mpi_request->TaskMID = cpu_to_le16(smid_task);
2429 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2430 mpt2sas_scsih_set_tm_flag(ioc, handle);
Kashyap, Desai5b768582009-08-20 13:24:31 +05302431 init_completion(&ioc->tm_cmds.done);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302432 mpt2sas_base_put_smid_hi_priority(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06002433 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
Eric Moore635374e2009-03-09 01:21:12 -06002434 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2435 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2436 ioc->name, __func__);
2437 _debug_dump_mf(mpi_request,
2438 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302439 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302440 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302441 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302442 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302443 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2444 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2445 goto err_out;
2446 }
Eric Moore635374e2009-03-09 01:21:12 -06002447 }
2448
2449 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2450 mpi_reply = ioc->tm_cmds.reply;
2451 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2452 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2453 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2454 le32_to_cpu(mpi_reply->IOCLogInfo),
2455 le32_to_cpu(mpi_reply->TerminationCount)));
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302456 if (ioc->logging_level & MPT_DEBUG_TM) {
Eric Moore635374e2009-03-09 01:21:12 -06002457 _scsih_response_code(ioc, mpi_reply->ResponseCode);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302458 if (mpi_reply->IOCStatus)
2459 _debug_dump_mf(mpi_request,
2460 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2461 }
Eric Moore635374e2009-03-09 01:21:12 -06002462 }
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302463
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302464 switch (type) {
2465 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302466 rc = SUCCESS;
2467 if (scsi_lookup->scmd == NULL)
2468 break;
2469 rc = FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302470 break;
2471
2472 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2473 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2474 rc = FAILED;
2475 else
2476 rc = SUCCESS;
2477 break;
2478
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302479 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302480 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2481 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2482 rc = FAILED;
2483 else
2484 rc = SUCCESS;
2485 break;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302486 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2487 rc = SUCCESS;
2488 break;
2489 default:
2490 rc = FAILED;
2491 break;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302492 }
2493
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302494 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2495 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302496 if (m_type == TM_MUTEX_ON)
2497 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302498
2499 return rc;
2500
2501 err_out:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302502 if (m_type == TM_MUTEX_ON)
2503 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302504 return rc;
Eric Moore635374e2009-03-09 01:21:12 -06002505}
2506
2507/**
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302508 * _scsih_tm_display_info - displays info about the device
2509 * @ioc: per adapter struct
2510 * @scmd: pointer to scsi command object
2511 *
2512 * Called by task management callback handlers.
2513 */
2514static void
2515_scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2516{
2517 struct scsi_target *starget = scmd->device->sdev_target;
2518 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2519 struct _sas_device *sas_device = NULL;
2520 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302521 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302522
2523 if (!priv_target)
2524 return;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302525 if (ioc->hide_ir_msg)
2526 device_str = "WarpDrive";
2527 else
2528 device_str = "volume";
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302529
2530 scsi_print_command(scmd);
2531 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302532 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2533 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2534 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302535 } else {
2536 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2537 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2538 priv_target->sas_address);
2539 if (sas_device) {
2540 if (priv_target->flags &
2541 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2542 starget_printk(KERN_INFO, starget,
2543 "volume handle(0x%04x), "
2544 "volume wwid(0x%016llx)\n",
2545 sas_device->volume_handle,
2546 (unsigned long long)sas_device->volume_wwid);
2547 }
2548 starget_printk(KERN_INFO, starget,
2549 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2550 sas_device->handle,
2551 (unsigned long long)sas_device->sas_address,
2552 sas_device->phy);
2553 starget_printk(KERN_INFO, starget,
2554 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2555 (unsigned long long)sas_device->enclosure_logical_id,
2556 sas_device->slot);
2557 }
2558 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2559 }
2560}
2561
2562/**
Eric Moored5d135b2009-05-18 13:02:08 -06002563 * _scsih_abort - eh threads main abort routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302564 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002565 *
2566 * Returns SUCCESS if command aborted else FAILED
2567 */
2568static int
Eric Moored5d135b2009-05-18 13:02:08 -06002569_scsih_abort(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002570{
2571 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2572 struct MPT2SAS_DEVICE *sas_device_priv_data;
2573 u16 smid;
2574 u16 handle;
2575 int r;
Eric Moore635374e2009-03-09 01:21:12 -06002576
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302577 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2578 "scmd(%p)\n", scmd);
2579 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002580
2581 sas_device_priv_data = scmd->device->hostdata;
2582 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302583 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2584 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002585 scmd->result = DID_NO_CONNECT << 16;
2586 scmd->scsi_done(scmd);
2587 r = SUCCESS;
2588 goto out;
2589 }
2590
2591 /* search for the command */
2592 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2593 if (!smid) {
2594 scmd->result = DID_RESET << 16;
2595 r = SUCCESS;
2596 goto out;
2597 }
2598
2599 /* for hidden raid components and volumes this is not supported */
2600 if (sas_device_priv_data->sas_target->flags &
2601 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2602 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2603 scmd->result = DID_RESET << 16;
2604 r = FAILED;
2605 goto out;
2606 }
2607
Kashyap, Desaifa7f3162009-09-23 17:26:58 +05302608 mpt2sas_halt_firmware(ioc);
2609
Eric Moore635374e2009-03-09 01:21:12 -06002610 handle = sas_device_priv_data->sas_target->handle;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302611 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2612 scmd->device->id, scmd->device->lun,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302613 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
2614 scmd->serial_number, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002615
2616 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302617 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2618 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002619 return r;
2620}
2621
Eric Moore635374e2009-03-09 01:21:12 -06002622/**
Eric Moored5d135b2009-05-18 13:02:08 -06002623 * _scsih_dev_reset - eh threads main device reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302624 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002625 *
2626 * Returns SUCCESS if command aborted else FAILED
2627 */
2628static int
Eric Moored5d135b2009-05-18 13:02:08 -06002629_scsih_dev_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002630{
2631 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2632 struct MPT2SAS_DEVICE *sas_device_priv_data;
2633 struct _sas_device *sas_device;
2634 unsigned long flags;
2635 u16 handle;
2636 int r;
2637
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302638 struct scsi_target *starget = scmd->device->sdev_target;
2639
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302640 starget_printk(KERN_INFO, starget, "attempting device reset! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302641 "scmd(%p)\n", scmd);
2642 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002643
2644 sas_device_priv_data = scmd->device->hostdata;
2645 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302646 starget_printk(KERN_INFO, starget, "device been deleted! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302647 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002648 scmd->result = DID_NO_CONNECT << 16;
2649 scmd->scsi_done(scmd);
2650 r = SUCCESS;
2651 goto out;
2652 }
2653
2654 /* for hidden raid components obtain the volume_handle */
2655 handle = 0;
2656 if (sas_device_priv_data->sas_target->flags &
2657 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2658 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2659 sas_device = _scsih_sas_device_find_by_handle(ioc,
2660 sas_device_priv_data->sas_target->handle);
2661 if (sas_device)
2662 handle = sas_device->volume_handle;
2663 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2664 } else
2665 handle = sas_device_priv_data->sas_target->handle;
2666
2667 if (!handle) {
2668 scmd->result = DID_RESET << 16;
2669 r = FAILED;
2670 goto out;
2671 }
2672
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302673 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2674 scmd->device->id, scmd->device->lun,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302675 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, 0,
2676 TM_MUTEX_ON);
Eric Moore993e0da2009-05-18 13:00:45 -06002677
2678 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302679 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2680 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002681 return r;
2682}
2683
2684/**
Eric Moored5d135b2009-05-18 13:02:08 -06002685 * _scsih_target_reset - eh threads main target reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302686 * @scmd: pointer to scsi command object
Eric Moore993e0da2009-05-18 13:00:45 -06002687 *
2688 * Returns SUCCESS if command aborted else FAILED
2689 */
2690static int
Eric Moored5d135b2009-05-18 13:02:08 -06002691_scsih_target_reset(struct scsi_cmnd *scmd)
Eric Moore993e0da2009-05-18 13:00:45 -06002692{
2693 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2694 struct MPT2SAS_DEVICE *sas_device_priv_data;
2695 struct _sas_device *sas_device;
2696 unsigned long flags;
2697 u16 handle;
2698 int r;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302699 struct scsi_target *starget = scmd->device->sdev_target;
Eric Moore993e0da2009-05-18 13:00:45 -06002700
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302701 starget_printk(KERN_INFO, starget, "attempting target reset! "
2702 "scmd(%p)\n", scmd);
2703 _scsih_tm_display_info(ioc, scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002704
2705 sas_device_priv_data = scmd->device->hostdata;
2706 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302707 starget_printk(KERN_INFO, starget, "target been deleted! "
2708 "scmd(%p)\n", scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002709 scmd->result = DID_NO_CONNECT << 16;
2710 scmd->scsi_done(scmd);
2711 r = SUCCESS;
2712 goto out;
2713 }
2714
2715 /* for hidden raid components obtain the volume_handle */
2716 handle = 0;
2717 if (sas_device_priv_data->sas_target->flags &
2718 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2719 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2720 sas_device = _scsih_sas_device_find_by_handle(ioc,
2721 sas_device_priv_data->sas_target->handle);
2722 if (sas_device)
2723 handle = sas_device->volume_handle;
2724 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2725 } else
2726 handle = sas_device_priv_data->sas_target->handle;
2727
2728 if (!handle) {
2729 scmd->result = DID_RESET << 16;
2730 r = FAILED;
2731 goto out;
2732 }
2733
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302734 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2735 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302736 30, 0, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002737
2738 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302739 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2740 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002741 return r;
2742}
2743
2744/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302745 * _scsih_host_reset - eh threads main host reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302746 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002747 *
2748 * Returns SUCCESS if command aborted else FAILED
2749 */
2750static int
Eric Moored5d135b2009-05-18 13:02:08 -06002751_scsih_host_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002752{
2753 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2754 int r, retval;
2755
2756 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2757 ioc->name, scmd);
2758 scsi_print_command(scmd);
2759
2760 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2761 FORCE_BIG_HAMMER);
2762 r = (retval < 0) ? FAILED : SUCCESS;
2763 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2764 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2765
2766 return r;
2767}
2768
2769/**
2770 * _scsih_fw_event_add - insert and queue up fw_event
2771 * @ioc: per adapter object
2772 * @fw_event: object describing the event
2773 * Context: This function will acquire ioc->fw_event_lock.
2774 *
2775 * This adds the firmware event object into link list, then queues it up to
2776 * be processed from user context.
2777 *
2778 * Return nothing.
2779 */
2780static void
2781_scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2782{
2783 unsigned long flags;
2784
2785 if (ioc->firmware_event_thread == NULL)
2786 return;
2787
2788 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2789 list_add_tail(&fw_event->list, &ioc->fw_event_list);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302790 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2791 queue_delayed_work(ioc->firmware_event_thread,
2792 &fw_event->delayed_work, 0);
Eric Moore635374e2009-03-09 01:21:12 -06002793 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2794}
2795
2796/**
2797 * _scsih_fw_event_free - delete fw_event
2798 * @ioc: per adapter object
2799 * @fw_event: object describing the event
2800 * Context: This function will acquire ioc->fw_event_lock.
2801 *
2802 * This removes firmware event object from link list, frees associated memory.
2803 *
2804 * Return nothing.
2805 */
2806static void
2807_scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2808 *fw_event)
2809{
2810 unsigned long flags;
2811
2812 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2813 list_del(&fw_event->list);
2814 kfree(fw_event->event_data);
2815 kfree(fw_event);
2816 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2817}
2818
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302819
Eric Moore635374e2009-03-09 01:21:12 -06002820/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302821 * _scsih_error_recovery_delete_devices - remove devices not responding
Eric Moore635374e2009-03-09 01:21:12 -06002822 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06002823 *
2824 * Return nothing.
2825 */
2826static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302827_scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06002828{
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302829 struct fw_event_work *fw_event;
2830
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302831 if (ioc->is_driver_loading)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302832 return;
Dan Carpenter181a9d72011-11-04 21:25:01 +03002833
2834 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2835 if (!fw_event)
2836 return;
2837
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302838 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2839 fw_event->ioc = ioc;
2840 _scsih_fw_event_add(ioc, fw_event);
2841}
2842
2843/**
2844 * mpt2sas_port_enable_complete - port enable completed (fake event)
2845 * @ioc: per adapter object
2846 *
2847 * Return nothing.
2848 */
2849void
2850mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2851{
2852 struct fw_event_work *fw_event;
2853
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302854 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2855 if (!fw_event)
2856 return;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302857 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302858 fw_event->ioc = ioc;
2859 _scsih_fw_event_add(ioc, fw_event);
2860}
2861
2862/**
2863 * _scsih_fw_event_cleanup_queue - cleanup event queue
2864 * @ioc: per adapter object
2865 *
2866 * Walk the firmware event queue, either killing timers, or waiting
2867 * for outstanding events to complete
2868 *
2869 * Return nothing.
2870 */
2871static void
2872_scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2873{
2874 struct fw_event_work *fw_event, *next;
2875
2876 if (list_empty(&ioc->fw_event_list) ||
2877 !ioc->firmware_event_thread || in_interrupt())
Eric Moore635374e2009-03-09 01:21:12 -06002878 return;
2879
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302880 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2881 if (cancel_delayed_work(&fw_event->delayed_work)) {
2882 _scsih_fw_event_free(ioc, fw_event);
2883 continue;
2884 }
2885 fw_event->cancel_pending_work = 1;
2886 }
Eric Moore635374e2009-03-09 01:21:12 -06002887}
2888
Eric Moore635374e2009-03-09 01:21:12 -06002889/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302890 * _scsih_ublock_io_all_device - unblock every device
2891 * @ioc: per adapter object
2892 *
2893 * change the device state from block to running
2894 */
2895static void
2896_scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2897{
2898 struct MPT2SAS_DEVICE *sas_device_priv_data;
2899 struct scsi_device *sdev;
2900
2901 shost_for_each_device(sdev, ioc->shost) {
2902 sas_device_priv_data = sdev->hostdata;
2903 if (!sas_device_priv_data)
2904 continue;
2905 if (!sas_device_priv_data->block)
2906 continue;
2907 sas_device_priv_data->block = 0;
2908 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2909 "handle(0x%04x)\n",
2910 sas_device_priv_data->sas_target->handle));
Mike Christie5d9fb5c2012-05-17 23:56:57 -05002911 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302912 }
2913}
2914/**
Eric Moore635374e2009-03-09 01:21:12 -06002915 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2916 * @ioc: per adapter object
2917 * @handle: device handle
2918 *
2919 * During device pull we need to appropiately set the sdev state.
2920 */
2921static void
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302922_scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06002923{
2924 struct MPT2SAS_DEVICE *sas_device_priv_data;
2925 struct scsi_device *sdev;
2926
2927 shost_for_each_device(sdev, ioc->shost) {
2928 sas_device_priv_data = sdev->hostdata;
2929 if (!sas_device_priv_data)
2930 continue;
2931 if (!sas_device_priv_data->block)
2932 continue;
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302933 if (sas_device_priv_data->sas_target->sas_address ==
2934 sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06002935 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2936 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05302937 "sas address(0x%016llx)\n", ioc->name,
2938 (unsigned long long)sas_address));
Eric Moore635374e2009-03-09 01:21:12 -06002939 sas_device_priv_data->block = 0;
Mike Christie5d9fb5c2012-05-17 23:56:57 -05002940 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
Eric Moore635374e2009-03-09 01:21:12 -06002941 }
2942 }
2943}
2944
2945/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302946 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2947 * @ioc: per adapter object
2948 * @handle: device handle
2949 *
2950 * During device pull we need to appropiately set the sdev state.
2951 */
2952static void
2953_scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2954{
2955 struct MPT2SAS_DEVICE *sas_device_priv_data;
2956 struct scsi_device *sdev;
2957
2958 shost_for_each_device(sdev, ioc->shost) {
2959 sas_device_priv_data = sdev->hostdata;
2960 if (!sas_device_priv_data)
2961 continue;
2962 if (sas_device_priv_data->block)
2963 continue;
2964 sas_device_priv_data->block = 1;
2965 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2966 "handle(0x%04x)\n",
2967 sas_device_priv_data->sas_target->handle));
2968 scsi_internal_device_block(sdev);
2969 }
2970}
2971
2972
2973/**
Eric Moore635374e2009-03-09 01:21:12 -06002974 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2975 * @ioc: per adapter object
2976 * @handle: device handle
2977 *
2978 * During device pull we need to appropiately set the sdev state.
2979 */
2980static void
2981_scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2982{
2983 struct MPT2SAS_DEVICE *sas_device_priv_data;
2984 struct scsi_device *sdev;
2985
2986 shost_for_each_device(sdev, ioc->shost) {
2987 sas_device_priv_data = sdev->hostdata;
2988 if (!sas_device_priv_data)
2989 continue;
2990 if (sas_device_priv_data->block)
2991 continue;
2992 if (sas_device_priv_data->sas_target->handle == handle) {
2993 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2994 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2995 "handle(0x%04x)\n", ioc->name, handle));
2996 sas_device_priv_data->block = 1;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05302997 scsi_internal_device_block(sdev);
Eric Moore635374e2009-03-09 01:21:12 -06002998 }
2999 }
3000}
3001
3002/**
3003 * _scsih_block_io_to_children_attached_to_ex
3004 * @ioc: per adapter object
3005 * @sas_expander: the sas_device object
3006 *
3007 * This routine set sdev state to SDEV_BLOCK for all devices
3008 * attached to this expander. This function called when expander is
3009 * pulled.
3010 */
3011static void
3012_scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
3013 struct _sas_node *sas_expander)
3014{
3015 struct _sas_port *mpt2sas_port;
3016 struct _sas_device *sas_device;
3017 struct _sas_node *expander_sibling;
3018 unsigned long flags;
3019
3020 if (!sas_expander)
3021 return;
3022
3023 list_for_each_entry(mpt2sas_port,
3024 &sas_expander->sas_port_list, port_list) {
3025 if (mpt2sas_port->remote_identify.device_type ==
3026 SAS_END_DEVICE) {
3027 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3028 sas_device =
3029 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3030 mpt2sas_port->remote_identify.sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303031 if (sas_device)
3032 set_bit(sas_device->handle,
3033 ioc->blocking_handles);
Eric Moore635374e2009-03-09 01:21:12 -06003034 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06003035 }
3036 }
3037
3038 list_for_each_entry(mpt2sas_port,
3039 &sas_expander->sas_port_list, port_list) {
3040
3041 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05303042 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06003043 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05303044 SAS_FANOUT_EXPANDER_DEVICE) {
Eric Moore635374e2009-03-09 01:21:12 -06003045 expander_sibling =
3046 mpt2sas_scsih_expander_find_by_sas_address(
3047 ioc, mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06003048 _scsih_block_io_to_children_attached_to_ex(ioc,
3049 expander_sibling);
3050 }
3051 }
3052}
3053
3054/**
3055 * _scsih_block_io_to_children_attached_directly
3056 * @ioc: per adapter object
3057 * @event_data: topology change event data
3058 *
3059 * This routine set sdev state to SDEV_BLOCK for all devices
3060 * direct attached during device pull.
3061 */
3062static void
3063_scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3064 Mpi2EventDataSasTopologyChangeList_t *event_data)
3065{
3066 int i;
3067 u16 handle;
3068 u16 reason_code;
3069 u8 phy_number;
3070
3071 for (i = 0; i < event_data->NumEntries; i++) {
3072 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3073 if (!handle)
3074 continue;
3075 phy_number = event_data->StartPhyNum + i;
3076 reason_code = event_data->PHY[i].PhyStatus &
3077 MPI2_EVENT_SAS_TOPO_RC_MASK;
3078 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3079 _scsih_block_io_device(ioc, handle);
3080 }
3081}
3082
3083/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303084 * _scsih_tm_tr_send - send task management request
3085 * @ioc: per adapter object
3086 * @handle: device handle
3087 * Context: interrupt time.
3088 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003089 * This code is to initiate the device removal handshake protocol
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303090 * with controller firmware. This function will issue target reset
3091 * using high priority request queue. It will send a sas iounit
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003092 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303093 *
3094 * This is designed to send muliple task management request at the same
3095 * time to the fifo. If the fifo is full, we will append the request,
3096 * and process it in a future completion.
3097 */
3098static void
3099_scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3100{
3101 Mpi2SCSITaskManagementRequest_t *mpi_request;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303102 u16 smid;
3103 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303104 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3105 u64 sas_address = 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303106 unsigned long flags;
3107 struct _tr_list *delayed_tr;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303108 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303109
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303110 if (ioc->remove_host) {
3111 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3112 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3113 return;
3114 } else if (ioc->pci_error_recovery) {
3115 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3116 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3117 handle));
3118 return;
3119 }
3120 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3121 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3122 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3123 "operational: handle(0x%04x)\n", __func__, ioc->name,
3124 handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303125 return;
3126 }
3127
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303128 /* if PD, then return */
3129 if (test_bit(handle, ioc->pd_handles))
3130 return;
3131
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303132 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3133 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303134 if (sas_device && sas_device->starget &&
3135 sas_device->starget->hostdata) {
3136 sas_target_priv_data = sas_device->starget->hostdata;
3137 sas_target_priv_data->deleted = 1;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303138 sas_address = sas_device->sas_address;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303139 }
3140 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303141
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303142 if (sas_target_priv_data) {
3143 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3144 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3145 (unsigned long long)sas_address));
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05303146 _scsih_ublock_io_device(ioc, sas_address);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05303147 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303148 }
3149
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303150 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3151 if (!smid) {
3152 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3153 if (!delayed_tr)
3154 return;
3155 INIT_LIST_HEAD(&delayed_tr->list);
3156 delayed_tr->handle = handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303157 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3158 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3159 "DELAYED:tr:handle(0x%04x), (open)\n",
3160 ioc->name, handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303161 return;
3162 }
3163
Kashyap, Desai1278b112010-03-09 17:34:13 +05303164 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3165 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3166 ioc->tm_tr_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303167 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3168 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3169 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3170 mpi_request->DevHandle = cpu_to_le16(handle);
3171 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303172 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3173}
3174
3175
3176
3177/**
3178 * _scsih_sas_control_complete - completion routine
3179 * @ioc: per adapter object
3180 * @smid: system request message index
3181 * @msix_index: MSIX table index supplied by the OS
3182 * @reply: reply message frame(lower 32bit addr)
3183 * Context: interrupt time.
3184 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003185 * This is the sas iounit control completion routine.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303186 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003187 * handshake protocol with controller firmware.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303188 *
3189 * Return 1 meaning mf should be freed from _base_interrupt
3190 * 0 means the mf is freed from this function.
3191 */
3192static u8
3193_scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3194 u8 msix_index, u32 reply)
3195{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303196 Mpi2SasIoUnitControlReply_t *mpi_reply =
3197 mpt2sas_base_get_reply_virt_addr(ioc, reply);
nagalakshmi.nandigama@lsi.com298c794d2012-03-20 12:07:17 +05303198 if (likely(mpi_reply)) {
3199 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3200 "sc_complete:handle(0x%04x), (open) "
3201 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3202 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3203 le16_to_cpu(mpi_reply->IOCStatus),
3204 le32_to_cpu(mpi_reply->IOCLogInfo)));
3205 } else {
3206 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3207 ioc->name, __FILE__, __LINE__, __func__);
3208 }
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303209 return 1;
3210}
3211
3212/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303213 * _scsih_tm_tr_volume_send - send target reset request for volumes
3214 * @ioc: per adapter object
3215 * @handle: device handle
3216 * Context: interrupt time.
3217 *
3218 * This is designed to send muliple task management request at the same
3219 * time to the fifo. If the fifo is full, we will append the request,
3220 * and process it in a future completion.
3221 */
3222static void
3223_scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3224{
3225 Mpi2SCSITaskManagementRequest_t *mpi_request;
3226 u16 smid;
3227 struct _tr_list *delayed_tr;
3228
Eric Moore3cb54692010-07-08 14:44:34 -06003229 if (ioc->shost_recovery || ioc->remove_host ||
3230 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303231 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3232 "progress!\n", __func__, ioc->name));
3233 return;
3234 }
3235
3236 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3237 if (!smid) {
3238 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3239 if (!delayed_tr)
3240 return;
3241 INIT_LIST_HEAD(&delayed_tr->list);
3242 delayed_tr->handle = handle;
3243 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3244 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3245 "DELAYED:tr:handle(0x%04x), (open)\n",
3246 ioc->name, handle));
3247 return;
3248 }
3249
3250 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3251 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3252 ioc->tm_tr_volume_cb_idx));
3253 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3254 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3255 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3256 mpi_request->DevHandle = cpu_to_le16(handle);
3257 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3258 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3259}
3260
3261/**
3262 * _scsih_tm_volume_tr_complete - target reset completion
3263 * @ioc: per adapter object
3264 * @smid: system request message index
3265 * @msix_index: MSIX table index supplied by the OS
3266 * @reply: reply message frame(lower 32bit addr)
3267 * Context: interrupt time.
3268 *
3269 * Return 1 meaning mf should be freed from _base_interrupt
3270 * 0 means the mf is freed from this function.
3271 */
3272static u8
3273_scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3274 u8 msix_index, u32 reply)
3275{
3276 u16 handle;
3277 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3278 Mpi2SCSITaskManagementReply_t *mpi_reply =
3279 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3280
Eric Moore3cb54692010-07-08 14:44:34 -06003281 if (ioc->shost_recovery || ioc->remove_host ||
3282 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303283 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3284 "progress!\n", __func__, ioc->name));
3285 return 1;
3286 }
nagalakshmi.nandigama@lsi.com298c794d2012-03-20 12:07:17 +05303287 if (unlikely(!mpi_reply)) {
3288 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3289 ioc->name, __FILE__, __LINE__, __func__);
3290 return 1;
3291 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303292 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3293 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3294 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3295 dewtprintk(ioc, printk("spurious interrupt: "
3296 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3297 le16_to_cpu(mpi_reply->DevHandle), smid));
3298 return 0;
3299 }
3300
3301 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3302 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3303 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3304 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3305 le32_to_cpu(mpi_reply->IOCLogInfo),
3306 le32_to_cpu(mpi_reply->TerminationCount)));
3307
3308 return _scsih_check_for_pending_tm(ioc, smid);
3309}
3310
3311/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303312 * _scsih_tm_tr_complete -
3313 * @ioc: per adapter object
3314 * @smid: system request message index
3315 * @msix_index: MSIX table index supplied by the OS
3316 * @reply: reply message frame(lower 32bit addr)
3317 * Context: interrupt time.
3318 *
3319 * This is the target reset completion routine.
3320 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003321 * handshake protocol with controller firmware.
3322 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303323 *
3324 * Return 1 meaning mf should be freed from _base_interrupt
3325 * 0 means the mf is freed from this function.
3326 */
3327static u8
3328_scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3329 u32 reply)
3330{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303331 u16 handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303332 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303333 Mpi2SCSITaskManagementReply_t *mpi_reply =
3334 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3335 Mpi2SasIoUnitControlRequest_t *mpi_request;
3336 u16 smid_sas_ctrl;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303337 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303338
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303339 if (ioc->remove_host) {
3340 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3341 "removed\n", __func__, ioc->name));
3342 return 1;
3343 } else if (ioc->pci_error_recovery) {
3344 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3345 "error recovery\n", __func__, ioc->name));
3346 return 1;
3347 }
3348 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3349 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3350 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3351 "operational\n", __func__, ioc->name));
Kashyap, Desai1278b112010-03-09 17:34:13 +05303352 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303353 }
nagalakshmi.nandigama@lsi.com298c794d2012-03-20 12:07:17 +05303354 if (unlikely(!mpi_reply)) {
3355 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3356 ioc->name, __FILE__, __LINE__, __func__);
3357 return 1;
3358 }
Kashyap, Desai1278b112010-03-09 17:34:13 +05303359 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3360 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3361 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3362 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3363 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3364 le16_to_cpu(mpi_reply->DevHandle), smid));
3365 return 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303366 }
3367
Kashyap, Desai1278b112010-03-09 17:34:13 +05303368 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3369 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3370 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3371 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3372 le32_to_cpu(mpi_reply->IOCLogInfo),
3373 le32_to_cpu(mpi_reply->TerminationCount)));
3374
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303375 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3376 if (!smid_sas_ctrl) {
3377 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3378 ioc->name, __func__);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303379 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303380 }
3381
Kashyap, Desai1278b112010-03-09 17:34:13 +05303382 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3383 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3384 ioc->tm_sas_control_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303385 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3386 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3387 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3388 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303389 mpi_request->DevHandle = mpi_request_tm->DevHandle;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303390 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303391
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303392 return _scsih_check_for_pending_tm(ioc, smid);
3393}
3394
3395/**
3396 * _scsih_check_for_pending_tm - check for pending task management
3397 * @ioc: per adapter object
3398 * @smid: system request message index
3399 *
3400 * This will check delayed target reset list, and feed the
3401 * next reqeust.
3402 *
3403 * Return 1 meaning mf should be freed from _base_interrupt
3404 * 0 means the mf is freed from this function.
3405 */
3406static u8
3407_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3408{
3409 struct _tr_list *delayed_tr;
3410
3411 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3412 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3413 struct _tr_list, list);
3414 mpt2sas_base_free_smid(ioc, smid);
3415 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3416 list_del(&delayed_tr->list);
3417 kfree(delayed_tr);
3418 return 0;
3419 }
3420
Kashyap, Desai1278b112010-03-09 17:34:13 +05303421 if (!list_empty(&ioc->delayed_tr_list)) {
3422 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3423 struct _tr_list, list);
3424 mpt2sas_base_free_smid(ioc, smid);
3425 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3426 list_del(&delayed_tr->list);
3427 kfree(delayed_tr);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303428 return 0;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303429 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303430
Kashyap, Desai1278b112010-03-09 17:34:13 +05303431 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303432}
3433
3434/**
Eric Moore635374e2009-03-09 01:21:12 -06003435 * _scsih_check_topo_delete_events - sanity check on topo events
3436 * @ioc: per adapter object
3437 * @event_data: the event data payload
3438 *
3439 * This routine added to better handle cable breaker.
3440 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003441 * This handles the case where driver receives multiple expander
Eric Moore635374e2009-03-09 01:21:12 -06003442 * add and delete events in a single shot. When there is a delete event
3443 * the routine will void any pending add events waiting in the event queue.
3444 *
3445 * Return nothing.
3446 */
3447static void
3448_scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3449 Mpi2EventDataSasTopologyChangeList_t *event_data)
3450{
3451 struct fw_event_work *fw_event;
3452 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3453 u16 expander_handle;
3454 struct _sas_node *sas_expander;
3455 unsigned long flags;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303456 int i, reason_code;
3457 u16 handle;
3458
3459 for (i = 0 ; i < event_data->NumEntries; i++) {
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303460 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3461 if (!handle)
3462 continue;
3463 reason_code = event_data->PHY[i].PhyStatus &
3464 MPI2_EVENT_SAS_TOPO_RC_MASK;
3465 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3466 _scsih_tm_tr_send(ioc, handle);
3467 }
Eric Moore635374e2009-03-09 01:21:12 -06003468
3469 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3470 if (expander_handle < ioc->sas_hba.num_phys) {
3471 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3472 return;
3473 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303474 if (event_data->ExpStatus ==
3475 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3476 /* put expander attached devices into blocking state */
Eric Moore635374e2009-03-09 01:21:12 -06003477 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3478 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3479 expander_handle);
Eric Moore635374e2009-03-09 01:21:12 -06003480 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303481 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3482 do {
3483 handle = find_first_bit(ioc->blocking_handles,
3484 ioc->facts.MaxDevHandle);
3485 if (handle < ioc->facts.MaxDevHandle)
3486 _scsih_block_io_device(ioc, handle);
3487 } while (test_and_clear_bit(handle, ioc->blocking_handles));
Eric Moore635374e2009-03-09 01:21:12 -06003488 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3489 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3490
3491 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3492 return;
3493
3494 /* mark ignore flag for pending events */
3495 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3496 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3497 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3498 fw_event->ignore)
3499 continue;
3500 local_event_data = fw_event->event_data;
3501 if (local_event_data->ExpStatus ==
3502 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3503 local_event_data->ExpStatus ==
3504 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3505 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3506 expander_handle) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303507 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06003508 "setting ignoring flag\n", ioc->name));
3509 fw_event->ignore = 1;
3510 }
3511 }
3512 }
3513 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3514}
3515
3516/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303517 * _scsih_set_volume_delete_flag - setting volume delete flag
3518 * @ioc: per adapter object
3519 * @handle: device handle
3520 *
3521 * This
3522 * Return nothing.
3523 */
3524static void
3525_scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3526{
3527 struct _raid_device *raid_device;
3528 struct MPT2SAS_TARGET *sas_target_priv_data;
3529 unsigned long flags;
3530
3531 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3532 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3533 if (raid_device && raid_device->starget &&
3534 raid_device->starget->hostdata) {
3535 sas_target_priv_data =
3536 raid_device->starget->hostdata;
3537 sas_target_priv_data->deleted = 1;
3538 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3539 "setting delete flag: handle(0x%04x), "
3540 "wwid(0x%016llx)\n", ioc->name, handle,
3541 (unsigned long long) raid_device->wwid));
3542 }
3543 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3544}
3545
3546/**
3547 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3548 * @handle: input handle
3549 * @a: handle for volume a
3550 * @b: handle for volume b
3551 *
3552 * IR firmware only supports two raid volumes. The purpose of this
3553 * routine is to set the volume handle in either a or b. When the given
3554 * input handle is non-zero, or when a and b have not been set before.
3555 */
3556static void
3557_scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3558{
3559 if (!handle || handle == *a || handle == *b)
3560 return;
3561 if (!*a)
3562 *a = handle;
3563 else if (!*b)
3564 *b = handle;
3565}
3566
3567/**
3568 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3569 * @ioc: per adapter object
3570 * @event_data: the event data payload
3571 * Context: interrupt time.
3572 *
3573 * This routine will send target reset to volume, followed by target
3574 * resets to the PDs. This is called when a PD has been removed, or
3575 * volume has been deleted or removed. When the target reset is sent
3576 * to volume, the PD target resets need to be queued to start upon
3577 * completion of the volume target reset.
3578 *
3579 * Return nothing.
3580 */
3581static void
3582_scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3583 Mpi2EventDataIrConfigChangeList_t *event_data)
3584{
3585 Mpi2EventIrConfigElement_t *element;
3586 int i;
3587 u16 handle, volume_handle, a, b;
3588 struct _tr_list *delayed_tr;
3589
3590 a = 0;
3591 b = 0;
3592
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303593 if (ioc->is_warpdrive)
3594 return;
3595
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303596 /* Volume Resets for Deleted or Removed */
3597 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3598 for (i = 0; i < event_data->NumElements; i++, element++) {
3599 if (element->ReasonCode ==
3600 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3601 element->ReasonCode ==
3602 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3603 volume_handle = le16_to_cpu(element->VolDevHandle);
3604 _scsih_set_volume_delete_flag(ioc, volume_handle);
3605 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3606 }
3607 }
3608
3609 /* Volume Resets for UNHIDE events */
3610 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3611 for (i = 0; i < event_data->NumElements; i++, element++) {
3612 if (le32_to_cpu(event_data->Flags) &
3613 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3614 continue;
3615 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3616 volume_handle = le16_to_cpu(element->VolDevHandle);
3617 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3618 }
3619 }
3620
3621 if (a)
3622 _scsih_tm_tr_volume_send(ioc, a);
3623 if (b)
3624 _scsih_tm_tr_volume_send(ioc, b);
3625
3626 /* PD target resets */
3627 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3628 for (i = 0; i < event_data->NumElements; i++, element++) {
3629 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3630 continue;
3631 handle = le16_to_cpu(element->PhysDiskDevHandle);
3632 volume_handle = le16_to_cpu(element->VolDevHandle);
3633 clear_bit(handle, ioc->pd_handles);
3634 if (!volume_handle)
3635 _scsih_tm_tr_send(ioc, handle);
3636 else if (volume_handle == a || volume_handle == b) {
3637 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3638 BUG_ON(!delayed_tr);
3639 INIT_LIST_HEAD(&delayed_tr->list);
3640 delayed_tr->handle = handle;
3641 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3642 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3643 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3644 handle));
3645 } else
3646 _scsih_tm_tr_send(ioc, handle);
3647 }
3648}
3649
3650
3651/**
3652 * _scsih_check_volume_delete_events - set delete flag for volumes
3653 * @ioc: per adapter object
3654 * @event_data: the event data payload
3655 * Context: interrupt time.
3656 *
3657 * This will handle the case when the cable connected to entire volume is
3658 * pulled. We will take care of setting the deleted flag so normal IO will
3659 * not be sent.
3660 *
3661 * Return nothing.
3662 */
3663static void
3664_scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3665 Mpi2EventDataIrVolume_t *event_data)
3666{
3667 u32 state;
3668
3669 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3670 return;
3671 state = le32_to_cpu(event_data->NewValue);
3672 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3673 MPI2_RAID_VOL_STATE_FAILED)
3674 _scsih_set_volume_delete_flag(ioc,
3675 le16_to_cpu(event_data->VolDevHandle));
3676}
3677
3678/**
Eric Moore635374e2009-03-09 01:21:12 -06003679 * _scsih_flush_running_cmds - completing outstanding commands.
3680 * @ioc: per adapter object
3681 *
3682 * The flushing out of all pending scmd commands following host reset,
3683 * where all IO is dropped to the floor.
3684 *
3685 * Return nothing.
3686 */
3687static void
3688_scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3689{
3690 struct scsi_cmnd *scmd;
3691 u16 smid;
3692 u16 count = 0;
3693
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303694 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05303695 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003696 if (!scmd)
3697 continue;
3698 count++;
3699 mpt2sas_base_free_smid(ioc, smid);
3700 scsi_dma_unmap(scmd);
Eric Moore3cb54692010-07-08 14:44:34 -06003701 if (ioc->pci_error_recovery)
3702 scmd->result = DID_NO_CONNECT << 16;
3703 else
3704 scmd->result = DID_RESET << 16;
Eric Moore635374e2009-03-09 01:21:12 -06003705 scmd->scsi_done(scmd);
3706 }
3707 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3708 ioc->name, count));
3709}
3710
3711/**
Eric Moore3c621b32009-05-18 12:59:41 -06003712 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3713 * @scmd: pointer to scsi command object
3714 * @mpi_request: pointer to the SCSI_IO reqest message frame
3715 *
3716 * Supporting protection 1 and 3.
3717 *
3718 * Returns nothing
3719 */
3720static void
3721_scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3722{
3723 u16 eedp_flags;
3724 unsigned char prot_op = scsi_get_prot_op(scmd);
3725 unsigned char prot_type = scsi_get_prot_type(scmd);
3726
Eric Moored334aa72010-04-22 10:47:40 -06003727 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
Eric Moore3c621b32009-05-18 12:59:41 -06003728 return;
3729
3730 if (prot_op == SCSI_PROT_READ_STRIP)
3731 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3732 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3733 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3734 else
3735 return;
3736
Eric Moore3c621b32009-05-18 12:59:41 -06003737 switch (prot_type) {
3738 case SCSI_PROT_DIF_TYPE1:
Martin K. Petersen756aca72011-05-18 00:45:22 -04003739 case SCSI_PROT_DIF_TYPE2:
Eric Moore3c621b32009-05-18 12:59:41 -06003740
3741 /*
3742 * enable ref/guard checking
3743 * auto increment ref tag
3744 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303745 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
Eric Moore3c621b32009-05-18 12:59:41 -06003746 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3747 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3748 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3749 cpu_to_be32(scsi_get_lba(scmd));
Eric Moored334aa72010-04-22 10:47:40 -06003750 break;
Eric Moore3c621b32009-05-18 12:59:41 -06003751
Eric Moore3c621b32009-05-18 12:59:41 -06003752 case SCSI_PROT_DIF_TYPE3:
3753
3754 /*
3755 * enable guard checking
3756 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303757 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
Eric Moore3c621b32009-05-18 12:59:41 -06003758 break;
3759 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05303760 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3761 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
Eric Moore3c621b32009-05-18 12:59:41 -06003762}
3763
3764/**
3765 * _scsih_eedp_error_handling - return sense code for EEDP errors
3766 * @scmd: pointer to scsi command object
3767 * @ioc_status: ioc status
3768 *
3769 * Returns nothing
3770 */
3771static void
3772_scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3773{
3774 u8 ascq;
Eric Moore3c621b32009-05-18 12:59:41 -06003775
3776 switch (ioc_status) {
3777 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3778 ascq = 0x01;
3779 break;
3780 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3781 ascq = 0x02;
3782 break;
3783 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3784 ascq = 0x03;
3785 break;
3786 default:
3787 ascq = 0x00;
3788 break;
3789 }
3790
Martin K. Petersen9b5cd132012-08-28 14:29:36 -04003791 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq);
3792 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
Eric Moore3c621b32009-05-18 12:59:41 -06003793 SAM_STAT_CHECK_CONDITION;
3794}
3795
3796/**
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303797 * _scsih_scsi_direct_io_get - returns direct io flag
3798 * @ioc: per adapter object
3799 * @smid: system request message index
3800 *
3801 * Returns the smid stored scmd pointer.
3802 */
3803static inline u8
3804_scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3805{
3806 return ioc->scsi_lookup[smid - 1].direct_io;
3807}
3808
3809/**
3810 * _scsih_scsi_direct_io_set - sets direct io flag
3811 * @ioc: per adapter object
3812 * @smid: system request message index
3813 * @direct_io: Zero or non-zero value to set in the direct_io flag
3814 *
3815 * Returns Nothing.
3816 */
3817static inline void
3818_scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3819{
3820 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3821}
3822
3823
3824/**
3825 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3826 * @ioc: per adapter object
3827 * @scmd: pointer to scsi command object
3828 * @raid_device: pointer to raid device data structure
3829 * @mpi_request: pointer to the SCSI_IO reqest message frame
3830 * @smid: system request message index
3831 *
3832 * Returns nothing
3833 */
3834static void
3835_scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3836 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3837 u16 smid)
3838{
3839 u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size;
3840 u32 stripe_sz, stripe_exp;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303841 u8 num_pds, *cdb_ptr, i;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303842 u8 cdb0 = scmd->cmnd[0];
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303843 u64 v_llba;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303844
3845 /*
3846 * Try Direct I/O to RAID memeber disks
3847 */
3848 if (cdb0 == READ_16 || cdb0 == READ_10 ||
3849 cdb0 == WRITE_16 || cdb0 == WRITE_10) {
3850 cdb_ptr = mpi_request->CDB.CDB32;
3851
3852 if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4]
3853 | cdb_ptr[5])) {
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303854 io_size = scsi_bufflen(scmd) >>
3855 raid_device->block_exponent;
3856 i = (cdb0 < READ_16) ? 2 : 6;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303857 /* get virtual lba */
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303858 v_lba = be32_to_cpu(*(__be32 *)(&cdb_ptr[i]));
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303859
3860 if (((u64)v_lba + (u64)io_size - 1) <=
3861 (u32)raid_device->max_lba) {
3862 stripe_sz = raid_device->stripe_sz;
3863 stripe_exp = raid_device->stripe_exponent;
3864 stripe_off = v_lba & (stripe_sz - 1);
3865
3866 /* Check whether IO falls within a stripe */
3867 if ((stripe_off + io_size) <= stripe_sz) {
3868 num_pds = raid_device->num_pds;
3869 p_lba = v_lba >> stripe_exp;
3870 stripe_unit = p_lba / num_pds;
3871 column = p_lba % num_pds;
3872 p_lba = (stripe_unit << stripe_exp) +
3873 stripe_off;
3874 mpi_request->DevHandle =
3875 cpu_to_le16(raid_device->
3876 pd_handle[column]);
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303877 (*(__be32 *)(&cdb_ptr[i])) =
3878 cpu_to_be32(p_lba);
3879 /*
3880 * WD: To indicate this I/O is directI/O
3881 */
3882 _scsih_scsi_direct_io_set(ioc, smid, 1);
3883 }
3884 }
3885 } else {
3886 io_size = scsi_bufflen(scmd) >>
3887 raid_device->block_exponent;
3888 /* get virtual lba */
3889 v_llba = be64_to_cpu(*(__be64 *)(&cdb_ptr[2]));
3890
3891 if ((v_llba + (u64)io_size - 1) <=
3892 raid_device->max_lba) {
3893 stripe_sz = raid_device->stripe_sz;
3894 stripe_exp = raid_device->stripe_exponent;
3895 stripe_off = (u32) (v_llba & (stripe_sz - 1));
3896
3897 /* Check whether IO falls within a stripe */
3898 if ((stripe_off + io_size) <= stripe_sz) {
3899 num_pds = raid_device->num_pds;
3900 p_lba = (u32)(v_llba >> stripe_exp);
3901 stripe_unit = p_lba / num_pds;
3902 column = p_lba % num_pds;
3903 p_lba = (stripe_unit << stripe_exp) +
3904 stripe_off;
3905 mpi_request->DevHandle =
3906 cpu_to_le16(raid_device->
3907 pd_handle[column]);
3908 (*(__be64 *)(&cdb_ptr[2])) =
3909 cpu_to_be64((u64)p_lba);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303910 /*
3911 * WD: To indicate this I/O is directI/O
3912 */
3913 _scsih_scsi_direct_io_set(ioc, smid, 1);
3914 }
3915 }
3916 }
3917 }
3918}
3919
3920/**
Eric Moored5d135b2009-05-18 13:02:08 -06003921 * _scsih_qcmd - main scsi request entry point
Eric Moore635374e2009-03-09 01:21:12 -06003922 * @scmd: pointer to scsi command object
3923 * @done: function pointer to be invoked on completion
3924 *
3925 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3926 *
3927 * Returns 0 on success. If there's a failure, return either:
3928 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3929 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3930 */
3931static int
Jeff Garzikf2812332010-11-16 02:10:29 -05003932_scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
Eric Moore635374e2009-03-09 01:21:12 -06003933{
3934 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3935 struct MPT2SAS_DEVICE *sas_device_priv_data;
3936 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303937 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06003938 Mpi2SCSIIORequest_t *mpi_request;
3939 u32 mpi_control;
3940 u16 smid;
Eric Moore635374e2009-03-09 01:21:12 -06003941
3942 scmd->scsi_done = done;
3943 sas_device_priv_data = scmd->device->hostdata;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303944 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Eric Moore635374e2009-03-09 01:21:12 -06003945 scmd->result = DID_NO_CONNECT << 16;
3946 scmd->scsi_done(scmd);
3947 return 0;
3948 }
3949
Kashyap, Desai78215782011-06-14 10:57:08 +05303950 if (ioc->pci_error_recovery || ioc->remove_host) {
Eric Moore3cb54692010-07-08 14:44:34 -06003951 scmd->result = DID_NO_CONNECT << 16;
3952 scmd->scsi_done(scmd);
3953 return 0;
3954 }
3955
Eric Moore635374e2009-03-09 01:21:12 -06003956 sas_target_priv_data = sas_device_priv_data->sas_target;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303957 /* invalid device handle */
3958 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
Eric Moore635374e2009-03-09 01:21:12 -06003959 scmd->result = DID_NO_CONNECT << 16;
3960 scmd->scsi_done(scmd);
3961 return 0;
3962 }
3963
Kashyap, Desai130b9582010-04-08 17:54:32 +05303964 /* host recovery or link resets sent via IOCTLs */
3965 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
Eric Moore635374e2009-03-09 01:21:12 -06003966 return SCSI_MLQUEUE_HOST_BUSY;
Uwe Kleine-König65155b32010-06-11 12:17:01 +02003967 /* device busy with task management */
Kashyap, Desai130b9582010-04-08 17:54:32 +05303968 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3969 return SCSI_MLQUEUE_DEVICE_BUSY;
3970 /* device has been deleted */
3971 else if (sas_target_priv_data->deleted) {
3972 scmd->result = DID_NO_CONNECT << 16;
3973 scmd->scsi_done(scmd);
3974 return 0;
3975 }
Eric Moore635374e2009-03-09 01:21:12 -06003976
3977 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3978 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3979 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3980 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3981 else
3982 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3983
3984 /* set tags */
3985 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3986 if (scmd->device->tagged_supported) {
3987 if (scmd->device->ordered_tags)
3988 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3989 else
3990 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3991 } else
3992/* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3993/* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3994 */
3995 mpi_control |= (0x500);
3996
3997 } else
3998 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303999 /* Make sure Device is not raid volume.
4000 * We do not expose raid functionality to upper layer for warpdrive.
4001 */
4002 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Eric Moored334aa72010-04-22 10:47:40 -06004003 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
Eric Moore635374e2009-03-09 01:21:12 -06004004 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
4005
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304006 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06004007 if (!smid) {
4008 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
4009 ioc->name, __func__);
4010 goto out;
4011 }
4012 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4013 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
Eric Moore3c621b32009-05-18 12:59:41 -06004014 _scsih_setup_eedp(scmd, mpi_request);
Eric Moored334aa72010-04-22 10:47:40 -06004015 if (scmd->cmd_len == 32)
4016 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
Eric Moore635374e2009-03-09 01:21:12 -06004017 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4018 if (sas_device_priv_data->sas_target->flags &
4019 MPT_TARGET_FLAGS_RAID_COMPONENT)
4020 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4021 else
4022 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4023 mpi_request->DevHandle =
4024 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4025 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
4026 mpi_request->Control = cpu_to_le32(mpi_control);
4027 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4028 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4029 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4030 mpi_request->SenseBufferLowAddress =
Kashyap, Desaiec9472c2009-09-23 17:34:13 +05304031 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004032 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
4033 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
4034 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304035 mpi_request->VF_ID = 0; /* TODO */
4036 mpi_request->VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004037 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4038 mpi_request->LUN);
4039 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4040
4041 if (!mpi_request->DataLength) {
4042 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
4043 } else {
4044 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
4045 mpt2sas_base_free_smid(ioc, smid);
4046 goto out;
4047 }
4048 }
4049
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304050 raid_device = sas_target_priv_data->raid_device;
4051 if (raid_device && raid_device->direct_io_enabled)
4052 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4053 smid);
4054
Kashyap, Desai58287fd2010-03-17 16:27:25 +05304055 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
4056 mpt2sas_base_put_smid_scsi_io(ioc, smid,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304057 le16_to_cpu(mpi_request->DevHandle));
Kashyap, Desai58287fd2010-03-17 16:27:25 +05304058 else
4059 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004060 return 0;
4061
4062 out:
4063 return SCSI_MLQUEUE_HOST_BUSY;
4064}
4065
Jeff Garzikf2812332010-11-16 02:10:29 -05004066static DEF_SCSI_QCMD(_scsih_qcmd)
4067
Eric Moore635374e2009-03-09 01:21:12 -06004068/**
4069 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4070 * @sense_buffer: sense data returned by target
4071 * @data: normalized skey/asc/ascq
4072 *
4073 * Return nothing.
4074 */
4075static void
4076_scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4077{
4078 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4079 /* descriptor format */
4080 data->skey = sense_buffer[1] & 0x0F;
4081 data->asc = sense_buffer[2];
4082 data->ascq = sense_buffer[3];
4083 } else {
4084 /* fixed format */
4085 data->skey = sense_buffer[2] & 0x0F;
4086 data->asc = sense_buffer[12];
4087 data->ascq = sense_buffer[13];
4088 }
4089}
4090
4091#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4092/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004093 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
Eric Moore635374e2009-03-09 01:21:12 -06004094 * @ioc: per adapter object
4095 * @scmd: pointer to scsi command object
4096 * @mpi_reply: reply mf payload returned from firmware
4097 *
4098 * scsi_status - SCSI Status code returned from target device
4099 * scsi_state - state info associated with SCSI_IO determined by ioc
4100 * ioc_status - ioc supplied status info
4101 *
4102 * Return nothing.
4103 */
4104static void
4105_scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4106 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4107{
4108 u32 response_info;
4109 u8 *response_bytes;
4110 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4111 MPI2_IOCSTATUS_MASK;
4112 u8 scsi_state = mpi_reply->SCSIState;
4113 u8 scsi_status = mpi_reply->SCSIStatus;
4114 char *desc_ioc_state = NULL;
4115 char *desc_scsi_status = NULL;
4116 char *desc_scsi_state = ioc->tmp_string;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304117 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304118 struct _sas_device *sas_device = NULL;
4119 unsigned long flags;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304120 struct scsi_target *starget = scmd->device->sdev_target;
4121 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304122 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304123
4124 if (!priv_target)
4125 return;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304126
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304127 if (ioc->hide_ir_msg)
4128 device_str = "WarpDrive";
4129 else
4130 device_str = "volume";
4131
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304132 if (log_info == 0x31170000)
4133 return;
Eric Moore635374e2009-03-09 01:21:12 -06004134
4135 switch (ioc_status) {
4136 case MPI2_IOCSTATUS_SUCCESS:
4137 desc_ioc_state = "success";
4138 break;
4139 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4140 desc_ioc_state = "invalid function";
4141 break;
4142 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4143 desc_ioc_state = "scsi recovered error";
4144 break;
4145 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4146 desc_ioc_state = "scsi invalid dev handle";
4147 break;
4148 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4149 desc_ioc_state = "scsi device not there";
4150 break;
4151 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4152 desc_ioc_state = "scsi data overrun";
4153 break;
4154 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4155 desc_ioc_state = "scsi data underrun";
4156 break;
4157 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4158 desc_ioc_state = "scsi io data error";
4159 break;
4160 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4161 desc_ioc_state = "scsi protocol error";
4162 break;
4163 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4164 desc_ioc_state = "scsi task terminated";
4165 break;
4166 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4167 desc_ioc_state = "scsi residual mismatch";
4168 break;
4169 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4170 desc_ioc_state = "scsi task mgmt failed";
4171 break;
4172 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4173 desc_ioc_state = "scsi ioc terminated";
4174 break;
4175 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4176 desc_ioc_state = "scsi ext terminated";
4177 break;
Eric Moore3c621b32009-05-18 12:59:41 -06004178 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4179 desc_ioc_state = "eedp guard error";
4180 break;
4181 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4182 desc_ioc_state = "eedp ref tag error";
4183 break;
4184 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4185 desc_ioc_state = "eedp app tag error";
4186 break;
Eric Moore635374e2009-03-09 01:21:12 -06004187 default:
4188 desc_ioc_state = "unknown";
4189 break;
4190 }
4191
4192 switch (scsi_status) {
4193 case MPI2_SCSI_STATUS_GOOD:
4194 desc_scsi_status = "good";
4195 break;
4196 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4197 desc_scsi_status = "check condition";
4198 break;
4199 case MPI2_SCSI_STATUS_CONDITION_MET:
4200 desc_scsi_status = "condition met";
4201 break;
4202 case MPI2_SCSI_STATUS_BUSY:
4203 desc_scsi_status = "busy";
4204 break;
4205 case MPI2_SCSI_STATUS_INTERMEDIATE:
4206 desc_scsi_status = "intermediate";
4207 break;
4208 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4209 desc_scsi_status = "intermediate condmet";
4210 break;
4211 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4212 desc_scsi_status = "reservation conflict";
4213 break;
4214 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4215 desc_scsi_status = "command terminated";
4216 break;
4217 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4218 desc_scsi_status = "task set full";
4219 break;
4220 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4221 desc_scsi_status = "aca active";
4222 break;
4223 case MPI2_SCSI_STATUS_TASK_ABORTED:
4224 desc_scsi_status = "task aborted";
4225 break;
4226 default:
4227 desc_scsi_status = "unknown";
4228 break;
4229 }
4230
4231 desc_scsi_state[0] = '\0';
4232 if (!scsi_state)
4233 desc_scsi_state = " ";
4234 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4235 strcat(desc_scsi_state, "response info ");
4236 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4237 strcat(desc_scsi_state, "state terminated ");
4238 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4239 strcat(desc_scsi_state, "no status ");
4240 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4241 strcat(desc_scsi_state, "autosense failed ");
4242 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4243 strcat(desc_scsi_state, "autosense valid ");
4244
4245 scsi_print_command(scmd);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304246
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304247 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304248 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4249 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304250 } else {
4251 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4252 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4253 priv_target->sas_address);
4254 if (sas_device) {
4255 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4256 "phy(%d)\n", ioc->name, sas_device->sas_address,
4257 sas_device->phy);
4258 printk(MPT2SAS_WARN_FMT
4259 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4260 ioc->name, sas_device->enclosure_logical_id,
4261 sas_device->slot);
4262 }
4263 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304264 }
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304265
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304266 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4267 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4268 desc_ioc_state, ioc_status, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004269 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4270 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4271 scsi_get_resid(scmd));
4272 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4273 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4274 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4275 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4276 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4277 scsi_status, desc_scsi_state, scsi_state);
4278
4279 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4280 struct sense_info data;
4281 _scsih_normalize_sense(scmd->sense_buffer, &data);
4282 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
Kashyap, Desaie94f6742010-03-17 16:24:52 +05304283 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4284 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
Eric Moore635374e2009-03-09 01:21:12 -06004285 }
4286
4287 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4288 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4289 response_bytes = (u8 *)&response_info;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304290 _scsih_response_code(ioc, response_bytes[0]);
Eric Moore635374e2009-03-09 01:21:12 -06004291 }
4292}
4293#endif
4294
4295/**
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304296 * _scsih_turn_on_fault_led - illuminate Fault LED
Eric Moore635374e2009-03-09 01:21:12 -06004297 * @ioc: per adapter object
4298 * @handle: device handle
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304299 * Context: process
4300 *
4301 * Return nothing.
4302 */
4303static void
4304_scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4305{
4306 Mpi2SepReply_t mpi_reply;
4307 Mpi2SepRequest_t mpi_request;
4308
4309 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4310 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4311 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4312 mpi_request.SlotStatus =
4313 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4314 mpi_request.DevHandle = cpu_to_le16(handle);
4315 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4316 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4317 &mpi_request)) != 0) {
4318 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4319 __FILE__, __LINE__, __func__);
4320 return;
4321 }
4322
4323 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4324 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4325 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4326 le16_to_cpu(mpi_reply.IOCStatus),
4327 le32_to_cpu(mpi_reply.IOCLogInfo)));
4328 return;
4329 }
4330}
4331
4332/**
4333 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4334 * @ioc: per adapter object
4335 * @handle: device handle
4336 * Context: interrupt.
4337 *
4338 * Return nothing.
4339 */
4340static void
4341_scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4342{
4343 struct fw_event_work *fw_event;
4344
4345 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4346 if (!fw_event)
4347 return;
4348 fw_event->event = MPT2SAS_TURN_ON_FAULT_LED;
4349 fw_event->device_handle = handle;
4350 fw_event->ioc = ioc;
4351 _scsih_fw_event_add(ioc, fw_event);
4352}
4353
4354/**
4355 * _scsih_smart_predicted_fault - process smart errors
4356 * @ioc: per adapter object
4357 * @handle: device handle
4358 * Context: interrupt.
Eric Moore635374e2009-03-09 01:21:12 -06004359 *
4360 * Return nothing.
4361 */
4362static void
4363_scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4364{
Eric Moore635374e2009-03-09 01:21:12 -06004365 struct scsi_target *starget;
4366 struct MPT2SAS_TARGET *sas_target_priv_data;
4367 Mpi2EventNotificationReply_t *event_reply;
4368 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4369 struct _sas_device *sas_device;
4370 ssize_t sz;
4371 unsigned long flags;
4372
4373 /* only handle non-raid devices */
4374 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4375 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4376 if (!sas_device) {
4377 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4378 return;
4379 }
4380 starget = sas_device->starget;
4381 sas_target_priv_data = starget->hostdata;
4382
4383 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4384 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4385 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4386 return;
4387 }
4388 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4389 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4390
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304391 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4392 _scsih_send_event_to_turn_on_fault_led(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06004393
4394 /* insert into event log */
4395 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4396 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
Anton Blanchardf6a290b42011-11-07 22:05:21 +11004397 event_reply = kzalloc(sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06004398 if (!event_reply) {
4399 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4400 ioc->name, __FILE__, __LINE__, __func__);
4401 return;
4402 }
4403
4404 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4405 event_reply->Event =
4406 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4407 event_reply->MsgLength = sz/4;
4408 event_reply->EventDataLength =
4409 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4410 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4411 event_reply->EventData;
4412 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4413 event_data->ASC = 0x5D;
4414 event_data->DevHandle = cpu_to_le16(handle);
4415 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4416 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4417 kfree(event_reply);
4418}
4419
4420/**
Eric Moored5d135b2009-05-18 13:02:08 -06004421 * _scsih_io_done - scsi request callback
Eric Moore635374e2009-03-09 01:21:12 -06004422 * @ioc: per adapter object
4423 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304424 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06004425 * @reply: reply message frame(lower 32bit addr)
4426 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304427 * Callback handler when using _scsih_qcmd.
Eric Moore635374e2009-03-09 01:21:12 -06004428 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304429 * Return 1 meaning mf should be freed from _base_interrupt
4430 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06004431 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304432static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304433_scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06004434{
4435 Mpi2SCSIIORequest_t *mpi_request;
4436 Mpi2SCSIIOReply_t *mpi_reply;
4437 struct scsi_cmnd *scmd;
4438 u16 ioc_status;
4439 u32 xfer_cnt;
4440 u8 scsi_state;
4441 u8 scsi_status;
4442 u32 log_info;
4443 struct MPT2SAS_DEVICE *sas_device_priv_data;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304444 u32 response_code = 0;
Kashyap, Desai82a45252011-07-05 12:40:23 +05304445 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06004446
4447 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05304448 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004449 if (scmd == NULL)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304450 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004451
4452 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4453
4454 if (mpi_reply == NULL) {
4455 scmd->result = DID_OK << 16;
4456 goto out;
4457 }
4458
4459 sas_device_priv_data = scmd->device->hostdata;
4460 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4461 sas_device_priv_data->sas_target->deleted) {
4462 scmd->result = DID_NO_CONNECT << 16;
4463 goto out;
4464 }
nagalakshmi.nandigama@lsi.com4da7af92011-12-01 07:53:02 +05304465 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304466 /*
4467 * WARPDRIVE: If direct_io is set then it is directIO,
4468 * the failed direct I/O should be redirected to volume
4469 */
nagalakshmi.nandigama@lsi.com4da7af92011-12-01 07:53:02 +05304470 if (_scsih_scsi_direct_io_get(ioc, smid) &&
4471 ((ioc_status & MPI2_IOCSTATUS_MASK)
4472 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
Kashyap, Desai82a45252011-07-05 12:40:23 +05304473 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4474 ioc->scsi_lookup[smid - 1].scmd = scmd;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304475 _scsih_scsi_direct_io_set(ioc, smid, 0);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05304476 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304477 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4478 mpi_request->DevHandle =
4479 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4480 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4481 sas_device_priv_data->sas_target->handle);
4482 return 0;
4483 }
4484
Eric Moore635374e2009-03-09 01:21:12 -06004485
4486 /* turning off TLR */
Kashyap, Desai9982f592009-09-23 17:23:07 +05304487 scsi_state = mpi_reply->SCSIState;
4488 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4489 response_code =
4490 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
Eric Moore635374e2009-03-09 01:21:12 -06004491 if (!sas_device_priv_data->tlr_snoop_check) {
4492 sas_device_priv_data->tlr_snoop_check++;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304493 /* Make sure Device is not raid volume.
4494 * We do not expose raid functionality to upper layer for warpdrive.
4495 */
4496 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Kashyap, Desai3ed21522010-02-17 16:08:36 +05304497 sas_is_tlr_enabled(scmd->device) &&
Kashyap, Desai84f0b042009-12-16 18:56:28 +05304498 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4499 sas_disable_tlr(scmd->device);
4500 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4501 }
Eric Moore635374e2009-03-09 01:21:12 -06004502 }
4503
4504 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4505 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
Eric Moore635374e2009-03-09 01:21:12 -06004506 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4507 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4508 else
4509 log_info = 0;
4510 ioc_status &= MPI2_IOCSTATUS_MASK;
Eric Moore635374e2009-03-09 01:21:12 -06004511 scsi_status = mpi_reply->SCSIStatus;
4512
4513 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4514 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4515 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4516 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4517 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4518 }
4519
4520 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4521 struct sense_info data;
4522 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4523 smid);
Eric Moore0d04df92009-04-21 15:38:43 -06004524 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
Eric Moore635374e2009-03-09 01:21:12 -06004525 le32_to_cpu(mpi_reply->SenseCount));
Eric Moore0d04df92009-04-21 15:38:43 -06004526 memcpy(scmd->sense_buffer, sense_data, sz);
Eric Moore635374e2009-03-09 01:21:12 -06004527 _scsih_normalize_sense(scmd->sense_buffer, &data);
4528 /* failure prediction threshold exceeded */
4529 if (data.asc == 0x5D)
4530 _scsih_smart_predicted_fault(ioc,
4531 le16_to_cpu(mpi_reply->DevHandle));
4532 }
4533
4534 switch (ioc_status) {
4535 case MPI2_IOCSTATUS_BUSY:
4536 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4537 scmd->result = SAM_STAT_BUSY;
4538 break;
4539
4540 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4541 scmd->result = DID_NO_CONNECT << 16;
4542 break;
4543
4544 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4545 if (sas_device_priv_data->block) {
Kashyap, Desaie4e7c7e2009-09-23 17:33:14 +05304546 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4547 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06004548 }
nagalakshmi.nandigama@lsi.com3ade1ca2011-12-01 07:42:40 +05304549 scmd->result = DID_SOFT_ERROR << 16;
4550 break;
Eric Moore635374e2009-03-09 01:21:12 -06004551 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4552 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4553 scmd->result = DID_RESET << 16;
4554 break;
4555
4556 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4557 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4558 scmd->result = DID_SOFT_ERROR << 16;
4559 else
4560 scmd->result = (DID_OK << 16) | scsi_status;
4561 break;
4562
4563 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4564 scmd->result = (DID_OK << 16) | scsi_status;
4565
4566 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4567 break;
4568
4569 if (xfer_cnt < scmd->underflow) {
4570 if (scsi_status == SAM_STAT_BUSY)
4571 scmd->result = SAM_STAT_BUSY;
4572 else
4573 scmd->result = DID_SOFT_ERROR << 16;
4574 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4575 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4576 scmd->result = DID_SOFT_ERROR << 16;
4577 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4578 scmd->result = DID_RESET << 16;
4579 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4580 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4581 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4582 scmd->result = (DRIVER_SENSE << 24) |
4583 SAM_STAT_CHECK_CONDITION;
4584 scmd->sense_buffer[0] = 0x70;
4585 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4586 scmd->sense_buffer[12] = 0x20;
4587 scmd->sense_buffer[13] = 0;
4588 }
4589 break;
4590
4591 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4592 scsi_set_resid(scmd, 0);
4593 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4594 case MPI2_IOCSTATUS_SUCCESS:
4595 scmd->result = (DID_OK << 16) | scsi_status;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304596 if (response_code ==
4597 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4598 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4599 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
Eric Moore635374e2009-03-09 01:21:12 -06004600 scmd->result = DID_SOFT_ERROR << 16;
4601 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4602 scmd->result = DID_RESET << 16;
4603 break;
4604
Eric Moore3c621b32009-05-18 12:59:41 -06004605 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4606 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4607 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4608 _scsih_eedp_error_handling(scmd, ioc_status);
4609 break;
Eric Moore635374e2009-03-09 01:21:12 -06004610 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4611 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4612 case MPI2_IOCSTATUS_INVALID_SGL:
4613 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4614 case MPI2_IOCSTATUS_INVALID_FIELD:
4615 case MPI2_IOCSTATUS_INVALID_STATE:
4616 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4617 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4618 default:
4619 scmd->result = DID_SOFT_ERROR << 16;
4620 break;
4621
4622 }
4623
4624#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4625 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4626 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4627#endif
4628
4629 out:
4630 scsi_dma_unmap(scmd);
4631 scmd->scsi_done(scmd);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304632 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004633}
4634
4635/**
Eric Moore635374e2009-03-09 01:21:12 -06004636 * _scsih_sas_host_refresh - refreshing sas host object contents
4637 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06004638 * Context: user
4639 *
4640 * During port enable, fw will send topology events for every device. Its
4641 * possible that the handles may change from the previous setting, so this
4642 * code keeping handles updating if changed.
4643 *
4644 * Return nothing.
4645 */
4646static void
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304647_scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06004648{
4649 u16 sz;
4650 u16 ioc_status;
4651 int i;
4652 Mpi2ConfigReply_t mpi_reply;
4653 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304654 u16 attached_handle;
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304655 u8 link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06004656
4657 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4658 "updating handles for sas_host(0x%016llx)\n",
4659 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4660
4661 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4662 * sizeof(Mpi2SasIOUnit0PhyData_t));
4663 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4664 if (!sas_iounit_pg0) {
4665 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4666 ioc->name, __FILE__, __LINE__, __func__);
4667 return;
4668 }
Eric Moore635374e2009-03-09 01:21:12 -06004669
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304670 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4671 sas_iounit_pg0, sz)) != 0)
4672 goto out;
4673 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4674 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4675 goto out;
4676 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304677 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304678 if (i == 0)
4679 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4680 PhyData[0].ControllerDevHandle);
4681 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4682 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4683 AttachedDevHandle);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304684 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4685 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304686 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304687 attached_handle, i, link_rate);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304688 }
Eric Moore635374e2009-03-09 01:21:12 -06004689 out:
4690 kfree(sas_iounit_pg0);
4691}
4692
4693/**
4694 * _scsih_sas_host_add - create sas host object
4695 * @ioc: per adapter object
4696 *
4697 * Creating host side data object, stored in ioc->sas_hba
4698 *
4699 * Return nothing.
4700 */
4701static void
4702_scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4703{
4704 int i;
4705 Mpi2ConfigReply_t mpi_reply;
4706 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4707 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4708 Mpi2SasPhyPage0_t phy_pg0;
4709 Mpi2SasDevicePage0_t sas_device_pg0;
4710 Mpi2SasEnclosurePage0_t enclosure_pg0;
4711 u16 ioc_status;
4712 u16 sz;
4713 u16 device_missing_delay;
4714
4715 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4716 if (!ioc->sas_hba.num_phys) {
4717 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4718 ioc->name, __FILE__, __LINE__, __func__);
4719 return;
4720 }
4721
4722 /* sas_iounit page 0 */
4723 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4724 sizeof(Mpi2SasIOUnit0PhyData_t));
4725 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4726 if (!sas_iounit_pg0) {
4727 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4728 ioc->name, __FILE__, __LINE__, __func__);
4729 return;
4730 }
4731 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4732 sas_iounit_pg0, sz))) {
4733 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4734 ioc->name, __FILE__, __LINE__, __func__);
4735 goto out;
4736 }
4737 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4738 MPI2_IOCSTATUS_MASK;
4739 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4740 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4741 ioc->name, __FILE__, __LINE__, __func__);
4742 goto out;
4743 }
4744
4745 /* sas_iounit page 1 */
4746 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4747 sizeof(Mpi2SasIOUnit1PhyData_t));
4748 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4749 if (!sas_iounit_pg1) {
4750 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4751 ioc->name, __FILE__, __LINE__, __func__);
4752 goto out;
4753 }
4754 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4755 sas_iounit_pg1, sz))) {
4756 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4757 ioc->name, __FILE__, __LINE__, __func__);
4758 goto out;
4759 }
4760 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4761 MPI2_IOCSTATUS_MASK;
4762 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4763 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4764 ioc->name, __FILE__, __LINE__, __func__);
4765 goto out;
4766 }
4767
4768 ioc->io_missing_delay =
4769 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4770 device_missing_delay =
4771 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4772 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4773 ioc->device_missing_delay = (device_missing_delay &
4774 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4775 else
4776 ioc->device_missing_delay = device_missing_delay &
4777 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4778
4779 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4780 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4781 sizeof(struct _sas_phy), GFP_KERNEL);
4782 if (!ioc->sas_hba.phy) {
4783 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4784 ioc->name, __FILE__, __LINE__, __func__);
4785 goto out;
4786 }
4787 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4788 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4789 i))) {
4790 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4791 ioc->name, __FILE__, __LINE__, __func__);
4792 goto out;
4793 }
4794 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4795 MPI2_IOCSTATUS_MASK;
4796 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4797 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4798 ioc->name, __FILE__, __LINE__, __func__);
4799 goto out;
4800 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304801
4802 if (i == 0)
4803 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4804 PhyData[0].ControllerDevHandle);
4805 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
Eric Moore635374e2009-03-09 01:21:12 -06004806 ioc->sas_hba.phy[i].phy_id = i;
4807 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4808 phy_pg0, ioc->sas_hba.parent_dev);
4809 }
4810 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304811 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06004812 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4813 ioc->name, __FILE__, __LINE__, __func__);
4814 goto out;
4815 }
Eric Moore635374e2009-03-09 01:21:12 -06004816 ioc->sas_hba.enclosure_handle =
4817 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4818 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4819 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4820 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4821 (unsigned long long) ioc->sas_hba.sas_address,
4822 ioc->sas_hba.num_phys) ;
4823
4824 if (ioc->sas_hba.enclosure_handle) {
4825 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4826 &enclosure_pg0,
4827 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4828 ioc->sas_hba.enclosure_handle))) {
4829 ioc->sas_hba.enclosure_logical_id =
4830 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4831 }
4832 }
4833
4834 out:
4835 kfree(sas_iounit_pg1);
4836 kfree(sas_iounit_pg0);
4837}
4838
4839/**
4840 * _scsih_expander_add - creating expander object
4841 * @ioc: per adapter object
4842 * @handle: expander handle
4843 *
4844 * Creating expander object, stored in ioc->sas_expander_list.
4845 *
4846 * Return 0 for success, else error.
4847 */
4848static int
4849_scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4850{
4851 struct _sas_node *sas_expander;
4852 Mpi2ConfigReply_t mpi_reply;
4853 Mpi2ExpanderPage0_t expander_pg0;
4854 Mpi2ExpanderPage1_t expander_pg1;
4855 Mpi2SasEnclosurePage0_t enclosure_pg0;
4856 u32 ioc_status;
4857 u16 parent_handle;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05304858 u64 sas_address, sas_address_parent = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004859 int i;
4860 unsigned long flags;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304861 struct _sas_port *mpt2sas_port = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06004862 int rc = 0;
4863
4864 if (!handle)
4865 return -1;
4866
Eric Moore3cb54692010-07-08 14:44:34 -06004867 if (ioc->shost_recovery || ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05304868 return -1;
4869
Eric Moore635374e2009-03-09 01:21:12 -06004870 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4871 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4872 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4873 ioc->name, __FILE__, __LINE__, __func__);
4874 return -1;
4875 }
4876
4877 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4878 MPI2_IOCSTATUS_MASK;
4879 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4880 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4881 ioc->name, __FILE__, __LINE__, __func__);
4882 return -1;
4883 }
4884
4885 /* handle out of order topology events */
4886 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304887 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4888 != 0) {
4889 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4890 ioc->name, __FILE__, __LINE__, __func__);
4891 return -1;
4892 }
4893 if (sas_address_parent != ioc->sas_hba.sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06004894 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304895 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4896 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004897 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4898 if (!sas_expander) {
4899 rc = _scsih_expander_add(ioc, parent_handle);
4900 if (rc != 0)
4901 return rc;
4902 }
4903 }
4904
Eric Moore635374e2009-03-09 01:21:12 -06004905 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304906 sas_address = le64_to_cpu(expander_pg0.SASAddress);
Eric Moore635374e2009-03-09 01:21:12 -06004907 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4908 sas_address);
4909 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4910
4911 if (sas_expander)
4912 return 0;
4913
4914 sas_expander = kzalloc(sizeof(struct _sas_node),
4915 GFP_KERNEL);
4916 if (!sas_expander) {
4917 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4918 ioc->name, __FILE__, __LINE__, __func__);
4919 return -1;
4920 }
4921
4922 sas_expander->handle = handle;
4923 sas_expander->num_phys = expander_pg0.NumPhys;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304924 sas_expander->sas_address_parent = sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06004925 sas_expander->sas_address = sas_address;
4926
4927 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4928 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304929 handle, parent_handle, (unsigned long long)
Eric Moore635374e2009-03-09 01:21:12 -06004930 sas_expander->sas_address, sas_expander->num_phys);
4931
4932 if (!sas_expander->num_phys)
4933 goto out_fail;
4934 sas_expander->phy = kcalloc(sas_expander->num_phys,
4935 sizeof(struct _sas_phy), GFP_KERNEL);
4936 if (!sas_expander->phy) {
4937 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4938 ioc->name, __FILE__, __LINE__, __func__);
4939 rc = -1;
4940 goto out_fail;
4941 }
4942
4943 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4944 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304945 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004946 if (!mpt2sas_port) {
4947 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4948 ioc->name, __FILE__, __LINE__, __func__);
4949 rc = -1;
4950 goto out_fail;
4951 }
4952 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4953
4954 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4955 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4956 &expander_pg1, i, handle))) {
4957 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4958 ioc->name, __FILE__, __LINE__, __func__);
Kashyap, Desai20f58952009-08-07 19:34:26 +05304959 rc = -1;
4960 goto out_fail;
Eric Moore635374e2009-03-09 01:21:12 -06004961 }
4962 sas_expander->phy[i].handle = handle;
4963 sas_expander->phy[i].phy_id = i;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304964
4965 if ((mpt2sas_transport_add_expander_phy(ioc,
4966 &sas_expander->phy[i], expander_pg1,
4967 sas_expander->parent_dev))) {
4968 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4969 ioc->name, __FILE__, __LINE__, __func__);
4970 rc = -1;
4971 goto out_fail;
4972 }
Eric Moore635374e2009-03-09 01:21:12 -06004973 }
4974
4975 if (sas_expander->enclosure_handle) {
4976 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4977 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4978 sas_expander->enclosure_handle))) {
4979 sas_expander->enclosure_logical_id =
4980 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4981 }
4982 }
4983
4984 _scsih_expander_node_add(ioc, sas_expander);
4985 return 0;
4986
4987 out_fail:
4988
Kashyap, Desai20f58952009-08-07 19:34:26 +05304989 if (mpt2sas_port)
4990 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304991 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004992 kfree(sas_expander);
4993 return rc;
4994}
4995
4996/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05304997 * _scsih_done - scsih callback handler.
4998 * @ioc: per adapter object
4999 * @smid: system request message index
5000 * @msix_index: MSIX table index supplied by the OS
5001 * @reply: reply message frame(lower 32bit addr)
5002 *
5003 * Callback handler when sending internal generated message frames.
5004 * The callback index passed is `ioc->scsih_cb_idx`
5005 *
5006 * Return 1 meaning mf should be freed from _base_interrupt
5007 * 0 means the mf is freed from this function.
5008 */
5009static u8
5010_scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5011{
5012 MPI2DefaultReply_t *mpi_reply;
5013
5014 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5015 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
5016 return 1;
5017 if (ioc->scsih_cmds.smid != smid)
5018 return 1;
5019 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
5020 if (mpi_reply) {
5021 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5022 mpi_reply->MsgLength*4);
5023 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
5024 }
5025 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
5026 complete(&ioc->scsih_cmds.done);
5027 return 1;
5028}
5029
5030/**
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305031 * mpt2sas_expander_remove - removing expander object
Eric Moore635374e2009-03-09 01:21:12 -06005032 * @ioc: per adapter object
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305033 * @sas_address: expander sas_address
Eric Moore635374e2009-03-09 01:21:12 -06005034 *
5035 * Return nothing.
5036 */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305037void
5038mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06005039{
5040 struct _sas_node *sas_expander;
5041 unsigned long flags;
5042
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305043 if (ioc->shost_recovery)
5044 return;
5045
Eric Moore635374e2009-03-09 01:21:12 -06005046 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305047 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5048 sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305049 if (sas_expander)
5050 list_del(&sas_expander->list);
Eric Moore635374e2009-03-09 01:21:12 -06005051 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305052 if (sas_expander)
5053 _scsih_expander_node_remove(ioc, sas_expander);
Eric Moore635374e2009-03-09 01:21:12 -06005054}
5055
5056/**
Kashyap, Desaib4344272010-03-17 16:24:14 +05305057 * _scsih_check_access_status - check access flags
5058 * @ioc: per adapter object
5059 * @sas_address: sas address
5060 * @handle: sas device handle
5061 * @access_flags: errors returned during discovery of the device
5062 *
5063 * Return 0 for success, else failure
5064 */
5065static u8
5066_scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5067 u16 handle, u8 access_status)
5068{
5069 u8 rc = 1;
5070 char *desc = NULL;
5071
5072 switch (access_status) {
5073 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5074 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5075 rc = 0;
5076 break;
5077 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5078 desc = "sata capability failed";
5079 break;
5080 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5081 desc = "sata affiliation conflict";
5082 break;
5083 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5084 desc = "route not addressable";
5085 break;
5086 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5087 desc = "smp error not addressable";
5088 break;
5089 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5090 desc = "device blocked";
5091 break;
5092 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5093 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5094 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5095 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5096 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5097 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5098 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5099 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5100 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5101 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5102 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5103 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5104 desc = "sata initialization failed";
5105 break;
5106 default:
5107 desc = "unknown";
5108 break;
5109 }
5110
5111 if (!rc)
5112 return 0;
5113
5114 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5115 "handle(0x%04x)\n", ioc->name, desc,
5116 (unsigned long long)sas_address, handle);
5117 return rc;
5118}
5119
5120static void
5121_scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5122{
5123 Mpi2ConfigReply_t mpi_reply;
5124 Mpi2SasDevicePage0_t sas_device_pg0;
5125 struct _sas_device *sas_device;
5126 u32 ioc_status;
5127 unsigned long flags;
5128 u64 sas_address;
5129 struct scsi_target *starget;
5130 struct MPT2SAS_TARGET *sas_target_priv_data;
5131 u32 device_info;
5132
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305133
Kashyap, Desaib4344272010-03-17 16:24:14 +05305134 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5135 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5136 return;
5137
5138 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5139 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5140 return;
5141
5142 /* check if this is end device */
5143 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5144 if (!(_scsih_is_end_device(device_info)))
5145 return;
5146
5147 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5148 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5149 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5150 sas_address);
5151
5152 if (!sas_device) {
5153 printk(MPT2SAS_ERR_FMT "device is not present "
5154 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5155 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5156 return;
5157 }
5158
5159 if (unlikely(sas_device->handle != handle)) {
5160 starget = sas_device->starget;
5161 sas_target_priv_data = starget->hostdata;
5162 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5163 " to (0x%04x)!!!\n", sas_device->handle, handle);
5164 sas_target_priv_data->handle = handle;
5165 sas_device->handle = handle;
5166 }
Kashyap, Desaib4344272010-03-17 16:24:14 +05305167
5168 /* check if device is present */
5169 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5170 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5171 printk(MPT2SAS_ERR_FMT "device is not present "
5172 "handle(0x%04x), flags!!!\n", ioc->name, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305173 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305174 return;
5175 }
5176
5177 /* check if there were any issues with discovery */
5178 if (_scsih_check_access_status(ioc, sas_address, handle,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305179 sas_device_pg0.AccessStatus)) {
5180 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305181 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305182 }
5183 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05305184 _scsih_ublock_io_device(ioc, sas_address);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305185
5186}
5187
5188/**
Eric Moore635374e2009-03-09 01:21:12 -06005189 * _scsih_add_device - creating sas device object
5190 * @ioc: per adapter object
5191 * @handle: sas device handle
5192 * @phy_num: phy number end device attached to
5193 * @is_pd: is this hidden raid component
5194 *
5195 * Creating end device object, stored in ioc->sas_device_list.
5196 *
5197 * Returns 0 for success, non-zero for failure.
5198 */
5199static int
5200_scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5201{
5202 Mpi2ConfigReply_t mpi_reply;
5203 Mpi2SasDevicePage0_t sas_device_pg0;
5204 Mpi2SasEnclosurePage0_t enclosure_pg0;
5205 struct _sas_device *sas_device;
5206 u32 ioc_status;
5207 __le64 sas_address;
5208 u32 device_info;
5209 unsigned long flags;
5210
5211 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5212 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5213 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5214 ioc->name, __FILE__, __LINE__, __func__);
5215 return -1;
5216 }
5217
5218 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5219 MPI2_IOCSTATUS_MASK;
5220 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5221 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5222 ioc->name, __FILE__, __LINE__, __func__);
5223 return -1;
5224 }
5225
Kashyap, Desaib4344272010-03-17 16:24:14 +05305226 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5227
Eric Moore635374e2009-03-09 01:21:12 -06005228 /* check if device is present */
5229 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5230 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5231 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5232 ioc->name, __FILE__, __LINE__, __func__);
5233 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5234 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5235 return -1;
5236 }
5237
Kashyap, Desaib4344272010-03-17 16:24:14 +05305238 /* check if there were any issues with discovery */
5239 if (_scsih_check_access_status(ioc, sas_address, handle,
5240 sas_device_pg0.AccessStatus))
Eric Moore635374e2009-03-09 01:21:12 -06005241 return -1;
Eric Moore635374e2009-03-09 01:21:12 -06005242
5243 /* check if this is end device */
5244 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5245 if (!(_scsih_is_end_device(device_info))) {
5246 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5247 ioc->name, __FILE__, __LINE__, __func__);
5248 return -1;
5249 }
5250
Eric Moore635374e2009-03-09 01:21:12 -06005251
5252 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5253 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5254 sas_address);
5255 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5256
Kashyap, Desaib4344272010-03-17 16:24:14 +05305257 if (sas_device)
Eric Moore635374e2009-03-09 01:21:12 -06005258 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06005259
5260 sas_device = kzalloc(sizeof(struct _sas_device),
5261 GFP_KERNEL);
5262 if (!sas_device) {
5263 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5264 ioc->name, __FILE__, __LINE__, __func__);
5265 return -1;
5266 }
5267
5268 sas_device->handle = handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305269 if (_scsih_get_sas_address(ioc, le16_to_cpu
5270 (sas_device_pg0.ParentDevHandle),
5271 &sas_device->sas_address_parent) != 0)
5272 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5273 ioc->name, __FILE__, __LINE__, __func__);
Eric Moore635374e2009-03-09 01:21:12 -06005274 sas_device->enclosure_handle =
5275 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5276 sas_device->slot =
5277 le16_to_cpu(sas_device_pg0.Slot);
5278 sas_device->device_info = device_info;
5279 sas_device->sas_address = sas_address;
Kashyap, Desai7fbae672010-06-17 13:45:17 +05305280 sas_device->phy = sas_device_pg0.PhyNum;
Eric Moore635374e2009-03-09 01:21:12 -06005281
5282 /* get enclosure_logical_id */
Kashyap, Desai15052c92009-08-07 19:33:17 +05305283 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5284 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5285 sas_device->enclosure_handle)))
Eric Moore635374e2009-03-09 01:21:12 -06005286 sas_device->enclosure_logical_id =
5287 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
Eric Moore635374e2009-03-09 01:21:12 -06005288
5289 /* get device name */
5290 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5291
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305292 if (ioc->wait_for_discovery_to_complete)
Eric Moore635374e2009-03-09 01:21:12 -06005293 _scsih_sas_device_init_add(ioc, sas_device);
5294 else
5295 _scsih_sas_device_add(ioc, sas_device);
5296
5297 return 0;
5298}
5299
5300/**
Kashyap, Desai1278b112010-03-09 17:34:13 +05305301 * _scsih_remove_device - removing sas device object
5302 * @ioc: per adapter object
5303 * @sas_device_delete: the sas_device object
5304 *
5305 * Return nothing.
5306 */
5307static void
5308_scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5309 struct _sas_device *sas_device)
5310{
Kashyap, Desai1278b112010-03-09 17:34:13 +05305311 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05305312
Kashyap, Desai1278b112010-03-09 17:34:13 +05305313 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5314 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305315 sas_device->handle, (unsigned long long)
5316 sas_device->sas_address));
Kashyap, Desai1278b112010-03-09 17:34:13 +05305317
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305318 if (sas_device->starget && sas_device->starget->hostdata) {
5319 sas_target_priv_data = sas_device->starget->hostdata;
Kashyap, Desai1278b112010-03-09 17:34:13 +05305320 sas_target_priv_data->deleted = 1;
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05305321 _scsih_ublock_io_device(ioc, sas_device->sas_address);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305322 sas_target_priv_data->handle =
5323 MPT2SAS_INVALID_DEVICE_HANDLE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05305324 }
5325
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05305326 if (!ioc->hide_drives)
5327 mpt2sas_transport_port_remove(ioc,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305328 sas_device->sas_address,
5329 sas_device->sas_address_parent);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305330
5331 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305332 "(0x%016llx)\n", ioc->name, sas_device->handle,
5333 (unsigned long long) sas_device->sas_address);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305334
5335 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5336 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305337 sas_device->handle, (unsigned long long)
5338 sas_device->sas_address));
5339 kfree(sas_device);
5340}
5341/**
5342 * _scsih_device_remove_by_handle - removing device object by handle
5343 * @ioc: per adapter object
5344 * @handle: device handle
5345 *
5346 * Return nothing.
5347 */
5348static void
5349_scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5350{
5351 struct _sas_device *sas_device;
5352 unsigned long flags;
5353
5354 if (ioc->shost_recovery)
5355 return;
5356
5357 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5358 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5359 if (sas_device)
5360 list_del(&sas_device->list);
5361 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5362 if (sas_device)
5363 _scsih_remove_device(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -06005364}
5365
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305366/**
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305367 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305368 * @ioc: per adapter object
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305369 * @sas_address: device sas_address
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305370 *
5371 * Return nothing.
5372 */
5373void
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305374mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
5375 u64 sas_address)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305376{
5377 struct _sas_device *sas_device;
5378 unsigned long flags;
5379
5380 if (ioc->shost_recovery)
5381 return;
5382
5383 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5384 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5385 sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305386 if (sas_device)
5387 list_del(&sas_device->list);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305388 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305389 if (sas_device)
5390 _scsih_remove_device(ioc, sas_device);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305391}
Eric Moore635374e2009-03-09 01:21:12 -06005392#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5393/**
5394 * _scsih_sas_topology_change_event_debug - debug for topology event
5395 * @ioc: per adapter object
5396 * @event_data: event data payload
5397 * Context: user.
5398 */
5399static void
5400_scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5401 Mpi2EventDataSasTopologyChangeList_t *event_data)
5402{
5403 int i;
5404 u16 handle;
5405 u16 reason_code;
5406 u8 phy_number;
5407 char *status_str = NULL;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305408 u8 link_rate, prev_link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06005409
5410 switch (event_data->ExpStatus) {
5411 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5412 status_str = "add";
5413 break;
5414 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5415 status_str = "remove";
5416 break;
5417 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305418 case 0:
Eric Moore635374e2009-03-09 01:21:12 -06005419 status_str = "responding";
5420 break;
5421 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5422 status_str = "remove delay";
5423 break;
5424 default:
5425 status_str = "unknown status";
5426 break;
5427 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305428 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
Eric Moore635374e2009-03-09 01:21:12 -06005429 ioc->name, status_str);
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305430 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
Eric Moore635374e2009-03-09 01:21:12 -06005431 "start_phy(%02d), count(%d)\n",
5432 le16_to_cpu(event_data->ExpanderDevHandle),
5433 le16_to_cpu(event_data->EnclosureHandle),
5434 event_data->StartPhyNum, event_data->NumEntries);
5435 for (i = 0; i < event_data->NumEntries; i++) {
5436 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5437 if (!handle)
5438 continue;
5439 phy_number = event_data->StartPhyNum + i;
5440 reason_code = event_data->PHY[i].PhyStatus &
5441 MPI2_EVENT_SAS_TOPO_RC_MASK;
5442 switch (reason_code) {
5443 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305444 status_str = "target add";
Eric Moore635374e2009-03-09 01:21:12 -06005445 break;
5446 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305447 status_str = "target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005448 break;
5449 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305450 status_str = "delay target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005451 break;
5452 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305453 status_str = "link rate change";
Eric Moore635374e2009-03-09 01:21:12 -06005454 break;
5455 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305456 status_str = "target responding";
Eric Moore635374e2009-03-09 01:21:12 -06005457 break;
5458 default:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305459 status_str = "unknown";
Eric Moore635374e2009-03-09 01:21:12 -06005460 break;
5461 }
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305462 link_rate = event_data->PHY[i].LinkRate >> 4;
5463 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305464 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305465 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5466 handle, status_str, link_rate, prev_link_rate);
5467
Eric Moore635374e2009-03-09 01:21:12 -06005468 }
5469}
5470#endif
5471
5472/**
5473 * _scsih_sas_topology_change_event - handle topology changes
5474 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305475 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005476 * Context: user.
5477 *
5478 */
5479static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305480_scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
Eric Moore635374e2009-03-09 01:21:12 -06005481 struct fw_event_work *fw_event)
5482{
5483 int i;
5484 u16 parent_handle, handle;
5485 u16 reason_code;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305486 u8 phy_number, max_phys;
Eric Moore635374e2009-03-09 01:21:12 -06005487 struct _sas_node *sas_expander;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305488 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06005489 unsigned long flags;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305490 u8 link_rate, prev_link_rate;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305491 Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06005492
5493#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5494 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5495 _scsih_sas_topology_change_event_debug(ioc, event_data);
5496#endif
5497
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305498 if (ioc->remove_host || ioc->pci_error_recovery)
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305499 return;
5500
Eric Moore635374e2009-03-09 01:21:12 -06005501 if (!ioc->sas_hba.num_phys)
5502 _scsih_sas_host_add(ioc);
5503 else
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305504 _scsih_sas_host_refresh(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005505
5506 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305507 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
Eric Moore635374e2009-03-09 01:21:12 -06005508 "event\n", ioc->name));
5509 return;
5510 }
5511
5512 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5513
5514 /* handle expander add */
5515 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5516 if (_scsih_expander_add(ioc, parent_handle) != 0)
5517 return;
5518
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305519 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5520 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5521 parent_handle);
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305522 if (sas_expander) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305523 sas_address = sas_expander->sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305524 max_phys = sas_expander->num_phys;
5525 } else if (parent_handle < ioc->sas_hba.num_phys) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305526 sas_address = ioc->sas_hba.sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305527 max_phys = ioc->sas_hba.num_phys;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305528 } else {
5529 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305530 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305531 }
5532 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305533
Eric Moore635374e2009-03-09 01:21:12 -06005534 /* handle siblings events */
5535 for (i = 0; i < event_data->NumEntries; i++) {
5536 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305537 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
Eric Moore635374e2009-03-09 01:21:12 -06005538 "expander event\n", ioc->name));
5539 return;
5540 }
Eric Moore3cb54692010-07-08 14:44:34 -06005541 if (ioc->shost_recovery || ioc->remove_host ||
5542 ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305543 return;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305544 phy_number = event_data->StartPhyNum + i;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305545 if (phy_number >= max_phys)
5546 continue;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305547 reason_code = event_data->PHY[i].PhyStatus &
5548 MPI2_EVENT_SAS_TOPO_RC_MASK;
5549 if ((event_data->PHY[i].PhyStatus &
5550 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5551 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
Eric Moore635374e2009-03-09 01:21:12 -06005552 continue;
5553 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5554 if (!handle)
5555 continue;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305556 link_rate = event_data->PHY[i].LinkRate >> 4;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305557 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Eric Moore635374e2009-03-09 01:21:12 -06005558 switch (reason_code) {
5559 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305560
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305561 if (ioc->shost_recovery)
5562 break;
5563
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305564 if (link_rate == prev_link_rate)
5565 break;
5566
5567 mpt2sas_transport_update_links(ioc, sas_address,
5568 handle, phy_number, link_rate);
5569
Kashyap, Desaib4344272010-03-17 16:24:14 +05305570 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5571 break;
5572
5573 _scsih_check_device(ioc, handle);
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305574 break;
Eric Moore635374e2009-03-09 01:21:12 -06005575 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305576
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305577 if (ioc->shost_recovery)
5578 break;
5579
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305580 mpt2sas_transport_update_links(ioc, sas_address,
5581 handle, phy_number, link_rate);
5582
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305583 _scsih_add_device(ioc, handle, phy_number, 0);
Eric Moore635374e2009-03-09 01:21:12 -06005584 break;
5585 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305586
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305587 _scsih_device_remove_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06005588 break;
5589 }
5590 }
5591
5592 /* handle expander removal */
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305593 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5594 sas_expander)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305595 mpt2sas_expander_remove(ioc, sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06005596
5597}
5598
5599#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5600/**
5601 * _scsih_sas_device_status_change_event_debug - debug for device event
5602 * @event_data: event data payload
5603 * Context: user.
5604 *
5605 * Return nothing.
5606 */
5607static void
5608_scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5609 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5610{
5611 char *reason_str = NULL;
5612
5613 switch (event_data->ReasonCode) {
5614 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5615 reason_str = "smart data";
5616 break;
5617 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5618 reason_str = "unsupported device discovered";
5619 break;
5620 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5621 reason_str = "internal device reset";
5622 break;
5623 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5624 reason_str = "internal task abort";
5625 break;
5626 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5627 reason_str = "internal task abort set";
5628 break;
5629 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5630 reason_str = "internal clear task set";
5631 break;
5632 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5633 reason_str = "internal query task";
5634 break;
5635 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5636 reason_str = "sata init failure";
5637 break;
5638 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5639 reason_str = "internal device reset complete";
5640 break;
5641 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5642 reason_str = "internal task abort complete";
5643 break;
5644 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5645 reason_str = "internal async notification";
5646 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05305647 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5648 reason_str = "expander reduced functionality";
5649 break;
5650 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5651 reason_str = "expander reduced functionality complete";
5652 break;
Eric Moore635374e2009-03-09 01:21:12 -06005653 default:
5654 reason_str = "unknown reason";
5655 break;
5656 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305657 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305658 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5659 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5660 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5661 le16_to_cpu(event_data->TaskTag));
Eric Moore635374e2009-03-09 01:21:12 -06005662 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305663 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005664 event_data->ASC, event_data->ASCQ);
5665 printk(KERN_INFO "\n");
5666}
5667#endif
5668
5669/**
5670 * _scsih_sas_device_status_change_event - handle device status change
5671 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305672 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005673 * Context: user.
5674 *
5675 * Return nothing.
5676 */
5677static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305678_scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5679 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005680{
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305681 struct MPT2SAS_TARGET *target_priv_data;
5682 struct _sas_device *sas_device;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05305683 u64 sas_address;
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305684 unsigned long flags;
5685 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5686 fw_event->event_data;
5687
Eric Moore635374e2009-03-09 01:21:12 -06005688#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5689 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305690 _scsih_sas_device_status_change_event_debug(ioc,
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305691 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005692#endif
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305693
Kashyap, Desaiefe82a12011-01-04 11:34:17 +05305694 /* In MPI Revision K (0xC), the internal device reset complete was
5695 * implemented, so avoid setting tm_busy flag for older firmware.
5696 */
5697 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5698 return;
5699
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305700 if (event_data->ReasonCode !=
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305701 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305702 event_data->ReasonCode !=
5703 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305704 return;
5705
5706 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5707 sas_address = le64_to_cpu(event_data->SASAddress);
5708 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5709 sas_address);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305710
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305711 if (!sas_device || !sas_device->starget) {
5712 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305713 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305714 }
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305715
5716 target_priv_data = sas_device->starget->hostdata;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305717 if (!target_priv_data) {
5718 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305719 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305720 }
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305721
5722 if (event_data->ReasonCode ==
5723 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5724 target_priv_data->tm_busy = 1;
5725 else
5726 target_priv_data->tm_busy = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305727 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005728}
5729
5730#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5731/**
5732 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5733 * @ioc: per adapter object
5734 * @event_data: event data payload
5735 * Context: user.
5736 *
5737 * Return nothing.
5738 */
5739static void
5740_scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5741 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5742{
5743 char *reason_str = NULL;
5744
5745 switch (event_data->ReasonCode) {
5746 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5747 reason_str = "enclosure add";
5748 break;
5749 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5750 reason_str = "enclosure remove";
5751 break;
5752 default:
5753 reason_str = "unknown reason";
5754 break;
5755 }
5756
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305757 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
Eric Moore635374e2009-03-09 01:21:12 -06005758 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5759 " number slots(%d)\n", ioc->name, reason_str,
5760 le16_to_cpu(event_data->EnclosureHandle),
5761 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5762 le16_to_cpu(event_data->StartSlot));
5763}
5764#endif
5765
5766/**
5767 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5768 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305769 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005770 * Context: user.
5771 *
5772 * Return nothing.
5773 */
5774static void
5775_scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305776 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005777{
5778#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5779 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5780 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305781 fw_event->event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005782#endif
5783}
5784
5785/**
Andrew Mortona78e21d2012-02-08 12:52:22 -08005786 * _scsih_sas_broadcast_primitive_event - handle broadcast events
Eric Moore635374e2009-03-09 01:21:12 -06005787 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305788 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005789 * Context: user.
5790 *
5791 * Return nothing.
5792 */
5793static void
Andrew Mortona78e21d2012-02-08 12:52:22 -08005794_scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305795 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005796{
5797 struct scsi_cmnd *scmd;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305798 struct scsi_device *sdev;
Eric Moore635374e2009-03-09 01:21:12 -06005799 u16 smid, handle;
5800 u32 lun;
5801 struct MPT2SAS_DEVICE *sas_device_priv_data;
5802 u32 termination_count;
5803 u32 query_count;
5804 Mpi2SCSITaskManagementReply_t *mpi_reply;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305805 Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
Kashyap, Desai463217b2009-10-05 15:53:06 +05305806 u16 ioc_status;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305807 unsigned long flags;
5808 int r;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305809 u8 max_retries = 0;
5810 u8 task_abort_retries;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305811
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305812 mutex_lock(&ioc->tm_cmds.mutex);
5813 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: phy number(%d), "
5814 "width(%d)\n", ioc->name, __func__, event_data->PhyNum,
5815 event_data->PortWidth));
5816
5817 _scsih_block_io_all_device(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005818
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305819 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305820 mpi_reply = ioc->tm_cmds.reply;
5821broadcast_aen_retry:
5822
5823 /* sanity checks for retrying this loop */
5824 if (max_retries++ == 5) {
5825 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5826 ioc->name, __func__));
5827 goto out;
5828 } else if (max_retries > 1)
5829 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5830 ioc->name, __func__, max_retries - 1));
5831
Eric Moore635374e2009-03-09 01:21:12 -06005832 termination_count = 0;
5833 query_count = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305834 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305835 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305836 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06005837 scmd = _scsih_scsi_lookup_get(ioc, smid);
5838 if (!scmd)
5839 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305840 sdev = scmd->device;
5841 sas_device_priv_data = sdev->hostdata;
Eric Moore635374e2009-03-09 01:21:12 -06005842 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5843 continue;
5844 /* skip hidden raid components */
5845 if (sas_device_priv_data->sas_target->flags &
5846 MPT_TARGET_FLAGS_RAID_COMPONENT)
5847 continue;
5848 /* skip volumes */
5849 if (sas_device_priv_data->sas_target->flags &
5850 MPT_TARGET_FLAGS_VOLUME)
5851 continue;
5852
5853 handle = sas_device_priv_data->sas_target->handle;
5854 lun = sas_device_priv_data->lun;
5855 query_count++;
5856
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305857 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305858 goto out;
5859
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305860 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305861 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5862 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0,
5863 TM_MUTEX_OFF);
5864 if (r == FAILED) {
5865 sdev_printk(KERN_WARNING, sdev,
5866 "mpt2sas_scsih_issue_tm: FAILED when sending "
5867 "QUERY_TASK: scmd(%p)\n", scmd);
5868 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5869 goto broadcast_aen_retry;
5870 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05305871 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5872 & MPI2_IOCSTATUS_MASK;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305873 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5874 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5875 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5876 scmd);
5877 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5878 goto broadcast_aen_retry;
5879 }
5880
5881 /* see if IO is still owned by IOC and target */
5882 if (mpi_reply->ResponseCode ==
Eric Moore635374e2009-03-09 01:21:12 -06005883 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5884 mpi_reply->ResponseCode ==
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305885 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305886 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005887 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305888 }
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305889 task_abort_retries = 0;
5890 tm_retry:
5891 if (task_abort_retries++ == 60) {
5892 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5893 "%s: ABORT_TASK: giving up\n", ioc->name,
5894 __func__));
5895 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5896 goto broadcast_aen_retry;
5897 }
5898
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305899 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305900 goto out_no_lock;
5901
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305902 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5903 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305904 scmd->serial_number, TM_MUTEX_OFF);
5905 if (r == FAILED) {
5906 sdev_printk(KERN_WARNING, sdev,
5907 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305908 "scmd(%p)\n", scmd);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305909 goto tm_retry;
5910 }
5911
5912 if (task_abort_retries > 1)
5913 sdev_printk(KERN_WARNING, sdev,
5914 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5915 " scmd(%p)\n",
5916 task_abort_retries - 1, scmd);
5917
Eric Moore635374e2009-03-09 01:21:12 -06005918 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305919 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005920 }
Eric Moore635374e2009-03-09 01:21:12 -06005921
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305922 if (ioc->broadcast_aen_pending) {
5923 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5924 " pending AEN\n", ioc->name, __func__));
5925 ioc->broadcast_aen_pending = 0;
5926 goto broadcast_aen_retry;
5927 }
5928
5929 out:
5930 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5931 out_no_lock:
5932
5933 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06005934 "%s - exit, query_count = %d termination_count = %d\n",
5935 ioc->name, __func__, query_count, termination_count));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305936
5937 ioc->broadcast_aen_busy = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305938 if (!ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305939 _scsih_ublock_io_all_device(ioc);
5940 mutex_unlock(&ioc->tm_cmds.mutex);
Eric Moore635374e2009-03-09 01:21:12 -06005941}
5942
5943/**
5944 * _scsih_sas_discovery_event - handle discovery events
5945 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305946 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005947 * Context: user.
5948 *
5949 * Return nothing.
5950 */
5951static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305952_scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5953 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005954{
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305955 Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
5956
Eric Moore635374e2009-03-09 01:21:12 -06005957#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5958 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305959 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005960 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5961 "start" : "stop");
5962 if (event_data->DiscoveryStatus)
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305963 printk("discovery_status(0x%08x)",
5964 le32_to_cpu(event_data->DiscoveryStatus));
Eric Moore635374e2009-03-09 01:21:12 -06005965 printk("\n");
5966 }
5967#endif
5968
5969 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05305970 !ioc->sas_hba.num_phys) {
5971 if (disable_discovery > 0 && ioc->shost_recovery) {
5972 /* Wait for the reset to complete */
5973 while (ioc->shost_recovery)
5974 ssleep(1);
5975 }
Eric Moore635374e2009-03-09 01:21:12 -06005976 _scsih_sas_host_add(ioc);
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05305977 }
Eric Moore635374e2009-03-09 01:21:12 -06005978}
5979
5980/**
5981 * _scsih_reprobe_lun - reprobing lun
5982 * @sdev: scsi device struct
5983 * @no_uld_attach: sdev->no_uld_attach flag setting
5984 *
5985 **/
5986static void
5987_scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5988{
5989 int rc;
5990
5991 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5992 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5993 sdev->no_uld_attach ? "hidding" : "exposing");
5994 rc = scsi_device_reprobe(sdev);
5995}
5996
5997/**
Eric Moore635374e2009-03-09 01:21:12 -06005998 * _scsih_sas_volume_add - add new volume
5999 * @ioc: per adapter object
6000 * @element: IR config element data
6001 * Context: user.
6002 *
6003 * Return nothing.
6004 */
6005static void
6006_scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
6007 Mpi2EventIrConfigElement_t *element)
6008{
6009 struct _raid_device *raid_device;
6010 unsigned long flags;
6011 u64 wwid;
6012 u16 handle = le16_to_cpu(element->VolDevHandle);
6013 int rc;
6014
Eric Moore635374e2009-03-09 01:21:12 -06006015 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6016 if (!wwid) {
6017 printk(MPT2SAS_ERR_FMT
6018 "failure at %s:%d/%s()!\n", ioc->name,
6019 __FILE__, __LINE__, __func__);
6020 return;
6021 }
6022
6023 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6024 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6025 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6026
6027 if (raid_device)
6028 return;
6029
6030 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6031 if (!raid_device) {
6032 printk(MPT2SAS_ERR_FMT
6033 "failure at %s:%d/%s()!\n", ioc->name,
6034 __FILE__, __LINE__, __func__);
6035 return;
6036 }
6037
6038 raid_device->id = ioc->sas_id++;
6039 raid_device->channel = RAID_CHANNEL;
6040 raid_device->handle = handle;
6041 raid_device->wwid = wwid;
6042 _scsih_raid_device_add(ioc, raid_device);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306043 if (!ioc->wait_for_discovery_to_complete) {
Eric Moore635374e2009-03-09 01:21:12 -06006044 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6045 raid_device->id, 0);
6046 if (rc)
6047 _scsih_raid_device_remove(ioc, raid_device);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306048 } else {
6049 spin_lock_irqsave(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06006050 _scsih_determine_boot_device(ioc, raid_device, 1);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306051 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6052 }
Eric Moore635374e2009-03-09 01:21:12 -06006053}
6054
6055/**
6056 * _scsih_sas_volume_delete - delete volume
6057 * @ioc: per adapter object
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306058 * @handle: volume device handle
Eric Moore635374e2009-03-09 01:21:12 -06006059 * Context: user.
6060 *
6061 * Return nothing.
6062 */
6063static void
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306064_scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Eric Moore635374e2009-03-09 01:21:12 -06006065{
6066 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06006067 unsigned long flags;
6068 struct MPT2SAS_TARGET *sas_target_priv_data;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306069 struct scsi_target *starget = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006070
Eric Moore635374e2009-03-09 01:21:12 -06006071 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6072 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306073 if (raid_device) {
6074 if (raid_device->starget) {
6075 starget = raid_device->starget;
6076 sas_target_priv_data = starget->hostdata;
6077 sas_target_priv_data->deleted = 1;
6078 }
6079 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6080 "(0x%016llx)\n", ioc->name, raid_device->handle,
6081 (unsigned long long) raid_device->wwid);
6082 list_del(&raid_device->list);
6083 kfree(raid_device);
Eric Moore635374e2009-03-09 01:21:12 -06006084 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306085 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6086 if (starget)
6087 scsi_remove_target(&starget->dev);
Eric Moore635374e2009-03-09 01:21:12 -06006088}
6089
6090/**
6091 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6092 * @ioc: per adapter object
6093 * @element: IR config element data
6094 * Context: user.
6095 *
6096 * Return nothing.
6097 */
6098static void
6099_scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6100 Mpi2EventIrConfigElement_t *element)
6101{
6102 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306103 struct scsi_target *starget = NULL;
6104 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06006105 unsigned long flags;
6106 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6107
6108 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6109 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306110 if (sas_device) {
6111 sas_device->volume_handle = 0;
6112 sas_device->volume_wwid = 0;
6113 clear_bit(handle, ioc->pd_handles);
6114 if (sas_device->starget && sas_device->starget->hostdata) {
6115 starget = sas_device->starget;
6116 sas_target_priv_data = starget->hostdata;
6117 sas_target_priv_data->flags &=
6118 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6119 }
6120 }
Eric Moore635374e2009-03-09 01:21:12 -06006121 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6122 if (!sas_device)
6123 return;
6124
6125 /* exposing raid component */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306126 if (starget)
6127 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
Eric Moore635374e2009-03-09 01:21:12 -06006128}
6129
6130/**
6131 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6132 * @ioc: per adapter object
6133 * @element: IR config element data
6134 * Context: user.
6135 *
6136 * Return nothing.
6137 */
6138static void
6139_scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6140 Mpi2EventIrConfigElement_t *element)
6141{
6142 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306143 struct scsi_target *starget = NULL;
6144 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06006145 unsigned long flags;
6146 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306147 u16 volume_handle = 0;
6148 u64 volume_wwid = 0;
6149
6150 mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle);
6151 if (volume_handle)
6152 mpt2sas_config_get_volume_wwid(ioc, volume_handle,
6153 &volume_wwid);
Eric Moore635374e2009-03-09 01:21:12 -06006154
6155 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6156 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306157 if (sas_device) {
6158 set_bit(handle, ioc->pd_handles);
6159 if (sas_device->starget && sas_device->starget->hostdata) {
6160 starget = sas_device->starget;
6161 sas_target_priv_data = starget->hostdata;
6162 sas_target_priv_data->flags |=
6163 MPT_TARGET_FLAGS_RAID_COMPONENT;
6164 sas_device->volume_handle = volume_handle;
6165 sas_device->volume_wwid = volume_wwid;
6166 }
6167 }
Eric Moore635374e2009-03-09 01:21:12 -06006168 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6169 if (!sas_device)
6170 return;
6171
6172 /* hiding raid component */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306173 if (starget)
6174 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
Eric Moore635374e2009-03-09 01:21:12 -06006175}
6176
6177/**
6178 * _scsih_sas_pd_delete - delete pd component
6179 * @ioc: per adapter object
6180 * @element: IR config element data
6181 * Context: user.
6182 *
6183 * Return nothing.
6184 */
6185static void
6186_scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6187 Mpi2EventIrConfigElement_t *element)
6188{
Eric Moore635374e2009-03-09 01:21:12 -06006189 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6190
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306191 _scsih_device_remove_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006192}
6193
6194/**
6195 * _scsih_sas_pd_add - remove pd component
6196 * @ioc: per adapter object
6197 * @element: IR config element data
6198 * Context: user.
6199 *
6200 * Return nothing.
6201 */
6202static void
6203_scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6204 Mpi2EventIrConfigElement_t *element)
6205{
6206 struct _sas_device *sas_device;
6207 unsigned long flags;
6208 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306209 Mpi2ConfigReply_t mpi_reply;
6210 Mpi2SasDevicePage0_t sas_device_pg0;
6211 u32 ioc_status;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306212 u64 sas_address;
6213 u16 parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006214
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306215 set_bit(handle, ioc->pd_handles);
6216
Eric Moore635374e2009-03-09 01:21:12 -06006217 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6218 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6219 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306220 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306221 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306222
6223 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6224 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6225 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6226 ioc->name, __FILE__, __LINE__, __func__);
6227 return;
6228 }
6229
6230 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6231 MPI2_IOCSTATUS_MASK;
6232 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6233 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6234 ioc->name, __FILE__, __LINE__, __func__);
6235 return;
6236 }
6237
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306238 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6239 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6240 mpt2sas_transport_update_links(ioc, sas_address, handle,
6241 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306242
6243 _scsih_add_device(ioc, handle, 0, 1);
Eric Moore635374e2009-03-09 01:21:12 -06006244}
6245
6246#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6247/**
6248 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6249 * @ioc: per adapter object
6250 * @event_data: event data payload
6251 * Context: user.
6252 *
6253 * Return nothing.
6254 */
6255static void
6256_scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6257 Mpi2EventDataIrConfigChangeList_t *event_data)
6258{
6259 Mpi2EventIrConfigElement_t *element;
6260 u8 element_type;
6261 int i;
6262 char *reason_str = NULL, *element_str = NULL;
6263
6264 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6265
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306266 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
Eric Moore635374e2009-03-09 01:21:12 -06006267 ioc->name, (le32_to_cpu(event_data->Flags) &
6268 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6269 "foreign" : "native", event_data->NumElements);
6270 for (i = 0; i < event_data->NumElements; i++, element++) {
6271 switch (element->ReasonCode) {
6272 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6273 reason_str = "add";
6274 break;
6275 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6276 reason_str = "remove";
6277 break;
6278 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6279 reason_str = "no change";
6280 break;
6281 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6282 reason_str = "hide";
6283 break;
6284 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6285 reason_str = "unhide";
6286 break;
6287 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6288 reason_str = "volume_created";
6289 break;
6290 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6291 reason_str = "volume_deleted";
6292 break;
6293 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6294 reason_str = "pd_created";
6295 break;
6296 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6297 reason_str = "pd_deleted";
6298 break;
6299 default:
6300 reason_str = "unknown reason";
6301 break;
6302 }
6303 element_type = le16_to_cpu(element->ElementFlags) &
6304 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6305 switch (element_type) {
6306 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6307 element_str = "volume";
6308 break;
6309 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6310 element_str = "phys disk";
6311 break;
6312 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6313 element_str = "hot spare";
6314 break;
6315 default:
6316 element_str = "unknown element";
6317 break;
6318 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306319 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
Eric Moore635374e2009-03-09 01:21:12 -06006320 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6321 reason_str, le16_to_cpu(element->VolDevHandle),
6322 le16_to_cpu(element->PhysDiskDevHandle),
6323 element->PhysDiskNum);
6324 }
6325}
6326#endif
6327
6328/**
6329 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6330 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306331 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006332 * Context: user.
6333 *
6334 * Return nothing.
6335 */
6336static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306337_scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6338 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006339{
6340 Mpi2EventIrConfigElement_t *element;
6341 int i;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306342 u8 foreign_config;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306343 Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006344
6345#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306346 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6347 && !ioc->hide_ir_msg)
Eric Moore635374e2009-03-09 01:21:12 -06006348 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6349
6350#endif
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306351
6352 if (ioc->shost_recovery)
6353 return;
6354
Kashyap, Desai62727a72009-08-07 19:35:18 +05306355 foreign_config = (le32_to_cpu(event_data->Flags) &
6356 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
Eric Moore635374e2009-03-09 01:21:12 -06006357
6358 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6359 for (i = 0; i < event_data->NumElements; i++, element++) {
6360
6361 switch (element->ReasonCode) {
6362 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6363 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306364 if (!foreign_config)
6365 _scsih_sas_volume_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006366 break;
6367 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6368 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306369 if (!foreign_config)
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306370 _scsih_sas_volume_delete(ioc,
6371 le16_to_cpu(element->VolDevHandle));
Eric Moore635374e2009-03-09 01:21:12 -06006372 break;
6373 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306374 if (!ioc->is_warpdrive)
6375 _scsih_sas_pd_hide(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006376 break;
6377 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306378 if (!ioc->is_warpdrive)
6379 _scsih_sas_pd_expose(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006380 break;
6381 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306382 if (!ioc->is_warpdrive)
6383 _scsih_sas_pd_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006384 break;
6385 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306386 if (!ioc->is_warpdrive)
6387 _scsih_sas_pd_delete(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006388 break;
6389 }
6390 }
6391}
6392
6393/**
6394 * _scsih_sas_ir_volume_event - IR volume event
6395 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306396 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006397 * Context: user.
6398 *
6399 * Return nothing.
6400 */
6401static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306402_scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6403 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006404{
6405 u64 wwid;
6406 unsigned long flags;
6407 struct _raid_device *raid_device;
6408 u16 handle;
6409 u32 state;
6410 int rc;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306411 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006412
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306413 if (ioc->shost_recovery)
6414 return;
6415
Eric Moore635374e2009-03-09 01:21:12 -06006416 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6417 return;
6418
6419 handle = le16_to_cpu(event_data->VolDevHandle);
6420 state = le32_to_cpu(event_data->NewValue);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306421 if (!ioc->hide_ir_msg)
6422 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6423 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6424 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006425
Eric Moore635374e2009-03-09 01:21:12 -06006426 switch (state) {
6427 case MPI2_RAID_VOL_STATE_MISSING:
6428 case MPI2_RAID_VOL_STATE_FAILED:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306429 _scsih_sas_volume_delete(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006430 break;
6431
6432 case MPI2_RAID_VOL_STATE_ONLINE:
6433 case MPI2_RAID_VOL_STATE_DEGRADED:
6434 case MPI2_RAID_VOL_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306435
6436 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6437 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6438 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6439
Eric Moore635374e2009-03-09 01:21:12 -06006440 if (raid_device)
6441 break;
6442
6443 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6444 if (!wwid) {
6445 printk(MPT2SAS_ERR_FMT
6446 "failure at %s:%d/%s()!\n", ioc->name,
6447 __FILE__, __LINE__, __func__);
6448 break;
6449 }
6450
6451 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6452 if (!raid_device) {
6453 printk(MPT2SAS_ERR_FMT
6454 "failure at %s:%d/%s()!\n", ioc->name,
6455 __FILE__, __LINE__, __func__);
6456 break;
6457 }
6458
6459 raid_device->id = ioc->sas_id++;
6460 raid_device->channel = RAID_CHANNEL;
6461 raid_device->handle = handle;
6462 raid_device->wwid = wwid;
6463 _scsih_raid_device_add(ioc, raid_device);
6464 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6465 raid_device->id, 0);
6466 if (rc)
6467 _scsih_raid_device_remove(ioc, raid_device);
6468 break;
6469
6470 case MPI2_RAID_VOL_STATE_INITIALIZING:
6471 default:
6472 break;
6473 }
6474}
6475
6476/**
6477 * _scsih_sas_ir_physical_disk_event - PD event
6478 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306479 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006480 * Context: user.
6481 *
6482 * Return nothing.
6483 */
6484static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306485_scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6486 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006487{
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306488 u16 handle, parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006489 u32 state;
6490 struct _sas_device *sas_device;
6491 unsigned long flags;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306492 Mpi2ConfigReply_t mpi_reply;
6493 Mpi2SasDevicePage0_t sas_device_pg0;
6494 u32 ioc_status;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306495 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306496 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006497
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306498 if (ioc->shost_recovery)
6499 return;
6500
Eric Moore635374e2009-03-09 01:21:12 -06006501 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6502 return;
6503
6504 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6505 state = le32_to_cpu(event_data->NewValue);
6506
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306507 if (!ioc->hide_ir_msg)
6508 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6509 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6510 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006511
Eric Moore635374e2009-03-09 01:21:12 -06006512 switch (state) {
Eric Moore635374e2009-03-09 01:21:12 -06006513 case MPI2_RAID_PD_STATE_ONLINE:
6514 case MPI2_RAID_PD_STATE_DEGRADED:
6515 case MPI2_RAID_PD_STATE_REBUILDING:
6516 case MPI2_RAID_PD_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306517 case MPI2_RAID_PD_STATE_HOT_SPARE:
6518
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306519 if (!ioc->is_warpdrive)
6520 set_bit(handle, ioc->pd_handles);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306521
6522 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6523 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6524 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6525
6526 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306527 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306528
6529 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6530 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6531 handle))) {
6532 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6533 ioc->name, __FILE__, __LINE__, __func__);
6534 return;
6535 }
6536
6537 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6538 MPI2_IOCSTATUS_MASK;
6539 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6540 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6541 ioc->name, __FILE__, __LINE__, __func__);
6542 return;
6543 }
6544
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306545 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6546 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6547 mpt2sas_transport_update_links(ioc, sas_address, handle,
6548 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306549
6550 _scsih_add_device(ioc, handle, 0, 1);
6551
Eric Moore635374e2009-03-09 01:21:12 -06006552 break;
6553
Kashyap, Desai62727a72009-08-07 19:35:18 +05306554 case MPI2_RAID_PD_STATE_OFFLINE:
Eric Moore635374e2009-03-09 01:21:12 -06006555 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6556 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
Eric Moore635374e2009-03-09 01:21:12 -06006557 default:
6558 break;
6559 }
6560}
6561
6562#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6563/**
6564 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6565 * @ioc: per adapter object
6566 * @event_data: event data payload
6567 * Context: user.
6568 *
6569 * Return nothing.
6570 */
6571static void
6572_scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6573 Mpi2EventDataIrOperationStatus_t *event_data)
6574{
6575 char *reason_str = NULL;
6576
6577 switch (event_data->RAIDOperation) {
6578 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6579 reason_str = "resync";
6580 break;
6581 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6582 reason_str = "online capacity expansion";
6583 break;
6584 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6585 reason_str = "consistency check";
6586 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306587 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6588 reason_str = "background init";
6589 break;
6590 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6591 reason_str = "make data consistent";
Eric Moore635374e2009-03-09 01:21:12 -06006592 break;
6593 }
6594
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306595 if (!reason_str)
6596 return;
6597
Eric Moore635374e2009-03-09 01:21:12 -06006598 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6599 "\thandle(0x%04x), percent complete(%d)\n",
6600 ioc->name, reason_str,
6601 le16_to_cpu(event_data->VolDevHandle),
6602 event_data->PercentComplete);
6603}
6604#endif
6605
6606/**
6607 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6608 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306609 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006610 * Context: user.
6611 *
6612 * Return nothing.
6613 */
6614static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306615_scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6616 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006617{
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306618 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
6619 static struct _raid_device *raid_device;
6620 unsigned long flags;
6621 u16 handle;
6622
Eric Moore635374e2009-03-09 01:21:12 -06006623#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306624 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6625 && !ioc->hide_ir_msg)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306626 _scsih_sas_ir_operation_status_event_debug(ioc,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306627 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06006628#endif
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306629
6630 /* code added for raid transport support */
6631 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6632
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306633 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306634 handle = le16_to_cpu(event_data->VolDevHandle);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306635 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306636 if (raid_device)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306637 raid_device->percent_complete =
6638 event_data->PercentComplete;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306639 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306640 }
Eric Moore635374e2009-03-09 01:21:12 -06006641}
6642
6643/**
Kashyap, Desai14695852010-03-30 10:52:44 +05306644 * _scsih_prep_device_scan - initialize parameters prior to device scan
6645 * @ioc: per adapter object
6646 *
6647 * Set the deleted flag prior to device scan. If the device is found during
6648 * the scan, then we clear the deleted flag.
6649 */
6650static void
6651_scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6652{
6653 struct MPT2SAS_DEVICE *sas_device_priv_data;
6654 struct scsi_device *sdev;
6655
6656 shost_for_each_device(sdev, ioc->shost) {
6657 sas_device_priv_data = sdev->hostdata;
6658 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6659 sas_device_priv_data->sas_target->deleted = 1;
6660 }
6661}
6662
6663/**
Eric Moore635374e2009-03-09 01:21:12 -06006664 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6665 * @ioc: per adapter object
6666 * @sas_address: sas address
6667 * @slot: enclosure slot id
6668 * @handle: device handle
6669 *
6670 * After host reset, find out whether devices are still responding.
6671 * Used in _scsi_remove_unresponsive_sas_devices.
6672 *
6673 * Return nothing.
6674 */
6675static void
6676_scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6677 u16 slot, u16 handle)
6678{
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306679 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006680 struct scsi_target *starget;
6681 struct _sas_device *sas_device;
6682 unsigned long flags;
6683
6684 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6685 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6686 if (sas_device->sas_address == sas_address &&
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306687 sas_device->slot == slot) {
Eric Moore635374e2009-03-09 01:21:12 -06006688 sas_device->responding = 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05306689 starget = sas_device->starget;
Kashyap, Desai14695852010-03-30 10:52:44 +05306690 if (starget && starget->hostdata) {
6691 sas_target_priv_data = starget->hostdata;
6692 sas_target_priv_data->tm_busy = 0;
6693 sas_target_priv_data->deleted = 0;
6694 } else
6695 sas_target_priv_data = NULL;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306696 if (starget)
6697 starget_printk(KERN_INFO, starget,
6698 "handle(0x%04x), sas_addr(0x%016llx), "
6699 "enclosure logical id(0x%016llx), "
6700 "slot(%d)\n", handle,
6701 (unsigned long long)sas_device->sas_address,
6702 (unsigned long long)
6703 sas_device->enclosure_logical_id,
6704 sas_device->slot);
Eric Moore635374e2009-03-09 01:21:12 -06006705 if (sas_device->handle == handle)
6706 goto out;
6707 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6708 sas_device->handle);
6709 sas_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306710 if (sas_target_priv_data)
6711 sas_target_priv_data->handle = handle;
Eric Moore635374e2009-03-09 01:21:12 -06006712 goto out;
6713 }
6714 }
6715 out:
6716 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6717}
6718
6719/**
6720 * _scsih_search_responding_sas_devices -
6721 * @ioc: per adapter object
6722 *
6723 * After host reset, find out whether devices are still responding.
6724 * If not remove.
6725 *
6726 * Return nothing.
6727 */
6728static void
6729_scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6730{
6731 Mpi2SasDevicePage0_t sas_device_pg0;
6732 Mpi2ConfigReply_t mpi_reply;
6733 u16 ioc_status;
6734 __le64 sas_address;
6735 u16 handle;
6736 u32 device_info;
6737 u16 slot;
6738
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306739 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006740
6741 if (list_empty(&ioc->sas_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306742 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006743
6744 handle = 0xFFFF;
6745 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6746 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6747 handle))) {
6748 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6749 MPI2_IOCSTATUS_MASK;
6750 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6751 break;
6752 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6753 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6754 if (!(_scsih_is_end_device(device_info)))
6755 continue;
6756 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6757 slot = le16_to_cpu(sas_device_pg0.Slot);
6758 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6759 handle);
6760 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306761out:
6762 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6763 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006764}
6765
6766/**
6767 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6768 * @ioc: per adapter object
6769 * @wwid: world wide identifier for raid volume
6770 * @handle: device handle
6771 *
6772 * After host reset, find out whether devices are still responding.
6773 * Used in _scsi_remove_unresponsive_raid_devices.
6774 *
6775 * Return nothing.
6776 */
6777static void
6778_scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6779 u16 handle)
6780{
6781 struct MPT2SAS_TARGET *sas_target_priv_data;
6782 struct scsi_target *starget;
6783 struct _raid_device *raid_device;
6784 unsigned long flags;
6785
6786 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6787 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6788 if (raid_device->wwid == wwid && raid_device->starget) {
Kashyap, Desai14695852010-03-30 10:52:44 +05306789 starget = raid_device->starget;
6790 if (starget && starget->hostdata) {
6791 sas_target_priv_data = starget->hostdata;
6792 sas_target_priv_data->deleted = 0;
6793 } else
6794 sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006795 raid_device->responding = 1;
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306796 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06006797 starget_printk(KERN_INFO, raid_device->starget,
6798 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6799 (unsigned long long)raid_device->wwid);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306800 /*
6801 * WARPDRIVE: The handles of the PDs might have changed
6802 * across the host reset so re-initialize the
6803 * required data for Direct IO
6804 */
6805 _scsih_init_warpdrive_properties(ioc, raid_device);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306806 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6807 if (raid_device->handle == handle) {
6808 spin_unlock_irqrestore(&ioc->raid_device_lock,
6809 flags);
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306810 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306811 }
Eric Moore635374e2009-03-09 01:21:12 -06006812 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6813 raid_device->handle);
6814 raid_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306815 if (sas_target_priv_data)
6816 sas_target_priv_data->handle = handle;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306817 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306818 return;
Eric Moore635374e2009-03-09 01:21:12 -06006819 }
6820 }
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306821
Eric Moore635374e2009-03-09 01:21:12 -06006822 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6823}
6824
6825/**
6826 * _scsih_search_responding_raid_devices -
6827 * @ioc: per adapter object
6828 *
6829 * After host reset, find out whether devices are still responding.
6830 * If not remove.
6831 *
6832 * Return nothing.
6833 */
6834static void
6835_scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6836{
6837 Mpi2RaidVolPage1_t volume_pg1;
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306838 Mpi2RaidVolPage0_t volume_pg0;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306839 Mpi2RaidPhysDiskPage0_t pd_pg0;
Eric Moore635374e2009-03-09 01:21:12 -06006840 Mpi2ConfigReply_t mpi_reply;
6841 u16 ioc_status;
6842 u16 handle;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306843 u8 phys_disk_num;
Eric Moore635374e2009-03-09 01:21:12 -06006844
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306845 if (!ioc->ir_firmware)
6846 return;
6847
6848 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6849 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006850
6851 if (list_empty(&ioc->raid_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306852 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006853
6854 handle = 0xFFFF;
6855 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6856 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6857 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6858 MPI2_IOCSTATUS_MASK;
6859 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6860 break;
6861 handle = le16_to_cpu(volume_pg1.DevHandle);
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306862
6863 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6864 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6865 sizeof(Mpi2RaidVolPage0_t)))
6866 continue;
6867
6868 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6869 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6870 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6871 _scsih_mark_responding_raid_device(ioc,
6872 le64_to_cpu(volume_pg1.WWID), handle);
Eric Moore635374e2009-03-09 01:21:12 -06006873 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306874
6875 /* refresh the pd_handles */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306876 if (!ioc->is_warpdrive) {
6877 phys_disk_num = 0xFF;
6878 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6879 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6880 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6881 phys_disk_num))) {
6882 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6883 MPI2_IOCSTATUS_MASK;
6884 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6885 break;
6886 phys_disk_num = pd_pg0.PhysDiskNum;
6887 handle = le16_to_cpu(pd_pg0.DevHandle);
6888 set_bit(handle, ioc->pd_handles);
6889 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306890 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306891out:
6892 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6893 "complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006894}
6895
6896/**
6897 * _scsih_mark_responding_expander - mark a expander as responding
6898 * @ioc: per adapter object
6899 * @sas_address: sas address
6900 * @handle:
6901 *
6902 * After host reset, find out whether devices are still responding.
6903 * Used in _scsi_remove_unresponsive_expanders.
6904 *
6905 * Return nothing.
6906 */
6907static void
6908_scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6909 u16 handle)
6910{
6911 struct _sas_node *sas_expander;
6912 unsigned long flags;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306913 int i;
Eric Moore635374e2009-03-09 01:21:12 -06006914
6915 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6916 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306917 if (sas_expander->sas_address != sas_address)
6918 continue;
6919 sas_expander->responding = 1;
6920 if (sas_expander->handle == handle)
Eric Moore635374e2009-03-09 01:21:12 -06006921 goto out;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306922 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6923 " from(0x%04x) to (0x%04x)!!!\n",
6924 (unsigned long long)sas_expander->sas_address,
6925 sas_expander->handle, handle);
6926 sas_expander->handle = handle;
6927 for (i = 0 ; i < sas_expander->num_phys ; i++)
6928 sas_expander->phy[i].handle = handle;
6929 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006930 }
6931 out:
6932 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6933}
6934
6935/**
6936 * _scsih_search_responding_expanders -
6937 * @ioc: per adapter object
6938 *
6939 * After host reset, find out whether devices are still responding.
6940 * If not remove.
6941 *
6942 * Return nothing.
6943 */
6944static void
6945_scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6946{
6947 Mpi2ExpanderPage0_t expander_pg0;
6948 Mpi2ConfigReply_t mpi_reply;
6949 u16 ioc_status;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05306950 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006951 u16 handle;
6952
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306953 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006954
6955 if (list_empty(&ioc->sas_expander_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306956 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006957
6958 handle = 0xFFFF;
6959 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6960 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6961
6962 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6963 MPI2_IOCSTATUS_MASK;
6964 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6965 break;
6966
6967 handle = le16_to_cpu(expander_pg0.DevHandle);
6968 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6969 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6970 "sas_addr(0x%016llx)\n", handle,
6971 (unsigned long long)sas_address);
6972 _scsih_mark_responding_expander(ioc, sas_address, handle);
6973 }
6974
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306975 out:
6976 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006977}
6978
6979/**
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05306980 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
Eric Moore635374e2009-03-09 01:21:12 -06006981 * @ioc: per adapter object
6982 *
6983 * Return nothing.
6984 */
6985static void
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05306986_scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06006987{
6988 struct _sas_device *sas_device, *sas_device_next;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306989 struct _sas_node *sas_expander, *sas_expander_next;
Eric Moore635374e2009-03-09 01:21:12 -06006990 struct _raid_device *raid_device, *raid_device_next;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306991 struct list_head tmp_list;
6992 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06006993
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306994 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
6995 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006996
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306997 /* removing unresponding end devices */
6998 printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n",
6999 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06007000 list_for_each_entry_safe(sas_device, sas_device_next,
7001 &ioc->sas_device_list, list) {
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307002 if (!sas_device->responding)
nagalakshmi.nandigama@lsi.com39af7a92012-03-20 12:09:26 +05307003 mpt2sas_device_remove_by_sas_address(ioc,
7004 sas_device->sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307005 else
Eric Moore635374e2009-03-09 01:21:12 -06007006 sas_device->responding = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007007 }
7008
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307009 /* removing unresponding volumes */
7010 if (ioc->ir_firmware) {
7011 printk(MPT2SAS_INFO_FMT "removing unresponding devices: "
7012 "volumes\n", ioc->name);
7013 list_for_each_entry_safe(raid_device, raid_device_next,
7014 &ioc->raid_device_list, list) {
7015 if (!raid_device->responding)
7016 _scsih_sas_volume_delete(ioc,
7017 raid_device->handle);
7018 else
7019 raid_device->responding = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007020 }
Eric Moore635374e2009-03-09 01:21:12 -06007021 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307022 /* removing unresponding expanders */
7023 printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n",
7024 ioc->name);
7025 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7026 INIT_LIST_HEAD(&tmp_list);
7027 list_for_each_entry_safe(sas_expander, sas_expander_next,
7028 &ioc->sas_expander_list, list) {
7029 if (!sas_expander->responding)
7030 list_move_tail(&sas_expander->list, &tmp_list);
7031 else
Eric Moore635374e2009-03-09 01:21:12 -06007032 sas_expander->responding = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307033 }
7034 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7035 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7036 list) {
7037 list_del(&sas_expander->list);
7038 _scsih_expander_node_remove(ioc, sas_expander);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307039 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307040 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
7041 ioc->name);
7042 /* unblock devices */
7043 _scsih_ublock_io_all_device(ioc);
7044}
7045
7046static void
7047_scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
7048 struct _sas_node *sas_expander, u16 handle)
7049{
7050 Mpi2ExpanderPage1_t expander_pg1;
7051 Mpi2ConfigReply_t mpi_reply;
7052 int i;
7053
7054 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7055 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
7056 &expander_pg1, i, handle))) {
7057 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7058 ioc->name, __FILE__, __LINE__, __func__);
7059 return;
7060 }
7061
7062 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
7063 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7064 expander_pg1.NegotiatedLinkRate >> 4);
7065 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307066}
7067
7068/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307069 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307070 * @ioc: per adapter object
7071 *
7072 * Return nothing.
7073 */
7074static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307075_scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307076{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307077 Mpi2ExpanderPage0_t expander_pg0;
7078 Mpi2SasDevicePage0_t sas_device_pg0;
7079 Mpi2RaidVolPage1_t volume_pg1;
7080 Mpi2RaidVolPage0_t volume_pg0;
7081 Mpi2RaidPhysDiskPage0_t pd_pg0;
7082 Mpi2EventIrConfigElement_t element;
7083 Mpi2ConfigReply_t mpi_reply;
7084 u8 phys_disk_num;
7085 u16 ioc_status;
7086 u16 handle, parent_handle;
7087 u64 sas_address;
7088 struct _sas_device *sas_device;
7089 struct _sas_node *expander_device;
7090 static struct _raid_device *raid_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307091 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307092
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307093 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307094
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307095 _scsih_sas_host_refresh(ioc);
7096
7097 /* expanders */
7098 handle = 0xFFFF;
7099 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7100 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7101 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7102 MPI2_IOCSTATUS_MASK;
7103 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7104 break;
7105 handle = le16_to_cpu(expander_pg0.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307106 spin_lock_irqsave(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307107 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7108 ioc, le64_to_cpu(expander_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307109 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307110 if (expander_device)
7111 _scsih_refresh_expander_links(ioc, expander_device,
7112 handle);
7113 else
7114 _scsih_expander_add(ioc, handle);
7115 }
7116
7117 if (!ioc->ir_firmware)
7118 goto skip_to_sas;
7119
7120 /* phys disk */
7121 phys_disk_num = 0xFF;
7122 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7123 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7124 phys_disk_num))) {
7125 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7126 MPI2_IOCSTATUS_MASK;
7127 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7128 break;
7129 phys_disk_num = pd_pg0.PhysDiskNum;
7130 handle = le16_to_cpu(pd_pg0.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307131 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307132 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307133 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307134 if (sas_device)
7135 continue;
7136 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7137 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7138 handle) != 0)
7139 continue;
7140 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7141 if (!_scsih_get_sas_address(ioc, parent_handle,
7142 &sas_address)) {
7143 mpt2sas_transport_update_links(ioc, sas_address,
7144 handle, sas_device_pg0.PhyNum,
7145 MPI2_SAS_NEG_LINK_RATE_1_5);
7146 set_bit(handle, ioc->pd_handles);
7147 _scsih_add_device(ioc, handle, 0, 1);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307148 }
7149 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307150
7151 /* volumes */
7152 handle = 0xFFFF;
7153 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7154 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7155 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7156 MPI2_IOCSTATUS_MASK;
7157 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7158 break;
7159 handle = le16_to_cpu(volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307160 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307161 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7162 le64_to_cpu(volume_pg1.WWID));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307163 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307164 if (raid_device)
7165 continue;
7166 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7167 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7168 sizeof(Mpi2RaidVolPage0_t)))
7169 continue;
7170 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7171 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7172 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7173 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7174 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7175 element.VolDevHandle = volume_pg1.DevHandle;
7176 _scsih_sas_volume_add(ioc, &element);
7177 }
7178 }
7179
7180 skip_to_sas:
7181
7182 /* sas devices */
7183 handle = 0xFFFF;
7184 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7185 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7186 handle))) {
7187 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7188 MPI2_IOCSTATUS_MASK;
7189 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7190 break;
7191 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7192 if (!(_scsih_is_end_device(
7193 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7194 continue;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307195 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307196 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7197 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307198 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307199 if (sas_device)
7200 continue;
7201 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7202 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7203 mpt2sas_transport_update_links(ioc, sas_address, handle,
7204 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7205 _scsih_add_device(ioc, handle, 0, 0);
7206 }
7207 }
7208
7209 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307210}
7211
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307212
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307213/**
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307214 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7215 * @ioc: per adapter object
7216 * @reset_phase: phase
7217 *
7218 * The handler for doing any required cleanup or initialization.
7219 *
7220 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7221 * MPT2_IOC_DONE_RESET
7222 *
7223 * Return nothing.
7224 */
7225void
7226mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7227{
7228 switch (reset_phase) {
7229 case MPT2_IOC_PRE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307230 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307231 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307232 break;
7233 case MPT2_IOC_AFTER_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307234 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307235 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307236 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7237 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7238 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7239 complete(&ioc->scsih_cmds.done);
7240 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307241 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7242 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7243 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7244 complete(&ioc->tm_cmds.done);
7245 }
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307246 _scsih_fw_event_cleanup_queue(ioc);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307247 _scsih_flush_running_cmds(ioc);
7248 break;
7249 case MPT2_IOC_DONE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307250 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307251 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307252 _scsih_sas_host_refresh(ioc);
Kashyap, Desai14695852010-03-30 10:52:44 +05307253 _scsih_prep_device_scan(ioc);
7254 _scsih_search_responding_sas_devices(ioc);
7255 _scsih_search_responding_raid_devices(ioc);
7256 _scsih_search_responding_expanders(ioc);
sreekanth.reddy@lsi.com14aa7f72012-07-17 15:56:13 +05307257 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7258 !ioc->sas_hba.num_phys)) {
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307259 _scsih_prep_device_scan(ioc);
7260 _scsih_search_responding_sas_devices(ioc);
7261 _scsih_search_responding_raid_devices(ioc);
7262 _scsih_search_responding_expanders(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307263 _scsih_error_recovery_delete_devices(ioc);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307264 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307265 break;
Eric Moore635374e2009-03-09 01:21:12 -06007266 }
7267}
7268
7269/**
7270 * _firmware_event_work - delayed task for processing firmware events
7271 * @ioc: per adapter object
7272 * @work: equal to the fw_event_work object
7273 * Context: user.
7274 *
7275 * Return nothing.
7276 */
7277static void
7278_firmware_event_work(struct work_struct *work)
7279{
7280 struct fw_event_work *fw_event = container_of(work,
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307281 struct fw_event_work, delayed_work.work);
Eric Moore635374e2009-03-09 01:21:12 -06007282 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7283
Eric Moore635374e2009-03-09 01:21:12 -06007284 /* the queue is being flushed so ignore this event */
Eric Moore3cb54692010-07-08 14:44:34 -06007285 if (ioc->remove_host || fw_event->cancel_pending_work ||
7286 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06007287 _scsih_fw_event_free(ioc, fw_event);
7288 return;
7289 }
Eric Moore635374e2009-03-09 01:21:12 -06007290
Eric Moore635374e2009-03-09 01:21:12 -06007291 switch (fw_event->event) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307292 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307293 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307294 ssleep(1);
7295 _scsih_remove_unresponding_sas_devices(ioc);
7296 _scsih_scan_for_devices_after_reset(ioc);
7297 break;
7298 case MPT2SAS_PORT_ENABLE_COMPLETE:
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307299 ioc->start_scan = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307300
7301
7302
7303 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7304 "from worker thread\n", ioc->name));
7305 break;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05307306 case MPT2SAS_TURN_ON_FAULT_LED:
7307 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
7308 break;
Eric Moore635374e2009-03-09 01:21:12 -06007309 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307310 _scsih_sas_topology_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007311 break;
7312 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307313 _scsih_sas_device_status_change_event(ioc,
7314 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007315 break;
7316 case MPI2_EVENT_SAS_DISCOVERY:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307317 _scsih_sas_discovery_event(ioc,
7318 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007319 break;
7320 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
Andrew Mortona78e21d2012-02-08 12:52:22 -08007321 _scsih_sas_broadcast_primitive_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307322 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007323 break;
7324 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7325 _scsih_sas_enclosure_dev_status_change_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307326 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007327 break;
7328 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307329 _scsih_sas_ir_config_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007330 break;
7331 case MPI2_EVENT_IR_VOLUME:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307332 _scsih_sas_ir_volume_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007333 break;
7334 case MPI2_EVENT_IR_PHYSICAL_DISK:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307335 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007336 break;
7337 case MPI2_EVENT_IR_OPERATION_STATUS:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307338 _scsih_sas_ir_operation_status_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007339 break;
Eric Moore635374e2009-03-09 01:21:12 -06007340 }
7341 _scsih_fw_event_free(ioc, fw_event);
7342}
7343
7344/**
7345 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7346 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307347 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06007348 * @reply: reply message frame(lower 32bit addr)
7349 * Context: interrupt.
7350 *
7351 * This function merely adds a new work task into ioc->firmware_event_thread.
7352 * The tasks are worked from _firmware_event_work in user context.
7353 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307354 * Return 1 meaning mf should be freed from _base_interrupt
7355 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06007356 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307357u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307358mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7359 u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06007360{
7361 struct fw_event_work *fw_event;
7362 Mpi2EventNotificationReply_t *mpi_reply;
Eric Moore635374e2009-03-09 01:21:12 -06007363 u16 event;
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307364 u16 sz;
Eric Moore635374e2009-03-09 01:21:12 -06007365
7366 /* events turned off due to host reset or driver unloading */
Eric Moore3cb54692010-07-08 14:44:34 -06007367 if (ioc->remove_host || ioc->pci_error_recovery)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307368 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007369
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307370 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
nagalakshmi.nandigama@lsi.com298c794d2012-03-20 12:07:17 +05307371
7372 if (unlikely(!mpi_reply)) {
7373 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7374 ioc->name, __FILE__, __LINE__, __func__);
7375 return 1;
7376 }
7377
Eric Moore635374e2009-03-09 01:21:12 -06007378 event = le16_to_cpu(mpi_reply->Event);
7379
7380 switch (event) {
7381 /* handle these */
7382 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7383 {
7384 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7385 (Mpi2EventDataSasBroadcastPrimitive_t *)
7386 mpi_reply->EventData;
7387
7388 if (baen_data->Primitive !=
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307389 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307390 return 1;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307391
7392 if (ioc->broadcast_aen_busy) {
7393 ioc->broadcast_aen_pending++;
7394 return 1;
7395 } else
7396 ioc->broadcast_aen_busy = 1;
Eric Moore635374e2009-03-09 01:21:12 -06007397 break;
7398 }
7399
7400 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7401 _scsih_check_topo_delete_events(ioc,
7402 (Mpi2EventDataSasTopologyChangeList_t *)
7403 mpi_reply->EventData);
7404 break;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05307405 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7406 _scsih_check_ir_config_unhide_events(ioc,
7407 (Mpi2EventDataIrConfigChangeList_t *)
7408 mpi_reply->EventData);
7409 break;
7410 case MPI2_EVENT_IR_VOLUME:
7411 _scsih_check_volume_delete_events(ioc,
7412 (Mpi2EventDataIrVolume_t *)
7413 mpi_reply->EventData);
7414 break;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307415 case MPI2_EVENT_LOG_ENTRY_ADDED:
7416 {
7417 Mpi2EventDataLogEntryAdded_t *log_entry;
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05307418 __le32 *log_code;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307419
7420 if (!ioc->is_warpdrive)
7421 break;
7422
7423 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7424 mpi_reply->EventData;
nagalakshmi.nandigama@lsi.comd838c362012-03-20 12:07:48 +05307425 log_code = (__le32 *)log_entry->LogData;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307426
7427 if (le16_to_cpu(log_entry->LogEntryQualifier)
7428 != MPT2_WARPDRIVE_LOGENTRY)
7429 break;
7430
7431 switch (le32_to_cpu(*log_code)) {
7432 case MPT2_WARPDRIVE_LC_SSDT:
7433 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7434 "IO Throttling has occurred in the WarpDrive "
7435 "subsystem. Check WarpDrive documentation for "
7436 "additional details.\n", ioc->name);
7437 break;
7438 case MPT2_WARPDRIVE_LC_SSDLW:
7439 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7440 "Program/Erase Cycles for the WarpDrive subsystem "
7441 "in degraded range. Check WarpDrive documentation "
7442 "for additional details.\n", ioc->name);
7443 break;
7444 case MPT2_WARPDRIVE_LC_SSDLF:
7445 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7446 "There are no Program/Erase Cycles for the "
7447 "WarpDrive subsystem. The storage device will be "
7448 "in read-only mode. Check WarpDrive documentation "
7449 "for additional details.\n", ioc->name);
7450 break;
7451 case MPT2_WARPDRIVE_LC_BRMF:
7452 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7453 "The Backup Rail Monitor has failed on the "
7454 "WarpDrive subsystem. Check WarpDrive "
7455 "documentation for additional details.\n",
7456 ioc->name);
7457 break;
7458 }
7459
7460 break;
7461 }
Eric Moore635374e2009-03-09 01:21:12 -06007462 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7463 case MPI2_EVENT_IR_OPERATION_STATUS:
7464 case MPI2_EVENT_SAS_DISCOVERY:
7465 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
Eric Moore635374e2009-03-09 01:21:12 -06007466 case MPI2_EVENT_IR_PHYSICAL_DISK:
Eric Moore635374e2009-03-09 01:21:12 -06007467 break;
7468
7469 default: /* ignore the rest */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307470 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007471 }
7472
7473 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
7474 if (!fw_event) {
7475 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7476 ioc->name, __FILE__, __LINE__, __func__);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307477 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007478 }
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307479 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7480 fw_event->event_data = kzalloc(sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06007481 if (!fw_event->event_data) {
7482 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7483 ioc->name, __FILE__, __LINE__, __func__);
7484 kfree(fw_event);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307485 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007486 }
7487
7488 memcpy(fw_event->event_data, mpi_reply->EventData,
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307489 sz);
Eric Moore635374e2009-03-09 01:21:12 -06007490 fw_event->ioc = ioc;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307491 fw_event->VF_ID = mpi_reply->VF_ID;
7492 fw_event->VP_ID = mpi_reply->VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -06007493 fw_event->event = event;
7494 _scsih_fw_event_add(ioc, fw_event);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307495 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007496}
7497
7498/* shost template */
7499static struct scsi_host_template scsih_driver_template = {
7500 .module = THIS_MODULE,
7501 .name = "Fusion MPT SAS Host",
7502 .proc_name = MPT2SAS_DRIVER_NAME,
Eric Moored5d135b2009-05-18 13:02:08 -06007503 .queuecommand = _scsih_qcmd,
7504 .target_alloc = _scsih_target_alloc,
7505 .slave_alloc = _scsih_slave_alloc,
7506 .slave_configure = _scsih_slave_configure,
7507 .target_destroy = _scsih_target_destroy,
7508 .slave_destroy = _scsih_slave_destroy,
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307509 .scan_finished = _scsih_scan_finished,
7510 .scan_start = _scsih_scan_start,
Eric Moored5d135b2009-05-18 13:02:08 -06007511 .change_queue_depth = _scsih_change_queue_depth,
7512 .change_queue_type = _scsih_change_queue_type,
7513 .eh_abort_handler = _scsih_abort,
7514 .eh_device_reset_handler = _scsih_dev_reset,
7515 .eh_target_reset_handler = _scsih_target_reset,
7516 .eh_host_reset_handler = _scsih_host_reset,
7517 .bios_param = _scsih_bios_param,
Eric Moore635374e2009-03-09 01:21:12 -06007518 .can_queue = 1,
7519 .this_id = -1,
7520 .sg_tablesize = MPT2SAS_SG_DEPTH,
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05307521 .max_sectors = 32767,
Eric Moore635374e2009-03-09 01:21:12 -06007522 .cmd_per_lun = 7,
7523 .use_clustering = ENABLE_CLUSTERING,
7524 .shost_attrs = mpt2sas_host_attrs,
7525 .sdev_attrs = mpt2sas_dev_attrs,
7526};
7527
7528/**
7529 * _scsih_expander_node_remove - removing expander device from list.
7530 * @ioc: per adapter object
7531 * @sas_expander: the sas_device object
7532 * Context: Calling function should acquire ioc->sas_node_lock.
7533 *
7534 * Removing object and freeing associated memory from the
7535 * ioc->sas_expander_list.
7536 *
7537 * Return nothing.
7538 */
7539static void
7540_scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7541 struct _sas_node *sas_expander)
7542{
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307543 struct _sas_port *mpt2sas_port, *next;
Eric Moore635374e2009-03-09 01:21:12 -06007544
7545 /* remove sibling ports attached to this expander */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307546 list_for_each_entry_safe(mpt2sas_port, next,
Eric Moore635374e2009-03-09 01:21:12 -06007547 &sas_expander->sas_port_list, port_list) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307548 if (ioc->shost_recovery)
7549 return;
Eric Moore635374e2009-03-09 01:21:12 -06007550 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307551 SAS_END_DEVICE)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307552 mpt2sas_device_remove_by_sas_address(ioc,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307553 mpt2sas_port->remote_identify.sas_address);
7554 else if (mpt2sas_port->remote_identify.device_type ==
7555 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06007556 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307557 SAS_FANOUT_EXPANDER_DEVICE)
7558 mpt2sas_expander_remove(ioc,
7559 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007560 }
7561
7562 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307563 sas_expander->sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06007564
7565 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7566 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7567 sas_expander->handle, (unsigned long long)
7568 sas_expander->sas_address);
7569
Eric Moore635374e2009-03-09 01:21:12 -06007570 kfree(sas_expander->phy);
7571 kfree(sas_expander);
7572}
7573
7574/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05307575 * _scsih_ir_shutdown - IR shutdown notification
7576 * @ioc: per adapter object
7577 *
7578 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7579 * the host system is shutting down.
7580 *
7581 * Return nothing.
7582 */
7583static void
7584_scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7585{
7586 Mpi2RaidActionRequest_t *mpi_request;
7587 Mpi2RaidActionReply_t *mpi_reply;
7588 u16 smid;
7589
7590 /* is IR firmware build loaded ? */
7591 if (!ioc->ir_firmware)
7592 return;
7593
7594 /* are there any volumes ? */
7595 if (list_empty(&ioc->raid_device_list))
7596 return;
7597
7598 mutex_lock(&ioc->scsih_cmds.mutex);
7599
7600 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7601 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7602 ioc->name, __func__);
7603 goto out;
7604 }
7605 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7606
7607 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7608 if (!smid) {
7609 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7610 ioc->name, __func__);
7611 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7612 goto out;
7613 }
7614
7615 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7616 ioc->scsih_cmds.smid = smid;
7617 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7618
7619 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7620 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7621
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307622 if (!ioc->hide_ir_msg)
7623 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307624 init_completion(&ioc->scsih_cmds.done);
7625 mpt2sas_base_put_smid_default(ioc, smid);
7626 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7627
7628 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7629 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7630 ioc->name, __func__);
7631 goto out;
7632 }
7633
7634 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7635 mpi_reply = ioc->scsih_cmds.reply;
7636
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307637 if (!ioc->hide_ir_msg)
7638 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7639 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7640 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7641 le32_to_cpu(mpi_reply->IOCLogInfo));
Kashyap, Desai744090d2009-10-05 15:56:56 +05307642 }
7643
7644 out:
7645 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7646 mutex_unlock(&ioc->scsih_cmds.mutex);
7647}
7648
7649/**
7650 * _scsih_shutdown - routine call during system shutdown
7651 * @pdev: PCI device struct
7652 *
7653 * Return nothing.
7654 */
7655static void
7656_scsih_shutdown(struct pci_dev *pdev)
7657{
7658 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7659 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307660 struct workqueue_struct *wq;
7661 unsigned long flags;
7662
7663 ioc->remove_host = 1;
7664 _scsih_fw_event_cleanup_queue(ioc);
7665
7666 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7667 wq = ioc->firmware_event_thread;
7668 ioc->firmware_event_thread = NULL;
7669 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7670 if (wq)
7671 destroy_workqueue(wq);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307672
7673 _scsih_ir_shutdown(ioc);
7674 mpt2sas_base_detach(ioc);
7675}
7676
7677/**
Eric Moored5d135b2009-05-18 13:02:08 -06007678 * _scsih_remove - detach and remove add host
Eric Moore635374e2009-03-09 01:21:12 -06007679 * @pdev: PCI device struct
7680 *
Kashyap, Desai744090d2009-10-05 15:56:56 +05307681 * Routine called when unloading the driver.
Eric Moore635374e2009-03-09 01:21:12 -06007682 * Return nothing.
7683 */
7684static void __devexit
Eric Moored5d135b2009-05-18 13:02:08 -06007685_scsih_remove(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06007686{
7687 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7688 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307689 struct _sas_port *mpt2sas_port, *next_port;
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307690 struct _raid_device *raid_device, *next;
7691 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06007692 struct workqueue_struct *wq;
7693 unsigned long flags;
7694
7695 ioc->remove_host = 1;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307696 _scsih_fw_event_cleanup_queue(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007697
7698 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7699 wq = ioc->firmware_event_thread;
7700 ioc->firmware_event_thread = NULL;
7701 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7702 if (wq)
7703 destroy_workqueue(wq);
7704
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307705 /* release all the volumes */
Kashyap, Desai3a9c9132011-01-04 11:40:23 +05307706 _scsih_ir_shutdown(ioc);
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307707 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7708 list) {
7709 if (raid_device->starget) {
7710 sas_target_priv_data =
7711 raid_device->starget->hostdata;
7712 sas_target_priv_data->deleted = 1;
7713 scsi_remove_target(&raid_device->starget->dev);
7714 }
7715 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7716 "(0x%016llx)\n", ioc->name, raid_device->handle,
7717 (unsigned long long) raid_device->wwid);
7718 _scsih_raid_device_remove(ioc, raid_device);
7719 }
7720
Eric Moore635374e2009-03-09 01:21:12 -06007721 /* free ports attached to the sas_host */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307722 list_for_each_entry_safe(mpt2sas_port, next_port,
Eric Moore635374e2009-03-09 01:21:12 -06007723 &ioc->sas_hba.sas_port_list, port_list) {
7724 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307725 SAS_END_DEVICE)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307726 mpt2sas_device_remove_by_sas_address(ioc,
Eric Moore635374e2009-03-09 01:21:12 -06007727 mpt2sas_port->remote_identify.sas_address);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307728 else if (mpt2sas_port->remote_identify.device_type ==
7729 SAS_EDGE_EXPANDER_DEVICE ||
7730 mpt2sas_port->remote_identify.device_type ==
7731 SAS_FANOUT_EXPANDER_DEVICE)
7732 mpt2sas_expander_remove(ioc,
7733 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007734 }
7735
7736 /* free phys attached to the sas_host */
7737 if (ioc->sas_hba.num_phys) {
7738 kfree(ioc->sas_hba.phy);
7739 ioc->sas_hba.phy = NULL;
7740 ioc->sas_hba.num_phys = 0;
7741 }
7742
7743 sas_remove_host(shost);
kashyap.desai@lsi.com9ae89b02011-08-04 16:47:50 +05307744 mpt2sas_base_detach(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007745 list_del(&ioc->list);
7746 scsi_remove_host(shost);
7747 scsi_host_put(shost);
7748}
7749
7750/**
7751 * _scsih_probe_boot_devices - reports 1st device
7752 * @ioc: per adapter object
7753 *
7754 * If specified in bios page 2, this routine reports the 1st
7755 * device scsi-ml or sas transport for persistent boot device
7756 * purposes. Please refer to function _scsih_determine_boot_device()
7757 */
7758static void
7759_scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7760{
7761 u8 is_raid;
7762 void *device;
7763 struct _sas_device *sas_device;
7764 struct _raid_device *raid_device;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307765 u16 handle;
7766 u64 sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007767 u64 sas_address;
7768 unsigned long flags;
7769 int rc;
7770
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307771 /* no Bios, return immediately */
7772 if (!ioc->bios_pg3.BiosVersion)
7773 return;
7774
Eric Moore635374e2009-03-09 01:21:12 -06007775 device = NULL;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307776 is_raid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007777 if (ioc->req_boot_device.device) {
7778 device = ioc->req_boot_device.device;
7779 is_raid = ioc->req_boot_device.is_raid;
7780 } else if (ioc->req_alt_boot_device.device) {
7781 device = ioc->req_alt_boot_device.device;
7782 is_raid = ioc->req_alt_boot_device.is_raid;
7783 } else if (ioc->current_boot_device.device) {
7784 device = ioc->current_boot_device.device;
7785 is_raid = ioc->current_boot_device.is_raid;
7786 }
7787
7788 if (!device)
7789 return;
7790
7791 if (is_raid) {
7792 raid_device = device;
7793 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7794 raid_device->id, 0);
7795 if (rc)
7796 _scsih_raid_device_remove(ioc, raid_device);
7797 } else {
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307798 spin_lock_irqsave(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06007799 sas_device = device;
7800 handle = sas_device->handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307801 sas_address_parent = sas_device->sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007802 sas_address = sas_device->sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06007803 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7804 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307805
7806 if (ioc->hide_drives)
7807 return;
Eric Moore635374e2009-03-09 01:21:12 -06007808 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307809 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -06007810 _scsih_sas_device_remove(ioc, sas_device);
7811 } else if (!sas_device->starget) {
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05307812 if (!ioc->is_driver_loading)
7813 mpt2sas_transport_port_remove(ioc, sas_address,
7814 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06007815 _scsih_sas_device_remove(ioc, sas_device);
7816 }
7817 }
7818}
7819
7820/**
7821 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7822 * @ioc: per adapter object
7823 *
7824 * Called during initial loading of the driver.
7825 */
7826static void
7827_scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7828{
7829 struct _raid_device *raid_device, *raid_next;
7830 int rc;
7831
7832 list_for_each_entry_safe(raid_device, raid_next,
7833 &ioc->raid_device_list, list) {
7834 if (raid_device->starget)
7835 continue;
7836 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7837 raid_device->id, 0);
7838 if (rc)
7839 _scsih_raid_device_remove(ioc, raid_device);
7840 }
7841}
7842
7843/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307844 * _scsih_probe_sas - reporting sas devices to sas transport
Eric Moore635374e2009-03-09 01:21:12 -06007845 * @ioc: per adapter object
7846 *
7847 * Called during initial loading of the driver.
7848 */
7849static void
7850_scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7851{
7852 struct _sas_device *sas_device, *next;
7853 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06007854
7855 /* SAS Device List */
7856 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7857 list) {
Eric Moore635374e2009-03-09 01:21:12 -06007858
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307859 if (ioc->hide_drives)
7860 continue;
7861
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307862 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7863 sas_device->sas_address_parent)) {
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307864 list_del(&sas_device->list);
7865 kfree(sas_device);
7866 continue;
Eric Moore635374e2009-03-09 01:21:12 -06007867 } else if (!sas_device->starget) {
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05307868 if (!ioc->is_driver_loading)
7869 mpt2sas_transport_port_remove(ioc,
7870 sas_device->sas_address,
7871 sas_device->sas_address_parent);
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307872 list_del(&sas_device->list);
7873 kfree(sas_device);
7874 continue;
7875
Eric Moore635374e2009-03-09 01:21:12 -06007876 }
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307877 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7878 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7879 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06007880 }
7881}
7882
7883/**
7884 * _scsih_probe_devices - probing for devices
7885 * @ioc: per adapter object
7886 *
7887 * Called during initial loading of the driver.
7888 */
7889static void
7890_scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7891{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307892 u16 volume_mapping_flags;
Eric Moore635374e2009-03-09 01:21:12 -06007893
7894 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7895 return; /* return when IOC doesn't support initiator mode */
7896
7897 _scsih_probe_boot_devices(ioc);
7898
7899 if (ioc->ir_firmware) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307900 volume_mapping_flags =
7901 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7902 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7903 if (volume_mapping_flags ==
7904 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
Eric Moore635374e2009-03-09 01:21:12 -06007905 _scsih_probe_raid(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307906 _scsih_probe_sas(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007907 } else {
Eric Moore635374e2009-03-09 01:21:12 -06007908 _scsih_probe_sas(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307909 _scsih_probe_raid(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007910 }
7911 } else
7912 _scsih_probe_sas(ioc);
7913}
7914
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307915
7916/**
7917 * _scsih_scan_start - scsi lld callback for .scan_start
7918 * @shost: SCSI host pointer
7919 *
7920 * The shost has the ability to discover targets on its own instead
7921 * of scanning the entire bus. In our implemention, we will kick off
7922 * firmware discovery.
7923 */
7924static void
7925_scsih_scan_start(struct Scsi_Host *shost)
7926{
7927 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7928 int rc;
7929
7930 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7931 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
7932
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05307933 if (disable_discovery > 0)
7934 return;
7935
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307936 ioc->start_scan = 1;
7937 rc = mpt2sas_port_enable(ioc);
7938
7939 if (rc != 0)
7940 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
7941}
7942
7943/**
7944 * _scsih_scan_finished - scsi lld callback for .scan_finished
7945 * @shost: SCSI host pointer
7946 * @time: elapsed time of the scan in jiffies
7947 *
7948 * This function will be called periodically until it returns 1 with the
7949 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7950 * we wait for firmware discovery to complete, then return 1.
7951 */
7952static int
7953_scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7954{
7955 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7956
sreekanth.reddy@lsi.com4b193172012-07-17 15:56:12 +05307957 if (disable_discovery > 0) {
7958 ioc->is_driver_loading = 0;
7959 ioc->wait_for_discovery_to_complete = 0;
7960 return 1;
7961 }
7962
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307963 if (time >= (300 * HZ)) {
7964 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7965 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
7966 "(timeout=300s)\n", ioc->name);
7967 ioc->is_driver_loading = 0;
7968 return 1;
7969 }
7970
7971 if (ioc->start_scan)
7972 return 0;
7973
7974 if (ioc->start_scan_failed) {
7975 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
7976 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
7977 ioc->is_driver_loading = 0;
7978 ioc->wait_for_discovery_to_complete = 0;
7979 ioc->remove_host = 1;
7980 return 1;
7981 }
7982
7983 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
7984 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7985
7986 if (ioc->wait_for_discovery_to_complete) {
7987 ioc->wait_for_discovery_to_complete = 0;
7988 _scsih_probe_devices(ioc);
7989 }
7990 mpt2sas_base_start_watchdog(ioc);
7991 ioc->is_driver_loading = 0;
7992 return 1;
7993}
7994
7995
Eric Moore635374e2009-03-09 01:21:12 -06007996/**
Eric Moored5d135b2009-05-18 13:02:08 -06007997 * _scsih_probe - attach and add scsi host
Eric Moore635374e2009-03-09 01:21:12 -06007998 * @pdev: PCI device struct
7999 * @id: pci device id
8000 *
8001 * Returns 0 success, anything else error.
8002 */
8003static int
Eric Moored5d135b2009-05-18 13:02:08 -06008004_scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
Eric Moore635374e2009-03-09 01:21:12 -06008005{
8006 struct MPT2SAS_ADAPTER *ioc;
8007 struct Scsi_Host *shost;
8008
8009 shost = scsi_host_alloc(&scsih_driver_template,
8010 sizeof(struct MPT2SAS_ADAPTER));
8011 if (!shost)
8012 return -ENODEV;
8013
8014 /* init local params */
8015 ioc = shost_priv(shost);
8016 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
8017 INIT_LIST_HEAD(&ioc->list);
Eric Mooreba33fad2009-03-15 21:37:18 -06008018 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
Eric Moore635374e2009-03-09 01:21:12 -06008019 ioc->shost = shost;
8020 ioc->id = mpt_ids++;
8021 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
8022 ioc->pdev = pdev;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308023 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8024 ioc->is_warpdrive = 1;
8025 ioc->hide_ir_msg = 1;
8026 } else
8027 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
Eric Moore635374e2009-03-09 01:21:12 -06008028 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8029 ioc->tm_cb_idx = tm_cb_idx;
8030 ioc->ctl_cb_idx = ctl_cb_idx;
8031 ioc->base_cb_idx = base_cb_idx;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308032 ioc->port_enable_cb_idx = port_enable_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008033 ioc->transport_cb_idx = transport_cb_idx;
Kashyap, Desai744090d2009-10-05 15:56:56 +05308034 ioc->scsih_cb_idx = scsih_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008035 ioc->config_cb_idx = config_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308036 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308037 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308038 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008039 ioc->logging_level = logging_level;
nagalakshmi.nandigama@lsi.com845a0e42011-12-01 07:42:04 +05308040 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
Eric Moore635374e2009-03-09 01:21:12 -06008041 /* misc semaphores and spin locks */
Kashyap, Desaid2742132010-06-17 13:28:55 +05308042 mutex_init(&ioc->reset_in_progress_mutex);
Eric Moore635374e2009-03-09 01:21:12 -06008043 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8044 spin_lock_init(&ioc->scsi_lookup_lock);
8045 spin_lock_init(&ioc->sas_device_lock);
8046 spin_lock_init(&ioc->sas_node_lock);
8047 spin_lock_init(&ioc->fw_event_lock);
8048 spin_lock_init(&ioc->raid_device_lock);
8049
8050 INIT_LIST_HEAD(&ioc->sas_device_list);
8051 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8052 INIT_LIST_HEAD(&ioc->sas_expander_list);
8053 INIT_LIST_HEAD(&ioc->fw_event_list);
8054 INIT_LIST_HEAD(&ioc->raid_device_list);
8055 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308056 INIT_LIST_HEAD(&ioc->delayed_tr_list);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308057 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
Eric Moore635374e2009-03-09 01:21:12 -06008058
8059 /* init shost parameters */
Eric Moored334aa72010-04-22 10:47:40 -06008060 shost->max_cmd_len = 32;
Eric Moore635374e2009-03-09 01:21:12 -06008061 shost->max_lun = max_lun;
8062 shost->transportt = mpt2sas_transport_template;
8063 shost->unique_id = ioc->id;
8064
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308065 if (max_sectors != 0xFFFF) {
8066 if (max_sectors < 64) {
8067 shost->max_sectors = 64;
sreekanth.reddy@lsi.comeece5de2012-07-17 15:56:09 +05308068 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "\
8069 "for max_sectors, range is 64 to 32767. Assigning "\
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308070 "value of 64.\n", ioc->name, max_sectors);
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05308071 } else if (max_sectors > 32767) {
8072 shost->max_sectors = 32767;
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308073 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8074 "for max_sectors, range is 64 to 8192. Assigning "
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05308075 "default value of 32767.\n", ioc->name,
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308076 max_sectors);
8077 } else {
8078 shost->max_sectors = max_sectors & 0xFFFE;
8079 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
8080 "set to %d\n", ioc->name, shost->max_sectors);
8081 }
8082 }
8083
Eric Moore635374e2009-03-09 01:21:12 -06008084 if ((scsi_add_host(shost, &pdev->dev))) {
8085 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8086 ioc->name, __FILE__, __LINE__, __func__);
8087 list_del(&ioc->list);
8088 goto out_add_shost_fail;
8089 }
8090
Eric Moore3c621b32009-05-18 12:59:41 -06008091 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
Eric Moored334aa72010-04-22 10:47:40 -06008092 | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308093 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
Eric Moore3c621b32009-05-18 12:59:41 -06008094
Eric Moore635374e2009-03-09 01:21:12 -06008095 /* event thread */
8096 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8097 "fw_event%d", ioc->id);
8098 ioc->firmware_event_thread = create_singlethread_workqueue(
8099 ioc->firmware_event_name);
8100 if (!ioc->firmware_event_thread) {
8101 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8102 ioc->name, __FILE__, __LINE__, __func__);
8103 goto out_thread_fail;
8104 }
8105
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308106 ioc->is_driver_loading = 1;
Eric Moore635374e2009-03-09 01:21:12 -06008107 if ((mpt2sas_base_attach(ioc))) {
8108 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8109 ioc->name, __FILE__, __LINE__, __func__);
8110 goto out_attach_fail;
8111 }
8112
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308113 if (ioc->is_warpdrive) {
8114 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8115 ioc->hide_drives = 0;
8116 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8117 ioc->hide_drives = 1;
8118 else {
8119 if (_scsih_get_num_volumes(ioc))
8120 ioc->hide_drives = 1;
8121 else
8122 ioc->hide_drives = 0;
8123 }
8124 } else
8125 ioc->hide_drives = 0;
nagalakshmi.nandigama@lsi.com2cb6fc82011-12-13 09:29:15 +05308126 scsi_scan_host(shost);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308127
Eric Moore635374e2009-03-09 01:21:12 -06008128 return 0;
8129
8130 out_attach_fail:
8131 destroy_workqueue(ioc->firmware_event_thread);
8132 out_thread_fail:
8133 list_del(&ioc->list);
8134 scsi_remove_host(shost);
8135 out_add_shost_fail:
Tomas Henzlf555e052012-04-17 15:24:48 +02008136 scsi_host_put(shost);
Eric Moore635374e2009-03-09 01:21:12 -06008137 return -ENODEV;
8138}
8139
8140#ifdef CONFIG_PM
8141/**
Eric Moored5d135b2009-05-18 13:02:08 -06008142 * _scsih_suspend - power management suspend main entry point
Eric Moore635374e2009-03-09 01:21:12 -06008143 * @pdev: PCI device struct
8144 * @state: PM state change to (usually PCI_D3)
8145 *
8146 * Returns 0 success, anything else error.
8147 */
8148static int
Eric Moored5d135b2009-05-18 13:02:08 -06008149_scsih_suspend(struct pci_dev *pdev, pm_message_t state)
Eric Moore635374e2009-03-09 01:21:12 -06008150{
8151 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8152 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05308153 pci_power_t device_state;
Eric Moore635374e2009-03-09 01:21:12 -06008154
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308155 mpt2sas_base_stop_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008156 scsi_block_requests(shost);
8157 device_state = pci_choose_state(pdev, state);
8158 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8159 "operating state [D%d]\n", ioc->name, pdev,
8160 pci_name(pdev), device_state);
8161
8162 mpt2sas_base_free_resources(ioc);
8163 pci_save_state(pdev);
8164 pci_disable_device(pdev);
8165 pci_set_power_state(pdev, device_state);
8166 return 0;
8167}
8168
8169/**
Eric Moored5d135b2009-05-18 13:02:08 -06008170 * _scsih_resume - power management resume main entry point
Eric Moore635374e2009-03-09 01:21:12 -06008171 * @pdev: PCI device struct
8172 *
8173 * Returns 0 success, anything else error.
8174 */
8175static int
Eric Moored5d135b2009-05-18 13:02:08 -06008176_scsih_resume(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06008177{
8178 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8179 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05308180 pci_power_t device_state = pdev->current_state;
Eric Moore635374e2009-03-09 01:21:12 -06008181 int r;
8182
8183 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8184 "operating state [D%d]\n", ioc->name, pdev,
8185 pci_name(pdev), device_state);
8186
8187 pci_set_power_state(pdev, PCI_D0);
8188 pci_enable_wake(pdev, PCI_D0, 0);
8189 pci_restore_state(pdev);
8190 ioc->pdev = pdev;
8191 r = mpt2sas_base_map_resources(ioc);
8192 if (r)
8193 return r;
8194
8195 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8196 scsi_unblock_requests(shost);
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308197 mpt2sas_base_start_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008198 return 0;
8199}
8200#endif /* CONFIG_PM */
8201
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308202/**
8203 * _scsih_pci_error_detected - Called when a PCI error is detected.
8204 * @pdev: PCI device struct
8205 * @state: PCI channel state
8206 *
8207 * Description: Called when a PCI error is detected.
8208 *
8209 * Return value:
8210 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8211 */
8212static pci_ers_result_t
8213_scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8214{
8215 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8216 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8217
8218 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8219 ioc->name, state);
8220
8221 switch (state) {
8222 case pci_channel_io_normal:
8223 return PCI_ERS_RESULT_CAN_RECOVER;
8224 case pci_channel_io_frozen:
Eric Moore3cb54692010-07-08 14:44:34 -06008225 /* Fatal error, prepare for slot reset */
8226 ioc->pci_error_recovery = 1;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308227 scsi_block_requests(ioc->shost);
8228 mpt2sas_base_stop_watchdog(ioc);
8229 mpt2sas_base_free_resources(ioc);
8230 return PCI_ERS_RESULT_NEED_RESET;
8231 case pci_channel_io_perm_failure:
Eric Moore3cb54692010-07-08 14:44:34 -06008232 /* Permanent error, prepare for device removal */
8233 ioc->pci_error_recovery = 1;
8234 mpt2sas_base_stop_watchdog(ioc);
8235 _scsih_flush_running_cmds(ioc);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308236 return PCI_ERS_RESULT_DISCONNECT;
8237 }
8238 return PCI_ERS_RESULT_NEED_RESET;
8239}
8240
8241/**
8242 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8243 * @pdev: PCI device struct
8244 *
8245 * Description: This routine is called by the pci error recovery
8246 * code after the PCI slot has been reset, just before we
8247 * should resume normal operations.
8248 */
8249static pci_ers_result_t
8250_scsih_pci_slot_reset(struct pci_dev *pdev)
8251{
8252 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8253 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8254 int rc;
8255
8256 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8257 ioc->name);
8258
Eric Moore3cb54692010-07-08 14:44:34 -06008259 ioc->pci_error_recovery = 0;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308260 ioc->pdev = pdev;
Eric Moore3cb54692010-07-08 14:44:34 -06008261 pci_restore_state(pdev);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308262 rc = mpt2sas_base_map_resources(ioc);
8263 if (rc)
8264 return PCI_ERS_RESULT_DISCONNECT;
8265
8266
8267 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8268 FORCE_BIG_HAMMER);
8269
8270 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8271 (rc == 0) ? "success" : "failed");
8272
8273 if (!rc)
8274 return PCI_ERS_RESULT_RECOVERED;
8275 else
8276 return PCI_ERS_RESULT_DISCONNECT;
8277}
8278
8279/**
8280 * _scsih_pci_resume() - resume normal ops after PCI reset
8281 * @pdev: pointer to PCI device
8282 *
8283 * Called when the error recovery driver tells us that its
8284 * OK to resume normal operation. Use completion to allow
8285 * halted scsi ops to resume.
8286 */
8287static void
8288_scsih_pci_resume(struct pci_dev *pdev)
8289{
8290 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8291 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8292
8293 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8294
8295 pci_cleanup_aer_uncorrect_error_status(pdev);
8296 mpt2sas_base_start_watchdog(ioc);
8297 scsi_unblock_requests(ioc->shost);
8298}
8299
8300/**
8301 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8302 * @pdev: pointer to PCI device
8303 */
8304static pci_ers_result_t
8305_scsih_pci_mmio_enabled(struct pci_dev *pdev)
8306{
8307 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8308 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8309
8310 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8311 ioc->name);
8312
8313 /* TODO - dump whatever for debugging purposes */
8314
8315 /* Request a slot reset. */
8316 return PCI_ERS_RESULT_NEED_RESET;
8317}
8318
8319static struct pci_error_handlers _scsih_err_handler = {
8320 .error_detected = _scsih_pci_error_detected,
8321 .mmio_enabled = _scsih_pci_mmio_enabled,
8322 .slot_reset = _scsih_pci_slot_reset,
8323 .resume = _scsih_pci_resume,
8324};
Eric Moore635374e2009-03-09 01:21:12 -06008325
8326static struct pci_driver scsih_driver = {
8327 .name = MPT2SAS_DRIVER_NAME,
8328 .id_table = scsih_pci_table,
Eric Moored5d135b2009-05-18 13:02:08 -06008329 .probe = _scsih_probe,
8330 .remove = __devexit_p(_scsih_remove),
Kashyap, Desai744090d2009-10-05 15:56:56 +05308331 .shutdown = _scsih_shutdown,
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308332 .err_handler = &_scsih_err_handler,
Eric Moore635374e2009-03-09 01:21:12 -06008333#ifdef CONFIG_PM
Eric Moored5d135b2009-05-18 13:02:08 -06008334 .suspend = _scsih_suspend,
8335 .resume = _scsih_resume,
Eric Moore635374e2009-03-09 01:21:12 -06008336#endif
8337};
8338
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308339/* raid transport support */
8340static struct raid_function_template mpt2sas_raid_functions = {
8341 .cookie = &scsih_driver_template,
8342 .is_raid = _scsih_is_raid,
8343 .get_resync = _scsih_get_resync,
8344 .get_state = _scsih_get_state,
8345};
Eric Moore635374e2009-03-09 01:21:12 -06008346
8347/**
Eric Moored5d135b2009-05-18 13:02:08 -06008348 * _scsih_init - main entry point for this driver.
Eric Moore635374e2009-03-09 01:21:12 -06008349 *
8350 * Returns 0 success, anything else error.
8351 */
8352static int __init
Eric Moored5d135b2009-05-18 13:02:08 -06008353_scsih_init(void)
Eric Moore635374e2009-03-09 01:21:12 -06008354{
8355 int error;
8356
8357 mpt_ids = 0;
8358 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8359 MPT2SAS_DRIVER_VERSION);
8360
8361 mpt2sas_transport_template =
8362 sas_attach_transport(&mpt2sas_transport_functions);
8363 if (!mpt2sas_transport_template)
8364 return -ENODEV;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308365 /* raid transport support */
8366 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8367 if (!mpt2sas_raid_template) {
8368 sas_release_transport(mpt2sas_transport_template);
8369 return -ENODEV;
8370 }
Eric Moore635374e2009-03-09 01:21:12 -06008371
8372 mpt2sas_base_initialize_callback_handler();
8373
8374 /* queuecommand callback hander */
Eric Moored5d135b2009-05-18 13:02:08 -06008375 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
Eric Moore635374e2009-03-09 01:21:12 -06008376
Uwe Kleine-König65155b32010-06-11 12:17:01 +02008377 /* task management callback handler */
Eric Moored5d135b2009-05-18 13:02:08 -06008378 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
Eric Moore635374e2009-03-09 01:21:12 -06008379
8380 /* base internal commands callback handler */
8381 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308382 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8383 mpt2sas_port_enable_done);
Eric Moore635374e2009-03-09 01:21:12 -06008384
8385 /* transport internal commands callback handler */
8386 transport_cb_idx = mpt2sas_base_register_callback_handler(
8387 mpt2sas_transport_done);
8388
Kashyap, Desai744090d2009-10-05 15:56:56 +05308389 /* scsih internal commands callback handler */
8390 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8391
Eric Moore635374e2009-03-09 01:21:12 -06008392 /* configuration page API internal commands callback handler */
8393 config_cb_idx = mpt2sas_base_register_callback_handler(
8394 mpt2sas_config_done);
8395
8396 /* ctl module callback handler */
8397 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8398
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308399 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8400 _scsih_tm_tr_complete);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308401
8402 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8403 _scsih_tm_volume_tr_complete);
8404
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308405 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8406 _scsih_sas_control_complete);
8407
Eric Moore635374e2009-03-09 01:21:12 -06008408 mpt2sas_ctl_init();
8409
8410 error = pci_register_driver(&scsih_driver);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308411 if (error) {
8412 /* raid transport support */
8413 raid_class_release(mpt2sas_raid_template);
Eric Moore635374e2009-03-09 01:21:12 -06008414 sas_release_transport(mpt2sas_transport_template);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308415 }
Eric Moore635374e2009-03-09 01:21:12 -06008416
8417 return error;
8418}
8419
8420/**
Eric Moored5d135b2009-05-18 13:02:08 -06008421 * _scsih_exit - exit point for this driver (when it is a module).
Eric Moore635374e2009-03-09 01:21:12 -06008422 *
8423 * Returns 0 success, anything else error.
8424 */
8425static void __exit
Eric Moored5d135b2009-05-18 13:02:08 -06008426_scsih_exit(void)
Eric Moore635374e2009-03-09 01:21:12 -06008427{
8428 printk(KERN_INFO "mpt2sas version %s unloading\n",
8429 MPT2SAS_DRIVER_VERSION);
8430
8431 pci_unregister_driver(&scsih_driver);
8432
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308433 mpt2sas_ctl_exit();
8434
Eric Moore635374e2009-03-09 01:21:12 -06008435 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8436 mpt2sas_base_release_callback_handler(tm_cb_idx);
8437 mpt2sas_base_release_callback_handler(base_cb_idx);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308438 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008439 mpt2sas_base_release_callback_handler(transport_cb_idx);
Kashyap, Desai744090d2009-10-05 15:56:56 +05308440 mpt2sas_base_release_callback_handler(scsih_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008441 mpt2sas_base_release_callback_handler(config_cb_idx);
8442 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8443
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308444 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308445 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308446 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8447
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308448 /* raid transport support */
8449 raid_class_release(mpt2sas_raid_template);
8450 sas_release_transport(mpt2sas_transport_template);
8451
Eric Moore635374e2009-03-09 01:21:12 -06008452}
8453
Eric Moored5d135b2009-05-18 13:02:08 -06008454module_init(_scsih_init);
8455module_exit(_scsih_exit);